Add "enable-larger-than-screen" option for BrowserWindow.

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.
This commit is contained in:
Cheng Zhao 2014-08-17 12:23:00 +08:00
parent 78afa29ade
commit 2a9f5a5fb8
8 changed files with 51 additions and 17 deletions

View 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_);

View 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_;

View 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 =

View 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);