blob: 6579f6ca039c330f64a68bcb81ecbfe333509c55 [file] [log] [blame]
James Cookb0bf8e82017-04-09 17:01:441// 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
5#ifndef ASH_FRAME_HEADER_VIEW_H_
6#define ASH_FRAME_HEADER_VIEW_H_
7
8#include <memory>
9
10#include "ash/ash_export.h"
Mitsuru Oshimaa6adca4f2019-07-10 23:30:4611#include "ash/public/cpp/tablet_mode_observer.h"
Peter Kastingce841352019-11-04 22:53:0312#include "base/callback.h"
James Cookb0bf8e82017-04-09 17:01:4413#include "base/macros.h"
Sigurdur Asgeirssone592c482021-01-28 16:17:2914#include "base/scoped_observation.h"
Antonio Gomes448bc6a52020-11-09 23:13:1715#include "chromeos/ui/frame/frame_header.h"
Antonio Gomes5da18e72020-10-16 15:28:2816#include "chromeos/ui/frame/immersive/immersive_fullscreen_controller_delegate.h"
James Cookb0bf8e82017-04-09 17:01:4417#include "third_party/skia/include/core/SkColor.h"
Evan Stade71facea12019-08-29 21:59:2218#include "ui/aura/window.h"
Evan Stade4a971192018-05-09 00:47:4019#include "ui/aura/window_observer.h"
Qiang Xua34f3f92018-04-11 02:37:0820#include "ui/base/ui_base_types.h"
James Cookb0bf8e82017-04-09 17:01:4421#include "ui/views/view.h"
22
Antonio Gomes5c833252020-10-13 18:42:1923namespace chromeos {
Antonio Gomes3a076582020-11-11 18:03:1124class DefaultFrameHeader;
Antonio Gomes5c833252020-10-13 18:42:1925class FrameCaptionButtonContainerView;
26}
27
xiyuan317fdbe2017-05-31 15:02:0228namespace gfx {
29class ImageSkia;
30}
31
James Cookb0bf8e82017-04-09 17:01:4432namespace views {
Tom Andersonf4c383b12018-12-05 02:45:3833class FrameCaptionButton;
James Cookb0bf8e82017-04-09 17:01:4434class ImageView;
35class Widget;
Mitsuru Oshima843a15b42020-10-01 11:31:3936class NonClientFrameView;
James Cookb0bf8e82017-04-09 17:01:4437}
38
39namespace ash {
40
Mitsuru Oshima40338d62017-10-26 20:00:4241enum class FrameBackButtonState;
James Cookb0bf8e82017-04-09 17:01:4442
43// View which paints the frame header (title, caption buttons...). It slides off
44// and on screen in immersive fullscreen.
Antonio Gomes5da18e72020-10-16 15:28:2845class ASH_EXPORT HeaderView
46 : public views::View,
47 public chromeos::ImmersiveFullscreenControllerDelegate,
48 public TabletModeObserver,
49 public aura::WindowObserver {
James Cookb0bf8e82017-04-09 17:01:4450 public:
51 // |target_widget| is the widget that the caption buttons act on.
52 // |target_widget| is not necessarily the same as the widget the header is
53 // placed in. For example, in immersive fullscreen this view may be painted in
54 // a widget that slides in and out on top of the main app or browser window.
55 // However, clicking a caption button should act on the target widget.
Mitsuru Oshima843a15b42020-10-01 11:31:3956 HeaderView(views::Widget* target_widget,
57 views::NonClientFrameView* frame_view);
James Cookb0bf8e82017-04-09 17:01:4458 ~HeaderView() override;
59
Mitsuru Oshima9d0c2172020-08-07 16:09:3660 METADATA_HEADER(HeaderView);
61
Peter Kastingce841352019-11-04 22:53:0362 void set_immersive_mode_changed_callback(base::RepeatingClosure callback) {
63 immersive_mode_changed_callback_ = std::move(callback);
64 }
James Cookb0bf8e82017-04-09 17:01:4465
Sammie Quon35c25b62017-12-01 23:22:5066 bool should_paint() { return should_paint_; }
67
James Cookb0bf8e82017-04-09 17:01:4468 // Schedules a repaint for the entire title.
69 void SchedulePaintForTitle();
70
71 // Tells the window controls to reset themselves to the normal state.
72 void ResetWindowControls();
73
74 // Returns the amount of the view's pixels which should be on screen.
75 int GetPreferredOnScreenHeight();
76
77 // Returns the view's preferred height.
78 int GetPreferredHeight();
79
80 // Returns the view's minimum width.
81 int GetMinimumWidth() const;
82
xiyuan317fdbe2017-05-31 15:02:0283 // Sets the avatar icon to be displayed on the frame header.
84 void SetAvatarIcon(const gfx::ImageSkia& avatar);
James Cookb0bf8e82017-04-09 17:01:4485
Mitsuru Oshimac3105492018-03-26 18:22:3086 void UpdateCaptionButtons();
James Cookb0bf8e82017-04-09 17:01:4487
Mitsuru Oshima29b93df2018-05-25 01:18:4888 void SetWidthInPixels(int width_in_pixels);
89
James Cookb0bf8e82017-04-09 17:01:4490 // views::View:
91 void Layout() override;
James Cookb0bf8e82017-04-09 17:01:4492 void ChildPreferredSizeChanged(views::View* child) override;
Mitsuru Oshima7ea97532019-05-16 16:43:2793 bool IsDrawn() const override;
James Cookb0bf8e82017-04-09 17:01:4494
Sammie Quonb9057f72017-07-20 23:44:0295 // TabletModeObserver:
Mitsuru Oshima0e9b7a62017-07-19 18:23:0396 void OnTabletModeStarted() override;
97 void OnTabletModeEnded() override;
James Cookb0bf8e82017-04-09 17:01:4498
Evan Stade4a971192018-05-09 00:47:4099 // aura::WindowObserver:
100 void OnWindowPropertyChanged(aura::Window* window,
101 const void* key,
102 intptr_t old) override;
103 void OnWindowDestroying(aura::Window* window) override;
104
Antonio Gomes5c833252020-10-13 18:42:19105 chromeos::FrameCaptionButtonContainerView* caption_button_container() {
James Cookb0bf8e82017-04-09 17:01:44106 return caption_button_container_;
107 }
108
109 views::View* avatar_icon() const;
110
Mitsuru Oshimaeee84c3b2018-04-12 05:56:24111 bool in_immersive_mode() const { return in_immersive_mode_; }
Mitsuru Oshimac2327d02018-05-01 00:29:00112 bool is_revealed() const { return fullscreen_visible_fraction_ > 0.0; }
Mitsuru Oshimaeee84c3b2018-04-12 05:56:24113
wutaob32762a2017-11-14 22:35:30114 void SetShouldPaintHeader(bool paint);
115
Tom Andersonf4c383b12018-12-05 02:45:38116 views::FrameCaptionButton* GetBackButton();
Mitsuru Oshimac3105492018-03-26 18:22:30117
James Cookb0bf8e82017-04-09 17:01:44118 // ImmersiveFullscreenControllerDelegate:
119 void OnImmersiveRevealStarted() override;
120 void OnImmersiveRevealEnded() override;
Mitsuru Oshimaeee84c3b2018-04-12 05:56:24121 void OnImmersiveFullscreenEntered() override;
James Cookb0bf8e82017-04-09 17:01:44122 void OnImmersiveFullscreenExited() override;
123 void SetVisibleFraction(double visible_fraction) override;
124 std::vector<gfx::Rect> GetVisibleBoundsInScreen() const override;
Mitsuru Oshima49b451e2019-08-13 10:51:13125 void Relayout() override;
James Cookb0bf8e82017-04-09 17:01:44126
Antonio Gomes3a076582020-11-11 18:03:11127 chromeos::DefaultFrameHeader* GetFrameHeader() { return frame_header_.get(); }
Mitsuru Oshima6d7f5b72018-05-19 21:43:50128
Mitsuru Oshima7a789e592018-04-13 00:46:41129 private:
Mitsuru Oshima29b93df2018-05-25 01:18:48130 class HeaderContentView;
131 friend class HeaderContentView;
132
133 // Paint the header content.
134 void PaintHeaderContent(gfx::Canvas* canvas);
135
Evan Stadee90c93d2018-06-26 21:27:28136 void UpdateBackButton();
Kazuki Takise5e6a32e62021-06-03 07:22:46137 void UpdateCenterButton();
Evan Stade6a49ef02018-08-14 22:35:22138 void UpdateCaptionButtonsVisibility();
Evan Stadee90c93d2018-06-26 21:27:28139
James Cookb0bf8e82017-04-09 17:01:44140 // The widget that the caption buttons act on.
141 views::Widget* target_widget_;
142
Peter Kastingce841352019-11-04 22:53:03143 // A callback to run when |in_immersive_mode_| changes.
144 base::RepeatingClosure immersive_mode_changed_callback_;
145
Evan Stade4a971192018-05-09 00:47:40146 // Helper for painting the header. The exact type of FrameHeader will depend
147 // on the type of window: In Mash, Chrome Browser windows use
148 // CustomFrameHeader which is aware of theming. In classic Ash, Chrome Browser
149 // windows won't use HeaderView at all. In either configuration, non Browser
150 // windows will use DefaultFrameHeader.
Antonio Gomes3a076582020-11-11 18:03:11151 std::unique_ptr<chromeos::DefaultFrameHeader> frame_header_;
James Cookb0bf8e82017-04-09 17:01:44152
Peter Kastingce841352019-11-04 22:53:03153 views::ImageView* avatar_icon_ = nullptr;
James Cookb0bf8e82017-04-09 17:01:44154
Mitsuru Oshima29b93df2018-05-25 01:18:48155 // View which draws the content of the frame.
156 HeaderContentView* header_content_view_ = nullptr;
157
James Cookb0bf8e82017-04-09 17:01:44158 // View which contains the window caption buttons.
Antonio Gomes5c833252020-10-13 18:42:19159 chromeos::FrameCaptionButtonContainerView* caption_button_container_ =
160 nullptr;
James Cookb0bf8e82017-04-09 17:01:44161
162 // The fraction of the header's height which is visible while in fullscreen.
163 // This value is meaningless when not in fullscreen.
Peter Kastingce841352019-11-04 22:53:03164 double fullscreen_visible_fraction_ = 0;
James Cookb0bf8e82017-04-09 17:01:44165
Evan Stade0b22a422018-09-05 17:03:01166 // True if a layer should be used for the immersive mode reveal. Some code
167 // needs HeaderView to always paint to a layer instead of only during
168 // immersive reveal (see WmNativeWidgetAura).
169 bool add_layer_for_immersive_ = false;
170
James Cookb0bf8e82017-04-09 17:01:44171 bool did_layout_ = false;
172
wutaob32762a2017-11-14 22:35:30173 // False to skip painting. Used for overview mode to hide the header.
Peter Kastingce841352019-11-04 22:53:03174 bool should_paint_ = true;
wutaob32762a2017-11-14 22:35:30175
Mitsuru Oshimaeee84c3b2018-04-12 05:56:24176 bool in_immersive_mode_ = false;
177
Mitsuru Oshima7ea97532019-05-16 16:43:27178 // This is used to compute visible bounds.
179 mutable bool is_drawn_override_ = false;
180
Evan Stade4a971192018-05-09 00:47:40181 // Observes property changes to |target_widget_|'s window.
Sigurdur Asgeirssone592c482021-01-28 16:17:29182 base::ScopedObservation<aura::Window, aura::WindowObserver>
183 window_observation_{this};
Evan Stade4a971192018-05-09 00:47:40184
James Cookb0bf8e82017-04-09 17:01:44185 DISALLOW_COPY_AND_ASSIGN(HeaderView);
186};
187
188} // namespace ash
189
190#endif // ASH_FRAME_HEADER_VIEW_H_