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

Side by Side Diff: third_party/WebKit/Source/core/events/EventTarget.cpp

Issue 2245723002: Support "once" event listener option (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Added forcing 'once' to be always defined." Created 4 years, 3 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 unified diff | Download patch
OLDNEW
1 /* 1 /*
2 * Copyright (C) 1999 Lars Knoll (knoll@kde.org) 2 * Copyright (C) 1999 Lars Knoll (knoll@kde.org)
3 * (C) 1999 Antti Koivisto (koivisto@kde.org) 3 * (C) 1999 Antti Koivisto (koivisto@kde.org)
4 * (C) 2001 Dirk Mueller (mueller@kde.org) 4 * (C) 2001 Dirk Mueller (mueller@kde.org)
5 * Copyright (C) 2004, 2005, 2006, 2007 Apple Inc. All rights reserved. 5 * Copyright (C) 2004, 2005, 2006, 2007 Apple Inc. All rights reserved.
6 * Copyright (C) 2006 Alexey Proskuryakov (ap@webkit.org) 6 * Copyright (C) 2006 Alexey Proskuryakov (ap@webkit.org)
7 * (C) 2007, 2008 Nikolas Zimmermann <zimmermann@kde.org> 7 * (C) 2007, 2008 Nikolas Zimmermann <zimmermann@kde.org>
8 * 8 *
9 * Redistribution and use in source and binary forms, with or without 9 * Redistribution and use in source and binary forms, with or without
10 * modification, are permitted provided that the following conditions 10 * modification, are permitted provided that the following conditions
(...skipping 592 matching lines...) Expand 10 before | Expand all | Expand 10 after
603 double blockedEventThreshold = blockedEventsWarningThreshold(context, event) ; 603 double blockedEventThreshold = blockedEventsWarningThreshold(context, event) ;
604 double now = 0.0; 604 double now = 0.0;
605 bool shouldReportBlockedEvent = false; 605 bool shouldReportBlockedEvent = false;
606 if (blockedEventThreshold) { 606 if (blockedEventThreshold) {
607 now = WTF::monotonicallyIncreasingTime(); 607 now = WTF::monotonicallyIncreasingTime();
608 shouldReportBlockedEvent = now - event->platformTimeStamp() > blockedEve ntThreshold; 608 shouldReportBlockedEvent = now - event->platformTimeStamp() > blockedEve ntThreshold;
609 } 609 }
610 bool firedListener = false; 610 bool firedListener = false;
611 611
612 while (i < size) { 612 while (i < size) {
613 RegisteredEventListener& registeredListener = entry[i]; 613 RegisteredEventListener registeredListener = entry[i];
614 614
615 // Move the iterator past this event listener. This must match 615 // Move the iterator past this event listener. This must match
616 // the handling of the FiringEventIterator::iterator in 616 // the handling of the FiringEventIterator::iterator in
617 // EventTarget::removeEventListener. 617 // EventTarget::removeEventListener.
618 ++i; 618 ++i;
619 619
620 if (event->eventPhase() == Event::kCapturingPhase && !registeredListener .capture()) 620 if (event->eventPhase() == Event::kCapturingPhase && !registeredListener .capture())
621 continue; 621 continue;
622 if (event->eventPhase() == Event::kBubblingPhase && registeredListener.c apture()) 622 if (event->eventPhase() == Event::kBubblingPhase && registeredListener.c apture())
623 continue; 623 continue;
624 624
625 EventListener* listener = registeredListener.listener();
626 // The listener will be retained by Member<EventListener> in the registe redListener,
627 // i and size are updated with the firing event iterator
628 // in case the listener is removed from the listener vector below.
629 if (registeredListener.once())
630 removeEventListener(event->type(), listener, registeredListener.capt ure());
631
625 // If stopImmediatePropagation has been called, we just break out immedi ately, without 632 // If stopImmediatePropagation has been called, we just break out immedi ately, without
626 // handling any more events on this target. 633 // handling any more events on this target.
627 if (event->immediatePropagationStopped()) 634 if (event->immediatePropagationStopped())
628 break; 635 break;
629 636
630 event->setHandlingPassive(registeredListener.passive()); 637 event->setHandlingPassive(registeredListener.passive());
631 bool passiveForced = registeredListener.passiveForcedForDocumentTarget() ; 638 bool passiveForced = registeredListener.passiveForcedForDocumentTarget() ;
632 639
633 InspectorInstrumentation::NativeBreakpoint nativeBreakpoint(context, thi s, event); 640 InspectorInstrumentation::NativeBreakpoint nativeBreakpoint(context, thi s, event);
634 641
635 EventListener* listener = registeredListener.listener();
636
637 // To match Mozilla, the AT_TARGET phase fires both capturing and bubbli ng 642 // To match Mozilla, the AT_TARGET phase fires both capturing and bubbli ng
638 // event listeners, even though that violates some versions of the DOM s pec. 643 // event listeners, even though that violates some versions of the DOM s pec.
639 listener->handleEvent(context, event); 644 listener->handleEvent(context, event);
640 firedListener = true; 645 firedListener = true;
641 646
642 // If we're about to report this event listener as blocking, make sure i t wasn't 647 // If we're about to report this event listener as blocking, make sure i t wasn't
643 // removed while handling the event. 648 // removed while handling the event.
644 if (shouldReportBlockedEvent && i > 0 && entry[i - 1].listener() == list ener 649 if (shouldReportBlockedEvent && i > 0 && entry[i - 1].listener() == list ener
645 && !entry[i - 1].passive() && !entry[i - 1].blockedEventWarningEmitt ed() && !event->defaultPrevented()) { 650 && !entry[i - 1].passive() && !entry[i - 1].blockedEventWarningEmitt ed() && !event->defaultPrevented()) {
646 reportBlockedEvent(context, event, &entry[i - 1], now - event->platf ormTimeStamp()); 651 reportBlockedEvent(context, event, &entry[i - 1], now - event->platf ormTimeStamp());
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
697 // they have one less listener to invoke. 702 // they have one less listener to invoke.
698 if (d->firingEventIterators) { 703 if (d->firingEventIterators) {
699 for (size_t i = 0; i < d->firingEventIterators->size(); ++i) { 704 for (size_t i = 0; i < d->firingEventIterators->size(); ++i) {
700 d->firingEventIterators->at(i).iterator = 0; 705 d->firingEventIterators->at(i).iterator = 0;
701 d->firingEventIterators->at(i).end = 0; 706 d->firingEventIterators->at(i).end = 0;
702 } 707 }
703 } 708 }
704 } 709 }
705 710
706 } // namespace blink 711 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698