arguments handing rewritten, doc updated

This commit is contained in:
evgenyzinoviev 2016-01-15 17:31:31 +01:00
parent f93d890874
commit b75dccb0be
9 changed files with 30 additions and 50 deletions

View file

@ -338,29 +338,19 @@ bool Window::IsFullscreen() {
return window_->IsFullscreen(); return window_->IsFullscreen();
} }
void Window::SetBounds(mate::Arguments* args) { void Window::SetBounds(const gfx::Rect& bounds, mate::Arguments* args) {
gfx::Rect rect;
bool animate = false; bool animate = false;
if (!args->GetNext(&rect) || args->GetNext(&animate);
(args->Length() == 2 && !args->GetNext(&animate))) { window_->SetBounds(bounds, animate);
args->ThrowError();
return;
}
window_->SetBounds(rect, animate);
} }
gfx::Rect Window::GetBounds() { gfx::Rect Window::GetBounds() {
return window_->GetBounds(); return window_->GetBounds();
} }
void Window::SetSize(mate::Arguments* args) { void Window::SetSize(int width, int height, mate::Arguments* args) {
int width = 0, height = 0;
bool animate = false; bool animate = false;
if (!args->GetNext(&width) || !args->GetNext(&height) || args->GetNext(&animate);
(args->Length() == 3 && !args->GetNext(&animate))) {
args->ThrowError();
return;
}
window_->SetSize(gfx::Size(width, height), animate); window_->SetSize(gfx::Size(width, height), animate);
} }
@ -372,14 +362,9 @@ std::vector<int> Window::GetSize() {
return result; return result;
} }
void Window::SetContentSize(mate::Arguments* args) { void Window::SetContentSize(int width, int height, mate::Arguments* args) {
int width = 0, height = 0;
bool animate = false; bool animate = false;
if (!args->GetNext(&width) || !args->GetNext(&height) || args->GetNext(&animate);
(args->Length() == 3 && !args->GetNext(&animate))) {
args->ThrowError();
return;
}
window_->SetContentSize(gfx::Size(width, height), animate); window_->SetContentSize(gfx::Size(width, height), animate);
} }
@ -435,14 +420,9 @@ void Window::Center() {
window_->Center(); window_->Center();
} }
void Window::SetPosition(mate::Arguments* args) { void Window::SetPosition(int x, int y, mate::Arguments* args) {
int x = 0, y = 0;
bool animate = false; bool animate = false;
if (!args->GetNext(&x) || !args->GetNext(&y) || args->GetNext(&animate);
(args->Length() == 3 && !args->GetNext(&animate))) {
args->ThrowError();
return;
}
window_->SetPosition(gfx::Point(x, y), animate); window_->SetPosition(gfx::Point(x, y), animate);
} }

View file

@ -94,11 +94,11 @@ class Window : public mate::TrackableObject<Window>,
bool IsMinimized(); bool IsMinimized();
void SetFullScreen(bool fullscreen); void SetFullScreen(bool fullscreen);
bool IsFullscreen(); bool IsFullscreen();
void SetBounds(mate::Arguments* args); void SetBounds(const gfx::Rect& bounds, mate::Arguments* args);
gfx::Rect GetBounds(); gfx::Rect GetBounds();
void SetSize(mate::Arguments* args); void SetSize(int width, int height, mate::Arguments* args);
std::vector<int> GetSize(); std::vector<int> GetSize();
void SetContentSize(mate::Arguments* args); void SetContentSize(int width, int height, mate::Arguments* args);
std::vector<int> GetContentSize(); std::vector<int> GetContentSize();
void SetMinimumSize(int width, int height); void SetMinimumSize(int width, int height);
std::vector<int> GetMinimumSize(); std::vector<int> GetMinimumSize();
@ -109,7 +109,7 @@ class Window : public mate::TrackableObject<Window>,
void SetAlwaysOnTop(bool top); void SetAlwaysOnTop(bool top);
bool IsAlwaysOnTop(); bool IsAlwaysOnTop();
void Center(); void Center();
void SetPosition(mate::Arguments* args); void SetPosition(int x, int y, mate::Arguments* args);
std::vector<int> GetPosition(); std::vector<int> GetPosition();
void SetTitle(const std::string& title); void SetTitle(const std::string& title);
std::string GetTitle(); std::string GetTitle();

View file

