| OLD | NEW |
| (Empty) |
| 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" | |
| 11 #include "ash/common/shelf/shelf_types.h" | |
| 12 #include "ash/common/system/tray/actionable_view.h" | |
| 13 #include "ash/common/wm/background_animator.h" | |
| 14 #include "base/macros.h" | |
| 15 #include "ui/compositor/layer_animation_observer.h" | |
| 16 #include "ui/views/bubble/tray_bubble_view.h" | |
| 17 | |
| 18 namespace ash { | |
| 19 class ShelfLayoutManager; | |
| 20 class StatusAreaWidget; | |
| 21 class TrayEventFilter; | |
| 22 class TrayBackground; | |
| 23 class WmShelf; | |
| 24 | |
| 25 // Base class for children of StatusAreaWidget: SystemTray, WebNotificationTray, | |
| 26 // LogoutButtonTray, OverviewButtonTray. | |
| 27 // This class handles setting and animating the background when the Launcher | |
| 28 // his shown/hidden. It also inherits from ActionableView so that the tray | |
| 29 // items can override PerformAction when clicked on. | |
| 30 class ASH_EXPORT TrayBackgroundView : public ActionableView, | |
| 31 public BackgroundAnimatorDelegate, | |
| 32 public ui::ImplicitAnimationObserver { | |
| 33 public: | |
| 34 static const char kViewClassName[]; | |
| 35 | |
| 36 // Base class for tray containers. Sets the border and layout. The container | |
| 37 // auto-resizes the widget when necessary. | |
| 38 class TrayContainer : public views::View { | |
| 39 public: | |
| 40 explicit TrayContainer(ShelfAlignment alignment); | |
| 41 ~TrayContainer() override {} | |
| 42 | |
| 43 void SetAlignment(ShelfAlignment alignment); | |
| 44 | |
| 45 void set_size(const gfx::Size& size) { size_ = size; } | |
| 46 | |
| 47 // views::View: | |
| 48 gfx::Size GetPreferredSize() const override; | |
| 49 | |
| 50 protected: | |
| 51 // views::View: | |
| 52 void ChildPreferredSizeChanged(views::View* child) override; | |
| 53 void ChildVisibilityChanged(View* child) override; | |
| 54 void ViewHierarchyChanged( | |
| 55 const ViewHierarchyChangedDetails& details) override; | |
| 56 | |
| 57 private: | |
| 58 void UpdateLayout(); | |
| 59 | |
| 60 ShelfAlignment alignment_; | |
| 61 gfx::Size size_; | |
| 62 | |
| 63 DISALLOW_COPY_AND_ASSIGN(TrayContainer); | |
| 64 }; | |
| 65 | |
| 66 explicit TrayBackgroundView(StatusAreaWidget* status_area_widget); | |
| 67 ~TrayBackgroundView() override; | |
| 68 | |
| 69 // Called after the tray has been added to the widget containing it. | |
| 70 virtual void Initialize(); | |
| 71 | |
| 72 // Initializes animations for the bubble. | |
| 73 static void InitializeBubbleAnimations(views::Widget* bubble_widget); | |
| 74 | |
| 75 // views::View: | |
| 76 void SetVisible(bool visible) override; | |
| 77 const char* GetClassName() const override; | |
| 78 void ChildPreferredSizeChanged(views::View* child) override; | |
| 79 void GetAccessibleState(ui::AXViewState* state) override; | |
| 80 void AboutToRequestFocusFromTabTraversal(bool reverse) override; | |
| 81 | |
| 82 // ActionableView: | |
| 83 bool PerformAction(const ui::Event& event) override; | |
| 84 gfx::Rect GetFocusBounds() override; | |
| 85 void OnGestureEvent(ui::GestureEvent* event) override; | |
| 86 | |
| 87 // BackgroundAnimatorDelegate: | |
| 88 void UpdateBackground(int alpha) override; | |
| 89 | |
| 90 // Called whenever the shelf alignment changes. | |
| 91 virtual void SetShelfAlignment(ShelfAlignment alignment); | |
| 92 | |
| 93 // Called when the anchor (tray or bubble) may have moved or changed. | |
| 94 virtual void AnchorUpdated() {} | |
| 95 | |
| 96 // Called from GetAccessibleState, must return a valid accessible name. | |
| 97 virtual base::string16 GetAccessibleNameForTray() = 0; | |
| 98 | |
| 99 // Called when the bubble is resized. | |
| 100 virtual void BubbleResized(const views::TrayBubbleView* bubble_view) {} | |
| 101 | |
| 102 // Hides the bubble associated with |bubble_view|. Called when the widget | |
| 103 // is closed. | |
| 104 virtual void HideBubbleWithView(const views::TrayBubbleView* bubble_view) = 0; | |
| 105 | |
| 106 // Called by the bubble wrapper when a click event occurs outside the bubble. | |
| 107 // May close the bubble. | |
| 108 virtual void ClickedOutsideBubble() = 0; | |
| 109 | |
| 110 // Sets |contents| as a child. | |
| 111 void SetContents(views::View* contents); | |
| 112 | |
| 113 // Creates and sets contents background to |background_|. | |
| 114 void SetContentsBackground(); | |
| 115 | |
| 116 // Returns the anchor rect for the bubble. | |
| 117 gfx::Rect GetBubbleAnchorRect( | |
| 118 views::Widget* anchor_widget, | |
| 119 views::TrayBubbleView::AnchorType anchor_type, | |
| 120 views::TrayBubbleView::AnchorAlignment anchor_alignment) const; | |
| 121 | |
| 122 // Returns the bubble anchor alignment based on |shelf_alignment_|. | |
| 123 views::TrayBubbleView::AnchorAlignment GetAnchorAlignment() const; | |
| 124 | |
| 125 // Forces the background to be drawn active if set to true. | |
| 126 void SetDrawBackgroundAsActive(bool visible); | |
| 127 | |
| 128 // Returns true when the the background was overridden to be drawn as active. | |
| 129 bool draw_background_as_active() const {return draw_background_as_active_; } | |
| 130 | |
| 131 StatusAreaWidget* status_area_widget() { | |
| 132 return status_area_widget_; | |
| 133 } | |
| 134 const StatusAreaWidget* status_area_widget() const { | |
| 135 return status_area_widget_; | |
| 136 } | |
| 137 TrayContainer* tray_container() const { return tray_container_; } | |
| 138 ShelfAlignment shelf_alignment() const { return shelf_alignment_; } | |
| 139 TrayEventFilter* tray_event_filter() { return tray_event_filter_.get(); } | |
| 140 | |
| 141 WmShelf* GetShelf(); | |
| 142 | |
| 143 // Updates the arrow visibility based on the launcher visibility. | |
| 144 void UpdateBubbleViewArrow(views::TrayBubbleView* bubble_view); | |
| 145 | |
| 146 private: | |
| 147 class TrayWidgetObserver; | |
| 148 | |
| 149 // Called from Initialize after all status area trays have been created. | |
| 150 // Sets the border based on the position of the view. | |
| 151 void SetTrayBorder(); | |
| 152 | |
| 153 // ui::ImplicitAnimationObserver: | |
| 154 void OnImplicitAnimationsCompleted() override; | |
| 155 bool RequiresNotificationWhenAnimatorDestroyed() const override; | |
| 156 | |
| 157 // Applies transformations to the |layer()| to animate the view when | |
| 158 // SetVisible(false) is called. | |
| 159 void HideTransformation(); | |
| 160 | |
| 161 // Unowned pointer to parent widget. | |
| 162 StatusAreaWidget* status_area_widget_; | |
| 163 | |
| 164 // Convenience pointer to the contents view. | |
| 165 TrayContainer* tray_container_; | |
| 166 | |
| 167 // Shelf alignment. | |
| 168 // TODO(jamescook): Don't cache this, get it from WmShelf. | |
| 169 ShelfAlignment shelf_alignment_; | |
| 170 | |
| 171 // Owned by the view passed to SetContents(). | |
| 172 TrayBackground* background_; | |
| 173 | |
| 174 // This variable stores the activation override which will tint the background | |
| 175 // differently if set to true. | |
| 176 bool draw_background_as_active_; | |
| 177 | |
| 178 std::unique_ptr<TrayWidgetObserver> widget_observer_; | |
| 179 std::unique_ptr<TrayEventFilter> tray_event_filter_; | |
| 180 | |
| 181 DISALLOW_COPY_AND_ASSIGN(TrayBackgroundView); | |
| 182 }; | |
| 183 | |
| 184 } // namespace ash | |
| 185 | |
| 186 #endif // ASH_SYSTEM_TRAY_TRAY_BACKGROUND_VIEW_H_ | |
| OLD | NEW |