| 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 408 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 419 void Editor::writeSelectionToPasteboard() | 419 void Editor::writeSelectionToPasteboard() |
| 420 { | 420 { |
| 421 KURL url = frame().document()->url(); | 421 KURL url = frame().document()->url(); |
| 422 String html = frame().selection().selectedHTMLForClipboard(); | 422 String html = frame().selection().selectedHTMLForClipboard(); |
| 423 String plainText = frame().selectedTextForClipboard(); | 423 String plainText = frame().selectedTextForClipboard(); |
| 424 Pasteboard::generalPasteboard()->writeHTML(html, url, plainText, canSmartCop
yOrDelete()); | 424 Pasteboard::generalPasteboard()->writeHTML(html, url, plainText, canSmartCop
yOrDelete()); |
| 425 } | 425 } |
| 426 | 426 |
| 427 static PassRefPtr<Image> imageFromNode(const Node& node) | 427 static PassRefPtr<Image> imageFromNode(const Node& node) |
| 428 { | 428 { |
| 429 node.document().updateLayoutIgnorePendingStylesheets(); | 429 node.document().updateStyleAndLayoutIgnorePendingStylesheets(); |
| 430 LayoutObject* layoutObject = node.layoutObject(); | 430 LayoutObject* layoutObject = node.layoutObject(); |
| 431 if (!layoutObject) | 431 if (!layoutObject) |
| 432 return nullptr; | 432 return nullptr; |
| 433 | 433 |
| 434 if (layoutObject->isCanvas()) | 434 if (layoutObject->isCanvas()) |
| 435 return toHTMLCanvasElement(node).copiedImage(FrontBuffer, PreferNoAccele
ration); | 435 return toHTMLCanvasElement(node).copiedImage(FrontBuffer, PreferNoAccele
ration); |
| 436 | 436 |
| 437 if (layoutObject->isImage()) { | 437 if (layoutObject->isImage()) { |
| 438 LayoutImage* layoutImage = toLayoutImage(layoutObject); | 438 LayoutImage* layoutImage = toLayoutImage(layoutObject); |
| 439 if (!layoutImage) | 439 if (!layoutImage) |
| (...skipping 244 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 684 DCHECK(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()->updateStyleAndLayout(); |
| 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 DCHECK(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. |
| (...skipping 12 matching lines...) Expand all Loading... |
| 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 } |
| 723 | 723 |
| 724 void Editor::unappliedEditing(EditCommandComposition* cmd) | 724 void Editor::unappliedEditing(EditCommandComposition* cmd) |
| 725 { | 725 { |
| 726 EventQueueScope scope; | 726 EventQueueScope scope; |
| 727 frame().document()->updateLayout(); | 727 frame().document()->updateStyleAndLayout(); |
| 728 | 728 |
| 729 dispatchEditableContentChangedEvents(cmd->startingRootEditableElement(), cmd
->endingRootEditableElement()); | 729 dispatchEditableContentChangedEvents(cmd->startingRootEditableElement(), cmd
->endingRootEditableElement()); |
| 730 | 730 |
| 731 VisibleSelection newSelection(cmd->startingSelection()); | 731 VisibleSelection newSelection(cmd->startingSelection()); |
| 732 newSelection.validatePositionsIfNeeded(); | 732 newSelection.validatePositionsIfNeeded(); |
| 733 if (newSelection.start().document() == frame().document() && newSelection.en
d().document() == frame().document()) | 733 if (newSelection.start().document() == frame().document() && newSelection.en
d().document() == frame().document()) |
| 734 changeSelectionAfterCommand(newSelection, FrameSelection::CloseTyping |
FrameSelection::ClearTypingStyle); | 734 changeSelectionAfterCommand(newSelection, FrameSelection::CloseTyping |
FrameSelection::ClearTypingStyle); |
| 735 | 735 |
| 736 m_lastEditCommand = nullptr; | 736 m_lastEditCommand = nullptr; |
| 737 if (UndoStack* undoStack = this->undoStack()) | 737 if (UndoStack* undoStack = this->undoStack()) |
| 738 undoStack->registerRedoStep(cmd); | 738 undoStack->registerRedoStep(cmd); |
| 739 respondToChangedContents(newSelection); | 739 respondToChangedContents(newSelection); |
| 740 } | 740 } |
| 741 | 741 |
| 742 void Editor::reappliedEditing(EditCommandComposition* cmd) | 742 void Editor::reappliedEditing(EditCommandComposition* cmd) |
| 743 { | 743 { |
| 744 EventQueueScope scope; | 744 EventQueueScope scope; |
| 745 frame().document()->updateLayout(); | 745 frame().document()->updateStyleAndLayout(); |
| 746 | 746 |
| 747 dispatchEditableContentChangedEvents(cmd->startingRootEditableElement(), cmd
->endingRootEditableElement()); | 747 dispatchEditableContentChangedEvents(cmd->startingRootEditableElement(), cmd
->endingRootEditableElement()); |
| 748 | 748 |
| 749 VisibleSelection newSelection(cmd->endingSelection()); | 749 VisibleSelection newSelection(cmd->endingSelection()); |
| 750 changeSelectionAfterCommand(newSelection, FrameSelection::CloseTyping | Fram
eSelection::ClearTypingStyle); | 750 changeSelectionAfterCommand(newSelection, FrameSelection::CloseTyping | Fram
eSelection::ClearTypingStyle); |
| 751 | 751 |
| 752 m_lastEditCommand = nullptr; | 752 m_lastEditCommand = nullptr; |
| 753 if (UndoStack* undoStack = this->undoStack()) | 753 if (UndoStack* undoStack = this->undoStack()) |
| 754 undoStack->registerUndoStep(cmd); | 754 undoStack->registerUndoStep(cmd); |
| 755 respondToChangedContents(newSelection); | 755 respondToChangedContents(newSelection); |
| (...skipping 265 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1021 } | 1021 } |
| 1022 | 1022 |
| 1023 void Editor::setBaseWritingDirection(WritingDirection direction) | 1023 void Editor::setBaseWritingDirection(WritingDirection direction) |
| 1024 { | 1024 { |
| 1025 Element* focusedElement = frame().document()->focusedElement(); | 1025 Element* focusedElement = frame().document()->focusedElement(); |
| 1026 if (isHTMLTextFormControlElement(focusedElement)) { | 1026 if (isHTMLTextFormControlElement(focusedElement)) { |
| 1027 if (direction == NaturalWritingDirection) | 1027 if (direction == NaturalWritingDirection) |
| 1028 return; | 1028 return; |
| 1029 focusedElement->setAttribute(dirAttr, direction == LeftToRightWritingDir
ection ? "ltr" : "rtl"); | 1029 focusedElement->setAttribute(dirAttr, direction == LeftToRightWritingDir
ection ? "ltr" : "rtl"); |
| 1030 focusedElement->dispatchInputEvent(); | 1030 focusedElement->dispatchInputEvent(); |
| 1031 frame().document()->updateLayoutTree(); | 1031 frame().document()->updateStyleAndLayoutTree(); |
| 1032 return; | 1032 return; |
| 1033 } | 1033 } |
| 1034 | 1034 |
| 1035 MutableStylePropertySet* style = MutableStylePropertySet::create(HTMLQuirksM
ode); | 1035 MutableStylePropertySet* style = MutableStylePropertySet::create(HTMLQuirksM
ode); |
| 1036 style->setProperty(CSSPropertyDirection, direction == LeftToRightWritingDire
ction ? "ltr" : direction == RightToLeftWritingDirection ? "rtl" : "inherit", fa
lse); | 1036 style->setProperty(CSSPropertyDirection, direction == LeftToRightWritingDire
ction ? "ltr" : direction == RightToLeftWritingDirection ? "rtl" : "inherit", fa
lse); |
| 1037 applyParagraphStyleToSelection(style, EditActionSetWritingDirection); | 1037 applyParagraphStyleToSelection(style, EditActionSetWritingDirection); |
| 1038 } | 1038 } |
| 1039 | 1039 |
| 1040 void Editor::revealSelectionAfterEditingOperation(const ScrollAlignment& alignme
nt, RevealExtentOption revealExtentOption) | 1040 void Editor::revealSelectionAfterEditingOperation(const ScrollAlignment& alignme
nt, RevealExtentOption revealExtentOption) |
| 1041 { | 1041 { |
| (...skipping 277 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1319 | 1319 |
| 1320 void Editor::toggleOverwriteModeEnabled() | 1320 void Editor::toggleOverwriteModeEnabled() |
| 1321 { | 1321 { |
| 1322 m_overwriteModeEnabled = !m_overwriteModeEnabled; | 1322 m_overwriteModeEnabled = !m_overwriteModeEnabled; |
| 1323 frame().selection().setShouldShowBlockCursor(m_overwriteModeEnabled); | 1323 frame().selection().setShouldShowBlockCursor(m_overwriteModeEnabled); |
| 1324 } | 1324 } |
| 1325 | 1325 |
| 1326 void Editor::tidyUpHTMLStructure(Document& document) | 1326 void Editor::tidyUpHTMLStructure(Document& document) |
| 1327 { | 1327 { |
| 1328 // hasEditableStyle() needs up-to-date ComputedStyle. | 1328 // hasEditableStyle() needs up-to-date ComputedStyle. |
| 1329 document.updateLayoutTree(); | 1329 document.updateStyleAndLayoutTree(); |
| 1330 bool needsValidStructure = document.hasEditableStyle() || (document.document
Element() && document.documentElement()->hasEditableStyle()); | 1330 bool needsValidStructure = document.hasEditableStyle() || (document.document
Element() && document.documentElement()->hasEditableStyle()); |
| 1331 if (!needsValidStructure) | 1331 if (!needsValidStructure) |
| 1332 return; | 1332 return; |
| 1333 Element* existingHead = nullptr; | 1333 Element* existingHead = nullptr; |
| 1334 Element* existingBody = nullptr; | 1334 Element* existingBody = nullptr; |
| 1335 Element* currentRoot = document.documentElement(); | 1335 Element* currentRoot = document.documentElement(); |
| 1336 if (currentRoot) { | 1336 if (currentRoot) { |
| 1337 if (isHTMLHtmlElement(currentRoot)) | 1337 if (isHTMLHtmlElement(currentRoot)) |
| 1338 return; | 1338 return; |
| 1339 if (isHTMLHeadElement(currentRoot)) | 1339 if (isHTMLHeadElement(currentRoot)) |
| (...skipping 27 matching lines...) Expand all Loading... |
| 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 |