system_menu_button.cc 2.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  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
  3. // found in the LICENSE file.
  4. #include "ash/system/tray/system_menu_button.h"
  5. #include "ash/style/ash_color_provider.h"
  6. #include "ash/style/style_util.h"
  7. #include "ash/system/tray/tray_constants.h"
  8. #include "ash/system/tray/tray_popup_ink_drop_style.h"
  9. #include "ash/system/tray/tray_popup_utils.h"
  10. #include "ash/system/tray/tray_utils.h"
  11. #include "ui/base/l10n/l10n_util.h"
  12. #include "ui/base/metadata/metadata_impl_macros.h"
  13. #include "ui/color/color_id.h"
  14. #include "ui/gfx/paint_vector_icon.h"
  15. #include "ui/gfx/vector_icon_utils.h"
  16. #include "ui/views/animation/flood_fill_ink_drop_ripple.h"
  17. #include "ui/views/animation/ink_drop_highlight.h"
  18. #include "ui/views/animation/ink_drop_impl.h"
  19. #include "ui/views/controls/focus_ring.h"
  20. namespace ash {
  21. SystemMenuButton::SystemMenuButton(PressedCallback callback,
  22. const gfx::ImageSkia& normal_icon,
  23. const gfx::ImageSkia& disabled_icon,
  24. int accessible_name_id)
  25. : views::ImageButton(std::move(callback)) {
  26. DCHECK_EQ(normal_icon.width(), disabled_icon.width());
  27. DCHECK_EQ(normal_icon.height(), disabled_icon.height());
  28. SetImage(STATE_NORMAL, normal_icon);
  29. SetImage(STATE_DISABLED, disabled_icon);
  30. SetImageHorizontalAlignment(ALIGN_CENTER);
  31. SetImageVerticalAlignment(ALIGN_MIDDLE);
  32. SetPreferredSize(gfx::Size(kMenuButtonSize, kMenuButtonSize));
  33. SetTooltipText(l10n_util::GetStringUTF16(accessible_name_id));
  34. StyleUtil::SetUpInkDropForButton(
  35. this, GetInkDropInsets(TrayPopupInkDropStyle::HOST_CENTERED));
  36. TrayPopupUtils::InstallHighlightPathGenerator(
  37. this, TrayPopupInkDropStyle::HOST_CENTERED);
  38. views::FocusRing::Get(this)->SetColorId(ui::kColorAshFocusRing);
  39. }
  40. SystemMenuButton::SystemMenuButton(PressedCallback callback,
  41. const gfx::VectorIcon& icon,
  42. int accessible_name_id)
  43. : SystemMenuButton(std::move(callback),
  44. gfx::ImageSkia(),
  45. gfx::ImageSkia(),
  46. accessible_name_id) {
  47. SetVectorIcon(icon);
  48. }
  49. void SystemMenuButton::SetVectorIcon(const gfx::VectorIcon& icon) {
  50. const SkColor icon_color = AshColorProvider::Get()->GetContentLayerColor(
  51. AshColorProvider::ContentLayerType::kButtonIconColor);
  52. SetImage(views::Button::STATE_NORMAL,
  53. gfx::CreateVectorIcon(icon, icon_color));
  54. SetImage(views::Button::STATE_DISABLED,
  55. gfx::CreateVectorIcon(
  56. icon, AshColorProvider::GetDisabledColor(icon_color)));
  57. }
  58. SystemMenuButton::~SystemMenuButton() = default;
  59. BEGIN_METADATA(SystemMenuButton, views::ImageButton)
  60. END_METADATA
  61. } // namespace ash