Bug 1130935 part.4 nsIMM32Handler::GetCharacterRectOfSelectedTextAt() should return wrting mode if it's necessary r=emk+smaug
authorMasayuki Nakano <masayuki@d-toybox.com>
Fri, 15 May 2015 10:18:07 +0900
changeset 243954 8ba5a18f576859065bf862a57d70956d86a3101d
parent 243953 3cca44bb0f434426685cebeadcb3e7568407439c
child 243955 c72c0cec7d618206ec7e0216c1ca8f14bbe5148f
push id59807
push usermasayuki@d-toybox.com
push dateFri, 15 May 2015 01:18:23 +0000
treeherdermozilla-inbound@c6c67158efef [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersemk
bugs1130935
milestone41.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 1130935 part.4 nsIMM32Handler::GetCharacterRectOfSelectedTextAt() should return wrting mode if it's necessary r=emk+smaug
dom/events/ContentEventHandler.cpp
widget/TextEvents.h
widget/windows/nsIMM32Handler.cpp
widget/windows/nsIMM32Handler.h
--- a/dom/events/ContentEventHandler.cpp
+++ b/dom/events/ContentEventHandler.cpp
@@ -1048,16 +1048,17 @@ ContentEventHandler::OnQueryCaretRect(Wi
     if (offset == aEvent->mInput.mOffset) {
       if (!caretFrame) {
         return NS_ERROR_FAILURE;
       }
       rv = ConvertToRootViewRelativeOffset(caretFrame, caretRect);
       NS_ENSURE_SUCCESS(rv, rv);
       aEvent->mReply.mRect = LayoutDevicePixel::FromUntyped(
         caretRect.ToOutsidePixels(caretFrame->PresContext()->AppUnitsPerDevPixel()));
+      aEvent->mReply.mWritingMode = caretFrame->GetWritingMode();
       aEvent->mReply.mOffset = aEvent->mInput.mOffset;
       aEvent->mSucceeded = true;
       return NS_OK;
     }
   }
 
   // Otherwise, we should set the guessed caret rect.
   nsRefPtr<nsRange> range = new nsRange(mRootContent);
@@ -1081,16 +1082,17 @@ ContentEventHandler::OnQueryCaretRect(Wi
   rect.width = caretRect.width;
   rect.height = frame->GetSize().height;
 
   rv = ConvertToRootViewRelativeOffset(frame, rect);
   NS_ENSURE_SUCCESS(rv, rv);
 
   aEvent->mReply.mRect = LayoutDevicePixel::FromUntyped(
       rect.ToOutsidePixels(mPresContext->AppUnitsPerDevPixel()));
+  aEvent->mReply.mWritingMode = frame->GetWritingMode();
   aEvent->mSucceeded = true;
   return NS_OK;
 }
 
 nsresult
 ContentEventHandler::OnQueryContentState(WidgetQueryContentEvent* aEvent)
 {
   nsresult rv = Init(aEvent);
--- a/widget/TextEvents.h
+++ b/widget/TextEvents.h
@@ -531,16 +531,17 @@ public:
     NS_ASSERTION(message == NS_QUERY_SELECTED_TEXT,
                  "not querying selection");
     return mReply.mOffset + (mReply.mReversed ? 0 : mReply.mString.Length());
   }
 
   mozilla::WritingMode GetWritingMode(void) const
   {
     NS_ASSERTION(message == NS_QUERY_SELECTED_TEXT ||
+                 message == NS_QUERY_CARET_RECT ||
                  message == NS_QUERY_TEXT_RECT,
                  "not querying selection or text rect");
     return mReply.mWritingMode;
   }
 
   bool mSucceeded;
   bool mWasAsync;
   bool mUseNativeLineBreak;
--- a/widget/windows/nsIMM32Handler.cpp
+++ b/widget/windows/nsIMM32Handler.cpp
@@ -91,16 +91,34 @@ public:
     if (aFlags & UI_CAP_ROTANY) {
       HandleSeparator(*this);
       AppendLiteral("UI_CAP_ROTANY");
     }
   }
   virtual ~GetIMEUIPropertyName() {}
 };
 
