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

Side by Side 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: Rebased Created 8 years, 6 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
« 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 »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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_controller.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 ZoomController::ZoomController(TabContentsWrapper* tab_contents)
19 : content::WebContentsObserver(tab_contents->web_contents()),
20 zoom_icon_state_(NONE),
21 zoom_percent_(100),
22 tab_contents_wrapper_(tab_contents),
23 observer_(NULL) {
24 default_zoom_level_.Init(prefs::kDefaultZoomLevel,
25 tab_contents->profile()->GetPrefs(), this);
26 registrar_.Add(this, content::NOTIFICATION_ZOOM_LEVEL_CHANGED,
27 content::NotificationService::AllBrowserContextsAndSources());
28
29 UpdateState();
30 }
31
32 ZoomController::~ZoomController() {
33 default_zoom_level_.Destroy();
34 registrar_.RemoveAll();
35 }
36
37 void ZoomController::DidNavigateMainFrame(
38 const content::LoadCommittedDetails& details,
39 const content::FrameNavigateParams& params) {
40 // If the main frame's content has changed, the new page may have a different
41 // zoom level from the old one.
42 UpdateState();
43 }
44
45 void ZoomController::Observe(int type,
46 const content::NotificationSource& source,
47 const content::NotificationDetails& details) {
48 switch (type) {
49 case chrome::NOTIFICATION_PREF_CHANGED: {
50 std::string* pref_name = content::Details<std::string>(details).ptr();
51 DCHECK(pref_name && *pref_name == prefs::kDefaultZoomLevel);
52 }
53 // Fall through.
54 case content::NOTIFICATION_ZOOM_LEVEL_CHANGED:
55 UpdateState();
56 break;
57 default:
58 NOTREACHED();
59 }
60 }
61
62 void ZoomController::UpdateState() {
63 double current_zoom_level =
64 tab_contents_wrapper_->web_contents()->GetZoomLevel();
65 double default_zoom_level = default_zoom_level_.GetValue();
66
67 ZoomIconState state;
68 if (content::ZoomValuesEqual(current_zoom_level, default_zoom_level))
69 state = NONE;
70 else if (current_zoom_level > default_zoom_level)
71 state = ZOOM_PLUS_ICON;
72 else
73 state = ZOOM_MINUS_ICON;
74
75 bool dummy;
76 int zoom_percent = tab_contents_wrapper_->web_contents()->
77 GetZoomPercent(&dummy, &dummy);
78
79 if (state != zoom_icon_state_) {
80 zoom_icon_state_ = state;
81 if (observer_)
82 observer_->OnZoomIconChanged(tab_contents_wrapper_, state);
83 }
84
85 if (zoom_percent != zoom_percent_) {
86 zoom_percent_ = zoom_percent;
87 if (observer_)
88 observer_->OnZoomChanged(tab_contents_wrapper_,
89 zoom_percent,
90 state != NONE);
91 }
92 }
OLDNEW
« 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