Skip to content

Commit

Permalink
Bug 1852478 - Convert CSS white-space into a shorthand that expands…
Browse files Browse the repository at this point in the history
… to `white-space-collapse` and `text-wrap-mode` longhands. r=firefox-style-system-reviewers,emilio

Note that although this builds, it would (by itself) result in some test breakage;
this is resolved in the following patches that build on this.

Differential Revision: https://phabricator.services.mozilla.com/D198790
  • Loading branch information
jfkthame committed Jan 26, 2024
1 parent 6c3ac6c commit 5741b2b
Show file tree
Hide file tree
Showing 18 changed files with 345 additions and 172 deletions.
87 changes: 78 additions & 9 deletions dom/base/use_counter_metrics.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -131,8 +131,8 @@ use.counter.error:
send_in_pings:
- use-counters

# Total of 2301 use counter metrics (excludes denominators).
# Total of 357 'page' use counters.
# Total of 2307 use counter metrics (excludes denominators).
# Total of 358 'page' use counters.
use.counter.page:
svgsvgelement_getelementbyid:
type: counter
Expand Down Expand Up @@ -6220,7 +6220,7 @@ use.counter.page:
send_in_pings:
- use-counters

# Total of 357 'document' use counters.
# Total of 358 'document' use counters.
use.counter.doc:
svgsvgelement_getelementbyid:
type: counter
Expand Down Expand Up @@ -15735,7 +15735,7 @@ use.counter.deprecated_ops.doc:
send_in_pings:
- use-counters

# Total of 693 'CSS (page)' use counters.
# Total of 695 'CSS (page)' use counters.
use.counter.css.page:
css_align_content:
type: counter
Expand Down Expand Up @@ -17709,6 +17709,23 @@ use.counter.css.page:
send_in_pings:
- use-counters

css_text_wrap_mode:
type: counter
description: >
Whether a page used the CSS property text-wrap-mode.
Compare against `use.counter.top_level_content_documents_destroyed`
to calculate the rate.
bugs:
- https://bugzilla.mozilla.org/show_bug.cgi?id=1852098
data_reviews:
- https://bugzilla.mozilla.org/show_bug.cgi?id=1852098
notification_emails:
- [email protected]
- [email protected]
expires: never
send_in_pings:
- use-counters

css_touch_action:
type: counter
description: >
Expand Down Expand Up @@ -17862,10 +17879,10 @@ use.counter.css.page:
send_in_pings:
- use-counters

css_white_space:
css_white_space_collapse:
type: counter
description: >
Whether a page used the CSS property white-space.
Whether a page used the CSS property white-space-collapse.
Compare against `use.counter.top_level_content_documents_destroyed`
to calculate the rate.
bugs:
Expand Down Expand Up @@ -23251,6 +23268,23 @@ use.counter.css.page:
send_in_pings:
- use-counters

css_white_space:
type: counter
description: >
Whether a page used the CSS property white-space.
Compare against `use.counter.top_level_content_documents_destroyed`
to calculate the rate.
bugs:
- https://bugzilla.mozilla.org/show_bug.cgi?id=1852098
data_reviews:
- https://bugzilla.mozilla.org/show_bug.cgi?id=1852098
notification_emails:
- [email protected]
- [email protected]
expires: never
send_in_pings:
- use-counters

css_webkit_text_stroke:
type: counter
description: >
Expand Down Expand Up @@ -27518,7 +27552,7 @@ use.counter.css.page:
send_in_pings:
- use-counters

# Total of 693 'CSS (document)' use counters.
# Total of 695 'CSS (document)' use counters.
use.counter.css.doc:
css_align_content:
type: counter
Expand Down Expand Up @@ -29492,6 +29526,23 @@ use.counter.css.doc:
send_in_pings:
- use-counters

