PageRenderTime 16ms CodeModel.GetById 2ms app.highlight 6ms RepoModel.GetById 2ms app.codeStats 0ms

/AppKit/Platform/DOM/CPDOMDisplayServer.h

http://github.com/cacaodev/cappuccino
C Header | 218 lines | 173 code | 24 blank | 21 comment | 25 complexity | 1a7234a02c96d519af86da1b67b4ad3a MD5 | raw file
  1/*
  2 * CPDOMDisplayServer.h
  3 * AppKit
  4 *
  5 * Created by Francisco Tolmasky.
  6 * Copyright 2008, 280 North, Inc.
  7 *
  8 * This library is free software; you can redistribute it and/or
  9 * modify it under the terms of the GNU Lesser General Public
 10 * License as published by the Free Software Foundation; either
 11 * version 2.1 of the License, or (at your option) any later version.
 12 *
 13 * This library is distributed in the hope that it will be useful,
 14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
 16 * Lesser General Public License for more details.
 17 *
 18 * You should have received a copy of the GNU Lesser General Public
 19 * License along with this library; if not, write to the Free Software
 20 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
 21 */
 22
 23#define DOM_OPTIMIZATION 0
 24
 25#define SetStyleOrigin      0
 26#define SetStyleLeftTop     0
 27#define SetStyleRightTop    1
 28#define SetStyleLeftBottom  2
 29#define SetStyleRightBottom 3
 30#define SetStyleSize        4
 31#define SetSize             5
 32#define AppendChild         6
 33#define InsertBefore        7
 34#define RemoveChild         8
 35
 36#define CPDOMDisplayServerSetStyleOrigin(anInstruction, aDOMElement, aTransform, x, y)\
 37    if (!aDOMElement.CPDOMDisplayContext)\
 38        aDOMElement.CPDOMDisplayContext = [];\
 39    var __index = aDOMElement.CPDOMDisplayContext[SetStyleOrigin];\
 40    if (!(__index >= 0))\
 41    {\
 42        __index = aDOMElement.CPDOMDisplayContext[SetStyleOrigin] = CPDOMDisplayServerInstructionCount;\
 43        CPDOMDisplayServerInstructionCount += 5;\
 44    }\
 45    CPDOMDisplayServerInstructions[__index] = anInstruction;\
 46    CPDOMDisplayServerInstructions[__index + 1] = aDOMElement;\
 47    CPDOMDisplayServerInstructions[__index + 2] = aTransform;\
 48    CPDOMDisplayServerInstructions[__index + 3] = x;\
 49    CPDOMDisplayServerInstructions[__index + 4] = y;
 50#if !DOM_OPTIMIZATION
 51#define CPDOMDisplayServerSetStyleLeftTop(aDOMElement, aTransform, aLeft, aTop) \
 52if (aTransform) var ____p = CGPointApplyAffineTransform(CGPointMake(aLeft, aTop), aTransform); \
 53else var ____p = CGPointMake(aLeft, aTop); \
 54aDOMElement.style.left = ROUND(____p.x) + "px";\
 55aDOMElement.style.top = ROUND(____p.y) + "px";
 56
 57#define CPDOMDisplayServerSetStyleRightTop(aDOMElement, aTransform, aRight, aTop) \
 58if (aTransform) var ____p = CGPointApplyAffineTransform(CGPointMake(aRight, aTop), aTransform); \
 59else var ____p = CGPointMake(aRight, aTop); \
 60aDOMElement.style.right = ROUND(____p.x) + "px";\
 61aDOMElement.style.top = ROUND(____p.y) + "px";
 62
 63#define CPDOMDisplayServerSetStyleLeftBottom(aDOMElement, aTransform, aLeft, aBottom) \
 64if (aTransform) var ____p = CGPointApplyAffineTransform(CGPointMake(aLeft, aBottom), aTransform); \
 65else var ____p = CGPointMake(aLeft, aBottom); \
 66aDOMElement.style.left = ROUND(____p.x) + "px";\
 67aDOMElement.style.bottom = ROUND(____p.y) + "px";
 68
 69#define CPDOMDisplayServerSetStyleRightBottom(aDOMElement, aTransform, aRight, aBottom) \
 70if (aTransform) var ____p = CGPointApplyAffineTransform(CGPointMake(aRight, aBottom), aTransform); \
 71else var ____p = CGPointMake(aRight, aBottom); \
 72aDOMElement.style.right = ROUND(____p.x) + "px";\
 73aDOMElement.style.bottom = ROUND(____p.y) + "px";
 74
 75#define CPDOMDisplayServerSetStyleSize(aDOMElement, aWidth, aHeight) \
 76    aDOMElement.style.width = MAX(0.0, ROUND(aWidth)) + "px";\
 77    aDOMElement.style.height = MAX(0.0, ROUND(aHeight)) + "px";
 78
 79#define CPDOMDisplayServerSetSize(aDOMElement, aWidth, aHeight) \
 80    aDOMElement.width = MAX(0.0, ROUND(aWidth));\
 81    aDOMElement.height = MAX(0.0, ROUND(aHeight));
 82
 83#define CPDOMDisplayServerSetStyleBackgroundSize(aDOMElement, aWidth, aHeight)\
 84    aDOMElement.style.backgroundSize = aWidth + ' ' + aHeight;
 85
 86#define CPDOMDisplayServerAppendChild(aParentElement, aChildElement) aParentElement.appendChild(aChildElement)
 87
 88#define CPDOMDisplayServerInsertBefore(aParentElement, aChildElement, aBeforeElement) aParentElement.insertBefore(aChildElement, aBeforeElement)
 89
 90#define CPDOMDisplayServerRemoveChild(aParentElement, aChildElement) aParentElement.removeChild(aChildElement)
 91
 92#define PREPARE_DOM_OPTIMIZATION()
 93#define EXECUTE_DOM_INSTRUCTIONS()
 94
 95#else
 96#define CPDOMDisplayServerSetStyleLeftTop(aDOMElement, aTransform, aLeft, aTop) CPDOMDisplayServerSetStyleOrigin(SetStyleLeftTop, aDOMElement, aTransform, aLeft, aTop)
 97
 98#define CPDOMDisplayServerSetStyleRightTop(aDOMElement, aTransform, aRight, aTop) CPDOMDisplayServerSetStyleOrigin(SetStyleRightTop, aDOMElement, aTransform, aRight, aTop)
 99
