Merge pull request #4922 from electron/bengotow/sheet-offset
Allow sheets to be attached at a custom offset #4679
This commit is contained in:
		
				commit
				
					
						eb9e0e5534
					
				
			
		
					 7 changed files with 47 additions and 4 deletions
				
			
		| 
						 | 
				
			
			@ -440,6 +440,10 @@ std::vector<int> Window::GetMaximumSize() {
 | 
			
		|||
  return result;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void Window::SetSheetOffset(double offset) {
 | 
			
		||||
  window_->SetSheetOffset(offset);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void Window::SetResizable(bool resizable) {
 | 
			
		||||
  window_->SetResizable(resizable);
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			@ -746,6 +750,7 @@ void Window::BuildPrototype(v8::Isolate* isolate,
 | 
			
		|||
      .SetMethod("getMinimumSize", &Window::GetMinimumSize)
 | 
			
		||||
      .SetMethod("setMaximumSize", &Window::SetMaximumSize)
 | 
			
		||||
      .SetMethod("getMaximumSize", &Window::GetMaximumSize)
 | 
			
		||||
      .SetMethod("setSheetOffset", &Window::SetSheetOffset)
 | 
			
		||||
      .SetMethod("setResizable", &Window::SetResizable)
 | 
			
		||||
      .SetMethod("isResizable", &Window::IsResizable)
 | 
			
		||||
      .SetMethod("setMovable", &Window::SetMovable)
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -110,6 +110,7 @@ class Window : public mate::TrackableObject<Window>,
 | 
			
		|||
  std::vector<int> GetMinimumSize();
 | 
			
		||||
  void SetMaximumSize(int width, int height);
 | 
			
		||||
  std::vector<int> GetMaximumSize();
 | 
			
		||||
  void SetSheetOffset(double offset);
 | 
			
		||||
  void SetResizable(bool resizable);
 | 
			
		||||
  bool IsResizable();
 | 
			
		||||
  void SetMovable(bool movable);
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -254,6 +254,14 @@ gfx::Size NativeWindow::GetMaximumSize() {
 | 
			
		|||
  return GetSizeConstraints().GetMaximumSize();
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void NativeWindow::SetSheetOffset(const double offset) {
 | 
			
		||||
  sheet_offset_ = offset;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
double NativeWindow::GetSheetOffset() {
 | 
			
		||||
  return sheet_offset_;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void NativeWindow::SetRepresentedFilename(const std::string& filename) {
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -123,6 +123,8 @@ 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 SetResizable(bool resizable) = 0;
 | 
			
		||||
  virtual bool IsResizable() = 0;
 | 
			
		||||
  virtual void SetMovable(bool movable) = 0;
 | 
			
		||||
| 
						 | 
				
			
			@ -326,6 +328,9 @@ 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 maintain the aspect ratio of a view which is inside of the
 | 
			
		||||
  // content view.
 | 
			
		||||
  double aspect_ratio_;
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -243,6 +243,13 @@ bool ScopedDisableResize::disable_resize_ = false;
 | 
			
		|||
  return NO;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
- (NSRect)window:(NSWindow *)window willPositionSheet:(NSWindow *)sheet usingRect:(NSRect)rect {
 | 
			
		||||
  NSView * view = window.contentView;
 | 
			
		||||
  rect.origin.y = view.frame.size.height - shell_->GetSheetOffset();
 | 
			
		||||
  return rect;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
@end
 | 
			
		||||
 | 
			
		||||
@interface AtomNSWindow : NSWindow {
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -675,6 +675,17 @@ 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)`
 | 
			
		||||
 | 
			
		||||
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 a HTML-rendered
 | 
			
		||||
toolbar. For example:
 | 
			
		||||
 | 
			
		||||
```
 | 
			
		||||
var toolbarRect = document.getElementById('toolbar').getBoundingClientRect();
 | 
			
		||||
win.setSheetOffset(toolbarRect.height);
 | 
			
		||||
```
 | 
			
		||||
 | 
			
		||||
### `win.flashFrame(flag)`
 | 
			
		||||
 | 
			
		||||
* `flag` Boolean
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -18,10 +18,6 @@ The Dialog is opened from Electron's main thread. If you want to use the dialog
 | 
			
		|||
const dialog = require('electron').remote.dialog;
 | 
			
		||||
```
 | 
			
		||||
 | 
			
		||||
**Note for OS X**: If you want to present dialogs as sheets, the only thing you
 | 
			
		||||
have to do is provide a `BrowserWindow` reference in the `browserWindow`
 | 
			
		||||
parameter.
 | 
			
		||||
 | 
			
		||||
## Methods
 | 
			
		||||
 | 
			
		||||
The `dialog` module has the following methods:
 | 
			
		||||
| 
						 | 
				
			
			@ -125,3 +121,13 @@ This API can be called safely before the `ready` event the `app` module emits,
 | 
			
		|||
it is usually used to report errors in early stage of startup.  If called
 | 
			
		||||
before the app `ready`event on Linux, the message will be emitted to stderr,
 | 
			
		||||
and no GUI dialog will appear.
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
## Sheets
 | 
			
		||||
 | 
			
		||||
On Mac OS X, dialogs are presented as sheets attached to a window if you provide
 | 
			
		||||
a `BrowserWindow` reference in the `browserWindow` parameter, or modals if no
 | 
			
		||||
window is provided.
 | 
			
		||||
 | 
			
		||||
You can call `BrowserWindow.getCurrentWindow().setSheetOffset(offset)` to change
 | 
			
		||||
the offset from the window frame where sheets are attached.
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue