Skip to content
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

Implement update source set & select image source #21181

Merged
merged 1 commit into from Jul 19, 2018

Conversation

@nupurbaghel
Copy link
Contributor

nupurbaghel commented Jul 15, 2018


  • ./mach build -d does not report any errors

  • ./mach test-tidy does not report any errors

  • These 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 Reviewable

@highfive
Copy link

highfive commented Jul 15, 2018

Heads up! This PR modifies the following files:

  • @asajeffrey: components/script/dom/htmlimageelement.rs, components/script/dom/bindings/trace.rs
  • @KiChjang: components/script/dom/htmlimageelement.rs, components/script/dom/bindings/trace.rs
  • @emilio: components/style/values/specified/source_size_list.rs
@highfive
Copy link

highfive commented Jul 15, 2018

warning Warning warning

  • These commits modify style and script code, but no tests are modified. Please consider adding a test!
@nupurbaghel
Copy link
Contributor Author

nupurbaghel commented Jul 15, 2018

r? @jdm
Step 5 of select_image_source will be added later. Also this PR includes changes made by #21178

@highfive highfive assigned jdm and unassigned gw3583 Jul 15, 2018
Copy link
Member

emilio left a comment

Thanks for working on this! @jdm should probably review the source selection logic and such, I just skimmed through the style-related parts :)

);
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.

@emilio

emilio Jul 16, 2018

Member

This should use MediaList instead of MediaCondition.

_ => false,
};

if *(&media_query.trim().is_empty()) || result {

This comment has been minimized.

@emilio

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.

@nupurbaghel

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.

@nupurbaghel

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.

@emilio

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.

@emilio

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.

@nupurbaghel

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.

@nupurbaghel

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.

@emilio

emilio Jul 16, 2018

Member

nit: I'd avoid the else, since given you return above it's not needed.

// Step 4.2
if !element.is::<HTMLSourceElement>() {
continue;
} else {

This comment has been minimized.

@emilio

emilio Jul 16, 2018

Member

Similarly, else after a continue statement is not needed.

};
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.

@emilio

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.

@emilio

emilio Jul 16, 2018

Member

(So you should probably do filter_map(DomRoot::downcast::<Element>) instead).

This comment has been minimized.

@nupurbaghel

nupurbaghel Jul 16, 2018

Author Contributor

Sure will update 👍

enum ParseState {
InDescriptor,
InParens,
AfterDescriptor,
}

#[derive(Debug, PartialEq)]
pub struct SourceSet {
pub imageSources: Vec<ImageSource>,

This comment has been minimized.

@emilio

emilio Jul 16, 2018

Member

let's use snake_case for the members, like: image_sources and source_size.

@nupurbaghel
Copy link
Contributor Author

nupurbaghel commented Jul 16, 2018

Thanks a lot for reviewing 😄 !

Copy link
Member

jdm left a comment

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.

@jdm

jdm Jul 17, 2018

Member

Do these members need to be public?

This comment has been minimized.

@nupurbaghel

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.

@jdm

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.

@jdm

jdm Jul 17, 2018

Member

Do these members need to be public?

This comment has been minimized.

@nupurbaghel

nupurbaghel Jul 17, 2018

Author Contributor

This can be avoided 👍 In fact, I think I can remove this struct totally

}

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.

@jdm

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.

@jdm

jdm Jul 17, 2018

Member

This can be vec![] or Vec::new(); no need to specify the type.

Some(xparent) => xparent.is::<HTMLPictureElement>(),
None => false
};
let nodes = parent.unwrap().upcast::<Node>().ChildNodes();

This comment has been minimized.

@jdm

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.

@nupurbaghel

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. 😅 Any other approach to solve this error ?

This comment has been minimized.

@jdm

jdm Jul 17, 2018

Member

What specific part of the code is the error message referring to?

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.

@jdm

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.

@jdm

jdm Jul 17, 2018

Member

This should return None instead of Some.


// Step 4
let mut repeat_indices = HashSet::new();
for mut outer_index in 0..len {

This comment has been minimized.

@jdm

jdm Jul 17, 2018

Member

No need for mut, right?

}
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.

@jdm

jdm Jul 17, 2018

Member

No need for mut, right?

/// 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.

@jdm

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.

@nupurbaghel
Copy link
Contributor Author

nupurbaghel commented Jul 17, 2018

Thank you for giving such a detailed review :)
We have made all the suggested changes 👍 And ready for the next review :P

@jdm
Copy link
Member

jdm commented Jul 17, 2018

This looks great! Please squash the commits together, and then we can merge this PR!

@jdm jdm mentioned this pull request Jul 17, 2018
4 of 4 tasks complete
@nupurbaghel nupurbaghel force-pushed the nupurbaghel:update_source_set branch from 5ca8897 to 536b869 Jul 17, 2018
@nupurbaghel
Copy link
Contributor Author

nupurbaghel commented Jul 17, 2018

Thanks for the heads up!
I have altered Step 2 of update_source_set to check for HTMLPictureElement, which got missed in the last commit. Hope its right now 😄 !

@jdm
Copy link
Member

