author | Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com> |
Mon, 03 May 2010 13:17:34 +0300 | |
changeset 19 | fcece45ef507 |
parent 0 | 1918ee327afb |
child 30 | 5dc02b23752f |
permissions | -rw-r--r-- |
0 | 1 |
/* |
2 |
* Copyright (C) 1999 Lars Knoll (knoll@kde.org) |
|
3 |
* (C) 1999 Antti Koivisto (koivisto@kde.org) |
|
4 |
* (C) 2000 Dirk Mueller (mueller@kde.org) |
|
5 |
* (C) 2004 Allan Sandfeld Jensen (kde@carewolf.com) |
|
6 |
* Copyright (C) 2004, 2005, 2006, 2007, 2008 Apple Inc. All rights reserved. |
|
7 |
* Copyright (C) 2009 Torch Mobile Inc. All rights reserved. (http://www.torchmobile.com/) |
|
8 |
* |
|
9 |
* This library is free software; you can redistribute it and/or |
|
10 |
* modify it under the terms of the GNU Library General Public |
|
11 |
* License as published by the Free Software Foundation; either |
|
12 |
* version 2 of the License, or (at your option) any later version. |
|
13 |
* |
|
14 |
* This library is distributed in the hope that it will be useful, |
|
15 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
16 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
|
17 |
* Library General Public License for more details. |
|
18 |
* |
|
19 |
* You should have received a copy of the GNU Library General Public License |
|
20 |
* along with this library; see the file COPYING.LIB. If not, write to |
|
21 |
* the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, |
|
22 |
* Boston, MA 02110-1301, USA. |
|
23 |
* |
|
24 |
*/ |
|
25 |
||
26 |
#include "config.h" |
|
27 |
#include "RenderObject.h" |
|
28 |
||
29 |
#include "AXObjectCache.h" |
|
30 |
#include "CSSStyleSelector.h" |
|
31 |
#include "FloatQuad.h" |
|
32 |
#include "Frame.h" |
|
33 |
#include "FrameView.h" |
|
34 |
#include "GraphicsContext.h" |
|
35 |
#include "HTMLNames.h" |
|
36 |
#include "HitTestResult.h" |
|
37 |
#include "Page.h" |
|
38 |
#include "RenderArena.h" |
|
39 |
#include "RenderCounter.h" |
|
40 |
#include "RenderFlexibleBox.h" |
|
41 |
#include "RenderImageGeneratedContent.h" |
|
42 |
#include "RenderInline.h" |
|
43 |
#include "RenderListItem.h" |
|
44 |
#include "RenderTableCell.h" |
|
45 |
#include "RenderTableCol.h" |
|
46 |
#include "RenderTableRow.h" |
|
47 |
#include "RenderTheme.h" |
|
48 |
#include "RenderView.h" |
|
49 |
#include "TransformState.h" |
|
50 |
#include "htmlediting.h" |
|
51 |
#include <algorithm> |
|
52 |
#include <stdio.h> |
|
53 |
#include <wtf/RefCountedLeakCounter.h> |
|
54 |
#include <wtf/UnusedParam.h> |
|
55 |
||
56 |
#if USE(ACCELERATED_COMPOSITING) |
|
57 |
#include "RenderLayerCompositor.h" |
|
58 |
#endif |
|
59 |
||
60 |
#if ENABLE(WML) |
|
61 |
#include "WMLNames.h" |
|
62 |
#endif |
|
63 |
||
64 |
using namespace std; |
|
65 |
||
66 |
namespace WebCore { |
|
67 |
||
68 |
using namespace HTMLNames; |
|
69 |
||
70 |
#ifndef NDEBUG |
|
71 |
static void* baseOfRenderObjectBeingDeleted; |
|
72 |
#endif |
|
73 |
||
74 |
bool RenderObject::s_affectsParentBlock = false; |
|
75 |
||
76 |
void* RenderObject::operator new(size_t sz, RenderArena* renderArena) throw() |
|
77 |
{ |
|
78 |
return renderArena->allocate(sz); |
|
79 |
} |
|
80 |
||
81 |
void RenderObject::operator delete(void* ptr, size_t sz) |
|
82 |
{ |
|
83 |
ASSERT(baseOfRenderObjectBeingDeleted == ptr); |
|
84 |
||
85 |
// Stash size where destroy can find it. |
|
86 |
*(size_t *)ptr = sz; |
|
87 |
} |
|
88 |
||
89 |
RenderObject* RenderObject::createObject(Node* node, RenderStyle* style) |
|
90 |
{ |
|
91 |
Document* doc = node->document(); |
|
92 |
RenderArena* arena = doc->renderArena(); |
|
93 |
||
94 |
// Minimal support for content properties replacing an entire element. |
|
95 |
// Works only if we have exactly one piece of content and it's a URL. |
|
96 |
// Otherwise acts as if we didn't support this feature. |
|
97 |
const ContentData* contentData = style->contentData(); |
|
98 |
if (contentData && !contentData->next() && contentData->isImage() && doc != node) { |
|
99 |
RenderImageGeneratedContent* image = new (arena) RenderImageGeneratedContent(node); |
|
100 |
image->setStyle(style); |
|
101 |
if (StyleImage* styleImage = contentData->image()) |
|
102 |
image->setStyleImage(styleImage); |
|
103 |
return image; |
|
104 |
} |
|
105 |
||
106 |
RenderObject* o = 0; |
|
107 |
||
108 |
switch (style->display()) { |
|
109 |
case NONE: |
|
110 |
break; |
|
111 |
case INLINE: |
|
112 |
o = new (arena) RenderInline(node); |
|
113 |
break; |
|
114 |
case BLOCK: |
|
115 |
o = new (arena) RenderBlock(node); |
|
116 |
break; |
|
117 |
case INLINE_BLOCK: |
|
118 |
o = new (arena) RenderBlock(node); |
|
119 |
break; |
|
120 |
case LIST_ITEM: |
|
121 |
o = new (arena) RenderListItem(node); |
|
122 |
break; |
|
123 |
case RUN_IN: |
|
124 |
case COMPACT: |
|
125 |
o = new (arena) RenderBlock(node); |
|
126 |
break; |
|
127 |
case TABLE: |
|
128 |
case INLINE_TABLE: |
|
129 |
o = new (arena) RenderTable(node); |
|
130 |
break; |
|
131 |
case TABLE_ROW_GROUP: |
|
132 |
case TABLE_HEADER_GROUP: |
|
133 |
case TABLE_FOOTER_GROUP: |
|
134 |
o = new (arena) RenderTableSection(node); |
|
135 |
break; |
|
136 |
case TABLE_ROW: |
|
137 |
o = new (arena) RenderTableRow(node); |
|
138 |
break; |
|
139 |
case TABLE_COLUMN_GROUP: |
|
140 |
case TABLE_COLUMN: |
|
141 |
o = new (arena) RenderTableCol(node); |
|
142 |
break; |
|
143 |
case TABLE_CELL: |
|
144 |
o = new (arena) RenderTableCell(node); |
|
145 |
break; |
|
146 |
case TABLE_CAPTION: |
|
147 |
#if ENABLE(WCSS) |
|
148 |
// As per the section 17.1 of the spec WAP-239-WCSS-20011026-a.pdf, |
|
149 |
// the marquee box inherits and extends the characteristics of the |
|
150 |
// principal block box ([CSS2] section 9.2.1). |
|
151 |
case WAP_MARQUEE: |
|
152 |
#endif |
|
153 |
o = new (arena) RenderBlock(node); |
|
154 |
break; |
|
155 |
case BOX: |
|
156 |
case INLINE_BOX: |
|
157 |
o = new (arena) RenderFlexibleBox(node); |
|
158 |
break; |
|
159 |
} |
|
160 |
||
161 |
return o; |
|
162 |
} |
|
163 |
||
164 |
#ifndef NDEBUG |
|
165 |
static WTF::RefCountedLeakCounter renderObjectCounter("RenderObject"); |
|
166 |
#endif |
|
167 |
||
168 |
RenderObject::RenderObject(Node* node) |
|
169 |
: CachedResourceClient() |
|
170 |
, m_style(0) |
|
171 |
, m_node(node) |
|
172 |
, m_parent(0) |
|
173 |
, m_previous(0) |
|
174 |
, m_next(0) |
|
175 |
#ifndef NDEBUG |
|
176 |
, m_hasAXObject(false) |
|
177 |
, m_setNeedsLayoutForbidden(false) |
|
178 |
#endif |
|
179 |
, m_needsLayout(false) |
|
180 |
, m_needsPositionedMovementLayout(false) |
|
181 |
, m_normalChildNeedsLayout(false) |
|
182 |
, m_posChildNeedsLayout(false) |
|
183 |
, m_prefWidthsDirty(false) |
|
184 |
, m_floating(false) |
|
185 |
, m_positioned(false) |
|
186 |
, m_relPositioned(false) |
|
187 |
, m_paintBackground(false) |
|
188 |
, m_isAnonymous(node == node->document()) |
|
189 |
, m_isText(false) |
|
190 |
, m_isBox(false) |
|
191 |
, m_inline(true) |
|
192 |
, m_replaced(false) |
|
193 |
, m_isDragging(false) |
|
194 |
, m_hasLayer(false) |
|
195 |
, m_hasOverflowClip(false) |
|
196 |
, m_hasTransform(false) |
|
197 |
, m_hasReflection(false) |
|
198 |
, m_hasOverrideSize(false) |
|
199 |
, m_hasCounterNodeMap(false) |
|
200 |
, m_everHadLayout(false) |
|
201 |
, m_childrenInline(false) |
|
202 |
, m_topMarginQuirk(false) |
|
203 |
, m_bottomMarginQuirk(false) |
|
204 |
, m_hasMarkupTruncation(false) |
|
205 |
, m_selectionState(SelectionNone) |
|
206 |
, m_hasColumns(false) |
|
207 |
, m_cellWidthChanged(false) |
|
208 |
{ |
|
209 |
#ifndef NDEBUG |
|
210 |
renderObjectCounter.increment(); |
|
211 |
#endif |
|
212 |
ASSERT(node); |
|
213 |
} |
|
214 |
||
215 |
RenderObject::~RenderObject() |
|
216 |
{ |
|
217 |
ASSERT(!node() || documentBeingDestroyed() || !document()->frame()->view() || document()->frame()->view()->layoutRoot() != this); |
|
218 |
#ifndef NDEBUG |
|
219 |
ASSERT(!m_hasAXObject); |
|
220 |
renderObjectCounter.decrement(); |
|
221 |
#endif |
|
222 |
} |
|
223 |
||
224 |
RenderTheme* RenderObject::theme() const |
|
225 |
{ |
|
226 |
ASSERT(document()->page()); |
|
227 |
||
228 |
return document()->page()->theme(); |
|
229 |
} |
|
230 |
||
231 |
bool RenderObject::isDescendantOf(const RenderObject* obj) const |
|
232 |
{ |
|
233 |
for (const RenderObject* r = this; r; r = r->m_parent) { |
|
234 |
if (r == obj) |
|
235 |
return true; |
|
236 |
} |
|
237 |
return false; |
|
238 |
} |
|
239 |
||
240 |
bool RenderObject::isBody() const |
|
241 |
{ |
|
242 |
return node() && node()->hasTagName(bodyTag); |
|
243 |
} |
|
244 |
||
245 |
bool RenderObject::isHR() const |
|
246 |
{ |
|
247 |
return node() && node()->hasTagName(hrTag); |
|
248 |
} |
|
249 |
||
250 |
bool RenderObject::isHTMLMarquee() const |
|
251 |
{ |
|
252 |
return node() && node()->renderer() == this && node()->hasTagName(marqueeTag); |
|
253 |
} |
|
254 |
||
255 |
static void updateListMarkerNumbers(RenderObject* child) |
|
256 |
{ |
|
257 |
for (RenderObject* sibling = child; sibling; sibling = sibling->nextSibling()) { |
|
258 |
if (sibling->isListItem()) |
|
259 |
toRenderListItem(sibling)->updateValue(); |
|
260 |
} |
|
261 |
} |
|
262 |
||
263 |
void RenderObject::addChild(RenderObject* newChild, RenderObject* beforeChild) |
|
264 |
{ |
|
265 |
RenderObjectChildList* children = virtualChildren(); |
|
266 |
ASSERT(children); |
|
267 |
if (!children) |
|
268 |
return; |
|
269 |
||
270 |
bool needsTable = false; |
|
271 |
||
272 |
if (newChild->isListItem()) |
|
273 |
updateListMarkerNumbers(beforeChild ? beforeChild : children->lastChild()); |
|
274 |
else if (newChild->isTableCol() && newChild->style()->display() == TABLE_COLUMN_GROUP) |
|
275 |
needsTable = !isTable(); |
|
276 |
else if (newChild->isRenderBlock() && newChild->style()->display() == TABLE_CAPTION) |
|
277 |
needsTable = !isTable(); |
|
278 |
else if (newChild->isTableSection()) |
|
279 |
needsTable = !isTable(); |
|
280 |
else if (newChild->isTableRow()) |
|
281 |
needsTable = !isTableSection(); |
|
282 |
else if (newChild->isTableCell()) { |
|
283 |
needsTable = !isTableRow(); |
|
284 |
// I'm not 100% sure this is the best way to fix this, but without this |
|
285 |
// change we recurse infinitely when trying to render the CSS2 test page: |
|
286 |
// http://www.bath.ac.uk/%7Epy8ieh/internet/eviltests/htmlbodyheadrendering2.html. |
|
287 |
// See Radar 2925291. |
|
288 |
if (needsTable && isTableCell() && !children->firstChild() && !newChild->isTableCell()) |
|
289 |
needsTable = false; |
|
290 |
} |
|
291 |
||
292 |
if (needsTable) { |
|
293 |
RenderTable* table; |
|
294 |
RenderObject* afterChild = beforeChild ? beforeChild->previousSibling() : children->lastChild(); |
|
295 |
if (afterChild && afterChild->isAnonymous() && afterChild->isTable()) |
|
296 |
table = toRenderTable(afterChild); |
|
297 |
else { |
|
298 |
table = new (renderArena()) RenderTable(document() /* is anonymous */); |
|
299 |
RefPtr<RenderStyle> newStyle = RenderStyle::create(); |
|
300 |
newStyle->inheritFrom(style()); |
|
301 |
newStyle->setDisplay(TABLE); |
|
302 |
table->setStyle(newStyle.release()); |
|
303 |
addChild(table, beforeChild); |
|
304 |
} |
|
305 |
table->addChild(newChild); |
|
306 |
} else { |
|
307 |
// Just add it... |
|
308 |
children->insertChildNode(this, newChild, beforeChild); |
|
309 |
} |
|
310 |
||
311 |
if (newChild->isText() && newChild->style()->textTransform() == CAPITALIZE) { |
|
312 |
RefPtr<StringImpl> textToTransform = toRenderText(newChild)->originalText(); |
|
313 |
if (textToTransform) |
|
314 |
toRenderText(newChild)->setText(textToTransform.release(), true); |
|
315 |
} |
|
316 |
} |
|
317 |
||
318 |
void RenderObject::removeChild(RenderObject* oldChild) |
|
319 |
{ |
|
320 |
RenderObjectChildList* children = virtualChildren(); |
|
321 |
ASSERT(children); |
|
322 |
if (!children) |
|
323 |
return; |
|
324 |
||
325 |
// We do this here instead of in removeChildNode, since the only extremely low-level uses of remove/appendChildNode |
|
326 |
// cannot affect the positioned object list, and the floating object list is irrelevant (since the list gets cleared on |
|
327 |
// layout anyway). |
|
328 |
if (oldChild->isFloatingOrPositioned()) |
|
329 |
toRenderBox(oldChild)->removeFloatingOrPositionedChildFromBlockLists(); |
|
330 |
||
331 |
children->removeChildNode(this, oldChild); |
|
332 |
} |
|
333 |
||
334 |
RenderObject* RenderObject::nextInPreOrder() const |
|
335 |
{ |
|
336 |
if (RenderObject* o = firstChild()) |
|
337 |
return o; |
|
338 |
||
339 |
return nextInPreOrderAfterChildren(); |
|
340 |
} |
|
341 |
||
342 |
RenderObject* RenderObject::nextInPreOrderAfterChildren() const |
|
343 |
{ |
|
344 |
RenderObject* o; |
|
345 |
if (!(o = nextSibling())) { |
|
346 |
o = parent(); |
|
347 |
while (o && !o->nextSibling()) |
|
348 |
o = o->parent(); |
|
349 |
if (o) |
|
350 |
o = o->nextSibling(); |
|
351 |
} |
|
352 |
||
353 |
return o; |
|
354 |
} |
|
355 |
||
356 |
RenderObject* RenderObject::nextInPreOrder(RenderObject* stayWithin) const |
|
357 |
{ |
|
358 |
if (RenderObject* o = firstChild()) |
|
359 |
return o; |
|
360 |
||
361 |
return nextInPreOrderAfterChildren(stayWithin); |
|
362 |
} |
|
363 |
||
364 |
RenderObject* RenderObject::nextInPreOrderAfterChildren(RenderObject* stayWithin) const |
|
365 |
{ |
|
366 |
if (this == stayWithin) |
|
367 |
return 0; |
|
368 |
||
369 |
RenderObject* o; |
|
370 |
if (!(o = nextSibling())) { |
|
371 |
o = parent(); |
|
372 |
while (o && !o->nextSibling()) { |
|
373 |
if (o == stayWithin) |
|
374 |
return 0; |
|
375 |
o = o->parent(); |
|
376 |
} |
|
377 |
if (o) |
|
378 |
o = o->nextSibling(); |
|
379 |
} |
|
380 |
||
381 |
return o; |
|
382 |
} |
|
383 |
||
384 |
RenderObject* RenderObject::previousInPreOrder() const |
|
385 |
{ |
|
386 |
if (RenderObject* o = previousSibling()) { |
|
387 |
while (o->lastChild()) |
|
388 |
o = o->lastChild(); |
|
389 |
return o; |
|
390 |
} |
|
391 |
||
392 |
return parent(); |
|
393 |
} |
|
394 |
||
395 |
RenderObject* RenderObject::childAt(unsigned index) const |
|
396 |
{ |
|
397 |
RenderObject* child = firstChild(); |
|
398 |
for (unsigned i = 0; child && i < index; i++) |
|
399 |
child = child->nextSibling(); |
|
400 |
return child; |
|
401 |
} |
|
402 |
||
403 |
RenderObject* RenderObject::firstLeafChild() const |
|
404 |
{ |
|
405 |
RenderObject* r = firstChild(); |
|
406 |
while (r) { |
|
407 |
RenderObject* n = 0; |
|
408 |
n = r->firstChild(); |
|
409 |
if (!n) |
|
410 |
break; |
|
411 |
r = n; |
|
412 |
} |
|
413 |
return r; |
|
414 |
} |
|
415 |
||
416 |
RenderObject* RenderObject::lastLeafChild() const |
|
417 |
{ |
|
418 |
RenderObject* r = lastChild(); |
|
419 |
while (r) { |
|
420 |
RenderObject* n = 0; |
|
421 |
n = r->lastChild(); |
|
422 |
if (!n) |
|
423 |
break; |
|
424 |
r = n; |
|
425 |
} |
|
426 |
return r; |
|
427 |
} |
|
428 |
||
429 |
static void addLayers(RenderObject* obj, RenderLayer* parentLayer, RenderObject*& newObject, |
|
430 |
RenderLayer*& beforeChild) |
|
431 |
{ |
|
432 |
if (obj->hasLayer()) { |
|
433 |
if (!beforeChild && newObject) { |
|
434 |
// We need to figure out the layer that follows newObject. We only do |
|
435 |
// this the first time we find a child layer, and then we update the |
|
436 |
// pointer values for newObject and beforeChild used by everyone else. |
|
437 |
beforeChild = newObject->parent()->findNextLayer(parentLayer, newObject); |
|
438 |
newObject = 0; |
|
439 |
} |
|
440 |
parentLayer->addChild(toRenderBoxModelObject(obj)->layer(), beforeChild); |
|
441 |
return; |
|
442 |
} |
|
443 |
||
444 |
for (RenderObject* curr = obj->firstChild(); curr; curr = curr->nextSibling()) |
|
445 |
addLayers(curr, parentLayer, newObject, beforeChild); |
|
446 |
} |
|
447 |
||
448 |
void RenderObject::addLayers(RenderLayer* parentLayer, RenderObject* newObject) |
|
449 |
{ |
|
450 |
if (!parentLayer) |
|
451 |
return; |
|
452 |
||
453 |
RenderObject* object = newObject; |
|
454 |
RenderLayer* beforeChild = 0; |
|
455 |
WebCore::addLayers(this, parentLayer, object, beforeChild); |
|
456 |
} |
|
457 |
||
458 |
void RenderObject::removeLayers(RenderLayer* parentLayer) |
|
459 |
{ |
|
460 |
if (!parentLayer) |
|
461 |
return; |
|
462 |
||
463 |
if (hasLayer()) { |
|
464 |
parentLayer->removeChild(toRenderBoxModelObject(this)->layer()); |
|
465 |
return; |
|
466 |
} |
|
467 |
||
468 |
for (RenderObject* curr = firstChild(); curr; curr = curr->nextSibling()) |
|
469 |
curr->removeLayers(parentLayer); |
|
470 |
} |
|
471 |
||
472 |
void RenderObject::moveLayers(RenderLayer* oldParent, RenderLayer* newParent) |
|
473 |
{ |
|
474 |
if (!newParent) |
|
475 |
return; |
|
476 |
||
477 |
if (hasLayer()) { |
|
478 |
RenderLayer* layer = toRenderBoxModelObject(this)->layer(); |
|
479 |
ASSERT(oldParent == layer->parent()); |
|
480 |
if (oldParent) |
|
481 |
oldParent->removeChild(layer); |
|
482 |
newParent->addChild(layer); |
|
483 |
return; |
|
484 |
} |
|
485 |
||
486 |
for (RenderObject* curr = firstChild(); curr; curr = curr->nextSibling()) |
|
487 |
curr->moveLayers(oldParent, newParent); |
|
488 |
} |
|
489 |
||
490 |
RenderLayer* RenderObject::findNextLayer(RenderLayer* parentLayer, RenderObject* startPoint, |
|
491 |
bool checkParent) |
|
492 |
{ |
|
493 |
// Error check the parent layer passed in. If it's null, we can't find anything. |
|
494 |
if (!parentLayer) |
|
495 |
return 0; |
|
496 |
||
497 |
// Step 1: If our layer is a child of the desired parent, then return our layer. |
|
498 |
RenderLayer* ourLayer = hasLayer() ? toRenderBoxModelObject(this)->layer() : 0; |
|
499 |
if (ourLayer && ourLayer->parent() == parentLayer) |
|
500 |
return ourLayer; |
|
501 |
||
502 |
// Step 2: If we don't have a layer, or our layer is the desired parent, then descend |
|
503 |
// into our siblings trying to find the next layer whose parent is the desired parent. |
|
504 |
if (!ourLayer || ourLayer == parentLayer) { |
|
505 |
for (RenderObject* curr = startPoint ? startPoint->nextSibling() : firstChild(); |
|
506 |
curr; curr = curr->nextSibling()) { |
|
507 |
RenderLayer* nextLayer = curr->findNextLayer(parentLayer, 0, false); |
|
508 |
if (nextLayer) |
|
509 |
return nextLayer; |
|
510 |
} |
|
511 |
} |
|
512 |
||
513 |
// Step 3: If our layer is the desired parent layer, then we're finished. We didn't |
|
514 |
// find anything. |
|
515 |
if (parentLayer == ourLayer) |
|
516 |
return 0; |
|
517 |
||
518 |
// Step 4: If |checkParent| is set, climb up to our parent and check its siblings that |
|
519 |
// follow us to see if we can locate a layer. |
|
520 |
if (checkParent && parent()) |
|
521 |
return parent()->findNextLayer(parentLayer, this, true); |
|
522 |
||
523 |
return 0; |
|
524 |
} |
|
525 |
||
526 |
RenderLayer* RenderObject::enclosingLayer() const |
|
527 |
{ |
|
528 |
const RenderObject* curr = this; |
|
529 |
while (curr) { |
|
530 |
RenderLayer* layer = curr->hasLayer() ? toRenderBoxModelObject(curr)->layer() : 0; |
|
531 |
if (layer) |
|
532 |
return layer; |
|
533 |
curr = curr->parent(); |
|
534 |
} |
|
535 |
return 0; |
|
536 |
} |
|
537 |
||
538 |
RenderLayer* RenderObject::enclosingSelfPaintingLayer() const |
|
539 |
{ |
|
540 |
const RenderObject* curr = this; |
|
541 |
while (curr) { |
|
542 |
RenderLayer* layer = curr->hasLayer() ? toRenderBoxModelObject(curr)->layer() : 0; |
|
543 |
if (layer && layer->isSelfPaintingLayer()) |
|
544 |
return layer; |
|
545 |
curr = curr->parent(); |
|
546 |
} |
|
547 |
return 0; |
|
548 |
} |
|
549 |
||
550 |
RenderBox* RenderObject::enclosingBox() const |
|
551 |
{ |
|
552 |
RenderObject* curr = const_cast<RenderObject*>(this); |
|
553 |
while (curr) { |
|
554 |
if (curr->isBox()) |
|
555 |
return toRenderBox(curr); |
|
556 |
curr = curr->parent(); |
|
557 |
} |
|
558 |
||
559 |
ASSERT_NOT_REACHED(); |
|
560 |
return 0; |
|
561 |
} |
|
562 |
||
563 |
RenderBlock* RenderObject::firstLineBlock() const |
|
564 |
{ |
|
565 |
return 0; |
|
566 |
} |
|
567 |
||
568 |
void RenderObject::setPrefWidthsDirty(bool b, bool markParents) |
|
569 |
{ |
|
570 |
bool alreadyDirty = m_prefWidthsDirty; |
|
571 |
m_prefWidthsDirty = b; |
|
572 |
if (b && !alreadyDirty && markParents && (isText() || (style()->position() != FixedPosition && style()->position() != AbsolutePosition))) |
|
573 |
invalidateContainerPrefWidths(); |
|
574 |
} |
|
575 |
||
576 |
void RenderObject::invalidateContainerPrefWidths() |
|
577 |
{ |
|
578 |
// In order to avoid pathological behavior when inlines are deeply nested, we do include them |
|
579 |
// in the chain that we mark dirty (even though they're kind of irrelevant). |
|
580 |
RenderObject* o = isTableCell() ? containingBlock() : container(); |
|
581 |
while (o && !o->m_prefWidthsDirty) { |
|
582 |
// Don't invalidate the outermost object of an unrooted subtree. That object will be |
|
583 |
// invalidated when the subtree is added to the document. |
|
584 |
RenderObject* container = o->isTableCell() ? o->containingBlock() : o->container(); |
|
585 |
if (!container && !o->isRenderView()) |
|
586 |
break; |
|
587 |
||
588 |
o->m_prefWidthsDirty = true; |
|
589 |
if (o->style()->position() == FixedPosition || o->style()->position() == AbsolutePosition) |
|
590 |
// A positioned object has no effect on the min/max width of its containing block ever. |
|
591 |
// We can optimize this case and not go up any further. |
|
592 |
break; |
|
593 |
o = container; |
|
594 |
} |
|
595 |
} |
|
596 |
||
597 |
void RenderObject::setLayerNeedsFullRepaint() |
|
598 |
{ |
|
599 |
ASSERT(hasLayer()); |
|
600 |
toRenderBoxModelObject(this)->layer()->setNeedsFullRepaint(true); |
|
601 |
} |
|
602 |
||
603 |
RenderBlock* RenderObject::containingBlock() const |
|
604 |
{ |
|
605 |
if (isTableCell()) { |
|
606 |
const RenderTableCell* cell = toRenderTableCell(this); |
|
607 |
if (parent() && cell->section()) |
|
608 |
return cell->table(); |
|
609 |
return 0; |
|
610 |
} |
|
611 |
||
612 |
if (isRenderView()) |
|
613 |
return const_cast<RenderView*>(toRenderView(this)); |
|
614 |
||
615 |
RenderObject* o = parent(); |
|
616 |
if (!isText() && m_style->position() == FixedPosition) { |
|
617 |
while (o && !o->isRenderView() && !(o->hasTransform() && o->isRenderBlock())) |
|
618 |
o = o->parent(); |
|
619 |
} else if (!isText() && m_style->position() == AbsolutePosition) { |
|
620 |
while (o && (o->style()->position() == StaticPosition || (o->isInline() && !o->isReplaced())) && !o->isRenderView() && !(o->hasTransform() && o->isRenderBlock())) { |
|
621 |
// For relpositioned inlines, we return the nearest enclosing block. We don't try |
|
622 |
// to return the inline itself. This allows us to avoid having a positioned objects |
|
623 |
// list in all RenderInlines and lets us return a strongly-typed RenderBlock* result |
|
624 |
// from this method. The container() method can actually be used to obtain the |
|
625 |
// inline directly. |
|
626 |
if (o->style()->position() == RelativePosition && o->isInline() && !o->isReplaced()) |
|
627 |
return o->containingBlock(); |
|
628 |
#if ENABLE(SVG) |
|
629 |
if (o->isSVGForeignObject()) //foreignObject is the containing block for contents inside it |
|
630 |
break; |
|
631 |
#endif |
|
632 |
||
633 |
o = o->parent(); |
|
634 |
} |
|
635 |
} else { |
|
636 |
while (o && ((o->isInline() && !o->isReplaced()) || o->isTableRow() || o->isTableSection() |
|
637 |
|| o->isTableCol() || o->isFrameSet() || o->isMedia() |
|
638 |
#if ENABLE(SVG) |
|
639 |
|| o->isSVGContainer() || o->isSVGRoot() |
|
640 |
#endif |
|
641 |
)) |
|
642 |
o = o->parent(); |
|
643 |
} |
|
644 |
||
645 |
if (!o || !o->isRenderBlock()) |
|
646 |
return 0; // Probably doesn't happen any more, but leave just in case. -dwh |
|
647 |
||
648 |
return toRenderBlock(o); |
|
649 |
} |
|
650 |
||
651 |
static bool mustRepaintFillLayers(const RenderObject* renderer, const FillLayer* layer) |
|
652 |
{ |
|
653 |
// Nobody will use multiple layers without wanting fancy positioning. |
|
654 |
if (layer->next()) |
|
655 |
return true; |
|
656 |
||
657 |
// Make sure we have a valid image. |
|
658 |
StyleImage* img = layer->image(); |
|
659 |
if (!img || !img->canRender(renderer->style()->effectiveZoom())) |
|
660 |
return false; |
|
661 |
||
662 |
if (!layer->xPosition().isZero() || !layer->yPosition().isZero()) |
|
663 |
return true; |
|
664 |
||
665 |
if (layer->size().type == SizeLength) { |
|
666 |
if (layer->size().size.width().isPercent() || layer->size().size.height().isPercent()) |
|
667 |
return true; |
|
668 |
} else if (layer->size().type == Contain || layer->size().type == Cover || img->usesImageContainerSize()) |
|
669 |
return true; |
|
670 |
||
671 |
return false; |
|
672 |
} |
|
673 |
||
674 |
bool RenderObject::mustRepaintBackgroundOrBorder() const |
|
675 |
{ |
|
676 |
if (hasMask() && mustRepaintFillLayers(this, style()->maskLayers())) |
|
677 |
return true; |
|
678 |
||
679 |
// If we don't have a background/border/mask, then nothing to do. |
|
680 |
if (!hasBoxDecorations()) |
|
681 |
return false; |
|
682 |
||
683 |
if (mustRepaintFillLayers(this, style()->backgroundLayers())) |
|
684 |
return true; |
|
685 |
||
686 |
// Our fill layers are ok. Let's check border. |
|
687 |
if (style()->hasBorder()) { |
|
688 |
// Border images are not ok. |
|
689 |
StyleImage* borderImage = style()->borderImage().image(); |
|
690 |
bool shouldPaintBorderImage = borderImage && borderImage->canRender(style()->effectiveZoom()); |
|
691 |
||
692 |
// If the image hasn't loaded, we're still using the normal border style. |
|
693 |
if (shouldPaintBorderImage && borderImage->isLoaded()) |
|
694 |
return true; |
|
695 |
} |
|
696 |
||
697 |
return false; |
|
698 |
} |
|
699 |
||
700 |
void RenderObject::drawLineForBoxSide(GraphicsContext* graphicsContext, int x1, int y1, int x2, int y2, |
|
701 |
BoxSide s, Color c, const Color& textcolor, EBorderStyle style, |
|
702 |
int adjbw1, int adjbw2) |
|
703 |
{ |
|
704 |
int width = (s == BSTop || s == BSBottom ? y2 - y1 : x2 - x1); |
|
705 |
||
706 |
if (style == DOUBLE && width < 3) |
|
707 |
style = SOLID; |
|
708 |
||
709 |
if (!c.isValid()) { |
|
710 |
if (style == INSET || style == OUTSET || style == RIDGE || style == GROOVE) |
|
711 |
c.setRGB(238, 238, 238); |
|
712 |
else |
|
713 |
c = textcolor; |
|
714 |
} |
|
715 |
||
716 |
switch (style) { |
|
717 |
case BNONE: |
|
718 |
case BHIDDEN: |
|
719 |
return; |
|
720 |
case DOTTED: |
|
721 |
case DASHED: |
|
722 |
graphicsContext->setStrokeColor(c); |
|
723 |
graphicsContext->setStrokeThickness(width); |
|
724 |
graphicsContext->setStrokeStyle(style == DASHED ? DashedStroke : DottedStroke); |
|
725 |
||
726 |
if (width > 0) |
|
727 |
switch (s) { |
|
728 |
case BSBottom: |
|
729 |
case BSTop: |
|
730 |
graphicsContext->drawLine(IntPoint(x1, (y1 + y2) / 2), IntPoint(x2, (y1 + y2) / 2)); |
|
731 |
break; |
|
732 |
case BSRight: |
|
733 |
case BSLeft: |
|
734 |
graphicsContext->drawLine(IntPoint((x1 + x2) / 2, y1), IntPoint((x1 + x2) / 2, y2)); |
|
735 |
break; |
|
736 |
} |
|
737 |
break; |
|
738 |
case DOUBLE: { |
|
739 |
int third = (width + 1) / 3; |
|
740 |
||
741 |
if (adjbw1 == 0 && adjbw2 == 0) { |
|
742 |
graphicsContext->setStrokeStyle(NoStroke); |
|
743 |
graphicsContext->setFillColor(c); |
|
744 |
switch (s) { |
|
745 |
case BSTop: |
|
746 |
case BSBottom: |
|
747 |
graphicsContext->drawRect(IntRect(x1, y1, x2 - x1, third)); |
|
748 |
graphicsContext->drawRect(IntRect(x1, y2 - third, x2 - x1, third)); |
|
749 |
break; |
|
750 |
case BSLeft: |
|
751 |
graphicsContext->drawRect(IntRect(x1, y1 + 1, third, y2 - y1 - 1)); |
|
752 |
graphicsContext->drawRect(IntRect(x2 - third, y1 + 1, third, y2 - y1 - 1)); |
|
753 |
break; |
|
754 |
case BSRight: |
|
755 |
graphicsContext->drawRect(IntRect(x1, y1 + 1, third, y2 - y1 - 1)); |
|
756 |
graphicsContext->drawRect(IntRect(x2 - third, y1 + 1, third, y2 - y1 - 1)); |
|
757 |
break; |
|
758 |
} |
|
759 |
} else { |
|
760 |
int adjbw1bigthird = ((adjbw1 > 0) ? adjbw1 + 1 : adjbw1 - 1) / 3; |
|
761 |
int adjbw2bigthird = ((adjbw2 > 0) ? adjbw2 + 1 : adjbw2 - 1) / 3; |
|
762 |
||
763 |
switch (s) { |
|
764 |
case BSTop: |
|
765 |
drawLineForBoxSide(graphicsContext, x1 + max((-adjbw1 * 2 + 1) / 3, 0), |
|
766 |
y1, x2 - max((-adjbw2 * 2 + 1) / 3, 0), y1 + third, |
|
767 |
s, c, textcolor, SOLID, adjbw1bigthird, adjbw2bigthird); |
|
768 |
drawLineForBoxSide(graphicsContext, x1 + max((adjbw1 * 2 + 1) / 3, 0), |
|
769 |
y2 - third, x2 - max((adjbw2 * 2 + 1) / 3, 0), y2, |
|
770 |
s, c, textcolor, SOLID, adjbw1bigthird, adjbw2bigthird); |
|
771 |
break; |
|
772 |
case BSLeft: |
|
773 |
drawLineForBoxSide(graphicsContext, x1, y1 + max((-adjbw1 * 2 + 1) / 3, 0), |
|
774 |
x1 + third, y2 - max((-adjbw2 * 2 + 1) / 3, 0), |
|
775 |
s, c, textcolor, SOLID, adjbw1bigthird, adjbw2bigthird); |
|
776 |
drawLineForBoxSide(graphicsContext, x2 - third, y1 + max((adjbw1 * 2 + 1) / 3, 0), |
|
777 |
x2, y2 - max((adjbw2 * 2 + 1) / 3, 0), |
|
778 |
s, c, textcolor, SOLID, adjbw1bigthird, adjbw2bigthird); |
|
779 |
break; |
|
780 |
case BSBottom: |
|
781 |
drawLineForBoxSide(graphicsContext, x1 + max((adjbw1 * 2 + 1) / 3, 0), |
|
782 |
y1, x2 - max((adjbw2 * 2 + 1) / 3, 0), y1 + third, |
|
783 |
s, c, textcolor, SOLID, adjbw1bigthird, adjbw2bigthird); |
|
784 |
drawLineForBoxSide(graphicsContext, x1 + max((-adjbw1 * 2 + 1) / 3, 0), |
|
785 |
y2 - third, x2 - max((-adjbw2 * 2 + 1) / 3, 0), y2, |
|
786 |
s, c, textcolor, SOLID, adjbw1bigthird, adjbw2bigthird); |
|
787 |
break; |
|
788 |
case BSRight: |
|
789 |
drawLineForBoxSide(graphicsContext, x1, y1 + max((adjbw1 * 2 + 1) / 3, 0), |
|
790 |
x1 + third, y2 - max((adjbw2 * 2 + 1) / 3, 0), |
|
791 |
s, c, textcolor, SOLID, adjbw1bigthird, adjbw2bigthird); |
|
792 |
drawLineForBoxSide(graphicsContext, x2 - third, y1 + max((-adjbw1 * 2 + 1) / 3, 0), |
|
793 |
x2, y2 - max((-adjbw2 * 2 + 1) / 3, 0), |
|
794 |
s, c, textcolor, SOLID, adjbw1bigthird, adjbw2bigthird); |
|
795 |
break; |
|
796 |
default: |
|
797 |
break; |
|
798 |
} |
|
799 |
} |
|
800 |
break; |
|
801 |
} |
|
802 |
case RIDGE: |
|
803 |
case GROOVE: |
|
804 |
{ |
|
805 |
EBorderStyle s1; |
|
806 |
EBorderStyle s2; |
|
807 |
if (style == GROOVE) { |
|
808 |
s1 = INSET; |
|
809 |
s2 = OUTSET; |
|
810 |
} else { |
|
811 |
s1 = OUTSET; |
|
812 |
s2 = INSET; |
|
813 |
} |
|
814 |
||
815 |
int adjbw1bighalf = ((adjbw1 > 0) ? adjbw1 + 1 : adjbw1 - 1) / 2; |
|
816 |
int adjbw2bighalf = ((adjbw2 > 0) ? adjbw2 + 1 : adjbw2 - 1) / 2; |
|
817 |
||
818 |
switch (s) { |
|
819 |
case BSTop: |
|
820 |
drawLineForBoxSide(graphicsContext, x1 + max(-adjbw1, 0) / 2, y1, x2 - max(-adjbw2, 0) / 2, (y1 + y2 + 1) / 2, |
|
821 |
s, c, textcolor, s1, adjbw1bighalf, adjbw2bighalf); |
|
822 |
drawLineForBoxSide(graphicsContext, x1 + max(adjbw1 + 1, 0) / 2, (y1 + y2 + 1) / 2, x2 - max(adjbw2 + 1, 0) / 2, y2, |
|
823 |
s, c, textcolor, s2, adjbw1 / 2, adjbw2 / 2); |
|
824 |
break; |
|
825 |
case BSLeft: |
|
826 |
drawLineForBoxSide(graphicsContext, x1, y1 + max(-adjbw1, 0) / 2, (x1 + x2 + 1) / 2, y2 - max(-adjbw2, 0) / 2, |
|
827 |
s, c, textcolor, s1, adjbw1bighalf, adjbw2bighalf); |
|
828 |
drawLineForBoxSide(graphicsContext, (x1 + x2 + 1) / 2, y1 + max(adjbw1 + 1, 0) / 2, x2, y2 - max(adjbw2 + 1, 0) / 2, |
|
829 |
s, c, textcolor, s2, adjbw1 / 2, adjbw2 / 2); |
|
830 |
break; |
|
831 |
case BSBottom: |
|
832 |
drawLineForBoxSide(graphicsContext, x1 + max(adjbw1, 0) / 2, y1, x2 - max(adjbw2, 0) / 2, (y1 + y2 + 1) / 2, |
|
833 |
s, c, textcolor, s2, adjbw1bighalf, adjbw2bighalf); |
|
834 |
drawLineForBoxSide(graphicsContext, x1 + max(-adjbw1 + 1, 0) / 2, (y1 + y2 + 1) / 2, x2 - max(-adjbw2 + 1, 0) / 2, y2, |
|
835 |
s, c, textcolor, s1, adjbw1/2, adjbw2/2); |
|
836 |
break; |
|
837 |
case BSRight: |
|
838 |
drawLineForBoxSide(graphicsContext, x1, y1 + max(adjbw1, 0) / 2, (x1 + x2 + 1) / 2, y2 - max(adjbw2, 0) / 2, |
|
839 |
s, c, textcolor, s2, adjbw1bighalf, adjbw2bighalf); |
|
840 |
drawLineForBoxSide(graphicsContext, (x1 + x2 + 1) / 2, y1 + max(-adjbw1 + 1, 0) / 2, x2, y2 - max(-adjbw2 + 1, 0) / 2, |
|
841 |
s, c, textcolor, s1, adjbw1/2, adjbw2/2); |
|
842 |
break; |
|
843 |
} |
|
844 |
break; |
|
845 |
} |
|
846 |
case INSET: |
|
847 |
if (s == BSTop || s == BSLeft) |
|
848 |
c = c.dark(); |
|
849 |
// fall through |
|
850 |
case OUTSET: |
|
851 |
if (style == OUTSET && (s == BSBottom || s == BSRight)) |
|
852 |
c = c.dark(); |
|
853 |
// fall through |
|
854 |
case SOLID: { |
|
855 |
graphicsContext->setStrokeStyle(NoStroke); |
|
856 |
graphicsContext->setFillColor(c); |
|
857 |
ASSERT(x2 >= x1); |
|
858 |
ASSERT(y2 >= y1); |
|
859 |
if (!adjbw1 && !adjbw2) { |
|
860 |
graphicsContext->drawRect(IntRect(x1, y1, x2 - x1, y2 - y1)); |
|
861 |
return; |
|
862 |
} |
|
863 |
FloatPoint quad[4]; |
|
864 |
switch (s) { |
|
865 |
case BSTop: |
|
866 |
quad[0] = FloatPoint(x1 + max(-adjbw1, 0), y1); |
|
867 |
quad[1] = FloatPoint(x1 + max(adjbw1, 0), y2); |
|
868 |
quad[2] = FloatPoint(x2 - max(adjbw2, 0), y2); |
|
869 |
quad[3] = FloatPoint(x2 - max(-adjbw2, 0), y1); |
|
870 |
break; |
|
871 |
case BSBottom: |
|
872 |
quad[0] = FloatPoint(x1 + max(adjbw1, 0), y1); |
|
873 |
quad[1] = FloatPoint(x1 + max(-adjbw1, 0), y2); |
|
874 |
quad[2] = FloatPoint(x2 - max(-adjbw2, 0), y2); |
|
875 |
quad[3] = FloatPoint(x2 - max(adjbw2, 0), y1); |
|
876 |
break; |
|
877 |
case BSLeft: |
|
878 |
quad[0] = FloatPoint(x1, y1 + max(-adjbw1, 0)); |
|
879 |
quad[1] = FloatPoint(x1, y2 - max(-adjbw2, 0)); |
|
880 |
quad[2] = FloatPoint(x2, y2 - max(adjbw2, 0)); |
|
881 |
quad[3] = FloatPoint(x2, y1 + max(adjbw1, 0)); |
|
882 |
break; |
|
883 |
case BSRight: |
|
884 |
quad[0] = FloatPoint(x1, y1 + max(adjbw1, 0)); |
|
885 |
quad[1] = FloatPoint(x1, y2 - max(adjbw2, 0)); |
|
886 |
quad[2] = FloatPoint(x2, y2 - max(-adjbw2, 0)); |
|
887 |
quad[3] = FloatPoint(x2, y1 + max(-adjbw1, 0)); |
|
888 |
break; |
|
889 |
} |
|
890 |
graphicsContext->drawConvexPolygon(4, quad); |
|
891 |
break; |
|
892 |
} |
|
893 |
} |
|
894 |
} |
|
895 |
||
896 |
void RenderObject::drawArcForBoxSide(GraphicsContext* graphicsContext, int x, int y, float thickness, IntSize radius, |
|
897 |
int angleStart, int angleSpan, BoxSide s, Color c, const Color& textColor, |
|
898 |
EBorderStyle style, bool firstCorner) |
|
899 |
{ |
|
900 |
if ((style == DOUBLE && thickness / 2 < 3) || ((style == RIDGE || style == GROOVE) && thickness / 2 < 2)) |
|
901 |
style = SOLID; |
|
902 |
||
903 |
if (!c.isValid()) { |
|
904 |
if (style == INSET || style == OUTSET || style == RIDGE || style == GROOVE) |
|
905 |
c.setRGB(238, 238, 238); |
|
906 |
else |
|
907 |
c = textColor; |
|
908 |
} |
|
909 |
||
910 |
switch (style) { |
|
911 |
case BNONE: |
|
912 |
case BHIDDEN: |
|
913 |
return; |
|
914 |
case DOTTED: |
|
915 |
case DASHED: |
|
916 |
graphicsContext->setStrokeColor(c); |
|
917 |
graphicsContext->setStrokeStyle(style == DOTTED ? DottedStroke : DashedStroke); |
|
918 |
graphicsContext->setStrokeThickness(thickness); |
|
919 |
graphicsContext->strokeArc(IntRect(x, y, radius.width() * 2, radius.height() * 2), angleStart, angleSpan); |
|
920 |
break; |
|
921 |
case DOUBLE: { |
|
922 |
float third = thickness / 3.0f; |
|
923 |
float innerThird = (thickness + 1.0f) / 6.0f; |
|
924 |
int shiftForInner = static_cast<int>(innerThird * 2.5f); |
|
925 |
||
926 |
int outerY = y; |
|
927 |
int outerHeight = radius.height() * 2; |
|
928 |
int innerX = x + shiftForInner; |
|
929 |
int innerY = y + shiftForInner; |
|
930 |
int innerWidth = (radius.width() - shiftForInner) * 2; |
|
931 |
int innerHeight = (radius.height() - shiftForInner) * 2; |
|
932 |
if (innerThird > 1 && (s == BSTop || (firstCorner && (s == BSLeft || s == BSRight)))) { |
|
933 |
outerHeight += 2; |
|
934 |
innerHeight += 2; |
|
935 |
} |
|
936 |
||
937 |
graphicsContext->setStrokeStyle(SolidStroke); |
|
938 |
graphicsContext->setStrokeColor(c); |
|
939 |
graphicsContext->setStrokeThickness(third); |
|
940 |
graphicsContext->strokeArc(IntRect(x, outerY, radius.width() * 2, outerHeight), angleStart, angleSpan); |
|
941 |
graphicsContext->setStrokeThickness(innerThird > 2 ? innerThird - 1 : innerThird); |
|
942 |
graphicsContext->strokeArc(IntRect(innerX, innerY, innerWidth, innerHeight), angleStart, angleSpan); |
|
943 |
break; |
|
944 |
} |
|
945 |
case GROOVE: |
|
946 |
case RIDGE: { |
|
947 |
Color c2; |
|
948 |
if ((style == RIDGE && (s == BSTop || s == BSLeft)) || |
|
949 |
(style == GROOVE && (s == BSBottom || s == BSRight))) |
|
950 |
c2 = c.dark(); |
|
951 |
else { |
|
952 |
c2 = c; |
|
953 |
c = c.dark(); |
|
954 |
} |
|
955 |
||
956 |
graphicsContext->setStrokeStyle(SolidStroke); |
|
957 |
graphicsContext->setStrokeColor(c); |
|
958 |
graphicsContext->setStrokeThickness(thickness); |
|
959 |
graphicsContext->strokeArc(IntRect(x, y, radius.width() * 2, radius.height() * 2), angleStart, angleSpan); |
|
960 |
||
961 |
float halfThickness = (thickness + 1.0f) / 4.0f; |
|
962 |
int shiftForInner = static_cast<int>(halfThickness * 1.5f); |
|
963 |
graphicsContext->setStrokeColor(c2); |
|
964 |
graphicsContext->setStrokeThickness(halfThickness > 2 ? halfThickness - 1 : halfThickness); |
|
965 |
graphicsContext->strokeArc(IntRect(x + shiftForInner, y + shiftForInner, (radius.width() - shiftForInner) * 2, |
|
966 |
(radius.height() - shiftForInner) * 2), angleStart, angleSpan); |
|
967 |
break; |
|
968 |
} |
|
969 |
case INSET: |
|
970 |
if (s == BSTop || s == BSLeft) |
|
971 |
c = c.dark(); |
|
972 |
case OUTSET: |
|
973 |
if (style == OUTSET && (s == BSBottom || s == BSRight)) |
|
974 |
c = c.dark(); |
|
975 |
case SOLID: |
|
976 |
graphicsContext->setStrokeStyle(SolidStroke); |
|
977 |
graphicsContext->setStrokeColor(c); |
|
978 |
graphicsContext->setStrokeThickness(thickness); |
|
979 |
graphicsContext->strokeArc(IntRect(x, y, radius.width() * 2, radius.height() * 2), angleStart, angleSpan); |
|
980 |
break; |
|
981 |
} |
|
982 |
} |
|
983 |
||
984 |
void RenderObject::addPDFURLRect(GraphicsContext* context, const IntRect& rect) |
|
985 |
{ |
|
986 |
if (rect.isEmpty()) |
|
987 |
return; |
|
988 |
Node* n = node(); |
|
989 |
if (!n || !n->isLink() || !n->isElementNode()) |
|
990 |
return; |
|
991 |
const AtomicString& href = static_cast<Element*>(n)->getAttribute(hrefAttr); |
|
992 |
if (href.isNull()) |
|
993 |
return; |
|
994 |
context->setURLForRect(n->document()->completeURL(href), rect); |
|
995 |
} |
|
996 |
||
997 |
void RenderObject::paintOutline(GraphicsContext* graphicsContext, int tx, int ty, int w, int h, const RenderStyle* style) |
|
998 |
{ |
|
999 |
if (!hasOutline()) |
|
1000 |
return; |
|
1001 |
||
1002 |
int ow = style->outlineWidth(); |
|
1003 |
EBorderStyle os = style->outlineStyle(); |
|
1004 |
||
1005 |
Color oc = style->outlineColor(); |
|
1006 |
if (!oc.isValid()) |
|
1007 |
oc = style->color(); |
|
1008 |
||
1009 |
int offset = style->outlineOffset(); |
|
1010 |
||
1011 |
if (style->outlineStyleIsAuto() || hasOutlineAnnotation()) { |
|
1012 |
if (!theme()->supportsFocusRing(style)) { |
|
1013 |
// Only paint the focus ring by hand if the theme isn't able to draw the focus ring. |
|
1014 |
graphicsContext->initFocusRing(ow, offset); |
|
1015 |
addFocusRingRects(graphicsContext, tx, ty); |
|
1016 |
if (style->outlineStyleIsAuto()) |
|
1017 |
graphicsContext->drawFocusRing(oc); |
|
1018 |
else |
|
1019 |
addPDFURLRect(graphicsContext, graphicsContext->focusRingBoundingRect()); |
|
1020 |
graphicsContext->clearFocusRing(); |
|
1021 |
} |
|
1022 |
} |
|
1023 |
||
1024 |
if (style->outlineStyleIsAuto() || style->outlineStyle() == BNONE) |
|
1025 |
return; |
|
1026 |
||
1027 |
tx -= offset; |
|
1028 |
ty -= offset; |
|
1029 |
w += 2 * offset; |
|
1030 |
h += 2 * offset; |
|
1031 |
||
1032 |
if (h < 0 || w < 0) |
|
1033 |
return; |
|
1034 |
||
1035 |
drawLineForBoxSide(graphicsContext, tx - ow, ty - ow, tx, ty + h + ow, |
|
1036 |
BSLeft, Color(oc), style->color(), os, ow, ow); |
|
1037 |
||
1038 |
drawLineForBoxSide(graphicsContext, tx - ow, ty - ow, tx + w + ow, ty, |
|
1039 |
BSTop, Color(oc), style->color(), os, ow, ow); |
|
1040 |
||
1041 |
drawLineForBoxSide(graphicsContext, tx + w, ty - ow, tx + w + ow, ty + h + ow, |
|
1042 |
BSRight, Color(oc), style->color(), os, ow, ow); |
|
1043 |
||
1044 |
drawLineForBoxSide(graphicsContext, tx - ow, ty + h, tx + w + ow, ty + h + ow, |
|
1045 |
BSBottom, Color(oc), style->color(), os, ow, ow); |
|
1046 |
} |
|
1047 |
||
1048 |
IntRect RenderObject::absoluteBoundingBoxRect(bool useTransforms) |
|
1049 |
{ |
|
1050 |
if (useTransforms) { |
|
1051 |
Vector<FloatQuad> quads; |
|
1052 |
absoluteQuads(quads); |
|
1053 |
||
1054 |
size_t n = quads.size(); |
|
1055 |
if (!n) |
|
1056 |
return IntRect(); |
|
1057 |
||
1058 |
IntRect result = quads[0].enclosingBoundingBox(); |
|
1059 |
for (size_t i = 1; i < n; ++i) |
|
1060 |
result.unite(quads[i].enclosingBoundingBox()); |
|
1061 |
return result; |
|
1062 |
} |
|
1063 |
||
1064 |
FloatPoint absPos = localToAbsolute(); |
|
1065 |
Vector<IntRect> rects; |
|
1066 |
absoluteRects(rects, absPos.x(), absPos.y()); |
|
1067 |
||
1068 |
size_t n = rects.size(); |
|
1069 |
if (!n) |
|
1070 |
return IntRect(); |
|
1071 |
||
1072 |
IntRect result = rects[0]; |
|
1073 |
for (size_t i = 1; i < n; ++i) |
|
1074 |
result.unite(rects[i]); |
|
1075 |
return result; |
|
1076 |
} |
|
1077 |
||
1078 |
void RenderObject::addAbsoluteRectForLayer(IntRect& result) |
|
1079 |
{ |
|
1080 |
if (hasLayer()) |
|
1081 |
result.unite(absoluteBoundingBoxRect()); |
|
1082 |
for (RenderObject* current = firstChild(); current; current = current->nextSibling()) |
|
1083 |
current->addAbsoluteRectForLayer(result); |
|
1084 |
} |
|
1085 |
||
1086 |
IntRect RenderObject::paintingRootRect(IntRect& topLevelRect) |
|
1087 |
{ |
|
1088 |
IntRect result = absoluteBoundingBoxRect(); |
|
1089 |
topLevelRect = result; |
|
1090 |
for (RenderObject* current = firstChild(); current; current = current->nextSibling()) |
|
1091 |
current->addAbsoluteRectForLayer(result); |
|
1092 |
return result; |
|
1093 |
} |
|
1094 |
||
1095 |
void RenderObject::paint(PaintInfo& /*paintInfo*/, int /*tx*/, int /*ty*/) |
|
1096 |
{ |
|
1097 |
} |
|
1098 |
||
1099 |
RenderBoxModelObject* RenderObject::containerForRepaint() const |
|
1100 |
{ |
|
1101 |
#if USE(ACCELERATED_COMPOSITING) |
|
1102 |
if (RenderView* v = view()) { |
|
1103 |
if (v->usesCompositing()) { |
|
1104 |
RenderLayer* compLayer = enclosingLayer()->enclosingCompositingLayer(); |
|
1105 |
return compLayer ? compLayer->renderer() : 0; |
|
1106 |
} |
|
1107 |
} |
|
1108 |
#endif |
|
1109 |
// Do root-relative repaint. |
|
1110 |
return 0; |
|
1111 |
} |
|
1112 |
||
1113 |
void RenderObject::repaintUsingContainer(RenderBoxModelObject* repaintContainer, const IntRect& r, bool immediate) |
|
1114 |
{ |
|
1115 |
if (!repaintContainer || repaintContainer->isRenderView()) { |
|
1116 |
RenderView* v = repaintContainer ? toRenderView(repaintContainer) : view(); |
|
1117 |
v->repaintViewRectangle(r, immediate); |
|
1118 |
} else { |
|
1119 |
#if USE(ACCELERATED_COMPOSITING) |
|
1120 |
RenderView* v = view(); |
|
1121 |
if (v->usesCompositing()) { |
|
1122 |
ASSERT(repaintContainer->hasLayer() && repaintContainer->layer()->isComposited()); |
|
1123 |
repaintContainer->layer()->setBackingNeedsRepaintInRect(r); |
|
1124 |
} |
|
1125 |
#else |
|
1126 |
ASSERT_NOT_REACHED(); |
|
1127 |
#endif |
|
1128 |
} |
|
1129 |
} |
|
1130 |
||
1131 |
void RenderObject::repaint(bool immediate) |
|
1132 |
{ |
|
1133 |
// Don't repaint if we're unrooted (note that view() still returns the view when unrooted) |
|
1134 |
RenderView* view; |
|
1135 |
if (!isRooted(&view)) |
|
1136 |
return; |
|
1137 |
||
1138 |
if (view->printing()) |
|
1139 |
return; // Don't repaint if we're printing. |
|
1140 |
||
1141 |
RenderBoxModelObject* repaintContainer = containerForRepaint(); |
|
1142 |
repaintUsingContainer(repaintContainer ? repaintContainer : view, clippedOverflowRectForRepaint(repaintContainer), immediate); |
|
1143 |
} |
|
1144 |
||
1145 |
void RenderObject::repaintRectangle(const IntRect& r, bool immediate) |
|
1146 |
{ |
|
1147 |
// Don't repaint if we're unrooted (note that view() still returns the view when unrooted) |
|
1148 |
RenderView* view; |
|
1149 |
if (!isRooted(&view)) |
|
1150 |
return; |
|
1151 |
||
1152 |
if (view->printing()) |
|
1153 |
return; // Don't repaint if we're printing. |
|
1154 |
||
1155 |
IntRect dirtyRect(r); |
|
1156 |
||
1157 |
// FIXME: layoutDelta needs to be applied in parts before/after transforms and |
|
1158 |
// repaint containers. https://bugs.webkit.org/show_bug.cgi?id=23308 |
|
1159 |
dirtyRect.move(view->layoutDelta()); |
|
1160 |
||
1161 |
RenderBoxModelObject* repaintContainer = containerForRepaint(); |
|
1162 |
computeRectForRepaint(repaintContainer, dirtyRect); |
|
1163 |
repaintUsingContainer(repaintContainer ? repaintContainer : view, dirtyRect, immediate); |
|
1164 |
} |
|
1165 |
||
1166 |
bool RenderObject::repaintAfterLayoutIfNeeded(RenderBoxModelObject* repaintContainer, const IntRect& oldBounds, const IntRect& oldOutlineBox) |
|
1167 |
{ |
|
1168 |
RenderView* v = view(); |
|
1169 |
if (v->printing()) |
|
1170 |
return false; // Don't repaint if we're printing. |
|
1171 |
||
1172 |
IntRect newBounds = clippedOverflowRectForRepaint(repaintContainer); |
|
1173 |
IntRect newOutlineBox; |
|
1174 |
||
1175 |
bool fullRepaint = selfNeedsLayout(); |
|
1176 |
// Presumably a background or a border exists if border-fit:lines was specified. |
|
1177 |
if (!fullRepaint && style()->borderFit() == BorderFitLines) |
|
1178 |
fullRepaint = true; |
|
1179 |
if (!fullRepaint) { |
|
1180 |
newOutlineBox = outlineBoundsForRepaint(repaintContainer); |
|
1181 |
if (newOutlineBox.location() != oldOutlineBox.location() || (mustRepaintBackgroundOrBorder() && (newBounds != oldBounds || newOutlineBox != oldOutlineBox))) |
|
1182 |
fullRepaint = true; |
|
1183 |
} |
|
1184 |
||
1185 |
if (!repaintContainer) |
|
1186 |
repaintContainer = v; |
|
1187 |
||
1188 |
if (fullRepaint) { |
|
1189 |
repaintUsingContainer(repaintContainer, oldBounds); |
|
1190 |
if (newBounds != oldBounds) |
|
1191 |
repaintUsingContainer(repaintContainer, newBounds); |
|
1192 |
return true; |
|
1193 |
} |
|
1194 |
||
1195 |
if (newBounds == oldBounds && newOutlineBox == oldOutlineBox) |
|
1196 |
return false; |
|
1197 |
||
1198 |
int deltaLeft = newBounds.x() - oldBounds.x(); |
|
1199 |
if (deltaLeft > 0) |
|
1200 |
repaintUsingContainer(repaintContainer, IntRect(oldBounds.x(), oldBounds.y(), deltaLeft, oldBounds.height())); |
|
1201 |
else if (deltaLeft < 0) |
|
1202 |
repaintUsingContainer(repaintContainer, IntRect(newBounds.x(), newBounds.y(), -deltaLeft, newBounds.height())); |
|
1203 |
||
1204 |
int deltaRight = newBounds.right() - oldBounds.right(); |
|
1205 |
if (deltaRight > 0) |
|
1206 |
repaintUsingContainer(repaintContainer, IntRect(oldBounds.right(), newBounds.y(), deltaRight, newBounds.height())); |
|
1207 |
else if (deltaRight < 0) |
|
1208 |
repaintUsingContainer(repaintContainer, IntRect(newBounds.right(), oldBounds.y(), -deltaRight, oldBounds.height())); |
|
1209 |
||
1210 |
int deltaTop = newBounds.y() - oldBounds.y(); |
|
1211 |
if (deltaTop > 0) |
|
1212 |
repaintUsingContainer(repaintContainer, IntRect(oldBounds.x(), oldBounds.y(), oldBounds.width(), deltaTop)); |
|
1213 |
else if (deltaTop < 0) |
|
1214 |
repaintUsingContainer(repaintContainer, IntRect(newBounds.x(), newBounds.y(), newBounds.width(), -deltaTop)); |
|
1215 |
||
1216 |
int deltaBottom = newBounds.bottom() - oldBounds.bottom(); |
|
1217 |
if (deltaBottom > 0) |
|
1218 |
repaintUsingContainer(repaintContainer, IntRect(newBounds.x(), oldBounds.bottom(), newBounds.width(), deltaBottom)); |
|
1219 |
else if (deltaBottom < 0) |
|
1220 |
repaintUsingContainer(repaintContainer, IntRect(oldBounds.x(), newBounds.bottom(), oldBounds.width(), -deltaBottom)); |
|
1221 |
||
1222 |
if (newOutlineBox == oldOutlineBox) |
|
1223 |
return false; |
|
1224 |
||
1225 |
// We didn't move, but we did change size. Invalidate the delta, which will consist of possibly |
|
1226 |
// two rectangles (but typically only one). |
|
1227 |
RenderStyle* outlineStyle = outlineStyleForRepaint(); |
|
1228 |
int ow = outlineStyle->outlineSize(); |
|
1229 |
int width = abs(newOutlineBox.width() - oldOutlineBox.width()); |
|
1230 |
if (width) { |
|
1231 |
int shadowLeft; |
|
1232 |
int shadowRight; |
|
1233 |
style()->getBoxShadowHorizontalExtent(shadowLeft, shadowRight); |
|
1234 |
||
1235 |
int borderRight = isBox() ? toRenderBox(this)->borderRight() : 0; |
|
1236 |
int borderWidth = max(-outlineStyle->outlineOffset(), max(borderRight, max(style()->borderTopRightRadius().width(), style()->borderBottomRightRadius().width()))) + max(ow, shadowRight); |
|
1237 |
IntRect rightRect(newOutlineBox.x() + min(newOutlineBox.width(), oldOutlineBox.width()) - borderWidth, |
|
1238 |
newOutlineBox.y(), |
|
1239 |
width + borderWidth, |
|
1240 |
max(newOutlineBox.height(), oldOutlineBox.height())); |
|
1241 |
int right = min(newBounds.right(), oldBounds.right()); |
|
1242 |
if (rightRect.x() < right) { |
|
1243 |
rightRect.setWidth(min(rightRect.width(), right - rightRect.x())); |
|
1244 |
repaintUsingContainer(repaintContainer, rightRect); |
|
1245 |
} |
|
1246 |
} |
|
1247 |
int height = abs(newOutlineBox.height() - oldOutlineBox.height()); |
|
1248 |
if (height) { |
|
1249 |
int shadowTop; |
|
1250 |
int shadowBottom; |
|
1251 |
style()->getBoxShadowVerticalExtent(shadowTop, shadowBottom); |
|
1252 |
||
1253 |
int borderBottom = isBox() ? toRenderBox(this)->borderBottom() : 0; |
|
1254 |
int borderHeight = max(-outlineStyle->outlineOffset(), max(borderBottom, max(style()->borderBottomLeftRadius().height(), style()->borderBottomRightRadius().height()))) + max(ow, shadowBottom); |
|
1255 |
IntRect bottomRect(newOutlineBox.x(), |
|
1256 |
min(newOutlineBox.bottom(), oldOutlineBox.bottom()) - borderHeight, |
|
1257 |
max(newOutlineBox.width(), oldOutlineBox.width()), |
|
1258 |
height + borderHeight); |
|
1259 |
int bottom = min(newBounds.bottom(), oldBounds.bottom()); |
|
1260 |
if (bottomRect.y() < bottom) { |
|
1261 |
bottomRect.setHeight(min(bottomRect.height(), bottom - bottomRect.y())); |
|
1262 |
repaintUsingContainer(repaintContainer, bottomRect); |
|
1263 |
} |
|
1264 |
} |
|
1265 |
return false; |
|
1266 |
} |
|
1267 |
||
1268 |
void RenderObject::repaintDuringLayoutIfMoved(const IntRect&) |
|
1269 |
{ |
|
1270 |
} |
|
1271 |
||
1272 |
void RenderObject::repaintOverhangingFloats(bool) |
|
1273 |
{ |
|
1274 |
} |
|
1275 |
||
1276 |
bool RenderObject::checkForRepaintDuringLayout() const |
|
1277 |
{ |
|
1278 |
// FIXME: <https://bugs.webkit.org/show_bug.cgi?id=20885> It is probably safe to also require |
|
1279 |
// m_everHadLayout. Currently, only RenderBlock::layoutBlock() adds this condition. See also |
|
1280 |
// <https://bugs.webkit.org/show_bug.cgi?id=15129>. |
|
1281 |
return !document()->view()->needsFullRepaint() && !hasLayer(); |
|
1282 |
} |
|
1283 |
||
1284 |
IntRect RenderObject::rectWithOutlineForRepaint(RenderBoxModelObject* repaintContainer, int outlineWidth) |
|
1285 |
{ |
|
1286 |
IntRect r(clippedOverflowRectForRepaint(repaintContainer)); |
|
1287 |
r.inflate(outlineWidth); |
|
1288 |
return r; |
|
1289 |
} |
|
1290 |
||
1291 |
IntRect RenderObject::clippedOverflowRectForRepaint(RenderBoxModelObject*) |
|
1292 |
{ |
|
1293 |
ASSERT_NOT_REACHED(); |
|
1294 |
return IntRect(); |
|
1295 |
} |
|
1296 |
||
1297 |
void RenderObject::computeRectForRepaint(RenderBoxModelObject* repaintContainer, IntRect& rect, bool fixed) |
|
1298 |
{ |
|
1299 |
if (repaintContainer == this) |
|
1300 |
return; |
|
1301 |
||
1302 |
if (RenderObject* o = parent()) { |
|
1303 |
if (o->isBlockFlow()) { |
|
1304 |
RenderBlock* cb = toRenderBlock(o); |
|
1305 |
if (cb->hasColumns()) |
|
1306 |
cb->adjustRectForColumns(rect); |
|
1307 |
} |
|
1308 |
||
1309 |
if (o->hasOverflowClip()) { |
|
1310 |
// o->height() is inaccurate if we're in the middle of a layout of |o|, so use the |
|
1311 |
// layer's size instead. Even if the layer's size is wrong, the layer itself will repaint |
|
1312 |
// anyway if its size does change. |
|
1313 |
RenderBox* boxParent = toRenderBox(o); |
|
1314 |
||
1315 |
IntRect boxRect(0, 0, boxParent->layer()->width(), boxParent->layer()->height()); |
|
1316 |
int x = rect.x(); |
|
1317 |
int y = rect.y(); |
|
1318 |
boxParent->layer()->subtractScrolledContentOffset(x, y); // For overflow:auto/scroll/hidden. |
|
1319 |
IntRect repaintRect(x, y, rect.width(), rect.height()); |
|
1320 |
rect = intersection(repaintRect, boxRect); |
|
1321 |
if (rect.isEmpty()) |
|
1322 |
return; |
|
1323 |
} |
|
1324 |
||
1325 |
o->computeRectForRepaint(repaintContainer, rect, fixed); |
|
1326 |
} |
|
1327 |
} |
|
1328 |
||
1329 |
void RenderObject::dirtyLinesFromChangedChild(RenderObject*) |
|
1330 |
{ |
|
1331 |
} |
|
1332 |
||
1333 |
#ifndef NDEBUG |
|
1334 |
||
1335 |
void RenderObject::showTreeForThis() const |
|
1336 |
{ |
|
1337 |
if (node()) |
|
1338 |
node()->showTreeForThis(); |
|
1339 |
} |
|
1340 |
||
1341 |
#endif // NDEBUG |
|
1342 |
||
1343 |
Color RenderObject::selectionBackgroundColor() const |
|
1344 |
{ |
|
1345 |
Color color; |
|
1346 |
if (style()->userSelect() != SELECT_NONE) { |
|
1347 |
RefPtr<RenderStyle> pseudoStyle = getUncachedPseudoStyle(SELECTION); |
|
1348 |
if (pseudoStyle && pseudoStyle->backgroundColor().isValid()) |
|
1349 |
color = pseudoStyle->backgroundColor().blendWithWhite(); |
|
1350 |
else |
|
1351 |
color = document()->frame()->selection()->isFocusedAndActive() ? |
|
1352 |
theme()->activeSelectionBackgroundColor() : |
|
1353 |
theme()->inactiveSelectionBackgroundColor(); |
|
1354 |
} |
|
1355 |
||
1356 |
return color; |
|
1357 |
} |
|
1358 |
||
1359 |
Color RenderObject::selectionForegroundColor() const |
|
1360 |
{ |
|
1361 |
Color color; |
|
1362 |
if (style()->userSelect() == SELECT_NONE) |
|
1363 |
return color; |
|
1364 |
||
1365 |
if (RefPtr<RenderStyle> pseudoStyle = getUncachedPseudoStyle(SELECTION)) { |
|
1366 |
color = pseudoStyle->textFillColor(); |
|
1367 |
if (!color.isValid()) |
|
1368 |
color = pseudoStyle->color(); |
|
1369 |
} else |
|
1370 |
color = document()->frame()->selection()->isFocusedAndActive() ? |
|
1371 |
theme()->activeSelectionForegroundColor() : |
|
1372 |
theme()->inactiveSelectionForegroundColor(); |
|
1373 |
||
1374 |
return color; |
|
1375 |
} |
|
1376 |
||
1377 |
#if ENABLE(DRAG_SUPPORT) |
|
1378 |
Node* RenderObject::draggableNode(bool dhtmlOK, bool uaOK, int x, int y, bool& dhtmlWillDrag) const |
|
1379 |
{ |
|
1380 |
if (!dhtmlOK && !uaOK) |
|
1381 |
return 0; |
|
1382 |
||
1383 |
for (const RenderObject* curr = this; curr; curr = curr->parent()) { |
|
1384 |
Node* elt = curr->node(); |
|
1385 |
if (elt && elt->nodeType() == Node::TEXT_NODE) { |
|
1386 |
// Since there's no way for the author to address the -webkit-user-drag style for a text node, |
|
1387 |
// we use our own judgement. |
|
1388 |
if (uaOK && view()->frameView()->frame()->eventHandler()->shouldDragAutoNode(curr->node(), IntPoint(x, y))) { |
|
1389 |
dhtmlWillDrag = false; |
|
1390 |
return curr->node(); |
|
1391 |
} |
|
1392 |
if (elt->canStartSelection()) |
|
1393 |
// In this case we have a click in the unselected portion of text. If this text is |
|
1394 |
// selectable, we want to start the selection process instead of looking for a parent |
|
1395 |
// to try to drag. |
|
1396 |
return 0; |
|
1397 |
} else { |
|
1398 |
EUserDrag dragMode = curr->style()->userDrag(); |
|
1399 |
if (dhtmlOK && dragMode == DRAG_ELEMENT) { |
|
1400 |
dhtmlWillDrag = true; |
|
1401 |
return curr->node(); |
|
1402 |
} |
|
1403 |
if (uaOK && dragMode == DRAG_AUTO |
|
1404 |
&& view()->frameView()->frame()->eventHandler()->shouldDragAutoNode(curr->node(), IntPoint(x, y))) { |
|
1405 |
dhtmlWillDrag = false; |
|
1406 |
return curr->node(); |
|
1407 |
} |
|
1408 |
} |
|
1409 |
} |
|
1410 |
return 0; |
|
1411 |
} |
|
1412 |
#endif // ENABLE(DRAG_SUPPORT) |
|
1413 |
||
1414 |
void RenderObject::selectionStartEnd(int& spos, int& epos) const |
|
1415 |
{ |
|
1416 |
view()->selectionStartEnd(spos, epos); |
|
1417 |
} |
|
1418 |
||
1419 |
void RenderObject::handleDynamicFloatPositionChange() |
|
1420 |
{ |
|
1421 |
// We have gone from not affecting the inline status of the parent flow to suddenly |
|
1422 |
// having an impact. See if there is a mismatch between the parent flow's |
|
1423 |
// childrenInline() state and our state. |
|
1424 |
setInline(style()->isDisplayInlineType()); |
|
1425 |
if (isInline() != parent()->childrenInline()) { |
|
1426 |
if (!isInline()) |
|
1427 |
toRenderBoxModelObject(parent())->childBecameNonInline(this); |
|
1428 |
else { |
|
1429 |
// An anonymous block must be made to wrap this inline. |
|
1430 |
RenderBlock* block = toRenderBlock(parent())->createAnonymousBlock(); |
|
1431 |
RenderObjectChildList* childlist = parent()->virtualChildren(); |
|
1432 |
childlist->insertChildNode(parent(), block, this); |
|
1433 |
block->children()->appendChildNode(block, childlist->removeChildNode(parent(), this)); |
|
1434 |
} |
|
1435 |
} |
|
1436 |
} |
|
1437 |
||
1438 |
void RenderObject::setAnimatableStyle(PassRefPtr<RenderStyle> style) |
|
1439 |
{ |
|
1440 |
if (!isText() && style) |
|
1441 |
setStyle(animation()->updateAnimations(this, style.get())); |
|
1442 |
else |
|
1443 |
setStyle(style); |
|
1444 |
} |
|
1445 |
||
1446 |
StyleDifference RenderObject::adjustStyleDifference(StyleDifference diff, unsigned contextSensitiveProperties) const |
|
1447 |
{ |
|
1448 |
#if USE(ACCELERATED_COMPOSITING) |
|
1449 |
// If transform changed, and we are not composited, need to do a layout. |
|
1450 |
if (contextSensitiveProperties & ContextSensitivePropertyTransform) { |
|
1451 |
// Text nodes share style with their parents but transforms don't apply to them, |
|
1452 |
// hence the !isText() check. |
|
1453 |
// FIXME: when transforms are taken into account for overflow, we will need to do a layout. |
|
1454 |
if (!isText() && (!hasLayer() || !toRenderBoxModelObject(this)->layer()->isComposited())) |
|
1455 |
diff = StyleDifferenceLayout; |
|
1456 |
else if (diff < StyleDifferenceRecompositeLayer) |
|
1457 |
diff = StyleDifferenceRecompositeLayer; |
|
1458 |
} |
|
1459 |
||
1460 |
// If opacity changed, and we are not composited, need to repaint (also |
|
1461 |
// ignoring text nodes) |
|
1462 |
if (contextSensitiveProperties & ContextSensitivePropertyOpacity) { |
|
1463 |
if (!isText() && (!hasLayer() || !toRenderBoxModelObject(this)->layer()->isComposited())) |
|
1464 |
diff = StyleDifferenceRepaintLayer; |
|
1465 |
else if (diff < StyleDifferenceRecompositeLayer) |
|
1466 |
diff = StyleDifferenceRecompositeLayer; |
|
1467 |
} |
|
1468 |
#else |
|
1469 |
UNUSED_PARAM(contextSensitiveProperties); |
|
1470 |
#endif |
|
1471 |
||
1472 |
// If we have no layer(), just treat a RepaintLayer hint as a normal Repaint. |
|
1473 |
if (diff == StyleDifferenceRepaintLayer && !hasLayer()) |
|
1474 |
diff = StyleDifferenceRepaint; |
|
1475 |
||
1476 |
return diff; |
|
1477 |
} |
|
1478 |
||
1479 |
void RenderObject::setStyle(PassRefPtr<RenderStyle> style) |
|
1480 |
{ |
|
1481 |
if (m_style == style) |
|
1482 |
return; |
|
1483 |
||
1484 |
StyleDifference diff = StyleDifferenceEqual; |
|
1485 |
unsigned contextSensitiveProperties = ContextSensitivePropertyNone; |
|
1486 |
if (m_style) |
|
1487 |
diff = m_style->diff(style.get(), contextSensitiveProperties); |
|
1488 |
||
1489 |
diff = adjustStyleDifference(diff, contextSensitiveProperties); |
|
1490 |
||
1491 |
styleWillChange(diff, style.get()); |
|
1492 |
||
1493 |
RefPtr<RenderStyle> oldStyle = m_style.release(); |
|
1494 |
m_style = style; |
|
1495 |
||
1496 |
updateFillImages(oldStyle ? oldStyle->backgroundLayers() : 0, m_style ? m_style->backgroundLayers() : 0); |
|
1497 |
updateFillImages(oldStyle ? oldStyle->maskLayers() : 0, m_style ? m_style->maskLayers() : 0); |
|
1498 |
||
1499 |
updateImage(oldStyle ? oldStyle->borderImage().image() : 0, m_style ? m_style->borderImage().image() : 0); |
|
1500 |
updateImage(oldStyle ? oldStyle->maskBoxImage().image() : 0, m_style ? m_style->maskBoxImage().image() : 0); |
|
1501 |
||
1502 |
// We need to ensure that view->maximalOutlineSize() is valid for any repaints that happen |
|
1503 |
// during styleDidChange (it's used by clippedOverflowRectForRepaint()). |
|
1504 |
if (m_style->outlineWidth() > 0 && m_style->outlineSize() > maximalOutlineSize(PaintPhaseOutline)) |
|
1505 |
toRenderView(document()->renderer())->setMaximalOutlineSize(m_style->outlineSize()); |
|
1506 |
||
1507 |
styleDidChange(diff, oldStyle.get()); |
|
1508 |
||
1509 |
if (!m_parent || isText()) |
|
1510 |
return; |
|
1511 |
||
1512 |
// Now that the layer (if any) has been updated, we need to adjust the diff again, |
|
1513 |
// check whether we should layout now, and decide if we need to repaint. |
|
1514 |
StyleDifference updatedDiff = adjustStyleDifference(diff, contextSensitiveProperties); |
|
1515 |
||
1516 |
if (diff <= StyleDifferenceLayoutPositionedMovementOnly) { |
|
1517 |
if (updatedDiff == StyleDifferenceLayout) |
|
1518 |
setNeedsLayoutAndPrefWidthsRecalc(); |
|
1519 |
else if (updatedDiff == StyleDifferenceLayoutPositionedMovementOnly) |
|
1520 |
setNeedsPositionedMovementLayout(); |
|
1521 |
} |
|
1522 |
||
1523 |
if (updatedDiff == StyleDifferenceRepaintLayer || updatedDiff == StyleDifferenceRepaint) { |
|
1524 |
// Do a repaint with the new style now, e.g., for example if we go from |
|
1525 |
// not having an outline to having an outline. |
|
1526 |
repaint(); |
|
1527 |
} |
|
1528 |
} |
|
1529 |
||
1530 |
void RenderObject::setStyleInternal(PassRefPtr<RenderStyle> style) |
|
1531 |
{ |
|
1532 |
m_style = style; |
|
1533 |
} |
|
1534 |
||
1535 |
void RenderObject::styleWillChange(StyleDifference diff, const RenderStyle* newStyle) |
|
1536 |
{ |
|
1537 |
if (m_style) { |
|
1538 |
// If our z-index changes value or our visibility changes, |
|
1539 |
// we need to dirty our stacking context's z-order list. |
|
1540 |
if (newStyle) { |
|
1541 |
bool visibilityChanged = m_style->visibility() != newStyle->visibility() |
|
1542 |
|| m_style->zIndex() != newStyle->zIndex() |
|
1543 |
|| m_style->hasAutoZIndex() != newStyle->hasAutoZIndex(); |
|
1544 |
#if ENABLE(DASHBOARD_SUPPORT) |
|
1545 |
if (visibilityChanged) |
|
1546 |
document()->setDashboardRegionsDirty(true); |
|
1547 |
#endif |
|
1548 |
if (visibilityChanged && AXObjectCache::accessibilityEnabled()) |
|
1549 |
document()->axObjectCache()->childrenChanged(this); |
|
1550 |
||
1551 |
// Keep layer hierarchy visibility bits up to date if visibility changes. |
|
1552 |
if (m_style->visibility() != newStyle->visibility()) { |
|
1553 |
if (RenderLayer* l = enclosingLayer()) { |
|
1554 |
if (newStyle->visibility() == VISIBLE) |
|
1555 |
l->setHasVisibleContent(true); |
|
1556 |
else if (l->hasVisibleContent() && (this == l->renderer() || l->renderer()->style()->visibility() != VISIBLE)) { |
|
1557 |
l->dirtyVisibleContentStatus(); |
|
1558 |
if (diff > StyleDifferenceRepaintLayer) |
|
1559 |
repaint(); |
|
1560 |
} |
|
1561 |
} |
|
1562 |
} |
|
1563 |
} |
|
1564 |
||
1565 |
if (m_parent && (diff == StyleDifferenceRepaint || newStyle->outlineSize() < m_style->outlineSize())) |
|
1566 |
repaint(); |
|
1567 |
if (isFloating() && (m_style->floating() != newStyle->floating())) |
|
1568 |
// For changes in float styles, we need to conceivably remove ourselves |
|
1569 |
// from the floating objects list. |
|
1570 |
toRenderBox(this)->removeFloatingOrPositionedChildFromBlockLists(); |
|
1571 |
else if (isPositioned() && (m_style->position() != newStyle->position())) |
|
1572 |
// For changes in positioning styles, we need to conceivably remove ourselves |
|
1573 |
// from the positioned objects list. |
|
1574 |
toRenderBox(this)->removeFloatingOrPositionedChildFromBlockLists(); |
|
1575 |
||
1576 |
s_affectsParentBlock = isFloatingOrPositioned() && |
|
1577 |
(!newStyle->isFloating() && newStyle->position() != AbsolutePosition && newStyle->position() != FixedPosition) |
|
1578 |
&& parent() && (parent()->isBlockFlow() || parent()->isRenderInline()); |
|
1579 |
||
1580 |
// reset style flags |
|
1581 |
if (diff == StyleDifferenceLayout || diff == StyleDifferenceLayoutPositionedMovementOnly) { |
|
1582 |
m_floating = false; |
|
1583 |
m_positioned = false; |
|
1584 |
m_relPositioned = false; |
|
1585 |
} |
|
1586 |
m_paintBackground = false; |
|
1587 |
m_hasOverflowClip = false; |
|
1588 |
m_hasTransform = false; |
|
1589 |
m_hasReflection = false; |
|
1590 |
} else |
|
1591 |
s_affectsParentBlock = false; |
|
1592 |
||
1593 |
if (view()->frameView()) { |
|
19
fcece45ef507
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1594 |
bool shouldBlitOnFixedBackgroundImage = false; |
fcece45ef507
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1595 |
#if ENABLE(FAST_MOBILE_SCROLLING) |
fcece45ef507
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1596 |
// On low-powered/mobile devices, preventing blitting on a scroll can cause noticeable delays |
fcece45ef507
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1597 |
// when scrolling a page with a fixed background image. As an optimization, assuming there are |
fcece45ef507
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1598 |
// no fixed positoned elements on the page, we can acclerate scrolling (via blitting) if we |
fcece45ef507
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1599 |
// ignore the CSS property "background-attachment: fixed". |
fcece45ef507
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1600 |
shouldBlitOnFixedBackgroundImage = true; |
fcece45ef507
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1601 |
#endif |
fcece45ef507
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1602 |
|
fcece45ef507
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1603 |
bool newStyleSlowScroll = newStyle && !shouldBlitOnFixedBackgroundImage && newStyle->hasFixedBackgroundImage(); |
fcece45ef507
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1604 |
bool oldStyleSlowScroll = m_style && !shouldBlitOnFixedBackgroundImage && m_style->hasFixedBackgroundImage(); |
0 | 1605 |
if (oldStyleSlowScroll != newStyleSlowScroll) { |
1606 |
if (oldStyleSlowScroll) |
|
1607 |
view()->frameView()->removeSlowRepaintObject(); |
|
1608 |
if (newStyleSlowScroll) |
|
1609 |
view()->frameView()->addSlowRepaintObject(); |
|
1610 |
} |
|
1611 |
} |
|
1612 |
} |
|
1613 |
||
1614 |
void RenderObject::styleDidChange(StyleDifference diff, const RenderStyle*) |
|
1615 |
{ |
|
1616 |
if (s_affectsParentBlock) |
|
1617 |
handleDynamicFloatPositionChange(); |
|
1618 |
||
1619 |
if (!m_parent) |
|
1620 |
return; |
|
1621 |
||
1622 |
if (diff == StyleDifferenceLayout) |
|
1623 |
setNeedsLayoutAndPrefWidthsRecalc(); |
|
1624 |
else if (diff == StyleDifferenceLayoutPositionedMovementOnly) |
|
1625 |
setNeedsPositionedMovementLayout(); |
|
1626 |
||
1627 |
// Don't check for repaint here; we need to wait until the layer has been |
|
1628 |
// updated by subclasses before we know if we have to repaint (in setStyle()). |
|
1629 |
} |
|
1630 |
||
1631 |
void RenderObject::updateFillImages(const FillLayer* oldLayers, const FillLayer* newLayers) |
|
1632 |
{ |
|
1633 |
// Optimize the common case |
|
1634 |
if (oldLayers && !oldLayers->next() && newLayers && !newLayers->next() && (oldLayers->image() == newLayers->image())) |
|
1635 |
return; |
|
1636 |
||
1637 |
// Go through the new layers and addClients first, to avoid removing all clients of an image. |
|
1638 |
for (const FillLayer* currNew = newLayers; currNew; currNew = currNew->next()) { |
|
1639 |
if (currNew->image()) |
|
1640 |
currNew->image()->addClient(this); |
|
1641 |
} |
|
1642 |
||
1643 |
for (const FillLayer* currOld = oldLayers; currOld; currOld = currOld->next()) { |
|
1644 |
if (currOld->image()) |
|
1645 |
currOld->image()->removeClient(this); |
|
1646 |
} |
|
1647 |
} |
|
1648 |
||
1649 |
void RenderObject::updateImage(StyleImage* oldImage, StyleImage* newImage) |
|
1650 |
{ |
|
1651 |
if (oldImage != newImage) { |
|
1652 |
if (oldImage) |
|
1653 |
oldImage->removeClient(this); |
|
1654 |
if (newImage) |
|
1655 |
newImage->addClient(this); |
|
1656 |
} |
|
1657 |
} |
|
1658 |
||
1659 |
IntRect RenderObject::viewRect() const |
|
1660 |
{ |
|
1661 |
return view()->viewRect(); |
|
1662 |
} |
|
1663 |
||
1664 |
FloatPoint RenderObject::localToAbsolute(FloatPoint localPoint, bool fixed, bool useTransforms) const |
|
1665 |
{ |
|
1666 |
TransformState transformState(TransformState::ApplyTransformDirection, localPoint); |
|
1667 |
mapLocalToContainer(0, fixed, useTransforms, transformState); |
|
1668 |
transformState.flatten(); |
|
1669 |
||
1670 |
return transformState.lastPlanarPoint(); |
|
1671 |
} |
|
1672 |
||
1673 |
FloatPoint RenderObject::absoluteToLocal(FloatPoint containerPoint, bool fixed, bool useTransforms) const |
|
1674 |
{ |
|
1675 |
TransformState transformState(TransformState::UnapplyInverseTransformDirection, containerPoint); |
|
1676 |
mapAbsoluteToLocalPoint(fixed, useTransforms, transformState); |
|
1677 |
transformState.flatten(); |
|
1678 |
||
1679 |
return transformState.lastPlanarPoint(); |
|
1680 |
} |
|
1681 |
||
1682 |
void RenderObject::mapLocalToContainer(RenderBoxModelObject* repaintContainer, bool fixed, bool useTransforms, TransformState& transformState) const |
|
1683 |
{ |
|
1684 |
if (repaintContainer == this) |
|
1685 |
return; |
|
1686 |
||
1687 |
RenderObject* o = parent(); |
|
1688 |
if (!o) |
|
1689 |
return; |
|
1690 |
||
1691 |
if (o->hasOverflowClip()) |
|
1692 |
transformState.move(-toRenderBox(o)->layer()->scrolledContentOffset()); |
|
1693 |
||
1694 |
o->mapLocalToContainer(repaintContainer, fixed, useTransforms, transformState); |
|
1695 |
} |
|
1696 |
||
1697 |
void RenderObject::mapAbsoluteToLocalPoint(bool fixed, bool useTransforms, TransformState& transformState) const |
|
1698 |
{ |
|
1699 |
RenderObject* o = parent(); |
|
1700 |
if (o) { |
|
1701 |
o->mapAbsoluteToLocalPoint(fixed, useTransforms, transformState); |
|
1702 |
if (o->hasOverflowClip()) |
|
1703 |
transformState.move(toRenderBox(o)->layer()->scrolledContentOffset()); |
|
1704 |
} |
|
1705 |
} |
|
1706 |
||
1707 |
bool RenderObject::shouldUseTransformFromContainer(const RenderObject* containerObject) const |
|
1708 |
{ |
|
1709 |
#if ENABLE(3D_RENDERING) |
|
1710 |
// hasTransform() indicates whether the object has transform, transform-style or perspective. We just care about transform, |
|
1711 |
// so check the layer's transform directly. |
|
1712 |
return (hasLayer() && toRenderBoxModelObject(this)->layer()->transform()) || (containerObject && containerObject->style()->hasPerspective()); |
|
1713 |
#else |
|
1714 |
UNUSED_PARAM(containerObject); |
|
1715 |
return hasTransform(); |
|
1716 |
#endif |
|
1717 |
} |
|
1718 |
||
1719 |
void RenderObject::getTransformFromContainer(const RenderObject* containerObject, const IntSize& offsetInContainer, TransformationMatrix& transform) const |
|
1720 |
{ |
|
1721 |
transform.makeIdentity(); |
|
1722 |
transform.translate(offsetInContainer.width(), offsetInContainer.height()); |
|
1723 |
RenderLayer* layer; |
|
1724 |
if (hasLayer() && (layer = toRenderBoxModelObject(this)->layer()) && layer->transform()) |
|
1725 |
transform.multLeft(layer->currentTransform()); |
|
1726 |
||
1727 |
#if ENABLE(3D_RENDERING) |
|
1728 |
if (containerObject && containerObject->hasLayer() && containerObject->style()->hasPerspective()) { |
|
1729 |
// Perpsective on the container affects us, so we have to factor it in here. |
|
1730 |
ASSERT(containerObject->hasLayer()); |
|
1731 |
FloatPoint perspectiveOrigin = toRenderBox(containerObject)->layer()->perspectiveOrigin(); |
|
1732 |
||
1733 |
TransformationMatrix perspectiveMatrix; |
|
1734 |
perspectiveMatrix.applyPerspective(containerObject->style()->perspective()); |
|
1735 |
||
1736 |
transform.translateRight3d(-perspectiveOrigin.x(), -perspectiveOrigin.y(), 0); |
|
1737 |
transform.multiply(perspectiveMatrix); |
|
1738 |
transform.translateRight3d(perspectiveOrigin.x(), perspectiveOrigin.y(), 0); |
|
1739 |
} |
|
1740 |
#else |
|
1741 |
UNUSED_PARAM(containerObject); |
|
1742 |
#endif |
|
1743 |
} |
|
1744 |
||
1745 |
FloatQuad RenderObject::localToContainerQuad(const FloatQuad& localQuad, RenderBoxModelObject* repaintContainer, bool fixed) const |
|
1746 |
{ |
|
1747 |
TransformState transformState(TransformState::ApplyTransformDirection, FloatPoint(), &localQuad); |
|
1748 |
mapLocalToContainer(repaintContainer, fixed, true, transformState); |
|
1749 |
transformState.flatten(); |
|
1750 |
||
1751 |
return transformState.lastPlanarQuad(); |
|
1752 |
} |
|
1753 |
||
1754 |
IntSize RenderObject::offsetFromContainer(RenderObject* o) const |
|
1755 |
{ |
|
1756 |
ASSERT(o == container()); |
|
1757 |
||
1758 |
IntSize offset; |
|
1759 |
if (o->hasOverflowClip()) |
|
1760 |
offset -= toRenderBox(o)->layer()->scrolledContentOffset(); |
|
1761 |
||
1762 |
return offset; |
|
1763 |
} |
|
1764 |
||
1765 |
IntSize RenderObject::offsetFromAncestorContainer(RenderObject* container) const |
|
1766 |
{ |
|
1767 |
IntSize offset; |
|
1768 |
const RenderObject* currContainer = this; |
|
1769 |
do { |
|
1770 |
RenderObject* nextContainer = currContainer->container(); |
|
1771 |
ASSERT(nextContainer); // This means we reached the top without finding container. |
|
1772 |
if (!nextContainer) |
|
1773 |
break; |
|
1774 |
ASSERT(!currContainer->hasTransform()); |
|
1775 |
offset += currContainer->offsetFromContainer(nextContainer); |
|
1776 |
currContainer = nextContainer; |
|
1777 |
} while (currContainer != container); |
|
1778 |
||
1779 |
return offset; |
|
1780 |
} |
|
1781 |
||
1782 |
IntRect RenderObject::localCaretRect(InlineBox*, int, int* extraWidthToEndOfLine) |
|
1783 |
{ |
|
1784 |
if (extraWidthToEndOfLine) |
|
1785 |
*extraWidthToEndOfLine = 0; |
|
1786 |
||
1787 |
return IntRect(); |
|
1788 |
} |
|
1789 |
||
1790 |
RenderView* RenderObject::view() const |
|
1791 |
{ |
|
1792 |
return toRenderView(document()->renderer()); |
|
1793 |
} |
|
1794 |
||
1795 |
bool RenderObject::isRooted(RenderView** view) |
|
1796 |
{ |
|
1797 |
RenderObject* o = this; |
|
1798 |
while (o->parent()) |
|
1799 |
o = o->parent(); |
|
1800 |
||
1801 |
if (!o->isRenderView()) |
|
1802 |
return false; |
|
1803 |
||
1804 |
if (view) |
|
1805 |
*view = toRenderView(o); |
|
1806 |
||
1807 |
return true; |
|
1808 |
} |
|
1809 |
||
1810 |
bool RenderObject::hasOutlineAnnotation() const |
|
1811 |
{ |
|
1812 |
return node() && node()->isLink() && document()->printing(); |
|
1813 |
} |
|
1814 |
||
1815 |
RenderObject* RenderObject::container(RenderBoxModelObject* repaintContainer, bool* repaintContainerSkipped) const |
|
1816 |
{ |
|
1817 |
if (repaintContainerSkipped) |
|
1818 |
*repaintContainerSkipped = false; |
|
1819 |
||
1820 |
// This method is extremely similar to containingBlock(), but with a few notable |
|
1821 |
// exceptions. |
|
1822 |
// (1) It can be used on orphaned subtrees, i.e., it can be called safely even when |
|
1823 |
// the object is not part of the primary document subtree yet. |
|
1824 |
// (2) For normal flow elements, it just returns the parent. |
|
1825 |
// (3) For absolute positioned elements, it will return a relative positioned inline. |
|
1826 |
// containingBlock() simply skips relpositioned inlines and lets an enclosing block handle |
|
1827 |
// the layout of the positioned object. This does mean that calcAbsoluteHorizontal and |
|
1828 |
// calcAbsoluteVertical have to use container(). |
|
1829 |
RenderObject* o = parent(); |
|
1830 |
||
1831 |
if (isText()) |
|
1832 |
return o; |
|
1833 |
||
1834 |
EPosition pos = m_style->position(); |
|
1835 |
if (pos == FixedPosition) { |
|
1836 |
// container() can be called on an object that is not in the |
|
1837 |
// tree yet. We don't call view() since it will assert if it |
|
1838 |
// can't get back to the canvas. Instead we just walk as high up |
|
1839 |
// as we can. If we're in the tree, we'll get the root. If we |
|
1840 |
// aren't we'll get the root of our little subtree (most likely |
|
1841 |
// we'll just return 0). |
|
1842 |
// FIXME: The definition of view() has changed to not crawl up the render tree. It might |
|
1843 |
// be safe now to use it. |
|
1844 |
while (o && o->parent() && !(o->hasTransform() && o->isRenderBlock())) { |
|
1845 |
if (repaintContainerSkipped && o == repaintContainer) |
|
1846 |
*repaintContainerSkipped = true; |
|
1847 |
o = o->parent(); |
|
1848 |
} |
|
1849 |
} else if (pos == AbsolutePosition) { |
|
1850 |
// Same goes here. We technically just want our containing block, but |
|
1851 |
// we may not have one if we're part of an uninstalled subtree. We'll |
|
1852 |
// climb as high as we can though. |
|
1853 |
while (o && o->style()->position() == StaticPosition && !o->isRenderView() && !(o->hasTransform() && o->isRenderBlock())) { |
|
1854 |
if (repaintContainerSkipped && o == repaintContainer) |
|
1855 |
*repaintContainerSkipped = true; |
|
1856 |
o = o->parent(); |
|
1857 |
} |
|
1858 |
} |
|
1859 |
||
1860 |
return o; |
|
1861 |
} |
|
1862 |
||
1863 |
bool RenderObject::isSelectionBorder() const |
|
1864 |
{ |
|
1865 |
SelectionState st = selectionState(); |
|
1866 |
return st == SelectionStart || st == SelectionEnd || st == SelectionBoth; |
|
1867 |
} |
|
1868 |
||
1869 |
void RenderObject::destroy() |
|
1870 |
{ |
|
1871 |
// Destroy any leftover anonymous children. |
|
1872 |
RenderObjectChildList* children = virtualChildren(); |
|
1873 |
if (children) |
|
1874 |
children->destroyLeftoverChildren(); |
|
1875 |
||
1876 |
// If this renderer is being autoscrolled, stop the autoscroll timer |
|
1877 |
||
1878 |
// FIXME: RenderObject::destroy should not get called with a renderar whose document |
|
1879 |
// has a null frame, so we assert this. However, we don't want release builds to crash which is why we |
|
1880 |
// check that the frame is not null. |
|
1881 |
ASSERT(document()->frame()); |
|
1882 |
if (document()->frame() && document()->frame()->eventHandler()->autoscrollRenderer() == this) |
|
1883 |
document()->frame()->eventHandler()->stopAutoscrollTimer(true); |
|
1884 |
||
1885 |
if (m_hasCounterNodeMap) |
|
1886 |
RenderCounter::destroyCounterNodes(this); |
|
1887 |
||
1888 |
if (AXObjectCache::accessibilityEnabled()) { |
|
1889 |
document()->axObjectCache()->childrenChanged(this->parent()); |
|
1890 |
document()->axObjectCache()->remove(this); |
|
1891 |
} |
|
1892 |
animation()->cancelAnimations(this); |
|
1893 |
||
1894 |
// By default no ref-counting. RenderWidget::destroy() doesn't call |
|
1895 |
// this function because it needs to do ref-counting. If anything |
|
1896 |
// in this function changes, be sure to fix RenderWidget::destroy() as well. |
|
1897 |
||
1898 |
remove(); |
|
1899 |
||
1900 |
// FIXME: Would like to do this in RenderBoxModelObject, but the timing is so complicated that this can't easily |
|
1901 |
// be moved into RenderBoxModelObject::destroy. |
|
1902 |
if (hasLayer()) { |
|
1903 |
setHasLayer(false); |
|
1904 |
toRenderBoxModelObject(this)->destroyLayer(); |
|
1905 |
} |
|
1906 |
arenaDelete(renderArena(), this); |
|
1907 |
} |
|
1908 |
||
1909 |
void RenderObject::arenaDelete(RenderArena* arena, void* base) |
|
1910 |
{ |
|
1911 |
if (m_style) { |
|
1912 |
for (const FillLayer* bgLayer = m_style->backgroundLayers(); bgLayer; bgLayer = bgLayer->next()) { |
|
1913 |
if (StyleImage* backgroundImage = bgLayer->image()) |
|
1914 |
backgroundImage->removeClient(this); |
|
1915 |
} |
|
1916 |
||
1917 |
for (const FillLayer* maskLayer = m_style->maskLayers(); maskLayer; maskLayer = maskLayer->next()) { |
|
1918 |
if (StyleImage* maskImage = maskLayer->image()) |
|
1919 |
maskImage->removeClient(this); |
|
1920 |
} |
|
1921 |
||
1922 |
if (StyleImage* borderImage = m_style->borderImage().image()) |
|
1923 |
borderImage->removeClient(this); |
|
1924 |
||
1925 |
if (StyleImage* maskBoxImage = m_style->maskBoxImage().image()) |
|
1926 |
maskBoxImage->removeClient(this); |
|
1927 |
} |
|
1928 |
||
1929 |
#ifndef NDEBUG |
|
1930 |
void* savedBase = baseOfRenderObjectBeingDeleted; |
|
1931 |
baseOfRenderObjectBeingDeleted = base; |
|
1932 |
#endif |
|
1933 |
delete this; |
|
1934 |
#ifndef NDEBUG |
|
1935 |
baseOfRenderObjectBeingDeleted = savedBase; |
|
1936 |
#endif |
|
1937 |
||
1938 |
// Recover the size left there for us by operator delete and free the memory. |
|
1939 |
arena->free(*(size_t*)base, base); |
|
1940 |
} |
|
1941 |
||
1942 |
VisiblePosition RenderObject::positionForCoordinates(int x, int y) |
|
1943 |
{ |
|
1944 |
return positionForPoint(IntPoint(x, y)); |
|
1945 |
} |
|
1946 |
||
1947 |
VisiblePosition RenderObject::positionForPoint(const IntPoint&) |
|
1948 |
{ |
|
1949 |
return createVisiblePosition(caretMinOffset(), DOWNSTREAM); |
|
1950 |
} |
|
1951 |
||
1952 |
void RenderObject::updateDragState(bool dragOn) |
|
1953 |
{ |
|
1954 |
bool valueChanged = (dragOn != m_isDragging); |
|
1955 |
m_isDragging = dragOn; |
|
1956 |
if (valueChanged && style()->affectedByDragRules()) |
|
1957 |
node()->setNeedsStyleRecalc(); |
|
1958 |
for (RenderObject* curr = firstChild(); curr; curr = curr->nextSibling()) |
|
1959 |
curr->updateDragState(dragOn); |
|
1960 |
} |
|
1961 |
||
1962 |
bool RenderObject::hitTest(const HitTestRequest& request, HitTestResult& result, const IntPoint& point, int tx, int ty, HitTestFilter hitTestFilter) |
|
1963 |
{ |
|
1964 |
bool inside = false; |
|
1965 |
if (hitTestFilter != HitTestSelf) { |
|
1966 |
// First test the foreground layer (lines and inlines). |
|
1967 |
inside = nodeAtPoint(request, result, point.x(), point.y(), tx, ty, HitTestForeground); |
|
1968 |
||
1969 |
// Test floats next. |
|
1970 |
if (!inside) |
|
1971 |
inside = nodeAtPoint(request, result, point.x(), point.y(), tx, ty, HitTestFloat); |
|
1972 |
||
1973 |
// Finally test to see if the mouse is in the background (within a child block's background). |
|
1974 |
if (!inside) |
|
1975 |
inside = nodeAtPoint(request, result, point.x(), point.y(), tx, ty, HitTestChildBlockBackgrounds); |
|
1976 |
} |
|
1977 |
||
1978 |
// See if the mouse is inside us but not any of our descendants |
|
1979 |
if (hitTestFilter != HitTestDescendants && !inside) |
|
1980 |
inside = nodeAtPoint(request, result, point.x(), point.y(), tx, ty, HitTestBlockBackground); |
|
1981 |
||
1982 |
return inside; |
|
1983 |
} |
|
1984 |
||
1985 |
void RenderObject::updateHitTestResult(HitTestResult& result, const IntPoint& point) |
|
1986 |
{ |
|
1987 |
if (result.innerNode()) |
|
1988 |
return; |
|
1989 |
||
1990 |
Node* n = node(); |
|
1991 |
if (n) { |
|
1992 |
result.setInnerNode(n); |
|
1993 |
if (!result.innerNonSharedNode()) |
|
1994 |
result.setInnerNonSharedNode(n); |
|
1995 |
result.setLocalPoint(point); |
|
1996 |
} |
|
1997 |
} |
|
1998 |
||
1999 |
bool RenderObject::nodeAtPoint(const HitTestRequest&, HitTestResult&, int /*x*/, int /*y*/, int /*tx*/, int /*ty*/, HitTestAction) |
|
2000 |
{ |
|
2001 |
return false; |
|
2002 |
} |
|
2003 |
||
2004 |
int RenderObject::lineHeight(bool firstLine, bool /*isRootLineBox*/) const |
|
2005 |
{ |
|
2006 |
return style(firstLine)->computedLineHeight(); |
|
2007 |
} |
|
2008 |
||
2009 |
int RenderObject::baselinePosition(bool firstLine, bool isRootLineBox) const |
|
2010 |
{ |
|
2011 |
const Font& f = style(firstLine)->font(); |
|
2012 |
return f.ascent() + (lineHeight(firstLine, isRootLineBox) - f.height()) / 2; |
|
2013 |
} |
|
2014 |
||
2015 |
void RenderObject::scheduleRelayout() |
|
2016 |
{ |
|
2017 |
if (isRenderView()) { |
|
2018 |
FrameView* view = toRenderView(this)->frameView(); |
|
2019 |
if (view) |
|
2020 |
view->scheduleRelayout(); |
|
2021 |
} else if (parent()) { |
|
2022 |
FrameView* v = view() ? view()->frameView() : 0; |
|
2023 |
if (v) |
|
2024 |
v->scheduleRelayoutOfSubtree(this); |
|
2025 |
} |
|
2026 |
} |
|
2027 |
||
2028 |
void RenderObject::layout() |
|
2029 |
{ |
|
2030 |
ASSERT(needsLayout()); |
|
2031 |
RenderObject* child = firstChild(); |
|
2032 |
while (child) { |
|
2033 |
child->layoutIfNeeded(); |
|
2034 |
ASSERT(!child->needsLayout()); |
|
2035 |
child = child->nextSibling(); |
|
2036 |
} |
|
2037 |
setNeedsLayout(false); |
|
2038 |
} |
|
2039 |
||
2040 |
PassRefPtr<RenderStyle> RenderObject::uncachedFirstLineStyle(RenderStyle* style) const |
|
2041 |
{ |
|
2042 |
if (!document()->usesFirstLineRules()) |
|
2043 |
return 0; |
|
2044 |
||
2045 |
ASSERT(!isText()); |
|
2046 |
||
2047 |
RefPtr<RenderStyle> result; |
|
2048 |
||
2049 |
if (isBlockFlow()) { |
|
2050 |
if (RenderBlock* firstLineBlock = this->firstLineBlock()) |
|
2051 |
result = firstLineBlock->getUncachedPseudoStyle(FIRST_LINE, style, firstLineBlock == this ? style : 0); |
|
2052 |
} else if (!isAnonymous() && isRenderInline()) { |
|
2053 |
RenderStyle* parentStyle = parent()->firstLineStyle(); |
|
2054 |
if (parentStyle != parent()->style()) |
|
2055 |
result = getUncachedPseudoStyle(FIRST_LINE_INHERITED, parentStyle, style); |
|
2056 |
} |
|
2057 |
||
2058 |
return result.release(); |
|
2059 |
} |
|
2060 |
||
2061 |
RenderStyle* RenderObject::firstLineStyleSlowCase() const |
|
2062 |
{ |
|
2063 |
ASSERT(document()->usesFirstLineRules()); |
|
2064 |
||
2065 |
RenderStyle* style = m_style.get(); |
|
2066 |
const RenderObject* renderer = isText() ? parent() : this; |
|
2067 |
if (renderer->isBlockFlow()) { |
|
2068 |
if (RenderBlock* firstLineBlock = renderer->firstLineBlock()) |
|
2069 |
style = firstLineBlock->getCachedPseudoStyle(FIRST_LINE, style); |
|
2070 |
} else if (!renderer->isAnonymous() && renderer->isRenderInline()) { |
|
2071 |
RenderStyle* parentStyle = renderer->parent()->firstLineStyle(); |
|
2072 |
if (parentStyle != renderer->parent()->style()) { |
|
2073 |
// A first-line style is in effect. Cache a first-line style for ourselves. |
|
2074 |
style->setHasPseudoStyle(FIRST_LINE_INHERITED); |
|
2075 |
style = renderer->getCachedPseudoStyle(FIRST_LINE_INHERITED, parentStyle); |
|
2076 |
} |
|
2077 |
} |
|
2078 |
||
2079 |
return style; |
|
2080 |
} |
|
2081 |
||
2082 |
RenderStyle* RenderObject::getCachedPseudoStyle(PseudoId pseudo, RenderStyle* parentStyle) const |
|
2083 |
{ |
|
2084 |
if (pseudo < FIRST_INTERNAL_PSEUDOID && !style()->hasPseudoStyle(pseudo)) |
|
2085 |
return 0; |
|
2086 |
||
2087 |
RenderStyle* cachedStyle = style()->getCachedPseudoStyle(pseudo); |
|
2088 |
if (cachedStyle) |
|
2089 |
return cachedStyle; |
|
2090 |
||
2091 |
RefPtr<RenderStyle> result = getUncachedPseudoStyle(pseudo, parentStyle); |
|
2092 |
if (result) |
|
2093 |
return style()->addCachedPseudoStyle(result.release()); |
|
2094 |
return 0; |
|
2095 |
} |
|
2096 |
||
2097 |
PassRefPtr<RenderStyle> RenderObject::getUncachedPseudoStyle(PseudoId pseudo, RenderStyle* parentStyle, RenderStyle* ownStyle) const |
|
2098 |
{ |
|
2099 |
if (pseudo < FIRST_INTERNAL_PSEUDOID && !ownStyle && !style()->hasPseudoStyle(pseudo)) |
|
2100 |
return 0; |
|
2101 |
||
2102 |
if (!parentStyle) { |
|
2103 |
ASSERT(!ownStyle); |
|
2104 |
parentStyle = style(); |
|
2105 |
} |
|
2106 |
||
2107 |
Node* n = node(); |
|
2108 |
while (n && !n->isElementNode()) |
|
2109 |
n = n->parentNode(); |
|
2110 |
if (!n) |
|
2111 |
return 0; |
|
2112 |
||
2113 |
RefPtr<RenderStyle> result; |
|
2114 |
if (pseudo == FIRST_LINE_INHERITED) { |
|
2115 |
result = document()->styleSelector()->styleForElement(static_cast<Element*>(n), parentStyle, false); |
|
2116 |
result->setStyleType(FIRST_LINE_INHERITED); |
|
2117 |
} else |
|
2118 |
result = document()->styleSelector()->pseudoStyleForElement(pseudo, static_cast<Element*>(n), parentStyle); |
|
2119 |
return result.release(); |
|
2120 |
} |
|
2121 |
||
2122 |
static Color decorationColor(RenderStyle* style) |
|
2123 |
{ |
|
2124 |
Color result; |
|
2125 |
if (style->textStrokeWidth() > 0) { |
|
2126 |
// Prefer stroke color if possible but not if it's fully transparent. |
|
2127 |
result = style->textStrokeColor(); |
|
2128 |
if (!result.isValid()) |
|
2129 |
result = style->color(); |
|
2130 |
if (result.alpha()) |
|
2131 |
return result; |
|
2132 |
} |
|
2133 |
||
2134 |
result = style->textFillColor(); |
|
2135 |
if (!result.isValid()) |
|
2136 |
result = style->color(); |
|
2137 |
return result; |
|
2138 |
} |
|
2139 |
||
2140 |
void RenderObject::getTextDecorationColors(int decorations, Color& underline, Color& overline, |
|
2141 |
Color& linethrough, bool quirksMode) |
|
2142 |
{ |
|
2143 |
RenderObject* curr = this; |
|
2144 |
do { |
|
2145 |
int currDecs = curr->style()->textDecoration(); |
|
2146 |
if (currDecs) { |
|
2147 |
if (currDecs & UNDERLINE) { |
|
2148 |
decorations &= ~UNDERLINE; |
|
2149 |
underline = decorationColor(curr->style()); |
|
2150 |
} |
|
2151 |
if (currDecs & OVERLINE) { |
|
2152 |
decorations &= ~OVERLINE; |
|
2153 |
overline = decorationColor(curr->style()); |
|
2154 |
} |
|
2155 |
if (currDecs & LINE_THROUGH) { |
|
2156 |
decorations &= ~LINE_THROUGH; |
|
2157 |
linethrough = decorationColor(curr->style()); |
|
2158 |
} |
|
2159 |
} |
|
2160 |
curr = curr->parent(); |
|
2161 |
if (curr && curr->isRenderBlock() && toRenderBlock(curr)->inlineContinuation()) |
|
2162 |
curr = toRenderBlock(curr)->inlineContinuation(); |
|
2163 |
} while (curr && decorations && (!quirksMode || !curr->node() || |
|
2164 |
(!curr->node()->hasTagName(aTag) && !curr->node()->hasTagName(fontTag)))); |
|
2165 |
||
2166 |
// If we bailed out, use the element we bailed out at (typically a <font> or <a> element). |
|
2167 |
if (decorations && curr) { |
|
2168 |
if (decorations & UNDERLINE) |
|
2169 |
underline = decorationColor(curr->style()); |
|
2170 |
if (decorations & OVERLINE) |
|
2171 |
overline = decorationColor(curr->style()); |
|
2172 |
if (decorations & LINE_THROUGH) |
|
2173 |
linethrough = decorationColor(curr->style()); |
|
2174 |
} |
|
2175 |
} |
|
2176 |
||
2177 |
#if ENABLE(DASHBOARD_SUPPORT) |
|
2178 |
void RenderObject::addDashboardRegions(Vector<DashboardRegionValue>& regions) |
|
2179 |
{ |
|
2180 |
// Convert the style regions to absolute coordinates. |
|
2181 |
if (style()->visibility() != VISIBLE || !isBox()) |
|
2182 |
return; |
|
2183 |
||
2184 |
RenderBox* box = toRenderBox(this); |
|
2185 |
||
2186 |
const Vector<StyleDashboardRegion>& styleRegions = style()->dashboardRegions(); |
|
2187 |
unsigned i, count = styleRegions.size(); |
|
2188 |
for (i = 0; i < count; i++) { |
|
2189 |
StyleDashboardRegion styleRegion = styleRegions[i]; |
|
2190 |
||
2191 |
int w = box->width(); |
|
2192 |
int h = box->height(); |
|
2193 |
||
2194 |
DashboardRegionValue region; |
|
2195 |
region.label = styleRegion.label; |
|
2196 |
region.bounds = IntRect(styleRegion.offset.left().value(), |
|
2197 |
styleRegion.offset.top().value(), |
|
2198 |
w - styleRegion.offset.left().value() - styleRegion.offset.right().value(), |
|
2199 |
h - styleRegion.offset.top().value() - styleRegion.offset.bottom().value()); |
|
2200 |
region.type = styleRegion.type; |
|
2201 |
||
2202 |
region.clip = region.bounds; |
|
2203 |
computeAbsoluteRepaintRect(region.clip); |
|
2204 |
if (region.clip.height() < 0) { |
|
2205 |
region.clip.setHeight(0); |
|
2206 |
region.clip.setWidth(0); |
|
2207 |
} |
|
2208 |
||
2209 |
FloatPoint absPos = localToAbsolute(); |
|
2210 |
region.bounds.setX(absPos.x() + styleRegion.offset.left().value()); |
|
2211 |
region.bounds.setY(absPos.y() + styleRegion.offset.top().value()); |
|
2212 |
||
2213 |
if (document()->frame()) { |
|
2214 |
float pageScaleFactor = document()->frame()->page()->chrome()->scaleFactor(); |
|
2215 |
if (pageScaleFactor != 1.0f) { |
|
2216 |
region.bounds.scale(pageScaleFactor); |
|
2217 |
region.clip.scale(pageScaleFactor); |
|
2218 |
} |
|
2219 |
} |
|
2220 |
||
2221 |
regions.append(region); |
|
2222 |
} |
|
2223 |
} |
|
2224 |
||
2225 |
void RenderObject::collectDashboardRegions(Vector<DashboardRegionValue>& regions) |
|
2226 |
{ |
|
2227 |
// RenderTexts don't have their own style, they just use their parent's style, |
|
2228 |
// so we don't want to include them. |
|
2229 |
if (isText()) |
|
2230 |
return; |
|
2231 |
||
2232 |
addDashboardRegions(regions); |
|
2233 |
for (RenderObject* curr = firstChild(); curr; curr = curr->nextSibling()) |
|
2234 |
curr->collectDashboardRegions(regions); |
|
2235 |
} |
|
2236 |
#endif |
|
2237 |
||
2238 |
bool RenderObject::willRenderImage(CachedImage*) |
|
2239 |
{ |
|
2240 |
// Without visibility we won't render (and therefore don't care about animation). |
|
2241 |
if (style()->visibility() != VISIBLE) |
|
2242 |
return false; |
|
2243 |
||
2244 |
// If we're not in a window (i.e., we're dormant from being put in the b/f cache or in a background tab) |
|
2245 |
// then we don't want to render either. |
|
2246 |
return !document()->inPageCache() && !document()->view()->isOffscreen(); |
|
2247 |
} |
|
2248 |
||
2249 |
int RenderObject::maximalOutlineSize(PaintPhase p) const |
|
2250 |
{ |
|
2251 |
if (p != PaintPhaseOutline && p != PaintPhaseSelfOutline && p != PaintPhaseChildOutlines) |
|
2252 |
return 0; |
|
2253 |
return toRenderView(document()->renderer())->maximalOutlineSize(); |
|
2254 |
} |
|
2255 |
||
2256 |
int RenderObject::caretMinOffset() const |
|
2257 |
{ |
|
2258 |
return 0; |
|
2259 |
} |
|
2260 |
||
2261 |
int RenderObject::caretMaxOffset() const |
|
2262 |
{ |
|
2263 |
if (isReplaced()) |
|
2264 |
return node() ? max(1U, node()->childNodeCount()) : 1; |
|
2265 |
if (isHR()) |
|
2266 |
return 1; |
|
2267 |
return 0; |
|
2268 |
} |
|
2269 |
||
2270 |
unsigned RenderObject::caretMaxRenderedOffset() const |
|
2271 |
{ |
|
2272 |
return 0; |
|
2273 |
} |
|
2274 |
||
2275 |
int RenderObject::previousOffset(int current) const |
|
2276 |
{ |
|
2277 |
return current - 1; |
|
2278 |
} |
|
2279 |
||
2280 |
int RenderObject::previousOffsetForBackwardDeletion(int current) const |
|
2281 |
{ |
|
2282 |
return current - 1; |
|
2283 |
} |
|
2284 |
||
2285 |
int RenderObject::nextOffset(int current) const |
|
2286 |
{ |
|
2287 |
return current + 1; |
|
2288 |
} |
|
2289 |
||
2290 |
void RenderObject::adjustRectForOutlineAndShadow(IntRect& rect) const |
|
2291 |
{ |
|
2292 |
int outlineSize = outlineStyleForRepaint()->outlineSize(); |
|
2293 |
if (ShadowData* boxShadow = style()->boxShadow()) { |
|
2294 |
int shadowLeft = 0; |
|
2295 |
int shadowRight = 0; |
|
2296 |
int shadowTop = 0; |
|
2297 |
int shadowBottom = 0; |
|
2298 |
||
2299 |
do { |
|
2300 |
if (boxShadow->style == Normal) { |
|
2301 |
shadowLeft = min(boxShadow->x - boxShadow->blur - boxShadow->spread - outlineSize, shadowLeft); |
|
2302 |
shadowRight = max(boxShadow->x + boxShadow->blur + boxShadow->spread + outlineSize, shadowRight); |
|
2303 |
shadowTop = min(boxShadow->y - boxShadow->blur - boxShadow->spread - outlineSize, shadowTop); |
|
2304 |
shadowBottom = max(boxShadow->y + boxShadow->blur + boxShadow->spread + outlineSize, shadowBottom); |
|
2305 |
} |
|
2306 |
||
2307 |
boxShadow = boxShadow->next; |
|
2308 |
} while (boxShadow); |
|
2309 |
||
2310 |
rect.move(shadowLeft, shadowTop); |
|
2311 |
rect.setWidth(rect.width() - shadowLeft + shadowRight); |
|
2312 |
rect.setHeight(rect.height() - shadowTop + shadowBottom); |
|
2313 |
} else |
|
2314 |
rect.inflate(outlineSize); |
|
2315 |
} |
|
2316 |
||
2317 |
AnimationController* RenderObject::animation() const |
|
2318 |
{ |
|
2319 |
return document()->frame()->animation(); |
|
2320 |
} |
|
2321 |
||
2322 |
void RenderObject::imageChanged(CachedImage* image, const IntRect* rect) |
|
2323 |
{ |
|
2324 |
imageChanged(static_cast<WrappedImagePtr>(image), rect); |
|
2325 |
} |
|
2326 |
||
2327 |
RenderBoxModelObject* RenderObject::offsetParent() const |
|
2328 |
{ |
|
2329 |
// If any of the following holds true return null and stop this algorithm: |
|
2330 |
// A is the root element. |
|
2331 |
// A is the HTML body element. |
|
2332 |
// The computed value of the position property for element A is fixed. |
|
2333 |
if (isRoot() || isBody() || (isPositioned() && style()->position() == FixedPosition)) |
|
2334 |
return 0; |
|
2335 |
||
2336 |
// If A is an area HTML element which has a map HTML element somewhere in the ancestor |
|
2337 |
// chain return the nearest ancestor map HTML element and stop this algorithm. |
|
2338 |
// FIXME: Implement! |
|
2339 |
||
2340 |
// Return the nearest ancestor element of A for which at least one of the following is |
|
2341 |
// true and stop this algorithm if such an ancestor is found: |
|
2342 |
// * The computed value of the position property is not static. |
|
2343 |
// * It is the HTML body element. |
|
2344 |
// * The computed value of the position property of A is static and the ancestor |
|
2345 |
// is one of the following HTML elements: td, th, or table. |
|
2346 |
// * Our own extension: if there is a difference in the effective zoom |
|
2347 |
bool skipTables = isPositioned() || isRelPositioned(); |
|
2348 |
float currZoom = style()->effectiveZoom(); |
|
2349 |
RenderObject* curr = parent(); |
|
2350 |
while (curr && (!curr->node() || |
|
2351 |
(!curr->isPositioned() && !curr->isRelPositioned() && !curr->isBody()))) { |
|
2352 |
Node* element = curr->node(); |
|
2353 |
if (!skipTables && element) { |
|
2354 |
bool isTableElement = element->hasTagName(tableTag) || |
|
2355 |
element->hasTagName(tdTag) || |
|
2356 |
element->hasTagName(thTag); |
|
2357 |
||
2358 |
#if ENABLE(WML) |
|
2359 |
if (!isTableElement && element->isWMLElement()) |
|
2360 |
isTableElement = element->hasTagName(WMLNames::tableTag) || |
|
2361 |
element->hasTagName(WMLNames::tdTag); |
|
2362 |
#endif |
|
2363 |
||
2364 |
if (isTableElement) |
|
2365 |
break; |
|
2366 |
} |
|
2367 |
||
2368 |
float newZoom = curr->style()->effectiveZoom(); |
|
2369 |
if (currZoom != newZoom) |
|
2370 |
break; |
|
2371 |
currZoom = newZoom; |
|
2372 |
curr = curr->parent(); |
|
2373 |
} |
|
2374 |
return curr && curr->isBoxModelObject() ? toRenderBoxModelObject(curr) : 0; |
|
2375 |
} |
|
2376 |
||
2377 |
VisiblePosition RenderObject::createVisiblePosition(int offset, EAffinity affinity) |
|
2378 |
{ |
|
2379 |
// If this is a non-anonymous renderer, then it's simple. |
|
2380 |
if (Node* node = this->node()) |
|
2381 |
return VisiblePosition(node, offset, affinity); |
|
2382 |
||
2383 |
// We don't want to cross the boundary between editable and non-editable |
|
2384 |
// regions of the document, but that is either impossible or at least |
|
2385 |
// extremely unlikely in any normal case because we stop as soon as we |
|
2386 |
// find a single non-anonymous renderer. |
|
2387 |
||
2388 |
// Find a nearby non-anonymous renderer. |
|
2389 |
RenderObject* child = this; |
|
2390 |
while (RenderObject* parent = child->parent()) { |
|
2391 |
// Find non-anonymous content after. |
|
2392 |
RenderObject* renderer = child; |
|
2393 |
while ((renderer = renderer->nextInPreOrder(parent))) { |
|
2394 |
if (Node* node = renderer->node()) |
|
2395 |
return VisiblePosition(node, 0, DOWNSTREAM); |
|
2396 |
} |
|
2397 |
||
2398 |
// Find non-anonymous content before. |
|
2399 |
renderer = child; |
|
2400 |
while ((renderer = renderer->previousInPreOrder())) { |
|
2401 |
if (renderer == parent) |
|
2402 |
break; |
|
2403 |
if (Node* node = renderer->node()) |
|
2404 |
return VisiblePosition(lastDeepEditingPositionForNode(node), DOWNSTREAM); |
|
2405 |
} |
|
2406 |
||
2407 |
// Use the parent itself unless it too is anonymous. |
|
2408 |
if (Node* node = parent->node()) |
|
2409 |
return VisiblePosition(node, 0, DOWNSTREAM); |
|
2410 |
||
2411 |
// Repeat at the next level up. |
|
2412 |
child = parent; |
|
2413 |
} |
|
2414 |
||
2415 |
// Everything was anonymous. Give up. |
|
2416 |
return VisiblePosition(); |
|
2417 |
} |
|
2418 |
||
2419 |
VisiblePosition RenderObject::createVisiblePosition(const Position& position) |
|
2420 |
{ |
|
2421 |
if (position.isNotNull()) |
|
2422 |
return VisiblePosition(position); |
|
2423 |
||
2424 |
ASSERT(!node()); |
|
2425 |
return createVisiblePosition(0, DOWNSTREAM); |
|
2426 |
} |
|
2427 |
||
2428 |
#if ENABLE(SVG) |
|
2429 |
||
2430 |
FloatRect RenderObject::objectBoundingBox() const |
|
2431 |
{ |
|
2432 |
ASSERT_NOT_REACHED(); |
|
2433 |
return FloatRect(); |
|
2434 |
} |
|
2435 |
||
2436 |
// Returns the smallest rectangle enclosing all of the painted content |
|
2437 |
// respecting clipping, masking, filters, opacity, stroke-width and markers |
|
2438 |
FloatRect RenderObject::repaintRectInLocalCoordinates() const |
|
2439 |
{ |
|
2440 |
ASSERT_NOT_REACHED(); |
|
2441 |
return FloatRect(); |
|
2442 |
} |
|
2443 |
||
2444 |
TransformationMatrix RenderObject::localTransform() const |
|
2445 |
{ |
|
2446 |
return TransformationMatrix(); |
|
2447 |
} |
|
2448 |
||
2449 |
TransformationMatrix RenderObject::localToParentTransform() const |
|
2450 |
{ |
|
2451 |
// FIXME: This double virtual call indirection is temporary until I can land the |
|
2452 |
// rest of the of the localToParentTransform() support for SVG. |
|
2453 |
return localTransform(); |
|
2454 |
} |
|
2455 |
||
2456 |
TransformationMatrix RenderObject::absoluteTransform() const |
|
2457 |
{ |
|
2458 |
// FIXME: This should use localToParentTransform(), but much of the SVG code |
|
2459 |
// depends on RenderBox::absoluteTransform() being the sum of the localTransform()s of all parent renderers. |
|
2460 |
if (parent()) |
|
2461 |
return localTransform() * parent()->absoluteTransform(); |
|
2462 |
return localTransform(); |
|
2463 |
} |
|
2464 |
||
2465 |
bool RenderObject::nodeAtFloatPoint(const HitTestRequest&, HitTestResult&, const FloatPoint&, HitTestAction) |
|
2466 |
{ |
|
2467 |
ASSERT_NOT_REACHED(); |
|
2468 |
return false; |
|
2469 |
} |
|
2470 |
||
2471 |
#endif // ENABLE(SVG) |
|
2472 |
||
2473 |
} // namespace WebCore |
|
2474 |
||
2475 |
#ifndef NDEBUG |
|
2476 |
||
2477 |
void showTree(const WebCore::RenderObject* ro) |
|
2478 |
{ |
|
2479 |
if (ro) |
|
2480 |
ro->showTreeForThis(); |
|
2481 |
} |
|
2482 |
||
2483 |
#endif |