Browse Source

refactor: AddBrowserView / RemoveBrowserView / SetTopBrowserView

Milan Burda 1 year ago
parent
commit
372523e4f5
2 changed files with 21 additions and 33 deletions
  1. 9 12
      shell/browser/native_window_mac.mm
  2. 12 21
      shell/browser/native_window_views.cc

+ 9 - 12
shell/browser/native_window_mac.mm

@@ -1268,14 +1268,13 @@ bool NativeWindowMac::IsFocusable() {
 }
 
 void NativeWindowMac::AddBrowserView(NativeBrowserView* view) {
-  [CATransaction begin];
-  [CATransaction setDisableActions:YES];
-
   if (!view) {
-    [CATransaction commit];
     return;
   }
 
+  [CATransaction begin];
+  [CATransaction setDisableActions:YES];
+
   add_browser_view(view);
   if (auto* native_view = GetNativeNSView(view)) {
     [[window_ contentView] addSubview:native_view
@@ -1288,14 +1287,13 @@ void NativeWindowMac::AddBrowserView(NativeBrowserView* view) {
 }
 
 void NativeWindowMac::RemoveBrowserView(NativeBrowserView* view) {
-  [CATransaction begin];
-  [CATransaction setDisableActions:YES];
-
   if (!view) {
-    [CATransaction commit];
     return;
   }
 
+  [CATransaction begin];
+  [CATransaction setDisableActions:YES];
+
   if (auto* native_view = GetNativeNSView(view)) {
     [native_view removeFromSuperview];
   }
@@ -1305,14 +1303,13 @@ void NativeWindowMac::RemoveBrowserView(NativeBrowserView* view) {
 }
 
 void NativeWindowMac::SetTopBrowserView(NativeBrowserView* view) {
-  [CATransaction begin];
-  [CATransaction setDisableActions:YES];
-
   if (!view) {
-    [CATransaction commit];
     return;
   }
 
+  [CATransaction begin];
+  [CATransaction setDisableActions:YES];
+
   remove_browser_view(view);
   add_browser_view(view);
   if (auto* native_view = GetNativeNSView(view)) {

+ 12 - 21
shell/browser/native_window_views.cc

@@ -1352,47 +1352,38 @@ void NativeWindowViews::SetMenu(ElectronMenuModel* menu_model) {
 }
 
 void NativeWindowViews::AddBrowserView(NativeBrowserView* view) {
-  if (!content_view())
-    return;
-
-  if (!view) {
+  if (!content_view() || !view) {
     return;
   }
 
   add_browser_view(view);
-  if (view->GetInspectableWebContentsView())
-    content_view()->AddChildView(
-        view->GetInspectableWebContentsView()->GetView());
+  if (auto* iwc_view = view->GetInspectableWebContentsView()) {
+    content_view()->AddChildView(iwc_view->GetView());
+  }
 }
 
 void NativeWindowViews::RemoveBrowserView(NativeBrowserView* view) {
-  if (!content_view())
-    return;
-
-  if (!view) {
+  if (!content_view() || !view) {
     return;
   }
 
-  if (view->GetInspectableWebContentsView())
-    content_view()->RemoveChildView(
-        view->GetInspectableWebContentsView()->GetView());
+  if (auto* iwc_view = view->GetInspectableWebContentsView()) {
+    content_view()->RemoveChildView(iwc_view->GetView());
+  }
   remove_browser_view(view);
 }
 
 void NativeWindowViews::SetTopBrowserView(NativeBrowserView* view) {
-  if (!content_view())
-    return;
-
-  if (!view) {
+  if (!content_view() || !view) {
     return;
   }
 
   remove_browser_view(view);
   add_browser_view(view);
 
-  if (view->GetInspectableWebContentsView())
-    content_view()->ReorderChildView(
-        view->GetInspectableWebContentsView()->GetView(), -1);
+  if (auto* iwc_view = view->GetInspectableWebContentsView()) {
+    content_view()->ReorderChildView(iwc_view->GetView(), -1);
+  }
 }
 
 void NativeWindowViews::SetParentWindow(NativeWindow* parent) {