css_text_wrap_mode:
type: counter
description: >
Whether a document used the CSS property text-wrap-mode.
Compare against `use.counter.content_documents_destroyed`
to calculate the rate.
bugs:
- https://bugzilla.mozilla.org/show_bug.cgi?id=1852098
data_reviews:
- https://bugzilla.mozilla.org/show_bug.cgi?id=1852098
notification_emails:
- [email protected]
- [email protected]
expires: never
send_in_pings:
- use-counters

css_touch_action:
type: counter
description: >
Expand Down Expand Up @@ -29645,10 +29696,10 @@ use.counter.css.doc:
send_in_pings:
- use-counters

css_white_space:
css_white_space_collapse:
type: counter
description: >
Whether a document used the CSS property white-space.
Whether a document used the CSS property white-space-collapse.
Compare against `use.counter.content_documents_destroyed`
to calculate the rate.
bugs:
Expand Down Expand Up @@ -35034,6 +35085,23 @@ use.counter.css.doc:
send_in_pings:
- use-counters

css_white_space:
type: counter
description: >
Whether a document used the CSS property white-space.
Compare against `use.counter.content_documents_destroyed`
to calculate the rate.
bugs:
- https://bugzilla.mozilla.org/show_bug.cgi?id=1852098
data_reviews:
- https://bugzilla.mozilla.org/show_bug.cgi?id=1852098
notification_emails:
- [email protected]
- [email protected]
expires: never
send_in_pings:
- use-counters

css_webkit_text_stroke:
type: counter
description: >
Expand Down Expand Up @@ -39300,3 +39368,4 @@ use.counter.css.doc:
expires: never
send_in_pings:
- use-counters

