Join GitHub today
GitHub is home to over 50 million developers working together to host and review code, manage projects, and build software together.
Sign upAdding all the relevant mutations #21680
Conversation
highfive
commented
Sep 11, 2018
|
Heads up! This PR modifies the following files:
|
0c572aa
to
8099b63
|
@jdm No new test passed after adding the relevant mutations. Is there something that I am missing? |
| &local_name!("src") => self.update_the_image_data(), | ||
| &local_name!("srcset") => self.update_the_image_data(), | ||
| &local_name!("src") | &local_name!("srcset") | | ||
| &local_name!("width") | &local_name!("crossorigin") => self.update_the_image_data(), |
This comment has been minimized.
This comment has been minimized.
jdm
Sep 13, 2018
Member
This should include sizes according to https://html.spec.whatwg.org/multipage/images.html#reacting-to-dom-mutations
| &local_name!("src") => self.update_the_image_data(), | ||
| &local_name!("srcset") => self.update_the_image_data(), | ||
| &local_name!("src") | &local_name!("srcset") | | ||
| &local_name!("width") | &local_name!("crossorigin") => self.update_the_image_data(), | ||
| _ => {}, | ||
| } | ||
| if let Some(parent) = self.upcast::<Node>().GetParentElement() { |
This comment has been minimized.
This comment has been minimized.
jdm
Sep 13, 2018
Member
I don't think we want to update the image data whenever any attribute was modified and the parent is a picture element. I'm not sure why this code is here, so let's remove it.
| @@ -1528,6 +1528,15 @@ impl VirtualMethods for HTMLImageElement { | |||
| self.super_type().unwrap().unbind_from_tree(context); | |||
| let document = document_from_node(self); | |||
| document.unregister_responsive_image(self); | |||
| if let Some(parent) = self.upcast::<Node>().GetParentElement() { | |||
This comment has been minimized.
This comment has been minimized.
jdm
Sep 13, 2018
Member
I think we'll need to check context.parent here instead. Removing the node from the tree may mean that it has no parent element according to the Node APIs. This will address the " removed from a picture parent element" mutation.
| if let Some(parent) = self.upcast::<Node>().GetParentElement() { | ||
| if parent.is::<HTMLPictureElement>() { | ||
| if let Some(previous_sibling) = self.upcast::<Node>().GetPreviousSibling() { | ||
| if previous_sibling.is::<HTMLSourceElement> () { |
This comment has been minimized.
This comment has been minimized.
jdm
Sep 13, 2018
Member
Is this trying to address "The element's parent is a picture element and a source element that was a previous sibling is removed."? We need to check for that state in the HTMLSourceElement::unbind_from_tree instead.
This comment has been minimized.
This comment has been minimized.
paavininanda
Sep 14, 2018
Author
Contributor
Yes, I tried to do it here because of the discussion that we had on Gitter. Will change this
| match attr.local_name() { | ||
| &local_name!("srcset") | &local_name!("sizes") | | ||
| &local_name!("media") | &local_name!("type") => { | ||
| if let Some(next_sibling) = self.upcast::<Node>().GetNextSibling() { |
This comment has been minimized.
This comment has been minimized.
jdm
Sep 13, 2018
Member
We will need to iterate over self.upcast::<Node>().following_siblings() instead of just getting the immediately following sibling.
| .map_or(false, |p| p.is::<HTMLPictureElement>()); | ||
| if is_parent_picture { | ||
| img.update_the_image_data(); | ||
| } |
This comment has been minimized.
This comment has been minimized.
jdm
Sep 13, 2018
Member
I don't think it makes sense to implement these mutation checks here. It splits the implementation between multiple files so it's harder to understand how the pieces fit together.
| } | ||
|
|
||
| pub fn unregister_responsive_image(&self, img: &HTMLImageElement) { | ||
| let index = self.responsive_images.borrow().iter().position(|x| **x == *img); | ||
| if let Some(i) = index { | ||
| self.responsive_images.borrow_mut().remove(i); | ||
| let elem = img.upcast::<Element>(); |
This comment has been minimized.
This comment has been minimized.
|
Closer! |
| if let Some(htmlimageelement_sibling) = next_sibling.downcast::<HTMLImageElement>() { | ||
| htmlimageelement_sibling.update_the_image_data(); | ||
| let mut next_siblings_iterator = self.upcast::<Node>().following_siblings(); | ||
| if let Some(next_sibling) = next_siblings_iterator.next() { |
This comment has been minimized.
This comment has been minimized.
jdm
Sep 14, 2018
Member
You will want to use a for loop to iterate over all the siblings, not just check the immediate sibling.
This comment has been minimized.
This comment has been minimized.
| &local_name!("srcset") | &local_name!("sizes") | | ||
| &local_name!("media") | &local_name!("type") => { | ||
| let mut next_siblings_iterator = self.upcast::<Node>().following_siblings(); | ||
| if let Some(next_sibling) = next_siblings_iterator.next() { |
This comment has been minimized.
This comment has been minimized.
jdm
Sep 14, 2018
Member
You will want to use a for loop to iterate over the siblings, rather than only checking the immediate sibling.
| /// <https://html.spec.whatwg.org/multipage/#the-source-element:nodes-are-inserted> | ||
| fn bind_to_tree(&self, tree_in_doc: bool) { | ||
| self.super_type().unwrap().bind_to_tree(tree_in_doc); | ||
| let parent = self.upcast::<Node>().GetParentNode().unwrap(); | ||
| if let Some(media) = parent.downcast::<HTMLMediaElement>() { | ||
| media.handle_source_child_insertion(); | ||
| } | ||
|
|
||
| let mut next_siblings_iterator = self.upcast::<Node>().following_siblings(); | ||
| if let Some(next_sibling) = next_siblings_iterator.next() { |
This comment has been minimized.
This comment has been minimized.
jdm
Sep 14, 2018
Member
It would be worth creating a helper function for the sibling iterator check to avoid duplicating this code.
| fn unbind_from_tree(&self, context: &UnbindContext) { | ||
| self.super_type().unwrap().unbind_from_tree(context); | ||
|
|
||
| let mut next_siblings_iterator = self.upcast::<Node>().following_siblings(); |
This comment has been minimized.
This comment has been minimized.
jdm
Sep 14, 2018
Member
Because we're unbinding, we need to be careful. You will want to use the next_sibling member of UnbindContext and call inclusive_next_sibling on that node instead, then loop over the iterator.
This comment has been minimized.
This comment has been minimized.
paavininanda
Sep 14, 2018
Author
Contributor
There is a prev_sibling in UnbindContext but not a next_sibling! I was trying to find it here - https://doc.servo.org/script/dom/node/struct.UnbindContext.html
This comment has been minimized.
This comment has been minimized.
|
This looks great! Please also remove and update the test expectations for that test! |
|
Nice solution using |
|
@bors-servo r+ |
|
|
Adding all the relevant mutations <!-- Please describe your changes on the following line: --> --- <!-- Thank you for contributing to Servo! Please replace each `[ ]` by `[X]` when the step is complete, and replace `__` with appropriate data: --> - [x] `./mach build -d` does not report any errors - [x] `./mach test-tidy` does not report any errors - [x] These changes fix a subset of #11416 <!-- Either: --> - [x] These changes do not require tests <!-- Also, please make sure that "Allow edits from maintainers" checkbox is checked, so that we can help you if you get stuck somewhere along the way.--> <!-- Pull requests that do not address these steps are welcome, but they will require additional verification as part of the review process. --> <!-- 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/21680) <!-- Reviewable:end -->
|
|
|
@jdm These all seem to be intermittent failures! |
|
I strongly suspect that these test result changes are not intermittent but triggered by #21751. |
|
Indeed, the same result appeared on both mac and linux: |
|
@bors-servo r=jdm |
|
|
Adding all the relevant mutations <!-- Please describe your changes on the following line: --> --- <!-- Thank you for contributing to Servo! Please replace each `[ ]` by `[X]` when the step is complete, and replace `__` with appropriate data: --> - [x] `./mach build -d` does not report any errors - [x] `./mach test-tidy` does not report any errors - [x] These changes fix a subset of #11416 <!-- Either: --> - [x] These changes do not require tests <!-- Also, please make sure that "Allow edits from maintainers" checkbox is checked, so that we can help you if you get stuck somewhere along the way.--> <!-- Pull requests that do not address these steps are welcome, but they will require additional verification as part of the review process. --> <!-- 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/21680) <!-- Reviewable:end -->
|
|
|
@bors-servo retry |
Adding all the relevant mutations <!-- Please describe your changes on the following line: --> --- <!-- Thank you for contributing to Servo! Please replace each `[ ]` by `[X]` when the step is complete, and replace `__` with appropriate data: --> - [x] `./mach build -d` does not report any errors - [x] `./mach test-tidy` does not report any errors - [x] These changes fix a subset of #11416 <!-- Either: --> - [x] These changes do not require tests <!-- Also, please make sure that "Allow edits from maintainers" checkbox is checked, so that we can help you if you get stuck somewhere along the way.--> <!-- Pull requests that do not address these steps are welcome, but they will require additional verification as part of the review process. --> <!-- 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/21680) <!-- Reviewable:end -->
|
|
paavininanda commentedSep 11, 2018
•
edited by SimonSapin
./mach build -ddoes not report any errors./mach test-tidydoes not report any errorsThis change is