chore: remove dead draggable region code (#38404)
This commit is contained in:
parent
b6c80ba646
commit
dec9a1d9db
3 changed files with 0 additions and 231 deletions
|
@ -4,28 +4,10 @@
|
|||
|
||||
#include "shell/browser/ui/drag_util.h"
|
||||
|
||||
#include <memory>
|
||||
|
||||
#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<gfx::Rect> CalculateNonDraggableRegions(
|
||||
std::unique_ptr<SkRegion> draggable,
|
||||
int width,
|
||||
int height) {
|
||||
std::vector<gfx::Rect> 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<SkRegion> DraggableRegionsToSkRegion(
|
||||
const std::vector<mojom::DraggableRegionPtr>& regions) {
|
||||
|
|
|
@ -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<base::FilePath>& files,
|
|||
const gfx::Image& icon,
|
||||
gfx::NativeView view);
|
||||
|
||||
std::vector<gfx::Rect> CalculateNonDraggableRegions(
|
||||
std::unique_ptr<SkRegion> draggable,
|
||||
int width,
|
||||
int height);
|
||||
|
||||
// Convert draggable regions in raw format to SkRegion format.
|
||||
std::unique_ptr<SkRegion> DraggableRegionsToSkRegion(
|
||||
const std::vector<mojom::DraggableRegionPtr>& regions);
|
||||
|
|
|
@ -5,217 +5,10 @@
|
|||
|
||||
#include "shell/browser/ui/inspectable_web_contents_view_mac.h"
|
||||
|
||||
#import <AppKit/AppKit.h>
|
||||
#import <objc/runtime.h>
|
||||
|
||||
#include <vector>
|
||||
|
||||
#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 {
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue