Bug 414190. getBoundingClientRect and getClientRects need special treatment of tables. r+sr=mats

This commit is contained in:
roc+@cs.cmu.edu 2008-01-28 09:42:52 -08:00
parent 155e62dc44
commit 0dcd3acd05
3 changed files with 146 additions and 19 deletions

View File

@ -803,31 +803,33 @@ nsNSElementTearoff::GetBoundingClientRect(nsIDOMTextRectangle** aResult)
r.UnionRect(r, nextRect);
}
} else {
r = nsLayoutUtils::GetAllInFlowBoundingRect(frame) +
GetOffsetFromInitialContainingBlock(frame);
// The weird frame layout of tables requires this
if (frame->GetType() == nsGkAtoms::tableOuterFrame) {
nsIFrame* innerTable = frame->GetFirstChild(nsnull);
if (innerTable) {
r = nsLayoutUtils::GetAllInFlowBoundingRect(innerTable) + innerTable->GetPosition();
}
nsIFrame* caption = frame->GetFirstChild(nsGkAtoms::captionList);
if (caption) {
r.UnionRect(r, nsLayoutUtils::GetAllInFlowBoundingRect(caption) + caption->GetPosition());
}
} else {
r = nsLayoutUtils::GetAllInFlowBoundingRect(frame);
}
r += GetOffsetFromInitialContainingBlock(frame);
}
SetTextRectangle(r, presContext, rect);
return NS_OK;
}
NS_IMETHODIMP
nsNSElementTearoff::GetClientRects(nsIDOMTextRectangleList** aResult)
static nsresult
AddRectanglesForFrames(nsTextRectangleList* aRectList, nsIFrame* aFrame)
{
// Weak ref, since we addref it below
nsTextRectangleList* rectList = new nsTextRectangleList();
if (!rectList)
return NS_ERROR_OUT_OF_MEMORY;
NS_ADDREF(*aResult = rectList);
nsIFrame* frame = mContent->GetPrimaryFrame(Flush_Layout);
if (!frame) {
// display:none, perhaps? Return an empty list
if (!aFrame)
return NS_OK;
}
nsPresContext* presContext = frame->PresContext();
for (nsIFrame* f = frame; f;
nsPresContext* presContext = aFrame->PresContext();
for (nsIFrame* f = aFrame; f;
f = nsLayoutUtils::GetNextContinuationOrSpecialSibling(f)) {
nsRefPtr<nsTextRectangle> rect = new nsTextRectangle();
if (!rect)
@ -838,8 +840,45 @@ nsNSElementTearoff::GetClientRects(nsIDOMTextRectangleList** aResult)
r = nsRect(GetOffsetFromInitialContainingBlock(f), f->GetSize());
}
SetTextRectangle(r, presContext, rect);
rectList->Append(rect);
aRectList->Append(rect);
}
return NS_OK;
}
NS_IMETHODIMP
nsNSElementTearoff::GetClientRects(nsIDOMTextRectangleList** aResult)
{
*aResult = nsnull;
// Weak ref, since we addref it below
nsRefPtr<nsTextRectangleList> rectList = new nsTextRectangleList();
if (!rectList)
return NS_ERROR_OUT_OF_MEMORY;
nsIFrame* frame = mContent->GetPrimaryFrame(Flush_Layout);
if (!frame) {
// display:none, perhaps? Return an empty list
*aResult = rectList.forget().get();
return NS_OK;
}
if (frame->GetType() == nsGkAtoms::tableOuterFrame) {
// The weird frame layout of tables requires this
nsIFrame* innerTable = frame->GetFirstChild(nsnull);
nsresult rv = AddRectanglesForFrames(rectList, innerTable);
if (NS_FAILED(rv))
return rv;
nsIFrame* caption = frame->GetFirstChild(nsGkAtoms::captionList);
rv = AddRectanglesForFrames(rectList, caption);
if (NS_FAILED(rv))
return rv;
} else {
nsresult rv = AddRectanglesForFrames(rectList, frame);
if (NS_FAILED(rv))
return rv;
}
*aResult = rectList.forget().get();
return NS_OK;
}

View File

