[evolution/wip/mcrha/webkit-jsc-api] Replace Selection::base/extent usage with Selection::anchor/focus members



commit 7ef10b1f9d76ef368b6aac36a145e0f17c9ecce7
Author: Milan Crha <mcrha redhat com>
Date:   Tue Feb 18 15:25:44 2020 +0100

    Replace Selection::base/extent usage with Selection::anchor/focus members
    
    The Selection::baseNode/baseOffset/extentNode/extentOffset are not
    part of the standard [1] and they do not update the same as the standard
    properties (like after double-click, which selects a word).
    
    [1] https://w3c.github.io/selection-api/#selection-interface

 data/webkit/e-editor.js    | 148 ++++++++++++++++++++--------------------
 data/webkit/e-selection.js | 164 ++++++++++++++++++++++-----------------------
 data/webkit/e-undo-redo.js |  36 +++++-----
 3 files changed, 174 insertions(+), 174 deletions(-)
---
diff --git a/data/webkit/e-editor.js b/data/webkit/e-editor.js
index 0873c8bb59..c4ef7ca158 100644
--- a/data/webkit/e-editor.js
+++ b/data/webkit/e-editor.js
@@ -101,7 +101,7 @@ var EvoEditor = {
        forceFormatStateUpdate : false,
        formattingState : {
                mode : -1,
-               baseElement : null, // to avoid often notifications when just moving within the same node
+               anchorElement : null, // to avoid often notifications when just moving within the same node
                bold : false,
                italic : false,
                underline : false,
@@ -124,39 +124,39 @@ var EvoEditor = {
 
 EvoEditor.maybeUpdateFormattingState = function(force)
 {
-       var baseElem = null;
+       var anchorElem = null;
 
        if (!document.getSelection().isCollapsed) {
                var commonParent;
 
-               commonParent = EvoEditor.GetCommonParent(document.getSelection().baseNode, 
document.getSelection().extentNode, true);
+               commonParent = EvoEditor.GetCommonParent(document.getSelection().anchorNode, 
document.getSelection().focusNode, true);
                if (commonParent) {
                        var child1, child2;
 
-                       child1 = EvoEditor.GetDirectChild(commonParent, document.getSelection().baseNode);
-                       child2 = EvoEditor.GetDirectChild(commonParent, document.getSelection().extentNode);
+                       child1 = EvoEditor.GetDirectChild(commonParent, document.getSelection().anchorNode);
+                       child2 = EvoEditor.GetDirectChild(commonParent, document.getSelection().focusNode);
 
                        if (child1 && (!child2 || (child2 && EvoEditor.GetChildIndex(commonParent, child1) <= 
EvoEditor.GetChildIndex(commonParent, child2)))) {
-                               baseElem = document.getSelection().extentNode;
+                               anchorElem = document.getSelection().focusNode;
                        }
                }
        }
 
-       if (!baseElem)
-               baseElem = document.getSelection().baseNode;
-       if (!baseElem)
-               baseElem = document.body ? document.body.firstElementChild : null;
+       if (!anchorElem)
+               anchorElem = document.getSelection().anchorNode;
+       if (!anchorElem)
+               anchorElem = document.body ? document.body.firstElementChild : null;
 
-       if (baseElem && baseElem.nodeType == baseElem.TEXT_NODE)
-               baseElem = baseElem.parentElement;
+       if (anchorElem && anchorElem.nodeType == anchorElem.TEXT_NODE)
+               anchorElem = anchorElem.parentElement;
 
-       if (force == EvoEditor.FORCE_NO && EvoEditor.formattingState.baseElement === baseElem && 
EvoEditor.mode == EvoEditor.formattingState.mode) {
+       if (force == EvoEditor.FORCE_NO && EvoEditor.formattingState.anchorElement === anchorElem && 
EvoEditor.mode == EvoEditor.formattingState.mode) {
                return;
        }
 
        force = force == EvoEditor.FORCE_YES;
 
-       EvoEditor.formattingState.baseElement = baseElem;
+       EvoEditor.formattingState.anchorElement = anchorElem;
 
        var changes = {}, nchanges = 0, value, tmp, computedStyle;
 
@@ -167,7 +167,7 @@ EvoEditor.maybeUpdateFormattingState = function(force)
                nchanges++;
        }
 
-       computedStyle = baseElem ? window.getComputedStyle(baseElem) : null;
+       computedStyle = anchorElem ? window.getComputedStyle(anchorElem) : null;
 
        value = (computedStyle ? computedStyle.fontWeight : "") == "bold";
        if (value != EvoEditor.formattingState.bold) {
@@ -187,7 +187,7 @@ EvoEditor.maybeUpdateFormattingState = function(force)
 
        tmp = computedStyle ? computedStyle.webkitTextDecorationsInEffect : "";
 
-       value = tmp.search("underline") >= 0 && (!baseElem || baseElem.tagName != "A");
+       value = tmp.search("underline") >= 0 && (!anchorElem || anchorElem.tagName != "A");
        if (force || value != EvoEditor.formattingState.underline) {
                EvoEditor.formattingState.underline = value;
                changes["underline"] = value;
@@ -281,7 +281,7 @@ EvoEditor.maybeUpdateFormattingState = function(force)
                bgColor : null
        };
 
-       for (parent = baseElem; parent && !(parent === document.body); parent = parent.parentElement) {
+       for (parent = anchorElem; parent && !(parent === document.body); parent = parent.parentElement) {
                if (obj.script == 0) {
                        if (parent.tagName == "SUB")
                                obj.script = -1;
@@ -579,8 +579,8 @@ EvoEditor.ClaimAffectedContent = function(startNode, endNode, flags)
        var currentElemsArray = null;
 
        if (!startNode) {
-               startNode = document.getSelection().baseNode;
-               endNode = document.getSelection().extentNode;
+               startNode = document.getSelection().anchorNode;
+               endNode = document.getSelection().focusNode;
 
                if (!startNode) {
                        startNode = document.body;
@@ -588,7 +588,7 @@ EvoEditor.ClaimAffectedContent = function(startNode, endNode, flags)
        }
 
        if (!endNode) {
-               endNode = document.getSelection().extentNode;
+               endNode = document.getSelection().focusNode;
 
                if (!endNode)
                        endNode = startNode;
@@ -1627,16 +1627,16 @@ EvoEditor.beforeInputCb = function(inputEvent)
        // when writing at the end of the anchor, then write into the anchor, not out (WebKit writes out)
        if (!selection ||
            !selection.isCollapsed ||
-           !selection.baseNode ||
-           selection.baseNode.nodeType != selection.baseNode.TEXT_NODE ||
-           selection.baseOffset != selection.baseNode.nodeValue.length ||
-           !selection.baseNode.parentElement ||
-           selection.baseNode.parentElement.tagName != "A")
+           !selection.anchorNode ||
+           selection.anchorNode.nodeType != selection.anchorNode.TEXT_NODE ||
+           selection.anchorOffset != selection.anchorNode.nodeValue.length ||
+           !selection.anchorNode.parentElement ||
+           selection.anchorNode.parentElement.tagName != "A")
                return;
 
-       var node = selection.baseNode;
+       var node = selection.anchorNode;
 
-       EvoUndoRedo.StartRecord(EvoUndoRedo.RECORD_KIND_EVENT, "insertText", selection.baseNode, 
selection.baseNode,
+       EvoUndoRedo.StartRecord(EvoUndoRedo.RECORD_KIND_EVENT, "insertText", selection.anchorNode, 
selection.anchorNode,
                EvoEditor.CLAIM_CONTENT_FLAG_SAVE_HTML | EvoEditor.CLAIM_CONTENT_FLAG_USE_PARENT_BLOCK_NODE);
 
        try {
@@ -1683,7 +1683,7 @@ EvoEditor.initializeContent = function()
                }
 
                // make sure there is a selection
-               if (!document.getSelection().baseNode) {
+               if (!document.getSelection().anchorNode) {
                        document.getSelection().setPosition(document.body.firstChild ? 
document.body.firstChild : document.body, 0);
                }
        }
@@ -2386,7 +2386,7 @@ EvoEditor.AfterInputEvent = function(inputEvent, isWordDelim)
        var isInsertParagraph = inputEvent.inputType == "insertParagraph";
        var selection = document.getSelection();
 
-       if (isInsertParagraph && selection.isCollapsed && selection.baseNode && selection.baseNode.tagName == 
"BODY") {
+       if (isInsertParagraph && selection.isCollapsed && selection.anchorNode && 
selection.anchorNode.tagName == "BODY") {
                document.execCommand("insertHTML", false, EvoEditor.emptyParagraphAsHtml());
                EvoUndoRedo.GroupTopRecords(2, "insertParagraph::withFormat");
                return;
@@ -2399,13 +2399,13 @@ EvoEditor.AfterInputEvent = function(inputEvent, isWordDelim)
                return;
        }
 
-       if (isInsertParagraph && selection.isCollapsed && selection.baseNode && selection.baseNode.tagName == 
"DIV") {
+       if (isInsertParagraph && selection.isCollapsed && selection.anchorNode && 
selection.anchorNode.tagName == "DIV") {
                // for example when moving away from ul/ol, the newly created
                // paragraph can inherit styles from it, which is also negative text-indent
-               selection.baseNode.removeAttribute("style");
+               selection.anchorNode.removeAttribute("style");
 
                if (EvoEditor.mode == EvoEditor.MODE_PLAIN_TEXT) {
-                       var node = selection.baseNode, citeLevel = 0;
+                       var node = selection.anchorNode, citeLevel = 0;
 
                        while (node && node.tagName != "BODY") {
                                if (node.tagName == "BLOCKQUOTE")
@@ -2415,7 +2415,7 @@ EvoEditor.AfterInputEvent = function(inputEvent, isWordDelim)
                        }
 
                        if (citeLevel * 2 < EvoEditor.NORMAL_PARAGRAPH_WIDTH) {
-                               selection.baseNode.style.width = (EvoEditor.NORMAL_PARAGRAPH_WIDTH - 
citeLevel * 2) + "ch";
+                               selection.anchorNode.style.width = (EvoEditor.NORMAL_PARAGRAPH_WIDTH - 
citeLevel * 2) + "ch";
                        }
                }
        }
@@ -2426,18 +2426,18 @@ EvoEditor.AfterInputEvent = function(inputEvent, isWordDelim)
                return;
        }
 
-       if (!selection.isCollapsed || !selection.baseNode)
+       if (!selection.isCollapsed || !selection.anchorNode)
                return;
 
-       var baseNode = selection.baseNode, parentElem;
+       var anchorNode = selection.anchorNode, parentElem;
 
-       if (baseNode.nodeType != baseNode.ELEMENT_NODE) {
-               parentElem = baseNode.parentElement;
+       if (anchorNode.nodeType != anchorNode.ELEMENT_NODE) {
+               parentElem = anchorNode.parentElement;
 
                if (!parentElem)
                        return;
        } else {
-               parentElem = baseNode;
+               parentElem = anchorNode;
        }
 
        if (isInsertParagraph) {
@@ -2446,13 +2446,13 @@ EvoEditor.AfterInputEvent = function(inputEvent, isWordDelim)
                if (!parentElem)
                        return;
 
-               baseNode = parentElem.lastChild;
+               anchorNode = parentElem.lastChild;
 
-               if (!baseNode || baseNode.nodeType != baseNode.TEXT_NODE)
+               if (!anchorNode || anchorNode.nodeType != anchorNode.TEXT_NODE)
                        return;
        }
 
-       if (!baseNode.nodeValue)
+       if (!anchorNode.nodeValue)
                return;
 
        var canLinks;
@@ -2462,7 +2462,7 @@ EvoEditor.AfterInputEvent = function(inputEvent, isWordDelim)
        if (canLinks) {
                var tmpNode;
 
-               for (tmpNode = baseNode; tmpNode && tmpNode.tagName != "BODY"; tmpNode = 
tmpNode.parentElement) {
+               for (tmpNode = anchorNode; tmpNode && tmpNode.tagName != "BODY"; tmpNode = 
tmpNode.parentElement) {
                        if (tmpNode.tagName == "A") {
                                canLinks = false;
                                break;
@@ -2470,29 +2470,29 @@ EvoEditor.AfterInputEvent = function(inputEvent, isWordDelim)
                }
        }
 
-       var text = baseNode.nodeValue, covered = false;
+       var text = anchorNode.nodeValue, covered = false;
 
        var replaceMatchWithNode = function(opType, match, newNode, canEmit) {
-               EvoUndoRedo.StartRecord(EvoUndoRedo.RECORD_KIND_CUSTOM, opType, baseNode.parentElement, 
baseNode.parentElement,
+               EvoUndoRedo.StartRecord(EvoUndoRedo.RECORD_KIND_CUSTOM, opType, anchorNode.parentElement, 
anchorNode.parentElement,
                        EvoEditor.CLAIM_CONTENT_FLAG_SAVE_HTML);
 
                try {
-                       var offset = selection.baseOffset, updateSelection = selection.baseNode === baseNode, 
newBaseNode;
+                       var offset = selection.anchorOffset, updateSelection = selection.anchorNode === 
anchorNode, newAnchorNode;
 
-                       baseNode.splitText(match.end);
-                       newBaseNode = baseNode.nextSibling;
-                       baseNode.splitText(match.start);
+                       anchorNode.splitText(match.end);
+                       newAnchorNode = anchorNode.nextSibling;
+                       anchorNode.splitText(match.start);
 
-                       baseNode = baseNode.nextSibling;
+                       anchorNode = anchorNode.nextSibling;
 
-                       baseNode.parentElement.insertBefore(newNode, baseNode);
+                       anchorNode.parentElement.insertBefore(newNode, anchorNode);
                        if (newNode.tagName == "A")
-                               newNode.appendChild(baseNode);
+                               newNode.appendChild(anchorNode);
                        else
-                               baseNode.parentElement.removeChild(baseNode);
+                               anchorNode.parentElement.removeChild(anchorNode);
 
-                       if (updateSelection && newBaseNode && offset - match.end >= 0)
-                               selection.setPosition(newBaseNode, offset - match.end);
+                       if (updateSelection && newAnchorNode && offset - match.end >= 0)
+                               selection.setPosition(newAnchorNode, offset - match.end);
                } finally {
                        EvoUndoRedo.StopRecord(EvoUndoRedo.RECORD_KIND_CUSTOM, opType);
 
@@ -2620,10 +2620,10 @@ EvoEditor.getParentElement = function(tagName, fromNode, canClimbUp)
        var node = fromNode;
 
        if (!node)
-               node = document.getSelection().extentNode;
+               node = document.getSelection().focusNode;
 
        if (!node)
-               node = document.getSelection().baseNode;
+               node = document.getSelection().anchorNode;
 
        while (node && node.nodeType != node.ELEMENT_NODE) {
                node = node.parentElement;
@@ -3946,7 +3946,7 @@ EvoEditor.InsertSignature = function(content, isHTML, uid, fromMessage, checkCha
                                document.getSelection().setPosition(document.body.firstChild, 0);
                        }
 
-                       node = document.getSelection().baseNode;
+                       node = document.getSelection().anchorNode;
 
                        if (node) {
                                if (node.nodeType != node.ELEMENT_NODE)
@@ -4013,7 +4013,7 @@ EvoEditor.InsertContent = function(text, isHTML, quote)
                }
 
                if (quote) {
-                       var baseNode = document.getSelection().baseNode, intoBody = false;
+                       var anchorNode = document.getSelection().anchorNode, intoBody = false;
 
                        if (!content.firstElementChild || (content.firstElementChild.tagName != "DIV" && 
content.firstElementChild.tagName != "P" &&
                            content.firstElementChild.tagName != "PRE")) {
@@ -4027,13 +4027,13 @@ EvoEditor.InsertContent = function(text, isHTML, quote)
                                content.appendChild(node);
                        }
 
-                       if (baseNode) {
+                       if (anchorNode) {
                                var node, parentBlock = null;
 
-                               if (baseNode.nodeType == baseNode.ELEMENT_NODE) {
-                                       node = baseNode;
+                               if (anchorNode.nodeType == anchorNode.ELEMENT_NODE) {
+                                       node = anchorNode;
                                } else {
-                                       node = baseNode.parentElement;
+                                       node = anchorNode.parentElement;
                                }
 
                                while (node && node.tagName != "BODY" && !EvoEditor.IsBlockNode(node)) {
@@ -4057,13 +4057,13 @@ EvoEditor.InsertContent = function(text, isHTML, quote)
                                        try {
                                                if (willSplit) {
                                                        // need to split the content up to the parent block 
node
-                                                       if (baseNode.nodeType == baseNode.TEXT_NODE) {
-                                                               
baseNode.splitText(document.getSelection().baseOffset);
+                                                       if (anchorNode.nodeType == anchorNode.TEXT_NODE) {
+                                                               
anchorNode.splitText(document.getSelection().anchorOffset);
                                                        }
 
-                                                       var from = baseNode.nextSibling, parent, nextFrom = 
null;
+                                                       var from = anchorNode.nextSibling, parent, nextFrom = 
null;
 
-                                                       parent = from ? from.parentElement : 
baseNode.parentElement;
+                                                       parent = from ? from.parentElement : 
anchorNode.parentElement;
 
                                                        if (!from && parent) {
                                                                from = parent.nextElementSibling;
@@ -4107,10 +4107,10 @@ EvoEditor.InsertContent = function(text, isHTML, quote)
                                                else
                                                        document.getSelection().setPosition(content, 0);
 
-                                               if (baseNode.nodeType == baseNode.ELEMENT_NODE && 
baseNode.parentElement &&
-                                                   (baseNode.tagName == "DIV" || baseNode.tagName == "P" || 
baseNode.tagName == "PRE") &&
-                                                   (!baseNode.children.length || (baseNode.children.length 
== 1 && baseNode.children[0].tagName == "BR"))) {
-                                                       baseNode.parentElement.removeChild(baseNode);
+                                               if (anchorNode.nodeType == anchorNode.ELEMENT_NODE && 
anchorNode.parentElement &&
+                                                   (anchorNode.tagName == "DIV" || anchorNode.tagName == "P" 
|| anchorNode.tagName == "PRE") &&
+                                                   (!anchorNode.children.length || 
(anchorNode.children.length == 1 && anchorNode.children[0].tagName == "BR"))) {
+                                                       anchorNode.parentElement.removeChild(anchorNode);
                                                }
                                        } finally {
                                                EvoUndoRedo.StopRecord(EvoUndoRedo.RECORD_KIND_CUSTOM, 
"InsertContent::text");
@@ -4353,8 +4353,8 @@ EvoEditor.WrapSelection = function()
 {
        var nodeFrom, nodeTo;
 
-       nodeFrom = EvoEditor.GetParentBlockNode(document.getSelection().baseNode);
-       nodeTo = EvoEditor.GetParentBlockNode(document.getSelection().extentNode);
+       nodeFrom = EvoEditor.GetParentBlockNode(document.getSelection().anchorNode);
+       nodeTo = EvoEditor.GetParentBlockNode(document.getSelection().focusNode);
 
        if (!nodeFrom || !nodeTo) {
                return;
@@ -4460,9 +4460,9 @@ EvoEditor.onContextMenu = function(event)
        var node = event.target;
 
        if (!node)
-               node = document.getSelection().extentNode;
+               node = document.getSelection().focusNode;
        if (!node)
-               node = document.getSelection().baseNode;
+               node = document.getSelection().anchorNode;
 
        EvoEditor.contextMenuNode = node;
 
diff --git a/data/webkit/e-selection.js b/data/webkit/e-selection.js
index 12e1ce30f5..76a0d9fd7b 100644
--- a/data/webkit/e-selection.js
+++ b/data/webkit/e-selection.js
@@ -128,19 +128,19 @@ EvoSelection.Store = function(doc)
 
        var selection = {}, sel = doc.getSelection();
 
-       selection.baseElem = sel.baseNode ? EvoSelection.GetChildPath(doc.body, sel.baseNode) : [];
-       selection.baseOffset = sel.baseOffset + EvoSelection.GetOverallTextOffset(sel.baseNode);
+       selection.anchorElem = sel.anchorNode ? EvoSelection.GetChildPath(doc.body, sel.anchorNode) : [];
+       selection.anchorOffset = sel.anchorOffset + EvoSelection.GetOverallTextOffset(sel.anchorNode);
 
-       if (sel.baseNode && sel.baseNode.nodeType == sel.baseNode.ELEMENT_NODE) {
-               selection.baseIsElement = true;
+       if (sel.anchorNode && sel.anchorNode.nodeType == sel.anchorNode.ELEMENT_NODE) {
+               selection.anchorIsElement = true;
        }
 
        if (!sel.isCollapsed) {
-               selection.extentElem = EvoSelection.GetChildPath(doc.body, sel.extentNode);
-               selection.extentOffset = sel.extentOffset + EvoSelection.GetOverallTextOffset(sel.extentNode);
+               selection.focusElem = EvoSelection.GetChildPath(doc.body, sel.focusNode);
+               selection.focusOffset = sel.focusOffset + EvoSelection.GetOverallTextOffset(sel.focusNode);
 
-               if (sel.extentNode && sel.extentNode.nodeType == sel.extentNode.ELEMENT_NODE) {
-                       selection.extentIsElement = true;
+               if (sel.focusNode && sel.focusNode.nodeType == sel.focusNode.ELEMENT_NODE) {
+                       selection.focusIsElement = true;
                }
        }
 
@@ -155,38 +155,38 @@ EvoSelection.Restore = function(doc, selection)
                return;
        }
 
-       var base_node, base_offset, extent_node, extent_offset;
+       var anchorNode, anchorOffset, focusNode, focusOffset;
 
-       base_node = EvoSelection.FindElementByPath(doc.body, selection.baseElem);
-       base_offset = selection.baseOffset;
+       anchorNode = EvoSelection.FindElementByPath(doc.body, selection.anchorElem);
+       anchorOffset = selection.anchorOffset;
 
-       if (!base_node) {
+       if (!anchorNode) {
                return;
        }
 
-       if (!base_offset) {
-               base_offset = 0;
+       if (!anchorOffset) {
+               anchorOffset = 0;
        }
 
-       if (!selection.baseIsElement) {
-               base_node = EvoSelection.GetTextOffsetNode(base_node, base_offset);
-               base_offset -= EvoSelection.GetOverallTextOffset(base_node);
+       if (!selection.anchorIsElement) {
+               anchorNode = EvoSelection.GetTextOffsetNode(anchorNode, anchorOffset);
+               anchorOffset -= EvoSelection.GetOverallTextOffset(anchorNode);
        }
 
-       extent_node = EvoSelection.FindElementByPath(doc.body, selection.extentElem);
-       extent_offset = selection.extentOffset;
+       focusNode = EvoSelection.FindElementByPath(doc.body, selection.focusElem);
+       focusOffset = selection.focusOffset;
 
-       if (extent_node) {
-               if (!selection.extentIsElement) {
-                       extent_node = EvoSelection.GetTextOffsetNode(extent_node, extent_offset);
-                       extent_offset -= EvoSelection.GetOverallTextOffset(extent_node);
+       if (focusNode) {
+               if (!selection.focusIsElement) {
+                       focusNode = EvoSelection.GetTextOffsetNode(focusNode, focusOffset);
+                       focusOffset -= EvoSelection.GetOverallTextOffset(focusNode);
                }
        }
 
-       if (extent_node)
-               doc.getSelection().setBaseAndExtent(base_node, base_offset, extent_node, extent_offset);
+       if (focusNode)
+               doc.getSelection().setBaseAndExtent(anchorNode, anchorOffset, focusNode, focusOffset);
        else
-               doc.getSelection().setPosition(base_node, base_offset);
+               doc.getSelection().setPosition(anchorNode, anchorOffset);
 }
 
 /* Encodes selection information to a string */
@@ -215,26 +215,26 @@ EvoSelection.ToString = function(selection)
                }
        };
 
-       var str = "", base_elem, base_offset, extent_elem, extent_offset;
+       var str = "", anchorElem, anchorOffset, focusElem, focusOffset;
 
-       base_elem = selection.baseElem;
-       base_offset = selection.baseOffset;
-       extent_elem = selection.extentElem;
-       extent_offset = selection.extentOffset;
+       anchorElem = selection.anchorElem;
+       anchorOffset = selection.anchorOffset;
+       focusElem = selection.focusElem;
+       focusOffset = selection.focusOffset;
 
-       str += "baseElem=" + utils.arrayToString(base_elem);
-       str += " baseOffset=" + (base_offset ? base_offset : 0);
+       str += "anchorElem=" + utils.arrayToString(anchorElem);
+       str += " anchorOffset=" + (anchorOffset ? anchorOffset : 0);
 
-       if (selection.baseIsElement) {
-               str += " baseIsElement=1";
+       if (selection.anchorIsElement) {
+               str += " anchorIsElement=1";
        }
 
-       if (extent_elem) {
-               str += " extentElem=" + utils.arrayToString(extent_elem);
-               str += " extentOffset=" + (extent_offset ? extent_offset : 0);
+       if (focusElem) {
+               str += " focusElem=" + utils.arrayToString(focusElem);
+               str += " focusOffset=" + (focusOffset ? focusOffset : 0);
 
-               if (selection.extentIsElement) {
-                       str += " extentIsElement=1";
+               if (selection.focusIsElement) {
+                       str += " focusIsElement=1";
                }
        }
 
@@ -289,13 +289,13 @@ EvoSelection.FromString = function(str)
        for (ii = 0; ii < split_str.length; ii++) {
                var name;
 
-               name = "baseElem";
+               name = "anchorElem";
                if (split_str[ii].startsWith(name + "=")) {
                        selection[name] = utils.arrayFromString(split_str[ii].slice(name.length + 1));
                        continue;
                }
 
-               name = "baseOffset";
+               name = "anchorOffset";
                if (split_str[ii].startsWith(name + "=")) {
                        var value;
 
@@ -306,7 +306,7 @@ EvoSelection.FromString = function(str)
                        continue;
                }
 
-               name = "baseIsElement";
+               name = "anchorIsElement";
                if (split_str[ii].startsWith(name + "=")) {
                        var value;
 
@@ -317,13 +317,13 @@ EvoSelection.FromString = function(str)
                        continue;
                }
 
-               name = "extentElem";
+               name = "focusElem";
                if (split_str[ii].startsWith(name + "=")) {
                        selection[name] = utils.arrayFromString(split_str[ii].slice(name.length + 1));
                        continue;
                }
 
-               name = "extentOffset";
+               name = "focusOffset";
                if (split_str[ii].startsWith(name + "=")) {
                        var value;
 
@@ -333,7 +333,7 @@ EvoSelection.FromString = function(str)
                        }
                }
 
-               name = "extentIsElement";
+               name = "focusIsElement";
                if (split_str[ii].startsWith(name + "=")) {
                        var value;
 
@@ -345,8 +345,8 @@ EvoSelection.FromString = function(str)
                }
        }
 
-       /* The "baseElem" is required, the rest is optional */
-       if (!selection.baseElem)
+       /* The "anchorElem" is required, the rest is optional */
+       if (!selection.anchorElem)
                return null;
 
        return selection;
@@ -364,55 +364,55 @@ EvoSelection.CreateUpdaterObject = function()
 {
        var obj = {
                selectionBefore : null,
-               selectionBaseNode : null,
-               selectionBaseOffset : -1,
-               selectionExtentNode : null,
-               selectionExtentOffset : -1,
-               changeBase : false,
-               changeExtent : false,
+               selectionAnchorNode : null,
+               selectionAnchorOffset : -1,
+               selectionFocusNode : null,
+               selectionFocusOffset : -1,
+               changeAnchor : false,
+               changeFocus : false,
 
                beforeRemove : function(node) {
-                       this.changeBase = false;
-                       this.changeExtent = false;
+                       this.changeAnchor = false;
+                       this.changeFocus = false;
 
-                       if (this.selectionBaseNode) {
-                               this.changeBase = node === this.selectionBaseNode ||
-                                       (this.selectionBaseNode.noteType == this.selectionBaseNode.TEXT_NODE 
&&
-                                        this.selectionBaseNode.parentElement === node);
+                       if (this.selectionAnchorNode) {
+                               this.changeAnchor = node === this.selectionAnchorNode ||
+                                       (this.selectionAnchorNode.noteType == 
this.selectionAnchorNode.TEXT_NODE &&
+                                        this.selectionAnchorNode.parentElement === node);
                        }
 
-                       if (this.selectionExtentNode) {
-                               this.changeExtent = node === this.selectionExtentNode ||
-                                       (this.selectionExtentNode.noteType == 
this.selectionExtentNode.TEXT_NODE &&
-                                        this.selectionExtentNode.parentElement === node);
+                       if (this.selectionFocusNode) {
+                               this.changeFocus = node === this.selectionFocusNode ||
+                                       (this.selectionFocusNode.noteType == 
this.selectionFocusNode.TEXT_NODE &&
+                                        this.selectionFocusNode.parentElement === node);
                        }
                },
 
                afterRemove : function(newNode) {
-                       if (this.changeBase) {
-                               this.selectionBaseNode = newNode;
-                               this.selectionBaseOffset += EvoSelection.GetOverallTextOffset(newNode);
+                       if (this.changeAnchor) {
+                               this.selectionAnchorNode = newNode;
+                               this.selectionAnchorOffset += EvoSelection.GetOverallTextOffset(newNode);
                        }
 
-                       if (this.changeExtent) {
-                               this.selectionExtentNode = newNode;
-                               this.selectionExtentOffset += EvoSelection.GetOverallTextOffset(newNode);
+                       if (this.changeFocus) {
+                               this.selectionFocusNode = newNode;
+                               this.selectionFocusOffset += EvoSelection.GetOverallTextOffset(newNode);
                        }
 
-                       this.changeBase = false;
-                       this.changeExtent = false;
+                       this.changeAnchor = false;
+                       this.changeFocus = false;
                },
 
                restore : function() {
-                       if (this.selectionBaseNode && this.selectionBaseNode.parentElement) {
+                       if (this.selectionAnchorNode && this.selectionAnchorNode.parentElement) {
                                var selection = {
-                                       baseElem : EvoSelection.GetChildPath(document.body, 
this.selectionBaseNode),
-                                       baseOffset : this.selectionBaseOffset
+                                       anchorElem : EvoSelection.GetChildPath(document.body, 
this.selectionAnchorNode),
+                                       anchorOffset : this.selectionAnchorOffset
                                };
 
-                               if (this.selectionExtentNode) {
-                                       selection.extentElem = EvoSelection.GetChildPath(document.body, 
this.selectionExtentNode);
-                                       selection.extentOffset = this.selectionExtentOffset;
+                               if (this.selectionFocusNode) {
+                                       selection.focusElem = EvoSelection.GetChildPath(document.body, 
this.selectionFocusNode);
+                                       selection.focusOffset = this.selectionFocusOffset;
                                }
 
                                EvoSelection.Restore(document, selection);
@@ -423,12 +423,12 @@ EvoSelection.CreateUpdaterObject = function()
        };
 
        obj.selectionBefore = EvoSelection.Store(document);
-       obj.selectionBaseNode = document.getSelection().baseNode;
-       obj.selectionBaseOffset = document.getSelection().baseOffset + 
EvoSelection.GetOverallTextOffset(obj.selectionBaseNode);
+       obj.selectionAnchorNode = document.getSelection().anchorNode;
+       obj.selectionAnchorOffset = document.getSelection().anchorOffset + 
EvoSelection.GetOverallTextOffset(obj.selectionAnchorNode);
 
        if (!document.getSelection().isCollapsed) {
-               obj.selectionExtentNode = document.getSelection().extentNode;
-               obj.selectionExtentOffset = document.getSelection().extentOffset + 
EvoSelection.GetOverallTextOffset(obj.selectionExtentNode);
+               obj.selectionFocusNode = document.getSelection().focusNode;
+               obj.selectionFocusOffset = document.getSelection().focusOffset + 
EvoSelection.GetOverallTextOffset(obj.selectionFocusNode);
        }
 
        return obj;
diff --git a/data/webkit/e-undo-redo.js b/data/webkit/e-undo-redo.js
index 15ac70482d..86aefcbe29 100644
--- a/data/webkit/e-undo-redo.js
+++ b/data/webkit/e-undo-redo.js
@@ -217,15 +217,15 @@ var EvoUndoRedo = {
                        return curr && prev &&
                                curr.kind == EvoUndoRedo.RECORD_KIND_EVENT &&
                                curr.opType == "insertText" &&
-                               !curr.selectionBefore.extentElem &&
+                               !curr.selectionBefore.focusElem &&
                                prev.kind == EvoUndoRedo.RECORD_KIND_EVENT &&
                                prev.opType == "insertText" &&
-                               !prev.selectionBefore.extentElem &&
+                               !prev.selectionBefore.focusElem &&
                                curr.firstChildIndex == prev.firstChildIndex &&
                                curr.restChildrenCount == prev.restChildrenCount &&
-                               curr.selectionBefore.baseOffset == prev.selectionAfter.baseOffset &&
+                               curr.selectionBefore.anchorOffset == prev.selectionAfter.anchorOffset &&
                                EvoUndoRedo.stack.pathMatches(curr.path, prev.path) &&
-                               EvoUndoRedo.stack.pathMatches(curr.selectionBefore.baseElem, 
prev.selectionAfter.baseElem);
+                               EvoUndoRedo.stack.pathMatches(curr.selectionBefore.anchorElem, 
prev.selectionAfter.anchorElem);
                },
 
                maybeMergeConsecutive : function(skipFirst, opType) {
@@ -248,7 +248,7 @@ var EvoUndoRedo = {
                        if (!curr ||
                            curr.kind != EvoUndoRedo.RECORD_KIND_EVENT ||
                            curr.opType != opType ||
-                           curr.selectionBefore.extentElem) {
+                           curr.selectionBefore.focusElem) {
                                return;
                        }
 
@@ -261,12 +261,12 @@ var EvoUndoRedo = {
 
                                if (prev.kind != EvoUndoRedo.RECORD_KIND_EVENT ||
                                    prev.opType != opType ||
-                                   prev.selectionBefore.extentElem ||
+                                   prev.selectionBefore.focusElem ||
                                    curr.firstChildIndex != prev.firstChildIndex ||
                                    curr.restChildrenCount != prev.restChildrenCount ||
-                                   curr.selectionBefore.baseOffset != prev.selectionAfter.baseOffset ||
+                                   curr.selectionBefore.anchorOffset != prev.selectionAfter.anchorOffset ||
                                    !EvoUndoRedo.stack.pathMatches(curr.path, prev.path) ||
-                                   !EvoUndoRedo.stack.pathMatches(curr.selectionBefore.baseElem, 
prev.selectionAfter.baseElem)) {
+                                   !EvoUndoRedo.stack.pathMatches(curr.selectionBefore.anchorElem, 
prev.selectionAfter.anchorElem)) {
                                        break;
                                }
 
@@ -394,49 +394,49 @@ EvoUndoRedo.beforeInputCb = function(inputEvent)
                if (opType == "deleteWordBackward") {
                        var sel = EvoSelection.Store(document);
                        document.getSelection().modify("move", "backward", "word");
-                       startNode = document.getSelection().baseNode;
+                       startNode = document.getSelection().anchorNode;
                        EvoSelection.Restore(document, sel);
                } else if (opType == "deleteWordForward") {
                        var sel = EvoSelection.Store(document);
                        document.getSelection().modify("move", "forward", "word");
-                       startNode = document.getSelection().baseNode;
+                       startNode = document.getSelection().anchorNode;
                        EvoSelection.Restore(document, sel);
                } else if (opType == "deleteSoftLineBackward") {
                        var sel = EvoSelection.Store(document);
                        document.getSelection().modify("move", "backward", "line");
-                       startNode = document.getSelection().baseNode;
+                       startNode = document.getSelection().anchorNode;
                        EvoSelection.Restore(document, sel);
                } else if (opType == "deleteSoftLineForward") {
                        var sel = EvoSelection.Store(document);
                        document.getSelection().modify("move", "forward", "line");
-                       startNode = document.getSelection().baseNode;
+                       startNode = document.getSelection().anchorNode;
                        EvoSelection.Restore(document, sel);
                } else if (opType == "deleteEntireSoftLine") {
                        var sel = EvoSelection.Store(document);
                        document.getSelection().modify("move", "backward", "line");
-                       startNode = document.getSelection().baseNode;
+                       startNode = document.getSelection().anchorNode;
                        document.getSelection().modify("move", "forward", "line");
-                       endNode = document.getSelection().baseNode;
+                       endNode = document.getSelection().anchorNode;
                        EvoSelection.Restore(document, sel);
                } else if (opType == "deleteHardLineBackward") {
                        var sel = EvoSelection.Store(document);
                        document.getSelection().modify("move", "backward", "paragraph");
-                       startNode = document.getSelection().baseNode;
+                       startNode = document.getSelection().anchorNode;
                        EvoSelection.Restore(document, sel);
                } else if (opType == "deleteHardLineForward") {
                        var sel = EvoSelection.Store(document);
                        document.getSelection().modify("move", "forward", "paragraph");
-                       startNode = document.getSelection().baseNode;
+                       startNode = document.getSelection().anchorNode;
                        EvoSelection.Restore(document, sel);
                } else if (opType == "deleteContentBackward") {
                        var sel = EvoSelection.Store(document);
                        document.getSelection().modify("move", "backward", "paragraph");
-                       startNode = document.getSelection().baseNode;
+                       startNode = document.getSelection().anchorNode;
                        EvoSelection.Restore(document, sel);
                } else if (opType == "deleteContentForward") {
                        var sel = EvoSelection.Store(document);
                        document.getSelection().modify("move", "forward", "paragraph");
-                       startNode = document.getSelection().baseNode;
+                       startNode = document.getSelection().anchorNode;
                        EvoSelection.Restore(document, sel);
                }
        }


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]