-
-
Notifications
You must be signed in to change notification settings - Fork 3.4k
Image maps project
Josh Matthews edited this page Sep 14, 2016
·
3 revisions
Background information: Image maps are an old HTML technology that allows treating arbitrary areas in an image as separate hyperlinks. Servo does not support them yet; the goal of this project is implement this missing feature.
Note: there are tools that can create image maps for testing. The Space Jam website contains a great premade example.
Initial steps:
- compile Servo and ensure that it runs on
tests/html/about-mozilla.html - email the mozilla.dev.servo mailing list (be sure to subscribe first!) introducing your group and asking any necessary questions
- define an
Areaenum inhtmlareaelement.rsthat supports rectangles, circles, and polygons (ie. coordinate representations) - implement constructors for each variant that accept a string argument, parse them into appropriate coordinates, and return an appropriate
Areainstance - implement a
hit_testmethod on Area that accepts aPoint2D<f32>argument and returns true if the point is within the area's coordinates (return false for all polygonal areas) - write tests for the
Areaconstructors and hit tests (add a newhtmlareaelement.rstotests/unit/script/and run./mach test-unit -p script) - add a method to
HTMLAreaElementthat returns anAreavalue derived from that element's attributes
Subsequent steps:
- add a method named
areastoHTMLImageElementthat returns a vector ofRoot<HTMLAreaElement>values - these are the result of finding theHTMLMapElementspecified in the image'susemapattribute, then retrieving its childHTMLAreaElementelements - write a method for
HTMLAreaElementthat implements the activation behaviour defined in the specification (seeHTMLAnchorElement::activation_behaviorfor a good model) - implement the
handle_eventmethod forHTMLImageElement(as part ofVirtualMethods) - if the event is aclickevent, iterate over the list of associated HTMLAreaElements and hit-test theAreavalues against the click event's coordinates. If an area matches, invoke theHTMLAreaElement's activation behavior - extra credit: implement polygon hit testing