header_view.h 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200
  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. #ifndef ASH_FRAME_HEADER_VIEW_H_
  5. #define ASH_FRAME_HEADER_VIEW_H_
  6. #include <memory>
  7. #include "ash/ash_export.h"
  8. #include "ash/public/cpp/tablet_mode_observer.h"
  9. #include "base/callback.h"
  10. #include "base/scoped_observation.h"
  11. #include "chromeos/ui/frame/frame_header.h"
  12. #include "chromeos/ui/frame/immersive/immersive_fullscreen_controller_delegate.h"
  13. #include "third_party/skia/include/core/SkColor.h"
  14. #include "ui/aura/window.h"
  15. #include "ui/aura/window_observer.h"
  16. #include "ui/base/ui_base_types.h"
  17. #include "ui/display/display_observer.h"
  18. #include "ui/views/view.h"
  19. namespace chromeos {
  20. class DefaultFrameHeader;
  21. class FrameCaptionButtonContainerView;
  22. }
  23. namespace gfx {
  24. class ImageSkia;
  25. }
  26. namespace views {
  27. class FrameCaptionButton;
  28. class ImageView;
  29. class Widget;
  30. class NonClientFrameView;
  31. }
  32. namespace ash {
  33. enum class FrameBackButtonState;
  34. // View which paints the frame header (title, caption buttons...). It slides off
  35. // and on screen in immersive fullscreen.
  36. class ASH_EXPORT HeaderView
  37. : public views::View,
  38. public chromeos::ImmersiveFullscreenControllerDelegate,
  39. public TabletModeObserver,
  40. public aura::WindowObserver,
  41. public display::DisplayObserver {
  42. public:
  43. // |target_widget| is the widget that the caption buttons act on.
  44. // |target_widget| is not necessarily the same as the widget the header is
  45. // placed in. For example, in immersive fullscreen this view may be painted in
  46. // a widget that slides in and out on top of the main app or browser window.
  47. // However, clicking a caption button should act on the target widget.
  48. HeaderView(views::Widget* target_widget,
  49. views::NonClientFrameView* frame_view);
  50. HeaderView(const HeaderView&) = delete;
  51. HeaderView& operator=(const HeaderView&) = delete;
  52. ~HeaderView() override;
  53. METADATA_HEADER(HeaderView);
  54. // Initialize the parts with side effects.
  55. void Init();
  56. void set_immersive_mode_changed_callback(base::RepeatingClosure callback) {
  57. immersive_mode_changed_callback_ = std::move(callback);
  58. }
  59. bool should_paint() { return should_paint_; }
  60. // Schedules a repaint for the entire title.
  61. void SchedulePaintForTitle();
  62. // Tells the window controls to reset themselves to the normal state.
  63. void ResetWindowControls();
  64. // Returns the amount of the view's pixels which should be on screen.
  65. int GetPreferredOnScreenHeight();
  66. // Returns the view's preferred height.
  67. int GetPreferredHeight();
  68. // Returns the view's minimum width.
  69. int GetMinimumWidth() const;
  70. // Sets the avatar icon to be displayed on the frame header.
  71. void SetAvatarIcon(const gfx::ImageSkia& avatar);
  72. void UpdateCaptionButtons();
  73. void SetWidthInPixels(int width_in_pixels);
  74. // views::View:
  75. void Layout() override;
  76. void ChildPreferredSizeChanged(views::View* child) override;
  77. bool IsDrawn() const override;
  78. // TabletModeObserver:
  79. void OnTabletModeStarted() override;
  80. void OnTabletModeEnded() override;
  81. // aura::WindowObserver:
  82. void OnWindowPropertyChanged(aura::Window* window,
  83. const void* key,
  84. intptr_t old) override;
  85. void OnWindowDestroying(aura::Window* window) override;
  86. // display::DisplayObserver:
  87. void OnDisplayMetricsChanged(const display::Display& display,
  88. uint32_t changed_metrics) override;
  89. chromeos::FrameCaptionButtonContainerView* caption_button_container() {
  90. return caption_button_container_;
  91. }
  92. views::View* avatar_icon() const;
  93. bool in_immersive_mode() const { return in_immersive_mode_; }
  94. bool is_revealed() const { return fullscreen_visible_fraction_ > 0.0; }
  95. void SetShouldPaintHeader(bool paint);
  96. views::FrameCaptionButton* GetBackButton();
  97. // ImmersiveFullscreenControllerDelegate:
  98. void OnImmersiveRevealStarted() override;
  99. void OnImmersiveRevealEnded() override;
  100. void OnImmersiveFullscreenEntered() override;
  101. void OnImmersiveFullscreenExited() override;
  102. void SetVisibleFraction(double visible_fraction) override;
  103. std::vector<gfx::Rect> GetVisibleBoundsInScreen() const override;
  104. void Relayout() override;
  105. chromeos::DefaultFrameHeader* GetFrameHeader() { return frame_header_.get(); }
  106. private:
  107. class HeaderContentView;
  108. friend class HeaderContentView;
  109. // Paint the header content.
  110. void PaintHeaderContent(gfx::Canvas* canvas);
  111. void UpdateBackButton();
  112. void UpdateCenterButton();
  113. void UpdateCaptionButtonsVisibility();
  114. // The widget that the caption buttons act on.
  115. views::Widget* target_widget_;
  116. // A callback to run when |in_immersive_mode_| changes.
  117. base::RepeatingClosure immersive_mode_changed_callback_;
  118. // Helper for painting the header. The exact type of FrameHeader will depend
  119. // on the type of window: In Mash, Chrome Browser windows use
  120. // CustomFrameHeader which is aware of theming. In classic Ash, Chrome Browser
  121. // windows won't use HeaderView at all. In either configuration, non Browser
  122. // windows will use DefaultFrameHeader.
  123. std::unique_ptr<chromeos::DefaultFrameHeader> frame_header_;
  124. views::ImageView* avatar_icon_ = nullptr;
  125. // View which draws the content of the frame.
  126. HeaderContentView* header_content_view_ = nullptr;
  127. // View which contains the window caption buttons.
  128. chromeos::FrameCaptionButtonContainerView* caption_button_container_ =
  129. nullptr;
  130. // The fraction of the header's height which is visible while in fullscreen.
  131. // This value is meaningless when not in fullscreen.
  132. double fullscreen_visible_fraction_ = 0;
  133. // True if a layer should be used for the immersive mode reveal. Some code
  134. // needs HeaderView to always paint to a layer instead of only during
  135. // immersive reveal (see WmNativeWidgetAura).
  136. bool add_layer_for_immersive_ = false;
  137. bool did_layout_ = false;
  138. // False to skip painting. Used for overview mode to hide the header.
  139. bool should_paint_ = true;
  140. bool in_immersive_mode_ = false;
  141. // This is used to compute visible bounds.
  142. mutable bool is_drawn_override_ = false;
  143. // Observes property changes to |target_widget_|'s window.
  144. base::ScopedObservation<aura::Window, aura::WindowObserver>
  145. window_observation_{this};
  146. };
  147. } // namespace ash
  148. #endif // ASH_FRAME_HEADER_VIEW_H_