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

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: Address dbeam@'s comments. 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 "base/basictypes.h" 8 #include "base/basictypes.h"
9 #include "base/compiler_specific.h" 9 #include "base/compiler_specific.h"
10 #include "base/observer_list.h"
10 #include "base/prefs/pref_member.h" 11 #include "base/prefs/pref_member.h"
11 #include "content/public/browser/host_zoom_map.h" 12 #include "content/public/browser/host_zoom_map.h"
12 #include "content/public/browser/web_contents_observer.h" 13 #include "content/public/browser/web_contents_observer.h"
13 #include "content/public/browser/web_contents_user_data.h" 14 #include "content/public/browser/web_contents_user_data.h"
14 15
15 class ZoomObserver; 16 class ZoomObserver;
16 17
17 namespace content { 18 namespace content {
18 class WebContents; 19 class WebContents;
19 } 20 }
20 21
21 // Per-tab class to manage the Omnibox zoom icon. 22 namespace extensions {
23 class Extension;
24 } // namespace extensions
25
26 // Per-tab class to manage zoom changes and the Omnibox zoom icon.
22 class ZoomController : public content::WebContentsObserver, 27 class ZoomController : public content::WebContentsObserver,
23 public content::WebContentsUserData<ZoomController> { 28 public content::WebContentsUserData<ZoomController> {
24 public: 29 public:
30 // Defines how zoom changes are handled.
31 enum ZoomMode {
32 // Results in default zoom behavior, i.e. zoom changes are handled
33 // automatically and on a per-origin basis, meaning that other tabs
34 // navigated to the same origin will also zoom.
35 ZOOM_MODE_DEFAULT,
36 // Results in zoom changes being handled automatically, but on a per-tab
37 // basis. Tabs in this zoom mode will not be affected by zoom changes in
38 // other tabs, and vice versa.
39 ZOOM_MODE_ISOLATED,
40 // Overrides the automatic handling of zoom changes. The |onZoomChange|
41 // event will still be dispatched, but the page will not actually be zoomed.
42 // These zoom changes can be handled manually by listening for the
43 // |onZoomChange| event. Zooming in this mode is also on a per-tab basis.
44 ZOOM_MODE_MANUAL,
45 // Disables all zooming in this tab. The tab will revert to default (100%)
46 // zoom, and all attempted zoom changes will be ignored.
47 ZOOM_MODE_DISABLED,
48 };
49
25 virtual ~ZoomController(); 50 virtual ~ZoomController();
26 51
27 int zoom_percent() const { return zoom_percent_; } 52 ZoomMode zoom_mode() const { return zoom_mode_; }
28 53
29 // Convenience method to quickly check if the tab's at default zoom. 54 // Convenience method to quickly check if the tab's at default zoom.
30 bool IsAtDefaultZoom() const; 55 bool IsAtDefaultZoom() const;
31 56
32 // Returns which image should be loaded for the current zoom level. 57 // Returns which image should be loaded for the current zoom level.
33 int GetResourceForZoomLevel() const; 58 int GetResourceForZoomLevel() const;
34 59
35 void set_observer(ZoomObserver* observer) { observer_ = observer; } 60 const extensions::Extension* last_extension() const {
61 return last_extension_.get();
62 }
63
64 void AddObserver(ZoomObserver* observer);
65 void RemoveObserver(ZoomObserver* observer);
66
67 double GetZoomLevel() const;
68 int GetZoomPercent() const;
Dan Beam 2014/06/26 22:16:38 nit: doc comment? usually if something is StudlyC
wjmaclean 2014/07/02 22:24:59 Done.
69
70 // Sets the zoom level through HostZoomMap.
71 // Returns true on success.
72 bool SetZoomLevel(double zoom_level);
73
74 // Sets the zoom level through WebContents::SetZoomLevel(), and attributes the
75 // zoom to |extension|. Returns a boolean flag indicating success (true) or
76 // failure (false).
77 bool SetZoomLevelByExtension(
78 double zoom_level,
79 const scoped_refptr<const extensions::Extension>& extension);
80
81 // Sets the zoom mode, which defines zoom behavior (see enum ZoomMode).
82 void SetZoomMode(ZoomMode zoom_mode);
36 83
37 // content::WebContentsObserver overrides: 84 // content::WebContentsObserver overrides:
38 virtual void DidNavigateMainFrame( 85 virtual void DidNavigateMainFrame(
39 const content::LoadCommittedDetails& details, 86 const content::LoadCommittedDetails& details,
40 const content::FrameNavigateParams& params) OVERRIDE; 87 const content::FrameNavigateParams& params) OVERRIDE;
41 88
42 private: 89 private:
43 explicit ZoomController(content::WebContents* web_contents); 90 explicit ZoomController(content::WebContents* web_contents);
44 friend class content::WebContentsUserData<ZoomController>; 91 friend class content::WebContentsUserData<ZoomController>;
45 friend class ZoomControllerTest; 92 friend class ZoomControllerTest;
46 93
47 void OnZoomLevelChanged(const content::HostZoomMap::ZoomLevelChange& change); 94 void OnZoomLevelChanged(const content::HostZoomMap::ZoomLevelChange& change);
48 95
49 // Updates the zoom icon and zoom percentage based on current values and 96 // Updates the zoom icon and zoom percentage based on current values and
50 // notifies the observer if changes have occurred. |host| may be empty, 97 // 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 98 // meaning the change should apply to ~all sites. If it is not empty, the
52 // change only affects sites with the given host. 99 // change only affects sites with the given host.
53 void UpdateState(const std::string& host); 100 void UpdateState(const std::string& host);
101 // Same as UpdateState, but takes into account whether a temporary zoom level
102 // has been set on |host| when deciding whether to show the zoom notification
103 // bubble.
104 void UpdateStateIncludingTemporary(const std::string& host,
105 bool is_temporary_zoom);
54 106
55 // The current zoom percentage. 107 // The current zoom mode.
56 int zoom_percent_; 108 ZoomMode zoom_mode_;
109
110 // Current zoom level.
111 double zoom_level_;
57 112
58 // Used to access the default zoom level preference. 113 // Used to access the default zoom level preference.
59 DoublePrefMember default_zoom_level_; 114 DoublePrefMember default_zoom_level_;
60 115
116 // Keeps track of the extension (if any) that initiated the last zoom change
117 // that took effect.
118 scoped_refptr<const extensions::Extension> last_extension_;
119
61 // Observer receiving notifications on state changes. 120 // Observer receiving notifications on state changes.
62 ZoomObserver* observer_; 121 ObserverList<ZoomObserver> observers_;
63 122
64 content::BrowserContext* browser_context_; 123 content::BrowserContext* browser_context_;
65 124
66 scoped_ptr<content::HostZoomMap::Subscription> zoom_subscription_; 125 scoped_ptr<content::HostZoomMap::Subscription> zoom_subscription_;
67 126
68 DISALLOW_COPY_AND_ASSIGN(ZoomController); 127 DISALLOW_COPY_AND_ASSIGN(ZoomController);
69 }; 128 };
70 129
71 #endif // CHROME_BROWSER_UI_ZOOM_ZOOM_CONTROLLER_H_ 130 #endif // CHROME_BROWSER_UI_ZOOM_ZOOM_CONTROLLER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698