Bug 1213589 part.9 ContentEventHandler::ShouldBreakLineBefore() should return false if the content is unknown HTML element r=smaug

This commit is contained in:
Masayuki Nakano 2015-12-02 13:20:01 +09:00
parent ca5b42279c
commit c62bfb339f
4 changed files with 72 additions and 31 deletions

View File

@ -8,6 +8,7 @@
#include "mozilla/IMEStateManager.h"
#include "mozilla/TextEvents.h"
#include "mozilla/dom/Element.h"
#include "mozilla/dom/HTMLUnknownElement.h"
#include "mozilla/dom/Selection.h"
#include "nsCaret.h"
#include "nsCOMPtr.h"
@ -24,6 +25,7 @@
#include "nsIObjectFrame.h"
#include "nsLayoutUtils.h"
#include "nsPresContext.h"
#include "nsQueryObject.h"
#include "nsRange.h"
#include "nsTextFragment.h"
#include "nsTextFrame.h"
@ -496,37 +498,43 @@ ContentEventHandler::ShouldBreakLineBefore(nsIContent* aContent,
// aContent for deciding if it's an inline. However, it's difficult
// IMEContentObserver to notify IME of text change caused by style change.
// Therefore, currently, we should check only from the tag for now.
// TODO: Check if the element is an unknown HTML element.
return !aContent->IsAnyOfHTMLElements(nsGkAtoms::a,
nsGkAtoms::abbr,
nsGkAtoms::acronym,
nsGkAtoms::b,
nsGkAtoms::bdi,
nsGkAtoms::bdo,
nsGkAtoms::big,
nsGkAtoms::cite,
nsGkAtoms::code,
nsGkAtoms::data,
nsGkAtoms::del,
nsGkAtoms::dfn,
nsGkAtoms::em,
nsGkAtoms::font,
nsGkAtoms::i,
nsGkAtoms::ins,
nsGkAtoms::kbd,
nsGkAtoms::mark,
nsGkAtoms::s,
nsGkAtoms::samp,
nsGkAtoms::small,
nsGkAtoms::span,
nsGkAtoms::strike,
nsGkAtoms::strong,
nsGkAtoms::sub,
nsGkAtoms::sup,
nsGkAtoms::time,
nsGkAtoms::tt,
nsGkAtoms::u,
nsGkAtoms::var);
if (aContent->IsAnyOfHTMLElements(nsGkAtoms::a,
nsGkAtoms::abbr,
nsGkAtoms::acronym,
nsGkAtoms::b,
nsGkAtoms::bdi,
nsGkAtoms::bdo,
nsGkAtoms::big,
nsGkAtoms::cite,
nsGkAtoms::code,
nsGkAtoms::data,
nsGkAtoms::del,
nsGkAtoms::dfn,
nsGkAtoms::em,
nsGkAtoms::font,
nsGkAtoms::i,
nsGkAtoms::ins,
nsGkAtoms::kbd,
nsGkAtoms::mark,
nsGkAtoms::s,
nsGkAtoms::samp,
nsGkAtoms::small,
nsGkAtoms::span,
nsGkAtoms::strike,
nsGkAtoms::strong,
nsGkAtoms::sub,
nsGkAtoms::sup,
nsGkAtoms::time,
nsGkAtoms::tt,
nsGkAtoms::u,
nsGkAtoms::var)) {
return false;
}
// If the element is unknown element, we shouldn't insert line breaks before
// it since unknown elements should be ignored.
RefPtr<HTMLUnknownElement> unknownHTMLElement = do_QueryObject(aContent);
return !unknownHTMLElement;
}
nsresult

View File

@ -14,6 +14,9 @@ NS_IMPL_NS_NEW_HTML_ELEMENT(Unknown)
namespace mozilla {
namespace dom {
NS_IMPL_ISUPPORTS_INHERITED(HTMLUnknownElement, nsGenericHTMLElement,
HTMLUnknownElement)
JSObject*
HTMLUnknownElement::WrapNode(JSContext *aCx, JS::Handle<JSObject*> aGivenProto)
{

View File

@ -12,9 +12,17 @@
namespace mozilla {
namespace dom {
#define NS_HTMLUNKNOWNELEMENT_IID \
{ 0xc09e665b, 0x3876, 0x40dd, \
{ 0x85, 0x28, 0x44, 0xc2, 0x3f, 0xd4, 0x58, 0xf2 } }
class HTMLUnknownElement final : public nsGenericHTMLElement
{
public:
NS_DECLARE_STATIC_IID_ACCESSOR(NS_HTMLUNKNOWNELEMENT_IID)
NS_DECL_ISUPPORTS_INHERITED
explicit HTMLUnknownElement(already_AddRefed<mozilla::dom::NodeInfo>& aNodeInfo)
: nsGenericHTMLElement(aNodeInfo)
{
@ -26,9 +34,12 @@ public:
virtual nsresult Clone(mozilla::dom::NodeInfo *aNodeInfo, nsINode **aResult) const override;
protected:
virtual ~HTMLUnknownElement() {}
virtual JSObject* WrapNode(JSContext *aCx, JS::Handle<JSObject*> aGivenProto) override;
};
NS_DEFINE_STATIC_IID_ACCESSOR(HTMLUnknownElement, NS_HTMLUNKNOWNELEMENT_IID)
} // namespace dom
} // namespace mozilla

View File

@ -3191,6 +3191,19 @@ function runSetSelectionEventTest()
is(selection.focusOffset, 0,
"runSetSelectionEventTest #15 (0, 0), \"" + contenteditable.innerHTML + "\": selection focus offset should be 0");
checkSelection(0, "", "runSetSelectionEventTest #15 (0, 0), \"" + contenteditable.innerHTML + "\"");
// #16
contenteditable.innerHTML = "a<blink>b</blink>c";
synthesizeSelectionSet(0, 3);
is(selection.anchorNode, contenteditable.firstChild,
"runSetSelectionEventTest #15 (0, 0), \"" + contenteditable.innerHTML + "\": selection anchor node should be the first text node");
is(selection.anchorOffset, 0,
"runSetSelectionEventTest #15 (0, 0), \"" + contenteditable.innerHTML + "\": selection anchor offset should be 0");
is(selection.focusNode, contenteditable.lastChild,
"runSetSelectionEventTest #15 (0, 0), \"" + contenteditable.innerHTML + "\": selection focus node should be the last text node");
is(selection.focusOffset, contenteditable.lastChild.wholeText.length,
"runSetSelectionEventTest #15 (0, 0), \"" + contenteditable.innerHTML + "\": selection focus offset should be the length of the last text node");
checkSelection(0, "abc", "runSetSelectionEventTest #16 (0, 3), \"" + contenteditable.innerHTML + "\"");
}
function runQueryTextContentEventTest()
@ -3387,6 +3400,12 @@ function runQueryTextContentEventTest()
result = synthesizeQueryTextContent(kLFLen*3, 1);
is(result.text, "", "runQueryTextContentEventTest #8 (kLFLen*3, 1), \"" + contenteditable.innerHTML + "\"");
// #16
contenteditable.innerHTML = "a<blink>b</blink>c";
result = synthesizeQueryTextContent(0, 3);
is(result.text, "abc", "runQueryTextContentEventTest #16 (0, 3), \"" + contenteditable.innerHTML + "\"");
}
function runCSSTransformTest()