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

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: fix mac Created 8 years, 5 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
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/profiles/profile.h" 7 #include "chrome/browser/profiles/profile.h"
8 #include "chrome/browser/ui/browser_finder.h" 8 #include "chrome/browser/ui/browser_finder.h"
9 #include "chrome/browser/ui/tab_contents/tab_contents.h" 9 #include "chrome/browser/ui/tab_contents/tab_contents.h"
10 #include "chrome/common/chrome_notification_types.h" 10 #include "chrome/common/chrome_notification_types.h"
11 #include "chrome/common/pref_names.h" 11 #include "chrome/common/pref_names.h"
12 #include "content/public/browser/notification_types.h" 12 #include "content/public/browser/notification_types.h"
13 #include "content/public/browser/notification_details.h" 13 #include "content/public/browser/notification_details.h"
14 #include "content/public/browser/notification_service.h" 14 #include "content/public/browser/notification_service.h"
15 #include "content/public/browser/web_contents.h" 15 #include "content/public/browser/web_contents.h"
16 #include "content/public/common/page_zoom.h" 16 #include "content/public/common/page_zoom.h"
17 17
18 ZoomController::ZoomController(TabContents* tab_contents) 18 ZoomController::ZoomController(TabContents* tab_contents)
19 : content::WebContentsObserver(tab_contents->web_contents()), 19 : content::WebContentsObserver(tab_contents->web_contents()),
20 zoom_icon_state_(NONE),
21 zoom_percent_(100), 20 zoom_percent_(100),
22 tab_contents_(tab_contents), 21 tab_contents_(tab_contents),
23 observer_(NULL) { 22 observer_(NULL) {
24 default_zoom_level_.Init(prefs::kDefaultZoomLevel, 23 default_zoom_level_.Init(prefs::kDefaultZoomLevel,
25 tab_contents->profile()->GetPrefs(), this); 24 tab_contents->profile()->GetPrefs(), this);
26 registrar_.Add(this, content::NOTIFICATION_ZOOM_LEVEL_CHANGED, 25 registrar_.Add(this, content::NOTIFICATION_ZOOM_LEVEL_CHANGED,
27 content::NotificationService::AllBrowserContextsAndSources()); 26 content::NotificationService::AllBrowserContextsAndSources());
28 27
29 UpdateState(false); 28 UpdateState(false);
30 } 29 }
31 30
32 ZoomController::~ZoomController() { 31 ZoomController::~ZoomController() {
33 default_zoom_level_.Destroy(); 32 default_zoom_level_.Destroy();
34 registrar_.RemoveAll(); 33 registrar_.RemoveAll();
35 } 34 }
36 35
36 bool ZoomController::IsAtDefaultZoom() const {
37 return content::ZoomValuesEqual(tab_contents_->web_contents()->GetZoomLevel(),
38 default_zoom_level_.GetValue());
39 }
40
37 void ZoomController::DidNavigateMainFrame( 41 void ZoomController::DidNavigateMainFrame(
38 const content::LoadCommittedDetails& details, 42 const content::LoadCommittedDetails& details,
39 const content::FrameNavigateParams& params) { 43 const content::FrameNavigateParams& params) {
40 // If the main frame's content has changed, the new page may have a different 44 // If the main frame's content has changed, the new page may have a different
41 // zoom level from the old one. 45 // zoom level from the old one.
42 UpdateState(false); 46 UpdateState(false);
43 } 47 }
44 48
45 void ZoomController::Observe(int type, 49 void ZoomController::Observe(int type,
46 const content::NotificationSource& source, 50 const content::NotificationSource& source,
47 const content::NotificationDetails& details) { 51 const content::NotificationDetails& details) {
48 switch (type) { 52 switch (type) {
49 case chrome::NOTIFICATION_PREF_CHANGED: { 53 case chrome::NOTIFICATION_PREF_CHANGED: {
50 std::string* pref_name = content::Details<std::string>(details).ptr(); 54 std::string* pref_name = content::Details<std::string>(details).ptr();
51 DCHECK(pref_name && *pref_name == prefs::kDefaultZoomLevel); 55 DCHECK(pref_name && *pref_name == prefs::kDefaultZoomLevel);
52 UpdateState(false); 56 UpdateState(false);
53 break; 57 break;
54 } 58 }
55 case content::NOTIFICATION_ZOOM_LEVEL_CHANGED: 59 case content::NOTIFICATION_ZOOM_LEVEL_CHANGED:
56 UpdateState(!content::Details<std::string>(details)->empty()); 60 UpdateState(!content::Details<std::string>(details)->empty());
57 break; 61 break;
58 default: 62 default:
59 NOTREACHED(); 63 NOTREACHED();
60 } 64 }
61 } 65 }
62 66
63 void ZoomController::UpdateState(bool can_show_bubble) { 67 void ZoomController::UpdateState(bool can_show_bubble) {
64 double current_zoom_level = tab_contents_->web_contents()->GetZoomLevel(); 68 bool dummy;
65 double default_zoom_level = default_zoom_level_.GetValue(); 69 zoom_percent_ = tab_contents_->web_contents()->GetZoomPercent(&dummy, &dummy);
66 70
67 ZoomIconState state; 71 if (observer_)
68 if (content::ZoomValuesEqual(current_zoom_level, default_zoom_level)) 72 observer_->OnZoomChanged(tab_contents_, can_show_bubble);
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_->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_, state);
83 }
84
85 if (zoom_percent != zoom_percent_) {
86 zoom_percent_ = zoom_percent;
87 if (observer_)
88 observer_->OnZoomChanged(tab_contents_,
89 zoom_percent,
90 can_show_bubble && state != NONE);
91 }
92 } 73 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698