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)
99 var DOMElementPrototype = nil,
101 BackgroundTrivialColor = 0,
102 BackgroundVerticalThreePartImage = 1,
103 BackgroundHorizontalThreePartImage = 2,
104 BackgroundNinePartImage = 3,
105 BackgroundTransparentColor = 4;
145 CGAffineTransform _boundsTransform;
146 CGAffineTransform _inverseBoundsTransform;
148 CPSet _registeredDraggedTypes;
149 CPArray _registeredDraggedTypesArray;
155 BOOL _postsFrameChangedNotifications;
156 BOOL _postsBoundsChangedNotifications;
157 BOOL _inhibitFrameAndBoundsChangedNotifications;
159 BOOL _isSuperviewAClipView;
162 DOMElement _DOMElement;
163 DOMElement _DOMContentsElement;
165 CPArray _DOMImageParts;
166 CPArray _DOMImageSizes;
168 unsigned _backgroundType;
176 BOOL _autoresizesSubviews;
177 unsigned _autoresizingMask;
183 BOOL _isInFullScreenMode;
185 _CPViewFullScreenModeState _fullScreenModeState;
189 CGSize _hierarchyScaleSize;
193 BOOL _needToSetTransformMatrix;
198 JSObject _ephemeralSubviews;
200 JSObject _ephemeralSubviewsForNames;
201 CPSet _ephereralSubviews;
207 unsigned _viewClassFlags;
211 Function _toolTipFunctionIn;
212 Function _toolTipFunctionOut;
213 BOOL _toolTipInstalled;
217 BOOL _allowsVibrancy;
222 BOOL _inhibitUpdateTrackingAreas;
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
276 return [CPSet setWithObjects:@"frameOrigin", @"frameSize"];
281 return [CPSet setWithObjects:@"boundsOrigin", @"boundsSize"];
289 - (void)_setupViewFlags
291 var theClass = [
self class],
292 classUID = [theClass UID];
298 if ([theClass instanceMethodForSelector:
@selector(drawRect:)] !== [
CPView instanceMethodForSelector:@selector(drawRect:)]
299 || [theClass instanceMethodForSelector:@selector(viewWillDraw)] !== [
CPView instanceMethodForSelector:@selector(viewWillDraw)])
302 if ([theClass instanceMethodForSelector:
@selector(
viewWillLayout)] !== [
CPView instanceMethodForSelector:@selector(viewWillLayout)])
305 if ([theClass instanceMethodForSelector:
@selector(
layoutSubviews)] !== [
CPView instanceMethodForSelector:@selector(layoutSubviews)])
323 - (id)initWithFrame:(CGRect)aFrame
329 var
width = CGRectGetWidth(aFrame),
330 height = CGRectGetHeight(aFrame);
333 _registeredDraggedTypes = [CPSet set];
334 _registeredDraggedTypesArray = [];
340 _frame = CGRectMakeCopy(aFrame);
341 _bounds = CGRectMake(0.0, 0.0, width, height);
344 _autoresizesSubviews = YES;
345 _clipsToBounds = YES;
351 _hierarchyScaleSize = CGSizeMake(1.0 , 1.0);
352 _scaleSize = CGSizeMake(1.0, 1.0);
356 _themeState = CPThemeStateNormal;
359 _DOMElement = DOMElementPrototype.cloneNode(
false);
360 AppKitTagDOMElement(
self, _DOMElement);
362 CPDOMDisplayServerSetStyleLeftTop(_DOMElement, NULL, CGRectGetMinX(aFrame), CGRectGetMinY(aFrame));
363 CPDOMDisplayServerSetStyleSize(_DOMElement, width, height);
369 [
self _setupViewFlags];
370 [
self _loadThemeAttributes];
384 if (_toolTip == aToolTip)
387 if (aToolTip && ![aToolTip isKindOfClass:
CPString])
392 [
self _manageToolTipInstallation];
395 - (void)_manageToolTipInstallation
397 if ([
self window] && _toolTip)
398 [
self _installToolTipEventHandlers];
400 [
self _uninstallToolTipEventHandlers];
406 - (void)_installToolTipEventHandlers
408 if (_toolTipInstalled)
411 if (!_toolTipFunctionIn)
412 _toolTipFunctionIn =
function(e) { [_CPToolTip scheduleToolTipForView:self]; }
414 if (!_toolTipFunctionOut)
415 _toolTipFunctionOut =
function(e) { [_CPToolTip invalidateCurrentToolTipIfNeeded]; };
418 if (_DOMElement.addEventListener)
420 _DOMElement.addEventListener(
"mouseover", _toolTipFunctionIn, YES);
421 _DOMElement.addEventListener(
"keypress", _toolTipFunctionOut, YES);
422 _DOMElement.addEventListener(
"mouseout", _toolTipFunctionOut, YES);
424 else if (_DOMElement.attachEvent)
426 _DOMElement.attachEvent(
"onmouseover", _toolTipFunctionIn);
427 _DOMElement.attachEvent(
"onkeypress", _toolTipFunctionOut);
428 _DOMElement.attachEvent(
"onmouseout", _toolTipFunctionOut);
432 _toolTipInstalled = YES;
439 - (void)_uninstallToolTipEventHandlers
441 if (!_toolTipInstalled)
445 if (_DOMElement.removeEventListener)
447 _DOMElement.removeEventListener(
"mouseover", _toolTipFunctionIn, YES);
448 _DOMElement.removeEventListener(
"keypress", _toolTipFunctionOut, YES);
449 _DOMElement.removeEventListener(
"mouseout", _toolTipFunctionOut, YES);
451 else if (_DOMElement.detachEvent)
453 _DOMElement.detachEvent(
"onmouseover", _toolTipFunctionIn);
454 _DOMElement.detachEvent(
"onkeypress", _toolTipFunctionOut);
455 _DOMElement.detachEvent(
"onmouseout", _toolTipFunctionOut);
459 _toolTipFunctionIn = nil;
460 _toolTipFunctionOut = nil;
462 _toolTipInstalled = NO;
480 return [_subviews copy];
497 [
self _insertSubview:aSubview atIndex:CPNotFound];
506 - (void)addSubview:(
CPView)aSubview positioned:(CPWindowOrderingMode)anOrderingMode relativeTo:(
CPView)anotherView
508 var index = anotherView ? [_subviews indexOfObjectIdenticalTo:anotherView] :
CPNotFound;
512 index = (anOrderingMode ===
CPWindowAbove) ? [_subviews count] : 0;
518 [
self _insertSubview:aSubview atIndex:index];
522 - (void)_insertSubview:(
CPView)aSubview atIndex:(int)anIndex
524 if (aSubview ===
self)
527 if (!aSubview._superview && _subviews.indexOf(aSubview) !==
CPNotFound)
535 var count = _subviews.length,
539 [[
self window] _dirtyKeyViewLoop];
542 if (aSubview._superview ==
self)
544 var index = [_subviews indexOfObjectIdenticalTo:aSubview];
547 if (index === anIndex || index === count - 1 && anIndex === count)
550 [_subviews removeObjectAtIndex:index];
553 CPDOMDisplayServerRemoveChild(_DOMElement, aSubview._DOMElement);
566 lastWindow = [superview window];
569 [aSubview _removeFromSuperview];
572 aSubview._superview =
self;
575 if (anIndex ===
CPNotFound || anIndex >= count)
577 _subviews.push(aSubview);
581 CPDOMDisplayServerAppendChild(_DOMElement, aSubview._DOMElement);
586 _subviews.splice(anIndex, 0, aSubview);
590 CPDOMDisplayServerInsertBefore(_DOMElement, aSubview._DOMElement, _subviews[anIndex + 1]._DOMElement);
594 [aSubview setNextResponder:self];
595 [aSubview _scaleSizeUnitSquareToSize:[
self _hierarchyScaleSize]];
600 [aSubview _notifyViewDidHide];
606 [aSubview _setWindow:_window];
608 if (!_window && lastWindow)
609 [aSubview _setWindow:nil];
616 [aSubview _notifyViewDidBecomeFirstResponder];
618 [aSubview _notifyViewDidResignFirstResponder];
621 [aSubview _notifyWindowDidBecomeKey];
623 [aSubview _notifyWindowDidResignKey];
646 [
self _removeFromSuperview];
650 [
self _setWindow:nil];
653 - (void)_removeFromSuperview
659 [[
self window] _dirtyKeyViewLoop];
661 [_superview willRemoveSubview:self];
663 [_superview._subviews removeObjectIdenticalTo:self];
666 CPDOMDisplayServerRemoveChild(_superview._DOMElement, _DOMElement);
672 [
self _notifyViewDidUnhide];
674 [
self _notifyWindowDidResignKey];
675 [
self _notifyViewDidResignFirstResponder];
687 if (aSubview._superview !==
self || aSubview === aView)
690 var index = [_subviews indexOfObjectIdenticalTo:aSubview];
692 [
self _insertSubview:aView atIndex:index];
697 - (void)setSubviews:(CPArray)newSubviews
700 [
CPException raise:CPInvalidArgumentException
reason:"newSubviews cannot be nil in -[CPView setSubviews:]"];
703 if ([_subviews
isEqual:newSubviews])
707 if ([_subviews count] === 0)
710 count = [newSubviews count];
712 for (; index < count; ++index)
713 [
self addSubview:newSubviews[index]];
719 if ([newSubviews count] === 0)
721 var count = [_subviews count];
724 [_subviews[count] removeFromSuperview];
730 var removedSubviews = [
CPMutableSet setWithArray:_subviews];
732 [removedSubviews removeObjectsInArray:newSubviews];
733 [removedSubviews makeObjectsPerformSelector:@selector(removeFromSuperview)];
736 var addedSubviews = [
CPMutableSet setWithArray:newSubviews];
738 [addedSubviews removeObjectsInArray:_subviews];
740 var addedSubview = nil,
741 addedSubviewEnumerator = [addedSubviews objectEnumerator];
743 while ((addedSubview = [addedSubviewEnumerator nextObject]) !== nil)
747 if ([_subviews
isEqual:newSubviews])
750 _subviews = [newSubviews copy];
754 count = [_subviews count];
756 for (; index < count; ++index)
758 var subview = _subviews[index];
760 CPDOMDisplayServerRemoveChild(_DOMElement, subview._DOMElement);
761 CPDOMDisplayServerAppendChild(_DOMElement, subview._DOMElement);
767 - (void)_setWindow:(
CPWindow)aWindow
769 [[
self window] _dirtyKeyViewLoop];
772 if ([_window firstResponder] ===
self && _window != aWindow)
773 [_window makeFirstResponder:nil];
780 if (_registeredDraggedTypes)
782 [_window _noteUnregisteredDraggedTypes:_registeredDraggedTypes];
783 [aWindow _noteRegisteredDraggedTypes:_registeredDraggedTypes];
787 if (_window && (_trackingAreas.length > 0))
788 [_window _removeTrackingAreaView:
self];
796 if (_trackingAreas.length > 0)
799 [_window _addTrackingAreaView:self];
800 owners = [
self _calcTrackingAreaOwners];
807 [
self _updateTrackingAreasForOwners:owners];
810 var count = [_subviews count];
813 [_subviews[count] _setWindow:aWindow];
815 if ([_window isKeyWindow])
822 [
self _manageToolTipInstallation];
824 [[
self window] _dirtyKeyViewLoop];
864 - (void)viewWillMoveToSuperview:(
CPView)aView
866 _isSuperviewAClipView = [aView isKindOfClass:[
CPClipView class]];
868 [
self _removeObservers];
871 [
self _addObservers];
890 - (void)_removeObservers
895 var count = [_subviews count];
898 [_subviews[count] _removeObservers];
903 - (void)_addObservers
908 var count = [_subviews count];
911 [_subviews[count] _addObservers];
924 while (view && ![view isKindOfClass:[_CPMenuItemView
class]])
925 view = [view superview];
928 return view._menuItem;
940 - (void)setTag:(CPInteger)aTag
952 if ([
self tag] == aTag)
956 count = _subviews.length;
958 for (; index < count; ++index)
960 var view = [_subviews[index] viewWithTag:aTag];
985 - (void)setFrame:(CGRect)aFrame
987 if (CGRectEqualToRect(_frame, aFrame))
990 _inhibitFrameAndBoundsChangedNotifications = YES;
995 _inhibitFrameAndBoundsChangedNotifications = NO;
997 if (_postsFrameChangedNotifications)
998 [CachedNotificationCenter postNotificationName:CPViewFrameDidChangeNotification object:self];
1000 if (_isSuperviewAClipView)
1003 if (!_inhibitUpdateTrackingAreas)
1004 [
self _updateTrackingAreas];
1013 return CGRectMakeCopy(_frame);
1018 return CGPointMakeCopy(_frame.origin);
1023 return CGSizeMakeCopy(_frame.size);
1033 - (void)setCenter:(CGPoint)aPoint
1035 [
self setFrameOrigin:CGPointMake(aPoint.x - _frame.size.width / 2.0, aPoint.y - _frame.size.height / 2.0)];
1044 return CGPointMake(_frame.size.width / 2.0 + _frame.origin.x, _frame.size.height / 2.0 + _frame.origin.y);
1054 - (void)setFrameOrigin:(CGPoint)aPoint
1056 var origin = _frame.origin;
1058 if (!aPoint || CGPointEqualToPoint(origin, aPoint))
1061 origin.x = aPoint.x;
1062 origin.y = aPoint.y;
1064 if (_postsFrameChangedNotifications && !_inhibitFrameAndBoundsChangedNotifications)
1065 [CachedNotificationCenter postNotificationName:CPViewFrameDidChangeNotification object:self];
1067 if (_isSuperviewAClipView && !_inhibitFrameAndBoundsChangedNotifications)
1071 var transform = _superview ? _superview._boundsTransform : NULL;
1073 CPDOMDisplayServerSetStyleLeftTop(_DOMElement, transform, origin.x, origin.y);
1076 if (!_inhibitUpdateTrackingAreas && !_inhibitFrameAndBoundsChangedNotifications)
1077 [
self _updateTrackingAreas];
1086 - (void)setFrameSize:(CGSize)aSize
1088 var size = _frame.size;
1090 if (!aSize || CGSizeEqualToSize(size, aSize))
1093 var oldSize = CGSizeMakeCopy(size);
1095 size.width = aSize.width;
1096 size.height = aSize.height;
1100 _bounds.size.width = aSize.width * 1 / _scaleSize.width;
1101 _bounds.size.height = aSize.height * 1 / _scaleSize.height;
1105 [_layer _owningViewBoundsChanged];
1107 if (_autoresizesSubviews)
1114 [
self _setDisplayServerSetStyleSize:size];
1116 if (_backgroundType !== BackgroundTrivialColor)
1118 if (_backgroundType === BackgroundTransparentColor)
1120 CPDOMDisplayServerSetStyleSize(_DOMImageParts[0], size.width, size.height);
1124 var images = [[_backgroundColor patternImage] imageSlices],
1128 if (_backgroundType === BackgroundVerticalThreePartImage)
1130 var top = _DOMImageSizes[0] ? _DOMImageSizes[0].height : 0,
1131 bottom = _DOMImageSizes[2] ? _DOMImageSizes[2].height : 0;
1136 CPDOMDisplayServerSetStyleBackgroundSize(_DOMImageParts[partIndex],
frameSize.width +
"px", top +
"px");
1137 CPDOMDisplayServerSetStyleSize(_DOMImageParts[partIndex], size.width, top);
1140 if (_DOMImageSizes[1])
1142 var height =
frameSize.height - top - bottom;
1144 CPDOMDisplayServerSetStyleBackgroundSize(_DOMImageParts[partIndex],
frameSize.width +
"px", height +
"px");
1145 CPDOMDisplayServerSetStyleSize(_DOMImageParts[partIndex], size.width, size.height - top - bottom);
1150 CPDOMDisplayServerSetStyleBackgroundSize(_DOMImageParts[partIndex],
frameSize.width +
"px", bottom +
"px");
1151 CPDOMDisplayServerSetStyleSize(_DOMImageParts[partIndex], size.width, bottom);
1154 else if (_backgroundType === BackgroundHorizontalThreePartImage)
1156 var left = _DOMImageSizes[0] ? _DOMImageSizes[0].width : 0,
1157 right = _DOMImageSizes[2] ? _DOMImageSizes[2].width : 0;
1162 CPDOMDisplayServerSetStyleBackgroundSize(_DOMImageParts[partIndex], left +
"px",
frameSize.height +
"px");
1163 CPDOMDisplayServerSetStyleSize(_DOMImageParts[partIndex], left, size.height);
1166 if (_DOMImageSizes[1])
1170 CPDOMDisplayServerSetStyleBackgroundSize(_DOMImageParts[partIndex], width +
"px",
frameSize.height +
"px");
1171 CPDOMDisplayServerSetStyleSize(_DOMImageParts[partIndex], size.width - left - right, size.height);
1176 CPDOMDisplayServerSetStyleBackgroundSize(_DOMImageParts[partIndex], right +
"px",
frameSize.height +
"px");
1177 CPDOMDisplayServerSetStyleSize(_DOMImageParts[partIndex], right, size.height);
1180 else if (_backgroundType === BackgroundNinePartImage)
1182 var left = _DOMImageSizes[0] ? _DOMImageSizes[0].width : 0,
1183 right = _DOMImageSizes[2] ? _DOMImageSizes[2].width : 0,
1184 top = _DOMImageSizes[0] ? _DOMImageSizes[0].height : 0,
1185 bottom = _DOMImageSizes[6] ? _DOMImageSizes[6].height : 0,
1186 width = size.width - left - right,
1187 height = size.height - top - bottom;
1189 if (_DOMImageSizes[0])
1191 if (_DOMImageSizes[1])
1193 CPDOMDisplayServerSetStyleSize(_DOMImageParts[partIndex],
width, top);
1196 if (_DOMImageSizes[2])
1198 if (_DOMImageSizes[3])
1200 CPDOMDisplayServerSetStyleSize(_DOMImageParts[partIndex], _DOMImageSizes[3].
width, height);
1203 if (_DOMImageSizes[4])
1205 CPDOMDisplayServerSetStyleSize(_DOMImageParts[partIndex],
width, height);
1208 if (_DOMImageSizes[5])
1210 CPDOMDisplayServerSetStyleSize(_DOMImageParts[partIndex], _DOMImageSizes[5].
width, height);
1213 if (_DOMImageSizes[6])
1215 if (_DOMImageSizes[7])
1217 CPDOMDisplayServerSetStyleSize(_DOMImageParts[partIndex],
width, _DOMImageSizes[7].height);
1224 if (_postsFrameChangedNotifications && !_inhibitFrameAndBoundsChangedNotifications)
1225 [CachedNotificationCenter postNotificationName:CPViewFrameDidChangeNotification object:self];
1227 if (_isSuperviewAClipView && !_inhibitFrameAndBoundsChangedNotifications)
1230 if (!_inhibitUpdateTrackingAreas && !_inhibitFrameAndBoundsChangedNotifications)
1231 [
self _updateTrackingAreas];
1239 - (void)_setDisplayServerSetStyleSize:(CGSize)aSize
1244 CPDOMDisplayServerSetStyleSize(_DOMElement, aSize.width * 1 / scale.width, aSize.height * 1 / scale.height);
1246 if (_DOMContentsElement)
1248 CPDOMDisplayServerSetSize(_DOMContentsElement, aSize.width * _highDPIRatio * 1 / scale.width, aSize.height * _highDPIRatio * 1 / scale.height);
1249 CPDOMDisplayServerSetStyleSize(_DOMContentsElement, aSize.width * 1 / scale.width, aSize.height * 1 / scale.height);
1251 _needToSetTransformMatrix = YES;
1261 - (void)setBounds:(CGRect)bounds
1263 if (CGRectEqualToRect(_bounds,
bounds))
1266 _inhibitFrameAndBoundsChangedNotifications = YES;
1271 _inhibitFrameAndBoundsChangedNotifications = NO;
1273 if (_postsBoundsChangedNotifications)
1274 [CachedNotificationCenter postNotificationName:CPViewBoundsDidChangeNotification object:self];
1276 if (_isSuperviewAClipView)
1279 if (!_inhibitUpdateTrackingAreas)
1280 [
self _updateTrackingAreas];
1289 return CGRectMakeCopy(_bounds);
1294 return CGPointMakeCopy(_bounds.origin);
1299 return CGSizeMakeCopy(_bounds.size);
1308 - (void)setBoundsOrigin:(CGPoint)aPoint
1310 var origin = _bounds.origin;
1312 if (CGPointEqualToPoint(origin, aPoint))
1315 origin.x = aPoint.x;
1316 origin.y = aPoint.y;
1318 if (origin.x != 0 || origin.y != 0)
1325 _boundsTransform = nil;
1326 _inverseBoundsTransform = nil;
1330 var index = _subviews.length;
1334 var view = _subviews[index],
1335 origin = view._frame.origin;
1337 CPDOMDisplayServerSetStyleLeftTop(view._DOMElement, _boundsTransform, origin.x, origin.y);
1341 if (_postsBoundsChangedNotifications && !_inhibitFrameAndBoundsChangedNotifications)
1342 [CachedNotificationCenter postNotificationName:CPViewBoundsDidChangeNotification object:self];
1344 if (_isSuperviewAClipView && !_inhibitFrameAndBoundsChangedNotifications)
1347 if (!_inhibitUpdateTrackingAreas && !_inhibitFrameAndBoundsChangedNotifications)
1348 [
self _updateTrackingAreas];
1357 - (void)setBoundsSize:(CGSize)aSize
1359 var size = _bounds.size;
1361 if (CGSizeEqualToSize(size, aSize))
1366 if (!CGSizeEqualToSize(size,
frameSize))
1368 var origin = _bounds.origin;
1370 origin.x /= size.width /
frameSize.width;
1371 origin.y /= size.height /
frameSize.height;
1374 size.width = aSize.width;
1375 size.height = aSize.height;
1377 if (!CGSizeEqualToSize(size,
frameSize))
1379 var origin = _bounds.origin;
1381 origin.x *= size.width /
frameSize.width;
1382 origin.y *= size.height /
frameSize.height;
1385 if (_postsBoundsChangedNotifications && !_inhibitFrameAndBoundsChangedNotifications)
1386 [CachedNotificationCenter postNotificationName:CPViewBoundsDidChangeNotification object:self];
1388 if (_isSuperviewAClipView && !_inhibitFrameAndBoundsChangedNotifications)
1391 if (!_inhibitUpdateTrackingAreas && !_inhibitFrameAndBoundsChangedNotifications)
1392 [
self _updateTrackingAreas];
1400 - (void)resizeWithOldSuperviewSize:(CGSize)aSize
1407 var
frame = _superview._frame,
1408 newFrame = CGRectMakeCopy(_frame),
1409 dX =
frame.size.width - aSize.width,
1410 dY =
frame.size.height - aSize.height,
1415 (mask &
CPViewMaxXMargin ? aSize.width - _frame.size.width - _frame.origin.x : 0),
1418 (mask &
CPViewMaxYMargin ? aSize.height - _frame.size.height - _frame.origin.y : 0);
1421 newFrame.origin.x += dX * (baseX > 0 ? _frame.origin.x / baseX : evenFractionX);
1424 newFrame.size.width += dX * (baseX > 0 ? _frame.size.width / baseX : evenFractionX);
1427 newFrame.origin.y += dY * (baseY > 0 ? _frame.origin.y / baseY : evenFractionY);
1430 newFrame.size.height += dY * (baseY > 0 ? _frame.size.height / baseY : evenFractionY);
1439 - (void)resizeSubviewsWithOldSize:(CGSize)aSize
1441 var count = _subviews.length;
1444 [_subviews[count] resizeWithOldSuperviewSize:aSize];
1454 - (void)setAutoresizesSubviews:(BOOL)aFlag
1456 _autoresizesSubviews = !!aFlag;
1465 return _autoresizesSubviews;
1472 - (void)setAutoresizingMask:(
unsigned)aMask
1474 _autoresizingMask = aMask;
1482 return _autoresizingMask;
1502 _fullScreenModeState = _CPViewFullScreenModeStateMake(
self);
1506 [fullScreenWindow setLevel:CPScreenSaverWindowLevel];
1507 [fullScreenWindow setAutoresizingMask:CPViewWidthSizable | CPViewHeightSizable];
1509 var contentView = [fullScreenWindow contentView];
1512 [contentView addSubview:self];
1515 [
self setFrame:CGRectMakeCopy([contentView bounds])];
1517 [fullScreenWindow makeKeyAndOrderFront:self];
1519 [fullScreenWindow makeFirstResponder:self];
1521 _isInFullScreenMode = YES;
1540 if (!_isInFullScreenMode)
1543 _isInFullScreenMode = NO;
1545 [
self setFrame:_fullScreenModeState.frame];
1547 [_fullScreenModeState.superview _insertSubview:self atIndex:_fullScreenModeState.index];
1557 return _isInFullScreenMode;
1564 - (void)setHidden:(BOOL)aFlag
1568 if (_isHidden === aFlag)
1576 _DOMElement.style.display = _isHidden ?
"none" :
"block";
1581 var view = [_window firstResponder];
1583 if ([view isKindOfClass:[
CPView class]])
1596 [
self _notifyViewDidHide];
1601 [
self _notifyViewDidUnhide];
1605 - (void)_notifyViewDidHide
1609 var count = [_subviews count];
1612 [_subviews[count] _notifyViewDidHide];
1615 - (void)_notifyViewDidUnhide
1619 var count = [_subviews count];
1622 [_subviews[count] _notifyViewDidUnhide];
1633 - (void)setClipsToBounds:(BOOL)shouldClip
1635 if (_clipsToBounds === shouldClip)
1638 _clipsToBounds = shouldClip;
1641 _DOMElement.style.overflow = _clipsToBounds ?
"hidden" :
"visible";
1647 return _clipsToBounds;
1655 - (void)setAlphaValue:(
float)anAlphaValue
1657 if (_opacity == anAlphaValue)
1660 _opacity = anAlphaValue;
1666 if (anAlphaValue === 1.0)
1667 try { _DOMElement.style.removeAttribute(
"filter") }
catch (anException) { }
1669 _DOMElement.style.filter =
"alpha(opacity=" + anAlphaValue * 100 +
")";
1672 _DOMElement.style.opacity = anAlphaValue;
1695 view = [view superview];
1697 return view !== nil;
1759 - (void)setHitTests:(BOOL)shouldHitTest
1761 _hitTests = !!shouldHitTest;
1771 if (_isHidden || !_hitTests)
1775 sizeScale = [
self _hierarchyScaleSize];
1782 if (!CGRectContainsPoint(
frame, aPoint))
1786 i = _subviews.length,
1787 adjustedPoint = CGPointMake(aPoint.x - CGRectGetMinX(
frame), aPoint.y - CGRectGetMinY(
frame));
1789 if (_inverseBoundsTransform)
1795 affineTransform.tx *= [_superview _hierarchyScaleSize].width;
1796 affineTransform.ty *= [_superview _hierarchyScaleSize].height;
1800 affineTransform.tx *= sizeScale.width;
1801 affineTransform.ty *= sizeScale.height;
1809 if (view = [_subviews[i] hitTest:adjustedPoint])
1835 [
super mouseDown:anEvent];
1844 else if ([[
self nextResponder] isKindOfClass:
CPView])
1845 [
super rightMouseDown:anEvent];
1852 return [
self menu] || [[
self class] defaultMenu];
1861 if (_backgroundColor == aColor)
1864 if (aColor == [
CPNull null])
1867 _backgroundColor = aColor;
1870 var patternImage = [_backgroundColor patternImage],
1871 colorExists = _backgroundColor && ([_backgroundColor patternImage] || [_backgroundColor alphaComponent] > 0.0),
1872 colorHasAlpha = colorExists && [_backgroundColor alphaComponent] < 1.0,
1874 colorNeedsDOMElement = colorHasAlpha && !supportsRGBA,
1878 if ([patternImage isThreePartImage])
1880 _backgroundType = [patternImage isVertical] ? BackgroundVerticalThreePartImage : BackgroundHorizontalThreePartImage;
1883 else if ([patternImage isNinePartImage])
1885 _backgroundType = BackgroundNinePartImage;
1890 _backgroundType = colorNeedsDOMElement ? BackgroundTransparentColor : BackgroundTrivialColor;
1891 amount = (colorNeedsDOMElement ? 1 : 0) - _DOMImageParts.length;
1895 if (_backgroundType === BackgroundVerticalThreePartImage || _backgroundType === BackgroundHorizontalThreePartImage || _backgroundType === BackgroundNinePartImage)
1897 slices = [patternImage imageSlices];
1900 amount = MIN(amount, slices.length);
1902 for (var i = 0, count = slices.length; i < count; i++)
1904 var image = slices[i],
1905 size = [image size];
1907 if (!size || (size.width == 0 && size.height == 0))
1910 _DOMImageSizes[i] = size;
1918 amount -= _DOMImageParts.length;
1926 var DOMElement = DOMElementPrototype.cloneNode(
false);
1928 DOMElement.style.zIndex = -1000;
1930 _DOMImageParts.push(DOMElement);
1931 _DOMElement.appendChild(DOMElement);
1938 _DOMElement.removeChild(_DOMImageParts.pop());
1941 if (_backgroundType === BackgroundTrivialColor || _backgroundType === BackgroundTransparentColor)
1943 var colorCSS = colorExists ? [_backgroundColor cssString] :
"";
1945 if (colorNeedsDOMElement)
1947 _DOMElement.style.background =
"";
1948 _DOMImageParts[0].style.background = [_backgroundColor cssString];
1951 CPDOMDisplayServerSetStyleBackgroundSize(_DOMImageParts[0], [patternImage size].
width +
"px", [patternImage size].height +
"px");
1954 _DOMImageParts[0].style.filter =
"alpha(opacity=" + [_backgroundColor alphaComponent] * 100 +
")";
1956 _DOMImageParts[0].style.opacity = [_backgroundColor alphaComponent];
1958 var size = [
self bounds].size;
1959 CPDOMDisplayServerSetStyleSize(_DOMImageParts[0], size.width, size.height);
1962 _DOMElement.style.background = colorCSS;
1965 CPDOMDisplayServerSetStyleBackgroundSize(_DOMElement, [patternImage size].
width +
"px", [patternImage size].height +
"px");
1972 for (var i = 0; i < slices.length; i++)
1974 var size = _DOMImageSizes[i];
1979 var image = slices[i];
1984 CPDOMDisplayServerSetStyleSize(_DOMImageParts[partIndex], size.width, size.height);
1986 _DOMImageParts[partIndex].style.background =
"url(\"" + [image filename] +
"\")";
1991 try { _DOMImageParts[partIndex].style.removeAttribute(
"filter") }
catch (anException) { }
1993 _DOMImageParts[partIndex].style.opacity = 1.0;
1999 if (_backgroundType == BackgroundNinePartImage)
2001 var left = _DOMImageSizes[0] ? _DOMImageSizes[0].width : 0,
2002 right = _DOMImageSizes[2] ? _DOMImageSizes[2].width : 0,
2003 top = _DOMImageSizes[0] ? _DOMImageSizes[0].height : 0,
2004 bottom = _DOMImageSizes[6] ? _DOMImageSizes[6].height : 0,
2005 width = frameSize.width - left - right,
2006 height = frameSize.height - top - bottom;
2010 if (_DOMImageSizes[0])
2012 CPDOMDisplayServerSetStyleLeftTop(_DOMImageParts[partIndex], NULL, 0.0, 0.0);
2015 if (_DOMImageSizes[1])
2017 CPDOMDisplayServerSetStyleLeftTop(_DOMImageParts[partIndex], NULL, left, 0.0);
2018 CPDOMDisplayServerSetStyleSize(_DOMImageParts[partIndex],
width, _DOMImageSizes[1].height);
2021 if (_DOMImageSizes[2])
2023 CPDOMDisplayServerSetStyleRightTop(_DOMImageParts[partIndex], NULL, 0.0, 0.0);
2026 if (_DOMImageSizes[3])
2028 CPDOMDisplayServerSetStyleLeftTop(_DOMImageParts[partIndex], NULL, 0.0, top);
2029 CPDOMDisplayServerSetStyleSize(_DOMImageParts[partIndex], _DOMImageSizes[3].
width, height);
2032 if (_DOMImageSizes[4])
2034 CPDOMDisplayServerSetStyleLeftTop(_DOMImageParts[partIndex], NULL, left, top);
2035 CPDOMDisplayServerSetStyleSize(_DOMImageParts[partIndex],
width, height);
2038 if (_DOMImageSizes[5])
2040 CPDOMDisplayServerSetStyleRightTop(_DOMImageParts[partIndex], NULL, 0.0, top);
2041 CPDOMDisplayServerSetStyleSize(_DOMImageParts[partIndex], _DOMImageSizes[5].
width, height);
2044 if (_DOMImageSizes[6])
2046 CPDOMDisplayServerSetStyleLeftBottom(_DOMImageParts[partIndex], NULL, 0.0, 0.0);
2049 if (_DOMImageSizes[7])
2051 CPDOMDisplayServerSetStyleLeftBottom(_DOMImageParts[partIndex], NULL, left, 0.0);
2052 CPDOMDisplayServerSetStyleSize(_DOMImageParts[partIndex],
width, _DOMImageSizes[7].height);
2055 if (_DOMImageSizes[8])
2057 CPDOMDisplayServerSetStyleRightBottom(_DOMImageParts[partIndex], NULL, 0.0, 0.0);
2060 else if (_backgroundType == BackgroundVerticalThreePartImage)
2062 var top = _DOMImageSizes[0] ? _DOMImageSizes[0].height : 0,
2063 bottom = _DOMImageSizes[2] ? _DOMImageSizes[2].height : 0;
2070 CPDOMDisplayServerSetStyleBackgroundSize(_DOMImageParts[partIndex], frameSize.width +
"px", top +
"px");
2071 CPDOMDisplayServerSetStyleLeftTop(_DOMImageParts[partIndex], NULL, 0.0, 0.0);
2072 CPDOMDisplayServerSetStyleSize(_DOMImageParts[partIndex], frameSize.width, top);
2075 if (_DOMImageSizes[1])
2077 var height = frameSize.height - top - bottom;
2080 CPDOMDisplayServerSetStyleBackgroundSize(_DOMImageParts[partIndex], frameSize.width +
"px", height +
"px");
2081 CPDOMDisplayServerSetStyleLeftTop(_DOMImageParts[partIndex], NULL, 0.0, top);
2082 CPDOMDisplayServerSetStyleSize(_DOMImageParts[partIndex], frameSize.width, height);
2087 CPDOMDisplayServerSetStyleBackgroundSize(_DOMImageParts[partIndex], frameSize.width +
"px", bottom +
"px");
2088 CPDOMDisplayServerSetStyleLeftBottom(_DOMImageParts[partIndex], NULL, 0.0, 0.0);
2089 CPDOMDisplayServerSetStyleSize(_DOMImageParts[partIndex], frameSize.width, bottom);
2092 else if (_backgroundType == BackgroundHorizontalThreePartImage)
2094 var left = _DOMImageSizes[0] ? _DOMImageSizes[0].width : 0,
2095 right = _DOMImageSizes[2] ? _DOMImageSizes[2].width : 0;
2102 CPDOMDisplayServerSetStyleBackgroundSize(_DOMImageParts[partIndex], left +
"px", frameSize.height +
"px");
2103 CPDOMDisplayServerSetStyleLeftTop(_DOMImageParts[partIndex], NULL, 0.0, 0.0);
2104 CPDOMDisplayServerSetStyleSize(_DOMImageParts[partIndex], left, frameSize.height);
2107 if (_DOMImageSizes[1])
2109 var
width = (frameSize.width - left - right);
2111 CPDOMDisplayServerSetStyleBackgroundSize(_DOMImageParts[partIndex], width +
"px", frameSize.height +
"px");
2112 CPDOMDisplayServerSetStyleLeftTop(_DOMImageParts[partIndex], NULL, left, 0.0);
2113 CPDOMDisplayServerSetStyleSize(_DOMImageParts[partIndex], width, frameSize.height);
2118 CPDOMDisplayServerSetStyleBackgroundSize(_DOMImageParts[partIndex], right +
"px", frameSize.height +
"px");
2119 CPDOMDisplayServerSetStyleRightTop(_DOMImageParts[partIndex], NULL, 0.0, 0.0);
2120 CPDOMDisplayServerSetStyleSize(_DOMImageParts[partIndex], right, frameSize.height);
2132 return _backgroundColor;
2142 - (CGPoint)convertPoint:(CGPoint)aPoint fromView:(
CPView)aView
2155 - (CGPoint)convertPointFromBase:(CGPoint)aPoint
2166 - (CGPoint)convertPoint:(CGPoint)aPoint toView:(
CPView)aView
2180 - (CGPoint)convertPointToBase:(CGPoint)aPoint
2191 - (CGSize)convertSize:(CGSize)aSize fromView:(
CPView)aView
2205 - (CGSize)convertSize:(CGSize)aSize toView:(
CPView)aView
2219 - (CGRect)convertRect:(CGRect)aRect fromView:(
CPView)aView
2232 - (CGRect)convertRectFromBase:(CGRect)aRect
2243 - (CGRect)convertRect:(CGRect)aRect toView:(
CPView)aView
2256 - (CGRect)convertRectToBase:(CGRect)aRect
2273 - (void)setPostsFrameChangedNotifications:(BOOL)shouldPostFrameChangedNotifications
2275 shouldPostFrameChangedNotifications = !!shouldPostFrameChangedNotifications;
2277 if (_postsFrameChangedNotifications === shouldPostFrameChangedNotifications)
2280 _postsFrameChangedNotifications = shouldPostFrameChangedNotifications;
2288 return _postsFrameChangedNotifications;
2303 - (void)setPostsBoundsChangedNotifications:(BOOL)shouldPostBoundsChangedNotifications
2305 shouldPostBoundsChangedNotifications = !!shouldPostBoundsChangedNotifications;
2307 if (_postsBoundsChangedNotifications === shouldPostBoundsChangedNotifications)
2310 _postsBoundsChangedNotifications = shouldPostBoundsChangedNotifications;
2320 return _postsBoundsChangedNotifications;
2333 - (void)dragImage:(
CPImage)anImage at:(CGPoint)aLocation offset:(CGSize)mouseOffset event:(
CPEvent)anEvent pasteboard:(
CPPasteboard)aPasteboard source:(
id)aSourceObject slideBack:(BOOL)slideBack
2335 [_window dragImage:anImage at:[
self convertPoint:aLocation
toView:nil] offset:mouseOffset event:anEvent pasteboard:aPasteboard source:aSourceObject slideBack:slideBack];
2348 - (void)dragView:(
CPView)aView at:(CGPoint)aLocation offset:(CGSize)mouseOffset event:(
CPEvent)anEvent pasteboard:(
CPPasteboard)aPasteboard source:(
id)aSourceObject slideBack:(BOOL)slideBack
2350 [_window dragView:aView at:[
self convertPoint:aLocation
toView:nil] offset:mouseOffset event:anEvent pasteboard:aPasteboard source:aSourceObject slideBack:slideBack];
2357 - (void)registerForDraggedTypes:(CPArray)pasteboardTypes
2359 if (!pasteboardTypes || ![pasteboardTypes count])
2362 var theWindow = [
self window];
2364 [theWindow _noteUnregisteredDraggedTypes:_registeredDraggedTypes];
2365 [_registeredDraggedTypes addObjectsFromArray:pasteboardTypes];
2366 [theWindow _noteRegisteredDraggedTypes:_registeredDraggedTypes];
2368 _registeredDraggedTypesArray = nil;
2377 if (!_registeredDraggedTypesArray)
2378 _registeredDraggedTypesArray = [_registeredDraggedTypes allObjects];
2380 return _registeredDraggedTypesArray;
2388 [[
self window] _noteUnregisteredDraggedTypes:_registeredDraggedTypes];
2390 _registeredDraggedTypes = [CPSet set];
2391 _registeredDraggedTypesArray = [];
2398 - (void)drawRect:(CGRect)aRect
2411 - (void)scaleUnitSquareToSize:(CGSize)aSize
2418 bounds.size.width *= _scaleSize.width;
2419 bounds.size.height *= _scaleSize.height;
2421 [
self willChangeValueForKey:@"scaleSize"];
2422 _scaleSize = CGSizeMakeCopy([
self scaleSize]);
2423 _scaleSize.height *= aSize.height;
2424 _scaleSize.width *= aSize.width;
2425 [
self didChangeValueForKey:@"scaleSize"];
2428 _hierarchyScaleSize = CGSizeMakeCopy([
self _hierarchyScaleSize]);
2429 _hierarchyScaleSize.height *= aSize.height;
2430 _hierarchyScaleSize.width *= aSize.width;
2437 [_subviews makeObjectsPerformSelector:@selector(_scaleSizeUnitSquareToSize:) withObject:aSize];
2444 - (void)_scaleSizeUnitSquareToSize:(CGSize)aSize
2446 _hierarchyScaleSize = CGSizeMakeCopy([_superview _hierarchyScaleSize]);
2450 _hierarchyScaleSize.width *= _scaleSize.width;
2451 _hierarchyScaleSize.height *= _scaleSize.height;
2454 [_subviews makeObjectsPerformSelector:@selector(_scaleSizeUnitSquareToSize:) withObject:aSize];
2460 - (CGSize)_hierarchyScaleSize
2462 return _hierarchyScaleSize || CGSizeMake(1.0, 1.0);
2468 - (void)_applyCSSScalingTranformations
2477 self._DOMElement.style[browserPropertyTransform] =
'scale(' + scale.width +
', ' + scale.height +
')';
2478 self._DOMElement.style[browserPropertyTransformOrigin] =
'0 0';
2480 [
self _setDisplayServerSetStyleSize:[
self frameSize]];
2494 [
self _applyCSSScalingTranformations];
2503 - (void)setNeedsDisplayInRect:(CGRect)aRect
2508 if (CGRectIsEmpty(aRect))
2511 if (_dirtyRect && !CGRectIsEmpty(_dirtyRect))
2512 _dirtyRect = CGRectUnion(aRect, _dirtyRect);
2514 _dirtyRect = CGRectMakeCopy(aRect);
2516 _CPDisplayServerAddDisplayObject(
self);
2521 return _dirtyRect && !CGRectIsEmpty(_dirtyRect);
2541 - (void)displayIfNeededInRect:(CGRect)aRect
2551 - (void)displayRect:(CGRect)aRect
2584 if (!_graphicsContext)
2589 var
width = CGRectGetWidth(_frame),
2590 height = CGRectGetHeight(_frame),
2591 devicePixelRatio =
window.devicePixelRatio || 1,
2596 _DOMContentsElement = graphicsPort.DOMElement;
2598 _DOMContentsElement.style.zIndex = -100;
2600 _DOMContentsElement.style.overflow =
"hidden";
2601 _DOMContentsElement.style.position =
"absolute";
2602 _DOMContentsElement.style.visibility =
"visible";
2604 CPDOMDisplayServerSetSize(_DOMContentsElement, width * _highDPIRatio, height * _highDPIRatio);
2606 CPDOMDisplayServerSetStyleLeftTop(_DOMContentsElement, NULL, 0.0, 0.0);
2607 CPDOMDisplayServerSetStyleSize(_DOMContentsElement, width, height);
2612 _DOMElement.style.webkitTransform =
'translateX(0)';
2614 CPDOMDisplayServerAppendChild(_DOMElement, _DOMContentsElement);
2617 _needToSetTransformMatrix = YES;
2621 if (_needToSetTransformMatrix && _highDPIRatio !== 1)
2622 [_graphicsContext graphicsPort].setTransform(_highDPIRatio, 0, 0 , _highDPIRatio, 0, 0);
2625 _needToSetTransformMatrix = NO;
2656 _CPDisplayServerAddLayoutObject(
self);
2661 return _needsLayout;
2696 [
self _recomputeAppearance];
2720 return CGRectIntersection([
self convertRect:[_superview
visibleRect] fromView:_superview], _bounds);
2730 while (superview && ![superview isKindOfClass:clipViewClass])
2731 superview = superview._superview;
2740 - (void)scrollPoint:(CGPoint)aPoint
2742 var clipView = [
self _enclosingClipView];
2755 - (BOOL)scrollRectToVisible:(CGRect)aRect
2758 aRect = CGRectIntersection(aRect, _bounds);
2761 if (CGRectIsEmpty(aRect))
2764 var enclosingClipView = [
self _enclosingClipView];
2767 if (!enclosingClipView)
2770 var documentView = [enclosingClipView documentView];
2777 var documentViewVisibleRect = [documentView visibleRect],
2781 if (CGRectContainsRect(documentViewVisibleRect, rectInDocumentView))
2784 var currentScrollPoint = documentViewVisibleRect.origin,
2785 scrollPoint = CGPointMakeCopy(currentScrollPoint),
2786 rectInDocumentViewMinX = CGRectGetMinX(rectInDocumentView),
2787 documentViewVisibleRectMinX = CGRectGetMinX(documentViewVisibleRect),
2788 doesItFitForWidth = documentViewVisibleRect.size.width >= rectInDocumentView.size.width;
2791 if (rectInDocumentViewMinX < documentViewVisibleRectMinX && doesItFitForWidth)
2793 scrollPoint.x = rectInDocumentViewMinX;
2794 else if (CGRectGetMaxX(rectInDocumentView) > CGRectGetMaxX(documentViewVisibleRect) && doesItFitForWidth)
2796 scrollPoint.x = CGRectGetMaxX(rectInDocumentView) - documentViewVisibleRect.size.width;
2797 else if (rectInDocumentViewMinX > documentViewVisibleRectMinX)
2799 scrollPoint.x = rectInDocumentViewMinX;
2800 else if (CGRectGetMaxX(rectInDocumentView) < CGRectGetMaxX(documentViewVisibleRect))
2802 scrollPoint.x = CGRectGetMaxX(rectInDocumentView) - documentViewVisibleRect.size.width;
2804 var rectInDocumentViewMinY = CGRectGetMinY(rectInDocumentView),
2805 documentViewVisibleRectMinY = CGRectGetMinY(documentViewVisibleRect),
2806 doesItFitForHeight = documentViewVisibleRect.size.height >= rectInDocumentView.size.height;
2808 if (rectInDocumentViewMinY < documentViewVisibleRectMinY && doesItFitForHeight)
2810 scrollPoint.y = rectInDocumentViewMinY;
2811 else if (CGRectGetMaxY(rectInDocumentView) > CGRectGetMaxY(documentViewVisibleRect) && doesItFitForHeight)
2813 scrollPoint.y = CGRectGetMaxY(rectInDocumentView) - documentViewVisibleRect.size.height;
2814 else if (rectInDocumentViewMinY > documentViewVisibleRectMinY)
2816 scrollPoint.y = rectInDocumentViewMinY;
2817 else if (CGRectGetMaxY(rectInDocumentView) < CGRectGetMaxY(documentViewVisibleRect))
2819 scrollPoint.y = CGRectGetMaxY(rectInDocumentView) - documentViewVisibleRect.size.height;
2823 if (CGPointEqualToPoint(scrollPoint, currentScrollPoint))
2826 [enclosingClipView scrollToPoint:scrollPoint];
2845 - (CGRect)adjustScroll:(CGRect)proposedVisibleRect
2847 return proposedVisibleRect;
2853 - (void)scrollRect:(CGRect)aRect by:(
float)anAmount
2878 - (void)scrollClipView:(
CPClipView)aClipView toPoint:(CGPoint)aPoint
2897 return _inLiveResize;
2911 _inLiveResize = YES;
2949 var count = [_subviews count];
2953 if ([_subviews[count] performKeyEquivalent:anEvent])
2966 return _nextKeyView;
2972 resultUID = [result UID],
2973 unsuitableResults = {};
2977 unsuitableResults[resultUID] = 1;
2978 result = [result nextKeyView];
2980 resultUID = [result UID];
2983 if (unsuitableResults[resultUID])
2992 return _previousKeyView;
2998 firstResult = result;
3002 result = [result previousKeyView];
3005 if (result === firstResult)
3012 - (void)_setPreviousKeyView:(
CPView)previous
3016 var previousWindow = [previous window];
3018 if (!previousWindow || previousWindow === _window)
3020 _previousKeyView = previous;
3025 _previousKeyView = nil;
3032 var nextWindow = [next
window];
3034 if (!nextWindow || nextWindow === _window)
3036 _nextKeyView = next;
3037 [_nextKeyView _setPreviousKeyView:self];
3054 if (_layer == aLayer)
3059 _layer._owningView = nil;
3061 _DOMElement.removeChild(_layer._DOMElement);
3069 var
bounds = CGRectMakeCopy([
self bounds]);
3071 [_layer _setOwningView:self];
3074 _layer._DOMElement.style.zIndex = 100;
3076 _DOMElement.appendChild(_layer._DOMElement);
3093 - (void)setWantsLayer:(BOOL)aFlag
3095 _wantsLayer = !!aFlag;
3117 - (void)setScaleSize:(CGSize)aSize
3119 if (CGSizeEqualToSize(_scaleSize, aSize))
3122 var size = CGSizeMakeZero(),
3123 scale = CGSizeMakeCopy([
self scaleSize]);
3125 size.height = aSize.height / scale.height;
3126 size.width = aSize.width / scale.width;
3138 return _scaleSize || CGSizeMake(1.0, 1.0);
3146 #pragma mark Override 3150 var shouldLayout = [
super setThemeState:aState];
3163 var shouldLayout = [
super unsetThemeState:aState];
3176 [
super setThemeClass:theClass];
3183 #pragma mark First responder 3187 var r = [
super becomeFirstResponder];
3190 [
self _notifyViewDidBecomeFirstResponder];
3195 - (void)_notifyViewDidBecomeFirstResponder
3199 var count = [_subviews count];
3202 [_subviews[count] _notifyViewDidBecomeFirstResponder];
3207 var r = [
super resignFirstResponder];
3210 [
self _notifyViewDidResignFirstResponder];
3215 - (void)_notifyViewDidResignFirstResponder
3219 var count = [_subviews count];
3222 [_subviews[count] _notifyViewDidResignFirstResponder];
3225 - (void)_notifyWindowDidBecomeKey
3229 var count = [_subviews count];
3232 [_subviews[count] _notifyWindowDidBecomeKey];
3235 - (void)_notifyWindowDidResignKey
3239 var count = [_subviews count];
3242 [_subviews[count] _notifyWindowDidResignKey];
3245 #pragma mark Theme Attributes 3247 - (void)_setThemeIncludingDescendants:(
CPTheme)aTheme
3249 [
self setTheme:aTheme];
3250 [[
self subviews] makeObjectsPerformSelector:@selector(_setThemeIncludingDescendants:) withObject:aTheme];
3255 if (!_themeAttributes)
3258 [
super objectDidChangeTheme];
3266 var currentValue = [
self currentValueForThemeAttribute:aName];
3268 [
super setValue:aValue forThemeAttribute:aName inState:aState];
3270 if ([
self currentValueForThemeAttribute:aName] === currentValue)
3277 - (void)setValue:(
id)aValue forThemeAttribute:(
CPString)aName
3279 var currentValue = [
self currentValueForThemeAttribute:aName];
3281 [
super setValue:aValue forThemeAttribute:aName ];
3283 if ([
self currentValueForThemeAttribute:aName] === currentValue)
3295 - (CGRect)rectForEphemeralSubviewNamed:(
CPString)aViewName
3297 return CGRectMakeZero();
3301 positioned:(CPWindowOrderingMode)anOrderingMode
3302 relativeToEphemeralSubviewNamed:(
CPString)relativeToViewName
3304 if (!_ephemeralSubviewsForNames)
3306 _ephemeralSubviewsForNames = {};
3307 _ephemeralSubviews = [CPSet set];
3314 if (!_ephemeralSubviewsForNames[aViewName])
3318 [_ephemeralSubviews addObject:_ephemeralSubviewsForNames[aViewName]];
3320 if (_ephemeralSubviewsForNames[aViewName])
3324 if (_ephemeralSubviewsForNames[aViewName])
3325 [_ephemeralSubviewsForNames[aViewName] setFrame:frame];
3327 else if (_ephemeralSubviewsForNames[aViewName])
3329 [_ephemeralSubviewsForNames[aViewName] removeFromSuperview];
3331 [_ephemeralSubviews removeObject:_ephemeralSubviewsForNames[aViewName]];
3332 delete _ephemeralSubviewsForNames[aViewName];
3335 return _ephemeralSubviewsForNames[aViewName];
3340 if (!_ephemeralSubviewsForNames)
3343 return (_ephemeralSubviewsForNames[aViewName] || nil);
3358 return [_superview effectiveAppearance];
3363 if ([_appearance
isEqual:anAppearance])
3366 [
self willChangeValueForKey:@"appearance"];
3367 _appearance = anAppearance;
3368 [
self didChangeValueForKey:@"appearance"];
3375 - (void)_recomputeAppearance
3417 for (var i = 0, size = [_subviews count]; i < size; i++)
3419 [[_subviews objectAtIndex:i] _recomputeAppearance];
3437 if (!trackingArea || [_trackingAreas containsObjectIdenticalTo:trackingArea])
3440 if ([trackingArea view])
3441 [
CPException raise:CPInternalInconsistencyException
reason:"Tracking area has already been added to another view."];
3443 [_trackingAreas addObject:trackingArea];
3447 [_window _addTrackingArea:trackingArea];
3449 [trackingArea _updateWindowRect];
3458 if (![_trackingAreas containsObjectIdenticalTo:trackingArea])
3459 [
CPException raise:CPInternalInconsistencyException
reason:"Trying to remove unreferenced trackingArea"];
3461 [
self _removeTrackingArea:trackingArea];
3500 while (_trackingAreas.length > 0)
3501 [
self _removeTrackingArea:_trackingAreas[0]];
3509 [_window _removeTrackingArea:trackingArea];
3512 [_trackingAreas removeObjectIdenticalTo:trackingArea];
3515 - (void)_updateTrackingAreas
3517 _inhibitUpdateTrackingAreas = YES;
3519 [
self _recursivelyUpdateTrackingAreas];
3521 _inhibitUpdateTrackingAreas = NO;
3524 - (void)_recursivelyUpdateTrackingAreas
3526 [
self _updateTrackingAreasForOwners:[
self _calcTrackingAreaOwners]];
3528 for (var i = 0; i < _subviews.length; i++)
3529 [_subviews[i] _recursivelyUpdateTrackingAreas];
3532 - (CPArray)_calcTrackingAreaOwners
3540 for (var i = 0; i < _trackingAreas.length; i++)
3542 var trackingArea = _trackingAreas[i];
3545 [trackingArea _updateWindowRect];
3549 var owner = [trackingArea owner];
3551 if (![owners containsObjectIdenticalTo:owner])
3552 [owners addObject:owner];
3559 - (void)_updateTrackingAreasForOwners:(CPArray)owners
3561 for (var i = 0; i < owners.length; i++)
3603 _DOMElement = DOMElementPrototype.cloneNode(
false);
3604 AppKitTagDOMElement(
self, _DOMElement);
3608 _frame = [aCoder decodeRectForKey:CPViewFrameKey];
3609 _bounds = [aCoder decodeRectForKey:CPViewBoundsKey];
3611 self = [
super initWithCoder:aCoder];
3615 _trackingAreas = [aCoder decodeObjectForKey:CPViewTrackingAreasKey];
3617 if (!_trackingAreas)
3618 _trackingAreas = [];
3621 _tag = [aCoder containsValueForKey:CPViewTagKey] ? [aCoder decodeIntForKey:CPViewTagKey] : -1;
3622 _identifier = [aCoder decodeObjectForKey:CPReuseIdentifierKey];
3624 _window = [aCoder decodeObjectForKey:CPViewWindowKey];
3625 _superview = [aCoder decodeObjectForKey:CPViewSuperviewKey];
3631 var
subviews = [aCoder decodeObjectForKey:CPViewSubviewsKey] || [];
3633 for (var i = 0, count = [subviews count]; i < count; ++i)
3636 subviews[i]._superview = nil;
3641 _registeredDraggedTypes = [CPSet set];
3642 _registeredDraggedTypesArray = [];
3646 if (_autoresizingMask === nil)
3647 _autoresizingMask = [aCoder decodeIntForKey:CPViewAutoresizingMaskKey] ||
CPViewNotSizable;
3649 _autoresizesSubviews = ![aCoder containsValueForKey:CPViewAutoresizesSubviewsKey] || [aCoder decodeBoolForKey:CPViewAutoresizesSubviewsKey];
3651 _hitTests = ![aCoder containsValueForKey:CPViewHitTestsKey] || [aCoder decodeBoolForKey:CPViewHitTestsKey];
3653 _toolTip = [aCoder decodeObjectForKey:CPViewToolTipKey];
3656 [
self _installToolTipEventHandlers];
3658 _scaleSize = [aCoder containsValueForKey:CPViewScaleKey] ? [aCoder decodeSizeForKey:CPViewScaleKey] : CGSizeMake(1.0, 1.0);
3659 _hierarchyScaleSize = [aCoder containsValueForKey:CPViewSizeScaleKey] ? [aCoder decodeSizeForKey:CPViewSizeScaleKey] : CGSizeMake(1.0, 1.0);
3660 _isScaled = [aCoder containsValueForKey:CPViewIsScaledKey] ? [aCoder decodeBoolForKey:CPViewIsScaledKey] : NO;
3664 _DOMImageParts = [];
3665 _DOMImageSizes = [];
3667 CPDOMDisplayServerSetStyleLeftTop(_DOMElement, NULL, CGRectGetMinX(_frame), CGRectGetMinY(_frame));
3668 [
self _setDisplayServerSetStyleSize:_frame.size];
3671 count = _subviews.length;
3673 for (; index < count; ++index)
3675 CPDOMDisplayServerAppendChild(_DOMElement, _subviews[index]._DOMElement);
3680 [
self setHidden:[aCoder decodeBoolForKey:CPViewIsHiddenKey]];
3683 [
self setAlphaValue:[aCoder decodeIntForKey:CPViewOpacityKey]];
3688 [
self _setupViewFlags];
3689 [
self _decodeThemeObjectsWithCoder:aCoder];
3691 [
self setAppearance:[aCoder decodeObjectForKey:CPViewAppearanceKey]];
3706 [
super encodeWithCoder:aCoder];
3709 [aCoder encodeInt:_tag forKey:CPViewTagKey];
3711 [aCoder encodeRect:_frame forKey:CPViewFrameKey];
3712 [aCoder encodeRect:_bounds forKey:CPViewBoundsKey];
3715 if (_window !== nil)
3716 [aCoder encodeConditionalObject:_window forKey:CPViewWindowKey];
3718 var count = [_subviews count],
3719 encodedSubviews = _subviews;
3721 if (count > 0 && [_ephemeralSubviews count] > 0)
3723 encodedSubviews = [encodedSubviews copy];
3726 if ([_ephemeralSubviews containsObject:encodedSubviews[count]])
3727 encodedSubviews.splice(count, 1);
3730 if (encodedSubviews.length > 0)
3731 [aCoder encodeObject:encodedSubviews forKey:CPViewSubviewsKey];
3734 if (_superview !== nil)
3735 [aCoder encodeConditionalObject:_superview forKey:CPViewSuperviewKey];
3738 [aCoder encodeInt:_autoresizingMask forKey:CPViewAutoresizingMaskKey];
3740 if (!_autoresizesSubviews)
3741 [aCoder encodeBool:_autoresizesSubviews forKey:CPViewAutoresizesSubviewsKey];
3743 if (_backgroundColor !== nil)
3744 [aCoder encodeObject:_backgroundColor forKey:CPViewBackgroundColorKey];
3746 if (_hitTests !== YES)
3747 [aCoder encodeBool:_hitTests forKey:CPViewHitTestsKey];
3749 if (_opacity !== 1.0)
3750 [aCoder encodeFloat:_opacity forKey:CPViewOpacityKey];
3753 [aCoder encodeBool:_isHidden forKey:CPViewIsHiddenKey];
3756 [aCoder encodeObject:_toolTip forKey:CPViewToolTipKey];
3761 [aCoder encodeConditionalObject:nextKeyView forKey:CPViewNextKeyViewKey];
3766 [aCoder encodeConditionalObject:previousKeyView forKey:CPViewPreviousKeyViewKey];
3768 [
self _encodeThemeObjectsWithCoder:aCoder];
3771 [aCoder encodeObject:_identifier forKey:CPReuseIdentifierKey];
3773 [aCoder encodeSize:[
self scaleSize] forKey:CPViewScaleKey];
3774 [aCoder encodeSize:[
self _hierarchyScaleSize] forKey:CPViewSizeScaleKey];
3775 [aCoder encodeBool:_isScaled forKey:CPViewIsScaledKey];
3776 [aCoder encodeObject:_appearance forKey:CPViewAppearanceKey];
3777 [aCoder encodeObject:_trackingAreas forKey:CPViewTrackingAreasKey];
3782 var _CPViewFullScreenModeStateMake =
function(aView)
3786 return {
autoresizingMask:aView._autoresizingMask,
frame:CGRectMakeCopy(aView._frame), index:(superview ? [superview._subviews indexOfObjectIdenticalTo:aView] : 0), superview:superview };
3789 var _CPViewGetTransform =
function( fromView, toView)
3798 var view = fromView;
3803 while (view && view != toView)
3805 var
frame = view._frame;
3813 transform.tx += CGRectGetMinX(frame);
3814 transform.ty += CGRectGetMinY(frame);
3816 if (view._boundsTransform)
3829 view = view._superview;
3833 if (view === toView)
3837 else if (fromView && toView)
3839 fromWindow = [fromView window];
3840 toWindow = [toView window];
3842 if (fromWindow && toWindow && fromWindow !== toWindow)
3851 while (view && view != fromView)
3853 var
frame = CGRectMakeCopy(view._frame);
3858 transform2.a *= 1 / view._scaleSize.width;
3859 transform2.d *= 1 / view._scaleSize.height;
3862 transform2.tx += CGRectGetMinX(frame) * transform2.a;
3863 transform2.ty += CGRectGetMinY(frame) * transform2.d;
3865 if (view._boundsTransform)
3868 inverseBoundsTransform.tx -= view._inverseBoundsTransform.tx * transform2.a;
3869 inverseBoundsTransform.ty -= view._inverseBoundsTransform.ty * transform2.d;
3874 view = view._superview;
3877 transform2.tx = -transform2.tx;
3878 transform2.ty = -transform2.ty;
3880 if (view === fromView)
id initWithFrame:(CGRect aFrame)
Used to implement exception handling (creating & raising).
void viewDidMoveToSuperview()
BOOL postsBoundsChangedNotifications()
void addSubview:(CPView aSubview)
void drawRect:(CGRect aRect)
void setAppearance:(CPAppearance anAppearance)
BOOL setThemeState:(ThemeState aState)
CPView nextValidKeyView()
void scrollToPoint:(CGPoint aPoint)
An object representation of nil.
void setView:(CPView aValue)
BOOL autoscroll:(CPEvent anEvent)
function CPBrowserBackingStorePixelRatio(context)
var CPViewHasCustomLayoutSubviews
var CPViewPreviousKeyViewKey
void setFrame:(CGRect aFrame)
function CGContextRestoreGState(aContext)
void setCurrentContext:(CPGraphicsContext aGraphicsContext)
void raise:reason:(CPString aName, [reason] CPString aReason)
CPArray registeredDraggedTypes()
void removeFromSuperview()
void viewWillMoveToWindow:(CPWindow aWindow)
BOOL enterFullScreenMode:withOptions:(CPScreen aScreen, [withOptions] CPDictionary options)
BOOL postsFrameChangedNotifications()
CPColor backgroundColor()
var CPViewHasCustomDrawRect
void setNeedsDisplayInRect:(CGRect aRect)
CPNotificationCenter defaultCenter()
CPInvalidArgumentException
A mutable key-value pair collection.
CPScrollView enclosingScrollView()
BOOL isInFullScreenMode()
BOOL enterFullScreenMode()
function ThemeState(stateNames)
void displayRectIgnoringOpacity:inContext:(CGRect aRect, [inContext] CPGraphicsContext aGraphicsContext)
void setBoundsOrigin:(CGPoint aPoint)
void displayRect:(CGRect aRect)
void setNeedsLayout:(BOOL needLayout)
id initWithContentRect:styleMask:(CGRect aContentRect, [styleMask] unsigned aStyleMask)
void viewWillMoveToSuperview:(CPView aView)
BOOL resignFirstResponder()
var CPViewAutoresizingMaskKey
CPView previousValidKeyView()
CPView createEphemeralSubviewNamed:(CPString aViewName)
id initWithName:object:userInfo:(CPString aNotificationName, [object] id anObject, [userInfo] CPDictionary aUserInfo)
var CPViewTrackingAreasKey
An immutable string (collection of characters).
CGPoint convertPoint:fromView:(CGPoint aPoint, [fromView] CPView aView)
var CPViewBackgroundColorKey
void removeAllTrackingAreas()
CPSet keyPathsForValuesAffectingFrame()
void addSubview:positioned:relativeTo:(CPView aSubview, [positioned] CPWindowOrderingMode anOrderingMode, [relativeTo] CPView anotherView)
function CPFeatureIsCompatible(aFeature)
BOOL mouseDownCanMoveWindow()
var CachedNotificationCenter
CPSet keyPathsForValuesAffectingBounds()
CGRect convertRect:toView:(CGRect aRect, [toView] CPView aView)
CPView nextValidKeyView()
void viewDidMoveToWindow()
void setHidden:(BOOL aFlag)
void setAutoresizingMask:(unsigned aMask)
void exitFullScreenMode()
void setNeedsDisplay:(BOOL aFlag)
CPGraphicsContext graphicsContextWithGraphicsPort:flipped:(CGContext aContext, [flipped] BOOL aFlag)
void viewDidEndLiveResize()
CPMenu menuForEvent:(CPEvent anEvent)
CGPoint convertPoint:toView:(CGPoint aPoint, [toView] CPView aView)
CPViewBoundsDidChangeNotification
function CGContextClearRect(aContext, aRect)
A notification that can be posted to a CPNotificationCenter.
void setAlphaValue:(float anAlphaValue)
BOOL isHighDPIDrawingEnabled()
void orderOut:(id aSender)
void objectDidChangeTheme()
CGRect convertRect:fromView:(CGRect aRect, [fromView] CPView aView)
void scaleUnitSquareToSize:(CGSize aSize)
CPAppearanceNameLightContent
CPMenuItem enclosingMenuItem()
CPAppearanceNameVibrantDark
global appkit_tag_dom_elements typedef _CPViewFullScreenModeState CPViewNotSizable
function CPBrowserStyleProperty(aProperty)
Defines methods for use when archiving & restoring (enc/decoding).
BOOL becomeFirstResponder()
CPAppearance effectiveAppearance()
var CPViewHighDPIDrawingEnabled
CPThemeStateFirstResponder
BOOL unsetThemeState:(ThemeState aState)
function CGContextSaveGState(aContext)
Sends messages (CPNotification) between objects.
BOOL needsPanelToBecomeKey()
void didAddSubview:(CPView aSubview)
void setBounds:(CGRect bounds)
CGAffineTransform affineTransform()
void setBackgroundColor:(CPColor aColor)
void setBoundsSize:(CGSize aSize)
CPAppearance effectiveAppearance()
var CPViewAutoresizesSubviewsKey
void setFrameSize:(CGSize aSize)
CPOpacityRequiresFilterFeature
void viewWillStartLiveResize()
CPAppearanceNameVibrantLight
var CPViewHasCustomViewWillLayout
unsigned autoresizingMask()
CPPlatformWindow platformWindow()
function CPPlatformHasBug(aBug)
void exitFullScreenModeWithOptions:(CPDictionary options)
function CGBitmapGraphicsContextCreate()
BOOL autoresizesSubviews()
CPWindowOrderingMode CPWindowAbove
void setFrameOrigin:(CGPoint aPoint)
void resizeSubviewsWithOldSize:(CGSize aSize)
void unregisterDraggedTypes()
CPViewFrameDidChangeNotification
CGRect rectForEphemeralSubviewNamed:(CPString aViewName)
BOOL isHiddenOrHasHiddenAncestor()
void updateTrackingAreas()
CPCanvasParentDrawErrorsOnMovementBug