Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1051)

Unified Diff: chrome/browser/ui/zoom/zoom_controller.cc

Issue 10444040: Tracks changes to zoom icon and zoom percentage. Notifies browser window if the icon should be chan… (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Addressed comments in code reviews. Created 8 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « chrome/browser/ui/zoom/zoom_controller.h ('k') | chrome/browser/ui/zoom/zoom_observer.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/browser/ui/zoom/zoom_controller.cc
diff --git a/chrome/browser/ui/zoom/zoom_controller.cc b/chrome/browser/ui/zoom/zoom_controller.cc
new file mode 100644
index 0000000000000000000000000000000000000000..efe143d521da35edd24eab1a0ea32d2897bfe1e6
--- /dev/null
+++ b/chrome/browser/ui/zoom/zoom_controller.cc
@@ -0,0 +1,88 @@
+// 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.
+
+#include "chrome/browser/ui/zoom/zoom_controller.h"
+
+#include "chrome/browser/profiles/profile.h"
+#include "chrome/browser/ui/browser_finder.h"
+#include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h"
+#include "chrome/common/chrome_notification_types.h"
+#include "chrome/common/pref_names.h"
+#include "content/public/browser/notification_types.h"
+#include "content/public/browser/notification_details.h"
+#include "content/public/browser/notification_service.h"
+#include "content/public/browser/web_contents.h"
+#include "content/public/common/page_zoom.h"
+
+ZoomController::ZoomController(TabContentsWrapper* tab_contents)
+ : content::WebContentsObserver(tab_contents->web_contents()),
+ tab_contents_wrapper_(tab_contents),
+ delegate_(NULL) {
+ default_zoom_level_.Init(prefs::kDefaultZoomLevel,
+ tab_contents->profile()->GetPrefs(), this);
+ registrar_.Add(this, content::NOTIFICATION_ZOOM_LEVEL_CHANGED,
+ content::NotificationService::AllBrowserContextsAndSources());
+
+ UpdateState();
+}
+
+ZoomController::~ZoomController() {
+ default_zoom_level_.Destroy();
+ registrar_.RemoveAll();
+}
+
+void ZoomController::DidNavigateMainFrame(
+ const content::LoadCommittedDetails& details,
+ const content::FrameNavigateParams& params) {
+ // If the main frame's content has changed, the new page may have a different
+ // zoom level from the old one.
+ UpdateState();
+}
+
+void ZoomController::Observe(int type,
+ const content::NotificationSource& source,
+ const content::NotificationDetails& details) {
+ switch (type) {
+ case chrome::NOTIFICATION_PREF_CHANGED: {
+ std::string* pref_name = content::Details<std::string>(details).ptr();
+ DCHECK(pref_name && *pref_name == prefs::kDefaultZoomLevel);
+ }
+ // Fall through.
+ case content::NOTIFICATION_ZOOM_LEVEL_CHANGED:
+ UpdateState();
+ break;
+ default:
+ NOTREACHED();
+ }
+}
+
+void ZoomController::UpdateState() {
+ double currentZoomLevel =
tfarina 2012/05/31 23:21:00 nit: current_zoom_level. Please fix the other occu
Kyle Horimoto 2012/05/31 23:37:20 Done.
+ tab_contents_wrapper_->web_contents()->GetZoomLevel();
+ double defaultZoomLevel = default_zoom_level_.GetValue();
+
+ ZoomIconState state;
+ if (content::ZoomValuesEqual(currentZoomLevel, defaultZoomLevel))
+ state = NONE;
+ else if (currentZoomLevel > defaultZoomLevel)
+ state = ZOOM_PLUS_ICON;
+ else
+ state = ZOOM_MINUS_ICON;
+
+ bool dummy;
+ int zoom_percent = tab_contents_wrapper_->web_contents()->
+ GetZoomPercent(&dummy, &dummy);
+
+ if (state != zoom_icon_state_) {
+ zoom_icon_state_ = state;
+ if (delegate())
+ delegate()->OnZoomIconChanged(tab_contents_wrapper_, state);
+ }
+
+ if (zoom_percent != zoom_percent_) {
+ zoom_percent_ = zoom_percent;
+ if (delegate())
tfarina 2012/05/31 23:21:00 nit: use direct access, i.e delegate_, this is the
Kyle Horimoto 2012/05/31 23:37:20 Done.
+ delegate()->OnZoomChanged(tab_contents_wrapper_, zoom_percent);
+ }
+}
« no previous file with comments | « chrome/browser/ui/zoom/zoom_controller.h ('k') | chrome/browser/ui/zoom/zoom_observer.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698