| 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 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 96 using namespace Unicode; | 96 using namespace Unicode; |
| 97 | 97 |
| 98 Editor::RevealSelectionScope::RevealSelectionScope(Editor* editor) | 98 Editor::RevealSelectionScope::RevealSelectionScope(Editor* editor) |
| 99 : m_editor(editor) | 99 : m_editor(editor) |
| 100 { | 100 { |
| 101 ++m_editor->m_preventRevealSelection; | 101 ++m_editor->m_preventRevealSelection; |
| 102 } | 102 } |
| 103 | 103 |
| 104 Editor::RevealSelectionScope::~RevealSelectionScope() | 104 Editor::RevealSelectionScope::~RevealSelectionScope() |
| 105 { | 105 { |
| 106 ASSERT(m_editor->m_preventRevealSelection); | 106 DCHECK(m_editor->m_preventRevealSelection); |
| 107 --m_editor->m_preventRevealSelection; | 107 --m_editor->m_preventRevealSelection; |
| 108 if (!m_editor->m_preventRevealSelection) | 108 if (!m_editor->m_preventRevealSelection) |
| 109 m_editor->frame().selection().revealSelection(ScrollAlignment::alignToEd
geIfNeeded, RevealExtent); | 109 m_editor->frame().selection().revealSelection(ScrollAlignment::alignToEd
geIfNeeded, RevealExtent); |
| 110 } | 110 } |
| 111 | 111 |
| 112 // When an event handler has moved the selection outside of a text control | 112 // When an event handler has moved the selection outside of a text control |
| 113 // we should use the target control's selection for this editing operation. | 113 // we should use the target control's selection for this editing operation. |
| 114 VisibleSelection Editor::selectionForCommand(Event* event) | 114 VisibleSelection Editor::selectionForCommand(Event* event) |
| 115 { | 115 { |
| 116 frame().selection().updateIfNeeded(); | 116 frame().selection().updateIfNeeded(); |
| (...skipping 171 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 288 } | 288 } |
| 289 | 289 |
| 290 bool Editor::deleteWithDirection(SelectionDirection direction, TextGranularity g
ranularity, bool killRing, bool isTypingAction) | 290 bool Editor::deleteWithDirection(SelectionDirection direction, TextGranularity g
ranularity, bool killRing, bool isTypingAction) |
| 291 { | 291 { |
| 292 if (!canEdit()) | 292 if (!canEdit()) |
| 293 return false; | 293 return false; |
| 294 | 294 |
| 295 EditingState editingState; | 295 EditingState editingState; |
| 296 if (frame().selection().isRange()) { | 296 if (frame().selection().isRange()) { |
| 297 if (isTypingAction) { | 297 if (isTypingAction) { |
| 298 ASSERT(frame().document()); | 298 DCHECK(frame().document()); |
| 299 TypingCommand::deleteKeyPressed(*frame().document(), canSmartCopyOrD
elete() ? TypingCommand::SmartDelete : 0, granularity); | 299 TypingCommand::deleteKeyPressed(*frame().document(), canSmartCopyOrD
elete() ? TypingCommand::SmartDelete : 0, granularity); |
| 300 revealSelectionAfterEditingOperation(); | 300 revealSelectionAfterEditingOperation(); |
| 301 } else { | 301 } else { |
| 302 if (killRing) | 302 if (killRing) |
| 303 addToKillRing(selectedRange()); | 303 addToKillRing(selectedRange()); |
| 304 deleteSelectionWithSmartDelete(canSmartCopyOrDelete()); | 304 deleteSelectionWithSmartDelete(canSmartCopyOrDelete()); |
| 305 // Implicitly calls revealSelectionAfterEditingOperation(). | 305 // Implicitly calls revealSelectionAfterEditingOperation(). |
| 306 } | 306 } |
| 307 } else { | 307 } else { |
| 308 TypingCommand::Options options = 0; | 308 TypingCommand::Options options = 0; |
| 309 if (canSmartCopyOrDelete()) | 309 if (canSmartCopyOrDelete()) |
| 310 options |= TypingCommand::SmartDelete; | 310 options |= TypingCommand::SmartDelete; |
| 311 if (killRing) | 311 if (killRing) |
| 312 options |= TypingCommand::KillRing; | 312 options |= TypingCommand::KillRing; |
| 313 switch (direction) { | 313 switch (direction) { |
| 314 case DirectionForward: | 314 case DirectionForward: |
| 315 case DirectionRight: | 315 case DirectionRight: |
| 316 ASSERT(frame().document()); | 316 DCHECK(frame().document()); |
| 317 TypingCommand::forwardDeleteKeyPressed(*frame().document(), &editing
State, options, granularity); | 317 TypingCommand::forwardDeleteKeyPressed(*frame().document(), &editing
State, options, granularity); |
| 318 if (editingState.isAborted()) | 318 if (editingState.isAborted()) |
| 319 return false; | 319 return false; |
| 320 break; | 320 break; |
| 321 case DirectionBackward: | 321 case DirectionBackward: |
| 322 case DirectionLeft: | 322 case DirectionLeft: |
| 323 ASSERT(frame().document()); | 323 DCHECK(frame().document()); |
| 324 TypingCommand::deleteKeyPressed(*frame().document(), options, granul
arity); | 324 TypingCommand::deleteKeyPressed(*frame().document(), options, granul
arity); |
| 325 break; | 325 break; |
| 326 } | 326 } |
| 327 revealSelectionAfterEditingOperation(); | 327 revealSelectionAfterEditingOperation(); |
| 328 } | 328 } |
| 329 | 329 |
| 330 // FIXME: We should to move this down into deleteKeyPressed. | 330 // FIXME: We should to move this down into deleteKeyPressed. |
| 331 // clear the "start new kill ring sequence" setting, because it was set to t
rue | 331 // clear the "start new kill ring sequence" setting, because it was set to t
rue |
| 332 // when the selection was updated by deleting the range | 332 // when the selection was updated by deleting the range |
| 333 if (killRing) | 333 if (killRing) |
| 334 setStartNewKillRingSequence(false); | 334 setStartNewKillRingSequence(false); |
| 335 | 335 |
| 336 return true; | 336 return true; |
| 337 } | 337 } |
| 338 | 338 |
| 339 void Editor::deleteSelectionWithSmartDelete(bool smartDelete) | 339 void Editor::deleteSelectionWithSmartDelete(bool smartDelete) |
| 340 { | 340 { |
| 341 if (frame().selection().isNone()) | 341 if (frame().selection().isNone()) |
| 342 return; | 342 return; |
| 343 | 343 |
| 344 ASSERT(frame().document()); | 344 DCHECK(frame().document()); |
| 345 DeleteSelectionCommand::create(*frame().document(), smartDelete)->apply(); | 345 DeleteSelectionCommand::create(*frame().document(), smartDelete)->apply(); |
| 346 } | 346 } |
| 347 | 347 |
| 348 void Editor::pasteAsPlainText(const String& pastingText, bool smartReplace) | 348 void Editor::pasteAsPlainText(const String& pastingText, bool smartReplace) |
| 349 { | 349 { |
| 350 Element* target = findEventTargetFromSelection(); | 350 Element* target = findEventTargetFromSelection(); |
| 351 if (!target) | 351 if (!target) |
| 352 return; | 352 return; |
| 353 target->dispatchEvent(TextEvent::createForPlainTextPaste(frame().domWindow()
, pastingText, smartReplace)); | 353 target->dispatchEvent(TextEvent::createForPlainTextPaste(frame().domWindow()
, pastingText, smartReplace)); |
| 354 } | 354 } |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 392 { | 392 { |
| 393 DocumentFragment* fragment = nullptr; | 393 DocumentFragment* fragment = nullptr; |
| 394 bool chosePlainText = false; | 394 bool chosePlainText = false; |
| 395 | 395 |
| 396 if (pasteboard->isHTMLAvailable()) { | 396 if (pasteboard->isHTMLAvailable()) { |
| 397 unsigned fragmentStart = 0; | 397 unsigned fragmentStart = 0; |
| 398 unsigned fragmentEnd = 0; | 398 unsigned fragmentEnd = 0; |
| 399 KURL url; | 399 KURL url; |
| 400 String markup = pasteboard->readHTML(url, fragmentStart, fragmentEnd); | 400 String markup = pasteboard->readHTML(url, fragmentStart, fragmentEnd); |
| 401 if (!markup.isEmpty()) { | 401 if (!markup.isEmpty()) { |
| 402 ASSERT(frame().document()); | 402 DCHECK(frame().document()); |
| 403 fragment = createFragmentFromMarkupWithContext(*frame().document(),
markup, fragmentStart, fragmentEnd, url, DisallowScriptingAndPluginContent); | 403 fragment = createFragmentFromMarkupWithContext(*frame().document(),
markup, fragmentStart, fragmentEnd, url, DisallowScriptingAndPluginContent); |
| 404 } | 404 } |
| 405 } | 405 } |
| 406 | 406 |
| 407 if (!fragment) { | 407 if (!fragment) { |
| 408 String text = pasteboard->plainText(); | 408 String text = pasteboard->plainText(); |
| 409 if (!text.isEmpty()) { | 409 if (!text.isEmpty()) { |
| 410 chosePlainText = true; | 410 chosePlainText = true; |
| 411 fragment = createFragmentFromText(selectedRange(), text); | 411 fragment = createFragmentFromText(selectedRange(), text); |
| 412 } | 412 } |
| (...skipping 30 matching lines...) Expand all Loading... |
| 443 if (!cachedImage || cachedImage->errorOccurred()) | 443 if (!cachedImage || cachedImage->errorOccurred()) |
| 444 return nullptr; | 444 return nullptr; |
| 445 return cachedImage->getImage(); | 445 return cachedImage->getImage(); |
| 446 } | 446 } |
| 447 | 447 |
| 448 return nullptr; | 448 return nullptr; |
| 449 } | 449 } |
| 450 | 450 |
| 451 static void writeImageNodeToPasteboard(Pasteboard* pasteboard, Node* node, const
String& title) | 451 static void writeImageNodeToPasteboard(Pasteboard* pasteboard, Node* node, const
String& title) |
| 452 { | 452 { |
| 453 ASSERT(pasteboard); | 453 DCHECK(pasteboard); |
| 454 ASSERT(node); | 454 DCHECK(node); |
| 455 | 455 |
| 456 RefPtr<Image> image = imageFromNode(*node); | 456 RefPtr<Image> image = imageFromNode(*node); |
| 457 if (!image.get()) | 457 if (!image.get()) |
| 458 return; | 458 return; |
| 459 | 459 |
| 460 // FIXME: This should probably be reconciled with HitTestResult::absoluteIma
geURL. | 460 // FIXME: This should probably be reconciled with HitTestResult::absoluteIma
geURL. |
| 461 AtomicString urlString; | 461 AtomicString urlString; |
| 462 if (isHTMLImageElement(*node) || isHTMLInputElement(*node)) | 462 if (isHTMLImageElement(*node) || isHTMLInputElement(*node)) |
| 463 urlString = toHTMLElement(node)->getAttribute(srcAttr); | 463 urlString = toHTMLElement(node)->getAttribute(srcAttr); |
| 464 else if (isSVGImageElement(*node)) | 464 else if (isSVGImageElement(*node)) |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 507 if (frame().selection().isNone() || !frame().selection().isContentEditable()
|| !fragment) | 507 if (frame().selection().isNone() || !frame().selection().isContentEditable()
|| !fragment) |
| 508 return; | 508 return; |
| 509 | 509 |
| 510 ReplaceSelectionCommand::CommandOptions options = ReplaceSelectionCommand::P
reventNesting | ReplaceSelectionCommand::SanitizeFragment; | 510 ReplaceSelectionCommand::CommandOptions options = ReplaceSelectionCommand::P
reventNesting | ReplaceSelectionCommand::SanitizeFragment; |
| 511 if (selectReplacement) | 511 if (selectReplacement) |
| 512 options |= ReplaceSelectionCommand::SelectReplacement; | 512 options |= ReplaceSelectionCommand::SelectReplacement; |
| 513 if (smartReplace) | 513 if (smartReplace) |
| 514 options |= ReplaceSelectionCommand::SmartReplace; | 514 options |= ReplaceSelectionCommand::SmartReplace; |
| 515 if (matchStyle) | 515 if (matchStyle) |
| 516 options |= ReplaceSelectionCommand::MatchStyle; | 516 options |= ReplaceSelectionCommand::MatchStyle; |
| 517 ASSERT(frame().document()); | 517 DCHECK(frame().document()); |
| 518 ReplaceSelectionCommand::create(*frame().document(), fragment, options, Edit
ActionPaste)->apply(); | 518 ReplaceSelectionCommand::create(*frame().document(), fragment, options, Edit
ActionPaste)->apply(); |
| 519 revealSelectionAfterEditingOperation(); | 519 revealSelectionAfterEditingOperation(); |
| 520 } | 520 } |
| 521 | 521 |
| 522 void Editor::replaceSelectionWithText(const String& text, bool selectReplacement
, bool smartReplace) | 522 void Editor::replaceSelectionWithText(const String& text, bool selectReplacement
, bool smartReplace) |
| 523 { | 523 { |
| 524 replaceSelectionWithFragment(createFragmentFromText(selectedRange(), text),
selectReplacement, smartReplace, true); | 524 replaceSelectionWithFragment(createFragmentFromText(selectedRange(), text),
selectReplacement, smartReplace, true); |
| 525 } | 525 } |
| 526 | 526 |
| 527 // TODO(xiaochengh): Merge it with |replaceSelectionWithFragment()|. | 527 // TODO(xiaochengh): Merge it with |replaceSelectionWithFragment()|. |
| 528 void Editor::replaceSelectionAfterDragging(DocumentFragment* fragment, bool smar
tReplace, bool plainText) | 528 void Editor::replaceSelectionAfterDragging(DocumentFragment* fragment, bool smar
tReplace, bool plainText) |
| 529 { | 529 { |
| 530 ReplaceSelectionCommand::CommandOptions options = ReplaceSelectionCommand::S
electReplacement | ReplaceSelectionCommand::PreventNesting; | 530 ReplaceSelectionCommand::CommandOptions options = ReplaceSelectionCommand::S
electReplacement | ReplaceSelectionCommand::PreventNesting; |
| 531 if (smartReplace) | 531 if (smartReplace) |
| 532 options |= ReplaceSelectionCommand::SmartReplace; | 532 options |= ReplaceSelectionCommand::SmartReplace; |
| 533 if (plainText) | 533 if (plainText) |
| 534 options |= ReplaceSelectionCommand::MatchStyle; | 534 options |= ReplaceSelectionCommand::MatchStyle; |
| 535 ASSERT(frame().document()); | 535 DCHECK(frame().document()); |
| 536 ReplaceSelectionCommand::create(*frame().document(), fragment, options, Edit
ActionDrag)->apply(); | 536 ReplaceSelectionCommand::create(*frame().document(), fragment, options, Edit
ActionDrag)->apply(); |
| 537 } | 537 } |
| 538 | 538 |
| 539 void Editor::moveSelectionAfterDragging(DocumentFragment* fragment, const Positi
on& pos, bool smartInsert, bool smartDelete) | 539 void Editor::moveSelectionAfterDragging(DocumentFragment* fragment, const Positi
on& pos, bool smartInsert, bool smartDelete) |
| 540 { | 540 { |
| 541 MoveSelectionCommand::create(fragment, pos, smartInsert, smartDelete)->apply
(); | 541 MoveSelectionCommand::create(fragment, pos, smartInsert, smartDelete)->apply
(); |
| 542 } | 542 } |
| 543 | 543 |
| 544 EphemeralRange Editor::selectedRange() | 544 EphemeralRange Editor::selectedRange() |
| 545 { | 545 { |
| (...skipping 21 matching lines...) Expand all Loading... |
| 567 if (AXObjectCache* cache = frame().document()->existingAXObjectCache()) | 567 if (AXObjectCache* cache = frame().document()->existingAXObjectCache()) |
| 568 cache->handleEditableTextContentChanged(node); | 568 cache->handleEditableTextContentChanged(node); |
| 569 } | 569 } |
| 570 | 570 |
| 571 spellChecker().updateMarkersForWordsAffectedByEditing(true); | 571 spellChecker().updateMarkersForWordsAffectedByEditing(true); |
| 572 client().respondToChangedContents(); | 572 client().respondToChangedContents(); |
| 573 } | 573 } |
| 574 | 574 |
| 575 void Editor::removeFormattingAndStyle() | 575 void Editor::removeFormattingAndStyle() |
| 576 { | 576 { |
| 577 ASSERT(frame().document()); | 577 DCHECK(frame().document()); |
| 578 RemoveFormatCommand::create(*frame().document())->apply(); | 578 RemoveFormatCommand::create(*frame().document())->apply(); |
| 579 } | 579 } |
| 580 | 580 |
| 581 void Editor::clearLastEditCommand() | 581 void Editor::clearLastEditCommand() |
| 582 { | 582 { |
| 583 m_lastEditCommand.clear(); | 583 m_lastEditCommand.clear(); |
| 584 } | 584 } |
| 585 | 585 |
| 586 Element* Editor::findEventTargetFrom(const VisibleSelection& selection) const | 586 Element* Editor::findEventTargetFrom(const VisibleSelection& selection) const |
| 587 { | 587 { |
| (...skipping 13 matching lines...) Expand all Loading... |
| 601 { | 601 { |
| 602 switch (frame().selection().getSelectionType()) { | 602 switch (frame().selection().getSelectionType()) { |
| 603 case NoSelection: | 603 case NoSelection: |
| 604 // do nothing | 604 // do nothing |
| 605 break; | 605 break; |
| 606 case CaretSelection: | 606 case CaretSelection: |
| 607 computeAndSetTypingStyle(style, editingAction); | 607 computeAndSetTypingStyle(style, editingAction); |
| 608 break; | 608 break; |
| 609 case RangeSelection: | 609 case RangeSelection: |
| 610 if (style) { | 610 if (style) { |
| 611 ASSERT(frame().document()); | 611 DCHECK(frame().document()); |
| 612 ApplyStyleCommand::create(*frame().document(), EditingStyle::create(
style), editingAction)->apply(); | 612 ApplyStyleCommand::create(*frame().document(), EditingStyle::create(
style), editingAction)->apply(); |
| 613 } | 613 } |
| 614 break; | 614 break; |
| 615 } | 615 } |
| 616 } | 616 } |
| 617 | 617 |
| 618 void Editor::applyParagraphStyle(StylePropertySet* style, EditAction editingActi
on) | 618 void Editor::applyParagraphStyle(StylePropertySet* style, EditAction editingActi
on) |
| 619 { | 619 { |
| 620 if (frame().selection().isNone() || !style) | 620 if (frame().selection().isNone() || !style) |
| 621 return; | 621 return; |
| 622 ASSERT(frame().document()); | 622 DCHECK(frame().document()); |
| 623 ApplyStyleCommand::create(*frame().document(), EditingStyle::create(style),
editingAction, ApplyStyleCommand::ForceBlockProperties)->apply(); | 623 ApplyStyleCommand::create(*frame().document(), EditingStyle::create(style),
editingAction, ApplyStyleCommand::ForceBlockProperties)->apply(); |
| 624 } | 624 } |
| 625 | 625 |
| 626 void Editor::applyStyleToSelection(StylePropertySet* style, EditAction editingAc
tion) | 626 void Editor::applyStyleToSelection(StylePropertySet* style, EditAction editingAc
tion) |
| 627 { | 627 { |
| 628 if (!style || style->isEmpty() || !canEditRichly()) | 628 if (!style || style->isEmpty() || !canEditRichly()) |
| 629 return; | 629 return; |
| 630 | 630 |
| 631 applyStyle(style, editingAction); | 631 applyStyle(style, editingAction); |
| 632 } | 632 } |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 674 { | 674 { |
| 675 // Note: Request spell checking for and only for |ReplaceSelectionCommand|s | 675 // Note: Request spell checking for and only for |ReplaceSelectionCommand|s |
| 676 // created in |Editor::replaceSelectionWithFragment()|. | 676 // created in |Editor::replaceSelectionWithFragment()|. |
| 677 // TODO(xiaochengh): May also need to do this after dragging crbug.com/29804
6. | 677 // TODO(xiaochengh): May also need to do this after dragging crbug.com/29804
6. |
| 678 if (cmd->editingAction() != EditActionPaste) | 678 if (cmd->editingAction() != EditActionPaste) |
| 679 return; | 679 return; |
| 680 if (!spellChecker().isContinuousSpellCheckingEnabled()) | 680 if (!spellChecker().isContinuousSpellCheckingEnabled()) |
| 681 return; | 681 return; |
| 682 if (!SpellChecker::isSpellCheckingEnabledFor(cmd->endingSelection())) | 682 if (!SpellChecker::isSpellCheckingEnabledFor(cmd->endingSelection())) |
| 683 return; | 683 return; |
| 684 ASSERT(cmd->isReplaceSelectionCommand()); | 684 DCHECK(cmd->isReplaceSelectionCommand()); |
| 685 const EphemeralRange& insertedRange = toReplaceSelectionCommand(cmd)->insert
edRange(); | 685 const EphemeralRange& insertedRange = toReplaceSelectionCommand(cmd)->insert
edRange(); |
| 686 if (insertedRange.isNull()) | 686 if (insertedRange.isNull()) |
| 687 return; | 687 return; |
| 688 spellChecker().chunkAndMarkAllMisspellingsAndBadGrammar(cmd->endingSelection
().rootEditableElement(), insertedRange); | 688 spellChecker().chunkAndMarkAllMisspellingsAndBadGrammar(cmd->endingSelection
().rootEditableElement(), insertedRange); |
| 689 } | 689 } |
| 690 | 690 |
| 691 void Editor::appliedEditing(CompositeEditCommand* cmd) | 691 void Editor::appliedEditing(CompositeEditCommand* cmd) |
| 692 { | 692 { |
| 693 EventQueueScope scope; | 693 EventQueueScope scope; |
| 694 frame().document()->updateLayout(); | 694 frame().document()->updateLayout(); |
| 695 | 695 |
| 696 // Request spell checking after pasting before any further DOM change. | 696 // Request spell checking after pasting before any further DOM change. |
| 697 requestSpellcheckingAfterApplyingCommand(cmd); | 697 requestSpellcheckingAfterApplyingCommand(cmd); |
| 698 | 698 |
| 699 EditCommandComposition* composition = cmd->composition(); | 699 EditCommandComposition* composition = cmd->composition(); |
| 700 ASSERT(composition); | 700 DCHECK(composition); |
| 701 dispatchEditableContentChangedEvents(composition->startingRootEditableElemen
t(), composition->endingRootEditableElement()); | 701 dispatchEditableContentChangedEvents(composition->startingRootEditableElemen
t(), composition->endingRootEditableElement()); |
| 702 VisibleSelection newSelection(cmd->endingSelection()); | 702 VisibleSelection newSelection(cmd->endingSelection()); |
| 703 | 703 |
| 704 // Don't clear the typing style with this selection change. We do those thin
gs elsewhere if necessary. | 704 // Don't clear the typing style with this selection change. We do those thin
gs elsewhere if necessary. |
| 705 changeSelectionAfterCommand(newSelection, 0); | 705 changeSelectionAfterCommand(newSelection, 0); |
| 706 | 706 |
| 707 if (!cmd->preservesTypingStyle()) | 707 if (!cmd->preservesTypingStyle()) |
| 708 frame().selection().clearTypingStyle(); | 708 frame().selection().clearTypingStyle(); |
| 709 | 709 |
| 710 // Command will be equal to last edit command only in the case of typing | 710 // Command will be equal to last edit command only in the case of typing |
| 711 if (m_lastEditCommand.get() == cmd) { | 711 if (m_lastEditCommand.get() == cmd) { |
| 712 ASSERT(cmd->isTypingCommand()); | 712 DCHECK(cmd->isTypingCommand()); |
| 713 } else { | 713 } else { |
| 714 // Only register a new undo command if the command passed in is | 714 // Only register a new undo command if the command passed in is |
| 715 // different from the last command | 715 // different from the last command |
| 716 m_lastEditCommand = cmd; | 716 m_lastEditCommand = cmd; |
| 717 if (UndoStack* undoStack = this->undoStack()) | 717 if (UndoStack* undoStack = this->undoStack()) |
| 718 undoStack->registerUndoStep(m_lastEditCommand->ensureComposition()); | 718 undoStack->registerUndoStep(m_lastEditCommand->ensureComposition()); |
| 719 } | 719 } |
| 720 | 720 |
| 721 respondToChangedContents(newSelection); | 721 respondToChangedContents(newSelection); |
| 722 } | 722 } |
| (...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 814 return true; | 814 return true; |
| 815 } | 815 } |
| 816 | 816 |
| 817 bool Editor::insertLineBreak() | 817 bool Editor::insertLineBreak() |
| 818 { | 818 { |
| 819 if (!canEdit()) | 819 if (!canEdit()) |
| 820 return false; | 820 return false; |
| 821 | 821 |
| 822 VisiblePosition caret = frame().selection().selection().visibleStart(); | 822 VisiblePosition caret = frame().selection().selection().visibleStart(); |
| 823 bool alignToEdge = isEndOfEditableOrNonEditableContent(caret); | 823 bool alignToEdge = isEndOfEditableOrNonEditableContent(caret); |
| 824 ASSERT(frame().document()); | 824 DCHECK(frame().document()); |
| 825 if (!TypingCommand::insertLineBreak(*frame().document())) | 825 if (!TypingCommand::insertLineBreak(*frame().document())) |
| 826 return false; | 826 return false; |
| 827 revealSelectionAfterEditingOperation(alignToEdge ? ScrollAlignment::alignToE
dgeIfNeeded : ScrollAlignment::alignCenterIfNeeded); | 827 revealSelectionAfterEditingOperation(alignToEdge ? ScrollAlignment::alignToE
dgeIfNeeded : ScrollAlignment::alignCenterIfNeeded); |
| 828 | 828 |
| 829 return true; | 829 return true; |
| 830 } | 830 } |
| 831 | 831 |
| 832 bool Editor::insertParagraphSeparator() | 832 bool Editor::insertParagraphSeparator() |
| 833 { | 833 { |
| 834 if (!canEdit()) | 834 if (!canEdit()) |
| 835 return false; | 835 return false; |
| 836 | 836 |
| 837 if (!canEditRichly()) | 837 if (!canEditRichly()) |
| 838 return insertLineBreak(); | 838 return insertLineBreak(); |
| 839 | 839 |
| 840 VisiblePosition caret = frame().selection().selection().visibleStart(); | 840 VisiblePosition caret = frame().selection().selection().visibleStart(); |
| 841 bool alignToEdge = isEndOfEditableOrNonEditableContent(caret); | 841 bool alignToEdge = isEndOfEditableOrNonEditableContent(caret); |
| 842 ASSERT(frame().document()); | 842 DCHECK(frame().document()); |
| 843 EditingState editingState; | 843 EditingState editingState; |
| 844 if (!TypingCommand::insertParagraphSeparator(*frame().document())) | 844 if (!TypingCommand::insertParagraphSeparator(*frame().document())) |
| 845 return false; | 845 return false; |
| 846 revealSelectionAfterEditingOperation(alignToEdge ? ScrollAlignment::alignToE
dgeIfNeeded : ScrollAlignment::alignCenterIfNeeded); | 846 revealSelectionAfterEditingOperation(alignToEdge ? ScrollAlignment::alignToE
dgeIfNeeded : ScrollAlignment::alignCenterIfNeeded); |
| 847 | 847 |
| 848 return true; | 848 return true; |
| 849 } | 849 } |
| 850 | 850 |
| 851 void Editor::cut() | 851 void Editor::cut() |
| 852 { | 852 { |
| (...skipping 28 matching lines...) Expand all Loading... |
| 881 Document* document = frame().document(); | 881 Document* document = frame().document(); |
| 882 if (HTMLImageElement* imageElement = imageElementFromImageDocument(docum
ent)) | 882 if (HTMLImageElement* imageElement = imageElementFromImageDocument(docum
ent)) |
| 883 writeImageNodeToPasteboard(Pasteboard::generalPasteboard(), imageEle
ment, document->title()); | 883 writeImageNodeToPasteboard(Pasteboard::generalPasteboard(), imageEle
ment, document->title()); |
| 884 else | 884 else |
| 885 writeSelectionToPasteboard(); | 885 writeSelectionToPasteboard(); |
| 886 } | 886 } |
| 887 } | 887 } |
| 888 | 888 |
| 889 void Editor::paste() | 889 void Editor::paste() |
| 890 { | 890 { |
| 891 ASSERT(frame().document()); | 891 DCHECK(frame().document()); |
| 892 if (tryDHTMLPaste(AllMimeTypes)) | 892 if (tryDHTMLPaste(AllMimeTypes)) |
| 893 return; // DHTML did the whole operation | 893 return; // DHTML did the whole operation |
| 894 if (!canPaste()) | 894 if (!canPaste()) |
| 895 return; | 895 return; |
| 896 spellChecker().updateMarkersForWordsAffectedByEditing(false); | 896 spellChecker().updateMarkersForWordsAffectedByEditing(false); |
| 897 ResourceFetcher* loader = frame().document()->fetcher(); | 897 ResourceFetcher* loader = frame().document()->fetcher(); |
| 898 ResourceCacheValidationSuppressor validationSuppressor(loader); | 898 ResourceCacheValidationSuppressor validationSuppressor(loader); |
| 899 if (frame().selection().isContentRichlyEditable()) | 899 if (frame().selection().isContentRichlyEditable()) |
| 900 pasteWithPasteboard(Pasteboard::generalPasteboard()); | 900 pasteWithPasteboard(Pasteboard::generalPasteboard()); |
| 901 else | 901 else |
| (...skipping 207 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1109 // change the caret's DOM position (["hello", 0]). In these situations the a
bove FrameSelection::setSelection call | 1109 // change the caret's DOM position (["hello", 0]). In these situations the a
bove FrameSelection::setSelection call |
| 1110 // does not call EditorClient::respondToChangedSelection(), which, on the Ma
c, sends selection change notifications and | 1110 // does not call EditorClient::respondToChangedSelection(), which, on the Ma
c, sends selection change notifications and |
| 1111 // starts a new kill ring sequence, but we want to do these things (matches
AppKit). | 1111 // starts a new kill ring sequence, but we want to do these things (matches
AppKit). |
| 1112 if (selectionDidNotChangeDOMPosition) | 1112 if (selectionDidNotChangeDOMPosition) |
| 1113 client().respondToChangedSelection(m_frame, frame().selection().getSelec
tionType()); | 1113 client().respondToChangedSelection(m_frame, frame().selection().getSelec
tionType()); |
| 1114 } | 1114 } |
| 1115 | 1115 |
| 1116 IntRect Editor::firstRectForRange(const EphemeralRange& range) const | 1116 IntRect Editor::firstRectForRange(const EphemeralRange& range) const |
| 1117 { | 1117 { |
| 1118 LayoutUnit extraWidthToEndOfLine; | 1118 LayoutUnit extraWidthToEndOfLine; |
| 1119 ASSERT(range.isNotNull()); | 1119 DCHECK(range.isNotNull()); |
| 1120 | 1120 |
| 1121 IntRect startCaretRect = RenderedPosition(createVisiblePosition(range.startP
osition()).deepEquivalent(), TextAffinity::Downstream).absoluteRect(&extraWidthT
oEndOfLine); | 1121 IntRect startCaretRect = RenderedPosition(createVisiblePosition(range.startP
osition()).deepEquivalent(), TextAffinity::Downstream).absoluteRect(&extraWidthT
oEndOfLine); |
| 1122 if (startCaretRect.isEmpty()) | 1122 if (startCaretRect.isEmpty()) |
| 1123 return IntRect(); | 1123 return IntRect(); |
| 1124 | 1124 |
| 1125 IntRect endCaretRect = RenderedPosition(createVisiblePosition(range.endPosit
ion()).deepEquivalent(), TextAffinity::Upstream).absoluteRect(); | 1125 IntRect endCaretRect = RenderedPosition(createVisiblePosition(range.endPosit
ion()).deepEquivalent(), TextAffinity::Upstream).absoluteRect(); |
| 1126 if (endCaretRect.isEmpty()) | 1126 if (endCaretRect.isEmpty()) |
| 1127 return IntRect(); | 1127 return IntRect(); |
| 1128 | 1128 |
| 1129 if (startCaretRect.y() == endCaretRect.y()) { | 1129 if (startCaretRect.y() == endCaretRect.y()) { |
| 1130 // start and end are on the same line | 1130 // start and end are on the same line |
| 1131 return IntRect(std::min(startCaretRect.x(), endCaretRect.x()), | 1131 return IntRect(std::min(startCaretRect.x(), endCaretRect.x()), |
| 1132 startCaretRect.y(), | 1132 startCaretRect.y(), |
| 1133 abs(endCaretRect.x() - startCaretRect.x()), | 1133 abs(endCaretRect.x() - startCaretRect.x()), |
| 1134 std::max(startCaretRect.height(), endCaretRect.height())); | 1134 std::max(startCaretRect.height(), endCaretRect.height())); |
| 1135 } | 1135 } |
| 1136 | 1136 |
| 1137 // start and end aren't on the same line, so go from start to the end of its
line | 1137 // start and end aren't on the same line, so go from start to the end of its
line |
| 1138 return IntRect(startCaretRect.x(), | 1138 return IntRect(startCaretRect.x(), |
| 1139 startCaretRect.y(), | 1139 startCaretRect.y(), |
| 1140 startCaretRect.width() + extraWidthToEndOfLine, | 1140 startCaretRect.width() + extraWidthToEndOfLine, |
| 1141 startCaretRect.height()); | 1141 startCaretRect.height()); |
| 1142 } | 1142 } |
| 1143 | 1143 |
| 1144 IntRect Editor::firstRectForRange(const Range* range) const | 1144 IntRect Editor::firstRectForRange(const Range* range) const |
| 1145 { | 1145 { |
| 1146 ASSERT(range); | 1146 DCHECK(range); |
| 1147 return firstRectForRange(EphemeralRange(range)); | 1147 return firstRectForRange(EphemeralRange(range)); |
| 1148 } | 1148 } |
| 1149 | 1149 |
| 1150 void Editor::computeAndSetTypingStyle(StylePropertySet* style, EditAction editin
gAction) | 1150 void Editor::computeAndSetTypingStyle(StylePropertySet* style, EditAction editin
gAction) |
| 1151 { | 1151 { |
| 1152 if (!style || style->isEmpty()) { | 1152 if (!style || style->isEmpty()) { |
| 1153 frame().selection().clearTypingStyle(); | 1153 frame().selection().clearTypingStyle(); |
| 1154 return; | 1154 return; |
| 1155 } | 1155 } |
| 1156 | 1156 |
| 1157 // Calculate the current typing style. | 1157 // Calculate the current typing style. |
| 1158 EditingStyle* typingStyle = nullptr; | 1158 EditingStyle* typingStyle = nullptr; |
| 1159 if (frame().selection().typingStyle()) { | 1159 if (frame().selection().typingStyle()) { |
| 1160 typingStyle = frame().selection().typingStyle()->copy(); | 1160 typingStyle = frame().selection().typingStyle()->copy(); |
| 1161 typingStyle->overrideWithStyle(style); | 1161 typingStyle->overrideWithStyle(style); |
| 1162 } else { | 1162 } else { |
| 1163 typingStyle = EditingStyle::create(style); | 1163 typingStyle = EditingStyle::create(style); |
| 1164 } | 1164 } |
| 1165 | 1165 |
| 1166 typingStyle->prepareToApplyAt(frame().selection().selection().visibleStart()
.deepEquivalent(), EditingStyle::PreserveWritingDirection); | 1166 typingStyle->prepareToApplyAt(frame().selection().selection().visibleStart()
.deepEquivalent(), EditingStyle::PreserveWritingDirection); |
| 1167 | 1167 |
| 1168 // Handle block styles, substracting these from the typing style. | 1168 // Handle block styles, substracting these from the typing style. |
| 1169 EditingStyle* blockStyle = typingStyle->extractAndRemoveBlockProperties(); | 1169 EditingStyle* blockStyle = typingStyle->extractAndRemoveBlockProperties(); |
| 1170 if (!blockStyle->isEmpty()) { | 1170 if (!blockStyle->isEmpty()) { |
| 1171 ASSERT(frame().document()); | 1171 DCHECK(frame().document()); |
| 1172 ApplyStyleCommand::create(*frame().document(), blockStyle, editingAction
)->apply(); | 1172 ApplyStyleCommand::create(*frame().document(), blockStyle, editingAction
)->apply(); |
| 1173 } | 1173 } |
| 1174 | 1174 |
| 1175 // Set the remaining style as the typing style. | 1175 // Set the remaining style as the typing style. |
| 1176 frame().selection().setTypingStyle(typingStyle); | 1176 frame().selection().setTypingStyle(typingStyle); |
| 1177 } | 1177 } |
| 1178 | 1178 |
| 1179 bool Editor::findString(const String& target, FindOptions options) | 1179 bool Editor::findString(const String& target, FindOptions options) |
| 1180 { | 1180 { |
| 1181 VisibleSelection selection = frame().selection().selection(); | 1181 VisibleSelection selection = frame().selection().selection(); |
| (...skipping 171 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1353 if (existingHead) | 1353 if (existingHead) |
| 1354 root->appendChild(existingHead); | 1354 root->appendChild(existingHead); |
| 1355 Element* body = nullptr; | 1355 Element* body = nullptr; |
| 1356 if (existingBody) | 1356 if (existingBody) |
| 1357 body = existingBody; | 1357 body = existingBody; |
| 1358 else | 1358 else |
| 1359 body = HTMLBodyElement::create(document); | 1359 body = HTMLBodyElement::create(document); |
| 1360 if (document.documentElement() && body != document.documentElement()) | 1360 if (document.documentElement() && body != document.documentElement()) |
| 1361 body->appendChild(document.documentElement()); | 1361 body->appendChild(document.documentElement()); |
| 1362 root->appendChild(body); | 1362 root->appendChild(body); |
| 1363 ASSERT(!document.documentElement()); | 1363 DCHECK(!document.documentElement()); |
| 1364 document.appendChild(root); | 1364 document.appendChild(root); |
| 1365 | 1365 |
| 1366 // TODO(tkent): Should we check and move Text node children of <html>? | 1366 // TODO(tkent): Should we check and move Text node children of <html>? |
| 1367 } | 1367 } |
| 1368 | 1368 |
| 1369 DEFINE_TRACE(Editor) | 1369 DEFINE_TRACE(Editor) |
| 1370 { | 1370 { |
| 1371 visitor->trace(m_frame); | 1371 visitor->trace(m_frame); |
| 1372 visitor->trace(m_lastEditCommand); | 1372 visitor->trace(m_lastEditCommand); |
| 1373 visitor->trace(m_mark); | 1373 visitor->trace(m_mark); |
| 1374 } | 1374 } |
| 1375 | 1375 |
| 1376 } // namespace blink | 1376 } // namespace blink |
| OLD | NEW |