Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(227)

Issue 44041: Add getElementsByClassName support

Can't Edit
Can't Publish+Mail
Start Review
Created:
16 years, 4 months ago by vlovich
Modified:
9 years, 9 months ago
Reviewers:
jgw, cromwellian
CC:
google-web-toolkit-contributors_googlegroups.com
Visibility:
Public.

Description

Enhancement request to track progress of adding getElementsByClassName support to Document & Elements. Ideally, it would follow HTML5 semantics as closely as possible, although this may be difficult for browsers that need use the XPath implementation for performance. There is also potentially a difference in behaviour if the lowest-overhead implementation: Safari XPath & browsers that implement getElementsByClassName natively will return a live NodeList. All other browsers will most likely have to return an array cast as a NodeList.

Patch Set 1 #

Total comments: 15
Unified diffs Side-by-side diffs Delta from patch set Stats (+129 lines, -0 lines) Patch
M user/src/com/google/gwt/dom/client/DOMImpl.java View 1 chunk +22 lines, -0 lines 5 comments Download
M user/src/com/google/gwt/dom/client/DOMImplSafari.java View 1 chunk +5 lines, -0 lines 2 comments Download
M user/src/com/google/gwt/dom/client/DOMImplStandard.java View 1 chunk +63 lines, -0 lines 6 comments Download
M user/src/com/google/gwt/dom/client/Document.java View 2 chunks +23 lines, -0 lines 2 comments Download
M user/src/com/google/gwt/dom/client/Element.java View 1 chunk +16 lines, -0 lines 0 comments Download

Messages

Total messages: 7
cromwellian
http://codereview.appspot.com/44041/diff/1/2 File user/src/com/google/gwt/dom/client/DOMImpl.java (right): http://codereview.appspot.com/44041/diff/1/2#newcode194 Line 194: for (j = regexps.length - 1; j >= ...
16 years, 4 months ago (2009-04-21 02:26:30 UTC) #1
vlovich
In the last response I meant to say getElementsByTagName returns a unique set, not getElementsByClassName ...
16 years, 4 months ago (2009-04-21 04:38:21 UTC) #2
vlovich
http://codereview.appspot.com/44041/diff/1/4 File user/src/com/google/gwt/dom/client/DOMImplStandard.java (right): http://codereview.appspot.com/44041/diff/1/4#newcode129 Line 129: var r, i, x = document.evaluate(xPath, parent, null, ...
16 years, 4 months ago (2009-04-21 05:11:14 UTC) #3
jgw
Thanks for digging into this -- it'll be helpful for a lot of developers. And ...
16 years, 4 months ago (2009-05-12 20:26:56 UTC) #4
vlovich
http://codereview.appspot.com/44041/diff/1/5 File user/src/com/google/gwt/dom/client/Document.java (right): http://codereview.appspot.com/44041/diff/1/5#newcode1148 Line 1148: return DOMImpl.impl.getElementsByClassName(this.<Element>cast(), className); On 2009/05/12 20:26:57, jgw wrote: ...
16 years, 4 months ago (2009-05-12 21:26:11 UTC) #5
cromwellian
Per Joel's request. http://codereview.appspot.com/44041/diff/1/3 File user/src/com/google/gwt/dom/client/DOMImplSafari.java (right): http://codereview.appspot.com/44041/diff/1/3#newcode173 Line 173: public native NodeList<Element> getElementsByXPath(Element parent, ...
16 years, 4 months ago (2009-05-14 18:50:42 UTC) #6
vlovich
16 years, 4 months ago (2009-05-14 20:38:11 UTC) #7
I'm going to start working on version 2 trying to incorporate all the feedback
so far.

http://codereview.appspot.com/44041/diff/1/3
File user/src/com/google/gwt/dom/client/DOMImplSafari.java (right):

http://codereview.appspot.com/44041/diff/1/3#newcode173
Line 173: public native NodeList<Element> getElementsByXPath(Element parent,
String xPath) /*-{
On 2009/05/14 18:50:42, cromwellian wrote:
> Where is this _getElementsByXPath function? Is this code copied from
> prototype.js? Also, if this is a function you've inserted on document, you
> should probably use $doc

Sorry - my bad.  Didn't read the code from the
http://webkit.org/blog/153/webkit-gets-native-getelementsbyclassname/ carefully
enough.  This function can be removed - the one provided in DOMImplStandard is
the one that should be used.

http://codereview.appspot.com/44041/diff/1/4
File user/src/com/google/gwt/dom/client/DOMImplStandard.java (right):

http://codereview.appspot.com/44041/diff/1/4#newcode159
Line 159: document.getElementsByClassName =
Element.prototype.getElementsByClassName = xpathImpl;
On 2009/05/14 18:50:42, cromwellian wrote:
> This code by default will run in an IFRAME that is different than the host
HTML
> page, so I'm not sure this is doing what you want, since you've overriding
> methods on the document object and Element.prototype of the IFRAME which
loaded
> the GWT code, not the one that has the elements you want to search.  $doc
refers
> to the document object of the host page.
> 

You are correct.  I should set them for the parent page, but please look at the
comment below for my proposed correction (this portion of code remains
unchanged).

http://codereview.appspot.com/44041/diff/1/4#newcode169
Line 169: if (!document.getElementsByClassName) {
On 2009/05/14 18:50:42, cromwellian wrote:
> The checks on document here are ok because another module or included JS
library
> might stomp on $doc.getElementsByClassName, so checking the private one in the
> IFRAME is better. However, if you truly want to check if a native
implementation
> exists, you can't just test for the existence of the function.

Actually, AFAIK, that's exactly the test to use to determine if the native
implementation exists (or in the more general case, if any implementation,
native or otherwise, of a JS function exists).

As for the stomping, I agree, but please comment on by reasoning in the added
snippet below.

http://codereview.appspot.com/44041/diff/1/4#newcode175
Line 175: }
I think I'm missing this code here to make it work:
  if (!$doc.getElementsByClassName) {
    $doc.getElementsByClassName = document.getElementsByClassName;
  }

  if (!$wnd.Element.prototype.getElementsByClassName) {
    $wnd.Element.prototype.getElementsByClassName =
Element.prototype.getElementsByClassName;
  }

In a little non-GWT snippet I wrote,
window.parent.Element.prototype.getElementsByClassName seemed to work from
within the iFrame on FF 3.5 in Linux.  Would this be an appropriate generic
solution?

Also, to detect stomping, I think, if the functions are already defined in $doc
but not document, we should give the developer some kind of warning message that
there might be a conflict with one of the libraries he/she uses.  What do you
think?  A call to GWT.log should probably suffice.
Sign in to reply to this message.

Powered by Google App Engine
RSS Feeds Recent Issues | This issue
This is Rietveld f62528b