From d71d76401870e089779ee54d86ceccd3e75a705e Mon Sep 17 00:00:00 2001 From: Brian Grinstead Date: Tue, 19 Nov 2019 20:30:54 +0000 Subject: [PATCH] Bug 1592369 - Set [orient], [pack], [dir], and [align] styles with CSS instead of reading the XUL layout attributes r=NeilDeakin Differential Revision: https://phabricator.services.mozilla.com/D51013 --HG-- extra : moz-landing-system : lando --- layout/xul/nsBoxFrame.cpp | 108 ++------------------------------ layout/xul/nsScrollbarFrame.cpp | 4 -- toolkit/content/minimal-xul.css | 10 ++- toolkit/content/xul.css | 34 +++++----- 4 files changed, 31 insertions(+), 125 deletions(-) diff --git a/layout/xul/nsBoxFrame.cpp b/layout/xul/nsBoxFrame.cpp index 5cdf00f9e13a..a543df3d9002 100644 --- a/layout/xul/nsBoxFrame.cpp +++ b/layout/xul/nsBoxFrame.cpp @@ -231,44 +231,10 @@ void nsBoxFrame::CacheAttributes() { } bool nsBoxFrame::GetInitialHAlignment(nsBoxFrame::Halignment& aHalign) { - if (!GetContent() || !GetContent()->IsElement()) return false; + if (!GetContent()) return false; - Element* element = GetContent()->AsElement(); - // XXXdwh Everything inside this if statement is deprecated code. - static Element::AttrValuesArray alignStrings[] = {nsGkAtoms::left, - nsGkAtoms::right, nullptr}; - static const Halignment alignValues[] = {hAlign_Left, hAlign_Right}; - int32_t index = element->FindAttrValueIn(kNameSpaceID_None, nsGkAtoms::align, - alignStrings, eCaseMatters); - if (index >= 0) { - aHalign = alignValues[index]; - return true; - } - - // Now that the deprecated stuff is out of the way, we move on to check the - // appropriate attribute. For horizontal boxes, we are checking the PACK - // attribute. For vertical boxes we are checking the ALIGN attribute. - nsAtom* attrName = IsXULHorizontal() ? nsGkAtoms::pack : nsGkAtoms::align; - static Element::AttrValuesArray strings[] = { - nsGkAtoms::_empty, nsGkAtoms::start, nsGkAtoms::center, nsGkAtoms::end, - nullptr}; - static const Halignment values[] = {hAlign_Left /*not used*/, hAlign_Left, - hAlign_Center, hAlign_Right}; - index = element->FindAttrValueIn(kNameSpaceID_None, attrName, strings, - eCaseMatters); - - if (index == Element::ATTR_VALUE_NO_MATCH) { - // The attr was present but had a nonsensical value. Revert to the default. - return false; - } - if (index > 0) { - aHalign = values[index]; - return true; - } - - // Now that we've checked for the attribute it's time to check CSS. For - // horizontal boxes we're checking PACK. For vertical boxes we are checking - // ALIGN. + // For horizontal boxes we're checking PACK. For vertical boxes we are + // checking ALIGN. const nsStyleXUL* boxInfo = StyleXUL(); if (IsXULHorizontal()) { switch (boxInfo->mBoxPack) { @@ -304,46 +270,9 @@ bool nsBoxFrame::GetInitialHAlignment(nsBoxFrame::Halignment& aHalign) { } bool nsBoxFrame::GetInitialVAlignment(nsBoxFrame::Valignment& aValign) { - if (!GetContent() || !GetContent()->IsElement()) return false; - - Element* element = GetContent()->AsElement(); - - static Element::AttrValuesArray valignStrings[] = { - nsGkAtoms::top, nsGkAtoms::baseline, nsGkAtoms::middle, nsGkAtoms::bottom, - nullptr}; - static const Valignment valignValues[] = {vAlign_Top, vAlign_BaseLine, - vAlign_Middle, vAlign_Bottom}; - int32_t index = element->FindAttrValueIn(kNameSpaceID_None, nsGkAtoms::valign, - valignStrings, eCaseMatters); - if (index >= 0) { - aValign = valignValues[index]; - return true; - } - - // Now that the deprecated stuff is out of the way, we move on to check the - // appropriate attribute. For horizontal boxes, we are checking the ALIGN - // attribute. For vertical boxes we are checking the PACK attribute. - nsAtom* attrName = IsXULHorizontal() ? nsGkAtoms::align : nsGkAtoms::pack; - static Element::AttrValuesArray strings[] = { - nsGkAtoms::_empty, nsGkAtoms::start, nsGkAtoms::center, - nsGkAtoms::baseline, nsGkAtoms::end, nullptr}; - static const Valignment values[] = {vAlign_Top /*not used*/, vAlign_Top, - vAlign_Middle, vAlign_BaseLine, - vAlign_Bottom}; - index = element->FindAttrValueIn(kNameSpaceID_None, attrName, strings, - eCaseMatters); - if (index == Element::ATTR_VALUE_NO_MATCH) { - // The attr was present but had a nonsensical value. Revert to the default. - return false; - } - if (index > 0) { - aValign = values[index]; - return true; - } - - // Now that we've checked for the attribute it's time to check CSS. For - // horizontal boxes we're checking ALIGN. For vertical boxes we are checking - // PACK. + if (!GetContent()) return false; + // For horizontal boxes we're checking ALIGN. For vertical boxes we are + // checking PACK. const nsStyleXUL* boxInfo = StyleXUL(); if (IsXULHorizontal()) { switch (boxInfo->mBoxAlign) { @@ -385,25 +314,12 @@ void nsBoxFrame::GetInitialOrientation(bool& aIsHorizontal) { // see if we are a vertical or horizontal box. if (!GetContent()) return; - // Check the style system first. const nsStyleXUL* boxInfo = StyleXUL(); if (boxInfo->mBoxOrient == StyleBoxOrient::Horizontal) { aIsHorizontal = true; } else { aIsHorizontal = false; } - - // Now see if we have an attribute. The attribute overrides - // the style system value. - if (!GetContent()->IsElement()) return; - - static Element::AttrValuesArray strings[] = {nsGkAtoms::vertical, - nsGkAtoms::horizontal, nullptr}; - int32_t index = GetContent()->AsElement()->FindAttrValueIn( - kNameSpaceID_None, nsGkAtoms::orient, strings, eCaseMatters); - if (index >= 0) { - aIsHorizontal = index == 1; - } } void nsBoxFrame::GetInitialDirection(bool& aIsNormal) { @@ -461,18 +377,6 @@ bool nsBoxFrame::GetInitialEqualSize(bool& aEqualSize) { bool nsBoxFrame::GetInitialAutoStretch(bool& aStretch) { if (!GetContent()) return false; - // Check the align attribute. - if (GetContent()->IsElement()) { - static Element::AttrValuesArray strings[] = {nsGkAtoms::_empty, - nsGkAtoms::stretch, nullptr}; - int32_t index = GetContent()->AsElement()->FindAttrValueIn( - kNameSpaceID_None, nsGkAtoms::align, strings, eCaseMatters); - if (index != Element::ATTR_MISSING && index != 0) { - aStretch = index == 1; - return true; - } - } - // Check the CSS box-align property. const nsStyleXUL* boxInfo = StyleXUL(); aStretch = (boxInfo->mBoxAlign == StyleBoxAlign::Stretch); diff --git a/layout/xul/nsScrollbarFrame.cpp b/layout/xul/nsScrollbarFrame.cpp index 11769cad2f13..023748b8466a 100644 --- a/layout/xul/nsScrollbarFrame.cpp +++ b/layout/xul/nsScrollbarFrame.cpp @@ -381,10 +381,6 @@ nsresult nsScrollbarFrame::CreateAnonymousContent( nodeInfoManager->GetNodeInfo(nsGkAtoms::thumb, nullptr, kNameSpaceID_XUL, nsINode::ELEMENT_NODE)); mThumb->SetAttr(kNameSpaceID_None, nsGkAtoms::orient, orient, false); - mThumb->SetAttr(kNameSpaceID_None, nsGkAtoms::align, - NS_LITERAL_STRING("center"), false); - mThumb->SetAttr(kNameSpaceID_None, nsGkAtoms::pack, - NS_LITERAL_STRING("center"), false); mSlider->AppendChildTo(mThumb, false); } diff --git a/toolkit/content/minimal-xul.css b/toolkit/content/minimal-xul.css index 50ec8018ef26..dfb8b6416451 100644 --- a/toolkit/content/minimal-xul.css +++ b/toolkit/content/minimal-xul.css @@ -38,7 +38,6 @@ } /* Rules required for style caching of anonymous content scrollbar parts */ - scrollcorner, resizer, scrollbar, scrollbarbutton, slider { /* All scrollbar parts must not inherit any properties from the scrollable * element (except for visibility and pointer-events), for the anonymous @@ -90,10 +89,19 @@ scrollcorner, resizer, scrollbar, scrollbarbutton, slider { box-sizing: border-box; } +scrollbar[orient="vertical"], +slider[orient="vertical"], +thumb[orient="vertical"] { + -moz-box-orient: vertical; +} + thumb { /* Prevent -moz-user-modify declaration from designmode.css having an * effect. */ -moz-user-modify: initial; + + -moz-box-align: center; + -moz-box-pack: center; } /* There are other rules that set direction and cursor on scrollbar, diff --git a/toolkit/content/xul.css b/toolkit/content/xul.css index 60a18dd86f37..5424e9846333 100644 --- a/toolkit/content/xul.css +++ b/toolkit/content/xul.css @@ -569,26 +569,24 @@ tabmodalprompt { display: none; } +[orient="vertical"] { -moz-box-orient: vertical !important; } +[orient="horizontal"] { -moz-box-orient: horizontal !important; } + +[align="start"] { -moz-box-align: start !important; } +[align="center"] { -moz-box-align: center !important; } +[align="end"] { -moz-box-align: end !important; } +[align="baseline"] { -moz-box-align: baseline !important; } +[align="stretch"] { -moz-box-align: stretch !important; } + +[pack="start"] { -moz-box-pack: start !important; } +[pack="center"] { -moz-box-pack: center !important; } +[pack="end"] { -moz-box-pack: end !important; } + @supports -moz-bool-pref("layout.css.emulate-moz-box-with-flex") { - /* Support common XUL attributes in the emulated flex mode so we can - test the browser in this configuration without mass-changing existing - markup and CSS. */ - [orient="vertical"] { -moz-box-orient: vertical; } - [orient="horizontal"] { -moz-box-orient: horizontal; } - - [align="start"] { -moz-box-align: start; } - [align="center"] { -moz-box-align: center; } - [align="end"] { -moz-box-align: end; } - [align="baseline"] { -moz-box-align: baseline; } - [align="stretch"] { -moz-box-align: stretch; } - - [pack="start"] { -moz-box-pack: start; } - [pack="center"] { -moz-box-pack: center; } - [pack="end"] { -moz-box-pack: end; } - /* This isn't a real solution for [flex] and [ordinal], but it covers enough - cases to render the browser chrome. If we get attr() in Bug 435426 this could - work for all cases. */ + cases to render the browser chrome for us to test emulated flex mode without + mass-changing existing markup and CSS. + If we get attr() in Bug 435426 this could work for all cases. */ [flex="1"] { -moz-box-flex: 1; } [flex="2"] { -moz-box-flex: 2; } [flex="3"] { -moz-box-flex: 3; }