Chromium Code Reviews| 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 15 matching lines...) Expand all Loading... | |
| 26 | 26 |
| 27 namespace blink { | 27 namespace blink { |
| 28 | 28 |
| 29 static inline bool textShouldBePainted(const LayoutSVGInlineText& textLayoutObje ct) | 29 static inline bool textShouldBePainted(const LayoutSVGInlineText& textLayoutObje ct) |
| 30 { | 30 { |
| 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 static bool paintsMarkerHighlights(const LayoutObject& layoutObject) | |
|
pdr.
2016/07/06 21:06:46
Make InlineTextBoxPainter's paintsMarkerHighlights
fs
2016/07/06 21:32:41
SVGInlineTextBoxPainter are not related to InlineT
| |
| 37 { | |
| 38 return layoutObject.node() && layoutObject.document().markers().hasMarkers(l ayoutObject.node()); | |
| 39 } | |
| 40 | |
| 36 bool SVGInlineTextBoxPainter::shouldPaintSelection(const PaintInfo& paintInfo) c onst | 41 bool SVGInlineTextBoxPainter::shouldPaintSelection(const PaintInfo& paintInfo) c onst |
| 37 { | 42 { |
| 38 return !paintInfo.isPrinting() && m_svgInlineTextBox.getSelectionState() != SelectionNone; | 43 return !paintInfo.isPrinting() && m_svgInlineTextBox.getSelectionState() != SelectionNone; |
| 39 } | 44 } |
| 40 | 45 |
| 41 void SVGInlineTextBoxPainter::paint(const PaintInfo& paintInfo, const LayoutPoin t& paintOffset) | 46 void SVGInlineTextBoxPainter::paint(const PaintInfo& paintInfo, const LayoutPoin t& paintOffset) |
| 42 { | 47 { |
| 43 ASSERT(paintInfo.phase == PaintPhaseForeground || paintInfo.phase == PaintPh aseSelection); | 48 ASSERT(paintInfo.phase == PaintPhaseForeground || paintInfo.phase == PaintPh aseSelection); |
| 44 ASSERT(m_svgInlineTextBox.truncation() == cNoTruncation); | 49 ASSERT(m_svgInlineTextBox.truncation() == cNoTruncation); |
| 45 | 50 |
| 46 if (m_svgInlineTextBox.getLineLayoutItem().style()->visibility() != VISIBLE) | 51 if (m_svgInlineTextBox.getLineLayoutItem().style()->visibility() != VISIBLE) |
| 47 return; | 52 return; |
| 48 | 53 |
| 49 // We're explicitly not supporting composition & custom underlines and custo m highlighters -- unlike InlineTextBox. | 54 // 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. | 55 // If we ever need that for SVG, it's very easy to refactor and reuse the co de. |
| 51 | 56 |
| 52 if (paintInfo.phase == PaintPhaseSelection && !shouldPaintSelection(paintInf o)) | 57 bool haveSelection = shouldPaintSelection(paintInfo); |
| 58 if (!haveSelection && paintInfo.phase == PaintPhaseSelection) | |
| 53 return; | 59 return; |
| 54 | 60 |
| 55 LayoutSVGInlineText& textLayoutObject = toLayoutSVGInlineText(*LineLayoutAPI Shim::layoutObjectFrom(m_svgInlineTextBox.getLineLayoutItem())); | 61 LayoutSVGInlineText& textLayoutObject = toLayoutSVGInlineText(*LineLayoutAPI Shim::layoutObjectFrom(m_svgInlineTextBox.getLineLayoutItem())); |
| 56 if (!textShouldBePainted(textLayoutObject)) | 62 if (!textShouldBePainted(textLayoutObject)) |
| 57 return; | 63 return; |
| 58 | 64 |
| 59 DisplayItem::Type displayItemType = DisplayItem::paintPhaseToDrawingType(pai ntInfo.phase); | 65 DisplayItem::Type displayItemType = DisplayItem::paintPhaseToDrawingType(pai ntInfo.phase); |
| 60 if (!DrawingRecorder::useCachedDrawingIfPossible(paintInfo.context, m_svgInl ineTextBox, displayItemType)) { | 66 if (!DrawingRecorder::useCachedDrawingIfPossible(paintInfo.context, m_svgInl ineTextBox, displayItemType)) { |
| 61 LayoutObject& parentLayoutObject = *LineLayoutAPIShim::layoutObjectFrom( m_svgInlineTextBox.parent()->getLineLayoutItem()); | 67 LayoutObject& parentLayoutObject = *LineLayoutAPIShim::layoutObjectFrom( m_svgInlineTextBox.parent()->getLineLayoutItem()); |
| 62 const ComputedStyle& style = parentLayoutObject.styleRef(); | 68 const ComputedStyle& style = parentLayoutObject.styleRef(); |
| 63 | 69 |
| 64 // TODO(chrishtr): passing the cull rect is incorrect. | 70 // We compute the paint rect with what looks like the logical values, to match the |
|
chrishtr
2016/07/06 20:53:20
Factor all this into a method saying it's computin
fs
2016/07/06 21:32:41
Will do.
fs
2016/07/06 23:33:30
Moved into a boundsFor... method.
| |
| 65 DrawingRecorder recorder(paintInfo.context, m_svgInlineTextBox, displayI temType, FloatRect(paintInfo.cullRect().m_rect)); | 71 // computation in SVGInlineTextBox::calculateBoundaries, and the fact th at vertical (etc) |
| 72 // layouts are handled by SVGTextLayoutEngine. | |
| 73 LayoutRect paintRect( | |
| 74 m_svgInlineTextBox.topLeft(), | |
| 75 LayoutSize(m_svgInlineTextBox.logicalWidth(), m_svgInlineTextBox.log icalHeight())); | |
|
chrishtr
2016/07/06 20:53:20
Physical, not logical.
fs
2016/07/06 21:32:41
Per the comment above this code, this is intention
| |
| 76 if (paintInfo.phase != PaintPhaseSelection && (haveSelection || paintsMa rkerHighlights(textLayoutObject))) { | |
| 77 paintRect.unite(m_svgInlineTextBox.localSelectionRect( | |
| 78 m_svgInlineTextBox.start(), m_svgInlineTextBox.start() + m_svgIn lineTextBox.len())); | |
| 79 } | |
| 80 paintRect.moveBy(paintOffset); | |
| 81 | |
| 82 DrawingRecorder recorder(paintInfo.context, m_svgInlineTextBox, displayI temType, FloatRect(paintRect)); | |
| 66 InlineTextBoxPainter(m_svgInlineTextBox).paintDocumentMarkers( | 83 InlineTextBoxPainter(m_svgInlineTextBox).paintDocumentMarkers( |
| 67 paintInfo, paintOffset, style, | 84 paintInfo, paintOffset, style, |
| 68 textLayoutObject.scaledFont(), DocumentMarkerPaintPhase::Background) ; | 85 textLayoutObject.scaledFont(), DocumentMarkerPaintPhase::Background) ; |
| 69 | 86 |
| 70 if (!m_svgInlineTextBox.textFragments().isEmpty()) | 87 if (!m_svgInlineTextBox.textFragments().isEmpty()) |
| 71 paintTextFragments(paintInfo, parentLayoutObject); | 88 paintTextFragments(paintInfo, parentLayoutObject); |
| 72 | 89 |
| 73 InlineTextBoxPainter(m_svgInlineTextBox).paintDocumentMarkers( | 90 InlineTextBoxPainter(m_svgInlineTextBox).paintDocumentMarkers( |
| 74 paintInfo, paintOffset, style, | 91 paintInfo, paintOffset, style, |
| 75 textLayoutObject.scaledFont(), DocumentMarkerPaintPhase::Foreground) ; | 92 textLayoutObject.scaledFont(), DocumentMarkerPaintPhase::Foreground) ; |
| (...skipping 420 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 496 stateSaver.save(); | 513 stateSaver.save(); |
| 497 paintInfo.context.concatCTM(fragment.buildFragmentTransform()); | 514 paintInfo.context.concatCTM(fragment.buildFragmentTransform()); |
| 498 } | 515 } |
| 499 FloatRect fragmentRect = m_svgInlineTextBox.selectionRectForTextFragment (fragment, textMatchInfo.startPosition, textMatchInfo.endPosition, style); | 516 FloatRect fragmentRect = m_svgInlineTextBox.selectionRectForTextFragment (fragment, textMatchInfo.startPosition, textMatchInfo.endPosition, style); |
| 500 paintInfo.context.setFillColor(color); | 517 paintInfo.context.setFillColor(color); |
| 501 paintInfo.context.fillRect(fragmentRect); | 518 paintInfo.context.fillRect(fragmentRect); |
| 502 } | 519 } |
| 503 } | 520 } |
| 504 | 521 |
| 505 } // namespace blink | 522 } // namespace blink |
| OLD | NEW |