mirror of
https://github.com/electron/electron.git
synced 2026-05-02 03:00:22 -04:00
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:
@@ -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_;
|
||||
}
|
||||
|
||||
@@ -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__";
|
||||
|
||||
@@ -381,7 +381,7 @@ void NativeWindowMac::SetContentView(views::View* view) {
|
||||
|
||||
root_view->AddChildViewRaw(content_view());
|
||||
|
||||
root_view->DeprecatedLayoutImmediately();
|
||||
FlushPendingRootLayout(root_view);
|
||||
}
|
||||
|
||||
void NativeWindowMac::Close() {
|
||||
|
||||
@@ -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() {
|
||||
|
||||
@@ -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) {
|
||||
|
||||
Reference in New Issue
Block a user