| 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 264 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 275 { | 275 { |
| 276 return canEdit(); | 276 return canEdit(); |
| 277 } | 277 } |
| 278 | 278 |
| 279 bool Editor::canDelete() const | 279 bool Editor::canDelete() const |
| 280 { | 280 { |
| 281 FrameSelection& selection = frame().selection(); | 281 FrameSelection& selection = frame().selection(); |
| 282 return selection.isRange() && selection.rootEditableElement(); | 282 return selection.isRange() && selection.rootEditableElement(); |
| 283 } | 283 } |
| 284 | 284 |
| 285 // TODO(xiaochengh): Merge it with |shouldDeleteRange|. | |
| 286 bool Editor::canDeleteRange(const EphemeralRange& range) const | |
| 287 { | |
| 288 DCHECK(!range.isCollapsed()) << range.startPosition(); | |
| 289 | |
| 290 Node* startContainer = range.startPosition().computeContainerNode(); | |
| 291 Node* endContainer = range.endPosition().computeContainerNode(); | |
| 292 if (!startContainer || !endContainer) | |
| 293 return false; | |
| 294 | |
| 295 return hasEditableStyle(*startContainer) && hasEditableStyle(*endContainer); | |
| 296 } | |
| 297 | |
| 298 bool Editor::smartInsertDeleteEnabled() const | 285 bool Editor::smartInsertDeleteEnabled() const |
| 299 { | 286 { |
| 300 if (Settings* settings = frame().settings()) | 287 if (Settings* settings = frame().settings()) |
| 301 return settings->smartInsertDeleteEnabled(); | 288 return settings->smartInsertDeleteEnabled(); |
| 302 return false; | 289 return false; |
| 303 } | 290 } |
| 304 | 291 |
| 305 bool Editor::canSmartCopyOrDelete() const | 292 bool Editor::canSmartCopyOrDelete() const |
| 306 { | 293 { |
| 307 return smartInsertDeleteEnabled() && frame().selection().granularity() == Wo
rdGranularity; | 294 return smartInsertDeleteEnabled() && frame().selection().granularity() == Wo
rdGranularity; |
| (...skipping 262 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 570 void Editor::moveSelectionAfterDragging(DocumentFragment* fragment, const Positi
on& pos, bool smartInsert, bool smartDelete) | 557 void Editor::moveSelectionAfterDragging(DocumentFragment* fragment, const Positi
on& pos, bool smartInsert, bool smartDelete) |
| 571 { | 558 { |
| 572 MoveSelectionCommand::create(fragment, pos, smartInsert, smartDelete)->apply
(); | 559 MoveSelectionCommand::create(fragment, pos, smartInsert, smartDelete)->apply
(); |
| 573 } | 560 } |
| 574 | 561 |
| 575 EphemeralRange Editor::selectedRange() | 562 EphemeralRange Editor::selectedRange() |
| 576 { | 563 { |
| 577 return frame().selection().selection().toNormalizedEphemeralRange(); | 564 return frame().selection().selection().toNormalizedEphemeralRange(); |
| 578 } | 565 } |
| 579 | 566 |
| 580 bool Editor::shouldDeleteRange(const EphemeralRange& range) const | 567 bool Editor::canDeleteRange(const EphemeralRange& range) const |
| 581 { | 568 { |
| 582 if (range.isCollapsed()) | 569 if (range.isCollapsed()) |
| 583 return false; | 570 return false; |
| 584 | 571 |
| 585 return canDeleteRange(range); | 572 Node* startContainer = range.startPosition().computeContainerNode(); |
| 573 Node* endContainer = range.endPosition().computeContainerNode(); |
| 574 if (!startContainer || !endContainer) |
| 575 return false; |
| 576 |
| 577 return hasEditableStyle(*startContainer) && hasEditableStyle(*endContainer); |
| 586 } | 578 } |
| 587 | 579 |
| 588 void Editor::notifyComponentsOnChangedSelection() | 580 void Editor::notifyComponentsOnChangedSelection() |
| 589 { | 581 { |
| 590 client().respondToChangedSelection(m_frame, frame().selection().getSelection
Type()); | 582 client().respondToChangedSelection(m_frame, frame().selection().getSelection
Type()); |
| 591 setStartNewKillRingSequence(true); | 583 setStartNewKillRingSequence(true); |
| 592 } | 584 } |
| 593 | 585 |
| 594 void Editor::respondToChangedContents(const VisibleSelection& endingSelection) | 586 void Editor::respondToChangedContents(const VisibleSelection& endingSelection) |
| 595 { | 587 { |
| (...skipping 283 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 879 return true; | 871 return true; |
| 880 } | 872 } |
| 881 | 873 |
| 882 void Editor::cut(EditorCommandSource source) | 874 void Editor::cut(EditorCommandSource source) |
| 883 { | 875 { |
| 884 if (tryDHTMLCut()) | 876 if (tryDHTMLCut()) |
| 885 return; // DHTML did the whole operation | 877 return; // DHTML did the whole operation |
| 886 if (!canCut()) | 878 if (!canCut()) |
| 887 return; | 879 return; |
| 888 // TODO(yosin) We should use early return style here. | 880 // TODO(yosin) We should use early return style here. |
| 889 if (shouldDeleteRange(selectedRange())) { | 881 if (canDeleteRange(selectedRange())) { |
| 890 spellChecker().updateMarkersForWordsAffectedByEditing(true); | 882 spellChecker().updateMarkersForWordsAffectedByEditing(true); |
| 891 if (enclosingTextFormControl(frame().selection().start())) { | 883 if (enclosingTextFormControl(frame().selection().start())) { |
| 892 String plainText = frame().selectedTextForClipboard(); | 884 String plainText = frame().selectedTextForClipboard(); |
| 893 Pasteboard::generalPasteboard()->writePlainText(plainText, | 885 Pasteboard::generalPasteboard()->writePlainText(plainText, |
| 894 canSmartCopyOrDelete() ? Pasteboard::CanSmartReplace : Pasteboar
d::CannotSmartReplace); | 886 canSmartCopyOrDelete() ? Pasteboard::CanSmartReplace : Pasteboar
d::CannotSmartReplace); |
| 895 } else { | 887 } else { |
| 896 writeSelectionToPasteboard(); | 888 writeSelectionToPasteboard(); |
| 897 } | 889 } |
| 898 | 890 |
| 899 if (source == CommandFromMenuOrKeyBinding) { | 891 if (source == CommandFromMenuOrKeyBinding) { |
| (...skipping 528 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1428 | 1420 |
| 1429 DEFINE_TRACE(Editor) | 1421 DEFINE_TRACE(Editor) |
| 1430 { | 1422 { |
| 1431 visitor->trace(m_frame); | 1423 visitor->trace(m_frame); |
| 1432 visitor->trace(m_lastEditCommand); | 1424 visitor->trace(m_lastEditCommand); |
| 1433 visitor->trace(m_undoStack); | 1425 visitor->trace(m_undoStack); |
| 1434 visitor->trace(m_mark); | 1426 visitor->trace(m_mark); |
| 1435 } | 1427 } |
| 1436 | 1428 |
| 1437 } // namespace blink | 1429 } // namespace blink |
| OLD | NEW |