From: hyatt@apple.com Date: Wed, 8 Feb 2012 17:34:22 +0000 (+0000) Subject: Source/WebCore: https://bugs.webkit.org/show_bug.cgi?id=78122 X-Git-Tag: 070512121124~13445 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=7b1ab8d657bf270b7373a3150eedb93dbfb8a85b;p=profile%2Fivi%2Fwebkit-efl.git Source/WebCore: https://bugs.webkit.org/show_bug.cgi?id=78122 Add support for the "contains" value for line-grid-snap. This value centers the line box in between the text-top and text-bottom of the minimum number of grid lines that enclose the line box. This is useful for centering headers in a line grid. Reviewed by Adam Roben. Added a new test in fast/line-grid. * rendering/RootInlineBox.cpp: (WebCore::RootInlineBox::lineGridSnapAdjustment): LayoutTests: https://bugs.webkit.org/show_bug.cgi?id=78122 Add a new test that shows the "contains" value in action. Reviewed by Adam Roben. * fast/line-grid/line-grid-contains-value.html: Added. * platform/mac/fast/line-grid/line-grid-contains-value-expected.png: Added. * platform/mac/fast/line-grid/line-grid-contains-value-expected.txt: Added. git-svn-id: http://svn.webkit.org/repository/webkit/trunk@107099 268f45cc-cd09-0410-ab3c-d52691b4dbfc --- diff --git a/LayoutTests/ChangeLog b/LayoutTests/ChangeLog index 3b19fee..5cb7f22 100644 --- a/LayoutTests/ChangeLog +++ b/LayoutTests/ChangeLog @@ -1,3 +1,15 @@ +2012-02-08 David Hyatt + + https://bugs.webkit.org/show_bug.cgi?id=78122 + + Add a new test that shows the "contains" value in action. + + Reviewed by Adam Roben. + + * fast/line-grid/line-grid-contains-value.html: Added. + * platform/mac/fast/line-grid/line-grid-contains-value-expected.png: Added. + * platform/mac/fast/line-grid/line-grid-contains-value-expected.txt: Added. + 2012-02-08 Dan Bernstein Moved a Mac-specific test to platform/mac. diff --git a/LayoutTests/fast/line-grid/line-grid-contains-value.html b/LayoutTests/fast/line-grid/line-grid-contains-value.html new file mode 100644 index 0000000..96f78f0 --- /dev/null +++ b/LayoutTests/fast/line-grid/line-grid-contains-value.html @@ -0,0 +1,36 @@ + + + + + + +
+
+This header should be centered in the grid lines. +
+
+This text should snap
+to a 36px font-size grid.
+There should be lots of spacing between these lines. + +
+
+ +
+
+xxxxxxxxxxxxxxxxx
+xxxxxxxxxxxxxxxxx
+xxxxxxxxxxxxxxxxx
+xxxxxxxxxxxxxxxxx
+xxxxxxxxxxxxxxxxx
+xxxxxxxxxxxxxxxxx
+xxxxxxxxxxxxxxxxx
+
+
+ + + diff --git a/LayoutTests/platform/mac/fast/line-grid/line-grid-contains-value-expected.png b/LayoutTests/platform/mac/fast/line-grid/line-grid-contains-value-expected.png new file mode 100644 index 0000000..e8ecaaf Binary files /dev/null and b/LayoutTests/platform/mac/fast/line-grid/line-grid-contains-value-expected.png differ diff --git a/LayoutTests/platform/mac/fast/line-grid/line-grid-contains-value-expected.txt b/LayoutTests/platform/mac/fast/line-grid/line-grid-contains-value-expected.txt new file mode 100644 index 0000000..7c341a2 --- /dev/null +++ b/LayoutTests/platform/mac/fast/line-grid/line-grid-contains-value-expected.txt @@ -0,0 +1,45 @@ +layer at (0,0) size 800x600 + RenderView at (0,0) size 800x600 +layer at (0,0) size 800x600 layerType: background only +layer at (10,10) size 620x305 + RenderBlock (positioned) zI: -1 {DIV} at (10,10) size 620x305 + RenderBlock {DIV} at (10,10) size 600x285 [color=#00FF00] + RenderText {#text} at (0,3) size 612x36 + text run at (0,3) width 612: "xxxxxxxxxxxxxxxxx" + RenderBR {BR} at (0,0) size 0x0 + RenderText {#text} at (0,44) size 612x36 + text run at (0,44) width 612: "xxxxxxxxxxxxxxxxx" + RenderBR {BR} at (0,0) size 0x0 + RenderText {#text} at (0,85) size 612x36 + text run at (0,85) width 612: "xxxxxxxxxxxxxxxxx" + RenderBR {BR} at (0,0) size 0x0 + RenderText {#text} at (0,126) size 612x36 + text run at (0,126) width 612: "xxxxxxxxxxxxxxxxx" + RenderBR {BR} at (0,0) size 0x0 + RenderText {#text} at (0,167) size 612x36 + text run at (0,167) width 612: "xxxxxxxxxxxxxxxxx" + RenderBR {BR} at (0,0) size 0x0 + RenderText {#text} at (0,208) size 612x36 + text run at (0,208) width 612: "xxxxxxxxxxxxxxxxx" + RenderBR {BR} at (0,0) size 0x0 + RenderText {#text} at (0,249) size 612x36 + text run at (0,249) width 612: "xxxxxxxxxxxxxxxxx" + RenderBR {BR} at (0,0) size 0x0 +layer at (0,0) size 800x600 layerType: foreground only + RenderBlock {HTML} at (0,0) size 800x600 + RenderBody {BODY} at (8,8) size 784x584 +layer at (10,10) size 620x301 + RenderBlock (positioned) {DIV} at (10,10) size 620x301 + RenderBlock {DIV} at (10,10) size 600x150 + RenderText {#text} at (0,13) size 594x137 + text run at (0,13) width 594: "This header should be centered" + text run at (0,95) width 310: "in the grid lines." + RenderBlock {DIV} at (10,160) size 600x131 + RenderText {#text} at (0,35) size 101x14 + text run at (0,35) width 101: "This text should snap" + RenderBR {BR} at (101,46) size 0x0 + RenderText {#text} at (0,76) size 113x14 + text run at (0,76) width 113: "to a 36px font-size grid." + RenderBR {BR} at (113,87) size 0x0 + RenderText {#text} at (0,117) size 245x14 + text run at (0,117) width 245: "There should be lots of spacing between these lines." diff --git a/Source/WebCore/ChangeLog b/Source/WebCore/ChangeLog index 26f0a18..aba101c 100644 --- a/Source/WebCore/ChangeLog +++ b/Source/WebCore/ChangeLog @@ -1,3 +1,18 @@ +2012-02-08 David Hyatt + + https://bugs.webkit.org/show_bug.cgi?id=78122 + + Add support for the "contains" value for line-grid-snap. This value centers the line box in between the + text-top and text-bottom of the minimum number of grid lines that enclose the line box. This is useful for + centering headers in a line grid. + + Reviewed by Adam Roben. + + Added a new test in fast/line-grid. + + * rendering/RootInlineBox.cpp: + (WebCore::RootInlineBox::lineGridSnapAdjustment): + 2012-02-08 Cary Clark [Skia Mac] Make misspelling underline dots unclipped diff --git a/Source/WebCore/rendering/RootInlineBox.cpp b/Source/WebCore/rendering/RootInlineBox.cpp index 081b3b7..0bffabc 100644 --- a/Source/WebCore/rendering/RootInlineBox.cpp +++ b/Source/WebCore/rendering/RootInlineBox.cpp @@ -330,7 +330,7 @@ LayoutUnit RootInlineBox::lineGridSnapAdjustment(LayoutUnit delta) const { // If our block doesn't have snapping turned on, do nothing. // FIXME: Implement bounds snapping. - if (block()->style()->lineGridSnap() != LineGridSnapBaseline) + if (block()->style()->lineGridSnap() == LineGridSnapNone) return 0; // Get the current line grid and offset. @@ -352,33 +352,54 @@ LayoutUnit RootInlineBox::lineGridSnapAdjustment(LayoutUnit delta) const // as established by the line box. // FIXME: Need to handle crazy line-box-contain values that cause the root line box to not be considered. I assume // the grid should honor line-box-contain. - LayoutUnit baselineMultiple = lineGridBox->lineBottomWithLeading() - lineGridBox->lineTopWithLeading(); - if (!baselineMultiple) + LayoutUnit gridLineHeight = lineGridBox->lineBottomWithLeading() - lineGridBox->lineTopWithLeading(); + if (!gridLineHeight) return 0; - LayoutUnit lineGridAscent = lineGrid->style()->fontMetrics().ascent(baselineType()); - LayoutUnit firstBaselinePosition = lineGridBlockOffset + lineGridAscent + lineGridBox->logicalTop(); - LayoutUnit currentBaselinePosition = blockOffset + logicalTop() + delta + block()->style()->fontMetrics().ascent(baselineType()); + LayoutUnit lineGridFontAscent = lineGrid->style()->fontMetrics().ascent(baselineType()); + LayoutUnit lineGridFontHeight = lineGridBox->logicalHeight(); + LayoutUnit firstTextTop = lineGridBlockOffset + lineGridBox->logicalTop(); + LayoutUnit firstBaselinePosition = firstTextTop + lineGridFontAscent; + + LayoutUnit currentTextTop = blockOffset + logicalTop() + delta; + LayoutUnit currentFontAscent = block()->style()->fontMetrics().ascent(baselineType()); + LayoutUnit currentBaselinePosition = currentTextTop + currentFontAscent; // If we're paginated, see if we're on a page after the first one. If so, the grid resets on subsequent pages. // FIXME: If the grid is an ancestor of the pagination establisher, then this is incorrect. LayoutUnit pageLogicalTop = 0; if (layoutState->isPaginated() && layoutState->pageLogicalHeight()) { pageLogicalTop = block()->pageLogicalTopForOffset(logicalTop() + delta); - if (pageLogicalTop > lineGridBlockOffset + lineGridBox->logicalTop()) - firstBaselinePosition = lineGridAscent + pageLogicalTop + lineGridBox->logicalTop() - lineGrid->borderBefore() - lineGrid->paddingBefore(); + if (pageLogicalTop > firstTextTop) + firstTextTop = pageLogicalTop + lineGridBox->logicalTop() - lineGrid->borderBefore() - lineGrid->paddingBefore(); } - + + if (block()->style()->lineGridSnap() == LineGridSnapContain) { + // Compute the desired offset from the text-top of a grid line. + // Look at our height (logicalHeight()). + // Look at the total available height. It's going to be (textBottom - textTop) + (n-1)*(multiple with leading) + // where n is number of grid lines required to enclose us. + if (logicalHeight() <= lineGridFontHeight) + firstTextTop += (lineGridFontHeight - logicalHeight()) / 2; + else { + LayoutUnit numberOfLinesWithLeading = ceilf(static_cast(logicalHeight() - lineGridFontHeight) / gridLineHeight); + LayoutUnit totalHeight = lineGridFontHeight + numberOfLinesWithLeading * gridLineHeight; + firstTextTop += (totalHeight - logicalHeight()) / 2; + } + firstBaselinePosition = firstTextTop + currentFontAscent; + } else + firstBaselinePosition = firstTextTop + lineGridFontAscent; + // If we're above the first line, just push to the first line. if (currentBaselinePosition < firstBaselinePosition) return delta + firstBaselinePosition - currentBaselinePosition; // Otherwise we're in the middle of the grid somewhere. Just push to the next line. LayoutUnit baselineOffset = currentBaselinePosition - firstBaselinePosition; - LayoutUnit remainder = baselineOffset % baselineMultiple; + LayoutUnit remainder = baselineOffset % gridLineHeight; LayoutUnit result = delta; if (remainder) - result += baselineMultiple - remainder; + result += gridLineHeight - remainder; // If we aren't paginated we can return the result. if (!layoutState->isPaginated() || !layoutState->pageLogicalHeight() || result == delta)