| OLD | NEW |
| (Empty) |
| 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 CHROME_BROWSER_UI_VIEWS_NOTIFICATIONS_BALLOON_VIEW_VIEWS_H_ | |
| 6 #define CHROME_BROWSER_UI_VIEWS_NOTIFICATIONS_BALLOON_VIEW_VIEWS_H_ | |
| 7 | |
| 8 #include "base/basictypes.h" | |
| 9 #include "base/memory/scoped_ptr.h" | |
| 10 #include "chrome/browser/notifications/balloon.h" | |
| 11 #include "content/public/browser/notification_observer.h" | |
| 12 #include "content/public/browser/notification_registrar.h" | |
| 13 #include "ui/gfx/animation/animation_delegate.h" | |
| 14 #include "ui/gfx/rect.h" | |
| 15 #include "ui/views/controls/button/button.h" | |
| 16 #include "ui/views/controls/button/menu_button_listener.h" | |
| 17 #include "ui/views/widget/widget_delegate.h" | |
| 18 | |
| 19 class BalloonCollection; | |
| 20 class BalloonViewHost; | |
| 21 class NotificationOptionsMenuModel; | |
| 22 | |
| 23 namespace gfx { | |
| 24 class Path; | |
| 25 class SlideAnimation; | |
| 26 } | |
| 27 | |
| 28 namespace views { | |
| 29 class ImageButton; | |
| 30 class Label; | |
| 31 class MenuButton; | |
| 32 class MenuRunner; | |
| 33 } | |
| 34 | |
| 35 // A balloon view is the UI component for a desktop notification toast. | |
| 36 // It draws a border, and within the border an HTML renderer. | |
| 37 class BalloonViewImpl : public BalloonView, | |
| 38 public views::MenuButtonListener, | |
| 39 public views::WidgetDelegateView, | |
| 40 public views::ButtonListener, | |
| 41 public content::NotificationObserver, | |
| 42 public gfx::AnimationDelegate { | |
| 43 public: | |
| 44 explicit BalloonViewImpl(BalloonCollection* collection); | |
| 45 virtual ~BalloonViewImpl(); | |
| 46 | |
| 47 // BalloonView interface. | |
| 48 virtual void Show(Balloon* balloon) OVERRIDE; | |
| 49 virtual void Update() OVERRIDE; | |
| 50 virtual void RepositionToBalloon() OVERRIDE; | |
| 51 virtual void Close(bool by_user) OVERRIDE; | |
| 52 virtual gfx::Size GetSize() const OVERRIDE; | |
| 53 virtual BalloonHost* GetHost() const OVERRIDE; | |
| 54 | |
| 55 void set_enable_web_ui(bool enable) { enable_web_ui_ = enable; } | |
| 56 | |
| 57 private: | |
| 58 // views::View interface. | |
| 59 virtual void OnPaint(gfx::Canvas* canvas) OVERRIDE; | |
| 60 virtual void OnBoundsChanged(const gfx::Rect& previous_bounds) OVERRIDE; | |
| 61 virtual gfx::Size GetPreferredSize() OVERRIDE; | |
| 62 | |
| 63 // views::MenuButtonListener interface. | |
| 64 virtual void OnMenuButtonClicked(views::View* source, | |
| 65 const gfx::Point& point) OVERRIDE; | |
| 66 | |
| 67 // views::WidgetDelegate interface. | |
| 68 virtual void OnDisplayChanged() OVERRIDE; | |
| 69 virtual void OnWorkAreaChanged() OVERRIDE; | |
| 70 virtual void DeleteDelegate() OVERRIDE; | |
| 71 | |
| 72 // views::ButtonListener interface. | |
| 73 virtual void ButtonPressed(views::Button* sender, | |
| 74 const ui::Event&) OVERRIDE; | |
| 75 | |
| 76 // content::NotificationObserver interface. | |
| 77 virtual void Observe(int type, | |
| 78 const content::NotificationSource& source, | |
| 79 const content::NotificationDetails& details) OVERRIDE; | |
| 80 | |
| 81 // gfx::AnimationDelegate interface. | |
| 82 virtual void AnimationProgressed(const gfx::Animation* animation) OVERRIDE; | |
| 83 | |
| 84 // Initializes the options menu. | |
| 85 void CreateOptionsMenu(); | |
| 86 | |
| 87 // Masks the contents to fit within the frame. | |
| 88 void GetContentsMask(const gfx::Rect& contents_rect, gfx::Path* path) const; | |
| 89 | |
| 90 // Masks the frame for the rounded corners of the shadow-bubble. | |
| 91 void GetFrameMask(const gfx::Rect&, gfx::Path* path) const; | |
| 92 | |
| 93 // Adjust the contents window size to be appropriate for the frame. | |
| 94 void SizeContentsWindow(); | |
| 95 | |
| 96 // The height of the balloon's shelf. | |
| 97 // The shelf is where is close button is located. | |
| 98 int GetShelfHeight() const; | |
| 99 | |
| 100 // The height of the part of the frame around the balloon. | |
| 101 int GetBalloonFrameHeight() const; | |
| 102 | |
| 103 int GetTotalWidth() const; | |
| 104 int GetTotalHeight() const; | |
| 105 | |
| 106 gfx::Rect GetCloseButtonBounds() const; | |
| 107 gfx::Rect GetOptionsButtonBounds() const; | |
| 108 gfx::Rect GetLabelBounds() const; | |
| 109 | |
| 110 // Where the balloon contents should be placed with respect to the top left | |
| 111 // of the frame. | |
| 112 gfx::Point GetContentsOffset() const; | |
| 113 | |
| 114 // Where the balloon contents should be in screen coordinates. | |
| 115 gfx::Rect GetContentsRectangle() const; | |
| 116 | |
| 117 // Returns the bounds for the frame container. | |
| 118 gfx::Rect GetBoundsForFrameContainer() const; | |
| 119 | |
| 120 // Non-owned pointer to the balloon which owns this object. | |
| 121 Balloon* balloon_; | |
| 122 | |
| 123 // Non-owned pointer to the balloon collection this is a part of. | |
| 124 BalloonCollection* collection_; | |
| 125 | |
| 126 // The window that contains the frame of the notification. | |
| 127 // Pointer owned by the View subclass. | |
| 128 views::Widget* frame_container_; | |
| 129 | |
| 130 // The window that contains the contents of the notification. | |
| 131 // Pointer owned by the View subclass. | |
| 132 views::Widget* html_container_; | |
| 133 | |
| 134 // The renderer of the HTML contents. | |
| 135 scoped_ptr<BalloonViewHost> html_contents_; | |
| 136 | |
| 137 // Pointer to sub-view is owned by the View sub-class. | |
| 138 views::ImageButton* close_button_; | |
| 139 | |
| 140 // Pointer to sub-view is owned by View class. | |
| 141 views::Label* source_label_; | |
| 142 | |
| 143 // An animation to move the balloon on the screen as its position changes. | |
| 144 scoped_ptr<gfx::SlideAnimation> animation_; | |
| 145 gfx::Rect anim_frame_start_; | |
| 146 gfx::Rect anim_frame_end_; | |
| 147 | |
| 148 // The options menu. | |
| 149 scoped_ptr<NotificationOptionsMenuModel> options_menu_model_; | |
| 150 scoped_ptr<views::MenuRunner> menu_runner_; | |
| 151 views::MenuButton* options_menu_button_; | |
| 152 | |
| 153 content::NotificationRegistrar notification_registrar_; | |
| 154 | |
| 155 // Set to true if this is browser generate web UI. | |
| 156 bool enable_web_ui_; | |
| 157 | |
| 158 // Most recent value passed to Close(). | |
| 159 bool closed_by_user_; | |
| 160 | |
| 161 // Has Close() been invoked? Use to ensure we don't attempt to do anything | |
| 162 // once Close() has been invoked. This is important as Close() destroys state | |
| 163 // such that other BalloonView methods may crash if used after Close(). | |
| 164 bool closed_; | |
| 165 | |
| 166 DISALLOW_COPY_AND_ASSIGN(BalloonViewImpl); | |
| 167 }; | |
| 168 | |
| 169 #endif // CHROME_BROWSER_UI_VIEWS_NOTIFICATIONS_BALLOON_VIEW_VIEWS_H_ | |
| OLD | NEW |