| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (C) 2014 Google Inc. All rights reserved. | 2 * Copyright (C) 2014 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 981 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 992 WebInputEvent::ShiftKey && | 992 WebInputEvent::ShiftKey && |
| 993 event.windowsKeyCode == VKEY_F10; | 993 event.windowsKeyCode == VKEY_F10; |
| 994 if ((isUnmodifiedMenuKey && | 994 if ((isUnmodifiedMenuKey && |
| 995 event.type == contextMenuKeyTriggeringEventType) || | 995 event.type == contextMenuKeyTriggeringEventType) || |
| 996 (isShiftF10 && event.type == shiftF10TriggeringEventType)) { | 996 (isShiftF10 && event.type == shiftF10TriggeringEventType)) { |
| 997 view()->sendContextMenuEvent(event); | 997 view()->sendContextMenuEvent(event); |
| 998 return WebInputEventResult::HandledSystem; | 998 return WebInputEventResult::HandledSystem; |
| 999 } | 999 } |
| 1000 #endif // !OS(MACOSX) | 1000 #endif // !OS(MACOSX) |
| 1001 | 1001 |
| 1002 return keyEventDefault(event); | 1002 return WebInputEventResult::NotHandled; |
| 1003 } | 1003 } |
| 1004 | 1004 |
| 1005 WebInputEventResult WebFrameWidgetImpl::handleCharEvent( | 1005 WebInputEventResult WebFrameWidgetImpl::handleCharEvent( |
| 1006 const WebKeyboardEvent& event) { | 1006 const WebKeyboardEvent& event) { |
| 1007 DCHECK_EQ(event.type, WebInputEvent::Char); | 1007 DCHECK_EQ(event.type, WebInputEvent::Char); |
| 1008 | 1008 |
| 1009 // Please refer to the comments explaining the m_suppressNextKeypressEvent | 1009 // Please refer to the comments explaining the m_suppressNextKeypressEvent |
| 1010 // member. The m_suppressNextKeypressEvent is set if the KeyDown is | 1010 // member. The m_suppressNextKeypressEvent is set if the KeyDown is |
| 1011 // handled by Webkit. A keyDown event is typically associated with a | 1011 // handled by Webkit. A keyDown event is typically associated with a |
| 1012 // keyPress(char) event and a keyUp event. We reset this flag here as it | 1012 // keyPress(char) event and a keyUp event. We reset this flag here as it |
| (...skipping 24 matching lines...) Expand all Loading... |
| 1037 if (event.isSystemKey) | 1037 if (event.isSystemKey) |
| 1038 return WebInputEventResult::NotHandled; | 1038 return WebInputEventResult::NotHandled; |
| 1039 | 1039 |
| 1040 if (suppress) | 1040 if (suppress) |
| 1041 return WebInputEventResult::HandledSuppressed; | 1041 return WebInputEventResult::HandledSuppressed; |
| 1042 | 1042 |
| 1043 WebInputEventResult result = handler.keyEvent(event); | 1043 WebInputEventResult result = handler.keyEvent(event); |
| 1044 if (result != WebInputEventResult::NotHandled) | 1044 if (result != WebInputEventResult::NotHandled) |
| 1045 return result; | 1045 return result; |
| 1046 | 1046 |
| 1047 return keyEventDefault(event); | |
| 1048 } | |
| 1049 | |
| 1050 WebInputEventResult WebFrameWidgetImpl::keyEventDefault( | |
| 1051 const WebKeyboardEvent& event) { | |
| 1052 LocalFrame* frame = toLocalFrame(focusedCoreFrame()); | |
| 1053 if (!frame) | |
| 1054 return WebInputEventResult::NotHandled; | |
| 1055 | |
| 1056 switch (event.type) { | |
| 1057 case WebInputEvent::Char: | |
| 1058 if (event.windowsKeyCode == VKEY_SPACE) { | |
| 1059 int keyCode = ((event.modifiers & WebInputEvent::ShiftKey) ? VKEY_PRIOR | |
| 1060 : VKEY_NEXT); | |
| 1061 return scrollViewWithKeyboard(keyCode, event.modifiers); | |
| 1062 } | |
| 1063 break; | |
| 1064 case WebInputEvent::KeyDown: | |
| 1065 case WebInputEvent::RawKeyDown: | |
| 1066 if (event.modifiers == WebInputEvent::ControlKey) { | |
| 1067 switch (event.windowsKeyCode) { | |
| 1068 #if !OS(MACOSX) | |
| 1069 case 'A': | |
| 1070 WebFrame::fromFrame(focusedCoreFrame()) | |
| 1071 ->toWebLocalFrame() | |
| 1072 ->executeCommand(WebString::fromUTF8("SelectAll")); | |
| 1073 return WebInputEventResult::HandledSystem; | |
| 1074 case VKEY_INSERT: | |
| 1075 case 'C': | |
| 1076 WebFrame::fromFrame(focusedCoreFrame()) | |
| 1077 ->toWebLocalFrame() | |
| 1078 ->executeCommand(WebString::fromUTF8("Copy")); | |
| 1079 return WebInputEventResult::HandledSystem; | |
| 1080 #endif | |
| 1081 // Match FF behavior in the sense that Ctrl+home/end are the only Ctrl | |
| 1082 // key combinations which affect scrolling. Safari is buggy in the | |
| 1083 // sense that it scrolls the page for all Ctrl+scrolling key | |
| 1084 // combinations. For e.g. Ctrl+pgup/pgdn/up/down, etc. | |
| 1085 case VKEY_HOME: | |
| 1086 case VKEY_END: | |
| 1087 break; | |
| 1088 default: | |
| 1089 return WebInputEventResult::NotHandled; | |
| 1090 } | |
| 1091 } | |
| 1092 if (!event.isSystemKey && !(event.modifiers & WebInputEvent::ShiftKey)) | |
| 1093 return scrollViewWithKeyboard(event.windowsKeyCode, event.modifiers); | |
| 1094 break; | |
| 1095 default: | |
| 1096 break; | |
| 1097 } | |
| 1098 return WebInputEventResult::NotHandled; | 1047 return WebInputEventResult::NotHandled; |
| 1099 } | 1048 } |
| 1100 | 1049 |
| 1101 WebInputEventResult WebFrameWidgetImpl::scrollViewWithKeyboard(int keyCode, | |
| 1102 int modifiers) { | |
| 1103 ScrollDirection scrollDirection; | |
| 1104 ScrollGranularity scrollGranularity; | |
| 1105 #if OS(MACOSX) | |
| 1106 // Control-Up/Down should be PageUp/Down on Mac. | |
| 1107 if (modifiers & WebMouseEvent::ControlKey) { | |
| 1108 if (keyCode == VKEY_UP) | |
| 1109 keyCode = VKEY_PRIOR; | |
| 1110 else if (keyCode == VKEY_DOWN) | |
| 1111 keyCode = VKEY_NEXT; | |
| 1112 } | |
| 1113 #endif | |
| 1114 if (!mapKeyCodeForScroll(keyCode, &scrollDirection, &scrollGranularity)) | |
| 1115 return WebInputEventResult::NotHandled; | |
| 1116 | |
| 1117 LocalFrame* frame = toLocalFrame(focusedCoreFrame()); | |
| 1118 if (frame && | |
| 1119 frame->eventHandler().bubblingScroll(scrollDirection, scrollGranularity)) | |
| 1120 return WebInputEventResult::HandledSystem; | |
| 1121 return WebInputEventResult::NotHandled; | |
| 1122 } | |
| 1123 | |
| 1124 bool WebFrameWidgetImpl::mapKeyCodeForScroll( | |
| 1125 int keyCode, | |
| 1126 ScrollDirection* scrollDirection, | |
| 1127 ScrollGranularity* scrollGranularity) { | |
| 1128 switch (keyCode) { | |
| 1129 case VKEY_LEFT: | |
| 1130 *scrollDirection = ScrollLeftIgnoringWritingMode; | |
| 1131 *scrollGranularity = ScrollByLine; | |
| 1132 break; | |
| 1133 case VKEY_RIGHT: | |
| 1134 *scrollDirection = ScrollRightIgnoringWritingMode; | |
| 1135 *scrollGranularity = ScrollByLine; | |
| 1136 break; | |
| 1137 case VKEY_UP: | |
| 1138 *scrollDirection = ScrollUpIgnoringWritingMode; | |
| 1139 *scrollGranularity = ScrollByLine; | |
| 1140 break; | |
| 1141 case VKEY_DOWN: | |
| 1142 *scrollDirection = ScrollDownIgnoringWritingMode; | |
| 1143 *scrollGranularity = ScrollByLine; | |
| 1144 break; | |
| 1145 case VKEY_HOME: | |
| 1146 *scrollDirection = ScrollUpIgnoringWritingMode; | |
| 1147 *scrollGranularity = ScrollByDocument; | |
| 1148 break; | |
| 1149 case VKEY_END: | |
| 1150 *scrollDirection = ScrollDownIgnoringWritingMode; | |
| 1151 *scrollGranularity = ScrollByDocument; | |
| 1152 break; | |
| 1153 case VKEY_PRIOR: // page up | |
| 1154 *scrollDirection = ScrollUpIgnoringWritingMode; | |
| 1155 *scrollGranularity = ScrollByPage; | |
| 1156 break; | |
| 1157 case VKEY_NEXT: // page down | |
| 1158 *scrollDirection = ScrollDownIgnoringWritingMode; | |
| 1159 *scrollGranularity = ScrollByPage; | |
| 1160 break; | |
| 1161 default: | |
| 1162 return false; | |
| 1163 } | |
| 1164 | |
| 1165 return true; | |
| 1166 } | |
| 1167 | |
| 1168 Frame* WebFrameWidgetImpl::focusedCoreFrame() const { | 1050 Frame* WebFrameWidgetImpl::focusedCoreFrame() const { |
| 1169 return page() ? page()->focusController().focusedOrMainFrame() : nullptr; | 1051 return page() ? page()->focusController().focusedOrMainFrame() : nullptr; |
| 1170 } | 1052 } |
| 1171 | 1053 |
| 1172 Element* WebFrameWidgetImpl::focusedElement() const { | 1054 Element* WebFrameWidgetImpl::focusedElement() const { |
| 1173 LocalFrame* frame = page()->focusController().focusedFrame(); | 1055 LocalFrame* frame = page()->focusController().focusedFrame(); |
| 1174 if (!frame) | 1056 if (!frame) |
| 1175 return nullptr; | 1057 return nullptr; |
| 1176 | 1058 |
| 1177 Document* document = frame->document(); | 1059 Document* document = frame->document(); |
| (...skipping 148 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1326 return nullptr; | 1208 return nullptr; |
| 1327 } | 1209 } |
| 1328 | 1210 |
| 1329 LocalFrame* WebFrameWidgetImpl::focusedLocalFrameAvailableForIme() const { | 1211 LocalFrame* WebFrameWidgetImpl::focusedLocalFrameAvailableForIme() const { |
| 1330 if (!m_imeAcceptEvents) | 1212 if (!m_imeAcceptEvents) |
| 1331 return nullptr; | 1213 return nullptr; |
| 1332 return focusedLocalFrameInWidget(); | 1214 return focusedLocalFrameInWidget(); |
| 1333 } | 1215 } |
| 1334 | 1216 |
| 1335 } // namespace blink | 1217 } // namespace blink |
| OLD | NEW |