Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 /** | 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
| 2 * Copyright (C) 2007 Rob Buis <buis@kde.org> | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 * Copyright (C) 2007 Nikolas Zimmermann <zimmermann@kde.org> | 3 // found in the LICENSE file. |
| 4 * Copyright (C) Research In Motion Limited 2010. All rights reserved. | |
| 5 * | |
| 6 * This library is free software; you can redistribute it and/or | |
| 7 * modify it under the terms of the GNU Library General Public | |
| 8 * License as published by the Free Software Foundation; either | |
| 9 * version 2 of the License, or (at your option) any later version. | |
| 10 * | |
| 11 * This library is distributed in the hope that it will be useful, | |
| 12 * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
| 13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
| 14 * Library General Public License for more details. | |
| 15 * | |
| 16 * You should have received a copy of the GNU Library General Public License | |
| 17 * along with this library; see the file COPYING.LIB. If not, write to | |
| 18 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, | |
| 19 * Boston, MA 02110-1301, USA. | |
| 20 */ | |
| 21 | 4 |
| 22 #include "config.h" | 5 #include "config.h" |
| 23 #include "core/rendering/svg/SVGInlineTextBox.h" | 6 #include "core/paint/SVGInlineTextBoxPainter.h" |
| 24 | 7 |
| 25 #include "core/dom/DocumentMarkerController.h" | 8 #include "core/dom/DocumentMarkerController.h" |
| 26 #include "core/dom/RenderedDocumentMarker.h" | 9 #include "core/dom/RenderedDocumentMarker.h" |
| 27 #include "core/editing/Editor.h" | 10 #include "core/editing/Editor.h" |
| 28 #include "core/frame/FrameView.h" | 11 #include "core/frame/FrameView.h" |
| 29 #include "core/frame/LocalFrame.h" | 12 #include "core/frame/LocalFrame.h" |
| 30 #include "core/paint/InlinePainter.h" | 13 #include "core/paint/InlinePainter.h" |
| 31 #include "core/rendering/HitTestResult.h" | 14 #include "core/paint/InlineTextBoxPainter.h" |
| 32 #include "core/rendering/InlineFlowBox.h" | |
| 33 #include "core/rendering/PaintInfo.h" | 15 #include "core/rendering/PaintInfo.h" |
| 34 #include "core/rendering/PointerEventsHitRules.h" | |
| 35 #include "core/rendering/RenderInline.h" | 16 #include "core/rendering/RenderInline.h" |
| 36 #include "core/rendering/RenderTheme.h" | 17 #include "core/rendering/RenderTheme.h" |
| 37 #include "core/rendering/style/ShadowList.h" | 18 #include "core/rendering/style/ShadowList.h" |
| 38 #include "core/rendering/svg/RenderSVGInlineText.h" | 19 #include "core/rendering/svg/RenderSVGInlineText.h" |
| 39 #include "core/rendering/svg/RenderSVGResource.h" | 20 #include "core/rendering/svg/RenderSVGResource.h" |
| 40 #include "core/rendering/svg/RenderSVGResourceSolidColor.h" | 21 #include "core/rendering/svg/RenderSVGResourceSolidColor.h" |
| 22 #include "core/rendering/svg/SVGInlineTextBox.h" | |
| 41 #include "core/rendering/svg/SVGRenderSupport.h" | 23 #include "core/rendering/svg/SVGRenderSupport.h" |
| 42 #include "core/rendering/svg/SVGResourcesCache.h" | 24 #include "core/rendering/svg/SVGResourcesCache.h" |
| 43 #include "core/rendering/svg/SVGTextRunRenderingContext.h" | |
| 44 #include "platform/FloatConversion.h" | |
| 45 #include "platform/fonts/FontCache.h" | |
| 46 #include "platform/graphics/GraphicsContextStateSaver.h" | |
| 47 | 25 |
| 48 namespace blink { | 26 namespace blink { |
| 49 | 27 |
| 50 struct ExpectedSVGInlineTextBoxSize : public InlineTextBox { | |
| 51 float float1; | |
| 52 uint32_t bitfields : 1; | |
| 53 Vector<SVGTextFragment> vector; | |
| 54 }; | |
| 55 | |
| 56 COMPILE_ASSERT(sizeof(SVGInlineTextBox) == sizeof(ExpectedSVGInlineTextBoxSize), SVGInlineTextBox_is_not_of_expected_size); | |
| 57 | |
| 58 SVGInlineTextBox::SVGInlineTextBox(RenderObject& object) | |
| 59 : InlineTextBox(object) | |
| 60 , m_logicalHeight(0) | |
| 61 , m_startsNewTextChunk(false) | |
| 62 { | |
| 63 } | |
| 64 | |
| 65 void SVGInlineTextBox::dirtyLineBoxes() | |
| 66 { | |
| 67 InlineTextBox::dirtyLineBoxes(); | |
| 68 | |
| 69 // Clear the now stale text fragments | |
| 70 clearTextFragments(); | |
| 71 | |
| 72 // And clear any following text fragments as the text on which they | |
| 73 // depend may now no longer exist, or glyph positions may be wrong | |
| 74 InlineTextBox* nextBox = nextTextBox(); | |
| 75 if (nextBox) | |
| 76 nextBox->dirtyLineBoxes(); | |
| 77 } | |
| 78 | |
| 79 int SVGInlineTextBox::offsetForPosition(float, bool) const | |
| 80 { | |
| 81 // SVG doesn't use the standard offset <-> position selection system, as it' s not suitable for SVGs complex needs. | |
| 82 // vertical text selection, inline boxes spanning multiple lines (contrary t o HTML, etc.) | |
| 83 ASSERT_NOT_REACHED(); | |
| 84 return 0; | |
| 85 } | |
| 86 | |
| 87 int SVGInlineTextBox::offsetForPositionInFragment(const SVGTextFragment& fragmen t, float position, bool includePartialGlyphs) const | |
| 88 { | |
| 89 RenderSVGInlineText& textRenderer = toRenderSVGInlineText(this->renderer()); | |
| 90 | |
| 91 float scalingFactor = textRenderer.scalingFactor(); | |
| 92 ASSERT(scalingFactor); | |
| 93 | |
| 94 RenderStyle* style = textRenderer.style(); | |
| 95 ASSERT(style); | |
| 96 | |
| 97 TextRun textRun = constructTextRun(style, fragment); | |
| 98 | |
| 99 // Eventually handle lengthAdjust="spacingAndGlyphs". | |
| 100 // FIXME: Handle vertical text. | |
| 101 AffineTransform fragmentTransform; | |
| 102 fragment.buildFragmentTransform(fragmentTransform); | |
| 103 if (!fragmentTransform.isIdentity()) | |
| 104 textRun.setHorizontalGlyphStretch(narrowPrecisionToFloat(fragmentTransfo rm.xScale())); | |
| 105 | |
| 106 return fragment.characterOffset - start() + textRenderer.scaledFont().offset ForPosition(textRun, position * scalingFactor, includePartialGlyphs); | |
| 107 } | |
| 108 | |
| 109 float SVGInlineTextBox::positionForOffset(int) const | |
| 110 { | |
| 111 // SVG doesn't use the offset <-> position selection system. | |
| 112 ASSERT_NOT_REACHED(); | |
| 113 return 0; | |
| 114 } | |
| 115 | |
| 116 FloatRect SVGInlineTextBox::selectionRectForTextFragment(const SVGTextFragment& fragment, int startPosition, int endPosition, RenderStyle* style) | |
| 117 { | |
| 118 ASSERT(startPosition < endPosition); | |
| 119 ASSERT(style); | |
| 120 | |
| 121 FontCachePurgePreventer fontCachePurgePreventer; | |
| 122 | |
| 123 RenderSVGInlineText& textRenderer = toRenderSVGInlineText(this->renderer()); | |
| 124 | |
| 125 float scalingFactor = textRenderer.scalingFactor(); | |
| 126 ASSERT(scalingFactor); | |
| 127 | |
| 128 const Font& scaledFont = textRenderer.scaledFont(); | |
| 129 const FontMetrics& scaledFontMetrics = scaledFont.fontMetrics(); | |
| 130 FloatPoint textOrigin(fragment.x, fragment.y); | |
| 131 if (scalingFactor != 1) | |
| 132 textOrigin.scale(scalingFactor, scalingFactor); | |
| 133 | |
| 134 textOrigin.move(0, -scaledFontMetrics.floatAscent()); | |
| 135 | |
| 136 FloatRect selectionRect = scaledFont.selectionRectForText(constructTextRun(s tyle, fragment), textOrigin, fragment.height * scalingFactor, startPosition, end Position); | |
| 137 if (scalingFactor == 1) | |
| 138 return selectionRect; | |
| 139 | |
| 140 selectionRect.scale(1 / scalingFactor); | |
| 141 return selectionRect; | |
| 142 } | |
| 143 | |
| 144 LayoutRect SVGInlineTextBox::localSelectionRect(int startPosition, int endPositi on) | |
| 145 { | |
| 146 int boxStart = start(); | |
| 147 startPosition = std::max(startPosition - boxStart, 0); | |
| 148 endPosition = std::min(endPosition - boxStart, static_cast<int>(len())); | |
| 149 if (startPosition >= endPosition) | |
| 150 return LayoutRect(); | |
| 151 | |
| 152 RenderStyle* style = renderer().style(); | |
| 153 ASSERT(style); | |
| 154 | |
| 155 AffineTransform fragmentTransform; | |
| 156 FloatRect selectionRect; | |
| 157 int fragmentStartPosition = 0; | |
| 158 int fragmentEndPosition = 0; | |
| 159 | |
| 160 unsigned textFragmentsSize = m_textFragments.size(); | |
| 161 for (unsigned i = 0; i < textFragmentsSize; ++i) { | |
| 162 const SVGTextFragment& fragment = m_textFragments.at(i); | |
| 163 | |
| 164 fragmentStartPosition = startPosition; | |
| 165 fragmentEndPosition = endPosition; | |
| 166 if (!mapStartEndPositionsIntoFragmentCoordinates(fragment, fragmentStart Position, fragmentEndPosition)) | |
| 167 continue; | |
| 168 | |
| 169 FloatRect fragmentRect = selectionRectForTextFragment(fragment, fragment StartPosition, fragmentEndPosition, style); | |
| 170 fragment.buildFragmentTransform(fragmentTransform); | |
| 171 fragmentRect = fragmentTransform.mapRect(fragmentRect); | |
| 172 | |
| 173 selectionRect.unite(fragmentRect); | |
| 174 } | |
| 175 | |
| 176 return enclosingIntRect(selectionRect); | |
| 177 } | |
| 178 | |
| 179 static inline bool textShouldBePainted(RenderSVGInlineText& textRenderer) | 28 static inline bool textShouldBePainted(RenderSVGInlineText& textRenderer) |
| 180 { | 29 { |
| 181 // Font::pixelSize(), returns FontDescription::computedPixelSize(), which re turns "int(x + 0.5)". | 30 // Font::pixelSize(), returns FontDescription::computedPixelSize(), which re turns "int(x + 0.5)". |
| 182 // If the absolute font size on screen is below x=0.5, don't render anything . | 31 // If the absolute font size on screen is below x=0.5, don't render anything . |
| 183 return textRenderer.scaledFont().fontDescription().computedPixelSize(); | 32 return textRenderer.scaledFont().fontDescription().computedPixelSize(); |
| 184 } | 33 } |
| 185 | 34 |
| 186 void SVGInlineTextBox::paintSelectionBackground(PaintInfo& paintInfo) | 35 void SVGInlineTextBoxPainter::paint(PaintInfo& paintInfo, const LayoutPoint& pai ntOffset) |
| 187 { | 36 { |
| 188 ASSERT(paintInfo.shouldPaintWithinRoot(&renderer())); | 37 ASSERT(paintInfo.shouldPaintWithinRoot(&renderer())); |
| 189 ASSERT(paintInfo.phase == PaintPhaseForeground || paintInfo.phase == PaintPh aseSelection); | 38 ASSERT(paintInfo.phase == PaintPhaseForeground || paintInfo.phase == PaintPh aseSelection); |
| 190 ASSERT(truncation() == cNoTruncation); | 39 ASSERT(truncation() == cNoTruncation); |
| 191 | 40 |
| 192 if (renderer().style()->visibility() != VISIBLE) | 41 if (m_svgInlineTextBox.renderer().style()->visibility() != VISIBLE) |
| 193 return; | 42 return; |
| 194 | 43 |
| 195 RenderObject& parentRenderer = parent()->renderer(); | 44 // Note: We're explicitely not supporting composition & custom underlines an d custom highlighters - unlike InlineTextBox. |
| 196 ASSERT(!parentRenderer.document().printing()); | 45 // If we ever need that for SVG, it's very easy to refactor and reuse the co de. |
| 197 | 46 |
| 198 // Determine whether or not we're selected. | 47 RenderObject& parentRenderer = m_svgInlineTextBox.parent()->renderer(); |
| 48 | |
| 199 bool paintSelectedTextOnly = paintInfo.phase == PaintPhaseSelection; | 49 bool paintSelectedTextOnly = paintInfo.phase == PaintPhaseSelection; |
| 200 bool hasSelection = selectionState() != RenderObject::SelectionNone; | 50 bool hasSelection = !parentRenderer.document().printing() && m_svgInlineText Box.selectionState() != RenderObject::SelectionNone; |
| 201 if (!hasSelection || paintSelectedTextOnly) | 51 if (!hasSelection && paintSelectedTextOnly) |
| 202 return; | 52 return; |
| 203 | 53 |
| 204 Color backgroundColor = renderer().selectionBackgroundColor(); | 54 RenderSVGInlineText& textRenderer = toRenderSVGInlineText(m_svgInlineTextBox .renderer()); |
| 205 if (!backgroundColor.alpha()) | |
| 206 return; | |
| 207 | |
| 208 RenderSVGInlineText& textRenderer = toRenderSVGInlineText(this->renderer()); | |
| 209 if (!textShouldBePainted(textRenderer)) | 55 if (!textShouldBePainted(textRenderer)) |
| 210 return; | 56 return; |
| 211 | 57 |
| 212 RenderStyle* style = parentRenderer.style(); | 58 RenderStyle* style = parentRenderer.style(); |
| 213 ASSERT(style); | 59 ASSERT(style); |
| 214 | 60 |
| 215 int startPosition, endPosition; | 61 InlineTextBoxPainter(m_svgInlineTextBox).paintDocumentMarkers(paintInfo.cont ext, paintOffset, style, textRenderer.scaledFont(), true); |
| 216 selectionStartEnd(startPosition, endPosition); | |
| 217 | |
| 218 int fragmentStartPosition = 0; | |
| 219 int fragmentEndPosition = 0; | |
| 220 AffineTransform fragmentTransform; | |
| 221 unsigned textFragmentsSize = m_textFragments.size(); | |
| 222 for (unsigned i = 0; i < textFragmentsSize; ++i) { | |
| 223 SVGTextFragment& fragment = m_textFragments.at(i); | |
| 224 | |
| 225 fragmentStartPosition = startPosition; | |
| 226 fragmentEndPosition = endPosition; | |
| 227 if (!mapStartEndPositionsIntoFragmentCoordinates(fragment, fragmentStart Position, fragmentEndPosition)) | |
| 228 continue; | |
| 229 | |
| 230 GraphicsContextStateSaver stateSaver(*paintInfo.context); | |
| 231 fragment.buildFragmentTransform(fragmentTransform); | |
| 232 if (!fragmentTransform.isIdentity()) | |
| 233 paintInfo.context->concatCTM(fragmentTransform); | |
| 234 | |
| 235 paintInfo.context->setFillColor(backgroundColor); | |
| 236 paintInfo.context->fillRect(selectionRectForTextFragment(fragment, fragm entStartPosition, fragmentEndPosition, style), backgroundColor); | |
| 237 } | |
| 238 } | |
| 239 | |
| 240 void SVGInlineTextBox::paint(PaintInfo& paintInfo, const LayoutPoint& paintOffse t, LayoutUnit, LayoutUnit) | |
| 241 { | |
| 242 ASSERT(paintInfo.shouldPaintWithinRoot(&renderer())); | |
| 243 ASSERT(paintInfo.phase == PaintPhaseForeground || paintInfo.phase == PaintPh aseSelection); | |
| 244 ASSERT(truncation() == cNoTruncation); | |
| 245 | |
| 246 if (renderer().style()->visibility() != VISIBLE) | |
| 247 return; | |
| 248 | |
| 249 // Note: We're explicitely not supporting composition & custom underlines an d custom highlighters - unlike InlineTextBox. | |
| 250 // If we ever need that for SVG, it's very easy to refactor and reuse the co de. | |
| 251 | |
| 252 RenderObject& parentRenderer = parent()->renderer(); | |
| 253 | |
| 254 bool paintSelectedTextOnly = paintInfo.phase == PaintPhaseSelection; | |
| 255 bool hasSelection = !parentRenderer.document().printing() && selectionState( ) != RenderObject::SelectionNone; | |
| 256 if (!hasSelection && paintSelectedTextOnly) | |
| 257 return; | |
| 258 | |
| 259 RenderSVGInlineText& textRenderer = toRenderSVGInlineText(this->renderer()); | |
| 260 if (!textShouldBePainted(textRenderer)) | |
| 261 return; | |
| 262 | |
| 263 RenderStyle* style = parentRenderer.style(); | |
| 264 ASSERT(style); | |
| 265 | |
| 266 paintDocumentMarkers(paintInfo.context, paintOffset, style, textRenderer.sca ledFont(), true); | |
| 267 | 62 |
| 268 const SVGRenderStyle& svgStyle = style->svgStyle(); | 63 const SVGRenderStyle& svgStyle = style->svgStyle(); |
| 269 | 64 |
| 270 bool hasFill = svgStyle.hasFill(); | 65 bool hasFill = svgStyle.hasFill(); |
| 271 bool hasVisibleStroke = svgStyle.hasVisibleStroke(); | 66 bool hasVisibleStroke = svgStyle.hasVisibleStroke(); |
| 272 | 67 |
| 273 RenderStyle* selectionStyle = style; | 68 RenderStyle* selectionStyle = style; |
| 274 if (hasSelection) { | 69 if (hasSelection) { |
| 275 selectionStyle = parentRenderer.getCachedPseudoStyle(SELECTION); | 70 selectionStyle = parentRenderer.getCachedPseudoStyle(SELECTION); |
| 276 if (selectionStyle) { | 71 if (selectionStyle) { |
| 277 const SVGRenderStyle& svgSelectionStyle = selectionStyle->svgStyle() ; | 72 const SVGRenderStyle& svgSelectionStyle = selectionStyle->svgStyle() ; |
| 278 | 73 |
| 279 if (!hasFill) | 74 if (!hasFill) |
| 280 hasFill = svgSelectionStyle.hasFill(); | 75 hasFill = svgSelectionStyle.hasFill(); |
| 281 if (!hasVisibleStroke) | 76 if (!hasVisibleStroke) |
| 282 hasVisibleStroke = svgSelectionStyle.hasVisibleStroke(); | 77 hasVisibleStroke = svgSelectionStyle.hasVisibleStroke(); |
| 283 } else { | 78 } else { |
| 284 selectionStyle = style; | 79 selectionStyle = style; |
| 285 } | 80 } |
| 286 } | 81 } |
| 287 | 82 |
| 288 if (textRenderer.frame() && textRenderer.frame()->view() && textRenderer.fra me()->view()->paintBehavior() & PaintBehaviorRenderingSVGMask) { | 83 if (textRenderer.frame() && textRenderer.frame()->view() && textRenderer.fra me()->view()->paintBehavior() & PaintBehaviorRenderingSVGMask) { |
|
fs
2014/10/06 08:34:53
You might hit a conflict here (https://codereview.
| |
| 289 hasFill = true; | 84 hasFill = true; |
| 290 hasVisibleStroke = false; | 85 hasVisibleStroke = false; |
| 291 } | 86 } |
| 292 | 87 |
| 293 AffineTransform fragmentTransform; | 88 AffineTransform fragmentTransform; |
| 294 unsigned textFragmentsSize = m_textFragments.size(); | 89 unsigned textFragmentsSize = m_svgInlineTextBox.textFragments().size(); |
| 295 for (unsigned i = 0; i < textFragmentsSize; ++i) { | 90 for (unsigned i = 0; i < textFragmentsSize; ++i) { |
| 296 SVGTextFragment& fragment = m_textFragments.at(i); | 91 SVGTextFragment& fragment = m_svgInlineTextBox.textFragments().at(i); |
| 297 | 92 |
| 298 GraphicsContextStateSaver stateSaver(*paintInfo.context, false); | 93 GraphicsContextStateSaver stateSaver(*paintInfo.context, false); |
| 299 fragment.buildFragmentTransform(fragmentTransform); | 94 fragment.buildFragmentTransform(fragmentTransform); |
| 300 if (!fragmentTransform.isIdentity()) { | 95 if (!fragmentTransform.isIdentity()) { |
| 301 stateSaver.save(); | 96 stateSaver.save(); |
| 302 paintInfo.context->concatCTM(fragmentTransform); | 97 paintInfo.context->concatCTM(fragmentTransform); |
| 303 } | 98 } |
| 304 | 99 |
| 305 // Spec: All text decorations except line-through should be drawn before the text is filled and stroked; thus, the text is rendered on top of these deco rations. | 100 // Spec: All text decorations except line-through should be drawn before the text is filled and stroked; thus, the text is rendered on top of these deco rations. |
| 306 unsigned decorations = style->textDecorationsInEffect(); | 101 unsigned decorations = style->textDecorationsInEffect(); |
| (...skipping 30 matching lines...) Expand all Loading... | |
| 337 // Spec: Line-through should be drawn after the text is filled and strok ed; thus, the line-through is rendered on top of the text. | 132 // Spec: Line-through should be drawn after the text is filled and strok ed; thus, the line-through is rendered on top of the text. |
| 338 if (decorations & TextDecorationLineThrough) | 133 if (decorations & TextDecorationLineThrough) |
| 339 paintDecoration(paintInfo.context, TextDecorationLineThrough, fragme nt); | 134 paintDecoration(paintInfo.context, TextDecorationLineThrough, fragme nt); |
| 340 } | 135 } |
| 341 | 136 |
| 342 // finally, paint the outline if any | 137 // finally, paint the outline if any |
| 343 if (style->hasOutline() && parentRenderer.isRenderInline()) | 138 if (style->hasOutline() && parentRenderer.isRenderInline()) |
| 344 InlinePainter(toRenderInline(parentRenderer)).paintOutline(paintInfo, pa intOffset); | 139 InlinePainter(toRenderInline(parentRenderer)).paintOutline(paintInfo, pa intOffset); |
| 345 } | 140 } |
| 346 | 141 |
| 347 class PaintingResourceScope { | 142 void SVGInlineTextBoxPainter::paintSelectionBackground(PaintInfo& paintInfo) |
| 348 public: | 143 { |
| 349 PaintingResourceScope(RenderObject& renderer) | 144 ASSERT(paintInfo.shouldPaintWithinRoot(&renderer())); |
| 350 : m_renderer(renderer) | 145 ASSERT(paintInfo.phase == PaintPhaseForeground || paintInfo.phase == PaintPh aseSelection); |
| 351 , m_paintingResource(0) | 146 ASSERT(m_svgInlineTextBox.truncation() == cNoTruncation); |
| 352 { | |
| 353 } | |
| 354 ~PaintingResourceScope() { ASSERT(!m_paintingResource); } | |
| 355 | 147 |
| 356 bool acquirePaintingResource(GraphicsContext*&, RenderStyle*, RenderSVGResou rceModeFlags); | 148 if (m_svgInlineTextBox.renderer().style()->visibility() != VISIBLE) |
| 357 void releasePaintingResource(GraphicsContext*&); | 149 return; |
| 358 | 150 |
| 359 private: | 151 RenderObject& parentRenderer = m_svgInlineTextBox.parent()->renderer(); |
| 360 RenderObject& m_renderer; | 152 ASSERT(!parentRenderer.document().printing()); |
| 361 RenderSVGResource* m_paintingResource; | |
| 362 }; | |
| 363 | 153 |
| 364 bool PaintingResourceScope::acquirePaintingResource(GraphicsContext*& context, R enderStyle* style, RenderSVGResourceModeFlags resourceModeFlags) | 154 // Determine whether or not we're selected. |
| 365 { | 155 bool paintSelectedTextOnly = paintInfo.phase == PaintPhaseSelection; |
| 366 ASSERT(style); | 156 bool hasSelection = m_svgInlineTextBox.selectionState() != RenderObject::Sel ectionNone; |
| 367 ASSERT(resourceModeFlags != ApplyToDefaultMode); | 157 if (!hasSelection || paintSelectedTextOnly) |
| 368 RenderSVGResourceMode resourceMode = static_cast<RenderSVGResourceMode>(reso urceModeFlags & (ApplyToFillMode | ApplyToStrokeMode)); | 158 return; |
| 369 ASSERT(resourceMode == ApplyToFillMode || resourceMode == ApplyToStrokeMode) ; | |
| 370 | 159 |
| 371 bool hasFallback = false; | 160 Color backgroundColor = m_svgInlineTextBox.renderer().selectionBackgroundCol or(); |
| 372 m_paintingResource = RenderSVGResource::requestPaintingResource(resourceMode , &m_renderer, style, hasFallback); | 161 if (!backgroundColor.alpha()) |
| 373 if (!m_paintingResource) | 162 return; |
| 374 return false; | |
| 375 | 163 |
| 376 if (!m_paintingResource->applyResource(&m_renderer, style, context, resource ModeFlags)) { | 164 RenderSVGInlineText& textRenderer = toRenderSVGInlineText(m_svgInlineTextBox .renderer()); |
| 377 if (hasFallback) { | 165 if (!textShouldBePainted(textRenderer)) |
| 378 m_paintingResource = RenderSVGResource::sharedSolidPaintingResource( ); | 166 return; |
| 379 m_paintingResource->applyResource(&m_renderer, style, context, resou rceModeFlags); | |
| 380 } | |
| 381 } | |
| 382 return true; | |
| 383 } | |
| 384 | 167 |
| 385 void PaintingResourceScope::releasePaintingResource(GraphicsContext*& context) | 168 RenderStyle* style = parentRenderer.style(); |
| 386 { | |
| 387 ASSERT(m_paintingResource); | |
| 388 | |
| 389 m_paintingResource->postApplyResource(&m_renderer, context); | |
| 390 m_paintingResource = 0; | |
| 391 } | |
| 392 | |
| 393 TextRun SVGInlineTextBox::constructTextRun(RenderStyle* style, const SVGTextFrag ment& fragment) const | |
| 394 { | |
| 395 ASSERT(style); | 169 ASSERT(style); |
| 396 | 170 |
| 397 RenderText* text = &renderer(); | 171 int startPosition, endPosition; |
| 172 m_svgInlineTextBox.selectionStartEnd(startPosition, endPosition); | |
| 398 | 173 |
| 399 // FIXME(crbug.com/264211): This should not be necessary but can occur if we | 174 int fragmentStartPosition = 0; |
| 400 // layout during layout. Remove this when 264211 is fixed. | 175 int fragmentEndPosition = 0; |
| 401 RELEASE_ASSERT(!text->needsLayout()); | 176 AffineTransform fragmentTransform; |
| 177 unsigned textFragmentsSize = m_svgInlineTextBox.textFragments().size(); | |
| 178 for (unsigned i = 0; i < textFragmentsSize; ++i) { | |
| 179 SVGTextFragment& fragment = m_svgInlineTextBox.textFragments().at(i); | |
| 402 | 180 |
| 403 TextRun run(static_cast<const LChar*>(0) // characters, will be set below if non-zero. | 181 fragmentStartPosition = startPosition; |
| 404 , 0 // length, will be set below if non-zero. | 182 fragmentEndPosition = endPosition; |
| 405 , 0 // xPos, only relevant with allowTabs=true | 183 if (!m_svgInlineTextBox.mapStartEndPositionsIntoFragmentCoordinates(frag ment, fragmentStartPosition, fragmentEndPosition)) |
| 406 , 0 // padding, only relevant for justified text, not relevant f or SVG | 184 continue; |
| 407 , TextRun::AllowTrailingExpansion | |
| 408 , direction() | |
| 409 , dirOverride() || style->rtlOrdering() == VisualOrder /* direct ionalOverride */); | |
| 410 | 185 |
| 411 if (fragment.length) { | 186 GraphicsContextStateSaver stateSaver(*paintInfo.context); |
| 412 if (text->is8Bit()) | 187 fragment.buildFragmentTransform(fragmentTransform); |
| 413 run.setText(text->characters8() + fragment.characterOffset, fragment .length); | 188 if (!fragmentTransform.isIdentity()) |
| 414 else | 189 paintInfo.context->concatCTM(fragmentTransform); |
| 415 run.setText(text->characters16() + fragment.characterOffset, fragmen t.length); | 190 |
| 191 paintInfo.context->setFillColor(backgroundColor); | |
| 192 paintInfo.context->fillRect(m_svgInlineTextBox.selectionRectForTextFragm ent(fragment, fragmentStartPosition, fragmentEndPosition, style), backgroundColo r); | |
| 416 } | 193 } |
| 417 | |
| 418 if (textRunNeedsRenderingContext(style->font())) | |
| 419 run.setRenderingContext(SVGTextRunRenderingContext::create(text)); | |
| 420 | |
| 421 // We handle letter & word spacing ourselves. | |
| 422 run.disableSpacing(); | |
| 423 | |
| 424 // Propagate the maximum length of the characters buffer to the TextRun, eve n when we're only processing a substring. | |
| 425 run.setCharactersLength(text->textLength() - fragment.characterOffset); | |
| 426 ASSERT(run.charactersLength() >= run.length()); | |
| 427 return run; | |
| 428 } | |
| 429 | |
| 430 bool SVGInlineTextBox::mapStartEndPositionsIntoFragmentCoordinates(const SVGText Fragment& fragment, int& startPosition, int& endPosition) const | |
| 431 { | |
| 432 if (startPosition >= endPosition) | |
| 433 return false; | |
| 434 | |
| 435 int offset = static_cast<int>(fragment.characterOffset) - start(); | |
| 436 int length = static_cast<int>(fragment.length); | |
| 437 | |
| 438 if (startPosition >= offset + length || endPosition <= offset) | |
| 439 return false; | |
| 440 | |
| 441 if (startPosition < offset) | |
| 442 startPosition = 0; | |
| 443 else | |
| 444 startPosition -= offset; | |
| 445 | |
| 446 if (endPosition > offset + length) | |
| 447 endPosition = length; | |
| 448 else { | |
| 449 ASSERT(endPosition >= offset); | |
| 450 endPosition -= offset; | |
| 451 } | |
| 452 | |
| 453 ASSERT(startPosition < endPosition); | |
| 454 return true; | |
| 455 } | |
| 456 | |
| 457 // Offset from the baseline for |decoration|. Positive offsets are above the bas eline. | |
| 458 static inline float baselineOffsetForDecoration(TextDecoration decoration, const FontMetrics& fontMetrics, float thickness) | |
| 459 { | |
| 460 // FIXME: For SVG Fonts we need to use the attributes defined in the <font-f ace> if specified. | |
| 461 // Compatible with Batik/Presto. | |
| 462 if (decoration == TextDecorationUnderline) | |
| 463 return -thickness * 1.5f; | |
| 464 if (decoration == TextDecorationOverline) | |
| 465 return fontMetrics.floatAscent() - thickness; | |
| 466 if (decoration == TextDecorationLineThrough) | |
| 467 return fontMetrics.floatAscent() * 3 / 8.0f; | |
| 468 | |
| 469 ASSERT_NOT_REACHED(); | |
| 470 return 0.0f; | |
| 471 } | |
| 472 | |
| 473 static inline float thicknessForDecoration(TextDecoration, const Font& font) | |
| 474 { | |
| 475 // FIXME: For SVG Fonts we need to use the attributes defined in the <font-f ace> if specified. | |
| 476 // Compatible with Batik/Presto | |
| 477 return font.fontDescription().computedSize() / 20.0f; | |
| 478 } | 194 } |
| 479 | 195 |
| 480 static inline RenderObject* findRenderObjectDefininingTextDecoration(InlineFlowB ox* parentBox) | 196 static inline RenderObject* findRenderObjectDefininingTextDecoration(InlineFlowB ox* parentBox) |
| 481 { | 197 { |
| 482 // Lookup first render object in parent hierarchy which has text-decoration set. | 198 // Lookup first render object in parent hierarchy which has text-decoration set. |
| 483 RenderObject* renderer = 0; | 199 RenderObject* renderer = 0; |
| 484 while (parentBox) { | 200 while (parentBox) { |
| 485 renderer = &parentBox->renderer(); | 201 renderer = &parentBox->renderer(); |
| 486 | 202 |
| 487 if (renderer->style() && renderer->style()->textDecoration() != TextDeco rationNone) | 203 if (renderer->style() && renderer->style()->textDecoration() != TextDeco rationNone) |
| 488 break; | 204 break; |
| 489 | 205 |
| 490 parentBox = parentBox->parent(); | 206 parentBox = parentBox->parent(); |
| 491 } | 207 } |
| 492 | 208 |
| 493 ASSERT(renderer); | 209 ASSERT(renderer); |
| 494 return renderer; | 210 return renderer; |
| 495 } | 211 } |
| 496 | 212 |
| 497 void SVGInlineTextBox::paintDecoration(GraphicsContext* context, TextDecoration decoration, const SVGTextFragment& fragment) | 213 void SVGInlineTextBoxPainter::paintDecoration(GraphicsContext* context, TextDeco ration decoration, const SVGTextFragment& fragment) |
| 498 { | 214 { |
| 499 if (renderer().style()->textDecorationsInEffect() == TextDecorationNone) | 215 if (m_svgInlineTextBox.renderer().style()->textDecorationsInEffect() == Text DecorationNone) |
| 500 return; | 216 return; |
| 501 | 217 |
| 502 // Find out which render style defined the text-decoration, as its fill/stro ke properties have to be used for drawing instead of ours. | 218 // Find out which render style defined the text-decoration, as its fill/stro ke properties have to be used for drawing instead of ours. |
| 503 RenderObject* decorationRenderer = findRenderObjectDefininingTextDecoration( parent()); | 219 RenderObject* decorationRenderer = findRenderObjectDefininingTextDecoration( m_svgInlineTextBox.parent()); |
| 504 RenderStyle* decorationStyle = decorationRenderer->style(); | 220 RenderStyle* decorationStyle = decorationRenderer->style(); |
| 505 ASSERT(decorationStyle); | 221 ASSERT(decorationStyle); |
| 506 | 222 |
| 507 if (decorationStyle->visibility() == HIDDEN) | 223 if (decorationStyle->visibility() == HIDDEN) |
| 508 return; | 224 return; |
| 509 | 225 |
| 510 const SVGRenderStyle& svgDecorationStyle = decorationStyle->svgStyle(); | 226 const SVGRenderStyle& svgDecorationStyle = decorationStyle->svgStyle(); |
| 511 | 227 |
| 512 for (int i = 0; i < 3; i++) { | 228 for (int i = 0; i < 3; i++) { |
| 513 switch (svgDecorationStyle.paintOrderType(i)) { | 229 switch (svgDecorationStyle.paintOrderType(i)) { |
| 514 case PT_FILL: | 230 case PT_FILL: |
| 515 if (svgDecorationStyle.hasFill()) | 231 if (svgDecorationStyle.hasFill()) |
| 516 paintDecorationWithStyle(context, decoration, fragment, decorati onRenderer, ApplyToFillMode); | 232 paintDecorationWithStyle(context, decoration, fragment, decorati onRenderer, ApplyToFillMode); |
| 517 break; | 233 break; |
| 518 case PT_STROKE: | 234 case PT_STROKE: |
| 519 if (svgDecorationStyle.hasVisibleStroke()) | 235 if (svgDecorationStyle.hasVisibleStroke()) |
| 520 paintDecorationWithStyle(context, decoration, fragment, decorati onRenderer, ApplyToStrokeMode); | 236 paintDecorationWithStyle(context, decoration, fragment, decorati onRenderer, ApplyToStrokeMode); |
| 521 break; | 237 break; |
| 522 case PT_MARKERS: | 238 case PT_MARKERS: |
| 523 break; | 239 break; |
| 524 default: | 240 default: |
| 525 ASSERT_NOT_REACHED(); | 241 ASSERT_NOT_REACHED(); |
| 526 } | 242 } |
| 527 } | 243 } |
| 528 } | 244 } |
| 529 | 245 |
| 530 void SVGInlineTextBox::paintDecorationWithStyle(GraphicsContext* context, TextDe coration decoration, | 246 // Offset from the baseline for |decoration|. Positive offsets are above the bas eline. |
| 247 static inline float baselineOffsetForDecoration(TextDecoration decoration, const FontMetrics& fontMetrics, float thickness) | |
| 248 { | |
| 249 // FIXME: For SVG Fonts we need to use the attributes defined in the <font-f ace> if specified. | |
| 250 // Compatible with Batik/Presto. | |
| 251 if (decoration == TextDecorationUnderline) | |
| 252 return -thickness * 1.5f; | |
| 253 if (decoration == TextDecorationOverline) | |
| 254 return fontMetrics.floatAscent() - thickness; | |
| 255 if (decoration == TextDecorationLineThrough) | |
| 256 return fontMetrics.floatAscent() * 3 / 8.0f; | |
| 257 | |
| 258 ASSERT_NOT_REACHED(); | |
| 259 return 0.0f; | |
| 260 } | |
| 261 | |
| 262 static inline float thicknessForDecoration(TextDecoration, const Font& font) | |
| 263 { | |
| 264 // FIXME: For SVG Fonts we need to use the attributes defined in the <font-f ace> if specified. | |
| 265 // Compatible with Batik/Presto | |
| 266 return font.fontDescription().computedSize() / 20.0f; | |
| 267 } | |
| 268 | |
| 269 class PaintingResourceScope { | |
| 270 public: | |
| 271 PaintingResourceScope(RenderObject& renderer) | |
| 272 : m_renderer(renderer) | |
| 273 , m_paintingResource(0) | |
| 274 { | |
| 275 } | |
| 276 ~PaintingResourceScope() { ASSERT(!m_paintingResource); } | |
| 277 | |
| 278 bool acquirePaintingResource(GraphicsContext*&, RenderStyle*, RenderSVGResou rceModeFlags); | |
| 279 void releasePaintingResource(GraphicsContext*&); | |
| 280 | |
| 281 private: | |
| 282 RenderObject& m_renderer; | |
| 283 RenderSVGResource* m_paintingResource; | |
| 284 }; | |
| 285 | |
| 286 bool PaintingResourceScope::acquirePaintingResource(GraphicsContext*& context, R enderStyle* style, RenderSVGResourceModeFlags resourceModeFlags) | |
| 287 { | |
| 288 ASSERT(style); | |
| 289 ASSERT(resourceModeFlags != ApplyToDefaultMode); | |
|
fs
2014/10/06 08:34:53
...and here (https://codereview.chromium.org/62239
| |
| 290 RenderSVGResourceMode resourceMode = static_cast<RenderSVGResourceMode>(reso urceModeFlags & (ApplyToFillMode | ApplyToStrokeMode)); | |
| 291 ASSERT(resourceMode == ApplyToFillMode || resourceMode == ApplyToStrokeMode) ; | |
| 292 | |
| 293 bool hasFallback = false; | |
| 294 m_paintingResource = RenderSVGResource::requestPaintingResource(resourceMode , &m_renderer, style, hasFallback); | |
| 295 if (!m_paintingResource) | |
| 296 return false; | |
| 297 | |
| 298 if (!m_paintingResource->applyResource(&m_renderer, style, context, resource ModeFlags)) { | |
| 299 if (hasFallback) { | |
| 300 m_paintingResource = RenderSVGResource::sharedSolidPaintingResource( ); | |
| 301 m_paintingResource->applyResource(&m_renderer, style, context, resou rceModeFlags); | |
| 302 } | |
| 303 } | |
| 304 return true; | |
| 305 } | |
| 306 | |
| 307 void PaintingResourceScope::releasePaintingResource(GraphicsContext*& context) | |
| 308 { | |
| 309 ASSERT(m_paintingResource); | |
| 310 | |
| 311 m_paintingResource->postApplyResource(&m_renderer, context); | |
| 312 m_paintingResource = 0; | |
| 313 } | |
| 314 | |
| 315 | |
| 316 void SVGInlineTextBoxPainter::paintDecorationWithStyle(GraphicsContext* context, TextDecoration decoration, | |
| 531 const SVGTextFragment& fragment, RenderObject* decorationRenderer, RenderSVG ResourceModeFlags resourceMode) | 317 const SVGTextFragment& fragment, RenderObject* decorationRenderer, RenderSVG ResourceModeFlags resourceMode) |
| 532 { | 318 { |
| 533 ASSERT(resourceMode != ApplyToDefaultMode); | 319 ASSERT(resourceMode != ApplyToDefaultMode); |
| 534 | 320 |
| 535 RenderStyle* decorationStyle = decorationRenderer->style(); | 321 RenderStyle* decorationStyle = decorationRenderer->style(); |
| 536 ASSERT(decorationStyle); | 322 ASSERT(decorationStyle); |
| 537 | 323 |
| 538 float scalingFactor = 1; | 324 float scalingFactor = 1; |
| 539 Font scaledFont; | 325 Font scaledFont; |
| 540 RenderSVGInlineText::computeNewScaledFontForStyle(decorationRenderer, decora tionStyle, scalingFactor, scaledFont); | 326 RenderSVGInlineText::computeNewScaledFontForStyle(decorationRenderer, decora tionStyle, scalingFactor, scaledFont); |
| (...skipping 10 matching lines...) Expand all Loading... | |
| 551 Path path; | 337 Path path; |
| 552 path.addRect(FloatRect(decorationOrigin, FloatSize(fragment.width, thickness / scalingFactor))); | 338 path.addRect(FloatRect(decorationOrigin, FloatSize(fragment.width, thickness / scalingFactor))); |
| 553 | 339 |
| 554 PaintingResourceScope resourceScope(*decorationRenderer); | 340 PaintingResourceScope resourceScope(*decorationRenderer); |
| 555 if (resourceScope.acquirePaintingResource(context, decorationStyle, resource Mode)) { | 341 if (resourceScope.acquirePaintingResource(context, decorationStyle, resource Mode)) { |
| 556 SVGRenderSupport::fillOrStrokePath(context, resourceMode, path); | 342 SVGRenderSupport::fillOrStrokePath(context, resourceMode, path); |
| 557 resourceScope.releasePaintingResource(context); | 343 resourceScope.releasePaintingResource(context); |
| 558 } | 344 } |
| 559 } | 345 } |
| 560 | 346 |
| 561 void SVGInlineTextBox::paintTextWithShadows(GraphicsContext* context, RenderStyl e* style, | 347 void SVGInlineTextBoxPainter::paintTextWithShadows(GraphicsContext* context, Ren derStyle* style, |
| 562 TextRun& textRun, const SVGTextFragment& fragment, int startPosition, int en dPosition, | 348 TextRun& textRun, const SVGTextFragment& fragment, int startPosition, int en dPosition, |
| 563 RenderSVGResourceModeFlags resourceMode) | 349 RenderSVGResourceModeFlags resourceMode) |
| 564 { | 350 { |
| 565 RenderSVGInlineText& textRenderer = toRenderSVGInlineText(this->renderer()); | 351 RenderSVGInlineText& textRenderer = toRenderSVGInlineText(m_svgInlineTextBox .renderer()); |
| 566 | 352 |
| 567 float scalingFactor = textRenderer.scalingFactor(); | 353 float scalingFactor = textRenderer.scalingFactor(); |
| 568 ASSERT(scalingFactor); | 354 ASSERT(scalingFactor); |
| 569 | 355 |
| 570 const Font& scaledFont = textRenderer.scaledFont(); | 356 const Font& scaledFont = textRenderer.scaledFont(); |
| 571 const ShadowList* shadowList = style->textShadow(); | 357 const ShadowList* shadowList = style->textShadow(); |
| 572 | 358 |
| 573 // Text shadows are disabled when printing. http://crbug.com/258321 | 359 // Text shadows are disabled when printing. http://crbug.com/258321 |
| 574 bool hasShadow = shadowList && !context->printing(); | 360 bool hasShadow = shadowList && !context->printing(); |
| 575 | 361 |
| 576 FloatPoint textOrigin(fragment.x, fragment.y); | 362 FloatPoint textOrigin(fragment.x, fragment.y); |
| 577 FloatSize textSize(fragment.width, fragment.height); | 363 FloatSize textSize(fragment.width, fragment.height); |
| 578 | 364 |
| 579 if (scalingFactor != 1) { | 365 if (scalingFactor != 1) { |
| 580 textOrigin.scale(scalingFactor, scalingFactor); | 366 textOrigin.scale(scalingFactor, scalingFactor); |
| 581 textSize.scale(scalingFactor); | 367 textSize.scale(scalingFactor); |
| 582 context->save(); | 368 context->save(); |
| 583 context->scale(1 / scalingFactor, 1 / scalingFactor); | 369 context->scale(1 / scalingFactor, 1 / scalingFactor); |
| 584 } | 370 } |
| 585 | 371 |
| 586 if (hasShadow) | 372 if (hasShadow) |
| 587 context->setDrawLooper(shadowList->createDrawLooper(DrawLooperBuilder::S hadowRespectsAlpha)); | 373 context->setDrawLooper(shadowList->createDrawLooper(DrawLooperBuilder::S hadowRespectsAlpha)); |
| 588 | 374 |
| 589 PaintingResourceScope resourceScope(parent()->renderer()); | 375 PaintingResourceScope resourceScope(m_svgInlineTextBox.parent()->renderer()) ; |
| 590 if (resourceScope.acquirePaintingResource(context, style, resourceMode)) { | 376 if (resourceScope.acquirePaintingResource(context, style, resourceMode)) { |
| 591 if (scalingFactor != 1 && resourceMode & ApplyToStrokeMode) | 377 if (scalingFactor != 1 && resourceMode & ApplyToStrokeMode) |
| 592 context->setStrokeThickness(context->strokeThickness() * scalingFact or); | 378 context->setStrokeThickness(context->strokeThickness() * scalingFact or); |
| 593 | 379 |
| 594 TextRunPaintInfo textRunPaintInfo(textRun); | 380 TextRunPaintInfo textRunPaintInfo(textRun); |
| 595 textRunPaintInfo.from = startPosition; | 381 textRunPaintInfo.from = startPosition; |
| 596 textRunPaintInfo.to = endPosition; | 382 textRunPaintInfo.to = endPosition; |
| 597 | 383 |
| 598 float baseline = scaledFont.fontMetrics().floatAscent(); | 384 float baseline = scaledFont.fontMetrics().floatAscent(); |
| 599 textRunPaintInfo.bounds = FloatRect(textOrigin.x(), textOrigin.y() - bas eline, | 385 textRunPaintInfo.bounds = FloatRect(textOrigin.x(), textOrigin.y() - bas eline, |
| 600 textSize.width(), textSize.height()); | 386 textSize.width(), textSize.height()); |
| 601 | 387 |
| 602 scaledFont.drawText(context, textRunPaintInfo, textOrigin); | 388 scaledFont.drawText(context, textRunPaintInfo, textOrigin); |
| 603 resourceScope.releasePaintingResource(context); | 389 resourceScope.releasePaintingResource(context); |
| 604 } | 390 } |
| 605 | 391 |
| 606 if (scalingFactor != 1) | 392 if (scalingFactor != 1) |
| 607 context->restore(); | 393 context->restore(); |
| 608 else if (hasShadow) | 394 else if (hasShadow) |
| 609 context->clearShadow(); | 395 context->clearShadow(); |
| 610 } | 396 } |
| 611 | 397 |
| 612 void SVGInlineTextBox::paintText(GraphicsContext* context, RenderStyle* style, | 398 void SVGInlineTextBoxPainter::paintText(GraphicsContext* context, RenderStyle* s tyle, |
| 613 RenderStyle* selectionStyle, const SVGTextFragment& fragment, | 399 RenderStyle* selectionStyle, const SVGTextFragment& fragment, |
| 614 RenderSVGResourceModeFlags resourceMode, bool hasSelection, bool paintSelect edTextOnly) | 400 RenderSVGResourceModeFlags resourceMode, bool hasSelection, bool paintSelect edTextOnly) |
| 615 { | 401 { |
| 616 ASSERT(style); | 402 ASSERT(style); |
| 617 ASSERT(selectionStyle); | 403 ASSERT(selectionStyle); |
| 618 | 404 |
| 619 int startPosition = 0; | 405 int startPosition = 0; |
| 620 int endPosition = 0; | 406 int endPosition = 0; |
| 621 if (hasSelection) { | 407 if (hasSelection) { |
| 622 selectionStartEnd(startPosition, endPosition); | 408 m_svgInlineTextBox.selectionStartEnd(startPosition, endPosition); |
| 623 hasSelection = mapStartEndPositionsIntoFragmentCoordinates(fragment, sta rtPosition, endPosition); | 409 hasSelection = m_svgInlineTextBox.mapStartEndPositionsIntoFragmentCoordi nates(fragment, startPosition, endPosition); |
| 624 } | 410 } |
| 625 | 411 |
| 626 // Fast path if there is no selection, just draw the whole chunk part using the regular style | 412 // Fast path if there is no selection, just draw the whole chunk part using the regular style |
| 627 TextRun textRun = constructTextRun(style, fragment); | 413 TextRun textRun = m_svgInlineTextBox.constructTextRun(style, fragment); |
| 628 if (!hasSelection || startPosition >= endPosition) { | 414 if (!hasSelection || startPosition >= endPosition) { |
| 629 paintTextWithShadows(context, style, textRun, fragment, 0, fragment.leng th, resourceMode); | 415 paintTextWithShadows(context, style, textRun, fragment, 0, fragment.leng th, resourceMode); |
| 630 return; | 416 return; |
| 631 } | 417 } |
| 632 | 418 |
| 633 // Eventually draw text using regular style until the start position of the selection | 419 // Eventually draw text using regular style until the start position of the selection |
| 634 if (startPosition > 0 && !paintSelectedTextOnly) | 420 if (startPosition > 0 && !paintSelectedTextOnly) |
| 635 paintTextWithShadows(context, style, textRun, fragment, 0, startPosition , resourceMode); | 421 paintTextWithShadows(context, style, textRun, fragment, 0, startPosition , resourceMode); |
| 636 | 422 |
| 637 // Draw text using selection style from the start to the end position of the selection | 423 // Draw text using selection style from the start to the end position of the selection |
| 638 if (style != selectionStyle) { | 424 if (style != selectionStyle) { |
| 639 StyleDifference diff; | 425 StyleDifference diff; |
| 640 diff.setNeedsPaintInvalidationObject(); | 426 diff.setNeedsPaintInvalidationObject(); |
| 641 SVGResourcesCache::clientStyleChanged(&parent()->renderer(), diff, selec tionStyle); | 427 SVGResourcesCache::clientStyleChanged(&m_svgInlineTextBox.parent()->rend erer(), diff, selectionStyle); |
| 642 } | 428 } |
| 643 | 429 |
| 644 paintTextWithShadows(context, selectionStyle, textRun, fragment, startPositi on, endPosition, resourceMode); | 430 paintTextWithShadows(context, selectionStyle, textRun, fragment, startPositi on, endPosition, resourceMode); |
| 645 | 431 |
| 646 if (style != selectionStyle) { | 432 if (style != selectionStyle) { |
| 647 StyleDifference diff; | 433 StyleDifference diff; |
| 648 diff.setNeedsPaintInvalidationObject(); | 434 diff.setNeedsPaintInvalidationObject(); |
| 649 SVGResourcesCache::clientStyleChanged(&parent()->renderer(), diff, style ); | 435 SVGResourcesCache::clientStyleChanged(&m_svgInlineTextBox.parent()->rend erer(), diff, style); |
| 650 } | 436 } |
| 651 | 437 |
| 652 // Eventually draw text using regular style from the end position of the sel ection to the end of the current chunk part | 438 // Eventually draw text using regular style from the end position of the sel ection to the end of the current chunk part |
| 653 if (endPosition < static_cast<int>(fragment.length) && !paintSelectedTextOnl y) | 439 if (endPosition < static_cast<int>(fragment.length) && !paintSelectedTextOnl y) |
| 654 paintTextWithShadows(context, style, textRun, fragment, endPosition, fra gment.length, resourceMode); | 440 paintTextWithShadows(context, style, textRun, fragment, endPosition, fra gment.length, resourceMode); |
| 655 } | 441 } |
| 656 | 442 |
| 657 void SVGInlineTextBox::paintDocumentMarker(GraphicsContext*, const FloatPoint&, DocumentMarker*, RenderStyle*, const Font&, bool) | 443 void SVGInlineTextBoxPainter::paintTextMatchMarker(GraphicsContext* context, con st FloatPoint&, DocumentMarker* marker, RenderStyle* style, const Font& font) |
| 658 { | |
| 659 // SVG does not have support for generic document markers (e.g., spellchecki ng, etc). | |
| 660 } | |
| 661 | |
| 662 void SVGInlineTextBox::paintTextMatchMarker(GraphicsContext* context, const Floa tPoint&, DocumentMarker* marker, RenderStyle* style, const Font& font) | |
| 663 { | 444 { |
| 664 // SVG is only interested in the TextMatch markers. | 445 // SVG is only interested in the TextMatch markers. |
| 665 if (marker->type() != DocumentMarker::TextMatch) | 446 if (marker->type() != DocumentMarker::TextMatch) |
| 666 return; | 447 return; |
| 667 | 448 |
| 668 RenderSVGInlineText& textRenderer = toRenderSVGInlineText(this->renderer()); | 449 RenderSVGInlineText& textRenderer = toRenderSVGInlineText(m_svgInlineTextBox .renderer()); |
| 669 | 450 |
| 670 FloatRect markerRect; | 451 FloatRect markerRect; |
| 671 AffineTransform fragmentTransform; | 452 AffineTransform fragmentTransform; |
| 672 for (InlineTextBox* box = textRenderer.firstTextBox(); box; box = box->nextT extBox()) { | 453 for (InlineTextBox* box = textRenderer.firstTextBox(); box; box = box->nextT extBox()) { |
| 673 if (!box->isSVGInlineTextBox()) | 454 if (!box->isSVGInlineTextBox()) |
| 674 continue; | 455 continue; |
| 675 | 456 |
| 676 SVGInlineTextBox* textBox = toSVGInlineTextBox(box); | 457 SVGInlineTextBox* textBox = toSVGInlineTextBox(box); |
| 677 | 458 |
| 678 int markerStartPosition = std::max<int>(marker->startOffset() - textBox- >start(), 0); | 459 int markerStartPosition = std::max<int>(marker->startOffset() - textBox- >start(), 0); |
| 679 int markerEndPosition = std::min<int>(marker->endOffset() - textBox->sta rt(), textBox->len()); | 460 int markerEndPosition = std::min<int>(marker->endOffset() - textBox->sta rt(), textBox->len()); |
| 680 | 461 |
| 681 if (markerStartPosition >= markerEndPosition) | 462 if (markerStartPosition >= markerEndPosition) |
| 682 continue; | 463 continue; |
| 683 | 464 |
| 684 const Vector<SVGTextFragment>& fragments = textBox->textFragments(); | 465 const Vector<SVGTextFragment>& fragments = textBox->textFragments(); |
| 685 unsigned textFragmentsSize = fragments.size(); | 466 unsigned textFragmentsSize = fragments.size(); |
| 686 for (unsigned i = 0; i < textFragmentsSize; ++i) { | 467 for (unsigned i = 0; i < textFragmentsSize; ++i) { |
| 687 const SVGTextFragment& fragment = fragments.at(i); | 468 const SVGTextFragment& fragment = fragments.at(i); |
| 688 | 469 |
| 689 int fragmentStartPosition = markerStartPosition; | 470 int fragmentStartPosition = markerStartPosition; |
| 690 int fragmentEndPosition = markerEndPosition; | 471 int fragmentEndPosition = markerEndPosition; |
| 691 if (!textBox->mapStartEndPositionsIntoFragmentCoordinates(fragment, fragmentStartPosition, fragmentEndPosition)) | 472 if (!textBox->mapStartEndPositionsIntoFragmentCoordinates(fragment, fragmentStartPosition, fragmentEndPosition)) |
| 692 continue; | 473 continue; |
| 693 | 474 |
| 694 FloatRect fragmentRect = textBox->selectionRectForTextFragment(fragm ent, fragmentStartPosition, fragmentEndPosition, style); | 475 FloatRect fragmentRect = textBox->selectionRectForTextFragment(fragm ent, fragmentStartPosition, fragmentEndPosition, style); |
| 695 fragment.buildFragmentTransform(fragmentTransform); | 476 fragment.buildFragmentTransform(fragmentTransform); |
| 696 | 477 |
| 697 // Draw the marker highlight. | 478 // Draw the marker highlight. |
| 698 if (renderer().frame()->editor().markedTextMatchesAreHighlighted()) { | 479 if (m_svgInlineTextBox.renderer().frame()->editor().markedTextMatche sAreHighlighted()) { |
| 699 Color color = marker->activeMatch() ? | 480 Color color = marker->activeMatch() ? |
| 700 RenderTheme::theme().platformActiveTextSearchHighlightColor( ) : | 481 RenderTheme::theme().platformActiveTextSearchHighlightColor( ) : |
| 701 RenderTheme::theme().platformInactiveTextSearchHighlightColo r(); | 482 RenderTheme::theme().platformInactiveTextSearchHighlightColo r(); |
| 702 GraphicsContextStateSaver stateSaver(*context); | 483 GraphicsContextStateSaver stateSaver(*context); |
| 703 if (!fragmentTransform.isIdentity()) | 484 if (!fragmentTransform.isIdentity()) |
| 704 context->concatCTM(fragmentTransform); | 485 context->concatCTM(fragmentTransform); |
| 705 context->setFillColor(color); | 486 context->setFillColor(color); |
| 706 context->fillRect(fragmentRect, color); | 487 context->fillRect(fragmentRect, color); |
| 707 } | 488 } |
| 708 | 489 |
| 709 fragmentRect = fragmentTransform.mapRect(fragmentRect); | 490 fragmentRect = fragmentTransform.mapRect(fragmentRect); |
| 710 markerRect.unite(fragmentRect); | 491 markerRect.unite(fragmentRect); |
| 711 } | 492 } |
| 712 } | 493 } |
| 713 | 494 |
| 714 toRenderedDocumentMarker(marker)->setRenderedRect(textRenderer.localToAbsolu teQuad(markerRect).enclosingBoundingBox()); | 495 toRenderedDocumentMarker(marker)->setRenderedRect(textRenderer.localToAbsolu teQuad(markerRect).enclosingBoundingBox()); |
| 715 } | 496 } |
| 716 | 497 |
| 717 FloatRect SVGInlineTextBox::calculateBoundaries() const | |
| 718 { | |
| 719 FloatRect textRect; | |
| 720 | |
| 721 RenderSVGInlineText& textRenderer = toRenderSVGInlineText(this->renderer()); | |
| 722 | |
| 723 float scalingFactor = textRenderer.scalingFactor(); | |
| 724 ASSERT(scalingFactor); | |
| 725 | |
| 726 float baseline = textRenderer.scaledFont().fontMetrics().floatAscent() / sca lingFactor; | |
| 727 | |
| 728 AffineTransform fragmentTransform; | |
| 729 unsigned textFragmentsSize = m_textFragments.size(); | |
| 730 for (unsigned i = 0; i < textFragmentsSize; ++i) { | |
| 731 const SVGTextFragment& fragment = m_textFragments.at(i); | |
| 732 FloatRect fragmentRect(fragment.x, fragment.y - baseline, fragment.width , fragment.height); | |
| 733 fragment.buildFragmentTransform(fragmentTransform); | |
| 734 fragmentRect = fragmentTransform.mapRect(fragmentRect); | |
| 735 | |
| 736 textRect.unite(fragmentRect); | |
| 737 } | |
| 738 | |
| 739 return textRect; | |
| 740 } | |
| 741 | |
| 742 bool SVGInlineTextBox::nodeAtPoint(const HitTestRequest& request, HitTestResult& result, const HitTestLocation& locationInContainer, const LayoutPoint& accumula tedOffset, LayoutUnit, LayoutUnit) | |
| 743 { | |
| 744 // FIXME: integrate with InlineTextBox::nodeAtPoint better. | |
| 745 ASSERT(!isLineBreak()); | |
| 746 | |
| 747 PointerEventsHitRules hitRules(PointerEventsHitRules::SVG_TEXT_HITTESTING, r equest, renderer().style()->pointerEvents()); | |
| 748 bool isVisible = renderer().style()->visibility() == VISIBLE; | |
| 749 if (isVisible || !hitRules.requireVisible) { | |
| 750 if (hitRules.canHitBoundingBox | |
| 751 || (hitRules.canHitStroke && (renderer().style()->svgStyle().hasStro ke() || !hitRules.requireStroke)) | |
| 752 || (hitRules.canHitFill && (renderer().style()->svgStyle().hasFill() || !hitRules.requireFill))) { | |
| 753 FloatPoint boxOrigin(x(), y()); | |
| 754 boxOrigin.moveBy(accumulatedOffset); | |
| 755 FloatRect rect(boxOrigin, size()); | |
| 756 if (locationInContainer.intersects(rect)) { | |
| 757 renderer().updateHitTestResult(result, locationInContainer.point () - toLayoutSize(accumulatedOffset)); | |
| 758 if (!result.addNodeToRectBasedTestResult(renderer().node(), requ est, locationInContainer, rect)) | |
| 759 return true; | |
| 760 } | |
| 761 } | |
| 762 } | |
| 763 return false; | |
| 764 } | |
| 765 | |
| 766 } // namespace blink | 498 } // namespace blink |
| OLD | NEW |