Updating trunk VERSION from 2139.0 to 2140.0
[chromium-blink-merge.git] / ui / views / bubble / tray_bubble_view.h
blob54f6cc880338051975c5a0d131f4025fe9fd00bc
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 UI_VIEWS_BUBBLE_TRAY_BUBBLE_VIEW_H_
6 #define UI_VIEWS_BUBBLE_TRAY_BUBBLE_VIEW_H_
8 #include "base/memory/scoped_ptr.h"
9 #include "ui/views/bubble/bubble_delegate.h"
10 #include "ui/views/mouse_watcher.h"
11 #include "ui/views/views_export.h"
13 // Specialized bubble view for bubbles associated with a tray icon (e.g. the
14 // Ash status area). Mostly this handles custom anchor location and arrow and
15 // border rendering. This also has its own delegate for handling mouse events
16 // and other implementation specific details.
18 namespace ui {
19 class LocatedEvent;
22 namespace views {
23 class View;
24 class Widget;
27 namespace views {
29 namespace internal {
30 class TrayBubbleBorder;
31 class TrayBubbleContentMask;
34 class VIEWS_EXPORT TrayBubbleView : public views::BubbleDelegateView,
35 public views::MouseWatcherListener {
36 public:
37 // AnchorType differentiates between bubbles that are anchored on a tray
38 // element (ANCHOR_TYPE_TRAY) and display an arrow, or that are floating on
39 // the screen away from the tray (ANCHOR_TYPE_BUBBLE).
40 enum AnchorType {
41 ANCHOR_TYPE_TRAY,
42 ANCHOR_TYPE_BUBBLE,
45 // AnchorAlignment determines to which side of the anchor the bubble will
46 // align itself.
47 enum AnchorAlignment {
48 ANCHOR_ALIGNMENT_BOTTOM,
49 ANCHOR_ALIGNMENT_LEFT,
50 ANCHOR_ALIGNMENT_RIGHT,
51 ANCHOR_ALIGNMENT_TOP
54 class VIEWS_EXPORT Delegate {
55 public:
56 typedef TrayBubbleView::AnchorType AnchorType;
57 typedef TrayBubbleView::AnchorAlignment AnchorAlignment;
59 Delegate() {}
60 virtual ~Delegate() {}
62 // Called when the view is destroyed. Any pointers to the view should be
63 // cleared when this gets called.
64 virtual void BubbleViewDestroyed() = 0;
66 // Called when the mouse enters/exits the view.
67 // Note: This event will only be called if the mouse gets actively moved by
68 // the user to enter the view.
69 virtual void OnMouseEnteredView() = 0;
70 virtual void OnMouseExitedView() = 0;
72 // Called from GetAccessibleState(); should return the appropriate
73 // accessible name for the bubble.
74 virtual base::string16 GetAccessibleNameForBubble() = 0;
76 // Passes responsibility for BubbleDelegateView::GetAnchorRect to the
77 // delegate.
78 virtual gfx::Rect GetAnchorRect(
79 views::Widget* anchor_widget,
80 AnchorType anchor_type,
81 AnchorAlignment anchor_alignment) const = 0;
83 // Called when a bubble wants to hide/destroy itself (e.g. last visible
84 // child view was closed).
85 virtual void HideBubble(const TrayBubbleView* bubble_view) = 0;
87 private:
88 DISALLOW_COPY_AND_ASSIGN(Delegate);
91 struct VIEWS_EXPORT InitParams {
92 static const int kArrowDefaultOffset;
94 InitParams(AnchorType anchor_type,
95 AnchorAlignment anchor_alignment,
96 int min_width,
97 int max_width);
98 AnchorType anchor_type;
99 AnchorAlignment anchor_alignment;
100 int min_width;
101 int max_width;
102 int max_height;
103 bool can_activate;
104 bool close_on_deactivate;
105 SkColor arrow_color;
106 bool first_item_has_no_margin;
107 views::BubbleBorder::Arrow arrow;
108 int arrow_offset;
109 views::BubbleBorder::ArrowPaintType arrow_paint_type;
110 views::BubbleBorder::Shadow shadow;
111 views::BubbleBorder::BubbleAlignment arrow_alignment;
114 // Constructs and returns a TrayBubbleView. init_params may be modified.
115 static TrayBubbleView* Create(gfx::NativeView parent_window,
116 views::View* anchor,
117 Delegate* delegate,
118 InitParams* init_params);
120 virtual ~TrayBubbleView();
122 // Sets up animations, and show the bubble. Must occur after CreateBubble()
123 // is called.
124 void InitializeAndShowBubble();
126 // Called whenever the bubble size or location may have changed.
127 void UpdateBubble();
129 // Sets the maximum bubble height and resizes the bubble.
130 void SetMaxHeight(int height);
132 // Sets the bubble width.
133 void SetWidth(int width);
135 // Sets whether or not to paint the bubble border arrow.
136 void SetArrowPaintType(views::BubbleBorder::ArrowPaintType arrow_paint_type);
138 // Returns the border insets. Called by TrayEventFilter.
139 gfx::Insets GetBorderInsets() const;
141 // Called when the delegate is destroyed.
142 void reset_delegate() { delegate_ = NULL; }
144 Delegate* delegate() { return delegate_; }
146 void set_gesture_dragging(bool dragging) { is_gesture_dragging_ = dragging; }
147 bool is_gesture_dragging() const { return is_gesture_dragging_; }
149 // Overridden from views::WidgetDelegate.
150 virtual bool CanActivate() const OVERRIDE;
151 virtual views::NonClientFrameView* CreateNonClientFrameView(
152 views::Widget* widget) OVERRIDE;
153 virtual bool WidgetHasHitTestMask() const OVERRIDE;
154 virtual void GetWidgetHitTestMask(gfx::Path* mask) const OVERRIDE;
156 // Overridden from views::BubbleDelegateView.
157 virtual gfx::Rect GetAnchorRect() const OVERRIDE;
159 // Overridden from views::View.
160 virtual gfx::Size GetPreferredSize() const OVERRIDE;
161 virtual gfx::Size GetMaximumSize() const OVERRIDE;
162 virtual int GetHeightForWidth(int width) const OVERRIDE;
163 virtual void OnMouseEntered(const ui::MouseEvent& event) OVERRIDE;
164 virtual void OnMouseExited(const ui::MouseEvent& event) OVERRIDE;
165 virtual void GetAccessibleState(ui::AXViewState* state) OVERRIDE;
167 // Overridden from MouseWatcherListener
168 virtual void MouseMovedOutOfHost() OVERRIDE;
170 protected:
171 TrayBubbleView(gfx::NativeView parent_window,
172 views::View* anchor,
173 Delegate* delegate,
174 const InitParams& init_params);
176 // Overridden from views::BubbleDelegateView.
177 virtual void Init() OVERRIDE;
179 // Overridden from views::View.
180 virtual void ChildPreferredSizeChanged(View* child) OVERRIDE;
181 virtual void ViewHierarchyChanged(
182 const ViewHierarchyChangedDetails& details) OVERRIDE;
184 private:
185 InitParams params_;
186 Delegate* delegate_;
187 int preferred_width_;
188 internal::TrayBubbleBorder* bubble_border_;
189 scoped_ptr<internal::TrayBubbleContentMask> bubble_content_mask_;
190 bool is_gesture_dragging_;
192 // True once the mouse cursor was actively moved by the user over the bubble.
193 // Only then the OnMouseExitedView() event will get passed on to listeners.
194 bool mouse_actively_entered_;
196 // Used to find any mouse movements.
197 scoped_ptr<MouseWatcher> mouse_watcher_;
199 DISALLOW_COPY_AND_ASSIGN(TrayBubbleView);
202 } // namespace views
204 #endif // UI_VIEWS_BUBBLE_TRAY_BUBBLE_VIEW_H_