7 changes: 5 additions & 2 deletions dom/html/HTMLPreElement.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,11 @@ void HTMLPreElement::MapAttributesIntoRule(
MappedDeclarationsBuilder& aBuilder) {
// wrap: empty
if (aBuilder.GetAttr(nsGkAtoms::wrap)) {
aBuilder.SetKeywordValue(eCSSProperty_white_space,
StyleWhiteSpace::PreWrap);
// Equivalent to expanding `white-space: pre-wrap`
aBuilder.SetKeywordValue(eCSSProperty_white_space_collapse,
StyleWhiteSpaceCollapse::Preserve);
aBuilder.SetKeywordValue(eCSSProperty_text_wrap_mode,
StyleTextWrapMode::Wrap);
}

nsGenericHTMLElement::MapCommonAttributesInto(aBuilder);
Expand Down
6 changes: 3 additions & 3 deletions dom/html/HTMLTableCellElement.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -163,16 +163,16 @@ void HTMLTableCellElement::MapAttributesIntoRule(
MappedDeclarationsBuilder& aBuilder) {
MapImageSizeAttributesInto(aBuilder);

if (!aBuilder.PropertyIsSet(eCSSProperty_white_space)) {
if (!aBuilder.PropertyIsSet(eCSSProperty_text_wrap_mode)) {
// nowrap: enum
if (aBuilder.GetAttr(nsGkAtoms::nowrap)) {
// See if our width is not a nonzero integer width.
const nsAttrValue* value = aBuilder.GetAttr(nsGkAtoms::width);
nsCompatibility mode = aBuilder.Document().GetCompatibilityMode();
if (!value || value->Type() != nsAttrValue::eInteger ||
value->GetIntegerValue() == 0 || eCompatibility_NavQuirks != mode) {
aBuilder.SetKeywordValue(eCSSProperty_white_space,
StyleWhiteSpace::Nowrap);
aBuilder.SetKeywordValue(eCSSProperty_text_wrap_mode,
StyleTextWrapMode::Nowrap);
}
}
}
Expand Down
14 changes: 8 additions & 6 deletions dom/html/HTMLTextAreaElement.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -365,12 +365,14 @@ bool HTMLTextAreaElement::ParseAttribute(int32_t aNamespaceID,
void HTMLTextAreaElement::MapAttributesIntoRule(
MappedDeclarationsBuilder& aBuilder) {
// wrap=off
if (!aBuilder.PropertyIsSet(eCSSProperty_white_space)) {
const nsAttrValue* value = aBuilder.GetAttr(nsGkAtoms::wrap);
if (value && value->Type() == nsAttrValue::eString &&
value->Equals(nsGkAtoms::OFF, eIgnoreCase)) {
aBuilder.SetKeywordValue(eCSSProperty_white_space, StyleWhiteSpace::Pre);
}
const nsAttrValue* value = aBuilder.GetAttr(nsGkAtoms::wrap);
if (value && value->Type() == nsAttrValue::eString &&
value->Equals(nsGkAtoms::OFF, eIgnoreCase)) {
// Equivalent to expanding `white-space; pre`
aBuilder.SetKeywordValue(eCSSProperty_white_space_collapse,
StyleWhiteSpaceCollapse::Preserve);
aBuilder.SetKeywordValue(eCSSProperty_text_wrap_mode,
StyleTextWrapMode::Nowrap);
}

nsGenericHTMLFormControlElementWithState::MapDivAlignAttributeInto(aBuilder);
Expand Down
11 changes: 7 additions & 4 deletions editor/libeditor/EditorUtils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -89,8 +89,8 @@ bool EditorUtils::IsDescendantOf(const nsINode& aNode, const nsINode& aParent,
}

// static
Maybe<StyleWhiteSpace> EditorUtils::GetComputedWhiteSpaceStyle(
const nsIContent& aContent) {
Maybe<std::pair<StyleWhiteSpaceCollapse, StyleTextWrapMode>>
EditorUtils::GetComputedWhiteSpaceStyles(const nsIContent& aContent) {
if (MOZ_UNLIKELY(!aContent.IsElement() && !aContent.GetParentElement())) {
return Nothing();
}
Expand All @@ -101,7 +101,9 @@ Maybe<StyleWhiteSpace> EditorUtils::GetComputedWhiteSpaceStyle(
if (NS_WARN_IF(!elementStyle)) {
return Nothing();
}
return Some(elementStyle->StyleText()->mWhiteSpace);
const auto* styleText = elementStyle->StyleText();
return Some(
std::pair(styleText->mWhiteSpaceCollapse, styleText->mTextWrapMode));
}

// static
Expand Down Expand Up @@ -164,7 +166,8 @@ bool EditorUtils::IsOnlyNewLinePreformatted(const nsIContent& aContent) {
return false;
}

return elementStyle->StyleText()->mWhiteSpace == StyleWhiteSpace::PreLine;
return elementStyle->StyleText()->mWhiteSpaceCollapse ==
StyleWhiteSpaceCollapse::PreserveBreaks;
}

// static
Expand Down
8 changes: 4 additions & 4 deletions editor/libeditor/EditorUtils.h
Original file line number Diff line number Diff line change
Expand Up @@ -401,10 +401,10 @@ class EditorUtils final {
}

/**
* Get computed white-space style of aContent.
* Get the two longhands that make up computed white-space style of aContent.
*/
static Maybe<StyleWhiteSpace> GetComputedWhiteSpaceStyle(
const nsIContent& aContent);
static Maybe<std::pair<StyleWhiteSpaceCollapse, StyleTextWrapMode>>
GetComputedWhiteSpaceStyles(const nsIContent& aContent);

/**
* IsWhiteSpacePreformatted() checks the style info for the node for the
Expand All @@ -421,7 +421,7 @@ class EditorUtils final {
/**
* IsOnlyNewLinePreformatted() checks whether the linefeed characters are
* preformated but white-spaces are collapsed, or otherwise. I.e., this
* returns true only when `white-space:pre-line`.
* returns true only when `white-space-collapse:pre-line`.
*/
static bool IsOnlyNewLinePreformatted(const nsIContent& aContent);

Expand Down
Loading

0 comments on commit 5741b2b

Please sign in to comment.