Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "config.h" | 5 #include "config.h" |
| 6 #include "core/paint/SVGInlineTextBoxPainter.h" | 6 #include "core/paint/SVGInlineTextBoxPainter.h" |
| 7 | 7 |
| 8 #include "core/editing/Editor.h" | 8 #include "core/editing/Editor.h" |
| 9 #include "core/editing/markers/DocumentMarkerController.h" | 9 #include "core/editing/markers/DocumentMarkerController.h" |
| 10 #include "core/editing/markers/RenderedDocumentMarker.h" | 10 #include "core/editing/markers/RenderedDocumentMarker.h" |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 57 if (!textShouldBePainted(textLayoutObject)) | 57 if (!textShouldBePainted(textLayoutObject)) |
| 58 return; | 58 return; |
| 59 | 59 |
| 60 DisplayItem::Type displayItemType = DisplayItem::paintPhaseToDrawingType(pai ntInfo.phase); | 60 DisplayItem::Type displayItemType = DisplayItem::paintPhaseToDrawingType(pai ntInfo.phase); |
| 61 if (!DrawingRecorder::useCachedDrawingIfPossible(*paintInfo.context, m_svgIn lineTextBox, displayItemType)) { | 61 if (!DrawingRecorder::useCachedDrawingIfPossible(*paintInfo.context, m_svgIn lineTextBox, displayItemType)) { |
| 62 LayoutObject& parentLayoutObject = *LineLayoutPaintShim::layoutObjectFro m(m_svgInlineTextBox.parent()->lineLayoutItem()); | 62 LayoutObject& parentLayoutObject = *LineLayoutPaintShim::layoutObjectFro m(m_svgInlineTextBox.parent()->lineLayoutItem()); |
| 63 const ComputedStyle& style = parentLayoutObject.styleRef(); | 63 const ComputedStyle& style = parentLayoutObject.styleRef(); |
| 64 | 64 |
| 65 // TODO(chrishtr): passing the cull rect is incorrect. | 65 // TODO(chrishtr): passing the cull rect is incorrect. |
| 66 DrawingRecorder recorder(*paintInfo.context, m_svgInlineTextBox, display ItemType, FloatRect(paintInfo.cullRect().m_rect)); | 66 DrawingRecorder recorder(*paintInfo.context, m_svgInlineTextBox, display ItemType, FloatRect(paintInfo.cullRect().m_rect)); |
| 67 | |
| 67 InlineTextBoxPainter(m_svgInlineTextBox).paintDocumentMarkers( | 68 InlineTextBoxPainter(m_svgInlineTextBox).paintDocumentMarkers( |
| 68 paintInfo.context, paintOffset, style, | 69 paintInfo, paintOffset, style, |
| 69 textLayoutObject.scaledFont(), true); | 70 textLayoutObject.scaledFont(), true); |
| 70 | 71 |
| 71 if (!m_svgInlineTextBox.textFragments().isEmpty()) | 72 if (!m_svgInlineTextBox.textFragments().isEmpty()) |
| 72 paintTextFragments(paintInfo, parentLayoutObject); | 73 paintTextFragments(paintInfo, parentLayoutObject); |
| 74 | |
| 75 InlineTextBoxPainter(m_svgInlineTextBox).paintDocumentMarkers( | |
| 76 paintInfo, paintOffset, style, | |
| 77 textLayoutObject.scaledFont(), false); | |
| 73 } | 78 } |
| 74 } | 79 } |
| 75 | 80 |
| 76 void SVGInlineTextBoxPainter::paintTextFragments(const PaintInfo& paintInfo, Lay outObject& parentLayoutObject) | 81 void SVGInlineTextBoxPainter::paintTextFragments(const PaintInfo& paintInfo, Lay outObject& parentLayoutObject) |
| 77 { | 82 { |
| 78 const ComputedStyle& style = parentLayoutObject.styleRef(); | 83 const ComputedStyle& style = parentLayoutObject.styleRef(); |
| 79 const SVGComputedStyle& svgStyle = style.svgStyle(); | 84 const SVGComputedStyle& svgStyle = style.svgStyle(); |
| 80 | 85 |
| 81 bool hasFill = svgStyle.hasFill(); | 86 bool hasFill = svgStyle.hasFill(); |
| 82 bool hasVisibleStroke = svgStyle.hasVisibleStroke(); | 87 bool hasVisibleStroke = svgStyle.hasVisibleStroke(); |
| (...skipping 311 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 394 StyleDifference diff; | 399 StyleDifference diff; |
| 395 diff.setNeedsPaintInvalidationObject(); | 400 diff.setNeedsPaintInvalidationObject(); |
| 396 SVGResourcesCache::clientStyleChanged(LineLayoutPaintShim::layoutObjectF rom(m_svgInlineTextBox.parent()->lineLayoutItem()), diff, style); | 401 SVGResourcesCache::clientStyleChanged(LineLayoutPaintShim::layoutObjectF rom(m_svgInlineTextBox.parent()->lineLayoutItem()), diff, style); |
| 397 } | 402 } |
| 398 | 403 |
| 399 // Eventually draw text using regular style from the end position of the sel ection to the end of the current chunk part | 404 // Eventually draw text using regular style from the end position of the sel ection to the end of the current chunk part |
| 400 if (endPosition < static_cast<int>(fragment.length) && !paintSelectedTextOnl y) | 405 if (endPosition < static_cast<int>(fragment.length) && !paintSelectedTextOnl y) |
| 401 paintTextWithShadows(paintInfo, style, textRun, fragment, endPosition, f ragment.length, resourceMode); | 406 paintTextWithShadows(paintInfo, style, textRun, fragment, endPosition, f ragment.length, resourceMode); |
| 402 } | 407 } |
| 403 | 408 |
| 404 void SVGInlineTextBoxPainter::paintTextMatchMarker(GraphicsContext* context, con st LayoutPoint&, DocumentMarker* marker, const ComputedStyle& style, const Font& font) | 409 void SVGInlineTextBoxPainter::paintTextMatchMarkerForeground(const PaintInfo& pa intInfo, const LayoutPoint& point, DocumentMarker* marker, const ComputedStyle& style, const Font& font) |
| 405 { | 410 { |
| 406 // SVG is only interested in the TextMatch markers. | 411 // SVG is only interested in the TextMatch markers. |
|
pdr.
2015/12/14 22:53:26
This comment only says what the if statement below
ramya.v
2015/12/15 06:12:23
Done.
| |
| 407 if (marker->type() != DocumentMarker::TextMatch) | 412 if (marker->type() != DocumentMarker::TextMatch) |
| 413 return; | |
| 414 | |
| 415 LayoutSVGInlineText& textLayoutObject = toLayoutSVGInlineText(*LineLayoutPai ntShim::layoutObjectFrom(m_svgInlineTextBox.lineLayoutItem())); | |
| 416 | |
| 417 for (InlineTextBox* box = textLayoutObject.firstTextBox(); box; box = box->n extTextBox()) { | |
|
pdr.
2015/12/14 22:53:26
This code is too much copy & paste from SVGInlineT
ramya.v
2015/12/15 06:12:23
Done.
| |
| 418 if (!box->isSVGInlineTextBox()) | |
| 419 continue; | |
| 420 | |
| 421 SVGInlineTextBox* textBox = toSVGInlineTextBox(box); | |
| 422 | |
| 423 int markerStartPosition = std::max<int>(marker->startOffset() - textBox- >start(), 0); | |
| 424 int markerEndPosition = std::min<int>(marker->endOffset() - textBox->sta rt(), textBox->len()); | |
| 425 | |
| 426 if (markerStartPosition >= markerEndPosition) | |
| 427 continue; | |
| 428 | |
| 429 const Vector<SVGTextFragment>& fragments = textBox->textFragments(); | |
| 430 unsigned textFragmentsSize = fragments.size(); | |
| 431 AffineTransform fragmentTransform; | |
| 432 for (unsigned i = 0; i < textFragmentsSize; ++i) { | |
| 433 const SVGTextFragment& fragment = fragments.at(i); | |
| 434 | |
| 435 int fragmentStartPosition = markerStartPosition; | |
| 436 int fragmentEndPosition = markerEndPosition; | |
| 437 if (!textBox->mapStartEndPositionsIntoFragmentCoordinates(fragment, fragmentStartPosition, fragmentEndPosition)) | |
| 438 continue; | |
| 439 | |
| 440 if (LineLayoutPaintShim::layoutObjectFrom(m_svgInlineTextBox.lineLay outItem())->frame()->editor().markedTextMatchesAreHighlighted()) { | |
| 441 Color textColor = marker->activeMatch() ? | |
| 442 LayoutTheme::theme().platformTextSearchColor(true) : | |
| 443 LayoutTheme::theme().platformTextSearchColor(false); | |
| 444 | |
| 445 GraphicsContextStateSaver stateSaver(*paintInfo.context, false); | |
| 446 fragment.buildFragmentTransform(fragmentTransform); | |
| 447 if (!fragmentTransform.isIdentity()) { | |
| 448 stateSaver.save(); | |
| 449 paintInfo.context->concatCTM(fragmentTransform); | |
| 450 } | |
| 451 | |
| 452 RefPtr<ComputedStyle> markerStyle = ComputedStyle::clone(style); | |
| 453 markerStyle->setFillPaintColor(textColor); | |
|
pdr.
2015/12/14 22:53:26
ComputedStyle is too big to be copying here. Can y
ramya.v
2015/12/15 06:12:23
I tried plumbing color through GraphicsContext usi
| |
| 454 TextRun textRun = m_svgInlineTextBox.constructTextRun(*markerSty le, fragment); | |
| 455 paintTextWithShadows(paintInfo, *markerStyle, textRun, fragment, fragmentStartPosition, fragmentEndPosition, ApplyToFillMode); | |
| 456 } | |
| 457 } | |
| 458 } | |
| 459 } | |
| 460 | |
| 461 void SVGInlineTextBoxPainter::paintTextMatchMarkerBackground(const PaintInfo& pa intInfo, const LayoutPoint& point, DocumentMarker* marker, const ComputedStyle& style, const Font& font) | |
| 462 { | |
| 463 // SVG is only interested in the TextMatch markers. | |
| 464 if (marker->type() != DocumentMarker::TextMatch) | |
| 408 return; | 465 return; |
| 409 | 466 |
| 410 LayoutSVGInlineText& textLayoutObject = toLayoutSVGInlineText(*LineLayoutPai ntShim::layoutObjectFrom(m_svgInlineTextBox.lineLayoutItem())); | 467 LayoutSVGInlineText& textLayoutObject = toLayoutSVGInlineText(*LineLayoutPai ntShim::layoutObjectFrom(m_svgInlineTextBox.lineLayoutItem())); |
| 411 | 468 |
| 412 AffineTransform fragmentTransform; | 469 AffineTransform fragmentTransform; |
| 413 for (InlineTextBox* box = textLayoutObject.firstTextBox(); box; box = box->n extTextBox()) { | 470 for (InlineTextBox* box = textLayoutObject.firstTextBox(); box; box = box->n extTextBox()) { |
| 414 if (!box->isSVGInlineTextBox()) | 471 if (!box->isSVGInlineTextBox()) |
| 415 continue; | 472 continue; |
| 416 | 473 |
| 417 SVGInlineTextBox* textBox = toSVGInlineTextBox(box); | 474 SVGInlineTextBox* textBox = toSVGInlineTextBox(box); |
| (...skipping 10 matching lines...) Expand all Loading... | |
| 428 const SVGTextFragment& fragment = fragments.at(i); | 485 const SVGTextFragment& fragment = fragments.at(i); |
| 429 | 486 |
| 430 int fragmentStartPosition = markerStartPosition; | 487 int fragmentStartPosition = markerStartPosition; |
| 431 int fragmentEndPosition = markerEndPosition; | 488 int fragmentEndPosition = markerEndPosition; |
| 432 if (!textBox->mapStartEndPositionsIntoFragmentCoordinates(fragment, fragmentStartPosition, fragmentEndPosition)) | 489 if (!textBox->mapStartEndPositionsIntoFragmentCoordinates(fragment, fragmentStartPosition, fragmentEndPosition)) |
| 433 continue; | 490 continue; |
| 434 | 491 |
| 435 FloatRect fragmentRect = textBox->selectionRectForTextFragment(fragm ent, fragmentStartPosition, fragmentEndPosition, style); | 492 FloatRect fragmentRect = textBox->selectionRectForTextFragment(fragm ent, fragmentStartPosition, fragmentEndPosition, style); |
| 436 fragment.buildFragmentTransform(fragmentTransform); | 493 fragment.buildFragmentTransform(fragmentTransform); |
| 437 | 494 |
| 438 // Draw the marker highlight. | |
| 439 if (LineLayoutPaintShim::layoutObjectFrom(m_svgInlineTextBox.lineLay outItem())->frame()->editor().markedTextMatchesAreHighlighted()) { | 495 if (LineLayoutPaintShim::layoutObjectFrom(m_svgInlineTextBox.lineLay outItem())->frame()->editor().markedTextMatchesAreHighlighted()) { |
| 440 Color color = marker->activeMatch() ? | 496 GraphicsContext* context = paintInfo.context; |
| 441 LayoutTheme::theme().platformActiveTextSearchHighlightColor( ) : | |
| 442 LayoutTheme::theme().platformInactiveTextSearchHighlightColo r(); | |
| 443 GraphicsContextStateSaver stateSaver(*context); | 497 GraphicsContextStateSaver stateSaver(*context); |
| 444 if (!fragmentTransform.isIdentity()) | 498 if (!fragmentTransform.isIdentity()) |
| 445 context->concatCTM(fragmentTransform); | 499 context->concatCTM(fragmentTransform); |
| 500 Color color = marker->activeMatch() ? | |
| 501 LayoutTheme::theme().platformTextSearchHighlightColor(true) : | |
| 502 LayoutTheme::theme().platformTextSearchHighlightColor(false) ; | |
| 503 | |
| 446 context->setFillColor(color); | 504 context->setFillColor(color); |
| 447 context->fillRect(fragmentRect, color); | 505 context->fillRect(fragmentRect, color); |
| 448 } | 506 } |
| 449 } | 507 } |
| 450 } | 508 } |
| 451 } | 509 } |
| 452 | 510 |
| 453 } // namespace blink | 511 } // namespace blink |
| OLD | NEW |