Move parseFontFaceDescriptor to CSSPropertyParser.cpp
[chromium-blink-merge.git] / third_party / WebKit / Source / core / paint / MultiColumnSetPainter.cpp
blob6d1c917e1ee4757c24b4cd8576a86f6b23af5bbb
1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "config.h"
6 #include "core/paint/MultiColumnSetPainter.h"
8 #include "core/layout/LayoutMultiColumnSet.h"
9 #include "core/paint/BlockPainter.h"
10 #include "core/paint/BoxPainter.h"
11 #include "core/paint/LayoutObjectDrawingRecorder.h"
12 #include "core/paint/PaintInfo.h"
13 #include "platform/geometry/LayoutPoint.h"
15 namespace blink {
17 void MultiColumnSetPainter::paintObject(const PaintInfo& paintInfo, const LayoutPoint& paintOffset)
19 if (m_layoutMultiColumnSet.style()->visibility() != VISIBLE)
20 return;
22 BlockPainter(m_layoutMultiColumnSet).paintObject(paintInfo, paintOffset);
24 // FIXME: Right now we're only painting in the foreground phase.
25 // Columns should technically respect phases and allow for background/float/foreground overlap etc., just like
26 // LayoutBlocks do. Note this is a pretty minor issue, since the old column implementation clipped columns
27 // anyway, thus making it impossible for them to overlap one another. It's also really unlikely that the columns
28 // would overlap another block.
29 if (!m_layoutMultiColumnSet.flowThread() || (paintInfo.phase != PaintPhaseForeground && paintInfo.phase != PaintPhaseSelection))
30 return;
32 paintColumnRules(paintInfo, paintOffset);
35 void MultiColumnSetPainter::paintColumnRules(const PaintInfo& paintInfo, const LayoutPoint& paintOffset)
37 if (m_layoutMultiColumnSet.flowThread()->isLayoutPagedFlowThread())
38 return;
40 const ComputedStyle& blockStyle = m_layoutMultiColumnSet.multiColumnBlockFlow()->styleRef();
41 const Color& ruleColor = m_layoutMultiColumnSet.resolveColor(blockStyle, CSSPropertyWebkitColumnRuleColor);
42 bool ruleTransparent = blockStyle.columnRuleIsTransparent();
43 EBorderStyle ruleStyle = blockStyle.columnRuleStyle();
44 LayoutUnit ruleThickness = blockStyle.columnRuleWidth();
45 LayoutUnit colGap = m_layoutMultiColumnSet.columnGap();
46 bool renderRule = ruleStyle > BHIDDEN && !ruleTransparent;
47 if (!renderRule)
48 return;
50 unsigned colCount = m_layoutMultiColumnSet.actualColumnCount();
51 if (colCount <= 1)
52 return;
54 if (LayoutObjectDrawingRecorder::useCachedDrawingIfPossible(*paintInfo.context, m_layoutMultiColumnSet, DisplayItem::ColumnRules, paintOffset))
55 return;
57 LayoutRect paintRect = m_layoutMultiColumnSet.visualOverflowRect();
58 paintRect.moveBy(paintOffset);
59 LayoutObjectDrawingRecorder drawingRecorder(*paintInfo.context, m_layoutMultiColumnSet, DisplayItem::ColumnRules, paintRect, paintOffset);
61 bool leftToRight = m_layoutMultiColumnSet.style()->isLeftToRightDirection();
62 LayoutUnit currLogicalLeftOffset = leftToRight ? LayoutUnit() : m_layoutMultiColumnSet.contentLogicalWidth();
63 LayoutUnit ruleAdd = m_layoutMultiColumnSet.borderAndPaddingLogicalLeft();
64 LayoutUnit ruleLogicalLeft = leftToRight ? LayoutUnit() : m_layoutMultiColumnSet.contentLogicalWidth();
65 LayoutUnit inlineDirectionSize = m_layoutMultiColumnSet.pageLogicalWidth();
66 BoxSide boxSide = m_layoutMultiColumnSet.isHorizontalWritingMode()
67 ? leftToRight ? BSLeft : BSRight
68 : leftToRight ? BSTop : BSBottom;
70 for (unsigned i = 0; i < colCount; i++) {
71 // Move to the next position.
72 if (leftToRight) {
73 ruleLogicalLeft += inlineDirectionSize + colGap / 2;
74 currLogicalLeftOffset += inlineDirectionSize + colGap;
75 } else {
76 ruleLogicalLeft -= (inlineDirectionSize + colGap / 2);
77 currLogicalLeftOffset -= (inlineDirectionSize + colGap);
80 // Now paint the column rule.
81 if (i < colCount - 1) {
82 LayoutUnit ruleLeft = m_layoutMultiColumnSet.isHorizontalWritingMode() ? paintOffset.x() + ruleLogicalLeft - ruleThickness / 2 + ruleAdd : paintOffset.x() + m_layoutMultiColumnSet.borderLeft() + m_layoutMultiColumnSet.paddingLeft();
83 LayoutUnit ruleRight = m_layoutMultiColumnSet.isHorizontalWritingMode() ? ruleLeft + ruleThickness : ruleLeft + m_layoutMultiColumnSet.contentWidth();
84 LayoutUnit ruleTop = m_layoutMultiColumnSet.isHorizontalWritingMode() ? paintOffset.y() + m_layoutMultiColumnSet.borderTop() + m_layoutMultiColumnSet.paddingTop() : paintOffset.y() + ruleLogicalLeft - ruleThickness / 2 + ruleAdd;
85 LayoutUnit ruleBottom = m_layoutMultiColumnSet.isHorizontalWritingMode() ? ruleTop + m_layoutMultiColumnSet.contentHeight() : ruleTop + ruleThickness;
86 IntRect pixelSnappedRuleRect = pixelSnappedIntRectFromEdges(ruleLeft, ruleTop, ruleRight, ruleBottom);
87 ObjectPainter::drawLineForBoxSide(paintInfo.context, pixelSnappedRuleRect.x(), pixelSnappedRuleRect.y(), pixelSnappedRuleRect.maxX(), pixelSnappedRuleRect.maxY(), boxSide, ruleColor, ruleStyle, 0, 0, true);
90 ruleLogicalLeft = currLogicalLeftOffset;
94 } // namespace blink