26 @global appkit_tag_dom_elements
28 @
typedef _CPViewFullScreenModeState
32 if (typeof(appkit_tag_dom_elements) !==
"undefined" && appkit_tag_dom_elements)
34 AppKitTagDOMElement =
function(owner, element)
36 element.setAttribute(
"data-cappuccino-view", [owner className]);
37 element.setAttribute(
"data-cappuccino-uid", [owner UID]);
42 AppKitTagDOMElement =
function(owner, element)
100 var DOMElementPrototype = nil,
102 BackgroundTrivialColor = 0,
103 BackgroundVerticalThreePartImage = 1,
104 BackgroundHorizontalThreePartImage = 2,
105 BackgroundNinePartImage = 3,
106 BackgroundTransparentColor = 4;
146 CGAffineTransform _boundsTransform;
147 CGAffineTransform _inverseBoundsTransform;
149 CPSet _registeredDraggedTypes;
150 CPArray _registeredDraggedTypesArray;
156 BOOL _postsFrameChangedNotifications;
157 BOOL _postsBoundsChangedNotifications;
158 BOOL _inhibitFrameAndBoundsChangedNotifications;
160 BOOL _isSuperviewAClipView;
163 DOMElement _DOMElement;
164 DOMElement _DOMContentsElement;
166 CPArray _DOMImageParts;
167 CPArray _DOMImageSizes;
169 unsigned _backgroundType;
177 BOOL _autoresizesSubviews;
178 unsigned _autoresizingMask;
184 BOOL _isInFullScreenMode;
186 _CPViewFullScreenModeState _fullScreenModeState;
190 CGSize _hierarchyScaleSize;
194 BOOL _needToSetTransformMatrix;
199 JSObject _ephemeralSubviews;
204 JSObject _themeAttributes;
205 unsigned _themeState;
207 JSObject _ephemeralSubviewsForNames;
208 CPSet _ephereralSubviews;
214 unsigned _viewClassFlags;
218 Function _toolTipFunctionIn;
219 Function _toolTipFunctionOut;
220 BOOL _toolTipInstalled;
231 if (
self !== [
CPView class])
235 DOMElementPrototype = document.createElement(
"div");
237 var style = DOMElementPrototype.style;
239 style.overflow =
"hidden";
240 style.position =
"absolute";
241 style.visibility =
"visible";
248 + (Class)_binderClassForBinding:(
CPString)aBinding
253 return [
super _binderClassForBinding:aBinding];
260 + (void)setHighDPIDrawingEnabled:(BOOL)isEnabled
269 + (BOOL)isHighDPIDrawingEnabled
274 - (void)_setupViewFlags
276 var theClass = [
self class],
277 classUID = [theClass UID];
283 if ([theClass instanceMethodForSelector:
@selector(drawRect:)] !== [
CPView instanceMethodForSelector:
@selector(drawRect:)])
286 if ([theClass instanceMethodForSelector:
@selector(layoutSubviews)] !== [
CPView instanceMethodForSelector:
@selector(layoutSubviews)])
295 + (CPSet)keyPathsForValuesAffectingFrame
297 return [CPSet setWithObjects:@"frameOrigin", @"frameSize"];
300 + (CPSet)keyPathsForValuesAffectingBounds
302 return [CPSet setWithObjects:@"boundsOrigin", @"boundsSize"];
319 - (id)initWithFrame:(CGRect)aFrame
325 var
width = CGRectGetWidth(aFrame),
326 height = CGRectGetHeight(aFrame);
329 _registeredDraggedTypes = [CPSet set];
330 _registeredDraggedTypesArray = [];
334 _frame = CGRectMakeCopy(aFrame);
335 _bounds = CGRectMake(0.0, 0.0, width, height);
338 _autoresizesSubviews = YES;
339 _clipsToBounds = YES;
345 _hierarchyScaleSize = CGSizeMake(1.0 , 1.0);
346 _scaleSize = CGSizeMake(1.0, 1.0);
350 _themeState = CPThemeStateNormal;
353 _DOMElement = DOMElementPrototype.cloneNode(
false);
354 AppKitTagDOMElement(
self, _DOMElement);
356 CPDOMDisplayServerSetStyleLeftTop(_DOMElement, NULL, CGRectGetMinX(aFrame), CGRectGetMinY(aFrame));
357 CPDOMDisplayServerSetStyleSize(_DOMElement, width, height);
363 [
self _setupViewFlags];
365 [
self _loadThemeAttributes];
379 if (_toolTip == aToolTip)
382 if (aToolTip && ![aToolTip isKindOfClass:
CPString])
387 [
self _manageToolTipInstallation];
390 - (void)_manageToolTipInstallation
392 if ([
self window] && _toolTip)
393 [
self _installToolTipEventHandlers];
395 [
self _uninstallToolTipEventHandlers];
401 - (void)_installToolTipEventHandlers
403 if (_toolTipInstalled)
406 if (!_toolTipFunctionIn)
407 _toolTipFunctionIn =
function(e) { [_CPToolTip scheduleToolTipForView:self]; }
409 if (!_toolTipFunctionOut)
410 _toolTipFunctionOut =
function(e) { [_CPToolTip invalidateCurrentToolTipIfNeeded]; };
413 if (_DOMElement.addEventListener)
415 _DOMElement.addEventListener(
"mouseover", _toolTipFunctionIn, YES);
416 _DOMElement.addEventListener(
"keypress", _toolTipFunctionOut, YES);
417 _DOMElement.addEventListener(
"mouseout", _toolTipFunctionOut, YES);
419 else if (_DOMElement.attachEvent)
421 _DOMElement.attachEvent(
"onmouseover", _toolTipFunctionIn);
422 _DOMElement.attachEvent(
"onkeypress", _toolTipFunctionOut);
423 _DOMElement.attachEvent(
"onmouseout", _toolTipFunctionOut);
427 _toolTipInstalled = YES;
434 - (void)_uninstallToolTipEventHandlers
436 if (!_toolTipInstalled)
440 if (_DOMElement.removeEventListener)
442 _DOMElement.removeEventListener(
"mouseover", _toolTipFunctionIn, YES);
443 _DOMElement.removeEventListener(
"keypress", _toolTipFunctionOut, YES);
444 _DOMElement.removeEventListener(
"mouseout", _toolTipFunctionOut, YES);
446 else if (_DOMElement.detachEvent)
448 _DOMElement.detachEvent(
"onmouseover", _toolTipFunctionIn);
449 _DOMElement.detachEvent(
"onkeypress", _toolTipFunctionOut);
450 _DOMElement.detachEvent(
"onmouseout", _toolTipFunctionOut);
454 _toolTipFunctionIn = nil;
455 _toolTipFunctionOut = nil;
457 _toolTipInstalled = NO;
475 return [_subviews copy];
492 [
self _insertSubview:aSubview atIndex:CPNotFound];
501 - (void)addSubview:(
CPView)aSubview positioned:(CPWindowOrderingMode)anOrderingMode relativeTo:(
CPView)anotherView
503 var index = anotherView ? [_subviews indexOfObjectIdenticalTo:anotherView] :
CPNotFound;
507 index = (anOrderingMode ===
CPWindowAbove) ? [_subviews count] : 0;
513 [
self _insertSubview:aSubview atIndex:index];
517 - (void)_insertSubview:(
CPView)aSubview atIndex:(
int)anIndex
519 if (aSubview ===
self)
522 if (!aSubview._superview && _subviews.indexOf(aSubview) !==
CPNotFound)
530 var count = _subviews.length,
534 [[
self window] _dirtyKeyViewLoop];
537 if (aSubview._superview ==
self)
539 var index = [_subviews indexOfObjectIdenticalTo:aSubview];
542 if (index === anIndex || index === count - 1 && anIndex === count)
545 [_subviews removeObjectAtIndex:index];
548 CPDOMDisplayServerRemoveChild(_DOMElement, aSubview._DOMElement);
559 var superview = aSubview._superview;
561 lastWindow = [superview window];
564 [aSubview _removeFromSuperview];
567 aSubview._superview =
self;
570 if (anIndex ===
CPNotFound || anIndex >= count)
572 _subviews.push(aSubview);
576 CPDOMDisplayServerAppendChild(_DOMElement, aSubview._DOMElement);
581 _subviews.splice(anIndex, 0, aSubview);
585 CPDOMDisplayServerInsertBefore(_DOMElement, aSubview._DOMElement, _subviews[anIndex + 1]._DOMElement);
590 [aSubview _scaleSizeUnitSquareToSize:[
self _hierarchyScaleSize]];
594 if (![aSubview
isHidden] && [
self isHiddenOrHasHiddenAncestor])
595 [aSubview _notifyViewDidHide];
601 [aSubview _setWindow:_window];
603 if (!_window && lastWindow)
604 [aSubview _setWindow:nil];
611 [aSubview _notifyViewDidBecomeFirstResponder];
613 [aSubview _notifyViewDidResignFirstResponder];
616 [aSubview _notifyWindowDidBecomeKey];
618 [aSubview _notifyWindowDidResignKey];
621 [
self didAddSubview:aSubview];
636 - (void)removeFromSuperview
638 var superview = _superview;
641 [
self _removeFromSuperview];
645 [
self _setWindow:nil];
648 - (void)_removeFromSuperview
654 [[
self window] _dirtyKeyViewLoop];
656 [_superview willRemoveSubview:self];
658 [_superview._subviews removeObjectIdenticalTo:self];
661 CPDOMDisplayServerRemoveChild(_superview._DOMElement, _DOMElement);
666 if (!_isHidden && [_superview isHiddenOrHasHiddenAncestor])
667 [
self _notifyViewDidUnhide];
669 [
self _notifyWindowDidResignKey];
670 [
self _notifyViewDidResignFirstResponder];
682 if (aSubview._superview !==
self || aSubview === aView)
685 var index = [_subviews indexOfObjectIdenticalTo:aSubview];
687 [
self _insertSubview:aView atIndex:index];
692 - (void)setSubviews:(CPArray)newSubviews
695 [
CPException raise:CPInvalidArgumentException
reason:"newSubviews cannot be nil in -[CPView setSubviews:]"];
698 if ([_subviews
isEqual:newSubviews])
702 if ([_subviews count] === 0)
705 count = [newSubviews count];
707 for (; index < count; ++index)
708 [
self addSubview:newSubviews[index]];
714 if ([newSubviews count] === 0)
716 var count = [_subviews count];
719 [_subviews[count] removeFromSuperview];
725 var removedSubviews = [
CPMutableSet setWithArray:_subviews];
727 [removedSubviews removeObjectsInArray:newSubviews];
728 [removedSubviews makeObjectsPerformSelector:@selector(removeFromSuperview)];
731 var addedSubviews = [
CPMutableSet setWithArray:newSubviews];
733 [addedSubviews removeObjectsInArray:_subviews];
735 var addedSubview = nil,
736 addedSubviewEnumerator = [addedSubviews objectEnumerator];
738 while ((addedSubview = [addedSubviewEnumerator nextObject]) !== nil)
742 if ([_subviews
isEqual:newSubviews])
745 _subviews = [newSubviews copy];
749 count = [_subviews count];
751 for (; index < count; ++index)
753 var subview = _subviews[index];
755 CPDOMDisplayServerRemoveChild(_DOMElement, subview._DOMElement);
756 CPDOMDisplayServerAppendChild(_DOMElement, subview._DOMElement);
762 - (void)_setWindow:(
CPWindow)aWindow
764 [[
self window] _dirtyKeyViewLoop];
767 if ([_window firstResponder] ===
self && _window != aWindow)
768 [_window makeFirstResponder:nil];
771 [
self viewWillMoveToWindow:aWindow];
775 if (_registeredDraggedTypes)
777 [_window _noteUnregisteredDraggedTypes:_registeredDraggedTypes];
778 [aWindow _noteRegisteredDraggedTypes:_registeredDraggedTypes];
783 var count = [_subviews count];
786 [_subviews[count] _setWindow:aWindow];
788 if ([_window isKeyWindow])
789 [
self setThemeState:CPThemeStateKeyWindow];
791 [
self unsetThemeState:CPThemeStateKeyWindow];
793 [
self viewDidMoveToWindow];
795 [
self _manageToolTipInstallation];
797 [[
self window] _dirtyKeyViewLoop];
812 }
while(view = [view superview])
820 - (void)viewDidMoveToSuperview
830 - (void)viewDidMoveToWindow
838 - (void)viewWillMoveToSuperview:(
CPView)aView
842 [
self _removeObservers];
845 [
self _addObservers];
864 - (void)_removeObservers
869 var count = [_subviews count];
872 [_subviews[count] _removeObservers];
877 - (void)_addObservers
882 var count = [_subviews count];
885 [_subviews[count] _addObservers];
898 while (view && ![view isKindOfClass:[_CPMenuItemView
class]])
899 view = [view superview];
902 return view._menuItem;
914 - (void)setTag:(CPInteger)aTag
926 if ([
self tag] == aTag)
930 count = _subviews.length;
932 for (; index < count; ++index)
934 var view = [_subviews[index] viewWithTag:aTag];
959 - (void)setFrame:(CGRect)aFrame
961 if (CGRectEqualToRect(_frame, aFrame))
964 _inhibitFrameAndBoundsChangedNotifications = YES;
969 _inhibitFrameAndBoundsChangedNotifications = NO;
971 if (_postsFrameChangedNotifications)
972 [CachedNotificationCenter postNotificationName:CPViewFrameDidChangeNotification object:self];
974 if (_isSuperviewAClipView)
984 return CGRectMakeCopy(_frame);
987 - (CGPoint)frameOrigin
989 return CGPointMakeCopy(_frame.origin);
994 return CGSizeMakeCopy(_frame.size);
1004 - (void)setCenter:(CGPoint)aPoint
1006 [
self setFrameOrigin:CGPointMake(aPoint.x - _frame.size.width / 2.0, aPoint.y - _frame.size.height / 2.0)];
1015 return CGPointMake(_frame.size.width / 2.0 + _frame.origin.x, _frame.size.height / 2.0 + _frame.origin.y);
1025 - (void)setFrameOrigin:(CGPoint)aPoint
1027 var origin = _frame.origin;
1029 if (!aPoint || CGPointEqualToPoint(origin, aPoint))
1032 origin.x = aPoint.x;
1033 origin.y = aPoint.y;
1035 if (_postsFrameChangedNotifications && !_inhibitFrameAndBoundsChangedNotifications)
1036 [CachedNotificationCenter postNotificationName:CPViewFrameDidChangeNotification object:self];
1038 if (_isSuperviewAClipView && !_inhibitFrameAndBoundsChangedNotifications)
1042 var transform = _superview ? _superview._boundsTransform : NULL;
1044 CPDOMDisplayServerSetStyleLeftTop(_DOMElement, transform, origin.x, origin.y);
1054 - (void)setFrameSize:(CGSize)aSize
1056 var size = _frame.size;
1058 if (!aSize || CGSizeEqualToSize(size, aSize))
1061 var oldSize = CGSizeMakeCopy(size);
1063 size.width = aSize.width;
1064 size.height = aSize.height;
1068 _bounds.size.width = aSize.width * 1 / _scaleSize.width;
1069 _bounds.size.height = aSize.height * 1 / _scaleSize.height;
1073 [_layer _owningViewBoundsChanged];
1075 if (_autoresizesSubviews)
1082 [
self _setDisplayServerSetStyleSize:size];
1084 if (_backgroundType !== BackgroundTrivialColor)
1086 if (_backgroundType === BackgroundTransparentColor)
1088 CPDOMDisplayServerSetStyleSize(_DOMImageParts[0], size.width, size.height);
1092 var images = [[_backgroundColor patternImage] imageSlices],
1096 if (_backgroundType === BackgroundVerticalThreePartImage)
1098 var top = _DOMImageSizes[0] ? _DOMImageSizes[0].height : 0,
1099 bottom = _DOMImageSizes[2] ? _DOMImageSizes[2].height : 0;
1104 CPDOMDisplayServerSetStyleBackgroundSize(_DOMImageParts[partIndex], frameSize.width +
"px", top +
"px");
1105 CPDOMDisplayServerSetStyleSize(_DOMImageParts[partIndex], size.width, top);
1108 if (_DOMImageSizes[1])
1110 var height = frameSize.height - top - bottom;
1112 CPDOMDisplayServerSetStyleBackgroundSize(_DOMImageParts[partIndex], frameSize.width +
"px", height +
"px");
1113 CPDOMDisplayServerSetStyleSize(_DOMImageParts[partIndex], size.width, size.height - top - bottom);
1118 CPDOMDisplayServerSetStyleBackgroundSize(_DOMImageParts[partIndex], frameSize.width +
"px", bottom +
"px");
1119 CPDOMDisplayServerSetStyleSize(_DOMImageParts[partIndex], size.width, bottom);
1122 else if (_backgroundType === BackgroundHorizontalThreePartImage)
1124 var left = _DOMImageSizes[0] ? _DOMImageSizes[0].width : 0,
1125 right = _DOMImageSizes[2] ? _DOMImageSizes[2].width : 0;
1130 CPDOMDisplayServerSetStyleBackgroundSize(_DOMImageParts[partIndex], left +
"px", frameSize.height +
"px");
1131 CPDOMDisplayServerSetStyleSize(_DOMImageParts[partIndex], left, size.height);
1134 if (_DOMImageSizes[1])
1136 var
width = (frameSize.width - left - right);
1138 CPDOMDisplayServerSetStyleBackgroundSize(_DOMImageParts[partIndex], width +
"px", frameSize.height +
"px");
1139 CPDOMDisplayServerSetStyleSize(_DOMImageParts[partIndex], size.width - left - right, size.height);
1144 CPDOMDisplayServerSetStyleBackgroundSize(_DOMImageParts[partIndex], right +
"px", frameSize.height +
"px");
1145 CPDOMDisplayServerSetStyleSize(_DOMImageParts[partIndex], right, size.height);
1148 else if (_backgroundType === BackgroundNinePartImage)
1150 var left = _DOMImageSizes[0] ? _DOMImageSizes[0].width : 0,
1151 right = _DOMImageSizes[2] ? _DOMImageSizes[2].width : 0,
1152 top = _DOMImageSizes[0] ? _DOMImageSizes[0].height : 0,
1153 bottom = _DOMImageSizes[6] ? _DOMImageSizes[6].height : 0,
1154 width = size.width - left - right,
1155 height = size.height - top - bottom;
1157 if (_DOMImageSizes[0])
1159 if (_DOMImageSizes[1])
1161 CPDOMDisplayServerSetStyleSize(_DOMImageParts[partIndex],
width, top);
1164 if (_DOMImageSizes[2])
1166 if (_DOMImageSizes[3])
1168 CPDOMDisplayServerSetStyleSize(_DOMImageParts[partIndex], _DOMImageSizes[3].
width, height);
1171 if (_DOMImageSizes[4])
1173 CPDOMDisplayServerSetStyleSize(_DOMImageParts[partIndex],
width, height);
1176 if (_DOMImageSizes[5])
1178 CPDOMDisplayServerSetStyleSize(_DOMImageParts[partIndex], _DOMImageSizes[5].
width, height);
1181 if (_DOMImageSizes[6])
1183 if (_DOMImageSizes[7])
1185 CPDOMDisplayServerSetStyleSize(_DOMImageParts[partIndex],
width, _DOMImageSizes[7].height);
1192 if (_postsFrameChangedNotifications && !_inhibitFrameAndBoundsChangedNotifications)
1193 [CachedNotificationCenter postNotificationName:CPViewFrameDidChangeNotification object:self];
1195 if (_isSuperviewAClipView && !_inhibitFrameAndBoundsChangedNotifications)
1204 - (void)_setDisplayServerSetStyleSize:(CGSize)aSize
1207 var scale = [
self scaleSize];
1209 CPDOMDisplayServerSetStyleSize(_DOMElement, aSize.width * 1 / scale.width, aSize.height * 1 / scale.height);
1211 if (_DOMContentsElement)
1213 CPDOMDisplayServerSetSize(_DOMContentsElement, aSize.width * _highDPIRatio * 1 / scale.width, aSize.height * _highDPIRatio * 1 / scale.height);
1214 CPDOMDisplayServerSetStyleSize(_DOMContentsElement, aSize.width * 1 / scale.width, aSize.height * 1 / scale.height);
1216 _needToSetTransformMatrix = YES;
1226 - (void)setBounds:(CGRect)bounds
1228 if (CGRectEqualToRect(_bounds, bounds))
1231 _inhibitFrameAndBoundsChangedNotifications = YES;
1236 _inhibitFrameAndBoundsChangedNotifications = NO;
1238 if (_postsBoundsChangedNotifications)
1239 [CachedNotificationCenter postNotificationName:CPViewBoundsDidChangeNotification object:self];
1241 if (_isSuperviewAClipView)
1251 return CGRectMakeCopy(_bounds);
1254 - (CGPoint)boundsOrigin
1256 return CGPointMakeCopy(_bounds.origin);
1259 - (CGSize)boundsSize
1261 return CGSizeMakeCopy(_bounds.size);
1270 - (void)setBoundsOrigin:(CGPoint)aPoint
1272 var origin = _bounds.origin;
1274 if (CGPointEqualToPoint(origin, aPoint))
1277 origin.x = aPoint.x;
1278 origin.y = aPoint.y;
1280 if (origin.x != 0 || origin.y != 0)
1287 _boundsTransform = nil;
1288 _inverseBoundsTransform = nil;
1292 var index = _subviews.length;
1296 var view = _subviews[index],
1297 origin = view._frame.origin;
1299 CPDOMDisplayServerSetStyleLeftTop(view._DOMElement, _boundsTransform, origin.x, origin.y);
1303 if (_postsBoundsChangedNotifications && !_inhibitFrameAndBoundsChangedNotifications)
1304 [CachedNotificationCenter postNotificationName:CPViewBoundsDidChangeNotification object:self];
1306 if (_isSuperviewAClipView && !_inhibitFrameAndBoundsChangedNotifications)
1316 - (void)setBoundsSize:(CGSize)aSize
1318 var size = _bounds.size;
1320 if (CGSizeEqualToSize(size, aSize))
1323 var frameSize = _frame.size;
1325 if (!CGSizeEqualToSize(size, frameSize))
1327 var origin = _bounds.origin;
1329 origin.x /= size.width / frameSize.width;
1330 origin.y /= size.height / frameSize.height;
1333 size.width = aSize.width;
1334 size.height = aSize.height;
1336 if (!CGSizeEqualToSize(size, frameSize))
1338 var origin = _bounds.origin;
1340 origin.x *= size.width / frameSize.width;
1341 origin.y *= size.height / frameSize.height;
1344 if (_postsBoundsChangedNotifications && !_inhibitFrameAndBoundsChangedNotifications)
1345 [CachedNotificationCenter postNotificationName:CPViewBoundsDidChangeNotification object:self];
1347 if (_isSuperviewAClipView && !_inhibitFrameAndBoundsChangedNotifications)
1356 - (void)resizeWithOldSuperviewSize:(CGSize)aSize
1363 var
frame = _superview._frame,
1364 newFrame = CGRectMakeCopy(_frame),
1365 dX = frame.size.width - aSize.width,
1366 dY = frame.size.height - aSize.height,
1370 (mask & CPViewWidthSizable ? _frame.size.width : 0) +
1371 (mask &
CPViewMaxXMargin ? aSize.width - _frame.size.width - _frame.origin.x : 0),
1373 (mask & CPViewHeightSizable ? _frame.size.height : 0) +
1374 (mask &
CPViewMaxYMargin ? aSize.height - _frame.size.height - _frame.origin.y : 0);
1377 newFrame.origin.x += dX * (baseX > 0 ? _frame.origin.x / baseX : evenFractionX);
1379 if (mask & CPViewWidthSizable)
1380 newFrame.size.width += dX * (baseX > 0 ? _frame.size.width / baseX : evenFractionX);
1382 if (mask & CPViewMinYMargin)
1383 newFrame.origin.y += dY * (baseY > 0 ? _frame.origin.y / baseY : evenFractionY);
1385 if (mask & CPViewHeightSizable)
1386 newFrame.size.height += dY * (baseY > 0 ? _frame.size.height / baseY : evenFractionY);
1395 - (void)resizeSubviewsWithOldSize:(CGSize)aSize
1397 var count = _subviews.length;
1400 [_subviews[count] resizeWithOldSuperviewSize:aSize];
1410 - (void)setAutoresizesSubviews:(BOOL)aFlag
1412 _autoresizesSubviews = !!aFlag;
1419 - (BOOL)autoresizesSubviews
1421 return _autoresizesSubviews;
1428 - (void)setAutoresizingMask:(
unsigned)aMask
1430 _autoresizingMask = aMask;
1436 - (unsigned)autoresizingMask
1438 return _autoresizingMask;
1446 - (BOOL)enterFullScreenMode
1458 _fullScreenModeState = _CPViewFullScreenModeStateMake(
self);
1462 [fullScreenWindow setLevel:CPScreenSaverWindowLevel];
1463 [fullScreenWindow setAutoresizingMask:CPViewWidthSizable | CPViewHeightSizable];
1465 var contentView = [fullScreenWindow contentView];
1468 [contentView addSubview:self];
1471 [
self setFrame:CGRectMakeCopy([contentView bounds])];
1473 [fullScreenWindow makeKeyAndOrderFront:self];
1475 [fullScreenWindow makeFirstResponder:self];
1477 _isInFullScreenMode = YES;
1485 - (void)exitFullScreenMode
1496 if (!_isInFullScreenMode)
1499 _isInFullScreenMode = NO;
1501 [
self setFrame:_fullScreenModeState.frame];
1503 [_fullScreenModeState.superview _insertSubview:self atIndex:_fullScreenModeState.index];
1511 - (BOOL)isInFullScreenMode
1513 return _isInFullScreenMode;
1520 - (void)setHidden:(BOOL)aFlag
1524 if (_isHidden === aFlag)
1532 _DOMElement.style.display = _isHidden ?
"none" :
"block";
1537 var view = [_window firstResponder];
1539 if ([view isKindOfClass:[
CPView class]])
1549 while (view = [view superview]);
1552 [
self _notifyViewDidHide];
1557 [
self _notifyViewDidUnhide];
1561 - (void)_notifyViewDidHide
1565 var count = [_subviews count];
1568 [_subviews[count] _notifyViewDidHide];
1571 - (void)_notifyViewDidUnhide
1573 [
self viewDidUnhide];
1575 var count = [_subviews count];
1578 [_subviews[count] _notifyViewDidUnhide];
1589 - (void)setClipsToBounds:(BOOL)shouldClip
1591 if (_clipsToBounds === shouldClip)
1594 _clipsToBounds = shouldClip;
1597 _DOMElement.style.overflow = _clipsToBounds ?
"hidden" :
"visible";
1601 - (BOOL)clipsToBounds
1603 return _clipsToBounds;
1611 - (void)setAlphaValue:(
float)anAlphaValue
1613 if (_opacity == anAlphaValue)
1616 _opacity = anAlphaValue;
1622 if (anAlphaValue === 1.0)
1623 try { _DOMElement.style.removeAttribute(
"filter") }
catch (anException) { }
1625 _DOMElement.style.filter =
"alpha(opacity=" + anAlphaValue * 100 +
")";
1628 _DOMElement.style.opacity = anAlphaValue;
1646 - (BOOL)isHiddenOrHasHiddenAncestor
1651 view = [view superview];
1653 return view !== nil;
1661 return ![
self isHiddenOrHasHiddenAncestor] && [[
self window] isVisible];
1687 - (void)viewDidUnhide
1715 - (void)setHitTests:(BOOL)shouldHitTest
1717 _hitTests = !!shouldHitTest;
1727 if (_isHidden || !_hitTests)
1731 sizeScale = [
self _hierarchyScaleSize];
1738 if (!CGRectContainsPoint(
frame, aPoint))
1742 i = _subviews.length,
1743 adjustedPoint = CGPointMake(aPoint.x - CGRectGetMinX(
frame), aPoint.y - CGRectGetMinY(
frame));
1745 if (_inverseBoundsTransform)
1751 affineTransform.tx *= [_superview _hierarchyScaleSize].width;
1752 affineTransform.ty *= [_superview _hierarchyScaleSize].height;
1756 affineTransform.tx *= sizeScale.width;
1757 affineTransform.ty *= sizeScale.height;
1765 if (view = [_subviews[i] hitTest:adjustedPoint])
1774 - (BOOL)needsPanelToBecomeKey
1783 - (BOOL)mouseDownCanMoveWindow
1790 if ([
self mouseDownCanMoveWindow])
1800 else if ([[
self nextResponder] isKindOfClass:
CPView])
1808 return [
self menu] || [[
self class] defaultMenu];
1817 if (_backgroundColor == aColor)
1820 if (aColor == [
CPNull null])
1823 _backgroundColor = aColor;
1826 var patternImage = [_backgroundColor patternImage],
1827 colorExists = _backgroundColor && ([_backgroundColor patternImage] || [_backgroundColor alphaComponent] > 0.0),
1828 colorHasAlpha = colorExists && [_backgroundColor alphaComponent] < 1.0,
1830 colorNeedsDOMElement = colorHasAlpha && !supportsRGBA,
1834 if ([patternImage isThreePartImage])
1836 _backgroundType = [patternImage isVertical] ? BackgroundVerticalThreePartImage : BackgroundHorizontalThreePartImage;
1839 else if ([patternImage isNinePartImage])
1841 _backgroundType = BackgroundNinePartImage;
1846 _backgroundType = colorNeedsDOMElement ? BackgroundTransparentColor : BackgroundTrivialColor;
1847 amount = (colorNeedsDOMElement ? 1 : 0) - _DOMImageParts.length;
1851 if (_backgroundType === BackgroundVerticalThreePartImage || _backgroundType === BackgroundHorizontalThreePartImage || _backgroundType === BackgroundNinePartImage)
1853 slices = [patternImage imageSlices];
1856 amount = MIN(amount, slices.length);
1858 for (var i = 0, count = slices.length; i < count; i++)
1860 var image = slices[i],
1861 size = [image size];
1863 if (!size || (size.width == 0 && size.height == 0))
1866 _DOMImageSizes[i] = size;
1874 amount -= _DOMImageParts.length;
1882 var DOMElement = DOMElementPrototype.cloneNode(
false);
1884 DOMElement.style.zIndex = -1000;
1886 _DOMImageParts.push(DOMElement);
1887 _DOMElement.appendChild(DOMElement);
1894 _DOMElement.removeChild(_DOMImageParts.pop());
1897 if (_backgroundType === BackgroundTrivialColor || _backgroundType === BackgroundTransparentColor)
1899 var colorCSS = colorExists ? [_backgroundColor cssString] :
"";
1901 if (colorNeedsDOMElement)
1903 _DOMElement.style.background =
"";
1904 _DOMImageParts[0].style.background = [_backgroundColor cssString];
1907 CPDOMDisplayServerSetStyleBackgroundSize(_DOMImageParts[0], [patternImage size].
width +
"px", [patternImage size].height +
"px");
1910 _DOMImageParts[0].style.filter =
"alpha(opacity=" + [_backgroundColor alphaComponent] * 100 +
")";
1912 _DOMImageParts[0].style.opacity = [_backgroundColor alphaComponent];
1914 var size = [
self bounds].size;
1915 CPDOMDisplayServerSetStyleSize(_DOMImageParts[0], size.width, size.height);
1918 _DOMElement.style.background = colorCSS;
1921 CPDOMDisplayServerSetStyleBackgroundSize(_DOMElement, [patternImage size].
width +
"px", [patternImage size].height +
"px");
1925 var frameSize = _frame.size,
1928 for (var i = 0; i < slices.length; i++)
1930 var size = _DOMImageSizes[i];
1935 var image = slices[i];
1940 CPDOMDisplayServerSetStyleSize(_DOMImageParts[partIndex], size.width, size.height);
1942 _DOMImageParts[partIndex].style.background =
"url(\"" + [image filename] +
"\")";
1947 try { _DOMImageParts[partIndex].style.removeAttribute(
"filter") }
catch (anException) { }
1949 _DOMImageParts[partIndex].style.opacity = 1.0;
1955 if (_backgroundType == BackgroundNinePartImage)
1957 var left = _DOMImageSizes[0] ? _DOMImageSizes[0].width : 0,
1958 right = _DOMImageSizes[2] ? _DOMImageSizes[2].width : 0,
1959 top = _DOMImageSizes[0] ? _DOMImageSizes[0].height : 0,
1960 bottom = _DOMImageSizes[6] ? _DOMImageSizes[6].height : 0,
1961 width = frameSize.width - left - right,
1962 height = frameSize.height - top - bottom;
1966 if (_DOMImageSizes[0])
1968 CPDOMDisplayServerSetStyleLeftTop(_DOMImageParts[partIndex], NULL, 0.0, 0.0);
1971 if (_DOMImageSizes[1])
1973 CPDOMDisplayServerSetStyleLeftTop(_DOMImageParts[partIndex], NULL, left, 0.0);
1974 CPDOMDisplayServerSetStyleSize(_DOMImageParts[partIndex],
width, _DOMImageSizes[1].height);
1977 if (_DOMImageSizes[2])
1979 CPDOMDisplayServerSetStyleRightTop(_DOMImageParts[partIndex], NULL, 0.0, 0.0);
1982 if (_DOMImageSizes[3])
1984 CPDOMDisplayServerSetStyleLeftTop(_DOMImageParts[partIndex], NULL, 0.0, top);
1985 CPDOMDisplayServerSetStyleSize(_DOMImageParts[partIndex], _DOMImageSizes[3].
width, height);
1988 if (_DOMImageSizes[4])
1990 CPDOMDisplayServerSetStyleLeftTop(_DOMImageParts[partIndex], NULL, left, top);
1991 CPDOMDisplayServerSetStyleSize(_DOMImageParts[partIndex],
width, height);
1994 if (_DOMImageSizes[5])
1996 CPDOMDisplayServerSetStyleRightTop(_DOMImageParts[partIndex], NULL, 0.0, top);
1997 CPDOMDisplayServerSetStyleSize(_DOMImageParts[partIndex], _DOMImageSizes[5].
width, height);
2000 if (_DOMImageSizes[6])
2002 CPDOMDisplayServerSetStyleLeftBottom(_DOMImageParts[partIndex], NULL, 0.0, 0.0);
2005 if (_DOMImageSizes[7])
2007 CPDOMDisplayServerSetStyleLeftBottom(_DOMImageParts[partIndex], NULL, left, 0.0);
2008 CPDOMDisplayServerSetStyleSize(_DOMImageParts[partIndex],
width, _DOMImageSizes[7].height);
2011 if (_DOMImageSizes[8])
2013 CPDOMDisplayServerSetStyleRightBottom(_DOMImageParts[partIndex], NULL, 0.0, 0.0);
2016 else if (_backgroundType == BackgroundVerticalThreePartImage)
2018 var top = _DOMImageSizes[0] ? _DOMImageSizes[0].height : 0,
2019 bottom = _DOMImageSizes[2] ? _DOMImageSizes[2].height : 0;
2026 CPDOMDisplayServerSetStyleBackgroundSize(_DOMImageParts[partIndex], frameSize.width +
"px", top +
"px");
2027 CPDOMDisplayServerSetStyleLeftTop(_DOMImageParts[partIndex], NULL, 0.0, 0.0);
2028 CPDOMDisplayServerSetStyleSize(_DOMImageParts[partIndex], frameSize.width, top);
2031 if (_DOMImageSizes[1])
2033 var height = frameSize.height - top - bottom;
2036 CPDOMDisplayServerSetStyleBackgroundSize(_DOMImageParts[partIndex], frameSize.width +
"px", height +
"px");
2037 CPDOMDisplayServerSetStyleLeftTop(_DOMImageParts[partIndex], NULL, 0.0, top);
2038 CPDOMDisplayServerSetStyleSize(_DOMImageParts[partIndex], frameSize.width, height);
2043 CPDOMDisplayServerSetStyleBackgroundSize(_DOMImageParts[partIndex], frameSize.width +
"px", bottom +
"px");
2044 CPDOMDisplayServerSetStyleLeftBottom(_DOMImageParts[partIndex], NULL, 0.0, 0.0);
2045 CPDOMDisplayServerSetStyleSize(_DOMImageParts[partIndex], frameSize.width, bottom);
2048 else if (_backgroundType == BackgroundHorizontalThreePartImage)
2050 var left = _DOMImageSizes[0] ? _DOMImageSizes[0].width : 0,
2051 right = _DOMImageSizes[2] ? _DOMImageSizes[2].width : 0;
2058 CPDOMDisplayServerSetStyleBackgroundSize(_DOMImageParts[partIndex], left +
"px", frameSize.height +
"px");
2059 CPDOMDisplayServerSetStyleLeftTop(_DOMImageParts[partIndex], NULL, 0.0, 0.0);
2060 CPDOMDisplayServerSetStyleSize(_DOMImageParts[partIndex], left, frameSize.height);
2063 if (_DOMImageSizes[1])
2065 var
width = (frameSize.width - left - right);
2067 CPDOMDisplayServerSetStyleBackgroundSize(_DOMImageParts[partIndex], width +
"px", frameSize.height +
"px");
2068 CPDOMDisplayServerSetStyleLeftTop(_DOMImageParts[partIndex], NULL, left, 0.0);
2069 CPDOMDisplayServerSetStyleSize(_DOMImageParts[partIndex], width, frameSize.height);
2074 CPDOMDisplayServerSetStyleBackgroundSize(_DOMImageParts[partIndex], right +
"px", frameSize.height +
"px");
2075 CPDOMDisplayServerSetStyleRightTop(_DOMImageParts[partIndex], NULL, 0.0, 0.0);
2076 CPDOMDisplayServerSetStyleSize(_DOMImageParts[partIndex], right, frameSize.height);
2088 return _backgroundColor;
2098 - (CGPoint)convertPoint:(CGPoint)aPoint fromView:(
CPView)aView
2111 - (CGPoint)convertPointFromBase:(CGPoint)aPoint
2122 - (CGPoint)convertPoint:(CGPoint)aPoint toView:(
CPView)aView
2136 - (CGPoint)convertPointToBase:(CGPoint)aPoint
2147 - (CGSize)convertSize:(CGSize)aSize fromView:(
CPView)aView
2161 - (CGSize)convertSize:(CGSize)aSize toView:(
CPView)aView
2175 - (CGRect)convertRect:(CGRect)aRect fromView:(
CPView)aView
2188 - (CGRect)convertRectFromBase:(CGRect)aRect
2199 - (CGRect)convertRect:(CGRect)aRect toView:(
CPView)aView
2212 - (CGRect)convertRectToBase:(CGRect)aRect
2229 - (void)setPostsFrameChangedNotifications:(BOOL)shouldPostFrameChangedNotifications
2231 shouldPostFrameChangedNotifications = !!shouldPostFrameChangedNotifications;
2233 if (_postsFrameChangedNotifications === shouldPostFrameChangedNotifications)
2236 _postsFrameChangedNotifications = shouldPostFrameChangedNotifications;
2242 - (BOOL)postsFrameChangedNotifications
2244 return _postsFrameChangedNotifications;
2259 - (void)setPostsBoundsChangedNotifications:(BOOL)shouldPostBoundsChangedNotifications
2261 shouldPostBoundsChangedNotifications = !!shouldPostBoundsChangedNotifications;
2263 if (_postsBoundsChangedNotifications === shouldPostBoundsChangedNotifications)
2266 _postsBoundsChangedNotifications = shouldPostBoundsChangedNotifications;
2274 - (BOOL)postsBoundsChangedNotifications
2276 return _postsBoundsChangedNotifications;
2289 - (void)dragImage:(
CPImage)anImage at:(CGPoint)aLocation offset:(CGSize)mouseOffset event:(
CPEvent)anEvent pasteboard:(
CPPasteboard)aPasteboard source:(
id)aSourceObject slideBack:(BOOL)slideBack
2291 [_window dragImage:anImage at:[
self convertPoint:aLocation
toView:nil] offset:mouseOffset event:anEvent pasteboard:aPasteboard source:aSourceObject slideBack:slideBack];
2304 - (void)dragView:(
CPView)aView at:(CGPoint)aLocation offset:(CGSize)mouseOffset event:(
CPEvent)anEvent pasteboard:(
CPPasteboard)aPasteboard source:(
id)aSourceObject slideBack:(BOOL)slideBack
2306 [_window dragView:aView at:[
self convertPoint:aLocation
toView:nil] offset:mouseOffset event:anEvent pasteboard:aPasteboard source:aSourceObject slideBack:slideBack];
2313 - (void)registerForDraggedTypes:(CPArray)pasteboardTypes
2315 if (!pasteboardTypes || ![pasteboardTypes count])
2318 var theWindow = [
self window];
2320 [theWindow _noteUnregisteredDraggedTypes:_registeredDraggedTypes];
2321 [_registeredDraggedTypes addObjectsFromArray:pasteboardTypes];
2322 [theWindow _noteRegisteredDraggedTypes:_registeredDraggedTypes];
2324 _registeredDraggedTypesArray = nil;
2331 - (CPArray)registeredDraggedTypes
2333 if (!_registeredDraggedTypesArray)
2334 _registeredDraggedTypesArray = [_registeredDraggedTypes allObjects];
2336 return _registeredDraggedTypesArray;
2342 - (void)unregisterDraggedTypes
2344 [[
self window] _noteUnregisteredDraggedTypes:_registeredDraggedTypes];
2346 _registeredDraggedTypes = [CPSet set];
2347 _registeredDraggedTypesArray = [];
2354 - (void)drawRect:(CGRect)aRect
2367 - (void)scaleUnitSquareToSize:(CGSize)aSize
2374 bounds.size.width *= _scaleSize.width;
2375 bounds.size.height *= _scaleSize.height;
2378 _scaleSize = CGSizeMakeCopy([
self scaleSize]);
2379 _scaleSize.height *= aSize.height;
2380 _scaleSize.width *= aSize.width;
2384 _hierarchyScaleSize = CGSizeMakeCopy([
self _hierarchyScaleSize]);
2385 _hierarchyScaleSize.height *= aSize.height;
2386 _hierarchyScaleSize.width *= aSize.width;
2393 [_subviews makeObjectsPerformSelector:@selector(_scaleSizeUnitSquareToSize:) withObject:aSize];
2400 - (void)_scaleSizeUnitSquareToSize:(CGSize)aSize
2402 _hierarchyScaleSize = CGSizeMakeCopy([_superview _hierarchyScaleSize]);
2406 _hierarchyScaleSize.width *= _scaleSize.width;
2407 _hierarchyScaleSize.height *= _scaleSize.height;
2410 [_subviews makeObjectsPerformSelector:@selector(_scaleSizeUnitSquareToSize:) withObject:aSize];
2416 - (CGSize)_hierarchyScaleSize
2418 return _hierarchyScaleSize || CGSizeMake(1.0, 1.0);
2424 - (void)_applyCSSScalingTranformations
2429 var scale = [
self scaleSize],
2433 self._DOMElement.style[browserPropertyTransform] =
'scale(' + scale.
width + ', ' + scale.height + ')';
2434 self._DOMElement.style[browserPropertyTransformOrigin] =
'0 0';
2436 [
self _setDisplayServerSetStyleSize:[
self frameSize]];
2450 [
self _applyCSSScalingTranformations];
2459 - (void)setNeedsDisplayInRect:(CGRect)aRect
2464 if (CGRectIsEmpty(aRect))
2467 if (_dirtyRect && !CGRectIsEmpty(_dirtyRect))
2468 _dirtyRect = CGRectUnion(aRect, _dirtyRect);
2470 _dirtyRect = CGRectMakeCopy(aRect);
2472 _CPDisplayServerAddDisplayObject(
self);
2475 - (BOOL)needsDisplay
2477 return _dirtyRect && !CGRectIsEmpty(_dirtyRect);
2483 - (void)displayIfNeeded
2485 if ([
self needsDisplay])
2497 - (void)displayIfNeededInRect:(CGRect)aRect
2499 if ([
self needsDisplay])
2507 - (void)displayRect:(CGRect)aRect
2531 - (void)viewWillDraw
2540 if (!_graphicsContext)
2545 var
width = CGRectGetWidth(_frame),
2546 height = CGRectGetHeight(_frame),
2547 devicePixelRatio = window.devicePixelRatio || 1,
2552 _DOMContentsElement = graphicsPort.DOMElement;
2554 _DOMContentsElement.style.zIndex = -100;
2556 _DOMContentsElement.style.overflow =
"hidden";
2557 _DOMContentsElement.style.position =
"absolute";
2558 _DOMContentsElement.style.visibility =
"visible";
2560 CPDOMDisplayServerSetSize(_DOMContentsElement, width * _highDPIRatio, height * _highDPIRatio);
2562 CPDOMDisplayServerSetStyleLeftTop(_DOMContentsElement, NULL, 0.0, 0.0);
2563 CPDOMDisplayServerSetStyleSize(_DOMContentsElement, width, height);
2568 _DOMElement.style.webkitTransform =
'translateX(0)';
2570 CPDOMDisplayServerAppendChild(_DOMElement, _DOMContentsElement);
2573 _needToSetTransformMatrix = YES;
2577 if (_needToSetTransformMatrix)
2578 [_graphicsContext graphicsPort].setTransform(_highDPIRatio, 0, 0 , _highDPIRatio, 0, 0);
2581 _needToSetTransformMatrix = NO;
2597 - (void)setNeedsLayout
2602 - (void)setNeedsLayout:(BOOL)needLayout
2612 _CPDisplayServerAddLayoutObject(
self);
2617 return _needsLayout;
2620 - (void)layoutIfNeeded
2630 - (void)layoutSubviews
2645 - (CGRect)visibleRect
2650 return CGRectIntersection([
self convertRect:[_superview visibleRect] fromView:_superview], _bounds);
2657 var superview = _superview,
2660 while (superview && ![superview isKindOfClass:clipViewClass])
2661 superview = superview._superview;
2670 - (void)scrollPoint:(CGPoint)aPoint
2672 var clipView = [
self _enclosingClipView];
2685 - (BOOL)scrollRectToVisible:(CGRect)aRect
2688 aRect = CGRectIntersection(aRect, _bounds);
2691 if (CGRectIsEmpty(aRect))
2694 var enclosingClipView = [
self _enclosingClipView];
2697 if (!enclosingClipView)
2700 var documentView = [enclosingClipView documentView];
2707 var documentViewVisibleRect = [documentView visibleRect],
2711 if (CGRectContainsRect(documentViewVisibleRect, rectInDocumentView))
2714 var scrollPoint = CGPointMakeCopy(documentViewVisibleRect.origin);
2717 if (CGRectGetMinX(rectInDocumentView) < CGRectGetMinX(documentViewVisibleRect))
2718 scrollPoint.x = CGRectGetMinX(rectInDocumentView);
2719 else if (CGRectGetMaxX(rectInDocumentView) > CGRectGetMaxX(documentViewVisibleRect))
2720 scrollPoint.x += CGRectGetMaxX(rectInDocumentView) - CGRectGetMaxX(documentViewVisibleRect);
2722 if (CGRectGetMinY(rectInDocumentView) < CGRectGetMinY(documentViewVisibleRect))
2723 scrollPoint.y = CGRectGetMinY(rectInDocumentView);
2724 else if (CGRectGetMaxY(rectInDocumentView) > CGRectGetMaxY(documentViewVisibleRect))
2725 scrollPoint.y += CGRectGetMaxY(rectInDocumentView) - CGRectGetMaxY(documentViewVisibleRect);
2727 [enclosingClipView scrollToPoint:scrollPoint];
2746 - (CGRect)adjustScroll:(CGRect)proposedVisibleRect
2748 return proposedVisibleRect;
2754 - (void)scrollRect:(CGRect)aRect by:(
float)anAmount
2765 var superview = _superview,
2768 while (superview && ![superview isKindOfClass:scrollViewClass])
2769 superview = superview._superview;
2779 - (void)scrollClipView:(
CPClipView)aClipView toPoint:(CGPoint)aPoint
2796 - (BOOL)inLiveResize
2798 return _inLiveResize;
2810 - (void)viewWillStartLiveResize
2812 _inLiveResize = YES;
2825 - (void)viewDidEndLiveResize
2850 var count = [_subviews count];
2854 if ([_subviews[count] performKeyEquivalent:anEvent])
2860 - (BOOL)canBecomeKeyView
2867 return _nextKeyView;
2873 resultUID = [result UID],
2874 unsuitableResults = {};
2876 while (result && ![result canBecomeKeyView])
2878 unsuitableResults[resultUID] = 1;
2879 result = [result nextKeyView];
2881 resultUID = [result UID];
2884 if (unsuitableResults[resultUID])
2893 return _previousKeyView;
2899 firstResult = result;
2901 while (result && ![result canBecomeKeyView])
2903 result = [result previousKeyView];
2906 if (result === firstResult)
2913 - (void)_setPreviousKeyView:(
CPView)previous
2917 var previousWindow = [previous
window];
2919 if (!previousWindow || previousWindow === _window)
2921 _previousKeyView = previous;
2926 _previousKeyView = nil;
2931 if (![next isEqual:
self])
2933 var nextWindow = [next
window];
2935 if (!nextWindow || nextWindow === _window)
2937 _nextKeyView = next;
2938 [_nextKeyView _setPreviousKeyView:self];
2955 if (_layer == aLayer)
2960 _layer._owningView = nil;
2962 _DOMElement.removeChild(_layer._DOMElement);
2970 var
bounds = CGRectMakeCopy([
self bounds]);
2972 [_layer _setOwningView:self];
2975 _layer._DOMElement.style.zIndex = 100;
2977 _DOMElement.appendChild(_layer._DOMElement);
2994 - (void)setWantsLayer:(BOOL)aFlag
2996 _wantsLayer = !!aFlag;
3018 - (void)setScaleSize:(CGSize)aSize
3020 if (CGSizeEqualToSize(_scaleSize, aSize))
3023 var size = CGSizeMakeZero(),
3024 scale = CGSizeMakeCopy([
self scaleSize]);
3026 size.height = aSize.height / scale.height;
3027 size.width = aSize.width / scale.width;
3039 return _scaleSize || CGSizeMake(1.0, 1.0);
3045 #pragma mark Theme States
3047 - (unsigned)themeState
3054 if (aState.isa && [aState isKindOfClass:CPArray])
3055 return _themeState.hasThemeState.apply(_themeState, aState);
3057 return _themeState.hasThemeState(aState);
3062 if (aState && aState.isa && [aState isKindOfClass:CPArray])
3063 aState = CPThemeState.apply(null, aState);
3065 if (_themeState.hasThemeState(aState))
3068 _themeState = CPThemeState(_themeState, aState);
3078 if (aState && aState.isa && [aState isKindOfClass:CPArray])
3079 aState = CPThemeState.apply(null, aState);
3081 var oldThemeState = _themeState;
3082 _themeState = _themeState.without(aState);
3084 if (oldThemeState === _themeState)
3093 - (BOOL)becomeFirstResponder
3097 [
self _notifyViewDidBecomeFirstResponder];
3101 - (void)_notifyViewDidBecomeFirstResponder
3103 [
self setThemeState:CPThemeStateFirstResponder];
3105 var count = [_subviews count];
3107 [_subviews[count] _notifyViewDidBecomeFirstResponder];
3110 - (BOOL)resignFirstResponder
3114 [
self _notifyViewDidResignFirstResponder];
3118 - (void)_notifyViewDidResignFirstResponder
3120 [
self unsetThemeState:CPThemeStateFirstResponder];
3122 var count = [_subviews count];
3124 [_subviews[count] _notifyViewDidResignFirstResponder];
3127 - (void)_notifyWindowDidBecomeKey
3129 [
self setThemeState:CPThemeStateKeyWindow];
3131 var count = [_subviews count];
3133 [_subviews[count] _notifyWindowDidBecomeKey];
3136 - (void)_notifyWindowDidResignKey
3138 [
self unsetThemeState:CPThemeStateKeyWindow];
3140 var count = [_subviews count];
3142 [_subviews[count] _notifyWindowDidResignKey];
3145 #pragma mark Theme Attributes
3157 return [[
self class] defaultThemeClass];
3162 _themeClass = theClass;
3164 [
self _loadThemeAttributes];
3175 + (CPArray)_themeAttributes
3180 var theClass = [
self class],
3185 for (; theClass && theClass !== CPViewClass; theClass = [theClass superclass])
3189 if (cachedAttributes)
3191 attributes = attributes.length ? attributes.concat(cachedAttributes) : attributes;
3197 var attributeDictionary = [theClass themeAttributes];
3199 if (!attributeDictionary)
3202 var attributeKeys = [attributeDictionary allKeys],
3203 attributeCount = attributeKeys.length;
3205 while (attributeCount--)
3207 var attributeName = attributeKeys[attributeCount],
3208 attributeValue = [attributeDictionary objectForKey:attributeName];
3210 attributes.push(attributeValue === nullValue ? nil : attributeValue);
3211 attributes.push(attributeName);
3218 - (void)_loadThemeAttributes
3220 var theClass = [
self class],
3221 attributes = [theClass _themeAttributes],
3222 count = attributes.length;
3227 var theme = [
self theme],
3228 themeClass = [
self themeClass];
3230 _themeAttributes = {};
3234 var attributeName = attributes[count--],
3235 attribute = [[_CPThemeAttribute alloc] initWithName:attributeName defaultValue:attributes[count]];
3237 [attribute setParentAttribute:[theme attributeWithName:attributeName forClass:themeClass]];
3239 _themeAttributes[attributeName] = attribute;
3245 if (_theme === aTheme)
3253 - (void)_setThemeIncludingDescendants:(
CPTheme)aTheme
3255 [
self setTheme:aTheme];
3256 [[
self subviews] makeObjectsPerformSelector:@selector(_setThemeIncludingDescendants:) withObject:aTheme];
3264 - (void)viewDidChangeTheme
3266 if (!_themeAttributes)
3269 var theme = [
self theme],
3272 for (var attributeName in _themeAttributes)
3273 if (_themeAttributes.hasOwnProperty(attributeName))
3274 [_themeAttributes[attributeName] setParentAttribute:[theme attributeWithName:attributeName forClass:themeClass]];
3282 var dictionary = @{};
3284 if (_themeAttributes)
3286 var theme = [
self theme];
3288 for (var attributeName in _themeAttributes)
3289 if (_themeAttributes.hasOwnProperty(attributeName))
3290 [dictionary setObject:_themeAttributes[attributeName] forKey:attributeName];
3298 if (aState.isa && [aState isKindOfClass:CPArray])
3299 aState = CPThemeState.apply(null, aState);
3301 if (!_themeAttributes || !_themeAttributes[aName])
3306 [_themeAttributes[aName] setValue:aValue forState:aState];
3308 if ([
self currentValueForThemeAttribute:aName] === currentValue)
3315 - (void)setValue:(
id)aValue forThemeAttribute:(
CPString)aName
3317 if (!_themeAttributes || !_themeAttributes[aName])
3322 [_themeAttributes[aName] setValue:aValue];
3324 if ([
self currentValueForThemeAttribute:aName] === currentValue)
3333 if (aState.isa && [aState isKindOfClass:CPArray])
3334 aState = CPThemeState.apply(null, aState);
3336 if (!_themeAttributes || !_themeAttributes[aName])
3339 return [_themeAttributes[aName] valueForState:aState];
3344 if (!_themeAttributes || !_themeAttributes[aName])
3347 return [_themeAttributes[aName] value];
3352 if (!_themeAttributes || !_themeAttributes[aName])
3355 return [_themeAttributes[aName] valueForState:_themeState];
3360 return (_themeAttributes && _themeAttributes[aName] !== undefined);
3371 - (void)registerThemeValues:(CPArray)themeValues
3373 for (var i = 0; i < themeValues.length; ++i)
3375 var attributeValueState = themeValues[i],
3376 attribute = attributeValueState[0],
3377 value = attributeValueState[1],
3378 state = attributeValueState[2];
3397 - (void)registerThemeValues:(CPArray)themeValues inherit:(CPArray)inheritedValues
3400 if (inheritedValues)
3412 - (CGRect)rectForEphemeralSubviewNamed:(
CPString)aViewName
3414 return CGRectMakeZero();
3418 positioned:(CPWindowOrderingMode)anOrderingMode
3419 relativeToEphemeralSubviewNamed:(
CPString)relativeToViewName
3421 if (!_ephemeralSubviewsForNames)
3423 _ephemeralSubviewsForNames = {};
3424 _ephemeralSubviews = [CPSet set];
3431 if (!_ephemeralSubviewsForNames[aViewName])
3435 [_ephemeralSubviews addObject:_ephemeralSubviewsForNames[aViewName]];
3437 if (_ephemeralSubviewsForNames[aViewName])
3441 if (_ephemeralSubviewsForNames[aViewName])
3442 [_ephemeralSubviewsForNames[aViewName] setFrame:frame];
3444 else if (_ephemeralSubviewsForNames[aViewName])
3446 [_ephemeralSubviewsForNames[aViewName] removeFromSuperview];
3448 [_ephemeralSubviews removeObject:_ephemeralSubviewsForNames[aViewName]];
3449 delete _ephemeralSubviewsForNames[aViewName];
3452 return _ephemeralSubviewsForNames[aViewName];
3457 if (!_ephemeralSubviewsForNames)
3460 return (_ephemeralSubviewsForNames[aViewName] || nil);
3501 _DOMElement = DOMElementPrototype.cloneNode(
false);
3502 AppKitTagDOMElement(
self, _DOMElement);
3506 _frame = [aCoder decodeRectForKey:CPViewFrameKey];
3507 _bounds = [aCoder decodeRectForKey:CPViewBoundsKey];
3514 _tag = [aCoder containsValueForKey:CPViewTagKey] ? [aCoder decodeIntForKey:CPViewTagKey] : -1;
3515 _identifier = [aCoder decodeObjectForKey:CPReuseIdentifierKey];
3517 _window = [aCoder decodeObjectForKey:CPViewWindowKey];
3518 _superview = [aCoder decodeObjectForKey:CPViewSuperviewKey];
3524 var subviews = [aCoder decodeObjectForKey:CPViewSubviewsKey] || [];
3526 for (var i = 0, count = [subviews count]; i < count; ++i)
3529 subviews[i]._superview = nil;
3534 _registeredDraggedTypes = [CPSet set];
3535 _registeredDraggedTypesArray = [];
3539 if (_autoresizingMask === nil)
3540 _autoresizingMask = [aCoder decodeIntForKey:CPViewAutoresizingMaskKey] ||
CPViewNotSizable;
3542 _autoresizesSubviews = ![aCoder containsValueForKey:CPViewAutoresizesSubviewsKey] || [aCoder decodeBoolForKey:CPViewAutoresizesSubviewsKey];
3544 _hitTests = ![aCoder containsValueForKey:CPViewHitTestsKey] || [aCoder decodeBoolForKey:CPViewHitTestsKey];
3546 _toolTip = [aCoder decodeObjectForKey:CPViewToolTipKey];
3549 [
self _installToolTipEventHandlers];
3551 _scaleSize = [aCoder containsValueForKey:CPViewScaleKey] ? [aCoder decodeSizeForKey:CPViewScaleKey] : CGSizeMake(1.0, 1.0);
3552 _hierarchyScaleSize = [aCoder containsValueForKey:CPViewSizeScaleKey] ? [aCoder decodeSizeForKey:CPViewSizeScaleKey] : CGSizeMake(1.0, 1.0);
3553 _isScaled = [aCoder containsValueForKey:CPViewIsScaledKey] ? [aCoder decodeBoolForKey:CPViewIsScaledKey] : NO;
3557 _DOMImageParts = [];
3558 _DOMImageSizes = [];
3560 CPDOMDisplayServerSetStyleLeftTop(_DOMElement, NULL, CGRectGetMinX(_frame), CGRectGetMinY(_frame));
3561 [
self _setDisplayServerSetStyleSize:_frame.size];
3564 count = _subviews.length;
3566 for (; index < count; ++index)
3568 CPDOMDisplayServerAppendChild(_DOMElement, _subviews[index]._DOMElement);
3573 [
self setHidden:[aCoder decodeBoolForKey:CPViewIsHiddenKey]];
3576 [
self setAlphaValue:[aCoder decodeIntForKey:CPViewOpacityKey]];
3581 [
self _setupViewFlags];
3584 _themeClass = [aCoder decodeObjectForKey:CPViewThemeClassKey];
3586 _themeAttributes = {};
3588 var theClass = [
self class],
3590 attributes = [theClass _themeAttributes],
3591 count = attributes.
length;
3595 var attributeName = attributes[count--];
3597 _themeAttributes[attributeName] =
CPThemeAttributeDecode(aCoder, attributeName, attributes[count], _theme, themeClass);
3616 [aCoder encodeInt:_tag forKey:CPViewTagKey];
3618 [aCoder encodeRect:_frame forKey:CPViewFrameKey];
3619 [aCoder encodeRect:_bounds forKey:CPViewBoundsKey];
3622 if (_window !== nil)
3623 [aCoder encodeConditionalObject:_window forKey:CPViewWindowKey];
3625 var count = [_subviews count],
3626 encodedSubviews = _subviews;
3628 if (count > 0 && [_ephemeralSubviews count] > 0)
3630 encodedSubviews = [encodedSubviews copy];
3633 if ([_ephemeralSubviews containsObject:encodedSubviews[count]])
3634 encodedSubviews.splice(count, 1);
3637 if (encodedSubviews.length > 0)
3638 [aCoder encodeObject:encodedSubviews forKey:CPViewSubviewsKey];
3641 if (_superview !== nil)
3642 [aCoder encodeConditionalObject:_superview forKey:CPViewSuperviewKey];
3645 [aCoder encodeInt:_autoresizingMask forKey:CPViewAutoresizingMaskKey];
3647 if (!_autoresizesSubviews)
3648 [aCoder encodeBool:_autoresizesSubviews forKey:CPViewAutoresizesSubviewsKey];
3650 if (_backgroundColor !== nil)
3651 [aCoder encodeObject:_backgroundColor forKey:CPViewBackgroundColorKey];
3653 if (_hitTests !== YES)
3654 [aCoder encodeBool:_hitTests forKey:CPViewHitTestsKey];
3656 if (_opacity !== 1.0)
3657 [aCoder encodeFloat:_opacity forKey:CPViewOpacityKey];
3660 [aCoder encodeBool:_isHidden forKey:CPViewIsHiddenKey];
3663 [aCoder encodeObject:_toolTip forKey:CPViewToolTipKey];
3667 if (nextKeyView !== nil && ![nextKeyView
isEqual:
self])
3668 [aCoder encodeConditionalObject:nextKeyView forKey:CPViewNextKeyViewKey];
3672 if (previousKeyView !== nil && ![previousKeyView
isEqual:
self])
3673 [aCoder encodeConditionalObject:previousKeyView forKey:CPViewPreviousKeyViewKey];
3675 [aCoder encodeObject:[
self themeClass] forKey:CPViewThemeClassKey];
3676 [aCoder encodeObject:String(_themeState) forKey:CPViewThemeStateKey];
3678 for (var attributeName in _themeAttributes)
3679 if (_themeAttributes.hasOwnProperty(attributeName))
3683 [aCoder encodeObject:_identifier forKey:CPReuseIdentifierKey];
3685 [aCoder encodeSize:[
self scaleSize] forKey:CPViewScaleKey];
3686 [aCoder encodeSize:[
self _hierarchyScaleSize] forKey:CPViewSizeScaleKey];
3687 [aCoder encodeBool:_isScaled forKey:CPViewIsScaledKey];
3692 var _CPViewFullScreenModeStateMake =
function(aView)
3694 var superview = aView._superview;
3696 return { autoresizingMask:aView._autoresizingMask,
frame:CGRectMakeCopy(aView._frame), index:(superview ? [superview._subviews indexOfObjectIdenticalTo:aView] : 0), superview:superview };
3699 var _CPViewGetTransform =
function( fromView, toView)
3708 var view = fromView;
3713 while (view && view != toView)
3715 var
frame = view._frame;
3723 transform.tx += CGRectGetMinX(frame);
3724 transform.ty += CGRectGetMinY(frame);
3726 if (view._boundsTransform)
3739 view = view._superview;
3743 if (view === toView)
3747 else if (fromView && toView)
3749 fromWindow = [fromView window];
3750 toWindow = [toView window];
3752 if (fromWindow && toWindow && fromWindow !== toWindow)
3761 while (view && view != fromView)
3763 var frame = CGRectMakeCopy(view._frame);
3768 transform2.a *= 1 / view._scaleSize.width;
3769 transform2.d *= 1 / view._scaleSize.height;
3772 transform2.tx += CGRectGetMinX(frame) * transform2.a;
3773 transform2.ty += CGRectGetMinY(frame) * transform2.d;
3775 if (view._boundsTransform)
3778 inverseBoundsTransform.tx -= view._inverseBoundsTransform.tx * transform2.a;
3779 inverseBoundsTransform.ty -= view._inverseBoundsTransform.ty * transform2.d;
3784 view = view._superview;
3787 transform2.tx = -transform2.tx;
3788 transform2.ty = -transform2.ty;
3790 if (view === fromView)
3839 _identifier = aValue;