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.
5 #ifndef ASH_SYSTEM_TRAY_TRAY_BACKGROUND_VIEW_H_
6 #define ASH_SYSTEM_TRAY_TRAY_BACKGROUND_VIEW_H_
8 #include "ash/ash_export.h"
9 #include "ash/shelf/background_animator.h"
10 #include "ash/shelf/shelf_types.h"
11 #include "ash/system/tray/actionable_view.h"
12 #include "ui/compositor/layer_animation_observer.h"
13 #include "ui/views/bubble/tray_bubble_view.h"
16 class ShelfLayoutManager
;
17 class StatusAreaWidget
;
18 class TrayEventFilter
;
21 // Base class for children of StatusAreaWidget: SystemTray, WebNotificationTray,
22 // LogoutButtonTray, OverviewButtonTray.
23 // This class handles setting and animating the background when the Launcher
24 // his shown/hidden. It also inherits from ActionableView so that the tray
25 // items can override PerformAction when clicked on.
26 class ASH_EXPORT TrayBackgroundView
: public ActionableView
,
27 public BackgroundAnimatorDelegate
,
28 public ui::ImplicitAnimationObserver
{
30 static const char kViewClassName
[];
32 // Base class for tray containers. Sets the border and layout. The container
33 // auto-resizes the widget when necessary.
34 class TrayContainer
: public views::View
{
36 explicit TrayContainer(ShelfAlignment alignment
);
37 ~TrayContainer() override
{}
39 void SetAlignment(ShelfAlignment alignment
);
41 void set_size(const gfx::Size
& size
) { size_
= size
; }
44 gfx::Size
GetPreferredSize() const override
;
48 void ChildPreferredSizeChanged(views::View
* child
) override
;
49 void ChildVisibilityChanged(View
* child
) override
;
50 void ViewHierarchyChanged(
51 const ViewHierarchyChangedDetails
& details
) override
;
56 ShelfAlignment alignment_
;
59 DISALLOW_COPY_AND_ASSIGN(TrayContainer
);
62 explicit TrayBackgroundView(StatusAreaWidget
* status_area_widget
);
63 ~TrayBackgroundView() override
;
65 // Called after the tray has been added to the widget containing it.
66 virtual void Initialize();
69 void SetVisible(bool visible
) override
;
70 const char* GetClassName() const override
;
71 void OnMouseEntered(const ui::MouseEvent
& event
) override
;
72 void OnMouseExited(const ui::MouseEvent
& event
) override
;
73 void ChildPreferredSizeChanged(views::View
* child
) override
;
74 void GetAccessibleState(ui::AXViewState
* state
) override
;
75 void AboutToRequestFocusFromTabTraversal(bool reverse
) override
;
78 bool PerformAction(const ui::Event
& event
) override
;
79 gfx::Rect
GetFocusBounds() override
;
80 void OnGestureEvent(ui::GestureEvent
* event
) override
;
82 // BackgroundAnimatorDelegate:
83 void UpdateBackground(int alpha
) override
;
85 // Called whenever the shelf alignment changes.
86 virtual void SetShelfAlignment(ShelfAlignment alignment
);
88 // Called when the anchor (tray or bubble) may have moved or changed.
89 virtual void AnchorUpdated() {}
91 // Called from GetAccessibleState, must return a valid accessible name.
92 virtual base::string16
GetAccessibleNameForTray() = 0;
94 // Called when the bubble is resized.
95 virtual void BubbleResized(const views::TrayBubbleView
* bubble_view
) {}
97 // Hides the bubble associated with |bubble_view|. Called when the widget
99 virtual void HideBubbleWithView(const views::TrayBubbleView
* bubble_view
) = 0;
101 // Called by the bubble wrapper when a click event occurs outside the bubble.
102 // May close the bubble. Returns true if the event is handled.
103 virtual bool ClickedOutsideBubble() = 0;
105 // Sets |contents| as a child.
106 void SetContents(views::View
* contents
);
108 // Creates and sets contents background to |background_|.
109 void SetContentsBackground();
111 // Sets whether the tray paints a background. Default is true, but is set to
112 // false if a window overlaps the shelf.
113 void SetPaintsBackground(bool value
,
114 BackgroundAnimatorChangeType change_type
);
116 // Initializes animations for the bubble.
117 void InitializeBubbleAnimations(views::Widget
* bubble_widget
);
119 // Returns the window hosting the bubble.
120 aura::Window
* GetBubbleWindowContainer() const;
122 // Returns the anchor rect for the bubble.
123 gfx::Rect
GetBubbleAnchorRect(
124 views::Widget
* anchor_widget
,
125 views::TrayBubbleView::AnchorType anchor_type
,
126 views::TrayBubbleView::AnchorAlignment anchor_alignment
) const;
128 // Returns the bubble anchor alignment based on |shelf_alignment_|.
129 views::TrayBubbleView::AnchorAlignment
GetAnchorAlignment() const;
131 // Forces the background to be drawn active if set to true.
132 void SetDrawBackgroundAsActive(bool visible
);
134 // Returns true when the the background was overridden to be drawn as active.
135 bool draw_background_as_active() const {return draw_background_as_active_
; }
137 StatusAreaWidget
* status_area_widget() {
138 return status_area_widget_
;
140 const StatusAreaWidget
* status_area_widget() const {
141 return status_area_widget_
;
143 TrayContainer
* tray_container() const { return tray_container_
; }
144 ShelfAlignment
shelf_alignment() const { return shelf_alignment_
; }
145 TrayEventFilter
* tray_event_filter() { return tray_event_filter_
.get(); }
147 ShelfLayoutManager
* GetShelfLayoutManager();
149 // Updates the arrow visibility based on the launcher visibility.
150 void UpdateBubbleViewArrow(views::TrayBubbleView
* bubble_view
);
153 class TrayWidgetObserver
;
155 // Called from Initialize after all status area trays have been created.
156 // Sets the border based on the position of the view.
157 void SetTrayBorder();
159 // ui::ImplicitAnimationObserver:
160 void OnImplicitAnimationsCompleted() override
;
162 // Applies transformations to the |layer()| to animate the view when
163 // SetVisible(false) is called.
164 void HideTransformation();
166 // Unowned pointer to parent widget.
167 StatusAreaWidget
* status_area_widget_
;
169 // Convenience pointer to the contents view.
170 TrayContainer
* tray_container_
;
173 ShelfAlignment shelf_alignment_
;
175 // Owned by the view passed to SetContents().
176 TrayBackground
* background_
;
178 // Animators for the background. They are only used for the old shelf layout.
179 BackgroundAnimator hide_background_animator_
;
180 BackgroundAnimator hover_background_animator_
;
182 // True if the background gets hovered.
185 // This variable stores the activation override which will tint the background
186 // differently if set to true.
187 bool draw_background_as_active_
;
189 scoped_ptr
<TrayWidgetObserver
> widget_observer_
;
190 scoped_ptr
<TrayEventFilter
> tray_event_filter_
;
192 DISALLOW_COPY_AND_ASSIGN(TrayBackgroundView
);
197 #endif // ASH_SYSTEM_TRAY_TRAY_BACKGROUND_VIEW_H_