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

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

Issue 12039058: content: convert zoom notifications to observer usage (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: rebase Created 7 years, 10 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/views/wrench_menu.cc ('k') | chrome/browser/ui/zoom/zoom_controller.cc » ('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 #ifndef CHROME_BROWSER_UI_ZOOM_ZOOM_CONTROLLER_H_ 5 #ifndef CHROME_BROWSER_UI_ZOOM_ZOOM_CONTROLLER_H_
6 #define CHROME_BROWSER_UI_ZOOM_ZOOM_CONTROLLER_H_ 6 #define CHROME_BROWSER_UI_ZOOM_ZOOM_CONTROLLER_H_
7 7
8 #include "base/basictypes.h" 8 #include "base/basictypes.h"
9 #include "base/compiler_specific.h" 9 #include "base/compiler_specific.h"
10 #include "base/prefs/public/pref_member.h" 10 #include "base/prefs/public/pref_member.h"
11 #include "content/public/browser/notification_observer.h" 11 #include "content/public/browser/host_zoom_map.h"
12 #include "content/public/browser/notification_registrar.h"
13 #include "content/public/browser/web_contents_observer.h" 12 #include "content/public/browser/web_contents_observer.h"
14 #include "content/public/browser/web_contents_user_data.h" 13 #include "content/public/browser/web_contents_user_data.h"
15 14
16 class ZoomObserver; 15 class ZoomObserver;
17 16
18 namespace content { 17 namespace content {
19 class WebContents; 18 class WebContents;
20 } 19 }
21 20
22 // Per-tab class to manage the Omnibox zoom icon. 21 // Per-tab class to manage the Omnibox zoom icon.
23 class ZoomController : public content::NotificationObserver, 22 class ZoomController : public content::WebContentsObserver,
24 public content::WebContentsObserver,
25 public content::WebContentsUserData<ZoomController> { 23 public content::WebContentsUserData<ZoomController> {
26 public: 24 public:
27 virtual ~ZoomController(); 25 virtual ~ZoomController();
28 26
29 int zoom_percent() const { return zoom_percent_; } 27 int zoom_percent() const { return zoom_percent_; }
30 28
31 // Convenience method to quickly check if the tab's at default zoom. 29 // Convenience method to quickly check if the tab's at default zoom.
32 bool IsAtDefaultZoom() const; 30 bool IsAtDefaultZoom() const;
33 31
34 // Returns which image should be loaded for the current zoom level. 32 // Returns which image should be loaded for the current zoom level.
35 int GetResourceForZoomLevel() const; 33 int GetResourceForZoomLevel() const;
36 34
37 void set_observer(ZoomObserver* observer) { observer_ = observer; } 35 void set_observer(ZoomObserver* observer) { observer_ = observer; }
38 36
39 // content::WebContentsObserver overrides: 37 // content::WebContentsObserver overrides:
40 virtual void DidNavigateMainFrame( 38 virtual void DidNavigateMainFrame(
41 const content::LoadCommittedDetails& details, 39 const content::LoadCommittedDetails& details,
42 const content::FrameNavigateParams& params) OVERRIDE; 40 const content::FrameNavigateParams& params) OVERRIDE;
43 41
44 // content::NotificationObserver overrides:
45 virtual void Observe(int type,
46 const content::NotificationSource& source,
47 const content::NotificationDetails& details) OVERRIDE;
48
49 private: 42 private:
50 explicit ZoomController(content::WebContents* web_contents); 43 explicit ZoomController(content::WebContents* web_contents);
51 friend class content::WebContentsUserData<ZoomController>; 44 friend class content::WebContentsUserData<ZoomController>;
52 friend class ZoomControllerTest; 45 friend class ZoomControllerTest;
53 46
47 void OnZoomLevelChanged(const std::string& host);
48
54 // Updates the zoom icon and zoom percentage based on current values and 49 // Updates the zoom icon and zoom percentage based on current values and
55 // notifies the observer if changes have occurred. |host| may be empty, 50 // notifies the observer if changes have occurred. |host| may be empty,
56 // meaning the change should apply to ~all sites. If it is not empty, the 51 // meaning the change should apply to ~all sites. If it is not empty, the
57 // change only affects sites with the given host. 52 // change only affects sites with the given host.
58 void UpdateState(const std::string& host); 53 void UpdateState(const std::string& host);
59 54
60 // The current zoom percentage. 55 // The current zoom percentage.
61 int zoom_percent_; 56 int zoom_percent_;
62 57
63 content::NotificationRegistrar registrar_;
64
65 // Used to access the default zoom level preference. 58 // Used to access the default zoom level preference.
66 DoublePrefMember default_zoom_level_; 59 DoublePrefMember default_zoom_level_;
67 60
68 // Observer receiving notifications on state changes. 61 // Observer receiving notifications on state changes.
69 ZoomObserver* observer_; 62 ZoomObserver* observer_;
70 63
64 content::BrowserContext* browser_context_;
65
66 content::HostZoomMap::ZoomLevelChangedCallback zoom_callback_;
67
71 DISALLOW_COPY_AND_ASSIGN(ZoomController); 68 DISALLOW_COPY_AND_ASSIGN(ZoomController);
72 }; 69 };
73 70
74 #endif // CHROME_BROWSER_UI_ZOOM_ZOOM_CONTROLLER_H_ 71 #endif // CHROME_BROWSER_UI_ZOOM_ZOOM_CONTROLLER_H_
OLDNEW
« no previous file with comments | « chrome/browser/ui/views/wrench_menu.cc ('k') | chrome/browser/ui/zoom/zoom_controller.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698