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 upImageMaps: Implemented support for parsing coord attribute to a shape… #13972
Conversation
|
Mostly superficial review, but there are a lot of style nits, so I hope it'd be helpful. Thanks for doing this work! |
| @@ -35,9 +157,16 @@ impl HTMLAreaElement { | |||
| prefix: Option<DOMString>, | |||
| document: &Document) -> Root<HTMLAreaElement> { | |||
| Node::reflect_node(box HTMLAreaElement::new_inherited(local_name, prefix, document), | |||
| document, | |||
| HTMLAreaElementBinding::Wrap) | |||
| document, | |||
This comment has been minimized.
This comment has been minimized.
| let input = "1.1, 1.1, 6.1, 1.1, 3.1, 3.1"; | ||
| let size = 6; | ||
|
|
||
| let mut vec = Vec::new (); |
This comment has been minimized.
This comment has been minimized.
emilio
Oct 29, 2016
Member
nit: rust style is not having space before the parentheses in a function call.
| /*Area::Rectangle tests*/ | ||
| #[test] | ||
| fn polygon_six_points_valid_input () | ||
| { |
This comment has been minimized.
This comment has been minimized.
emilio
Oct 29, 2016
Member
nit: Brace uses to be in the same line as the function name except when there's a where clause.
|
|
||
| /*Area::Rectangle tests*/ | ||
| #[test] | ||
| fn polygon_six_points_valid_input () |
This comment has been minimized.
This comment has been minimized.
|
|
||
| let mut vec = Vec::new (); | ||
|
|
||
| vec.push(1.1); |
This comment has been minimized.
This comment has been minimized.
emilio
Oct 29, 2016
Member
Also, you could write this as: vec![1.1, 1.1, 6.1, ...], here and everywhere else.
| } | ||
|
|
||
| //only junk exist | ||
| if array.len() == 0 { |
This comment has been minimized.
This comment has been minimized.
| index = index + 1; | ||
| } | ||
|
|
||
| //only junk exist |
This comment has been minimized.
This comment has been minimized.
| { | ||
| let num; | ||
| let size; | ||
| let mut stringval; |
This comment has been minimized.
This comment has been minimized.
| assert_eq! (left_r, vec[2]); | ||
| assert_eq! (top_b, vec[3]); | ||
| }, | ||
| _ => { assert!(false); }, |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
| 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]); |
This comment has been minimized.
This comment has been minimized.
|
r? @jdm |
|
Thanks Emilio and Keith for your comments. Changes made as per comments. |
|
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) |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
| @@ -2017,6 +2017,7 @@ dependencies = [ | |||
| name = "script_tests" | |||
| version = "0.0.1" | |||
| dependencies = [ | |||
| "euclid 0.10.2 (registry+https://github.com/rust-lang/crates.io-index)", | |||
This comment has been minimized.
This comment has been minimized.
jdm
Nov 1, 2016
Member
We will need to run ./mach cargo-update -p script to ensure that ports/cef/Cargo.lock is also updated.
This comment has been minimized.
This comment has been minimized.
shravan-achar
Nov 4, 2016
Author
Contributor
The command throws an error: package id specification script matched no package. Is it a different package name?
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
shravan-achar
Nov 4, 2016
Author
Contributor
No luck. Same error. Tried script_tests, script, tests, test, scripts too.
This comment has been minimized.
This comment has been minimized.
jdm
Nov 4, 2016
Member
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.
| @@ -14,3 +14,4 @@ msg = {path = "../../../components/msg"} | |||
| plugins = {path = "../../../components/plugins"} | |||
| script = {path = "../../../components/script"} | |||
| url = {version = "1.2", features = ["heap_size"]} | |||
| euclid = "0.10.2" | |||
This comment has been minimized.
This comment has been minimized.
| 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, |
This comment has been minimized.
This comment has been minimized.
jdm
Nov 1, 2016
Member
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 { |
This comment has been minimized.
This comment has been minimized.
|
|
||
| let final_size = number_list.len(); | ||
|
|
||
| if final_size == 3 { |
This comment has been minimized.
This comment has been minimized.
jdm
Nov 1, 2016
Member
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.
This comment has been minimized.
This comment has been minimized.
shravan-achar
Nov 2, 2016
•
Author
Contributor
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.
This comment has been minimized.
This comment has been minimized.
jdm
Nov 2, 2016
Member
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?
This comment has been minimized.
This comment has been minimized.
jdm
Nov 2, 2016
Member
Oh, and if you were really asking about how to access the attribute value from Servo: https://dxr.mozilla.org/servo/rev/ebae89aa2e7d83801d8b0a3ec83ba208b551663d/components/script/dom/htmlmediaelement.rs#446 is a good example.
This comment has been minimized.
This comment has been minimized.
jdm
Nov 2, 2016
Member
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.
This comment has been minimized.
This comment has been minimized.
shravan-achar
Nov 3, 2016
Author
Contributor
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"))?
This comment has been minimized.
This comment has been minimized.
| } | ||
|
|
||
| Area::Rectangle { left_l: number_list[0], top_t: number_list[1], left_r: number_list[2], | ||
| top_b: number_list[3] } |
This comment has been minimized.
This comment has been minimized.
| 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, |
This comment has been minimized.
This comment has been minimized.
jdm
Nov 1, 2016
Member
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) + |
This comment has been minimized.
This comment has been minimized.
| } | ||
|
|
||
| // Convert String to float | ||
| let mut string_val = String::from_utf8(array); |
This comment has been minimized.
This comment has been minimized.
|
|
|
|
|
Changes made. Test-tidy and build pass. |
|
Minor nits fixed |
|
@bors-servo r=Manishearth,emilio,jdm |
|
|
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 -->
|
|
|
@jdm hmm, the unit tests here try to use |
|
See components/script/test.rs, where we re-export the DOM things that
need to be testable.
…On Wed, Jan 11, 2017 at 08:08:33AM -0800, Manish Goregaokar wrote:
@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?
--
You are receiving this because you commented.
Reply to this email directly or view it on GitHub:
#13972 (comment)
|
|
Sorry @shravan-achar, #11672 merged since these changes were made which caused the build error when compiling tests. |
|
@bors-servo r=Manishearth,emilio,jdm |
|
|
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 -->
|
|
shravan-achar commentedOct 29, 2016
•
edited by larsbergstrom
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 -ddoes not report any errors./mach test-tidydoes not report any errors… object in HTMLAreaElement
This change is