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

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

Issue 10959054: Switch ZoomTabHelper to use WebContentsUserData. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: rebase Created 8 years, 2 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 #include "grit/theme_resources.h"
19 19
20 ZoomController::ZoomController(TabContents* tab_contents) 20 int ZoomController::kUserDataKey;
21 : content::WebContentsObserver(tab_contents->web_contents()), 21
22 ZoomController::ZoomController(content::WebContents* web_contents)
23 : content::WebContentsObserver(web_contents),
22 zoom_percent_(100), 24 zoom_percent_(100),
23 tab_contents_(tab_contents),
24 observer_(NULL) { 25 observer_(NULL) {
25 default_zoom_level_.Init(prefs::kDefaultZoomLevel, 26 default_zoom_level_.Init(prefs::kDefaultZoomLevel,
26 tab_contents->profile()->GetPrefs(), this); 27 Profile::FromBrowserContext(
28 web_contents->GetBrowserContext())->GetPrefs(),
29 this);
27 registrar_.Add(this, content::NOTIFICATION_ZOOM_LEVEL_CHANGED, 30 registrar_.Add(this, content::NOTIFICATION_ZOOM_LEVEL_CHANGED,
28 content::NotificationService::AllBrowserContextsAndSources()); 31 content::NotificationService::AllBrowserContextsAndSources());
29 32
30 UpdateState(false); 33 UpdateState(false);
31 } 34 }
32 35
33 ZoomController::~ZoomController() { 36 ZoomController::~ZoomController() {
34 default_zoom_level_.Destroy(); 37 default_zoom_level_.Destroy();
35 registrar_.RemoveAll(); 38 registrar_.RemoveAll();
36 } 39 }
37 40
38 bool ZoomController::IsAtDefaultZoom() const { 41 bool ZoomController::IsAtDefaultZoom() const {
39 return content::ZoomValuesEqual(tab_contents_->web_contents()->GetZoomLevel(), 42 return content::ZoomValuesEqual(web_contents()->GetZoomLevel(),
40 default_zoom_level_.GetValue()); 43 default_zoom_level_.GetValue());
41 } 44 }
42 45
43 int ZoomController::GetResourceForZoomLevel() const { 46 int ZoomController::GetResourceForZoomLevel() const {
44 DCHECK(!IsAtDefaultZoom()); 47 DCHECK(!IsAtDefaultZoom());
45 double zoom = tab_contents_->web_contents()->GetZoomLevel(); 48 double zoom = web_contents()->GetZoomLevel();
46 return zoom > default_zoom_level_.GetValue() ? IDR_ZOOM_PLUS : IDR_ZOOM_MINUS; 49 return zoom > default_zoom_level_.GetValue() ? IDR_ZOOM_PLUS : IDR_ZOOM_MINUS;
47 } 50 }
48 51
49 void ZoomController::DidNavigateMainFrame( 52 void ZoomController::DidNavigateMainFrame(
50 const content::LoadCommittedDetails& details, 53 const content::LoadCommittedDetails& details,
51 const content::FrameNavigateParams& params) { 54 const content::FrameNavigateParams& params) {
52 // If the main frame's content has changed, the new page may have a different 55 // If the main frame's content has changed, the new page may have a different
53 // zoom level from the old one. 56 // zoom level from the old one.
54 UpdateState(false); 57 UpdateState(false);
55 } 58 }
(...skipping 11 matching lines...) Expand all
67 case content::NOTIFICATION_ZOOM_LEVEL_CHANGED: 70 case content::NOTIFICATION_ZOOM_LEVEL_CHANGED:
68 UpdateState(!content::Details<std::string>(details)->empty()); 71 UpdateState(!content::Details<std::string>(details)->empty());
69 break; 72 break;
70 default: 73 default:
71 NOTREACHED(); 74 NOTREACHED();
72 } 75 }
73 } 76 }
74 77
75 void ZoomController::UpdateState(bool can_show_bubble) { 78 void ZoomController::UpdateState(bool can_show_bubble) {
76 bool dummy; 79 bool dummy;
77 zoom_percent_ = tab_contents_->web_contents()->GetZoomPercent(&dummy, &dummy); 80 zoom_percent_ = web_contents()->GetZoomPercent(&dummy, &dummy);
78 81
79 if (observer_) 82 if (observer_)
80 observer_->OnZoomChanged(tab_contents_, can_show_bubble); 83 observer_->OnZoomChanged(web_contents(), can_show_bubble);
81 } 84 }
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