Commit cd7085a7 authored by jeremya@chromium.org's avatar jeremya@chromium.org

[mac] Implement {frame: 'none'} app window on Mac.

Support for draggable regions hasn't landed yet, so we hard-code 20px of
draggable space at the top of the window.

BUG=130182
R=rsesek@chromium.org


Review URL: https://chromiumcodereview.appspot.com/10824004

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@150062 0039d316-1c4b-4281-b951-d872f2087c98
parent 6a17682d
...@@ -73,6 +73,11 @@ class ShellWindowCocoa : public ShellWindow { ...@@ -73,6 +73,11 @@ class ShellWindowCocoa : public ShellWindow {
NSWindow* window() const; NSWindow* window() const;
void InstallView();
void UninstallView();
bool has_frame_;
bool is_fullscreen_; bool is_fullscreen_;
NSRect restored_bounds_; NSRect restored_bounds_;
......
...@@ -82,11 +82,27 @@ ...@@ -82,11 +82,27 @@
@end @end
@interface ControlRegionView : NSView
@end
@implementation ControlRegionView
- (BOOL)mouseDownCanMoveWindow {
return NO;
}
- (NSView*)hitTest:(NSPoint)aPoint {
return nil;
}
@end
@interface NSView (WebContentsView)
- (void)setMouseDownCanMoveWindow:(BOOL)can_move;
@end
ShellWindowCocoa::ShellWindowCocoa(Profile* profile, ShellWindowCocoa::ShellWindowCocoa(Profile* profile,
const extensions::Extension* extension, const extensions::Extension* extension,
const GURL& url, const GURL& url,
const ShellWindow::CreateParams& params) const ShellWindow::CreateParams& params)
: ShellWindow(profile, extension, url), : ShellWindow(profile, extension, url),
has_frame_(params.frame == ShellWindow::CreateParams::FRAME_CHROME),
attention_request_id_(0) { attention_request_id_(0) {
// Flip coordinates based on the primary screen. // Flip coordinates based on the primary screen.
NSRect main_screen_rect = [[[NSScreen screens] objectAtIndex:0] frame]; NSRect main_screen_rect = [[[NSScreen screens] objectAtIndex:0] frame];
...@@ -117,17 +133,57 @@ ShellWindowCocoa::ShellWindowCocoa(Profile* profile, ...@@ -117,17 +133,57 @@ ShellWindowCocoa::ShellWindowCocoa(Profile* profile,
[window respondsToSelector:@selector(setBottomCornerRounded:)]) [window respondsToSelector:@selector(setBottomCornerRounded:)])
[window setBottomCornerRounded:NO]; [window setBottomCornerRounded:NO];
window_controller_.reset(
[[ShellWindowController alloc] initWithWindow:window.release()]);
NSView* view = web_contents()->GetView()->GetNativeView(); NSView* view = web_contents()->GetView()->GetNativeView();
[view setFrame:[[window contentView] bounds]];
[view setAutoresizingMask:NSViewWidthSizable | NSViewHeightSizable]; [view setAutoresizingMask:NSViewWidthSizable | NSViewHeightSizable];
[[window contentView] addSubview:view];
window_controller_.reset( if (!has_frame_) {
[[ShellWindowController alloc] initWithWindow:window.release()]); // TODO(jeremya): this is a temporary hack to allow moving the window while
// we still don't have proper draggable region support.
NSView* controlRegion = [[ControlRegionView alloc] init];
[controlRegion setFrame:NSMakeRect(0, 0, NSWidth([view bounds]),
NSHeight([view bounds]) - 20)];
[controlRegion setAutoresizingMask:
NSViewWidthSizable | NSViewHeightSizable];
[view addSubview:controlRegion];
[controlRegion release];
}
InstallView();
[[window_controller_ window] setDelegate:window_controller_]; [[window_controller_ window] setDelegate:window_controller_];
[window_controller_ setShellWindow:this]; [window_controller_ setShellWindow:this];
} }
void ShellWindowCocoa::InstallView() {
NSView* view = web_contents()->GetView()->GetNativeView();
if (has_frame_) {
[view setFrame:[[window() contentView] bounds]];
[[window() contentView] addSubview:view];
} else {
// TODO(jeremya): find a cleaner way to send this information to the
// WebContentsViewCocoa view.
DCHECK([view
respondsToSelector:@selector(setMouseDownCanMoveWindow:)]);
[view setMouseDownCanMoveWindow:YES];
NSView* frameView = [[window() contentView] superview];
[view setFrame:[frameView bounds]];
[frameView addSubview:view];
[[window() standardWindowButton:NSWindowZoomButton] setHidden:YES];
[[window() standardWindowButton:NSWindowMiniaturizeButton] setHidden:YES];
[[window() standardWindowButton:NSWindowCloseButton] setHidden:YES];
}
}
void ShellWindowCocoa::UninstallView() {
NSView* view = web_contents()->GetView()->GetNativeView();
[view removeFromSuperview];
}
bool ShellWindowCocoa::IsActive() const { bool ShellWindowCocoa::IsActive() const {
return [window() isKeyWindow]; return [window() isKeyWindow];
} }
...@@ -167,6 +223,12 @@ void ShellWindowCocoa::SetFullscreen(bool fullscreen) { ...@@ -167,6 +223,12 @@ void ShellWindowCocoa::SetFullscreen(bool fullscreen) {
kCGDisplayBlendSolidColor, 0.0, 0.0, 0.0, /*synchronous=*/true); kCGDisplayBlendSolidColor, 0.0, 0.0, 0.0, /*synchronous=*/true);
} }
// Since frameless windows insert the WebContentsView into the NSThemeFrame
// ([[window contentView] superview]), and since that NSThemeFrame is
// destroyed and recreated when we change the styleMask of the window, we
// need to remove the view from the window when we change the style, and
// add it back afterwards.
UninstallView();
if (fullscreen) { if (fullscreen) {
restored_bounds_ = [window() frame]; restored_bounds_ = [window() frame];
[window() setStyleMask:NSBorderlessWindowMask]; [window() setStyleMask:NSBorderlessWindowMask];
...@@ -176,10 +238,13 @@ void ShellWindowCocoa::SetFullscreen(bool fullscreen) { ...@@ -176,10 +238,13 @@ void ShellWindowCocoa::SetFullscreen(bool fullscreen) {
base::mac::RequestFullScreen(base::mac::kFullScreenModeAutoHideAll); base::mac::RequestFullScreen(base::mac::kFullScreenModeAutoHideAll);
} else { } else {
base::mac::ReleaseFullScreen(base::mac::kFullScreenModeAutoHideAll); base::mac::ReleaseFullScreen(base::mac::kFullScreenModeAutoHideAll);
[window() setStyleMask:NSTitledWindowMask | NSClosableWindowMask | NSUInteger style_mask = NSTitledWindowMask | NSClosableWindowMask |
NSMiniaturizableWindowMask | NSResizableWindowMask]; NSMiniaturizableWindowMask | NSResizableWindowMask |
NSTexturedBackgroundWindowMask;
[window() setStyleMask:style_mask];
[window() setFrame:restored_bounds_ display:YES]; [window() setFrame:restored_bounds_ display:YES];
} }
InstallView();
// Fade back in. // Fade back in.
if (did_fade_out) { if (did_fade_out) {
......
...@@ -37,8 +37,11 @@ class Point; ...@@ -37,8 +37,11 @@ class Point;
WebContentsViewMac* webContentsView_; // WEAK; owns us WebContentsViewMac* webContentsView_; // WEAK; owns us
scoped_nsobject<WebDragSource> dragSource_; scoped_nsobject<WebDragSource> dragSource_;
scoped_nsobject<WebDragDest> dragDest_; scoped_nsobject<WebDragDest> dragDest_;
BOOL mouseDownCanMoveWindow_;
} }
- (void)setMouseDownCanMoveWindow:(BOOL)canMove;
// Expose this, since sometimes one needs both the NSView and the // Expose this, since sometimes one needs both the NSView and the
// WebContentsImpl. // WebContentsImpl.
- (WebContentsImpl*)webContents; - (WebContentsImpl*)webContents;
......
...@@ -412,6 +412,10 @@ void WebContentsViewMac::CloseTab() { ...@@ -412,6 +412,10 @@ void WebContentsViewMac::CloseTab() {
} }
} }
- (void)setMouseDownCanMoveWindow:(BOOL)canMove {
mouseDownCanMoveWindow_ = canMove;
}
- (BOOL)mouseDownCanMoveWindow { - (BOOL)mouseDownCanMoveWindow {
// This is needed to prevent mouseDowns from moving the window // This is needed to prevent mouseDowns from moving the window
// around. The default implementation returns YES only for opaque // around. The default implementation returns YES only for opaque
...@@ -419,7 +423,7 @@ void WebContentsViewMac::CloseTab() { ...@@ -419,7 +423,7 @@ void WebContentsViewMac::CloseTab() {
// its subviews do paint their entire frames. Returning NO here // its subviews do paint their entire frames. Returning NO here
// saves us the effort of overriding this method in every possible // saves us the effort of overriding this method in every possible
// subview. // subview.
return NO; return mouseDownCanMoveWindow_;
} }
- (void)pasteboard:(NSPasteboard*)sender provideDataForType:(NSString*)type { - (void)pasteboard:(NSPasteboard*)sender provideDataForType:(NSString*)type {
......
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