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

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

Issue 7508014: Add member variables to VirtualKeyboardSelector (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: rewrote CheckUrls Created 9 years, 4 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
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 #ifndef CHROME_BROWSER_CHROMEOS_INPUT_METHOD_VIRTUAL_KEYBOARD_SELECTOR_H_ 5 #ifndef CHROME_BROWSER_CHROMEOS_INPUT_METHOD_VIRTUAL_KEYBOARD_SELECTOR_H_
6 #define CHROME_BROWSER_CHROMEOS_INPUT_METHOD_VIRTUAL_KEYBOARD_SELECTOR_H_ 6 #define CHROME_BROWSER_CHROMEOS_INPUT_METHOD_VIRTUAL_KEYBOARD_SELECTOR_H_
7 #pragma once 7 #pragma once
8 8
9 #include <list> 9 #include <list>
10 #include <map> 10 #include <map>
11 #include <set> 11 #include <set>
12 #include <string> 12 #include <string>
13 13
14 #include "base/basictypes.h" 14 #include "base/basictypes.h"
15 #include "googleurl/src/gurl.h" 15 #include "googleurl/src/gurl.h"
16 16
17 namespace chromeos { 17 namespace chromeos {
18 namespace input_method { 18 namespace input_method {
19 19
20 // A class which represents a virtual keyboard extension. One virtual keyboard 20 // A class which represents a virtual keyboard extension. One virtual keyboard
21 // extension can support more than one keyboard layout. 21 // extension can support more than one keyboard layout.
22 class VirtualKeyboard { 22 class VirtualKeyboard {
23 public: 23 public:
24 VirtualKeyboard(const GURL& url, 24 VirtualKeyboard(const GURL& url,
25 const std::string& name,
25 const std::set<std::string>& supported_layouts, 26 const std::set<std::string>& supported_layouts,
26 bool is_system); 27 bool is_system);
27 ~VirtualKeyboard(); 28 ~VirtualKeyboard();
28 29
29 // Returns URL for displaying the keyboard UI specified by |layout|. 30 // Returns URL for displaying the keyboard UI specified by |layout|.
30 // For example, when |url_| is "http://adcfj..kjhil/" and |layout| is "us", 31 // For example, when |url_| is "http://adcfj..kjhil/" and |layout| is "us",
31 // the function would return "http://adcfj..kjhil/index.html#us". When 32 // the function would return "http://adcfj..kjhil/index.html#us". When
32 // |layout| is empty, it returns |url_| as-is, which is "http://adcfj..kjhil/" 33 // |layout| is empty, it returns |url_| as-is, which is "http://adcfj..kjhil/"
33 // in this case. 34 // in this case.
34 GURL GetURLForLayout(const std::string& layout) const; 35 GURL GetURLForLayout(const std::string& layout) const;
35 36
36 // Returns true if the virtual keyboard extension supports the |layout|. 37 // Returns true if the virtual keyboard extension supports the |layout|.
37 bool IsLayoutSupported(const std::string& layout) const; 38 bool IsLayoutSupported(const std::string& layout) const;
38 39
39 const GURL& url() const { return url_; } 40 const GURL& url() const { return url_; }
41 const std::string& name() const { return name_; }
40 const std::set<std::string>& supported_layouts() const { 42 const std::set<std::string>& supported_layouts() const {
41 return supported_layouts_; 43 return supported_layouts_;
42 } 44 }
43 bool is_system() const { return is_system_; } 45 bool is_system() const { return is_system_; }
44 46
45 private: 47 private:
46 const GURL url_; 48 const GURL url_;
49 const std::string name_;
47 const std::set<std::string> supported_layouts_; 50 const std::set<std::string> supported_layouts_;
48 const bool is_system_; 51 const bool is_system_;
49 52
50 DISALLOW_COPY_AND_ASSIGN(VirtualKeyboard); 53 DISALLOW_COPY_AND_ASSIGN(VirtualKeyboard);
51 }; 54 };
52 55
53 // A class which holds all available virtual keyboard extensions. 56 // A class which holds all available virtual keyboard extensions.
54 class VirtualKeyboardSelector { 57 class VirtualKeyboardSelector {
55 public: 58 public:
56 VirtualKeyboardSelector(); 59 VirtualKeyboardSelector();
57 ~VirtualKeyboardSelector(); 60 ~VirtualKeyboardSelector();
58 61
59 // Adds a new virtual keyboard extension. If |keyboard.is_system_| is true, 62 // Adds a new virtual keyboard extension. If |keyboard.is_system_| is true,
60 // the virtual keyboard extension will have lower priority than non-system 63 // the virtual keyboard extension will have lower priority than non-system
61 // keyboard extensions. Returns false if a virtual keyboard extension 64 // keyboard extensions. Returns false if a virtual keyboard extension
62 // specified by the |url| is already added. 65 // specified by the |url| is already added.
63 // TODO(yusukes): Add RemoveVirtualKeyboard() as well. 66 // TODO(yusukes): Add RemoveVirtualKeyboard() as well.
64 bool AddVirtualKeyboard(const GURL& url, 67 bool AddVirtualKeyboard(const GURL& url,
68 const std::string& name,
65 const std::set<std::string>& supported_layouts, 69 const std::set<std::string>& supported_layouts,
66 bool is_system); 70 bool is_system);
67 71
68 // Selects and returns the most suitable virtual keyboard extension for the 72 // Selects and returns the most suitable virtual keyboard extension for the
69 // |layout|. Returns NULL if no virtual keyboard extension for the layout 73 // |layout|. Returns NULL if no virtual keyboard extension for the layout
70 // is found. If a specific virtual keyboard extension for the |layout| is 74 // is found. If a specific virtual keyboard extension for the |layout| is
71 // already set by SetUserPreference, the virtual keyboard extension is always 75 // already set by SetUserPreference, the virtual keyboard extension is always
72 // returned. If |current_|, which is the virtual keyboard extension currently 76 // returned. If |current_|, which is the virtual keyboard extension currently
73 // in use, supports the |layout|, the current one will be returned. Otherwise 77 // in use, supports the |layout|, the current one will be returned. Otherwise
74 // the function scans the list of |keyboards_| and then the list of 78 // the function scans the list of |keyboards_| and then the list of
(...skipping 13 matching lines...) Expand all
88 // |url| is not registered, or the extension specified by the |url| does not 92 // |url| is not registered, or the extension specified by the |url| does not
89 // support the |layout|. 93 // support the |layout|.
90 bool SetUserPreference(const std::string& layout, const GURL& url); 94 bool SetUserPreference(const std::string& layout, const GURL& url);
91 95
92 // Removes the preference for the |layout| added by SetUserPreference. 96 // Removes the preference for the |layout| added by SetUserPreference.
93 void RemoveUserPreference(const std::string& layout); 97 void RemoveUserPreference(const std::string& layout);
94 98
95 // Removes all preferences added by SetUserPreference. 99 // Removes all preferences added by SetUserPreference.
96 void ClearAllUserPreferences(); 100 void ClearAllUserPreferences();
97 101
102 const std::map<GURL, const VirtualKeyboard*>& url_to_keyboard() const {
103 return url_to_keyboard_;
104 }
105
106 const std::multimap<
107 std::string, const VirtualKeyboard*>& layout_to_keyboard() const {
108 return layout_to_keyboard_;
109 }
110
98 protected: 111 protected:
99 // Selects and returns the most suitable virtual keyboard extension for the 112 // Selects and returns the most suitable virtual keyboard extension for the
100 // |layout|. Unlike SelectVirtualKeyboard(), this function only scans 113 // |layout|. Unlike SelectVirtualKeyboard(), this function only scans
101 // |keyboards_| and |system_keyboards_| (in this order), and never updates 114 // |keyboards_| and |system_keyboards_| (in this order), and never updates
102 // |current_|. The function is protected for testability. 115 // |current_|. The function is protected for testability.
103 const VirtualKeyboard* SelectVirtualKeyboardWithoutPreferences( 116 const VirtualKeyboard* SelectVirtualKeyboardWithoutPreferences(
104 const std::string& layout); 117 const std::string& layout);
105 118
106 // The function is protected for testability. 119 // The function is protected for testability.
107 const std::map<std::string, const VirtualKeyboard*>& user_preference() const { 120 const std::map<std::string, const VirtualKeyboard*>& user_preference() const {
(...skipping 12 matching lines...) Expand all
120 // TODO(yusukes): Support per-site preference. e.g. always use virtual 133 // TODO(yusukes): Support per-site preference. e.g. always use virtual
121 // keyboard ABC on https://mail.google.com/, XYZ on http://www.google.com/. 134 // keyboard ABC on https://mail.google.com/, XYZ on http://www.google.com/.
122 135
123 // The virtual keyboard currently in use. 136 // The virtual keyboard currently in use.
124 const VirtualKeyboard* current_; 137 const VirtualKeyboard* current_;
125 138
126 // A map from URL to virtual keyboard extension. The map is for making 139 // A map from URL to virtual keyboard extension. The map is for making
127 // SetUserPreference() faster. 140 // SetUserPreference() faster.
128 std::map<GURL, const VirtualKeyboard*> url_to_keyboard_; 141 std::map<GURL, const VirtualKeyboard*> url_to_keyboard_;
129 142
143 // A *multi* map from layout name to virtual keyboard extension. An example
144 // value of the variable would be: { "us": extension1,
145 // "us(dvorak)": extension1,
146 // "us": extension2 }
147 std::multimap<std::string, const VirtualKeyboard*> layout_to_keyboard_;
148
130 DISALLOW_COPY_AND_ASSIGN(VirtualKeyboardSelector); 149 DISALLOW_COPY_AND_ASSIGN(VirtualKeyboardSelector);
131 }; 150 };
132 151
133 } // namespace input_method 152 } // namespace input_method
134 } // namespace chromeos 153 } // namespace chromeos
135 154
136 #endif // CHROME_BROWSER_CHROMEOS_INPUT_METHOD_VIRTUAL_KEYBOARD_SELECTOR_H_ 155 #endif // CHROME_BROWSER_CHROMEOS_INPUT_METHOD_VIRTUAL_KEYBOARD_SELECTOR_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698