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