diff --git a/shell/browser/native_window_views_win.cc b/shell/browser/native_window_views_win.cc index 510dcbd9f78b..72adbf19f0a5 100644 --- a/shell/browser/native_window_views_win.cc +++ b/shell/browser/native_window_views_win.cc @@ -239,6 +239,15 @@ int GetAppbarAutohideEdges(HWND hwnd) { return edges; } +void TriggerNCCalcSize(HWND hwnd) { + RECT rcClient; + ::GetWindowRect(hwnd, &rcClient); + + ::SetWindowPos(hwnd, NULL, rcClient.left, rcClient.top, + rcClient.right - rcClient.left, rcClient.bottom - rcClient.top, + SWP_FRAMECHANGED); +} + } // namespace std::set NativeWindowViews::forwarding_windows_; @@ -369,8 +378,12 @@ bool NativeWindowViews::PreHandleMSG(UINT message, // https://blogs.msdn.microsoft.com/wpfsdk/2008/09/08/custom-window-chrome-in-wpf/ DefWindowProcW(GetAcceleratedWidget(), WM_NCCALCSIZE, w_param, l_param); - params->rgrc[0] = PROPOSED; - params->rgrc[1] = BEFORE; + if (last_window_state_ == ui::SHOW_STATE_MAXIMIZED) { + params->rgrc[0].top = 0; + } else { + params->rgrc[0] = PROPOSED; + params->rgrc[1] = BEFORE; + } return true; } else { @@ -453,26 +466,15 @@ void NativeWindowViews::HandleSizeEvent(WPARAM w_param, LPARAM l_param) { // window state and notify the user accordingly. switch (w_param) { case SIZE_MAXIMIZED: { - // Frameless maximized windows are size compensated by Windows for a - // border that's not actually there, so we must conter-compensate. - // https://blogs.msdn.microsoft.com/wpfsdk/2008/09/08/custom-window-chrome-in-wpf/ - if (!has_frame()) { - float scale_factor = display::win::ScreenWin::GetScaleFactorForHWND( - GetAcceleratedWidget()); - - int border = - GetSystemMetrics(SM_CXFRAME) + GetSystemMetrics(SM_CXPADDEDBORDER); - if (!thick_frame_) { - border -= GetSystemMetrics(SM_CXBORDER); - } - root_view_->SetInsets(gfx::Insets(border).Scale(1.0f / scale_factor)); - } - last_window_state_ = ui::SHOW_STATE_MAXIMIZED; if (consecutive_moves_) { last_normal_bounds_ = last_normal_bounds_before_move_; } + if (!has_frame()) { + TriggerNCCalcSize(GetAcceleratedWidget()); + } + NotifyWindowMaximize(); break; } @@ -497,8 +499,12 @@ void NativeWindowViews::HandleSizeEvent(WPARAM w_param, LPARAM l_param) { switch (last_window_state_) { case ui::SHOW_STATE_MAXIMIZED: last_window_state_ = ui::SHOW_STATE_NORMAL; - root_view_->SetInsets(gfx::Insets(0)); NotifyWindowUnmaximize(); + + if (!has_frame()) { + TriggerNCCalcSize(GetAcceleratedWidget()); + } + break; case ui::SHOW_STATE_MINIMIZED: if (IsFullscreen()) { diff --git a/shell/browser/ui/views/root_view.cc b/shell/browser/ui/views/root_view.cc index 3f54b68c7980..761202fffe39 100644 --- a/shell/browser/ui/views/root_view.cc +++ b/shell/browser/ui/views/root_view.cc @@ -176,18 +176,14 @@ void RootView::Layout() { return; const auto menu_bar_bounds = - menu_bar_visible_ - ? gfx::Rect(insets_.left(), insets_.top(), - size().width() - insets_.width(), kMenuBarHeight) - : gfx::Rect(); + menu_bar_visible_ ? gfx::Rect(0, 0, size().width(), kMenuBarHeight) + : gfx::Rect(); if (menu_bar_) menu_bar_->SetBoundsRect(menu_bar_bounds); window_->content_view()->SetBoundsRect( - gfx::Rect(insets_.left(), - menu_bar_visible_ ? menu_bar_bounds.bottom() : insets_.top(), - size().width() - insets_.width(), - size().height() - menu_bar_bounds.height() - insets_.height())); + gfx::Rect(0, menu_bar_visible_ ? menu_bar_bounds.bottom() : 0, + size().width(), size().height() - menu_bar_bounds.height())); } gfx::Size RootView::GetMinimumSize() const { @@ -224,11 +220,4 @@ void RootView::UnregisterAcceleratorsWithFocusManager() { focus_manager->UnregisterAccelerators(this); } -void RootView::SetInsets(const gfx::Insets& insets) { - if (insets != insets_) { - insets_ = insets; - Layout(); - } -} - } // namespace electron diff --git a/shell/browser/ui/views/root_view.h b/shell/browser/ui/views/root_view.h index 07c440946e70..5a1c41232450 100644 --- a/shell/browser/ui/views/root_view.h +++ b/shell/browser/ui/views/root_view.h @@ -40,8 +40,6 @@ class RootView : public views::View { // Register/Unregister accelerators supported by the menu model. void RegisterAcceleratorsWithFocusManager(AtomMenuModel* menu_model); void UnregisterAcceleratorsWithFocusManager(); - void SetInsets(const gfx::Insets& insets); - gfx::Insets insets() const { return insets_; } // views::View: void Layout() override; @@ -59,8 +57,6 @@ class RootView : public views::View { bool menu_bar_visible_ = false; bool menu_bar_alt_pressed_ = false; - gfx::Insets insets_; - // Map from accelerator to menu item's command id. accelerator_util::AcceleratorTable accelerator_table_;