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 upImplement update source set & select image source #21181
Conversation
highfive
commented
Jul 15, 2018
|
Heads up! This PR modifies the following files:
|
highfive
commented
Jul 15, 2018
| ); | ||
| let mut parserInput = ParserInput::new(&media_query); | ||
| let mut parser = Parser::new(&mut parserInput); | ||
| let condition = MediaCondition::parse(&context, &mut parser); |
This comment has been minimized.
This comment has been minimized.
| _ => false, | ||
| }; | ||
|
|
||
| if *(&media_query.trim().is_empty()) || result { |
This comment has been minimized.
This comment has been minimized.
emilio
Jul 16, 2018
Member
And once it does that the is_empty check is not necessary, not the owned String.
This comment has been minimized.
This comment has been minimized.
nupurbaghel
Jul 16, 2018
Author
Contributor
Do you mean that MediaList checks for empty string condition too? Or that dereferencing is not needed ?
This comment has been minimized.
This comment has been minimized.
nupurbaghel
Jul 16, 2018
Author
Contributor
@jdm Does this mean that we have to evaluate the MediaList to generate the final bool result?
This comment has been minimized.
This comment has been minimized.
emilio
Jul 16, 2018
Member
Yeah, an empty MediaList evaluates to true:
window.matchMedia("").matches
<- true
| pub struct SourceSize { | ||
| condition: MediaCondition, | ||
| value: Length, | ||
| /// https://html.spec.whatwg.org/multipage/#source-size |
This comment has been minimized.
This comment has been minimized.
emilio
Jul 16, 2018
Member
There's no need to make these public, nor below. And why is PartialEq needed?
This comment has been minimized.
This comment has been minimized.
nupurbaghel
Jul 16, 2018
Author
Contributor
The normalising_source_densities requires to extract "value" from the SourceSize.
let length = &source_set.sourceSize.value.clone().unwrap();
Hence value has to be public. Also since we are using sourceSize from SourceSizeList above, we needed its members to be public.
This comment has been minimized.
This comment has been minimized.
nupurbaghel
Jul 16, 2018
Author
Contributor
PartialEq was added for unit tests as I remember, I can remove them from here if needed.
|
|
||
| // Step 4.1.6 | ||
| return ; | ||
| } else { |
This comment has been minimized.
This comment has been minimized.
| // Step 4.2 | ||
| if !element.is::<HTMLSourceElement>() { | ||
| continue; | ||
| } else { |
This comment has been minimized.
This comment has been minimized.
| }; | ||
| let nodes = parent.unwrap().upcast::<Node>().ChildNodes(); | ||
| let elements = match is_parent_picture { | ||
| true => nodes.iter().map(|n| DomRoot::from_ref(&*(*n).downcast::<Element>().unwrap())).collect(), |
This comment has been minimized.
This comment has been minimized.
emilio
Jul 16, 2018
Member
Is there any guarantee that the child nodes are Elements? I suspect you can end up with text nodes there easily, and then this will crash.
This comment has been minimized.
This comment has been minimized.
emilio
Jul 16, 2018
Member
(So you should probably do filter_map(DomRoot::downcast::<Element>) instead).
This comment has been minimized.
This comment has been minimized.
| enum ParseState { | ||
| InDescriptor, | ||
| InParens, | ||
| AfterDescriptor, | ||
| } | ||
|
|
||
| #[derive(Debug, PartialEq)] | ||
| pub struct SourceSet { | ||
| pub imageSources: Vec<ImageSource>, |
This comment has been minimized.
This comment has been minimized.
emilio
Jul 16, 2018
Member
let's use snake_case for the members, like: image_sources and source_size.
|
Thanks a lot for reviewing |
|
I did not have any difficulties matching this code against the algorithms in the specification. Great work! |
| #[derive(Debug, PartialEq)] | ||
| pub struct SourceSet { | ||
| pub image_sources: Vec<ImageSource>, | ||
| pub source_size: SourceSizeList, |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
nupurbaghel
Jul 17, 2018
Author
Contributor
Step 4.1.1 and 4.1.2 require setting of individual params of SourceSet. I think we should keep them public
This comment has been minimized.
This comment has been minimized.
jdm
Jul 17, 2018
Member
Public only affects uses of the structure outside of the current module (ie. file). Since all uses are within the file, it should not need to be public.
| #[derive(Debug, PartialEq)] | ||
| pub struct Size { | ||
| pub query: Option<MediaQuery>, | ||
| pub length: Length, |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
nupurbaghel
Jul 17, 2018
•
Author
Contributor
This can be avoided
| } | ||
|
|
||
| impl HTMLImageElement { | ||
| pub fn get_url(&self) -> Option<ServoUrl> { | ||
| self.current_request.borrow().parsed_url.clone() | ||
| } | ||
|
|
||
| pub fn new_source_set() -> SourceSet { |
This comment has been minimized.
This comment has been minimized.
jdm
Jul 17, 2018
Member
It's more idiomatic to make this a static method named new on SourceSet itself.
|
|
||
| pub fn new_source_set() -> SourceSet { | ||
| SourceSet { | ||
| image_sources: Vec::<ImageSource>::new(), |
This comment has been minimized.
This comment has been minimized.
| Some(xparent) => xparent.is::<HTMLPictureElement>(), | ||
| None => false | ||
| }; | ||
| let nodes = parent.unwrap().upcast::<Node>().ChildNodes(); |
This comment has been minimized.
This comment has been minimized.
jdm
Jul 17, 2018
Member
This looks like it would break if used on any image element that does not have a parent. Let's do this instead:
let elements = match parent {
Some(p) => {
let nodes = p.upcast::<Node>().ChildNodes();
nodes.iter().filter_map(DomRoot::downcast::<Element>)
.map(|n| DomRoot::from_ref(&*n)).collect()
}
None => {
vec![DomRoot::from_ref(&*elem)]
}
};
This comment has been minimized.
This comment has been minimized.
nupurbaghel
Jul 17, 2018
Author
Contributor
Keeping nodes inside the Some{ } gives "borrowed value does not live long enough" error. That is the reason it was kept outside before.
This comment has been minimized.
This comment has been minimized.
| fn select_image_source(&self) -> Option<DOMString> { | ||
| // TODO: select an image source from source set | ||
| self.update_source_set().first().cloned() | ||
| fn select_image_source(&self) -> Option<ImageSource> { |
This comment has been minimized.
This comment has been minimized.
jdm
Jul 17, 2018
Member
Instead of an ImageSource, this should return Option<(DOMString, f32)> (or an Option of a new struct that contains those members).
|
|
||
| // Step 2 | ||
| if len == 0 { | ||
| return Some(ImageSource { |
This comment has been minimized.
This comment has been minimized.
|
|
||
| // Step 4 | ||
| let mut repeat_indices = HashSet::new(); | ||
| for mut outer_index in 0..len { |
This comment has been minimized.
This comment has been minimized.
| } | ||
| let imgsource = &source_set.image_sources[outer_index]; | ||
| let pixel_density = imgsource.descriptor.den.unwrap(); | ||
| for mut inner_index in (outer_index + 1)..len { |
This comment has been minimized.
This comment has been minimized.
| /// https://html.spec.whatwg.org/multipage/#source-size-list | ||
| pub source_sizes: Vec<SourceSize>, | ||
| /// https://html.spec.whatwg.org/multipage/#source-size-list | ||
| pub value: Option<Length>, |
This comment has been minimized.
This comment has been minimized.
jdm
Jul 17, 2018
Member
To avoid making these fields public, perhaps we can add a method called set_fallback_value that mutates self.value.
|
Thank you for giving such a detailed review :) |
|
This looks great! Please squash the commits together, and then we can merge this PR! |
5ca8897
to
536b869
|
Thanks for the heads up! |
|
Good catch! |
|
|
Implement update source set & select image source <!-- 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 #11416 (github issue number if applicable). - [x] These changes require tests but cannot be written until implementation of responsive images is complete <!-- 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/21181) <!-- Reviewable:end -->
|
|
|
I ran the update-wpt command. Many tests have started passing it seems :) |
|
@bors-servo r+ |
|
|
Implement update source set & select image source <!-- 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 #11416 (github issue number if applicable). - [x] These changes require tests but cannot be written until implementation of responsive images is complete <!-- 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/21181) <!-- Reviewable:end -->
|
|
|
|
I think we can mark all of those as expected results - we'll need to investigate the new failures adoption.html, but they look like a logic bug in the existing code, not something added by this PR. |
9d1af62
to
8d06da8
|
Okay updated other results as expected too. New failures in adoption.html will be investigated in another PR i guess |
|
@bors-servo r+ |
|
|
Implement update source set & select image source <!-- 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 #11416 (github issue number if applicable). - [x] These changes require tests but cannot be written until implementation of responsive images is complete <!-- 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/21181) <!-- Reviewable:end -->
|
|
MozReview-Commit-ID: FpZ0YvXEYmP
MozReview-Commit-ID: FpZ0YvXEYmP UltraBlame original commit: d62f2b15b2a4c7598a6c53d4c2da0e3e3d782789
MozReview-Commit-ID: FpZ0YvXEYmP UltraBlame original commit: d62f2b15b2a4c7598a6c53d4c2da0e3e3d782789
MozReview-Commit-ID: FpZ0YvXEYmP UltraBlame original commit: d62f2b15b2a4c7598a6c53d4c2da0e3e3d782789
nupurbaghel commentedJul 15, 2018
•
edited by SimonSapin
./mach build -ddoes not report any errors./mach test-tidydoes not report any errorsThese changes fix #11416 (github issue number if applicable).
These changes require tests but cannot be written until implementation of responsive images is complete
This change is