OLD | NEW |
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_VIEW_H_ | 5 #ifndef CHROME_BROWSER_CHROMEOS_INPUT_METHOD_CANDIDATE_VIEW_H_ |
6 #define CHROME_BROWSER_CHROMEOS_INPUT_METHOD_CANDIDATE_VIEW_H_ | 6 #define CHROME_BROWSER_CHROMEOS_INPUT_METHOD_CANDIDATE_VIEW_H_ |
7 | 7 |
8 #include "base/gtest_prod_util.h" | 8 #include "base/gtest_prod_util.h" |
9 #include "chromeos/ime/candidate_window.h" | 9 #include "chromeos/ime/candidate_window.h" |
| 10 #include "ui/views/controls/button/custom_button.h" |
10 #include "ui/views/controls/label.h" | 11 #include "ui/views/controls/label.h" |
11 #include "ui/views/view.h" | 12 #include "ui/views/view.h" |
12 | 13 |
13 namespace chromeos { | 14 namespace chromeos { |
14 namespace input_method { | 15 namespace input_method { |
15 | 16 |
16 class CandidateWindowView; | |
17 | |
18 // CandidateView renderes a row of a candidate. | 17 // CandidateView renderes a row of a candidate. |
19 class CandidateView : public views::View { | 18 class CandidateView : public views::CustomButton { |
20 public: | 19 public: |
21 CandidateView(CandidateWindowView* parent_candidate_window, | 20 CandidateView(views::ButtonListener* listener, |
22 int index_in_page, | |
23 CandidateWindow::Orientation orientation); | 21 CandidateWindow::Orientation orientation); |
24 virtual ~CandidateView() {} | 22 virtual ~CandidateView() {} |
25 // Initializes the candidate view with the given column widths. | |
26 // A width of 0 means that the column is resizable. | |
27 void Init(int shortcut_column_width, | |
28 int candidate_column_width, | |
29 int annotation_column_width, | |
30 int column_height); | |
31 | 23 |
32 // Sets candidate text to the given text. | 24 void GetPreferredWidths(int* shortcut_width, |
33 void SetCandidateText(const base::string16& text); | 25 int* candidate_width); |
34 | 26 |
35 // Sets shortcut text to the given text. | 27 void SetWidths(int shortcut_width, |
36 void SetShortcutText(const base::string16& text); | 28 int candidate_width); |
37 | 29 |
38 // Sets annotation text to the given text. | 30 void SetEntry(const CandidateWindow::Entry& entry); |
39 void SetAnnotationText(const base::string16& text); | |
40 | 31 |
41 // Sets infolist icon. | 32 // Sets infolist icon. |
42 void SetInfolistIcon(bool enable); | 33 void SetInfolistIcon(bool enable); |
43 | 34 |
44 // Selects the candidate row. Changes the appearance to make it look | |
45 // like a selected candidate. | |
46 void Select(); | |
47 | |
48 // Unselects the candidate row. Changes the appearance to make it look | |
49 // like an unselected candidate. | |
50 void Unselect(); | |
51 | |
52 // Enables or disables the candidate row based on |enabled|. Changes the | |
53 // appearance to make it look like unclickable area. | |
54 void SetRowEnabled(bool enabled); | |
55 | |
56 // Returns the relative position of the candidate label. | |
57 gfx::Point GetCandidateLabelPosition() const; | |
58 | |
59 private: | 35 private: |
60 friend class CandidateWindowViewTest; | 36 friend class CandidateWindowViewTest; |
61 FRIEND_TEST_ALL_PREFIXES(CandidateWindowViewTest, ShortcutSettingTest); | 37 FRIEND_TEST_ALL_PREFIXES(CandidateWindowViewTest, ShortcutSettingTest); |
| 38 |
| 39 // Overridden from views::CustomButton: |
| 40 virtual void StateChanged() OVERRIDE; |
| 41 |
62 // Overridden from View: | 42 // Overridden from View: |
63 virtual bool OnMousePressed(const ui::MouseEvent& event) OVERRIDE; | 43 virtual bool OnMouseDragged(const ui::MouseEvent& event) OVERRIDE; |
64 virtual void OnGestureEvent(ui::GestureEvent* event) OVERRIDE; | 44 virtual void Layout() OVERRIDE; |
65 | 45 virtual gfx::Size GetPreferredSize() OVERRIDE; |
66 // Selects the candidate located at the point. | |
67 void SelectCandidateAt(const gfx::Point& location); | |
68 | |
69 // Notifies labels of their new background colors. Called whenever the view's | |
70 // background color changes. | |
71 void UpdateLabelBackgroundColors(); | |
72 | |
73 // Zero-origin index in the current page. | |
74 int index_in_page_; | |
75 | 46 |
76 // The orientation of the candidate view. | 47 // The orientation of the candidate view. |
77 CandidateWindow::Orientation orientation_; | 48 CandidateWindow::Orientation orientation_; |
78 | 49 |
79 // The parent candidate window that contains this view. | |
80 CandidateWindowView* parent_candidate_window_; | |
81 | |
82 // Views created in the class will be part of tree of |this|, so these | 50 // Views created in the class will be part of tree of |this|, so these |
83 // child views will be deleted when |this| is deleted. | 51 // child views will be deleted when |this| is deleted. |
84 | 52 |
85 // The shortcut label renders shortcut numbers like 1, 2, and 3. | 53 // The shortcut label renders shortcut numbers like 1, 2, and 3. |
86 views::Label* shortcut_label_; | 54 views::Label* shortcut_label_; |
87 // The candidate label renders candidates. | 55 // The candidate label renders candidates. |
88 views::Label* candidate_label_; | 56 views::Label* candidate_label_; |
89 // The annotation label renders annotations. | 57 // The annotation label renders annotations. |
90 views::Label* annotation_label_; | 58 views::Label* annotation_label_; |
91 | 59 |
| 60 int shortcut_width_; |
| 61 int candidate_width_; |
| 62 |
92 // The infolist icon. | 63 // The infolist icon. |
93 views::View* infolist_icon_; | 64 views::View* infolist_icon_; |
94 bool infolist_icon_enabled_; | |
95 | 65 |
96 DISALLOW_COPY_AND_ASSIGN(CandidateView); | 66 DISALLOW_COPY_AND_ASSIGN(CandidateView); |
97 }; | 67 }; |
98 | 68 |
99 } // namespace input_method | 69 } // namespace input_method |
100 } // namespace chromeos | 70 } // namespace chromeos |
101 | 71 |
102 #endif // CHROME_BROWSER_CHROMEOS_INPUT_METHOD_CANDIDATE_VIEW_H_ | 72 #endif // CHROME_BROWSER_CHROMEOS_INPUT_METHOD_CANDIDATE_VIEW_H_ |
OLD | NEW |