refactor: add NativeWindow::FromWidget() helper (#46917)

refactor: add NativeWindow::FromWidet() helper

refactor: make kElectronNativeWindowKey a protected field
This commit is contained in:
Charles Kerr 2025-05-05 09:27:41 -05:00 committed by GitHub
commit 1f4f1b4afc
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
5 changed files with 20 additions and 12 deletions

View file

@ -99,12 +99,11 @@ void WebContentsView::WebContentsDestroyed() {
void WebContentsView::OnViewAddedToWidget(views::View* observed_view) {
DCHECK_EQ(observed_view, view());
views::Widget* widget = view()->GetWidget();
auto* native_window =
static_cast<NativeWindow*>(widget->GetNativeWindowProperty(
electron::kElectronNativeWindowKey.c_str()));
NativeWindow* native_window = NativeWindow::FromWidget(view()->GetWidget());
if (!native_window)
return;
// We don't need to call SetOwnerWindow(nullptr) in OnViewRemovedFromWidget
// because that's handled in the WebContents dtor called prior.
api_web_contents_->SetOwnerWindow(native_window);
@ -114,11 +113,11 @@ void WebContentsView::OnViewAddedToWidget(views::View* observed_view) {
void WebContentsView::OnViewRemovedFromWidget(views::View* observed_view) {
DCHECK_EQ(observed_view, view());
views::Widget* widget = view()->GetWidget();
auto* native_window = static_cast<NativeWindow*>(
widget->GetNativeWindowProperty(kElectronNativeWindowKey.c_str()));
NativeWindow* native_window = NativeWindow::FromWidget(view()->GetWidget());
if (!native_window)
return;
native_window->RemoveDraggableRegionProvider(this);
}