| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (C) 2004 Apple Computer, Inc. All rights reserved. | 2 * Copyright (C) 2004 Apple Computer, 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 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 46 public: | 46 public: |
| 47 class InDOMTree { | 47 class InDOMTree { |
| 48 public: | 48 public: |
| 49 using PositionType = Position; | 49 using PositionType = Position; |
| 50 | 50 |
| 51 static bool equalSelections(const VisibleSelection&, const VisibleSelect
ion&); | 51 static bool equalSelections(const VisibleSelection&, const VisibleSelect
ion&); |
| 52 static PositionType selectionBase(const VisibleSelection& selection) { r
eturn selection.base(); } | 52 static PositionType selectionBase(const VisibleSelection& selection) { r
eturn selection.base(); } |
| 53 static PositionType selectionExtent(const VisibleSelection& selection) {
return selection.extent(); } | 53 static PositionType selectionExtent(const VisibleSelection& selection) {
return selection.extent(); } |
| 54 static PositionType selectionStart(const VisibleSelection& selection) {
return selection.start(); } | 54 static PositionType selectionStart(const VisibleSelection& selection) {
return selection.start(); } |
| 55 static PositionType selectionEnd(const VisibleSelection& selection) { re
turn selection.end(); } | 55 static PositionType selectionEnd(const VisibleSelection& selection) { re
turn selection.end(); } |
| 56 static SelectionType selectionType(const VisibleSelection& selection) {
return selection.selectionType(); } |
| 56 static VisiblePosition selectionVisibleStart(const VisibleSelection& sel
ection) { return selection.visibleStart(); } | 57 static VisiblePosition selectionVisibleStart(const VisibleSelection& sel
ection) { return selection.visibleStart(); } |
| 57 static VisiblePosition selectionVisibleEnd(const VisibleSelection& selec
tion) { return selection.visibleEnd(); } | 58 static VisiblePosition selectionVisibleEnd(const VisibleSelection& selec
tion) { return selection.visibleEnd(); } |
| 58 static PositionType toPositionType(const Position& position) { return po
sition; } | 59 static PositionType toPositionType(const Position& position) { return po
sition; } |
| 59 }; | 60 }; |
| 60 | 61 |
| 61 class InComposedTree { | 62 class InComposedTree { |
| 62 public: | 63 public: |
| 63 using PositionType = PositionInComposedTree; | 64 using PositionType = PositionInComposedTree; |
| 64 | 65 |
| 66 static bool equalSelections(const VisibleSelection&, const VisibleSelect
ion&); |
| 67 static bool isRange(const VisibleSelection& selection) { return selectio
nType(selection) == RangeSelection; } |
| 65 static PositionType selectionBase(const VisibleSelection& selection) { r
eturn selection.baseInComposedTree(); } | 68 static PositionType selectionBase(const VisibleSelection& selection) { r
eturn selection.baseInComposedTree(); } |
| 66 static PositionType selectionExtent(const VisibleSelection& selection) {
return selection.extentInComposedTree(); } | 69 static PositionType selectionExtent(const VisibleSelection& selection) {
return selection.extentInComposedTree(); } |
| 67 static PositionType selectionStart(const VisibleSelection& selection) {
return selection.startInComposedTree(); } | 70 static PositionType selectionStart(const VisibleSelection& selection) {
return selection.startInComposedTree(); } |
| 68 static PositionType selectionEnd(const VisibleSelection& selection) { re
turn selection.endInComposedTree(); } | 71 static PositionType selectionEnd(const VisibleSelection& selection) { re
turn selection.endInComposedTree(); } |
| 72 static SelectionType selectionType(const VisibleSelection& selection) {
return selection.selectionTypeInComposedTree(); } |
| 73 static VisiblePosition selectionVisibleStart(const VisibleSelection& sel
ection) |
| 74 { |
| 75 return VisiblePosition(selectionStart(selection), isRange(selection)
? DOWNSTREAM : selection.affinity()); |
| 76 } |
| 77 static VisiblePosition selectionVisibleEnd(const VisibleSelection& selec
tion) |
| 78 { |
| 79 return VisiblePosition(selectionEnd(selection), isRange(selection) ?
UPSTREAM : selection.affinity()); |
| 80 } |
| 81 static PositionType toPositionType(const Position& position) { return to
PositionInComposedTree(position); } |
| 69 }; | 82 }; |
| 70 | 83 |
| 71 VisibleSelection(); | 84 VisibleSelection(); |
| 72 | 85 |
| 73 VisibleSelection(const Position&, EAffinity, bool isDirectional = false); | 86 VisibleSelection(const Position&, EAffinity, bool isDirectional = false); |
| 74 VisibleSelection(const Position& base, const Position& extent, EAffinity = S
EL_DEFAULT_AFFINITY, bool isDirectional = false); | 87 VisibleSelection(const Position& base, const Position& extent, EAffinity = S
EL_DEFAULT_AFFINITY, bool isDirectional = false); |
| 75 VisibleSelection(const PositionInComposedTree& base, const PositionInCompose
dTree& extent, EAffinity = SEL_DEFAULT_AFFINITY, bool isDirectional = false); | 88 VisibleSelection(const PositionInComposedTree& base, const PositionInCompose
dTree& extent, EAffinity = SEL_DEFAULT_AFFINITY, bool isDirectional = false); |
| 76 | 89 |
| 77 explicit VisibleSelection(const Range*, EAffinity = SEL_DEFAULT_AFFINITY, bo
ol isDirectional = false); | 90 explicit VisibleSelection(const Range*, EAffinity = SEL_DEFAULT_AFFINITY, bo
ol isDirectional = false); |
| 78 | 91 |
| 79 explicit VisibleSelection(const VisiblePosition&, bool isDirectional = false
); | 92 explicit VisibleSelection(const VisiblePosition&, bool isDirectional = false
); |
| 80 VisibleSelection(const VisiblePosition&, const VisiblePosition&, bool isDire
ctional = false); | 93 VisibleSelection(const VisiblePosition&, const VisiblePosition&, bool isDire
ctional = false); |
| 81 | 94 |
| 82 VisibleSelection(const VisibleSelection&); | 95 VisibleSelection(const VisibleSelection&); |
| 83 VisibleSelection& operator=(const VisibleSelection&); | 96 VisibleSelection& operator=(const VisibleSelection&); |
| 84 | 97 |
| 85 static VisibleSelection selectionFromContentsOfNode(Node*); | 98 static VisibleSelection selectionFromContentsOfNode(Node*); |
| 86 | 99 |
| 87 SelectionType selectionType() const { return m_selectionType; } | 100 SelectionType selectionType() const { return m_selectionType; } |
| 101 SelectionType selectionTypeInComposedTree() const; |
| 88 | 102 |
| 89 void setAffinity(EAffinity affinity) { m_affinity = affinity; } | 103 void setAffinity(EAffinity affinity) { m_affinity = affinity; } |
| 90 EAffinity affinity() const { return m_affinity; } | 104 EAffinity affinity() const { return m_affinity; } |
| 91 | 105 |
| 92 void setBase(const Position&); | 106 void setBase(const Position&); |
| 93 void setBase(const PositionInComposedTree&); | 107 void setBase(const PositionInComposedTree&); |
| 94 void setBase(const VisiblePosition&); | 108 void setBase(const VisiblePosition&); |
| 95 void setExtent(const Position&); | 109 void setExtent(const Position&); |
| 96 void setExtent(const PositionInComposedTree&); | 110 void setExtent(const PositionInComposedTree&); |
| 97 void setExtent(const VisiblePosition&); | 111 void setExtent(const VisiblePosition&); |
| (...skipping 12 matching lines...) Expand all Loading... |
| 110 VisiblePosition visibleBase() const { return VisiblePosition(m_base, isRange
() ? (isBaseFirst() ? UPSTREAM : DOWNSTREAM) : affinity()); } | 124 VisiblePosition visibleBase() const { return VisiblePosition(m_base, isRange
() ? (isBaseFirst() ? UPSTREAM : DOWNSTREAM) : affinity()); } |
| 111 VisiblePosition visibleExtent() const { return VisiblePosition(m_extent, isR
ange() ? (isBaseFirst() ? DOWNSTREAM : UPSTREAM) : affinity()); } | 125 VisiblePosition visibleExtent() const { return VisiblePosition(m_extent, isR
ange() ? (isBaseFirst() ? DOWNSTREAM : UPSTREAM) : affinity()); } |
| 112 | 126 |
| 113 bool isNone() const { return selectionType() == NoSelection; } | 127 bool isNone() const { return selectionType() == NoSelection; } |
| 114 bool isCaret() const { return selectionType() == CaretSelection; } | 128 bool isCaret() const { return selectionType() == CaretSelection; } |
| 115 bool isRange() const { return selectionType() == RangeSelection; } | 129 bool isRange() const { return selectionType() == RangeSelection; } |
| 116 bool isCaretOrRange() const { return selectionType() != NoSelection; } | 130 bool isCaretOrRange() const { return selectionType() != NoSelection; } |
| 117 bool isNonOrphanedRange() const { return isRange() && !start().isOrphan() &&
!end().isOrphan(); } | 131 bool isNonOrphanedRange() const { return isRange() && !start().isOrphan() &&
!end().isOrphan(); } |
| 118 bool isNonOrphanedCaretOrRange() const { return isCaretOrRange() && !start()
.isOrphan() && !end().isOrphan(); } | 132 bool isNonOrphanedCaretOrRange() const { return isCaretOrRange() && !start()
.isOrphan() && !end().isOrphan(); } |
| 119 static SelectionType selectionType(const Position& start, const Position& en
d); | 133 static SelectionType selectionType(const Position& start, const Position& en
d); |
| 134 static SelectionType selectionType(const PositionInComposedTree& start, cons
t PositionInComposedTree& end); |
| 120 | 135 |
| 121 bool isBaseFirst() const { return m_baseIsFirst; } | 136 bool isBaseFirst() const { return m_baseIsFirst; } |
| 122 bool isDirectional() const { return m_isDirectional; } | 137 bool isDirectional() const { return m_isDirectional; } |
| 123 void setIsDirectional(bool isDirectional) { m_isDirectional = isDirectional;
} | 138 void setIsDirectional(bool isDirectional) { m_isDirectional = isDirectional;
} |
| 124 | 139 |
| 125 void appendTrailingWhitespace(); | 140 void appendTrailingWhitespace(); |
| 126 | 141 |
| 127 bool expandUsingGranularity(TextGranularity granularity); | 142 bool expandUsingGranularity(TextGranularity granularity); |
| 143 bool expandUsingGranularityInComposedTree(TextGranularity); |
| 128 | 144 |
| 129 // We don't yet support multi-range selections, so we only ever have one ran
ge to return. | 145 // We don't yet support multi-range selections, so we only ever have one ran
ge to return. |
| 130 PassRefPtrWillBeRawPtr<Range> firstRange() const; | 146 PassRefPtrWillBeRawPtr<Range> firstRange() const; |
| 131 | 147 |
| 132 bool intersectsNode(Node*) const; | 148 bool intersectsNode(Node*) const; |
| 133 | 149 |
| 134 // FIXME: Most callers probably don't want these functions, but | 150 // FIXME: Most callers probably don't want these functions, but |
| 135 // are using them for historical reasons. toNormalizedRange and | 151 // are using them for historical reasons. toNormalizedRange and |
| 136 // toNormalizedPositions contracts the range around text, and | 152 // toNormalizedPositions contracts the range around text, and |
| 137 // moves the caret upstream before returning the range/positions. | 153 // moves the caret upstream before returning the range/positions. |
| 138 PassRefPtrWillBeRawPtr<Range> toNormalizedRange() const; | 154 PassRefPtrWillBeRawPtr<Range> toNormalizedRange() const; |
| 139 bool toNormalizedPositions(Position& start, Position& end) const; | 155 bool toNormalizedPositions(Position& start, Position& end) const; |
| 140 static void normalizePositions(const Position& start, const Position& end, P
osition* normalizedStart, Position* normalizedEnd); | 156 static void normalizePositions(const Position& start, const Position& end, P
osition* normalizedStart, Position* normalizedEnd); |
| 141 static void normalizePositions(const PositionInComposedTree& start, const Po
sitionInComposedTree& end, PositionInComposedTree* outStart, PositionInComposedT
ree* outEnd); | 157 static void normalizePositions(const PositionInComposedTree& start, const Po
sitionInComposedTree& end, PositionInComposedTree* outStart, PositionInComposedT
ree* outEnd); |
| 142 | 158 |
| 143 Element* rootEditableElement() const; | 159 Element* rootEditableElement() const; |
| 144 bool isContentEditable() const; | 160 bool isContentEditable() const; |
| 145 bool hasEditableStyle() const; | 161 bool hasEditableStyle() const; |
| 146 bool isContentRichlyEditable() const; | 162 bool isContentRichlyEditable() const; |
| 147 // Returns a shadow tree node for legacy shadow trees, a child of the | 163 // Returns a shadow tree node for legacy shadow trees, a child of the |
| 148 // ShadowRoot node for new shadow trees, or 0 for non-shadow trees. | 164 // ShadowRoot node for new shadow trees, or 0 for non-shadow trees. |
| 149 Node* nonBoundaryShadowTreeRootNode() const; | 165 Node* nonBoundaryShadowTreeRootNode() const; |
| 150 | 166 |
| 151 VisiblePosition visiblePositionRespectingEditingBoundary(const LayoutPoint&
localPoint, Node* targetNode) const; | 167 VisiblePosition visiblePositionRespectingEditingBoundary(const LayoutPoint&
localPoint, Node* targetNode) const; |
| 152 PositionWithAffinity positionRespectingEditingBoundary(const LayoutPoint& lo
calPoint, Node* targetNode) const; | 168 PositionWithAffinity positionRespectingEditingBoundary(const LayoutPoint& lo
calPoint, Node* targetNode) const; |
| 153 | 169 |
| 154 void setWithoutValidation(const Position&, const Position&); | 170 void setWithoutValidation(const Position&, const Position&); |
| 171 void setWithoutValidation(const PositionInComposedTree&, const PositionInCom
posedTree&); |
| 155 | 172 |
| 156 // Listener of VisibleSelection modification. didChangeVisibleSelection() wi
ll be invoked when base, extent, start | 173 // Listener of VisibleSelection modification. didChangeVisibleSelection() wi
ll be invoked when base, extent, start |
| 157 // or end is moved to a different position. | 174 // or end is moved to a different position. |
| 158 // | 175 // |
| 159 // Objects implementing |ChangeObserver| interface must outlive the VisibleS
election object. | 176 // Objects implementing |ChangeObserver| interface must outlive the VisibleS
election object. |
| 160 class CORE_EXPORT ChangeObserver : public WillBeGarbageCollectedMixin { | 177 class CORE_EXPORT ChangeObserver : public WillBeGarbageCollectedMixin { |
| 161 WTF_MAKE_NONCOPYABLE(ChangeObserver); | 178 WTF_MAKE_NONCOPYABLE(ChangeObserver); |
| 162 public: | 179 public: |
| 163 ChangeObserver(); | 180 ChangeObserver(); |
| 164 virtual ~ChangeObserver(); | 181 virtual ~ChangeObserver(); |
| (...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 248 | 265 |
| 249 } // namespace blink | 266 } // namespace blink |
| 250 | 267 |
| 251 #ifndef NDEBUG | 268 #ifndef NDEBUG |
| 252 // Outside the WebCore namespace for ease of invocation from gdb. | 269 // Outside the WebCore namespace for ease of invocation from gdb. |
| 253 void showTree(const blink::VisibleSelection&); | 270 void showTree(const blink::VisibleSelection&); |
| 254 void showTree(const blink::VisibleSelection*); | 271 void showTree(const blink::VisibleSelection*); |
| 255 #endif | 272 #endif |
| 256 | 273 |
| 257 #endif // VisibleSelection_h | 274 #endif // VisibleSelection_h |
| OLD | NEW |