| 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_COMMON_SYSTEM_TRAY_TRAY_BACKGROUND_VIEW_H_ | |
| 6 #define ASH_COMMON_SYSTEM_TRAY_TRAY_BACKGROUND_VIEW_H_ | |
| 7 | |
| 8 #include <memory> | |
| 9 | |
| 10 #include "ash/ash_export.h" | |
| 11 #include "ash/common/shelf/shelf_background_animator_observer.h" | |
| 12 #include "ash/common/system/tray/actionable_view.h" | |
| 13 #include "ash/public/cpp/shelf_types.h" | |
| 14 #include "base/macros.h" | |
| 15 #include "ui/compositor/layer_animation_observer.h" | |
| 16 #include "ui/gfx/geometry/insets.h" | |
| 17 #include "ui/views/bubble/tray_bubble_view.h" | |
| 18 | |
| 19 namespace ash { | |
| 20 class TrayEventFilter; | |
| 21 class TrayBackground; | |
| 22 class WmShelf; | |
| 23 | |
| 24 // Base class for children of StatusAreaWidget: SystemTray, WebNotificationTray, | |
| 25 // LogoutButtonTray, OverviewButtonTray. | |
| 26 // This class handles setting and animating the background when the Launcher | |
| 27 // is shown/hidden. It also inherits from ActionableView so that the tray | |
| 28 // items can override PerformAction when clicked on. | |
| 29 class ASH_EXPORT TrayBackgroundView : public ActionableView, | |
| 30 public ui::ImplicitAnimationObserver, | |
| 31 public ShelfBackgroundAnimatorObserver { | |
| 32 public: | |
| 33 static const char kViewClassName[]; | |
| 34 | |
| 35 // Base class for tray containers. Sets the border and layout. The container | |
| 36 // auto-resizes the widget when necessary. | |
| 37 class TrayContainer : public views::View { | |
| 38 public: | |
| 39 explicit TrayContainer(ShelfAlignment alignment); | |
| 40 ~TrayContainer() override {} | |
| 41 | |
| 42 void SetAlignment(ShelfAlignment alignment); | |
| 43 | |
| 44 void SetMargin(int main_axis_margin, int cross_axis_margin); | |
| 45 | |
| 46 protected: | |
| 47 // views::View: | |
| 48 void ChildPreferredSizeChanged(views::View* child) override; | |
| 49 void ChildVisibilityChanged(View* child) override; | |
| 50 void ViewHierarchyChanged( | |
| 51 const ViewHierarchyChangedDetails& details) override; | |
| 52 | |
| 53 private: | |
| 54 void UpdateLayout(); | |
| 55 | |
| 56 ShelfAlignment alignment_; | |
| 57 int main_axis_margin_ = 0; | |
| 58 int cross_axis_margin_ = 0; | |
| 59 | |
| 60 DISALLOW_COPY_AND_ASSIGN(TrayContainer); | |
| 61 }; | |
| 62 | |
| 63 explicit TrayBackgroundView(WmShelf* wm_shelf); | |
| 64 ~TrayBackgroundView() override; | |
| 65 | |
| 66 // Called after the tray has been added to the widget containing it. | |
| 67 virtual void Initialize(); | |
| 68 | |
| 69 // Initializes animations for the bubble. | |
| 70 static void InitializeBubbleAnimations(views::Widget* bubble_widget); | |
| 71 | |
| 72 // views::View: | |
| 73 void SetVisible(bool visible) override; | |
| 74 const char* GetClassName() const override; | |
| 75 void ChildPreferredSizeChanged(views::View* child) override; | |
| 76 void GetAccessibleNodeData(ui::AXNodeData* node_data) override; | |
| 77 void AboutToRequestFocusFromTabTraversal(bool reverse) override; | |
| 78 void OnPaint(gfx::Canvas* canvas) override; | |
| 79 | |
| 80 // ActionableView: | |
| 81 std::unique_ptr<views::InkDropRipple> CreateInkDropRipple() const override; | |
| 82 std::unique_ptr<views::InkDropHighlight> CreateInkDropHighlight() | |
| 83 const override; | |
| 84 void OnGestureEvent(ui::GestureEvent* event) override; | |
| 85 | |
| 86 // Called whenever the shelf alignment changes. | |
| 87 virtual void SetShelfAlignment(ShelfAlignment alignment); | |
| 88 | |
| 89 // Called when the anchor (tray or bubble) may have moved or changed. | |
| 90 virtual void AnchorUpdated() {} | |
| 91 | |
| 92 // Called from GetAccessibleNodeData, must return a valid accessible name. | |
| 93 virtual base::string16 GetAccessibleNameForTray() = 0; | |
| 94 | |
| 95 // Called when the bubble is resized. | |
| 96 virtual void BubbleResized(const views::TrayBubbleView* bubble_view) {} | |
| 97 | |
| 98 // Hides the bubble associated with |bubble_view|. Called when the widget | |
| 99 // is closed. | |
| 100 virtual void HideBubbleWithView(const views::TrayBubbleView* bubble_view) = 0; | |
| 101 | |
| 102 // Called by the bubble wrapper when a click event occurs outside the bubble. | |
| 103 // May close the bubble. | |
| 104 virtual void ClickedOutsideBubble() = 0; | |
| 105 | |
| 106 // Sets |contents| as a child. | |
| 107 void SetContents(views::View* contents); | |
| 108 | |
| 109 // Creates and sets contents background to |background_|. |draws_active| | |
| 110 // determines if the view's background should be drawn as active when the view | |
| 111 // is in the active state. | |
| 112 void SetContentsBackground(bool draws_active); | |
| 113 | |
| 114 // Returns the bubble anchor alignment based on |shelf_alignment_|. | |
| 115 views::TrayBubbleView::AnchorAlignment GetAnchorAlignment() const; | |
| 116 | |
| 117 void SetIsActive(bool is_active); | |
| 118 bool is_active() const { return is_active_; } | |
| 119 | |
| 120 TrayContainer* tray_container() const { return tray_container_; } | |
| 121 ShelfAlignment shelf_alignment() const { return shelf_alignment_; } | |
| 122 TrayEventFilter* tray_event_filter() { return tray_event_filter_.get(); } | |
| 123 WmShelf* shelf() { return wm_shelf_; } | |
| 124 | |
| 125 // Updates the arrow visibility based on the launcher visibility. | |
| 126 void UpdateBubbleViewArrow(views::TrayBubbleView* bubble_view); | |
| 127 | |
| 128 // ShelfBackgroundAnimatorObserver: | |
| 129 void UpdateShelfItemBackground(SkColor color) override; | |
| 130 | |
| 131 // Updates the visibility of this tray's separator. | |
| 132 void set_separator_visibility(bool visible) { separator_visible_ = visible; } | |
| 133 | |
| 134 // Gets the anchor for bubbles, which is tray_container(). | |
| 135 views::View* GetBubbleAnchor() const; | |
| 136 | |
| 137 // Gets additional insets for positioning bubbles relative to | |
| 138 // tray_container(). | |
| 139 gfx::Insets GetBubbleAnchorInsets() const; | |
| 140 | |
| 141 protected: | |
| 142 // ActionableView: | |
| 143 std::unique_ptr<views::InkDropMask> CreateInkDropMask() const override; | |
| 144 bool ShouldEnterPushedState(const ui::Event& event) override; | |
| 145 bool PerformAction(const ui::Event& event) override; | |
| 146 void HandlePerformActionResult(bool action_performed, | |
| 147 const ui::Event& event) override; | |
| 148 void OnPaintFocus(gfx::Canvas* canvas) override; | |
| 149 | |
| 150 private: | |
| 151 class TrayWidgetObserver; | |
| 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 // Helper function that calculates background insets relative to local bounds. | |
| 162 gfx::Insets GetBackgroundInsets() const; | |
| 163 | |
| 164 // Helper function that calculates background bounds relative to local bounds | |
| 165 // based on background insets returned from GetBackgroundInsets(). | |
| 166 gfx::Rect GetBackgroundBounds() const; | |
| 167 | |
| 168 // The shelf containing the system tray for this view. | |
| 169 WmShelf* wm_shelf_; | |
| 170 | |
| 171 // Convenience pointer to the contents view. | |
| 172 TrayContainer* tray_container_; | |
| 173 | |
| 174 // Shelf alignment. | |
| 175 // TODO(jamescook): Don't cache this, get it from WmShelf. | |
| 176 ShelfAlignment shelf_alignment_; | |
| 177 | |
| 178 // Owned by the view passed to SetContents(). | |
| 179 TrayBackground* background_; | |
| 180 | |
| 181 // Determines if the view is active. This changes how the background is drawn | |
| 182 // in non-MD version and how the ink drop ripples behave in MD version. | |
| 183 bool is_active_; | |
| 184 | |
| 185 // Visibility of this tray's separator which is a line of 1x32px and 4px to | |
| 186 // right of tray. | |
| 187 bool separator_visible_; | |
| 188 | |
| 189 std::unique_ptr<TrayWidgetObserver> widget_observer_; | |
| 190 std::unique_ptr<TrayEventFilter> tray_event_filter_; | |
| 191 | |
| 192 DISALLOW_COPY_AND_ASSIGN(TrayBackgroundView); | |
| 193 }; | |
| 194 | |
| 195 } // namespace ash | |
| 196 | |
| 197 #endif // ASH_COMMON_SYSTEM_TRAY_TRAY_BACKGROUND_VIEW_H_ | |
| OLD | NEW |