| 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" |
| 11 #include "ash/system/tray/view_click_listener.h" | 11 #include "ash/system/tray/view_click_listener.h" |
| 12 #include "ui/accessibility/ax_node_data.h" | 12 #include "ui/accessibility/ax_node_data.h" |
| 13 #include "ui/base/resource/resource_bundle.h" | |
| 14 #include "ui/gfx/canvas.h" | 13 #include "ui/gfx/canvas.h" |
| 15 #include "ui/gfx/font_list.h" | |
| 16 #include "ui/gfx/paint_vector_icon.h" | 14 #include "ui/gfx/paint_vector_icon.h" |
| 17 #include "ui/resources/grit/ui_resources.h" | 15 #include "ui/resources/grit/ui_resources.h" |
| 18 #include "ui/views/border.h" | |
| 19 #include "ui/views/controls/image_view.h" | 16 #include "ui/views/controls/image_view.h" |
| 20 #include "ui/views/controls/label.h" | 17 #include "ui/views/controls/label.h" |
| 21 #include "ui/views/layout/box_layout.h" | |
| 22 #include "ui/views/layout/fill_layout.h" | 18 #include "ui/views/layout/fill_layout.h" |
| 23 #include "ui/views/resources/grit/views_resources.h" | 19 #include "ui/views/resources/grit/views_resources.h" |
| 24 | 20 |
| 25 namespace { | |
| 26 | |
| 27 const gfx::FontList& GetFontList(bool highlight) { | |
| 28 return ui::ResourceBundle::GetSharedInstance().GetFontList( | |
| 29 highlight ? ui::ResourceBundle::BoldFont : ui::ResourceBundle::BaseFont); | |
| 30 } | |
| 31 | |
| 32 } // namespace | |
| 33 | |
| 34 namespace ash { | 21 namespace ash { |
| 35 | 22 |
| 36 HoverHighlightView::HoverHighlightView(ViewClickListener* listener) | 23 HoverHighlightView::HoverHighlightView(ViewClickListener* listener) |
| 37 : ActionableView(nullptr, TrayPopupInkDropStyle::FILL_BOUNDS), | 24 : ActionableView(nullptr, TrayPopupInkDropStyle::FILL_BOUNDS), |
| 38 listener_(listener) { | 25 listener_(listener) { |
| 39 set_notify_enter_exit_on_child(true); | 26 set_notify_enter_exit_on_child(true); |
| 40 SetInkDropMode(InkDropHostView::InkDropMode::ON); | 27 SetInkDropMode(InkDropHostView::InkDropMode::ON); |
| 41 } | 28 } |
| 42 | 29 |
| 43 HoverHighlightView::~HoverHighlightView() {} | 30 HoverHighlightView::~HoverHighlightView() {} |
| 44 | 31 |
| 45 bool HoverHighlightView::GetTooltipText(const gfx::Point& p, | |
| 46 base::string16* tooltip) const { | |
| 47 if (tooltip_.empty()) | |
| 48 return false; | |
| 49 *tooltip = tooltip_; | |
| 50 return true; | |
| 51 } | |
| 52 | |
| 53 void HoverHighlightView::AddRightIcon(const gfx::ImageSkia& image, | 32 void HoverHighlightView::AddRightIcon(const gfx::ImageSkia& image, |
| 54 int icon_size) { | 33 int icon_size) { |
| 55 DCHECK(!right_view_); | 34 DCHECK(!right_view_); |
| 56 | 35 |
| 57 views::ImageView* right_icon = TrayPopupUtils::CreateMainImageView(); | 36 views::ImageView* right_icon = TrayPopupUtils::CreateMainImageView(); |
| 58 right_icon->SetImage(image); | 37 right_icon->SetImage(image); |
| 59 AddRightView(right_icon); | 38 AddRightView(right_icon); |
| 60 } | 39 } |
| 61 | 40 |
| 62 void HoverHighlightView::AddRightView(views::View* view) { | 41 void HoverHighlightView::AddRightView(views::View* view) { |
| 63 DCHECK(!right_view_); | 42 DCHECK(!right_view_); |
| 64 | 43 |
| 65 right_view_ = view; | 44 right_view_ = view; |
| 66 right_view_->SetEnabled(enabled()); | 45 right_view_->SetEnabled(enabled()); |
| 67 tri_view_->AddView(TriView::Container::END, right_view_); | 46 tri_view_->AddView(TriView::Container::END, right_view_); |
| 68 tri_view_->SetContainerVisible(TriView::Container::END, true); | 47 tri_view_->SetContainerVisible(TriView::Container::END, true); |
| 69 } | 48 } |
| 70 | 49 |
| 71 // TODO(tdanderson): Ensure all checkable detailed view rows use this | |
| 72 // mechanism, and share the code that sets the accessible state for | |
| 73 // a checkbox. See crbug.com/652674. | |
| 74 void HoverHighlightView::SetRightViewVisible(bool visible) { | 50 void HoverHighlightView::SetRightViewVisible(bool visible) { |
| 75 if (!right_view_) | 51 if (!right_view_) |
| 76 return; | 52 return; |
| 77 | 53 |
| 78 right_view_->SetVisible(visible); | 54 right_view_->SetVisible(visible); |
| 79 Layout(); | 55 Layout(); |
| 80 } | 56 } |
| 81 | 57 |
| 82 void HoverHighlightView::AddIconAndLabel(const gfx::ImageSkia& image, | 58 void HoverHighlightView::AddIconAndLabel(const gfx::ImageSkia& image, |
| 83 const base::string16& text) { | 59 const base::string16& text) { |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 135 sub_style.set_color_style(TrayPopupItemStyle::ColorStyle::INACTIVE); | 111 sub_style.set_color_style(TrayPopupItemStyle::ColorStyle::INACTIVE); |
| 136 sub_style.SetupLabel(sub_text_label_); | 112 sub_style.SetupLabel(sub_text_label_); |
| 137 tri_view_->AddView(TriView::Container::CENTER, sub_text_label_); | 113 tri_view_->AddView(TriView::Container::CENTER, sub_text_label_); |
| 138 } | 114 } |
| 139 | 115 |
| 140 tri_view_->SetContainerVisible(TriView::Container::END, false); | 116 tri_view_->SetContainerVisible(TriView::Container::END, false); |
| 141 | 117 |
| 142 SetAccessibleName(text); | 118 SetAccessibleName(text); |
| 143 } | 119 } |
| 144 | 120 |
| 145 views::Label* HoverHighlightView::AddLabelDeprecated( | |
| 146 const base::string16& text, | |
| 147 gfx::HorizontalAlignment alignment, | |
| 148 bool highlight) { | |
| 149 box_layout_ = new views::BoxLayout(views::BoxLayout::kHorizontal, 0, 0, 0); | |
| 150 SetLayoutManager(box_layout_); | |
| 151 text_label_ = new views::Label(text); | |
| 152 int left_margin = kTrayPopupPaddingHorizontal; | |
| 153 int right_margin = kTrayPopupPaddingHorizontal; | |
| 154 if (alignment != gfx::ALIGN_CENTER) { | |
| 155 if (base::i18n::IsRTL()) | |
| 156 right_margin += kTrayPopupDetailsLabelExtraLeftMargin; | |
| 157 else | |
| 158 left_margin += kTrayPopupDetailsLabelExtraLeftMargin; | |
| 159 } | |
| 160 text_label_->SetBorder( | |
| 161 views::CreateEmptyBorder(5, left_margin, 5, right_margin)); | |
| 162 text_label_->SetHorizontalAlignment(alignment); | |
| 163 text_label_->SetFontList(GetFontList(highlight)); | |
| 164 // Do not set alpha value in disable color. It will have issue with elide | |
| 165 // blending filter in disabled state for rendering label text color. | |
| 166 text_label_->SetDisabledColor(SkColorSetARGB(255, 127, 127, 127)); | |
| 167 if (text_default_color_) | |
| 168 text_label_->SetEnabledColor(text_default_color_); | |
| 169 text_label_->SetEnabled(enabled()); | |
| 170 AddChildView(text_label_); | |
| 171 box_layout_->SetFlexForView(text_label_, 1); | |
| 172 | |
| 173 SetAccessibleName(text); | |
| 174 return text_label_; | |
| 175 } | |
| 176 | |
| 177 void HoverHighlightView::AddLabelRow(const base::string16& text) { | 121 void HoverHighlightView::AddLabelRow(const base::string16& text) { |
| 178 SetLayoutManager(new views::FillLayout); | 122 SetLayoutManager(new views::FillLayout); |
| 179 tri_view_ = TrayPopupUtils::CreateDefaultRowView(); | 123 tri_view_ = TrayPopupUtils::CreateDefaultRowView(); |
| 180 AddChildView(tri_view_); | 124 AddChildView(tri_view_); |
| 181 | 125 |
| 182 text_label_ = TrayPopupUtils::CreateDefaultLabel(); | 126 text_label_ = TrayPopupUtils::CreateDefaultLabel(); |
| 183 text_label_->SetText(text); | 127 text_label_->SetText(text); |
| 184 | 128 |
| 185 TrayPopupItemStyle style(TrayPopupItemStyle::FontStyle::DETAILED_VIEW_LABEL); | 129 TrayPopupItemStyle style(TrayPopupItemStyle::FontStyle::DETAILED_VIEW_LABEL); |
| 186 style.SetupLabel(text_label_); | 130 style.SetupLabel(text_label_); |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 223 return; // Not a checkbox | 167 return; // Not a checkbox |
| 224 | 168 |
| 225 // Checkbox | 169 // Checkbox |
| 226 node_data->role = ui::AX_ROLE_CHECK_BOX; | 170 node_data->role = ui::AX_ROLE_CHECK_BOX; |
| 227 node_data->AddIntAttribute(ui::AX_ATTR_CHECKED_STATE, checked_state); | 171 node_data->AddIntAttribute(ui::AX_ATTR_CHECKED_STATE, checked_state); |
| 228 } | 172 } |
| 229 | 173 |
| 230 gfx::Size HoverHighlightView::GetPreferredSize() const { | 174 gfx::Size HoverHighlightView::GetPreferredSize() const { |
| 231 gfx::Size size = ActionableView::GetPreferredSize(); | 175 gfx::Size size = ActionableView::GetPreferredSize(); |
| 232 | 176 |
| 233 if (custom_height_) | 177 if (!expandable_ || size.height() < kTrayPopupItemMinHeight) |
| 234 size.set_height(custom_height_); | |
| 235 else if (!expandable_ || size.height() < kTrayPopupItemMinHeight) | |
| 236 size.set_height(kTrayPopupItemMinHeight); | 178 size.set_height(kTrayPopupItemMinHeight); |
| 237 | 179 |
| 238 return size; | 180 return size; |
| 239 } | 181 } |
| 240 | 182 |
| 241 int HoverHighlightView::GetHeightForWidth(int width) const { | 183 int HoverHighlightView::GetHeightForWidth(int width) const { |
| 242 return GetPreferredSize().height(); | 184 return GetPreferredSize().height(); |
| 243 } | 185 } |
| 244 | 186 |
| 245 void HoverHighlightView::OnEnabledChanged() { | 187 void HoverHighlightView::OnEnabledChanged() { |
| 246 if (left_icon_) | 188 if (left_icon_) |
| 247 left_icon_->SetEnabled(enabled()); | 189 left_icon_->SetEnabled(enabled()); |
| 248 if (text_label_) | 190 if (text_label_) |
| 249 text_label_->SetEnabled(enabled()); | 191 text_label_->SetEnabled(enabled()); |
| 250 if (right_view_) | 192 if (right_view_) |
| 251 right_view_->SetEnabled(enabled()); | 193 right_view_->SetEnabled(enabled()); |
| 252 } | 194 } |
| 253 | 195 |
| 254 void HoverHighlightView::OnFocus() { | 196 void HoverHighlightView::OnFocus() { |
| 255 ScrollRectToVisible(gfx::Rect(gfx::Point(), size())); | 197 ScrollRectToVisible(gfx::Rect(gfx::Point(), size())); |
| 256 ActionableView::OnFocus(); | 198 ActionableView::OnFocus(); |
| 257 } | 199 } |
| 258 | 200 |
| 259 } // namespace ash | 201 } // namespace ash |
| OLD | NEW |