| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011, 2012 Apple Inc.
All rights reserved. | 2 * Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011, 2012 Apple Inc.
All rights reserved. |
| 3 * Copyright (C) 2008, 2010 Nokia Corporation and/or its subsidiary(-ies) | 3 * Copyright (C) 2008, 2010 Nokia Corporation and/or its subsidiary(-ies) |
| 4 * Copyright (C) 2007 Alp Toker <alp@atoker.com> | 4 * Copyright (C) 2007 Alp Toker <alp@atoker.com> |
| 5 * Copyright (C) 2008 Eric Seidel <eric@webkit.org> | 5 * Copyright (C) 2008 Eric Seidel <eric@webkit.org> |
| 6 * Copyright (C) 2008 Dirk Schulze <krit@webkit.org> | 6 * Copyright (C) 2008 Dirk Schulze <krit@webkit.org> |
| 7 * Copyright (C) 2010 Torch Mobile (Beijing) Co. Ltd. All rights reserved. | 7 * Copyright (C) 2010 Torch Mobile (Beijing) Co. Ltd. All rights reserved. |
| 8 * Copyright (C) 2012, 2013 Intel Corporation. All rights reserved. | 8 * Copyright (C) 2012, 2013 Intel Corporation. All rights reserved. |
| 9 * Copyright (C) 2013 Adobe Systems Incorporated. All rights reserved. | 9 * Copyright (C) 2013 Adobe Systems Incorporated. All rights reserved. |
| 10 * | 10 * |
| (...skipping 391 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 402 return canvas()->baseTransform(); | 402 return canvas()->baseTransform(); |
| 403 } | 403 } |
| 404 | 404 |
| 405 String CanvasRenderingContext2D::font() const | 405 String CanvasRenderingContext2D::font() const |
| 406 { | 406 { |
| 407 if (!state().hasRealizedFont()) | 407 if (!state().hasRealizedFont()) |
| 408 return defaultFont; | 408 return defaultFont; |
| 409 | 409 |
| 410 canvas()->document().canvasFontCache()->willUseCurrentFont(); | 410 canvas()->document().canvasFontCache()->willUseCurrentFont(); |
| 411 StringBuilder serializedFont; | 411 StringBuilder serializedFont; |
| 412 const FontDescription& fontDescription = state().font().fontDescription(); | 412 const FontDescription& fontDescription = state().font().getFontDescription()
; |
| 413 | 413 |
| 414 if (fontDescription.style() == FontStyleItalic) | 414 if (fontDescription.style() == FontStyleItalic) |
| 415 serializedFont.appendLiteral("italic "); | 415 serializedFont.appendLiteral("italic "); |
| 416 if (fontDescription.weight() == FontWeightBold) | 416 if (fontDescription.weight() == FontWeightBold) |
| 417 serializedFont.appendLiteral("bold "); | 417 serializedFont.appendLiteral("bold "); |
| 418 if (fontDescription.variant() == FontVariantSmallCaps) | 418 if (fontDescription.variant() == FontVariantSmallCaps) |
| 419 serializedFont.appendLiteral("small-caps "); | 419 serializedFont.appendLiteral("small-caps "); |
| 420 | 420 |
| 421 serializedFont.appendNumber(fontDescription.computedPixelSize()); | 421 serializedFont.appendNumber(fontDescription.computedPixelSize()); |
| 422 serializedFont.appendLiteral("px"); | 422 serializedFont.appendLiteral("px"); |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 466 if (i != m_fontsResolvedUsingCurrentStyle.end()) { | 466 if (i != m_fontsResolvedUsingCurrentStyle.end()) { |
| 467 ASSERT(m_fontLRUList.contains(newFont)); | 467 ASSERT(m_fontLRUList.contains(newFont)); |
| 468 m_fontLRUList.remove(newFont); | 468 m_fontLRUList.remove(newFont); |
| 469 m_fontLRUList.add(newFont); | 469 m_fontLRUList.add(newFont); |
| 470 modifiableState().setFont(i->value, canvas()->document().styleEngine
().fontSelector()); | 470 modifiableState().setFont(i->value, canvas()->document().styleEngine
().fontSelector()); |
| 471 } else { | 471 } else { |
| 472 MutableStylePropertySet* parsedStyle = canvasFontCache->parseFont(ne
wFont); | 472 MutableStylePropertySet* parsedStyle = canvasFontCache->parseFont(ne
wFont); |
| 473 if (!parsedStyle) | 473 if (!parsedStyle) |
| 474 return; | 474 return; |
| 475 fontStyle = ComputedStyle::create(); | 475 fontStyle = ComputedStyle::create(); |
| 476 FontDescription elementFontDescription(computedStyle->fontDescriptio
n()); | 476 FontDescription elementFontDescription(computedStyle->getFontDescrip
tion()); |
| 477 // Reset the computed size to avoid inheriting the zoom factor from
the <canvas> element. | 477 // Reset the computed size to avoid inheriting the zoom factor from
the <canvas> element. |
| 478 elementFontDescription.setComputedSize(elementFontDescription.specif
iedSize()); | 478 elementFontDescription.setComputedSize(elementFontDescription.specif
iedSize()); |
| 479 fontStyle->setFontDescription(elementFontDescription); | 479 fontStyle->setFontDescription(elementFontDescription); |
| 480 fontStyle->font().update(fontStyle->font().fontSelector()); | 480 fontStyle->font().update(fontStyle->font().getFontSelector()); |
| 481 canvas()->document().ensureStyleResolver().computeFont(fontStyle.get
(), *parsedStyle); | 481 canvas()->document().ensureStyleResolver().computeFont(fontStyle.get
(), *parsedStyle); |
| 482 m_fontsResolvedUsingCurrentStyle.add(newFont, fontStyle->font()); | 482 m_fontsResolvedUsingCurrentStyle.add(newFont, fontStyle->font()); |
| 483 ASSERT(!m_fontLRUList.contains(newFont)); | 483 ASSERT(!m_fontLRUList.contains(newFont)); |
| 484 m_fontLRUList.add(newFont); | 484 m_fontLRUList.add(newFont); |
| 485 pruneLocalFontCache(canvasFontCache->hardMaxFonts()); // hard limit | 485 pruneLocalFontCache(canvasFontCache->hardMaxFonts()); // hard limit |
| 486 schedulePruneLocalFontCacheIfNeeded(); // soft limit | 486 schedulePruneLocalFontCacheIfNeeded(); // soft limit |
| 487 modifiableState().setFont(fontStyle->font(), canvas()->document().st
yleEngine().fontSelector()); | 487 modifiableState().setFont(fontStyle->font(), canvas()->document().st
yleEngine().fontSelector()); |
| 488 } | 488 } |
| 489 } else { | 489 } else { |
| 490 Font resolvedFont; | 490 Font resolvedFont; |
| (...skipping 190 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 681 canvas()->document().updateLayoutTreeForNode(canvas()); | 681 canvas()->document().updateLayoutTreeForNode(canvas()); |
| 682 const Font& font = accessFont(); | 682 const Font& font = accessFont(); |
| 683 | 683 |
| 684 TextDirection direction; | 684 TextDirection direction; |
| 685 if (state().getDirection() == CanvasRenderingContext2DState::DirectionInheri
t) | 685 if (state().getDirection() == CanvasRenderingContext2DState::DirectionInheri
t) |
| 686 direction = determineDirectionality(text); | 686 direction = determineDirectionality(text); |
| 687 else | 687 else |
| 688 direction = toTextDirection(state().getDirection(), canvas()); | 688 direction = toTextDirection(state().getDirection(), canvas()); |
| 689 TextRun textRun(text, 0, 0, TextRun::AllowTrailingExpansion | TextRun::Forbi
dLeadingExpansion, direction, false); | 689 TextRun textRun(text, 0, 0, TextRun::AllowTrailingExpansion | TextRun::Forbi
dLeadingExpansion, direction, false); |
| 690 textRun.setNormalizeSpace(true); | 690 textRun.setNormalizeSpace(true); |
| 691 FloatRect textBounds = font.selectionRectForText(textRun, FloatPoint(), font
.fontDescription().computedSize(), 0, -1, true); | 691 FloatRect textBounds = font.selectionRectForText(textRun, FloatPoint(), font
.getFontDescription().computedSize(), 0, -1, true); |
| 692 | 692 |
| 693 // x direction | 693 // x direction |
| 694 metrics->setWidth(font.width(textRun)); | 694 metrics->setWidth(font.width(textRun)); |
| 695 metrics->setActualBoundingBoxLeft(-textBounds.x()); | 695 metrics->setActualBoundingBoxLeft(-textBounds.x()); |
| 696 metrics->setActualBoundingBoxRight(textBounds.maxX()); | 696 metrics->setActualBoundingBoxRight(textBounds.maxX()); |
| 697 | 697 |
| 698 // y direction | 698 // y direction |
| 699 const FontMetrics& fontMetrics = font.fontMetrics(); | 699 const FontMetrics& fontMetrics = font.getFontMetrics(); |
| 700 const float ascent = fontMetrics.floatAscent(); | 700 const float ascent = fontMetrics.floatAscent(); |
| 701 const float descent = fontMetrics.floatDescent(); | 701 const float descent = fontMetrics.floatDescent(); |
| 702 const float baselineY = getFontBaseline(fontMetrics); | 702 const float baselineY = getFontBaseline(fontMetrics); |
| 703 | 703 |
| 704 metrics->setFontBoundingBoxAscent(ascent - baselineY); | 704 metrics->setFontBoundingBoxAscent(ascent - baselineY); |
| 705 metrics->setFontBoundingBoxDescent(descent + baselineY); | 705 metrics->setFontBoundingBoxDescent(descent + baselineY); |
| 706 metrics->setActualBoundingBoxAscent(-textBounds.y() - baselineY); | 706 metrics->setActualBoundingBoxAscent(-textBounds.y() - baselineY); |
| 707 metrics->setActualBoundingBoxDescent(textBounds.maxY() + baselineY); | 707 metrics->setActualBoundingBoxDescent(textBounds.maxY() + baselineY); |
| 708 | 708 |
| 709 // Note : top/bottom and ascend/descend are currently the same, so there's n
o difference | 709 // Note : top/bottom and ascend/descend are currently the same, so there's n
o difference |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 741 // is expected when !m_hasAlpha, so we need to fall out of display list mode
when | 741 // is expected when !m_hasAlpha, so we need to fall out of display list mode
when |
| 742 // drawing text to an opaque canvas | 742 // drawing text to an opaque canvas |
| 743 // crbug.com/583809 | 743 // crbug.com/583809 |
| 744 if (!m_hasAlpha && !isAccelerated()) | 744 if (!m_hasAlpha && !isAccelerated()) |
| 745 canvas()->disableDeferral(DisableDeferralReasonSubPixelTextAntiAliasingS
upport); | 745 canvas()->disableDeferral(DisableDeferralReasonSubPixelTextAntiAliasingS
upport); |
| 746 | 746 |
| 747 const Font& font = accessFont(); | 747 const Font& font = accessFont(); |
| 748 if (!font.primaryFont()) | 748 if (!font.primaryFont()) |
| 749 return; | 749 return; |
| 750 | 750 |
| 751 const FontMetrics& fontMetrics = font.fontMetrics(); | 751 const FontMetrics& fontMetrics = font.getFontMetrics(); |
| 752 | 752 |
| 753 // FIXME: Need to turn off font smoothing. | 753 // FIXME: Need to turn off font smoothing. |
| 754 | 754 |
| 755 const ComputedStyle* computedStyle = 0; | 755 const ComputedStyle* computedStyle = 0; |
| 756 TextDirection direction = toTextDirection(state().getDirection(), canvas(),
&computedStyle); | 756 TextDirection direction = toTextDirection(state().getDirection(), canvas(),
&computedStyle); |
| 757 bool isRTL = direction == RTL; | 757 bool isRTL = direction == RTL; |
| 758 bool override = computedStyle ? isOverride(computedStyle->unicodeBidi()) : f
alse; | 758 bool override = computedStyle ? isOverride(computedStyle->unicodeBidi()) : f
alse; |
| 759 | 759 |
| 760 TextRun textRun(text, 0, 0, TextRun::AllowTrailingExpansion, direction, over
ride); | 760 TextRun textRun(text, 0, 0, TextRun::AllowTrailingExpansion, direction, over
ride); |
| 761 textRun.setNormalizeSpace(true); | 761 textRun.setNormalizeSpace(true); |
| (...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 908 } | 908 } |
| 909 | 909 |
| 910 void CanvasRenderingContext2D::drawFocusRing(const Path& path) | 910 void CanvasRenderingContext2D::drawFocusRing(const Path& path) |
| 911 { | 911 { |
| 912 if (!drawingCanvas()) | 912 if (!drawingCanvas()) |
| 913 return; | 913 return; |
| 914 | 914 |
| 915 SkColor color = LayoutTheme::theme().focusRingColor().rgb(); | 915 SkColor color = LayoutTheme::theme().focusRingColor().rgb(); |
| 916 const int focusRingWidth = 5; | 916 const int focusRingWidth = 5; |
| 917 | 917 |
| 918 drawPlatformFocusRing(path.skPath(), drawingCanvas(), color, focusRingWidth)
; | 918 drawPlatformFocusRing(path.getSkPath(), drawingCanvas(), color, focusRingWid
th); |
| 919 | 919 |
| 920 // We need to add focusRingWidth to dirtyRect. | 920 // We need to add focusRingWidth to dirtyRect. |
| 921 StrokeData strokeData; | 921 StrokeData strokeData; |
| 922 strokeData.setThickness(focusRingWidth); | 922 strokeData.setThickness(focusRingWidth); |
| 923 | 923 |
| 924 SkIRect dirtyRect; | 924 SkIRect dirtyRect; |
| 925 if (!computeDirtyRect(path.strokeBoundingRect(strokeData), &dirtyRect)) | 925 if (!computeDirtyRect(path.strokeBoundingRect(strokeData), &dirtyRect)) |
| 926 return; | 926 return; |
| 927 | 927 |
| 928 didDraw(dirtyRect); | 928 didDraw(dirtyRect); |
| (...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1015 | 1015 |
| 1016 unsigned CanvasRenderingContext2D::hitRegionsCount() const | 1016 unsigned CanvasRenderingContext2D::hitRegionsCount() const |
| 1017 { | 1017 { |
| 1018 if (m_hitRegionManager) | 1018 if (m_hitRegionManager) |
| 1019 return m_hitRegionManager->getHitRegionsCount(); | 1019 return m_hitRegionManager->getHitRegionsCount(); |
| 1020 | 1020 |
| 1021 return 0; | 1021 return 0; |
| 1022 } | 1022 } |
| 1023 | 1023 |
| 1024 } // namespace blink | 1024 } // namespace blink |
| OLD | NEW |