+class GetWritingModeName : public nsAutoCString
+{
+public:
+  GetWritingModeName(const WritingMode& aWritingMode)
+  {
+    if (!aWritingMode.IsVertical()) {
+      Assign("Horizontal");
+      return;
+    }
+    if (aWritingMode.IsVerticalLR()) {
+      Assign("Vertical (LR)");
+      return;
+    }
+    Assign("Vertical (RL)");
+  }
+  virtual ~GetWritingModeName() {}
+};
+
 static UINT sWM_MSIME_MOUSE = 0; // mouse message for MSIME 98/2000
 
 //-------------------------------------------------------------------------
 //
 // from http://download.microsoft.com/download/6/0/9/60908e9e-d2c1-47db-98f6-216af76a235f/msime.h
 // The document for this has been removed from MSDN...
 //
 //-------------------------------------------------------------------------
@@ -1874,17 +1892,18 @@ nsIMM32Handler::ConvertToANSIString(cons
   ::WideCharToMultiByte(aCodePage, 0, (LPCWSTR)aStr.get(), aStr.Length(),
                         (LPSTR)aANSIStr.BeginWriting(), len, nullptr, nullptr);
   return true;
 }
 
 bool
 nsIMM32Handler::GetCharacterRectOfSelectedTextAt(nsWindow* aWindow,
                                                  uint32_t aOffset,
-                                                 nsIntRect &aCharRect)
+                                                 nsIntRect& aCharRect,
+                                                 WritingMode* aWritingMode)
 {
   nsIntPoint point(0, 0);
 
   WidgetQueryContentEvent selection(true, NS_QUERY_SELECTED_TEXT, aWindow);
   aWindow->InitEvent(selection, &point);
   aWindow->DispatchWindowEvent(&selection);
   if (!selection.mSucceeded) {
     PR_LOG(gIMM32Log, PR_LOG_ALWAYS,
@@ -1911,31 +1930,39 @@ nsIMM32Handler::GetCharacterRectOfSelect
   nsIntRect r;
   if (!useCaretRect) {
     WidgetQueryContentEvent charRect(true, NS_QUERY_TEXT_RECT, aWindow);
     charRect.InitForQueryTextRect(offset, 1);
     aWindow->InitEvent(charRect, &point);
     aWindow->DispatchWindowEvent(&charRect);
     if (charRect.mSucceeded) {
       aCharRect = LayoutDevicePixel::ToUntyped(charRect.mReply.mRect);
+      if (aWritingMode) {
+        *aWritingMode = charRect.GetWritingMode();
+      }
       PR_LOG(gIMM32Log, PR_LOG_ALWAYS,
         ("IMM32: GetCharacterRectOfSelectedTextAt, aOffset=%lu, SUCCEEDED\n",
          aOffset));
       PR_LOG(gIMM32Log, PR_LOG_ALWAYS,
-        ("IMM32: GetCharacterRectOfSelectedTextAt, aCharRect={ x: %ld, y: %ld, width: %ld, height: %ld }\n",
-         aCharRect.x, aCharRect.y, aCharRect.width, aCharRect.height));
+        ("IMM32: GetCharacterRectOfSelectedTextAt, "
+         "aCharRect={ x: %ld, y: %ld, width: %ld, height: %ld }, "
+         "charRect.GetWritingMode()=%s",
+         aCharRect.x, aCharRect.y, aCharRect.width, aCharRect.height,
+         GetWritingModeName(charRect.GetWritingMode()).get()));
       return true;
     }
   }
 
-  return GetCaretRect(aWindow, aCharRect);
+  return GetCaretRect(aWindow, aCharRect, aWritingMode);
 }
 
 bool
-nsIMM32Handler::GetCaretRect(nsWindow* aWindow, nsIntRect &aCaretRect)
+nsIMM32Handler::GetCaretRect(nsWindow* aWindow,
+                             nsIntRect& aCaretRect,
+                             WritingMode* aWritingMode)
 {
   nsIntPoint point(0, 0);
 
   WidgetQueryContentEvent selection(true, NS_QUERY_SELECTED_TEXT, aWindow);
   aWindow->InitEvent(selection, &point);
   aWindow->DispatchWindowEvent(&selection);
   if (!selection.mSucceeded) {
     PR_LOG(gIMM32Log, PR_LOG_ALWAYS,
@@ -1950,19 +1977,25 @@ nsIMM32Handler::GetCaretRect(nsWindow* a
   aWindow->InitEvent(caretRect, &point);
   aWindow->DispatchWindowEvent(&caretRect);
   if (!caretRect.mSucceeded) {
     PR_LOG(gIMM32Log, PR_LOG_ALWAYS,
       ("IMM32: GetCaretRect,  FAILED (NS_QUERY_CARET_RECT)\n"));
     return false;
   }
   aCaretRect = LayoutDevicePixel::ToUntyped(caretRect.mReply.mRect);
+  if (aWritingMode) {
+    *aWritingMode = caretRect.GetWritingMode();
+  }
   PR_LOG(gIMM32Log, PR_LOG_ALWAYS,
-    ("IMM32: GetCaretRect, SUCCEEDED, aCaretRect={ x: %ld, y: %ld, width: %ld, height: %ld }\n",
-     aCaretRect.x, aCaretRect.y, aCaretRect.width, aCaretRect.height));
+    ("IMM32: GetCaretRect, SUCCEEDED, "
+     "aCaretRect={ x: %ld, y: %ld, width: %ld, height: %ld }, "
+     "caretRect.GetWritingMode()=%s",
+     aCaretRect.x, aCaretRect.y, aCaretRect.width, aCaretRect.height,
+     GetWritingModeName(caretRect.GetWritingMode()).get()));
   return true;
 }
 
 bool
 nsIMM32Handler::SetIMERelatedWindowsPos(nsWindow* aWindow,
                                         const nsIMEContext &aIMEContext)
 {
   nsIntRect r;
--- a/widget/windows/nsIMM32Handler.h
+++ b/widget/windows/nsIMM32Handler.h
@@ -276,20 +276,24 @@ protected:
   bool ConvertToANSIString(const nsAFlatString& aStr,
                              UINT aCodePage,
                              nsACString& aANSIStr);
 
   bool SetIMERelatedWindowsPos(nsWindow* aWindow,
                                const nsIMEContext& aIMEContext);
   void SetIMERelatedWindowsPosOnPlugin(nsWindow* aWindow,
                                        const nsIMEContext& aIMEContext);
-  bool GetCharacterRectOfSelectedTextAt(nsWindow* aWindow,
-                                          uint32_t aOffset,
-                                          nsIntRect &aCharRect);
-  bool GetCaretRect(nsWindow* aWindow, nsIntRect &aCaretRect);
+  bool GetCharacterRectOfSelectedTextAt(
+         nsWindow* aWindow,
+         uint32_t aOffset,
+         nsIntRect& aCharRect,
+         mozilla::WritingMode* aWritingMode = nullptr);
+  bool GetCaretRect(nsWindow* aWindow,
+                    nsIntRect& aCaretRect,
+                    mozilla::WritingMode* aWritingMode = nullptr);
   void GetCompositionString(const nsIMEContext &aIMEContext,
                             DWORD aIndex,
                             nsAString& aCompositionString) const;
 
   /**
    * AdjustCompositionFont() makes IME vertical writing mode if it's supported.
    */
   void AdjustCompositionFont(const nsIMEContext& aIMEContext,