| OLD | NEW |
| 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2013 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/common/system/tray/special_popup_row.h" | 5 #include "ash/common/system/tray/special_popup_row.h" |
| 6 | 6 |
| 7 #include "ash/common/ash_constants.h" | 7 #include "ash/common/ash_constants.h" |
| 8 #include "ash/common/material_design/material_design_controller.h" | 8 #include "ash/common/material_design/material_design_controller.h" |
| 9 #include "ash/common/system/tray/hover_highlight_view.h" | 9 #include "ash/common/system/tray/hover_highlight_view.h" |
| 10 #include "ash/common/system/tray/system_menu_button.h" | |
| 11 #include "ash/common/system/tray/throbber_view.h" | 10 #include "ash/common/system/tray/throbber_view.h" |
| 12 #include "ash/common/system/tray/tray_constants.h" | 11 #include "ash/common/system/tray/tray_constants.h" |
| 13 #include "ash/common/system/tray/tray_popup_header_button.h" | 12 #include "ash/common/system/tray/tray_popup_header_button.h" |
| 14 #include "ash/common/system/tray/tray_popup_item_style.h" | |
| 15 #include "ash/common/system/tray/tray_popup_utils.h" | |
| 16 #include "ash/resources/vector_icons/vector_icons.h" | |
| 17 #include "grit/ash_resources.h" | 13 #include "grit/ash_resources.h" |
| 18 #include "grit/ash_strings.h" | 14 #include "grit/ash_strings.h" |
| 19 #include "ui/base/resource/resource_bundle.h" | 15 #include "ui/base/resource/resource_bundle.h" |
| 20 #include "ui/gfx/canvas.h" | 16 #include "ui/gfx/canvas.h" |
| 21 #include "ui/gfx/geometry/insets.h" | 17 #include "ui/gfx/geometry/insets.h" |
| 22 #include "ui/gfx/geometry/rect.h" | 18 #include "ui/gfx/geometry/rect.h" |
| 23 #include "ui/gfx/paint_vector_icon.h" | |
| 24 #include "ui/views/background.h" | 19 #include "ui/views/background.h" |
| 25 #include "ui/views/border.h" | 20 #include "ui/views/border.h" |
| 26 #include "ui/views/controls/button/custom_button.h" | 21 #include "ui/views/controls/button/custom_button.h" |
| 27 #include "ui/views/controls/button/image_button.h" | 22 #include "ui/views/controls/button/image_button.h" |
| 28 #include "ui/views/controls/button/toggle_button.h" | |
| 29 #include "ui/views/controls/label.h" | 23 #include "ui/views/controls/label.h" |
| 30 #include "ui/views/controls/separator.h" | 24 #include "ui/views/controls/separator.h" |
| 31 #include "ui/views/layout/box_layout.h" | 25 #include "ui/views/layout/box_layout.h" |
| 32 #include "ui/views/painter.h" | 26 #include "ui/views/painter.h" |
| 33 | 27 |
| 34 namespace ash { | 28 namespace ash { |
| 35 namespace { | 29 namespace { |
| 36 | 30 |
| 37 const int kIconPaddingLeft = 5; | 31 const int kIconPaddingLeft = 5; |
| 38 const int kSeparatorInset = 10; | 32 const int kSeparatorInset = 10; |
| 39 const int kSpecialPopupRowHeight = 55; | 33 const int kSpecialPopupRowHeight = 55; |
| 40 const int kSpecialPopupRowHeightMd = 48; | |
| 41 const int kBorderHeight = 1; | 34 const int kBorderHeight = 1; |
| 42 const SkColor kBorderColor = SkColorSetRGB(0xaa, 0xaa, 0xaa); | 35 const SkColor kBorderColor = SkColorSetRGB(0xaa, 0xaa, 0xaa); |
| 43 | 36 |
| 44 views::View* CreateViewContainer() { | 37 views::View* CreateViewContainer() { |
| 45 views::View* view = new views::View; | 38 views::View* view = new views::View; |
| 46 if (MaterialDesignController::IsSystemTrayMenuMaterial()) { | 39 view->SetLayoutManager( |
| 47 views::BoxLayout* box_layout = | 40 new views::BoxLayout(views::BoxLayout::kHorizontal, 0, 0, 0)); |
| 48 new views::BoxLayout(views::BoxLayout::kHorizontal, 4, 0, 0); | 41 view->SetBorder(views::CreateEmptyBorder(4, 0, 4, 5)); |
| 49 box_layout->set_main_axis_alignment( | |
| 50 views::BoxLayout::MAIN_AXIS_ALIGNMENT_START); | |
| 51 box_layout->set_cross_axis_alignment( | |
| 52 views::BoxLayout::CROSS_AXIS_ALIGNMENT_CENTER); | |
| 53 view->SetLayoutManager(box_layout); | |
| 54 } else { | |
| 55 view->SetLayoutManager( | |
| 56 new views::BoxLayout(views::BoxLayout::kHorizontal, 0, 0, 0)); | |
| 57 view->SetBorder(views::CreateEmptyBorder(4, 0, 4, 5)); | |
| 58 } | |
| 59 | |
| 60 return view; | 42 return view; |
| 61 } | 43 } |
| 62 | 44 |
| 63 } // namespace | 45 } // namespace |
| 64 | 46 |
| 65 SpecialPopupRow::SpecialPopupRow() | 47 SpecialPopupRow::SpecialPopupRow() |
| 66 : views_before_content_container_(nullptr), | 48 : content_(nullptr), views_after_content_container_(nullptr) { |
| 67 content_(nullptr), | 49 DCHECK(!MaterialDesignController::IsSystemTrayMenuMaterial()); |
| 68 views_after_content_container_(nullptr), | 50 set_background( |
| 69 label_(nullptr) { | 51 views::Background::CreateSolidBackground(kHeaderBackgroundColor)); |
| 70 if (MaterialDesignController::IsSystemTrayMenuMaterial()) { | 52 SetBorder( |
| 71 SetBorder( | 53 views::CreateSolidSidedBorder(kBorderHeight, 0, 0, 0, kBorderColor)); |
| 72 views::CreateSolidSidedBorder(0, 0, kBorderHeight, 0, kBorderColor)); | |
| 73 } else { | |
| 74 set_background( | |
| 75 views::Background::CreateSolidBackground(kHeaderBackgroundColor)); | |
| 76 SetBorder( | |
| 77 views::CreateSolidSidedBorder(kBorderHeight, 0, 0, 0, kBorderColor)); | |
| 78 } | |
| 79 } | 54 } |
| 80 | 55 |
| 81 SpecialPopupRow::~SpecialPopupRow() {} | 56 SpecialPopupRow::~SpecialPopupRow() {} |
| 82 | 57 |
| 83 void SpecialPopupRow::SetTextLabel(int string_id, ViewClickListener* listener) { | 58 void SpecialPopupRow::SetTextLabel(int string_id, ViewClickListener* listener) { |
| 84 if (MaterialDesignController::IsSystemTrayMenuMaterial()) | 59 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); |
| 85 SetTextLabelMd(string_id, listener); | 60 HoverHighlightView* container = new HoverHighlightView(listener); |
| 86 else | 61 container->SetLayoutManager(new views::BoxLayout( |
| 87 SetTextLabelNonMd(string_id, listener); | 62 views::BoxLayout::kHorizontal, 0, 3, kIconPaddingLeft)); |
| 63 |
| 64 container->set_highlight_color(SkColorSetARGB(0, 0, 0, 0)); |
| 65 container->set_default_color(SkColorSetARGB(0, 0, 0, 0)); |
| 66 container->set_text_highlight_color(kHeaderTextColorHover); |
| 67 container->set_text_default_color(kHeaderTextColorNormal); |
| 68 |
| 69 container->AddIconAndLabel( |
| 70 *rb.GetImageNamed(IDR_AURA_UBER_TRAY_LESS).ToImageSkia(), |
| 71 rb.GetLocalizedString(string_id), true /* highlight */); |
| 72 |
| 73 container->SetBorder( |
| 74 views::CreateEmptyBorder(0, kTrayPopupPaddingHorizontal, 0, 0)); |
| 75 |
| 76 container->SetAccessibleName( |
| 77 rb.GetLocalizedString(IDS_ASH_STATUS_TRAY_PREVIOUS_MENU)); |
| 78 SetContent(container); |
| 88 } | 79 } |
| 89 | 80 |
| 90 void SpecialPopupRow::SetContent(views::View* view) { | 81 void SpecialPopupRow::SetContent(views::View* view) { |
| 91 CHECK(!content_); | 82 CHECK(!content_); |
| 92 views::BoxLayout* box_layout = | 83 views::BoxLayout* box_layout = |
| 93 new views::BoxLayout(views::BoxLayout::kHorizontal, 0, 0, 0); | 84 new views::BoxLayout(views::BoxLayout::kHorizontal, 0, 0, 0); |
| 94 SetLayoutManager(box_layout); | 85 SetLayoutManager(box_layout); |
| 95 content_ = view; | 86 content_ = view; |
| 96 // TODO(tdanderson): Consider moving this logic to a BoxLayout subclass. | 87 AddChildViewAt(content_, 0); |
| 97 AddChildViewAt(content_, views_before_content_container_ ? 1 : 0); | |
| 98 if (MaterialDesignController::IsSystemTrayMenuMaterial()) | |
| 99 box_layout->SetFlexForView(content_, 1); | |
| 100 } | |
| 101 | |
| 102 views::Button* SpecialPopupRow::AddBackButton(views::ButtonListener* listener) { | |
| 103 SystemMenuButton* button = new SystemMenuButton( | |
| 104 listener, SystemMenuButton::InkDropStyle::SQUARE, | |
| 105 kSystemMenuArrowBackIcon, IDS_ASH_STATUS_TRAY_PREVIOUS_MENU); | |
| 106 AddViewBeforeContent(button); | |
| 107 return button; | |
| 108 } | |
| 109 | |
| 110 views::CustomButton* SpecialPopupRow::AddSettingsButton( | |
| 111 views::ButtonListener* listener, | |
| 112 LoginStatus status) { | |
| 113 SystemMenuButton* button = new SystemMenuButton( | |
| 114 listener, SystemMenuButton::InkDropStyle::SQUARE, kSystemMenuSettingsIcon, | |
| 115 IDS_ASH_STATUS_TRAY_SETTINGS); | |
| 116 if (!TrayPopupUtils::CanOpenWebUISettings(status)) | |
| 117 button->SetState(views::Button::STATE_DISABLED); | |
| 118 AddViewAfterContent(button); | |
| 119 return button; | |
| 120 } | |
| 121 | |
| 122 views::CustomButton* SpecialPopupRow::AddHelpButton( | |
| 123 views::ButtonListener* listener, | |
| 124 LoginStatus status) { | |
| 125 SystemMenuButton* button = | |
| 126 new SystemMenuButton(listener, SystemMenuButton::InkDropStyle::SQUARE, | |
| 127 kSystemMenuHelpIcon, IDS_ASH_STATUS_TRAY_HELP); | |
| 128 if (!TrayPopupUtils::CanOpenWebUISettings(status)) | |
| 129 button->SetState(views::Button::STATE_DISABLED); | |
| 130 AddViewAfterContent(button); | |
| 131 return button; | |
| 132 } | |
| 133 | |
| 134 views::ToggleButton* SpecialPopupRow::AddToggleButton( | |
| 135 views::ButtonListener* listener) { | |
| 136 // TODO(tdanderson): Define the focus rect for ToggleButton. | |
| 137 views::ToggleButton* toggle = new views::ToggleButton(listener); | |
| 138 toggle->SetFocusForPlatform(); | |
| 139 | |
| 140 views::View* container = new views::View; | |
| 141 views::BoxLayout* layout = | |
| 142 new views::BoxLayout(views::BoxLayout::kVertical, 0, 0, 0); | |
| 143 layout->set_main_axis_alignment(views::BoxLayout::MAIN_AXIS_ALIGNMENT_CENTER); | |
| 144 layout->set_cross_axis_alignment( | |
| 145 views::BoxLayout::CROSS_AXIS_ALIGNMENT_CENTER); | |
| 146 container->SetLayoutManager(layout); | |
| 147 | |
| 148 container->AddChildView(toggle); | |
| 149 AddViewAfterContent(container); | |
| 150 | |
| 151 return toggle; | |
| 152 } | 88 } |
| 153 | 89 |
| 154 void SpecialPopupRow::AddViewToTitleRow(views::View* view) { | 90 void SpecialPopupRow::AddViewToTitleRow(views::View* view) { |
| 155 AddViewAfterContent(view); | 91 AddViewAfterContent(view); |
| 156 } | 92 } |
| 157 | 93 |
| 158 void SpecialPopupRow::AddViewToRowNonMd(views::View* view, bool add_separator) { | 94 void SpecialPopupRow::AddViewToRowNonMd(views::View* view, bool add_separator) { |
| 159 AddViewAfterContent(view, add_separator); | 95 AddViewAfterContent(view, add_separator); |
| 160 } | 96 } |
| 161 | 97 |
| 162 gfx::Size SpecialPopupRow::GetPreferredSize() const { | 98 gfx::Size SpecialPopupRow::GetPreferredSize() const { |
| 163 gfx::Size size = views::View::GetPreferredSize(); | 99 gfx::Size size = views::View::GetPreferredSize(); |
| 164 size.set_height(MaterialDesignController::IsSystemTrayMenuMaterial() | 100 size.set_height(kSpecialPopupRowHeight); |
| 165 ? kSpecialPopupRowHeightMd + GetInsets().height() | |
| 166 : kSpecialPopupRowHeight); | |
| 167 return size; | 101 return size; |
| 168 } | 102 } |
| 169 | 103 |
| 170 int SpecialPopupRow::GetHeightForWidth(int width) const { | 104 int SpecialPopupRow::GetHeightForWidth(int width) const { |
| 171 return MaterialDesignController::IsSystemTrayMenuMaterial() | 105 return kSpecialPopupRowHeight; |
| 172 ? kSpecialPopupRowHeightMd + GetInsets().height() | |
| 173 : kSpecialPopupRowHeight; | |
| 174 } | 106 } |
| 175 | 107 |
| 176 void SpecialPopupRow::Layout() { | 108 void SpecialPopupRow::Layout() { |
| 177 views::View::Layout(); | 109 views::View::Layout(); |
| 178 | 110 |
| 179 if (MaterialDesignController::IsSystemTrayMenuMaterial()) | |
| 180 return; | |
| 181 | |
| 182 const gfx::Rect content_bounds = GetContentsBounds(); | 111 const gfx::Rect content_bounds = GetContentsBounds(); |
| 183 if (content_bounds.IsEmpty()) | 112 if (content_bounds.IsEmpty()) |
| 184 return; | 113 return; |
| 185 | 114 |
| 186 if (!views_after_content_container_) { | 115 if (!views_after_content_container_) { |
| 187 content_->SetBoundsRect(GetContentsBounds()); | 116 content_->SetBoundsRect(GetContentsBounds()); |
| 188 return; | 117 return; |
| 189 } | 118 } |
| 190 | 119 |
| 191 gfx::Rect bounds(views_after_content_container_->GetPreferredSize()); | 120 gfx::Rect bounds(views_after_content_container_->GetPreferredSize()); |
| 192 bounds.set_height(content_bounds.height()); | 121 bounds.set_height(content_bounds.height()); |
| 193 | 122 |
| 194 gfx::Rect container_bounds = content_bounds; | 123 gfx::Rect container_bounds = content_bounds; |
| 195 container_bounds.ClampToCenteredSize(bounds.size()); | 124 container_bounds.ClampToCenteredSize(bounds.size()); |
| 196 container_bounds.set_x(content_bounds.width() - container_bounds.width()); | 125 container_bounds.set_x(content_bounds.width() - container_bounds.width()); |
| 197 views_after_content_container_->SetBoundsRect(container_bounds); | 126 views_after_content_container_->SetBoundsRect(container_bounds); |
| 198 | 127 |
| 199 bounds = content_->bounds(); | 128 bounds = content_->bounds(); |
| 200 bounds.set_width(views_after_content_container_->x()); | 129 bounds.set_width(views_after_content_container_->x()); |
| 201 content_->SetBoundsRect(bounds); | 130 content_->SetBoundsRect(bounds); |
| 202 } | 131 } |
| 203 | 132 |
| 204 void SpecialPopupRow::OnNativeThemeChanged(const ui::NativeTheme* theme) { | |
| 205 views::View::OnNativeThemeChanged(theme); | |
| 206 UpdateStyle(); | |
| 207 } | |
| 208 | |
| 209 void SpecialPopupRow::UpdateStyle() { | |
| 210 if (!MaterialDesignController::IsSystemTrayMenuMaterial() || !label_) | |
| 211 return; | |
| 212 | |
| 213 // TODO(tdanderson|bruthig): Consider changing the SpecialPopupRow | |
| 214 // constructor to accept information about the row's style (e.g., | |
| 215 // FontStyle, variations in padding values, etc). | |
| 216 TrayPopupItemStyle style(GetNativeTheme(), | |
| 217 TrayPopupItemStyle::FontStyle::TITLE); | |
| 218 style.SetupLabel(label_); | |
| 219 } | |
| 220 | |
| 221 void SpecialPopupRow::AddViewBeforeContent(views::View* view) { | |
| 222 if (!views_before_content_container_) { | |
| 223 views_before_content_container_ = CreateViewContainer(); | |
| 224 AddChildViewAt(views_before_content_container_, 0); | |
| 225 } | |
| 226 views_before_content_container_->AddChildView(view); | |
| 227 } | |
| 228 | |
| 229 void SpecialPopupRow::AddViewAfterContent(views::View* view) { | 133 void SpecialPopupRow::AddViewAfterContent(views::View* view) { |
| 230 AddViewAfterContent(view, false); | 134 AddViewAfterContent(view, false); |
| 231 } | 135 } |
| 232 | 136 |
| 233 void SpecialPopupRow::AddViewAfterContent(views::View* view, | 137 void SpecialPopupRow::AddViewAfterContent(views::View* view, |
| 234 bool add_separator) { | 138 bool add_separator) { |
| 235 if (!views_after_content_container_) { | 139 if (!views_after_content_container_) { |
| 236 views_after_content_container_ = CreateViewContainer(); | 140 views_after_content_container_ = CreateViewContainer(); |
| 237 AddChildView(views_after_content_container_); | 141 AddChildView(views_after_content_container_); |
| 238 } | 142 } |
| 239 | 143 |
| 240 if (add_separator) { | 144 if (add_separator) { |
| 241 views::Separator* separator = | 145 views::Separator* separator = |
| 242 new views::Separator(views::Separator::VERTICAL); | 146 new views::Separator(views::Separator::VERTICAL); |
| 243 separator->SetColor(ash::kBorderDarkColor); | 147 separator->SetColor(ash::kBorderDarkColor); |
| 244 separator->SetBorder( | 148 separator->SetBorder( |
| 245 views::CreateEmptyBorder(kSeparatorInset, 0, kSeparatorInset, 0)); | 149 views::CreateEmptyBorder(kSeparatorInset, 0, kSeparatorInset, 0)); |
| 246 views_after_content_container_->AddChildView(separator); | 150 views_after_content_container_->AddChildView(separator); |
| 247 } | 151 } |
| 248 | 152 |
| 249 views_after_content_container_->AddChildView(view); | 153 views_after_content_container_->AddChildView(view); |
| 250 } | 154 } |
| 251 | 155 |
| 252 void SpecialPopupRow::SetTextLabelMd(int string_id, | |
| 253 ViewClickListener* listener) { | |
| 254 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); | |
| 255 views::View* container = new views::View; | |
| 256 | |
| 257 views::BoxLayout* box_layout = | |
| 258 new views::BoxLayout(views::BoxLayout::kVertical, 4, 4, 0); | |
| 259 box_layout->set_main_axis_alignment( | |
| 260 views::BoxLayout::MAIN_AXIS_ALIGNMENT_CENTER); | |
| 261 box_layout->set_cross_axis_alignment( | |
| 262 views::BoxLayout::CROSS_AXIS_ALIGNMENT_START); | |
| 263 container->SetLayoutManager(box_layout); | |
| 264 | |
| 265 label_ = new views::Label(rb.GetLocalizedString(string_id)); | |
| 266 container->AddChildView(label_); | |
| 267 UpdateStyle(); | |
| 268 | |
| 269 SetContent(container); | |
| 270 } | |
| 271 | |
| 272 void SpecialPopupRow::SetTextLabelNonMd(int string_id, | |
| 273 ViewClickListener* listener) { | |
| 274 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); | |
| 275 HoverHighlightView* container = new HoverHighlightView(listener); | |
| 276 container->SetLayoutManager(new views::BoxLayout( | |
| 277 views::BoxLayout::kHorizontal, 0, 3, kIconPaddingLeft)); | |
| 278 | |
| 279 container->set_highlight_color(SkColorSetARGB(0, 0, 0, 0)); | |
| 280 container->set_default_color(SkColorSetARGB(0, 0, 0, 0)); | |
| 281 container->set_text_highlight_color(kHeaderTextColorHover); | |
| 282 container->set_text_default_color(kHeaderTextColorNormal); | |
| 283 | |
| 284 container->AddIconAndLabel( | |
| 285 *rb.GetImageNamed(IDR_AURA_UBER_TRAY_LESS).ToImageSkia(), | |
| 286 rb.GetLocalizedString(string_id), true /* highlight */); | |
| 287 | |
| 288 container->SetBorder( | |
| 289 views::CreateEmptyBorder(0, kTrayPopupPaddingHorizontal, 0, 0)); | |
| 290 | |
| 291 container->SetAccessibleName( | |
| 292 rb.GetLocalizedString(IDS_ASH_STATUS_TRAY_PREVIOUS_MENU)); | |
| 293 SetContent(container); | |
| 294 } | |
| 295 | |
| 296 } // namespace ash | 156 } // namespace ash |
| OLD | NEW |