window_mini_view.h 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. // Copyright 2019 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_MINI_VIEW_H_
  5. #define ASH_WM_WINDOW_MINI_VIEW_H_
  6. #include "ash/ash_export.h"
  7. #include "base/scoped_observation.h"
  8. #include "ui/aura/window.h"
  9. #include "ui/aura/window_observer.h"
  10. #include "ui/base/metadata/metadata_header_macros.h"
  11. #include "ui/views/controls/button/button.h"
  12. namespace views {
  13. class ImageView;
  14. class Label;
  15. class View;
  16. } // namespace views
  17. namespace ash {
  18. class WindowPreviewView;
  19. class WmHighlightItemBorder;
  20. // WindowMiniView is a view which contains a header and optionally a mirror of
  21. // the given window. Displaying the mirror is chosen by the subclass by calling
  22. // |SetShowPreview| in their constructors (or later on if they like).
  23. class ASH_EXPORT WindowMiniView : public views::View,
  24. public aura::WindowObserver {
  25. public:
  26. METADATA_HEADER(WindowMiniView);
  27. WindowMiniView(const WindowMiniView&) = delete;
  28. WindowMiniView& operator=(const WindowMiniView&) = delete;
  29. ~WindowMiniView() override;
  30. static constexpr int kHeaderHeightDp = 40;
  31. // The size in dp of the window icon shown on the alt-tab/overview window next
  32. // to the title.
  33. static constexpr gfx::Size kIconSize = gfx::Size(24, 24);
  34. // Padding between header items.
  35. static constexpr int kHeaderPaddingDp = 12;
  36. // Sets the visibility of |backdrop_view_|. Creates it if it is null.
  37. void SetBackdropVisibility(bool visible);
  38. // Creates or deletes |preview_view_| as needed.
  39. void SetShowPreview(bool show);
  40. // Sets or hides rounded corners on |preview_view_|, if it exists.
  41. void UpdatePreviewRoundedCorners(bool show);
  42. // Shows or hides a focus ring around this view.
  43. void UpdateBorderState(bool show);
  44. views::View* header_view() { return header_view_; }
  45. views::Label* title_label() const { return title_label_; }
  46. views::ImageView* icon_view() { return icon_view_; }
  47. views::View* backdrop_view() { return backdrop_view_; }
  48. WindowPreviewView* preview_view() const { return preview_view_; }
  49. protected:
  50. explicit WindowMiniView(aura::Window* source_window);
  51. // Updates the icon view by creating it if necessary, and grabbing the correct
  52. // image from |source_window_|.
  53. void UpdateIconView();
  54. // Returns the bounds where the backdrop and preview should go.
  55. gfx::Rect GetContentAreaBounds() const;
  56. // Subclasses can override these functions to provide customization for
  57. // margins and layouts of certain elements.
  58. virtual gfx::Rect GetHeaderBounds() const;
  59. virtual gfx::Size GetPreviewViewSize() const;
  60. // views::View:
  61. void Layout() override;
  62. void GetAccessibleNodeData(ui::AXNodeData* node_data) override;
  63. void OnThemeChanged() override;
  64. // aura::WindowObserver:
  65. void OnWindowPropertyChanged(aura::Window* window,
  66. const void* key,
  67. intptr_t old) override;
  68. void OnWindowDestroying(aura::Window* window) override;
  69. void OnWindowTitleChanged(aura::Window* window) override;
  70. aura::Window* source_window() const { return source_window_; }
  71. private:
  72. // The window this class is meant to be a header for. This class also may
  73. // optionally show a mirrored view of this window.
  74. aura::Window* source_window_;
  75. // Views for the icon and title.
  76. views::View* header_view_ = nullptr;
  77. views::Label* title_label_ = nullptr;
  78. views::ImageView* icon_view_ = nullptr;
  79. // Owned by |content_view_| via `View::border_`. This is just a convenient
  80. // pointer to it.
  81. WmHighlightItemBorder* border_ptr_;
  82. // A view that covers the area except the header. It is null when the window
  83. // associated is not pillar or letter boxed.
  84. views::View* backdrop_view_ = nullptr;
  85. // Optionally shows a preview of |window_|.
  86. WindowPreviewView* preview_view_ = nullptr;
  87. base::ScopedObservation<aura::Window, aura::WindowObserver>
  88. window_observation_{this};
  89. };
  90. } // namespace ash
  91. #endif // ASH_WM_WINDOW_MINI_VIEW_H_