@interface HMExternalBrowserWindowController : NSWindowController
-
@property (nonatomic, weak) IBOutlet WebView *webView;
-@property (nonatomic, weak) IBOutlet NSSegmentedControl *goSegment;
+
+@property (nonatomic) NSString *urlString;
+@property (nonatomic) NSSize windowContentSize;
+@property (readonly) NSRect contentVisibleRect;
+@property BOOL canResize;
+@property BOOL canScroll;
+
+
- (IBAction)clickGoBackSegment:(id)sender;
#import "HMAppDelegate.h"
@interface HMExternalBrowserWindowController ()
-
+@property (nonatomic, weak) IBOutlet NSSegmentedControl *goSegment;
@end
@implementation HMExternalBrowserWindowController
+@synthesize canResize = _canResize;
+@synthesize canScroll = _canScroll;
+
- (id)init
{
self = [super initWithWindowNibName:NSStringFromClass([self class])];
HMAppDelegate *appDelegate = [[NSApplication sharedApplication] delegate];
[self.webView setApplicationNameForUserAgent:appDelegate.appNameForUserAgent];
+
+ self.canResize = YES;
+ self.canScroll = YES;
}
- (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context
[super observeValueForKeyPath:keyPath ofObject:object change:change context:context];
}
-/*
-
-
- http://www.dmm.com/netgame/-/basket/
-
- */
+static BOOL sameState(BOOL a, BOOL b) {
+ if(a && b) {
+ return YES;
+ }
+ if(!a && !b) {
+ return YES;
+ }
+ return NO;
+}
+- (void)setCanResize:(BOOL)canResize
+{
+ if(sameState(_canResize, canResize)) return;
+
+ _canResize = canResize;
+
+ NSUInteger styleMaks = self.window.styleMask;
+ if(canResize) {
+ styleMaks |= NSResizableWindowMask;
+ } else {
+ styleMaks &= ~NSResizableWindowMask;
+ }
+ self.window.styleMask = styleMaks;
+}
+- (BOOL)canResize
+{
+ return _canResize;
+}
+- (void)setCanScroll:(BOOL)canScroll
+{
+ if(sameState(_canScroll, canScroll)) return;
+
+ _canScroll = canScroll;
+
+ if(canScroll) {
+ [[[self.webView mainFrame] frameView] setAllowsScrolling:YES];
+ } else {
+ [[[self.webView mainFrame] frameView] setAllowsScrolling:NO];
+ }
+}
+- (BOOL)canScroll
+{
+ return _canScroll;
+}
+
+- (NSString *)urlString
+{
+ return self.webView.mainFrameURL;
+}
+- (NSRect)contentVisibleRect
+{
+ return self.webView.visibleRect;
+}
+
+- (void)setWindowContentSize:(NSSize)windowContentSize
+{
+ NSRect contentRect;
+ contentRect.origin = NSZeroPoint;
+ contentRect.size = windowContentSize;
+
+ NSRect newFrame = [self.window frameRectForContentRect:contentRect];
+ NSRect frame = self.window.frame;
+ newFrame.origin.x = NSMinX(frame);
+ newFrame.origin.y = NSMaxY(frame) - NSHeight(newFrame);
+
+ [self.window setFrame:newFrame display:YES];
+}
+- (NSSize)windowContentSize
+{
+ NSRect frame = self.window.frame;
+ NSRect contentRect = [self.window contentRectForFrameRect:frame];
+ return contentRect.size;
+}
- (IBAction)reloadContent:(id)sender
{
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
-<document type="com.apple.InterfaceBuilder3.Cocoa.XIB" version="3.0" toolsVersion="7531" systemVersion="14D131" targetRuntime="MacOSX.Cocoa" propertyAccessControl="none">
+<document type="com.apple.InterfaceBuilder3.Cocoa.XIB" version="3.0" toolsVersion="7706" systemVersion="14D136" targetRuntime="MacOSX.Cocoa" propertyAccessControl="none">
<dependencies>
<deployment identifier="macosx"/>
- <plugIn identifier="com.apple.InterfaceBuilder.CocoaPlugin" version="7531"/>
- <plugIn identifier="com.apple.WebKitIBPlugin" version="7531"/>
+ <plugIn identifier="com.apple.InterfaceBuilder.CocoaPlugin" version="7706"/>
+ <plugIn identifier="com.apple.WebKitIBPlugin" version="7706"/>
</dependencies>
<objects>
<customObject id="-2" userLabel="File's Owner" customClass="HMExternalBrowserWindowController">
</webView>
</subviews>
</view>
- <toolbar key="toolbar" implicitIdentifier="5B7CBCD4-15D6-41E0-B4FD-96F089B89683" autosavesConfiguration="NO" allowsUserCustomization="NO" displayMode="iconOnly" sizeMode="regular" id="SpO-Qb-h0u">
+ <toolbar key="toolbar" implicitIdentifier="5B7CBCD4-15D6-41E0-B4FD-96F089B89683" autosavesConfiguration="NO" displayMode="iconAndLabel" sizeMode="regular" id="SpO-Qb-h0u">
<allowedToolbarItems>
<toolbarItem implicitItemIdentifier="D74BA0C4-BF39-447F-8B06-F4B1EF0BE5EC" label="Address" paletteLabel="Address" id="dk4-x0-fn2">
<nil key="toolTip"/>
<action selector="goHome:" target="-2" id="7WE-aZ-0yM"/>
</connections>
</toolbarItem>
+ <toolbarItem implicitItemIdentifier="D8C9124A-CB95-4031-BDD2-16E6A7807759" label="Scroll Lock" paletteLabel="Scroll Lock" id="QwU-Py-Vzr">
+ <nil key="toolTip"/>
+ <size key="minSize" width="34" height="25"/>
+ <size key="maxSize" width="34" height="32"/>
+ <button key="view" verticalHuggingPriority="750" id="lIn-uu-eHu">
+ <rect key="frame" x="0.0" y="14" width="34" height="25"/>
+ <autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMinY="YES"/>
+ <buttonCell key="cell" type="roundTextured" title="SC" bezelStyle="texturedRounded" alignment="center" borderStyle="border" imageScaling="proportionallyDown" inset="2" id="lE8-PW-EdX">
+ <behavior key="behavior" lightByBackground="YES" lightByGray="YES" changeBackground="YES" changeGray="YES"/>
+ <font key="font" metaFont="system"/>
+ </buttonCell>
+ <connections>
+ <binding destination="-2" name="value" keyPath="canScroll" id="Ecd-cr-lwI">
+ <dictionary key="options">
+ <string key="NSValueTransformerName">NSNegateBoolean</string>
+ </dictionary>
+ </binding>
+ </connections>
+ </button>
+ </toolbarItem>
+ <toolbarItem implicitItemIdentifier="169D6888-0E3D-4A99-B657-2256D029340F" label="Resize Lock" paletteLabel="Resize Lock" id="DmT-Fb-EfY">
+ <nil key="toolTip"/>
+ <size key="minSize" width="34" height="25"/>
+ <size key="maxSize" width="34" height="32"/>
+ <button key="view" verticalHuggingPriority="750" id="5Ib-oj-x0A">
+ <rect key="frame" x="0.0" y="14" width="34" height="25"/>
+ <autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMinY="YES"/>
+ <buttonCell key="cell" type="roundTextured" title="RS" bezelStyle="texturedRounded" alignment="center" borderStyle="border" imageScaling="proportionallyDown" inset="2" id="gLF-bQ-UuT">
+ <behavior key="behavior" pushIn="YES" lightByBackground="YES" lightByGray="YES" changeBackground="YES" changeGray="YES"/>
+ <font key="font" metaFont="system"/>
+ </buttonCell>
+ <connections>
+ <binding destination="-2" name="value" keyPath="canResize" id="RPl-W7-gDI">
+ <dictionary key="options">
+ <string key="NSValueTransformerName">NSNegateBoolean</string>
+ </dictionary>
+ </binding>
+ </connections>
+ </button>
+ </toolbarItem>
</allowedToolbarItems>
<defaultToolbarItems>
<toolbarItem reference="yBb-7R-Qfc"/>
+ <toolbarItem reference="QwU-Py-Vzr"/>
+ <toolbarItem reference="DmT-Fb-EfY"/>
<toolbarItem reference="fQm-0j-yZH"/>
<toolbarItem reference="dk4-x0-fn2"/>
</defaultToolbarItems>