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

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

Issue 2630583002: Add setting to isolate zoom changes by default. (Closed)
Patch Set: Add more tests. Created 3 years, 11 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
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 COMPONENTS_ZOOM_ZOOM_CONTROLLER_H_ 5 #ifndef COMPONENTS_ZOOM_ZOOM_CONTROLLER_H_
6 #define COMPONENTS_ZOOM_ZOOM_CONTROLLER_H_ 6 #define COMPONENTS_ZOOM_ZOOM_CONTROLLER_H_
7 7
8 #include <memory> 8 #include <memory>
9 9
10 #include "base/compiler_specific.h" 10 #include "base/compiler_specific.h"
11 #include "base/gtest_prod_util.h"
11 #include "base/macros.h" 12 #include "base/macros.h"
12 #include "base/memory/ref_counted.h" 13 #include "base/memory/ref_counted.h"
13 #include "base/observer_list.h" 14 #include "base/observer_list.h"
14 #include "components/prefs/pref_member.h" 15 #include "components/prefs/pref_member.h"
15 #include "content/public/browser/host_zoom_map.h" 16 #include "content/public/browser/host_zoom_map.h"
16 #include "content/public/browser/web_contents_observer.h" 17 #include "content/public/browser/web_contents_observer.h"
17 #include "content/public/browser/web_contents_user_data.h" 18 #include "content/public/browser/web_contents_user_data.h"
19 #include "content/public/browser/zoom_level_delegate.h"
18 20
19 class ZoomControllerTest; 21 class ZoomControllerTest;
22 FORWARD_DECLARE_TEST(ZoomControllerTest, OnDefaultZoomScopeChanged);
23 FORWARD_DECLARE_TEST(ZoomControllerPerTabTest, OnDefaultZoomScopeChanged);
20 24
21 namespace content { 25 namespace content {
22 class WebContents; 26 class WebContents;
23 } 27 }
24 28
25 namespace zoom { 29 namespace zoom {
26 class ZoomObserver; 30 class ZoomObserver;
27 31
28 class ZoomRequestClient : public base::RefCounted<ZoomRequestClient> { 32 class ZoomRequestClient : public base::RefCounted<ZoomRequestClient> {
29 public: 33 public:
(...skipping 11 matching lines...) Expand all
41 45
42 // Per-tab class to manage zoom changes and the Omnibox zoom icon. 46 // Per-tab class to manage zoom changes and the Omnibox zoom icon.
43 class ZoomController : public content::WebContentsObserver, 47 class ZoomController : public content::WebContentsObserver,
44 public content::WebContentsUserData<ZoomController> { 48 public content::WebContentsUserData<ZoomController> {
45 public: 49 public:
46 // Defines how zoom changes are handled. 50 // Defines how zoom changes are handled.
47 enum ZoomMode { 51 enum ZoomMode {
48 // Results in default zoom behavior, i.e. zoom changes are handled 52 // Results in default zoom behavior, i.e. zoom changes are handled
49 // automatically and on a per-origin basis, meaning that other tabs 53 // automatically and on a per-origin basis, meaning that other tabs
50 // navigated to the same origin will also zoom. 54 // navigated to the same origin will also zoom.
55 // TODO Would we want to rename this?
wjmaclean 2017/01/19 21:09:05 Nit: write as "TODO(<ldap>):"
Kevin McNee 2017/02/03 23:17:20 Acknowledged.
51 ZOOM_MODE_DEFAULT, 56 ZOOM_MODE_DEFAULT,
52 // Results in zoom changes being handled automatically, but on a per-tab 57 // Results in zoom changes being handled automatically, but on a per-tab
53 // basis. Tabs in this zoom mode will not be affected by zoom changes in 58 // basis. Tabs in this zoom mode will not be affected by zoom changes in
54 // other tabs, and vice versa. 59 // other tabs, and vice versa.
55 ZOOM_MODE_ISOLATED, 60 ZOOM_MODE_ISOLATED,
56 // Overrides the automatic handling of zoom changes. The |onZoomChange| 61 // Overrides the automatic handling of zoom changes. The |onZoomChange|
57 // event will still be dispatched, but the page will not actually be zoomed. 62 // event will still be dispatched, but the page will not actually be zoomed.
58 // These zoom changes can be handled manually by listening for the 63 // These zoom changes can be handled manually by listening for the
59 // |onZoomChange| event. Zooming in this mode is also on a per-tab basis. 64 // |onZoomChange| event. Zooming in this mode is also on a per-tab basis.
60 ZOOM_MODE_MANUAL, 65 ZOOM_MODE_MANUAL,
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after
148 void SetPageScaleFactorIsOneForTesting(bool is_one); 153 void SetPageScaleFactorIsOneForTesting(bool is_one);
149 bool PageScaleFactorIsOne() const; 154 bool PageScaleFactorIsOne() const;
150 155
151 // content::WebContentsObserver overrides: 156 // content::WebContentsObserver overrides:
152 void DidNavigateMainFrame( 157 void DidNavigateMainFrame(
153 const content::LoadCommittedDetails& details, 158 const content::LoadCommittedDetails& details,
154 const content::FrameNavigateParams& params) override; 159 const content::FrameNavigateParams& params) override;
155 void WebContentsDestroyed() override; 160 void WebContentsDestroyed() override;
156 void RenderFrameHostChanged(content::RenderFrameHost* old_host, 161 void RenderFrameHostChanged(content::RenderFrameHost* old_host,
157 content::RenderFrameHost* new_host) override; 162 content::RenderFrameHost* new_host) override;
163 void DidCloneToNewWebContents(
164 content::WebContents* old_web_contents,
165 content::WebContents* new_web_contents) override;
166 void WebContentsReplaced(content::WebContents* old_web_contents,
167 content::WebContents* new_web_contents) override;
158 168
159 protected: 169 protected:
160 // Protected for testing. 170 // Protected for testing.
161 explicit ZoomController(content::WebContents* web_contents); 171 explicit ZoomController(content::WebContents* web_contents);
162 172
163 private: 173 private:
164 friend class content::WebContentsUserData<ZoomController>; 174 friend class content::WebContentsUserData<ZoomController>;
165 friend class ::ZoomControllerTest; 175 friend class ::ZoomControllerTest;
176 FRIEND_TEST_ALL_PREFIXES(::ZoomControllerTest, OnDefaultZoomScopeChanged);
177 FRIEND_TEST_ALL_PREFIXES(::ZoomControllerPerTabTest,
178 OnDefaultZoomScopeChanged);
166 179
167 void ResetZoomModeOnNavigationIfNeeded(const GURL& url); 180 void ResetZoomModeOnNavigationIfNeeded(const GURL& url);
181 void UpdateZoomModeOnScopeChangeIfNeeded();
182 void PreserveTemporaryZoomLevel(content::WebContents* old_web_contents,
183 content::WebContents* new_web_contents) const;
168 void OnZoomLevelChanged(const content::HostZoomMap::ZoomLevelChange& change); 184 void OnZoomLevelChanged(const content::HostZoomMap::ZoomLevelChange& change);
185 void OnDefaultZoomScopeChanged();
169 186
170 // Updates the zoom icon and zoom percentage based on current values and 187 // Updates the zoom icon and zoom percentage based on current values and
171 // notifies the observer if changes have occurred. |host| may be empty, 188 // notifies the observer if changes have occurred. |host| may be empty,
172 // meaning the change should apply to ~all sites. If it is not empty, the 189 // meaning the change should apply to ~all sites. If it is not empty, the
173 // change only affects sites with the given host. 190 // change only affects sites with the given host.
174 void UpdateState(const std::string& host); 191 void UpdateState(const std::string& host);
175 192
176 // True if changes to zoom level can trigger the zoom notification bubble. 193 // True if changes to zoom level can trigger the zoom notification bubble.
177 bool can_show_bubble_; 194 bool can_show_bubble_;
178 195
179 // The current zoom mode. 196 // The current zoom mode.
180 ZoomMode zoom_mode_; 197 ZoomMode zoom_mode_;
181 198
199 // Whether zoom changes are by default scoped to a page's origin.
200 // If false, they are scoped to the tab.
201 bool default_per_origin_;
202
182 // Current zoom level. 203 // Current zoom level.
183 double zoom_level_; 204 double zoom_level_;
184 205
185 std::unique_ptr<ZoomChangedEventData> event_data_; 206 std::unique_ptr<ZoomChangedEventData> event_data_;
186 207
187 // Keeps track of the extension (if any) that initiated the last zoom change 208 // Keeps track of the extension (if any) that initiated the last zoom change
188 // that took effect. 209 // that took effect.
189 scoped_refptr<const ZoomRequestClient> last_client_; 210 scoped_refptr<const ZoomRequestClient> last_client_;
190 211
191 // Observer receiving notifications on state changes. 212 // Observer receiving notifications on state changes.
192 base::ObserverList<ZoomObserver> observers_; 213 base::ObserverList<ZoomObserver> observers_;
193 214
194 content::BrowserContext* browser_context_; 215 content::BrowserContext* browser_context_;
195 // Keep track of the HostZoomMap we're currently subscribed to. 216 // Keep track of the HostZoomMap we're currently subscribed to.
196 content::HostZoomMap* host_zoom_map_; 217 content::HostZoomMap* host_zoom_map_;
197 218
198 std::unique_ptr<content::HostZoomMap::Subscription> zoom_subscription_; 219 std::unique_ptr<content::HostZoomMap::Subscription> zoom_subscription_;
220 std::unique_ptr<content::ZoomLevelDelegate::DefaultZoomScopeSubscription>
221 default_zoom_scope_subscription_;
199 222
200 DISALLOW_COPY_AND_ASSIGN(ZoomController); 223 DISALLOW_COPY_AND_ASSIGN(ZoomController);
201 }; 224 };
202 225
203 } // namespace zoom 226 } // namespace zoom
204 227
205 #endif // COMPONENTS_ZOOM_ZOOM_CONTROLLER_H_ 228 #endif // COMPONENTS_ZOOM_ZOOM_CONTROLLER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698