window_cycle_tab_slider_button.cc 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. // Copyright 2020 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/wm/window_cycle/window_cycle_tab_slider_button.h"
  5. #include "ash/style/ash_color_provider.h"
  6. #include "base/strings/utf_string_conversions.h"
  7. #include "ui/base/metadata/metadata_impl_macros.h"
  8. #include "ui/gfx/canvas.h"
  9. #include "ui/views/background.h"
  10. #include "ui/views/controls/label.h"
  11. #include "ui/views/layout/box_layout.h"
  12. namespace ash {
  13. namespace {
  14. // The height of the tab slider button.
  15. constexpr int kTabSliderButtonHeight = 32;
  16. // The horizontal insets between the label and the button.
  17. constexpr int kTabSliderButtonHorizontalInsets = 20;
  18. // The font size of the button label.
  19. constexpr int kTabSliderButtonLabelFontSizeDp = 13;
  20. } // namespace
  21. WindowCycleTabSliderButton::WindowCycleTabSliderButton(
  22. views::Button::PressedCallback callback,
  23. const std::u16string& label_text)
  24. : LabelButton(std::move(callback), label_text) {
  25. SetHorizontalAlignment(gfx::ALIGN_CENTER);
  26. label()->SetFontList(
  27. label()
  28. ->font_list()
  29. .DeriveWithSizeDelta(kTabSliderButtonLabelFontSizeDp -
  30. label()->font_list().GetFontSize())
  31. .DeriveWithWeight(gfx::Font::Weight::MEDIUM));
  32. SetEnabledTextColors(AshColorProvider::Get()->GetContentLayerColor(
  33. AshColorProvider::ContentLayerType::kTextColorPrimary));
  34. }
  35. void WindowCycleTabSliderButton::SetToggled(bool is_toggled) {
  36. if (is_toggled == toggled_)
  37. return;
  38. toggled_ = is_toggled;
  39. SetEnabledTextColors(AshColorProvider::Get()->GetContentLayerColor(
  40. toggled_ ? AshColorProvider::ContentLayerType::kButtonLabelColorPrimary
  41. : AshColorProvider::ContentLayerType::kTextColorPrimary));
  42. }
  43. gfx::Size WindowCycleTabSliderButton::CalculatePreferredSize() const {
  44. return gfx::Size(label()->GetPreferredSize().width() +
  45. 2 * kTabSliderButtonHorizontalInsets,
  46. kTabSliderButtonHeight);
  47. }
  48. BEGIN_METADATA(WindowCycleTabSliderButton, views::LabelButton)
  49. END_METADATA
  50. } // namespace ash