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