Give captions the right style context parent when dynamically restyling. Bug378240, r=bernd, sr=dbaron
authorbzbarsky@mit.edu
Sun, 22 Apr 2007 12:15:24 -0700
changeset 706 e5b5a0cc1d5ec8baf9cfa4a57120d7604b7dd06c
parent 705 65e4979062c4ab95224d746eaefb84664ea15107
child 707 b0d73580fb9df99e11d938fdbb0d83c984c39eff
push idunknown
push userunknown
push dateunknown
reviewersbernd, dbaron
bugs378240
milestone1.9a4pre
Give captions the right style context parent when dynamically restyling. Bug378240, r=bernd, sr=dbaron
layout/reftests/bugs/323656-6-ref.html
layout/reftests/bugs/323656-6.html
layout/reftests/bugs/reftest.list
layout/tables/nsTableOuterFrame.cpp
layout/tables/nsTableOuterFrame.h
new file mode 100644
--- /dev/null
+++ b/layout/reftests/bugs/323656-6-ref.html
@@ -0,0 +1,40 @@
+<!DOCTYPE html>
+<html>
+  <head>
+    <title>Test inheritance into captions</title>
+    <style>
+      /**
+       * The idea is that "color" inherits by default while "border-color" does
+       * not.  So if the former is red and the latter is green on a parent, and
+       * the child's border-color is set to "inherit", it'll be green only if
+       * the child is inheriting from the parent.  If not, it'll either be
+       * whatever the border-color is on what it's inheriting from, which will
+       * be red if what it's inheriting from has the default (currentColor)
+       * border-color).
+       */
+      
+      /* 't' for "test" */
+      * { color: red; border: 0px hidden red; background: transparent }
+      .t, .t2 { border-color: green }
+      .t > :first-child
+        { border-color: green; border-style: solid; border-width: 10px }
+      .t2 > :first-child
+        { border-style: solid; border-width: 10px }
+      .t2 > .test 
+        { border-color: green }
+    </style>
+  </head>
+  <body>
+    <table class="t"><caption></caption></table>
+
+    <table class="t2 d2"><caption class="test"></caption></table>
+
+    <table class="t d"><caption></caption></table>
+    <table class="t d"><caption></caption></table>
+    <table class="t d"><caption></caption></table>
+
+    <table class="t2 d d2"><caption class="test"></caption></table>
+    <table class="t2 d d2"><caption class="test"></caption></table>
+    <table class="t2 d d2"><caption class="test"></caption></table>
+    </body>
+</html>
new file mode 100644
--- /dev/null
+++ b/layout/reftests/bugs/323656-6.html
@@ -0,0 +1,57 @@
+<!DOCTYPE html>
+<html>
+  <head>
+    <title>Test inheritance into captions</title>
+    <style>
+      /**
+       * The idea is that "color" inherits by default while "border-color" does
+       * not.  So if the former is red and the latter is green on a parent, and
+       * the child's border-color is set to "inherit", it'll be green only if
+       * the child is inheriting from the parent.  If not, it'll either be
+       * whatever the border-color is on what it's inheriting from, which will
+       * be red if what it's inheriting from has the default (currentColor)
+       * border-color).
+       */
+      
+      /* 't' for "test" */
+      * { color: red; border: 0px hidden red; background: transparent }
+      .t, .t2 { border-color: green }
+      .t > caption
+        { border-color: inherit; border-style: solid; border-width: 10px }
+      .t2 > caption
+        { border-style: solid; border-width: 10px }
+      .t2 > caption.test 
+        { border-color: inherit }
+    </style>
+    <script>
+      function makeCaption() {
+        return document.createElement("caption");
+      }
+
+      window.onload = function() {
+        var lst = document.getElementsByClassName("d");
+        for (var i = 0; i < lst.length; ++i) {
+          lst[i].appendChild(makeCaption());
+        }
+
+        var lst = document.getElementsByClassName("d2");
+        for (var i = 0; i < lst.length; ++i) {
+          lst[i].firstChild.className = "test";
+        }
+      }
+    </script>
+  </head>
+  <body>
+    <table class="t"><caption></caption></table>
+
+    <table class="t2 d2"><caption></caption></table>
+
+    <table class="t d"></table>
+    <div class="t d"></div>
+    <div style="display: table" class="t d"></div>
+
+    <table class="t2 d d2"></table>
+    <div class="t2 d d2"></div>
+    <div style="display: table" class="t2 d d2"></div>
+    </body>
+</html>
--- a/layout/reftests/bugs/reftest.list
+++ b/layout/reftests/bugs/reftest.list
@@ -100,16 +100,17 @@ fails == 25888-3r.html 25888-3r-ref.html
 == 315620-2a.xhtml 315620-2-ref.xhtml
 != 315620-2b.xhtml 315620-2-ref.xhtml
 == 322461-1.xml 322461-1-ref.html
 == 323656-1.html 323656-1-ref.html
 == 323656-2.html 323656-2-ref.html
 == 323656-3.html 323656-3-ref.html
 == 323656-4.html 323656-4-ref.html
 fails == 323656-5.svg 323656-5-ref.svg # bug 377584
