Updating trunk VERSION from 2139.0 to 2140.0
[chromium-blink-merge.git] / ash / system / tray / tray_background_view.h
blobda4eaf547ce28d0d34e9b4df2c69263aab9cf3bb
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"
15 namespace ash {
16 class ShelfLayoutManager;
17 class StatusAreaWidget;
18 class TrayEventFilter;
19 class TrayBackground;
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 {
29 public:
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 {
35 public:
36 explicit TrayContainer(ShelfAlignment alignment);
37 virtual ~TrayContainer() {}
39 void SetAlignment(ShelfAlignment alignment);
41 void set_size(const gfx::Size& size) { size_ = size; }
43 // views::View:
44 virtual gfx::Size GetPreferredSize() const OVERRIDE;
46 protected:
47 // views::View:
48 virtual void ChildPreferredSizeChanged(views::View* child) OVERRIDE;
49 virtual void ChildVisibilityChanged(View* child) OVERRIDE;
50 virtual void ViewHierarchyChanged(
51 const ViewHierarchyChangedDetails& details) OVERRIDE;
53 private:
54 void UpdateLayout();
56 ShelfAlignment alignment_;
57 gfx::Size size_;
59 DISALLOW_COPY_AND_ASSIGN(TrayContainer);
62 explicit TrayBackgroundView(StatusAreaWidget* status_area_widget);
63 virtual ~TrayBackgroundView();
65 // Called after the tray has been added to the widget containing it.
66 virtual void Initialize();
68 // views::View:
69 virtual void SetVisible(bool visible) OVERRIDE;
70 virtual const char* GetClassName() const OVERRIDE;
71 virtual void OnMouseEntered(const ui::MouseEvent& event) OVERRIDE;
72 virtual void OnMouseExited(const ui::MouseEvent& event) OVERRIDE;
73 virtual void ChildPreferredSizeChanged(views::View* child) OVERRIDE;
74 virtual void GetAccessibleState(ui::AXViewState* state) OVERRIDE;
75 virtual void AboutToRequestFocusFromTabTraversal(bool reverse) OVERRIDE;
77 // ActionableView:
78 virtual bool PerformAction(const ui::Event& event) OVERRIDE;
79 virtual gfx::Rect GetFocusBounds() OVERRIDE;
81 // BackgroundAnimatorDelegate:
82 virtual void UpdateBackground(int alpha) OVERRIDE;
84 // Called whenever the shelf alignment changes.
85 virtual void SetShelfAlignment(ShelfAlignment alignment);
87 // Called when the anchor (tray or bubble) may have moved or changed.
88 virtual void AnchorUpdated() {}
90 // Called from GetAccessibleState, must return a valid accessible name.
91 virtual base::string16 GetAccessibleNameForTray() = 0;
93 // Called when the bubble is resized.
94 virtual void BubbleResized(const views::TrayBubbleView* bubble_view) {}
96 // Hides the bubble associated with |bubble_view|. Called when the widget
97 // is closed.
98 virtual void HideBubbleWithView(const views::TrayBubbleView* bubble_view) = 0;
100 // Called by the bubble wrapper when a click event occurs outside the bubble.
101 // May close the bubble. Returns true if the event is handled.
102 virtual bool ClickedOutsideBubble() = 0;
104 // Sets |contents| as a child.
105 void SetContents(views::View* contents);
107 // Creates and sets contents background to |background_|.
108 void SetContentsBackground();
110 // Sets whether the tray paints a background. Default is true, but is set to
111 // false if a window overlaps the shelf.
112 void SetPaintsBackground(bool value,
113 BackgroundAnimatorChangeType change_type);
115 // Initializes animations for the bubble.
116 void InitializeBubbleAnimations(views::Widget* bubble_widget);
118 // Returns the window hosting the bubble.
119 aura::Window* GetBubbleWindowContainer() const;
121 // Returns the anchor rect for the bubble.
122 gfx::Rect GetBubbleAnchorRect(
123 views::Widget* anchor_widget,
124 views::TrayBubbleView::AnchorType anchor_type,
125 views::TrayBubbleView::AnchorAlignment anchor_alignment) const;
127 // Returns the bubble anchor alignment based on |shelf_alignment_|.
128 views::TrayBubbleView::AnchorAlignment GetAnchorAlignment() const;
130 // Forces the background to be drawn active if set to true.
131 void SetDrawBackgroundAsActive(bool visible);
133 // Returns true when the the background was overridden to be drawn as active.
134 bool draw_background_as_active() const {return draw_background_as_active_; }
136 StatusAreaWidget* status_area_widget() {
137 return status_area_widget_;
139 const StatusAreaWidget* status_area_widget() const {
140 return status_area_widget_;
142 TrayContainer* tray_container() const { return tray_container_; }
143 ShelfAlignment shelf_alignment() const { return shelf_alignment_; }
144 TrayEventFilter* tray_event_filter() { return tray_event_filter_.get(); }
146 ShelfLayoutManager* GetShelfLayoutManager();
148 // Updates the arrow visibility based on the launcher visibility.
149 void UpdateBubbleViewArrow(views::TrayBubbleView* bubble_view);
151 private:
152 class TrayWidgetObserver;
154 // Called from Initialize after all status area trays have been created.
155 // Sets the border based on the position of the view.
156 void SetTrayBorder();
158 // ui::ImplicitAnimationObserver:
159 virtual void OnImplicitAnimationsCompleted() OVERRIDE;
161 // Applies transformations to the |layer()| to animate the view when
162 // SetVisible(false) is called.
163 void HideTransformation();
165 // Unowned pointer to parent widget.
166 StatusAreaWidget* status_area_widget_;
168 // Convenience pointer to the contents view.
169 TrayContainer* tray_container_;
171 // Shelf alignment.
172 ShelfAlignment shelf_alignment_;
174 // Owned by the view passed to SetContents().
175 TrayBackground* background_;
177 // Animators for the background. They are only used for the old shelf layout.
178 BackgroundAnimator hide_background_animator_;
179 BackgroundAnimator hover_background_animator_;
181 // True if the background gets hovered.
182 bool hovered_;
184 // This variable stores the activation override which will tint the background
185 // differently if set to true.
186 bool draw_background_as_active_;
188 scoped_ptr<TrayWidgetObserver> widget_observer_;
189 scoped_ptr<TrayEventFilter> tray_event_filter_;
191 DISALLOW_COPY_AND_ASSIGN(TrayBackgroundView);
194 } // namespace ash
196 #endif // ASH_SYSTEM_TRAY_TRAY_BACKGROUND_VIEW_H_