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

Side by Side Diff: third_party/WebKit/Source/core/input/KeyboardEventManager.cpp

Issue 2255323004: Create MouseEventManager and EventHandlingUtil (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebasing 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 // Copyright 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "KeyboardEventManager.h" 5 #include "KeyboardEventManager.h"
6 6
7 #include "core/dom/Element.h" 7 #include "core/dom/Element.h"
8 #include "core/editing/Editor.h" 8 #include "core/editing/Editor.h"
9 #include "core/events/KeyboardEvent.h" 9 #include "core/events/KeyboardEvent.h"
10 #include "core/html/HTMLDialogElement.h" 10 #include "core/html/HTMLDialogElement.h"
11 #include "core/input/EventHandler.h" 11 #include "core/input/EventHandlingUtil.h"
12 #include "core/input/ScrollManager.h"
12 #include "core/layout/LayoutObject.h" 13 #include "core/layout/LayoutObject.h"
13 #include "core/layout/LayoutTextControlSingleLine.h" 14 #include "core/layout/LayoutTextControlSingleLine.h"
14 #include "core/loader/FrameLoaderClient.h" 15 #include "core/loader/FrameLoaderClient.h"
15 #include "core/page/ChromeClient.h" 16 #include "core/page/ChromeClient.h"
16 #include "core/page/FocusController.h" 17 #include "core/page/FocusController.h"
17 #include "core/page/Page.h" 18 #include "core/page/Page.h"
18 #include "core/page/SpatialNavigation.h" 19 #include "core/page/SpatialNavigation.h"
19 #include "platform/UserGestureIndicator.h" 20 #include "platform/UserGestureIndicator.h"
20 #include "platform/WindowsKeyboardCodes.h" 21 #include "platform/WindowsKeyboardCodes.h"
21 #include "public/platform/WebInputEvent.h" 22 #include "public/platform/WebInputEvent.h"
(...skipping 30 matching lines...) Expand all
52 53
53 } // namespace 54 } // namespace
54 55
55 KeyboardEventManager::KeyboardEventManager( 56 KeyboardEventManager::KeyboardEventManager(
56 LocalFrame* frame, ScrollManager* scrollManager) 57 LocalFrame* frame, ScrollManager* scrollManager)
57 : m_frame(frame) 58 : m_frame(frame)
58 , m_scrollManager(scrollManager) 59 , m_scrollManager(scrollManager)
59 { 60 {
60 } 61 }
61 62
62 KeyboardEventManager::~KeyboardEventManager()
63 {
64 }
65
66 bool KeyboardEventManager::handleAccessKey(const WebKeyboardEvent& evt) 63 bool KeyboardEventManager::handleAccessKey(const WebKeyboardEvent& evt)
67 { 64 {
68 // FIXME: Ignoring the state of Shift key is what neither IE nor Firefox do. 65 // FIXME: Ignoring the state of Shift key is what neither IE nor Firefox do.
69 // IE matches lower and upper case access keys regardless of Shift key state - but if both upper and 66 // IE matches lower and upper case access keys regardless of Shift key state - but if both upper and
70 // lower case variants are present in a document, the correct element is mat ched based on Shift key state. 67 // lower case variants are present in a document, the correct element is mat ched based on Shift key state.
71 // Firefox only matches an access key if Shift is not pressed, and does that case-insensitively. 68 // Firefox only matches an access key if Shift is not pressed, and does that case-insensitively.
72 DCHECK(!(kAccessKeyModifiers & WebInputEvent::ShiftKey)); 69 DCHECK(!(kAccessKeyModifiers & WebInputEvent::ShiftKey));
73 if ((evt.modifiers & (WebKeyboardEvent::KeyModifiers & ~WebInputEvent::Shift Key)) != kAccessKeyModifiers) 70 if ((evt.modifiers & (WebKeyboardEvent::KeyModifiers & ~WebInputEvent::Shift Key)) != kAccessKeyModifiers)
74 return false; 71 return false;
75 String key = String(evt.unmodifiedText); 72 String key = String(evt.unmodifiedText);
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
113 // On Windows, WebKit explicitly calls handleAccessKey() instead of dispatch ing a keypress event for WM_SYSCHAR messages. 110 // On Windows, WebKit explicitly calls handleAccessKey() instead of dispatch ing a keypress event for WM_SYSCHAR messages.
114 // Other platforms currently match either Mac or Windows behavior, depending on whether they send combined KeyDown events. 111 // Other platforms currently match either Mac or Windows behavior, depending on whether they send combined KeyDown events.
115 bool matchedAnAccessKey = false; 112 bool matchedAnAccessKey = false;
116 if (initialKeyEvent.type == WebInputEvent::KeyDown) 113 if (initialKeyEvent.type == WebInputEvent::KeyDown)
117 matchedAnAccessKey = handleAccessKey(initialKeyEvent); 114 matchedAnAccessKey = handleAccessKey(initialKeyEvent);
118 115
119 // FIXME: it would be fair to let an input method handle KeyUp events before DOM dispatch. 116 // FIXME: it would be fair to let an input method handle KeyUp events before DOM dispatch.
120 if (initialKeyEvent.type == WebInputEvent::KeyUp || initialKeyEvent.type == WebInputEvent::Char) { 117 if (initialKeyEvent.type == WebInputEvent::KeyUp || initialKeyEvent.type == WebInputEvent::Char) {
121 KeyboardEvent* domEvent = KeyboardEvent::create(initialKeyEvent, m_frame ->document()->domWindow()); 118 KeyboardEvent* domEvent = KeyboardEvent::create(initialKeyEvent, m_frame ->document()->domWindow());
122 119
123 return EventHandler::toWebInputEventResult(node->dispatchEvent(domEvent) ); 120 return EventHandlingUtil::toWebInputEventResult(node->dispatchEvent(domE vent));
124 } 121 }
125 122
126 WebKeyboardEvent keyDownEvent = initialKeyEvent; 123 WebKeyboardEvent keyDownEvent = initialKeyEvent;
127 if (keyDownEvent.type != WebInputEvent::RawKeyDown) 124 if (keyDownEvent.type != WebInputEvent::RawKeyDown)
128 keyDownEvent.type = WebInputEvent::RawKeyDown; 125 keyDownEvent.type = WebInputEvent::RawKeyDown;
129 KeyboardEvent* keydown = KeyboardEvent::create(keyDownEvent, m_frame->docume nt()->domWindow()); 126 KeyboardEvent* keydown = KeyboardEvent::create(keyDownEvent, m_frame->docume nt()->domWindow());
130 if (matchedAnAccessKey) 127 if (matchedAnAccessKey)
131 keydown->setDefaultPrevented(true); 128 keydown->setDefaultPrevented(true);
132 keydown->setTarget(node); 129 keydown->setTarget(node);
133 130
134 DispatchEventResult dispatchResult = node->dispatchEvent(keydown); 131 DispatchEventResult dispatchResult = node->dispatchEvent(keydown);
135 if (dispatchResult != DispatchEventResult::NotCanceled) 132 if (dispatchResult != DispatchEventResult::NotCanceled)
136 return EventHandler::toWebInputEventResult(dispatchResult); 133 return EventHandlingUtil::toWebInputEventResult(dispatchResult);
137 // If frame changed as a result of keydown dispatch, then return early to av oid sending a subsequent keypress message to the new frame. 134 // If frame changed as a result of keydown dispatch, then return early to av oid sending a subsequent keypress message to the new frame.
138 bool changedFocusedFrame = m_frame->page() && m_frame != m_frame->page()->fo cusController().focusedOrMainFrame(); 135 bool changedFocusedFrame = m_frame->page() && m_frame != m_frame->page()->fo cusController().focusedOrMainFrame();
139 if (changedFocusedFrame) 136 if (changedFocusedFrame)
140 return WebInputEventResult::HandledSystem; 137 return WebInputEventResult::HandledSystem;
141 138
142 if (initialKeyEvent.type == WebInputEvent::RawKeyDown) 139 if (initialKeyEvent.type == WebInputEvent::RawKeyDown)
143 return WebInputEventResult::NotHandled; 140 return WebInputEventResult::NotHandled;
144 141
145 // Focus may have changed during keydown handling, so refetch node. 142 // Focus may have changed during keydown handling, so refetch node.
146 // But if we are dispatching a fake backward compatibility keypress, then we pretend that the keypress happened on the original node. 143 // But if we are dispatching a fake backward compatibility keypress, then we pretend that the keypress happened on the original node.
(...skipping 10 matching lines...) Expand all
157 return WebInputEventResult::NotHandled; 154 return WebInputEventResult::NotHandled;
158 } 155 }
159 #endif 156 #endif
160 157
161 WebKeyboardEvent keyPressEvent = initialKeyEvent; 158 WebKeyboardEvent keyPressEvent = initialKeyEvent;
162 keyPressEvent.type = WebInputEvent::Char; 159 keyPressEvent.type = WebInputEvent::Char;
163 if (keyPressEvent.text[0] == 0) 160 if (keyPressEvent.text[0] == 0)
164 return WebInputEventResult::NotHandled; 161 return WebInputEventResult::NotHandled;
165 KeyboardEvent* keypress = KeyboardEvent::create(keyPressEvent, m_frame->docu ment()->domWindow()); 162 KeyboardEvent* keypress = KeyboardEvent::create(keyPressEvent, m_frame->docu ment()->domWindow());
166 keypress->setTarget(node); 163 keypress->setTarget(node);
167 return EventHandler::toWebInputEventResult(node->dispatchEvent(keypress)); 164 return EventHandlingUtil::toWebInputEventResult(node->dispatchEvent(keypress ));
168 } 165 }
169 166
170 void KeyboardEventManager::capsLockStateMayHaveChanged() 167 void KeyboardEventManager::capsLockStateMayHaveChanged()
171 { 168 {
172 if (Element* element = m_frame->document()->focusedElement()) { 169 if (Element* element = m_frame->document()->focusedElement()) {
173 if (LayoutObject* r = element->layoutObject()) { 170 if (LayoutObject* r = element->layoutObject()) {
174 if (r->isTextField()) 171 if (r->isTextField())
175 toLayoutTextControlSingleLine(r)->capsLockStateMayHaveChanged(); 172 toLayoutTextControlSingleLine(r)->capsLockStateMayHaveChanged();
176 } 173 }
177 } 174 }
(...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after
303 300
304 void KeyboardEventManager::defaultEscapeEventHandler(KeyboardEvent* event) 301 void KeyboardEventManager::defaultEscapeEventHandler(KeyboardEvent* event)
305 { 302 {
306 if (HTMLDialogElement* dialog = m_frame->document()->activeModalDialog()) 303 if (HTMLDialogElement* dialog = m_frame->document()->activeModalDialog())
307 dialog->dispatchEvent(Event::createCancelable(EventTypeNames::cancel)); 304 dialog->dispatchEvent(Event::createCancelable(EventTypeNames::cancel));
308 } 305 }
309 306
310 DEFINE_TRACE(KeyboardEventManager) 307 DEFINE_TRACE(KeyboardEventManager)
311 { 308 {
312 visitor->trace(m_frame); 309 visitor->trace(m_frame);
310 visitor->trace(m_scrollManager);
313 } 311 }
314 312
315 static OverrideCapsLockState s_overrideCapsLockState; 313 static OverrideCapsLockState s_overrideCapsLockState;
316 314
317 void KeyboardEventManager::setCurrentCapsLockState(OverrideCapsLockState state) { s_overrideCapsLockState = state; } 315 void KeyboardEventManager::setCurrentCapsLockState(OverrideCapsLockState state) { s_overrideCapsLockState = state; }
318 316
319 bool KeyboardEventManager::currentCapsLockState() 317 bool KeyboardEventManager::currentCapsLockState()
320 { 318 {
321 switch (s_overrideCapsLockState) { 319 switch (s_overrideCapsLockState) {
322 case OverrideCapsLockState::Default: 320 case OverrideCapsLockState::Default:
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
358 if (currentModifiers & ::cmdKey) 356 if (currentModifiers & ::cmdKey)
359 modifiers |= WebInputEvent::MetaKey; 357 modifiers |= WebInputEvent::MetaKey;
360 #else 358 #else
361 // TODO(crbug.com/538289): Implement on other platforms. 359 // TODO(crbug.com/538289): Implement on other platforms.
362 return static_cast<WebInputEvent::Modifiers>(0); 360 return static_cast<WebInputEvent::Modifiers>(0);
363 #endif 361 #endif
364 return static_cast<WebInputEvent::Modifiers>(modifiers); 362 return static_cast<WebInputEvent::Modifiers>(modifiers);
365 } 363 }
366 364
367 } // namespace blink 365 } // namespace blink
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/core/input/KeyboardEventManager.h ('k') | third_party/WebKit/Source/core/input/MouseEventManager.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698