-
-
Notifications
You must be signed in to change notification settings - Fork 3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Do not use borrowed types in the selectors::Element trait. #23463
Conversation
Thanks for the pull request, and welcome! The Servo team is excited to review your changes, and you should hear from @asajeffrey (or someone else) soon. |
Heads up! This PR modifies the following files:
|
components/selectors/tree.rs
Outdated
@@ -58,10 +58,21 @@ pub trait Element: Sized + Clone + Debug { | |||
|
|||
fn is_html_element_in_html_document(&self) -> bool; | |||
|
|||
fn local_name(&self) -> &<Self::Impl as SelectorImpl>::BorrowedLocalName; | |||
fn local_name_hash(&self) -> u32; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is ugly. I know. We need three methods instead of one now...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we don't need get_local_name
or get_namespace
, instead fn local_name
and fn namespace
should move to TElement
(in components/style/dom.rs
).
components/style/selector_map.rs
Outdated
@@ -226,7 +226,7 @@ impl SelectorMap<Rule> { | |||
} | |||
}); | |||
|
|||
if let Some(rules) = self.local_name_hash.get(rule_hash_target.local_name()) { | |||
if let Some(rules) = self.local_name_hash.get(&rule_hash_target.get_local_name()) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This method invokes clone()
now. Which is bad. By I don't know how to fix it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This doesn't need to use selectors::Element
. You can move the fn local_name
signature to TElement
. So selectors
doesn't need get_local_name
, and this shouldn't need to call clone()
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the patch! Needs some changes, I think it can be simpler.
components/style/selector_map.rs
Outdated
@@ -226,7 +226,7 @@ impl SelectorMap<Rule> { | |||
} | |||
}); | |||
|
|||
if let Some(rules) = self.local_name_hash.get(rule_hash_target.local_name()) { | |||
if let Some(rules) = self.local_name_hash.get(&rule_hash_target.get_local_name()) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This doesn't need to use selectors::Element
. You can move the fn local_name
signature to TElement
. So selectors
doesn't need get_local_name
, and this shouldn't need to call clone()
.
components/style/bloom.rs
Outdated
f(element.local_name().get_hash()); | ||
f(element.namespace().get_hash()); | ||
f(element.local_name_hash()); | ||
f(element.namespace_hash()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same, this doesn't need to use selectors::Element
, and selectors
doesn't need Element::namespace_hash
.
components/selectors/tree.rs
Outdated
@@ -58,10 +58,21 @@ pub trait Element: Sized + Clone + Debug { | |||
|
|||
fn is_html_element_in_html_document(&self) -> bool; | |||
|
|||
fn local_name(&self) -> &<Self::Impl as SelectorImpl>::BorrowedLocalName; | |||
fn local_name_hash(&self) -> u32; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we don't need get_local_name
or get_namespace
, instead fn local_name
and fn namespace
should move to TElement
(in components/style/dom.rs
).
@@ -90,8 +90,7 @@ impl Invalidation { | |||
// This could look at the quirks mode of the document, instead | |||
// of testing against both names, but it's probably not worth | |||
// it. | |||
let local_name = element.local_name(); | |||
return *local_name == **name || *local_name == **lower_name; | |||
return element.has_local_name(name) || element.has_local_name(lower_name); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Similarly this shouldn't need to change.
components/style/rule_collector.rs
Outdated
@@ -42,7 +42,7 @@ pub fn containing_shadow_ignoring_svg_use<E: TElement>( | |||
loop { | |||
let host = shadow.host(); | |||
let host_is_svg_use_element = | |||
host.is_svg_element() && host.local_name() == &*local_name!("use"); | |||
host.is_svg_element() && host.has_local_name(&local_name!("use")); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
these don't need to change, but may be nicer this way, your call.
components/style/sharing/mod.rs
Outdated
|
||
if target.namespace() != candidate.element.namespace() { | ||
trace!("Miss: Namespace"); | ||
if !target.is_same_type(&candidate.element) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This doesn't need to change either, and I'd prefer to keep the two checks to remain separate to see why it fails.
&self, | ||
local_name: &<Self::Impl as ::selectors::SelectorImpl>::BorrowedLocalName, | ||
) -> bool { | ||
self.element.has_local_name(local_name) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure it this is correct.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, this is right, local name / namespace don't change.
@@ -877,6 +877,12 @@ pub trait TElement: | |||
hints: &mut V, | |||
) where | |||
V: Push<ApplicableDeclarationBlock>; | |||
|
|||
/// Returns element's local name. | |||
fn local_name(&self) -> &LocalName; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This still needs to use the Borrowed*
gunk, so that you don't break Firefox.
Also this actually needs to be implemented, right?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure what exact type should be used?
Yes. It's used in the code.
Finally, I was able to build it locally without any errors. |
@emilio ? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, sorry for the lag.
This looks great, thanks! But I need to fix the Firefox implementation as well in servo/components/style/gecko/wrapper.rs
.
So I'll land this after #23456 lands, if you don't mind.
Thanks again!
Thanks. No problem. |
I'm cherry-picking this in the next sync |
#23503 includes this commit along with the Firefox changes needed. Thanks a lot for the patch @RazrFalcon! |
…it. r=emilio This cherry-picks servo/servo#23463 with a few fixes for the Gecko build.
…it. r=emilio This cherry-picks servo/servo#23463 with a few fixes for the Gecko build.
style: sync changes from mozilla-central See each individual commit for details. This also cherry-picks #23463 with a few fixes that were needed in Gecko-only code. <!-- Reviewable:start --> --- This change is [<img src="https://reviewable.io/review_button.svg" height="34" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/servo/23503) <!-- Reviewable:end -->
style: sync changes from mozilla-central See each individual commit for details. This also cherry-picks #23463 with a few fixes that were needed in Gecko-only code. <!-- Reviewable:start --> --- This change is [<img src="https://reviewable.io/review_button.svg" height="34" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/servo/23503) <!-- Reviewable:end -->
…it. r=emilio This cherry-picks servo/servo#23463 with a few fixes for the Gecko build. UltraBlame original commit: 53a5f4a6e1de21b62be288cac96763aeece78277
…it. r=emilio This cherry-picks servo/servo#23463 with a few fixes for the Gecko build. UltraBlame original commit: 53a5f4a6e1de21b62be288cac96763aeece78277
…it. r=emilio This cherry-picks servo/servo#23463 with a few fixes for the Gecko build. UltraBlame original commit: 53a5f4a6e1de21b62be288cac96763aeece78277
This change allows implementing the
selectors::Element
trait for types that doesn't support borrowed types, like rc-tree../mach build -d
does not report any errors./mach test-tidy
does not report any errorsThis change is