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

Unified Diff: Source/core/editing/DeleteSelectionCommand.cpp

Issue 15011008: Don't insert rednant placeholder for text control after deleting (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: 2013-05-10T19:11 Created 7 years, 7 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
Index: Source/core/editing/DeleteSelectionCommand.cpp
diff --git a/Source/core/editing/DeleteSelectionCommand.cpp b/Source/core/editing/DeleteSelectionCommand.cpp
index b006a9af715a30bf4c4e4bca88ac3bb162bb4dbf..013108ba9d880293d45f4153195ee51ce89c2aef 100644
--- a/Source/core/editing/DeleteSelectionCommand.cpp
+++ b/Source/core/editing/DeleteSelectionCommand.cpp
@@ -37,8 +37,7 @@
#include "core/editing/Editor.h"
#include "core/editing/VisibleUnits.h"
#include "core/editing/htmlediting.h"
-#include "core/html/HTMLInputElement.h"
-#include "core/html/HTMLTextAreaElement.h"
+#include "core/html/HTMLTextFormControlElement.h"
#include "core/page/EditorClient.h"
#include "core/page/Frame.h"
#include "core/rendering/RenderTableCell.h"
@@ -70,6 +69,23 @@ static bool isTableRowEmpty(Node* row)
return true;
}
+static bool shouldNotHavePlaceholder(HTMLTextFormControlElement* textControl)
+{
+ if (!textControl)
+ return false;
+
+ Node* textElement = textControl->innerTextElement();
+ if (!textElement)
+ return false;
+
+ // When text control is empty, we don't need to have placeholder.
+ if (!textElement->firstChild())
+ return true;
+
+ // Text control ends with placeholder.
+ return textElement->lastChild()->hasTagName(brTag);
+}
+
DeleteSelectionCommand::DeleteSelectionCommand(Document *document, bool smartDelete, bool mergeBlocksAfterDelete, bool replace, bool expandForSpecialElements, bool sanitizeMarkup)
: CompositeEditCommand(document)
, m_hasSelectionToDelete(false)
@@ -802,7 +818,9 @@ void DeleteSelectionCommand::doApply()
m_needPlaceholder = false;
}
-
+
+ RefPtr<HTMLTextFormControlElement> textControl = enclosingTextFormControl(m_selectionToDelete.start());
+
// set up our state
initializePositionData();
@@ -828,7 +846,10 @@ void DeleteSelectionCommand::doApply()
mergeParagraphs();
removePreviouslySelectedEmptyTableRows();
-
+
+ if (m_needPlaceholder && shouldNotHavePlaceholder(textControl.get()))
+ m_needPlaceholder = false;
+
RefPtr<Node> placeholder = m_needPlaceholder ? createBreakElement(document()).get() : 0;
if (placeholder) {

Powered by Google App Engine
This is Rietveld 408576698