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/EventHandler.h" |
12 #include "core/layout/LayoutObject.h" | 12 #include "core/layout/LayoutObject.h" |
13 #include "core/layout/LayoutTextControlSingleLine.h" | 13 #include "core/layout/LayoutTextControlSingleLine.h" |
14 #include "core/loader/FrameLoaderClient.h" | 14 #include "core/loader/FrameLoaderClient.h" |
15 #include "core/page/ChromeClient.h" | 15 #include "core/page/ChromeClient.h" |
16 #include "core/page/FocusController.h" | 16 #include "core/page/FocusController.h" |
17 #include "core/page/Page.h" | 17 #include "core/page/Page.h" |
18 #include "core/page/SpatialNavigation.h" | 18 #include "core/page/SpatialNavigation.h" |
19 #include "platform/PlatformKeyboardEvent.h" | 19 #include "platform/PlatformKeyboardEvent.h" |
20 #include "platform/UserGestureIndicator.h" | 20 #include "platform/UserGestureIndicator.h" |
21 #include "platform/WindowsKeyboardCodes.h" | 21 #include "platform/WindowsKeyboardCodes.h" |
22 | 22 |
23 namespace blink { | 23 namespace blink { |
24 | 24 |
25 namespace { | 25 namespace { |
26 | 26 |
27 WebFocusType focusDirectionForKey(const AtomicString& keyIdentifier) | 27 WebFocusType focusDirectionForKey(const String& key) |
28 { | 28 { |
29 DEFINE_STATIC_LOCAL(AtomicString, Down, ("Down")); | |
30 DEFINE_STATIC_LOCAL(AtomicString, Up, ("Up")); | |
31 DEFINE_STATIC_LOCAL(AtomicString, Left, ("Left")); | |
32 DEFINE_STATIC_LOCAL(AtomicString, Right, ("Right")); | |
33 | |
34 WebFocusType retVal = WebFocusTypeNone; | 29 WebFocusType retVal = WebFocusTypeNone; |
35 | 30 if (key == "ArrowDown") |
36 if (keyIdentifier == Down) | |
37 retVal = WebFocusTypeDown; | 31 retVal = WebFocusTypeDown; |
38 else if (keyIdentifier == Up) | 32 else if (key == "ArrowUp") |
39 retVal = WebFocusTypeUp; | 33 retVal = WebFocusTypeUp; |
40 else if (keyIdentifier == Left) | 34 else if (key == "ArrowLeft") |
41 retVal = WebFocusTypeLeft; | 35 retVal = WebFocusTypeLeft; |
42 else if (keyIdentifier == Right) | 36 else if (key == "ArrowRight") |
43 retVal = WebFocusTypeRight; | 37 retVal = WebFocusTypeRight; |
44 | |
45 return retVal; | 38 return retVal; |
46 } | 39 } |
47 | 40 |
48 } // namespace | 41 } // namespace |
49 | 42 |
50 KeyboardEventManager::KeyboardEventManager( | 43 KeyboardEventManager::KeyboardEventManager( |
51 LocalFrame* frame, ScrollManager* scrollManager) | 44 LocalFrame* frame, ScrollManager* scrollManager) |
52 : m_frame(frame) | 45 : m_frame(frame) |
53 , m_scrollManager(scrollManager) | 46 , m_scrollManager(scrollManager) |
54 { | 47 { |
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
167 { | 160 { |
168 if (event->type() == EventTypeNames::keydown) { | 161 if (event->type() == EventTypeNames::keydown) { |
169 // Clear caret blinking suspended state to make sure that caret blinks | 162 // Clear caret blinking suspended state to make sure that caret blinks |
170 // when we type again after long pressing on an empty input field. | 163 // when we type again after long pressing on an empty input field. |
171 if (m_frame && m_frame->selection().isCaretBlinkingSuspended()) | 164 if (m_frame && m_frame->selection().isCaretBlinkingSuspended()) |
172 m_frame->selection().setCaretBlinkingSuspended(false); | 165 m_frame->selection().setCaretBlinkingSuspended(false); |
173 | 166 |
174 m_frame->editor().handleKeyboardEvent(event); | 167 m_frame->editor().handleKeyboardEvent(event); |
175 if (event->defaultHandled()) | 168 if (event->defaultHandled()) |
176 return; | 169 return; |
177 if (event->keyIdentifier() == "U+0009") { | 170 if (event->key() == "Tab") { |
178 defaultTabEventHandler(event); | 171 defaultTabEventHandler(event); |
179 } else if (event->keyIdentifier() == "U+0008") { | 172 } else if (event->key() == "Backspace") { |
180 defaultBackspaceEventHandler(event); | 173 defaultBackspaceEventHandler(event); |
181 } else if (event->keyIdentifier() == "U+001B") { | 174 } else if (event->key() == "Escape") { |
182 defaultEscapeEventHandler(event); | 175 defaultEscapeEventHandler(event); |
183 } else { | 176 } else { |
184 WebFocusType type = focusDirectionForKey(AtomicString(event->keyIden
tifier())); | 177 WebFocusType type = focusDirectionForKey(event->key()); |
185 if (type != WebFocusTypeNone) | 178 if (type != WebFocusTypeNone) |
186 defaultArrowEventHandler(type, event); | 179 defaultArrowEventHandler(type, event); |
187 } | 180 } |
188 } | 181 } |
189 if (event->type() == EventTypeNames::keypress) { | 182 if (event->type() == EventTypeNames::keypress) { |
190 m_frame->editor().handleKeyboardEvent(event); | 183 m_frame->editor().handleKeyboardEvent(event); |
191 if (event->defaultHandled()) | 184 if (event->defaultHandled()) |
192 return; | 185 return; |
193 if (event->charCode() == ' ') | 186 if (event->charCode() == ' ') |
194 defaultSpaceEventHandler(event, possibleFocusedNode); | 187 defaultSpaceEventHandler(event, possibleFocusedNode); |
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
291 if (HTMLDialogElement* dialog = m_frame->document()->activeModalDialog()) | 284 if (HTMLDialogElement* dialog = m_frame->document()->activeModalDialog()) |
292 dialog->dispatchEvent(Event::createCancelable(EventTypeNames::cancel)); | 285 dialog->dispatchEvent(Event::createCancelable(EventTypeNames::cancel)); |
293 } | 286 } |
294 | 287 |
295 DEFINE_TRACE(KeyboardEventManager) | 288 DEFINE_TRACE(KeyboardEventManager) |
296 { | 289 { |
297 visitor->trace(m_frame); | 290 visitor->trace(m_frame); |
298 } | 291 } |
299 | 292 |
300 } // namespace blink | 293 } // namespace blink |
OLD | NEW |