Changeset 128116 in webkit
- Timestamp:
- Sep 10, 2012 3:21:49 PM (12 years ago)
- Location:
- trunk
- Files:
-
- 6 added
- 8 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/LayoutTests/ChangeLog
r128113 r128116 1 2012-09-10 Justin Novosad <junov@chromium.org> 2 3 Implement canvas v5 line dash feature 4 https://bugs.webkit.org/show_bug.cgi?id=82560 5 6 Reviewed by Darin Adler. 7 8 New layout tests for the canvas lineDash feature. 9 -Validate normal behavior of lineDash state change operations. 10 -Validate behavior when attempting invalid state changes. 11 -Validate rendering behavior. 12 13 * fast/canvas/canvas-lineDash-expected.txt: Added. 14 * fast/canvas/canvas-lineDash-invalid-expected.txt: Added. 15 * fast/canvas/canvas-lineDash-invalid.html: Added. 16 * fast/canvas/canvas-lineDash.html: Added. 17 * fast/canvas/script-tests/canvas-lineDash-invalid.js: Added. 18 (resetLineDash): 19 (trySettingLineDash): 20 (trySettingLineDashWithNoArgs): 21 (trySettingLineDashOffset): 22 * fast/canvas/script-tests/canvas-lineDash.js: Added. 23 (dataToArray): 24 (getPixel): 25 (pixelShouldBe): 26 1 27 2012-08-31 Jon Lee <jonlee@apple.com> 2 28 -
trunk/Source/WebCore/ChangeLog
r128115 r128116 1 2012-09-10 Justin Novosad <junov@chromium.org> 2 3 Implement canvas v5 line dash feature 4 https://bugs.webkit.org/show_bug.cgi?id=82560 5 6 Reviewed by Darin Adler. 7 8 Adding new canvas 2d context API methods getLineDash and setLineDash, 9 and new attribute lineDashOffset. Implementation mostly based on 10 the existing webkitLineDash feature, with changes that reflect the 11 canvas v5 specification. This change is visible to all JS ports, 12 unlike webkitLineDash which is not exposed to V8. The new lineDash 13 and the legacy webkitLineDash features access the same rendering 14 context state. The JavasScriptCore binding layer was augmented to 15 support the sequence<float> IDL type. 16 17 Tests: fast/canvas/canvas-lineDash-invalid.html 18 fast/canvas/canvas-lineDash.html 19 20 * bindings/js/JSCanvasRenderingContext2DCustom.cpp: 21 (WebCore::JSCanvasRenderingContext2D::webkitLineDash): 22 (WebCore::JSCanvasRenderingContext2D::setWebkitLineDash): 23 * bindings/js/JSDOMBinding.h: 24 Added template specialization on float to NativeValueTraits in order to 25 add support for the sequence<double> IDL type to JavaScriptCore. 26 * html/canvas/CanvasRenderingContext2D.cpp: 27 (WebCore::CanvasRenderingContext2D::getLineDash): 28 New 2D canvas API method, returns the current line dash array 29 (WebCore::lineDashSequenceIsValid): 30 Returns true if the line dash array contains only non-negative finite 31 numbers. 32 (WebCore::CanvasRenderingContext2D::setLineDash): 33 New 2D canvas API method, set the line dash array. 34 (WebCore::CanvasRenderingContext2D::setWebkitLineDash): 35 Legacy implementation, does not double the new line dash array if 36 it contains an odd number of elements. Just accepts it as is. 37 (WebCore::CanvasRenderingContext2D::lineDashOffset): 38 Attribute getter 39 (WebCore::CanvasRenderingContext2D::setLineDashOffset): 40 Attribute setter 41 (WebCore::CanvasRenderingContext2D::webkitLineDashOffset): 42 Alias for lineDashOffset 43 (WebCore::CanvasRenderingContext2D::setWebkitLineDashOffset): 44 Alias for setLineDashOffset 45 (WebCore::CanvasRenderingContext2D::applyLineDash): 46 Sends the line dash state to the GraphicsContext 47 * html/canvas/CanvasRenderingContext2D.h: 48 (CanvasRenderingContext2D): 49 (State): 50 * html/canvas/CanvasRenderingContext2D.idl: 51 * platform/graphics/DashArray.h: 52 1 53 2012-09-10 Sheriff Bot <webkit.review.bot@gmail.com> 2 54 -
trunk/Source/WebCore/bindings/js/JSCanvasRenderingContext2DCustom.cpp
r127191 r128116 95 95 { 96 96 CanvasRenderingContext2D* context = static_cast<CanvasRenderingContext2D*>(impl()); 97 const DashArray* dash = context->webkitLineDash();97 const Vector<float>& dash = context->getLineDash(); 98 98 99 99 MarkedArgumentBuffer list; 100 DashArray::const_iterator end = dash->end();101 for ( DashArray::const_iterator it = dash->begin(); it != end; ++it)100 Vector<float>::const_iterator end = dash.end(); 101 for (Vector<float>::const_iterator it = dash.begin(); it != end; ++it) 102 102 list.append(JSValue(*it)); 103 103 return constructArray(exec, globalObject(), list); … … 109 109 return; 110 110 111 DashArraydash;111 Vector<float> dash; 112 112 JSArray* valueArray = asArray(value); 113 113 for (unsigned i = 0; i < valueArray->length(); ++i) { -
trunk/Source/WebCore/bindings/js/JSDOMBinding.h
r127191 r128116 376 376 }; 377 377 378 template<> 379 struct NativeValueTraits<float> { 380 static inline bool arrayNativeValue(JSC::ExecState* exec, JSC::JSValue jsValue, float& indexedValue) 381 { 382 indexedValue = jsValue.toFloat(exec); 383 return !exec->hadException(); 384 } 385 }; 386 378 387 template <class T> 379 388 Vector<T> toNativeArray(JSC::ExecState* exec, JSC::JSValue value) -
trunk/Source/WebCore/html/canvas/CanvasRenderingContext2D.cpp
r128076 r128116 509 509 } 510 510 511 const DashArray* CanvasRenderingContext2D::webkitLineDash() const 512 { 513 return &state().m_lineDash; 514 } 515 516 void CanvasRenderingContext2D::setWebkitLineDash(const DashArray& dash) 517 { 518 if (state().m_lineDash == dash) 519 return; 511 const Vector<float>& CanvasRenderingContext2D::getLineDash() const 512 { 513 return state().m_lineDash; 514 } 515 516 static bool lineDashSequenceIsValid(const Vector<float>& dash) 517 { 518 for (size_t i = 0; i < dash.size(); i++) { 519 if (!isfinite(dash[i]) || dash[i] < 0) 520 return false; 521 } 522 return true; 523 } 524 525 void CanvasRenderingContext2D::setLineDash(const Vector<float>& dash) 526 { 527 if (!lineDashSequenceIsValid(dash)) 528 return; 529 520 530 realizeSaves(); 521 531 modifiableState().m_lineDash = dash; 522 GraphicsContext* c = drawingContext(); 523 if (!c) 524 return; 525 c->setLineDash(state().m_lineDash, state().m_lineDashOffset); 532 // Spec requires the concatenation of two copies the dash list when the 533 // number of elements is odd 534 if (dash.size() % 2) 535 modifiableState().m_lineDash.append(dash); 536 537 applyLineDash(); 538 } 539 540 void CanvasRenderingContext2D::setWebkitLineDash(const Vector<float>& dash) 541 { 542 if (!lineDashSequenceIsValid(dash)) 543 return; 544 545 realizeSaves(); 546 modifiableState().m_lineDash = dash; 547 548 applyLineDash(); 549 } 550 551 float CanvasRenderingContext2D::lineDashOffset() const 552 { 553 return state().m_lineDashOffset; 554 } 555 556 void CanvasRenderingContext2D::setLineDashOffset(float offset) 557 { 558 if (!isfinite(offset) || state().m_lineDashOffset == offset) 559 return; 560 561 realizeSaves(); 562 modifiableState().m_lineDashOffset = offset; 563 applyLineDash(); 526 564 } 527 565 528 566 float CanvasRenderingContext2D::webkitLineDashOffset() const 529 567 { 530 return state().m_lineDashOffset;568 return lineDashOffset(); 531 569 } 532 570 533 571 void CanvasRenderingContext2D::setWebkitLineDashOffset(float offset) 534 572 { 535 if (!isfinite(offset)) 536 return; 537 if (state().m_lineDashOffset == offset) 538 return; 539 realizeSaves(); 540 modifiableState().m_lineDashOffset = offset; 541 GraphicsContext* c = drawingContext(); 542 if (!c) 543 return; 544 c->setLineDash(state().m_lineDash, state().m_lineDashOffset); 573 setLineDashOffset(offset); 574 } 575 576 void CanvasRenderingContext2D::applyLineDash() const 577 { 578 GraphicsContext* c = drawingContext(); 579 if (!c) 580 return; 581 DashArray convertedLineDash(state().m_lineDash.size()); 582 for (size_t i = 0; i < state().m_lineDash.size(); ++i) 583 convertedLineDash[i] = static_cast<DashArrayElement>(state().m_lineDash[i]); 584 c->setLineDash(convertedLineDash, state().m_lineDashOffset); 545 585 } 546 586 -
trunk/Source/WebCore/html/canvas/CanvasRenderingContext2D.h
r127757 r128116 85 85 void setMiterLimit(float); 86 86 87 const DashArray* webkitLineDash() const; 88 void setWebkitLineDash(const DashArray&); 89 87 const Vector<float>& getLineDash() const; 88 void setLineDash(const Vector<float>&); 89 void setWebkitLineDash(const Vector<float>&); 90 91 float lineDashOffset() const; 92 void setLineDashOffset(float); 90 93 float webkitLineDashOffset() const; 91 94 void setWebkitLineDashOffset(float); … … 251 254 AffineTransform m_transform; 252 255 bool m_invertibleCTM; 253 DashArraym_lineDash;256 Vector<float> m_lineDash; 254 257 float m_lineDashOffset; 255 258 bool m_imageSmoothingEnabled; … … 277 280 const State& state() const { return m_stateStack.last(); } 278 281 282 void applyLineDash() const; 279 283 void setShadow(const FloatSize& offset, float blur, RGBA32 color); 280 284 void applyShadow(); -
trunk/Source/WebCore/html/canvas/CanvasRenderingContext2D.idl
r121714 r128116 75 75 attribute [TreatNullAs=NullString] DOMString shadowColor; 76 76 77 void setLineDash(in sequence<float> dash); 78 sequence<float> getLineDash(); 79 attribute float lineDashOffset; 80 77 81 // FIXME: These attributes should also be implemented for V8. 78 82 #if !(defined(V8_BINDING) && V8_BINDING) -
trunk/Source/WebCore/platform/graphics/DashArray.h
r84101 r128116 30 30 31 31 #if USE(CG) 32 typedef Vector<CGFloat> DashArray;32 typedef CGFloat DashArrayElement; 33 33 #elif USE(CAIRO) 34 typedef Vector<double> DashArray;34 typedef double DashArrayElement; 35 35 #else 36 typedef Vector<float> DashArray;36 typedef float DashArrayElement; 37 37 #endif 38 38 39 typedef Vector<DashArrayElement> DashArray; 40 39 41 #endif // DashArray_h
Note: See TracChangeset
for help on using the changeset viewer.