Bug 688789 - Stop touching the frame tree to determine whether a node is editable or not; r=roc

This commit is contained in:
Ehsan Akhgari 2011-10-17 00:11:29 -04:00
Родитель 9960ec3300
Коммит b92d32a562
3 изменённых файлов: 71 добавлений и 76 удалений

Просмотреть файл

@ -6,5 +6,5 @@ load 407256-1.html
load 430624-1.html
load 459613.html
load 475132-1.xhtml
asserts-if(Android,6) load 633709.xhtml
asserts-if(!Android,1) load 633709.xhtml # Bug 695364
asserts-if(!Android,6) load 636074-1.html # Bug 439258, charged to the wrong test due to bug 635550

Просмотреть файл

@ -115,6 +115,7 @@
#include "nsITransferable.h"
#include "nsComputedDOMStyle.h"
#include "nsTextEditUtils.h"
#include "nsComputedDOMStyle.h"
#include "mozilla/FunctionTimer.h"
#include "mozilla/Preferences.h"
@ -3614,6 +3615,18 @@ nsEditor::IsTextInDirtyFrameVisible(nsIDOMNode *aNode)
return true;
}
static bool
IsElementVisible(nsIContent* aContent) {
mozilla::dom::Element* element = aContent->AsElement();
nsRefPtr<nsStyleContext> styleContext =
nsComputedDOMStyle::GetStyleContextForElementNoFlush(element,
nsnull, nsnull);
if (styleContext) {
return styleContext->GetStyleDisplay()->mDisplay != NS_STYLE_DISPLAY_NONE;
}
return false;
}
bool
nsEditor::IsEditable(nsIDOMNode *aNode)
{
@ -3626,31 +3639,13 @@ nsEditor::IsEditable(nsIDOMNode *aNode)
nsCOMPtr<nsIContent> content = do_QueryInterface(aNode);
if (content)
{
nsIFrame *resultFrame = content->GetPrimaryFrame();
if (!resultFrame) // if it has no frame, it is not editable
if (content->IsElement() &&
!IsElementVisible(content)) // If the element is invisible, it's not editable
return false;
NS_ASSERTION(content->IsNodeOfType(nsINode::eTEXT) ||
content->IsElement(),
"frame for non element-or-text?");
if (!content->IsNodeOfType(nsINode::eTEXT))
return true; // not a text node; has a frame
return true; // not a text node; not invisible
// test the textframe and all its non-fluid continuations
while (resultFrame) {
if (resultFrame->GetStateBits() & NS_FRAME_IS_DIRTY) // we can only trust width data for undirty frames
{
// In the past a comment said:
// "assume all text nodes with dirty frames are editable"
// Nowadays we use a virtual function, that assumes TRUE
// in the simple editor world,
// and uses enhanced logic to find out in the HTML world.
return IsTextInDirtyFrameVisible(aNode);
}
if (resultFrame->HasAnyNoncollapsedCharacters()) {
return true;
}
resultFrame = resultFrame->GetNextContinuation();
}
return IsTextInDirtyFrameVisible(aNode);
}
return false; // didn't pass any editability test
}

Просмотреть файл

