Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- From b4918b0403145c1fbcf63e49299905b5cbdc6a5c Mon Sep 17 00:00:00 2001
- From: Antonio Gomes <tonikitoo@webkit.org>
- Date: Mon, 14 Jun 2010 15:37:15 -0400
- Subject: [PATCH] 2010-06-17 Antonio Gomes <tonikitoo@webkit.org>
- In summary, the patch:
- * adds a OrderedNodeList class that inherits NodeList and works as a wrapper
- to ListHashSet, making possible to expose it to Web content;
- * implements a Document::nodesFromRect(x,y,horizontalPadding, verticarPadding)
- method, making use of the rect hittest support.
- No new tests. (OOPS!)
- * WebCore.pro:
- * dom/Document.cpp:
- (WebCore::Document::nodesFromRect):
- * dom/Document.h:
- * dom/OrderedNodeList.cpp: Added.
- (WebCore::OrderedNodeList::length):
- (WebCore::OrderedNodeList::item):
- (WebCore::OrderedNodeList::itemWithName):
- * dom/OrderedNodeList.h: Added.
- (WebCore::OrderedNodeList::adopt):
- (WebCore::OrderedNodeList::OrderedNodeList):
- ---
- WebCore/ChangeLog | 22 ++++++++++++
- WebCore/WebCore.pro | 2 +
- WebCore/dom/Document.cpp | 46 +++++++++++++++++++++++++
- WebCore/dom/Document.h | 2 +
- WebCore/dom/OrderedNodeList.cpp | 67 +++++++++++++++++++++++++++++++++++++
- WebCore/dom/OrderedNodeList.h | 70 +++++++++++++++++++++++++++++++++++++++
- 6 files changed, 209 insertions(+), 0 deletions(-)
- create mode 100644 WebCore/dom/OrderedNodeList.cpp
- create mode 100644 WebCore/dom/OrderedNodeList.h
- diff --git a/WebCore/ChangeLog b/WebCore/ChangeLog
- index 935b590..d44596f 100644
- --- a/WebCore/ChangeLog
- +++ b/WebCore/ChangeLog
- @@ -1,3 +1,25 @@
- +2010-06-17 Antonio Gomes <tonikitoo@webkit.org>
- +
- + In summary, the patch:
- + * adds a OrderedNodeList class that inherits NodeList and works as a wrapper
- + to ListHashSet, making possible to expose it to Web content;
- + * implements a Document::nodesFromRect(x,y,horizontalPadding, verticarPadding)
- + method, making use of the rect hittest support.
- +
- + No new tests. (OOPS!)
- +
- + * WebCore.pro:
- + * dom/Document.cpp:
- + (WebCore::Document::nodesFromRect):
- + * dom/Document.h:
- + * dom/OrderedNodeList.cpp: Added.
- + (WebCore::OrderedNodeList::length):
- + (WebCore::OrderedNodeList::item):
- + (WebCore::OrderedNodeList::itemWithName):
- + * dom/OrderedNodeList.h: Added.
- + (WebCore::OrderedNodeList::adopt):
- + (WebCore::OrderedNodeList::OrderedNodeList):
- +
- 2010-06-17 Pavel Feldman <pfeldman@chromium.org>
- Unreviewed: chromium tests fix. Added InspectorBackend delegates for new inspector methods.
- diff --git a/WebCore/WebCore.pro b/WebCore/WebCore.pro
- index 06da9a2..380d7ba 100644
- --- a/WebCore/WebCore.pro
- +++ b/WebCore/WebCore.pro
- @@ -500,6 +500,7 @@ SOURCES += \
- dom/Notation.cpp \
- dom/OptionGroupElement.cpp \
- dom/OptionElement.cpp \
- + dom/OrderedNodeList.cpp \
- dom/OverflowEvent.cpp \
- dom/PageTransitionEvent.cpp \
- dom/PopStateEvent.cpp \
- @@ -1234,6 +1235,7 @@ HEADERS += \
- dom/Notation.h \
- dom/OptionElement.h \
- dom/OptionGroupElement.h \
- + dom/OrderedNodeList.h \
- dom/OverflowEvent.h \
- dom/PageTransitionEvent.h \
- dom/Position.h \
- diff --git a/WebCore/dom/Document.cpp b/WebCore/dom/Document.cpp
- index 9269ac7..6135a84 100644
- --- a/WebCore/dom/Document.cpp
- +++ b/WebCore/dom/Document.cpp
- @@ -97,6 +97,7 @@
- #include "NodeFilter.h"
- #include "NodeIterator.h"
- #include "NodeWithIndex.h"
- +#include "OrderedNodeList.h"
- #include "OverflowEvent.h"
- #include "Page.h"
- #include "PageGroup.h"
- @@ -999,6 +1000,51 @@ KURL Document::baseURI() const
- return m_baseURL;
- }
- +// FIXME: we need to discuss the DOM API here. Maybe making it receive a real Rect,
- +// i.e. x, y, w, h.
- +
- +// nodesFromRect
- +PassRefPtr<NodeList> Document::nodesFromRect(int x, int y, const IntSize& padding) const
- +{
- + return nodesFromRect(IntPoint(x, y), padding);
- +}
- +
- +PassRefPtr<NodeList> Document::nodesFromRect(const IntPoint& point, const IntSize& padding) const
- +{
- + // FIXME: Share code between this, elementFromPoint and caretRangeFromPoint.
- + if (!renderer())
- + return 0;
- +
- + Frame* frame = this->frame();
- + if (!frame)
- + return 0;
- +
- + FrameView* frameView = frame->view();
- + if (!frameView)
- + return 0;
- +
- + float zoomFactor = frameView->pageZoomFactor();
- + IntPoint resolvedPoint = roundedIntPoint(FloatPoint(point.x() * zoomFactor + view()->scrollX(), point.y() * zoomFactor + view()->scrollY()));
- +
- + HitTestRequest request(HitTestRequest::ReadOnly | HitTestRequest::Active);
- + HitTestResult result(resolvedPoint, padding);
- +
- + if (!frameView->visibleContentRect().intersects(result.regionFromPoint(resolvedPoint)))
- + return 0;
- +
- + renderView()->layer()->hitTest(request, result);
- +
- + // FIXME: we are returning Nodes and probably want Elements.
- + // We could add elements to the HitTest instead of Nodes.
- + // while (n && !n->isElementNode())
- + // n = n->parentNode();
- + // if (n)
- + // n = n->shadowAncestorNode();
- + // return static_cast<Element*>(n);
- +
- + return OrderedNodeList::adopt(result.rawNodeList());
- +}
- +
- Element* Document::elementFromPoint(int x, int y) const
- {
- // FIXME: Share code between this and caretRangeFromPoint.
- diff --git a/WebCore/dom/Document.h b/WebCore/dom/Document.h
- index bc12da3..56d2adc 100644
- --- a/WebCore/dom/Document.h
- +++ b/WebCore/dom/Document.h
- @@ -299,6 +299,8 @@ public:
- bool hasElementWithId(AtomicStringImpl* id) const;
- bool containsMultipleElementsWithId(const AtomicString& elementId) { return m_duplicateIds.contains(elementId.impl()); }
- + PassRefPtr<NodeList> nodesFromRect(int x, int y, const IntSize& padding) const;
- + PassRefPtr<NodeList> nodesFromRect(const IntPoint& point, const IntSize& padding) const;
- Element* elementFromPoint(int x, int y) const;
- PassRefPtr<Range> caretRangeFromPoint(int x, int y);
- diff --git a/WebCore/dom/OrderedNodeList.cpp b/WebCore/dom/OrderedNodeList.cpp
- new file mode 100644
- index 0000000..3c6ba86
- --- /dev/null
- +++ b/WebCore/dom/OrderedNodeList.cpp
- @@ -0,0 +1,67 @@
- +/*
- + * Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies)
- + * Copyright (C) 2010 Antonio Gomes <tonikitoo@webkit.org>
- + *
- + * Redistribution and use in source and binary forms, with or without
- + * modification, are permitted provided that the following conditions
- + * are met:
- + *
- + * 1. Redistributions of source code must retain the above copyright
- + * notice, this list of conditions and the following disclaimer.
- + * 2. Redistributions in binary form must reproduce the above copyright
- + * notice, this list of conditions and the following disclaimer in the
- + * documentation and/or other materials provided with the distribution.
- + * 3. Neither the name of Apple Computer, Inc. ("Apple") nor the names of
- + * its contributors may be used to endorse or promote products derived
- + * from this software without specific prior written permission.
- + *
- + * THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY
- + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
- + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
- + * DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY
- + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
- + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
- + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
- + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
- + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- + */
- +
- +#include "config.h"
- +#include "OrderedNodeList.h"
- +
- +#include "Element.h"
- +
- +namespace WebCore {
- +
- +unsigned OrderedNodeList::length() const
- +{
- + return m_nodes.size();
- +}
- +
- +Node* OrderedNodeList::item(unsigned index) const
- +{
- + if (index < m_nodes.size()) {
- + ListHashSet<RefPtr<Node> >::const_iterator it = m_nodes.begin();
- + for (int count = 0; count < index; ++it, ++count);
- + return (*it).get();
- + }
- +
- + return 0;
- +}
- +
- +Node* OrderedNodeList::itemWithName(const AtomicString& elementId) const
- +{
- + ListHashSet<RefPtr<Node> >::const_iterator it = m_nodes.begin();
- + ListHashSet<RefPtr<Node> >::const_iterator end = m_nodes.end();
- + for ( ; it != end ; ++it) {
- + Node* node = (*it).get();
- + // FIXME: This should probably be using getIdAttribute instead of idForStyleResolution.
- + if (node->hasID() && static_cast<Element*>(node)->getIdAttribute() == elementId)
- + return node;
- + }
- +
- + return 0;
- +}
- +
- +} // namespace WebCore
- diff --git a/WebCore/dom/OrderedNodeList.h b/WebCore/dom/OrderedNodeList.h
- new file mode 100644
- index 0000000..613f988
- --- /dev/null
- +++ b/WebCore/dom/OrderedNodeList.h
- @@ -0,0 +1,70 @@
- +/*
- + * Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies)
- + * Copyright (C) 2010 Antonio Gomes <tonikitoo@webkit.org>
- + *
- + * Redistribution and use in source and binary forms, with or without
- + * modification, are permitted provided that the following conditions
- + * are met:
- + *
- + * 1. Redistributions of source code must retain the above copyright
- + * notice, this list of conditions and the following disclaimer.
- + * 2. Redistributions in binary form must reproduce the above copyright
- + * notice, this list of conditions and the following disclaimer in the
- + * documentation and/or other materials provided with the distribution.
- + * 3. Neither the name of Apple Computer, Inc. ("Apple") nor the names of
- + * its contributors may be used to endorse or promote products derived
- + * from this software without specific prior written permission.
- + *
- + * THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY
- + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
- + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
- + * DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY
- + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
- + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
- + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
- + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
- + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- + */
- +
- +#ifndef OrderedNodeList_h
- +#define OrderedNodeList_h
- +
- +#include "NodeList.h"
- +#include <wtf/ListHashSet.h>
- +#include <wtf/PassRefPtr.h>
- +#include <wtf/RefPtr.h>
- +
- +namespace WebCore {
- +
- + class Node;
- +
- + class OrderedNodeList : public NodeList {
- + public:
- + // Adopts the contents of the nodes ListHashSet.
- + static PassRefPtr<OrderedNodeList> adopt(const ListHashSet<RefPtr<Node> >& nodes)
- + {
- + adopt(const_cast<ListHashSet<RefPtr<Node> >&>(nodes));
- + }
- +
- + static PassRefPtr<OrderedNodeList> adopt(ListHashSet<RefPtr<Node> >& nodes)
- + {
- + return adoptRef(new OrderedNodeList(nodes));
- + }
- +
- + virtual unsigned length() const;
- + virtual Node* item(unsigned index) const;
- + virtual Node* itemWithName(const AtomicString&) const;
- +
- + private:
- + OrderedNodeList(ListHashSet<RefPtr<Node> >& nodes)
- + {
- + m_nodes.swap(nodes);
- + }
- +
- + ListHashSet<RefPtr<Node> > m_nodes;
- + };
- +
- +} // namespace WebCore
- +
- +#endif // OrderedNodeList_h
- --
- 1.7.0.4
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement