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

Side by Side Diff: chrome/browser/extensions/api/input_ime/input_ime_api.cc

Issue 1055673002: [Extensions API] Remove inline enums (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Latest master Created 5 years, 8 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 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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/api/input_ime/input_ime_api.h" 5 #include "chrome/browser/extensions/api/input_ime/input_ime_api.h"
6 6
7 #include "base/strings/string_number_conversions.h" 7 #include "base/strings/string_number_conversions.h"
8 #include "base/values.h" 8 #include "base/values.h"
9 #include "chrome/browser/chromeos/input_method/input_method_engine.h" 9 #include "chrome/browser/chromeos/input_method/input_method_engine.h"
10 #include "chrome/browser/chromeos/login/lock/screen_locker.h" 10 #include "chrome/browser/chromeos/login/lock/screen_locker.h"
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
52 52
53 void SetMenuItemToMenu(const input_ime::MenuItem& input, 53 void SetMenuItemToMenu(const input_ime::MenuItem& input,
54 InputMethodEngineInterface::MenuItem* out) { 54 InputMethodEngineInterface::MenuItem* out) {
55 out->modified = 0; 55 out->modified = 0;
56 out->id = input.id; 56 out->id = input.id;
57 if (input.label) { 57 if (input.label) {
58 out->modified |= InputMethodEngineInterface::MENU_ITEM_MODIFIED_LABEL; 58 out->modified |= InputMethodEngineInterface::MENU_ITEM_MODIFIED_LABEL;
59 out->label = *input.label; 59 out->label = *input.label;
60 } 60 }
61 61
62 if (input.style != input_ime::MenuItem::STYLE_NONE) { 62 if (input.style != input_ime::MENU_ITEM_STYLE_NONE) {
63 out->modified |= InputMethodEngineInterface::MENU_ITEM_MODIFIED_STYLE; 63 out->modified |= InputMethodEngineInterface::MENU_ITEM_MODIFIED_STYLE;
64 out->style = static_cast<InputMethodEngineInterface::MenuItemStyle>( 64 out->style = static_cast<InputMethodEngineInterface::MenuItemStyle>(
65 input.style); 65 input.style);
66 } 66 }
67 67
68 if (input.visible) 68 if (input.visible)
69 out->modified |= InputMethodEngineInterface::MENU_ITEM_MODIFIED_VISIBLE; 69 out->modified |= InputMethodEngineInterface::MENU_ITEM_MODIFIED_VISIBLE;
70 out->visible = input.visible ? *input.visible : true; 70 out->visible = input.visible ? *input.visible : true;
71 71
72 if (input.checked) 72 if (input.checked)
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
128 128
129 ~ImeObserver() override {} 129 ~ImeObserver() override {}
130 130
131 void OnActivate(const std::string& component_id) override { 131 void OnActivate(const std::string& component_id) override {
132 if (extension_id_.empty() || 132 if (extension_id_.empty() ||
133 !HasListener(input_ime::OnActivate::kEventName)) 133 !HasListener(input_ime::OnActivate::kEventName))
134 return; 134 return;
135 135
136 scoped_ptr<base::ListValue> args(input_ime::OnActivate::Create( 136 scoped_ptr<base::ListValue> args(input_ime::OnActivate::Create(
137 component_id, 137 component_id,
138 input_ime::OnActivate::ParseScreen(GetCurrentScreenType()))); 138 input_ime::ParseScreenType(GetCurrentScreenType())));
139 139
140 DispatchEventToExtension( 140 DispatchEventToExtension(
141 extension_id_, input_ime::OnActivate::kEventName, args.Pass()); 141 extension_id_, input_ime::OnActivate::kEventName, args.Pass());
142 } 142 }
143 143
144 void OnDeactivated(const std::string& component_id) override { 144 void OnDeactivated(const std::string& component_id) override {
145 if (extension_id_.empty() || 145 if (extension_id_.empty() ||
146 !HasListener(input_ime::OnDeactivated::kEventName)) 146 !HasListener(input_ime::OnDeactivated::kEventName))
147 return; 147 return;
148 148
149 scoped_ptr<base::ListValue> args( 149 scoped_ptr<base::ListValue> args(
150 input_ime::OnDeactivated::Create(component_id)); 150 input_ime::OnDeactivated::Create(component_id));
151 151
152 DispatchEventToExtension( 152 DispatchEventToExtension(
153 extension_id_, input_ime::OnDeactivated::kEventName, args.Pass()); 153 extension_id_, input_ime::OnDeactivated::kEventName, args.Pass());
154 } 154 }
155 155
156 void OnFocus( 156 void OnFocus(
157 const InputMethodEngineInterface::InputContext& context) override { 157 const InputMethodEngineInterface::InputContext& context) override {
158 if (extension_id_.empty() || !HasListener(input_ime::OnFocus::kEventName)) 158 if (extension_id_.empty() || !HasListener(input_ime::OnFocus::kEventName))
159 return; 159 return;
160 160
161 input_ime::InputContext context_value; 161 input_ime::InputContext context_value;
162 context_value.context_id = context.id; 162 context_value.context_id = context.id;
163 context_value.type = input_ime::InputContext::ParseType(context.type); 163 context_value.type = input_ime::ParseInputContextType(context.type);
164 context_value.auto_correct = context.auto_correct; 164 context_value.auto_correct = context.auto_correct;
165 context_value.auto_complete = context.auto_complete; 165 context_value.auto_complete = context.auto_complete;
166 context_value.spell_check = context.spell_check; 166 context_value.spell_check = context.spell_check;
167 167
168 scoped_ptr<base::ListValue> args(input_ime::OnFocus::Create(context_value)); 168 scoped_ptr<base::ListValue> args(input_ime::OnFocus::Create(context_value));
169 169
170 DispatchEventToExtension( 170 DispatchEventToExtension(
171 extension_id_, input_ime::OnFocus::kEventName, args.Pass()); 171 extension_id_, input_ime::OnFocus::kEventName, args.Pass());
172 } 172 }
173 173
174 void OnBlur(int context_id) override { 174 void OnBlur(int context_id) override {
175 if (extension_id_.empty() || !HasListener(input_ime::OnBlur::kEventName)) 175 if (extension_id_.empty() || !HasListener(input_ime::OnBlur::kEventName))
176 return; 176 return;
177 177
178 scoped_ptr<base::ListValue> args(input_ime::OnBlur::Create(context_id)); 178 scoped_ptr<base::ListValue> args(input_ime::OnBlur::Create(context_id));
179 179
180 DispatchEventToExtension( 180 DispatchEventToExtension(
181 extension_id_, input_ime::OnBlur::kEventName, args.Pass()); 181 extension_id_, input_ime::OnBlur::kEventName, args.Pass());
182 } 182 }
183 183
184 void OnInputContextUpdate( 184 void OnInputContextUpdate(
185 const InputMethodEngineInterface::InputContext& context) override { 185 const InputMethodEngineInterface::InputContext& context) override {
186 if (extension_id_.empty() || 186 if (extension_id_.empty() ||
187 !HasListener(input_ime::OnInputContextUpdate::kEventName)) 187 !HasListener(input_ime::OnInputContextUpdate::kEventName))
188 return; 188 return;
189 189
190 input_ime::InputContext context_value; 190 input_ime::InputContext context_value;
191 context_value.context_id = context.id; 191 context_value.context_id = context.id;
192 context_value.type = input_ime::InputContext::ParseType(context.type); 192 context_value.type = input_ime::ParseInputContextType(context.type);
193 193
194 scoped_ptr<base::ListValue> args( 194 scoped_ptr<base::ListValue> args(
195 input_ime::OnInputContextUpdate::Create(context_value)); 195 input_ime::OnInputContextUpdate::Create(context_value));
196 196
197 DispatchEventToExtension(extension_id_, 197 DispatchEventToExtension(extension_id_,
198 input_ime::OnInputContextUpdate::kEventName, 198 input_ime::OnInputContextUpdate::kEventName,
199 args.Pass()); 199 args.Pass());
200 } 200 }
201 201
202 void OnKeyEvent(const std::string& component_id, 202 void OnKeyEvent(const std::string& component_id,
(...skipping 11 matching lines...) Expand all
214 return; 214 return;
215 } 215 }
216 216
217 extensions::InputImeEventRouter* ime_event_router = 217 extensions::InputImeEventRouter* ime_event_router =
218 extensions::InputImeEventRouter::GetInstance(); 218 extensions::InputImeEventRouter::GetInstance();
219 219
220 const std::string request_id = 220 const std::string request_id =
221 ime_event_router->AddRequest(component_id, key_data); 221 ime_event_router->AddRequest(component_id, key_data);
222 222
223 input_ime::KeyboardEvent key_data_value; 223 input_ime::KeyboardEvent key_data_value;
224 key_data_value.type = input_ime::KeyboardEvent::ParseType(event.type); 224 key_data_value.type = input_ime::ParseKeyboardEventType(event.type);
225 key_data_value.request_id = request_id; 225 key_data_value.request_id = request_id;
226 if (!event.extension_id.empty()) 226 if (!event.extension_id.empty())
227 key_data_value.extension_id.reset(new std::string(event.extension_id)); 227 key_data_value.extension_id.reset(new std::string(event.extension_id));
228 key_data_value.key = event.key; 228 key_data_value.key = event.key;
229 key_data_value.code = event.code; 229 key_data_value.code = event.code;
230 key_data_value.alt_key.reset(new bool(event.alt_key)); 230 key_data_value.alt_key.reset(new bool(event.alt_key));
231 key_data_value.ctrl_key.reset(new bool(event.ctrl_key)); 231 key_data_value.ctrl_key.reset(new bool(event.ctrl_key));
232 key_data_value.shift_key.reset(new bool(event.shift_key)); 232 key_data_value.shift_key.reset(new bool(event.shift_key));
233 key_data_value.caps_lock.reset(new bool(event.caps_lock)); 233 key_data_value.caps_lock.reset(new bool(event.caps_lock));
234 234
235 scoped_ptr<base::ListValue> args( 235 scoped_ptr<base::ListValue> args(
236 input_ime::OnKeyEvent::Create(component_id, key_data_value)); 236 input_ime::OnKeyEvent::Create(component_id, key_data_value));
237 237
238 DispatchEventToExtension( 238 DispatchEventToExtension(
239 extension_id_, input_ime::OnKeyEvent::kEventName, args.Pass()); 239 extension_id_, input_ime::OnKeyEvent::kEventName, args.Pass());
240 } 240 }
241 241
242 void OnCandidateClicked( 242 void OnCandidateClicked(
243 const std::string& component_id, 243 const std::string& component_id,
244 int candidate_id, 244 int candidate_id,
245 InputMethodEngineInterface::MouseButtonEvent button) override { 245 InputMethodEngineInterface::MouseButtonEvent button) override {
246 if (extension_id_.empty() || 246 if (extension_id_.empty() ||
247 !HasListener(input_ime::OnCandidateClicked::kEventName)) 247 !HasListener(input_ime::OnCandidateClicked::kEventName))
248 return; 248 return;
249 249
250 input_ime::OnCandidateClicked::Button button_enum = 250 input_ime::MouseButton button_enum = input_ime::MOUSE_BUTTON_NONE;
251 input_ime::OnCandidateClicked::BUTTON_NONE;
252 switch (button) { 251 switch (button) {
253 case InputMethodEngineInterface::MOUSE_BUTTON_MIDDLE: 252 case InputMethodEngineInterface::MOUSE_BUTTON_MIDDLE:
254 button_enum = input_ime::OnCandidateClicked::BUTTON_MIDDLE; 253 button_enum = input_ime::MOUSE_BUTTON_MIDDLE;
255 break; 254 break;
256 255
257 case InputMethodEngineInterface::MOUSE_BUTTON_RIGHT: 256 case InputMethodEngineInterface::MOUSE_BUTTON_RIGHT:
258 button_enum = input_ime::OnCandidateClicked::BUTTON_RIGHT; 257 button_enum = input_ime::MOUSE_BUTTON_RIGHT;
259 break; 258 break;
260 259
261 case InputMethodEngineInterface::MOUSE_BUTTON_LEFT: 260 case InputMethodEngineInterface::MOUSE_BUTTON_LEFT:
262 // Default to left. 261 // Default to left.
263 default: 262 default:
264 button_enum = input_ime::OnCandidateClicked::BUTTON_LEFT; 263 button_enum = input_ime::MOUSE_BUTTON_LEFT;
265 break; 264 break;
266 } 265 }
267 266
268 scoped_ptr<base::ListValue> args(input_ime::OnCandidateClicked::Create( 267 scoped_ptr<base::ListValue> args(input_ime::OnCandidateClicked::Create(
269 component_id, candidate_id, button_enum)); 268 component_id, candidate_id, button_enum));
270 269
271 DispatchEventToExtension( 270 DispatchEventToExtension(
272 extension_id_, input_ime::OnCandidateClicked::kEventName, args.Pass()); 271 extension_id_, input_ime::OnCandidateClicked::kEventName, args.Pass());
273 } 272 }
274 273
(...skipping 269 matching lines...) Expand 10 before | Expand all | Expand 10 after
544 SetComposition::Params::Create(*args_)); 543 SetComposition::Params::Create(*args_));
545 const SetComposition::Params::Parameters& params = parent_params->parameters; 544 const SetComposition::Params::Parameters& params = parent_params->parameters;
546 std::vector<InputMethodEngineInterface::SegmentInfo> segments; 545 std::vector<InputMethodEngineInterface::SegmentInfo> segments;
547 if (params.segments) { 546 if (params.segments) {
548 const std::vector<linked_ptr< 547 const std::vector<linked_ptr<
549 SetComposition::Params::Parameters::SegmentsType> >& 548 SetComposition::Params::Parameters::SegmentsType> >&
550 segments_args = *params.segments; 549 segments_args = *params.segments;
551 for (size_t i = 0; i < segments_args.size(); ++i) { 550 for (size_t i = 0; i < segments_args.size(); ++i) {
552 EXTENSION_FUNCTION_VALIDATE( 551 EXTENSION_FUNCTION_VALIDATE(
553 segments_args[i]->style != 552 segments_args[i]->style !=
554 SetComposition::Params::Parameters::SegmentsType::STYLE_NONE); 553 input_ime::UNDERLINE_STYLE_NONE);
555 segments.push_back(InputMethodEngineInterface::SegmentInfo()); 554 segments.push_back(InputMethodEngineInterface::SegmentInfo());
556 segments.back().start = segments_args[i]->start; 555 segments.back().start = segments_args[i]->start;
557 segments.back().end = segments_args[i]->end; 556 segments.back().end = segments_args[i]->end;
558 if (segments_args[i]->style == 557 if (segments_args[i]->style ==
559 SetComposition::Params::Parameters::SegmentsType::STYLE_UNDERLINE) { 558 input_ime::UNDERLINE_STYLE_UNDERLINE) {
560 segments.back().style = 559 segments.back().style =
561 InputMethodEngineInterface::SEGMENT_STYLE_UNDERLINE; 560 InputMethodEngineInterface::SEGMENT_STYLE_UNDERLINE;
562 } else if (segments_args[i]->style == 561 } else if (segments_args[i]->style ==
563 SetComposition::Params::Parameters::SegmentsType:: 562 input_ime::UNDERLINE_STYLE_DOUBLEUNDERLINE) {
564 STYLE_DOUBLEUNDERLINE) {
565 segments.back().style = 563 segments.back().style =
566 InputMethodEngineInterface::SEGMENT_STYLE_DOUBLE_UNDERLINE; 564 InputMethodEngineInterface::SEGMENT_STYLE_DOUBLE_UNDERLINE;
567 } else { 565 } else {
568 segments.back().style = 566 segments.back().style =
569 InputMethodEngineInterface::SEGMENT_STYLE_NO_UNDERLINE; 567 InputMethodEngineInterface::SEGMENT_STYLE_NO_UNDERLINE;
570 } 568 }
571 } 569 }
572 } 570 }
573 571
574 int selection_start = 572 int selection_start =
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
641 error_ = kErrorEngineNotAvailable; 639 error_ = kErrorEngineNotAvailable;
642 return false; 640 return false;
643 } 641 }
644 642
645 const std::vector<linked_ptr<input_ime::KeyboardEvent> >& key_data = 643 const std::vector<linked_ptr<input_ime::KeyboardEvent> >& key_data =
646 params.key_data; 644 params.key_data;
647 std::vector<chromeos::InputMethodEngineInterface::KeyboardEvent> key_data_out; 645 std::vector<chromeos::InputMethodEngineInterface::KeyboardEvent> key_data_out;
648 646
649 for (size_t i = 0; i < key_data.size(); ++i) { 647 for (size_t i = 0; i < key_data.size(); ++i) {
650 chromeos::InputMethodEngineInterface::KeyboardEvent event; 648 chromeos::InputMethodEngineInterface::KeyboardEvent event;
651 event.type = input_ime::KeyboardEvent::ToString(key_data[i]->type); 649 event.type = input_ime::ToString(key_data[i]->type);
652 event.key = key_data[i]->key; 650 event.key = key_data[i]->key;
653 event.code = key_data[i]->code; 651 event.code = key_data[i]->code;
654 event.key_code = key_data[i]->key_code.get() ? *(key_data[i]->key_code) : 0; 652 event.key_code = key_data[i]->key_code.get() ? *(key_data[i]->key_code) : 0;
655 if (key_data[i]->alt_key) 653 if (key_data[i]->alt_key)
656 event.alt_key = *(key_data[i]->alt_key); 654 event.alt_key = *(key_data[i]->alt_key);
657 if (key_data[i]->ctrl_key) 655 if (key_data[i]->ctrl_key)
658 event.ctrl_key = *(key_data[i]->ctrl_key); 656 event.ctrl_key = *(key_data[i]->ctrl_key);
659 if (key_data[i]->shift_key) 657 if (key_data[i]->shift_key)
660 event.shift_key = *(key_data[i]->shift_key); 658 event.shift_key = *(key_data[i]->shift_key);
661 if (key_data[i]->caps_lock) 659 if (key_data[i]->caps_lock)
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
703 if (properties.vertical) { 701 if (properties.vertical) {
704 properties_out.is_vertical = *properties.vertical; 702 properties_out.is_vertical = *properties.vertical;
705 modified = true; 703 modified = true;
706 } 704 }
707 705
708 if (properties.page_size) { 706 if (properties.page_size) {
709 properties_out.page_size = *properties.page_size; 707 properties_out.page_size = *properties.page_size;
710 modified = true; 708 modified = true;
711 } 709 }
712 710
713 if (properties.window_position == 711 if (properties.window_position == input_ime::WINDOW_POSITION_COMPOSITION) {
714 SetCandidateWindowProperties::Params::Parameters::Properties::
715 WINDOW_POSITION_COMPOSITION) {
716 properties_out.show_window_at_composition = true; 712 properties_out.show_window_at_composition = true;
717 modified = true; 713 modified = true;
718 } else if (properties.window_position == 714 } else if (properties.window_position == input_ime::WINDOW_POSITION_CURSOR) {
719 SetCandidateWindowProperties::Params::Parameters::Properties::
720 WINDOW_POSITION_CURSOR) {
721 properties_out.show_window_at_composition = false; 715 properties_out.show_window_at_composition = false;
722 modified = true; 716 modified = true;
723 } 717 }
724 718
725 if (properties.auxiliary_text) { 719 if (properties.auxiliary_text) {
726 properties_out.auxiliary_text = *properties.auxiliary_text; 720 properties_out.auxiliary_text = *properties.auxiliary_text;
727 modified = true; 721 modified = true;
728 } 722 }
729 723
730 if (properties.auxiliary_text_visible) { 724 if (properties.auxiliary_text_visible) {
(...skipping 195 matching lines...) Expand 10 before | Expand all | Expand 10 after
926 // Notifies the IME extension for IME ready with onActivate/onFocus events. 920 // Notifies the IME extension for IME ready with onActivate/onFocus events.
927 if (engine) 921 if (engine)
928 engine->Enable(engine->GetActiveComponentId()); 922 engine->Enable(engine->GetActiveComponentId());
929 } 923 }
930 924
931 InputImeEventRouter* InputImeAPI::input_ime_event_router() { 925 InputImeEventRouter* InputImeAPI::input_ime_event_router() {
932 return InputImeEventRouter::GetInstance(); 926 return InputImeEventRouter::GetInstance();
933 } 927 }
934 928
935 } // namespace extensions 929 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698