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
|
/*
* Dillo Widget
*
* Copyright 2013-2014 Sebastian Geerken <sgeerken@dillo.org>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version.
*
* This program 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 General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "oofpositionedmgr.hh"
#include "textblock.hh"
#include "../lout/debug.hh"
using namespace lout::object;
using namespace lout::container::typed;
using namespace lout::misc;
using namespace dw::core;
using namespace dw::core::style;
namespace dw {
OOFPositionedMgr::OOFPositionedMgr (Textblock *containingBlock)
{
DBG_OBJ_CREATE ("dw::OOFPositionedMgr");
this->containingBlock = (Textblock*)containingBlock;
children = new Vector<Widget> (1, false);
DBG_OBJ_SET_NUM ("children.size", children->size());
}
OOFPositionedMgr::~OOFPositionedMgr ()
{
delete children;
DBG_OBJ_DELETE ();
}
void OOFPositionedMgr::sizeAllocateStart (Textblock *caller,
Allocation *allocation)
{
containingBlockAllocation = *allocation;
}
void OOFPositionedMgr::sizeAllocateEnd (Textblock *caller)
{
DBG_OBJ_ENTER ("resize.oofm", 0, "sizeAllocateEnd", "%p", caller);
if (caller == containingBlock) {
sizeAllocateChildren ();
bool sizeChanged = doChildrenExceedCB ();
bool extremesChanged = haveExtremesChanged ();
if (sizeChanged || extremesChanged)
containingBlock->oofSizeChanged (extremesChanged);
}
DBG_OBJ_LEAVE ();
}
void OOFPositionedMgr::sizeAllocateChildren ()
{
DBG_OBJ_ENTER0 ("resize.oofm", 0, "sizeAllocateChildren");
int refWidth = containingBlock->getAvailWidth (true);
int refHeight = containingBlock->getAvailHeight (true);
for (int i = 0; i < children->size(); i++) {
Widget *child = children->get (i);
int x, y, width, ascent, descent;
calcPosAndSizeChildOfChild (child, refWidth, refHeight, &x, &y, &width,
&ascent, &descent);
Allocation childAllocation;
childAllocation.x = containingBlockAllocation.x + x;
childAllocation.y = containingBlockAllocation.y + y;
childAllocation.width = width;
childAllocation.ascent = ascent;
childAllocation.descent = descent;
child->sizeAllocate (&childAllocation);
}
DBG_OBJ_LEAVE ();
}
void OOFPositionedMgr::containerSizeChangedForChildren ()
{
DBG_OBJ_ENTER0 ("resize", 0, "containerSizeChangedForChildren");
for (int i = 0; i < children->size(); i++)
children->get(i)->containerSizeChanged ();
DBG_OBJ_LEAVE ();
}
bool OOFPositionedMgr::doChildrenExceedCB ()
{
#if 0
DBG_OBJ_ENTER ("resize.oofm", 0, "doFloatsExceedCB", "%s",
side == LEFT ? "LEFT" : "RIGHT");
// This method is called to determine whether the *requisition* of
// the CB must be recalculated. So, we check the float allocations
// against the *requisition* of the CB, which may (e. g. within
// tables) differ from the new allocation. (Generally, a widget may
// allocated at a different size.)
Requisition cbReq;
containingBlock->sizeRequest (&cbReq);
for (int i = 0; i < children->size () && !exceeds; i++) {
Widget *child = children->get (i);
Allocation *childAlloc = child->getAllocation ();
DBG_OBJ_MSGF ("resize.oofm", 2,
"Does childAlloc = (%d, %d, %d * %d) exceed CBA = "
"(%d, %d, %d * %d)?",
childAlloc->x, childAlloc->y, childAlloc->width,
childAlloc->ascent + childAlloc->descent,
containingBlockAllocation.x, containingBlockAllocation.y,
cbReq.width, cbReq.ascent + cbReq.descent);
if (childAlloc->x + childAlloc->width
> containingBlockAllocation.x + cbReq.width ||
childAlloc->y + childAlloc->ascent + childAlloc->descent
> containingBlockAllocation.y + cbReq.ascent + cbReq.descent) {
exceeds = true;
DBG_OBJ_MSG ("resize.oofm", 2, "Yes.");
} else
DBG_OBJ_MSG ("resize.oofm", 2, "No.");
}
DBG_OBJ_MSGF ("resize.oofm", 1, "=> %s", exceeds ? "true" : "false");
DBG_OBJ_LEAVE ();
return exceeds;
#endif
return false;
}
bool OOFPositionedMgr::haveExtremesChanged ()
{
// TODO Something to do?
return false;
}
void OOFPositionedMgr::draw (View *view, Rectangle *area)
{
DBG_OBJ_ENTER ("draw", 0, "draw", "%d, %d, %d * %d",
area->x, area->y, area->width, area->height);
for (int i = 0; i < children->size(); i++) {
Widget *child = children->get(i);
Rectangle childArea;
if (child->intersects (area, &childArea))
child->draw (view, &childArea);
}
DBG_OBJ_LEAVE ();
}
void OOFPositionedMgr::addWidgetInFlow (Textblock *textblock,
Textblock *parentBlock, int externalIndex)
{
}
int OOFPositionedMgr::addWidgetOOF (Widget *widget, Textblock *generatingBlock,
int externalIndex)
{
DBG_OBJ_ENTER ("construct.oofm", 0, "addWidgetOOF", "%p, %p, %d",
widget, generatingBlock, externalIndex);
children->put (widget);
int subRef = children->size() - 1;
DBG_OBJ_SET_NUM ("children.size", children->size());
DBG_OBJ_ARRSET_PTR ("children", children->size() - 1, widget);
DBG_OBJ_MSGF ("construct.oofm", 1, "=> %d", subRef);
DBG_OBJ_LEAVE ();
return subRef;
}
void OOFPositionedMgr::moveExternalIndices (Textblock *generatingBlock,
int oldStartIndex, int diff)
{
}
void OOFPositionedMgr::markSizeChange (int ref)
{
}
void OOFPositionedMgr::markExtremesChange (int ref)
{
}
Widget *OOFPositionedMgr::getWidgetAtPoint (int x, int y, int level)
{
for (int i = 0; i < children->size(); i++) {
Widget *child = children->get(i);
if (child->wasAllocated ()) {
Widget *childAtPoint = child->getWidgetAtPoint (x, y, level + 1);
if (childAtPoint)
return childAtPoint;
}
}
return NULL;
}
void OOFPositionedMgr::tellPosition (Widget *widget, int yReq)
{
}
void OOFPositionedMgr::getSize (Requisition *cbReq, int *oofWidth,
int *oofHeight)
{
DBG_OBJ_ENTER0 ("resize.oofm", 0, "getSize");
*oofWidth = *oofHeight = 0;
int refWidth = containingBlock->getAvailWidth (true);
int refHeight = containingBlock->getAvailHeight (true);
for (int i = 0; i < children->size(); i++) {
Widget *child = children->get(i);
int x, y, width, ascent, descent;
calcPosAndSizeChildOfChild (child, refWidth, refHeight, &x, &y, &width,
&ascent, &descent);
*oofWidth = max (*oofWidth, x + width);
*oofHeight = max (*oofHeight, y + ascent + descent);
}
DBG_OBJ_LEAVE ();
}
void OOFPositionedMgr::getExtremes (Extremes *cbExtr, int *oofMinWidth,
int *oofMaxWidth)
{
DBG_OBJ_ENTER ("resize.oofm", 0, "getExtremes", "(%d / %d), ...",
cbExtr->minWidth, cbExtr->maxWidth);
// TODO Something to do?
*oofMinWidth = *oofMaxWidth = 0;
DBG_OBJ_LEAVE ();
}
int OOFPositionedMgr::getLeftBorder (Textblock *textblock, int y, int h,
Textblock *lastGB, int lastExtIndex)
{
return 0;
}
int OOFPositionedMgr::getRightBorder (Textblock *textblock, int y, int h,
Textblock *lastGB, int lastExtIndex)
{
return 0;
}
bool OOFPositionedMgr::hasFloatLeft (Textblock *textblock, int y, int h,
Textblock *lastGB, int lastExtIndex)
{
return false;
}
bool OOFPositionedMgr::hasFloatRight (Textblock *textblock, int y, int h,
Textblock *lastGB, int lastExtIndex)
{
return false;
}
int OOFPositionedMgr::getLeftFloatHeight (Textblock *textblock, int y, int h,
Textblock *lastGB, int lastExtIndex)
{
return 0;
}
int OOFPositionedMgr::getRightFloatHeight (Textblock *textblock, int y, int h,
Textblock *lastGB, int lastExtIndex)
{
return 0;
}
int OOFPositionedMgr::getClearPosition (Textblock *textblock)
{
return 0;
}
bool OOFPositionedMgr::affectsLeftBorder (Widget *widget)
{
return false;
}
bool OOFPositionedMgr::affectsRightBorder (Widget *widget)
{
return false;
}
bool OOFPositionedMgr::dealingWithSizeOfChild (Widget *child)
{
return true;
}
int OOFPositionedMgr::getAvailWidthOfChild (Widget *child, bool forceValue)
{
DBG_OBJ_ENTER ("resize.oofm", 0,
"OOFPositionedMgr/getAvailWidthOfChild", "%p, %s",
child, forceValue ? "true" : "false");
int width;
if (child->getStyle()->width == style::LENGTH_AUTO &&
child->getStyle()->minWidth == style::LENGTH_AUTO &&
child->getStyle()->maxWidth == style::LENGTH_AUTO) {
// TODO This should (perhaps?) only used when 'width' is undefined.
// TODO Is "boxDiffWidth()" correct here?
DBG_OBJ_MSG ("resize.oofm", 1, "no specification");
if (forceValue) {
int availWidth = containingBlock->getAvailWidth (true);
width = max (availWidth - containingBlock->boxDiffWidth ()
- getPosLeft (child, availWidth)
- getPosRight (child, availWidth),
0);
} else
width = -1;
} else
// TODO Percentage widths must refer to padding area.
child->calcFinalWidth (child->getStyle(), -1, containingBlock, 0,
forceValue, &width);
if (width != -1)
width = max (width, child->getMinWidth (NULL, forceValue));
DBG_OBJ_MSGF ("resize.oofm", 1, "=> %d", width);
DBG_OBJ_LEAVE ();
return width;
}
int OOFPositionedMgr::getAvailHeightOfChild (Widget *child, bool forceValue)
{
// TODO FF shows a bit different priority for heights than for
// widths, in case of over-determined values.
DBG_OBJ_ENTER ("resize.oofm", 0,
"OOFPositionedMgr/getAvailHeightOfChild", "%p, %s",
child, forceValue ? "true" : "false");
int height;
if (child->getStyle()->height == style::LENGTH_AUTO &&
child->getStyle()->minHeight == style::LENGTH_AUTO &&
child->getStyle()->maxHeight == style::LENGTH_AUTO) {
// TODO This should (perhaps?) only used when 'height' is undefined.
// TODO Is "boxDiffHeight()" correct here?
DBG_OBJ_MSG ("resize.oofm", 1, "no specification");
if (forceValue) {
int availHeight = containingBlock->getAvailHeight (true);
height = max (availHeight - containingBlock->boxDiffHeight ()
- getPosTop (child, availHeight)
- getPosBottom (child, availHeight),
0);
} else
height = -1;
} else
// TODO Percentage heights must refer to padding area.
height = child->calcHeight (child->getStyle()->height, true, -1,
containingBlock, forceValue);
DBG_OBJ_MSGF ("resize.oofm", 1, "=> %d", height);
DBG_OBJ_LEAVE ();
return height;
}
int OOFPositionedMgr::getPosBorder (style::Length cssValue, int refLength)
{
if (style::isAbsLength (cssValue))
return style::absLengthVal (cssValue);
else if (style::isPerLength (cssValue))
return style::multiplyWithPerLength (refLength, cssValue);
else
// standard value for 'left', 'right', 'top', 'bottom':
return 0;
}
void OOFPositionedMgr::calcPosAndSizeChildOfChild (Widget *child, int refWidth,
int refHeight, int *x,
int *y, int *width,
int *ascent, int *descent)
{
DBG_OBJ_ENTER ("resize.oofm", 0, "calcPosAndSizeChildOfChild",
"%p, %d, %d, ...", child, refWidth, refHeight);
Requisition childRequisition;
child->sizeRequest (&childRequisition);
*x = getPosLeft (child, refWidth);
*y = getPosTop (child, refHeight);
// TODO (i) Consider {min|max}-{width|heigt}. (ii) Clarify where
// sizes refer to. (iii) Height is always apportioned to descent
// (ascent is preserved), which makes sense when the children are
// textblocks. (iv) Consider minimal width (getMinWidth)?
if (style::isAbsLength (child->getStyle()->width))
*width = style::absLengthVal (child->getStyle()->width);
else if (style::isPerLength (child->getStyle()->width))
*width = style::multiplyWithPerLength (refWidth,
child->getStyle()->width);
else
*width = childRequisition.width;
*ascent = childRequisition.ascent;
*descent = childRequisition.descent;
if (style::isAbsLength (child->getStyle()->height)) {
DBG_OBJ_MSGF ("resize.oofm", 1, "absolute height: %dpx",
style::absLengthVal (child->getStyle()->height));
int height = style::absLengthVal (child->getStyle()->height);
splitHeightPreserveAscent (height, ascent, descent);
} else if (style::isPerLength (child->getStyle()->height)) {
DBG_OBJ_MSGF ("resize.oofm", 1, "percentage height: %g%%",
100 * style::perLengthVal_useThisOnlyForDebugging
(child->getStyle()->height));
int height = style::multiplyWithPerLength (refHeight,
child->getStyle()->height);
splitHeightPreserveAscent (height, ascent, descent);
} else
DBG_OBJ_MSG ("resize.oofm", 1, "height not specified");
DBG_OBJ_MSGF ("resize.oofm", 0, "=> %d, %d, %d * (%d + %d)",
*x, *y, *width, *ascent, *descent);
DBG_OBJ_LEAVE ();
}
int OOFPositionedMgr::getNumWidgets ()
{
return children->size();
}
Widget *OOFPositionedMgr::getWidget (int i)
{
return children->get (i);
}
} // namespace dw
|