Bug 998941 - part 1-6: Make HTMLEditor set InputEvent.data when InputEvent.inputType is "fontName" r=smaug,m_kato
authorMasayuki Nakano <masayuki@d-toybox.com>
Tue, 19 Feb 2019 06:30:50 +0000
changeset 517731 f4039b1e1fb6696443deb7ffd152568f6c20e240
parent 517730 d392cc639292ac3a3fc4a8439f7bc55b8d03ef0e
child 517732 ef76c4985c1a632742814949279816207396ff38
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-6: Make HTMLEditor set InputEvent.data when InputEvent.inputType is "fontName" r=smaug,m_kato Although neither Chrome nor Safari does not set InputEvent.data value when InputEvent.inputType is "fontName", but it's easy to implement. Therefore, this patch implements it as declaration of Input Events. This patch uses given value as-is. Perhaps, this shouldn't cause any problems because such value can be set to Element.style.fontFamily without any changes. Note that automated test will be added into WPT later. Differential Revision: https://phabricator.services.mozilla.com/D19294
editor/libeditor/HTMLStyleEditor.cpp
widget/EventForwards.h
--- a/editor/libeditor/HTMLStyleEditor.cpp
+++ b/editor/libeditor/HTMLStyleEditor.cpp
@@ -62,16 +62,25 @@ nsresult HTMLEditor::SetInlinePropertyAs
                                                nsAtom* aAttribute,
                                                const nsAString& aValue) {
   AutoEditActionDataSetter editActionData(
       *this,
       HTMLEditUtils::GetEditActionForFormatText(aProperty, aAttribute, true));
   if (NS_WARN_IF(!editActionData.CanHandle())) {
     return NS_ERROR_NOT_INITIALIZED;
   }
+  switch (editActionData.GetEditAction()) {
+    case EditAction::eSetFontFamilyProperty:
+      MOZ_ASSERT(!aValue.IsVoid());
+      // XXX Should we trim unnecessary whitespaces?
+      editActionData.SetData(aValue);
+      break;
+    default:
+      break;
+  }
 
   AutoTransactionBatch treatAsOneTransaction(*this);
 
   if (&aProperty == nsGkAtoms::sup) {
     // Superscript and Subscript styles are mutually exclusive.
     nsresult rv = RemoveInlinePropertyInternal(nsGkAtoms::sub, nullptr);
     if (NS_WARN_IF(NS_FAILED(rv))) {
       return rv;
@@ -100,16 +109,25 @@ HTMLEditor::SetInlineProperty(const nsAS
   }
   RefPtr<nsAtom> attribute = AtomizeAttribute(aAttribute);
   AutoEditActionDataSetter editActionData(
       *this,
       HTMLEditUtils::GetEditActionForFormatText(*property, attribute, true));
   if (NS_WARN_IF(!editActionData.CanHandle())) {
     return NS_ERROR_NOT_INITIALIZED;
   }
+  switch (editActionData.GetEditAction()) {
+    case EditAction::eSetFontFamilyProperty:
+      MOZ_ASSERT(!aValue.IsVoid());
+      // XXX Should we trim unnecessary whitespaces?
+      editActionData.SetData(aValue);
+      break;
+    default:
+      break;
+  }
   return SetInlinePropertyInternal(*property, attribute, aValue);
 }
 
 nsresult HTMLEditor::SetInlinePropertyInternal(nsAtom& aProperty,
                                                nsAtom* aAttribute,
                                                const nsAString& aValue) {
   MOZ_ASSERT(IsEditActionDataAvailable());
 
@@ -1218,17 +1236,24 @@ HTMLEditor::RemoveAllInlineProperties() 
 nsresult HTMLEditor::RemoveInlinePropertyAsAction(nsAtom& aProperty,
                                                   nsAtom* aAttribute) {
   AutoEditActionDataSetter editActionData(
       *this,
       HTMLEditUtils::GetEditActionForFormatText(aProperty, aAttribute, false));
   if (NS_WARN_IF(!editActionData.CanHandle())) {
     return NS_ERROR_NOT_INITIALIZED;
   }
-
+  switch (editActionData.GetEditAction()) {
+    case EditAction::eRemoveFontFamilyProperty:
+      MOZ_ASSERT(!EmptyString().IsVoid());
+      editActionData.SetData(EmptyString());
+      break;
+    default:
+      break;
+  }
   nsresult rv = RemoveInlinePropertyInternal(&aProperty, aAttribute);
   if (NS_WARN_IF(NS_FAILED(rv))) {
     return rv;
   }
   return NS_OK;
 }
 
 NS_IMETHODIMP
@@ -1238,17 +1263,24 @@ HTMLEditor::RemoveInlineProperty(const n
   RefPtr<nsAtom> attribute = AtomizeAttribute(aAttribute);
 
   AutoEditActionDataSetter editActionData(
       *this,
       HTMLEditUtils::GetEditActionForFormatText(*property, attribute, false));
   if (NS_WARN_IF(!editActionData.CanHandle())) {
     return NS_ERROR_NOT_INITIALIZED;
   }
-
+  switch (editActionData.GetEditAction()) {
+    case EditAction::eRemoveFontFamilyProperty:
+      MOZ_ASSERT(!EmptyString().IsVoid());
+      editActionData.SetData(EmptyString());
+      break;
+    default:
+      break;
+  }
   return RemoveInlinePropertyInternal(property, attribute);
 }
 
 nsresult HTMLEditor::RemoveInlinePropertyInternal(nsAtom* aProperty,
                                                   nsAtom* aAttribute) {
   MOZ_ASSERT(IsEditActionDataAvailable());
   MOZ_ASSERT(aAttribute != nsGkAtoms::_empty);
 
--- a/widget/EventForwards.h
+++ b/widget/EventForwards.h
@@ -159,16 +159,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:
+    case EditorInputType::eFormatFontName:
       return true;
     default:
       return false;
   }
 }
 
 #define NS_DEFINE_COMMAND(aName, aCommandStr) , Command##aName
 #define NS_DEFINE_COMMAND_NO_EXEC_COMMAND(aName) , Command##aName