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

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

Merged
merged 2 commits into from Jan 11, 2017

Conversation

@shravan-achar
Copy link
Contributor

shravan-achar commented Oct 29, 2016

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

@shravan-achar shravan-achar force-pushed the shravan-achar:master branch from 489ab18 to 010e606 Oct 29, 2016
Copy link
Member

emilio left a comment

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.

@emilio

emilio Oct 29, 2016

Member

Why this indentation change?

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.

@emilio

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.

@emilio

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.

@emilio

emilio Oct 29, 2016

Member

nit: no space after function name


let mut vec = Vec::new ();

vec.push(1.1);

This comment has been minimized.

@emilio

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.

@emilio

emilio Oct 29, 2016

Member

nit: array.is_empty().

index = index + 1;
}

//only junk exist

This comment has been minimized.

@emilio

emilio Oct 29, 2016

Member

nit: Only junk exists.

{
let num;
let size;
let mut stringval;

This comment has been minimized.

@emilio

emilio Oct 29, 2016

Member

nit: please use snake_case: string_val, number_list.

assert_eq! (left_r, vec[2]);
assert_eq! (top_b, vec[3]);
},
_ => { assert!(false); },

This comment has been minimized.

@emilio

emilio Oct 29, 2016

Member

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

This comment has been minimized.

@KiChjang

KiChjang Oct 29, 2016

Member

unreachable!() may make more sense here.

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.

@emilio

emilio Oct 29, 2016

Member

nit: No space after assert_eq!.

@emilio
Copy link
Member

emilio commented Oct 29, 2016

r? @jdm

@shravan-achar shravan-achar force-pushed the shravan-achar:master branch from 010e606 to c75ff9c Oct 31, 2016
@shravan-achar shravan-achar force-pushed the shravan-achar:master branch from c75ff9c to d45eeac Oct 31, 2016
@shravan-achar
Copy link
Contributor Author

shravan-achar commented Oct 31, 2016

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

Copy link
Member

jdm left a comment

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.

@jdm

jdm Nov 1, 2016

Member

nit: revert this indentation change.

This comment has been minimized.

@jdm

jdm Nov 7, 2016

Member

This should still be reverted.

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

@jdm

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.

@shravan-achar

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.

@jdm

jdm Nov 4, 2016

Member

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

This comment has been minimized.

@shravan-achar

shravan-achar Nov 4, 2016

Author Contributor

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

This comment has been minimized.

@jdm

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.

@jdm

jdm Nov 1, 2016

Member

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,

This comment has been minimized.

@jdm

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.

@jdm

jdm Nov 1, 2016

Member

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


let final_size = number_list.len();

if final_size == 3 {

This comment has been minimized.

@jdm

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.

@shravan-achar

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.

@jdm

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.

@jdm

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.

@jdm

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.

@shravan-achar

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.

@jdm

jdm Nov 3, 2016

Member

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

This comment has been minimized.

@jdm

jdm Nov 1, 2016

Member

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,

This comment has been minimized.

@jdm

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.

@jdm

jdm Nov 1, 2016

Member

nit: move the calculation on to the next line.

}

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

This comment has been minimized.

@jdm

jdm Nov 1, 2016

Member

I don' think this needs to be mutable?

@bors-servo
Copy link
Contributor

bors-servo commented Nov 3, 2016

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

@jdm
Copy link
Member

jdm commented Nov 4, 2016

./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 label Nov 4, 2016
@shravan-achar shravan-achar force-pushed the shravan-achar:master branch from 63f9610 to 3fbf458 Nov 5, 2016
@shravan-achar
Copy link
Contributor Author

shravan-achar commented Nov 5, 2016

Changes made. Test-tidy and build pass.

@jdm jdm removed the S-fails-tidy label Nov 7, 2016
@shravan-achar
Copy link
Contributor Author

shravan-achar commented Jan 11, 2017

Minor nits fixed

@Manishearth Manishearth force-pushed the shravan-achar:master branch from 0b18af2 to 980dde7 Jan 11, 2017
@Manishearth
Copy link
Member

Manishearth commented Jan 11, 2017

@bors-servo r=Manishearth,emilio,jdm

@bors-servo
Copy link
Contributor

bors-servo commented Jan 11, 2017

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

@bors-servo
Copy link
Contributor

bors-servo commented Jan 11, 2017

Testing commit 980dde7 with merge a065191...

bors-servo added 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
Contributor

bors-servo commented Jan 11, 2017

💔 Test failed - linux-dev

@Manishearth
Copy link
Member

Manishearth commented Jan 11, 2017

@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
Copy link
Member

emilio commented Jan 11, 2017

@jdm
Copy link
Member

jdm commented Jan 11, 2017

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

@Manishearth
Copy link
Member

Manishearth commented Jan 11, 2017

@bors-servo r=Manishearth,emilio,jdm

@bors-servo
Copy link
Contributor

bors-servo commented Jan 11, 2017

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

@bors-servo
Copy link
Contributor

bors-servo commented Jan 11, 2017

Testing commit d3be70b with merge f6940f6...

bors-servo added 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 bors-servo merged commit d3be70b into servo:master Jan 11, 2017
2 of 3 checks passed
2 of 3 checks passed
continuous-integration/travis-ci/pr The Travis CI build failed
Details
continuous-integration/appveyor/pr AppVeyor build succeeded
Details
homu Test successful
Details
@bors-servo bors-servo mentioned this pull request Jan 11, 2017
4 of 4 tasks complete
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.

None yet

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