| 
									
										
										
										
											2014-10-31 11:17:05 -07:00
										 |  |  | // Copyright (c) 2013 GitHub, Inc. | 
					
						
							| 
									
										
										
										
											2014-04-25 17:49:37 +08:00
										 |  |  | // Use of this source code is governed by the MIT license that can be | 
					
						
							| 
									
										
										
										
											2013-04-12 15:04:46 +08:00
										 |  |  | // found in the LICENSE file. | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-03-16 08:30:26 +08:00
										 |  |  | #include "atom/browser/native_window_mac.h" | 
					
						
							| 
									
										
										
										
											2013-04-12 15:04:46 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-10-12 17:21:56 -07:00
										 |  |  | #include <Quartz/Quartz.h> | 
					
						
							| 
									
										
										
										
											2016-10-26 09:55:34 +09:00
										 |  |  | #include <string> | 
					
						
							| 
									
										
										
										
											2013-04-16 00:25:08 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-05-25 19:25:51 -04:00
										 |  |  | #include "atom/browser/window_list.h" | 
					
						
							| 
									
										
										
										
											2016-04-02 20:35:57 +09:00
										 |  |  | #include "atom/common/color_util.h" | 
					
						
							| 
									
										
										
										
											2014-03-16 08:30:26 +08:00
										 |  |  | #include "atom/common/draggable_region.h" | 
					
						
							|  |  |  | #include "atom/common/options_switches.h" | 
					
						
							| 
									
										
										
										
											2014-05-15 15:19:02 +08:00
										 |  |  | #include "base/mac/mac_util.h" | 
					
						
							| 
									
										
										
										
											2016-04-03 11:59:21 +09:00
										 |  |  | #include "base/mac/scoped_cftyperef.h" | 
					
						
							| 
									
										
										
										
											2014-05-15 15:19:02 +08:00
										 |  |  | #include "base/strings/sys_string_conversions.h" | 
					
						
							| 
									
										
										
										
											2015-05-04 12:06:03 +08:00
										 |  |  | #include "brightray/browser/inspectable_web_contents.h" | 
					
						
							|  |  |  | #include "brightray/browser/inspectable_web_contents_view.h" | 
					
						
							| 
									
										
										
										
											2016-06-17 10:58:04 -07:00
										 |  |  | #include "brightray/browser/mac/event_dispatching_window.h" | 
					
						
							| 
									
										
										
										
											2015-04-13 20:10:51 +08:00
										 |  |  | #include "content/public/browser/browser_accessibility_state.h" | 
					
						
							| 
									
										
										
										
											2013-04-12 15:04:46 +08:00
										 |  |  | #include "content/public/browser/web_contents.h" | 
					
						
							| 
									
										
										
										
											2013-05-24 17:51:15 +08:00
										 |  |  | #include "content/public/browser/render_view_host.h" | 
					
						
							| 
									
										
										
										
											2014-07-24 13:53:29 +08:00
										 |  |  | #include "content/public/browser/render_widget_host_view.h" | 
					
						
							| 
									
										
										
										
											2014-06-23 21:51:42 +08:00
										 |  |  | #include "native_mate/dictionary.h" | 
					
						
							| 
									
										
										
										
											2016-04-02 21:17:38 +09:00
										 |  |  | #include "skia/ext/skia_utils_mac.h" | 
					
						
							| 
									
										
										
										
											2016-09-06 17:24:37 +09:00
										 |  |  | #include "third_party/skia/include/core/SkRegion.h" | 
					
						
							| 
									
										
										
										
											2015-10-21 07:33:43 +08:00
										 |  |  | #include "ui/gfx/skia_util.h" | 
					
						
							| 
									
										
										
										
											2013-04-12 15:04:46 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-08-05 14:12:55 +08: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 23:52:29 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-12-11 14:25:51 -08: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 15:42:30 +08:00
										 |  |  | @interface AtomNSWindowDelegate : NSObject<NSWindowDelegate> { | 
					
						
							|  |  |  |  @private | 
					
						
							|  |  |  |   atom::NativeWindowMac* shell_; | 
					
						
							| 
									
										
										
										
											2016-06-22 14:06:54 +09:00
										 |  |  |   bool is_zooming_; | 
					
						
							| 
									
										
										
										
											2013-05-01 15:42:30 +08:00
										 |  |  | } | 
					
						
							|  |  |  | - (id)initWithShell:(atom::NativeWindowMac*)shell; | 
					
						
							|  |  |  | @end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | @implementation AtomNSWindowDelegate | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | - (id)initWithShell:(atom::NativeWindowMac*)shell { | 
					
						
							| 
									
										
										
										
											2014-03-15 19:28:23 +08:00
										 |  |  |   if ((self = [super init])) { | 
					
						
							| 
									
										
										
										
											2013-05-01 15:42:30 +08:00
										 |  |  |     shell_ = shell; | 
					
						
							| 
									
										
										
										
											2016-06-22 14:06:54 +09:00
										 |  |  |     is_zooming_ = false; | 
					
						
							| 
									
										
										
										
											2014-03-15 19:28:23 +08:00
										 |  |  |   } | 
					
						
							| 
									
										
										
										
											2013-05-01 15:42:30 +08:00
										 |  |  |   return self; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-03-08 11:11:17 -08: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(); | 
					
						
							|  |  |  |    } | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-10-26 12:12:12 +09:00
										 |  |  | // Called when the user clicks the zoom button or selects it from the Window | 
					
						
							| 
									
										
										
										
											2016-10-27 11:49:13 -07:00
										 |  |  | // menu to determine the "standard size" of the window. | 
					
						
							| 
									
										
										
										
											2016-10-26 12:12:12 +09:00
										 |  |  | - (NSRect)windowWillUseStandardFrame:(NSWindow*)window | 
					
						
							|  |  |  |                         defaultFrame:(NSRect)frame { | 
					
						
							| 
									
										
										
										
											2016-10-27 11:29:51 -07:00
										 |  |  |   if (!shell_->zoom_to_page_width()) | 
					
						
							| 
									
										
										
										
											2016-10-26 12:12:12 +09:00
										 |  |  |     return frame; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   // If the shift key is down, maximize. | 
					
						
							|  |  |  |   if ([[NSApp currentEvent] modifierFlags] & NSShiftKeyMask) | 
					
						
							|  |  |  |     return frame; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   content::WebContents* web_contents = shell_->web_contents(); | 
					
						
							| 
									
										
										
										
											2016-10-27 11:49:13 -07:00
										 |  |  |   if (!web_contents) | 
					
						
							|  |  |  |     return frame; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-10-27 12:13:45 -07:00
										 |  |  |   CGFloat page_width = static_cast<CGFloat>( | 
					
						
							| 
									
										
										
										
											2016-10-27 11:49:13 -07:00
										 |  |  |       web_contents->GetPreferredSize().width()); | 
					
						
							| 
									
										
										
										
											2016-10-27 12:13:45 -07:00
										 |  |  |   NSRect window_frame = [window frame]; | 
					
						
							| 
									
										
										
										
											2016-10-26 12:12:12 +09:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-10-27 11:49:13 -07:00
										 |  |  |   // Never shrink from the current size on zoom. | 
					
						
							| 
									
										
										
										
											2016-10-27 12:13:45 -07:00
										 |  |  |   CGFloat zoomed_width = std::max(page_width, NSWidth(window_frame)); | 
					
						
							| 
									
										
										
										
											2016-10-26 12:12:12 +09:00
										 |  |  | 
 | 
					
						
							|  |  |  |   // |frame| determines our maximum extents. We need to set the origin of the | 
					
						
							|  |  |  |   // frame -- and only move it left if necessary. | 
					
						
							| 
									
										
										
										
											2016-10-27 12:13:45 -07:00
										 |  |  |   if (window_frame.origin.x + zoomed_width > NSMaxX(frame)) | 
					
						
							|  |  |  |     frame.origin.x = NSMaxX(frame) - zoomed_width; | 
					
						
							| 
									
										
										
										
											2016-10-26 12:12:12 +09:00
										 |  |  |   else | 
					
						
							| 
									
										
										
										
											2016-10-27 12:13:45 -07:00
										 |  |  |     frame.origin.x = window_frame.origin.x; | 
					
						
							| 
									
										
										
										
											2016-10-26 12:12:12 +09:00
										 |  |  | 
 | 
					
						
							|  |  |  |   // Set the width. Don't touch y or height. | 
					
						
							| 
									
										
										
										
											2016-10-27 12:13:45 -07:00
										 |  |  |   frame.size.width = zoomed_width; | 
					
						
							| 
									
										
										
										
											2016-10-26 12:12:12 +09:00
										 |  |  | 
 | 
					
						
							|  |  |  |   return frame; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-05-21 13:46:13 -04:00
										 |  |  | - (void)windowDidBecomeMain:(NSNotification*)notification { | 
					
						
							| 
									
										
										
										
											2015-06-25 14:54:00 +08:00
										 |  |  |   content::WebContents* web_contents = shell_->web_contents(); | 
					
						
							| 
									
										
										
										
											2014-07-25 10:38:19 +08:00
										 |  |  |   if (!web_contents) | 
					
						
							|  |  |  |     return; | 
					
						
							| 
									
										
										
										
											2014-07-24 13:53:29 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-07-28 15:29:51 +08:00
										 |  |  |   web_contents->RestoreFocus(); | 
					
						
							| 
									
										
										
										
											2014-07-25 10:38:19 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  |   content::RenderWidgetHostView* rwhv = web_contents->GetRenderWidgetHostView(); | 
					
						
							| 
									
										
										
										
											2014-07-24 13:53:29 +08:00
										 |  |  |   if (rwhv) | 
					
						
							|  |  |  |     rwhv->SetActive(true); | 
					
						
							| 
									
										
										
										
											2014-07-31 17:35:08 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  |   shell_->NotifyWindowFocus(); | 
					
						
							| 
									
										
										
										
											2014-05-21 13:46:13 -04:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-05-24 18:15:27 +08:00
										 |  |  | - (void)windowDidResignMain:(NSNotification*)notification { | 
					
						
							| 
									
										
										
										
											2015-06-25 14:54:00 +08:00
										 |  |  |   content::WebContents* web_contents = shell_->web_contents(); | 
					
						
							| 
									
										
										
										
											2014-07-25 10:38:19 +08:00
										 |  |  |   if (!web_contents) | 
					
						
							|  |  |  |     return; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-07-28 15:29:51 +08:00
										 |  |  |   web_contents->StoreFocus(); | 
					
						
							| 
									
										
										
										
											2014-07-24 13:53:29 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-07-25 10:38:19 +08:00
										 |  |  |   content::RenderWidgetHostView* rwhv = web_contents->GetRenderWidgetHostView(); | 
					
						
							| 
									
										
										
										
											2014-07-24 13:53:29 +08:00
										 |  |  |   if (rwhv) | 
					
						
							|  |  |  |     rwhv->SetActive(false); | 
					
						
							| 
									
										
										
										
											2014-07-31 17:35:08 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  |   shell_->NotifyWindowBlur(); | 
					
						
							| 
									
										
										
										
											2013-05-24 17:51:15 +08:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-07-23 10:07:58 +08:00
										 |  |  | - (NSSize)windowWillResize:(NSWindow*)sender toSize:(NSSize)frameSize { | 
					
						
							| 
									
										
										
										
											2015-07-16 13:54:51 -04:00
										 |  |  |   NSSize newSize = frameSize; | 
					
						
							| 
									
										
										
										
											2015-07-22 10:23:31 -04:00
										 |  |  |   double aspectRatio = shell_->GetAspectRatio(); | 
					
						
							| 
									
										
										
										
											2015-07-16 13:54:51 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-07-22 10:23:31 -04:00
										 |  |  |   if (aspectRatio > 0.0) { | 
					
						
							| 
									
										
										
										
											2015-07-23 10:07:58 +08: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); | 
					
						
							| 
									
										
										
										
											2016-05-22 15:43:47 -07:00
										 |  |  |     newSize.height = | 
					
						
							|  |  |  |         roundf((newSize.width - extraWidthPlusFrame) / aspectRatio + | 
					
						
							|  |  |  |                extraHeightPlusFrame); | 
					
						
							| 
									
										
										
										
											2015-07-16 13:54:51 -04:00
										 |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   return newSize; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-12-23 15:50:42 -08:00
										 |  |  | - (void)windowDidResize:(NSNotification*)notification { | 
					
						
							| 
									
										
										
										
											2015-10-21 07:33:43 +08:00
										 |  |  |   shell_->UpdateDraggableRegionViews(); | 
					
						
							| 
									
										
										
										
											2015-05-09 21:25:10 +05:30
										 |  |  |   shell_->NotifyWindowResize(); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | - (void)windowDidMove:(NSNotification*)notification { | 
					
						
							| 
									
										
										
										
											2015-05-20 14:07:13 +05:30
										 |  |  |   // TODO(zcbenz): Remove the alias after figuring out a proper | 
					
						
							| 
									
										
										
										
											2016-08-15 13:14:19 -07:00
										 |  |  |   // way to dispatch move. | 
					
						
							| 
									
										
										
										
											2015-05-09 21:25:10 +05:30
										 |  |  |   shell_->NotifyWindowMove(); | 
					
						
							| 
									
										
										
										
											2015-05-20 14:07:13 +05:30
										 |  |  |   shell_->NotifyWindowMoved(); | 
					
						
							| 
									
										
										
										
											2013-09-11 18:10:28 +08:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-11-25 13:16:51 +08:00
										 |  |  | - (void)windowDidMiniaturize:(NSNotification*)notification { | 
					
						
							|  |  |  |   shell_->NotifyWindowMinimize(); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | - (void)windowDidDeminiaturize:(NSNotification*)notification { | 
					
						
							|  |  |  |   shell_->NotifyWindowRestore(); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | - (BOOL)windowShouldZoom:(NSWindow*)window toFrame:(NSRect)newFrame { | 
					
						
							| 
									
										
										
										
											2016-06-22 14:06:54 +09:00
										 |  |  |   is_zooming_ = true; | 
					
						
							| 
									
										
										
										
											2014-11-25 13:16:51 +08:00
										 |  |  |   return YES; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-06-22 14:06:54 +09:00
										 |  |  | - (void)windowDidEndLiveResize:(NSNotification*)notification { | 
					
						
							|  |  |  |   if (is_zooming_) { | 
					
						
							|  |  |  |     if (shell_->IsMaximized()) | 
					
						
							|  |  |  |       shell_->NotifyWindowMaximize(); | 
					
						
							|  |  |  |     else | 
					
						
							|  |  |  |       shell_->NotifyWindowUnmaximize(); | 
					
						
							|  |  |  |     is_zooming_ = false; | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-12-23 12:38:11 +08:00
										 |  |  | - (void)windowWillEnterFullScreen:(NSNotification*)notification { | 
					
						
							|  |  |  |   // Hide the native toolbar before entering fullscreen, so there is no visual | 
					
						
							|  |  |  |   // artifacts. | 
					
						
							| 
									
										
										
										
											2017-02-07 09:32:40 -08:00
										 |  |  |   if (base::mac::IsAtLeastOS10_10() && | 
					
						
							| 
									
										
										
										
											2016-09-03 00:45:20 +02:00
										 |  |  |       shell_->title_bar_style() == atom::NativeWindowMac::HIDDEN_INSET) { | 
					
						
							| 
									
										
										
										
											2015-12-21 20:55:23 +02:00
										 |  |  |     NSWindow* window = shell_->GetNativeWindow(); | 
					
						
							|  |  |  |     [window setToolbar:nil]; | 
					
						
							|  |  |  |   } | 
					
						
							| 
									
										
										
										
											2014-11-25 13:16:51 +08:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-12-23 12:38:11 +08:00
										 |  |  | - (void)windowDidEnterFullScreen:(NSNotification*)notification { | 
					
						
							|  |  |  |   shell_->NotifyWindowEnterFullScreen(); | 
					
						
							| 
									
										
										
										
											2015-12-21 20:55:23 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-06-17 10:54:50 +09:00
										 |  |  |   // For frameless window we don't show set title for normal mode since the | 
					
						
							|  |  |  |   // titlebar is expected to be empty, but after entering fullscreen mode we | 
					
						
							|  |  |  |   // have to set one, because title bar is visible here. | 
					
						
							| 
									
										
										
										
											2016-06-07 17:26:26 +09:00
										 |  |  |   NSWindow* window = shell_->GetNativeWindow(); | 
					
						
							| 
									
										
										
										
											2016-06-17 11:02:37 +09:00
										 |  |  |   if ((shell_->transparent() || !shell_->has_frame()) && | 
					
						
							| 
									
										
										
										
											2017-02-07 09:32:40 -08:00
										 |  |  |       base::mac::IsAtLeastOS10_10() && | 
					
						
							| 
									
										
										
										
											2016-06-17 10:54:50 +09:00
										 |  |  |       // FIXME(zcbenz): Showing titlebar for hiddenInset window is weird under | 
					
						
							|  |  |  |       // fullscreen mode. | 
					
						
							|  |  |  |       shell_->title_bar_style() != atom::NativeWindowMac::HIDDEN_INSET) { | 
					
						
							|  |  |  |     [window setTitleVisibility:NSWindowTitleVisible]; | 
					
						
							|  |  |  |   } | 
					
						
							| 
									
										
										
										
											2016-06-07 17:26:26 +09:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-12-23 12:38:11 +08:00
										 |  |  |   // Restore the native toolbar immediately after entering fullscreen, if we do | 
					
						
							|  |  |  |   // this before leaving fullscreen, traffic light buttons will be jumping. | 
					
						
							| 
									
										
										
										
											2017-02-07 09:32:40 -08:00
										 |  |  |   if (base::mac::IsAtLeastOS10_10() && | 
					
						
							| 
									
										
										
										
											2016-09-03 00:45:20 +02:00
										 |  |  |       shell_->title_bar_style() == atom::NativeWindowMac::HIDDEN_INSET) { | 
					
						
							| 
									
										
										
										
											2015-12-21 20:55:23 +02:00
										 |  |  |     base::scoped_nsobject<NSToolbar> toolbar( | 
					
						
							|  |  |  |         [[NSToolbar alloc] initWithIdentifier:@"titlebarStylingToolbar"]); | 
					
						
							|  |  |  |     [toolbar setShowsBaselineSeparator:NO]; | 
					
						
							|  |  |  |     [window setToolbar:toolbar]; | 
					
						
							| 
									
										
										
										
											2016-05-17 16:19:28 +09:00
										 |  |  | 
 | 
					
						
							|  |  |  |     // Set window style to hide the toolbar, otherwise the toolbar will show in | 
					
						
							|  |  |  |     // fullscreen mode. | 
					
						
							|  |  |  |     shell_->SetStyleMask(true, NSFullSizeContentViewWindowMask); | 
					
						
							| 
									
										
										
										
											2015-12-21 20:55:23 +02:00
										 |  |  |   } | 
					
						
							| 
									
										
										
										
											2015-12-23 12:38:11 +08:00
										 |  |  | } | 
					
						
							| 
									
										
										
										
											2015-12-21 20:55:23 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-05-17 16:19:28 +09:00
										 |  |  | - (void)windowWillExitFullScreen:(NSNotification*)notification { | 
					
						
							| 
									
										
										
										
											2016-06-17 10:54:50 +09:00
										 |  |  |   // Restore the titlebar visibility. | 
					
						
							| 
									
										
										
										
											2016-06-07 17:26:26 +09:00
										 |  |  |   NSWindow* window = shell_->GetNativeWindow(); | 
					
						
							| 
									
										
										
										
											2016-06-17 11:02:37 +09:00
										 |  |  |   if ((shell_->transparent() || !shell_->has_frame()) && | 
					
						
							| 
									
										
										
										
											2017-02-07 09:32:40 -08:00
										 |  |  |       base::mac::IsAtLeastOS10_10() && | 
					
						
							| 
									
										
										
										
											2016-06-17 10:54:50 +09:00
										 |  |  |       shell_->title_bar_style() != atom::NativeWindowMac::HIDDEN_INSET) { | 
					
						
							|  |  |  |     [window setTitleVisibility:NSWindowTitleHidden]; | 
					
						
							|  |  |  |   } | 
					
						
							| 
									
										
										
										
											2016-06-07 17:26:26 +09:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-05-17 16:19:28 +09:00
										 |  |  |   // Turn off the style for toolbar. | 
					
						
							| 
									
										
										
										
											2017-02-07 09:32:40 -08:00
										 |  |  |   if (base::mac::IsAtLeastOS10_10() && | 
					
						
							| 
									
										
										
										
											2016-09-03 00:45:20 +02:00
										 |  |  |       shell_->title_bar_style() == atom::NativeWindowMac::HIDDEN_INSET) { | 
					
						
							| 
									
										
										
										
											2016-05-17 16:19:28 +09:00
										 |  |  |     shell_->SetStyleMask(false, NSFullSizeContentViewWindowMask); | 
					
						
							| 
									
										
										
										
											2016-09-03 00:45:20 +02:00
										 |  |  |   } | 
					
						
							| 
									
										
										
										
											2016-05-17 16:19:28 +09:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-12-23 12:38:11 +08:00
										 |  |  | - (void)windowDidExitFullScreen:(NSNotification*)notification { | 
					
						
							| 
									
										
										
										
											2014-11-25 13:16:51 +08:00
										 |  |  |   shell_->NotifyWindowLeaveFullScreen(); | 
					
						
							| 
									
										
										
										
											2014-03-15 19:28:23 +08:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-05-24 17:51:15 +08:00
										 |  |  | - (void)windowWillClose:(NSNotification*)notification { | 
					
						
							| 
									
										
										
										
											2014-04-23 10:24:46 +08:00
										 |  |  |   shell_->NotifyWindowClosed(); | 
					
						
							| 
									
										
										
										
											2015-11-26 13:55:59 +08: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 16:12:00 +08:00
										 |  |  | } | 
					
						
							| 
									
										
										
										
											2013-05-01 15:42:30 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-05-01 16:12:00 +08: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 13:27:51 +08:00
										 |  |  |   shell_->RequestToClosePage(); | 
					
						
							| 
									
										
										
										
											2013-05-01 16:12:00 +08:00
										 |  |  |   return NO; | 
					
						
							| 
									
										
										
										
											2013-05-01 15:42:30 +08:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-04-20 09:18:50 +09:00
										 |  |  | - (NSRect)window:(NSWindow*)window | 
					
						
							|  |  |  |     willPositionSheet:(NSWindow*)sheet usingRect:(NSRect)rect { | 
					
						
							|  |  |  |   NSView* view = window.contentView; | 
					
						
							| 
									
										
										
										
											2016-05-18 23:39:16 -07:00
										 |  |  | 
 | 
					
						
							|  |  |  |   rect.origin.x = shell_->GetSheetOffsetX(); | 
					
						
							|  |  |  |   rect.origin.y = view.frame.size.height - shell_->GetSheetOffsetY(); | 
					
						
							| 
									
										
										
										
											2016-03-26 18:12:25 -07:00
										 |  |  |   return rect; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-05-01 15:42:30 +08:00
										 |  |  | @end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-10-12 17:21:56 -07:00
										 |  |  | @interface AtomPreviewItem : NSObject <QLPreviewItem> | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-10-24 11:49:30 -07:00
										 |  |  | @property (nonatomic, retain) NSURL* previewItemURL; | 
					
						
							|  |  |  | @property (nonatomic, retain) NSString* previewItemTitle; | 
					
						
							| 
									
										
										
										
											2016-10-12 17:21:56 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-10-24 11:49:30 -07:00
										 |  |  | - (id)initWithURL:(NSURL*)url title:(NSString*)title; | 
					
						
							| 
									
										
										
										
											2016-10-12 17:21:56 -07:00
										 |  |  | 
 | 
					
						
							|  |  |  | @end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | @implementation AtomPreviewItem | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-10-24 11:49:30 -07:00
										 |  |  | - (id)initWithURL:(NSURL*)url title:(NSString*)title { | 
					
						
							| 
									
										
										
										
											2016-10-26 09:47:22 +09:00
										 |  |  |   self = [super init]; | 
					
						
							| 
									
										
										
										
											2016-10-12 17:21:56 -07:00
										 |  |  |   if (self) { | 
					
						
							|  |  |  |     self.previewItemURL = url; | 
					
						
							|  |  |  |     self.previewItemTitle = title; | 
					
						
							| 
									
										
										
										
											2016-10-26 09:47:22 +09:00
										 |  |  |   } | 
					
						
							| 
									
										
										
										
											2016-10-12 17:21:56 -07:00
										 |  |  |   return self; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | @end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | @interface AtomNSWindow : EventDispatchingWindow<QLPreviewPanelDataSource, QLPreviewPanelDelegate> { | 
					
						
							| 
									
										
										
										
											2014-08-17 12:23:00 +08:00
										 |  |  |  @private | 
					
						
							| 
									
										
										
										
											2013-04-12 15:53:29 +08:00
										 |  |  |   atom::NativeWindowMac* shell_; | 
					
						
							| 
									
										
										
										
											2014-08-17 12:23:00 +08:00
										 |  |  |   bool enable_larger_than_screen_; | 
					
						
							| 
									
										
										
										
											2016-09-03 00:45:20 +02:00
										 |  |  |   CGFloat windowButtonsInterButtonSpacing_; | 
					
						
							| 
									
										
										
										
											2013-04-12 15:53:29 +08:00
										 |  |  | } | 
					
						
							| 
									
										
										
										
											2015-04-27 11:47:26 +08:00
										 |  |  | @property BOOL acceptsFirstMouse; | 
					
						
							| 
									
										
										
										
											2015-04-27 12:08:22 +08:00
										 |  |  | @property BOOL disableAutoHideCursor; | 
					
						
							| 
									
										
										
										
											2015-11-19 00:39:45 -08:00
										 |  |  | @property BOOL disableKeyOrMainWindow; | 
					
						
							| 
									
										
										
										
											2016-09-03 00:45:20 +02:00
										 |  |  | @property NSPoint windowButtonsOffset; | 
					
						
							| 
									
										
										
										
											2016-10-12 17:21:56 -07:00
										 |  |  | @property (nonatomic, retain) AtomPreviewItem* quickLookItem; | 
					
						
							| 
									
										
										
										
											2016-11-10 20:36:21 +01:00
										 |  |  | @property (nonatomic, retain) NSView* vibrantView; | 
					
						
							| 
									
										
										
										
											2015-11-19 00:39:45 -08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-04-12 15:53:29 +08:00
										 |  |  | - (void)setShell:(atom::NativeWindowMac*)shell; | 
					
						
							| 
									
										
										
										
											2014-08-17 12:23:00 +08:00
										 |  |  | - (void)setEnableLargerThanScreen:(bool)enable; | 
					
						
							| 
									
										
										
										
											2016-09-03 00:45:20 +02:00
										 |  |  | - (void)enableWindowButtonsOffset; | 
					
						
							| 
									
										
										
										
											2013-04-12 15:53:29 +08:00
										 |  |  | @end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | @implementation AtomNSWindow | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | - (void)setShell:(atom::NativeWindowMac*)shell { | 
					
						
							|  |  |  |   shell_ = shell; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-08-17 12:23:00 +08:00
										 |  |  | - (void)setEnableLargerThanScreen:(bool)enable { | 
					
						
							|  |  |  |   enable_larger_than_screen_ = enable; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-12-07 19:56:23 +08: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 10:24:36 +08:00
										 |  |  | - (NSRect)constrainFrameRect:(NSRect)frameRect toScreen:(NSScreen*)screen { | 
					
						
							| 
									
										
										
										
											2015-08-05 14:12:55 +08:00
										 |  |  |   // Resizing is disabled. | 
					
						
							|  |  |  |   if (ScopedDisableResize::IsResizeDisabled()) | 
					
						
							|  |  |  |     return [self frame]; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   // Enable the window to be larger than screen. | 
					
						
							| 
									
										
										
										
											2014-08-17 12:23:00 +08:00
										 |  |  |   if (enable_larger_than_screen_) | 
					
						
							|  |  |  |     return frameRect; | 
					
						
							|  |  |  |   else | 
					
						
							|  |  |  |     return [super constrainFrameRect:frameRect toScreen:screen]; | 
					
						
							| 
									
										
										
										
											2014-08-11 10:24:36 +08:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-08-15 13:14:19 -07:00
										 |  |  | - (void)setFrame:(NSRect)windowFrame display:(BOOL)displayViews { | 
					
						
							|  |  |  |   // constrainFrameRect is not called on hidden windows so disable adjusting | 
					
						
							|  |  |  |   // the frame directly when resize is disabled | 
					
						
							|  |  |  |   if (!ScopedDisableResize::IsResizeDisabled()) | 
					
						
							|  |  |  |     [super setFrame:windowFrame display:displayViews]; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-08-17 11:26:02 +08:00
										 |  |  | - (id)accessibilityAttributeValue:(NSString*)attribute { | 
					
						
							| 
									
										
										
										
											2015-04-13 20:10:51 +08: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 11:26:02 +08:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-11-20 13:06:42 +08:00
										 |  |  | - (BOOL)canBecomeMainWindow { | 
					
						
							|  |  |  |   return !self.disableKeyOrMainWindow; | 
					
						
							| 
									
										
										
										
											2015-11-19 00:39:45 -08:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-11-20 13:06:42 +08:00
										 |  |  | - (BOOL)canBecomeKeyWindow { | 
					
						
							|  |  |  |   return !self.disableKeyOrMainWindow; | 
					
						
							| 
									
										
										
										
											2015-11-19 00:39:45 -08:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-09-03 00:45:20 +02:00
										 |  |  | - (void)enableWindowButtonsOffset { | 
					
						
							|  |  |  |   auto closeButton = [self standardWindowButton:NSWindowCloseButton]; | 
					
						
							|  |  |  |   auto miniaturizeButton = [self standardWindowButton:NSWindowMiniaturizeButton]; | 
					
						
							|  |  |  |   auto zoomButton = [self standardWindowButton:NSWindowZoomButton]; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   [closeButton setPostsFrameChangedNotifications:YES]; | 
					
						
							|  |  |  |   [miniaturizeButton setPostsFrameChangedNotifications:YES]; | 
					
						
							|  |  |  |   [zoomButton setPostsFrameChangedNotifications:YES]; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   windowButtonsInterButtonSpacing_ = | 
					
						
							|  |  |  |     NSMinX([miniaturizeButton frame]) - NSMaxX([closeButton frame]); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   auto center = [NSNotificationCenter defaultCenter]; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   [center addObserver:self | 
					
						
							|  |  |  |              selector:@selector(adjustCloseButton:) | 
					
						
							|  |  |  |                  name:NSViewFrameDidChangeNotification | 
					
						
							|  |  |  |                object:closeButton]; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   [center addObserver:self | 
					
						
							|  |  |  |              selector:@selector(adjustMiniaturizeButton:) | 
					
						
							|  |  |  |                  name:NSViewFrameDidChangeNotification | 
					
						
							|  |  |  |                object:miniaturizeButton]; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   [center addObserver:self | 
					
						
							|  |  |  |              selector:@selector(adjustZoomButton:) | 
					
						
							|  |  |  |                  name:NSViewFrameDidChangeNotification | 
					
						
							|  |  |  |                object:zoomButton]; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | - (void)adjustCloseButton:(NSNotification*)notification { | 
					
						
							|  |  |  |   [self adjustButton:[notification object] | 
					
						
							|  |  |  |               ofKind:NSWindowCloseButton]; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | - (void)adjustMiniaturizeButton:(NSNotification*)notification { | 
					
						
							|  |  |  |   [self adjustButton:[notification object] | 
					
						
							|  |  |  |               ofKind:NSWindowMiniaturizeButton]; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | - (void)adjustZoomButton:(NSNotification*)notification { | 
					
						
							|  |  |  |   [self adjustButton:[notification object] | 
					
						
							|  |  |  |               ofKind:NSWindowZoomButton]; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | - (void)adjustButton:(NSButton*)button | 
					
						
							|  |  |  |               ofKind:(NSWindowButton)kind { | 
					
						
							|  |  |  |   NSRect buttonFrame = [button frame]; | 
					
						
							|  |  |  |   NSRect frameViewBounds = [[self frameView] bounds]; | 
					
						
							|  |  |  |   NSPoint offset = self.windowButtonsOffset; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   buttonFrame.origin = NSMakePoint( | 
					
						
							|  |  |  |     offset.x, | 
					
						
							|  |  |  |     (NSHeight(frameViewBounds) - NSHeight(buttonFrame) - offset.y)); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   switch (kind) { | 
					
						
							|  |  |  |     case NSWindowZoomButton: | 
					
						
							|  |  |  |       buttonFrame.origin.x += NSWidth( | 
					
						
							|  |  |  |         [[self standardWindowButton:NSWindowMiniaturizeButton] frame]); | 
					
						
							|  |  |  |       buttonFrame.origin.x += windowButtonsInterButtonSpacing_; | 
					
						
							|  |  |  |       // fallthrough | 
					
						
							|  |  |  |     case NSWindowMiniaturizeButton: | 
					
						
							|  |  |  |       buttonFrame.origin.x += NSWidth( | 
					
						
							|  |  |  |         [[self standardWindowButton:NSWindowCloseButton] frame]); | 
					
						
							|  |  |  |       buttonFrame.origin.x += windowButtonsInterButtonSpacing_; | 
					
						
							|  |  |  |       // fallthrough | 
					
						
							|  |  |  |     default: | 
					
						
							|  |  |  |       break; | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   BOOL didPost = [button postsBoundsChangedNotifications]; | 
					
						
							|  |  |  |   [button setPostsFrameChangedNotifications:NO]; | 
					
						
							|  |  |  |   [button setFrame:buttonFrame]; | 
					
						
							|  |  |  |   [button setPostsFrameChangedNotifications:didPost]; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | - (NSView*)frameView { | 
					
						
							|  |  |  |   return [[self contentView] superview]; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-10-12 17:21:56 -07:00
										 |  |  | // Quicklook methods | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-10-24 11:54:22 -07:00
										 |  |  | - (BOOL)acceptsPreviewPanelControl:(QLPreviewPanel*)panel { | 
					
						
							| 
									
										
										
										
											2016-10-12 17:21:56 -07:00
										 |  |  |   return YES; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-10-24 11:54:22 -07:00
										 |  |  | - (void)beginPreviewPanelControl:(QLPreviewPanel*)panel { | 
					
						
							| 
									
										
										
										
											2016-10-12 17:21:56 -07:00
										 |  |  |   panel.delegate = self; | 
					
						
							|  |  |  |   panel.dataSource = self; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-10-24 11:54:22 -07:00
										 |  |  | - (void)endPreviewPanelControl:(QLPreviewPanel*)panel { | 
					
						
							| 
									
										
										
										
											2016-10-12 17:21:56 -07:00
										 |  |  |   panel.delegate = nil; | 
					
						
							|  |  |  |   panel.dataSource = nil; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-10-24 11:54:22 -07:00
										 |  |  | - (NSInteger)numberOfPreviewItemsInPreviewPanel:(QLPreviewPanel*)panel { | 
					
						
							| 
									
										
										
										
											2016-10-12 17:21:56 -07:00
										 |  |  |   return 1; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-10-24 11:55:48 -07:00
										 |  |  | - (id <QLPreviewItem>)previewPanel:(QLPreviewPanel*)panel previewItemAtIndex:(NSInteger)index { | 
					
						
							| 
									
										
										
										
											2016-10-12 17:21:56 -07:00
										 |  |  |   return [self quickLookItem]; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-10-24 11:55:48 -07:00
										 |  |  | - (void)previewFileAtPath:(NSString*)path  withName:(NSString*) fileName { | 
					
						
							| 
									
										
										
										
											2016-10-25 07:52:56 -07:00
										 |  |  |   NSURL* url = [[[NSURL alloc] initFileURLWithPath:path] autorelease]; | 
					
						
							| 
									
										
										
										
											2016-10-14 09:42:50 -07:00
										 |  |  |   [self setQuickLookItem:[[[AtomPreviewItem alloc] initWithURL:url title:fileName] autorelease]]; | 
					
						
							| 
									
										
										
										
											2016-10-12 17:21:56 -07:00
										 |  |  |   [[QLPreviewPanel sharedPreviewPanel] makeKeyAndOrderFront:nil]; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-04-12 15:53:29 +08:00
										 |  |  | @end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-10-21 07:33:43 +08:00
										 |  |  | @interface ControlRegionView : NSView | 
					
						
							| 
									
										
										
										
											2013-09-05 23:52:29 +08:00
										 |  |  | @end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | @implementation ControlRegionView | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | - (BOOL)mouseDownCanMoveWindow { | 
					
						
							|  |  |  |   return NO; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | - (NSView*)hitTest:(NSPoint)aPoint { | 
					
						
							| 
									
										
										
										
											2015-10-21 07:33:43 +08:00
										 |  |  |   return nil; | 
					
						
							| 
									
										
										
										
											2013-09-05 23:52:29 +08:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-10-21 07:33:43 +08:00
										 |  |  | @end | 
					
						
							| 
									
										
										
										
											2015-03-24 14:50:29 +05:30
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-10-21 07:33:43 +08:00
										 |  |  | @interface NSView (WebContentsView) | 
					
						
							|  |  |  | - (void)setMouseDownCanMoveWindow:(BOOL)can_move; | 
					
						
							| 
									
										
										
										
											2013-09-05 23:52:29 +08:00
										 |  |  | @end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-09-17 15:58:08 +08: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 16:17:49 +08: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 15:58:08 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  |   // Fill the rounded rect. | 
					
						
							| 
									
										
										
										
											2014-09-18 16:17:49 +08: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 15:58:08 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  |   // Calculate the progress width. | 
					
						
							| 
									
										
										
										
											2014-09-18 16:17:49 +08:00
										 |  |  |   rect.size.width = floor(rect.size.width * ([self doubleValue] / [self maxValue])); | 
					
						
							| 
									
										
										
										
											2014-09-17 15:58:08 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  |   // Fill the progress bar with color blue. | 
					
						
							|  |  |  |   [[NSColor colorWithSRGBRed:0.2 green:0.6 blue:1 alpha:1] set]; | 
					
						
							|  |  |  |   NSRectFill(rect); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | @end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-06-17 10:54:50 +09:00
										 |  |  | namespace mate { | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | template<> | 
					
						
							|  |  |  | struct Converter<atom::NativeWindowMac::TitleBarStyle> { | 
					
						
							|  |  |  |   static bool FromV8(v8::Isolate* isolate, v8::Handle<v8::Value> val, | 
					
						
							|  |  |  |                      atom::NativeWindowMac::TitleBarStyle* out) { | 
					
						
							|  |  |  |     std::string title_bar_style; | 
					
						
							|  |  |  |     if (!ConvertFromV8(isolate, val, &title_bar_style)) | 
					
						
							|  |  |  |       return false; | 
					
						
							|  |  |  |     if (title_bar_style == "hidden") { | 
					
						
							|  |  |  |       *out = atom::NativeWindowMac::HIDDEN; | 
					
						
							|  |  |  |     } else if (title_bar_style == "hidden-inset" ||  // Deprecate this after 2.0 | 
					
						
							|  |  |  |                title_bar_style == "hiddenInset") { | 
					
						
							| 
									
										
										
										
											2016-09-03 00:45:20 +02:00
										 |  |  |       *out = atom::NativeWindowMac::HIDDEN_INSET; | 
					
						
							| 
									
										
										
										
											2016-06-17 10:54:50 +09:00
										 |  |  |     } else { | 
					
						
							|  |  |  |       return false; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |     return true; | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | }  // namespace mate | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-04-12 15:04:46 +08:00
										 |  |  | namespace atom { | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-06-25 09:47:57 +08:00
										 |  |  | NativeWindowMac::NativeWindowMac( | 
					
						
							| 
									
										
										
										
											2016-08-08 16:33:16 +09:00
										 |  |  |     brightray::InspectableWebContents* web_contents, | 
					
						
							| 
									
										
										
										
											2016-06-19 12:06:08 +09:00
										 |  |  |     const mate::Dictionary& options, | 
					
						
							|  |  |  |     NativeWindow* parent) | 
					
						
							| 
									
										
										
										
											2016-08-08 16:33:16 +09:00
										 |  |  |     : NativeWindow(web_contents, options, parent), | 
					
						
							| 
									
										
										
										
											2013-04-12 15:04:46 +08:00
										 |  |  |       is_kiosk_(false), | 
					
						
							| 
									
										
										
										
											2017-01-14 00:04:51 +01:00
										 |  |  |       was_fullscreen_(false), | 
					
						
							| 
									
										
										
										
											2016-10-27 11:29:51 -07:00
										 |  |  |       zoom_to_page_width_(false), | 
					
						
							| 
									
										
										
										
											2015-12-23 12:38:11 +08:00
										 |  |  |       attention_request_id_(0), | 
					
						
							| 
									
										
										
										
											2016-09-17 22:29:32 +08:00
										 |  |  |       title_bar_style_(NORMAL) { | 
					
						
							| 
									
										
										
										
											2014-01-06 18:58:30 +08:00
										 |  |  |   int width = 800, height = 600; | 
					
						
							| 
									
										
										
										
											2015-11-13 13:58:31 +08:00
										 |  |  |   options.Get(options::kWidth, &width); | 
					
						
							|  |  |  |   options.Get(options::kHeight, &height); | 
					
						
							| 
									
										
										
										
											2013-04-12 15:04:46 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-12-20 13:49:35 -08:00
										 |  |  |   NSRect main_screen_rect = [[[NSScreen screens] firstObject] frame]; | 
					
						
							| 
									
										
										
										
											2013-04-12 15:04:46 +08:00
										 |  |  |   NSRect cocoa_bounds = NSMakeRect( | 
					
						
							| 
									
										
										
										
											2013-09-11 22:02:42 -04:00
										 |  |  |       round((NSWidth(main_screen_rect) - width) / 2) , | 
					
						
							|  |  |  |       round((NSHeight(main_screen_rect) - height) / 2), | 
					
						
							| 
									
										
										
										
											2013-04-12 15:04:46 +08:00
										 |  |  |       width, | 
					
						
							|  |  |  |       height); | 
					
						
							| 
									
										
										
										
											2013-09-11 18:10:28 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-10-06 15:23:23 +08:00
										 |  |  |   bool resizable = true; | 
					
						
							| 
									
										
										
										
											2015-11-13 13:58:31 +08:00
										 |  |  |   options.Get(options::kResizable, &resizable); | 
					
						
							| 
									
										
										
										
											2015-05-06 10:08:24 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-01-18 23:46:35 +01:00
										 |  |  |   bool minimizable = true; | 
					
						
							|  |  |  |   options.Get(options::kMinimizable, &minimizable); | 
					
						
							| 
									
										
										
										
											2016-01-22 23:51:52 -08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-01-22 22:24:33 +01:00
										 |  |  |   bool maximizable = true; | 
					
						
							|  |  |  |   options.Get(options::kMaximizable, &maximizable); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-01-18 23:46:35 +01:00
										 |  |  |   bool closable = true; | 
					
						
							|  |  |  |   options.Get(options::kClosable, &closable); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-08-15 21:36:57 +02:00
										 |  |  |   options.Get(options::kTitleBarStyle, &title_bar_style_); | 
					
						
							| 
									
										
										
										
											2015-09-25 16:21:08 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-11-19 00:39:45 -08: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 02:23:18 -08:00
										 |  |  |   NSUInteger styleMask = NSTitledWindowMask; | 
					
						
							| 
									
										
										
										
											2016-01-18 23:46:35 +01:00
										 |  |  |   if (minimizable) { | 
					
						
							|  |  |  |     styleMask |= NSMiniaturizableWindowMask; | 
					
						
							|  |  |  |   } | 
					
						
							| 
									
										
										
										
											2016-01-23 02:23:18 -08:00
										 |  |  |   if (closable) { | 
					
						
							|  |  |  |     styleMask |= NSClosableWindowMask; | 
					
						
							| 
									
										
										
										
											2016-01-18 23:46:35 +01:00
										 |  |  |   } | 
					
						
							| 
									
										
										
										
											2016-06-17 10:54:50 +09:00
										 |  |  |   if (title_bar_style_ != NORMAL) { | 
					
						
							| 
									
										
										
										
											2016-05-17 15:48:14 +09:00
										 |  |  |     // The window without titlebar is treated the same with frameless window. | 
					
						
							|  |  |  |     set_has_frame(false); | 
					
						
							|  |  |  |   } | 
					
						
							| 
									
										
										
										
											2015-08-05 12:46:32 +08:00
										 |  |  |   if (!useStandardWindow || transparent() || !has_frame()) { | 
					
						
							| 
									
										
										
										
											2015-05-06 10:08:24 -04:00
										 |  |  |     styleMask |= NSTexturedBackgroundWindowMask; | 
					
						
							|  |  |  |   } | 
					
						
							| 
									
										
										
										
											2015-10-06 15:23:23 +08:00
										 |  |  |   if (resizable) { | 
					
						
							|  |  |  |     styleMask |= NSResizableWindowMask; | 
					
						
							|  |  |  |   } | 
					
						
							| 
									
										
										
										
											2015-12-21 20:55:23 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-03-25 18:51:29 +08:00
										 |  |  |   window_.reset([[AtomNSWindow alloc] | 
					
						
							| 
									
										
										
										
											2013-09-12 11:20:38 -04:00
										 |  |  |       initWithContentRect:cocoa_bounds | 
					
						
							| 
									
										
										
										
											2015-05-06 10:08:24 -04:00
										 |  |  |                 styleMask:styleMask | 
					
						
							| 
									
										
										
										
											2013-09-12 11:20:38 -04:00
										 |  |  |                   backing:NSBackingStoreBuffered | 
					
						
							| 
									
										
										
										
											2015-03-25 18:51:29 +08:00
										 |  |  |                     defer:YES]); | 
					
						
							|  |  |  |   [window_ setShell:this]; | 
					
						
							| 
									
										
										
										
											2015-08-05 12:46:32 +08:00
										 |  |  |   [window_ setEnableLargerThanScreen:enable_larger_than_screen()]; | 
					
						
							| 
									
										
										
										
											2013-09-11 18:10:28 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-03-25 18:51:29 +08:00
										 |  |  |   window_delegate_.reset([[AtomNSWindowDelegate alloc] initWithShell:this]); | 
					
						
							|  |  |  |   [window_ setDelegate:window_delegate_]; | 
					
						
							| 
									
										
										
										
											2014-03-15 19:28:23 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-06-20 14:49:24 +09:00
										 |  |  |   // Only use native parent window for non-modal windows. | 
					
						
							|  |  |  |   if (parent && !is_modal()) { | 
					
						
							| 
									
										
										
										
											2016-06-19 12:06:08 +09:00
										 |  |  |     SetParentWindow(parent); | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-08-05 12:46:32 +08:00
										 |  |  |   if (transparent()) { | 
					
						
							| 
									
										
										
										
											2016-01-19 15:24:16 -08:00
										 |  |  |     // Setting the background color to clear will also hide the shadow. | 
					
						
							| 
									
										
										
										
											2014-12-23 11:17:56 -08:00
										 |  |  |     [window_ setBackgroundColor:[NSColor clearColor]]; | 
					
						
							|  |  |  |   } | 
					
						
							| 
									
										
										
										
											2015-04-25 10:35:28 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-11-19 00:39:45 -08:00
										 |  |  |   if (windowType == "desktop") { | 
					
						
							|  |  |  |     [window_ setLevel:kCGDesktopWindowLevel - 1]; | 
					
						
							| 
									
										
										
										
											2015-11-20 13:06:42 +08:00
										 |  |  |     [window_ setDisableKeyOrMainWindow:YES]; | 
					
						
							| 
									
										
										
										
											2015-11-19 00:39:45 -08:00
										 |  |  |     [window_ setCollectionBehavior: | 
					
						
							|  |  |  |         (NSWindowCollectionBehaviorCanJoinAllSpaces | | 
					
						
							|  |  |  |          NSWindowCollectionBehaviorStationary | | 
					
						
							|  |  |  |          NSWindowCollectionBehaviorIgnoresCycle)]; | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-06-13 17:10:28 +09:00
										 |  |  |   bool focusable; | 
					
						
							|  |  |  |   if (options.Get(options::kFocusable, &focusable) && !focusable) | 
					
						
							|  |  |  |     [window_ setDisableKeyOrMainWindow:YES]; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-06-17 11:02:37 +09:00
										 |  |  |   if (transparent() || !has_frame()) { | 
					
						
							| 
									
										
										
										
											2017-02-07 09:32:40 -08:00
										 |  |  |     if (base::mac::IsAtLeastOS10_10()) { | 
					
						
							| 
									
										
										
										
											2016-06-23 13:00:14 +09:00
										 |  |  |       // Don't show title bar. | 
					
						
							|  |  |  |       [window_ setTitleVisibility:NSWindowTitleHidden]; | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2016-06-17 10:54:50 +09:00
										 |  |  |     // Remove non-transparent corners, see http://git.io/vfonD. | 
					
						
							| 
									
										
										
										
											2015-04-18 19:08:22 +07:00
										 |  |  |     [window_ setOpaque:NO]; | 
					
						
							| 
									
										
										
										
											2016-06-17 10:54:50 +09:00
										 |  |  |   } | 
					
						
							| 
									
										
										
										
											2014-12-23 11:17:56 -08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-04-11 12:32:42 +08:00
										 |  |  |   // We will manage window's lifetime ourselves. | 
					
						
							| 
									
										
										
										
											2014-04-11 12:45:48 +08:00
										 |  |  |   [window_ setReleasedWhenClosed:NO]; | 
					
						
							| 
									
										
										
										
											2014-04-11 12:32:42 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-09-25 16:38:36 +08:00
										 |  |  |   // Hide the title bar. | 
					
						
							| 
									
										
										
										
											2016-06-17 10:54:50 +09:00
										 |  |  |   if (title_bar_style_ == HIDDEN_INSET) { | 
					
						
							| 
									
										
										
										
											2017-02-07 09:32:40 -08:00
										 |  |  |     if (base::mac::IsAtLeastOS10_10()) { | 
					
						
							| 
									
										
										
										
											2016-09-03 00:45:20 +02:00
										 |  |  |       [window_ setTitlebarAppearsTransparent:YES]; | 
					
						
							|  |  |  |       base::scoped_nsobject<NSToolbar> toolbar( | 
					
						
							|  |  |  |           [[NSToolbar alloc] initWithIdentifier:@"titlebarStylingToolbar"]); | 
					
						
							|  |  |  |       [toolbar setShowsBaselineSeparator:NO]; | 
					
						
							|  |  |  |       [window_ setToolbar:toolbar]; | 
					
						
							|  |  |  |     } else { | 
					
						
							|  |  |  |       [window_ enableWindowButtonsOffset]; | 
					
						
							|  |  |  |       [window_ setWindowButtonsOffset:NSMakePoint(12, 10)]; | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2015-09-14 14:15:41 +02:00
										 |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-06-18 15:26:26 +02:00
										 |  |  |   // On macOS the initial window size doesn't include window frame. | 
					
						
							| 
									
										
										
										
											2014-05-15 15:19:02 +08:00
										 |  |  |   bool use_content_size = false; | 
					
						
							| 
									
										
										
										
											2015-11-13 13:58:31 +08:00
										 |  |  |   options.Get(options::kUseContentSize, &use_content_size); | 
					
						
							| 
									
										
										
										
											2015-08-05 12:46:32 +08:00
										 |  |  |   if (!has_frame() || !use_content_size) | 
					
						
							| 
									
										
										
										
											2014-05-15 15:19:02 +08:00
										 |  |  |     SetSize(gfx::Size(width, height)); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-10-27 11:29:51 -07:00
										 |  |  |   options.Get(options::kZoomToPageWidth, &zoom_to_page_width_); | 
					
						
							| 
									
										
										
										
											2016-10-26 12:12:12 +09:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-03-15 19:28:23 +08:00
										 |  |  |   // Enable the NSView to accept first mouse event. | 
					
						
							|  |  |  |   bool acceptsFirstMouse = false; | 
					
						
							| 
									
										
										
										
											2015-11-13 13:58:31 +08:00
										 |  |  |   options.Get(options::kAcceptFirstMouse, &acceptsFirstMouse); | 
					
						
							| 
									
										
										
										
											2015-04-27 11:47:26 +08:00
										 |  |  |   [window_ setAcceptsFirstMouse:acceptsFirstMouse]; | 
					
						
							| 
									
										
										
										
											2013-04-12 15:04:46 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-04-27 12:08:22 +08:00
										 |  |  |   // Disable auto-hiding cursor. | 
					
						
							|  |  |  |   bool disableAutoHideCursor = false; | 
					
						
							| 
									
										
										
										
											2015-11-13 13:58:31 +08:00
										 |  |  |   options.Get(options::kDisableAutoHideCursor, &disableAutoHideCursor); | 
					
						
							| 
									
										
										
										
											2015-04-27 12:08:22 +08:00
										 |  |  |   [window_ setDisableAutoHideCursor:disableAutoHideCursor]; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-09-05 23:52:29 +08:00
										 |  |  |   NSView* view = inspectable_web_contents()->GetView()->GetNativeView(); | 
					
						
							|  |  |  |   [view setAutoresizingMask:NSViewWidthSizable | NSViewHeightSizable]; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-01-25 15:02:43 +08:00
										 |  |  |   // Use an NSEvent monitor to listen for the wheel event. | 
					
						
							|  |  |  |   BOOL __block began = NO; | 
					
						
							|  |  |  |   wheel_event_monitor_ = [NSEvent | 
					
						
							| 
									
										
										
										
											2016-01-21 16:31:31 -08:00
										 |  |  |     addLocalMonitorForEventsMatchingMask:NSScrollWheelMask | 
					
						
							| 
									
										
										
										
											2016-01-25 15:02:43 +08:00
										 |  |  |     handler:^(NSEvent* event) { | 
					
						
							| 
									
										
										
										
											2016-01-21 16:36:48 -08:00
										 |  |  |       if ([[event window] windowNumber] != [window_ windowNumber]) | 
					
						
							| 
									
										
										
										
											2016-01-21 16:31:31 -08:00
										 |  |  |         return event; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-08-08 16:33:16 +09:00
										 |  |  |       if (!web_contents) | 
					
						
							| 
									
										
										
										
											2016-01-21 16:31:31 -08:00
										 |  |  |         return event; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-09-17 22:29:32 +08:00
										 |  |  |       if (!began && (([event phase] == NSEventPhaseMayBegin) || | 
					
						
							| 
									
										
										
										
											2016-08-08 16:33:16 +09:00
										 |  |  |                                  ([event phase] == NSEventPhaseBegan))) { | 
					
						
							| 
									
										
										
										
											2016-01-21 16:31:31 -08:00
										 |  |  |         this->NotifyWindowScrollTouchBegin(); | 
					
						
							| 
									
										
										
										
											2016-01-25 15:02:43 +08:00
										 |  |  |         began = YES; | 
					
						
							|  |  |  |       } else if (began && (([event phase] == NSEventPhaseEnded) || | 
					
						
							|  |  |  |                            ([event phase] == NSEventPhaseCancelled))) { | 
					
						
							| 
									
										
										
										
											2016-01-21 16:31:31 -08:00
										 |  |  |         this->NotifyWindowScrollTouchEnd(); | 
					
						
							| 
									
										
										
										
											2016-01-25 15:02:43 +08:00
										 |  |  |         began = NO; | 
					
						
							| 
									
										
										
										
											2016-01-21 16:31:31 -08:00
										 |  |  |       } | 
					
						
							| 
									
										
										
										
											2016-01-21 09:40:21 -08:00
										 |  |  |       return event; | 
					
						
							| 
									
										
										
										
											2016-01-25 15:02:43 +08:00
										 |  |  |   }]; | 
					
						
							| 
									
										
										
										
											2016-01-21 09:40:21 -08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-04-12 15:04:46 +08:00
										 |  |  |   InstallView(); | 
					
						
							| 
									
										
										
										
											2016-06-08 13:56:45 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-11-10 20:36:21 +01:00
										 |  |  |   std::string type; | 
					
						
							|  |  |  |   if (options.Get(options::kVibrancyType, &type)) { | 
					
						
							|  |  |  |     SetVibrancy(type); | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-06-08 13:56:45 -07:00
										 |  |  |   // Set maximizable state last to ensure zoom button does not get reset | 
					
						
							|  |  |  |   // by calls to other APIs. | 
					
						
							| 
									
										
										
										
											2016-08-04 16:47:03 -07:00
										 |  |  |   SetMaximizable(maximizable); | 
					
						
							| 
									
										
										
										
											2016-08-01 18:01:21 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-08-08 16:33:16 +09:00
										 |  |  |   RegisterInputEventObserver( | 
					
						
							|  |  |  |       web_contents->GetWebContents()->GetRenderViewHost()); | 
					
						
							| 
									
										
										
										
											2013-04-12 15:04:46 +08:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | NativeWindowMac::~NativeWindowMac() { | 
					
						
							| 
									
										
										
										
											2016-01-25 15:02:43 +08:00
										 |  |  |   [NSEvent removeMonitor:wheel_event_monitor_]; | 
					
						
							| 
									
										
										
										
											2015-06-25 11:07:23 +08:00
										 |  |  |   Observe(nullptr); | 
					
						
							| 
									
										
										
										
											2013-04-12 15:04:46 +08:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void NativeWindowMac::Close() { | 
					
						
							| 
									
										
										
										
											2016-06-20 14:49:24 +09:00
										 |  |  |   // When this is a sheet showing, performClose won't work. | 
					
						
							|  |  |  |   if (is_modal() && parent() && IsVisible()) { | 
					
						
							| 
									
										
										
										
											2016-09-07 15:24:37 -07:00
										 |  |  |     [parent()->GetNativeWindow() endSheet:window_]; | 
					
						
							| 
									
										
										
										
											2016-06-20 14:49:24 +09:00
										 |  |  |     CloseImmediately(); | 
					
						
							|  |  |  |     return; | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-05-25 19:25:51 -04:00
										 |  |  |   if (!IsClosable()) { | 
					
						
							|  |  |  |     WindowList::WindowCloseCancelled(this); | 
					
						
							|  |  |  |     return; | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-04-11 12:45:48 +08:00
										 |  |  |   [window_ performClose:nil]; | 
					
						
							| 
									
										
										
										
											2013-04-12 15:04:46 +08:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-05-01 16:12:00 +08:00
										 |  |  | void NativeWindowMac::CloseImmediately() { | 
					
						
							| 
									
										
										
										
											2014-04-11 12:45:48 +08:00
										 |  |  |   [window_ close]; | 
					
						
							| 
									
										
										
										
											2013-05-01 16:12:00 +08:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-04-12 15:04:46 +08:00
										 |  |  | void NativeWindowMac::Focus(bool focus) { | 
					
						
							| 
									
										
										
										
											2013-10-03 09:39:17 +08:00
										 |  |  |   if (!IsVisible()) | 
					
						
							|  |  |  |     return; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   if (focus) { | 
					
						
							| 
									
										
										
										
											2013-05-25 15:08:58 +08:00
										 |  |  |     [[NSApplication sharedApplication] activateIgnoringOtherApps:YES]; | 
					
						
							| 
									
										
										
										
											2014-04-11 12:45:48 +08:00
										 |  |  |     [window_ makeKeyAndOrderFront:nil]; | 
					
						
							| 
									
										
										
										
											2013-05-25 15:08:58 +08:00
										 |  |  |   } else { | 
					
						
							| 
									
										
										
										
											2014-04-11 12:45:48 +08:00
										 |  |  |     [window_ orderBack:nil]; | 
					
						
							| 
									
										
										
										
											2013-05-25 15:08:58 +08:00
										 |  |  |   } | 
					
						
							| 
									
										
										
										
											2013-04-12 15:04:46 +08:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-05-16 22:56:52 +08:00
										 |  |  | bool NativeWindowMac::IsFocused() { | 
					
						
							| 
									
										
										
										
											2014-04-11 12:45:48 +08:00
										 |  |  |   return [window_ isKeyWindow]; | 
					
						
							| 
									
										
										
										
											2013-05-16 22:56:52 +08:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-04-12 15:04:46 +08:00
										 |  |  | void NativeWindowMac::Show() { | 
					
						
							| 
									
										
										
										
											2016-06-20 14:49:24 +09:00
										 |  |  |   if (is_modal() && parent()) { | 
					
						
							| 
									
										
										
										
											2016-09-29 11:49:24 -07:00
										 |  |  |     if ([window_ sheetParent] == nil) | 
					
						
							|  |  |  |       [parent()->GetNativeWindow() beginSheet:window_ | 
					
						
							|  |  |  |                             completionHandler:^(NSModalResponse) {}]; | 
					
						
							| 
									
										
										
										
											2016-06-20 14:49:24 +09:00
										 |  |  |     return; | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-12-27 17:41:13 -08: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 22:51:20 +08:00
										 |  |  |   [window_ makeKeyAndOrderFront:nil]; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void NativeWindowMac::ShowInactive() { | 
					
						
							| 
									
										
										
										
											2014-09-09 14:47:04 +08:00
										 |  |  |   [window_ orderFrontRegardless]; | 
					
						
							| 
									
										
										
										
											2013-04-12 15:04:46 +08:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void NativeWindowMac::Hide() { | 
					
						
							| 
									
										
										
										
											2016-06-20 14:49:24 +09:00
										 |  |  |   if (is_modal() && parent()) { | 
					
						
							|  |  |  |     [window_ orderOut:nil]; | 
					
						
							|  |  |  |     [parent()->GetNativeWindow() endSheet:window_]; | 
					
						
							|  |  |  |     return; | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-04-11 12:45:48 +08:00
										 |  |  |   [window_ orderOut:nil]; | 
					
						
							| 
									
										
										
										
											2013-04-12 15:04:46 +08:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-10-03 08:27:59 +08:00
										 |  |  | bool NativeWindowMac::IsVisible() { | 
					
						
							| 
									
										
										
										
											2014-04-11 12:45:48 +08:00
										 |  |  |   return [window_ isVisible]; | 
					
						
							| 
									
										
										
										
											2013-10-03 08:27:59 +08:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-06-17 17:38:44 +09:00
										 |  |  | bool NativeWindowMac::IsEnabled() { | 
					
						
							| 
									
										
										
										
											2016-06-20 14:49:24 +09:00
										 |  |  |   return [window_ attachedSheet] == nil; | 
					
						
							| 
									
										
										
										
											2016-06-17 17:38:44 +09:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-04-12 15:04:46 +08:00
										 |  |  | void NativeWindowMac::Maximize() { | 
					
						
							| 
									
										
										
										
											2016-04-23 01:15:00 +02:00
										 |  |  |   if (IsMaximized()) | 
					
						
							|  |  |  |     return; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-04-11 12:45:48 +08:00
										 |  |  |   [window_ zoom:nil]; | 
					
						
							| 
									
										
										
										
											2013-04-12 15:04:46 +08:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void NativeWindowMac::Unmaximize() { | 
					
						
							| 
									
										
										
										
											2016-04-23 01:15:00 +02:00
										 |  |  |   if (!IsMaximized()) | 
					
						
							|  |  |  |     return; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-04-11 12:45:48 +08:00
										 |  |  |   [window_ zoom:nil]; | 
					
						
							| 
									
										
										
										
											2013-04-12 15:04:46 +08:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-06-28 10:17:37 +09:00
										 |  |  | bool NativeWindowMac::IsMaximized() { | 
					
						
							| 
									
										
										
										
											2016-03-05 01:39:13 -05: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 23:58:49 +02:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-04-12 15:04:46 +08:00
										 |  |  | void NativeWindowMac::Minimize() { | 
					
						
							| 
									
										
										
										
											2014-04-11 12:45:48 +08:00
										 |  |  |   [window_ miniaturize:nil]; | 
					
						
							| 
									
										
										
										
											2013-04-12 15:04:46 +08:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void NativeWindowMac::Restore() { | 
					
						
							| 
									
										
										
										
											2014-04-11 12:45:48 +08:00
										 |  |  |   [window_ deminiaturize:nil]; | 
					
						
							| 
									
										
										
										
											2013-04-12 15:04:46 +08:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-07-26 13:58:26 +08:00
										 |  |  | bool NativeWindowMac::IsMinimized() { | 
					
						
							|  |  |  |   return [window_ isMiniaturized]; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-11-25 14:34:14 +08:00
										 |  |  | void NativeWindowMac::SetFullScreen(bool fullscreen) { | 
					
						
							| 
									
										
										
										
											2013-06-04 18:15:03 +08:00
										 |  |  |   if (fullscreen == IsFullscreen()) | 
					
						
							| 
									
										
										
										
											2013-04-12 15:04:46 +08:00
										 |  |  |     return; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-04-11 12:45:48 +08:00
										 |  |  |   [window_ toggleFullScreen:nil]; | 
					
						
							| 
									
										
										
										
											2013-04-12 15:04:46 +08:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-04-21 19:05:36 +05:30
										 |  |  | bool NativeWindowMac::IsFullscreen() const { | 
					
						
							| 
									
										
										
										
											2014-04-11 12:45:48 +08:00
										 |  |  |   return [window_ styleMask] & NSFullScreenWindowMask; | 
					
						
							| 
									
										
										
										
											2013-04-12 15:04:46 +08:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-01-15 05:54:12 +01:00
										 |  |  | void NativeWindowMac::SetBounds(const gfx::Rect& bounds, bool animate) { | 
					
						
							| 
									
										
										
										
											2016-07-11 16:44:42 +09:00
										 |  |  |   // Do nothing if in fullscreen mode. | 
					
						
							|  |  |  |   if (IsFullscreen()) | 
					
						
							|  |  |  |     return; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-07-07 20:02:18 +09:00
										 |  |  |   // Check size constraints since setFrame does not check it. | 
					
						
							|  |  |  |   gfx::Size size = bounds.size(); | 
					
						
							|  |  |  |   size.SetToMax(GetMinimumSize()); | 
					
						
							|  |  |  |   gfx::Size max_size = GetMaximumSize(); | 
					
						
							|  |  |  |   if (!max_size.IsEmpty()) | 
					
						
							|  |  |  |     size.SetToMin(max_size); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   NSRect cocoa_bounds = NSMakeRect(bounds.x(), 0, size.width(), size.height()); | 
					
						
							| 
									
										
										
										
											2015-05-01 20:10:46 +05:30
										 |  |  |   // Flip coordinates based on the primary screen. | 
					
						
							| 
									
										
										
										
											2016-12-20 13:49:35 -08:00
										 |  |  |   NSScreen* screen = [[NSScreen screens] firstObject]; | 
					
						
							| 
									
										
										
										
											2015-05-01 20:10:46 +05:30
										 |  |  |   cocoa_bounds.origin.y = | 
					
						
							| 
									
										
										
										
											2016-07-07 20:02:18 +09:00
										 |  |  |       NSHeight([screen frame]) - size.height() - bounds.y(); | 
					
						
							| 
									
										
										
										
											2015-05-01 20:10:46 +05:30
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-01-15 05:54:12 +01:00
										 |  |  |   [window_ setFrame:cocoa_bounds display:YES animate:animate]; | 
					
						
							| 
									
										
										
										
											2015-05-01 16:20:53 +05:30
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | gfx::Rect NativeWindowMac::GetBounds() { | 
					
						
							| 
									
										
										
										
											2015-05-01 20:10:46 +05:30
										 |  |  |   NSRect frame = [window_ frame]; | 
					
						
							| 
									
										
										
										
											2015-05-04 12:06:03 +08:00
										 |  |  |   gfx::Rect bounds(frame.origin.x, 0, NSWidth(frame), NSHeight(frame)); | 
					
						
							| 
									
										
										
										
											2016-12-20 13:49:35 -08:00
										 |  |  |   NSScreen* screen = [[NSScreen screens] firstObject]; | 
					
						
							| 
									
										
										
										
											2015-05-04 12:06:03 +08:00
										 |  |  |   bounds.set_y(NSHeight([screen frame]) - NSMaxY(frame)); | 
					
						
							|  |  |  |   return bounds; | 
					
						
							| 
									
										
										
										
											2015-05-01 16:20:53 +05:30
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-10-05 16:19:01 +08:00
										 |  |  | void NativeWindowMac::SetContentSizeConstraints( | 
					
						
							|  |  |  |     const extensions::SizeConstraints& size_constraints) { | 
					
						
							| 
									
										
										
										
											2015-10-06 15:15:23 +08: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 12:45:48 +08:00
										 |  |  |   NSView* content = [window_ contentView]; | 
					
						
							| 
									
										
										
										
											2015-10-05 16:19:01 +08:00
										 |  |  |   if (size_constraints.HasMinimumSize()) { | 
					
						
							| 
									
										
										
										
											2015-10-06 15:15:23 +08:00
										 |  |  |     NSSize min_size = convertSize(size_constraints.GetMinimumSize()); | 
					
						
							| 
									
										
										
										
											2015-10-05 20:09:29 +08:00
										 |  |  |     [window_ setContentMinSize:[content convertSize:min_size toView:nil]]; | 
					
						
							| 
									
										
										
										
											2015-10-05 16:19:01 +08:00
										 |  |  |   } | 
					
						
							|  |  |  |   if (size_constraints.HasMaximumSize()) { | 
					
						
							| 
									
										
										
										
											2015-10-06 15:15:23 +08:00
										 |  |  |     NSSize max_size = convertSize(size_constraints.GetMaximumSize()); | 
					
						
							| 
									
										
										
										
											2015-10-05 20:09:29 +08:00
										 |  |  |     [window_ setContentMaxSize:[content convertSize:max_size toView:nil]]; | 
					
						
							| 
									
										
										
										
											2015-10-05 16:19:01 +08:00
										 |  |  |   } | 
					
						
							|  |  |  |   NativeWindow::SetContentSizeConstraints(size_constraints); | 
					
						
							| 
									
										
										
										
											2013-04-18 15:38:04 +08:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-04-12 15:04:46 +08:00
										 |  |  | void NativeWindowMac::SetResizable(bool resizable) { | 
					
						
							| 
									
										
										
										
											2016-01-23 03:12:19 -08:00
										 |  |  |   SetStyleMask(resizable, NSResizableWindowMask); | 
					
						
							| 
									
										
										
										
											2013-04-12 15:04:46 +08:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-04-18 15:38:04 +08:00
										 |  |  | bool NativeWindowMac::IsResizable() { | 
					
						
							| 
									
										
										
										
											2014-04-11 12:45:48 +08:00
										 |  |  |   return [window_ styleMask] & NSResizableWindowMask; | 
					
						
							| 
									
										
										
										
											2013-04-18 15:38:04 +08:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-05-22 16:50:50 -07:00
										 |  |  | void NativeWindowMac::SetAspectRatio(double aspect_ratio, | 
					
						
							| 
									
										
										
										
											2016-05-22 18:36:05 -07:00
										 |  |  |                                      const gfx::Size& extra_size) { | 
					
						
							| 
									
										
										
										
											2016-07-11 16:43:01 +09:00
										 |  |  |   NativeWindow::SetAspectRatio(aspect_ratio, extra_size); | 
					
						
							| 
									
										
										
										
											2016-05-22 16:50:50 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-07-11 16:43:01 +09:00
										 |  |  |   // Reset the behaviour to default if aspect_ratio is set to 0 or less. | 
					
						
							|  |  |  |   if (aspect_ratio > 0.0) | 
					
						
							|  |  |  |     [window_ setAspectRatio:NSMakeSize(aspect_ratio, 1.0)]; | 
					
						
							|  |  |  |   else | 
					
						
							|  |  |  |     [window_ setResizeIncrements:NSMakeSize(1.0, 1.0)]; | 
					
						
							| 
									
										
										
										
											2016-05-22 16:50:50 -07:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-10-26 09:47:22 +09:00
										 |  |  | void NativeWindowMac::PreviewFile(const std::string& path, | 
					
						
							|  |  |  |                                   const std::string& display_name) { | 
					
						
							|  |  |  |   NSString* path_ns = [NSString stringWithUTF8String:path.c_str()]; | 
					
						
							|  |  |  |   NSString* name_ns = [NSString stringWithUTF8String:display_name.c_str()]; | 
					
						
							|  |  |  |   [window_ previewFileAtPath:path_ns withName:name_ns]; | 
					
						
							| 
									
										
										
										
											2016-10-11 18:08:01 -07:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-11-21 13:30:13 -05:00
										 |  |  | void NativeWindowMac::CloseFilePreview() { | 
					
						
							|  |  |  |   if ([QLPreviewPanel sharedPreviewPanelExists]) { | 
					
						
							|  |  |  |     [[QLPreviewPanel sharedPreviewPanel] close]; | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-01-18 23:46:35 +01:00
										 |  |  | void NativeWindowMac::SetMovable(bool movable) { | 
					
						
							|  |  |  |   [window_ setMovable:movable]; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | bool NativeWindowMac::IsMovable() { | 
					
						
							|  |  |  |   return [window_ isMovable]; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void NativeWindowMac::SetMinimizable(bool minimizable) { | 
					
						
							| 
									
										
										
										
											2016-01-23 03:12:19 -08:00
										 |  |  |   SetStyleMask(minimizable, NSMiniaturizableWindowMask); | 
					
						
							| 
									
										
										
										
											2016-01-18 23:46:35 +01:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | bool NativeWindowMac::IsMinimizable() { | 
					
						
							|  |  |  |   return [window_ styleMask] & NSMiniaturizableWindowMask; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-01-22 22:24:33 +01:00
										 |  |  | void NativeWindowMac::SetMaximizable(bool maximizable) { | 
					
						
							|  |  |  |   [[window_ standardWindowButton:NSWindowZoomButton] setEnabled:maximizable]; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | bool NativeWindowMac::IsMaximizable() { | 
					
						
							|  |  |  |   return [[window_ standardWindowButton:NSWindowZoomButton] isEnabled]; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-01-22 23:47:37 -08:00
										 |  |  | void NativeWindowMac::SetFullScreenable(bool fullscreenable) { | 
					
						
							| 
									
										
										
										
											2016-01-23 03:12:19 -08:00
										 |  |  |   SetCollectionBehavior( | 
					
						
							|  |  |  |       fullscreenable, NSWindowCollectionBehaviorFullScreenPrimary); | 
					
						
							|  |  |  |   // On EL Capitan this flag is required to hide fullscreen button. | 
					
						
							|  |  |  |   SetCollectionBehavior( | 
					
						
							|  |  |  |       !fullscreenable, NSWindowCollectionBehaviorFullScreenAuxiliary); | 
					
						
							| 
									
										
										
										
											2016-01-22 22:24:33 +01:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-01-22 23:47:37 -08:00
										 |  |  | bool NativeWindowMac::IsFullScreenable() { | 
					
						
							| 
									
										
										
										
											2016-01-23 03:12:19 -08:00
										 |  |  |   NSUInteger collectionBehavior = [window_ collectionBehavior]; | 
					
						
							|  |  |  |   return collectionBehavior & NSWindowCollectionBehaviorFullScreenPrimary; | 
					
						
							| 
									
										
										
										
											2016-01-22 22:24:33 +01:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-01-18 23:46:35 +01:00
										 |  |  | void NativeWindowMac::SetClosable(bool closable) { | 
					
						
							| 
									
										
										
										
											2016-01-23 03:12:19 -08:00
										 |  |  |   SetStyleMask(closable, NSClosableWindowMask); | 
					
						
							| 
									
										
										
										
											2016-01-18 23:46:35 +01:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | bool NativeWindowMac::IsClosable() { | 
					
						
							|  |  |  |   return [window_ styleMask] & NSClosableWindowMask; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-01-30 15:32:05 -08:00
										 |  |  | void NativeWindowMac::SetAlwaysOnTop(bool top, const std::string& level, | 
					
						
							|  |  |  |                                      int relativeLevel, std::string* error) { | 
					
						
							| 
									
										
										
										
											2016-09-22 09:22:28 -07:00
										 |  |  |   int windowLevel = NSNormalWindowLevel; | 
					
						
							| 
									
										
										
										
											2017-01-24 20:08:08 -08:00
										 |  |  |   CGWindowLevel maxWindowLevel = CGWindowLevelForKey(kCGMaximumWindowLevelKey); | 
					
						
							| 
									
										
										
										
											2017-01-26 19:12:10 -08:00
										 |  |  |   CGWindowLevel minWindowLevel = CGWindowLevelForKey(kCGMinimumWindowLevelKey); | 
					
						
							| 
									
										
										
										
											2017-02-07 09:32:40 -08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-09-22 09:22:28 -07:00
										 |  |  |   if (top) { | 
					
						
							|  |  |  |     if (level == "floating") { | 
					
						
							|  |  |  |       windowLevel = NSFloatingWindowLevel; | 
					
						
							|  |  |  |     } else if (level == "torn-off-menu") { | 
					
						
							|  |  |  |       windowLevel = NSTornOffMenuWindowLevel; | 
					
						
							|  |  |  |     } else if (level == "modal-panel") { | 
					
						
							|  |  |  |       windowLevel = NSModalPanelWindowLevel; | 
					
						
							|  |  |  |     } else if (level == "main-menu") { | 
					
						
							|  |  |  |       windowLevel = NSMainMenuWindowLevel; | 
					
						
							|  |  |  |     } else if (level == "status") { | 
					
						
							|  |  |  |       windowLevel = NSStatusWindowLevel; | 
					
						
							|  |  |  |     } else if (level == "pop-up-menu") { | 
					
						
							|  |  |  |       windowLevel = NSPopUpMenuWindowLevel; | 
					
						
							|  |  |  |     } else if (level == "screen-saver") { | 
					
						
							|  |  |  |       windowLevel = NSScreenSaverWindowLevel; | 
					
						
							|  |  |  |     } else if (level == "dock") { | 
					
						
							| 
									
										
										
										
											2016-12-06 22:48:40 +01:00
										 |  |  |       // Deprecated by macOS, but kept for backwards compatibility | 
					
						
							| 
									
										
										
										
											2016-09-22 09:22:28 -07:00
										 |  |  |       windowLevel = NSDockWindowLevel; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |   } | 
					
						
							| 
									
										
										
										
											2017-01-23 20:36:09 -08:00
										 |  |  | 
 | 
					
						
							|  |  |  |   NSInteger newLevel = windowLevel + relativeLevel; | 
					
						
							| 
									
										
										
										
											2017-01-26 19:12:10 -08:00
										 |  |  |   if (newLevel >= minWindowLevel && newLevel <= maxWindowLevel) { | 
					
						
							| 
									
										
										
										
											2017-01-23 20:36:09 -08:00
										 |  |  |     [window_ setLevel:newLevel]; | 
					
						
							|  |  |  |   } else { | 
					
						
							| 
									
										
										
										
											2017-01-24 20:08:08 -08:00
										 |  |  |     *error = std::string([[NSString stringWithFormat: | 
					
						
							| 
									
										
										
										
											2017-01-26 19:12:10 -08:00
										 |  |  |       @"relativeLevel must be between %d and %d", minWindowLevel, | 
					
						
							|  |  |  |       maxWindowLevel] UTF8String]); | 
					
						
							| 
									
										
										
										
											2017-01-23 20:36:09 -08:00
										 |  |  |   } | 
					
						
							| 
									
										
										
										
											2013-04-12 15:04:46 +08:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-04-18 15:38:04 +08:00
										 |  |  | bool NativeWindowMac::IsAlwaysOnTop() { | 
					
						
							| 
									
										
										
										
											2016-09-22 09:41:06 -07:00
										 |  |  |   return [window_ level] != NSNormalWindowLevel; | 
					
						
							| 
									
										
										
										
											2013-04-18 15:38:04 +08:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-05-10 20:34:05 +08:00
										 |  |  | void NativeWindowMac::Center() { | 
					
						
							| 
									
										
										
										
											2014-04-11 12:45:48 +08:00
										 |  |  |   [window_ center]; | 
					
						
							| 
									
										
										
										
											2013-04-12 15:04:46 +08:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-02-13 19:41:24 -08:00
										 |  |  | void NativeWindowMac::Invalidate() { | 
					
						
							|  |  |  |   [window_ flushWindow]; | 
					
						
							| 
									
										
										
										
											2017-02-14 11:09:15 -08:00
										 |  |  |   [[window_ contentView] setNeedsDisplay:YES]; | 
					
						
							| 
									
										
										
										
											2017-02-13 19:41:24 -08:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-04-12 15:04:46 +08:00
										 |  |  | void NativeWindowMac::SetTitle(const std::string& title) { | 
					
						
							| 
									
										
										
										
											2016-06-23 13:00:14 +09:00
										 |  |  |   // For macOS <= 10.9, the setTitleVisibility API is not available, we have | 
					
						
							|  |  |  |   // to avoid calling setTitle for frameless window. | 
					
						
							| 
									
										
										
										
											2017-02-07 09:32:40 -08:00
										 |  |  |   if (!base::mac::IsAtLeastOS10_10() && (transparent() || !has_frame())) | 
					
						
							| 
									
										
										
										
											2016-06-23 13:00:14 +09:00
										 |  |  |     return; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-06-17 10:54:50 +09:00
										 |  |  |   [window_ setTitle:base::SysUTF8ToNSString(title)]; | 
					
						
							| 
									
										
										
										
											2013-04-12 15:04:46 +08:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-04-18 14:30:05 +08:00
										 |  |  | std::string NativeWindowMac::GetTitle() { | 
					
						
							| 
									
										
										
										
											2016-06-17 10:54:50 +09:00
										 |  |  |   return base::SysNSStringToUTF8([window_ title]);; | 
					
						
							| 
									
										
										
										
											2013-04-18 14:30:05 +08:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-04-12 15:04:46 +08: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 10:29:51 +08:00
										 |  |  | void NativeWindowMac::SetSkipTaskbar(bool skip) { | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-04-12 15:04:46 +08:00
										 |  |  | void NativeWindowMac::SetKiosk(bool kiosk) { | 
					
						
							| 
									
										
										
										
											2014-06-09 13:04:59 +08:00
										 |  |  |   if (kiosk && !is_kiosk_) { | 
					
						
							|  |  |  |     kiosk_options_ = [NSApp currentSystemPresentationOptions]; | 
					
						
							| 
									
										
										
										
											2013-04-12 15:04:46 +08:00
										 |  |  |     NSApplicationPresentationOptions options = | 
					
						
							|  |  |  |         NSApplicationPresentationHideDock + | 
					
						
							| 
									
										
										
										
											2013-09-11 16:23:17 -04:00
										 |  |  |         NSApplicationPresentationHideMenuBar + | 
					
						
							| 
									
										
										
										
											2013-04-12 15:04:46 +08:00
										 |  |  |         NSApplicationPresentationDisableAppleMenu + | 
					
						
							|  |  |  |         NSApplicationPresentationDisableProcessSwitching + | 
					
						
							|  |  |  |         NSApplicationPresentationDisableForceQuit + | 
					
						
							|  |  |  |         NSApplicationPresentationDisableSessionTermination + | 
					
						
							|  |  |  |         NSApplicationPresentationDisableHideApplication; | 
					
						
							|  |  |  |     [NSApp setPresentationOptions:options]; | 
					
						
							|  |  |  |     is_kiosk_ = true; | 
					
						
							| 
									
										
										
										
											2017-01-14 00:04:51 +01:00
										 |  |  |     was_fullscreen_ = IsFullscreen(); | 
					
						
							| 
									
										
										
										
											2017-01-19 00:40:34 +01:00
										 |  |  |     if (!was_fullscreen_) SetFullScreen(true); | 
					
						
							| 
									
										
										
										
											2014-06-09 13:04:59 +08:00
										 |  |  |   } else if (!kiosk && is_kiosk_) { | 
					
						
							|  |  |  |     is_kiosk_ = false; | 
					
						
							| 
									
										
										
										
											2017-01-14 00:04:51 +01:00
										 |  |  |     if (!was_fullscreen_) SetFullScreen(false); | 
					
						
							| 
									
										
										
										
											2014-06-09 13:04:59 +08:00
										 |  |  |     [NSApp setPresentationOptions:kiosk_options_]; | 
					
						
							| 
									
										
										
										
											2013-04-12 15:04:46 +08:00
										 |  |  |   } | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | bool NativeWindowMac::IsKiosk() { | 
					
						
							|  |  |  |   return is_kiosk_; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-10-23 11:35:33 +08:00
										 |  |  | void NativeWindowMac::SetBackgroundColor(const std::string& color_name) { | 
					
						
							| 
									
										
										
										
											2016-04-14 21:52:17 +09:00
										 |  |  |   SkColor color = ParseHexColor(color_name); | 
					
						
							| 
									
										
										
										
											2016-09-06 17:24:37 +09:00
										 |  |  |   base::ScopedCFTypeRef<CGColorRef> cgcolor( | 
					
						
							|  |  |  |       skia::CGColorCreateFromSkColor(color)); | 
					
						
							| 
									
										
										
										
											2016-04-14 21:52:17 +09:00
										 |  |  |   [[[window_ contentView] layer] setBackgroundColor:cgcolor]; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   const auto view = web_contents()->GetRenderWidgetHostView(); | 
					
						
							|  |  |  |   if (view) | 
					
						
							|  |  |  |     view->SetBackgroundColor(color); | 
					
						
							| 
									
										
										
										
											2015-10-23 11:35:33 +08:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-01-23 01:15:49 +01:00
										 |  |  | void NativeWindowMac::SetHasShadow(bool has_shadow) { | 
					
						
							|  |  |  |   [window_ setHasShadow:has_shadow]; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | bool NativeWindowMac::HasShadow() { | 
					
						
							|  |  |  |   return [window_ hasShadow]; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-05-27 14:15:34 +08:00
										 |  |  | void NativeWindowMac::SetRepresentedFilename(const std::string& filename) { | 
					
						
							|  |  |  |   [window_ setRepresentedFilename:base::SysUTF8ToNSString(filename)]; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-07-18 21:42:26 +08:00
										 |  |  | std::string NativeWindowMac::GetRepresentedFilename() { | 
					
						
							|  |  |  |   return base::SysNSStringToUTF8([window_ representedFilename]); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-05-27 14:15:34 +08:00
										 |  |  | void NativeWindowMac::SetDocumentEdited(bool edited) { | 
					
						
							|  |  |  |   [window_ setDocumentEdited:edited]; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-07-24 15:48:33 +08:00
										 |  |  | bool NativeWindowMac::IsDocumentEdited() { | 
					
						
							|  |  |  |   return [window_ isDocumentEdited]; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-12-06 10:14:54 +08:00
										 |  |  | void NativeWindowMac::SetIgnoreMouseEvents(bool ignore) { | 
					
						
							|  |  |  |   [window_ setIgnoresMouseEvents:ignore]; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-06-22 10:40:01 +02:00
										 |  |  | void NativeWindowMac::SetContentProtection(bool enable) { | 
					
						
							|  |  |  |   [window_ setSharingType:enable ? NSWindowSharingNone | 
					
						
							|  |  |  |                                  : NSWindowSharingReadOnly]; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-06-17 15:28:43 +09:00
										 |  |  | void NativeWindowMac::SetParentWindow(NativeWindow* parent) { | 
					
						
							| 
									
										
										
										
											2016-06-20 14:49:24 +09:00
										 |  |  |   if (is_modal()) | 
					
						
							|  |  |  |     return; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   NativeWindow::SetParentWindow(parent); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-06-17 15:28:43 +09:00
										 |  |  |   // Remove current parent window. | 
					
						
							|  |  |  |   if ([window_ parentWindow]) | 
					
						
							|  |  |  |     [[window_ parentWindow] removeChildWindow:window_]; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   // Set new current window. | 
					
						
							|  |  |  |   if (parent) | 
					
						
							|  |  |  |     [parent->GetNativeWindow() addChildWindow:window_ ordered:NSWindowAbove]; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-05-03 19:31:24 +08:00
										 |  |  | gfx::NativeWindow NativeWindowMac::GetNativeWindow() { | 
					
						
							| 
									
										
										
										
											2014-04-11 12:45:48 +08:00
										 |  |  |   return window_; | 
					
						
							| 
									
										
										
										
											2013-05-03 19:31:24 +08:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-01-07 22:38:35 +02:00
										 |  |  | gfx::AcceleratedWidget NativeWindowMac::GetAcceleratedWidget() { | 
					
						
							| 
									
										
										
										
											2016-01-08 00:27:53 +02:00
										 |  |  |   return inspectable_web_contents()->GetView()->GetNativeView(); | 
					
						
							| 
									
										
										
										
											2016-01-07 22:38:35 +02:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-08-09 16:05:44 -07:00
										 |  |  | void NativeWindowMac::SetProgressBar(double progress, const NativeWindow::ProgressState state) { | 
					
						
							| 
									
										
										
										
											2014-09-17 15:58:08 +08:00
										 |  |  |   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]; | 
					
						
							| 
									
										
										
										
											2016-06-16 14:57:23 -07:00
										 |  |  |   } | 
					
						
							| 
									
										
										
										
											2014-09-17 15:58:08 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-06-16 14:57:23 -07:00
										 |  |  |   if ([[dock_tile.contentView subviews] count] == 0) { | 
					
						
							| 
									
										
										
										
											2014-09-17 15:58:08 +08:00
										 |  |  |     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]; | 
					
						
							| 
									
										
										
										
											2016-06-16 14:57:23 -07:00
										 |  |  |     [dock_tile.contentView addSubview:progress_indicator]; | 
					
						
							| 
									
										
										
										
											2014-09-17 15:58:08 +08:00
										 |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   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 18:56:03 +08:00
										 |  |  |     [progress_indicator setHidden:NO]; | 
					
						
							| 
									
										
										
										
											2014-09-17 15:58:08 +08:00
										 |  |  |     [progress_indicator setIndeterminate:YES]; | 
					
						
							| 
									
										
										
										
											2014-09-21 18:56:03 +08:00
										 |  |  |     [progress_indicator setDoubleValue:1]; | 
					
						
							| 
									
										
										
										
											2014-09-17 15:58:08 +08:00
										 |  |  |   } else { | 
					
						
							| 
									
										
										
										
											2014-09-21 18:56:03 +08:00
										 |  |  |     [progress_indicator setHidden:NO]; | 
					
						
							| 
									
										
										
										
											2014-09-17 15:58:08 +08:00
										 |  |  |     [progress_indicator setDoubleValue:progress]; | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  |   [dock_tile display]; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-02-10 17:14:26 -08:00
										 |  |  | void NativeWindowMac::SetOverlayIcon(const gfx::Image& overlay, | 
					
						
							|  |  |  |                                      const std::string& description) { | 
					
						
							| 
									
										
										
										
											2015-02-07 11:56:03 -08:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-03-26 14:18:37 +08:00
										 |  |  | void NativeWindowMac::SetVisibleOnAllWorkspaces(bool visible) { | 
					
						
							| 
									
										
										
										
											2016-01-23 03:12:19 -08:00
										 |  |  |   SetCollectionBehavior(visible, NSWindowCollectionBehaviorCanJoinAllSpaces); | 
					
						
							| 
									
										
										
										
											2015-03-26 14:18:37 +08:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | bool NativeWindowMac::IsVisibleOnAllWorkspaces() { | 
					
						
							| 
									
										
										
										
											2015-03-27 19:41:07 +08:00
										 |  |  |   NSUInteger collectionBehavior = [window_ collectionBehavior]; | 
					
						
							|  |  |  |   return collectionBehavior & NSWindowCollectionBehaviorCanJoinAllSpaces; | 
					
						
							| 
									
										
										
										
											2015-03-26 14:18:37 +08:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-11-28 11:38:40 -08:00
										 |  |  | void NativeWindowMac::SetAutoHideCursor(bool auto_hide) { | 
					
						
							|  |  |  |   [window_ setDisableAutoHideCursor:!auto_hide]; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-11-07 21:22:41 +01:00
										 |  |  | void NativeWindowMac::SetVibrancy(const std::string& type) { | 
					
						
							| 
									
										
										
										
											2017-01-23 19:05:49 +09:00
										 |  |  |   if (!base::mac::IsOS10_10()) return; | 
					
						
							| 
									
										
										
										
											2016-11-07 21:22:41 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-11-10 20:36:21 +01:00
										 |  |  |   NSView* vibrant_view = [window_ vibrantView]; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-11-10 11:59:25 +01:00
										 |  |  |   if (type.empty()) { | 
					
						
							| 
									
										
										
										
											2016-11-10 20:36:21 +01:00
										 |  |  |     if (vibrant_view == nil) return; | 
					
						
							| 
									
										
										
										
											2016-11-10 11:59:25 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-11-10 20:36:21 +01:00
										 |  |  |     [vibrant_view removeFromSuperview]; | 
					
						
							|  |  |  |     [window_ setVibrantView:nil]; | 
					
						
							| 
									
										
										
										
											2016-11-10 11:59:25 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  |     return; | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-11-10 20:36:21 +01:00
										 |  |  |   NSVisualEffectView* effect_view = (NSVisualEffectView*)vibrant_view; | 
					
						
							| 
									
										
										
										
											2016-11-10 11:59:25 +01:00
										 |  |  |   if (effect_view == nil) { | 
					
						
							| 
									
										
										
										
											2016-11-11 08:44:11 -08:00
										 |  |  |     effect_view = [[[NSVisualEffectView alloc] | 
					
						
							|  |  |  |         initWithFrame: [[window_ contentView] bounds]] autorelease]; | 
					
						
							| 
									
										
										
										
											2016-11-10 20:36:21 +01:00
										 |  |  |     [window_ setVibrantView:(NSView*)effect_view]; | 
					
						
							| 
									
										
										
										
											2016-11-07 21:22:41 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-11-11 08:44:26 -08:00
										 |  |  |     [effect_view setAutoresizingMask:NSViewWidthSizable | NSViewHeightSizable]; | 
					
						
							| 
									
										
										
										
											2016-11-10 11:59:25 +01:00
										 |  |  |     [effect_view setBlendingMode:NSVisualEffectBlendingModeBehindWindow]; | 
					
						
							|  |  |  |     [effect_view setState:NSVisualEffectStateActive]; | 
					
						
							|  |  |  |     [[window_ contentView] addSubview:effect_view | 
					
						
							| 
									
										
										
										
											2016-11-07 21:22:41 +01:00
										 |  |  |                            positioned:NSWindowBelow | 
					
						
							|  |  |  |                            relativeTo:nil]; | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   NSVisualEffectMaterial vibrancyType = NSVisualEffectMaterialLight; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   if (type == "appearance-based") { | 
					
						
							|  |  |  |     vibrancyType = NSVisualEffectMaterialAppearanceBased; | 
					
						
							|  |  |  |   } else if (type == "light") { | 
					
						
							|  |  |  |     vibrancyType = NSVisualEffectMaterialLight; | 
					
						
							|  |  |  |   } else if (type == "dark") { | 
					
						
							|  |  |  |     vibrancyType = NSVisualEffectMaterialDark; | 
					
						
							|  |  |  |   } else if (type == "titlebar") { | 
					
						
							|  |  |  |     vibrancyType = NSVisualEffectMaterialTitlebar; | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-02-07 09:32:40 -08:00
										 |  |  |   if (base::mac::IsAtLeastOS10_11()) { | 
					
						
							| 
									
										
										
										
											2016-11-14 16:06:42 -08:00
										 |  |  |     // TODO(kevinsawicki): Use NSVisualEffectMaterial* constants directly once | 
					
						
							|  |  |  |     // they are available in the minimum SDK version | 
					
						
							| 
									
										
										
										
											2016-11-07 21:22:41 +01:00
										 |  |  |     if (type == "selection") { | 
					
						
							| 
									
										
										
										
											2016-11-14 16:06:42 -08:00
										 |  |  |       // NSVisualEffectMaterialSelection | 
					
						
							|  |  |  |       vibrancyType = (NSVisualEffectMaterial) 4; | 
					
						
							| 
									
										
										
										
											2016-11-07 21:22:41 +01:00
										 |  |  |     } else if (type == "menu") { | 
					
						
							| 
									
										
										
										
											2016-11-14 16:06:42 -08:00
										 |  |  |       // NSVisualEffectMaterialMenu | 
					
						
							|  |  |  |       vibrancyType = (NSVisualEffectMaterial) 5; | 
					
						
							| 
									
										
										
										
											2016-11-07 21:22:41 +01:00
										 |  |  |     } else if (type == "popover") { | 
					
						
							| 
									
										
										
										
											2016-11-14 16:06:42 -08:00
										 |  |  |       // NSVisualEffectMaterialPopover | 
					
						
							|  |  |  |       vibrancyType = (NSVisualEffectMaterial) 6; | 
					
						
							| 
									
										
										
										
											2016-11-07 21:22:41 +01:00
										 |  |  |     } else if (type == "sidebar") { | 
					
						
							| 
									
										
										
										
											2016-11-14 16:06:42 -08:00
										 |  |  |       // NSVisualEffectMaterialSidebar | 
					
						
							|  |  |  |       vibrancyType = (NSVisualEffectMaterial) 7; | 
					
						
							| 
									
										
										
										
											2016-11-07 21:22:41 +01:00
										 |  |  |     } else if (type == "medium-light") { | 
					
						
							| 
									
										
										
										
											2016-11-14 16:06:42 -08:00
										 |  |  |       // NSVisualEffectMaterialMediumLight | 
					
						
							|  |  |  |       vibrancyType = (NSVisualEffectMaterial) 8; | 
					
						
							| 
									
										
										
										
											2016-11-07 21:22:41 +01:00
										 |  |  |     } else if (type == "ultra-dark") { | 
					
						
							| 
									
										
										
										
											2016-11-14 16:06:42 -08:00
										 |  |  |       // NSVisualEffectMaterialUltraDark | 
					
						
							|  |  |  |       vibrancyType = (NSVisualEffectMaterial) 9; | 
					
						
							| 
									
										
										
										
											2016-11-07 21:22:41 +01:00
										 |  |  |     } | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-11-10 11:59:25 +01:00
										 |  |  |   [effect_view setMaterial:vibrancyType]; | 
					
						
							| 
									
										
										
										
											2016-11-07 21:22:41 +01:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-08-08 16:33:16 +09:00
										 |  |  | void NativeWindowMac::OnInputEvent(const blink::WebInputEvent& event) { | 
					
						
							|  |  |  |   switch (event.type) { | 
					
						
							|  |  |  |     case blink::WebInputEvent::GestureScrollBegin: | 
					
						
							|  |  |  |     case blink::WebInputEvent::GestureScrollUpdate: | 
					
						
							|  |  |  |     case blink::WebInputEvent::GestureScrollEnd: | 
					
						
							| 
									
										
										
										
											2016-09-17 22:29:32 +08:00
										 |  |  |         this->NotifyWindowScrollTouchEdge(); | 
					
						
							| 
									
										
										
										
											2016-08-08 16:33:16 +09:00
										 |  |  |       break; | 
					
						
							|  |  |  |     default: | 
					
						
							|  |  |  |       break; | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void NativeWindowMac::RenderViewHostChanged( | 
					
						
							|  |  |  |     content::RenderViewHost* old_host, | 
					
						
							|  |  |  |     content::RenderViewHost* new_host) { | 
					
						
							|  |  |  |   UnregisterInputEventObserver(old_host); | 
					
						
							|  |  |  |   RegisterInputEventObserver(new_host); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-10-21 07:33:43 +08: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 { | 
					
						
							| 
									
										
										
										
											2016-05-23 10:59:39 +09:00
										 |  |  |     std::unique_ptr<SkRegion> draggable(DraggableRegionsToSkRegion(regions)); | 
					
						
							|  |  |  |     std::unique_ptr<SkRegion> non_draggable(new SkRegion); | 
					
						
							| 
									
										
										
										
											2015-10-21 07:33:43 +08:00
										 |  |  |     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; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-08-04 10:58:59 -07:00
										 |  |  | gfx::Rect NativeWindowMac::ContentBoundsToWindowBounds( | 
					
						
							|  |  |  |     const gfx::Rect& bounds) { | 
					
						
							| 
									
										
										
										
											2016-08-04 12:02:24 -07:00
										 |  |  |   if (has_frame()) { | 
					
						
							|  |  |  |     gfx::Rect window_bounds( | 
					
						
							|  |  |  |         [window_ frameRectForContentRect:bounds.ToCGRect()]); | 
					
						
							|  |  |  |     int frame_height = window_bounds.height() - bounds.height(); | 
					
						
							|  |  |  |     window_bounds.set_y(window_bounds.y() - frame_height); | 
					
						
							|  |  |  |     return window_bounds; | 
					
						
							|  |  |  |   } else { | 
					
						
							| 
									
										
										
										
											2016-08-04 10:58:59 -07:00
										 |  |  |     return bounds; | 
					
						
							| 
									
										
										
										
											2016-08-04 12:02:24 -07:00
										 |  |  |   } | 
					
						
							| 
									
										
										
										
											2015-10-05 16:19:01 +08:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-08-04 10:58:59 -07:00
										 |  |  | gfx::Rect NativeWindowMac::WindowBoundsToContentBounds( | 
					
						
							|  |  |  |     const gfx::Rect& bounds) { | 
					
						
							|  |  |  |   if (has_frame()) { | 
					
						
							|  |  |  |     gfx::Rect content_bounds( | 
					
						
							|  |  |  |         [window_ contentRectForFrameRect:bounds.ToCGRect()]); | 
					
						
							|  |  |  |     int frame_height = bounds.height() - content_bounds.height(); | 
					
						
							|  |  |  |     content_bounds.set_y(content_bounds.y() + frame_height); | 
					
						
							|  |  |  |     return content_bounds; | 
					
						
							|  |  |  |   } else { | 
					
						
							|  |  |  |     return bounds; | 
					
						
							|  |  |  |   } | 
					
						
							| 
									
										
										
										
											2015-10-05 16:19:01 +08:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-10-21 07:33:43 +08:00
										 |  |  | void NativeWindowMac::UpdateDraggableRegions( | 
					
						
							|  |  |  |     const std::vector<DraggableRegion>& regions) { | 
					
						
							|  |  |  |   NativeWindow::UpdateDraggableRegions(regions); | 
					
						
							|  |  |  |   draggable_regions_ = regions; | 
					
						
							|  |  |  |   UpdateDraggableRegionViews(regions); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-08-15 21:36:57 +02:00
										 |  |  | void NativeWindowMac::ShowWindowButton(NSWindowButton button) { | 
					
						
							|  |  |  |   auto view = [window_ standardWindowButton:button]; | 
					
						
							|  |  |  |   [view.superview addSubview:view positioned:NSWindowAbove relativeTo:nil]; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-04-12 15:04:46 +08:00
										 |  |  | void NativeWindowMac::InstallView() { | 
					
						
							| 
									
										
										
										
											2016-12-08 12:12:53 +09:00
										 |  |  |   // Make sure the bottom corner is rounded for non-modal windows: http://crbug.com/396264. | 
					
						
							| 
									
										
										
										
											2016-07-12 15:01:37 +09:00
										 |  |  |   // But do not enable it on OS X 10.9 for transparent window, otherwise a | 
					
						
							|  |  |  |   // semi-transparent frame would show. | 
					
						
							| 
									
										
										
										
											2017-01-23 19:05:49 +09:00
										 |  |  |   if (!(transparent() && base::mac::IsOS10_9()) && !is_modal()) | 
					
						
							| 
									
										
										
										
											2016-07-12 15:01:37 +09:00
										 |  |  |     [[window_ contentView] setWantsLayer:YES]; | 
					
						
							| 
									
										
										
										
											2015-08-26 15:45:38 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-04-12 16:41:15 +08:00
										 |  |  |   NSView* view = inspectable_web_contents()->GetView()->GetNativeView(); | 
					
						
							| 
									
										
										
										
											2015-08-05 12:46:32 +08:00
										 |  |  |   if (has_frame()) { | 
					
						
							| 
									
										
										
										
											2014-04-11 12:45:48 +08:00
										 |  |  |     [view setFrame:[[window_ contentView] bounds]]; | 
					
						
							|  |  |  |     [[window_ contentView] addSubview:view]; | 
					
						
							| 
									
										
										
										
											2013-09-05 23:52:29 +08:00
										 |  |  |   } else { | 
					
						
							| 
									
										
										
										
											2015-08-26 15:45:38 +08: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 16:23:17 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-07-11 15:58:07 +09:00
										 |  |  |     // The fullscreen button should always be hidden for frameless window. | 
					
						
							|  |  |  |     [[window_ standardWindowButton:NSWindowFullScreenButton] setHidden:YES]; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-08-15 21:36:57 +02:00
										 |  |  |     if (title_bar_style_ != NORMAL) { | 
					
						
							| 
									
										
										
										
											2017-01-23 19:05:49 +09:00
										 |  |  |       if (base::mac::IsOS10_9()) { | 
					
						
							| 
									
										
										
										
											2016-08-15 21:36:57 +02:00
										 |  |  |         ShowWindowButton(NSWindowZoomButton); | 
					
						
							|  |  |  |         ShowWindowButton(NSWindowMiniaturizeButton); | 
					
						
							|  |  |  |         ShowWindowButton(NSWindowCloseButton); | 
					
						
							|  |  |  |       } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-05-17 15:48:14 +09:00
										 |  |  |       return; | 
					
						
							| 
									
										
										
										
											2016-08-15 21:36:57 +02:00
										 |  |  |     } | 
					
						
							| 
									
										
										
										
											2016-05-17 15:48:14 +09:00
										 |  |  | 
 | 
					
						
							|  |  |  |     // Hide the window buttons. | 
					
						
							| 
									
										
										
										
											2014-04-11 12:45:48 +08:00
										 |  |  |     [[window_ standardWindowButton:NSWindowZoomButton] setHidden:YES]; | 
					
						
							|  |  |  |     [[window_ standardWindowButton:NSWindowMiniaturizeButton] setHidden:YES]; | 
					
						
							|  |  |  |     [[window_ standardWindowButton:NSWindowCloseButton] setHidden:YES]; | 
					
						
							| 
									
										
										
										
											2014-12-23 15:50:42 -08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-06-18 15:26:26 +02:00
										 |  |  |     // Some third-party macOS utilities check the zoom button's enabled state to | 
					
						
							| 
									
										
										
										
											2014-12-23 15:50:42 -08:00
										 |  |  |     // 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 23:52:29 +08:00
										 |  |  |   } | 
					
						
							| 
									
										
										
										
											2013-04-12 15:04:46 +08:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void NativeWindowMac::UninstallView() { | 
					
						
							| 
									
										
										
										
											2013-09-06 11:54:52 +08:00
										 |  |  |   NSView* view = inspectable_web_contents()->GetView()->GetNativeView(); | 
					
						
							| 
									
										
										
										
											2013-04-12 15:04:46 +08:00
										 |  |  |   [view removeFromSuperview]; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-10-21 07:33:43 +08:00
										 |  |  | void NativeWindowMac::UpdateDraggableRegionViews( | 
					
						
							|  |  |  |     const std::vector<DraggableRegion>& regions) { | 
					
						
							| 
									
										
										
										
											2016-05-17 15:48:14 +09:00
										 |  |  |   if (has_frame()) | 
					
						
							| 
									
										
										
										
											2015-10-21 07:33:43 +08: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 14:54:00 +08:00
										 |  |  |   NSView* webView = web_contents()->GetNativeView(); | 
					
						
							| 
									
										
										
										
											2015-10-21 07:33:43 +08:00
										 |  |  |   NSInteger webViewWidth = NSWidth([webView bounds]); | 
					
						
							|  |  |  |   NSInteger webViewHeight = NSHeight([webView bounds]); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-08-04 12:00:35 +02:00
										 |  |  |   if ([webView respondsToSelector:@selector(setMouseDownCanMoveWindow:)]) { | 
					
						
							|  |  |  |     [webView setMouseDownCanMoveWindow:YES]; | 
					
						
							|  |  |  |   } | 
					
						
							| 
									
										
										
										
											2015-10-21 07:33:43 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  |   // 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 23:52:29 +08:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-01-23 03:12:19 -08:00
										 |  |  | void NativeWindowMac::SetStyleMask(bool on, NSUInteger flag) { | 
					
						
							| 
									
										
										
										
											2016-08-15 13:14:19 -07:00
										 |  |  |   // Changing the styleMask of a frameless windows causes it to change size so | 
					
						
							|  |  |  |   // we explicitly disable resizing while setting it. | 
					
						
							|  |  |  |   ScopedDisableResize disable_resize; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-08-04 16:47:03 -07:00
										 |  |  |   bool was_maximizable = IsMaximizable(); | 
					
						
							| 
									
										
										
										
											2016-01-23 03:12:19 -08:00
										 |  |  |   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 | 
					
						
							| 
									
										
										
										
											2016-06-18 15:26:26 +02:00
										 |  |  |   // a bug of Cocoa or macOS. | 
					
						
							| 
									
										
										
										
											2016-08-04 16:47:03 -07:00
										 |  |  |   SetMaximizable(was_maximizable); | 
					
						
							| 
									
										
										
										
											2016-01-23 03:12:19 -08:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void NativeWindowMac::SetCollectionBehavior(bool on, NSUInteger flag) { | 
					
						
							| 
									
										
										
										
											2016-08-04 16:47:03 -07:00
										 |  |  |   bool was_maximizable = IsMaximizable(); | 
					
						
							| 
									
										
										
										
											2016-01-23 03:12:19 -08:00
										 |  |  |   if (on) | 
					
						
							|  |  |  |     [window_ setCollectionBehavior:[window_ collectionBehavior] | flag]; | 
					
						
							|  |  |  |   else | 
					
						
							|  |  |  |     [window_ setCollectionBehavior:[window_ collectionBehavior] & (~flag)]; | 
					
						
							|  |  |  |   // Change collectionBehavior will make the zoom button revert to default, | 
					
						
							| 
									
										
										
										
											2016-06-18 15:26:26 +02:00
										 |  |  |   // probably a bug of Cocoa or macOS. | 
					
						
							| 
									
										
										
										
											2016-08-04 16:47:03 -07:00
										 |  |  |   SetMaximizable(was_maximizable); | 
					
						
							| 
									
										
										
										
											2016-01-23 03:12:19 -08:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-08-08 16:33:16 +09:00
										 |  |  | void NativeWindowMac::RegisterInputEventObserver( | 
					
						
							|  |  |  |     content::RenderViewHost* host) { | 
					
						
							|  |  |  |   if (host) | 
					
						
							|  |  |  |     host->GetWidget()->AddInputEventObserver(this); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void NativeWindowMac::UnregisterInputEventObserver( | 
					
						
							|  |  |  |     content::RenderViewHost* host) { | 
					
						
							|  |  |  |   if (host) | 
					
						
							|  |  |  |     host->GetWidget()->RemoveInputEventObserver(this); | 
					
						
							| 
									
										
										
										
											2016-08-01 18:01:21 +08:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-04-12 15:04:46 +08:00
										 |  |  | // static | 
					
						
							| 
									
										
										
										
											2015-06-25 09:47:57 +08:00
										 |  |  | NativeWindow* NativeWindow::Create( | 
					
						
							|  |  |  |     brightray::InspectableWebContents* inspectable_web_contents, | 
					
						
							| 
									
										
										
										
											2016-06-19 12:06:08 +09:00
										 |  |  |     const mate::Dictionary& options, | 
					
						
							|  |  |  |     NativeWindow* parent) { | 
					
						
							|  |  |  |   return new NativeWindowMac(inspectable_web_contents, options, parent); | 
					
						
							| 
									
										
										
										
											2013-04-12 15:04:46 +08:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | }  // namespace atom |