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

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

Issue 2573073003: Collapse the API surface on WebInputEvent via accessor functions. (Closed)
Patch Set: Fix nits Created 3 years, 11 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/DocumentUserGestureToken.h" 7 #include "core/dom/DocumentUserGestureToken.h"
8 #include "core/dom/Element.h" 8 #include "core/dom/Element.h"
9 #include "core/editing/Editor.h" 9 #include "core/editing/Editor.h"
10 #include "core/events/KeyboardEvent.h" 10 #include "core/events/KeyboardEvent.h"
(...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after
132 visitor->trace(m_scrollManager); 132 visitor->trace(m_scrollManager);
133 } 133 }
134 134
135 bool KeyboardEventManager::handleAccessKey(const WebKeyboardEvent& evt) { 135 bool KeyboardEventManager::handleAccessKey(const WebKeyboardEvent& evt) {
136 // FIXME: Ignoring the state of Shift key is what neither IE nor Firefox do. 136 // FIXME: Ignoring the state of Shift key is what neither IE nor Firefox do.
137 // IE matches lower and upper case access keys regardless of Shift key state - 137 // IE matches lower and upper case access keys regardless of Shift key state -
138 // but if both upper and lower case variants are present in a document, the 138 // but if both upper and lower case variants are present in a document, the
139 // correct element is matched based on Shift key state. Firefox only matches 139 // correct element is matched based on Shift key state. Firefox only matches
140 // an access key if Shift is not pressed, and does that case-insensitively. 140 // an access key if Shift is not pressed, and does that case-insensitively.
141 DCHECK(!(kAccessKeyModifiers & WebInputEvent::ShiftKey)); 141 DCHECK(!(kAccessKeyModifiers & WebInputEvent::ShiftKey));
142 if ((evt.modifiers & (WebKeyboardEvent::KeyModifiers & 142 if ((evt.modifiers() & (WebKeyboardEvent::KeyModifiers &
143 ~WebInputEvent::ShiftKey)) != kAccessKeyModifiers) 143 ~WebInputEvent::ShiftKey)) != kAccessKeyModifiers)
144 return false; 144 return false;
145 String key = String(evt.unmodifiedText); 145 String key = String(evt.unmodifiedText);
146 Element* elem = m_frame->document()->getElementByAccessKey(key.lower()); 146 Element* elem = m_frame->document()->getElementByAccessKey(key.lower());
147 if (!elem) 147 if (!elem)
148 return false; 148 return false;
149 elem->accessKeyAction(false); 149 elem->accessKeyAction(false);
150 return true; 150 return true;
151 } 151 }
152 152
153 WebInputEventResult KeyboardEventManager::keyEvent( 153 WebInputEventResult KeyboardEventManager::keyEvent(
154 const WebKeyboardEvent& initialKeyEvent) { 154 const WebKeyboardEvent& initialKeyEvent) {
155 m_frame->chromeClient().clearToolTip(*m_frame); 155 m_frame->chromeClient().clearToolTip(*m_frame);
156 156
157 if (initialKeyEvent.windowsKeyCode == VK_CAPITAL) 157 if (initialKeyEvent.windowsKeyCode == VK_CAPITAL)
158 capsLockStateMayHaveChanged(); 158 capsLockStateMayHaveChanged();
159 159
160 if (m_scrollManager->middleClickAutoscrollInProgress()) { 160 if (m_scrollManager->middleClickAutoscrollInProgress()) {
161 DCHECK(RuntimeEnabledFeatures::middleClickAutoscrollEnabled()); 161 DCHECK(RuntimeEnabledFeatures::middleClickAutoscrollEnabled());
162 // If a key is pressed while the middleClickAutoscroll is in progress then 162 // If a key is pressed while the middleClickAutoscroll is in progress then
163 // we want to stop. 163 // we want to stop.
164 if (initialKeyEvent.type == WebInputEvent::KeyDown || 164 if (initialKeyEvent.type() == WebInputEvent::KeyDown ||
165 initialKeyEvent.type == WebInputEvent::RawKeyDown) 165 initialKeyEvent.type() == WebInputEvent::RawKeyDown)
166 m_scrollManager->stopAutoscroll(); 166 m_scrollManager->stopAutoscroll();
167 167
168 // If we were in panscroll mode, we swallow the key event 168 // If we were in panscroll mode, we swallow the key event
169 return WebInputEventResult::HandledSuppressed; 169 return WebInputEventResult::HandledSuppressed;
170 } 170 }
171 171
172 // Check for cases where we are too early for events -- possible unmatched key 172 // Check for cases where we are too early for events -- possible unmatched key
173 // up from pressing return in the location bar. 173 // up from pressing return in the location bar.
174 Node* node = eventTargetNodeForDocument(m_frame->document()); 174 Node* node = eventTargetNodeForDocument(m_frame->document());
175 if (!node) 175 if (!node)
176 return WebInputEventResult::NotHandled; 176 return WebInputEventResult::NotHandled;
177 177
178 UserGestureIndicator gestureIndicator( 178 UserGestureIndicator gestureIndicator(
179 DocumentUserGestureToken::create(m_frame->document())); 179 DocumentUserGestureToken::create(m_frame->document()));
180 180
181 // In IE, access keys are special, they are handled after default keydown 181 // In IE, access keys are special, they are handled after default keydown
182 // processing, but cannot be canceled - this is hard to match. On Mac OS X, 182 // processing, but cannot be canceled - this is hard to match. On Mac OS X,
183 // we process them before dispatching keydown, as the default keydown handler 183 // we process them before dispatching keydown, as the default keydown handler
184 // implements Emacs key bindings, which may conflict with access keys. Then we 184 // implements Emacs key bindings, which may conflict with access keys. Then we
185 // dispatch keydown, but suppress its default handling. 185 // dispatch keydown, but suppress its default handling.
186 // On Windows, WebKit explicitly calls handleAccessKey() instead of 186 // On Windows, WebKit explicitly calls handleAccessKey() instead of
187 // dispatching a keypress event for WM_SYSCHAR messages. Other platforms 187 // dispatching a keypress event for WM_SYSCHAR messages. Other platforms
188 // currently match either Mac or Windows behavior, depending on whether they 188 // currently match either Mac or Windows behavior, depending on whether they
189 // send combined KeyDown events. 189 // send combined KeyDown events.
190 bool matchedAnAccessKey = false; 190 bool matchedAnAccessKey = false;
191 if (initialKeyEvent.type == WebInputEvent::KeyDown) 191 if (initialKeyEvent.type() == WebInputEvent::KeyDown)
192 matchedAnAccessKey = handleAccessKey(initialKeyEvent); 192 matchedAnAccessKey = handleAccessKey(initialKeyEvent);
193 193
194 // FIXME: it would be fair to let an input method handle KeyUp events before 194 // FIXME: it would be fair to let an input method handle KeyUp events before
195 // DOM dispatch. 195 // DOM dispatch.
196 if (initialKeyEvent.type == WebInputEvent::KeyUp || 196 if (initialKeyEvent.type() == WebInputEvent::KeyUp ||
197 initialKeyEvent.type == WebInputEvent::Char) { 197 initialKeyEvent.type() == WebInputEvent::Char) {
198 KeyboardEvent* domEvent = KeyboardEvent::create( 198 KeyboardEvent* domEvent = KeyboardEvent::create(
199 initialKeyEvent, m_frame->document()->domWindow()); 199 initialKeyEvent, m_frame->document()->domWindow());
200 200
201 return EventHandlingUtil::toWebInputEventResult( 201 return EventHandlingUtil::toWebInputEventResult(
202 node->dispatchEvent(domEvent)); 202 node->dispatchEvent(domEvent));
203 } 203 }
204 204
205 WebKeyboardEvent keyDownEvent = initialKeyEvent; 205 WebKeyboardEvent keyDownEvent = initialKeyEvent;
206 if (keyDownEvent.type != WebInputEvent::RawKeyDown) 206 if (keyDownEvent.type() != WebInputEvent::RawKeyDown)
207 keyDownEvent.setType(WebInputEvent::RawKeyDown); 207 keyDownEvent.setType(WebInputEvent::RawKeyDown);
208 KeyboardEvent* keydown = 208 KeyboardEvent* keydown =
209 KeyboardEvent::create(keyDownEvent, m_frame->document()->domWindow()); 209 KeyboardEvent::create(keyDownEvent, m_frame->document()->domWindow());
210 if (matchedAnAccessKey) 210 if (matchedAnAccessKey)
211 keydown->setDefaultPrevented(true); 211 keydown->setDefaultPrevented(true);
212 keydown->setTarget(node); 212 keydown->setTarget(node);
213 213
214 DispatchEventResult dispatchResult = node->dispatchEvent(keydown); 214 DispatchEventResult dispatchResult = node->dispatchEvent(keydown);
215 if (dispatchResult != DispatchEventResult::NotCanceled) 215 if (dispatchResult != DispatchEventResult::NotCanceled)
216 return EventHandlingUtil::toWebInputEventResult(dispatchResult); 216 return EventHandlingUtil::toWebInputEventResult(dispatchResult);
217 // If frame changed as a result of keydown dispatch, then return early to 217 // If frame changed as a result of keydown dispatch, then return early to
218 // avoid sending a subsequent keypress message to the new frame. 218 // avoid sending a subsequent keypress message to the new frame.
219 bool changedFocusedFrame = 219 bool changedFocusedFrame =
220 m_frame->page() && 220 m_frame->page() &&
221 m_frame != m_frame->page()->focusController().focusedOrMainFrame(); 221 m_frame != m_frame->page()->focusController().focusedOrMainFrame();
222 if (changedFocusedFrame) 222 if (changedFocusedFrame)
223 return WebInputEventResult::HandledSystem; 223 return WebInputEventResult::HandledSystem;
224 224
225 if (initialKeyEvent.type == WebInputEvent::RawKeyDown) 225 if (initialKeyEvent.type() == WebInputEvent::RawKeyDown)
226 return WebInputEventResult::NotHandled; 226 return WebInputEventResult::NotHandled;
227 227
228 // Focus may have changed during keydown handling, so refetch node. 228 // Focus may have changed during keydown handling, so refetch node.
229 // But if we are dispatching a fake backward compatibility keypress, then we 229 // But if we are dispatching a fake backward compatibility keypress, then we
230 // pretend that the keypress happened on the original node. 230 // pretend that the keypress happened on the original node.
231 node = eventTargetNodeForDocument(m_frame->document()); 231 node = eventTargetNodeForDocument(m_frame->document());
232 if (!node) 232 if (!node)
233 return WebInputEventResult::NotHandled; 233 return WebInputEventResult::NotHandled;
234 234
235 #if OS(MACOSX) 235 #if OS(MACOSX)
(...skipping 216 matching lines...) Expand 10 before | Expand all | Expand 10 after
452 if (currentModifiers & ::cmdKey) 452 if (currentModifiers & ::cmdKey)
453 modifiers |= WebInputEvent::MetaKey; 453 modifiers |= WebInputEvent::MetaKey;
454 #else 454 #else
455 // TODO(crbug.com/538289): Implement on other platforms. 455 // TODO(crbug.com/538289): Implement on other platforms.
456 return static_cast<WebInputEvent::Modifiers>(0); 456 return static_cast<WebInputEvent::Modifiers>(0);
457 #endif 457 #endif
458 return static_cast<WebInputEvent::Modifiers>(modifiers); 458 return static_cast<WebInputEvent::Modifiers>(modifiers);
459 } 459 }
460 460
461 } // namespace blink 461 } // namespace blink
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/core/input/GestureManager.cpp ('k') | third_party/WebKit/Source/core/input/MouseEventManager.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698