diff --git a/libcef/browser/browser_host_impl_win.cc b/libcef/browser/browser_host_impl_win.cc index ee228a486..7f46d11a9 100644 --- a/libcef/browser/browser_host_impl_win.cc +++ b/libcef/browser/browser_host_impl_win.cc @@ -589,13 +589,15 @@ LRESULT CALLBACK CefBrowserHostImpl::WndProc(HWND hwnd, UINT message, 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 && browser && browser->window_widget_) { - // Resize the Widget window to the full size of the browser window. + if (browser && browser->window_widget_) { + // Pass window resize events to the HWND for the DesktopNativeWidgetAura + // root window. Passing size 0x0 (wParam == SIZE_MINIMIZED, for example) + // will cause the widget to be hidden which reduces resource usage. RECT rc; GetClientRect(hwnd, &rc); - browser->window_widget_->SetSize(gfx::Size(rc.right, rc.bottom)); + SetWindowPos(HWNDForWidget(browser->window_widget_), NULL, + rc.left, rc.top, rc.right - rc.left, rc.bottom - rc.top, + SWP_NOZORDER); } return 0; diff --git a/tests/cefclient/cefclient_win.cpp b/tests/cefclient/cefclient_win.cpp index 3b4c2a748..1edc997e2 100644 --- a/tests/cefclient/cefclient_win.cpp +++ b/tests/cefclient/cefclient_win.cpp @@ -596,43 +596,51 @@ LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, } return 0; - case WM_SIZE: + case WM_SIZE: { if (!g_handler.get()) break; - // Mark the off-screen browser as hidden when the frame window is - // minimized to reduce resource usage. - if (AppIsOffScreenRenderingEnabled()) { + // For off-screen browsers when the frame window is minimized set the + // browser as hidden to reduce resource usage. + const bool offscreen = AppIsOffScreenRenderingEnabled(); + if (offscreen) { 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()) { + if (g_handler->GetBrowser()) { // Retrieve the window handle (parent window with off-screen rendering). CefWindowHandle hwnd = g_handler->GetBrowser()->GetHost()->GetWindowHandle(); if (hwnd) { - // Resize the window and address bar to match the new frame size. - RECT rect; - GetClientRect(hWnd, &rect); - rect.top += URLBAR_HEIGHT; + if (wParam == SIZE_MINIMIZED) { + // For windowed browsers when the frame window is minimized set the + // browser window size to 0x0 to reduce resource usage. + if (!offscreen) { + SetWindowPos(hwnd, NULL, + 0, 0, 0, 0, SWP_NOZORDER | SWP_NOMOVE | SWP_NOACTIVATE); + } + } else { + // Resize the window and address bar to match the new frame size. + RECT rect; + GetClientRect(hWnd, &rect); + rect.top += URLBAR_HEIGHT; - int urloffset = rect.left + BUTTON_WIDTH * 4; + int urloffset = rect.left + BUTTON_WIDTH * 4; - HDWP hdwp = BeginDeferWindowPos(1); - hdwp = DeferWindowPos(hdwp, editWnd, NULL, urloffset, - 0, rect.right - urloffset, URLBAR_HEIGHT, SWP_NOZORDER); - hdwp = DeferWindowPos(hdwp, hwnd, NULL, - rect.left, rect.top, rect.right - rect.left, rect.bottom - rect.top, - SWP_NOZORDER); - EndDeferWindowPos(hdwp); + HDWP hdwp = BeginDeferWindowPos(1); + hdwp = DeferWindowPos(hdwp, editWnd, NULL, urloffset, + 0, rect.right - urloffset, URLBAR_HEIGHT, SWP_NOZORDER); + hdwp = DeferWindowPos(hdwp, hwnd, NULL, + rect.left, rect.top, rect.right - rect.left, + rect.bottom - rect.top, SWP_NOZORDER); + EndDeferWindowPos(hdwp); + } } } - break; + } break; case WM_ERASEBKGND: if (g_handler.get() && g_handler->GetBrowser()) {