Bug 998941 - part 1-5: Make HTMLEditor set InputEvent.data when InputEvent.inputType is "insertLink" r=smaug,m_kato
authorMasayuki Nakano <masayuki@d-toybox.com>
Tue, 19 Feb 2019 06:30:12 +0000
changeset 517730 d392cc639292ac3a3fc4a8439f7bc55b8d03ef0e
parent 517729 cfd766ac996375620525ee17540e80d03872cf08
child 517731 f4039b1e1fb6696443deb7ffd152568f6c20e240
push id10862
push userffxbld-merge
push dateMon, 11 Mar 2019 13:01:11 +0000
treeherdermozilla-beta@a2e7f5c935da [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerssmaug, m_kato
bugs998941
milestone67.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
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
editor/libeditor/HTMLEditor.cpp
editor/libeditor/tests/test_dom_input_event_on_htmleditor.html
widget/EventForwards.h
--- a/editor/libeditor/HTMLEditor.cpp
+++ b/editor/libeditor/HTMLEditor.cpp
@@ -2945,16 +2945,20 @@ HTMLEditor::InsertLinkAroundSelection(El
 
   // Be sure we were given an anchor element
   RefPtr<HTMLAnchorElement> anchor =
       HTMLAnchorElement::FromNodeOrNull(aAnchorElement);
   if (!anchor) {
     return NS_OK;
   }
 
+  nsAutoString rawHref;
+  anchor->GetAttr(kNameSpaceID_None, nsGkAtoms::href, rawHref);
+  editActionData.SetData(rawHref);
+
   nsAutoString href;
   anchor->GetHref(href);
   if (href.IsEmpty()) {
     return NS_OK;
   }
 
   nsresult rv;
   AutoPlaceholderBatch treatAsOneTransaction(*this);
--- a/editor/libeditor/tests/test_dom_input_event_on_htmleditor.html
+++ b/editor/libeditor/tests/test_dom_input_event_on_htmleditor.html
@@ -397,16 +397,42 @@ function runTests() {
        aDescription + "input event should be fired by dispatching cmd_switchTextDirection command #2");
     ok(inputEvent.isTrusted,
        aDescription + "input event should be trusted when dispatching cmd_switchTextDirection command #2");
     is(inputEvent.inputType, "formatSetBlockTextDirection",
        aDescription + 'inputType should be "formatSetBlockTextDirection" when dispatching cmd_switchTextDirection command #2');
     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);
   }
 
   doTests(document.getElementById("editor1").contentDocument,
           document.getElementById("editor1").contentWindow,
           "Editor1, body has contenteditable attribute");
   doTests(document.getElementById("editor2").contentDocument,
           document.getElementById("editor2").contentWindow,
--- a/widget/EventForwards.h
+++ b/widget/EventForwards.h
@@ -158,16 +158,17 @@ inline bool IsDataAvailableOnTextEditor(
  */
 inline bool IsDataAvailableOnHTMLEditor(EditorInputType aInputType) {
   switch (aInputType) {
     case EditorInputType::eInsertText:
     case EditorInputType::eInsertCompositionText:
     case EditorInputType::eInsertFromComposition:  // Only level 2
     case EditorInputType::eFormatSetBlockTextDirection:
     case EditorInputType::eFormatSetInlineTextDirection:
+    case EditorInputType::eInsertLink:
       return true;
     default:
       return false;
   }
 }
 
 #define NS_DEFINE_COMMAND(aName, aCommandStr) , Command##aName
 #define NS_DEFINE_COMMAND_NO_EXEC_COMMAND(aName) , Command##aName