Changeset 186858 in webkit
- Timestamp:
- Jul 15, 2015 2:19:29 PM (9 years ago)
- Location:
- trunk
- Files:
-
- 7 added
- 12 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/LayoutTests/ChangeLog
r186840 r186858 1 2015-07-15 Tim Horton <timothy_horton@apple.com> 2 3 Factor rect shrink-wrapping code out of RenderThemeMac for future reuse 4 https://bugs.webkit.org/show_bug.cgi?id=146973 5 <rdar://problem/21643094> 6 7 Reviewed by Anders Carlsson. 8 9 * fast/shrink-wrap/rect-shrink-wrap-expected.png: Added. 10 * fast/shrink-wrap/rect-shrink-wrap-expected.txt: Added. 11 * fast/shrink-wrap/rect-shrink-wrap.html: Added. 12 Add a test of both working and broken (indicated by comments in the test) 13 shrink-wrapping cases. 14 1 15 2015-07-15 Wenson Hsieh <wenson_hsieh@apple.com> 2 16 -
trunk/Source/WebCore/CMakeLists.txt
r186803 r186858 1743 1743 html/canvas/CanvasRenderingContext2D.cpp 1744 1744 html/canvas/CanvasStyle.cpp 1745 html/canvas/DOMPath.cpp 1745 1746 html/canvas/EXTBlendMinMax.cpp 1746 1747 html/canvas/EXTFragDepth.cpp … … 2172 2173 platform/graphics/Path.cpp 2173 2174 platform/graphics/PathTraversalState.cpp 2175 platform/graphics/PathUtilities.cpp 2174 2176 platform/graphics/Pattern.cpp 2175 2177 platform/graphics/PlatformTimeRanges.cpp -
trunk/Source/WebCore/ChangeLog
r186857 r186858 1 2015-07-15 Tim Horton <timothy_horton@apple.com> 2 3 Factor rect shrink-wrapping code out of RenderThemeMac for future reuse 4 https://bugs.webkit.org/show_bug.cgi?id=146973 5 <rdar://problem/21643094> 6 7 Reviewed by Anders Carlsson. 8 9 Test: fast/shrink-wrap/rect-shrink-wrap.html 10 11 * WebCore.xcodeproj/project.pbxproj: 12 Add DOMPath.cpp and PathUtilities.{h, cpp}. 13 14 * bindings/js/JSDOMBinding.h: 15 (WebCore::NativeValueTraits<double>::nativeValue): 16 Make it possible to use sequence<double> in IDL files. 17 18 * bindings/scripts/CodeGeneratorJS.pm: 19 Export JSDOMPath for use in Internals. 20 21 * html/canvas/DOMPath.cpp: Added. 22 (WebCore::DOMPath::~DOMPath): 23 * html/canvas/DOMPath.h: 24 Out-of-line the DOMPath destructor so as not to anger the bindings 25 integrity checker (otherwise, the address of the DOMPath destructor 26 is different in WebCoreTestSupport and WebCore, causing us to fail 27 the vtable equality test). 28 29 * platform/graphics/Path.h: 30 Forward declare FloatRect instead of including it unnecessarily. 31 Export ensurePlatformPath(). 32 33 * platform/graphics/PathUtilities.cpp: Added. 34 (WebCore::addShrinkWrapRightCorner): 35 (WebCore::addShrinkWrapLeftCorner): 36 (WebCore::addShrinkWrappedPathForRects): 37 These parts are extracted from RenderThemeMac, with two changes: 38 + support for arbitrarily-aligned rects 39 (the other version assumed they were horizontally center-aligned) 40 + support for overlapping rects 41 (the other version assumed they touched but did not overlap) 42 43 There are still things missing: 44 + support for a fallback when the shape is too hard to shrink-wrap 45 46 And things broken: 47 + if the distance between two edges is smaller than the corner radius, 48 we'll end up with a sharp edge in the path 49 50 Both of these cases are covered in the layout test and can be improved. 51 52 (WebCore::rectsIntersectOrTouch): 53 Rect intersection with <= instead of <. 54 55 (WebCore::contiguousRectGroupsFromRects): 56 Given a set of rects, find all of the contiguous regions. We'll 57 shrink-wrap each region independently. 58 59 (WebCore::PathUtilities::pathWithShrinkWrappedRects): 60 * platform/graphics/PathUtilities.h: Added. 61 Add PathUtilities, where the shrink-wrapping code lives. 62 63 * rendering/RenderThemeMac.mm: 64 (WebCore::paintAttachmentTitleBackground): 65 (WebCore::addAttachmentTitleBackgroundRightCorner): Deleted. 66 (WebCore::addAttachmentTitleBackgroundLeftCorner): Deleted. 67 Remove shrink-wrapping implementation and make use of the one in PathUtilities. 68 69 * testing/Internals.cpp: 70 (WebCore::Internals::pathWithShrinkWrappedRects): 71 * testing/Internals.h: 72 * testing/Internals.idl: 73 Expose pathWithShrinkWrappedRects to tests via Internals. 74 It takes a sequence<double> where every four values are the x, y, w, h 75 of a rect, and returns a DOMPath which can be used with Canvas. 76 1 77 2015-07-15 Enrica Casucci <enrica@apple.com> 2 78 -
trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj
r186856 r186858 1125 1125 2D4F96F71A1ECC240098BF88 /* TextIndicatorWindow.h in Headers */ = {isa = PBXBuildFile; fileRef = 2D4F96F31A1ECC240098BF88 /* TextIndicatorWindow.h */; settings = {ATTRIBUTES = (Private, ); }; }; 1126 1126 2D4F96F81A1ECC240098BF88 /* TextIndicatorWindow.mm in Sources */ = {isa = PBXBuildFile; fileRef = 2D4F96F41A1ECC240098BF88 /* TextIndicatorWindow.mm */; }; 1127 2D5002F81B56D7810020AAF7 /* DOMPath.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 2D5002F71B56D7810020AAF7 /* DOMPath.cpp */; }; 1128 2D5002FB1B56D7990020AAF7 /* PathUtilities.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 2D5002F91B56D7990020AAF7 /* PathUtilities.cpp */; }; 1129 2D5002FC1B56D7990020AAF7 /* PathUtilities.h in Headers */ = {isa = PBXBuildFile; fileRef = 2D5002FA1B56D7990020AAF7 /* PathUtilities.h */; }; 1127 1130 2D58D8551A15F65F00A5F726 /* DataDetection.h in Headers */ = {isa = PBXBuildFile; fileRef = 2D58D8531A15F65F00A5F726 /* DataDetection.h */; settings = {ATTRIBUTES = (Private, ); }; }; 1128 1131 2D58D8561A15F65F00A5F726 /* DataDetection.mm in Sources */ = {isa = PBXBuildFile; fileRef = 2D58D8541A15F65F00A5F726 /* DataDetection.mm */; }; … … 8302 8305 2D4F96F31A1ECC240098BF88 /* TextIndicatorWindow.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = TextIndicatorWindow.h; sourceTree = "<group>"; }; 8303 8306 2D4F96F41A1ECC240098BF88 /* TextIndicatorWindow.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = TextIndicatorWindow.mm; sourceTree = "<group>"; }; 8307 2D5002F71B56D7810020AAF7 /* DOMPath.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = DOMPath.cpp; sourceTree = "<group>"; }; 8308 2D5002F91B56D7990020AAF7 /* PathUtilities.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = PathUtilities.cpp; sourceTree = "<group>"; }; 8309 2D5002FA1B56D7990020AAF7 /* PathUtilities.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = PathUtilities.h; sourceTree = "<group>"; }; 8304 8310 2D58D8531A15F65F00A5F726 /* DataDetection.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = DataDetection.h; sourceTree = "<group>"; }; 8305 8311 2D58D8541A15F65F00A5F726 /* DataDetection.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = DataDetection.mm; sourceTree = "<group>"; }; … … 16179 16185 49484FBF102CF23C00187DD3 /* CanvasStyle.cpp */, 16180 16186 49484FC0102CF23C00187DD3 /* CanvasStyle.h */, 16187 2D5002F71B56D7810020AAF7 /* DOMPath.cpp */, 16181 16188 FB91392016AE4B0B001FE682 /* DOMPath.h */, 16182 16189 FB91392116AE4B0B001FE682 /* DOMPath.idl */, … … 21030 21037 A88DD4880B4629B000C02990 /* PathTraversalState.cpp */, 21031 21038 A88DD4860B4629A300C02990 /* PathTraversalState.h */, 21039 2D5002F91B56D7990020AAF7 /* PathUtilities.cpp */, 21040 2D5002FA1B56D7990020AAF7 /* PathUtilities.h */, 21032 21041 A8FA6E5C0E4CFDED00D5CF49 /* Pattern.cpp */, 21033 21042 A8FA6E5B0E4CFDED00D5CF49 /* Pattern.h */, … … 24146 24155 06027CAD0B1CBFC000884B2D /* ContextMenuItem.h in Headers */, 24147 24156 7ADE722610CBBB9B006B3B3A /* ContextMenuProvider.h in Headers */, 24157 2D5002FC1B56D7990020AAF7 /* PathUtilities.h in Headers */, 24148 24158 759CB837192DA9190012BC64 /* ControlStates.h in Headers */, 24149 24159 FD31602912B0267600C1A359 /* ConvolverNode.h in Headers */, … … 29740 29750 AA12DF491743DF83004DAFDF /* PlatformSpeechSynthesizerIOS.mm in Sources */, 29741 29751 297BE3D816C03CCE003316BD /* PlatformSpeechSynthesizerMac.mm in Sources */, 29752 2D5002FB1B56D7990020AAF7 /* PathUtilities.cpp in Sources */, 29742 29753 1AD8F81C11CAB9E900E93E54 /* PlatformStrategies.cpp in Sources */, 29743 29754 074E82BA18A69F0E007EF54C /* PlatformTimeRanges.cpp in Sources */, … … 30513 30524 7A93868518DCC14500B8263D /* VTTScanner.cpp in Sources */, 30514 30525 A14832B1187F61E100DA63A6 /* WAKAppKitStubs.m in Sources */, 30526 2D5002F81B56D7810020AAF7 /* DOMPath.cpp in Sources */, 30515 30527 A14832B3187F629100DA63A6 /* WAKClipView.m in Sources */, 30516 30528 A14832B5187F62FC00DA63A6 /* WAKResponder.m in Sources */, -
trunk/Source/WebCore/bindings/js/JSDOMBinding.h
r186414 r186858 508 508 }; 509 509 510 template<> struct NativeValueTraits<double> { 511 static inline bool nativeValue(JSC::ExecState* exec, JSC::JSValue jsValue, double& indexedValue) 512 { 513 indexedValue = jsValue.toNumber(exec); 514 return !exec->hadException(); 515 } 516 }; 517 510 518 template<typename T, typename JST> Vector<RefPtr<T>> toRefPtrNativeArray(JSC::ExecState* exec, JSC::JSValue value, T* (*toT)(JSC::JSValue value)) 511 519 { -
trunk/Source/WebCore/bindings/scripts/CodeGeneratorJS.pm
r186323 r186858 241 241 "JSCSSStyleDeclaration" => 1, 242 242 "JSDocument" => 1, 243 "JSDOMPath" => 1, 243 244 "JSDOMWindow" => 1, 244 245 "JSElement" => 1, -
trunk/Source/WebCore/html/canvas/DOMPath.h
r177733 r186858 36 36 namespace WebCore { 37 37 38 class DOMPath final : public RefCounted<DOMPath>, public CanvasPathMethods {38 class WEBCORE_EXPORT DOMPath final : public RefCounted<DOMPath>, public CanvasPathMethods { 39 39 WTF_MAKE_FAST_ALLOCATED; 40 40 public: 41 WEBCORE_EXPORT virtual ~DOMPath(); 42 41 43 static Ref<DOMPath> create() { return adoptRef(*new DOMPath); } 42 44 static Ref<DOMPath> create(const Path& path) { return adoptRef(*new DOMPath(path)); } -
trunk/Source/WebCore/platform/graphics/Path.h
r182828 r186858 29 29 #define Path_h 30 30 31 #include "FloatRect.h" 31 32 #include "WindRule.h" 32 33 #include <wtf/FastMalloc.h> … … 57 58 class AffineTransform; 58 59 class FloatPoint; 59 class FloatRect;60 60 class FloatRoundedRect; 61 61 class FloatSize; … … 145 145 PlatformPathPtr platformPath() const { return m_path; } 146 146 // ensurePlatformPath() will allocate a PlatformPath if it has not yet been and will never return null. 147 PlatformPathPtr ensurePlatformPath();147 WEBCORE_EXPORT PlatformPathPtr ensurePlatformPath(); 148 148 149 149 WEBCORE_EXPORT void apply(void* info, PathApplierFunction) const; -
trunk/Source/WebCore/rendering/RenderThemeMac.mm
r186399 r186858 53 53 #import "Page.h" 54 54 #import "PaintInfo.h" 55 #import "PathUtilities.h" 55 56 #import "RenderAttachment.h" 56 57 #import "RenderLayer.h" … … 2380 2381 } 2381 2382 2382 static void addAttachmentTitleBackgroundRightCorner(Path& path, const FloatRect* fromRect, const FloatRect* toRect)2383 {2384 FloatSize horizontalRadius(attachmentTitleBackgroundRadius, 0);2385 FloatSize verticalRadius(0, attachmentTitleBackgroundRadius);2386 2387 if (!fromRect) {2388 // For the first (top) rect:2389 2390 path.moveTo(toRect->minXMinYCorner() + horizontalRadius);2391 2392 // Across the top, towards the right.2393 path.addLineTo(toRect->maxXMinYCorner() - horizontalRadius);2394 2395 // Arc the top corner.2396 path.addArcTo(toRect->maxXMinYCorner(), toRect->maxXMinYCorner() + verticalRadius, attachmentTitleBackgroundRadius);2397 2398 // Down the right.2399 path.addLineTo(toRect->maxXMaxYCorner() - verticalRadius);2400 } else if (!toRect) {2401 // For the last rect:2402 2403 // Arc the bottom corner.2404 path.addArcTo(fromRect->maxXMaxYCorner(), fromRect->maxXMaxYCorner() - horizontalRadius, attachmentTitleBackgroundRadius);2405 } else {2406 // For middle rects:2407 2408 float widthDifference = toRect->width() - fromRect->width();2409 2410 // Skip over very similar-width rects, because we can't make2411 // sensible curves between them.2412 if (fabs(widthDifference) < std::numeric_limits<float>::epsilon())2413 return;2414 2415 if (widthDifference < 0) {2416 // Arc the outer corner.2417 path.addArcTo(FloatPoint(fromRect->maxX(), toRect->y()), FloatPoint(fromRect->maxX(), toRect->y()) - horizontalRadius, attachmentTitleBackgroundRadius);2418 2419 // Across the bottom, towards the left.2420 path.addLineTo(toRect->maxXMinYCorner() + horizontalRadius);2421 2422 // Arc the inner corner.2423 path.addArcTo(toRect->maxXMinYCorner(), toRect->maxXMinYCorner() + verticalRadius, attachmentTitleBackgroundRadius);2424 } else {2425 // Arc the inner corner.2426 path.addArcTo(FloatPoint(fromRect->maxX(), toRect->y()), FloatPoint(fromRect->maxX(), toRect->y()) + horizontalRadius, attachmentTitleBackgroundRadius);2427 2428 // Across the bottom, towards the right.2429 path.addLineTo(toRect->maxXMinYCorner() - horizontalRadius);2430 2431 // Arc the outer corner.2432 path.addArcTo(toRect->maxXMinYCorner(), toRect->maxXMinYCorner() + verticalRadius, attachmentTitleBackgroundRadius);2433 }2434 2435 // Down the right.2436 path.addLineTo(toRect->maxXMaxYCorner() - verticalRadius);2437 }2438 }2439 2440 static void addAttachmentTitleBackgroundLeftCorner(Path& path, const FloatRect* fromRect, const FloatRect* toRect)2441 {2442 FloatSize horizontalRadius(attachmentTitleBackgroundRadius, 0);2443 FloatSize verticalRadius(0, attachmentTitleBackgroundRadius);2444 2445 if (!fromRect) {2446 // For the first (bottom) rect:2447 2448 // Across the bottom, towards the left.2449 path.addLineTo(toRect->minXMaxYCorner() + horizontalRadius);2450 2451 // Arc the bottom corner.2452 path.addArcTo(toRect->minXMaxYCorner(), toRect->minXMaxYCorner() - verticalRadius, attachmentTitleBackgroundRadius);2453 2454 // Up the left.2455 path.addLineTo(toRect->minXMinYCorner() + verticalRadius);2456 } else if (!toRect) {2457 // For the last (top) rect:2458 2459 // Arc the top corner.2460 path.addArcTo(fromRect->minXMinYCorner(), fromRect->minXMinYCorner() + horizontalRadius, attachmentTitleBackgroundRadius);2461 } else {2462 // For middle rects:2463 float widthDifference = toRect->width() - fromRect->width();2464 2465 // Skip over very similar-width rects, because we can't make2466 // sensible curves between them.2467 if (fabs(widthDifference) < std::numeric_limits<float>::epsilon())2468 return;2469 2470 if (widthDifference < 0) {2471 // Arc the inner corner.2472 path.addArcTo(FloatPoint(fromRect->x(), toRect->maxY()), FloatPoint(fromRect->x(), toRect->maxY()) + horizontalRadius, attachmentTitleBackgroundRadius);2473 2474 // Across the bottom, towards the right.2475 path.addLineTo(toRect->minXMaxYCorner() - horizontalRadius);2476 2477 // Arc the outer corner.2478 path.addArcTo(toRect->minXMaxYCorner(), toRect->minXMaxYCorner() - verticalRadius, attachmentTitleBackgroundRadius);2479 } else {2480 // Arc the outer corner.2481 path.addArcTo(FloatPoint(fromRect->x(), toRect->maxY()), FloatPoint(fromRect->x(), toRect->maxY()) - horizontalRadius, attachmentTitleBackgroundRadius);2482 2483 // Across the bottom, towards the left.2484 path.addLineTo(toRect->minXMaxYCorner() + horizontalRadius);2485 2486 // Arc the inner corner.2487 path.addArcTo(toRect->minXMaxYCorner(), toRect->minXMaxYCorner() - verticalRadius, attachmentTitleBackgroundRadius);2488 }2489 2490 // Up the right.2491 path.addLineTo(toRect->minXMinYCorner() + verticalRadius);2492 }2493 }2494 2495 2383 static void paintAttachmentTitleBackground(const RenderAttachment& attachment, GraphicsContext& context, AttachmentLayout& layout) 2496 2384 { … … 2498 2386 return; 2499 2387 2500 Path backgroundPath; 2501 2502 for (size_t i = 0; i <= layout.lines.size(); ++i) 2503 addAttachmentTitleBackgroundRightCorner(backgroundPath, i ? &layout.lines[i - 1].backgroundRect : nullptr, i < layout.lines.size() ? &layout.lines[i].backgroundRect : nullptr); 2504 2505 for (size_t i = 0; i <= layout.lines.size(); ++i) { 2506 size_t reverseIndex = layout.lines.size() - i; 2507 addAttachmentTitleBackgroundLeftCorner(backgroundPath, reverseIndex < layout.lines.size() ? &layout.lines[reverseIndex].backgroundRect : nullptr, reverseIndex ? &layout.lines[reverseIndex - 1].backgroundRect : nullptr); 2508 } 2509 2510 backgroundPath.closeSubpath(); 2388 Vector<FloatRect> backgroundRects; 2389 2390 for (size_t i = 0; i < layout.lines.size(); ++i) 2391 backgroundRects.append(layout.lines[i].backgroundRect); 2511 2392 2512 2393 Color backgroundColor; … … 2517 2398 2518 2399 context.setFillColor(backgroundColor, ColorSpaceDeviceRGB); 2400 2401 Path backgroundPath = PathUtilities::pathWithShrinkWrappedRects(backgroundRects, attachmentTitleBackgroundRadius); 2519 2402 context.fillPath(backgroundPath); 2520 2403 } -
trunk/Source/WebCore/testing/Internals.cpp
r186388 r186858 40 40 #include "ContentDistributor.h" 41 41 #include "Cursor.h" 42 #include "DOMPath.h" 42 43 #include "DOMStringList.h" 43 44 #include "DOMWindow.h" … … 88 89 #include "PageCache.h" 89 90 #include "PageOverlay.h" 91 #include "PathUtilities.h" 90 92 #include "PlatformMediaSessionManager.h" 91 93 #include "PrintContext.h" … … 2920 2922 } 2921 2923 2922 } 2924 PassRefPtr<DOMPath> Internals::pathWithShrinkWrappedRects(Vector<double> rectComponents, ExceptionCode& ec) 2925 { 2926 if (rectComponents.size() % 4) { 2927 ec = INVALID_ACCESS_ERR; 2928 return nullptr; 2929 } 2930 2931 Vector<FloatRect> rects; 2932 while (!rectComponents.isEmpty()) { 2933 double height = rectComponents.takeLast(); 2934 double width = rectComponents.takeLast(); 2935 double y = rectComponents.takeLast(); 2936 double x = rectComponents.takeLast(); 2937 2938 rects.append(FloatRect(x, y, width, height)); 2939 } 2940 2941 rects.reverse(); 2942 2943 // FIXME: radius should be a parameter instead of fixed as 8. 2944 Path path = PathUtilities::pathWithShrinkWrappedRects(rects, 8); 2945 return DOMPath::create(path); 2946 } 2947 2948 } -
trunk/Source/WebCore/testing/Internals.h
r186388 r186858 45 45 class ClientRect; 46 46 class ClientRectList; 47 class DOMPath; 47 48 class DOMStringList; 48 49 class DOMWindow; … … 415 416 #endif 416 417 418 PassRefPtr<DOMPath> pathWithShrinkWrappedRects(Vector<double>, ExceptionCode&); 419 417 420 private: 418 421 explicit Internals(Document*); -
trunk/Source/WebCore/testing/Internals.idl
r186388 r186858 376 376 [RaisesException] DOMString scrollSnapOffsets(Element element); 377 377 #endif 378 379 [RaisesException] DOMPath pathWithShrinkWrappedRects(sequence<double> rectComponents); 378 380 };
Note: See TracChangeset
for help on using the changeset viewer.