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

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: Created 7 years, 11 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 #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::HostZoomMap::Observer,
24 public content::WebContentsObserver, 23 public content::WebContentsObserver,
25 public content::WebContentsUserData<ZoomController> { 24 public content::WebContentsUserData<ZoomController> {
26 public: 25 public:
27 virtual ~ZoomController(); 26 virtual ~ZoomController();
28 27
29 int zoom_percent() const { return zoom_percent_; } 28 int zoom_percent() const { return zoom_percent_; }
30 29
31 // Convenience method to quickly check if the tab's at default zoom. 30 // Convenience method to quickly check if the tab's at default zoom.
32 bool IsAtDefaultZoom() const; 31 bool IsAtDefaultZoom() const;
33 32
34 // Returns which image should be loaded for the current zoom level. 33 // Returns which image should be loaded for the current zoom level.
35 int GetResourceForZoomLevel() const; 34 int GetResourceForZoomLevel() const;
36 35
37 void set_observer(ZoomObserver* observer) { observer_ = observer; } 36 void set_observer(ZoomObserver* observer) { observer_ = observer; }
38 37
38 // content::HostZoomMap::Observer overrides:
39 virtual void OnZoomLevelChanged(const std::string& host) OVERRIDE;
40
39 // content::WebContentsObserver overrides: 41 // content::WebContentsObserver overrides:
40 virtual void DidNavigateMainFrame( 42 virtual void DidNavigateMainFrame(
41 const content::LoadCommittedDetails& details, 43 const content::LoadCommittedDetails& details,
42 const content::FrameNavigateParams& params) OVERRIDE; 44 const content::FrameNavigateParams& params) OVERRIDE;
43 45
44 // content::NotificationObserver overrides:
45 virtual void Observe(int type,
46 const content::NotificationSource& source,
47 const content::NotificationDetails& details) OVERRIDE;
48
49 private: 46 private:
50 explicit ZoomController(content::WebContents* web_contents); 47 explicit ZoomController(content::WebContents* web_contents);
51 friend class content::WebContentsUserData<ZoomController>; 48 friend class content::WebContentsUserData<ZoomController>;
52 friend class ZoomControllerTest; 49 friend class ZoomControllerTest;
53 50
54 // Updates the zoom icon and zoom percentage based on current values and 51 // Updates the zoom icon and zoom percentage based on current values and
55 // notifies the observer if changes have occurred. |host| may be empty, 52 // 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 53 // meaning the change should apply to ~all sites. If it is not empty, the
57 // change only affects sites with the given host. 54 // change only affects sites with the given host.
58 void UpdateState(const std::string& host); 55 void UpdateState(const std::string& host);
59 56
60 // The current zoom percentage. 57 // The current zoom percentage.
61 int zoom_percent_; 58 int zoom_percent_;
62 59
63 content::NotificationRegistrar registrar_;
64
65 // Used to access the default zoom level preference. 60 // Used to access the default zoom level preference.
66 DoublePrefMember default_zoom_level_; 61 DoublePrefMember default_zoom_level_;
67 62
68 // Observer receiving notifications on state changes. 63 // Observer receiving notifications on state changes.
69 ZoomObserver* observer_; 64 ZoomObserver* observer_;
70 65
71 DISALLOW_COPY_AND_ASSIGN(ZoomController); 66 DISALLOW_COPY_AND_ASSIGN(ZoomController);
72 }; 67 };
73 68
74 #endif // CHROME_BROWSER_UI_ZOOM_ZOOM_CONTROLLER_H_ 69 #endif // CHROME_BROWSER_UI_ZOOM_ZOOM_CONTROLLER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698