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

Side by Side Diff: Source/WebCore/editing/ReplaceSelectionCommand.cpp

Issue 7640019: Merge 92966 (Closed) Base URL: http://svn.webkit.org/repository/webkit/branches/chromium/782/
Patch Set: Created 9 years, 4 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
« no previous file with comments | « Source/WebCore/editing/FrameSelection.cpp ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2005, 2006, 2008 Apple Inc. All rights reserved. 2 * Copyright (C) 2005, 2006, 2008 Apple Inc. All rights reserved.
3 * 3 *
4 * Redistribution and use in source and binary forms, with or without 4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions 5 * modification, are permitted provided that the following conditions
6 * are met: 6 * are met:
7 * 1. Redistributions of source code must retain the above copyright 7 * 1. Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer. 8 * notice, this list of conditions and the following disclaimer.
9 * 2. Redistributions in binary form must reproduce the above copyright 9 * 2. Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the 10 * notice, this list of conditions and the following disclaimer in the
(...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after
132 m_hasInterchangeNewlineAtStart(false), 132 m_hasInterchangeNewlineAtStart(false),
133 m_hasInterchangeNewlineAtEnd(false) 133 m_hasInterchangeNewlineAtEnd(false)
134 { 134 {
135 if (!m_document) 135 if (!m_document)
136 return; 136 return;
137 if (!m_fragment) 137 if (!m_fragment)
138 return; 138 return;
139 if (!m_fragment->firstChild()) 139 if (!m_fragment->firstChild())
140 return; 140 return;
141 141
142 Element* editableRoot = selection.rootEditableElement(); 142 RefPtr<Element> editableRoot = selection.rootEditableElement();
143 ASSERT(editableRoot); 143 ASSERT(editableRoot);
144 if (!editableRoot) 144 if (!editableRoot)
145 return; 145 return;
146 146
147 Node* shadowAncestorNode = editableRoot->shadowAncestorNode(); 147 Node* shadowAncestorNode = editableRoot->shadowAncestorNode();
148 148
149 if (!editableRoot->getAttributeEventListener(eventNames().webkitBeforeTextIn sertedEvent) && 149 if (!editableRoot->getAttributeEventListener(eventNames().webkitBeforeTextIn sertedEvent) &&
150 // FIXME: Remove these checks once textareas and textfields actually reg ister an event handler. 150 // FIXME: Remove these checks once textareas and textfields actually reg ister an event handler.
151 !(shadowAncestorNode && shadowAncestorNode->renderer() && shadowAncestor Node->renderer()->isTextControl()) && 151 !(shadowAncestorNode && shadowAncestorNode->renderer() && shadowAncestor Node->renderer()->isTextControl()) &&
152 editableRoot->rendererIsRichlyEditable()) { 152 editableRoot->rendererIsRichlyEditable()) {
153 removeInterchangeNodes(m_fragment.get()); 153 removeInterchangeNodes(m_fragment.get());
154 return; 154 return;
155 } 155 }
156 156
157 Node* styleNode = selection.base().deprecatedNode(); 157 RefPtr<Node> styleNode = selection.base().deprecatedNode();
158 RefPtr<StyledElement> holder = insertFragmentForTestRendering(styleNode); 158 RefPtr<StyledElement> holder = insertFragmentForTestRendering(styleNode.get( ));
159 if (!holder) { 159 if (!holder) {
160 removeInterchangeNodes(m_fragment.get()); 160 removeInterchangeNodes(m_fragment.get());
161 return; 161 return;
162 } 162 }
163 163
164 RefPtr<Range> range = VisibleSelection::selectionFromContentsOfNode(holder.g et()).toNormalizedRange(); 164 RefPtr<Range> range = VisibleSelection::selectionFromContentsOfNode(holder.g et()).toNormalizedRange();
165 String text = plainText(range.get()); 165 String text = plainText(range.get());
166 // Give the root a chance to change the text. 166 // Give the root a chance to change the text.
167 RefPtr<BeforeTextInsertedEvent> evt = BeforeTextInsertedEvent::create(text); 167 RefPtr<BeforeTextInsertedEvent> evt = BeforeTextInsertedEvent::create(text);
168 ExceptionCode ec = 0; 168 ExceptionCode ec = 0;
169 editableRoot->dispatchEvent(evt, ec); 169 editableRoot->dispatchEvent(evt, ec);
170 ASSERT(ec == 0); 170 ASSERT(ec == 0);
171 if (text != evt->text() || !editableRoot->rendererIsRichlyEditable()) { 171 if (text != evt->text() || !editableRoot->rendererIsRichlyEditable()) {
172 restoreTestRenderingNodesToFragment(holder.get()); 172 restoreTestRenderingNodesToFragment(holder.get());
173 removeNode(holder); 173 removeNode(holder);
174 174
175 m_fragment = createFragmentFromText(selection.toNormalizedRange().get(), evt->text()); 175 m_fragment = createFragmentFromText(selection.toNormalizedRange().get(), evt->text());
176 if (!m_fragment->firstChild()) 176 if (!m_fragment->firstChild())
177 return; 177 return;
178 holder = insertFragmentForTestRendering(styleNode); 178 holder = insertFragmentForTestRendering(styleNode.get());
179 } 179 }
180 180
181 removeInterchangeNodes(holder.get()); 181 removeInterchangeNodes(holder.get());
182 182
183 removeUnrenderedNodes(holder.get()); 183 removeUnrenderedNodes(holder.get());
184 restoreTestRenderingNodesToFragment(holder.get()); 184 restoreTestRenderingNodesToFragment(holder.get());
185 removeNode(holder); 185 removeNode(holder);
186 } 186 }
187 187
188 bool ReplacementFragment::isEmpty() const 188 bool ReplacementFragment::isEmpty() const
(...skipping 1129 matching lines...) Expand 10 before | Expand all | Expand 10 after
1318 end = Position(start.containerNode(), start.offsetInContainerNode() + text.l ength(), Position::PositionIsOffsetInAnchor); 1318 end = Position(start.containerNode(), start.offsetInContainerNode() + text.l ength(), Position::PositionIsOffsetInAnchor);
1319 1319
1320 VisibleSelection selectionAfterReplace(m_selectReplacement ? start : end, en d); 1320 VisibleSelection selectionAfterReplace(m_selectReplacement ? start : end, en d);
1321 1321
1322 setEndingSelection(selectionAfterReplace); 1322 setEndingSelection(selectionAfterReplace);
1323 1323
1324 return true; 1324 return true;
1325 } 1325 }
1326 1326
1327 } // namespace WebCore 1327 } // namespace WebCore
OLDNEW
« no previous file with comments | « Source/WebCore/editing/FrameSelection.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698