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

Side by Side Diff: third_party/WebKit/Source/web/WebViewImpl.cpp

Issue 2430183002: Move arrow scrolling into KeyboardEventManager. (Closed)
Patch Set: Add keyEvent() null check to fix test Created 4 years, 1 month 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 /* 1 /*
2 * Copyright (C) 2011, 2012 Google Inc. All rights reserved. 2 * Copyright (C) 2011, 2012 Google Inc. All rights reserved.
3 * 3 *
4 * Redistribution and use in source and binary forms, with or without 4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are 5 * modification, are permitted provided that the following conditions are
6 * met: 6 * met:
7 * 7 *
8 * * Redistributions of source code must retain the above copyright 8 * * Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer. 9 * notice, this list of conditions and the following disclaimer.
10 * * Redistributions in binary form must reproduce the above 10 * * Redistributions in binary form must reproduce the above
(...skipping 1171 matching lines...) Expand 10 before | Expand all | Expand 10 after
1182 WebInputEvent::ShiftKey && 1182 WebInputEvent::ShiftKey &&
1183 event.windowsKeyCode == VKEY_F10; 1183 event.windowsKeyCode == VKEY_F10;
1184 if ((isUnmodifiedMenuKey && 1184 if ((isUnmodifiedMenuKey &&
1185 event.type == contextMenuKeyTriggeringEventType) || 1185 event.type == contextMenuKeyTriggeringEventType) ||
1186 (isShiftF10 && event.type == shiftF10TriggeringEventType)) { 1186 (isShiftF10 && event.type == shiftF10TriggeringEventType)) {
1187 sendContextMenuEvent(event); 1187 sendContextMenuEvent(event);
1188 return WebInputEventResult::HandledSystem; 1188 return WebInputEventResult::HandledSystem;
1189 } 1189 }
1190 #endif // !OS(MACOSX) 1190 #endif // !OS(MACOSX)
1191 1191
1192 if (keyEventDefault(event))
1193 return WebInputEventResult::HandledSystem;
1194 return WebInputEventResult::NotHandled; 1192 return WebInputEventResult::NotHandled;
1195 } 1193 }
1196 1194
1197 WebInputEventResult WebViewImpl::handleCharEvent( 1195 WebInputEventResult WebViewImpl::handleCharEvent(
1198 const WebKeyboardEvent& event) { 1196 const WebKeyboardEvent& event) {
1199 DCHECK_EQ(event.type, WebInputEvent::Char); 1197 DCHECK_EQ(event.type, WebInputEvent::Char);
1200 TRACE_EVENT1("input", "WebViewImpl::handleCharEvent", "text", 1198 TRACE_EVENT1("input", "WebViewImpl::handleCharEvent", "text",
1201 String(event.text).utf8()); 1199 String(event.text).utf8());
1202 1200
1203 // Please refer to the comments explaining the m_suppressNextKeypressEvent 1201 // Please refer to the comments explaining the m_suppressNextKeypressEvent
(...skipping 29 matching lines...) Expand all
1233 // events. 1231 // events.
1234 if (event.isSystemKey) 1232 if (event.isSystemKey)
1235 return WebInputEventResult::NotHandled; 1233 return WebInputEventResult::NotHandled;
1236 1234
1237 if (suppress) 1235 if (suppress)
1238 return WebInputEventResult::HandledSuppressed; 1236 return WebInputEventResult::HandledSuppressed;
1239 1237
1240 WebInputEventResult result = handler.keyEvent(event); 1238 WebInputEventResult result = handler.keyEvent(event);
1241 if (result != WebInputEventResult::NotHandled) 1239 if (result != WebInputEventResult::NotHandled)
1242 return result; 1240 return result;
1243 if (keyEventDefault(event))
1244 return WebInputEventResult::HandledSystem;
1245 1241
1246 return WebInputEventResult::NotHandled; 1242 return WebInputEventResult::NotHandled;
1247 } 1243 }
1248 1244
1249 WebRect WebViewImpl::computeBlockBound(const WebPoint& pointInRootFrame, 1245 WebRect WebViewImpl::computeBlockBound(const WebPoint& pointInRootFrame,
1250 bool ignoreClipping) { 1246 bool ignoreClipping) {
1251 if (!mainFrameImpl()) 1247 if (!mainFrameImpl())
1252 return WebRect(); 1248 return WebRect();
1253 1249
1254 // Use the point-based hit test to find the node. 1250 // Use the point-based hit test to find the node.
(...skipping 401 matching lines...) Expand 10 before | Expand all | Expand 10 after
1656 page()->contextMenuController().clearContextMenu(); 1652 page()->contextMenuController().clearContextMenu();
1657 { 1653 {
1658 ContextMenuAllowedScope scope; 1654 ContextMenuAllowedScope scope;
1659 if (LocalFrame* focusedFrame = 1655 if (LocalFrame* focusedFrame =
1660 toLocalFrame(page()->focusController().focusedOrMainFrame())) 1656 toLocalFrame(page()->focusController().focusedOrMainFrame()))
1661 focusedFrame->eventHandler().sendContextMenuEventForKey( 1657 focusedFrame->eventHandler().sendContextMenuEventForKey(
1662 element.unwrap<Element>()); 1658 element.unwrap<Element>());
1663 } 1659 }
1664 } 1660 }
1665 1661
1666 bool WebViewImpl::keyEventDefault(const WebKeyboardEvent& event) {
1667 LocalFrame* frame = toLocalFrame(focusedCoreFrame());
1668 if (!frame)
1669 return false;
1670
1671 switch (event.type) {
1672 case WebInputEvent::Char:
1673 if (event.windowsKeyCode == VKEY_SPACE) {
1674 int keyCode = ((event.modifiers & WebInputEvent::ShiftKey) ? VKEY_PRIOR
1675 : VKEY_NEXT);
1676 return scrollViewWithKeyboard(keyCode, event.modifiers);
1677 }
1678 break;
1679 case WebInputEvent::KeyDown:
1680 case WebInputEvent::RawKeyDown:
1681 if (event.modifiers == WebInputEvent::ControlKey) {
1682 switch (event.windowsKeyCode) {
1683 #if !OS(MACOSX)
1684 case 'A':
1685 focusedFrame()->executeCommand(WebString::fromUTF8("SelectAll"));
1686 return true;
1687 case VKEY_INSERT:
1688 case 'C':
1689 focusedFrame()->executeCommand(WebString::fromUTF8("Copy"));
1690 return true;
1691 #endif
1692 // Match FF behavior in the sense that Ctrl+home/end are the only Ctrl
1693 // key combinations which affect scrolling. Safari is buggy in the
1694 // sense that it scrolls the page for all Ctrl+scrolling key
1695 // combinations. For e.g. Ctrl+pgup/pgdn/up/down, etc.
1696 case VKEY_HOME:
1697 case VKEY_END:
1698 break;
1699 default:
1700 return false;
1701 }
1702 }
1703 if (!event.isSystemKey && !(event.modifiers & WebInputEvent::ShiftKey))
1704 return scrollViewWithKeyboard(event.windowsKeyCode, event.modifiers);
1705 break;
1706 default:
1707 break;
1708 }
1709 return false;
1710 }
1711
1712 bool WebViewImpl::scrollViewWithKeyboard(int keyCode, int modifiers) {
1713 ScrollDirectionPhysical scrollDirectionPhysical;
1714 ScrollGranularity scrollGranularity;
1715 #if OS(MACOSX)
1716 // Alt-Up/Down should be PageUp/Down on Mac.
1717 if (modifiers & WebMouseEvent::AltKey) {
1718 if (keyCode == VKEY_UP)
1719 keyCode = VKEY_PRIOR;
1720 else if (keyCode == VKEY_DOWN)
1721 keyCode = VKEY_NEXT;
1722 }
1723 #endif
1724 if (!mapKeyCodeForScroll(keyCode, &scrollDirectionPhysical,
1725 &scrollGranularity))
1726 return false;
1727
1728 if (LocalFrame* frame = toLocalFrame(focusedCoreFrame()))
1729 return frame->eventHandler().bubblingScroll(
1730 toScrollDirection(scrollDirectionPhysical), scrollGranularity);
1731 return false;
1732 }
1733
1734 bool WebViewImpl::mapKeyCodeForScroll(int keyCode,
1735 ScrollDirectionPhysical* scrollDirection,
1736 ScrollGranularity* scrollGranularity) {
1737 switch (keyCode) {
1738 case VKEY_LEFT:
1739 *scrollDirection = ScrollLeft;
1740 *scrollGranularity = ScrollByLine;
1741 break;
1742 case VKEY_RIGHT:
1743 *scrollDirection = ScrollRight;
1744 *scrollGranularity = ScrollByLine;
1745 break;
1746 case VKEY_UP:
1747 *scrollDirection = ScrollUp;
1748 *scrollGranularity = ScrollByLine;
1749 break;
1750 case VKEY_DOWN:
1751 *scrollDirection = ScrollDown;
1752 *scrollGranularity = ScrollByLine;
1753 break;
1754 case VKEY_HOME:
1755 *scrollDirection = ScrollUp;
1756 *scrollGranularity = ScrollByDocument;
1757 break;
1758 case VKEY_END:
1759 *scrollDirection = ScrollDown;
1760 *scrollGranularity = ScrollByDocument;
1761 break;
1762 case VKEY_PRIOR: // page up
1763 *scrollDirection = ScrollUp;
1764 *scrollGranularity = ScrollByPage;
1765 break;
1766 case VKEY_NEXT: // page down
1767 *scrollDirection = ScrollDown;
1768 *scrollGranularity = ScrollByPage;
1769 break;
1770 default:
1771 return false;
1772 }
1773
1774 return true;
1775 }
1776
1777 PagePopup* WebViewImpl::openPagePopup(PagePopupClient* client) { 1662 PagePopup* WebViewImpl::openPagePopup(PagePopupClient* client) {
1778 DCHECK(client); 1663 DCHECK(client);
1779 if (hasOpenedPopup()) 1664 if (hasOpenedPopup())
1780 hidePopups(); 1665 hidePopups();
1781 DCHECK(!m_pagePopup); 1666 DCHECK(!m_pagePopup);
1782 1667
1783 WebWidget* popupWidget = m_client->createPopupMenu(WebPopupTypePage); 1668 WebWidget* popupWidget = m_client->createPopupMenu(WebPopupTypePage);
1784 // createPopupMenu returns nullptr if this renderer process is about to die. 1669 // createPopupMenu returns nullptr if this renderer process is about to die.
1785 if (!popupWidget) 1670 if (!popupWidget)
1786 return nullptr; 1671 return nullptr;
(...skipping 2764 matching lines...) Expand 10 before | Expand all | Expand 10 after
4551 if (focusedFrame->localFrameRoot() != mainFrameImpl()->frame()) 4436 if (focusedFrame->localFrameRoot() != mainFrameImpl()->frame())
4552 return nullptr; 4437 return nullptr;
4553 return focusedFrame; 4438 return focusedFrame;
4554 } 4439 }
4555 4440
4556 LocalFrame* WebViewImpl::focusedLocalFrameAvailableForIme() const { 4441 LocalFrame* WebViewImpl::focusedLocalFrameAvailableForIme() const {
4557 return m_imeAcceptEvents ? focusedLocalFrameInWidget() : nullptr; 4442 return m_imeAcceptEvents ? focusedLocalFrameInWidget() : nullptr;
4558 } 4443 }
4559 4444
4560 } // namespace blink 4445 } // namespace blink
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/web/WebViewImpl.h ('k') | third_party/WebKit/Source/web/tests/WebViewTest.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698