| 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/resources/vector_icons/vector_icons.h" | 7 #include "ash/resources/vector_icons/vector_icons.h" |
| 8 #include "ash/system/tray/tray_constants.h" | 8 #include "ash/system/tray/tray_constants.h" |
| 9 #include "ash/system/tray/tray_popup_utils.h" | 9 #include "ash/system/tray/tray_popup_utils.h" |
| 10 #include "ash/system/tray/tri_view.h" | 10 #include "ash/system/tray/tri_view.h" |
| (...skipping 13 matching lines...) Expand all Loading... |
| 24 : ActionableView(nullptr, TrayPopupInkDropStyle::FILL_BOUNDS), | 24 : ActionableView(nullptr, TrayPopupInkDropStyle::FILL_BOUNDS), |
| 25 listener_(listener) { | 25 listener_(listener) { |
| 26 set_notify_enter_exit_on_child(true); | 26 set_notify_enter_exit_on_child(true); |
| 27 SetInkDropMode(InkDropHostView::InkDropMode::ON); | 27 SetInkDropMode(InkDropHostView::InkDropMode::ON); |
| 28 } | 28 } |
| 29 | 29 |
| 30 HoverHighlightView::~HoverHighlightView() {} | 30 HoverHighlightView::~HoverHighlightView() {} |
| 31 | 31 |
| 32 void HoverHighlightView::AddRightIcon(const gfx::ImageSkia& image, | 32 void HoverHighlightView::AddRightIcon(const gfx::ImageSkia& image, |
| 33 int icon_size) { | 33 int icon_size) { |
| 34 DCHECK(is_populated_); |
| 34 DCHECK(!right_view_); | 35 DCHECK(!right_view_); |
| 35 | 36 |
| 36 views::ImageView* right_icon = TrayPopupUtils::CreateMainImageView(); | 37 views::ImageView* right_icon = TrayPopupUtils::CreateMainImageView(); |
| 37 right_icon->SetImage(image); | 38 right_icon->SetImage(image); |
| 38 AddRightView(right_icon); | 39 AddRightView(right_icon); |
| 39 } | 40 } |
| 40 | 41 |
| 41 void HoverHighlightView::AddRightView(views::View* view) { | 42 void HoverHighlightView::AddRightView(views::View* view) { |
| 43 DCHECK(is_populated_); |
| 42 DCHECK(!right_view_); | 44 DCHECK(!right_view_); |
| 43 | 45 |
| 44 right_view_ = view; | 46 right_view_ = view; |
| 45 right_view_->SetEnabled(enabled()); | 47 right_view_->SetEnabled(enabled()); |
| 46 tri_view_->AddView(TriView::Container::END, right_view_); | 48 tri_view_->AddView(TriView::Container::END, right_view_); |
| 47 tri_view_->SetContainerVisible(TriView::Container::END, true); | 49 tri_view_->SetContainerVisible(TriView::Container::END, true); |
| 48 } | 50 } |
| 49 | 51 |
| 50 void HoverHighlightView::SetRightViewVisible(bool visible) { | 52 void HoverHighlightView::SetRightViewVisible(bool visible) { |
| 53 DCHECK(is_populated_); |
| 51 if (!right_view_) | 54 if (!right_view_) |
| 52 return; | 55 return; |
| 53 | 56 |
| 54 right_view_->SetVisible(visible); | 57 right_view_->SetVisible(visible); |
| 55 Layout(); | 58 Layout(); |
| 56 } | 59 } |
| 57 | 60 |
| 58 void HoverHighlightView::SetSubText(const base::string16& sub_text) { | 61 void HoverHighlightView::SetSubText(const base::string16& sub_text) { |
| 62 DCHECK(is_populated_); |
| 59 DCHECK(text_label_); | 63 DCHECK(text_label_); |
| 60 DCHECK(!sub_text.empty()); | 64 DCHECK(!sub_text.empty()); |
| 61 | 65 |
| 62 if (!sub_text_label_) { | 66 if (!sub_text_label_) { |
| 63 sub_text_label_ = TrayPopupUtils::CreateDefaultLabel(); | 67 sub_text_label_ = TrayPopupUtils::CreateDefaultLabel(); |
| 64 tri_view_->AddView(TriView::Container::CENTER, sub_text_label_); | 68 tri_view_->AddView(TriView::Container::CENTER, sub_text_label_); |
| 65 } | 69 } |
| 66 | 70 |
| 67 TrayPopupItemStyle sub_style(TrayPopupItemStyle::FontStyle::CAPTION); | 71 TrayPopupItemStyle sub_style(TrayPopupItemStyle::FontStyle::CAPTION); |
| 68 sub_style.set_color_style(TrayPopupItemStyle::ColorStyle::INACTIVE); | 72 sub_style.set_color_style(TrayPopupItemStyle::ColorStyle::INACTIVE); |
| (...skipping 27 matching lines...) Expand all Loading... |
| 96 const base::string16& text, | 100 const base::string16& text, |
| 97 TrayPopupItemStyle::FontStyle font_style) { | 101 TrayPopupItemStyle::FontStyle font_style) { |
| 98 DoAddIconAndLabels(image, text, font_style, base::string16()); | 102 DoAddIconAndLabels(image, text, font_style, base::string16()); |
| 99 } | 103 } |
| 100 | 104 |
| 101 void HoverHighlightView::DoAddIconAndLabels( | 105 void HoverHighlightView::DoAddIconAndLabels( |
| 102 const gfx::ImageSkia& image, | 106 const gfx::ImageSkia& image, |
| 103 const base::string16& text, | 107 const base::string16& text, |
| 104 TrayPopupItemStyle::FontStyle font_style, | 108 TrayPopupItemStyle::FontStyle font_style, |
| 105 const base::string16& sub_text) { | 109 const base::string16& sub_text) { |
| 110 DCHECK(!is_populated_); |
| 111 is_populated_ = true; |
| 112 |
| 106 SetLayoutManager(new views::FillLayout); | 113 SetLayoutManager(new views::FillLayout); |
| 107 tri_view_ = TrayPopupUtils::CreateDefaultRowView(); | 114 tri_view_ = TrayPopupUtils::CreateDefaultRowView(); |
| 108 AddChildView(tri_view_); | 115 AddChildView(tri_view_); |
| 109 | 116 |
| 110 left_icon_ = TrayPopupUtils::CreateMainImageView(); | 117 left_icon_ = TrayPopupUtils::CreateMainImageView(); |
| 111 left_icon_->SetImage(image); | 118 left_icon_->SetImage(image); |
| 112 left_icon_->SetEnabled(enabled()); | 119 left_icon_->SetEnabled(enabled()); |
| 113 tri_view_->AddView(TriView::Container::START, left_icon_); | 120 tri_view_->AddView(TriView::Container::START, left_icon_); |
| 114 | 121 |
| 115 text_label_ = TrayPopupUtils::CreateDefaultLabel(); | 122 text_label_ = TrayPopupUtils::CreateDefaultLabel(); |
| 116 text_label_->SetText(text); | 123 text_label_->SetText(text); |
| 117 text_label_->SetEnabled(enabled()); | 124 text_label_->SetEnabled(enabled()); |
| 118 TrayPopupItemStyle style(font_style); | 125 TrayPopupItemStyle style(font_style); |
| 119 style.SetupLabel(text_label_); | 126 style.SetupLabel(text_label_); |
| 120 tri_view_->AddView(TriView::Container::CENTER, text_label_); | 127 tri_view_->AddView(TriView::Container::CENTER, text_label_); |
| 121 | 128 |
| 122 if (!sub_text.empty()) | 129 if (!sub_text.empty()) |
| 123 SetSubText(sub_text); | 130 SetSubText(sub_text); |
| 124 | 131 |
| 125 tri_view_->SetContainerVisible(TriView::Container::END, false); | 132 tri_view_->SetContainerVisible(TriView::Container::END, false); |
| 126 | 133 |
| 127 SetAccessibleName(text); | 134 SetAccessibleName(text); |
| 128 } | 135 } |
| 129 | 136 |
| 130 void HoverHighlightView::AddLabelRow(const base::string16& text) { | 137 void HoverHighlightView::AddLabelRow(const base::string16& text) { |
| 138 DCHECK(!is_populated_); |
| 139 is_populated_ = true; |
| 140 |
| 131 SetLayoutManager(new views::FillLayout); | 141 SetLayoutManager(new views::FillLayout); |
| 132 tri_view_ = TrayPopupUtils::CreateDefaultRowView(); | 142 tri_view_ = TrayPopupUtils::CreateDefaultRowView(); |
| 133 AddChildView(tri_view_); | 143 AddChildView(tri_view_); |
| 134 | 144 |
| 135 text_label_ = TrayPopupUtils::CreateDefaultLabel(); | 145 text_label_ = TrayPopupUtils::CreateDefaultLabel(); |
| 136 text_label_->SetText(text); | 146 text_label_->SetText(text); |
| 137 | 147 |
| 138 TrayPopupItemStyle style(TrayPopupItemStyle::FontStyle::DETAILED_VIEW_LABEL); | 148 TrayPopupItemStyle style(TrayPopupItemStyle::FontStyle::DETAILED_VIEW_LABEL); |
| 139 style.SetupLabel(text_label_); | 149 style.SetupLabel(text_label_); |
| 140 tri_view_->AddView(TriView::Container::CENTER, text_label_); | 150 tri_view_->AddView(TriView::Container::CENTER, text_label_); |
| 141 | 151 |
| 142 SetAccessibleName(text); | 152 SetAccessibleName(text); |
| 143 } | 153 } |
| 144 | 154 |
| 145 void HoverHighlightView::SetExpandable(bool expandable) { | 155 void HoverHighlightView::SetExpandable(bool expandable) { |
| 146 if (expandable != expandable_) { | 156 if (expandable != expandable_) { |
| 147 expandable_ = expandable; | 157 expandable_ = expandable; |
| 148 InvalidateLayout(); | 158 InvalidateLayout(); |
| 149 } | 159 } |
| 150 } | 160 } |
| 151 | 161 |
| 152 void HoverHighlightView::SetAccessiblityState( | 162 void HoverHighlightView::SetAccessiblityState( |
| 153 AccessibilityState accessibility_state) { | 163 AccessibilityState accessibility_state) { |
| 154 accessibility_state_ = accessibility_state; | 164 accessibility_state_ = accessibility_state; |
| 155 if (accessibility_state_ != AccessibilityState::DEFAULT) | 165 if (accessibility_state_ != AccessibilityState::DEFAULT) |
| 156 NotifyAccessibilityEvent(ui::AX_EVENT_CHECKED_STATE_CHANGED, true); | 166 NotifyAccessibilityEvent(ui::AX_EVENT_CHECKED_STATE_CHANGED, true); |
| 157 } | 167 } |
| 158 | 168 |
| 169 void HoverHighlightView::Reset() { |
| 170 RemoveAllChildViews(true); |
| 171 text_label_ = nullptr; |
| 172 sub_text_label_ = nullptr; |
| 173 left_icon_ = nullptr; |
| 174 right_view_ = nullptr; |
| 175 tri_view_ = nullptr; |
| 176 is_populated_ = false; |
| 177 } |
| 178 |
| 159 bool HoverHighlightView::PerformAction(const ui::Event& event) { | 179 bool HoverHighlightView::PerformAction(const ui::Event& event) { |
| 160 if (!listener_) | 180 if (!listener_) |
| 161 return false; | 181 return false; |
| 162 listener_->OnViewClicked(this); | 182 listener_->OnViewClicked(this); |
| 163 return true; | 183 return true; |
| 164 } | 184 } |
| 165 | 185 |
| 166 void HoverHighlightView::GetAccessibleNodeData(ui::AXNodeData* node_data) { | 186 void HoverHighlightView::GetAccessibleNodeData(ui::AXNodeData* node_data) { |
| 167 ActionableView::GetAccessibleNodeData(node_data); | 187 ActionableView::GetAccessibleNodeData(node_data); |
| 168 | 188 |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 201 if (right_view_) | 221 if (right_view_) |
| 202 right_view_->SetEnabled(enabled()); | 222 right_view_->SetEnabled(enabled()); |
| 203 } | 223 } |
| 204 | 224 |
| 205 void HoverHighlightView::OnFocus() { | 225 void HoverHighlightView::OnFocus() { |
| 206 ScrollRectToVisible(gfx::Rect(gfx::Point(), size())); | 226 ScrollRectToVisible(gfx::Rect(gfx::Point(), size())); |
| 207 ActionableView::OnFocus(); | 227 ActionableView::OnFocus(); |
| 208 } | 228 } |
| 209 | 229 |
| 210 } // namespace ash | 230 } // namespace ash |
| OLD | NEW |