Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(259)

Side by Side Diff: chrome/browser/ui/zoom/zoom_controller.h

Issue 301733006: Zoom Extension API (chrome) (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Add event manager for manual zoom events. Created 6 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 <queue>
9
8 #include "base/basictypes.h" 10 #include "base/basictypes.h"
9 #include "base/compiler_specific.h" 11 #include "base/compiler_specific.h"
10 #include "base/prefs/pref_member.h" 12 #include "base/prefs/pref_member.h"
11 #include "content/public/browser/host_zoom_map.h" 13 #include "content/public/browser/host_zoom_map.h"
12 #include "content/public/browser/web_contents_observer.h" 14 #include "content/public/browser/web_contents_observer.h"
13 #include "content/public/browser/web_contents_user_data.h" 15 #include "content/public/browser/web_contents_user_data.h"
16 #include "extensions/common/extension.h"
Devlin 2014/06/16 19:04:50 Why full include?
wjmaclean 2014/06/18 19:03:55 Done.
14 17
15 class ZoomObserver; 18 class ZoomObserver;
16 19
17 namespace content { 20 namespace content {
18 class WebContents; 21 class WebContents;
19 } 22 }
20 23
21 // Per-tab class to manage the Omnibox zoom icon. 24 // Defines how zoom changes are handled.
25 // |kZoomModeDefault| results in default zoom behavior, i.e. zoom changes are
26 // handled automatically and on a per-origin basis, meaning that other
27 // tabs navigated to the same origin will also zoom.
28 // |kZoomModeIsolated| results in zoom changes being handled automatically,
29 // but on a per-tab basis. Tabs in this zoom mode will not be affected by
30 // zoom changes in other tabs, and vice versa.
31 // |kZoomModeManual| overrides the automatic handling of zoom changes. The
32 // |onZoomChange| event will still be dispatched, but the page will not
33 // actually be zoomed. These zoom changes can be handled manually by
34 // listening for the |onZoomChange| event. Zooming in this mode is also on
35 // a per-tab basis.
36 // |kZoomModeDisabled| disables all zooming in this tab. The tab will revert
37 // to default (100%) zoom, and all attempted zoom changes will be ignored.
38 enum ZoomMode {
39 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.
40 kZoomModeIsolated,
41 kZoomModeManual,
42 kZoomModeDisabled,
43 };
44
45 // Per-tab class to manage zoom changes and the Omnibox zoom icon.
22 class ZoomController : public content::WebContentsObserver, 46 class ZoomController : public content::WebContentsObserver,
23 public content::WebContentsUserData<ZoomController> { 47 public content::WebContentsUserData<ZoomController> {
24 public: 48 public:
25 virtual ~ZoomController(); 49 virtual ~ZoomController();
26 50
27 int zoom_percent() const { return zoom_percent_; } 51 ZoomMode zoom_mode() const { return zoom_mode_; }
28 52
29 // Convenience method to quickly check if the tab's at default zoom. 53 // Convenience method to quickly check if the tab's at default zoom.
30 bool IsAtDefaultZoom() const; 54 bool IsAtDefaultZoom() const;
31 55
32 // Returns which image should be loaded for the current zoom level. 56 // Returns which image should be loaded for the current zoom level.
33 int GetResourceForZoomLevel() const; 57 int GetResourceForZoomLevel() const;
34 58
59 const extensions::Extension* last_extension() const;
60
35 void set_observer(ZoomObserver* observer) { observer_ = observer; } 61 void set_observer(ZoomObserver* observer) { observer_ = observer; }
36 62
63 double GetZoomLevel() const;
64 int GetZoomPercent() const;
65
66 // Sets the zoom level through HostZoomMap.
67 // 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.
68 bool SetZoomLevel(double zoom_level);
69
70 // Sets the zoom level through WebContents::SetZoomLevel(), and attributes the
71 // zoom to |extension|. Returns a boolean flag indicating success (true) or
72 // failure (false).
73 bool SetZoomLevelByExtension(
74 double zoom_level,
75 scoped_refptr<const extensions::Extension> extension);
76
77 // Sets the zoom mode, which defines zoom behavior (see enum ZoomMode).
78 void SetZoomMode(ZoomMode zoom_mode);
79
37 // content::WebContentsObserver overrides: 80 // content::WebContentsObserver overrides:
38 virtual void DidNavigateMainFrame( 81 virtual void DidNavigateMainFrame(
39 const content::LoadCommittedDetails& details, 82 const content::LoadCommittedDetails& details,
40 const content::FrameNavigateParams& params) OVERRIDE; 83 const content::FrameNavigateParams& params) OVERRIDE;
41 84
42 private: 85 private:
43 explicit ZoomController(content::WebContents* web_contents); 86 explicit ZoomController(content::WebContents* web_contents);
44 friend class content::WebContentsUserData<ZoomController>; 87 friend class content::WebContentsUserData<ZoomController>;
45 friend class ZoomControllerTest; 88 friend class ZoomControllerTest;
46 89
47 void OnZoomLevelChanged(const content::HostZoomMap::ZoomLevelChange& change); 90 void OnZoomLevelChanged(const content::HostZoomMap::ZoomLevelChange& change);
48 91
49 // Updates the zoom icon and zoom percentage based on current values and 92 // Updates the zoom icon and zoom percentage based on current values and
50 // notifies the observer if changes have occurred. |host| may be empty, 93 // notifies the observer if changes have occurred. |host| may be empty,
51 // meaning the change should apply to ~all sites. If it is not empty, the 94 // meaning the change should apply to ~all sites. If it is not empty, the
52 // change only affects sites with the given host. 95 // change only affects sites with the given host.
53 void UpdateState(const std::string& host); 96 void UpdateState(const std::string& host);
97 void UpdateState(const std::string& host, bool is_temporary_zoom);
54 98
55 // The current zoom percentage. 99 // This function serves as a callback that will be called after a zoom
56 int zoom_percent_; 100 // change has completed that is initiated from SetZoomLevelByExtension().
101 void ZoomCallback(scoped_refptr<const extensions::Extension> extension,
102 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.
103
104 // The current zoom mode.
105 ZoomMode zoom_mode_;
106
107 // Current zoom level.
108 double zoom_level_;
57 109
58 // Used to access the default zoom level preference. 110 // Used to access the default zoom level preference.
59 DoublePrefMember default_zoom_level_; 111 DoublePrefMember default_zoom_level_;
60 112
113 // Keeps track of the extension (if any) that initiated the last zoom change
114 // that took effect.
115 scoped_refptr<const extensions::Extension> last_extension_;
116
61 // Observer receiving notifications on state changes. 117 // Observer receiving notifications on state changes.
62 ZoomObserver* observer_; 118 ZoomObserver* observer_;
63 119
64 content::BrowserContext* browser_context_; 120 content::BrowserContext* browser_context_;
65 121
66 scoped_ptr<content::HostZoomMap::Subscription> zoom_subscription_; 122 scoped_ptr<content::HostZoomMap::Subscription> zoom_subscription_;
67 123
124 // Keeps track of extensions that initiated zoom changes so that they can be
125 // attributed when the zoom changes complete.
126 std::queue<scoped_refptr<const extensions::Extension> > extensions_;
127
68 DISALLOW_COPY_AND_ASSIGN(ZoomController); 128 DISALLOW_COPY_AND_ASSIGN(ZoomController);
69 }; 129 };
70 130
71 #endif // CHROME_BROWSER_UI_ZOOM_ZOOM_CONTROLLER_H_ 131 #endif // CHROME_BROWSER_UI_ZOOM_ZOOM_CONTROLLER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698