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

Side by Side Diff: chrome/browser/ui/zoom/zoom_controller.cc

Issue 10736028: Refactor browser window zoom handling and enable zoom icon on all platforms. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: . Created 8 years, 4 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 | Annotate | Revision Log
« 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
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "chrome/browser/ui/zoom/zoom_controller.h" 5 #include "chrome/browser/ui/zoom/zoom_controller.h"
6 6
7 #include "chrome/browser/prefs/pref_service.h" 7 #include "chrome/browser/prefs/pref_service.h"
8 #include "chrome/browser/profiles/profile.h" 8 #include "chrome/browser/profiles/profile.h"
9 #include "chrome/browser/ui/browser_finder.h" 9 #include "chrome/browser/ui/browser_finder.h"
10 #include "chrome/browser/ui/tab_contents/tab_contents.h" 10 #include "chrome/browser/ui/tab_contents/tab_contents.h"
11 #include "chrome/common/chrome_notification_types.h" 11 #include "chrome/common/chrome_notification_types.h"
12 #include "chrome/common/pref_names.h" 12 #include "chrome/common/pref_names.h"
13 #include "content/public/browser/notification_types.h" 13 #include "content/public/browser/notification_types.h"
14 #include "content/public/browser/notification_details.h" 14 #include "content/public/browser/notification_details.h"
15 #include "content/public/browser/notification_service.h" 15 #include "content/public/browser/notification_service.h"
16 #include "content/public/browser/web_contents.h" 16 #include "content/public/browser/web_contents.h"
17 #include "content/public/common/page_zoom.h" 17 #include "content/public/common/page_zoom.h"
18 #include "grit/theme_resources.h"
18 19
19 ZoomController::ZoomController(TabContents* tab_contents) 20 ZoomController::ZoomController(TabContents* tab_contents)
20 : content::WebContentsObserver(tab_contents->web_contents()), 21 : content::WebContentsObserver(tab_contents->web_contents()),
21 zoom_icon_state_(NONE),
22 zoom_percent_(100), 22 zoom_percent_(100),
23 tab_contents_(tab_contents), 23 tab_contents_(tab_contents),
24 observer_(NULL) { 24 observer_(NULL) {
25 default_zoom_level_.Init(prefs::kDefaultZoomLevel, 25 default_zoom_level_.Init(prefs::kDefaultZoomLevel,
26 tab_contents->profile()->GetPrefs(), this); 26 tab_contents->profile()->GetPrefs(), this);
27 registrar_.Add(this, content::NOTIFICATION_ZOOM_LEVEL_CHANGED, 27 registrar_.Add(this, content::NOTIFICATION_ZOOM_LEVEL_CHANGED,
28 content::NotificationService::AllBrowserContextsAndSources()); 28 content::NotificationService::AllBrowserContextsAndSources());
29 29
30 UpdateState(false); 30 UpdateState(false);
31 } 31 }
32 32
33 ZoomController::~ZoomController() { 33 ZoomController::~ZoomController() {
34 default_zoom_level_.Destroy(); 34 default_zoom_level_.Destroy();
35 registrar_.RemoveAll(); 35 registrar_.RemoveAll();
36 } 36 }
37 37
38 bool ZoomController::IsAtDefaultZoom() const {
39 return content::ZoomValuesEqual(tab_contents_->web_contents()->GetZoomLevel(),
40 default_zoom_level_.GetValue());
41 }
42
43 int ZoomController::GetResourceForZoomLevel() const {
44 DCHECK(!IsAtDefaultZoom());
45 double zoom = tab_contents_->web_contents()->GetZoomLevel();
46 return zoom > default_zoom_level_.GetValue() ? IDR_ZOOM_PLUS : IDR_ZOOM_MINUS;
47 }
48
38 void ZoomController::DidNavigateMainFrame( 49 void ZoomController::DidNavigateMainFrame(
39 const content::LoadCommittedDetails& details, 50 const content::LoadCommittedDetails& details,
40 const content::FrameNavigateParams& params) { 51 const content::FrameNavigateParams& params) {
41 // If the main frame's content has changed, the new page may have a different 52 // If the main frame's content has changed, the new page may have a different
42 // zoom level from the old one. 53 // zoom level from the old one.
43 UpdateState(false); 54 UpdateState(false);
44 } 55 }
45 56
46 void ZoomController::Observe(int type, 57 void ZoomController::Observe(int type,
47 const content::NotificationSource& source, 58 const content::NotificationSource& source,
48 const content::NotificationDetails& details) { 59 const content::NotificationDetails& details) {
49 switch (type) { 60 switch (type) {
50 case chrome::NOTIFICATION_PREF_CHANGED: { 61 case chrome::NOTIFICATION_PREF_CHANGED: {
51 std::string* pref_name = content::Details<std::string>(details).ptr(); 62 std::string* pref_name = content::Details<std::string>(details).ptr();
52 DCHECK(pref_name && *pref_name == prefs::kDefaultZoomLevel); 63 DCHECK(pref_name && *pref_name == prefs::kDefaultZoomLevel);
53 UpdateState(false); 64 UpdateState(false);
54 break; 65 break;
55 } 66 }
56 case content::NOTIFICATION_ZOOM_LEVEL_CHANGED: 67 case content::NOTIFICATION_ZOOM_LEVEL_CHANGED:
57 UpdateState(!content::Details<std::string>(details)->empty()); 68 UpdateState(!content::Details<std::string>(details)->empty());
58 break; 69 break;
59 default: 70 default:
60 NOTREACHED(); 71 NOTREACHED();
61 } 72 }
62 } 73 }
63 74
64 void ZoomController::UpdateState(bool can_show_bubble) { 75 void ZoomController::UpdateState(bool can_show_bubble) {
65 double current_zoom_level = tab_contents_->web_contents()->GetZoomLevel(); 76 bool dummy;
66 double default_zoom_level = default_zoom_level_.GetValue(); 77 zoom_percent_ = tab_contents_->web_contents()->GetZoomPercent(&dummy, &dummy);
67 78
68 ZoomIconState state; 79 if (observer_)
69 if (content::ZoomValuesEqual(current_zoom_level, default_zoom_level)) 80 observer_->OnZoomChanged(tab_contents_, can_show_bubble);
70 state = NONE;
71 else if (current_zoom_level > default_zoom_level)
72 state = ZOOM_PLUS_ICON;
73 else
74 state = ZOOM_MINUS_ICON;
75
76 bool dummy;
77 int zoom_percent = tab_contents_->web_contents()->
78 GetZoomPercent(&dummy, &dummy);
79
80 if (state != zoom_icon_state_) {
81 zoom_icon_state_ = state;
82 if (observer_)
83 observer_->OnZoomIconChanged(tab_contents_, state);
84 }
85
86 if (zoom_percent != zoom_percent_) {
87 zoom_percent_ = zoom_percent;
88 if (observer_)
89 observer_->OnZoomChanged(tab_contents_,
90 zoom_percent,
91 can_show_bubble && state != NONE);
92 }
93 } 81 }
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