fix: BrowserView rendering flicker (#27585)
This commit is contained in:
parent
f69c11105f
commit
fa09183ed1
2 changed files with 62 additions and 11 deletions
|
@ -135,7 +135,7 @@
|
||||||
],
|
],
|
||||||
"docs/api/**/*.md": [
|
"docs/api/**/*.md": [
|
||||||
"ts-node script/gen-filenames.ts",
|
"ts-node script/gen-filenames.ts",
|
||||||
"markdownlint --config .markdownlint.auotfix.json --fix",
|
"markdownlint --config .markdownlint.autofix.json --fix",
|
||||||
"git add filenames.auto.gni"
|
"git add filenames.auto.gni"
|
||||||
],
|
],
|
||||||
"{*.patch,.patches}": [
|
"{*.patch,.patches}": [
|
||||||
|
|
|
@ -4,6 +4,7 @@
|
||||||
|
|
||||||
#include "shell/browser/native_browser_view_mac.h"
|
#include "shell/browser/native_browser_view_mac.h"
|
||||||
|
|
||||||
|
#import <objc/runtime.h>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
#include "shell/browser/ui/drag_util.h"
|
#include "shell/browser/ui/drag_util.h"
|
||||||
|
@ -30,6 +31,33 @@ const NSAutoresizingMaskOptions kDefaultAutoResizingMask =
|
||||||
|
|
||||||
@synthesize initialLocation;
|
@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 {
|
- (BOOL)mouseDownCanMoveWindow {
|
||||||
return NO;
|
return NO;
|
||||||
}
|
}
|
||||||
|
@ -134,11 +162,9 @@ const NSAutoresizingMaskOptions kDefaultAutoResizingMask =
|
||||||
}
|
}
|
||||||
|
|
||||||
// For debugging purposes only.
|
// For debugging purposes only.
|
||||||
- (void)drawRect:(NSRect)aRect {
|
- (void)drawDebugRect:(NSRect)aRect {
|
||||||
if (getenv("ELECTRON_DEBUG_DRAG_REGIONS")) {
|
[[[NSColor greenColor] colorWithAlphaComponent:0.5] set];
|
||||||
[[[NSColor greenColor] colorWithAlphaComponent:0.5] set];
|
NSRectFill([self bounds]);
|
||||||
NSRectFill([self bounds]);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@end
|
@end
|
||||||
|
@ -148,16 +174,41 @@ const NSAutoresizingMaskOptions kDefaultAutoResizingMask =
|
||||||
|
|
||||||
@implementation ExcludeDragRegionView
|
@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 {
|
- (BOOL)mouseDownCanMoveWindow {
|
||||||
return NO;
|
return NO;
|
||||||
}
|
}
|
||||||
|
|
||||||
// For debugging purposes only.
|
// For debugging purposes only.
|
||||||
- (void)drawRect:(NSRect)aRect {
|
- (void)drawDebugRect:(NSRect)aRect {
|
||||||
if (getenv("ELECTRON_DEBUG_DRAG_REGIONS")) {
|
[[[NSColor redColor] colorWithAlphaComponent:0.5] set];
|
||||||
[[[NSColor redColor] colorWithAlphaComponent:0.5] set];
|
NSRectFill([self bounds]);
|
||||||
NSRectFill([self bounds]);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@end
|
@end
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue