Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(447)

Unified Diff: third_party/WebKit/Source/core/events/EventTarget.cpp

Issue 2205523004: Refactored UseCounter code for event-listener-firing. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Added a TODO for the suspicious |if|. Created 4 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « third_party/WebKit/Source/core/events/EventTarget.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: third_party/WebKit/Source/core/events/EventTarget.cpp
diff --git a/third_party/WebKit/Source/core/events/EventTarget.cpp b/third_party/WebKit/Source/core/events/EventTarget.cpp
index 6cdf0e1161aa15f9079046976c71436abc773a56..90bcd0ac657c8161af92f62be2d2ff3a033f9a16 100644
--- a/third_party/WebKit/Source/core/events/EventTarget.cpp
+++ b/third_party/WebKit/Source/core/events/EventTarget.cpp
@@ -545,6 +545,17 @@ DispatchEventResult EventTarget::fireEventListeners(Event* event)
return dispatchEventResult(*event);
}
+bool EventTarget::checkTypeThenUseCount(
+ const Event* event, const AtomicString& eventTypeToCount, const UseCounter::Feature feature)
+{
+ if (event->type() == eventTypeToCount) {
+ if (LocalDOMWindow* executingWindow = this->executingWindow())
+ UseCounter::count(executingWindow->document(), feature);
+ return true;
+ }
+ return false;
+}
+
bool EventTarget::fireEventListeners(Event* event, EventTargetData* d, EventListenerVector& entry)
{
// Fire all listeners registered for this event. Don't fire listeners removed
@@ -552,38 +563,25 @@ bool EventTarget::fireEventListeners(Event* event, EventTargetData* d, EventList
// dispatch. Conveniently, all new event listeners will be added after or at
// index |size|, so iterating up to (but not including) |size| naturally excludes
// new event listeners.
- //
- // TODO(mustaq): This code needs to be refactored, crbug.com/629601
- if (event->type() == EventTypeNames::beforeunload) {
+ if (checkTypeThenUseCount(event, EventTypeNames::beforeunload, UseCounter::DocumentBeforeUnloadFired)) {
if (LocalDOMWindow* executingWindow = this->executingWindow()) {
+ // TODO(mustaq): Is the |if| condition correct? crbug.com/635029
if (executingWindow->top())
UseCounter::count(executingWindow->document(), UseCounter::SubFrameBeforeUnloadFired);
- UseCounter::count(executingWindow->document(), UseCounter::DocumentBeforeUnloadFired);
}
- } else if (event->type() == EventTypeNames::unload) {
- if (LocalDOMWindow* executingWindow = this->executingWindow())
- UseCounter::count(executingWindow->document(), UseCounter::DocumentUnloadFired);
- } else if (event->type() == EventTypeNames::DOMFocusIn || event->type() == EventTypeNames::DOMFocusOut) {
- if (LocalDOMWindow* executingWindow = this->executingWindow())
- UseCounter::count(executingWindow->document(), UseCounter::DOMFocusInOutEvent);
- } else if (event->type() == EventTypeNames::focusin || event->type() == EventTypeNames::focusout) {
- if (LocalDOMWindow* executingWindow = this->executingWindow())
- UseCounter::count(executingWindow->document(), UseCounter::FocusInOutEvent);
- } else if (event->type() == EventTypeNames::textInput) {
- if (LocalDOMWindow* executingWindow = this->executingWindow())
- UseCounter::count(executingWindow->document(), UseCounter::TextInputFired);
- } else if (event->type() == EventTypeNames::touchstart) {
- if (LocalDOMWindow* executingWindow = this->executingWindow())
- UseCounter::count(executingWindow->document(), UseCounter::TouchStartFired);
- } else if (event->type() == EventTypeNames::mousedown) {
- if (LocalDOMWindow* executingWindow = this->executingWindow())
- UseCounter::count(executingWindow->document(), UseCounter::MouseDownFired);
- } else if (event->type() == EventTypeNames::pointerdown) {
+ } else if (checkTypeThenUseCount(event, EventTypeNames::unload, UseCounter::DocumentUnloadFired)) {
+ } else if (checkTypeThenUseCount(event, EventTypeNames::DOMFocusIn, UseCounter::DOMFocusInOutEvent)) {
+ } else if (checkTypeThenUseCount(event, EventTypeNames::DOMFocusOut, UseCounter::DOMFocusInOutEvent)) {
+ } else if (checkTypeThenUseCount(event, EventTypeNames::focusin, UseCounter::FocusInOutEvent)) {
+ } else if (checkTypeThenUseCount(event, EventTypeNames::focusout, UseCounter::FocusInOutEvent)) {
+ } else if (checkTypeThenUseCount(event, EventTypeNames::textInput, UseCounter::TextInputFired)) {
+ } else if (checkTypeThenUseCount(event, EventTypeNames::touchstart, UseCounter::TouchStartFired)) {
+ } else if (checkTypeThenUseCount(event, EventTypeNames::mousedown, UseCounter::MouseDownFired)) {
+ } else if (checkTypeThenUseCount(event, EventTypeNames::pointerdown, UseCounter::PointerDownFired)) {
if (LocalDOMWindow* executingWindow = this->executingWindow()) {
- if (event->isPointerEvent() && static_cast<PointerEvent*>(event)->pointerType() == "touch")
+ if (static_cast<PointerEvent*>(event)->pointerType() == "touch")
UseCounter::count(executingWindow->document(), UseCounter::PointerDownFiredForTouch);
- UseCounter::count(executingWindow->document(), UseCounter::PointerDownFired);
}
}
« no previous file with comments | « third_party/WebKit/Source/core/events/EventTarget.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698