Commit d843d2ba authored by yosin's avatar yosin Committed by Commit bot

Make editingIgnoresContents() as global function

This patch makes |editingIgnoresContents()| as global function instead of
static member function of template class |EditingStratgegy| since it doesn't
use template parameter to simplify code for improving code health.

BUG=n/a
TEST=n/a; no behavior changes

Review-Url: https://codereview.chromium.org/2441693004
Cr-Commit-Position: refs/heads/master@{#427016}
parent 99a27564
...@@ -23,9 +23,11 @@ int EditingAlgorithm<Traversal>::caretMaxOffset(const Node& node) { ...@@ -23,9 +23,11 @@ int EditingAlgorithm<Traversal>::caretMaxOffset(const Node& node) {
return lastOffsetForEditing(&node); return lastOffsetForEditing(&node);
} }
template <typename Traversal> // TODO(yosin): We should move "isEmptyNonEditableNodeInEditable()" to
bool EditingAlgorithm<Traversal>::isEmptyNonEditableNodeInEditable( // "EditingUtilities.cpp"
const Node* node) { // |isEmptyNonEditableNodeInEditable()| is introduced for fixing
// http://crbug.com/428986.
static bool isEmptyNonEditableNodeInEditable(const Node* node) {
// Editability is defined the DOM tree rather than the flat tree. For example: // Editability is defined the DOM tree rather than the flat tree. For example:
// DOM: // DOM:
// <host> // <host>
...@@ -36,12 +38,18 @@ bool EditingAlgorithm<Traversal>::isEmptyNonEditableNodeInEditable( ...@@ -36,12 +38,18 @@ bool EditingAlgorithm<Traversal>::isEmptyNonEditableNodeInEditable(
// Flat Tree: // Flat Tree:
// <host><div ce><span1>unedittable</span></div></host> // <host><div ce><span1>unedittable</span></div></host>
// e.g. editing/shadow/breaking-editing-boundaries.html // e.g. editing/shadow/breaking-editing-boundaries.html
return !Traversal::hasChildren(*node) && !hasEditableStyle(*node) && return !NodeTraversal::hasChildren(*node) && !hasEditableStyle(*node) &&
node->parentNode() && hasEditableStyle(*node->parentNode()); node->parentNode() && hasEditableStyle(*node->parentNode());
} }
template <typename Traversal> // TODO(yosin): We should move "editingIgnoresContent()" to
bool EditingAlgorithm<Traversal>::editingIgnoresContent(const Node* node) { // "EditingUtilities.cpp"
// TODO(yosin) We should make |editingIgnoresContent()| to take |Node&| instead
// |Node*|.
// TODO(yosin): We should not use |isEmptyNonEditableNodeInEditable()| in
// |editingIgnoresContent()| since |isEmptyNonEditableNodeInEditable()|
// requires clean layout tree.
bool editingIgnoresContent(const Node* node) {
return !node->canContainRangeEndPoint() || return !node->canContainRangeEndPoint() ||
isEmptyNonEditableNodeInEditable(node); isEmptyNonEditableNodeInEditable(node);
} }
......
...@@ -25,11 +25,6 @@ class CORE_TEMPLATE_CLASS_EXPORT EditingAlgorithm : public Traversal { ...@@ -25,11 +25,6 @@ class CORE_TEMPLATE_CLASS_EXPORT EditingAlgorithm : public Traversal {
public: public:
static int caretMaxOffset(const Node&); static int caretMaxOffset(const Node&);
// TODO(yosin) We should make following functions to take |Node&| instead
// of |Node*|.
static bool isEmptyNonEditableNodeInEditable(const Node*);
static bool editingIgnoresContent(const Node*);
// This method is used to create positions in the DOM. It returns the // This method is used to create positions in the DOM. It returns the
// maximum valid offset in a node. It returns 1 for some elements even // maximum valid offset in a node. It returns 1 for some elements even
// though they do not have children, which creates technically invalid DOM // though they do not have children, which creates technically invalid DOM
......
...@@ -163,9 +163,8 @@ inline ContainerNode* parentCrossingShadowBoundaries<EditingInFlatTreeStrategy>( ...@@ -163,9 +163,8 @@ inline ContainerNode* parentCrossingShadowBoundaries<EditingInFlatTreeStrategy>(
// Returns true for nodes that either have no content, or have content that is // Returns true for nodes that either have no content, or have content that is
// ignored (skipped over) while editing. There are no VisiblePositions inside // ignored (skipped over) while editing. There are no VisiblePositions inside
// these nodes. // these nodes.
inline bool editingIgnoresContent(const Node* node) { // TODO(yosin) We should make |editingIgnoresContent()| take |Node&|.
return EditingStrategy::editingIgnoresContent(node); bool editingIgnoresContent(const Node*);
}
inline bool canHaveChildrenForEditing(const Node* node) { inline bool canHaveChildrenForEditing(const Node* node) {
return !node->isTextNode() && node->canContainRangeEndPoint(); return !node->isTextNode() && node->canContainRangeEndPoint();
......
...@@ -67,7 +67,7 @@ PositionTemplate<Strategy> PositionTemplate<Strategy>::editingPositionOf( ...@@ -67,7 +67,7 @@ PositionTemplate<Strategy> PositionTemplate<Strategy>::editingPositionOf(
if (!anchorNode || anchorNode->isTextNode()) if (!anchorNode || anchorNode->isTextNode())
return PositionTemplate<Strategy>(anchorNode, offset); return PositionTemplate<Strategy>(anchorNode, offset);
if (!Strategy::editingIgnoresContent(anchorNode)) if (!editingIgnoresContent(anchorNode))
return PositionTemplate<Strategy>(anchorNode, offset); return PositionTemplate<Strategy>(anchorNode, offset);
if (offset == 0) if (offset == 0)
...@@ -179,7 +179,7 @@ PositionTemplate<Strategy>::parentAnchoredEquivalent() const { ...@@ -179,7 +179,7 @@ PositionTemplate<Strategy>::parentAnchoredEquivalent() const {
// needed for positions before and after Tables // needed for positions before and after Tables
if (m_offset == 0 && !isAfterAnchorOrAfterChildren()) { if (m_offset == 0 && !isAfterAnchorOrAfterChildren()) {
if (Strategy::parent(*m_anchorNode) && if (Strategy::parent(*m_anchorNode) &&
(Strategy::editingIgnoresContent(m_anchorNode.get()) || (editingIgnoresContent(m_anchorNode.get()) ||
isDisplayInsideTable(m_anchorNode.get()))) isDisplayInsideTable(m_anchorNode.get())))
return inParentBeforeNode(*m_anchorNode); return inParentBeforeNode(*m_anchorNode);
return PositionTemplate<Strategy>(m_anchorNode.get(), 0); return PositionTemplate<Strategy>(m_anchorNode.get(), 0);
...@@ -187,7 +187,7 @@ PositionTemplate<Strategy>::parentAnchoredEquivalent() const { ...@@ -187,7 +187,7 @@ PositionTemplate<Strategy>::parentAnchoredEquivalent() const {
if (!m_anchorNode->isCharacterDataNode() && if (!m_anchorNode->isCharacterDataNode() &&
(isAfterAnchorOrAfterChildren() || (isAfterAnchorOrAfterChildren() ||
static_cast<unsigned>(m_offset) == m_anchorNode->countChildren()) && static_cast<unsigned>(m_offset) == m_anchorNode->countChildren()) &&
(Strategy::editingIgnoresContent(m_anchorNode.get()) || (editingIgnoresContent(m_anchorNode.get()) ||
isDisplayInsideTable(m_anchorNode.get())) && isDisplayInsideTable(m_anchorNode.get())) &&
computeContainerNode()) { computeContainerNode()) {
return inParentAfterNode(*m_anchorNode); return inParentAfterNode(*m_anchorNode);
...@@ -485,8 +485,8 @@ PositionTemplate<Strategy> ...@@ -485,8 +485,8 @@ PositionTemplate<Strategy>
PositionTemplate<Strategy>::firstPositionInOrBeforeNode(Node* node) { PositionTemplate<Strategy>::firstPositionInOrBeforeNode(Node* node) {
if (!node) if (!node)
return PositionTemplate<Strategy>(); return PositionTemplate<Strategy>();
return Strategy::editingIgnoresContent(node) ? beforeNode(node) return editingIgnoresContent(node) ? beforeNode(node)
: firstPositionInNode(node); : firstPositionInNode(node);
} }
// static // static
...@@ -495,8 +495,8 @@ PositionTemplate<Strategy> ...@@ -495,8 +495,8 @@ PositionTemplate<Strategy>
PositionTemplate<Strategy>::lastPositionInOrAfterNode(Node* node) { PositionTemplate<Strategy>::lastPositionInOrAfterNode(Node* node) {
if (!node) if (!node)
return PositionTemplate<Strategy>(); return PositionTemplate<Strategy>();
return Strategy::editingIgnoresContent(node) ? afterNode(node) return editingIgnoresContent(node) ? afterNode(node)
: lastPositionInNode(node); : lastPositionInNode(node);
} }
PositionInFlatTree toPositionInFlatTree(const Position& pos) { PositionInFlatTree toPositionInFlatTree(const Position& pos) {
......
...@@ -73,8 +73,7 @@ PositionIteratorAlgorithm<Strategy>::deprecatedComputePosition() const { ...@@ -73,8 +73,7 @@ PositionIteratorAlgorithm<Strategy>::deprecatedComputePosition() const {
DCHECK_NE(m_offsetsInAnchorNode[m_depthToAnchorNode], kInvalidOffset); DCHECK_NE(m_offsetsInAnchorNode[m_depthToAnchorNode], kInvalidOffset);
// FIXME: This check is inadaquete because any ancestor could be ignored by // FIXME: This check is inadaquete because any ancestor could be ignored by
// editing // editing
if (Strategy::editingIgnoresContent( if (editingIgnoresContent(Strategy::parent(*m_nodeAfterPositionInAnchor)))
Strategy::parent(*m_nodeAfterPositionInAnchor)))
return PositionTemplate<Strategy>::beforeNode(m_anchorNode); return PositionTemplate<Strategy>::beforeNode(m_anchorNode);
return PositionTemplate<Strategy>( return PositionTemplate<Strategy>(
m_anchorNode, m_offsetsInAnchorNode[m_depthToAnchorNode]); m_anchorNode, m_offsetsInAnchorNode[m_depthToAnchorNode]);
......
...@@ -1930,7 +1930,7 @@ static PositionTemplate<Strategy> endOfParagraphAlgorithm( ...@@ -1930,7 +1930,7 @@ static PositionTemplate<Strategy> endOfParagraphAlgorithm(
candidateOffset = candidateOffset =
layoutObject->caretMaxOffset() + text->textStartOffset(); layoutObject->caretMaxOffset() + text->textStartOffset();
nextNodeItreator = Strategy::next(*nextNodeItreator, startBlock); nextNodeItreator = Strategy::next(*nextNodeItreator, startBlock);
} else if (Strategy::editingIgnoresContent(nextNodeItreator) || } else if (editingIgnoresContent(nextNodeItreator) ||
isDisplayInsideTable(nextNodeItreator)) { isDisplayInsideTable(nextNodeItreator)) {
candidateNode = nextNodeItreator; candidateNode = nextNodeItreator;
candidateType = PositionAnchorType::AfterAnchor; candidateType = PositionAnchorType::AfterAnchor;
...@@ -2847,7 +2847,7 @@ static PositionTemplate<Strategy> mostBackwardCaretPosition( ...@@ -2847,7 +2847,7 @@ static PositionTemplate<Strategy> mostBackwardCaretPosition(
// Return position after tables and nodes which have content that can be // Return position after tables and nodes which have content that can be
// ignored. // ignored.
if (Strategy::editingIgnoresContent(currentNode) || if (editingIgnoresContent(currentNode) ||
isDisplayInsideTable(currentNode)) { isDisplayInsideTable(currentNode)) {
if (currentPos.atEndOfNode()) if (currentPos.atEndOfNode())
return PositionTemplate<Strategy>::afterNode(currentNode); return PositionTemplate<Strategy>::afterNode(currentNode);
...@@ -3024,7 +3024,7 @@ PositionTemplate<Strategy> mostForwardCaretPosition( ...@@ -3024,7 +3024,7 @@ PositionTemplate<Strategy> mostForwardCaretPosition(
// Return position before tables and nodes which have content that can be // Return position before tables and nodes which have content that can be
// ignored. // ignored.
if (Strategy::editingIgnoresContent(currentNode) || if (editingIgnoresContent(currentNode) ||
isDisplayInsideTable(currentNode)) { isDisplayInsideTable(currentNode)) {
if (currentPos.offsetInLeafNode() <= layoutObject->caretMinOffset()) if (currentPos.offsetInLeafNode() <= layoutObject->caretMinOffset())
return PositionTemplate<Strategy>::editingPositionOf( return PositionTemplate<Strategy>::editingPositionOf(
...@@ -3172,8 +3172,7 @@ static bool isVisuallyEquivalentCandidateAlgorithm( ...@@ -3172,8 +3172,7 @@ static bool isVisuallyEquivalentCandidateAlgorithm(
return false; return false;
} }
if (isDisplayInsideTable(anchorNode) || if (isDisplayInsideTable(anchorNode) || editingIgnoresContent(anchorNode)) {
Strategy::editingIgnoresContent(anchorNode)) {
if (!position.atFirstEditingPositionForNode() && if (!position.atFirstEditingPositionForNode() &&
!position.atLastEditingPositionForNode()) !position.atLastEditingPositionForNode())
return false; return false;
......
...@@ -213,7 +213,7 @@ void SpellChecker::didBeginEditing(Element* element) { ...@@ -213,7 +213,7 @@ void SpellChecker::didBeginEditing(Element* element) {
} }
if (isTextField || !parent->isAlreadySpellChecked()) { if (isTextField || !parent->isAlreadySpellChecked()) {
if (EditingStrategy::editingIgnoresContent(element)) if (editingIgnoresContent(element))
return; return;
// We always recheck textfields because markers are removed from them on // We always recheck textfields because markers are removed from them on
// blur. // blur.
......
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