James Cook | b0bf8e8 | 2017-04-09 17:01:44 | [diff] [blame] | 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 | |
| 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 Cook | b0bf8e8 | 2017-04-09 17:01:44 | [diff] [blame] | 11 | #include "ash/shelf/shelf_background_animator_observer.h" |
Tetsui Ohkubo | 852abe6 | 2018-10-03 02:52:27 | [diff] [blame] | 12 | #include "ash/system/model/virtual_keyboard_model.h" |
James Cook | b0bf8e8 | 2017-04-09 17:01:44 | [diff] [blame] | 13 | #include "ash/system/tray/actionable_view.h" |
James Cook | 76e9205 | 2018-09-21 23:10:30 | [diff] [blame] | 14 | #include "ash/system/tray/tray_bubble_view.h" |
Tim Song | 23378f3 | 2019-11-21 06:07:07 | [diff] [blame] | 15 | #include "ash/system/user/login_status.h" |
James Cook | b0bf8e8 | 2017-04-09 17:01:44 | [diff] [blame] | 16 | #include "base/macros.h" |
| 17 | #include "ui/compositor/layer_animation_observer.h" |
| 18 | #include "ui/gfx/geometry/insets.h" |
James Cook | b0bf8e8 | 2017-04-09 17:01:44 | [diff] [blame] | 19 | |
| 20 | namespace ash { |
James Cook | 840177e | 2017-05-25 02:20:01 | [diff] [blame] | 21 | class Shelf; |
mohsen | e6704a0 | 2017-04-20 06:30:20 | [diff] [blame] | 22 | class TrayContainer; |
| 23 | class TrayEventFilter; |
James Cook | b0bf8e8 | 2017-04-09 17:01:44 | [diff] [blame] | 24 | |
mohsen | e6704a0 | 2017-04-20 06:30:20 | [diff] [blame] | 25 | // 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 Cook | b0bf8e8 | 2017-04-09 17:01:44 | [diff] [blame] | 29 | class ASH_EXPORT TrayBackgroundView : public ActionableView, |
Ahmed Mehfooz | 6cabcc949 | 2020-12-15 10:02:13 | [diff] [blame] | 30 | public ui::LayerAnimationObserver, |
minch | d8633937 | 2017-07-18 20:07:50 | [diff] [blame] | 31 | public ShelfBackgroundAnimatorObserver, |
Tetsui Ohkubo | 852abe6 | 2018-10-03 02:52:27 | [diff] [blame] | 32 | public TrayBubbleView::Delegate, |
| 33 | public VirtualKeyboardModel::Observer { |
James Cook | b0bf8e8 | 2017-04-09 17:01:44 | [diff] [blame] | 34 | public: |
Sara Kato | 43f5bc3 | 2021-02-18 23:37:13 | [diff] [blame] | 35 | METADATA_HEADER(TrayBackgroundView); |
James Cook | b0bf8e8 | 2017-04-09 17:01:44 | [diff] [blame] | 36 | |
James Cook | 840177e | 2017-05-25 02:20:01 | [diff] [blame] | 37 | explicit TrayBackgroundView(Shelf* shelf); |
Sara Kato | 43f5bc3 | 2021-02-18 23:37:13 | [diff] [blame] | 38 | TrayBackgroundView(const TrayBackgroundView&) = delete; |
| 39 | TrayBackgroundView& operator=(const TrayBackgroundView&) = delete; |
James Cook | b0bf8e8 | 2017-04-09 17:01:44 | [diff] [blame] | 40 | ~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 Cook | b0bf8e8 | 2017-04-09 17:01:44 | [diff] [blame] | 48 | // ActionableView: |
| 49 | std::unique_ptr<views::InkDropRipple> CreateInkDropRipple() const override; |
| 50 | std::unique_ptr<views::InkDropHighlight> CreateInkDropHighlight() |
| 51 | const override; |
| 52 | |
Tetsui Ohkubo | 852abe6 | 2018-10-03 02:52:27 | [diff] [blame] | 53 | // VirtualKeyboardModel::Observer: |
| 54 | void OnVirtualKeyboardVisibilityChanged() override; |
| 55 | |
minch | d8633937 | 2017-07-18 20:07:50 | [diff] [blame] | 56 | // Returns the associated tray bubble view, if one exists. Otherwise returns |
| 57 | // nullptr. |
James Cook | 76e9205 | 2018-09-21 23:10:30 | [diff] [blame] | 58 | virtual TrayBubbleView* GetBubbleView(); |
minch | d8633937 | 2017-07-18 20:07:50 | [diff] [blame] | 59 | |
Ahmed Mehfooz | 15cebdd | 2021-03-03 01:07:07 | [diff] [blame] | 60 | // Returns the associated tray bubble widget, if a bubble exists. Otherwise |
| 61 | // returns nullptr. |
| 62 | virtual views::Widget* GetBubbleWidget() const; |
| 63 | |
minch | d8633937 | 2017-07-18 20:07:50 | [diff] [blame] | 64 | // Closes the associated tray bubble view if it exists and is currently |
| 65 | // showing. |
| 66 | virtual void CloseBubble(); |
| 67 | |
Qiang Xu | a3c10f4 | 2017-10-02 20:41:30 | [diff] [blame] | 68 | // 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 Mehfooz | 15cebdd | 2021-03-03 01:07:07 | [diff] [blame] | 70 | virtual void ShowBubble(); |
minch | d8633937 | 2017-07-18 20:07:50 | [diff] [blame] | 71 | |
Manu Cornet | 26988c5 | 2020-02-27 21:40:16 | [diff] [blame] | 72 | // 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 Song | 23378f3 | 2019-11-21 06:07:07 | [diff] [blame] | 78 | |
| 79 | // Called to update the tray button after the login status changes. |
Manu Cornet | 3e74a3c | 2020-02-24 22:43:17 | [diff] [blame] | 80 | virtual void UpdateAfterLoginStatusChange(); |
James Cook | b0bf8e8 | 2017-04-09 17:01:44 | [diff] [blame] | 81 | |
Tim Song | 21921b98 | 2019-11-08 00:57:14 | [diff] [blame] | 82 | // Called whenever the status area's collapse state changes. |
| 83 | virtual void UpdateAfterStatusAreaCollapseChange(); |
| 84 | |
James Cook | b0bf8e8 | 2017-04-09 17:01:44 | [diff] [blame] | 85 | // Called when the anchor (tray or bubble) may have moved or changed. |
Min Chen | c3328909 | 2018-11-16 18:47:18 | [diff] [blame] | 86 | virtual void AnchorUpdated() {} |
James Cook | b0bf8e8 | 2017-04-09 17:01:44 | [diff] [blame] | 87 | |
| 88 | // Called from GetAccessibleNodeData, must return a valid accessible name. |
Jan Wilken Dörrie | 85285b0 | 2021-03-11 23:38:47 | [diff] [blame^] | 89 | virtual std::u16string GetAccessibleNameForTray() = 0; |
James Cook | b0bf8e8 | 2017-04-09 17:01:44 | [diff] [blame] | 90 | |
Toni Barzic | e4627b85 | 2020-06-04 02:22:49 | [diff] [blame] | 91 | // 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 Cook | b0bf8e8 | 2017-04-09 17:01:44 | [diff] [blame] | 96 | // Called when the bubble is resized. |
James Cook | 76e9205 | 2018-09-21 23:10:30 | [diff] [blame] | 97 | virtual void BubbleResized(const TrayBubbleView* bubble_view); |
James Cook | b0bf8e8 | 2017-04-09 17:01:44 | [diff] [blame] | 98 | |
| 99 | // Hides the bubble associated with |bubble_view|. Called when the widget |
| 100 | // is closed. |
James Cook | 76e9205 | 2018-09-21 23:10:30 | [diff] [blame] | 101 | virtual void HideBubbleWithView(const TrayBubbleView* bubble_view) = 0; |
James Cook | b0bf8e8 | 2017-04-09 17:01:44 | [diff] [blame] | 102 | |
| 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 | |
minch | 2cb7a9d3 | 2020-10-30 22:18:29 | [diff] [blame] | 107 | // Updates the background layer. |
| 108 | virtual void UpdateBackground(); |
| 109 | |
James Cook | b0bf8e8 | 2017-04-09 17:01:44 | [diff] [blame] | 110 | void SetIsActive(bool is_active); |
| 111 | bool is_active() const { return is_active_; } |
| 112 | |
| 113 | TrayContainer* tray_container() const { return tray_container_; } |
James Cook | b0bf8e8 | 2017-04-09 17:01:44 | [diff] [blame] | 114 | TrayEventFilter* tray_event_filter() { return tray_event_filter_.get(); } |
James Cook | 840177e | 2017-05-25 02:20:01 | [diff] [blame] | 115 | Shelf* shelf() { return shelf_; } |
James Cook | b0bf8e8 | 2017-04-09 17:01:44 | [diff] [blame] | 116 | |
| 117 | // Updates the arrow visibility based on the launcher visibility. |
James Cook | 76e9205 | 2018-09-21 23:10:30 | [diff] [blame] | 118 | void UpdateBubbleViewArrow(TrayBubbleView* bubble_view); |
James Cook | b0bf8e8 | 2017-04-09 17:01:44 | [diff] [blame] | 119 | |
James Cook | b0bf8e8 | 2017-04-09 17:01:44 | [diff] [blame] | 120 | // Updates the visibility of this tray's separator. |
| 121 | void set_separator_visibility(bool visible) { separator_visible_ = visible; } |
| 122 | |
Tim Song | 21921b98 | 2019-11-08 00:57:14 | [diff] [blame] | 123 | // 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 Cook | b0bf8e8 | 2017-04-09 17:01:44 | [diff] [blame] | 128 | // 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 | |
jamescook | c330160 | 2017-05-30 21:49:28 | [diff] [blame] | 135 | // Returns the container window for the bubble (on the proper display). |
minch | d8633937 | 2017-07-18 20:07:50 | [diff] [blame] | 136 | aura::Window* GetBubbleWindowContainer(); |
| 137 | |
F#m | 74a4347 | 2017-08-30 23:46:42 | [diff] [blame] | 138 | // 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 Mehfooz | 15cebdd | 2021-03-03 01:07:07 | [diff] [blame] | 142 | // ActionableView: |
| 143 | bool PerformAction(const ui::Event& event) override; |
| 144 | |
Tim Song | 21921b98 | 2019-11-08 00:57:14 | [diff] [blame] | 145 | // 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 Song | 23378f3 | 2019-11-21 06:07:07 | [diff] [blame] | 149 | virtual void SetVisiblePreferred(bool visible_preferred); |
| 150 | bool visible_preferred() const { return visible_preferred_; } |
Tim Song | 21921b98 | 2019-11-08 00:57:14 | [diff] [blame] | 151 | |
James Cook | b0bf8e8 | 2017-04-09 17:01:44 | [diff] [blame] | 152 | protected: |
| 153 | // ActionableView: |
Peter Boström | 653ea1c | 2018-12-19 18:35:35 | [diff] [blame] | 154 | void OnBoundsChanged(const gfx::Rect& previous_bounds) override; |
James Cook | b0bf8e8 | 2017-04-09 17:01:44 | [diff] [blame] | 155 | bool ShouldEnterPushedState(const ui::Event& event) override; |
James Cook | b0bf8e8 | 2017-04-09 17:01:44 | [diff] [blame] | 156 | void HandlePerformActionResult(bool action_performed, |
| 157 | const ui::Event& event) override; |
F#m | 74a4347 | 2017-08-30 23:46:42 | [diff] [blame] | 158 | views::PaintInfo::ScaleType GetPaintScaleType() const override; |
James Cook | b0bf8e8 | 2017-04-09 17:01:44 | [diff] [blame] | 159 | |
Tetsui Ohkubo | 852abe6 | 2018-10-03 02:52:27 | [diff] [blame] | 160 | void set_show_with_virtual_keyboard(bool show_with_virtual_keyboard) { |
| 161 | show_with_virtual_keyboard_ = show_with_virtual_keyboard; |
| 162 | } |
| 163 | |
Ahmed Mehfooz | 6cabcc949 | 2020-12-15 10:02:13 | [diff] [blame] | 164 | void set_use_bounce_in_animation(bool use_bounce_in_animation) { |
| 165 | use_bounce_in_animation_ = use_bounce_in_animation; |
| 166 | } |
| 167 | |
James Cook | b0bf8e8 | 2017-04-09 17:01:44 | [diff] [blame] | 168 | private: |
| 169 | class TrayWidgetObserver; |
| 170 | |
Tim Song | 23378f3 | 2019-11-21 06:07:07 | [diff] [blame] | 171 | void StartVisibilityAnimation(bool visible); |
| 172 | |
Tim Song | 21921b98 | 2019-11-08 00:57:14 | [diff] [blame] | 173 | // views::View: |
Tim Song | 21921b98 | 2019-11-08 00:57:14 | [diff] [blame] | 174 | void AboutToRequestFocusFromTabTraversal(bool reverse) override; |
| 175 | void GetAccessibleNodeData(ui::AXNodeData* node_data) override; |
| 176 | void ChildPreferredSizeChanged(views::View* child) override; |
| 177 | |
James Cook | b0bf8e8 | 2017-04-09 17:01:44 | [diff] [blame] | 178 | // ui::ImplicitAnimationObserver: |
Ahmed Mehfooz | 6cabcc949 | 2020-12-15 10:02:13 | [diff] [blame] | 179 | void OnLayerAnimationAborted(ui::LayerAnimationSequence* sequence) override {} |
| 180 | void OnLayerAnimationEnded(ui::LayerAnimationSequence* sequence) override; |
| 181 | void OnLayerAnimationScheduled( |
| 182 | ui::LayerAnimationSequence* sequence) override {} |
James Cook | b0bf8e8 | 2017-04-09 17:01:44 | [diff] [blame] | 183 | |
| 184 | // Applies transformations to the |layer()| to animate the view when |
| 185 | // SetVisible(false) is called. |
Ahmed Mehfooz | 6cabcc949 | 2020-12-15 10:02:13 | [diff] [blame] | 186 | void HideAnimation(); |
| 187 | void FadeInAnimation(); |
| 188 | void BounceInAnimation(); |
James Cook | b0bf8e8 | 2017-04-09 17:01:44 | [diff] [blame] | 189 | |
| 190 | // Helper function that calculates background insets relative to local bounds. |
| 191 | gfx::Insets GetBackgroundInsets() const; |
| 192 | |
Tim Song | 21921b98 | 2019-11-08 00:57:14 | [diff] [blame] | 193 | // Returns the effective visibility of the tray item based on the current |
| 194 | // state. |
| 195 | bool GetEffectiveVisibility(); |
| 196 | |
James Cook | b0bf8e8 | 2017-04-09 17:01:44 | [diff] [blame] | 197 | // The shelf containing the system tray for this view. |
James Cook | 840177e | 2017-05-25 02:20:01 | [diff] [blame] | 198 | Shelf* shelf_; |
James Cook | b0bf8e8 | 2017-04-09 17:01:44 | [diff] [blame] | 199 | |
| 200 | // Convenience pointer to the contents view. |
| 201 | TrayContainer* tray_container_; |
| 202 | |
James Cook | b0bf8e8 | 2017-04-09 17:01:44 | [diff] [blame] | 203 | // 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 Ohkubo | 852abe6 | 2018-10-03 02:52:27 | [diff] [blame] | 211 | // 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 Hanada | ceeeedd | 2018-10-05 01:36:00 | [diff] [blame] | 216 | // If true, the view always shows up when virtual keyboard is visible. |
Tetsui Ohkubo | 852abe6 | 2018-10-03 02:52:27 | [diff] [blame] | 217 | bool show_with_virtual_keyboard_; |
| 218 | |
Tim Song | 21921b98 | 2019-11-08 00:57:14 | [diff] [blame] | 219 | // If true, the view is visible when the status area is collapsed. |
| 220 | bool show_when_collapsed_; |
| 221 | |
Ahmed Mehfooz | 6cabcc949 | 2020-12-15 10:02:13 | [diff] [blame] | 222 | bool use_bounce_in_animation_ = false; |
| 223 | |
James Cook | b0bf8e8 | 2017-04-09 17:01:44 | [diff] [blame] | 224 | std::unique_ptr<TrayWidgetObserver> widget_observer_; |
| 225 | std::unique_ptr<TrayEventFilter> tray_event_filter_; |
James Cook | b0bf8e8 | 2017-04-09 17:01:44 | [diff] [blame] | 226 | }; |
| 227 | |
| 228 | } // namespace ash |
| 229 | |
| 230 | #endif // ASH_SYSTEM_TRAY_TRAY_BACKGROUND_VIEW_H_ |