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

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

Issue 10979019: [gtk] fix zoom bubble showing up on wrong window (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: . 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
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/host_zoom_map.h"
13 #include "content/public/browser/notification_types.h" 14 #include "content/public/browser/notification_types.h"
14 #include "content/public/browser/notification_details.h" 15 #include "content/public/browser/notification_details.h"
15 #include "content/public/browser/notification_service.h" 16 #include "content/public/browser/notification_service.h"
16 #include "content/public/browser/web_contents.h" 17 #include "content/public/browser/web_contents.h"
17 #include "content/public/common/page_zoom.h" 18 #include "content/public/common/page_zoom.h"
18 #include "grit/theme_resources.h" 19 #include "grit/theme_resources.h"
20 #include "net/base/net_util.h"
19 21
20 int ZoomController::kUserDataKey; 22 int ZoomController::kUserDataKey;
21 23
22 ZoomController::ZoomController(content::WebContents* web_contents) 24 ZoomController::ZoomController(content::WebContents* web_contents)
23 : content::WebContentsObserver(web_contents), 25 : content::WebContentsObserver(web_contents),
24 zoom_percent_(100), 26 zoom_percent_(100),
25 observer_(NULL) { 27 observer_(NULL) {
26 default_zoom_level_.Init(prefs::kDefaultZoomLevel, 28 Profile* profile =
27 Profile::FromBrowserContext( 29 Profile::FromBrowserContext(web_contents->GetBrowserContext());
28 web_contents->GetBrowserContext())->GetPrefs(), 30 default_zoom_level_.Init(prefs::kDefaultZoomLevel, profile->GetPrefs(), this);
29 this); 31
32 content::HostZoomMap* zoom_map =
33 content::HostZoomMap::GetForBrowserContext(profile);
30 registrar_.Add(this, content::NOTIFICATION_ZOOM_LEVEL_CHANGED, 34 registrar_.Add(this, content::NOTIFICATION_ZOOM_LEVEL_CHANGED,
31 content::NotificationService::AllBrowserContextsAndSources()); 35 content::Source<content::HostZoomMap>(zoom_map));
32 36
33 UpdateState(false); 37 UpdateState(std::string());
34 } 38 }
35 39
36 ZoomController::~ZoomController() { 40 ZoomController::~ZoomController() {
37 default_zoom_level_.Destroy(); 41 default_zoom_level_.Destroy();
38 registrar_.RemoveAll(); 42 registrar_.RemoveAll();
39 } 43 }
40 44
41 bool ZoomController::IsAtDefaultZoom() const { 45 bool ZoomController::IsAtDefaultZoom() const {
42 return content::ZoomValuesEqual(web_contents()->GetZoomLevel(), 46 return content::ZoomValuesEqual(web_contents()->GetZoomLevel(),
43 default_zoom_level_.GetValue()); 47 default_zoom_level_.GetValue());
44 } 48 }
45 49
46 int ZoomController::GetResourceForZoomLevel() const { 50 int ZoomController::GetResourceForZoomLevel() const {
47 DCHECK(!IsAtDefaultZoom()); 51 DCHECK(!IsAtDefaultZoom());
48 double zoom = web_contents()->GetZoomLevel(); 52 double zoom = web_contents()->GetZoomLevel();
49 return zoom > default_zoom_level_.GetValue() ? IDR_ZOOM_PLUS : IDR_ZOOM_MINUS; 53 return zoom > default_zoom_level_.GetValue() ? IDR_ZOOM_PLUS : IDR_ZOOM_MINUS;
50 } 54 }
51 55
52 void ZoomController::DidNavigateMainFrame( 56 void ZoomController::DidNavigateMainFrame(
53 const content::LoadCommittedDetails& details, 57 const content::LoadCommittedDetails& details,
54 const content::FrameNavigateParams& params) { 58 const content::FrameNavigateParams& params) {
55 // If the main frame's content has changed, the new page may have a different 59 // If the main frame's content has changed, the new page may have a different
56 // zoom level from the old one. 60 // zoom level from the old one.
57 UpdateState(false); 61 UpdateState(std::string());
58 } 62 }
59 63
60 void ZoomController::Observe(int type, 64 void ZoomController::Observe(int type,
61 const content::NotificationSource& source, 65 const content::NotificationSource& source,
62 const content::NotificationDetails& details) { 66 const content::NotificationDetails& details) {
63 switch (type) { 67 switch (type) {
64 case chrome::NOTIFICATION_PREF_CHANGED: { 68 case chrome::NOTIFICATION_PREF_CHANGED: {
65 std::string* pref_name = content::Details<std::string>(details).ptr(); 69 std::string* pref_name = content::Details<std::string>(details).ptr();
66 DCHECK(pref_name && *pref_name == prefs::kDefaultZoomLevel); 70 DCHECK(pref_name && *pref_name == prefs::kDefaultZoomLevel);
67 UpdateState(false); 71 UpdateState(std::string());
68 break; 72 break;
69 } 73 }
70 case content::NOTIFICATION_ZOOM_LEVEL_CHANGED: 74 case content::NOTIFICATION_ZOOM_LEVEL_CHANGED:
71 UpdateState(!content::Details<std::string>(details)->empty()); 75 UpdateState(*content::Details<std::string>(details).ptr());
72 break; 76 break;
73 default: 77 default:
74 NOTREACHED(); 78 NOTREACHED();
75 } 79 }
76 } 80 }
77 81
78 void ZoomController::UpdateState(bool can_show_bubble) { 82 void ZoomController::UpdateState(const std::string& host) {
83 if (!host.empty() &&
84 host != net::GetHostOrSpecFromURL(web_contents()->GetURL())) {
85 return;
86 }
87
79 bool dummy; 88 bool dummy;
80 zoom_percent_ = web_contents()->GetZoomPercent(&dummy, &dummy); 89 zoom_percent_ = web_contents()->GetZoomPercent(&dummy, &dummy);
81 90
82 if (observer_) 91 if (observer_)
83 observer_->OnZoomChanged(web_contents(), can_show_bubble); 92 observer_->OnZoomChanged(web_contents(), !host.empty());
84 } 93 }
OLDNEW
« no previous file with comments | « chrome/browser/ui/zoom/zoom_controller.h ('k') | content/browser/web_contents/web_contents_impl.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698