Diff
Modified: trunk/Source/WebCore/ChangeLog (121231 => 121232)
--- trunk/Source/WebCore/ChangeLog 2012-06-26 06:05:25 UTC (rev 121231)
+++ trunk/Source/WebCore/ChangeLog 2012-06-26 06:29:58 UTC (rev 121232)
@@ -1,3 +1,38 @@
+2012-06-25 Ryosuke Niwa <rn...@webkit.org>
+
+ Get rid of firstItem and nextItem from HTMLCollection
+ https://bugs.webkit.org/show_bug.cgi?id=89923
+
+ Reviewed by Andreas Kling.
+
+ Removed HTMLCollection::firstItem and HTMLCollection::nextItem.
+ Also added hasAnyItem() and hasExactlyOneItem() to HTMLCollection so that named getter on Document
+ doesn't need to compute the full length before returning a HTMLCollection.
+
+ * accessibility/AccessibilityRenderObject.cpp:
+ (WebCore::AccessibilityRenderObject::getDocumentLinks):
+ * bindings/js/JSDOMWindowCustom.cpp:
+ (WebCore::namedItemGetter):
+ * bindings/js/JSHTMLDocumentCustom.cpp:
+ (WebCore::JSHTMLDocument::nameGetter):
+ * bindings/v8/custom/V8DOMWindowCustom.cpp:
+ (WebCore::V8DOMWindow::namedPropertyGetter):
+ * bindings/v8/custom/V8HTMLDocumentCustom.cpp:
+ (WebCore::V8HTMLDocument::GetNamedProperty):
+ * dom/Document.cpp:
+ (WebCore::Document::openSearchDescriptionURL):
+ * html/HTMLCollection.cpp:
+ (WebCore::shouldIncludeChildren):
+ (WebCore::HTMLCollection::HTMLCollection):
+ (WebCore):
+ (WebCore::HTMLCollection::item):
+ * html/HTMLCollection.h:
+ (HTMLCollection):
+ (WebCore::HTMLCollection::hasAnyItem):
+ (WebCore::HTMLCollection::hasExactlyOneItem):
+ * html/HTMLMapElement.cpp:
+ (WebCore::HTMLMapElement::imageElement):
+
2012-06-25 Pratik Solanki <psola...@apple.com>
_javascript_ resources have low priority when SVG is enabled
Modified: trunk/Source/WebCore/accessibility/AccessibilityRenderObject.cpp (121231 => 121232)
--- trunk/Source/WebCore/accessibility/AccessibilityRenderObject.cpp 2012-06-26 06:05:25 UTC (rev 121231)
+++ trunk/Source/WebCore/accessibility/AccessibilityRenderObject.cpp 2012-06-26 06:29:58 UTC (rev 121232)
@@ -2424,9 +2424,8 @@
void AccessibilityRenderObject::getDocumentLinks(AccessibilityChildrenVector& result)
{
Document* document = m_renderer->document();
- HTMLCollection* coll = document->links();
- Node* curr = coll->firstItem();
- while (curr) {
+ HTMLCollection* links = document->links();
+ for (unsigned i = 0; Node* curr = links->item(i); i++) {
RenderObject* obj = curr->renderer();
if (obj) {
RefPtr<AccessibilityObject> axobj = document->axObjectCache()->getOrCreate(obj);
@@ -2444,7 +2443,6 @@
result.append(areaObject);
}
}
- curr = coll->nextItem();
}
}
Modified: trunk/Source/WebCore/bindings/js/JSDOMWindowCustom.cpp (121231 => 121232)
--- trunk/Source/WebCore/bindings/js/JSDOMWindowCustom.cpp 2012-06-26 06:05:25 UTC (rev 121231)
+++ trunk/Source/WebCore/bindings/js/JSDOMWindowCustom.cpp 2012-06-26 06:29:58 UTC (rev 121232)
@@ -117,8 +117,8 @@
ASSERT(document->isHTMLDocument());
HTMLCollection* collection = document->windowNamedItems(propertyNameToAtomicString(propertyName));
- if (collection->length() == 1)
- return toJS(exec, thisObj, collection->firstItem());
+ if (collection->hasExactlyOneItem())
+ return toJS(exec, thisObj, collection->item(0));
return toJS(exec, thisObj, collection);
}
Modified: trunk/Source/WebCore/bindings/js/JSHTMLDocumentCustom.cpp (121231 => 121232)
--- trunk/Source/WebCore/bindings/js/JSHTMLDocumentCustom.cpp 2012-06-26 06:05:25 UTC (rev 121231)
+++ trunk/Source/WebCore/bindings/js/JSHTMLDocumentCustom.cpp 2012-06-26 06:29:58 UTC (rev 121232)
@@ -64,12 +64,11 @@
HTMLCollection* collection = document->documentNamedItems(propertyNameToAtomicString(propertyName));
- unsigned length = collection->length();
- if (!length)
+ if (!collection->hasAnyItem())
return jsUndefined();
- if (length == 1) {
- Node* node = collection->firstItem();
+ if (collection->hasExactlyOneItem()) {
+ Node* node = collection->item(0);
Frame* frame;
if (node->hasTagName(iframeTag) && (frame = static_cast<HTMLIFrameElement*>(node)->contentFrame()))
Modified: trunk/Source/WebCore/bindings/v8/custom/V8DOMWindowCustom.cpp (121231 => 121232)
--- trunk/Source/WebCore/bindings/v8/custom/V8DOMWindowCustom.cpp 2012-06-26 06:05:25 UTC (rev 121231)
+++ trunk/Source/WebCore/bindings/v8/custom/V8DOMWindowCustom.cpp 2012-06-26 06:29:58 UTC (rev 121232)
@@ -521,9 +521,9 @@
if (doc && doc->isHTMLDocument()) {
if (static_cast<HTMLDocument*>(doc)->hasNamedItem(propName.impl()) || doc->hasElementWithId(propName.impl())) {
HTMLCollection* items = doc->windowNamedItems(propName);
- if (items->length() >= 1) {
- if (items->length() == 1)
- return toV8(items->firstItem(), info.GetIsolate());
+ if (items->hasAnyItem()) {
+ if (items->hasExactlyOneItem())
+ return toV8(items->item(0), info.GetIsolate());
return toV8(items, info.GetIsolate());
}
}
Modified: trunk/Source/WebCore/bindings/v8/custom/V8HTMLDocumentCustom.cpp (121231 => 121232)
--- trunk/Source/WebCore/bindings/v8/custom/V8HTMLDocumentCustom.cpp 2012-06-26 06:05:25 UTC (rev 121231)
+++ trunk/Source/WebCore/bindings/v8/custom/V8HTMLDocumentCustom.cpp 2012-06-26 06:29:58 UTC (rev 121232)
@@ -85,11 +85,11 @@
return v8::Handle<v8::Value>();
HTMLCollection* items = htmlDocument->documentNamedItems(key);
- if (!items->length())
+ if (!items->hasAnyItem())
return v8::Handle<v8::Value>();
- if (items->length() == 1) {
- Node* node = items->firstItem();
+ if (items->hasExactlyOneItem()) {
+ Node* node = items->item(0);
Frame* frame = 0;
if (node->hasTagName(HTMLNames::iframeTag) && (frame = static_cast<HTMLIFrameElement*>(node)->contentFrame()))
return toV8(frame->domWindow(), isolate);
Modified: trunk/Source/WebCore/dom/Document.cpp (121231 => 121232)
--- trunk/Source/WebCore/dom/Document.cpp 2012-06-26 06:05:25 UTC (rev 121231)
+++ trunk/Source/WebCore/dom/Document.cpp 2012-06-26 06:29:58 UTC (rev 121232)
@@ -4581,7 +4581,7 @@
return KURL();
HTMLCollection* children = head()->children();
- for (Node* child = children->firstItem(); child; child = children->nextItem()) {
+ for (unsigned i = 0; Node* child = children->item(i); i++) {
if (!child->hasTagName(linkTag))
continue;
HTMLLinkElement* linkElement = static_cast<HTMLLinkElement*>(child);
Modified: trunk/Source/WebCore/html/HTMLCollection.cpp (121231 => 121232)
--- trunk/Source/WebCore/html/HTMLCollection.cpp 2012-06-26 06:05:25 UTC (rev 121231)
+++ trunk/Source/WebCore/html/HTMLCollection.cpp 2012-06-26 06:29:58 UTC (rev 121232)
@@ -36,17 +36,8 @@
using namespace HTMLNames;
-HTMLCollection::HTMLCollection(Node* base, CollectionType type)
- : m_includeChildren(shouldIncludeChildren(type))
- , m_type(type)
- , m_base(base)
+static bool shouldIncludeChildren(CollectionType type)
{
- ASSERT(m_base);
- m_cache.clear();
-}
-
-bool HTMLCollection::shouldIncludeChildren(CollectionType type)
-{
switch (type) {
case DocAll:
case DocAnchors:
@@ -78,6 +69,15 @@
return false;
}
+HTMLCollection::HTMLCollection(Node* base, CollectionType type)
+ : m_includeChildren(shouldIncludeChildren(type))
+ , m_type(type)
+ , m_base(base)
+{
+ ASSERT(m_base);
+ m_cache.clear();
+}
+
PassOwnPtr<HTMLCollection> HTMLCollection::create(Node* base, CollectionType type)
{
return adoptPtr(new HTMLCollection(base, type));
@@ -199,41 +199,25 @@
Node* HTMLCollection::item(unsigned index) const
{
- invalidateCacheIfNeeded();
- if (m_cache.current && m_cache.position == index)
- return m_cache.current;
- if (m_cache.hasLength && m_cache.length <= index)
- return 0;
- if (!m_cache.current || m_cache.position > index) {
- m_cache.current = itemAfter(0);
- m_cache.position = 0;
- if (!m_cache.current)
- return 0;
- }
- Element* e = m_cache.current;
- for (unsigned pos = m_cache.position; e && pos < index; pos++)
- e = itemAfter(e);
- m_cache.current = e;
- m_cache.position = index;
- return m_cache.current;
+ invalidateCacheIfNeeded();
+ if (m_cache.current && m_cache.position == index)
+ return m_cache.current;
+ if (m_cache.hasLength && m_cache.length <= index)
+ return 0;
+ if (!m_cache.current || m_cache.position > index) {
+ m_cache.current = itemAfter(0);
+ m_cache.position = 0;
+ if (!m_cache.current)
+ return 0;
+ }
+ Element* e = m_cache.current;
+ for (unsigned pos = m_cache.position; e && pos < index; pos++)
+ e = itemAfter(e);
+ m_cache.current = e;
+ m_cache.position = index;
+ return m_cache.current;
}
-Node* HTMLCollection::firstItem() const
-{
- return item(0);
-}
-
-Node* HTMLCollection::nextItem() const
-{
- invalidateCacheIfNeeded();
-
- // Look for the 'second' item. The first one is currentItem, already given back.
- Element* retval = itemAfter(m_cache.current);
- m_cache.current = retval;
- m_cache.position++;
- return retval;
-}
-
static inline bool nameShouldBeVisibleInDocumentAll(HTMLElement* element)
{
// The document.all collection returns only certain types of elements by name,
Modified: trunk/Source/WebCore/html/HTMLCollection.h (121231 => 121232)
--- trunk/Source/WebCore/html/HTMLCollection.h 2012-06-26 06:05:25 UTC (rev 121231)
+++ trunk/Source/WebCore/html/HTMLCollection.h 2012-06-26 06:29:58 UTC (rev 121232)
@@ -44,20 +44,26 @@
void ref() { m_base->ref(); }
void deref() { m_base->deref(); }
+ // DOM API
unsigned length() const;
-
virtual Node* item(unsigned index) const;
- virtual Node* nextItem() const;
-
virtual Node* namedItem(const AtomicString& name) const;
+ PassRefPtr<NodeList> tags(const String&);
- Node* firstItem() const;
-
+ // Non-DOM API
bool hasNamedItem(const AtomicString& name) const;
void namedItems(const AtomicString& name, Vector<RefPtr<Node> >&) const;
+ bool hasAnyItem() const
+ {
+ invalidateCacheIfNeeded();
+ return (m_cache.hasLength && m_cache.length) || m_cache.current || item(0);
+ }
+ bool hasExactlyOneItem() const
+ {
+ invalidateCacheIfNeeded();
+ return (m_cache.hasLength && m_cache.length == 1) || (m_cache.current && !itemAfter(m_cache.current)) || (item(0) && !item(1));
+ }
- PassRefPtr<NodeList> tags(const String&);
-
Node* base() const { return m_base; }
CollectionType type() const { return static_cast<CollectionType>(m_type); }
@@ -98,7 +104,6 @@
} m_cache;
private:
- static bool shouldIncludeChildren(CollectionType);
bool checkForNameMatch(Element*, bool checkName, const AtomicString& name) const;
virtual unsigned calcLength() const;
Modified: trunk/Source/WebCore/html/HTMLMapElement.cpp (121231 => 121232)
--- trunk/Source/WebCore/html/HTMLMapElement.cpp 2012-06-26 06:05:25 UTC (rev 121231)
+++ trunk/Source/WebCore/html/HTMLMapElement.cpp 2012-06-26 06:29:58 UTC (rev 121232)
@@ -82,8 +82,8 @@
HTMLImageElement* HTMLMapElement::imageElement()
{
- HTMLCollection* coll = document()->images();
- for (Node* curr = coll->firstItem(); curr; curr = coll->nextItem()) {
+ HTMLCollection* images = document()->images();
+ for (unsigned i = 0; Node* curr = images->item(i); i++) {
if (!curr->hasTagName(imgTag))
continue;
Modified: trunk/Source/WebKit/chromium/ChangeLog (121231 => 121232)
--- trunk/Source/WebKit/chromium/ChangeLog 2012-06-26 06:05:25 UTC (rev 121231)
+++ trunk/Source/WebKit/chromium/ChangeLog 2012-06-26 06:29:58 UTC (rev 121232)
@@ -1,3 +1,24 @@
+2012-06-25 Ryosuke Niwa <rn...@webkit.org>
+
+ Get rid of firstItem and nextItem from HTMLCollection
+ https://bugs.webkit.org/show_bug.cgi?id=89923
+
+ Reviewed by Andreas Kling.
+
+ Re-implement WebNodeCollection::firstItem() and WebNodeCollection::nextItem() in WebKit code
+ because we got rid of it from WebCore implementation.
+
+ This is an extremely poor API and we shouldn't be exposing it in the future.
+
+ * public/WebNodeCollection.h:
+ (WebKit::WebNodeCollection::WebNodeCollection):
+ (WebNodeCollection):
+ * src/WebNodeCollection.cpp:
+ (WebKit::WebNodeCollection::nextItem):
+ (WebKit::WebNodeCollection::firstItem):
+ * src/WebPageSerializerImpl.cpp:
+ (WebKit::WebPageSerializerImpl::collectTargetFrames):
+
2012-06-25 Luke Macpherson <macpher...@chromium.org>
Add runtime flag to enable/disable CSS variables (in addition to existing compile-time flag).
Modified: trunk/Source/WebKit/chromium/public/WebNodeCollection.h (121231 => 121232)
--- trunk/Source/WebKit/chromium/public/WebNodeCollection.h 2012-06-26 06:05:25 UTC (rev 121231)
+++ trunk/Source/WebKit/chromium/public/WebNodeCollection.h 2012-06-26 06:29:58 UTC (rev 121232)
@@ -46,7 +46,7 @@
public:
~WebNodeCollection() { reset(); }
- WebNodeCollection() : m_private(0) { }
+ WebNodeCollection() : m_private(0), m_current(0) { }
WebNodeCollection(const WebNodeCollection& n) : m_private(0) { assign(n); }
WebNodeCollection& operator=(const WebNodeCollection& n)
{
@@ -70,6 +70,7 @@
private:
void assign(WebCore::HTMLCollection*);
WebCore::HTMLCollection* m_private;
+ mutable unsigned m_current;
};
} // namespace WebKit
Modified: trunk/Source/WebKit/chromium/src/WebNodeCollection.cpp (121231 => 121232)
--- trunk/Source/WebKit/chromium/src/WebNodeCollection.cpp 2012-06-26 06:05:25 UTC (rev 121231)
+++ trunk/Source/WebKit/chromium/src/WebNodeCollection.cpp 2012-06-26 06:29:58 UTC (rev 121232)
@@ -74,12 +74,16 @@
WebNode WebNodeCollection::nextItem() const
{
- return WebNode(m_private->nextItem());
+ Node* node = m_private->item(m_current);
+ if (node)
+ m_current++;
+ return WebNode(node);
}
WebNode WebNodeCollection::firstItem() const
{
- return WebNode(m_private->firstItem());
+ m_current = 0;
+ return nextItem();
}
} // namespace WebKit
Modified: trunk/Source/WebKit/chromium/src/WebPageSerializerImpl.cpp (121231 => 121232)
--- trunk/Source/WebKit/chromium/src/WebPageSerializerImpl.cpp 2012-06-26 06:05:25 UTC (rev 121231)
+++ trunk/Source/WebKit/chromium/src/WebPageSerializerImpl.cpp 2012-06-26 06:29:58 UTC (rev 121232)
@@ -477,7 +477,8 @@
Document* currentDoc = currentFrame->frame()->document();
// Go through sub-frames.
RefPtr<HTMLAllCollection> all = currentDoc->all();
- for (Node* node = all->firstItem(); node; node = all->nextItem()) {
+
+ for (unsigned i = 0; Node* node = all->item(i); i++) {
if (!node->isHTMLElement())
continue;
Element* element = static_cast<Element*>(node);