本文整理汇总了C++中LayoutBlock类的典型用法代码示例。如果您正苦于以下问题:C++ LayoutBlock类的具体用法?C++ LayoutBlock怎么用?C++ LayoutBlock使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了LayoutBlock类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: innerEditorElement
int LayoutTextControl::firstLineBoxBaseline() const {
int result = LayoutBlock::firstLineBoxBaseline();
if (result != -1)
return result;
// When the text is empty, |LayoutBlock::firstLineBoxBaseline()| cannot
// compute the baseline because lineboxes do not exist.
Element* innerEditor = innerEditorElement();
if (!innerEditor || !innerEditor->layoutObject())
return -1;
LayoutBlock* innerEditorLayoutObject =
toLayoutBlock(innerEditor->layoutObject());
const SimpleFontData* fontData =
innerEditorLayoutObject->style(true)->font().primaryFont();
DCHECK(fontData);
if (!fontData)
return -1;
LayoutUnit baseline(fontData->getFontMetrics().ascent(AlphabeticBaseline));
for (LayoutObject* box = innerEditorLayoutObject; box && box != this;
box = box->parent()) {
if (box->isBox())
baseline += toLayoutBox(box)->logicalTop();
}
return baseline.toInt();
}
示例2: TEST_F
TEST_F(VisualRectMappingTest, LayoutInline) {
document().setBaseURLOverride(KURL(ParsedURLString, "http://test.com"));
setBodyInnerHTML(
"<style>body { margin: 0; }</style>"
"<div id='container' style='overflow: scroll; width: 50px; height: 50px'>"
" <span><img style='width: 20px; height: 100px'></span>"
" <span id=leaf></span></div>");
LayoutBlock* container =
toLayoutBlock(getLayoutObjectByElementId("container"));
LayoutObject* leaf = container->lastChild();
container->setScrollTop(LayoutUnit(50));
LayoutRect originalRect(0, 60, 20, 80);
LayoutRect rect = originalRect;
EXPECT_TRUE(leaf->mapToVisualRectInAncestorSpace(container, rect));
rect.move(-container->scrolledContentOffset());
EXPECT_EQ(rect, LayoutRect(0, 10, 20, 80));
rect = originalRect;
EXPECT_TRUE(leaf->mapToVisualRectInAncestorSpace(&layoutView(), rect));
EXPECT_EQ(rect, LayoutRect(0, 10, 20, 40));
checkPaintInvalidationStateRectMapping(rect, originalRect, *leaf,
layoutView(), layoutView());
rect = LayoutRect(0, 60, 80, 0);
EXPECT_TRUE(
leaf->mapToVisualRectInAncestorSpace(container, rect, EdgeInclusive));
rect.move(-container->scrolledContentOffset());
EXPECT_EQ(rect, LayoutRect(0, 10, 80, 0));
}
示例3: floorf
LayoutUnit SnapToLinesLayouter::computeInitialPositionAdjustment(LayoutUnit& step) const
{
// 6. Let line position be the text track cue computed line position.
// 7. Round line position to an integer by adding 0.5 and then flooring it.
LayoutUnit linePosition = floorf(m_linePosition + 0.5f);
WritingMode writingMode = m_cueBox.style()->writingMode();
// 8. Vertical Growing Left: Add one to line position then negate it.
if (writingMode == RightToLeftWritingMode)
linePosition = -(linePosition + 1);
// 9. Let position be the result of multiplying step and line position.
LayoutUnit position = step * linePosition;
// 10. Vertical Growing Left: Decrease position by the width of the
// bounding box of the boxes in boxes, then increase position by step.
if (writingMode == RightToLeftWritingMode) {
position -= m_cueBox.size().width();
position += step;
}
// 11. If line position is less than zero...
if (linePosition < 0) {
LayoutBlock* parentBlock = m_cueBox.containingBlock();
// Horizontal / Vertical: ... then increase position by the
// height / width of the video's rendering area ...
position += blink::isHorizontalWritingMode(writingMode) ? parentBlock->size().height() : parentBlock->size().width();
// ... and negate step.
step = -step;
}
return position;
}
示例4: findGoodTouchTargets
void findGoodTouchTargets(const IntRect& touchBoxInRootFrame, LocalFrame* mainFrame, Vector<IntRect>& goodTargets, WillBeHeapVector<RawPtrWillBeMember<Node>>& highlightNodes)
{
goodTargets.clear();
int touchPointPadding = ceil(std::max(touchBoxInRootFrame.width(), touchBoxInRootFrame.height()) * 0.5);
IntPoint touchPoint = touchBoxInRootFrame.center();
IntPoint contentsPoint = mainFrame->view()->rootFrameToContents(touchPoint);
HitTestResult result = mainFrame->eventHandler().hitTestResultAtPoint(contentsPoint, HitTestRequest::ReadOnly | HitTestRequest::Active | HitTestRequest::ListBased, LayoutSize(touchPointPadding, touchPointPadding));
const WillBeHeapListHashSet<RefPtrWillBeMember<Node>>& hitResults = result.listBasedTestResult();
// Blacklist nodes that are container of disambiguated nodes.
// It is not uncommon to have a clickable <div> that contains other clickable objects.
// This heuristic avoids excessive disambiguation in that case.
WillBeHeapHashSet<RawPtrWillBeMember<Node>> blackList;
for (const auto& hitResult : hitResults) {
// Ignore any Nodes that can't be clicked on.
LayoutObject* layoutObject = hitResult.get()->layoutObject();
if (!layoutObject || !hitResult.get()->willRespondToMouseClickEvents())
continue;
// Blacklist all of the Node's containers.
for (LayoutBlock* container = layoutObject->containingBlock(); container; container = container->containingBlock()) {
Node* containerNode = container->node();
if (!containerNode)
continue;
if (!blackList.add(containerNode).isNewEntry)
break;
}
}
WillBeHeapHashMap<RawPtrWillBeMember<Node>, TouchTargetData> touchTargets;
float bestScore = 0;
for (const auto& hitResult : hitResults) {
for (Node* node = hitResult.get(); node; node = node->parentNode()) {
if (blackList.contains(node))
continue;
if (node->isDocumentNode() || isHTMLHtmlElement(*node) || isHTMLBodyElement(*node))
break;
if (node->willRespondToMouseClickEvents()) {
TouchTargetData& targetData = touchTargets.add(node, TouchTargetData()).storedValue->value;
targetData.windowBoundingBox = boundingBoxForEventNodes(node);
targetData.score = scoreTouchTarget(touchPoint, touchPointPadding, targetData.windowBoundingBox);
bestScore = std::max(bestScore, targetData.score);
break;
}
}
}
for (const auto& touchTarget : touchTargets) {
// Currently the scoring function uses the overlap area with the fat point as the score.
// We ignore the candidates that has less than 1/2 overlap (we consider not really ambiguous enough) than the best candidate to avoid excessive popups.
if (touchTarget.value.score < bestScore * 0.5)
continue;
goodTargets.append(touchTarget.value.windowBoundingBox);
highlightNodes.append(touchTarget.key);
}
}
示例5: caretLayoutObject
IntRect CaretBase::absoluteBoundsForLocalRect(Node* node, const LayoutRect& rect) const
{
LayoutBlock* caretPainter = caretLayoutObject(node);
if (!caretPainter)
return IntRect();
LayoutRect localRect(rect);
caretPainter->flipForWritingMode(localRect);
return caretPainter->localToAbsoluteQuad(FloatRect(localRect)).enclosingBoundingBox();
}
示例6: createPositionWithAffinity
PositionWithAffinity LayoutSVGInlineText::positionForPoint(const LayoutPoint& point)
{
if (!firstTextBox() || !textLength())
return createPositionWithAffinity(0, DOWNSTREAM);
ASSERT(m_scalingFactor);
float baseline = m_scaledFont.fontMetrics().floatAscent() / m_scalingFactor;
LayoutBlock* containingBlock = this->containingBlock();
ASSERT(containingBlock);
// Map local point to absolute point, as the character origins stored in the text fragments use absolute coordinates.
FloatPoint absolutePoint(point);
absolutePoint.moveBy(containingBlock->location());
float closestDistance = std::numeric_limits<float>::max();
float closestDistancePosition = 0;
const SVGTextFragment* closestDistanceFragment = 0;
SVGInlineTextBox* closestDistanceBox = 0;
AffineTransform fragmentTransform;
for (InlineTextBox* box = firstTextBox(); box; box = box->nextTextBox()) {
if (!box->isSVGInlineTextBox())
continue;
SVGInlineTextBox* textBox = toSVGInlineTextBox(box);
Vector<SVGTextFragment>& fragments = textBox->textFragments();
unsigned textFragmentsSize = fragments.size();
for (unsigned i = 0; i < textFragmentsSize; ++i) {
const SVGTextFragment& fragment = fragments.at(i);
FloatRect fragmentRect(fragment.x, fragment.y - baseline, fragment.width, fragment.height);
fragment.buildFragmentTransform(fragmentTransform);
if (!fragmentTransform.isIdentity())
fragmentRect = fragmentTransform.mapRect(fragmentRect);
float distance = 0;
if (!fragmentRect.contains(absolutePoint))
distance = squaredDistanceToClosestPoint(fragmentRect, absolutePoint);
if (distance <= closestDistance) {
closestDistance = distance;
closestDistanceBox = textBox;
closestDistanceFragment = &fragment;
closestDistancePosition = fragmentRect.x();
}
}
}
if (!closestDistanceFragment)
return createPositionWithAffinity(0, DOWNSTREAM);
int offset = closestDistanceBox->offsetForPositionInFragment(*closestDistanceFragment, absolutePoint.x() - closestDistancePosition, true);
return createPositionWithAffinity(offset + closestDistanceBox->start(), offset > 0 ? VP_UPSTREAM_IF_POSSIBLE : DOWNSTREAM);
}
示例7: ASSERT
void LayoutRubyRun::addChild(LayoutObject* child, LayoutObject* beforeChild)
{
ASSERT(child);
if (child->isRubyText()) {
if (!beforeChild) {
// LayoutRuby has already ascertained that we can add the child here.
ASSERT(!hasRubyText());
// prepend ruby texts as first child
LayoutBlockFlow::addChild(child, firstChild());
} else if (beforeChild->isRubyText()) {
// New text is inserted just before another.
// In this case the new text takes the place of the old one, and
// the old text goes into a new run that is inserted as next sibling.
ASSERT(beforeChild->parent() == this);
LayoutObject* ruby = parent();
ASSERT(ruby->isRuby());
LayoutBlock* newRun = staticCreateRubyRun(ruby);
ruby->addChild(newRun, nextSibling());
// Add the new ruby text and move the old one to the new run
// Note: Doing it in this order and not using LayoutRubyRun's methods,
// in order to avoid automatic removal of the ruby run in case there is no
// other child besides the old ruby text.
LayoutBlockFlow::addChild(child, beforeChild);
LayoutBlockFlow::removeChild(beforeChild);
newRun->addChild(beforeChild);
} else if (hasRubyBase()) {
// Insertion before a ruby base object.
// In this case we need insert a new run before the current one and split the base.
LayoutObject* ruby = parent();
LayoutRubyRun* newRun = staticCreateRubyRun(ruby);
ruby->addChild(newRun, this);
newRun->addChild(child);
// Make sure we don't leave anything in the percentage descendant
// map before moving the children to the new base.
if (hasPercentHeightDescendants())
clearPercentHeightDescendants();
rubyBaseSafe()->moveChildren(newRun->rubyBaseSafe(), beforeChild);
}
} else {
// child is not a text -> insert it into the base
// (append it instead if beforeChild is the ruby text)
LayoutRubyBase* base = rubyBaseSafe();
if (beforeChild == base)
beforeChild = base->firstChild();
if (beforeChild && beforeChild->isRubyText())
beforeChild = 0;
ASSERT(!beforeChild || beforeChild->isDescendantOf(base));
base->addChild(child, beforeChild);
}
}
示例8: TEST_F
TEST_F(LayoutObjectTest, PaintingLayerOfOverflowClipLayerUnderColumnSpanAll) {
setBodyInnerHTML(
"<div id='columns' style='columns: 3'>"
" <div style='column-span: all'>"
" <div id='overflow-clip-layer' style='height: 100px; overflow: "
"hidden'></div>"
" </div>"
"</div>");
LayoutObject* overflowClipObject =
getLayoutObjectByElementId("overflow-clip-layer");
LayoutBlock* columns = toLayoutBlock(getLayoutObjectByElementId("columns"));
EXPECT_EQ(columns->layer(), overflowClipObject->paintingLayer());
}
示例9: TEST_F
TEST_F(LayoutObjectTest, MapToVisibleRectInContainerSpace)
{
setBodyInnerHTML(
"<div id='container' style='overflow: scroll; will-change: transform; width: 50px; height: 50px'>"
" <span><img style='width: 20px; height: 100px'></span>"
" text text text text text text text"
"</div>");
LayoutBlock* container = toLayoutBlock(document().getElementById("container")->layoutObject());
LayoutText* text = toLayoutText(container->lastChild());
container->setScrollTop(50);
LayoutRect rect(0, 60, 20, 20);
text->mapToVisibleRectInAncestorSpace(container, rect, nullptr);
EXPECT_TRUE(rect == LayoutRect(0, 10, 20, 20));
}
示例10: toLayoutInline
void BlockPainter::paintContinuationOutlines(const PaintInfo& info, const LayoutPoint& paintOffset)
{
LayoutInline* inlineCont = m_layoutBlock.inlineElementContinuation();
if (inlineCont && inlineCont->style()->hasOutline() && inlineCont->style()->visibility() == VISIBLE) {
LayoutInline* inlineLayoutObject = toLayoutInline(inlineCont->node()->layoutObject());
LayoutBlock* cb = m_layoutBlock.containingBlock();
bool inlineEnclosedInSelfPaintingLayer = false;
for (LayoutBoxModelObject* box = inlineLayoutObject; box != cb; box = box->parent()->enclosingBoxModelObject()) {
if (box->hasSelfPaintingLayer()) {
inlineEnclosedInSelfPaintingLayer = true;
break;
}
}
// Do not add continuations for outline painting by our containing block if we are a relative positioned
// anonymous block (i.e. have our own layer), paint them straightaway instead. This is because a block depends on layoutObjects in its continuation table being
// in the same layer.
if (!inlineEnclosedInSelfPaintingLayer && !m_layoutBlock.hasLayer()) {
cb->addContinuationWithOutline(inlineLayoutObject);
} else if (!inlineLayoutObject->firstLineBox() || (!inlineEnclosedInSelfPaintingLayer && m_layoutBlock.hasLayer())) {
// The outline might be painted multiple times if multiple blocks have the same inline element continuation, and the inline has a self-painting layer.
ScopeRecorder scopeRecorder(*info.context);
InlinePainter(*inlineLayoutObject).paintOutline(info, paintOffset - m_layoutBlock.locationOffset() + inlineLayoutObject->containingBlock()->location());
}
}
ContinuationOutlineTableMap* table = continuationOutlineTable();
if (table->isEmpty())
return;
OwnPtr<ListHashSet<LayoutInline*>> continuations = table->take(&m_layoutBlock);
if (!continuations)
return;
LayoutPoint accumulatedPaintOffset = paintOffset;
// Paint each continuation outline.
ListHashSet<LayoutInline*>::iterator end = continuations->end();
for (ListHashSet<LayoutInline*>::iterator it = continuations->begin(); it != end; ++it) {
// Need to add in the coordinates of the intervening blocks.
LayoutInline* flow = *it;
LayoutBlock* block = flow->containingBlock();
for ( ; block && block != &m_layoutBlock; block = block->containingBlock())
accumulatedPaintOffset.moveBy(block->location());
ASSERT(block);
InlinePainter(*flow).paintOutline(info, accumulatedPaintOffset);
}
}
示例11: isIndependentDescendant
static bool isIndependentDescendant(const LayoutBlock* layoutObject)
{
ASSERT(isPotentialClusterRoot(layoutObject));
LayoutBlock* containingBlock = layoutObject->containingBlock();
return layoutObject->isLayoutView()
|| layoutObject->isFloating()
|| layoutObject->isOutOfFlowPositioned()
|| layoutObject->isTableCell()
|| layoutObject->isTableCaption()
|| layoutObject->isFlexibleBoxIncludingDeprecated()
|| (containingBlock && containingBlock->isHorizontalWritingMode() != layoutObject->isHorizontalWritingMode())
|| layoutObject->style()->isDisplayReplacedType()
|| layoutObject->isTextArea()
|| layoutObject->style()->userModify() != READ_ONLY;
}
示例12: createPositionWithAffinity
PositionWithAffinity LayoutSVGInlineText::positionForPoint(const LayoutPoint& point)
{
if (!hasTextBoxes() || !textLength())
return createPositionWithAffinity(0);
ASSERT(m_scalingFactor);
float baseline = m_scaledFont.getFontMetrics().floatAscent() / m_scalingFactor;
LayoutBlock* containingBlock = this->containingBlock();
ASSERT(containingBlock);
// Map local point to absolute point, as the character origins stored in the text fragments use absolute coordinates.
FloatPoint absolutePoint(point);
absolutePoint.moveBy(containingBlock->location());
float closestDistance = std::numeric_limits<float>::max();
float closestDistancePosition = 0;
const SVGTextFragment* closestDistanceFragment = nullptr;
SVGInlineTextBox* closestDistanceBox = nullptr;
for (InlineTextBox* box = firstTextBox(); box; box = box->nextTextBox()) {
if (!box->isSVGInlineTextBox())
continue;
SVGInlineTextBox* textBox = toSVGInlineTextBox(box);
for (const SVGTextFragment& fragment : textBox->textFragments()) {
FloatRect fragmentRect = fragment.boundingBox(baseline);
float distance = 0;
if (!fragmentRect.contains(absolutePoint))
distance = fragmentRect.squaredDistanceTo(absolutePoint);
if (distance <= closestDistance) {
closestDistance = distance;
closestDistanceBox = textBox;
closestDistanceFragment = &fragment;
closestDistancePosition = fragmentRect.x();
}
}
}
if (!closestDistanceFragment)
return createPositionWithAffinity(0);
int offset = closestDistanceBox->offsetForPositionInFragment(*closestDistanceFragment, LayoutUnit(absolutePoint.x() - closestDistancePosition), true);
return createPositionWithAffinity(offset + closestDistanceBox->start(), offset > 0 ? VP_UPSTREAM_IF_POSSIBLE : TextAffinity::Downstream);
}
示例13: visualOverflowRectWithPaintOffset
static inline LayoutRect visualOverflowRectWithPaintOffset(const LayoutBlock& layoutBox, const LayoutPoint& paintOffset)
{
if (!RuntimeEnabledFeatures::slimmingPaintEnabled())
return LayoutRect();
LayoutRect bounds = layoutBox.visualOverflowRect();
bounds.moveBy(paintOffset);
return bounds;
}
示例14: innerEditorElement
void LayoutTextControl::styleDidChange(StyleDifference diff, const ComputedStyle* oldStyle)
{
LayoutBlockFlow::styleDidChange(diff, oldStyle);
Element* innerEditor = innerEditorElement();
if (!innerEditor)
return;
LayoutBlock* innerEditorLayoutObject = toLayoutBlock(innerEditor->layoutObject());
if (innerEditorLayoutObject) {
// We may have set the width and the height in the old style in layout().
// Reset them now to avoid getting a spurious layout hint.
innerEditorLayoutObject->mutableStyleRef().setHeight(Length());
innerEditorLayoutObject->mutableStyleRef().setWidth(Length());
innerEditorLayoutObject->setStyle(createInnerEditorStyle(styleRef()));
innerEditor->setNeedsStyleRecalc(SubtreeStyleChange, StyleChangeReasonForTracing::create(StyleChangeReason::Control));
}
textFormControlElement()->updatePlaceholderVisibility(false);
}
示例15: multiColumnBlockFlow
void LayoutMultiColumnFlowThread::calculateColumnCountAndWidth(LayoutUnit& width, unsigned& count) const
{
LayoutBlock* columnBlock = multiColumnBlockFlow();
const ComputedStyle* columnStyle = columnBlock->style();
LayoutUnit availableWidth = columnBlock->contentLogicalWidth();
LayoutUnit columnGap = columnBlock->columnGap();
LayoutUnit computedColumnWidth = max<LayoutUnit>(1, LayoutUnit(columnStyle->columnWidth()));
unsigned computedColumnCount = max<int>(1, columnStyle->columnCount());
ASSERT(!columnStyle->hasAutoColumnCount() || !columnStyle->hasAutoColumnWidth());
if (columnStyle->hasAutoColumnWidth() && !columnStyle->hasAutoColumnCount()) {
count = computedColumnCount;
width = std::max<LayoutUnit>(0, (availableWidth - ((count - 1) * columnGap)) / count);
} else if (!columnStyle->hasAutoColumnWidth() && columnStyle->hasAutoColumnCount()) {
count = std::max<LayoutUnit>(1, (availableWidth + columnGap) / (computedColumnWidth + columnGap));
width = ((availableWidth + columnGap) / count) - columnGap;
} else {
count = std::max<LayoutUnit>(std::min<LayoutUnit>(computedColumnCount, (availableWidth + columnGap) / (computedColumnWidth + columnGap)), 1);
width = ((availableWidth + columnGap) / count) - columnGap;
}
}