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 334 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
345 bool killRing, | 345 bool killRing, |
346 bool isTypingAction) { | 346 bool isTypingAction) { |
347 if (!canEdit()) | 347 if (!canEdit()) |
348 return false; | 348 return false; |
349 | 349 |
350 EditingState editingState; | 350 EditingState editingState; |
351 if (frame().selection().isRange()) { | 351 if (frame().selection().isRange()) { |
352 if (isTypingAction) { | 352 if (isTypingAction) { |
353 DCHECK(frame().document()); | 353 DCHECK(frame().document()); |
354 TypingCommand::deleteKeyPressed( | 354 TypingCommand::deleteKeyPressed( |
355 *frame().document(), source, | 355 *frame().document(), |
356 canSmartCopyOrDelete() ? TypingCommand::SmartDelete : 0, granularity); | 356 canSmartCopyOrDelete() ? TypingCommand::SmartDelete : 0, granularity); |
357 revealSelectionAfterEditingOperation(); | 357 revealSelectionAfterEditingOperation(); |
358 } else { | 358 } else { |
359 if (killRing) | 359 if (killRing) |
360 addToKillRing(selectedRange()); | 360 addToKillRing(selectedRange()); |
361 deleteSelectionWithSmartDelete( | 361 deleteSelectionWithSmartDelete( |
362 source, | 362 source, |
363 canSmartCopyOrDelete() ? DeleteMode::Smart : DeleteMode::Simple, | 363 canSmartCopyOrDelete() ? DeleteMode::Smart : DeleteMode::Simple, |
364 deletionInputTypeFromTextGranularity(direction, granularity)); | 364 deletionInputTypeFromTextGranularity(direction, granularity)); |
365 // Implicitly calls revealSelectionAfterEditingOperation(). | 365 // Implicitly calls revealSelectionAfterEditingOperation(). |
366 } | 366 } |
367 } else { | 367 } else { |
368 TypingCommand::Options options = 0; | 368 TypingCommand::Options options = 0; |
369 if (canSmartCopyOrDelete()) | 369 if (canSmartCopyOrDelete()) |
370 options |= TypingCommand::SmartDelete; | 370 options |= TypingCommand::SmartDelete; |
371 if (killRing) | 371 if (killRing) |
372 options |= TypingCommand::KillRing; | 372 options |= TypingCommand::KillRing; |
373 switch (direction) { | 373 switch (direction) { |
374 case DeleteDirection::Forward: | 374 case DeleteDirection::Forward: |
375 DCHECK(frame().document()); | 375 DCHECK(frame().document()); |
376 TypingCommand::forwardDeleteKeyPressed( | 376 TypingCommand::forwardDeleteKeyPressed( |
377 *frame().document(), source, &editingState, options, granularity); | 377 *frame().document(), &editingState, options, granularity); |
378 if (editingState.isAborted()) | 378 if (editingState.isAborted()) |
379 return false; | 379 return false; |
380 break; | 380 break; |
381 case DeleteDirection::Backward: | 381 case DeleteDirection::Backward: |
382 DCHECK(frame().document()); | 382 DCHECK(frame().document()); |
383 TypingCommand::deleteKeyPressed(*frame().document(), source, options, | 383 TypingCommand::deleteKeyPressed(*frame().document(), options, |
384 granularity); | 384 granularity); |
385 break; | 385 break; |
386 } | 386 } |
387 revealSelectionAfterEditingOperation(); | 387 revealSelectionAfterEditingOperation(); |
388 } | 388 } |
389 | 389 |
390 // FIXME: We should to move this down into deleteKeyPressed. | 390 // FIXME: We should to move this down into deleteKeyPressed. |
391 // clear the "start new kill ring sequence" setting, because it was set to | 391 // clear the "start new kill ring sequence" setting, because it was set to |
392 // true when the selection was updated by deleting the range | 392 // true when the selection was updated by deleting the range |
393 if (killRing) | 393 if (killRing) |
394 setStartNewKillRingSequence(false); | 394 setStartNewKillRingSequence(false); |
395 | 395 |
396 return true; | 396 return true; |
397 } | 397 } |
398 | 398 |
| 399 // TODO(chongz): Pass |EditCommandSource| to |CompositeEditCommand|. |
399 void Editor::deleteSelectionWithSmartDelete( | 400 void Editor::deleteSelectionWithSmartDelete( |
400 EditCommandSource source, | 401 EditCommandSource, |
401 DeleteMode deleteMode, | 402 DeleteMode deleteMode, |
402 InputEvent::InputType inputType, | 403 InputEvent::InputType inputType, |
403 const Position& referenceMovePosition) { | 404 const Position& referenceMovePosition) { |
404 if (frame().selection().isNone()) | 405 if (frame().selection().isNone()) |
405 return; | 406 return; |
406 | 407 |
407 const bool kMergeBlocksAfterDelete = true; | 408 const bool kMergeBlocksAfterDelete = true; |
408 const bool kExpandForSpecialElements = false; | 409 const bool kExpandForSpecialElements = false; |
409 const bool kSanitizeMarkup = true; | 410 const bool kSanitizeMarkup = true; |
410 DCHECK(frame().document()); | 411 DCHECK(frame().document()); |
411 DeleteSelectionCommand::create( | 412 DeleteSelectionCommand::create( |
412 *frame().document(), deleteMode == DeleteMode::Smart, | 413 *frame().document(), deleteMode == DeleteMode::Smart, |
413 kMergeBlocksAfterDelete, kExpandForSpecialElements, kSanitizeMarkup, | 414 kMergeBlocksAfterDelete, kExpandForSpecialElements, kSanitizeMarkup, |
414 inputType, referenceMovePosition) | 415 inputType, referenceMovePosition) |
415 ->apply(source); | 416 ->apply(); |
416 } | 417 } |
417 | 418 |
418 void Editor::pasteAsPlainText(const String& pastingText, bool smartReplace) { | 419 void Editor::pasteAsPlainText(const String& pastingText, bool smartReplace) { |
419 Element* target = findEventTargetFromSelection(); | 420 Element* target = findEventTargetFromSelection(); |
420 if (!target) | 421 if (!target) |
421 return; | 422 return; |
422 target->dispatchEvent(TextEvent::createForPlainTextPaste( | 423 target->dispatchEvent(TextEvent::createForPlainTextPaste( |
423 frame().domWindow(), pastingText, smartReplace)); | 424 frame().domWindow(), pastingText, smartReplace)); |
424 } | 425 } |
425 | 426 |
(...skipping 157 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
583 // invalidate clipboard here for security | 584 // invalidate clipboard here for security |
584 dataTransfer->setAccessPolicy(DataTransferNumb); | 585 dataTransfer->setAccessPolicy(DataTransferNumb); |
585 | 586 |
586 return !noDefaultProcessing; | 587 return !noDefaultProcessing; |
587 } | 588 } |
588 | 589 |
589 bool Editor::canSmartReplaceWithPasteboard(Pasteboard* pasteboard) { | 590 bool Editor::canSmartReplaceWithPasteboard(Pasteboard* pasteboard) { |
590 return smartInsertDeleteEnabled() && pasteboard->canSmartReplace(); | 591 return smartInsertDeleteEnabled() && pasteboard->canSmartReplace(); |
591 } | 592 } |
592 | 593 |
593 void Editor::replaceSelectionWithFragment(EditCommandSource source, | 594 // TODO(chongz): Pass |EditCommandSource| to |CompositeEditCommand|. |
| 595 void Editor::replaceSelectionWithFragment(EditCommandSource, |
594 DocumentFragment* fragment, | 596 DocumentFragment* fragment, |
595 bool selectReplacement, | 597 bool selectReplacement, |
596 bool smartReplace, | 598 bool smartReplace, |
597 bool matchStyle, | 599 bool matchStyle, |
598 InputEvent::InputType inputType) { | 600 InputEvent::InputType inputType) { |
599 DCHECK(!frame().document()->needsLayoutTreeUpdate()); | 601 DCHECK(!frame().document()->needsLayoutTreeUpdate()); |
600 if (frame().selection().isNone() || | 602 if (frame().selection().isNone() || |
601 !frame().selection().isContentEditable() || !fragment) | 603 !frame().selection().isContentEditable() || !fragment) |
602 return; | 604 return; |
603 | 605 |
604 ReplaceSelectionCommand::CommandOptions options = | 606 ReplaceSelectionCommand::CommandOptions options = |
605 ReplaceSelectionCommand::PreventNesting | | 607 ReplaceSelectionCommand::PreventNesting | |
606 ReplaceSelectionCommand::SanitizeFragment; | 608 ReplaceSelectionCommand::SanitizeFragment; |
607 if (selectReplacement) | 609 if (selectReplacement) |
608 options |= ReplaceSelectionCommand::SelectReplacement; | 610 options |= ReplaceSelectionCommand::SelectReplacement; |
609 if (smartReplace) | 611 if (smartReplace) |
610 options |= ReplaceSelectionCommand::SmartReplace; | 612 options |= ReplaceSelectionCommand::SmartReplace; |
611 if (matchStyle) | 613 if (matchStyle) |
612 options |= ReplaceSelectionCommand::MatchStyle; | 614 options |= ReplaceSelectionCommand::MatchStyle; |
613 DCHECK(frame().document()); | 615 DCHECK(frame().document()); |
614 ReplaceSelectionCommand::create(*frame().document(), fragment, options, | 616 ReplaceSelectionCommand::create(*frame().document(), fragment, options, |
615 inputType) | 617 inputType) |
616 ->apply(source); | 618 ->apply(); |
617 revealSelectionAfterEditingOperation(); | 619 revealSelectionAfterEditingOperation(); |
618 } | 620 } |
619 | 621 |
620 void Editor::replaceSelectionWithText(EditCommandSource source, | 622 void Editor::replaceSelectionWithText(EditCommandSource source, |
621 const String& text, | 623 const String& text, |
622 bool selectReplacement, | 624 bool selectReplacement, |
623 bool smartReplace, | 625 bool smartReplace, |
624 InputEvent::InputType inputType) { | 626 InputEvent::InputType inputType) { |
625 replaceSelectionWithFragment( | 627 replaceSelectionWithFragment( |
626 source, createFragmentFromText(selectedRange(), text), selectReplacement, | 628 source, createFragmentFromText(selectedRange(), text), selectReplacement, |
627 smartReplace, true, inputType); | 629 smartReplace, true, inputType); |
628 } | 630 } |
629 | 631 |
630 // TODO(xiaochengh): Merge it with |replaceSelectionWithFragment()|. | 632 // TODO(xiaochengh): Merge it with |replaceSelectionWithFragment()|. |
631 void Editor::replaceSelectionAfterDragging(DocumentFragment* fragment, | 633 void Editor::replaceSelectionAfterDragging(DocumentFragment* fragment, |
632 InsertMode insertMode, | 634 InsertMode insertMode, |
633 DragSourceType dragSourceType) { | 635 DragSourceType dragSourceType) { |
634 ReplaceSelectionCommand::CommandOptions options = | 636 ReplaceSelectionCommand::CommandOptions options = |
635 ReplaceSelectionCommand::SelectReplacement | | 637 ReplaceSelectionCommand::SelectReplacement | |
636 ReplaceSelectionCommand::PreventNesting; | 638 ReplaceSelectionCommand::PreventNesting; |
637 if (insertMode == InsertMode::Smart) | 639 if (insertMode == InsertMode::Smart) |
638 options |= ReplaceSelectionCommand::SmartReplace; | 640 options |= ReplaceSelectionCommand::SmartReplace; |
639 if (dragSourceType == DragSourceType::PlainTextSource) | 641 if (dragSourceType == DragSourceType::PlainTextSource) |
640 options |= ReplaceSelectionCommand::MatchStyle; | 642 options |= ReplaceSelectionCommand::MatchStyle; |
641 DCHECK(frame().document()); | 643 DCHECK(frame().document()); |
642 ReplaceSelectionCommand::create(*frame().document(), fragment, options, | 644 ReplaceSelectionCommand::create(*frame().document(), fragment, options, |
643 InputEvent::InputType::InsertFromDrop) | 645 InputEvent::InputType::InsertFromDrop) |
644 ->apply(EditCommandSource::kMenuOrKeyBinding); | 646 ->apply(); |
645 } | 647 } |
646 | 648 |
647 bool Editor::deleteSelectionAfterDraggingWithEvents( | 649 bool Editor::deleteSelectionAfterDraggingWithEvents( |
648 Element* dragSource, | 650 Element* dragSource, |
649 DeleteMode deleteMode, | 651 DeleteMode deleteMode, |
650 const Position& referenceMovePosition) { | 652 const Position& referenceMovePosition) { |
651 if (!dragSource || !dragSource->isConnected()) | 653 if (!dragSource || !dragSource->isConnected()) |
652 return true; | 654 return true; |
653 | 655 |
654 // Dispatch 'beforeinput'. | 656 // Dispatch 'beforeinput'. |
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
721 if (frame().settings() && frame().settings()->getAccessibilityEnabled()) { | 723 if (frame().settings() && frame().settings()->getAccessibilityEnabled()) { |
722 Node* node = endingSelection.start().anchorNode(); | 724 Node* node = endingSelection.start().anchorNode(); |
723 if (AXObjectCache* cache = frame().document()->existingAXObjectCache()) | 725 if (AXObjectCache* cache = frame().document()->existingAXObjectCache()) |
724 cache->handleEditableTextContentChanged(node); | 726 cache->handleEditableTextContentChanged(node); |
725 } | 727 } |
726 | 728 |
727 spellChecker().updateMarkersForWordsAffectedByEditing(true); | 729 spellChecker().updateMarkersForWordsAffectedByEditing(true); |
728 client().respondToChangedContents(); | 730 client().respondToChangedContents(); |
729 } | 731 } |
730 | 732 |
731 void Editor::removeFormattingAndStyle(EditCommandSource source) { | 733 // TODO(chongz): Pass |EditCommandSource| to |CompositeEditCommand|. |
| 734 void Editor::removeFormattingAndStyle(EditCommandSource) { |
732 DCHECK(frame().document()); | 735 DCHECK(frame().document()); |
733 RemoveFormatCommand::create(*frame().document())->apply(source); | 736 RemoveFormatCommand::create(*frame().document())->apply(); |
734 } | 737 } |
735 | 738 |
736 void Editor::registerCommandGroup(CompositeEditCommand* commandGroupWrapper) { | 739 void Editor::registerCommandGroup(CompositeEditCommand* commandGroupWrapper) { |
737 DCHECK(commandGroupWrapper->isCommandGroupWrapper()); | 740 DCHECK(commandGroupWrapper->isCommandGroupWrapper()); |
738 m_lastEditCommand = commandGroupWrapper; | 741 m_lastEditCommand = commandGroupWrapper; |
739 } | 742 } |
740 | 743 |
741 void Editor::clearLastEditCommand() { | 744 void Editor::clearLastEditCommand() { |
742 m_lastEditCommand.clear(); | 745 m_lastEditCommand.clear(); |
743 } | 746 } |
(...skipping 18 matching lines...) Expand all Loading... |
762 // do nothing | 765 // do nothing |
763 break; | 766 break; |
764 case CaretSelection: | 767 case CaretSelection: |
765 computeAndSetTypingStyle(source, style, inputType); | 768 computeAndSetTypingStyle(source, style, inputType); |
766 break; | 769 break; |
767 case RangeSelection: | 770 case RangeSelection: |
768 if (style) { | 771 if (style) { |
769 DCHECK(frame().document()); | 772 DCHECK(frame().document()); |
770 ApplyStyleCommand::create(*frame().document(), | 773 ApplyStyleCommand::create(*frame().document(), |
771 EditingStyle::create(style), inputType) | 774 EditingStyle::create(style), inputType) |
772 ->apply(source); | 775 ->apply(); |
773 } | 776 } |
774 break; | 777 break; |
775 } | 778 } |
776 } | 779 } |
777 | 780 |
778 void Editor::applyParagraphStyle(EditCommandSource source, | 781 // TODO(chongz): Pass |EditCommandSource| to |CompositeEditCommand|. |
| 782 void Editor::applyParagraphStyle(EditCommandSource, |
779 StylePropertySet* style, | 783 StylePropertySet* style, |
780 InputEvent::InputType inputType) { | 784 InputEvent::InputType inputType) { |
781 if (frame().selection().isNone() || !style) | 785 if (frame().selection().isNone() || !style) |
782 return; | 786 return; |
783 DCHECK(frame().document()); | 787 DCHECK(frame().document()); |
784 ApplyStyleCommand::create(*frame().document(), EditingStyle::create(style), | 788 ApplyStyleCommand::create(*frame().document(), EditingStyle::create(style), |
785 inputType, ApplyStyleCommand::ForceBlockProperties) | 789 inputType, ApplyStyleCommand::ForceBlockProperties) |
786 ->apply(source); | 790 ->apply(); |
787 } | 791 } |
788 | 792 |
789 void Editor::applyStyleToSelection(EditCommandSource source, | 793 void Editor::applyStyleToSelection(EditCommandSource source, |
790 StylePropertySet* style, | 794 StylePropertySet* style, |
791 InputEvent::InputType inputType) { | 795 InputEvent::InputType inputType) { |
792 if (!style || style->isEmpty() || !canEditRichly()) | 796 if (!style || style->isEmpty() || !canEditRichly()) |
793 return; | 797 return; |
794 | 798 |
795 applyStyle(source, style, inputType); | 799 applyStyle(source, style, inputType); |
796 } | 800 } |
(...skipping 207 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1004 | 1008 |
1005 const VisibleSelection& selection = selectionForCommand(triggeringEvent); | 1009 const VisibleSelection& selection = selectionForCommand(triggeringEvent); |
1006 if (!selection.isContentEditable()) | 1010 if (!selection.isContentEditable()) |
1007 return false; | 1011 return false; |
1008 | 1012 |
1009 spellChecker().updateMarkersForWordsAffectedByEditing( | 1013 spellChecker().updateMarkersForWordsAffectedByEditing( |
1010 isSpaceOrNewline(text[0])); | 1014 isSpaceOrNewline(text[0])); |
1011 | 1015 |
1012 // Insert the text | 1016 // Insert the text |
1013 TypingCommand::insertText( | 1017 TypingCommand::insertText( |
1014 *selection.start().document(), source, text, selection, | 1018 *selection.start().document(), text, selection, |
1015 selectInsertedText ? TypingCommand::SelectInsertedText : 0, | 1019 selectInsertedText ? TypingCommand::SelectInsertedText : 0, |
1016 triggeringEvent && triggeringEvent->isComposition() | 1020 triggeringEvent && triggeringEvent->isComposition() |
1017 ? TypingCommand::TextCompositionConfirm | 1021 ? TypingCommand::TextCompositionConfirm |
1018 : TypingCommand::TextCompositionNone); | 1022 : TypingCommand::TextCompositionNone); |
1019 | 1023 |
1020 // Reveal the current selection | 1024 // Reveal the current selection |
1021 if (LocalFrame* editedFrame = selection.start().document()->frame()) { | 1025 if (LocalFrame* editedFrame = selection.start().document()->frame()) { |
1022 if (Page* page = editedFrame->page()) { | 1026 if (Page* page = editedFrame->page()) { |
1023 LocalFrame* focusedOrMainFrame = | 1027 LocalFrame* focusedOrMainFrame = |
1024 toLocalFrame(page->focusController().focusedOrMainFrame()); | 1028 toLocalFrame(page->focusController().focusedOrMainFrame()); |
1025 focusedOrMainFrame->selection().revealSelection( | 1029 focusedOrMainFrame->selection().revealSelection( |
1026 ScrollAlignment::alignCenterIfNeeded); | 1030 ScrollAlignment::alignCenterIfNeeded); |
1027 } | 1031 } |
1028 } | 1032 } |
1029 | 1033 |
1030 return true; | 1034 return true; |
1031 } | 1035 } |
1032 | 1036 |
1033 bool Editor::insertLineBreak() { | 1037 bool Editor::insertLineBreak() { |
1034 if (!canEdit()) | 1038 if (!canEdit()) |
1035 return false; | 1039 return false; |
1036 | 1040 |
1037 VisiblePosition caret = frame().selection().selection().visibleStart(); | 1041 VisiblePosition caret = frame().selection().selection().visibleStart(); |
1038 bool alignToEdge = isEndOfEditableOrNonEditableContent(caret); | 1042 bool alignToEdge = isEndOfEditableOrNonEditableContent(caret); |
1039 DCHECK(frame().document()); | 1043 DCHECK(frame().document()); |
1040 // we can pass |EditCommandSource::kMenuOrKeyBinding| because | 1044 if (!TypingCommand::insertLineBreak(*frame().document())) |
1041 // |insertLineBreak()| is only used by |Editor::handleTextEvent()| and | |
1042 // |Editor::insertParagraphSeparator()|. | |
1043 if (!TypingCommand::insertLineBreak(*frame().document(), | |
1044 EditCommandSource::kMenuOrKeyBinding)) | |
1045 return false; | 1045 return false; |
1046 revealSelectionAfterEditingOperation( | 1046 revealSelectionAfterEditingOperation( |
1047 alignToEdge ? ScrollAlignment::alignToEdgeIfNeeded | 1047 alignToEdge ? ScrollAlignment::alignToEdgeIfNeeded |
1048 : ScrollAlignment::alignCenterIfNeeded); | 1048 : ScrollAlignment::alignCenterIfNeeded); |
1049 | 1049 |
1050 return true; | 1050 return true; |
1051 } | 1051 } |
1052 | 1052 |
1053 bool Editor::insertParagraphSeparator() { | 1053 bool Editor::insertParagraphSeparator() { |
1054 if (!canEdit()) | 1054 if (!canEdit()) |
1055 return false; | 1055 return false; |
1056 | 1056 |
1057 if (!canEditRichly()) | 1057 if (!canEditRichly()) |
1058 return insertLineBreak(); | 1058 return insertLineBreak(); |
1059 | 1059 |
1060 VisiblePosition caret = frame().selection().selection().visibleStart(); | 1060 VisiblePosition caret = frame().selection().selection().visibleStart(); |
1061 bool alignToEdge = isEndOfEditableOrNonEditableContent(caret); | 1061 bool alignToEdge = isEndOfEditableOrNonEditableContent(caret); |
1062 DCHECK(frame().document()); | 1062 DCHECK(frame().document()); |
1063 EditingState editingState; | 1063 EditingState editingState; |
1064 // We can |EditCommandSource::kMenuOrKeyBinding| because | 1064 if (!TypingCommand::insertParagraphSeparator(*frame().document())) |
1065 // |Editor::insertParagraphSeparator()| is only used by | |
1066 // |Editor::handleTextEvent()|. | |
1067 if (!TypingCommand::insertParagraphSeparator( | |
1068 *frame().document(), EditCommandSource::kMenuOrKeyBinding)) | |
1069 return false; | 1065 return false; |
1070 revealSelectionAfterEditingOperation( | 1066 revealSelectionAfterEditingOperation( |
1071 alignToEdge ? ScrollAlignment::alignToEdgeIfNeeded | 1067 alignToEdge ? ScrollAlignment::alignToEdgeIfNeeded |
1072 : ScrollAlignment::alignCenterIfNeeded); | 1068 : ScrollAlignment::alignCenterIfNeeded); |
1073 | 1069 |
1074 return true; | 1070 return true; |
1075 } | 1071 } |
1076 | 1072 |
1077 void Editor::cut(EditCommandSource source) { | 1073 void Editor::cut(EditCommandSource source) { |
1078 if (tryDHTMLCut()) | 1074 if (tryDHTMLCut()) |
(...skipping 364 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1443 std::max(startCaretRect.height(), endCaretRect.height())); | 1439 std::max(startCaretRect.height(), endCaretRect.height())); |
1444 } | 1440 } |
1445 | 1441 |
1446 // start and end aren't on the same line, so go from start to the end of its | 1442 // start and end aren't on the same line, so go from start to the end of its |
1447 // line | 1443 // line |
1448 return IntRect(startCaretRect.x(), startCaretRect.y(), | 1444 return IntRect(startCaretRect.x(), startCaretRect.y(), |
1449 (startCaretRect.width() + extraWidthToEndOfLine).toInt(), | 1445 (startCaretRect.width() + extraWidthToEndOfLine).toInt(), |
1450 startCaretRect.height()); | 1446 startCaretRect.height()); |
1451 } | 1447 } |
1452 | 1448 |
1453 void Editor::computeAndSetTypingStyle(EditCommandSource source, | 1449 // TODO(chongz): Pass |EditCommandSource| to |CompositeEditCommand|. |
| 1450 void Editor::computeAndSetTypingStyle(EditCommandSource, |
1454 StylePropertySet* style, | 1451 StylePropertySet* style, |
1455 InputEvent::InputType inputType) { | 1452 InputEvent::InputType inputType) { |
1456 if (!style || style->isEmpty()) { | 1453 if (!style || style->isEmpty()) { |
1457 frame().selection().clearTypingStyle(); | 1454 frame().selection().clearTypingStyle(); |
1458 return; | 1455 return; |
1459 } | 1456 } |
1460 | 1457 |
1461 // Calculate the current typing style. | 1458 // Calculate the current typing style. |
1462 EditingStyle* typingStyle = nullptr; | 1459 EditingStyle* typingStyle = nullptr; |
1463 if (frame().selection().typingStyle()) { | 1460 if (frame().selection().typingStyle()) { |
1464 typingStyle = frame().selection().typingStyle()->copy(); | 1461 typingStyle = frame().selection().typingStyle()->copy(); |
1465 typingStyle->overrideWithStyle(style); | 1462 typingStyle->overrideWithStyle(style); |
1466 } else { | 1463 } else { |
1467 typingStyle = EditingStyle::create(style); | 1464 typingStyle = EditingStyle::create(style); |
1468 } | 1465 } |
1469 | 1466 |
1470 typingStyle->prepareToApplyAt( | 1467 typingStyle->prepareToApplyAt( |
1471 frame().selection().selection().visibleStart().deepEquivalent(), | 1468 frame().selection().selection().visibleStart().deepEquivalent(), |
1472 EditingStyle::PreserveWritingDirection); | 1469 EditingStyle::PreserveWritingDirection); |
1473 | 1470 |
1474 // Handle block styles, substracting these from the typing style. | 1471 // Handle block styles, substracting these from the typing style. |
1475 EditingStyle* blockStyle = typingStyle->extractAndRemoveBlockProperties(); | 1472 EditingStyle* blockStyle = typingStyle->extractAndRemoveBlockProperties(); |
1476 if (!blockStyle->isEmpty()) { | 1473 if (!blockStyle->isEmpty()) { |
1477 DCHECK(frame().document()); | 1474 DCHECK(frame().document()); |
1478 ApplyStyleCommand::create(*frame().document(), blockStyle, inputType) | 1475 ApplyStyleCommand::create(*frame().document(), blockStyle, inputType) |
1479 ->apply(source); | 1476 ->apply(); |
1480 } | 1477 } |
1481 | 1478 |
1482 // Set the remaining style as the typing style. | 1479 // Set the remaining style as the typing style. |
1483 frame().selection().setTypingStyle(typingStyle); | 1480 frame().selection().setTypingStyle(typingStyle); |
1484 } | 1481 } |
1485 | 1482 |
1486 bool Editor::findString(const String& target, FindOptions options) { | 1483 bool Editor::findString(const String& target, FindOptions options) { |
1487 VisibleSelection selection = frame().selection().selection(); | 1484 VisibleSelection selection = frame().selection().selection(); |
1488 | 1485 |
1489 // TODO(yosin) We should make |findRangeOfString()| to return | 1486 // TODO(yosin) We should make |findRangeOfString()| to return |
(...skipping 248 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1738 } | 1735 } |
1739 | 1736 |
1740 DEFINE_TRACE(Editor) { | 1737 DEFINE_TRACE(Editor) { |
1741 visitor->trace(m_frame); | 1738 visitor->trace(m_frame); |
1742 visitor->trace(m_lastEditCommand); | 1739 visitor->trace(m_lastEditCommand); |
1743 visitor->trace(m_undoStack); | 1740 visitor->trace(m_undoStack); |
1744 visitor->trace(m_mark); | 1741 visitor->trace(m_mark); |
1745 } | 1742 } |
1746 | 1743 |
1747 } // namespace blink | 1744 } // namespace blink |
OLD | NEW |