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, 2011, 2013 Apple Inc. All rights reserved. |
7 | * Copyright (C) 2009 Google Inc. All rights reserved. |
8 | * Copyright (C) 2009 Torch Mobile Inc. All rights reserved. (http://www.torchmobile.com/) |
9 | * |
10 | * This library is free software; you can redistribute it and/or |
11 | * modify it under the terms of the GNU Library General Public |
12 | * License as published by the Free Software Foundation; either |
13 | * version 2 of the License, or (at your option) any later version. |
14 | * |
15 | * This library is distributed in the hope that it will be useful, |
16 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
17 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
18 | * Library General Public License for more details. |
19 | * |
20 | * You should have received a copy of the GNU Library General Public License |
21 | * along with this library; see the file COPYING.LIB. If not, write to |
22 | * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, |
23 | * Boston, MA 02110-1301, USA. |
24 | * |
25 | */ |
26 | |
27 | #include "config.h" |
28 | #include "RenderObject.h" |
29 | |
30 | #include "AXObjectCache.h" |
31 | #include "CSSAnimationController.h" |
32 | #include "Editing.h" |
33 | #include "FloatQuad.h" |
34 | #include "Frame.h" |
35 | #include "FrameSelection.h" |
36 | #include "FrameView.h" |
37 | #include "GeometryUtilities.h" |
38 | #include "GraphicsContext.h" |
39 | #include "HTMLElement.h" |
40 | #include "HTMLNames.h" |
41 | #include "HTMLTableCellElement.h" |
42 | #include "HTMLTableElement.h" |
43 | #include "HitTestResult.h" |
44 | #include "LogicalSelectionOffsetCaches.h" |
45 | #include "Page.h" |
46 | #include "PseudoElement.h" |
47 | #include "RenderChildIterator.h" |
48 | #include "RenderCounter.h" |
49 | #include "RenderFragmentedFlow.h" |
50 | #include "RenderGeometryMap.h" |
51 | #include "RenderInline.h" |
52 | #include "RenderIterator.h" |
53 | #include "RenderLayer.h" |
54 | #include "RenderLayerBacking.h" |
55 | #include "RenderLayerCompositor.h" |
56 | #include "RenderMultiColumnFlow.h" |
57 | #include "RenderRuby.h" |
58 | #include "RenderSVGBlock.h" |
59 | #include "RenderSVGInline.h" |
60 | #include "RenderSVGModelObject.h" |
61 | #include "RenderSVGResourceContainer.h" |
62 | #include "RenderSVGRoot.h" |
63 | #include "RenderScrollbarPart.h" |
64 | #include "RenderTableRow.h" |
65 | #include "RenderTheme.h" |
66 | #include "RenderTreeBuilder.h" |
67 | #include "RenderView.h" |
68 | #include "RenderWidget.h" |
69 | #include "SVGRenderSupport.h" |
70 | #include "StyleResolver.h" |
71 | #include "TransformState.h" |
72 | #include <algorithm> |
73 | #include <stdio.h> |
74 | #include <wtf/IsoMallocInlines.h> |
75 | #include <wtf/RefCountedLeakCounter.h> |
76 | #include <wtf/text/TextStream.h> |
77 | |
78 | #if PLATFORM(IOS_FAMILY) |
79 | #include "SelectionRect.h" |
80 | #endif |
81 | |
82 | namespace WebCore { |
83 | |
84 | using namespace HTMLNames; |
85 | |
86 | WTF_MAKE_ISO_ALLOCATED_IMPL(RenderObject); |
87 | |
88 | #ifndef NDEBUG |
89 | |
90 | RenderObject::SetLayoutNeededForbiddenScope::SetLayoutNeededForbiddenScope(RenderObject* renderObject, bool isForbidden) |
91 | : m_renderObject(renderObject) |
92 | , m_preexistingForbidden(m_renderObject->isSetNeedsLayoutForbidden()) |
93 | { |
94 | m_renderObject->setNeedsLayoutIsForbidden(isForbidden); |
95 | } |
96 | |
97 | RenderObject::SetLayoutNeededForbiddenScope::~SetLayoutNeededForbiddenScope() |
98 | { |
99 | m_renderObject->setNeedsLayoutIsForbidden(m_preexistingForbidden); |
100 | } |
101 | #endif |
102 | |
103 | struct SameSizeAsRenderObject { |
104 | virtual ~SameSizeAsRenderObject() = default; // Allocate vtable pointer. |
105 | void* pointers[5]; |
106 | #ifndef NDEBUG |
107 | unsigned m_debugBitfields : 2; |
108 | #endif |
109 | unsigned m_bitfields; |
110 | }; |
111 | |
112 | COMPILE_ASSERT(sizeof(RenderObject) == sizeof(SameSizeAsRenderObject), RenderObject_should_stay_small); |
113 | |
114 | DEFINE_DEBUG_ONLY_GLOBAL(WTF::RefCountedLeakCounter, renderObjectCounter, ("RenderObject" )); |
115 | |
116 | void RenderObjectDeleter::operator() (RenderObject* renderer) const |
117 | { |
118 | renderer->destroy(); |
119 | } |
120 | |
121 | RenderObject::RenderObject(Node& node) |
122 | : CachedImageClient() |
123 | , m_node(node) |
124 | , m_parent(nullptr) |
125 | , m_previous(nullptr) |
126 | , m_next(nullptr) |
127 | #ifndef NDEBUG |
128 | , m_hasAXObject(false) |
129 | , m_setNeedsLayoutForbidden(false) |
130 | #endif |
131 | , m_bitfields(node) |
132 | { |
133 | if (RenderView* renderView = node.document().renderView()) |
134 | renderView->didCreateRenderer(); |
135 | #ifndef NDEBUG |
136 | renderObjectCounter.increment(); |
137 | #endif |
138 | } |
139 | |
140 | RenderObject::~RenderObject() |
141 | { |
142 | view().didDestroyRenderer(); |
143 | #ifndef NDEBUG |
144 | ASSERT(!m_hasAXObject); |
145 | renderObjectCounter.decrement(); |
146 | #endif |
147 | ASSERT(!hasRareData()); |
148 | } |
149 | |
150 | RenderTheme& RenderObject::theme() const |
151 | { |
152 | return RenderTheme::singleton(); |
153 | } |
154 | |
155 | bool RenderObject::isDescendantOf(const RenderObject* ancestor) const |
156 | { |
157 | for (const RenderObject* renderer = this; renderer; renderer = renderer->m_parent) { |
158 | if (renderer == ancestor) |
159 | return true; |
160 | } |
161 | return false; |
162 | } |
163 | |
164 | bool RenderObject::isLegend() const |
165 | { |
166 | return node() && node()->hasTagName(legendTag); |
167 | } |
168 | |
169 | |
170 | bool RenderObject::isFieldset() const |
171 | { |
172 | return node() && node()->hasTagName(fieldsetTag); |
173 | } |
174 | |
175 | bool RenderObject::isHTMLMarquee() const |
176 | { |
177 | return node() && node()->renderer() == this && node()->hasTagName(marqueeTag); |
178 | } |
179 | |
180 | void RenderObject::setFragmentedFlowStateIncludingDescendants(FragmentedFlowState state) |
181 | { |
182 | setFragmentedFlowState(state); |
183 | |
184 | if (!is<RenderElement>(*this)) |
185 | return; |
186 | |
187 | for (auto& child : childrenOfType<RenderObject>(downcast<RenderElement>(*this))) { |
188 | // If the child is a fragmentation context it already updated the descendants flag accordingly. |
189 | if (child.isRenderFragmentedFlow()) |
190 | continue; |
191 | ASSERT(state != child.fragmentedFlowState()); |
192 | child.setFragmentedFlowStateIncludingDescendants(state); |
193 | } |
194 | } |
195 | |
196 | RenderObject::FragmentedFlowState RenderObject::computedFragmentedFlowState(const RenderObject& renderer) |
197 | { |
198 | if (!renderer.parent()) |
199 | return renderer.fragmentedFlowState(); |
200 | |
201 | if (is<RenderMultiColumnFlow>(renderer)) { |
202 | // Multicolumn flows do not inherit the flow state. |
203 | return InsideInFragmentedFlow; |
204 | } |
205 | |
206 | auto inheritedFlowState = RenderObject::NotInsideFragmentedFlow; |
207 | if (is<RenderText>(renderer)) |
208 | inheritedFlowState = renderer.parent()->fragmentedFlowState(); |
209 | else if (is<RenderSVGBlock>(renderer) || is<RenderSVGInline>(renderer) || is<RenderSVGModelObject>(renderer)) { |
210 | // containingBlock() skips svg boundary (SVG root is a RenderReplaced). |
211 | if (auto* svgRoot = SVGRenderSupport::findTreeRootObject(downcast<RenderElement>(renderer))) |
212 | inheritedFlowState = svgRoot->fragmentedFlowState(); |
213 | } else if (auto* container = renderer.container()) |
214 | inheritedFlowState = container->fragmentedFlowState(); |
215 | else { |
216 | // Splitting lines or doing continuation, so just keep the current state. |
217 | inheritedFlowState = renderer.fragmentedFlowState(); |
218 | } |
219 | return inheritedFlowState; |
220 | } |
221 | |
222 | void RenderObject::initializeFragmentedFlowStateOnInsertion() |
223 | { |
224 | ASSERT(parent()); |
225 | |
226 | // A RenderFragmentedFlow is always considered to be inside itself, so it never has to change its state in response to parent changes. |
227 | if (isRenderFragmentedFlow()) |
228 | return; |
229 | |
230 | auto computedState = computedFragmentedFlowState(*this); |
231 | if (fragmentedFlowState() == computedState) |
232 | return; |
233 | |
234 | setFragmentedFlowStateIncludingDescendants(computedState); |
235 | } |
236 | |
237 | void RenderObject::resetFragmentedFlowStateOnRemoval() |
238 | { |
239 | if (fragmentedFlowState() == NotInsideFragmentedFlow) |
240 | return; |
241 | |
242 | if (!renderTreeBeingDestroyed() && is<RenderElement>(*this)) { |
243 | downcast<RenderElement>(*this).removeFromRenderFragmentedFlow(); |
244 | return; |
245 | } |
246 | |
247 | // A RenderFragmentedFlow is always considered to be inside itself, so it never has to change its state in response to parent changes. |
248 | if (isRenderFragmentedFlow()) |
249 | return; |
250 | |
251 | setFragmentedFlowStateIncludingDescendants(NotInsideFragmentedFlow); |
252 | } |
253 | |
254 | void RenderObject::setParent(RenderElement* parent) |
255 | { |
256 | m_parent = parent; |
257 | } |
258 | |
259 | RenderObject* RenderObject::nextInPreOrder() const |
260 | { |
261 | if (RenderObject* o = firstChildSlow()) |
262 | return o; |
263 | |
264 | return nextInPreOrderAfterChildren(); |
265 | } |
266 | |
267 | RenderObject* RenderObject::nextInPreOrderAfterChildren() const |
268 | { |
269 | RenderObject* o; |
270 | if (!(o = nextSibling())) { |
271 | o = parent(); |
272 | while (o && !o->nextSibling()) |
273 | o = o->parent(); |
274 | if (o) |
275 | o = o->nextSibling(); |
276 | } |
277 | |
278 | return o; |
279 | } |
280 | |
281 | RenderObject* RenderObject::nextInPreOrder(const RenderObject* stayWithin) const |
282 | { |
283 | if (RenderObject* o = firstChildSlow()) |
284 | return o; |
285 | |
286 | return nextInPreOrderAfterChildren(stayWithin); |
287 | } |
288 | |
289 | RenderObject* RenderObject::nextInPreOrderAfterChildren(const RenderObject* stayWithin) const |
290 | { |
291 | if (this == stayWithin) |
292 | return nullptr; |
293 | |
294 | const RenderObject* current = this; |
295 | RenderObject* next; |
296 | while (!(next = current->nextSibling())) { |
297 | current = current->parent(); |
298 | if (!current || current == stayWithin) |
299 | return nullptr; |
300 | } |
301 | return next; |
302 | } |
303 | |
304 | RenderObject* RenderObject::previousInPreOrder() const |
305 | { |
306 | if (RenderObject* o = previousSibling()) { |
307 | while (RenderObject* last = o->lastChildSlow()) |
308 | o = last; |
309 | return o; |
310 | } |
311 | |
312 | return parent(); |
313 | } |
314 | |
315 | RenderObject* RenderObject::previousInPreOrder(const RenderObject* stayWithin) const |
316 | { |
317 | if (this == stayWithin) |
318 | return nullptr; |
319 | |
320 | return previousInPreOrder(); |
321 | } |
322 | |
323 | RenderObject* RenderObject::childAt(unsigned index) const |
324 | { |
325 | RenderObject* child = firstChildSlow(); |
326 | for (unsigned i = 0; child && i < index; i++) |
327 | child = child->nextSibling(); |
328 | return child; |
329 | } |
330 | |
331 | RenderObject* RenderObject::firstLeafChild() const |
332 | { |
333 | RenderObject* r = firstChildSlow(); |
334 | while (r) { |
335 | RenderObject* n = nullptr; |
336 | n = r->firstChildSlow(); |
337 | if (!n) |
338 | break; |
339 | r = n; |
340 | } |
341 | return r; |
342 | } |
343 | |
344 | RenderObject* RenderObject::lastLeafChild() const |
345 | { |
346 | RenderObject* r = lastChildSlow(); |
347 | while (r) { |
348 | RenderObject* n = nullptr; |
349 | n = r->lastChildSlow(); |
350 | if (!n) |
351 | break; |
352 | r = n; |
353 | } |
354 | return r; |
355 | } |
356 | |
357 | #if ENABLE(TEXT_AUTOSIZING) |
358 | |
359 | // Non-recursive version of the DFS search. |
360 | RenderObject* RenderObject::traverseNext(const RenderObject* stayWithin, HeightTypeTraverseNextInclusionFunction inclusionFunction, int& currentDepth, int& newFixedDepth) const |
361 | { |
362 | BlockContentHeightType overflowType; |
363 | |
364 | // Check for suitable children. |
365 | for (RenderObject* child = firstChildSlow(); child; child = child->nextSibling()) { |
366 | overflowType = inclusionFunction(*child); |
367 | if (overflowType != FixedHeight) { |
368 | currentDepth++; |
369 | if (overflowType == OverflowHeight) |
370 | newFixedDepth = currentDepth; |
371 | ASSERT(!stayWithin || child->isDescendantOf(stayWithin)); |
372 | return child; |
373 | } |
374 | } |
375 | |
376 | if (this == stayWithin) |
377 | return nullptr; |
378 | |
379 | // Now we traverse other nodes if they exist, otherwise |
380 | // we go to the parent node and try doing the same. |
381 | const RenderObject* n = this; |
382 | while (n) { |
383 | while (n && !n->nextSibling() && (!stayWithin || n->parent() != stayWithin)) { |
384 | n = n->parent(); |
385 | currentDepth--; |
386 | } |
387 | if (!n) |
388 | return nullptr; |
389 | for (RenderObject* sibling = n->nextSibling(); sibling; sibling = sibling->nextSibling()) { |
390 | overflowType = inclusionFunction(*sibling); |
391 | if (overflowType != FixedHeight) { |
392 | if (overflowType == OverflowHeight) |
393 | newFixedDepth = currentDepth; |
394 | ASSERT(!stayWithin || !n->nextSibling() || n->nextSibling()->isDescendantOf(stayWithin)); |
395 | return sibling; |
396 | } |
397 | } |
398 | if (!stayWithin || n->parent() != stayWithin) { |
399 | n = n->parent(); |
400 | currentDepth--; |
401 | } else |
402 | return nullptr; |
403 | } |
404 | return nullptr; |
405 | } |
406 | |
407 | #endif // ENABLE(TEXT_AUTOSIZING) |
408 | |
409 | RenderLayer* RenderObject::enclosingLayer() const |
410 | { |
411 | for (auto& renderer : lineageOfType<RenderLayerModelObject>(*this)) { |
412 | if (renderer.hasLayer()) |
413 | return renderer.layer(); |
414 | } |
415 | return nullptr; |
416 | } |
417 | |
418 | bool RenderObject::scrollRectToVisible(const LayoutRect& absoluteRect, bool insideFixed, const ScrollRectToVisibleOptions& options) |
419 | { |
420 | if (options.revealMode == SelectionRevealMode::DoNotReveal) |
421 | return false; |
422 | |
423 | RenderLayer* enclosingLayer = this->enclosingLayer(); |
424 | if (!enclosingLayer) |
425 | return false; |
426 | |
427 | enclosingLayer->scrollRectToVisible(absoluteRect, insideFixed, options); |
428 | return true; |
429 | } |
430 | |
431 | RenderBox& RenderObject::enclosingBox() const |
432 | { |
433 | return *lineageOfType<RenderBox>(const_cast<RenderObject&>(*this)).first(); |
434 | } |
435 | |
436 | RenderBoxModelObject& RenderObject::enclosingBoxModelObject() const |
437 | { |
438 | return *lineageOfType<RenderBoxModelObject>(const_cast<RenderObject&>(*this)).first(); |
439 | } |
440 | |
441 | const RenderBox* RenderObject::enclosingScrollableContainerForSnapping() const |
442 | { |
443 | auto& renderBox = enclosingBox(); |
444 | if (auto* scrollableContainer = renderBox.findEnclosingScrollableContainer()) { |
445 | // The scrollable container for snapping cannot be the node itself. |
446 | if (scrollableContainer != this) |
447 | return scrollableContainer; |
448 | if (renderBox.parentBox()) |
449 | return renderBox.parentBox()->findEnclosingScrollableContainer(); |
450 | } |
451 | return nullptr; |
452 | } |
453 | |
454 | RenderBlock* RenderObject::firstLineBlock() const |
455 | { |
456 | return nullptr; |
457 | } |
458 | |
459 | static inline bool objectIsRelayoutBoundary(const RenderElement* object) |
460 | { |
461 | // FIXME: In future it may be possible to broaden these conditions in order to improve performance. |
462 | if (object->isRenderView()) |
463 | return true; |
464 | |
465 | if (object->isTextControl()) |
466 | return true; |
467 | |
468 | if (object->isSVGRoot()) |
469 | return true; |
470 | |
471 | if (!object->hasOverflowClip()) |
472 | return false; |
473 | |
474 | if (object->style().width().isIntrinsicOrAuto() || object->style().height().isIntrinsicOrAuto() || object->style().height().isPercentOrCalculated()) |
475 | return false; |
476 | |
477 | // Table parts can't be relayout roots since the table is responsible for layouting all the parts. |
478 | if (object->isTablePart()) |
479 | return false; |
480 | |
481 | return true; |
482 | } |
483 | |
484 | void RenderObject::clearNeedsLayout() |
485 | { |
486 | m_bitfields.setNeedsLayout(false); |
487 | setEverHadLayout(true); |
488 | setPosChildNeedsLayoutBit(false); |
489 | setNeedsSimplifiedNormalFlowLayoutBit(false); |
490 | setNormalChildNeedsLayoutBit(false); |
491 | setNeedsPositionedMovementLayoutBit(false); |
492 | if (is<RenderElement>(*this)) |
493 | downcast<RenderElement>(*this).setAncestorLineBoxDirty(false); |
494 | #ifndef NDEBUG |
495 | checkBlockPositionedObjectsNeedLayout(); |
496 | #endif |
497 | } |
498 | |
499 | static void scheduleRelayoutForSubtree(RenderElement& renderer) |
500 | { |
501 | if (is<RenderView>(renderer)) { |
502 | downcast<RenderView>(renderer).frameView().layoutContext().scheduleLayout(); |
503 | return; |
504 | } |
505 | |
506 | if (renderer.isRooted()) |
507 | renderer.view().frameView().layoutContext().scheduleSubtreeLayout(renderer); |
508 | } |
509 | |
510 | void RenderObject::markContainingBlocksForLayout(ScheduleRelayout scheduleRelayout, RenderElement* newRoot) |
511 | { |
512 | ASSERT(scheduleRelayout == ScheduleRelayout::No || !newRoot); |
513 | ASSERT(!isSetNeedsLayoutForbidden()); |
514 | |
515 | auto ancestor = container(); |
516 | |
517 | bool simplifiedNormalFlowLayout = needsSimplifiedNormalFlowLayout() && !selfNeedsLayout() && !normalChildNeedsLayout(); |
518 | bool hasOutOfFlowPosition = !isText() && style().hasOutOfFlowPosition(); |
519 | |
520 | while (ancestor) { |
521 | #ifndef NDEBUG |
522 | // FIXME: Remove this once we remove the special cases for counters, quotes and mathml |
523 | // calling setNeedsLayout during preferred width computation. |
524 | SetLayoutNeededForbiddenScope layoutForbiddenScope(ancestor, isSetNeedsLayoutForbidden()); |
525 | #endif |
526 | // Don't mark the outermost object of an unrooted subtree. That object will be |
527 | // marked when the subtree is added to the document. |
528 | auto container = ancestor->container(); |
529 | if (!container && !ancestor->isRenderView()) |
530 | return; |
531 | if (hasOutOfFlowPosition) { |
532 | bool willSkipRelativelyPositionedInlines = !ancestor->isRenderBlock() || ancestor->isAnonymousBlock(); |
533 | // Skip relatively positioned inlines and anonymous blocks to get to the enclosing RenderBlock. |
534 | while (ancestor && (!ancestor->isRenderBlock() || ancestor->isAnonymousBlock())) |
535 | ancestor = ancestor->container(); |
536 | if (!ancestor || ancestor->posChildNeedsLayout()) |
537 | return; |
538 | if (willSkipRelativelyPositionedInlines) |
539 | container = ancestor->container(); |
540 | ancestor->setPosChildNeedsLayoutBit(true); |
541 | simplifiedNormalFlowLayout = true; |
542 | } else if (simplifiedNormalFlowLayout) { |
543 | if (ancestor->needsSimplifiedNormalFlowLayout()) |
544 | return; |
545 | ancestor->setNeedsSimplifiedNormalFlowLayoutBit(true); |
546 | } else { |
547 | if (ancestor->normalChildNeedsLayout()) |
548 | return; |
549 | ancestor->setNormalChildNeedsLayoutBit(true); |
550 | } |
551 | ASSERT(!ancestor->isSetNeedsLayoutForbidden()); |
552 | |
553 | if (ancestor == newRoot) |
554 | return; |
555 | |
556 | if (scheduleRelayout == ScheduleRelayout::Yes && objectIsRelayoutBoundary(ancestor)) |
557 | break; |
558 | |
559 | hasOutOfFlowPosition = ancestor->style().hasOutOfFlowPosition(); |
560 | ancestor = container; |
561 | } |
562 | |
563 | if (scheduleRelayout == ScheduleRelayout::Yes && ancestor) |
564 | scheduleRelayoutForSubtree(*ancestor); |
565 | } |
566 | |
567 | #ifndef NDEBUG |
568 | void RenderObject::checkBlockPositionedObjectsNeedLayout() |
569 | { |
570 | ASSERT(!needsLayout()); |
571 | |
572 | if (is<RenderBlock>(*this)) |
573 | downcast<RenderBlock>(*this).checkPositionedObjectsNeedLayout(); |
574 | } |
575 | #endif |
576 | |
577 | void RenderObject::setPreferredLogicalWidthsDirty(bool shouldBeDirty, MarkingBehavior markParents) |
578 | { |
579 | bool alreadyDirty = preferredLogicalWidthsDirty(); |
580 | m_bitfields.setPreferredLogicalWidthsDirty(shouldBeDirty); |
581 | if (shouldBeDirty && !alreadyDirty && markParents == MarkContainingBlockChain && (isText() || !style().hasOutOfFlowPosition())) |
582 | invalidateContainerPreferredLogicalWidths(); |
583 | } |
584 | |
585 | void RenderObject::invalidateContainerPreferredLogicalWidths() |
586 | { |
587 | // In order to avoid pathological behavior when inlines are deeply nested, we do include them |
588 | // in the chain that we mark dirty (even though they're kind of irrelevant). |
589 | auto o = isTableCell() ? containingBlock() : container(); |
590 | while (o && !o->preferredLogicalWidthsDirty()) { |
591 | // Don't invalidate the outermost object of an unrooted subtree. That object will be |
592 | // invalidated when the subtree is added to the document. |
593 | auto container = o->isTableCell() ? o->containingBlock() : o->container(); |
594 | if (!container && !o->isRenderView()) |
595 | break; |
596 | |
597 | o->m_bitfields.setPreferredLogicalWidthsDirty(true); |
598 | if (o->style().hasOutOfFlowPosition()) |
599 | // A positioned object has no effect on the min/max width of its containing block ever. |
600 | // We can optimize this case and not go up any further. |
601 | break; |
602 | o = container; |
603 | } |
604 | } |
605 | |
606 | void RenderObject::setLayerNeedsFullRepaint() |
607 | { |
608 | ASSERT(hasLayer()); |
609 | downcast<RenderLayerModelObject>(*this).layer()->setRepaintStatus(NeedsFullRepaint); |
610 | } |
611 | |
612 | void RenderObject::setLayerNeedsFullRepaintForPositionedMovementLayout() |
613 | { |
614 | ASSERT(hasLayer()); |
615 | downcast<RenderLayerModelObject>(*this).layer()->setRepaintStatus(NeedsFullRepaintForPositionedMovementLayout); |
616 | } |
617 | |
618 | RenderBlock* RenderObject::containingBlock() const |
619 | { |
620 | auto containingBlockForRenderer = [](const RenderElement& renderer) |
621 | { |
622 | if (renderer.isAbsolutelyPositioned()) |
623 | return renderer.containingBlockForAbsolutePosition(); |
624 | if (renderer.isFixedPositioned()) |
625 | return renderer.containingBlockForFixedPosition(); |
626 | return renderer.containingBlockForObjectInFlow(); |
627 | }; |
628 | |
629 | if (is<RenderText>(*this)) |
630 | return containingBlockForObjectInFlow(); |
631 | |
632 | if (!parent() && is<RenderScrollbarPart>(*this)) { |
633 | if (auto* scrollbarPart = downcast<RenderScrollbarPart>(*this).rendererOwningScrollbar()) |
634 | return containingBlockForRenderer(*scrollbarPart); |
635 | return nullptr; |
636 | } |
637 | return containingBlockForRenderer(downcast<RenderElement>(*this)); |
638 | } |
639 | |
640 | RenderBlock* RenderObject::containingBlockForObjectInFlow() const |
641 | { |
642 | auto* renderer = parent(); |
643 | while (renderer && ((renderer->isInline() && !renderer->isReplaced()) || !renderer->isRenderBlock())) |
644 | renderer = renderer->parent(); |
645 | return downcast<RenderBlock>(renderer); |
646 | } |
647 | |
648 | void RenderObject::addPDFURLRect(PaintInfo& paintInfo, const LayoutPoint& paintOffset) |
649 | { |
650 | Vector<LayoutRect> focusRingRects; |
651 | addFocusRingRects(focusRingRects, paintOffset, paintInfo.paintContainer); |
652 | LayoutRect urlRect = unionRect(focusRingRects); |
653 | |
654 | if (urlRect.isEmpty()) |
655 | return; |
656 | Node* node = this->node(); |
657 | if (!is<Element>(node) || !node->isLink()) |
658 | return; |
659 | Element& element = downcast<Element>(*node); |
660 | const AtomicString& href = element.getAttribute(hrefAttr); |
661 | if (href.isNull()) |
662 | return; |
663 | |
664 | if (paintInfo.context().supportsInternalLinks()) { |
665 | String outAnchorName; |
666 | Element* linkTarget = element.findAnchorElementForLink(outAnchorName); |
667 | if (linkTarget) { |
668 | paintInfo.context().setDestinationForRect(outAnchorName, urlRect); |
669 | return; |
670 | } |
671 | } |
672 | |
673 | paintInfo.context().setURLForRect(node->document().completeURL(href), urlRect); |
674 | |
675 | } |
676 | |
677 | #if PLATFORM(IOS_FAMILY) |
678 | // This function is similar in spirit to RenderText::absoluteRectsForRange, but returns rectangles |
679 | // which are annotated with additional state which helps iOS draw selections in its unique way. |
680 | // No annotations are added in this class. |
681 | // FIXME: Move to RenderText with absoluteRectsForRange()? |
682 | void RenderObject::collectSelectionRects(Vector<SelectionRect>& rects, unsigned start, unsigned end) |
683 | { |
684 | Vector<FloatQuad> quads; |
685 | |
686 | if (!firstChildSlow()) { |
687 | // FIXME: WebKit's position for an empty span after a BR is incorrect, so we can't trust |
688 | // quads for them. We don't need selection rects for those anyway though, since they |
689 | // are just empty containers. See <https://bugs.webkit.org/show_bug.cgi?id=49358>. |
690 | RenderObject* previous = previousSibling(); |
691 | Node* node = this->node(); |
692 | if (!previous || !previous->isBR() || !node || !node->isContainerNode() || !isInline()) { |
693 | // For inline elements we don't use absoluteQuads, since it takes into account continuations and leads to wrong results. |
694 | absoluteQuadsForSelection(quads); |
695 | } |
696 | } else { |
697 | unsigned offset = start; |
698 | for (RenderObject* child = childAt(start); child && offset < end; child = child->nextSibling(), ++offset) |
699 | child->absoluteQuads(quads); |
700 | } |
701 | |
702 | unsigned numberOfQuads = quads.size(); |
703 | for (unsigned i = 0; i < numberOfQuads; ++i) |
704 | rects.append(SelectionRect(quads[i].enclosingBoundingBox(), isHorizontalWritingMode(), view().pageNumberForBlockProgressionOffset(quads[i].enclosingBoundingBox().x()))); |
705 | } |
706 | #endif |
707 | |
708 | IntRect RenderObject::absoluteBoundingBoxRect(bool useTransforms, bool* wasFixed) const |
709 | { |
710 | if (useTransforms) { |
711 | Vector<FloatQuad> quads; |
712 | absoluteQuads(quads, wasFixed); |
713 | |
714 | size_t n = quads.size(); |
715 | if (!n) |
716 | return IntRect(); |
717 | |
718 | IntRect result = quads[0].enclosingBoundingBox(); |
719 | for (size_t i = 1; i < n; ++i) |
720 | result.unite(quads[i].enclosingBoundingBox()); |
721 | return result; |
722 | } |
723 | |
724 | FloatPoint absPos = localToAbsolute(FloatPoint(), 0 /* ignore transforms */, wasFixed); |
725 | Vector<IntRect> rects; |
726 | absoluteRects(rects, flooredLayoutPoint(absPos)); |
727 | |
728 | size_t n = rects.size(); |
729 | if (!n) |
730 | return IntRect(); |
731 | |
732 | LayoutRect result = rects[0]; |
733 | for (size_t i = 1; i < n; ++i) |
734 | result.unite(rects[i]); |
735 | return snappedIntRect(result); |
736 | } |
737 | |
738 | void RenderObject::absoluteFocusRingQuads(Vector<FloatQuad>& quads) |
739 | { |
740 | Vector<LayoutRect> rects; |
741 | // FIXME: addFocusRingRects() needs to be passed this transform-unaware |
742 | // localToAbsolute() offset here because RenderInline::addFocusRingRects() |
743 | // implicitly assumes that. This doesn't work correctly with transformed |
744 | // descendants. |
745 | FloatPoint absolutePoint = localToAbsolute(); |
746 | addFocusRingRects(rects, flooredLayoutPoint(absolutePoint)); |
747 | float deviceScaleFactor = document().deviceScaleFactor(); |
748 | for (auto rect : rects) { |
749 | rect.moveBy(LayoutPoint(-absolutePoint)); |
750 | quads.append(localToAbsoluteQuad(FloatQuad(snapRectToDevicePixels(rect, deviceScaleFactor)))); |
751 | } |
752 | } |
753 | |
754 | FloatRect RenderObject::absoluteBoundingBoxRectForRange(const Range* range) |
755 | { |
756 | if (!range) |
757 | return FloatRect(); |
758 | |
759 | range->ownerDocument().updateLayout(); |
760 | |
761 | Vector<FloatQuad> quads; |
762 | range->absoluteTextQuads(quads); |
763 | |
764 | if (quads.isEmpty()) |
765 | return FloatRect(); |
766 | |
767 | FloatRect result = quads[0].boundingBox(); |
768 | for (size_t i = 1; i < quads.size(); ++i) |
769 | result.uniteEvenIfEmpty(quads[i].boundingBox()); |
770 | |
771 | return result; |
772 | } |
773 | |
774 | void RenderObject::addAbsoluteRectForLayer(LayoutRect& result) |
775 | { |
776 | if (hasLayer()) |
777 | result.unite(absoluteBoundingBoxRectIgnoringTransforms()); |
778 | |
779 | if (!is<RenderElement>(*this)) |
780 | return; |
781 | |
782 | for (auto& child : childrenOfType<RenderObject>(downcast<RenderElement>(*this))) |
783 | child.addAbsoluteRectForLayer(result); |
784 | } |
785 | |
786 | // FIXME: change this to use the subtreePaint terminology |
787 | LayoutRect RenderObject::paintingRootRect(LayoutRect& topLevelRect) |
788 | { |
789 | LayoutRect result = absoluteBoundingBoxRectIgnoringTransforms(); |
790 | topLevelRect = result; |
791 | if (is<RenderElement>(*this)) { |
792 | for (auto& child : childrenOfType<RenderObject>(downcast<RenderElement>(*this))) |
793 | child.addAbsoluteRectForLayer(result); |
794 | } |
795 | return result; |
796 | } |
797 | |
798 | RenderLayerModelObject* RenderObject::containerForRepaint() const |
799 | { |
800 | RenderLayerModelObject* repaintContainer = nullptr; |
801 | |
802 | if (view().usesCompositing()) { |
803 | if (RenderLayer* parentLayer = enclosingLayer()) { |
804 | RenderLayer* compLayer = parentLayer->enclosingCompositingLayerForRepaint(); |
805 | if (compLayer) |
806 | repaintContainer = &compLayer->renderer(); |
807 | } |
808 | } |
809 | if (view().hasSoftwareFilters()) { |
810 | if (RenderLayer* parentLayer = enclosingLayer()) { |
811 | RenderLayer* enclosingFilterLayer = parentLayer->enclosingFilterLayer(); |
812 | if (enclosingFilterLayer) |
813 | return &enclosingFilterLayer->renderer(); |
814 | } |
815 | } |
816 | |
817 | // If we have a flow thread, then we need to do individual repaints within the RenderFragmentContainers instead. |
818 | // Return the flow thread as a repaint container in order to create a chokepoint that allows us to change |
819 | // repainting to do individual region repaints. |
820 | RenderFragmentedFlow* parentRenderFragmentedFlow = enclosingFragmentedFlow(); |
821 | if (parentRenderFragmentedFlow) { |
822 | // If we have already found a repaint container then we will repaint into that container only if it is part of the same |
823 | // flow thread. Otherwise we will need to catch the repaint call and send it to the flow thread. |
824 | RenderFragmentedFlow* repaintContainerFragmentedFlow = repaintContainer ? repaintContainer->enclosingFragmentedFlow() : nullptr; |
825 | if (!repaintContainerFragmentedFlow || repaintContainerFragmentedFlow != parentRenderFragmentedFlow) |
826 | repaintContainer = parentRenderFragmentedFlow; |
827 | } |
828 | return repaintContainer; |
829 | } |
830 | |
831 | void RenderObject::propagateRepaintToParentWithOutlineAutoIfNeeded(const RenderLayerModelObject& repaintContainer, const LayoutRect& repaintRect) const |
832 | { |
833 | if (!hasOutlineAutoAncestor()) |
834 | return; |
835 | |
836 | // FIXME: We should really propagate only when the child renderer sticks out. |
837 | bool repaintRectNeedsConverting = false; |
838 | // Issue repaint on the renderer with outline: auto. |
839 | for (const auto* renderer = this; renderer; renderer = renderer->parent()) { |
840 | bool rendererHasOutlineAutoAncestor = renderer->hasOutlineAutoAncestor(); |
841 | ASSERT(rendererHasOutlineAutoAncestor |
842 | || renderer->outlineStyleForRepaint().outlineStyleIsAuto() == OutlineIsAuto::On |
843 | || (is<RenderBoxModelObject>(*renderer) && downcast<RenderBoxModelObject>(*renderer).isContinuation())); |
844 | if (renderer == &repaintContainer && rendererHasOutlineAutoAncestor) |
845 | repaintRectNeedsConverting = true; |
846 | if (rendererHasOutlineAutoAncestor) |
847 | continue; |
848 | // Issue repaint on the correct repaint container. |
849 | LayoutRect adjustedRepaintRect = repaintRect; |
850 | adjustedRepaintRect.inflate(renderer->outlineStyleForRepaint().outlineSize()); |
851 | if (!repaintRectNeedsConverting) |
852 | repaintContainer.repaintRectangle(adjustedRepaintRect); |
853 | else if (is<RenderLayerModelObject>(renderer)) { |
854 | const auto& rendererWithOutline = downcast<RenderLayerModelObject>(*renderer); |
855 | adjustedRepaintRect = LayoutRect(repaintContainer.localToContainerQuad(FloatRect(adjustedRepaintRect), &rendererWithOutline).boundingBox()); |
856 | rendererWithOutline.repaintRectangle(adjustedRepaintRect); |
857 | } |
858 | return; |
859 | } |
860 | ASSERT_NOT_REACHED(); |
861 | } |
862 | |
863 | void RenderObject::repaintUsingContainer(const RenderLayerModelObject* repaintContainer, const LayoutRect& r, bool shouldClipToLayer) const |
864 | { |
865 | if (r.isEmpty()) |
866 | return; |
867 | |
868 | if (!repaintContainer) |
869 | repaintContainer = &view(); |
870 | |
871 | if (is<RenderFragmentedFlow>(*repaintContainer)) { |
872 | downcast<RenderFragmentedFlow>(*repaintContainer).repaintRectangleInFragments(r); |
873 | return; |
874 | } |
875 | |
876 | propagateRepaintToParentWithOutlineAutoIfNeeded(*repaintContainer, r); |
877 | |
878 | if (repaintContainer->hasFilter() && repaintContainer->layer() && repaintContainer->layer()->requiresFullLayerImageForFilters()) { |
879 | repaintContainer->layer()->setFilterBackendNeedsRepaintingInRect(r); |
880 | return; |
881 | } |
882 | |
883 | if (repaintContainer->isRenderView()) { |
884 | RenderView& view = this->view(); |
885 | ASSERT(repaintContainer == &view); |
886 | bool viewHasCompositedLayer = view.isComposited(); |
887 | if (!viewHasCompositedLayer || view.layer()->backing()->paintsIntoWindow()) { |
888 | LayoutRect rect = r; |
889 | if (viewHasCompositedLayer && view.layer()->transform()) |
890 | rect = LayoutRect(view.layer()->transform()->mapRect(snapRectToDevicePixels(rect, document().deviceScaleFactor()))); |
891 | view.repaintViewRectangle(rect); |
892 | return; |
893 | } |
894 | } |
895 | |
896 | if (view().usesCompositing()) { |
897 | ASSERT(repaintContainer->isComposited()); |
898 | repaintContainer->layer()->setBackingNeedsRepaintInRect(r, shouldClipToLayer ? GraphicsLayer::ClipToLayer : GraphicsLayer::DoNotClipToLayer); |
899 | } |
900 | } |
901 | |
902 | void RenderObject::repaint() const |
903 | { |
904 | // Don't repaint if we're unrooted (note that view() still returns the view when unrooted) |
905 | if (!isRooted()) |
906 | return; |
907 | |
908 | const RenderView& view = this->view(); |
909 | if (view.printing()) |
910 | return; |
911 | |
912 | RenderLayerModelObject* repaintContainer = containerForRepaint(); |
913 | repaintUsingContainer(repaintContainer, clippedOverflowRectForRepaint(repaintContainer)); |
914 | } |
915 | |
916 | void RenderObject::repaintRectangle(const LayoutRect& r, bool shouldClipToLayer) const |
917 | { |
918 | // Don't repaint if we're unrooted (note that view() still returns the view when unrooted) |
919 | if (!isRooted()) |
920 | return; |
921 | |
922 | const RenderView& view = this->view(); |
923 | if (view.printing()) |
924 | return; |
925 | |
926 | LayoutRect dirtyRect(r); |
927 | // FIXME: layoutDelta needs to be applied in parts before/after transforms and |
928 | // repaint containers. https://bugs.webkit.org/show_bug.cgi?id=23308 |
929 | dirtyRect.move(view.frameView().layoutContext().layoutDelta()); |
930 | |
931 | RenderLayerModelObject* repaintContainer = containerForRepaint(); |
932 | repaintUsingContainer(repaintContainer, computeRectForRepaint(dirtyRect, repaintContainer), shouldClipToLayer); |
933 | } |
934 | |
935 | void RenderObject::repaintSlowRepaintObject() const |
936 | { |
937 | // Don't repaint if we're unrooted (note that view() still returns the view when unrooted) |
938 | if (!isRooted()) |
939 | return; |
940 | |
941 | const RenderView& view = this->view(); |
942 | if (view.printing()) |
943 | return; |
944 | |
945 | const RenderLayerModelObject* repaintContainer = containerForRepaint(); |
946 | |
947 | bool shouldClipToLayer = true; |
948 | IntRect repaintRect; |
949 | // If this is the root background, we need to check if there is an extended background rect. If |
950 | // there is, then we should not allow painting to clip to the layer size. |
951 | if (isDocumentElementRenderer() || isBody()) { |
952 | shouldClipToLayer = !view.frameView().hasExtendedBackgroundRectForPainting(); |
953 | repaintRect = snappedIntRect(view.backgroundRect()); |
954 | } else |
955 | repaintRect = snappedIntRect(clippedOverflowRectForRepaint(repaintContainer)); |
956 | |
957 | repaintUsingContainer(repaintContainer, repaintRect, shouldClipToLayer); |
958 | } |
959 | |
960 | IntRect RenderObject::pixelSnappedAbsoluteClippedOverflowRect() const |
961 | { |
962 | return snappedIntRect(absoluteClippedOverflowRect()); |
963 | } |
964 | |
965 | LayoutRect RenderObject::rectWithOutlineForRepaint(const RenderLayerModelObject* repaintContainer, LayoutUnit outlineWidth) const |
966 | { |
967 | LayoutRect r(clippedOverflowRectForRepaint(repaintContainer)); |
968 | r.inflate(outlineWidth); |
969 | return r; |
970 | } |
971 | |
972 | LayoutRect RenderObject::clippedOverflowRectForRepaint(const RenderLayerModelObject*) const |
973 | { |
974 | ASSERT_NOT_REACHED(); |
975 | return LayoutRect(); |
976 | } |
977 | |
978 | bool RenderObject::shouldApplyCompositedContainerScrollsForRepaint() |
979 | { |
980 | #if PLATFORM(IOS_FAMILY) |
981 | return false; |
982 | #else |
983 | return true; |
984 | #endif |
985 | } |
986 | |
987 | RenderObject::VisibleRectContext RenderObject::visibleRectContextForRepaint() |
988 | { |
989 | VisibleRectContext context; |
990 | if (shouldApplyCompositedContainerScrollsForRepaint()) |
991 | context.m_options.add(VisibleRectContextOption::ApplyCompositedContainerScrolls); |
992 | return context; |
993 | } |
994 | |
995 | LayoutRect RenderObject::computeRectForRepaint(const LayoutRect& rect, const RenderLayerModelObject* repaintContainer) const |
996 | { |
997 | return *computeVisibleRectInContainer(rect, repaintContainer, visibleRectContextForRepaint()); |
998 | } |
999 | |
1000 | FloatRect RenderObject::computeFloatRectForRepaint(const FloatRect& rect, const RenderLayerModelObject* repaintContainer) const |
1001 | { |
1002 | return *computeFloatVisibleRectInContainer(rect, repaintContainer, visibleRectContextForRepaint()); |
1003 | } |
1004 | |
1005 | Optional<LayoutRect> RenderObject::computeVisibleRectInContainer(const LayoutRect& rect, const RenderLayerModelObject* container, VisibleRectContext context) const |
1006 | { |
1007 | if (container == this) |
1008 | return rect; |
1009 | |
1010 | auto* parent = this->parent(); |
1011 | if (!parent) |
1012 | return rect; |
1013 | |
1014 | LayoutRect adjustedRect = rect; |
1015 | if (parent->hasOverflowClip()) { |
1016 | bool isEmpty = !downcast<RenderBox>(*parent).applyCachedClipAndScrollPosition(adjustedRect, container, context); |
1017 | if (isEmpty) { |
1018 | if (context.m_options.contains(VisibleRectContextOption::UseEdgeInclusiveIntersection)) |
1019 | return WTF::nullopt; |
1020 | return adjustedRect; |
1021 | } |
1022 | } |
1023 | return parent->computeVisibleRectInContainer(adjustedRect, container, context); |
1024 | } |
1025 | |
1026 | Optional<FloatRect> RenderObject::computeFloatVisibleRectInContainer(const FloatRect&, const RenderLayerModelObject*, VisibleRectContext) const |
1027 | { |
1028 | ASSERT_NOT_REACHED(); |
1029 | return FloatRect(); |
1030 | } |
1031 | |
1032 | #if ENABLE(TREE_DEBUGGING) |
1033 | |
1034 | static void outputRenderTreeLegend(TextStream& stream) |
1035 | { |
1036 | stream.nextLine(); |
1037 | stream << "(B)lock/(I)nline/I(N)line-block, (A)bsolute/Fi(X)ed/(R)elative/Stic(K)y, (F)loating, (O)verflow clip, Anon(Y)mous, (G)enerated, has(L)ayer, (C)omposited, (+)Dirty style, (+)Dirty layout" ; |
1038 | stream.nextLine(); |
1039 | } |
1040 | |
1041 | void RenderObject::showNodeTreeForThis() const |
1042 | { |
1043 | if (!node()) |
1044 | return; |
1045 | node()->showTreeForThis(); |
1046 | } |
1047 | |
1048 | void RenderObject::showRenderTreeForThis() const |
1049 | { |
1050 | const WebCore::RenderObject* root = this; |
1051 | while (root->parent()) |
1052 | root = root->parent(); |
1053 | TextStream stream(TextStream::LineMode::MultipleLine, TextStream::Formatting::SVGStyleRect); |
1054 | outputRenderTreeLegend(stream); |
1055 | root->outputRenderSubTreeAndMark(stream, this, 1); |
1056 | WTFLogAlways("%s" , stream.release().utf8().data()); |
1057 | } |
1058 | |
1059 | void RenderObject::showLineTreeForThis() const |
1060 | { |
1061 | if (!is<RenderBlockFlow>(*this)) |
1062 | return; |
1063 | TextStream stream(TextStream::LineMode::MultipleLine, TextStream::Formatting::SVGStyleRect); |
1064 | outputRenderTreeLegend(stream); |
1065 | outputRenderObject(stream, false, 1); |
1066 | downcast<RenderBlockFlow>(*this).outputLineTreeAndMark(stream, nullptr, 2); |
1067 | WTFLogAlways("%s" , stream.release().utf8().data()); |
1068 | } |
1069 | |
1070 | static const RenderFragmentedFlow* enclosingFragmentedFlowFromRenderer(const RenderObject* renderer) |
1071 | { |
1072 | if (!renderer) |
1073 | return nullptr; |
1074 | |
1075 | if (renderer->fragmentedFlowState() == RenderObject::NotInsideFragmentedFlow) |
1076 | return nullptr; |
1077 | |
1078 | if (is<RenderFragmentedFlow>(*renderer)) |
1079 | return downcast<RenderFragmentedFlow>(renderer); |
1080 | |
1081 | if (is<RenderBlock>(*renderer)) |
1082 | return downcast<RenderBlock>(*renderer).cachedEnclosingFragmentedFlow(); |
1083 | |
1084 | return nullptr; |
1085 | } |
1086 | |
1087 | void RenderObject::outputRegionsInformation(TextStream& stream) const |
1088 | { |
1089 | const RenderFragmentedFlow* ftcb = enclosingFragmentedFlowFromRenderer(this); |
1090 | |
1091 | if (!ftcb) { |
1092 | // Only the boxes have region range information. |
1093 | // Try to get the flow thread containing block information |
1094 | // from the containing block of this box. |
1095 | if (is<RenderBox>(*this)) |
1096 | ftcb = enclosingFragmentedFlowFromRenderer(containingBlock()); |
1097 | } |
1098 | |
1099 | if (!ftcb) |
1100 | return; |
1101 | |
1102 | RenderFragmentContainer* startRegion = nullptr; |
1103 | RenderFragmentContainer* endRegion = nullptr; |
1104 | ftcb->getFragmentRangeForBox(downcast<RenderBox>(this), startRegion, endRegion); |
1105 | stream << " [Rs:" << startRegion << " Re:" << endRegion << "]" ; |
1106 | } |
1107 | |
1108 | void RenderObject::outputRenderObject(TextStream& stream, bool mark, int depth) const |
1109 | { |
1110 | if (isInlineBlockOrInlineTable()) |
1111 | stream << "N" ; |
1112 | else if (isInline()) |
1113 | stream << "I" ; |
1114 | else |
1115 | stream << "B" ; |
1116 | |
1117 | if (isPositioned()) { |
1118 | if (isRelativelyPositioned()) |
1119 | stream << "R" ; |
1120 | else if (isStickilyPositioned()) |
1121 | stream << "K" ; |
1122 | else if (isOutOfFlowPositioned()) { |
1123 | if (isAbsolutelyPositioned()) |
1124 | stream << "A" ; |
1125 | else |
1126 | stream << "X" ; |
1127 | } |
1128 | } else |
1129 | stream << "-" ; |
1130 | |
1131 | if (isFloating()) |
1132 | stream << "F" ; |
1133 | else |
1134 | stream << "-" ; |
1135 | |
1136 | if (hasOverflowClip()) |
1137 | stream << "O" ; |
1138 | else |
1139 | stream << "-" ; |
1140 | |
1141 | if (isAnonymous()) |
1142 | stream << "Y" ; |
1143 | else |
1144 | stream << "-" ; |
1145 | |
1146 | if (isPseudoElement() || isAnonymous()) |
1147 | stream << "G" ; |
1148 | else |
1149 | stream << "-" ; |
1150 | |
1151 | if (hasLayer()) |
1152 | stream << "L" ; |
1153 | else |
1154 | stream << "-" ; |
1155 | |
1156 | if (isComposited()) |
1157 | stream << "C" ; |
1158 | else |
1159 | stream << "-" ; |
1160 | |
1161 | stream << " " ; |
1162 | |
1163 | if (node() && node()->needsStyleRecalc()) |
1164 | stream << "+" ; |
1165 | else |
1166 | stream << "-" ; |
1167 | |
1168 | if (needsLayout()) |
1169 | stream << "+" ; |
1170 | else |
1171 | stream << "-" ; |
1172 | |
1173 | int printedCharacters = 0; |
1174 | if (mark) { |
1175 | stream << "*" ; |
1176 | ++printedCharacters; |
1177 | } |
1178 | |
1179 | while (++printedCharacters <= depth * 2) |
1180 | stream << " " ; |
1181 | |
1182 | if (node()) |
1183 | stream << node()->nodeName().utf8().data() << " " ; |
1184 | |
1185 | String name = renderName(); |
1186 | // FIXME: Renderer's name should not include property value listing. |
1187 | int pos = name.find('('); |
1188 | if (pos > 0) |
1189 | stream << name.left(pos - 1).utf8().data(); |
1190 | else |
1191 | stream << name.utf8().data(); |
1192 | |
1193 | if (is<RenderBox>(*this)) { |
1194 | auto& renderBox = downcast<RenderBox>(*this); |
1195 | FloatRect boxRect = renderBox.frameRect(); |
1196 | if (renderBox.isInFlowPositioned()) |
1197 | boxRect.move(renderBox.offsetForInFlowPosition()); |
1198 | stream << " " << boxRect; |
1199 | } else if (is<RenderInline>(*this) && isInFlowPositioned()) { |
1200 | FloatSize inlineOffset = downcast<RenderInline>(*this).offsetForInFlowPosition(); |
1201 | stream << " (" << inlineOffset.width() << ", " << inlineOffset.height() << ")" ; |
1202 | } |
1203 | |
1204 | stream << " renderer->(" << this << ")" ; |
1205 | if (node()) { |
1206 | stream << " node->(" << node() << ")" ; |
1207 | if (node()->isTextNode()) { |
1208 | String value = node()->nodeValue(); |
1209 | stream << " length->(" << value.length() << ")" ; |
1210 | |
1211 | value.replaceWithLiteral('\\', "\\\\" ); |
1212 | value.replaceWithLiteral('\n', "\\n" ); |
1213 | |
1214 | const int maxPrintedLength = 80; |
1215 | if (value.length() > maxPrintedLength) { |
1216 | String substring = value.substring(0, maxPrintedLength); |
1217 | stream << " \"" << substring.utf8().data() << "\"..." ; |
1218 | } else |
1219 | stream << " \"" << value.utf8().data() << "\"" ; |
1220 | } |
1221 | } |
1222 | if (is<RenderBoxModelObject>(*this)) { |
1223 | auto& renderer = downcast<RenderBoxModelObject>(*this); |
1224 | if (renderer.continuation()) |
1225 | stream << " continuation->(" << renderer.continuation() << ")" ; |
1226 | } |
1227 | outputRegionsInformation(stream); |
1228 | if (needsLayout()) { |
1229 | stream << " layout->" ; |
1230 | if (selfNeedsLayout()) |
1231 | stream << "[self]" ; |
1232 | if (normalChildNeedsLayout()) |
1233 | stream << "[normal child]" ; |
1234 | if (posChildNeedsLayout()) |
1235 | stream << "[positioned child]" ; |
1236 | if (needsSimplifiedNormalFlowLayout()) |
1237 | stream << "[simplified]" ; |
1238 | if (needsPositionedMovementLayout()) |
1239 | stream << "[positioned movement]" ; |
1240 | } |
1241 | stream.nextLine(); |
1242 | } |
1243 | |
1244 | void RenderObject::outputRenderSubTreeAndMark(TextStream& stream, const RenderObject* markedObject, int depth) const |
1245 | { |
1246 | outputRenderObject(stream, markedObject == this, depth); |
1247 | if (is<RenderBlockFlow>(*this)) |
1248 | downcast<RenderBlockFlow>(*this).outputLineTreeAndMark(stream, nullptr, depth + 1); |
1249 | |
1250 | for (auto* child = firstChildSlow(); child; child = child->nextSibling()) |
1251 | child->outputRenderSubTreeAndMark(stream, markedObject, depth + 1); |
1252 | } |
1253 | |
1254 | #endif // NDEBUG |
1255 | |
1256 | FloatPoint RenderObject::localToAbsolute(const FloatPoint& localPoint, MapCoordinatesFlags mode, bool* wasFixed) const |
1257 | { |
1258 | TransformState transformState(TransformState::ApplyTransformDirection, localPoint); |
1259 | mapLocalToContainer(nullptr, transformState, mode | ApplyContainerFlip, wasFixed); |
1260 | transformState.flatten(); |
1261 | |
1262 | return transformState.lastPlanarPoint(); |
1263 | } |
1264 | |
1265 | FloatPoint RenderObject::absoluteToLocal(const FloatPoint& containerPoint, MapCoordinatesFlags mode) const |
1266 | { |
1267 | TransformState transformState(TransformState::UnapplyInverseTransformDirection, containerPoint); |
1268 | mapAbsoluteToLocalPoint(mode, transformState); |
1269 | transformState.flatten(); |
1270 | |
1271 | return transformState.lastPlanarPoint(); |
1272 | } |
1273 | |
1274 | FloatQuad RenderObject::absoluteToLocalQuad(const FloatQuad& quad, MapCoordinatesFlags mode) const |
1275 | { |
1276 | TransformState transformState(TransformState::UnapplyInverseTransformDirection, quad.boundingBox().center(), quad); |
1277 | mapAbsoluteToLocalPoint(mode, transformState); |
1278 | transformState.flatten(); |
1279 | return transformState.lastPlanarQuad(); |
1280 | } |
1281 | |
1282 | void RenderObject::mapLocalToContainer(const RenderLayerModelObject* repaintContainer, TransformState& transformState, MapCoordinatesFlags mode, bool* wasFixed) const |
1283 | { |
1284 | if (repaintContainer == this) |
1285 | return; |
1286 | |
1287 | auto* parent = this->parent(); |
1288 | if (!parent) |
1289 | return; |
1290 | |
1291 | // FIXME: this should call offsetFromContainer to share code, but I'm not sure it's ever called. |
1292 | LayoutPoint centerPoint(transformState.mappedPoint()); |
1293 | if (mode & ApplyContainerFlip && is<RenderBox>(*parent)) { |
1294 | if (parent->style().isFlippedBlocksWritingMode()) |
1295 | transformState.move(downcast<RenderBox>(parent)->flipForWritingMode(LayoutPoint(transformState.mappedPoint())) - centerPoint); |
1296 | mode &= ~ApplyContainerFlip; |
1297 | } |
1298 | |
1299 | if (is<RenderBox>(*parent)) |
1300 | transformState.move(-toLayoutSize(downcast<RenderBox>(*parent).scrollPosition())); |
1301 | |
1302 | parent->mapLocalToContainer(repaintContainer, transformState, mode, wasFixed); |
1303 | } |
1304 | |
1305 | const RenderObject* RenderObject::pushMappingToContainer(const RenderLayerModelObject* ancestorToStopAt, RenderGeometryMap& geometryMap) const |
1306 | { |
1307 | ASSERT_UNUSED(ancestorToStopAt, ancestorToStopAt != this); |
1308 | |
1309 | auto* container = parent(); |
1310 | if (!container) |
1311 | return nullptr; |
1312 | |
1313 | // FIXME: this should call offsetFromContainer to share code, but I'm not sure it's ever called. |
1314 | LayoutSize offset; |
1315 | if (is<RenderBox>(*container)) |
1316 | offset = -toLayoutSize(downcast<RenderBox>(*container).scrollPosition()); |
1317 | |
1318 | geometryMap.push(this, offset, false); |
1319 | |
1320 | return container; |
1321 | } |
1322 | |
1323 | void RenderObject::mapAbsoluteToLocalPoint(MapCoordinatesFlags mode, TransformState& transformState) const |
1324 | { |
1325 | if (auto* parent = this->parent()) { |
1326 | parent->mapAbsoluteToLocalPoint(mode, transformState); |
1327 | if (is<RenderBox>(*parent)) |
1328 | transformState.move(toLayoutSize(downcast<RenderBox>(*parent).scrollPosition())); |
1329 | } |
1330 | } |
1331 | |
1332 | bool RenderObject::shouldUseTransformFromContainer(const RenderObject* containerObject) const |
1333 | { |
1334 | #if ENABLE(3D_TRANSFORMS) |
1335 | return hasTransform() || (containerObject && containerObject->style().hasPerspective()); |
1336 | #else |
1337 | UNUSED_PARAM(containerObject); |
1338 | return hasTransform(); |
1339 | #endif |
1340 | } |
1341 | |
1342 | void RenderObject::getTransformFromContainer(const RenderObject* containerObject, const LayoutSize& offsetInContainer, TransformationMatrix& transform) const |
1343 | { |
1344 | transform.makeIdentity(); |
1345 | transform.translate(offsetInContainer.width(), offsetInContainer.height()); |
1346 | RenderLayer* layer; |
1347 | if (hasLayer() && (layer = downcast<RenderLayerModelObject>(*this).layer()) && layer->transform()) |
1348 | transform.multiply(layer->currentTransform()); |
1349 | |
1350 | #if ENABLE(3D_TRANSFORMS) |
1351 | if (containerObject && containerObject->hasLayer() && containerObject->style().hasPerspective()) { |
1352 | // Perpsective on the container affects us, so we have to factor it in here. |
1353 | ASSERT(containerObject->hasLayer()); |
1354 | FloatPoint perspectiveOrigin = downcast<RenderLayerModelObject>(*containerObject).layer()->perspectiveOrigin(); |
1355 | |
1356 | TransformationMatrix perspectiveMatrix; |
1357 | perspectiveMatrix.applyPerspective(containerObject->style().perspective()); |
1358 | |
1359 | transform.translateRight3d(-perspectiveOrigin.x(), -perspectiveOrigin.y(), 0); |
1360 | transform = perspectiveMatrix * transform; |
1361 | transform.translateRight3d(perspectiveOrigin.x(), perspectiveOrigin.y(), 0); |
1362 | } |
1363 | #else |
1364 | UNUSED_PARAM(containerObject); |
1365 | #endif |
1366 | } |
1367 | |
1368 | FloatQuad RenderObject::localToContainerQuad(const FloatQuad& localQuad, const RenderLayerModelObject* repaintContainer, MapCoordinatesFlags mode, bool* wasFixed) const |
1369 | { |
1370 | // Track the point at the center of the quad's bounding box. As mapLocalToContainer() calls offsetFromContainer(), |
1371 | // it will use that point as the reference point to decide which column's transform to apply in multiple-column blocks. |
1372 | TransformState transformState(TransformState::ApplyTransformDirection, localQuad.boundingBox().center(), localQuad); |
1373 | mapLocalToContainer(repaintContainer, transformState, mode | ApplyContainerFlip, wasFixed); |
1374 | transformState.flatten(); |
1375 | |
1376 | return transformState.lastPlanarQuad(); |
1377 | } |
1378 | |
1379 | FloatPoint RenderObject::localToContainerPoint(const FloatPoint& localPoint, const RenderLayerModelObject* repaintContainer, MapCoordinatesFlags mode, bool* wasFixed) const |
1380 | { |
1381 | TransformState transformState(TransformState::ApplyTransformDirection, localPoint); |
1382 | mapLocalToContainer(repaintContainer, transformState, mode | ApplyContainerFlip, wasFixed); |
1383 | transformState.flatten(); |
1384 | |
1385 | return transformState.lastPlanarPoint(); |
1386 | } |
1387 | |
1388 | LayoutSize RenderObject::offsetFromContainer(RenderElement& container, const LayoutPoint&, bool* offsetDependsOnPoint) const |
1389 | { |
1390 | ASSERT(&container == this->container()); |
1391 | |
1392 | LayoutSize offset; |
1393 | if (is<RenderBox>(container)) |
1394 | offset -= toLayoutSize(downcast<RenderBox>(container).scrollPosition()); |
1395 | |
1396 | if (offsetDependsOnPoint) |
1397 | *offsetDependsOnPoint = is<RenderFragmentedFlow>(container); |
1398 | |
1399 | return offset; |
1400 | } |
1401 | |
1402 | LayoutSize RenderObject::offsetFromAncestorContainer(RenderElement& container) const |
1403 | { |
1404 | LayoutSize offset; |
1405 | LayoutPoint referencePoint; |
1406 | const RenderObject* currContainer = this; |
1407 | do { |
1408 | RenderElement* nextContainer = currContainer->container(); |
1409 | ASSERT(nextContainer); // This means we reached the top without finding container. |
1410 | if (!nextContainer) |
1411 | break; |
1412 | ASSERT(!currContainer->hasTransform()); |
1413 | LayoutSize currentOffset = currContainer->offsetFromContainer(*nextContainer, referencePoint); |
1414 | offset += currentOffset; |
1415 | referencePoint.move(currentOffset); |
1416 | currContainer = nextContainer; |
1417 | } while (currContainer != &container); |
1418 | |
1419 | return offset; |
1420 | } |
1421 | |
1422 | LayoutRect RenderObject::localCaretRect(InlineBox*, unsigned, LayoutUnit* ) |
1423 | { |
1424 | if (extraWidthToEndOfLine) |
1425 | *extraWidthToEndOfLine = 0; |
1426 | |
1427 | return LayoutRect(); |
1428 | } |
1429 | |
1430 | bool RenderObject::isRooted() const |
1431 | { |
1432 | return isDescendantOf(&view()); |
1433 | } |
1434 | |
1435 | static inline RenderElement* containerForElement(const RenderObject& renderer, const RenderLayerModelObject* repaintContainer, bool* repaintContainerSkipped) |
1436 | { |
1437 | // This method is extremely similar to containingBlock(), but with a few notable |
1438 | // exceptions. |
1439 | // (1) For normal flow elements, it just returns the parent. |
1440 | // (2) For absolute positioned elements, it will return a relative positioned inline, while |
1441 | // containingBlock() skips to the non-anonymous containing block. |
1442 | // This does mean that computePositionedLogicalWidth and computePositionedLogicalHeight have to use container(). |
1443 | auto pos = renderer.style().position(); |
1444 | auto* parent = renderer.parent(); |
1445 | if (is<RenderText>(renderer) || (pos != PositionType::Fixed && pos != PositionType::Absolute)) |
1446 | return parent; |
1447 | for (; parent && (pos == PositionType::Absolute ? !parent->canContainAbsolutelyPositionedObjects() : !parent->canContainFixedPositionObjects()); parent = parent->parent()) { |
1448 | if (repaintContainerSkipped && repaintContainer == parent) |
1449 | *repaintContainerSkipped = true; |
1450 | } |
1451 | return parent; |
1452 | } |
1453 | |
1454 | RenderElement* RenderObject::container() const |
1455 | { |
1456 | return containerForElement(*this, nullptr, nullptr); |
1457 | } |
1458 | |
1459 | RenderElement* RenderObject::container(const RenderLayerModelObject* repaintContainer, bool& repaintContainerSkipped) const |
1460 | { |
1461 | repaintContainerSkipped = false; |
1462 | return containerForElement(*this, repaintContainer, &repaintContainerSkipped); |
1463 | } |
1464 | |
1465 | bool RenderObject::isSelectionBorder() const |
1466 | { |
1467 | SelectionState st = selectionState(); |
1468 | return st == SelectionStart |
1469 | || st == SelectionEnd |
1470 | || st == SelectionBoth |
1471 | || view().selection().start() == this |
1472 | || view().selection().end() == this; |
1473 | } |
1474 | |
1475 | void RenderObject::willBeDestroyed() |
1476 | { |
1477 | ASSERT(!m_parent); |
1478 | ASSERT(renderTreeBeingDestroyed() || !is<RenderElement>(*this) || !view().frameView().hasSlowRepaintObject(downcast<RenderElement>(*this))); |
1479 | |
1480 | if (AXObjectCache* cache = document().existingAXObjectCache()) |
1481 | cache->remove(this); |
1482 | |
1483 | if (auto* node = this->node()) { |
1484 | // FIXME: Continuations should be anonymous. |
1485 | ASSERT(!node->renderer() || node->renderer() == this || (is<RenderElement>(*this) && downcast<RenderElement>(*this).isContinuation())); |
1486 | if (node->renderer() == this) |
1487 | node->setRenderer(nullptr); |
1488 | } |
1489 | |
1490 | removeRareData(); |
1491 | } |
1492 | |
1493 | void RenderObject::insertedIntoTree() |
1494 | { |
1495 | // FIXME: We should ASSERT(isRooted()) here but generated content makes some out-of-order insertion. |
1496 | if (!isFloating() && parent()->childrenInline()) |
1497 | parent()->dirtyLinesFromChangedChild(*this); |
1498 | } |
1499 | |
1500 | void RenderObject::willBeRemovedFromTree() |
1501 | { |
1502 | // FIXME: We should ASSERT(isRooted()) but we have some out-of-order removals which would need to be fixed first. |
1503 | // Update cached boundaries in SVG renderers, if a child is removed. |
1504 | parent()->setNeedsBoundariesUpdate(); |
1505 | } |
1506 | |
1507 | void RenderObject::destroy() |
1508 | { |
1509 | RELEASE_ASSERT(!m_parent); |
1510 | RELEASE_ASSERT(!m_next); |
1511 | RELEASE_ASSERT(!m_previous); |
1512 | RELEASE_ASSERT(!m_bitfields.beingDestroyed()); |
1513 | |
1514 | m_bitfields.setBeingDestroyed(true); |
1515 | |
1516 | #if PLATFORM(IOS_FAMILY) |
1517 | if (hasLayer()) |
1518 | downcast<RenderBoxModelObject>(*this).layer()->willBeDestroyed(); |
1519 | #endif |
1520 | |
1521 | willBeDestroyed(); |
1522 | |
1523 | if (is<RenderWidget>(*this)) { |
1524 | downcast<RenderWidget>(*this).deref(); |
1525 | return; |
1526 | } |
1527 | delete this; |
1528 | } |
1529 | |
1530 | Position RenderObject::positionForPoint(const LayoutPoint& point) |
1531 | { |
1532 | // FIXME: This should just create a Position object instead (webkit.org/b/168566). |
1533 | return positionForPoint(point, nullptr).deepEquivalent(); |
1534 | } |
1535 | |
1536 | VisiblePosition RenderObject::positionForPoint(const LayoutPoint&, const RenderFragmentContainer*) |
1537 | { |
1538 | return createVisiblePosition(caretMinOffset(), DOWNSTREAM); |
1539 | } |
1540 | |
1541 | void RenderObject::updateDragState(bool dragOn) |
1542 | { |
1543 | bool valueChanged = (dragOn != isDragging()); |
1544 | setIsDragging(dragOn); |
1545 | |
1546 | if (!is<RenderElement>(*this)) |
1547 | return; |
1548 | auto& renderElement = downcast<RenderElement>(*this); |
1549 | |
1550 | if (valueChanged && renderElement.element() && (style().affectedByDrag() || renderElement.element()->childrenAffectedByDrag())) |
1551 | renderElement.element()->invalidateStyleForSubtree(); |
1552 | |
1553 | for (auto& child : childrenOfType<RenderObject>(renderElement)) |
1554 | child.updateDragState(dragOn); |
1555 | } |
1556 | |
1557 | bool RenderObject::isComposited() const |
1558 | { |
1559 | return hasLayer() && downcast<RenderLayerModelObject>(*this).layer()->isComposited(); |
1560 | } |
1561 | |
1562 | bool RenderObject::hitTest(const HitTestRequest& request, HitTestResult& result, const HitTestLocation& locationInContainer, const LayoutPoint& accumulatedOffset, HitTestFilter hitTestFilter) |
1563 | { |
1564 | bool inside = false; |
1565 | if (hitTestFilter != HitTestSelf) { |
1566 | // First test the foreground layer (lines and inlines). |
1567 | inside = nodeAtPoint(request, result, locationInContainer, accumulatedOffset, HitTestForeground); |
1568 | |
1569 | // Test floats next. |
1570 | if (!inside) |
1571 | inside = nodeAtPoint(request, result, locationInContainer, accumulatedOffset, HitTestFloat); |
1572 | |
1573 | // Finally test to see if the mouse is in the background (within a child block's background). |
1574 | if (!inside) |
1575 | inside = nodeAtPoint(request, result, locationInContainer, accumulatedOffset, HitTestChildBlockBackgrounds); |
1576 | } |
1577 | |
1578 | // See if the mouse is inside us but not any of our descendants |
1579 | if (hitTestFilter != HitTestDescendants && !inside) |
1580 | inside = nodeAtPoint(request, result, locationInContainer, accumulatedOffset, HitTestBlockBackground); |
1581 | |
1582 | return inside; |
1583 | } |
1584 | |
1585 | void RenderObject::updateHitTestResult(HitTestResult& result, const LayoutPoint& point) |
1586 | { |
1587 | if (result.innerNode()) |
1588 | return; |
1589 | |
1590 | Node* node = this->node(); |
1591 | |
1592 | // If we hit the anonymous renderers inside generated content we should |
1593 | // actually hit the generated content so walk up to the PseudoElement. |
1594 | if (!node && parent() && parent()->isBeforeOrAfterContent()) { |
1595 | for (auto* renderer = parent(); renderer && !node; renderer = renderer->parent()) |
1596 | node = renderer->element(); |
1597 | } |
1598 | |
1599 | if (node) { |
1600 | result.setInnerNode(node); |
1601 | if (!result.innerNonSharedNode()) |
1602 | result.setInnerNonSharedNode(node); |
1603 | result.setLocalPoint(point); |
1604 | } |
1605 | } |
1606 | |
1607 | bool RenderObject::nodeAtPoint(const HitTestRequest&, HitTestResult&, const HitTestLocation& /*locationInContainer*/, const LayoutPoint& /*accumulatedOffset*/, HitTestAction) |
1608 | { |
1609 | return false; |
1610 | } |
1611 | |
1612 | int RenderObject::innerLineHeight() const |
1613 | { |
1614 | return style().computedLineHeight(); |
1615 | } |
1616 | |
1617 | #if ENABLE(DASHBOARD_SUPPORT) |
1618 | void RenderObject::addAnnotatedRegions(Vector<AnnotatedRegionValue>& regions) |
1619 | { |
1620 | // Convert the style regions to absolute coordinates. |
1621 | if (style().visibility() != Visibility::Visible || !is<RenderBox>(*this)) |
1622 | return; |
1623 | |
1624 | auto& box = downcast<RenderBox>(*this); |
1625 | FloatPoint absPos = localToAbsolute(); |
1626 | |
1627 | const Vector<StyleDashboardRegion>& styleRegions = style().dashboardRegions(); |
1628 | for (const auto& styleRegion : styleRegions) { |
1629 | LayoutUnit w = box.width(); |
1630 | LayoutUnit h = box.height(); |
1631 | |
1632 | AnnotatedRegionValue region; |
1633 | region.label = styleRegion.label; |
1634 | region.bounds = LayoutRect(styleRegion.offset.left().value(), |
1635 | styleRegion.offset.top().value(), |
1636 | w - styleRegion.offset.left().value() - styleRegion.offset.right().value(), |
1637 | h - styleRegion.offset.top().value() - styleRegion.offset.bottom().value()); |
1638 | region.type = styleRegion.type; |
1639 | |
1640 | region.clip = computeAbsoluteRepaintRect(region.bounds); |
1641 | if (region.clip.height() < 0) { |
1642 | region.clip.setHeight(0); |
1643 | region.clip.setWidth(0); |
1644 | } |
1645 | |
1646 | region.bounds.setX(absPos.x() + styleRegion.offset.left().value()); |
1647 | region.bounds.setY(absPos.y() + styleRegion.offset.top().value()); |
1648 | |
1649 | regions.append(region); |
1650 | } |
1651 | } |
1652 | |
1653 | void RenderObject::collectAnnotatedRegions(Vector<AnnotatedRegionValue>& regions) |
1654 | { |
1655 | // RenderTexts don't have their own style, they just use their parent's style, |
1656 | // so we don't want to include them. |
1657 | if (is<RenderText>(*this)) |
1658 | return; |
1659 | |
1660 | addAnnotatedRegions(regions); |
1661 | for (RenderObject* current = downcast<RenderElement>(*this).firstChild(); current; current = current->nextSibling()) |
1662 | current->collectAnnotatedRegions(regions); |
1663 | } |
1664 | #endif |
1665 | |
1666 | int RenderObject::caretMinOffset() const |
1667 | { |
1668 | return 0; |
1669 | } |
1670 | |
1671 | int RenderObject::caretMaxOffset() const |
1672 | { |
1673 | if (isReplaced()) |
1674 | return node() ? std::max(1U, node()->countChildNodes()) : 1; |
1675 | if (isHR()) |
1676 | return 1; |
1677 | return 0; |
1678 | } |
1679 | |
1680 | int RenderObject::previousOffset(int current) const |
1681 | { |
1682 | return current - 1; |
1683 | } |
1684 | |
1685 | int RenderObject::previousOffsetForBackwardDeletion(int current) const |
1686 | { |
1687 | return current - 1; |
1688 | } |
1689 | |
1690 | int RenderObject::nextOffset(int current) const |
1691 | { |
1692 | return current + 1; |
1693 | } |
1694 | |
1695 | void RenderObject::adjustRectForOutlineAndShadow(LayoutRect& rect) const |
1696 | { |
1697 | LayoutUnit outlineSize = outlineStyleForRepaint().outlineSize(); |
1698 | if (const ShadowData* boxShadow = style().boxShadow()) { |
1699 | boxShadow->adjustRectForShadow(rect, outlineSize); |
1700 | return; |
1701 | } |
1702 | rect.inflate(outlineSize); |
1703 | } |
1704 | |
1705 | void RenderObject::imageChanged(CachedImage* image, const IntRect* rect) |
1706 | { |
1707 | imageChanged(static_cast<WrappedImagePtr>(image), rect); |
1708 | } |
1709 | |
1710 | RenderBoxModelObject* RenderObject::offsetParent() const |
1711 | { |
1712 | // If any of the following holds true return null and stop this algorithm: |
1713 | // A is the root element. |
1714 | // A is the HTML body element. |
1715 | // The computed value of the position property for element A is fixed. |
1716 | if (isDocumentElementRenderer() || isBody() || isFixedPositioned()) |
1717 | return nullptr; |
1718 | |
1719 | // If A is an area HTML element which has a map HTML element somewhere in the ancestor |
1720 | // chain return the nearest ancestor map HTML element and stop this algorithm. |
1721 | // FIXME: Implement! |
1722 | |
1723 | // Return the nearest ancestor element of A for which at least one of the following is |
1724 | // true and stop this algorithm if such an ancestor is found: |
1725 | // * The computed value of the position property is not static. |
1726 | // * It is the HTML body element. |
1727 | // * The computed value of the position property of A is static and the ancestor |
1728 | // is one of the following HTML elements: td, th, or table. |
1729 | // * Our own extension: if there is a difference in the effective zoom |
1730 | |
1731 | bool skipTables = isPositioned(); |
1732 | float currZoom = style().effectiveZoom(); |
1733 | auto current = parent(); |
1734 | while (current && (!current->element() || (!current->isPositioned() && !current->isBody()))) { |
1735 | Element* element = current->element(); |
1736 | if (!skipTables && element && (is<HTMLTableElement>(*element) || is<HTMLTableCellElement>(*element))) |
1737 | break; |
1738 | |
1739 | float newZoom = current->style().effectiveZoom(); |
1740 | if (currZoom != newZoom) |
1741 | break; |
1742 | currZoom = newZoom; |
1743 | current = current->parent(); |
1744 | } |
1745 | |
1746 | return is<RenderBoxModelObject>(current) ? downcast<RenderBoxModelObject>(current) : nullptr; |
1747 | } |
1748 | |
1749 | VisiblePosition RenderObject::createVisiblePosition(int offset, EAffinity affinity) const |
1750 | { |
1751 | // If this is a non-anonymous renderer in an editable area, then it's simple. |
1752 | if (Node* node = nonPseudoNode()) { |
1753 | if (!node->hasEditableStyle()) { |
1754 | // If it can be found, we prefer a visually equivalent position that is editable. |
1755 | Position position = createLegacyEditingPosition(node, offset); |
1756 | Position candidate = position.downstream(CanCrossEditingBoundary); |
1757 | if (candidate.deprecatedNode()->hasEditableStyle()) |
1758 | return VisiblePosition(candidate, affinity); |
1759 | candidate = position.upstream(CanCrossEditingBoundary); |
1760 | if (candidate.deprecatedNode()->hasEditableStyle()) |
1761 | return VisiblePosition(candidate, affinity); |
1762 | } |
1763 | // FIXME: Eliminate legacy editing positions |
1764 | return VisiblePosition(createLegacyEditingPosition(node, offset), affinity); |
1765 | } |
1766 | |
1767 | // We don't want to cross the boundary between editable and non-editable |
1768 | // regions of the document, but that is either impossible or at least |
1769 | // extremely unlikely in any normal case because we stop as soon as we |
1770 | // find a single non-anonymous renderer. |
1771 | |
1772 | // Find a nearby non-anonymous renderer. |
1773 | const RenderObject* child = this; |
1774 | while (const auto parent = child->parent()) { |
1775 | // Find non-anonymous content after. |
1776 | const RenderObject* renderer = child; |
1777 | while ((renderer = renderer->nextInPreOrder(parent))) { |
1778 | if (Node* node = renderer->nonPseudoNode()) |
1779 | return VisiblePosition(firstPositionInOrBeforeNode(node), DOWNSTREAM); |
1780 | } |
1781 | |
1782 | // Find non-anonymous content before. |
1783 | renderer = child; |
1784 | while ((renderer = renderer->previousInPreOrder())) { |
1785 | if (renderer == parent) |
1786 | break; |
1787 | if (Node* node = renderer->nonPseudoNode()) |
1788 | return VisiblePosition(lastPositionInOrAfterNode(node), DOWNSTREAM); |
1789 | } |
1790 | |
1791 | // Use the parent itself unless it too is anonymous. |
1792 | if (Element* element = parent->nonPseudoElement()) |
1793 | return VisiblePosition(firstPositionInOrBeforeNode(element), DOWNSTREAM); |
1794 | |
1795 | // Repeat at the next level up. |
1796 | child = parent; |
1797 | } |
1798 | |
1799 | // Everything was anonymous. Give up. |
1800 | return VisiblePosition(); |
1801 | } |
1802 | |
1803 | VisiblePosition RenderObject::createVisiblePosition(const Position& position) const |
1804 | { |
1805 | if (position.isNotNull()) |
1806 | return VisiblePosition(position); |
1807 | |
1808 | ASSERT(!node()); |
1809 | return createVisiblePosition(0, DOWNSTREAM); |
1810 | } |
1811 | |
1812 | CursorDirective RenderObject::getCursor(const LayoutPoint&, Cursor&) const |
1813 | { |
1814 | return SetCursorBasedOnStyle; |
1815 | } |
1816 | |
1817 | bool RenderObject::useDarkAppearance() const |
1818 | { |
1819 | return document().useDarkAppearance(&style()); |
1820 | } |
1821 | |
1822 | OptionSet<StyleColor::Options> RenderObject::styleColorOptions() const |
1823 | { |
1824 | return document().styleColorOptions(&style()); |
1825 | } |
1826 | |
1827 | bool RenderObject::canUpdateSelectionOnRootLineBoxes() |
1828 | { |
1829 | if (needsLayout()) |
1830 | return false; |
1831 | |
1832 | RenderBlock* containingBlock = this->containingBlock(); |
1833 | return containingBlock ? !containingBlock->needsLayout() : true; |
1834 | } |
1835 | |
1836 | // We only create "generated" child renderers like one for first-letter if: |
1837 | // - the firstLetterBlock can have children in the DOM and |
1838 | // - the block doesn't have any special assumption on its text children. |
1839 | // This correctly prevents form controls from having such renderers. |
1840 | bool RenderObject::canHaveGeneratedChildren() const |
1841 | { |
1842 | return canHaveChildren(); |
1843 | } |
1844 | |
1845 | Node* RenderObject::generatingPseudoHostElement() const |
1846 | { |
1847 | return downcast<PseudoElement>(*node()).hostElement(); |
1848 | } |
1849 | |
1850 | void RenderObject::setNeedsBoundariesUpdate() |
1851 | { |
1852 | if (auto renderer = parent()) |
1853 | renderer->setNeedsBoundariesUpdate(); |
1854 | } |
1855 | |
1856 | FloatRect RenderObject::objectBoundingBox() const |
1857 | { |
1858 | ASSERT_NOT_REACHED(); |
1859 | return FloatRect(); |
1860 | } |
1861 | |
1862 | FloatRect RenderObject::strokeBoundingBox() const |
1863 | { |
1864 | ASSERT_NOT_REACHED(); |
1865 | return FloatRect(); |
1866 | } |
1867 | |
1868 | // Returns the smallest rectangle enclosing all of the painted content |
1869 | // respecting clipping, masking, filters, opacity, stroke-width and markers |
1870 | FloatRect RenderObject::repaintRectInLocalCoordinates() const |
1871 | { |
1872 | ASSERT_NOT_REACHED(); |
1873 | return FloatRect(); |
1874 | } |
1875 | |
1876 | AffineTransform RenderObject::localTransform() const |
1877 | { |
1878 | static const AffineTransform identity; |
1879 | return identity; |
1880 | } |
1881 | |
1882 | const AffineTransform& RenderObject::localToParentTransform() const |
1883 | { |
1884 | static const AffineTransform identity; |
1885 | return identity; |
1886 | } |
1887 | |
1888 | bool RenderObject::nodeAtFloatPoint(const HitTestRequest&, HitTestResult&, const FloatPoint&, HitTestAction) |
1889 | { |
1890 | ASSERT_NOT_REACHED(); |
1891 | return false; |
1892 | } |
1893 | |
1894 | RenderFragmentedFlow* RenderObject::locateEnclosingFragmentedFlow() const |
1895 | { |
1896 | RenderBlock* containingBlock = this->containingBlock(); |
1897 | return containingBlock ? containingBlock->enclosingFragmentedFlow() : nullptr; |
1898 | } |
1899 | |
1900 | void RenderObject::calculateBorderStyleColor(const BorderStyle& style, const BoxSide& side, Color& color) |
1901 | { |
1902 | ASSERT(style == BorderStyle::Inset || style == BorderStyle::Outset); |
1903 | // This values were derived empirically. |
1904 | const RGBA32 baseDarkColor = 0xFF202020; |
1905 | const RGBA32 baseLightColor = 0xFFEBEBEB; |
1906 | enum Operation { Darken, Lighten }; |
1907 | |
1908 | Operation operation = (side == BSTop || side == BSLeft) == (style == BorderStyle::Inset) ? Darken : Lighten; |
1909 | |
1910 | // Here we will darken the border decoration color when needed. This will yield a similar behavior as in FF. |
1911 | if (operation == Darken) { |
1912 | if (differenceSquared(color, Color::black) > differenceSquared(baseDarkColor, Color::black)) |
1913 | color = color.dark(); |
1914 | } else { |
1915 | if (differenceSquared(color, Color::white) > differenceSquared(baseLightColor, Color::white)) |
1916 | color = color.light(); |
1917 | } |
1918 | } |
1919 | |
1920 | void RenderObject::setIsDragging(bool isDragging) |
1921 | { |
1922 | if (isDragging || hasRareData()) |
1923 | ensureRareData().setIsDragging(isDragging); |
1924 | } |
1925 | |
1926 | void RenderObject::setHasReflection(bool hasReflection) |
1927 | { |
1928 | if (hasReflection || hasRareData()) |
1929 | ensureRareData().setHasReflection(hasReflection); |
1930 | } |
1931 | |
1932 | void RenderObject::setIsRenderFragmentedFlow(bool isFragmentedFlow) |
1933 | { |
1934 | if (isFragmentedFlow || hasRareData()) |
1935 | ensureRareData().setIsRenderFragmentedFlow(isFragmentedFlow); |
1936 | } |
1937 | |
1938 | void RenderObject::setHasOutlineAutoAncestor(bool hasOutlineAutoAncestor) |
1939 | { |
1940 | if (hasOutlineAutoAncestor || hasRareData()) |
1941 | ensureRareData().setHasOutlineAutoAncestor(hasOutlineAutoAncestor); |
1942 | } |
1943 | |
1944 | RenderObject::RareDataMap& RenderObject::rareDataMap() |
1945 | { |
1946 | static NeverDestroyed<RareDataMap> map; |
1947 | return map; |
1948 | } |
1949 | |
1950 | const RenderObject::RenderObjectRareData& RenderObject::rareData() const |
1951 | { |
1952 | ASSERT(hasRareData()); |
1953 | return *rareDataMap().get(this); |
1954 | } |
1955 | |
1956 | RenderObject::RenderObjectRareData& RenderObject::ensureRareData() |
1957 | { |
1958 | setHasRareData(true); |
1959 | return *rareDataMap().ensure(this, [] { return std::make_unique<RenderObjectRareData>(); }).iterator->value; |
1960 | } |
1961 | |
1962 | void RenderObject::removeRareData() |
1963 | { |
1964 | rareDataMap().remove(this); |
1965 | setHasRareData(false); |
1966 | } |
1967 | |
1968 | #if ENABLE(TREE_DEBUGGING) |
1969 | |
1970 | void printRenderTreeForLiveDocuments() |
1971 | { |
1972 | for (const auto* document : Document::allDocuments()) { |
1973 | if (!document->renderView()) |
1974 | continue; |
1975 | if (document->frame() && document->frame()->isMainFrame()) |
1976 | fprintf(stderr, "----------------------main frame--------------------------\n" ); |
1977 | fprintf(stderr, "%s" , document->url().string().utf8().data()); |
1978 | showRenderTree(document->renderView()); |
1979 | } |
1980 | } |
1981 | |
1982 | void printLayerTreeForLiveDocuments() |
1983 | { |
1984 | for (const auto* document : Document::allDocuments()) { |
1985 | if (!document->renderView()) |
1986 | continue; |
1987 | if (document->frame() && document->frame()->isMainFrame()) |
1988 | fprintf(stderr, "----------------------main frame--------------------------\n" ); |
1989 | fprintf(stderr, "%s" , document->url().string().utf8().data()); |
1990 | showLayerTree(document->renderView()); |
1991 | } |
1992 | } |
1993 | |
1994 | void printGraphicsLayerTreeForLiveDocuments() |
1995 | { |
1996 | for (const auto* document : Document::allDocuments()) { |
1997 | if (!document->renderView()) |
1998 | continue; |
1999 | if (document->frame() && document->frame()->isMainFrame()) { |
2000 | WTFLogAlways("Graphics layer tree for root document %p %s" , document, document->url().string().utf8().data()); |
2001 | showGraphicsLayerTreeForCompositor(document->renderView()->compositor()); |
2002 | } |
2003 | } |
2004 | } |
2005 | |
2006 | #endif // ENABLE(TREE_DEBUGGING) |
2007 | |
2008 | } // namespace WebCore |
2009 | |
2010 | #if ENABLE(TREE_DEBUGGING) |
2011 | |
2012 | void showNodeTree(const WebCore::RenderObject* object) |
2013 | { |
2014 | if (!object) |
2015 | return; |
2016 | object->showNodeTreeForThis(); |
2017 | } |
2018 | |
2019 | void showLineTree(const WebCore::RenderObject* object) |
2020 | { |
2021 | if (!object) |
2022 | return; |
2023 | object->showLineTreeForThis(); |
2024 | } |
2025 | |
2026 | void showRenderTree(const WebCore::RenderObject* object) |
2027 | { |
2028 | if (!object) |
2029 | return; |
2030 | object->showRenderTreeForThis(); |
2031 | } |
2032 | |
2033 | #endif |
2034 | |