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