Commit 4253aba6 authored by fsamuel's avatar fsamuel Committed by Commit bot

<webview>: Zooming the embedder should zoom the guest by the same level.

Note: Currently this solution is implemented in the chrome module but once
ZoomController moves to extensions, zooming from embedder to guest should
move to GuestViewBase and a more general solution should be made available
for GuestView types that wish to receive this zoom plumbing.

BUG=416581

Review URL: https://codereview.chromium.org/598163003

Cr-Commit-Position: refs/heads/master@{#296540}
parent 1eec8bec
...@@ -123,6 +123,20 @@ void ChromeWebViewGuestDelegate::OnEmbedderDestroyed() { ...@@ -123,6 +123,20 @@ void ChromeWebViewGuestDelegate::OnEmbedderDestroyed() {
web_view_guest()->view_instance_id())); web_view_guest()->view_instance_id()));
} }
void ChromeWebViewGuestDelegate::OnDidAttachToEmbedder() {
// TODO(fsamuel): This code should be implemented in GuestViewBase once the
// ZoomController moves to the extensions module.
ZoomController* zoom_controller = ZoomController::FromWebContents(
web_view_guest()->embedder_web_contents());
if (!zoom_controller)
return;
// Listen to the embedder's zoom changes.
zoom_controller->AddObserver(this);
// Set the guest's initial zoom level to be equal to the embedder's.
ZoomController::FromWebContents(guest_web_contents())->
SetZoomLevel(zoom_controller->GetZoomLevel());
}
void ChromeWebViewGuestDelegate::OnDidCommitProvisionalLoadForFrame( void ChromeWebViewGuestDelegate::OnDidCommitProvisionalLoadForFrame(
bool is_main_frame) { bool is_main_frame) {
// Update the current zoom factor for the new page. // Update the current zoom factor for the new page.
...@@ -238,3 +252,9 @@ void ChromeWebViewGuestDelegate::OnAccessibilityStatusChanged( ...@@ -238,3 +252,9 @@ void ChromeWebViewGuestDelegate::OnAccessibilityStatusChanged(
} }
} }
#endif #endif
void ChromeWebViewGuestDelegate::OnZoomChanged(
const ZoomController::ZoomChangedEventData& data) {
ZoomController::FromWebContents(guest_web_contents())->
SetZoomLevel(data.new_zoom_level);
}
...@@ -6,6 +6,7 @@ ...@@ -6,6 +6,7 @@
#define CHROME_BROWSER_GUEST_VIEW_WEB_VIEW_CHROME_WEB_VIEW_GUEST_DELEGATE_H_ #define CHROME_BROWSER_GUEST_VIEW_WEB_VIEW_CHROME_WEB_VIEW_GUEST_DELEGATE_H_
#include "chrome/browser/extensions/api/web_view/chrome_web_view_internal_api.h" #include "chrome/browser/extensions/api/web_view/chrome_web_view_internal_api.h"
#include "chrome/browser/ui/zoom/zoom_observer.h"
#include "extensions/browser/guest_view/web_view/web_view_guest.h" #include "extensions/browser/guest_view/web_view/web_view_guest.h"
#include "extensions/browser/guest_view/web_view/web_view_guest_delegate.h" #include "extensions/browser/guest_view/web_view/web_view_guest_delegate.h"
...@@ -19,7 +20,8 @@ namespace ui { ...@@ -19,7 +20,8 @@ namespace ui {
class SimpleMenuModel; class SimpleMenuModel;
} // namespace ui } // namespace ui
class ChromeWebViewGuestDelegate : public extensions::WebViewGuestDelegate { class ChromeWebViewGuestDelegate : public extensions::WebViewGuestDelegate,
public ZoomObserver {
public : public :
explicit ChromeWebViewGuestDelegate( explicit ChromeWebViewGuestDelegate(
extensions::WebViewGuest* web_view_guest); extensions::WebViewGuest* web_view_guest);
...@@ -31,6 +33,7 @@ class ChromeWebViewGuestDelegate : public extensions::WebViewGuestDelegate { ...@@ -31,6 +33,7 @@ class ChromeWebViewGuestDelegate : public extensions::WebViewGuestDelegate {
const content::ContextMenuParams& params) OVERRIDE; const content::ContextMenuParams& params) OVERRIDE;
virtual void OnAttachWebViewHelpers(content::WebContents* contents) OVERRIDE; virtual void OnAttachWebViewHelpers(content::WebContents* contents) OVERRIDE;
virtual void OnEmbedderDestroyed() OVERRIDE; virtual void OnEmbedderDestroyed() OVERRIDE;
virtual void OnDidAttachToEmbedder() OVERRIDE;
virtual void OnDidCommitProvisionalLoadForFrame(bool is_main_frame) OVERRIDE; virtual void OnDidCommitProvisionalLoadForFrame(bool is_main_frame) OVERRIDE;
virtual void OnDidInitialize() OVERRIDE; virtual void OnDidInitialize() OVERRIDE;
virtual void OnDocumentLoadedInFrame( virtual void OnDocumentLoadedInFrame(
...@@ -41,6 +44,10 @@ class ChromeWebViewGuestDelegate : public extensions::WebViewGuestDelegate { ...@@ -41,6 +44,10 @@ class ChromeWebViewGuestDelegate : public extensions::WebViewGuestDelegate {
int request_id, int request_id,
const MenuItemVector* items) OVERRIDE; const MenuItemVector* items) OVERRIDE;
// ZoomObserver implementation.
virtual void OnZoomChanged(
const ZoomController::ZoomChangedEventData& data) OVERRIDE;
extensions::WebViewGuest* web_view_guest() const { return web_view_guest_; } extensions::WebViewGuest* web_view_guest() const { return web_view_guest_; }
private: private:
......
...@@ -301,6 +301,9 @@ void WebViewGuest::DidAttachToEmbedder() { ...@@ -301,6 +301,9 @@ void WebViewGuest::DidAttachToEmbedder() {
// We need to set the background opaque flag after navigation to ensure that // We need to set the background opaque flag after navigation to ensure that
// there is a RenderWidgetHostView available. // there is a RenderWidgetHostView available.
SetAllowTransparency(allow_transparency); SetAllowTransparency(allow_transparency);
if (web_view_guest_delegate_)
web_view_guest_delegate_->OnDidAttachToEmbedder();
} }
void WebViewGuest::DidInitialize() { void WebViewGuest::DidInitialize() {
......
...@@ -43,6 +43,10 @@ class WebViewGuestDelegate { ...@@ -43,6 +43,10 @@ class WebViewGuestDelegate {
// Called to perform some cleanup prior to destruction. // Called to perform some cleanup prior to destruction.
virtual void OnEmbedderDestroyed() = 0; virtual void OnEmbedderDestroyed() = 0;
// Called after the guest has been attached to an embedder and suspended
// resource loads have been resumed.
virtual void OnDidAttachToEmbedder() = 0;
// Called when the guest WebContents commits a provisional load in any frame. // Called when the guest WebContents commits a provisional load in any frame.
virtual void OnDidCommitProvisionalLoadForFrame(bool is_main_frame) = 0; virtual void OnDidCommitProvisionalLoadForFrame(bool is_main_frame) = 0;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment