| 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/PlatformKeyboardEvent.h" | 20 #include "platform/PlatformKeyboardEvent.h" |
| 20 #include "platform/UserGestureIndicator.h" | 21 #include "platform/UserGestureIndicator.h" |
| 21 #include "platform/WindowsKeyboardCodes.h" | 22 #include "platform/WindowsKeyboardCodes.h" |
| (...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 103 // On Windows, WebKit explicitly calls handleAccessKey() instead of dispatch
ing a keypress event for WM_SYSCHAR messages. | 104 // On Windows, WebKit explicitly calls handleAccessKey() instead of dispatch
ing a keypress event for WM_SYSCHAR messages. |
| 104 // Other platforms currently match either Mac or Windows behavior, depending
on whether they send combined KeyDown events. | 105 // Other platforms currently match either Mac or Windows behavior, depending
on whether they send combined KeyDown events. |
| 105 bool matchedAnAccessKey = false; | 106 bool matchedAnAccessKey = false; |
| 106 if (initialKeyEvent.type() == PlatformEvent::KeyDown) | 107 if (initialKeyEvent.type() == PlatformEvent::KeyDown) |
| 107 matchedAnAccessKey = handleAccessKey(initialKeyEvent); | 108 matchedAnAccessKey = handleAccessKey(initialKeyEvent); |
| 108 | 109 |
| 109 // FIXME: it would be fair to let an input method handle KeyUp events before
DOM dispatch. | 110 // FIXME: it would be fair to let an input method handle KeyUp events before
DOM dispatch. |
| 110 if (initialKeyEvent.type() == PlatformEvent::KeyUp || initialKeyEvent.type()
== PlatformEvent::Char) { | 111 if (initialKeyEvent.type() == PlatformEvent::KeyUp || initialKeyEvent.type()
== PlatformEvent::Char) { |
| 111 KeyboardEvent* domEvent = KeyboardEvent::create(initialKeyEvent, m_frame
->document()->domWindow()); | 112 KeyboardEvent* domEvent = KeyboardEvent::create(initialKeyEvent, m_frame
->document()->domWindow()); |
| 112 | 113 |
| 113 return EventHandler::toWebInputEventResult(node->dispatchEvent(domEvent)
); | 114 return EventHandlingUtil::toWebInputEventResult(node->dispatchEvent(domE
vent)); |
| 114 } | 115 } |
| 115 | 116 |
| 116 PlatformKeyboardEvent keyDownEvent = initialKeyEvent; | 117 PlatformKeyboardEvent keyDownEvent = initialKeyEvent; |
| 117 if (keyDownEvent.type() != PlatformEvent::RawKeyDown) | 118 if (keyDownEvent.type() != PlatformEvent::RawKeyDown) |
| 118 keyDownEvent.disambiguateKeyDownEvent(PlatformEvent::RawKeyDown); | 119 keyDownEvent.disambiguateKeyDownEvent(PlatformEvent::RawKeyDown); |
| 119 KeyboardEvent* keydown = KeyboardEvent::create(keyDownEvent, m_frame->docume
nt()->domWindow()); | 120 KeyboardEvent* keydown = KeyboardEvent::create(keyDownEvent, m_frame->docume
nt()->domWindow()); |
| 120 if (matchedAnAccessKey) | 121 if (matchedAnAccessKey) |
| 121 keydown->setDefaultPrevented(true); | 122 keydown->setDefaultPrevented(true); |
| 122 keydown->setTarget(node); | 123 keydown->setTarget(node); |
| 123 | 124 |
| 124 DispatchEventResult dispatchResult = node->dispatchEvent(keydown); | 125 DispatchEventResult dispatchResult = node->dispatchEvent(keydown); |
| 125 if (dispatchResult != DispatchEventResult::NotCanceled) | 126 if (dispatchResult != DispatchEventResult::NotCanceled) |
| 126 return EventHandler::toWebInputEventResult(dispatchResult); | 127 return EventHandlingUtil::toWebInputEventResult(dispatchResult); |
| 127 // If frame changed as a result of keydown dispatch, then return early to av
oid sending a subsequent keypress message to the new frame. | 128 // If frame changed as a result of keydown dispatch, then return early to av
oid sending a subsequent keypress message to the new frame. |
| 128 bool changedFocusedFrame = m_frame->page() && m_frame != m_frame->page()->fo
cusController().focusedOrMainFrame(); | 129 bool changedFocusedFrame = m_frame->page() && m_frame != m_frame->page()->fo
cusController().focusedOrMainFrame(); |
| 129 if (changedFocusedFrame) | 130 if (changedFocusedFrame) |
| 130 return WebInputEventResult::HandledSystem; | 131 return WebInputEventResult::HandledSystem; |
| 131 | 132 |
| 132 if (initialKeyEvent.type() == PlatformEvent::RawKeyDown) | 133 if (initialKeyEvent.type() == PlatformEvent::RawKeyDown) |
| 133 return WebInputEventResult::NotHandled; | 134 return WebInputEventResult::NotHandled; |
| 134 | 135 |
| 135 // Focus may have changed during keydown handling, so refetch node. | 136 // Focus may have changed during keydown handling, so refetch node. |
| 136 // But if we are dispatching a fake backward compatibility keypress, then we
pretend that the keypress happened on the original node. | 137 // But if we are dispatching a fake backward compatibility keypress, then we
pretend that the keypress happened on the original node. |
| 137 node = eventTargetNodeForDocument(m_frame->document()); | 138 node = eventTargetNodeForDocument(m_frame->document()); |
| 138 if (!node) | 139 if (!node) |
| 139 return WebInputEventResult::NotHandled; | 140 return WebInputEventResult::NotHandled; |
| 140 | 141 |
| 141 PlatformKeyboardEvent keyPressEvent = initialKeyEvent; | 142 PlatformKeyboardEvent keyPressEvent = initialKeyEvent; |
| 142 keyPressEvent.disambiguateKeyDownEvent(PlatformEvent::Char); | 143 keyPressEvent.disambiguateKeyDownEvent(PlatformEvent::Char); |
| 143 if (keyPressEvent.text().isEmpty()) | 144 if (keyPressEvent.text().isEmpty()) |
| 144 return WebInputEventResult::NotHandled; | 145 return WebInputEventResult::NotHandled; |
| 145 KeyboardEvent* keypress = KeyboardEvent::create(keyPressEvent, m_frame->docu
ment()->domWindow()); | 146 KeyboardEvent* keypress = KeyboardEvent::create(keyPressEvent, m_frame->docu
ment()->domWindow()); |
| 146 keypress->setTarget(node); | 147 keypress->setTarget(node); |
| 147 return EventHandler::toWebInputEventResult(node->dispatchEvent(keypress)); | 148 return EventHandlingUtil::toWebInputEventResult(node->dispatchEvent(keypress
)); |
| 148 } | 149 } |
| 149 | 150 |
| 150 void KeyboardEventManager::capsLockStateMayHaveChanged() | 151 void KeyboardEventManager::capsLockStateMayHaveChanged() |
| 151 { | 152 { |
| 152 if (Element* element = m_frame->document()->focusedElement()) { | 153 if (Element* element = m_frame->document()->focusedElement()) { |
| 153 if (LayoutObject* r = element->layoutObject()) { | 154 if (LayoutObject* r = element->layoutObject()) { |
| 154 if (r->isTextField()) | 155 if (r->isTextField()) |
| 155 toLayoutTextControlSingleLine(r)->capsLockStateMayHaveChanged(); | 156 toLayoutTextControlSingleLine(r)->capsLockStateMayHaveChanged(); |
| 156 } | 157 } |
| 157 } | 158 } |
| (...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 286 if (HTMLDialogElement* dialog = m_frame->document()->activeModalDialog()) | 287 if (HTMLDialogElement* dialog = m_frame->document()->activeModalDialog()) |
| 287 dialog->dispatchEvent(Event::createCancelable(EventTypeNames::cancel)); | 288 dialog->dispatchEvent(Event::createCancelable(EventTypeNames::cancel)); |
| 288 } | 289 } |
| 289 | 290 |
| 290 DEFINE_TRACE(KeyboardEventManager) | 291 DEFINE_TRACE(KeyboardEventManager) |
| 291 { | 292 { |
| 292 visitor->trace(m_frame); | 293 visitor->trace(m_frame); |
| 293 } | 294 } |
| 294 | 295 |
| 295 } // namespace blink | 296 } // namespace blink |
| OLD | NEW |