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
|
/*
* Dillo Widget
*
* Copyright 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 "oofawarewidget.hh"
#include "ooffloatsmgr.hh"
#include "oofposabsmgr.hh"
#include "oofposfixedmgr.hh"
using namespace dw;
using namespace dw::core;
using namespace lout::misc;
namespace dw {
namespace oof {
int OOFAwareWidget::CLASS_ID = -1;
OOFAwareWidget::OOFAwareWidget ()
{
DBG_OBJ_CREATE ("dw::oof::OOFAwareWidget");
registerName ("dw::oof::OOFAwareWidget", &CLASS_ID);
for (int i = 0; i < NUM_OOFM; i++) {
oofContainer[i] = NULL;
outOfFlowMgr[i] = NULL;
}
}
OOFAwareWidget::~OOFAwareWidget ()
{
for (int i = 0; i < NUM_OOFM; i++) {
if(outOfFlowMgr[i]) {
// I feel more comfortable by letting the OOF aware widget delete
// these widgets, instead of doing this in ~OutOfFlowMgr.
for (int j = 0; j < outOfFlowMgr[i]->getNumWidgets (); j++)
delete outOfFlowMgr[i]->getWidget (j);
delete outOfFlowMgr[i];
}
}
DBG_OBJ_DELETE ();
}
void OOFAwareWidget::notifySetAsTopLevel()
{
oofContainer[OOFM_FLOATS] = oofContainer[OOFM_ABSOLUTE]
= oofContainer[OOFM_FIXED] = this;
}
bool OOFAwareWidget::isOOFContainer (Widget *widget, int oofmIndex)
{
// TODO The methods isPossibleContainer() and isPossibleContainerParent()
// are only used in few cases. Does not matter currently, however.
switch (oofmIndex) {
case OOFM_FLOATS:
return widget->instanceOf (OOFAwareWidget::CLASS_ID) &&
(// For floats, only some OOF aware widgets are considered as
// containers.
((OOFAwareWidget*)widget)->isPossibleContainer (OOFM_FLOATS) &&
// The second condition: that this block is "out of flow", in a
// wider sense.
(// The toplevel widget is "out of flow", since there is no
// parent, and so no context.
widget->getParent() == NULL ||
// A similar reasoning applies to a widget with an
// unsuitable parent (typical example: a table cell (this
// is also a text block, so possible float container)
// within a table widget, which is not a suitable float
// container parent).
!(widget->getParent()->instanceOf (OOFAwareWidget::CLASS_ID) &&
((OOFAwareWidget*)widget->getParent())
->isPossibleContainerParent (OOFM_FLOATS)) ||
// Inline blocks are containing blocks, too.
widget->getStyle()->display == core::style::DISPLAY_INLINE_BLOCK ||
// Finally, "out of flow" in a narrower sense: floats; absolutely
// and fixedly positioned elements.
testWidgetOutOfFlow (widget)));
case OOFM_ABSOLUTE:
// Only the toplevel widget (as for all) as well as absolutely,
// relatively, and fixedly positioned elements constitute the
// containing block for absolutely positioned elements, but
// neither floats nor other elements like table cells.
//
// (Notice that relative positions are not yet supported, but
// only tested to get the correct containing block. Furthermore,
// it seems that this test would be incorrect for floats.)
//
// We also test whether this widget is a textblock: is this
// necessary? (What about other absolutely widgets containing
// children, like tables? TODO: Check CSS spec.)
return widget->instanceOf (OOFAwareWidget::CLASS_ID) &&
(widget->getParent() == NULL ||
testWidgetAbsolutelyPositioned (widget) ||
testWidgetRelativelyPositioned (widget) ||
testWidgetFixedlyPositioned (widget));
case OOFM_FIXED:
// The single container for fixedly positioned elements is the
// toplevel (canvas; actually the viewport). (The toplevel
// widget should always be a textblock; at least this is the
// case in dillo.)
return widget->getParent() == NULL;
default:
// compiler happiness
lout::misc::assertNotReached ();
return false;
}
}
void OOFAwareWidget::notifySetParent ()
{
// Search for containing blocks.
for (int oofmIndex = 0; oofmIndex < NUM_OOFM; oofmIndex++) {
oofContainer[oofmIndex] = NULL;
for (Widget *widget = this;
widget != NULL && oofContainer[oofmIndex] == NULL;
widget = widget->getParent ())
if (isOOFContainer (widget, oofmIndex)) {
assert (widget->instanceOf (OOFAwareWidget::CLASS_ID));
oofContainer[oofmIndex] = (OOFAwareWidget*)widget;
}
DBG_OBJ_ARRSET_PTR ("oofContainer", oofmIndex, oofContainer[oofmIndex]);
assert (oofContainer[oofmIndex] != NULL);
}
}
void OOFAwareWidget::initOutOfFlowMgrs ()
{
if (oofContainer[OOFM_FLOATS]->outOfFlowMgr[OOFM_FLOATS] == NULL) {
oofContainer[OOFM_FLOATS]->outOfFlowMgr[OOFM_FLOATS] =
new OOFFloatsMgr (oofContainer[OOFM_FLOATS]);
DBG_OBJ_ASSOC (oofContainer[OOFM_FLOATS],
oofContainer[OOFM_FLOATS]->outOfFlowMgr[OOFM_FLOATS]);
}
if (oofContainer[OOFM_ABSOLUTE]->outOfFlowMgr[OOFM_ABSOLUTE] == NULL) {
oofContainer[OOFM_ABSOLUTE]->outOfFlowMgr[OOFM_ABSOLUTE] =
new OOFPosAbsMgr (oofContainer[OOFM_ABSOLUTE]);
DBG_OBJ_ASSOC (oofContainer[OOFM_ABSOLUTE],
oofContainer[OOFM_ABSOLUTE]->outOfFlowMgr[OOFM_ABSOLUTE]);
}
if (oofContainer[OOFM_FIXED]->outOfFlowMgr[OOFM_FIXED] == NULL) {
oofContainer[OOFM_FIXED]->outOfFlowMgr[OOFM_FIXED] =
new OOFPosFixedMgr (oofContainer[OOFM_FIXED]);
DBG_OBJ_ASSOC (oofContainer[OOFM_FIXED],
oofContainer[OOFM_FIXED]->outOfFlowMgr[OOFM_FIXED]);
}
}
void OOFAwareWidget::correctRequisitionByOOF (Requisition *requisition)
{
for (int i = 0; i < NUM_OOFM; i++) {
if (outOfFlowMgr[i]) {
int oofWidth, oofHeight;
DBG_OBJ_MSGF ("resize", 1,
"before considering widgets by OOFM #%d: %d * (%d + %d)",
i, requisition->width, requisition->ascent,
requisition->descent);
outOfFlowMgr[i]->getSize (requisition, &oofWidth, &oofHeight);
if (oofWidth > requisition->width)
requisition->width = oofWidth;
if (oofHeight > requisition->ascent + requisition->descent)
requisition->descent = oofHeight - requisition->ascent;
}
}
}
void OOFAwareWidget::correctExtremesByOOF (Extremes *extremes)
{
for (int i = 0; i < NUM_OOFM; i++) {
if (outOfFlowMgr[i]) {
int oofMinWidth, oofMaxWidth;
outOfFlowMgr[i]->getExtremes (extremes, &oofMinWidth, &oofMaxWidth);
DBG_OBJ_MSGF ("resize", 1, "OOFM (#%d) correction: %d / %d",
i, oofMinWidth, oofMaxWidth);
extremes->minWidth = max (extremes->minWidth, oofMinWidth);
extremes->minWidthIntrinsic = max (extremes->minWidthIntrinsic,
oofMinWidth);
extremes->maxWidth = max (extremes->maxWidth, oofMaxWidth);
extremes->maxWidthIntrinsic = max (extremes->maxWidthIntrinsic,
oofMinWidth);
}
}
}
void OOFAwareWidget::sizeAllocateStart (core::Allocation *allocation)
{
for (int i = 0; i < NUM_OOFM; i++)
if (oofContainer[i]->outOfFlowMgr[i])
oofContainer[i]->outOfFlowMgr[i]->sizeAllocateStart (this, allocation);
}
void OOFAwareWidget::sizeAllocateEnd ()
{
for (int i = 0; i < NUM_OOFM; i++)
if (oofContainer[i]->outOfFlowMgr[i])
oofContainer[i]->outOfFlowMgr[i]->sizeAllocateEnd (this);
}
void OOFAwareWidget::containerSizeChangedForChildrenOOF ()
{
for (int i = 0; i < NUM_OOFM; i++)
if (outOfFlowMgr[i])
outOfFlowMgr[i]->containerSizeChangedForChildren ();
}
void OOFAwareWidget::drawOOF (View *view, Rectangle *area)
{
for (int i = 0; i < NUM_OOFM; i++)
if(outOfFlowMgr[i])
outOfFlowMgr[i]->draw(view, area);
}
Widget *OOFAwareWidget::getWidgetOOFAtPoint (int x, int y, int level)
{
for (int i = 0; i < NUM_OOFM; i++) {
Widget *oofWidget =
outOfFlowMgr[i] ?
outOfFlowMgr[i]->getWidgetAtPoint (x, y, level) : NULL;
if (oofWidget)
return oofWidget;
}
return NULL;
}
void OOFAwareWidget::borderChanged (int y, Widget *vloat)
{
assertNotReached ();
}
void OOFAwareWidget::oofSizeChanged (bool extremesChanged)
{
DBG_OBJ_ENTER ("resize", 0, "oofSizeChanged", "%s",
extremesChanged ? "true" : "false");
queueResize (-1, extremesChanged);
// Extremes changes may become also relevant for the children.
if (extremesChanged)
containerSizeChanged ();
DBG_OBJ_LEAVE ();
}
int OOFAwareWidget::getLineBreakWidth ()
{
assertNotReached ();
return 0;
}
bool OOFAwareWidget::isPossibleContainer (int oofmIndex)
{
return oofmIndex != OOFM_FLOATS;
}
bool OOFAwareWidget::isPossibleContainerParent (int oofmIndex)
{
return oofmIndex != OOFM_FLOATS;
}
} // namespace oof
} // namespace dw
|