Advertisement
Guest User

Untitled

a guest
May 31st, 2017
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Diff 11.91 KB | None | 0 0
  1. From b4918b0403145c1fbcf63e49299905b5cbdc6a5c Mon Sep 17 00:00:00 2001
  2. From: Antonio Gomes <tonikitoo@webkit.org>
  3. Date: Mon, 14 Jun 2010 15:37:15 -0400
  4. Subject: [PATCH] 2010-06-17  Antonio Gomes  <tonikitoo@webkit.org>
  5.  
  6.         In summary, the patch:
  7.         * adds a OrderedNodeList class that inherits NodeList and works as a wrapper
  8.           to ListHashSet, making possible to expose it to Web content;
  9.         * implements a Document::nodesFromRect(x,y,horizontalPadding, verticarPadding)
  10.           method, making use of the rect hittest support.
  11.  
  12.         No new tests. (OOPS!)
  13.  
  14.         * WebCore.pro:
  15.         * dom/Document.cpp:
  16.         (WebCore::Document::nodesFromRect):
  17.         * dom/Document.h:
  18.         * dom/OrderedNodeList.cpp: Added.
  19.         (WebCore::OrderedNodeList::length):
  20.         (WebCore::OrderedNodeList::item):
  21.         (WebCore::OrderedNodeList::itemWithName):
  22.         * dom/OrderedNodeList.h: Added.
  23.         (WebCore::OrderedNodeList::adopt):
  24.         (WebCore::OrderedNodeList::OrderedNodeList):
  25. ---
  26. WebCore/ChangeLog               |   22 ++++++++++++
  27.  WebCore/WebCore.pro             |    2 +
  28.  WebCore/dom/Document.cpp        |   46 +++++++++++++++++++++++++
  29.  WebCore/dom/Document.h          |    2 +
  30.  WebCore/dom/OrderedNodeList.cpp |   67 +++++++++++++++++++++++++++++++++++++
  31.  WebCore/dom/OrderedNodeList.h   |   70 +++++++++++++++++++++++++++++++++++++++
  32.  6 files changed, 209 insertions(+), 0 deletions(-)
  33.  create mode 100644 WebCore/dom/OrderedNodeList.cpp
  34.  create mode 100644 WebCore/dom/OrderedNodeList.h
  35.  
  36. diff --git a/WebCore/ChangeLog b/WebCore/ChangeLog
  37. index 935b590..d44596f 100644
  38. --- a/WebCore/ChangeLog
  39. +++ b/WebCore/ChangeLog
  40. @@ -1,3 +1,25 @@
  41. +2010-06-17  Antonio Gomes  <tonikitoo@webkit.org>
  42. +
  43. +        In summary, the patch:
  44. +        * adds a OrderedNodeList class that inherits NodeList and works as a wrapper
  45. +          to ListHashSet, making possible to expose it to Web content;
  46. +        * implements a Document::nodesFromRect(x,y,horizontalPadding, verticarPadding)
  47. +          method, making use of the rect hittest support.
  48. +
  49. +        No new tests. (OOPS!)
  50. +
  51. +        * WebCore.pro:
  52. +        * dom/Document.cpp:
  53. +        (WebCore::Document::nodesFromRect):
  54. +        * dom/Document.h:
  55. +        * dom/OrderedNodeList.cpp: Added.
  56. +        (WebCore::OrderedNodeList::length):
  57. +        (WebCore::OrderedNodeList::item):
  58. +        (WebCore::OrderedNodeList::itemWithName):
  59. +        * dom/OrderedNodeList.h: Added.
  60. +        (WebCore::OrderedNodeList::adopt):
  61. +        (WebCore::OrderedNodeList::OrderedNodeList):
  62. +
  63.  2010-06-17  Pavel Feldman  <pfeldman@chromium.org>
  64.  
  65.          Unreviewed: chromium tests fix. Added InspectorBackend delegates for new inspector methods.
  66. diff --git a/WebCore/WebCore.pro b/WebCore/WebCore.pro
  67. index 06da9a2..380d7ba 100644
  68. --- a/WebCore/WebCore.pro
  69. +++ b/WebCore/WebCore.pro
  70. @@ -500,6 +500,7 @@ SOURCES += \
  71.      dom/Notation.cpp \
  72.      dom/OptionGroupElement.cpp \
  73.      dom/OptionElement.cpp \
  74. +    dom/OrderedNodeList.cpp \
  75.      dom/OverflowEvent.cpp \
  76.      dom/PageTransitionEvent.cpp \
  77.      dom/PopStateEvent.cpp \
  78. @@ -1234,6 +1235,7 @@ HEADERS += \
  79.      dom/Notation.h \
  80.      dom/OptionElement.h \
  81.      dom/OptionGroupElement.h \
  82. +    dom/OrderedNodeList.h \
  83.      dom/OverflowEvent.h \
  84.      dom/PageTransitionEvent.h \
  85.      dom/Position.h \
  86. diff --git a/WebCore/dom/Document.cpp b/WebCore/dom/Document.cpp
  87. index 9269ac7..6135a84 100644
  88. --- a/WebCore/dom/Document.cpp
  89. +++ b/WebCore/dom/Document.cpp
  90. @@ -97,6 +97,7 @@
  91.  #include "NodeFilter.h"
  92.  #include "NodeIterator.h"
  93.  #include "NodeWithIndex.h"
  94. +#include "OrderedNodeList.h"
  95.  #include "OverflowEvent.h"
  96.  #include "Page.h"
  97.  #include "PageGroup.h"
  98. @@ -999,6 +1000,51 @@ KURL Document::baseURI() const
  99.      return m_baseURL;
  100.  }
  101.  
  102. +// FIXME: we need to discuss the DOM API here. Maybe making it receive a real Rect,
  103. +// i.e. x, y, w, h.
  104. +
  105. +// nodesFromRect
  106. +PassRefPtr<NodeList> Document::nodesFromRect(int x, int y, const IntSize& padding) const
  107. +{
  108. +    return nodesFromRect(IntPoint(x, y), padding);
  109. +}
  110. +
  111. +PassRefPtr<NodeList> Document::nodesFromRect(const IntPoint& point, const IntSize& padding) const
  112. +{
  113. +    // FIXME: Share code between this, elementFromPoint and caretRangeFromPoint.
  114. +    if (!renderer())
  115. +        return 0;
  116. +
  117. +    Frame* frame = this->frame();
  118. +    if (!frame)
  119. +        return 0;
  120. +
  121. +    FrameView* frameView = frame->view();
  122. +    if (!frameView)
  123. +        return 0;
  124. +
  125. +    float zoomFactor = frameView->pageZoomFactor();
  126. +    IntPoint resolvedPoint = roundedIntPoint(FloatPoint(point.x() * zoomFactor  + view()->scrollX(), point.y() * zoomFactor + view()->scrollY()));
  127. +
  128. +    HitTestRequest request(HitTestRequest::ReadOnly | HitTestRequest::Active);
  129. +    HitTestResult result(resolvedPoint, padding);
  130. +
  131. +    if (!frameView->visibleContentRect().intersects(result.regionFromPoint(resolvedPoint)))
  132. +        return 0;
  133. +
  134. +    renderView()->layer()->hitTest(request, result);
  135. +
  136. +    // FIXME: we are returning Nodes and probably want Elements.
  137. +    //        We could add elements to the HitTest instead of Nodes.
  138. +    // while (n && !n->isElementNode())
  139. +    //    n = n->parentNode();
  140. +    // if (n)
  141. +    //    n = n->shadowAncestorNode();
  142. +    // return static_cast<Element*>(n);
  143. +
  144. +    return OrderedNodeList::adopt(result.rawNodeList());
  145. +}
  146. +
  147.  Element* Document::elementFromPoint(int x, int y) const
  148.  {
  149.      // FIXME: Share code between this and caretRangeFromPoint.
  150. diff --git a/WebCore/dom/Document.h b/WebCore/dom/Document.h
  151. index bc12da3..56d2adc 100644
  152. --- a/WebCore/dom/Document.h
  153. +++ b/WebCore/dom/Document.h
  154. @@ -299,6 +299,8 @@ public:
  155.      bool hasElementWithId(AtomicStringImpl* id) const;
  156.      bool containsMultipleElementsWithId(const AtomicString& elementId) { return m_duplicateIds.contains(elementId.impl()); }
  157.  
  158. +    PassRefPtr<NodeList> nodesFromRect(int x, int y, const IntSize& padding) const;
  159. +    PassRefPtr<NodeList> nodesFromRect(const IntPoint& point, const IntSize& padding) const;
  160.      Element* elementFromPoint(int x, int y) const;
  161.      PassRefPtr<Range> caretRangeFromPoint(int x, int y);
  162.  
  163. diff --git a/WebCore/dom/OrderedNodeList.cpp b/WebCore/dom/OrderedNodeList.cpp
  164. new file mode 100644
  165. index 0000000..3c6ba86
  166. --- /dev/null
  167. +++ b/WebCore/dom/OrderedNodeList.cpp
  168. @@ -0,0 +1,67 @@
  169. +/*
  170. + * Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies)
  171. + * Copyright (C) 2010 Antonio Gomes <tonikitoo@webkit.org>
  172. + *
  173. + * Redistribution and use in source and binary forms, with or without
  174. + * modification, are permitted provided that the following conditions
  175. + * are met:
  176. + *
  177. + * 1.  Redistributions of source code must retain the above copyright
  178. + *     notice, this list of conditions and the following disclaimer.
  179. + * 2.  Redistributions in binary form must reproduce the above copyright
  180. + *     notice, this list of conditions and the following disclaimer in the
  181. + *     documentation and/or other materials provided with the distribution.
  182. + * 3.  Neither the name of Apple Computer, Inc. ("Apple") nor the names of
  183. + *     its contributors may be used to endorse or promote products derived
  184. + *     from this software without specific prior written permission.
  185. + *
  186. + * THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY
  187. + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
  188. + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  189. + * DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY
  190. + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  191. + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  192. + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
  193. + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  194. + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
  195. + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  196. + */
  197. +
  198. +#include "config.h"
  199. +#include "OrderedNodeList.h"
  200. +
  201. +#include "Element.h"
  202. +
  203. +namespace WebCore {
  204. +
  205. +unsigned OrderedNodeList::length() const
  206. +{
  207. +    return m_nodes.size();
  208. +}
  209. +
  210. +Node* OrderedNodeList::item(unsigned index) const
  211. +{
  212. +    if (index < m_nodes.size()) {
  213. +        ListHashSet<RefPtr<Node> >::const_iterator it = m_nodes.begin();
  214. +        for (int count = 0; count < index; ++it, ++count);
  215. +        return (*it).get();
  216. +    }
  217. +
  218. +    return 0;
  219. +}
  220. +
  221. +Node* OrderedNodeList::itemWithName(const AtomicString& elementId) const
  222. +{
  223. +    ListHashSet<RefPtr<Node> >::const_iterator it = m_nodes.begin();
  224. +    ListHashSet<RefPtr<Node> >::const_iterator end = m_nodes.end();
  225. +    for ( ; it != end ; ++it) {
  226. +        Node* node = (*it).get();
  227. +        // FIXME: This should probably be using getIdAttribute instead of idForStyleResolution.
  228. +        if (node->hasID() && static_cast<Element*>(node)->getIdAttribute() == elementId)
  229. +            return node;
  230. +    }
  231. +
  232. +    return 0;
  233. +}
  234. +
  235. +} // namespace WebCore
  236. diff --git a/WebCore/dom/OrderedNodeList.h b/WebCore/dom/OrderedNodeList.h
  237. new file mode 100644
  238. index 0000000..613f988
  239. --- /dev/null
  240. +++ b/WebCore/dom/OrderedNodeList.h
  241. @@ -0,0 +1,70 @@
  242. +/*
  243. + * Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies)
  244. + * Copyright (C) 2010 Antonio Gomes <tonikitoo@webkit.org>
  245. + *
  246. + * Redistribution and use in source and binary forms, with or without
  247. + * modification, are permitted provided that the following conditions
  248. + * are met:
  249. + *
  250. + * 1.  Redistributions of source code must retain the above copyright
  251. + *     notice, this list of conditions and the following disclaimer.
  252. + * 2.  Redistributions in binary form must reproduce the above copyright
  253. + *     notice, this list of conditions and the following disclaimer in the
  254. + *     documentation and/or other materials provided with the distribution.
  255. + * 3.  Neither the name of Apple Computer, Inc. ("Apple") nor the names of
  256. + *     its contributors may be used to endorse or promote products derived
  257. + *     from this software without specific prior written permission.
  258. + *
  259. + * THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY
  260. + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
  261. + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  262. + * DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY
  263. + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  264. + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  265. + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
  266. + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  267. + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
  268. + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  269. + */
  270. +
  271. +#ifndef OrderedNodeList_h
  272. +#define OrderedNodeList_h
  273. +
  274. +#include "NodeList.h"
  275. +#include <wtf/ListHashSet.h>
  276. +#include <wtf/PassRefPtr.h>
  277. +#include <wtf/RefPtr.h>
  278. +
  279. +namespace WebCore {
  280. +
  281. +    class Node;
  282. +
  283. +    class OrderedNodeList : public NodeList {
  284. +    public:
  285. +        // Adopts the contents of the nodes ListHashSet.
  286. +        static PassRefPtr<OrderedNodeList> adopt(const ListHashSet<RefPtr<Node> >& nodes)
  287. +        {
  288. +            adopt(const_cast<ListHashSet<RefPtr<Node> >&>(nodes));
  289. +        }
  290. +
  291. +        static PassRefPtr<OrderedNodeList> adopt(ListHashSet<RefPtr<Node> >& nodes)
  292. +        {
  293. +            return adoptRef(new OrderedNodeList(nodes));
  294. +        }
  295. +
  296. +        virtual unsigned length() const;
  297. +        virtual Node* item(unsigned index) const;
  298. +        virtual Node* itemWithName(const AtomicString&) const;
  299. +
  300. +    private:
  301. +        OrderedNodeList(ListHashSet<RefPtr<Node> >& nodes)
  302. +        {
  303. +            m_nodes.swap(nodes);
  304. +        }
  305. +
  306. +        ListHashSet<RefPtr<Node> > m_nodes;
  307. +    };
  308. +
  309. +} // namespace WebCore
  310. +
  311. +#endif // OrderedNodeList_h
  312. --
  313. 1.7.0.4
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement