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..9722a0f93a88b9a4ae861b4bf23cc8881966f519 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,76 @@ bool WebContentsImpl::IsSubframe() const { |
| } |
| void WebContentsImpl::SetZoomLevel(double level) { |
| - Send(new ViewMsg_SetZoomLevel(GetRoutingID(), level)); |
| + if (current_zoom_mode_ == kZoomModeDisabled) |
| + return; |
| + |
| + ZoomChangeDetails zoom_change_details; |
| + zoom_change_details.old_zoom_level = GetZoomLevel(); |
| + zoom_change_details.new_zoom_level = level; |
| + zoom_change_details.zoom_mode = current_zoom_mode_; |
| + NotificationService::current()->Notify( |
| + content::NOTIFICATION_WEB_CONTENTS_ZOOM_CHANGE, |
| + Source<WebContents>(this), |
| + content::Details<ZoomChangeDetails>( |
| + &zoom_change_details)); |
| + |
| + 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(); |
| + |
| + if (mode == kZoomModeDefault) { |
|
Fady Samuel
2014/04/10 14:27:25
I think a switch statement would be easier to read
paulmeyer
2014/04/10 15:11:49
Done.
|
| + Send(new ViewMsg_SetZoomLevel(GetRoutingID(), 0, original_zoom_level, |
| + kZoomModeDefault)); |
| + NotificationService::current()->Notify( |
| + NOTIFICATION_WEB_CONTENTS_NO_TEMPORARY_ZOOM_LEVEL, |
| + Source<WebContents>(this), |
| + NotificationService::NoDetails()); |
| + } else if (mode == kZoomModeIsolated) { |
| + if (current_zoom_mode_ != kZoomModeDisabled) { |
| + Send(new ViewMsg_SetZoomLevel(GetRoutingID(), 0, original_zoom_level, |
| + kZoomModeIsolated)); |
| + } |
| + } else if (mode == kZoomModeManual) { |
| + if (current_zoom_mode_ != kZoomModeDisabled) { |
| + Send(new ViewMsg_SetZoomLevel(GetRoutingID(), 0, 0, kZoomModeIsolated)); |
| + current_zoom_mode_ = mode; |
| + SetZoomLevel(original_zoom_level); |
| + } |
| + } else if (mode == kZoomModeDisabled) { |
| + if (current_zoom_mode_ != kZoomModeManual) { |
| + Send(new ViewMsg_SetZoomLevel(GetRoutingID(), 0, 0, kZoomModeIsolated)); |
| + } |
| + } else { |
| + NOTREACHED(); |
| + } |
| + |
| + 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 +2499,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 +2900,11 @@ void WebContentsImpl::NotifyDisconnected() { |
| void WebContentsImpl::NotifyNavigationEntryCommitted( |
| const LoadCommittedDetails& load_details) { |
| + if (load_details.is_navigation_to_different_page()) { |
|
Fady Samuel
2014/04/10 14:27:25
A comment here would be useful.
paulmeyer
2014/04/10 15:11:49
Done.
|
| + temporary_zoom_settings_ = false; |
| + SetZoomMode(kZoomModeDefault); |
| + } |
| + |
| FOR_EACH_OBSERVER( |
| WebContentsObserver, observers_, NavigationEntryCommitted(load_details)); |
| } |