summaryrefslogtreecommitdiffstats
path: root/components
diff options
context:
space:
mode:
authorwjmaclean <wjmaclean@chromium.org>2015-02-04 08:14:22 -0800
committerCommit bot <commit-bot@chromium.org>2015-02-04 16:15:03 +0000
commit70081cb1ac42234766c745dd6422b78ea4291cd2 (patch)
tree0c220c7778282c530792d11178c16bd4e2d41d0d /components
parentbb4db81dcbbe045c9ed2a7d05662af06064a3884 (diff)
downloadchromium_src-70081cb1ac42234766c745dd6422b78ea4291cd2.zip
chromium_src-70081cb1ac42234766c745dd6422b78ea4291cd2.tar.gz
chromium_src-70081cb1ac42234766c745dd6422b78ea4291cd2.tar.bz2
Plumb default zoom level change events to zoom icon in location bar.
At present, a change in the default zoom level does not immediately update the zoom icon in the location bar. E.g. if we change the zoom level of chrome://settings to 90% (causing the zoom icon to display a '-' symbol), then change the default zoom level to be 75%, the icon should switch to show '+'. This CL adds an event subscription to the ZoomEventManager in order to receive notifications about default zoom level changes. BUG=451349 Review URL: https://codereview.chromium.org/897513003 Cr-Commit-Position: refs/heads/master@{#314568}
Diffstat (limited to 'components')
-rw-r--r--components/ui/zoom/BUILD.gn1
-rw-r--r--components/ui/zoom/zoom_event_manager.cc16
-rw-r--r--components/ui/zoom/zoom_event_manager.h14
-rw-r--r--components/ui/zoom/zoom_event_manager_observer.h23
-rw-r--r--components/ui_zoom.gypi1
5 files changed, 55 insertions, 0 deletions
diff --git a/components/ui/zoom/BUILD.gn b/components/ui/zoom/BUILD.gn
index a3958b8..8774b0d 100644
--- a/components/ui/zoom/BUILD.gn
+++ b/components/ui/zoom/BUILD.gn
@@ -12,6 +12,7 @@ static_library("ui_zoom") {
"zoom_controller.h",
"zoom_event_manager.cc",
"zoom_event_manager.h",
+ "zoom_event_manager_observer.h",
"zoom_observer.h",
]
diff --git a/components/ui/zoom/zoom_event_manager.cc b/components/ui/zoom/zoom_event_manager.cc
index 7290627..f841123 100644
--- a/components/ui/zoom/zoom_event_manager.cc
+++ b/components/ui/zoom/zoom_event_manager.cc
@@ -4,6 +4,7 @@
#include "components/ui/zoom/zoom_event_manager.h"
+#include "components/ui/zoom/zoom_event_manager_observer.h"
#include "content/public/browser/browser_context.h"
namespace {
@@ -37,4 +38,19 @@ ZoomEventManager::AddZoomLevelChangedCallback(
return zoom_level_changed_callbacks_.Add(callback);
}
+void ZoomEventManager::OnDefaultZoomLevelChanged() {
+ FOR_EACH_OBSERVER(ZoomEventManagerObserver, observers_,
+ OnDefaultZoomLevelChanged());
+}
+
+void ZoomEventManager::AddZoomEventManagerObserver(
+ ZoomEventManagerObserver* observer) {
+ observers_.AddObserver(observer);
+}
+
+void ZoomEventManager::RemoveZoomEventManagerObserver(
+ ZoomEventManagerObserver* observer) {
+ observers_.RemoveObserver(observer);
+}
+
} // namespace ui_zoom
diff --git a/components/ui/zoom/zoom_event_manager.h b/components/ui/zoom/zoom_event_manager.h
index 3f0fcf0..72d335d 100644
--- a/components/ui/zoom/zoom_event_manager.h
+++ b/components/ui/zoom/zoom_event_manager.h
@@ -7,6 +7,7 @@
#include "base/callback_list.h"
#include "base/memory/weak_ptr.h"
+#include "base/observer_list.h"
#include "base/supports_user_data.h"
#include "content/public/browser/host_zoom_map.h"
@@ -16,6 +17,8 @@ class BrowserContext;
namespace ui_zoom {
+class ZoomEventManagerObserver;
+
// This class serves as a target for event notifications from all ZoomController
// objects. Classes that need to know about browser-specific zoom events (e.g.
// manual-mode zoom) should subscribe here.
@@ -34,9 +37,19 @@ class ZoomEventManager : public base::SupportsUserData::Data {
void OnZoomLevelChanged(const content::HostZoomMap::ZoomLevelChange& change);
// Add and remove zoom level changed callbacks.
+ // TODO(wjmaclean): Convert this callback mechanism to use
+ // ZoomEventManagerObserver instead.
scoped_ptr<content::HostZoomMap::Subscription> AddZoomLevelChangedCallback(
const content::HostZoomMap::ZoomLevelChangedCallback& callback);
+ // Called by ZoomLevelDelegates when changes are made to the default zoom
+ // level for their associated HostZoomMap.
+ void OnDefaultZoomLevelChanged();
+
+ // Add and remove observers.
+ void AddZoomEventManagerObserver(ZoomEventManagerObserver* observer);
+ void RemoveZoomEventManagerObserver(ZoomEventManagerObserver* observer);
+
// Get a weak ptr to be used by clients who may themselves be UserData for
// the context, since the order of destruction is undefined between the client
// and this class.
@@ -47,6 +60,7 @@ class ZoomEventManager : public base::SupportsUserData::Data {
private:
base::CallbackList<void(const content::HostZoomMap::ZoomLevelChange&)>
zoom_level_changed_callbacks_;
+ ObserverList<ZoomEventManagerObserver> observers_;
base::WeakPtrFactory<ZoomEventManager> weak_ptr_factory_;
DISALLOW_COPY_AND_ASSIGN(ZoomEventManager);
diff --git a/components/ui/zoom/zoom_event_manager_observer.h b/components/ui/zoom/zoom_event_manager_observer.h
new file mode 100644
index 0000000..f3afedc
--- /dev/null
+++ b/components/ui/zoom/zoom_event_manager_observer.h
@@ -0,0 +1,23 @@
+// Copyright 2015 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 COMPONENTS_UI_ZOOM_ZOOM_EVENT_MANAGER_OBSERVER_H_
+#define COMPONENTS_UI_ZOOM_ZOOM_EVENT_MANAGER_OBSERVER_H_
+
+namespace ui_zoom {
+
+class ZoomEventManagerObserver {
+ public:
+ // TODO(wjmaclean): convert existing ZoomLevelChangedCallbacks to be
+ // observers.
+ virtual void OnZoomLevelChanged() {}
+ virtual void OnDefaultZoomLevelChanged() {}
+
+ protected:
+ virtual ~ZoomEventManagerObserver() {}
+};
+
+} // namespace ui_zoom
+
+#endif // COMPONENTS_UI_ZOOM_ZOOM_EVENT_MANAGER_OBSERVER_H_
diff --git a/components/ui_zoom.gypi b/components/ui_zoom.gypi
index fc3ed76..15e988d 100644
--- a/components/ui_zoom.gypi
+++ b/components/ui_zoom.gypi
@@ -27,6 +27,7 @@
'ui/zoom/zoom_controller.h',
'ui/zoom/zoom_event_manager.cc',
'ui/zoom/zoom_event_manager.h',
+ 'ui/zoom/zoom_event_manager_observer.h',
'ui/zoom/zoom_observer.h'
],
}