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 base::string16
GetAccessibleNameForBubble() = 0;
76 // Passes responsibility for BubbleDelegateView::GetAnchorRect to the
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;
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
,
98 AnchorType anchor_type
;
99 AnchorAlignment anchor_alignment
;
104 bool close_on_deactivate
;
106 bool first_item_has_no_margin
;
107 views::BubbleBorder::Arrow arrow
;
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
,
118 InitParams
* init_params
);
120 ~TrayBubbleView() override
;
122 // Sets up animations, and show the bubble. Must occur after CreateBubble()
124 void InitializeAndShowBubble();
126 // Called whenever the bubble size or location may have changed.
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 bool CanActivate() const override
;
151 views::NonClientFrameView
* CreateNonClientFrameView(
152 views::Widget
* widget
) override
;
153 bool WidgetHasHitTestMask() const override
;
154 void GetWidgetHitTestMask(gfx::Path
* mask
) const override
;
156 // Overridden from views::BubbleDelegateView.
157 gfx::Rect
GetAnchorRect() const override
;
159 // Overridden from views::View.
160 gfx::Size
GetPreferredSize() const override
;
161 gfx::Size
GetMaximumSize() const override
;
162 int GetHeightForWidth(int width
) const override
;
163 void OnMouseEntered(const ui::MouseEvent
& event
) override
;
164 void OnMouseExited(const ui::MouseEvent
& event
) override
;
165 void GetAccessibleState(ui::AXViewState
* state
) override
;
167 // Overridden from MouseWatcherListener
168 void MouseMovedOutOfHost() override
;
171 TrayBubbleView(gfx::NativeView parent_window
,
174 const InitParams
& init_params
);
176 // Overridden from views::BubbleDelegateView.
177 void Init() override
;
179 // Overridden from views::View.
180 void ChildPreferredSizeChanged(View
* child
) override
;
181 void ViewHierarchyChanged(
182 const ViewHierarchyChangedDetails
& details
) override
;
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
);
204 #endif // UI_VIEWS_BUBBLE_TRAY_BUBBLE_VIEW_H_