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>
|
|
|
|
|
2014-03-16 00:30:26 +00:00
|
|
|
#import "atom/browser/ui/cocoa/event_processing_window.h"
|
|
|
|
#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"
|
|
|
|
#include "base/strings/sys_string_conversions.h"
|
2013-04-12 12:31:15 +00:00
|
|
|
#include "content/public/browser/native_web_keyboard_event.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"
|
2014-05-15 07:19:02 +00:00
|
|
|
#include "vendor/brightray/browser/inspectable_web_contents.h"
|
|
|
|
#include "vendor/brightray/browser/inspectable_web_contents_view.h"
|
2013-04-12 07:04:46 +00:00
|
|
|
|
2013-09-12 07:13:56 +00:00
|
|
|
static const CGFloat kAtomWindowCornerRadius = 4.0;
|
2013-09-05 15:52:29 +00:00
|
|
|
|
|
|
|
@interface NSView (PrivateMethods)
|
|
|
|
- (CGFloat)roundedCornerRadius;
|
|
|
|
@end
|
|
|
|
|
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_;
|
2014-03-15 11:28:23 +00:00
|
|
|
BOOL acceptsFirstMouse_;
|
2013-05-01 07:42:30 +00:00
|
|
|
}
|
|
|
|
- (id)initWithShell:(atom::NativeWindowMac*)shell;
|
2014-03-15 11:28:23 +00:00
|
|
|
- (void)setAcceptsFirstMouse:(BOOL)accept;
|
2013-05-01 07:42:30 +00:00
|
|
|
@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
|
|
|
acceptsFirstMouse_ = NO;
|
|
|
|
}
|
2013-05-01 07:42:30 +00:00
|
|
|
return self;
|
|
|
|
}
|
|
|
|
|
2014-03-15 11:28:23 +00:00
|
|
|
- (void)setAcceptsFirstMouse:(BOOL)accept {
|
|
|
|
acceptsFirstMouse_ = accept;
|
|
|
|
}
|
|
|
|
|
2014-05-21 17:46:13 +00:00
|
|
|
- (void)windowDidBecomeMain:(NSNotification*)notification {
|
2014-07-25 02:38:19 +00:00
|
|
|
content::WebContents* web_contents = shell_->GetWebContents();
|
|
|
|
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 {
|
2014-07-25 02:38:19 +00:00
|
|
|
content::WebContents* web_contents = shell_->GetWebContents();
|
|
|
|
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
|
|
|
}
|
|
|
|
|
2014-12-23 23:50:42 +00:00
|
|
|
- (void)windowDidResize:(NSNotification*)notification {
|
2013-09-11 10:10:28 +00:00
|
|
|
if (!shell_->has_frame())
|
|
|
|
shell_->ClipWebView();
|
|
|
|
}
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void)windowDidEnterFullScreen:(NSNotification*)notification {
|
|
|
|
shell_->NotifyWindowEnterFullScreen();
|
|
|
|
}
|
|
|
|
|
2014-03-15 11:28:23 +00:00
|
|
|
- (void)windowDidExitFullScreen:(NSNotification*)notification {
|
|
|
|
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();
|
2013-05-01 08:12:00 +00:00
|
|
|
[self autorelease];
|
|
|
|
}
|
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.
|
|
|
|
shell_->CloseWebContents();
|
|
|
|
return NO;
|
2013-05-01 07:42:30 +00:00
|
|
|
}
|
|
|
|
|
2014-03-15 11:28:23 +00:00
|
|
|
- (BOOL)acceptsFirstMouse:(NSEvent*)event {
|
|
|
|
return acceptsFirstMouse_;
|
2013-09-11 05:05:08 +00:00
|
|
|
}
|
|
|
|
|
2013-05-01 07:42:30 +00:00
|
|
|
@end
|
|
|
|
|
2014-01-16 02:09:36 +00:00
|
|
|
@interface AtomNSWindow : EventProcessingWindow {
|
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
|
|
|
}
|
|
|
|
- (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;
|
|
|
|
}
|
|
|
|
|
2014-08-11 02:24:36 +00:00
|
|
|
// Enable the window to be larger than screen.
|
|
|
|
- (NSRect)constrainFrameRect:(NSRect)frameRect toScreen:(NSScreen*)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
|
|
|
}
|
|
|
|
|
2013-05-15 12:24:51 +00:00
|
|
|
- (IBAction)reload:(id)sender {
|
2014-10-19 08:27:50 +00:00
|
|
|
content::WebContents* web_contents = shell_->GetWebContents();
|
|
|
|
content::NavigationController::LoadURLParams params(web_contents->GetURL());
|
|
|
|
web_contents->GetController().LoadURLWithParams(params);
|
2013-05-15 12:24:51 +00:00
|
|
|
}
|
|
|
|
|
2013-04-12 07:53:29 +00:00
|
|
|
- (IBAction)showDevTools:(id)sender {
|
2013-05-10 12:54:55 +00:00
|
|
|
shell_->OpenDevTools();
|
2013-04-12 07:53:29 +00:00
|
|
|
}
|
|
|
|
|
2014-08-17 03:26:02 +00:00
|
|
|
// Returns an empty array for AXChildren attribute, this will force the
|
|
|
|
// SpeechSynthesisServer to use its classical way of speaking the selected text:
|
|
|
|
// by invoking the "Command+C" for current application and then speak out
|
|
|
|
// what's in the clipboard. Otherwise the "Text to Speech" would always speak
|
|
|
|
// out window's title.
|
|
|
|
// This behavior is taken by both FireFox and Chrome, see also FireFox's bug on
|
|
|
|
// more of how SpeechSynthesisServer chose which text to read:
|
|
|
|
// https://bugzilla.mozilla.org/show_bug.cgi?id=674612
|
|
|
|
- (id)accessibilityAttributeValue:(NSString*)attribute {
|
|
|
|
if ([attribute isEqualToString:@"AXChildren"])
|
|
|
|
return [NSArray array];
|
|
|
|
return [super accessibilityAttributeValue:attribute];
|
|
|
|
}
|
|
|
|
|
2013-04-12 07:53:29 +00:00
|
|
|
@end
|
|
|
|
|
2013-09-05 15:52:29 +00:00
|
|
|
@interface ControlRegionView : NSView {
|
|
|
|
@private
|
|
|
|
atom::NativeWindowMac* shellWindow_; // Weak; owns self.
|
|
|
|
}
|
|
|
|
@end
|
|
|
|
|
|
|
|
@implementation ControlRegionView
|
|
|
|
|
|
|
|
- (id)initWithShellWindow:(atom::NativeWindowMac*)shellWindow {
|
|
|
|
if ((self = [super init]))
|
|
|
|
shellWindow_ = shellWindow;
|
|
|
|
return self;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (BOOL)mouseDownCanMoveWindow {
|
|
|
|
return NO;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (NSView*)hitTest:(NSPoint)aPoint {
|
2013-09-06 03:54:52 +00:00
|
|
|
if (!shellWindow_->IsWithinDraggableRegion(aPoint)) {
|
2013-09-05 15:52:29 +00:00
|
|
|
return nil;
|
|
|
|
}
|
|
|
|
return self;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void)mouseDown:(NSEvent*)event {
|
|
|
|
shellWindow_->HandleMouseEvent(event);
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void)mouseDragged:(NSEvent*)event {
|
|
|
|
shellWindow_->HandleMouseEvent(event);
|
|
|
|
}
|
|
|
|
|
|
|
|
@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 {
|
|
|
|
|
2014-12-23 23:50:42 +00:00
|
|
|
namespace {
|
|
|
|
|
|
|
|
// Convert draggable regions in raw format to SkRegion format. Caller is
|
|
|
|
// responsible for deleting the returned SkRegion instance.
|
|
|
|
SkRegion* DraggableRegionsToSkRegion(
|
|
|
|
const std::vector<DraggableRegion>& regions) {
|
|
|
|
SkRegion* sk_region = new SkRegion;
|
|
|
|
for (std::vector<DraggableRegion>::const_iterator iter = regions.begin();
|
|
|
|
iter != regions.end();
|
|
|
|
++iter) {
|
|
|
|
const DraggableRegion& region = *iter;
|
|
|
|
sk_region->op(
|
|
|
|
region.bounds.x(),
|
|
|
|
region.bounds.y(),
|
|
|
|
region.bounds.right(),
|
|
|
|
region.bounds.bottom(),
|
|
|
|
region.draggable ? SkRegion::kUnion_Op : SkRegion::kDifference_Op);
|
|
|
|
}
|
|
|
|
return sk_region;
|
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace
|
|
|
|
|
2013-04-20 05:42:39 +00:00
|
|
|
NativeWindowMac::NativeWindowMac(content::WebContents* web_contents,
|
2014-06-23 13:51:42 +00:00
|
|
|
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),
|
2013-09-06 03:54:52 +00:00
|
|
|
attention_request_id_(0) {
|
2014-01-06 10:58:30 +00:00
|
|
|
int width = 800, height = 600;
|
2014-06-23 13:51:42 +00:00
|
|
|
options.Get(switches::kWidth, &width);
|
|
|
|
options.Get(switches::kHeight, &height);
|
2013-04-12 07:04:46 +00:00
|
|
|
|
|
|
|
NSRect main_screen_rect = [[[NSScreen screens] objectAtIndex:0] frame];
|
|
|
|
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
|
|
|
|
2014-12-23 20:31:27 +00:00
|
|
|
AtomNSWindow* atomWindow = [[AtomNSWindow alloc]
|
2013-09-12 15:20:38 +00:00
|
|
|
initWithContentRect:cocoa_bounds
|
|
|
|
styleMask:NSTitledWindowMask | NSClosableWindowMask |
|
2013-09-25 08:18:33 +00:00
|
|
|
NSMiniaturizableWindowMask | NSResizableWindowMask |
|
|
|
|
NSTexturedBackgroundWindowMask
|
2013-09-12 15:20:38 +00:00
|
|
|
backing:NSBackingStoreBuffered
|
|
|
|
defer:YES];
|
2013-09-11 10:10:28 +00:00
|
|
|
|
|
|
|
[atomWindow setShell:this];
|
2014-08-17 04:23:00 +00:00
|
|
|
[atomWindow setEnableLargerThanScreen:enable_larger_than_screen_];
|
2014-04-11 04:47:22 +00:00
|
|
|
window_.reset(atomWindow);
|
2013-09-11 10:10:28 +00:00
|
|
|
|
2014-03-15 11:28:23 +00:00
|
|
|
AtomNSWindowDelegate* delegate =
|
|
|
|
[[AtomNSWindowDelegate alloc] initWithShell:this];
|
2014-04-11 04:45:48 +00:00
|
|
|
[window_ setDelegate:delegate];
|
2014-03-15 11:28:23 +00:00
|
|
|
|
2014-12-23 19:17:56 +00:00
|
|
|
if (transparent_) {
|
|
|
|
// Make window has transparent background.
|
|
|
|
[window_ setOpaque:NO];
|
|
|
|
[window_ setHasShadow:NO];
|
|
|
|
[window_ setBackgroundColor:[NSColor clearColor]];
|
|
|
|
}
|
|
|
|
|
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
|
|
|
|
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;
|
2014-06-23 13:51:42 +00:00
|
|
|
options.Get(switches::kUseContentSize, &use_content_size);
|
2014-05-15 07:19:02 +00:00
|
|
|
if (has_frame_ && !use_content_size)
|
|
|
|
SetSize(gfx::Size(width, height));
|
|
|
|
|
2014-03-15 11:28:23 +00:00
|
|
|
// Enable the NSView to accept first mouse event.
|
|
|
|
bool acceptsFirstMouse = false;
|
2014-06-23 13:51:42 +00:00
|
|
|
options.Get(switches::kAcceptFirstMouse, &acceptsFirstMouse);
|
2014-03-15 11:28:23 +00:00
|
|
|
[delegate setAcceptsFirstMouse:acceptsFirstMouse];
|
2013-04-12 07:04:46 +00:00
|
|
|
|
|
|
|
// Disable fullscreen button when 'fullscreen' is specified to false.
|
|
|
|
bool fullscreen;
|
2014-06-23 13:51:42 +00:00
|
|
|
if (!(options.Get(switches::kFullscreen, &fullscreen) &&
|
2013-04-12 07:04:46 +00:00
|
|
|
!fullscreen)) {
|
2014-04-11 04:45:48 +00:00
|
|
|
NSUInteger collectionBehavior = [window_ collectionBehavior];
|
2013-04-12 07:04:46 +00:00
|
|
|
collectionBehavior |= NSWindowCollectionBehaviorFullScreenPrimary;
|
2014-04-11 04:45:48 +00:00
|
|
|
[window_ setCollectionBehavior:collectionBehavior];
|
2013-04-12 07:04:46 +00:00
|
|
|
}
|
|
|
|
|
2013-09-05 15:52:29 +00:00
|
|
|
NSView* view = inspectable_web_contents()->GetView()->GetNativeView();
|
|
|
|
[view setAutoresizingMask:NSViewWidthSizable | NSViewHeightSizable];
|
|
|
|
|
2013-04-12 07:04:46 +00:00
|
|
|
InstallView();
|
|
|
|
}
|
|
|
|
|
|
|
|
NativeWindowMac::~NativeWindowMac() {
|
2014-04-11 04:32:42 +00:00
|
|
|
// Force InspectableWebContents to be destroyed before we destroy window,
|
|
|
|
// because it may still be observing the window at this time.
|
2014-04-11 10:43:01 +00:00
|
|
|
DestroyWebContents();
|
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::Move(const gfx::Rect& pos) {
|
|
|
|
NSRect cocoa_bounds = NSMakeRect(pos.x(), 0,
|
|
|
|
pos.width(),
|
|
|
|
pos.height());
|
|
|
|
// Flip coordinates based on the primary screen.
|
|
|
|
NSScreen* screen = [[NSScreen screens] objectAtIndex:0];
|
|
|
|
cocoa_bounds.origin.y =
|
|
|
|
NSHeight([screen frame]) - pos.height() - pos.y();
|
|
|
|
|
2014-04-11 04:45:48 +00:00
|
|
|
[window_ setFrame:cocoa_bounds display:YES];
|
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() {
|
2014-04-11 04:45:48 +00:00
|
|
|
[window_ zoom:nil];
|
2013-04-12 07:04:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void NativeWindowMac::Unmaximize() {
|
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() {
|
2014-05-14 21:58:49 +00:00
|
|
|
return [window_ isZoomed];
|
|
|
|
}
|
|
|
|
|
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
|
|
|
}
|
|
|
|
|
|
|
|
bool NativeWindowMac::IsFullscreen() {
|
2014-04-11 04:45:48 +00:00
|
|
|
return [window_ styleMask] & NSFullScreenWindowMask;
|
2013-04-12 07:04:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void NativeWindowMac::SetSize(const gfx::Size& size) {
|
|
|
|
NSRect frame = [window_ frame];
|
|
|
|
frame.origin.y -= size.height() - frame.size.height;
|
|
|
|
frame.size.width = size.width();
|
|
|
|
frame.size.height = size.height();
|
|
|
|
|
2014-04-11 04:45:48 +00:00
|
|
|
[window_ setFrame:frame display:YES];
|
2013-04-12 07:04:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
gfx::Size NativeWindowMac::GetSize() {
|
|
|
|
NSRect frame = [window_ frame];
|
|
|
|
return gfx::Size(frame.size.width, frame.size.height);
|
|
|
|
}
|
|
|
|
|
2014-05-15 08:05:35 +00:00
|
|
|
void NativeWindowMac::SetContentSize(const gfx::Size& size) {
|
|
|
|
NSRect frame_nsrect = [window_ frame];
|
|
|
|
NSSize frame = frame_nsrect.size;
|
|
|
|
NSSize content = [window_ contentRectForFrameRect:frame_nsrect].size;
|
|
|
|
|
|
|
|
int width = size.width() + frame.width - content.width;
|
|
|
|
int height = size.height() + frame.height - content.height;
|
|
|
|
frame_nsrect.origin.y -= height - frame_nsrect.size.height;
|
|
|
|
frame_nsrect.size.width = width;
|
|
|
|
frame_nsrect.size.height = height;
|
|
|
|
[window_ setFrame:frame_nsrect display:YES];
|
|
|
|
}
|
|
|
|
|
2014-05-15 07:30:04 +00:00
|
|
|
gfx::Size NativeWindowMac::GetContentSize() {
|
|
|
|
NSRect bounds = [[window_ contentView] bounds];
|
|
|
|
return gfx::Size(bounds.size.width, bounds.size.height);
|
|
|
|
}
|
|
|
|
|
2013-04-17 14:49:49 +00:00
|
|
|
void NativeWindowMac::SetMinimumSize(const gfx::Size& size) {
|
|
|
|
NSSize min_size = NSMakeSize(size.width(), size.height());
|
2014-04-11 04:45:48 +00:00
|
|
|
NSView* content = [window_ contentView];
|
|
|
|
[window_ setContentMinSize:[content convertSize:min_size toView:nil]];
|
2013-04-12 07:04:46 +00:00
|
|
|
}
|
|
|
|
|
2013-04-18 07:38:04 +00:00
|
|
|
gfx::Size NativeWindowMac::GetMinimumSize() {
|
2014-04-11 04:45:48 +00:00
|
|
|
NSView* content = [window_ contentView];
|
|
|
|
NSSize min_size = [content convertSize:[window_ contentMinSize]
|
2013-04-18 07:38:04 +00:00
|
|
|
fromView:nil];
|
|
|
|
return gfx::Size(min_size.width, min_size.height);
|
|
|
|
}
|
|
|
|
|
2013-04-17 14:49:49 +00:00
|
|
|
void NativeWindowMac::SetMaximumSize(const gfx::Size& size) {
|
|
|
|
NSSize max_size = NSMakeSize(size.width(), size.height());
|
2014-04-11 04:45:48 +00:00
|
|
|
NSView* content = [window_ contentView];
|
|
|
|
[window_ setContentMaxSize:[content convertSize:max_size toView:nil]];
|
2013-04-12 07:04:46 +00:00
|
|
|
}
|
|
|
|
|
2013-04-18 07:38:04 +00:00
|
|
|
gfx::Size NativeWindowMac::GetMaximumSize() {
|
2014-04-11 04:45:48 +00:00
|
|
|
NSView* content = [window_ contentView];
|
|
|
|
NSSize max_size = [content convertSize:[window_ contentMaxSize]
|
2013-04-18 07:38:04 +00:00
|
|
|
fromView:nil];
|
|
|
|
return gfx::Size(max_size.width, max_size.height);
|
|
|
|
}
|
|
|
|
|
2013-04-12 07:04:46 +00:00
|
|
|
void NativeWindowMac::SetResizable(bool resizable) {
|
|
|
|
if (resizable) {
|
2014-04-11 04:45:48 +00:00
|
|
|
[[window_ standardWindowButton:NSWindowZoomButton] setEnabled:YES];
|
2014-04-11 04:47:22 +00:00
|
|
|
[window_ setStyleMask:[window_ styleMask] | NSResizableWindowMask];
|
2013-04-12 07:04:46 +00:00
|
|
|
} else {
|
2014-04-11 04:45:48 +00:00
|
|
|
[[window_ standardWindowButton:NSWindowZoomButton] setEnabled:NO];
|
2014-04-11 04:47:22 +00:00
|
|
|
[window_ setStyleMask:[window_ styleMask] ^ 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
|
|
|
}
|
|
|
|
|
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::SetPosition(const gfx::Point& position) {
|
|
|
|
Move(gfx::Rect(position, GetSize()));
|
|
|
|
}
|
|
|
|
|
|
|
|
gfx::Point NativeWindowMac::GetPosition() {
|
|
|
|
NSRect frame = [window_ frame];
|
|
|
|
NSScreen* screen = [[NSScreen screens] objectAtIndex:0];
|
|
|
|
|
|
|
|
return gfx::Point(frame.origin.x,
|
|
|
|
NSHeight([screen frame]) - frame.origin.y - frame.size.height);
|
|
|
|
}
|
|
|
|
|
|
|
|
void NativeWindowMac::SetTitle(const std::string& title) {
|
2014-12-23 19:48:20 +00:00
|
|
|
// We don't want the title to show in transparent window.
|
|
|
|
if (transparent_)
|
|
|
|
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_;
|
|
|
|
}
|
|
|
|
|
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];
|
|
|
|
}
|
|
|
|
|
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
|
|
|
}
|
|
|
|
|
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() {
|
|
|
|
content::WebContents* web_contents = GetWebContents();
|
2014-12-19 20:48:53 +00:00
|
|
|
if (!web_contents)
|
|
|
|
return;
|
2014-12-18 23:40:35 +00:00
|
|
|
content::RenderWidgetHostView* rwhv = web_contents->GetRenderWidgetHostView();
|
|
|
|
if (!rwhv)
|
|
|
|
return;
|
|
|
|
rwhv->ShowDefinitionForSelection();
|
|
|
|
}
|
|
|
|
|
2013-09-06 03:54:52 +00:00
|
|
|
bool NativeWindowMac::IsWithinDraggableRegion(NSPoint point) const {
|
|
|
|
if (!draggable_region_)
|
|
|
|
return false;
|
2014-12-23 20:31:27 +00:00
|
|
|
content::WebContents* web_contents = GetWebContents();
|
|
|
|
if (!web_contents)
|
|
|
|
return false;
|
|
|
|
NSView* webView = web_contents->GetNativeView();
|
2013-09-06 03:54:52 +00:00
|
|
|
NSInteger webViewHeight = NSHeight([webView bounds]);
|
|
|
|
// |draggable_region_| is stored in local platform-indepdent coordiate system
|
|
|
|
// while |point| is in local Cocoa coordinate system. Do the conversion
|
|
|
|
// to match these two.
|
|
|
|
return draggable_region_->contains(point.x, webViewHeight - point.y);
|
|
|
|
}
|
|
|
|
|
2013-09-05 15:52:29 +00:00
|
|
|
void NativeWindowMac::HandleMouseEvent(NSEvent* event) {
|
2014-10-25 03:06:39 +00:00
|
|
|
NSPoint eventLoc = [event locationInWindow];
|
|
|
|
NSRect mouseRect = [window_ convertRectToScreen:NSMakeRect(eventLoc.x, eventLoc.y, 0, 0)];
|
|
|
|
NSPoint current_mouse_location = mouseRect.origin;
|
|
|
|
|
2013-09-05 15:52:29 +00:00
|
|
|
if ([event type] == NSLeftMouseDown) {
|
2014-04-11 04:45:48 +00:00
|
|
|
NSPoint frame_origin = [window_ frame].origin;
|
2013-09-06 04:12:17 +00:00
|
|
|
last_mouse_offset_ = NSMakePoint(
|
|
|
|
frame_origin.x - current_mouse_location.x,
|
|
|
|
frame_origin.y - current_mouse_location.y);
|
|
|
|
} else if ([event type] == NSLeftMouseDragged) {
|
2014-04-11 04:45:48 +00:00
|
|
|
[window_ setFrameOrigin:NSMakePoint(
|
2013-09-06 04:12:17 +00:00
|
|
|
current_mouse_location.x + last_mouse_offset_.x,
|
|
|
|
current_mouse_location.y + last_mouse_offset_.y)];
|
2013-09-05 15:52:29 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-09-05 12:06:54 +00:00
|
|
|
void NativeWindowMac::UpdateDraggableRegions(
|
|
|
|
const std::vector<DraggableRegion>& regions) {
|
2013-09-05 15:52:29 +00:00
|
|
|
// Draggable region is not supported for non-frameless window.
|
|
|
|
if (has_frame_)
|
|
|
|
return;
|
|
|
|
|
2014-12-23 23:50:42 +00:00
|
|
|
draggable_region_.reset(DraggableRegionsToSkRegion(regions));
|
2013-09-05 12:06:54 +00:00
|
|
|
}
|
|
|
|
|
2013-04-12 12:31:15 +00:00
|
|
|
void NativeWindowMac::HandleKeyboardEvent(
|
|
|
|
content::WebContents*,
|
|
|
|
const content::NativeWebKeyboardEvent& event) {
|
|
|
|
if (event.skip_in_browser ||
|
|
|
|
event.type == content::NativeWebKeyboardEvent::Char)
|
|
|
|
return;
|
|
|
|
|
2014-06-17 08:33:52 +00:00
|
|
|
if (event.os_event.window == window_) {
|
|
|
|
EventProcessingWindow* event_window =
|
|
|
|
static_cast<EventProcessingWindow*>(window_);
|
|
|
|
DCHECK([event_window isKindOfClass:[EventProcessingWindow class]]);
|
|
|
|
[event_window redispatchKeyEvent:event.os_event];
|
|
|
|
} else {
|
|
|
|
// The event comes from detached devtools view, and it has already been
|
|
|
|
// handled by the devtools itself, we now send it to application menu to
|
|
|
|
// make menu acclerators work.
|
2014-07-25 03:03:25 +00:00
|
|
|
BOOL handled = [[NSApp mainMenu] performKeyEquivalent:event.os_event];
|
|
|
|
// Handle the cmd+~ shortcut.
|
|
|
|
if (!handled && (event.os_event.modifierFlags & NSCommandKeyMask) &&
|
|
|
|
(event.os_event.keyCode == 50 /* ~ key */))
|
|
|
|
Focus(true);
|
2014-06-17 08:33:52 +00:00
|
|
|
}
|
2013-04-12 12:31:15 +00:00
|
|
|
}
|
|
|
|
|
2013-04-12 07:04:46 +00:00
|
|
|
void NativeWindowMac::InstallView() {
|
2013-04-12 08:41:15 +00:00
|
|
|
NSView* view = inspectable_web_contents()->GetView()->GetNativeView();
|
2013-09-05 15:52:29 +00:00
|
|
|
if (has_frame_) {
|
2014-07-02 08:38:11 +00:00
|
|
|
// Add layer with white background for the contents view.
|
|
|
|
base::scoped_nsobject<CALayer> layer([[CALayer alloc] init]);
|
|
|
|
[layer setBackgroundColor:CGColorGetConstantColor(kCGColorWhite)];
|
|
|
|
[view setLayer:layer];
|
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 {
|
2014-12-11 22:25:51 +00:00
|
|
|
if (base::mac::IsOSYosemiteOrLater()) {
|
|
|
|
// 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];
|
|
|
|
} else {
|
|
|
|
NSView* frameView = [[window_ contentView] superview];
|
|
|
|
[view setFrame:[frameView bounds]];
|
|
|
|
[frameView addSubview:view];
|
|
|
|
}
|
2013-09-11 20:23:17 +00:00
|
|
|
|
2013-09-11 10:10:28 +00:00
|
|
|
ClipWebView();
|
2014-12-23 23:50:42 +00:00
|
|
|
InstallDraggableRegionView();
|
2013-09-11 10:10:28 +00:00
|
|
|
|
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];
|
|
|
|
}
|
|
|
|
|
2013-09-11 10:10:28 +00:00
|
|
|
void NativeWindowMac::ClipWebView() {
|
2014-07-28 07:29:51 +00:00
|
|
|
NSView* webView = GetWebContents()->GetNativeView();
|
2014-12-23 23:50:42 +00:00
|
|
|
webView.layer.masksToBounds = YES;
|
|
|
|
webView.layer.cornerRadius = kAtomWindowCornerRadius;
|
2013-09-05 15:52:29 +00:00
|
|
|
}
|
|
|
|
|
2014-12-23 23:50:42 +00:00
|
|
|
void NativeWindowMac::InstallDraggableRegionView() {
|
|
|
|
NSView* webView = GetWebContents()->GetNativeView();
|
|
|
|
base::scoped_nsobject<NSView> controlRegion(
|
|
|
|
[[ControlRegionView alloc] initWithShellWindow:this]);
|
|
|
|
[controlRegion setFrame:NSMakeRect(0, 0,
|
|
|
|
NSWidth([webView bounds]),
|
|
|
|
NSHeight([webView bounds]))];
|
|
|
|
[webView addSubview:controlRegion];
|
2013-09-05 15:52:29 +00:00
|
|
|
}
|
|
|
|
|
2013-04-12 07:04:46 +00:00
|
|
|
// static
|
2013-04-20 05:42:39 +00:00
|
|
|
NativeWindow* NativeWindow::Create(content::WebContents* web_contents,
|
2014-06-23 13:51:42 +00:00
|
|
|
const mate::Dictionary& options) {
|
2013-04-20 05:42:39 +00:00
|
|
|
return new NativeWindowMac(web_contents, options);
|
2013-04-12 07:04:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace atom
|