OLD | NEW |
| (Empty) |
1 // Copyright (c) 2012 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 // The header files provides APIs for monitoring and controlling input | |
6 // method UI status. The APIs encapsulate the APIs of IBus, the underlying | |
7 // input method framework. | |
8 // TODO(nona): Remove IBusUiController. | |
9 | |
10 #ifndef CHROME_BROWSER_CHROMEOS_INPUT_METHOD_IBUS_UI_CONTROLLER_H_ | |
11 #define CHROME_BROWSER_CHROMEOS_INPUT_METHOD_IBUS_UI_CONTROLLER_H_ | |
12 | |
13 #include <string> | |
14 #include <vector> | |
15 | |
16 #include "base/basictypes.h" | |
17 #include "base/observer_list.h" | |
18 #include "chromeos/dbus/ibus/ibus_panel_service.h" | |
19 | |
20 namespace gfx { | |
21 class Rect; | |
22 } // namespace gfx | |
23 | |
24 namespace chromeos { | |
25 namespace input_method { | |
26 | |
27 // A key for attaching the |ibus_service_panel_| object to |ibus_|. | |
28 const char kPanelObjectKey[] = "panel-object"; | |
29 | |
30 class InputMethodDescriptor; | |
31 typedef std::vector<InputMethodDescriptor> InputMethodDescriptors; | |
32 | |
33 // IBusUiController is used to interact with the IBus daemon. | |
34 class IBusUiController : public ibus::IBusPanelCandidateWindowHandlerInterface { | |
35 public: | |
36 class Observer { | |
37 public: | |
38 // Called when the auxiliary text becomes hidden. | |
39 virtual void OnHideAuxiliaryText() = 0; | |
40 | |
41 // Called when the lookup table becomes hidden. | |
42 virtual void OnHideLookupTable() = 0; | |
43 | |
44 // Called when the preedit text becomes hidden. | |
45 virtual void OnHidePreeditText() = 0; | |
46 | |
47 // Called when the cursor location is set. | |
48 virtual void OnSetCursorLocation(const ibus::Rect& cusor_location, | |
49 const ibus::Rect& composition_head) = 0; | |
50 | |
51 // Called when the auxiliary text is updated. | |
52 virtual void OnUpdateAuxiliaryText(const std::string& text, | |
53 bool visible) = 0; | |
54 | |
55 // Called when the lookup table is updated. | |
56 virtual void OnUpdateLookupTable(const ibus::IBusLookupTable& table, | |
57 bool visible) = 0; | |
58 | |
59 // Called when the preedit text is updated. | |
60 virtual void OnUpdatePreeditText(const std::string& utf8_text, | |
61 unsigned int cursor, bool visible) = 0; | |
62 }; | |
63 | |
64 IBusUiController(); | |
65 virtual ~IBusUiController(); | |
66 | |
67 // Creates an instance of the class. The constructor is unused. | |
68 static IBusUiController* Create(); | |
69 | |
70 // Adds and removes observers for IBus UI notifications. Clients must be | |
71 // sure to remove the observer before they go away. To capture the | |
72 // initial connection change, you should add an observer before calling | |
73 // Connect(). | |
74 void AddObserver(Observer* observer); | |
75 void RemoveObserver(Observer* observer); | |
76 | |
77 // Notifies that a candidate is clicked. |CandidateClicked| signal will be | |
78 // sent to the ibus-daemon. | |
79 // | |
80 // - |index| Index in the Lookup table. The semantics is same with | |
81 // |cursor_absolute_index|. | |
82 // - |button| GdkEventButton::button (1: left button, etc.) | |
83 // - |state| GdkEventButton::state (key modifier flags) | |
84 void NotifyCandidateClicked(int index, int button, int flags); | |
85 | |
86 // Notifies that the cursor up button is clicked. |CursorUp| signal will be | |
87 // sent to the ibus-daemon | |
88 void NotifyCursorUp(); | |
89 | |
90 // Notifies that the cursor down button is clicked. |CursorDown| signal | |
91 // will be sent to the ibus-daemon | |
92 void NotifyCursorDown(); | |
93 | |
94 // Notifies that the page up button is clicked. |PageUp| signal will be | |
95 // sent to the ibus-daemon | |
96 void NotifyPageUp(); | |
97 | |
98 // Notifies that the page down button is clicked. |PageDown| signal will be | |
99 // sent to the ibus-daemon | |
100 void NotifyPageDown(); | |
101 | |
102 private: | |
103 // IBusPanelHandlerInterface overrides. | |
104 virtual void UpdateLookupTable(const ibus::IBusLookupTable& table, | |
105 bool visible) OVERRIDE; | |
106 virtual void HideLookupTable() OVERRIDE; | |
107 virtual void UpdateAuxiliaryText(const std::string& text, | |
108 bool visible) OVERRIDE; | |
109 virtual void HideAuxiliaryText() OVERRIDE; | |
110 virtual void UpdatePreeditText(const std::string& text, uint32 cursor_pos, | |
111 bool visible) OVERRIDE; | |
112 virtual void HidePreeditText() OVERRIDE; | |
113 virtual void SetCursorLocation(const ibus::Rect& cursor_location, | |
114 const ibus::Rect& composition_head) OVERRIDE; | |
115 | |
116 ObserverList<Observer> observers_; | |
117 | |
118 DISALLOW_COPY_AND_ASSIGN(IBusUiController); | |
119 }; | |
120 | |
121 } // namespace input_method | |
122 } // namespace chromeos | |
123 | |
124 #endif // CHROME_BROWSER_CHROMEOS_INPUT_METHOD_IBUS_UI_CONTROLLER_H_ | |
OLD | NEW |