Commit 330fc4a1 authored by Sidney San Martín's avatar Sidney San Martín Committed by Commit Bot

Make all MacViews windows potentially draggable.

This fixes the PiP window not being draggable on Mac.

Bug: 849983
Change-Id: I1b0f503de1a1f154f23afd1870943a6b7009be75
Reviewed-on: https://chromium-review.googlesource.com/1121145
Commit-Queue: Sidney San Martín <sdy@chromium.org>
Reviewed-by: default avatarAvi Drissman <avi@chromium.org>
Cr-Commit-Position: refs/heads/master@{#572038}
parent c3743d15
...@@ -15,19 +15,13 @@ ...@@ -15,19 +15,13 @@
@interface NSWindow (PrivateAPI) @interface NSWindow (PrivateAPI)
+ (Class)frameViewClassForStyleMask:(NSUInteger)windowStyle; + (Class)frameViewClassForStyleMask:(NSUInteger)windowStyle;
// Available in later point releases of 10.10. On 10.11+, use the public
// -performWindowDragWithEvent: instead.
- (void)beginWindowDragWithEvent:(NSEvent*)event;
@end @end
// Weak lets Chrome launch even if a future macOS doesn't have NSThemeFrame. @interface NSThemeFrame (PrivateAPI)
WEAK_IMPORT_ATTRIBUTE
@interface NSThemeFrame : NSView
- (CGFloat)_titlebarHeight; - (CGFloat)_titlebarHeight;
@end @end
@interface BrowserWindowFrame : NSThemeFrame @interface BrowserWindowFrame : NativeWidgetMacNSWindowTitledFrame
@end @end
@implementation BrowserWindowFrame @implementation BrowserWindowFrame
...@@ -78,20 +72,6 @@ WEAK_IMPORT_ATTRIBUTE ...@@ -78,20 +72,6 @@ WEAK_IMPORT_ATTRIBUTE
return NSZeroRect; return NSZeroRect;
} }
// Lets the window be dragged by its title bar on 10.11 and older.
- (void)mouseDown:(NSEvent*)event {
if (@available(macOS 10.12, *))
; // Not needed on 10.12 and up.
else if (@available(macOS 10.11, *))
[self.window performWindowDragWithEvent:event];
else if ([self.window
respondsToSelector:@selector(beginWindowDragWithEvent:)])
[self.window beginWindowDragWithEvent:event];
else
NOTREACHED();
[super mouseDown:event];
}
@end @end
@implementation BrowserNativeWidgetWindow @implementation BrowserNativeWidgetWindow
...@@ -107,13 +87,6 @@ WEAK_IMPORT_ATTRIBUTE ...@@ -107,13 +87,6 @@ WEAK_IMPORT_ATTRIBUTE
return [super frameViewClassForStyleMask:windowStyle]; return [super frameViewClassForStyleMask:windowStyle];
} }
// The base implementation returns YES if the window's frame view is a custom
// class, which causes undesirable changes in behavior. AppKit NSWindow
// subclasses are known to override it and return NO.
- (BOOL)_usesCustomDrawing {
return NO;
}
// Handle "Move focus to the window toolbar" configured in System Preferences -> // Handle "Move focus to the window toolbar" configured in System Preferences ->
// Keyboard -> Shortcuts -> Keyboard. Usually Ctrl+F5. The argument (|unknown|) // Keyboard -> Shortcuts -> Keyboard. Usually Ctrl+F5. The argument (|unknown|)
// tends to just be nil. // tends to just be nil.
......
...@@ -6,31 +6,13 @@ ...@@ -6,31 +6,13 @@
@interface NSWindow (PrivateAPI) @interface NSWindow (PrivateAPI)
+ (Class)frameViewClassForStyleMask:(NSUInteger)windowStyle; + (Class)frameViewClassForStyleMask:(NSUInteger)windowStyle;
- (void)beginWindowDragWithEvent:(NSEvent*)event
NS_DEPRECATED_MAC(10_10, 10_11, "Use performWindowDragWithEvent: instead.");
@end @end
// Weak lets Chrome launch even if a future macOS doesn't have NSThemeFrame. @interface NativeWidgetMacFramelessNSWindowFrame
WEAK_IMPORT_ATTRIBUTE : NativeWidgetMacNSWindowTitledFrame
@interface NSThemeFrame : NSView
@end
@interface NativeWidgetMacFramelessNSWindowFrame : NSThemeFrame
@end @end
@implementation NativeWidgetMacFramelessNSWindowFrame @implementation NativeWidgetMacFramelessNSWindowFrame
// If a mouseDown: falls through to the frame view, turn it into a window drag.
- (void)mouseDown:(NSEvent*)event {
if (@available(macOS 10.11, *))
[self.window performWindowDragWithEvent:event];
else if (@available(macOS 10.10, *))
[self.window beginWindowDragWithEvent:event];
else
NOTREACHED();
[super mouseDown:event];
}
- (BOOL)_hidingTitlebar { - (BOOL)_hidingTitlebar {
return YES; return YES;
} }
...@@ -45,8 +27,4 @@ WEAK_IMPORT_ATTRIBUTE ...@@ -45,8 +27,4 @@ WEAK_IMPORT_ATTRIBUTE
return [super frameViewClassForStyleMask:windowStyle]; return [super frameViewClassForStyleMask:windowStyle];
} }
- (BOOL)_usesCustomDrawing {
return NO;
}
@end @end
...@@ -12,6 +12,24 @@ ...@@ -12,6 +12,24 @@
@protocol WindowTouchBarDelegate; @protocol WindowTouchBarDelegate;
// Weak lets Chrome launch even if a future macOS doesn't have the below classes
WEAK_IMPORT_ATTRIBUTE
@interface NSNextStepFrame : NSView
@end
WEAK_IMPORT_ATTRIBUTE
@interface NSThemeFrame : NSView
@end
VIEWS_EXPORT
@interface NativeWidgetMacNSWindowBorderlessFrame : NSNextStepFrame
@end
VIEWS_EXPORT
@interface NativeWidgetMacNSWindowTitledFrame : NSThemeFrame
@end
// The NSWindow used by BridgedNativeWidget. Provides hooks into AppKit that // The NSWindow used by BridgedNativeWidget. Provides hooks into AppKit that
// can only be accomplished by overriding methods. // can only be accomplished by overriding methods.
VIEWS_EXPORT VIEWS_EXPORT
......
...@@ -15,7 +15,12 @@ ...@@ -15,7 +15,12 @@
#include "ui/views/widget/widget_delegate.h" #include "ui/views/widget/widget_delegate.h"
@interface NSWindow (Private) @interface NSWindow (Private)
+ (Class)frameViewClassForStyleMask:(NSWindowStyleMask)windowStyle;
- (BOOL)hasKeyAppearance; - (BOOL)hasKeyAppearance;
// Available in later point releases of 10.10. On 10.11+, use the public
// -performWindowDragWithEvent: instead.
- (void)beginWindowDragWithEvent:(NSEvent*)event;
@end @end
@interface NativeWidgetMacNSWindow () @interface NativeWidgetMacNSWindow ()
...@@ -29,6 +34,38 @@ ...@@ -29,6 +34,38 @@
- (BOOL)_isTitleHidden; - (BOOL)_isTitleHidden;
@end @end
// Use this category to implement mouseDown: on multiple frame view classes
// with different superclasses.
@interface NSView (CRFrameViewAdditions)
- (void)cr_mouseDownOnFrameView:(NSEvent*)event;
@end
@implementation NSView (CRFrameViewAdditions)
// If a mouseDown: falls through to the frame view, turn it into a window drag.
- (void)cr_mouseDownOnFrameView:(NSEvent*)event {
if (@available(macOS 10.11, *))
return [self.window performWindowDragWithEvent:event];
else if ([self.window
respondsToSelector:@selector(beginWindowDragWithEvent:)])
return [self.window beginWindowDragWithEvent:event];
else
NOTREACHED();
[super mouseDown:event];
}
@end
@implementation NativeWidgetMacNSWindowTitledFrame
- (void)mouseDown:(NSEvent*)event {
[self cr_mouseDownOnFrameView:event];
}
@end
@implementation NativeWidgetMacNSWindowBorderlessFrame
- (void)mouseDown:(NSEvent*)event {
[self cr_mouseDownOnFrameView:event];
}
@end
@implementation NativeWidgetMacNSWindow { @implementation NativeWidgetMacNSWindow {
@private @private
base::scoped_nsobject<CommandDispatcher> commandDispatcher_; base::scoped_nsobject<CommandDispatcher> commandDispatcher_;
...@@ -99,6 +136,17 @@ ...@@ -99,6 +136,17 @@
// NSWindow overrides. // NSWindow overrides.
+ (Class)frameViewClassForStyleMask:(NSWindowStyleMask)windowStyle {
if (windowStyle & NSWindowStyleMaskTitled) {
if (Class customFrame = [NativeWidgetMacNSWindowTitledFrame class])
return customFrame;
} else if (Class customFrame =
[NativeWidgetMacNSWindowBorderlessFrame class]) {
return customFrame;
}
return [super frameViewClassForStyleMask:windowStyle];
}
- (BOOL)_isTitleHidden { - (BOOL)_isTitleHidden {
if (![self delegate]) if (![self delegate])
return NO; return NO;
...@@ -106,6 +154,13 @@ ...@@ -106,6 +154,13 @@
return ![self viewsWidget]->widget_delegate()->ShouldShowWindowTitle(); return ![self viewsWidget]->widget_delegate()->ShouldShowWindowTitle();
} }
// The base implementation returns YES if the window's frame view is a custom
// class, which causes undesirable changes in behavior. AppKit NSWindow
// subclasses are known to override it and return NO.
- (BOOL)_usesCustomDrawing {
return NO;
}
// Ignore [super canBecome{Key,Main}Window]. The default is NO for windows with // Ignore [super canBecome{Key,Main}Window]. The default is NO for windows with
// NSBorderlessWindowMask, which is not the desired behavior. // NSBorderlessWindowMask, which is not the desired behavior.
// Note these can be called via -[NSWindow close] while the widget is being torn // Note these can be called via -[NSWindow close] while the widget is being torn
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment