Bug 1269017 part 2 - [css-grid] Give grid an implementation of CSSAlignmentForAbsPosChild(). r=mats
authorDaniel Holbert <dholbert@cs.stanford.edu>
Tue, 08 Nov 2016 16:30:00 -0800
changeset 351832 5e6f0bf39062d35752108049fb4b70cc5732f2bd
parent 351831 5795b76480b60724e3fc5e703d8f0848a88dad13
child 351833 ab70dc086596dc45abba729112247a7b6c684b57
push id6795
push userjlund@mozilla.com
push dateMon, 23 Jan 2017 14:19:46 +0000
treeherdermozilla-esr52@76101b503191 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmats
bugs1269017
milestone52.0a1
Bug 1269017 part 2 - [css-grid] Give grid an implementation of CSSAlignmentForAbsPosChild(). r=mats This grid implementation is similar to the one on nsFlexContainerFrame, with a few simplifications: - We can simply use the LogicalAxis to decide between align-* vs justify-* prpoerties (whereas flexbox has extra abstraction from the flex axes). - We don't have to bother with "align-content" or "justify-content", since those apply to grid areas rather than to children. (And any grid area that's involved will be sized/positioned separately.) - Grid can unconditionally treat "flex-start" & "flex-end" as "start" & "end". MozReview-Commit-ID: 9l1Wq9Cq5T0
layout/generic/nsGridContainerFrame.cpp
layout/generic/nsGridContainerFrame.h
--- a/layout/generic/nsGridContainerFrame.cpp
+++ b/layout/generic/nsGridContainerFrame.cpp
@@ -6627,16 +6627,68 @@ nsGridContainerFrame::RemoveFrame(ChildL
         frameThatMayLie->GetPrevInFlow());
     } while (frameThatMayLie);
   }
 #endif
 
   nsContainerFrame::RemoveFrame(aListID, aOldFrame);
 }
 
+uint16_t
+nsGridContainerFrame::CSSAlignmentForAbsPosChild(const ReflowInput& aChildRI,
+                                                 LogicalAxis aLogicalAxis) const
+{
+  MOZ_ASSERT(aChildRI.mFrame->IsAbsolutelyPositioned(),
+             "This method should only be called for abspos children");
+
+  uint16_t alignment = (aLogicalAxis == eLogicalAxisInline) ?
+    aChildRI.mStylePosition->UsedJustifySelf(nullptr) :
+    aChildRI.mStylePosition->UsedAlignSelf(nullptr);
+
+  // XXX strip off <overflow-position> bits until we implement it
+  // (bug 1311892)
+  alignment &= ~NS_STYLE_ALIGN_FLAG_BITS;
+
+  // We group 'auto' with 'normal', because the spec says:
+  //    "The 'auto' keyword is interpreted as 'normal'
+  //     if the box is absolutely positioned [...]"
+  // https://drafts.csswg.org/css-align-3/#valdef-align-self-auto
+  // https://drafts.csswg.org/css-align-3/#valdef-justify-self-auto
+  if (alignment == NS_STYLE_ALIGN_AUTO ||
+      alignment == NS_STYLE_ALIGN_NORMAL) {
+    // "the 'normal' keyword behaves as 'start' on replaced
+    // absolutely-positioned boxes, and behaves as 'stretch' on all other
+    // absolutely-positioned boxes."
+    // https://drafts.csswg.org/css-align/#align-abspos
+    // https://drafts.csswg.org/css-align/#justify-abspos
+    alignment = aChildRI.mFrame->IsFrameOfType(nsIFrame::eReplaced) ?
+      NS_STYLE_ALIGN_START : NS_STYLE_ALIGN_STRETCH;
+  } else if (alignment == NS_STYLE_ALIGN_FLEX_START) {
+    alignment = NS_STYLE_ALIGN_START;
+  } else if (alignment == NS_STYLE_ALIGN_FLEX_END) {
+    alignment = NS_STYLE_ALIGN_END;
+  } else if (alignment == NS_STYLE_ALIGN_LEFT ||
+             alignment == NS_STYLE_ALIGN_RIGHT) {
+    if (aLogicalAxis == eLogicalAxisInline) {
+      const bool isLeft = (alignment == NS_STYLE_ALIGN_LEFT);
+      WritingMode wm = GetWritingMode();
+      alignment = (isLeft == wm.IsBidiLTR()) ? NS_STYLE_ALIGN_START
+                                             : NS_STYLE_ALIGN_END;
+    } else {
+      alignment = NS_STYLE_ALIGN_START;
+    }
+  } else if (alignment == NS_STYLE_ALIGN_BASELINE) {
+    alignment = NS_STYLE_ALIGN_START;
+  } else if (alignment == NS_STYLE_ALIGN_LAST_BASELINE) {
+    alignment = NS_STYLE_ALIGN_END;
+  }
+
+  return alignment;
+}
+
 nscoord
 nsGridContainerFrame::SynthesizeBaseline(
   const FindItemInGridOrderResult& aGridOrderItem,
   LogicalAxis          aAxis,
   BaselineSharingGroup aGroup,
   const nsSize&        aCBPhysicalSize,
   nscoord              aCBSize,
   WritingMode          aCBWM)
--- a/layout/generic/nsGridContainerFrame.h
+++ b/layout/generic/nsGridContainerFrame.h
@@ -121,16 +121,19 @@ public:
 #endif
 
   // nsContainerFrame overrides
   bool DrainSelfOverflowList() override;
   void AppendFrames(ChildListID aListID, nsFrameList& aFrameList) override;
   void InsertFrames(ChildListID aListID, nsIFrame* aPrevFrame,
                     nsFrameList& aFrameList) override;
   void RemoveFrame(ChildListID aListID, nsIFrame* aOldFrame) override;
+  uint16_t CSSAlignmentForAbsPosChild(
+            const ReflowInput& aChildRI,
+            mozilla::LogicalAxis aLogicalAxis) const override;
 
 #ifdef DEBUG
   void SetInitialChildList(ChildListID  aListID,
                            nsFrameList& aChildList) override;
 #endif
 
   /**
    * Return the containing block for aChild which MUST be an abs.pos. child