зеркало из https://github.com/mozilla/gecko-dev.git
Don't insert a <br> when deleting all content in an inline contenteditable element. b=456244 r+sr=peterv
This commit is contained in:
Родитель
7cae04cb73
Коммит
32a840925b
|
@ -42,6 +42,10 @@ VPATH = @srcdir@
|
|||
|
||||
include $(DEPTH)/config/autoconf.mk
|
||||
|
||||
ifdef ENABLE_TESTS
|
||||
DIRS += tests
|
||||
endif
|
||||
|
||||
MODULE = editor
|
||||
LIBRARY_NAME = htmleditor_s
|
||||
LIBXUL_LIBRARY = 1
|
||||
|
|
|
@ -7573,26 +7573,28 @@ nsHTMLEditRules::AdjustSelection(nsISelection *aSelection, nsIEditor::EDirection
|
|||
nsCOMPtr<nsIDOMNode> theblock;
|
||||
if (IsBlockNode(selNode)) theblock = selNode;
|
||||
else theblock = mHTMLEditor->GetBlockNodeParent(selNode);
|
||||
PRBool bIsEmptyNode;
|
||||
res = mHTMLEditor->IsEmptyNode(theblock, &bIsEmptyNode, PR_FALSE, PR_FALSE);
|
||||
if (NS_FAILED(res)) return res;
|
||||
// check if br can go into the destination node
|
||||
if (bIsEmptyNode && mHTMLEditor->CanContainTag(selNode, NS_LITERAL_STRING("br")))
|
||||
{
|
||||
nsIDOMElement *rootElement = mHTMLEditor->GetRoot();
|
||||
if (!rootElement) return NS_ERROR_FAILURE;
|
||||
nsCOMPtr<nsIDOMNode> rootNode(do_QueryInterface(rootElement));
|
||||
if (selNode == rootNode)
|
||||
if (theblock && mHTMLEditor->IsEditable(theblock)) {
|
||||
PRBool bIsEmptyNode;
|
||||
res = mHTMLEditor->IsEmptyNode(theblock, &bIsEmptyNode, PR_FALSE, PR_FALSE);
|
||||
if (NS_FAILED(res)) return res;
|
||||
// check if br can go into the destination node
|
||||
if (bIsEmptyNode && mHTMLEditor->CanContainTag(selNode, NS_LITERAL_STRING("br")))
|
||||
{
|
||||
// Our root node is completely empty. Don't add a <br> here.
|
||||
// AfterEditInner() will add one for us when it calls
|
||||
// CreateBogusNodeIfNeeded()!
|
||||
return NS_OK;
|
||||
}
|
||||
nsIDOMElement *rootElement = mHTMLEditor->GetRoot();
|
||||
if (!rootElement) return NS_ERROR_FAILURE;
|
||||
nsCOMPtr<nsIDOMNode> rootNode(do_QueryInterface(rootElement));
|
||||
if (selNode == rootNode)
|
||||
{
|
||||
// Our root node is completely empty. Don't add a <br> here.
|
||||
// AfterEditInner() will add one for us when it calls
|
||||
// CreateBogusNodeIfNeeded()!
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
nsCOMPtr<nsIDOMNode> brNode;
|
||||
// we know we can skip the rest of this routine given the cirumstance
|
||||
return CreateMozBR(selNode, selOffset, address_of(brNode));
|
||||
nsCOMPtr<nsIDOMNode> brNode;
|
||||
// we know we can skip the rest of this routine given the cirumstance
|
||||
return CreateMozBR(selNode, selOffset, address_of(brNode));
|
||||
}
|
||||
}
|
||||
|
||||
// are we in a text node?
|
||||
|
|
|
@ -0,0 +1,53 @@
|
|||
#
|
||||
# ***** BEGIN LICENSE BLOCK *****
|
||||
# Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
||||
#
|
||||
# The contents of this file are subject to the Mozilla Public License Version
|
||||
# 1.1 (the "License"); you may not use this file except in compliance with
|
||||
# the License. You may obtain a copy of the License at
|
||||
# http://www.mozilla.org/MPL/
|
||||
#
|
||||
# Software distributed under the License is distributed on an "AS IS" basis,
|
||||
# WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
||||
# for the specific language governing rights and limitations under the
|
||||
# License.
|
||||
#
|
||||
# The Original Code is mozilla.org code.
|
||||
#
|
||||
# The Initial Developer of the Original Code is
|
||||
# Mozilla Foundation.
|
||||
# Portions created by the Initial Developer are Copyright (C) 2008
|
||||
# the Initial Developer. All Rights Reserved.
|
||||
#
|
||||
# Contributor(s):
|
||||
#
|
||||
# Alternatively, the contents of this file may be used under the terms of
|
||||
# either of the GNU General Public License Version 2 or later (the "GPL"),
|
||||
# or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
||||
# in which case the provisions of the GPL or the LGPL are applicable instead
|
||||
# of those above. If you wish to allow use of your version of this file only
|
||||
# under the terms of either the GPL or the LGPL, and not to allow others to
|
||||
# use your version of this file under the terms of the MPL, indicate your
|
||||
# decision by deleting the provisions above and replace them with the notice
|
||||
# and other provisions required by the GPL or the LGPL. If you do not delete
|
||||
# the provisions above, a recipient may use your version of this file under
|
||||
# the terms of any one of the MPL, the GPL or the LGPL.
|
||||
#
|
||||
# ***** END LICENSE BLOCK *****
|
||||
|
||||
DEPTH = ../../../..
|
||||
topsrcdir = @top_srcdir@
|
||||
srcdir = @srcdir@
|
||||
VPATH = @srcdir@
|
||||
relativesrcdir = editor/libeditor/html/tests
|
||||
|
||||
include $(DEPTH)/config/autoconf.mk
|
||||
include $(topsrcdir)/config/rules.mk
|
||||
|
||||
_TEST_FILES = \
|
||||
test_bug456244.html \
|
||||
$(NULL)
|
||||
|
||||
libs:: $(_TEST_FILES)
|
||||
$(INSTALL) $(foreach f,$^,"$f") $(DEPTH)/_tests/testing/mochitest/tests/$(relativesrcdir)
|
||||
|
|
@ -0,0 +1,72 @@
|
|||
<!DOCTYPE HTML>
|
||||
<html><head>
|
||||
<title>Test for bug 456244</title>
|
||||
<style src="/tests/SimpleTest/test.css" type="text/css"></style>
|
||||
<script type="application/javascript" src="/MochiKit/packed.js"></script>
|
||||
<script type="application/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
|
||||
<script type="text/javascript" src="/tests/SimpleTest/EventUtils.js"></script>
|
||||
|
||||
<script class="testbody" type="application/javascript">
|
||||
function runTest() {
|
||||
netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
|
||||
|
||||
function select(id) {
|
||||
var e = document.getElementById(id);
|
||||
e.focus();
|
||||
return e;
|
||||
}
|
||||
|
||||
function setupIframe(id) {
|
||||
var e = document.getElementById(id);
|
||||
var doc = e.contentDocument;
|
||||
doc.body.innerHTML = String.fromCharCode(10)+'<span id="' + id + '_span" style="border:1px solid blue" contenteditable="true">X</span>'+String.fromCharCode(10);
|
||||
e = doc.getElementById(id + "_span");
|
||||
e.focus();
|
||||
return e;
|
||||
}
|
||||
|
||||
function test_end_bs(e) {
|
||||
const msg = "Deleting all text in contenteditable inline element";
|
||||
var before = e.parentNode.childNodes[0].nodeValue;
|
||||
sendKey("right", e);
|
||||
sendKey("back_space", e);
|
||||
sendKey("back_space", e);
|
||||
is(e.parentNode.childNodes[0].nodeValue, before, msg + " with id=" + e.id);
|
||||
is(e.innerHTML, "", msg + " with id=" + e.id);
|
||||
}
|
||||
|
||||
test_end_bs(select("t1"));
|
||||
test_end_bs(setupIframe('i1',0));
|
||||
|
||||
{
|
||||
const msg = "Deleting all text in contenteditable body element";
|
||||
var e = document.getElementById('i2');
|
||||
var doc = e.contentDocument;
|
||||
doc.body.setAttribute("contenteditable", "true");
|
||||
doc.body.focus();
|
||||
sendKey("right", doc.body);
|
||||
sendKey("back_space", doc.body);
|
||||
is(doc.body.innerHTML, "<br>", msg + " with id=" + e.id);
|
||||
}
|
||||
|
||||
SimpleTest.finish();
|
||||
}
|
||||
|
||||
SimpleTest.waitForExplicitFinish();
|
||||
addLoadEvent(runTest);
|
||||
</script>
|
||||
</head>
|
||||
<body>
|
||||
<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=456244">Mozilla Bug 456244</a>
|
||||
<p id="display"></p>
|
||||
|
||||
<pre id="test">
|
||||
</pre>
|
||||
|
||||
<div> <span id="t1" style="border:1px solid blue" contenteditable="true">X</span> Y</div>
|
||||
|
||||
<iframe id="i1" width="200" height="100" src="about:blank"></iframe><br>
|
||||
<iframe id="i2" width="200" height="100" src="about:blank">X</iframe><br>
|
||||
|
||||
</body>
|
||||
</html>
|
Загрузка…
Ссылка в новой задаче