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