1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238
|
/*
* Copyright (C) 2011 Adobe Systems Incorporated. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above
* copyright notice, this list of conditions and the following
* disclaimer.
* 2. Redistributions in binary form must reproduce the above
* copyright notice, this list of conditions and the following
* disclaimer in the documentation and/or other materials
* provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER "AS IS" AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
* OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
* TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
* THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*/
#include "core/layout/LayoutFlowThread.h"
#include "core/layout/FragmentainerIterator.h"
#include "core/layout/LayoutMultiColumnSet.h"
namespace blink {
LayoutFlowThread::LayoutFlowThread()
: LayoutBlockFlow(nullptr),
m_columnSetsInvalidated(false),
m_pageLogicalSizeChanged(false) {}
LayoutFlowThread* LayoutFlowThread::locateFlowThreadContainingBlockOf(
const LayoutObject& descendant) {
ASSERT(descendant.isInsideFlowThread());
LayoutObject* curr = const_cast<LayoutObject*>(&descendant);
while (curr) {
if (curr->isSVGChild())
return nullptr;
if (curr->isLayoutFlowThread())
return toLayoutFlowThread(curr);
LayoutObject* container = curr->container();
curr = curr->parent();
while (curr != container) {
if (curr->isLayoutFlowThread()) {
// The nearest ancestor flow thread isn't in our containing block chain.
// Then we aren't really part of any flow thread, and we should stop
// looking. This happens when there are out-of-flow objects or column
// spanners.
return nullptr;
}
curr = curr->parent();
}
}
return nullptr;
}
void LayoutFlowThread::removeColumnSetFromThread(
LayoutMultiColumnSet* columnSet) {
ASSERT(columnSet);
m_multiColumnSetList.remove(columnSet);
invalidateColumnSets();
// Clear the interval tree right away, instead of leaving it around with dead
// objects. Not that anyone _should_ try to access the interval tree when the
// column sets are marked as invalid, but this is actually possible if other
// parts of the engine has bugs that cause us to not lay out everything that
// was marked for layout, so that LayoutObject::assertLaidOut() (and a LOT
// of other assertions) fails.
m_multiColumnSetIntervalTree.clear();
}
void LayoutFlowThread::validateColumnSets() {
m_columnSetsInvalidated = false;
// Called to get the maximum logical width for the columnSet.
updateLogicalWidth();
generateColumnSetIntervalTree();
}
bool LayoutFlowThread::mapToVisualRectInAncestorSpace(
const LayoutBoxModelObject* ancestor,
LayoutRect& rect,
VisualRectFlags visualRectFlags) const {
// A flow thread should never be an invalidation container.
DCHECK(ancestor != this);
rect = fragmentsBoundingBox(rect);
return LayoutBlockFlow::mapToVisualRectInAncestorSpace(ancestor, rect,
visualRectFlags);
}
void LayoutFlowThread::layout() {
m_pageLogicalSizeChanged = m_columnSetsInvalidated && everHadLayout();
LayoutBlockFlow::layout();
m_pageLogicalSizeChanged = false;
}
void LayoutFlowThread::computeLogicalHeight(
LayoutUnit,
LayoutUnit logicalTop,
LogicalExtentComputedValues& computedValues) const {
computedValues.m_position = logicalTop;
computedValues.m_extent = LayoutUnit();
for (LayoutMultiColumnSetList::const_iterator iter =
m_multiColumnSetList.begin();
iter != m_multiColumnSetList.end(); ++iter) {
LayoutMultiColumnSet* columnSet = *iter;
computedValues.m_extent += columnSet->logicalHeightInFlowThread();
}
}
void LayoutFlowThread::absoluteQuadsForDescendant(const LayoutBox& descendant,
Vector<FloatQuad>& quads,
MapCoordinatesFlags mode) {
LayoutPoint offsetFromFlowThread;
for (const LayoutObject* object = &descendant; object != this;) {
const LayoutObject* container = object->container();
offsetFromFlowThread += object->offsetFromContainer(container);
object = container;
}
LayoutRect boundingRectInFlowThread(offsetFromFlowThread,
descendant.frameRect().size());
// Set up a fragments relative to the descendant, in the flow thread
// coordinate space, and convert each of them, individually, to absolute
// coordinates.
for (FragmentainerIterator iterator(*this, boundingRectInFlowThread);
!iterator.atEnd(); iterator.advance()) {
LayoutRect fragment = boundingRectInFlowThread;
// We use inclusiveIntersect() because intersect() would reset the
// coordinates for zero-height objects.
fragment.inclusiveIntersect(iterator.fragmentainerInFlowThread());
fragment.moveBy(-offsetFromFlowThread);
quads.push_back(descendant.localToAbsoluteQuad(FloatRect(fragment), mode));
}
}
bool LayoutFlowThread::nodeAtPoint(HitTestResult& result,
const HitTestLocation& locationInContainer,
const LayoutPoint& accumulatedOffset,
HitTestAction hitTestAction) {
if (hitTestAction == HitTestBlockBackground)
return false;
return LayoutBlockFlow::nodeAtPoint(result, locationInContainer,
accumulatedOffset, hitTestAction);
}
LayoutUnit LayoutFlowThread::pageLogicalHeightForOffset(LayoutUnit offset) {
LayoutMultiColumnSet* columnSet =
columnSetAtBlockOffset(offset, AssociateWithLatterPage);
if (!columnSet)
return LayoutUnit();
return columnSet->pageLogicalHeightForOffset(offset);
}
LayoutUnit LayoutFlowThread::pageRemainingLogicalHeightForOffset(
LayoutUnit offset,
PageBoundaryRule pageBoundaryRule) {
LayoutMultiColumnSet* columnSet =
columnSetAtBlockOffset(offset, pageBoundaryRule);
if (!columnSet)
return LayoutUnit();
return columnSet->pageRemainingLogicalHeightForOffset(offset,
pageBoundaryRule);
}
void LayoutFlowThread::generateColumnSetIntervalTree() {
// FIXME: Optimize not to clear the interval all the time. This implies
// manually managing the tree nodes lifecycle.
m_multiColumnSetIntervalTree.clear();
m_multiColumnSetIntervalTree.initIfNeeded();
for (auto columnSet : m_multiColumnSetList)
m_multiColumnSetIntervalTree.add(MultiColumnSetIntervalTree::createInterval(
columnSet->logicalTopInFlowThread(),
columnSet->logicalBottomInFlowThread(), columnSet));
}
LayoutUnit LayoutFlowThread::nextLogicalTopForUnbreakableContent(
LayoutUnit flowThreadOffset,
LayoutUnit contentLogicalHeight) const {
LayoutMultiColumnSet* columnSet =
columnSetAtBlockOffset(flowThreadOffset, AssociateWithLatterPage);
if (!columnSet)
return flowThreadOffset;
return columnSet->nextLogicalTopForUnbreakableContent(flowThreadOffset,
contentLogicalHeight);
}
LayoutRect LayoutFlowThread::fragmentsBoundingBox(
const LayoutRect& layerBoundingBox) const {
ASSERT(!RuntimeEnabledFeatures::slimmingPaintV2Enabled() ||
!m_columnSetsInvalidated);
LayoutRect result;
for (auto* columnSet : m_multiColumnSetList)
result.unite(columnSet->fragmentsBoundingBox(layerBoundingBox));
return result;
}
void LayoutFlowThread::flowThreadToContainingCoordinateSpace(
LayoutUnit& blockPosition,
LayoutUnit& inlinePosition) const {
LayoutPoint position(inlinePosition, blockPosition);
// First we have to make |position| physical, because that's what offsetLeft()
// expects and returns.
if (!isHorizontalWritingMode())
position = position.transposedPoint();
position = flipForWritingMode(position);
position.move(columnOffset(position));
// Make |position| logical again, and read out the values.
position = flipForWritingMode(position);
if (!isHorizontalWritingMode())
position = position.transposedPoint();
blockPosition = position.y();
inlinePosition = position.x();
}
void LayoutFlowThread::MultiColumnSetSearchAdapter::collectIfNeeded(
const MultiColumnSetInterval& interval) {
if (m_result)
return;
if (interval.low() <= m_offset && interval.high() > m_offset)
m_result = interval.data();
}
} // namespace blink
|