Chromium Code Reviews| Index: chrome/browser/ui/zoom/zoom_controller.h |
| diff --git a/chrome/browser/ui/zoom/zoom_controller.h b/chrome/browser/ui/zoom/zoom_controller.h |
| index 3c427a716d6956b4603ee54f1d1fe67dd4780985..2735b65b5e2c9ede65ac569deb30f53ac55b11ca 100644 |
| --- a/chrome/browser/ui/zoom/zoom_controller.h |
| +++ b/chrome/browser/ui/zoom/zoom_controller.h |
| @@ -5,12 +5,15 @@ |
| #ifndef CHROME_BROWSER_UI_ZOOM_ZOOM_CONTROLLER_H_ |
| #define CHROME_BROWSER_UI_ZOOM_ZOOM_CONTROLLER_H_ |
| +#include <queue> |
| + |
| #include "base/basictypes.h" |
| #include "base/compiler_specific.h" |
| #include "base/prefs/pref_member.h" |
| #include "content/public/browser/host_zoom_map.h" |
| #include "content/public/browser/web_contents_observer.h" |
| #include "content/public/browser/web_contents_user_data.h" |
| +#include "extensions/common/extension.h" |
|
Devlin
2014/06/16 19:04:50
Why full include?
wjmaclean
2014/06/18 19:03:55
Done.
|
| class ZoomObserver; |
| @@ -18,13 +21,34 @@ namespace content { |
| class WebContents; |
| } |
| -// Per-tab class to manage the Omnibox zoom icon. |
| +// Defines how zoom changes are handled. |
| +// |kZoomModeDefault| results in default zoom behavior, i.e. zoom changes are |
| +// handled automatically and on a per-origin basis, meaning that other |
| +// tabs navigated to the same origin will also zoom. |
| +// |kZoomModeIsolated| results in zoom changes being handled automatically, |
| +// but on a per-tab basis. Tabs in this zoom mode will not be affected by |
| +// zoom changes in other tabs, and vice versa. |
| +// |kZoomModeManual| overrides the automatic handling of zoom changes. The |
| +// |onZoomChange| event will still be dispatched, but the page will not |
| +// actually be zoomed. These zoom changes can be handled manually by |
| +// listening for the |onZoomChange| event. Zooming in this mode is also on |
| +// a per-tab basis. |
| +// |kZoomModeDisabled| disables all zooming in this tab. The tab will revert |
| +// to default (100%) zoom, and all attempted zoom changes will be ignored. |
| +enum ZoomMode { |
| + kZoomModeDefault, |
|
Devlin
2014/06/16 19:04:50
Typically, we nest these enums in a class (unless
wjmaclean
2014/06/18 19:03:55
Done.
|
| + kZoomModeIsolated, |
| + kZoomModeManual, |
| + kZoomModeDisabled, |
| +}; |
| + |
| +// Per-tab class to manage zoom changes and the Omnibox zoom icon. |
| class ZoomController : public content::WebContentsObserver, |
| public content::WebContentsUserData<ZoomController> { |
| public: |
| virtual ~ZoomController(); |
| - int zoom_percent() const { return zoom_percent_; } |
| + ZoomMode zoom_mode() const { return zoom_mode_; } |
| // Convenience method to quickly check if the tab's at default zoom. |
| bool IsAtDefaultZoom() const; |
| @@ -32,8 +56,27 @@ class ZoomController : public content::WebContentsObserver, |
| // Returns which image should be loaded for the current zoom level. |
| int GetResourceForZoomLevel() const; |
| + const extensions::Extension* last_extension() const; |
| + |
| void set_observer(ZoomObserver* observer) { observer_ = observer; } |
| + double GetZoomLevel() const; |
| + int GetZoomPercent() const; |
| + |
| + // Sets the zoom level through HostZoomMap. |
| + // Returns a boolean flag indicating success (true) or failure (false). |
|
Devlin
2014/06/16 19:04:50
Shorter: "Returns true on success."
wjmaclean
2014/06/18 19:03:55
Done.
|
| + bool SetZoomLevel(double zoom_level); |
| + |
| + // Sets the zoom level through WebContents::SetZoomLevel(), and attributes the |
| + // zoom to |extension|. Returns a boolean flag indicating success (true) or |
| + // failure (false). |
| + bool SetZoomLevelByExtension( |
| + double zoom_level, |
| + scoped_refptr<const extensions::Extension> extension); |
| + |
| + // Sets the zoom mode, which defines zoom behavior (see enum ZoomMode). |
| + void SetZoomMode(ZoomMode zoom_mode); |
| + |
| // content::WebContentsObserver overrides: |
| virtual void DidNavigateMainFrame( |
| const content::LoadCommittedDetails& details, |
| @@ -51,13 +94,26 @@ class ZoomController : public content::WebContentsObserver, |
| // meaning the change should apply to ~all sites. If it is not empty, the |
| // change only affects sites with the given host. |
| void UpdateState(const std::string& host); |
| + void UpdateState(const std::string& host, bool is_temporary_zoom); |
| + |
| + // This function serves as a callback that will be called after a zoom |
| + // change has completed that is initiated from SetZoomLevelByExtension(). |
| + void ZoomCallback(scoped_refptr<const extensions::Extension> extension, |
| + const base::Callback<void(void)>& callback); |
|
Devlin
2014/06/16 19:04:50
base::Callback<void(void)> = base::Closure
wjmaclean
2014/06/18 19:03:55
Done.
|
| - // The current zoom percentage. |
| - int zoom_percent_; |
| + // The current zoom mode. |
| + ZoomMode zoom_mode_; |
| + |
| + // Current zoom level. |
| + double zoom_level_; |
| // Used to access the default zoom level preference. |
| DoublePrefMember default_zoom_level_; |
| + // Keeps track of the extension (if any) that initiated the last zoom change |
| + // that took effect. |
| + scoped_refptr<const extensions::Extension> last_extension_; |
| + |
| // Observer receiving notifications on state changes. |
| ZoomObserver* observer_; |
| @@ -65,6 +121,10 @@ class ZoomController : public content::WebContentsObserver, |
| scoped_ptr<content::HostZoomMap::Subscription> zoom_subscription_; |
| + // Keeps track of extensions that initiated zoom changes so that they can be |
| + // attributed when the zoom changes complete. |
| + std::queue<scoped_refptr<const extensions::Extension> > extensions_; |
| + |
| DISALLOW_COPY_AND_ASSIGN(ZoomController); |
| }; |