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

Side by Side Diff: third_party/WebKit/Source/core/editing/commands/SetCharacterDataCommand.cpp

Issue 2706033007: Add SetCharacterDataCommand (Closed)
Patch Set: Remove updateStyleAndLayout(), add DCHECK, add more tests Created 3 years, 10 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 unified diff | Download patch
OLDNEW
(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
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698