2014-10-31 18:17:05 +00:00
|
|
|
// Copyright (c) 2013 GitHub, Inc.
|
2014-04-25 09:49:37 +00:00
|
|
|
// Use of this source code is governed by the MIT license that can be
|
2013-04-12 07:04:46 +00:00
|
|
|
// found in the LICENSE file.
|
|
|
|
|
2014-03-16 00:30:26 +00:00
|
|
|
#include "atom/browser/native_window_mac.h"
|
2013-04-12 07:04:46 +00:00
|
|
|
|
2013-04-15 16:25:08 +00:00
|
|
|
#include <string>
|
|
|
|
|
2016-04-02 11:35:57 +00:00
|
|
|
#include "atom/common/color_util.h"
|
2014-03-16 00:30:26 +00:00
|
|
|
#include "atom/common/draggable_region.h"
|
|
|
|
#include "atom/common/options_switches.h"
|
2014-05-15 07:19:02 +00:00
|
|
|
#include "base/mac/mac_util.h"
|
2016-04-03 02:59:21 +00:00
|
|
|
#include "base/mac/scoped_cftyperef.h"
|
2014-05-15 07:19:02 +00:00
|
|
|
#include "base/strings/sys_string_conversions.h"
|
2015-05-04 04:06:03 +00:00
|
|
|
#include "brightray/browser/inspectable_web_contents.h"
|
|
|
|
#include "brightray/browser/inspectable_web_contents_view.h"
|
2015-04-13 12:10:51 +00:00
|
|
|
#include "content/public/browser/browser_accessibility_state.h"
|
2013-04-12 07:04:46 +00:00
|
|
|
#include "content/public/browser/web_contents.h"
|
2013-05-24 09:51:15 +00:00
|
|
|
#include "content/public/browser/render_view_host.h"
|
2014-07-24 05:53:29 +00:00
|
|
|
#include "content/public/browser/render_widget_host_view.h"
|
2014-06-23 13:51:42 +00:00
|
|
|
#include "native_mate/dictionary.h"
|
2016-04-02 12:17:38 +00:00
|
|
|
#include "skia/ext/skia_utils_mac.h"
|
2015-10-20 23:33:43 +00:00
|
|
|
#include "ui/gfx/skia_util.h"
|
2013-04-12 07:04:46 +00:00
|
|
|
|
2015-08-05 06:12:55 +00:00
|
|
|
namespace {
|
|
|
|
|
|
|
|
// Prevents window from resizing during the scope.
|
|
|
|
class ScopedDisableResize {
|
|
|
|
public:
|
|
|
|
ScopedDisableResize() { disable_resize_ = true; }
|
|
|
|
~ScopedDisableResize() { disable_resize_ = false; }
|
|
|
|
|
|
|
|
static bool IsResizeDisabled() { return disable_resize_; }
|
|
|
|
|
|
|
|
private:
|
|
|
|
static bool disable_resize_;
|
|
|
|
};
|
|
|
|
|
|
|
|
bool ScopedDisableResize::disable_resize_ = false;
|
|
|
|
|
|
|
|
} // namespace
|
2013-09-05 15:52:29 +00:00
|
|
|
|
2014-12-11 22:25:51 +00:00
|
|
|
// This view always takes the size of its superview. It is intended to be used
|
|
|
|
// as a NSWindow's contentView. It is needed because NSWindow's implementation
|
|
|
|
// explicitly resizes the contentView at inopportune times.
|
|
|
|
@interface FullSizeContentView : NSView
|
|
|
|
@end
|
|
|
|
|
|
|
|
@implementation FullSizeContentView
|
|
|
|
|
|
|
|
// This method is directly called by NSWindow during a window resize on OSX
|
|
|
|
// 10.10.0, beta 2. We must override it to prevent the content view from
|
|
|
|
// shrinking.
|
|
|
|
- (void)setFrameSize:(NSSize)size {
|
|
|
|
if ([self superview])
|
|
|
|
size = [[self superview] bounds].size;
|
|
|
|
[super setFrameSize:size];
|
|
|
|
}
|
|
|
|
|
|
|
|
// The contentView gets moved around during certain full-screen operations.
|
|
|
|
// This is less than ideal, and should eventually be removed.
|
|
|
|
- (void)viewDidMoveToSuperview {
|
|
|
|
[self setFrame:[[self superview] bounds]];
|
|
|
|
}
|
|
|
|
|
|
|
|
@end
|
|
|
|
|
2013-05-01 07:42:30 +00:00
|
|
|
@interface AtomNSWindowDelegate : NSObject<NSWindowDelegate> {
|
|
|
|
@private
|
|
|
|
atom::NativeWindowMac* shell_;
|
|
|
|
}
|
|
|
|
- (id)initWithShell:(atom::NativeWindowMac*)shell;
|
|
|
|
@end
|
|
|
|
|
|
|
|
@implementation AtomNSWindowDelegate
|
|
|
|
|
|
|
|
- (id)initWithShell:(atom::NativeWindowMac*)shell {
|
2014-03-15 11:28:23 +00:00
|
|
|
if ((self = [super init])) {
|
2013-05-01 07:42:30 +00:00
|
|
|
shell_ = shell;
|
2014-03-15 11:28:23 +00:00
|
|
|
}
|
2013-05-01 07:42:30 +00:00
|
|
|
return self;
|
|
|
|
}
|
|
|
|
|
2016-03-08 19:11:17 +00:00
|
|
|
- (void)windowDidChangeOcclusionState:(NSNotification *)notification {
|
|
|
|
// notification.object is the window that changed its state.
|
|
|
|
// It's safe to use self.window instead if you don't assign one delegate to many windows
|
|
|
|
NSWindow *window = notification.object;
|
|
|
|
|
|
|
|
// check occlusion binary flag
|
|
|
|
if (window.occlusionState & NSWindowOcclusionStateVisible) {
|
|
|
|
// The app is visible
|
|
|
|
shell_->NotifyWindowShow();
|
|
|
|
} else {
|
|
|
|
// The app is not visible
|
|
|
|
shell_->NotifyWindowHide();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-05-21 17:46:13 +00:00
|
|
|
- (void)windowDidBecomeMain:(NSNotification*)notification {
|
2015-06-25 06:54:00 +00:00
|
|
|
content::WebContents* web_contents = shell_->web_contents();
|
2014-07-25 02:38:19 +00:00
|
|
|
if (!web_contents)
|
|
|
|
return;
|
2014-07-24 05:53:29 +00:00
|
|
|
|
2014-07-28 07:29:51 +00:00
|
|
|
web_contents->RestoreFocus();
|
2014-07-25 02:38:19 +00:00
|
|
|
|
|
|
|
content::RenderWidgetHostView* rwhv = web_contents->GetRenderWidgetHostView();
|
2014-07-24 05:53:29 +00:00
|
|
|
if (rwhv)
|
|
|
|
rwhv->SetActive(true);
|
2014-07-31 09:35:08 +00:00
|
|
|
|
|
|
|
shell_->NotifyWindowFocus();
|
2014-05-21 17:46:13 +00:00
|
|
|
}
|
|
|
|
|
2013-05-24 10:15:27 +00:00
|
|
|
- (void)windowDidResignMain:(NSNotification*)notification {
|
2015-06-25 06:54:00 +00:00
|
|
|
content::WebContents* web_contents = shell_->web_contents();
|
2014-07-25 02:38:19 +00:00
|
|
|
if (!web_contents)
|
|
|
|
return;
|
|
|
|
|
2014-07-28 07:29:51 +00:00
|
|
|
web_contents->StoreFocus();
|
2014-07-24 05:53:29 +00:00
|
|
|
|
2014-07-25 02:38:19 +00:00
|
|
|
content::RenderWidgetHostView* rwhv = web_contents->GetRenderWidgetHostView();
|
2014-07-24 05:53:29 +00:00
|
|
|
if (rwhv)
|
|
|
|
rwhv->SetActive(false);
|
2014-07-31 09:35:08 +00:00
|
|
|
|
|
|
|
shell_->NotifyWindowBlur();
|
2013-05-24 09:51:15 +00:00
|
|
|
}
|
|
|
|
|
2015-07-23 02:07:58 +00:00
|
|
|
- (NSSize)windowWillResize:(NSWindow*)sender toSize:(NSSize)frameSize {
|
2015-07-16 17:54:51 +00:00
|
|
|
NSSize newSize = frameSize;
|
2015-07-22 14:23:31 +00:00
|
|
|
double aspectRatio = shell_->GetAspectRatio();
|
2015-07-16 17:54:51 +00:00
|
|
|
|
2015-07-22 14:23:31 +00:00
|
|
|
if (aspectRatio > 0.0) {
|
2015-07-23 02:07:58 +00:00
|
|
|
gfx::Size windowSize = shell_->GetSize();
|
|
|
|
gfx::Size contentSize = shell_->GetContentSize();
|
|
|
|
gfx::Size extraSize = shell_->GetAspectRatioExtraSize();
|
|
|
|
|
|
|
|
double extraWidthPlusFrame =
|
|
|
|
windowSize.width() - contentSize.width() + extraSize.width();
|
|
|
|
double extraHeightPlusFrame =
|
|
|
|
windowSize.height() - contentSize.height() + extraSize.height();
|
|
|
|
|
|
|
|
newSize.width =
|
|
|
|
roundf((frameSize.height - extraHeightPlusFrame) * aspectRatio +
|
|
|
|
extraWidthPlusFrame);
|
|
|
|
|
|
|
|
// If the new width is less than the frame size use it as the primary
|
|
|
|
// constraint. This ensures that the value returned by this method will
|
|
|
|
// never be larger than the users requested window size.
|
2015-07-22 14:23:31 +00:00
|
|
|
if (newSize.width <= frameSize.width) {
|
2015-07-23 02:07:58 +00:00
|
|
|
newSize.height =
|
|
|
|
roundf((newSize.width - extraWidthPlusFrame) / aspectRatio +
|
|
|
|
extraHeightPlusFrame);
|
|
|
|
} else {
|
|
|
|
newSize.height =
|
|
|
|
roundf((frameSize.width - extraWidthPlusFrame) / aspectRatio +
|
|
|
|
extraHeightPlusFrame);
|
|
|
|
newSize.width =
|
|
|
|
roundf((newSize.height - extraHeightPlusFrame) * aspectRatio +
|
|
|
|
extraWidthPlusFrame);
|
2015-07-16 17:54:51 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return newSize;
|
|
|
|
}
|
|
|
|
|
2014-12-23 23:50:42 +00:00
|
|
|
- (void)windowDidResize:(NSNotification*)notification {
|
2015-10-20 23:33:43 +00:00
|
|
|
shell_->UpdateDraggableRegionViews();
|
2015-05-09 15:55:10 +00:00
|
|
|
shell_->NotifyWindowResize();
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void)windowDidMove:(NSNotification*)notification {
|
2015-05-20 08:37:13 +00:00
|
|
|
// TODO(zcbenz): Remove the alias after figuring out a proper
|
2015-06-25 01:47:57 +00:00
|
|
|
// way to disptach move.
|
2015-05-09 15:55:10 +00:00
|
|
|
shell_->NotifyWindowMove();
|
2015-05-20 08:37:13 +00:00
|
|
|
shell_->NotifyWindowMoved();
|
2013-09-11 10:10:28 +00:00
|
|
|
}
|
|
|
|
|
2014-11-25 05:16:51 +00:00
|
|
|
- (void)windowDidMiniaturize:(NSNotification*)notification {
|
|
|
|
shell_->NotifyWindowMinimize();
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void)windowDidDeminiaturize:(NSNotification*)notification {
|
|
|
|
shell_->NotifyWindowRestore();
|
|
|
|
}
|
|
|
|
|
|
|
|
- (BOOL)windowShouldZoom:(NSWindow*)window toFrame:(NSRect)newFrame {
|
|
|
|
// Cocoa doen't have concept of maximize/unmaximize, so wee need to emulate
|
|
|
|
// them by calculating size change when zooming.
|
|
|
|
if (newFrame.size.width < [window frame].size.width ||
|
|
|
|
newFrame.size.height < [window frame].size.height)
|
|
|
|
shell_->NotifyWindowUnmaximize();
|
|
|
|
else
|
|
|
|
shell_->NotifyWindowMaximize();
|
|
|
|
return YES;
|
|
|
|
}
|
|
|
|
|
2015-12-23 04:38:11 +00:00
|
|
|
- (void)windowWillEnterFullScreen:(NSNotification*)notification {
|
|
|
|
// Hide the native toolbar before entering fullscreen, so there is no visual
|
|
|
|
// artifacts.
|
|
|
|
if (shell_->should_hide_native_toolbar_in_fullscreen()) {
|
2015-12-21 18:55:23 +00:00
|
|
|
NSWindow* window = shell_->GetNativeWindow();
|
|
|
|
[window setToolbar:nil];
|
|
|
|
}
|
2014-11-25 05:16:51 +00:00
|
|
|
}
|
|
|
|
|
2015-12-23 04:38:11 +00:00
|
|
|
- (void)windowDidEnterFullScreen:(NSNotification*)notification {
|
|
|
|
shell_->NotifyWindowEnterFullScreen();
|
2015-12-21 18:55:23 +00:00
|
|
|
|
2015-12-23 04:38:11 +00:00
|
|
|
// Restore the native toolbar immediately after entering fullscreen, if we do
|
|
|
|
// this before leaving fullscreen, traffic light buttons will be jumping.
|
|
|
|
if (shell_->should_hide_native_toolbar_in_fullscreen()) {
|
2015-12-21 18:55:23 +00:00
|
|
|
NSWindow* window = shell_->GetNativeWindow();
|
|
|
|
base::scoped_nsobject<NSToolbar> toolbar(
|
|
|
|
[[NSToolbar alloc] initWithIdentifier:@"titlebarStylingToolbar"]);
|
|
|
|
[toolbar setShowsBaselineSeparator:NO];
|
|
|
|
[window setToolbar:toolbar];
|
2016-05-17 07:19:28 +00:00
|
|
|
|
|
|
|
// Set window style to hide the toolbar, otherwise the toolbar will show in
|
|
|
|
// fullscreen mode.
|
|
|
|
shell_->SetStyleMask(true, NSFullSizeContentViewWindowMask);
|
2015-12-21 18:55:23 +00:00
|
|
|
}
|
2015-12-23 04:38:11 +00:00
|
|
|
}
|
2015-12-21 18:55:23 +00:00
|
|
|
|
2016-05-17 07:19:28 +00:00
|
|
|
- (void)windowWillExitFullScreen:(NSNotification*)notification {
|
|
|
|
// Turn off the style for toolbar.
|
|
|
|
if (shell_->should_hide_native_toolbar_in_fullscreen())
|
|
|
|
shell_->SetStyleMask(false, NSFullSizeContentViewWindowMask);
|
|
|
|
}
|
|
|
|
|
2015-12-23 04:38:11 +00:00
|
|
|
- (void)windowDidExitFullScreen:(NSNotification*)notification {
|
2016-05-17 07:19:28 +00:00
|
|
|
// For certain versions of OS X the fullscreen button will automatically show
|
|
|
|
// after exiting fullscreen mode.
|
2014-03-15 11:28:23 +00:00
|
|
|
if (!shell_->has_frame()) {
|
|
|
|
NSWindow* window = shell_->GetNativeWindow();
|
|
|
|
[[window standardWindowButton:NSWindowFullScreenButton] setHidden:YES];
|
|
|
|
}
|
2014-11-25 05:16:51 +00:00
|
|
|
|
|
|
|
shell_->NotifyWindowLeaveFullScreen();
|
2014-03-15 11:28:23 +00:00
|
|
|
}
|
|
|
|
|
2013-05-24 09:51:15 +00:00
|
|
|
- (void)windowWillClose:(NSNotification*)notification {
|
2014-04-23 02:24:46 +00:00
|
|
|
shell_->NotifyWindowClosed();
|
2015-11-26 05:55:59 +00:00
|
|
|
|
|
|
|
// Clears the delegate when window is going to be closed, since EL Capitan it
|
|
|
|
// is possible that the methods of delegate would get called after the window
|
|
|
|
// has been closed.
|
|
|
|
[shell_->GetNativeWindow() setDelegate:nil];
|
2013-05-01 08:12:00 +00:00
|
|
|
}
|
2013-05-01 07:42:30 +00:00
|
|
|
|
2013-05-01 08:12:00 +00:00
|
|
|
- (BOOL)windowShouldClose:(id)window {
|
|
|
|
// When user tries to close the window by clicking the close button, we do
|
|
|
|
// not close the window immediately, instead we try to close the web page
|
|
|
|
// fisrt, and when the web page is closed the window will also be closed.
|
2015-06-25 05:27:51 +00:00
|
|
|
shell_->RequestToClosePage();
|
2013-05-01 08:12:00 +00:00
|
|
|
return NO;
|
2013-05-01 07:42:30 +00:00
|
|
|
}
|
|
|
|
|
2016-04-20 00:18:50 +00:00
|
|
|
- (NSRect)window:(NSWindow*)window
|
|
|
|
willPositionSheet:(NSWindow*)sheet usingRect:(NSRect)rect {
|
|
|
|
NSView* view = window.contentView;
|
2016-05-19 06:39:16 +00:00
|
|
|
|
|
|
|
rect.origin.x = shell_->GetSheetOffsetX();
|
|
|
|
rect.origin.y = view.frame.size.height - shell_->GetSheetOffsetY();
|
2016-03-27 01:12:25 +00:00
|
|
|
return rect;
|
|
|
|
}
|
|
|
|
|
2013-05-01 07:42:30 +00:00
|
|
|
@end
|
|
|
|
|
2015-12-08 03:20:07 +00:00
|
|
|
@interface AtomNSWindow : NSWindow {
|
2014-08-17 04:23:00 +00:00
|
|
|
@private
|
2013-04-12 07:53:29 +00:00
|
|
|
atom::NativeWindowMac* shell_;
|
2014-08-17 04:23:00 +00:00
|
|
|
bool enable_larger_than_screen_;
|
2013-04-12 07:53:29 +00:00
|
|
|
}
|
2015-04-27 03:47:26 +00:00
|
|
|
@property BOOL acceptsFirstMouse;
|
2015-04-27 04:08:22 +00:00
|
|
|
@property BOOL disableAutoHideCursor;
|
2015-11-19 08:39:45 +00:00
|
|
|
@property BOOL disableKeyOrMainWindow;
|
|
|
|
|
2013-04-12 07:53:29 +00:00
|
|
|
- (void)setShell:(atom::NativeWindowMac*)shell;
|
2014-08-17 04:23:00 +00:00
|
|
|
- (void)setEnableLargerThanScreen:(bool)enable;
|
2013-04-12 07:53:29 +00:00
|
|
|
@end
|
|
|
|
|
|
|
|
@implementation AtomNSWindow
|
|
|
|
|
|
|
|
- (void)setShell:(atom::NativeWindowMac*)shell {
|
|
|
|
shell_ = shell;
|
|
|
|
}
|
|
|
|
|
2014-08-17 04:23:00 +00:00
|
|
|
- (void)setEnableLargerThanScreen:(bool)enable {
|
|
|
|
enable_larger_than_screen_ = enable;
|
|
|
|
}
|
|
|
|
|
2015-12-07 11:56:23 +00:00
|
|
|
// NSWindow overrides.
|
|
|
|
|
2016-03-18 15:20:04 +00:00
|
|
|
- (void)swipeWithEvent:(NSEvent *)event {
|
2016-03-23 15:20:11 +00:00
|
|
|
if (event.deltaY == 1.0) {
|
|
|
|
shell_->NotifyWindowSwipe("up");
|
|
|
|
} else if (event.deltaX == -1.0) {
|
|
|
|
shell_->NotifyWindowSwipe("right");
|
|
|
|
} else if (event.deltaY == -1.0) {
|
|
|
|
shell_->NotifyWindowSwipe("down");
|
|
|
|
} else if (event.deltaX == 1.0) {
|
|
|
|
shell_->NotifyWindowSwipe("left");
|
|
|
|
}
|
2016-03-18 15:20:04 +00:00
|
|
|
}
|
|
|
|
|
2014-08-11 02:24:36 +00:00
|
|
|
- (NSRect)constrainFrameRect:(NSRect)frameRect toScreen:(NSScreen*)screen {
|
2015-08-05 06:12:55 +00:00
|
|
|
// Resizing is disabled.
|
|
|
|
if (ScopedDisableResize::IsResizeDisabled())
|
|
|
|
return [self frame];
|
|
|
|
|
|
|
|
// Enable the window to be larger than screen.
|
2014-08-17 04:23:00 +00:00
|
|
|
if (enable_larger_than_screen_)
|
|
|
|
return frameRect;
|
|
|
|
else
|
|
|
|
return [super constrainFrameRect:frameRect toScreen:screen];
|
2014-08-11 02:24:36 +00:00
|
|
|
}
|
|
|
|
|
2014-08-17 03:26:02 +00:00
|
|
|
- (id)accessibilityAttributeValue:(NSString*)attribute {
|
2015-04-13 12:10:51 +00:00
|
|
|
if (![attribute isEqualToString:@"AXChildren"])
|
|
|
|
return [super accessibilityAttributeValue:attribute];
|
|
|
|
|
|
|
|
// Filter out objects that aren't the title bar buttons. This has the effect
|
|
|
|
// of removing the window title, which VoiceOver already sees.
|
|
|
|
// * when VoiceOver is disabled, this causes Cmd+C to be used for TTS but
|
|
|
|
// still leaves the buttons available in the accessibility tree.
|
|
|
|
// * when VoiceOver is enabled, the full accessibility tree is used.
|
|
|
|
// Without removing the title and with VO disabled, the TTS would always read
|
|
|
|
// the window title instead of using Cmd+C to get the selected text.
|
|
|
|
NSPredicate *predicate = [NSPredicate predicateWithFormat:
|
|
|
|
@"(self isKindOfClass: %@) OR (self.className == %@)",
|
|
|
|
[NSButtonCell class],
|
|
|
|
@"RenderWidgetHostViewCocoa"];
|
|
|
|
|
|
|
|
NSArray *children = [super accessibilityAttributeValue:attribute];
|
|
|
|
return [children filteredArrayUsingPredicate:predicate];
|
2014-08-17 03:26:02 +00:00
|
|
|
}
|
|
|
|
|
2015-11-20 05:06:42 +00:00
|
|
|
- (BOOL)canBecomeMainWindow {
|
|
|
|
return !self.disableKeyOrMainWindow;
|
2015-11-19 08:39:45 +00:00
|
|
|
}
|
|
|
|
|
2015-11-20 05:06:42 +00:00
|
|
|
- (BOOL)canBecomeKeyWindow {
|
|
|
|
return !self.disableKeyOrMainWindow;
|
2015-11-19 08:39:45 +00:00
|
|
|
}
|
|
|
|
|
2013-04-12 07:53:29 +00:00
|
|
|
@end
|
|
|
|
|
2015-10-20 23:33:43 +00:00
|
|
|
@interface ControlRegionView : NSView
|
2013-09-05 15:52:29 +00:00
|
|
|
@end
|
|
|
|
|
|
|
|
@implementation ControlRegionView
|
|
|
|
|
|
|
|
- (BOOL)mouseDownCanMoveWindow {
|
|
|
|
return NO;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (NSView*)hitTest:(NSPoint)aPoint {
|
2015-10-20 23:33:43 +00:00
|
|
|
return nil;
|
2013-09-05 15:52:29 +00:00
|
|
|
}
|
|
|
|
|
2015-10-20 23:33:43 +00:00
|
|
|
@end
|
2015-03-24 09:20:29 +00:00
|
|
|
|
2015-10-20 23:33:43 +00:00
|
|
|
@interface NSView (WebContentsView)
|
|
|
|
- (void)setMouseDownCanMoveWindow:(BOOL)can_move;
|
2013-09-05 15:52:29 +00:00
|
|
|
@end
|
|
|
|
|
2014-09-17 07:58:08 +00:00
|
|
|
@interface AtomProgressBar : NSProgressIndicator
|
|
|
|
@end
|
|
|
|
|
|
|
|
@implementation AtomProgressBar
|
|
|
|
|
|
|
|
- (void)drawRect:(NSRect)dirtyRect {
|
|
|
|
if (self.style != NSProgressIndicatorBarStyle)
|
|
|
|
return;
|
|
|
|
// Draw edges of rounded rect.
|
|
|
|
NSRect rect = NSInsetRect([self bounds], 1.0, 1.0);
|
2014-09-18 08:17:49 +00:00
|
|
|
CGFloat radius = rect.size.height / 2;
|
|
|
|
NSBezierPath* bezier_path = [NSBezierPath bezierPathWithRoundedRect:rect xRadius:radius yRadius:radius];
|
|
|
|
[bezier_path setLineWidth:2.0];
|
|
|
|
[[NSColor grayColor] set];
|
|
|
|
[bezier_path stroke];
|
2014-09-17 07:58:08 +00:00
|
|
|
|
|
|
|
// Fill the rounded rect.
|
2014-09-18 08:17:49 +00:00
|
|
|
rect = NSInsetRect(rect, 2.0, 2.0);
|
|
|
|
radius = rect.size.height / 2;
|
|
|
|
bezier_path = [NSBezierPath bezierPathWithRoundedRect:rect xRadius:radius yRadius:radius];
|
|
|
|
[bezier_path setLineWidth:1.0];
|
|
|
|
[bezier_path addClip];
|
2014-09-17 07:58:08 +00:00
|
|
|
|
|
|
|
// Calculate the progress width.
|
2014-09-18 08:17:49 +00:00
|
|
|
rect.size.width = floor(rect.size.width * ([self doubleValue] / [self maxValue]));
|
2014-09-17 07:58:08 +00:00
|
|
|
|
|
|
|
// Fill the progress bar with color blue.
|
|
|
|
[[NSColor colorWithSRGBRed:0.2 green:0.6 blue:1 alpha:1] set];
|
|
|
|
NSRectFill(rect);
|
|
|
|
}
|
|
|
|
|
|
|
|
@end
|
|
|
|
|
2013-04-12 07:04:46 +00:00
|
|
|
namespace atom {
|
|
|
|
|
2015-06-25 01:47:57 +00:00
|
|
|
NativeWindowMac::NativeWindowMac(
|
|
|
|
brightray::InspectableWebContents* web_contents,
|
|
|
|
const mate::Dictionary& options)
|
2013-04-20 05:42:39 +00:00
|
|
|
: NativeWindow(web_contents, options),
|
2013-04-12 07:04:46 +00:00
|
|
|
is_kiosk_(false),
|
2015-12-23 04:38:11 +00:00
|
|
|
attention_request_id_(0),
|
2016-05-17 06:48:14 +00:00
|
|
|
force_show_buttons_(false),
|
2015-12-23 04:38:11 +00:00
|
|
|
should_hide_native_toolbar_in_fullscreen_(false) {
|
2014-01-06 10:58:30 +00:00
|
|
|
int width = 800, height = 600;
|
2015-11-13 05:58:31 +00:00
|
|
|
options.Get(options::kWidth, &width);
|
|
|
|
options.Get(options::kHeight, &height);
|
2013-04-12 07:04:46 +00:00
|
|
|
|
2015-05-10 08:51:18 +00:00
|
|
|
NSRect main_screen_rect = [[[NSScreen screens] objectAtIndex:0] frame];
|
2013-04-12 07:04:46 +00:00
|
|
|
NSRect cocoa_bounds = NSMakeRect(
|
2013-09-12 02:02:42 +00:00
|
|
|
round((NSWidth(main_screen_rect) - width) / 2) ,
|
|
|
|
round((NSHeight(main_screen_rect) - height) / 2),
|
2013-04-12 07:04:46 +00:00
|
|
|
width,
|
|
|
|
height);
|
2013-09-11 10:10:28 +00:00
|
|
|
|
2015-10-06 07:23:23 +00:00
|
|
|
bool resizable = true;
|
2015-11-13 05:58:31 +00:00
|
|
|
options.Get(options::kResizable, &resizable);
|
2015-05-06 14:08:24 +00:00
|
|
|
|
2016-01-18 22:46:35 +00:00
|
|
|
bool minimizable = true;
|
|
|
|
options.Get(options::kMinimizable, &minimizable);
|
2016-01-23 07:51:52 +00:00
|
|
|
|
2016-01-22 21:24:33 +00:00
|
|
|
bool maximizable = true;
|
|
|
|
options.Get(options::kMaximizable, &maximizable);
|
|
|
|
|
2016-01-18 22:46:35 +00:00
|
|
|
bool closable = true;
|
|
|
|
options.Get(options::kClosable, &closable);
|
|
|
|
|
2015-09-25 08:21:08 +00:00
|
|
|
// New title bar styles are available in Yosemite or newer
|
|
|
|
std::string titleBarStyle;
|
|
|
|
if (base::mac::IsOSYosemiteOrLater())
|
2015-11-13 05:58:31 +00:00
|
|
|
options.Get(options::kTitleBarStyle, &titleBarStyle);
|
2015-09-25 08:21:08 +00:00
|
|
|
|
2015-11-19 08:39:45 +00:00
|
|
|
std::string windowType;
|
|
|
|
options.Get(options::kType, &windowType);
|
|
|
|
|
|
|
|
bool useStandardWindow = true;
|
|
|
|
// eventually deprecate separate "standardWindow" option in favor of
|
|
|
|
// standard / textured window types
|
|
|
|
options.Get(options::kStandardWindow, &useStandardWindow);
|
|
|
|
if (windowType == "textured") {
|
|
|
|
useStandardWindow = false;
|
|
|
|
}
|
|
|
|
|
2016-01-23 10:23:18 +00:00
|
|
|
NSUInteger styleMask = NSTitledWindowMask;
|
2016-01-18 22:46:35 +00:00
|
|
|
if (minimizable) {
|
|
|
|
styleMask |= NSMiniaturizableWindowMask;
|
|
|
|
}
|
2016-01-23 10:23:18 +00:00
|
|
|
if (closable) {
|
|
|
|
styleMask |= NSClosableWindowMask;
|
2016-01-18 22:46:35 +00:00
|
|
|
}
|
2016-05-17 06:48:14 +00:00
|
|
|
if ((titleBarStyle == "hidden") || (titleBarStyle == "hidden-inset")) {
|
|
|
|
// The window without titlebar is treated the same with frameless window.
|
|
|
|
set_has_frame(false);
|
|
|
|
force_show_buttons_ = true;
|
|
|
|
}
|
2015-08-05 04:46:32 +00:00
|
|
|
if (!useStandardWindow || transparent() || !has_frame()) {
|
2015-05-06 14:08:24 +00:00
|
|
|
styleMask |= NSTexturedBackgroundWindowMask;
|
|
|
|
}
|
2015-10-06 07:23:23 +00:00
|
|
|
if (resizable) {
|
|
|
|
styleMask |= NSResizableWindowMask;
|
|
|
|
}
|
2015-12-21 18:55:23 +00:00
|
|
|
|
2015-03-25 10:51:29 +00:00
|
|
|
window_.reset([[AtomNSWindow alloc]
|
2013-09-12 15:20:38 +00:00
|
|
|
initWithContentRect:cocoa_bounds
|
2015-05-06 14:08:24 +00:00
|
|
|
styleMask:styleMask
|
2013-09-12 15:20:38 +00:00
|
|
|
backing:NSBackingStoreBuffered
|
2015-03-25 10:51:29 +00:00
|
|
|
defer:YES]);
|
|
|
|
[window_ setShell:this];
|
2015-08-05 04:46:32 +00:00
|
|
|
[window_ setEnableLargerThanScreen:enable_larger_than_screen()];
|
2013-09-11 10:10:28 +00:00
|
|
|
|
2015-03-25 10:51:29 +00:00
|
|
|
window_delegate_.reset([[AtomNSWindowDelegate alloc] initWithShell:this]);
|
|
|
|
[window_ setDelegate:window_delegate_];
|
2014-03-15 11:28:23 +00:00
|
|
|
|
2015-08-05 04:46:32 +00:00
|
|
|
if (transparent()) {
|
2014-12-23 19:17:56 +00:00
|
|
|
// Make window has transparent background.
|
|
|
|
[window_ setOpaque:NO];
|
2016-01-19 23:24:16 +00:00
|
|
|
// Setting the background color to clear will also hide the shadow.
|
2014-12-23 19:17:56 +00:00
|
|
|
[window_ setBackgroundColor:[NSColor clearColor]];
|
|
|
|
}
|
2015-04-25 02:35:28 +00:00
|
|
|
|
2015-11-19 08:39:45 +00:00
|
|
|
if (windowType == "desktop") {
|
|
|
|
[window_ setLevel:kCGDesktopWindowLevel - 1];
|
2015-11-20 05:06:42 +00:00
|
|
|
[window_ setDisableKeyOrMainWindow:YES];
|
2015-11-19 08:39:45 +00:00
|
|
|
[window_ setCollectionBehavior:
|
|
|
|
(NSWindowCollectionBehaviorCanJoinAllSpaces |
|
|
|
|
NSWindowCollectionBehaviorStationary |
|
|
|
|
NSWindowCollectionBehaviorIgnoresCycle)];
|
|
|
|
}
|
|
|
|
|
2015-04-25 02:35:28 +00:00
|
|
|
// Remove non-transparent corners, see http://git.io/vfonD.
|
2015-08-05 04:46:32 +00:00
|
|
|
if (!has_frame())
|
2015-04-18 12:08:22 +00:00
|
|
|
[window_ setOpaque:NO];
|
2014-12-23 19:17:56 +00:00
|
|
|
|
2014-04-11 04:32:42 +00:00
|
|
|
// We will manage window's lifetime ourselves.
|
2014-04-11 04:45:48 +00:00
|
|
|
[window_ setReleasedWhenClosed:NO];
|
2014-04-11 04:32:42 +00:00
|
|
|
|
2015-09-25 08:38:36 +00:00
|
|
|
// Hide the title bar.
|
2016-05-17 07:19:28 +00:00
|
|
|
if (titleBarStyle == "hidden-inset") {
|
2015-09-25 08:21:08 +00:00
|
|
|
[window_ setTitlebarAppearsTransparent:YES];
|
|
|
|
[window_ setTitleVisibility:NSWindowTitleHidden];
|
|
|
|
if (titleBarStyle == "hidden-inset") {
|
|
|
|
base::scoped_nsobject<NSToolbar> toolbar(
|
|
|
|
[[NSToolbar alloc] initWithIdentifier:@"titlebarStylingToolbar"]);
|
|
|
|
[toolbar setShowsBaselineSeparator:NO];
|
|
|
|
[window_ setToolbar:toolbar];
|
2016-05-17 06:48:14 +00:00
|
|
|
should_hide_native_toolbar_in_fullscreen_ = true;
|
2015-09-14 12:15:41 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-05-15 07:19:02 +00:00
|
|
|
// On OS X the initial window size doesn't include window frame.
|
|
|
|
bool use_content_size = false;
|
2015-11-13 05:58:31 +00:00
|
|
|
options.Get(options::kUseContentSize, &use_content_size);
|
2015-08-05 04:46:32 +00:00
|
|
|
if (!has_frame() || !use_content_size)
|
2014-05-15 07:19:02 +00:00
|
|
|
SetSize(gfx::Size(width, height));
|
|
|
|
|
2014-03-15 11:28:23 +00:00
|
|
|
// Enable the NSView to accept first mouse event.
|
|
|
|
bool acceptsFirstMouse = false;
|
2015-11-13 05:58:31 +00:00
|
|
|
options.Get(options::kAcceptFirstMouse, &acceptsFirstMouse);
|
2015-04-27 03:47:26 +00:00
|
|
|
[window_ setAcceptsFirstMouse:acceptsFirstMouse];
|
2013-04-12 07:04:46 +00:00
|
|
|
|
2015-04-27 04:08:22 +00:00
|
|
|
// Disable auto-hiding cursor.
|
|
|
|
bool disableAutoHideCursor = false;
|
2015-11-13 05:58:31 +00:00
|
|
|
options.Get(options::kDisableAutoHideCursor, &disableAutoHideCursor);
|
2015-04-27 04:08:22 +00:00
|
|
|
[window_ setDisableAutoHideCursor:disableAutoHideCursor];
|
|
|
|
|
2016-03-05 12:54:41 +00:00
|
|
|
// Disable zoom button if window is not resizable.
|
|
|
|
if (!maximizable)
|
2016-01-22 21:24:33 +00:00
|
|
|
SetMaximizable(false);
|
2016-01-18 22:46:35 +00:00
|
|
|
|
2013-09-05 15:52:29 +00:00
|
|
|
NSView* view = inspectable_web_contents()->GetView()->GetNativeView();
|
|
|
|
[view setAutoresizingMask:NSViewWidthSizable | NSViewHeightSizable];
|
|
|
|
|
2016-01-25 07:02:43 +00:00
|
|
|
// Use an NSEvent monitor to listen for the wheel event.
|
|
|
|
BOOL __block began = NO;
|
|
|
|
wheel_event_monitor_ = [NSEvent
|
2016-01-22 00:31:31 +00:00
|
|
|
addLocalMonitorForEventsMatchingMask:NSScrollWheelMask
|
2016-01-25 07:02:43 +00:00
|
|
|
handler:^(NSEvent* event) {
|
2016-01-22 00:36:48 +00:00
|
|
|
if ([[event window] windowNumber] != [window_ windowNumber])
|
2016-01-22 00:31:31 +00:00
|
|
|
return event;
|
|
|
|
|
|
|
|
if (!web_contents)
|
|
|
|
return event;
|
|
|
|
|
2016-01-25 07:02:43 +00:00
|
|
|
if (!began && (([event phase] == NSEventPhaseMayBegin) ||
|
|
|
|
([event phase] == NSEventPhaseBegan))) {
|
2016-01-22 00:31:31 +00:00
|
|
|
this->NotifyWindowScrollTouchBegin();
|
2016-01-25 07:02:43 +00:00
|
|
|
began = YES;
|
|
|
|
} else if (began && (([event phase] == NSEventPhaseEnded) ||
|
|
|
|
([event phase] == NSEventPhaseCancelled))) {
|
2016-01-22 00:31:31 +00:00
|
|
|
this->NotifyWindowScrollTouchEnd();
|
2016-01-25 07:02:43 +00:00
|
|
|
began = NO;
|
2016-01-22 00:31:31 +00:00
|
|
|
}
|
2016-01-21 17:40:21 +00:00
|
|
|
return event;
|
2016-01-25 07:02:43 +00:00
|
|
|
}];
|
2016-01-21 17:40:21 +00:00
|
|
|
|
2013-04-12 07:04:46 +00:00
|
|
|
InstallView();
|
|
|
|
}
|
|
|
|
|
|
|
|
NativeWindowMac::~NativeWindowMac() {
|
2016-01-25 07:02:43 +00:00
|
|
|
[NSEvent removeMonitor:wheel_event_monitor_];
|
2015-06-25 03:07:23 +00:00
|
|
|
Observe(nullptr);
|
2013-04-12 07:04:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void NativeWindowMac::Close() {
|
2014-04-11 04:45:48 +00:00
|
|
|
[window_ performClose:nil];
|
2013-04-12 07:04:46 +00:00
|
|
|
}
|
|
|
|
|
2013-05-01 08:12:00 +00:00
|
|
|
void NativeWindowMac::CloseImmediately() {
|
2014-04-11 04:45:48 +00:00
|
|
|
[window_ close];
|
2013-05-01 08:12:00 +00:00
|
|
|
}
|
|
|
|
|
2013-04-12 07:04:46 +00:00
|
|
|
void NativeWindowMac::Focus(bool focus) {
|
2013-10-03 01:39:17 +00:00
|
|
|
if (!IsVisible())
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (focus) {
|
2013-05-25 07:08:58 +00:00
|
|
|
[[NSApplication sharedApplication] activateIgnoringOtherApps:YES];
|
2014-04-11 04:45:48 +00:00
|
|
|
[window_ makeKeyAndOrderFront:nil];
|
2013-05-25 07:08:58 +00:00
|
|
|
} else {
|
2014-04-11 04:45:48 +00:00
|
|
|
[window_ orderBack:nil];
|
2013-05-25 07:08:58 +00:00
|
|
|
}
|
2013-04-12 07:04:46 +00:00
|
|
|
}
|
|
|
|
|
2013-05-16 14:56:52 +00:00
|
|
|
bool NativeWindowMac::IsFocused() {
|
2014-04-11 04:45:48 +00:00
|
|
|
return [window_ isKeyWindow];
|
2013-05-16 14:56:52 +00:00
|
|
|
}
|
|
|
|
|
2013-04-12 07:04:46 +00:00
|
|
|
void NativeWindowMac::Show() {
|
2014-12-28 01:41:13 +00:00
|
|
|
// This method is supposed to put focus on window, however if the app does not
|
|
|
|
// have focus then "makeKeyAndOrderFront" will only show the window.
|
|
|
|
[NSApp activateIgnoringOtherApps:YES];
|
|
|
|
|
2014-10-17 14:51:20 +00:00
|
|
|
[window_ makeKeyAndOrderFront:nil];
|
|
|
|
}
|
|
|
|
|
|
|
|
void NativeWindowMac::ShowInactive() {
|
2014-09-09 06:47:04 +00:00
|
|
|
[window_ orderFrontRegardless];
|
2013-04-12 07:04:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void NativeWindowMac::Hide() {
|
2014-04-11 04:45:48 +00:00
|
|
|
[window_ orderOut:nil];
|
2013-04-12 07:04:46 +00:00
|
|
|
}
|
|
|
|
|
2013-10-03 00:27:59 +00:00
|
|
|
bool NativeWindowMac::IsVisible() {
|
2014-04-11 04:45:48 +00:00
|
|
|
return [window_ isVisible];
|
2013-10-03 00:27:59 +00:00
|
|
|
}
|
|
|
|
|
2013-04-12 07:04:46 +00:00
|
|
|
void NativeWindowMac::Maximize() {
|
2016-04-22 23:15:00 +00:00
|
|
|
if (IsMaximized())
|
|
|
|
return;
|
|
|
|
|
2014-04-11 04:45:48 +00:00
|
|
|
[window_ zoom:nil];
|
2013-04-12 07:04:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void NativeWindowMac::Unmaximize() {
|
2016-04-22 23:15:00 +00:00
|
|
|
if (!IsMaximized())
|
|
|
|
return;
|
|
|
|
|
2014-04-11 04:45:48 +00:00
|
|
|
[window_ zoom:nil];
|
2013-04-12 07:04:46 +00:00
|
|
|
}
|
|
|
|
|
2014-06-28 01:17:37 +00:00
|
|
|
bool NativeWindowMac::IsMaximized() {
|
2016-03-05 06:39:13 +00:00
|
|
|
if (([window_ styleMask] & NSResizableWindowMask) != 0) {
|
|
|
|
return [window_ isZoomed];
|
|
|
|
} else {
|
|
|
|
NSRect rectScreen = [[NSScreen mainScreen] visibleFrame];
|
|
|
|
NSRect rectWindow = [window_ frame];
|
|
|
|
return (rectScreen.origin.x == rectWindow.origin.x &&
|
|
|
|
rectScreen.origin.y == rectWindow.origin.y &&
|
|
|
|
rectScreen.size.width == rectWindow.size.width &&
|
|
|
|
rectScreen.size.height == rectWindow.size.height);
|
|
|
|
}
|
2014-05-14 21:58:49 +00:00
|
|
|
}
|
|
|
|
|
2013-04-12 07:04:46 +00:00
|
|
|
void NativeWindowMac::Minimize() {
|
2014-04-11 04:45:48 +00:00
|
|
|
[window_ miniaturize:nil];
|
2013-04-12 07:04:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void NativeWindowMac::Restore() {
|
2014-04-11 04:45:48 +00:00
|
|
|
[window_ deminiaturize:nil];
|
2013-04-12 07:04:46 +00:00
|
|
|
}
|
|
|
|
|
2014-07-26 05:58:26 +00:00
|
|
|
bool NativeWindowMac::IsMinimized() {
|
|
|
|
return [window_ isMiniaturized];
|
|
|
|
}
|
|
|
|
|
2014-11-25 06:34:14 +00:00
|
|
|
void NativeWindowMac::SetFullScreen(bool fullscreen) {
|
2013-06-04 10:15:03 +00:00
|
|
|
if (fullscreen == IsFullscreen())
|
2013-04-12 07:04:46 +00:00
|
|
|
return;
|
|
|
|
|
2013-06-04 10:15:03 +00:00
|
|
|
if (!base::mac::IsOSLionOrLater()) {
|
|
|
|
LOG(ERROR) << "Fullscreen mode is only supported above Lion";
|
2013-04-12 07:04:46 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2014-04-11 04:45:48 +00:00
|
|
|
[window_ toggleFullScreen:nil];
|
2013-04-12 07:04:46 +00:00
|
|
|
}
|
|
|
|
|
2015-04-21 13:35:36 +00:00
|
|
|
bool NativeWindowMac::IsFullscreen() const {
|
2014-04-11 04:45:48 +00:00
|
|
|
return [window_ styleMask] & NSFullScreenWindowMask;
|
2013-04-12 07:04:46 +00:00
|
|
|
}
|
|
|
|
|
2016-01-15 04:54:12 +00:00
|
|
|
void NativeWindowMac::SetBounds(const gfx::Rect& bounds, bool animate) {
|
2015-05-01 14:40:46 +00:00
|
|
|
NSRect cocoa_bounds = NSMakeRect(bounds.x(), 0,
|
|
|
|
bounds.width(),
|
|
|
|
bounds.height());
|
|
|
|
// Flip coordinates based on the primary screen.
|
2015-05-10 08:51:18 +00:00
|
|
|
NSScreen* screen = [[NSScreen screens] objectAtIndex:0];
|
2015-05-01 14:40:46 +00:00
|
|
|
cocoa_bounds.origin.y =
|
|
|
|
NSHeight([screen frame]) - bounds.height() - bounds.y();
|
|
|
|
|
2016-01-15 04:54:12 +00:00
|
|
|
[window_ setFrame:cocoa_bounds display:YES animate:animate];
|
2015-05-01 10:50:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
gfx::Rect NativeWindowMac::GetBounds() {
|
2015-05-01 14:40:46 +00:00
|
|
|
NSRect frame = [window_ frame];
|
2015-05-04 04:06:03 +00:00
|
|
|
gfx::Rect bounds(frame.origin.x, 0, NSWidth(frame), NSHeight(frame));
|
2015-05-10 08:51:18 +00:00
|
|
|
NSScreen* screen = [[NSScreen screens] objectAtIndex:0];
|
2015-05-04 04:06:03 +00:00
|
|
|
bounds.set_y(NSHeight([screen frame]) - NSMaxY(frame));
|
|
|
|
return bounds;
|
2015-05-01 10:50:53 +00:00
|
|
|
}
|
|
|
|
|
2015-10-05 08:19:01 +00:00
|
|
|
void NativeWindowMac::SetContentSizeConstraints(
|
|
|
|
const extensions::SizeConstraints& size_constraints) {
|
2015-10-06 07:15:23 +00:00
|
|
|
auto convertSize = [this](const gfx::Size& size) {
|
|
|
|
// Our frameless window still has titlebar attached, so setting contentSize
|
|
|
|
// will result in actual content size being larger.
|
|
|
|
if (!has_frame()) {
|
|
|
|
NSRect frame = NSMakeRect(0, 0, size.width(), size.height());
|
|
|
|
NSRect content = [window_ contentRectForFrameRect:frame];
|
|
|
|
return content.size;
|
|
|
|
} else {
|
|
|
|
return NSMakeSize(size.width(), size.height());
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2014-04-11 04:45:48 +00:00
|
|
|
NSView* content = [window_ contentView];
|
2015-10-05 08:19:01 +00:00
|
|
|
if (size_constraints.HasMinimumSize()) {
|
2015-10-06 07:15:23 +00:00
|
|
|
NSSize min_size = convertSize(size_constraints.GetMinimumSize());
|
2015-10-05 12:09:29 +00:00
|
|
|
[window_ setContentMinSize:[content convertSize:min_size toView:nil]];
|
2015-10-05 08:19:01 +00:00
|
|
|
}
|
|
|
|
if (size_constraints.HasMaximumSize()) {
|
2015-10-06 07:15:23 +00:00
|
|
|
NSSize max_size = convertSize(size_constraints.GetMaximumSize());
|
2015-10-05 12:09:29 +00:00
|
|
|
[window_ setContentMaxSize:[content convertSize:max_size toView:nil]];
|
2015-10-05 08:19:01 +00:00
|
|
|
}
|
|
|
|
NativeWindow::SetContentSizeConstraints(size_constraints);
|
2013-04-18 07:38:04 +00:00
|
|
|
}
|
|
|
|
|
2013-04-12 07:04:46 +00:00
|
|
|
void NativeWindowMac::SetResizable(bool resizable) {
|
2015-08-05 06:12:55 +00:00
|
|
|
// Change styleMask for frameless causes the window to change size, so we have
|
|
|
|
// to explicitly disables that.
|
|
|
|
ScopedDisableResize disable_resize;
|
2016-01-23 11:12:19 +00:00
|
|
|
SetStyleMask(resizable, NSResizableWindowMask);
|
2013-04-12 07:04:46 +00:00
|
|
|
}
|
|
|
|
|
2013-04-18 07:38:04 +00:00
|
|
|
bool NativeWindowMac::IsResizable() {
|
2014-04-11 04:45:48 +00:00
|
|
|
return [window_ styleMask] & NSResizableWindowMask;
|
2013-04-18 07:38:04 +00:00
|
|
|
}
|
|
|
|
|
2016-01-18 22:46:35 +00:00
|
|
|
void NativeWindowMac::SetMovable(bool movable) {
|
|
|
|
[window_ setMovable:movable];
|
|
|
|
}
|
|
|
|
|
|
|
|
bool NativeWindowMac::IsMovable() {
|
|
|
|
return [window_ isMovable];
|
|
|
|
}
|
|
|
|
|
|
|
|
void NativeWindowMac::SetMinimizable(bool minimizable) {
|
2016-01-23 11:12:19 +00:00
|
|
|
SetStyleMask(minimizable, NSMiniaturizableWindowMask);
|
2016-01-18 22:46:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bool NativeWindowMac::IsMinimizable() {
|
|
|
|
return [window_ styleMask] & NSMiniaturizableWindowMask;
|
|
|
|
}
|
|
|
|
|
2016-01-22 21:24:33 +00:00
|
|
|
void NativeWindowMac::SetMaximizable(bool maximizable) {
|
|
|
|
[[window_ standardWindowButton:NSWindowZoomButton] setEnabled:maximizable];
|
|
|
|
}
|
|
|
|
|
|
|
|
bool NativeWindowMac::IsMaximizable() {
|
|
|
|
return [[window_ standardWindowButton:NSWindowZoomButton] isEnabled];
|
|
|
|
}
|
|
|
|
|
2016-01-23 07:47:37 +00:00
|
|
|
void NativeWindowMac::SetFullScreenable(bool fullscreenable) {
|
2016-01-23 11:12:19 +00:00
|
|
|
SetCollectionBehavior(
|
|
|
|
fullscreenable, NSWindowCollectionBehaviorFullScreenPrimary);
|
|
|
|
// On EL Capitan this flag is required to hide fullscreen button.
|
|
|
|
SetCollectionBehavior(
|
|
|
|
!fullscreenable, NSWindowCollectionBehaviorFullScreenAuxiliary);
|
2016-01-22 21:24:33 +00:00
|
|
|
}
|
|
|
|
|
2016-01-23 07:47:37 +00:00
|
|
|
bool NativeWindowMac::IsFullScreenable() {
|
2016-01-23 11:12:19 +00:00
|
|
|
NSUInteger collectionBehavior = [window_ collectionBehavior];
|
|
|
|
return collectionBehavior & NSWindowCollectionBehaviorFullScreenPrimary;
|
2016-01-22 21:24:33 +00:00
|
|
|
}
|
|
|
|
|
2016-01-18 22:46:35 +00:00
|
|
|
void NativeWindowMac::SetClosable(bool closable) {
|
2016-01-23 11:12:19 +00:00
|
|
|
SetStyleMask(closable, NSClosableWindowMask);
|
2016-01-18 22:46:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bool NativeWindowMac::IsClosable() {
|
|
|
|
return [window_ styleMask] & NSClosableWindowMask;
|
|
|
|
}
|
|
|
|
|
2013-04-12 07:04:46 +00:00
|
|
|
void NativeWindowMac::SetAlwaysOnTop(bool top) {
|
2014-04-11 04:45:48 +00:00
|
|
|
[window_ setLevel:(top ? NSFloatingWindowLevel : NSNormalWindowLevel)];
|
2013-04-12 07:04:46 +00:00
|
|
|
}
|
|
|
|
|
2013-04-18 07:38:04 +00:00
|
|
|
bool NativeWindowMac::IsAlwaysOnTop() {
|
2014-04-11 04:45:48 +00:00
|
|
|
return [window_ level] == NSFloatingWindowLevel;
|
2013-04-18 07:38:04 +00:00
|
|
|
}
|
|
|
|
|
2013-05-10 12:34:05 +00:00
|
|
|
void NativeWindowMac::Center() {
|
2014-04-11 04:45:48 +00:00
|
|
|
[window_ center];
|
2013-04-12 07:04:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void NativeWindowMac::SetTitle(const std::string& title) {
|
2015-08-26 07:45:38 +00:00
|
|
|
// We don't want the title to show in transparent or frameless window.
|
|
|
|
if (transparent() || !has_frame())
|
2014-12-23 19:48:20 +00:00
|
|
|
return;
|
|
|
|
|
2014-04-11 04:45:48 +00:00
|
|
|
[window_ setTitle:base::SysUTF8ToNSString(title)];
|
2013-04-12 07:04:46 +00:00
|
|
|
}
|
|
|
|
|
2013-04-18 06:30:05 +00:00
|
|
|
std::string NativeWindowMac::GetTitle() {
|
2014-04-11 04:45:48 +00:00
|
|
|
return base::SysNSStringToUTF8([window_ title]);
|
2013-04-18 06:30:05 +00:00
|
|
|
}
|
|
|
|
|
2013-04-12 07:04:46 +00:00
|
|
|
void NativeWindowMac::FlashFrame(bool flash) {
|
|
|
|
if (flash) {
|
|
|
|
attention_request_id_ = [NSApp requestUserAttention:NSInformationalRequest];
|
|
|
|
} else {
|
|
|
|
[NSApp cancelUserAttentionRequest:attention_request_id_];
|
|
|
|
attention_request_id_ = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-06-16 02:29:51 +00:00
|
|
|
void NativeWindowMac::SetSkipTaskbar(bool skip) {
|
|
|
|
}
|
|
|
|
|
2013-04-12 07:04:46 +00:00
|
|
|
void NativeWindowMac::SetKiosk(bool kiosk) {
|
2014-06-09 05:04:59 +00:00
|
|
|
if (kiosk && !is_kiosk_) {
|
|
|
|
kiosk_options_ = [NSApp currentSystemPresentationOptions];
|
2013-04-12 07:04:46 +00:00
|
|
|
NSApplicationPresentationOptions options =
|
|
|
|
NSApplicationPresentationHideDock +
|
2013-09-11 20:23:17 +00:00
|
|
|
NSApplicationPresentationHideMenuBar +
|
2013-04-12 07:04:46 +00:00
|
|
|
NSApplicationPresentationDisableAppleMenu +
|
|
|
|
NSApplicationPresentationDisableProcessSwitching +
|
|
|
|
NSApplicationPresentationDisableForceQuit +
|
|
|
|
NSApplicationPresentationDisableSessionTermination +
|
|
|
|
NSApplicationPresentationDisableHideApplication;
|
|
|
|
[NSApp setPresentationOptions:options];
|
|
|
|
is_kiosk_ = true;
|
2014-11-25 06:34:14 +00:00
|
|
|
SetFullScreen(true);
|
2014-06-09 05:04:59 +00:00
|
|
|
} else if (!kiosk && is_kiosk_) {
|
|
|
|
is_kiosk_ = false;
|
2014-11-25 06:34:14 +00:00
|
|
|
SetFullScreen(false);
|
2014-06-09 05:04:59 +00:00
|
|
|
[NSApp setPresentationOptions:kiosk_options_];
|
2013-04-12 07:04:46 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
bool NativeWindowMac::IsKiosk() {
|
|
|
|
return is_kiosk_;
|
|
|
|
}
|
|
|
|
|
2015-10-23 03:35:33 +00:00
|
|
|
void NativeWindowMac::SetBackgroundColor(const std::string& color_name) {
|
2016-04-14 12:52:17 +00:00
|
|
|
SkColor color = ParseHexColor(color_name);
|
|
|
|
base::ScopedCFTypeRef<CGColorRef> cgcolor =
|
|
|
|
skia::CGColorCreateFromSkColor(color);
|
|
|
|
[[[window_ contentView] layer] setBackgroundColor:cgcolor];
|
|
|
|
|
|
|
|
const auto view = web_contents()->GetRenderWidgetHostView();
|
|
|
|
if (view)
|
|
|
|
view->SetBackgroundColor(color);
|
2015-10-23 03:35:33 +00:00
|
|
|
}
|
|
|
|
|
2016-01-23 00:15:49 +00:00
|
|
|
void NativeWindowMac::SetHasShadow(bool has_shadow) {
|
|
|
|
[window_ setHasShadow:has_shadow];
|
|
|
|
}
|
|
|
|
|
|
|
|
bool NativeWindowMac::HasShadow() {
|
|
|
|
return [window_ hasShadow];
|
|
|
|
}
|
|
|
|
|
2014-05-27 06:15:34 +00:00
|
|
|
void NativeWindowMac::SetRepresentedFilename(const std::string& filename) {
|
|
|
|
[window_ setRepresentedFilename:base::SysUTF8ToNSString(filename)];
|
|
|
|
}
|
|
|
|
|
2014-07-18 13:42:26 +00:00
|
|
|
std::string NativeWindowMac::GetRepresentedFilename() {
|
|
|
|
return base::SysNSStringToUTF8([window_ representedFilename]);
|
|
|
|
}
|
|
|
|
|
2014-05-27 06:15:34 +00:00
|
|
|
void NativeWindowMac::SetDocumentEdited(bool edited) {
|
|
|
|
[window_ setDocumentEdited:edited];
|
|
|
|
}
|
|
|
|
|
2014-07-24 07:48:33 +00:00
|
|
|
bool NativeWindowMac::IsDocumentEdited() {
|
|
|
|
return [window_ isDocumentEdited];
|
|
|
|
}
|
|
|
|
|
2015-12-06 02:14:54 +00:00
|
|
|
void NativeWindowMac::SetIgnoreMouseEvents(bool ignore) {
|
|
|
|
[window_ setIgnoresMouseEvents:ignore];
|
|
|
|
}
|
|
|
|
|
2013-12-04 08:32:32 +00:00
|
|
|
bool NativeWindowMac::HasModalDialog() {
|
2014-04-11 04:45:48 +00:00
|
|
|
return [window_ attachedSheet] != nil;
|
2013-12-04 08:32:32 +00:00
|
|
|
}
|
|
|
|
|
2013-05-03 11:31:24 +00:00
|
|
|
gfx::NativeWindow NativeWindowMac::GetNativeWindow() {
|
2014-04-11 04:45:48 +00:00
|
|
|
return window_;
|
2013-05-03 11:31:24 +00:00
|
|
|
}
|
|
|
|
|
2016-01-07 20:38:35 +00:00
|
|
|
gfx::AcceleratedWidget NativeWindowMac::GetAcceleratedWidget() {
|
2016-01-07 22:27:53 +00:00
|
|
|
return inspectable_web_contents()->GetView()->GetNativeView();
|
2016-01-07 20:38:35 +00:00
|
|
|
}
|
|
|
|
|
2014-09-17 07:58:08 +00:00
|
|
|
void NativeWindowMac::SetProgressBar(double progress) {
|
|
|
|
NSDockTile* dock_tile = [NSApp dockTile];
|
|
|
|
|
|
|
|
// For the first time API invoked, we need to create a ContentView in DockTile.
|
|
|
|
if (dock_tile.contentView == NULL) {
|
|
|
|
NSImageView* image_view = [[NSImageView alloc] init];
|
|
|
|
[image_view setImage:[NSApp applicationIconImage]];
|
|
|
|
[dock_tile setContentView:image_view];
|
|
|
|
|
|
|
|
NSProgressIndicator* progress_indicator = [[AtomProgressBar alloc]
|
|
|
|
initWithFrame:NSMakeRect(0.0f, 0.0f, dock_tile.size.width, 15.0)];
|
|
|
|
[progress_indicator setStyle:NSProgressIndicatorBarStyle];
|
|
|
|
[progress_indicator setIndeterminate:NO];
|
|
|
|
[progress_indicator setBezeled:YES];
|
|
|
|
[progress_indicator setMinValue:0];
|
|
|
|
[progress_indicator setMaxValue:1];
|
|
|
|
[progress_indicator setHidden:NO];
|
|
|
|
[image_view addSubview:progress_indicator];
|
|
|
|
}
|
|
|
|
|
|
|
|
NSProgressIndicator* progress_indicator =
|
|
|
|
static_cast<NSProgressIndicator*>([[[dock_tile contentView] subviews]
|
|
|
|
objectAtIndex:0]);
|
|
|
|
if (progress < 0) {
|
|
|
|
[progress_indicator setHidden:YES];
|
|
|
|
} else if (progress > 1) {
|
2014-09-21 10:56:03 +00:00
|
|
|
[progress_indicator setHidden:NO];
|
2014-09-17 07:58:08 +00:00
|
|
|
[progress_indicator setIndeterminate:YES];
|
2014-09-21 10:56:03 +00:00
|
|
|
[progress_indicator setDoubleValue:1];
|
2014-09-17 07:58:08 +00:00
|
|
|
} else {
|
2014-09-21 10:56:03 +00:00
|
|
|
[progress_indicator setHidden:NO];
|
2014-09-17 07:58:08 +00:00
|
|
|
[progress_indicator setDoubleValue:progress];
|
|
|
|
}
|
|
|
|
[dock_tile display];
|
|
|
|
}
|
|
|
|
|
2015-02-11 01:14:26 +00:00
|
|
|
void NativeWindowMac::SetOverlayIcon(const gfx::Image& overlay,
|
|
|
|
const std::string& description) {
|
2015-02-07 19:56:03 +00:00
|
|
|
}
|
|
|
|
|
2014-12-18 23:40:35 +00:00
|
|
|
void NativeWindowMac::ShowDefinitionForSelection() {
|
2015-06-25 06:54:00 +00:00
|
|
|
if (!web_contents())
|
2014-12-19 20:48:53 +00:00
|
|
|
return;
|
2015-06-25 06:54:00 +00:00
|
|
|
auto rwhv = web_contents()->GetRenderWidgetHostView();
|
2014-12-18 23:40:35 +00:00
|
|
|
if (!rwhv)
|
|
|
|
return;
|
|
|
|
rwhv->ShowDefinitionForSelection();
|
|
|
|
}
|
|
|
|
|
2015-03-26 06:18:37 +00:00
|
|
|
void NativeWindowMac::SetVisibleOnAllWorkspaces(bool visible) {
|
2016-01-23 11:12:19 +00:00
|
|
|
SetCollectionBehavior(visible, NSWindowCollectionBehaviorCanJoinAllSpaces);
|
2015-03-26 06:18:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bool NativeWindowMac::IsVisibleOnAllWorkspaces() {
|
2015-03-27 11:41:07 +00:00
|
|
|
NSUInteger collectionBehavior = [window_ collectionBehavior];
|
|
|
|
return collectionBehavior & NSWindowCollectionBehaviorCanJoinAllSpaces;
|
2015-03-26 06:18:37 +00:00
|
|
|
}
|
|
|
|
|
2015-10-20 23:33:43 +00:00
|
|
|
std::vector<gfx::Rect> NativeWindowMac::CalculateNonDraggableRegions(
|
|
|
|
const std::vector<DraggableRegion>& regions, int width, int height) {
|
|
|
|
std::vector<gfx::Rect> result;
|
|
|
|
if (regions.empty()) {
|
|
|
|
result.push_back(gfx::Rect(0, 0, width, height));
|
|
|
|
} else {
|
|
|
|
scoped_ptr<SkRegion> draggable(DraggableRegionsToSkRegion(regions));
|
|
|
|
scoped_ptr<SkRegion> non_draggable(new SkRegion);
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2015-10-05 08:19:01 +00:00
|
|
|
gfx::Size NativeWindowMac::ContentSizeToWindowSize(const gfx::Size& size) {
|
2015-10-05 11:32:23 +00:00
|
|
|
if (!has_frame())
|
|
|
|
return size;
|
|
|
|
|
2015-10-05 08:19:01 +00:00
|
|
|
NSRect content = NSMakeRect(0, 0, size.width(), size.height());
|
|
|
|
NSRect frame = [window_ frameRectForContentRect:content];
|
|
|
|
return gfx::Size(frame.size);
|
|
|
|
}
|
|
|
|
|
|
|
|
gfx::Size NativeWindowMac::WindowSizeToContentSize(const gfx::Size& size) {
|
2015-10-05 11:32:23 +00:00
|
|
|
if (!has_frame())
|
|
|
|
return size;
|
|
|
|
|
2015-10-05 08:19:01 +00:00
|
|
|
NSRect frame = NSMakeRect(0, 0, size.width(), size.height());
|
|
|
|
NSRect content = [window_ contentRectForFrameRect:frame];
|
|
|
|
return gfx::Size(content.size);
|
|
|
|
}
|
|
|
|
|
2015-10-20 23:33:43 +00:00
|
|
|
void NativeWindowMac::UpdateDraggableRegions(
|
|
|
|
const std::vector<DraggableRegion>& regions) {
|
|
|
|
NativeWindow::UpdateDraggableRegions(regions);
|
|
|
|
draggable_regions_ = regions;
|
|
|
|
UpdateDraggableRegionViews(regions);
|
|
|
|
}
|
|
|
|
|
2013-04-12 07:04:46 +00:00
|
|
|
void NativeWindowMac::InstallView() {
|
2015-08-26 07:45:38 +00:00
|
|
|
// Make sure the bottom corner is rounded: http://crbug.com/396264.
|
|
|
|
[[window_ contentView] setWantsLayer:YES];
|
|
|
|
|
2013-04-12 08:41:15 +00:00
|
|
|
NSView* view = inspectable_web_contents()->GetView()->GetNativeView();
|
2015-08-05 04:46:32 +00:00
|
|
|
if (has_frame()) {
|
2014-04-11 04:45:48 +00:00
|
|
|
[view setFrame:[[window_ contentView] bounds]];
|
|
|
|
[[window_ contentView] addSubview:view];
|
2013-09-05 15:52:29 +00:00
|
|
|
} else {
|
2015-08-26 07:45:38 +00:00
|
|
|
// In OSX 10.10, adding subviews to the root view for the NSView hierarchy
|
|
|
|
// produces warnings. To eliminate the warnings, we resize the contentView
|
|
|
|
// to fill the window, and add subviews to that.
|
|
|
|
// http://crbug.com/380412
|
|
|
|
content_view_.reset([[FullSizeContentView alloc] init]);
|
|
|
|
[content_view_
|
|
|
|
setAutoresizingMask:NSViewWidthSizable | NSViewHeightSizable];
|
|
|
|
[content_view_ setFrame:[[[window_ contentView] superview] bounds]];
|
|
|
|
[window_ setContentView:content_view_];
|
|
|
|
|
|
|
|
[view setFrame:[content_view_ bounds]];
|
|
|
|
[content_view_ addSubview:view];
|
2013-09-11 20:23:17 +00:00
|
|
|
|
2016-05-17 06:48:14 +00:00
|
|
|
if (force_show_buttons_)
|
|
|
|
return;
|
|
|
|
|
|
|
|
// Hide the window buttons.
|
2014-04-11 04:45:48 +00:00
|
|
|
[[window_ standardWindowButton:NSWindowZoomButton] setHidden:YES];
|
|
|
|
[[window_ standardWindowButton:NSWindowMiniaturizeButton] setHidden:YES];
|
|
|
|
[[window_ standardWindowButton:NSWindowCloseButton] setHidden:YES];
|
2014-12-23 23:50:42 +00:00
|
|
|
|
|
|
|
// Some third-party OS X utilities check the zoom button's enabled state to
|
|
|
|
// determine whether to show custom UI on hover, so we disable it here to
|
|
|
|
// prevent them from doing so in a frameless app window.
|
|
|
|
[[window_ standardWindowButton:NSWindowZoomButton] setEnabled:NO];
|
2013-09-05 15:52:29 +00:00
|
|
|
}
|
2013-04-12 07:04:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void NativeWindowMac::UninstallView() {
|
2013-09-06 03:54:52 +00:00
|
|
|
NSView* view = inspectable_web_contents()->GetView()->GetNativeView();
|
2013-04-12 07:04:46 +00:00
|
|
|
[view removeFromSuperview];
|
|
|
|
}
|
|
|
|
|
2015-10-20 23:33:43 +00:00
|
|
|
void NativeWindowMac::UpdateDraggableRegionViews(
|
|
|
|
const std::vector<DraggableRegion>& regions) {
|
2016-05-17 06:48:14 +00:00
|
|
|
if (has_frame())
|
2015-10-20 23:33:43 +00:00
|
|
|
return;
|
|
|
|
|
|
|
|
// All ControlRegionViews should be added as children of the WebContentsView,
|
|
|
|
// because WebContentsView will be removed and re-added when entering and
|
|
|
|
// leaving fullscreen mode.
|
2015-06-25 06:54:00 +00:00
|
|
|
NSView* webView = web_contents()->GetNativeView();
|
2015-10-20 23:33:43 +00:00
|
|
|
NSInteger webViewWidth = NSWidth([webView bounds]);
|
|
|
|
NSInteger webViewHeight = NSHeight([webView bounds]);
|
|
|
|
|
|
|
|
[webView setMouseDownCanMoveWindow:YES];
|
|
|
|
|
|
|
|
// Remove all ControlRegionViews that are added last time.
|
|
|
|
// Note that [webView subviews] returns the view's mutable internal array and
|
|
|
|
// it should be copied to avoid mutating the original array while enumerating
|
|
|
|
// it.
|
|
|
|
base::scoped_nsobject<NSArray> subviews([[webView subviews] copy]);
|
|
|
|
for (NSView* subview in subviews.get())
|
|
|
|
if ([subview isKindOfClass:[ControlRegionView class]])
|
|
|
|
[subview removeFromSuperview];
|
|
|
|
|
|
|
|
// Draggable regions is implemented by having the whole web view draggable
|
|
|
|
// (mouseDownCanMoveWindow) and overlaying regions that are not draggable.
|
|
|
|
std::vector<gfx::Rect> system_drag_exclude_areas =
|
|
|
|
CalculateNonDraggableRegions(regions, webViewWidth, webViewHeight);
|
|
|
|
|
|
|
|
// Create and add a ControlRegionView for each region that needs to be
|
|
|
|
// excluded from the dragging.
|
|
|
|
for (std::vector<gfx::Rect>::const_iterator iter =
|
|
|
|
system_drag_exclude_areas.begin();
|
|
|
|
iter != system_drag_exclude_areas.end();
|
|
|
|
++iter) {
|
|
|
|
base::scoped_nsobject<NSView> controlRegion(
|
|
|
|
[[ControlRegionView alloc] initWithFrame:NSZeroRect]);
|
|
|
|
[controlRegion setFrame:NSMakeRect(iter->x(),
|
|
|
|
webViewHeight - iter->bottom(),
|
|
|
|
iter->width(),
|
|
|
|
iter->height())];
|
|
|
|
[webView addSubview:controlRegion];
|
|
|
|
}
|
|
|
|
|
|
|
|
// AppKit will not update its cache of mouseDownCanMoveWindow unless something
|
|
|
|
// changes. Previously we tried adding an NSView and removing it, but for some
|
|
|
|
// reason it required reposting the mouse-down event, and didn't always work.
|
|
|
|
// Calling the below seems to be an effective solution.
|
|
|
|
[window_ setMovableByWindowBackground:NO];
|
|
|
|
[window_ setMovableByWindowBackground:YES];
|
2013-09-05 15:52:29 +00:00
|
|
|
}
|
|
|
|
|
2016-01-23 11:12:19 +00:00
|
|
|
void NativeWindowMac::SetStyleMask(bool on, NSUInteger flag) {
|
|
|
|
bool zoom_button_enabled = IsMaximizable();
|
|
|
|
if (on)
|
|
|
|
[window_ setStyleMask:[window_ styleMask] | flag];
|
|
|
|
else
|
|
|
|
[window_ setStyleMask:[window_ styleMask] & (~flag)];
|
|
|
|
// Change style mask will make the zoom button revert to default, probably
|
|
|
|
// a bug of Cocoa or OS X.
|
|
|
|
if (!zoom_button_enabled)
|
|
|
|
SetMaximizable(false);
|
|
|
|
}
|
|
|
|
|
|
|
|
void NativeWindowMac::SetCollectionBehavior(bool on, NSUInteger flag) {
|
|
|
|
bool zoom_button_enabled = IsMaximizable();
|
|
|
|
if (on)
|
|
|
|
[window_ setCollectionBehavior:[window_ collectionBehavior] | flag];
|
|
|
|
else
|
|
|
|
[window_ setCollectionBehavior:[window_ collectionBehavior] & (~flag)];
|
|
|
|
// Change collectionBehavior will make the zoom button revert to default,
|
|
|
|
// probably a bug of Cocoa or OS X.
|
|
|
|
if (!zoom_button_enabled)
|
|
|
|
SetMaximizable(false);
|
|
|
|
}
|
|
|
|
|
2013-04-12 07:04:46 +00:00
|
|
|
// static
|
2015-06-25 01:47:57 +00:00
|
|
|
NativeWindow* NativeWindow::Create(
|
|
|
|
brightray::InspectableWebContents* inspectable_web_contents,
|
|
|
|
const mate::Dictionary& options) {
|
|
|
|
return new NativeWindowMac(inspectable_web_contents, options);
|
2013-04-12 07:04:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace atom
|