-
Notifications
You must be signed in to change notification settings - Fork 15.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add -webkit-app-region support to BrowserView #10232
Changes from 4 commits
df66223
fdd0d67
ebe058e
ae5c8e6
a5dfb09
a55015d
7bfece1
47d652b
d913b53
4c48908
b4bb008
6191e6e
f068058
cd5cd25
a44c2d5
fdfbf3a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,10 +8,100 @@ | |
#include "skia/ext/skia_utils_mac.h" | ||
#include "ui/gfx/geometry/rect.h" | ||
|
||
using base::scoped_nsobject; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is this needed? |
||
|
||
// Match view::Views behavior where the view sticks to the top-left origin. | ||
const NSAutoresizingMaskOptions kDefaultAutoResizingMask = | ||
NSViewMaxXMargin | NSViewMinYMargin; | ||
|
||
@interface DragRegionView : NSView | ||
|
||
@property (assign) NSPoint initialLocation; | ||
|
||
@end | ||
|
||
@implementation DragRegionView | ||
|
||
- (BOOL)mouseDownCanMoveWindow | ||
{ | ||
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:)]) { | ||
[self.window performWindowDragWithEvent:event]; | ||
return; | ||
} | ||
|
||
self.initialLocation = [event locationInWindow]; | ||
} | ||
|
||
- (void)mouseDragged:(NSEvent *)theEvent | ||
{ | ||
if ([self.window respondsToSelector:@selector(performWindowDragWithEvent:)]) { | ||
return; | ||
} | ||
|
||
NSPoint currentLocation; | ||
NSPoint newOrigin; | ||
|
||
NSRect screenFrame = [[NSScreen mainScreen] frame]; | ||
NSRect windowFrame = [self.window frame]; | ||
|
||
currentLocation = [NSEvent mouseLocation]; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Maybe we could move these up so that we don't have to leave |
||
newOrigin.x = currentLocation.x - self.initialLocation.x; | ||
newOrigin.y = currentLocation.y - self.initialLocation.y; | ||
|
||
// Don't let window get dragged up under the menu bar | ||
if( (newOrigin.y+windowFrame.size.height) > (screenFrame.origin.y+screenFrame.size.height) ){ | ||
newOrigin.y=screenFrame.origin.y + (screenFrame.size.height-windowFrame.size.height); | ||
} | ||
|
||
// Move the window to the new location | ||
[self.window setFrameOrigin:newOrigin]; | ||
} | ||
|
||
// Debugging tips: | ||
// Uncomment the following four lines to color DragRegionView bright red | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Maybe this could be in a:
with a comment at the top:
|
||
// - (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 { | ||
|
||
NativeBrowserViewMac::NativeBrowserViewMac( | ||
|
@@ -51,6 +141,47 @@ | |
view.layer.backgroundColor = skia::CGColorCreateFromSkColor(color); | ||
} | ||
|
||
void NativeBrowserViewMac::UpdateDraggableRegions( | ||
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 | ||
// 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. | ||
base::scoped_nsobject<NSView> dragRegion( | ||
[[DragRegionView alloc] initWithFrame:NSZeroRect]); | ||
[dragRegion setFrame:NSMakeRect(0, | ||
0, | ||
webViewWidth, | ||
webViewHeight)]; | ||
|
||
// Then, on top of that, add "exclusion zones" | ||
for (std::vector<gfx::Rect>::const_iterator iter = | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You can use |
||
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(), | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There is a good chance I'm missing something, but just in case: is this assuming the browser view bounds are 100% of the containing window? Should use |
||
webViewHeight - iter->bottom(), | ||
iter->width(), | ||
iter->height())]; | ||
[dragRegion addSubview:controlRegion]; | ||
} | ||
|
||
// Add the DragRegion to the WebView | ||
[webView addSubview:dragRegion]; | ||
} | ||
|
||
// static | ||
NativeBrowserView* NativeBrowserView::Create( | ||
brightray::InspectableWebContentsView* web_contents_view) { | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1767,6 +1767,12 @@ static bool FromV8(v8::Isolate* isolate, v8::Handle<v8::Value> val, | |
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 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think this comment is not needed, the code is sufficiently clear. |
||
// 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 = | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please use
const std::vector<gfx::Rect&
to avoid copying.Could you also use
{}
and get rid of the change tonative_browser_view.cc
.