From 2f01e225e32d0c0994b8610c4b4dcc51cb876e56 Mon Sep 17 00:00:00 2001 From: Xidorn Quan Date: Thu, 11 Dec 2014 09:26:18 +1100 Subject: [PATCH] Bug 1098275 - Inlinize block-level boxes inside ruby. r=heycam --HG-- extra : rebase_source : 70a969d3a6be4ea5dfe14777aa7c31189ade7211 extra : source : 30e0ea21cdfaa29f2c138f0b8975da984e8ac009 --- layout/base/RestyleManager.cpp | 7 +++++++ layout/style/nsStyleContext.cpp | 17 +++++++++++------ layout/style/nsStyleContext.h | 6 ++++++ layout/style/nsStyleStruct.h | 5 +++-- 4 files changed, 27 insertions(+), 8 deletions(-) diff --git a/layout/base/RestyleManager.cpp b/layout/base/RestyleManager.cpp index f9a84c543b1..4229e9a11af 100644 --- a/layout/base/RestyleManager.cpp +++ b/layout/base/RestyleManager.cpp @@ -2904,6 +2904,13 @@ ElementRestyler::ComputeRestyleResultFromNewContext(nsIFrame* aSelf, return eRestyleResult_Continue; } + if (oldContext->IsDirectlyInsideRuby() != + aNewContext->IsDirectlyInsideRuby()) { + LOG_RESTYLE_CONTINUE("NS_STYLE_IS_DIRECTLY_INSIDE_RUBY differes between old" + " and new style contexts"); + return eRestyleResult_Continue; + } + return eRestyleResult_Stop; } diff --git a/layout/style/nsStyleContext.cpp b/layout/style/nsStyleContext.cpp index a6bd9f02edb..e7e5974282d 100644 --- a/layout/style/nsStyleContext.cpp +++ b/layout/style/nsStyleContext.cpp @@ -507,8 +507,8 @@ nsStyleContext::ApplyStyleFixups(bool aSkipParentDisplayBasedStyleFixup) // # The computed 'display' of a flex item is determined // # by applying the table in CSS 2.1 Chapter 9.7. // ...which converts inline-level elements to their block-level equivalents. - // Any direct children of elements with Ruby display values which are - // block-level are converted to their inline-level equivalents. + // Any block-level element directly contained by elements with ruby display + // values are converted to their inline-level equivalents. if (!aSkipParentDisplayBasedStyleFixup && mParent) { // Skip display:contents ancestors to reach the potential container. // (If there are only display:contents ancestors between this node and @@ -558,12 +558,17 @@ nsStyleContext::ApplyStyleFixups(bool aSkipParentDisplayBasedStyleFixup) mutable_display->mDisplay = displayVal; } } - } else if (containerDisp->IsRubyDisplayType()) { + } + + // The display change should only occur for "in-flow" children + if (!disp->IsOutOfFlowStyle() && + ((containerDisp->mDisplay == NS_STYLE_DISPLAY_INLINE && + containerContext->IsDirectlyInsideRuby()) || + containerDisp->IsRubyDisplayType())) { + mBits |= NS_STYLE_IS_DIRECTLY_INSIDE_RUBY; uint8_t displayVal = disp->mDisplay; nsRuleNode::EnsureInlineDisplay(displayVal); - // The display change should only occur for "in-flow" children - if (displayVal != disp->mDisplay && - !disp->IsOutOfFlowStyle()) { + if (displayVal != disp->mDisplay) { nsStyleDisplay *mutable_display = static_cast(GetUniqueStyleData(eStyleStruct_Display)); mutable_display->mDisplay = displayVal; diff --git a/layout/style/nsStyleContext.h b/layout/style/nsStyleContext.h index 9279b47e638..2c2081e05dd 100644 --- a/layout/style/nsStyleContext.h +++ b/layout/style/nsStyleContext.h @@ -130,6 +130,12 @@ public: bool HasTextDecorationLines() const { return !!(mBits & NS_STYLE_HAS_TEXT_DECORATION_LINES); } + // Whether this style context or any of its inline-level ancestors + // is directly contained by a ruby box? It is used to inlinize + // block-level descendants and suppress line breaks inside ruby. + bool IsDirectlyInsideRuby() const + { return !!(mBits & NS_STYLE_IS_DIRECTLY_INSIDE_RUBY); } + // Does this style context represent the style for a pseudo-element or // inherit data from such a style context? Whether this returns true // is equivalent to whether it or any of its ancestors returns diff --git a/layout/style/nsStyleStruct.h b/layout/style/nsStyleStruct.h index bf5e7c28da9..fac59fc184f 100644 --- a/layout/style/nsStyleStruct.h +++ b/layout/style/nsStyleStruct.h @@ -56,9 +56,10 @@ class imgIContainer; // See nsStyleContext::AssertStructsNotUsedElsewhere // (This bit is currently only used in #ifdef DEBUG code.) #define NS_STYLE_IS_GOING_AWAY 0x040000000 +// See nsStyleContext::IsDirectlyInsideRuby +#define NS_STYLE_IS_DIRECTLY_INSIDE_RUBY 0x080000000 // See nsStyleContext::GetPseudoEnum -#define NS_STYLE_CONTEXT_TYPE_MASK 0xf80000000 -#define NS_STYLE_CONTEXT_TYPE_SHIFT 31 +#define NS_STYLE_CONTEXT_TYPE_SHIFT 32 // Additional bits for nsRuleNode's mDependentBits: #define NS_RULE_NODE_GC_MARK 0x02000000