Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2012 The Chromium Authors. All rights reserved. | 1 // Copyright 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 #include "ash/system/tray/hover_highlight_view.h" | 5 #include "ash/system/tray/hover_highlight_view.h" |
| 6 | 6 |
| 7 #include "ash/system/tray/fixed_sized_image_view.h" | 7 #include "ash/system/tray/fixed_sized_image_view.h" |
| 8 #include "ash/system/tray/tray_constants.h" | 8 #include "ash/system/tray/tray_constants.h" |
| 9 #include "ash/system/tray/view_click_listener.h" | 9 #include "ash/system/tray/view_click_listener.h" |
| 10 #include "base/command_line.h" | |
|
flackr
2014/10/01 18:29:21
Remove this include?
jonross
2014/10/01 18:51:16
Done.
| |
| 10 #include "ui/accessibility/ax_view_state.h" | 11 #include "ui/accessibility/ax_view_state.h" |
| 11 #include "ui/base/resource/resource_bundle.h" | 12 #include "ui/base/resource/resource_bundle.h" |
| 13 #include "ui/base/ui_base_switches_util.h" | |
| 12 #include "ui/gfx/canvas.h" | 14 #include "ui/gfx/canvas.h" |
| 13 #include "ui/gfx/font_list.h" | 15 #include "ui/gfx/font_list.h" |
| 14 #include "ui/resources/grit/ui_resources.h" | 16 #include "ui/resources/grit/ui_resources.h" |
| 15 #include "ui/views/border.h" | 17 #include "ui/views/border.h" |
| 16 #include "ui/views/controls/image_view.h" | 18 #include "ui/views/controls/image_view.h" |
| 17 #include "ui/views/controls/label.h" | 19 #include "ui/views/controls/label.h" |
| 18 #include "ui/views/layout/box_layout.h" | 20 #include "ui/views/layout/box_layout.h" |
| 19 #include "ui/views/layout/fill_layout.h" | 21 #include "ui/views/layout/fill_layout.h" |
| 20 | 22 |
| 21 namespace { | 23 namespace { |
| (...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 123 return AddLabel(text, gfx::ALIGN_LEFT, style); | 125 return AddLabel(text, gfx::ALIGN_LEFT, style); |
| 124 } | 126 } |
| 125 | 127 |
| 126 void HoverHighlightView::SetExpandable(bool expandable) { | 128 void HoverHighlightView::SetExpandable(bool expandable) { |
| 127 if (expandable != expandable_) { | 129 if (expandable != expandable_) { |
| 128 expandable_ = expandable; | 130 expandable_ = expandable; |
| 129 InvalidateLayout(); | 131 InvalidateLayout(); |
| 130 } | 132 } |
| 131 } | 133 } |
| 132 | 134 |
| 135 void HoverHighlightView::SetHoverHighlight(bool hover) { | |
| 136 if (hover_ == hover) | |
| 137 return; | |
| 138 hover_ = hover; | |
| 139 if (!text_label_) | |
| 140 return; | |
| 141 if (hover_ && text_highlight_color_) | |
| 142 text_label_->SetEnabledColor(text_highlight_color_); | |
| 143 if (!hover_ && text_default_color_) | |
| 144 text_label_->SetEnabledColor(text_default_color_); | |
| 145 SchedulePaint(); | |
| 146 } | |
| 147 | |
| 133 bool HoverHighlightView::PerformAction(const ui::Event& event) { | 148 bool HoverHighlightView::PerformAction(const ui::Event& event) { |
| 134 if (!listener_) | 149 if (!listener_) |
| 135 return false; | 150 return false; |
| 136 listener_->OnViewClicked(this); | 151 listener_->OnViewClicked(this); |
| 137 return true; | 152 return true; |
| 138 } | 153 } |
| 139 | 154 |
| 140 void HoverHighlightView::GetAccessibleState(ui::AXViewState* state) { | 155 void HoverHighlightView::GetAccessibleState(ui::AXViewState* state) { |
| 141 ActionableView::GetAccessibleState(state); | 156 ActionableView::GetAccessibleState(state); |
| 142 | 157 |
| 143 if (checkable_) { | 158 if (checkable_) { |
| 144 state->role = ui::AX_ROLE_CHECK_BOX; | 159 state->role = ui::AX_ROLE_CHECK_BOX; |
| 145 if (checked_) | 160 if (checked_) |
| 146 state->AddStateFlag(ui::AX_STATE_CHECKED); | 161 state->AddStateFlag(ui::AX_STATE_CHECKED); |
| 147 } | 162 } |
| 148 } | 163 } |
| 149 | 164 |
| 150 gfx::Size HoverHighlightView::GetPreferredSize() const { | 165 gfx::Size HoverHighlightView::GetPreferredSize() const { |
| 151 gfx::Size size = ActionableView::GetPreferredSize(); | 166 gfx::Size size = ActionableView::GetPreferredSize(); |
| 152 if (!expandable_ || size.height() < kTrayPopupItemHeight) | 167 if (!expandable_ || size.height() < kTrayPopupItemHeight) |
| 153 size.set_height(kTrayPopupItemHeight); | 168 size.set_height(kTrayPopupItemHeight); |
| 154 return size; | 169 return size; |
| 155 } | 170 } |
| 156 | 171 |
| 157 int HoverHighlightView::GetHeightForWidth(int width) const { | 172 int HoverHighlightView::GetHeightForWidth(int width) const { |
| 158 return GetPreferredSize().height(); | 173 return GetPreferredSize().height(); |
| 159 } | 174 } |
| 160 | 175 |
| 161 void HoverHighlightView::OnMouseEntered(const ui::MouseEvent& event) { | 176 void HoverHighlightView::OnMouseEntered(const ui::MouseEvent& event) { |
| 162 hover_ = true; | 177 SetHoverHighlight(true); |
| 163 if (text_highlight_color_ && text_label_) | |
| 164 text_label_->SetEnabledColor(text_highlight_color_); | |
| 165 SchedulePaint(); | |
| 166 } | 178 } |
| 167 | 179 |
| 168 void HoverHighlightView::OnMouseExited(const ui::MouseEvent& event) { | 180 void HoverHighlightView::OnMouseExited(const ui::MouseEvent& event) { |
| 169 hover_ = false; | 181 SetHoverHighlight(false); |
| 170 if (text_default_color_ && text_label_) | 182 } |
| 171 text_label_->SetEnabledColor(text_default_color_); | 183 |
| 172 SchedulePaint(); | 184 void HoverHighlightView::OnGestureEvent(ui::GestureEvent* event) { |
| 185 if (switches::IsTouchFeedbackEnabled()) { | |
| 186 if (event->type() == ui::ET_GESTURE_TAP_DOWN) { | |
| 187 SetHoverHighlight(true); | |
| 188 } else if (event->type() == ui::ET_GESTURE_TAP_CANCEL || | |
| 189 event->type() == ui::ET_GESTURE_TAP) { | |
| 190 SetHoverHighlight(false); | |
| 191 } | |
| 192 } | |
| 193 ActionableView::OnGestureEvent(event); | |
| 173 } | 194 } |
| 174 | 195 |
| 175 void HoverHighlightView::OnEnabledChanged() { | 196 void HoverHighlightView::OnEnabledChanged() { |
| 176 for (int i = 0; i < child_count(); ++i) | 197 for (int i = 0; i < child_count(); ++i) |
| 177 child_at(i)->SetEnabled(enabled()); | 198 child_at(i)->SetEnabled(enabled()); |
| 178 } | 199 } |
| 179 | 200 |
| 180 void HoverHighlightView::OnPaintBackground(gfx::Canvas* canvas) { | 201 void HoverHighlightView::OnPaintBackground(gfx::Canvas* canvas) { |
| 181 canvas->DrawColor(hover_ ? highlight_color_ : default_color_); | 202 canvas->DrawColor(hover_ ? highlight_color_ : default_color_); |
| 182 } | 203 } |
| 183 | 204 |
| 184 void HoverHighlightView::OnFocus() { | 205 void HoverHighlightView::OnFocus() { |
| 185 ScrollRectToVisible(gfx::Rect(gfx::Point(), size())); | 206 ScrollRectToVisible(gfx::Rect(gfx::Point(), size())); |
| 186 ActionableView::OnFocus(); | 207 ActionableView::OnFocus(); |
| 187 } | 208 } |
| 188 | 209 |
| 189 } // namespace ash | 210 } // namespace ash |
| OLD | NEW |