diff options
-rw-r--r-- | chrome/browser/cocoa/notifications/balloon_controller_unittest.mm | 1 | ||||
-rw-r--r-- | chrome/browser/gtk/notifications/balloon_view_gtk.cc | 2 | ||||
-rw-r--r-- | chrome/browser/gtk/notifications/balloon_view_gtk.h | 4 | ||||
-rw-r--r-- | chrome/browser/notifications/balloon_collection.cc | 5 | ||||
-rw-r--r-- | chrome/browser/notifications/balloon_collection.h | 3 | ||||
-rw-r--r-- | chrome/browser/notifications/balloon_collection_impl.h | 1 | ||||
-rw-r--r-- | chrome/browser/notifications/balloon_collection_linux.cc | 2 | ||||
-rw-r--r-- | chrome/browser/notifications/balloon_collection_win.cc | 2 | ||||
-rw-r--r-- | chrome/browser/notifications/desktop_notifications_unittest.h | 1 | ||||
-rw-r--r-- | chrome/browser/views/notifications/balloon_view.cc | 9 | ||||
-rw-r--r-- | chrome/browser/views/notifications/balloon_view.h | 11 | ||||
-rw-r--r-- | views/widget/widget.h | 7 | ||||
-rwxr-xr-x | views/widget/widget_delegate.h | 23 | ||||
-rw-r--r-- | views/widget/widget_gtk.cc | 11 | ||||
-rw-r--r-- | views/widget/widget_gtk.h | 6 | ||||
-rw-r--r-- | views/widget/widget_win.cc | 17 | ||||
-rw-r--r-- | views/widget/widget_win.h | 8 |
17 files changed, 104 insertions, 9 deletions
diff --git a/chrome/browser/cocoa/notifications/balloon_controller_unittest.mm b/chrome/browser/cocoa/notifications/balloon_controller_unittest.mm index bd5d1cd..d9f9c8f 100644 --- a/chrome/browser/cocoa/notifications/balloon_controller_unittest.mm +++ b/chrome/browser/cocoa/notifications/balloon_controller_unittest.mm @@ -21,6 +21,7 @@ class MockBalloonCollection : public BalloonCollection { virtual bool Remove(const Notification& notification) { return false; } virtual bool HasSpace() const { return true; } virtual void ResizeBalloon(Balloon* balloon, const gfx::Size& size) {}; + virtual void DisplayChanged() {} virtual void OnBalloonClosed(Balloon* source) {}; }; diff --git a/chrome/browser/gtk/notifications/balloon_view_gtk.cc b/chrome/browser/gtk/notifications/balloon_view_gtk.cc index dbae12a..e022b5e 100644 --- a/chrome/browser/gtk/notifications/balloon_view_gtk.cc +++ b/chrome/browser/gtk/notifications/balloon_view_gtk.cc @@ -83,7 +83,7 @@ const int kDefaultShelfHeight = 24; } // namespace -BalloonViewImpl::BalloonViewImpl() +BalloonViewImpl::BalloonViewImpl(BalloonCollection* collection) : balloon_(NULL), frame_container_(NULL), html_container_(NULL), diff --git a/chrome/browser/gtk/notifications/balloon_view_gtk.h b/chrome/browser/gtk/notifications/balloon_view_gtk.h index b0cf8ed..a6ea598 100644 --- a/chrome/browser/gtk/notifications/balloon_view_gtk.h +++ b/chrome/browser/gtk/notifications/balloon_view_gtk.h @@ -18,7 +18,7 @@ #include "chrome/common/notification_observer.h" #include "chrome/common/notification_registrar.h" - +class BalloonCollection; class BalloonViewHost; class MenuGtk; class NineBox; @@ -34,7 +34,7 @@ class BalloonViewImpl : public BalloonView, public NotificationObserver, public AnimationDelegate { public: - BalloonViewImpl(); + explicit BalloonViewImpl(BalloonCollection* collection); ~BalloonViewImpl(); // BalloonView interface. diff --git a/chrome/browser/notifications/balloon_collection.cc b/chrome/browser/notifications/balloon_collection.cc index b8b7e9f..3d516ef 100644 --- a/chrome/browser/notifications/balloon_collection.cc +++ b/chrome/browser/notifications/balloon_collection.cc @@ -90,6 +90,11 @@ void BalloonCollectionImpl::ResizeBalloon(Balloon* balloon, PositionBalloons(true); } +void BalloonCollectionImpl::DisplayChanged() { + layout_.RefreshSystemMetrics(); + PositionBalloons(true); +} + void BalloonCollectionImpl::OnBalloonClosed(Balloon* source) { // We want to free the balloon when finished. scoped_ptr<Balloon> closed(source); diff --git a/chrome/browser/notifications/balloon_collection.h b/chrome/browser/notifications/balloon_collection.h index ff37a12..998142b 100644 --- a/chrome/browser/notifications/balloon_collection.h +++ b/chrome/browser/notifications/balloon_collection.h @@ -48,6 +48,9 @@ class BalloonCollection { // Request the resizing of a balloon. virtual void ResizeBalloon(Balloon* balloon, const gfx::Size& size) = 0; + // Update for new screen dimensions. + virtual void DisplayChanged() = 0; + // Inform the collection that a balloon was closed. virtual void OnBalloonClosed(Balloon* source) = 0; diff --git a/chrome/browser/notifications/balloon_collection_impl.h b/chrome/browser/notifications/balloon_collection_impl.h index c8eef59..ba54b51 100644 --- a/chrome/browser/notifications/balloon_collection_impl.h +++ b/chrome/browser/notifications/balloon_collection_impl.h @@ -29,6 +29,7 @@ class BalloonCollectionImpl : public BalloonCollection { virtual bool Remove(const Notification& notification); virtual bool HasSpace() const; virtual void ResizeBalloon(Balloon* balloon, const gfx::Size& size); + virtual void DisplayChanged(); virtual void OnBalloonClosed(Balloon* source); protected: diff --git a/chrome/browser/notifications/balloon_collection_linux.cc b/chrome/browser/notifications/balloon_collection_linux.cc index 5d0c2b7..54cd7ee 100644 --- a/chrome/browser/notifications/balloon_collection_linux.cc +++ b/chrome/browser/notifications/balloon_collection_linux.cc @@ -12,7 +12,7 @@ Balloon* BalloonCollectionImpl::MakeBalloon(const Notification& notification, Profile* profile) { Balloon* balloon = new Balloon(notification, profile, this); - balloon->set_view(new BalloonViewImpl()); + balloon->set_view(new BalloonViewImpl(this)); gfx::Size size(layout_.min_balloon_width(), layout_.min_balloon_height()); balloon->set_content_size(size); return balloon; diff --git a/chrome/browser/notifications/balloon_collection_win.cc b/chrome/browser/notifications/balloon_collection_win.cc index 405ea04..e8b60e0 100644 --- a/chrome/browser/notifications/balloon_collection_win.cc +++ b/chrome/browser/notifications/balloon_collection_win.cc @@ -11,7 +11,7 @@ Balloon* BalloonCollectionImpl::MakeBalloon(const Notification& notification, Profile* profile) { Balloon* balloon = new Balloon(notification, profile, this); - balloon->set_view(new BalloonViewImpl()); + balloon->set_view(new BalloonViewImpl(this)); gfx::Size size(layout_.min_balloon_width(), layout_.min_balloon_height()); balloon->set_content_size(size); return balloon; diff --git a/chrome/browser/notifications/desktop_notifications_unittest.h b/chrome/browser/notifications/desktop_notifications_unittest.h index 927e519..54131e5 100644 --- a/chrome/browser/notifications/desktop_notifications_unittest.h +++ b/chrome/browser/notifications/desktop_notifications_unittest.h @@ -71,6 +71,7 @@ class MockBalloonCollection : public BalloonCollectionImpl { virtual bool HasSpace() const { return count() < kMockBalloonSpace; } virtual Balloon* MakeBalloon(const Notification& notification, Profile* profile); + virtual void DisplayChanged() {} virtual void OnBalloonClosed(Balloon* source); // Number of balloons being shown. diff --git a/chrome/browser/views/notifications/balloon_view.cc b/chrome/browser/views/notifications/balloon_view.cc index f101669..9292de4 100644 --- a/chrome/browser/views/notifications/balloon_view.cc +++ b/chrome/browser/views/notifications/balloon_view.cc @@ -15,6 +15,7 @@ #include "base/string_util.h" #include "chrome/browser/browser_theme_provider.h" #include "chrome/browser/notifications/balloon.h" +#include "chrome/browser/notifications/balloon_collection.h" #include "chrome/browser/notifications/desktop_notification_service.h" #include "chrome/browser/profile.h" #include "chrome/browser/renderer_host/render_view_host.h" @@ -95,8 +96,9 @@ class BalloonCloseButtonListener : public views::ButtonListener { BalloonView* view_; }; -BalloonViewImpl::BalloonViewImpl() +BalloonViewImpl::BalloonViewImpl(BalloonCollection* collection) : balloon_(NULL), + collection_(collection), frame_container_(NULL), html_container_(NULL), html_contents_(NULL), @@ -148,6 +150,10 @@ void BalloonViewImpl::RunMenu(views::View* source, const gfx::Point& pt) { RunOptionsMenu(pt); } +void BalloonViewImpl::DisplayChanged() { + collection_->DisplayChanged(); +} + void BalloonViewImpl::DelayedClose(bool by_user) { html_contents_->Shutdown(); html_container_->CloseNow(); @@ -315,6 +321,7 @@ void BalloonViewImpl::Show(Balloon* balloon) { frame_container_ = Widget::CreatePopupWidget(Widget::Transparent, Widget::AcceptEvents, Widget::DeleteOnDestroy); + frame_container_->SetWidgetDelegate(this); frame_container_->SetAlwaysOnTop(true); frame_container_->Init(NULL, balloon_rect); frame_container_->SetContentsView(this); diff --git a/chrome/browser/views/notifications/balloon_view.h b/chrome/browser/views/notifications/balloon_view.h index 84147ad..6d8da54 100644 --- a/chrome/browser/views/notifications/balloon_view.h +++ b/chrome/browser/views/notifications/balloon_view.h @@ -23,6 +23,7 @@ #include "views/controls/label.h" #include "views/controls/menu/view_menu_delegate.h" #include "views/view.h" +#include "views/widget/widget_delegate.h" namespace views { class ButtonListener; @@ -32,6 +33,7 @@ class WidgetWin; class Menu2; } // namespace views +class BalloonCollection; class BalloonViewHost; class NotificationDetails; class NotificationSource; @@ -42,11 +44,12 @@ class SlideAnimation; class BalloonViewImpl : public BalloonView, public views::View, public views::ViewMenuDelegate, + public views::WidgetDelegate, public menus::SimpleMenuModel::Delegate, public NotificationObserver, public AnimationDelegate { public: - BalloonViewImpl(); + explicit BalloonViewImpl(BalloonCollection* collection); ~BalloonViewImpl(); // BalloonView interface. @@ -67,6 +70,9 @@ class BalloonViewImpl : public BalloonView, // views::ViewMenuDelegate interface. void RunMenu(views::View* source, const gfx::Point& pt); + // views::WidgetDelegate interface. + void DisplayChanged(); + // menus::SimpleMenuModel::Delegate interface. virtual bool IsCommandIdChecked(int command_id) const; virtual bool IsCommandIdEnabled(int command_id) const; @@ -128,6 +134,9 @@ class BalloonViewImpl : public BalloonView, // Non-owned pointer to the balloon which owns this object. Balloon* balloon_; + // Non-owned pointer to the balloon collection this is a part of. + BalloonCollection* collection_; + // The window that contains the frame of the notification. // Pointer owned by the View subclass. views::Widget* frame_container_; diff --git a/views/widget/widget.h b/views/widget/widget.h index a3959b4..3f537f6 100644 --- a/views/widget/widget.h +++ b/views/widget/widget.h @@ -26,6 +26,7 @@ class FocusManager; class RootView; class TooltipManager; class View; +class WidgetDelegate; class Window; //////////////////////////////////////////////////////////////////////////////// @@ -91,6 +92,12 @@ class Widget { // contents as the window is sized. virtual void Init(gfx::NativeView parent, const gfx::Rect& bounds) = 0; + // Returns the WidgetDelegate for delegating certain events. + virtual WidgetDelegate* GetWidgetDelegate() = 0; + + // Sets the WidgetDelegate. + virtual void SetWidgetDelegate(WidgetDelegate* delegate) = 0; + // Sets the specified view as the contents of this Widget. There can only // be one contents view child of this Widget's RootView. This view is sized to // fit the entire size of the RootView. The RootView takes ownership of this diff --git a/views/widget/widget_delegate.h b/views/widget/widget_delegate.h new file mode 100755 index 0000000..4607376 --- /dev/null +++ b/views/widget/widget_delegate.h @@ -0,0 +1,23 @@ +// Copyright (c) 2006-2010 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#ifndef VIEWS_WIDGET_WIDGET_DELEGATE_H_ +#define VIEWS_WIDGET_WIDGET_DELEGATE_H_ + +namespace views { + +// WidgetDelegate interface +// Handles events on Widgets in context-specific ways. +class WidgetDelegate { + public: + virtual ~WidgetDelegate() {} + + // Called with the display changes (color depth or resolution). + virtual void DisplayChanged() = 0; +}; + +} // namespace views + +#endif // VIEWS_WIDGET_WIDGET_DELEGATE_H_ + diff --git a/views/widget/widget_gtk.cc b/views/widget/widget_gtk.cc index b14f118..bfd0ab4 100644 --- a/views/widget/widget_gtk.cc +++ b/views/widget/widget_gtk.cc @@ -105,7 +105,8 @@ WidgetGtk::WidgetGtk(Type type) is_active_(false), transient_to_parent_(false), got_initial_focus_in_(false), - has_focus_(false) { + has_focus_(false), + delegate_(NULL) { static bool installed_message_loop_observer = false; if (!installed_message_loop_observer) { installed_message_loop_observer = true; @@ -379,6 +380,14 @@ void WidgetGtk::Init(GtkWidget* parent, } } +WidgetDelegate* WidgetWin::GetWidgetDelegate() { + return delegate_; +} + +void WidgetDelegate::SetWidgetDelegate(WidgetDelegate* delegate) { + delegate_ = delegate; +} + void WidgetGtk::SetContentsView(View* view) { root_view_->SetContentsView(view); } diff --git a/views/widget/widget_gtk.h b/views/widget/widget_gtk.h index 29d99be..87baeb5 100644 --- a/views/widget/widget_gtk.h +++ b/views/widget/widget_gtk.h @@ -137,6 +137,8 @@ class WidgetGtk // Overridden from Widget: virtual void Init(gfx::NativeView parent, const gfx::Rect& bounds); + virtual WidgetDelegate* GetWidgetDelegate(); + virtual void SetWidgetDelegate(WidgetDelegate* delegate); virtual void SetContentsView(View* view); virtual void GetBounds(gfx::Rect* out, bool including_frame) const; virtual void SetBounds(const gfx::Rect& bounds); @@ -470,6 +472,10 @@ class WidgetGtk // this to determine whether we should process the event. bool has_focus_; + // Non owned pointer to optional delegate. May be NULL if no delegate is + // being used. + WidgetDelegate* delegate_; + DISALLOW_COPY_AND_ASSIGN(WidgetGtk); }; diff --git a/views/widget/widget_win.cc b/views/widget/widget_win.cc index 5fb5cf8..5527190 100644 --- a/views/widget/widget_win.cc +++ b/views/widget/widget_win.cc @@ -20,6 +20,7 @@ #include "views/widget/default_theme_provider.h" #include "views/widget/drop_target_win.h" #include "views/widget/root_view.h" +#include "views/widget/widget_delegate.h" #include "views/window/window_win.h" namespace views { @@ -55,7 +56,8 @@ WidgetWin::WidgetWin() last_mouse_event_was_move_(false), is_mouse_down_(false), is_window_(false), - restore_focus_when_enabled_(false) { + restore_focus_when_enabled_(false), + delegate_(NULL) { } WidgetWin::~WidgetWin() { @@ -160,6 +162,14 @@ void WidgetWin::Init(gfx::NativeView parent, const gfx::Rect& bounds) { ImmAssociateContextEx(hwnd(), NULL, 0); } +WidgetDelegate* WidgetWin::GetWidgetDelegate() { + return delegate_; +} + +void WidgetWin::SetWidgetDelegate(WidgetDelegate* delegate) { + delegate_ = delegate; +} + void WidgetWin::SetContentsView(View* view) { root_view_->SetContentsView(view); } @@ -534,6 +544,11 @@ void WidgetWin::OnDestroy() { RemoveProp(hwnd(), kRootViewWindowProperty); } +void WidgetWin::OnDisplayChange(UINT bits_per_pixel, CSize screen_size) { + if (GetWidgetDelegate()) + GetWidgetDelegate()->DisplayChanged(); +} + LRESULT WidgetWin::OnDwmCompositionChanged(UINT msg, WPARAM w_param, LPARAM l_param) { diff --git a/views/widget/widget_win.h b/views/widget/widget_win.h index b8246da..f5ac2d1 100644 --- a/views/widget/widget_win.h +++ b/views/widget/widget_win.h @@ -122,6 +122,7 @@ class WidgetWin : public app::WindowImpl, MSG_WM_COMMAND(OnCommand) MSG_WM_CREATE(OnCreate) MSG_WM_DESTROY(OnDestroy) + MSG_WM_DISPLAYCHANGE(OnDisplayChange) MSG_WM_ERASEBKGND(OnEraseBkgnd) MSG_WM_ENDSESSION(OnEndSession) MSG_WM_ENTERSIZEMOVE(OnEnterSizeMove) @@ -180,6 +181,8 @@ class WidgetWin : public app::WindowImpl, // Overridden from Widget: virtual void Init(gfx::NativeView parent, const gfx::Rect& bounds); + virtual WidgetDelegate* GetWidgetDelegate(); + virtual void SetWidgetDelegate(WidgetDelegate* delegate); virtual void SetContentsView(View* view); virtual void GetBounds(gfx::Rect* out, bool including_frame) const; virtual void SetBounds(const gfx::Rect& bounds); @@ -325,6 +328,7 @@ class WidgetWin : public app::WindowImpl, // WARNING: If you override this be sure and invoke super, otherwise we'll // leak a few things. virtual void OnDestroy(); + virtual void OnDisplayChange(UINT bits_per_pixel, CSize screen_size); virtual LRESULT OnDwmCompositionChanged(UINT msg, WPARAM w_param, LPARAM l_param); @@ -544,6 +548,10 @@ class WidgetWin : public app::WindowImpl, ScopedComPtr<IAccessible> accessibility_root_; scoped_ptr<DefaultThemeProvider> default_theme_provider_; + + // Non owned pointer to optional delegate. May be NULL if no delegate is + // being used. + WidgetDelegate* delegate_; }; } // namespace views |