Skip to content

Commit

Permalink
add step 5 with logs
Browse files Browse the repository at this point in the history
  • Loading branch information
nupurbaghel committed Jul 19, 2018
1 parent e571873 commit d1d30a4
Showing 1 changed file with 32 additions and 2 deletions.
34 changes: 32 additions & 2 deletions components/script/dom/htmlimageelement.rs
Original file line number Diff line number Diff line change
Expand Up @@ -598,20 +598,50 @@ impl HTMLImageElement {
let pixel_density = imgsource.descriptor.den.unwrap();
for inner_index in (outer_index + 1)..len {
let imgsource2 = &source_set.image_sources[inner_index];
println!("descriptor1 {:?}",pixel_density);
println!("source 1 {:?}", imgsource);
if pixel_density == imgsource2.descriptor.den.unwrap() {
repeat_indices.insert(inner_index);
println!("found a repeating index {}",inner_index);
println!("url {:?}", imgsource2);
}
}
}
let mut max_den = 0f64; //initial value of current_den in Step 5
let mut max_index = 0; //initial value of result_index in Step 5
let mut current_index = 0;
let img_sources = &mut vec![];
for outer_index in 0..len {
if !repeat_indices.contains(&outer_index) {
img_sources.push(&source_set.image_sources[outer_index]);
println!("This url is getting pushed");
println!("{:?}",source_set.image_sources);
// set max density and index
let den = img_sources[current_index].descriptor.den.unwrap();
if max_den < den {
max_den = den;
max_index = current_index;
}
current_index = current_index + 1;
}
}

// TODO Step 5 - select source based on pixel density
let selected_source = img_sources.remove(0).clone();
// Step 5
let mut closest_den = max_den;
let mut result_index = max_index;
let device = document_from_node(self).device();
if device.is_some() {
let device_den: f64 = device.unwrap().device_pixel_ratio().get().into();
println!("device_den {:?}", device_den);
for outer_index in 0..img_sources.len() {
let current_den = img_sources[outer_index].descriptor.den.unwrap();
if current_den < closest_den && current_den >= device_den {
closest_den = current_den;
result_index = outer_index;
}
}
}
let selected_source = img_sources.remove(result_index).clone();
Some((DOMString::from_string(selected_source.url), selected_source.descriptor.den.unwrap() as f32))
}

Expand Down

0 comments on commit d1d30a4

Please sign in to comment.