OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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/chromeos/input_method/input_method_engine.h" | 5 #include "chrome/browser/chromeos/input_method/input_method_engine.h" |
6 | 6 |
7 #undef FocusIn | 7 #undef FocusIn |
8 #undef FocusOut | 8 #undef FocusOut |
9 #undef RootWindow | 9 #undef RootWindow |
10 #include <map> | 10 #include <map> |
(...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
155 context_id_(0), | 155 context_id_(0), |
156 next_context_id_(1), | 156 next_context_id_(1), |
157 composition_text_(new CompositionText()), | 157 composition_text_(new CompositionText()), |
158 composition_cursor_(0), | 158 composition_cursor_(0), |
159 candidate_window_(new ui::CandidateWindow()), | 159 candidate_window_(new ui::CandidateWindow()), |
160 window_visible_(false), | 160 window_visible_(false), |
161 sent_key_event_(NULL) { | 161 sent_key_event_(NULL) { |
162 } | 162 } |
163 | 163 |
164 InputMethodEngine::~InputMethodEngine() { | 164 InputMethodEngine::~InputMethodEngine() { |
165 if (start_time_.ToInternalValue()) | |
166 RecordHistogram("WorkingTime", (end_time_ - start_time_).InSeconds()); | |
167 } | 165 } |
168 | 166 |
169 void InputMethodEngine::Initialize( | 167 void InputMethodEngine::Initialize( |
170 scoped_ptr<InputMethodEngineInterface::Observer> observer, | 168 scoped_ptr<InputMethodEngineInterface::Observer> observer, |
171 const char* extension_id) { | 169 const char* extension_id) { |
172 DCHECK(observer) << "Observer must not be null."; | 170 DCHECK(observer) << "Observer must not be null."; |
173 | 171 |
174 // TODO(komatsu): It is probably better to set observer out of Initialize. | 172 // TODO(komatsu): It is probably better to set observer out of Initialize. |
175 observer_ = observer.Pass(); | 173 observer_ = observer.Pass(); |
176 extension_id_ = extension_id; | 174 extension_id_ = extension_id; |
177 } | 175 } |
178 | 176 |
179 void InputMethodEngine::RecordHistogram(const char* name, int count) { | |
180 std::string histo_name = base::StringPrintf( | |
181 "InputMethod.%s.%s", name, active_component_id_.c_str()); | |
182 base::HistogramBase* counter = base::Histogram::FactoryGet( | |
183 histo_name, 0, 1000000, 50, base::HistogramBase::kNoFlags); | |
184 if (counter) | |
185 counter->Add(count); | |
186 } | |
187 | |
188 const std::string& InputMethodEngine::GetActiveComponentId() const { | 177 const std::string& InputMethodEngine::GetActiveComponentId() const { |
189 return active_component_id_; | 178 return active_component_id_; |
190 } | 179 } |
191 | 180 |
192 bool InputMethodEngine::SetComposition( | 181 bool InputMethodEngine::SetComposition( |
193 int context_id, | 182 int context_id, |
194 const char* text, | 183 const char* text, |
195 int selection_start, | 184 int selection_start, |
196 int selection_end, | 185 int selection_end, |
197 int cursor, | 186 int cursor, |
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
263 *error = kErrorNotActive; | 252 *error = kErrorNotActive; |
264 return false; | 253 return false; |
265 } | 254 } |
266 if (context_id != context_id_ || context_id_ == -1) { | 255 if (context_id != context_id_ || context_id_ == -1) { |
267 *error = kErrorWrongContext; | 256 *error = kErrorWrongContext; |
268 return false; | 257 return false; |
269 } | 258 } |
270 | 259 |
271 IMEBridge::Get()->GetInputContextHandler()->CommitText(text); | 260 IMEBridge::Get()->GetInputContextHandler()->CommitText(text); |
272 | 261 |
273 // Records times for using input method. | 262 // Records histograms for committed characters. |
274 if (!start_time_.ToInternalValue()) | 263 if (!composition_text_->text().empty()) { |
275 start_time_ = base::Time::Now(); | 264 size_t len = GetUtf8StringLength(text); |
276 end_time_ = base::Time::Now(); | 265 UMA_HISTOGRAM_CUSTOM_COUNTS("InputMethod.CommitLength", |
277 // Records histograms for counts of commits and committed characters. | 266 len, 1, 25, 25); |
278 RecordHistogram("Commit", 1); | 267 } |
279 RecordHistogram("CommitCharacter", GetUtf8StringLength(text)); | |
280 return true; | 268 return true; |
281 } | 269 } |
282 | 270 |
283 bool InputMethodEngine::SendKeyEvents( | 271 bool InputMethodEngine::SendKeyEvents( |
284 int context_id, | 272 int context_id, |
285 const std::vector<KeyboardEvent>& events) { | 273 const std::vector<KeyboardEvent>& events) { |
286 if (!IsActive()) { | 274 if (!IsActive()) { |
287 return false; | 275 return false; |
288 } | 276 } |
289 // context_id == 0, means sending key events to non-input field. | 277 // context_id == 0, means sending key events to non-input field. |
(...skipping 29 matching lines...) Expand all Loading... |
319 base::string16 key_char = base::UTF8ToUTF16(event.key); | 307 base::string16 key_char = base::UTF8ToUTF16(event.key); |
320 if (key_char.size() == 1) | 308 if (key_char.size() == 1) |
321 ui_event.set_character(key_char[0]); | 309 ui_event.set_character(key_char[0]); |
322 } | 310 } |
323 base::AutoReset<const ui::KeyEvent*> reset_sent_key(&sent_key_event_, | 311 base::AutoReset<const ui::KeyEvent*> reset_sent_key(&sent_key_event_, |
324 &ui_event); | 312 &ui_event); |
325 ui::EventDispatchDetails details = dispatcher->OnEventFromSource(&ui_event); | 313 ui::EventDispatchDetails details = dispatcher->OnEventFromSource(&ui_event); |
326 if (details.dispatcher_destroyed) | 314 if (details.dispatcher_destroyed) |
327 break; | 315 break; |
328 } | 316 } |
| 317 |
329 return true; | 318 return true; |
330 } | 319 } |
331 | 320 |
332 const InputMethodEngine::CandidateWindowProperty& | 321 const InputMethodEngine::CandidateWindowProperty& |
333 InputMethodEngine::GetCandidateWindowProperty() const { | 322 InputMethodEngine::GetCandidateWindowProperty() const { |
334 return candidate_window_property_; | 323 return candidate_window_property_; |
335 } | 324 } |
336 | 325 |
337 void InputMethodEngine::SetCandidateWindowProperty( | 326 void InputMethodEngine::SetCandidateWindowProperty( |
338 const CandidateWindowProperty& property) { | 327 const CandidateWindowProperty& property) { |
(...skipping 227 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
566 } | 555 } |
567 | 556 |
568 void InputMethodEngine::Enable(const std::string& component_id) { | 557 void InputMethodEngine::Enable(const std::string& component_id) { |
569 DCHECK(!component_id.empty()); | 558 DCHECK(!component_id.empty()); |
570 active_component_id_ = component_id; | 559 active_component_id_ = component_id; |
571 observer_->OnActivate(component_id); | 560 observer_->OnActivate(component_id); |
572 current_input_type_ = IMEBridge::Get()->GetCurrentTextInputType(); | 561 current_input_type_ = IMEBridge::Get()->GetCurrentTextInputType(); |
573 FocusIn(IMEEngineHandlerInterface::InputContext( | 562 FocusIn(IMEEngineHandlerInterface::InputContext( |
574 current_input_type_, ui::TEXT_INPUT_MODE_DEFAULT)); | 563 current_input_type_, ui::TEXT_INPUT_MODE_DEFAULT)); |
575 EnableInputView(); | 564 EnableInputView(); |
576 | |
577 start_time_ = base::Time(); | |
578 end_time_ = base::Time(); | |
579 RecordHistogram("Enable", 1); | |
580 } | 565 } |
581 | 566 |
582 void InputMethodEngine::Disable() { | 567 void InputMethodEngine::Disable() { |
583 active_component_id_.clear(); | 568 active_component_id_.clear(); |
584 observer_->OnDeactivated(active_component_id_); | 569 observer_->OnDeactivated(active_component_id_); |
585 | |
586 if (start_time_.ToInternalValue()) | |
587 RecordHistogram("WorkingTime", (end_time_ - start_time_).InSeconds()); | |
588 } | 570 } |
589 | 571 |
590 void InputMethodEngine::PropertyActivate(const std::string& property_name) { | 572 void InputMethodEngine::PropertyActivate(const std::string& property_name) { |
591 observer_->OnMenuItemActivated(active_component_id_, property_name); | 573 observer_->OnMenuItemActivated(active_component_id_, property_name); |
592 } | 574 } |
593 | 575 |
594 void InputMethodEngine::Reset() { | 576 void InputMethodEngine::Reset() { |
595 observer_->OnReset(active_component_id_); | 577 observer_->OnReset(active_component_id_); |
596 } | 578 } |
597 | 579 |
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
673 // TODO(nona): Implement it. | 655 // TODO(nona): Implement it. |
674 break; | 656 break; |
675 } | 657 } |
676 } | 658 } |
677 } | 659 } |
678 | 660 |
679 // TODO(nona): Support item.children. | 661 // TODO(nona): Support item.children. |
680 } | 662 } |
681 | 663 |
682 } // namespace chromeos | 664 } // namespace chromeos |
OLD | NEW |