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

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

Issue 23822003: Have EditCommand classes deal with Document references, not pointers (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Created 7 years, 3 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 | Annotate | Revision Log
« no previous file with comments | « Source/core/editing/FormatBlockCommand.h ('k') | Source/core/editing/IndentOutdentCommand.h » ('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) 2006 Apple Computer, Inc. All rights reserved. 2 * Copyright (C) 2006 Apple Computer, 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 26 matching lines...) Expand all
37 37
38 using namespace HTMLNames; 38 using namespace HTMLNames;
39 39
40 static Node* enclosingBlockToSplitTreeTo(Node* startNode); 40 static Node* enclosingBlockToSplitTreeTo(Node* startNode);
41 static bool isElementForFormatBlock(const QualifiedName& tagName); 41 static bool isElementForFormatBlock(const QualifiedName& tagName);
42 static inline bool isElementForFormatBlock(Node* node) 42 static inline bool isElementForFormatBlock(Node* node)
43 { 43 {
44 return node->isElementNode() && isElementForFormatBlock(toElement(node)->tag QName()); 44 return node->isElementNode() && isElementForFormatBlock(toElement(node)->tag QName());
45 } 45 }
46 46
47 FormatBlockCommand::FormatBlockCommand(Document* document, const QualifiedName& tagName) 47 FormatBlockCommand::FormatBlockCommand(Document& document, const QualifiedName& tagName)
48 : ApplyBlockElementCommand(document, tagName) 48 : ApplyBlockElementCommand(document, tagName)
49 , m_didApply(false) 49 , m_didApply(false)
50 { 50 {
51 } 51 }
52 52
53 void FormatBlockCommand::formatSelection(const VisiblePosition& startOfSelection , const VisiblePosition& endOfSelection) 53 void FormatBlockCommand::formatSelection(const VisiblePosition& startOfSelection , const VisiblePosition& endOfSelection)
54 { 54 {
55 if (!isElementForFormatBlock(tagName())) 55 if (!isElementForFormatBlock(tagName()))
56 return; 56 return;
57 ApplyBlockElementCommand::formatSelection(startOfSelection, endOfSelection); 57 ApplyBlockElementCommand::formatSelection(startOfSelection, endOfSelection);
58 m_didApply = true; 58 m_didApply = true;
59 } 59 }
60 60
61 void FormatBlockCommand::formatRange(const Position& start, const Position& end, const Position& endOfSelection, RefPtr<Element>& blockNode) 61 void FormatBlockCommand::formatRange(const Position& start, const Position& end, const Position& endOfSelection, RefPtr<Element>& blockNode)
62 { 62 {
63 Node* nodeToSplitTo = enclosingBlockToSplitTreeTo(start.deprecatedNode()); 63 Node* nodeToSplitTo = enclosingBlockToSplitTreeTo(start.deprecatedNode());
64 RefPtr<Node> outerBlock = (start.deprecatedNode() == nodeToSplitTo) ? start. deprecatedNode() : splitTreeToNode(start.deprecatedNode(), nodeToSplitTo); 64 RefPtr<Node> outerBlock = (start.deprecatedNode() == nodeToSplitTo) ? start. deprecatedNode() : splitTreeToNode(start.deprecatedNode(), nodeToSplitTo);
65 RefPtr<Node> nodeAfterInsertionPosition = outerBlock; 65 RefPtr<Node> nodeAfterInsertionPosition = outerBlock;
66 66
67 RefPtr<Range> range = Range::create(document(), start, endOfSelection); 67 RefPtr<Range> range = Range::create(&document(), start, endOfSelection);
68 Element* refNode = enclosingBlockFlowElement(end); 68 Element* refNode = enclosingBlockFlowElement(end);
69 Element* root = editableRootForPosition(start); 69 Element* root = editableRootForPosition(start);
70 // Root is null for elements with contenteditable=false. 70 // Root is null for elements with contenteditable=false.
71 if (!root || !refNode) 71 if (!root || !refNode)
72 return; 72 return;
73 if (isElementForFormatBlock(refNode->tagQName()) && start == startOfBlock(st art) 73 if (isElementForFormatBlock(refNode->tagQName()) && start == startOfBlock(st art)
74 && (end == endOfBlock(end) || isNodeVisiblyContainedWithin(refNode, rang e.get())) 74 && (end == endOfBlock(end) || isNodeVisiblyContainedWithin(refNode, rang e.get()))
75 && refNode != root && !root->isDescendantOf(refNode)) { 75 && refNode != root && !root->isDescendantOf(refNode)) {
76 // Already in a block element that only contains the current paragraph 76 // Already in a block element that only contains the current paragraph
77 if (refNode->hasTagName(tagName())) 77 if (refNode->hasTagName(tagName()))
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after
154 return n; 154 return n;
155 if (isBlock(n)) 155 if (isBlock(n))
156 lastBlock = n; 156 lastBlock = n;
157 if (isListElement(n)) 157 if (isListElement(n))
158 return n->parentNode()->rendererIsEditable() ? n->parentNode() : n; 158 return n->parentNode()->rendererIsEditable() ? n->parentNode() : n;
159 } 159 }
160 return lastBlock; 160 return lastBlock;
161 } 161 }
162 162
163 } 163 }
OLDNEW
« no previous file with comments | « Source/core/editing/FormatBlockCommand.h ('k') | Source/core/editing/IndentOutdentCommand.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698