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

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

Issue 1512803004: Use refs for GraphicsContext (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@ScrollbarTheme
Patch Set: Created 5 years 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 "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 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
51 // If we ever need that for SVG, it's very easy to refactor and reuse the co de. 51 // If we ever need that for SVG, it's very easy to refactor and reuse the co de.
52 52
53 if (paintInfo.phase == PaintPhaseSelection && !shouldPaintSelection(paintInf o)) 53 if (paintInfo.phase == PaintPhaseSelection && !shouldPaintSelection(paintInf o))
54 return; 54 return;
55 55
56 LayoutSVGInlineText& textLayoutObject = toLayoutSVGInlineText(*LineLayoutPai ntShim::layoutObjectFrom(m_svgInlineTextBox.lineLayoutItem())); 56 LayoutSVGInlineText& textLayoutObject = toLayoutSVGInlineText(*LineLayoutPai ntShim::layoutObjectFrom(m_svgInlineTextBox.lineLayoutItem()));
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_svgInl ineTextBox, 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, displayI temType, FloatRect(paintInfo.cullRect().m_rect));
67 InlineTextBoxPainter(m_svgInlineTextBox).paintDocumentMarkers( 67 InlineTextBoxPainter(m_svgInlineTextBox).paintDocumentMarkers(
68 paintInfo.context, paintOffset, style, 68 paintInfo.context, paintOffset, style,
69 textLayoutObject.scaledFont(), true); 69 textLayoutObject.scaledFont(), true);
70 70
71 if (!m_svgInlineTextBox.textFragments().isEmpty()) 71 if (!m_svgInlineTextBox.textFragments().isEmpty())
72 paintTextFragments(paintInfo, parentLayoutObject); 72 paintTextFragments(paintInfo, parentLayoutObject);
73 } 73 }
74 } 74 }
75 75
76 void SVGInlineTextBoxPainter::paintTextFragments(const PaintInfo& paintInfo, Lay outObject& parentLayoutObject) 76 void SVGInlineTextBoxPainter::paintTextFragments(const PaintInfo& paintInfo, Lay outObject& parentLayoutObject)
(...skipping 23 matching lines...) Expand all
100 if (paintInfo.isRenderingClipPathAsMaskImage()) { 100 if (paintInfo.isRenderingClipPathAsMaskImage()) {
101 hasFill = true; 101 hasFill = true;
102 hasVisibleStroke = false; 102 hasVisibleStroke = false;
103 } 103 }
104 104
105 AffineTransform fragmentTransform; 105 AffineTransform fragmentTransform;
106 unsigned textFragmentsSize = m_svgInlineTextBox.textFragments().size(); 106 unsigned textFragmentsSize = m_svgInlineTextBox.textFragments().size();
107 for (unsigned i = 0; i < textFragmentsSize; ++i) { 107 for (unsigned i = 0; i < textFragmentsSize; ++i) {
108 const SVGTextFragment& fragment = m_svgInlineTextBox.textFragments().at( i); 108 const SVGTextFragment& fragment = m_svgInlineTextBox.textFragments().at( i);
109 109
110 GraphicsContextStateSaver stateSaver(*paintInfo.context, false); 110 GraphicsContextStateSaver stateSaver(paintInfo.context, false);
111 fragment.buildFragmentTransform(fragmentTransform); 111 fragment.buildFragmentTransform(fragmentTransform);
112 if (!fragmentTransform.isIdentity()) { 112 if (!fragmentTransform.isIdentity()) {
113 stateSaver.save(); 113 stateSaver.save();
114 paintInfo.context->concatCTM(fragmentTransform); 114 paintInfo.context.concatCTM(fragmentTransform);
115 } 115 }
116 116
117 // 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. 117 // 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.
118 unsigned decorations = style.textDecorationsInEffect(); 118 unsigned decorations = style.textDecorationsInEffect();
119 if (decorations & TextDecorationUnderline) 119 if (decorations & TextDecorationUnderline)
120 paintDecoration(paintInfo, TextDecorationUnderline, fragment); 120 paintDecoration(paintInfo, TextDecorationUnderline, fragment);
121 if (decorations & TextDecorationOverline) 121 if (decorations & TextDecorationOverline)
122 paintDecoration(paintInfo, TextDecorationOverline, fragment); 122 paintDecoration(paintInfo, TextDecorationOverline, fragment);
123 123
124 for (int i = 0; i < 3; i++) { 124 for (int i = 0; i < 3; i++) {
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
174 AffineTransform fragmentTransform; 174 AffineTransform fragmentTransform;
175 unsigned textFragmentsSize = m_svgInlineTextBox.textFragments().size(); 175 unsigned textFragmentsSize = m_svgInlineTextBox.textFragments().size();
176 for (unsigned i = 0; i < textFragmentsSize; ++i) { 176 for (unsigned i = 0; i < textFragmentsSize; ++i) {
177 const SVGTextFragment& fragment = m_svgInlineTextBox.textFragments().at( i); 177 const SVGTextFragment& fragment = m_svgInlineTextBox.textFragments().at( i);
178 178
179 fragmentStartPosition = startPosition; 179 fragmentStartPosition = startPosition;
180 fragmentEndPosition = endPosition; 180 fragmentEndPosition = endPosition;
181 if (!m_svgInlineTextBox.mapStartEndPositionsIntoFragmentCoordinates(frag ment, fragmentStartPosition, fragmentEndPosition)) 181 if (!m_svgInlineTextBox.mapStartEndPositionsIntoFragmentCoordinates(frag ment, fragmentStartPosition, fragmentEndPosition))
182 continue; 182 continue;
183 183
184 GraphicsContextStateSaver stateSaver(*paintInfo.context); 184 GraphicsContextStateSaver stateSaver(paintInfo.context);
185 fragment.buildFragmentTransform(fragmentTransform); 185 fragment.buildFragmentTransform(fragmentTransform);
186 if (!fragmentTransform.isIdentity()) 186 if (!fragmentTransform.isIdentity())
187 paintInfo.context->concatCTM(fragmentTransform); 187 paintInfo.context.concatCTM(fragmentTransform);
188 188
189 paintInfo.context->setFillColor(backgroundColor); 189 paintInfo.context.setFillColor(backgroundColor);
190 paintInfo.context->fillRect(m_svgInlineTextBox.selectionRectForTextFragm ent(fragment, fragmentStartPosition, fragmentEndPosition, style), backgroundColo r); 190 paintInfo.context.fillRect(m_svgInlineTextBox.selectionRectForTextFragme nt(fragment, fragmentStartPosition, fragmentEndPosition, style), backgroundColor );
191 } 191 }
192 } 192 }
193 193
194 static inline LayoutObject* findLayoutObjectDefininingTextDecoration(InlineFlowB ox* parentBox) 194 static inline LayoutObject* findLayoutObjectDefininingTextDecoration(InlineFlowB ox* parentBox)
195 { 195 {
196 // Lookup first layout object in parent hierarchy which has text-decoration set. 196 // Lookup first layout object in parent hierarchy which has text-decoration set.
197 LayoutObject* layoutObject = 0; 197 LayoutObject* layoutObject = 0;
198 while (parentBox) { 198 while (parentBox) {
199 layoutObject = LineLayoutPaintShim::layoutObjectFrom(parentBox->lineLayo utItem()); 199 layoutObject = LineLayoutPaintShim::layoutObjectFrom(parentBox->lineLayo utItem());
200 200
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
264 const SVGComputedStyle& svgDecorationStyle = decorationStyle.svgStyle(); 264 const SVGComputedStyle& svgDecorationStyle = decorationStyle.svgStyle();
265 265
266 for (int i = 0; i < 3; i++) { 266 for (int i = 0; i < 3; i++) {
267 switch (svgDecorationStyle.paintOrderType(i)) { 267 switch (svgDecorationStyle.paintOrderType(i)) {
268 case PT_FILL: 268 case PT_FILL:
269 if (svgDecorationStyle.hasFill()) { 269 if (svgDecorationStyle.hasFill()) {
270 SkPaint fillPaint; 270 SkPaint fillPaint;
271 if (!SVGPaintContext::paintForLayoutObject(paintInfo, decoration Style, *decorationLayoutObject, ApplyToFillMode, fillPaint)) 271 if (!SVGPaintContext::paintForLayoutObject(paintInfo, decoration Style, *decorationLayoutObject, ApplyToFillMode, fillPaint))
272 break; 272 break;
273 fillPaint.setAntiAlias(true); 273 fillPaint.setAntiAlias(true);
274 paintInfo.context->drawPath(path.skPath(), fillPaint); 274 paintInfo.context.drawPath(path.skPath(), fillPaint);
275 } 275 }
276 break; 276 break;
277 case PT_STROKE: 277 case PT_STROKE:
278 if (svgDecorationStyle.hasVisibleStroke()) { 278 if (svgDecorationStyle.hasVisibleStroke()) {
279 SkPaint strokePaint; 279 SkPaint strokePaint;
280 if (!SVGPaintContext::paintForLayoutObject(paintInfo, decoration Style, *decorationLayoutObject, ApplyToStrokeMode, strokePaint)) 280 if (!SVGPaintContext::paintForLayoutObject(paintInfo, decoration Style, *decorationLayoutObject, ApplyToStrokeMode, strokePaint))
281 break; 281 break;
282 strokePaint.setAntiAlias(true); 282 strokePaint.setAntiAlias(true);
283 StrokeData strokeData; 283 StrokeData strokeData;
284 SVGLayoutSupport::applyStrokeStyleToStrokeData(strokeData, decor ationStyle, *decorationLayoutObject); 284 SVGLayoutSupport::applyStrokeStyleToStrokeData(strokeData, decor ationStyle, *decorationLayoutObject);
285 if (svgDecorationStyle.vectorEffect() == VE_NON_SCALING_STROKE) 285 if (svgDecorationStyle.vectorEffect() == VE_NON_SCALING_STROKE)
286 strokeData.setThickness(strokeData.thickness() / scalingFact or); 286 strokeData.setThickness(strokeData.thickness() / scalingFact or);
287 strokeData.setupPaint(&strokePaint); 287 strokeData.setupPaint(&strokePaint);
288 paintInfo.context->drawPath(path.skPath(), strokePaint); 288 paintInfo.context.drawPath(path.skPath(), strokePaint);
289 } 289 }
290 break; 290 break;
291 case PT_MARKERS: 291 case PT_MARKERS:
292 break; 292 break;
293 default: 293 default:
294 ASSERT_NOT_REACHED(); 294 ASSERT_NOT_REACHED();
295 } 295 }
296 } 296 }
297 } 297 }
298 298
299 void SVGInlineTextBoxPainter::paintTextWithShadows(const PaintInfo& paintInfo, c onst ComputedStyle& style, 299 void SVGInlineTextBoxPainter::paintTextWithShadows(const PaintInfo& paintInfo, c onst ComputedStyle& style,
300 TextRun& textRun, const SVGTextFragment& fragment, int startPosition, int en dPosition, 300 TextRun& textRun, const SVGTextFragment& fragment, int startPosition, int en dPosition,
301 LayoutSVGResourceMode resourceMode) 301 LayoutSVGResourceMode resourceMode)
302 { 302 {
303 LayoutSVGInlineText& textLayoutObject = toLayoutSVGInlineText(*LineLayoutPai ntShim::layoutObjectFrom(m_svgInlineTextBox.lineLayoutItem())); 303 LayoutSVGInlineText& textLayoutObject = toLayoutSVGInlineText(*LineLayoutPai ntShim::layoutObjectFrom(m_svgInlineTextBox.lineLayoutItem()));
304 304
305 float scalingFactor = textLayoutObject.scalingFactor(); 305 float scalingFactor = textLayoutObject.scalingFactor();
306 ASSERT(scalingFactor); 306 ASSERT(scalingFactor);
307 307
308 const Font& scaledFont = textLayoutObject.scaledFont(); 308 const Font& scaledFont = textLayoutObject.scaledFont();
309 const ShadowList* shadowList = style.textShadow(); 309 const ShadowList* shadowList = style.textShadow();
310 GraphicsContext* context = paintInfo.context; 310 GraphicsContext& context = paintInfo.context;
311 311
312 // Text shadows are disabled when printing. http://crbug.com/258321 312 // Text shadows are disabled when printing. http://crbug.com/258321
313 bool hasShadow = shadowList && !paintInfo.isPrinting(); 313 bool hasShadow = shadowList && !paintInfo.isPrinting();
314 314
315 FloatPoint textOrigin(fragment.x, fragment.y); 315 FloatPoint textOrigin(fragment.x, fragment.y);
316 FloatSize textSize(fragment.width, fragment.height); 316 FloatSize textSize(fragment.width, fragment.height);
317 AffineTransform paintServerTransform; 317 AffineTransform paintServerTransform;
318 const AffineTransform* additionalPaintServerTransform = 0; 318 const AffineTransform* additionalPaintServerTransform = 0;
319 319
320 GraphicsContextStateSaver stateSaver(*context, false); 320 GraphicsContextStateSaver stateSaver(context, false);
321 if (scalingFactor != 1) { 321 if (scalingFactor != 1) {
322 textOrigin.scale(scalingFactor, scalingFactor); 322 textOrigin.scale(scalingFactor, scalingFactor);
323 textSize.scale(scalingFactor); 323 textSize.scale(scalingFactor);
324 stateSaver.save(); 324 stateSaver.save();
325 context->scale(1 / scalingFactor, 1 / scalingFactor); 325 context.scale(1 / scalingFactor, 1 / scalingFactor);
326 // Adjust the paint-server coordinate space. 326 // Adjust the paint-server coordinate space.
327 paintServerTransform.scale(scalingFactor); 327 paintServerTransform.scale(scalingFactor);
328 additionalPaintServerTransform = &paintServerTransform; 328 additionalPaintServerTransform = &paintServerTransform;
329 } 329 }
330 330
331 SkPaint paint; 331 SkPaint paint;
332 if (!SVGPaintContext::paintForLayoutObject(paintInfo, style, *LineLayoutPain tShim::layoutObjectFrom(m_svgInlineTextBox.parent()->lineLayoutItem()), resource Mode, paint, additionalPaintServerTransform)) 332 if (!SVGPaintContext::paintForLayoutObject(paintInfo, style, *LineLayoutPain tShim::layoutObjectFrom(m_svgInlineTextBox.parent()->lineLayoutItem()), resource Mode, paint, additionalPaintServerTransform))
333 return; 333 return;
334 paint.setAntiAlias(true); 334 paint.setAntiAlias(true);
335 335
(...skipping 12 matching lines...) Expand all
348 } 348 }
349 349
350 TextRunPaintInfo textRunPaintInfo(textRun); 350 TextRunPaintInfo textRunPaintInfo(textRun);
351 textRunPaintInfo.from = startPosition; 351 textRunPaintInfo.from = startPosition;
352 textRunPaintInfo.to = endPosition; 352 textRunPaintInfo.to = endPosition;
353 353
354 float baseline = scaledFont.fontMetrics().floatAscent(); 354 float baseline = scaledFont.fontMetrics().floatAscent();
355 textRunPaintInfo.bounds = FloatRect(textOrigin.x(), textOrigin.y() - baselin e, 355 textRunPaintInfo.bounds = FloatRect(textOrigin.x(), textOrigin.y() - baselin e,
356 textSize.width(), textSize.height()); 356 textSize.width(), textSize.height());
357 357
358 context->drawText(scaledFont, textRunPaintInfo, textOrigin, paint); 358 context.drawText(scaledFont, textRunPaintInfo, textOrigin, paint);
359 } 359 }
360 360
361 void SVGInlineTextBoxPainter::paintText(const PaintInfo& paintInfo, const Comput edStyle& style, 361 void SVGInlineTextBoxPainter::paintText(const PaintInfo& paintInfo, const Comput edStyle& style,
362 const ComputedStyle& selectionStyle, const SVGTextFragment& fragment, 362 const ComputedStyle& selectionStyle, const SVGTextFragment& fragment,
363 LayoutSVGResourceMode resourceMode, bool shouldPaintSelection) 363 LayoutSVGResourceMode resourceMode, bool shouldPaintSelection)
364 { 364 {
365 int startPosition = 0; 365 int startPosition = 0;
366 int endPosition = 0; 366 int endPosition = 0;
367 if (shouldPaintSelection) { 367 if (shouldPaintSelection) {
368 m_svgInlineTextBox.selectionStartEnd(startPosition, endPosition); 368 m_svgInlineTextBox.selectionStartEnd(startPosition, endPosition);
(...skipping 25 matching lines...) Expand all
394 StyleDifference diff; 394 StyleDifference diff;
395 diff.setNeedsPaintInvalidationObject(); 395 diff.setNeedsPaintInvalidationObject();
396 SVGResourcesCache::clientStyleChanged(LineLayoutPaintShim::layoutObjectF rom(m_svgInlineTextBox.parent()->lineLayoutItem()), diff, style); 396 SVGResourcesCache::clientStyleChanged(LineLayoutPaintShim::layoutObjectF rom(m_svgInlineTextBox.parent()->lineLayoutItem()), diff, style);
397 } 397 }
398 398
399 // Eventually draw text using regular style from the end position of the sel ection to the end of the current chunk part 399 // 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) 400 if (endPosition < static_cast<int>(fragment.length) && !paintSelectedTextOnl y)
401 paintTextWithShadows(paintInfo, style, textRun, fragment, endPosition, f ragment.length, resourceMode); 401 paintTextWithShadows(paintInfo, style, textRun, fragment, endPosition, f ragment.length, resourceMode);
402 } 402 }
403 403
404 void SVGInlineTextBoxPainter::paintTextMatchMarker(GraphicsContext* context, con st LayoutPoint&, DocumentMarker* marker, const ComputedStyle& style, const Font& font) 404 void SVGInlineTextBoxPainter::paintTextMatchMarker(GraphicsContext& context, con st LayoutPoint&, DocumentMarker* marker, const ComputedStyle& style, const Font& font)
405 { 405 {
406 // SVG is only interested in the TextMatch markers. 406 // SVG is only interested in the TextMatch markers.
407 if (marker->type() != DocumentMarker::TextMatch) 407 if (marker->type() != DocumentMarker::TextMatch)
408 return; 408 return;
409 409
410 LayoutSVGInlineText& textLayoutObject = toLayoutSVGInlineText(*LineLayoutPai ntShim::layoutObjectFrom(m_svgInlineTextBox.lineLayoutItem())); 410 LayoutSVGInlineText& textLayoutObject = toLayoutSVGInlineText(*LineLayoutPai ntShim::layoutObjectFrom(m_svgInlineTextBox.lineLayoutItem()));
411 411
412 AffineTransform fragmentTransform; 412 AffineTransform fragmentTransform;
413 for (InlineTextBox* box = textLayoutObject.firstTextBox(); box; box = box->n extTextBox()) { 413 for (InlineTextBox* box = textLayoutObject.firstTextBox(); box; box = box->n extTextBox()) {
414 if (!box->isSVGInlineTextBox()) 414 if (!box->isSVGInlineTextBox())
(...skipping 18 matching lines...) Expand all
433 continue; 433 continue;
434 434
435 FloatRect fragmentRect = textBox->selectionRectForTextFragment(fragm ent, fragmentStartPosition, fragmentEndPosition, style); 435 FloatRect fragmentRect = textBox->selectionRectForTextFragment(fragm ent, fragmentStartPosition, fragmentEndPosition, style);
436 fragment.buildFragmentTransform(fragmentTransform); 436 fragment.buildFragmentTransform(fragmentTransform);
437 437
438 // Draw the marker highlight. 438 // Draw the marker highlight.
439 if (LineLayoutPaintShim::layoutObjectFrom(m_svgInlineTextBox.lineLay outItem())->frame()->editor().markedTextMatchesAreHighlighted()) { 439 if (LineLayoutPaintShim::layoutObjectFrom(m_svgInlineTextBox.lineLay outItem())->frame()->editor().markedTextMatchesAreHighlighted()) {
440 Color color = marker->activeMatch() ? 440 Color color = marker->activeMatch() ?
441 LayoutTheme::theme().platformActiveTextSearchHighlightColor( ) : 441 LayoutTheme::theme().platformActiveTextSearchHighlightColor( ) :
442 LayoutTheme::theme().platformInactiveTextSearchHighlightColo r(); 442 LayoutTheme::theme().platformInactiveTextSearchHighlightColo r();
443 GraphicsContextStateSaver stateSaver(*context); 443 GraphicsContextStateSaver stateSaver(context);
444 if (!fragmentTransform.isIdentity()) 444 if (!fragmentTransform.isIdentity())
445 context->concatCTM(fragmentTransform); 445 context.concatCTM(fragmentTransform);
446 context->setFillColor(color); 446 context.setFillColor(color);
447 context->fillRect(fragmentRect, color); 447 context.fillRect(fragmentRect, color);
448 } 448 }
449 } 449 }
450 } 450 }
451 } 451 }
452 452
453 } // namespace blink 453 } // namespace blink
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/core/paint/SVGInlineTextBoxPainter.h ('k') | third_party/WebKit/Source/core/paint/SVGMaskPainter.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698