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_MESSAGE_CENTER_VIEWS_MESSAGE_BUBBLE_BASE_H_ 6 #define UI_MESSAGE_CENTER_VIEWS_MESSAGE_BUBBLE_BASE_H_ 7 8 #include "base/memory/scoped_ptr.h" 9 #include "ui/message_center/message_center.h" 10 #include "ui/message_center/message_center_export.h" 11 #include "ui/views/bubble/tray_bubble_view.h" 12 13 namespace message_center { 14 class MessageCenterTray; 15 16 class MESSAGE_CENTER_EXPORT MessageBubbleBase { 17 public: 18 MessageBubbleBase(MessageCenter* message_center, MessageCenterTray* tray); 19 20 virtual ~MessageBubbleBase(); 21 22 // Gets called when the bubble view associated with this bubble is 23 // destroyed. Clears |bubble_view_| and calls OnBubbleViewDestroyed. 24 void BubbleViewDestroyed(); 25 26 // Sets/Gets the maximum height of the bubble view. Setting 0 changes the 27 // bubble to the default size. max_height() will return the default size 28 // if SetMaxHeight() has not been called yet. 29 void SetMaxHeight(int height); max_height()30 int max_height() const { return max_height_; } 31 32 // Gets the init params for the implementation. 33 virtual views::TrayBubbleView::InitParams GetInitParams( 34 views::TrayBubbleView::AnchorAlignment anchor_alignment) = 0; 35 36 // Called after the bubble view has been constructed. Creates and initializes 37 // the bubble contents. 38 virtual void InitializeContents(views::TrayBubbleView* bubble_view) = 0; 39 40 // Called from BubbleViewDestroyed for implementation specific details. 41 virtual void OnBubbleViewDestroyed() = 0; 42 43 // Updates the bubble; implementation dependent. 44 virtual void UpdateBubbleView() = 0; 45 46 // Called when the mouse enters/exists the view. 47 virtual void OnMouseEnteredView() = 0; 48 virtual void OnMouseExitedView() = 0; 49 50 // Schedules bubble for layout after all notifications have been 51 // added and icons have had a chance to load. 52 void ScheduleUpdate(); 53 54 bool IsVisible() const; 55 bubble_view()56 views::TrayBubbleView* bubble_view() const { return bubble_view_; } 57 58 static const SkColor kBackgroundColor; 59 60 protected: 61 views::TrayBubbleView::InitParams GetDefaultInitParams( 62 views::TrayBubbleView::AnchorAlignment anchor_alignment); message_center()63 MessageCenter* message_center() { return message_center_; } tray()64 MessageCenterTray* tray() { return tray_; } set_bubble_view(views::TrayBubbleView * bubble_view)65 void set_bubble_view(views::TrayBubbleView* bubble_view) { 66 bubble_view_ = bubble_view; 67 } 68 69 private: 70 MessageCenter* message_center_; 71 MessageCenterTray* tray_; 72 views::TrayBubbleView* bubble_view_; 73 int max_height_; 74 base::WeakPtrFactory<MessageBubbleBase> weak_ptr_factory_; 75 76 DISALLOW_COPY_AND_ASSIGN(MessageBubbleBase); 77 }; 78 79 } // namespace message_center 80 81 #endif // UI_MESSAGE_CENTER_VIEWS_MESSAGE_BUBBLE_BASE_H_ 82