Remove REM units.

The code to make them dynamically update was already removed when
Document::inheritHtmlAndBodyElementStyles was removed. We might want
to add them back later, but probably in a different way, so lets
remove the code for now to make refactoring the style system easier.

R=eseidel@chromium.org

Review URL: https://codereview.chromium.org/788883005
This commit is contained in:
Elliott Sprehn 2014-12-15 17:29:04 -08:00
parent 4b7e60d511
commit ca96d732de
30 changed files with 12 additions and 114 deletions

View File

@ -66,7 +66,6 @@ bool DeferredLegacyStyleInterpolation::interpolationRequiresStyleResolve(const C
primitiveValue.accumulateLengthArray(lengthArray);
return lengthArray[CSSPrimitiveValue::UnitTypeFontSize] != 0
|| lengthArray[CSSPrimitiveValue::UnitTypeFontXSize] != 0
|| lengthArray[CSSPrimitiveValue::UnitTypeRootFontSize] != 0
|| lengthArray[CSSPrimitiveValue::UnitTypeZeroCharacterWidth] != 0
|| lengthArray[CSSPrimitiveValue::UnitTypeViewportWidth] != 0
|| lengthArray[CSSPrimitiveValue::UnitTypeViewportHeight] != 0

View File

@ -62,7 +62,6 @@ static CalculationCategory unitCategory(CSSPrimitiveValue::UnitType type)
case CSSPrimitiveValue::CSS_IN:
case CSSPrimitiveValue::CSS_PT:
case CSSPrimitiveValue::CSS_PC:
case CSSPrimitiveValue::CSS_REMS:
case CSSPrimitiveValue::CSS_CHS:
case CSSPrimitiveValue::CSS_VW:
case CSSPrimitiveValue::CSS_VH:
@ -93,7 +92,6 @@ static bool hasDoubleValue(CSSPrimitiveValue::UnitType type)
case CSSPrimitiveValue::CSS_EMS:
case CSSPrimitiveValue::CSS_EXS:
case CSSPrimitiveValue::CSS_CHS:
case CSSPrimitiveValue::CSS_REMS:
case CSSPrimitiveValue::CSS_PX:
case CSSPrimitiveValue::CSS_CM:
case CSSPrimitiveValue::CSS_MM:

View File

@ -61,8 +61,7 @@ PassRefPtr<Image> CSSGradientValue::image(RenderObject* renderer, const IntSize&
// We need to create an image.
RefPtr<Gradient> gradient;
RenderStyle* rootStyle = renderer->document().documentElement()->renderStyle();
CSSToLengthConversionData conversionData(renderer->style(), rootStyle, renderer->view());
CSSToLengthConversionData conversionData(renderer->style(), renderer->view());
if (isLinearGradientValue())
gradient = toCSSLinearGradientValue(this)->createGradient(conversionData, size);
else

View File

@ -68,7 +68,7 @@ void CSSMatrix::setMatrixValue(const String& string, ExceptionState& exceptionSt
DEFINE_STATIC_REF(RenderStyle, defaultStyle, RenderStyle::createDefaultStyle());
TransformOperations operations;
if (!TransformBuilder::createTransformOperations(value.get(), CSSToLengthConversionData(defaultStyle, defaultStyle, 0), operations)) {
if (!TransformBuilder::createTransformOperations(value.get(), CSSToLengthConversionData(defaultStyle, 0), operations)) {
exceptionState.throwDOMException(SyntaxError, "Failed to interpret '" + string + "' as a transformation operation.");
return;
}

View File

@ -76,7 +76,6 @@ static inline bool isValidCSSUnitTypeForDoubleConversion(CSSPrimitiveValue::Unit
case CSSPrimitiveValue::CSS_PT:
case CSSPrimitiveValue::CSS_PX:
case CSSPrimitiveValue::CSS_RAD:
case CSSPrimitiveValue::CSS_REMS:
case CSSPrimitiveValue::CSS_CHS:
case CSSPrimitiveValue::CSS_S:
case CSSPrimitiveValue::CSS_TURN:
@ -134,7 +133,6 @@ StringToUnitTable createStringToUnitTable()
table.set(String("vh"), CSSPrimitiveValue::CSS_VH);
table.set(String("vmax"), CSSPrimitiveValue::CSS_VMIN);
table.set(String("vmin"), CSSPrimitiveValue::CSS_VMAX);
table.set(String("rem"), CSSPrimitiveValue::CSS_REMS);
table.set(String("fr"), CSSPrimitiveValue::CSS_FR);
table.set(String("turn"), CSSPrimitiveValue::CSS_TURN);
table.set(String("ch"), CSSPrimitiveValue::CSS_CHS);
@ -460,7 +458,6 @@ void CSSPrimitiveValue::cleanup()
case CSS_PERCENTAGE:
case CSS_EMS:
case CSS_EXS:
case CSS_REMS:
case CSS_CHS:
case CSS_PX:
case CSS_CM:
@ -575,7 +572,6 @@ double CSSPrimitiveValue::computeLengthDouble(const CSSToLengthConversionData& c
return m_value.calc->computeLengthPx(conversionData);
const RenderStyle& style = conversionData.style();
const RenderStyle* rootStyle = conversionData.rootStyle();
bool computingFontSize = conversionData.computingFontSize();
double factor;
@ -593,12 +589,6 @@ double CSSPrimitiveValue::computeLengthDouble(const CSSToLengthConversionData& c
else
factor = (computingFontSize ? style.fontDescription().specifiedSize() : style.fontDescription().computedSize()) / 2.0;
break;
case CSS_REMS:
if (rootStyle)
factor = computingFontSize ? rootStyle->fontDescription().specifiedSize() : rootStyle->fontDescription().computedSize();
else
factor = 1.0;
break;
case CSS_CHS:
factor = style.fontMetrics().zeroWidth();
break;
@ -840,9 +830,6 @@ bool CSSPrimitiveValue::unitTypeToLengthUnitType(UnitType unitType, LengthUnitTy
case CSSPrimitiveValue::CSS_EXS:
lengthType = UnitTypeFontXSize;
return true;
case CSSPrimitiveValue::CSS_REMS:
lengthType = UnitTypeRootFontSize;
return true;
case CSSPrimitiveValue::CSS_CHS:
lengthType = UnitTypeZeroCharacterWidth;
return true;
@ -875,8 +862,6 @@ CSSPrimitiveValue::UnitType CSSPrimitiveValue::lengthUnitTypeToUnitType(LengthUn
return CSSPrimitiveValue::CSS_EMS;
case UnitTypeFontXSize:
return CSSPrimitiveValue::CSS_EXS;
case UnitTypeRootFontSize:
return CSSPrimitiveValue::CSS_REMS;
case UnitTypeZeroCharacterWidth:
return CSSPrimitiveValue::CSS_CHS;
case UnitTypePercentage:
@ -1012,8 +997,6 @@ const char* CSSPrimitiveValue::unitTypeToString(UnitType type)
return "em";
case CSS_EXS:
return "ex";
case CSS_REMS:
return "rem";
case CSS_CHS:
return "ch";
case CSS_PX:
@ -1103,7 +1086,6 @@ String CSSPrimitiveValue::customCSSText(CSSTextFormattingFlags formattingFlag) c
case CSS_PERCENTAGE:
case CSS_EMS:
case CSS_EXS:
case CSS_REMS:
case CSS_CHS:
case CSS_PX:
case CSS_CM:
@ -1218,7 +1200,6 @@ PassRefPtr<CSSPrimitiveValue> CSSPrimitiveValue::cloneForCSSOM() const
case CSS_PERCENTAGE:
case CSS_EMS:
case CSS_EXS:
case CSS_REMS:
case CSS_CHS:
case CSS_PX:
case CSS_CM:
@ -1277,7 +1258,6 @@ bool CSSPrimitiveValue::equals(const CSSPrimitiveValue& other) const
case CSS_PERCENTAGE:
case CSS_EMS:
case CSS_EXS:
case CSS_REMS:
case CSS_PX:
case CSS_CM:
case CSS_DPPX:

View File

@ -113,7 +113,7 @@ public:
// These are from CSS3 Values and Units, but that isn't a finished standard yet
CSS_TURN = 107,
CSS_REMS = 108,
// CSS_REMS = 108,
CSS_CHS = 109,
// This is used by the CSS Shapes draft
@ -135,7 +135,6 @@ public:
UnitTypePercentage,
UnitTypeFontSize,
UnitTypeFontXSize,
UnitTypeRootFontSize,
UnitTypeZeroCharacterWidth,
UnitTypeViewportWidth,
UnitTypeViewportHeight,
@ -177,14 +176,13 @@ public:
{
return m_primitiveUnitType == CSS_EMS
|| m_primitiveUnitType == CSS_EXS
|| m_primitiveUnitType == CSS_REMS
|| m_primitiveUnitType == CSS_CHS;
}
bool isViewportPercentageLength() const { return isViewportPercentageLength(static_cast<UnitType>(m_primitiveUnitType)); }
static bool isViewportPercentageLength(UnitType type) { return type >= CSS_VW && type <= CSS_VMAX; }
static bool isLength(UnitType type)
{
return (type >= CSS_EMS && type <= CSS_PC) || type == CSS_REMS || type == CSS_CHS || isViewportPercentageLength(type);
return (type >= CSS_EMS && type <= CSS_PC) || type == CSS_CHS || isViewportPercentageLength(type);
}
bool isLength() const { return isLength(primitiveType()); }
bool isNumber() const { return primitiveType() == CSS_NUMBER; }

View File

@ -36,9 +36,8 @@
namespace blink {
CSSToLengthConversionData::CSSToLengthConversionData(const RenderStyle* style, const RenderStyle* rootStyle, const RenderView* renderView, bool computingFontSize)
CSSToLengthConversionData::CSSToLengthConversionData(const RenderStyle* style, const RenderView* renderView, bool computingFontSize)
: m_style(style)
, m_rootStyle(rootStyle)
, m_viewportWidth(renderView ? renderView->layoutViewportWidth() : 0)
, m_viewportHeight(renderView ? renderView->layoutViewportHeight() : 0)
, m_computingFontSize(computingFontSize)

View File

@ -41,10 +41,9 @@ class RenderView;
class CSSToLengthConversionData {
public:
CSSToLengthConversionData(const RenderStyle* currStyle, const RenderStyle* rootStyle, const RenderView*, bool computingFontSize = false);
CSSToLengthConversionData(const RenderStyle* currStyle, const RenderView*, bool computingFontSize = false);
const RenderStyle& style() const { return *m_style; }
const RenderStyle* rootStyle() const { return m_rootStyle; }
bool computingFontSize() const { return m_computingFontSize; }
// Accessing these marks the style as having viewport units
@ -54,11 +53,9 @@ public:
double viewportMaxPercent() const;
void setStyle(const RenderStyle* style) { m_style = style; }
void setRootStyle(const RenderStyle* rootStyle) { m_rootStyle = rootStyle; }
private:
const RenderStyle* m_style;
const RenderStyle* m_rootStyle;
float m_viewportWidth;
float m_viewportHeight;
bool m_computingFontSize;

View File

@ -86,7 +86,6 @@ static bool positiveLengthUnit(const int unit)
case CSSPrimitiveValue::CSS_IN:
case CSSPrimitiveValue::CSS_PT:
case CSSPrimitiveValue::CSS_PC:
case CSSPrimitiveValue::CSS_REMS:
case CSSPrimitiveValue::CSS_CHS:
return true;
}

View File

@ -136,7 +136,6 @@ bool MediaValues::computeLengthImpl(double value, CSSPrimitiveValue::UnitType ty
double factor = 0;
switch (type) {
case CSSPrimitiveValue::CSS_EMS:
case CSSPrimitiveValue::CSS_REMS:
factor = defaultFontSize;
break;
case CSSPrimitiveValue::CSS_PX:

View File

@ -27,7 +27,6 @@ TEST(MediaValuesTest, Basic)
TestCase testCases[] = {
{ 40.0, CSSPrimitiveValue::CSS_PX, 16, 300, 300, true, 40 },
{ 40.0, CSSPrimitiveValue::CSS_EMS, 16, 300, 300, true, 640 },
{ 40.0, CSSPrimitiveValue::CSS_REMS, 16, 300, 300, true, 640 },
{ 40.0, CSSPrimitiveValue::CSS_EXS, 16, 300, 300, true, 320 },
{ 40.0, CSSPrimitiveValue::CSS_CHS, 16, 300, 300, true, 320 },
{ 43.0, CSSPrimitiveValue::CSS_VW, 16, 848, 976, true, 364 },

View File

@ -36,8 +36,7 @@
namespace blink {
StyleSheetContents::StyleSheetContents(const CSSParserContext& context)
: m_usesRemUnits(false)
, m_hasMediaQueries(false)
: m_hasMediaQueries(false)
, m_parserContext(context)
{
}

View File

@ -55,12 +55,9 @@ public:
bool parseString(const String&);
void parserAppendRule(PassRefPtr<StyleRuleBase>);
void parserSetUsesRemUnits(bool b) { m_usesRemUnits = b; }
const Vector<RefPtr<StyleRuleBase> >& childRules() const { return m_childRules; }
bool usesRemUnits() const { return m_usesRemUnits; }
void registerClient(CSSStyleSheet*);
void unregisterClient(CSSStyleSheet*);
@ -75,7 +72,6 @@ public:
private:
explicit StyleSheetContents(const CSSParserContext&);
bool m_usesRemUnits : 1;
bool m_hasMediaQueries : 1;
OwnPtr<RuleSet> m_ruleSet;

View File

@ -200,7 +200,6 @@ inline static CSSParserValue makeIdentValue(CSSParserString string)
%token SUPPORTS_AND
%token SUPPORTS_OR
%token <number> REMS
%token <number> CHS
%token <number> EMS
%token <number> EXS
@ -1302,11 +1301,6 @@ unary_term:
| KHERTZ { $$.setFromNumber($1, CSSPrimitiveValue::CSS_KHZ); }
| EMS { $$.setFromNumber($1, CSSPrimitiveValue::CSS_EMS); }
| EXS { $$.setFromNumber($1, CSSPrimitiveValue::CSS_EXS); }
| REMS {
$$.setFromNumber($1, CSSPrimitiveValue::CSS_REMS);
if (parser->m_styleSheet)
parser->m_styleSheet->parserSetUsesRemUnits(true);
}
| CHS { $$.setFromNumber($1, CSSPrimitiveValue::CSS_CHS); }
| VW { $$.setFromNumber($1, CSSPrimitiveValue::CSS_VW); }
| VH { $$.setFromNumber($1, CSSPrimitiveValue::CSS_VH); }

View File

@ -248,7 +248,6 @@ bool CSSPropertyParser::validUnit(CSSParserValue* value, Units unitflags, CSSPar
b = (unitflags & FPercent);
break;
case CSSPrimitiveValue::CSS_EMS:
case CSSPrimitiveValue::CSS_REMS:
case CSSPrimitiveValue::CSS_CHS:
case CSSPrimitiveValue::CSS_EXS:
case CSSPrimitiveValue::CSS_PX:

View File

@ -843,9 +843,6 @@ inline void CSSTokenizer::detectNumberToken(CharacterType* type, int length)
CASE("rad") {
m_token = RADS;
}
CASE("rem") {
m_token = REMS;
}
CASE("s") {
m_token = SECS;
}

View File

@ -31,7 +31,6 @@ namespace blink {
ElementResolveContext::ElementResolveContext(const Document& document)
: m_element(nullptr)
, m_parentNode(nullptr)
, m_rootElementStyle(document.documentElement() ? document.documentElement()->renderStyle() : document.renderStyle())
, m_distributedToInsertionPoint(false)
{
}
@ -43,13 +42,6 @@ ElementResolveContext::ElementResolveContext(Element& element)
NodeRenderingTraversal::ParentDetails parentDetails;
m_parentNode = NodeRenderingTraversal::parent(&element, &parentDetails);
m_distributedToInsertionPoint = parentDetails.insertionPoint();
const Document& document = element.document();
Node* documentElement = document.documentElement();
RenderStyle* documentStyle = document.renderStyle();
m_rootElementStyle = documentElement && element != documentElement ? documentElement->renderStyle() : documentStyle;
if (!m_rootElementStyle)
m_rootElementStyle = documentStyle;
}
} // namespace blink

View File

@ -42,13 +42,11 @@ public:
Element* element() const { return m_element; }
const ContainerNode* parentNode() const { return m_parentNode; }
const RenderStyle* rootElementStyle() const { return m_rootElementStyle; }
bool distributedToInsertionPoint() const { return m_distributedToInsertionPoint; }
private:
RawPtr<Element> m_element;
RawPtr<ContainerNode> m_parentNode;
RenderStyle* m_rootElementStyle;
bool m_distributedToInsertionPoint;
};

View File

@ -276,7 +276,7 @@ static float smallerFontSize(float size)
}
// FIXME: Have to pass RenderStyles here for calc/computed values. This shouldn't be neecessary.
void FontBuilder::setFontSizeValue(CSSValue* value, RenderStyle* parentStyle, const RenderStyle* rootElementStyle)
void FontBuilder::setFontSizeValue(CSSValue* value, RenderStyle* parentStyle)
{
if (!value->isPrimitiveValue())
return;
@ -328,7 +328,7 @@ void FontBuilder::setFontSizeValue(CSSValue* value, RenderStyle* parentStyle, co
// If we have viewport units the conversion will mark the parent style as having viewport units.
bool parentHasViewportUnits = parentStyle->hasViewportUnits();
parentStyle->setHasViewportUnits(false);
CSSToLengthConversionData conversionData(parentStyle, rootElementStyle, m_document->renderView(), true);
CSSToLengthConversionData conversionData(parentStyle, m_document->renderView(), true);
if (primitiveValue->isLength())
size = primitiveValue->computeLength<float>(conversionData);
else if (primitiveValue->isCalculatedPercentageWithLength())

View File

@ -59,7 +59,7 @@ public:
void setFontSizeInitial();
void setFontSizeInherit(const FontDescription&);
void setFontSizeValue(CSSValue*, RenderStyle* parentStyle, const RenderStyle* rootElementStyle);
void setFontSizeValue(CSSValue*, RenderStyle* parentStyle);
void setWeight(FontWeight);
void setStretch(FontStretch);

View File

@ -186,7 +186,7 @@ void StyleBuilderFunctions::applyInheritCSSPropertyFontSize(StyleResolverState&
void StyleBuilderFunctions::applyValueCSSPropertyFontSize(StyleResolverState& state, CSSValue* value)
{
state.fontBuilder().setFontSizeValue(value, state.parentStyle(), state.rootElementStyle());
state.fontBuilder().setFontSizeValue(value, state.parentStyle());
}
void StyleBuilderFunctions::applyValueCSSPropertyLineHeight(StyleResolverState& state, CSSValue* value)

View File

@ -33,7 +33,7 @@ StyleResolverState::StyleResolverState(Document& document, Element* element, Ren
: m_elementContext(element ? ElementResolveContext(*element) : ElementResolveContext(document))
, m_document(document)
, m_style(nullptr)
, m_cssToLengthConversionData(0, rootElementStyle(), document.renderView())
, m_cssToLengthConversionData(0, document.renderView())
, m_parentStyle(parentStyle)
, m_lineHeightValue(nullptr)
, m_styleMap(*this, m_elementStyleResources)

View File

@ -53,7 +53,6 @@ public:
// These are all just pass-through methods to ElementResolveContext.
Element* element() const { return m_elementContext.element(); }
const ContainerNode* parentNode() const { return m_elementContext.parentNode(); }
const RenderStyle* rootElementStyle() const { return m_elementContext.rootElementStyle(); }
bool distributedToInsertionPoint() const { return m_elementContext.distributedToInsertionPoint(); }

View File

@ -1078,9 +1078,6 @@ void Document::updateRenderTree(StyleRecalcChange change)
// re-attaching our containing iframe, which when asked HTMLFrameElementBase::isURLAllowed
// hits a null-dereference due to security code always assuming the document has a SecurityOrigin.
if (m_elemSheet && m_elemSheet->contents()->usesRemUnits())
m_styleEngine->setUsesRemUnit(true);
updateStyle(change);
// As a result of the style recalculation, the currently hovered element might have been
@ -1573,15 +1570,6 @@ void Document::updateBaseURL()
if (!m_baseURL.isValid())
m_baseURL = KURL();
// FIXME(sky): remove?
if (m_elemSheet) {
// Element sheet is silly. It never contains anything.
bool usesRemUnits = m_elemSheet->contents()->usesRemUnits();
m_elemSheet = CSSStyleSheet::create(this, m_baseURL);
// FIXME: So we are not really the parser. The right fix is to eliminate the element sheet completely.
m_elemSheet->contents()->parserSetUsesRemUnits(usesRemUnits);
}
}
void Document::didLoadAllImports()

View File

@ -76,8 +76,6 @@ void DocumentStyleSheetCollection::updateActiveStyleSheets(StyleEngine* engine)
document().setNeedsStyleRecalc(SubtreeStyleChange);
collection.swap(*this);
updateUsesRemUnits();
}
}

View File

@ -70,7 +70,6 @@ void ShadowTreeStyleSheetCollection::updateActiveStyleSheets(StyleEngine* engine
toShadowRoot(treeScope().rootNode()).host()->setNeedsStyleRecalc(SubtreeStyleChange);
collection.swap(*this);
updateUsesRemUnits();
}
}

View File

@ -47,7 +47,6 @@ StyleEngine::StyleEngine(Document& document)
, m_isMaster(!document.importsController() || document.importsController()->master() == &document)
, m_documentStyleSheetCollection(DocumentStyleSheetCollection::create(document))
, m_documentScopeDirty(true)
, m_usesRemUnits(false)
, m_ignorePendingStylesheets(false)
// We don't need to create CSSFontSelector for imported document or
// HTMLTemplateElement's document, because those documents have no frame.
@ -236,8 +235,6 @@ void StyleEngine::updateActiveStyleSheets()
}
m_activeTreeScopes.removeAll(treeScopesRemoved);
m_usesRemUnits = documentStyleSheetCollection()->usesRemUnits();
m_dirtyTreeScopes.clear();
m_documentScopeDirty = false;
}

View File

@ -88,9 +88,6 @@ public:
// FIXME(sky): Remove this and ::first-line.
bool usesFirstLineRules() const { return false; }
bool usesRemUnits() const { return m_usesRemUnits; }
void setUsesRemUnit(bool b) { m_usesRemUnits = b; }
void didRemoveShadowRoot(ShadowRoot*);
void appendActiveAuthorStyleSheets();
@ -181,8 +178,6 @@ private:
TreeScopeSet m_dirtyTreeScopes;
TreeScopeSet m_activeTreeScopes;
bool m_usesRemUnits;
bool m_ignorePendingStylesheets;
OwnPtr<StyleResolver> m_resolver;

View File

@ -38,7 +38,6 @@ namespace blink {
TreeScopeStyleSheetCollection::TreeScopeStyleSheetCollection(TreeScope& treeScope)
: m_treeScope(treeScope)
, m_usesRemUnits(false)
{
}
@ -68,18 +67,4 @@ void TreeScopeStyleSheetCollection::clearMediaQueryRuleSetStyleSheets()
}
}
static bool styleSheetsUseRemUnits(const Vector<RefPtr<CSSStyleSheet> >& sheets)
{
for (unsigned i = 0; i < sheets.size(); ++i) {
if (sheets[i]->contents()->usesRemUnits())
return true;
}
return false;
}
void TreeScopeStyleSheetCollection::updateUsesRemUnits()
{
m_usesRemUnits = styleSheetsUseRemUnits(m_activeAuthorStyleSheets);
}
}

View File

@ -52,8 +52,6 @@ public:
void removeStyleSheetCandidateNode(Node*, ContainerNode* scopingNode);
bool hasStyleSheetCandidateNodes() const { return !m_styleSheetCandidateNodes.isEmpty(); }
bool usesRemUnits() const { return m_usesRemUnits; }
DocumentOrderedList& styleSheetCandidateNodes() { return m_styleSheetCandidateNodes; }
void clearMediaQueryRuleSetStyleSheets();
@ -70,11 +68,8 @@ protected:
Additive
};
void updateUsesRemUnits();
protected:
RawPtr<TreeScope> m_treeScope;
bool m_usesRemUnits;
DocumentOrderedList m_styleSheetCandidateNodes;
};