Bug 1166436 part.1 Create mozilla::ContentCache and TabParent should store the text to it r=m_kato
authorMasayuki Nakano <masayuki@d-toybox.com>
Fri, 05 Jun 2015 18:28:18 +0900
changeset 247353 7082d6cfb3718e624d844226c0dbfb89e07ed4dc
parent 247352 09b21b07a540d7c4bf683ed241ec9ca551744772
child 247354 c152e396e9c3592c7fac82ceb946188304bb6f01
push id28864
push userkwierso@gmail.com
push dateFri, 05 Jun 2015 21:49:37 +0000
treeherdermozilla-central@97a39c939c51 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersm_kato
bugs1166436
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 1166436 part.1 Create mozilla::ContentCache and TabParent should store the text to it r=m_kato
dom/ipc/TabParent.cpp
dom/ipc/TabParent.h
widget/ContentCache.cpp
widget/ContentCache.h
widget/WidgetUtils.cpp
widget/moz.build
--- a/dom/ipc/TabParent.cpp
+++ b/dom/ipc/TabParent.cpp
@@ -1901,17 +1901,17 @@ TabParent::RecvNotifyIMEFocus(const bool
   mIMESelectionAnchor = 0;
   mIMESelectionFocus = 0;
   widget->NotifyIME(IMENotification(aFocus ? NOTIFY_IME_OF_FOCUS :
                                              NOTIFY_IME_OF_BLUR));
 
   if (aFocus) {
     *aPreference = widget->GetIMEUpdatePreference();
   } else {
-    mIMECacheText.Truncate(0);
+    mContentCache.Clear();
   }
   return true;
 }
 
 bool
 TabParent::RecvNotifyIMETextChange(const uint32_t& aStart,
                                    const uint32_t& aEnd,
                                    const uint32_t& aNewEnd,
@@ -1993,18 +1993,17 @@ TabParent::RecvNotifyIMESelection(const 
     widget->NotifyIME(notification);
   }
   return true;
 }
 
 bool
 TabParent::RecvNotifyIMETextHint(const nsString& aText)
 {
-  // Replace our cache with new text
-  mIMECacheText = aText;
+  mContentCache.SetText(aText);
   return true;
 }
 
 bool
 TabParent::RecvNotifyIMEMouseButtonEvent(
              const IMENotification& aIMENotification,
              bool* aConsumedByIME)
 {
@@ -2225,46 +2224,46 @@ TabParent::HandleQueryContentEvent(Widge
   switch (aEvent.message)
   {
   case NS_QUERY_SELECTED_TEXT:
     {
       aEvent.mReply.mOffset = std::min(mIMESelectionAnchor, mIMESelectionFocus);
       if (mIMESelectionAnchor == mIMESelectionFocus) {
         aEvent.mReply.mString.Truncate(0);
       } else {
-        if (mIMESelectionAnchor > mIMECacheText.Length() ||
-            mIMESelectionFocus > mIMECacheText.Length()) {
+        if (mIMESelectionAnchor > mContentCache.TextLength() ||
+            mIMESelectionFocus > mContentCache.TextLength()) {
           break;
         }
         uint32_t selLen = mIMESelectionAnchor > mIMESelectionFocus ?
                           mIMESelectionAnchor - mIMESelectionFocus :
                           mIMESelectionFocus - mIMESelectionAnchor;
-        aEvent.mReply.mString = Substring(mIMECacheText,
+        aEvent.mReply.mString = Substring(mContentCache.Text(),
                                           aEvent.mReply.mOffset,
                                           selLen);
       }
       aEvent.mReply.mReversed = mIMESelectionFocus < mIMESelectionAnchor;
       aEvent.mReply.mHasSelection = true;
       aEvent.mReply.mWritingMode = mWritingMode;
       aEvent.mSucceeded = true;
     }
     break;
   case NS_QUERY_TEXT_CONTENT:
     {
       uint32_t inputOffset = aEvent.mInput.mOffset,
                inputEnd = inputOffset + aEvent.mInput.mLength;
 
-      if (inputEnd > mIMECacheText.Length()) {
-        inputEnd = mIMECacheText.Length();
+      if (inputEnd > mContentCache.TextLength()) {
+        inputEnd = mContentCache.TextLength();
       }
       if (inputEnd < inputOffset) {
         break;
       }
       aEvent.mReply.mOffset = inputOffset;
-      aEvent.mReply.mString = Substring(mIMECacheText,
+      aEvent.mReply.mString = Substring(mContentCache.Text(),
                                         inputOffset,
                                         inputEnd - inputOffset);
       aEvent.mSucceeded = true;
     }
     break;
   case NS_QUERY_TEXT_RECT:
     {
       if (aEvent.mInput.mOffset < mIMECompositionRectOffset ||
@@ -2277,20 +2276,20 @@ TabParent::HandleQueryContentEvent(Widge
 
       uint32_t baseOffset = aEvent.mInput.mOffset - mIMECompositionRectOffset;
       uint32_t endOffset = baseOffset + aEvent.mInput.mLength;
       aEvent.mReply.mRect.SetEmpty();
       for (uint32_t i = baseOffset; i < endOffset; i++) {
         aEvent.mReply.mRect =
           aEvent.mReply.mRect.Union(mIMECompositionRects[i]);
       }
-      if (aEvent.mInput.mOffset < mIMECacheText.Length()) {
+      if (aEvent.mInput.mOffset < mContentCache.TextLength()) {
         aEvent.mReply.mString =
-          Substring(mIMECacheText, aEvent.mInput.mOffset,
-                    mIMECacheText.Length() >= aEvent.mInput.EndOffset() ?
+          Substring(mContentCache.Text(), aEvent.mInput.mOffset,
+                    mContentCache.TextLength() >= aEvent.mInput.EndOffset() ?
                       aEvent.mInput.mLength : UINT32_MAX);
       } else {
         aEvent.mReply.mString.Truncate();
       }
       aEvent.mReply.mOffset = aEvent.mInput.mOffset;
       aEvent.mReply.mRect = aEvent.mReply.mRect - GetChildProcessOffset();
       aEvent.mReply.mWritingMode = mWritingMode;
       aEvent.mSucceeded = true;
--- a/dom/ipc/TabParent.h
+++ b/dom/ipc/TabParent.h
@@ -3,16 +3,17 @@
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 #ifndef mozilla_tabs_TabParent_h
 #define mozilla_tabs_TabParent_h
 
 #include "js/TypeDecls.h"
+#include "mozilla/ContentCache.h"
 #include "mozilla/dom/ipc/IdType.h"
 #include "mozilla/dom/PBrowserParent.h"
 #include "mozilla/dom/PFilePickerParent.h"
 #include "mozilla/dom/TabContext.h"
 #include "mozilla/EventForwards.h"
 #include "mozilla/dom/File.h"
 #include "mozilla/WritingModes.h"
 #include "mozilla/RefPtr.h"
@@ -473,17 +474,17 @@ protected:
 
     bool InitBrowserConfiguration(const nsCString& aURI,
                                   BrowserConfiguration& aConfiguration);
 
     void SetHasContentOpener(bool aHasContentOpener);
 
     // IME
     static TabParent *mIMETabParent;
-    nsString mIMECacheText;
+    ContentCache mContentCache;
     uint32_t mIMESelectionAnchor;
     uint32_t mIMESelectionFocus;
     mozilla::WritingMode mWritingMode;
     bool mIMEComposing;
     bool mIMECompositionEnding;
     uint32_t mIMEEventCountAfterEnding;
     // Buffer to store composition text during ResetInputState
     // Compositions in almost all cases are small enough for nsAutoString
new file mode 100644
--- /dev/null
+++ b/widget/ContentCache.cpp
@@ -0,0 +1,24 @@
+/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*-
+ * vim: sw=2 ts=8 et :
+ */
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+#include "mozilla/ContentCache.h"
+
+namespace mozilla {
+
+void
+ContentCache::Clear()
+{
+  mText.Truncate();
+}
+
+void
+ContentCache::SetText(const nsAString& aText)
+{
+  mText = aText;
+}
+
+} // namespace mozilla
new file mode 100644
--- /dev/null
+++ b/widget/ContentCache.h
@@ -0,0 +1,39 @@
+/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*-
+ * vim: sw=2 ts=8 et :
+ */
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+#ifndef mozilla_ContentCache_h
+#define mozilla_ContentCache_h
+
+#include <stdint.h>
+
+#include "nsString.h"
+
+namespace mozilla {
+
+/**
+ * ContentCache stores various information of the child content.  This hides
+ * raw information but you can access more useful information with a lot of
+ * methods.
+ */
+
+class ContentCache final
+{
+public:
+  void Clear();
+
+  void SetText(const nsAString& aText);
+  const nsString& Text() const { return mText; }
+  uint32_t TextLength() const { return mText.Length(); }
+
+private:
+  // Whole text in the target
+  nsString mText;
+};
+
+} // namespace mozilla
+
+#endif // mozilla_ContentCache_h
--- a/widget/WidgetUtils.cpp
+++ b/widget/WidgetUtils.cpp
@@ -88,19 +88,22 @@ nsIntRect RotateRect(nsIntRect aRect,
                        aRect.x,
                        aRect.height, aRect.width);
     default:
       MOZ_CRASH("Unknown rotation");
       return aRect;
   }
 }
 
+namespace widget {
+
 uint32_t
 WidgetUtils::IsTouchDeviceSupportPresent()
 {
 #ifdef XP_WIN
   return WinUtils::IsTouchDeviceSupportPresent();
 #else
   return 0;
 #endif
 }
 
+} // namespace widget
 } // namespace mozilla
--- a/widget/moz.build
+++ b/widget/moz.build
@@ -104,16 +104,17 @@ EXPORTS += [
     'nsWidgetsCID.h',
     'PluginWidgetProxy.h',
     'PuppetWidget.h',
 ]
 
 EXPORTS.mozilla += [
     'BasicEvents.h',
     'CommandList.h',
+    'ContentCache.h',
     'ContentEvents.h',
     'EventClassList.h',
     'EventForwards.h',
     'FontRange.h',
     'LookAndFeel.h',
     'MiscEvents.h',
     'MouseEvents.h',
     'TextEventDispatcher.h',
@@ -126,16 +127,17 @@ EXPORTS.mozilla += [
 ]
 
 EXPORTS.mozilla.widget += [
     'PuppetBidiKeyboard.h',
     'WidgetMessageUtils.h',
 ]
 
 UNIFIED_SOURCES += [
+    'ContentCache.cpp',
     'ContentHelper.cpp',
     'GfxDriverInfo.cpp',
     'GfxInfoBase.cpp',
     'GfxInfoCollector.cpp',
     'GfxInfoWebGL.cpp',
     'InputData.cpp',
     'nsBaseAppShell.cpp',
     'nsBaseDragService.cpp',