OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 #include "chrome/browser/chromeos/input_method/candidate_view.h" | 5 #include "chrome/browser/chromeos/input_method/candidate_view.h" |
6 | 6 |
7 #include "base/strings/utf_string_conversions.h" | 7 #include "base/strings/utf_string_conversions.h" |
8 #include "chrome/browser/chromeos/input_method/candidate_window_constants.h" | 8 #include "chrome/browser/chromeos/input_method/candidate_window_constants.h" |
9 #include "ui/base/ime/candidate_window.h" | 9 #include "chromeos/ime/candidate_window.h" |
10 #include "ui/gfx/color_utils.h" | 10 #include "ui/gfx/color_utils.h" |
11 #include "ui/native_theme/native_theme.h" | 11 #include "ui/native_theme/native_theme.h" |
12 #include "ui/views/background.h" | 12 #include "ui/views/background.h" |
13 #include "ui/views/border.h" | 13 #include "ui/views/border.h" |
14 #include "ui/views/controls/label.h" | 14 #include "ui/views/controls/label.h" |
15 #include "ui/views/widget/widget.h" | 15 #include "ui/views/widget/widget.h" |
16 | 16 |
17 namespace chromeos { | 17 namespace chromeos { |
18 namespace input_method { | 18 namespace input_method { |
19 | 19 |
(...skipping 16 matching lines...) Expand all Loading... |
36 size.SetToMin(gfx::Size(kMaxCandidateLabelWidth, size.height())); | 36 size.SetToMin(gfx::Size(kMaxCandidateLabelWidth, size.height())); |
37 return size; | 37 return size; |
38 } | 38 } |
39 | 39 |
40 DISALLOW_COPY_AND_ASSIGN(VerticalCandidateLabel); | 40 DISALLOW_COPY_AND_ASSIGN(VerticalCandidateLabel); |
41 }; | 41 }; |
42 | 42 |
43 // Creates the shortcut label, and returns it (never returns NULL). | 43 // Creates the shortcut label, and returns it (never returns NULL). |
44 // The label text is not set in this function. | 44 // The label text is not set in this function. |
45 views::Label* CreateShortcutLabel( | 45 views::Label* CreateShortcutLabel( |
46 ui::CandidateWindow::Orientation orientation, | 46 CandidateWindow::Orientation orientation, |
47 const ui::NativeTheme& theme) { | 47 const ui::NativeTheme& theme) { |
48 // Create the shortcut label. The label will be owned by | 48 // Create the shortcut label. The label will be owned by |
49 // |wrapped_shortcut_label|, hence it's deleted when | 49 // |wrapped_shortcut_label|, hence it's deleted when |
50 // |wrapped_shortcut_label| is deleted. | 50 // |wrapped_shortcut_label| is deleted. |
51 views::Label* shortcut_label = new views::Label; | 51 views::Label* shortcut_label = new views::Label; |
52 | 52 |
53 if (orientation == ui::CandidateWindow::VERTICAL) { | 53 if (orientation == CandidateWindow::VERTICAL) { |
54 shortcut_label->SetFontList( | 54 shortcut_label->SetFontList( |
55 shortcut_label->font_list().DeriveFontListWithSizeDeltaAndStyle( | 55 shortcut_label->font_list().DeriveFontListWithSizeDeltaAndStyle( |
56 kFontSizeDelta, gfx::Font::BOLD)); | 56 kFontSizeDelta, gfx::Font::BOLD)); |
57 } else { | 57 } else { |
58 shortcut_label->SetFontList( | 58 shortcut_label->SetFontList( |
59 shortcut_label->font_list().DeriveFontListWithSizeDelta( | 59 shortcut_label->font_list().DeriveFontListWithSizeDelta( |
60 kFontSizeDelta)); | 60 kFontSizeDelta)); |
61 } | 61 } |
62 // TODO(satorux): Maybe we need to use language specific fonts for | 62 // TODO(satorux): Maybe we need to use language specific fonts for |
63 // candidate_label, like Chinese font for Chinese input method? | 63 // candidate_label, like Chinese font for Chinese input method? |
64 shortcut_label->SetEnabledColor(theme.GetSystemColor( | 64 shortcut_label->SetEnabledColor(theme.GetSystemColor( |
65 ui::NativeTheme::kColorId_LabelEnabledColor)); | 65 ui::NativeTheme::kColorId_LabelEnabledColor)); |
66 shortcut_label->SetDisabledColor(theme.GetSystemColor( | 66 shortcut_label->SetDisabledColor(theme.GetSystemColor( |
67 ui::NativeTheme::kColorId_LabelDisabledColor)); | 67 ui::NativeTheme::kColorId_LabelDisabledColor)); |
68 | 68 |
69 // Setup paddings. | 69 // Setup paddings. |
70 const gfx::Insets kVerticalShortcutLabelInsets(1, 6, 1, 6); | 70 const gfx::Insets kVerticalShortcutLabelInsets(1, 6, 1, 6); |
71 const gfx::Insets kHorizontalShortcutLabelInsets(1, 3, 1, 0); | 71 const gfx::Insets kHorizontalShortcutLabelInsets(1, 3, 1, 0); |
72 const gfx::Insets insets = | 72 const gfx::Insets insets = |
73 (orientation == ui::CandidateWindow::VERTICAL ? | 73 (orientation == CandidateWindow::VERTICAL ? |
74 kVerticalShortcutLabelInsets : | 74 kVerticalShortcutLabelInsets : |
75 kHorizontalShortcutLabelInsets); | 75 kHorizontalShortcutLabelInsets); |
76 shortcut_label->set_border(views::Border::CreateEmptyBorder( | 76 shortcut_label->set_border(views::Border::CreateEmptyBorder( |
77 insets.top(), insets.left(), insets.bottom(), insets.right())); | 77 insets.top(), insets.left(), insets.bottom(), insets.right())); |
78 | 78 |
79 // Add decoration based on the orientation. | 79 // Add decoration based on the orientation. |
80 if (orientation == ui::CandidateWindow::VERTICAL) { | 80 if (orientation == CandidateWindow::VERTICAL) { |
81 // Set the background color. | 81 // Set the background color. |
82 SkColor blackish = color_utils::AlphaBlend( | 82 SkColor blackish = color_utils::AlphaBlend( |
83 SK_ColorBLACK, | 83 SK_ColorBLACK, |
84 theme.GetSystemColor(ui::NativeTheme::kColorId_WindowBackground), | 84 theme.GetSystemColor(ui::NativeTheme::kColorId_WindowBackground), |
85 0x40); | 85 0x40); |
86 SkColor transparent_blakish = color_utils::AlphaBlend( | 86 SkColor transparent_blakish = color_utils::AlphaBlend( |
87 SK_ColorTRANSPARENT, blackish, 0xE0); | 87 SK_ColorTRANSPARENT, blackish, 0xE0); |
88 shortcut_label->set_background( | 88 shortcut_label->set_background( |
89 views::Background::CreateSolidBackground(transparent_blakish)); | 89 views::Background::CreateSolidBackground(transparent_blakish)); |
90 } | 90 } |
91 | 91 |
92 return shortcut_label; | 92 return shortcut_label; |
93 } | 93 } |
94 | 94 |
95 // Creates the candidate label, and returns it (never returns NULL). | 95 // Creates the candidate label, and returns it (never returns NULL). |
96 // The label text is not set in this function. | 96 // The label text is not set in this function. |
97 views::Label* CreateCandidateLabel( | 97 views::Label* CreateCandidateLabel( |
98 ui::CandidateWindow::Orientation orientation) { | 98 CandidateWindow::Orientation orientation) { |
99 views::Label* candidate_label = NULL; | 99 views::Label* candidate_label = NULL; |
100 | 100 |
101 // Create the candidate label. The label will be added to |this| as a | 101 // Create the candidate label. The label will be added to |this| as a |
102 // child view, hence it's deleted when |this| is deleted. | 102 // child view, hence it's deleted when |this| is deleted. |
103 if (orientation == ui::CandidateWindow::VERTICAL) { | 103 if (orientation == CandidateWindow::VERTICAL) { |
104 candidate_label = new VerticalCandidateLabel; | 104 candidate_label = new VerticalCandidateLabel; |
105 } else { | 105 } else { |
106 candidate_label = new views::Label; | 106 candidate_label = new views::Label; |
107 } | 107 } |
108 | 108 |
109 // Change the font size. | 109 // Change the font size. |
110 candidate_label->SetFontList( | 110 candidate_label->SetFontList( |
111 candidate_label->font_list().DeriveFontListWithSizeDelta(kFontSizeDelta)); | 111 candidate_label->font_list().DeriveFontListWithSizeDelta(kFontSizeDelta)); |
112 candidate_label->SetHorizontalAlignment(gfx::ALIGN_LEFT); | 112 candidate_label->SetHorizontalAlignment(gfx::ALIGN_LEFT); |
113 | 113 |
114 return candidate_label; | 114 return candidate_label; |
115 } | 115 } |
116 | 116 |
117 // Creates the annotation label, and return it (never returns NULL). | 117 // Creates the annotation label, and return it (never returns NULL). |
118 // The label text is not set in this function. | 118 // The label text is not set in this function. |
119 views::Label* CreateAnnotationLabel( | 119 views::Label* CreateAnnotationLabel( |
120 ui::CandidateWindow::Orientation orientation, | 120 CandidateWindow::Orientation orientation, const ui::NativeTheme& theme) { |
121 const ui::NativeTheme& theme) { | |
122 // Create the annotation label. | 121 // Create the annotation label. |
123 views::Label* annotation_label = new views::Label; | 122 views::Label* annotation_label = new views::Label; |
124 | 123 |
125 // Change the font size and color. | 124 // Change the font size and color. |
126 annotation_label->SetFontList( | 125 annotation_label->SetFontList( |
127 annotation_label->font_list().DeriveFontListWithSizeDelta( | 126 annotation_label->font_list().DeriveFontListWithSizeDelta( |
128 kFontSizeDelta)); | 127 kFontSizeDelta)); |
129 annotation_label->SetEnabledColor(theme.GetSystemColor( | 128 annotation_label->SetEnabledColor(theme.GetSystemColor( |
130 ui::NativeTheme::kColorId_LabelDisabledColor)); | 129 ui::NativeTheme::kColorId_LabelDisabledColor)); |
131 annotation_label->SetHorizontalAlignment(gfx::ALIGN_LEFT); | 130 annotation_label->SetHorizontalAlignment(gfx::ALIGN_LEFT); |
132 | 131 |
133 return annotation_label; | 132 return annotation_label; |
134 } | 133 } |
135 | 134 |
136 } // namespace | 135 } // namespace |
137 | 136 |
138 CandidateView::CandidateView( | 137 CandidateView::CandidateView( |
139 views::ButtonListener* listener, | 138 views::ButtonListener* listener, |
140 ui::CandidateWindow::Orientation orientation) | 139 CandidateWindow::Orientation orientation) |
141 : views::CustomButton(listener), | 140 : views::CustomButton(listener), |
142 orientation_(orientation), | 141 orientation_(orientation), |
143 shortcut_label_(NULL), | 142 shortcut_label_(NULL), |
144 candidate_label_(NULL), | 143 candidate_label_(NULL), |
145 annotation_label_(NULL), | 144 annotation_label_(NULL), |
146 infolist_icon_(NULL) { | 145 infolist_icon_(NULL) { |
147 set_border(views::Border::CreateEmptyBorder(1, 1, 1, 1)); | 146 set_border(views::Border::CreateEmptyBorder(1, 1, 1, 1)); |
148 | 147 |
149 const ui::NativeTheme& theme = *GetNativeTheme(); | 148 const ui::NativeTheme& theme = *GetNativeTheme(); |
150 shortcut_label_ = CreateShortcutLabel(orientation, theme); | 149 shortcut_label_ = CreateShortcutLabel(orientation, theme); |
151 candidate_label_ = CreateCandidateLabel(orientation); | 150 candidate_label_ = CreateCandidateLabel(orientation); |
152 annotation_label_ = CreateAnnotationLabel(orientation, theme); | 151 annotation_label_ = CreateAnnotationLabel(orientation, theme); |
153 | 152 |
154 AddChildView(shortcut_label_); | 153 AddChildView(shortcut_label_); |
155 AddChildView(candidate_label_); | 154 AddChildView(candidate_label_); |
156 AddChildView(annotation_label_); | 155 AddChildView(annotation_label_); |
157 | 156 |
158 if (orientation == ui::CandidateWindow::VERTICAL) { | 157 if (orientation == CandidateWindow::VERTICAL) { |
159 infolist_icon_ = new views::View; | 158 infolist_icon_ = new views::View; |
160 infolist_icon_->set_background( | 159 infolist_icon_->set_background( |
161 views::Background::CreateSolidBackground(theme.GetSystemColor( | 160 views::Background::CreateSolidBackground(theme.GetSystemColor( |
162 ui::NativeTheme::kColorId_FocusedBorderColor))); | 161 ui::NativeTheme::kColorId_FocusedBorderColor))); |
163 AddChildView(infolist_icon_); | 162 AddChildView(infolist_icon_); |
164 } | 163 } |
165 } | 164 } |
166 | 165 |
167 void CandidateView::GetPreferredWidths(int* shortcut_width, | 166 void CandidateView::GetPreferredWidths(int* shortcut_width, |
168 int* candidate_width) { | 167 int* candidate_width) { |
169 *shortcut_width = shortcut_label_->GetPreferredSize().width(); | 168 *shortcut_width = shortcut_label_->GetPreferredSize().width(); |
170 *candidate_width = candidate_label_->GetPreferredSize().width(); | 169 *candidate_width = candidate_label_->GetPreferredSize().width(); |
171 } | 170 } |
172 | 171 |
173 void CandidateView::SetWidths(int shortcut_width, int candidate_width) { | 172 void CandidateView::SetWidths(int shortcut_width, int candidate_width) { |
174 shortcut_width_ = shortcut_width; | 173 shortcut_width_ = shortcut_width; |
175 shortcut_label_->SetVisible(shortcut_width_ != 0); | 174 shortcut_label_->SetVisible(shortcut_width_ != 0); |
176 candidate_width_ = candidate_width; | 175 candidate_width_ = candidate_width; |
177 } | 176 } |
178 | 177 |
179 void CandidateView::SetEntry(const ui::CandidateWindow::Entry& entry) { | 178 void CandidateView::SetEntry(const CandidateWindow::Entry& entry) { |
180 std::string label = entry.label; | 179 std::string label = entry.label; |
181 if (!label.empty() && orientation_ != ui::CandidateWindow::VERTICAL) | 180 if (!label.empty() && orientation_ != CandidateWindow::VERTICAL) |
182 label += '.'; | 181 label += '.'; |
183 shortcut_label_->SetText(base::UTF8ToUTF16(label)); | 182 shortcut_label_->SetText(base::UTF8ToUTF16(label)); |
184 candidate_label_->SetText(base::UTF8ToUTF16(entry.value)); | 183 candidate_label_->SetText(base::UTF8ToUTF16(entry.value)); |
185 annotation_label_->SetText(base::UTF8ToUTF16(entry.annotation)); | 184 annotation_label_->SetText(base::UTF8ToUTF16(entry.annotation)); |
186 } | 185 } |
187 | 186 |
188 void CandidateView::SetInfolistIcon(bool enable) { | 187 void CandidateView::SetInfolistIcon(bool enable) { |
189 if (infolist_icon_) | 188 if (infolist_icon_) |
190 infolist_icon_->SetVisible(enable); | 189 infolist_icon_->SetVisible(enable); |
191 SchedulePaint(); | 190 SchedulePaint(); |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
233 } | 232 } |
234 | 233 |
235 return false; | 234 return false; |
236 } | 235 } |
237 | 236 |
238 return views::CustomButton::OnMouseDragged(event); | 237 return views::CustomButton::OnMouseDragged(event); |
239 } | 238 } |
240 | 239 |
241 void CandidateView::Layout() { | 240 void CandidateView::Layout() { |
242 const int padding_width = | 241 const int padding_width = |
243 orientation_ == ui::CandidateWindow::VERTICAL ? 4 : 6; | 242 orientation_ == CandidateWindow::VERTICAL ? 4 : 6; |
244 int x = 0; | 243 int x = 0; |
245 shortcut_label_->SetBounds(x, 0, shortcut_width_, height()); | 244 shortcut_label_->SetBounds(x, 0, shortcut_width_, height()); |
246 if (shortcut_width_ > 0) | 245 if (shortcut_width_ > 0) |
247 x += shortcut_width_ + padding_width; | 246 x += shortcut_width_ + padding_width; |
248 candidate_label_->SetBounds(x, 0, candidate_width_, height()); | 247 candidate_label_->SetBounds(x, 0, candidate_width_, height()); |
249 x += candidate_width_ + padding_width; | 248 x += candidate_width_ + padding_width; |
250 | 249 |
251 int right = bounds().right(); | 250 int right = bounds().right(); |
252 if (infolist_icon_ && infolist_icon_->visible()) { | 251 if (infolist_icon_ && infolist_icon_->visible()) { |
253 infolist_icon_->SetBounds( | 252 infolist_icon_->SetBounds( |
254 right - kInfolistIndicatorIconWidth - kInfolistIndicatorIconPadding, | 253 right - kInfolistIndicatorIconWidth - kInfolistIndicatorIconPadding, |
255 kInfolistIndicatorIconPadding, | 254 kInfolistIndicatorIconPadding, |
256 kInfolistIndicatorIconWidth, | 255 kInfolistIndicatorIconWidth, |
257 height() - kInfolistIndicatorIconPadding * 2); | 256 height() - kInfolistIndicatorIconPadding * 2); |
258 right -= kInfolistIndicatorIconWidth + kInfolistIndicatorIconPadding * 2; | 257 right -= kInfolistIndicatorIconWidth + kInfolistIndicatorIconPadding * 2; |
259 } | 258 } |
260 annotation_label_->SetBounds(x, 0, right - x, height()); | 259 annotation_label_->SetBounds(x, 0, right - x, height()); |
261 } | 260 } |
262 | 261 |
263 gfx::Size CandidateView::GetPreferredSize() { | 262 gfx::Size CandidateView::GetPreferredSize() { |
264 const int padding_width = | 263 const int padding_width = |
265 orientation_ == ui::CandidateWindow::VERTICAL ? 4 : 6; | 264 orientation_ == CandidateWindow::VERTICAL ? 4 : 6; |
266 gfx::Size size; | 265 gfx::Size size; |
267 if (shortcut_label_->visible()) { | 266 if (shortcut_label_->visible()) { |
268 size = shortcut_label_->GetPreferredSize(); | 267 size = shortcut_label_->GetPreferredSize(); |
269 size.Enlarge(padding_width, 0); | 268 size.Enlarge(padding_width, 0); |
270 } | 269 } |
271 gfx::Size candidate_size = candidate_label_->GetPreferredSize(); | 270 gfx::Size candidate_size = candidate_label_->GetPreferredSize(); |
272 size.Enlarge(candidate_size.width() + padding_width, 0); | 271 size.Enlarge(candidate_size.width() + padding_width, 0); |
273 size.SetToMax(candidate_size); | 272 size.SetToMax(candidate_size); |
274 if (annotation_label_->visible()) { | 273 if (annotation_label_->visible()) { |
275 gfx::Size annotation_size = annotation_label_->GetPreferredSize(); | 274 gfx::Size annotation_size = annotation_label_->GetPreferredSize(); |
276 size.Enlarge(annotation_size.width() + padding_width, 0); | 275 size.Enlarge(annotation_size.width() + padding_width, 0); |
277 size.SetToMax(annotation_size); | 276 size.SetToMax(annotation_size); |
278 } | 277 } |
279 | 278 |
280 // Reserves the margin for infolist_icon even if it's not visible. | 279 // Reserves the margin for infolist_icon even if it's not visible. |
281 size.Enlarge( | 280 size.Enlarge( |
282 kInfolistIndicatorIconWidth + kInfolistIndicatorIconPadding * 2, 0); | 281 kInfolistIndicatorIconWidth + kInfolistIndicatorIconPadding * 2, 0); |
283 return size; | 282 return size; |
284 } | 283 } |
285 | 284 |
286 } // namespace input_method | 285 } // namespace input_method |
287 } // namespace chromeos | 286 } // namespace chromeos |
OLD | NEW |