Changeset 250837 in webkit
- Timestamp:
- Oct 8, 2019 10:26:30 AM (5 years ago)
- Location:
- trunk/Source/WebCore
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Source/WebCore/ChangeLog
r250831 r250837 1 2019-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 1 22 2019-10-08 Wenson Hsieh <wenson_hsieh@apple.com> 2 23 -
trunk/Source/WebCore/layout/displaytree/DisplayBox.h
r250128 r250837 37 37 class RenderStyle; 38 38 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 51 39 namespace Display { 52 40 … … 54 42 WTF_MAKE_ISO_ALLOCATED(Box); 55 43 public: 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 67 44 Box(const RenderStyle&); 68 45 Box(const Box&); … … 143 120 #endif 144 121 145 private:146 struct Style {147 Style(const RenderStyle&);148 149 BoxSizing boxSizing { BoxSizing::ContentBox };150 };151 152 122 void setTopLeft(const LayoutPoint&); 153 123 void setTop(LayoutUnit); … … 155 125 void moveHorizontally(LayoutUnit offset) { m_topLeft.move(offset, 0_lu); } 156 126 void moveVertically(LayoutUnit offset) { m_topLeft.move(0_lu, offset); } 127 void moveBy(LayoutPoint offset) { m_topLeft.moveBy(offset); } 157 128 158 129 void setContentBoxHeight(LayoutUnit); … … 166 137 void setBorder(Layout::Edges); 167 138 void setPadding(Optional<Layout::Edges>); 139 140 private: 141 struct Style { 142 Style(const RenderStyle&); 143 144 BoxSizing boxSizing { BoxSizing::ContentBox }; 145 }; 168 146 169 147 #if !ASSERT_DISABLED -
trunk/Source/WebCore/layout/displaytree/DisplayPainter.cpp
r250769 r250837 29 29 #if ENABLE(LAYOUT_FORMATTING_CONTEXT) 30 30 31 #include "Color.h" 32 #include "DisplayBox.h" 31 33 #include "GraphicsContext.h" 34 #include "InlineFormattingState.h" 35 #include "LayoutContainer.h" 36 #include "LayoutDescendantIterator.h" 32 37 #include "LayoutState.h" 38 #include "RenderStyle.h" 39 #include "TextRun.h" 33 40 34 41 namespace WebCore { 35 42 namespace Display { 36 43 37 void Painter::paint(const Layout::LayoutState&, GraphicsContext&)44 static void paintBlockLevelBoxDecoration(GraphicsContext& context, const Box& absoluteDisplayBox, const RenderStyle& style) 38 45 { 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 99 static 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 115 void 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 } 39 143 } 40 144 -
trunk/Source/WebCore/layout/floats/FloatingContext.h
r250766 r250837 36 36 37 37 class FloatAvoider; 38 class FloatBox; 38 39 class FormattingContext; 39 40 class Box; -
trunk/Source/WebCore/layout/inlineformatting/InlineFormattingState.h
r250490 r250837 53 53 void addInlineItem(std::unique_ptr<InlineItem>&& inlineItem) { m_inlineItems.append(WTFMove(inlineItem)); } 54 54 55 const InlineRuns& inlineRuns() const { return m_inlineRuns; } 55 56 InlineRuns& inlineRuns() { return m_inlineRuns; } 56 57 void addInlineRun(const Display::Run& inlineRun) { m_inlineRuns.append(inlineRun); } 57 58 59 const LineBoxes& lineBoxes() const { return m_lineBoxes; } 58 60 LineBoxes& lineBoxes() { return m_lineBoxes; } 59 61 void addLineBox(LineBox lineBox) { m_lineBoxes.append(lineBox); }
Note: See TracChangeset
for help on using the changeset viewer.