From 0d6b82612fa9013f53a8e194f80124a40e8cae3c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?LIU=20Dongyuan=20/=20=E6=9F=B3=E4=B8=9C=E5=8E=9F?= Date: Fri, 25 Sep 2015 21:42:58 -0700 Subject: [PATCH] [Close #44] Add quark.resizePopup() --- README.md | 3 ++- quark-shell/Base.lproj/MainMenu.xib | 17 +++++++++++++---- quark-shell/QSHAppDelegate.h | 1 + quark-shell/QSHAppDelegate.m | 7 +++++++ quark-shell/QSHWebViewDelegate.m | 18 +++++++++++++++++- sample/index.html | 3 +++ 6 files changed, 43 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index 2a24f84..c771567 100644 --- a/README.md +++ b/README.md @@ -33,10 +33,11 @@ quark.appBundleVersion // Enable/disable Web Inspector quark.debug = true -// Open/close the popup window +// Manipulate the popup window quark.openPopup() quark.closePopup() quark.togglePopup() +quark.resizePopup({width: 326, height: 623}) // Quit application quark.quit() diff --git a/quark-shell/Base.lproj/MainMenu.xib b/quark-shell/Base.lproj/MainMenu.xib index 40079cd..5345994 100644 --- a/quark-shell/Base.lproj/MainMenu.xib +++ b/quark-shell/Base.lproj/MainMenu.xib @@ -1,8 +1,9 @@ - + - - + + + @@ -27,13 +28,21 @@ - + + + + + + + + + diff --git a/quark-shell/QSHAppDelegate.h b/quark-shell/QSHAppDelegate.h index 366443c..f071bc9 100644 --- a/quark-shell/QSHAppDelegate.h +++ b/quark-shell/QSHAppDelegate.h @@ -19,5 +19,6 @@ - (void)showWindow; - (void)hideWindow; - (void)toggleWindow; +- (void)resizeWindow:(CGSize)size; @end diff --git a/quark-shell/QSHAppDelegate.m b/quark-shell/QSHAppDelegate.m index e9f33f1..a319ed4 100644 --- a/quark-shell/QSHAppDelegate.m +++ b/quark-shell/QSHAppDelegate.m @@ -117,6 +117,13 @@ } } + +- (void)resizeWindow:(CGSize)size +{ + [self.window setFrame:CGRectMake(0, 0, size.width, size.height) display:NO]; + [self refreshStyle]; +} + - (void)statusItemClicked { const NSUInteger buttonMask = [NSEvent pressedMouseButtons]; diff --git a/quark-shell/QSHWebViewDelegate.m b/quark-shell/QSHWebViewDelegate.m index 60c5450..d1e6840 100644 --- a/quark-shell/QSHWebViewDelegate.m +++ b/quark-shell/QSHWebViewDelegate.m @@ -67,6 +67,7 @@ static const NSInteger kPreferencesDefaultHeight = 192; if (selector == @selector(openPopup) || selector == @selector(closePopup) || selector == @selector(togglePopup) || + selector == @selector(resizePopup:) || selector == @selector(quit) || selector == @selector(openURL:) || selector == @selector(changeIcon:) || @@ -103,7 +104,10 @@ static const NSInteger kPreferencesDefaultHeight = 192; { id result = nil; - if (selector == @selector(notify:)) { + if (selector == @selector(resizePopup:)) { + result = @"resizePopup"; + } + else if (selector == @selector(notify:)) { result = @"notify"; } else if (selector == @selector(changeIcon:)) { @@ -183,6 +187,18 @@ static const NSInteger kPreferencesDefaultHeight = 192; [self.appDelegate toggleWindow]; } +- (void)resizePopup:(WebScriptObject *)obj +{ + QSHWebScriptObjectConverter *converter = [[QSHWebScriptObjectConverter alloc] initWithWebView:self.webView]; + NSDictionary *options = [converter dictionaryFromWebScriptObject:obj]; + CGFloat width = [options[@"width"] doubleValue]; + CGFloat height = [options[@"height"] doubleValue]; + + if (options[@"width"] && options[@"height"]) { + [self.appDelegate resizeWindow:CGSizeMake(width, height)]; + } +} + - (void)quit { [NSApp terminate:nil]; diff --git a/sample/index.html b/sample/index.html index 0e78cb2..232d1f8 100644 --- a/sample/index.html +++ b/sample/index.html @@ -52,6 +52,7 @@ } button:active { background-color: #e8e8e8; + color: black; } canvas { display: none; @@ -90,6 +91,8 @@

+ +