Chromium Code Reviews| Index: third_party/WebKit/Source/core/editing/commands/SetCharacterDataCommand.cpp |
| diff --git a/third_party/WebKit/Source/core/editing/commands/SetCharacterDataCommand.cpp b/third_party/WebKit/Source/core/editing/commands/SetCharacterDataCommand.cpp |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..440a025c2badd8d5ee9c3356db8f4b7c84b13ae7 |
| --- /dev/null |
| +++ b/third_party/WebKit/Source/core/editing/commands/SetCharacterDataCommand.cpp |
| @@ -0,0 +1,72 @@ |
| +// Copyright 2017 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#include "core/editing/commands/SetCharacterDataCommand.h" |
| + |
| +#include "core/editing/EditingUtilities.h" |
| +#include "core/frame/Settings.h" |
| +#include "core/layout/LayoutText.h" |
| + |
| +namespace blink { |
| + |
| +SetCharacterDataCommand::SetCharacterDataCommand(Text* node, |
| + unsigned offset, |
| + unsigned count, |
| + const String& text) |
| + : SimpleEditCommand(node->document()), |
| + m_node(node), |
| + m_offset(offset), |
| + m_count(count), |
| + m_newText(text) { |
| + DCHECK(m_node); |
| + DCHECK_LE(m_offset, m_node->length()); |
| + DCHECK_LE(m_offset + m_count, m_node->length()); |
| +} |
| + |
| +void SetCharacterDataCommand::doApply(EditingState*) { |
| + // TODO(editing-dev): The use of updateStyleAndLayoutTree() |
| + // needs to be audited. See http://crbug.com/590369 for more details. |
| + document().updateStyleAndLayoutTree(); |
| + if (!hasEditableStyle(*m_node)) |
| + return; |
| + |
| + DummyExceptionStateForTesting exceptionState; |
| + m_previousTextForUndo = |
| + m_node->substringData(m_offset, m_count, exceptionState); |
| + if (exceptionState.hadException()) |
| + return; |
| + |
| + const bool passwordEchoEnabled = |
| + document().settings() && document().settings()->getPasswordEchoEnabled(); |
| + |
| + if (passwordEchoEnabled) { |
| + LayoutText* layoutText = m_node->layoutObject(); |
| + if (layoutText && layoutText->isSecure()) { |
| + layoutText->momentarilyRevealLastTypedCharacter(m_offset + |
|
yosin_UTC9
2017/02/22 06:44:32
Wow, we need to find out alternative way in layout
|
| + m_newText.length() - 1); |
| + } |
| + } |
| + |
| + m_node->replaceData(m_offset, m_count, m_newText, |
| + IGNORE_EXCEPTION_FOR_TESTING); |
| + document().updateStyleAndLayout(); |
|
yosin_UTC9
2017/02/22 06:44:32
We need to wait xiaochengh@'s patch.
|
| +} |
| + |
| +void SetCharacterDataCommand::doUnapply() { |
| + // TODO(editing-dev): The use of updateStyleAndLayoutTree() |
| + // needs to be audited. See http://crbug.com/590369 for more details. |
| + document().updateStyleAndLayoutTree(); |
| + if (!hasEditableStyle(*m_node)) |
| + return; |
| + |
| + m_node->replaceData(m_offset, m_newText.length(), m_previousTextForUndo, |
| + IGNORE_EXCEPTION_FOR_TESTING); |
| +} |
| + |
| +DEFINE_TRACE(SetCharacterDataCommand) { |
| + visitor->trace(m_node); |
| + SimpleEditCommand::trace(visitor); |
| +} |
| + |
| +} // namespace blink |