49
|
1 |
/*
|
|
2 |
* Copyright (c) 2000 - 2004 Nokia Corporation and/or its subsidiary(-ies).
|
|
3 |
* All rights reserved.
|
|
4 |
* This component and the accompanying materials are made available
|
|
5 |
* under the terms of the License "Eclipse Public License v1.0"
|
|
6 |
* which accompanies this distribution, and is available
|
|
7 |
* at the URL "http://www.eclipse.org/legal/epl-v10.html".
|
|
8 |
*
|
|
9 |
* Initial Contributors:
|
|
10 |
* Nokia Corporation - initial contribution.
|
|
11 |
*
|
|
12 |
* Contributors:
|
|
13 |
*
|
|
14 |
* Description:
|
|
15 |
*
|
|
16 |
*/
|
|
17 |
|
|
18 |
#include "nw_lmgr_containerboxi.h"
|
|
19 |
#include "nw_lmgr_box.h"
|
|
20 |
#include "nw_lmgr_flowbox.h"
|
|
21 |
#include "nw_lmgr_rootbox.h"
|
|
22 |
#include "nw_lmgr_splittextbox.h"
|
|
23 |
#include "nw_lmgr_statictablebox.h"
|
|
24 |
#include "nw_lmgr_statictablerowbox.h"
|
|
25 |
#include "nw_lmgr_statictablecellbox.h"
|
|
26 |
#include "nw_lmgr_activecontainerbox.h"
|
|
27 |
#include "nw_lmgr_cssproperties.h"
|
|
28 |
#include "nw_adt_resizablevector.h"
|
|
29 |
#include "nw_lmgr_eventhandler.h"
|
|
30 |
#include "GDIDeviceContext.h"
|
|
31 |
#include "nw_lmgr_slavepropertylist.h"
|
|
32 |
#include "nw_adt_vectoriterator.h"
|
|
33 |
#include "BrsrStatusCodes.h"
|
|
34 |
#include "BoxRender.h"
|
|
35 |
#include "nwx_logger.h"
|
|
36 |
#include "nwx_settings.h"
|
|
37 |
#include "ObjectUtils.h"
|
|
38 |
#include "nw_lmgr_posflowbox.h"
|
|
39 |
|
|
40 |
/* ------------------------------------------------------------------------- *
|
|
41 |
private final methods
|
|
42 |
* ------------------------------------------------------------------------- */
|
|
43 |
|
|
44 |
/* ------------------------------------------------------------------------- *
|
|
45 |
static data
|
|
46 |
* ------------------------------------------------------------------------- */
|
|
47 |
|
|
48 |
const
|
|
49 |
NW_LMgr_ContainerBox_Class_t NW_LMgr_ContainerBox_Class = {
|
|
50 |
{ /* NW_Object_Core */
|
|
51 |
/* super */ &NW_LMgr_Box_Class,
|
|
52 |
/* queryInterface */ _NW_Object_Base_QueryInterface
|
|
53 |
},
|
|
54 |
{ /* NW_Object_Base */
|
|
55 |
/* interfaceList */ NULL
|
|
56 |
},
|
|
57 |
{ /* NW_Object_Dynamic */
|
|
58 |
/* instanceSize */ sizeof (NW_LMgr_ContainerBox_t),
|
|
59 |
/* construct */ _NW_LMgr_ContainerBox_Construct,
|
|
60 |
/* destruct */ _NW_LMgr_ContainerBox_Destruct
|
|
61 |
},
|
|
62 |
{ /* NW_LMgr_Box */
|
|
63 |
/* split */ _NW_LMgr_Box_Split,
|
|
64 |
/* resize */ _NW_LMgr_ContainerBox_Resize,
|
|
65 |
/* postResize */ _NW_LMgr_Box_PostResize,
|
|
66 |
/* getMinimumContentSize */ _NW_LMgr_Box_GetMinimumContentSize,
|
|
67 |
/* hasFixedContentSize */ _NW_LMgr_Box_HasFixedContentSize,
|
|
68 |
/* constrain */ _NW_LMgr_Box_Constrain,
|
|
69 |
/* draw */ _NW_LMgr_Box_Draw,
|
|
70 |
/* render */ _NW_LMgr_ContainerBox_Render,
|
|
71 |
/* getBaseline */ _NW_LMgr_ContainerBox_GetBaseline,
|
|
72 |
/* shift */ _NW_LMgr_ContainerBox_Shift,
|
|
73 |
/* clone */ _NW_LMgr_ContainerBox_Clone
|
|
74 |
},
|
|
75 |
{ /* NW_LMgr_ContainerBox */
|
|
76 |
/* unused */ NW_Object_Unused
|
|
77 |
}
|
|
78 |
};
|
|
79 |
|
|
80 |
/* ------------------------------------------------------------------------- *
|
|
81 |
virtual methods
|
|
82 |
* ------------------------------------------------------------------------- */
|
|
83 |
|
|
84 |
/* ------------------------------------------------------------------------- *
|
|
85 |
* Function: NW_LMgr_ContainerBox_Construct
|
|
86 |
* Description: The constructor.
|
|
87 |
* Returns: KBrsrSuccess, KBrsrOutOfMemory.
|
|
88 |
*/
|
|
89 |
|
|
90 |
TBrowserStatusCode
|
|
91 |
_NW_LMgr_ContainerBox_Construct (NW_Object_Dynamic_t* dynamicObject,
|
|
92 |
va_list* argp)
|
|
93 |
{
|
|
94 |
NW_LMgr_ContainerBox_t* container;
|
|
95 |
|
|
96 |
NW_TRY(status) {
|
|
97 |
|
|
98 |
/* for convenience */
|
|
99 |
container = NW_LMgr_ContainerBoxOf (dynamicObject);
|
|
100 |
|
|
101 |
/* invoke our superclass constructor */
|
|
102 |
status = _NW_LMgr_Box_Construct (dynamicObject, argp);
|
|
103 |
_NW_THROW_ON_ERROR(status);
|
|
104 |
|
|
105 |
/* initialize the member variables */
|
|
106 |
container->children = (NW_ADT_DynamicVector_t*)
|
|
107 |
NW_ADT_ResizableVector_New (sizeof (NW_LMgr_Box_t*), 0, 5 );
|
|
108 |
NW_THROW_OOM_ON_NULL(container->children, status);
|
|
109 |
}
|
|
110 |
NW_CATCH(status) {
|
|
111 |
}
|
|
112 |
NW_FINALLY {
|
|
113 |
return status;
|
|
114 |
}
|
|
115 |
NW_END_TRY
|
|
116 |
}
|
|
117 |
|
|
118 |
/* ------------------------------------------------------------------------- *
|
|
119 |
* Function: NW_LMgr_ContainerBox_Destruct
|
|
120 |
* Description: The destructor.
|
|
121 |
* Returns: void
|
|
122 |
*/
|
|
123 |
|
|
124 |
void
|
|
125 |
_NW_LMgr_ContainerBox_Destruct (NW_Object_Dynamic_t* dynamicObject)
|
|
126 |
{
|
|
127 |
NW_LMgr_ContainerBox_t* container;
|
|
128 |
NW_ADT_Vector_Metric_t numChildren;
|
|
129 |
NW_Int32 index;
|
|
130 |
|
|
131 |
/* for convenience */
|
|
132 |
container = NW_LMgr_ContainerBoxOf (dynamicObject);
|
|
133 |
|
|
134 |
if (container->children != NULL) {
|
|
135 |
/* before deleting the object, we must delete any children
|
|
136 |
contained by us */
|
|
137 |
numChildren =
|
|
138 |
NW_ADT_Vector_GetSize (container->children);
|
|
139 |
for (index = numChildren - 1; index >= 0; index--) {
|
|
140 |
NW_LMgr_Box_t* child;
|
|
141 |
|
|
142 |
child = *(NW_LMgr_Box_t**)
|
|
143 |
NW_ADT_Vector_ElementAt (container->children,
|
|
144 |
(NW_ADT_Vector_Metric_t) index);
|
|
145 |
NW_Object_Delete (child);
|
|
146 |
}
|
|
147 |
|
|
148 |
/* release our resources */
|
|
149 |
NW_Object_Delete (container->children);
|
|
150 |
}
|
|
151 |
}
|
|
152 |
|
|
153 |
|
|
154 |
TBrowserStatusCode
|
|
155 |
_NW_LMgr_ContainerBox_Resize( NW_LMgr_Box_t* box, NW_LMgr_FormatContext_t* context )
|
|
156 |
{
|
|
157 |
TBrowserStatusCode status;
|
|
158 |
NW_LMgr_ContainerBox_t* container;
|
|
159 |
|
|
160 |
NW_REQUIRED_PARAM( context );
|
|
161 |
NW_ASSERT( box != NULL );
|
|
162 |
|
|
163 |
container = NW_LMgr_ContainerBoxOf( box );
|
|
164 |
status = NW_LMgr_ContainerBox_ResizeToChildren( container );
|
|
165 |
if (NW_Object_IsInstanceOf(NW_LMgr_BoxOf(NW_LMgr_Box_GetParent(box)),& NW_LMgr_PosFlowBox_Class))
|
|
166 |
{
|
|
167 |
NW_GDI_Dimension2D_t size;
|
|
168 |
NW_LMgr_Box_GetSizeProperties(box, &size);
|
|
169 |
if (size.width > box->iFormatBounds.dimension.width)
|
|
170 |
{
|
|
171 |
box->iFormatBounds.dimension.width = size.width;
|
|
172 |
}
|
|
173 |
|
|
174 |
if (size.height > box->iFormatBounds.dimension.height)
|
|
175 |
{
|
|
176 |
box->iFormatBounds.dimension.height = size.height;
|
|
177 |
}
|
|
178 |
}
|
|
179 |
return status;
|
|
180 |
}
|
|
181 |
|
|
182 |
/* ------------------------------------------------------------------------- *
|
|
183 |
* Function: NW_LMgr_ContainerBox_Shift
|
|
184 |
* Description: ContainerBox::Shift shifts the container and the subtree
|
|
185 |
* below it.
|
|
186 |
* Returns: KBrsrSuccess, KBrsrOutOfMemory.
|
|
187 |
*/
|
|
188 |
|
|
189 |
TBrowserStatusCode
|
|
190 |
_NW_LMgr_ContainerBox_Shift (NW_LMgr_Box_t* box,
|
|
191 |
NW_GDI_Point2D_t *delta)
|
|
192 |
{
|
|
193 |
NW_LMgr_BoxVisitor_t * visitor = NULL;
|
|
194 |
NW_LMgr_Box_t *child;
|
|
195 |
|
|
196 |
NW_TRY(status) {
|
|
197 |
|
|
198 |
NW_ASSERT(box != NULL);
|
|
199 |
|
|
200 |
visitor = NW_LMgr_ContainerBox_GetBoxVisitor(box);
|
|
201 |
NW_THROW_OOM_ON_NULL(visitor, status);
|
|
202 |
|
|
203 |
/* Invoke base-class shift on this box and all children */
|
|
204 |
|
|
205 |
while ((child = NW_LMgr_BoxVisitor_NextBox(visitor, NULL)) != NULL) {
|
|
206 |
status = NW_LMgr_Box_Class.NW_LMgr_Box.shift(child, delta);
|
|
207 |
_NW_THROW_ON_ERROR(status);
|
|
208 |
}
|
|
209 |
}
|
|
210 |
NW_CATCH(status) {
|
|
211 |
}
|
|
212 |
NW_FINALLY {
|
|
213 |
NW_Object_Delete(visitor);
|
|
214 |
return status;
|
|
215 |
}
|
|
216 |
NW_END_TRY
|
|
217 |
}
|
|
218 |
|
|
219 |
/* ------------------------------------------------------------------------- *
|
|
220 |
* Function: NW_LMgr_ContainerBox_Clone
|
|
221 |
* Description: Clones of containers only inherit the property list. They
|
|
222 |
* also have their "Clone" flag set. The children are not
|
|
223 |
* copied into the new box.
|
|
224 |
* Returns: The new box, or NULL in case of an error.
|
|
225 |
*/
|
|
226 |
NW_LMgr_Box_t*
|
|
227 |
_NW_LMgr_ContainerBox_Clone (NW_LMgr_Box_t* box)
|
|
228 |
{
|
|
229 |
NW_LMgr_Box_t *newBox = NULL;
|
|
230 |
|
|
231 |
/* parameter assertion block */
|
|
232 |
NW_ASSERT(NW_Object_IsInstanceOf (box, &NW_LMgr_ContainerBox_Class));
|
|
233 |
|
|
234 |
/* Create the new box */
|
|
235 |
newBox = (NW_LMgr_Box_t*) NW_LMgr_ContainerBox_New (0);
|
|
236 |
if (newBox == NULL) {
|
|
237 |
return NULL;
|
|
238 |
}
|
|
239 |
|
|
240 |
/* Copy the property list, if one exists */
|
|
241 |
if (box->propList != NULL) {
|
|
242 |
newBox->propList = NW_LMgr_PropertyList_Clone (box->propList);
|
|
243 |
}
|
|
244 |
else{
|
|
245 |
/* instantiate a new SimplePropertyList object */
|
|
246 |
newBox->propList = (NW_LMgr_PropertyList_t*)
|
|
247 |
NW_LMgr_SlavePropertyList_New (NULL);
|
|
248 |
}
|
|
249 |
if (newBox->propList == NULL) {
|
|
250 |
NW_Object_Delete (newBox);
|
|
251 |
return NULL;
|
|
252 |
}
|
|
253 |
|
|
254 |
return newBox;
|
|
255 |
}
|
|
256 |
|
|
257 |
/* ------------------------------------------------------------------------- *
|
|
258 |
public/protected final methods
|
|
259 |
* ------------------------------------------------------------------------- */
|
|
260 |
|
|
261 |
/* ------------------------------------------------------------------------- */
|
|
262 |
TBrowserStatusCode
|
|
263 |
NW_LMgr_ContainerBox_Collapse (NW_LMgr_ContainerBox_t* thisObj)
|
|
264 |
{
|
|
265 |
NW_LMgr_PropertyList_t* propertyList;
|
|
266 |
NW_LMgr_Property_t prop;
|
|
267 |
NW_LMgr_ContainerBox_t* siblingBox;
|
|
268 |
NW_LMgr_Box_t* childBox;
|
|
269 |
TBrowserStatusCode status = KBrsrSuccess;
|
|
270 |
|
|
271 |
/* parameter assertion block */
|
|
272 |
NW_ASSERT (NW_Object_IsInstanceOf (thisObj, &NW_LMgr_ContainerBox_Class));
|
|
273 |
|
|
274 |
propertyList = NW_LMgr_Box_PropListGet(NW_LMgr_BoxOf(thisObj));
|
|
275 |
if (propertyList == NULL){
|
|
276 |
return KBrsrSuccess;
|
|
277 |
}
|
|
278 |
|
|
279 |
NW_ASSERT (NW_Object_IsInstanceOf (propertyList, &NW_LMgr_PropertyList_Class));
|
|
280 |
|
|
281 |
/* the master box will take care of coolapsing the slave boxes */
|
|
282 |
if (NW_Object_IsInstanceOf(propertyList, &NW_LMgr_SlavePropertyList_Class)){
|
|
283 |
return KBrsrSuccess;
|
|
284 |
}
|
|
285 |
|
|
286 |
/* if the propertylist is not slave propertylist, it definitely is a simple
|
|
287 |
property list, and this box is a master box - so start collapse
|
|
288 |
*/
|
|
289 |
|
|
290 |
/* implement collapse */
|
|
291 |
|
|
292 |
/* Get sibling box */
|
|
293 |
prop.value.object = NULL;
|
|
294 |
(void)NW_LMgr_PropertyList_Get(propertyList, NW_CSS_Prop_sibling, &prop);
|
|
295 |
if (prop.value.object == NULL){
|
|
296 |
return KBrsrSuccess;
|
|
297 |
}
|
|
298 |
|
|
299 |
while(prop.value.object)
|
|
300 |
{
|
|
301 |
NW_ADT_Vector_Metric_t childCount;
|
|
302 |
|
|
303 |
siblingBox = NW_LMgr_ContainerBoxOf(prop.value.object);
|
|
304 |
|
|
305 |
/* This condition should never happen unless sibling boxes are not created
|
|
306 |
properly. Should it be an ASSERT instead?? */
|
|
307 |
if (!NW_Object_IsInstanceOf(NW_LMgr_BoxOf(siblingBox)->propList,
|
|
308 |
&NW_LMgr_SlavePropertyList_Class))
|
|
309 |
{
|
|
310 |
return KBrsrFailure;
|
|
311 |
}
|
|
312 |
|
|
313 |
/* Insert your sibling's children in master container box */
|
|
314 |
/* PROBLEM: Make Container_GetChild recognize NW_ADT_Vector_AtEnd */
|
|
315 |
childCount = NW_LMgr_ContainerBox_GetChildCount(siblingBox);
|
|
316 |
while (childCount > 0)
|
|
317 |
{
|
|
318 |
childCount--;
|
|
319 |
childBox = NW_LMgr_ContainerBox_GetChild(siblingBox, childCount);
|
|
320 |
NW_ASSERT(childBox);
|
|
321 |
|
|
322 |
/* Insert ChildAt will remove the child from the old parent
|
|
323 |
which is the sibling box
|
|
324 |
*/
|
|
325 |
/* The following method should be more efficient - we get the child
|
|
326 |
from the old box, and then again search for it to remove it.
|
|
327 |
RemoveChild should return a box, so that we can use that box to
|
|
328 |
attach it somewhere else */
|
|
329 |
status = NW_LMgr_ContainerBox_InsertChildAt(thisObj, childBox, 0);
|
|
330 |
if (status != KBrsrSuccess) {
|
|
331 |
return status;
|
|
332 |
}
|
|
333 |
|
|
334 |
}
|
|
335 |
|
|
336 |
/* Get next sibling box */
|
|
337 |
propertyList = NW_LMgr_Box_PropListGet(NW_LMgr_BoxOf(siblingBox));
|
|
338 |
NW_ASSERT (NW_Object_IsInstanceOf (propertyList, &NW_LMgr_PropertyList_Class));
|
|
339 |
|
|
340 |
prop.value.object = NULL;
|
|
341 |
(void)NW_LMgr_PropertyList_Get(propertyList, NW_CSS_Prop_sibling, &prop);
|
|
342 |
|
|
343 |
/* delete the sibling box */
|
|
344 |
NW_Object_Delete(siblingBox);
|
|
345 |
|
|
346 |
/* If we come back in a loop to the master box, then stop */
|
|
347 |
if (prop.value.object == thisObj)
|
|
348 |
break;
|
|
349 |
}
|
|
350 |
/* We also want to remove the sibling property on the master box,
|
|
351 |
since we are collapsing the split containers */
|
|
352 |
(void)NW_LMgr_Box_RemoveProperty(NW_LMgr_BoxOf(thisObj), NW_CSS_Prop_sibling);
|
|
353 |
|
|
354 |
return KBrsrSuccess;
|
|
355 |
}
|
|
356 |
|
|
357 |
/* ------------------------------------------------------------------------- *
|
|
358 |
* Function: NW_LMgr_ContainerBox_InsertChildAt
|
|
359 |
* Description: Inserts a child at the given index. If a child is already
|
|
360 |
* attached to a parent, it detaches it first.
|
|
361 |
* Returns: KBrsrSuccess if successful, KBrsrFailure if the index
|
|
362 |
* is out of bounds, KBrsrOutOfMemory.
|
|
363 |
*/
|
|
364 |
|
|
365 |
TBrowserStatusCode
|
|
366 |
NW_LMgr_ContainerBox_InsertChildAt (NW_LMgr_ContainerBox_t* container,
|
|
367 |
NW_LMgr_Box_t* child,
|
|
368 |
NW_ADT_Vector_Metric_t where)
|
|
369 |
{
|
|
370 |
NW_LMgr_ContainerBox_t* parent;
|
|
371 |
|
|
372 |
NW_TRY(status) {
|
|
373 |
|
|
374 |
NW_ASSERT(child != NULL);
|
|
375 |
|
|
376 |
/* Remove the child from its existing parent, if necessary */
|
|
377 |
parent = NW_LMgr_Box_GetParent (child);
|
|
378 |
if (parent != NULL) {
|
|
379 |
status = NW_LMgr_ContainerBox_RemoveChild (parent, child);
|
|
380 |
_NW_THROW_ON_ERROR(status);
|
|
381 |
}
|
|
382 |
|
|
383 |
/* Insert the child into our 'children' vector */
|
|
384 |
NW_THROW_OOM_ON_NULL(NW_ADT_DynamicVector_InsertAt(container->children,
|
|
385 |
&child, where),
|
|
386 |
status);
|
|
387 |
|
|
388 |
/* Set the parent field of the Box - note that we do this as
|
|
389 |
a 'friend' class */
|
|
390 |
NW_LMgr_Box_SetParent (child, container);
|
|
391 |
}
|
|
392 |
NW_CATCH(status) {
|
|
393 |
}
|
|
394 |
NW_FINALLY {
|
|
395 |
return status;
|
|
396 |
}
|
|
397 |
NW_END_TRY
|
|
398 |
}
|
|
399 |
|
|
400 |
/* ------------------------------------------------------------------------- *
|
|
401 |
* Function: NW_LMgr_ContainerBox_AddChild
|
|
402 |
* Description: Adds a child to the end of the container.
|
|
403 |
* Returns: KBrsrSuccess, KBrsrOutOfMemory.
|
|
404 |
*/
|
|
405 |
|
|
406 |
TBrowserStatusCode
|
|
407 |
NW_LMgr_ContainerBox_AddChild (NW_LMgr_ContainerBox_t* container,
|
|
408 |
NW_LMgr_Box_t* child)
|
|
409 |
{
|
|
410 |
return NW_LMgr_ContainerBox_InsertChildAt (container, child,
|
|
411 |
NW_ADT_Vector_AtEnd);
|
|
412 |
}
|
|
413 |
|
|
414 |
/* ------------------------------------------------------------------------- *
|
|
415 |
* Function: NW_LMgr_ContainerBox_InsertChild
|
|
416 |
* Description: Inserts a child immediately before the box pointed to by
|
|
417 |
* "where".
|
|
418 |
* If "where" is not a child of the container, KBrsrFailure
|
|
419 |
* is returned.
|
|
420 |
* Returns: KBrsrSuccess, KBrsrFailure, KBrsrOutOfMemory.
|
|
421 |
*/
|
|
422 |
|
|
423 |
TBrowserStatusCode
|
|
424 |
NW_LMgr_ContainerBox_InsertChild (NW_LMgr_ContainerBox_t* container,
|
|
425 |
NW_LMgr_Box_t* child,
|
|
426 |
NW_LMgr_Box_t* where)
|
|
427 |
{
|
|
428 |
NW_ADT_Vector_Metric_t index;
|
|
429 |
|
|
430 |
index = NW_ADT_Vector_GetElementIndex (container->children,
|
|
431 |
&where);
|
|
432 |
if (index == NW_ADT_Vector_AtEnd) {
|
|
433 |
return KBrsrFailure;
|
|
434 |
}
|
|
435 |
return NW_LMgr_ContainerBox_InsertChildAt (container, child, index);
|
|
436 |
}
|
|
437 |
|
|
438 |
/* ------------------------------------------------------------------------- *
|
|
439 |
* Function: NW_LMgr_ContainerBox_InsertChildAft
|
|
440 |
* Description: Inserts a child immediately following the box pointed to by
|
|
441 |
* "where". If "where" is not a child of the container,
|
|
442 |
* KBrsrFailure is returned.
|
|
443 |
* Returns: KBrsrSuccess, KBrsrFailure, KBrsrOutOfMemory.
|
|
444 |
*/
|
|
445 |
|
|
446 |
TBrowserStatusCode
|
|
447 |
NW_LMgr_ContainerBox_InsertChildAft (NW_LMgr_ContainerBox_t* container,
|
|
448 |
NW_LMgr_Box_t* child,
|
|
449 |
NW_LMgr_Box_t* where)
|
|
450 |
{
|
|
451 |
NW_ADT_Vector_Metric_t index;
|
|
452 |
|
|
453 |
index = NW_ADT_Vector_GetElementIndex (container->children,
|
|
454 |
&where);
|
|
455 |
if (index == NW_ADT_Vector_AtEnd) {
|
|
456 |
return KBrsrFailure; /* TODO: return a more descriptive error code */
|
|
457 |
}
|
|
458 |
if ((index + 1)
|
|
459 |
< NW_ADT_Vector_GetSize(container->children)) {
|
|
460 |
return NW_LMgr_ContainerBox_InsertChildAt (container, child,
|
|
461 |
((NW_ADT_Vector_Metric_t)
|
|
462 |
(index+1)));
|
|
463 |
} else {
|
|
464 |
return NW_LMgr_ContainerBox_AddChild (container, child);
|
|
465 |
}
|
|
466 |
}
|
|
467 |
|
|
468 |
/* ------------------------------------------------------------------------- *
|
|
469 |
* Function: NW_LMgr_ContainerBox_AppendChildrenOf
|
|
470 |
* Description: Appends the children of "source" to the container pointed
|
|
471 |
* to by "container".
|
|
472 |
* Returns: KBrsrSuccess, KBrsrOutOfMemory.
|
|
473 |
*/
|
|
474 |
|
|
475 |
TBrowserStatusCode
|
|
476 |
NW_LMgr_ContainerBox_AppendChildrenOf (NW_LMgr_ContainerBox_t* container,
|
|
477 |
NW_LMgr_ContainerBox_t* source)
|
|
478 |
{
|
|
479 |
NW_TRY(status) {
|
|
480 |
while (NW_ADT_Vector_GetSize (source->children) != 0) {
|
|
481 |
NW_LMgr_Box_t* child;
|
|
482 |
|
|
483 |
child = *(NW_LMgr_Box_t**) NW_ADT_Vector_ElementAt (source->children, 0);
|
|
484 |
NW_ASSERT(child != NULL);
|
|
485 |
|
|
486 |
status = NW_LMgr_ContainerBox_AddChild (container, child);
|
|
487 |
_NW_THROW_ON_ERROR(status);
|
|
488 |
}
|
|
489 |
}
|
|
490 |
NW_CATCH(status) {
|
|
491 |
}
|
|
492 |
NW_FINALLY {
|
|
493 |
return status;
|
|
494 |
}
|
|
495 |
NW_END_TRY
|
|
496 |
}
|
|
497 |
|
|
498 |
/* ------------------------------------------------------------------------- *
|
|
499 |
* Function: NW_LMgr_ContainerBox_ReplaceChild
|
|
500 |
* Description: Replaces "originalChild" with "newChild".
|
|
501 |
* Returns: KBrsrSuccess, KBrsrFailure if the original child
|
|
502 |
* is not inside "container", KBrsrOutOfMemory.
|
|
503 |
*/
|
|
504 |
|
|
505 |
TBrowserStatusCode
|
|
506 |
NW_LMgr_ContainerBox_ReplaceChild (NW_LMgr_ContainerBox_t* container,
|
|
507 |
NW_LMgr_Box_t* originalChild,
|
|
508 |
NW_LMgr_Box_t* newChild)
|
|
509 |
{
|
|
510 |
NW_ADT_Vector_Metric_t index;
|
|
511 |
|
|
512 |
NW_TRY(status) {
|
|
513 |
index = NW_ADT_Vector_GetElementIndex(container->children,
|
|
514 |
&originalChild);
|
|
515 |
if (index == NW_ADT_Vector_AtEnd) {
|
|
516 |
NW_THROW_STATUS(status, KBrsrFailure);
|
|
517 |
}
|
|
518 |
|
|
519 |
status = NW_LMgr_ContainerBox_InsertChildAt (container, newChild, index);
|
|
520 |
_NW_THROW_ON_ERROR(status);
|
|
521 |
|
|
522 |
status = NW_LMgr_ContainerBox_RemoveChild (container, originalChild);
|
|
523 |
_NW_THROW_ON_ERROR(status);
|
|
524 |
}
|
|
525 |
NW_CATCH(status) {
|
|
526 |
}
|
|
527 |
NW_FINALLY {
|
|
528 |
return status;
|
|
529 |
}
|
|
530 |
NW_END_TRY
|
|
531 |
}
|
|
532 |
|
|
533 |
/* ------------------------------------------------------------------------- *
|
|
534 |
* Function: NW_LMgr_ContainerBox_GetChildIndex
|
|
535 |
* Description: Finds the index of "child" in the container.
|
|
536 |
* Returns: The index, or NW_ADT_Vector_AtEnd, if the child in not inside
|
|
537 |
* container.
|
|
538 |
*/
|
|
539 |
|
|
540 |
NW_ADT_Vector_Metric_t
|
|
541 |
NW_LMgr_ContainerBox_GetChildIndex (NW_LMgr_ContainerBox_t* container,
|
|
542 |
NW_LMgr_Box_t* child)
|
|
543 |
{
|
|
544 |
|
|
545 |
return NW_ADT_Vector_GetElementIndex (container->children,
|
|
546 |
&child);
|
|
547 |
|
|
548 |
}
|
|
549 |
|
|
550 |
/* ------------------------------------------------------------------------- *
|
|
551 |
* Function: NW_LMgr_ContainerBox_RemoveChild
|
|
552 |
* Description: Removes the child pointed to by "component" from the container.
|
|
553 |
* Returns: KBrsrSuccess, KBrsrFailure if the original child
|
|
554 |
* is not inside "container", KBrsrOutOfMemory.
|
|
555 |
*/
|
|
556 |
|
|
557 |
TBrowserStatusCode
|
|
558 |
NW_LMgr_ContainerBox_RemoveChild (NW_LMgr_ContainerBox_t* container,
|
|
559 |
NW_LMgr_Box_t* component)
|
|
560 |
{
|
|
561 |
NW_TRY(status) {
|
|
562 |
/* parameter assertion block */
|
|
563 |
NW_ASSERT(NW_Object_IsInstanceOf (container, &NW_LMgr_ContainerBox_Class));
|
|
564 |
NW_ASSERT(NW_Object_IsInstanceOf (component, &NW_LMgr_Box_Class));
|
|
565 |
|
|
566 |
/* search the 'children' vector for the element */
|
|
567 |
status = NW_ADT_DynamicVector_RemoveElement (container->children,
|
|
568 |
&component);
|
|
569 |
_NW_THROW_ON_ERROR(status);
|
|
570 |
|
|
571 |
/* clear the parent field of the component - note that we do this as a
|
|
572 |
'friend' of the class */
|
|
573 |
NW_LMgr_Box_SetParent (component, NULL);
|
|
574 |
}
|
|
575 |
NW_CATCH(status) {
|
|
576 |
}
|
|
577 |
NW_FINALLY {
|
|
578 |
return status;
|
|
579 |
}
|
|
580 |
NW_END_TRY
|
|
581 |
}
|
|
582 |
|
|
583 |
/* ------------------------------------------------------------------------- */
|
|
584 |
TBrowserStatusCode
|
|
585 |
NW_LMgr_ContainerBox_RemoveChildren (NW_LMgr_ContainerBox_t* thisObj)
|
|
586 |
{
|
|
587 |
NW_ADT_VectorIterator_t iterator;
|
|
588 |
|
|
589 |
NW_Object_Invalidate (&iterator);
|
|
590 |
NW_TRY (status) {
|
|
591 |
(void) NW_ADT_VectorIterator_Initialize (&iterator, thisObj->children,
|
|
592 |
NW_ADT_Vector_AtFront,
|
|
593 |
NW_ADT_Vector_AtEnd,
|
|
594 |
NW_ADT_IteratorDirection_Increment);
|
|
595 |
|
|
596 |
while (NW_ADT_Iterator_HasMoreElements (&iterator)) {
|
|
597 |
NW_LMgr_Box_t* child;
|
|
598 |
|
|
599 |
status = NW_ADT_Iterator_GetNextElement (&iterator, &child);
|
|
600 |
NW_THROW_ON_ERROR (status);
|
|
601 |
|
|
602 |
status = NW_LMgr_ContainerBox_RemoveChild (thisObj, child);
|
|
603 |
NW_THROW_ON_ERROR (status);
|
|
604 |
}
|
|
605 |
}
|
|
606 |
|
|
607 |
NW_CATCH (status) { /* empty */ }
|
|
608 |
|
|
609 |
NW_FINALLY {
|
|
610 |
NW_Object_Terminate (&iterator);
|
|
611 |
return status;
|
|
612 |
} NW_END_TRY
|
|
613 |
}
|
|
614 |
|
|
615 |
/* ------------------------------------------------------------------------- */
|
|
616 |
TBrowserStatusCode
|
|
617 |
NW_LMgr_ContainerBox_DeleteChildren (NW_LMgr_ContainerBox_t* thisObj)
|
|
618 |
{
|
|
619 |
NW_LMgr_Box_t** child;
|
|
620 |
|
|
621 |
NW_TRY (status) {
|
|
622 |
while ((child = (NW_LMgr_Box_t**) NW_ADT_Vector_ElementAt (thisObj->children, 0)) != NULL) {
|
|
623 |
status = NW_LMgr_ContainerBox_RemoveChild (thisObj, *child);
|
|
624 |
NW_THROW_ON_ERROR (status);
|
|
625 |
|
|
626 |
NW_Object_Delete(*child);
|
|
627 |
}
|
|
628 |
}
|
|
629 |
|
|
630 |
NW_CATCH (status) { /* empty */ }
|
|
631 |
|
|
632 |
NW_FINALLY {
|
|
633 |
return status;
|
|
634 |
} NW_END_TRY
|
|
635 |
}
|
|
636 |
|
|
637 |
|
|
638 |
/* ------------------------------------------------------------------------- *
|
|
639 |
* Function: NW_LMgr_ContainerBox_GetChildCount
|
|
640 |
* Description: Counts the number of children of the container.
|
|
641 |
* Returns: The number of children, 0 if the container is empty.
|
|
642 |
*/
|
|
643 |
|
|
644 |
NW_ADT_Vector_Metric_t
|
|
645 |
NW_LMgr_ContainerBox_GetChildCount (NW_LMgr_ContainerBox_t* container)
|
|
646 |
{
|
|
647 |
return NW_ADT_Vector_GetSize (container->children);
|
|
648 |
}
|
|
649 |
|
|
650 |
/* ------------------------------------------------------------------------- *
|
|
651 |
* Function: NW_LMgr_ContainerBox_GetChild
|
|
652 |
* Description: Gets the child at "index".
|
|
653 |
* Returns: The child box, or NULL if the index is out of bounds.
|
|
654 |
*/
|
|
655 |
|
|
656 |
NW_LMgr_Box_t*
|
|
657 |
NW_LMgr_ContainerBox_GetChild (NW_LMgr_ContainerBox_t* container,
|
|
658 |
NW_ADT_Vector_Metric_t index)
|
|
659 |
{
|
|
660 |
NW_LMgr_Box_t** entry;
|
|
661 |
|
|
662 |
entry =
|
|
663 |
(NW_LMgr_Box_t**) NW_ADT_Vector_ElementAt (container->children, index);
|
|
664 |
if (entry != NULL) {
|
|
665 |
return *entry;
|
|
666 |
}
|
|
667 |
return NULL;
|
|
668 |
}
|
|
669 |
|
|
670 |
/* ------------------------------------------------------------------------- *
|
|
671 |
* Function: NW_LMgr_ContainerBox_SplitAtIndex
|
|
672 |
* Description: SplitAtIndex returns a clone of the container containing the
|
|
673 |
* first "index" children. The remaining children stay in the
|
|
674 |
* original container. If "index" is 0, the split container
|
|
675 |
* will be empty. If "index" points to the last child, the
|
|
676 |
* original container will remain empty.
|
|
677 |
* Returns: The split container, or NULL if an error occured.
|
|
678 |
*/
|
|
679 |
|
|
680 |
NW_LMgr_Box_t*
|
|
681 |
NW_LMgr_ContainerBox_SplitAtIndex (NW_LMgr_ContainerBox_t* container,
|
|
682 |
NW_ADT_Vector_Metric_t index){
|
|
683 |
NW_ADT_Vector_Metric_t childCount, childIndex;
|
|
684 |
NW_LMgr_ContainerBox_t *splitContainer = NULL;
|
|
685 |
NW_LMgr_Box_t *childBox;
|
|
686 |
NW_LMgr_Property_t prop;
|
|
687 |
NW_LMgr_PropertyValue_t dirValue;
|
|
688 |
|
|
689 |
childCount = NW_LMgr_ContainerBox_GetChildCount (container);
|
|
690 |
|
|
691 |
/* Verify input parameters */
|
|
692 |
if (childCount <= 1 || index >= childCount) {
|
|
693 |
NW_ASSERT(0);
|
|
694 |
return NULL;
|
|
695 |
}
|
|
696 |
|
|
697 |
NW_TRY(status) {
|
|
698 |
/* Get the text direction */
|
|
699 |
dirValue.token = NW_CSS_PropValue_ltr;
|
|
700 |
status = NW_LMgr_Box_GetPropertyValue(NW_LMgr_BoxOf(container),
|
|
701 |
NW_CSS_Prop_textDirection,
|
|
702 |
NW_CSS_ValueType_Token,
|
|
703 |
&dirValue);
|
|
704 |
NW_THROW_ON(status, KBrsrOutOfMemory);
|
|
705 |
|
|
706 |
/* Create the new container */
|
|
707 |
splitContainer =
|
|
708 |
(NW_LMgr_ContainerBox_t*)NW_LMgr_Box_Clone ((NW_LMgr_Box_t*)container);
|
|
709 |
NW_THROW_OOM_ON_NULL(splitContainer, status);
|
|
710 |
|
|
711 |
/* Move children to the new container */
|
|
712 |
for (childIndex = 0; childIndex < index; childIndex++) {
|
|
713 |
childBox = NW_LMgr_ContainerBox_GetChild(container, 0);
|
|
714 |
|
|
715 |
/* AddChild will remove the child from the old parent */
|
|
716 |
status = NW_LMgr_ContainerBox_AddChild(splitContainer, childBox);
|
|
717 |
_NW_THROW_ON_ERROR(status);
|
|
718 |
}
|
|
719 |
|
|
720 |
/* Get and set sibling property on the cloned box's property list */
|
|
721 |
prop.value.object = NULL;
|
|
722 |
(void)NW_LMgr_Box_GetPropertyFromList(NW_LMgr_BoxOf(container),
|
|
723 |
NW_CSS_Prop_sibling, &prop);
|
|
724 |
if (prop.value.object == NULL){
|
|
725 |
/* Set sibling property on the cloned box's property list */
|
|
726 |
prop.type = NW_ADT_ValueType_Object | NW_CSS_ValueType_Copy;
|
|
727 |
prop.value.object = container;
|
|
728 |
status = NW_LMgr_Box_SetProperty(NW_LMgr_BoxOf(splitContainer),
|
|
729 |
NW_CSS_Prop_sibling, &prop);
|
|
730 |
NW_ASSERT (status == KBrsrSuccess);
|
|
731 |
}
|
|
732 |
|
|
733 |
/* Set sibling property on the master box's property list */
|
|
734 |
prop.type = NW_ADT_ValueType_Object | NW_CSS_ValueType_Copy;
|
|
735 |
prop.value.object = splitContainer;
|
|
736 |
status = NW_LMgr_Box_SetProperty(NW_LMgr_BoxOf(container),
|
|
737 |
NW_CSS_Prop_sibling, &prop);
|
|
738 |
NW_ASSERT (status == KBrsrSuccess);
|
|
739 |
|
|
740 |
#if 0
|
|
741 |
#pragma message (__FILE__ ": ::MEMO::BE AWARE that this code should be commented out. It does exist in CORE.")
|
|
742 |
// If this code is added LTR support should be added too
|
|
743 |
status = NW_LMgr_Box_SetProperty((NW_LMgr_Box_t*)splitContainer,
|
|
744 |
NW_CSS_Prop_rightPadding,
|
|
745 |
&prop);
|
|
746 |
_NW_THROW_ON_ERROR(status);
|
|
747 |
status = NW_LMgr_Box_SetProperty((NW_LMgr_Box_t*)splitContainer,
|
|
748 |
NW_CSS_Prop_rightMargin,
|
|
749 |
&prop);
|
|
750 |
_NW_THROW_ON_ERROR(status);
|
|
751 |
status = NW_LMgr_Box_SetProperty((NW_LMgr_Box_t*)container,
|
|
752 |
NW_CSS_Prop_leftPadding,
|
|
753 |
&prop);
|
|
754 |
_NW_THROW_ON_ERROR(status);
|
|
755 |
status = NW_LMgr_Box_SetProperty((NW_LMgr_Box_t*)container,
|
|
756 |
NW_CSS_Prop_leftMargin,
|
|
757 |
&prop);
|
|
758 |
_NW_THROW_ON_ERROR(status);
|
|
759 |
#endif
|
|
760 |
}
|
|
761 |
NW_CATCH(status) {
|
|
762 |
NW_Object_Delete(splitContainer);
|
|
763 |
|
|
764 |
splitContainer = NULL;
|
|
765 |
}
|
|
766 |
NW_FINALLY {
|
|
767 |
return (NW_LMgr_Box_t*)splitContainer;
|
|
768 |
}
|
|
769 |
NW_END_TRY
|
|
770 |
}
|
|
771 |
|
|
772 |
/* -------------------------------------------------------------------------- *
|
|
773 |
* Function: NW_LMgr_ContainerBox_GetBaseline
|
|
774 |
* Description: Returns the baseline of the container.
|
|
775 |
* According to the CSS spec, the baseline for boxes containing
|
|
776 |
* multiple lines of text is the baseline of the first line of
|
|
777 |
* text.
|
|
778 |
* We assume here that this also applies to boxes that contain
|
|
779 |
* mixed text and other content: i.e. that this applies to all
|
|
780 |
* containers by default.
|
|
781 |
* Returns: The baseline of the first child, or 0 if the container is
|
|
782 |
* empty.
|
|
783 |
*/
|
|
784 |
|
|
785 |
/* TODO: The box may not begin at the top of the container, so its baseline
|
|
786 |
* BUG! might be larger than is currently calculated.
|
|
787 |
*/
|
|
788 |
|
|
789 |
NW_GDI_Metric_t
|
|
790 |
_NW_LMgr_ContainerBox_GetBaseline(NW_LMgr_Box_t* box)
|
|
791 |
{
|
|
792 |
NW_LMgr_Box_t *firstChild;
|
|
793 |
|
|
794 |
if (NW_LMgr_ContainerBox_GetChildCount(NW_LMgr_ContainerBoxOf(box)) != 0){
|
|
795 |
firstChild = NW_LMgr_ContainerBox_GetChild(NW_LMgr_ContainerBoxOf(box), 0);
|
|
796 |
NW_ASSERT(firstChild != NULL);
|
|
797 |
return NW_LMgr_Box_GetBaseline(firstChild);
|
|
798 |
} else {
|
|
799 |
return 0;
|
|
800 |
}
|
|
801 |
}
|
|
802 |
|
|
803 |
/* -------------------------------------------------------------------------- *
|
|
804 |
* Function: NW_LMgr_ContainerBox_Render
|
|
805 |
* Description: Renders the container and its children.
|
|
806 |
* Returns: KBrsrSuccess, KBrsrOutOfMemory
|
|
807 |
*/
|
|
808 |
|
|
809 |
TBrowserStatusCode
|
|
810 |
_NW_LMgr_ContainerBox_Render (NW_LMgr_Box_t* box,
|
|
811 |
CGDIDeviceContext* deviceContext,
|
|
812 |
NW_GDI_Rectangle_t* clipRect,
|
|
813 |
NW_LMgr_Box_t *currentBox,
|
|
814 |
NW_Uint8 flags,
|
|
815 |
NW_Bool* hasFocus,
|
|
816 |
NW_Bool* skipChildren,
|
|
817 |
NW_LMgr_RootBox_t *rootBox )
|
|
818 |
{
|
|
819 |
NW_GDI_Rectangle_t oldClip = {{0, 0}, {0, 0}};
|
|
820 |
NW_GDI_Rectangle_t newClip;
|
|
821 |
NW_GDI_Rectangle_t realClip;
|
|
822 |
NW_GDI_Rectangle_t visibleArea;
|
|
823 |
NW_GDI_Rectangle_t viewBounds;
|
|
824 |
NW_GDI_Rectangle_t boxBounds = NW_LMgr_Box_GetDisplayBounds(box);
|
|
825 |
NW_LMgr_PropertyValue_t value;
|
|
826 |
NW_LMgr_PropertyValue_t floatVal;
|
|
827 |
NW_LMgr_PropertyValue_t visibilityVal;
|
|
828 |
NW_Bool clipRectChanged = NW_FALSE;
|
|
829 |
NW_Bool containerVisible = NW_FALSE;
|
|
830 |
void** ptr = NULL;
|
|
831 |
NW_Bool cachePresent = NW_FALSE;
|
|
832 |
|
|
833 |
NW_TRY(status)
|
|
834 |
{
|
|
835 |
// Should we draw floats?
|
|
836 |
if (!(flags & NW_LMgr_Box_Flags_DrawFloats))
|
|
837 |
{
|
|
838 |
floatVal.token = NW_CSS_PropValue_none;
|
|
839 |
NW_LMgr_Box_GetPropertyValue(box, NW_CSS_Prop_float, NW_CSS_ValueType_Token, &floatVal);
|
|
840 |
if (floatVal.token != NW_CSS_PropValue_none)
|
|
841 |
{
|
|
842 |
NW_THROW_SUCCESS( status );
|
|
843 |
}
|
|
844 |
}
|
|
845 |
// check if the this box has focus
|
|
846 |
// if hasFocus is already set to true by any parent
|
|
847 |
// then it should not be overuled.
|
|
848 |
if( !(*hasFocus) && currentBox == box )
|
|
849 |
{
|
|
850 |
*hasFocus = NW_TRUE;
|
|
851 |
}
|
|
852 |
// Get the view bounds
|
|
853 |
viewBounds = *(deviceContext->DisplayBounds());
|
|
854 |
viewBounds.point = *(deviceContext->Origin());
|
|
855 |
|
|
856 |
// Determine the part of the box within the clip.
|
|
857 |
if( !NW_GDI_Rectangle_Cross( clipRect, &boxBounds, &visibleArea ) )
|
|
858 |
{
|
|
859 |
// out of the view
|
|
860 |
goto drawChildren;
|
|
861 |
}
|
|
862 |
// Is the box visible on-screen? If not, stil try to draw
|
|
863 |
// the children
|
|
864 |
if( !NW_GDI_Rectangle_Cross( &viewBounds, &visibleArea, NULL ) )
|
|
865 |
{
|
|
866 |
goto drawChildren;
|
|
867 |
}
|
|
868 |
// If the clip is not visible on-screen, we
|
|
869 |
// draw neither the Container nor its children;
|
|
870 |
// in case we are calculating the extents, we will still
|
|
871 |
// have to peek into all children
|
|
872 |
if (!NW_GDI_Rectangle_Cross( clipRect, &viewBounds, &realClip ) )
|
|
873 |
{
|
|
874 |
goto drawChildren;
|
|
875 |
}
|
|
876 |
|
|
877 |
// Save the old clip rect
|
|
878 |
oldClip = deviceContext->ClipRect();
|
|
879 |
// Set the new clip rect
|
|
880 |
deviceContext->SetClipRect( &realClip );
|
|
881 |
clipRectChanged = NW_TRUE;
|
|
882 |
|
|
883 |
// Check if visibility val is set to not visible. In that case
|
|
884 |
// we do not draw the Container, but we still try to draw the
|
|
885 |
// children (the Visiblity prop may be overriden)
|
|
886 |
visibilityVal.token = NW_CSS_PropValue_visible;
|
|
887 |
(void) NW_LMgr_Box_GetPropertyValue (box, NW_CSS_Prop_visibility,
|
|
888 |
NW_CSS_ValueType_Token, &visibilityVal);
|
|
889 |
|
|
890 |
if (visibilityVal.token != NW_CSS_PropValue_visible)
|
|
891 |
{
|
|
892 |
goto drawChildren;
|
|
893 |
}
|
|
894 |
|
|
895 |
// make the box draw itself
|
|
896 |
status = NW_LMgr_Box_Draw( box, deviceContext, *hasFocus );
|
|
897 |
containerVisible = NW_TRUE;
|
|
898 |
_NW_THROW_ON_ERROR (status);
|
|
899 |
|
|
900 |
// Add the box and the clip to the cache
|
|
901 |
cachePresent = NW_LMgr_Box_Update_RenderCache (rootBox, box, &realClip, &ptr);
|
|
902 |
if (cachePresent)
|
|
903 |
{
|
|
904 |
NW_THROW_OOM_ON_NULL(ptr, status);
|
|
905 |
}
|
|
906 |
|
|
907 |
// Even if the Container itself is not visible, its children
|
|
908 |
// might be
|
|
909 |
// note that this is overruled in smallscreen mode as we do not
|
|
910 |
// render any children of a non visible container.
|
|
911 |
drawChildren:
|
|
912 |
|
|
913 |
// Modify the clip rectangle, if necessary
|
|
914 |
newClip = *clipRect;
|
|
915 |
value.token = NW_CSS_PropValue_visible;
|
|
916 |
(void)NW_LMgr_Box_GetPropertyValue(box, NW_CSS_Prop_overflow,
|
|
917 |
NW_CSS_ValueType_Token, &value);
|
|
918 |
|
|
919 |
if( value.token == NW_CSS_PropValue_hidden )
|
|
920 |
{
|
|
921 |
NW_LMgr_FrameInfo_t padding;
|
|
922 |
NW_LMgr_FrameInfo_t border;
|
|
923 |
NW_GDI_Rectangle_t tempClip = boxBounds;
|
|
924 |
|
|
925 |
NW_LMgr_Box_GetPadding( box, &padding, ELMgrFrameAll );
|
|
926 |
NW_LMgr_Box_GetBorderWidth( box, &border, ELMgrFrameAll );
|
|
927 |
tempClip.point.x = (NW_GDI_Metric_t)(boxBounds.point.x + padding.left
|
|
928 |
+ border.left);
|
|
929 |
tempClip.point.y = (NW_GDI_Metric_t)(boxBounds.point.y + padding.top
|
|
930 |
+ border.top);
|
|
931 |
tempClip.dimension.width = (NW_GDI_Metric_t)(boxBounds.dimension.width
|
|
932 |
- padding.left
|
|
933 |
- padding.right
|
|
934 |
- border.left - border.right);
|
|
935 |
tempClip.dimension.height = (NW_GDI_Metric_t)(boxBounds.dimension.height
|
|
936 |
- padding.top
|
|
937 |
- padding.bottom
|
|
938 |
- border.top
|
|
939 |
- border.bottom);
|
|
940 |
|
|
941 |
if (!NW_GDI_Rectangle_Cross(&tempClip, clipRect, &newClip))
|
|
942 |
{
|
|
943 |
// children are out of view
|
|
944 |
containerVisible = NW_FALSE;
|
|
945 |
NW_THROW_SUCCESS(status);
|
|
946 |
}
|
|
947 |
else
|
|
948 |
{
|
|
949 |
// modify cliprect for the children.
|
|
950 |
*clipRect = newClip;
|
|
951 |
}
|
|
952 |
}
|
|
953 |
}
|
|
954 |
NW_CATCH(status)
|
|
955 |
{
|
|
956 |
}
|
|
957 |
NW_FINALLY
|
|
958 |
{
|
|
959 |
// skip children unless the container is visible
|
|
960 |
*skipChildren = (NW_Bool)( containerVisible == NW_TRUE ? NW_FALSE : NW_TRUE );
|
|
961 |
if( clipRectChanged == NW_TRUE )
|
|
962 |
{
|
|
963 |
/* Reset the clip rect */
|
|
964 |
deviceContext->SetClipRect( &oldClip);
|
|
965 |
}
|
|
966 |
return status;
|
|
967 |
}
|
|
968 |
NW_END_TRY
|
|
969 |
}
|
|
970 |
|
|
971 |
/* ------------------------------------------------------------------------- *
|
|
972 |
* Function: NW_LMgr_ContainerBox_ResizeToChildren
|
|
973 |
* Description: Resize makes the container box just big enough to enclose all of
|
|
974 |
* its children. Although the box is invisible and has no effect
|
|
975 |
* on the enclosing flow, these bounds are available to the
|
|
976 |
* UI event mechanism to identify which action container should
|
|
977 |
* handle an event. Note a limitation here: the container box
|
|
978 |
* can't actually do this correctly until the children have all
|
|
979 |
* been formatted: something the container can't really do itself
|
|
980 |
* because it lacks a formatting context. Since formatting contexts
|
|
981 |
* are not attached to boxes, there is no way to walk up the
|
|
982 |
* tree looking for one either.
|
|
983 |
* Returns: KBrsrSuccess
|
|
984 |
*/
|
|
985 |
|
|
986 |
TBrowserStatusCode
|
|
987 |
NW_LMgr_ContainerBox_ResizeToChildren(NW_LMgr_ContainerBox_t* container)
|
|
988 |
{
|
|
989 |
NW_ADT_Vector_Metric_t numChildren;
|
|
990 |
NW_LMgr_Box_t* thisBox = NW_LMgr_BoxOf(container);
|
|
991 |
NW_ADT_Vector_Metric_t index;
|
|
992 |
const NW_ADT_Vector_t *children;
|
|
993 |
NW_LMgr_PropertyValue_t propValue;
|
|
994 |
NW_LMgr_FrameInfo_t borders, padding;
|
|
995 |
NW_GDI_Rectangle_t containerBounds = NW_LMgr_Box_GetFormatBounds(thisBox);
|
|
996 |
NW_LMgr_RootBox_t* rootBox = NW_LMgr_Box_GetRootBox( thisBox );
|
|
997 |
TBrowserStatusCode status = KBrsrSuccess;
|
|
998 |
NW_Bool FirstVisibleChild = NW_TRUE;
|
|
999 |
|
|
1000 |
NW_ASSERT(container != NULL);
|
|
1001 |
|
|
1002 |
children = NW_LMgr_ContainerBox_GetChildren(container);
|
|
1003 |
|
|
1004 |
numChildren = NW_ADT_Vector_GetSize(children);
|
|
1005 |
|
|
1006 |
// Initialize the values for the case there are no visible children.
|
|
1007 |
containerBounds.point.x = containerBounds.point.y = 0;
|
|
1008 |
containerBounds.dimension.width = containerBounds.dimension.height = 0;
|
|
1009 |
NW_LMgr_Box_SetFormatBounds( thisBox, containerBounds );
|
|
1010 |
|
|
1011 |
for (index = 0; index < numChildren; index++) {
|
|
1012 |
NW_LMgr_Box_t* child;
|
|
1013 |
|
|
1014 |
child = *(NW_LMgr_Box_t**) NW_ADT_Vector_ElementAt (children, index);
|
|
1015 |
containerBounds = NW_LMgr_Box_GetFormatBounds(thisBox);
|
|
1016 |
|
|
1017 |
// If the child box is not displayable, ignore it.
|
|
1018 |
propValue.token = NW_CSS_PropValue_display_inline;
|
|
1019 |
NW_LMgr_Box_GetPropertyValue(child, NW_CSS_Prop_display, NW_CSS_ValueType_Token, &propValue);
|
|
1020 |
if (propValue.token == NW_CSS_PropValue_none){
|
|
1021 |
continue;
|
|
1022 |
}
|
|
1023 |
|
|
1024 |
// This step is skipped in vertical layout mode (see the comment in
|
|
1025 |
// CLMgr_BoxFormatHandler::UpdateDisplayBounds) or if the child is an object-box.
|
|
1026 |
// Object-boxes are always paired with a container-box that has it as the
|
|
1027 |
// only child. Because of this it should never skip the object-box -- otherwise
|
|
1028 |
// the container-box will have 0,0 dimensions.
|
|
1029 |
//if( !NW_LMgr_RootBox_GetSmallScreenOn( rootBox ) && !ObjectUtils::IsObjectBox(*child, EFalse))
|
|
1030 |
// {
|
|
1031 |
// If the child box is a float, ignore it.
|
|
1032 |
// propValue.token = NW_CSS_PropValue_none;
|
|
1033 |
// NW_LMgr_Box_GetPropertyValue(child, NW_CSS_Prop_float, NW_CSS_ValueType_Token, &propValue);
|
|
1034 |
// if (propValue.token != NW_CSS_PropValue_none)
|
|
1035 |
// {
|
|
1036 |
// continue;
|
|
1037 |
// }
|
|
1038 |
// }
|
|
1039 |
|
|
1040 |
// If the child box is a container that has no visible children, ignore it.
|
|
1041 |
NW_GDI_Rectangle_t childBoxBounds = NW_LMgr_Box_GetFormatBounds( child );
|
|
1042 |
if ((childBoxBounds.dimension.height == 0) && (childBoxBounds.dimension.width == 0)){
|
|
1043 |
if (NW_Object_IsInstanceOf(child, &NW_LMgr_ContainerBox_Class)){
|
|
1044 |
continue;
|
|
1045 |
}
|
|
1046 |
}
|
|
1047 |
|
|
1048 |
if(FirstVisibleChild){
|
|
1049 |
FirstVisibleChild = NW_FALSE;
|
|
1050 |
NW_LMgr_Box_SetFormatBounds( NW_LMgr_BoxOf( container ), childBoxBounds );
|
|
1051 |
}
|
|
1052 |
else{
|
|
1053 |
if(childBoxBounds.point.x < containerBounds.point.x){
|
|
1054 |
containerBounds.point.x = childBoxBounds.point.x;
|
|
1055 |
NW_LMgr_Box_SetFormatBounds( thisBox, containerBounds );
|
|
1056 |
}
|
|
1057 |
|
|
1058 |
if(childBoxBounds.point.y < containerBounds.point.y){
|
|
1059 |
containerBounds.point.y = childBoxBounds.point.y;
|
|
1060 |
NW_LMgr_Box_SetFormatBounds( thisBox, containerBounds );
|
|
1061 |
}
|
|
1062 |
|
|
1063 |
if((childBoxBounds.point.x + childBoxBounds.dimension.width) >
|
|
1064 |
(containerBounds.point.x + containerBounds.dimension.width)){
|
|
1065 |
containerBounds.dimension.width = (NW_GDI_Metric_t)
|
|
1066 |
(childBoxBounds.point.x + childBoxBounds.dimension.width -
|
|
1067 |
containerBounds.point.x);
|
|
1068 |
NW_LMgr_Box_SetFormatBounds( thisBox, containerBounds );
|
|
1069 |
}
|
|
1070 |
|
|
1071 |
if((childBoxBounds.point.y + childBoxBounds.dimension.height) >
|
|
1072 |
(containerBounds.point.y + containerBounds.dimension.height)){
|
|
1073 |
containerBounds.dimension.height = (NW_GDI_Metric_t)
|
|
1074 |
(childBoxBounds.point.y + childBoxBounds.dimension.height -
|
|
1075 |
containerBounds.point.y);
|
|
1076 |
NW_LMgr_Box_SetFormatBounds( thisBox, containerBounds );
|
|
1077 |
}
|
|
1078 |
}
|
|
1079 |
}
|
|
1080 |
containerBounds = NW_LMgr_Box_GetFormatBounds(thisBox);
|
|
1081 |
|
|
1082 |
if ((containerBounds.dimension.width != 0) &&
|
|
1083 |
(containerBounds.dimension.height != 0)) {
|
|
1084 |
/* Now take into account the borders and padding */
|
|
1085 |
NW_LMgr_Box_GetBorderWidth(thisBox, &borders, ELMgrFrameAll );
|
|
1086 |
NW_LMgr_Box_GetPadding(thisBox, &padding, ELMgrFrameAll );
|
|
1087 |
containerBounds.point.x = (NW_GDI_Metric_t)(containerBounds.point.x - borders.left - padding.left);
|
|
1088 |
containerBounds.point.y = (NW_GDI_Metric_t)(containerBounds.point.y - borders.top - padding.top);
|
|
1089 |
containerBounds.dimension.width = (NW_GDI_Metric_t)(containerBounds.dimension.width +
|
|
1090 |
borders.left + padding.left + borders.right + padding.right);
|
|
1091 |
containerBounds.dimension.height = (NW_GDI_Metric_t)(containerBounds.dimension.height +
|
|
1092 |
borders.top + padding.top + borders.bottom + padding.bottom);
|
|
1093 |
}
|
|
1094 |
NW_LMgr_Box_SetFormatBounds( thisBox, containerBounds );
|
|
1095 |
return status;
|
|
1096 |
}
|
|
1097 |
|
|
1098 |
/* ------------------------------------------------------------------------- *
|
|
1099 |
* Function: NW_LMgr_ContainerBox_Initialize
|
|
1100 |
* A public method to add any anonymous block container boxes to
|
|
1101 |
* a block container that contains both block and inline content.
|
|
1102 |
* This assures that all content in a block box participates
|
|
1103 |
* in the same format context (either block or inline). This becomes
|
|
1104 |
* essential when margins are collapsed. CSS2 p98.
|
|
1105 |
*/
|
|
1106 |
|
|
1107 |
TBrowserStatusCode
|
|
1108 |
NW_LMgr_ContainerBox_Initialize(NW_LMgr_ContainerBox_t *container)
|
|
1109 |
{
|
|
1110 |
NW_TRY (status)
|
|
1111 |
{
|
|
1112 |
NW_ADT_Vector_Metric_t index;
|
|
1113 |
const NW_ADT_Vector_t *children;
|
|
1114 |
NW_LMgr_Box_t* child;
|
|
1115 |
NW_LMgr_ContainerBox_t *newContainer;
|
|
1116 |
NW_LMgr_PropertyValue_t floatVal;
|
|
1117 |
|
|
1118 |
children = NW_LMgr_ContainerBox_GetChildren(container);
|
|
1119 |
|
|
1120 |
index = 0;
|
|
1121 |
while (index < NW_ADT_Vector_GetSize(children)) {
|
|
1122 |
|
|
1123 |
child = *(NW_LMgr_Box_t**) NW_ADT_Vector_ElementAt (children, index);
|
|
1124 |
|
|
1125 |
if (NW_Object_IsInstanceOf(child, &NW_LMgr_SplitTextBox_Class))
|
|
1126 |
{
|
|
1127 |
NW_Object_Delete(child);
|
|
1128 |
child = NULL;
|
|
1129 |
continue;
|
|
1130 |
}
|
|
1131 |
|
|
1132 |
else if (NW_Object_IsInstanceOf(child, &NW_LMgr_AbstractTextBox_Class))
|
|
1133 |
{
|
|
1134 |
if( NW_LMgr_AbstractTextBox_IsBlank(NW_LMgr_AbstractTextBoxOf(child)) )
|
|
1135 |
{
|
|
1136 |
NW_Object_Delete(child);
|
|
1137 |
child = NULL;
|
|
1138 |
continue;
|
|
1139 |
}
|
|
1140 |
}
|
|
1141 |
|
|
1142 |
else if (NW_Object_IsInstanceOf(child, &NW_LMgr_FlowBox_Class) ||
|
|
1143 |
NW_Object_IsClass(child, &NW_LMgr_StaticTableBox_Class) ||
|
|
1144 |
NW_Object_IsClass(child, &NW_LMgr_StaticTableRowBox_Class)) {
|
|
1145 |
|
|
1146 |
floatVal.token = NW_CSS_PropValue_none;
|
|
1147 |
status = NW_LMgr_Box_GetPropertyValue(child, NW_CSS_Prop_float, NW_CSS_ValueType_Token, &floatVal);
|
|
1148 |
if (status == KBrsrOutOfMemory) {
|
|
1149 |
return KBrsrOutOfMemory;
|
|
1150 |
}
|
|
1151 |
|
|
1152 |
if (floatVal.token == NW_CSS_PropValue_none) {
|
|
1153 |
|
|
1154 |
newContainer = NW_LMgr_ContainerBox_New(0);
|
|
1155 |
NW_THROW_OOM_ON_NULL(newContainer, status);
|
|
1156 |
|
|
1157 |
status = NW_LMgr_ContainerBox_AppendChildrenOf(newContainer, NW_LMgr_ContainerBoxOf(child));
|
|
1158 |
_NW_THROW_ON_ERROR(status);
|
|
1159 |
|
|
1160 |
status = NW_LMgr_ContainerBox_ReplaceChild(container, child, NW_LMgr_BoxOf(newContainer));
|
|
1161 |
_NW_THROW_ON_ERROR(status);
|
|
1162 |
|
|
1163 |
(void) NW_LMgr_Box_SetPropList(NW_LMgr_BoxOf(newContainer), NW_LMgr_Box_PropListGet(child));
|
|
1164 |
(void) NW_LMgr_Box_SetPropList(child, NULL);
|
|
1165 |
NW_LMgr_Box_RemoveProperty(NW_LMgr_BoxOf(newContainer), NW_CSS_Prop_display);
|
|
1166 |
NW_LMgr_Box_RemoveProperty(NW_LMgr_BoxOf(newContainer), NW_CSS_Prop_float);
|
|
1167 |
|
|
1168 |
NW_Object_Delete(child);
|
|
1169 |
child = NULL;
|
|
1170 |
}
|
|
1171 |
}
|
|
1172 |
|
|
1173 |
index ++;
|
|
1174 |
}
|
|
1175 |
|
|
1176 |
} NW_CATCH (status) {
|
|
1177 |
} NW_FINALLY {
|
|
1178 |
return KBrsrSuccess;
|
|
1179 |
} NW_END_TRY
|
|
1180 |
}
|
|
1181 |
|
|
1182 |
/* ------------------------------------------------------------------------- *
|
|
1183 |
* Function: NW_LMgr_ContainerBox_InitializeSSL
|
|
1184 |
* A public method to remove empty text child box in small screen mode
|
|
1185 |
*/
|
|
1186 |
|
|
1187 |
TBrowserStatusCode
|
|
1188 |
NW_LMgr_ContainerBox_InitializeSSL(NW_LMgr_ContainerBox_t *container)
|
|
1189 |
{
|
|
1190 |
TBrowserStatusCode status = KBrsrSuccess;
|
|
1191 |
NW_ADT_Vector_Metric_t index;
|
|
1192 |
const NW_ADT_Vector_t *children;
|
|
1193 |
NW_LMgr_Box_t* child;
|
|
1194 |
|
|
1195 |
children = NW_LMgr_ContainerBox_GetChildren(container);
|
|
1196 |
|
|
1197 |
index = 0;
|
|
1198 |
while (index < NW_ADT_Vector_GetSize(children))
|
|
1199 |
{
|
|
1200 |
child = *(NW_LMgr_Box_t**) NW_ADT_Vector_ElementAt (children, index);
|
|
1201 |
|
|
1202 |
if (NW_Object_IsInstanceOf(child, &NW_LMgr_AbstractTextBox_Class))
|
|
1203 |
{
|
|
1204 |
if( NW_LMgr_AbstractTextBox_IsBlank(NW_LMgr_AbstractTextBoxOf(child)) )
|
|
1205 |
{
|
|
1206 |
NW_Object_Delete(child);
|
|
1207 |
child = NULL;
|
|
1208 |
continue;
|
|
1209 |
}
|
|
1210 |
}
|
|
1211 |
index ++;
|
|
1212 |
}
|
|
1213 |
|
|
1214 |
return status;
|
|
1215 |
}
|
|
1216 |
|
|
1217 |
NW_Bool NW_LMgr_ContainerBox_IsLastChild(NW_LMgr_Box_t* box)
|
|
1218 |
{
|
|
1219 |
return box == NW_LMgr_BoxOf(NW_LMgr_ContainerBox_GetChild(NW_LMgr_Box_GetParent((box)),
|
|
1220 |
(NW_ADT_Vector_Metric_t) (NW_LMgr_ContainerBox_GetChildCount(NW_LMgr_Box_GetParent((box))) - 1 )));
|
|
1221 |
}
|
|
1222 |
|
|
1223 |
/* ------------------------------------------------------------------------- *
|
|
1224 |
convenience functions
|
|
1225 |
* ------------------------------------------------------------------------- */
|
|
1226 |
|
|
1227 |
/* ------------------------------------------------------------------------- */
|
|
1228 |
NW_LMgr_ContainerBox_t*
|
|
1229 |
NW_LMgr_ContainerBox_New (NW_ADT_Vector_Metric_t numProperties)
|
|
1230 |
{
|
|
1231 |
return (NW_LMgr_ContainerBox_t*)
|
|
1232 |
NW_Object_New (&NW_LMgr_ContainerBox_Class, numProperties);
|
|
1233 |
}
|
|
1234 |
|
|
1235 |
|
|
1236 |
|
|
1237 |
|
|
1238 |
|