From dec9a1d9dbefea1b1b5c5c5d03c2cf34a85cf1de Mon Sep 17 00:00:00 2001 From: Cheng Zhao Date: Wed, 24 May 2023 17:03:07 +0900 Subject: [PATCH] chore: remove dead draggable region code (#38404) --- shell/browser/ui/drag_util.cc | 18 -- shell/browser/ui/drag_util.h | 6 - .../ui/inspectable_web_contents_view_mac.mm | 207 ------------------ 3 files changed, 231 deletions(-) diff --git a/shell/browser/ui/drag_util.cc b/shell/browser/ui/drag_util.cc index 603d05b14642..9d5beef7658f 100644 --- a/shell/browser/ui/drag_util.cc +++ b/shell/browser/ui/drag_util.cc @@ -4,28 +4,10 @@ #include "shell/browser/ui/drag_util.h" -#include - #include "ui/gfx/geometry/skia_conversions.h" namespace electron { -// Return a vector of non-draggable regions that fill a window of size -// |width| by |height|, but leave gaps where the window should be draggable. -std::vector CalculateNonDraggableRegions( - std::unique_ptr draggable, - int width, - int height) { - std::vector result; - SkRegion non_draggable; - non_draggable.op({0, 0, width, height}, SkRegion::kUnion_Op); - non_draggable.op(*draggable, SkRegion::kDifference_Op); - for (SkRegion::Iterator it(non_draggable); !it.done(); it.next()) { - result.push_back(gfx::SkIRectToRect(it.rect())); - } - return result; -} - // Convert draggable regions in raw format to SkRegion format. std::unique_ptr DraggableRegionsToSkRegion( const std::vector& regions) { diff --git a/shell/browser/ui/drag_util.h b/shell/browser/ui/drag_util.h index 6de7808822cf..b3e18a505c4e 100644 --- a/shell/browser/ui/drag_util.h +++ b/shell/browser/ui/drag_util.h @@ -10,7 +10,6 @@ #include "shell/common/api/api.mojom.h" #include "third_party/skia/include/core/SkRegion.h" -#include "ui/gfx/geometry/rect.h" #include "ui/gfx/image/image.h" namespace base { @@ -23,11 +22,6 @@ void DragFileItems(const std::vector& files, const gfx::Image& icon, gfx::NativeView view); -std::vector CalculateNonDraggableRegions( - std::unique_ptr draggable, - int width, - int height); - // Convert draggable regions in raw format to SkRegion format. std::unique_ptr DraggableRegionsToSkRegion( const std::vector& regions); diff --git a/shell/browser/ui/inspectable_web_contents_view_mac.mm b/shell/browser/ui/inspectable_web_contents_view_mac.mm index 10440e0e21c6..b93267eb345c 100644 --- a/shell/browser/ui/inspectable_web_contents_view_mac.mm +++ b/shell/browser/ui/inspectable_web_contents_view_mac.mm @@ -5,217 +5,10 @@ #include "shell/browser/ui/inspectable_web_contents_view_mac.h" -#import -#import - -#include - #include "base/strings/sys_string_conversions.h" #import "shell/browser/ui/cocoa/electron_inspectable_web_contents_view.h" -#include "shell/browser/ui/drag_util.h" #include "shell/browser/ui/inspectable_web_contents.h" #include "shell/browser/ui/inspectable_web_contents_view_delegate.h" -#include "ui/gfx/geometry/rect.h" - -@interface DragRegionView : NSView - -@property(assign) NSPoint initialLocation; - -@end - -@interface NSWindow () -- (void)performWindowDragWithEvent:(NSEvent*)event; -@end - -@implementation DragRegionView - -@synthesize initialLocation; - -+ (void)load { - if (getenv("ELECTRON_DEBUG_DRAG_REGIONS")) { - static dispatch_once_t onceToken; - dispatch_once(&onceToken, ^{ - SEL originalSelector = @selector(drawRect:); - SEL swizzledSelector = @selector(drawDebugRect:); - - Method originalMethod = - class_getInstanceMethod([self class], originalSelector); - Method swizzledMethod = - class_getInstanceMethod([self class], swizzledSelector); - BOOL didAddMethod = - class_addMethod([self class], originalSelector, - method_getImplementation(swizzledMethod), - method_getTypeEncoding(swizzledMethod)); - - if (didAddMethod) { - class_replaceMethod([self class], swizzledSelector, - method_getImplementation(originalMethod), - method_getTypeEncoding(originalMethod)); - } else { - method_exchangeImplementations(originalMethod, swizzledMethod); - } - }); - } -} - -- (BOOL)mouseDownCanMoveWindow { - return - [self.window respondsToSelector:@selector(performWindowDragWithEvent:)]; -} - -- (BOOL)acceptsFirstMouse:(NSEvent*)event { - return YES; -} - -- (BOOL)shouldIgnoreMouseEvent { - NSEventType type = [[NSApp currentEvent] type]; - return type != NSEventTypeLeftMouseDragged && - type != NSEventTypeLeftMouseDown; -} - -- (NSView*)hitTest:(NSPoint)point { - // Pass-through events that hit one of the exclusion zones - for (NSView* exclusion_zones in [self subviews]) { - if ([exclusion_zones hitTest:point]) - return nil; - } - - return self; -} - -- (void)mouseDown:(NSEvent*)event { - [super mouseDown:event]; - - if ([self.window respondsToSelector:@selector(performWindowDragWithEvent:)]) { - // According to Google, using performWindowDragWithEvent: - // does not generate a NSWindowWillMoveNotification. Hence post one. - [[NSNotificationCenter defaultCenter] - postNotificationName:NSWindowWillMoveNotification - object:self]; - - [self.window performWindowDragWithEvent:event]; - - return; - } - - if (self.window.styleMask & NSWindowStyleMaskFullScreen) { - return; - } - - self.initialLocation = [event locationInWindow]; -} - -- (void)mouseDragged:(NSEvent*)event { - if ([self.window respondsToSelector:@selector(performWindowDragWithEvent:)]) { - return; - } - - if (self.window.styleMask & NSWindowStyleMaskFullScreen) { - return; - } - - NSPoint currentLocation = [NSEvent mouseLocation]; - NSPoint newOrigin; - - NSRect screenFrame = [[NSScreen mainScreen] frame]; - NSSize screenSize = screenFrame.size; - NSRect windowFrame = [self.window frame]; - NSSize windowSize = windowFrame.size; - - newOrigin.x = currentLocation.x - self.initialLocation.x; - newOrigin.y = currentLocation.y - self.initialLocation.y; - - BOOL inMenuBar = (newOrigin.y + windowSize.height) > - (screenFrame.origin.y + screenSize.height); - BOOL screenAboveMainScreen = false; - - if (inMenuBar) { - for (NSScreen* screen in [NSScreen screens]) { - NSRect currentScreenFrame = [screen frame]; - BOOL isHigher = currentScreenFrame.origin.y > screenFrame.origin.y; - - // If there's another screen that is generally above the current screen, - // we'll draw a new rectangle that is just above the current screen. If - // the "higher" screen intersects with this rectangle, we'll allow drawing - // above the menubar. - if (isHigher) { - NSRect aboveScreenRect = - NSMakeRect(screenFrame.origin.x, - screenFrame.origin.y + screenFrame.size.height - 10, - screenFrame.size.width, 200); - - BOOL screenAboveIntersects = - NSIntersectsRect(currentScreenFrame, aboveScreenRect); - - if (screenAboveIntersects) { - screenAboveMainScreen = true; - break; - } - } - } - } - - // Don't let window get dragged up under the menu bar - if (inMenuBar && !screenAboveMainScreen) { - newOrigin.y = screenFrame.origin.y + - (screenFrame.size.height - windowFrame.size.height); - } - - // Move the window to the new location - [self.window setFrameOrigin:newOrigin]; -} - -// For debugging purposes only. -- (void)drawDebugRect:(NSRect)aRect { - [[[NSColor greenColor] colorWithAlphaComponent:0.5] set]; - NSRectFill([self bounds]); -} - -@end - -@interface ExcludeDragRegionView : NSView -@end - -@implementation ExcludeDragRegionView - -+ (void)load { - if (getenv("ELECTRON_DEBUG_DRAG_REGIONS")) { - static dispatch_once_t onceToken; - dispatch_once(&onceToken, ^{ - SEL originalSelector = @selector(drawRect:); - SEL swizzledSelector = @selector(drawDebugRect:); - - Method originalMethod = - class_getInstanceMethod([self class], originalSelector); - Method swizzledMethod = - class_getInstanceMethod([self class], swizzledSelector); - BOOL didAddMethod = - class_addMethod([self class], originalSelector, - method_getImplementation(swizzledMethod), - method_getTypeEncoding(swizzledMethod)); - - if (didAddMethod) { - class_replaceMethod([self class], swizzledSelector, - method_getImplementation(originalMethod), - method_getTypeEncoding(originalMethod)); - } else { - method_exchangeImplementations(originalMethod, swizzledMethod); - } - }); - } -} - -- (BOOL)mouseDownCanMoveWindow { - return NO; -} - -// For debugging purposes only. -- (void)drawDebugRect:(NSRect)aRect { - [[[NSColor redColor] colorWithAlphaComponent:0.5] set]; - NSRectFill([self bounds]); -} - -@end namespace electron {