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

Side by Side Diff: Source/core/editing/TypingCommand.cpp

Issue 166573003: Port ParentNode API to ElementTraversal (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Created 6 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
« no previous file with comments | « Source/core/dom/ParentNode.h ('k') | Source/core/svg/SVGPatternElement.cpp » ('j') | 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, 2007, 2008 Apple Inc. All rights reserved. 2 * Copyright (C) 2005, 2006, 2007, 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 11 matching lines...) Expand all
22 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 22 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
23 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 23 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
24 */ 24 */
25 25
26 #include "config.h" 26 #include "config.h"
27 #include "core/editing/TypingCommand.h" 27 #include "core/editing/TypingCommand.h"
28 28
29 #include "HTMLNames.h" 29 #include "HTMLNames.h"
30 #include "core/dom/Document.h" 30 #include "core/dom/Document.h"
31 #include "core/dom/Element.h" 31 #include "core/dom/Element.h"
32 #include "core/dom/ElementTraversal.h"
32 #include "core/editing/BreakBlockquoteCommand.h" 33 #include "core/editing/BreakBlockquoteCommand.h"
33 #include "core/editing/Editor.h" 34 #include "core/editing/Editor.h"
34 #include "core/editing/FrameSelection.h" 35 #include "core/editing/FrameSelection.h"
35 #include "core/editing/InsertLineBreakCommand.h" 36 #include "core/editing/InsertLineBreakCommand.h"
36 #include "core/editing/InsertParagraphSeparatorCommand.h" 37 #include "core/editing/InsertParagraphSeparatorCommand.h"
37 #include "core/editing/InsertTextCommand.h" 38 #include "core/editing/InsertTextCommand.h"
38 #include "core/editing/SpellChecker.h" 39 #include "core/editing/SpellChecker.h"
39 #include "core/editing/VisiblePosition.h" 40 #include "core/editing/VisiblePosition.h"
40 #include "core/editing/VisibleUnits.h" 41 #include "core/editing/VisibleUnits.h"
41 #include "core/editing/htmlediting.h" 42 #include "core/editing/htmlediting.h"
(...skipping 332 matching lines...) Expand 10 before | Expand all | Expand 10 after
374 applyCommandToComposite(BreakBlockquoteCommand::create(document())); 375 applyCommandToComposite(BreakBlockquoteCommand::create(document()));
375 typingAddedToOpenCommand(InsertParagraphSeparatorInQuotedContent); 376 typingAddedToOpenCommand(InsertParagraphSeparatorInQuotedContent);
376 } 377 }
377 378
378 bool TypingCommand::makeEditableRootEmpty() 379 bool TypingCommand::makeEditableRootEmpty()
379 { 380 {
380 Element* root = endingSelection().rootEditableElement(); 381 Element* root = endingSelection().rootEditableElement();
381 if (!root || !root->firstChild()) 382 if (!root || !root->firstChild())
382 return false; 383 return false;
383 384
384 if (root->firstChild() == root->lastChild() && root->firstElementChild() && root->firstElementChild()->hasTagName(brTag)) { 385 if (root->firstChild() == root->lastChild()) {
385 // If there is a single child and it could be a placeholder, leave it al one. 386 Element* firstElementChild = ElementTraversal::firstWithin(*root);
386 if (root->renderer() && root->renderer()->isRenderBlockFlow()) 387 if (firstElementChild && firstElementChild->hasTagName(brTag)) {
387 return false; 388 // If there is a single child and it could be a placeholder, leave i t alone.
389 if (root->renderer() && root->renderer()->isRenderBlockFlow())
390 return false;
391 }
388 } 392 }
389 393
390 while (Node* child = root->firstChild()) 394 while (Node* child = root->firstChild())
391 removeNode(child); 395 removeNode(child);
392 396
393 addBlockPlaceholderIfNeeded(root); 397 addBlockPlaceholderIfNeeded(root);
394 setEndingSelection(VisibleSelection(firstPositionInNode(root), DOWNSTREAM, e ndingSelection().isDirectional())); 398 setEndingSelection(VisibleSelection(firstPositionInNode(root), DOWNSTREAM, e ndingSelection().isDirectional()));
395 399
396 return true; 400 return true;
397 } 401 }
(...skipping 216 matching lines...) Expand 10 before | Expand all | Expand 10 after
614 ASSERT_NOT_REACHED(); 618 ASSERT_NOT_REACHED();
615 m_preservesTypingStyle = false; 619 m_preservesTypingStyle = false;
616 } 620 }
617 621
618 bool TypingCommand::isTypingCommand() const 622 bool TypingCommand::isTypingCommand() const
619 { 623 {
620 return true; 624 return true;
621 } 625 }
622 626
623 } // namespace WebCore 627 } // namespace WebCore
OLDNEW
« no previous file with comments | « Source/core/dom/ParentNode.h ('k') | Source/core/svg/SVGPatternElement.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698