Bug 1055342 part.2 Implement nsTextStore::GetCurrentText() for retrieving current text content even without document lock r=emk
authorMasayuki Nakano <masayuki@d-toybox.com>
Sat, 23 Aug 2014 23:24:42 +0900
changeset 201219 8a7771c44e38058c9ac51d9390b823a3c23b7350
parent 201218 a180dbeebe4fbb6d3d131bbe54c5f8297f781740
child 201220 4cfdd3fe42f4a2b8b07a06afd656a33248c16bba
push id48112
push usermasayuki@d-toybox.com
push dateSat, 23 Aug 2014 14:24:53 +0000
treeherdermozilla-inbound@8a7771c44e38 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersemk
bugs1055342
milestone34.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 1055342 part.2 Implement nsTextStore::GetCurrentText() for retrieving current text content even without document lock r=emk
widget/windows/nsTextStore.cpp
widget/windows/nsTextStore.h
--- a/widget/windows/nsTextStore.cpp
+++ b/widget/windows/nsTextStore.cpp
@@ -1421,35 +1421,56 @@ nsTextStore::LockedContent()
 
   Selection& currentSel = CurrentSelection();
   if (currentSel.IsDirty()) {
     mLockedContent.Clear();
     return mLockedContent;
   }
 
   if (!mLockedContent.IsInitialized()) {
-    MOZ_ASSERT(mWidget && !mWidget->Destroyed());
-
-    WidgetQueryContentEvent queryText(true, NS_QUERY_TEXT_CONTENT, mWidget);
-    queryText.InitForQueryTextContent(0, UINT32_MAX);
-    mWidget->InitEvent(queryText);
-    mWidget->DispatchWindowEvent(&queryText);
-    NS_ENSURE_TRUE(queryText.mSucceeded, mLockedContent);
-
-    mLockedContent.Init(queryText.mReply.mString);
+    nsAutoString text;
+    if (NS_WARN_IF(!GetCurrentText(text))) {
+      mLockedContent.Clear();
+      return mLockedContent;
+    }
+
+    mLockedContent.Init(text);
   }
 
   PR_LOG(sTextStoreLog, PR_LOG_DEBUG,
          ("TSF: 0x%p   nsTextStore::LockedContent(): "
           "mLockedContent={ mText.Length()=%d }",
           this, mLockedContent.Text().Length()));
 
   return mLockedContent;
 }
 
+bool
+nsTextStore::GetCurrentText(nsAString& aTextContent)
+{
+  if (mLockedContent.IsInitialized()) {
+    aTextContent = mLockedContent.Text();
+    return true;
+  }
+
+  MOZ_ASSERT(mWidget && !mWidget->Destroyed());
+
+  WidgetQueryContentEvent queryText(true, NS_QUERY_TEXT_CONTENT, mWidget);
+  queryText.InitForQueryTextContent(0, UINT32_MAX);
+  mWidget->InitEvent(queryText);
+  mWidget->DispatchWindowEvent(&queryText);
+  if (NS_WARN_IF(!queryText.mSucceeded)) {
+    aTextContent.Truncate();
+    return false;
+  }
+
+  aTextContent = queryText.mReply.mString;
+  return true;
+}
+
 nsTextStore::Selection&
 nsTextStore::CurrentSelection()
 {
   if (mSelection.IsDirty()) {
     // If the window has never been available, we should crash since working
     // with broken values may make TIP confused.
     if (!mWidget || mWidget->Destroyed()) {
       MOZ_CRASH();
--- a/widget/windows/nsTextStore.h
+++ b/widget/windows/nsTextStore.h
@@ -659,16 +659,20 @@ protected:
   // we need to reduce the memory usage.  This is initialized by
   // LockedContent() automatically.  So, don't access this member directly
   // except at calling Clear(), IsInitialized(), IsLayoutChangedAfter() or
   // IsLayoutChanged().
   Content mLockedContent;
 
   Content& LockedContent();
 
+  // While the documet is locked, this returns the text stored by
+  // mLockedContent.  Otherwise, return the current text content.
+  bool GetCurrentText(nsAString& aTextContent);
+
   // The input scopes for this context, defaults to IS_DEFAULT.
   nsTArray<InputScope>         mInputScopes;
 
   // Support retrieving attributes.
   // TODO: We should support RightToLeft, perhaps.
   enum
   {
     // Used for result of GetRequestedAttrIndex()