+== 323656-6.html 323656-6-ref.html
 == 325486-1.html 325486-1-ref.html
 random == 328829-1.xhtml 328829-1-ref.xhtml # bug 369046 (intermittent)
 == 328829-2.xhtml 328829-2-ref.xhtml
 == 332360.html 332360-ref.html
 == 332360-ltr.html 332360-ltr-ref.html
 == 332360-width.html 332360-ref.html
 == 332360-width-ltr.html 332360-ltr-ref.html
 == 332557-1.html 332557-1-ref.html
--- a/layout/tables/nsTableOuterFrame.cpp
+++ b/layout/tables/nsTableOuterFrame.cpp
@@ -105,16 +105,40 @@ nsTableCaptionFrame::ComputeAutoSize(nsI
   nsSize result = nsBlockFrame::ComputeAutoSize(aRenderingContext, aCBSize,
                     aAvailableWidth, aMargin, aBorder, aPadding, aShrinkWrap);
   if (IsSideCaption(this)) {
     result.width = GetMinWidth(aRenderingContext);
   }
   return result;
 }
 
+NS_IMETHODIMP 
+nsTableCaptionFrame::GetParentStyleContextFrame(nsPresContext* aPresContext,
+                                                nsIFrame**      aProviderFrame,
+                                                PRBool*         aIsChild)
+{
+  // The caption's style context parent is the inner frame, unless
+  // it's anonymous.
+  nsIFrame* outerFrame = GetParent();
+  if (outerFrame && outerFrame->GetType() == nsGkAtoms::tableOuterFrame) {
+    nsIFrame* innerFrame = outerFrame->GetFirstChild(nsnull);
+    if (innerFrame) {
+      *aProviderFrame =
+        nsFrame::CorrectStyleParentFrame(innerFrame,
+                                         GetStyleContext()->GetPseudoType());
+      *aIsChild = PR_FALSE;
+      return NS_OK;
+    }
+  }
+
+  NS_NOTREACHED("Where is our inner table frame?");
+  return nsBlockFrame::GetParentStyleContextFrame(aPresContext, aProviderFrame,
+                                                  aIsChild);
+}
+
 #ifdef NS_DEBUG
 NS_IMETHODIMP
 nsTableCaptionFrame::GetFrameName(nsAString& aResult) const
 {
   return MakeFrameName(NS_LITERAL_STRING("Caption"), aResult);
 }
 #endif
 
--- a/layout/tables/nsTableOuterFrame.h
+++ b/layout/tables/nsTableOuterFrame.h
@@ -52,16 +52,19 @@ public:
   virtual nsIAtom* GetType() const;
   friend nsIFrame* NS_NewTableCaptionFrame(nsIPresShell* aPresShell, nsStyleContext*  aContext);
 
   virtual nsSize ComputeAutoSize(nsIRenderingContext *aRenderingContext,
                                  nsSize aCBSize, nscoord aAvailableWidth,
                                  nsSize aMargin, nsSize aBorder,
                                  nsSize aPadding, PRBool aShrinkWrap);
 
+  NS_IMETHOD GetParentStyleContextFrame(nsPresContext* aPresContext,
+                                        nsIFrame**      aProviderFrame,
+                                        PRBool*         aIsChild);
 #ifdef NS_DEBUG
   NS_IMETHOD GetFrameName(nsAString& aResult) const;
 #endif
 
 protected:
   nsTableCaptionFrame(nsStyleContext*  aContext);
   virtual ~nsTableCaptionFrame();
 };