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

Side by Side Diff: third_party/WebKit/Source/core/paint/SVGInlineTextBoxPainter.cpp

Issue 2599483002: Extract helper function. (Closed)
Patch Set: Created 3 years, 12 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 // 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 521 matching lines...) Expand 10 before | Expand all | Expand 10 after
532 if (endPosition < static_cast<int>(fragment.length) && 532 if (endPosition < static_cast<int>(fragment.length) &&
533 !paintSelectedTextOnly) { 533 !paintSelectedTextOnly) {
534 SkPaint paint; 534 SkPaint 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 DocumentMarker* marker) const { 542 const DocumentMarker& marker) const {
543 const Vector<SVGTextFragmentWithRange> emptyTextMatchList; 543 const Vector<SVGTextFragmentWithRange> emptyTextMatchList;
544 544
545 // SVG does not support grammar or spellcheck markers, so skip anything but 545 // SVG does not support grammar or spellcheck markers, so skip anything but
546 // TextMatch. 546 // TextMatch.
547 if (marker->type() != DocumentMarker::TextMatch) 547 if (marker.type() != DocumentMarker::TextMatch)
548 return emptyTextMatchList; 548 return emptyTextMatchList;
549 549
550 if (!inlineLayoutObject().frame()->editor().markedTextMatchesAreHighlighted()) 550 if (!inlineLayoutObject().frame()->editor().markedTextMatchesAreHighlighted())
551 return emptyTextMatchList; 551 return emptyTextMatchList;
552 552
553 int markerStartPosition = 553 int markerStartPosition =
554 std::max<int>(marker->startOffset() - m_svgInlineTextBox.start(), 0); 554 std::max<int>(marker.startOffset() - m_svgInlineTextBox.start(), 0);
555 int markerEndPosition = 555 int markerEndPosition =
556 std::min<int>(marker->endOffset() - m_svgInlineTextBox.start(), 556 std::min<int>(marker.endOffset() - m_svgInlineTextBox.start(),
557 m_svgInlineTextBox.len()); 557 m_svgInlineTextBox.len());
558 558
559 if (markerStartPosition >= markerEndPosition) 559 if (markerStartPosition >= markerEndPosition)
560 return emptyTextMatchList; 560 return emptyTextMatchList;
561 561
562 return collectFragmentsInRange(markerStartPosition, markerEndPosition); 562 return collectFragmentsInRange(markerStartPosition, markerEndPosition);
563 } 563 }
564 564
565 Vector<SVGTextFragmentWithRange> 565 Vector<SVGTextFragmentWithRange>
566 SVGInlineTextBoxPainter::collectFragmentsInRange(int startPosition, 566 SVGInlineTextBoxPainter::collectFragmentsInRange(int startPosition,
(...skipping 10 matching lines...) Expand all
577 577
578 fragmentInfoList.append(SVGTextFragmentWithRange( 578 fragmentInfoList.append(SVGTextFragmentWithRange(
579 fragment, fragmentStartPosition, fragmentEndPosition)); 579 fragment, fragmentStartPosition, fragmentEndPosition));
580 } 580 }
581 return fragmentInfoList; 581 return fragmentInfoList;
582 } 582 }
583 583
584 void SVGInlineTextBoxPainter::paintTextMatchMarkerForeground( 584 void SVGInlineTextBoxPainter::paintTextMatchMarkerForeground(
585 const PaintInfo& paintInfo, 585 const PaintInfo& paintInfo,
586 const LayoutPoint& point, 586 const LayoutPoint& point,
587 DocumentMarker* marker, 587 const DocumentMarker& marker,
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 SkPaint 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 SkPaint 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);
(...skipping 11 matching lines...) Expand all
618 textMatchInfo.endPosition, fillPaint); 618 textMatchInfo.endPosition, fillPaint);
619 if (shouldPaintStroke) 619 if (shouldPaintStroke)
620 paintText(paintInfo, textRun, fragment, textMatchInfo.startPosition, 620 paintText(paintInfo, textRun, fragment, textMatchInfo.startPosition,
621 textMatchInfo.endPosition, strokePaint); 621 textMatchInfo.endPosition, strokePaint);
622 } 622 }
623 } 623 }
624 624
625 void SVGInlineTextBoxPainter::paintTextMatchMarkerBackground( 625 void SVGInlineTextBoxPainter::paintTextMatchMarkerBackground(
626 const PaintInfo& paintInfo, 626 const PaintInfo& paintInfo,
627 const LayoutPoint& point, 627 const LayoutPoint& point,
628 DocumentMarker* marker, 628 const DocumentMarker& marker,
629 const ComputedStyle& style, 629 const ComputedStyle& style,
630 const Font& font) { 630 const Font& font) {
631 const Vector<SVGTextFragmentWithRange> textMatchInfoList = 631 const Vector<SVGTextFragmentWithRange> textMatchInfoList =
632 collectTextMatches(marker); 632 collectTextMatches(marker);
633 if (textMatchInfoList.isEmpty()) 633 if (textMatchInfoList.isEmpty())
634 return; 634 return;
635 635
636 Color color = LayoutTheme::theme().platformTextSearchHighlightColor( 636 Color color = LayoutTheme::theme().platformTextSearchHighlightColor(
637 marker->activeMatch()); 637 marker.activeMatch());
638 for (const SVGTextFragmentWithRange& textMatchInfo : textMatchInfoList) { 638 for (const SVGTextFragmentWithRange& textMatchInfo : textMatchInfoList) {
639 const SVGTextFragment& fragment = textMatchInfo.fragment; 639 const SVGTextFragment& fragment = textMatchInfo.fragment;
640 640
641 GraphicsContextStateSaver stateSaver(paintInfo.context, false); 641 GraphicsContextStateSaver stateSaver(paintInfo.context, false);
642 if (fragment.isTransformed()) { 642 if (fragment.isTransformed()) {
643 stateSaver.save(); 643 stateSaver.save();
644 paintInfo.context.concatCTM(fragment.buildFragmentTransform()); 644 paintInfo.context.concatCTM(fragment.buildFragmentTransform());
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
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698