Commit 70081cb1 authored by wjmaclean's avatar wjmaclean Committed by Commit bot

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}
parent bb4db81d
......@@ -64,6 +64,7 @@
#include "components/search_engines/template_url_service.h"
#include "components/translate/core/browser/language_state.h"
#include "components/ui/zoom/zoom_controller.h"
#include "components/ui/zoom/zoom_event_manager.h"
#include "content/public/browser/render_widget_host_view.h"
#include "content/public/browser/web_contents.h"
#include "extensions/browser/extension_registry.h"
......@@ -193,6 +194,9 @@ LocationBarView::LocationBarView(Browser* browser,
if (browser_)
browser_->search_model()->AddObserver(this);
ui_zoom::ZoomEventManager::GetForBrowserContext(profile)
->AddZoomEventManagerObserver(this);
}
LocationBarView::~LocationBarView() {
......@@ -200,6 +204,9 @@ LocationBarView::~LocationBarView() {
template_url_service_->RemoveObserver(this);
if (browser_)
browser_->search_model()->RemoveObserver(this);
ui_zoom::ZoomEventManager::GetForBrowserContext(profile())
->RemoveZoomEventManagerObserver(this);
}
////////////////////////////////////////////////////////////////////////////////
......@@ -1153,6 +1160,10 @@ bool LocationBarView::RefreshZoomView() {
return was_visible != zoom_view_->visible();
}
void LocationBarView::OnDefaultZoomLevelChanged() {
RefreshZoomView();
}
void LocationBarView::RefreshTranslateIcon() {
if (!TranslateService::IsTranslateBubbleEnabled())
return;
......
......@@ -20,6 +20,7 @@
#include "chrome/browser/ui/views/extensions/extension_popup.h"
#include "chrome/browser/ui/views/omnibox/omnibox_view_views.h"
#include "components/search_engines/template_url_service_observer.h"
#include "components/ui/zoom/zoom_event_manager_observer.h"
#include "ui/gfx/animation/animation_delegate.h"
#include "ui/gfx/font.h"
#include "ui/gfx/geometry/rect.h"
......@@ -83,7 +84,8 @@ class LocationBarView : public LocationBar,
public DropdownBarHostDelegate,
public gfx::AnimationDelegate,
public TemplateURLServiceObserver,
public SearchModelObserver {
public SearchModelObserver,
public ui_zoom::ZoomEventManagerObserver {
public:
// The location bar view's class name.
static const char kViewClassName[];
......@@ -259,6 +261,10 @@ class LocationBarView : public LocationBar,
ToolbarModel* GetToolbarModel() override;
content::WebContents* GetWebContents() override;
// ZoomEventManagerObserver:
// Updates the view for the zoom icon when default zoom levels change.
void OnDefaultZoomLevelChanged() override;
// Thickness of the edges of the omnibox background images, in normal mode.
static const int kNormalEdgeThickness;
// The same, but for popup mode.
......
......@@ -71,6 +71,8 @@ void ChromeZoomLevelPrefs::SetDefaultZoomLevelPref(double level) {
// set this manually.
host_zoom_map_->SetDefaultZoomLevel(level);
default_zoom_changed_callbacks_.Notify();
if (zoom_event_manager_)
zoom_event_manager_->OnDefaultZoomLevelChanged();
}
double ChromeZoomLevelPrefs::GetDefaultZoomLevelPref() const {
......
......@@ -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",
]
......
......@@ -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
......@@ -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);
......
// 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_
......@@ -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'
],
}
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment