[go: nahoru, domu]

blob: bb28454614a458e11ea9793358465e97a3a77131 [file] [log] [blame]
James Cookb0bf8e82017-04-09 17:01:441// 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
5#ifndef ASH_SYSTEM_TRAY_TRAY_BACKGROUND_VIEW_H_
6#define ASH_SYSTEM_TRAY_TRAY_BACKGROUND_VIEW_H_
7
8#include <memory>
9
10#include "ash/ash_export.h"
James Cookb0bf8e82017-04-09 17:01:4411#include "ash/shelf/shelf_background_animator_observer.h"
Tetsui Ohkubo852abe62018-10-03 02:52:2712#include "ash/system/model/virtual_keyboard_model.h"
James Cookb0bf8e82017-04-09 17:01:4413#include "ash/system/tray/actionable_view.h"
James Cook76e92052018-09-21 23:10:3014#include "ash/system/tray/tray_bubble_view.h"
Tim Song23378f32019-11-21 06:07:0715#include "ash/system/user/login_status.h"
James Cookb0bf8e82017-04-09 17:01:4416#include "base/macros.h"
17#include "ui/compositor/layer_animation_observer.h"
18#include "ui/gfx/geometry/insets.h"
James Cookb0bf8e82017-04-09 17:01:4419
20namespace ash {
James Cook840177e2017-05-25 02:20:0121class Shelf;
mohsene6704a02017-04-20 06:30:2022class TrayContainer;
23class TrayEventFilter;
James Cookb0bf8e82017-04-09 17:01:4424
mohsene6704a02017-04-20 06:30:2025// Base class for some children of StatusAreaWidget. This class handles setting
26// and animating the background when the Launcher is shown/hidden. It also
27// inherits from ActionableView so that the tray items can override
28// PerformAction when clicked on.
James Cookb0bf8e82017-04-09 17:01:4429class ASH_EXPORT TrayBackgroundView : public ActionableView,
Ahmed Mehfooz6cabcc9492020-12-15 10:02:1330 public ui::LayerAnimationObserver,
minchd86339372017-07-18 20:07:5031 public ShelfBackgroundAnimatorObserver,
Tetsui Ohkubo852abe62018-10-03 02:52:2732 public TrayBubbleView::Delegate,
33 public VirtualKeyboardModel::Observer {
James Cookb0bf8e82017-04-09 17:01:4434 public:
Sara Kato43f5bc32021-02-18 23:37:1335 METADATA_HEADER(TrayBackgroundView);
James Cookb0bf8e82017-04-09 17:01:4436
James Cook840177e2017-05-25 02:20:0137 explicit TrayBackgroundView(Shelf* shelf);
Sara Kato43f5bc32021-02-18 23:37:1338 TrayBackgroundView(const TrayBackgroundView&) = delete;
39 TrayBackgroundView& operator=(const TrayBackgroundView&) = delete;
James Cookb0bf8e82017-04-09 17:01:4440 ~TrayBackgroundView() override;
41
42 // Called after the tray has been added to the widget containing it.
43 virtual void Initialize();
44
45 // Initializes animations for the bubble.
46 static void InitializeBubbleAnimations(views::Widget* bubble_widget);
47
James Cookb0bf8e82017-04-09 17:01:4448 // ActionableView:
49 std::unique_ptr<views::InkDropRipple> CreateInkDropRipple() const override;
50 std::unique_ptr<views::InkDropHighlight> CreateInkDropHighlight()
51 const override;
52
Tetsui Ohkubo852abe62018-10-03 02:52:2753 // VirtualKeyboardModel::Observer:
54 void OnVirtualKeyboardVisibilityChanged() override;
55
minchd86339372017-07-18 20:07:5056 // Returns the associated tray bubble view, if one exists. Otherwise returns
57 // nullptr.
James Cook76e92052018-09-21 23:10:3058 virtual TrayBubbleView* GetBubbleView();
minchd86339372017-07-18 20:07:5059
Ahmed Mehfooz15cebdd2021-03-03 01:07:0760 // Returns the associated tray bubble widget, if a bubble exists. Otherwise
61 // returns nullptr.
62 virtual views::Widget* GetBubbleWidget() const;
63
minchd86339372017-07-18 20:07:5064 // Closes the associated tray bubble view if it exists and is currently
65 // showing.
66 virtual void CloseBubble();
67
Qiang Xua3c10f42017-10-02 20:41:3068 // Shows the associated tray bubble if one exists. |show_by_click| indicates
69 // whether the showing operation is initiated by mouse or gesture click.
Ahmed Mehfooz15cebdd2021-03-03 01:07:0770 virtual void ShowBubble();
minchd86339372017-07-18 20:07:5071
Manu Cornet26988c52020-02-27 21:40:1672 // Calculates the ideal bounds that this view should have depending on the
73 // constraints.
74 virtual void CalculateTargetBounds();
75
76 // Makes this view's bounds and layout match its calculated target bounds.
77 virtual void UpdateLayout();
Tim Song23378f32019-11-21 06:07:0778
79 // Called to update the tray button after the login status changes.
Manu Cornet3e74a3c2020-02-24 22:43:1780 virtual void UpdateAfterLoginStatusChange();
James Cookb0bf8e82017-04-09 17:01:4481
Tim Song21921b982019-11-08 00:57:1482 // Called whenever the status area's collapse state changes.
83 virtual void UpdateAfterStatusAreaCollapseChange();
84
James Cookb0bf8e82017-04-09 17:01:4485 // Called when the anchor (tray or bubble) may have moved or changed.
Min Chenc33289092018-11-16 18:47:1886 virtual void AnchorUpdated() {}
James Cookb0bf8e82017-04-09 17:01:4487
88 // Called from GetAccessibleNodeData, must return a valid accessible name.
Jan Wilken Dörrie85285b02021-03-11 23:38:4789 virtual std::u16string GetAccessibleNameForTray() = 0;
James Cookb0bf8e82017-04-09 17:01:4490
Toni Barzice4627b852020-06-04 02:22:4991 // Called when a locale change is detected. It should reload any strings the
92 // view may be using. Note that the locale is not expected to change after the
93 // user logs in.
94 virtual void HandleLocaleChange() = 0;
95
James Cookb0bf8e82017-04-09 17:01:4496 // Called when the bubble is resized.
James Cook76e92052018-09-21 23:10:3097 virtual void BubbleResized(const TrayBubbleView* bubble_view);
James Cookb0bf8e82017-04-09 17:01:4498
99 // Hides the bubble associated with |bubble_view|. Called when the widget
100 // is closed.
James Cook76e92052018-09-21 23:10:30101 virtual void HideBubbleWithView(const TrayBubbleView* bubble_view) = 0;
James Cookb0bf8e82017-04-09 17:01:44102
103 // Called by the bubble wrapper when a click event occurs outside the bubble.
104 // May close the bubble.
105 virtual void ClickedOutsideBubble() = 0;
106
minch2cb7a9d32020-10-30 22:18:29107 // Updates the background layer.
108 virtual void UpdateBackground();
109
James Cookb0bf8e82017-04-09 17:01:44110 void SetIsActive(bool is_active);
111 bool is_active() const { return is_active_; }
112
113 TrayContainer* tray_container() const { return tray_container_; }
James Cookb0bf8e82017-04-09 17:01:44114 TrayEventFilter* tray_event_filter() { return tray_event_filter_.get(); }
James Cook840177e2017-05-25 02:20:01115 Shelf* shelf() { return shelf_; }
James Cookb0bf8e82017-04-09 17:01:44116
117 // Updates the arrow visibility based on the launcher visibility.
James Cook76e92052018-09-21 23:10:30118 void UpdateBubbleViewArrow(TrayBubbleView* bubble_view);
James Cookb0bf8e82017-04-09 17:01:44119
James Cookb0bf8e82017-04-09 17:01:44120 // Updates the visibility of this tray's separator.
121 void set_separator_visibility(bool visible) { separator_visible_ = visible; }
122
Tim Song21921b982019-11-08 00:57:14123 // Sets whether to show the view when the status area is collapsed.
124 void set_show_when_collapsed(bool show_when_collapsed) {
125 show_when_collapsed_ = show_when_collapsed;
126 }
127
James Cookb0bf8e82017-04-09 17:01:44128 // Gets the anchor for bubbles, which is tray_container().
129 views::View* GetBubbleAnchor() const;
130
131 // Gets additional insets for positioning bubbles relative to
132 // tray_container().
133 gfx::Insets GetBubbleAnchorInsets() const;
134
jamescookc3301602017-05-30 21:49:28135 // Returns the container window for the bubble (on the proper display).
minchd86339372017-07-18 20:07:50136 aura::Window* GetBubbleWindowContainer();
137
F#m74a43472017-08-30 23:46:42138 // Helper function that calculates background bounds relative to local bounds
139 // based on background insets returned from GetBackgroundInsets().
140 gfx::Rect GetBackgroundBounds() const;
141
Ahmed Mehfooz15cebdd2021-03-03 01:07:07142 // ActionableView:
143 bool PerformAction(const ui::Event& event) override;
144
Tim Song21921b982019-11-08 00:57:14145 // Sets whether the tray item should be shown by default (e.g. it is
146 // activated). The effective visibility of the tray item is determined by the
147 // current state of the status tray (i.e. whether the virtual keyboard is
148 // showing or if it is collapsed).
Tim Song23378f32019-11-21 06:07:07149 virtual void SetVisiblePreferred(bool visible_preferred);
150 bool visible_preferred() const { return visible_preferred_; }
Tim Song21921b982019-11-08 00:57:14151
James Cookb0bf8e82017-04-09 17:01:44152 protected:
153 // ActionableView:
Peter Boström653ea1c2018-12-19 18:35:35154 void OnBoundsChanged(const gfx::Rect& previous_bounds) override;
James Cookb0bf8e82017-04-09 17:01:44155 bool ShouldEnterPushedState(const ui::Event& event) override;
James Cookb0bf8e82017-04-09 17:01:44156 void HandlePerformActionResult(bool action_performed,
157 const ui::Event& event) override;
F#m74a43472017-08-30 23:46:42158 views::PaintInfo::ScaleType GetPaintScaleType() const override;
James Cookb0bf8e82017-04-09 17:01:44159
Tetsui Ohkubo852abe62018-10-03 02:52:27160 void set_show_with_virtual_keyboard(bool show_with_virtual_keyboard) {
161 show_with_virtual_keyboard_ = show_with_virtual_keyboard;
162 }
163
Ahmed Mehfooz6cabcc9492020-12-15 10:02:13164 void set_use_bounce_in_animation(bool use_bounce_in_animation) {
165 use_bounce_in_animation_ = use_bounce_in_animation;
166 }
167
James Cookb0bf8e82017-04-09 17:01:44168 private:
169 class TrayWidgetObserver;
170
Tim Song23378f32019-11-21 06:07:07171 void StartVisibilityAnimation(bool visible);
172
Tim Song21921b982019-11-08 00:57:14173 // views::View:
Tim Song21921b982019-11-08 00:57:14174 void AboutToRequestFocusFromTabTraversal(bool reverse) override;
175 void GetAccessibleNodeData(ui::AXNodeData* node_data) override;
176 void ChildPreferredSizeChanged(views::View* child) override;
177
James Cookb0bf8e82017-04-09 17:01:44178 // ui::ImplicitAnimationObserver:
Ahmed Mehfooz6cabcc9492020-12-15 10:02:13179 void OnLayerAnimationAborted(ui::LayerAnimationSequence* sequence) override {}
180 void OnLayerAnimationEnded(ui::LayerAnimationSequence* sequence) override;
181 void OnLayerAnimationScheduled(
182 ui::LayerAnimationSequence* sequence) override {}
James Cookb0bf8e82017-04-09 17:01:44183
184 // Applies transformations to the |layer()| to animate the view when
185 // SetVisible(false) is called.
Ahmed Mehfooz6cabcc9492020-12-15 10:02:13186 void HideAnimation();
187 void FadeInAnimation();
188 void BounceInAnimation();
James Cookb0bf8e82017-04-09 17:01:44189
190 // Helper function that calculates background insets relative to local bounds.
191 gfx::Insets GetBackgroundInsets() const;
192
Tim Song21921b982019-11-08 00:57:14193 // Returns the effective visibility of the tray item based on the current
194 // state.
195 bool GetEffectiveVisibility();
196
James Cookb0bf8e82017-04-09 17:01:44197 // The shelf containing the system tray for this view.
James Cook840177e2017-05-25 02:20:01198 Shelf* shelf_;
James Cookb0bf8e82017-04-09 17:01:44199
200 // Convenience pointer to the contents view.
201 TrayContainer* tray_container_;
202
James Cookb0bf8e82017-04-09 17:01:44203 // Determines if the view is active. This changes how the ink drop ripples
204 // behave.
205 bool is_active_;
206
207 // Visibility of this tray's separator which is a line of 1x32px and 4px to
208 // right of tray.
209 bool separator_visible_;
210
Tetsui Ohkubo852abe62018-10-03 02:52:27211 // During virtual keyboard is shown, visibility changes to TrayBackgroundView
212 // are ignored. In such case, preferred visibility is reflected after the
213 // virtual keyboard is hidden.
214 bool visible_preferred_;
215
Yuichiro Hanadaceeeedd2018-10-05 01:36:00216 // If true, the view always shows up when virtual keyboard is visible.
Tetsui Ohkubo852abe62018-10-03 02:52:27217 bool show_with_virtual_keyboard_;
218
Tim Song21921b982019-11-08 00:57:14219 // If true, the view is visible when the status area is collapsed.
220 bool show_when_collapsed_;
221
Ahmed Mehfooz6cabcc9492020-12-15 10:02:13222 bool use_bounce_in_animation_ = false;
223
James Cookb0bf8e82017-04-09 17:01:44224 std::unique_ptr<TrayWidgetObserver> widget_observer_;
225 std::unique_ptr<TrayEventFilter> tray_event_filter_;
James Cookb0bf8e82017-04-09 17:01:44226};
227
228} // namespace ash
229
230#endif // ASH_SYSTEM_TRAY_TRAY_BACKGROUND_VIEW_H_