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

Side by Side Diff: chrome/browser/chromeos/input_method/virtual_keyboard_selector.cc

Issue 7074008: initial version of auto VK switching. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: demo update Created 9 years, 6 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 | Annotate | Revision Log
OLDNEW
(Empty)
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
3 // found in the LICENSE file.
4
5 #include "chrome/browser/chromeos/input_method/virtual_keyboard_selector.h"
6
7 #include "base/logging.h"
8 #include "base/stl_util-inl.h"
9
10 namespace {
11 const char kDefaultURLPath[] = "index.html";
12 const size_t kDefaultURLPathLen = arraysize(kDefaultURLPath) - 1;
13 } // namespace
14
15 namespace chromeos {
16 namespace input_method {
17
18 GURL VirtualKeyboard::GetURLForLayout(const std::string& layout) const {
19 if (layout.empty()) {
20 return url_;
21 }
22 url_canon::Replacements<char> replacements;
23 replacements.SetPath(
24 kDefaultURLPath, url_parse::Component(0, kDefaultURLPathLen));
25 // TODO(yusukes): would be better to URL-encode the |layout|?
26 replacements.SetRef(layout.c_str(), url_parse::Component(0, layout.length()));
27 return url_.ReplaceComponents(replacements);
28 }
29
30 VirtualKeyboardSelector::VirtualKeyboardSelector()
31 : current_(NULL) {
32 }
33
34 VirtualKeyboardSelector::~VirtualKeyboardSelector() {
35 STLDeleteElements(&keyboards_);
36 }
37
38 void VirtualKeyboardSelector::AddVirtualKeyboard(
39 const GURL& url,
40 const std::set<std::string>& supported_layouts,
41 bool is_system) {
42 const VirtualKeyboard* new_keyboard = new VirtualKeyboard(url,
43 supported_layouts,
44 is_system);
45 if (is_system) {
46 system_keyboards_.push_front(new_keyboard);
47 } else {
48 keyboards_.push_front(new_keyboard);
49 }
50 current_ =
51 keyboards_.empty() ? system_keyboards_.front() : keyboards_.front();
52 }
53
54 const VirtualKeyboard* VirtualKeyboardSelector::SelectVirtualKeyboard(
55 const std::string& layout) {
56 if (layout.empty()) {
57 LOG(ERROR) << "No layout is specified";
58 return NULL;
59 }
60
61 // First, check whether the current keyboard supports the layout.
62 if (current_ && current_->supported_layouts().count(layout) > 0) {
63 return current_;
64 }
65
66 const VirtualKeyboard* keyboard = SelectVirtualKeyboardInternal(layout);
67 if (!keyboard) {
68 VLOG(1) << "No virtual keyboard for " << layout << " is found";
69 return NULL;
70 }
71
72 current_ = keyboard;
73 return keyboard;
74 }
75
76 const VirtualKeyboard* VirtualKeyboardSelector::SelectVirtualKeyboardInternal(
77 const std::string& layout) {
78 std::list<const VirtualKeyboard*>::const_iterator iter;
79 for (iter = keyboards_.begin(); iter != keyboards_.end(); ++iter) {
80 if ((*iter)->supported_layouts().count(layout) > 0) {
81 return *iter;
82 }
83 }
84 for (iter = system_keyboards_.begin();
85 iter != system_keyboards_.end(); ++iter) {
86 if ((*iter)->supported_layouts().count(layout) > 0) {
87 return *iter;
88 }
89 }
90 return NULL;
91 }
92
93 } // namespace input_method
94 } // namespace chromeos
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698