mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-11-26 06:11:37 +00:00
Bug 1691858 - Minor cleanup of our @page rule setup. r=AlaskanEmily
Actually, there's not so much we can improve right now, in the sense that: * We need the ::-moz-page-content pseudo-element to be able to set `display` on the page, since that's a style rule rather than a @page rule. We could get away without it. * Keeping the current code-path (slightly cleaned up) is less code, for now at least. We can have a separate code-path or what not that actually performs the @page rule selector-matching and what not if needed when we get to named pages or other page selectors. Selectors like :first should be pretty trivial to implement, actually. We make some paged mode anon boxes non-inheriting anon boxes. This allows us to share the styles and is generally nicer. They don't need to inherit from anywhere. We could remove the origin handling and don't look at UA rules or what not, but it seems pretty harmless to do that. We also fix the name of the pseudo-elements to match the capitalization. Differential Revision: https://phabricator.services.mozilla.com/D104772
This commit is contained in:
parent
a5dea5e689
commit
216b9a6afb
@ -2691,12 +2691,9 @@ void nsCSSFrameConstructor::ConstructAnonymousContentForCanvas(
|
||||
PrintedSheetFrame* nsCSSFrameConstructor::ConstructPrintedSheetFrame(
|
||||
PresShell* aPresShell, nsContainerFrame* aParentFrame,
|
||||
nsIFrame* aPrevSheetFrame) {
|
||||
ComputedStyle* parentComputedStyle = aParentFrame->Style();
|
||||
ServoStyleSet* styleSet = aPresShell->StyleSet();
|
||||
|
||||
RefPtr<ComputedStyle> printedSheetPseudoStyle =
|
||||
styleSet->ResolveInheritingAnonymousBoxStyle(
|
||||
PseudoStyleType::printedSheet, parentComputedStyle);
|
||||
aPresShell->StyleSet()->ResolveNonInheritingAnonymousBoxStyle(
|
||||
PseudoStyleType::printedSheet);
|
||||
|
||||
auto* printedSheetFrame =
|
||||
NS_NewPrintedSheetFrame(aPresShell, printedSheetPseudoStyle);
|
||||
@ -2709,12 +2706,10 @@ PrintedSheetFrame* nsCSSFrameConstructor::ConstructPrintedSheetFrame(
|
||||
nsContainerFrame* nsCSSFrameConstructor::ConstructPageFrame(
|
||||
PresShell* aPresShell, nsContainerFrame* aParentFrame,
|
||||
nsIFrame* aPrevPageFrame, nsContainerFrame*& aCanvasFrame) {
|
||||
ComputedStyle* parentComputedStyle = aParentFrame->Style();
|
||||
ServoStyleSet* styleSet = aPresShell->StyleSet();
|
||||
|
||||
RefPtr<ComputedStyle> pagePseudoStyle =
|
||||
styleSet->ResolveInheritingAnonymousBoxStyle(PseudoStyleType::page,
|
||||
parentComputedStyle);
|
||||
styleSet->ResolveNonInheritingAnonymousBoxStyle(PseudoStyleType::page);
|
||||
|
||||
nsContainerFrame* pageFrame = NS_NewPageFrame(aPresShell, pagePseudoStyle);
|
||||
|
||||
@ -2723,8 +2718,8 @@ nsContainerFrame* nsCSSFrameConstructor::ConstructPageFrame(
|
||||
pageFrame->Init(nullptr, aParentFrame, aPrevPageFrame);
|
||||
|
||||
RefPtr<ComputedStyle> pageContentPseudoStyle;
|
||||
pageContentPseudoStyle = styleSet->ResolveInheritingAnonymousBoxStyle(
|
||||
PseudoStyleType::pageContent, pagePseudoStyle);
|
||||
pageContentPseudoStyle = styleSet->ResolveNonInheritingAnonymousBoxStyle(
|
||||
PseudoStyleType::pageContent);
|
||||
|
||||
nsContainerFrame* pageContentFrame =
|
||||
NS_NewPageContentFrame(aPresShell, pageContentPseudoStyle);
|
||||
|
@ -528,12 +528,6 @@ ServoStyleSet::ResolveInheritingAnonymousBoxStyle(PseudoStyleType aType,
|
||||
already_AddRefed<ComputedStyle>
|
||||
ServoStyleSet::ResolveNonInheritingAnonymousBoxStyle(PseudoStyleType aType) {
|
||||
MOZ_ASSERT(PseudoStyle::IsNonInheritingAnonBox(aType));
|
||||
MOZ_ASSERT(aType != PseudoStyleType::pageContent,
|
||||
"If pageContent ends up non-inheriting, check "
|
||||
"whether we need to do anything to move the "
|
||||
"@page handling from ResolveInheritingAnonymousBoxStyle to "
|
||||
"ResolveNonInheritingAnonymousBoxStyle");
|
||||
|
||||
nsCSSAnonBoxes::NonInheriting type =
|
||||
nsCSSAnonBoxes::NonInheritingTypeForPseudoType(aType);
|
||||
RefPtr<ComputedStyle>& cache = mNonInheritingComputedStyles[type];
|
||||
|
@ -70,7 +70,10 @@ CSS_NON_INHERITING_ANON_BOX(framesetBlank, ":-moz-frameset-blank")
|
||||
CSS_NON_INHERITING_ANON_BOX(tableColGroup, ":-moz-table-column-group")
|
||||
CSS_NON_INHERITING_ANON_BOX(tableCol, ":-moz-table-column")
|
||||
|
||||
CSS_NON_INHERITING_ANON_BOX(pageBreak, ":-moz-pagebreak")
|
||||
CSS_NON_INHERITING_ANON_BOX(page, ":-moz-page")
|
||||
CSS_NON_INHERITING_ANON_BOX(pageBreak, ":-moz-page-break")
|
||||
CSS_NON_INHERITING_ANON_BOX(pageContent, ":-moz-page-content")
|
||||
CSS_NON_INHERITING_ANON_BOX(printedSheet, ":-moz-printed-sheet")
|
||||
|
||||
// Applies to blocks that wrap contiguous runs of "column-span: all"
|
||||
// elements in multi-column subtrees, or the wrappers themselves, all the
|
||||
@ -108,10 +111,7 @@ CSS_WRAPPER_ANON_BOX(tableRowGroup, ":-moz-table-row-group")
|
||||
CSS_WRAPPER_ANON_BOX(tableRow, ":-moz-table-row")
|
||||
|
||||
CSS_ANON_BOX(canvas, ":-moz-canvas")
|
||||
CSS_ANON_BOX(page, ":-moz-page")
|
||||
CSS_ANON_BOX(pageContent, ":-moz-pagecontent")
|
||||
CSS_ANON_BOX(pageSequence, ":-moz-page-sequence")
|
||||
CSS_ANON_BOX(printedSheet, ":-moz-printed-sheet")
|
||||
CSS_ANON_BOX(scrolledContent, ":-moz-scrolled-content")
|
||||
CSS_ANON_BOX(scrolledCanvas, ":-moz-scrolled-canvas")
|
||||
CSS_ANON_BOX(scrolledPageSequence, ":-moz-scrolled-page-sequence")
|
||||
|
@ -319,12 +319,12 @@
|
||||
}
|
||||
}
|
||||
|
||||
*|*::-moz-pagecontent {
|
||||
*|*::-moz-page-content {
|
||||
display: block;
|
||||
margin: auto;
|
||||
}
|
||||
|
||||
*|*::-moz-pagebreak {
|
||||
*|*::-moz-page-break {
|
||||
display: block;
|
||||
}
|
||||
|
||||
|
@ -669,7 +669,7 @@ impl Stylist {
|
||||
{
|
||||
debug_assert!(pseudo.is_precomputed());
|
||||
|
||||
let rule_node = self.rule_node_for_precomputed_pseudo(guards, pseudo, None);
|
||||
let rule_node = self.rule_node_for_precomputed_pseudo(guards, pseudo, vec![]);
|
||||
|
||||
self.precomputed_values_for_pseudo_with_rule_node::<E>(
|
||||
guards,
|
||||
@ -709,42 +709,40 @@ impl Stylist {
|
||||
)
|
||||
}
|
||||
|
||||
/// Returns the rule node for given precomputed pseudo-element.
|
||||
/// Returns the rule node for a given precomputed pseudo-element.
|
||||
///
|
||||
/// If we want to include extra declarations to this precomputed pseudo-element,
|
||||
/// we can provide a vector of ApplicableDeclarationBlock to extra_declarations
|
||||
/// argument. This is useful for providing extra @page rules.
|
||||
/// If we want to include extra declarations to this precomputed
|
||||
/// pseudo-element, we can provide a vector of ApplicableDeclarationBlocks
|
||||
/// to extra_declarations. This is useful for @page rules.
|
||||
pub fn rule_node_for_precomputed_pseudo(
|
||||
&self,
|
||||
guards: &StylesheetGuards,
|
||||
pseudo: &PseudoElement,
|
||||
extra_declarations: Option<Vec<ApplicableDeclarationBlock>>,
|
||||
mut extra_declarations: Vec<ApplicableDeclarationBlock>,
|
||||
) -> StrongRuleNode {
|
||||
let mut decl;
|
||||
let mut declarations_with_extra;
|
||||
let declarations = match self
|
||||
.cascade_data
|
||||
.user_agent
|
||||
.precomputed_pseudo_element_decls
|
||||
.get(pseudo)
|
||||
{
|
||||
Some(declarations) => match extra_declarations {
|
||||
Some(mut extra_decls) => {
|
||||
decl = declarations.clone();
|
||||
decl.append(&mut extra_decls);
|
||||
Some(&decl)
|
||||
},
|
||||
None => Some(declarations),
|
||||
Some(declarations) => {
|
||||
if !extra_declarations.is_empty() {
|
||||
declarations_with_extra = declarations.clone();
|
||||
declarations_with_extra.append(&mut extra_declarations);
|
||||
&*declarations_with_extra
|
||||
} else {
|
||||
&**declarations
|
||||
}
|
||||
},
|
||||
None => extra_declarations.as_ref(),
|
||||
None => &[],
|
||||
};
|
||||
|
||||
match declarations {
|
||||
Some(decls) => self.rule_tree.insert_ordered_rules_with_important(
|
||||
decls.into_iter().map(|a| a.clone().for_rule_tree()),
|
||||
guards,
|
||||
),
|
||||
None => self.rule_tree.root().clone(),
|
||||
}
|
||||
self.rule_tree.insert_ordered_rules_with_important(
|
||||
declarations.into_iter().map(|a| a.clone().for_rule_tree()),
|
||||
guards,
|
||||
)
|
||||
}
|
||||
|
||||
/// Returns the style for an anonymous box of the given type.
|
||||
|
@ -3593,33 +3593,32 @@ pub unsafe extern "C" fn Servo_ComputedValues_GetForAnonymousBox(
|
||||
|
||||
let metrics = get_metrics_provider_for_product();
|
||||
|
||||
// If the pseudo element is PageContent, we should append the precomputed
|
||||
// pseudo element declerations with specified page rules.
|
||||
let page_decls = match pseudo {
|
||||
PseudoElement::PageContent => {
|
||||
let mut declarations = vec![];
|
||||
let iter = data.stylist.iter_extra_data_origins_rev();
|
||||
for (data, origin) in iter {
|
||||
let level = match origin {
|
||||
Origin::UserAgent => CascadeLevel::UANormal,
|
||||
Origin::User => CascadeLevel::UserNormal,
|
||||
Origin::Author => CascadeLevel::same_tree_author_normal(),
|
||||
};
|
||||
for rule in data.pages.iter() {
|
||||
declarations.push(ApplicableDeclarationBlock::from_declarations(
|
||||
rule.read_with(level.guard(&guards)).block.clone(),
|
||||
level,
|
||||
));
|
||||
}
|
||||
// If the pseudo element is PageContent, we should append @page rules to the
|
||||
// precomputed pseudo.
|
||||
//
|
||||
// TODO(emilio): We'll need a separate code path or extra arguments for
|
||||
// named pages, etc.
|
||||
let mut extra_declarations = vec![];
|
||||
if pseudo == PseudoElement::PageContent {
|
||||
let iter = data.stylist.iter_extra_data_origins_rev();
|
||||
for (data, origin) in iter {
|
||||
let level = match origin {
|
||||
Origin::UserAgent => CascadeLevel::UANormal,
|
||||
Origin::User => CascadeLevel::UserNormal,
|
||||
Origin::Author => CascadeLevel::same_tree_author_normal(),
|
||||
};
|
||||
for rule in data.pages.iter() {
|
||||
extra_declarations.push(ApplicableDeclarationBlock::from_declarations(
|
||||
rule.read_with(level.guard(&guards)).block.clone(),
|
||||
level,
|
||||
));
|
||||
}
|
||||
Some(declarations)
|
||||
},
|
||||
_ => None,
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
let rule_node = data
|
||||
.stylist
|
||||
.rule_node_for_precomputed_pseudo(&guards, &pseudo, page_decls);
|
||||
.rule_node_for_precomputed_pseudo(&guards, &pseudo, extra_declarations);
|
||||
|
||||
data.stylist
|
||||
.precomputed_values_for_pseudo_with_rule_node::<GeckoElement>(
|
||||
|
@ -2452,7 +2452,10 @@ STATIC_ATOMS = [
|
||||
NonInheritingAnonBoxAtom("AnonBox_framesetBlank", ":-moz-frameset-blank"),
|
||||
NonInheritingAnonBoxAtom("AnonBox_tableColGroup", ":-moz-table-column-group"),
|
||||
NonInheritingAnonBoxAtom("AnonBox_tableCol", ":-moz-table-column"),
|
||||
NonInheritingAnonBoxAtom("AnonBox_pageBreak", ":-moz-pagebreak"),
|
||||
NonInheritingAnonBoxAtom("AnonBox_page", ":-moz-page"),
|
||||
NonInheritingAnonBoxAtom("AnonBox_pageBreak", ":-moz-page-break"),
|
||||
NonInheritingAnonBoxAtom("AnonBox_pageContent", ":-moz-page-content"),
|
||||
NonInheritingAnonBoxAtom("AnonBox_printedSheet", ":-moz-printed-sheet"),
|
||||
NonInheritingAnonBoxAtom("AnonBox_columnSpanWrapper", ":-moz-column-span-wrapper"),
|
||||
InheritingAnonBoxAtom("AnonBox_mozText", ":-moz-text"),
|
||||
InheritingAnonBoxAtom("AnonBox_firstLetterContinuation", ":-moz-first-letter-continuation"),
|
||||
@ -2473,10 +2476,7 @@ STATIC_ATOMS = [
|
||||
InheritingAnonBoxAtom("AnonBox_tableRowGroup", ":-moz-table-row-group"),
|
||||
InheritingAnonBoxAtom("AnonBox_tableRow", ":-moz-table-row"),
|
||||
InheritingAnonBoxAtom("AnonBox_canvas", ":-moz-canvas"),
|
||||
InheritingAnonBoxAtom("AnonBox_page", ":-moz-page"),
|
||||
InheritingAnonBoxAtom("AnonBox_pageContent", ":-moz-pagecontent"),
|
||||
InheritingAnonBoxAtom("AnonBox_pageSequence", ":-moz-page-sequence"),
|
||||
InheritingAnonBoxAtom("AnonBox_printedSheet", ":-moz-printed-sheet"),
|
||||
InheritingAnonBoxAtom("AnonBox_scrolledContent", ":-moz-scrolled-content"),
|
||||
InheritingAnonBoxAtom("AnonBox_scrolledCanvas", ":-moz-scrolled-canvas"),
|
||||
InheritingAnonBoxAtom("AnonBox_scrolledPageSequence", ":-moz-scrolled-page-sequence"),
|
||||
|
Loading…
Reference in New Issue
Block a user