Bug 1275914 part.8 TextComposition should always update its composition start offset during composing r?smaug draft
authorMasayuki Nakano <masayuki@d-toybox.com>
Fri, 10 Jun 2016 22:57:33 +0900
changeset 377869 9bc433373606eddb633a84666d64d6e9877168e2
parent 377868 5ae8107545004d2215b66f40b0d744dd4af680d4
child 377878 e1f2894c101fcde17f63354b84eb243b3eedd1e5
push id20876
push usermasayuki@d-toybox.com
push dateMon, 13 Jun 2016 08:27:53 +0000
reviewerssmaug
bugs1275914
milestone50.0a1
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,43 @@ 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) {
+      if (range.IsClause() && !range.mStartOffset) {
+        return &range;
+      }
+    }
+    MOZ_ASSERT(!HasClauses());
+    return nullptr;
+  }
 };
 
 } // namespace mozilla
 
 #endif // mozilla_TextRage_h_