| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (C) 1999 Lars Knoll (knoll@kde.org) | 2 * Copyright (C) 1999 Lars Knoll (knoll@kde.org) |
| 3 * Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009 Apple Inc. All rights | 3 * Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009 Apple Inc. All rights |
| 4 * reserved. | 4 * reserved. |
| 5 * | 5 * |
| 6 * This library is free software; you can redistribute it and/or | 6 * This library is free software; you can redistribute it and/or |
| 7 * modify it under the terms of the GNU Library General Public | 7 * modify it under the terms of the GNU Library General Public |
| 8 * License as published by the Free Software Foundation; either | 8 * License as published by the Free Software Foundation; either |
| 9 * version 2 of the License, or (at your option) any later version. | 9 * version 2 of the License, or (at your option) any later version. |
| 10 * | 10 * |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 48 const PositionInFlatTree& end = visibleSelection.end(); | 48 const PositionInFlatTree& end = visibleSelection.end(); |
| 49 if (end.isNotNull() && (!end.isConnected() || end.document() != document)) | 49 if (end.isNotNull() && (!end.isConnected() || end.document() != document)) |
| 50 return false; | 50 return false; |
| 51 const PositionInFlatTree extent = visibleSelection.extent(); | 51 const PositionInFlatTree extent = visibleSelection.extent(); |
| 52 if (extent.isNotNull() && | 52 if (extent.isNotNull() && |
| 53 (!extent.isConnected() || extent.document() != document)) | 53 (!extent.isConnected() || extent.document() != document)) |
| 54 return false; | 54 return false; |
| 55 return true; | 55 return true; |
| 56 } | 56 } |
| 57 | 57 |
| 58 VisibleSelectionInFlatTree PendingSelection::calcVisibleSelection( | 58 SelectionInFlatTree PendingSelection::calcVisibleSelection( |
| 59 const VisibleSelectionInFlatTree& originalSelection) const { | 59 const VisibleSelectionInFlatTree& originalSelection) const { |
| 60 const PositionInFlatTree& start = originalSelection.start(); | 60 const PositionInFlatTree& start = originalSelection.start(); |
| 61 const PositionInFlatTree& end = originalSelection.end(); | 61 const PositionInFlatTree& end = originalSelection.end(); |
| 62 SelectionType selectionType = originalSelection.getSelectionType(); | 62 SelectionType selectionType = originalSelection.getSelectionType(); |
| 63 const TextAffinity affinity = originalSelection.affinity(); | 63 const TextAffinity affinity = originalSelection.affinity(); |
| 64 | 64 |
| 65 bool paintBlockCursor = | 65 bool paintBlockCursor = |
| 66 m_frameSelection->shouldShowBlockCursor() && | 66 m_frameSelection->shouldShowBlockCursor() && |
| 67 selectionType == SelectionType::CaretSelection && | 67 selectionType == SelectionType::CaretSelection && |
| 68 !isLogicalEndOfLine(createVisiblePosition(end, affinity)); | 68 !isLogicalEndOfLine(createVisiblePosition(end, affinity)); |
| 69 VisibleSelectionInFlatTree selection; | |
| 70 if (enclosingTextControl(start.computeContainerNode())) { | 69 if (enclosingTextControl(start.computeContainerNode())) { |
| 71 // TODO(yosin) We should use |PositionMoveType::CodePoint| to avoid | 70 // TODO(yosin) We should use |PositionMoveType::CodePoint| to avoid |
| 72 // ending paint at middle of character. | 71 // ending paint at middle of character. |
| 73 PositionInFlatTree endPosition = | 72 PositionInFlatTree endPosition = |
| 74 paintBlockCursor ? nextPositionOf(originalSelection.extent(), | 73 paintBlockCursor ? nextPositionOf(originalSelection.extent(), |
| 75 PositionMoveType::CodeUnit) | 74 PositionMoveType::CodeUnit) |
| 76 : end; | 75 : end; |
| 77 selection.setWithoutValidation(start, endPosition); | 76 return SelectionInFlatTree::Builder() |
| 78 return selection; | 77 .setBaseAndExtent(start, endPosition) |
| 78 .build(); |
| 79 } | 79 } |
| 80 | 80 |
| 81 const VisiblePositionInFlatTree& visibleStart = createVisiblePosition( | 81 const VisiblePositionInFlatTree& visibleStart = createVisiblePosition( |
| 82 start, selectionType == SelectionType::RangeSelection | 82 start, selectionType == SelectionType::RangeSelection |
| 83 ? TextAffinity::Downstream | 83 ? TextAffinity::Downstream |
| 84 : affinity); | 84 : affinity); |
| 85 if (visibleStart.isNull()) | 85 if (visibleStart.isNull()) |
| 86 return VisibleSelectionInFlatTree(); | 86 return SelectionInFlatTree(); |
| 87 if (paintBlockCursor) { | 87 if (paintBlockCursor) { |
| 88 const VisiblePositionInFlatTree visibleExtent = nextPositionOf( | 88 const VisiblePositionInFlatTree visibleExtent = nextPositionOf( |
| 89 createVisiblePosition(end, affinity), CanSkipOverEditingBoundary); | 89 createVisiblePosition(end, affinity), CanSkipOverEditingBoundary); |
| 90 if (visibleExtent.isNull()) | 90 if (visibleExtent.isNull()) |
| 91 return VisibleSelectionInFlatTree(); | 91 return SelectionInFlatTree(); |
| 92 SelectionInFlatTree::Builder builder; | 92 SelectionInFlatTree::Builder builder; |
| 93 builder.collapse(visibleStart.toPositionWithAffinity()); | 93 builder.collapse(visibleStart.toPositionWithAffinity()); |
| 94 builder.extend(visibleExtent.deepEquivalent()); | 94 builder.extend(visibleExtent.deepEquivalent()); |
| 95 return createVisibleSelection(builder.build()); | 95 return builder.build(); |
| 96 } | 96 } |
| 97 const VisiblePositionInFlatTree visibleEnd = | 97 const VisiblePositionInFlatTree visibleEnd = |
| 98 createVisiblePosition(end, selectionType == SelectionType::RangeSelection | 98 createVisiblePosition(end, selectionType == SelectionType::RangeSelection |
| 99 ? TextAffinity::Upstream | 99 ? TextAffinity::Upstream |
| 100 : affinity); | 100 : affinity); |
| 101 if (visibleEnd.isNull()) | 101 if (visibleEnd.isNull()) |
| 102 return VisibleSelectionInFlatTree(); | 102 return SelectionInFlatTree(); |
| 103 SelectionInFlatTree::Builder builder; | 103 SelectionInFlatTree::Builder builder; |
| 104 builder.collapse(visibleStart.toPositionWithAffinity()); | 104 builder.collapse(visibleStart.toPositionWithAffinity()); |
| 105 builder.extend(visibleEnd.deepEquivalent()); | 105 builder.extend(visibleEnd.deepEquivalent()); |
| 106 return createVisibleSelection(builder.build()); | 106 return builder.build(); |
| 107 } | 107 } |
| 108 | 108 |
| 109 void PendingSelection::commit(LayoutView& layoutView) { | 109 void PendingSelection::commit(LayoutView& layoutView) { |
| 110 if (!hasPendingSelection()) | 110 if (!hasPendingSelection()) |
| 111 return; | 111 return; |
| 112 DCHECK(!layoutView.needsLayout()); | 112 DCHECK(!layoutView.needsLayout()); |
| 113 m_hasPendingSelection = false; | 113 m_hasPendingSelection = false; |
| 114 | 114 |
| 115 const VisibleSelectionInFlatTree& originalSelection = | 115 const VisibleSelectionInFlatTree& originalSelection = |
| 116 m_frameSelection->computeVisibleSelectionInFlatTree(); | 116 m_frameSelection->computeVisibleSelectionInFlatTree(); |
| 117 | 117 |
| 118 // Skip if pending VisibilePositions became invalid before we reach here. | 118 // Skip if pending VisibilePositions became invalid before we reach here. |
| 119 if (!isSelectionInDocument(originalSelection, layoutView.document())) | 119 if (!isSelectionInDocument(originalSelection, layoutView.document())) |
| 120 return; | 120 return; |
| 121 | 121 |
| 122 // Construct a new VisibleSolution, since visibleSelection() is not | 122 // Construct a new VisibleSolution, since visibleSelection() is not |
| 123 // necessarily valid, and the following steps assume a valid selection. See | 123 // necessarily valid, and the following steps assume a valid selection. See |
| 124 // <https://bugs.webkit.org/show_bug.cgi?id=69563> and | 124 // <https://bugs.webkit.org/show_bug.cgi?id=69563> and |
| 125 // <rdar://problem/10232866>. | 125 // <rdar://problem/10232866>. |
| 126 const VisibleSelectionInFlatTree& selection = | 126 const VisibleSelectionInFlatTree& selection = |
| 127 calcVisibleSelection(originalSelection); | 127 createVisibleSelection(calcVisibleSelection(originalSelection)); |
| 128 | 128 |
| 129 if (!selection.isRange()) { | 129 if (!selection.isRange()) { |
| 130 layoutView.clearSelection(); | 130 layoutView.clearSelection(); |
| 131 return; | 131 return; |
| 132 } | 132 } |
| 133 | 133 |
| 134 // Use the rightmost candidate for the start of the selection, and the | 134 // Use the rightmost candidate for the start of the selection, and the |
| 135 // leftmost candidate for the end of the selection. Example: foo <a>bar</a>. | 135 // leftmost candidate for the end of the selection. Example: foo <a>bar</a>. |
| 136 // Imagine that a line wrap occurs after 'foo', and that 'bar' is selected. | 136 // Imagine that a line wrap occurs after 'foo', and that 'bar' is selected. |
| 137 // If we pass [foo, 3] as the start of the selection, the selection painting | 137 // If we pass [foo, 3] as the start of the selection, the selection painting |
| (...skipping 23 matching lines...) Expand all Loading... |
| 161 DCHECK(layoutView == endLayoutObject->view()); | 161 DCHECK(layoutView == endLayoutObject->view()); |
| 162 layoutView.setSelection(startLayoutObject, startPos.computeEditingOffset(), | 162 layoutView.setSelection(startLayoutObject, startPos.computeEditingOffset(), |
| 163 endLayoutObject, endPos.computeEditingOffset()); | 163 endLayoutObject, endPos.computeEditingOffset()); |
| 164 } | 164 } |
| 165 | 165 |
| 166 DEFINE_TRACE(PendingSelection) { | 166 DEFINE_TRACE(PendingSelection) { |
| 167 visitor->trace(m_frameSelection); | 167 visitor->trace(m_frameSelection); |
| 168 } | 168 } |
| 169 | 169 |
| 170 } // namespace blink | 170 } // namespace blink |
| OLD | NEW |