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