Title: [145757] trunk/Source/WebKit
Revision
145757
Author
[email protected]
Date
2013-03-13 14:49:35 -0700 (Wed, 13 Mar 2013)

Log Message

[BlackBerry] Add Proximity Detector.
https://bugs.webkit.org/show_bug.cgi?id=112278

Patch by Genevieve Mak <[email protected]> on 2013-03-13
Reviewed by Rob Buis.

Internally Reviewed by Mike Lattanzio.
PR #243385

Source/WebKit:

* PlatformBlackBerry.cmake:

Source/WebKit/blackberry:

* WebKitSupport/ProximityDetector.cpp: Added.
(WebKit):
(BlackBerry::WebKit::getPriorityLevel):
(BlackBerry::WebKit::ProximityDetector::ProximityDetector):
(BlackBerry::WebKit::ProximityDetector::~ProximityDetector):
(BlackBerry::WebKit::ProximityDetector::findBestPoint):
* WebKitSupport/ProximityDetector.h: Added.
(WebCore):
(WebKit):
(ProximityDetector):

Modified Paths

Added Paths

Diff

Modified: trunk/Source/WebKit/ChangeLog (145756 => 145757)


--- trunk/Source/WebKit/ChangeLog	2013-03-13 21:43:13 UTC (rev 145756)
+++ trunk/Source/WebKit/ChangeLog	2013-03-13 21:49:35 UTC (rev 145757)
@@ -1,3 +1,15 @@
+2013-03-13  Genevieve Mak  <[email protected]>
+
+        [BlackBerry] Add Proximity Detector.
+        https://bugs.webkit.org/show_bug.cgi?id=112278
+
+        Reviewed by Rob Buis.
+
+        Internally Reviewed by Mike Lattanzio.
+        PR #243385
+
+        * PlatformBlackBerry.cmake:
+
 2013-03-08  Roger Fong  <[email protected]>
 
         Build fix for AppleWin VS2010.

Modified: trunk/Source/WebKit/PlatformBlackBerry.cmake (145756 => 145757)


--- trunk/Source/WebKit/PlatformBlackBerry.cmake	2013-03-13 21:43:13 UTC (rev 145756)
+++ trunk/Source/WebKit/PlatformBlackBerry.cmake	2013-03-13 21:49:35 UTC (rev 145757)
@@ -135,6 +135,7 @@
     blackberry/WebKitSupport/InRegionScrollableArea.cpp
     blackberry/WebKitSupport/InspectorOverlayBlackBerry.cpp
     blackberry/WebKitSupport/NotificationManager.cpp
+    blackberry/WebKitSupport/ProximityDetector.cpp
     blackberry/WebKitSupport/RenderQueue.cpp
     blackberry/WebKitSupport/SelectionHandler.cpp
     blackberry/WebKitSupport/SelectionOverlay.cpp

Modified: trunk/Source/WebKit/blackberry/ChangeLog (145756 => 145757)


--- trunk/Source/WebKit/blackberry/ChangeLog	2013-03-13 21:43:13 UTC (rev 145756)
+++ trunk/Source/WebKit/blackberry/ChangeLog	2013-03-13 21:49:35 UTC (rev 145757)
@@ -1,3 +1,24 @@
+2013-03-13  Genevieve Mak  <[email protected]>
+
+        [BlackBerry] Add Proximity Detector.
+        https://bugs.webkit.org/show_bug.cgi?id=112278
+
+        Reviewed by Rob Buis.
+
+        Internally Reviewed by Mike Lattanzio.
+        PR #243385
+
+        * WebKitSupport/ProximityDetector.cpp: Added.
+        (WebKit):
+        (BlackBerry::WebKit::getPriorityLevel):
+        (BlackBerry::WebKit::ProximityDetector::ProximityDetector):
+        (BlackBerry::WebKit::ProximityDetector::~ProximityDetector):
+        (BlackBerry::WebKit::ProximityDetector::findBestPoint):
+        * WebKitSupport/ProximityDetector.h: Added.
+        (WebCore):
+        (WebKit):
+        (ProximityDetector):
+
 2013-03-13  Iris Wu  <[email protected]>
 
         [BlackBerry] Touch Hold selection does not scroll text area or other subframe until selection reaches bottom of the page.

Added: trunk/Source/WebKit/blackberry/WebKitSupport/ProximityDetector.cpp (0 => 145757)


