|
80 | 80 | #include "HTMLScriptElement.h"
|
81 | 81 | #include "HTMLSelectElement.h"
|
82 | 82 | #include "HTMLTemplateElement.h"
|
| 83 | +#include "HTMLTextAreaElement.h" |
83 | 84 | #include "IdChangeInvalidation.h"
|
84 | 85 | #include "IdTargetObserverRegistry.h"
|
| 86 | +#include "InputType.h" |
85 | 87 | #include "InspectorInstrumentation.h"
|
86 | 88 | #include "JSDOMPromiseDeferred.h"
|
87 | 89 | #include "JSLazyEventListener.h"
|
@@ -4752,6 +4754,53 @@ bool Element::isSpellCheckingEnabled() const
|
4752 | 4754 | return true;
|
4753 | 4755 | }
|
4754 | 4756 |
|
| 4757 | +bool Element::isWritingSuggestionsEnabled() const |
| 4758 | +{ |
| 4759 | + // If none of the following conditions are true, then return `false`. |
| 4760 | + |
| 4761 | + // `element` is an `input` element whose `type` attribute is in either the |
| 4762 | + // `Text`, `Search`, `URL`, `Email` state and is `mutable`. |
| 4763 | + auto isEligibleInputElement = [&] { |
| 4764 | + RefPtr input = dynamicDowncast<HTMLInputElement>(*this); |
| 4765 | + if (!input) |
| 4766 | + return false; |
| 4767 | + |
| 4768 | + return !input->isDisabledFormControl() && input->supportsWritingSuggestions(); |
| 4769 | + }; |
| 4770 | + |
| 4771 | + // `element` is a `textarea` element that is `mutable`. |
| 4772 | + auto isEligibleTextArea = [&] { |
| 4773 | + RefPtr textArea = dynamicDowncast<HTMLTextAreaElement>(*this); |
| 4774 | + if (!textArea) |
| 4775 | + return false; |
| 4776 | + |
| 4777 | + return !textArea->isDisabledFormControl(); |
| 4778 | + }; |
| 4779 | + |
| 4780 | + // `element` is an `editing host` or is `editable`. |
| 4781 | + |
| 4782 | + if (!isEligibleInputElement() && !isEligibleTextArea() && !hasEditableStyle()) |
| 4783 | + return false; |
| 4784 | + |
| 4785 | + // If `element` has an 'inclusive ancestor' with a `writingsuggestions` content attribute that's |
| 4786 | + // not in the `default` state and the nearest such ancestor's `writingsuggestions` content attribute |
| 4787 | + // is in the `false` state, then return `false`. |
| 4788 | + |
| 4789 | + for (auto* ancestor = this; ancestor; ancestor = ancestor->parentElementInComposedTree()) { |
| 4790 | + auto& value = ancestor->attributeWithoutSynchronization(HTMLNames::writingsuggestionsAttr); |
| 4791 | + |
| 4792 | + if (value.isNull()) |
| 4793 | + continue; |
| 4794 | + if (value.isEmpty() || equalLettersIgnoringASCIICase(value, "true"_s)) |
| 4795 | + return true; |
| 4796 | + if (equalLettersIgnoringASCIICase(value, "false"_s)) |
| 4797 | + return false; |
| 4798 | + } |
| 4799 | + |
| 4800 | + // Otherwise, return `true`. |
| 4801 | + return true; |
| 4802 | +} |
| 4803 | + |
4755 | 4804 | #if ASSERT_ENABLED
|
4756 | 4805 | bool Element::fastAttributeLookupAllowed(const QualifiedName& name) const
|
4757 | 4806 | {
|
|
0 commit comments