100#define CPDOMDisplayServerSetStyleLeftBottom(aDOMElement, aTransform, aLeft, aBottom) CPDOMDisplayServerSetStyleOrigin(SetStyleLeftBottom, aDOMElement, aTransform, aLeft, aBottom)
101
102#define CPDOMDisplayServerSetStyleRightBottom(aDOMElement, aTransform, aRight, aBottom) CPDOMDisplayServerSetStyleOrigin(SetStyleRightBottom, aDOMElement, aTransform, aRight, aBottom)
103
104#define CPDOMDisplayServerSetStyleSize(aDOMElement, aWidth, aHeight)\
105    if (!aDOMElement.CPDOMDisplayContext)\
106        aDOMElement.CPDOMDisplayContext = [];\
107    var __index = aDOMElement.CPDOMDisplayContext[SetStyleSize];\
108    if (!(__index >= 0))\
109    {\
110        __index = aDOMElement.CPDOMDisplayContext[SetStyleSize] = CPDOMDisplayServerInstructionCount;\
111        CPDOMDisplayServerInstructionCount += 4;\
112    }\
113    CPDOMDisplayServerInstructions[__index] = SetStyleSize;\
114    CPDOMDisplayServerInstructions[__index + 1] = aDOMElement;\
115    CPDOMDisplayServerInstructions[__index + 2] = aWidth;\
116    CPDOMDisplayServerInstructions[__index + 3] = aHeight;
117
118#define CPDOMDisplayServerSetSize(aDOMElement, aWidth, aHeight)\
119    if (!aDOMElement.CPDOMDisplayContext)\
120        aDOMElement.CPDOMDisplayContext = [];\
121    var __index = aDOMElement.CPDOMDisplayContext[SetSize];\
122    if (!(__index >= 0))\
123    {\
124        __index = aDOMElement.CPDOMDisplayContext[SetSize] = CPDOMDisplayServerInstructionCount;\
125        CPDOMDisplayServerInstructionCount += 4;\
126    }\
127    CPDOMDisplayServerInstructions[__index] = SetSize;\
128    CPDOMDisplayServerInstructions[__index + 1] = aDOMElement;\
129    CPDOMDisplayServerInstructions[__index + 2] = aWidth;\
130    CPDOMDisplayServerInstructions[__index + 3] = aHeight;
131
132#define CPDOMDisplayServerSetStyleBackgroundSize(aDOMElement, aWidth, aHeight)\
133    aDOMElement.style.backgroundSize = aWidth + ' ' + aHeight;
134
135#define CPDOMDisplayServerAppendChild(aParentElement, aChildElement)\
136    if (aChildElement.CPDOMDisplayContext) aChildElement.CPDOMDisplayContext[SetStyleOrigin] = -1;\
137    CPDOMDisplayServerInstructions[CPDOMDisplayServerInstructionCount++] = AppendChild;\
138    CPDOMDisplayServerInstructions[CPDOMDisplayServerInstructionCount++] = aParentElement;\
139    CPDOMDisplayServerInstructions[CPDOMDisplayServerInstructionCount++] = aChildElement;
140
141#define CPDOMDisplayServerInsertBefore(aParentElement, aChildElement, aBeforeElement)\
142    if (aChildElement.CPDOMDisplayContext) aChildElement.CPDOMDisplayContext[SetStyleOrigin] = -1;\
143    CPDOMDisplayServerInstructions[CPDOMDisplayServerInstructionCount++] = InsertBefore;\
144    CPDOMDisplayServerInstructions[CPDOMDisplayServerInstructionCount++] = aParentElement;\
145    CPDOMDisplayServerInstructions[CPDOMDisplayServerInstructionCount++] = aChildElement;\
146    CPDOMDisplayServerInstructions[CPDOMDisplayServerInstructionCount++] = aBeforeElement;
147
148#define CPDOMDisplayServerRemoveChild(aParentElement, aChildElement)\
149    CPDOMDisplayServerInstructions[CPDOMDisplayServerInstructionCount++] = RemoveChild;\
150    CPDOMDisplayServerInstructions[CPDOMDisplayServerInstructionCount++] = aParentElement;\
151    CPDOMDisplayServerInstructions[CPDOMDisplayServerInstructionCount++] = aChildElement;
152
153#define PREPARE_DOM_OPTIMIZATION()\
154CPDOMDisplayServerInstructions = [];\
155CPDOMDisplayServerInstructionCount = 0;
156#define EXECUTE_DOM_INSTRUCTIONS()\
157    var index = 0;\
158    while (index < CPDOMDisplayServerInstructionCount)\
159    {\
160        var instruction = CPDOMDisplayServerInstructions[index++];\
161        try{\
162            switch (instruction)\
163            {\
164                case SetStyleLeftTop:\
165                case SetStyleRightTop:\
166                case SetStyleLeftBottom:\
167                case SetStyleRightBottom:   var element = CPDOMDisplayServerInstructions[index],\
168                                                style = element.style,\
169                                                x = (instruction == SetStyleLeftTop || instruction == SetStyleLeftBottom) ? "left" : "right",\
170                                                y = (instruction == SetStyleLeftTop || instruction == SetStyleRightTop) ? "top" : "bottom";\
171                                            CPDOMDisplayServerInstructions[index++] = nil;\
172                                            var transform = CPDOMDisplayServerInstructions[index++];\
173                                            if (transform)\
174                                            {\
175                                                var point = CGPointMake(CPDOMDisplayServerInstructions[index++], CPDOMDisplayServerInstructions[index++]),\
176                                                    transformed = CGPointApplyAffineTransform(point, transform);\
177                                                style[x] = ROUND(transformed.x) + "px";\
178                                                style[y] = ROUND(transformed.y) + "px";\
179                                            }\
180                                            else\
181                                            {\
182                                                style[x] = ROUND(CPDOMDisplayServerInstructions[index++]) + "px";\
183                                                style[y] = ROUND(CPDOMDisplayServerInstructions[index++]) + "px";\
184                                            }\
185                                            element.CPDOMDisplayContext[SetStyleOrigin] = -1;\
186                                            break;\
187                case SetStyleSize:          var element = CPDOMDisplayServerInstructions[index],\
188                                                style = element.style;\
189                                            CPDOMDisplayServerInstructions[index++] = nil;\
190                                            element.CPDOMDisplayContext[SetStyleSize] = -1;\
191                                            style.width = MAX(0.0, ROUND(CPDOMDisplayServerInstructions[index++])) + "px";\
192                                            style.height = MAX(0.0, ROUND(CPDOMDisplayServerInstructions[index++])) + "px";\
193                                            break;\
194                case SetSize:               var element = CPDOMDisplayServerInstructions[index];\
195                                            CPDOMDisplayServerInstructions[index++] = nil;\
196                                            element.CPDOMDisplayContext[SetSize] = -1;\
197                                            element.width = MAX(0.0, ROUND(CPDOMDisplayServerInstructions[index++]));\
198                                            element.height = MAX(0.0, ROUND(CPDOMDisplayServerInstructions[index++]));\
199                                            break;\
200                case AppendChild:           CPDOMDisplayServerInstructions[index].appendChild(CPDOMDisplayServerInstructions[index + 1]);\
201                                            CPDOMDisplayServerInstructions[index++] = nil;\
202                                            CPDOMDisplayServerInstructions[index++] = nil;\
203                                            break;\
204                case InsertBefore:          CPDOMDisplayServerInstructions[index].insertBefore(CPDOMDisplayServerInstructions[index + 1], CPDOMDisplayServerInstructions[index + 2]);\
205                                            CPDOMDisplayServerInstructions[index++] = nil;\
206                                            CPDOMDisplayServerInstructions[index++] = nil;\
207                                            CPDOMDisplayServerInstructions[index++] = nil;\
208                                            break;\
209                case RemoveChild:           CPDOMDisplayServerInstructions[index].removeChild(CPDOMDisplayServerInstructions[index + 1]);\
210                                            CPDOMDisplayServerInstructions[index++] = nil;\
211                                            CPDOMDisplayServerInstructions[index++] = nil;\
212                                            break;\
213                }\
214            }\
215            catch(e) { CPLog("e " + e + " " + instruction); }\
216        }\
217        CPDOMDisplayServerInstructionCount = 0;
218#endif