Skip to content

ImageMaps: Implemented support for parsing coord attribute to a shape… - #13972

Merged
bors-servo merged 2 commits into
servo:masterfrom
shravan-achar:master
Jan 11, 2017
Merged

bors-servo merged 2 commits into
servo:masterfrom
shravan-achar:master

Conversation

@shravan-achar

@shravan-achar shravan-achar commented Oct 29, 2016 •

Copy link
Copy Markdown
Contributor

Image Maps: (Part 1) Implemented support for parsing coord attribute to a shape object.
Implemented a hit_test method to see if a point is within the area. Tests for constructors and hit_test included


  • ./mach build -d does not report any errors
  • ./mach test-tidy does not report any errors
  • These changes fix #__ (github issue number if applicable).
  • There are tests for these changes OR
  • These changes do not require tests because _____

… object in HTMLAreaElement


This change is Reviewable

@highfive highfive added the S-awaiting-review There is new code that needs to be reviewed. label Oct 29, 2016

@emilio emilio left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Mostly superficial review, but there are a lot of style nits, so I hope it'd be helpful.

Thanks for doing this work!

Node::reflect_node(box HTMLAreaElement::new_inherited(local_name, prefix, document),
document,
HTMLAreaElementBinding::Wrap)
document,

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why this indentation change?

Comment thread tests/unit/script/htmlareaelement.rs Outdated
let input = "1.1, 1.1, 6.1, 1.1, 3.1, 3.1";
let size = 6;

let mut vec = Vec::new ();

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: rust style is not having space before the parentheses in a function call.

Comment thread tests/unit/script/htmlareaelement.rs Outdated
/*Area::Rectangle tests*/
#[test]
fn polygon_six_points_valid_input ()
{

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: Brace uses to be in the same line as the function name except when there's a where clause.

Comment thread tests/unit/script/htmlareaelement.rs Outdated

/*Area::Rectangle tests*/
#[test]
fn polygon_six_points_valid_input ()

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: no space after function name

Comment thread tests/unit/script/htmlareaelement.rs Outdated

let mut vec = Vec::new ();

vec.push(1.1);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also, you could write this as: vec![1.1, 1.1, 6.1, ...], here and everywhere else.

}

//only junk exist
if array.len() == 0 {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: array.is_empty().

index = index + 1;
}

//only junk exist

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: Only junk exists.

{
let num;
let size;
let mut stringval;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: please use snake_case: string_val, number_list.

Comment thread tests/unit/script/htmlareaelement.rs Outdated
assert_eq! (left_r, vec[2]);
assert_eq! (top_b, vec[3]);
},
_ => { assert!(false); },

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can use panic! here too if you want, but that's probably fine.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

unreachable!() may make more sense here.

Comment thread tests/unit/script/htmlareaelement.rs Outdated
Area::Rectangle { left_l, top_t, left_r, top_b } => {
assert!(left_l < left_r);
assert!(top_t < top_b);
assert_eq! (left_l, vec[0]);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: No space after assert_eq!.

@emilio

emilio commented Oct 29, 2016

Copy link
Copy Markdown
Member

r? @jdm

@KiChjang KiChjang added S-needs-code-changes Changes have not yet been made that were requested by a reviewer. and removed S-awaiting-review There is new code that needs to be reviewed. labels Oct 31, 2016
@highfive highfive added S-awaiting-review There is new code that needs to be reviewed. and removed S-needs-code-changes Changes have not yet been made that were requested by a reviewer. labels Oct 31, 2016
@shravan-achar

Copy link
Copy Markdown
Contributor Author

Thanks Emilio and Keith for your comments. Changes made as per comments.

@jdm jdm left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great start! The comments I have are a combination of style nits and suggestions for more idiomatic Rust code, along with some design changes that should make the resulting code easier to read.

document,
HTMLAreaElementBinding::Wrap)
document,
HTMLAreaElementBinding::Wrap)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: revert this indentation change.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should still be reverted.

