| OLD | NEW |
| 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/FrameView.h" | 28 #include "core/frame/FrameView.h" |
| 29 #include "core/frame/LocalFrame.h" | 29 #include "core/frame/LocalFrame.h" |
| 30 #include "core/paint/InlinePainter.h" | 30 #include "core/paint/SVGInlineTextBoxPainter.h" |
| 31 #include "core/rendering/HitTestResult.h" | 31 #include "core/rendering/HitTestResult.h" |
| 32 #include "core/rendering/InlineFlowBox.h" | 32 #include "core/rendering/InlineFlowBox.h" |
| 33 #include "core/rendering/PaintInfo.h" | 33 #include "core/rendering/PaintInfo.h" |
| 34 #include "core/rendering/PointerEventsHitRules.h" | 34 #include "core/rendering/PointerEventsHitRules.h" |
| 35 #include "core/rendering/RenderInline.h" | 35 #include "core/rendering/RenderInline.h" |
| 36 #include "core/rendering/RenderTheme.h" | 36 #include "core/rendering/RenderTheme.h" |
| 37 #include "core/rendering/style/ShadowList.h" | |
| 38 #include "core/rendering/svg/RenderSVGInlineText.h" | 37 #include "core/rendering/svg/RenderSVGInlineText.h" |
| 39 #include "core/rendering/svg/RenderSVGResource.h" | 38 #include "core/rendering/svg/RenderSVGResource.h" |
| 40 #include "core/rendering/svg/RenderSVGResourceSolidColor.h" | 39 #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" | 40 #include "core/rendering/svg/SVGTextRunRenderingContext.h" |
| 44 #include "platform/FloatConversion.h" | 41 #include "platform/FloatConversion.h" |
| 45 #include "platform/fonts/FontCache.h" | 42 #include "platform/fonts/FontCache.h" |
| 46 #include "platform/graphics/GraphicsContextStateSaver.h" | 43 #include "platform/graphics/GraphicsContextStateSaver.h" |
| 47 | 44 |
| 48 namespace blink { | 45 namespace blink { |
| 49 | 46 |
| 50 struct ExpectedSVGInlineTextBoxSize : public InlineTextBox { | 47 struct ExpectedSVGInlineTextBoxSize : public InlineTextBox { |
| 51 float float1; | 48 float float1; |
| 52 uint32_t bitfields : 1; | 49 uint32_t bitfields : 1; |
| (...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 169 FloatRect fragmentRect = selectionRectForTextFragment(fragment, fragment
StartPosition, fragmentEndPosition, style); | 166 FloatRect fragmentRect = selectionRectForTextFragment(fragment, fragment
StartPosition, fragmentEndPosition, style); |
| 170 fragment.buildFragmentTransform(fragmentTransform); | 167 fragment.buildFragmentTransform(fragmentTransform); |
| 171 fragmentRect = fragmentTransform.mapRect(fragmentRect); | 168 fragmentRect = fragmentTransform.mapRect(fragmentRect); |
| 172 | 169 |
| 173 selectionRect.unite(fragmentRect); | 170 selectionRect.unite(fragmentRect); |
| 174 } | 171 } |
| 175 | 172 |
| 176 return enclosingIntRect(selectionRect); | 173 return enclosingIntRect(selectionRect); |
| 177 } | 174 } |
| 178 | 175 |
| 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) | 176 void SVGInlineTextBox::paint(PaintInfo& paintInfo, const LayoutPoint& paintOffse
t, LayoutUnit, LayoutUnit) |
| 241 { | 177 { |
| 242 ASSERT(paintInfo.shouldPaintWithinRoot(&renderer())); | 178 SVGInlineTextBoxPainter(*this).paint(paintInfo, paintOffset); |
| 243 ASSERT(paintInfo.phase == PaintPhaseForeground || paintInfo.phase == PaintPh
aseSelection); | |
| 244 ASSERT(truncation() == cNoTruncation); | |
| 245 | |
| 246 if (renderer().style()->visibility() != VISIBLE) | |
| 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 paintDocumentMarkers(paintInfo.context, paintOffset, style, textRenderer.sca
ledFont(), 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 (textRenderer.frame() && textRenderer.frame()->view() && textRenderer.fra
me()->view()->paintBehavior() & PaintBehaviorRenderingSVGMask) { | |
| 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 ASSERT(resourceModeFlags != ApplyToDefaultMode); | |
| 368 RenderSVGResourceMode resourceMode = static_cast<RenderSVGResourceMode>(reso
urceModeFlags & (ApplyToFillMode | ApplyToStrokeMode)); | |
| 369 ASSERT(resourceMode == ApplyToFillMode || resourceMode == ApplyToStrokeMode)
; | |
| 370 | |
| 371 bool hasFallback = false; | |
| 372 m_paintingResource = RenderSVGResource::requestPaintingResource(resourceMode
, &m_renderer, style, hasFallback); | |
| 373 if (!m_paintingResource) | |
| 374 return false; | |
| 375 | |
| 376 if (!m_paintingResource->applyResource(&m_renderer, style, context, resource
ModeFlags)) { | |
| 377 if (hasFallback) { | |
| 378 m_paintingResource = RenderSVGResource::sharedSolidPaintingResource(
); | |
| 379 m_paintingResource->applyResource(&m_renderer, style, context, resou
rceModeFlags); | |
| 380 } | |
| 381 } | |
| 382 return true; | |
| 383 } | |
| 384 | |
| 385 void PaintingResourceScope::releasePaintingResource(GraphicsContext*& context) | |
| 386 { | |
| 387 ASSERT(m_paintingResource); | |
| 388 | |
| 389 m_paintingResource->postApplyResource(&m_renderer, context); | |
| 390 m_paintingResource = 0; | |
| 391 } | 179 } |
| 392 | 180 |
| 393 TextRun SVGInlineTextBox::constructTextRun(RenderStyle* style, const SVGTextFrag
ment& fragment) const | 181 TextRun SVGInlineTextBox::constructTextRun(RenderStyle* style, const SVGTextFrag
ment& fragment) const |
| 394 { | 182 { |
| 395 ASSERT(style); | 183 ASSERT(style); |
| 396 | 184 |
| 397 RenderText* text = &renderer(); | 185 RenderText* text = &renderer(); |
| 398 | 186 |
| 399 // 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 |
| 400 // 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 Loading... |
| 447 endPosition = length; | 235 endPosition = length; |
| 448 else { | 236 else { |
| 449 ASSERT(endPosition >= offset); | 237 ASSERT(endPosition >= offset); |
| 450 endPosition -= offset; | 238 endPosition -= offset; |
| 451 } | 239 } |
| 452 | 240 |
| 453 ASSERT(startPosition < endPosition); | 241 ASSERT(startPosition < endPosition); |
| 454 return true; | 242 return true; |
| 455 } | 243 } |
| 456 | 244 |
| 457 // Offset from the baseline for |decoration|. Positive offsets are above the bas
eline. | |
| 458 static inline float baselineOffsetForDecoration(TextDecoration decoration, const
FontMetrics& fontMetrics, float thickness) | |
| 459 { | |
| 460 // FIXME: For SVG Fonts we need to use the attributes defined in the <font-f
ace> if specified. | |
| 461 // Compatible with Batik/Presto. | |
| 462 if (decoration == TextDecorationUnderline) | |
| 463 return -thickness * 1.5f; | |
| 464 if (decoration == TextDecorationOverline) | |
| 465 return fontMetrics.floatAscent() - thickness; | |
| 466 if (decoration == TextDecorationLineThrough) | |
| 467 return fontMetrics.floatAscent() * 3 / 8.0f; | |
| 468 | |
| 469 ASSERT_NOT_REACHED(); | |
| 470 return 0.0f; | |
| 471 } | |
| 472 | |
| 473 static inline float thicknessForDecoration(TextDecoration, const Font& font) | |
| 474 { | |
| 475 // FIXME: For SVG Fonts we need to use the attributes defined in the <font-f
ace> if specified. | |
| 476 // Compatible with Batik/Presto | |
| 477 return font.fontDescription().computedSize() / 20.0f; | |
| 478 } | |
| 479 | |
| 480 static inline RenderObject* findRenderObjectDefininingTextDecoration(InlineFlowB
ox* parentBox) | |
| 481 { | |
| 482 // Lookup first render object in parent hierarchy which has text-decoration
set. | |
| 483 RenderObject* renderer = 0; | |
| 484 while (parentBox) { | |
| 485 renderer = &parentBox->renderer(); | |
| 486 | |
| 487 if (renderer->style() && renderer->style()->textDecoration() != TextDeco
rationNone) | |
| 488 break; | |
| 489 | |
| 490 parentBox = parentBox->parent(); | |
| 491 } | |
| 492 | |
| 493 ASSERT(renderer); | |
| 494 return renderer; | |
| 495 } | |
| 496 | |
| 497 void SVGInlineTextBox::paintDecoration(GraphicsContext* context, TextDecoration
decoration, const SVGTextFragment& fragment) | |
| 498 { | |
| 499 if (renderer().style()->textDecorationsInEffect() == TextDecorationNone) | |
| 500 return; | |
| 501 | |
| 502 // Find out which render style defined the text-decoration, as its fill/stro
ke properties have to be used for drawing instead of ours. | |
| 503 RenderObject* decorationRenderer = findRenderObjectDefininingTextDecoration(
parent()); | |
| 504 RenderStyle* decorationStyle = decorationRenderer->style(); | |
| 505 ASSERT(decorationStyle); | |
| 506 | |
| 507 if (decorationStyle->visibility() == HIDDEN) | |
| 508 return; | |
| 509 | |
| 510 const SVGRenderStyle& svgDecorationStyle = decorationStyle->svgStyle(); | |
| 511 | |
| 512 for (int i = 0; i < 3; i++) { | |
| 513 switch (svgDecorationStyle.paintOrderType(i)) { | |
| 514 case PT_FILL: | |
| 515 if (svgDecorationStyle.hasFill()) | |
| 516 paintDecorationWithStyle(context, decoration, fragment, decorati
onRenderer, ApplyToFillMode); | |
| 517 break; | |
| 518 case PT_STROKE: | |
| 519 if (svgDecorationStyle.hasVisibleStroke()) | |
| 520 paintDecorationWithStyle(context, decoration, fragment, decorati
onRenderer, ApplyToStrokeMode); | |
| 521 break; | |
| 522 case PT_MARKERS: | |
| 523 break; | |
| 524 default: | |
| 525 ASSERT_NOT_REACHED(); | |
| 526 } | |
| 527 } | |
| 528 } | |
| 529 | |
| 530 void SVGInlineTextBox::paintDecorationWithStyle(GraphicsContext* context, TextDe
coration decoration, | |
| 531 const SVGTextFragment& fragment, RenderObject* decorationRenderer, RenderSVG
ResourceModeFlags resourceMode) | |
| 532 { | |
| 533 ASSERT(resourceMode != ApplyToDefaultMode); | |
| 534 | |
| 535 RenderStyle* decorationStyle = decorationRenderer->style(); | |
| 536 ASSERT(decorationStyle); | |
| 537 | |
| 538 float scalingFactor = 1; | |
| 539 Font scaledFont; | |
| 540 RenderSVGInlineText::computeNewScaledFontForStyle(decorationRenderer, decora
tionStyle, scalingFactor, scaledFont); | |
| 541 ASSERT(scalingFactor); | |
| 542 | |
| 543 float thickness = thicknessForDecoration(decoration, scaledFont); | |
| 544 | |
| 545 if (fragment.width <= 0 && thickness <= 0) | |
| 546 return; | |
| 547 | |
| 548 float decorationOffset = baselineOffsetForDecoration(decoration, scaledFont.
fontMetrics(), thickness); | |
| 549 FloatPoint decorationOrigin(fragment.x, fragment.y - decorationOffset / scal
ingFactor); | |
| 550 | |
| 551 Path path; | |
| 552 path.addRect(FloatRect(decorationOrigin, FloatSize(fragment.width, thickness
/ scalingFactor))); | |
| 553 | |
| 554 PaintingResourceScope resourceScope(*decorationRenderer); | |
| 555 if (resourceScope.acquirePaintingResource(context, decorationStyle, resource
Mode)) { | |
| 556 SVGRenderSupport::fillOrStrokePath(context, resourceMode, path); | |
| 557 resourceScope.releasePaintingResource(context); | |
| 558 } | |
| 559 } | |
| 560 | |
| 561 void SVGInlineTextBox::paintTextWithShadows(GraphicsContext* context, RenderStyl
e* style, | |
| 562 TextRun& textRun, const SVGTextFragment& fragment, int startPosition, int en
dPosition, | |
| 563 RenderSVGResourceModeFlags resourceMode) | |
| 564 { | |
| 565 RenderSVGInlineText& textRenderer = toRenderSVGInlineText(this->renderer()); | |
| 566 | |
| 567 float scalingFactor = textRenderer.scalingFactor(); | |
| 568 ASSERT(scalingFactor); | |
| 569 | |
| 570 const Font& scaledFont = textRenderer.scaledFont(); | |
| 571 const ShadowList* shadowList = style->textShadow(); | |
| 572 | |
| 573 // Text shadows are disabled when printing. http://crbug.com/258321 | |
| 574 bool hasShadow = shadowList && !context->printing(); | |
| 575 | |
| 576 FloatPoint textOrigin(fragment.x, fragment.y); | |
| 577 FloatSize textSize(fragment.width, fragment.height); | |
| 578 | |
| 579 if (scalingFactor != 1) { | |
| 580 textOrigin.scale(scalingFactor, scalingFactor); | |
| 581 textSize.scale(scalingFactor); | |
| 582 context->save(); | |
| 583 context->scale(1 / scalingFactor, 1 / scalingFactor); | |
| 584 } | |
| 585 | |
| 586 if (hasShadow) | |
| 587 context->setDrawLooper(shadowList->createDrawLooper(DrawLooperBuilder::S
hadowRespectsAlpha)); | |
| 588 | |
| 589 PaintingResourceScope resourceScope(parent()->renderer()); | |
| 590 if (resourceScope.acquirePaintingResource(context, style, resourceMode)) { | |
| 591 if (scalingFactor != 1 && resourceMode & ApplyToStrokeMode) | |
| 592 context->setStrokeThickness(context->strokeThickness() * scalingFact
or); | |
| 593 | |
| 594 TextRunPaintInfo textRunPaintInfo(textRun); | |
| 595 textRunPaintInfo.from = startPosition; | |
| 596 textRunPaintInfo.to = endPosition; | |
| 597 | |
| 598 float baseline = scaledFont.fontMetrics().floatAscent(); | |
| 599 textRunPaintInfo.bounds = FloatRect(textOrigin.x(), textOrigin.y() - bas
eline, | |
| 600 textSize.width(), textSize.height()); | |
| 601 | |
| 602 scaledFont.drawText(context, textRunPaintInfo, textOrigin); | |
| 603 resourceScope.releasePaintingResource(context); | |
| 604 } | |
| 605 | |
| 606 if (scalingFactor != 1) | |
| 607 context->restore(); | |
| 608 else if (hasShadow) | |
| 609 context->clearShadow(); | |
| 610 } | |
| 611 | |
| 612 void SVGInlineTextBox::paintText(GraphicsContext* context, RenderStyle* style, | |
| 613 RenderStyle* selectionStyle, const SVGTextFragment& fragment, | |
| 614 RenderSVGResourceModeFlags resourceMode, bool hasSelection, bool paintSelect
edTextOnly) | |
| 615 { | |
| 616 ASSERT(style); | |
| 617 ASSERT(selectionStyle); | |
| 618 | |
| 619 int startPosition = 0; | |
| 620 int endPosition = 0; | |
| 621 if (hasSelection) { | |
| 622 selectionStartEnd(startPosition, endPosition); | |
| 623 hasSelection = mapStartEndPositionsIntoFragmentCoordinates(fragment, sta
rtPosition, endPosition); | |
| 624 } | |
| 625 | |
| 626 // Fast path if there is no selection, just draw the whole chunk part using
the regular style | |
| 627 TextRun textRun = constructTextRun(style, fragment); | |
| 628 if (!hasSelection || startPosition >= endPosition) { | |
| 629 paintTextWithShadows(context, style, textRun, fragment, 0, fragment.leng
th, resourceMode); | |
| 630 return; | |
| 631 } | |
| 632 | |
| 633 // Eventually draw text using regular style until the start position of the
selection | |
| 634 if (startPosition > 0 && !paintSelectedTextOnly) | |
| 635 paintTextWithShadows(context, style, textRun, fragment, 0, startPosition
, resourceMode); | |
| 636 | |
| 637 // Draw text using selection style from the start to the end position of the
selection | |
| 638 if (style != selectionStyle) { | |
| 639 StyleDifference diff; | |
| 640 diff.setNeedsPaintInvalidationObject(); | |
| 641 SVGResourcesCache::clientStyleChanged(&parent()->renderer(), diff, selec
tionStyle); | |
| 642 } | |
| 643 | |
| 644 paintTextWithShadows(context, selectionStyle, textRun, fragment, startPositi
on, endPosition, resourceMode); | |
| 645 | |
| 646 if (style != selectionStyle) { | |
| 647 StyleDifference diff; | |
| 648 diff.setNeedsPaintInvalidationObject(); | |
| 649 SVGResourcesCache::clientStyleChanged(&parent()->renderer(), diff, style
); | |
| 650 } | |
| 651 | |
| 652 // Eventually draw text using regular style from the end position of the sel
ection to the end of the current chunk part | |
| 653 if (endPosition < static_cast<int>(fragment.length) && !paintSelectedTextOnl
y) | |
| 654 paintTextWithShadows(context, style, textRun, fragment, endPosition, fra
gment.length, resourceMode); | |
| 655 } | |
| 656 | |
| 657 void SVGInlineTextBox::paintDocumentMarker(GraphicsContext*, const FloatPoint&,
DocumentMarker*, RenderStyle*, const Font&, bool) | 245 void SVGInlineTextBox::paintDocumentMarker(GraphicsContext*, const FloatPoint&,
DocumentMarker*, RenderStyle*, const Font&, bool) |
| 658 { | 246 { |
| 659 // 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). |
| 660 } | 248 } |
| 661 | 249 |
| 662 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) |
| 663 { | 251 { |
| 664 // SVG is only interested in the TextMatch markers. | 252 SVGInlineTextBoxPainter(*this).paintTextMatchMarker(context, point, marker,
style, font); |
| 665 if (marker->type() != DocumentMarker::TextMatch) | |
| 666 return; | |
| 667 | |
| 668 RenderSVGInlineText& textRenderer = toRenderSVGInlineText(this->renderer()); | |
| 669 | |
| 670 FloatRect markerRect; | |
| 671 AffineTransform fragmentTransform; | |
| 672 for (InlineTextBox* box = textRenderer.firstTextBox(); box; box = box->nextT
extBox()) { | |
| 673 if (!box->isSVGInlineTextBox()) | |
| 674 continue; | |
| 675 | |
| 676 SVGInlineTextBox* textBox = toSVGInlineTextBox(box); | |
| 677 | |
| 678 int markerStartPosition = std::max<int>(marker->startOffset() - textBox-
>start(), 0); | |
| 679 int markerEndPosition = std::min<int>(marker->endOffset() - textBox->sta
rt(), textBox->len()); | |
| 680 | |
| 681 if (markerStartPosition >= markerEndPosition) | |
| 682 continue; | |
| 683 | |
| 684 const Vector<SVGTextFragment>& fragments = textBox->textFragments(); | |
| 685 unsigned textFragmentsSize = fragments.size(); | |
| 686 for (unsigned i = 0; i < textFragmentsSize; ++i) { | |
| 687 const SVGTextFragment& fragment = fragments.at(i); | |
| 688 | |
| 689 int fragmentStartPosition = markerStartPosition; | |
| 690 int fragmentEndPosition = markerEndPosition; | |
| 691 if (!textBox->mapStartEndPositionsIntoFragmentCoordinates(fragment,
fragmentStartPosition, fragmentEndPosition)) | |
| 692 continue; | |
| 693 | |
| 694 FloatRect fragmentRect = textBox->selectionRectForTextFragment(fragm
ent, fragmentStartPosition, fragmentEndPosition, style); | |
| 695 fragment.buildFragmentTransform(fragmentTransform); | |
| 696 | |
| 697 // Draw the marker highlight. | |
| 698 if (renderer().frame()->editor().markedTextMatchesAreHighlighted())
{ | |
| 699 Color color = marker->activeMatch() ? | |
| 700 RenderTheme::theme().platformActiveTextSearchHighlightColor(
) : | |
| 701 RenderTheme::theme().platformInactiveTextSearchHighlightColo
r(); | |
| 702 GraphicsContextStateSaver stateSaver(*context); | |
| 703 if (!fragmentTransform.isIdentity()) | |
| 704 context->concatCTM(fragmentTransform); | |
| 705 context->setFillColor(color); | |
| 706 context->fillRect(fragmentRect, color); | |
| 707 } | |
| 708 | |
| 709 fragmentRect = fragmentTransform.mapRect(fragmentRect); | |
| 710 markerRect.unite(fragmentRect); | |
| 711 } | |
| 712 } | |
| 713 | |
| 714 toRenderedDocumentMarker(marker)->setRenderedRect(textRenderer.localToAbsolu
teQuad(markerRect).enclosingBoundingBox()); | |
| 715 } | 253 } |
| 716 | 254 |
| 717 FloatRect SVGInlineTextBox::calculateBoundaries() const | 255 FloatRect SVGInlineTextBox::calculateBoundaries() const |
| 718 { | 256 { |
| 719 FloatRect textRect; | 257 FloatRect textRect; |
| 720 | 258 |
| 721 RenderSVGInlineText& textRenderer = toRenderSVGInlineText(this->renderer()); | 259 RenderSVGInlineText& textRenderer = toRenderSVGInlineText(this->renderer()); |
| 722 | 260 |
| 723 float scalingFactor = textRenderer.scalingFactor(); | 261 float scalingFactor = textRenderer.scalingFactor(); |
| 724 ASSERT(scalingFactor); | 262 ASSERT(scalingFactor); |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 757 renderer().updateHitTestResult(result, locationInContainer.point
() - toLayoutSize(accumulatedOffset)); | 295 renderer().updateHitTestResult(result, locationInContainer.point
() - toLayoutSize(accumulatedOffset)); |
| 758 if (!result.addNodeToRectBasedTestResult(renderer().node(), requ
est, locationInContainer, rect)) | 296 if (!result.addNodeToRectBasedTestResult(renderer().node(), requ
est, locationInContainer, rect)) |
| 759 return true; | 297 return true; |
| 760 } | 298 } |
| 761 } | 299 } |
| 762 } | 300 } |
| 763 return false; | 301 return false; |
| 764 } | 302 } |
| 765 | 303 |
| 766 } // namespace blink | 304 } // namespace blink |
| OLD | NEW |