Bug 1568536 - Simplify some style system APIs. r=heycam

Return a raw pointer instead of a strong reference to a ComputedStyle, and
handle the case of the style not being present by returning null rather than
requiring an extra function to check it and crashing if the precondition is not
met.

Also, name them so that it's clear they just return outdated styles and don't
make any extra effort.

This is just cleanup that makes the next patch easier / more obvious.

Differential Revision: https://phabricator.services.mozilla.com/D40080

--HG--
extra : moz-landing-system : lando
This commit is contained in:
Emilio Cobos Álvarez 2019-08-16 05:59:03 +00:00
parent bb5fdfc10c
commit a03875ef63
3 changed files with 31 additions and 51 deletions

View File

@ -4122,19 +4122,16 @@ void Element::AddSizeOfExcludingThis(nsWindowSizes& aSizes,
// Now measure just the ComputedValues (and style structs) under
// mServoData. This counts towards the relevant fields in |aSizes|.
RefPtr<ComputedStyle> sc;
if (Servo_Element_HasPrimaryComputedValues(this)) {
sc = Servo_Element_GetPrimaryComputedValues(this).Consume();
if (!aSizes.mState.HaveSeenPtr(sc.get())) {
sc->AddSizeOfIncludingThis(aSizes, &aSizes.mLayoutComputedValuesDom);
if (auto* style = Servo_Element_GetMaybeOutOfDateStyle(this)) {
if (!aSizes.mState.HaveSeenPtr(style)) {
style->AddSizeOfIncludingThis(aSizes, &aSizes.mLayoutComputedValuesDom);
}
for (size_t i = 0; i < PseudoStyle::kEagerPseudoCount; i++) {
if (Servo_Element_HasPseudoComputedValues(this, i)) {
sc = Servo_Element_GetPseudoComputedValues(this, i).Consume();
if (!aSizes.mState.HaveSeenPtr(sc.get())) {
sc->AddSizeOfIncludingThis(aSizes,
&aSizes.mLayoutComputedValuesDom);
if (auto* style = Servo_Element_GetMaybeOutOfDatePseudoStyle(this, i)) {
if (!aSizes.mState.HaveSeenPtr(style)) {
style->AddSizeOfIncludingThis(aSizes,
&aSizes.mLayoutComputedValuesDom);
}
}
}

View File

@ -4723,12 +4723,15 @@ already_AddRefed<ComputedStyle> nsCSSFrameConstructor::ResolveComputedStyle(
// can go. Note that this is not a correctness issue, since we'll restyle
// later in any case.
//
// Also, this probably doesn't need to be a strong ref...
//
// Do NOT add new callers to this function in this file, ever, or I'll find
// out.
RefPtr<ComputedStyle> parentStyle =
Servo_Element_GetPrimaryComputedValues(parent).Consume();
//
// FIXME(emilio): The const_cast is unfortunate, but it's not worse than what
// we did before.
auto* parentStyle =
const_cast<ComputedStyle*>(Servo_Element_GetMaybeOutOfDateStyle(parent));
MOZ_ASSERT(parentStyle,
"How are we inserting text frames in an unstyled element?");
return mPresShell->StyleSet()->ResolveStyleForText(aContent, parentStyle);
}

View File

@ -1230,51 +1230,31 @@ pub extern "C" fn Servo_Element_SizeOfExcludingThisAndCVs(
}
#[no_mangle]
pub extern "C" fn Servo_Element_HasPrimaryComputedValues(element: &RawGeckoElement) -> bool {
let element = GeckoElement(element);
let data = element
.borrow_data()
.expect("Looking for CVs on unstyled element");
data.has_styles()
}
#[no_mangle]
pub extern "C" fn Servo_Element_GetPrimaryComputedValues(
pub extern "C" fn Servo_Element_GetMaybeOutOfDateStyle(
element: &RawGeckoElement,
) -> Strong<ComputedValues> {
) -> *const ComputedValues {
let element = GeckoElement(element);
let data = element
.borrow_data()
.expect("Getting CVs on unstyled element");
data.styles.primary().clone().into()
let data = match element.borrow_data() {
Some(d) => d,
None => return ptr::null(),
};
&**data.styles.primary() as *const _
}
#[no_mangle]
pub extern "C" fn Servo_Element_HasPseudoComputedValues(
pub extern "C" fn Servo_Element_GetMaybeOutOfDatePseudoStyle(
element: &RawGeckoElement,
index: usize,
) -> bool {
) -> *const ComputedValues {
let element = GeckoElement(element);
let data = element
.borrow_data()
.expect("Looking for CVs on unstyled element");
data.styles.pseudos.as_array()[index].is_some()
}
#[no_mangle]
pub extern "C" fn Servo_Element_GetPseudoComputedValues(
element: &RawGeckoElement,
index: usize,
) -> Strong<ComputedValues> {
let element = GeckoElement(element);
let data = element
.borrow_data()
.expect("Getting CVs that aren't present");
data.styles.pseudos.as_array()[index]
.as_ref()
.expect("Getting CVs that aren't present")
.clone()
.into()
let data = match element.borrow_data() {
Some(d) => d,
None => return ptr::null(),
};
match data.styles.pseudos.as_array()[index].as_ref() {
Some(style) => &**style as *const _,
None => ptr::null(),
}
}
#[no_mangle]