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

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

Issue 121163003: Cleanup CandidateWindowView. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: fix Created 6 years, 12 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) 2012 The Chromium Authors. All rights reserved. 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 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_CANDIDATE_WINDOW_VIEW_H_ 5 #ifndef CHROME_BROWSER_CHROMEOS_INPUT_METHOD_CANDIDATE_WINDOW_VIEW_H_
6 #define CHROME_BROWSER_CHROMEOS_INPUT_METHOD_CANDIDATE_WINDOW_VIEW_H_ 6 #define CHROME_BROWSER_CHROMEOS_INPUT_METHOD_CANDIDATE_WINDOW_VIEW_H_
7 7
8 #include "base/gtest_prod_util.h"
9 #include "base/memory/scoped_ptr.h"
10 #include "chromeos/ime/candidate_window.h" 8 #include "chromeos/ime/candidate_window.h"
11 #include "ui/views/view.h" 9 #include "ui/views/bubble/bubble_delegate.h"
12 10 #include "ui/views/controls/button/button.h"
13 namespace gfx {
14 class Font;
15 }
16 11
17 namespace chromeos { 12 namespace chromeos {
18 namespace input_method { 13 namespace input_method {
19 14
20 class CandidateView; 15 class CandidateView;
21 class CandidateWindow;
22 class HidableArea;
23 class InformationTextArea; 16 class InformationTextArea;
24 17
25 // CandidateWindowView is the main container of the candidate window UI. 18 // CandidateWindowView is the main container of the candidate window UI.
26 class CandidateWindowView : public views::View { 19 class CandidateWindowView : public views::BubbleDelegateView,
20 public views::ButtonListener {
27 public: 21 public:
28 // The object can be monitored by the observer. 22 // The object can be monitored by the observer.
29 class Observer { 23 class Observer {
30 public: 24 public:
31 virtual ~Observer() {} 25 virtual ~Observer() {}
32 // The function is called when a candidate is committed. 26 // The function is called when a candidate is committed.
33 virtual void OnCandidateCommitted(int index) = 0; 27 virtual void OnCandidateCommitted(int index) = 0;
34
35 virtual void OnCandidateWindowOpened() = 0;
36 virtual void OnCandidateWindowClosed() = 0;
37 }; 28 };
38 29
39 explicit CandidateWindowView(views::Widget* parent_frame); 30 explicit CandidateWindowView(gfx::NativeView parent);
40 virtual ~CandidateWindowView(); 31 virtual ~CandidateWindowView();
41 void Init(); 32 views::Widget* InitWidget();
42 33
43 // Adds the given observer. The ownership is not transferred. 34 // Adds the given observer. The ownership is not transferred.
44 void AddObserver(Observer* observer) { 35 void AddObserver(Observer* observer) {
45 observers_.AddObserver(observer); 36 observers_.AddObserver(observer);
46 } 37 }
47 38
48 // Removes the given observer. 39 // Removes the given observer.
49 void RemoveObserver(Observer* observer) { 40 void RemoveObserver(Observer* observer) {
50 observers_.RemoveObserver(observer); 41 observers_.RemoveObserver(observer);
51 } 42 }
52 43
53 // Selects the candidate specified by the index in the current page
54 // (zero-origin). Changes the appearance of the selected candidate,
55 // updates the information in the candidate window as needed.
56 void SelectCandidateAt(int index_in_page);
57
58 // The function is called when a candidate is being dragged. From the
59 // given point, locates the candidate under the mouse cursor, and
60 // selects it.
61 void OnCandidatePressed(const gfx::Point& point);
62
63 // Commits the candidate currently being selected.
64 void CommitCandidate();
65
66 // Hides the lookup table. 44 // Hides the lookup table.
67 void HideLookupTable(); 45 void HideLookupTable();
68 46
69 // Hides the auxiliary text. 47 // Hides the auxiliary text.
70 void HideAuxiliaryText(); 48 void HideAuxiliaryText();
71 49
72 // Hides the preedit text. 50 // Hides the preedit text.
73 void HidePreeditText(); 51 void HidePreeditText();
74 52
75 // Hides whole the candidate window.
76 void HideAll();
77
78 // Shows the lookup table. 53 // Shows the lookup table.
79 void ShowLookupTable(); 54 void ShowLookupTable();
80 55
81 // Shows the auxiliary text. 56 // Shows the auxiliary text.
82 void ShowAuxiliaryText(); 57 void ShowAuxiliaryText();
83 58
84 // Shows the preedit text. 59 // Shows the preedit text.
85 void ShowPreeditText(); 60 void ShowPreeditText();
86 61
87 // Updates the preedit text. 62 // Updates the preedit text.
88 void UpdatePreeditText(const std::string& utf8_text); 63 void UpdatePreeditText(const std::string& utf8_text);
89 64
90 // Returns true if we should update candidate views in the window. For
91 // instance, if we are going to show the same candidates as before, we
92 // don't have to update candidate views. This happens when the user just
93 // moves the cursor in the same page in the candidate window.
94 static bool ShouldUpdateCandidateViews(
95 const CandidateWindow& old_candidate_window,
96 const CandidateWindow& new_candidate_window);
97
98 // Updates candidates of the candidate window from |candidate_window|. 65 // Updates candidates of the candidate window from |candidate_window|.
99 // Candidates are arranged per |orientation|. 66 // Candidates are arranged per |orientation|.
100 void UpdateCandidates(const CandidateWindow& candidate_window); 67 void UpdateCandidates(const CandidateWindow& candidate_window);
101 68
102 // Resizes and moves the parent frame. The two actions should be 69 void SetCursorBounds(const gfx::Rect& cursor_bounds,
103 // performed consecutively as resizing may require the candidate window 70 const gfx::Rect& composition_head);
104 // to move. For instance, we may need to move the candidate window from
105 // below the cursor to above the cursor, if the candidate window becomes
106 // too big to be shown near the bottom of the screen. This function
107 // needs to be called when the visible contents of the candidate window
108 // are modified.
109 void ResizeAndMoveParentFrame();
110
111 // Returns the horizontal offset used for placing the vertical candidate
112 // window so that the first candidate is aligned with the the text being
113 // converted like:
114 //
115 // XXX <- The user is converting XXX
116 // +-----+
117 // |1 XXX|
118 // |2 YYY|
119 // |3 ZZZ|
120 //
121 // Returns 0 if no candidate is present.
122 int GetHorizontalOffset();
123
124 void set_cursor_bounds(const gfx::Rect& cursor_bounds) {
125 cursor_bounds_ = cursor_bounds;
126 }
127
128 void set_composition_head_bounds(
129 const gfx::Rect& composition_head_bounds) {
130 composition_head_bounds_ = composition_head_bounds;
131 }
132
133 const gfx::Rect& cursor_bounds() const { return cursor_bounds_; }
134 const gfx::Rect& composition_head_bounds() const {
135 return composition_head_bounds_;
136 }
137
138 protected:
139 // Override View::VisibilityChanged()
140 virtual void VisibilityChanged(View* starting_from, bool is_visible) OVERRIDE;
141
142 // Override View::OnBoundsChanged()
143 virtual void OnBoundsChanged(const gfx::Rect& previous_bounds) OVERRIDE;
144 71
145 private: 72 private:
146 FRIEND_TEST_ALL_PREFIXES(CandidateWindowViewTest, 73 friend class CandidateWindowViewTest;
147 UpdateCandidatesTest_CursorVisibility); 74
148 FRIEND_TEST_ALL_PREFIXES(CandidateWindowViewTest, ShortcutSettingTest); 75 // Overridden from views::ButtonListener:
149 FRIEND_TEST_ALL_PREFIXES(CandidateWindowViewTest, 76 virtual void ButtonPressed(views::Button* sender,
150 DoNotChangeRowHeightWithLabelSwitchTest); 77 const ui::Event& event) OVERRIDE;
78
79 void SelectCandidateAt(int index_in_page);
80 void UpdateVisibility();
151 81
152 // Initializes the candidate views if needed. 82 // Initializes the candidate views if needed.
153 void MaybeInitializeCandidateViews(const CandidateWindow& candidate_window); 83 void MaybeInitializeCandidateViews(const CandidateWindow& candidate_window);
154 84
155 // Returns the appropriate area (header or footer) to put auxiliary texts. 85 // The candidate window data model.
156 InformationTextArea* GetAuxiliaryTextArea();
157
158 // Returns true if the candidate window is open. The suggestion window does
159 // not count as the candidate window.
160 bool IsCandidateWindowOpen() const;
161
162 // Notifies observers if the candidate window's opened/closed state has
163 // changed from the previous call to this function.
164 void NotifyIfCandidateWindowOpenedOrClosed();
165
166 // The candidate window.
167 CandidateWindow candidate_window_; 86 CandidateWindow candidate_window_;
168 87
169 // The index in the current page of the candidate currently being selected. 88 // The index in the current page of the candidate currently being selected.
170 int selected_candidate_index_in_page_; 89 int selected_candidate_index_in_page_;
171 90
172 // The observers of the object. 91 // The observers of the object.
173 ObserverList<Observer> observers_; 92 ObserverList<Observer> observers_;
174 93
175 // The parent frame.
176 views::Widget* parent_frame_;
177
178 // Views created in the class will be part of tree of |this|, so these 94 // Views created in the class will be part of tree of |this|, so these
179 // child views will be deleted when |this| is deleted. 95 // child views will be deleted when |this| is deleted.
96 InformationTextArea* auxiliary_text_;
97 InformationTextArea* preedit_;
98 views::View* candidate_area_;
180 99
181 // The preedit area is where the preedit text is shown, if it is needed
182 // in cases such as the focus is on a plugin that doesn't support in-line
183 // preedit drawing.
184 InformationTextArea* preedit_area_;
185 // The header area is where the auxiliary text is shown, if the
186 // orientation is horizontal. If the auxiliary text is not provided, we
187 // show nothing. For instance, we show pinyin text like "zhong'guo".
188 InformationTextArea* header_area_;
189 // The candidate area is where candidates are rendered.
190 HidableArea* candidate_area_;
191 // The candidate views are used for rendering candidates. 100 // The candidate views are used for rendering candidates.
192 std::vector<CandidateView*> candidate_views_; 101 std::vector<CandidateView*> candidate_views_;
193 // The footer area is where the auxiliary text is shown, if the
194 // orientation is vertical. Usually the auxiliary text is used for
195 // showing candidate number information like 2/19.
196 InformationTextArea* footer_area_;
197 102
198 // Current columns size in |candidate_area_|. 103 // Current columns size in |candidate_area_|.
199 gfx::Size previous_shortcut_column_size_; 104 gfx::Size previous_shortcut_column_size_;
200 gfx::Size previous_candidate_column_size_; 105 gfx::Size previous_candidate_column_size_;
201 gfx::Size previous_annotation_column_size_; 106 gfx::Size previous_annotation_column_size_;
202 107
203 // The last cursor bounds. 108 // The last cursor bounds.
204 gfx::Rect cursor_bounds_; 109 gfx::Rect cursor_bounds_;
205 110
206 // The last compostion head bounds. 111 // The last compostion head bounds.
207 gfx::Rect composition_head_bounds_; 112 gfx::Rect composition_head_bounds_;
208 113
209 // True if the candidate window should be shown with aligning with composition 114 // True if the candidate window should be shown with aligning with composition
210 // text as opposed to the cursor. 115 // text as opposed to the cursor.
211 bool should_show_at_composition_head_; 116 bool should_show_at_composition_head_;
212 117
213 // True if the candidate window should be shonw on the upper side of 118 // True if the candidate window should be shonw on the upper side of
214 // composition text. 119 // composition text.
215 bool should_show_upper_side_; 120 bool should_show_upper_side_;
216 121
217 // True if the candidate window was open. This is used to determine when to 122 // True if the candidate window was open. This is used to determine when to
218 // send OnCandidateWindowOpened and OnCandidateWindowClosed events. 123 // send OnCandidateWindowOpened and OnCandidateWindowClosed events.
219 bool was_candidate_window_open_; 124 bool was_candidate_window_open_;
220 125
221 // This function judge whether the candidate window should be shown or not,
222 // if should be, shows parent_frame and if not, hides parent_frame.
223 void UpdateParentArea();
224
225 DISALLOW_COPY_AND_ASSIGN(CandidateWindowView); 126 DISALLOW_COPY_AND_ASSIGN(CandidateWindowView);
226 }; 127 };
227 128
228 } // namespace input_method 129 } // namespace input_method
229 } // namespace chromeos 130 } // namespace chromeos
230 131
231 #endif // CHROME_BROWSER_CHROMEOS_INPUT_METHOD_CANDIDATE_WINDOW_VIEW_H_ 132 #endif // CHROME_BROWSER_CHROMEOS_INPUT_METHOD_CANDIDATE_WINDOW_VIEW_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698