page_switcher.h 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. // Copyright (c) 2012 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_APP_LIST_VIEWS_PAGE_SWITCHER_H_
  5. #define ASH_APP_LIST_VIEWS_PAGE_SWITCHER_H_
  6. #include "ash/public/cpp/pagination/pagination_model_observer.h"
  7. #include "ui/gfx/color_palette.h"
  8. #include "ui/views/view.h"
  9. namespace views {
  10. class Button;
  11. }
  12. namespace ash {
  13. class PaginationModel;
  14. // PageSwitcher represents its underlying PaginationModel with a button
  15. // strip. Each page in the PageinationModel has a button in the strip and
  16. // when the button is clicked, the corresponding page becomes selected.
  17. class PageSwitcher : public views::View,
  18. public PaginationModelObserver {
  19. public:
  20. static constexpr int kMaxButtonRadiusForRootGrid = 16;
  21. static constexpr int kMaxButtonRadiusForFolderGrid = 10;
  22. PageSwitcher(PaginationModel* model,
  23. bool is_root_app_grid_page_switcher,
  24. bool is_tablet_mode,
  25. SkColor background_color = gfx::kPlaceholderColor);
  26. PageSwitcher(const PageSwitcher&) = delete;
  27. PageSwitcher& operator=(const PageSwitcher&) = delete;
  28. ~PageSwitcher() override;
  29. // Overridden from views::View:
  30. gfx::Size CalculatePreferredSize() const override;
  31. void Layout() override;
  32. const char* GetClassName() const override;
  33. void OnThemeChanged() override;
  34. void set_ignore_button_press(bool ignore) { ignore_button_press_ = ignore; }
  35. void set_is_tablet_mode(bool started) { is_tablet_mode_ = started; }
  36. private:
  37. // Button pressed callback.
  38. void HandlePageSwitch(const ui::Event& event);
  39. // Overridden from PaginationModelObserver:
  40. void TotalPagesChanged(int previous_page_count, int new_page_count) override;
  41. void SelectedPageChanged(int old_selected, int new_selected) override;
  42. PaginationModel* model_; // Owned by AppsGridView.
  43. views::View* buttons_; // Owned by views hierarchy.
  44. // True if the page switcher's root view is the AppsGridView.
  45. const bool is_root_app_grid_page_switcher_;
  46. // True if button press should be ignored.
  47. bool ignore_button_press_ = false;
  48. // Whether tablet mode is enabled.
  49. bool is_tablet_mode_;
  50. };
  51. } // namespace ash
  52. #endif // ASH_APP_LIST_VIEWS_PAGE_SWITCHER_H_