diff --git a/layout/generic/nsBlockFrame.cpp b/layout/generic/nsBlockFrame.cpp
index ff0820860417..ca31c9e31f16 100644
--- a/layout/generic/nsBlockFrame.cpp
+++ b/layout/generic/nsBlockFrame.cpp
@@ -6442,6 +6442,10 @@ nsBlockFrame::BuildDisplayList(nsDisplayListBuilder* aBuilder,
a11y::AccType
nsBlockFrame::AccessibleType()
{
+ if (IsTableCaption()) {
+ return GetRect().IsEmpty() ? a11y::eNoType : a11y::eHTMLCaptionType;
+ }
+
// block frame may be for
if (mContent->Tag() == nsGkAtoms::hr) {
return a11y::eHTMLHRType;
diff --git a/layout/generic/nsContainerFrame.cpp b/layout/generic/nsContainerFrame.cpp
index 9c77a3948948..d8a47d6b7506 100644
--- a/layout/generic/nsContainerFrame.cpp
+++ b/layout/generic/nsContainerFrame.cpp
@@ -885,7 +885,7 @@ nsContainerFrame::DoInlineIntrinsicISize(nsRenderingContext *aRenderingContext,
/* virtual */
LogicalSize
-nsContainerFrame::ComputeAutoSize(nsRenderingContext *aRenderingContext,
+nsContainerFrame::ComputeAutoSize(nsRenderingContext* aRenderingContext,
WritingMode aWM,
const LogicalSize& aCBSize,
nscoord aAvailableISize,
@@ -908,6 +908,33 @@ nsContainerFrame::ComputeAutoSize(nsRenderingContext *aRenderingContext,
} else {
result.ISize(aWM) = availBased;
}
+
+ if (IsTableCaption()) {
+ // If we're a container for font size inflation, then shrink
+ // wrapping inside of us should not apply font size inflation.
+ AutoMaybeDisableFontInflation an(this);
+
+ // XXX todo: make this aware of vertical writing modes
+ uint8_t captionSide = StyleTableBorder()->mCaptionSide;
+ if (captionSide == NS_STYLE_CAPTION_SIDE_LEFT ||
+ captionSide == NS_STYLE_CAPTION_SIDE_RIGHT) {
+ result.ISize(aWM) = GetMinISize(aRenderingContext);
+ } else if (captionSide == NS_STYLE_CAPTION_SIDE_TOP ||
+ captionSide == NS_STYLE_CAPTION_SIDE_BOTTOM) {
+ // The outer frame constrains our available width to the width of
+ // the table. Grow if our min-width is bigger than that, but not
+ // larger than the containing block width. (It would really be nice
+ // to transmit that information another way, so we could grow up to
+ // the table's available width, but that's harder.)
+ nscoord min = GetMinISize(aRenderingContext);
+ if (min > aCBSize.ISize(aWM)) {
+ min = aCBSize.ISize(aWM);
+ }
+ if (min > result.ISize(aWM)) {
+ result.ISize(aWM) = min;
+ }
+ }
+ }
return result;
}
diff --git a/layout/generic/nsFrame.cpp b/layout/generic/nsFrame.cpp
index ee27fee037b4..0f13d08d0b18 100644
--- a/layout/generic/nsFrame.cpp
+++ b/layout/generic/nsFrame.cpp
@@ -7080,6 +7080,9 @@ nsFrame::ChildIsDirty(nsIFrame* aChild)
a11y::AccType
nsFrame::AccessibleType()
{
+ if (IsTableCaption() && !GetRect().IsEmpty()) {
+ return a11y::eHTMLCaptionType;
+ }
return a11y::eNoType;
}
#endif
@@ -7748,11 +7751,20 @@ GetIBSplitSiblingForAnonymousBlock(const nsIFrame* aFrame)
static nsIFrame*
GetCorrectedParent(const nsIFrame* aFrame)
{
- nsIFrame *parent = aFrame->GetParent();
+ nsIFrame* parent = aFrame->GetParent();
if (!parent) {
return nullptr;
}
+ // For a table caption we want the _inner_ table frame (unless it's anonymous)
+ // as the style parent.
+ if (aFrame->IsTableCaption()) {
+ nsIFrame* innerTable = parent->GetFirstPrincipalChild();
+ if (!innerTable->StyleContext()->GetPseudo()) {
+ return innerTable;
+ }
+ }
+
// Outer tables are always anon boxes; if we're in here for an outer
// table, that actually means its the _inner_ table that wants to
// know its parent. So get the pseudo of the inner in that case.
diff --git a/layout/generic/nsGfxScrollFrame.cpp b/layout/generic/nsGfxScrollFrame.cpp
index 6ec4dfeebaa8..a89daa99e60d 100644
--- a/layout/generic/nsGfxScrollFrame.cpp
+++ b/layout/generic/nsGfxScrollFrame.cpp
@@ -931,6 +931,10 @@ nsHTMLScrollFrame::GetFrameName(nsAString& aResult) const
a11y::AccType
nsHTMLScrollFrame::AccessibleType()
{
+ if (IsTableCaption()) {
+ return GetRect().IsEmpty() ? a11y::eNoType : a11y::eHTMLCaptionType;
+ }
+
// Create an accessible regardless of focusable state because the state can be
// changed during frame life cycle without any notifications to accessibility.
if (mContent->IsRootOfNativeAnonymousSubtree() ||