| 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 reserv
ed. | 3 * Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009 Apple Inc. All rights reserv
ed. |
| 4 * | 4 * |
| 5 * This library is free software; you can redistribute it and/or | 5 * This library is free software; you can redistribute it and/or |
| 6 * modify it under the terms of the GNU Library General Public | 6 * modify it under the terms of the GNU Library General Public |
| 7 * License as published by the Free Software Foundation; either | 7 * License as published by the Free Software Foundation; either |
| 8 * version 2 of the License, or (at your option) any later version. | 8 * version 2 of the License, or (at your option) any later version. |
| 9 * | 9 * |
| 10 * This library is distributed in the hope that it will be useful, | 10 * This library is distributed in the hope that it will be useful, |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 43 m_hasPendingSelection = true; | 43 m_hasPendingSelection = true; |
| 44 } | 44 } |
| 45 | 45 |
| 46 void PendingSelection::clear() | 46 void PendingSelection::clear() |
| 47 { | 47 { |
| 48 m_hasPendingSelection = false; | 48 m_hasPendingSelection = false; |
| 49 m_selection = VisibleSelection(); | 49 m_selection = VisibleSelection(); |
| 50 m_shouldShowBlockCursor = false; | 50 m_shouldShowBlockCursor = false; |
| 51 } | 51 } |
| 52 | 52 |
| 53 bool PendingSelection::isInDocument(const Document& document) const | 53 template <typename Strategy> |
| 54 bool PendingSelection::isInDocumentAlgorithm(const Document& document) const |
| 54 { | 55 { |
| 55 Position start = m_selection.start(); | 56 using PositionType = typename Strategy::PositionType; |
| 57 |
| 58 PositionType start = Strategy::selectionStart(m_selection); |
| 56 if (start.isNotNull() && (!start.inDocument() || start.document() != documen
t)) | 59 if (start.isNotNull() && (!start.inDocument() || start.document() != documen
t)) |
| 57 return false; | 60 return false; |
| 58 Position end = m_selection.end(); | 61 PositionType end = Strategy::selectionEnd(m_selection); |
| 59 if (end.isNotNull() && (!end.inDocument() || end.document() != document)) | 62 if (end.isNotNull() && (!end.inDocument() || end.document() != document)) |
| 60 return false; | 63 return false; |
| 61 Position extent = m_selection.extent(); | 64 PositionType extent = Strategy::selectionExtent(m_selection); |
| 62 if (extent.isNotNull() && (!extent.inDocument() || extent.document() != docu
ment)) | 65 if (extent.isNotNull() && (!extent.inDocument() || extent.document() != docu
ment)) |
| 63 return false; | 66 return false; |
| 64 return true; | 67 return true; |
| 65 } | 68 } |
| 66 | 69 |
| 67 VisibleSelection PendingSelection::calcVisibleSelection() const | 70 bool PendingSelection::isInDocument(const Document& document) const |
| 68 { | 71 { |
| 69 Position start = m_selection.start(); | 72 return isInDocumentAlgorithm<VisibleSelection::InDOMTree>(document); |
| 70 Position end = m_selection.end(); | 73 } |
| 74 |
| 75 template <typename Strategy> |
| 76 VisibleSelection PendingSelection::calcVisibleSelectionAlgorithm() const |
| 77 { |
| 78 using PositionType = typename Strategy::PositionType; |
| 79 |
| 80 PositionType start = Strategy::selectionStart(m_selection); |
| 81 PositionType end = Strategy::selectionEnd(m_selection); |
| 71 SelectionType selectionType = VisibleSelection::selectionType(start, end); | 82 SelectionType selectionType = VisibleSelection::selectionType(start, end); |
| 72 EAffinity affinity = m_selection.affinity(); | 83 EAffinity affinity = m_selection.affinity(); |
| 73 | 84 |
| 74 bool paintBlockCursor = m_shouldShowBlockCursor && selectionType == Selectio
nType::CaretSelection && !isLogicalEndOfLine(VisiblePosition(end, affinity)); | 85 bool paintBlockCursor = m_shouldShowBlockCursor && selectionType == Selectio
nType::CaretSelection && !isLogicalEndOfLine(VisiblePosition(end, affinity)); |
| 75 VisibleSelection selection; | 86 VisibleSelection selection; |
| 76 if (enclosingTextFormControl(start)) { | 87 if (enclosingTextFormControl(start.containerNode())) { |
| 77 Position endPosition = paintBlockCursor ? m_selection.extent().next() :
end; | 88 PositionType endPosition = paintBlockCursor ? Strategy::selectionExtent(
m_selection).next() : end; |
| 78 selection.setWithoutValidation(start, endPosition); | 89 selection.setWithoutValidation(start, endPosition); |
| 79 return selection; | 90 return selection; |
| 80 } | 91 } |
| 81 | 92 |
| 82 VisiblePosition visibleStart = VisiblePosition(start, selectionType == Selec
tionType::RangeSelection ? DOWNSTREAM : affinity); | 93 VisiblePosition visibleStart = VisiblePosition(start, selectionType == Selec
tionType::RangeSelection ? DOWNSTREAM : affinity); |
| 83 if (paintBlockCursor) { | 94 if (paintBlockCursor) { |
| 84 VisiblePosition visibleExtent(end, affinity); | 95 VisiblePosition visibleExtent(end, affinity); |
| 85 visibleExtent = visibleExtent.next(CanSkipOverEditingBoundary); | 96 visibleExtent = visibleExtent.next(CanSkipOverEditingBoundary); |
| 86 return VisibleSelection(visibleStart, visibleExtent); | 97 return VisibleSelection(visibleStart, visibleExtent); |
| 87 } | 98 } |
| 88 VisiblePosition visibleEnd(end, selectionType == SelectionType::RangeSelecti
on ? UPSTREAM : affinity); | 99 VisiblePosition visibleEnd(end, selectionType == SelectionType::RangeSelecti
on ? UPSTREAM : affinity); |
| 89 return VisibleSelection(visibleStart, visibleEnd); | 100 return VisibleSelection(visibleStart, visibleEnd); |
| 90 } | 101 } |
| 91 | 102 |
| 103 VisibleSelection PendingSelection::calcVisibleSelection() const |
| 104 { |
| 105 return calcVisibleSelectionAlgorithm<VisibleSelection::InDOMTree>(); |
| 106 } |
| 107 |
| 92 DEFINE_TRACE(PendingSelection) | 108 DEFINE_TRACE(PendingSelection) |
| 93 { | 109 { |
| 94 visitor->trace(m_selection); | 110 visitor->trace(m_selection); |
| 95 } | 111 } |
| 96 | 112 |
| 97 } // namespace blink | 113 } // namespace blink |
| OLD | NEW |