Teach sky.Paragraph how to actually compute layout

Previously layout was exiting early because the frame view
was null. Now we actually compute some layout and paint the
text. This patch makes paragraph_builder_test pass.
This commit is contained in:
Adam Barth
2015-09-17 00:26:19 -07:00
parent 7e9abfa288
commit 77264d3e94
13 changed files with 110 additions and 41 deletions
+4 -4
View File
@@ -130,12 +130,12 @@ CPP_SPECIAL_CONVERSION_RULES = {
'FilterQuality': 'SkFilterQuality',
'PaintingStyle': 'SkPaint::Style',
# TODO(abarth): Give these better C++ types.
'FontStyle': 'int',
'FontWeight': 'int',
'FontStyle': 'FontStyle',
'FontWeight': 'FontWeight',
'TextAlign': 'int',
'TextBaseline': 'int',
'TextDecoration': 'int',
'TextDecorationStyle': 'int',
'TextDecoration': 'TextDecoration',
'TextDecorationStyle': 'TextDecorationStyle',
}
+1
View File
@@ -610,6 +610,7 @@ sky_core_files = [
"text/ParagraphStyle.h",
"text/TextAlign.h",
"text/TextBaseline.h",
"text/TextDecoration.cpp",
"text/TextDecoration.h",
"text/TextDecorationStyle.h",
"text/TextStyle.cpp",
+3 -8
View File
@@ -106,13 +106,12 @@ bool RenderView::hitTest(const HitTestRequest& request, const HitTestLocation& l
void RenderView::computeLogicalHeight(LayoutUnit logicalHeight, LayoutUnit, LogicalExtentComputedValues& computedValues) const
{
computedValues.m_extent = m_frameView ? LayoutUnit(viewLogicalHeight()) : logicalHeight;
computedValues.m_extent = logicalHeight;
}
void RenderView::updateLogicalWidth()
{
if (m_frameView)
setLogicalWidth(viewLogicalWidth());
setLogicalWidth(viewLogicalWidth());
}
bool RenderView::isChildAllowed(RenderObject* child, RenderStyle*) const
@@ -124,7 +123,7 @@ void RenderView::layout()
{
SubtreeLayoutScope layoutScope(*this);
bool relayoutChildren = (!m_frameView || width() != viewWidth() || height() != viewHeight());
bool relayoutChildren = width() != viewWidth() || height() != viewHeight();
if (relayoutChildren) {
layoutScope.setChildNeedsLayout(this);
for (RenderObject* child = firstChild(); child; child = child->nextSibling()) {
@@ -354,15 +353,11 @@ IntRect RenderView::documentRect() const
int RenderView::viewHeight() const
{
if (m_frameView)
return m_frameView->layoutSize().height();
return m_frameViewSize.height();
}
int RenderView::viewWidth() const
{
if (m_frameView)
return m_frameView->layoutSize().width();
return m_frameViewSize.width();
}
-3
View File
@@ -11,7 +11,4 @@ enum FontStyle {
/// Use glyphs designed for slanting
italic,
/// Use the upright glyphs but slant them during painting
oblique // TODO(abarth): Remove. We don't really support this value.
}
+1 -1
View File
@@ -12,7 +12,7 @@ namespace blink {
template <>
struct DartConverter<FontStyle>
: public DartConverterEnum<int> {};
: public DartConverterEnum<FontStyle> {};
} // namespace blink
+1 -1
View File
@@ -12,7 +12,7 @@ namespace blink {
template <>
struct DartConverter<FontWeight>
: public DartConverterEnum<int> {};
: public DartConverterEnum<FontWeight> {};
} // namespace blink
+17 -9
View File
@@ -4,7 +4,9 @@
#include "sky/engine/core/text/ParagraphBuilder.h"
#include "sky/engine/core/rendering/PaintInfo.h"
#include "sky/engine/core/rendering/style/RenderStyle.h"
#include "sky/engine/platform/graphics/GraphicsContext.h"
namespace blink {
@@ -19,46 +21,52 @@ Paragraph::~Paragraph()
double Paragraph::width()
{
return m_renderView->firstChildBox()->width();
return firstChildBox()->width();
}
double Paragraph::height()
{
return m_renderView->firstChildBox()->height();
return firstChildBox()->height();
}
double Paragraph::minIntrinsicWidth()
{
return 0.0;
return firstChildBox()->minPreferredLogicalWidth();
}
double Paragraph::maxIntrinsicWidth()
{
return 0.0;
return firstChildBox()->maxPreferredLogicalWidth();
}
double Paragraph::alphabeticBaseline()
{
return 0.0;
return firstChildBox()->firstLineBoxBaseline(FontBaselineOrAuto(AlphabeticBaseline));
}
double Paragraph::ideographicBaseline()
{
return 0.0;
return firstChildBox()->firstLineBoxBaseline(FontBaselineOrAuto(IdeographicBaseline));
}
void Paragraph::layout()
{
LayoutUnit maxWidth = std::max(m_minWidth, m_maxWidth);
LayoutUnit maxHeight = std::max(m_minHeight, m_maxHeight);
IntSize maxSize(maxWidth, maxHeight);
m_renderView->setFrameViewSize(maxSize);
m_renderView->setFrameViewSize(IntSize(maxWidth, maxHeight));
m_renderView->layout();
}
void Paragraph::paint(Canvas* canvas, const Offset& offset)
{
// Very simplified painting to allow painting an arbitrary (layer-less) subtree.
GraphicsContext context(canvas->skCanvas());
Vector<RenderBox*> layers;
PaintInfo paintInfo(&context, m_renderView->absoluteBoundingBoxRect(), m_renderView.get());
LayoutPoint paintOffset(offset.sk_size.width(), offset.sk_size.height());
m_renderView->RenderBox::paint(paintInfo, paintOffset, layers);
// Note we're ignoring any layers encountered.
// TODO(abarth): Remove the concept of RenderLayers.
}
} // namespace blink
+2
View File
@@ -48,6 +48,8 @@ public:
RenderView* renderView() const { return m_renderView.get(); }
private:
RenderBox* firstChildBox() const { return m_renderView->firstChildBox(); }
LayoutUnit m_minWidth;
LayoutUnit m_maxWidth;
LayoutUnit m_minHeight;
+33
View File
@@ -0,0 +1,33 @@
// Copyright 2015 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "sky/engine/core/text/TextDecoration.h"
namespace blink {
static TextDecoration toTextDecoration(int index) {
switch (index) {
case 0: // none
return TextDecorationNone;
case 1: // underline
return TextDecorationUnderline;
case 2: // overline
return TextDecorationOverline;
case 3: // lineThrough
return TextDecorationLineThrough;
default:
return TextDecorationNone;
}
}
TextDecoration DartConverter<TextDecoration>::FromArguments(
Dart_NativeArguments args, int index, Dart_Handle& exception) {
return toTextDecoration(DartConverterEnum<int>::FromArguments(args, index, exception));
}
TextDecoration DartConverter<TextDecoration>::FromDart(Dart_Handle handle) {
return toTextDecoration(DartConverterEnum<int>::FromDart(handle));
}
} // namespace blink
+7 -2
View File
@@ -11,8 +11,13 @@
namespace blink {
template <>
struct DartConverter<TextDecoration>
: public DartConverterEnum<int> {};
struct DartConverter<TextDecoration> {
static TextDecoration FromArguments(Dart_NativeArguments args,
int index,
Dart_Handle& exception);
static TextDecoration FromDart(Dart_Handle handle);
};
} // namespace blink
+1 -1
View File
@@ -12,7 +12,7 @@ namespace blink {
template <>
struct DartConverter<TextDecorationStyle>
: public DartConverterEnum<int> {};
: public DartConverterEnum<TextDecorationStyle> {};
} // namespace blink
+14 -4
View File
@@ -10,12 +10,22 @@ TextStyle::TextStyle(
SkColor color,
const String& fontFamily,
double fontSize,
int fontWeight,
int fontStyle,
const Vector<int>& decoration,
FontWeight fontWeight,
FontStyle fontStyle,
const Vector<TextDecoration>& decoration,
SkColor decorationColor,
int decorationStyle)
TextDecorationStyle decorationStyle)
: m_color(color)
, m_fontFamily(fontFamily)
, m_fontSize(fontSize)
, m_fontWeight(fontWeight)
, m_fontStyle(fontStyle)
, m_decoration(TextDecorationNone)
, m_decorationColor(decorationColor)
, m_decorationStyle(decorationStyle)
{
for (const auto& d : decoration)
m_decoration |= d;
}
TextStyle::~TextStyle()
+26 -8
View File
@@ -24,11 +24,11 @@ public:
SkColor color = SK_ColorWHITE,
const String& fontFamily = nullAtom,
double fontSize = 0.0,
int fontWeight = 0,
int fontStyle = 0,
const Vector<int>& decoration = Vector<int>(),
FontWeight fontWeight = FontWeightNormal,
FontStyle fontStyle = FontStyleNormal,
const Vector<TextDecoration>& decoration = Vector<TextDecoration>(),
SkColor decorationColor = SK_ColorWHITE,
int decorationStyle = 0
TextDecorationStyle decorationStyle = TextDecorationStyleSolid
) {
return adoptRef(new TextStyle(
color,
@@ -44,17 +44,35 @@ public:
~TextStyle() override;
SkColor color() const { return m_color; }
const String& fontFamily() const { return m_fontFamily; }
double fontSize() const { return m_fontSize; }
FontWeight fontWeight() const { return m_fontWeight; }
FontStyle fontStyle() const { return m_fontStyle; }
TextDecoration decoration() const { return m_decoration; }
SkColor decorationColor() const { return m_decorationColor; }
TextDecorationStyle decorationStyle() const { return m_decorationStyle; }
private:
explicit TextStyle(
SkColor color,
const String& fontFamily,
double fontSize,
int fontWeight,
int fontStyle,
const Vector<int>& decoration,
FontWeight fontWeight,
FontStyle fontStyle,
const Vector<TextDecoration>& decoration,
SkColor decorationColor,
int decorationStyle
TextDecorationStyle decorationStyle
);
SkColor m_color;
String m_fontFamily;
double m_fontSize;
FontWeight m_fontWeight;
FontStyle m_fontStyle;
TextDecoration m_decoration;
SkColor m_decorationColor;
TextDecorationStyle m_decorationStyle;
};
} // namespace blink