Commit f85a642c authored by commit-queue@webkit.org's avatar commit-queue@webkit.org
Browse files

[BlackBerry] Add Proximity Detector.

https://bugs.webkit.org/show_bug.cgi?id=112278

Patch by Genevieve Mak <gmak@rim.com> 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):

git-svn-id: http://svn.webkit.org/repository/webkit/trunk@145757 268f45cc-cd09-0410-ab3c-d52691b4dbfc
parent 854657f9
2013-03-13 Genevieve Mak <gmak@rim.com>
[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 <roger_fong@apple.com>
Build fix for AppleWin VS2010.
......
......@@ -135,6 +135,7 @@ list(APPEND WebKit_SOURCES
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
......
2013-03-13 Genevieve Mak <gmak@rim.com>
[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 <shuwu@blackberry.com>
 
[BlackBerry] Touch Hold selection does not scroll text area or other subframe until selection reaches bottom of the page.
......
/*
* 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;
}
}
}
/*
* 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
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment