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

Side by Side Diff: components/ui/zoom/zoom_controller.h

Issue 769593003: Move ZoomObserver, ZoomController and ZoomEventManager to components/. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Move ui_zoom stuff to components instead. Created 6 years 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
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 COMPONENTS_UI_ZOOM_ZOOM_CONTROLLER_H_
6 #define CHROME_BROWSER_UI_ZOOM_ZOOM_CONTROLLER_H_ 6 #define COMPONENTS_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/ref_counted.h"
10 #include "base/memory/scoped_ptr.h" 11 #include "base/memory/scoped_ptr.h"
11 #include "base/observer_list.h" 12 #include "base/observer_list.h"
12 #include "base/prefs/pref_member.h" 13 #include "base/prefs/pref_member.h"
13 #include "content/public/browser/host_zoom_map.h" 14 #include "content/public/browser/host_zoom_map.h"
14 #include "content/public/browser/web_contents_observer.h" 15 #include "content/public/browser/web_contents_observer.h"
15 #include "content/public/browser/web_contents_user_data.h" 16 #include "content/public/browser/web_contents_user_data.h"
16 17
17 class ZoomObserver; 18 class ZoomControllerTest;
18 19
19 namespace content { 20 namespace content {
20 class WebContents; 21 class WebContents;
21 } 22 }
22 23
23 namespace extensions { 24 namespace components {
24 class Extension; 25 class ZoomObserver;
25 } // namespace extensions 26
27 class ZoomRequestClient : public base::RefCounted<ZoomRequestClient> {
28 public:
29 ZoomRequestClient() {}
30
31 protected:
32 virtual ~ZoomRequestClient() {}
33
34 private:
35 friend class base::RefCounted<ZoomRequestClient>;
36
37 DISALLOW_COPY_AND_ASSIGN(ZoomRequestClient);
38 };
26 39
27 // Per-tab class to manage zoom changes and the Omnibox zoom icon. 40 // Per-tab class to manage zoom changes and the Omnibox zoom icon.
28 class ZoomController : public content::WebContentsObserver, 41 class ZoomController : public content::WebContentsObserver,
29 public content::WebContentsUserData<ZoomController> { 42 public content::WebContentsUserData<ZoomController> {
30 public: 43 public:
31 // Defines how zoom changes are handled. 44 // Defines how zoom changes are handled.
32 enum ZoomMode { 45 enum ZoomMode {
33 // Results in default zoom behavior, i.e. zoom changes are handled 46 // Results in default zoom behavior, i.e. zoom changes are handled
34 // automatically and on a per-origin basis, meaning that other tabs 47 // automatically and on a per-origin basis, meaning that other tabs
35 // navigated to the same origin will also zoom. 48 // navigated to the same origin will also zoom.
36 ZOOM_MODE_DEFAULT, 49 ZOOM_MODE_DEFAULT,
37 // Results in zoom changes being handled automatically, but on a per-tab 50 // 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 51 // basis. Tabs in this zoom mode will not be affected by zoom changes in
39 // other tabs, and vice versa. 52 // other tabs, and vice versa.
40 ZOOM_MODE_ISOLATED, 53 ZOOM_MODE_ISOLATED,
41 // Overrides the automatic handling of zoom changes. The |onZoomChange| 54 // Overrides the automatic handling of zoom changes. The |onZoomChange|
42 // event will still be dispatched, but the page will not actually be zoomed. 55 // 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 56 // 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. 57 // |onZoomChange| event. Zooming in this mode is also on a per-tab basis.
45 ZOOM_MODE_MANUAL, 58 ZOOM_MODE_MANUAL,
46 // Disables all zooming in this tab. The tab will revert to default (100%) 59 // Disables all zooming in this tab. The tab will revert to default (100%)
47 // zoom, and all attempted zoom changes will be ignored. 60 // zoom, and all attempted zoom changes will be ignored.
48 ZOOM_MODE_DISABLED, 61 ZOOM_MODE_DISABLED,
49 }; 62 };
50 63
64 enum RelativeZoom {
65 ZOOM_BELOW_DEFAULT_ZOOM,
66 ZOOM_AT_DEFAULT_ZOOM,
67 ZOOM_ABOVE_DEFAULT_ZOOM
68 };
69
51 struct ZoomChangedEventData { 70 struct ZoomChangedEventData {
52 ZoomChangedEventData(content::WebContents* web_contents, 71 ZoomChangedEventData(content::WebContents* web_contents,
53 double old_zoom_level, 72 double old_zoom_level,
54 double new_zoom_level, 73 double new_zoom_level,
55 ZoomController::ZoomMode zoom_mode, 74 ZoomController::ZoomMode zoom_mode,
56 bool can_show_bubble) 75 bool can_show_bubble)
57 : web_contents(web_contents), 76 : web_contents(web_contents),
58 old_zoom_level(old_zoom_level), 77 old_zoom_level(old_zoom_level),
59 new_zoom_level(new_zoom_level), 78 new_zoom_level(new_zoom_level),
60 zoom_mode(zoom_mode), 79 zoom_mode(zoom_mode),
(...skipping 13 matching lines...) Expand all
74 // inlining. 93 // inlining.
75 double GetDefaultZoomLevel() const { 94 double GetDefaultZoomLevel() const {
76 return content::HostZoomMap::GetForWebContents(web_contents()) 95 return content::HostZoomMap::GetForWebContents(web_contents())
77 ->GetDefaultZoomLevel(); 96 ->GetDefaultZoomLevel();
78 } 97 }
79 98
80 // Convenience method to quickly check if the tab's at default zoom. 99 // Convenience method to quickly check if the tab's at default zoom.
81 bool IsAtDefaultZoom() const; 100 bool IsAtDefaultZoom() const;
82 101
83 // Returns which image should be loaded for the current zoom level. 102 // Returns which image should be loaded for the current zoom level.
84 int GetResourceForZoomLevel() const; 103 RelativeZoom GetZoomRelativeToDefault() const;
85 104
86 const extensions::Extension* last_extension() const { 105 const ZoomRequestClient* last_client() const {
87 return last_extension_.get(); 106 return last_client_.get();
88 } 107 }
89 108
90 void AddObserver(ZoomObserver* observer); 109 void AddObserver(ZoomObserver* observer);
91 void RemoveObserver(ZoomObserver* observer); 110 void RemoveObserver(ZoomObserver* observer);
92 111
93 // Used to set whether the zoom notification bubble can be shown when the 112 // 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 113 // zoom level is changed for this controller. Default behavior is to show
95 // the bubble. 114 // the bubble.
96 void SetShowsNotificationBubble(bool can_show_bubble) { 115 void SetShowsNotificationBubble(bool can_show_bubble) {
97 can_show_bubble_ = can_show_bubble; 116 can_show_bubble_ = can_show_bubble;
98 } 117 }
99 118
100 // Gets the current zoom level by querying HostZoomMap (if not in manual zoom 119 // Gets the current zoom level by querying HostZoomMap (if not in manual zoom
101 // mode) or from the ZoomController local value otherwise. 120 // mode) or from the ZoomController local value otherwise.
102 double GetZoomLevel() const; 121 double GetZoomLevel() const;
103 // Calls GetZoomLevel() then converts the returned value to a percentage 122 // Calls GetZoomLevel() then converts the returned value to a percentage
104 // zoom factor. 123 // zoom factor.
105 // Virtual for testing. 124 // Virtual for testing.
106 virtual int GetZoomPercent() const; 125 virtual int GetZoomPercent() const;
107 126
108 // Sets the zoom level through HostZoomMap. 127 // Sets the zoom level through HostZoomMap.
109 // Returns true on success. 128 // Returns true on success.
110 bool SetZoomLevel(double zoom_level); 129 bool SetZoomLevel(double zoom_level);
111 130
112 // Sets the zoom level via HostZoomMap (or stores it locally if in manual zoom 131 // Sets the zoom level via HostZoomMap (or stores it locally if in manual zoom
113 // mode), and attributes the zoom to |extension|. Returns true on success. 132 // mode), and attributes the zoom to |extension|. Returns true on success.
114 bool SetZoomLevelByExtension( 133 bool SetZoomLevelByClient(
115 double zoom_level, 134 double zoom_level,
116 const scoped_refptr<const extensions::Extension>& extension); 135 const scoped_refptr<const ZoomRequestClient>& extension);
Ken Rockot(use gerrit already) 2014/12/03 21:42:48 nit: client -> extension
wjmaclean 2014/12/04 15:04:30 Done.
117 136
118 // Sets the zoom mode, which defines zoom behavior (see enum ZoomMode). 137 // Sets the zoom mode, which defines zoom behavior (see enum ZoomMode).
119 void SetZoomMode(ZoomMode zoom_mode); 138 void SetZoomMode(ZoomMode zoom_mode);
120 139
121 // content::WebContentsObserver overrides: 140 // content::WebContentsObserver overrides:
122 void DidNavigateMainFrame( 141 void DidNavigateMainFrame(
123 const content::LoadCommittedDetails& details, 142 const content::LoadCommittedDetails& details,
124 const content::FrameNavigateParams& params) override; 143 const content::FrameNavigateParams& params) override;
125 void WebContentsDestroyed() override; 144 void WebContentsDestroyed() override;
126 145
127 protected: 146 protected:
128 // Protected for testing. 147 // Protected for testing.
129 explicit ZoomController(content::WebContents* web_contents); 148 explicit ZoomController(content::WebContents* web_contents);
130 149
131 private: 150 private:
132 friend class content::WebContentsUserData<ZoomController>; 151 friend class content::WebContentsUserData<ZoomController>;
133 friend class ZoomControllerTest; 152 friend class ::ZoomControllerTest;
134 153
135 void OnZoomLevelChanged(const content::HostZoomMap::ZoomLevelChange& change); 154 void OnZoomLevelChanged(const content::HostZoomMap::ZoomLevelChange& change);
136 155
137 // Updates the zoom icon and zoom percentage based on current values and 156 // Updates the zoom icon and zoom percentage based on current values and
138 // notifies the observer if changes have occurred. |host| may be empty, 157 // 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 158 // meaning the change should apply to ~all sites. If it is not empty, the
140 // change only affects sites with the given host. 159 // change only affects sites with the given host.
141 void UpdateState(const std::string& host); 160 void UpdateState(const std::string& host);
142 161
143 // True if changes to zoom level can trigger the zoom notification bubble. 162 // True if changes to zoom level can trigger the zoom notification bubble.
144 bool can_show_bubble_; 163 bool can_show_bubble_;
145 164
146 // The current zoom mode. 165 // The current zoom mode.
147 ZoomMode zoom_mode_; 166 ZoomMode zoom_mode_;
148 167
149 // Current zoom level. 168 // Current zoom level.
150 double zoom_level_; 169 double zoom_level_;
151 170
152 scoped_ptr<ZoomChangedEventData> event_data_; 171 scoped_ptr<ZoomChangedEventData> event_data_;
153 172
154 // Keeps track of the extension (if any) that initiated the last zoom change 173 // Keeps track of the extension (if any) that initiated the last zoom change
155 // that took effect. 174 // that took effect.
156 scoped_refptr<const extensions::Extension> last_extension_; 175 scoped_refptr<const ZoomRequestClient> last_client_;
157 176
158 // Observer receiving notifications on state changes. 177 // Observer receiving notifications on state changes.
159 ObserverList<ZoomObserver> observers_; 178 ObserverList<ZoomObserver> observers_;
160 179
161 content::BrowserContext* browser_context_; 180 content::BrowserContext* browser_context_;
162 181
163 scoped_ptr<content::HostZoomMap::Subscription> zoom_subscription_; 182 scoped_ptr<content::HostZoomMap::Subscription> zoom_subscription_;
164 183
165 DISALLOW_COPY_AND_ASSIGN(ZoomController); 184 DISALLOW_COPY_AND_ASSIGN(ZoomController);
166 }; 185 };
167 186
168 #endif // CHROME_BROWSER_UI_ZOOM_ZOOM_CONTROLLER_H_ 187 } // namespace extensions
188
189 #endif // COMPONENTS_UI_ZOOM_ZOOM_CONTROLLER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698