| OLD | NEW |
| 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 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 113 // On Windows, WebKit explicitly calls handleAccessKey() instead of dispatch
ing a keypress event for WM_SYSCHAR messages. | 114 // 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. | 115 // Other platforms currently match either Mac or Windows behavior, depending
on whether they send combined KeyDown events. |
| 115 bool matchedAnAccessKey = false; | 116 bool matchedAnAccessKey = false; |
| 116 if (initialKeyEvent.type == WebInputEvent::KeyDown) | 117 if (initialKeyEvent.type == WebInputEvent::KeyDown) |
| 117 matchedAnAccessKey = handleAccessKey(initialKeyEvent); | 118 matchedAnAccessKey = handleAccessKey(initialKeyEvent); |
| 118 | 119 |
| 119 // FIXME: it would be fair to let an input method handle KeyUp events before
DOM dispatch. | 120 // 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) { | 121 if (initialKeyEvent.type == WebInputEvent::KeyUp || initialKeyEvent.type ==
WebInputEvent::Char) { |
| 121 KeyboardEvent* domEvent = KeyboardEvent::create(initialKeyEvent, m_frame
->document()->domWindow()); | 122 KeyboardEvent* domEvent = KeyboardEvent::create(initialKeyEvent, m_frame
->document()->domWindow()); |
| 122 | 123 |
| 123 return EventHandler::toWebInputEventResult(node->dispatchEvent(domEvent)
); | 124 return EventHandlingUtil::toWebInputEventResult(node->dispatchEvent(domE
vent)); |
| 124 } | 125 } |
| 125 | 126 |
| 126 WebKeyboardEvent keyDownEvent = initialKeyEvent; | 127 WebKeyboardEvent keyDownEvent = initialKeyEvent; |
| 127 if (keyDownEvent.type != WebInputEvent::RawKeyDown) | 128 if (keyDownEvent.type != WebInputEvent::RawKeyDown) |
| 128 keyDownEvent.type = WebInputEvent::RawKeyDown; | 129 keyDownEvent.type = WebInputEvent::RawKeyDown; |
| 129 KeyboardEvent* keydown = KeyboardEvent::create(keyDownEvent, m_frame->docume
nt()->domWindow()); | 130 KeyboardEvent* keydown = KeyboardEvent::create(keyDownEvent, m_frame->docume
nt()->domWindow()); |
| 130 if (matchedAnAccessKey) | 131 if (matchedAnAccessKey) |
| 131 keydown->setDefaultPrevented(true); | 132 keydown->setDefaultPrevented(true); |
| 132 keydown->setTarget(node); | 133 keydown->setTarget(node); |
| 133 | 134 |
| 134 DispatchEventResult dispatchResult = node->dispatchEvent(keydown); | 135 DispatchEventResult dispatchResult = node->dispatchEvent(keydown); |
| 135 if (dispatchResult != DispatchEventResult::NotCanceled) | 136 if (dispatchResult != DispatchEventResult::NotCanceled) |
| 136 return EventHandler::toWebInputEventResult(dispatchResult); | 137 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. | 138 // 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(); | 139 bool changedFocusedFrame = m_frame->page() && m_frame != m_frame->page()->fo
cusController().focusedOrMainFrame(); |
| 139 if (changedFocusedFrame) | 140 if (changedFocusedFrame) |
| 140 return WebInputEventResult::HandledSystem; | 141 return WebInputEventResult::HandledSystem; |
| 141 | 142 |
| 142 if (initialKeyEvent.type == WebInputEvent::RawKeyDown) | 143 if (initialKeyEvent.type == WebInputEvent::RawKeyDown) |
| 143 return WebInputEventResult::NotHandled; | 144 return WebInputEventResult::NotHandled; |
| 144 | 145 |
| 145 // Focus may have changed during keydown handling, so refetch node. | 146 // 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. | 147 // 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 Loading... |
| 157 return WebInputEventResult::NotHandled; | 158 return WebInputEventResult::NotHandled; |
| 158 } | 159 } |
| 159 #endif | 160 #endif |
| 160 | 161 |
| 161 WebKeyboardEvent keyPressEvent = initialKeyEvent; | 162 WebKeyboardEvent keyPressEvent = initialKeyEvent; |
| 162 keyPressEvent.type = WebInputEvent::Char; | 163 keyPressEvent.type = WebInputEvent::Char; |
| 163 if (keyPressEvent.text[0] == 0) | 164 if (keyPressEvent.text[0] == 0) |
| 164 return WebInputEventResult::NotHandled; | 165 return WebInputEventResult::NotHandled; |
| 165 KeyboardEvent* keypress = KeyboardEvent::create(keyPressEvent, m_frame->docu
ment()->domWindow()); | 166 KeyboardEvent* keypress = KeyboardEvent::create(keyPressEvent, m_frame->docu
ment()->domWindow()); |
| 166 keypress->setTarget(node); | 167 keypress->setTarget(node); |
| 167 return EventHandler::toWebInputEventResult(node->dispatchEvent(keypress)); | 168 return EventHandlingUtil::toWebInputEventResult(node->dispatchEvent(keypress
)); |
| 168 } | 169 } |
| 169 | 170 |
| 170 void KeyboardEventManager::capsLockStateMayHaveChanged() | 171 void KeyboardEventManager::capsLockStateMayHaveChanged() |
| 171 { | 172 { |
| 172 if (Element* element = m_frame->document()->focusedElement()) { | 173 if (Element* element = m_frame->document()->focusedElement()) { |
| 173 if (LayoutObject* r = element->layoutObject()) { | 174 if (LayoutObject* r = element->layoutObject()) { |
| 174 if (r->isTextField()) | 175 if (r->isTextField()) |
| 175 toLayoutTextControlSingleLine(r)->capsLockStateMayHaveChanged(); | 176 toLayoutTextControlSingleLine(r)->capsLockStateMayHaveChanged(); |
| 176 } | 177 } |
| 177 } | 178 } |
| (...skipping 180 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 358 if (currentModifiers & ::cmdKey) | 359 if (currentModifiers & ::cmdKey) |
| 359 modifiers |= WebInputEvent::MetaKey; | 360 modifiers |= WebInputEvent::MetaKey; |
| 360 #else | 361 #else |
| 361 // TODO(crbug.com/538289): Implement on other platforms. | 362 // TODO(crbug.com/538289): Implement on other platforms. |
| 362 return static_cast<WebInputEvent::Modifiers>(0); | 363 return static_cast<WebInputEvent::Modifiers>(0); |
| 363 #endif | 364 #endif |
| 364 return static_cast<WebInputEvent::Modifiers>(modifiers); | 365 return static_cast<WebInputEvent::Modifiers>(modifiers); |
| 365 } | 366 } |
| 366 | 367 |
| 367 } // namespace blink | 368 } // namespace blink |
| OLD | NEW |