Changeset 243954 in webkit
- Timestamp:
- Apr 5, 2019, 5:03:46 PM (7 years ago)
- Location:
- trunk/Source
- Files:
-
- 22 edited
-
WTF/ChangeLog (modified) (1 diff)
-
WTF/wtf/WeakHashSet.h (modified) (2 diffs)
-
WTF/wtf/WeakPtr.h (modified) (1 diff)
-
WebCore/ChangeLog (modified) (1 diff)
-
WebCore/dom/Element.h (modified) (1 diff)
-
WebCore/html/FormAssociatedElement.cpp (modified) (5 diffs)
-
WebCore/html/FormAssociatedElement.h (modified) (3 diffs)
-
WebCore/html/HTMLElement.cpp (modified) (1 diff)
-
WebCore/html/HTMLElement.h (modified) (2 diffs)
-
WebCore/html/HTMLFormControlElement.h (modified) (1 diff)
-
WebCore/html/HTMLFormControlsCollection.cpp (modified) (2 diffs)
-
WebCore/html/HTMLFormControlsCollection.h (modified) (1 diff)
-
WebCore/html/HTMLFormElement.cpp (modified) (5 diffs)
-
WebCore/html/HTMLFormElement.h (modified) (3 diffs)
-
WebCore/html/HTMLImageElement.cpp (modified) (3 diffs)
-
WebCore/html/HTMLImageElement.h (modified) (1 diff)
-
WebCore/html/HTMLInputElement.h (modified) (1 diff)
-
WebCore/html/HTMLMediaElement.h (modified) (1 diff)
-
WebCore/html/HTMLObjectElement.h (modified) (1 diff)
-
WebCore/html/HTMLPictureElement.h (modified) (1 diff)
-
WebCore/html/HTMLSlotElement.h (modified) (1 diff)
-
WebCore/svg/SVGElement.h (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
trunk/Source/WTF/ChangeLog
r243944 r243954 1 2019-04-05 Ryosuke Niwa <rniwa@webkit.org> 2 3 Make WeakPtr<Element> possible and deploy it in form associated elements code 4 https://bugs.webkit.org/show_bug.cgi?id=196626 5 6 Reviewed by Antti Koivisto. 7 8 Make it possible to call WeakHashSet::remove and WeakHashSet::contains with 9 a subclass type U of a type T used to define WeakReference<T>. 10 11 Also added computesEmpty, which is slightly more efficient than computeSize 12 when m_set is either empty or when there are non-released weak references in the set. 13 14 * wtf/WeakHashSet.h: 15 (WTF::WeakHashSet::remove): 16 (WTF::WeakHashSet::contains const): 17 (WTF::WeakHashSet::computesEmpty const): Added. 18 * wtf/WeakPtr.h: Added an explicit forward declaration of WeakHashSet to avoid 19 build failures in GTK+ and WPE ports. 20 1 21 2019-04-05 Eric Carlson <eric.carlson@apple.com> 2 22 -
trunk/Source/WTF/wtf/WeakHashSet.h
r243941 r243954 92 92 } 93 93 94 void remove(const T& value) 94 template <typename U> 95 bool remove(const U& value) 95 96 { 96 auto* weakReference = value.weakPtrFactory().m_ref.get();97 auto* weakReference = weak_reference_downcast<T>(value.weakPtrFactory().m_ref.get()); 97 98 if (!weakReference) 98 return ;99 m_set.remove(weakReference);99 return false; 100 return m_set.remove(weakReference); 100 101 } 101 102 102 bool contains(const T& value) const 103 template <typename U> 104 bool contains(const U& value) const 103 105 { 104 auto* weakReference = value.weakPtrFactory().m_ref.get();106 auto* weakReference = weak_reference_downcast<T>(value.weakPtrFactory().m_ref.get()); 105 107 if (!weakReference) 106 108 return false; … … 109 111 110 112 unsigned capacity() const { return m_set.capacity(); } 113 114 bool computesEmpty() const 115 { 116 if (m_set.isEmpty()) 117 return true; 118 for (auto& value : m_set) { 119 if (value->get()) 120 return false; 121 } 122 return true; 123 } 111 124 112 125 unsigned computeSize() const -
trunk/Source/WTF/wtf/WeakPtr.h
r242387 r243954 34 34 namespace WTF { 35 35 36 template<typename U> class WeakHashSet; 36 37 template<typename T> class WeakPtr; 37 38 template<typename T> class WeakPtrFactory; -
trunk/Source/WebCore/ChangeLog
r243943 r243954 1 2019-04-05 Ryosuke Niwa <rniwa@webkit.org> 2 3 Make WeakPtr<Element> possible and deploy it in form associated elements code 4 https://bugs.webkit.org/show_bug.cgi?id=196626 5 6 Reviewed by Antti Koivisto. 7 8 Make Element inherit from CanMakeWeakPtr and deploy WeakPtr<*Element> in FormAssociatedElement and HTMLFormElement. 9 10 No new tests sine there should be no behavioral change. 11 12 * dom/Element.h: 13 * html/FormAssociatedElement.cpp: 14 (WebCore::FormAssociatedElement::FormAssociatedElement): 15 (WebCore::FormAssociatedElement::insertedIntoAncestor): 16 (WebCore::FormAssociatedElement::setForm): 17 (WebCore::FormAssociatedElement::resetFormOwner): 18 (WebCore::FormAssociatedElement::formAttributeChanged): 19 * html/FormAssociatedElement.h: 20 (WebCore::FormAssociatedElement::form const): 21 * html/HTMLElement.cpp: 22 (WebCore::HTMLElement::asFormNamedItem): 23 (WebCore::HTMLElement::asFormAssociatedElement): 24 * html/HTMLElement.h: 25 (WebCore::HTMLElement::asFormNamedItem): Deleted. 26 * html/HTMLFormControlElement.h: 27 * html/HTMLFormControlsCollection.cpp: 28 (WebCore::HTMLFormControlsCollection::formImageElements const): Inlined into updateNamedElementCache. 29 (WebCore::HTMLFormControlsCollection::updateNamedElementCache const): 30 * html/HTMLFormControlsCollection.h: 31 * html/HTMLFormElement.cpp: 32 (WebCore::HTMLFormElement::registerInvalidAssociatedFormControl): 33 (WebCore::HTMLFormElement::removeInvalidAssociatedFormControlIfNeeded): 34 (WebCore::HTMLFormElement::registerImgElement): 35 (WebCore::HTMLFormElement::defaultButton const): 36 (WebCore::HTMLFormElement::resetDefaultButton): 37 (WebCore::HTMLFormElement::matchesValidPseudoClass const): 38 (WebCore::HTMLFormElement::matchesInvalidPseudoClass const): 39 * html/HTMLFormElement.h: 40 * html/HTMLImageElement.cpp: 41 (WebCore::HTMLImageElement::HTMLImageElement): 42 (WebCore::HTMLImageElement::insertedIntoAncestor): 43 * html/HTMLImageElement.h: 44 * html/HTMLInputElement.h: 45 * html/HTMLMediaElement.h: 46 * html/HTMLObjectElement.h: 47 * html/HTMLPictureElement.h: 48 * html/HTMLSlotElement.h: 49 * svg/SVGElement.h: 50 1 51 2019-04-05 Caitlin Potter <caitp@igalia.com> 2 52 -
trunk/Source/WebCore/dom/Element.h
r243941 r243954 78 78 #endif 79 79 80 class Element : public ContainerNode {80 class Element : public ContainerNode , public CanMakeWeakPtr<Element> { 81 81 WTF_MAKE_ISO_ALLOCATED(Element); 82 82 public: -
trunk/Source/WebCore/html/FormAssociatedElement.cpp
r243941 r243954 53 53 FormAssociatedElement::FormAssociatedElement(HTMLFormElement* form) 54 54 : m_form(nullptr) 55 , m_formSetByParser( form)55 , m_formSetByParser(makeWeakPtr(form)) 56 56 { 57 57 } … … 75 75 // The form could have been removed by a script during parsing. 76 76 if (m_formSetByParser->isConnected()) 77 setForm(m_formSetByParser );77 setForm(m_formSetByParser.get()); 78 78 m_formSetByParser = nullptr; 79 79 } … … 147 147 if (m_form) 148 148 m_form->removeFormElement(this); 149 m_form = newForm;150 if ( m_form)151 m_form->registerFormElement(this);149 m_form = makeWeakPtr(newForm); 150 if (newForm) 151 newForm->registerFormElement(this); 152 152 didChangeForm(); 153 153 } … … 173 173 void FormAssociatedElement::resetFormOwner() 174 174 { 175 RefPtr<HTMLFormElement> originalForm = m_form ;176 setForm(findAssociatedForm(&asHTMLElement(), m_form));175 RefPtr<HTMLFormElement> originalForm = m_form.get(); 176 setForm(findAssociatedForm(&asHTMLElement(), originalForm.get())); 177 177 HTMLElement& element = asHTMLElement(); 178 if (m_form && m_form != originalForm && m_form->isConnected()) 178 auto* newForm = m_form.get(); 179 if (newForm && newForm != originalForm && newForm->isConnected()) 179 180 element.document().didAssociateFormControl(element); 180 181 } … … 185 186 if (!element.hasAttributeWithoutSynchronization(formAttr)) { 186 187 // The form attribute removed. We need to reset form owner here. 187 RefPtr<HTMLFormElement> originalForm = m_form; 188 RefPtr<HTMLFormElement> originalForm = m_form.get(); 189 // FIXME: Why does this not pass originalForm to findClosestFormAncestor? 188 190 setForm(HTMLFormElement::findClosestFormAncestor(element)); 189 if (m_form && m_form != originalForm && m_form->isConnected()) 191 auto* newForm = m_form.get(); 192 if (newForm && newForm != originalForm && newForm->isConnected()) 190 193 element.document().didAssociateFormControl(element); 191 194 m_formAttributeTargetObserver = nullptr; -
trunk/Source/WebCore/html/FormAssociatedElement.h
r243941 r243954 26 26 #include "FormNamedItem.h" 27 27 #include "Node.h" 28 #include <wtf/WeakPtr.h> 28 29 #include <wtf/text/WTFString.h> 29 30 … … 48 49 49 50 static HTMLFormElement* findAssociatedForm(const HTMLElement*, HTMLFormElement*); 50 HTMLFormElement* form() const { return m_form ; }51 HTMLFormElement* form() const { return m_form.get(); } 51 52 ValidityState* validity(); 52 53 … … 118 119 119 120 std::unique_ptr<FormAttributeTargetObserver> m_formAttributeTargetObserver; 120 HTMLFormElement*m_form;121 HTMLFormElement*m_formSetByParser;121 WeakPtr<HTMLFormElement> m_form; 122 WeakPtr<HTMLFormElement> m_formSetByParser; 122 123 String m_customValidationMessage; 123 124 }; -
trunk/Source/WebCore/html/HTMLElement.cpp
r243941 r243954 763 763 } 764 764 765 FormNamedItem* HTMLElement::asFormNamedItem() 766 { 767 return nullptr; 768 } 769 770 FormAssociatedElement* HTMLElement::asFormAssociatedElement() 771 { 772 return nullptr; 773 } 774 765 775 static inline bool elementAffectsDirectionality(const Node& node) 766 776 { -
trunk/Source/WebCore/html/HTMLElement.h
r243941 r243954 33 33 34 34 class DocumentFragment; 35 class FormAssociatedElement; 35 36 class FormNamedItem; 36 37 class HTMLCollection; … … 89 90 90 91 virtual bool isLabelable() const { return false; } 91 virtual FormNamedItem* asFormNamedItem() { return 0; } 92 virtual FormNamedItem* asFormNamedItem(); 93 virtual FormAssociatedElement* asFormAssociatedElement(); 92 94 93 95 bool hasTagName(const HTMLQualifiedName& name) const { return hasLocalName(name.localName()); } -
trunk/Source/WebCore/html/HTMLFormControlElement.h
r243941 r243954 176 176 HTMLElement& asHTMLElement() final { return *this; } 177 177 const HTMLFormControlElement& asHTMLElement() const final { return *this; } 178 HTMLFormControlElement* asFormNamedItem() final { return this; } 178 FormNamedItem* asFormNamedItem() final { return this; } 179 FormAssociatedElement* asFormAssociatedElement() final { return this; } 179 180 180 181 bool needsMouseFocusableQuirk() const; -
trunk/Source/WebCore/html/HTMLFormControlsCollection.cpp
r243941 r243954 76 76 } 77 77 78 const Vector<HTMLImageElement*>& HTMLFormControlsCollection::formImageElements() const79 {80 return ownerNode().imageElements();81 }82 83 78 static unsigned findFormAssociatedElement(const Vector<FormAssociatedElement*>& elements, const Element& element) 84 79 { … … 146 141 } 147 142 148 for (auto* elementPtr : formImageElements()) { 143 for (auto& elementPtr : ownerNode().imageElements()) { 144 if (!elementPtr) 145 continue; 149 146 HTMLImageElement& element = *elementPtr; 150 147 const AtomicString& id = element.getIdAttribute(); -
trunk/Source/WebCore/html/HTMLFormControlsCollection.h
r243941 r243954 57 57 const Vector<FormAssociatedElement*>& unsafeFormControlElements() const; 58 58 Vector<Ref<FormAssociatedElement>> copyFormControlElementsVector() const; 59 const Vector<HTMLImageElement*>& formImageElements() const;60 59 61 60 mutable Element* m_cachedElement; -
trunk/Source/WebCore/html/HTMLFormElement.cpp
r243941 r243954 567 567 ASSERT(static_cast<const Element&>(formControlElement).matchesInvalidPseudoClass()); 568 568 569 if (m_invalidAssociatedFormControls. isEmpty())569 if (m_invalidAssociatedFormControls.computesEmpty()) 570 570 invalidateStyleForSubtree(); 571 m_invalidAssociatedFormControls.add( &formControlElement);571 m_invalidAssociatedFormControls.add(const_cast<HTMLFormControlElement&>(formControlElement)); 572 572 } 573 573 574 574 void HTMLFormElement::removeInvalidAssociatedFormControlIfNeeded(const HTMLFormControlElement& formControlElement) 575 575 { 576 if (m_invalidAssociatedFormControls.remove( &formControlElement)) {577 if (m_invalidAssociatedFormControls. isEmpty())576 if (m_invalidAssociatedFormControls.remove(formControlElement)) { 577 if (m_invalidAssociatedFormControls.computesEmpty()) 578 578 invalidateStyleForSubtree(); 579 579 } … … 588 588 { 589 589 ASSERT(m_imageElements.find(e) == notFound); 590 m_imageElements.append( e);590 m_imageElements.append(makeWeakPtr(e)); 591 591 } 592 592 … … 682 682 HTMLFormControlElement* HTMLFormElement::defaultButton() const 683 683 { 684 if ( !m_defaultButton) {685 for (auto& associatedElement : m_associatedElements) {686 if (!is<HTMLFormControlElement>(*associatedElement))687 continue;688 HTMLFormControlElement& control = downcast<HTMLFormControlElement>(*associatedElement);689 if (control.isSuccessfulSubmitButton()) {690 m_defaultButton = &control;691 break;692 }684 if (m_defaultButton) 685 return m_defaultButton.get(); 686 for (auto& associatedElement : m_associatedElements) { 687 if (!is<HTMLFormControlElement>(*associatedElement)) 688 continue; 689 HTMLFormControlElement& control = downcast<HTMLFormControlElement>(*associatedElement); 690 if (control.isSuccessfulSubmitButton()) { 691 m_defaultButton = makeWeakPtr(control); 692 return &control; 693 693 } 694 694 } 695 return m_defaultButton;695 return nullptr; 696 696 } 697 697 … … 707 707 ScriptDisallowedScope::InMainThread scriptDisallowedScope; 708 708 709 auto* oldDefault = m_defaultButton; 710 m_defaultButton = nullptr; 709 auto oldDefault = WTFMove(m_defaultButton); 711 710 defaultButton(); 712 711 if (m_defaultButton != oldDefault) { … … 811 810 bool HTMLFormElement::matchesValidPseudoClass() const 812 811 { 813 return m_invalidAssociatedFormControls. isEmpty();812 return m_invalidAssociatedFormControls.computesEmpty(); 814 813 } 815 814 816 815 bool HTMLFormElement::matchesInvalidPseudoClass() const 817 816 { 818 return !m _invalidAssociatedFormControls.isEmpty();817 return !matchesValidPseudoClass(); 819 818 } 820 819 -
trunk/Source/WebCore/html/HTMLFormElement.h
r243941 r243954 30 30 #include <memory> 31 31 #include <wtf/IsoMalloc.h> 32 #include <wtf/WeakHashSet.h> 32 33 33 34 #if ENABLE(IOS_AUTOCORRECT_AND_AUTOCAPITALIZE) … … 121 122 WEBCORE_EXPORT const Vector<FormAssociatedElement*>& unsafeAssociatedElements() const; 122 123 Vector<Ref<FormAssociatedElement>> copyAssociatedElementsVector() const; 123 const Vector< HTMLImageElement*>& imageElements() const { return m_imageElements; }124 const Vector<WeakPtr<HTMLImageElement>>& imageElements() const { return m_imageElements; } 124 125 125 126 StringPairVector textFieldValues() const; … … 174 175 175 176 RadioButtonGroups m_radioButtonGroups; 176 mutable HTMLFormControlElement* m_defaultButton { nullptr };177 mutable WeakPtr<HTMLFormControlElement> m_defaultButton; 177 178 178 179 unsigned m_associatedElementsBeforeIndex { 0 }; 179 180 unsigned m_associatedElementsAfterIndex { 0 }; 180 181 Vector<FormAssociatedElement*> m_associatedElements; 181 Vector< HTMLImageElement*> m_imageElements;182 HashSet<const HTMLFormControlElement*> m_invalidAssociatedFormControls;182 Vector<WeakPtr<HTMLImageElement>> m_imageElements; 183 WeakHashSet<HTMLFormControlElement> m_invalidAssociatedFormControls; 183 184 184 185 bool m_wasUserSubmitted { false }; -
trunk/Source/WebCore/html/HTMLImageElement.cpp
r243941 r243954 72 72 , m_imageLoader(*this) 73 73 , m_form(nullptr) 74 , m_formSetByParser( form)74 , m_formSetByParser(makeWeakPtr(form)) 75 75 , m_compositeOperator(CompositeSourceOver) 76 76 , m_imageDevicePixelRatio(1.0f) … … 331 331 { 332 332 if (m_formSetByParser) { 333 m_form = m_formSetByParser; 334 m_formSetByParser = nullptr; 333 m_form = WTFMove(m_formSetByParser); 335 334 m_form->registerImgElement(this); 336 335 } … … 342 341 343 342 if (!m_form) { 344 m_form = HTMLFormElement::findClosestFormAncestor(*this); 345 if (m_form) 346 m_form->registerImgElement(this); 343 if (auto* newForm = HTMLFormElement::findClosestFormAncestor(*this)) { 344 m_form = makeWeakPtr(newForm); 345 newForm->registerImgElement(this); 346 } 347 347 } 348 348 -
trunk/Source/WebCore/html/HTMLImageElement.h
r243941 r243954 174 174 175 175 HTMLImageLoader m_imageLoader; 176 HTMLFormElement*m_form;177 HTMLFormElement*m_formSetByParser;176 WeakPtr<HTMLFormElement> m_form; 177 WeakPtr<HTMLFormElement> m_formSetByParser; 178 178 179 179 CompositeOperator m_compositeOperator; -
trunk/Source/WebCore/html/HTMLInputElement.h
r243941 r243954 55 55 }; 56 56 57 class HTMLInputElement : public HTMLTextFormControlElement , public CanMakeWeakPtr<HTMLInputElement>{57 class HTMLInputElement : public HTMLTextFormControlElement { 58 58 WTF_MAKE_ISO_ALLOCATED(HTMLInputElement); 59 59 public: -
trunk/Source/WebCore/html/HTMLMediaElement.h
r243941 r243954 127 127 , public ActiveDOMObject 128 128 , public MediaControllerInterface 129 , public CanMakeWeakPtr<HTMLMediaElement>130 129 , public PlatformMediaSessionClient 131 130 , private MediaCanStartListener -
trunk/Source/WebCore/html/HTMLObjectElement.h
r243941 r243954 92 92 93 93 FormNamedItem* asFormNamedItem() final { return this; } 94 FormAssociatedElement* asFormAssociatedElement() final { return this; } 94 95 HTMLObjectElement& asHTMLElement() final { return *this; } 95 96 const HTMLObjectElement& asHTMLElement() const final { return *this; } -
trunk/Source/WebCore/html/HTMLPictureElement.h
r243941 r243954 31 31 namespace WebCore { 32 32 33 class HTMLPictureElement final : public HTMLElement , public CanMakeWeakPtr<HTMLPictureElement>{33 class HTMLPictureElement final : public HTMLElement { 34 34 WTF_MAKE_ISO_ALLOCATED(HTMLPictureElement); 35 35 public: -
trunk/Source/WebCore/html/HTMLSlotElement.h
r243941 r243954 31 31 namespace WebCore { 32 32 33 class HTMLSlotElement final : public HTMLElement , public CanMakeWeakPtr<HTMLSlotElement>{33 class HTMLSlotElement final : public HTMLElement { 34 34 WTF_MAKE_ISO_ALLOCATED(HTMLSlotElement); 35 35 public: -
trunk/Source/WebCore/svg/SVGElement.h
r243941 r243954 48 48 void mapAttributeToCSSProperty(HashMap<AtomicStringImpl*, CSSPropertyID>* propertyNameToIdMap, const QualifiedName& attrName); 49 49 50 class SVGElement : public StyledElement, public SVGLangSpace, public SVGPropertyOwner , public CanMakeWeakPtr<SVGElement>{50 class SVGElement : public StyledElement, public SVGLangSpace, public SVGPropertyOwner { 51 51 WTF_MAKE_ISO_ALLOCATED(SVGElement); 52 52 public:
Note:
See TracChangeset
for help on using the changeset viewer.