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

Side by Side Diff: Source/core/editing/EditorCommand.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/Editor.cpp ('k') | Source/core/editing/FormatBlockCommand.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, 2007, 2008 Apple Inc. All rights reserved. 2 * Copyright (C) 2006, 2007, 2008 Apple Inc. All rights reserved.
3 * Copyright (C) 2008 Nokia Corporation and/or its subsidiary(-ies) 3 * Copyright (C) 2008 Nokia Corporation and/or its subsidiary(-ies)
4 * Copyright (C) 2009 Igalia S.L. 4 * Copyright (C) 2009 Igalia S.L.
5 * 5 *
6 * Redistribution and use in source and binary forms, with or without 6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions 7 * modification, are permitted provided that the following conditions
8 * are met: 8 * are met:
9 * 1. Redistributions of source code must retain the above copyright 9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer. 10 * notice, this list of conditions and the following disclaimer.
(...skipping 174 matching lines...) Expand 10 before | Expand all | Expand 10 after
185 case CommandFromDOMWithUserInterface: 185 case CommandFromDOMWithUserInterface:
186 frame.editor().applyParagraphStyle(style.get()); 186 frame.editor().applyParagraphStyle(style.get());
187 return true; 187 return true;
188 } 188 }
189 ASSERT_NOT_REACHED(); 189 ASSERT_NOT_REACHED();
190 return false; 190 return false;
191 } 191 }
192 192
193 static bool executeInsertFragment(Frame& frame, PassRefPtr<DocumentFragment> fra gment) 193 static bool executeInsertFragment(Frame& frame, PassRefPtr<DocumentFragment> fra gment)
194 { 194 {
195 applyCommand(ReplaceSelectionCommand::create(frame.document(), fragment, Rep laceSelectionCommand::PreventNesting, EditActionUnspecified)); 195 ASSERT(frame.document());
196 applyCommand(ReplaceSelectionCommand::create(*frame.document(), fragment, Re placeSelectionCommand::PreventNesting, EditActionUnspecified));
196 return true; 197 return true;
197 } 198 }
198 199
199 static bool executeInsertNode(Frame& frame, PassRefPtr<Node> content) 200 static bool executeInsertNode(Frame& frame, PassRefPtr<Node> content)
200 { 201 {
201 RefPtr<DocumentFragment> fragment = DocumentFragment::create(frame.document( )); 202 RefPtr<DocumentFragment> fragment = DocumentFragment::create(frame.document( ));
202 TrackExceptionState es; 203 TrackExceptionState es;
203 fragment->appendChild(content, es); 204 fragment->appendChild(content, es);
204 if (es.hadException()) 205 if (es.hadException())
205 return false; 206 return false;
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after
282 { 283 {
283 frame.editor().copy(); 284 frame.editor().copy();
284 return true; 285 return true;
285 } 286 }
286 287
287 static bool executeCreateLink(Frame& frame, Event*, EditorCommandSource, const S tring& value) 288 static bool executeCreateLink(Frame& frame, Event*, EditorCommandSource, const S tring& value)
288 { 289 {
289 // FIXME: If userInterface is true, we should display a dialog box to let th e user enter a URL. 290 // FIXME: If userInterface is true, we should display a dialog box to let th e user enter a URL.
290 if (value.isEmpty()) 291 if (value.isEmpty())
291 return false; 292 return false;
292 applyCommand(CreateLinkCommand::create(frame.document(), value)); 293 ASSERT(frame.document());
294 applyCommand(CreateLinkCommand::create(*frame.document(), value));
293 return true; 295 return true;
294 } 296 }
295 297
296 static bool executeCut(Frame& frame, Event*, EditorCommandSource source, const S tring&) 298 static bool executeCut(Frame& frame, Event*, EditorCommandSource source, const S tring&)
297 { 299 {
298 if (source == CommandFromMenuOrKeyBinding) { 300 if (source == CommandFromMenuOrKeyBinding) {
299 UserTypingGestureIndicator typingGestureIndicator(&frame); 301 UserTypingGestureIndicator typingGestureIndicator(&frame);
300 frame.editor().cut(); 302 frame.editor().cut();
301 } else { 303 } else {
302 frame.editor().cut(); 304 frame.editor().cut();
(...skipping 17 matching lines...) Expand all
320 case CommandFromMenuOrKeyBinding: { 322 case CommandFromMenuOrKeyBinding: {
321 // Doesn't modify the text if the current selection isn't a range. 323 // Doesn't modify the text if the current selection isn't a range.
322 UserTypingGestureIndicator typingGestureIndicator(&frame); 324 UserTypingGestureIndicator typingGestureIndicator(&frame);
323 frame.editor().performDelete(); 325 frame.editor().performDelete();
324 return true; 326 return true;
325 } 327 }
326 case CommandFromDOM: 328 case CommandFromDOM:
327 case CommandFromDOMWithUserInterface: 329 case CommandFromDOMWithUserInterface:
328 // If the current selection is a caret, delete the preceding character. IE performs forwardDelete, but we currently side with Firefox. 330 // If the current selection is a caret, delete the preceding character. IE performs forwardDelete, but we currently side with Firefox.
329 // Doesn't scroll to make the selection visible, or modify the kill ring (this time, siding with IE, not Firefox). 331 // Doesn't scroll to make the selection visible, or modify the kill ring (this time, siding with IE, not Firefox).
330 TypingCommand::deleteKeyPressed(frame.document(), frame.selection()->gra nularity() == WordGranularity ? TypingCommand::SmartDelete : 0); 332 ASSERT(frame.document());
333 TypingCommand::deleteKeyPressed(*frame.document(), frame.selection()->gr anularity() == WordGranularity ? TypingCommand::SmartDelete : 0);
331 return true; 334 return true;
332 } 335 }
333 ASSERT_NOT_REACHED(); 336 ASSERT_NOT_REACHED();
334 return false; 337 return false;
335 } 338 }
336 339
337 static bool executeDeleteBackward(Frame& frame, Event*, EditorCommandSource, con st String&) 340 static bool executeDeleteBackward(Frame& frame, Event*, EditorCommandSource, con st String&)
338 { 341 {
339 frame.editor().deleteWithDirection(DirectionBackward, CharacterGranularity, false, true); 342 frame.editor().deleteWithDirection(DirectionBackward, CharacterGranularity, false, true);
340 return true; 343 return true;
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after
440 { 443 {
441 String tagName = value.lower(); 444 String tagName = value.lower();
442 if (tagName[0] == '<' && tagName[tagName.length() - 1] == '>') 445 if (tagName[0] == '<' && tagName[tagName.length() - 1] == '>')
443 tagName = tagName.substring(1, tagName.length() - 2); 446 tagName = tagName.substring(1, tagName.length() - 2);
444 447
445 String localName, prefix; 448 String localName, prefix;
446 if (!Document::parseQualifiedName(tagName, prefix, localName, IGNORE_EXCEPTI ON)) 449 if (!Document::parseQualifiedName(tagName, prefix, localName, IGNORE_EXCEPTI ON))
447 return false; 450 return false;
448 QualifiedName qualifiedTagName(prefix, localName, xhtmlNamespaceURI); 451 QualifiedName qualifiedTagName(prefix, localName, xhtmlNamespaceURI);
449 452
450 RefPtr<FormatBlockCommand> command = FormatBlockCommand::create(frame.docume nt(), qualifiedTagName); 453 ASSERT(frame.document());
454 RefPtr<FormatBlockCommand> command = FormatBlockCommand::create(*frame.docum ent(), qualifiedTagName);
451 applyCommand(command); 455 applyCommand(command);
452 return command->didApply(); 456 return command->didApply();
453 } 457 }
454 458
455 static bool executeForwardDelete(Frame& frame, Event*, EditorCommandSource sourc e, const String&) 459 static bool executeForwardDelete(Frame& frame, Event*, EditorCommandSource sourc e, const String&)
456 { 460 {
457 switch (source) { 461 switch (source) {
458 case CommandFromMenuOrKeyBinding: 462 case CommandFromMenuOrKeyBinding:
459 frame.editor().deleteWithDirection(DirectionForward, CharacterGranularit y, false, true); 463 frame.editor().deleteWithDirection(DirectionForward, CharacterGranularit y, false, true);
460 return true; 464 return true;
461 case CommandFromDOM: 465 case CommandFromDOM:
462 case CommandFromDOMWithUserInterface: 466 case CommandFromDOMWithUserInterface:
463 // Doesn't scroll to make the selection visible, or modify the kill ring . 467 // Doesn't scroll to make the selection visible, or modify the kill ring .
464 // ForwardDelete is not implemented in IE or Firefox, so this behavior i s only needed for 468 // ForwardDelete is not implemented in IE or Firefox, so this behavior i s only needed for
465 // backward compatibility with ourselves, and for consistency with Delet e. 469 // backward compatibility with ourselves, and for consistency with Delet e.
466 TypingCommand::forwardDeleteKeyPressed(frame.document()); 470 ASSERT(frame.document());
471 TypingCommand::forwardDeleteKeyPressed(*frame.document());
467 return true; 472 return true;
468 } 473 }
469 ASSERT_NOT_REACHED(); 474 ASSERT_NOT_REACHED();
470 return false; 475 return false;
471 } 476 }
472 477
473 static bool executeIgnoreSpelling(Frame& frame, Event*, EditorCommandSource, con st String&) 478 static bool executeIgnoreSpelling(Frame& frame, Event*, EditorCommandSource, con st String&)
474 { 479 {
475 frame.editor().ignoreSpelling(); 480 frame.editor().ignoreSpelling();
476 return true; 481 return true;
477 } 482 }
478 483
479 static bool executeIndent(Frame& frame, Event*, EditorCommandSource, const Strin g&) 484 static bool executeIndent(Frame& frame, Event*, EditorCommandSource, const Strin g&)
480 { 485 {
481 applyCommand(IndentOutdentCommand::create(frame.document(), IndentOutdentCom mand::Indent)); 486 ASSERT(frame.document());
487 applyCommand(IndentOutdentCommand::create(*frame.document(), IndentOutdentCo mmand::Indent));
482 return true; 488 return true;
483 } 489 }
484 490
485 static bool executeInsertBacktab(Frame& frame, Event* event, EditorCommandSource , const String&) 491 static bool executeInsertBacktab(Frame& frame, Event* event, EditorCommandSource , const String&)
486 { 492 {
487 return targetFrame(frame, event)->eventHandler()->handleTextInputEvent("\t", event, TextEventInputBackTab); 493 return targetFrame(frame, event)->eventHandler()->handleTextInputEvent("\t", event, TextEventInputBackTab);
488 } 494 }
489 495
490 static bool executeInsertHorizontalRule(Frame& frame, Event*, EditorCommandSourc e, const String& value) 496 static bool executeInsertHorizontalRule(Frame& frame, Event*, EditorCommandSourc e, const String& value)
491 { 497 {
(...skipping 19 matching lines...) Expand all
511 static bool executeInsertLineBreak(Frame& frame, Event* event, EditorCommandSour ce source, const String&) 517 static bool executeInsertLineBreak(Frame& frame, Event* event, EditorCommandSour ce source, const String&)
512 { 518 {
513 switch (source) { 519 switch (source) {
514 case CommandFromMenuOrKeyBinding: 520 case CommandFromMenuOrKeyBinding:
515 return targetFrame(frame, event)->eventHandler()->handleTextInputEvent(" \n", event, TextEventInputLineBreak); 521 return targetFrame(frame, event)->eventHandler()->handleTextInputEvent(" \n", event, TextEventInputLineBreak);
516 case CommandFromDOM: 522 case CommandFromDOM:
517 case CommandFromDOMWithUserInterface: 523 case CommandFromDOMWithUserInterface:
518 // Doesn't scroll to make the selection visible, or modify the kill ring . 524 // Doesn't scroll to make the selection visible, or modify the kill ring .
519 // InsertLineBreak is not implemented in IE or Firefox, so this behavior is only needed for 525 // InsertLineBreak is not implemented in IE or Firefox, so this behavior is only needed for
520 // backward compatibility with ourselves, and for consistency with other commands. 526 // backward compatibility with ourselves, and for consistency with other commands.
521 TypingCommand::insertLineBreak(frame.document(), 0); 527 ASSERT(frame.document());
528 TypingCommand::insertLineBreak(*frame.document(), 0);
522 return true; 529 return true;
523 } 530 }
524 ASSERT_NOT_REACHED(); 531 ASSERT_NOT_REACHED();
525 return false; 532 return false;
526 } 533 }
527 534
528 static bool executeInsertNewline(Frame& frame, Event* event, EditorCommandSource , const String&) 535 static bool executeInsertNewline(Frame& frame, Event* event, EditorCommandSource , const String&)
529 { 536 {
530 Frame* targetFrame = WebCore::targetFrame(frame, event); 537 Frame* targetFrame = WebCore::targetFrame(frame, event);
531 return targetFrame->eventHandler()->handleTextInputEvent("\n", event, target Frame->editor().canEditRichly() ? TextEventInputKeyboard : TextEventInputLineBre ak); 538 return targetFrame->eventHandler()->handleTextInputEvent("\n", event, target Frame->editor().canEditRichly() ? TextEventInputKeyboard : TextEventInputLineBre ak);
532 } 539 }
533 540
534 static bool executeInsertNewlineInQuotedContent(Frame& frame, Event*, EditorComm andSource, const String&) 541 static bool executeInsertNewlineInQuotedContent(Frame& frame, Event*, EditorComm andSource, const String&)
535 { 542 {
536 TypingCommand::insertParagraphSeparatorInQuotedContent(frame.document()); 543 ASSERT(frame.document());
544 TypingCommand::insertParagraphSeparatorInQuotedContent(*frame.document());
537 return true; 545 return true;
538 } 546 }
539 547
540 static bool executeInsertOrderedList(Frame& frame, Event*, EditorCommandSource, const String&) 548 static bool executeInsertOrderedList(Frame& frame, Event*, EditorCommandSource, const String&)
541 { 549 {
542 applyCommand(InsertListCommand::create(frame.document(), InsertListCommand:: OrderedList)); 550 ASSERT(frame.document());
551 applyCommand(InsertListCommand::create(*frame.document(), InsertListCommand: :OrderedList));
543 return true; 552 return true;
544 } 553 }
545 554
546 static bool executeInsertParagraph(Frame& frame, Event*, EditorCommandSource, co nst String&) 555 static bool executeInsertParagraph(Frame& frame, Event*, EditorCommandSource, co nst String&)
547 { 556 {
548 TypingCommand::insertParagraphSeparator(frame.document(), 0); 557 ASSERT(frame.document());
558 TypingCommand::insertParagraphSeparator(*frame.document(), 0);
549 return true; 559 return true;
550 } 560 }
551 561
552 static bool executeInsertTab(Frame& frame, Event* event, EditorCommandSource, co nst String&) 562 static bool executeInsertTab(Frame& frame, Event* event, EditorCommandSource, co nst String&)
553 { 563 {
554 return targetFrame(frame, event)->eventHandler()->handleTextInputEvent("\t", event); 564 return targetFrame(frame, event)->eventHandler()->handleTextInputEvent("\t", event);
555 } 565 }
556 566
557 static bool executeInsertText(Frame& frame, Event*, EditorCommandSource, const S tring& value) 567 static bool executeInsertText(Frame& frame, Event*, EditorCommandSource, const S tring& value)
558 { 568 {
559 TypingCommand::insertText(frame.document(), value, 0); 569 ASSERT(frame.document());
570 TypingCommand::insertText(*frame.document(), value, 0);
560 return true; 571 return true;
561 } 572 }
562 573
563 static bool executeInsertUnorderedList(Frame& frame, Event*, EditorCommandSource , const String&) 574 static bool executeInsertUnorderedList(Frame& frame, Event*, EditorCommandSource , const String&)
564 { 575 {
565 applyCommand(InsertListCommand::create(frame.document(), InsertListCommand:: UnorderedList)); 576 ASSERT(frame.document());
577 applyCommand(InsertListCommand::create(*frame.document(), InsertListCommand: :UnorderedList));
566 return true; 578 return true;
567 } 579 }
568 580
569 static bool executeJustifyCenter(Frame& frame, Event*, EditorCommandSource sourc e, const String&) 581 static bool executeJustifyCenter(Frame& frame, Event*, EditorCommandSource sourc e, const String&)
570 { 582 {
571 return executeApplyParagraphStyle(frame, source, EditActionCenter, CSSProper tyTextAlign, "center"); 583 return executeApplyParagraphStyle(frame, source, EditActionCenter, CSSProper tyTextAlign, "center");
572 } 584 }
573 585
574 static bool executeJustifyFull(Frame& frame, Event*, EditorCommandSource source, const String&) 586 static bool executeJustifyFull(Frame& frame, Event*, EditorCommandSource source, const String&)
575 { 587 {
(...skipping 327 matching lines...) Expand 10 before | Expand all | Expand 10 after
903 } 915 }
904 916
905 static bool executeMoveToRightEndOfLineAndModifySelection(Frame& frame, Event*, EditorCommandSource, const String&) 917 static bool executeMoveToRightEndOfLineAndModifySelection(Frame& frame, Event*, EditorCommandSource, const String&)
906 { 918 {
907 frame.selection()->modify(FrameSelection::AlterationExtend, DirectionRight, LineBoundary, UserTriggered); 919 frame.selection()->modify(FrameSelection::AlterationExtend, DirectionRight, LineBoundary, UserTriggered);
908 return true; 920 return true;
909 } 921 }
910 922
911 static bool executeOutdent(Frame& frame, Event*, EditorCommandSource, const Stri ng&) 923 static bool executeOutdent(Frame& frame, Event*, EditorCommandSource, const Stri ng&)
912 { 924 {
913 applyCommand(IndentOutdentCommand::create(frame.document(), IndentOutdentCom mand::Outdent)); 925 ASSERT(frame.document());
926 applyCommand(IndentOutdentCommand::create(*frame.document(), IndentOutdentCo mmand::Outdent));
914 return true; 927 return true;
915 } 928 }
916 929
917 static bool executeToggleOverwrite(Frame& frame, Event*, EditorCommandSource, co nst String&) 930 static bool executeToggleOverwrite(Frame& frame, Event*, EditorCommandSource, co nst String&)
918 { 931 {
919 frame.editor().toggleOverwriteModeEnabled(); 932 frame.editor().toggleOverwriteModeEnabled();
920 return true; 933 return true;
921 } 934 }
922 935
923 static bool executePaste(Frame& frame, Event*, EditorCommandSource source, const String&) 936 static bool executePaste(Frame& frame, Event*, EditorCommandSource source, const String&)
(...skipping 202 matching lines...) Expand 10 before | Expand all | Expand 10 after
1126 } 1139 }
1127 1140
1128 static bool executeUndo(Frame& frame, Event*, EditorCommandSource, const String& ) 1141 static bool executeUndo(Frame& frame, Event*, EditorCommandSource, const String& )
1129 { 1142 {
1130 frame.editor().undo(); 1143 frame.editor().undo();
1131 return true; 1144 return true;
1132 } 1145 }
1133 1146
1134 static bool executeUnlink(Frame& frame, Event*, EditorCommandSource, const Strin g&) 1147 static bool executeUnlink(Frame& frame, Event*, EditorCommandSource, const Strin g&)
1135 { 1148 {
1136 applyCommand(UnlinkCommand::create(frame.document())); 1149 ASSERT(frame.document());
1150 applyCommand(UnlinkCommand::create(*frame.document()));
1137 return true; 1151 return true;
1138 } 1152 }
1139 1153
1140 static bool executeUnscript(Frame& frame, Event*, EditorCommandSource source, co nst String&) 1154 static bool executeUnscript(Frame& frame, Event*, EditorCommandSource source, co nst String&)
1141 { 1155 {
1142 return executeApplyStyle(frame, source, EditActionUnscript, CSSPropertyVerti calAlign, "baseline"); 1156 return executeApplyStyle(frame, source, EditActionUnscript, CSSPropertyVerti calAlign, "baseline");
1143 } 1157 }
1144 1158
1145 static bool executeUnselect(Frame& frame, Event*, EditorCommandSource, const Str ing&) 1159 static bool executeUnselect(Frame& frame, Event*, EditorCommandSource, const Str ing&)
1146 { 1160 {
(...skipping 595 matching lines...) Expand 10 before | Expand all | Expand 10 after
1742 return m_command->state(*m_frame, triggeringEvent) == TrueTriState ? "tr ue" : "false"; 1756 return m_command->state(*m_frame, triggeringEvent) == TrueTriState ? "tr ue" : "false";
1743 return m_command->value(*m_frame, triggeringEvent); 1757 return m_command->value(*m_frame, triggeringEvent);
1744 } 1758 }
1745 1759
1746 bool Editor::Command::isTextInsertion() const 1760 bool Editor::Command::isTextInsertion() const
1747 { 1761 {
1748 return m_command && m_command->isTextInsertion; 1762 return m_command && m_command->isTextInsertion;
1749 } 1763 }
1750 1764
1751 } // namespace WebCore 1765 } // namespace WebCore
OLDNEW
« no previous file with comments | « Source/core/editing/Editor.cpp ('k') | Source/core/editing/FormatBlockCommand.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698