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 313 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
324 bool killRing, | 324 bool killRing, |
325 bool isTypingAction) { | 325 bool isTypingAction) { |
326 if (!canEdit()) | 326 if (!canEdit()) |
327 return false; | 327 return false; |
328 | 328 |
329 EditingState editingState; | 329 EditingState editingState; |
330 if (frame().selection().isRange()) { | 330 if (frame().selection().isRange()) { |
331 if (isTypingAction) { | 331 if (isTypingAction) { |
332 DCHECK(frame().document()); | 332 DCHECK(frame().document()); |
333 TypingCommand::deleteKeyPressed( | 333 TypingCommand::deleteKeyPressed( |
334 *frame().document(), | 334 *frame().document(), source, |
335 canSmartCopyOrDelete() ? TypingCommand::SmartDelete : 0, granularity); | 335 canSmartCopyOrDelete() ? TypingCommand::SmartDelete : 0, granularity); |
336 revealSelectionAfterEditingOperation(); | 336 revealSelectionAfterEditingOperation(); |
337 } else { | 337 } else { |
338 if (killRing) | 338 if (killRing) |
339 addToKillRing(selectedRange()); | 339 addToKillRing(selectedRange()); |
340 deleteSelectionWithSmartDelete( | 340 deleteSelectionWithSmartDelete( |
341 source, | 341 source, |
342 canSmartCopyOrDelete() ? DeleteMode::Smart : DeleteMode::Simple, | 342 canSmartCopyOrDelete() ? DeleteMode::Smart : DeleteMode::Simple, |
343 deletionInputTypeFromTextGranularity(direction, granularity)); | 343 deletionInputTypeFromTextGranularity(direction, granularity)); |
344 // Implicitly calls revealSelectionAfterEditingOperation(). | 344 // Implicitly calls revealSelectionAfterEditingOperation(). |
345 } | 345 } |
346 } else { | 346 } else { |
347 TypingCommand::Options options = 0; | 347 TypingCommand::Options options = 0; |
348 if (canSmartCopyOrDelete()) | 348 if (canSmartCopyOrDelete()) |
349 options |= TypingCommand::SmartDelete; | 349 options |= TypingCommand::SmartDelete; |
350 if (killRing) | 350 if (killRing) |
351 options |= TypingCommand::KillRing; | 351 options |= TypingCommand::KillRing; |
352 switch (direction) { | 352 switch (direction) { |
353 case DeleteDirection::Forward: | 353 case DeleteDirection::Forward: |
354 DCHECK(frame().document()); | 354 DCHECK(frame().document()); |
355 TypingCommand::forwardDeleteKeyPressed( | 355 TypingCommand::forwardDeleteKeyPressed( |
356 *frame().document(), &editingState, options, granularity); | 356 *frame().document(), source, &editingState, options, granularity); |
357 if (editingState.isAborted()) | 357 if (editingState.isAborted()) |
358 return false; | 358 return false; |
359 break; | 359 break; |
360 case DeleteDirection::Backward: | 360 case DeleteDirection::Backward: |
361 DCHECK(frame().document()); | 361 DCHECK(frame().document()); |
362 TypingCommand::deleteKeyPressed(*frame().document(), options, | 362 TypingCommand::deleteKeyPressed(*frame().document(), source, options, |
363 granularity); | 363 granularity); |
364 break; | 364 break; |
365 } | 365 } |
366 revealSelectionAfterEditingOperation(); | 366 revealSelectionAfterEditingOperation(); |
367 } | 367 } |
368 | 368 |
369 // FIXME: We should to move this down into deleteKeyPressed. | 369 // FIXME: We should to move this down into deleteKeyPressed. |
370 // clear the "start new kill ring sequence" setting, because it was set to | 370 // clear the "start new kill ring sequence" setting, because it was set to |
371 // true when the selection was updated by deleting the range | 371 // true when the selection was updated by deleting the range |
372 if (killRing) | 372 if (killRing) |
373 setStartNewKillRingSequence(false); | 373 setStartNewKillRingSequence(false); |
374 | 374 |
375 return true; | 375 return true; |
376 } | 376 } |
377 | 377 |
378 // TODO(chongz): Pass |EditCommandSource| to |CompositeEditCommand|. | |
379 void Editor::deleteSelectionWithSmartDelete( | 378 void Editor::deleteSelectionWithSmartDelete( |
380 EditCommandSource, | 379 EditCommandSource source, |
381 DeleteMode deleteMode, | 380 DeleteMode deleteMode, |
382 InputEvent::InputType inputType, | 381 InputEvent::InputType inputType, |
383 const Position& referenceMovePosition) { | 382 const Position& referenceMovePosition) { |
384 if (frame().selection().isNone()) | 383 if (frame().selection().isNone()) |
385 return; | 384 return; |
386 | 385 |
387 const bool kMergeBlocksAfterDelete = true; | 386 const bool kMergeBlocksAfterDelete = true; |
388 const bool kExpandForSpecialElements = false; | 387 const bool kExpandForSpecialElements = false; |
389 const bool kSanitizeMarkup = true; | 388 const bool kSanitizeMarkup = true; |
390 DCHECK(frame().document()); | 389 DCHECK(frame().document()); |
391 DeleteSelectionCommand::create( | 390 DeleteSelectionCommand::create( |
392 *frame().document(), deleteMode == DeleteMode::Smart, | 391 *frame().document(), deleteMode == DeleteMode::Smart, |
393 kMergeBlocksAfterDelete, kExpandForSpecialElements, kSanitizeMarkup, | 392 kMergeBlocksAfterDelete, kExpandForSpecialElements, kSanitizeMarkup, |
394 inputType, referenceMovePosition) | 393 inputType, referenceMovePosition) |
395 ->apply(); | 394 ->apply(source); |
396 } | 395 } |
397 | 396 |
398 void Editor::pasteAsPlainText(const String& pastingText, bool smartReplace) { | 397 void Editor::pasteAsPlainText(const String& pastingText, bool smartReplace) { |
399 Element* target = findEventTargetFromSelection(); | 398 Element* target = findEventTargetFromSelection(); |
400 if (!target) | 399 if (!target) |
401 return; | 400 return; |
402 target->dispatchEvent(TextEvent::createForPlainTextPaste( | 401 target->dispatchEvent(TextEvent::createForPlainTextPaste( |
403 frame().domWindow(), pastingText, smartReplace)); | 402 frame().domWindow(), pastingText, smartReplace)); |
404 } | 403 } |
405 | 404 |
(...skipping 157 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
563 // invalidate clipboard here for security | 562 // invalidate clipboard here for security |
564 dataTransfer->setAccessPolicy(DataTransferNumb); | 563 dataTransfer->setAccessPolicy(DataTransferNumb); |
565 | 564 |
566 return !noDefaultProcessing; | 565 return !noDefaultProcessing; |
567 } | 566 } |
568 | 567 |
569 bool Editor::canSmartReplaceWithPasteboard(Pasteboard* pasteboard) { | 568 bool Editor::canSmartReplaceWithPasteboard(Pasteboard* pasteboard) { |
570 return smartInsertDeleteEnabled() && pasteboard->canSmartReplace(); | 569 return smartInsertDeleteEnabled() && pasteboard->canSmartReplace(); |
571 } | 570 } |
572 | 571 |
573 // TODO(chongz): Pass |EditCommandSource| to |CompositeEditCommand|. | 572 void Editor::replaceSelectionWithFragment(EditCommandSource source, |
574 void Editor::replaceSelectionWithFragment(EditCommandSource, | |
575 DocumentFragment* fragment, | 573 DocumentFragment* fragment, |
576 bool selectReplacement, | 574 bool selectReplacement, |
577 bool smartReplace, | 575 bool smartReplace, |
578 bool matchStyle, | 576 bool matchStyle, |
579 InputEvent::InputType inputType) { | 577 InputEvent::InputType inputType) { |
580 DCHECK(!frame().document()->needsLayoutTreeUpdate()); | 578 DCHECK(!frame().document()->needsLayoutTreeUpdate()); |
581 if (frame().selection().isNone() || | 579 if (frame().selection().isNone() || |
582 !frame().selection().isContentEditable() || !fragment) | 580 !frame().selection().isContentEditable() || !fragment) |
583 return; | 581 return; |
584 | 582 |
585 ReplaceSelectionCommand::CommandOptions options = | 583 ReplaceSelectionCommand::CommandOptions options = |
586 ReplaceSelectionCommand::PreventNesting | | 584 ReplaceSelectionCommand::PreventNesting | |
587 ReplaceSelectionCommand::SanitizeFragment; | 585 ReplaceSelectionCommand::SanitizeFragment; |
588 if (selectReplacement) | 586 if (selectReplacement) |
589 options |= ReplaceSelectionCommand::SelectReplacement; | 587 options |= ReplaceSelectionCommand::SelectReplacement; |
590 if (smartReplace) | 588 if (smartReplace) |
591 options |= ReplaceSelectionCommand::SmartReplace; | 589 options |= ReplaceSelectionCommand::SmartReplace; |
592 if (matchStyle) | 590 if (matchStyle) |
593 options |= ReplaceSelectionCommand::MatchStyle; | 591 options |= ReplaceSelectionCommand::MatchStyle; |
594 DCHECK(frame().document()); | 592 DCHECK(frame().document()); |
595 ReplaceSelectionCommand::create(*frame().document(), fragment, options, | 593 ReplaceSelectionCommand::create(*frame().document(), fragment, options, |
596 inputType) | 594 inputType) |
597 ->apply(); | 595 ->apply(source); |
598 revealSelectionAfterEditingOperation(); | 596 revealSelectionAfterEditingOperation(); |
599 } | 597 } |
600 | 598 |
601 void Editor::replaceSelectionWithText(EditCommandSource source, | 599 void Editor::replaceSelectionWithText(EditCommandSource source, |
602 const String& text, | 600 const String& text, |
603 bool selectReplacement, | 601 bool selectReplacement, |
604 bool smartReplace, | 602 bool smartReplace, |
605 InputEvent::InputType inputType) { | 603 InputEvent::InputType inputType) { |
606 replaceSelectionWithFragment( | 604 replaceSelectionWithFragment( |
607 source, createFragmentFromText(selectedRange(), text), selectReplacement, | 605 source, createFragmentFromText(selectedRange(), text), selectReplacement, |
608 smartReplace, true, inputType); | 606 smartReplace, true, inputType); |
609 } | 607 } |
610 | 608 |
611 // TODO(xiaochengh): Merge it with |replaceSelectionWithFragment()|. | 609 // TODO(xiaochengh): Merge it with |replaceSelectionWithFragment()|. |
612 void Editor::replaceSelectionAfterDragging(DocumentFragment* fragment, | 610 void Editor::replaceSelectionAfterDragging(DocumentFragment* fragment, |
613 InsertMode insertMode, | 611 InsertMode insertMode, |
614 DragSourceType dragSourceType) { | 612 DragSourceType dragSourceType) { |
615 ReplaceSelectionCommand::CommandOptions options = | 613 ReplaceSelectionCommand::CommandOptions options = |
616 ReplaceSelectionCommand::SelectReplacement | | 614 ReplaceSelectionCommand::SelectReplacement | |
617 ReplaceSelectionCommand::PreventNesting; | 615 ReplaceSelectionCommand::PreventNesting; |
618 if (insertMode == InsertMode::Smart) | 616 if (insertMode == InsertMode::Smart) |
619 options |= ReplaceSelectionCommand::SmartReplace; | 617 options |= ReplaceSelectionCommand::SmartReplace; |
620 if (dragSourceType == DragSourceType::PlainTextSource) | 618 if (dragSourceType == DragSourceType::PlainTextSource) |
621 options |= ReplaceSelectionCommand::MatchStyle; | 619 options |= ReplaceSelectionCommand::MatchStyle; |
622 DCHECK(frame().document()); | 620 DCHECK(frame().document()); |
623 ReplaceSelectionCommand::create(*frame().document(), fragment, options, | 621 ReplaceSelectionCommand::create(*frame().document(), fragment, options, |
624 InputEvent::InputType::InsertFromDrop) | 622 InputEvent::InputType::InsertFromDrop) |
625 ->apply(); | 623 ->apply(EditCommandSource::kMenuOrKeyBinding); |
626 } | 624 } |
627 | 625 |
628 bool Editor::deleteSelectionAfterDraggingWithEvents( | 626 bool Editor::deleteSelectionAfterDraggingWithEvents( |
629 Element* dragSource, | 627 Element* dragSource, |
630 DeleteMode deleteMode, | 628 DeleteMode deleteMode, |
631 const Position& referenceMovePosition) { | 629 const Position& referenceMovePosition) { |
632 if (!dragSource || !dragSource->isConnected()) | 630 if (!dragSource || !dragSource->isConnected()) |
633 return true; | 631 return true; |
634 | 632 |
635 // Dispatch 'beforeinput'. | 633 // Dispatch 'beforeinput'. |
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
702 if (frame().settings() && frame().settings()->accessibilityEnabled()) { | 700 if (frame().settings() && frame().settings()->accessibilityEnabled()) { |
703 Node* node = endingSelection.start().anchorNode(); | 701 Node* node = endingSelection.start().anchorNode(); |
704 if (AXObjectCache* cache = frame().document()->existingAXObjectCache()) | 702 if (AXObjectCache* cache = frame().document()->existingAXObjectCache()) |
705 cache->handleEditableTextContentChanged(node); | 703 cache->handleEditableTextContentChanged(node); |
706 } | 704 } |
707 | 705 |
708 spellChecker().updateMarkersForWordsAffectedByEditing(true); | 706 spellChecker().updateMarkersForWordsAffectedByEditing(true); |
709 client().respondToChangedContents(); | 707 client().respondToChangedContents(); |
710 } | 708 } |
711 | 709 |
712 // TODO(chongz): Pass |EditCommandSource| to |CompositeEditCommand|. | 710 void Editor::removeFormattingAndStyle(EditCommandSource source) { |
713 void Editor::removeFormattingAndStyle(EditCommandSource) { | |
714 DCHECK(frame().document()); | 711 DCHECK(frame().document()); |
715 RemoveFormatCommand::create(*frame().document())->apply(); | 712 RemoveFormatCommand::create(*frame().document())->apply(source); |
716 } | 713 } |
717 | 714 |
718 void Editor::registerCommandGroup(CompositeEditCommand* commandGroupWrapper) { | 715 void Editor::registerCommandGroup(CompositeEditCommand* commandGroupWrapper) { |
719 DCHECK(commandGroupWrapper->isCommandGroupWrapper()); | 716 DCHECK(commandGroupWrapper->isCommandGroupWrapper()); |
720 m_lastEditCommand = commandGroupWrapper; | 717 m_lastEditCommand = commandGroupWrapper; |
721 } | 718 } |
722 | 719 |
723 void Editor::clearLastEditCommand() { | 720 void Editor::clearLastEditCommand() { |
724 m_lastEditCommand.clear(); | 721 m_lastEditCommand.clear(); |
725 } | 722 } |
(...skipping 18 matching lines...) Expand all Loading... |
744 // do nothing | 741 // do nothing |
745 break; | 742 break; |
746 case CaretSelection: | 743 case CaretSelection: |
747 computeAndSetTypingStyle(source, style, inputType); | 744 computeAndSetTypingStyle(source, style, inputType); |
748 break; | 745 break; |
749 case RangeSelection: | 746 case RangeSelection: |
750 if (style) { | 747 if (style) { |
751 DCHECK(frame().document()); | 748 DCHECK(frame().document()); |
752 ApplyStyleCommand::create(*frame().document(), | 749 ApplyStyleCommand::create(*frame().document(), |
753 EditingStyle::create(style), inputType) | 750 EditingStyle::create(style), inputType) |
754 ->apply(); | 751 ->apply(source); |
755 } | 752 } |
756 break; | 753 break; |
757 } | 754 } |
758 } | 755 } |
759 | 756 |
760 // TODO(chongz): Pass |EditCommandSource| to |CompositeEditCommand|. | 757 void Editor::applyParagraphStyle(EditCommandSource source, |
761 void Editor::applyParagraphStyle(EditCommandSource, | |
762 StylePropertySet* style, | 758 StylePropertySet* style, |
763 InputEvent::InputType inputType) { | 759 InputEvent::InputType inputType) { |
764 if (frame().selection().isNone() || !style) | 760 if (frame().selection().isNone() || !style) |
765 return; | 761 return; |
766 DCHECK(frame().document()); | 762 DCHECK(frame().document()); |
767 ApplyStyleCommand::create(*frame().document(), EditingStyle::create(style), | 763 ApplyStyleCommand::create(*frame().document(), EditingStyle::create(style), |
768 inputType, ApplyStyleCommand::ForceBlockProperties) | 764 inputType, ApplyStyleCommand::ForceBlockProperties) |
769 ->apply(); | 765 ->apply(source); |
770 } | 766 } |
771 | 767 |
772 void Editor::applyStyleToSelection(EditCommandSource source, | 768 void Editor::applyStyleToSelection(EditCommandSource source, |
773 StylePropertySet* style, | 769 StylePropertySet* style, |
774 InputEvent::InputType inputType) { | 770 InputEvent::InputType inputType) { |
775 if (!style || style->isEmpty() || !canEditRichly()) | 771 if (!style || style->isEmpty() || !canEditRichly()) |
776 return; | 772 return; |
777 | 773 |
778 applyStyle(source, style, inputType); | 774 applyStyle(source, style, inputType); |
779 } | 775 } |
(...skipping 199 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
979 | 975 |
980 const VisibleSelection& selection = selectionForCommand(triggeringEvent); | 976 const VisibleSelection& selection = selectionForCommand(triggeringEvent); |
981 if (!selection.isContentEditable()) | 977 if (!selection.isContentEditable()) |
982 return false; | 978 return false; |
983 | 979 |
984 spellChecker().updateMarkersForWordsAffectedByEditing( | 980 spellChecker().updateMarkersForWordsAffectedByEditing( |
985 isSpaceOrNewline(text[0])); | 981 isSpaceOrNewline(text[0])); |
986 | 982 |
987 // Insert the text | 983 // Insert the text |
988 TypingCommand::insertText( | 984 TypingCommand::insertText( |
989 *selection.start().document(), text, selection, | 985 *selection.start().document(), source, text, selection, |
990 selectInsertedText ? TypingCommand::SelectInsertedText : 0, | 986 selectInsertedText ? TypingCommand::SelectInsertedText : 0, |
991 triggeringEvent && triggeringEvent->isComposition() | 987 triggeringEvent && triggeringEvent->isComposition() |
992 ? TypingCommand::TextCompositionConfirm | 988 ? TypingCommand::TextCompositionConfirm |
993 : TypingCommand::TextCompositionNone); | 989 : TypingCommand::TextCompositionNone); |
994 | 990 |
995 // Reveal the current selection | 991 // Reveal the current selection |
996 if (LocalFrame* editedFrame = selection.start().document()->frame()) { | 992 if (LocalFrame* editedFrame = selection.start().document()->frame()) { |
997 if (Page* page = editedFrame->page()) { | 993 if (Page* page = editedFrame->page()) { |
998 LocalFrame* focusedOrMainFrame = | 994 LocalFrame* focusedOrMainFrame = |
999 toLocalFrame(page->focusController().focusedOrMainFrame()); | 995 toLocalFrame(page->focusController().focusedOrMainFrame()); |
1000 focusedOrMainFrame->selection().revealSelection( | 996 focusedOrMainFrame->selection().revealSelection( |
1001 ScrollAlignment::alignCenterIfNeeded); | 997 ScrollAlignment::alignCenterIfNeeded); |
1002 } | 998 } |
1003 } | 999 } |
1004 | 1000 |
1005 return true; | 1001 return true; |
1006 } | 1002 } |
1007 | 1003 |
1008 bool Editor::insertLineBreak() { | 1004 bool Editor::insertLineBreak() { |
1009 if (!canEdit()) | 1005 if (!canEdit()) |
1010 return false; | 1006 return false; |
1011 | 1007 |
1012 VisiblePosition caret = frame().selection().selection().visibleStart(); | 1008 VisiblePosition caret = frame().selection().selection().visibleStart(); |
1013 bool alignToEdge = isEndOfEditableOrNonEditableContent(caret); | 1009 bool alignToEdge = isEndOfEditableOrNonEditableContent(caret); |
1014 DCHECK(frame().document()); | 1010 DCHECK(frame().document()); |
1015 if (!TypingCommand::insertLineBreak(*frame().document())) | 1011 // we can pass |EditCommandSource::kMenuOrKeyBinding| because |
| 1012 // |insertLineBreak()| is only used by |Editor::handleTextEvent()| and |
| 1013 // |Editor::insertParagraphSeparator()|. |
| 1014 if (!TypingCommand::insertLineBreak(*frame().document(), |
| 1015 EditCommandSource::kMenuOrKeyBinding)) |
1016 return false; | 1016 return false; |
1017 revealSelectionAfterEditingOperation( | 1017 revealSelectionAfterEditingOperation( |
1018 alignToEdge ? ScrollAlignment::alignToEdgeIfNeeded | 1018 alignToEdge ? ScrollAlignment::alignToEdgeIfNeeded |
1019 : ScrollAlignment::alignCenterIfNeeded); | 1019 : ScrollAlignment::alignCenterIfNeeded); |
1020 | 1020 |
1021 return true; | 1021 return true; |
1022 } | 1022 } |
1023 | 1023 |
1024 bool Editor::insertParagraphSeparator() { | 1024 bool Editor::insertParagraphSeparator() { |
1025 if (!canEdit()) | 1025 if (!canEdit()) |
1026 return false; | 1026 return false; |
1027 | 1027 |
1028 if (!canEditRichly()) | 1028 if (!canEditRichly()) |
1029 return insertLineBreak(); | 1029 return insertLineBreak(); |
1030 | 1030 |
1031 VisiblePosition caret = frame().selection().selection().visibleStart(); | 1031 VisiblePosition caret = frame().selection().selection().visibleStart(); |
1032 bool alignToEdge = isEndOfEditableOrNonEditableContent(caret); | 1032 bool alignToEdge = isEndOfEditableOrNonEditableContent(caret); |
1033 DCHECK(frame().document()); | 1033 DCHECK(frame().document()); |
1034 EditingState editingState; | 1034 EditingState editingState; |
1035 if (!TypingCommand::insertParagraphSeparator(*frame().document())) | 1035 // We can |EditCommandSource::kMenuOrKeyBinding| because |
| 1036 // |Editor::insertParagraphSeparator()| is only used by |
| 1037 // |Editor::handleTextEvent()|. |
| 1038 if (!TypingCommand::insertParagraphSeparator( |
| 1039 *frame().document(), EditCommandSource::kMenuOrKeyBinding)) |
1036 return false; | 1040 return false; |
1037 revealSelectionAfterEditingOperation( | 1041 revealSelectionAfterEditingOperation( |
1038 alignToEdge ? ScrollAlignment::alignToEdgeIfNeeded | 1042 alignToEdge ? ScrollAlignment::alignToEdgeIfNeeded |
1039 : ScrollAlignment::alignCenterIfNeeded); | 1043 : ScrollAlignment::alignCenterIfNeeded); |
1040 | 1044 |
1041 return true; | 1045 return true; |
1042 } | 1046 } |
1043 | 1047 |
1044 void Editor::cut(EditCommandSource source) { | 1048 void Editor::cut(EditCommandSource source) { |
1045 if (tryDHTMLCut()) | 1049 if (tryDHTMLCut()) |
(...skipping 364 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1410 std::max(startCaretRect.height(), endCaretRect.height())); | 1414 std::max(startCaretRect.height(), endCaretRect.height())); |
1411 } | 1415 } |
1412 | 1416 |
1413 // start and end aren't on the same line, so go from start to the end of its | 1417 // start and end aren't on the same line, so go from start to the end of its |
1414 // line | 1418 // line |
1415 return IntRect(startCaretRect.x(), startCaretRect.y(), | 1419 return IntRect(startCaretRect.x(), startCaretRect.y(), |
1416 (startCaretRect.width() + extraWidthToEndOfLine).toInt(), | 1420 (startCaretRect.width() + extraWidthToEndOfLine).toInt(), |
1417 startCaretRect.height()); | 1421 startCaretRect.height()); |
1418 } | 1422 } |
1419 | 1423 |
1420 // TODO(chongz): Pass |EditCommandSource| to |CompositeEditCommand|. | 1424 void Editor::computeAndSetTypingStyle(EditCommandSource source, |
1421 void Editor::computeAndSetTypingStyle(EditCommandSource, | |
1422 StylePropertySet* style, | 1425 StylePropertySet* style, |
1423 InputEvent::InputType inputType) { | 1426 InputEvent::InputType inputType) { |
1424 if (!style || style->isEmpty()) { | 1427 if (!style || style->isEmpty()) { |
1425 frame().selection().clearTypingStyle(); | 1428 frame().selection().clearTypingStyle(); |
1426 return; | 1429 return; |
1427 } | 1430 } |
1428 | 1431 |
1429 // Calculate the current typing style. | 1432 // Calculate the current typing style. |
1430 EditingStyle* typingStyle = nullptr; | 1433 EditingStyle* typingStyle = nullptr; |
1431 if (frame().selection().typingStyle()) { | 1434 if (frame().selection().typingStyle()) { |
1432 typingStyle = frame().selection().typingStyle()->copy(); | 1435 typingStyle = frame().selection().typingStyle()->copy(); |
1433 typingStyle->overrideWithStyle(style); | 1436 typingStyle->overrideWithStyle(style); |
1434 } else { | 1437 } else { |
1435 typingStyle = EditingStyle::create(style); | 1438 typingStyle = EditingStyle::create(style); |
1436 } | 1439 } |
1437 | 1440 |
1438 typingStyle->prepareToApplyAt( | 1441 typingStyle->prepareToApplyAt( |
1439 frame().selection().selection().visibleStart().deepEquivalent(), | 1442 frame().selection().selection().visibleStart().deepEquivalent(), |
1440 EditingStyle::PreserveWritingDirection); | 1443 EditingStyle::PreserveWritingDirection); |
1441 | 1444 |
1442 // Handle block styles, substracting these from the typing style. | 1445 // Handle block styles, substracting these from the typing style. |
1443 EditingStyle* blockStyle = typingStyle->extractAndRemoveBlockProperties(); | 1446 EditingStyle* blockStyle = typingStyle->extractAndRemoveBlockProperties(); |
1444 if (!blockStyle->isEmpty()) { | 1447 if (!blockStyle->isEmpty()) { |
1445 DCHECK(frame().document()); | 1448 DCHECK(frame().document()); |
1446 ApplyStyleCommand::create(*frame().document(), blockStyle, inputType) | 1449 ApplyStyleCommand::create(*frame().document(), blockStyle, inputType) |
1447 ->apply(); | 1450 ->apply(source); |
1448 } | 1451 } |
1449 | 1452 |
1450 // Set the remaining style as the typing style. | 1453 // Set the remaining style as the typing style. |
1451 frame().selection().setTypingStyle(typingStyle); | 1454 frame().selection().setTypingStyle(typingStyle); |
1452 } | 1455 } |
1453 | 1456 |
1454 bool Editor::findString(const String& target, FindOptions options) { | 1457 bool Editor::findString(const String& target, FindOptions options) { |
1455 VisibleSelection selection = frame().selection().selection(); | 1458 VisibleSelection selection = frame().selection().selection(); |
1456 | 1459 |
1457 // TODO(yosin) We should make |findRangeOfString()| to return | 1460 // TODO(yosin) We should make |findRangeOfString()| to return |
(...skipping 248 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1706 } | 1709 } |
1707 | 1710 |
1708 DEFINE_TRACE(Editor) { | 1711 DEFINE_TRACE(Editor) { |
1709 visitor->trace(m_frame); | 1712 visitor->trace(m_frame); |
1710 visitor->trace(m_lastEditCommand); | 1713 visitor->trace(m_lastEditCommand); |
1711 visitor->trace(m_undoStack); | 1714 visitor->trace(m_undoStack); |
1712 visitor->trace(m_mark); | 1715 visitor->trace(m_mark); |
1713 } | 1716 } |
1714 | 1717 |
1715 } // namespace blink | 1718 } // namespace blink |
OLD | NEW |