365e63a05d308f2275a88420718dda459f899254
[platform/framework/web/crosswalk.git] / src / ash / system / tray / tray_background_view.h
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_SYSTEM_TRAY_TRAY_BACKGROUND_VIEW_H_
6 #define ASH_SYSTEM_TRAY_TRAY_BACKGROUND_VIEW_H_
7
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"
13
14 namespace ash {
15 class ShelfLayoutManager;
16 class StatusAreaWidget;
17 class TrayEventFilter;
18 class TrayBackground;
19
20 // Base class for children of StatusAreaWidget: SystemTray, WebNotificationTray,
21 // LogoutButtonTray.
22 // This class handles setting and animating the background when the Launcher
23 // his shown/hidden. It also inherits from ActionableView so that the tray
24 // items can override PerformAction when clicked on.
25 class ASH_EXPORT TrayBackgroundView : public ActionableView,
26                                       public BackgroundAnimatorDelegate {
27  public:
28   static const char kViewClassName[];
29
30   // Base class for tray containers. Sets the border and layout. The container
31   // auto-resizes the widget when necessary.
32   class TrayContainer : public views::View {
33    public:
34     explicit TrayContainer(ShelfAlignment alignment);
35     virtual ~TrayContainer() {}
36
37     void SetAlignment(ShelfAlignment alignment);
38
39     void set_size(const gfx::Size& size) { size_ = size; }
40
41     // Overridden from views::View.
42     virtual gfx::Size GetPreferredSize() OVERRIDE;
43
44    protected:
45     // Overridden from views::View.
46     virtual void ChildPreferredSizeChanged(views::View* child) OVERRIDE;
47     virtual void ChildVisibilityChanged(View* child) OVERRIDE;
48     virtual void ViewHierarchyChanged(
49         const ViewHierarchyChangedDetails& details) OVERRIDE;
50
51    private:
52     void UpdateLayout();
53
54     ShelfAlignment alignment_;
55     gfx::Size size_;
56
57     DISALLOW_COPY_AND_ASSIGN(TrayContainer);
58   };
59
60   explicit TrayBackgroundView(StatusAreaWidget* status_area_widget);
61   virtual ~TrayBackgroundView();
62
63   // Called after the tray has been added to the widget containing it.
64   virtual void Initialize();
65
66   // Overridden from views::View.
67   virtual const char* GetClassName() const OVERRIDE;
68   virtual void OnMouseEntered(const ui::MouseEvent& event) OVERRIDE;
69   virtual void OnMouseExited(const ui::MouseEvent& event) OVERRIDE;
70   virtual void ChildPreferredSizeChanged(views::View* child) OVERRIDE;
71   virtual void GetAccessibleState(ui::AXViewState* state) OVERRIDE;
72   virtual void AboutToRequestFocusFromTabTraversal(bool reverse) OVERRIDE;
73
74   // Overridden from ActionableView.
75   virtual bool PerformAction(const ui::Event& event) OVERRIDE;
76   virtual gfx::Rect GetFocusBounds() OVERRIDE;
77
78   // Overridden from BackgroundAnimatorDelegate.
79   virtual void UpdateBackground(int alpha) OVERRIDE;
80
81   // Called whenever the shelf alignment changes.
82   virtual void SetShelfAlignment(ShelfAlignment alignment);
83
84   // Called when the anchor (tray or bubble) may have moved or changed.
85   virtual void AnchorUpdated() {}
86
87   // Called from GetAccessibleState, must return a valid accessible name.
88   virtual base::string16 GetAccessibleNameForTray() = 0;
89
90   // Called when the bubble is resized.
91   virtual void BubbleResized(const views::TrayBubbleView* bubble_view) {}
92
93   // Hides the bubble associated with |bubble_view|. Called when the widget
94   // is closed.
95   virtual void HideBubbleWithView(const views::TrayBubbleView* bubble_view) = 0;
96
97   // Called by the bubble wrapper when a click event occurs outside the bubble.
98   // May close the bubble. Returns true if the event is handled.
99   virtual bool ClickedOutsideBubble() = 0;
100
101   // Sets |contents| as a child.
102   void SetContents(views::View* contents);
103
104   // Creates and sets contents background to |background_|.
105   void SetContentsBackground();
106
107   // Sets whether the tray paints a background. Default is true, but is set to
108   // false if a window overlaps the shelf.
109   void SetPaintsBackground(bool value,
110                            BackgroundAnimatorChangeType change_type);
111
112   // Initializes animations for the bubble.
113   void InitializeBubbleAnimations(views::Widget* bubble_widget);
114
115   // Returns the window hosting the bubble.
116   aura::Window* GetBubbleWindowContainer() const;
117
118   // Returns the anchor rect for the bubble.
119   gfx::Rect GetBubbleAnchorRect(
120       views::Widget* anchor_widget,
121       views::TrayBubbleView::AnchorType anchor_type,
122       views::TrayBubbleView::AnchorAlignment anchor_alignment) const;
123
124   // Returns the bubble anchor alignment based on |shelf_alignment_|.
125   views::TrayBubbleView::AnchorAlignment GetAnchorAlignment() const;
126
127   // Forces the background to be drawn active if set to true.
128   void SetDrawBackgroundAsActive(bool visible);
129
130   // Returns true when the the background was overridden to be drawn as active.
131   bool draw_background_as_active() const {return draw_background_as_active_; }
132
133   StatusAreaWidget* status_area_widget() {
134     return status_area_widget_;
135   }
136   const StatusAreaWidget* status_area_widget() const {
137     return status_area_widget_;
138   }
139   TrayContainer* tray_container() const { return tray_container_; }
140   ShelfAlignment shelf_alignment() const { return shelf_alignment_; }
141   TrayEventFilter* tray_event_filter() { return tray_event_filter_.get(); }
142
143   ShelfLayoutManager* GetShelfLayoutManager();
144
145   // Updates the arrow visibility based on the launcher visibility.
146   void UpdateBubbleViewArrow(views::TrayBubbleView* bubble_view);
147
148  private:
149   class TrayWidgetObserver;
150
151   // Called from Initialize after all status area trays have been created.
152   // Sets the border based on the position of the view.
153   void SetTrayBorder();
154
155   // Unowned pointer to parent widget.
156   StatusAreaWidget* status_area_widget_;
157
158   // Convenience pointer to the contents view.
159   TrayContainer* tray_container_;
160
161   // Shelf alignment.
162   ShelfAlignment shelf_alignment_;
163
164   // Owned by the view passed to SetContents().
165   TrayBackground* background_;
166
167   // Animators for the background. They are only used for the old shelf layout.
168   BackgroundAnimator hide_background_animator_;
169   BackgroundAnimator hover_background_animator_;
170
171   // True if the background gets hovered.
172   bool hovered_;
173
174   // This variable stores the activation override which will tint the background
175   // differently if set to true.
176   bool draw_background_as_active_;
177
178   scoped_ptr<TrayWidgetObserver> widget_observer_;
179   scoped_ptr<TrayEventFilter> tray_event_filter_;
180
181   DISALLOW_COPY_AND_ASSIGN(TrayBackgroundView);
182 };
183
184 }  // namespace ash
185
186 #endif  // ASH_SYSTEM_TRAY_TRAY_BACKGROUND_VIEW_H_