--- trunk/Source/WebKit/blackberry/WebKitSupport/ProximityDetector.cpp	                        (rev 0)
+++ trunk/Source/WebKit/blackberry/WebKitSupport/ProximityDetector.cpp	2013-03-13 21:49:35 UTC (rev 145757)
@@ -0,0 +1,115 @@
+/*
+ * Copyright (C) 2012, 2013 Research In Motion Limited. All rights reserved.
+ */
+
+#include "config.h"
+#include "ProximityDetector.h"
+
+#include "Document.h"
+#include "Element.h"
+#include "ExceptionCode.h"
+#include "HTMLNames.h"
+#include "HitTestResult.h"
+#include "RenderLayer.h"
+#include "RenderObject.h"
+#include "RenderView.h"
+#include "WebPage_p.h"
+
+using namespace WebCore;
+
+namespace BlackBerry {
+namespace WebKit {
+
+static int getPriorityLevel(Node* node)
+{
+    // Priority level is ascending with zero being the lowest.
+    if (node->isTextNode())
+        return 1;
+
+    if (!node->isElementNode())
+        return 0;
+
+    Element* element = toElement(node);
+    ASSERT(element);
+    ExceptionCode ec = 0;
+
+    if (element->webkitMatchesSelector("img,obj", ec))
+        return 1;
+
+    if (element->hasTagName(HTMLNames::pTag))
+        return 2;
+
+    if (element->webkitMatchesSelector("h1,h2,h3,h4,h5,h6", ec))
+        return 3;
+
+    return 0;
+}
+
+ProximityDetector::ProximityDetector(WebPagePrivate* webPage)
+    : m_webPage(webPage)
+{
+}
+
+ProximityDetector::~ProximityDetector()
+{
+}
+
+IntPoint ProximityDetector::findBestPoint(const IntPoint& documentPos, const IntRect& documentPaddingRect)
+{
+    ASSERT(m_webPage);
+
+    if (!m_webPage->m_mainFrame)
+        return contentPos;
+
+    Document* document = m_webPage->m_mainFrame->document();
+
+    if (!document || !document->frame()->view())
+        return contentPos;
+
+    unsigned left = -paddingRect.x();
+    unsigned top = -paddingRect.y();
+    unsigned right = paddingRect.maxX();
+    unsigned bottom = paddingRect.maxY();
+
+    // Adjust hit point to frame
+    IntPoint frameContentPos(document->frame()->view()->windowToContents(m_webPage->m_mainFrame->view()->contentsToWindow(contentPos)));
+    HitTestRequest request(HitTestRequest::ReadOnly | HitTestRequest::Active | HitTestRequest::IgnoreClipping);
+    HitTestResult result(frameContentPos, top, right, bottom, left);
+    document->renderView()->layer()->hitTest(request, result);
+
+    IntPoint bestPoint = contentPos;
+    int bestPriority = 0;
+
+    // Iterate over the list of nodes checking both priority and location
+    ListHashSet<RefPtr<Node> > intersectedNodes = result.rectBasedTestResult();
+    ListHashSet<RefPtr<Node> >::const_iterator it = intersectedNodes.begin();
+    ListHashSet<RefPtr<Node> >::const_iterator end = intersectedNodes.end();
+    for ( ; it != end; ++it) {
+
+        Node* curNode = (*it).get();
+        if (!curNode || !curNode->renderer())
+            continue;
+
+        IntRect curRect = curNode->renderer()->absoluteBoundingBoxRect(true /*use transforms*/);
+        IntRect hitTestRect = HitTestResult::rectForPoint(contentPos, top, right, bottom, left);
+
+        // Check that top corner does not exceed padding
+        if (!hitTestRect.contains(curRect.location()))
+            continue;
+
+        int priority = getPriorityLevel(curNode);
+        if (!priority)
+            continue;
+
+        bool equalPriorityAndCloser = (priority == bestPriority) && (contentPos.distanceSquaredToPoint(bestPoint) > contentPos.distanceSquaredToPoint(curRect.location()));
+        if (priority > bestPriority || equalPriorityAndCloser) {
+            bestPoint = curRect.location(); // use top left
+            bestPriority = priority;
+        }
+    }
+
+    return bestPoint;
+}
+
+}
+}

Added: trunk/Source/WebKit/blackberry/WebKitSupport/ProximityDetector.h (0 => 145757)


--- trunk/Source/WebKit/blackberry/WebKitSupport/ProximityDetector.h	                        (rev 0)
+++ trunk/Source/WebKit/blackberry/WebKitSupport/ProximityDetector.h	2013-03-13 21:49:35 UTC (rev 145757)
@@ -0,0 +1,32 @@
+/*
+ * Copyright (C) 2012, 2013 Research In Motion Limited. All rights reserved.
+ */
+
+#ifndef ProximityDetector_h
+#define ProximityDetector_h
+
+namespace WebCore {
+class IntPoint;
+class IntRect;
+}
+
+namespace BlackBerry {
+namespace WebKit {
+
+class WebPagePrivate;
+
+class ProximityDetector {
+public:
+    ProximityDetector(WebPagePrivate* webpage);
+    ~ProximityDetector();
+
+    WebCore::IntPoint findBestPoint(const WebCore::IntPoint& documentPos, const WebCore::IntRect& documentPaddingRect);
+
+private:
+    WebPagePrivate* m_webPage;
+};
+
+}
+}
+
+#endif // ProximityDetector_h
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to