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/chromeos/cros/cros_library.h" | |
| 12 #include "chrome/browser/chromeos/cros/input_method_library.h" | |
| 13 #include "chrome/browser/extensions/extension_tabs_module.h" | |
|
Mihai Parparita -not on Chrome
2011/04/27 23:34:51
Why do you need this include?
Yusuke Sato
2011/04/28 10:57:07
Removed, thanks.
On 2011/04/27 23:34:51, Mihai Pa
| |
| 11 #include "chrome/browser/extensions/key_identifier_conversion_views.h" | 14 #include "chrome/browser/extensions/key_identifier_conversion_views.h" |
| 12 #include "chrome/browser/ui/browser.h" | 15 #include "chrome/browser/ui/browser.h" |
| 13 #include "chrome/browser/ui/browser_window.h" | 16 #include "chrome/browser/ui/browser_window.h" |
| 14 #include "chrome/browser/ui/views/frame/browser_view.h" | 17 #include "chrome/browser/ui/views/frame/browser_view.h" |
| 15 #include "views/events/event.h" | 18 #include "views/events/event.h" |
| 16 #include "views/ime/input_method.h" | 19 #include "views/ime/input_method.h" |
| 17 #include "views/widget/widget.h" | 20 #include "views/widget/widget.h" |
| 18 | 21 |
| 19 namespace { | 22 namespace { |
| 20 | 23 |
| (...skipping 17 matching lines...) Expand all Loading... | |
| 38 | 41 |
| 39 ui::EventType GetTypeFromString(const std::string& type) { | 42 ui::EventType GetTypeFromString(const std::string& type) { |
| 40 if (type == kKeyDown) { | 43 if (type == kKeyDown) { |
| 41 return ui::ET_KEY_PRESSED; | 44 return ui::ET_KEY_PRESSED; |
| 42 } else if (type == kKeyUp) { | 45 } else if (type == kKeyUp) { |
| 43 return ui::ET_KEY_RELEASED; | 46 return ui::ET_KEY_RELEASED; |
| 44 } | 47 } |
| 45 return ui::ET_UNKNOWN; | 48 return ui::ET_UNKNOWN; |
| 46 } | 49 } |
| 47 | 50 |
| 51 bool GetDoubleValue( | |
|
Mihai Parparita -not on Chrome
2011/04/27 23:34:51
This is at least the third implementation of such
Yusuke Sato
2011/04/28 10:57:07
I did it in a separate CL. Please review http://co
Yusuke Sato
2011/05/02 07:01:02
Done.
| |
| 52 const DictionaryValue* dict, const char* key, double* result) { | |
|
Zachary Kuznia
2011/04/27 10:25:09
nit: This should fit on the previous line
Yusuke Sato
2011/04/28 10:57:07
I'll remove the function.
On 2011/04/27 10:25:09,
| |
| 53 int result_int = 0; | |
| 54 // Since number literals in JS like 0.0 and 1.0 are treated as Integers, we | |
| 55 // have to call GetInteger() first. | |
| 56 if (dict->GetInteger(key, &result_int)) { | |
| 57 *result = result_int; | |
| 58 return true; | |
| 59 } | |
| 60 return dict->GetDouble(key, result); | |
| 61 } | |
| 62 | |
| 48 } // namespace | 63 } // namespace |
| 49 | 64 |
| 50 void InputFunction::Run() { | 65 void InputFunction::Run() { |
| 51 SendResponse(RunImpl()); | 66 SendResponse(RunImpl()); |
| 52 } | 67 } |
| 53 | 68 |
| 54 views::Widget* SendKeyboardEventInputFunction::GetTopLevelWidget() { | 69 views::Widget* SendKeyboardEventInputFunction::GetTopLevelWidget() { |
| 55 Browser* browser = GetCurrentBrowser(); | 70 Browser* browser = GetCurrentBrowser(); |
| 56 if (!browser) | 71 if (!browser) |
| 57 return NULL; | 72 return NULL; |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 109 views::InputMethod* ime = widget->GetInputMethod(); | 124 views::InputMethod* ime = widget->GetInputMethod(); |
| 110 if (ime) { | 125 if (ime) { |
| 111 ime->DispatchKeyEvent(event); | 126 ime->DispatchKeyEvent(event); |
| 112 } else if (!widget->OnKeyEvent(event)) { | 127 } else if (!widget->OnKeyEvent(event)) { |
| 113 error_ = kKeyEventUnprocessedError; | 128 error_ = kKeyEventUnprocessedError; |
| 114 return false; | 129 return false; |
| 115 } | 130 } |
| 116 | 131 |
| 117 return true; | 132 return true; |
| 118 } | 133 } |
| 134 | |
| 135 bool SendHandwritingStrokesFunction::RunImpl() { | |
| 136 ListValue* value = NULL; | |
| 137 EXTENSION_FUNCTION_VALIDATE(args_->GetList(0, &value)); | |
| 138 | |
| 139 chromeos::HandwritingStrokes strokes; | |
| 140 for (size_t i = 0; i < value->GetSize(); ++i) { | |
| 141 DictionaryValue* dict; | |
| 142 double x = 0.0; | |
| 143 double y = 0.0; | |
| 144 EXTENSION_FUNCTION_VALIDATE(value->GetDictionary(i, &dict)); | |
| 145 EXTENSION_FUNCTION_VALIDATE(GetDoubleValue(dict, "x", &x)); | |
| 146 EXTENSION_FUNCTION_VALIDATE(GetDoubleValue(dict, "y", &y)); | |
| 147 strokes.push_back(std::make_pair(x, y)); | |
| 148 } | |
| 149 chromeos::CrosLibrary::Get()->GetInputMethodLibrary()-> | |
|
Mihai Parparita -not on Chrome
2011/04/27 23:34:51
Other extensions that use CrosLibrary check if it'
Yusuke Sato
2011/04/28 10:57:07
It's definitely better to have the check. Added. T
| |
| 150 SendHandwritingStrokes(strokes); | |
| 151 return true; | |
| 152 } | |
| 153 | |
| 154 bool CancelHandwritingFunction::RunImpl() { | |
| 155 int n_strokes = 0; // zero means 'clear all strokes'. | |
| 156 if (HasOptionalArgument(0)) { | |
| 157 EXTENSION_FUNCTION_VALIDATE(args_->GetInteger(0, &n_strokes)); | |
| 158 } | |
| 159 chromeos::CrosLibrary::Get()->GetInputMethodLibrary()-> | |
| 160 CancelHandwriting(n_strokes); | |
| 161 return true; | |
| 162 } | |
| OLD | NEW |