Bug 1471174 - Constify nsIFrame::IsScrolledOutOfView. r?birtles draft
authorHiroyuki Ikezoe <hikezoe@mozilla.com>
Wed, 27 Jun 2018 09:08:36 +0900
changeset 811147 bdd7029aac5c12d3030b6e6290e74fd3ade9e0fb
parent 811103 1c235a552c32ba6c97e6030c497c49f72c7d48a8
child 811148 e6fc4b8df4dba8839d041cbd943bbc252d24a335
push id114204
push userhikezoe@mozilla.com
push dateWed, 27 Jun 2018 00:44:53 +0000
reviewersbirtles
bugs1471174
milestone63.0a1
Bug 1471174 - Constify nsIFrame::IsScrolledOutOfView. r?birtles The reason why const_cast is used for nsLayoutUtils::GetNearestScrollableFrame is that if we changed the function as well, it ends up scattering const_cast in most call sites of the function. That's because GetNearestScrollableFrame has a do_QueryFrame call for the given nsIFrame* and returns the queried frame, so it will be like this; const nsIScrollableFrame* GetNearestScrollableFrame(const nsIFrame*, ..) Most call sites of this function are then calls do_QueryFrame for the returned nsIScrollableFrame*. MozReview-Commit-ID: EwccKUITL89
layout/generic/nsFrame.cpp
layout/generic/nsIFrame.h
--- a/layout/generic/nsFrame.cpp
+++ b/layout/generic/nsFrame.cpp
@@ -10954,22 +10954,22 @@ nsIFrame::IsStackingContext()
   const nsStyleDisplay* disp = StyleDisplay();
   const bool isPositioned = disp->IsAbsPosContainingBlock(this);
   return IsStackingContext(EffectSet::GetEffectSet(this), disp,
                            StylePosition(), StyleEffects(),
                            isPositioned);
 }
 
 static bool
-IsFrameScrolledOutOfView(nsIFrame* aTarget,
+IsFrameScrolledOutOfView(const nsIFrame* aTarget,
                          const nsRect& aTargetRect,
-                         nsIFrame* aParent)
+                         const nsIFrame* aParent)
 {
   nsIScrollableFrame* scrollableFrame =
-    nsLayoutUtils::GetNearestScrollableFrame(aParent,
+    nsLayoutUtils::GetNearestScrollableFrame(const_cast<nsIFrame*>(aParent),
       nsLayoutUtils::SCROLLABLE_SAME_DOC |
       nsLayoutUtils::SCROLLABLE_FIXEDPOS_FINDS_ROOT |
       nsLayoutUtils::SCROLLABLE_INCLUDE_HIDDEN);
   if (!scrollableFrame) {
     return false;
   }
 
   nsIFrame *scrollableParent = do_QueryFrame(scrollableFrame);
@@ -11003,17 +11003,17 @@ IsFrameScrolledOutOfView(nsIFrame* aTarg
   if (!parent) {
     return false;
   }
 
   return IsFrameScrolledOutOfView(aTarget, aTargetRect, parent);
 }
 
 bool
-nsIFrame::IsScrolledOutOfView()
+nsIFrame::IsScrolledOutOfView() const
 {
   nsRect rect = GetVisualOverflowRectRelativeToSelf();
   return IsFrameScrolledOutOfView(this, rect, this);
 }
 
 gfx::Matrix
 nsIFrame::ComputeWidgetTransform()
 {
--- a/layout/generic/nsIFrame.h
+++ b/layout/generic/nsIFrame.h
@@ -4011,17 +4011,17 @@ public:
   }
   bool BackfaceIsHidden() const {
     return StyleDisplay()->BackfaceIsHidden();
   }
 
   /**
    * Returns true if the frame is scrolled out of view.
    */
-  bool IsScrolledOutOfView();
+  bool IsScrolledOutOfView() const;
 
   /**
    * Computes a 2D matrix from the -moz-window-transform and
    * -moz-window-transform-origin properties on aFrame.
    * Values that don't result in a 2D matrix will be ignored and an identity
    * matrix will be returned instead.
    */
   Matrix ComputeWidgetTransform();