97 CPArray _backwardStack;
98 CPArray _forwardStack;
100 BOOL _ignoreLoadStart;
104 id _downloadDelegate;
105 id _frameLoadDelegate;
107 id _resourceLoadDelegate;
115 Function _loadCallback;
118 int _effectiveScrollMode;
119 BOOL _contentIsAccessible;
120 CPTimer _contentSizeCheckTimer;
121 int _contentSizePollCount;
123 int _loadHTMLStringTimer;
125 BOOL _drawsBackground;
128 - (id)initWithFrame:(CGRect)frameRect frameName:(
CPString)frameName groupName:(
CPString)groupName
130 if (
self = [
self initWithFrame:frameRect])
132 _iframe.name = frameName;
138 - (id)initWithFrame:(CGRect)aFrame
140 if (
self = [super initWithFrame:aFrame])
146 _contentIsAccessible = YES;
149 _drawsBackground = YES;
153 [
self _initDOMWithFrame:aFrame];
159 - (id)_initDOMWithFrame:(CGRect)aFrame
161 _ignoreLoadStart = YES;
162 _ignoreLoadEnd = YES;
164 _iframe = document.createElement(
"iframe");
165 _iframe.name =
"iframe_" + FLOOR(RAND() * 10000);
166 _iframe.style.width =
"100%";
167 _iframe.style.height =
"100%";
168 _iframe.style.borderWidth =
"0px";
169 _iframe.frameBorder =
"0";
171 [
self _applyBackgroundColor];
173 _loadCallback =
function()
176 if (!_ignoreLoadStart)
179 [
self _startedLoading];
182 [_backwardStack addObject:_mainFrameURL];
185 _mainFrameURL = _iframe.src;
188 [_forwardStack removeAllObjects];
191 _ignoreLoadStart = NO;
195 [
self _finishedLoading];
203 if (_iframe.addEventListener)
204 _iframe.addEventListener(
"load", _loadCallback,
false);
205 else if (_iframe.attachEvent)
206 _iframe.attachEvent(
"onload", _loadCallback);
208 _frameView = [[
CPView alloc] initWithFrame:[
self bounds]];
209 [_frameView setAutoresizingMask:CPViewWidthSizable | CPViewHeightSizable];
211 _scrollView = [[
CPScrollView alloc] initWithFrame:[
self bounds]];
212 [_scrollView setAutohidesScrollers:YES];
213 [_scrollView setAutoresizingMask:CPViewWidthSizable | CPViewHeightSizable];
214 [_scrollView setDocumentView:_frameView];
216 _frameView._DOMElement.appendChild(_iframe);
218 [
self _updateEffectiveScrollMode];
220 [
self addSubview:_scrollView];
223 - (void)setFrameSize:(CGSize)aSize
226 [
self _resizeWebFrame];
229 - (void)viewDidUnhide
233 [_frameView setFrameSize:[_scrollView contentSize]];
234 [
self _resizeWebFrame];
235 [
self _scheduleContentSizeCheck];
238 - (void)_attachScrollEventIfNecessary
243 var win = [
self DOMWindow];
245 if (win && win.addEventListener)
247 var scrollEventHandler =
function(anEvent)
249 var frameBounds = [
self bounds],
250 frameCenter = CGPointMake(CGRectGetMidX(frameBounds), CGRectGetMidY(frameBounds)),
251 windowOrigin = [
self convertPoint:frameCenter toView:nil],
252 globalOrigin = [[
self window] convertBaseToBridge:windowOrigin];
254 anEvent._overrideLocation = globalOrigin;
255 [[[
self window] platformWindow] scrollEvent:anEvent];
258 win.addEventListener(
"DOMMouseScroll", scrollEventHandler,
false);
259 win.addEventListener(
"wheel", scrollEventHandler,
false);
263 - (void)_resizeWebFrame
268 if (![
self _isVisible])
275 var visibleRect = [_frameView visibleRect];
276 [_frameView setFrameSize:CGSizeMake(CGRectGetMaxX(visibleRect), CGRectGetMaxY(visibleRect))];
279 var win = [
self DOMWindow];
281 if (win && win.document && win.document.body)
283 var
width = win.document.body.scrollWidth,
284 height = win.document.body.scrollHeight;
286 _iframe.setAttribute(
"width",
width);
287 _iframe.setAttribute(
"height", height);
289 [_frameView setFrameSize:CGSizeMake(width, height)];
295 if (!win || !win.document)
297 CPLog.warn(
"using default size 800*1600");
298 [_frameView setFrameSize:CGSizeMake(800, 1600)];
302 [_frameView scrollRectToVisible:visibleRect];
317 - (void)setScrollMode:(
int)aScrollMode
319 if (_scrollMode == aScrollMode)
322 _scrollMode = aScrollMode;
324 [
self _updateEffectiveScrollMode];
336 - (int)effectiveScrollMode
338 return _effectiveScrollMode;
341 - (void)_updateEffectiveScrollMode
355 CPLog.warn(
self +
" unable to use CPWebViewScrollAppKit scroll mode due to same origin policy.");
359 if (_newScrollMode !== _effectiveScrollMode)
360 [
self _setEffectiveScrollMode:_newScrollMode];
363 - (void)_setEffectiveScrollMode:(
int)aScrollMode
365 _effectiveScrollMode = aScrollMode;
367 _ignoreLoadStart = YES;
368 _ignoreLoadEnd = YES;
370 var parent = _iframe.parentNode;
372 parent.removeChild(_iframe);
376 [_scrollView setHasHorizontalScroller:YES];
377 [_scrollView setHasVerticalScroller:YES];
379 _iframe.setAttribute(
"scrolling",
"no");
383 [_scrollView setHasHorizontalScroller:NO];
384 [_scrollView setHasVerticalScroller:NO];
386 _iframe.setAttribute(
"scrolling",
"no");
390 [_scrollView setHasHorizontalScroller:NO];
391 [_scrollView setHasVerticalScroller:NO];
393 _iframe.setAttribute(
"scrolling",
"auto");
395 [_frameView setFrameSize:[_scrollView bounds].size];
398 parent.appendChild(_iframe);
399 [
self _applyBackgroundColor];
401 [
self _resizeWebFrame];
404 - (void)_maybePollWebFrameSize
407 [
self _resizeWebFrame];
409 [_contentSizeCheckTimer invalidate];
431 [_frameView setFrameSize:[_scrollView contentSize]];
433 [
self _startedLoading];
435 _ignoreLoadStart = YES;
443 - (void)_loadMainFrameURL
445 [
self _startedLoading];
447 _ignoreLoadStart = YES;
449 _url = _mainFrameURL;
462 _contentIsAccessible = [cpurl _passesSameOriginPolicy];
463 [
self _updateEffectiveScrollMode];
469 else if (_html !== nil)
474 _contentIsAccessible = YES;
475 [
self _updateEffectiveScrollMode];
479 if (_loadHTMLStringTimer !== nil)
481 window.clearTimeout(_loadHTMLStringTimer);
482 _loadHTMLStringTimer = nil;
486 _loadHTMLStringTimer = window.setTimeout(
function()
488 var win = [
self DOMWindow];
494 win.document.write(_html ||
"<html><body></body></html>");
496 window.setTimeout(_loadCallback, 1);
501 - (void)_startedLoading
507 if ([_frameLoadDelegate respondsToSelector:
@selector(webView:didStartProvisionalLoadForFrame:)])
508 [_frameLoadDelegate webView:
self didStartProvisionalLoadForFrame:nil];
511 - (void)_finishedLoading
515 [
self _resizeWebFrame];
516 [
self _attachScrollEventIfNecessary];
518 [
self _scheduleContentSizeCheck];
522 if ([_frameLoadDelegate respondsToSelector:
@selector(webView:didFinishLoadForFrame:)])
523 [_frameLoadDelegate webView:
self didFinishLoadForFrame:nil];
526 - (void)_scheduleContentSizeCheck
528 [_contentSizeCheckTimer invalidate];
547 _contentSizePollCount = 0;
568 return _mainFrameURL;
579 [_backwardStack addObject:_mainFrameURL];
581 _mainFrameURL = URLString;
582 [_forwardStack removeAllObjects];
584 [
self _loadMainFrameURL];
594 if (_backwardStack.length > 0)
597 [_forwardStack addObject:_mainFrameURL];
599 _mainFrameURL = [_backwardStack lastObject];
600 [_backwardStack removeLastObject];
602 [
self _loadMainFrameURL];
617 if (_forwardStack.length > 0)
620 [_backwardStack addObject:_mainFrameURL];
622 _mainFrameURL = [_forwardStack lastObject];
623 [_forwardStack removeLastObject];
625 [
self _loadMainFrameURL];
641 return (_backwardStack.length > 0);
652 return (_forwardStack.length > 0);
655 - (WebBackForwardList)backForwardList
658 return { back: _backwardStack, forward: _forwardStack };
667 _iframe.parentNode.removeChild(_iframe);
675 - (DOMWindow)DOMWindow
679 return (_iframe.contentDocument && _iframe.contentDocument.defaultView) || _iframe.contentWindow;
696 if (!_wso || win != [_wso window])
717 return result ? String(result) : nil;
726 - (JSObject)objectByEvaluatingJavaScriptFromString:(
CPString)script
738 - (DOMCSSStyleDeclaration)computedStyleForElement:(DOMElement)element pseudoElement:(
CPString)pseudoElement
745 return win.document.defaultView.getComputedStyle(element, pseudoElement);
754 - (BOOL)drawsBackground
756 return _drawsBackground;
770 - (void)setDrawsBackground:(BOOL)drawsBackground
772 if (drawsBackground == _drawsBackground)
775 _drawsBackground = drawsBackground;
777 [
self _applyBackgroundColor];
783 [
self _applyBackgroundColor];
786 - (void)_applyBackgroundColor
791 _iframe.allowtransparency = !_drawsBackground;
792 _iframe.style.backgroundColor = _drawsBackground ? [bgColor cssString] :
"transparent";
804 - (@action)takeStringURLFrom:(
id)sender
814 - (@action)goBack:(
id)sender
824 - (@action)goForward:(
id)sender
834 - (@action)stopLoading:(
id)sender
844 - (@action)reload:(
id)sender
847 if (!_url && (_html !== nil))
850 [
self _loadMainFrameURL];
859 - (@action)print:(
id)sender
867 alert(
'Please click the webpage and select "Print" from the "File" menu');
876 - (id)downloadDelegate
878 return _downloadDelegate;
881 - (void)setDownloadDelegate:(
id)anObject
883 _downloadDelegate = anObject;
886 - (id)frameLoadDelegate
888 return _frameLoadDelegate;
891 - (void)setFrameLoadDelegate:(
id)anObject
893 _frameLoadDelegate = anObject;
898 return _policyDelegate;
901 - (void)setPolicyDelegate:(
id)anObject
903 _policyDelegate = anObject;
906 - (id)resourceLoadDelegate
908 return _resourceLoadDelegate;
911 - (void)setResourceLoadDelegate:(
id)anObject
913 _resourceLoadDelegate = anObject;
921 - (void)setUIDelegate:(
id)anObject
923 _UIDelegate = anObject;
940 - (id)initWithWindow:(Window)aWindow
942 if (
self = [super
init])
956 - (id)callWebScriptMethod:(
CPString)methodName withArguments:(CPArray)args
959 if (typeof _window[methodName] ==
"function")
963 return _window[methodName].apply(_window, args);
982 return _window.eval(script);
1018 _mainFrameURL = nil;
1019 _backwardStack = [];
1024 [
self _initDOMWithFrame:[
self frame]];
1030 [
self _updateEffectiveScrollMode];
1043 var actualSubviews = _subviews;
1046 _subviews = actualSubviews;
1060 - (BOOL)_passesSameOriginPolicy
1068 if (![
self scheme] && ![
self host] && ![
self port])
1071 return ([documentURL scheme] == [
self scheme] && [documentURL host] == [
self host] && [documentURL port] == [
self port]);
CPWebViewAppKitScrollPollInterval
id initWithCoder:(CPCoder aCoder)
The main run loop for the application.
void loadHTMLString:(CPString aString)
void postNotificationName:object:(CPString aNotificationName, [object] id anObject)
CPNotificationCenter defaultCenter()
void setMainFrameURL:(CPString URLString)
CPRunLoop currentRunLoop()
void loadHTMLString:baseURL:(CPString aString, [baseURL] CPURL URL)
An immutable string (collection of characters).
CPWebViewProgressFinishedNotification
CPInternetExplorerBrowserEngine
function CPFeatureIsCompatible(aFeature)
Window CPWebViewProgressStartedNotification
JSObject objectByEvaluatingJavaScriptFromString:(CPString script)
void encodeWithCoder:(CPCoder aCoder)
CPColor backgroundColor()
CPTimer scheduledTimerWithTimeInterval:target:selector:userInfo:repeats:(CPTimeInterval seconds, [target] id aTarget, [selector] SEL aSelector, [userInfo] id userInfo, [repeats] BOOL shouldRepeat)
CPDate limitDateForMode:(CPString aMode)
id evaluateWebScript:(CPString script)
void setBackgroundColor:(CPColor aColor)
A timer object that can send a message after the given time interval.
Defines methods for use when archiving & restoring (enc/decoding).
CPWebViewAppKitScrollMaxPollCount
Sends messages (CPNotification) between objects.
void setBackgroundColor:(CPColor aColor)
void setFrameSize:(CGSize aSize)
CPWebScriptObject windowScriptObject()
function CPBrowserIsEngine(anEngine)
id URLWithString:(CPString URLString)
CPSOPDisabledFromFileURLs