Chromium Code Reviews| 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 } | |
| 26 | |
| 27 void SetCharacterDataCommand::doApply(EditingState*) { | |
| 28 // TODO(editing-dev): The use of updateStyleAndLayoutTree() | |
| 29 // needs to be audited. See http://crbug.com/590369 for more details. | |
| 30 document().updateStyleAndLayoutTree(); | |
| 31 if (!hasEditableStyle(*m_node)) | |
| 32 return; | |
| 33 | |
| 34 DummyExceptionStateForTesting exceptionState; | |
| 35 m_previousTextForUndo = | |
| 36 m_node->substringData(m_offset, m_count, exceptionState); | |
| 37 if (exceptionState.hadException()) | |
| 38 return; | |
| 39 | |
| 40 const bool passwordEchoEnabled = | |
| 41 document().settings() && document().settings()->getPasswordEchoEnabled(); | |
| 42 | |
| 43 if (passwordEchoEnabled) { | |
| 44 LayoutText* layoutText = m_node->layoutObject(); | |
| 45 if (layoutText && layoutText->isSecure()) { | |
| 46 layoutText->momentarilyRevealLastTypedCharacter(m_offset + | |
|
yosin_UTC9
2017/02/22 06:44:32
Wow, we need to find out alternative way in layout
| |
| 47 m_newText.length() - 1); | |
| 48 } | |
| 49 } | |
| 50 | |
| 51 m_node->replaceData(m_offset, m_count, m_newText, | |
| 52 IGNORE_EXCEPTION_FOR_TESTING); | |
| 53 document().updateStyleAndLayout(); | |
|
yosin_UTC9
2017/02/22 06:44:32
We need to wait xiaochengh@'s patch.
| |
| 54 } | |
| 55 | |
| 56 void SetCharacterDataCommand::doUnapply() { | |
| 57 // TODO(editing-dev): The use of updateStyleAndLayoutTree() | |
| 58 // needs to be audited. See http://crbug.com/590369 for more details. | |
| 59 document().updateStyleAndLayoutTree(); | |
| 60 if (!hasEditableStyle(*m_node)) | |
| 61 return; | |
| 62 | |
| 63 m_node->replaceData(m_offset, m_newText.length(), m_previousTextForUndo, | |
| 64 IGNORE_EXCEPTION_FOR_TESTING); | |
| 65 } | |
| 66 | |
| 67 DEFINE_TRACE(SetCharacterDataCommand) { | |
| 68 visitor->trace(m_node); | |
| 69 SimpleEditCommand::trace(visitor); | |
| 70 } | |
| 71 | |
| 72 } // namespace blink | |
| OLD | NEW |