@ -8469,22 +8469,22 @@ const TEST_RESULTS = {
"selscore": 0,
"valresult": 6,
"selresult": 3,
"output": "`foo [bar ´<b>`baz] qoz´</b>` quz sic´",
"innerHTML": "`foo [bar ´<b>`baz] qoz´</b>` quz sic´",
"outerHTML": "<body xmlns=\"http://www.w3.org/1999/xhtml\" onload=\"setDesignMode()\">`foo [bar ´<b>`baz] qoz´</b>` quz sic´</body>",
"bodyInnerHTML": "`foo [bar ´<b>`baz] qoz´</b>` quz sic´",
"bodyOuterHTML": "<body xmlns=\"http://www.w3.org/1999/xhtml\" onload=\"setDesignMode()\">`foo [bar ´<b>`baz] qoz´</b>` quz sic´</body>"
"output": "`foo [´<b>`bar ´`baz] qoz´</b>` quz sic´",
"innerHTML": "`foo [´<b>`bar ´`baz] qoz´</b>` quz sic´",
"outerHTML": "<body xmlns=\"http://www.w3.org/1999/xhtml\" onload=\"setDesignMode()\">`foo [´<b>`bar ´`baz] qoz´</b>` quz sic´</body>",
"bodyInnerHTML": "`foo [´<b>`bar ´`baz] qoz´</b>` quz sic´",
"bodyOuterHTML": "<body xmlns=\"http://www.w3.org/1999/xhtml\" onload=\"setDesignMode()\">`foo [´<b>`bar ´`baz] qoz´</b>` quz sic´</body>"
},
"body": {
"valscore": 0,
"selscore": 0,
"valresult": 6,
"selresult": 3,
"output": "`foo [bar ´<b>`baz] qoz´</b>` quz sic´",
"innerHTML": "`foo [bar ´<b>`baz] qoz´</b>` quz sic´",
"outerHTML": "<body xmlns=\"http://www.w3.org/1999/xhtml\" contenteditable=\"true\">`foo [bar ´<b>`baz] qoz´</b>` quz sic´</body>",
"bodyInnerHTML": "`foo [bar ´<b>`baz] qoz´</b>` quz sic´",
"bodyOuterHTML": "<body xmlns=\"http://www.w3.org/1999/xhtml\" contenteditable=\"true\">`foo [bar ´<b>`baz] qoz´</b>` quz sic´</body>"
"output": "`foo [´<b>`bar ´`baz] qoz´</b>` quz sic´",
"innerHTML": "`foo [´<b>`bar ´`baz] qoz´</b>` quz sic´",
"outerHTML": "<body xmlns=\"http://www.w3.org/1999/xhtml\" contenteditable=\"true\">`foo [´<b>`bar ´`baz] qoz´</b>` quz sic´</body>",
"bodyInnerHTML": "`foo [´<b>`bar ´`baz] qoz´</b>` quz sic´",
"bodyOuterHTML": "<body xmlns=\"http://www.w3.org/1999/xhtml\" contenteditable=\"true\">`foo [´<b>`bar ´`baz] qoz´</b>` quz sic´</body>"
},
"div": {
"valscore": 0,
@ -8990,26 +8990,26 @@ const TEST_RESULTS = {
},
"U_U-1_SW": {
"dM": {
"valscore": 0,
"selscore": 0,
"valresult": 6,
"selresult": 3,
"output": "`foo´<u>`[bar]´</u>`baz´",
"innerHTML": "`foo´<u>`[bar]´</u>`baz´",
"outerHTML": "<body xmlns=\"http://www.w3.org/1999/xhtml\" onload=\"setDesignMode()\">`foo´<u>`[bar]´</u>`baz´</body>",
"bodyInnerHTML": "`foo´<u>`[bar]´</u>`baz´",
"bodyOuterHTML": "<body xmlns=\"http://www.w3.org/1999/xhtml\" onload=\"setDesignMode()\">`foo´<u>`[bar]´</u>`baz´</body>"
"valscore": 1,
"selscore": 1,
"valresult": 8,
"selresult": 5,
"output": "`foo[bar]baz´",
"innerHTML": "`foo[bar]baz´",
"outerHTML": "<body xmlns=\"http://www.w3.org/1999/xhtml\" onload=\"setDesignMode()\">`foo[bar]baz´</body>",
"bodyInnerHTML": "`foo[bar]baz´",
"bodyOuterHTML": "<body xmlns=\"http://www.w3.org/1999/xhtml\" onload=\"setDesignMode()\">`foo[bar]baz´</body>"
},
"body": {
"valscore": 0,
"selscore": 0,
"valresult": 6,
"selresult": 3,
"output": "`foo´<u>`[bar]´</u>`baz´",
"innerHTML": "`foo´<u>`[bar]´</u>`baz´",
"outerHTML": "<body xmlns=\"http://www.w3.org/1999/xhtml\" contenteditable=\"true\">`foo´<u>`[bar]´</u>`baz´</body>",
"bodyInnerHTML": "`foo´<u>`[bar]´</u>`baz´",
"bodyOuterHTML": "<body xmlns=\"http://www.w3.org/1999/xhtml\" contenteditable=\"true\">`foo´<u>`[bar]´</u>`baz´</body>"
"valscore": 1,
"selscore": 1,
"valresult": 8,
"selresult": 5,
"output": "`foo[bar]baz´",
"innerHTML": "`foo[bar]baz´",
"outerHTML": "<body xmlns=\"http://www.w3.org/1999/xhtml\" contenteditable=\"true\">`foo[bar]baz´</body>",
"bodyInnerHTML": "`foo[bar]baz´",
"bodyOuterHTML": "<body xmlns=\"http://www.w3.org/1999/xhtml\" contenteditable=\"true\">`foo[bar]baz´</body>"
},
"div": {
"valscore": 1,
@ -9379,22 +9379,22 @@ const TEST_RESULTS = {
"selscore": 0,
"valresult": 6,
"selresult": 3,
"output": "`foo´<s><strike>`[bar]´</strike></s>`baz´",
"innerHTML": "`foo´<s><strike>`[bar]´</strike></s>`baz´",
"outerHTML": "<body xmlns=\"http://www.w3.org/1999/xhtml\" onload=\"setDesignMode()\">`foo´<s><strike>`[bar]´</strike></s>`baz´</body>",
"bodyInnerHTML": "`foo´<s><strike>`[bar]´</strike></s>`baz´",
"bodyOuterHTML": "<body xmlns=\"http://www.w3.org/1999/xhtml\" onload=\"setDesignMode()\">`foo´<s><strike>`[bar]´</strike></s>`baz´</body>"
"output": "`foo´<strike><s>`[bar]´</s></strike>`baz´",
"innerHTML": "`foo´<strike><s>`[bar]´</s></strike>`baz´",
"outerHTML": "<body xmlns=\"http://www.w3.org/1999/xhtml\" onload=\"setDesignMode()\">`foo´<strike><s>`[bar]´</s></strike>`baz´</body>",
"bodyInnerHTML": "`foo´<strike><s>`[bar]´</s></strike>`baz´",
"bodyOuterHTML": "<body xmlns=\"http://www.w3.org/1999/xhtml\" onload=\"setDesignMode()\">`foo´<strike><s>`[bar]´</s></strike>`baz´</body>"
},
"body": {
"valscore": 0,
"selscore": 0,
"valresult": 6,
"selresult": 3,
"output": "`foo´<s><strike>`[bar]´</strike></s>`baz´",
"innerHTML": "`foo´<s><strike>`[bar]´</strike></s>`baz´",
"outerHTML": "<body xmlns=\"http://www.w3.org/1999/xhtml\" contenteditable=\"true\">`foo´<s><strike>`[bar]´</strike></s>`baz´</body>",
"bodyInnerHTML": "`foo´<s><strike>`[bar]´</strike></s>`baz´",
"bodyOuterHTML": "<body xmlns=\"http://www.w3.org/1999/xhtml\" contenteditable=\"true\">`foo´<s><strike>`[bar]´</strike></s>`baz´</body>"
"output": "`foo´<strike><s>`[bar]´</s></strike>`baz´",
"innerHTML": "`foo´<strike><s>`[bar]´</s></strike>`baz´",
"outerHTML": "<body xmlns=\"http://www.w3.org/1999/xhtml\" contenteditable=\"true\">`foo´<strike><s>`[bar]´</s></strike>`baz´</body>",
"bodyInnerHTML": "`foo´<strike><s>`[bar]´</s></strike>`baz´",
"bodyOuterHTML": "<body xmlns=\"http://www.w3.org/1999/xhtml\" contenteditable=\"true\">`foo´<strike><s>`[bar]´</s></strike>`baz´</body>"
},
"div": {
"valscore": 0,
@ -10254,33 +10254,33 @@ const TEST_RESULTS = {
"selscore": 1,
"valresult": 8,
"selresult": 5,
"output": "{<img src=\"pic.jpg\" height=\"140\" align=\"right\" width=\"200\">`abc]´",
"innerHTML": "{<img src=\"pic.jpg\" height=\"140\" align=\"right\" width=\"200\">`abc]´",
"outerHTML": "<body xmlns=\"http://www.w3.org/1999/xhtml\" onload=\"setDesignMode()\">{<img width=\"200\" align=\"right\" height=\"140\" src=\"pic.jpg\">`abc]´</body>",
"bodyInnerHTML": "{<img src=\"pic.jpg\" height=\"140\" align=\"right\" width=\"200\">`abc]´",
"bodyOuterHTML": "<body xmlns=\"http://www.w3.org/1999/xhtml\" onload=\"setDesignMode()\">{<img width=\"200\" align=\"right\" height=\"140\" src=\"pic.jpg\">`abc]´</body>"
"output": "{<img src=\"pic.jpg\" align=\"right\" height=\"140\" width=\"200\">`abc]´",
"innerHTML": "{<img src=\"pic.jpg\" align=\"right\" height=\"140\" width=\"200\">`abc]´",
"outerHTML": "<body xmlns=\"http://www.w3.org/1999/xhtml\" onload=\"setDesignMode()\">{<img width=\"200\" height=\"140\" align=\"right\" src=\"pic.jpg\">`abc]´</body>",
"bodyInnerHTML": "{<img src=\"pic.jpg\" align=\"right\" height=\"140\" width=\"200\">`abc]´",
"bodyOuterHTML": "<body xmlns=\"http://www.w3.org/1999/xhtml\" onload=\"setDesignMode()\">{<img width=\"200\" height=\"140\" align=\"right\" src=\"pic.jpg\">`abc]´</body>"
},
"body": {
"valscore": 1,
"selscore": 1,
"valresult": 8,
"selresult": 5,
"output": "{<img src=\"pic.jpg\" height=\"140\" align=\"right\" width=\"200\">`abc]´",
"innerHTML": "{<img src=\"pic.jpg\" height=\"140\" align=\"right\" width=\"200\">`abc]´",
"outerHTML": "<body xmlns=\"http://www.w3.org/1999/xhtml\" contenteditable=\"true\">{<img width=\"200\" align=\"right\" height=\"140\" src=\"pic.jpg\">`abc]´</body>",
"bodyInnerHTML": "{<img src=\"pic.jpg\" height=\"140\" align=\"right\" width=\"200\">`abc]´",
"bodyOuterHTML": "<body xmlns=\"http://www.w3.org/1999/xhtml\" contenteditable=\"true\">{<img width=\"200\" align=\"right\" height=\"140\" src=\"pic.jpg\">`abc]´</body>"
"output": "{<img src=\"pic.jpg\" align=\"right\" height=\"140\" width=\"200\">`abc]´",
"innerHTML": "{<img src=\"pic.jpg\" align=\"right\" height=\"140\" width=\"200\">`abc]´",
"outerHTML": "<body xmlns=\"http://www.w3.org/1999/xhtml\" contenteditable=\"true\">{<img width=\"200\" height=\"140\" align=\"right\" src=\"pic.jpg\">`abc]´</body>",
"bodyInnerHTML": "{<img src=\"pic.jpg\" align=\"right\" height=\"140\" width=\"200\">`abc]´",
"bodyOuterHTML": "<body xmlns=\"http://www.w3.org/1999/xhtml\" contenteditable=\"true\">{<img width=\"200\" height=\"140\" align=\"right\" src=\"pic.jpg\">`abc]´</body>"
},
"div": {
"valscore": 1,
"selscore": 1,
"valresult": 8,
"selresult": 5,
"output": "{<img src=\"pic.jpg\" height=\"140\" align=\"right\" width=\"200\">`abc]´",
"innerHTML": "{<img src=\"pic.jpg\" height=\"140\" align=\"right\" width=\"200\">`abc]´",
"outerHTML": "<div xmlns=\"http://www.w3.org/1999/xhtml\" contenteditable=\"true\" id=\"editor-div\">{<img width=\"200\" align=\"right\" height=\"140\" src=\"pic.jpg\">`abc]´</div>",
"bodyInnerHTML": "CAN<br>ARY<div id=\"editor-div\" contenteditable=\"true\">{<img src=\"pic.jpg\" height=\"140\" align=\"right\" width=\"200\">`abc]´</div>CAN<br>ARY",
"bodyOuterHTML": "<body xmlns=\"http://www.w3.org/1999/xhtml\">CAN<br>ARY<div contenteditable=\"true\" id=\"editor-div\">{<img width=\"200\" align=\"right\" height=\"140\" src=\"pic.jpg\">`abc]´</div>CAN<br>ARY</body>"
"output": "{<img src=\"pic.jpg\" align=\"right\" height=\"140\" width=\"200\">`abc]´",
"innerHTML": "{<img src=\"pic.jpg\" align=\"right\" height=\"140\" width=\"200\">`abc]´",
"outerHTML": "<div xmlns=\"http://www.w3.org/1999/xhtml\" contenteditable=\"true\" id=\"editor-div\">{<img width=\"200\" height=\"140\" align=\"right\" src=\"pic.jpg\">`abc]´</div>",
"bodyInnerHTML": "CAN<br>ARY<div id=\"editor-div\" contenteditable=\"true\">{<img src=\"pic.jpg\" align=\"right\" height=\"140\" width=\"200\">`abc]´</div>CAN<br>ARY",
"bodyOuterHTML": "<body xmlns=\"http://www.w3.org/1999/xhtml\">CAN<br>ARY<div contenteditable=\"true\" id=\"editor-div\">{<img width=\"200\" height=\"140\" align=\"right\" src=\"pic.jpg\">`abc]´</div>CAN<br>ARY</body>"
}
},
"OUTDENT_BQ-1_SW": {