]> khamidou — GitHub mirrors - electron.git/commitdiff
Add "enable-larger-than-screen" option for BrowserWindow.
authorCheng Zhao <zcbenz@gmail.com>
Sun, 17 Aug 2014 04:23:00 +0000 (12:23 +0800)
committerCheng Zhao <zcbenz@gmail.com>
Sun, 17 Aug 2014 04:23:00 +0000 (12:23 +0800)
From now on BrowserWindow can only be resized larger than screen or
moved out of screen when this option is set to "true".

Fixes #582.

atom/browser/native_window.cc
atom/browser/native_window.h
atom/browser/native_window_mac.mm
atom/browser/native_window_views.cc
atom/common/options_switches.cc
atom/common/options_switches.h
docs/api/browser-window.md
spec/api-browser-window-spec.coffee

index 163c0f5f2858c9e5afb3add63e688cdb84eb53c4..d39300121de8aa1691ea51bcae8104abb31e8fbd 100644 (file)
@@ -58,6 +58,7 @@ NativeWindow::NativeWindow(content::WebContents* web_contents,
                            const mate::Dictionary& options)
     : content::WebContentsObserver(web_contents),
       has_frame_(true),
+      enable_larger_than_screen_(false),
       is_closed_(false),
       node_integration_("except-iframe"),
       has_dialog_attached_(false),
