From 0d571915dfdfbb3c9aa7f3b8e67af713e6119b2e Mon Sep 17 00:00:00 2001 From: Masayuki Nakano Date: Tue, 19 Feb 2019 06:30:12 +0000 Subject: [PATCH] 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 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 --- editor/libeditor/HTMLEditor.cpp | 4 +++ .../test_dom_input_event_on_htmleditor.html | 26 +++++++++++++++++++ widget/EventForwards.h | 1 + 3 files changed, 31 insertions(+) diff --git a/editor/libeditor/HTMLEditor.cpp b/editor/libeditor/HTMLEditor.cpp index 43b53573ac30..789e608d61ec 100644 --- a/editor/libeditor/HTMLEditor.cpp +++ b/editor/libeditor/HTMLEditor.cpp @@ -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()) { diff --git a/editor/libeditor/tests/test_dom_input_event_on_htmleditor.html b/editor/libeditor/tests/test_dom_input_event_on_htmleditor.html index 96e0c7498188..039c0420c9ff 100644 --- a/editor/libeditor/tests/test_dom_input_event_on_htmleditor.html +++ b/editor/libeditor/tests/test_dom_input_event_on_htmleditor.html @@ -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); } diff --git a/widget/EventForwards.h b/widget/EventForwards.h index 71306273a58f..4541ab0452fb 100644 --- a/widget/EventForwards.h +++ b/widget/EventForwards.h @@ -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;