Merge pull request #3537 from etiktin/make_BrowserWindow_options_optional
Make BrowserWindow options argument optional
This commit is contained in:
commit
634fef2508
4 changed files with 79 additions and 48 deletions
|
@ -261,13 +261,23 @@ void Window::OnWindowMessage(UINT message, WPARAM w_param, LPARAM l_param) {
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// static
|
// static
|
||||||
mate::Wrappable* Window::New(v8::Isolate* isolate,
|
mate::Wrappable* Window::New(v8::Isolate* isolate, mate::Arguments* args) {
|
||||||
const mate::Dictionary& options) {
|
|
||||||
if (!Browser::Get()->is_ready()) {
|
if (!Browser::Get()->is_ready()) {
|
||||||
isolate->ThrowException(v8::Exception::Error(mate::StringToV8(
|
isolate->ThrowException(v8::Exception::Error(mate::StringToV8(
|
||||||
isolate, "Cannot create BrowserWindow before app is ready")));
|
isolate, "Cannot create BrowserWindow before app is ready")));
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (args->Length() > 1) {
|
||||||
|
args->ThrowError();
|
||||||
|
return nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
|
mate::Dictionary options;
|
||||||
|
if (!(args->Length() == 1 && args->GetNext(&options))) {
|
||||||
|
options = mate::Dictionary::CreateEmpty(isolate);
|
||||||
|
}
|
||||||
|
|
||||||
return new Window(isolate, options);
|
return new Window(isolate, options);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -38,8 +38,7 @@ class WebContents;
|
||||||
class Window : public mate::TrackableObject<Window>,
|
class Window : public mate::TrackableObject<Window>,
|
||||||
public NativeWindowObserver {
|
public NativeWindowObserver {
|
||||||
public:
|
public:
|
||||||
static mate::Wrappable* New(v8::Isolate* isolate,
|
static mate::Wrappable* New(v8::Isolate* isolate, mate::Arguments* args);
|
||||||
const mate::Dictionary& options);
|
|
||||||
|
|
||||||
static void BuildPrototype(v8::Isolate* isolate,
|
static void BuildPrototype(v8::Isolate* isolate,
|
||||||
v8::Local<v8::ObjectTemplate> prototype);
|
v8::Local<v8::ObjectTemplate> prototype);
|
||||||
|
|
|
@ -25,49 +25,58 @@ You can also create a window without chrome by using
|
||||||
|
|
||||||
It creates a new `BrowserWindow` with native properties as set by the `options`.
|
It creates a new `BrowserWindow` with native properties as set by the `options`.
|
||||||
|
|
||||||
### `new BrowserWindow(options)`
|
### `new BrowserWindow([options])`
|
||||||
|
|
||||||
`options` Object, properties:
|
`options` Object (optional), properties:
|
||||||
|
|
||||||
* `width` Integer - Window's width.
|
* `width` Integer - Window's width in pixels. Default is `800`.
|
||||||
* `height` Integer - Window's height.
|
* `height` Integer - Window's height in pixels. Default is `600`.
|
||||||
* `x` Integer - Window's left offset from screen.
|
* `x` Integer - Window's left offset from screen. Default is to center the
|
||||||
* `y` Integer - Window's top offset from screen.
|
window.
|
||||||
|
* `y` Integer - Window's top offset from screen. Default is to center the
|
||||||
|
window.
|
||||||
* `useContentSize` Boolean - The `width` and `height` would be used as web
|
* `useContentSize` Boolean - The `width` and `height` would be used as web
|
||||||
page's size, which means the actual window's size will include window
|
page's size, which means the actual window's size will include window
|
||||||
frame's size and be slightly larger.
|
frame's size and be slightly larger. Default is `false`.
|
||||||
* `center` Boolean - Show window in the center of the screen.
|
* `center` Boolean - Show window in the center of the screen.
|
||||||
* `minWidth` Integer - Window's minimum width.
|
* `minWidth` Integer - Window's minimum width. Default is `0`.
|
||||||
* `minHeight` Integer - Window's minimum height.
|
* `minHeight` Integer - Window's minimum height. Default is `0`.
|
||||||
* `maxWidth` Integer - Window's maximum width.
|
* `maxWidth` Integer - Window's maximum width. Default is no limit.
|
||||||
* `maxHeight` Integer - Window's maximum height.
|
* `maxHeight` Integer - Window's maximum height. Default is no limit.
|
||||||
* `resizable` Boolean - Whether window is resizable.
|
* `resizable` Boolean - Whether window is resizable. Default is `true`.
|
||||||
* `alwaysOnTop` Boolean - Whether the window should always stay on top of
|
* `alwaysOnTop` Boolean - Whether the window should always stay on top of
|
||||||
other windows.
|
other windows. Default is `false`.
|
||||||
* `fullscreen` Boolean - Whether the window should show in fullscreen. When
|
* `fullscreen` Boolean - Whether the window should show in fullscreen. When
|
||||||
set to `false` the fullscreen button will be hidden or disabled on OS X.
|
set to `false` the fullscreen button will be hidden or disabled on OS X.
|
||||||
* `skipTaskbar` Boolean - Whether to show the window in taskbar.
|
Default is `false`.
|
||||||
* `kiosk` Boolean - The kiosk mode.
|
* `skipTaskbar` Boolean - Whether to show the window in taskbar. Default is
|
||||||
* `title` String - Default window title.
|
`false`.
|
||||||
|
* `kiosk` Boolean - The kiosk mode. Default is `false`.
|
||||||
|
* `title` String - Default window title. Default is `"Electron"`.
|
||||||
* `icon` [NativeImage](native-image.md) - The window icon, when omitted on
|
* `icon` [NativeImage](native-image.md) - The window icon, when omitted on
|
||||||
Windows the executable's icon would be used as window icon.
|
Windows the executable's icon would be used as window icon.
|
||||||
* `show` Boolean - Whether window should be shown when created.
|
* `show` Boolean - Whether window should be shown when created. Default is
|
||||||
|
`true`.
|
||||||
* `frame` Boolean - Specify `false` to create a
|
* `frame` Boolean - Specify `false` to create a
|
||||||
[Frameless Window](frameless-window.md).
|
[Frameless Window](frameless-window.md). Default is `true`.
|
||||||
* `acceptFirstMouse` Boolean - Whether the web view accepts a single
|
* `acceptFirstMouse` Boolean - Whether the web view accepts a single
|
||||||
mouse-down event that simultaneously activates the window.
|
mouse-down event that simultaneously activates the window. Default is `false`.
|
||||||
* `disableAutoHideCursor` Boolean - Whether to hide cursor when typing.
|
* `disableAutoHideCursor` Boolean - Whether to hide cursor when typing. Default
|
||||||
|
is `false`.
|
||||||
* `autoHideMenuBar` Boolean - Auto hide the menu bar unless the `Alt`
|
* `autoHideMenuBar` Boolean - Auto hide the menu bar unless the `Alt`
|
||||||
key is pressed.
|
key is pressed. Default is `false`.
|
||||||
* `enableLargerThanScreen` Boolean - Enable the window to be resized larger
|
* `enableLargerThanScreen` Boolean - Enable the window to be resized larger
|
||||||
than screen.
|
than screen. Default is `false`.
|
||||||
* `backgroundColor` String - Window's background color as Hexadecimal value,
|
* `backgroundColor` String - Window's background color as Hexadecimal value,
|
||||||
like `#66CD00` or `#FFF`. This is only implemented on Linux and Windows.
|
like `#66CD00` or `#FFF`. This is only implemented on Linux and Windows.
|
||||||
|
Default is `#000` (black).
|
||||||
* `darkTheme` Boolean - Forces using dark theme for the window, only works on
|
* `darkTheme` Boolean - Forces using dark theme for the window, only works on
|
||||||
some GTK+3 desktop environments.
|
some GTK+3 desktop environments. Default is `false`.
|
||||||
* `transparent` Boolean - Makes the window [transparent](frameless-window.md).
|
* `transparent` Boolean - Makes the window [transparent](frameless-window.md).
|
||||||
|
Default is `false`.
|
||||||
* `type` String - Specifies the type of the window, which applies
|
* `type` String - Specifies the type of the window, which applies
|
||||||
additional platform-specific properties.
|
additional platform-specific properties. By default it's undefined and you'll
|
||||||
|
get a regular app window. Supported values:
|
||||||
* On Linux, possible types are `desktop`, `dock`, `toolbar`, `splash`,
|
* On Linux, possible types are `desktop`, `dock`, `toolbar`, `splash`,
|
||||||
`notification`.
|
`notification`.
|
||||||
* On OS X, possible types are `desktop`, `textured`. The `textured` type adds
|
* On OS X, possible types are `desktop`, `textured`. The `textured` type adds
|
||||||
|
@ -79,7 +88,7 @@ It creates a new `BrowserWindow` with native properties as set by the `options`.
|
||||||
* `titleBarStyle` String, OS X - specifies the style of window title bar.
|
* `titleBarStyle` String, OS X - specifies the style of window title bar.
|
||||||
This option is supported on OS X 10.10 Yosemite and newer. There are three
|
This option is supported on OS X 10.10 Yosemite and newer. There are three
|
||||||
possible values:
|
possible values:
|
||||||
* `default` or not specified results in the standard gray opaque Mac title
|
* `default` or not specified, results in the standard gray opaque Mac title
|
||||||
bar.
|
bar.
|
||||||
* `hidden` results in a hidden title bar and a full size content window, yet
|
* `hidden` results in a hidden title bar and a full size content window, yet
|
||||||
the title bar still has the standard window controls ("traffic lights") in
|
the title bar still has the standard window controls ("traffic lights") in
|
||||||
|
@ -104,33 +113,38 @@ It creates a new `BrowserWindow` with native properties as set by the `options`.
|
||||||
`partition`, multiple pages can share the same session. If the `partition`
|
`partition`, multiple pages can share the same session. If the `partition`
|
||||||
is unset then default session of the app will be used.
|
is unset then default session of the app will be used.
|
||||||
* `zoomFactor` Number - The default zoom factor of the page, `3.0` represents
|
* `zoomFactor` Number - The default zoom factor of the page, `3.0` represents
|
||||||
`300%`.
|
`300%`. Default is `1.0`.
|
||||||
* `javascript` Boolean
|
* `javascript` Boolean - Enables JavaScript support. Default is `true`.
|
||||||
* `webSecurity` Boolean - When setting `false`, it will disable the
|
* `webSecurity` Boolean - When setting `false`, it will disable the
|
||||||
same-origin policy (Usually using testing websites by people), and set
|
same-origin policy (Usually using testing websites by people), and set
|
||||||
`allowDisplayingInsecureContent` and `allowRunningInsecureContent` to
|
`allowDisplayingInsecureContent` and `allowRunningInsecureContent` to
|
||||||
`true` if these two options are not set by user.
|
`true` if these two options are not set by user. Default is `true`.
|
||||||
* `allowDisplayingInsecureContent` Boolean - Allow an https page to display
|
* `allowDisplayingInsecureContent` Boolean - Allow an https page to display
|
||||||
content like images from http URLs.
|
content like images from http URLs. Default is `false`.
|
||||||
* `allowRunningInsecureContent` Boolean - Allow a https page to run
|
* `allowRunningInsecureContent` Boolean - Allow a https page to run
|
||||||
JavaScript, CSS or plugins from http URLs.
|
JavaScript, CSS or plugins from http URLs. Default is `false`.
|
||||||
* `images` Boolean
|
* `images` Boolean - Enables image support. Default is `true`.
|
||||||
* `java` Boolean
|
* `java` Boolean - Enables Java support. Default is `false`.
|
||||||
* `textAreasAreResizable` Boolean
|
* `textAreasAreResizable` Boolean - Make TextArea elements resizable. Default
|
||||||
* `webgl` Boolean
|
is `true`.
|
||||||
* `webaudio` Boolean
|
* `webgl` Boolean - Enables WebGL support. Default is `true`.
|
||||||
* `plugins` Boolean - Whether plugins should be enabled.
|
* `webaudio` Boolean - Enables WebAudio support. Default is `true`.
|
||||||
* `experimentalFeatures` Boolean
|
* `plugins` Boolean - Whether plugins should be enabled. Default is `false`.
|
||||||
* `experimentalCanvasFeatures` Boolean
|
* `experimentalFeatures` Boolean - Enables Chromium's experimental features.
|
||||||
* `overlayScrollbars` Boolean
|
Default is `false`.
|
||||||
* `overlayFullscreenVideo` Boolean
|
* `experimentalCanvasFeatures` Boolean - Enables Chromium's experimental
|
||||||
* `sharedWorker` Boolean
|
canvas features. Default is `false`.
|
||||||
* `directWrite` Boolean - Whether the DirectWrite font rendering system on
|
* `overlayScrollbars` Boolean - Enables overlay scrollbars. Default is
|
||||||
Windows is enabled.
|
`false`.
|
||||||
|
* `overlayFullscreenVideo` Boolean - Enables overlay fullscreen video. Default
|
||||||
|
is `false`
|
||||||
|
* `sharedWorker` Boolean - Enables Shared Worker support. Default is `false`.
|
||||||
|
* `directWrite` Boolean - Enables DirectWrite font rendering system on
|
||||||
|
Windows. Default is `true`.
|
||||||
* `pageVisibility` Boolean - Page would be forced to be always in visible
|
* `pageVisibility` Boolean - Page would be forced to be always in visible
|
||||||
or hidden state once set, instead of reflecting current window's
|
or hidden state once set, instead of reflecting current window's
|
||||||
visibility. Users can set it to `true` to prevent throttling of DOM
|
visibility. Users can set it to `true` to prevent throttling of DOM
|
||||||
timers.
|
timers. Default is `false`.
|
||||||
|
|
||||||
## Events
|
## Events
|
||||||
|
|
||||||
|
|
|
@ -322,3 +322,11 @@ describe 'browser-window module', ->
|
||||||
done()
|
done()
|
||||||
|
|
||||||
w.loadURL "file://#{fixtures}/pages/save_page/index.html"
|
w.loadURL "file://#{fixtures}/pages/save_page/index.html"
|
||||||
|
|
||||||
|
describe 'BrowserWindow options argument is optional', ->
|
||||||
|
it 'should create a window with default size (800x600)', ->
|
||||||
|
w.destroy()
|
||||||
|
w = new BrowserWindow()
|
||||||
|
size = w.getSize()
|
||||||
|
assert.equal size[0], 800
|
||||||
|
assert.equal size[1], 600
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue