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 step 5 of select_image_source #21215

Merged
merged 1 commit into from Jul 20, 2018

Conversation

@nupurbaghel
Copy link
Contributor

nupurbaghel commented Jul 19, 2018

This step is responsible for selecting an image source based on user agent's environment( closest value which is greater than user's pixel density)
In case of no device, maximum density source is selected.


  • ./mach build -d does not report any errors
  • ./mach test-tidy does not report any errors
  • These changes fix #11416
  • These changes do not require tests because tests are already present

This change is Reviewable

@highfive
Copy link

highfive commented Jul 19, 2018

Heads up! This PR modifies the following files:

  • @asajeffrey: components/script/dom/htmlimageelement.rs
  • @KiChjang: components/script/dom/htmlimageelement.rs
@highfive
Copy link

highfive commented Jul 19, 2018

warning Warning warning

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

nupurbaghel commented Jul 19, 2018

r? @jdm

@highfive highfive assigned jdm and unassigned emilio Jul 19, 2018
@jdm
Copy link
Member

jdm commented Jul 19, 2018

@bors-servo
Copy link
Contributor

bors-servo commented Jul 19, 2018

Trying commit e45af10 with merge 92d16a3...

bors-servo added a commit that referenced this pull request Jul 19, 2018
Implement step 5 of select_image_source

<!-- Please describe your changes on the following line: -->
This step is responsible for selecting an image source based on user agent's environment( closest value which is greater than user's pixel density)
In case of no device, maximum density source is selected.

---
<!-- 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

<!-- Either: -->
- [x] These changes do not require tests because tests are already present

<!-- 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/21215)
<!-- Reviewable:end -->
@bors-servo
Copy link
Contributor

bors-servo commented Jul 19, 2018

💔 Test failed - mac-rel-wpt1

@jdm
Copy link
Member

jdm commented Jul 20, 2018

That's #20734.

@nupurbaghel
Copy link
Contributor Author

nupurbaghel commented Jul 20, 2018

Alright, this issue seems to be a problem to everyone. How do you solve it 😅 ?

Copy link
Member

jdm left a comment

My only suggestion here is to use iterators for these loops instead of explicit array indexes when possible.

max_den = den;
max_index = current_index;
}
current_index = current_index + 1;

This comment has been minimized.

@jdm

jdm Jul 20, 2018

Member

We can write this more idiomatically as:

let mut max = (0f64, 0);
for image_source in &source_set.image_sources {
    if repeat_indices.contains(&index) {
        continue;
    }
    let den = image_source.descriptor.den.unwrap();
    if max.0 < den {
        max = (den, img_sources.len());
    }
    img_sources.push(image_source);
}

This comment has been minimized.

@nupurbaghel

nupurbaghel Jul 20, 2018

Author Contributor

Do we have to generate index here too by enumerating like the next suggestion ?

This comment has been minimized.

@jdm

jdm Jul 20, 2018

Member

Oh, right. Yes, I missed that one.

let device = document_from_node(self).device();
if device.is_some() {
let device_den: f64 = device.unwrap().device_pixel_ratio().get().into();
for outer_index in 0..img_sources.len() {

This comment has been minimized.

@jdm

jdm Jul 20, 2018

Member

We can write this more idiomatically as:

if let Some(device) = device {
    let device_den = device.device_pixel_ratio().get() as f64;
    let mut best_candidate = max;
    for (index, image_source) in img_sources.iter().enumerate() {
        let current_den = image_source.descriptor.den.unwrap();
        if current_den < best_candidate.0 && current_den >= device_den {
            best_candidate = (current_den, index);
        }
    }
}
@nupurbaghel nupurbaghel force-pushed the nupurbaghel:update_source_set branch from e45af10 to c881c2a Jul 20, 2018
@nupurbaghel
Copy link
Contributor Author

nupurbaghel commented Jul 20, 2018

Made the suggested changes 👍

@jdm
jdm approved these changes Jul 20, 2018
@jdm
Copy link
Member

jdm commented Jul 20, 2018

@bors-servo
Copy link
Contributor

bors-servo commented Jul 20, 2018

📌 Commit c881c2a has been approved by jdm

@bors-servo
Copy link
Contributor

bors-servo commented Jul 20, 2018

Testing commit c881c2a with merge aa76909...

bors-servo added a commit that referenced this pull request Jul 20, 2018
Implement step 5 of select_image_source

<!-- Please describe your changes on the following line: -->
This step is responsible for selecting an image source based on user agent's environment( closest value which is greater than user's pixel density)
In case of no device, maximum density source is selected.

---
<!-- 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

<!-- Either: -->
- [x] These changes do not require tests because tests are already present

<!-- 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/21215)
<!-- Reviewable:end -->
@bors-servo
Copy link
Contributor

bors-servo commented Jul 20, 2018

@bors-servo bors-servo merged commit c881c2a into servo:master Jul 20, 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
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.

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