-
Notifications
You must be signed in to change notification settings - Fork 16.2k
Add -webkit-app-region support to BrowserView #10232
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
Conversation
++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 comment
The 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 view.frame
and view.superview.frame
to handle the case where the browserview.SetBounds()
has been used to position it in the bottom right corner?
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.
Awesome, thanks so much for fixing this! I left a few comments, but LGTM otherwise.
atom/browser/native_browser_view.h
Outdated
@@ -38,6 +40,10 @@ class NativeBrowserView { | |||
virtual void SetBounds(const gfx::Rect& bounds) = 0; | |||
virtual void SetBackgroundColor(SkColor color) = 0; | |||
|
|||
// Called when the window needs to update its draggable region. | |||
virtual void UpdateDraggableRegions( | |||
std::vector<gfx::Rect> system_drag_exclude_areas); |
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 to native_browser_view.cc
.
@@ -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 comment
The reason will be displayed to describe this comment to others. Learn more.
Is this needed?
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 comment
The reason will be displayed to describe this comment to others. Learn more.
You can use auto
instead of std::vector<gfx::Rect>::const_iterator
.
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 comment
The 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 currentLocation
and newOrigin
uninitailized. You could also you NSMakeRect
to initialize newOrigin
in one line.
} | ||
|
||
// 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 comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe this could be in a:
#ifdef DEBUG_DRAG_REGIONS
...
#endif
with a comment at the top:
// Uncomment to...
//#define DEBUG_DRAG_REGIONS
atom/browser/native_window_mac.mm
Outdated
@@ -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 comment
The reason will be displayed to describe this comment to others. Learn more.
I think this comment is not needed, the code is sufficiently clear.
Thanks a ton for the review, @poiru! I implemented all of it, this should now be "good to go":tm: |
67fb3ff
to
6191e6e
Compare
@felixrieseberg You've got a few cpp linting errors
|
@MarshallOfSound: Fixed! |
@felixrieseberg still got some weirdness here:
|
Hm, this one is tough. I'd love to use the method, but I'm not sure how to convince the build machines that I want to only use it if it's available. We can get by without, but the native drag feel is superior. |
@felixrieseberg You'd probably have to use a similar technique to the touchbar forward declarations. Issue is the build machiens SDK is less than 10.11 (I think it's 10.9) so it doesn't know anything about that method. You can forward declare though and then just wrap your method call in a version check |
I gave interface extension a try, that should work. @MarshallOfSound Thanks, if that doesn't stick, I'll study your code 👍 |
atom/browser/native_browser_view.cc
Outdated
|
||
#include "atom/browser/api/atom_api_web_contents.h" | ||
#include "atom/browser/native_browser_view.h" |
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.
Suprised linting doesn't complain about this, standard afaik is to have the header file for the current cc file as the first thing in the file (like it was originally). If you put this back at the top I'll approve it 😀
Add -webkit-app-region support to BrowserView
Backport #10232 (drag-browser-view)
This PR adds support for
-webkit-app-region
to the experimental BrowserView API. Major downside right now: This PR ensures that the draggable regions of the HTML content in the window are respected, it does not implement draggable regions for the content of the BrowserView.NSView Implementation Overview
Before
3️⃣ BrowserView (not draggable)
2️⃣ Multiple exclusion zones
1️⃣ Window's RenderView (contains a NSView that's draggable)
0️⃣ Window
After
5️⃣ Multiple exclusion zones
4️⃣ Draggable NSView
3️⃣ BrowserView (not draggable)
2️⃣ Multiple exclusion zones
1️⃣ Window's RenderView (contains a NSView that's draggable)
0️⃣ Window
This PR uses
performWindowDragWithEvent
where supported (10.11 and up) and good ol' window moving code on versions below. This PR also didn't have to do anything on Windows, where the window'swebkit-app-region
are already respected regardless of a BrowserView presence.Why the window's draggable regions?
Despite my best efforts, I was completely unable to get the
-webkit-app-region
-regions for the content of the actual BrowserView. In addition, the BrowserView usesinspectable_web_contents
instead ofweb_contents
, which has a minor difference in the preciseNSView
class that is being returned fromGetNativeView()
. Long story short: I was unable to make it work, but this alternative ensures that you can use the BrowserView and still build apps with a custom frame andwebkit-app-region
.Also: This mirrors the behavior on Windows, where the window's drag regions also take control over dragging in the BrowserView. Truly cross-platform 😉