Upstream version 5.34.104.0
[platform/framework/web/crosswalk.git] / src / third_party / WebKit / LayoutTests / fast / shapes / resources / rounded-rectangle.js
1 function ellipseXIntercept(yi, rx, ry)
2 {
3     return rx * Math.sqrt(1 - (yi * yi) / (ry * ry));
4 }
5
6 function scanConvertRoundedRectangleOutside(r, height, lineHeight, corner)
7 {
8     var intervals = [];
9     var upperCorner = true;
10     var lowerCorner = true;
11
12     if (corner == "upper")
13         lowerCorner = false;
14     else if (corner == "lower")
15         upperCorner = false;
16
17     for (var y = 0; y < height; y += lineHeight) {
18         if (y + lineHeight <= r.y || y >= r.y + r.height)
19             continue;
20
21         if (upperCorner && (y + lineHeight < r.y + r.ry)) {
22             // within the upper rounded corner part of the rectangle
23             var dx = ellipseXIntercept(y + lineHeight - r.y - r.ry, r.rx, r.ry);
24             intervals.push( { y: y, left: r.x + r.rx - dx, right: r.x + r.width - r.rx + dx} );
25         }
26         else if (lowerCorner && (y > r.y + r.height - r.ry)) {
27             // within the lower rounded corner part of the rectangle
28             var dx = ellipseXIntercept(y - (r.y + r.height - r.ry), r.rx, r.ry);
29             intervals.push( { y: y, left: r.x + r.rx - dx, right: r.x + r.width - r.rx + dx} );
30         }
31         else // within the rectangle's vertical edges
32             intervals.push( {y: y, left: r.x, right: r.x + r.width} );
33     }
34
35     return intervals;
36 }
37
38 function genLeftRightRoundedRectFloatShapeOutsideRefTest(args)
39 {
40     genLeftRoundedRectFloatShapeOutsideRefTest(args);
41     genRightRoundedRectFloatShapeOutsideRefTest(args);
42 }
43
44 function genLeftRoundedRectFloatShapeOutsideRefTest(args)
45 {
46     var leftRoundedRect = args.roundedRect;
47     var leftRoundedRectIntervals = scanConvertRoundedRectangleOutside(leftRoundedRect, args.containerHeight, args.lineHeight, args.corner);
48     var leftFloatDivs = leftRoundedRectIntervals.map(function(interval) {
49         var width = SubPixelLayout.snapToLayoutUnit(interval.right);
50         var cls = "left-" + args.floatElementClassSuffix;
51         return '<div class="' + cls + '" style="width:' + width + 'px"></div>';
52     });
53     document.getElementById("left-" + args.insertElementIdSuffix).insertAdjacentHTML('afterend', leftFloatDivs.join("\n"));
54 }
55
56 function genRightRoundedRectFloatShapeOutsideRefTest(args)
57 {
58     var rightRoundedRect = Object.create(args.roundedRect);
59     rightRoundedRect.x = args.containerWidth - args.roundedRect.width;
60     var rightRoundedRectIntervals = scanConvertRoundedRectangleOutside(rightRoundedRect, args.containerHeight, args.lineHeight, args.corner);
61     var rightFloatDivs = rightRoundedRectIntervals.map(function(interval) {
62         var width = args.containerWidth - SubPixelLayout.snapToLayoutUnit(interval.left);
63         var cls = "right-" + args.floatElementClassSuffix;
64         return '<div class="' + cls + '" style="width:' + width + 'px"></div>';
65     });
66     document.getElementById("right-" + args.insertElementIdSuffix).insertAdjacentHTML('afterend', rightFloatDivs.join("\n"));
67 }