Bug 1166436 part.11 Remove unnecessary public methods of mozilla::ContentCache r=m_kato
authorMasayuki Nakano <masayuki@d-toybox.com>
Fri, 05 Jun 2015 18:28:20 +0900
changeset 247326 c8afeac76c0e0a82e709d9ef0672a37396b74341
parent 247325 d813014e797c44abbf39b10e11dbbb632ef1ae27
child 247327 6ee382b70183f82318b2fd5d3966f87e2fc09ee4
push id60677
push usermasayuki@d-toybox.com
push dateFri, 05 Jun 2015 09:28:37 +0000
treeherdermozilla-inbound@cbaeacbb9700 [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.11 Remove unnecessary public methods of mozilla::ContentCache r=m_kato
dom/ipc/TabParent.cpp
widget/ContentCache.cpp
widget/ContentCache.h
--- a/dom/ipc/TabParent.cpp
+++ b/dom/ipc/TabParent.cpp
@@ -1957,26 +1957,17 @@ TabParent::RecvNotifyIMESelection(const 
 
   mContentCache.AssignContent(aContentCache);
 
   const nsIMEUpdatePreference updatePreference =
     widget->GetIMEUpdatePreference();
   if (updatePreference.WantSelectionChange() &&
       (updatePreference.WantChangesCausedByComposition() ||
        !aCausedByComposition)) {
-    IMENotification notification(NOTIFY_IME_OF_SELECTION_CHANGE);
-    notification.mSelectionChangeData.mOffset = mContentCache.SelectionStart();
-    notification.mSelectionChangeData.mLength = mContentCache.SelectionLength();
-    notification.mSelectionChangeData.mReversed =
-      mContentCache.SelectionReversed();
-    notification.mSelectionChangeData.SetWritingMode(
-      mContentCache.SelectionWritingMode());
-    notification.mSelectionChangeData.mCausedByComposition =
-      aCausedByComposition;
-    widget->NotifyIME(notification);
+    mContentCache.NotifyIMEOfSelectionChange(widget, aCausedByComposition);
   }
   return true;
 }
 
 bool
 TabParent::RecvUpdateContentCache(const ContentCache& aContentCache)
 {
   nsCOMPtr<nsIWidget> widget = GetWidget();
@@ -2207,20 +2198,17 @@ bool
 TabParent::SendSelectionEvent(WidgetSelectionEvent& event)
 {
   if (mIsDestroyed) {
     return false;
   }
   // XXX The writing mode is wrong, but this should cause a call of
   //     RecvNotifyIMESelection().  If so, why do we need to modify the range
   //     here??
-  mContentCache.SetSelection(
-    event.mOffset + (event.mReversed ? event.mLength : 0),
-    event.mOffset + (!event.mReversed ? event.mLength : 0),
-    mContentCache.SelectionWritingMode());
+  mContentCache.SetSelection(event.mOffset, event.mLength, event.mReversed);
   return PBrowserParent::SendSelectionEvent(event);
 }
 
 /*static*/ TabParent*
 TabParent::GetFrom(nsFrameLoader* aFrameLoader)
 {
   if (!aFrameLoader) {
     return nullptr;
--- a/widget/ContentCache.cpp
+++ b/widget/ContentCache.cpp
@@ -50,17 +50,17 @@ ContentCache::HandleQueryContentEvent(Wi
   aEvent.mReply.mFocusedWidget = aWidget;
 
   switch (aEvent.message) {
     case NS_QUERY_SELECTED_TEXT:
       aEvent.mReply.mOffset = mSelection.StartOffset();
       if (mSelection.Collapsed()) {
         aEvent.mReply.mString.Truncate(0);
       } else {
-        if (NS_WARN_IF(SelectionEndIsGraterThanTextLength())) {
+        if (NS_WARN_IF(mSelection.EndOffset() > mText.Length())) {
           return false;
         }
         aEvent.mReply.mString =
           Substring(mText, aEvent.mReply.mOffset, mSelection.Length());
       }
       aEvent.mReply.mReversed = mSelection.Reversed();
       aEvent.mReply.mHasSelection = true;
       aEvent.mReply.mWritingMode = mSelection.mWritingMode;
@@ -204,20 +204,20 @@ ContentCache::CacheText(nsIWidget* aWidg
     return false;
   }
 
   nsEventStatus status = nsEventStatus_eIgnore;
   WidgetQueryContentEvent queryText(true, NS_QUERY_TEXT_CONTENT, aWidget);
   queryText.InitForQueryTextContent(0, UINT32_MAX);
   aWidget->DispatchEvent(&queryText, status);
   if (NS_WARN_IF(!queryText.mSucceeded)) {
-    SetText(EmptyString());
+    mText.Truncate();
     return false;
   }
-  SetText(queryText.mReply.mString);
+  mText = queryText.mReply.mString;
   return true;
 }
 
 bool
 ContentCache::CacheTextRects(nsIWidget* aWidget)
 {
   // CacheTextRects() must be called in content process.
   if (NS_WARN_IF(mIsChrome)) {
@@ -246,22 +246,16 @@ ContentCache::CacheTextRects(nsIWidget* 
       return false;
     }
     mTextRectArray.mRects.AppendElement(textRect.mReply.mRect);
   }
   return true;
 }
 
 void
-ContentCache::SetText(const nsAString& aText)
-{
-  mText = aText;
-}
-
-void
 ContentCache::SetSelection(uint32_t aStartOffset,
                            uint32_t aLength,
                            bool aReversed,
                            const WritingMode& aWritingMode)
 {
   if (!aReversed) {
     mSelection.mAnchor = aStartOffset;
     mSelection.mFocus = aStartOffset + aLength;
@@ -278,29 +272,16 @@ ContentCache::SetSelection(uint32_t aAnc
                            const WritingMode& aWritingMode)
 {
   mSelection.mAnchor = aAnchorOffset;
   mSelection.mFocus = aFocusOffset;
   mSelection.mWritingMode = aWritingMode;
 }
 
 bool
-ContentCache::InitTextRectArray(uint32_t aOffset,
-                                const RectArray& aTextRectArray)
-{
-  if (NS_WARN_IF(aOffset >= TextLength()) ||
-      NS_WARN_IF(aOffset + aTextRectArray.Length() > TextLength())) {
-    return false;
-  }
-  mTextRectArray.mStart = aOffset;
-  mTextRectArray.mRects = aTextRectArray;
-  return true;
-}
-
-bool
 ContentCache::GetTextRect(uint32_t aOffset,
                           LayoutDeviceIntRect& aTextRect) const
 {
   if (NS_WARN_IF(!mTextRectArray.InRange(aOffset))) {
     aTextRect.SetEmpty();
     return false;
   }
   aTextRect = mTextRectArray.GetRect(aOffset);
@@ -316,28 +297,16 @@ ContentCache::GetUnionTextRects(uint32_t
     aUnionTextRect.SetEmpty();
     return false;
   }
   aUnionTextRect = mTextRectArray.GetUnionRect(aOffset, aLength);
   return true;
 }
 
 bool
-ContentCache::InitCaretRect(uint32_t aOffset,
-                            const LayoutDeviceIntRect& aCaretRect)
-{
-  if (NS_WARN_IF(aOffset > TextLength())) {
-    return false;
-  }
-  mCaret.mOffset = aOffset;
-  mCaret.mRect = aCaretRect;
-  return true;
-}
-
-bool
 ContentCache::GetCaretRect(uint32_t aOffset,
                            LayoutDeviceIntRect& aCaretRect) const
 {
   if (mCaret.mOffset != aOffset) {
     aCaretRect.SetEmpty();
     return false;
   }
   aCaretRect = mCaret.mRect;
@@ -345,17 +314,17 @@ ContentCache::GetCaretRect(uint32_t aOff
 }
 
 bool
 ContentCache::OnCompositionEvent(const WidgetCompositionEvent& aEvent)
 {
   if (!aEvent.CausesDOMTextEvent()) {
     MOZ_ASSERT(aEvent.message == NS_COMPOSITION_START);
     mIsComposing = !aEvent.CausesDOMCompositionEndEvent();
-    mCompositionStart = SelectionStart();
+    mCompositionStart = mSelection.StartOffset();
     // XXX What's this case??
     if (mRequestedToCommitOrCancelComposition) {
       mCommitStringByRequest = aEvent.mData;
       mCompositionEventsDuringRequest++;
       return false;
     }
     return true;
   }
@@ -373,17 +342,17 @@ ContentCache::OnCompositionEvent(const W
     mCommitStringByRequest = aEvent.mData;
     mCompositionEventsDuringRequest++;
     return false;
   }
 
   // We must be able to simulate the selection because
   // we might not receive selection updates in time
   if (!mIsComposing) {
-    mCompositionStart = SelectionStart();
+    mCompositionStart = mSelection.StartOffset();
   }
   // XXX This causes different behavior from non-e10s mode.
   //     Selection range should represent caret position in the composition
   //     string but this means selection range is all of the composition string.
   SetSelection(mCompositionStart + aEvent.mData.Length(),
                mSelection.mWritingMode);
   mIsComposing = !aEvent.CausesDOMCompositionEndEvent();
   return true;
@@ -401,16 +370,30 @@ ContentCache::RequestToCommitComposition
                                                REQUEST_TO_COMMIT_COMPOSITION));
 
   mRequestedToCommitOrCancelComposition = false;
   aLastString = mCommitStringByRequest;
   mCommitStringByRequest.Truncate(0);
   return mCompositionEventsDuringRequest;
 }
 
+void
+ContentCache::NotifyIMEOfSelectionChange(nsIWidget* aWidget,
+                                         bool aCausedByComposition) const
+{
+  IMENotification notification(NOTIFY_IME_OF_SELECTION_CHANGE);
+  notification.mSelectionChangeData.mOffset = mSelection.StartOffset();
+  notification.mSelectionChangeData.mLength = mSelection.Length();
+  notification.mSelectionChangeData.mReversed = mSelection.Reversed();
+  notification.mSelectionChangeData.SetWritingMode(mSelection.mWritingMode);
+  notification.mSelectionChangeData.mCausedByComposition =
+    aCausedByComposition;
+  aWidget->NotifyIME(notification);
+}
+
 /*****************************************************************************
  * mozilla::ContentCache::TextRectArray
  *****************************************************************************/
 
 LayoutDeviceIntRect
 ContentCache::TextRectArray::GetRect(uint32_t aOffset) const
 {
   LayoutDeviceIntRect rect;
--- a/widget/ContentCache.h
+++ b/widget/ContentCache.h
@@ -79,20 +79,16 @@ public:
    */
   bool CacheEditorRect(nsIWidget* aWidget);
   bool CacheSelection(nsIWidget* aWidget);
   bool CacheText(nsIWidget* aWidget);
   bool CacheTextRects(nsIWidget* aWidget);
 
   bool CacheAll(nsIWidget* aWidget);
 
-  void SetText(const nsAString& aText);
-  const nsString& Text() const { return mText; }
-  uint32_t TextLength() const { return mText.Length(); }
-
   /**
    * OnCompositionEvent() should be called before sending composition string.
    * This returns true if the event should be sent.  Otherwise, false.
    */
   bool OnCompositionEvent(const WidgetCompositionEvent& aCompositionEvent);
   /**
    * RequestToCommitComposition() requests to commit or cancel composition to
    * the widget.  If it's handled synchronously, this returns the number of
@@ -106,68 +102,44 @@ public:
    *                    commit or cancel composition.
    * @return            The count of composition events ignored after a call of
    *                    WillRequestToCommitOrCancelComposition().
    */
   uint32_t RequestToCommitComposition(nsIWidget* aWidget,
                                       bool aCancel,
                                       nsAString& aLastString);
 
+  /**
+   * NotifyIMEOfSelectionChange() notifies IME of selection change with
+   * storing selection range.
+   *
+   * @param aWidget                 A widget to notify IME of the notification.
+   * @param aCausedByComposition    true if the change is caused by composition.
+   *                                Otherwise, false.
+   */
+  void NotifyIMEOfSelectionChange(nsIWidget* aWidget,
+                                  bool aCausedByComposition) const;
+
   void SetSelection(uint32_t aCaretOffset, const WritingMode& aWritingMode)
   {
     SetSelection(aCaretOffset, aCaretOffset, aWritingMode);
   }
   void SetSelection(uint32_t aStartOffset,
                     uint32_t aLength,
+                    bool aReversed)
+  {
+    SetSelection(aStartOffset, aLength, aReversed, mSelection.mWritingMode);
+  }
+  void SetSelection(uint32_t aStartOffset,
+                    uint32_t aLength,
                     bool aReversed,
                     const WritingMode& aWritingMode);
   void SetSelection(uint32_t aAnchorOffset,
                     uint32_t aFocusOffset,
                     const WritingMode& aWritingMode);
-  bool SelectionCollapsed() const { return mSelection.Collapsed(); }
-  bool SelectionReversed() const { return mSelection.Reversed(); }
-  bool SelectionEndIsGraterThanTextLength() const
-  {
-    return SelectionEnd() > TextLength();
-  }
-  uint32_t SelectionAnchor() const { return mSelection.mAnchor; }
-  uint32_t SelectionFocus() const { return mSelection.mFocus; }
-  uint32_t SelectionStart() const { return mSelection.StartOffset(); }
-  uint32_t SelectionEnd() const { return mSelection.EndOffset(); }
-  uint32_t SelectionLength() const { return mSelection.Length(); }
-
-  const WritingMode& SelectionWritingMode() const
-  {
-    return mSelection.mWritingMode;
-  }
-
-  bool UpdateTextRectArray(const RectArray& aTextRectArray)
-  {
-    return InitTextRectArray(mTextRectArray.mStart, aTextRectArray);
-  }
-  bool InitTextRectArray(uint32_t aOffset, const RectArray& aTextRectArray);
-  bool GetTextRect(uint32_t aOffset,
-                   LayoutDeviceIntRect& aTextRect) const;
-  bool GetUnionTextRects(uint32_t aOffset,
-                         uint32_t aLength,
-                         LayoutDeviceIntRect& aUnionTextRect) const;
-
-  bool UpdateCaretRect(const LayoutDeviceIntRect& aCaretRect)
-  {
-    return InitCaretRect(mCaret.mOffset, aCaretRect);
-  }
-  bool InitCaretRect(uint32_t aOffset, const LayoutDeviceIntRect& aCaretRect);
-  uint32_t CaretOffset() const { return mCaret.mOffset; }
-  bool GetCaretRect(uint32_t aOffset, LayoutDeviceIntRect& aCaretRect) const;
-
-  void SetEditorRect(const LayoutDeviceIntRect& aEditorRect)
-  {
-    mEditorRect = aEditorRect;
-  }
-  const LayoutDeviceIntRect& GetEditorRect() const { return mEditorRect; }
 
 private:
   // Whole text in the target
   nsString mText;
   // This is commit string which is caused by our request.
   nsString mCommitStringByRequest;
   // Start offset of the composition string.
   uint32_t mCompositionStart;
@@ -275,14 +247,21 @@ private:
   } mTextRectArray;
 
   LayoutDeviceIntRect mEditorRect;
 
   bool mIsComposing;
   bool mRequestedToCommitOrCancelComposition;
   bool mIsChrome;
 
+  bool GetCaretRect(uint32_t aOffset, LayoutDeviceIntRect& aCaretRect) const;
+  bool GetTextRect(uint32_t aOffset,
+                   LayoutDeviceIntRect& aTextRect) const;
+  bool GetUnionTextRects(uint32_t aOffset,
+                         uint32_t aLength,
+                         LayoutDeviceIntRect& aUnionTextRect) const;
+
   friend struct IPC::ParamTraits<ContentCache>;
 };
 
 } // namespace mozilla
 
 #endif // mozilla_ContentCache_h