diff options
Diffstat (limited to 'chrome/browser/chromeos/notifications/notification_panel.cc')
-rw-r--r-- | chrome/browser/chromeos/notifications/notification_panel.cc | 53 |
1 files changed, 32 insertions, 21 deletions
diff --git a/chrome/browser/chromeos/notifications/notification_panel.cc b/chrome/browser/chromeos/notifications/notification_panel.cc index 46c5b81..5d599ed 100644 --- a/chrome/browser/chromeos/notifications/notification_panel.cc +++ b/chrome/browser/chromeos/notifications/notification_panel.cc @@ -9,14 +9,18 @@ #include "app/gfx/canvas.h" #include "app/l10n_util.h" #include "app/resource_bundle.h" -#include "base/singleton.h" #include "chrome/browser/chromeos/notifications/balloon_view.h" #include "grit/generated_resources.h" #include "views/background.h" +#include "views/controls/scroll_view.h" #include "views/widget/widget_gtk.h" namespace chromeos { +// Maximum height of the notification panel. +// TODO(oshima): Get this from system's metrics. +const int kMaxPanelHeight = 400; + class BalloonContainer : public views::View { public: explicit BalloonContainer(int margin) @@ -52,7 +56,8 @@ class BalloonContainer : public views::View { height += c->height() + margin_; max_width = std::max(max_width, c->width()); } - if (height > 0) height -= margin_; + if (height > 0) + height -= margin_; preferred_size_.set_width(max_width); preferred_size_.set_height(height); PreferredSizeChanged(); @@ -62,15 +67,12 @@ class BalloonContainer : public views::View { private: gfx::Size preferred_size_; int margin_; -}; -// static -NotificationPanel* NotificationPanel::Get() { - return Singleton<NotificationPanel>::get(); -} + DISALLOW_COPY_AND_ASSIGN(BalloonContainer); +}; NotificationPanel::NotificationPanel() - : panel_widget_(NULL) { + : balloon_container_(NULL) { Init(); } @@ -79,37 +81,46 @@ NotificationPanel::~NotificationPanel() { gfx::Rect NotificationPanel::GetPanelBounds() { gfx::Size pref_size = balloon_container_->GetPreferredSize(); - int new_height = pref_size.height(); - return gfx::Rect(0, 0, pref_size.width(), new_height); + int new_height = std::min(pref_size.height(), kMaxPanelHeight); + int new_width = pref_size.width(); + if (new_height != pref_size.height()) + new_width += scroll_view_->GetScrollBarWidth(); + return gfx::Rect(0, 0, new_width, new_height); } void NotificationPanel::Init() { DCHECK(!panel_widget_.get()); balloon_container_ = new BalloonContainer(1); - balloon_container_->set_parent_owned(false); balloon_container_->set_background( views::Background::CreateSolidBackground(ResourceBundle::frame_color)); + + scroll_view_.reset(new views::ScrollView()); + scroll_view_->set_parent_owned(false); + scroll_view_->SetContents(balloon_container_); } -void NotificationPanel::Add(BalloonViewImpl* view) { +void NotificationPanel::Add(Balloon* balloon) { + BalloonViewImpl* view = + static_cast<BalloonViewImpl*>(balloon->view()); balloon_container_->AddChildView(view); balloon_container_->UpdateBounds(); - balloon_container_->Layout(); - if (panel_widget_.get()) { + scroll_view_->Layout(); + if (panel_widget_.get()) panel_widget_->SetBounds(GetPanelBounds()); - } + Show(); } -void NotificationPanel::Remove(BalloonViewImpl* view) { +void NotificationPanel::Remove(Balloon* balloon) { + BalloonViewImpl* view = + static_cast<BalloonViewImpl*>(balloon->view()); balloon_container_->RemoveChildView(view); balloon_container_->UpdateBounds(); - balloon_container_->Layout(); + scroll_view_->Layout(); if (panel_widget_.get()) { - if (balloon_container_->GetChildViewCount() == 0) { + if (balloon_container_->GetChildViewCount() == 0) Hide(); - } else { + else panel_widget_->SetBounds(GetPanelBounds()); - } } } @@ -119,7 +130,7 @@ void NotificationPanel::Show() { // when resizing. This needs to be investigated. panel_widget_.reset(new views::WidgetGtk(views::WidgetGtk::TYPE_WINDOW)); panel_widget_->Init(NULL, GetPanelBounds()); - panel_widget_->SetContentsView(balloon_container_); + panel_widget_->SetContentsView(scroll_view_.get()); panel_controller_.reset( new PanelController(this, GTK_WINDOW(panel_widget_->GetNativeView()), |