Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(86)

Unified Diff: third_party/WebKit/Source/core/layout/svg/line/SVGRootInlineBox.cpp

Issue 2524113002: Fix SVG vertical text layout issues (Closed)
Patch Set: - Created 4 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: third_party/WebKit/Source/core/layout/svg/line/SVGRootInlineBox.cpp
diff --git a/third_party/WebKit/Source/core/layout/svg/line/SVGRootInlineBox.cpp b/third_party/WebKit/Source/core/layout/svg/line/SVGRootInlineBox.cpp
index 05b78e9f01f1f7e71473e89d33ef0718278edb20..dc9ce84caf51890504915a11995412655fbe20ad 100644
--- a/third_party/WebKit/Source/core/layout/svg/line/SVGRootInlineBox.cpp
+++ b/third_party/WebKit/Source/core/layout/svg/line/SVGRootInlineBox.cpp
@@ -69,67 +69,60 @@ void SVGRootInlineBox::computePerCharacterLayoutInformation() {
// Perform SVG text layout phase four
// Position & resize all SVGInlineText/FlowBoxes in the inline box tree,
// resize the root box as well as the LayoutSVGText parent block.
- LayoutRect childRect;
- layoutChildBoxes(this, &childRect);
- layoutRootBox(childRect);
+ LayoutRect childRect = layoutInlineBoxes(*this);
+
+ // Finally, assign the root block position, now that all content is laid out.
+ LineLayoutBlockFlow parentBlock = block();
+ parentBlock.setLocation(childRect.location());
+ parentBlock.setSize(childRect.size());
+
+ adjustInlineBoxesToBlockSpace(*this);
+
+ setLineTopBottomPositions(LayoutUnit(), logicalHeight(), LayoutUnit(),
+ logicalHeight());
}
-void SVGRootInlineBox::layoutChildBoxes(InlineFlowBox* start,
- LayoutRect* childRect) {
- for (InlineBox* child = start->firstChild(); child;
- child = child->nextOnLine()) {
- LayoutRect boxRect;
- if (child->isSVGInlineTextBox()) {
- ASSERT(child->getLineLayoutItem().isSVGInlineText());
-
- SVGInlineTextBox* textBox = toSVGInlineTextBox(child);
- boxRect = textBox->calculateBoundaries();
- textBox->setX(boxRect.x());
- textBox->setY(boxRect.y());
- textBox->setLogicalWidth(boxRect.width());
- textBox->setLogicalHeight(boxRect.height());
- } else {
- // Skip generated content.
- if (!child->getLineLayoutItem().node())
- continue;
-
- SVGInlineFlowBox* flowBox = toSVGInlineFlowBox(child);
- layoutChildBoxes(flowBox);
-
- boxRect = flowBox->calculateBoundaries();
- flowBox->setX(boxRect.x());
- flowBox->setY(boxRect.y());
- flowBox->setLogicalWidth(boxRect.width());
- flowBox->setLogicalHeight(boxRect.height());
- }
- if (childRect)
- childRect->unite(boxRect);
+LayoutRect SVGRootInlineBox::layoutInlineBoxes(InlineBox& box) {
+ LayoutRect rect;
+ if (box.isSVGInlineTextBox()) {
+ rect = toSVGInlineTextBox(box).calculateBoundaries();
+ } else {
+ for (InlineBox* child = toInlineFlowBox(box).firstChild(); child;
+ child = child->nextOnLine())
+ rect.unite(layoutInlineBoxes(*child));
}
+
+ box.setX(rect.x());
+ box.setY(rect.y());
+ box.setLogicalWidth(box.isHorizontal() ? rect.width() : rect.height());
+ LayoutUnit logicalHeight = box.isHorizontal() ? rect.height() : rect.width();
+ if (box.isSVGInlineTextBox())
+ toSVGInlineTextBox(box).setLogicalHeight(logicalHeight);
+ else if (box.isSVGInlineFlowBox())
+ toSVGInlineFlowBox(box).setLogicalHeight(logicalHeight);
+ else
+ toSVGRootInlineBox(box).setLogicalHeight(logicalHeight);
+
+ return rect;
}
-void SVGRootInlineBox::layoutRootBox(const LayoutRect& childRect) {
+void SVGRootInlineBox::adjustInlineBoxesToBlockSpace(InlineBox& box) {
LineLayoutBlockFlow parentBlock = block();
+ LayoutRect rect(box.topLeft(), box.size());
+ // In layoutChildBoxes(), the box was laid out in physical SVG coordinates.
+ rect.moveBy(-parentBlock.location());
+ // Convert physical coordinates into "physical coordinates in flipped block
+ // direction".
+ parentBlock.flipForWritingMode(rect);
+ box.setX(rect.x());
+ box.setY(rect.y());
+
+ if (!box.isInlineFlowBox())
+ return;
- // Finally, assign the root block position, now that all content is laid out.
- LayoutRect boundingRect = childRect;
- parentBlock.setLocation(boundingRect.location());
- parentBlock.setSize(boundingRect.size());
-
- // Position all children relative to the parent block.
- for (InlineBox* child = firstChild(); child; child = child->nextOnLine()) {
- // Skip generated content.
- if (!child->getLineLayoutItem().node())
- continue;
- child->move(LayoutSize(-childRect.x(), -childRect.y()));
- }
-
- // Position ourselves.
- setX(LayoutUnit());
- setY(LayoutUnit());
- setLogicalWidth(childRect.width());
- setLogicalHeight(childRect.height());
- setLineTopBottomPositions(LayoutUnit(), boundingRect.height(), LayoutUnit(),
- boundingRect.height());
+ for (InlineBox* child = toInlineFlowBox(box).firstChild(); child;
+ child = child->nextOnLine())
+ adjustInlineBoxesToBlockSpace(*child);
}
InlineBox* SVGRootInlineBox::closestLeafChildForPosition(

Powered by Google App Engine
This is Rietveld 408576698