| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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/tray_popup_utils.h" | 5 #include "ash/common/system/tray/tray_popup_utils.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 #include <utility> | 8 #include <utility> |
| 9 | 9 |
| 10 #include "ash/common/ash_constants.h" | 10 #include "ash/common/ash_constants.h" |
| (...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 105 tri_view->SetMaxSize(container, | 105 tri_view->SetMaxSize(container, |
| 106 gfx::Size(SizeRangeLayout::kAbsoluteMaxSize, | 106 gfx::Size(SizeRangeLayout::kAbsoluteMaxSize, |
| 107 GetTrayConstant(TRAY_POPUP_ITEM_MAX_HEIGHT))); | 107 GetTrayConstant(TRAY_POPUP_ITEM_MAX_HEIGHT))); |
| 108 } | 108 } |
| 109 | 109 |
| 110 class BorderlessLabelButton : public views::LabelButton { | 110 class BorderlessLabelButton : public views::LabelButton { |
| 111 public: | 111 public: |
| 112 BorderlessLabelButton(views::ButtonListener* listener, | 112 BorderlessLabelButton(views::ButtonListener* listener, |
| 113 const base::string16& text) | 113 const base::string16& text) |
| 114 : LabelButton(listener, text) { | 114 : LabelButton(listener, text) { |
| 115 if (MaterialDesignController::IsSystemTrayMenuMaterial()) { | 115 const int kHorizontalPadding = 20; |
| 116 SetInkDropMode(views::InkDropHostView::InkDropMode::ON); | 116 SetBorder(views::CreateEmptyBorder(gfx::Insets(0, kHorizontalPadding))); |
| 117 set_has_ink_drop_action_on_click(true); | 117 TrayPopupItemStyle style(TrayPopupItemStyle::FontStyle::BUTTON); |
| 118 set_ink_drop_base_color(kTrayPopupInkDropBaseColor); | 118 style.SetupLabel(label()); |
| 119 set_ink_drop_visible_opacity(kTrayPopupInkDropRippleOpacity); | |
| 120 const int kHorizontalPadding = 20; | |
| 121 SetBorder(views::CreateEmptyBorder(gfx::Insets(0, kHorizontalPadding))); | |
| 122 TrayPopupItemStyle style(TrayPopupItemStyle::FontStyle::BUTTON); | |
| 123 style.SetupLabel(label()); | |
| 124 SetFocusPainter(TrayPopupUtils::CreateFocusPainter()); | |
| 125 } else { | |
| 126 SetBorder(std::unique_ptr<views::Border>(new TrayPopupLabelButtonBorder)); | |
| 127 SetFocusPainter(views::Painter::CreateSolidFocusPainter( | |
| 128 kFocusBorderColor, gfx::Insets(1, 1, 2, 2))); | |
| 129 set_animate_on_state_change(false); | |
| 130 } | |
| 131 SetHorizontalAlignment(gfx::ALIGN_CENTER); | 119 SetHorizontalAlignment(gfx::ALIGN_CENTER); |
| 132 SetFocusForPlatform(); | 120 SetFocusPainter(TrayPopupUtils::CreateFocusPainter()); |
| 121 |
| 122 TrayPopupUtils::ConfigureTrayPopupButton(this); |
| 133 } | 123 } |
| 134 | 124 |
| 135 ~BorderlessLabelButton() override {} | 125 ~BorderlessLabelButton() override {} |
| 136 | 126 |
| 137 // views::LabelButton: | 127 // views::LabelButton: |
| 138 int GetHeightForWidth(int width) const override { | 128 int GetHeightForWidth(int width) const override { return kMenuButtonSize; } |
| 139 if (MaterialDesignController::IsSystemTrayMenuMaterial()) | |
| 140 return kMenuButtonSize; | |
| 141 | |
| 142 return LabelButton::GetHeightForWidth(width); | |
| 143 } | |
| 144 | 129 |
| 145 private: | 130 private: |
| 131 // TODO(estade,bruthig): there's a lot in common here with ActionableView. |
| 132 // Find a way to share. See related TODO on InkDropHostView::SetInkDropMode(). |
| 146 std::unique_ptr<views::InkDrop> CreateInkDrop() override { | 133 std::unique_ptr<views::InkDrop> CreateInkDrop() override { |
| 147 return TrayPopupUtils::CreateInkDrop(TrayPopupInkDropStyle::INSET_BOUNDS, | 134 return TrayPopupUtils::CreateInkDrop(TrayPopupInkDropStyle::INSET_BOUNDS, |
| 148 this); | 135 this); |
| 149 } | 136 } |
| 150 | 137 |
| 151 std::unique_ptr<views::InkDropRipple> CreateInkDropRipple() const override { | 138 std::unique_ptr<views::InkDropRipple> CreateInkDropRipple() const override { |
| 152 return TrayPopupUtils::CreateInkDropRipple( | 139 return TrayPopupUtils::CreateInkDropRipple( |
| 153 TrayPopupInkDropStyle::INSET_BOUNDS, this, | 140 TrayPopupInkDropStyle::INSET_BOUNDS, this, |
| 154 GetInkDropCenterBasedOnLastEvent()); | 141 GetInkDropCenterBasedOnLastEvent()); |
| 155 } | 142 } |
| (...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 273 toggle->SetFocusPainter(CreateFocusPainter()); | 260 toggle->SetFocusPainter(CreateFocusPainter()); |
| 274 toggle->SetAccessibleName(l10n_util::GetStringUTF16(accessible_name_id)); | 261 toggle->SetAccessibleName(l10n_util::GetStringUTF16(accessible_name_id)); |
| 275 return toggle; | 262 return toggle; |
| 276 } | 263 } |
| 277 | 264 |
| 278 std::unique_ptr<views::Painter> TrayPopupUtils::CreateFocusPainter() { | 265 std::unique_ptr<views::Painter> TrayPopupUtils::CreateFocusPainter() { |
| 279 return views::Painter::CreateSolidFocusPainter( | 266 return views::Painter::CreateSolidFocusPainter( |
| 280 kFocusBorderColor, kFocusBorderThickness, gfx::InsetsF()); | 267 kFocusBorderColor, kFocusBorderThickness, gfx::InsetsF()); |
| 281 } | 268 } |
| 282 | 269 |
| 270 void TrayPopupUtils::ConfigureTrayPopupButton(views::CustomButton* button) { |
| 271 // All buttons that call into here want this focus painter, but |
| 272 // SetFocusPainter is defined separately on derived classes and isn't part of |
| 273 // CustomButton. TODO(estade): Address this. |
| 274 // button->SetFocusPainter(TrayPopupUtils::CreateFocusPainter()); |
| 275 button->SetFocusForPlatform(); |
| 276 |
| 277 button->SetInkDropMode(views::InkDropHostView::InkDropMode::ON); |
| 278 button->set_has_ink_drop_action_on_click(true); |
| 279 button->set_ink_drop_base_color(kTrayPopupInkDropBaseColor); |
| 280 button->set_ink_drop_visible_opacity(kTrayPopupInkDropRippleOpacity); |
| 281 } |
| 282 |
| 283 void TrayPopupUtils::ConfigureAsStickyHeader(views::View* view) { | 283 void TrayPopupUtils::ConfigureAsStickyHeader(views::View* view) { |
| 284 view->set_id(VIEW_ID_STICKY_HEADER); | 284 view->set_id(VIEW_ID_STICKY_HEADER); |
| 285 view->set_background( | 285 view->set_background( |
| 286 views::Background::CreateSolidBackground(kBackgroundColor)); | 286 views::Background::CreateSolidBackground(kBackgroundColor)); |
| 287 view->SetBorder( | 287 view->SetBorder( |
| 288 views::CreateEmptyBorder(gfx::Insets(kMenuSeparatorVerticalPadding, 0))); | 288 views::CreateEmptyBorder(gfx::Insets(kMenuSeparatorVerticalPadding, 0))); |
| 289 view->SetPaintToLayer(); | 289 view->SetPaintToLayer(); |
| 290 view->layer()->SetFillsBoundsOpaquely(false); | 290 view->layer()->SetFillsBoundsOpaquely(false); |
| 291 } | 291 } |
| 292 | 292 |
| (...skipping 20 matching lines...) Expand all Loading... |
| 313 | 313 |
| 314 views::LabelButton* TrayPopupUtils::CreateTrayPopupBorderlessButton( | 314 views::LabelButton* TrayPopupUtils::CreateTrayPopupBorderlessButton( |
| 315 views::ButtonListener* listener, | 315 views::ButtonListener* listener, |
| 316 const base::string16& text) { | 316 const base::string16& text) { |
| 317 return new BorderlessLabelButton(listener, text); | 317 return new BorderlessLabelButton(listener, text); |
| 318 } | 318 } |
| 319 | 319 |
| 320 views::LabelButton* TrayPopupUtils::CreateTrayPopupButton( | 320 views::LabelButton* TrayPopupUtils::CreateTrayPopupButton( |
| 321 views::ButtonListener* listener, | 321 views::ButtonListener* listener, |
| 322 const base::string16& text) { | 322 const base::string16& text) { |
| 323 if (!MaterialDesignController::IsSystemTrayMenuMaterial()) | |
| 324 return CreateTrayPopupBorderlessButton(listener, text); | |
| 325 | |
| 326 auto* button = views::MdTextButton::Create(listener, text); | 323 auto* button = views::MdTextButton::Create(listener, text); |
| 327 button->SetProminent(true); | 324 button->SetProminent(true); |
| 328 return button; | 325 return button; |
| 329 } | 326 } |
| 330 | 327 |
| 331 views::Separator* TrayPopupUtils::CreateVerticalSeparator() { | 328 views::Separator* TrayPopupUtils::CreateVerticalSeparator() { |
| 332 views::Separator* separator = | 329 views::Separator* separator = |
| 333 new views::Separator(views::Separator::HORIZONTAL); | 330 new views::Separator(views::Separator::HORIZONTAL); |
| 334 separator->SetPreferredSize(kHorizontalSeparatorHeight); | 331 separator->SetPreferredSize(kHorizontalSeparatorHeight); |
| 335 separator->SetColor(kHorizontalSeparatorColor); | 332 separator->SetColor(kHorizontalSeparatorColor); |
| (...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 448 bool TrayPopupUtils::CanOpenWebUISettings(LoginStatus status) { | 445 bool TrayPopupUtils::CanOpenWebUISettings(LoginStatus status) { |
| 449 // TODO(tdanderson): Consider moving this into WmShell, or introduce a | 446 // TODO(tdanderson): Consider moving this into WmShell, or introduce a |
| 450 // CanShowSettings() method in each delegate type that has a | 447 // CanShowSettings() method in each delegate type that has a |
| 451 // ShowSettings() method. | 448 // ShowSettings() method. |
| 452 return status != LoginStatus::NOT_LOGGED_IN && | 449 return status != LoginStatus::NOT_LOGGED_IN && |
| 453 status != LoginStatus::LOCKED && | 450 status != LoginStatus::LOCKED && |
| 454 !WmShell::Get()->GetSessionStateDelegate()->IsInSecondaryLoginScreen(); | 451 !WmShell::Get()->GetSessionStateDelegate()->IsInSecondaryLoginScreen(); |
| 455 } | 452 } |
| 456 | 453 |
| 457 } // namespace ash | 454 } // namespace ash |
| OLD | NEW |