refactor: use views NonClientHitTest for draggable regions on mac (#35603)

* refactor: use views NonClientHitTest for draggable regions on mac

* iwyu

* add backport of 9bb5f0316

* chore: update patches

* remove some unneeded functions

* remove test for triggering when BW is focused

* chore: update patches

* simplify views/mac split now that the draggable logic is the same

* Apply suggestions from code review

Co-authored-by: Charles Kerr <charles@charleskerr.com>

* Update shell/browser/native_window.h

Co-authored-by: Charles Kerr <charles@charleskerr.com>

* fix build

Co-authored-by: PatchUp <73610968+patchup[bot]@users.noreply.github.com>
Co-authored-by: Charles Kerr <charles@charleskerr.com>
This commit is contained in:
Jeremy Rose 2022-10-12 09:05:45 -07:00 committed by GitHub
parent 7ce94eb0b4
commit 8a926ffde4
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
15 changed files with 70 additions and 392 deletions

View file

@ -21,16 +21,12 @@ using electron::InspectableWebContentsViewMac;
- (void)setMouseDownCanMoveWindow:(BOOL)can_move;
@end
@interface ControlRegionView : NSView
@end
@interface ElectronInspectableWebContentsView : BaseView <NSWindowDelegate> {
@private
electron::InspectableWebContentsViewMac* inspectableWebContentsView_;
base::scoped_nsobject<NSView> fake_view_;
base::scoped_nsobject<NSWindow> devtools_window_;
base::scoped_nsobject<ControlRegionView> devtools_mask_;
BOOL devtools_visible_;
BOOL devtools_docked_;
BOOL devtools_is_first_responder_;

View file

@ -11,18 +11,6 @@
#include "shell/browser/ui/inspectable_web_contents_view_mac.h"
#include "ui/gfx/mac/scoped_cocoa_disable_screen_updates.h"
@implementation ControlRegionView
- (BOOL)mouseDownCanMoveWindow {
return NO;
}
- (NSView*)hitTest:(NSPoint)aPoint {
return nil;
}
@end
@implementation ElectronInspectableWebContentsView
- (instancetype)initWithInspectableWebContentsViewMac:
@ -49,9 +37,6 @@
[self addSubview:contentsView];
}
// This will float above devtools to exclude it from dragging.
devtools_mask_.reset([[ControlRegionView alloc] initWithFrame:NSZeroRect]);
// See https://code.google.com/p/chromium/issues/detail?id=348490.
[self setWantsLayer:YES];
@ -116,12 +101,6 @@
devtools_visible_ = visible;
if (devtools_docked_) {
if (visible) {
// The devToolsView is placed under the contentsView, so it has to be
// draggable to make draggable region of contentsView work.
[devToolsView setMouseDownCanMoveWindow:YES];
// This view will exclude the actual devtools part from dragging.
[self addSubview:devtools_mask_.get()];
// Place the devToolsView under contentsView, notice that we didn't set
// sizes for them until the setContentsResizingStrategy message.
[self addSubview:devToolsView positioned:NSWindowBelow relativeTo:nil];
@ -132,7 +111,6 @@
} else {
gfx::ScopedCocoaDisableScreenUpdates disabler;
[devToolsView removeFromSuperview];
[devtools_mask_ removeFromSuperview];
[self adjustSubviews];
[self notifyDevToolsResized];
}
@ -225,7 +203,7 @@
NSView* devToolsView = [[self subviews] objectAtIndex:0];
NSView* contentsView = [[self subviews] objectAtIndex:1];
DCHECK_EQ(3u, [[self subviews] count]);
DCHECK_EQ(2u, [[self subviews] count]);
gfx::Rect new_devtools_bounds;
gfx::Rect new_contents_bounds;
@ -253,7 +231,6 @@
devtools_frame.size.width = sb.size.width - cf.size.width;
devtools_frame.size.height = sb.size.height;
}
[devtools_mask_ setFrame:devtools_frame];
[self notifyDevToolsResized];
}

View file

@ -95,7 +95,7 @@ int FramelessView::NonClientHitTest(const gfx::Point& cursor) {
// Check for possible draggable region in the client area for the frameless
// window.
SkRegion* draggable_region = window_->draggable_region();
const SkRegion* draggable_region = window_->draggable_region();
if (draggable_region && draggable_region->contains(cursor.x(), cursor.y()))
return HTCAPTION;