corinthia-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From j...@apache.org
Subject [23/31] incubator-corinthia git commit: Cursor hit testing inside empty footnotes/endnotes
Date Mon, 23 Feb 2015 11:39:26 GMT
Cursor hit testing inside empty footnotes/endnotes

Position_atPoint mostly relies on document.caretRangeFromPoint for hit
testing, but this doesn't work for empty footnotes or endnotes, as there
is no actual text. Instead, caretRangeFromPoint returns the position
directly after the last letter before the note. So we do the same thing
as for images, which is checking if the adjacent image or empty note has
a bounding rect containing the specified point.


Project: http://git-wip-us.apache.org/repos/asf/incubator-corinthia/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-corinthia/commit/f3b4302f
Tree: http://git-wip-us.apache.org/repos/asf/incubator-corinthia/tree/f3b4302f
Diff: http://git-wip-us.apache.org/repos/asf/incubator-corinthia/diff/f3b4302f

Branch: refs/heads/experimentzip
Commit: f3b4302f63482db56147b329be4dbc8aefc5bffe
Parents: 334338e
Author: Peter Kelly <peter@uxproductivity.com>
Authored: Wed Feb 18 16:43:58 2015 +0700
Committer: Peter Kelly <peter@uxproductivity.com>
Committed: Wed Feb 18 16:44:51 2015 +0700

----------------------------------------------------------------------
 Editor/src/Position.js | 12 ++++++++++--
 Editor/src/types.js    |  5 +++++
 2 files changed, 15 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-corinthia/blob/f3b4302f/Editor/src/Position.js
----------------------------------------------------------------------
diff --git a/Editor/src/Position.js b/Editor/src/Position.js
index 0421367..aaf5cb6 100644
--- a/Editor/src/Position.js
+++ b/Editor/src/Position.js
@@ -968,15 +968,16 @@ var Position_atPoint;
             return null;
 
         var pos = new Position(range.startContainer,range.startOffset);
+        pos = Position_preferElementPosition(pos);
 
         if (pos.node.nodeType == Node.ELEMENT_NODE) {
             var prev = pos.node.childNodes[pos.offset-1];
             var next = pos.node.childNodes[pos.offset];
 
-            if ((prev != null) && (prev._type == HTML_IMG) && elementContainsPoint(prev,x,y))
+            if ((prev != null) && nodeMayContainPos(prev) && elementContainsPoint(prev,x,y))
                 return new Position(prev,0);
 
-            if ((next != null) && (next._type == HTML_IMG) && elementContainsPoint(next,x,y))
+            if ((next != null) && nodeMayContainPos(next) && elementContainsPoint(next,x,y))
                 return new Position(next,0);
         }
 
@@ -985,6 +986,13 @@ var Position_atPoint;
         return pos;
     }
 
+    // This is used for nodes that can potentially be the right match for a hit test, but
for
+    // which caretRangeFromPoint() returns the wrong result
+    function nodeMayContainPos(node)
+    {
+        return ((node._type == HTML_IMG) || isEmptyNoteNode(node));
+    }
+
     function elementContainsPoint(element,x,y)
     {
         var rect = element.getBoundingClientRect();

http://git-wip-us.apache.org/repos/asf/incubator-corinthia/blob/f3b4302f/Editor/src/types.js
----------------------------------------------------------------------
diff --git a/Editor/src/types.js b/Editor/src/types.js
index 392852f..473997d 100644
--- a/Editor/src/types.js
+++ b/Editor/src/types.js
@@ -175,6 +175,11 @@ function isNoteNode(node)
     return ((className == "footnote") || (className == "endnote"));
 }
 
+function isEmptyNoteNode(node)
+{
+    return isNoteNode(node) && !nodeHasContent(node);
+}
+
 function isItemNumber(node)
 {
     if (node.nodeType == Node.TEXT_NODE) {


Mime
View raw message