Bug 987718 - Part 1: Add FirstAndLastRectCollector to nsLayoutUtils; r=roc
authorMorris Tseng <mtseng@mozilla.com>
Wed, 04 Jun 2014 22:53:00 +0200
changeset 206049 9928bd00f32c7655f390d0299302b4b8cfdbb962
parent 206048 ffcfc25479e9ee569cafba3978c2b02b2070f9a8
child 206050 83bdc6425e06708a45c86af1544c4df3d9ec5953
push id3741
push userasasaki@mozilla.com
push dateMon, 21 Jul 2014 20:25:18 +0000
treeherdermozilla-beta@4d6f46f5af68 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersroc
bugs987718
milestone32.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 987718 - Part 1: Add FirstAndLastRectCollector to nsLayoutUtils; r=roc
layout/base/nsLayoutUtils.cpp
layout/base/nsLayoutUtils.h
--- a/layout/base/nsLayoutUtils.cpp
+++ b/layout/base/nsLayoutUtils.cpp
@@ -3226,16 +3226,30 @@ nsLayoutUtils::RectListBuilder::RectList
 
 void nsLayoutUtils::RectListBuilder::AddRect(const nsRect& aRect) {
   nsRefPtr<DOMRect> rect = new DOMRect(mRectList);
 
   rect->SetLayoutRect(aRect);
   mRectList->Append(rect);
 }
 
+nsLayoutUtils::FirstAndLastRectCollector::FirstAndLastRectCollector()
+  : mSeenFirstRect(false)
+{
+}
+
+void nsLayoutUtils::FirstAndLastRectCollector::AddRect(const nsRect& aRect) {
+  if (!mSeenFirstRect) {
+    mSeenFirstRect = true;
+    mFirstRect = aRect;
+  }
+
+  mLastRect = aRect;
+}
+
 nsIFrame* nsLayoutUtils::GetContainingBlockForClientRect(nsIFrame* aFrame)
 {
   return aFrame->PresContext()->PresShell()->GetRootFrame();
 }
 
 nsRect
 nsLayoutUtils::GetAllInFlowRectsUnion(nsIFrame* aFrame, nsIFrame* aRelativeTo,
                                       uint32_t aFlags) {
--- a/layout/base/nsLayoutUtils.h
+++ b/layout/base/nsLayoutUtils.h
@@ -1004,16 +1004,31 @@ public:
 
   struct RectListBuilder : public RectCallback {
     DOMRectList* mRectList;
 
     RectListBuilder(DOMRectList* aList);
     virtual void AddRect(const nsRect& aRect);
   };
 
+  /**
+   * SelectionCaret draws carets base on range. The carets are at begin
+   * and end position of range's client rects. This class help us to
+   * collect first and last rect for drawing carets.
+   */
+  struct FirstAndLastRectCollector : public RectCallback {
+    nsRect mFirstRect;
+    nsRect mLastRect;
+    bool mSeenFirstRect;
+
+    FirstAndLastRectCollector();
+
+    virtual void AddRect(const nsRect& aRect);
+  };
+
   static nsIFrame* GetContainingBlockForClientRect(nsIFrame* aFrame);
 
   enum {
     RECTS_ACCOUNT_FOR_TRANSFORMS = 0x01,
     // Two bits for specifying which box type to use.
     // With neither bit set (default), use the border box.
     RECTS_USE_CONTENT_BOX = 0x02,
     RECTS_USE_PADDING_BOX = 0x04,