Closed Bug 1055533 Opened 10 years ago Closed 10 years ago

Implement Element.closest()

Categories

(Core :: DOM: Core & HTML, defect)

defect
Not set
normal

Tracking

()

RESOLVED FIXED
mozilla35

People

(Reporter: crimsteam, Assigned: agi, Mentored)

Details

(Keywords: dev-doc-complete, Whiteboard: [lang=c++])

Attachments

(2 files, 2 obsolete files)

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.
OS: Windows 7 → All
Hardware: x86_64 → All
Version: 34 Branch → Trunk
Mentor: bzbarsky
Status: UNCONFIRMED → NEW
Ever confirmed: true
Whiteboard: [lang=c++]
Hi, I'm interested in this bug. Where should I start with this?
Hi, Lynn. Thanks for your help! Boris, can you point to a DXR link to get Lynn started?
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 :)
Attached patch Implement closest() (obsolete) — Splinter Review
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+
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)
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...
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.
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)
No, I don't have Level 3 yet. Thanks bz!
Flags: needinfo?(agi.novanta)
Keywords: checkin-needed
Attachment #8489263 - Flags: review?(bzbarsky)
https://hg.mozilla.org/mozilla-central/rev/a567789cf4ae
Status: ASSIGNED → RESOLVED
Closed: 10 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+
(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
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
I landed the tests in web-platform-tests so we'll get them on the next update.
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.

Attachment

General

Created:
Updated:
Size: