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 "ash/ime/candidate_view.h" | 5 #include "ash/ime/candidate_view.h" |
6 | 6 |
7 #include "ash/ime/candidate_window_constants.h" | 7 #include "ash/ime/candidate_window_constants.h" |
8 #include "base/strings/utf_string_conversions.h" | 8 #include "base/strings/utf_string_conversions.h" |
9 #include "ui/base/ime/candidate_window.h" | 9 #include "ui/base/ime/candidate_window.h" |
10 #include "ui/gfx/color_utils.h" | 10 #include "ui/gfx/color_utils.h" |
(...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
133 } // namespace | 133 } // namespace |
134 | 134 |
135 CandidateView::CandidateView( | 135 CandidateView::CandidateView( |
136 views::ButtonListener* listener, | 136 views::ButtonListener* listener, |
137 ui::CandidateWindow::Orientation orientation) | 137 ui::CandidateWindow::Orientation orientation) |
138 : views::CustomButton(listener), | 138 : views::CustomButton(listener), |
139 orientation_(orientation), | 139 orientation_(orientation), |
140 shortcut_label_(NULL), | 140 shortcut_label_(NULL), |
141 candidate_label_(NULL), | 141 candidate_label_(NULL), |
142 annotation_label_(NULL), | 142 annotation_label_(NULL), |
143 infolist_icon_(NULL) { | 143 infolist_icon_(NULL), |
144 shortcut_width_(0), | |
145 candidate_width_(0), | |
146 highlighted_(false) { | |
144 SetBorder(views::Border::CreateEmptyBorder(1, 1, 1, 1)); | 147 SetBorder(views::Border::CreateEmptyBorder(1, 1, 1, 1)); |
145 | 148 |
146 const ui::NativeTheme& theme = *GetNativeTheme(); | 149 const ui::NativeTheme& theme = *GetNativeTheme(); |
147 shortcut_label_ = CreateShortcutLabel(orientation, theme); | 150 shortcut_label_ = CreateShortcutLabel(orientation, theme); |
148 candidate_label_ = CreateCandidateLabel(orientation); | 151 candidate_label_ = CreateCandidateLabel(orientation); |
149 annotation_label_ = CreateAnnotationLabel(orientation, theme); | 152 annotation_label_ = CreateAnnotationLabel(orientation, theme); |
150 | 153 |
151 AddChildView(shortcut_label_); | 154 AddChildView(shortcut_label_); |
152 AddChildView(candidate_label_); | 155 AddChildView(candidate_label_); |
153 AddChildView(annotation_label_); | 156 AddChildView(annotation_label_); |
(...skipping 27 matching lines...) Expand all Loading... | |
181 candidate_label_->SetText(entry.value); | 184 candidate_label_->SetText(entry.value); |
182 annotation_label_->SetText(entry.annotation); | 185 annotation_label_->SetText(entry.annotation); |
183 } | 186 } |
184 | 187 |
185 void CandidateView::SetInfolistIcon(bool enable) { | 188 void CandidateView::SetInfolistIcon(bool enable) { |
186 if (infolist_icon_) | 189 if (infolist_icon_) |
187 infolist_icon_->SetVisible(enable); | 190 infolist_icon_->SetVisible(enable); |
188 SchedulePaint(); | 191 SchedulePaint(); |
189 } | 192 } |
190 | 193 |
191 void CandidateView::StateChanged() { | 194 void CandidateView::SetHighlighted(bool highlighted) { |
192 shortcut_label_->SetEnabled(state() != STATE_DISABLED); | 195 if (highlighted_ == highlighted) |
193 if (state() == STATE_PRESSED) { | 196 return; |
197 | |
198 highlighted_ = highlighted; | |
199 if (highlighted) { | |
194 ui::NativeTheme* theme = GetNativeTheme(); | 200 ui::NativeTheme* theme = GetNativeTheme(); |
195 set_background( | 201 set_background( |
196 views::Background::CreateSolidBackground(theme->GetSystemColor( | 202 views::Background::CreateSolidBackground(theme->GetSystemColor( |
197 ui::NativeTheme::kColorId_TextfieldSelectionBackgroundFocused))); | 203 ui::NativeTheme::kColorId_TextfieldSelectionBackgroundFocused))); |
198 SetBorder(views::Border::CreateSolidBorder( | 204 SetBorder(views::Border::CreateSolidBorder( |
199 1, | 205 1, |
200 theme->GetSystemColor(ui::NativeTheme::kColorId_FocusedBorderColor))); | 206 theme->GetSystemColor(ui::NativeTheme::kColorId_FocusedBorderColor))); |
201 | 207 |
202 // Cancel currently focused one. | 208 // Cancel currently focused one. |
203 for (int i = 0; i < parent()->child_count(); ++i) { | 209 for (int i = 0; i < parent()->child_count(); ++i) { |
204 CandidateView* view = | 210 CandidateView* view = |
205 static_cast<CandidateView*>((parent()->child_at(i))); | 211 static_cast<CandidateView*>((parent()->child_at(i))); |
206 if (view != this && view->state() == STATE_PRESSED) | 212 if (view != this) |
207 view->SetState(STATE_NORMAL); | 213 view->SetHighlighted(false); |
208 } | 214 } |
209 } else { | 215 } else { |
210 set_background(NULL); | 216 set_background(NULL); |
211 SetBorder(views::Border::CreateEmptyBorder(1, 1, 1, 1)); | 217 SetBorder(views::Border::CreateEmptyBorder(1, 1, 1, 1)); |
212 } | 218 } |
219 SchedulePaint(); | |
220 } | |
221 | |
222 void CandidateView::StateChanged() { | |
223 shortcut_label_->SetEnabled(state() != STATE_DISABLED); | |
224 if (state() == STATE_PRESSED) | |
225 SetHighlighted(true); | |
oshima
2014/04/23 23:50:07
shouldn't this be
SetHighlighted(state() == STAT
Jun Mukai
2014/04/23 23:58:02
No, state() can be changed to 'HOVER' and then 'NO
oshima
2014/04/24 00:05:37
Ah i see. Can you add test for this? It looks subt
Jun Mukai
2014/04/24 19:01:39
Done.
| |
213 } | 226 } |
214 | 227 |
215 bool CandidateView::OnMouseDragged(const ui::MouseEvent& event) { | 228 bool CandidateView::OnMouseDragged(const ui::MouseEvent& event) { |
216 if (!HitTestPoint(event.location())) { | 229 if (!HitTestPoint(event.location())) { |
217 // Moves the drag target to the sibling view. | 230 // Moves the drag target to the sibling view. |
218 gfx::Point location_in_widget(event.location()); | 231 gfx::Point location_in_widget(event.location()); |
219 ConvertPointToWidget(this, &location_in_widget); | 232 ConvertPointToWidget(this, &location_in_widget); |
220 for (int i = 0; i < parent()->child_count(); ++i) { | 233 for (int i = 0; i < parent()->child_count(); ++i) { |
221 views::View* sibling = parent()->child_at(i); | 234 CandidateView* sibling = |
235 static_cast<CandidateView*>(parent()->child_at(i)); | |
222 if (sibling == this) | 236 if (sibling == this) |
223 continue; | 237 continue; |
224 gfx::Point location_in_sibling(location_in_widget); | 238 gfx::Point location_in_sibling(location_in_widget); |
225 ConvertPointFromWidget(sibling, &location_in_sibling); | 239 ConvertPointFromWidget(sibling, &location_in_sibling); |
226 if (sibling->HitTestPoint(location_in_sibling)) { | 240 if (sibling->HitTestPoint(location_in_sibling)) { |
227 GetWidget()->GetRootView()->SetMouseHandler(sibling); | 241 GetWidget()->GetRootView()->SetMouseHandler(sibling); |
228 return sibling->OnMouseDragged(event); | 242 sibling->SetHighlighted(true); |
243 return sibling->OnMouseDragged(ui::MouseEvent(event, this, sibling)); | |
229 } | 244 } |
230 } | 245 } |
231 | 246 |
232 return false; | 247 return false; |
233 } | 248 } |
234 | 249 |
235 return views::CustomButton::OnMouseDragged(event); | 250 return views::CustomButton::OnMouseDragged(event); |
236 } | 251 } |
237 | 252 |
238 void CandidateView::Layout() { | 253 void CandidateView::Layout() { |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
277 } | 292 } |
278 | 293 |
279 // Reserves the margin for infolist_icon even if it's not visible. | 294 // Reserves the margin for infolist_icon even if it's not visible. |
280 size.Enlarge( | 295 size.Enlarge( |
281 kInfolistIndicatorIconWidth + kInfolistIndicatorIconPadding * 2, 0); | 296 kInfolistIndicatorIconWidth + kInfolistIndicatorIconPadding * 2, 0); |
282 return size; | 297 return size; |
283 } | 298 } |
284 | 299 |
285 } // namespace ime | 300 } // namespace ime |
286 } // namespace ash | 301 } // namespace ash |
OLD | NEW |