Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 "chrome/browser/extensions/extension_input_api.h" | 5 #include "chrome/browser/extensions/extension_input_api.h" |
| 6 | 6 |
| 7 #include <string> | 7 #include <string> |
| 8 | 8 |
| 9 #include "base/string_util.h" | 9 #include "base/string_util.h" |
| 10 #include "base/values.h" | 10 #include "base/values.h" |
| 11 #include "chrome/browser/browser_window.h" | 11 #include "chrome/browser/browser_window.h" |
| 12 #include "chrome/browser/extensions/extension_tabs_module.h" | 12 #include "chrome/browser/extensions/extension_tabs_module.h" |
| 13 #include "chrome/browser/extensions/key_identifier_conversion_views.h" | |
| 13 #include "chrome/browser/renderer_host/render_view_host.h" | 14 #include "chrome/browser/renderer_host/render_view_host.h" |
| 14 #include "chrome/browser/ui/browser.h" | 15 #include "chrome/browser/ui/browser.h" |
| 15 #include "chrome/browser/ui/views/frame/browser_view.h" | 16 #include "chrome/browser/ui/views/frame/browser_view.h" |
| 16 #include "chrome/common/native_web_keyboard_event.h" | 17 #include "chrome/common/native_web_keyboard_event.h" |
| 17 #include "third_party/WebKit/Source/WebKit/chromium/public/WebInputEvent.h" | 18 #include "third_party/WebKit/Source/WebKit/chromium/public/WebInputEvent.h" |
| 18 #include "ui/base/keycodes/keyboard_code_conversion.h" | |
| 19 #include "views/event.h" | 19 #include "views/event.h" |
| 20 #include "views/widget/root_view.h" | 20 #include "views/widget/root_view.h" |
| 21 | 21 |
| 22 namespace { | 22 namespace { |
| 23 | 23 |
| 24 // Keys. | 24 // Keys. |
| 25 const char kType[] = "type"; | 25 const char kType[] = "type"; |
| 26 const char kKeyIdentifier[] = "keyIdentifier"; | 26 const char kKeyIdentifier[] = "keyIdentifier"; |
| 27 const char kAlt[] = "altKey"; | 27 const char kAlt[] = "altKey"; |
| 28 const char kCtrl[] = "ctrlKey"; | 28 const char kCtrl[] = "ctrlKey"; |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 79 views::Event::EventType type = GetTypeFromString(type_name); | 79 views::Event::EventType type = GetTypeFromString(type_name); |
| 80 if (type == views::Event::ET_UNKNOWN) { | 80 if (type == views::Event::ET_UNKNOWN) { |
| 81 error_ = kUnknownEventTypeError; | 81 error_ = kUnknownEventTypeError; |
| 82 return false; | 82 return false; |
| 83 } | 83 } |
| 84 | 84 |
| 85 std::string identifier; | 85 std::string identifier; |
| 86 EXTENSION_FUNCTION_VALIDATE(args->GetString(kKeyIdentifier, &identifier)); | 86 EXTENSION_FUNCTION_VALIDATE(args->GetString(kKeyIdentifier, &identifier)); |
| 87 TrimWhitespaceASCII(identifier, TRIM_ALL, &identifier); | 87 TrimWhitespaceASCII(identifier, TRIM_ALL, &identifier); |
| 88 | 88 |
| 89 ui::KeyboardCode code = ui::KeyCodeFromKeyIdentifier(identifier); | 89 const views::KeyEvent& prototype_event = |
| 90 if (code == ui::VKEY_UNKNOWN) { | 90 KeyEventFromKeyIdentifier(identifier); |
| 91 if (prototype_event.GetKeyCode() == ui::VKEY_UNKNOWN) { | |
| 91 error_ = kUnknownOrUnsupportedKeyIdentiferError; | 92 error_ = kUnknownOrUnsupportedKeyIdentiferError; |
| 92 return false; | 93 return false; |
| 93 } | 94 } |
| 94 | 95 |
| 95 int flags = 0; | 96 int flags = prototype_event.GetFlags(); |
| 96 bool alt = false; | 97 bool alt = false; |
| 97 if (args->GetBoolean(kAlt, &alt)) | 98 if (args->GetBoolean(kAlt, &alt)) |
| 98 flags |= alt ? WebKit::WebInputEvent::AltKey : 0; | 99 flags |= alt ? views::Event::EF_ALT_DOWN : 0; |
| 99 bool ctrl = false; | 100 bool ctrl = false; |
| 100 if (args->GetBoolean(kCtrl, &ctrl)) | 101 if (args->GetBoolean(kCtrl, &ctrl)) |
| 101 flags |= ctrl ? WebKit::WebInputEvent::ControlKey : 0; | 102 flags |= ctrl ? views::Event::EF_CONTROL_DOWN : 0; |
| 102 bool meta = false; | |
| 103 if (args->GetBoolean(kMeta, &meta)) | |
| 104 flags |= meta ? WebKit::WebInputEvent::MetaKey : 0; | |
| 105 bool shift = false; | 103 bool shift = false; |
| 106 if (args->GetBoolean(kShift, &shift)) | 104 if (args->GetBoolean(kShift, &shift)) |
| 107 flags |= shift ? WebKit::WebInputEvent::ShiftKey : 0; | 105 flags |= shift ? views::Event::EF_SHIFT_DOWN : 0; |
| 106 // Views does not have a Meta event flag, so ignore that argument | |
|
Erik does not do reviews
2011/01/31 06:28:35
nit: space above comment
Should this return an er
bryeung
2011/02/02 20:56:44
I've changed this to return an error.
My original
| |
| 108 | 107 |
| 109 views::RootView* root_view = GetRootView(); | 108 views::RootView* root_view = GetRootView(); |
| 110 if (!root_view) { | 109 if (!root_view) { |
| 111 error_ = kNoValidRecipientError; | 110 error_ = kNoValidRecipientError; |
| 112 return false; | 111 return false; |
| 113 } | 112 } |
| 114 | 113 |
| 115 views::KeyEvent event(type, code, flags, 0, 0); | 114 views::KeyEvent event(type, prototype_event.GetKeyCode(), flags, 0, 0); |
| 116 if (!root_view->ProcessKeyEvent(event)) { | 115 if (!root_view->ProcessKeyEvent(event)) { |
| 117 error_ = kKeyEventUnprocessedError; | 116 error_ = kKeyEventUnprocessedError; |
| 118 return false; | 117 return false; |
| 119 } | 118 } |
| 120 | 119 |
| 121 return true; | 120 return true; |
| 122 } | 121 } |
| OLD | NEW |