diff options
author | stevenjb@chromium.org <stevenjb@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-01-17 22:38:22 +0000 |
---|---|---|
committer | stevenjb@chromium.org <stevenjb@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-01-17 22:38:22 +0000 |
commit | 1979453de9770526bf4b6f8b7adab57f5e4b2de6 (patch) | |
tree | 7184ebd0469112854dd17a682e6e76f65c468b08 /chrome/browser/notifications | |
parent | 539ee3e4239962f775f0c7e42bc4816642eae671 (diff) | |
download | chromium_src-1979453de9770526bf4b6f8b7adab57f5e4b2de6.zip chromium_src-1979453de9770526bf4b6f8b7adab57f5e4b2de6.tar.gz chromium_src-1979453de9770526bf4b6f8b7adab57f5e4b2de6.tar.bz2 |
Implement chromeos SystemNotification on Aura by introducing BalloonCollectionImplAura.
BUG=98331
TEST=Test system notifications (failed network connect, low battery) on ChromeOS Aura.
Review URL: http://codereview.chromium.org/9187043
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@117984 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/notifications')
6 files changed, 43 insertions, 17 deletions
diff --git a/chrome/browser/notifications/balloon_collection_base.cc b/chrome/browser/notifications/balloon_collection_base.cc index 4e9ab50f..278f4a9 100644 --- a/chrome/browser/notifications/balloon_collection_base.cc +++ b/chrome/browser/notifications/balloon_collection_base.cc @@ -1,4 +1,4 @@ -// Copyright (c) 2010 The Chromium Authors. All rights reserved. +// Copyright (c) 2012 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. @@ -16,8 +16,11 @@ BalloonCollectionBase::~BalloonCollectionBase() { STLDeleteElements(&balloons_); } -void BalloonCollectionBase::Add(Balloon* balloon) { - balloons_.push_back(balloon); +void BalloonCollectionBase::Add(Balloon* balloon, bool add_to_front) { + if (add_to_front) + balloons_.push_front(balloon); + else + balloons_.push_back(balloon); } void BalloonCollectionBase::Remove(Balloon* balloon) { diff --git a/chrome/browser/notifications/balloon_collection_base.h b/chrome/browser/notifications/balloon_collection_base.h index c388ac9..578c76e 100644 --- a/chrome/browser/notifications/balloon_collection_base.h +++ b/chrome/browser/notifications/balloon_collection_base.h @@ -1,4 +1,4 @@ -// Copyright (c) 2010 The Chromium Authors. All rights reserved. +// Copyright (c) 2012 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. @@ -27,7 +27,7 @@ class BalloonCollectionBase { typedef std::deque<Balloon*> Balloons; // Adds a balloon to the collection. Takes ownership of pointer. - virtual void Add(Balloon* balloon); + virtual void Add(Balloon* balloon, bool add_to_front); // Removes a balloon from the collection (if present). Frees // the pointer after removal. diff --git a/chrome/browser/notifications/balloon_collection_impl.cc b/chrome/browser/notifications/balloon_collection_impl.cc index 26e1363..b12548f 100644 --- a/chrome/browser/notifications/balloon_collection_impl.cc +++ b/chrome/browser/notifications/balloon_collection_impl.cc @@ -58,8 +58,9 @@ BalloonCollectionImpl::BalloonCollectionImpl() BalloonCollectionImpl::~BalloonCollectionImpl() { } -void BalloonCollectionImpl::Add(const Notification& notification, - Profile* profile) { +void BalloonCollectionImpl::AddImpl(const Notification& notification, + Profile* profile, + bool add_to_front) { Balloon* new_balloon = MakeBalloon(notification, profile); // The +1 on width is necessary because width is fixed on notifications, // so since we always have the max size, we would always hit the scrollbar @@ -73,7 +74,7 @@ void BalloonCollectionImpl::Add(const Notification& notification, if (count > 0 && layout_.RequiresOffsets()) new_balloon->set_offset(base_.balloons()[count - 1]->offset()); #endif - base_.Add(new_balloon); + base_.Add(new_balloon, add_to_front); PositionBalloons(false); // There may be no listener in a unit test. @@ -85,6 +86,11 @@ void BalloonCollectionImpl::Add(const Notification& notification, on_collection_changed_callback_.Run(); } +void BalloonCollectionImpl::Add(const Notification& notification, + Profile* profile) { + AddImpl(notification, profile, false); +} + bool BalloonCollectionImpl::RemoveById(const std::string& id) { return base_.CloseById(id); } diff --git a/chrome/browser/notifications/balloon_collection_impl.h b/chrome/browser/notifications/balloon_collection_impl.h index 032fabb..749c9e0 100644 --- a/chrome/browser/notifications/balloon_collection_impl.h +++ b/chrome/browser/notifications/balloon_collection_impl.h @@ -1,4 +1,4 @@ -// Copyright (c) 2011 The Chromium Authors. All rights reserved. +// Copyright (c) 2012 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. @@ -72,6 +72,10 @@ class BalloonCollectionImpl : public BalloonCollection, virtual void DidProcessEvent(GdkEvent* event) OVERRIDE; #endif + // base_ is embedded, so this is a simple accessor for the number of + // balloons in the collection. + int count() const { return base_.count(); } + protected: // Calculates layout values for the balloons including // the scaling, the max/min sizes, and the upper left corner of each. @@ -165,14 +169,23 @@ class BalloonCollectionImpl : public BalloonCollection, DISALLOW_COPY_AND_ASSIGN(Layout); }; - // Creates a new balloon. Overridable by unit tests. The caller is - // responsible for freeing the pointer returned. + // Creates a new balloon. Overridable by derived classes and unit tests. + // The caller is responsible for freeing the pointer returned. virtual Balloon* MakeBalloon(const Notification& notification, Profile* profile); + // Protected implementation of Add with additional add_to_front parameter + // for use by derived classes. + void AddImpl(const Notification& notification, + Profile* profile, + bool add_to_front); + // Gets a bounding box for all the current balloons in screen coordinates. gfx::Rect GetBalloonsBoundingBox() const; + BalloonCollectionBase& base() { return base_; } + Layout& layout() { return layout_; } + private: // Adjusts the positions of the balloons (e.g., when one is closed). // Implemented by each platform for specific UI requirements. diff --git a/chrome/browser/notifications/balloon_collection_views.cc b/chrome/browser/notifications/balloon_collection_views.cc index f5ac0e4..763fba1 100644 --- a/chrome/browser/notifications/balloon_collection_views.cc +++ b/chrome/browser/notifications/balloon_collection_views.cc @@ -1,4 +1,4 @@ -// Copyright (c) 2011 The Chromium Authors. All rights reserved. +// Copyright (c) 2012 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. @@ -108,7 +108,9 @@ void BalloonCollectionImpl::SetPositionPreference( PositionBalloons(true); } +#if !defined(USE_AURA) // static BalloonCollection* BalloonCollection::Create() { return new BalloonCollectionImpl(); } +#endif diff --git a/chrome/browser/notifications/notification_options_menu_model.cc b/chrome/browser/notifications/notification_options_menu_model.cc index 2578c3f..c486742 100644 --- a/chrome/browser/notifications/notification_options_menu_model.cc +++ b/chrome/browser/notifications/notification_options_menu_model.cc @@ -1,4 +1,4 @@ -// Copyright (c) 2011 The Chromium Authors. All rights reserved. +// Copyright (c) 2012 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. @@ -129,16 +129,18 @@ NotificationOptionsMenuModel::NotificationOptionsMenuModel(Balloon* balloon) IDS_EXTENSIONS_DISABLE); AddItem(kToggleExtensionCommand, disable_label); } - } else { + } else if (!notification.display_source().empty()) { const string16 disable_label = l10n_util::GetStringFUTF16( IDS_NOTIFICATION_BALLOON_REVOKE_MESSAGE, notification.display_source()); AddItem(kTogglePermissionCommand, disable_label); } - const string16 settings_label = l10n_util::GetStringUTF16( - IDS_NOTIFICATIONS_SETTINGS_BUTTON); - AddItem(kOpenContentSettingsCommand, settings_label); + if (!notification.display_source().empty()) { + const string16 settings_label = l10n_util::GetStringUTF16( + IDS_NOTIFICATIONS_SETTINGS_BUTTON); + AddItem(kOpenContentSettingsCommand, settings_label); + } corner_menu_model_.reset(new CornerSelectionMenuModel(balloon)); AddSubMenu(kCornerSelectionSubMenu, |