From 67d59cb2b9eb91a127ad83c2a73fe84be99e8f34 Mon Sep 17 00:00:00 2001 From: Marshall Greenblatt Date: Fri, 5 Apr 2013 17:37:40 +0000 Subject: [PATCH] Add CefBrowserHost::WasHidden() method for notifying a windowless browser that it has been hidden or shown (issue #909). git-svn-id: https://chromiumembedded.googlecode.com/svn/trunk@1180 5089003a-bbd8-11dd-ad1f-f1f9622dbc98 --- include/capi/cef_browser_capi.h | 7 ++++++ include/cef_browser.h | 8 +++++++ libcef/browser/browser_host_impl.cc | 27 ++++++++++++++++++++++++ libcef/browser/browser_host_impl.h | 1 + libcef_dll/cpptoc/browser_host_cpptoc.cc | 14 ++++++++++++ libcef_dll/ctocpp/browser_host_ctocpp.cc | 11 ++++++++++ libcef_dll/ctocpp/browser_host_ctocpp.h | 1 + 7 files changed, 69 insertions(+) diff --git a/include/capi/cef_browser_capi.h b/include/capi/cef_browser_capi.h index 2e57797de..1e16fab86 100644 --- a/include/capi/cef_browser_capi.h +++ b/include/capi/cef_browser_capi.h @@ -339,6 +339,13 @@ typedef struct _cef_browser_host_t { /// void (CEF_CALLBACK *was_resized)(struct _cef_browser_host_t* self); + /// + // Notify the browser that it has been hidden or shown. Layouting and + // cef_render_handler_t::OnPaint notification will stop when the browser is + // hidden. This function is only used when window rendering is disabled. + /// + void (CEF_CALLBACK *was_hidden)(struct _cef_browser_host_t* self, int hidden); + /// // Invalidate the |dirtyRect| region of the view. The browser will call // cef_render_handler_t::OnPaint asynchronously with the updated regions. This diff --git a/include/cef_browser.h b/include/cef_browser.h index 3bf802242..51d37bdba 100644 --- a/include/cef_browser.h +++ b/include/cef_browser.h @@ -380,6 +380,14 @@ class CefBrowserHost : public virtual CefBase { /*--cef()--*/ virtual void WasResized() =0; + /// + // Notify the browser that it has been hidden or shown. Layouting and + // CefRenderHandler::OnPaint notification will stop when the browser is + // hidden. This method is only used when window rendering is disabled. + /// + /*--cef()--*/ + virtual void WasHidden(bool hidden) =0; + /// // Invalidate the |dirtyRect| region of the view. The browser will call // CefRenderHandler::OnPaint asynchronously with the updated regions. This diff --git a/libcef/browser/browser_host_impl.cc b/libcef/browser/browser_host_impl.cc index 5b4c190b8..6a54de219 100644 --- a/libcef/browser/browser_host_impl.cc +++ b/libcef/browser/browser_host_impl.cc @@ -641,6 +641,32 @@ void CefBrowserHostImpl::WasResized() { widget->WasResized(); } +void CefBrowserHostImpl::WasHidden(bool hidden) { + if (!IsWindowRenderingDisabled()) { + NOTREACHED() << "Window rendering is not disabled"; + return; + } + + if (!CEF_CURRENTLY_ON_UIT()) { + CEF_POST_TASK(CEF_UIT, + base::Bind(&CefBrowserHostImpl::WasHidden, this, hidden)); + return; + } + + if (!web_contents()) + return; + + content::RenderWidgetHostImpl* widget = + content::RenderWidgetHostImpl::From(web_contents()->GetRenderViewHost()); + if (!widget) + return; + + if (hidden) + widget->WasHidden(); + else + widget->WasShown(); +} + void CefBrowserHostImpl::Invalidate(const CefRect& dirtyRect, PaintElementType type) { if (!IsWindowRenderingDisabled()) { @@ -848,6 +874,7 @@ void CefBrowserHostImpl::SendFocusEvent(bool setFocus) { widget->Blur(); } } + void CefBrowserHostImpl::SendCaptureLostEvent() { if (!CEF_CURRENTLY_ON_UIT()) { CEF_POST_TASK(CEF_UIT, diff --git a/libcef/browser/browser_host_impl.h b/libcef/browser/browser_host_impl.h index 9486dde03..6b6b01813 100644 --- a/libcef/browser/browser_host_impl.h +++ b/libcef/browser/browser_host_impl.h @@ -129,6 +129,7 @@ class CefBrowserHostImpl : public CefBrowserHost, virtual bool IsMouseCursorChangeDisabled() OVERRIDE; virtual bool IsWindowRenderingDisabled() OVERRIDE; virtual void WasResized() OVERRIDE; + virtual void WasHidden(bool hidden) OVERRIDE; virtual void Invalidate(const CefRect& dirtyRect, PaintElementType type) OVERRIDE; virtual void SendKeyEvent(const CefKeyEvent& event) OVERRIDE; diff --git a/libcef_dll/cpptoc/browser_host_cpptoc.cc b/libcef_dll/cpptoc/browser_host_cpptoc.cc index 545ae3833..fc4db80d8 100644 --- a/libcef_dll/cpptoc/browser_host_cpptoc.cc +++ b/libcef_dll/cpptoc/browser_host_cpptoc.cc @@ -335,6 +335,19 @@ void CEF_CALLBACK browser_host_was_resized(struct _cef_browser_host_t* self) { CefBrowserHostCppToC::Get(self)->WasResized(); } +void CEF_CALLBACK browser_host_was_hidden(struct _cef_browser_host_t* self, + int hidden) { + // AUTO-GENERATED CONTENT - DELETE THIS COMMENT BEFORE MODIFYING + + DCHECK(self); + if (!self) + return; + + // Execute + CefBrowserHostCppToC::Get(self)->WasHidden( + hidden?true:false); +} + void CEF_CALLBACK browser_host_invalidate(struct _cef_browser_host_t* self, const cef_rect_t* dirtyRect, enum cef_paint_element_type_t type) { // AUTO-GENERATED CONTENT - DELETE THIS COMMENT BEFORE MODIFYING @@ -504,6 +517,7 @@ CefBrowserHostCppToC::CefBrowserHostCppToC(CefBrowserHost* cls) struct_.struct_.is_window_rendering_disabled = browser_host_is_window_rendering_disabled; struct_.struct_.was_resized = browser_host_was_resized; + struct_.struct_.was_hidden = browser_host_was_hidden; struct_.struct_.invalidate = browser_host_invalidate; struct_.struct_.send_key_event = browser_host_send_key_event; struct_.struct_.send_mouse_click_event = browser_host_send_mouse_click_event; diff --git a/libcef_dll/ctocpp/browser_host_ctocpp.cc b/libcef_dll/ctocpp/browser_host_ctocpp.cc index ad09c30cb..021d3c8de 100644 --- a/libcef_dll/ctocpp/browser_host_ctocpp.cc +++ b/libcef_dll/ctocpp/browser_host_ctocpp.cc @@ -279,6 +279,17 @@ void CefBrowserHostCToCpp::WasResized() { struct_->was_resized(struct_); } +void CefBrowserHostCToCpp::WasHidden(bool hidden) { + if (CEF_MEMBER_MISSING(struct_, was_hidden)) + return; + + // AUTO-GENERATED CONTENT - DELETE THIS COMMENT BEFORE MODIFYING + + // Execute + struct_->was_hidden(struct_, + hidden); +} + void CefBrowserHostCToCpp::Invalidate(const CefRect& dirtyRect, PaintElementType type) { if (CEF_MEMBER_MISSING(struct_, invalidate)) diff --git a/libcef_dll/ctocpp/browser_host_ctocpp.h b/libcef_dll/ctocpp/browser_host_ctocpp.h index d5ef119dd..3cd89bdf1 100644 --- a/libcef_dll/ctocpp/browser_host_ctocpp.h +++ b/libcef_dll/ctocpp/browser_host_ctocpp.h @@ -56,6 +56,7 @@ class CefBrowserHostCToCpp virtual bool IsMouseCursorChangeDisabled() OVERRIDE; virtual bool IsWindowRenderingDisabled() OVERRIDE; virtual void WasResized() OVERRIDE; + virtual void WasHidden(bool hidden) OVERRIDE; virtual void Invalidate(const CefRect& dirtyRect, PaintElementType type) OVERRIDE; virtual void SendKeyEvent(const CefKeyEvent& event) OVERRIDE;