Surface synchronization: Implement auto-resize for OOPIF/BrowserPlugin
https://chromium-review.googlesource.com/c/chromium/src/+/753801
This commit is contained in:
parent
ea7e273a06
commit
3ad0639b2e
4 changed files with 28 additions and 17 deletions
|
@ -785,6 +785,14 @@ content::JavaScriptDialogManager* WebContents::GetJavaScriptDialogManager(
|
|||
return dialog_manager_.get();
|
||||
}
|
||||
|
||||
void WebContents::ResizeDueToAutoResize(
|
||||
content::WebContents* web_contents,
|
||||
const gfx::Size& new_size) {
|
||||
if (IsGuest()) {
|
||||
guest_delegate_->ResizeDueToAutoResize(new_size);
|
||||
}
|
||||
}
|
||||
|
||||
void WebContents::BeforeUnloadFired(const base::TimeTicks& proceed_time) {
|
||||
// Do nothing, we override this method just to avoid compilation error since
|
||||
// there are two virtual functions named BeforeUnloadFired.
|
||||
|
|
|
@ -337,6 +337,8 @@ class WebContents : public mate::TrackableObject<WebContents>,
|
|||
const content::BluetoothChooser::EventHandler& handler) override;
|
||||
content::JavaScriptDialogManager* GetJavaScriptDialogManager(
|
||||
content::WebContents* source) override;
|
||||
void ResizeDueToAutoResize(content::WebContents* web_contents,
|
||||
const gfx::Size& new_size) override;
|
||||
|
||||
// content::WebContentsObserver:
|
||||
void BeforeUnloadFired(const base::TimeTicks& proceed_time) override;
|
||||
|
|
|
@ -80,21 +80,26 @@ void WebViewGuestDelegate::SetSize(const SetSizeParams& params) {
|
|||
new_size = GetDefaultSize();
|
||||
}
|
||||
|
||||
bool changed_due_to_auto_resize = false;
|
||||
if (auto_size_enabled_) {
|
||||
// Autosize was previously enabled.
|
||||
rvh->DisableAutoResize(new_size);
|
||||
GuestSizeChangedDueToAutoSize(guest_size_, new_size);
|
||||
changed_due_to_auto_resize = true;
|
||||
} else {
|
||||
// Autosize was already disabled.
|
||||
guest_host_->SizeContents(new_size);
|
||||
}
|
||||
|
||||
guest_size_ = new_size;
|
||||
UpdateGuestSize(new_size, changed_due_to_auto_resize);
|
||||
}
|
||||
|
||||
auto_size_enabled_ = enable_auto_size;
|
||||
}
|
||||
|
||||
void WebViewGuestDelegate::ResizeDueToAutoResize(const gfx::Size& new_size) {
|
||||
UpdateGuestSize(new_size, auto_size_enabled_);
|
||||
}
|
||||
|
||||
void WebViewGuestDelegate::DidFinishNavigation(
|
||||
content::NavigationHandle* navigation_handle) {
|
||||
if (navigation_handle->HasCommitted() && !navigation_handle->IsErrorPage()) {
|
||||
|
@ -126,13 +131,6 @@ content::WebContents* WebViewGuestDelegate::GetOwnerWebContents() const {
|
|||
return embedder_web_contents_;
|
||||
}
|
||||
|
||||
void WebViewGuestDelegate::GuestSizeChanged(const gfx::Size& new_size) {
|
||||
if (!auto_size_enabled_)
|
||||
return;
|
||||
GuestSizeChangedDueToAutoSize(guest_size_, new_size);
|
||||
guest_size_ = new_size;
|
||||
}
|
||||
|
||||
void WebViewGuestDelegate::SetGuestHost(content::GuestHost* guest_host) {
|
||||
guest_host_ = guest_host;
|
||||
}
|
||||
|
@ -163,11 +161,13 @@ void WebViewGuestDelegate::OnZoomLevelChanged(
|
|||
}
|
||||
}
|
||||
|
||||
void WebViewGuestDelegate::GuestSizeChangedDueToAutoSize(
|
||||
const gfx::Size& old_size,
|
||||
const gfx::Size& new_size) {
|
||||
api_web_contents_->Emit("size-changed", old_size.width(), old_size.height(),
|
||||
new_size.width(), new_size.height());
|
||||
void WebViewGuestDelegate::UpdateGuestSize(const gfx::Size& new_size,
|
||||
bool due_to_auto_resize) {
|
||||
if (due_to_auto_resize)
|
||||
api_web_contents_->Emit("size-changed", guest_size_.width(),
|
||||
guest_size_.height(), new_size.width(),
|
||||
new_size.height());
|
||||
guest_size_ = new_size;
|
||||
}
|
||||
|
||||
gfx::Size WebViewGuestDelegate::GetDefaultSize() const {
|
||||
|
|
|
@ -47,6 +47,9 @@ class WebViewGuestDelegate : public content::BrowserPluginGuestDelegate,
|
|||
// and normal sizes.
|
||||
void SetSize(const SetSizeParams& params);
|
||||
|
||||
// Invoked when the contents auto-resized and the container should match it.
|
||||
void ResizeDueToAutoResize(const gfx::Size& new_size);
|
||||
|
||||
// Return true if attached.
|
||||
bool IsAttached() const { return attached_; }
|
||||
|
||||
|
@ -59,7 +62,6 @@ class WebViewGuestDelegate : public content::BrowserPluginGuestDelegate,
|
|||
void DidAttach(int guest_proxy_routing_id) final;
|
||||
void DidDetach() final;
|
||||
content::WebContents* GetOwnerWebContents() const final;
|
||||
void GuestSizeChanged(const gfx::Size& new_size) final;
|
||||
void SetGuestHost(content::GuestHost* guest_host) final;
|
||||
void WillAttach(content::WebContents* embedder_web_contents,
|
||||
int element_instance_id,
|
||||
|
@ -82,8 +84,7 @@ class WebViewGuestDelegate : public content::BrowserPluginGuestDelegate,
|
|||
//
|
||||
// This gives the derived class an opportunity to inform its container element
|
||||
// or perform other actions.
|
||||
void GuestSizeChangedDueToAutoSize(const gfx::Size& old_size,
|
||||
const gfx::Size& new_size);
|
||||
void UpdateGuestSize(const gfx::Size& new_size, bool due_to_auto_resize);
|
||||
|
||||
// Returns the default size of the guestview.
|
||||
gfx::Size GetDefaultSize() const;
|
||||
|
|
Loading…
Reference in a new issue