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

Side by Side Diff: chrome/browser/ui/zoom/zoom_tab_helper.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: 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 unified diff | Download patch
OLDNEW
(Empty)
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "chrome/browser/ui/zoom/zoom_tab_helper.h"
6
7 #include "chrome/browser/profiles/profile.h"
8 #include "chrome/browser/ui/browser_finder.h"
9 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h"
10 #include "chrome/common/chrome_notification_types.h"
11 #include "chrome/common/pref_names.h"
12 #include "content/public/browser/notification_types.h"
13 #include "content/public/browser/notification_details.h"
14 #include "content/public/browser/notification_service.h"
15 #include "content/public/browser/web_contents.h"
16 #include "content/public/common/page_zoom.h"
17
18 ZoomTabHelper::ZoomTabHelper(TabContentsWrapper* tab_contents)
19 : content::WebContentsObserver(tab_contents->web_contents()),
20 tab_contents_wrapper_(tab_contents),
21 delegate_(NULL) {
22 default_zoom_level_.Init(prefs::kDefaultZoomLevel,
23 tab_contents->profile()->GetPrefs(), this);
24 registrar_.Add(this, content::NOTIFICATION_ZOOM_LEVEL_CHANGED,
25 content::NotificationService::AllBrowserContextsAndSources());
26
27 UpdateState();
28 }
29
30 ZoomTabHelper::~ZoomTabHelper() {
31 default_zoom_level_.Destroy();
32 registrar_.RemoveAll();
33 }
34
35 void ZoomTabHelper::DidNavigateMainFrame(
36 const content::LoadCommittedDetails& details,
37 const content::FrameNavigateParams& params) {
38 // If the main frame's content has changed, the new page may have a different
39 // zoom level from the old one.
40 UpdateState();
41 }
42
43 void ZoomTabHelper::Observe(int type,
44 const content::NotificationSource& source,
45 const content::NotificationDetails& details) {
46 switch (type) {
47 case chrome::NOTIFICATION_PREF_CHANGED: {
48 std::string* pref_name = content::Details<std::string>(details).ptr();
49 DCHECK(pref_name && *pref_name == prefs::kDefaultZoomLevel);
50 }
51 // Fall through.
52 case content::NOTIFICATION_ZOOM_LEVEL_CHANGED:
53 UpdateState();
54 break;
55 default:
56 NOTREACHED();
57 }
58 }
59
60 void ZoomTabHelper::UpdateState() {
61 double currentZoomLevel =
62 tab_contents_wrapper_->web_contents()->GetZoomLevel();
63 double defaultZoomLevel = default_zoom_level_.GetValue();
64
65 ZoomIconState state;
66 if (content::ZoomValuesEqual(currentZoomLevel, defaultZoomLevel))
67 state = NONE;
68 else if (currentZoomLevel > defaultZoomLevel)
69 state = ZOOM_PLUS_ICON;
70 else
71 state = ZOOM_MINUS_ICON;
72
73 bool dummy;
74 int zoomPercent = tab_contents_wrapper_->web_contents()->
75 GetZoomPercent(&dummy, &dummy);
76
77 if (state != zoom_icon_state_) {
78 zoom_icon_state_ = state;
79 if (delegate())
80 delegate()->ZoomIconStateChanged(tab_contents_wrapper_,
81 state,
82 zoomPercent);
83 }
84
85 if (zoomPercent != zoom_percent_) {
86 zoom_percent_ = zoomPercent;
87 if (delegate())
88 delegate()->ZoomChanged(tab_contents_wrapper_, zoomPercent);
89 }
90 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698