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

Side by Side Diff: third_party/WebKit/Source/core/editing/EditingBehavior.cpp

Issue 2290313002: Remove PlatformKeyboardEvent (Closed)
Patch Set: One more fix Created 4 years, 3 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 /* 1 /*
2 * Copyright (C) 2006, 2007 Apple, Inc. All rights reserved. 2 * Copyright (C) 2006, 2007 Apple, Inc. All rights reserved.
3 * Copyright (C) 2012 Google, Inc. All rights reserved. 3 * Copyright (C) 2012 Google, Inc. All rights reserved.
4 * 4 *
5 * Redistribution and use in source and binary forms, with or without 5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions 6 * modification, are permitted provided that the following conditions
7 * are met: 7 * are met:
8 * 1. Redistributions of source code must retain the above copyright 8 * 1. 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 * 2. Redistributions in binary form must reproduce the above copyright 10 * 2. Redistributions in binary form must reproduce the above copyright
(...skipping 10 matching lines...) Expand all
21 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY 21 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
22 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 22 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
23 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 23 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
24 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 24 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
25 */ 25 */
26 26
27 #include "core/editing/EditingBehavior.h" 27 #include "core/editing/EditingBehavior.h"
28 28
29 #include "core/events/KeyboardEvent.h" 29 #include "core/events/KeyboardEvent.h"
30 #include "platform/KeyboardCodes.h" 30 #include "platform/KeyboardCodes.h"
31 #include "platform/PlatformKeyboardEvent.h" 31 #include "public/platform/WebInputEvent.h"
32 32
33 namespace blink { 33 namespace blink {
34 34
35 namespace { 35 namespace {
36 36
37 // 37 //
38 // The below code was adapted from the WebKit file webview.cpp 38 // The below code was adapted from the WebKit file webview.cpp
39 // 39 //
40 40
41 const unsigned CtrlKey = 1 << 0; 41 const unsigned CtrlKey = WebInputEvent::ControlKey;
42 const unsigned AltKey = 1 << 1; 42 const unsigned AltKey = WebInputEvent::AltKey;
43 const unsigned ShiftKey = 1 << 2; 43 const unsigned ShiftKey = WebInputEvent::ShiftKey;
44 const unsigned MetaKey = 1 << 3; 44 const unsigned MetaKey = WebInputEvent::MetaKey;
45 #if OS(MACOSX) 45 #if OS(MACOSX)
46 // Aliases for the generic key defintions to make kbd shortcuts definitions more 46 // Aliases for the generic key defintions to make kbd shortcuts definitions more
47 // readable on OS X. 47 // readable on OS X.
48 const unsigned OptionKey = AltKey; 48 const unsigned OptionKey = AltKey;
49 49
50 // Do not use this constant for anything but cursor movement commands. Keys 50 // Do not use this constant for anything but cursor movement commands. Keys
51 // with cmd set have their |isSystemKey| bit set, so chances are the shortcut 51 // with cmd set have their |isSystemKey| bit set, so chances are the shortcut
52 // will not be executed. Another, less important, reason is that shortcuts 52 // will not be executed. Another, less important, reason is that shortcuts
53 // defined in the layoutObject do not blink the menu item that they triggered. S ee 53 // defined in the layoutObject do not blink the menu item that they triggered. S ee
54 // http://crbug.com/25856 and the bugs linked from there for details. 54 // http://crbug.com/25856 and the bugs linked from there for details.
(...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after
201 if (key == entry.key && modifiers == entry.modifiers) 201 if (key == entry.key && modifiers == entry.modifiers)
202 return entry.name; 202 return entry.name;
203 } 203 }
204 return nullptr; 204 return nullptr;
205 } 205 }
206 206
207 } // anonymous namespace 207 } // anonymous namespace
208 208
209 const char* EditingBehavior::interpretKeyEvent(const KeyboardEvent& event) const 209 const char* EditingBehavior::interpretKeyEvent(const KeyboardEvent& event) const
210 { 210 {
211 const PlatformKeyboardEvent* keyEvent = event.keyEvent(); 211 const WebKeyboardEvent* keyEvent = event.keyEvent();
212 if (!keyEvent) 212 if (!keyEvent)
213 return ""; 213 return "";
214 214
215 static HashMap<int, const char*>* keyDownCommandsMap = nullptr; 215 static HashMap<int, const char*>* keyDownCommandsMap = nullptr;
216 static HashMap<int, const char*>* keyPressCommandsMap = nullptr; 216 static HashMap<int, const char*>* keyPressCommandsMap = nullptr;
217 217
218 if (!keyDownCommandsMap) { 218 if (!keyDownCommandsMap) {
219 keyDownCommandsMap = new HashMap<int, const char*>; 219 keyDownCommandsMap = new HashMap<int, const char*>;
220 keyPressCommandsMap = new HashMap<int, const char*>; 220 keyPressCommandsMap = new HashMap<int, const char*>;
221 221
222 for (const auto& entry : kKeyboardCodeKeyDownEntries) { 222 for (const auto& entry : kKeyboardCodeKeyDownEntries) {
223 keyDownCommandsMap->set(entry.modifiers << 16 | entry.virtualKey, en try.name); 223 keyDownCommandsMap->set(entry.modifiers << 16 | entry.virtualKey, en try.name);
224 } 224 }
225 225
226 for (const auto& entry : kKeyboardCodeKeyPressEntries) { 226 for (const auto& entry : kKeyboardCodeKeyPressEntries) {
227 keyPressCommandsMap->set(entry.modifiers << 16 | entry.charCode, ent ry.name); 227 keyPressCommandsMap->set(entry.modifiers << 16 | entry.charCode, ent ry.name);
228 } 228 }
229 } 229 }
230 230
231 unsigned modifiers = 0; 231 unsigned modifiers = keyEvent->modifiers & (ShiftKey | AltKey | CtrlKey | Me taKey);
232 if (keyEvent->shiftKey())
233 modifiers |= ShiftKey;
234 if (keyEvent->altKey())
235 modifiers |= AltKey;
236 if (keyEvent->ctrlKey())
237 modifiers |= CtrlKey;
238 if (keyEvent->metaKey())
239 modifiers |= MetaKey;
240 232
241 if (keyEvent->type() == PlatformEvent::RawKeyDown) { 233 if (keyEvent->type == WebInputEvent::RawKeyDown) {
242 int mapKey = modifiers << 16 | event.keyCode(); 234 int mapKey = modifiers << 16 | event.keyCode();
243 const char* name = mapKey ? keyDownCommandsMap->get(mapKey) : nullptr; 235 const char* name = mapKey ? keyDownCommandsMap->get(mapKey) : nullptr;
244 if (!name) 236 if (!name)
245 name = lookupCommandNameFromDomKeyKeyDown(keyEvent->key(), modifiers ); 237 name = lookupCommandNameFromDomKeyKeyDown(event.key(), modifiers);
246 return name; 238 return name;
247 } 239 }
248 240
249 int mapKey = modifiers << 16 | event.charCode(); 241 int mapKey = modifiers << 16 | event.charCode();
250 return mapKey ? keyPressCommandsMap->get(mapKey) : 0; 242 return mapKey ? keyPressCommandsMap->get(mapKey) : 0;
251 } 243 }
252 244
253 bool EditingBehavior::shouldInsertCharacter(const KeyboardEvent& event) const 245 bool EditingBehavior::shouldInsertCharacter(const KeyboardEvent& event) const
254 { 246 {
255 if (event.keyEvent()->text().length() != 1) 247 if (event.keyEvent()->text[1] != 0)
256 return true; 248 return true;
257 249
258 // On Gtk/Linux, it emits key events with ASCII text and ctrl on for ctrl-<x >. 250 // On Gtk/Linux, it emits key events with ASCII text and ctrl on for ctrl-<x >.
259 // In Webkit, EditorClient::handleKeyboardEvent in 251 // In Webkit, EditorClient::handleKeyboardEvent in
260 // WebKit/gtk/WebCoreSupport/EditorClientGtk.cpp drop such events. 252 // WebKit/gtk/WebCoreSupport/EditorClientGtk.cpp drop such events.
261 // On Mac, it emits key events with ASCII text and meta on for Command-<x>. 253 // On Mac, it emits key events with ASCII text and meta on for Command-<x>.
262 // These key events should not emit text insert event. 254 // These key events should not emit text insert event.
263 // Alt key would be used to insert alternative character, so we should let 255 // Alt key would be used to insert alternative character, so we should let
264 // through. Also note that Ctrl-Alt combination equals to AltGr key which is 256 // through. Also note that Ctrl-Alt combination equals to AltGr key which is
265 // also used to insert alternative character. 257 // also used to insert alternative character.
266 // http://code.google.com/p/chromium/issues/detail?id=10846 258 // http://code.google.com/p/chromium/issues/detail?id=10846
267 // Windows sets both alt and meta are on when "Alt" key pressed. 259 // Windows sets both alt and meta are on when "Alt" key pressed.
268 // http://code.google.com/p/chromium/issues/detail?id=2215 260 // http://code.google.com/p/chromium/issues/detail?id=2215
269 // Also, we should not rely on an assumption that keyboards don't 261 // Also, we should not rely on an assumption that keyboards don't
270 // send ASCII characters when pressing a control key on Windows, 262 // send ASCII characters when pressing a control key on Windows,
271 // which may be configured to do it so by user. 263 // which may be configured to do it so by user.
272 // See also http://en.wikipedia.org/wiki/Keyboard_Layout 264 // See also http://en.wikipedia.org/wiki/Keyboard_Layout
273 // FIXME(ukai): investigate more detail for various keyboard layout. 265 // FIXME(ukai): investigate more detail for various keyboard layout.
274 UChar ch = event.keyEvent()->text()[0U]; 266 UChar ch = event.keyEvent()->text[0U];
275 267
276 // Don't insert null or control characters as they can result in 268 // Don't insert null or control characters as they can result in
277 // unexpected behaviour 269 // unexpected behaviour
278 if (ch < ' ') 270 if (ch < ' ')
279 return false; 271 return false;
280 #if !OS(WIN) 272 #if !OS(WIN)
281 // Don't insert ASCII character if ctrl w/o alt or meta is on. 273 // Don't insert ASCII character if ctrl w/o alt or meta is on.
282 // On Mac, we should ignore events when meta is on (Command-<x>). 274 // On Mac, we should ignore events when meta is on (Command-<x>).
283 if (ch < 0x80) { 275 if (ch < 0x80) {
284 if (event.keyEvent()->ctrlKey() && !event.keyEvent()->altKey()) 276 if (event.ctrlKey() && !event.altKey())
285 return false; 277 return false;
286 #if OS(MACOSX) 278 #if OS(MACOSX)
287 if (event.keyEvent()->metaKey()) 279 if (event.metaKey())
288 return false; 280 return false;
289 #endif 281 #endif
290 } 282 }
291 #endif 283 #endif
292 284
293 return true; 285 return true;
294 } 286 }
295 } // namespace blink 287 } // namespace blink
296 288
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698