Bug 1275914 part.8 TextComposition should always update its composition start offset during composing r=smaug
authorMasayuki Nakano <masayuki@d-toybox.com>
Mon, 20 Jun 2016 16:34:40 +0900
changeset 342180 0aeee92e288e305a6c29a683a48a9c7a5fc7c079
parent 342179 d758ecd88650be969181e8add7423721ea54a7fc
child 342181 0cefc193909c8878ca39cae149a36f3d08739e82
push id6389
push userraliiev@mozilla.com
push dateMon, 19 Sep 2016 13:38:22 +0000
treeherdermozilla-beta@01d67bfe6c81 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerssmaug
bugs1275914
milestone50.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 1275914 part.8 TextComposition should always update its composition start offset during composing r=smaug TextComposition should update its composition start offset after every DOM event dispatch with first clause's selection type if there is composition string. MozReview-Commit-ID: HFkePci1PhU
dom/events/TextComposition.cpp
widget/TextRange.h
--- a/dom/events/TextComposition.cpp
+++ b/dom/events/TextComposition.cpp
@@ -434,16 +434,22 @@ TextComposition::HandleSelectionEvent(ns
   handler.OnSelectionEvent(aSelectionEvent);
 }
 
 uint32_t
 TextComposition::GetSelectionStartOffset()
 {
   nsCOMPtr<nsIWidget> widget = mPresContext->GetRootWidget();
   WidgetQueryContentEvent selectedTextEvent(true, eQuerySelectedText, widget);
+  if (mRanges && mRanges->HasClauses()) {
+    selectedTextEvent.InitForQuerySelectedText(
+                        ToSelectionType(mRanges->GetFirstClause()->mRangeType));
+  } else {
+    selectedTextEvent.InitForQuerySelectedText(SelectionType::eNormal);
+  }
 
   // The editor which has this composition is observed by active
   // IMEContentObserver, we can use the cache of it.
   RefPtr<IMEContentObserver> contentObserver =
     IMEStateManager::GetActiveContentObserver();
   bool doQuerySelection = true;
   if (contentObserver) {
     if (contentObserver->IsManaging(this)) {
--- a/widget/TextRange.h
+++ b/widget/TextRange.h
@@ -270,22 +270,45 @@ public:
     for (const TextRange& range : *this) {
       if (range.mRangeType == TextRangeType::eCaret) {
         return true;
       }
     }
     return false;
   }
 
+  bool HasClauses() const
+  {
+    for (const TextRange& range : *this) {
+      if (range.IsClause()) {
+        return true;
+      }
+    }
+    return false;
+  }
+
   uint32_t GetCaretPosition() const
   {
     for (const TextRange& range : *this) {
       if (range.mRangeType == TextRangeType::eCaret) {
         return range.mStartOffset;
       }
     }
     return UINT32_MAX;
   }
+
+  const TextRange* GetFirstClause() const
+  {
+    for (const TextRange& range : *this) {
+      // Look for the range of a clause whose start offset is 0 because the
+      // first clause's start offset is always 0.
+      if (range.IsClause() && !range.mStartOffset) {
+        return &range;
+      }
+    }
+    MOZ_ASSERT(!HasClauses());
+    return nullptr;
+  }
 };
 
 } // namespace mozilla
 
 #endif // mozilla_TextRage_h_