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 "core/paint/SVGInlineTextBoxPainter.h" | 5 #include "core/paint/SVGInlineTextBoxPainter.h" |
6 | 6 |
7 #include "core/editing/Editor.h" | 7 #include "core/editing/Editor.h" |
8 #include "core/editing/markers/DocumentMarkerController.h" | 8 #include "core/editing/markers/DocumentMarkerController.h" |
9 #include "core/editing/markers/RenderedDocumentMarker.h" | 9 #include "core/editing/markers/RenderedDocumentMarker.h" |
10 #include "core/frame/LocalFrame.h" | 10 #include "core/frame/LocalFrame.h" |
(...skipping 20 matching lines...) Expand all Loading... |
31 // Font::pixelSize(), returns FontDescription::computedPixelSize(), which re
turns "int(x + 0.5)". | 31 // Font::pixelSize(), returns FontDescription::computedPixelSize(), which re
turns "int(x + 0.5)". |
32 // If the absolute font size on screen is below x=0.5, don't render anything
. | 32 // If the absolute font size on screen is below x=0.5, don't render anything
. |
33 return textLayoutObject.scaledFont().getFontDescription().computedPixelSize(
); | 33 return textLayoutObject.scaledFont().getFontDescription().computedPixelSize(
); |
34 } | 34 } |
35 | 35 |
36 bool SVGInlineTextBoxPainter::shouldPaintSelection(const PaintInfo& paintInfo) c
onst | 36 bool SVGInlineTextBoxPainter::shouldPaintSelection(const PaintInfo& paintInfo) c
onst |
37 { | 37 { |
38 return !paintInfo.isPrinting() && m_svgInlineTextBox.getSelectionState() !=
SelectionNone; | 38 return !paintInfo.isPrinting() && m_svgInlineTextBox.getSelectionState() !=
SelectionNone; |
39 } | 39 } |
40 | 40 |
| 41 FloatRect SVGInlineTextBoxPainter::boundsForDrawingRecorder( |
| 42 const LayoutPoint& paintOffset, bool includeSelectionRect) const |
| 43 { |
| 44 // We compute the paint rect with what looks like the logical values, to mat
ch the |
| 45 // computation in SVGInlineTextBox::calculateBoundaries, and the fact that v
ertical (etc) |
| 46 // layouts are handled by SVGTextLayoutEngine. |
| 47 LayoutRect bounds( |
| 48 m_svgInlineTextBox.topLeft(), |
| 49 LayoutSize(m_svgInlineTextBox.logicalWidth(), m_svgInlineTextBox.logical
Height())); |
| 50 if (includeSelectionRect) { |
| 51 bounds.unite(m_svgInlineTextBox.localSelectionRect( |
| 52 m_svgInlineTextBox.start(), m_svgInlineTextBox.start() + m_svgInline
TextBox.len())); |
| 53 } |
| 54 bounds.moveBy(paintOffset); |
| 55 return FloatRect(bounds); |
| 56 } |
| 57 |
41 void SVGInlineTextBoxPainter::paint(const PaintInfo& paintInfo, const LayoutPoin
t& paintOffset) | 58 void SVGInlineTextBoxPainter::paint(const PaintInfo& paintInfo, const LayoutPoin
t& paintOffset) |
42 { | 59 { |
43 ASSERT(paintInfo.phase == PaintPhaseForeground || paintInfo.phase == PaintPh
aseSelection); | 60 ASSERT(paintInfo.phase == PaintPhaseForeground || paintInfo.phase == PaintPh
aseSelection); |
44 ASSERT(m_svgInlineTextBox.truncation() == cNoTruncation); | 61 ASSERT(m_svgInlineTextBox.truncation() == cNoTruncation); |
45 | 62 |
46 if (m_svgInlineTextBox.getLineLayoutItem().style()->visibility() != VISIBLE) | 63 if (m_svgInlineTextBox.getLineLayoutItem().style()->visibility() != VISIBLE) |
47 return; | 64 return; |
48 | 65 |
49 // We're explicitly not supporting composition & custom underlines and custo
m highlighters -- unlike InlineTextBox. | 66 // We're explicitly not supporting composition & custom underlines and custo
m highlighters -- unlike InlineTextBox. |
50 // If we ever need that for SVG, it's very easy to refactor and reuse the co
de. | 67 // If we ever need that for SVG, it's very easy to refactor and reuse the co
de. |
51 | 68 |
52 if (paintInfo.phase == PaintPhaseSelection && !shouldPaintSelection(paintInf
o)) | 69 bool haveSelection = shouldPaintSelection(paintInfo); |
| 70 if (!haveSelection && paintInfo.phase == PaintPhaseSelection) |
53 return; | 71 return; |
54 | 72 |
55 LayoutSVGInlineText& textLayoutObject = toLayoutSVGInlineText(*LineLayoutAPI
Shim::layoutObjectFrom(m_svgInlineTextBox.getLineLayoutItem())); | 73 LayoutSVGInlineText& textLayoutObject = toLayoutSVGInlineText(*LineLayoutAPI
Shim::layoutObjectFrom(m_svgInlineTextBox.getLineLayoutItem())); |
56 if (!textShouldBePainted(textLayoutObject)) | 74 if (!textShouldBePainted(textLayoutObject)) |
57 return; | 75 return; |
58 | 76 |
59 DisplayItem::Type displayItemType = DisplayItem::paintPhaseToDrawingType(pai
ntInfo.phase); | 77 DisplayItem::Type displayItemType = DisplayItem::paintPhaseToDrawingType(pai
ntInfo.phase); |
60 if (!DrawingRecorder::useCachedDrawingIfPossible(paintInfo.context, m_svgInl
ineTextBox, displayItemType)) { | 78 if (!DrawingRecorder::useCachedDrawingIfPossible(paintInfo.context, m_svgInl
ineTextBox, displayItemType)) { |
61 LayoutObject& parentLayoutObject = *LineLayoutAPIShim::layoutObjectFrom(
m_svgInlineTextBox.parent()->getLineLayoutItem()); | 79 LayoutObject& parentLayoutObject = *LineLayoutAPIShim::layoutObjectFrom(
m_svgInlineTextBox.parent()->getLineLayoutItem()); |
62 const ComputedStyle& style = parentLayoutObject.styleRef(); | 80 const ComputedStyle& style = parentLayoutObject.styleRef(); |
63 | 81 |
64 // TODO(chrishtr): passing the cull rect is incorrect. | 82 bool includeSelectionRect = paintInfo.phase != PaintPhaseSelection |
65 DrawingRecorder recorder(paintInfo.context, m_svgInlineTextBox, displayI
temType, FloatRect(paintInfo.cullRect().m_rect)); | 83 && (haveSelection || InlineTextBoxPainter::paintsMarkerHighlights(te
xtLayoutObject)); |
| 84 DrawingRecorder recorder(paintInfo.context, m_svgInlineTextBox, displayI
temType, |
| 85 boundsForDrawingRecorder(paintOffset, includeSelectionRect)); |
66 InlineTextBoxPainter(m_svgInlineTextBox).paintDocumentMarkers( | 86 InlineTextBoxPainter(m_svgInlineTextBox).paintDocumentMarkers( |
67 paintInfo, paintOffset, style, | 87 paintInfo, paintOffset, style, |
68 textLayoutObject.scaledFont(), DocumentMarkerPaintPhase::Background)
; | 88 textLayoutObject.scaledFont(), DocumentMarkerPaintPhase::Background)
; |
69 | 89 |
70 if (!m_svgInlineTextBox.textFragments().isEmpty()) | 90 if (!m_svgInlineTextBox.textFragments().isEmpty()) |
71 paintTextFragments(paintInfo, parentLayoutObject); | 91 paintTextFragments(paintInfo, parentLayoutObject); |
72 | 92 |
73 InlineTextBoxPainter(m_svgInlineTextBox).paintDocumentMarkers( | 93 InlineTextBoxPainter(m_svgInlineTextBox).paintDocumentMarkers( |
74 paintInfo, paintOffset, style, | 94 paintInfo, paintOffset, style, |
75 textLayoutObject.scaledFont(), DocumentMarkerPaintPhase::Foreground)
; | 95 textLayoutObject.scaledFont(), DocumentMarkerPaintPhase::Foreground)
; |
(...skipping 420 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
496 stateSaver.save(); | 516 stateSaver.save(); |
497 paintInfo.context.concatCTM(fragment.buildFragmentTransform()); | 517 paintInfo.context.concatCTM(fragment.buildFragmentTransform()); |
498 } | 518 } |
499 FloatRect fragmentRect = m_svgInlineTextBox.selectionRectForTextFragment
(fragment, textMatchInfo.startPosition, textMatchInfo.endPosition, style); | 519 FloatRect fragmentRect = m_svgInlineTextBox.selectionRectForTextFragment
(fragment, textMatchInfo.startPosition, textMatchInfo.endPosition, style); |
500 paintInfo.context.setFillColor(color); | 520 paintInfo.context.setFillColor(color); |
501 paintInfo.context.fillRect(fragmentRect); | 521 paintInfo.context.fillRect(fragmentRect); |
502 } | 522 } |
503 } | 523 } |
504 | 524 |
505 } // namespace blink | 525 } // namespace blink |
OLD | NEW |