Skip to content

Commit ca67bf8

Browse files
committed
Bug 2019254 Part 1 - Use indices in CSSContainerRule glue for conditions. r=firefox-style-system-reviewers,emilio
Differential Revision: https://phabricator.services.mozilla.com/D290611
1 parent 4ad704f commit ca67bf8

2 files changed

Lines changed: 43 additions & 23 deletions

File tree

layout/style/CSSContainerRule.cpp

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -57,18 +57,28 @@ void CSSContainerRule::GetCssText(nsACString& aCssText) const {
5757
}
5858

5959
void CSSContainerRule::GetContainerName(nsACString& aName) const {
60-
Servo_ContainerRule_GetContainerName(mRawRule, &aName);
60+
const size_t n = Servo_ContainerRule_GetConditionsLength(mRawRule);
61+
if (n == 1) {
62+
Servo_ContainerRule_GetContainerName(mRawRule, 0, &aName);
63+
}
6164
}
6265

6366
void CSSContainerRule::GetContainerQuery(nsACString& aQuery) const {
64-
Servo_ContainerRule_GetContainerQuery(mRawRule, &aQuery);
67+
const size_t n = Servo_ContainerRule_GetConditionsLength(mRawRule);
68+
if (n == 1) {
69+
Servo_ContainerRule_GetContainerQuery(mRawRule, 0, &aQuery);
70+
}
6571
}
6672

6773
void CSSContainerRule::GetConditions(
6874
nsTArray<CSSContainerCondition>& aConditions) const {
69-
auto& condition = *aConditions.AppendElement();
70-
GetContainerName(condition.mName);
71-
GetContainerQuery(condition.mQuery);
75+
const size_t n = Servo_ContainerRule_GetConditionsLength(mRawRule);
76+
aConditions.SetCapacity(n);
77+
for (size_t i = 0; i < n; i++) {
78+
CSSContainerCondition& condition = *aConditions.AppendElement();
79+
Servo_ContainerRule_GetContainerName(mRawRule, i, &condition.mName);
80+
Servo_ContainerRule_GetContainerQuery(mRawRule, i, &condition.mQuery);
81+
}
7282
}
7383

7484
Element* CSSContainerRule::QueryContainerFor(const Element& aElement) const {

servo/ports/geckolib/glue.rs

Lines changed: 28 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -3457,38 +3457,48 @@ pub extern "C" fn Servo_ContainerRule_GetConditionText(
34573457
}
34583458

34593459
#[no_mangle]
3460-
pub extern "C" fn Servo_ContainerRule_GetContainerQuery(
3460+
pub extern "C" fn Servo_ContainerRule_GetConditionsLength(rule: &ContainerRule) -> usize {
3461+
rule.conditions.0.len()
3462+
}
3463+
3464+
#[no_mangle]
3465+
pub extern "C" fn Servo_ContainerRule_GetContainerName(
34613466
rule: &ContainerRule,
3467+
i: usize,
34623468
result: &mut nsACString,
34633469
) {
3464-
if let Some(condition) = rule.conditions.0.first().and_then(|c| c.query_condition()){
3465-
condition.to_css(&mut CssWriter::new(result)).unwrap();
3470+
if let Some(condition) = rule.conditions.0.get(i) {
3471+
let name = condition.name();
3472+
if !name.is_none() {
3473+
name.to_css(&mut CssWriter::new(result)).unwrap();
3474+
}
34663475
}
34673476
}
34683477

34693478
#[no_mangle]
3470-
pub extern "C" fn Servo_ContainerRule_QueryContainerFor(
3479+
pub extern "C" fn Servo_ContainerRule_GetContainerQuery(
34713480
rule: &ContainerRule,
3472-
element: &RawGeckoElement,
3473-
) -> *const RawGeckoElement {
3474-
debug_assert_eq!(rule.conditions.0.len(), 1);
3475-
let condition = rule.conditions.0.first().unwrap();
3476-
condition
3477-
.find_container(GeckoElement(element), None)
3478-
.map_or(ptr::null(), |result| result.element.0)
3481+
i: usize,
3482+
result: &mut nsACString,
3483+
) {
3484+
if let Some(condition) = rule.conditions.0.get(i) {
3485+
if let Some(condition) = condition.query_condition() {
3486+
condition.to_css(&mut CssWriter::new(result)).unwrap();
3487+
}
3488+
}
34793489
}
34803490

34813491
#[no_mangle]
3482-
pub extern "C" fn Servo_ContainerRule_GetContainerName(
3492+
pub extern "C" fn Servo_ContainerRule_QueryContainerFor(
34833493
rule: &ContainerRule,
3484-
result: &mut nsACString,
3485-
) {
3486-
if let Some(condition) = rule.conditions.0.first() {
3487-
let name = condition.name();
3488-
if !name.is_none() {
3489-
name.to_css(&mut CssWriter::new(result)).unwrap();
3494+
element: &RawGeckoElement,
3495+
) -> *const RawGeckoElement {
3496+
for condition in rule.conditions.0.iter() {
3497+
if let Some(result) = condition.find_container(GeckoElement(element), None) {
3498+
return result.element.0;
34903499
}
34913500
}
3501+
ptr::null()
34923502
}
34933503

34943504
#[no_mangle]

0 commit comments

Comments
 (0)