Commit e6de234d authored by yosin@chromium.org's avatar yosin@chromium.org

Introduce isRenderedCharacter(Position) function

This patch introduces |isRenderedCharacter(Position)()| as replacement of
|PositionAlgorithm<Strategy>::isRenderedCharacter()| to simplify source code
for improving code health, since |isRenderedCharacter()| is used only for
positions in DOM tree, thus we don't need to have composed tree version.

This patch is a part of |Position| class cleanup to reduce |LayoutObject|
dependency.


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

Review URL: https://codereview.chromium.org/1286993006

git-svn-id: svn://svn.chromium.org/blink/trunk@200801 bbb929c8-8fbe-4397-9dbb-9b2b20218538
parent c2fb6b81
...@@ -931,20 +931,19 @@ bool PositionAlgorithm<Strategy>::inRenderedText() const ...@@ -931,20 +931,19 @@ bool PositionAlgorithm<Strategy>::inRenderedText() const
return false; return false;
} }
template <typename Strategy> bool isRenderedCharacter(const Position& position)
bool PositionAlgorithm<Strategy>::isRenderedCharacter() const
{ {
if (isNull()) if (position.isNull())
return false; return false;
ASSERT(isOffsetInAnchor()); ASSERT(position.isOffsetInAnchor());
if (!anchorNode()->isTextNode()) if (!position.anchorNode()->isTextNode())
return false; return false;
LayoutObject* layoutObject = anchorNode()->layoutObject(); LayoutObject* layoutObject = position.anchorNode()->layoutObject();
if (!layoutObject) if (!layoutObject)
return false; return false;
return toLayoutText(layoutObject)->isRenderedCharacter(offsetInContainerNode()); return toLayoutText(layoutObject)->isRenderedCharacter(position.offsetInContainerNode());
} }
template <typename Strategy> template <typename Strategy>
......
...@@ -200,7 +200,6 @@ public: ...@@ -200,7 +200,6 @@ public:
bool isCandidate() const; bool isCandidate() const;
bool inRenderedText() const; bool inRenderedText() const;
bool isRenderedCharacter() const;
InlineBoxPosition computeInlineBoxPosition(EAffinity) const; InlineBoxPosition computeInlineBoxPosition(EAffinity) const;
InlineBoxPosition computeInlineBoxPosition(EAffinity, TextDirection primaryDirection) const; InlineBoxPosition computeInlineBoxPosition(EAffinity, TextDirection primaryDirection) const;
...@@ -255,6 +254,12 @@ extern template class CORE_EXTERN_TEMPLATE_EXPORT PositionAlgorithm<EditingInCom ...@@ -255,6 +254,12 @@ extern template class CORE_EXTERN_TEMPLATE_EXPORT PositionAlgorithm<EditingInCom
using Position = PositionAlgorithm<EditingStrategy>; using Position = PositionAlgorithm<EditingStrategy>;
using PositionInComposedTree = PositionAlgorithm<EditingInComposedTreeStrategy>; using PositionInComposedTree = PositionAlgorithm<EditingInComposedTreeStrategy>;
// TODO(yosin) |isRenderedCharacter()| should be removed, and we should use
// |VisiblePosition::characterAfter()| and |VisiblePosition::characterBefore()|.
// TODO(yosin) We should move |isRenderedCharacter()| to "VisibleUnits.cpp",
// since it is used only in "editing/commands/"
CORE_EXPORT bool isRenderedCharacter(const Position&);
template <typename Strategy> template <typename Strategy>
bool operator==(const PositionAlgorithm<Strategy>& a, const PositionAlgorithm<Strategy>& b) bool operator==(const PositionAlgorithm<Strategy>& a, const PositionAlgorithm<Strategy>& b)
{ {
......
...@@ -570,13 +570,15 @@ void DeleteSelectionCommand::handleGeneralDelete() ...@@ -570,13 +570,15 @@ void DeleteSelectionCommand::handleGeneralDelete()
void DeleteSelectionCommand::fixupWhitespace() void DeleteSelectionCommand::fixupWhitespace()
{ {
document().updateLayoutIgnorePendingStylesheets(); document().updateLayoutIgnorePendingStylesheets();
// FIXME: isRenderedCharacter should be removed, and we should use VisiblePosition::characterAfter and VisiblePosition::characterBefore // TODO(yosin) |isRenderedCharacter()| should be removed, and we should use
if (m_leadingWhitespace.isNotNull() && !m_leadingWhitespace.isRenderedCharacter() && m_leadingWhitespace.anchorNode()->isTextNode()) { // |VisiblePosition::characterAfter()| and
// |VisiblePosition::characterBefore()|
if (m_leadingWhitespace.isNotNull() && !isRenderedCharacter(m_leadingWhitespace) && m_leadingWhitespace.anchorNode()->isTextNode()) {
Text* textNode = toText(m_leadingWhitespace.anchorNode()); Text* textNode = toText(m_leadingWhitespace.anchorNode());
ASSERT(!textNode->layoutObject() || textNode->layoutObject()->style()->collapseWhiteSpace()); ASSERT(!textNode->layoutObject() || textNode->layoutObject()->style()->collapseWhiteSpace());
replaceTextInNodePreservingMarkers(textNode, m_leadingWhitespace.computeOffsetInContainerNode(), 1, nonBreakingSpaceString()); replaceTextInNodePreservingMarkers(textNode, m_leadingWhitespace.computeOffsetInContainerNode(), 1, nonBreakingSpaceString());
} }
if (m_trailingWhitespace.isNotNull() && !m_trailingWhitespace.isRenderedCharacter() && m_trailingWhitespace.anchorNode()->isTextNode()) { if (m_trailingWhitespace.isNotNull() && !isRenderedCharacter(m_trailingWhitespace) && m_trailingWhitespace.anchorNode()->isTextNode()) {
Text* textNode = toText(m_trailingWhitespace.anchorNode()); Text* textNode = toText(m_trailingWhitespace.anchorNode());
ASSERT(!textNode->layoutObject() || textNode->layoutObject()->style()->collapseWhiteSpace()); ASSERT(!textNode->layoutObject() || textNode->layoutObject()->style()->collapseWhiteSpace());
replaceTextInNodePreservingMarkers(textNode, m_trailingWhitespace.computeOffsetInContainerNode(), 1, nonBreakingSpaceString()); replaceTextInNodePreservingMarkers(textNode, m_trailingWhitespace.computeOffsetInContainerNode(), 1, nonBreakingSpaceString());
......
...@@ -123,7 +123,9 @@ void InsertLineBreakCommand::doApply() ...@@ -123,7 +123,9 @@ void InsertLineBreakCommand::doApply()
// Handle whitespace that occurs after the split // Handle whitespace that occurs after the split
document().updateLayoutIgnorePendingStylesheets(); document().updateLayoutIgnorePendingStylesheets();
if (!endingPosition.isRenderedCharacter()) { // TODO(yosin) |isRenderedCharacter()| should be removed, and we should
// use |VisiblePosition::characterAfter()|.
if (!isRenderedCharacter(endingPosition)) {
Position positionBeforeTextNode(positionInParentBeforeNode(*textNode)); Position positionBeforeTextNode(positionInParentBeforeNode(*textNode));
// Clear out all whitespace and insert one non-breaking space // Clear out all whitespace and insert one non-breaking space
deleteInsignificantTextDownstream(endingPosition); deleteInsignificantTextDownstream(endingPosition);
......
...@@ -417,7 +417,9 @@ void InsertParagraphSeparatorCommand::doApply() ...@@ -417,7 +417,9 @@ void InsertParagraphSeparatorCommand::doApply()
// Handle whitespace that occurs after the split // Handle whitespace that occurs after the split
if (positionAfterSplit.isNotNull()) { if (positionAfterSplit.isNotNull()) {
document().updateLayoutIgnorePendingStylesheets(); document().updateLayoutIgnorePendingStylesheets();
if (!positionAfterSplit.isRenderedCharacter()) { // TODO(yosin) |isRenderedCharacter()| should be removed, and we should
// use |VisiblePosition::characterAfter()|.
if (!isRenderedCharacter(positionAfterSplit)) {
// Clear out all whitespace and insert one non-breaking space // Clear out all whitespace and insert one non-breaking space
ASSERT(!positionAfterSplit.computeContainerNode()->layoutObject() || positionAfterSplit.computeContainerNode()->layoutObject()->style()->collapseWhiteSpace()); ASSERT(!positionAfterSplit.computeContainerNode()->layoutObject() || positionAfterSplit.computeContainerNode()->layoutObject()->style()->collapseWhiteSpace());
deleteInsignificantTextDownstream(positionAfterSplit); deleteInsignificantTextDownstream(positionAfterSplit);
......
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