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.
30 class TrayBubbleBorder;
31 class TrayBubbleContentMask;
34 class VIEWS_EXPORT TrayBubbleView : public views::BubbleDelegateView,
35 public views::MouseWatcherListener {
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).
45 // AnchorAlignment determines to which side of the anchor the bubble will
47 enum AnchorAlignment {
48 ANCHOR_ALIGNMENT_BOTTOM,
49 ANCHOR_ALIGNMENT_LEFT,
50 ANCHOR_ALIGNMENT_RIGHT,
54 class VIEWS_EXPORT Delegate {
56 typedef TrayBubbleView::AnchorType AnchorType;
57 typedef TrayBubbleView::AnchorAlignment AnchorAlignment;
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 string16 GetAccessibleNameForBubble() = 0;
76 // Passes responsibility for BubbleDelegateView::GetAnchorRect to the
78 virtual gfx::Rect GetAnchorRect(views::Widget* anchor_widget,
79 AnchorType anchor_type,
80 AnchorAlignment anchor_alignment) = 0;
82 // Called when a bubble wants to hide/destroy itself (e.g. last visible
83 // child view was closed).
84 virtual void HideBubble(const TrayBubbleView* bubble_view) = 0;
87 DISALLOW_COPY_AND_ASSIGN(Delegate);
90 struct VIEWS_EXPORT InitParams {
91 static const int kArrowDefaultOffset;
93 InitParams(AnchorType anchor_type,
94 AnchorAlignment anchor_alignment,
97 AnchorType anchor_type;
98 AnchorAlignment anchor_alignment;
103 bool close_on_deactivate;
105 bool first_item_has_no_margin;
106 views::BubbleBorder::Arrow arrow;
108 views::BubbleBorder::ArrowPaintType arrow_paint_type;
109 views::BubbleBorder::Shadow shadow;
110 views::BubbleBorder::BubbleAlignment arrow_alignment;
113 // Constructs and returns a TrayBubbleView. init_params may be modified.
114 static TrayBubbleView* Create(gfx::NativeView parent_window,
117 InitParams* init_params);
119 virtual ~TrayBubbleView();
121 // Sets up animations, and show the bubble. Must occur after CreateBubble()
123 void InitializeAndShowBubble();
125 // Called whenever the bubble size or location may have changed.
128 // Sets the maximum bubble height and resizes the bubble.
129 void SetMaxHeight(int height);
131 // Sets the bubble width.
132 void SetWidth(int width);
134 // Sets whether or not to paint the bubble border arrow.
135 void SetArrowPaintType(views::BubbleBorder::ArrowPaintType arrow_paint_type);
137 // Returns the border insets. Called by TrayEventFilter.
138 gfx::Insets GetBorderInsets() const;
140 // Called when the delegate is destroyed.
141 void reset_delegate() { delegate_ = NULL; }
143 Delegate* delegate() { return delegate_; }
145 void set_gesture_dragging(bool dragging) { is_gesture_dragging_ = dragging; }
146 bool is_gesture_dragging() const { return is_gesture_dragging_; }
148 // Overridden from views::WidgetDelegate.
149 virtual bool CanActivate() const OVERRIDE;
150 virtual views::NonClientFrameView* CreateNonClientFrameView(
151 views::Widget* widget) OVERRIDE;
152 virtual bool WidgetHasHitTestMask() const OVERRIDE;
153 virtual void GetWidgetHitTestMask(gfx::Path* mask) const OVERRIDE;
155 // Overridden from views::BubbleDelegateView.
156 virtual gfx::Rect GetAnchorRect() OVERRIDE;
158 // Overridden from views::View.
159 virtual gfx::Size GetPreferredSize() OVERRIDE;
160 virtual gfx::Size GetMaximumSize() OVERRIDE;
161 virtual int GetHeightForWidth(int width) OVERRIDE;
162 virtual void OnMouseEntered(const ui::MouseEvent& event) OVERRIDE;
163 virtual void OnMouseExited(const ui::MouseEvent& event) OVERRIDE;
164 virtual void GetAccessibleState(ui::AccessibleViewState* state) OVERRIDE;
166 // Overridden from MouseWatcherListener
167 virtual void MouseMovedOutOfHost() OVERRIDE;
170 TrayBubbleView(gfx::NativeView parent_window,
173 const InitParams& init_params);
175 // Overridden from views::BubbleDelegateView.
176 virtual void Init() OVERRIDE;
178 // Overridden from views::View.
179 virtual void ChildPreferredSizeChanged(View* child) OVERRIDE;
180 virtual void ViewHierarchyChanged(
181 const ViewHierarchyChangedDetails& details) OVERRIDE;
186 int preferred_width_;
187 internal::TrayBubbleBorder* bubble_border_;
188 scoped_ptr<internal::TrayBubbleContentMask> bubble_content_mask_;
189 bool is_gesture_dragging_;
191 // True once the mouse cursor was actively moved by the user over the bubble.
192 // Only then the OnMouseExitedView() event will get passed on to listeners.
193 bool mouse_actively_entered_;
195 // Used to find any mouse movements.
196 scoped_ptr<MouseWatcher> mouse_watcher_;
198 DISALLOW_COPY_AND_ASSIGN(TrayBubbleView);
203 #endif // UI_VIEWS_BUBBLE_TRAY_BUBBLE_VIEW_H_