| 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/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 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 53 else if (event->key() == "ArrowLeft") | 53 else if (event->key() == "ArrowLeft") |
| 54 retVal = WebFocusTypeLeft; | 54 retVal = WebFocusTypeLeft; |
| 55 else if (event->key() == "ArrowRight") | 55 else if (event->key() == "ArrowRight") |
| 56 retVal = WebFocusTypeRight; | 56 retVal = WebFocusTypeRight; |
| 57 return retVal; | 57 return retVal; |
| 58 } | 58 } |
| 59 | 59 |
| 60 bool mapKeyCodeForScroll(int keyCode, | 60 bool mapKeyCodeForScroll(int keyCode, |
| 61 WebInputEvent::Modifiers modifiers, | 61 WebInputEvent::Modifiers modifiers, |
| 62 ScrollDirection* scrollDirection, | 62 ScrollDirection* scrollDirection, |
| 63 ScrollGranularity* scrollGranularity) { | 63 ScrollGranularity* scrollGranularity, |
| 64 UseCounter::Feature* scrollUseUMA) { |
| 64 if (modifiers & WebInputEvent::ShiftKey || modifiers & WebInputEvent::MetaKey) | 65 if (modifiers & WebInputEvent::ShiftKey || modifiers & WebInputEvent::MetaKey) |
| 65 return false; | 66 return false; |
| 66 | 67 |
| 67 if (modifiers & WebInputEvent::AltKey) { | 68 if (modifiers & WebInputEvent::AltKey) { |
| 68 // Alt-Up/Down should behave like PageUp/Down on Mac. (Note that Alt-keys | 69 // Alt-Up/Down should behave like PageUp/Down on Mac. (Note that Alt-keys |
| 69 // on other platforms are suppressed due to isSystemKey being set.) | 70 // on other platforms are suppressed due to isSystemKey being set.) |
| 70 if (keyCode == VKEY_UP) | 71 if (keyCode == VKEY_UP) |
| 71 keyCode = VKEY_PRIOR; | 72 keyCode = VKEY_PRIOR; |
| 72 else if (keyCode == VKEY_DOWN) | 73 else if (keyCode == VKEY_DOWN) |
| 73 keyCode = VKEY_NEXT; | 74 keyCode = VKEY_NEXT; |
| 74 else | 75 else |
| 75 return false; | 76 return false; |
| 76 } | 77 } |
| 77 | 78 |
| 78 if (modifiers & WebInputEvent::ControlKey) { | 79 if (modifiers & WebInputEvent::ControlKey) { |
| 79 // Match FF behavior in the sense that Ctrl+home/end are the only Ctrl | 80 // Match FF behavior in the sense that Ctrl+home/end are the only Ctrl |
| 80 // key combinations which affect scrolling. | 81 // key combinations which affect scrolling. |
| 81 if (keyCode != VKEY_HOME && keyCode != VKEY_END) | 82 if (keyCode != VKEY_HOME && keyCode != VKEY_END) |
| 82 return false; | 83 return false; |
| 83 } | 84 } |
| 84 | 85 |
| 85 switch (keyCode) { | 86 switch (keyCode) { |
| 86 case VKEY_LEFT: | 87 case VKEY_LEFT: |
| 87 *scrollDirection = ScrollLeftIgnoringWritingMode; | 88 *scrollDirection = ScrollLeftIgnoringWritingMode; |
| 88 *scrollGranularity = ScrollByLine; | 89 *scrollGranularity = ScrollByLine; |
| 90 *scrollUseUMA = UseCounter::ScrollByKeyboardArrowKeys; |
| 89 break; | 91 break; |
| 90 case VKEY_RIGHT: | 92 case VKEY_RIGHT: |
| 91 *scrollDirection = ScrollRightIgnoringWritingMode; | 93 *scrollDirection = ScrollRightIgnoringWritingMode; |
| 92 *scrollGranularity = ScrollByLine; | 94 *scrollGranularity = ScrollByLine; |
| 95 *scrollUseUMA = UseCounter::ScrollByKeyboardArrowKeys; |
| 93 break; | 96 break; |
| 94 case VKEY_UP: | 97 case VKEY_UP: |
| 95 *scrollDirection = ScrollUpIgnoringWritingMode; | 98 *scrollDirection = ScrollUpIgnoringWritingMode; |
| 96 *scrollGranularity = ScrollByLine; | 99 *scrollGranularity = ScrollByLine; |
| 100 *scrollUseUMA = UseCounter::ScrollByKeyboardArrowKeys; |
| 97 break; | 101 break; |
| 98 case VKEY_DOWN: | 102 case VKEY_DOWN: |
| 99 *scrollDirection = ScrollDownIgnoringWritingMode; | 103 *scrollDirection = ScrollDownIgnoringWritingMode; |
| 100 *scrollGranularity = ScrollByLine; | 104 *scrollGranularity = ScrollByLine; |
| 105 *scrollUseUMA = UseCounter::ScrollByKeyboardArrowKeys; |
| 101 break; | 106 break; |
| 102 case VKEY_HOME: | 107 case VKEY_HOME: |
| 103 *scrollDirection = ScrollUpIgnoringWritingMode; | 108 *scrollDirection = ScrollUpIgnoringWritingMode; |
| 104 *scrollGranularity = ScrollByDocument; | 109 *scrollGranularity = ScrollByDocument; |
| 110 *scrollUseUMA = UseCounter::ScrollByKeyboardHomeEndKeys; |
| 105 break; | 111 break; |
| 106 case VKEY_END: | 112 case VKEY_END: |
| 107 *scrollDirection = ScrollDownIgnoringWritingMode; | 113 *scrollDirection = ScrollDownIgnoringWritingMode; |
| 108 *scrollGranularity = ScrollByDocument; | 114 *scrollGranularity = ScrollByDocument; |
| 115 *scrollUseUMA = UseCounter::ScrollByKeyboardHomeEndKeys; |
| 109 break; | 116 break; |
| 110 case VKEY_PRIOR: // page up | 117 case VKEY_PRIOR: // page up |
| 111 *scrollDirection = ScrollUpIgnoringWritingMode; | 118 *scrollDirection = ScrollUpIgnoringWritingMode; |
| 112 *scrollGranularity = ScrollByPage; | 119 *scrollGranularity = ScrollByPage; |
| 120 *scrollUseUMA = UseCounter::ScrollByKeyboardPageUpDownKeys; |
| 113 break; | 121 break; |
| 114 case VKEY_NEXT: // page down | 122 case VKEY_NEXT: // page down |
| 115 *scrollDirection = ScrollDownIgnoringWritingMode; | 123 *scrollDirection = ScrollDownIgnoringWritingMode; |
| 116 *scrollGranularity = ScrollByPage; | 124 *scrollGranularity = ScrollByPage; |
| 125 *scrollUseUMA = UseCounter::ScrollByKeyboardPageUpDownKeys; |
| 117 break; | 126 break; |
| 118 default: | 127 default: |
| 119 return false; | 128 return false; |
| 120 } | 129 } |
| 121 | 130 |
| 122 return true; | 131 return true; |
| 123 } | 132 } |
| 124 | 133 |
| 125 } // namespace | 134 } // namespace |
| 126 | 135 |
| (...skipping 174 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 301 | 310 |
| 302 if (event->ctrlKey() || event->metaKey() || event->altKey()) | 311 if (event->ctrlKey() || event->metaKey() || event->altKey()) |
| 303 return; | 312 return; |
| 304 | 313 |
| 305 ScrollDirection direction = event->shiftKey() ? ScrollBlockDirectionBackward | 314 ScrollDirection direction = event->shiftKey() ? ScrollBlockDirectionBackward |
| 306 : ScrollBlockDirectionForward; | 315 : ScrollBlockDirectionForward; |
| 307 | 316 |
| 308 // FIXME: enable scroll customization in this case. See crbug.com/410974. | 317 // FIXME: enable scroll customization in this case. See crbug.com/410974. |
| 309 if (m_scrollManager->logicalScroll(direction, ScrollByPage, nullptr, | 318 if (m_scrollManager->logicalScroll(direction, ScrollByPage, nullptr, |
| 310 possibleFocusedNode)) { | 319 possibleFocusedNode)) { |
| 320 UseCounter::count(m_frame->document(), |
| 321 UseCounter::ScrollByKeyboardSpacebarKey); |
| 311 event->setDefaultHandled(); | 322 event->setDefaultHandled(); |
| 312 return; | 323 return; |
| 313 } | 324 } |
| 314 } | 325 } |
| 315 | 326 |
| 316 void KeyboardEventManager::defaultBackspaceEventHandler(KeyboardEvent* event) { | 327 void KeyboardEventManager::defaultBackspaceEventHandler(KeyboardEvent* event) { |
| 317 DCHECK_EQ(event->type(), EventTypeNames::keydown); | 328 DCHECK_EQ(event->type(), EventTypeNames::keydown); |
| 318 | 329 |
| 319 if (!RuntimeEnabledFeatures::backspaceDefaultHandlerEnabled()) | 330 if (!RuntimeEnabledFeatures::backspaceDefaultHandlerEnabled()) |
| 320 return; | 331 return; |
| (...skipping 28 matching lines...) Expand all Loading... |
| 349 event->setDefaultHandled(); | 360 event->setDefaultHandled(); |
| 350 return; | 361 return; |
| 351 } | 362 } |
| 352 } | 363 } |
| 353 | 364 |
| 354 if (event->keyEvent() && event->keyEvent()->isSystemKey) | 365 if (event->keyEvent() && event->keyEvent()->isSystemKey) |
| 355 return; | 366 return; |
| 356 | 367 |
| 357 ScrollDirection scrollDirection; | 368 ScrollDirection scrollDirection; |
| 358 ScrollGranularity scrollGranularity; | 369 ScrollGranularity scrollGranularity; |
| 370 UseCounter::Feature scrollUseUMA; |
| 359 if (!mapKeyCodeForScroll(event->keyCode(), event->modifiers(), | 371 if (!mapKeyCodeForScroll(event->keyCode(), event->modifiers(), |
| 360 &scrollDirection, &scrollGranularity)) | 372 &scrollDirection, &scrollGranularity, &scrollUseUMA)) |
| 361 return; | 373 return; |
| 362 | 374 |
| 363 if (m_scrollManager->bubblingScroll(scrollDirection, scrollGranularity, | 375 if (m_scrollManager->bubblingScroll(scrollDirection, scrollGranularity, |
| 364 nullptr, possibleFocusedNode)) { | 376 nullptr, possibleFocusedNode)) { |
| 377 UseCounter::count(m_frame->document(), scrollUseUMA); |
| 365 event->setDefaultHandled(); | 378 event->setDefaultHandled(); |
| 366 return; | 379 return; |
| 367 } | 380 } |
| 368 } | 381 } |
| 369 | 382 |
| 370 void KeyboardEventManager::defaultTabEventHandler(KeyboardEvent* event) { | 383 void KeyboardEventManager::defaultTabEventHandler(KeyboardEvent* event) { |
| 371 DCHECK_EQ(event->type(), EventTypeNames::keydown); | 384 DCHECK_EQ(event->type(), EventTypeNames::keydown); |
| 372 | 385 |
| 373 // We should only advance focus on tabs if no special modifier keys are held | 386 // We should only advance focus on tabs if no special modifier keys are held |
| 374 // down. | 387 // down. |
| (...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 455 if (currentModifiers & ::cmdKey) | 468 if (currentModifiers & ::cmdKey) |
| 456 modifiers |= WebInputEvent::MetaKey; | 469 modifiers |= WebInputEvent::MetaKey; |
| 457 #else | 470 #else |
| 458 // TODO(crbug.com/538289): Implement on other platforms. | 471 // TODO(crbug.com/538289): Implement on other platforms. |
| 459 return static_cast<WebInputEvent::Modifiers>(0); | 472 return static_cast<WebInputEvent::Modifiers>(0); |
| 460 #endif | 473 #endif |
| 461 return static_cast<WebInputEvent::Modifiers>(modifiers); | 474 return static_cast<WebInputEvent::Modifiers>(modifiers); |
| 462 } | 475 } |
| 463 | 476 |
| 464 } // namespace blink | 477 } // namespace blink |
| OLD | NEW |