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

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 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 <queue>
Devlin 2014/06/19 21:15:30 Do we still need this?
wjmaclean 2014/06/20 22:01:34 Good catch, no. Removed.
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"
14 16
15 class ZoomObserver; 17 class ZoomObserver;
16 18
17 namespace content { 19 namespace content {
18 class WebContents; 20 class WebContents;
19 } 21 }
20 22
21 // Per-tab class to manage the Omnibox zoom icon. 23 namespace extensions {
24 class Extension;
25 } // namespace extensions
26
27 // Per-tab class to manage zoom changes and the Omnibox zoom icon.
22 class ZoomController : public content::WebContentsObserver, 28 class ZoomController : public content::WebContentsObserver,
23 public content::WebContentsUserData<ZoomController> { 29 public content::WebContentsUserData<ZoomController> {
24 public: 30 public:
31 // Defines how zoom changes are handled.
32 // |kZoomModeDefault| results in default zoom behavior, i.e. zoom changes are
33 // handled automatically and on a per-origin basis, meaning that other
34 // tabs navigated to the same origin will also zoom.
35 // |kZoomModeIsolated| results in zoom changes being handled automatically,
36 // but on a per-tab basis. Tabs in this zoom mode will not be affected by
37 // zoom changes in other tabs, and vice versa.
38 // |kZoomModeManual| overrides the automatic handling of zoom changes. The
39 // |onZoomChange| event will still be dispatched, but the page will not
40 // actually be zoomed. These zoom changes can be handled manually by
41 // listening for the |onZoomChange| event. Zooming in this mode is also on
42 // a per-tab basis.
43 // |kZoomModeDisabled| disables all zooming in this tab. The tab will revert
44 // to default (100%) zoom, and all attempted zoom changes will be ignored.
45 enum ZoomMode {
46 kZoomModeDefault,
47 kZoomModeIsolated,
48 kZoomModeManual,
49 kZoomModeDisabled,
50 };
51
25 virtual ~ZoomController(); 52 virtual ~ZoomController();
26 53
27 int zoom_percent() const { return zoom_percent_; } 54 ZoomMode zoom_mode() const { return zoom_mode_; }
28 55
29 // Convenience method to quickly check if the tab's at default zoom. 56 // Convenience method to quickly check if the tab's at default zoom.
30 bool IsAtDefaultZoom() const; 57 bool IsAtDefaultZoom() const;
31 58
32 // Returns which image should be loaded for the current zoom level. 59 // Returns which image should be loaded for the current zoom level.
33 int GetResourceForZoomLevel() const; 60 int GetResourceForZoomLevel() const;
34 61
35 void set_observer(ZoomObserver* observer) { observer_ = observer; } 62 const extensions::Extension* last_extension() const {
63 return last_extension_.get();
64 }
65
66 void AddObserver(ZoomObserver* observer) { observers_.push_back(observer); }
Devlin 2014/06/19 21:15:30 A "remove observer" would also be good :)
wjmaclean 2014/06/20 22:01:34 OK, I don't mind adding that. The reason I haven't
67
68 double GetZoomLevel() const;
69 int GetZoomPercent() const;
70
71 // Sets the zoom level through HostZoomMap.
72 // Returns true on success.
73 bool SetZoomLevel(double zoom_level);
74
75 // Sets the zoom level through WebContents::SetZoomLevel(), and attributes the
76 // zoom to |extension|. Returns a boolean flag indicating success (true) or
77 // failure (false).
78 bool SetZoomLevelByExtension(
79 double zoom_level,
80 scoped_refptr<const extensions::Extension> extension);
81
82 // Sets the zoom mode, which defines zoom behavior (see enum ZoomMode).
83 void SetZoomMode(ZoomMode zoom_mode);
36 84
37 // content::WebContentsObserver overrides: 85 // content::WebContentsObserver overrides:
38 virtual void DidNavigateMainFrame( 86 virtual void DidNavigateMainFrame(
39 const content::LoadCommittedDetails& details, 87 const content::LoadCommittedDetails& details,
40 const content::FrameNavigateParams& params) OVERRIDE; 88 const content::FrameNavigateParams& params) OVERRIDE;
41 89
42 private: 90 private:
43 explicit ZoomController(content::WebContents* web_contents); 91 explicit ZoomController(content::WebContents* web_contents);
44 friend class content::WebContentsUserData<ZoomController>; 92 friend class content::WebContentsUserData<ZoomController>;
45 friend class ZoomControllerTest; 93 friend class ZoomControllerTest;
46 94
47 void OnZoomLevelChanged(const content::HostZoomMap::ZoomLevelChange& change); 95 void OnZoomLevelChanged(const content::HostZoomMap::ZoomLevelChange& change);
48 96
49 // Updates the zoom icon and zoom percentage based on current values and 97 // Updates the zoom icon and zoom percentage based on current values and
50 // notifies the observer if changes have occurred. |host| may be empty, 98 // 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 99 // meaning the change should apply to ~all sites. If it is not empty, the
52 // change only affects sites with the given host. 100 // change only affects sites with the given host.
53 void UpdateState(const std::string& host); 101 void UpdateState(const std::string& host);
102 void UpdateStateIncludingTemporary(const std::string& host,
Devlin 2014/06/19 21:15:30 Document the difference between this and UpdateSta
wjmaclean 2014/06/20 22:01:34 Done.
103 bool is_temporary_zoom);
54 104
55 // The current zoom percentage. 105 // The current zoom mode.
56 int zoom_percent_; 106 ZoomMode zoom_mode_;
107
108 // Current zoom level.
109 double zoom_level_;
57 110
58 // Used to access the default zoom level preference. 111 // Used to access the default zoom level preference.
59 DoublePrefMember default_zoom_level_; 112 DoublePrefMember default_zoom_level_;
60 113
114 // Keeps track of the extension (if any) that initiated the last zoom change
115 // that took effect.
116 scoped_refptr<const extensions::Extension> last_extension_;
117
61 // Observer receiving notifications on state changes. 118 // Observer receiving notifications on state changes.
62 ZoomObserver* observer_; 119 std::vector<ZoomObserver*> observers_;
Devlin 2014/06/19 21:15:30 Take a look at ObserverList (base/observer_list.h)
wjmaclean 2014/06/20 22:01:34 Done.
63 120
64 content::BrowserContext* browser_context_; 121 content::BrowserContext* browser_context_;
65 122
66 scoped_ptr<content::HostZoomMap::Subscription> zoom_subscription_; 123 scoped_ptr<content::HostZoomMap::Subscription> zoom_subscription_;
67 124
68 DISALLOW_COPY_AND_ASSIGN(ZoomController); 125 DISALLOW_COPY_AND_ASSIGN(ZoomController);
69 }; 126 };
70 127
71 #endif // CHROME_BROWSER_UI_ZOOM_ZOOM_CONTROLLER_H_ 128 #endif // CHROME_BROWSER_UI_ZOOM_ZOOM_CONTROLLER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698