🔧 Make work with complex shapes
This commit is contained in:
parent
fdd0d67fd3
commit
ebe058e7cb
4 changed files with 67 additions and 21 deletions
|
@ -42,7 +42,7 @@ class NativeBrowserView {
|
|||
|
||||
// Called when the window needs to update its draggable region.
|
||||
virtual void UpdateDraggableRegions(
|
||||
const std::vector<DraggableRegion>& regions) = 0;
|
||||
std::vector<gfx::Rect> system_drag_exclude_areas) = 0;
|
||||
|
||||
protected:
|
||||
explicit NativeBrowserView(
|
||||
|
|
|
@ -22,7 +22,7 @@ class NativeBrowserViewMac : public NativeBrowserView {
|
|||
void SetAutoResizeFlags(uint8_t flags) override;
|
||||
void SetBounds(const gfx::Rect& bounds) override;
|
||||
void SetBackgroundColor(SkColor color) override;
|
||||
void UpdateDraggableRegions(const std::vector<DraggableRegion>& regions) override;
|
||||
void UpdateDraggableRegions(std::vector<gfx::Rect> system_drag_exclude_areas) override;
|
||||
|
||||
private:
|
||||
DISALLOW_COPY_AND_ASSIGN(NativeBrowserViewMac);
|
||||
|
|
|
@ -27,6 +27,17 @@ const NSAutoresizingMaskOptions kDefaultAutoResizingMask =
|
|||
return NO;
|
||||
}
|
||||
|
||||
- (NSView *)hitTest:(NSPoint)aPoint
|
||||
{
|
||||
// Pass-through events that don't hit one of the exclusion zones
|
||||
for (NSView *exlusion_zones in [self subviews]) {
|
||||
if ([exlusion_zones hitTest:aPoint])
|
||||
return nil;
|
||||
}
|
||||
|
||||
return self;
|
||||
}
|
||||
|
||||
- (void)mouseDown:(NSEvent *)event
|
||||
{
|
||||
if ([self.window respondsToSelector:@selector(performWindowDragWithEvent:)]) {
|
||||
|
@ -63,13 +74,32 @@ const NSAutoresizingMaskOptions kDefaultAutoResizingMask =
|
|||
}
|
||||
|
||||
// Debugging tips:
|
||||
// Uncomment the following four lines to color DragRegionViews bright red
|
||||
- (void)drawRect:(NSRect)aRect
|
||||
{
|
||||
[[NSColor redColor] set];
|
||||
NSRectFill([self bounds]);
|
||||
// Uncomment the following four lines to color DragRegionView bright red
|
||||
// - (void)drawRect:(NSRect)aRect
|
||||
// {
|
||||
// [[NSColor redColor] set];
|
||||
// NSRectFill([self bounds]);
|
||||
// }
|
||||
|
||||
@end
|
||||
|
||||
@interface ExcludeDragRegionView : NSView
|
||||
@end
|
||||
|
||||
@implementation ExcludeDragRegionView
|
||||
|
||||
- (BOOL)mouseDownCanMoveWindow {
|
||||
return NO;
|
||||
}
|
||||
|
||||
// Debugging tips:
|
||||
// Uncomment the following four lines to color ExcludeDragRegionView bright red
|
||||
// - (void)drawRect:(NSRect)aRect
|
||||
// {
|
||||
// [[NSColor greenColor] set];
|
||||
// NSRectFill([self bounds]);
|
||||
// }
|
||||
|
||||
@end
|
||||
|
||||
namespace atom {
|
||||
|
@ -112,9 +142,10 @@ void NativeBrowserViewMac::SetBackgroundColor(SkColor color) {
|
|||
}
|
||||
|
||||
void NativeBrowserViewMac::UpdateDraggableRegions(
|
||||
const std::vector<DraggableRegion>& regions) {
|
||||
std::vector<gfx::Rect> system_drag_exclude_areas) {
|
||||
NSView* webView = GetInspectableWebContentsView()->GetNativeView();
|
||||
NSInteger webViewHeight = NSHeight([webView bounds]);
|
||||
NSInteger webViewWidth = NSWidth([webView bounds]);
|
||||
|
||||
// Remove all DraggableRegionViews that are added last time.
|
||||
// Note that [webView subviews] returns the view's mutable internal array and
|
||||
|
@ -125,15 +156,30 @@ void NativeBrowserViewMac::UpdateDraggableRegions(
|
|||
if ([subview isKindOfClass:[DragRegionView class]])
|
||||
[subview removeFromSuperview];
|
||||
|
||||
for (const DraggableRegion& region : regions) {
|
||||
base::scoped_nsobject<NSView> dragRegion(
|
||||
// Create one giant NSView that is draggable.
|
||||
base::scoped_nsobject<NSView> dragRegion(
|
||||
[[DragRegionView alloc] initWithFrame:NSZeroRect]);
|
||||
[dragRegion setFrame:NSMakeRect(region.bounds.x(),
|
||||
webViewHeight - region.bounds.bottom(),
|
||||
region.bounds.width(),
|
||||
region.bounds.height())];
|
||||
[webView addSubview:dragRegion];
|
||||
[dragRegion setFrame:NSMakeRect(0,
|
||||
0,
|
||||
webViewWidth,
|
||||
webViewHeight)];
|
||||
|
||||
// Then, on top of that, add "exclusion zones"
|
||||
for (std::vector<gfx::Rect>::const_iterator iter =
|
||||
system_drag_exclude_areas.begin();
|
||||
iter != system_drag_exclude_areas.end();
|
||||
++iter) {
|
||||
base::scoped_nsobject<NSView> controlRegion(
|
||||
[[ExcludeDragRegionView alloc] initWithFrame:NSZeroRect]);
|
||||
[controlRegion setFrame:NSMakeRect(iter->x(),
|
||||
webViewHeight - iter->bottom(),
|
||||
iter->width(),
|
||||
iter->height())];
|
||||
[dragRegion addSubview:controlRegion];
|
||||
}
|
||||
|
||||
// Add the DragRegion to the WebView
|
||||
[webView addSubview:dragRegion];
|
||||
}
|
||||
|
||||
// static
|
||||
|
|
|
@ -1753,12 +1753,6 @@ void NativeWindowMac::UpdateDraggableRegionViews(
|
|||
[webView setMouseDownCanMoveWindow:YES];
|
||||
}
|
||||
|
||||
// Call down to a BrowserView, if it exists, and inform it about the
|
||||
// draggable areas
|
||||
if (browser_view_) {
|
||||
browser_view_->UpdateDraggableRegions(regions);
|
||||
}
|
||||
|
||||
// Remove all ControlRegionViews 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
|
||||
|
@ -1773,6 +1767,12 @@ void NativeWindowMac::UpdateDraggableRegionViews(
|
|||
std::vector<gfx::Rect> system_drag_exclude_areas =
|
||||
CalculateNonDraggableRegions(regions, webViewWidth, webViewHeight);
|
||||
|
||||
// Call down to a BrowserView, if it exists, and inform it about the
|
||||
// draggable areas
|
||||
if (browser_view_) {
|
||||
browser_view_->UpdateDraggableRegions(system_drag_exclude_areas);
|
||||
}
|
||||
|
||||
// Create and add a ControlRegionView for each region that needs to be
|
||||
// excluded from the dragging.
|
||||
for (std::vector<gfx::Rect>::const_iterator iter =
|
||||
|
|
Loading…
Reference in a new issue