| 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 #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 <set> | 11 #include <set> |
| 11 #include <string> | 12 #include <string> |
| 12 | 13 |
| 13 #include "base/basictypes.h" | 14 #include "base/basictypes.h" |
| 14 #include "googleurl/src/gurl.h" | 15 #include "googleurl/src/gurl.h" |
| 15 | 16 |
| 16 namespace chromeos { | 17 namespace chromeos { |
| 17 namespace input_method { | 18 namespace input_method { |
| 18 | 19 |
| 19 // A class which represents a virtual keyboard extension. One virtual keyboard | 20 // A class which represents a virtual keyboard extension. One virtual keyboard |
| 20 // extension can support more than one keyboard layout. | 21 // extension can support more than one keyboard layout. |
| 21 class VirtualKeyboard { | 22 class VirtualKeyboard { |
| 22 public: | 23 public: |
| 23 VirtualKeyboard(const GURL& url, | 24 VirtualKeyboard(const GURL& url, |
| 24 const std::set<std::string>& supported_layouts, | 25 const std::set<std::string>& supported_layouts, |
| 25 bool is_system); | 26 bool is_system); |
| 26 ~VirtualKeyboard(); | 27 ~VirtualKeyboard(); |
| 27 | 28 |
| 28 // Returns URL for displaying the keyboard UI specified by |layout|. | 29 // Returns URL for displaying the keyboard UI specified by |layout|. |
| 29 // For example, when |url_| is "http://adcfj..kjhil/" and |layout| is "us", | 30 // For example, when |url_| is "http://adcfj..kjhil/" and |layout| is "us", |
| 30 // the function would return "http://adcfj..kjhil/index.html#us". When | 31 // the function would return "http://adcfj..kjhil/index.html#us". When |
| 31 // |layout| is empty, it returns |url_| as-is, which is "http://adcfj..kjhil/" | 32 // |layout| is empty, it returns |url_| as-is, which is "http://adcfj..kjhil/" |
| 32 // in this case. | 33 // in this case. |
| 33 GURL GetURLForLayout(const std::string& layout) const; | 34 GURL GetURLForLayout(const std::string& layout) const; |
| 34 | 35 |
| 36 // Returns true if the virtual keyboard extension supports the |layout|. |
| 37 bool IsLayoutSupported(const std::string& layout) const; |
| 38 |
| 35 const GURL& url() const { return url_; } | 39 const GURL& url() const { return url_; } |
| 36 const std::set<std::string>& supported_layouts() const { | 40 const std::set<std::string>& supported_layouts() const { |
| 37 return supported_layouts_; | 41 return supported_layouts_; |
| 38 } | 42 } |
| 39 bool is_system() const { return is_system_; } | 43 bool is_system() const { return is_system_; } |
| 40 | 44 |
| 41 private: | 45 private: |
| 42 const GURL url_; | 46 const GURL url_; |
| 43 const std::set<std::string> supported_layouts_; | 47 const std::set<std::string> supported_layouts_; |
| 44 const bool is_system_; | 48 const bool is_system_; |
| (...skipping 10 matching lines...) Expand all Loading... |
| 55 // Adds a new virtual keyboard extension. If |keyboard.is_system_| is true, | 59 // Adds a new virtual keyboard extension. If |keyboard.is_system_| is true, |
| 56 // the virtual keyboard extension will have lower priority than non-system | 60 // the virtual keyboard extension will have lower priority than non-system |
| 57 // keyboard extensions. | 61 // keyboard extensions. |
| 58 // TODO(yusukes): Add RemoveVirtualKeyboard() as well. | 62 // TODO(yusukes): Add RemoveVirtualKeyboard() as well. |
| 59 void AddVirtualKeyboard(const GURL& url, | 63 void AddVirtualKeyboard(const GURL& url, |
| 60 const std::set<std::string>& supported_layouts, | 64 const std::set<std::string>& supported_layouts, |
| 61 bool is_system); | 65 bool is_system); |
| 62 | 66 |
| 63 // Selects and returns the most suitable virtual keyboard extension for the | 67 // Selects and returns the most suitable virtual keyboard extension for the |
| 64 // |layout|. Returns NULL if no virtual keyboard extension for the layout | 68 // |layout|. Returns NULL if no virtual keyboard extension for the layout |
| 65 // is found. If |current_|, which is the virtual keyboard extension currently | 69 // is found. If a specific virtual keyboard extension for the |layout| is |
| 70 // already set by SetUserPreference, the virtual keyboard extension is always |
| 71 // returned. If |current_|, which is the virtual keyboard extension currently |
| 66 // in use, supports the |layout|, the current one will be returned. Otherwise | 72 // in use, supports the |layout|, the current one will be returned. Otherwise |
| 67 // the function scans the list of |keyboards_| and then the list of | 73 // the function scans the list of |keyboards_| and then the list of |
| 68 // |system_keyboards_|. The most recently added keyboards to each list take | 74 // |system_keyboards_|. The most recently added keyboards to each list take |
| 69 // precedence. | 75 // precedence. |
| 70 // | 76 // |
| 71 // Checking the |current_| keyboard is important for the following use case: | 77 // Checking the |current_| keyboard is important for the following use case: |
| 72 // - If I have installed a VK extension that provides a US and an FR layout | 78 // - If I have installed a VK extension that provides a US and an FR layout |
| 73 // and I switch from the US layout of the extension (+ English IME) to the | 79 // and I switch from the US layout of the extension (+ English IME) to the |
| 74 // French IME, then I would like to use the FR layout of the extension I am | 80 // French IME, then I would like to use the FR layout of the extension I am |
| 75 // currently using. | 81 // currently using. |
| 76 const VirtualKeyboard* SelectVirtualKeyboard(const std::string& layout); | 82 const VirtualKeyboard* SelectVirtualKeyboard(const std::string& layout); |
| 77 | 83 |
| 78 // TODO(yusukes): Add a function something like | 84 // Sets user preferences on virtual keyboard selection so that the virtual |
| 79 // void SetUserPreference(const std::string& layout, | 85 // keyboard extension specified by the |url| is always selected for the |
| 80 // const VirtualKeyboard& keyboard); | 86 // |layout|. Returns false if a virtual keyboard extension whose address is |
| 81 // so that users could use a specific virtual keyboard extension for the | 87 // |url| is not registered, or the extension specified by the |url| does not |
| 82 // |layout|. | 88 // support the |layout|. |
| 89 bool SetUserPreference(const std::string& layout, const GURL& url); |
| 90 |
| 91 // Removes the preference for the |layout| added by SetUserPreference. |
| 92 void RemoveUserPreference(const std::string& layout); |
| 83 | 93 |
| 84 protected: | 94 protected: |
| 85 // This function neither checks |current_| nor updates the variable. The | 95 // Selects and returns the most suitable virtual keyboard extension for the |
| 86 // function is protected for testability. | 96 // |layout|. Unlike SelectVirtualKeyboard(), this function only scans |
| 87 const VirtualKeyboard* SelectVirtualKeyboardInternal( | 97 // |keyboards_| and |system_keyboards_| (in this order), and never updates |
| 98 // |current_|. The function is protected for testability. |
| 99 const VirtualKeyboard* SelectVirtualKeyboardWithoutPreferences( |
| 88 const std::string& layout); | 100 const std::string& layout); |
| 89 | 101 |
| 90 private: | 102 private: |
| 91 // A list of third party virtual keyboard extensions. | 103 // A list of third party virtual keyboard extensions. |
| 92 std::list<const VirtualKeyboard*> keyboards_; | 104 std::list<const VirtualKeyboard*> keyboards_; |
| 93 // A list of system virtual keyboard extensions. | 105 // A list of system virtual keyboard extensions. |
| 94 std::list<const VirtualKeyboard*> system_keyboards_; | 106 std::list<const VirtualKeyboard*> system_keyboards_; |
| 95 | 107 |
| 108 // A map from layout name to virtual keyboard extension. |
| 109 std::map<std::string, const VirtualKeyboard*> user_preference_; |
| 110 |
| 111 // TODO(yusukes): Support per-site preference. e.g. always use virtual |
| 112 // keyboard ABC on https://mail.google.com/, XYZ on http://www.google.com/. |
| 113 |
| 96 // The virtual keyboard currently in use. | 114 // The virtual keyboard currently in use. |
| 97 const VirtualKeyboard* current_; | 115 const VirtualKeyboard* current_; |
| 98 | 116 |
| 99 DISALLOW_COPY_AND_ASSIGN(VirtualKeyboardSelector); | 117 DISALLOW_COPY_AND_ASSIGN(VirtualKeyboardSelector); |
| 100 }; | 118 }; |
| 101 | 119 |
| 102 } // namespace input_method | 120 } // namespace input_method |
| 103 } // namespace chromeos | 121 } // namespace chromeos |
| 104 | 122 |
| 105 #endif // CHROME_BROWSER_CHROMEOS_INPUT_METHOD_VIRTUAL_KEYBOARD_SELECTOR_H_ | 123 #endif // CHROME_BROWSER_CHROMEOS_INPUT_METHOD_VIRTUAL_KEYBOARD_SELECTOR_H_ |
| OLD | NEW |