summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorrsesek@chromium.org <rsesek@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-03-08 20:22:10 +0000
committerrsesek@chromium.org <rsesek@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-03-08 20:22:10 +0000
commit70972786c4482be756009025b0750e4e72a3d088 (patch)
treed275122c00bdff05570193a432dd2cbe9a3a9799
parente9c42d5cb01ffdc5956e226190208a915f321bbb (diff)
downloadchromium_src-70972786c4482be756009025b0750e4e72a3d088.zip
chromium_src-70972786c4482be756009025b0750e4e72a3d088.tar.gz
chromium_src-70972786c4482be756009025b0750e4e72a3d088.tar.bz2
Break the dependency of MessageCenterSettingsController on views.
This refactors NotifierSettingsViewDelegate into a NotifierSettingsProvider (controller), a NotifierSettingsDelegate (view), and a function ShowSettings() to bring up up the UI. BUG=179916 Review URL: https://codereview.chromium.org/12614009 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@187028 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r--chrome/browser/notifications/message_center_settings_controller.cc25
-rw-r--r--chrome/browser/notifications/message_center_settings_controller.h10
-rw-r--r--ui/message_center/message_center.gyp4
-rw-r--r--ui/message_center/notifier_settings.cc (renamed from ui/message_center/notifier_settings_view_delegate.cc)10
-rw-r--r--ui/message_center/notifier_settings.h (renamed from ui/message_center/notifier_settings_view_delegate.h)33
-rw-r--r--ui/message_center/views/notifier_settings_view.cc20
-rw-r--r--ui/message_center/views/notifier_settings_view.h20
7 files changed, 75 insertions, 47 deletions
diff --git a/chrome/browser/notifications/message_center_settings_controller.cc b/chrome/browser/notifications/message_center_settings_controller.cc
index 96ca7c0..05cd5d5 100644
--- a/chrome/browser/notifications/message_center_settings_controller.cc
+++ b/chrome/browser/notifications/message_center_settings_controller.cc
@@ -16,28 +16,17 @@
#include "chrome/common/cancelable_task_tracker.h"
#include "ui/gfx/image/image.h"
#include "ui/message_center/message_center_constants.h"
-#include "ui/message_center/views/notifier_settings_view.h"
-#include "ui/views/widget/widget.h"
MessageCenterSettingsController::MessageCenterSettingsController()
- : settings_view_(NULL) {
+ : delegate_(NULL) {
}
MessageCenterSettingsController::~MessageCenterSettingsController() {
- if (settings_view_) {
- settings_view_->set_delegate(NULL);
- settings_view_->GetWidget()->Close();
- settings_view_ = NULL;
- }
}
void MessageCenterSettingsController::ShowSettingsDialog(
gfx::NativeView context) {
- if (settings_view_)
- settings_view_->GetWidget()->StackAtTop();
- else
- settings_view_ =
- message_center::NotifierSettingsView::Create(this, context);
+ delegate_ = message_center::ShowSettings(this, context);
}
void MessageCenterSettingsController::GetNotifierList(
@@ -142,7 +131,7 @@ void MessageCenterSettingsController::SetNotifierEnabled(
}
void MessageCenterSettingsController::OnNotifierSettingsClosing() {
- settings_view_ = NULL;
+ delegate_ = NULL;
DCHECK(favicon_tracker_.get());
favicon_tracker_->TryCancelAll();
}
@@ -150,15 +139,15 @@ void MessageCenterSettingsController::OnNotifierSettingsClosing() {
void MessageCenterSettingsController::OnFaviconLoaded(
const GURL& url,
const history::FaviconImageResult& favicon_result) {
- if (!settings_view_)
+ if (!delegate_)
return;
- settings_view_->UpdateFavicon(url, favicon_result.image);
+ delegate_->UpdateFavicon(url, favicon_result.image);
}
void MessageCenterSettingsController::SetAppImage(const std::string& id,
const gfx::ImageSkia& image) {
- if (!settings_view_)
+ if (!delegate_)
return;
- settings_view_->UpdateIconImage(id, image);
+ delegate_->UpdateIconImage(id, gfx::Image(image) );
}
diff --git a/chrome/browser/notifications/message_center_settings_controller.h b/chrome/browser/notifications/message_center_settings_controller.h
index 54e4806..2c8a9f4 100644
--- a/chrome/browser/notifications/message_center_settings_controller.h
+++ b/chrome/browser/notifications/message_center_settings_controller.h
@@ -11,18 +11,14 @@
#include "base/memory/scoped_ptr.h"
#include "chrome/browser/extensions/app_icon_loader.h"
#include "chrome/browser/history/history_types.h"
-#include "ui/message_center/notifier_settings_view_delegate.h"
+#include "ui/message_center/notifier_settings.h"
class CancelableTaskTracker;
-namespace message_center {
-class NotifierSettingsView;
-}
-
// The class to bridge between the settings UI of notifiers and the preference
// storage.
class MessageCenterSettingsController
- : public message_center::NotifierSettingsViewDelegate,
+ : public message_center::NotifierSettingsProvider,
public extensions::AppIconLoader::Delegate {
public:
MessageCenterSettingsController();
@@ -52,7 +48,7 @@ class MessageCenterSettingsController
// The view displaying notifier settings. NULL if the settings are not
// visible.
- message_center::NotifierSettingsView* settings_view_;
+ message_center::NotifierSettingsDelegate* delegate_;
// The task tracker for loading favicons.
scoped_ptr<CancelableTaskTracker> favicon_tracker_;
diff --git a/ui/message_center/message_center.gyp b/ui/message_center/message_center.gyp
index 46c8f8c..bd8a07a9 100644
--- a/ui/message_center/message_center.gyp
+++ b/ui/message_center/message_center.gyp
@@ -45,8 +45,8 @@
'notification_list.h',
'notification_types.cc',
'notification_types.h',
- 'notifier_settings_view_delegate.cc',
- 'notifier_settings_view_delegate.h',
+ 'notifier_settings.cc',
+ 'notifier_settings.h',
'views/message_bubble_base.cc',
'views/message_bubble_base.h',
'views/message_center_bubble.cc',
diff --git a/ui/message_center/notifier_settings_view_delegate.cc b/ui/message_center/notifier_settings.cc
index 2e8ffc2..78246f5 100644
--- a/ui/message_center/notifier_settings_view_delegate.cc
+++ b/ui/message_center/notifier_settings.cc
@@ -2,10 +2,18 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
-#include "ui/message_center/notifier_settings_view_delegate.h"
+#include "ui/message_center/notifier_settings.h"
namespace message_center {
+#if !defined(TOOLKIT_VIEWS)
+NotifierSettingsDelegate* ShowSettings(NotifierSettingsProvider* provider,
+ gfx::NativeView context) {
+ NOTIMPLEMENTED();
+ return NULL;
+}
+#endif
+
Notifier::Notifier(const std::string& id,
const string16& name,
bool enabled)
diff --git a/ui/message_center/notifier_settings_view_delegate.h b/ui/message_center/notifier_settings.h
index 9ea850c..f62e964 100644
--- a/ui/message_center/notifier_settings_view_delegate.h
+++ b/ui/message_center/notifier_settings.h
@@ -2,8 +2,8 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
-#ifndef UI_MESSAGE_CENTER_NOTIFIER_SETTINGS_VIEW_DELEGATE_H_
-#define UI_MESSAGE_CENTER_NOTIFIER_SETTINGS_VIEW_DELEGATE_H_
+#ifndef UI_MESSAGE_CENTER_NOTIFIER_SETTINGS_H_
+#define UI_MESSAGE_CENTER_NOTIFIER_SETTINGS_H_
#include <string>
@@ -14,6 +14,16 @@
namespace message_center {
+class NotifierSettingsDelegate;
+class NotifierSettingsProvider;
+
+// Brings up the settings dialog and returns a weak reference to the delegate,
+// which is typically the view. If the dialog already exists, it is brought to
+// the front, otherwise it is created.
+MESSAGE_CENTER_EXPORT NotifierSettingsDelegate* ShowSettings(
+ NotifierSettingsProvider* provider,
+ gfx::NativeView context);
+
// The struct to hold the information of notifiers. The information will be
// used by NotifierSettingsView.
struct MESSAGE_CENTER_EXPORT Notifier {
@@ -53,8 +63,9 @@ struct MESSAGE_CENTER_EXPORT Notifier {
DISALLOW_COPY_AND_ASSIGN(Notifier);
};
-// The delegate class for NotifierSettingsView.
-class MESSAGE_CENTER_EXPORT NotifierSettingsViewDelegate {
+// A class used by NotifierSettingsView to integrate with a setting system
+// for the clients of this module.
+class MESSAGE_CENTER_EXPORT NotifierSettingsProvider {
public:
// Collects the current notifier list and fills to |notifiers|. Caller takes
// the ownership of the elements of |notifiers|.
@@ -68,6 +79,18 @@ class MESSAGE_CENTER_EXPORT NotifierSettingsViewDelegate {
virtual void OnNotifierSettingsClosing() = 0;
};
+// A delegate class implemented by the view of the NotifierSettings to get
+// notified when the controller has changed data.
+class MESSAGE_CENTER_EXPORT NotifierSettingsDelegate {
+ public:
+ // Called when an icon in the controller has been updated.
+ virtual void UpdateIconImage(const std::string& id,
+ const gfx::Image& icon) = 0;
+
+ // Called when the controller detects that a favicon has changed.
+ virtual void UpdateFavicon(const GURL& url, const gfx::Image& icon) = 0;
+};
+
} // namespace message_center
-#endif // UI_MESSAGE_CENTER_NOTIFIER_SETTINGS_VIEW_DELEGATE_H_
+#endif // UI_MESSAGE_CENTER_NOTIFIER_SETTINGS_H_
diff --git a/ui/message_center/views/notifier_settings_view.cc b/ui/message_center/views/notifier_settings_view.cc
index c65d4e0..208a602 100644
--- a/ui/message_center/views/notifier_settings_view.cc
+++ b/ui/message_center/views/notifier_settings_view.cc
@@ -10,7 +10,6 @@
#include "ui/gfx/image/image.h"
#include "ui/gfx/size.h"
#include "ui/message_center/message_center_constants.h"
-#include "ui/message_center/notifier_settings_view_delegate.h"
#include "ui/views/background.h"
#include "ui/views/border.h"
#include "ui/views/controls/button/checkbox.h"
@@ -30,8 +29,18 @@ namespace {
const int kSpaceInButtonComponents = 16;
const int kMarginWidth = 16;
+NotifierSettingsView* settings_view_ = NULL;
+
} // namespace
+NotifierSettingsDelegate* ShowSettings(NotifierSettingsProvider* provider,
+ gfx::NativeView context) {
+ if (!settings_view_) {
+ settings_view_ = NotifierSettingsView::Create(provider, context);
+ }
+ return settings_view_;
+}
+
// We do not use views::Checkbox class directly because it doesn't support
// showing 'icon'.
class NotifierSettingsView::NotifierButton : public views::CustomButton,
@@ -103,7 +112,7 @@ class NotifierSettingsView::NotifierButton : public views::CustomButton,
// static
NotifierSettingsView* NotifierSettingsView::Create(
- NotifierSettingsViewDelegate* delegate,
+ NotifierSettingsProvider* delegate,
gfx::NativeView context) {
NotifierSettingsView* view = new NotifierSettingsView(delegate);
views::Widget* widget = new views::Widget;
@@ -117,11 +126,11 @@ NotifierSettingsView* NotifierSettingsView::Create(
}
void NotifierSettingsView::UpdateIconImage(const std::string& id,
- const gfx::ImageSkia& icon) {
+ const gfx::Image& icon) {
for (std::set<NotifierButton*>::iterator iter = buttons_.begin();
iter != buttons_.end(); ++iter) {
if ((*iter)->notifier().id == id) {
- (*iter)->UpdateIconImage(gfx::Image(icon));
+ (*iter)->UpdateIconImage(icon);
return;
}
}
@@ -139,7 +148,7 @@ void NotifierSettingsView::UpdateFavicon(const GURL& url,
}
NotifierSettingsView::NotifierSettingsView(
- NotifierSettingsViewDelegate* delegate)
+ NotifierSettingsProvider* delegate)
: delegate_(delegate) {
DCHECK(delegate_);
@@ -168,6 +177,7 @@ NotifierSettingsView::NotifierSettingsView(
}
NotifierSettingsView::~NotifierSettingsView() {
+ settings_view_ = NULL;
}
bool NotifierSettingsView::CanResize() const {
diff --git a/ui/message_center/views/notifier_settings_view.h b/ui/message_center/views/notifier_settings_view.h
index 4aa7701..08a20d8 100644
--- a/ui/message_center/views/notifier_settings_view.h
+++ b/ui/message_center/views/notifier_settings_view.h
@@ -13,36 +13,38 @@
#include "ui/gfx/image/image_skia.h"
#include "ui/gfx/native_widget_types.h"
#include "ui/message_center/message_center_export.h"
+#include "ui/message_center/notifier_settings.h"
#include "ui/views/controls/button/button.h"
#include "ui/views/widget/widget_delegate.h"
namespace message_center {
-class NotifierSettingsViewDelegate;
-
// A class to show the list of notifier extensions / URL patterns and allow
// users to customize the settings.
class MESSAGE_CENTER_EXPORT NotifierSettingsView
- : public views::WidgetDelegateView,
+ : public NotifierSettingsDelegate,
+ public views::WidgetDelegateView,
public views::ButtonListener {
public:
// Create a new widget of the notifier settings and returns it. Note that
// the widget and the view is self-owned. It'll be deleted when it's closed
// or the chrome's shutdown.
- static NotifierSettingsView* Create(NotifierSettingsViewDelegate* delegate,
+ static NotifierSettingsView* Create(NotifierSettingsProvider* delegate,
gfx::NativeView context);
- void UpdateIconImage(const std::string& id, const gfx::ImageSkia& icon);
- void UpdateFavicon(const GURL& url, const gfx::Image& icon);
+ // Overridden from NotifierSettingsDelegate:
+ virtual void UpdateIconImage(const std::string& id,
+ const gfx::Image& icon) OVERRIDE;
+ virtual void UpdateFavicon(const GURL& url, const gfx::Image& icon) OVERRIDE;
- void set_delegate(NotifierSettingsViewDelegate* new_delegate) {
+ void set_delegate(NotifierSettingsProvider* new_delegate) {
delegate_ = new_delegate;
}
private:
class NotifierButton;
- NotifierSettingsView(NotifierSettingsViewDelegate* delegate);
+ NotifierSettingsView(NotifierSettingsProvider* delegate);
virtual ~NotifierSettingsView();
// Overridden from views::WidgetDelegate:
@@ -55,7 +57,7 @@ class MESSAGE_CENTER_EXPORT NotifierSettingsView
virtual void ButtonPressed(views::Button* sender,
const ui::Event& event) OVERRIDE;
- NotifierSettingsViewDelegate* delegate_;
+ NotifierSettingsProvider* delegate_;
std::set<NotifierButton*> buttons_;
DISALLOW_COPY_AND_ASSIGN(NotifierSettingsView);