Chromium Code Reviews| Index: content/browser/web_contents/web_contents_impl.cc |
| diff --git a/content/browser/web_contents/web_contents_impl.cc b/content/browser/web_contents/web_contents_impl.cc |
| index a19fcd9921d563c334e361a83b4689aad1dc658e..6204c1952e4b1cbcd0d90bdc5b61b6f5f3bee258 100644 |
| --- a/content/browser/web_contents/web_contents_impl.cc |
| +++ b/content/browser/web_contents/web_contents_impl.cc |
| @@ -338,7 +338,9 @@ WebContentsImpl::WebContentsImpl( |
| color_chooser_identifier_(0), |
| render_view_message_source_(NULL), |
| fullscreen_widget_routing_id_(MSG_ROUTING_NONE), |
| - is_subframe_(false) { |
| + is_subframe_(false), |
| + current_zoom_mode_(kZoomModeDefault), |
| + current_zoom_id_(1) { |
| for (size_t i = 0; i < g_created_callbacks.Get().size(); i++) |
| g_created_callbacks.Get().at(i).Run(this); |
| frame_tree_.SetFrameRemoveListener( |
| @@ -1986,7 +1988,14 @@ bool WebContentsImpl::GetClosedByUserGesture() const { |
| return closed_by_user_gesture_; |
| } |
| +content::ZoomMode WebContentsImpl::GetZoomMode() const { |
| + return current_zoom_mode_; |
| +} |
| + |
| double WebContentsImpl::GetZoomLevel() const { |
| + if (current_zoom_mode_ == kZoomModeDisabled) |
| + return 0; |
| + |
| HostZoomMapImpl* zoom_map = static_cast<HostZoomMapImpl*>( |
| HostZoomMap::GetForBrowserContext(GetBrowserContext())); |
| if (!zoom_map) |
| @@ -2086,12 +2095,79 @@ bool WebContentsImpl::IsSubframe() const { |
| } |
| void WebContentsImpl::SetZoomLevel(double level) { |
| - Send(new ViewMsg_SetZoomLevel(GetRoutingID(), level)); |
| + if (current_zoom_mode_ == kZoomModeDisabled) |
| + return; |
| + |
| + // Notify observers about the initiated zoom change. |
| + FOR_EACH_OBSERVER(WebContentsObserver, observers_, |
|
Fady Samuel
2014/04/10 17:09:03
Can this go at the bottom after all other operatio
paulmeyer
2014/04/10 17:24:37
Yes. Done.
|
| + DidSetZoomLevel(GetZoomLevel(), level, current_zoom_mode_)); |
| + |
| + Send(new ViewMsg_SetZoomLevel(GetRoutingID(), current_zoom_id_++, level, |
| + current_zoom_mode_)); |
| BrowserPluginEmbedder* embedder = GetBrowserPluginEmbedder(); |
| if (embedder) |
| embedder->SetZoomLevel(level); |
| } |
| +void WebContentsImpl::SetZoomLevel(double level, |
| + const base::Callback<void(void)>& callback) { |
| + if (current_zoom_mode_ == kZoomModeDisabled) |
| + return; |
| + |
| + // Add the callback to HostZoomMap so that it can be called after the zoom |
| + // change has completed. |
| + HostZoomMapImpl* zoom_map = static_cast<HostZoomMapImpl*>( |
| + HostZoomMap::GetForBrowserContext(GetBrowserContext())); |
| + DCHECK(zoom_map); |
| + zoom_map->AddZoomCallback(current_zoom_id_, callback); |
| + SetZoomLevel(level); |
| +} |
| + |
| +void WebContentsImpl::SetZoomMode(ZoomMode mode) { |
| + if (mode == current_zoom_mode_) |
| + return; |
| + |
| + double original_zoom_level = GetZoomLevel(); |
| + switch (mode) { |
| + case kZoomModeDefault: { |
| + Send(new ViewMsg_SetZoomLevel(GetRoutingID(), 0, original_zoom_level, |
| + kZoomModeDefault)); |
| + // Remove per-tab zoom data for this tab. |
| + HostZoomMapImpl* zoom_map = static_cast<HostZoomMapImpl*>( |
| + HostZoomMap::GetForBrowserContext(GetBrowserContext())); |
| + DCHECK(zoom_map); |
| + int render_process_id = GetRenderProcessHost()->GetID(); |
| + int render_view_id = GetRenderViewHost()->GetRoutingID(); |
| + zoom_map->EraseTemporaryZoomLevel(render_process_id, render_view_id); |
| + break; |
| + } |
| + case kZoomModeIsolated: { |
| + if (current_zoom_mode_ != kZoomModeDisabled) { |
|
Fady Samuel
2014/04/10 17:09:03
Please explain in comments what this check does.
paulmeyer
2014/04/10 17:24:37
Done.
|
| + Send(new ViewMsg_SetZoomLevel(GetRoutingID(), 0, original_zoom_level, |
| + kZoomModeIsolated)); |
| + } |
| + break; |
| + } |
| + case kZoomModeManual: { |
| + if (current_zoom_mode_ != kZoomModeDisabled) { |
|
Fady Samuel
2014/04/10 17:09:03
Please explain in comments what this check does.
paulmeyer
2014/04/10 17:24:37
Done.
|
| + Send(new ViewMsg_SetZoomLevel(GetRoutingID(), 0, 0, kZoomModeIsolated)); |
| + current_zoom_mode_ = mode; |
| + SetZoomLevel(original_zoom_level); |
| + } |
| + break; |
| + } |
| + case kZoomModeDisabled: { |
| + if (current_zoom_mode_ != kZoomModeManual) { |
|
Fady Samuel
2014/04/10 17:09:03
Please explain in comments what this check does.
paulmeyer
2014/04/10 17:24:37
Done.
|
| + Send(new ViewMsg_SetZoomLevel(GetRoutingID(), 0, 0, kZoomModeIsolated)); |
| + } |
| + break; |
| + } |
| + } |
| + |
| + current_zoom_mode_ = mode; |
| + temporary_zoom_settings_ = mode != kZoomModeDefault; |
| +} |
| + |
| void WebContentsImpl::Find(int request_id, |
| const base::string16& search_text, |
| const blink::WebFindOptions& options) { |
| @@ -2426,7 +2502,8 @@ void WebContentsImpl::OnUpdateZoomLimits(int minimum_percent, |
| bool remember) { |
| minimum_zoom_percent_ = minimum_percent; |
| maximum_zoom_percent_ = maximum_percent; |
| - temporary_zoom_settings_ = !remember; |
| + temporary_zoom_settings_ = !remember || |
| + current_zoom_mode_ != kZoomModeDefault; |
| } |
| void WebContentsImpl::OnEnumerateDirectory(int request_id, |
| @@ -2826,6 +2903,12 @@ void WebContentsImpl::NotifyDisconnected() { |
| void WebContentsImpl::NotifyNavigationEntryCommitted( |
| const LoadCommittedDetails& load_details) { |
| + // The zoom mode resets on navigation to a different page. |
| + if (load_details.is_navigation_to_different_page()) { |
| + temporary_zoom_settings_ = false; |
| + SetZoomMode(kZoomModeDefault); |
| + } |
| + |
| FOR_EACH_OBSERVER( |
| WebContentsObserver, observers_, NavigationEntryCommitted(load_details)); |
| } |