OLD | NEW |
(Empty) | |
| 1 // Copyright 2017 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "core/editing/commands/SetCharacterDataCommand.h" |
| 6 |
| 7 #include "core/editing/EditingUtilities.h" |
| 8 #include "core/frame/Settings.h" |
| 9 #include "core/layout/LayoutText.h" |
| 10 |
| 11 namespace blink { |
| 12 |
| 13 SetCharacterDataCommand::SetCharacterDataCommand(Text* node, |
| 14 unsigned offset, |
| 15 unsigned count, |
| 16 const String& text) |
| 17 : SimpleEditCommand(node->document()), |
| 18 m_node(node), |
| 19 m_offset(offset), |
| 20 m_count(count), |
| 21 m_newText(text) { |
| 22 DCHECK(m_node); |
| 23 DCHECK_LE(m_offset, m_node->length()); |
| 24 DCHECK_LE(m_offset + m_count, m_node->length()); |
| 25 // Callers shouldn't be trying to perform no-op replacements |
| 26 DCHECK(!(count == 0 && text.length() == 0)); |
| 27 } |
| 28 |
| 29 void SetCharacterDataCommand::doApply(EditingState*) { |
| 30 // TODO(editing-dev): The use of updateStyleAndLayoutTree() |
| 31 // needs to be audited. See http://crbug.com/590369 for more details. |
| 32 document().updateStyleAndLayoutTree(); |
| 33 if (!hasEditableStyle(*m_node)) |
| 34 return; |
| 35 |
| 36 DummyExceptionStateForTesting exceptionState; |
| 37 m_previousTextForUndo = |
| 38 m_node->substringData(m_offset, m_count, exceptionState); |
| 39 if (exceptionState.hadException()) |
| 40 return; |
| 41 |
| 42 const bool passwordEchoEnabled = |
| 43 document().settings() && document().settings()->getPasswordEchoEnabled(); |
| 44 |
| 45 if (passwordEchoEnabled) { |
| 46 LayoutText* layoutText = m_node->layoutObject(); |
| 47 if (layoutText && layoutText->isSecure()) { |
| 48 layoutText->momentarilyRevealLastTypedCharacter(m_offset + |
| 49 m_newText.length() - 1); |
| 50 } |
| 51 } |
| 52 |
| 53 m_node->replaceData(m_offset, m_count, m_newText, |
| 54 IGNORE_EXCEPTION_FOR_TESTING); |
| 55 } |
| 56 |
| 57 void SetCharacterDataCommand::doUnapply() { |
| 58 // TODO(editing-dev): The use of updateStyleAndLayoutTree() |
| 59 // needs to be audited. See http://crbug.com/590369 for more details. |
| 60 document().updateStyleAndLayoutTree(); |
| 61 if (!hasEditableStyle(*m_node)) |
| 62 return; |
| 63 |
| 64 m_node->replaceData(m_offset, m_newText.length(), m_previousTextForUndo, |
| 65 IGNORE_EXCEPTION_FOR_TESTING); |
| 66 } |
| 67 |
| 68 DEFINE_TRACE(SetCharacterDataCommand) { |
| 69 visitor->trace(m_node); |
| 70 SimpleEditCommand::trace(visitor); |
| 71 } |
| 72 |
| 73 } // namespace blink |
OLD | NEW |