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/ash_switches.h" | |
| 7 #include "ash/system/tray/fixed_sized_image_view.h" | 8 #include "ash/system/tray/fixed_sized_image_view.h" |
| 8 #include "ash/system/tray/tray_constants.h" | 9 #include "ash/system/tray/tray_constants.h" |
| 9 #include "ash/system/tray/view_click_listener.h" | 10 #include "ash/system/tray/view_click_listener.h" |
| 11 #include "base/command_line.h" | |
| 10 #include "ui/accessibility/ax_view_state.h" | 12 #include "ui/accessibility/ax_view_state.h" |
| 11 #include "ui/base/resource/resource_bundle.h" | 13 #include "ui/base/resource/resource_bundle.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 { |
| 22 | 24 |
| 23 const int kCheckLabelPadding = 4; | 25 const int kCheckLabelPadding = 4; |
| 24 | 26 |
| 25 } // namespace | 27 } // namespace |
| 26 | 28 |
| 27 namespace ash { | 29 namespace ash { |
| 28 | 30 |
| 29 HoverHighlightView::HoverHighlightView(ViewClickListener* listener) | 31 HoverHighlightView::HoverHighlightView(ViewClickListener* listener) |
| 30 : listener_(listener), | 32 : listener_(listener), |
| 31 text_label_(NULL), | 33 text_label_(NULL), |
| 32 highlight_color_(kHoverBackgroundColor), | 34 highlight_color_(kHoverBackgroundColor), |
| 33 default_color_(0), | 35 default_color_(0), |
| 34 text_highlight_color_(0), | 36 text_highlight_color_(0), |
| 35 text_default_color_(0), | 37 text_default_color_(0), |
| 36 hover_(false), | 38 hover_(false), |
| 37 expandable_(false), | 39 expandable_(false), |
| 38 checkable_(false), | 40 checkable_(false), |
| 39 checked_(false) { | 41 checked_(false), |
| 42 touch_feedback_enabled_(false) { | |
| 40 set_notify_enter_exit_on_child(true); | 43 set_notify_enter_exit_on_child(true); |
| 44 if (CommandLine::ForCurrentProcess()-> | |
| 45 HasSwitch(switches::kAshEnableTouchViewTouchFeedback)) { | |
| 46 touch_feedback_enabled_ = true; | |
| 47 } | |
| 41 } | 48 } |
| 42 | 49 |
| 43 HoverHighlightView::~HoverHighlightView() { | 50 HoverHighlightView::~HoverHighlightView() { |
| 44 } | 51 } |
| 45 | 52 |
| 46 void HoverHighlightView::AddIconAndLabel(const gfx::ImageSkia& image, | 53 void HoverHighlightView::AddIconAndLabel(const gfx::ImageSkia& image, |
| 47 const base::string16& text, | 54 const base::string16& text, |
| 48 gfx::Font::FontStyle style) { | 55 gfx::Font::FontStyle style) { |
| 49 SetLayoutManager(new views::BoxLayout( | 56 SetLayoutManager(new views::BoxLayout( |
| 50 views::BoxLayout::kHorizontal, 0, 3, kTrayPopupPaddingBetweenItems)); | 57 views::BoxLayout::kHorizontal, 0, 3, kTrayPopupPaddingBetweenItems)); |
| (...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 123 return AddLabel(text, gfx::ALIGN_LEFT, style); | 130 return AddLabel(text, gfx::ALIGN_LEFT, style); |
| 124 } | 131 } |
| 125 | 132 |
| 126 void HoverHighlightView::SetExpandable(bool expandable) { | 133 void HoverHighlightView::SetExpandable(bool expandable) { |
| 127 if (expandable != expandable_) { | 134 if (expandable != expandable_) { |
| 128 expandable_ = expandable; | 135 expandable_ = expandable; |
| 129 InvalidateLayout(); | 136 InvalidateLayout(); |
| 130 } | 137 } |
| 131 } | 138 } |
| 132 | 139 |
| 140 void HoverHighlightView::SetHoverHighlight(bool hover) { | |
| 141 if (hover_ == hover) | |
| 142 return; | |
| 143 hover_ = hover; | |
| 144 if (!text_label_) | |
| 145 return; | |
| 146 if (hover_ && text_highlight_color_) | |
| 147 text_label_->SetEnabledColor(text_highlight_color_); | |
| 148 if (!hover_ && text_default_color_) | |
| 149 text_label_->SetEnabledColor(text_default_color_); | |
| 150 SchedulePaint(); | |
| 151 } | |
| 152 | |
| 133 bool HoverHighlightView::PerformAction(const ui::Event& event) { | 153 bool HoverHighlightView::PerformAction(const ui::Event& event) { |
| 134 if (!listener_) | 154 if (!listener_) |
| 135 return false; | 155 return false; |
| 136 listener_->OnViewClicked(this); | 156 listener_->OnViewClicked(this); |
| 137 return true; | 157 return true; |
| 138 } | 158 } |
| 139 | 159 |
| 140 void HoverHighlightView::GetAccessibleState(ui::AXViewState* state) { | 160 void HoverHighlightView::GetAccessibleState(ui::AXViewState* state) { |
| 141 ActionableView::GetAccessibleState(state); | 161 ActionableView::GetAccessibleState(state); |
| 142 | 162 |
| 143 if (checkable_) { | 163 if (checkable_) { |
| 144 state->role = ui::AX_ROLE_CHECK_BOX; | 164 state->role = ui::AX_ROLE_CHECK_BOX; |
| 145 if (checked_) | 165 if (checked_) |
| 146 state->AddStateFlag(ui::AX_STATE_CHECKED); | 166 state->AddStateFlag(ui::AX_STATE_CHECKED); |
| 147 } | 167 } |
| 148 } | 168 } |
| 149 | 169 |
| 150 gfx::Size HoverHighlightView::GetPreferredSize() const { | 170 gfx::Size HoverHighlightView::GetPreferredSize() const { |
| 151 gfx::Size size = ActionableView::GetPreferredSize(); | 171 gfx::Size size = ActionableView::GetPreferredSize(); |
| 152 if (!expandable_ || size.height() < kTrayPopupItemHeight) | 172 if (!expandable_ || size.height() < kTrayPopupItemHeight) |
| 153 size.set_height(kTrayPopupItemHeight); | 173 size.set_height(kTrayPopupItemHeight); |
| 154 return size; | 174 return size; |
| 155 } | 175 } |
| 156 | 176 |
| 157 int HoverHighlightView::GetHeightForWidth(int width) const { | 177 int HoverHighlightView::GetHeightForWidth(int width) const { |
| 158 return GetPreferredSize().height(); | 178 return GetPreferredSize().height(); |
| 159 } | 179 } |
| 160 | 180 |
| 161 void HoverHighlightView::OnMouseEntered(const ui::MouseEvent& event) { | 181 void HoverHighlightView::OnMouseEntered(const ui::MouseEvent& event) { |
| 162 hover_ = true; | 182 SetHoverHighlight(true); |
| 163 if (text_highlight_color_ && text_label_) | |
| 164 text_label_->SetEnabledColor(text_highlight_color_); | |
| 165 SchedulePaint(); | |
| 166 } | 183 } |
| 167 | 184 |
| 168 void HoverHighlightView::OnMouseExited(const ui::MouseEvent& event) { | 185 void HoverHighlightView::OnMouseExited(const ui::MouseEvent& event) { |
| 169 hover_ = false; | 186 SetHoverHighlight(false); |
| 170 if (text_default_color_ && text_label_) | 187 } |
| 171 text_label_->SetEnabledColor(text_default_color_); | 188 |
| 172 SchedulePaint(); | 189 void HoverHighlightView::OnGestureEvent(ui::GestureEvent* event) { |
| 190 if (touch_feedback_enabled_) { | |
| 191 if (event->type() == ui::ET_GESTURE_TAP_DOWN) { | |
| 192 SetHoverHighlight(true); | |
| 193 } else if (event->type() == ui::ET_GESTURE_SCROLL_BEGIN || | |
|
flackr
2014/09/10 22:54:31
SCROLL_BEGIN shouldn't be necessary, should get a
jonross
2014/09/11 15:53:22
Done.
| |
| 194 event->type() == ui::ET_GESTURE_TAP_CANCEL || | |
| 195 event->type() == ui::ET_GESTURE_END) { | |
| 196 SetHoverHighlight(false); | |
| 197 } | |
| 198 } | |
| 199 ActionableView::OnGestureEvent(event); | |
| 173 } | 200 } |
| 174 | 201 |
| 175 void HoverHighlightView::OnEnabledChanged() { | 202 void HoverHighlightView::OnEnabledChanged() { |
| 176 for (int i = 0; i < child_count(); ++i) | 203 for (int i = 0; i < child_count(); ++i) |
| 177 child_at(i)->SetEnabled(enabled()); | 204 child_at(i)->SetEnabled(enabled()); |
| 178 } | 205 } |
| 179 | 206 |
| 180 void HoverHighlightView::OnPaintBackground(gfx::Canvas* canvas) { | 207 void HoverHighlightView::OnPaintBackground(gfx::Canvas* canvas) { |
| 181 canvas->DrawColor(hover_ ? highlight_color_ : default_color_); | 208 canvas->DrawColor(hover_ ? highlight_color_ : default_color_); |
| 182 } | 209 } |
| 183 | 210 |
| 184 void HoverHighlightView::OnFocus() { | 211 void HoverHighlightView::OnFocus() { |
| 185 ScrollRectToVisible(gfx::Rect(gfx::Point(), size())); | 212 ScrollRectToVisible(gfx::Rect(gfx::Point(), size())); |
| 186 ActionableView::OnFocus(); | 213 ActionableView::OnFocus(); |
| 187 } | 214 } |
| 188 | 215 |
| 189 } // namespace ash | 216 } // namespace ash |
| OLD | NEW |