00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023 @import <Foundation/CPArray.j>
00024 @import <Foundation/CPObject.j>
00025
00026 #include "CPDOMDisplayServer.h"
00027
00028
00029 @implementation CPDOMWindowLayer : CPObject
00030 {
00031 int _level;
00032 CPArray _windows;
00033 DOMElement _DOMElement;
00034 }
00035
00036 - (id)initWithLevel:(int)aLevel
00037 {
00038 self = [super init];
00039
00040 if (self)
00041 {
00042 _level = aLevel;
00043
00044 _windows = [];
00045
00046 _DOMElement = document.createElement("div");
00047 _DOMElement.style.position = "absolute";
00048 _DOMElement.style.top = "0px";
00049 _DOMElement.style.left = "0px";
00050 _DOMElement.style.width = "1px";
00051 _DOMElement.style.height = "1px";
00052 }
00053
00054 return self;
00055 }
00056
00057 - (int)level
00058 {
00059 return _level;
00060 }
00061
00062 - (void)removeWindow:(CPWindow)aWindow
00063 {
00064 var index = aWindow._index,
00065 count = _windows.length - 1;
00066
00067 CPDOMDisplayServerRemoveChild(_DOMElement, aWindow._DOMElement);
00068
00069 [_windows removeObjectAtIndex:aWindow._index];
00070
00071 for (; index < count; ++index)
00072 {
00073 _windows[index]._index = index;
00074 _windows[index]._DOMElement.style.zIndex = index;
00075 }
00076
00077 aWindow._isVisible = NO;
00078 }
00079
00080 - (void)insertWindow:(CPWindow)aWindow atIndex:(unsigned)anIndex
00081 {
00082
00083 var count = [_windows count],
00084 zIndex = (anIndex == CPNotFound ? count : anIndex),
00085 isVisible = aWindow._isVisible;
00086
00087
00088 if (isVisible)
00089 {
00090 zIndex = MIN(zIndex, aWindow._index);
00091 [_windows removeObjectAtIndex:aWindow._index];
00092 }
00093 else
00094 ++count;
00095
00096 if (anIndex == CPNotFound || anIndex >= count)
00097 [_windows addObject:aWindow];
00098 else
00099 [_windows insertObject:aWindow atIndex:anIndex];
00100
00101
00102 for (; zIndex < count; ++zIndex)
00103 {
00104 _windows[zIndex]._index = zIndex;
00105 _windows[zIndex]._DOMElement.style.zIndex = zIndex;
00106 }
00107
00108 if (!isVisible)
00109 {
00110 CPDOMDisplayServerAppendChild(_DOMElement, aWindow._DOMElement);
00111
00112 aWindow._isVisible = YES;
00113
00114 if ([aWindow styleMask] & CPBorderlessBridgeWindowMask)
00115 [aWindow setFrame:[aWindow._bridge contentBounds]];
00116 }
00117 }
00118
00119 @end