From 359123458d284f92daff000610519eb9e99d1b1b Mon Sep 17 00:00:00 2001 From: leethomas Date: Wed, 18 May 2016 23:39:16 -0700 Subject: [PATCH 1/4] =?UTF-8?q?=F0=9F=8D=8E=20=20allow=20x-axis=20offset?= =?UTF-8?q?=20to=20be=20set=20for=20sheets?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- atom/browser/api/atom_api_window.cc | 9 +++++++-- atom/browser/api/atom_api_window.h | 3 ++- atom/browser/native_window.cc | 20 +++++++++++++++----- atom/browser/native_window.h | 12 ++++++++---- atom/browser/native_window_mac.mm | 4 +++- 5 files changed, 35 insertions(+), 13 deletions(-) diff --git a/atom/browser/api/atom_api_window.cc b/atom/browser/api/atom_api_window.cc index 399b4d36d2ec..0266d49a85d5 100644 --- a/atom/browser/api/atom_api_window.cc +++ b/atom/browser/api/atom_api_window.cc @@ -371,8 +371,12 @@ std::vector Window::GetMaximumSize() { return result; } -void Window::SetSheetOffset(double offset) { - window_->SetSheetOffset(offset); +void Window::SetSheetOffset(double offsetY) { + window_->SetSheetOffset(offsetY); +} + +void Window::SetSheetOffsets(double offsetX, double offsetY) { + window_->SetSheetOffsets(offsetX, offsetY); } void Window::SetResizable(bool resizable) { @@ -682,6 +686,7 @@ void Window::BuildPrototype(v8::Isolate* isolate, .SetMethod("setMaximumSize", &Window::SetMaximumSize) .SetMethod("getMaximumSize", &Window::GetMaximumSize) .SetMethod("setSheetOffset", &Window::SetSheetOffset) + .SetMethod("setSheetOffsets", &Window::SetSheetOffsets) .SetMethod("setResizable", &Window::SetResizable) .SetMethod("isResizable", &Window::IsResizable) .SetMethod("setMovable", &Window::SetMovable) diff --git a/atom/browser/api/atom_api_window.h b/atom/browser/api/atom_api_window.h index a00e063d99f8..2eef725eaca8 100644 --- a/atom/browser/api/atom_api_window.h +++ b/atom/browser/api/atom_api_window.h @@ -110,7 +110,8 @@ class Window : public mate::TrackableObject, std::vector GetMinimumSize(); void SetMaximumSize(int width, int height); std::vector GetMaximumSize(); - void SetSheetOffset(double offset); + void SetSheetOffset(double offsetY); + void SetSheetOffsets(double offsetX, double offsetY); void SetResizable(bool resizable); bool IsResizable(); void SetMovable(bool movable); diff --git a/atom/browser/native_window.cc b/atom/browser/native_window.cc index 0d5c26c560d1..af874cae483d 100644 --- a/atom/browser/native_window.cc +++ b/atom/browser/native_window.cc @@ -53,7 +53,8 @@ NativeWindow::NativeWindow( enable_larger_than_screen_(false), is_closed_(false), has_dialog_attached_(false), - sheet_offset_(0.0), + sheet_offset_x_(0.0), + sheet_offset_y_(0.0), aspect_ratio_(0.0), inspectable_web_contents_(inspectable_web_contents), weak_factory_(this) { @@ -254,12 +255,21 @@ gfx::Size NativeWindow::GetMaximumSize() { return GetSizeConstraints().GetMaximumSize(); } -void NativeWindow::SetSheetOffset(const double offset) { - sheet_offset_ = offset; +void NativeWindow::SetSheetOffset(const double offsetY) { + sheet_offset_y_ = offsetY; } -double NativeWindow::GetSheetOffset() { - return sheet_offset_; +void NativeWindow::SetSheetOffsets(const double offsetX, const double offsetY) { + sheet_offset_x_ = offsetX; + sheet_offset_y_ = offsetY; +} + +double NativeWindow::GetSheetOffsetX() { + return sheet_offset_x_; +} + +double NativeWindow::GetSheetOffsetY() { + return sheet_offset_y_; } void NativeWindow::SetRepresentedFilename(const std::string& filename) { diff --git a/atom/browser/native_window.h b/atom/browser/native_window.h index 7317a7ba6f76..813eeb53126d 100644 --- a/atom/browser/native_window.h +++ b/atom/browser/native_window.h @@ -123,8 +123,10 @@ class NativeWindow : public base::SupportsUserData, virtual gfx::Size GetMinimumSize(); virtual void SetMaximumSize(const gfx::Size& size); virtual gfx::Size GetMaximumSize(); - virtual void SetSheetOffset(const double offset); - virtual double GetSheetOffset(); + virtual void SetSheetOffset(const double offsetY); + virtual void SetSheetOffsets(const double offsetX, const double offsetY); + virtual double GetSheetOffsetX(); + virtual double GetSheetOffsetY(); virtual void SetResizable(bool resizable) = 0; virtual bool IsResizable() = 0; virtual void SetMovable(bool movable) = 0; @@ -320,8 +322,10 @@ class NativeWindow : public base::SupportsUserData, // it should be cancelled when we can prove that the window is responsive. base::CancelableClosure window_unresposive_closure_; - // Used to display sheets at the appropriate vertical offset - double sheet_offset_; + // Used to display sheets at the appropriate horizontal and vertical offsets + // on OS X. + double sheet_offset_x_; + double sheet_offset_y_; // Used to maintain the aspect ratio of a view which is inside of the // content view. diff --git a/atom/browser/native_window_mac.mm b/atom/browser/native_window_mac.mm index bfffc7a08d64..333b282266f5 100644 --- a/atom/browser/native_window_mac.mm +++ b/atom/browser/native_window_mac.mm @@ -257,7 +257,9 @@ bool ScopedDisableResize::disable_resize_ = false; - (NSRect)window:(NSWindow*)window willPositionSheet:(NSWindow*)sheet usingRect:(NSRect)rect { NSView* view = window.contentView; - rect.origin.y = view.frame.size.height - shell_->GetSheetOffset(); + + rect.origin.x = shell_->GetSheetOffsetX(); + rect.origin.y = view.frame.size.height - shell_->GetSheetOffsetY(); return rect; } From eaacbc86c7f2a5997e75615a6acdfefd1cf198eb Mon Sep 17 00:00:00 2001 From: leethomas Date: Wed, 18 May 2016 23:59:18 -0700 Subject: [PATCH 2/4] =?UTF-8?q?=F0=9F=93=9D=20=20update=20english=20docs?= =?UTF-8?q?=20to=20include=20setSheetOffsets?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docs/api/browser-window.md | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/docs/api/browser-window.md b/docs/api/browser-window.md index 93785878d146..a00b814a598c 100644 --- a/docs/api/browser-window.md +++ b/docs/api/browser-window.md @@ -682,7 +682,7 @@ Returns the title of the native window. **Note:** The title of web page can be different from the title of the native window. -### `win.setSheetOffset(offset)` _OS X_ +### `win.setSheetOffset(offsetY)` _OS X_ Changes the attachment point for sheets on Mac OS X. By default, sheets are attached just below the window frame, but you may want to display them beneath @@ -693,6 +693,16 @@ let toolbarRect = document.getElementById('toolbar').getBoundingClientRect(); win.setSheetOffset(toolbarRect.height); ``` +### `win.setSheetOffsets(offsetX, offsetY)` _OS X_ + +Like `win.setSheetOffset` but allows for an offset along the x-axis to be set +in addition to the y-axis. + +```javascript +let toolbarRect = document.getElementById('toolbar').getBoundingClientRect(); +win.setSheetOffset(toolbarRect.left, toolbarRect.height); +``` + ### `win.flashFrame(flag)` * `flag` Boolean From 7d93642f42657130fa5a3e2be019da1c2e849eba Mon Sep 17 00:00:00 2001 From: leethomas Date: Thu, 19 May 2016 20:19:08 -0700 Subject: [PATCH 3/4] extend setSheetOffset to accept an optional 2nd offset --- atom/browser/api/atom_api_window.cc | 11 ++++------- atom/browser/api/atom_api_window.h | 3 +-- atom/browser/native_window.cc | 6 +----- atom/browser/native_window.h | 3 +-- 4 files changed, 7 insertions(+), 16 deletions(-) diff --git a/atom/browser/api/atom_api_window.cc b/atom/browser/api/atom_api_window.cc index 0266d49a85d5..64847154bcc2 100644 --- a/atom/browser/api/atom_api_window.cc +++ b/atom/browser/api/atom_api_window.cc @@ -371,12 +371,10 @@ std::vector Window::GetMaximumSize() { return result; } -void Window::SetSheetOffset(double offsetY) { - window_->SetSheetOffset(offsetY); -} - -void Window::SetSheetOffsets(double offsetX, double offsetY) { - window_->SetSheetOffsets(offsetX, offsetY); +void Window::SetSheetOffset(double offsetY, mate::Arguments* args) { + double offsetX = 0.0; + args->GetNext(&offsetX); + window_->SetSheetOffset(offsetX, offsetY); } void Window::SetResizable(bool resizable) { @@ -686,7 +684,6 @@ void Window::BuildPrototype(v8::Isolate* isolate, .SetMethod("setMaximumSize", &Window::SetMaximumSize) .SetMethod("getMaximumSize", &Window::GetMaximumSize) .SetMethod("setSheetOffset", &Window::SetSheetOffset) - .SetMethod("setSheetOffsets", &Window::SetSheetOffsets) .SetMethod("setResizable", &Window::SetResizable) .SetMethod("isResizable", &Window::IsResizable) .SetMethod("setMovable", &Window::SetMovable) diff --git a/atom/browser/api/atom_api_window.h b/atom/browser/api/atom_api_window.h index 2eef725eaca8..d44f706f7011 100644 --- a/atom/browser/api/atom_api_window.h +++ b/atom/browser/api/atom_api_window.h @@ -110,8 +110,7 @@ class Window : public mate::TrackableObject, std::vector GetMinimumSize(); void SetMaximumSize(int width, int height); std::vector GetMaximumSize(); - void SetSheetOffset(double offsetY); - void SetSheetOffsets(double offsetX, double offsetY); + void SetSheetOffset(double offsetY, mate::Arguments* args); void SetResizable(bool resizable); bool IsResizable(); void SetMovable(bool movable); diff --git a/atom/browser/native_window.cc b/atom/browser/native_window.cc index af874cae483d..39848d8dd094 100644 --- a/atom/browser/native_window.cc +++ b/atom/browser/native_window.cc @@ -255,11 +255,7 @@ gfx::Size NativeWindow::GetMaximumSize() { return GetSizeConstraints().GetMaximumSize(); } -void NativeWindow::SetSheetOffset(const double offsetY) { - sheet_offset_y_ = offsetY; -} - -void NativeWindow::SetSheetOffsets(const double offsetX, const double offsetY) { +void NativeWindow::SetSheetOffset(const double offsetX, const double offsetY) { sheet_offset_x_ = offsetX; sheet_offset_y_ = offsetY; } diff --git a/atom/browser/native_window.h b/atom/browser/native_window.h index 813eeb53126d..f4fae05f14b3 100644 --- a/atom/browser/native_window.h +++ b/atom/browser/native_window.h @@ -123,8 +123,7 @@ class NativeWindow : public base::SupportsUserData, virtual gfx::Size GetMinimumSize(); virtual void SetMaximumSize(const gfx::Size& size); virtual gfx::Size GetMaximumSize(); - virtual void SetSheetOffset(const double offsetY); - virtual void SetSheetOffsets(const double offsetX, const double offsetY); + virtual void SetSheetOffset(const double offsetX, const double offsetY); virtual double GetSheetOffsetX(); virtual double GetSheetOffsetY(); virtual void SetResizable(bool resizable) = 0; From 9196a9f3341d786f3920935ee5635292a3fbab3a Mon Sep 17 00:00:00 2001 From: leethomas Date: Thu, 19 May 2016 20:26:46 -0700 Subject: [PATCH 4/4] update docs --- docs/api/browser-window.md | 12 +----------- 1 file changed, 1 insertion(+), 11 deletions(-) diff --git a/docs/api/browser-window.md b/docs/api/browser-window.md index a00b814a598c..b3100e93344e 100644 --- a/docs/api/browser-window.md +++ b/docs/api/browser-window.md @@ -682,7 +682,7 @@ Returns the title of the native window. **Note:** The title of web page can be different from the title of the native window. -### `win.setSheetOffset(offsetY)` _OS X_ +### `win.setSheetOffset(offsetY[, offsetX])` _OS X_ Changes the attachment point for sheets on Mac OS X. By default, sheets are attached just below the window frame, but you may want to display them beneath @@ -693,16 +693,6 @@ let toolbarRect = document.getElementById('toolbar').getBoundingClientRect(); win.setSheetOffset(toolbarRect.height); ``` -### `win.setSheetOffsets(offsetX, offsetY)` _OS X_ - -Like `win.setSheetOffset` but allows for an offset along the x-axis to be set -in addition to the y-axis. - -```javascript -let toolbarRect = document.getElementById('toolbar').getBoundingClientRect(); -win.setSheetOffset(toolbarRect.left, toolbarRect.height); -``` - ### `win.flashFrame(flag)` * `flag` Boolean