@ -92,7 +92,7 @@ void NativeWindow::InitFromOptions(const mate::Dictionary& options) {
int x = -1, y = -1; int x = -1, y = -1;
bool center; bool center;
if (options.Get(options::kX, &x) && options.Get(options::kY, &y)) { if (options.Get(options::kX, &x) && options.Get(options::kY, &y)) {
SetPosition(gfx::Point(x, y), false); SetPosition(gfx::Point(x, y));
} else if (options.Get(options::kCenter, &center) && center) { } else if (options.Get(options::kCenter, &center) && center) {
Center(); Center();
} }

View file

@ -105,13 +105,13 @@ class NativeWindow : public base::SupportsUserData,
virtual bool IsMinimized() = 0; virtual bool IsMinimized() = 0;
virtual void SetFullScreen(bool fullscreen) = 0; virtual void SetFullScreen(bool fullscreen) = 0;
virtual bool IsFullscreen() const = 0; virtual bool IsFullscreen() const = 0;
virtual void SetBounds(const gfx::Rect& bounds, bool animate) = 0; virtual void SetBounds(const gfx::Rect& bounds, bool animate = false) = 0;
virtual gfx::Rect GetBounds() = 0; virtual gfx::Rect GetBounds() = 0;
virtual void SetSize(const gfx::Size& size, bool animate); virtual void SetSize(const gfx::Size& size, bool animate = false);
virtual gfx::Size GetSize(); virtual gfx::Size GetSize();
virtual void SetPosition(const gfx::Point& position, bool animate); virtual void SetPosition(const gfx::Point& position, bool animate = false);
virtual gfx::Point GetPosition(); virtual gfx::Point GetPosition();
virtual void SetContentSize(const gfx::Size& size, bool animate); virtual void SetContentSize(const gfx::Size& size, bool animate = false);
virtual gfx::Size GetContentSize(); virtual gfx::Size GetContentSize();
virtual void SetSizeConstraints( virtual void SetSizeConstraints(
const extensions::SizeConstraints& size_constraints); const extensions::SizeConstraints& size_constraints);

View file

@ -42,7 +42,7 @@ class NativeWindowMac : public NativeWindow {
bool IsMinimized() override; bool IsMinimized() override;
void SetFullScreen(bool fullscreen) override; void SetFullScreen(bool fullscreen) override;
bool IsFullscreen() const override; bool IsFullscreen() const override;
void SetBounds(const gfx::Rect& bounds, bool animate) override; void SetBounds(const gfx::Rect& bounds, bool animate = false) override;
gfx::Rect GetBounds() override; gfx::Rect GetBounds() override;
void SetContentSizeConstraints( void SetContentSizeConstraints(
const extensions::SizeConstraints& size_constraints) override; const extensions::SizeConstraints& size_constraints) override;

View file

@ -456,7 +456,7 @@ NativeWindowMac::NativeWindowMac(
bool use_content_size = false; bool use_content_size = false;
options.Get(options::kUseContentSize, &use_content_size); options.Get(options::kUseContentSize, &use_content_size);
if (!has_frame() || !use_content_size) if (!has_frame() || !use_content_size)
SetSize(gfx::Size(width, height), false); SetSize(gfx::Size(width, height));
// Enable the NSView to accept first mouse event. // Enable the NSView to accept first mouse event.
bool acceptsFirstMouse = false; bool acceptsFirstMouse = false;

View file

@ -375,7 +375,7 @@ bool NativeWindowViews::IsFullscreen() const {
return window_->IsFullscreen(); return window_->IsFullscreen();
} }
void NativeWindowViews::SetBounds(const gfx::Rect& bounds, bool animate) { void NativeWindowViews::SetBounds(const gfx::Rect& bounds, bool animate = false) {
#if defined(USE_X11) #if defined(USE_X11)
// On Linux the minimum and maximum size should be updated with window size // On Linux the minimum and maximum size should be updated with window size
// when window is not resizable. // when window is not resizable.
@ -586,7 +586,7 @@ void NativeWindowViews::SetMenu(ui::MenuModel* menu_model) {
SetContentSizeConstraints(constraints); SetContentSizeConstraints(constraints);
// Resize the window to make sure content size is not changed. // Resize the window to make sure content size is not changed.
SetContentSize(content_size, false); SetContentSize(content_size);
} }
} }
} }

View file

@ -121,7 +121,7 @@ void NativeWindowViews::HandleSizeEvent(WPARAM w_param, LPARAM l_param) {
// When the window is restored we resize it to the previous known // When the window is restored we resize it to the previous known
// normal size. // normal size.
NativeWindow::SetSize(last_normal_size_, false); NativeWindow::SetSize(last_normal_size_);
NotifyWindowUnmaximize(); NotifyWindowUnmaximize();
break; break;
@ -134,7 +134,7 @@ void NativeWindowViews::HandleSizeEvent(WPARAM w_param, LPARAM l_param) {
// When the window is restored we resize it to the previous known // When the window is restored we resize it to the previous known
// normal size. // normal size.
NativeWindow::SetSize(last_normal_size_, false); NativeWindow::SetSize(last_normal_size_);
NotifyWindowRestore(); NotifyWindowRestore();
} }

View file

@ -450,14 +450,14 @@ height areas you have within the overall content view.
### `win.setBounds(options[, animate])` ### `win.setBounds(options[, animate])`
`options` Object, properties: * `options` Object, properties:
* `x` Integer * `x` Integer
* `y` Integer * `y` Integer
* `width` Integer * `width` Integer
* `height` Integer * `height` Integer
`animate` Boolean (optional) _OS X_ * `animate` Boolean (optional) _OS X_
Resizes and moves the window to `width`, `height`, `x`, `y`. Resizes and moves the window to `width`, `height`, `x`, `y`.