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

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

Issue 2397723004: reflow comments in core/input (Closed)
Patch Set: Created 4 years, 2 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"
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
56 ScrollManager* scrollManager) 56 ScrollManager* scrollManager)
57 : m_frame(frame), m_scrollManager(scrollManager) {} 57 : m_frame(frame), m_scrollManager(scrollManager) {}
58 58
59 DEFINE_TRACE(KeyboardEventManager) { 59 DEFINE_TRACE(KeyboardEventManager) {
60 visitor->trace(m_frame); 60 visitor->trace(m_frame);
61 visitor->trace(m_scrollManager); 61 visitor->trace(m_scrollManager);
62 } 62 }
63 63
64 bool KeyboardEventManager::handleAccessKey(const WebKeyboardEvent& evt) { 64 bool KeyboardEventManager::handleAccessKey(const WebKeyboardEvent& evt) {
65 // 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.
66 // 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 -
67 // lower case variants are present in a document, the correct element is match ed based on Shift key state. 67 // but if both upper and lower case variants are present in a document, the
68 // Firefox only matches an access key if Shift is not pressed, and does that c ase-insensitively. 68 // correct element is matched based on Shift key state. Firefox only matches
69 // an access key if Shift is not pressed, and does that case-insensitively.
69 DCHECK(!(kAccessKeyModifiers & WebInputEvent::ShiftKey)); 70 DCHECK(!(kAccessKeyModifiers & WebInputEvent::ShiftKey));
70 if ((evt.modifiers & (WebKeyboardEvent::KeyModifiers & 71 if ((evt.modifiers & (WebKeyboardEvent::KeyModifiers &
71 ~WebInputEvent::ShiftKey)) != kAccessKeyModifiers) 72 ~WebInputEvent::ShiftKey)) != kAccessKeyModifiers)
72 return false; 73 return false;
73 String key = String(evt.unmodifiedText); 74 String key = String(evt.unmodifiedText);
74 Element* elem = m_frame->document()->getElementByAccessKey(key.lower()); 75 Element* elem = m_frame->document()->getElementByAccessKey(key.lower());
75 if (!elem) 76 if (!elem)
76 return false; 77 return false;
77 elem->accessKeyAction(false); 78 elem->accessKeyAction(false);
78 return true; 79 return true;
79 } 80 }
80 81
81 WebInputEventResult KeyboardEventManager::keyEvent( 82 WebInputEventResult KeyboardEventManager::keyEvent(
82 const WebKeyboardEvent& initialKeyEvent) { 83 const WebKeyboardEvent& initialKeyEvent) {
83 m_frame->chromeClient().clearToolTip(*m_frame); 84 m_frame->chromeClient().clearToolTip(*m_frame);
84 85
85 if (initialKeyEvent.windowsKeyCode == VK_CAPITAL) 86 if (initialKeyEvent.windowsKeyCode == VK_CAPITAL)
86 capsLockStateMayHaveChanged(); 87 capsLockStateMayHaveChanged();
87 88
88 if (m_scrollManager->middleClickAutoscrollInProgress()) { 89 if (m_scrollManager->middleClickAutoscrollInProgress()) {
89 DCHECK(RuntimeEnabledFeatures::middleClickAutoscrollEnabled()); 90 DCHECK(RuntimeEnabledFeatures::middleClickAutoscrollEnabled());
90 // If a key is pressed while the middleClickAutoscroll is in progress then w e want to stop 91 // If a key is pressed while the middleClickAutoscroll is in progress then
92 // we want to stop.
91 if (initialKeyEvent.type == WebInputEvent::KeyDown || 93 if (initialKeyEvent.type == WebInputEvent::KeyDown ||
92 initialKeyEvent.type == WebInputEvent::RawKeyDown) 94 initialKeyEvent.type == WebInputEvent::RawKeyDown)
93 m_scrollManager->stopAutoscroll(); 95 m_scrollManager->stopAutoscroll();
94 96
95 // If we were in panscroll mode, we swallow the key event 97 // If we were in panscroll mode, we swallow the key event
96 return WebInputEventResult::HandledSuppressed; 98 return WebInputEventResult::HandledSuppressed;
97 } 99 }
98 100
99 // Check for cases where we are too early for events -- possible unmatched key up 101 // Check for cases where we are too early for events -- possible unmatched key
100 // from pressing return in the location bar. 102 // up from pressing return in the location bar.
101 Node* node = eventTargetNodeForDocument(m_frame->document()); 103 Node* node = eventTargetNodeForDocument(m_frame->document());
102 if (!node) 104 if (!node)
103 return WebInputEventResult::NotHandled; 105 return WebInputEventResult::NotHandled;
104 106
105 UserGestureIndicator gestureIndicator(DefinitelyProcessingUserGesture); 107 UserGestureIndicator gestureIndicator(DefinitelyProcessingUserGesture);
106 108
107 // In IE, access keys are special, they are handled after default keydown proc essing, but cannot be canceled - this is hard to match. 109 // In IE, access keys are special, they are handled after default keydown
108 // On Mac OS X, we process them before dispatching keydown, as the default key down handler implements Emacs key bindings, which may conflict 110 // processing, but cannot be canceled - this is hard to match. On Mac OS X,
109 // with access keys. Then we dispatch keydown, but suppress its default handli ng. 111 // we process them before dispatching keydown, as the default keydown handler
110 // On Windows, WebKit explicitly calls handleAccessKey() instead of dispatchin g a keypress event for WM_SYSCHAR messages. 112 // implements Emacs key bindings, which may conflict with access keys. Then we
111 // Other platforms currently match either Mac or Windows behavior, depending o n whether they send combined KeyDown events. 113 // dispatch keydown, but suppress its default handling.
114 // On Windows, WebKit explicitly calls handleAccessKey() instead of
115 // dispatching a keypress event for WM_SYSCHAR messages. Other platforms
116 // currently match either Mac or Windows behavior, depending on whether they
117 // send combined KeyDown events.
112 bool matchedAnAccessKey = false; 118 bool matchedAnAccessKey = false;
113 if (initialKeyEvent.type == WebInputEvent::KeyDown) 119 if (initialKeyEvent.type == WebInputEvent::KeyDown)
114 matchedAnAccessKey = handleAccessKey(initialKeyEvent); 120 matchedAnAccessKey = handleAccessKey(initialKeyEvent);
115 121
116 // FIXME: it would be fair to let an input method handle KeyUp events before D OM dispatch. 122 // FIXME: it would be fair to let an input method handle KeyUp events before
123 // DOM dispatch.
117 if (initialKeyEvent.type == WebInputEvent::KeyUp || 124 if (initialKeyEvent.type == WebInputEvent::KeyUp ||
118 initialKeyEvent.type == WebInputEvent::Char) { 125 initialKeyEvent.type == WebInputEvent::Char) {
119 KeyboardEvent* domEvent = KeyboardEvent::create( 126 KeyboardEvent* domEvent = KeyboardEvent::create(
120 initialKeyEvent, m_frame->document()->domWindow()); 127 initialKeyEvent, m_frame->document()->domWindow());
121 128
122 return EventHandlingUtil::toWebInputEventResult( 129 return EventHandlingUtil::toWebInputEventResult(
123 node->dispatchEvent(domEvent)); 130 node->dispatchEvent(domEvent));
124 } 131 }
125 132
126 WebKeyboardEvent keyDownEvent = initialKeyEvent; 133 WebKeyboardEvent keyDownEvent = initialKeyEvent;
127 if (keyDownEvent.type != WebInputEvent::RawKeyDown) 134 if (keyDownEvent.type != WebInputEvent::RawKeyDown)
128 keyDownEvent.type = WebInputEvent::RawKeyDown; 135 keyDownEvent.type = WebInputEvent::RawKeyDown;
129 KeyboardEvent* keydown = 136 KeyboardEvent* keydown =
130 KeyboardEvent::create(keyDownEvent, m_frame->document()->domWindow()); 137 KeyboardEvent::create(keyDownEvent, m_frame->document()->domWindow());
131 if (matchedAnAccessKey) 138 if (matchedAnAccessKey)
132 keydown->setDefaultPrevented(true); 139 keydown->setDefaultPrevented(true);
133 keydown->setTarget(node); 140 keydown->setTarget(node);
134 141
135 DispatchEventResult dispatchResult = node->dispatchEvent(keydown); 142 DispatchEventResult dispatchResult = node->dispatchEvent(keydown);
136 if (dispatchResult != DispatchEventResult::NotCanceled) 143 if (dispatchResult != DispatchEventResult::NotCanceled)
137 return EventHandlingUtil::toWebInputEventResult(dispatchResult); 144 return EventHandlingUtil::toWebInputEventResult(dispatchResult);
138 // If frame changed as a result of keydown dispatch, then return early to avoi d sending a subsequent keypress message to the new frame. 145 // If frame changed as a result of keydown dispatch, then return early to
146 // avoid sending a subsequent keypress message to the new frame.
139 bool changedFocusedFrame = 147 bool changedFocusedFrame =
140 m_frame->page() && 148 m_frame->page() &&
141 m_frame != m_frame->page()->focusController().focusedOrMainFrame(); 149 m_frame != m_frame->page()->focusController().focusedOrMainFrame();
142 if (changedFocusedFrame) 150 if (changedFocusedFrame)
143 return WebInputEventResult::HandledSystem; 151 return WebInputEventResult::HandledSystem;
144 152
145 if (initialKeyEvent.type == WebInputEvent::RawKeyDown) 153 if (initialKeyEvent.type == WebInputEvent::RawKeyDown)
146 return WebInputEventResult::NotHandled; 154 return WebInputEventResult::NotHandled;
147 155
148 // Focus may have changed during keydown handling, so refetch node. 156 // Focus may have changed during keydown handling, so refetch node.
149 // But if we are dispatching a fake backward compatibility keypress, then we p retend that the keypress happened on the original node. 157 // But if we are dispatching a fake backward compatibility keypress, then we
158 // pretend that the keypress happened on the original node.
150 node = eventTargetNodeForDocument(m_frame->document()); 159 node = eventTargetNodeForDocument(m_frame->document());
151 if (!node) 160 if (!node)
152 return WebInputEventResult::NotHandled; 161 return WebInputEventResult::NotHandled;
153 162
154 #if OS(MACOSX) 163 #if OS(MACOSX)
155 // According to NSEvents.h, OpenStep reserves the range 0xF700-0xF8FF for 164 // According to NSEvents.h, OpenStep reserves the range 0xF700-0xF8FF for
156 // function keys. However, some actual private use characters happen to be 165 // function keys. However, some actual private use characters happen to be
157 // in this range, e.g. the Apple logo (Option+Shift+K). 0xF7FF is an 166 // in this range, e.g. the Apple logo (Option+Shift+K). 0xF7FF is an
158 // arbitrary cut-off. 167 // arbitrary cut-off.
159 if (initialKeyEvent.text[0U] >= 0xF700 && 168 if (initialKeyEvent.text[0U] >= 0xF700 &&
(...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after
273 if (m_frame->document()->inDesignMode()) 282 if (m_frame->document()->inDesignMode())
274 return; 283 return;
275 284
276 if (page->focusController().advanceFocus(focusType)) 285 if (page->focusController().advanceFocus(focusType))
277 event->setDefaultHandled(); 286 event->setDefaultHandled();
278 } 287 }
279 288
280 void KeyboardEventManager::defaultTabEventHandler(KeyboardEvent* event) { 289 void KeyboardEventManager::defaultTabEventHandler(KeyboardEvent* event) {
281 DCHECK_EQ(event->type(), EventTypeNames::keydown); 290 DCHECK_EQ(event->type(), EventTypeNames::keydown);
282 291
283 // We should only advance focus on tabs if no special modifier keys are held d own. 292 // We should only advance focus on tabs if no special modifier keys are held
293 // down.
284 if (event->ctrlKey() || event->metaKey()) 294 if (event->ctrlKey() || event->metaKey())
285 return; 295 return;
286 296
287 #if !OS(MACOSX) 297 #if !OS(MACOSX)
288 // Option-Tab is a shortcut based on a system-wide preference on Mac but 298 // Option-Tab is a shortcut based on a system-wide preference on Mac but
289 // should be ignored on all other platforms. 299 // should be ignored on all other platforms.
290 if (event->altKey()) 300 if (event->altKey())
291 return; 301 return;
292 #endif 302 #endif
293 303
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after
362 if (currentModifiers & ::cmdKey) 372 if (currentModifiers & ::cmdKey)
363 modifiers |= WebInputEvent::MetaKey; 373 modifiers |= WebInputEvent::MetaKey;
364 #else 374 #else
365 // TODO(crbug.com/538289): Implement on other platforms. 375 // TODO(crbug.com/538289): Implement on other platforms.
366 return static_cast<WebInputEvent::Modifiers>(0); 376 return static_cast<WebInputEvent::Modifiers>(0);
367 #endif 377 #endif
368 return static_cast<WebInputEvent::Modifiers>(modifiers); 378 return static_cast<WebInputEvent::Modifiers>(modifiers);
369 } 379 }
370 380
371 } // namespace blink 381 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698