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)
93 _CPViewWillAppearNotification =
@"CPViewWillAppearNotification";
94 _CPViewDidAppearNotification =
@"CPViewDidAppearNotification";
95 _CPViewWillDisappearNotification =
@"CPViewWillDisappearNotification";
96 _CPViewDidDisappearNotification =
@"CPViewDidDisappearNotification";
104 var DOMElementPrototype = nil,
106 BackgroundTrivialColor = 0,
107 BackgroundVerticalThreePartImage = 1,
108 BackgroundHorizontalThreePartImage = 2,
109 BackgroundNinePartImage = 3,
110 BackgroundTransparentColor = 4;
150 CGAffineTransform _boundsTransform;
151 CGAffineTransform _inverseBoundsTransform;
153 CPSet _registeredDraggedTypes;
154 CPArray _registeredDraggedTypesArray;
157 BOOL _isHiddenOrHasHiddenAncestor;
161 BOOL _postsFrameChangedNotifications;
162 BOOL _postsBoundsChangedNotifications;
163 BOOL _inhibitFrameAndBoundsChangedNotifications;
165 BOOL _isSuperviewAClipView;
168 DOMElement _DOMElement;
169 DOMElement _DOMContentsElement;
171 CPArray _DOMImageParts;
172 CPArray _DOMImageSizes;
174 unsigned _backgroundType;
182 BOOL _autoresizesSubviews;
183 unsigned _autoresizingMask;
189 BOOL _isInFullScreenMode;
191 _CPViewFullScreenModeState _fullScreenModeState;
195 CGSize _hierarchyScaleSize;
199 BOOL _needToSetTransformMatrix;
204 JSObject _ephemeralSubviews;
206 JSObject _ephemeralSubviewsForNames;
207 CPSet _ephereralSubviews;
213 unsigned _viewClassFlags;
217 Function _toolTipFunctionIn;
218 Function _toolTipFunctionOut;
219 BOOL _toolTipInstalled;
223 BOOL _allowsVibrancy;
228 BOOL _inhibitUpdateTrackingAreas;
232 BOOL _inhibitDOMUpdates;
242 if (
self !== [
CPView class])
246 DOMElementPrototype = document.createElement(
"div");
248 var style = DOMElementPrototype.style;
250 style.overflow =
"hidden";
251 style.position =
"absolute";
252 style.visibility =
"visible";
259 + (Class)_binderClassForBinding:(
CPString)aBinding
264 return [
super _binderClassForBinding:aBinding];
271 + (void)setHighDPIDrawingEnabled:(BOOL)isEnabled
287 return [CPSet setWithObjects:@"frameOrigin", @"frameSize"];
292 return [CPSet setWithObjects:@"boundsOrigin", @"boundsSize"];
300 - (void)_setupViewFlags
302 var theClass = [
self class],
303 classUID = [theClass UID];
309 if ([theClass instanceMethodForSelector:
@selector(drawRect:)] !== [
CPView instanceMethodForSelector:@selector(drawRect:)]
310 || [theClass instanceMethodForSelector:@selector(viewWillDraw)] !== [
CPView instanceMethodForSelector:@selector(viewWillDraw)])
313 if ([theClass instanceMethodForSelector:
@selector(
viewWillLayout)] !== [
CPView instanceMethodForSelector:@selector(viewWillLayout)])
316 if ([theClass instanceMethodForSelector:
@selector(
layoutSubviews)] !== [
CPView instanceMethodForSelector:@selector(layoutSubviews)])
334 - (id)initWithFrame:(CGRect)aFrame
340 var
width = CGRectGetWidth(aFrame),
341 height = CGRectGetHeight(aFrame);
344 _registeredDraggedTypes = [CPSet set];
345 _registeredDraggedTypesArray = [];
351 _frame = CGRectMakeCopy(aFrame);
352 _bounds = CGRectMake(0.0, 0.0, width, height);
355 _autoresizesSubviews = YES;
356 _clipsToBounds = YES;
360 _isHiddenOrHasHiddenAncestor = NO;
363 _hierarchyScaleSize = CGSizeMake(1.0 , 1.0);
364 _scaleSize = CGSizeMake(1.0, 1.0);
368 _themeState = CPThemeStateNormal;
371 _DOMElement = DOMElementPrototype.cloneNode(
false);
372 AppKitTagDOMElement(
self, _DOMElement);
374 CPDOMDisplayServerSetStyleLeftTop(_DOMElement, NULL, CGRectGetMinX(aFrame), CGRectGetMinY(aFrame));
375 CPDOMDisplayServerSetStyleSize(_DOMElement, width, height);
382 _animationsDictionary = @{};
384 [
self _setupViewFlags];
385 [
self _loadThemeAttributes];
387 _inhibitDOMUpdates = NO;
401 if (_toolTip === aToolTip)
404 if (aToolTip && ![aToolTip isKindOfClass:
CPString])
409 [
self _manageToolTipInstallation];
412 - (void)_manageToolTipInstallation
414 if ([
self window] && _toolTip)
415 [
self _installToolTipEventHandlers];
417 [
self _uninstallToolTipEventHandlers];
423 - (void)_installToolTipEventHandlers
425 if (_toolTipInstalled)
428 if (!_toolTipFunctionIn)
429 _toolTipFunctionIn =
function(e) { [_CPToolTip scheduleToolTipForView:self]; }
431 if (!_toolTipFunctionOut)
432 _toolTipFunctionOut =
function(e) { [_CPToolTip invalidateCurrentToolTipIfNeeded]; };
435 if (_DOMElement.addEventListener)
437 _DOMElement.addEventListener(
"mouseover", _toolTipFunctionIn, YES);
438 _DOMElement.addEventListener(
"keypress", _toolTipFunctionOut, YES);
439 _DOMElement.addEventListener(
"mouseout", _toolTipFunctionOut, YES);
441 else if (_DOMElement.attachEvent)
443 _DOMElement.attachEvent(
"onmouseover", _toolTipFunctionIn);
444 _DOMElement.attachEvent(
"onkeypress", _toolTipFunctionOut);
445 _DOMElement.attachEvent(
"onmouseout", _toolTipFunctionOut);
449 _toolTipInstalled = YES;
456 - (void)_uninstallToolTipEventHandlers
458 if (!_toolTipInstalled)
462 if (_DOMElement.removeEventListener)
464 _DOMElement.removeEventListener(
"mouseover", _toolTipFunctionIn, YES);
465 _DOMElement.removeEventListener(
"keypress", _toolTipFunctionOut, YES);
466 _DOMElement.removeEventListener(
"mouseout", _toolTipFunctionOut, YES);
468 else if (_DOMElement.detachEvent)
470 _DOMElement.detachEvent(
"onmouseover", _toolTipFunctionIn);
471 _DOMElement.detachEvent(
"onkeypress", _toolTipFunctionOut);
472 _DOMElement.detachEvent(
"onmouseout", _toolTipFunctionOut);
476 _toolTipFunctionIn = nil;
477 _toolTipFunctionOut = nil;
479 _toolTipInstalled = NO;
497 return [_subviews copy];
514 [
self _insertSubview:aSubview atIndex:CPNotFound];
523 - (void)addSubview:(
CPView)aSubview positioned:(CPWindowOrderingMode)anOrderingMode relativeTo:(
CPView)anotherView
525 var index = anotherView ? [_subviews indexOfObjectIdenticalTo:anotherView] :
CPNotFound;
529 index = (anOrderingMode ===
CPWindowAbove) ? [_subviews count] : 0;
535 [
self _insertSubview:aSubview atIndex:index];
539 - (void)_insertSubview:(
CPView)aSubview atIndex:(int)anIndex
541 if (aSubview ===
self)
544 if (!aSubview._superview && _subviews.indexOf(aSubview) !==
CPNotFound)
552 var count = _subviews.length,
556 [[
self window] _dirtyKeyViewLoop];
559 if (aSubview._superview ===
self)
561 var index = [_subviews indexOfObjectIdenticalTo:aSubview];
564 if (index === anIndex || index === count - 1 && anIndex === count)
567 [_subviews removeObjectAtIndex:index];
570 CPDOMDisplayServerRemoveChild(_DOMElement, aSubview._DOMElement);
583 lastWindow = [superview window];
586 [aSubview _removeFromSuperview];
588 [aSubview _postViewWillAppearNotification];
590 [aSubview _setSuperview:self];
593 if (anIndex ===
CPNotFound || anIndex >= count)
595 _subviews.push(aSubview);
599 CPDOMDisplayServerAppendChild(_DOMElement, aSubview._DOMElement);
604 _subviews.splice(anIndex, 0, aSubview);
608 CPDOMDisplayServerInsertBefore(_DOMElement, aSubview._DOMElement, _subviews[anIndex + 1]._DOMElement);
612 [aSubview setNextResponder:self];
613 [aSubview _scaleSizeUnitSquareToSize:[
self _hierarchyScaleSize]];
619 [aSubview _setWindow:_window];
621 if (!_window && lastWindow)
622 [aSubview _setWindow:nil];
629 [aSubview _notifyViewDidBecomeFirstResponder];
631 [aSubview _notifyViewDidResignFirstResponder];
634 [aSubview _notifyWindowDidBecomeKey];
636 [aSubview _notifyWindowDidResignKey];
659 [
self _removeFromSuperview];
663 [
self _setWindow:nil];
666 - (void)_removeFromSuperview
672 [[
self window] _dirtyKeyViewLoop];
674 [_superview willRemoveSubview:self];
675 [
self _postViewWillDisappearNotification];
677 [_superview._subviews removeObjectIdenticalTo:self];
680 CPDOMDisplayServerRemoveChild(_superview._DOMElement, _DOMElement);
685 [
self _setSuperview:nil];
687 [
self _notifyWindowDidResignKey];
688 [
self _notifyViewDidResignFirstResponder];
698 if (aSubview._superview !==
self || aSubview === aView)
701 var index = [_subviews indexOfObjectIdenticalTo:aSubview];
703 [
self _insertSubview:aView atIndex:index];
708 - (void)setSubviews:(CPArray)newSubviews
711 [
CPException raise:CPInvalidArgumentException
reason:"newSubviews cannot be nil in -[CPView setSubviews:]"];
714 if ([_subviews
isEqual:newSubviews])
718 if ([_subviews count] === 0)
721 count = [newSubviews count];
723 for (; index < count; ++index)
724 [
self addSubview:newSubviews[index]];
730 if ([newSubviews count] === 0)
732 var count = [_subviews count];
735 [_subviews[count] removeFromSuperview];
741 var removedSubviews = [
CPMutableSet setWithArray:_subviews];
743 [removedSubviews removeObjectsInArray:newSubviews];
744 [removedSubviews makeObjectsPerformSelector:@selector(removeFromSuperview)];
747 var addedSubviews = [
CPMutableSet setWithArray:newSubviews];
749 [addedSubviews removeObjectsInArray:_subviews];
751 var addedSubview = nil,
752 addedSubviewEnumerator = [addedSubviews objectEnumerator];
754 while ((addedSubview = [addedSubviewEnumerator nextObject]) !== nil)
758 if ([_subviews
isEqual:newSubviews])
761 _subviews = [newSubviews copy];
765 count = [_subviews count];
767 for (; index < count; ++index)
769 var subview = _subviews[index];
771 CPDOMDisplayServerRemoveChild(_DOMElement, subview._DOMElement);
772 CPDOMDisplayServerAppendChild(_DOMElement, subview._DOMElement);
778 - (void)_setWindow:(
CPWindow)aWindow
780 [[
self window] _dirtyKeyViewLoop];
783 if ([_window firstResponder] ===
self && _window != aWindow)
784 [_window makeFirstResponder:nil];
791 if (_registeredDraggedTypes)
793 [_window _noteUnregisteredDraggedTypes:_registeredDraggedTypes];
794 [aWindow _noteRegisteredDraggedTypes:_registeredDraggedTypes];
798 if (_window && (_trackingAreas.length > 0))
799 [_window _removeTrackingAreaView:
self];
807 if (_trackingAreas.length > 0)
810 [_window _addTrackingAreaView:self];
811 owners = [
self _calcTrackingAreaOwners];
818 [
self _updateTrackingAreasForOwners:owners];
821 var count = [_subviews count];
824 [_subviews[count] _setWindow:aWindow];
826 if ([_window isKeyWindow])
833 [
self _manageToolTipInstallation];
835 [[
self window] _dirtyKeyViewLoop];
875 - (void)viewWillMoveToSuperview:(
CPView)aView
877 _isSuperviewAClipView = [aView isKindOfClass:[
CPClipView class]];
879 [
self _removeObservers];
882 [
self _addObservers];
901 - (void)_removeObservers
906 var count = [_subviews count];
909 [_subviews[count] _removeObservers];
914 - (void)_addObservers
919 var count = [_subviews count];
922 [_subviews[count] _addObservers];
935 while (view && ![view isKindOfClass:[_CPMenuItemView
class]])
936 view = [view superview];
939 return view._menuItem;
951 - (void)setTag:(CPInteger)aTag
963 if ([
self tag] === aTag)
967 count = _subviews.length;
969 for (; index < count; ++index)
971 var view = [_subviews[index] viewWithTag:aTag];
996 - (void)setFrame:(CGRect)aFrame
998 if (CGRectEqualToRect(_frame, aFrame) && !_forceUpdates)
1001 _inhibitFrameAndBoundsChangedNotifications = YES;
1006 _inhibitFrameAndBoundsChangedNotifications = NO;
1008 if (_postsFrameChangedNotifications)
1009 [CachedNotificationCenter postNotificationName:CPViewFrameDidChangeNotification object:self];
1011 if (_isSuperviewAClipView)
1014 if (!_inhibitUpdateTrackingAreas)
1015 [
self _updateTrackingAreasWithRecursion:YES];
1024 return CGRectMakeCopy(_frame);
1029 return CGPointMakeCopy(_frame.origin);
1034 return CGSizeMakeCopy(_frame.size);
1044 - (void)setCenter:(CGPoint)aPoint
1046 [
self setFrameOrigin:CGPointMake(aPoint.x - _frame.size.width / 2.0, aPoint.y - _frame.size.height / 2.0)];
1055 return CGPointMake(_frame.size.width / 2.0 + _frame.origin.x, _frame.size.height / 2.0 + _frame.origin.y);
1065 - (void)setFrameOrigin:(CGPoint)aPoint
1067 var origin = _frame.origin;
1069 if (!aPoint || (CGPointEqualToPoint(origin, aPoint) && !_forceUpdates))
1072 origin.x = aPoint.x;
1073 origin.y = aPoint.y;
1075 if (_postsFrameChangedNotifications && !_inhibitFrameAndBoundsChangedNotifications)
1076 [CachedNotificationCenter postNotificationName:CPViewFrameDidChangeNotification object:self];
1078 if (_isSuperviewAClipView && !_inhibitFrameAndBoundsChangedNotifications)
1082 if (!_inhibitDOMUpdates)
1084 var transform = _superview ? _superview._boundsTransform : NULL;
1086 CPDOMDisplayServerSetStyleLeftTop(_DOMElement, transform, origin.x, origin.y);
1090 if (!_inhibitUpdateTrackingAreas && !_inhibitFrameAndBoundsChangedNotifications)
1091 [
self _updateTrackingAreasWithRecursion:YES];
1100 - (void)setFrameSize:(CGSize)aSize
1102 var size = _frame.size;
1104 if (!aSize || (CGSizeEqualToSize(size, aSize) && !_forceUpdates))
1107 var oldSize = CGSizeMakeCopy(size);
1109 size.width = aSize.width;
1110 size.height = aSize.height;
1114 _bounds.size.width = aSize.width * 1 / _scaleSize.width;
1115 _bounds.size.height = aSize.height * 1 / _scaleSize.height;
1119 [_layer _owningViewBoundsChanged];
1121 if (_autoresizesSubviews)
1128 [
self _setDisplayServerSetStyleSize:size];
1130 if (_backgroundType !== BackgroundTrivialColor)
1132 if (_backgroundType === BackgroundTransparentColor)
1134 CPDOMDisplayServerSetStyleSize(_DOMImageParts[0], size.width, size.height);
1138 var images = [[_backgroundColor patternImage] imageSlices],
1142 if (_backgroundType === BackgroundVerticalThreePartImage)
1144 var top = _DOMImageSizes[0] ? _DOMImageSizes[0].height : 0,
1145 bottom = _DOMImageSizes[2] ? _DOMImageSizes[2].height : 0;
1150 CPDOMDisplayServerSetStyleBackgroundSize(_DOMImageParts[partIndex],
frameSize.width +
"px", top +
"px");
1151 CPDOMDisplayServerSetStyleSize(_DOMImageParts[partIndex], size.width, top);
1154 if (_DOMImageSizes[1])
1156 var height =
frameSize.height - top - bottom;
1158 CPDOMDisplayServerSetStyleBackgroundSize(_DOMImageParts[partIndex],
frameSize.width +
"px", height +
"px");
1159 CPDOMDisplayServerSetStyleSize(_DOMImageParts[partIndex], size.width, size.height - top - bottom);
1164 CPDOMDisplayServerSetStyleBackgroundSize(_DOMImageParts[partIndex],
frameSize.width +
"px", bottom +
"px");
1165 CPDOMDisplayServerSetStyleSize(_DOMImageParts[partIndex], size.width, bottom);
1168 else if (_backgroundType === BackgroundHorizontalThreePartImage)
1170 var left = _DOMImageSizes[0] ? _DOMImageSizes[0].width : 0,
1171 right = _DOMImageSizes[2] ? _DOMImageSizes[2].width : 0;
1176 CPDOMDisplayServerSetStyleBackgroundSize(_DOMImageParts[partIndex], left +
"px",
frameSize.height +
"px");
1177 CPDOMDisplayServerSetStyleSize(_DOMImageParts[partIndex], left, size.height);
1180 if (_DOMImageSizes[1])
1184 CPDOMDisplayServerSetStyleBackgroundSize(_DOMImageParts[partIndex], width +
"px",
frameSize.height +
"px");
1185 CPDOMDisplayServerSetStyleSize(_DOMImageParts[partIndex], size.width - left - right, size.height);
1190 CPDOMDisplayServerSetStyleBackgroundSize(_DOMImageParts[partIndex], right +
"px",
frameSize.height +
"px");
1191 CPDOMDisplayServerSetStyleSize(_DOMImageParts[partIndex], right, size.height);
1194 else if (_backgroundType === BackgroundNinePartImage)
1196 var left = _DOMImageSizes[0] ? _DOMImageSizes[0].width : 0,
1197 right = _DOMImageSizes[2] ? _DOMImageSizes[2].width : 0,
1198 top = _DOMImageSizes[0] ? _DOMImageSizes[0].height : 0,
1199 bottom = _DOMImageSizes[6] ? _DOMImageSizes[6].height : 0,
1200 width = size.width - left - right,
1201 height = size.height - top - bottom;
1203 if (_DOMImageSizes[0])
1205 if (_DOMImageSizes[1])
1207 CPDOMDisplayServerSetStyleSize(_DOMImageParts[partIndex],
width, top);
1210 if (_DOMImageSizes[2])
1212 if (_DOMImageSizes[3])
1214 CPDOMDisplayServerSetStyleSize(_DOMImageParts[partIndex], _DOMImageSizes[3].
width, height);
1217 if (_DOMImageSizes[4])
1219 CPDOMDisplayServerSetStyleSize(_DOMImageParts[partIndex],
width, height);
1222 if (_DOMImageSizes[5])
1224 CPDOMDisplayServerSetStyleSize(_DOMImageParts[partIndex], _DOMImageSizes[5].
width, height);
1227 if (_DOMImageSizes[6])
1229 if (_DOMImageSizes[7])
1231 CPDOMDisplayServerSetStyleSize(_DOMImageParts[partIndex],
width, _DOMImageSizes[7].height);
1238 if (_postsFrameChangedNotifications && !_inhibitFrameAndBoundsChangedNotifications)
1239 [CachedNotificationCenter postNotificationName:CPViewFrameDidChangeNotification object:self];
1241 if (_isSuperviewAClipView && !_inhibitFrameAndBoundsChangedNotifications)
1244 if (!_inhibitUpdateTrackingAreas && !_inhibitFrameAndBoundsChangedNotifications)
1245 [
self _updateTrackingAreasWithRecursion:!_autoresizesSubviews];
1253 - (void)_setDisplayServerSetStyleSize:(CGSize)aSize
1258 if (!_inhibitDOMUpdates)
1259 CPDOMDisplayServerSetStyleSize(_DOMElement, aSize.width * 1 / scale.width, aSize.height * 1 / scale.height);
1261 if (_DOMContentsElement)
1263 CPDOMDisplayServerSetSize(_DOMContentsElement, aSize.width * _highDPIRatio * 1 / scale.width, aSize.height * _highDPIRatio * 1 / scale.height);
1264 CPDOMDisplayServerSetStyleSize(_DOMContentsElement, aSize.width * 1 / scale.width, aSize.height * 1 / scale.height);
1266 _needToSetTransformMatrix = YES;
1276 - (void)setBounds:(CGRect)bounds
1278 if (CGRectEqualToRect(_bounds,
bounds))
1281 _inhibitFrameAndBoundsChangedNotifications = YES;
1286 _inhibitFrameAndBoundsChangedNotifications = NO;
1288 if (_postsBoundsChangedNotifications)
1289 [CachedNotificationCenter postNotificationName:CPViewBoundsDidChangeNotification object:self];
1291 if (_isSuperviewAClipView)
1294 if (!_inhibitUpdateTrackingAreas)
1295 [
self _updateTrackingAreasWithRecursion:YES];
1304 return CGRectMakeCopy(_bounds);
1309 return CGPointMakeCopy(_bounds.origin);
1314 return CGSizeMakeCopy(_bounds.size);
1323 - (void)setBoundsOrigin:(CGPoint)aPoint
1325 var origin = _bounds.origin;
1327 if (CGPointEqualToPoint(origin, aPoint))
1330 origin.x = aPoint.x;
1331 origin.y = aPoint.y;
1333 if (origin.x != 0 || origin.y != 0)
1340 _boundsTransform = nil;
1341 _inverseBoundsTransform = nil;
1345 var index = _subviews.length;
1349 var view = _subviews[index],
1350 origin = view._frame.origin;
1352 CPDOMDisplayServerSetStyleLeftTop(view._DOMElement, _boundsTransform, origin.x, origin.y);
1356 if (_postsBoundsChangedNotifications && !_inhibitFrameAndBoundsChangedNotifications)
1357 [CachedNotificationCenter postNotificationName:CPViewBoundsDidChangeNotification object:self];
1359 if (_isSuperviewAClipView && !_inhibitFrameAndBoundsChangedNotifications)
1362 if (!_inhibitUpdateTrackingAreas && !_inhibitFrameAndBoundsChangedNotifications)
1363 [
self _updateTrackingAreasWithRecursion:YES];
1372 - (void)setBoundsSize:(CGSize)aSize
1374 var size = _bounds.size;
1376 if (CGSizeEqualToSize(size, aSize))
1381 if (!CGSizeEqualToSize(size,
frameSize))
1383 var origin = _bounds.origin;
1385 origin.x /= size.width /
frameSize.width;
1386 origin.y /= size.height /
frameSize.height;
1389 size.width = aSize.width;
1390 size.height = aSize.height;
1392 if (!CGSizeEqualToSize(size,
frameSize))
1394 var origin = _bounds.origin;
1396 origin.x *= size.width /
frameSize.width;
1397 origin.y *= size.height /
frameSize.height;
1400 if (_postsBoundsChangedNotifications && !_inhibitFrameAndBoundsChangedNotifications)
1401 [CachedNotificationCenter postNotificationName:CPViewBoundsDidChangeNotification object:self];
1403 if (_isSuperviewAClipView && !_inhibitFrameAndBoundsChangedNotifications)
1406 if (!_inhibitUpdateTrackingAreas && !_inhibitFrameAndBoundsChangedNotifications)
1407 [
self _updateTrackingAreasWithRecursion:YES];
1415 - (void)resizeWithOldSuperviewSize:(CGSize)aSize
1422 var
frame = _superview._frame,
1423 newFrame = CGRectMakeCopy(_frame),
1424 dX =
frame.size.width - aSize.width,
1425 dY =
frame.size.height - aSize.height,
1430 (mask &
CPViewMaxXMargin ? aSize.width - _frame.size.width - _frame.origin.x : 0),
1433 (mask &
CPViewMaxYMargin ? aSize.height - _frame.size.height - _frame.origin.y : 0);
1436 newFrame.origin.x += dX * (baseX > 0 ? _frame.origin.x / baseX : evenFractionX);
1439 newFrame.size.width += dX * (baseX > 0 ? _frame.size.width / baseX : evenFractionX);
1442 newFrame.origin.y += dY * (baseY > 0 ? _frame.origin.y / baseY : evenFractionY);
1445 newFrame.size.height += dY * (baseY > 0 ? _frame.size.height / baseY : evenFractionY);
1454 - (void)resizeSubviewsWithOldSize:(CGSize)aSize
1456 var count = _subviews.length;
1459 [_subviews[count] resizeWithOldSuperviewSize:aSize];
1469 - (void)setAutoresizesSubviews:(BOOL)aFlag
1471 _autoresizesSubviews = !!aFlag;
1480 return _autoresizesSubviews;
1487 - (void)setAutoresizingMask:(
unsigned)aMask
1489 _autoresizingMask = aMask;
1497 return _autoresizingMask;
1517 _fullScreenModeState = _CPViewFullScreenModeStateMake(
self);
1521 [fullScreenWindow setLevel:CPScreenSaverWindowLevel];
1522 [fullScreenWindow setAutoresizingMask:CPViewWidthSizable | CPViewHeightSizable];
1524 var contentView = [fullScreenWindow contentView];
1527 [contentView addSubview:self];
1530 [
self setFrame:CGRectMakeCopy([contentView bounds])];
1532 [fullScreenWindow makeKeyAndOrderFront:self];
1534 [fullScreenWindow makeFirstResponder:self];
1536 _isInFullScreenMode = YES;
1555 if (!_isInFullScreenMode)
1558 _isInFullScreenMode = NO;
1560 [
self setFrame:_fullScreenModeState.frame];
1562 [_fullScreenModeState.superview _insertSubview:self atIndex:_fullScreenModeState.index];
1572 return _isInFullScreenMode;
1579 - (void)setHidden:(BOOL)aFlag
1583 if (_isHidden === aFlag)
1589 _DOMElement.style.display = aFlag ?
"none" :
"block";
1594 var view = [_window firstResponder];
1596 if ([view isKindOfClass:[
CPView class]])
1609 [
self _postViewWillDisappearNotification];
1610 [
self _recursiveGainedHiddenAncestor];
1616 [
self _postViewWillAppearNotification];
1617 [
self _recursiveLostHiddenAncestor];
1623 - (void)_postViewWillAppearNotification
1628 - (void)_postViewDidAppearNotification
1633 - (void)_postViewWillDisappearNotification
1638 - (void)_postViewDidDisappearNotification
1643 - (void)_setSuperview:(
CPView)aSuperview
1645 var hasOldSuperview = (_superview !== nil),
1646 hasNewSuperview = (aSuperview !== nil),
1647 oldSuperviewIsHidden = hasOldSuperview && [_superview isHiddenOrHasHiddenAncestor],
1648 newSuperviewIsHidden = hasNewSuperview && [aSuperview isHiddenOrHasHiddenAncestor];
1650 if (!newSuperviewIsHidden && oldSuperviewIsHidden)
1651 [
self _recursiveLostHiddenAncestor];
1653 if (newSuperviewIsHidden && !oldSuperviewIsHidden)
1654 [
self _recursiveGainedHiddenAncestor];
1656 _superview = aSuperview;
1658 if (hasOldSuperview)
1659 [
self _postViewDidDisappearNotification];
1661 if (hasNewSuperview)
1662 [
self _postViewDidAppearNotification];
1665 - (void)_recursiveLostHiddenAncestor
1667 if (_isHiddenOrHasHiddenAncestor)
1669 _isHiddenOrHasHiddenAncestor = NO;
1673 [_subviews enumerateObjectsUsingBlock:function(view, idx, stop)
1675 [view _recursiveLostHiddenAncestor];
1679 - (void)_recursiveGainedHiddenAncestor
1686 _isHiddenOrHasHiddenAncestor = YES;
1688 [_subviews enumerateObjectsUsingBlock:function(view, idx, stop)
1690 [view _recursiveGainedHiddenAncestor];
1702 - (void)setClipsToBounds:(BOOL)shouldClip
1704 if (_clipsToBounds === shouldClip)
1707 _clipsToBounds = shouldClip;
1710 _DOMElement.style.overflow = _clipsToBounds ?
"hidden" :
"visible";
1716 return _clipsToBounds;
1724 - (void)setAlphaValue:(
float)anAlphaValue
1726 if (_opacity === anAlphaValue)
1729 _opacity = anAlphaValue;
1735 if (anAlphaValue === 1.0)
1736 try { _DOMElement.style.removeAttribute(
"filter") }
catch (anException) { }
1738 _DOMElement.style.filter =
"alpha(opacity=" + anAlphaValue * 100 +
")";
1741 _DOMElement.style.opacity = anAlphaValue;
1761 return _isHiddenOrHasHiddenAncestor;
1823 - (void)setHitTests:(BOOL)shouldHitTest
1825 _hitTests = !!shouldHitTest;
1835 if (_isHidden || !_hitTests)
1839 sizeScale = [
self _hierarchyScaleSize];
1846 if (!CGRectContainsPoint(
frame, aPoint))
1850 i = _subviews.length,
1851 adjustedPoint = CGPointMake(aPoint.x - CGRectGetMinX(
frame), aPoint.y - CGRectGetMinY(
frame));
1853 if (_inverseBoundsTransform)
1859 affineTransform.tx *= [_superview _hierarchyScaleSize].width;
1860 affineTransform.ty *= [_superview _hierarchyScaleSize].height;
1864 affineTransform.tx *= sizeScale.width;
1865 affineTransform.ty *= sizeScale.height;
1873 if (view = [_subviews[i] hitTest:adjustedPoint])
1899 [
super mouseDown:anEvent];
1908 else if ([[
self nextResponder] isKindOfClass:
CPView])
1909 [
super rightMouseDown:anEvent];
1916 return [
self menu] || [[
self class] defaultMenu];
1925 if (_backgroundColor === aColor)
1928 if (aColor === [
CPNull null])
1931 _backgroundColor = aColor;
1934 var patternImage = [_backgroundColor patternImage],
1935 colorExists = _backgroundColor && ([_backgroundColor patternImage] || [_backgroundColor alphaComponent] > 0.0),
1936 colorHasAlpha = colorExists && [_backgroundColor alphaComponent] < 1.0,
1938 colorNeedsDOMElement = colorHasAlpha && !supportsRGBA,
1942 if ([patternImage isThreePartImage])
1944 _backgroundType = [patternImage isVertical] ? BackgroundVerticalThreePartImage : BackgroundHorizontalThreePartImage;
1947 else if ([patternImage isNinePartImage])
1949 _backgroundType = BackgroundNinePartImage;
1954 _backgroundType = colorNeedsDOMElement ? BackgroundTransparentColor : BackgroundTrivialColor;
1955 amount = (colorNeedsDOMElement ? 1 : 0) - _DOMImageParts.length;
1959 if (_backgroundType === BackgroundVerticalThreePartImage || _backgroundType === BackgroundHorizontalThreePartImage || _backgroundType === BackgroundNinePartImage)
1961 slices = [patternImage imageSlices];
1964 amount = MIN(amount, slices.length);
1966 for (var i = 0, count = slices.length; i < count; i++)
1968 var image = slices[i],
1969 size = [image size];
1971 if (!size || (size.width === 0 && size.height === 0))
1974 _DOMImageSizes[i] = size;
1982 amount -= _DOMImageParts.length;
1990 var DOMElement = DOMElementPrototype.cloneNode(
false);
1992 DOMElement.style.zIndex = -1000;
1994 _DOMImageParts.push(DOMElement);
1995 _DOMElement.appendChild(DOMElement);
2002 _DOMElement.removeChild(_DOMImageParts.pop());
2005 if (_backgroundType === BackgroundTrivialColor || _backgroundType === BackgroundTransparentColor)
2007 var colorCSS = colorExists ? [_backgroundColor cssString] :
"";
2009 if (colorNeedsDOMElement)
2011 _DOMElement.style.background =
"";
2012 _DOMImageParts[0].style.background = [_backgroundColor cssString];
2015 CPDOMDisplayServerSetStyleBackgroundSize(_DOMImageParts[0], [patternImage size].
width +
"px", [patternImage size].height +
"px");
2018 _DOMImageParts[0].style.filter =
"alpha(opacity=" + [_backgroundColor alphaComponent] * 100 +
")";
2020 _DOMImageParts[0].style.opacity = [_backgroundColor alphaComponent];
2022 var size = [
self bounds].size;
2023 CPDOMDisplayServerSetStyleSize(_DOMImageParts[0], size.width, size.height);
2027 _DOMElement.style.background = colorCSS;
2030 CPDOMDisplayServerSetStyleBackgroundSize(_DOMElement, [patternImage size].
width +
"px", [patternImage size].height +
"px");
2038 for (var i = 0; i < slices.length; i++)
2040 var size = _DOMImageSizes[i];
2045 var image = slices[i];
2050 CPDOMDisplayServerSetStyleSize(_DOMImageParts[partIndex], size.width, size.height);
2052 _DOMImageParts[partIndex].style.background =
"url(\"" + [image filename] +
"\")";
2057 try { _DOMImageParts[partIndex].style.removeAttribute(
"filter") }
catch (anException) { }
2059 _DOMImageParts[partIndex].style.opacity = 1.0;
2065 if (_backgroundType === BackgroundNinePartImage)
2067 var left = _DOMImageSizes[0] ? _DOMImageSizes[0].width : 0,
2068 right = _DOMImageSizes[2] ? _DOMImageSizes[2].width : 0,
2069 top = _DOMImageSizes[0] ? _DOMImageSizes[0].height : 0,
2070 bottom = _DOMImageSizes[6] ? _DOMImageSizes[6].height : 0,
2071 width = frameSize.width - left - right,
2072 height = frameSize.height - top - bottom;
2076 if (_DOMImageSizes[0])
2078 CPDOMDisplayServerSetStyleLeftTop(_DOMImageParts[partIndex], NULL, 0.0, 0.0);
2081 if (_DOMImageSizes[1])
2083 CPDOMDisplayServerSetStyleLeftTop(_DOMImageParts[partIndex], NULL, left, 0.0);
2084 CPDOMDisplayServerSetStyleSize(_DOMImageParts[partIndex],
width, _DOMImageSizes[1].height);
2087 if (_DOMImageSizes[2])
2089 CPDOMDisplayServerSetStyleRightTop(_DOMImageParts[partIndex], NULL, 0.0, 0.0);
2092 if (_DOMImageSizes[3])
2094 CPDOMDisplayServerSetStyleLeftTop(_DOMImageParts[partIndex], NULL, 0.0, top);
2095 CPDOMDisplayServerSetStyleSize(_DOMImageParts[partIndex], _DOMImageSizes[3].
width, height);
2098 if (_DOMImageSizes[4])
2100 CPDOMDisplayServerSetStyleLeftTop(_DOMImageParts[partIndex], NULL, left, top);
2101 CPDOMDisplayServerSetStyleSize(_DOMImageParts[partIndex],
width, height);
2104 if (_DOMImageSizes[5])
2106 CPDOMDisplayServerSetStyleRightTop(_DOMImageParts[partIndex], NULL, 0.0, top);
2107 CPDOMDisplayServerSetStyleSize(_DOMImageParts[partIndex], _DOMImageSizes[5].
width, height);
2110 if (_DOMImageSizes[6])
2112 CPDOMDisplayServerSetStyleLeftBottom(_DOMImageParts[partIndex], NULL, 0.0, 0.0);
2115 if (_DOMImageSizes[7])
2117 CPDOMDisplayServerSetStyleLeftBottom(_DOMImageParts[partIndex], NULL, left, 0.0);
2118 CPDOMDisplayServerSetStyleSize(_DOMImageParts[partIndex],
width, _DOMImageSizes[7].height);
2121 if (_DOMImageSizes[8])
2123 CPDOMDisplayServerSetStyleRightBottom(_DOMImageParts[partIndex], NULL, 0.0, 0.0);
2126 else if (_backgroundType === BackgroundVerticalThreePartImage)
2128 var top = _DOMImageSizes[0] ? _DOMImageSizes[0].height : 0,
2129 bottom = _DOMImageSizes[2] ? _DOMImageSizes[2].height : 0;
2136 CPDOMDisplayServerSetStyleBackgroundSize(_DOMImageParts[partIndex], frameSize.width +
"px", top +
"px");
2137 CPDOMDisplayServerSetStyleLeftTop(_DOMImageParts[partIndex], NULL, 0.0, 0.0);
2138 CPDOMDisplayServerSetStyleSize(_DOMImageParts[partIndex], frameSize.width, top);
2141 if (_DOMImageSizes[1])
2143 var height = frameSize.height - top - bottom;
2146 CPDOMDisplayServerSetStyleBackgroundSize(_DOMImageParts[partIndex], frameSize.width +
"px", height +
"px");
2147 CPDOMDisplayServerSetStyleLeftTop(_DOMImageParts[partIndex], NULL, 0.0, top);
2148 CPDOMDisplayServerSetStyleSize(_DOMImageParts[partIndex], frameSize.width, height);
2153 CPDOMDisplayServerSetStyleBackgroundSize(_DOMImageParts[partIndex], frameSize.width +
"px", bottom +
"px");
2154 CPDOMDisplayServerSetStyleLeftBottom(_DOMImageParts[partIndex], NULL, 0.0, 0.0);
2155 CPDOMDisplayServerSetStyleSize(_DOMImageParts[partIndex], frameSize.width, bottom);
2158 else if (_backgroundType === BackgroundHorizontalThreePartImage)
2160 var left = _DOMImageSizes[0] ? _DOMImageSizes[0].width : 0,
2161 right = _DOMImageSizes[2] ? _DOMImageSizes[2].width : 0;
2168 CPDOMDisplayServerSetStyleBackgroundSize(_DOMImageParts[partIndex], left +
"px", frameSize.height +
"px");
2169 CPDOMDisplayServerSetStyleLeftTop(_DOMImageParts[partIndex], NULL, 0.0, 0.0);
2170 CPDOMDisplayServerSetStyleSize(_DOMImageParts[partIndex], left, frameSize.height);
2173 if (_DOMImageSizes[1])
2175 var
width = (frameSize.width - left - right);
2177 CPDOMDisplayServerSetStyleBackgroundSize(_DOMImageParts[partIndex], width +
"px", frameSize.height +
"px");
2178 CPDOMDisplayServerSetStyleLeftTop(_DOMImageParts[partIndex], NULL, left, 0.0);
2179 CPDOMDisplayServerSetStyleSize(_DOMImageParts[partIndex], width, frameSize.height);
2184 CPDOMDisplayServerSetStyleBackgroundSize(_DOMImageParts[partIndex], right +
"px", frameSize.height +
"px");
2185 CPDOMDisplayServerSetStyleRightTop(_DOMImageParts[partIndex], NULL, 0.0, 0.0);
2186 CPDOMDisplayServerSetStyleSize(_DOMImageParts[partIndex], right, frameSize.height);
2198 return _backgroundColor;
2208 - (CGPoint)convertPoint:(CGPoint)aPoint fromView:(
CPView)aView
2221 - (CGPoint)convertPointFromBase:(CGPoint)aPoint
2232 - (CGPoint)convertPoint:(CGPoint)aPoint toView:(
CPView)aView
2246 - (CGPoint)convertPointToBase:(CGPoint)aPoint
2257 - (CGSize)convertSize:(CGSize)aSize fromView:(
CPView)aView
2271 - (CGSize)convertSize:(CGSize)aSize toView:(
CPView)aView
2285 - (CGRect)convertRect:(CGRect)aRect fromView:(
CPView)aView
2298 - (CGRect)convertRectFromBase:(CGRect)aRect
2309 - (CGRect)convertRect:(CGRect)aRect toView:(
CPView)aView
2322 - (CGRect)convertRectToBase:(CGRect)aRect
2339 - (void)setPostsFrameChangedNotifications:(BOOL)shouldPostFrameChangedNotifications
2341 shouldPostFrameChangedNotifications = !!shouldPostFrameChangedNotifications;
2343 if (_postsFrameChangedNotifications === shouldPostFrameChangedNotifications)
2346 _postsFrameChangedNotifications = shouldPostFrameChangedNotifications;
2354 return _postsFrameChangedNotifications;
2369 - (void)setPostsBoundsChangedNotifications:(BOOL)shouldPostBoundsChangedNotifications
2371 shouldPostBoundsChangedNotifications = !!shouldPostBoundsChangedNotifications;
2373 if (_postsBoundsChangedNotifications === shouldPostBoundsChangedNotifications)
2376 _postsBoundsChangedNotifications = shouldPostBoundsChangedNotifications;
2386 return _postsBoundsChangedNotifications;
2399 - (void)dragImage:(
CPImage)anImage at:(CGPoint)aLocation offset:(CGSize)mouseOffset event:(
CPEvent)anEvent pasteboard:(
CPPasteboard)aPasteboard source:(
id)aSourceObject slideBack:(BOOL)slideBack
2401 [_window dragImage:anImage at:[
self convertPoint:aLocation
toView:nil] offset:mouseOffset event:anEvent pasteboard:aPasteboard source:aSourceObject slideBack:slideBack];
2414 - (void)dragView:(
CPView)aView at:(CGPoint)aLocation offset:(CGSize)mouseOffset event:(
CPEvent)anEvent pasteboard:(
CPPasteboard)aPasteboard source:(
id)aSourceObject slideBack:(BOOL)slideBack
2416 [_window dragView:aView at:[
self convertPoint:aLocation
toView:nil] offset:mouseOffset event:anEvent pasteboard:aPasteboard source:aSourceObject slideBack:slideBack];
2423 - (void)registerForDraggedTypes:(CPArray)pasteboardTypes
2425 if (!pasteboardTypes || ![pasteboardTypes count])
2428 var theWindow = [
self window];
2430 [theWindow _noteUnregisteredDraggedTypes:_registeredDraggedTypes];
2431 [_registeredDraggedTypes addObjectsFromArray:pasteboardTypes];
2432 [theWindow _noteRegisteredDraggedTypes:_registeredDraggedTypes];
2434 _registeredDraggedTypesArray = nil;
2443 if (!_registeredDraggedTypesArray)
2444 _registeredDraggedTypesArray = [_registeredDraggedTypes allObjects];
2446 return _registeredDraggedTypesArray;
2454 [[
self window] _noteUnregisteredDraggedTypes:_registeredDraggedTypes];
2456 _registeredDraggedTypes = [CPSet set];
2457 _registeredDraggedTypesArray = [];
2464 - (void)drawRect:(CGRect)aRect
2477 - (void)scaleUnitSquareToSize:(CGSize)aSize
2484 bounds.size.width *= _scaleSize.width;
2485 bounds.size.height *= _scaleSize.height;
2487 [
self willChangeValueForKey:@"scaleSize"];
2488 _scaleSize = CGSizeMakeCopy([
self scaleSize]);
2489 _scaleSize.height *= aSize.height;
2490 _scaleSize.width *= aSize.width;
2491 [
self didChangeValueForKey:@"scaleSize"];
2494 _hierarchyScaleSize = CGSizeMakeCopy([
self _hierarchyScaleSize]);
2495 _hierarchyScaleSize.height *= aSize.height;
2496 _hierarchyScaleSize.width *= aSize.width;
2503 [_subviews makeObjectsPerformSelector:@selector(_scaleSizeUnitSquareToSize:) withObject:aSize];
2510 - (void)_scaleSizeUnitSquareToSize:(CGSize)aSize
2512 _hierarchyScaleSize = CGSizeMakeCopy([_superview _hierarchyScaleSize]);
2516 _hierarchyScaleSize.width *= _scaleSize.width;
2517 _hierarchyScaleSize.height *= _scaleSize.height;
2520 [_subviews makeObjectsPerformSelector:@selector(_scaleSizeUnitSquareToSize:) withObject:aSize];
2526 - (CGSize)_hierarchyScaleSize
2528 return _hierarchyScaleSize || CGSizeMake(1.0, 1.0);
2534 - (void)_applyCSSScalingTranformations
2543 self._DOMElement.style[browserPropertyTransform] =
'scale(' + scale.width +
', ' + scale.height +
')';
2544 self._DOMElement.style[browserPropertyTransformOrigin] =
'0 0';
2546 [
self _setDisplayServerSetStyleSize:[
self frameSize]];
2560 [
self _applyCSSScalingTranformations];
2569 - (void)setNeedsDisplayInRect:(CGRect)aRect
2574 if (CGRectIsEmpty(aRect))
2577 if (_dirtyRect && !CGRectIsEmpty(_dirtyRect))
2578 _dirtyRect = CGRectUnion(aRect, _dirtyRect);
2580 _dirtyRect = CGRectMakeCopy(aRect);
2582 _CPDisplayServerAddDisplayObject(
self);
2587 return _dirtyRect && !CGRectIsEmpty(_dirtyRect);
2607 - (void)displayIfNeededInRect:(CGRect)aRect
2617 - (void)displayRect:(CGRect)aRect
2650 if (!_graphicsContext)
2655 var
width = CGRectGetWidth(_frame),
2656 height = CGRectGetHeight(_frame),
2657 devicePixelRatio =
window.devicePixelRatio || 1,
2662 _DOMContentsElement = graphicsPort.DOMElement;
2664 _DOMContentsElement.style.zIndex = -100;
2666 _DOMContentsElement.style.overflow =
"hidden";
2667 _DOMContentsElement.style.position =
"absolute";
2668 _DOMContentsElement.style.visibility =
"visible";
2670 CPDOMDisplayServerSetSize(_DOMContentsElement, width * _highDPIRatio, height * _highDPIRatio);
2672 CPDOMDisplayServerSetStyleLeftTop(_DOMContentsElement, NULL, 0.0, 0.0);
2673 CPDOMDisplayServerSetStyleSize(_DOMContentsElement, width, height);
2678 _DOMElement.style.webkitTransform =
'translateX(0)';
2680 CPDOMDisplayServerAppendChild(_DOMElement, _DOMContentsElement);
2683 _needToSetTransformMatrix = YES;
2687 if (_needToSetTransformMatrix && _highDPIRatio !== 1)
2688 [_graphicsContext graphicsPort].setTransform(_highDPIRatio, 0, 0 , _highDPIRatio, 0, 0);
2691 _needToSetTransformMatrix = NO;
2722 _CPDisplayServerAddLayoutObject(
self);
2727 return _needsLayout;
2762 [
self _recomputeAppearance];
2786 return CGRectIntersection([
self convertRect:[_superview
visibleRect] fromView:_superview], _bounds);
2796 while (superview && ![superview isKindOfClass:clipViewClass])
2797 superview = superview._superview;
2806 - (void)scrollPoint:(CGPoint)aPoint
2808 var clipView = [
self _enclosingClipView];
2821 - (BOOL)scrollRectToVisible:(CGRect)aRect
2824 aRect = CGRectIntersection(aRect, _bounds);
2827 if (CGRectIsEmpty(aRect))
2830 var enclosingClipView = [
self _enclosingClipView];
2833 if (!enclosingClipView)
2836 var documentView = [enclosingClipView documentView];
2843 var documentViewVisibleRect = [documentView visibleRect],
2847 if (CGRectContainsRect(documentViewVisibleRect, rectInDocumentView))
2850 var currentScrollPoint = documentViewVisibleRect.origin,
2851 scrollPoint = CGPointMakeCopy(currentScrollPoint),
2852 rectInDocumentViewMinX = CGRectGetMinX(rectInDocumentView),
2853 documentViewVisibleRectMinX = CGRectGetMinX(documentViewVisibleRect),
2854 doesItFitForWidth = documentViewVisibleRect.size.width >= rectInDocumentView.size.width;
2857 if (rectInDocumentViewMinX < documentViewVisibleRectMinX && doesItFitForWidth)
2859 scrollPoint.x = rectInDocumentViewMinX;
2860 else if (CGRectGetMaxX(rectInDocumentView) > CGRectGetMaxX(documentViewVisibleRect) && doesItFitForWidth)
2862 scrollPoint.x = CGRectGetMaxX(rectInDocumentView) - documentViewVisibleRect.size.width;
2863 else if (rectInDocumentViewMinX > documentViewVisibleRectMinX)
2865 scrollPoint.x = rectInDocumentViewMinX;
2866 else if (CGRectGetMaxX(rectInDocumentView) < CGRectGetMaxX(documentViewVisibleRect))
2868 scrollPoint.x = CGRectGetMaxX(rectInDocumentView) - documentViewVisibleRect.size.width;
2870 var rectInDocumentViewMinY = CGRectGetMinY(rectInDocumentView),
2871 documentViewVisibleRectMinY = CGRectGetMinY(documentViewVisibleRect),
2872 doesItFitForHeight = documentViewVisibleRect.size.height >= rectInDocumentView.size.height;
2874 if (rectInDocumentViewMinY < documentViewVisibleRectMinY && doesItFitForHeight)
2876 scrollPoint.y = rectInDocumentViewMinY;
2877 else if (CGRectGetMaxY(rectInDocumentView) > CGRectGetMaxY(documentViewVisibleRect) && doesItFitForHeight)
2879 scrollPoint.y = CGRectGetMaxY(rectInDocumentView) - documentViewVisibleRect.size.height;
2880 else if (rectInDocumentViewMinY > documentViewVisibleRectMinY)
2882 scrollPoint.y = rectInDocumentViewMinY;
2883 else if (CGRectGetMaxY(rectInDocumentView) < CGRectGetMaxY(documentViewVisibleRect))
2885 scrollPoint.y = CGRectGetMaxY(rectInDocumentView) - documentViewVisibleRect.size.height;
2889 if (CGPointEqualToPoint(scrollPoint, currentScrollPoint))
2892 [enclosingClipView scrollToPoint:scrollPoint];
2911 - (CGRect)adjustScroll:(CGRect)proposedVisibleRect
2913 return proposedVisibleRect;
2919 - (void)scrollRect:(CGRect)aRect by:(
float)anAmount
2944 - (void)scrollClipView:(
CPClipView)aClipView toPoint:(CGPoint)aPoint
2963 return _inLiveResize;
2977 _inLiveResize = YES;
3015 var count = [_subviews count];
3019 if ([_subviews[count] performKeyEquivalent:anEvent])
3032 return _nextKeyView;
3038 resultUID = [result UID],
3039 unsuitableResults = {};
3043 unsuitableResults[resultUID] = 1;
3044 result = [result nextKeyView];
3046 resultUID = [result UID];
3049 if (unsuitableResults[resultUID])
3058 return _previousKeyView;
3064 firstResult = result;
3068 result = [result previousKeyView];
3071 if (result === firstResult)
3078 - (void)_setPreviousKeyView:(
CPView)previous
3082 var previousWindow = [previous window];
3084 if (!previousWindow || previousWindow === _window)
3086 _previousKeyView = previous;
3091 _previousKeyView = nil;
3098 var nextWindow = [next
window];
3100 if (!nextWindow || nextWindow === _window)
3102 _nextKeyView = next;
3103 [_nextKeyView _setPreviousKeyView:self];
3120 if (_layer === aLayer)
3125 _layer._owningView = nil;
3127 _DOMElement.removeChild(_layer._DOMElement);
3135 var
bounds = CGRectMakeCopy([
self bounds]);
3137 [_layer _setOwningView:self];
3140 _layer._DOMElement.style.zIndex = 100;
3142 _DOMElement.appendChild(_layer._DOMElement);
3159 - (void)setWantsLayer:(BOOL)aFlag
3161 _wantsLayer = !!aFlag;
3183 - (void)setScaleSize:(CGSize)aSize
3185 if (CGSizeEqualToSize(_scaleSize, aSize))
3188 var size = CGSizeMakeZero(),
3189 scale = CGSizeMakeCopy([
self scaleSize]);
3191 size.height = aSize.height / scale.height;
3192 size.width = aSize.width / scale.width;
3204 return _scaleSize || CGSizeMake(1.0, 1.0);
3212 #pragma mark Override 3216 var shouldLayout = [
super setThemeState:aState];
3229 var shouldLayout = [
super unsetThemeState:aState];
3242 [
super setThemeClass:theClass];
3249 #pragma mark First responder 3253 var r = [
super becomeFirstResponder];
3256 [
self _notifyViewDidBecomeFirstResponder];
3261 - (void)_notifyViewDidBecomeFirstResponder
3265 var count = [_subviews count];
3268 [_subviews[count] _notifyViewDidBecomeFirstResponder];
3273 var r = [
super resignFirstResponder];
3276 [
self _notifyViewDidResignFirstResponder];
3281 - (void)_notifyViewDidResignFirstResponder
3285 var count = [_subviews count];
3288 [_subviews[count] _notifyViewDidResignFirstResponder];
3291 - (void)_notifyWindowDidBecomeKey
3295 var count = [_subviews count];
3298 [_subviews[count] _notifyWindowDidBecomeKey];
3301 - (void)_notifyWindowDidResignKey
3305 var count = [_subviews count];
3308 [_subviews[count] _notifyWindowDidResignKey];
3311 #pragma mark Theme Attributes 3313 - (void)_setThemeIncludingDescendants:(
CPTheme)aTheme
3315 [
self setTheme:aTheme];
3316 [[
self subviews] makeObjectsPerformSelector:@selector(_setThemeIncludingDescendants:) withObject:aTheme];
3321 if (!_themeAttributes)
3324 [
super objectDidChangeTheme];
3332 var currentValue = [
self currentValueForThemeAttribute:aName];
3334 [
super setValue:aValue forThemeAttribute:aName inState:aState];
3336 if ([
self currentValueForThemeAttribute:aName] === currentValue)
3343 - (void)setValue:(
id)aValue forThemeAttribute:(
CPString)aName
3345 var currentValue = [
self currentValueForThemeAttribute:aName];
3347 [
super setValue:aValue forThemeAttribute:aName ];
3349 if ([
self currentValueForThemeAttribute:aName] === currentValue)
3361 - (CGRect)rectForEphemeralSubviewNamed:(
CPString)aViewName
3363 return CGRectMakeZero();
3367 positioned:(CPWindowOrderingMode)anOrderingMode
3368 relativeToEphemeralSubviewNamed:(
CPString)relativeToViewName
3370 if (!_ephemeralSubviewsForNames)
3372 _ephemeralSubviewsForNames = {};
3373 _ephemeralSubviews = [CPSet set];
3380 if (!_ephemeralSubviewsForNames[aViewName])
3384 [_ephemeralSubviews addObject:_ephemeralSubviewsForNames[aViewName]];
3386 if (_ephemeralSubviewsForNames[aViewName])
3390 if (_ephemeralSubviewsForNames[aViewName])
3391 [_ephemeralSubviewsForNames[aViewName] setFrame:frame];
3393 else if (_ephemeralSubviewsForNames[aViewName])
3395 [_ephemeralSubviewsForNames[aViewName] removeFromSuperview];
3397 [_ephemeralSubviews removeObject:_ephemeralSubviewsForNames[aViewName]];
3398 delete _ephemeralSubviewsForNames[aViewName];
3401 return _ephemeralSubviewsForNames[aViewName];
3406 if (!_ephemeralSubviewsForNames)
3409 return (_ephemeralSubviewsForNames[aViewName] || nil);
3424 return [_superview effectiveAppearance];
3429 if ([_appearance
isEqual:anAppearance])
3432 [
self willChangeValueForKey:@"appearance"];
3433 _appearance = anAppearance;
3434 [
self didChangeValueForKey:@"appearance"];
3441 - (void)_recomputeAppearance
3483 for (var i = 0, size = [_subviews count]; i < size; i++)
3485 [[_subviews objectAtIndex:i] _recomputeAppearance];
3503 if (!trackingArea || [_trackingAreas containsObjectIdenticalTo:trackingArea])
3506 if ([trackingArea view])
3507 [
CPException raise:CPInternalInconsistencyException
reason:"Tracking area has already been added to another view."];
3509 [_trackingAreas addObject:trackingArea];
3513 [_window _addTrackingArea:trackingArea];
3515 [trackingArea _updateWindowRect];
3524 if (![_trackingAreas containsObjectIdenticalTo:trackingArea])
3525 [
CPException raise:CPInternalInconsistencyException
reason:"Trying to remove unreferenced trackingArea"];
3527 [
self _removeTrackingArea:trackingArea];
3566 while (_trackingAreas.length > 0)
3567 [
self _removeTrackingArea:_trackingAreas[0]];
3575 [_window _removeTrackingArea:trackingArea];
3578 [_trackingAreas removeObjectIdenticalTo:trackingArea];
3581 - (void)_updateTrackingAreasWithRecursion:(BOOL)shouldCallRecursively
3583 _inhibitUpdateTrackingAreas = YES;
3585 [
self _updateTrackingAreasForOwners:[
self _calcTrackingAreaOwners]];
3587 if (shouldCallRecursively)
3591 for (var i = 0; i < _subviews.length; i++)
3592 [_subviews[i] _updateTrackingAreasWithRecursion:YES];
3595 _inhibitUpdateTrackingAreas = NO;
3598 - (CPArray)_calcTrackingAreaOwners
3606 for (var i = 0; i < _trackingAreas.length; i++)
3608 var trackingArea = _trackingAreas[i];
3611 [trackingArea _updateWindowRect];
3615 var owner = [trackingArea owner];
3617 if (![owners containsObjectIdenticalTo:owner])
3618 [owners addObject:owner];
3625 - (void)_updateTrackingAreasForOwners:(CPArray)owners
3627 for (var i = 0; i < owners.length; i++)
3669 _DOMElement = DOMElementPrototype.cloneNode(
false);
3670 AppKitTagDOMElement(
self, _DOMElement);
3674 _frame = [aCoder decodeRectForKey:CPViewFrameKey];
3675 _bounds = [aCoder decodeRectForKey:CPViewBoundsKey];
3677 self = [
super initWithCoder:aCoder];
3681 _trackingAreas = [aCoder decodeObjectForKey:CPViewTrackingAreasKey];
3683 if (!_trackingAreas)
3684 _trackingAreas = [];
3687 _tag = [aCoder containsValueForKey:CPViewTagKey] ? [aCoder decodeIntForKey:CPViewTagKey] : -1;
3688 _identifier = [aCoder decodeObjectForKey:CPReuseIdentifierKey];
3690 _window = [aCoder decodeObjectForKey:CPViewWindowKey];
3691 _superview = [aCoder decodeObjectForKey:CPViewSuperviewKey];
3696 var
subviews = [aCoder decodeObjectForKey:CPViewSubviewsKey] || [];
3698 for (var i = 0, count = [subviews count]; i < count; ++i)
3701 subviews[i]._superview = nil;
3706 _registeredDraggedTypes = [CPSet set];
3707 _registeredDraggedTypesArray = [];
3711 if (_autoresizingMask === nil)
3712 _autoresizingMask = [aCoder decodeIntForKey:CPViewAutoresizingMaskKey] ||
CPViewNotSizable;
3714 _autoresizesSubviews = ![aCoder containsValueForKey:CPViewAutoresizesSubviewsKey] || [aCoder decodeBoolForKey:CPViewAutoresizesSubviewsKey];
3716 _hitTests = ![aCoder containsValueForKey:CPViewHitTestsKey] || [aCoder decodeBoolForKey:CPViewHitTestsKey];
3718 _toolTip = [aCoder decodeObjectForKey:CPViewToolTipKey];
3721 [
self _installToolTipEventHandlers];
3723 _scaleSize = [aCoder containsValueForKey:CPViewScaleKey] ? [aCoder decodeSizeForKey:CPViewScaleKey] : CGSizeMake(1.0, 1.0);
3724 _hierarchyScaleSize = [aCoder containsValueForKey:CPViewSizeScaleKey] ? [aCoder decodeSizeForKey:CPViewSizeScaleKey] : CGSizeMake(1.0, 1.0);
3725 _isScaled = [aCoder containsValueForKey:CPViewIsScaledKey] ? [aCoder decodeBoolForKey:CPViewIsScaledKey] : NO;
3729 _DOMImageParts = [];
3730 _DOMImageSizes = [];
3732 CPDOMDisplayServerSetStyleLeftTop(_DOMElement, NULL, CGRectGetMinX(_frame), CGRectGetMinY(_frame));
3733 [
self _setDisplayServerSetStyleSize:_frame.size];
3736 count = _subviews.length;
3738 for (; index < count; ++index)
3740 CPDOMDisplayServerAppendChild(_DOMElement, _subviews[index]._DOMElement);
3745 [
self setHidden:[aCoder decodeBoolForKey:CPViewIsHiddenKey]];
3746 _isHiddenOrHasHiddenAncestor = NO;
3749 [
self setAlphaValue:[aCoder decodeIntForKey:CPViewOpacityKey]];
3754 [
self _setupViewFlags];
3755 [
self _decodeThemeObjectsWithCoder:aCoder];
3757 [
self setAppearance:[aCoder decodeObjectForKey:CPViewAppearanceKey]];
3772 [
super encodeWithCoder:aCoder];
3775 [aCoder encodeInt:_tag forKey:CPViewTagKey];
3777 [aCoder encodeRect:_frame forKey:CPViewFrameKey];
3778 [aCoder encodeRect:_bounds forKey:CPViewBoundsKey];
3781 if (_window !== nil)
3782 [aCoder encodeConditionalObject:_window forKey:CPViewWindowKey];
3784 var count = [_subviews count],
3785 encodedSubviews = _subviews;
3787 if (count > 0 && [_ephemeralSubviews count] > 0)
3789 encodedSubviews = [encodedSubviews copy];
3792 if ([_ephemeralSubviews containsObject:encodedSubviews[count]])
3793 encodedSubviews.splice(count, 1);
3796 if (encodedSubviews.length > 0)
3797 [aCoder encodeObject:encodedSubviews forKey:CPViewSubviewsKey];
3800 if (_superview !== nil)
3801 [aCoder encodeConditionalObject:_superview forKey:CPViewSuperviewKey];
3804 [aCoder encodeInt:_autoresizingMask forKey:CPViewAutoresizingMaskKey];
3806 if (!_autoresizesSubviews)
3807 [aCoder encodeBool:_autoresizesSubviews forKey:CPViewAutoresizesSubviewsKey];
3809 if (_backgroundColor !== nil)
3810 [aCoder encodeObject:_backgroundColor forKey:CPViewBackgroundColorKey];
3812 if (_hitTests !== YES)
3813 [aCoder encodeBool:_hitTests forKey:CPViewHitTestsKey];
3815 if (_opacity !== 1.0)
3816 [aCoder encodeFloat:_opacity forKey:CPViewOpacityKey];
3819 [aCoder encodeBool:_isHidden forKey:CPViewIsHiddenKey];
3822 [aCoder encodeObject:_toolTip forKey:CPViewToolTipKey];
3827 [aCoder encodeConditionalObject:nextKeyView forKey:CPViewNextKeyViewKey];
3832 [aCoder encodeConditionalObject:previousKeyView forKey:CPViewPreviousKeyViewKey];
3834 [
self _encodeThemeObjectsWithCoder:aCoder];
3837 [aCoder encodeObject:_identifier forKey:CPReuseIdentifierKey];
3839 [aCoder encodeSize:[
self scaleSize] forKey:CPViewScaleKey];
3840 [aCoder encodeSize:[
self _hierarchyScaleSize] forKey:CPViewSizeScaleKey];
3841 [aCoder encodeBool:_isScaled forKey:CPViewIsScaledKey];
3842 [aCoder encodeObject:_appearance forKey:CPViewAppearanceKey];
3843 [aCoder encodeObject:_trackingAreas forKey:CPViewTrackingAreasKey];
3848 var _CPViewFullScreenModeStateMake =
function(aView)
3852 return {
autoresizingMask:aView._autoresizingMask,
frame:CGRectMakeCopy(aView._frame), index:(superview ? [superview._subviews indexOfObjectIdenticalTo:aView] : 0), superview:superview };
3855 var _CPViewGetTransform =
function( fromView, toView)
3864 var view = fromView;
3869 while (view && view != toView)
3871 var
frame = view._frame;
3879 transform.tx += CGRectGetMinX(frame);
3880 transform.ty += CGRectGetMinY(frame);
3882 if (view._boundsTransform)
3895 view = view._superview;
3899 if (view === toView)
3903 else if (fromView && toView)
3905 fromWindow = [fromView window];
3906 toWindow = [toView window];
3908 if (fromWindow && toWindow && fromWindow !== toWindow)
3917 while (view && view != fromView)
3919 var
frame = CGRectMakeCopy(view._frame);
3924 transform2.a *= 1 / view._scaleSize.width;
3925 transform2.d *= 1 / view._scaleSize.height;
3928 transform2.tx += CGRectGetMinX(frame) * transform2.a;
3929 transform2.ty += CGRectGetMinY(frame) * transform2.d;
3931 if (view._boundsTransform)
3934 inverseBoundsTransform.tx -= view._inverseBoundsTransform.tx * transform2.a;
3935 inverseBoundsTransform.ty -= view._inverseBoundsTransform.ty * transform2.d;
3940 view = view._superview;
3943 transform2.tx = -transform2.tx;
3944 transform2.ty = -transform2.ty;
3946 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 postNotificationName:object:userInfo:(CPString aNotificationName, [object] id anObject, [userInfo] CPDictionary aUserInfo)
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