window_cycle_tab_slider.h 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  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. #ifndef ASH_WM_WINDOW_CYCLE_WINDOW_CYCLE_TAB_SLIDER_H_
  5. #define ASH_WM_WINDOW_CYCLE_WINDOW_CYCLE_TAB_SLIDER_H_
  6. #include "ash/ash_export.h"
  7. #include "ash/wm/window_cycle/window_cycle_tab_slider_button.h"
  8. #include "ash/wm/wm_highlight_item_border.h"
  9. #include "ui/base/metadata/metadata_header_macros.h"
  10. namespace gfx {
  11. class Size;
  12. }
  13. namespace ash {
  14. // A WindowCycleTabSlider containing two buttons to switch between
  15. // all desks and current desks mode.
  16. class ASH_EXPORT WindowCycleTabSlider : public views::View {
  17. public:
  18. METADATA_HEADER(WindowCycleTabSlider);
  19. WindowCycleTabSlider();
  20. WindowCycleTabSlider(const WindowCycleTabSlider&) = delete;
  21. WindowCycleTabSlider& operator=(const WindowCycleTabSlider&) = delete;
  22. ~WindowCycleTabSlider() override = default;
  23. // Sets |is_focused_| to |focus| and displays or hides the highlight on the
  24. // active button selector during keyboard navigation.
  25. void SetFocus(bool focus);
  26. // Updates UI when user prefs change.
  27. void OnModePrefsChanged();
  28. // views::View:
  29. void Layout() override;
  30. gfx::Size CalculatePreferredSize() const override;
  31. bool is_focused() const { return is_focused_; }
  32. private:
  33. friend class WindowCycleListTestApi;
  34. // Updates the active button selector with moving animation from the
  35. // currently selected button to the target button representing |per_desk|
  36. // mode.
  37. void UpdateActiveButtonSelector(bool per_desk);
  38. // Returns an equalized button size calculated from maximum width and height
  39. // of the prefer size of all buttons.
  40. gfx::Size GetPreferredSizeForButtons();
  41. // The view that acts as an active button selector to show the active button
  42. // background and the highlight border if applicable. It is animated during
  43. // mode change.
  44. views::View* active_button_selector_;
  45. // The highlight border, the focus ring, of the active button selector.
  46. // The border shows up when the tab slider is focused during keyboard
  47. // navigation.
  48. WmHighlightItemBorder* highlight_border_;
  49. // The view that contains the tab slider buttons.
  50. views::View* buttons_container_;
  51. WindowCycleTabSliderButton* all_desks_tab_slider_button_;
  52. WindowCycleTabSliderButton* current_desk_tab_slider_button_;
  53. // True if the tab slider is focused when using keyboard navigation.
  54. bool is_focused_ = false;
  55. };
  56. } // namespace ash
  57. #endif // ASH_WM_WINDOW_CYCLE_WINDOW_CYCLE_TAB_SLIDER_H_