OLD | NEW |
1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2009 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/cros/language_library.h" | 5 #include "chrome/browser/chromeos/cros/language_library.h" |
6 | 6 |
7 #include "base/basictypes.h" | 7 #include "base/basictypes.h" |
8 #include "base/message_loop.h" | 8 #include "base/message_loop.h" |
9 #include "base/string_util.h" | 9 #include "base/string_util.h" |
10 #include "chrome/browser/chrome_thread.h" | 10 #include "chrome/browser/chrome_thread.h" |
(...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
140 if (portions.size() >= 2 && !portions[1].empty()) { | 140 if (portions.size() >= 2 && !portions[1].empty()) { |
141 language_code.append("-"); | 141 language_code.append("-"); |
142 language_code.append(StringToUpperASCII(portions[1])); | 142 language_code.append(StringToUpperASCII(portions[1])); |
143 } | 143 } |
144 } | 144 } |
145 return language_code; | 145 return language_code; |
146 } | 146 } |
147 | 147 |
148 LanguageLibraryImpl::LanguageLibraryImpl() | 148 LanguageLibraryImpl::LanguageLibraryImpl() |
149 : input_method_status_connection_(NULL), | 149 : input_method_status_connection_(NULL), |
150 current_input_method_("", "", "", ""), | 150 current_input_method_("", "", "", "") { |
151 is_focused_(false) { | |
152 scoped_ptr<InputMethodDescriptors> input_method_descriptors( | 151 scoped_ptr<InputMethodDescriptors> input_method_descriptors( |
153 CreateFallbackInputMethodDescriptors()); | 152 CreateFallbackInputMethodDescriptors()); |
154 current_input_method_ = input_method_descriptors->at(0); | 153 current_input_method_ = input_method_descriptors->at(0); |
155 } | 154 } |
156 | 155 |
157 LanguageLibraryImpl::~LanguageLibraryImpl() { | 156 LanguageLibraryImpl::~LanguageLibraryImpl() { |
158 if (input_method_status_connection_) { | 157 if (input_method_status_connection_) { |
159 chromeos::DisconnectInputMethodStatus(input_method_status_connection_); | 158 chromeos::DisconnectInputMethodStatus(input_method_status_connection_); |
160 } | 159 } |
161 } | 160 } |
(...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
293 // static | 292 // static |
294 void LanguageLibraryImpl::UpdatePropertyHandler( | 293 void LanguageLibraryImpl::UpdatePropertyHandler( |
295 void* object, const ImePropertyList& prop_list) { | 294 void* object, const ImePropertyList& prop_list) { |
296 LanguageLibraryImpl* language_library = | 295 LanguageLibraryImpl* language_library = |
297 static_cast<LanguageLibraryImpl*>(object); | 296 static_cast<LanguageLibraryImpl*>(object); |
298 language_library->UpdateProperty(prop_list); | 297 language_library->UpdateProperty(prop_list); |
299 } | 298 } |
300 | 299 |
301 // static | 300 // static |
302 void LanguageLibraryImpl::FocusChangedHandler(void* object, bool is_focused) { | 301 void LanguageLibraryImpl::FocusChangedHandler(void* object, bool is_focused) { |
303 LanguageLibraryImpl* language_library = | 302 // TODO(yusukes): Remove this function. Modify MonitorInputMethodStatuslibcros |
304 static_cast<LanguageLibraryImpl*>(object); | 303 // API as well. |
305 language_library->FocusChanged(is_focused); | |
306 } | 304 } |
307 | 305 |
308 bool LanguageLibraryImpl::EnsureStarted() { | 306 bool LanguageLibraryImpl::EnsureStarted() { |
309 if (input_method_status_connection_) { | 307 if (input_method_status_connection_) { |
310 if (chromeos::InputMethodStatusConnectionIsAlive( | 308 if (chromeos::InputMethodStatusConnectionIsAlive( |
311 input_method_status_connection_)) { | 309 input_method_status_connection_)) { |
312 return true; | 310 return true; |
313 } | 311 } |
314 DLOG(WARNING) << "IBus connection is closed. Trying to reconnect..."; | 312 DLOG(WARNING) << "IBus connection is closed. Trying to reconnect..."; |
315 chromeos::DisconnectInputMethodStatus(input_method_status_connection_); | 313 chromeos::DisconnectInputMethodStatus(input_method_status_connection_); |
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
373 this, &LanguageLibraryImpl::UpdateProperty, prop_list)); | 371 this, &LanguageLibraryImpl::UpdateProperty, prop_list)); |
374 return; | 372 return; |
375 } | 373 } |
376 | 374 |
377 for (size_t i = 0; i < prop_list.size(); ++i) { | 375 for (size_t i = 0; i < prop_list.size(); ++i) { |
378 FindAndUpdateProperty(prop_list[i], ¤t_ime_properties_); | 376 FindAndUpdateProperty(prop_list[i], ¤t_ime_properties_); |
379 } | 377 } |
380 FOR_EACH_OBSERVER(Observer, observers_, ImePropertiesChanged(this)); | 378 FOR_EACH_OBSERVER(Observer, observers_, ImePropertiesChanged(this)); |
381 } | 379 } |
382 | 380 |
383 void LanguageLibraryImpl::FocusChanged(bool is_focused) { | |
384 if (!ChromeThread::CurrentlyOn(ChromeThread::UI)) { | |
385 ChromeThread::PostTask( | |
386 ChromeThread::UI, FROM_HERE, | |
387 NewRunnableMethod( | |
388 this, &LanguageLibraryImpl::FocusChanged, is_focused)); | |
389 return; | |
390 } | |
391 | |
392 is_focused_ = is_focused; | |
393 FOR_EACH_OBSERVER(Observer, observers_, FocusChanged(this)); | |
394 } | |
395 | |
396 } // namespace chromeos | 381 } // namespace chromeos |
OLD | NEW |