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 // Base class for tray containers. Sets the border and layout. The container
30 // auto-resizes the widget when necessary.
31 class TrayContainer
: public views::View
{
33 explicit TrayContainer(ShelfAlignment alignment
);
34 virtual ~TrayContainer() {}
36 void SetAlignment(ShelfAlignment alignment
);
38 void set_size(const gfx::Size
& size
) { size_
= size
; }
40 // Overridden from views::View.
41 virtual gfx::Size
GetPreferredSize() OVERRIDE
;
44 // Overridden from views::View.
45 virtual void ChildPreferredSizeChanged(views::View
* child
) OVERRIDE
;
46 virtual void ChildVisibilityChanged(View
* child
) OVERRIDE
;
47 virtual void ViewHierarchyChanged(bool is_add
,
49 View
* child
) OVERRIDE
;
54 ShelfAlignment alignment_
;
57 DISALLOW_COPY_AND_ASSIGN(TrayContainer
);
60 explicit TrayBackgroundView(internal::StatusAreaWidget
* status_area_widget
);
61 virtual ~TrayBackgroundView();
63 // Called after the tray has been added to the widget containing it.
64 virtual void Initialize();
66 // Overridden from views::View.
67 virtual void OnMouseEntered(const ui::MouseEvent
& event
) OVERRIDE
;
68 virtual void OnMouseExited(const ui::MouseEvent
& event
) OVERRIDE
;
69 virtual void ChildPreferredSizeChanged(views::View
* child
) OVERRIDE
;
70 virtual void OnPaintFocusBorder(gfx::Canvas
* canvas
) OVERRIDE
;
71 virtual void GetAccessibleState(ui::AccessibleViewState
* state
) OVERRIDE
;
72 virtual void AboutToRequestFocusFromTabTraversal(bool reverse
) OVERRIDE
;
74 // Overridden from internal::ActionableView.
75 virtual bool PerformAction(const ui::Event
& event
) OVERRIDE
;
77 // Overridden from internal::BackgroundAnimatorDelegate.
78 virtual void UpdateBackground(int alpha
) OVERRIDE
;
80 // Called whenever the shelf alignment changes.
81 virtual void SetShelfAlignment(ShelfAlignment alignment
);
83 // Called when the anchor (tray or bubble) may have moved or changed.
84 virtual void AnchorUpdated() {}
86 // Called from GetAccessibleState, must return a valid accessible name.
87 virtual string16
GetAccessibleNameForTray() = 0;
89 // Hides the bubble associated with |bubble_view|. Called when the widget
91 virtual void HideBubbleWithView(const views::TrayBubbleView
* bubble_view
) = 0;
93 // Called by the bubble wrapper when a click event occurs outside the bubble.
94 // May close the bubble. Returns true if the event is handled.
95 virtual bool ClickedOutsideBubble() = 0;
97 // Sets |contents| as a child.
98 void SetContents(views::View
* contents
);
100 // Creates and sets contents background to |background_|.
101 void SetContentsBackground();
103 // Initializes animations for the bubble.
104 void InitializeBubbleAnimations(views::Widget
* bubble_widget
);
106 // Returns the window hosting the bubble.
107 aura::Window
* GetBubbleWindowContainer() const;
109 // Returns the anchor rect for the bubble.
110 gfx::Rect
GetBubbleAnchorRect(
111 views::Widget
* anchor_widget
,
112 views::TrayBubbleView::AnchorType anchor_type
,
113 views::TrayBubbleView::AnchorAlignment anchor_alignment
) const;
115 // Returns the bubble anchor alignment based on |shelf_alignment_|.
116 views::TrayBubbleView::AnchorAlignment
GetAnchorAlignment() const;
118 StatusAreaWidget
* status_area_widget() {
119 return status_area_widget_
;
121 const StatusAreaWidget
* status_area_widget() const {
122 return status_area_widget_
;
124 TrayContainer
* tray_container() const { return tray_container_
; }
125 ShelfAlignment
shelf_alignment() const { return shelf_alignment_
; }
126 TrayEventFilter
* tray_event_filter() { return tray_event_filter_
.get(); }
128 ShelfLayoutManager
* GetShelfLayoutManager();
130 // Updates the arrow visibilty based on the launcher visibilty.
131 void UpdateBubbleViewArrow(views::TrayBubbleView
* bubble_view
);
134 class TrayWidgetObserver
;
136 // Called from Initialize after all status area trays have been created.
137 // Sets the border based on the position of the view.
140 // Unowned pointer to parent widget.
141 StatusAreaWidget
* status_area_widget_
;
143 // Convenience pointer to the contents view.
144 TrayContainer
* tray_container_
;
147 ShelfAlignment shelf_alignment_
;
149 // Owned by the view passed to SetContents().
150 internal::TrayBackground
* background_
;
152 internal::BackgroundAnimator hover_background_animator_
;
153 scoped_ptr
<TrayWidgetObserver
> widget_observer_
;
154 scoped_ptr
<TrayEventFilter
> tray_event_filter_
;
156 DISALLOW_COPY_AND_ASSIGN(TrayBackgroundView
);
159 } // namespace internal
162 #endif // ASH_SYSTEM_TRAY_TRAY_BACKGROUND_VIEW_H_