| 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 "chrome/browser/api/prefs/pref_member.h" | 10 #include "chrome/browser/api/prefs/pref_member.h" |
| 11 #include "chrome/browser/tab_contents/web_contents_user_data.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 | 15 |
| 15 class TabContents; | |
| 16 class ZoomObserver; | 16 class ZoomObserver; |
| 17 | 17 |
| 18 namespace content { |
| 19 class WebContents; |
| 20 } |
| 21 |
| 18 // Per-tab class to manage the Omnibox zoom icon. | 22 // Per-tab class to manage the Omnibox zoom icon. |
| 19 class ZoomController : public content::NotificationObserver, | 23 class ZoomController : public content::NotificationObserver, |
| 20 public content::WebContentsObserver { | 24 public content::WebContentsObserver, |
| 25 public WebContentsUserData<ZoomController> { |
| 21 public: | 26 public: |
| 22 explicit ZoomController(TabContents* tab_contents); | |
| 23 virtual ~ZoomController(); | 27 virtual ~ZoomController(); |
| 24 | 28 |
| 25 int zoom_percent() const { return zoom_percent_; } | 29 int zoom_percent() const { return zoom_percent_; } |
| 26 | 30 |
| 27 // Convenience method to quickly check if the tab's at default zoom. | 31 // Convenience method to quickly check if the tab's at default zoom. |
| 28 bool IsAtDefaultZoom() const; | 32 bool IsAtDefaultZoom() const; |
| 29 | 33 |
| 30 // Returns which image should be loaded for the current zoom level. | 34 // Returns which image should be loaded for the current zoom level. |
| 31 int GetResourceForZoomLevel() const; | 35 int GetResourceForZoomLevel() const; |
| 32 | 36 |
| 33 void set_observer(ZoomObserver* observer) { observer_ = observer; } | 37 void set_observer(ZoomObserver* observer) { observer_ = observer; } |
| 34 | 38 |
| 35 private: | 39 private: |
| 40 explicit ZoomController(content::WebContents* web_contents); |
| 41 static int kUserDataKey; |
| 42 friend class WebContentsUserData<ZoomController>; |
| 43 |
| 36 // content::WebContentsObserver overrides: | 44 // content::WebContentsObserver overrides: |
| 37 virtual void DidNavigateMainFrame( | 45 virtual void DidNavigateMainFrame( |
| 38 const content::LoadCommittedDetails& details, | 46 const content::LoadCommittedDetails& details, |
| 39 const content::FrameNavigateParams& params) OVERRIDE; | 47 const content::FrameNavigateParams& params) OVERRIDE; |
| 40 | 48 |
| 41 // content::NotificationObserver overrides: | 49 // content::NotificationObserver overrides: |
| 42 virtual void Observe(int type, | 50 virtual void Observe(int type, |
| 43 const content::NotificationSource& source, | 51 const content::NotificationSource& source, |
| 44 const content::NotificationDetails& details) OVERRIDE; | 52 const content::NotificationDetails& details) OVERRIDE; |
| 45 | 53 |
| 46 // Updates the zoom icon and zoom percentage based on current values and | 54 // Updates the zoom icon and zoom percentage based on current values and |
| 47 // notifies the observer if changes have occurred. |can_show_bubble| will be | 55 // notifies the observer if changes have occurred. |can_show_bubble| will be |
| 48 // true only if the active window changes the zoom on the current page (i.e., | 56 // true only if the active window changes the zoom on the current page (i.e., |
| 49 // inactive window zoom changes, creating a new tab/window, or shifting | 57 // inactive window zoom changes, creating a new tab/window, or shifting |
| 50 // between tabs/windows, although they may involve a change in the zoom, | 58 // between tabs/windows, although they may involve a change in the zoom, |
| 51 // should not trigger showing a bubble). | 59 // should not trigger showing a bubble). |
| 52 void UpdateState(bool can_show_bubble); | 60 void UpdateState(bool can_show_bubble); |
| 53 | 61 |
| 54 // The current zoom percentage. | 62 // The current zoom percentage. |
| 55 int zoom_percent_; | 63 int zoom_percent_; |
| 56 | 64 |
| 57 content::NotificationRegistrar registrar_; | 65 content::NotificationRegistrar registrar_; |
| 58 | 66 |
| 59 // Used to access the default zoom level preference. | 67 // Used to access the default zoom level preference. |
| 60 DoublePrefMember default_zoom_level_; | 68 DoublePrefMember default_zoom_level_; |
| 61 | 69 |
| 62 // TabContents that owns this instance. | |
| 63 TabContents* tab_contents_; | |
| 64 | |
| 65 // Observer receiving notifications on state changes. | 70 // Observer receiving notifications on state changes. |
| 66 ZoomObserver* observer_; | 71 ZoomObserver* observer_; |
| 67 | 72 |
| 68 DISALLOW_COPY_AND_ASSIGN(ZoomController); | 73 DISALLOW_COPY_AND_ASSIGN(ZoomController); |
| 69 }; | 74 }; |
| 70 | 75 |
| 71 #endif // CHROME_BROWSER_UI_ZOOM_ZOOM_CONTROLLER_H_ | 76 #endif // CHROME_BROWSER_UI_ZOOM_ZOOM_CONTROLLER_H_ |
| OLD | NEW |