Implement Element.closest()

RESOLVED FIXED in mozilla35

Status

()

Core
DOM: Core & HTML
RESOLVED FIXED
3 years ago
3 years ago

People

(Reporter: Arkadiusz Michalski (Spirit), Assigned: agi, Mentored)

Tracking

({dev-doc-complete})

Trunk
mozilla35
dev-doc-complete
Points:
---

Firefox Tracking Flags

(Not tracked)

Details

(Whiteboard: [lang=c++])

Attachments

(2 attachments, 2 obsolete attachments)

(Reporter)

Description

3 years ago
User Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:31.0) Gecko/20100101 Firefox/31.0 (Beta/Release)
Build ID: 20140716183446

Steps to reproduce:

This method is new in DOM spec:
http://dom.spec.whatwg.org/#dom-element-closest
https://www.w3.org/Bugs/Public/show_bug.cgi?id=16488

At now its not yet implemented anywhere but maybe Firefox will be first.

Updated

3 years ago
OS: Windows 7 → All
Hardware: x86_64 → All
Version: 34 Branch → Trunk
Mentor: bzbarsky@mit.edu
Status: UNCONFIRMED → NEW
Ever confirmed: true
Whiteboard: [lang=c++]

Comment 1

3 years ago
Hi, I'm interested in this bug. Where should I start with this?

Comment 2

3 years ago
Hi, Lynn. Thanks for your help! Boris, can you point to a DXR link to get Lynn started?
(Assignee)

Comment 3

3 years ago
So I was actually going to work on this (I've already emailed Lynn about it). I have a patch ready I just have to re-read one more time before posting it :)
(Assignee)

Comment 4

3 years ago
Created attachment 8480349 [details] [diff] [review]
Implement closest()
(Assignee)

Comment 5

3 years ago
Comment on attachment 8480349 [details] [diff] [review]
Implement closest()

bz what do you think?
Attachment #8480349 - Attachment description: WIP → Implement closest()
Attachment #8480349 - Flags: review?(bzbarsky)
Ugh.  I'm sorry I didn't see comment 2; apparently being a mentor on a bug doesn't mean you get mail for it.  :(
Comment on attachment 8480349 [details] [diff] [review]
Implement closest()

You don't need the NS_IMETHOD bits in Element.h: this API is not declared in nsIDOMElement.idl (and shouldn't be).  That also means you don't need the nsresult-returning version of this method.

You also don't need to add anything to nsINode.  This API should live on Element only, just like Matches() does.

Also like :matches(), you want to call OwnerDoc()->FlushPendingLinkUpdates() in here before doing any matching.

The rest of this looks great.  r=me with the above simplifications
Attachment #8480349 - Flags: review?(bzbarsky) → review+
(Assignee)

Comment 8

3 years ago
Created attachment 8481984 [details] [diff] [review]
Implement Element.Closest() ; r=bz

Thanks for the quick review bz! I did all the changes, asking to review again in case you want to see the patch before checkin.

Green Try on Win & Android: https://tbpl.mozilla.org/?tree=Try&rev=de43c16c0e12
Assignee: nobody → agi.novanta
Attachment #8480349 - Attachment is obsolete: true
Status: NEW → ASSIGNED
Attachment #8481984 - Flags: review?(bzbarsky)
(Assignee)

Updated

3 years ago
Keywords: dev-doc-needed
Comment on attachment 8481984 [details] [diff] [review]
Implement Element.Closest() ; r=bz

One more nit, because the spec is in the process of changing:  You want to do this right after creating the TreeMatchContext:

   matchingContext.SetHasSpecifiedScope();
   matchingContext.AddScopeElement(this);

and maybe add a basic test for closest(":scope")?

r=me
Attachment #8481984 - Flags: review?(bzbarsky) → review+
On the other hand, now Anne and Tab are arguing about how :scope is supposed to work here.  So we may want to wait until they decide something...
(Assignee)

Comment 11

3 years ago
OK, I'm following the discussion on www-dom as well.
Giovanni, looks like Anne and Tab agreed on what comment 9 says, so if you get a chance to do that, it would be wonderful.
(Assignee)

Comment 13

3 years ago
Created attachment 8489043 [details] [diff] [review]
Implement Element.Closest() v2

With pleasure! I added those two lines and three very basic tests. 

The test ":has(> :scope)" throws because we haven't implmeneted :has yet, I suppose? (I can't find the bug for it). I added that as a todo.

Asking for review in case you want to see it again before checkin, thanks!
Attachment #8481984 - Attachment is obsolete: true
Attachment #8489043 - Flags: review?(bzbarsky)
Comment on attachment 8489043 [details] [diff] [review]
Implement Element.Closest() v2

> The test ":has(> :scope)" throws because we haven't implmeneted :has yet,

Yep.

r=me.

Do you have the bits to push this to inbound, or should I do that?
Attachment #8489043 - Flags: review?(bzbarsky) → review+
Flags: needinfo?(agi.novanta)
(Assignee)

Comment 15

3 years ago
No, I don't have Level 3 yet. Thanks bz!
Flags: needinfo?(agi.novanta)
Keywords: checkin-needed
https://hg.mozilla.org/integration/mozilla-inbound/rev/a567789cf4ae
Keywords: checkin-needed
Created attachment 8489263 [details] [diff] [review]
Fix web-platform-tests metadata for addition of Element.closest
Attachment #8489263 - Flags: review?(bzbarsky)
https://hg.mozilla.org/mozilla-central/rev/a567789cf4ae
Status: ASSIGNED → RESOLVED
Last Resolved: 3 years ago
Resolution: --- → FIXED
Target Milestone: --- → mozilla35
Comment on attachment 8489263 [details] [diff] [review]
Fix web-platform-tests metadata for addition of Element.closest

r=me

We should consider adding web-platform-tests for the actual behavior of :closest....
Attachment #8489263 - Flags: review?(bzbarsky) → review+
https://hg.mozilla.org/integration/mozilla-inbound/rev/8cd3333dbb2d
(In reply to Boris Zbarsky [:bz] from comment #19) 
> We should consider adding web-platform-tests for the actual behavior of
> :closest....

Indeed we should. So I ported the mochitests from this patch. Needs some review (but not much since the actual tests are already reviewed) [1]

[1] https://critic.hoppipolla.co.uk/r/2600
https://hg.mozilla.org/mozilla-central/rev/8cd3333dbb2d
With the help of Ziyunfei (who fixed my errors in the example and translated it to Chinese), doc updated:
https://developer.mozilla.org/en-US/docs/Web/API/Element.closest
https://developer.mozilla.org/en-US/Firefox/Releases/35
Keywords: dev-doc-needed → dev-doc-complete
I landed the tests in web-platform-tests so we'll get them on the next update.

Comment 25

3 years ago
I couldn't see relevant documentation about Element.closest() in https://developer.mozilla.org/en-US/Firefox/Releases/35. Am I missing something?

Also I think this feature deserves to be rel-noted, what do you think?
Flags: needinfo?(jypenator)
merihakar: you are right, the mention in Fx 35 for devs wasn't there; it is now. Thanks for noticing it, I don't know what happened there.
Flags: needinfo?(jypenator)
You need to log in before you can comment on or make changes to this bug.