| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "config.h" | 5 #include "config.h" |
| 6 #include "core/paint/ListMarkerPainter.h" | 6 #include "core/paint/ListMarkerPainter.h" |
| 7 | 7 |
| 8 #include "core/layout/LayoutListItem.h" |
| 9 #include "core/layout/LayoutListMarker.h" |
| 8 #include "core/layout/PaintInfo.h" | 10 #include "core/layout/PaintInfo.h" |
| 9 #include "core/layout/TextRunConstructor.h" | 11 #include "core/layout/TextRunConstructor.h" |
| 10 #include "core/paint/BlockPainter.h" | 12 #include "core/paint/BlockPainter.h" |
| 11 #include "core/paint/GraphicsContextAnnotator.h" | 13 #include "core/paint/GraphicsContextAnnotator.h" |
| 12 #include "core/paint/RenderDrawingRecorder.h" | 14 #include "core/paint/RenderDrawingRecorder.h" |
| 13 #include "core/rendering/RenderListItem.h" | |
| 14 #include "core/rendering/RenderListMarker.h" | |
| 15 #include "platform/geometry/LayoutPoint.h" | 15 #include "platform/geometry/LayoutPoint.h" |
| 16 #include "platform/graphics/GraphicsContextStateSaver.h" | 16 #include "platform/graphics/GraphicsContextStateSaver.h" |
| 17 #include "wtf/unicode/CharacterNames.h" | 17 #include "wtf/unicode/CharacterNames.h" |
| 18 | 18 |
| 19 namespace blink { | 19 namespace blink { |
| 20 | 20 |
| 21 void ListMarkerPainter::paint(const PaintInfo& paintInfo, const LayoutPoint& pai
ntOffset) | 21 void ListMarkerPainter::paint(const PaintInfo& paintInfo, const LayoutPoint& pai
ntOffset) |
| 22 { | 22 { |
| 23 ANNOTATE_GRAPHICS_CONTEXT(paintInfo, &m_renderListMarker); | 23 ANNOTATE_GRAPHICS_CONTEXT(paintInfo, &m_layoutListMarker); |
| 24 | 24 |
| 25 if (paintInfo.phase != PaintPhaseForeground) | 25 if (paintInfo.phase != PaintPhaseForeground) |
| 26 return; | 26 return; |
| 27 | 27 |
| 28 if (m_renderListMarker.style()->visibility() != VISIBLE) | 28 if (m_layoutListMarker.style()->visibility() != VISIBLE) |
| 29 return; | 29 return; |
| 30 | 30 |
| 31 LayoutPoint boxOrigin(paintOffset + m_renderListMarker.location()); | 31 LayoutPoint boxOrigin(paintOffset + m_layoutListMarker.location()); |
| 32 LayoutRect overflowRect(m_renderListMarker.visualOverflowRect()); | 32 LayoutRect overflowRect(m_layoutListMarker.visualOverflowRect()); |
| 33 overflowRect.moveBy(boxOrigin); | 33 overflowRect.moveBy(boxOrigin); |
| 34 | 34 |
| 35 IntRect pixelSnappedOverflowRect = pixelSnappedIntRect(overflowRect); | 35 IntRect pixelSnappedOverflowRect = pixelSnappedIntRect(overflowRect); |
| 36 if (!paintInfo.rect.intersects(pixelSnappedOverflowRect)) | 36 if (!paintInfo.rect.intersects(pixelSnappedOverflowRect)) |
| 37 return; | 37 return; |
| 38 | 38 |
| 39 RenderDrawingRecorder recorder(paintInfo.context, m_renderListMarker, paintI
nfo.phase, pixelSnappedOverflowRect); | 39 RenderDrawingRecorder recorder(paintInfo.context, m_layoutListMarker, paintI
nfo.phase, pixelSnappedOverflowRect); |
| 40 if (recorder.canUseCachedDrawing()) | 40 if (recorder.canUseCachedDrawing()) |
| 41 return; | 41 return; |
| 42 | 42 |
| 43 LayoutRect box(boxOrigin, m_renderListMarker.size()); | 43 LayoutRect box(boxOrigin, m_layoutListMarker.size()); |
| 44 | 44 |
| 45 IntRect marker = m_renderListMarker.getRelativeMarkerRect(); | 45 IntRect marker = m_layoutListMarker.getRelativeMarkerRect(); |
| 46 marker.moveBy(roundedIntPoint(boxOrigin)); | 46 marker.moveBy(roundedIntPoint(boxOrigin)); |
| 47 | 47 |
| 48 GraphicsContext* context = paintInfo.context; | 48 GraphicsContext* context = paintInfo.context; |
| 49 | 49 |
| 50 if (m_renderListMarker.isImage()) { | 50 if (m_layoutListMarker.isImage()) { |
| 51 context->drawImage(m_renderListMarker.image()->image(&m_renderListMarker
, marker.size()).get(), marker); | 51 context->drawImage(m_layoutListMarker.image()->image(&m_layoutListMarker
, marker.size()).get(), marker); |
| 52 if (m_renderListMarker.selectionState() != LayoutObject::SelectionNone)
{ | 52 if (m_layoutListMarker.selectionState() != LayoutObject::SelectionNone)
{ |
| 53 LayoutRect selRect = m_renderListMarker.localSelectionRect(); | 53 LayoutRect selRect = m_layoutListMarker.localSelectionRect(); |
| 54 selRect.moveBy(boxOrigin); | 54 selRect.moveBy(boxOrigin); |
| 55 context->fillRect(pixelSnappedIntRect(selRect), m_renderListMarker.s
electionBackgroundColor()); | 55 context->fillRect(pixelSnappedIntRect(selRect), m_layoutListMarker.s
electionBackgroundColor()); |
| 56 } | 56 } |
| 57 return; | 57 return; |
| 58 } | 58 } |
| 59 | 59 |
| 60 if (m_renderListMarker.selectionState() != LayoutObject::SelectionNone) { | 60 if (m_layoutListMarker.selectionState() != LayoutObject::SelectionNone) { |
| 61 LayoutRect selRect = m_renderListMarker.localSelectionRect(); | 61 LayoutRect selRect = m_layoutListMarker.localSelectionRect(); |
| 62 selRect.moveBy(boxOrigin); | 62 selRect.moveBy(boxOrigin); |
| 63 context->fillRect(pixelSnappedIntRect(selRect), m_renderListMarker.selec
tionBackgroundColor()); | 63 context->fillRect(pixelSnappedIntRect(selRect), m_layoutListMarker.selec
tionBackgroundColor()); |
| 64 } | 64 } |
| 65 | 65 |
| 66 const Color color(m_renderListMarker.resolveColor(CSSPropertyColor)); | 66 const Color color(m_layoutListMarker.resolveColor(CSSPropertyColor)); |
| 67 context->setStrokeColor(color); | 67 context->setStrokeColor(color); |
| 68 context->setStrokeStyle(SolidStroke); | 68 context->setStrokeStyle(SolidStroke); |
| 69 context->setStrokeThickness(1.0f); | 69 context->setStrokeThickness(1.0f); |
| 70 context->setFillColor(color); | 70 context->setFillColor(color); |
| 71 | 71 |
| 72 EListStyleType type = m_renderListMarker.style()->listStyleType(); | 72 EListStyleType type = m_layoutListMarker.style()->listStyleType(); |
| 73 switch (type) { | 73 switch (type) { |
| 74 case Disc: | 74 case Disc: |
| 75 context->fillEllipse(marker); | 75 context->fillEllipse(marker); |
| 76 return; | 76 return; |
| 77 case Circle: | 77 case Circle: |
| 78 context->strokeEllipse(marker); | 78 context->strokeEllipse(marker); |
| 79 return; | 79 return; |
| 80 case Square: | 80 case Square: |
| 81 context->fillRect(marker); | 81 context->fillRect(marker); |
| 82 return; | 82 return; |
| (...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 154 case UpperGreek: | 154 case UpperGreek: |
| 155 case UpperHexadecimal: | 155 case UpperHexadecimal: |
| 156 case UpperLatin: | 156 case UpperLatin: |
| 157 case UpperNorwegian: | 157 case UpperNorwegian: |
| 158 case UpperRoman: | 158 case UpperRoman: |
| 159 case Urdu: | 159 case Urdu: |
| 160 case Asterisks: | 160 case Asterisks: |
| 161 case Footnotes: | 161 case Footnotes: |
| 162 break; | 162 break; |
| 163 } | 163 } |
| 164 if (m_renderListMarker.text().isEmpty()) | 164 if (m_layoutListMarker.text().isEmpty()) |
| 165 return; | 165 return; |
| 166 | 166 |
| 167 const Font& font = m_renderListMarker.style()->font(); | 167 const Font& font = m_layoutListMarker.style()->font(); |
| 168 TextRun textRun = constructTextRun(&m_renderListMarker, font, m_renderListMa
rker.text(), m_renderListMarker.styleRef()); | 168 TextRun textRun = constructTextRun(&m_layoutListMarker, font, m_layoutListMa
rker.text(), m_layoutListMarker.styleRef()); |
| 169 | 169 |
| 170 GraphicsContextStateSaver stateSaver(*context, false); | 170 GraphicsContextStateSaver stateSaver(*context, false); |
| 171 if (!m_renderListMarker.style()->isHorizontalWritingMode()) { | 171 if (!m_layoutListMarker.style()->isHorizontalWritingMode()) { |
| 172 marker.moveBy(roundedIntPoint(-boxOrigin)); | 172 marker.moveBy(roundedIntPoint(-boxOrigin)); |
| 173 marker = marker.transposedRect(); | 173 marker = marker.transposedRect(); |
| 174 marker.moveBy(IntPoint(roundToInt(box.x()), roundToInt(box.y() - m_rende
rListMarker.logicalHeight()))); | 174 marker.moveBy(IntPoint(roundToInt(box.x()), roundToInt(box.y() - m_layou
tListMarker.logicalHeight()))); |
| 175 stateSaver.save(); | 175 stateSaver.save(); |
| 176 context->translate(marker.x(), marker.maxY()); | 176 context->translate(marker.x(), marker.maxY()); |
| 177 context->rotate(static_cast<float>(deg2rad(90.))); | 177 context->rotate(static_cast<float>(deg2rad(90.))); |
| 178 context->translate(-marker.x(), -marker.maxY()); | 178 context->translate(-marker.x(), -marker.maxY()); |
| 179 } | 179 } |
| 180 | 180 |
| 181 TextRunPaintInfo textRunPaintInfo(textRun); | 181 TextRunPaintInfo textRunPaintInfo(textRun); |
| 182 textRunPaintInfo.bounds = marker; | 182 textRunPaintInfo.bounds = marker; |
| 183 IntPoint textOrigin = IntPoint(marker.x(), marker.y() + m_renderListMarker.s
tyle()->fontMetrics().ascent()); | 183 IntPoint textOrigin = IntPoint(marker.x(), marker.y() + m_layoutListMarker.s
tyle()->fontMetrics().ascent()); |
| 184 | 184 |
| 185 if (type == Asterisks || type == Footnotes) { | 185 if (type == Asterisks || type == Footnotes) { |
| 186 context->drawText(font, textRunPaintInfo, textOrigin); | 186 context->drawText(font, textRunPaintInfo, textOrigin); |
| 187 } else { | 187 } else { |
| 188 // Text is not arbitrary. We can judge whether it's RTL from the first c
haracter, | 188 // Text is not arbitrary. We can judge whether it's RTL from the first c
haracter, |
| 189 // and we only need to handle the direction RightToLeft for now. | 189 // and we only need to handle the direction RightToLeft for now. |
| 190 bool textNeedsReversing = WTF::Unicode::direction(m_renderListMarker.tex
t()[0]) == WTF::Unicode::RightToLeft; | 190 bool textNeedsReversing = WTF::Unicode::direction(m_layoutListMarker.tex
t()[0]) == WTF::Unicode::RightToLeft; |
| 191 StringBuilder reversedText; | 191 StringBuilder reversedText; |
| 192 if (textNeedsReversing) { | 192 if (textNeedsReversing) { |
| 193 unsigned length = m_renderListMarker.text().length(); | 193 unsigned length = m_layoutListMarker.text().length(); |
| 194 reversedText.reserveCapacity(length); | 194 reversedText.reserveCapacity(length); |
| 195 for (int i = length - 1; i >= 0; --i) | 195 for (int i = length - 1; i >= 0; --i) |
| 196 reversedText.append(m_renderListMarker.text()[i]); | 196 reversedText.append(m_layoutListMarker.text()[i]); |
| 197 ASSERT(reversedText.length() == length); | 197 ASSERT(reversedText.length() == length); |
| 198 textRun.setText(reversedText.toString()); | 198 textRun.setText(reversedText.toString()); |
| 199 } | 199 } |
| 200 | 200 |
| 201 const UChar suffix = m_renderListMarker.listMarkerSuffix(type, m_renderL
istMarker.listItem()->value()); | 201 const UChar suffix = m_layoutListMarker.listMarkerSuffix(type, m_layoutL
istMarker.listItem()->value()); |
| 202 UChar suffixStr[2] = { | 202 UChar suffixStr[2] = { |
| 203 m_renderListMarker.style()->isLeftToRightDirection() ? suffix : ' ', | 203 m_layoutListMarker.style()->isLeftToRightDirection() ? suffix : ' ', |
| 204 m_renderListMarker.style()->isLeftToRightDirection() ? ' ' : suffix | 204 m_layoutListMarker.style()->isLeftToRightDirection() ? ' ' : suffix |
| 205 }; | 205 }; |
| 206 TextRun suffixRun = constructTextRun(&m_renderListMarker, font, suffixSt
r, 2, m_renderListMarker.styleRef(), m_renderListMarker.style()->direction()); | 206 TextRun suffixRun = constructTextRun(&m_layoutListMarker, font, suffixSt
r, 2, m_layoutListMarker.styleRef(), m_layoutListMarker.style()->direction()); |
| 207 TextRunPaintInfo suffixRunInfo(suffixRun); | 207 TextRunPaintInfo suffixRunInfo(suffixRun); |
| 208 suffixRunInfo.bounds = marker; | 208 suffixRunInfo.bounds = marker; |
| 209 | 209 |
| 210 if (m_renderListMarker.style()->isLeftToRightDirection()) { | 210 if (m_layoutListMarker.style()->isLeftToRightDirection()) { |
| 211 context->drawText(font, textRunPaintInfo, textOrigin); | 211 context->drawText(font, textRunPaintInfo, textOrigin); |
| 212 context->drawText(font, suffixRunInfo, textOrigin + IntSize(font.wid
th(textRun), 0)); | 212 context->drawText(font, suffixRunInfo, textOrigin + IntSize(font.wid
th(textRun), 0)); |
| 213 } else { | 213 } else { |
| 214 context->drawText(font, suffixRunInfo, textOrigin); | 214 context->drawText(font, suffixRunInfo, textOrigin); |
| 215 context->drawText(font, textRunPaintInfo, textOrigin + IntSize(font.
width(suffixRun), 0)); | 215 context->drawText(font, textRunPaintInfo, textOrigin + IntSize(font.
width(suffixRun), 0)); |
| 216 } | 216 } |
| 217 } | 217 } |
| 218 } | 218 } |
| 219 | 219 |
| 220 } // namespace blink | 220 } // namespace blink |
| OLD | NEW |