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 * |
11 * This library is distributed in the hope that it will be useful, | 11 * This library is distributed in the hope that it will be useful, |
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of | 12 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | 13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
14 * Library General Public License for more details. | 14 * Library General Public License for more details. |
15 * | 15 * |
16 * You should have received a copy of the GNU Library General Public License | 16 * You should have received a copy of the GNU Library General Public License |
17 * along with this library; see the file COPYING.LIB. If not, write to | 17 * along with this library; see the file COPYING.LIB. If not, write to |
18 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, | 18 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, |
19 * Boston, MA 02110-1301, USA. | 19 * Boston, MA 02110-1301, USA. |
20 */ | 20 */ |
21 | 21 |
22 #include "core/editing/PendingSelection.h" | 22 #include "core/editing/LayoutSelection.h" |
23 | 23 |
24 #include "core/dom/Document.h" | 24 #include "core/dom/Document.h" |
25 #include "core/editing/EditingUtilities.h" | 25 #include "core/editing/EditingUtilities.h" |
26 #include "core/editing/FrameSelection.h" | 26 #include "core/editing/FrameSelection.h" |
27 #include "core/editing/VisiblePosition.h" | 27 #include "core/editing/VisiblePosition.h" |
28 #include "core/editing/VisibleUnits.h" | 28 #include "core/editing/VisibleUnits.h" |
29 #include "core/html/TextControlElement.h" | 29 #include "core/html/TextControlElement.h" |
30 #include "core/layout/LayoutView.h" | 30 #include "core/layout/LayoutView.h" |
31 | 31 |
32 namespace blink { | 32 namespace blink { |
33 | 33 |
34 PendingSelection::PendingSelection(FrameSelection& frameSelection) | 34 LayoutSelection::LayoutSelection(FrameSelection& frameSelection) |
35 : m_frameSelection(&frameSelection), m_hasPendingSelection(false) {} | 35 : m_frameSelection(&frameSelection), m_hasPendingSelection(false) {} |
36 | 36 |
37 const VisibleSelection& PendingSelection::visibleSelection() const { | 37 const VisibleSelection& LayoutSelection::visibleSelection() const { |
38 return m_frameSelection->computeVisibleSelectionInDOMTree(); | 38 return m_frameSelection->computeVisibleSelectionInDOMTree(); |
39 } | 39 } |
40 | 40 |
41 static bool isSelectionInDocument( | 41 static bool isSelectionInDocument( |
42 const VisibleSelectionInFlatTree& visibleSelection, | 42 const VisibleSelectionInFlatTree& visibleSelection, |
43 const Document& document) { | 43 const Document& document) { |
44 const PositionInFlatTree& start = visibleSelection.start(); | 44 const PositionInFlatTree& start = visibleSelection.start(); |
45 if (start.isNotNull() && | 45 if (start.isNotNull() && |
46 (!start.isConnected() || start.document() != document)) | 46 (!start.isConnected() || start.document() != document)) |
47 return false; | 47 return false; |
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 SelectionInFlatTree PendingSelection::calcVisibleSelection( | 58 SelectionInFlatTree LayoutSelection::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)); |
(...skipping 30 matching lines...) Expand all Loading... |
99 ? TextAffinity::Upstream | 99 ? TextAffinity::Upstream |
100 : affinity); | 100 : affinity); |
101 if (visibleEnd.isNull()) | 101 if (visibleEnd.isNull()) |
102 return SelectionInFlatTree(); | 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 builder.build(); | 106 return builder.build(); |
107 } | 107 } |
108 | 108 |
109 void PendingSelection::commit(LayoutView& layoutView) { | 109 void LayoutSelection::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())) |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
157 LayoutObject* startLayoutObject = startPos.anchorNode()->layoutObject(); | 157 LayoutObject* startLayoutObject = startPos.anchorNode()->layoutObject(); |
158 LayoutObject* endLayoutObject = endPos.anchorNode()->layoutObject(); | 158 LayoutObject* endLayoutObject = endPos.anchorNode()->layoutObject(); |
159 if (!startLayoutObject || !endLayoutObject) | 159 if (!startLayoutObject || !endLayoutObject) |
160 return; | 160 return; |
161 DCHECK(layoutView == startLayoutObject->view()); | 161 DCHECK(layoutView == startLayoutObject->view()); |
162 DCHECK(layoutView == endLayoutObject->view()); | 162 DCHECK(layoutView == endLayoutObject->view()); |
163 layoutView.setSelection(startLayoutObject, startPos.computeEditingOffset(), | 163 layoutView.setSelection(startLayoutObject, startPos.computeEditingOffset(), |
164 endLayoutObject, endPos.computeEditingOffset()); | 164 endLayoutObject, endPos.computeEditingOffset()); |
165 } | 165 } |
166 | 166 |
167 DEFINE_TRACE(PendingSelection) { | 167 DEFINE_TRACE(LayoutSelection) { |
168 visitor->trace(m_frameSelection); | 168 visitor->trace(m_frameSelection); |
169 } | 169 } |
170 | 170 |
171 } // namespace blink | 171 } // namespace blink |
OLD | NEW |