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
|
/**
* Copyright (C) 2000 Lars Knoll (knoll@kde.org)
* Copyright (C) 2006, 2013 Apple Inc. All rights reserved.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Library General Public License for more details.
*
* You should have received a copy of the GNU Library General Public License
* along with this library; see the file COPYING.LIB. If not, write to
* the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
* Boston, MA 02110-1301, USA.
*
*/
#include "config.h"
#include "RenderLineBreak.h"
#include "Document.h"
#include "FontMetrics.h"
#include "HTMLElement.h"
#include "HTMLWBRElement.h"
#include "InlineIteratorBoxInlines.h"
#include "InlineIteratorLineBox.h"
#include "InlineIteratorSVGTextBox.h"
#include "InlineRunAndOffset.h"
#include "LineSelection.h"
#include "LogicalSelectionOffsetCaches.h"
#include "RenderBlock.h"
#include "RenderBoxModelObjectInlines.h"
#include "RenderView.h"
#include "SVGElementTypeHelpers.h"
#include "SVGInlineTextBox.h"
#include "VisiblePosition.h"
#include <wtf/TZoneMallocInlines.h>
#if PLATFORM(IOS_FAMILY)
#include "SelectionGeometry.h"
#endif
namespace WebCore {
WTF_MAKE_TZONE_OR_ISO_ALLOCATED_IMPL(RenderLineBreak);
RenderLineBreak::RenderLineBreak(HTMLElement& element, RenderStyle&& style)
: RenderBoxModelObject(Type::LineBreak, element, WTFMove(style), { }, is<HTMLWBRElement>(element) ? OptionSet<LineBreakFlag> { LineBreakFlag::IsWBR } : OptionSet<LineBreakFlag> { })
{
ASSERT(isRenderLineBreak());
}
RenderLineBreak::~RenderLineBreak()
{
}
LayoutUnit RenderLineBreak::lineHeight(bool firstLine, LineDirectionMode /*direction*/, LinePositionMode /*linePositionMode*/) const
{
if (firstLine) {
auto& firstLineStyle = this->firstLineStyle();
if (&firstLineStyle != &style())
return LayoutUnit::fromFloatCeil(firstLineStyle.computedLineHeight());
}
if (!m_cachedLineHeight)
m_cachedLineHeight = LayoutUnit::fromFloatCeil(style().computedLineHeight());
return *m_cachedLineHeight;
}
LayoutUnit RenderLineBreak::baselinePosition(FontBaseline baselineType, bool firstLine, LineDirectionMode direction, LinePositionMode linePositionMode) const
{
auto& style = firstLine ? firstLineStyle() : this->style();
auto& fontMetrics = style.metricsOfPrimaryFont();
return LayoutUnit { (fontMetrics.ascent(baselineType) + (lineHeight(firstLine, direction, linePositionMode) - fontMetrics.height()) / 2) };
}
int RenderLineBreak::caretMinOffset() const
{
return 0;
}
int RenderLineBreak::caretMaxOffset() const
{
return 1;
}
bool RenderLineBreak::canBeSelectionLeaf() const
{
return true;
}
VisiblePosition RenderLineBreak::positionForPoint(const LayoutPoint&, HitTestSource, const RenderFragmentContainer*)
{
return createVisiblePosition(0, Affinity::Downstream);
}
IntRect RenderLineBreak::linesBoundingBox() const
{
auto run = InlineIterator::boxFor(*this);
if (!run)
return { };
return enclosingIntRect(run->visualRectIgnoringBlockDirection());
}
void RenderLineBreak::boundingRects(Vector<LayoutRect>& rects, const LayoutPoint& accumulatedOffset) const
{
auto box = InlineIterator::boxFor(*this);
if (!box)
return;
auto rect = LayoutRect { box->visualRectIgnoringBlockDirection() };
rect.moveBy(accumulatedOffset);
rects.append(rect);
}
void RenderLineBreak::absoluteQuads(Vector<FloatQuad>& quads, bool* wasFixed) const
{
auto box = InlineIterator::boxFor(*this);
if (!box)
return;
auto rect = box->visualRectIgnoringBlockDirection();
quads.append(localToAbsoluteQuad(FloatRect(rect.location(), rect.size()), UseTransforms, wasFixed));
}
void RenderLineBreak::updateFromStyle()
{
m_cachedLineHeight = { };
RELEASE_ASSERT_WITH_SECURITY_IMPLICATION(isInline());
}
#if PLATFORM(IOS_FAMILY)
void RenderLineBreak::collectSelectionGeometries(Vector<SelectionGeometry>& rects, unsigned, unsigned)
{
auto run = InlineIterator::boxFor(*this);
if (!run)
return;
auto lineBox = run->lineBox();
auto lineSelectionRect = LineSelection::logicalRect(*lineBox);
LayoutRect rect = IntRect(run->logicalLeftIgnoringInlineDirection(), lineSelectionRect.y(), 0, lineSelectionRect.height());
if (!lineBox->isHorizontal())
rect = rect.transposedRect();
if (lineBox->isFirstAfterPageBreak()) {
if (run->isHorizontal())
rect.shiftYEdgeTo(lineBox->logicalTop());
else
rect.shiftXEdgeTo(lineBox->logicalTop());
}
// FIXME: Out-of-flow positioned line breaks do not follow normal containing block chain.
auto* containingBlock = RenderObject::containingBlockForPositionType(PositionType::Static, *this);
// Map rect, extended left to leftOffset, and right to rightOffset, through transforms to get minX and maxX.
LogicalSelectionOffsetCaches cache(*containingBlock);
LayoutUnit leftOffset = containingBlock->logicalLeftSelectionOffset(*containingBlock, LayoutUnit(run->logicalTop()), cache);
LayoutUnit rightOffset = containingBlock->logicalRightSelectionOffset(*containingBlock, LayoutUnit(run->logicalTop()), cache);
LayoutRect extentsRect = rect;
if (run->isHorizontal()) {
extentsRect.setX(leftOffset);
extentsRect.setWidth(rightOffset - leftOffset);
} else {
extentsRect.setY(leftOffset);
extentsRect.setHeight(rightOffset - leftOffset);
}
extentsRect = localToAbsoluteQuad(FloatRect(extentsRect)).enclosingBoundingBox();
if (!run->isHorizontal())
extentsRect = extentsRect.transposedRect();
bool isFirstOnLine = !run->nextLineLeftwardOnLine();
bool isLastOnLine = !run->nextLineRightwardOnLine();
bool isFixed = false;
auto absoluteQuad = localToAbsoluteQuad(FloatRect(rect), UseTransforms, &isFixed);
bool boxIsHorizontal = !is<InlineIterator::SVGTextBoxIterator>(run) ? run->isHorizontal() : !writingMode().isVertical();
rects.append(SelectionGeometry(absoluteQuad, HTMLElement::selectionRenderingBehavior(element()), run->direction(), extentsRect.x(), extentsRect.maxX(), extentsRect.maxY(), 0, run->isLineBreak(), isFirstOnLine, isLastOnLine, false, false, boxIsHorizontal, isFixed, view().pageNumberForBlockProgressionOffset(absoluteQuad.enclosingBoundingBox().x())));
}
#endif
} // namespace WebCore
|