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

Side by Side Diff: Source/core/html/canvas/CanvasRenderingContext2D.cpp

Issue 232313004: Add StrictTypeChecking to CRC2D.{drawImage,createPattern} (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Created 6 years, 8 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 | Annotate | Revision Log
OLDNEW
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 1450 matching lines...) Expand 10 before | Expand all | Expand 10 after
1461 FloatSize offset = dstRect->location() - scaledSrcLocation; 1461 FloatSize offset = dstRect->location() - scaledSrcLocation;
1462 1462
1463 srcRect->intersect(imageRect); 1463 srcRect->intersect(imageRect);
1464 1464
1465 // To clip the destination rectangle in the same proportion, transform the c lipped src rect 1465 // To clip the destination rectangle in the same proportion, transform the c lipped src rect
1466 *dstRect = *srcRect; 1466 *dstRect = *srcRect;
1467 dstRect->scale(scale.width(), scale.height()); 1467 dstRect->scale(scale.width(), scale.height());
1468 dstRect->move(offset); 1468 dstRect->move(offset);
1469 } 1469 }
1470 1470
1471 static bool checkImageSource(CanvasImageSource* imageSource, ExceptionState& exc eptionState)
1472 {
1473 if (!imageSource) {
1474 // FIXME: Message should mention ImageBitmap once that feature ships.
1475 exceptionState.throwTypeError(ExceptionMessages::argumentNullOrIncorrect Type(1, String("HTMLImageElement, HTMLCanvasElement or HTMLVideoElement")));
1476 return false;
1477 }
1478 return true;
1479 }
1480
1481 void CanvasRenderingContext2D::drawImage(CanvasImageSource* imageSource, float x , float y, ExceptionState& exceptionState) 1471 void CanvasRenderingContext2D::drawImage(CanvasImageSource* imageSource, float x , float y, ExceptionState& exceptionState)
1482 { 1472 {
1483 if (!checkImageSource(imageSource, exceptionState))
1484 return;
1485 FloatSize destRectSize = imageSource->defaultDestinationSize(); 1473 FloatSize destRectSize = imageSource->defaultDestinationSize();
1486 drawImage(imageSource, x, y, destRectSize.width(), destRectSize.height(), ex ceptionState); 1474 drawImage(imageSource, x, y, destRectSize.width(), destRectSize.height(), ex ceptionState);
1487 } 1475 }
1488 1476
1489 void CanvasRenderingContext2D::drawImage(CanvasImageSource* imageSource, 1477 void CanvasRenderingContext2D::drawImage(CanvasImageSource* imageSource,
1490 float x, float y, float width, float height, ExceptionState& exceptionState) 1478 float x, float y, float width, float height, ExceptionState& exceptionState)
1491 { 1479 {
1492 if (!checkImageSource(imageSource, exceptionState))
1493 return;
1494 FloatSize sourceRectSize = imageSource->sourceSize(); 1480 FloatSize sourceRectSize = imageSource->sourceSize();
1495 drawImage(imageSource, 0, 0, sourceRectSize.width(), sourceRectSize.height() , x, y, width, height, exceptionState); 1481 drawImage(imageSource, 0, 0, sourceRectSize.width(), sourceRectSize.height() , x, y, width, height, exceptionState);
1496 } 1482 }
1497 1483
1498 void CanvasRenderingContext2D::drawImage(CanvasImageSource* imageSource, 1484 void CanvasRenderingContext2D::drawImage(CanvasImageSource* imageSource,
1499 float sx, float sy, float sw, float sh, 1485 float sx, float sy, float sw, float sh,
1500 float dx, float dy, float dw, float dh, ExceptionState& exceptionState) 1486 float dx, float dy, float dw, float dh, ExceptionState& exceptionState)
1501 { 1487 {
1502 GraphicsContext* c = drawingContext(); // Do not exit yet if !c because we m ay need to throw exceptions first 1488 GraphicsContext* c = drawingContext(); // Do not exit yet if !c because we m ay need to throw exceptions first
1503 CompositeOperator op = c ? c->compositeOperation() : CompositeSourceOver; 1489 CompositeOperator op = c ? c->compositeOperation() : CompositeSourceOver;
1504 blink::WebBlendMode blendMode = c ? c->blendModeOperation() : blink::WebBlen dModeNormal; 1490 blink::WebBlendMode blendMode = c ? c->blendModeOperation() : blink::WebBlen dModeNormal;
1505 drawImageInternal(imageSource, sx, sy, sw, sh, dx, dy, dw, dh, exceptionStat e, op, blendMode); 1491 drawImageInternal(imageSource, sx, sy, sw, sh, dx, dy, dw, dh, exceptionStat e, op, blendMode);
1506 } 1492 }
1507 1493
1508 void CanvasRenderingContext2D::drawImageInternal(CanvasImageSource* imageSource, 1494 void CanvasRenderingContext2D::drawImageInternal(CanvasImageSource* imageSource,
1509 float sx, float sy, float sw, float sh, 1495 float sx, float sy, float sw, float sh,
1510 float dx, float dy, float dw, float dh, ExceptionState& exceptionState, 1496 float dx, float dy, float dw, float dh, ExceptionState& exceptionState,
1511 CompositeOperator op, blink::WebBlendMode blendMode) 1497 CompositeOperator op, blink::WebBlendMode blendMode)
1512 { 1498 {
1513 if (!checkImageSource(imageSource, exceptionState))
1514 return;
1515
1516 RefPtr<Image> image; 1499 RefPtr<Image> image;
1517 SourceImageStatus sourceImageStatus; 1500 SourceImageStatus sourceImageStatus;
1518 if (!imageSource->isVideoElement()) { 1501 if (!imageSource->isVideoElement()) {
1519 SourceImageMode mode = canvas() == imageSource ? CopySourceImageIfVolati le : DontCopySourceImage; // Thunking for == 1502 SourceImageMode mode = canvas() == imageSource ? CopySourceImageIfVolati le : DontCopySourceImage; // Thunking for ==
1520 image = imageSource->getSourceImageForCanvas(mode, &sourceImageStatus); 1503 image = imageSource->getSourceImageForCanvas(mode, &sourceImageStatus);
1521 if (sourceImageStatus == UndecodableSourceImageStatus) 1504 if (sourceImageStatus == UndecodableSourceImageStatus)
1522 exceptionState.throwDOMException(InvalidStateError, "The HTMLImageEl ement provided is in the 'broken' state."); 1505 exceptionState.throwDOMException(InvalidStateError, "The HTMLImageEl ement provided is in the 'broken' state.");
1523 if (!image || !image->width() || !image->height()) 1506 if (!image || !image->width() || !image->height())
1524 return; 1507 return;
1525 } 1508 }
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
1588 c->translate(-srcRect.x(), -srcRect.y()); 1571 c->translate(-srcRect.x(), -srcRect.y());
1589 video->paintCurrentFrameInContext(c, IntRect(IntPoint(), IntSize(video->vide oWidth(), video->videoHeight()))); 1572 video->paintCurrentFrameInContext(c, IntRect(IntPoint(), IntSize(video->vide oWidth(), video->videoHeight())));
1590 stateSaver.restore(); 1573 stateSaver.restore();
1591 } 1574 }
1592 1575
1593 void CanvasRenderingContext2D::drawImageFromRect(HTMLImageElement* image, 1576 void CanvasRenderingContext2D::drawImageFromRect(HTMLImageElement* image,
1594 float sx, float sy, float sw, float sh, 1577 float sx, float sy, float sw, float sh,
1595 float dx, float dy, float dw, float dh, 1578 float dx, float dy, float dw, float dh,
1596 const String& compositeOperation) 1579 const String& compositeOperation)
1597 { 1580 {
1581 if (!image)
1582 return;
1598 CompositeOperator op; 1583 CompositeOperator op;
1599 blink::WebBlendMode blendOp = blink::WebBlendModeNormal; 1584 blink::WebBlendMode blendOp = blink::WebBlendModeNormal;
1600 if (!parseCompositeAndBlendOperator(compositeOperation, op, blendOp) || blen dOp != blink::WebBlendModeNormal) 1585 if (!parseCompositeAndBlendOperator(compositeOperation, op, blendOp) || blen dOp != blink::WebBlendModeNormal)
1601 op = CompositeSourceOver; 1586 op = CompositeSourceOver;
1602 1587
1603 drawImageInternal(image, sx, sy, sw, sh, dx, dy, dw, dh, IGNORE_EXCEPTION, o p, blendOp); 1588 drawImageInternal(image, sx, sy, sw, sh, dx, dy, dw, dh, IGNORE_EXCEPTION, o p, blendOp);
1604 } 1589 }
1605 1590
1606 void CanvasRenderingContext2D::setAlpha(float alpha) 1591 void CanvasRenderingContext2D::setAlpha(float alpha)
1607 { 1592 {
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after
1709 if (exceptionState.hadException()) 1694 if (exceptionState.hadException())
1710 return nullptr; 1695 return nullptr;
1711 1696
1712 RefPtr<CanvasGradient> gradient = CanvasGradient::create(FloatPoint(x0, y0), r0, FloatPoint(x1, y1), r1); 1697 RefPtr<CanvasGradient> gradient = CanvasGradient::create(FloatPoint(x0, y0), r0, FloatPoint(x1, y1), r1);
1713 return gradient.release(); 1698 return gradient.release();
1714 } 1699 }
1715 1700
1716 PassRefPtr<CanvasPattern> CanvasRenderingContext2D::createPattern(CanvasImageSou rce* imageSource, 1701 PassRefPtr<CanvasPattern> CanvasRenderingContext2D::createPattern(CanvasImageSou rce* imageSource,
1717 const String& repetitionType, ExceptionState& exceptionState) 1702 const String& repetitionType, ExceptionState& exceptionState)
1718 { 1703 {
1719 if (!checkImageSource(imageSource, exceptionState))
1720 return nullptr;
1721 bool repeatX, repeatY; 1704 bool repeatX, repeatY;
1722 CanvasPattern::parseRepetitionType(repetitionType, repeatX, repeatY, excepti onState); 1705 CanvasPattern::parseRepetitionType(repetitionType, repeatX, repeatY, excepti onState);
1723 if (exceptionState.hadException()) 1706 if (exceptionState.hadException())
1724 return nullptr; 1707 return nullptr;
1725 1708
1726 SourceImageStatus status; 1709 SourceImageStatus status;
1727 RefPtr<Image> imageForRendering = imageSource->getSourceImageForCanvas(CopyS ourceImageIfVolatile, &status); 1710 RefPtr<Image> imageForRendering = imageSource->getSourceImageForCanvas(CopyS ourceImageIfVolatile, &status);
1728 1711
1729 switch (status) { 1712 switch (status) {
1730 case NormalSourceImageStatus: 1713 case NormalSourceImageStatus:
(...skipping 703 matching lines...) Expand 10 before | Expand all | Expand 10 after
2434 c->setAlphaAsFloat(1.0); 2417 c->setAlphaAsFloat(1.0);
2435 c->clearShadow(); 2418 c->clearShadow();
2436 c->setCompositeOperation(CompositeSourceOver, blink::WebBlendModeNormal); 2419 c->setCompositeOperation(CompositeSourceOver, blink::WebBlendModeNormal);
2437 c->drawFocusRing(path, focusRingWidth, focusRingOutline, focusRingColor); 2420 c->drawFocusRing(path, focusRingWidth, focusRingOutline, focusRingColor);
2438 c->restore(); 2421 c->restore();
2439 2422
2440 didDraw(dirtyRect); 2423 didDraw(dirtyRect);
2441 } 2424 }
2442 2425
2443 } // namespace WebCore 2426 } // namespace WebCore
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698