|
@@ -267,65 +267,4 @@ void InspectableWebContentsViewMac::SetTitle(const std::u16string& title) {
|
|
|
[view_ setTitle:base::SysUTF16ToNSString(title)];
|
|
|
}
|
|
|
|
|
|
-void InspectableWebContentsViewMac::UpdateDraggableRegions(
|
|
|
- const std::vector<mojom::DraggableRegionPtr>& regions) {
|
|
|
- auto* web_contents = inspectable_web_contents()->GetWebContents();
|
|
|
- NSView* web_view = web_contents->GetNativeView().GetNativeNSView();
|
|
|
- NSView* inspectable_view = GetNativeView().GetNativeNSView();
|
|
|
- NSView* inspectable_superview = inspectable_view.superview;
|
|
|
-
|
|
|
- NSInteger webViewWidth = NSWidth([web_view bounds]);
|
|
|
- NSInteger webViewHeight = NSHeight([web_view bounds]);
|
|
|
-
|
|
|
- // Draggable regions are implemented by having the whole web view draggable
|
|
|
- // and overlaying regions that are not draggable.
|
|
|
- if (&draggable_regions_ != ®ions)
|
|
|
- draggable_regions_ = mojo::Clone(regions);
|
|
|
-
|
|
|
- std::vector<gfx::Rect> drag_exclude_rects;
|
|
|
- if (draggable_regions_.empty()) {
|
|
|
- drag_exclude_rects.emplace_back(0, 0, webViewWidth, webViewHeight);
|
|
|
- } else {
|
|
|
- drag_exclude_rects = CalculateNonDraggableRegions(
|
|
|
- DraggableRegionsToSkRegion(draggable_regions_), webViewWidth,
|
|
|
- webViewHeight);
|
|
|
- }
|
|
|
-
|
|
|
- // 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([[web_view subviews] copy]);
|
|
|
- for (NSView* subview in subviews.get()) {
|
|
|
- if ([subview isKindOfClass:[DragRegionView class]])
|
|
|
- [subview removeFromSuperview];
|
|
|
- }
|
|
|
-
|
|
|
- // Create one giant NSView that is draggable.
|
|
|
- base::scoped_nsobject<NSView> drag_region_view(
|
|
|
- [[DragRegionView alloc] initWithFrame:web_view.bounds]);
|
|
|
- [web_view addSubview:drag_region_view];
|
|
|
-
|
|
|
- // Then, on top of that, add "exclusion zones".
|
|
|
- const int superview_height =
|
|
|
- (inspectable_superview) ? inspectable_superview.frame.size.height : 0;
|
|
|
- if (!inspectable_superview)
|
|
|
- inspectable_superview = inspectable_view;
|
|
|
- const int offset_x = inspectable_view.frame.origin.x;
|
|
|
- const int offset_y = superview_height - inspectable_view.frame.origin.y -
|
|
|
- inspectable_view.frame.size.height;
|
|
|
- for (const auto& rect : drag_exclude_rects) {
|
|
|
- const auto x = rect.x() + offset_x;
|
|
|
- const auto y = superview_height - (rect.bottom() + offset_y);
|
|
|
- const auto exclude_rect = NSMakeRect(x, y, rect.width(), rect.height());
|
|
|
-
|
|
|
- const auto drag_region_view_exclude_rect =
|
|
|
- [inspectable_superview convertRect:exclude_rect
|
|
|
- toView:drag_region_view];
|
|
|
-
|
|
|
- base::scoped_nsobject<NSView> exclude_drag_region_view(
|
|
|
- [[ExcludeDragRegionView alloc]
|
|
|
- initWithFrame:drag_region_view_exclude_rect]);
|
|
|
- [drag_region_view addSubview:exclude_drag_region_view];
|
|
|
- }
|
|
|
-}
|
|
|
-
|
|
|
} // namespace electron
|