balloon_view.h revision c407dc5cd9bdc5668497f21b26b09d988ab439de
1// Copyright (c) 2010 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// Draws the view for the balloons. 6 7#ifndef CHROME_BROWSER_CHROMEOS_NOTIFICATIONS_BALLOON_VIEW_H_ 8#define CHROME_BROWSER_CHROMEOS_NOTIFICATIONS_BALLOON_VIEW_H_ 9 10#include "base/basictypes.h" 11#include "base/scoped_ptr.h" 12#include "base/task.h" 13#include "chrome/browser/notifications/balloon.h" 14#include "chrome/common/notification_registrar.h" 15#include "chrome/common/notification_service.h" 16#include "gfx/path.h" 17#include "gfx/point.h" 18#include "gfx/rect.h" 19#include "gfx/size.h" 20#include "views/view.h" 21 22namespace views { 23class Menu2; 24class MenuButton; 25class MouseEvent; 26class TextButton; 27class WidgetGtk; 28} // namespace views 29 30class BalloonViewHost; 31class Notification; 32class NotificationDetails; 33class NotificationSource; 34 35namespace chromeos { 36 37class NotificationControlView; 38 39// A balloon view is the UI component for a notification panel. 40class BalloonViewImpl : public BalloonView, 41 public views::View, 42 public NotificationObserver { 43 public: 44 BalloonViewImpl(bool sticky, bool controls); 45 ~BalloonViewImpl(); 46 47 // views::View interface. 48 virtual void Layout(); 49 virtual void ViewHierarchyChanged(bool is_add, View* parent, View* child); 50 51 // BalloonView interface. 52 virtual void Show(Balloon* balloon); 53 virtual void Update(); 54 virtual void Close(bool by_user); 55 virtual void RepositionToBalloon(); 56 gfx::Size GetSize() const; 57 virtual BalloonHost* GetHost() const; 58 59 // True if the notification is stale. False if the notification is new. 60 bool stale() const { return stale_; } 61 62 // Makes the notification stale. 63 void set_stale() { stale_ = true; } 64 65 // True if the notification is sticky. 66 bool sticky() const { return sticky_; } 67 68 // True if the notification is being closed. 69 bool closed() const { return closed_; } 70 71 // True if the balloon is for the given |notification|. 72 bool IsFor(const Notification& notification) const; 73 74 // Called when the notification becomes active (mouse is on). 75 void Activated(); 76 77 // Called when the notification becomes inactive. 78 void Deactivated(); 79 80 private: 81 friend class NotificationControlView; 82 83 // views::View interface. 84 virtual gfx::Size GetPreferredSize() { 85 return gfx::Size(1000, 1000); 86 } 87 88 // NotificationObserver interface. 89 virtual void Observe(NotificationType type, 90 const NotificationSource& source, 91 const NotificationDetails& details); 92 93 // Initializes the options menu. 94 void CreateOptionsMenu(); 95 96 // Do the delayed close work. 97 void DelayedClose(bool by_user); 98 99 // Denies the permission to show the ballooon from its source. 100 void DenyPermission(); 101 102 // Returns the renderer's native view. 103 gfx::NativeView GetParentNativeView(); 104 105 // Non-owned pointer to the balloon which owns this object. 106 Balloon* balloon_; 107 108 // The renderer of the HTML contents. Pointer owned by the views hierarchy. 109 BalloonViewHost* html_contents_; 110 111 // The following factory is used to call methods at a later time. 112 ScopedRunnableMethodFactory<BalloonViewImpl> method_factory_; 113 114 // A widget for ControlView. 115 scoped_ptr<views::WidgetGtk> control_view_host_; 116 117 bool stale_; 118 NotificationRegistrar notification_registrar_; 119 // A sticky flag. A sticky notification cannot be dismissed by a user. 120 bool sticky_; 121 // True if a notification should have info/option/dismiss label/buttons. 122 bool controls_; 123 // True if the notification is being closed. 124 bool closed_; 125 126 DISALLOW_COPY_AND_ASSIGN(BalloonViewImpl); 127}; 128 129} // namespace chromeos 130 131#endif // CHROME_BROWSER_CHROMEOS_NOTIFICATIONS_BALLOON_VIEW_H_ 132