chore: remove calls to DeprecatedLayoutImmediately (#51183)

* chore: remove calls to DeprecatedLayoutImmediately

Replace the calls to `DeprecatedLayoutImmediately` that have test
coverage.

- The docked DevTools test added last week covers the three calls in IWCV.

- api-web-contents-view-spec covers the calls from NativeWindow{Views,Mac}.

There are a couple of remaining calls that don't have test coverage yet.
I'll get to them in a followup.

* test: handle both sync or microtask layout

* refactor: add a FlushPendingRootLayout() helper
This commit is contained in:
Charles Kerr
2026-04-22 05:34:07 -05:00
committed by GitHub
parent 71e8a5ca80
commit 54eb30a642
5 changed files with 23 additions and 5 deletions

View File

@@ -240,6 +240,13 @@ void NativeWindow::SetShape(const std::vector<gfx::Rect>& rects) {
widget()->SetShape(std::make_unique<std::vector<gfx::Rect>>(rects));
}
void NativeWindow::FlushPendingRootLayout(views::View* view) {
view->InvalidateLayout();
if (views::Widget* widget = view->GetWidget())
widget->LayoutRootViewIfNecessary();
}
bool NativeWindow::IsClosed() const {
return is_closed_;
}

View File

@@ -462,6 +462,7 @@ class NativeWindow : public views::WidgetDelegate {
const views::Widget* GetWidget() const override;
void set_content_view(views::View* view) { content_view_ = view; }
void FlushPendingRootLayout(views::View* view);
static inline constexpr base::cstring_view kNativeWindowKey =
"__ELECTRON_NATIVE_WINDOW__";

View File

@@ -381,7 +381,7 @@ void NativeWindowMac::SetContentView(views::View* view) {
root_view->AddChildViewRaw(content_view());
root_view->DeprecatedLayoutImmediately();
FlushPendingRootLayout(root_view);
}
void NativeWindowMac::Close() {

View File

@@ -533,7 +533,7 @@ void NativeWindowViews::SetContentView(views::View* view) {
set_content_view(view);
focused_view_ = view;
root_view_.GetMainView()->AddChildViewRaw(content_view());
root_view_.GetMainView()->DeprecatedLayoutImmediately();
FlushPendingRootLayout(root_view_.GetMainView());
}
void NativeWindowViews::Close() {

View File

@@ -23,6 +23,16 @@
#include "ui/views/window/client_view.h"
namespace electron {
namespace {
void FlushPendingRootLayout(views::View* view) {
view->InvalidateLayout();
if (views::Widget* widget = view->GetWidget())
widget->LayoutRootViewIfNecessary();
}
} // namespace
class DevToolsWindowDelegate : public views::ClientView,
public views::WidgetDelegate {
@@ -135,7 +145,7 @@ void InspectableWebContentsView::ShowDevTools(bool activate) {
devtools_web_view_->SetWebContents(
inspectable_web_contents_->GetDevToolsWebContents());
devtools_web_view_->RequestFocus();
DeprecatedLayoutImmediately();
FlushPendingRootLayout(this);
}
}
@@ -173,7 +183,7 @@ void InspectableWebContentsView::CloseDevTools() {
} else {
devtools_web_view_->SetVisible(false);
devtools_web_view_->SetWebContents(nullptr);
DeprecatedLayoutImmediately();
FlushPendingRootLayout(this);
}
}
@@ -223,7 +233,7 @@ void InspectableWebContentsView::SetIsDocked(bool docked, bool activate) {
void InspectableWebContentsView::SetContentsResizingStrategy(
const DevToolsContentsResizingStrategy& strategy) {
strategy_.CopyFrom(strategy);
DeprecatedLayoutImmediately();
FlushPendingRootLayout(this);
}
void InspectableWebContentsView::SetTitle(const std::u16string& title) {