OLD | NEW |
1 /* | 1 /* |
2 * Copyright (C) 2006, 2007, 2008, 2011 Apple Inc. All rights reserved. | 2 * Copyright (C) 2006, 2007, 2008, 2011 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 * | 4 * |
5 * Redistribution and use in source and binary forms, with or without | 5 * Redistribution and use in source and binary forms, with or without |
6 * modification, are permitted provided that the following conditions | 6 * modification, are permitted provided that the following conditions |
7 * are met: | 7 * are met: |
8 * 1. Redistributions of source code must retain the above copyright | 8 * 1. Redistributions of source code must retain the above copyright |
9 * notice, this list of conditions and the following disclaimer. | 9 * notice, this list of conditions and the following disclaimer. |
10 * 2. Redistributions in binary form must reproduce the above copyright | 10 * 2. Redistributions in binary form must reproduce the above copyright |
(...skipping 284 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
295 return client().isSelectTrailingWhitespaceEnabled(); | 295 return client().isSelectTrailingWhitespaceEnabled(); |
296 } | 296 } |
297 | 297 |
298 bool Editor::deleteWithDirection(SelectionDirection direction, TextGranularity g
ranularity, bool killRing, bool isTypingAction) | 298 bool Editor::deleteWithDirection(SelectionDirection direction, TextGranularity g
ranularity, bool killRing, bool isTypingAction) |
299 { | 299 { |
300 if (!canEdit()) | 300 if (!canEdit()) |
301 return false; | 301 return false; |
302 | 302 |
303 if (m_frame->selection()->isRange()) { | 303 if (m_frame->selection()->isRange()) { |
304 if (isTypingAction) { | 304 if (isTypingAction) { |
305 TypingCommand::deleteKeyPressed(m_frame->document(), canSmartCopyOrD
elete() ? TypingCommand::SmartDelete : 0, granularity); | 305 ASSERT(m_frame->document()); |
| 306 TypingCommand::deleteKeyPressed(*m_frame->document(), canSmartCopyOr
Delete() ? TypingCommand::SmartDelete : 0, granularity); |
306 revealSelectionAfterEditingOperation(); | 307 revealSelectionAfterEditingOperation(); |
307 } else { | 308 } else { |
308 if (killRing) | 309 if (killRing) |
309 addToKillRing(selectedRange().get(), false); | 310 addToKillRing(selectedRange().get(), false); |
310 deleteSelectionWithSmartDelete(canSmartCopyOrDelete()); | 311 deleteSelectionWithSmartDelete(canSmartCopyOrDelete()); |
311 // Implicitly calls revealSelectionAfterEditingOperation(). | 312 // Implicitly calls revealSelectionAfterEditingOperation(). |
312 } | 313 } |
313 } else { | 314 } else { |
314 TypingCommand::Options options = 0; | 315 TypingCommand::Options options = 0; |
315 if (canSmartCopyOrDelete()) | 316 if (canSmartCopyOrDelete()) |
316 options |= TypingCommand::SmartDelete; | 317 options |= TypingCommand::SmartDelete; |
317 if (killRing) | 318 if (killRing) |
318 options |= TypingCommand::KillRing; | 319 options |= TypingCommand::KillRing; |
319 switch (direction) { | 320 switch (direction) { |
320 case DirectionForward: | 321 case DirectionForward: |
321 case DirectionRight: | 322 case DirectionRight: |
322 TypingCommand::forwardDeleteKeyPressed(m_frame->document(), options,
granularity); | 323 ASSERT(m_frame->document()); |
| 324 TypingCommand::forwardDeleteKeyPressed(*m_frame->document(), options
, granularity); |
323 break; | 325 break; |
324 case DirectionBackward: | 326 case DirectionBackward: |
325 case DirectionLeft: | 327 case DirectionLeft: |
326 TypingCommand::deleteKeyPressed(m_frame->document(), options, granul
arity); | 328 ASSERT(m_frame->document()); |
| 329 TypingCommand::deleteKeyPressed(*m_frame->document(), options, granu
larity); |
327 break; | 330 break; |
328 } | 331 } |
329 revealSelectionAfterEditingOperation(); | 332 revealSelectionAfterEditingOperation(); |
330 } | 333 } |
331 | 334 |
332 // FIXME: We should to move this down into deleteKeyPressed. | 335 // FIXME: We should to move this down into deleteKeyPressed. |
333 // clear the "start new kill ring sequence" setting, because it was set to t
rue | 336 // clear the "start new kill ring sequence" setting, because it was set to t
rue |
334 // when the selection was updated by deleting the range | 337 // when the selection was updated by deleting the range |
335 if (killRing) | 338 if (killRing) |
336 setStartNewKillRingSequence(false); | 339 setStartNewKillRingSequence(false); |
337 | 340 |
338 return true; | 341 return true; |
339 } | 342 } |
340 | 343 |
341 void Editor::deleteSelectionWithSmartDelete(bool smartDelete) | 344 void Editor::deleteSelectionWithSmartDelete(bool smartDelete) |
342 { | 345 { |
343 if (m_frame->selection()->isNone()) | 346 if (m_frame->selection()->isNone()) |
344 return; | 347 return; |
345 | 348 |
346 applyCommand(DeleteSelectionCommand::create(m_frame->document(), smartDelete
)); | 349 ASSERT(m_frame->document()); |
| 350 applyCommand(DeleteSelectionCommand::create(*m_frame->document(), smartDelet
e)); |
347 } | 351 } |
348 | 352 |
349 void Editor::pasteAsPlainText(const String& pastingText, bool smartReplace) | 353 void Editor::pasteAsPlainText(const String& pastingText, bool smartReplace) |
350 { | 354 { |
351 Node* target = findEventTargetFromSelection(); | 355 Node* target = findEventTargetFromSelection(); |
352 if (!target) | 356 if (!target) |
353 return; | 357 return; |
354 target->dispatchEvent(TextEvent::createForPlainTextPaste(m_frame->domWindow(
), pastingText, smartReplace), IGNORE_EXCEPTION); | 358 target->dispatchEvent(TextEvent::createForPlainTextPaste(m_frame->domWindow(
), pastingText, smartReplace), IGNORE_EXCEPTION); |
355 } | 359 } |
356 | 360 |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
404 if (m_frame->selection()->isNone() || !m_frame->selection()->isContentEditab
le() || !fragment) | 408 if (m_frame->selection()->isNone() || !m_frame->selection()->isContentEditab
le() || !fragment) |
405 return; | 409 return; |
406 | 410 |
407 ReplaceSelectionCommand::CommandOptions options = ReplaceSelectionCommand::P
reventNesting | ReplaceSelectionCommand::SanitizeFragment; | 411 ReplaceSelectionCommand::CommandOptions options = ReplaceSelectionCommand::P
reventNesting | ReplaceSelectionCommand::SanitizeFragment; |
408 if (selectReplacement) | 412 if (selectReplacement) |
409 options |= ReplaceSelectionCommand::SelectReplacement; | 413 options |= ReplaceSelectionCommand::SelectReplacement; |
410 if (smartReplace) | 414 if (smartReplace) |
411 options |= ReplaceSelectionCommand::SmartReplace; | 415 options |= ReplaceSelectionCommand::SmartReplace; |
412 if (matchStyle) | 416 if (matchStyle) |
413 options |= ReplaceSelectionCommand::MatchStyle; | 417 options |= ReplaceSelectionCommand::MatchStyle; |
414 applyCommand(ReplaceSelectionCommand::create(m_frame->document(), fragment,
options, EditActionPaste)); | 418 ASSERT(m_frame->document()); |
| 419 applyCommand(ReplaceSelectionCommand::create(*m_frame->document(), fragment,
options, EditActionPaste)); |
415 revealSelectionAfterEditingOperation(); | 420 revealSelectionAfterEditingOperation(); |
416 | 421 |
417 if (m_frame->selection()->isInPasswordField() || !isContinuousSpellCheckingE
nabled()) | 422 if (m_frame->selection()->isInPasswordField() || !isContinuousSpellCheckingE
nabled()) |
418 return; | 423 return; |
419 Node* nodeToCheck = m_frame->selection()->rootEditableElement(); | 424 Node* nodeToCheck = m_frame->selection()->rootEditableElement(); |
420 if (!nodeToCheck) | 425 if (!nodeToCheck) |
421 return; | 426 return; |
422 | 427 |
423 RefPtr<Range> rangeToCheck = Range::create(m_frame->document(), firstPositio
nInNode(nodeToCheck), lastPositionInNode(nodeToCheck)); | 428 RefPtr<Range> rangeToCheck = Range::create(m_frame->document(), firstPositio
nInNode(nodeToCheck), lastPositionInNode(nodeToCheck)); |
424 m_spellCheckRequester->requestCheckingFor(SpellCheckRequest::create(resolveT
extCheckingTypeMask(TextCheckingTypeSpelling | TextCheckingTypeGrammar), TextChe
ckingProcessBatch, rangeToCheck, rangeToCheck)); | 429 m_spellCheckRequester->requestCheckingFor(SpellCheckRequest::create(resolveT
extCheckingTypeMask(TextCheckingTypeSpelling | TextCheckingTypeGrammar), TextChe
ckingProcessBatch, rangeToCheck, rangeToCheck)); |
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
519 } | 524 } |
520 | 525 |
521 return FalseTriState; | 526 return FalseTriState; |
522 } | 527 } |
523 | 528 |
524 PassRefPtr<Node> Editor::insertOrderedList() | 529 PassRefPtr<Node> Editor::insertOrderedList() |
525 { | 530 { |
526 if (!canEditRichly()) | 531 if (!canEditRichly()) |
527 return 0; | 532 return 0; |
528 | 533 |
529 RefPtr<Node> newList = InsertListCommand::insertList(m_frame->document(), In
sertListCommand::OrderedList); | 534 ASSERT(m_frame->document()); |
| 535 RefPtr<Node> newList = InsertListCommand::insertList(*m_frame->document(), I
nsertListCommand::OrderedList); |
530 revealSelectionAfterEditingOperation(); | 536 revealSelectionAfterEditingOperation(); |
531 return newList; | 537 return newList; |
532 } | 538 } |
533 | 539 |
534 PassRefPtr<Node> Editor::insertUnorderedList() | 540 PassRefPtr<Node> Editor::insertUnorderedList() |
535 { | 541 { |
536 if (!canEditRichly()) | 542 if (!canEditRichly()) |
537 return 0; | 543 return 0; |
538 | 544 |
539 RefPtr<Node> newList = InsertListCommand::insertList(m_frame->document(), In
sertListCommand::UnorderedList); | 545 ASSERT(m_frame->document()); |
| 546 RefPtr<Node> newList = InsertListCommand::insertList(*m_frame->document(), I
nsertListCommand::UnorderedList); |
540 revealSelectionAfterEditingOperation(); | 547 revealSelectionAfterEditingOperation(); |
541 return newList; | 548 return newList; |
542 } | 549 } |
543 | 550 |
544 bool Editor::canIncreaseSelectionListLevel() | 551 bool Editor::canIncreaseSelectionListLevel() |
545 { | 552 { |
546 return canEditRichly() && IncreaseSelectionListLevelCommand::canIncreaseSele
ctionListLevel(m_frame->document()); | 553 ASSERT(m_frame->document()); |
| 554 return canEditRichly() && IncreaseSelectionListLevelCommand::canIncreaseSele
ctionListLevel(*m_frame->document()); |
547 } | 555 } |
548 | 556 |
549 bool Editor::canDecreaseSelectionListLevel() | 557 bool Editor::canDecreaseSelectionListLevel() |
550 { | 558 { |
551 return canEditRichly() && DecreaseSelectionListLevelCommand::canDecreaseSele
ctionListLevel(m_frame->document()); | 559 ASSERT(m_frame->document()); |
| 560 return canEditRichly() && DecreaseSelectionListLevelCommand::canDecreaseSele
ctionListLevel(*m_frame->document()); |
552 } | 561 } |
553 | 562 |
554 PassRefPtr<Node> Editor::increaseSelectionListLevel() | 563 PassRefPtr<Node> Editor::increaseSelectionListLevel() |
555 { | 564 { |
556 if (!canEditRichly() || m_frame->selection()->isNone()) | 565 if (!canEditRichly() || m_frame->selection()->isNone()) |
557 return 0; | 566 return 0; |
558 | 567 |
559 RefPtr<Node> newList = IncreaseSelectionListLevelCommand::increaseSelectionL
istLevel(m_frame->document()); | 568 ASSERT(m_frame->document()); |
| 569 RefPtr<Node> newList = IncreaseSelectionListLevelCommand::increaseSelectionL
istLevel(*m_frame->document()); |
560 revealSelectionAfterEditingOperation(); | 570 revealSelectionAfterEditingOperation(); |
561 return newList; | 571 return newList; |
562 } | 572 } |
563 | 573 |
564 PassRefPtr<Node> Editor::increaseSelectionListLevelOrdered() | 574 PassRefPtr<Node> Editor::increaseSelectionListLevelOrdered() |
565 { | 575 { |
566 if (!canEditRichly() || m_frame->selection()->isNone()) | 576 if (!canEditRichly() || m_frame->selection()->isNone()) |
567 return 0; | 577 return 0; |
568 | 578 |
569 RefPtr<Node> newList = IncreaseSelectionListLevelCommand::increaseSelectionL
istLevelOrdered(m_frame->document()); | 579 ASSERT(m_frame->document()); |
| 580 RefPtr<Node> newList = IncreaseSelectionListLevelCommand::increaseSelectionL
istLevelOrdered(*m_frame->document()); |
570 revealSelectionAfterEditingOperation(); | 581 revealSelectionAfterEditingOperation(); |
571 return newList.release(); | 582 return newList.release(); |
572 } | 583 } |
573 | 584 |
574 PassRefPtr<Node> Editor::increaseSelectionListLevelUnordered() | 585 PassRefPtr<Node> Editor::increaseSelectionListLevelUnordered() |
575 { | 586 { |
576 if (!canEditRichly() || m_frame->selection()->isNone()) | 587 if (!canEditRichly() || m_frame->selection()->isNone()) |
577 return 0; | 588 return 0; |
578 | 589 |
579 RefPtr<Node> newList = IncreaseSelectionListLevelCommand::increaseSelectionL
istLevelUnordered(m_frame->document()); | 590 ASSERT(m_frame->document()); |
| 591 RefPtr<Node> newList = IncreaseSelectionListLevelCommand::increaseSelectionL
istLevelUnordered(*m_frame->document()); |
580 revealSelectionAfterEditingOperation(); | 592 revealSelectionAfterEditingOperation(); |
581 return newList.release(); | 593 return newList.release(); |
582 } | 594 } |
583 | 595 |
584 void Editor::decreaseSelectionListLevel() | 596 void Editor::decreaseSelectionListLevel() |
585 { | 597 { |
586 if (!canEditRichly() || m_frame->selection()->isNone()) | 598 if (!canEditRichly() || m_frame->selection()->isNone()) |
587 return; | 599 return; |
588 | 600 |
589 DecreaseSelectionListLevelCommand::decreaseSelectionListLevel(m_frame->docum
ent()); | 601 ASSERT(m_frame->document()); |
| 602 DecreaseSelectionListLevelCommand::decreaseSelectionListLevel(*m_frame->docu
ment()); |
590 revealSelectionAfterEditingOperation(); | 603 revealSelectionAfterEditingOperation(); |
591 } | 604 } |
592 | 605 |
593 void Editor::removeFormattingAndStyle() | 606 void Editor::removeFormattingAndStyle() |
594 { | 607 { |
595 applyCommand(RemoveFormatCommand::create(m_frame->document())); | 608 ASSERT(m_frame->document()); |
| 609 applyCommand(RemoveFormatCommand::create(*m_frame->document())); |
596 } | 610 } |
597 | 611 |
598 void Editor::clearLastEditCommand() | 612 void Editor::clearLastEditCommand() |
599 { | 613 { |
600 m_lastEditCommand.clear(); | 614 m_lastEditCommand.clear(); |
601 } | 615 } |
602 | 616 |
603 // Returns whether caller should continue with "the default processing", which i
s the same as | 617 // Returns whether caller should continue with "the default processing", which i
s the same as |
604 // the event handler NOT setting the return value to false | 618 // the event handler NOT setting the return value to false |
605 bool Editor::dispatchCPPEvent(const AtomicString &eventType, ClipboardAccessPoli
cy policy) | 619 bool Editor::dispatchCPPEvent(const AtomicString &eventType, ClipboardAccessPoli
cy policy) |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
641 void Editor::applyStyle(StylePropertySet* style, EditAction editingAction) | 655 void Editor::applyStyle(StylePropertySet* style, EditAction editingAction) |
642 { | 656 { |
643 switch (m_frame->selection()->selectionType()) { | 657 switch (m_frame->selection()->selectionType()) { |
644 case VisibleSelection::NoSelection: | 658 case VisibleSelection::NoSelection: |
645 // do nothing | 659 // do nothing |
646 break; | 660 break; |
647 case VisibleSelection::CaretSelection: | 661 case VisibleSelection::CaretSelection: |
648 computeAndSetTypingStyle(style, editingAction); | 662 computeAndSetTypingStyle(style, editingAction); |
649 break; | 663 break; |
650 case VisibleSelection::RangeSelection: | 664 case VisibleSelection::RangeSelection: |
651 if (style) | 665 if (style) { |
652 applyCommand(ApplyStyleCommand::create(m_frame->document(), EditingS
tyle::create(style).get(), editingAction)); | 666 ASSERT(m_frame->document()); |
| 667 applyCommand(ApplyStyleCommand::create(*m_frame->document(), Editing
Style::create(style).get(), editingAction)); |
| 668 } |
653 break; | 669 break; |
654 } | 670 } |
655 } | 671 } |
656 | 672 |
657 bool Editor::shouldApplyStyle(StylePropertySet* style, Range* range) | 673 bool Editor::shouldApplyStyle(StylePropertySet* style, Range* range) |
658 { | 674 { |
659 return client().shouldApplyStyle(style, range); | 675 return client().shouldApplyStyle(style, range); |
660 } | 676 } |
661 | 677 |
662 void Editor::applyParagraphStyle(StylePropertySet* style, EditAction editingActi
on) | 678 void Editor::applyParagraphStyle(StylePropertySet* style, EditAction editingActi
on) |
663 { | 679 { |
664 switch (m_frame->selection()->selectionType()) { | 680 switch (m_frame->selection()->selectionType()) { |
665 case VisibleSelection::NoSelection: | 681 case VisibleSelection::NoSelection: |
666 // do nothing | 682 // do nothing |
667 break; | 683 break; |
668 case VisibleSelection::CaretSelection: | 684 case VisibleSelection::CaretSelection: |
669 case VisibleSelection::RangeSelection: | 685 case VisibleSelection::RangeSelection: |
670 if (style) | 686 if (style) { |
671 applyCommand(ApplyStyleCommand::create(m_frame->document(), EditingS
tyle::create(style).get(), editingAction, ApplyStyleCommand::ForceBlockPropertie
s)); | 687 ASSERT(m_frame->document()); |
| 688 applyCommand(ApplyStyleCommand::create(*m_frame->document(), Editing
Style::create(style).get(), editingAction, ApplyStyleCommand::ForceBlockProperti
es)); |
| 689 } |
672 break; | 690 break; |
673 } | 691 } |
674 } | 692 } |
675 | 693 |
676 void Editor::applyStyleToSelection(StylePropertySet* style, EditAction editingAc
tion) | 694 void Editor::applyStyleToSelection(StylePropertySet* style, EditAction editingAc
tion) |
677 { | 695 { |
678 if (!style || style->isEmpty() || !canEditRichly()) | 696 if (!style || style->isEmpty() || !canEditRichly()) |
679 return; | 697 return; |
680 | 698 |
681 if (client().shouldApplyStyle(style, m_frame->selection()->toNormalizedRange
().get())) | 699 if (client().shouldApplyStyle(style, m_frame->selection()->toNormalizedRange
().get())) |
(...skipping 27 matching lines...) Expand all Loading... |
709 if (!selectionStyle || !selectionStyle->style()) | 727 if (!selectionStyle || !selectionStyle->style()) |
710 return String(); | 728 return String(); |
711 | 729 |
712 if (propertyID == CSSPropertyFontSize) | 730 if (propertyID == CSSPropertyFontSize) |
713 return String::number(selectionStyle->legacyFontSize(m_frame->document()
)); | 731 return String::number(selectionStyle->legacyFontSize(m_frame->document()
)); |
714 return selectionStyle->style()->getPropertyValue(propertyID); | 732 return selectionStyle->style()->getPropertyValue(propertyID); |
715 } | 733 } |
716 | 734 |
717 void Editor::indent() | 735 void Editor::indent() |
718 { | 736 { |
719 applyCommand(IndentOutdentCommand::create(m_frame->document(), IndentOutdent
Command::Indent)); | 737 ASSERT(m_frame->document()); |
| 738 applyCommand(IndentOutdentCommand::create(*m_frame->document(), IndentOutden
tCommand::Indent)); |
720 } | 739 } |
721 | 740 |
722 void Editor::outdent() | 741 void Editor::outdent() |
723 { | 742 { |
724 applyCommand(IndentOutdentCommand::create(m_frame->document(), IndentOutdent
Command::Outdent)); | 743 ASSERT(m_frame->document()); |
| 744 applyCommand(IndentOutdentCommand::create(*m_frame->document(), IndentOutden
tCommand::Outdent)); |
725 } | 745 } |
726 | 746 |
727 static void dispatchEditableContentChangedEvents(PassRefPtr<Element> startRoot,
PassRefPtr<Element> endRoot) | 747 static void dispatchEditableContentChangedEvents(PassRefPtr<Element> startRoot,
PassRefPtr<Element> endRoot) |
728 { | 748 { |
729 if (startRoot) | 749 if (startRoot) |
730 startRoot->dispatchEvent(Event::create(eventNames().webkitEditableConten
tChangedEvent), IGNORE_EXCEPTION); | 750 startRoot->dispatchEvent(Event::create(eventNames().webkitEditableConten
tChangedEvent), IGNORE_EXCEPTION); |
731 if (endRoot && endRoot != startRoot) | 751 if (endRoot && endRoot != startRoot) |
732 endRoot->dispatchEvent(Event::create(eventNames().webkitEditableContentC
hangedEvent), IGNORE_EXCEPTION); | 752 endRoot->dispatchEvent(Event::create(eventNames().webkitEditableContentC
hangedEvent), IGNORE_EXCEPTION); |
733 } | 753 } |
734 | 754 |
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
832 if (!text.isEmpty()) | 852 if (!text.isEmpty()) |
833 updateMarkersForWordsAffectedByEditing(isSpaceOrNewline(text[0])); | 853 updateMarkersForWordsAffectedByEditing(isSpaceOrNewline(text[0])); |
834 | 854 |
835 // Get the selection to use for the event that triggered this insertText. | 855 // Get the selection to use for the event that triggered this insertText. |
836 // If the event handler changed the selection, we may want to use a differen
t selection | 856 // If the event handler changed the selection, we may want to use a differen
t selection |
837 // that is contained in the event target. | 857 // that is contained in the event target. |
838 selection = selectionForCommand(triggeringEvent); | 858 selection = selectionForCommand(triggeringEvent); |
839 if (selection.isContentEditable()) { | 859 if (selection.isContentEditable()) { |
840 if (Node* selectionStart = selection.start().deprecatedNode()) { | 860 if (Node* selectionStart = selection.start().deprecatedNode()) { |
841 RefPtr<Document> document = &selectionStart->document(); | 861 RefPtr<Document> document = &selectionStart->document(); |
| 862 ASSERT(document); |
842 | 863 |
843 // Insert the text | 864 // Insert the text |
844 TypingCommand::Options options = 0; | 865 TypingCommand::Options options = 0; |
845 if (selectInsertedText) | 866 if (selectInsertedText) |
846 options |= TypingCommand::SelectInsertedText; | 867 options |= TypingCommand::SelectInsertedText; |
847 TypingCommand::insertText(document.get(), text, selection, options,
triggeringEvent && triggeringEvent->isComposition() ? TypingCommand::TextComposi
tionConfirm : TypingCommand::TextCompositionNone); | 868 TypingCommand::insertText(*document.get(), text, selection, options,
triggeringEvent && triggeringEvent->isComposition() ? TypingCommand::TextCompos
itionConfirm : TypingCommand::TextCompositionNone); |
848 | 869 |
849 // Reveal the current selection | 870 // Reveal the current selection |
850 if (Frame* editedFrame = document->frame()) { | 871 if (Frame* editedFrame = document->frame()) { |
851 if (Page* page = editedFrame->page()) | 872 if (Page* page = editedFrame->page()) |
852 page->focusController().focusedOrMainFrame()->selection()->r
evealSelection(ScrollAlignment::alignCenterIfNeeded); | 873 page->focusController().focusedOrMainFrame()->selection()->r
evealSelection(ScrollAlignment::alignCenterIfNeeded); |
853 } | 874 } |
854 } | 875 } |
855 } | 876 } |
856 | 877 |
857 return true; | 878 return true; |
858 } | 879 } |
859 | 880 |
860 bool Editor::insertLineBreak() | 881 bool Editor::insertLineBreak() |
861 { | 882 { |
862 if (!canEdit()) | 883 if (!canEdit()) |
863 return false; | 884 return false; |
864 | 885 |
865 if (!shouldInsertText("\n", m_frame->selection()->toNormalizedRange().get(),
EditorInsertActionTyped)) | 886 if (!shouldInsertText("\n", m_frame->selection()->toNormalizedRange().get(),
EditorInsertActionTyped)) |
866 return true; | 887 return true; |
867 | 888 |
868 VisiblePosition caret = m_frame->selection()->selection().visibleStart(); | 889 VisiblePosition caret = m_frame->selection()->selection().visibleStart(); |
869 bool alignToEdge = isEndOfEditableOrNonEditableContent(caret); | 890 bool alignToEdge = isEndOfEditableOrNonEditableContent(caret); |
870 TypingCommand::insertLineBreak(m_frame->document(), 0); | 891 ASSERT(m_frame->document()); |
| 892 TypingCommand::insertLineBreak(*m_frame->document(), 0); |
871 revealSelectionAfterEditingOperation(alignToEdge ? ScrollAlignment::alignToE
dgeIfNeeded : ScrollAlignment::alignCenterIfNeeded); | 893 revealSelectionAfterEditingOperation(alignToEdge ? ScrollAlignment::alignToE
dgeIfNeeded : ScrollAlignment::alignCenterIfNeeded); |
872 | 894 |
873 return true; | 895 return true; |
874 } | 896 } |
875 | 897 |
876 bool Editor::insertParagraphSeparator() | 898 bool Editor::insertParagraphSeparator() |
877 { | 899 { |
878 if (!canEdit()) | 900 if (!canEdit()) |
879 return false; | 901 return false; |
880 | 902 |
881 if (!canEditRichly()) | 903 if (!canEditRichly()) |
882 return insertLineBreak(); | 904 return insertLineBreak(); |
883 | 905 |
884 if (!shouldInsertText("\n", m_frame->selection()->toNormalizedRange().get(),
EditorInsertActionTyped)) | 906 if (!shouldInsertText("\n", m_frame->selection()->toNormalizedRange().get(),
EditorInsertActionTyped)) |
885 return true; | 907 return true; |
886 | 908 |
887 VisiblePosition caret = m_frame->selection()->selection().visibleStart(); | 909 VisiblePosition caret = m_frame->selection()->selection().visibleStart(); |
888 bool alignToEdge = isEndOfEditableOrNonEditableContent(caret); | 910 bool alignToEdge = isEndOfEditableOrNonEditableContent(caret); |
889 TypingCommand::insertParagraphSeparator(m_frame->document(), 0); | 911 ASSERT(m_frame->document()); |
| 912 TypingCommand::insertParagraphSeparator(*m_frame->document(), 0); |
890 revealSelectionAfterEditingOperation(alignToEdge ? ScrollAlignment::alignToE
dgeIfNeeded : ScrollAlignment::alignCenterIfNeeded); | 913 revealSelectionAfterEditingOperation(alignToEdge ? ScrollAlignment::alignToE
dgeIfNeeded : ScrollAlignment::alignCenterIfNeeded); |
891 | 914 |
892 return true; | 915 return true; |
893 } | 916 } |
894 | 917 |
895 void Editor::cut() | 918 void Editor::cut() |
896 { | 919 { |
897 if (tryDHTMLCut()) | 920 if (tryDHTMLCut()) |
898 return; // DHTML did the whole operation | 921 return; // DHTML did the whole operation |
899 if (!canCut()) { | 922 if (!canCut()) { |
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
984 if (&startNode->document() != &endNode->document()) | 1007 if (&startNode->document() != &endNode->document()) |
985 return; | 1008 return; |
986 // check if start node is before endNode | 1009 // check if start node is before endNode |
987 Node* node = startNode; | 1010 Node* node = startNode; |
988 while (node && node != endNode) | 1011 while (node && node != endNode) |
989 node = NodeTraversal::next(node); | 1012 node = NodeTraversal::next(node); |
990 if (!node) | 1013 if (!node) |
991 return; | 1014 return; |
992 } | 1015 } |
993 | 1016 |
994 applyCommand(SimplifyMarkupCommand::create(m_frame->document(), startNode, (
endNode) ? NodeTraversal::next(endNode) : 0)); | 1017 ASSERT(m_frame->document()); |
| 1018 applyCommand(SimplifyMarkupCommand::create(*m_frame->document(), startNode,
(endNode) ? NodeTraversal::next(endNode) : 0)); |
995 } | 1019 } |
996 | 1020 |
997 void Editor::copyURL(const KURL& url, const String& title) | 1021 void Editor::copyURL(const KURL& url, const String& title) |
998 { | 1022 { |
999 Pasteboard::generalPasteboard()->writeURL(url, title); | 1023 Pasteboard::generalPasteboard()->writeURL(url, title); |
1000 } | 1024 } |
1001 | 1025 |
1002 void Editor::copyImage(const HitTestResult& result) | 1026 void Editor::copyImage(const HitTestResult& result) |
1003 { | 1027 { |
1004 KURL url = result.absoluteLinkURL(); | 1028 KURL url = result.absoluteLinkURL(); |
(...skipping 881 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1886 if (m_frame->selection()->typingStyle()) { | 1910 if (m_frame->selection()->typingStyle()) { |
1887 typingStyle = m_frame->selection()->typingStyle()->copy(); | 1911 typingStyle = m_frame->selection()->typingStyle()->copy(); |
1888 typingStyle->overrideWithStyle(style); | 1912 typingStyle->overrideWithStyle(style); |
1889 } else | 1913 } else |
1890 typingStyle = EditingStyle::create(style); | 1914 typingStyle = EditingStyle::create(style); |
1891 | 1915 |
1892 typingStyle->prepareToApplyAt(m_frame->selection()->selection().visibleStart
().deepEquivalent(), EditingStyle::PreserveWritingDirection); | 1916 typingStyle->prepareToApplyAt(m_frame->selection()->selection().visibleStart
().deepEquivalent(), EditingStyle::PreserveWritingDirection); |
1893 | 1917 |
1894 // Handle block styles, substracting these from the typing style. | 1918 // Handle block styles, substracting these from the typing style. |
1895 RefPtr<EditingStyle> blockStyle = typingStyle->extractAndRemoveBlockProperti
es(); | 1919 RefPtr<EditingStyle> blockStyle = typingStyle->extractAndRemoveBlockProperti
es(); |
1896 if (!blockStyle->isEmpty()) | 1920 if (!blockStyle->isEmpty()) { |
1897 applyCommand(ApplyStyleCommand::create(m_frame->document(), blockStyle.g
et(), editingAction)); | 1921 ASSERT(m_frame->document()); |
| 1922 applyCommand(ApplyStyleCommand::create(*m_frame->document(), blockStyle.
get(), editingAction)); |
| 1923 } |
1898 | 1924 |
1899 // Set the remaining style as the typing style. | 1925 // Set the remaining style as the typing style. |
1900 m_frame->selection()->setTypingStyle(typingStyle); | 1926 m_frame->selection()->setTypingStyle(typingStyle); |
1901 } | 1927 } |
1902 | 1928 |
1903 void Editor::textAreaOrTextFieldDidBeginEditing(Element* e) | 1929 void Editor::textAreaOrTextFieldDidBeginEditing(Element* e) |
1904 { | 1930 { |
1905 elementDidBeginEditing(e); | 1931 elementDidBeginEditing(e); |
1906 } | 1932 } |
1907 | 1933 |
(...skipping 294 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2202 return WebCore::unifiedTextCheckerEnabled(m_frame); | 2228 return WebCore::unifiedTextCheckerEnabled(m_frame); |
2203 } | 2229 } |
2204 | 2230 |
2205 void Editor::toggleOverwriteModeEnabled() | 2231 void Editor::toggleOverwriteModeEnabled() |
2206 { | 2232 { |
2207 m_overwriteModeEnabled = !m_overwriteModeEnabled; | 2233 m_overwriteModeEnabled = !m_overwriteModeEnabled; |
2208 frame().selection()->setShouldShowBlockCursor(m_overwriteModeEnabled); | 2234 frame().selection()->setShouldShowBlockCursor(m_overwriteModeEnabled); |
2209 }; | 2235 }; |
2210 | 2236 |
2211 } // namespace WebCore | 2237 } // namespace WebCore |
OLD | NEW |