refactor: don't call deprecated WidgetDelegate
API in NativeWindowViews
(#46885)
* refactor: don't call RegisterDeleteDelegateCallback() move NativeWindowViews' on-widget-delegate-destroyed callback logic to the NativeWindowViews destructor. Since NativeWindowViews subclasses from WidgetDelegate and |this| *is* the delegate being destroyed, we can handle this more cleanly in ~NativeWindowViews() instead of in a separate callback. Co-authored-by: Charles Kerr <charles@charleskerr.com> * chore: remove NativeWindowViews from the grandfathered-classes-that-can-call-deprecated-views-behavior patch Co-authored-by: Charles Kerr <charles@charleskerr.com> * refactor: don't call RegisterDeleteDelegateCallback() RegisterDeleteDelegateCallback() is private upstream API, so we shouldn't be using it. Move the on-widget-delegate-destroyed callback logic over to our methods NativeWindowViews::OnWidgetDestroying() and NativeWindowViews::OnWidgetDestroyed(). Co-authored-by: Charles Kerr <charles@charleskerr.com> --------- Co-authored-by: trop[bot] <37223003+trop[bot]@users.noreply.github.com> Co-authored-by: Charles Kerr <charles@charleskerr.com>
This commit is contained in:
parent
6696b98ecc
commit
7c77018b19
2 changed files with 16 additions and 25 deletions
|
@ -49,10 +49,10 @@ index ae7eab37f12ba80ec423d229cf048021e9ba6765..507a75dc7947295db221b01356fa57ba
|
|||
// These existing cases are "grandfathered in", but there shouldn't be more.
|
||||
// See comments atop class.
|
||||
diff --git a/ui/views/widget/widget_delegate.h b/ui/views/widget/widget_delegate.h
|
||||
index 7c2463cb91d00de2b0fa4f10221ea960be860d9a..0d5c63e7efbe42d5352abdeb594175904af30c41 100644
|
||||
index 7c2463cb91d00de2b0fa4f10221ea960be860d9a..e79beefddbd815e1ba7d9be86256e49d3ee7c619 100644
|
||||
--- a/ui/views/widget/widget_delegate.h
|
||||
+++ b/ui/views/widget/widget_delegate.h
|
||||
@@ -169,6 +169,13 @@ namespace data_controls {
|
||||
@@ -169,6 +169,12 @@ namespace data_controls {
|
||||
class DesktopDataControlsDialog;
|
||||
}
|
||||
|
||||
|
@ -60,13 +60,12 @@ index 7c2463cb91d00de2b0fa4f10221ea960be860d9a..0d5c63e7efbe42d5352abdeb59417590
|
|||
+class AutofillPopupView;
|
||||
+class DevToolsWindowDelegate;
|
||||
+class NativeWindowMac;
|
||||
+class NativeWindowViews;
|
||||
+}
|
||||
+
|
||||
namespace enterprise_connectors {
|
||||
class ContentAnalysisDialog;
|
||||
class ContentAnalysisDialogBehaviorBrowserTest;
|
||||
@@ -371,6 +378,7 @@ class VIEWS_EXPORT WidgetDelegate {
|
||||
@@ -371,6 +377,7 @@ class VIEWS_EXPORT WidgetDelegate {
|
||||
|
||||
class OwnedByWidgetPassKey {
|
||||
private:
|
||||
|
@ -74,16 +73,15 @@ index 7c2463cb91d00de2b0fa4f10221ea960be860d9a..0d5c63e7efbe42d5352abdeb59417590
|
|||
// DO NOT ADD TO THIS LIST!
|
||||
// These existing cases are "grandfathered in", but there shouldn't be more.
|
||||
// See comments atop `SetOwnedByWidget()`.
|
||||
@@ -468,6 +476,8 @@ class VIEWS_EXPORT WidgetDelegate {
|
||||
@@ -468,6 +475,7 @@ class VIEWS_EXPORT WidgetDelegate {
|
||||
};
|
||||
class RegisterDeleteCallbackPassKey {
|
||||
private:
|
||||
+ friend class electron::NativeWindowMac;
|
||||
+ friend class electron::NativeWindowViews;
|
||||
// DO NOT ADD TO THIS LIST!
|
||||
// These existing cases are "grandfathered in", but there shouldn't be more.
|
||||
// See comments atop `RegisterDeleteDelegateCallback()`.
|
||||
@@ -918,6 +928,7 @@ class VIEWS_EXPORT WidgetDelegateView : public WidgetDelegate, public View {
|
||||
@@ -918,6 +926,7 @@ class VIEWS_EXPORT WidgetDelegateView : public WidgetDelegate, public View {
|
||||
View* GetContentsView() override;
|
||||
|
||||
private:
|
||||
|
|
|
@ -435,22 +435,6 @@ NativeWindowViews::NativeWindowViews(const gin_helper::Dictionary& options,
|
|||
// bounds if the bounds are smaller than the current display
|
||||
SetBounds(gfx::Rect(GetPosition(), bounds.size()), false);
|
||||
#endif
|
||||
|
||||
RegisterDeleteDelegateCallback(
|
||||
RegisterDeleteCallbackPassKey(),
|
||||
base::BindOnce(
|
||||
[](NativeWindowViews* window) {
|
||||
if (window->is_modal() && window->parent()) {
|
||||
auto* parent = window->parent();
|
||||
// Enable parent window after current window gets closed.
|
||||
static_cast<NativeWindowViews*>(parent)->DecrementChildModals();
|
||||
// Focus on parent window.
|
||||
parent->Focus(true);
|
||||
}
|
||||
|
||||
window->NotifyWindowClosed();
|
||||
},
|
||||
this));
|
||||
}
|
||||
|
||||
NativeWindowViews::~NativeWindowViews() {
|
||||
|
@ -1725,13 +1709,22 @@ void NativeWindowViews::OnWidgetBoundsChanged(views::Widget* changed_widget,
|
|||
}
|
||||
|
||||
void NativeWindowViews::OnWidgetDestroying(views::Widget* widget) {
|
||||
aura::Window* window = GetNativeWindow();
|
||||
if (window)
|
||||
if (aura::Window* window = GetNativeWindow())
|
||||
window->RemovePreTargetHandler(this);
|
||||
|
||||
if (is_modal()) {
|
||||
if (NativeWindow* const parent = this->parent()) {
|
||||
// Enable parent window after current window gets closed.
|
||||
static_cast<NativeWindowViews*>(parent)->DecrementChildModals();
|
||||
// Focus on parent window.
|
||||
parent->Focus(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void NativeWindowViews::OnWidgetDestroyed(views::Widget* changed_widget) {
|
||||
widget_destroyed_ = true;
|
||||
NotifyWindowClosed();
|
||||
}
|
||||
|
||||
views::View* NativeWindowViews::GetInitiallyFocusedView() {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue