| 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 EXTENSIONS_BROWSER_UI_ZOOM_ZOOM_CONTROLLER_H_ |
| 6 #define CHROME_BROWSER_UI_ZOOM_ZOOM_CONTROLLER_H_ | 6 #define EXTENSIONS_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/memory/scoped_ptr.h" | 10 #include "base/memory/scoped_ptr.h" |
| 11 #include "base/observer_list.h" | 11 #include "base/observer_list.h" |
| 12 #include "base/prefs/pref_member.h" | 12 #include "base/prefs/pref_member.h" |
| 13 #include "content/public/browser/host_zoom_map.h" | 13 #include "content/public/browser/host_zoom_map.h" |
| 14 #include "content/public/browser/web_contents_observer.h" | 14 #include "content/public/browser/web_contents_observer.h" |
| 15 #include "content/public/browser/web_contents_user_data.h" | 15 #include "content/public/browser/web_contents_user_data.h" |
| 16 | 16 |
| 17 class ZoomObserver; | 17 class ZoomControllerTest; |
| 18 | 18 |
| 19 namespace content { | 19 namespace content { |
| 20 class WebContents; | 20 class WebContents; |
| 21 } | 21 } |
| 22 | 22 |
| 23 namespace extensions { | 23 namespace extensions { |
| 24 class Extension; | 24 class Extension; |
| 25 } // namespace extensions | 25 class ZoomObserver; |
| 26 | 26 |
| 27 // Per-tab class to manage zoom changes and the Omnibox zoom icon. | 27 // Per-tab class to manage zoom changes and the Omnibox zoom icon. |
| 28 class ZoomController : public content::WebContentsObserver, | 28 class ZoomController : public content::WebContentsObserver, |
| 29 public content::WebContentsUserData<ZoomController> { | 29 public content::WebContentsUserData<ZoomController> { |
| 30 public: | 30 public: |
| 31 // Defines how zoom changes are handled. | 31 // Defines how zoom changes are handled. |
| 32 enum ZoomMode { | 32 enum ZoomMode { |
| 33 // Results in default zoom behavior, i.e. zoom changes are handled | 33 // Results in default zoom behavior, i.e. zoom changes are handled |
| 34 // automatically and on a per-origin basis, meaning that other tabs | 34 // automatically and on a per-origin basis, meaning that other tabs |
| 35 // navigated to the same origin will also zoom. | 35 // navigated to the same origin will also zoom. |
| 36 ZOOM_MODE_DEFAULT, | 36 ZOOM_MODE_DEFAULT, |
| 37 // Results in zoom changes being handled automatically, but on a per-tab | 37 // Results in zoom changes being handled automatically, but on a per-tab |
| 38 // basis. Tabs in this zoom mode will not be affected by zoom changes in | 38 // basis. Tabs in this zoom mode will not be affected by zoom changes in |
| 39 // other tabs, and vice versa. | 39 // other tabs, and vice versa. |
| 40 ZOOM_MODE_ISOLATED, | 40 ZOOM_MODE_ISOLATED, |
| 41 // Overrides the automatic handling of zoom changes. The |onZoomChange| | 41 // Overrides the automatic handling of zoom changes. The |onZoomChange| |
| 42 // event will still be dispatched, but the page will not actually be zoomed. | 42 // event will still be dispatched, but the page will not actually be zoomed. |
| 43 // These zoom changes can be handled manually by listening for the | 43 // These zoom changes can be handled manually by listening for the |
| 44 // |onZoomChange| event. Zooming in this mode is also on a per-tab basis. | 44 // |onZoomChange| event. Zooming in this mode is also on a per-tab basis. |
| 45 ZOOM_MODE_MANUAL, | 45 ZOOM_MODE_MANUAL, |
| 46 // Disables all zooming in this tab. The tab will revert to default (100%) | 46 // Disables all zooming in this tab. The tab will revert to default (100%) |
| 47 // zoom, and all attempted zoom changes will be ignored. | 47 // zoom, and all attempted zoom changes will be ignored. |
| 48 ZOOM_MODE_DISABLED, | 48 ZOOM_MODE_DISABLED, |
| 49 }; | 49 }; |
| 50 | 50 |
| 51 enum RelativeZoom { |
| 52 ZOOM_BELOW_DEFAULT_ZOOM, |
| 53 ZOOM_AT_DEFAULT_ZOOM, |
| 54 ZOOM_ABOVE_DEFAULT_ZOOM |
| 55 }; |
| 56 |
| 51 struct ZoomChangedEventData { | 57 struct ZoomChangedEventData { |
| 52 ZoomChangedEventData(content::WebContents* web_contents, | 58 ZoomChangedEventData(content::WebContents* web_contents, |
| 53 double old_zoom_level, | 59 double old_zoom_level, |
| 54 double new_zoom_level, | 60 double new_zoom_level, |
| 55 ZoomController::ZoomMode zoom_mode, | 61 ZoomController::ZoomMode zoom_mode, |
| 56 bool can_show_bubble) | 62 bool can_show_bubble) |
| 57 : web_contents(web_contents), | 63 : web_contents(web_contents), |
| 58 old_zoom_level(old_zoom_level), | 64 old_zoom_level(old_zoom_level), |
| 59 new_zoom_level(new_zoom_level), | 65 new_zoom_level(new_zoom_level), |
| 60 zoom_mode(zoom_mode), | 66 zoom_mode(zoom_mode), |
| (...skipping 13 matching lines...) Expand all Loading... |
| 74 // inlining. | 80 // inlining. |
| 75 double GetDefaultZoomLevel() const { | 81 double GetDefaultZoomLevel() const { |
| 76 return content::HostZoomMap::GetForWebContents(web_contents()) | 82 return content::HostZoomMap::GetForWebContents(web_contents()) |
| 77 ->GetDefaultZoomLevel(); | 83 ->GetDefaultZoomLevel(); |
| 78 } | 84 } |
| 79 | 85 |
| 80 // Convenience method to quickly check if the tab's at default zoom. | 86 // Convenience method to quickly check if the tab's at default zoom. |
| 81 bool IsAtDefaultZoom() const; | 87 bool IsAtDefaultZoom() const; |
| 82 | 88 |
| 83 // Returns which image should be loaded for the current zoom level. | 89 // Returns which image should be loaded for the current zoom level. |
| 84 int GetResourceForZoomLevel() const; | 90 RelativeZoom GetZoomRelativeToDefault() const; |
| 85 | 91 |
| 86 const extensions::Extension* last_extension() const { | 92 const extensions::Extension* last_extension() const { |
| 87 return last_extension_.get(); | 93 return last_extension_.get(); |
| 88 } | 94 } |
| 89 | 95 |
| 90 void AddObserver(ZoomObserver* observer); | 96 void AddObserver(ZoomObserver* observer); |
| 91 void RemoveObserver(ZoomObserver* observer); | 97 void RemoveObserver(ZoomObserver* observer); |
| 92 | 98 |
| 93 // Used to set whether the zoom notification bubble can be shown when the | 99 // Used to set whether the zoom notification bubble can be shown when the |
| 94 // zoom level is changed for this controller. Default behavior is to show | 100 // zoom level is changed for this controller. Default behavior is to show |
| (...skipping 28 matching lines...) Expand all Loading... |
| 123 const content::LoadCommittedDetails& details, | 129 const content::LoadCommittedDetails& details, |
| 124 const content::FrameNavigateParams& params) override; | 130 const content::FrameNavigateParams& params) override; |
| 125 void WebContentsDestroyed() override; | 131 void WebContentsDestroyed() override; |
| 126 | 132 |
| 127 protected: | 133 protected: |
| 128 // Protected for testing. | 134 // Protected for testing. |
| 129 explicit ZoomController(content::WebContents* web_contents); | 135 explicit ZoomController(content::WebContents* web_contents); |
| 130 | 136 |
| 131 private: | 137 private: |
| 132 friend class content::WebContentsUserData<ZoomController>; | 138 friend class content::WebContentsUserData<ZoomController>; |
| 133 friend class ZoomControllerTest; | 139 friend class ::ZoomControllerTest; |
| 134 | 140 |
| 135 void OnZoomLevelChanged(const content::HostZoomMap::ZoomLevelChange& change); | 141 void OnZoomLevelChanged(const content::HostZoomMap::ZoomLevelChange& change); |
| 136 | 142 |
| 137 // Updates the zoom icon and zoom percentage based on current values and | 143 // Updates the zoom icon and zoom percentage based on current values and |
| 138 // notifies the observer if changes have occurred. |host| may be empty, | 144 // notifies the observer if changes have occurred. |host| may be empty, |
| 139 // meaning the change should apply to ~all sites. If it is not empty, the | 145 // meaning the change should apply to ~all sites. If it is not empty, the |
| 140 // change only affects sites with the given host. | 146 // change only affects sites with the given host. |
| 141 void UpdateState(const std::string& host); | 147 void UpdateState(const std::string& host); |
| 142 | 148 |
| 143 // True if changes to zoom level can trigger the zoom notification bubble. | 149 // True if changes to zoom level can trigger the zoom notification bubble. |
| (...skipping 14 matching lines...) Expand all Loading... |
| 158 // Observer receiving notifications on state changes. | 164 // Observer receiving notifications on state changes. |
| 159 ObserverList<ZoomObserver> observers_; | 165 ObserverList<ZoomObserver> observers_; |
| 160 | 166 |
| 161 content::BrowserContext* browser_context_; | 167 content::BrowserContext* browser_context_; |
| 162 | 168 |
| 163 scoped_ptr<content::HostZoomMap::Subscription> zoom_subscription_; | 169 scoped_ptr<content::HostZoomMap::Subscription> zoom_subscription_; |
| 164 | 170 |
| 165 DISALLOW_COPY_AND_ASSIGN(ZoomController); | 171 DISALLOW_COPY_AND_ASSIGN(ZoomController); |
| 166 }; | 172 }; |
| 167 | 173 |
| 168 #endif // CHROME_BROWSER_UI_ZOOM_ZOOM_CONTROLLER_H_ | 174 } // namespace extensions |
| 175 |
| 176 #endif // EXTENSIONS_BROWSER_UI_ZOOM_ZOOM_CONTROLLER_H_ |
| OLD | NEW |