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 332 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
343 Path path; | 343 Path path; |
344 path.addRect(FloatRect(decorationOrigin, | 344 path.addRect(FloatRect(decorationOrigin, |
345 FloatSize(fragment.width, thickness / scalingFactor))); | 345 FloatSize(fragment.width, thickness / scalingFactor))); |
346 | 346 |
347 const SVGComputedStyle& svgDecorationStyle = decorationStyle.svgStyle(); | 347 const SVGComputedStyle& svgDecorationStyle = decorationStyle.svgStyle(); |
348 | 348 |
349 for (int i = 0; i < 3; i++) { | 349 for (int i = 0; i < 3; i++) { |
350 switch (svgDecorationStyle.paintOrderType(i)) { | 350 switch (svgDecorationStyle.paintOrderType(i)) { |
351 case PT_FILL: | 351 case PT_FILL: |
352 if (svgDecorationStyle.hasFill()) { | 352 if (svgDecorationStyle.hasFill()) { |
353 SkPaint fillPaint; | 353 PaintFlags fillPaint; |
354 if (!SVGPaintContext::paintForLayoutObject( | 354 if (!SVGPaintContext::paintForLayoutObject( |
355 paintInfo, decorationStyle, *decorationLayoutObject, | 355 paintInfo, decorationStyle, *decorationLayoutObject, |
356 ApplyToFillMode, fillPaint)) | 356 ApplyToFillMode, fillPaint)) |
357 break; | 357 break; |
358 fillPaint.setAntiAlias(true); | 358 fillPaint.setAntiAlias(true); |
359 paintInfo.context.drawPath(path.getSkPath(), fillPaint); | 359 paintInfo.context.drawPath(path.getSkPath(), fillPaint); |
360 } | 360 } |
361 break; | 361 break; |
362 case PT_STROKE: | 362 case PT_STROKE: |
363 if (svgDecorationStyle.hasVisibleStroke()) { | 363 if (svgDecorationStyle.hasVisibleStroke()) { |
364 SkPaint strokePaint; | 364 PaintFlags strokePaint; |
365 if (!SVGPaintContext::paintForLayoutObject( | 365 if (!SVGPaintContext::paintForLayoutObject( |
366 paintInfo, decorationStyle, *decorationLayoutObject, | 366 paintInfo, decorationStyle, *decorationLayoutObject, |
367 ApplyToStrokeMode, strokePaint)) | 367 ApplyToStrokeMode, strokePaint)) |
368 break; | 368 break; |
369 strokePaint.setAntiAlias(true); | 369 strokePaint.setAntiAlias(true); |
370 float strokeScaleFactor = | 370 float strokeScaleFactor = |
371 svgDecorationStyle.vectorEffect() == VE_NON_SCALING_STROKE | 371 svgDecorationStyle.vectorEffect() == VE_NON_SCALING_STROKE |
372 ? 1 / scalingFactor | 372 ? 1 / scalingFactor |
373 : 1; | 373 : 1; |
374 StrokeData strokeData; | 374 StrokeData strokeData; |
(...skipping 10 matching lines...) Expand all Loading... |
385 break; | 385 break; |
386 default: | 386 default: |
387 ASSERT_NOT_REACHED(); | 387 ASSERT_NOT_REACHED(); |
388 } | 388 } |
389 } | 389 } |
390 } | 390 } |
391 | 391 |
392 bool SVGInlineTextBoxPainter::setupTextPaint(const PaintInfo& paintInfo, | 392 bool SVGInlineTextBoxPainter::setupTextPaint(const PaintInfo& paintInfo, |
393 const ComputedStyle& style, | 393 const ComputedStyle& style, |
394 LayoutSVGResourceMode resourceMode, | 394 LayoutSVGResourceMode resourceMode, |
395 SkPaint& paint) { | 395 PaintFlags& paint) { |
396 LayoutSVGInlineText& textLayoutObject = inlineText(); | 396 LayoutSVGInlineText& textLayoutObject = inlineText(); |
397 | 397 |
398 float scalingFactor = textLayoutObject.scalingFactor(); | 398 float scalingFactor = textLayoutObject.scalingFactor(); |
399 DCHECK(scalingFactor); | 399 DCHECK(scalingFactor); |
400 | 400 |
401 AffineTransform paintServerTransform; | 401 AffineTransform paintServerTransform; |
402 const AffineTransform* additionalPaintServerTransform = nullptr; | 402 const AffineTransform* additionalPaintServerTransform = nullptr; |
403 | 403 |
404 if (scalingFactor != 1) { | 404 if (scalingFactor != 1) { |
405 // Adjust the paint-server coordinate space. | 405 // Adjust the paint-server coordinate space. |
(...skipping 26 matching lines...) Expand all Loading... |
432 strokeData.setupPaint(&paint); | 432 strokeData.setupPaint(&paint); |
433 } | 433 } |
434 return true; | 434 return true; |
435 } | 435 } |
436 | 436 |
437 void SVGInlineTextBoxPainter::paintText(const PaintInfo& paintInfo, | 437 void SVGInlineTextBoxPainter::paintText(const PaintInfo& paintInfo, |
438 TextRun& textRun, | 438 TextRun& textRun, |
439 const SVGTextFragment& fragment, | 439 const SVGTextFragment& fragment, |
440 int startPosition, | 440 int startPosition, |
441 int endPosition, | 441 int endPosition, |
442 const SkPaint& paint) { | 442 const PaintFlags& paint) { |
443 LayoutSVGInlineText& textLayoutObject = inlineText(); | 443 LayoutSVGInlineText& textLayoutObject = inlineText(); |
444 const Font& scaledFont = textLayoutObject.scaledFont(); | 444 const Font& scaledFont = textLayoutObject.scaledFont(); |
445 | 445 |
446 float scalingFactor = textLayoutObject.scalingFactor(); | 446 float scalingFactor = textLayoutObject.scalingFactor(); |
447 DCHECK(scalingFactor); | 447 DCHECK(scalingFactor); |
448 | 448 |
449 FloatPoint textOrigin(fragment.x, fragment.y); | 449 FloatPoint textOrigin(fragment.x, fragment.y); |
450 FloatSize textSize(fragment.width, fragment.height); | 450 FloatSize textSize(fragment.width, fragment.height); |
451 | 451 |
452 GraphicsContext& context = paintInfo.context; | 452 GraphicsContext& context = paintInfo.context; |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
485 m_svgInlineTextBox.selectionStartEnd(startPosition, endPosition); | 485 m_svgInlineTextBox.selectionStartEnd(startPosition, endPosition); |
486 shouldPaintSelection = | 486 shouldPaintSelection = |
487 m_svgInlineTextBox.mapStartEndPositionsIntoFragmentCoordinates( | 487 m_svgInlineTextBox.mapStartEndPositionsIntoFragmentCoordinates( |
488 fragment, startPosition, endPosition); | 488 fragment, startPosition, endPosition); |
489 } | 489 } |
490 | 490 |
491 // Fast path if there is no selection, just draw the whole chunk part using | 491 // Fast path if there is no selection, just draw the whole chunk part using |
492 // the regular style. | 492 // the regular style. |
493 TextRun textRun = m_svgInlineTextBox.constructTextRun(style, fragment); | 493 TextRun textRun = m_svgInlineTextBox.constructTextRun(style, fragment); |
494 if (!shouldPaintSelection || startPosition >= endPosition) { | 494 if (!shouldPaintSelection || startPosition >= endPosition) { |
495 SkPaint paint; | 495 PaintFlags paint; |
496 if (setupTextPaint(paintInfo, style, resourceMode, paint)) | 496 if (setupTextPaint(paintInfo, style, resourceMode, paint)) |
497 paintText(paintInfo, textRun, fragment, 0, fragment.length, paint); | 497 paintText(paintInfo, textRun, fragment, 0, fragment.length, paint); |
498 return; | 498 return; |
499 } | 499 } |
500 | 500 |
501 // Eventually draw text using regular style until the start position of the | 501 // Eventually draw text using regular style until the start position of the |
502 // selection. | 502 // selection. |
503 bool paintSelectedTextOnly = paintInfo.phase == PaintPhaseSelection; | 503 bool paintSelectedTextOnly = paintInfo.phase == PaintPhaseSelection; |
504 if (startPosition > 0 && !paintSelectedTextOnly) { | 504 if (startPosition > 0 && !paintSelectedTextOnly) { |
505 SkPaint paint; | 505 PaintFlags paint; |
506 if (setupTextPaint(paintInfo, style, resourceMode, paint)) | 506 if (setupTextPaint(paintInfo, style, resourceMode, paint)) |
507 paintText(paintInfo, textRun, fragment, 0, startPosition, paint); | 507 paintText(paintInfo, textRun, fragment, 0, startPosition, paint); |
508 } | 508 } |
509 | 509 |
510 // Draw text using selection style from the start to the end position of the | 510 // Draw text using selection style from the start to the end position of the |
511 // selection. | 511 // selection. |
512 if (style != selectionStyle) { | 512 if (style != selectionStyle) { |
513 StyleDifference diff; | 513 StyleDifference diff; |
514 diff.setNeedsPaintInvalidationObject(); | 514 diff.setNeedsPaintInvalidationObject(); |
515 SVGResourcesCache::clientStyleChanged(&parentInlineLayoutObject(), diff, | 515 SVGResourcesCache::clientStyleChanged(&parentInlineLayoutObject(), diff, |
516 selectionStyle); | 516 selectionStyle); |
517 } | 517 } |
518 | 518 |
519 SkPaint paint; | 519 PaintFlags paint; |
520 if (setupTextPaint(paintInfo, selectionStyle, resourceMode, paint)) | 520 if (setupTextPaint(paintInfo, selectionStyle, resourceMode, paint)) |
521 paintText(paintInfo, textRun, fragment, startPosition, endPosition, paint); | 521 paintText(paintInfo, textRun, fragment, startPosition, endPosition, paint); |
522 | 522 |
523 if (style != selectionStyle) { | 523 if (style != selectionStyle) { |
524 StyleDifference diff; | 524 StyleDifference diff; |
525 diff.setNeedsPaintInvalidationObject(); | 525 diff.setNeedsPaintInvalidationObject(); |
526 SVGResourcesCache::clientStyleChanged(&parentInlineLayoutObject(), diff, | 526 SVGResourcesCache::clientStyleChanged(&parentInlineLayoutObject(), diff, |
527 style); | 527 style); |
528 } | 528 } |
529 | 529 |
530 // Eventually draw text using regular style from the end position of the | 530 // Eventually draw text using regular style from the end position of the |
531 // selection to the end of the current chunk part. | 531 // selection to the end of the current chunk part. |
532 if (endPosition < static_cast<int>(fragment.length) && | 532 if (endPosition < static_cast<int>(fragment.length) && |
533 !paintSelectedTextOnly) { | 533 !paintSelectedTextOnly) { |
534 SkPaint paint; | 534 PaintFlags paint; |
535 if (setupTextPaint(paintInfo, style, resourceMode, paint)) | 535 if (setupTextPaint(paintInfo, style, resourceMode, paint)) |
536 paintText(paintInfo, textRun, fragment, endPosition, fragment.length, | 536 paintText(paintInfo, textRun, fragment, endPosition, fragment.length, |
537 paint); | 537 paint); |
538 } | 538 } |
539 } | 539 } |
540 | 540 |
541 Vector<SVGTextFragmentWithRange> SVGInlineTextBoxPainter::collectTextMatches( | 541 Vector<SVGTextFragmentWithRange> SVGInlineTextBoxPainter::collectTextMatches( |
542 const DocumentMarker& marker) const { | 542 const DocumentMarker& marker) const { |
543 const Vector<SVGTextFragmentWithRange> emptyTextMatchList; | 543 const Vector<SVGTextFragmentWithRange> emptyTextMatchList; |
544 | 544 |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
588 const ComputedStyle& style, | 588 const ComputedStyle& style, |
589 const Font& font) { | 589 const Font& font) { |
590 const Vector<SVGTextFragmentWithRange> textMatchInfoList = | 590 const Vector<SVGTextFragmentWithRange> textMatchInfoList = |
591 collectTextMatches(marker); | 591 collectTextMatches(marker); |
592 if (textMatchInfoList.isEmpty()) | 592 if (textMatchInfoList.isEmpty()) |
593 return; | 593 return; |
594 | 594 |
595 Color textColor = | 595 Color textColor = |
596 LayoutTheme::theme().platformTextSearchColor(marker.activeMatch()); | 596 LayoutTheme::theme().platformTextSearchColor(marker.activeMatch()); |
597 | 597 |
598 SkPaint fillPaint; | 598 PaintFlags fillPaint; |
599 fillPaint.setColor(textColor.rgb()); | 599 fillPaint.setColor(textColor.rgb()); |
600 fillPaint.setAntiAlias(true); | 600 fillPaint.setAntiAlias(true); |
601 | 601 |
602 SkPaint strokePaint; | 602 PaintFlags strokePaint; |
603 bool shouldPaintStroke = false; | 603 bool shouldPaintStroke = false; |
604 if (setupTextPaint(paintInfo, style, ApplyToStrokeMode, strokePaint)) { | 604 if (setupTextPaint(paintInfo, style, ApplyToStrokeMode, strokePaint)) { |
605 shouldPaintStroke = true; | 605 shouldPaintStroke = true; |
606 strokePaint.setLooper(nullptr); | 606 strokePaint.setLooper(nullptr); |
607 strokePaint.setColor(textColor.rgb()); | 607 strokePaint.setColor(textColor.rgb()); |
608 } | 608 } |
609 | 609 |
610 for (const SVGTextFragmentWithRange& textMatchInfo : textMatchInfoList) { | 610 for (const SVGTextFragmentWithRange& textMatchInfo : textMatchInfoList) { |
611 const SVGTextFragment& fragment = textMatchInfo.fragment; | 611 const SVGTextFragment& fragment = textMatchInfo.fragment; |
612 GraphicsContextStateSaver stateSaver(paintInfo.context); | 612 GraphicsContextStateSaver stateSaver(paintInfo.context); |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
645 } | 645 } |
646 FloatRect fragmentRect = m_svgInlineTextBox.selectionRectForTextFragment( | 646 FloatRect fragmentRect = m_svgInlineTextBox.selectionRectForTextFragment( |
647 fragment, textMatchInfo.startPosition, textMatchInfo.endPosition, | 647 fragment, textMatchInfo.startPosition, textMatchInfo.endPosition, |
648 style); | 648 style); |
649 paintInfo.context.setFillColor(color); | 649 paintInfo.context.setFillColor(color); |
650 paintInfo.context.fillRect(fragmentRect); | 650 paintInfo.context.fillRect(fragmentRect); |
651 } | 651 } |
652 } | 652 } |
653 | 653 |
654 } // namespace blink | 654 } // namespace blink |
OLD | NEW |