+2010-06-25 Yuzo Fujishima <yuzo@google.com>
+
+ Reviewed by Shinichiro Hamaji.
+
+ Improve default value handling for page format properties.
+ https://bugs.webkit.org/show_bug.cgi?id=41150
+
+ * printing/page-format-data-expected.txt:
+ * printing/page-format-data.html:
+ * printing/page-rule-selection-expected.txt:
+ * printing/page-rule-selection.html:
+
2010-06-27 Andreas Kling <andreas.kling@nokia.com>
Reviewed by Darin Adler.
PASS layoutTestController.isPageBoxVisible(0) is true
Test default page size
-PASS layoutTestController.preferredPageSizeInPixels(0) is inchSize(8.5, 11)
+PASS layoutTestController.pageSizeAndMarginsInPixels(0, 100, 200, 1, 2, 3, 4) is '(100, 200)' + pxMargins(1, 2, 3, 4)
Test auto page size
-PASS layoutTestController.preferredPageSizeInPixels(0) is inchSize(8.5, 11)
+PASS layoutTestController.pageSizeAndMarginsInPixels(0, 100, 200, 1, 2, 3, 4) is '(100, 200)' + pxMargins(1, 2, 3, 4)
Test landscape
-PASS layoutTestController.preferredPageSizeInPixels(0) is inchSize(11, 8.5)
+PASS layoutTestController.pageSizeAndMarginsInPixels(0, 100, 200, 1, 2, 3, 4) is '(200, 100)' + pxMargins(1, 2, 3, 4)
+PASS layoutTestController.pageSizeAndMarginsInPixels(0, 200, 100, 1, 2, 3, 4) is '(200, 100)' + pxMargins(1, 2, 3, 4)
Test portrait
-PASS layoutTestController.preferredPageSizeInPixels(0) is inchSize(8.5, 11)
+PASS layoutTestController.pageSizeAndMarginsInPixels(0, 100, 200, 1, 2, 3, 4) is '(100, 200)' + pxMargins(1, 2, 3, 4)
+PASS layoutTestController.pageSizeAndMarginsInPixels(0, 200, 100, 1, 2, 3, 4) is '(100, 200)' + pxMargins(1, 2, 3, 4)
Test a5
-PASS layoutTestController.preferredPageSizeInPixels(0) is mmSize(148, 210)
+PASS layoutTestController.pageSizeAndMarginsInPixels(0, 100, 200, 1, 2, 3, 4) is mmSize(148, 210) + pxMargins(1, 2, 3, 4)
Test a5 landscape
-PASS layoutTestController.preferredPageSizeInPixels(0) is mmSize(210, 148)
+PASS layoutTestController.pageSizeAndMarginsInPixels(0, 100, 200, 1, 2, 3, 4) is mmSize(210, 148) + pxMargins(1, 2, 3, 4)
Test portrait a4
-PASS layoutTestController.preferredPageSizeInPixels(0) is mmSize(210, 297)
+PASS layoutTestController.pageSizeAndMarginsInPixels(0, 100, 200, 1, 2, 3, 4) is mmSize(210, 297) + pxMargins(1, 2, 3, 4)
Test a3
-PASS layoutTestController.preferredPageSizeInPixels(0) is mmSize(297, 420)
+PASS layoutTestController.pageSizeAndMarginsInPixels(0, 100, 200, 1, 2, 3, 4) is mmSize(297, 420) + pxMargins(1, 2, 3, 4)
Test b5
-PASS layoutTestController.preferredPageSizeInPixels(0) is mmSize(176, 250)
+PASS layoutTestController.pageSizeAndMarginsInPixels(0, 100, 200, 1, 2, 3, 4) is mmSize(176, 250) + pxMargins(1, 2, 3, 4)
Test b4
-PASS layoutTestController.preferredPageSizeInPixels(0) is mmSize(250, 353)
+PASS layoutTestController.pageSizeAndMarginsInPixels(0, 100, 200, 1, 2, 3, 4) is mmSize(250, 353) + pxMargins(1, 2, 3, 4)
Test letter
-PASS layoutTestController.preferredPageSizeInPixels(0) is inchSize(8.5, 11)
+PASS layoutTestController.pageSizeAndMarginsInPixels(0, 100, 200, 1, 2, 3, 4) is inchSize(8.5, 11) + pxMargins(1, 2, 3, 4)
Test legal
-PASS layoutTestController.preferredPageSizeInPixels(0) is inchSize(8.5, 14)
+PASS layoutTestController.pageSizeAndMarginsInPixels(0, 100, 200, 1, 2, 3, 4) is inchSize(8.5, 14) + pxMargins(1, 2, 3, 4)
Test ledger
-PASS layoutTestController.preferredPageSizeInPixels(0) is inchSize(11, 17)
+PASS layoutTestController.pageSizeAndMarginsInPixels(0, 100, 200, 1, 2, 3, 4) is inchSize(11, 17) + pxMargins(1, 2, 3, 4)
Test 10cm
-PASS layoutTestController.preferredPageSizeInPixels(0) is mmSize(100, 100)
+PASS layoutTestController.pageSizeAndMarginsInPixels(0, 100, 200, 1, 2, 3, 4) is mmSize(100, 100) + pxMargins(1, 2, 3, 4)
Test 20cm x 30cm
-PASS layoutTestController.preferredPageSizeInPixels(0) is mmSize(200, 300)
+PASS layoutTestController.pageSizeAndMarginsInPixels(0, 100, 200, 1, 2, 3, 4) is mmSize(200, 300) + pxMargins(1, 2, 3, 4)
Test 10000px 20000px
-PASS layoutTestController.preferredPageSizeInPixels(0) is '(10000,20000)'
+PASS layoutTestController.pageSizeAndMarginsInPixels(0, 100, 200, 1, 2, 3, 4) is '(10000, 20000)' + pxMargins(1, 2, 3, 4)
Test invalid page size: -10cm
-PASS layoutTestController.preferredPageSizeInPixels(0) is '(10000,20000)'
+PASS layoutTestController.pageSizeAndMarginsInPixels(0, 100, 200, 1, 2, 3, 4) is '(10000, 20000)' + pxMargins(1, 2, 3, 4)
Test invalid page size: a4 a4
-PASS layoutTestController.preferredPageSizeInPixels(0) is '(10000,20000)'
+PASS layoutTestController.pageSizeAndMarginsInPixels(0, 100, 200, 1, 2, 3, 4) is '(10000, 20000)' + pxMargins(1, 2, 3, 4)
Test invalid page size: landscape portrait
-PASS layoutTestController.preferredPageSizeInPixels(0) is '(10000,20000)'
+PASS layoutTestController.pageSizeAndMarginsInPixels(0, 100, 200, 1, 2, 3, 4) is '(10000, 20000)' + pxMargins(1, 2, 3, 4)
Test invalid page size: 10cm letter
-PASS layoutTestController.preferredPageSizeInPixels(0) is '(10000,20000)'
+PASS layoutTestController.pageSizeAndMarginsInPixels(0, 100, 200, 1, 2, 3, 4) is '(10000, 20000)' + pxMargins(1, 2, 3, 4)
Test invalid page size: 10cm 10cm 10cm
-PASS layoutTestController.preferredPageSizeInPixels(0) is '(10000,20000)'
+PASS layoutTestController.pageSizeAndMarginsInPixels(0, 100, 200, 1, 2, 3, 4) is '(10000, 20000)' + pxMargins(1, 2, 3, 4)
Test invalid page size: empty
-PASS layoutTestController.preferredPageSizeInPixels(0) is '(10000,20000)'
+PASS layoutTestController.pageSizeAndMarginsInPixels(0, 100, 200, 1, 2, 3, 4) is '(10000, 20000)' + pxMargins(1, 2, 3, 4)
-Test page area when margin, padding, and border are 0px
-PASS layoutTestController.pageAreaRectInPixels(0) is '(0,0,10000,20000)'
-Test non-zero margin, padding, and border
-PASS layoutTestController.pageAreaRectInPixels(0) is '(2184,273,7270,18635)'
-Test percentage margin and padding
-PASS layoutTestController.pageAreaRectInPixels(0) is '(1500,2500,7000,15000)'
+Test 0px margins
+PASS layoutTestController.pageSizeAndMarginsInPixels(0, 100, 200, 1, 2, 3, 4) is '(10000, 20000)' + pxMargins(0, 0, 0, 0)
+Test non-zero margins
+PASS layoutTestController.pageSizeAndMarginsInPixels(0, 100, 200, 1, 2, 3, 4) is '(10000, 20000)' + pxMargins(10, 20, 40, 80)
+Test percentage margin
+PASS layoutTestController.pageSizeAndMarginsInPixels(0, 100, 200, 1, 2, 3, 4) is '(10000, 20000)' + pxMargins(800, 400, 200, 100)
+Test margin: auto 4% 2% 1%
+PASS layoutTestController.pageSizeAndMarginsInPixels(0, 100, 200, 1, 2, 3, 4) is '(10000, 20000)' + pxMargins(1, 400, 200, 100)
+Test margin: 8% auto 2% 1%
+PASS layoutTestController.pageSizeAndMarginsInPixels(0, 100, 200, 1, 2, 3, 4) is '(10000, 20000)' + pxMargins(800, 2, 200, 100)
+Test margin: 8% 4% auto 1%
+PASS layoutTestController.pageSizeAndMarginsInPixels(0, 100, 200, 1, 2, 3, 4) is '(10000, 20000)' + pxMargins(800, 400, 3, 100)
+Test margin: 8% 4% 2% auto
+PASS layoutTestController.pageSizeAndMarginsInPixels(0, 100, 200, 1, 2, 3, 4) is '(10000, 20000)' + pxMargins(800, 400, 200, 4)
Test visibility: hidden
-PASS layoutTestController.pageAreaRectInPixels(0) is '(1500,2500,7000,15000)'
+PASS layoutTestController.pageSizeAndMarginsInPixels(0, 100, 200, 1, 2, 3, 4) is '(10000, 20000)' + pxMargins(800, 400, 200, 4)
PASS successfullyParsed is true
function inchSize(width, height)
{
- return "(" + Math.floor(width * 96) + "," + Math.floor(height * 96) + ")";
+ return "(" + Math.floor(width * 96) + ", " + Math.floor(height * 96) + ")";
}
function mmSize(width, height)
{
- return "(" + Math.floor(width * 96 / 25.4) + "," + Math.floor(height * 96 / 25.4) + ")";
+ return "(" + Math.floor(width * 96 / 25.4) + ", " + Math.floor(height * 96 / 25.4) + ")";
+ }
+
+ function pxMargins(top, right, bottom, left)
+ {
+ return " " + top + " " + right + " " + bottom + " " + left;
}
if (window.layoutTestController) {
// Page size tests
debug("Test default page size");
- shouldBe("layoutTestController.preferredPageSizeInPixels(0)", "inchSize(8.5, 11)"); // Letter
+ shouldBe("layoutTestController.pageSizeAndMarginsInPixels(0, 100, 200, 1, 2, 3, 4)", "'(100, 200)' + pxMargins(1, 2, 3, 4)");
debug("Test auto page size");
appendStyle("@page {size:auto;}");
- shouldBe("layoutTestController.preferredPageSizeInPixels(0)", "inchSize(8.5, 11)");
+ shouldBe("layoutTestController.pageSizeAndMarginsInPixels(0, 100, 200, 1, 2, 3, 4)", "'(100, 200)' + pxMargins(1, 2, 3, 4)");
debug("Test landscape");
appendStyle("@page {size:landscape;}");
- shouldBe("layoutTestController.preferredPageSizeInPixels(0)", "inchSize(11, 8.5)");
+ shouldBe("layoutTestController.pageSizeAndMarginsInPixels(0, 100, 200, 1, 2, 3, 4)", "'(200, 100)' + pxMargins(1, 2, 3, 4)");
+ shouldBe("layoutTestController.pageSizeAndMarginsInPixels(0, 200, 100, 1, 2, 3, 4)", "'(200, 100)' + pxMargins(1, 2, 3, 4)");
debug("Test portrait");
appendStyle("@page {size:portrait;}");
- shouldBe("layoutTestController.preferredPageSizeInPixels(0)", "inchSize(8.5, 11)");
+ shouldBe("layoutTestController.pageSizeAndMarginsInPixels(0, 100, 200, 1, 2, 3, 4)", "'(100, 200)' + pxMargins(1, 2, 3, 4)");
+ shouldBe("layoutTestController.pageSizeAndMarginsInPixels(0, 200, 100, 1, 2, 3, 4)", "'(100, 200)' + pxMargins(1, 2, 3, 4)");
debug("Test a5");
appendStyle("@page {size:a5;}");
- shouldBe("layoutTestController.preferredPageSizeInPixels(0)", "mmSize(148, 210)");
+ shouldBe("layoutTestController.pageSizeAndMarginsInPixels(0, 100, 200, 1, 2, 3, 4)", "mmSize(148, 210) + pxMargins(1, 2, 3, 4)");
debug("Test a5 landscape");
appendStyle("@page {size:a5 landscape;}");
- shouldBe("layoutTestController.preferredPageSizeInPixels(0)", "mmSize(210, 148)");
+ shouldBe("layoutTestController.pageSizeAndMarginsInPixels(0, 100, 200, 1, 2, 3, 4)", "mmSize(210, 148) + pxMargins(1, 2, 3, 4)");
debug("Test portrait a4");
appendStyle("@page {size:portrait a4;}");
- shouldBe("layoutTestController.preferredPageSizeInPixels(0)", "mmSize(210, 297)");
+ shouldBe("layoutTestController.pageSizeAndMarginsInPixels(0, 100, 200, 1, 2, 3, 4)", "mmSize(210, 297) + pxMargins(1, 2, 3, 4)");
debug("Test a3");
appendStyle("@page {size:a3;}");
- shouldBe("layoutTestController.preferredPageSizeInPixels(0)", "mmSize(297, 420)");
+ shouldBe("layoutTestController.pageSizeAndMarginsInPixels(0, 100, 200, 1, 2, 3, 4)", "mmSize(297, 420) + pxMargins(1, 2, 3, 4)");
debug("Test b5");
appendStyle("@page {size:b5;}");
- shouldBe("layoutTestController.preferredPageSizeInPixels(0)", "mmSize(176, 250)");
+ shouldBe("layoutTestController.pageSizeAndMarginsInPixels(0, 100, 200, 1, 2, 3, 4)", "mmSize(176, 250) + pxMargins(1, 2, 3, 4)");
debug("Test b4");
appendStyle("@page {size:b4;}");
- shouldBe("layoutTestController.preferredPageSizeInPixels(0)", "mmSize(250, 353)");
+ shouldBe("layoutTestController.pageSizeAndMarginsInPixels(0, 100, 200, 1, 2, 3, 4)", "mmSize(250, 353) + pxMargins(1, 2, 3, 4)");
debug("Test letter");
appendStyle("@page {size:letter;}");
- shouldBe("layoutTestController.preferredPageSizeInPixels(0)", "inchSize(8.5, 11)");
+ shouldBe("layoutTestController.pageSizeAndMarginsInPixels(0, 100, 200, 1, 2, 3, 4)", "inchSize(8.5, 11) + pxMargins(1, 2, 3, 4)");
debug("Test legal");
appendStyle("@page {size:legal;}");
- shouldBe("layoutTestController.preferredPageSizeInPixels(0)", "inchSize(8.5, 14)");
+ shouldBe("layoutTestController.pageSizeAndMarginsInPixels(0, 100, 200, 1, 2, 3, 4)", "inchSize(8.5, 14) + pxMargins(1, 2, 3, 4)");
debug("Test ledger");
appendStyle("@page {size:ledger;}");
- shouldBe("layoutTestController.preferredPageSizeInPixels(0)", "inchSize(11, 17)");
+ shouldBe("layoutTestController.pageSizeAndMarginsInPixels(0, 100, 200, 1, 2, 3, 4)", "inchSize(11, 17) + pxMargins(1, 2, 3, 4)");
debug("Test 10cm");
appendStyle("@page {size:10cm;}");
- shouldBe("layoutTestController.preferredPageSizeInPixels(0)", "mmSize(100, 100)");
+ shouldBe("layoutTestController.pageSizeAndMarginsInPixels(0, 100, 200, 1, 2, 3, 4)", "mmSize(100, 100) + pxMargins(1, 2, 3, 4)");
debug("Test 20cm x 30cm");
appendStyle("@page {size:20cm 30cm;}");
- shouldBe("layoutTestController.preferredPageSizeInPixels(0)", "mmSize(200, 300)");
+ shouldBe("layoutTestController.pageSizeAndMarginsInPixels(0, 100, 200, 1, 2, 3, 4)", "mmSize(200, 300) + pxMargins(1, 2, 3, 4)");
debug("Test 10000px 20000px");
appendStyle("@page {size:10000px 20000px;}");
- shouldBe("layoutTestController.preferredPageSizeInPixels(0)", "'(10000,20000)'");
+ shouldBe("layoutTestController.pageSizeAndMarginsInPixels(0, 100, 200, 1, 2, 3, 4)", "'(10000, 20000)' + pxMargins(1, 2, 3, 4)");
debug("Test invalid page size: -10cm");
appendStyle("@page {size:-10cm;}");
- shouldBe("layoutTestController.preferredPageSizeInPixels(0)", "'(10000,20000)'");
+ shouldBe("layoutTestController.pageSizeAndMarginsInPixels(0, 100, 200, 1, 2, 3, 4)", "'(10000, 20000)' + pxMargins(1, 2, 3, 4)");
debug("Test invalid page size: a4 a4");
appendStyle("@page {size:a4 a4;}");
- shouldBe("layoutTestController.preferredPageSizeInPixels(0)", "'(10000,20000)'");
+ shouldBe("layoutTestController.pageSizeAndMarginsInPixels(0, 100, 200, 1, 2, 3, 4)", "'(10000, 20000)' + pxMargins(1, 2, 3, 4)");
debug("Test invalid page size: landscape portrait");
appendStyle("@page {size:landscape portrait;}");
- shouldBe("layoutTestController.preferredPageSizeInPixels(0)", "'(10000,20000)'");
+ shouldBe("layoutTestController.pageSizeAndMarginsInPixels(0, 100, 200, 1, 2, 3, 4)", "'(10000, 20000)' + pxMargins(1, 2, 3, 4)");
debug("Test invalid page size: 10cm letter");
appendStyle("@page {size:10cm letter;}");
- shouldBe("layoutTestController.preferredPageSizeInPixels(0)", "'(10000,20000)'");
+ shouldBe("layoutTestController.pageSizeAndMarginsInPixels(0, 100, 200, 1, 2, 3, 4)", "'(10000, 20000)' + pxMargins(1, 2, 3, 4)");
debug("Test invalid page size: 10cm 10cm 10cm");
appendStyle("@page {size:10cm 10cm 10cm;}");
- shouldBe("layoutTestController.preferredPageSizeInPixels(0)", "'(10000,20000)'");
+ shouldBe("layoutTestController.pageSizeAndMarginsInPixels(0, 100, 200, 1, 2, 3, 4)", "'(10000, 20000)' + pxMargins(1, 2, 3, 4)");
debug("Test invalid page size: empty");
appendStyle("@page {size:;}");
- shouldBe("layoutTestController.preferredPageSizeInPixels(0)", "'(10000,20000)'");
+ shouldBe("layoutTestController.pageSizeAndMarginsInPixels(0, 100, 200, 1, 2, 3, 4)", "'(10000, 20000)' + pxMargins(1, 2, 3, 4)");
debug("");
- // Page area tests
+ // Margin tests
+
+ debug("Test 0px margins");
+ appendStyle("@page {margin:0px;}");
+ shouldBe("layoutTestController.pageSizeAndMarginsInPixels(0, 100, 200, 1, 2, 3, 4)", "'(10000, 20000)' + pxMargins(0, 0, 0, 0)");
+
+ debug("Test non-zero margins");
+ appendStyle("@page {margin:10px 20px 40px 80px;}");
+ shouldBe("layoutTestController.pageSizeAndMarginsInPixels(0, 100, 200, 1, 2, 3, 4)", "'(10000, 20000)' + pxMargins(10, 20, 40, 80)");
+
+ debug("Test percentage margin");
+ appendStyle("@page {margin: 8% 4% 2% 1%;}");
+ shouldBe("layoutTestController.pageSizeAndMarginsInPixels(0, 100, 200, 1, 2, 3, 4)", "'(10000, 20000)' + pxMargins(800, 400, 200, 100)");
+
+ debug("Test margin: auto 4% 2% 1%");
+ appendStyle("@page {margin: auto 4% 2% 1%;}");
+ shouldBe("layoutTestController.pageSizeAndMarginsInPixels(0, 100, 200, 1, 2, 3, 4)", "'(10000, 20000)' + pxMargins(1, 400, 200, 100)");
- debug("Test page area when margin, padding, and border are 0px");
- appendStyle("@page {margin:0px;padding:0px;border:0px;}");
- shouldBe("layoutTestController.pageAreaRectInPixels(0)", "'(0,0,10000,20000)'");
+ debug("Test margin: 8% auto 2% 1%");
+ appendStyle("@page {margin: 8% auto 2% 1%;}");
+ shouldBe("layoutTestController.pageSizeAndMarginsInPixels(0, 100, 200, 1, 2, 3, 4)", "'(10000, 20000)' + pxMargins(800, 2, 200, 100)");
- debug("Test non-zero margin, padding, and border");
- appendStyle("@page {margin:1px 2px 4px 8px; padding:16px 32px 64px 128px; border-width:256px 512px 1024px 2048px;}"); // top, right, bottom, left
- shouldBe("layoutTestController.pageAreaRectInPixels(0)", "'(2184,273,7270,18635)'");
+ debug("Test margin: 8% 4% auto 1%");
+ appendStyle("@page {margin: 8% 4% auto 1%;}");
+ shouldBe("layoutTestController.pageSizeAndMarginsInPixels(0, 100, 200, 1, 2, 3, 4)", "'(10000, 20000)' + pxMargins(800, 400, 3, 100)");
- debug("Test percentage margin and padding");
- appendStyle("@page {margin:20% 10%; padding:5%; border-width:0px;}");
- shouldBe("layoutTestController.pageAreaRectInPixels(0)", "'(1500,2500,7000,15000)'");
+ debug("Test margin: 8% 4% 2% auto");
+ appendStyle("@page {margin: 8% 4% 2% auto;}");
+ shouldBe("layoutTestController.pageSizeAndMarginsInPixels(0, 100, 200, 1, 2, 3, 4)", "'(10000, 20000)' + pxMargins(800, 400, 200, 4)");
debug("Test visibility: hidden");
appendStyle("@page {visibility:hidden}");
- shouldBe("layoutTestController.pageAreaRectInPixels(0)", "'(1500,2500,7000,15000)'");
+ shouldBe("layoutTestController.pageSizeAndMarginsInPixels(0, 100, 200, 1, 2, 3, 4)", "'(10000, 20000)' + pxMargins(800, 400, 200, 4)");
debug("");
On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
-Default margin is 1in = 96px.
-PASS layoutTestController.pageProperty('margin-left', 0) is "96"
-PASS layoutTestController.pageProperty('margin-left', 1) is "96"
-PASS layoutTestController.pageProperty('margin-left', 2) is "96"
-PASS layoutTestController.pageProperty('margin-left', 3) is "96"
-PASS layoutTestController.pageProperty('margin-left', 4) is "96"
+Default margin is auto.
+PASS layoutTestController.pageProperty('margin-left', 0) is "auto"
+PASS layoutTestController.pageProperty('margin-left', 1) is "auto"
+PASS layoutTestController.pageProperty('margin-left', 2) is "auto"
+PASS layoutTestController.pageProperty('margin-left', 3) is "auto"
+PASS layoutTestController.pageProperty('margin-left', 4) is "auto"
Set margin to 200px via user style sheet.
PASS layoutTestController.pageProperty('margin-left', 0) is "200"
PASS layoutTestController.pageProperty('margin-left', 1) is "200"
if (window.layoutTestController) {
layoutTestController.dumpAsText();
- debug("Default margin is 1in = 96px.");
- shouldBeEqualToString("layoutTestController.pageProperty('margin-left', 0)", "96");
- shouldBeEqualToString("layoutTestController.pageProperty('margin-left', 1)", "96");
- shouldBeEqualToString("layoutTestController.pageProperty('margin-left', 2)", "96");
- shouldBeEqualToString("layoutTestController.pageProperty('margin-left', 3)", "96");
- shouldBeEqualToString("layoutTestController.pageProperty('margin-left', 4)", "96");
+ debug("Default margin is auto.");
+ shouldBeEqualToString("layoutTestController.pageProperty('margin-left', 0)", "auto");
+ shouldBeEqualToString("layoutTestController.pageProperty('margin-left', 1)", "auto");
+ shouldBeEqualToString("layoutTestController.pageProperty('margin-left', 2)", "auto");
+ shouldBeEqualToString("layoutTestController.pageProperty('margin-left', 3)", "auto");
+ shouldBeEqualToString("layoutTestController.pageProperty('margin-left', 4)", "auto");
debug("Set margin to 200px via user style sheet.");
layoutTestController.addUserStyleSheet("@page { margin:200px; }");
+2010-06-25 Yuzo Fujishima <yuzo@google.com>
+
+ Reviewed by Shinichiro Hamaji.
+
+ Improve default value handling for page format properties.
+
+ Default page size and orientation have been hard-coded.
+ Instead, pass default page size and margins to
+ WebCore::Document::pageSizeAndMarginsInPixels to handle auto page size
+ and margins specified as percentages.
+ Return margins instead of page rect.
+
+ https://bugs.webkit.org/show_bug.cgi?id=41150
+
+ * WebCore.base.exp:
+ * css/CSSStyleSelector.cpp:
+ (WebCore::CSSStyleSelector::applyPageSizeProperty):
+ (WebCore::CSSStyleSelector::pageSizeFromName):
+ * css/html.css:
+ (@page):
+ * dom/Document.cpp:
+ (WebCore::Document::pageSizeAndMarginsInPixels):
+ * dom/Document.h:
+ * page/PrintContext.cpp:
+ (WebCore::PrintContext::pageProperty):
+ (WebCore::PrintContext::pageSizeAndMarginsInPixels):
+ * page/PrintContext.h:
+ * rendering/style/RenderStyle.h:
+ (WebCore::InheritedFlags::pageSizeType):
+ (WebCore::InheritedFlags::setPageSizeType):
+ (WebCore::InheritedFlags::resetPageSizeType):
+ * rendering/style/StyleRareNonInheritedData.cpp:
+ (WebCore::StyleRareNonInheritedData::StyleRareNonInheritedData):
+ (WebCore::StyleRareNonInheritedData::operator==):
+ * rendering/style/StyleRareNonInheritedData.h:
+ (WebCore::):
+
2010-06-27 Adam Barth <abarth@webkit.org>
Reviewed by Eric Seidel.
__ZN7WebCore12PrintContext12pagePropertyEPNS_5FrameEPKci
__ZN7WebCore12PrintContext13numberOfPagesEPNS_5FrameERKNS_9FloatSizeE
__ZN7WebCore12PrintContext16isPageBoxVisibleEPNS_5FrameEi
-__ZN7WebCore12PrintContext20pageAreaRectInPixelsEPNS_5FrameEi
__ZN7WebCore12PrintContext20pageNumberForElementEPNS_7ElementERKNS_9FloatSizeE
-__ZN7WebCore12PrintContext25preferredPageSizeInPixelsEPNS_5FrameEi
+__ZN7WebCore12PrintContext26pageSizeAndMarginsInPixelsEPNS_5FrameEiiiiiii
__ZN7WebCore12PrintContext28computePageRectsWithPageSizeERKNS_9FloatSizeEb
__ZN7WebCore12PrintContextC1EPNS_5FrameE
__ZN7WebCore12PrintContextD1Ev
__ZN7WebCore8Document16isPageBoxVisibleEi
__ZN7WebCore8Document17getFocusableNodesERN3WTF6VectorINS1_6RefPtrINS_4NodeEEELm0EEE
__ZN7WebCore8Document19accessSVGExtensionsEv
-__ZN7WebCore8Document20pageAreaRectInPixelsEi
__ZN7WebCore8Document22createDocumentFragmentEv
__ZN7WebCore8Document23renderedRectsForMarkersENS_14DocumentMarker10MarkerTypeE
__ZN7WebCore8Document24setShouldCreateRenderersEb
-__ZN7WebCore8Document25preferredPageSizeInPixelsEi
+__ZN7WebCore8Document26pageSizeAndMarginsInPixelsEiRNS_7IntSizeERiS3_S3_S3_
__ZN7WebCore8Document36updateLayoutIgnorePendingStylesheetsEv
__ZN7WebCore8Document4headEv
__ZN7WebCore8FormDataD1Ev
#include "CSSBorderImageValue.h"
#include "CSSCursorImageValue.h"
#include "CSSFontFaceRule.h"
-#include "CSSHelper.h"
#include "CSSImportRule.h"
#include "CSSMediaRule.h"
#include "CSSPageRule.h"
void CSSStyleSelector::applyPageSizeProperty(CSSValue* value)
{
+ m_style->resetPageSizeType();
if (!value->isValueList())
return;
CSSValueList* valueList = static_cast<CSSValueList*>(value);
Length width;
Length height;
+ PageSizeType pageSizeType = PAGE_SIZE_AUTO;
switch (valueList->length()) {
case 2: {
// <length>{2} | <page-size> <orientation>
+ pageSizeType = PAGE_SIZE_RESOLVED;
if (!valueList->item(0)->isPrimitiveValue() || !valueList->item(1)->isPrimitiveValue())
return;
CSSPrimitiveValue* primitiveValue0 = static_cast<CSSPrimitiveValue*>(valueList->item(0));
int type = primitiveValue->primitiveType();
if (CSSPrimitiveValue::isUnitTypeLength(type)) {
// <length>
+ pageSizeType = PAGE_SIZE_RESOLVED;
width = height = Length(primitiveValue->computeLengthIntForLength(style(), m_rootElementStyle), Fixed);
} else {
if (type != CSSPrimitiveValue::CSS_IDENT)
return;
switch (primitiveValue->getIdent()) {
case CSSValueAuto:
- // auto
- if (!pageSizeFromName(0, 0, width, height))
- return;
+ pageSizeType = PAGE_SIZE_AUTO;
break;
case CSSValuePortrait:
+ pageSizeType = PAGE_SIZE_AUTO_PORTRAIT;
+ break;
case CSSValueLandscape:
- // <page-size>
- if (!pageSizeFromName(0, primitiveValue, width, height))
- return;
+ pageSizeType = PAGE_SIZE_AUTO_LANDSCAPE;
break;
default:
- // [ portrait | landscape]
+ // <page-size>
+ pageSizeType = PAGE_SIZE_RESOLVED;
if (!pageSizeFromName(primitiveValue, 0, width, height))
return;
}
default:
return;
}
+ m_style->setPageSizeType(pageSizeType);
m_style->setPageSize(LengthSize(width, height));
return;
}
static const Length legalWidth = inchLength(8.5), legalHeight = inchLength(14);
static const Length ledgerWidth = inchLength(11), ledgerHeight = inchLength(17);
- // FIXME: Define UA default page size. Assume letter for now.
- int ident = CSSValueLetter;
- if (pageSizeName) {
- if (pageSizeName->primitiveType() != CSSPrimitiveValue::CSS_IDENT)
- return false;
- ident = pageSizeName->getIdent();
- }
+ if (!pageSizeName || pageSizeName->primitiveType() != CSSPrimitiveValue::CSS_IDENT)
+ return false;
- // FIXME: Define UA default page orientation. Assume portrait for now.
- bool portrait = true;
- if (pageOrientation) {
- if (pageOrientation->primitiveType() != CSSPrimitiveValue::CSS_IDENT)
- return false;
- switch (pageOrientation->getIdent()) {
- case CSSValueLandscape:
- portrait = false;
- break;
- case CSSValuePortrait:
- portrait = true;
- break;
- default:
- return false;
- }
- }
- switch (ident) {
+ switch (pageSizeName->getIdent()) {
case CSSValueA5:
width = a5Width;
height = a5Height;
default:
return false;
}
- if (!portrait)
- swap(width, height);
+
+ if (pageOrientation) {
+ if (pageOrientation->primitiveType() != CSSPrimitiveValue::CSS_IDENT)
+ return false;
+ switch (pageOrientation->getIdent()) {
+ case CSSValueLandscape:
+ std::swap(width, height);
+ break;
+ case CSSValuePortrait:
+ // Nothing to do.
+ break;
+ default:
+ return false;
+ }
+ }
return true;
}
@page {
/* FIXME: Define the right default values for page properties. */
size: auto;
- margin: 1in;
+ margin: auto;
+ padding: 0px;
+ border-width: 0px;
}
/* noscript is handled internally, as it depends on settings */
return style->visibility() != HIDDEN; // display property doesn't apply to @page.
}
-IntRect Document::pageAreaRectInPixels(int pageIndex)
+void Document::pageSizeAndMarginsInPixels(int pageIndex, IntSize& pageSize, int& marginTop, int& marginRight, int& marginBottom, int& marginLeft)
{
RefPtr<RenderStyle> style = styleForPage(pageIndex);
- IntSize pageSize = preferredPageSizeInPixels(pageIndex);
- // 100% value for margin-{left,right,top,bottom}. This is used also for top and bottom. http://www.w3.org/TR/CSS2/box.html#value-def-margin-width
- int maxValue = pageSize.width();
- int surroundLeft = style->marginLeft().calcValue(maxValue) + style->borderLeft().width() + style->paddingLeft().calcValue(maxValue);
- int surroundRight = style->marginRight().calcValue(maxValue) + style->borderRight().width() + style->paddingRight().calcValue(maxValue);
- int surroundTop = style->marginTop().calcValue(maxValue) + style->borderTop().width() + style->paddingTop().calcValue(maxValue);
- int surroundBottom = style->marginBottom().calcValue(maxValue) + style->borderBottom().width() + style->paddingBottom().calcValue(maxValue);
- int width = pageSize.width() - surroundLeft - surroundRight;
- int height = pageSize.height() - surroundTop - surroundBottom;
- return IntRect(surroundLeft, surroundTop, width, height);
-}
+ int width = pageSize.width();
+ int height = pageSize.height();
+ switch (style->pageSizeType()) {
+ case PAGE_SIZE_AUTO:
+ break;
+ case PAGE_SIZE_AUTO_LANDSCAPE:
+ if (width < height)
+ std::swap(width, height);
+ break;
+ case PAGE_SIZE_AUTO_PORTRAIT:
+ if (width > height)
+ std::swap(width, height);
+ break;
+ case PAGE_SIZE_RESOLVED: {
+ LengthSize size = style->pageSize();
+ ASSERT(size.width().isFixed());
+ ASSERT(size.height().isFixed());
+ width = size.width().calcValue(0);
+ height = size.height().calcValue(0);
+ break;
+ }
+ default:
+ ASSERT_NOT_REACHED();
+ }
+ pageSize = IntSize(width, height);
-IntSize Document::preferredPageSizeInPixels(int pageIndex)
-{
- RefPtr<RenderStyle> style = styleForPage(pageIndex);
- LengthSize size = style->pageSize();
- ASSERT(size.width().isFixed());
- ASSERT(size.height().isFixed());
- return IntSize(size.width().calcValue(0), size.height().calcValue(0));
+ // The percentage is calculated with respect to the width even for margin top and bottom.
+ // http://www.w3.org/TR/CSS2/box.html#margin-properties
+ marginTop = style->marginTop().isAuto() ? marginTop : style->marginTop().calcValue(width);
+ marginRight = style->marginRight().isAuto() ? marginRight : style->marginRight().calcValue(width);
+ marginBottom = style->marginBottom().isAuto() ? marginBottom : style->marginBottom().calcValue(width);
+ marginLeft = style->marginLeft().isAuto() ? marginLeft : style->marginLeft().calcValue(width);
}
void Document::createStyleSelector()
void updateLayoutIgnorePendingStylesheets();
PassRefPtr<RenderStyle> styleForElementIgnoringPendingStylesheets(Element*);
PassRefPtr<RenderStyle> styleForPage(int pageIndex);
+
+ // Returns true if page box (margin boxes and page borders) is visible.
bool isPageBoxVisible(int pageIndex);
- IntRect pageAreaRectInPixels(int pageIndex);
- IntSize preferredPageSizeInPixels(int pageIndex);
+
+ // Returns the preferred page size and margins in pixels, assuming 96
+ // pixels per inch. pageSize, marginTop, marginRight, marginBottom,
+ // marginLeft must be initialized to the default values that are used if
+ // auto is specified.
+ void pageSizeAndMarginsInPixels(int pageIndex, IntSize& pageSize, int& marginTop, int& marginRight, int& marginBottom, int& marginLeft);
+
static void updateStyleForAllDocuments(); // FIXME: Try to reduce the # of calls to this function.
DocLoader* docLoader() { return m_docLoader.get(); }
RefPtr<RenderStyle> style = document->styleForPage(pageNumber);
// Implement formatters for properties we care about.
- if (!strcmp(propertyName, "margin-left"))
+ if (!strcmp(propertyName, "margin-left")) {
+ if (style->marginLeft().isAuto())
+ return String("auto");
return String::format("%d", style->marginLeft().rawValue());
+ }
if (!strcmp(propertyName, "line-height"))
return String::format("%d", style->lineHeight().rawValue());
if (!strcmp(propertyName, "font-size"))
return frame->document()->isPageBoxVisible(pageNumber);
}
-String PrintContext::pageAreaRectInPixels(Frame* frame, int pageNumber)
-{
- IntRect pageArea = frame->document()->pageAreaRectInPixels(pageNumber);
- return String::format("(%d,%d,%d,%d)", pageArea.x(), pageArea.y(), pageArea.width(), pageArea.height());
-}
-
-String PrintContext::preferredPageSizeInPixels(Frame* frame, int pageNumber)
+String PrintContext::pageSizeAndMarginsInPixels(Frame* frame, int pageNumber, int width, int height, int marginTop, int marginRight, int marginBottom, int marginLeft)
{
- IntSize pageSize = frame->document()->preferredPageSizeInPixels(pageNumber);
- return String::format("(%d,%d)", pageSize.width(), pageSize.height());
+ IntSize pageSize(width, height);
+ frame->document()->pageSizeAndMarginsInPixels(pageNumber, pageSize, marginTop, marginRight, marginBottom, marginLeft);
+ return String::format("(%d, %d) %d %d %d %d", pageSize.width(), pageSize.height(), marginTop, marginRight, marginBottom, marginLeft);
}
int PrintContext::numberOfPages(Frame* frame, const FloatSize& pageSizeInPixels)
static int pageNumberForElement(Element*, const FloatSize& pageSizeInPixels);
static String pageProperty(Frame* frame, const char* propertyName, int pageNumber);
static bool isPageBoxVisible(Frame* frame, int pageNumber);
- static String pageAreaRectInPixels(Frame* frame, int pageNumber);
- static String preferredPageSizeInPixels(Frame* frame, int pageNumber);
+ static String pageSizeAndMarginsInPixels(Frame* frame, int pageNumber, int width, int height, int marginTop, int marginRight, int marginBottom, int marginLeft);
static int numberOfPages(Frame*, const FloatSize& pageSizeInPixels);
protected:
Length perspectiveOriginX() const { return rareNonInheritedData->m_perspectiveOriginX; }
Length perspectiveOriginY() const { return rareNonInheritedData->m_perspectiveOriginY; }
LengthSize pageSize() const { return rareNonInheritedData->m_pageSize; }
+ PageSizeType pageSizeType() const { return rareNonInheritedData->m_pageSizeType; }
#if USE(ACCELERATED_COMPOSITING)
// When set, this ensures that styles compare as different. Used during accelerated animations.
void setPerspectiveOriginX(Length l) { SET_VAR(rareNonInheritedData, m_perspectiveOriginX, l); }
void setPerspectiveOriginY(Length l) { SET_VAR(rareNonInheritedData, m_perspectiveOriginY, l); }
void setPageSize(LengthSize s) { SET_VAR(rareNonInheritedData, m_pageSize, s); }
+ void setPageSizeType(PageSizeType t) { SET_VAR(rareNonInheritedData, m_pageSizeType, t); }
+ void resetPageSizeType() { SET_VAR(rareNonInheritedData, m_pageSizeType, PAGE_SIZE_AUTO); }
#if USE(ACCELERATED_COMPOSITING)
void setIsRunningAcceleratedAnimation(bool b = true) { SET_VAR(rareNonInheritedData, m_runningAcceleratedAnimation, b); }
#if ENABLE(XBL)
, bindingURI(0)
#endif
+ , m_pageSize()
+ , m_pageSizeType(PAGE_SIZE_AUTO)
{
}
#if ENABLE(XBL)
, bindingURI(o.bindingURI ? o.bindingURI->copy() : 0)
#endif
+ , m_pageSize(o.m_pageSize)
+ , m_pageSizeType(o.m_pageSizeType)
{
}
&& (m_perspective == o.m_perspective)
&& (m_perspectiveOriginX == o.m_perspectiveOriginX)
&& (m_perspectiveOriginY == o.m_perspectiveOriginY)
+ && (m_pageSize == o.m_pageSize)
+ && (m_pageSizeType == o.m_pageSizeType)
;
}
class BindingURI;
#endif
+// Page size type.
+// StyleRareNonInheritedData::m_pageSize is meaningful only when
+// StyleRareNonInheritedData::m_pageSizeType is PAGE_SIZE_RESOLVED.
+enum PageSizeType {
+ PAGE_SIZE_AUTO, // size: auto
+ PAGE_SIZE_AUTO_LANDSCAPE, // size: landscape
+ PAGE_SIZE_AUTO_PORTRAIT, // size: portrait
+ PAGE_SIZE_RESOLVED // Size is fully resolved.
+};
+
// This struct is for rarely used non-inherited CSS3, CSS2, and WebKit-specific properties.
// By grouping them together, we save space, and only allocate this object when someone
// actually uses one of these properties.
Length m_perspectiveOriginY;
LengthSize m_pageSize;
+ PageSizeType m_pageSizeType;
#if ENABLE(XBL)
OwnPtr<BindingURI> bindingURI; // The XBL binding URI list.
+2010-06-25 Yuzo Fujishima <yuzo@google.com>
+
+ Reviewed by Shinichiro Hamaji.
+
+ Improve default value handling for page format properties.
+ https://bugs.webkit.org/show_bug.cgi?id=41150
+
+ * public/WebFrame.h:
+ * src/WebFrameImpl.cpp:
+ (WebKit::WebFrameImpl::pageSizeAndMarginsInPixels):
+ * src/WebFrameImpl.h:
+
2010-06-26 Sheriff Bot <webkit.review.bot@gmail.com>
Unreviewed, rolling out r61943.
// Returns true if page box (margin boxes and page borders) is visible.
virtual bool isPageBoxVisible(int pageIndex) = 0;
- // Returns the page area rectangle in pixels, assuming 96 pixels per inch.
- virtual WebRect pageAreaRectInPixels(int pageIndex) = 0;
-
- // Returns the preferred page size in pixels, assuming 96 pixels per inch.
- virtual WebSize preferredPageSizeInPixels(int pageIndex) = 0;
-
+ // Returns the preferred page size and margins in pixels, assuming 96
+ // pixels per inch. pageSize, marginTop, marginRight, marginBottom,
+ // marginLeft must be initialized to the default values that are used if
+ // auto is specified.
+ virtual void pageSizeAndMarginsInPixels(int pageIndex,
+ WebSize& pageSize,
+ int& marginTop,
+ int& marginRight,
+ int& marginBottom,
+ int& marginLeft) = 0;
// Find-in-page --------------------------------------------------------
return frame()->document()->isPageBoxVisible(pageIndex);
}
-WebRect WebFrameImpl::pageAreaRectInPixels(int pageIndex)
-{
- return frame()->document()->pageAreaRectInPixels(pageIndex);
-}
-
-WebSize WebFrameImpl::preferredPageSizeInPixels(int pageIndex)
-{
- return frame()->document()->preferredPageSizeInPixels(pageIndex);
+void WebFrameImpl::pageSizeAndMarginsInPixels(int pageIndex,
+ WebSize& pageSize,
+ int& marginTop,
+ int& marginRight,
+ int& marginBottom,
+ int& marginLeft)
+{
+ IntSize size(pageSize.width, pageSize.height);
+ frame()->document()->pageSizeAndMarginsInPixels(pageIndex,
+ size,
+ marginTop,
+ marginRight,
+ marginBottom,
+ marginLeft);
+ pageSize = size;
}
bool WebFrameImpl::find(int identifier,
virtual float getPrintPageShrink(int page);
virtual void printEnd();
virtual bool isPageBoxVisible(int pageIndex);
- virtual WebRect pageAreaRectInPixels(int pageIndex);
- virtual WebSize preferredPageSizeInPixels(int pageIndex);
+ virtual void pageSizeAndMarginsInPixels(int pageIndex,
+ WebSize& pageSize,
+ int& marginTop,
+ int& marginRight,
+ int& marginBottom,
+ int& marginLeft);
virtual bool find(
int identifier, const WebString& searchText, const WebFindOptions&,
bool wrapWithinFrame, WebRect* selectionRect);
+2010-06-25 Yuzo Fujishima <yuzo@google.com>
+
+ Reviewed by Shinichiro Hamaji.
+
+ Improve default value handling for page format properties.
+ https://bugs.webkit.org/show_bug.cgi?id=41150
+
+ * Misc/WebCoreStatistics.h:
+ * Misc/WebCoreStatistics.mm:
+ (-[WebFrame pageSizeAndMarginsInPixels:pageNumber:width:height:marginTop:marginRight:marginBottom:]):
+
2010-06-26 Tony Gentilcore <tonyg@chromium.org>
Reviewed by Dimitri Glazkov.
- (int)numberOfPages:(float)pageWidthInPixels:(float)pageHeightInPixels;
- (NSString *)pageProperty:(const char*)propertyName:(int)pageNumber;
- (bool)isPageBoxVisible:(int)pageNumber;
-- (NSString *)pageAreaRectInPixels:(int)pageNumber;
-- (NSString *)preferredPageSizeInPixels:(int)pageNumber;
+- (NSString *)pageSizeAndMarginsInPixels:(int)pageNumber:(int)width:(int)height:(int)marginTop:(int)marginRight:(int)marginBottom:(int)marginLeft;
@end
return PrintContext::isPageBoxVisible(_private->coreFrame, pageNumber);
}
-- (NSString *)pageAreaRectInPixels:(int)pageNumber
+- (NSString *)pageSizeAndMarginsInPixels:(int)pageNumber:(int)width:(int)height:(int)marginTop:(int)marginRight:(int)marginBottom:(int)marginLeft
{
- return PrintContext::pageAreaRectInPixels(_private->coreFrame, pageNumber);
-}
-
-- (NSString *)preferredPageSizeInPixels:(int)pageNumber;
-{
- return PrintContext::preferredPageSizeInPixels(_private->coreFrame, pageNumber);
+ return PrintContext::pageSizeAndMarginsInPixels(_private->coreFrame, pageNumber, width, height, marginTop, marginRight, marginBottom, marginLeft);
}
@end
+2010-06-25 Yuzo Fujishima <yuzo@google.com>
+
+ Reviewed by Shinichiro Hamaji.
+
+ Improve default value handling for page format properties.
+ https://bugs.webkit.org/show_bug.cgi?id=41150
+
+ * DumpRenderTree/LayoutTestController.cpp:
+ (parsePageNumber):
+ (parsePageNumberSizeMarings):
+ (pageSizeAndMarginsInPixelsCallback):
+ (LayoutTestController::staticFunctions):
+ * DumpRenderTree/LayoutTestController.h:
+ * DumpRenderTree/gtk/LayoutTestControllerGtk.cpp:
+ (LayoutTestController::pageSizeAndMarginsInPixels):
+ * DumpRenderTree/mac/LayoutTestControllerMac.mm:
+ (LayoutTestController::pageSizeAndMarginsInPixels):
+ * DumpRenderTree/win/LayoutTestControllerWin.cpp:
+ (LayoutTestController::pageSizeAndMarginsInPixels):
+
2010-06-21 Robert Hogan <robert@webkit.org>
Reviewed by Kenneth Rohde Christiansen.
static bool parsePageNumber(JSContextRef context, int argumentCount, const JSValueRef* arguments, JSValueRef* exception, int& pageNumber)
{
pageNumber = 0;
- if (argumentCount != 1)
+ switch (argumentCount) {
+ case 1:
+ pageNumber = static_cast<int>(JSValueToNumber(context, arguments[0], exception));
+ if (*exception)
+ return false;
+ // Fall through.
+ case 0:
+ return true;
+ default:
+ return false;
+ }
+}
+
+static bool parsePageNumberSizeMarings(JSContextRef context, int argumentCount, const JSValueRef* arguments, JSValueRef* exception, int& pageNumber, int& width, int& height, int& marginTop, int& marginRight, int& marginBottom, int& marginLeft)
+{
+ pageNumber = 0;
+ width = height = 0;
+ marginTop = marginRight = marginBottom = marginLeft = 0;
+
+ switch (argumentCount) {
+ case 7:
+ marginLeft = static_cast<int>(JSValueToNumber(context, arguments[6], exception));
+ if (*exception)
+ return false;
+ // Fall through.
+ case 6:
+ marginBottom = static_cast<int>(JSValueToNumber(context, arguments[5], exception));
+ if (*exception)
+ return false;
+ // Fall through.
+ case 5:
+ marginRight = static_cast<int>(JSValueToNumber(context, arguments[4], exception));
+ if (*exception)
+ return false;
+ // Fall through.
+ case 4:
+ marginTop = static_cast<int>(JSValueToNumber(context, arguments[3], exception));
+ if (*exception)
+ return false;
+ // Fall through.
+ case 3:
+ height = static_cast<int>(JSValueToNumber(context, arguments[2], exception));
+ if (*exception)
+ return false;
+ // Fall through.
+ case 2:
+ width = static_cast<int>(JSValueToNumber(context, arguments[1], exception));
+ if (*exception)
+ return false;
+ // Fall through.
+ case 1:
+ pageNumber = static_cast<int>(JSValueToNumber(context, arguments[0], exception));
+ if (*exception)
+ return false;
+ // Fall through.
+ return true;
+ default:
return false;
- pageNumber = static_cast<int>(JSValueToNumber(context, arguments[0], exception));
- return !*exception;
+ }
}
static JSValueRef pageNumberForElementByIdCallback(JSContextRef context, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception)
return JSValueMakeBoolean(context, controller->isPageBoxVisible(pageNumber));
}
-static JSValueRef pageAreaRectInPixelsCallback(JSContextRef context, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception)
-{
- int pageNumber = 0;
- if (!parsePageNumber(context, argumentCount, arguments, exception, pageNumber))
- return JSValueMakeUndefined(context);
-
- LayoutTestController* controller = static_cast<LayoutTestController*>(JSObjectGetPrivate(thisObject));
- return JSValueMakeString(context, controller->pageAreaRectInPixels(pageNumber).get());
-}
-
-static JSValueRef preferredPageSizeInPixelsCallback(JSContextRef context, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception)
+static JSValueRef pageSizeAndMarginsInPixelsCallback(JSContextRef context, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception)
{
int pageNumber = 0;
- if (!parsePageNumber(context, argumentCount, arguments, exception, pageNumber))
+ int width = 0, height = 0;
+ int marginTop = 0, marginRight = 0, marginBottom = 0, marginLeft = 0;
+ if (!parsePageNumberSizeMarings(context, argumentCount, arguments, exception, pageNumber, width, height, marginTop, marginRight, marginBottom, marginLeft))
return JSValueMakeUndefined(context);
LayoutTestController* controller = static_cast<LayoutTestController*>(JSObjectGetPrivate(thisObject));
- return JSValueMakeString(context, controller->preferredPageSizeInPixels(pageNumber).get());
+ return JSValueMakeString(context, controller->pageSizeAndMarginsInPixels(pageNumber, width, height, marginTop, marginRight, marginBottom, marginLeft).get());
}
static JSValueRef queueBackNavigationCallback(JSContextRef context, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception)
{ "numberOfActiveAnimations", numberOfActiveAnimationsCallback, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontDelete },
{ "overridePreference", overridePreferenceCallback, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontDelete },
{ "pageNumberForElementById", pageNumberForElementByIdCallback, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontDelete },
- { "pageAreaRectInPixels", pageAreaRectInPixelsCallback, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontDelete },
+ { "pageSizeAndMarginsInPixels", pageSizeAndMarginsInPixelsCallback, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontDelete },
{ "pageProperty", pagePropertyCallback, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontDelete },
{ "pathToLocalResource", pathToLocalResourceCallback, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontDelete },
{ "pauseAnimationAtTimeOnElementWithId", pauseAnimationAtTimeOnElementWithIdCallback, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontDelete },
{ "pauseTransitionAtTimeOnElementWithId", pauseTransitionAtTimeOnElementWithIdCallback, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontDelete },
- { "preferredPageSizeInPixels", preferredPageSizeInPixelsCallback, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontDelete },
{ "sampleSVGAnimationForElementAtTime", sampleSVGAnimationForElementAtTimeCallback, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontDelete },
{ "printToPDF", dumpAsPDFCallback, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontDelete },
{ "queueBackNavigation", queueBackNavigationCallback, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontDelete },
void overridePreference(JSStringRef key, JSStringRef value);
int pageNumberForElementById(JSStringRef id, float pageWidthInPixels, float pageHeightInPixels);
JSRetainPtr<JSStringRef> pageProperty(const char* propertyName, int pageNumber) const;
+ JSRetainPtr<JSStringRef> pageSizeAndMarginsInPixels(int pageNumber, int width, int height, int marginTop, int marginRight, int marginBottom, int marginLeft) const;
bool isPageBoxVisible(int pageNumber) const;
- JSRetainPtr<JSStringRef> pageAreaRectInPixels(int pageNumber) const;
- JSRetainPtr<JSStringRef> preferredPageSizeInPixels(int pageNumber) const;
JSStringRef pathToLocalResource(JSContextRef, JSStringRef url);
void queueBackNavigation(int howFarBackward);
void queueForwardNavigation(int howFarForward);
return false;
}
-JSRetainPtr<JSStringRef> LayoutTestController::pageAreaRectInPixels(int pageNumber) const
-{
- // FIXME: implement
- return JSRetainPtr<JSStringRef>();
-}
-
-JSRetainPtr<JSStringRef> LayoutTestController::preferredPageSizeInPixels(int pageNumber) const
+JSRetainPtr<JSStringRef> LayoutTestController::pageSizeAndMarginsInPixels(int pageNumber, int width, int height, int marginTop, int marginRight, int marginBottom, int marginLeft) const
{
// FIXME: implement
return JSRetainPtr<JSStringRef>();
return [mainFrame isPageBoxVisible:pageNumber];
}
-JSRetainPtr<JSStringRef> LayoutTestController::pageAreaRectInPixels(int pageNumber) const
+JSRetainPtr<JSStringRef> LayoutTestController::pageSizeAndMarginsInPixels(int pageNumber, int width, int height, int marginTop, int marginRight, int marginBottom, int marginLeft) const
{
- JSRetainPtr<JSStringRef> propertyValue(Adopt, JSStringCreateWithCFString((CFStringRef)[mainFrame pageAreaRectInPixels:pageNumber]));
- return propertyValue;
-}
-
-JSRetainPtr<JSStringRef> LayoutTestController::preferredPageSizeInPixels(int pageNumber) const
-{
- JSRetainPtr<JSStringRef> propertyValue(Adopt, JSStringCreateWithCFString((CFStringRef)[mainFrame preferredPageSizeInPixels:pageNumber]));
+ JSRetainPtr<JSStringRef> propertyValue(Adopt, JSStringCreateWithCFString((CFStringRef)[mainFrame pageSizeAndMarginsInPixels:pageNumber:width:height:marginTop:marginRight:marginBottom:marginLeft]));
return propertyValue;
}
return false;
}
-JSRetainPtr<JSStringRef> LayoutTestController::pageAreaRectInPixels(int pageNumber) const
-{
- // FIXME: implement
- return JSRetainPtr<JSStringRef>();
-}
-
-JSRetainPtr<JSStringRef> LayoutTestController::preferredPageSizeInPixels(int pageNumber) const
+JSRetainPtr<JSStringRef> LayoutTestController::pageSizeAndMarginsInPixels(int pageNumber, int width, int height, int marginTop, int marginRight, int marginBottom, int marginLeft) const
{
// FIXME: implement
return JSRetainPtr<JSStringRef>();