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

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

Issue 2627103003: [EditCommandSource] Pass source through |CompositeEditCommand| ctor instead of |apply(source)| (Closed)
Patch Set: Created 3 years, 11 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
1 /* 1 /*
2 * Copyright (C) 2006, 2008 Apple Inc. All rights reserved. 2 * Copyright (C) 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 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
48 if (!node->layoutObject() || !node->layoutObject()->isLayoutBlock()) 48 if (!node->layoutObject() || !node->layoutObject()->isLayoutBlock())
49 return false; 49 return false;
50 const HTMLElement& element = toHTMLElement(*node); 50 const HTMLElement& element = toHTMLElement(*node);
51 // TODO(yosin): We should check OL/UL element has "list-style-type" CSS 51 // TODO(yosin): We should check OL/UL element has "list-style-type" CSS
52 // property to make sure they layout contents as list. 52 // property to make sure they layout contents as list.
53 return isHTMLUListElement(element) || isHTMLOListElement(element) || 53 return isHTMLUListElement(element) || isHTMLOListElement(element) ||
54 element.hasTagName(blockquoteTag); 54 element.hasTagName(blockquoteTag);
55 } 55 }
56 56
57 IndentOutdentCommand::IndentOutdentCommand(Document& document, 57 IndentOutdentCommand::IndentOutdentCommand(Document& document,
58 EditCommandSource source,
58 EIndentType typeOfAction) 59 EIndentType typeOfAction)
59 : ApplyBlockElementCommand( 60 : ApplyBlockElementCommand(
60 document, 61 document,
62 source,
61 blockquoteTag, 63 blockquoteTag,
62 "margin: 0 0 0 40px; border: none; padding: 0px;"), 64 "margin: 0 0 0 40px; border: none; padding: 0px;"),
63 m_typeOfAction(typeOfAction) {} 65 m_typeOfAction(typeOfAction) {}
64 66
65 bool IndentOutdentCommand::tryIndentingAsListItem(const Position& start, 67 bool IndentOutdentCommand::tryIndentingAsListItem(const Position& start,
66 const Position& end, 68 const Position& end,
67 EditingState* editingState) { 69 EditingState* editingState) {
68 // If our selection is not inside a list, bail out. 70 // If our selection is not inside a list, bail out.
69 Node* lastNodeInSelectedParagraph = start.anchorNode(); 71 Node* lastNodeInSelectedParagraph = start.anchorNode();
70 HTMLElement* listElement = enclosingList(lastNodeInSelectedParagraph); 72 HTMLElement* listElement = enclosingList(lastNodeInSelectedParagraph);
(...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after
203 HTMLElement* enclosingElement = toHTMLElement( 205 HTMLElement* enclosingElement = toHTMLElement(
204 enclosingNodeOfType(visibleStartOfParagraph.deepEquivalent(), 206 enclosingNodeOfType(visibleStartOfParagraph.deepEquivalent(),
205 &isHTMLListOrBlockquoteElement)); 207 &isHTMLListOrBlockquoteElement));
206 // We can't outdent if there is no place to go! 208 // We can't outdent if there is no place to go!
207 if (!enclosingElement || !hasEditableStyle(*enclosingElement->parentNode())) 209 if (!enclosingElement || !hasEditableStyle(*enclosingElement->parentNode()))
208 return; 210 return;
209 211
210 // Use InsertListCommand to remove the selection from the list 212 // Use InsertListCommand to remove the selection from the list
211 if (isHTMLOListElement(*enclosingElement)) { 213 if (isHTMLOListElement(*enclosingElement)) {
212 applyCommandToComposite( 214 applyCommandToComposite(
213 InsertListCommand::create(document(), InsertListCommand::OrderedList), 215 InsertListCommand::create(document(), EditCommandSource::kInternal,
216 InsertListCommand::OrderedList),
214 editingState); 217 editingState);
215 return; 218 return;
216 } 219 }
217 if (isHTMLUListElement(*enclosingElement)) { 220 if (isHTMLUListElement(*enclosingElement)) {
218 applyCommandToComposite( 221 applyCommandToComposite(
219 InsertListCommand::create(document(), InsertListCommand::UnorderedList), 222 InsertListCommand::create(document(), EditCommandSource::kInternal,
223 InsertListCommand::UnorderedList),
220 editingState); 224 editingState);
221 return; 225 return;
222 } 226 }
223 227
224 // The selection is inside a blockquote i.e. enclosingNode is a blockquote 228 // The selection is inside a blockquote i.e. enclosingNode is a blockquote
225 VisiblePosition positionInEnclosingBlock = 229 VisiblePosition positionInEnclosingBlock =
226 VisiblePosition::firstPositionInNode(enclosingElement); 230 VisiblePosition::firstPositionInNode(enclosingElement);
227 // If the blockquote is inline, the start of the enclosing block coincides 231 // If the blockquote is inline, the start of the enclosing block coincides
228 // with positionInEnclosingBlock. 232 // with positionInEnclosingBlock.
229 VisiblePosition startOfEnclosingBlock = 233 VisiblePosition startOfEnclosingBlock =
(...skipping 181 matching lines...) Expand 10 before | Expand all | Expand 10 after
411 else 415 else
412 indentIntoBlockquote(start, end, blockquoteForNextIndent, editingState); 416 indentIntoBlockquote(start, end, blockquoteForNextIndent, editingState);
413 } 417 }
414 418
415 InputEvent::InputType IndentOutdentCommand::inputType() const { 419 InputEvent::InputType IndentOutdentCommand::inputType() const {
416 return m_typeOfAction == Indent ? InputEvent::InputType::FormatIndent 420 return m_typeOfAction == Indent ? InputEvent::InputType::FormatIndent
417 : InputEvent::InputType::FormatOutdent; 421 : InputEvent::InputType::FormatOutdent;
418 } 422 }
419 423
420 } // namespace blink 424 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698