Comment thread components/servo/Cargo.lock Outdated
name = "script_tests"
version = "0.0.1"
dependencies = [
"euclid 0.10.2 (registry+https://github.com/rust-lang/crates.io-index)",

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We will need to run ./mach cargo-update -p script to ensure that ports/cef/Cargo.lock is also updated.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The command throws an error: package id specification script matched no package. Is it a different package name?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Odd - what about ./mach cargo-update -p script_tests?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No luck. Same error. Tried script_tests, script, tests, test, scripts too.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure why that's happening, but I think my original comment was wrong and ports/cef/Cargo.lock does not need to be updated. Go ahead and ignore this.

Comment thread tests/unit/script/Cargo.toml Outdated
plugins = {path = "../../../components/plugins"}
script = {path = "../../../components/script"}
url = {version = "1.2", features = ["heap_size"]}
euclid = "0.10.2"

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: keep these in alphabetical order, please.

Circle { left: f32, top: f32, radius: f32 },
Rectangle { left_l: f32, top_t: f32, left_r: f32, top_b: f32 },
Polygon { points: Vec<f32> },
Default,

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Rather than a default variant, we should make our parsing functions return Option<Area> instead.


// https://html.spec.whatwg.org/multipage/#rules-for-parsing-a-list-of-floating-point-numbers
impl Area {
pub fn get_area(coord: &str) -> Area {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's call this method parse and have it return Option<Area>.


let final_size = number_list.len();

if final_size == 3 {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The specification says that we should parse lists of coordinates with a particular target state. From "each area element in areas must be processed as follows", see step 4: https://html.spec.whatwg.org/multipage/embedded-content.html#image-map-processing-model . Rather than only returning a circle if there are exactly 3 elements, we should be returning a circle if there are at least 3 instead (and we're attempting to parse a circle).

I recommend a second enum with variants for the intended parse target, and taking that as an argument in Area::parse.

@shravan-achar shravan-achar Nov 2, 2016 •

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In HTMLAreaElement.idl, we noticed that all the attributes are commented out. We were thinking if these are necessary to access 'area' elements attributes such as shape and coords. We were not sure how to access these
For this, we were thinking of seeing which of the values are populated by running a debugger on servo, but we were also not sure of which of the HTML features are implemented on Servo.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The attributes in the webidl files only affect JS code that uses the element.something syntax. It's still possible to use element.getAttribute('something'), which corresponds to the <element something=value> content attribute. Does that make sense?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You may need to use Atom::from_slice("coords") instead of atom!("coords"), because it's not present in the list in https://github.com/servo/string-cache/ yet.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We get the 'shape' attribute as a string. Do we need another enum to state the variant or we can pass around the string (ex: parse("1,1,1,1", "Rectangle"))?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it makes sense to pass a strongly-typed enum rather than a string.

}

Area::Rectangle { left_l: number_list[0], top_t: number_list[1], left_r: number_list[2],
top_b: number_list[3] }

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit:

Area::Rectangle {
    left_l: ...,
    top_t: ...,
    // etc.
}

radius * radius <= 0.0,

Area::Rectangle { left_l, top_t, left_r, top_b } => p.x <= left_r && p.x >= left_l &&
p.y <= top_b && p.y >= top_t,

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit:

Area::Rectangle { left_l, top_t, left_r, top_b } =>
    p.x <= left_r && p.x >= left_l &&
    p.y <= top_b && p.y >= top_t,


pub fn hit_test(&self, p: Point2D<f32>) -> bool {
match *self {
Area::Circle { left, top, radius } => (p.x - left)*(p.x - left) +

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: move the calculation on to the next line.

}

// Convert String to float
let mut string_val = String::from_utf8(array);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don' think this needs to be mutable?

@jdm jdm added S-needs-code-changes Changes have not yet been made that were requested by a reviewer. and removed S-awaiting-review There is new code that needs to be reviewed. labels Nov 1, 2016
@bors-servo

Copy link
Copy Markdown
Contributor

☔ The latest upstream changes (presumably #14043) made this pull request unmergeable. Please resolve the merge conflicts.

@highfive highfive added the S-needs-rebase There are merge conflict errors. label Nov 3, 2016
@highfive highfive added S-awaiting-review There is new code that needs to be reviewed. and removed S-needs-code-changes Changes have not yet been made that were requested by a reviewer. labels Nov 4, 2016
@jdm jdm added S-needs-code-changes Changes have not yet been made that were requested by a reviewer. and removed S-needs-rebase There are merge conflict errors. S-awaiting-review There is new code that needs to be reviewed. labels Nov 4, 2016
@jdm

jdm commented Nov 4, 2016

Copy link
Copy Markdown
Member

./mach test-tidy is failing:

./components/script/dom/htmlareaelement.rs:16: use statement is not in alphabetical order
    expected: html5ever_atoms::LocalName
    found: euclid::point::Point2D

@jdm jdm added the S-fails-tidy `./mach test-tidy` reported errors. label Nov 4, 2016
@highfive highfive added S-awaiting-review There is new code that needs to be reviewed. and removed S-needs-code-changes Changes have not yet been made that were requested by a reviewer. labels Nov 5, 2016
@shravan-achar

shravan-achar commented Nov 5, 2016 •

Copy link
Copy Markdown
Contributor Author

Changes made. Test-tidy and build pass.

@jdm jdm removed the S-fails-tidy `./mach test-tidy` reported errors. label Nov 7, 2016
@shravan-achar

Copy link
Copy Markdown
Contributor Author

Minor nits fixed

@Manishearth

Copy link
Copy Markdown
Member

@bors-servo r=Manishearth,emilio,jdm

@bors-servo

Copy link
Copy Markdown
Contributor

📌 Commit 980dde7 has been approved by Manishearth,emilio,jdm

@highfive highfive added S-awaiting-merge The PR is in the process of compiling and running tests on the automated CI. and removed S-awaiting-review There is new code that needs to be reviewed. labels Jan 11, 2017
@bors-servo

Copy link
Copy Markdown
Contributor

⌛ Testing commit 980dde7 with merge a065191...

bors-servo pushed a commit that referenced this pull request Jan 11, 2017
ImageMaps: Implemented support for parsing coord attribute to a shape…

<!-- Please describe your changes on the following line: -->

Image Maps: (Part 1) Implemented support for parsing coord attribute to a shape object.
                       Implemented a hit_test method to see if a point is within the area. Tests for constructors                      and hit_test included

---

<!-- Thank you for contributing to Servo! Please replace each `[ ]` by `[X]` when the step is complete, and replace `__` with appropriate data: -->
- [ ] `./mach build -d` does not report any errors
- [ ] `./mach test-tidy` does not report any errors
- [ ] These changes fix #__ (github issue number if applicable).

<!-- Either: -->
- [ ] There are tests for these changes OR
- [ ] These changes do not require tests because _____

<!-- Pull requests that do not address these steps are welcome, but they will require additional verification as part of the review process. -->

… object in HTMLAreaElement

<!-- 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/13972)

<!-- Reviewable:end -->
@bors-servo

Copy link
Copy Markdown
Contributor

💔 Test failed - linux-dev

@highfive highfive added S-tests-failed The changes caused existing tests to fail. and removed S-awaiting-merge The PR is in the process of compiling and running tests on the automated CI. labels Jan 11, 2017
@Manishearth

Copy link
Copy Markdown
Member

@jdm hmm, the unit tests here try to use script::dom, which is private. We've never really had unit tests for script, so we haven't hit this problem before. Any idea how this should be addressed?

@emilio

emilio commented Jan 11, 2017 via email

Copy link
Copy Markdown
Member

@jdm jdm added S-needs-code-changes Changes have not yet been made that were requested by a reviewer. and removed S-tests-failed The changes caused existing tests to fail. labels Jan 11, 2017
@jdm

jdm commented Jan 11, 2017

Copy link
Copy Markdown
Member

Sorry @shravan-achar, #11672 merged since these changes were made which caused the build error when compiling tests.

@highfive highfive added S-awaiting-review There is new code that needs to be reviewed. and removed S-needs-code-changes Changes have not yet been made that were requested by a reviewer. labels Jan 11, 2017
@Manishearth

Copy link
Copy Markdown
Member

@bors-servo r=Manishearth,emilio,jdm

@bors-servo

Copy link
Copy Markdown
Contributor

📌 Commit d3be70b has been approved by Manishearth,emilio,jdm

@highfive highfive added S-awaiting-merge The PR is in the process of compiling and running tests on the automated CI. and removed S-awaiting-review There is new code that needs to be reviewed. labels Jan 11, 2017
@bors-servo

Copy link
Copy Markdown
Contributor

⌛ Testing commit d3be70b with merge f6940f6...

bors-servo pushed a commit that referenced this pull request Jan 11, 2017
ImageMaps: Implemented support for parsing coord attribute to a shape…

<!-- Please describe your changes on the following line: -->

Image Maps: (Part 1) Implemented support for parsing coord attribute to a shape object.
                       Implemented a hit_test method to see if a point is within the area. Tests for constructors                      and hit_test included

---

<!-- Thank you for contributing to Servo! Please replace each `[ ]` by `[X]` when the step is complete, and replace `__` with appropriate data: -->
- [ ] `./mach build -d` does not report any errors
- [ ] `./mach test-tidy` does not report any errors
- [ ] These changes fix #__ (github issue number if applicable).

<!-- Either: -->
- [ ] There are tests for these changes OR
- [ ] These changes do not require tests because _____

<!-- Pull requests that do not address these steps are welcome, but they will require additional verification as part of the review process. -->

… object in HTMLAreaElement

<!-- 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/13972)

<!-- Reviewable:end -->
@bors-servo

Copy link
Copy Markdown
Contributor

@bors-servo
bors-servo merged commit d3be70b into servo:master Jan 11, 2017
@highfive highfive removed the S-awaiting-merge The PR is in the process of compiling and running tests on the automated CI. label Jan 11, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

8 participants