Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 /* | 1 /* |
| 2 * Copyright (C) 2005, 2006, 2007 Apple, Inc. All rights reserved. | 2 * Copyright (C) 2005, 2006, 2007 Apple, Inc. All rights reserved. |
| 3 * | 3 * |
| 4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
| 5 * modification, are permitted provided that the following conditions | 5 * modification, are permitted provided that the following conditions |
| 6 * are met: | 6 * are met: |
| 7 * 1. Redistributions of source code must retain the above copyright | 7 * 1. Redistributions of source code must retain the above copyright |
| 8 * notice, this list of conditions and the following disclaimer. | 8 * notice, this list of conditions and the following disclaimer. |
| 9 * 2. Redistributions in binary form must reproduce the above copyright | 9 * 2. Redistributions in binary form must reproduce the above copyright |
| 10 * notice, this list of conditions and the following disclaimer in the | 10 * notice, this list of conditions and the following disclaimer in the |
| (...skipping 20 matching lines...) Expand all Loading... | |
| 31 #include "core/editing/commands/CompositeEditCommand.h" | 31 #include "core/editing/commands/CompositeEditCommand.h" |
| 32 #include "core/frame/LocalFrame.h" | 32 #include "core/frame/LocalFrame.h" |
| 33 #include "core/layout/LayoutText.h" | 33 #include "core/layout/LayoutText.h" |
| 34 | 34 |
| 35 namespace blink { | 35 namespace blink { |
| 36 | 36 |
| 37 EditCommand::EditCommand(Document& document) | 37 EditCommand::EditCommand(Document& document) |
| 38 : m_document(&document) | 38 : m_document(&document) |
| 39 , m_parent(nullptr) | 39 , m_parent(nullptr) |
| 40 { | 40 { |
| 41 ASSERT(m_document); | 41 DCHECK(m_document); |
| 42 ASSERT(m_document->frame()); | 42 DCHECK(m_document->frame()); |
| 43 setStartingSelection(m_document->frame()->selection().selection()); | 43 setStartingSelection(m_document->frame()->selection().selection()); |
| 44 setEndingSelection(m_startingSelection); | 44 setEndingSelection(m_startingSelection); |
| 45 } | 45 } |
| 46 | 46 |
| 47 EditCommand::~EditCommand() | 47 EditCommand::~EditCommand() |
| 48 { | 48 { |
| 49 } | 49 } |
| 50 | 50 |
| 51 EditAction EditCommand::editingAction() const | 51 EditAction EditCommand::editingAction() const |
| 52 { | 52 { |
| 53 return EditActionUnspecified; | 53 return EditActionUnspecified; |
| 54 } | 54 } |
| 55 | 55 |
| 56 static inline EditCommandComposition* compositionIfPossible(EditCommand* command ) | 56 static inline EditCommandComposition* compositionIfPossible(EditCommand* command ) |
| 57 { | 57 { |
| 58 if (!command->isCompositeEditCommand()) | 58 if (!command->isCompositeEditCommand()) |
| 59 return 0; | 59 return 0; |
| 60 return toCompositeEditCommand(command)->composition(); | 60 return toCompositeEditCommand(command)->composition(); |
| 61 } | 61 } |
| 62 | 62 |
| 63 void EditCommand::setStartingSelection(const VisibleSelection& selection) | 63 void EditCommand::setStartingSelection(const VisibleSelection& selection) |
| 64 { | 64 { |
| 65 for (EditCommand* command = this; ; command = command->m_parent) { | 65 for (EditCommand* command = this; ; command = command->m_parent) { |
| 66 if (EditCommandComposition* composition = compositionIfPossible(command) ) { | 66 if (EditCommandComposition* composition = compositionIfPossible(command) ) { |
| 67 ASSERT(command->isTopLevelCommand()); | 67 DCHECK(command->isTopLevelCommand()); |
| 68 composition->setStartingSelection(selection); | 68 composition->setStartingSelection(selection); |
| 69 } | 69 } |
| 70 command->m_startingSelection = selection; | 70 command->m_startingSelection = selection; |
| 71 if (!command->m_parent || command->m_parent->isFirstCommand(command)) | 71 if (!command->m_parent || command->m_parent->isFirstCommand(command)) |
| 72 break; | 72 break; |
| 73 } | 73 } |
| 74 } | 74 } |
| 75 | 75 |
| 76 void EditCommand::setEndingSelection(const VisibleSelection& selection) | 76 void EditCommand::setEndingSelection(const VisibleSelection& selection) |
| 77 { | 77 { |
| 78 for (EditCommand* command = this; command; command = command->m_parent) { | 78 for (EditCommand* command = this; command; command = command->m_parent) { |
| 79 if (EditCommandComposition* composition = compositionIfPossible(command) ) { | 79 if (EditCommandComposition* composition = compositionIfPossible(command) ) { |
| 80 ASSERT(command->isTopLevelCommand()); | 80 DCHECK(command->isTopLevelCommand()); |
| 81 composition->setEndingSelection(selection); | 81 composition->setEndingSelection(selection); |
| 82 } | 82 } |
| 83 command->m_endingSelection = selection; | 83 command->m_endingSelection = selection; |
| 84 } | 84 } |
| 85 } | 85 } |
| 86 | 86 |
| 87 void EditCommand::setEndingSelection(const VisiblePosition& position) | 87 void EditCommand::setEndingSelection(const VisiblePosition& position) |
| 88 { | 88 { |
| 89 setEndingSelection(VisibleSelection(position)); | 89 setEndingSelection(VisibleSelection(position)); |
| 90 } | 90 } |
| 91 | 91 |
| 92 bool EditCommand::isRenderedCharacter(const Position& position) | 92 bool EditCommand::isRenderedCharacter(const Position& position) |
| 93 { | 93 { |
| 94 if (position.isNull()) | 94 if (position.isNull()) |
| 95 return false; | 95 return false; |
| 96 ASSERT(position.isOffsetInAnchor()); | 96 DCHECK(position.isOffsetInAnchor()); |
|
yosin_UTC9
2016/04/14 04:35:02
How about adding |<< position|?
| |
| 97 if (!position.anchorNode()->isTextNode()) | 97 if (!position.anchorNode()->isTextNode()) |
| 98 return false; | 98 return false; |
| 99 | 99 |
| 100 LayoutObject* layoutObject = position.anchorNode()->layoutObject(); | 100 LayoutObject* layoutObject = position.anchorNode()->layoutObject(); |
| 101 if (!layoutObject) | 101 if (!layoutObject) |
| 102 return false; | 102 return false; |
| 103 | 103 |
| 104 return toLayoutText(layoutObject)->isRenderedCharacter(position.offsetInCont ainerNode()); | 104 return toLayoutText(layoutObject)->isRenderedCharacter(position.offsetInCont ainerNode()); |
| 105 } | 105 } |
| 106 | 106 |
| 107 void EditCommand::setParent(CompositeEditCommand* parent) | 107 void EditCommand::setParent(CompositeEditCommand* parent) |
| 108 { | 108 { |
| 109 ASSERT((parent && !m_parent) || (!parent && m_parent)); | 109 DCHECK((parent && !m_parent) || (!parent && m_parent)); |
| 110 ASSERT(!parent || !isCompositeEditCommand() || !toCompositeEditCommand(this) ->composition()); | 110 DCHECK(!parent || !isCompositeEditCommand() || !toCompositeEditCommand(this) ->composition()); |
| 111 m_parent = parent; | 111 m_parent = parent; |
| 112 if (parent) { | 112 if (parent) { |
| 113 m_startingSelection = parent->m_endingSelection; | 113 m_startingSelection = parent->m_endingSelection; |
| 114 m_endingSelection = parent->m_endingSelection; | 114 m_endingSelection = parent->m_endingSelection; |
| 115 } | 115 } |
| 116 } | 116 } |
| 117 | 117 |
| 118 void SimpleEditCommand::doReapply() | 118 void SimpleEditCommand::doReapply() |
| 119 { | 119 { |
| 120 EditingState editingState; | 120 EditingState editingState; |
| 121 doApply(&editingState); | 121 doApply(&editingState); |
| 122 } | 122 } |
| 123 | 123 |
| 124 DEFINE_TRACE(EditCommand) | 124 DEFINE_TRACE(EditCommand) |
| 125 { | 125 { |
| 126 visitor->trace(m_document); | 126 visitor->trace(m_document); |
| 127 visitor->trace(m_startingSelection); | 127 visitor->trace(m_startingSelection); |
| 128 visitor->trace(m_endingSelection); | 128 visitor->trace(m_endingSelection); |
| 129 visitor->trace(m_parent); | 129 visitor->trace(m_parent); |
| 130 } | 130 } |
| 131 | 131 |
| 132 } // namespace blink | 132 } // namespace blink |
| OLD | NEW |