OLD | NEW |
(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 #ifndef CHROME_BROWSER_CHROMEOS_INPUT_METHOD_VIRTUAL_KEYBOARD_SELECTOR_H_ |
| 6 #define CHROME_BROWSER_CHROMEOS_INPUT_METHOD_VIRTUAL_KEYBOARD_SELECTOR_H_ |
| 7 #pragma once |
| 8 |
| 9 #include <list> |
| 10 #include <set> |
| 11 #include <string> |
| 12 |
| 13 #include "base/basictypes.h" |
| 14 #include "googleurl/src/gurl.h" |
| 15 |
| 16 namespace chromeos { |
| 17 namespace input_method { |
| 18 |
| 19 // A class which represents a virtual keyboard extension. One virtual keyboard |
| 20 // extension can support more than one keyboard layout. |
| 21 class VirtualKeyboard { |
| 22 public: |
| 23 VirtualKeyboard(const GURL& url, |
| 24 const std::set<std::string>& supported_layouts, |
| 25 bool is_system) |
| 26 : url_(url), |
| 27 supported_layouts_(supported_layouts), |
| 28 is_system_(is_system) {} |
| 29 |
| 30 // Returns URL for displaying the keyboard UI specified by |layout|. |
| 31 // For example, when |url_| is "http://adcfj..kjhil/" and |layout| is "us", |
| 32 // the function would return "http://adcfj..kjhil/index.html#us". When |
| 33 // |layout| is empty, it returns |url_| as-is, which is "http://adcfj..kjhil/" |
| 34 // in this case. |
| 35 GURL GetURLForLayout(const std::string& layout) const; |
| 36 |
| 37 const GURL& url() const { return url_; } |
| 38 const std::set<std::string>& supported_layouts() const { |
| 39 return supported_layouts_; |
| 40 } |
| 41 bool is_system() const { return is_system_; } |
| 42 |
| 43 private: |
| 44 const GURL url_; |
| 45 const std::set<std::string> supported_layouts_; |
| 46 const bool is_system_; |
| 47 |
| 48 DISALLOW_COPY_AND_ASSIGN(VirtualKeyboard); |
| 49 }; |
| 50 |
| 51 // A class which holds all available virtual keyboard extensions. |
| 52 class VirtualKeyboardSelector { |
| 53 public: |
| 54 VirtualKeyboardSelector(); |
| 55 ~VirtualKeyboardSelector(); |
| 56 |
| 57 // Adds a new virtual keyboard extension. If |keyboard.is_system_| is true, |
| 58 // the virtual keyboard extension will initially have lower priority than non- |
| 59 // system keyboard extensions. |
| 60 // TODO(yusukes): Add RemoveVirtualKeyboard() as well. |
| 61 void AddVirtualKeyboard(const GURL& url, |
| 62 const std::set<std::string>& supported_layouts, |
| 63 bool is_system); |
| 64 |
| 65 // Selects and returns the most suitable virtual keyboard extension for the |
| 66 // |layout|. Returns NULL if no virtual keyboard extension for the layout |
| 67 // is found. If |current_|, which is the virtual keyboard extension currently |
| 68 // in use, supports the |layout|, the current one will be returned. Otherwise |
| 69 // the function scans the lists of |keyboards_| and |system_keyboards_|, |
| 70 // respectively. |
| 71 // |
| 72 // Checking the |current_| keyboard is important for the following use case: |
| 73 // - If I have installed a VK extension that provides a US and an FR layout |
| 74 // and I switch from the US layout of the extension (+ English IME) to the |
| 75 // French IME, then I would like to use the FR layout of the extension I am |
| 76 // currently using. |
| 77 const VirtualKeyboard* SelectVirtualKeyboard(const std::string& layout); |
| 78 |
| 79 // TODO(yusukes): Add a function something like |
| 80 // void SetUserPreference(const std::string& layout, |
| 81 // const VirtualKeyboard& keyboard); |
| 82 // so that users could use a specific virtual keyboard extension for the |
| 83 // |layout|. |
| 84 |
| 85 protected: |
| 86 // This function neither checks |current_| nor updates the variable. The |
| 87 // function is protected for testability. |
| 88 const VirtualKeyboard* SelectVirtualKeyboardInternal( |
| 89 const std::string& layout); |
| 90 |
| 91 private: |
| 92 // A list of 3rd party virtual keyboard extensions. |
| 93 std::list<const VirtualKeyboard*> keyboards_; |
| 94 // A list of system virtual keyboard extensions. |
| 95 std::list<const VirtualKeyboard*> system_keyboards_; |
| 96 |
| 97 // The virtual keyboard currently in use. |
| 98 const VirtualKeyboard* current_; |
| 99 |
| 100 DISALLOW_COPY_AND_ASSIGN(VirtualKeyboardSelector); |
| 101 }; |
| 102 |
| 103 } // namespace input_method |
| 104 } // namespace chromeos |
| 105 |
| 106 #endif // CHROME_BROWSER_CHROMEOS_INPUT_METHOD_VIRTUAL_KEYBOARD_SELECTOR_H_ |
OLD | NEW |