-
Notifications
You must be signed in to change notification settings - Fork 336
/
CPView.j
2713 lines (2160 loc) · 75.5 KB
/
CPView.j
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*
* CPView.j
* AppKit
*
* Created by Francisco Tolmasky.
* Copyright 2008, 280 North, Inc.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
@import <Foundation/CPArray.j>
@import <Foundation/CPObjJRuntime.j>
@import "CGAffineTransform.j"
@import "CGGeometry.j"
@import "CPColor.j"
@import "CPGeometry.j"
@import "CPGraphicsContext.j"
@import "CPResponder.j"
@import "CPTheme.j"
@import "_CPDisplayServer.j"
#include "Platform/Platform.h"
#include "CoreGraphics/CGAffineTransform.h"
#include "CoreGraphics/CGGeometry.h"
#include "Platform/DOM/CPDOMDisplayServer.h"
/*
@global
@group CPViewAutoresizingMasks
The default resizingMask, the view will not resize or reposition itself.
*/
CPViewNotSizable = 0;
/*
@global
@group CPViewAutoresizingMasks
Allow for flexible space on the left hand side of the view.
*/
CPViewMinXMargin = 1;
/*
@global
@group CPViewAutoresizingMasks
The view should grow and shrink horizontally with its parent view.
*/
CPViewWidthSizable = 2;
/*
@global
@group CPViewAutoresizingMasks
Allow for flexible space to the right hand side of the view.
*/
CPViewMaxXMargin = 4;
/*
@global
@group CPViewAutoresizingMasks
Allow for flexible space above the view.
*/
CPViewMinYMargin = 8;
/*
@global
@group CPViewAutoresizingMasks
The view should grow and shrink vertically with its parent view.
*/
CPViewHeightSizable = 16;
/*
@global
@group CPViewAutoresizingMasks
Allow for flexible space below the view.
*/
CPViewMaxYMargin = 32;
CPViewBoundsDidChangeNotification = @"CPViewBoundsDidChangeNotification";
CPViewFrameDidChangeNotification = @"CPViewFrameDidChangeNotification";
var CachedNotificationCenter = nil,
CachedThemeAttributes = nil;
#if PLATFORM(DOM)
var DOMElementPrototype = nil,
BackgroundTrivialColor = 0,
BackgroundVerticalThreePartImage = 1,
BackgroundHorizontalThreePartImage = 2,
BackgroundNinePartImage = 3,
BackgroundTransparentColor = 4;
#endif
var CPViewFlags = { },
CPViewHasCustomDrawRect = 1 << 0,
CPViewHasCustomLayoutSubviews = 1 << 1;
/*!
@ingroup appkit
@class CPView
<p>CPView is a class which provides facilities for drawing
in a window and receiving events. It is the superclass of many of the visual
elements of the GUI.</p>
<p>In order to display itself, a view must be placed in a window (represented by an
CPWindow object). Within the window is a hierarchy of CPViews,
headed by the window's content view. Every other view in a window is a descendant
of this view.</p>
<p>Subclasses can override \c -drawRect: in order to implement their
appearance. Other methods of CPView and CPResponder can
also be overridden to handle user generated events.
*/
@implementation CPView : CPResponder
{
CPWindow _window;
CPView _superview;
CPArray _subviews;
CPGraphicsContext _graphicsContext;
int _tag;
CGRect _frame;
CGRect _bounds;
CGAffineTransform _boundsTransform;
CGAffineTransform _inverseBoundsTransform;
CPSet _registeredDraggedTypes;
CPArray _registeredDraggedTypesArray;
BOOL _isHidden;
BOOL _hitTests;
BOOL _clipsToBounds;
BOOL _postsFrameChangedNotifications;
BOOL _postsBoundsChangedNotifications;
BOOL _inhibitFrameAndBoundsChangedNotifications;
#if PLATFORM(DOM)
DOMElement _DOMElement;
DOMElement _DOMContentsElement;
CPArray _DOMImageParts;
CPArray _DOMImageSizes;
unsigned _backgroundType;
#endif
CGRect _dirtyRect;
float _opacity;
CPColor _backgroundColor;
BOOL _autoresizesSubviews;
unsigned _autoresizingMask;
CALayer _layer;
BOOL _wantsLayer;
// Full Screen State
BOOL _isInFullScreenMode;
_CPViewFullScreenModeState _fullScreenModeState;
// Layout Support
BOOL _needsLayout;
JSObject _ephemeralSubviews;
// Theming Support
CPTheme _theme;
JSObject _themeAttributes;
unsigned _themeState;
JSObject _ephemeralSubviewsForNames;
CPSet _ephereralSubviews;
// Key View Support
CPView _nextKeyView;
CPView _previousKeyView;
unsigned _viewClassFlags;
}
/*
Private method for Objective-J.
@ignore
*/
+ (void)initialize
{
if (self !== [CPView class])
return;
#if PLATFORM(DOM)
DOMElementPrototype = document.createElement("div");
var style = DOMElementPrototype.style;
style.overflow = "hidden";
style.position = "absolute";
style.visibility = "visible";
style.zIndex = 0;
#endif
CachedNotificationCenter = [CPNotificationCenter defaultCenter];
}
- (void)setupViewFlags
{
var theClass = [self class],
classUID = [theClass UID];
if (CPViewFlags[classUID] === undefined)
{
var flags = 0;
if ([theClass instanceMethodForSelector:@selector(drawRect:)] !== [CPView instanceMethodForSelector:@selector(drawRect:)])
flags |= CPViewHasCustomDrawRect;
if ([theClass instanceMethodForSelector:@selector(layoutSubviews)] !== [CPView instanceMethodForSelector:@selector(layoutSubviews)])
flags |= CPViewHasCustomLayoutSubviews;
CPViewFlags[classUID] = flags;
}
_viewClassFlags = CPViewFlags[classUID];
}
+ (CPSet)keyPathsForValuesAffectingFrame
{
return [CPSet setWithObjects:@"frameOrigin", @"frameSize"];
}
+ (CPSet)keyPathsForValuesAffectingBounds
{
return [CPSet setWithObjects:@"boundsOrigin", @"boundsSize"];
}
+ (CPMenu)defaultMenu
{
return nil;
}
- (id)init
{
return [self initWithFrame:CGRectMakeZero()];
}
/*!
Initializes the receiver for usage with the specified bounding rectangle
@return the initialized view
*/
- (id)initWithFrame:(CGRect)aFrame
{
self = [super init];
if (self)
{
var width = _CGRectGetWidth(aFrame),
height = _CGRectGetHeight(aFrame);
_subviews = [];
_registeredDraggedTypes = [CPSet set];
_registeredDraggedTypesArray = [];
_tag = -1;
_frame = _CGRectMakeCopy(aFrame);
_bounds = _CGRectMake(0.0, 0.0, width, height);
_autoresizingMask = CPViewNotSizable;
_autoresizesSubviews = YES;
_clipsToBounds = YES;
_opacity = 1.0;
_isHidden = NO;
_hitTests = YES;
#if PLATFORM(DOM)
_DOMElement = DOMElementPrototype.cloneNode(false);
CPDOMDisplayServerSetStyleLeftTop(_DOMElement, NULL, _CGRectGetMinX(aFrame), _CGRectGetMinY(aFrame));
CPDOMDisplayServerSetStyleSize(_DOMElement, width, height);
_DOMImageParts = [];
_DOMImageSizes = [];
#endif
_theme = [CPTheme defaultTheme];
_themeState = CPThemeStateNormal;
[self setupViewFlags];
[self _loadThemeAttributes];
}
return self;
}
/*!
Returns the container view of the receiver
@return the receiver's containing view
*/
- (CPView)superview
{
return _superview;
}
/*!
Returns an array of all the views contained as direct children of the receiver
@return an array of CPViews
*/
- (CPArray)subviews
{
return [_subviews copy];
}
/*!
Returns the window containing this receiver
*/
- (CPWindow)window
{
return _window;
}
/*!
Makes the argument a subview of the receiver.
@param aSubview the CPView to make a subview
*/
- (void)addSubview:(CPView)aSubview
{
[self _insertSubview:aSubview atIndex:CPNotFound];
}
/*!
Makes \c aSubview a subview of the receiver. It is positioned relative to \c anotherView
@param aSubview the view to add as a subview
@param anOrderingMode specifies \c aSubview's ordering relative to \c anotherView
@param anotherView \c aSubview will be positioned relative to this argument
*/
- (void)addSubview:(CPView)aSubview positioned:(CPWindowOrderingMode)anOrderingMode relativeTo:(CPView)anotherView
{
var index = anotherView ? [_subviews indexOfObjectIdenticalTo:anotherView] : CPNotFound;
// In other words, if no view, then either all the way at the bottom or all the way at the top.
if (index === CPNotFound)
index = (anOrderingMode === CPWindowAbove) ? [_subviews count] : 0;
// else, if we have a view, above if above.
else if (anOrderingMode === CPWindowAbove)
++index;
[self _insertSubview:aSubview atIndex:index];
}
/* @ignore */
- (void)_insertSubview:(CPView)aSubview atIndex:(int)anIndex
{
// We will have to adjust the z-index of all views starting at this index.
var count = _subviews.length;
// dirty the key view loop, in case the window wants to auto recalculate it
[[self window] _dirtyKeyViewLoop];
// If this is already one of our subviews, remove it.
if (aSubview._superview == self)
{
var index = [_subviews indexOfObjectIdenticalTo:aSubview];
// FIXME: should this be anIndex >= count? (last one)
if (index === anIndex || index === count - 1 && anIndex === count)
return;
[_subviews removeObjectAtIndex:index];
#if PLATFORM(DOM)
CPDOMDisplayServerRemoveChild(_DOMElement, aSubview._DOMElement);
#endif
if (anIndex > index)
--anIndex;
//We've effectively made the subviews array shorter, so represent that.
--count;
}
else
{
// Remove the view from its previous superview.
[aSubview removeFromSuperview];
// Set the subview's window to our own.
[aSubview _setWindow:_window];
// Notify the subview that it will be moving.
[aSubview viewWillMoveToSuperview:self];
// Set ourselves as the superview.
aSubview._superview = self;
}
if (anIndex === CPNotFound || anIndex >= count)
{
_subviews.push(aSubview);
#if PLATFORM(DOM)
// Attach the actual node.
CPDOMDisplayServerAppendChild(_DOMElement, aSubview._DOMElement);
#endif
}
else
{
_subviews.splice(anIndex, 0, aSubview);
#if PLATFORM(DOM)
// Attach the actual node.
CPDOMDisplayServerInsertBefore(_DOMElement, aSubview._DOMElement, _subviews[anIndex + 1]._DOMElement);
#endif
}
[aSubview setNextResponder:self];
[aSubview viewDidMoveToSuperview];
[self didAddSubview:aSubview];
}
/*!
Called when the receiver has added \c aSubview to it's child views.
@param aSubview the view that was added
*/
- (void)didAddSubview:(CPView)aSubview
{
}
/*!
Removes the receiver from it's container view and window.
Does nothing if there's no container view.
*/
- (void)removeFromSuperview
{
if (!_superview)
return;
// dirty the key view loop, in case the window wants to auto recalculate it
[[self window] _dirtyKeyViewLoop];
[_superview willRemoveSubview:self];
[_superview._subviews removeObject:self];
#if PLATFORM(DOM)
CPDOMDisplayServerRemoveChild(_superview._DOMElement, _DOMElement);
#endif
_superview = nil;
[self _setWindow:nil];
}
/*!
Replaces the specified child view with another view
@param aSubview the view to replace
@param aView the replacement view
*/
- (void)replaceSubview:(CPView)aSubview with:(CPView)aView
{
if (aSubview._superview != self)
return;
var index = [_subviews indexOfObjectIdenticalTo:aSubview];
[aSubview removeFromSuperview];
[self _insertSubview:aView atIndex:index];
}
- (void)setSubviews:(CPArray)newSubviews
{
if (!newSubviews)
[CPException raise:CPInvalidArgumentException reason:"newSubviews cannot be nil in -[CPView setSubviews:]"];
// Trivial Case 0: Same array somehow
if ([_subviews isEqual:newSubviews])
return;
// Trivial Case 1: No current subviews, simply add all new subviews.
if ([_subviews count] === 0)
{
var index = 0,
count = [newSubviews count];
for (; index < count; ++index)
[self addSubview:newSubviews[index]];
return;
}
// Trivial Case 2: No new subviews, simply remove all current subviews.
if ([newSubviews count] === 0)
{
var count = [_subviews count];
while (count--)
[_subviews[count] removeFromSuperview];
return;
}
// Find out the views that were removed.
var removedSubviews = [CPMutableSet setWithArray:_subviews];
[removedSubviews removeObjectsInArray:newSubviews];
[removedSubviews makeObjectsPerformSelector:@selector(removeFromSuperview)];
// Find out which views need to be added.
var addedSubviews = [CPMutableSet setWithArray:newSubviews];
[addedSubviews removeObjectsInArray:_subviews];
var addedSubview = nil,
addedSubviewEnumerator = [addedSubviews objectEnumerator];
while (addedSubview = [addedSubviewEnumerator nextObject])
[self addSubview:addedSubview];
// If the order is fine, no need to reorder.
if ([_subviews isEqual:newSubviews])
return;
_subviews = [newSubviews copy];
#if PLATFORM(DOM)
var index = 0,
count = [_subviews count];
for (; index < count; ++index)
{
var subview = _subviews[index];
CPDOMDisplayServerRemoveChild(_DOMElement, subview._DOMElement);
CPDOMDisplayServerAppendChild(_DOMElement, subview._DOMElement);
}
#endif
}
/* @ignore */
- (void)_setWindow:(CPWindow)aWindow
{
if (_window === aWindow)
return;
[[self window] _dirtyKeyViewLoop];
// Clear out first responder if we're the first responder and leaving.
if ([_window firstResponder] === self)
[_window makeFirstResponder:nil];
// Notify the view and its subviews
[self viewWillMoveToWindow:aWindow];
// Unregister the drag events from the current window and register
// them in the new window.
if (_registeredDraggedTypes)
{
[_window _noteUnregisteredDraggedTypes:_registeredDraggedTypes];
[aWindow _noteRegisteredDraggedTypes:_registeredDraggedTypes];
}
_window = aWindow;
var count = [_subviews count];
while (count--)
[_subviews[count] _setWindow:aWindow];
[self viewDidMoveToWindow];
[[self window] _dirtyKeyViewLoop];
}
/*!
Returns \c YES if the receiver is, or is a descendant of, \c aView.
@param aView the view to test for ancestry
*/
- (BOOL)isDescendantOf:(CPView)aView
{
var view = self;
do
{
if (view == aView)
return YES;
} while(view = [view superview])
return NO;
}
/*!
Called when the receiver's superview has changed.
*/
- (void)viewDidMoveToSuperview
{
// if (_graphicsContext)
[self setNeedsDisplay:YES];
}
/*!
Called when the receiver has been moved to a new CPWindow.
*/
- (void)viewDidMoveToWindow
{
}
/*!
Called when the receiver is about to be moved to a new view.
@param aView the view to which the receiver will be moved
*/
- (void)viewWillMoveToSuperview:(CPView)aView
{
}
/*!
Called when the receiver is about to be moved to a new window.
@param aWindow the window to which the receiver will be moved.
*/
- (void)viewWillMoveToWindow:(CPWindow)aWindow
{
}
/*!
Called when the receiver is about to be remove one of its subviews.
@param aView the view that will be removed
*/
- (void)willRemoveSubview:(CPView)aView
{
}
/*!
Returns the menu item containing the receiver or one of its ancestor views.
@return a menu item, or \c nil if the view or one of its ancestors wasn't found
*/
- (CPMenuItem)enclosingMenuItem
{
var view = self;
while (view && ![view isKindOfClass:[_CPMenuItemView class]])
view = [view superview];
if (view)
return view._menuItem;
return nil;
/* var view = self,
enclosingMenuItem = _enclosingMenuItem;
while (!enclosingMenuItem && (view = view._enclosingMenuItem))
view = [view superview];
return enclosingMenuItem;*/
}
- (void)setTag:(CPInteger)aTag
{
_tag = aTag;
}
- (CPInteger)tag
{
return _tag;
}
- (CPView)viewWithTag:(CPInteger)aTag
{
if ([self tag] == aTag)
return self;
var index = 0,
count = _subviews.length;
for (; index < count; ++index)
{
var view = [_subviews[index] viewWithTag:aTag];
if (view)
return view;
}
return nil;
}
/*!
Returns whether the view is flipped.
@return \c YES if the view is flipped. \c NO, otherwise.
*/
- (BOOL)isFlipped
{
return YES;
}
/*!
Sets the frame size of the receiver to the dimensions and origin of the provided rectangle in the coordinate system
of the superview. The method also posts an CPViewFrameDidChangeNotification to the notification
center if the receiver is configured to do so. If the frame is the same as the current frame, the method simply
returns (and no notificaion is posted).
@param aFrame the rectangle specifying the new origin and size of the receiver
*/
- (void)setFrame:(CGRect)aFrame
{
if (_CGRectEqualToRect(_frame, aFrame))
return;
_inhibitFrameAndBoundsChangedNotifications = YES;
[self setFrameOrigin:aFrame.origin];
[self setFrameSize:aFrame.size];
_inhibitFrameAndBoundsChangedNotifications = NO;
if (_postsFrameChangedNotifications)
[CachedNotificationCenter postNotificationName:CPViewFrameDidChangeNotification object:self];
}
/*!
Returns the receiver's frame.
@return a copy of the receiver's frame
*/
- (CGRect)frame
{
return _CGRectMakeCopy(_frame);
}
- (CGPoint)frameOrigin
{
return _CGPointMakeCopy(_frame.origin);
}
- (CGSize)frameSize
{
return _CGSizeMakeCopy(_frame.size);
}
/*!
Moves the center of the receiver's frame to the provided point. The point is defined in the superview's coordinate system.
The method posts a CPViewFrameDidChangeNotification to the default notification center if the receiver
is configured to do so. If the specified origin is the same as the frame's current origin, the method will
simply return (and no notification will be posted).
@param aPoint the new origin point
*/
- (void)setCenter:(CGPoint)aPoint
{
[self setFrameOrigin:CGPointMake(aPoint.x - _frame.size.width / 2.0, aPoint.y - _frame.size.height / 2.0)];
}
/*!
Returns the center of the receiver's frame to the provided point. The point is defined in the superview's coordinate system.
@return CGPoint the center point of the receiver's frame
*/
- (CGPoint)center
{
return CGPointMake(_frame.size.width / 2.0 + _frame.origin.x, _frame.size.height / 2.0 + _frame.origin.y);
}
/*!
Sets the receiver's frame origin to the provided point. The point is defined in the superview's coordinate system.
The method posts a CPViewFrameDidChangeNotification to the default notification center if the receiver
is configured to do so. If the specified origin is the same as the frame's current origin, the method will
simply return (and no notification will be posted).
@param aPoint the new origin point
*/
- (void)setFrameOrigin:(CGPoint)aPoint
{
var origin = _frame.origin;
if (!aPoint || _CGPointEqualToPoint(origin, aPoint))
return;
origin.x = aPoint.x;
origin.y = aPoint.y;
if (_postsFrameChangedNotifications && !_inhibitFrameAndBoundsChangedNotifications)
[CachedNotificationCenter postNotificationName:CPViewFrameDidChangeNotification object:self];
#if PLATFORM(DOM)
var transform = _superview ? _superview._boundsTransform : NULL;
CPDOMDisplayServerSetStyleLeftTop(_DOMElement, transform, origin.x, origin.y);
#endif
}
/*!
Sets the receiver's frame size. If \c aSize is the same as the frame's current dimensions, this
method simply returns. The method posts a CPViewFrameDidChangeNotification to the
default notification center if the receiver is configured to do so.
@param aSize the new size for the frame
*/
- (void)setFrameSize:(CGSize)aSize
{
var size = _frame.size;
if (!aSize || _CGSizeEqualToSize(size, aSize))
return;
var oldSize = _CGSizeMakeCopy(size);
size.width = aSize.width;
size.height = aSize.height;
if (YES)
{
_bounds.size.width = aSize.width;
_bounds.size.height = aSize.height;
}
if (_layer)
[_layer _owningViewBoundsChanged];
if (_autoresizesSubviews)
[self resizeSubviewsWithOldSize:oldSize];
[self setNeedsLayout];
[self setNeedsDisplay:YES];
#if PLATFORM(DOM)
CPDOMDisplayServerSetStyleSize(_DOMElement, size.width, size.height);
if (_DOMContentsElement)
{
CPDOMDisplayServerSetSize(_DOMContentsElement, size.width, size.height);
CPDOMDisplayServerSetStyleSize(_DOMContentsElement, size.width, size.height);
}
if (_backgroundType !== BackgroundTrivialColor)
{
if (_backgroundType === BackgroundTransparentColor)
{
CPDOMDisplayServerSetStyleSize(_DOMImageParts[0], size.width, size.height);
}
else
{
var images = [[_backgroundColor patternImage] imageSlices];
if (_backgroundType === BackgroundVerticalThreePartImage)
{
CPDOMDisplayServerSetStyleSize(_DOMImageParts[1], size.width, size.height - _DOMImageSizes[0].height - _DOMImageSizes[2].height);
}
else if (_backgroundType === BackgroundHorizontalThreePartImage)
{
CPDOMDisplayServerSetStyleSize(_DOMImageParts[1], size.width - _DOMImageSizes[0].width - _DOMImageSizes[2].width, size.height);
}
else if (_backgroundType === BackgroundNinePartImage)
{
var width = size.width - _DOMImageSizes[0].width - _DOMImageSizes[2].width,
height = size.height - _DOMImageSizes[0].height - _DOMImageSizes[6].height;
CPDOMDisplayServerSetStyleSize(_DOMImageParts[1], width, _DOMImageSizes[0].height);
CPDOMDisplayServerSetStyleSize(_DOMImageParts[3], _DOMImageSizes[3].width, height);
CPDOMDisplayServerSetStyleSize(_DOMImageParts[4], width, height);
CPDOMDisplayServerSetStyleSize(_DOMImageParts[5], _DOMImageSizes[5].width, height);
CPDOMDisplayServerSetStyleSize(_DOMImageParts[7], width, _DOMImageSizes[7].height);
}
}
}
#endif
if (_postsFrameChangedNotifications && !_inhibitFrameAndBoundsChangedNotifications)
[CachedNotificationCenter postNotificationName:CPViewFrameDidChangeNotification object:self];
}
/*!
Sets the receiver's bounds. The bounds define the size and location of the receiver inside it's frame. Posts a
CPViewBoundsDidChangeNotification to the default notification center if the receiver is configured to do so.
@param bounds the new bounds
*/
- (void)setBounds:(CGRect)bounds
{
if (_CGRectEqualToRect(_bounds, bounds))
return;
_inhibitFrameAndBoundsChangedNotifications = YES;
[self setBoundsOrigin:bounds.origin];
[self setBoundsSize:bounds.size];
_inhibitFrameAndBoundsChangedNotifications = NO;
if (_postsBoundsChangedNotifications)
[CachedNotificationCenter postNotificationName:CPViewBoundsDidChangeNotification object:self];
}
/*!
Returns the receiver's bounds. The bounds define the size
and location of the receiver inside its frame.
*/
- (CGRect)bounds
{
return _CGRectMakeCopy(_bounds);
}
- (CGPoint)boundsOrigin
{
return _CGPointMakeCopy(_bounds.origin);
}
- (CGSize)boundsSize
{
return _CGSizeMakeCopy(_bounds.size);
}
/*!
Sets the location of the receiver inside its frame. The method
posts a CPViewBoundsDidChangeNotification to the
default notification center if the receiver is configured to do so.
@param aPoint the new location for the receiver
*/
- (void)setBoundsOrigin:(CGPoint)aPoint
{
var origin = _bounds.origin;
if (_CGPointEqualToPoint(origin, aPoint))
return;
origin.x = aPoint.x;
origin.y = aPoint.y;
if (origin.x != 0 || origin.y != 0)
{
_boundsTransform = _CGAffineTransformMakeTranslation(-origin.x, -origin.y);
_inverseBoundsTransform = CGAffineTransformInvert(_boundsTransform);
}
else
{
_boundsTransform = nil;
_inverseBoundsTransform = nil;
}
#if PLATFORM(DOM)
var index = _subviews.length;
while (index--)
{
var view = _subviews[index],
origin = view._frame.origin;
CPDOMDisplayServerSetStyleLeftTop(view._DOMElement, _boundsTransform, origin.x, origin.y);
}
#endif
if (_postsBoundsChangedNotifications && !_inhibitFrameAndBoundsChangedNotifications)
[CachedNotificationCenter postNotificationName:CPViewBoundsDidChangeNotification object:self];
}
/*!
Sets the receiver's size inside its frame. The method posts a
CPViewBoundsDidChangeNotification to the default
notification center if the receiver is configured to do so.
@param aSize the new size for the receiver
*/
- (void)setBoundsSize:(CGSize)aSize
{
var size = _bounds.size;
if (_CGSizeEqualToSize(size, aSize))
return;
var frameSize = _frame.size;
if (!_CGSizeEqualToSize(size, frameSize))
{
var origin = _bounds.origin;
origin.x /= size.width / frameSize.width;
origin.y /= size.height / frameSize.height;
}
size.width = aSize.width;
size.height = aSize.height;
if (!_CGSizeEqualToSize(size, frameSize))
{
var origin = _bounds.origin;
origin.x *= size.width / frameSize.width;
origin.y *= size.height / frameSize.height;
}
if (_postsBoundsChangedNotifications && !_inhibitFrameAndBoundsChangedNotifications)
[CachedNotificationCenter postNotificationName:CPViewBoundsDidChangeNotification object:self];
}
/*!
Notifies subviews that the superview changed size.
@param aSize the size of the old superview