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_count, m_node->length()); | |
|
yosin_UTC9
2017/02/20 07:26:26
Please add
DCHECK_LT(m_offset, m_node->length());
| |
| 24 } | |
| 25 | |
| 26 void SetCharacterDataCommand::doApply(EditingState*) { | |
| 27 DCHECK(m_node); | |
|
yosin_UTC9
2017/02/20 07:26:26
nit: We don't need to have DCHECK(m_node). |m_node
| |
| 28 | |
| 29 document().updateStyleAndLayoutTree(); | |
|
yosin_UTC9
2017/02/20 07:26:26
Please add following comment before L29
// TODO(e
| |
| 30 if (!hasEditableStyle(*m_node)) | |
| 31 return; | |
| 32 | |
| 33 DummyExceptionStateForTesting exceptionState; | |
| 34 m_previousTextForUndo = | |
| 35 m_node->substringData(m_offset, m_count, exceptionState); | |
| 36 if (exceptionState.hadException()) | |
| 37 return; | |
| 38 | |
| 39 bool passwordEchoEnabled = | |
|
yosin_UTC9
2017/02/20 07:26:26
nit: s/bool/const bool/
| |
| 40 document().settings() && document().settings()->getPasswordEchoEnabled(); | |
| 41 | |
| 42 if (passwordEchoEnabled) { | |
| 43 LayoutText* layoutText = m_node->layoutObject(); | |
| 44 if (layoutText && layoutText->isSecure()) { | |
| 45 layoutText->momentarilyRevealLastTypedCharacter(m_offset + | |
| 46 m_newText.length() - 1); | |
| 47 } | |
| 48 } | |
| 49 | |
| 50 m_node->replaceData(m_offset, m_count, m_newText, | |
| 51 IGNORE_EXCEPTION_FOR_TESTING); | |
| 52 document().updateStyleAndLayout(); | |
| 53 } | |
| 54 | |
| 55 void SetCharacterDataCommand::doUnapply() { | |
| 56 DCHECK(m_node); | |
|
yosin_UTC9
2017/02/20 07:26:26
nit: We don't need to have DCHECK(m_node). |m_node
| |
| 57 | |
| 58 if (!hasEditableStyle(*m_node)) | |
|
yosin_UTC9
2017/02/20 07:26:26
Please update layout tree:
// TODO(editing-dev):
rlanday
2017/02/21 20:04:06
Can you please explain to me what this is doing an
Xiaocheng
2017/02/22 01:49:23
This function resolves style for all elements in t
| |
| 59 return; | |
| 60 | |
| 61 m_node->replaceData(m_offset, m_newText.length(), m_previousTextForUndo, | |
| 62 IGNORE_EXCEPTION_FOR_TESTING); | |
| 63 m_node->document().updateStyleAndLayout(); | |
|
yosin_UTC9
2017/02/20 07:26:26
Please don't call |updateStyleAndLayout()| here.
| |
| 64 } | |
| 65 | |
| 66 DEFINE_TRACE(SetCharacterDataCommand) { | |
| 67 visitor->trace(m_node); | |
| 68 SimpleEditCommand::trace(visitor); | |
| 69 } | |
| 70 | |
| 71 } // namespace blink | |
| OLD | NEW |