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

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

Issue 1378583003: Unstrangle unhandled key event callback for webview (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: changed variable names and comments Created 5 years 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
« no previous file with comments | « third_party/WebKit/Source/core/input/EventHandler.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2006, 2007, 2008, 2009, 2010, 2011 Apple Inc. All rights reserv ed. 2 * Copyright (C) 2006, 2007, 2008, 2009, 2010, 2011 Apple Inc. All rights reserv ed.
3 * Copyright (C) 2006 Alexey Proskuryakov (ap@webkit.org) 3 * Copyright (C) 2006 Alexey Proskuryakov (ap@webkit.org)
4 * Copyright (C) 2012 Digia Plc. and/or its subsidiary(-ies) 4 * Copyright (C) 2012 Digia Plc. and/or its subsidiary(-ies)
5 * 5 *
6 * Redistribution and use in source and binary forms, with or without 6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions 7 * modification, are permitted provided that the following conditions
8 * are met: 8 * are met:
9 * 1. Redistributions of source code must retain the above copyright 9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer. 10 * notice, this list of conditions and the following disclaimer.
(...skipping 286 matching lines...) Expand 10 before | Expand all | Expand 10 after
297 , m_mouseDownTimestamp(0) 297 , m_mouseDownTimestamp(0)
298 , m_touchPressed(false) 298 , m_touchPressed(false)
299 , m_preventMouseEventForPointerTypeMouse(false) 299 , m_preventMouseEventForPointerTypeMouse(false)
300 , m_inPointerCanceledState(false) 300 , m_inPointerCanceledState(false)
301 , m_scrollGestureHandlingNode(nullptr) 301 , m_scrollGestureHandlingNode(nullptr)
302 , m_lastGestureScrollOverWidget(false) 302 , m_lastGestureScrollOverWidget(false)
303 , m_longTapShouldInvokeContextMenu(false) 303 , m_longTapShouldInvokeContextMenu(false)
304 , m_activeIntervalTimer(this, &EventHandler::activeIntervalTimerFired) 304 , m_activeIntervalTimer(this, &EventHandler::activeIntervalTimerFired)
305 , m_lastShowPressTimestamp(0) 305 , m_lastShowPressTimestamp(0)
306 , m_deltaConsumedForScrollSequence(false) 306 , m_deltaConsumedForScrollSequence(false)
307 , m_overrideNextKeyupEvent(false)
308 , m_returnValueForNextKeyupEvent(false)
307 { 309 {
308 } 310 }
309 311
310 EventHandler::~EventHandler() 312 EventHandler::~EventHandler()
311 { 313 {
312 ASSERT(!m_fakeMouseMoveEventTimer.isActive()); 314 ASSERT(!m_fakeMouseMoveEventTimer.isActive());
313 } 315 }
314 316
315 DEFINE_TRACE(EventHandler) 317 DEFINE_TRACE(EventHandler)
316 { 318 {
(...skipping 2826 matching lines...) Expand 10 before | Expand all | Expand 10 after
3143 String key = evt.unmodifiedText(); 3145 String key = evt.unmodifiedText();
3144 Element* elem = m_frame->document()->getElementByAccessKey(key.lower()); 3146 Element* elem = m_frame->document()->getElementByAccessKey(key.lower());
3145 if (!elem) 3147 if (!elem)
3146 return false; 3148 return false;
3147 elem->accessKeyAction(false); 3149 elem->accessKeyAction(false);
3148 return true; 3150 return true;
3149 } 3151 }
3150 3152
3151 bool EventHandler::keyEvent(const PlatformKeyboardEvent& initialKeyEvent) 3153 bool EventHandler::keyEvent(const PlatformKeyboardEvent& initialKeyEvent)
3152 { 3154 {
3155 bool overrideKeyupEvent = false;
dtapuska 2015/12/02 14:25:12 Not every keyup corresponds to a keydown. Ctrl-Tab
3156 bool returnValueForKeyupEvent = false;
3157 switch (initialKeyEvent.type()) {
3158 case PlatformEvent::KeyUp:
3159 overrideKeyupEvent = m_overrideNextKeyupEvent;
3160 returnValueForKeyupEvent = m_returnValueForNextKeyupEvent;
3161 m_returnValueForNextKeyupEvent = false;
3162 m_overrideNextKeyupEvent = false;
3163 break;
3164 case PlatformEvent::RawKeyDown:
3165 case PlatformEvent::KeyDown:
3166 m_returnValueForNextKeyupEvent = false;
3167 m_overrideNextKeyupEvent = false;
3168 break;
3169 default:
3170 break;
3171 }
3172
3153 RefPtrWillBeRawPtr<FrameView> protector(m_frame->view()); 3173 RefPtrWillBeRawPtr<FrameView> protector(m_frame->view());
3154 m_frame->chromeClient().setToolTip(String(), LTR); 3174 m_frame->chromeClient().setToolTip(String(), LTR);
3155 3175
3156 if (initialKeyEvent.windowsVirtualKeyCode() == VK_CAPITAL) 3176 if (initialKeyEvent.windowsVirtualKeyCode() == VK_CAPITAL)
3157 capsLockStateMayHaveChanged(); 3177 capsLockStateMayHaveChanged();
3158 3178
3159 #if OS(WIN) 3179 #if OS(WIN)
3160 if (panScrollInProgress()) { 3180 if (panScrollInProgress()) {
3161 // If a key is pressed while the panScroll is in progress then we want t o stop 3181 // If a key is pressed while the panScroll is in progress then we want t o stop
3162 if (initialKeyEvent.type() == PlatformEvent::KeyDown || initialKeyEvent. type() == PlatformEvent::RawKeyDown) 3182 if (initialKeyEvent.type() == PlatformEvent::KeyDown || initialKeyEvent. type() == PlatformEvent::RawKeyDown)
(...skipping 14 matching lines...) Expand all
3177 3197
3178 // In IE, access keys are special, they are handled after default keydown pr ocessing, but cannot be canceled - this is hard to match. 3198 // In IE, access keys are special, they are handled after default keydown pr ocessing, but cannot be canceled - this is hard to match.
3179 // On Mac OS X, we process them before dispatching keydown, as the default k eydown handler implements Emacs key bindings, which may conflict 3199 // On Mac OS X, we process them before dispatching keydown, as the default k eydown handler implements Emacs key bindings, which may conflict
3180 // with access keys. Then we dispatch keydown, but suppress its default hand ling. 3200 // with access keys. Then we dispatch keydown, but suppress its default hand ling.
3181 // On Windows, WebKit explicitly calls handleAccessKey() instead of dispatch ing a keypress event for WM_SYSCHAR messages. 3201 // On Windows, WebKit explicitly calls handleAccessKey() instead of dispatch ing a keypress event for WM_SYSCHAR messages.
3182 // Other platforms currently match either Mac or Windows behavior, depending on whether they send combined KeyDown events. 3202 // Other platforms currently match either Mac or Windows behavior, depending on whether they send combined KeyDown events.
3183 bool matchedAnAccessKey = false; 3203 bool matchedAnAccessKey = false;
3184 if (initialKeyEvent.type() == PlatformEvent::KeyDown) 3204 if (initialKeyEvent.type() == PlatformEvent::KeyDown)
3185 matchedAnAccessKey = handleAccessKey(initialKeyEvent); 3205 matchedAnAccessKey = handleAccessKey(initialKeyEvent);
3186 3206
3187 // FIXME: it would be fair to let an input method handle KeyUp events before DOM dispatch. 3207 if (initialKeyEvent.type() == PlatformEvent::Char) {
3188 if (initialKeyEvent.type() == PlatformEvent::KeyUp || initialKeyEvent.type() == PlatformEvent::Char) 3208 bool result = !node->dispatchKeyEvent(initialKeyEvent);
3189 return !node->dispatchKeyEvent(initialKeyEvent); 3209 if (m_overrideNextKeyupEvent) {
3210 m_returnValueForNextKeyupEvent |= result;
3211 }
3212 return result;
3213 }
3214
3215 if (initialKeyEvent.type() == PlatformEvent::KeyUp) {
3216 bool result = !node->dispatchKeyEvent(initialKeyEvent);
3217 return overrideKeyupEvent ? returnValueForKeyupEvent : result;
3218 }
3190 3219
3191 PlatformKeyboardEvent keyDownEvent = initialKeyEvent; 3220 PlatformKeyboardEvent keyDownEvent = initialKeyEvent;
3192 if (keyDownEvent.type() != PlatformEvent::RawKeyDown) 3221 if (keyDownEvent.type() != PlatformEvent::RawKeyDown)
3193 keyDownEvent.disambiguateKeyDownEvent(PlatformEvent::RawKeyDown); 3222 keyDownEvent.disambiguateKeyDownEvent(PlatformEvent::RawKeyDown);
3194 RefPtrWillBeRawPtr<KeyboardEvent> keydown = KeyboardEvent::create(keyDownEve nt, m_frame->document()->domWindow()); 3223 RefPtrWillBeRawPtr<KeyboardEvent> keydown = KeyboardEvent::create(keyDownEve nt, m_frame->document()->domWindow());
3195 if (matchedAnAccessKey) 3224 if (matchedAnAccessKey)
3196 keydown->setDefaultPrevented(true); 3225 keydown->setDefaultPrevented(true);
3197 keydown->setTarget(node); 3226 keydown->setTarget(node);
3198 3227
3199 if (initialKeyEvent.type() == PlatformEvent::RawKeyDown) { 3228 if (initialKeyEvent.type() == PlatformEvent::RawKeyDown) {
3200 node->dispatchEvent(keydown); 3229 node->dispatchEvent(keydown);
3201 // If frame changed as a result of keydown dispatch, then return true to avoid sending a subsequent keypress message to the new frame. 3230 // If frame changed as a result of keydown dispatch, then return true to avoid sending a subsequent keypress message to the new frame.
3202 bool changedFocusedFrame = m_frame->page() && m_frame != m_frame->page() ->focusController().focusedOrMainFrame(); 3231 bool changedFocusedFrame = m_frame->page() && m_frame != m_frame->page() ->focusController().focusedOrMainFrame();
3203 return keydown->defaultHandled() || keydown->defaultPrevented() || chang edFocusedFrame; 3232 bool result = keydown->defaultHandled() || keydown->defaultPrevented() | | changedFocusedFrame;
3233 // We are returning a value that may be different from the return value of dispatchEvent().
3234 // We should return the same value for the next keyup event.
3235 m_overrideNextKeyupEvent = true;
3236 m_returnValueForNextKeyupEvent = result;
3237 return result;
3204 } 3238 }
3205 3239
3206 node->dispatchEvent(keydown); 3240 node->dispatchEvent(keydown);
3207 // If frame changed as a result of keydown dispatch, then return early to av oid sending a subsequent keypress message to the new frame. 3241 // If frame changed as a result of keydown dispatch, then return early to av oid sending a subsequent keypress message to the new frame.
3208 bool changedFocusedFrame = m_frame->page() && m_frame != m_frame->page()->fo cusController().focusedOrMainFrame(); 3242 bool changedFocusedFrame = m_frame->page() && m_frame != m_frame->page()->fo cusController().focusedOrMainFrame();
3209 bool keydownResult = keydown->defaultHandled() || keydown->defaultPrevented( ) || changedFocusedFrame; 3243 bool keydownResult = keydown->defaultHandled() || keydown->defaultPrevented( ) || changedFocusedFrame;
3210 if (keydownResult) 3244 if (keydownResult)
3211 return keydownResult; 3245 return keydownResult;
3212 3246
3213 // Focus may have changed during keydown handling, so refetch node. 3247 // Focus may have changed during keydown handling, so refetch node.
(...skipping 874 matching lines...) Expand 10 before | Expand all | Expand 10 after
4088 PlatformEvent::Modifiers EventHandler::accessKeyModifiers() 4122 PlatformEvent::Modifiers EventHandler::accessKeyModifiers()
4089 { 4123 {
4090 #if OS(MACOSX) 4124 #if OS(MACOSX)
4091 return static_cast<PlatformEvent::Modifiers>(PlatformEvent::CtrlKey | Platfo rmEvent::AltKey); 4125 return static_cast<PlatformEvent::Modifiers>(PlatformEvent::CtrlKey | Platfo rmEvent::AltKey);
4092 #else 4126 #else
4093 return PlatformEvent::AltKey; 4127 return PlatformEvent::AltKey;
4094 #endif 4128 #endif
4095 } 4129 }
4096 4130
4097 } // namespace blink 4131 } // namespace blink
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/core/input/EventHandler.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698