Use NSView convertRect:toView: for BrowserView DragRegionView positioning
This commit is contained in:
parent
377e6c3210
commit
3b8ddd0997
1 changed files with 24 additions and 39 deletions
|
@ -195,53 +195,38 @@ void NativeBrowserViewMac::SetBackgroundColor(SkColor color) {
|
||||||
|
|
||||||
void NativeBrowserViewMac::UpdateDraggableRegions(
|
void NativeBrowserViewMac::UpdateDraggableRegions(
|
||||||
const std::vector<gfx::Rect>& drag_exclude_rects) {
|
const std::vector<gfx::Rect>& drag_exclude_rects) {
|
||||||
NSView* webView = GetInspectableWebContentsView()->GetNativeView();
|
NSView* inspectable_view = GetInspectableWebContentsView()->GetNativeView();
|
||||||
|
NSView* window_content_view = inspectable_view.superview;
|
||||||
|
const auto window_content_view_height = NSHeight(window_content_view.bounds);
|
||||||
|
|
||||||
NSInteger superViewHeight = NSHeight([webView.superview bounds]);
|
// Remove all DragRegionViews that were added last time. Note that we need
|
||||||
NSInteger webViewHeight = NSHeight([webView bounds]);
|
// to copy the `subviews` array to avoid mutation during iteration.
|
||||||
NSInteger webViewWidth = NSWidth([webView bounds]);
|
base::scoped_nsobject<NSArray> subviews([[inspectable_view subviews] copy]);
|
||||||
NSInteger webViewX = NSMinX([webView frame]);
|
for (NSView* subview in subviews.get()) {
|
||||||
NSInteger webViewY = 0;
|
if ([subview isKindOfClass:[DragRegionView class]]) {
|
||||||
|
[subview removeFromSuperview];
|
||||||
// Apple's NSViews have their coordinate system originate at the bottom left,
|
}
|
||||||
// meaning that we need to be a bit smarter when it comes to calculating our
|
|
||||||
// current top offset
|
|
||||||
if (webViewHeight > superViewHeight) {
|
|
||||||
webViewY = std::abs(webViewHeight - superViewHeight - (std::abs(NSMinY([webView frame]))));
|
|
||||||
} else {
|
|
||||||
webViewY = superViewHeight - NSMaxY([webView frame]);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Remove all DraggableRegionViews that are added last time.
|
|
||||||
// Note that [webView subviews] returns the view's mutable internal array and
|
|
||||||
// it should be copied to avoid mutating the original array while enumerating
|
|
||||||
// it.
|
|
||||||
base::scoped_nsobject<NSArray> subviews([[webView subviews] copy]);
|
|
||||||
for (NSView* subview in subviews.get())
|
|
||||||
if ([subview isKindOfClass:[DragRegionView class]])
|
|
||||||
[subview removeFromSuperview];
|
|
||||||
|
|
||||||
// Create one giant NSView that is draggable.
|
// Create one giant NSView that is draggable.
|
||||||
base::scoped_nsobject<NSView> dragRegion(
|
base::scoped_nsobject<NSView> drag_region_view(
|
||||||
[[DragRegionView alloc] initWithFrame:NSZeroRect]);
|
[[DragRegionView alloc] initWithFrame:inspectable_view.bounds]);
|
||||||
[dragRegion setFrame:NSMakeRect(0,
|
[inspectable_view addSubview:drag_region_view];
|
||||||
0,
|
|
||||||
webViewWidth,
|
|
||||||
webViewHeight)];
|
|
||||||
|
|
||||||
// Then, on top of that, add "exclusion zones"
|
// Then, on top of that, add "exclusion zones"
|
||||||
for (const auto& rect : drag_exclude_rects) {
|
for (const auto& rect : drag_exclude_rects) {
|
||||||
base::scoped_nsobject<NSView> controlRegion(
|
const auto window_content_view_exclude_rect =
|
||||||
[[ExcludeDragRegionView alloc] initWithFrame:NSZeroRect]);
|
NSMakeRect(rect.x(), window_content_view_height - rect.bottom(),
|
||||||
[controlRegion setFrame:NSMakeRect(rect.x() - webViewX,
|
rect.width(), rect.height());
|
||||||
webViewHeight - rect.bottom() + webViewY,
|
const auto drag_region_view_exclude_rect =
|
||||||
rect.width(),
|
[window_content_view convertRect:window_content_view_exclude_rect
|
||||||
rect.height())];
|
toView:drag_region_view];
|
||||||
[dragRegion addSubview:controlRegion];
|
|
||||||
}
|
|
||||||
|
|
||||||
// Add the DragRegion to the WebView
|
base::scoped_nsobject<NSView> exclude_drag_region_view(
|
||||||
[webView addSubview:dragRegion];
|
[[ExcludeDragRegionView alloc]
|
||||||
|
initWithFrame:drag_region_view_exclude_rect]);
|
||||||
|
[drag_region_view addSubview:exclude_drag_region_view];
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// static
|
// static
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue