Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(717)

Side by Side Diff: Source/core/rendering/svg/SVGInlineTextBox.cpp

Issue 627773002: Move painting code from SVGInlineTextBox to SVGInlineTextBoxPainter. (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Fix debug build. Created 6 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 /** 1 /**
2 * Copyright (C) 2007 Rob Buis <buis@kde.org> 2 * Copyright (C) 2007 Rob Buis <buis@kde.org>
3 * Copyright (C) 2007 Nikolas Zimmermann <zimmermann@kde.org> 3 * Copyright (C) 2007 Nikolas Zimmermann <zimmermann@kde.org>
4 * Copyright (C) Research In Motion Limited 2010. All rights reserved. 4 * Copyright (C) Research In Motion Limited 2010. All rights reserved.
5 * 5 *
6 * This library is free software; you can redistribute it and/or 6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Library General Public 7 * modify it under the terms of the GNU Library General Public
8 * License as published by the Free Software Foundation; either 8 * License as published by the Free Software Foundation; either
9 * version 2 of the License, or (at your option) any later version. 9 * version 2 of the License, or (at your option) any later version.
10 * 10 *
11 * This library is distributed in the hope that it will be useful, 11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Library General Public License for more details. 14 * Library General Public License for more details.
15 * 15 *
16 * You should have received a copy of the GNU Library General Public License 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 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, 18 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
19 * Boston, MA 02110-1301, USA. 19 * Boston, MA 02110-1301, USA.
20 */ 20 */
21 21
22 #include "config.h" 22 #include "config.h"
23 #include "core/rendering/svg/SVGInlineTextBox.h" 23 #include "core/rendering/svg/SVGInlineTextBox.h"
24 24
25 #include "core/dom/DocumentMarkerController.h" 25 #include "core/dom/DocumentMarkerController.h"
26 #include "core/dom/RenderedDocumentMarker.h" 26 #include "core/dom/RenderedDocumentMarker.h"
27 #include "core/editing/Editor.h" 27 #include "core/editing/Editor.h"
28 #include "core/frame/LocalFrame.h" 28 #include "core/frame/LocalFrame.h"
29 #include "core/paint/InlinePainter.h" 29 #include "core/paint/SVGInlineTextBoxPainter.h"
30 #include "core/paint/InlineTextBoxPainter.h"
31 #include "core/rendering/HitTestResult.h" 30 #include "core/rendering/HitTestResult.h"
32 #include "core/rendering/InlineFlowBox.h" 31 #include "core/rendering/InlineFlowBox.h"
33 #include "core/rendering/PaintInfo.h" 32 #include "core/rendering/PaintInfo.h"
34 #include "core/rendering/PointerEventsHitRules.h" 33 #include "core/rendering/PointerEventsHitRules.h"
35 #include "core/rendering/RenderInline.h" 34 #include "core/rendering/RenderInline.h"
36 #include "core/rendering/RenderTheme.h" 35 #include "core/rendering/RenderTheme.h"
37 #include "core/rendering/style/ShadowList.h"
38 #include "core/rendering/svg/RenderSVGInlineText.h" 36 #include "core/rendering/svg/RenderSVGInlineText.h"
39 #include "core/rendering/svg/RenderSVGResource.h" 37 #include "core/rendering/svg/RenderSVGResource.h"
40 #include "core/rendering/svg/RenderSVGResourceSolidColor.h" 38 #include "core/rendering/svg/RenderSVGResourceSolidColor.h"
41 #include "core/rendering/svg/SVGRenderSupport.h"
42 #include "core/rendering/svg/SVGResourcesCache.h"
43 #include "core/rendering/svg/SVGTextRunRenderingContext.h" 39 #include "core/rendering/svg/SVGTextRunRenderingContext.h"
44 #include "platform/FloatConversion.h" 40 #include "platform/FloatConversion.h"
45 #include "platform/fonts/FontCache.h" 41 #include "platform/fonts/FontCache.h"
46 #include "platform/graphics/GraphicsContextStateSaver.h" 42 #include "platform/graphics/GraphicsContextStateSaver.h"
47 43
48 namespace blink { 44 namespace blink {
49 45
50 struct ExpectedSVGInlineTextBoxSize : public InlineTextBox { 46 struct ExpectedSVGInlineTextBoxSize : public InlineTextBox {
51 float float1; 47 float float1;
52 uint32_t bitfields : 1; 48 uint32_t bitfields : 1;
(...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after
169 FloatRect fragmentRect = selectionRectForTextFragment(fragment, fragment StartPosition, fragmentEndPosition, style); 165 FloatRect fragmentRect = selectionRectForTextFragment(fragment, fragment StartPosition, fragmentEndPosition, style);
170 fragment.buildFragmentTransform(fragmentTransform); 166 fragment.buildFragmentTransform(fragmentTransform);
171 fragmentRect = fragmentTransform.mapRect(fragmentRect); 167 fragmentRect = fragmentTransform.mapRect(fragmentRect);
172 168
173 selectionRect.unite(fragmentRect); 169 selectionRect.unite(fragmentRect);
174 } 170 }
175 171
176 return enclosingIntRect(selectionRect); 172 return enclosingIntRect(selectionRect);
177 } 173 }
178 174
179 static inline bool textShouldBePainted(RenderSVGInlineText& textRenderer)
180 {
181 // 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 .
183 return textRenderer.scaledFont().fontDescription().computedPixelSize();
184 }
185
186 void SVGInlineTextBox::paintSelectionBackground(PaintInfo& paintInfo)
187 {
188 ASSERT(paintInfo.shouldPaintWithinRoot(&renderer()));
189 ASSERT(paintInfo.phase == PaintPhaseForeground || paintInfo.phase == PaintPh aseSelection);
190 ASSERT(truncation() == cNoTruncation);
191
192 if (renderer().style()->visibility() != VISIBLE)
193 return;
194
195 RenderObject& parentRenderer = parent()->renderer();
196 ASSERT(!parentRenderer.document().printing());
197
198 // Determine whether or not we're selected.
199 bool paintSelectedTextOnly = paintInfo.phase == PaintPhaseSelection;
200 bool hasSelection = selectionState() != RenderObject::SelectionNone;
201 if (!hasSelection || paintSelectedTextOnly)
202 return;
203
204 Color backgroundColor = renderer().selectionBackgroundColor();
205 if (!backgroundColor.alpha())
206 return;
207
208 RenderSVGInlineText& textRenderer = toRenderSVGInlineText(this->renderer());
209 if (!textShouldBePainted(textRenderer))
210 return;
211
212 RenderStyle* style = parentRenderer.style();
213 ASSERT(style);
214
215 int startPosition, endPosition;
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) 175 void SVGInlineTextBox::paint(PaintInfo& paintInfo, const LayoutPoint& paintOffse t, LayoutUnit, LayoutUnit)
241 { 176 {
242 ASSERT(paintInfo.shouldPaintWithinRoot(&renderer()));
243 ASSERT(paintInfo.phase == PaintPhaseForeground || paintInfo.phase == PaintPh aseSelection);
244 ASSERT(truncation() == cNoTruncation);
245 177
246 if (renderer().style()->visibility() != VISIBLE) 178 SVGInlineTextBoxPainter(*this).paint(paintInfo, paintOffset);
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 InlineTextBoxPainter(*this).paintDocumentMarkers(paintInfo.context, paintOff set, style, textRenderer.scaledFont(), true);
267
268 const SVGRenderStyle& svgStyle = style->svgStyle();
269
270 bool hasFill = svgStyle.hasFill();
271 bool hasVisibleStroke = svgStyle.hasVisibleStroke();
272
273 RenderStyle* selectionStyle = style;
274 if (hasSelection) {
275 selectionStyle = parentRenderer.getCachedPseudoStyle(SELECTION);
276 if (selectionStyle) {
277 const SVGRenderStyle& svgSelectionStyle = selectionStyle->svgStyle() ;
278
279 if (!hasFill)
280 hasFill = svgSelectionStyle.hasFill();
281 if (!hasVisibleStroke)
282 hasVisibleStroke = svgSelectionStyle.hasVisibleStroke();
283 } else {
284 selectionStyle = style;
285 }
286 }
287
288 if (SVGRenderSupport::isRenderingClipPathAsMaskImage(textRenderer)) {
289 hasFill = true;
290 hasVisibleStroke = false;
291 }
292
293 AffineTransform fragmentTransform;
294 unsigned textFragmentsSize = m_textFragments.size();
295 for (unsigned i = 0; i < textFragmentsSize; ++i) {
296 SVGTextFragment& fragment = m_textFragments.at(i);
297
298 GraphicsContextStateSaver stateSaver(*paintInfo.context, false);
299 fragment.buildFragmentTransform(fragmentTransform);
300 if (!fragmentTransform.isIdentity()) {
301 stateSaver.save();
302 paintInfo.context->concatCTM(fragmentTransform);
303 }
304
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.
306 unsigned decorations = style->textDecorationsInEffect();
307 if (decorations & TextDecorationUnderline)
308 paintDecoration(paintInfo.context, TextDecorationUnderline, fragment );
309 if (decorations & TextDecorationOverline)
310 paintDecoration(paintInfo.context, TextDecorationOverline, fragment) ;
311
312 for (int i = 0; i < 3; i++) {
313 switch (svgStyle.paintOrderType(i)) {
314 case PT_FILL:
315 // Fill text
316 if (hasFill) {
317 paintText(paintInfo.context, style, selectionStyle, fragment ,
318 ApplyToFillMode | ApplyToTextMode, hasSelection, paintSe lectedTextOnly);
319 }
320 break;
321 case PT_STROKE:
322 // Stroke text
323 if (hasVisibleStroke) {
324 paintText(paintInfo.context, style, selectionStyle, fragment ,
325 ApplyToStrokeMode | ApplyToTextMode, hasSelection, paint SelectedTextOnly);
326 }
327 break;
328 case PT_MARKERS:
329 // Markers don't apply to text
330 break;
331 default:
332 ASSERT_NOT_REACHED();
333 break;
334 }
335 }
336
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.
338 if (decorations & TextDecorationLineThrough)
339 paintDecoration(paintInfo.context, TextDecorationLineThrough, fragme nt);
340 }
341
342 // finally, paint the outline if any
343 if (style->hasOutline() && parentRenderer.isRenderInline())
344 InlinePainter(toRenderInline(parentRenderer)).paintOutline(paintInfo, pa intOffset);
345 }
346
347 class PaintingResourceScope {
348 public:
349 PaintingResourceScope(RenderObject& renderer)
350 : m_renderer(renderer)
351 , m_paintingResource(0)
352 {
353 }
354 ~PaintingResourceScope() { ASSERT(!m_paintingResource); }
355
356 bool acquirePaintingResource(GraphicsContext*&, RenderStyle*, RenderSVGResou rceModeFlags);
357 void releasePaintingResource(GraphicsContext*&);
358
359 private:
360 RenderObject& m_renderer;
361 RenderSVGResource* m_paintingResource;
362 };
363
364 bool PaintingResourceScope::acquirePaintingResource(GraphicsContext*& context, R enderStyle* style, RenderSVGResourceModeFlags resourceModeFlags)
365 {
366 ASSERT(style);
367 RenderSVGResourceMode resourceMode = static_cast<RenderSVGResourceMode>(reso urceModeFlags & (ApplyToFillMode | ApplyToStrokeMode));
368 ASSERT(resourceMode == ApplyToFillMode || resourceMode == ApplyToStrokeMode) ;
369
370 bool hasFallback = false;
371 m_paintingResource = RenderSVGResource::requestPaintingResource(resourceMode , &m_renderer, style, hasFallback);
372 if (!m_paintingResource)
373 return false;
374
375 if (!m_paintingResource->applyResource(&m_renderer, style, context, resource ModeFlags)) {
376 if (hasFallback) {
377 m_paintingResource = RenderSVGResource::sharedSolidPaintingResource( );
378 m_paintingResource->applyResource(&m_renderer, style, context, resou rceModeFlags);
379 }
380 }
381 return true;
382 }
383
384 void PaintingResourceScope::releasePaintingResource(GraphicsContext*& context)
385 {
386 ASSERT(m_paintingResource);
387
388 m_paintingResource->postApplyResource(context);
389 m_paintingResource = 0;
390 } 179 }
391 180
392 TextRun SVGInlineTextBox::constructTextRun(RenderStyle* style, const SVGTextFrag ment& fragment) const 181 TextRun SVGInlineTextBox::constructTextRun(RenderStyle* style, const SVGTextFrag ment& fragment) const
393 { 182 {
394 ASSERT(style); 183 ASSERT(style);
395 184
396 RenderText* text = &renderer(); 185 RenderText* text = &renderer();
397 186
398 // FIXME(crbug.com/264211): This should not be necessary but can occur if we 187 // FIXME(crbug.com/264211): This should not be necessary but can occur if we
399 // layout during layout. Remove this when 264211 is fixed. 188 // layout during layout. Remove this when 264211 is fixed.
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
446 endPosition = length; 235 endPosition = length;
447 else { 236 else {
448 ASSERT(endPosition >= offset); 237 ASSERT(endPosition >= offset);
449 endPosition -= offset; 238 endPosition -= offset;
450 } 239 }
451 240
452 ASSERT(startPosition < endPosition); 241 ASSERT(startPosition < endPosition);
453 return true; 242 return true;
454 } 243 }
455 244
456 // Offset from the baseline for |decoration|. Positive offsets are above the bas eline.
457 static inline float baselineOffsetForDecoration(TextDecoration decoration, const FontMetrics& fontMetrics, float thickness)
458 {
459 // FIXME: For SVG Fonts we need to use the attributes defined in the <font-f ace> if specified.
460 // Compatible with Batik/Presto.
461 if (decoration == TextDecorationUnderline)
462 return -thickness * 1.5f;
463 if (decoration == TextDecorationOverline)
464 return fontMetrics.floatAscent() - thickness;
465 if (decoration == TextDecorationLineThrough)
466 return fontMetrics.floatAscent() * 3 / 8.0f;
467
468 ASSERT_NOT_REACHED();
469 return 0.0f;
470 }
471
472 static inline float thicknessForDecoration(TextDecoration, const Font& font)
473 {
474 // FIXME: For SVG Fonts we need to use the attributes defined in the <font-f ace> if specified.
475 // Compatible with Batik/Presto
476 return font.fontDescription().computedSize() / 20.0f;
477 }
478
479 static inline RenderObject* findRenderObjectDefininingTextDecoration(InlineFlowB ox* parentBox)
480 {
481 // Lookup first render object in parent hierarchy which has text-decoration set.
482 RenderObject* renderer = 0;
483 while (parentBox) {
484 renderer = &parentBox->renderer();
485
486 if (renderer->style() && renderer->style()->textDecoration() != TextDeco rationNone)
487 break;
488
489 parentBox = parentBox->parent();
490 }
491
492 ASSERT(renderer);
493 return renderer;
494 }
495
496 void SVGInlineTextBox::paintDecoration(GraphicsContext* context, TextDecoration decoration, const SVGTextFragment& fragment)
497 {
498 if (renderer().style()->textDecorationsInEffect() == TextDecorationNone)
499 return;
500
501 // Find out which render style defined the text-decoration, as its fill/stro ke properties have to be used for drawing instead of ours.
502 RenderObject* decorationRenderer = findRenderObjectDefininingTextDecoration( parent());
503 RenderStyle* decorationStyle = decorationRenderer->style();
504 ASSERT(decorationStyle);
505
506 if (decorationStyle->visibility() == HIDDEN)
507 return;
508
509 const SVGRenderStyle& svgDecorationStyle = decorationStyle->svgStyle();
510
511 for (int i = 0; i < 3; i++) {
512 switch (svgDecorationStyle.paintOrderType(i)) {
513 case PT_FILL:
514 if (svgDecorationStyle.hasFill())
515 paintDecorationWithStyle(context, decoration, fragment, decorati onRenderer, ApplyToFillMode);
516 break;
517 case PT_STROKE:
518 if (svgDecorationStyle.hasVisibleStroke())
519 paintDecorationWithStyle(context, decoration, fragment, decorati onRenderer, ApplyToStrokeMode);
520 break;
521 case PT_MARKERS:
522 break;
523 default:
524 ASSERT_NOT_REACHED();
525 }
526 }
527 }
528
529 void SVGInlineTextBox::paintDecorationWithStyle(GraphicsContext* context, TextDe coration decoration,
530 const SVGTextFragment& fragment, RenderObject* decorationRenderer, RenderSVG ResourceModeFlags resourceMode)
531 {
532 RenderStyle* decorationStyle = decorationRenderer->style();
533 ASSERT(decorationStyle);
534
535 float scalingFactor = 1;
536 Font scaledFont;
537 RenderSVGInlineText::computeNewScaledFontForStyle(decorationRenderer, decora tionStyle, scalingFactor, scaledFont);
538 ASSERT(scalingFactor);
539
540 float thickness = thicknessForDecoration(decoration, scaledFont);
541
542 if (fragment.width <= 0 && thickness <= 0)
543 return;
544
545 float decorationOffset = baselineOffsetForDecoration(decoration, scaledFont. fontMetrics(), thickness);
546 FloatPoint decorationOrigin(fragment.x, fragment.y - decorationOffset / scal ingFactor);
547
548 Path path;
549 path.addRect(FloatRect(decorationOrigin, FloatSize(fragment.width, thickness / scalingFactor)));
550
551 PaintingResourceScope resourceScope(*decorationRenderer);
552 if (resourceScope.acquirePaintingResource(context, decorationStyle, resource Mode)) {
553 SVGRenderSupport::fillOrStrokePath(context, resourceMode, path);
554 resourceScope.releasePaintingResource(context);
555 }
556 }
557
558 void SVGInlineTextBox::paintTextWithShadows(GraphicsContext* context, RenderStyl e* style,
559 TextRun& textRun, const SVGTextFragment& fragment, int startPosition, int en dPosition,
560 RenderSVGResourceModeFlags resourceMode)
561 {
562 RenderSVGInlineText& textRenderer = toRenderSVGInlineText(this->renderer());
563
564 float scalingFactor = textRenderer.scalingFactor();
565 ASSERT(scalingFactor);
566
567 const Font& scaledFont = textRenderer.scaledFont();
568 const ShadowList* shadowList = style->textShadow();
569
570 // Text shadows are disabled when printing. http://crbug.com/258321
571 bool hasShadow = shadowList && !context->printing();
572
573 FloatPoint textOrigin(fragment.x, fragment.y);
574 FloatSize textSize(fragment.width, fragment.height);
575
576 if (scalingFactor != 1) {
577 textOrigin.scale(scalingFactor, scalingFactor);
578 textSize.scale(scalingFactor);
579 context->save();
580 context->scale(1 / scalingFactor, 1 / scalingFactor);
581 }
582
583 if (hasShadow)
584 context->setDrawLooper(shadowList->createDrawLooper(DrawLooperBuilder::S hadowRespectsAlpha));
585
586 PaintingResourceScope resourceScope(parent()->renderer());
587 if (resourceScope.acquirePaintingResource(context, style, resourceMode)) {
588 if (scalingFactor != 1 && resourceMode & ApplyToStrokeMode)
589 context->setStrokeThickness(context->strokeThickness() * scalingFact or);
590
591 TextRunPaintInfo textRunPaintInfo(textRun);
592 textRunPaintInfo.from = startPosition;
593 textRunPaintInfo.to = endPosition;
594
595 float baseline = scaledFont.fontMetrics().floatAscent();
596 textRunPaintInfo.bounds = FloatRect(textOrigin.x(), textOrigin.y() - bas eline,
597 textSize.width(), textSize.height());
598
599 scaledFont.drawText(context, textRunPaintInfo, textOrigin);
600 resourceScope.releasePaintingResource(context);
601 }
602
603 if (scalingFactor != 1)
604 context->restore();
605 else if (hasShadow)
606 context->clearShadow();
607 }
608
609 void SVGInlineTextBox::paintText(GraphicsContext* context, RenderStyle* style,
610 RenderStyle* selectionStyle, const SVGTextFragment& fragment,
611 RenderSVGResourceModeFlags resourceMode, bool hasSelection, bool paintSelect edTextOnly)
612 {
613 ASSERT(style);
614 ASSERT(selectionStyle);
615
616 int startPosition = 0;
617 int endPosition = 0;
618 if (hasSelection) {
619 selectionStartEnd(startPosition, endPosition);
620 hasSelection = mapStartEndPositionsIntoFragmentCoordinates(fragment, sta rtPosition, endPosition);
621 }
622
623 // Fast path if there is no selection, just draw the whole chunk part using the regular style
624 TextRun textRun = constructTextRun(style, fragment);
625 if (!hasSelection || startPosition >= endPosition) {
626 paintTextWithShadows(context, style, textRun, fragment, 0, fragment.leng th, resourceMode);
627 return;
628 }
629
630 // Eventually draw text using regular style until the start position of the selection
631 if (startPosition > 0 && !paintSelectedTextOnly)
632 paintTextWithShadows(context, style, textRun, fragment, 0, startPosition , resourceMode);
633
634 // Draw text using selection style from the start to the end position of the selection
635 if (style != selectionStyle) {
636 StyleDifference diff;
637 diff.setNeedsPaintInvalidationObject();
638 SVGResourcesCache::clientStyleChanged(&parent()->renderer(), diff, selec tionStyle);
639 }
640
641 paintTextWithShadows(context, selectionStyle, textRun, fragment, startPositi on, endPosition, resourceMode);
642
643 if (style != selectionStyle) {
644 StyleDifference diff;
645 diff.setNeedsPaintInvalidationObject();
646 SVGResourcesCache::clientStyleChanged(&parent()->renderer(), diff, style );
647 }
648
649 // Eventually draw text using regular style from the end position of the sel ection to the end of the current chunk part
650 if (endPosition < static_cast<int>(fragment.length) && !paintSelectedTextOnl y)
651 paintTextWithShadows(context, style, textRun, fragment, endPosition, fra gment.length, resourceMode);
652 }
653
654 void SVGInlineTextBox::paintDocumentMarker(GraphicsContext*, const FloatPoint&, DocumentMarker*, RenderStyle*, const Font&, bool) 245 void SVGInlineTextBox::paintDocumentMarker(GraphicsContext*, const FloatPoint&, DocumentMarker*, RenderStyle*, const Font&, bool)
655 { 246 {
656 // SVG does not have support for generic document markers (e.g., spellchecki ng, etc). 247 // SVG does not have support for generic document markers (e.g., spellchecki ng, etc).
657 } 248 }
658 249
659 void SVGInlineTextBox::paintTextMatchMarker(GraphicsContext* context, const Floa tPoint&, DocumentMarker* marker, RenderStyle* style, const Font& font) 250 void SVGInlineTextBox::paintTextMatchMarker(GraphicsContext* context, const Floa tPoint& point, DocumentMarker* marker, RenderStyle* style, const Font& font)
660 { 251 {
661 // SVG is only interested in the TextMatch markers. 252 SVGInlineTextBoxPainter(*this).paintTextMatchMarker(context, point, marker, style, font);
662 if (marker->type() != DocumentMarker::TextMatch)
663 return;
664
665 RenderSVGInlineText& textRenderer = toRenderSVGInlineText(this->renderer());
666
667 FloatRect markerRect;
668 AffineTransform fragmentTransform;
669 for (InlineTextBox* box = textRenderer.firstTextBox(); box; box = box->nextT extBox()) {
670 if (!box->isSVGInlineTextBox())
671 continue;
672
673 SVGInlineTextBox* textBox = toSVGInlineTextBox(box);
674
675 int markerStartPosition = std::max<int>(marker->startOffset() - textBox- >start(), 0);
676 int markerEndPosition = std::min<int>(marker->endOffset() - textBox->sta rt(), textBox->len());
677
678 if (markerStartPosition >= markerEndPosition)
679 continue;
680
681 const Vector<SVGTextFragment>& fragments = textBox->textFragments();
682 unsigned textFragmentsSize = fragments.size();
683 for (unsigned i = 0; i < textFragmentsSize; ++i) {
684 const SVGTextFragment& fragment = fragments.at(i);
685
686 int fragmentStartPosition = markerStartPosition;
687 int fragmentEndPosition = markerEndPosition;
688 if (!textBox->mapStartEndPositionsIntoFragmentCoordinates(fragment, fragmentStartPosition, fragmentEndPosition))
689 continue;
690
691 FloatRect fragmentRect = textBox->selectionRectForTextFragment(fragm ent, fragmentStartPosition, fragmentEndPosition, style);
692 fragment.buildFragmentTransform(fragmentTransform);
693
694 // Draw the marker highlight.
695 if (renderer().frame()->editor().markedTextMatchesAreHighlighted()) {
696 Color color = marker->activeMatch() ?
697 RenderTheme::theme().platformActiveTextSearchHighlightColor( ) :
698 RenderTheme::theme().platformInactiveTextSearchHighlightColo r();
699 GraphicsContextStateSaver stateSaver(*context);
700 if (!fragmentTransform.isIdentity())
701 context->concatCTM(fragmentTransform);
702 context->setFillColor(color);
703 context->fillRect(fragmentRect, color);
704 }
705
706 fragmentRect = fragmentTransform.mapRect(fragmentRect);
707 markerRect.unite(fragmentRect);
708 }
709 }
710
711 toRenderedDocumentMarker(marker)->setRenderedRect(textRenderer.localToAbsolu teQuad(markerRect).enclosingBoundingBox());
712 } 253 }
713 254
714 FloatRect SVGInlineTextBox::calculateBoundaries() const 255 FloatRect SVGInlineTextBox::calculateBoundaries() const
715 { 256 {
716 FloatRect textRect; 257 FloatRect textRect;
717 258
718 RenderSVGInlineText& textRenderer = toRenderSVGInlineText(this->renderer()); 259 RenderSVGInlineText& textRenderer = toRenderSVGInlineText(this->renderer());
719 260
720 float scalingFactor = textRenderer.scalingFactor(); 261 float scalingFactor = textRenderer.scalingFactor();
721 ASSERT(scalingFactor); 262 ASSERT(scalingFactor);
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
754 renderer().updateHitTestResult(result, locationInContainer.point () - toLayoutSize(accumulatedOffset)); 295 renderer().updateHitTestResult(result, locationInContainer.point () - toLayoutSize(accumulatedOffset));
755 if (!result.addNodeToRectBasedTestResult(renderer().node(), requ est, locationInContainer, rect)) 296 if (!result.addNodeToRectBasedTestResult(renderer().node(), requ est, locationInContainer, rect))
756 return true; 297 return true;
757 } 298 }
758 } 299 }
759 } 300 }
760 return false; 301 return false;
761 } 302 }
762 303
763 } // namespace blink 304 } // namespace blink
OLDNEW
« no previous file with comments | « Source/core/rendering/svg/SVGInlineTextBox.h ('k') | Source/core/rendering/svg/SVGRootInlineBox.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698