2012-02-19 Antonio Gomes <agomes@rim.com>
authortonikitoo@webkit.org <tonikitoo@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 24 Feb 2012 04:28:34 +0000 (04:28 +0000)
committertonikitoo@webkit.org <tonikitoo@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 24 Feb 2012 04:28:34 +0000 (04:28 +0000)
        Fat fingers - Add a clearer way to distinguish the node we want (shadow or non-shadow)
        https://bugs.webkit.org/show_bug.cgi?id=79256
        PR #127814 / MKS_2587410

        Reviewed by Rob Buis.

        Patch adds a cleaner way for call sites of FatFingersResult to
        query for the appropriated target node: shadow or non-shadow DOM nodes.

        It also renames FatFingersResults::validNode to ::node, assuming
        that "invalid" nodes are not applicable in any context.

        * Api/WebPage.cpp:
        (BlackBerry::WebKit::WebPagePrivate::clearDocumentData):
        (BlackBerry::WebKit::WebPagePrivate::contextNode):
        (BlackBerry::WebKit::WebPagePrivate::handleMouseEvent):
        * WebKitSupport/FatFingers.h:
        (FatFingersResult):
        (BlackBerry::WebKit::FatFingersResult::node):
        (BlackBerry::WebKit::FatFingersResult::nodeAsElementIfApplicable):
        * WebKitSupport/SelectionHandler.cpp:
        (BlackBerry::WebKit::SelectionHandler::selectAtPoint):
        * WebKitSupport/TouchEventHandler.cpp:
        (BlackBerry::WebKit::TouchEventHandler::touchHoldEvent):
        (BlackBerry::WebKit::TouchEventHandler::handleTouchPoint):

git-svn-id: http://svn.webkit.org/repository/webkit/trunk@108721 268f45cc-cd09-0410-ab3c-d52691b4dbfc

Source/WebKit/blackberry/Api/WebPage.cpp
Source/WebKit/blackberry/ChangeLog
Source/WebKit/blackberry/WebKitSupport/FatFingers.h
Source/WebKit/blackberry/WebKitSupport/SelectionHandler.cpp
Source/WebKit/blackberry/WebKitSupport/TouchEventHandler.cpp

index 490a88c..f3ce5f0 100644 (file)
@@ -2259,7 +2259,7 @@ PassRefPtr<Node> WebPagePrivate::contextNode(TargetDetectionStrategy strategy)
 
     // Check for text input.
     if (isTouching && lastFatFingersResult.isTextInput())
-        return lastFatFingersResult.node(ShadowContentNotAllowed);
+        return lastFatFingersResult.node(FatFingersResult::ShadowContentNotAllowed);
 
     IntPoint contentPos;
     if (isTouching)
@@ -2269,7 +2269,7 @@ PassRefPtr<Node> WebPagePrivate::contextNode(TargetDetectionStrategy strategy)
 
     if (strategy == RectBased) {
         FatFingersResult result = FatFingers(this, lastFatFingersResult.adjustedPosition(), FatFingers::Text).findBestPoint();
-        return result.node(ShadowContentNotAllowed);
+        return result.node(FatFingersResult::ShadowContentNotAllowed);
     }
 
     HitTestResult result = eventHandler->hitTestResultAtPoint(contentPos, false /*allowShadowContent*/);
@@ -3461,7 +3461,7 @@ bool WebPagePrivate::handleMouseEvent(PlatformMouseEvent& mouseEvent)
         const FatFingersResult lastFatFingersResult = m_touchEventHandler->lastFatFingersResult();
 
         // Fat fingers can deal with shadow content.
