Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(122)

Unified Diff: Source/WebCore/editing/TextIterator.cpp

Issue 12780019: Merge 145954 "TextIterator emits LF for a br element inside an e..." (Closed) Base URL: http://svn.webkit.org/repository/webkit/branches/chromium/1410/
Patch Set: Created 7 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « Source/WebCore/editing/TextIterator.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: Source/WebCore/editing/TextIterator.cpp
===================================================================
--- Source/WebCore/editing/TextIterator.cpp (revision 146097)
+++ Source/WebCore/editing/TextIterator.cpp (working copy)
@@ -747,14 +747,13 @@
return t && (t->cellBefore(rc) || t->cellAbove(rc));
}
-static bool shouldEmitNewlineForNode(Node* node)
+static bool shouldEmitNewlineForNode(Node* node, bool emitsOriginalText)
{
- // br elements are represented by a single newline.
- RenderObject* r = node->renderer();
- if (!r)
- return node->hasTagName(brTag);
-
- return r->isBR();
+ RenderObject* renderer = node->renderer();
+
+ if (renderer ? !renderer->isBR() : !node->hasTagName(brTag))
+ return false;
+ return emitsOriginalText || !(node->isInShadowTree() && node->shadowHost()->toInputElement());
}
static bool shouldEmitNewlinesBeforeAndAfterNode(Node* node)
@@ -956,7 +955,7 @@
bool TextIterator::handleNonTextNode()
{
- if (shouldEmitNewlineForNode(m_node))
+ if (shouldEmitNewlineForNode(m_node, m_emitsOriginalText))
emitCharacter('\n', m_node->parentNode(), m_node, 0, 1);
else if (m_emitsCharactersBetweenAllVisiblePositions && m_node->renderer() && m_node->renderer()->isHR())
emitCharacter(' ', m_node->parentNode(), m_node, 0, 1);
@@ -1110,6 +1109,7 @@
, m_shouldHandleFirstLetter(false)
, m_stopsOnFormControls(false)
, m_shouldStop(false)
+ , m_emitsOriginalText(false)
{
}
@@ -1134,6 +1134,7 @@
, m_shouldHandleFirstLetter(false)
, m_stopsOnFormControls(behavior & TextIteratorStopsOnFormControls)
, m_shouldStop(false)
+ , m_emitsOriginalText(false)
{
ASSERT(behavior == TextIteratorDefaultBehavior || behavior == TextIteratorStopsOnFormControls);
@@ -1342,7 +1343,7 @@
{
// We can use a linefeed in place of a tab because this simple iterator is only used to
// find boundaries, not actual content. A linefeed breaks words, sentences, and paragraphs.
- if (shouldEmitNewlineForNode(m_node) || shouldEmitNewlineAfterNode(m_node) || shouldEmitTabBeforeNode(m_node)) {
+ if (shouldEmitNewlineForNode(m_node, m_emitsOriginalText) || shouldEmitNewlineAfterNode(m_node) || shouldEmitTabBeforeNode(m_node)) {
unsigned index = m_node->nodeIndex();
// The start of this emitted range is wrong. Ensuring correctness would require
// VisiblePositions and so would be slow. previousBoundary expects this.
@@ -1353,7 +1354,7 @@
void SimplifiedBackwardsTextIterator::exitNode()
{
- if (shouldEmitNewlineForNode(m_node) || shouldEmitNewlineBeforeNode(m_node) || shouldEmitTabBeforeNode(m_node)) {
+ if (shouldEmitNewlineForNode(m_node, m_emitsOriginalText) || shouldEmitNewlineBeforeNode(m_node) || shouldEmitTabBeforeNode(m_node)) {
// The start of this emitted range is wrong. Ensuring correctness would require
// VisiblePositions and so would be slow. previousBoundary expects this.
emitCharacter('\n', m_node, 0, 0);
« no previous file with comments | « Source/WebCore/editing/TextIterator.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698