jdm commented Jul 17, 2018

Good catch!
@bors-servo r+

@bors-servo
Copy link
Contributor

bors-servo commented Jul 17, 2018

📌 Commit 536b869 has been approved by jdm

@bors-servo
Copy link
Contributor

bors-servo commented Jul 17, 2018

Testing commit 536b869 with merge b8e2dbc...

bors-servo added a commit that referenced this pull request Jul 17, 2018
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 -->
@bors-servo
Copy link
Contributor

bors-servo commented Jul 17, 2018

💔 Test failed - linux-rel-css

@nupurbaghel
Copy link
Contributor Author

nupurbaghel commented Jul 18, 2018

I ran the update-wpt command. Many tests have started passing it seems :)

@jdm
Copy link
Member

jdm commented Jul 18, 2018

@bors-servo
Copy link
Contributor

bors-servo commented Jul 18, 2018

📌 Commit 9d1af62 has been approved by jdm

@bors-servo
Copy link
Contributor

bors-servo commented Jul 18, 2018

Testing commit 9d1af62 with merge 4bbc2c4...

bors-servo added a commit that referenced this pull request Jul 18, 2018
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 -->
@bors-servo
Copy link
Contributor

bors-servo commented Jul 18, 2018

💔 Test failed - linux-rel-css

@jdm
Copy link
Member

jdm commented Jul 18, 2018

 ▶ OK [expected TIMEOUT] /html/semantics/embedded-content/the-img-element/adoption.html

  ▶ Unexpected subtest result in /html/semantics/embedded-content/the-img-element/adoption.html:
  │ FAIL [expected TIMEOUT] img (srcset 1 cand)
  │   → assert_equals: expected "http://web-platform.test:8000/images/green-1x1.png" but got "/images/green-1x1.png"
  │ FAIL [expected TIMEOUT] img (srcset 1 cand), parent is picture
  │   → assert_equals: expected "http://web-platform.test:8000/images/green-1x1.png" but got "/images/green-1x1.png"
  │ FAIL [expected TIMEOUT] img (srcset 1 cand), previous sibling is source
  │   → assert_equals: expected "http://web-platform.test:8000/images/green-1x1.png" but got "/images/green-1x1.png"
  │ 
  │ t/</i.onload<@http://web-platform.test:8000/html/semantics/embedded-content/the-img-element/adoption.html:31:7
  │ Test.prototype.step@http://web-platform.test:8000/resources/testharness.js:1538:20
  └ Test.prototype.step_func_done/<@http://web-platform.test:8000/resources/testharness.js:1578:17

  ▶ Unexpected subtest result in /html/semantics/embedded-content/the-img-element/update-the-image-data/fail-to-resolve.html:
  └ PASS [expected FAIL] <img srcset="//[" src="/images/red.png">
@jdm
Copy link
Member

jdm commented Jul 18, 2018

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.

@nupurbaghel nupurbaghel force-pushed the nupurbaghel:update_source_set branch from 9d1af62 to 8d06da8 Jul 19, 2018
@nupurbaghel
Copy link
Contributor Author

nupurbaghel commented Jul 19, 2018

Okay updated other results as expected too. New failures in adoption.html will be investigated in another PR i guess 😅

@jdm
Copy link
Member

jdm commented Jul 19, 2018

@bors-servo
Copy link
Contributor

bors-servo commented Jul 19, 2018

📌 Commit 8d06da8 has been approved by jdm

@bors-servo
Copy link
Contributor

bors-servo commented Jul 19, 2018

Testing commit 8d06da8 with merge e571873...

bors-servo added a commit that referenced this pull request Jul 19, 2018
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 -->
@bors-servo
Copy link
Contributor

bors-servo commented Jul 19, 2018

@bors-servo bors-servo merged commit 8d06da8 into servo:master Jul 19, 2018
3 checks passed
3 checks passed
continuous-integration/appveyor/pr AppVeyor build succeeded
Details
continuous-integration/travis-ci/pr The Travis CI build passed
Details
homu Test successful
Details
moz-v2v-gh pushed a commit to mozilla/gecko-dev that referenced this pull request Jul 24, 2018
gecko-dev-updater pushed a commit to marco-c/gecko-dev-comments-removed that referenced this pull request Oct 3, 2019
MozReview-Commit-ID: FpZ0YvXEYmP

UltraBlame original commit: d62f2b15b2a4c7598a6c53d4c2da0e3e3d782789
gecko-dev-updater pushed a commit to marco-c/gecko-dev-wordified-and-comments-removed that referenced this pull request Oct 3, 2019
MozReview-Commit-ID: FpZ0YvXEYmP

UltraBlame original commit: d62f2b15b2a4c7598a6c53d4c2da0e3e3d782789
gecko-dev-updater pushed a commit to marco-c/gecko-dev-wordified that referenced this pull request Oct 3, 2019
MozReview-Commit-ID: FpZ0YvXEYmP

UltraBlame original commit: d62f2b15b2a4c7598a6c53d4c2da0e3e3d782789
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked issues

Successfully merging this pull request may close these issues.

6 participants
You can’t perform that action at this time.