OLD | NEW |
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 #include "components/ui/zoom/zoom_controller.h" | 5 #include "components/zoom/zoom_controller.h" |
6 | 6 |
7 #include "components/ui/zoom/zoom_event_manager.h" | 7 #include "components/zoom/zoom_event_manager.h" |
8 #include "components/ui/zoom/zoom_observer.h" | 8 #include "components/zoom/zoom_observer.h" |
9 #include "content/public/browser/host_zoom_map.h" | 9 #include "content/public/browser/host_zoom_map.h" |
10 #include "content/public/browser/navigation_details.h" | 10 #include "content/public/browser/navigation_details.h" |
11 #include "content/public/browser/navigation_entry.h" | 11 #include "content/public/browser/navigation_entry.h" |
12 #include "content/public/browser/render_process_host.h" | 12 #include "content/public/browser/render_process_host.h" |
13 #include "content/public/browser/render_view_host.h" | 13 #include "content/public/browser/render_view_host.h" |
14 #include "content/public/browser/web_contents.h" | 14 #include "content/public/browser/web_contents.h" |
15 #include "content/public/common/page_type.h" | 15 #include "content/public/common/page_type.h" |
16 #include "content/public/common/page_zoom.h" | 16 #include "content/public/common/page_zoom.h" |
17 #include "net/base/url_util.h" | 17 #include "net/base/url_util.h" |
18 | 18 |
19 DEFINE_WEB_CONTENTS_USER_DATA_KEY(ui_zoom::ZoomController); | 19 DEFINE_WEB_CONTENTS_USER_DATA_KEY(zoom::ZoomController); |
20 | 20 |
21 namespace ui_zoom { | 21 namespace zoom { |
22 | 22 |
23 double ZoomController::GetZoomLevelForWebContents( | 23 double ZoomController::GetZoomLevelForWebContents( |
24 const content::WebContents* web_contents) { | 24 const content::WebContents* web_contents) { |
25 if (!web_contents) | 25 if (!web_contents) |
26 return 0.0; | 26 return 0.0; |
27 | 27 |
28 auto zoom_controller = FromWebContents(web_contents); | 28 auto zoom_controller = FromWebContents(web_contents); |
29 if (zoom_controller) | 29 if (zoom_controller) |
30 return zoom_controller->GetZoomLevel(); | 30 return zoom_controller->GetZoomLevel(); |
31 | 31 |
32 return content::HostZoomMap::GetZoomLevel(web_contents); | 32 return content::HostZoomMap::GetZoomLevel(web_contents); |
33 } | 33 } |
34 | 34 |
35 ZoomController::ZoomController(content::WebContents* web_contents) | 35 ZoomController::ZoomController(content::WebContents* web_contents) |
36 : content::WebContentsObserver(web_contents), | 36 : content::WebContentsObserver(web_contents), |
37 can_show_bubble_(true), | 37 can_show_bubble_(true), |
38 zoom_mode_(ZOOM_MODE_DEFAULT), | 38 zoom_mode_(ZOOM_MODE_DEFAULT), |
39 zoom_level_(1.0), | 39 zoom_level_(1.0), |
40 browser_context_(web_contents->GetBrowserContext()) { | 40 browser_context_(web_contents->GetBrowserContext()) { |
41 host_zoom_map_ = content::HostZoomMap::GetForWebContents(web_contents); | 41 host_zoom_map_ = content::HostZoomMap::GetForWebContents(web_contents); |
42 zoom_level_ = host_zoom_map_->GetDefaultZoomLevel(); | 42 zoom_level_ = host_zoom_map_->GetDefaultZoomLevel(); |
43 | 43 |
44 zoom_subscription_ = host_zoom_map_->AddZoomLevelChangedCallback( | 44 zoom_subscription_ = host_zoom_map_->AddZoomLevelChangedCallback( |
45 base::Bind(&ZoomController::OnZoomLevelChanged, base::Unretained(this))); | 45 base::Bind(&ZoomController::OnZoomLevelChanged, base::Unretained(this))); |
46 | 46 |
47 UpdateState(std::string()); | 47 UpdateState(std::string()); |
48 } | 48 } |
49 | 49 |
50 ZoomController::~ZoomController() { | 50 ZoomController::~ZoomController() {} |
51 } | |
52 | 51 |
53 bool ZoomController::IsAtDefaultZoom() const { | 52 bool ZoomController::IsAtDefaultZoom() const { |
54 return content::ZoomValuesEqual(GetZoomLevel(), GetDefaultZoomLevel()); | 53 return content::ZoomValuesEqual(GetZoomLevel(), GetDefaultZoomLevel()); |
55 } | 54 } |
56 | 55 |
57 ZoomController::RelativeZoom ZoomController::GetZoomRelativeToDefault() const { | 56 ZoomController::RelativeZoom ZoomController::GetZoomRelativeToDefault() const { |
58 double current_level = GetZoomLevel(); | 57 double current_level = GetZoomLevel(); |
59 double default_level = GetDefaultZoomLevel(); | 58 double default_level = GetDefaultZoomLevel(); |
60 if (content::ZoomValuesEqual(current_level, default_level)) | 59 if (content::ZoomValuesEqual(current_level, default_level)) |
61 return ZOOM_AT_DEFAULT_ZOOM; | 60 return ZOOM_AT_DEFAULT_ZOOM; |
(...skipping 198 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
260 zoom_mode_ = new_mode; | 259 zoom_mode_ = new_mode; |
261 } | 260 } |
262 | 261 |
263 void ZoomController::ResetZoomModeOnNavigationIfNeeded(const GURL& url) { | 262 void ZoomController::ResetZoomModeOnNavigationIfNeeded(const GURL& url) { |
264 if (zoom_mode_ != ZOOM_MODE_ISOLATED && zoom_mode_ != ZOOM_MODE_MANUAL) | 263 if (zoom_mode_ != ZOOM_MODE_ISOLATED && zoom_mode_ != ZOOM_MODE_MANUAL) |
265 return; | 264 return; |
266 | 265 |
267 int render_process_id = web_contents()->GetRenderProcessHost()->GetID(); | 266 int render_process_id = web_contents()->GetRenderProcessHost()->GetID(); |
268 int render_view_id = web_contents()->GetRenderViewHost()->GetRoutingID(); | 267 int render_view_id = web_contents()->GetRenderViewHost()->GetRoutingID(); |
269 content::HostZoomMap* zoom_map = | 268 content::HostZoomMap* zoom_map = |
270 content::HostZoomMap::GetForWebContents(web_contents()); | 269 content::HostZoomMap::GetForWebContents(web_contents()); |
271 zoom_level_ = zoom_map->GetDefaultZoomLevel(); | 270 zoom_level_ = zoom_map->GetDefaultZoomLevel(); |
272 double old_zoom_level = zoom_map->GetZoomLevel(web_contents()); | 271 double old_zoom_level = zoom_map->GetZoomLevel(web_contents()); |
273 double new_zoom_level = zoom_map->GetZoomLevelForHostAndScheme( | 272 double new_zoom_level = zoom_map->GetZoomLevelForHostAndScheme( |
274 url.scheme(), net::GetHostOrSpecFromURL(url)); | 273 url.scheme(), net::GetHostOrSpecFromURL(url)); |
275 event_data_.reset(new ZoomChangedEventData( | 274 event_data_.reset(new ZoomChangedEventData(web_contents(), old_zoom_level, |
276 web_contents(), old_zoom_level, new_zoom_level, ZOOM_MODE_DEFAULT, | 275 new_zoom_level, ZOOM_MODE_DEFAULT, |
277 false /* can_show_bubble */)); | 276 false /* can_show_bubble */)); |
278 // The call to ClearTemporaryZoomLevel() doesn't generate any events from | 277 // The call to ClearTemporaryZoomLevel() doesn't generate any events from |
279 // HostZoomMap, but the call to UpdateState() at the end of this function | 278 // HostZoomMap, but the call to UpdateState() at the end of this function |
280 // will notify our observers. | 279 // will notify our observers. |
281 // Note: it's possible the render_process/view ids have disappeared (e.g. | 280 // Note: it's possible the render_process/view ids have disappeared (e.g. |
282 // if we navigated to a new origin), but this won't cause a problem in the | 281 // if we navigated to a new origin), but this won't cause a problem in the |
283 // call below. | 282 // call below. |
284 zoom_map->ClearTemporaryZoomLevel(render_process_id, render_view_id); | 283 zoom_map->ClearTemporaryZoomLevel(render_process_id, render_view_id); |
285 zoom_mode_ = ZOOM_MODE_DEFAULT; | 284 zoom_mode_ = ZOOM_MODE_DEFAULT; |
286 } | 285 } |
287 | 286 |
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
358 zoom_level, zoom_mode_, | 357 zoom_level, zoom_mode_, |
359 false /* can_show_bubble */); | 358 false /* can_show_bubble */); |
360 FOR_EACH_OBSERVER(ZoomObserver, observers_, | 359 FOR_EACH_OBSERVER(ZoomObserver, observers_, |
361 OnZoomChanged(zoom_change_data)); | 360 OnZoomChanged(zoom_change_data)); |
362 } | 361 } |
363 } | 362 } |
364 | 363 |
365 void ZoomController::SetPageScaleFactorIsOneForTesting(bool is_one) { | 364 void ZoomController::SetPageScaleFactorIsOneForTesting(bool is_one) { |
366 int render_process_id = web_contents()->GetRenderProcessHost()->GetID(); | 365 int render_process_id = web_contents()->GetRenderProcessHost()->GetID(); |
367 int render_view_id = web_contents()->GetRenderViewHost()->GetRoutingID(); | 366 int render_view_id = web_contents()->GetRenderViewHost()->GetRoutingID(); |
368 host_zoom_map_->SetPageScaleFactorIsOneForView( | 367 host_zoom_map_->SetPageScaleFactorIsOneForView(render_process_id, |
369 render_process_id, render_view_id, is_one); | 368 render_view_id, is_one); |
370 } | 369 } |
371 | 370 |
372 bool ZoomController::PageScaleFactorIsOne() const { | 371 bool ZoomController::PageScaleFactorIsOne() const { |
373 return content::HostZoomMap::PageScaleFactorIsOne(web_contents()); | 372 return content::HostZoomMap::PageScaleFactorIsOne(web_contents()); |
374 } | 373 } |
375 | 374 |
376 } // namespace ui_zoom | 375 } // namespace zoom |
OLD | NEW |