-        node = lastFatFingersResult.node(ShadowContentNotAllowed);
+        node = lastFatFingersResult.node(FatFingersResult::ShadowContentNotAllowed);
     }
 
     if (!node) {
index 00891b2..9af0693 100644 (file)
@@ -1,3 +1,31 @@
+2012-02-19  Antonio Gomes  <agomes@rim.com>
+
+        Fat fingers - Add a clearer way to distinguish the node we want (shadow or non-shadow)
+        https://bugs.webkit.org/show_bug.cgi?id=79256
+        PR #127814 / MKS_2587410
+
+        Reviewed by Rob Buis.
+
+        Patch adds a cleaner way for call sites of FatFingersResult to
+        query for the appropriated target node: shadow or non-shadow DOM nodes.
+
+        It also renames FatFingersResults::validNode to ::node, assuming
+        that "invalid" nodes are not applicable in any context.
+
+        * Api/WebPage.cpp:
+        (BlackBerry::WebKit::WebPagePrivate::clearDocumentData):
+        (BlackBerry::WebKit::WebPagePrivate::contextNode):
+        (BlackBerry::WebKit::WebPagePrivate::handleMouseEvent):
+        * WebKitSupport/FatFingers.h:
+        (FatFingersResult):
+        (BlackBerry::WebKit::FatFingersResult::node):
+        (BlackBerry::WebKit::FatFingersResult::nodeAsElementIfApplicable):
+        * WebKitSupport/SelectionHandler.cpp:
+        (BlackBerry::WebKit::SelectionHandler::selectAtPoint):
+        * WebKitSupport/TouchEventHandler.cpp:
+        (BlackBerry::WebKit::TouchEventHandler::touchHoldEvent):
+        (BlackBerry::WebKit::TouchEventHandler::handleTouchPoint):
+
 2012-02-23  Jacky Jiang  <zhajiang@rim.com>
 
         [BlackBerry] Upstream BlackBerry API web page related files
index 6b847e1..cb31f97 100644 (file)
@@ -50,6 +50,7 @@ class TouchEventHandler;
 
 class FatFingersResult {
 public:
+
     FatFingersResult(const WebCore::IntPoint& p = WebCore::IntPoint::zero())
         : m_originalPosition(p)
         , m_adjustedPosition(p)
@@ -74,10 +75,33 @@ public:
     bool positionWasAdjusted() const { return m_isValid && m_positionWasAdjusted; }
     bool isTextInput() const { return m_isValid && !!m_nodeUnderFatFinger && m_isTextInput; }
     bool isValid() const { return m_isValid; }
-    WebCore::Node* validNode() const { return m_nodeUnderFatFinger && m_nodeUnderFatFinger->inDocument() ? m_nodeUnderFatFinger.get() : 0; }
-    WebCore::Element* nodeAsElementIfApplicable() const
+
+    enum ContentType { ShadowContentAllowed, ShadowContentNotAllowed };
+
+    WebCore::Node* node(ContentType type = ShadowContentAllowed) const
     {
-        return static_cast<WebCore::Element*>(m_nodeUnderFatFinger && m_nodeUnderFatFinger->inDocument() && m_nodeUnderFatFinger->isElementNode() ? m_nodeUnderFatFinger.get() : 0);
+        if (!m_nodeUnderFatFinger || !m_nodeUnderFatFinger->inDocument())
+            return 0;
+
+        WebCore::Node* result = m_nodeUnderFatFinger.get();
+
+        if (type == ShadowContentAllowed)
+            return result;
+
+        // Shadow trees can be nested.
+        while (result->isInShadowTree())
+            result = toElement(result->shadowAncestorNode());
+
+        return result;
+    }
+
+    WebCore::Element* nodeAsElementIfApplicable(ContentType type = ShadowContentAllowed) const
+    {
+        WebCore::Node* result = node(type);
+        if (!result || !result->isElementNode())
+            return 0;
+
+        return static_cast<WebCore::Element*>(result);
     }
 
 private:
index 5577692..91b9350 100644 (file)
@@ -539,7 +539,7 @@ void SelectionHandler::selectAtPoint(const IntPoint& location)
     // FIXME: Factory this get right fat finger code into a helper.
     const FatFingersResult lastFatFingersResult = m_webPage->m_touchEventHandler->lastFatFingersResult();
     if (lastFatFingersResult.positionWasAdjusted() && lastFatFingersResult.nodeAsElementIfApplicable()) {
-        targetNode = lastFatFingersResult.validNode();
+        targetNode = lastFatFingersResult.node(FatFingersResult::ShadowContentNotAllowed);
         targetPosition = lastFatFingersResult.adjustedPosition();
     } else {
         FatFingersResult newFatFingersResult = FatFingers(m_webPage, location, FatFingers::Text).findBestPoint();
@@ -547,7 +547,7 @@ void SelectionHandler::selectAtPoint(const IntPoint& location)
             return;
 
         targetPosition = newFatFingersResult.adjustedPosition();
-        targetNode = newFatFingersResult.validNode();
+        targetNode = newFatFingersResult.node(FatFingersResult::ShadowContentNotAllowed);
     }
 
     ASSERT(targetNode);
index 50ad9d4..cfe559a 100644 (file)
@@ -168,7 +168,7 @@ void TouchEventHandler::touchHoldEvent()
         handleFatFingerPressed();
 
     // Clear the focus ring indication if tap-and-hold'ing on a link.
-    if (m_lastFatFingersResult.validNode() && m_lastFatFingersResult.validNode()->isLink())
+    if (m_lastFatFingersResult.node() && m_lastFatFingersResult.node()->isLink())
         m_webPage->clearFocusNode();
 }
 
@@ -186,13 +186,13 @@ bool TouchEventHandler::handleTouchPoint(Platform::TouchPoint& point)
             m_lastFatFingersResult = FatFingers(m_webPage, contentPos, FatFingers::ClickableElement).findBestPoint();
 
             Element* elementUnderFatFinger = 0;
-            if (m_lastFatFingersResult.positionWasAdjusted() && m_lastFatFingersResult.validNode()) {
-                ASSERT(m_lastFatFingersResult.validNode()->isElementNode());
+            if (m_lastFatFingersResult.positionWasAdjusted() && m_lastFatFingersResult.node()) {
+                ASSERT(m_lastFatFingersResult.node()->isElementNode());
                 elementUnderFatFinger = m_lastFatFingersResult.nodeAsElementIfApplicable();
             }
 
             // Set or reset the touch mode.
-            Element* possibleTargetNodeForMouseMoveEvents = static_cast<Element*>(m_lastFatFingersResult.positionWasAdjusted() ? elementUnderFatFinger : m_lastFatFingersResult.validNode());
+            Element* possibleTargetNodeForMouseMoveEvents = static_cast<Element*>(m_lastFatFingersResult.positionWasAdjusted() ? elementUnderFatFinger : m_lastFatFingersResult.node());
             m_convertTouchToMouse = shouldConvertTouchToMouse(possibleTargetNodeForMouseMoveEvents);
 
             if (elementUnderFatFinger)