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

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

Issue 752083003: Use IDL union types for CanvasRenderingContext2D.{fill,stroke}Style (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Created 6 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 | 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 416 matching lines...) Expand 10 before | Expand all | Expand 10 after
427 return; 427 return;
428 m_path.transform(state().m_transform); 428 m_path.transform(state().m_transform);
429 m_stateStack.removeLast(); 429 m_stateStack.removeLast();
430 m_path.transform(state().m_transform.inverse()); 430 m_path.transform(state().m_transform.inverse());
431 GraphicsContext* c = drawingContext(); 431 GraphicsContext* c = drawingContext();
432 if (c) 432 if (c)
433 c->restore(); 433 c->restore();
434 validateStateStack(); 434 validateStateStack();
435 } 435 }
436 436
437 CanvasStyle* CanvasRenderingContext2D::strokeStyle() const 437 static inline void convertCanvasStyleToUnionType(CanvasStyle* style, StringOrCan vasGradientOrCanvasPattern& returnValue)
438 { 438 {
439 return state().m_strokeStyle.get(); 439 if (CanvasGradient* gradient = style->canvasGradient()) {
440 returnValue.setCanvasGradient(gradient);
441 return;
442 }
443 if (CanvasPattern* pattern = style->canvasPattern()) {
444 returnValue.setCanvasPattern(pattern);
445 return;
446 }
447 returnValue.setString(style->color());
440 } 448 }
441 449
442 void CanvasRenderingContext2D::setStrokeStyle(PassRefPtrWillBeRawPtr<CanvasStyle > prpStyle) 450 void CanvasRenderingContext2D::strokeStyle(StringOrCanvasGradientOrCanvasPattern & returnValue) const
443 { 451 {
444 RefPtrWillBeRawPtr<CanvasStyle> style = prpStyle; 452 convertCanvasStyleToUnionType(state().m_strokeStyle.get(), returnValue);
453 }
445 454
446 if (!style) 455 void CanvasRenderingContext2D::setStrokeStyle(const StringOrCanvasGradientOrCanv asPattern& style)
447 return; 456 {
457 ASSERT(!style.isNull());
448 458
449 if (state().m_strokeStyle && state().m_strokeStyle->isEquivalentColor(*style )) 459 String colorString;
450 return; 460 RefPtrWillBeRawPtr<CanvasStyle> canvasStyle;
461 if (style.isString()) {
462 colorString = style.getAsString();
463 if (colorString == state().m_unparsedStrokeColor)
fs 2014/11/24 13:20:24 The removal of the legacy APIs seems to have dropp
Justin Novosad 2014/11/24 15:41:02 Thanks for catching that. the removal was unintent
464 return;
465 RGBA32 parsedColor = 0;
466 if (!parseColorOrCurrentColor(parsedColor, colorString, canvas()))
467 return;
468 if (state().m_strokeStyle->isEquivalentRGBA(parsedColor)) {
469 realizeSaves(nullptr);
470 modifiableState().m_unparsedStrokeColor = colorString;
471 return;
472 }
473 canvasStyle = CanvasStyle::createFromRGBA(parsedColor);
474 } else if (style.isCanvasGradient()) {
475 canvasStyle = CanvasStyle::createFromGradient(style.getAsCanvasGradient( ));
476 } else if (style.isCanvasPattern()) {
477 RefPtrWillBeRawPtr<CanvasPattern> canvasPattern = style.getAsCanvasPatte rn();
451 478
452 if (style->isCurrentColor()) { 479 if (canvas()->originClean() && !canvasPattern->originClean())
453 if (style->hasOverrideAlpha()) 480 canvas()->setOriginTainted();
454 style = CanvasStyle::createFromRGBA(colorWithOverrideAlpha(currentCo lor(canvas()), style->overrideAlpha())); 481
455 else 482 canvasStyle = CanvasStyle::createFromPattern(canvasPattern);
456 style = CanvasStyle::createFromRGBA(currentColor(canvas()));
457 } else if (canvas()->originClean() && style->canvasPattern() && !style->canv asPattern()->originClean()) {
458 canvas()->setOriginTainted();
459 } 483 }
460 484
485 ASSERT(canvasStyle);
486
461 GraphicsContext* c = drawingContext(); 487 GraphicsContext* c = drawingContext();
462 realizeSaves(c); 488 realizeSaves(c);
463 modifiableState().m_strokeStyle = style.release(); 489 modifiableState().m_strokeStyle = canvasStyle.release();
464 if (!c) 490 if (!c)
465 return; 491 return;
466 state().m_strokeStyle->applyStrokeColor(c); 492 state().m_strokeStyle->applyStrokeColor(c);
467 modifiableState().m_unparsedStrokeColor = String(); 493 modifiableState().m_unparsedStrokeColor = colorString;
468 } 494 }
469 495
470 CanvasStyle* CanvasRenderingContext2D::fillStyle() const 496 void CanvasRenderingContext2D::fillStyle(StringOrCanvasGradientOrCanvasPattern& returnValue) const
471 { 497 {
472 return state().m_fillStyle.get(); 498 convertCanvasStyleToUnionType(state().m_fillStyle.get(), returnValue);
473 } 499 }
474 500
475 void CanvasRenderingContext2D::setFillStyle(PassRefPtrWillBeRawPtr<CanvasStyle> prpStyle) 501 void CanvasRenderingContext2D::setFillStyle(const StringOrCanvasGradientOrCanvas Pattern& style)
476 { 502 {
477 RefPtrWillBeRawPtr<CanvasStyle> style = prpStyle; 503 ASSERT(!style.isNull());
478 504
479 if (!style) 505 String colorString;
480 return; 506 RefPtrWillBeRawPtr<CanvasStyle> canvasStyle;
507 if (style.isString()) {
508 colorString = style.getAsString();
509 if (colorString == state().m_unparsedFillColor)
510 return;
511 RGBA32 parsedColor = 0;
512 if (!parseColorOrCurrentColor(parsedColor, colorString, canvas()))
513 return;
514 if (state().m_fillStyle->isEquivalentRGBA(parsedColor)) {
515 realizeSaves(nullptr);
516 modifiableState().m_unparsedFillColor = colorString;
517 return;
518 }
519 canvasStyle = CanvasStyle::createFromRGBA(parsedColor);
520 } else if (style.isCanvasGradient()) {
521 canvasStyle = CanvasStyle::createFromGradient(style.getAsCanvasGradient( ));
522 } else if (style.isCanvasPattern()) {
523 RefPtrWillBeRawPtr<CanvasPattern> canvasPattern = style.getAsCanvasPatte rn();
481 524
482 if (state().m_fillStyle && state().m_fillStyle->isEquivalentColor(*style)) 525 if (canvas()->originClean() && !canvasPattern->originClean())
483 return; 526 canvas()->setOriginTainted();
484 527
485 if (style->isCurrentColor()) { 528 canvasStyle = CanvasStyle::createFromPattern(canvasPattern);
486 if (style->hasOverrideAlpha())
487 style = CanvasStyle::createFromRGBA(colorWithOverrideAlpha(currentCo lor(canvas()), style->overrideAlpha()));
488 else
489 style = CanvasStyle::createFromRGBA(currentColor(canvas()));
490 } else if (canvas()->originClean() && style->canvasPattern() && !style->canv asPattern()->originClean()) {
491 canvas()->setOriginTainted();
492 } 529 }
493 530
531 ASSERT(canvasStyle);
532
494 GraphicsContext* c = drawingContext(); 533 GraphicsContext* c = drawingContext();
495 realizeSaves(c); 534 realizeSaves(c);
496 modifiableState().m_fillStyle = style.release(); 535 modifiableState().m_fillStyle = canvasStyle.release();
497 if (!c) 536 if (!c)
498 return; 537 return;
499 state().m_fillStyle->applyFillColor(c); 538 state().m_fillStyle->applyFillColor(c);
500 modifiableState().m_unparsedFillColor = String(); 539 modifiableState().m_unparsedFillColor = colorString;
501 } 540 }
502 541
503 float CanvasRenderingContext2D::lineWidth() const 542 float CanvasRenderingContext2D::lineWidth() const
504 { 543 {
505 return state().m_lineWidth; 544 return state().m_lineWidth;
506 } 545 }
507 546
508 void CanvasRenderingContext2D::setLineWidth(float width) 547 void CanvasRenderingContext2D::setLineWidth(float width)
509 { 548 {
510 if (!std::isfinite(width) || width <= 0) 549 if (!std::isfinite(width) || width <= 0)
(...skipping 1816 matching lines...) Expand 10 before | Expand all | Expand 10 after
2327 2366
2328 unsigned CanvasRenderingContext2D::hitRegionsCount() const 2367 unsigned CanvasRenderingContext2D::hitRegionsCount() const
2329 { 2368 {
2330 if (m_hitRegionManager) 2369 if (m_hitRegionManager)
2331 return m_hitRegionManager->getHitRegionsCount(); 2370 return m_hitRegionManager->getHitRegionsCount();
2332 2371
2333 return 0; 2372 return 0;
2334 } 2373 }
2335 2374
2336 } // namespace blink 2375 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698