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