@ -123,6 +123,7 @@ _TEST_FILES = test_bug5141.html \
test_bug405182.html \
test_bug403841.html \
test_bug410229.html \
test_bug414190.html \
$(NULL)
libs:: $(_TEST_FILES)

View File

@ -0,0 +1,87 @@
<!DOCTYPE HTML>
<html>
<!--
https://bugzilla.mozilla.org/show_bug.cgi?id=414190
-->
<head>
<title>Test for Bug 414190</title>
<script type="text/javascript" src="/MochiKit/MochiKit.js"></script>
<script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
<link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
</head>
<body>
<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=414190">Mozilla Bug 414190</a>
<p id="display"></p>
<table id="table" border="0" cellspacing="0" cellpadding="0"
style="width:100px; border:10px solid silver;">
<tr><td id="cell" style="height:100px;"></td></tr>
<caption id="caption" style="caption-side:bottom; width:50px; height:70px; background:yellow;"></caption>
</table>
<div id="content" style="display: none">
</div>
<pre id="test">
<script class="testbody" type="text/javascript">
function isEqualRect(r1, r2, r1border, s) {
is(r1.left + r1border, r2.left, s + " (left)");
is(r1.right - r1border, r2.right, s + " (right)");
is(r1.top + r1border, r2.top, s + " (top)");
is(r1.bottom - r1border, r2.bottom, s + " (bottom)");
}
var table = document.getElementById("table");
var cell = document.getElementById("cell");
var caption = document.getElementById("caption");
var tableRects = table.getClientRects();
var tableBoundingRect = table.getBoundingClientRect();
var cellBoundingRect = cell.getBoundingClientRect();
var captionBoundingRect = caption.getBoundingClientRect();
is(tableRects.length, 2, "Table should have rects for body and caption");
isEqualRect(tableRects[0], cellBoundingRect, 10,
"Table first rect should be cell rect");
isEqualRect(tableRects[1], captionBoundingRect, 0,
"Table second rect should be caption rect");
is(cellBoundingRect.right - cellBoundingRect.left, 80, "Cell incorrect width");
is(cellBoundingRect.bottom - cellBoundingRect.top, 100, "Cell incorrect height");
is(captionBoundingRect.right - captionBoundingRect.left, 50, "Caption incorrect width");
is(captionBoundingRect.bottom - captionBoundingRect.top, 70, "Caption incorrect height");
is(captionBoundingRect.top, cellBoundingRect.bottom + 10, "Discontiguous vertical geometry");
is(tableBoundingRect.top, cellBoundingRect.top - 10, "Table top error");
is(tableBoundingRect.left, cellBoundingRect.left - 10, "Table left error");
is(tableBoundingRect.bottom, captionBoundingRect.bottom, "Table bottom error");
is(tableBoundingRect.right, cellBoundingRect.right + 10, "Table right error");
caption.style.captionSide = "left";
tableRects = table.getClientRects();
tableBoundingRect = table.getBoundingClientRect();
cellBoundingRect = cell.getBoundingClientRect();
captionBoundingRect = caption.getBoundingClientRect();
is(tableRects.length, 2, "Table should have rects for body and caption");
isEqualRect(tableRects[0], cellBoundingRect, 10,
"Table first rect should be cell rect plus border");
isEqualRect(tableRects[1], captionBoundingRect, 0,
"Table second rect should be caption rect");
is(cellBoundingRect.right - cellBoundingRect.left, 80, "Cell incorrect width");
is(cellBoundingRect.bottom - cellBoundingRect.top, 100, "Cell incorrect height");
is(captionBoundingRect.right - captionBoundingRect.left, 50, "Caption incorrect width");
is(captionBoundingRect.bottom - captionBoundingRect.top, 70, "Caption incorrect height");
// This fails right now, see bug 414193
todo_is(captionBoundingRect.right + 10, cellBoundingRect.left, "Discontiguous horizontal geometry");
is(tableBoundingRect.top, cellBoundingRect.top - 10, "Table top error");
is(tableBoundingRect.left, captionBoundingRect.left, "Table left error");
is(tableBoundingRect.bottom, cellBoundingRect.bottom + 10, "Table bottom error");
is(tableBoundingRect.right, cellBoundingRect.right + 10, "Table right error");
</script>
</pre>
</body>
</html>