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

Side by Side Diff: Source/core/dom/WheelController.cpp

Issue 206603002: Add EventHandlerRegistry (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Refactoring WIP. Created 6 years, 9 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
(Empty)
1 /*
2 * Copyright (C) 2013 Google, Inc. All rights reserved.
3 *
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
6 * are met:
7 * * Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.
9 * * Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution.
12 *
13 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ``AS IS'' AND ANY
14 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
15 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
16 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
17 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
18 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
19 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
20 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
21 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
22 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
23 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
24 */
25
26 #include "config.h"
27 #include "core/dom/WheelController.h"
28
29 #include "core/dom/Document.h"
30 #include "core/events/ThreadLocalEventNames.h"
31 #include "core/events/WheelEvent.h"
32 #include "core/frame/LocalFrame.h"
33 #include "core/page/Page.h"
34 #include "core/page/scrolling/ScrollingCoordinator.h"
35
36 namespace WebCore {
37
38 WheelController::WheelController(Document& document)
39 : DOMWindowLifecycleObserver(document.domWindow())
40 , m_wheelEventHandlerCount(0)
41 {
42 }
43
44 WheelController::~WheelController()
45 {
46 }
47
48 const char* WheelController::supplementName()
49 {
50 return "WheelController";
51 }
52
53 WheelController* WheelController::from(Document& document)
54 {
55 WheelController* controller = static_cast<WheelController*>(DocumentSuppleme nt::from(document, supplementName()));
56 if (!controller) {
57 controller = new WheelController(document);
58 DocumentSupplement::provideTo(document, supplementName(), adoptPtr(contr oller));
59 }
60 return controller;
61 }
62
63 static void wheelEventHandlerCountChanged(Document& document)
64 {
65 Page* page = document.page();
66 if (!page)
67 return;
68
69 ScrollingCoordinator* scrollingCoordinator = page->scrollingCoordinator();
70 if (!scrollingCoordinator)
71 return;
72
73 FrameView* frameView = document.view();
74 if (!frameView)
75 return;
76
77 scrollingCoordinator->frameViewWheelEventHandlerCountChanged(frameView);
78 }
79
80 void WheelController::didAddWheelEventHandler(Document& document)
81 {
82 ++m_wheelEventHandlerCount;
83 Page* page = document.page();
84 LocalFrame* mainFrame = page ? page->mainFrame() : 0;
85 if (mainFrame)
86 mainFrame->notifyChromeClientWheelEventHandlerCountChanged();
87
88 wheelEventHandlerCountChanged(document);
89 }
90
91 void WheelController::didRemoveWheelEventHandler(Document& document)
92 {
93 ASSERT(m_wheelEventHandlerCount > 0);
94 --m_wheelEventHandlerCount;
95 Page* page = document.page();
96 LocalFrame* mainFrame = page ? page->mainFrame() : 0;
97 if (mainFrame)
98 mainFrame->notifyChromeClientWheelEventHandlerCountChanged();
99
100 wheelEventHandlerCountChanged(document);
101 }
102
103 void WheelController::didAddEventListener(DOMWindow* window, const AtomicString& eventType)
104 {
105 if (eventType != EventTypeNames::wheel && eventType != EventTypeNames::mouse wheel)
106 return;
107
108 Document* document = window->document();
109 ASSERT(document);
110 didAddWheelEventHandler(*document);
111 }
112
113 void WheelController::didRemoveEventListener(DOMWindow* window, const AtomicStri ng& eventType)
114 {
115 if (eventType != EventTypeNames::wheel && eventType != EventTypeNames::mouse wheel)
116 return;
117
118 Document* document = window->document();
119 ASSERT(document);
120 didRemoveWheelEventHandler(*document);
121 }
122
123 } // namespace WebCore
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698