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/views/bubble/tray_bubble_view.h"
17 class ShelfLayoutManager
;
18 class StatusAreaWidget
;
19 class TrayEventFilter
;
22 // Base class for children of StatusAreaWidget: SystemTray, WebNotificationTray.
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
{
29 static const char kViewClassName
[];
31 // Base class for tray containers. Sets the border and layout. The container
32 // auto-resizes the widget when necessary.
33 class TrayContainer
: public views::View
{
35 explicit TrayContainer(ShelfAlignment alignment
);
36 virtual ~TrayContainer() {}
38 void SetAlignment(ShelfAlignment alignment
);
40 void set_size(const gfx::Size
& size
) { size_
= size
; }
42 // Overridden from views::View.
43 virtual gfx::Size
GetPreferredSize() OVERRIDE
;
46 // Overridden from views::View.
47 virtual void ChildPreferredSizeChanged(views::View
* child
) OVERRIDE
;
48 virtual void ChildVisibilityChanged(View
* child
) OVERRIDE
;
49 virtual void ViewHierarchyChanged(
50 const ViewHierarchyChangedDetails
& details
) OVERRIDE
;
55 ShelfAlignment alignment_
;
58 DISALLOW_COPY_AND_ASSIGN(TrayContainer
);
61 explicit TrayBackgroundView(internal::StatusAreaWidget
* status_area_widget
);
62 virtual ~TrayBackgroundView();
64 // Called after the tray has been added to the widget containing it.
65 virtual void Initialize();
67 // Overridden from views::View.
68 virtual const char* GetClassName() const OVERRIDE
;
69 virtual void OnMouseEntered(const ui::MouseEvent
& event
) OVERRIDE
;
70 virtual void OnMouseExited(const ui::MouseEvent
& event
) OVERRIDE
;
71 virtual void ChildPreferredSizeChanged(views::View
* child
) OVERRIDE
;
72 virtual void OnPaintFocusBorder(gfx::Canvas
* canvas
) OVERRIDE
;
73 virtual void GetAccessibleState(ui::AccessibleViewState
* state
) OVERRIDE
;
74 virtual void AboutToRequestFocusFromTabTraversal(bool reverse
) OVERRIDE
;
76 // Overridden from internal::ActionableView.
77 virtual bool PerformAction(const ui::Event
& event
) OVERRIDE
;
79 // Overridden from internal::BackgroundAnimatorDelegate.
80 virtual void UpdateBackground(int alpha
) OVERRIDE
;
82 // Called whenever the shelf alignment changes.
83 virtual void SetShelfAlignment(ShelfAlignment alignment
);
85 // Called when the anchor (tray or bubble) may have moved or changed.
86 virtual void AnchorUpdated() {}
88 // Called from GetAccessibleState, must return a valid accessible name.
89 virtual base::string16
GetAccessibleNameForTray() = 0;
91 // Hides the bubble associated with |bubble_view|. Called when the widget
93 virtual void HideBubbleWithView(const views::TrayBubbleView
* bubble_view
) = 0;
95 // Called by the bubble wrapper when a click event occurs outside the bubble.
96 // May close the bubble. Returns true if the event is handled.
97 virtual bool ClickedOutsideBubble() = 0;
99 // Sets |contents| as a child.
100 void SetContents(views::View
* contents
);
102 // Creates and sets contents background to |background_|.
103 void SetContentsBackground();
105 // Sets whether the tray paints a background. Default is true, but is set to
106 // false if a window overlaps the shelf.
107 void SetPaintsBackground(
109 internal::BackgroundAnimator::ChangeType change_type
);
111 // Initializes animations for the bubble.
112 void InitializeBubbleAnimations(views::Widget
* bubble_widget
);
114 // Returns the window hosting the bubble.
115 aura::Window
* GetBubbleWindowContainer() const;
117 // Returns the anchor rect for the bubble.
118 gfx::Rect
GetBubbleAnchorRect(
119 views::Widget
* anchor_widget
,
120 views::TrayBubbleView::AnchorType anchor_type
,
121 views::TrayBubbleView::AnchorAlignment anchor_alignment
) const;
123 // Returns the bubble anchor alignment based on |shelf_alignment_|.
124 views::TrayBubbleView::AnchorAlignment
GetAnchorAlignment() const;
126 // Updates the view visual based on the visibility of the bubble.
127 void SetBubbleVisible(bool visible
);
129 StatusAreaWidget
* status_area_widget() {
130 return status_area_widget_
;
132 const StatusAreaWidget
* status_area_widget() const {
133 return status_area_widget_
;
135 TrayContainer
* tray_container() const { return tray_container_
; }
136 ShelfAlignment
shelf_alignment() const { return shelf_alignment_
; }
137 TrayEventFilter
* tray_event_filter() { return tray_event_filter_
.get(); }
139 ShelfLayoutManager
* GetShelfLayoutManager();
141 // Updates the arrow visibilty based on the launcher visibilty.
142 void UpdateBubbleViewArrow(views::TrayBubbleView
* bubble_view
);
144 // Provides the background with a function to query for pressed state.
145 virtual bool IsPressed();
148 class TrayWidgetObserver
;
150 // Called from Initialize after all status area trays have been created.
151 // Sets the border based on the position of the view.
154 // Unowned pointer to parent widget.
155 StatusAreaWidget
* status_area_widget_
;
157 // Convenience pointer to the contents view.
158 TrayContainer
* tray_container_
;
161 ShelfAlignment shelf_alignment_
;
163 // Owned by the view passed to SetContents().
164 internal::TrayBackground
* background_
;
166 internal::BackgroundAnimator hide_background_animator_
;
167 internal::BackgroundAnimator hover_background_animator_
;
170 scoped_ptr
<TrayWidgetObserver
> widget_observer_
;
171 scoped_ptr
<TrayEventFilter
> tray_event_filter_
;
173 DISALLOW_COPY_AND_ASSIGN(TrayBackgroundView
);
176 } // namespace internal
179 #endif // ASH_SYSTEM_TRAY_TRAY_BACKGROUND_VIEW_H_