Changeset 250837 in webkit


Ignore:
Timestamp:
Oct 8, 2019 10:26:30 AM (5 years ago)
Author:
Alan Bujtas
Message:

[LFC][Painting] Add very basic block and inline painting
https://bugs.webkit.org/show_bug.cgi?id=202697
<rdar://problem/56076562>

Reviewed by Antti Koivisto.

This is a very basic border/background painting with simple text. No phases/z-index/layers of any kind.

  • layout/displaytree/DisplayBox.h: This seems to be getting out of hand.

(WebCore::Display::Box::moveBy):

  • layout/displaytree/DisplayPainter.cpp:

(WebCore::Display::paintBlockLevelBoxDecoration):
(WebCore::Display::paintInlineContent):
(WebCore::Display::Painter::paint):

  • layout/floats/FloatingContext.h:
  • layout/inlineformatting/InlineFormattingState.h:

(WebCore::Layout::InlineFormattingState::inlineRuns const):
(WebCore::Layout::InlineFormattingState::lineBoxes const):

Location:
trunk/Source/WebCore
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r250831 r250837  
     12019-10-08  Zalan Bujtas  <zalan@apple.com>
     2
     3        [LFC][Painting] Add very basic block and inline painting
     4        https://bugs.webkit.org/show_bug.cgi?id=202697
     5        <rdar://problem/56076562>
     6
     7        Reviewed by Antti Koivisto.
     8
     9        This is a very basic border/background painting with simple text. No phases/z-index/layers of any kind.
     10
     11        * layout/displaytree/DisplayBox.h: This seems to be getting out of hand.
     12        (WebCore::Display::Box::moveBy):
     13        * layout/displaytree/DisplayPainter.cpp:
     14        (WebCore::Display::paintBlockLevelBoxDecoration):
     15        (WebCore::Display::paintInlineContent):
     16        (WebCore::Display::Painter::paint):
     17        * layout/floats/FloatingContext.h:
     18        * layout/inlineformatting/InlineFormattingState.h:
     19        (WebCore::Layout::InlineFormattingState::inlineRuns const):
     20        (WebCore::Layout::InlineFormattingState::lineBoxes const):
     21
    1222019-10-08  Wenson Hsieh  <wenson_hsieh@apple.com>
    223
  • trunk/Source/WebCore/layout/displaytree/DisplayBox.h

    r250128 r250837  
    3737class RenderStyle;
    3838
    39 namespace Layout {
    40 class BlockFormattingContext;
    41 class FloatAvoider;
    42 class FloatBox;
    43 class FormattingContext;
    44 class FloatingContext;
    45 class InlineFormattingContext;
    46 class LayoutContext;
    47 class LayoutState;
    48 class TableFormattingContext;
    49 }
    50 
    5139namespace Display {
    5240
     
    5442    WTF_MAKE_ISO_ALLOCATED(Box);
    5543public:
    56     friend class Layout::BlockFormattingContext;
    57     friend class Layout::FloatAvoider;
    58     friend class Layout::FloatBox;
    59     friend class Layout::FormattingContext;
    60     friend class Layout::FloatingContext;
    61     friend class Layout::InlineFormattingContext;
    62     // This is temporary and should be removed when LayoutContext::run is no longer needed.
    63     friend class Layout::LayoutContext;
    64     friend class Layout::LayoutState;
    65     friend class Layout::TableFormattingContext;
    66 
    6744    Box(const RenderStyle&);
    6845    Box(const Box&);
     
    143120#endif
    144121
    145 private:
    146     struct Style {
    147         Style(const RenderStyle&);
    148 
    149         BoxSizing boxSizing { BoxSizing::ContentBox };
    150     };
    151 
    152122    void setTopLeft(const LayoutPoint&);
    153123    void setTop(LayoutUnit);
     
    155125    void moveHorizontally(LayoutUnit offset) { m_topLeft.move(offset, 0_lu); }
    156126    void moveVertically(LayoutUnit offset) { m_topLeft.move(0_lu, offset); }
     127    void moveBy(LayoutPoint offset) { m_topLeft.moveBy(offset); }
    157128
    158129    void setContentBoxHeight(LayoutUnit);
     
    166137    void setBorder(Layout::Edges);
    167138    void setPadding(Optional<Layout::Edges>);
     139
     140private:
     141    struct Style {
     142        Style(const RenderStyle&);
     143
     144        BoxSizing boxSizing { BoxSizing::ContentBox };
     145    };
    168146
    169147#if !ASSERT_DISABLED
  • trunk/Source/WebCore/layout/displaytree/DisplayPainter.cpp

    r250769 r250837  
    2929#if ENABLE(LAYOUT_FORMATTING_CONTEXT)
    3030
     31#include "Color.h"
     32#include "DisplayBox.h"
    3133#include "GraphicsContext.h"
     34#include "InlineFormattingState.h"
     35#include "LayoutContainer.h"
     36#include "LayoutDescendantIterator.h"
    3237#include "LayoutState.h"
     38#include "RenderStyle.h"
     39#include "TextRun.h"
    3340
    3441namespace WebCore {
    3542namespace Display {
    3643
    37 void Painter::paint(const Layout::LayoutState&, GraphicsContext&)
     44static void paintBlockLevelBoxDecoration(GraphicsContext& context, const Box& absoluteDisplayBox, const RenderStyle& style)
    3845{
     46    auto borderBoxAbsoluteTopLeft = absoluteDisplayBox.topLeft();
     47    // Background color
     48    if (style.hasBackground())
     49        context.fillRect({ borderBoxAbsoluteTopLeft, FloatSize { absoluteDisplayBox.borderBoxWidth(), absoluteDisplayBox.borderBoxHeight() } }, style.backgroundColor());
     50
     51    // Border
     52    if (style.hasBorder()) {
     53
     54        auto drawBorderSide = [&](auto start, auto end, const auto& borderStyle) {
     55            context.setStrokeColor(borderStyle.color());
     56            context.setStrokeThickness(borderStyle.width());
     57            context.drawLine(start, end);
     58        };
     59
     60        context.setFillColor(Color::transparent);
     61
     62        auto borderBoxWidth = absoluteDisplayBox.borderBoxWidth();
     63        auto borderBoxHeight = absoluteDisplayBox.borderBoxHeight();
     64
     65        // Top
     66        {
     67            auto borderWidth = style.borderTop().width();
     68            auto start = LayoutPoint { borderBoxAbsoluteTopLeft };
     69            auto end = LayoutPoint { start.x() + borderBoxWidth, start.y() + borderWidth };
     70            drawBorderSide(start, end, style.borderTop());
     71        }
     72
     73        // Right
     74        {
     75            auto borderWidth = style.borderRight().width();
     76            auto start = LayoutPoint { borderBoxAbsoluteTopLeft.x() + borderBoxWidth - borderWidth, borderBoxAbsoluteTopLeft.y() };
     77            auto end = LayoutPoint { start.x() + borderWidth, borderBoxAbsoluteTopLeft.y() + borderBoxHeight };
     78            drawBorderSide(start, end, style.borderRight());
     79        }
     80
     81        // Bottom
     82        {
     83            auto borderWidth = style.borderBottom().width();
     84            auto start = LayoutPoint { borderBoxAbsoluteTopLeft.x(), borderBoxAbsoluteTopLeft.y() + borderBoxHeight - borderWidth };
     85            auto end = LayoutPoint { start.x() + borderBoxWidth, start.y() + borderWidth };
     86            drawBorderSide(start, end, style.borderBottom());
     87        }
     88
     89        // Left
     90        {
     91            auto borderWidth = style.borderLeft().width();
     92            auto start = borderBoxAbsoluteTopLeft;
     93            auto end = LayoutPoint { start.x() + borderWidth, borderBoxAbsoluteTopLeft.y() + borderBoxHeight };
     94            drawBorderSide(start, end, style.borderLeft());
     95        }
     96    }
     97}
     98
     99static void paintInlineContent(GraphicsContext& context, const Box& absoluteDisplayBox, const RenderStyle& style, const String& content, const Layout::InlineFormattingState& formattingState)
     100{
     101    // FIXME: Only very simple text painting for now.
     102    auto& lineBox = formattingState.lineBoxes()[0];
     103    for (auto& run : formattingState.inlineRuns()) {
     104        if (!run.textContext())
     105            continue;
     106        context.setStrokeColor(style.color());
     107        context.setFillColor(style.color());
     108        auto logicalTopLeft = absoluteDisplayBox.topLeft() + run.logicalTopLeft();
     109        auto textContext = run.textContext().value();
     110        auto runContent = content.substring(textContext.start(), textContext.length());
     111        context.drawText(style.fontCascade(), TextRun { runContent }, { logicalTopLeft.x(), logicalTopLeft.y() + lineBox.baselineOffset() });
     112    }
     113}
     114
     115void Painter::paint(const Layout::LayoutState& layoutState, GraphicsContext& context)
     116{
     117    auto absoluteDisplayBox = [&](const auto& layoutBox) {
     118        auto absoluteBox = Box { layoutState.displayBoxForLayoutBox(layoutBox) };
     119        for (auto* container = layoutBox.containingBlock(); container != &layoutBox.initialContainingBlock(); container = container->containingBlock())
     120            absoluteBox.moveBy(layoutState.displayBoxForLayoutBox(*container).topLeft());
     121        return absoluteBox;
     122    };
     123
     124    auto& layoutRoot = layoutState.root();
     125    auto& rootDisplayBox = layoutState.displayBoxForLayoutBox(layoutRoot);
     126    context.fillRect({ FloatPoint { }, FloatSize { rootDisplayBox.borderBoxWidth(), rootDisplayBox.borderBoxHeight() } }, Color::white);
     127
     128    for (auto& layoutBox : Layout::descendantsOfType<Layout::Box>(layoutRoot)) {
     129        if (layoutBox.isBlockLevelBox()) {
     130            paintBlockLevelBoxDecoration(context, absoluteDisplayBox(layoutBox), layoutBox.style());
     131            continue;
     132        }
     133        // FIXME: This only covers the most simple cases like <div>inline content</div>
     134        // Find a way to conect inline runs and the inline content.
     135        if (layoutBox.isInlineLevelBox() && layoutBox.isAnonymous()) {
     136            ASSERT(layoutBox.hasTextContent());
     137            auto& containingBlock = *layoutBox.containingBlock();
     138            auto& inlineFormattingState = downcast<Layout::InlineFormattingState>(layoutState.establishedFormattingState(containingBlock));
     139            paintInlineContent(context, absoluteDisplayBox(containingBlock), layoutBox.style(), layoutBox.textContent(), inlineFormattingState);
     140
     141        }
     142    }
    39143}
    40144
  • trunk/Source/WebCore/layout/floats/FloatingContext.h

    r250766 r250837  
    3636
    3737class FloatAvoider;
     38class FloatBox;
    3839class FormattingContext;
    3940class Box;
  • trunk/Source/WebCore/layout/inlineformatting/InlineFormattingState.h

    r250490 r250837  
    5353    void addInlineItem(std::unique_ptr<InlineItem>&& inlineItem) { m_inlineItems.append(WTFMove(inlineItem)); }
    5454
     55    const InlineRuns& inlineRuns() const { return m_inlineRuns; }
    5556    InlineRuns& inlineRuns() { return m_inlineRuns; }
    5657    void addInlineRun(const Display::Run& inlineRun) { m_inlineRuns.append(inlineRun); }
    5758
     59    const LineBoxes& lineBoxes() const { return m_lineBoxes; }
    5860    LineBoxes& lineBoxes() { return m_lineBoxes; }
    5961    void addLineBox(LineBox lineBox) { m_lineBoxes.append(lineBox); }
Note: See TracChangeset for help on using the changeset viewer.