Changeset 287802 in webkit
- Timestamp:
- Jan 7, 2022, 6:13:46 PM (5 years ago)
- Location:
- trunk/Source/WebCore
- Files:
-
- 5 edited
-
ChangeLog (modified) (1 diff)
-
dom/Document.cpp (modified) (3 diffs)
-
dom/Document.h (modified) (1 diff)
-
dom/Element.cpp (modified) (1 diff)
-
dom/Element.h (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
trunk/Source/WebCore/ChangeLog
r287787 r287802 1 2022-01-07 Alexey Shvayka <ashvayka@apple.com> 2 3 Don't dispatch "focusin" / "focusout" events if there are no listeners 4 https://bugs.webkit.org/show_bug.cgi?id=234928 5 6 Reviewed by Geoff Garen. 7 8 This patch avoids creating and dispatching "focusin" / "focusout" events if it's 9 guaranteed there are no registered listeners for them. These events are rather new 10 and not widely popular: according to Chrome stats, only 17% page loads use them [1], 11 which is even less than `document.all`. 12 13 Together with r287787, creation of four FocusEvent instances is now avoided when 14 focus is changed, advancing attached microbenchmark by 6%. 15 16 [1] https://chromestatus.com/metrics/feature/timeline/popularity/433 17 18 No new tests, no behavior change. 19 20 * dom/Document.cpp: 21 (WebCore::Document::setFocusedElement): 22 (WebCore::Document::addListenerTypeIfNeeded): 23 * dom/Document.h: 24 * dom/Element.cpp: 25 (WebCore::Element::dispatchFocusInEventIfNeeded): 26 (WebCore::Element::dispatchFocusOutEventIfNeeded): 27 (WebCore::Element::dispatchFocusInEvent): Deleted. 28 (WebCore::Element::dispatchFocusOutEvent): Deleted. 29 * dom/Element.h: 30 1 31 2022-01-07 Alexey Shvayka <ashvayka@apple.com> 2 32 -
trunk/Source/WebCore/dom/Document.cpp
r287787 r287802 4659 4659 } 4660 4660 4661 oldFocusedElement->dispatchFocusOutEvent (newFocusedElement.copyRef()); // DOM level 3 bubbling blur event.4661 oldFocusedElement->dispatchFocusOutEventIfNeeded(newFocusedElement.copyRef()); // DOM level 3 bubbling blur event. 4662 4662 4663 4663 if (m_focusedElement) { … … 4724 4724 } 4725 4725 4726 m_focusedElement->dispatchFocusInEvent (oldFocusedElement.copyRef()); // DOM level 3 bubbling focus event.4726 m_focusedElement->dispatchFocusInEventIfNeeded(oldFocusedElement.copyRef()); // DOM level 3 bubbling focus event. 4727 4727 4728 4728 if (m_focusedElement != newFocusedElement) { … … 5286 5286 else if (eventType == eventNames().resizeEvent) 5287 5287 addListenerType(RESIZE_LISTENER); 5288 else if (eventType == eventNames().focusinEvent) 5289 addListenerType(FOCUSIN_LISTENER); 5290 else if (eventType == eventNames().focusoutEvent) 5291 addListenerType(FOCUSOUT_LISTENER); 5288 5292 } 5289 5293 -
trunk/Source/WebCore/dom/Document.h
r287707 r287802 907 907 FORCEDOWN_LISTENER = 1 << 15, 908 908 FORCEUP_LISTENER = 1 << 16, 909 RESIZE_LISTENER = 1 << 17 909 RESIZE_LISTENER = 1 << 17, 910 FOCUSIN_LISTENER = 1 << 18, 911 FOCUSOUT_LISTENER = 1 << 19, 910 912 }; 911 913 -
trunk/Source/WebCore/dom/Element.cpp
r287787 r287802 3183 3183 } 3184 3184 3185 void Element::dispatchFocusInEvent(RefPtr<Element>&& oldFocusedElement) 3186 { 3185 void Element::dispatchFocusInEventIfNeeded(RefPtr<Element>&& oldFocusedElement) 3186 { 3187 if (!document().hasListenerType(Document::FOCUSIN_LISTENER)) 3188 return; 3187 3189 RELEASE_ASSERT_WITH_SECURITY_IMPLICATION(ScriptDisallowedScope::InMainThread::isScriptAllowed() || !isInWebProcess()); 3188 3190 dispatchScopedEvent(FocusEvent::create(eventNames().focusinEvent, Event::CanBubble::Yes, Event::IsCancelable::No, document().windowProxy(), 0, WTFMove(oldFocusedElement))); 3189 3191 } 3190 3192 3191 void Element::dispatchFocusOutEvent(RefPtr<Element>&& newFocusedElement) 3192 { 3193 void Element::dispatchFocusOutEventIfNeeded(RefPtr<Element>&& newFocusedElement) 3194 { 3195 if (!document().hasListenerType(Document::FOCUSOUT_LISTENER)) 3196 return; 3193 3197 RELEASE_ASSERT_WITH_SECURITY_IMPLICATION(ScriptDisallowedScope::InMainThread::isScriptAllowed() || !isInWebProcess()); 3194 3198 dispatchScopedEvent(FocusEvent::create(eventNames().focusoutEvent, Event::CanBubble::Yes, Event::IsCancelable::No, document().windowProxy(), 0, WTFMove(newFocusedElement))); -
trunk/Source/WebCore/dom/Element.h
r287787 r287802 572 572 573 573 // FIXME: Consider changing signature to accept Element* because all callers perform copyRef(). 574 void dispatchFocusInEvent (RefPtr<Element>&& oldFocusedElement);575 void dispatchFocusOutEvent (RefPtr<Element>&& newFocusedElement);574 void dispatchFocusInEventIfNeeded(RefPtr<Element>&& oldFocusedElement); 575 void dispatchFocusOutEventIfNeeded(RefPtr<Element>&& newFocusedElement); 576 576 virtual void dispatchFocusEvent(RefPtr<Element>&& oldFocusedElement, FocusDirection); 577 577 virtual void dispatchBlurEvent(RefPtr<Element>&& newFocusedElement);
Note:
See TracChangeset
for help on using the changeset viewer.