From df2242aff24a433ba6ca21799e31c8095a42037d Mon Sep 17 00:00:00 2001 From: Marshall Greenblatt Date: Thu, 4 Sep 2014 22:15:16 +0000 Subject: [PATCH] - Fix initial state of the |is_showing_| flag in CefRenderWidgetHostViewOSR (issue #1363). - Windows: Modify the cefclient OSR example to call WasHidden(true) when the app is minimized. git-svn-id: https://chromiumembedded.googlecode.com/svn/trunk@1818 5089003a-bbd8-11dd-ad1f-f1f9622dbc98 --- libcef/browser/render_widget_host_view_osr.cc | 2 +- tests/cefclient/cefclient.cpp | 18 +++++++++++---- tests/cefclient/cefclient_osr_widget_win.cpp | 13 ++++++++++- tests/cefclient/cefclient_osr_widget_win.h | 2 ++ tests/cefclient/cefclient_win.cpp | 23 ++++++++++++++----- 5 files changed, 46 insertions(+), 12 deletions(-) diff --git a/libcef/browser/render_widget_host_view_osr.cc b/libcef/browser/render_widget_host_view_osr.cc index d761728b6..acf41a3c7 100644 --- a/libcef/browser/render_widget_host_view_osr.cc +++ b/libcef/browser/render_widget_host_view_osr.cc @@ -155,7 +155,7 @@ CefRenderWidgetHostViewOSR::CefRenderWidgetHostViewOSR( render_widget_host_(content::RenderWidgetHostImpl::From(widget)), parent_host_view_(NULL), popup_host_view_(NULL), - is_showing_(false), + is_showing_(true), is_destroyed_(false), #if defined(OS_MACOSX) text_input_context_osr_mac_(NULL), diff --git a/tests/cefclient/cefclient.cpp b/tests/cefclient/cefclient.cpp index aa3a5542a..749e05fbc 100644 --- a/tests/cefclient/cefclient.cpp +++ b/tests/cefclient/cefclient.cpp @@ -18,7 +18,13 @@ #include "cefclient/string_util.h" CefRefPtr g_handler; + +namespace { + CefRefPtr g_command_line; +int g_offscreen_state = 0; + +} // namespace CefRefPtr AppGetBrowser() { if (!g_handler.get()) @@ -78,11 +84,15 @@ void AppGetBrowserSettings(CefBrowserSettings& settings) { } bool AppIsOffScreenRenderingEnabled() { - DCHECK(g_command_line.get()); - if (!g_command_line.get()) - return false; + if (g_offscreen_state == 0) { + // Store the value so it isn't queried multiple times. + DCHECK(g_command_line.get()); + g_offscreen_state = + g_command_line->HasSwitch(cefclient::kOffScreenRenderingEnabled) ? + 1 : 2; + } - return g_command_line->HasSwitch(cefclient::kOffScreenRenderingEnabled); + return (g_offscreen_state == 1); } void RunGetSourceTest(CefRefPtr browser) { diff --git a/tests/cefclient/cefclient_osr_widget_win.cpp b/tests/cefclient/cefclient_osr_widget_win.cpp index 0ec4c9712..630cd024b 100644 --- a/tests/cefclient/cefclient_osr_widget_win.cpp +++ b/tests/cefclient/cefclient_osr_widget_win.cpp @@ -192,6 +192,16 @@ void OSRWindow::Invalidate() { kRenderDelay); } +void OSRWindow::WasHidden(bool hidden) { + if (hidden == hidden_) + return; + CefRefPtr browser = browser_provider_->GetBrowser(); + if (!browser) + return; + browser->GetHost()->WasHidden(hidden); + hidden_ = hidden; +} + CefBrowserHost::DragOperationsMask OSRWindow::OnDragEnter(CefRefPtr drag_data, CefMouseEvent ev, @@ -226,9 +236,10 @@ OSRWindow::OSRWindow(OSRBrowserProvider* browser_provider, bool transparent) hWnd_(NULL), hDC_(NULL), hRC_(NULL), + current_drag_op_(DRAG_OPERATION_NONE), painting_popup_(false), render_task_pending_(false), - current_drag_op_(DRAG_OPERATION_NONE) { + hidden_(false) { } OSRWindow::~OSRWindow() { diff --git a/tests/cefclient/cefclient_osr_widget_win.h b/tests/cefclient/cefclient_osr_widget_win.h index 811e8a154..c7542f426 100644 --- a/tests/cefclient/cefclient_osr_widget_win.h +++ b/tests/cefclient/cefclient_osr_widget_win.h @@ -87,6 +87,7 @@ class OSRWindow : public ClientHandler::RenderHandler, CefBrowserHost::DragOperationsMask effect) OVERRIDE; void Invalidate(); + void WasHidden(bool hidden); static int GetCefKeyboardModifiers(WPARAM wparam, LPARAM lparam); static int GetCefMouseModifiers(WPARAM wparam); @@ -119,6 +120,7 @@ class OSRWindow : public ClientHandler::RenderHandler, bool painting_popup_; bool render_task_pending_; + bool hidden_; IMPLEMENT_REFCOUNTING(OSRWindow); }; diff --git a/tests/cefclient/cefclient_win.cpp b/tests/cefclient/cefclient_win.cpp index 91077db80..3b4c2a748 100644 --- a/tests/cefclient/cefclient_win.cpp +++ b/tests/cefclient/cefclient_win.cpp @@ -597,15 +597,26 @@ LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, return 0; case WM_SIZE: - // Minimizing resizes the window to 0x0 which causes our layout to go all - // screwy, so we just ignore it. - if (wParam != SIZE_MINIMIZED && g_handler.get() && - g_handler->GetBrowser()) { + if (!g_handler.get()) + break; + + // Mark the off-screen browser as hidden when the frame window is + // minimized to reduce resource usage. + if (AppIsOffScreenRenderingEnabled()) { + CefRefPtr osr_window = + static_cast(g_handler->GetOSRHandler().get()); + if (osr_window) + osr_window->WasHidden(wParam == SIZE_MINIMIZED); + } + + // Don't resize the window if minimizing because the resulting size of 0x0 + // causes the layout to go all screwy. + if (wParam != SIZE_MINIMIZED && g_handler->GetBrowser()) { + // Retrieve the window handle (parent window with off-screen rendering). CefWindowHandle hwnd = g_handler->GetBrowser()->GetHost()->GetWindowHandle(); if (hwnd) { - // Resize the browser window and address bar to match the new frame - // window size + // Resize the window and address bar to match the new frame size. RECT rect; GetClientRect(hWnd, &rect); rect.top += URLBAR_HEIGHT;