зеркало из https://github.com/mozilla/pjs.git
Make getBoundingClientRect()/getClientRects() deal with a detached range and non-content boundary nodes. b=529670 r=roc
This commit is contained in:
Родитель
e7d983dea3
Коммит
235f1d9df9
|
@ -0,0 +1,18 @@
|
|||
<!DOCTYPE HTML>
|
||||
<html><head>
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
|
||||
<title>Testcase for bug 529670</title>
|
||||
<script>
|
||||
function boom() {
|
||||
document.createRange().getClientRects()
|
||||
document.createRange().getBoundingClientRect()
|
||||
|
||||
var range = document.createRange();
|
||||
range.detach();
|
||||
range.getClientRects()
|
||||
range.getBoundingClientRect()
|
||||
}
|
||||
</script>
|
||||
</head>
|
||||
<body onload="boom()"></body>
|
||||
</html>
|
|
@ -59,3 +59,4 @@ load 493281-1.html
|
|||
load 493281-2.html
|
||||
load 490760-1.xhtml
|
||||
load 494810-1.html
|
||||
load 529670.html
|
||||
|
|
|
@ -2119,7 +2119,7 @@ static void CollectClientRects(nsLayoutUtils::RectCallback* aCollector,
|
|||
if (iter.IsDone()) {
|
||||
// the range is collapsed, only continue if the cursor is in a text node
|
||||
nsCOMPtr<nsIContent> content = do_QueryInterface(aStartParent);
|
||||
if (content->IsNodeOfType(nsINode::eTEXT)) {
|
||||
if (content && content->IsNodeOfType(nsINode::eTEXT)) {
|
||||
nsIFrame* frame = content->GetPrimaryFrame();
|
||||
if (frame && frame->GetType() == nsGkAtoms::textFrame) {
|
||||
nsTextFrame* textFrame = static_cast<nsTextFrame*>(frame);
|
||||
|
@ -2144,6 +2144,8 @@ static void CollectClientRects(nsLayoutUtils::RectCallback* aCollector,
|
|||
nsCOMPtr<nsIDOMNode> node(iter.GetCurrentNode());
|
||||
iter.Next();
|
||||
nsCOMPtr<nsIContent> content = do_QueryInterface(node);
|
||||
if (!content)
|
||||
continue;
|
||||
if (content->IsNodeOfType(nsINode::eTEXT)) {
|
||||
if (node == startContainer) {
|
||||
PRInt32 offset = startContainer == endContainer ?
|
||||
|
@ -2152,7 +2154,7 @@ static void CollectClientRects(nsLayoutUtils::RectCallback* aCollector,
|
|||
continue;
|
||||
} else if (node == endContainer) {
|
||||
GetPartialTextRect(aCollector, content, 0, aEndOffset);
|
||||
continue;
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -2167,6 +2169,8 @@ static void CollectClientRects(nsLayoutUtils::RectCallback* aCollector,
|
|||
NS_IMETHODIMP
|
||||
nsRange::GetBoundingClientRect(nsIDOMClientRect** aResult)
|
||||
{
|
||||
*aResult = nsnull;
|
||||
|
||||
// Weak ref, since we addref it below
|
||||
nsClientRect* rect = new nsClientRect();
|
||||
if (!rect)
|
||||
|
@ -2174,6 +2178,9 @@ nsRange::GetBoundingClientRect(nsIDOMClientRect** aResult)
|
|||
|
||||
NS_ADDREF(*aResult = rect);
|
||||
|
||||
if (!mStartParent)
|
||||
return NS_OK;
|
||||
|
||||
nsLayoutUtils::RectAccumulator accumulator;
|
||||
|
||||
CollectClientRects(&accumulator, this, mStartParent, mStartOffset,
|
||||
|
@ -2190,6 +2197,9 @@ nsRange::GetClientRects(nsIDOMClientRectList** aResult)
|
|||
{
|
||||
*aResult = nsnull;
|
||||
|
||||
if (!mStartParent)
|
||||
return NS_OK;
|
||||
|
||||
nsRefPtr<nsClientRectList> rectList = new nsClientRectList();
|
||||
if (!rectList)
|
||||
return NS_ERROR_OUT_OF_MEMORY;
|
||||
|
|
Загрузка…
Ссылка в новой задаче