Bug 998941 - part 1-5: Make HTMLEditor set InputEvent.data when InputEvent.inputType is "insertLink" r=smaug,m_kato

Although neither Chrome nor Safari does not set InputEvent.data value when
InputEvent.inputType is "insertLink", but it's easy to implement.  Therefore,
this patch implements it as declaration of Input Events.

This patch sets the value to raw href attribute value because we create
<a> element without absolute URI when web apps call execCommand("createLink")
with relative URI.

Differential Revision: https://phabricator.services.mozilla.com/D19291

--HG--
extra : moz-landing-system : lando
This commit is contained in:
Masayuki Nakano 2019-02-19 06:30:12 +00:00
parent 122ab2691a
commit 0d571915df
3 changed files with 31 additions and 0 deletions

View File

@ -2950,6 +2950,10 @@ HTMLEditor::InsertLinkAroundSelection(Element* aAnchorElement) {
return NS_OK;
}
nsAutoString rawHref;
anchor->GetAttr(kNameSpaceID_None, nsGkAtoms::href, rawHref);
editActionData.SetData(rawHref);
nsAutoString href;
anchor->GetHref(href);
if (href.IsEmpty()) {

View File

@ -402,6 +402,32 @@ function runTests() {
is(inputEvent.data, "ltr",
aDescription + 'data should be "ltr" when dispatching cmd_switchTextDirection command #2');
// Inserting link
editTarget.innerHTML = "link";
editTarget.focus();
selection.selectAllChildren(editTarget);
inputEvent = null;
aDocument.execCommand("createLink", false, "https://example.com/foo/bar.html");
ok(inputEvent,
aDescription + 'input event should be fired by execCommand("createLink", false, "https://example.com/foo/bar.html")');
ok(inputEvent.isTrusted,
aDescription + 'input event should be trusted when execCommand("createLink", false, "https://example.com/foo/bar.html")');
is(inputEvent.inputType, "insertLink",
aDescription + 'inputType should be "insertLink" when execCommand("createLink", false, "https://example.com/foo/bar.html")');
is(inputEvent.data, "https://example.com/foo/bar.html",
aDescription + 'data should be "https://example.com/foo/bar.html" when execCommand("createLink", false, "https://example.com/foo/bar.html")');
selection.selectAllChildren(editTarget);
aDocument.execCommand("createLink", false, "foo/bar.html");
ok(inputEvent,
aDescription + 'input event should be fired by execCommand("createLink", false, "foo/bar.html")');
ok(inputEvent.isTrusted,
aDescription + 'input event should be trusted when execCommand("createLink", false, "foo/bar.html")');
is(inputEvent.inputType, "insertLink",
aDescription + 'inputType should be "insertLink" when execCommand("createLink", false, "foo/bar.html")');
is(inputEvent.data, "foo/bar.html",
aDescription + 'data should be "foo/bar.html" when execCommand("createLink", false, "foo/bar.html")');
aWindow.removeEventListener("input", handler, true);
}

View File

@ -163,6 +163,7 @@ inline bool IsDataAvailableOnHTMLEditor(EditorInputType aInputType) {
case EditorInputType::eInsertFromComposition: // Only level 2
case EditorInputType::eFormatSetBlockTextDirection:
case EditorInputType::eFormatSetInlineTextDirection:
case EditorInputType::eInsertLink:
return true;
default:
return false;