@@ -66,6 +67,7 @@ NativeWindow::NativeWindow(content::WebContents* web_contents,
       inspectable_web_contents_(
           brightray::InspectableWebContents::Create(web_contents)) {
   options.Get(switches::kFrame, &has_frame_);
+  options.Get(switches::kEnableLargerThanScreen, &enable_larger_than_screen_);
 
   // Read icon before window is created.
   options.Get(switches::kIcon, &icon_);
index 5dccb365ae1feb403b256b822600e09b24bb8b4e..8a207cdc5d2a57ad857d6f11dd1cec8c1f35857f 100644 (file)
@@ -251,6 +251,9 @@ class NativeWindow : public brightray::DefaultWebContentsDelegate,
   // Whether window has standard frame.
   bool has_frame_;
 
+  // Whether window can be resized larger than screen.
+  bool enable_larger_than_screen_;
+
   // Window icon.
   gfx::ImageSkia icon_;
 
index 6f59187ce5fd2fe04bb0a8dfdcc9548f18f8d483..d1139f4558e60def3dd173b5656094cfc235710d 100644 (file)
@@ -108,10 +108,12 @@ static const CGFloat kAtomWindowCornerRadius = 4.0;
 @end
 
 @interface AtomNSWindow : EventProcessingWindow {
- @protected
+ @private
   atom::NativeWindowMac* shell_;
+  bool enable_larger_than_screen_;
 }
 - (void)setShell:(atom::NativeWindowMac*)shell;
+- (void)setEnableLargerThanScreen:(bool)enable;
 @end
 
 @implementation AtomNSWindow
@@ -120,9 +122,16 @@ static const CGFloat kAtomWindowCornerRadius = 4.0;
   shell_ = shell;
 }
 
+- (void)setEnableLargerThanScreen:(bool)enable {
+  enable_larger_than_screen_ = enable;
+}
+
 // Enable the window to be larger than screen.
 - (NSRect)constrainFrameRect:(NSRect)frameRect toScreen:(NSScreen*)screen {
-  return frameRect;
+  if (enable_larger_than_screen_)
+    return frameRect;
+  else
+    return [super constrainFrameRect:frameRect toScreen:screen];
 }
 
 - (IBAction)reload:(id)sender {
@@ -213,6 +222,7 @@ NativeWindowMac::NativeWindowMac(content::WebContents* web_contents,
                     defer:YES];
 
   [atomWindow setShell:this];
+  [atomWindow setEnableLargerThanScreen:enable_larger_than_screen_];
   window_.reset(atomWindow);
 
   AtomNSWindowDelegate* delegate =
index 09b65ac77b008e78c24454f90da612b8acc608d5..b6862348911e601ef68ba2f96f75aacd56c605ea 100644 (file)
@@ -114,16 +114,18 @@ NativeWindowViews::NativeWindowViews(content::WebContents* web_contents,
       menu_bar_alt_pressed_(false),
       keyboard_event_handler_(new views::UnhandledKeyboardEventHandler),
       use_content_size_(false),
-      resizable_(true),
-      // We need to set a default maximum window size here otherwise Windows
-      // will not allow us to resize the window larger than scree.
-      // Setting directly to INT_MAX somehow doesn't work, so we just devide
-      // by 10, which should still be large enough.
-      maximum_size_(INT_MAX / 10, INT_MAX / 10) {
+      resizable_(true) {
   options.Get(switches::kResizable, &resizable_);
   options.Get(switches::kTitle, &title_);
   options.Get(switches::kAutoHideMenuBar, &menu_bar_autohide_);
 
+  if (enable_larger_than_screen_)
+    // We need to set a default maximum window size here otherwise Windows
+    // will not allow us to resize the window larger than scree.
+    // Setting directly to INT_MAX somehow doesn't work, so we just devide
+    // by 10, which should still be large enough.
+    maximum_size_.set(INT_MAX / 10, INT_MAX / 10);
+
   int width = 800, height = 600;
   options.Get(switches::kWidth, &width);
   options.Get(switches::kHeight, &height);
index 8aa7638f45419251f974472d172ae41a0752913b..cfde597a9be1bb7b1ebb3c530aa88b6e26840fcf 100644 (file)
@@ -51,6 +51,9 @@ const char kZoomFactor[] = "zoom-factor";
 // The menu bar is hidden unless "Alt" is pressed.
 const char kAutoHideMenuBar[] = "auto-hide-menu-bar";
 
+// Enable window to be resized larger than screen.
+const char kEnableLargerThanScreen[] = "enable-larger-than-screen";
+
 }  // namespace switches
 
 }  // namespace atom
index f9e202d97e384af516a392f0fb9729ae703456cc..8c6cd072df46a20798a762f0481266e068128248 100644 (file)
@@ -33,6 +33,7 @@ extern const char kUseContentSize[];
 extern const char kWebPreferences[];
 extern const char kZoomFactor[];
 extern const char kAutoHideMenuBar[];
+extern const char kEnableLargerThanScreen[];
 
 }  // namespace switches
 
index 3b9e7f0d09d7e546a3e882e4ec35c63261136675..dc85eac1d58a06ccb9fdb5b52273a7b98072e5f5 100644 (file)
@@ -61,6 +61,8 @@ normal browsers, see [Web Security](web-security.md) for more.
      mouse-down event that simultaneously activates the window
   * `auto-hide-menu-bar` Boolean - Auto hide the menu bar unless the `Alt`
     key is pressed.
+  * `enable-larger-than-screen` Boolean - Enable the window to be resized larger
+    than screen.
   * `web-preferences` Object - Settings of web page's features
     * `javascript` Boolean
     * `web-security` Boolean
index e295f0a54494aa987041225fb1138c8563ba70a2..e649ae291bc612f0c38208e89dc585028b698c79 100644 (file)
@@ -76,15 +76,6 @@ describe 'browser-window module', ->
       assert.equal after[0], size[0]
       assert.equal after[1], size[1]
 
-    it 'can set the window larger than screen', ->
-      size = require('screen').getPrimaryDisplay().size
-      size.width += 100
-      size.height += 100
-      w.setSize size.width, size.height
-      after = w.getSize()
-      assert.equal after[0], size.width
-      assert.equal after[1], size.height
-
   describe 'BrowserWindow.setContentSize(width, height)', ->
     it 'sets the content size', ->
       size = [400, 400]
@@ -110,6 +101,26 @@ describe 'browser-window module', ->
       assert.equal size[0], 400
       assert.equal size[1], 400
 
+  describe '"enable-larger-than-screen" option', ->
+    beforeEach ->
+      w.destroy()
+      w = new BrowserWindow(show: true, width: 400, height: 400, 'enable-larger-than-screen': true)
+
+    it 'can move the window out of screen', ->
+      w.setPosition -10, -10
+      after = w.getPosition()
+      assert.equal after[0], -10
+      assert.equal after[1], -10
+
+    it 'can set the window larger than screen', ->
+      size = require('screen').getPrimaryDisplay().size
+      size.width += 100
+      size.height += 100
+      w.setSize size.width, size.height
+      after = w.getSize()
+      assert.equal after[0], size.width
+      assert.equal after[1], size.height
+
   describe 'beforeunload handler', ->
     it 'returning true would not prevent close', (done) ->
       w.on 'closed', ->