| 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/chromeos/input_method/virtual_keyboard_selector.h" | 5 #include "chrome/browser/chromeos/input_method/virtual_keyboard_selector.h" |
| 6 | 6 |
| 7 #include "base/logging.h" | 7 #include "base/logging.h" |
| 8 #include "base/stl_util.h" | 8 #include "base/stl_util.h" |
| 9 | 9 |
| 10 namespace { | 10 namespace { |
| (...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 97 const std::string& layout = *layout_iter; | 97 const std::string& layout = *layout_iter; |
| 98 layout_to_keyboard_.insert(std::make_pair(layout, new_keyboard)); | 98 layout_to_keyboard_.insert(std::make_pair(layout, new_keyboard)); |
| 99 } | 99 } |
| 100 | 100 |
| 101 return true; | 101 return true; |
| 102 } | 102 } |
| 103 | 103 |
| 104 const VirtualKeyboard* VirtualKeyboardSelector::SelectVirtualKeyboard( | 104 const VirtualKeyboard* VirtualKeyboardSelector::SelectVirtualKeyboard( |
| 105 const std::string& layout) { | 105 const std::string& layout) { |
| 106 if (layout.empty()) { | 106 if (layout.empty()) { |
| 107 LOG(ERROR) << "No layout is specified"; | 107 DVLOG(1) << "No layout is specified"; |
| 108 return NULL; | 108 return NULL; |
| 109 } | 109 } |
| 110 | 110 |
| 111 // First, check the user pref. | 111 // First, check the user pref. |
| 112 std::map<std::string, const VirtualKeyboard*>::const_iterator iter = | 112 std::map<std::string, const VirtualKeyboard*>::const_iterator iter = |
| 113 user_preference_.find(layout); | 113 user_preference_.find(layout); |
| 114 if (iter != user_preference_.end() && | 114 if (iter != user_preference_.end() && |
| 115 iter->second->IsLayoutSupported(layout)) { | 115 iter->second->IsLayoutSupported(layout)) { |
| 116 current_ = iter->second; | 116 current_ = iter->second; |
| 117 return current_; | 117 return current_; |
| 118 } | 118 } |
| 119 | 119 |
| 120 // Second, check whether the current keyboard supports the layout. | 120 // Second, check whether the current keyboard supports the layout. |
| 121 if (current_ && current_->IsLayoutSupported(layout)) { | 121 if (current_ && current_->IsLayoutSupported(layout)) { |
| 122 return current_; | 122 return current_; |
| 123 } | 123 } |
| 124 | 124 |
| 125 const VirtualKeyboard* keyboard = | 125 const VirtualKeyboard* keyboard = |
| 126 SelectVirtualKeyboardWithoutPreferences(layout); | 126 SelectVirtualKeyboardWithoutPreferences(layout); |
| 127 if (!keyboard) { | 127 if (!keyboard) { |
| 128 VLOG(1) << "No virtual keyboard for " << layout << " is found"; | 128 DVLOG(1) << "No virtual keyboard for " << layout << " is found"; |
| 129 return NULL; | 129 return NULL; |
| 130 } | 130 } |
| 131 | 131 |
| 132 current_ = keyboard; | 132 current_ = keyboard; |
| 133 return keyboard; | 133 return keyboard; |
| 134 } | 134 } |
| 135 | 135 |
| 136 bool VirtualKeyboardSelector::SetUserPreference( | 136 bool VirtualKeyboardSelector::SetUserPreference( |
| 137 const std::string& layout, const GURL& url) { | 137 const std::string& layout, const GURL& url) { |
| 138 std::map<GURL, const VirtualKeyboard*>::const_iterator iter = | 138 std::map<GURL, const VirtualKeyboard*>::const_iterator iter = |
| 139 url_to_keyboard_.find(url); | 139 url_to_keyboard_.find(url); |
| 140 if (iter == url_to_keyboard_.end()) { | 140 if (iter == url_to_keyboard_.end()) { |
| 141 VLOG(1) << "Can't set user preference: unknown URL"; | 141 DVLOG(1) << "Can't set user preference: unknown URL"; |
| 142 return false; | 142 return false; |
| 143 } | 143 } |
| 144 | 144 |
| 145 const VirtualKeyboard* keyboard = iter->second; | 145 const VirtualKeyboard* keyboard = iter->second; |
| 146 if (!keyboard->IsLayoutSupported(layout)) { | 146 if (!keyboard->IsLayoutSupported(layout)) { |
| 147 VLOG(1) << "Requested layout is not supported by requested URL"; | 147 DVLOG(1) << "Requested layout is not supported by requested URL"; |
| 148 return false; | 148 return false; |
| 149 } | 149 } |
| 150 | 150 |
| 151 RemoveUserPreference(layout); | 151 RemoveUserPreference(layout); |
| 152 user_preference_.insert(std::make_pair(layout, keyboard)); | 152 user_preference_.insert(std::make_pair(layout, keyboard)); |
| 153 return true; | 153 return true; |
| 154 } | 154 } |
| 155 | 155 |
| 156 void VirtualKeyboardSelector::RemoveUserPreference(const std::string& layout) { | 156 void VirtualKeyboardSelector::RemoveUserPreference(const std::string& layout) { |
| 157 user_preference_.erase(layout); | 157 user_preference_.erase(layout); |
| 158 } | 158 } |
| 159 | 159 |
| 160 void VirtualKeyboardSelector::ClearAllUserPreferences() { | 160 void VirtualKeyboardSelector::ClearAllUserPreferences() { |
| 161 user_preference_.clear(); | 161 user_preference_.clear(); |
| 162 } | 162 } |
| 163 | 163 |
| 164 const VirtualKeyboard* | 164 const VirtualKeyboard* |
| 165 VirtualKeyboardSelector::SelectVirtualKeyboardWithoutPreferences( | 165 VirtualKeyboardSelector::SelectVirtualKeyboardWithoutPreferences( |
| 166 const std::string& layout) { | 166 const std::string& layout) { |
| 167 const VirtualKeyboard* keyboard = | 167 const VirtualKeyboard* keyboard = |
| 168 SelectVirtualKeyboardInternal(keyboards_, layout); | 168 SelectVirtualKeyboardInternal(keyboards_, layout); |
| 169 if (!keyboard) | 169 if (!keyboard) |
| 170 keyboard = SelectVirtualKeyboardInternal(system_keyboards_, layout); | 170 keyboard = SelectVirtualKeyboardInternal(system_keyboards_, layout); |
| 171 return keyboard; | 171 return keyboard; |
| 172 } | 172 } |
| 173 | 173 |
| 174 } // namespace input_method | 174 } // namespace input_method |
| 175 } // namespace chromeos | 175 } // namespace chromeos |
| OLD | NEW |