Browse Source

Make BrowserView DragRegionViews children of the WebContents view

Previously they were children of the `InspectableWebContentsView` view,
which caused this assertion to fail:

https://github.com/electron/electron/blob/f9938884248627335c59da6b3b0ff0dc7df3b258/brightray/browser/mac/bry_inspectable_web_contents_view.mm#L162
Birunthan Mohanathas 7 years ago
parent
commit
42934a1006

+ 4 - 0
atom/browser/native_browser_view.cc

@@ -22,4 +22,8 @@ NativeBrowserView::GetInspectableWebContentsView() {
   return inspectable_web_contents_->GetView();
 }
 
+content::WebContents* NativeBrowserView::GetWebContents() {
+  return inspectable_web_contents_->GetWebContents();
+}
+
 }  // namespace atom

+ 2 - 0
atom/browser/native_browser_view.h

@@ -9,6 +9,7 @@
 
 #include "atom/common/draggable_region.h"
 #include "base/macros.h"
+#include "content/public/browser/web_contents.h"
 #include "third_party/skia/include/core/SkColor.h"
 
 namespace brightray {
@@ -39,6 +40,7 @@ class NativeBrowserView {
   }
 
   brightray::InspectableWebContentsView* GetInspectableWebContentsView();
+  content::WebContents* GetWebContents();
 
   virtual void SetAutoResizeFlags(uint8_t flags) = 0;
   virtual void SetBounds(const gfx::Rect& bounds) = 0;

+ 4 - 3
atom/browser/native_browser_view_mac.mm

@@ -195,13 +195,14 @@ void NativeBrowserViewMac::SetBackgroundColor(SkColor color) {
 
 void NativeBrowserViewMac::UpdateDraggableRegions(
     const std::vector<gfx::Rect>& drag_exclude_rects) {
+  NSView* web_view = GetWebContents()->GetNativeView();
   NSView* inspectable_view = GetInspectableWebContentsView()->GetNativeView();
   NSView* window_content_view = inspectable_view.superview;
   const auto window_content_view_height = NSHeight(window_content_view.bounds);
 
   // Remove all DragRegionViews that were added last time. Note that we need
   // to copy the `subviews` array to avoid mutation during iteration.
-  base::scoped_nsobject<NSArray> subviews([[inspectable_view subviews] copy]);
+  base::scoped_nsobject<NSArray> subviews([[web_view subviews] copy]);
   for (NSView* subview in subviews.get()) {
     if ([subview isKindOfClass:[DragRegionView class]]) {
       [subview removeFromSuperview];
@@ -210,8 +211,8 @@ void NativeBrowserViewMac::UpdateDraggableRegions(
 
   // Create one giant NSView that is draggable.
   base::scoped_nsobject<NSView> drag_region_view(
-      [[DragRegionView alloc] initWithFrame:inspectable_view.bounds]);
-  [inspectable_view addSubview:drag_region_view];
+      [[DragRegionView alloc] initWithFrame:web_view.bounds]);
+  [web_view addSubview:drag_region_view];
 
   // Then, on top of that, add "exclusion zones"
   for (const auto& rect : drag_exclude_rects) {