Bug 1305355 part.3 IMEInputHandler shouldn't append any ranges when composition string is empty r=m_kato
authorMasayuki Nakano <masayuki@d-toybox.com>
Mon, 26 Sep 2016 17:19:30 +0900
changeset 315395 fb4fd0ff521501151f43eb1dc07294bbc88f8130
parent 315394 fa9da7230277a57e27c6602c85723dddad457d88
child 315396 8c84b761884028e774165afce0b6eea847b09835
push id30748
push usercbook@mozilla.com
push dateWed, 28 Sep 2016 13:53:19 +0000
treeherdermozilla-central@8c84b7618840 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersm_kato
bugs1305355
milestone52.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 1305355 part.3 IMEInputHandler shouldn't append any ranges when composition string is empty r=m_kato IMEInputHandler shouldn't append any ranges to dispatch empty composition event since empty clause information may make TextComposition confused. Additionally, it doesn't need to append caret range because CompositionTransaction always sets caret at start of composition when the composition string is empty. MozReview-Commit-ID: FkLWePXZGJf
widget/cocoa/TextInputHandler.mm
--- a/widget/cocoa/TextInputHandler.mm
+++ b/widget/cocoa/TextInputHandler.mm
@@ -2803,24 +2803,31 @@ IMEInputHandler::GetRangeCount(NSAttribu
 }
 
 already_AddRefed<mozilla::TextRangeArray>
 IMEInputHandler::CreateTextRangeArray(NSAttributedString *aAttrString,
                                       NSRange& aSelectedRange)
 {
   NS_OBJC_BEGIN_TRY_ABORT_BLOCK_NIL;
 
+  RefPtr<mozilla::TextRangeArray> textRangeArray =
+                                      new mozilla::TextRangeArray();
+
+  // Note that we shouldn't append ranges when composition string
+  // is empty because it may cause TextComposition confused.
+  if (![aAttrString length]) {
+    return textRangeArray.forget();
+  }
+
   // Convert the Cocoa range into the TextRange Array used in Gecko.
   // Iterate through the attributed string and map the underline attribute to
   // Gecko IME textrange attributes.  We may need to change the code here if
   // we change the implementation of validAttributesForMarkedText.
   NSRange limitRange = NSMakeRange(0, [aAttrString length]);
   uint32_t rangeCount = GetRangeCount(aAttrString);
-  RefPtr<mozilla::TextRangeArray> textRangeArray =
-                                      new mozilla::TextRangeArray();
   for (uint32_t i = 0; i < rangeCount && limitRange.length > 0; i++) {
     NSRange effectiveRange;
     id attributeValue = [aAttrString attribute:NSUnderlineStyleAttributeName
                                        atIndex:limitRange.location
                          longestEffectiveRange:&effectiveRange
                                        inRange:limitRange];
 
     TextRange range;