| 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 21 matching lines...) Expand all Loading... |
| 32 #include "core/editing/SelectionType.h" | 32 #include "core/editing/SelectionType.h" |
| 33 #include "core/editing/TextAffinity.h" | 33 #include "core/editing/TextAffinity.h" |
| 34 #include "core/editing/TextGranularity.h" | 34 #include "core/editing/TextGranularity.h" |
| 35 #include "core/editing/VisiblePosition.h" | 35 #include "core/editing/VisiblePosition.h" |
| 36 #include "core/editing/VisibleUnits.h" | 36 #include "core/editing/VisibleUnits.h" |
| 37 #include "wtf/Allocator.h" | 37 #include "wtf/Allocator.h" |
| 38 | 38 |
| 39 namespace blink { | 39 namespace blink { |
| 40 | 40 |
| 41 class LayoutPoint; | 41 class LayoutPoint; |
| 42 class SelectionAdjuster; | |
| 43 | 42 |
| 44 // TODO(yosin) We should use capitalized name instead of |SEL_DEFAULT_AFFINITY|. | 43 // TODO(yosin) We should use capitalized name instead of |SEL_DEFAULT_AFFINITY|. |
| 45 const TextAffinity SEL_DEFAULT_AFFINITY = TextAffinity::Downstream; // NOLINT | 44 const TextAffinity SEL_DEFAULT_AFFINITY = TextAffinity::Downstream; // NOLINT |
| 46 enum SelectionDirection { DirectionForward, DirectionBackward, DirectionRight, D
irectionLeft }; | 45 enum SelectionDirection { DirectionForward, DirectionBackward, DirectionRight, D
irectionLeft }; |
| 47 | 46 |
| 48 // Listener of |VisibleSelection| modification. |didChangeVisibleSelection()| | 47 // Listener of |VisibleSelection| modification. |didChangeVisibleSelection()| |
| 49 // will be invoked when base, extent, start or end is moved to a different | 48 // will be invoked when base, extent, start or end is moved to a different |
| 50 // position. | 49 // position. |
| 51 // | 50 // |
| 52 // Objects implementing |VisibleSelectionChangeObserver| interface must outlive | 51 // Objects implementing |VisibleSelectionChangeObserver| interface must outlive |
| (...skipping 15 matching lines...) Expand all Loading... |
| 68 VisibleSelectionTemplate(); | 67 VisibleSelectionTemplate(); |
| 69 VisibleSelectionTemplate(const PositionTemplate<Strategy>&, TextAffinity, bo
ol isDirectional = false); | 68 VisibleSelectionTemplate(const PositionTemplate<Strategy>&, TextAffinity, bo
ol isDirectional = false); |
| 70 VisibleSelectionTemplate(const PositionTemplate<Strategy>& base, const Posit
ionTemplate<Strategy>& extent, TextAffinity = SEL_DEFAULT_AFFINITY, bool isDirec
tional = false); | 69 VisibleSelectionTemplate(const PositionTemplate<Strategy>& base, const Posit
ionTemplate<Strategy>& extent, TextAffinity = SEL_DEFAULT_AFFINITY, bool isDirec
tional = false); |
| 71 explicit VisibleSelectionTemplate(const EphemeralRangeTemplate<Strategy>&, T
extAffinity = SEL_DEFAULT_AFFINITY, bool isDirectional = false); | 70 explicit VisibleSelectionTemplate(const EphemeralRangeTemplate<Strategy>&, T
extAffinity = SEL_DEFAULT_AFFINITY, bool isDirectional = false); |
| 72 | 71 |
| 73 explicit VisibleSelectionTemplate(const VisiblePositionTemplate<Strategy>&,
bool isDirectional = false); | 72 explicit VisibleSelectionTemplate(const VisiblePositionTemplate<Strategy>&,
bool isDirectional = false); |
| 74 VisibleSelectionTemplate(const VisiblePositionTemplate<Strategy>&, const Vis
iblePositionTemplate<Strategy>&, bool isDirectional = false); | 73 VisibleSelectionTemplate(const VisiblePositionTemplate<Strategy>&, const Vis
iblePositionTemplate<Strategy>&, bool isDirectional = false); |
| 75 | 74 |
| 76 explicit VisibleSelectionTemplate(const PositionWithAffinityTemplate<Strateg
y>&, bool isDirectional = false); | 75 explicit VisibleSelectionTemplate(const PositionWithAffinityTemplate<Strateg
y>&, bool isDirectional = false); |
| 77 | 76 |
| 77 static VisibleSelectionTemplate<Strategy> createWithoutValidation(const Posi
tionTemplate<Strategy>& base, const PositionTemplate<Strategy>& extent, const Po
sitionTemplate<Strategy>& start, const PositionTemplate<Strategy>& end, TextAffi
nity, bool isDirectional); |
| 78 |
| 78 VisibleSelectionTemplate(const VisibleSelectionTemplate&); | 79 VisibleSelectionTemplate(const VisibleSelectionTemplate&); |
| 79 VisibleSelectionTemplate& operator=(const VisibleSelectionTemplate&); | 80 VisibleSelectionTemplate& operator=(const VisibleSelectionTemplate&); |
| 80 | 81 |
| 81 static VisibleSelectionTemplate selectionFromContentsOfNode(Node*); | 82 static VisibleSelectionTemplate selectionFromContentsOfNode(Node*); |
| 82 | 83 |
| 83 SelectionType selectionType() const { return m_selectionType; } | 84 SelectionType selectionType() const { return m_selectionType; } |
| 84 | 85 |
| 85 void setAffinity(TextAffinity affinity) { m_affinity = affinity; } | 86 void setAffinity(TextAffinity affinity) { m_affinity = affinity; } |
| 86 TextAffinity affinity() const { return m_affinity; } | 87 TextAffinity affinity() const { return m_affinity; } |
| 87 | 88 |
| (...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 157 #ifndef NDEBUG | 158 #ifndef NDEBUG |
| 158 void debugPosition(const char* message) const; | 159 void debugPosition(const char* message) const; |
| 159 void formatForDebugger(char* buffer, unsigned length) const; | 160 void formatForDebugger(char* buffer, unsigned length) const; |
| 160 void showTreeForThis() const; | 161 void showTreeForThis() const; |
| 161 #endif | 162 #endif |
| 162 | 163 |
| 163 void setStartRespectingGranularity(TextGranularity, EWordSide = RightWordIfO
nBoundary); | 164 void setStartRespectingGranularity(TextGranularity, EWordSide = RightWordIfO
nBoundary); |
| 164 void setEndRespectingGranularity(TextGranularity, EWordSide = RightWordIfOnB
oundary); | 165 void setEndRespectingGranularity(TextGranularity, EWordSide = RightWordIfOnB
oundary); |
| 165 | 166 |
| 166 private: | 167 private: |
| 167 friend class SelectionAdjuster; | 168 VisibleSelectionTemplate(const PositionTemplate<Strategy>& base, const Posit
ionTemplate<Strategy>& extent, const PositionTemplate<Strategy>& start, const Po
sitionTemplate<Strategy>& end, TextAffinity, bool isDirectional); |
| 168 | 169 |
| 169 void validate(TextGranularity = CharacterGranularity); | 170 void validate(TextGranularity = CharacterGranularity); |
| 170 | 171 |
| 171 // Support methods for validate() | 172 // Support methods for validate() |
| 172 void setBaseAndExtentToDeepEquivalents(); | 173 void setBaseAndExtentToDeepEquivalents(); |
| 173 void adjustSelectionToAvoidCrossingShadowBoundaries(); | 174 void adjustSelectionToAvoidCrossingShadowBoundaries(); |
| 174 void adjustSelectionToAvoidCrossingEditingBoundaries(); | 175 void adjustSelectionToAvoidCrossingEditingBoundaries(); |
| 175 void updateSelectionType(); | 176 void updateSelectionType(); |
| 176 | 177 |
| 177 // We need to store these as Positions because VisibleSelection is | 178 // We need to store these as Positions because VisibleSelection is |
| (...skipping 21 matching lines...) Expand all Loading... |
| 199 bool m_baseIsFirst : 1; // True if base is before the extent | 200 bool m_baseIsFirst : 1; // True if base is before the extent |
| 200 bool m_isDirectional : 1; // Non-directional ignores m_baseIsFirst and selec
tion always extends on shift + arrow key. | 201 bool m_isDirectional : 1; // Non-directional ignores m_baseIsFirst and selec
tion always extends on shift + arrow key. |
| 201 }; | 202 }; |
| 202 | 203 |
| 203 extern template class CORE_EXTERN_TEMPLATE_EXPORT VisibleSelectionTemplate<Editi
ngStrategy>; | 204 extern template class CORE_EXTERN_TEMPLATE_EXPORT VisibleSelectionTemplate<Editi
ngStrategy>; |
| 204 extern template class CORE_EXTERN_TEMPLATE_EXPORT VisibleSelectionTemplate<Editi
ngInComposedTreeStrategy>; | 205 extern template class CORE_EXTERN_TEMPLATE_EXPORT VisibleSelectionTemplate<Editi
ngInComposedTreeStrategy>; |
| 205 | 206 |
| 206 using VisibleSelection = VisibleSelectionTemplate<EditingStrategy>; | 207 using VisibleSelection = VisibleSelectionTemplate<EditingStrategy>; |
| 207 using VisibleSelectionInComposedTree = VisibleSelectionTemplate<EditingInCompose
dTreeStrategy>; | 208 using VisibleSelectionInComposedTree = VisibleSelectionTemplate<EditingInCompose
dTreeStrategy>; |
| 208 | 209 |
| 209 // TODO(yosin): We should move |SelectionAdjuster| to its own file. | |
| 210 class SelectionAdjuster final { | |
| 211 STATIC_ONLY(SelectionAdjuster); | |
| 212 public: | |
| 213 static void adjustSelectionInComposedTree(VisibleSelectionInComposedTree*, c
onst VisibleSelection&); | |
| 214 static void adjustSelectionInDOMTree(VisibleSelection*, const VisibleSelecti
onInComposedTree&); | |
| 215 static void adjustSelectionToAvoidCrossingShadowBoundaries(VisibleSelection*
); | |
| 216 static void adjustSelectionToAvoidCrossingShadowBoundaries(VisibleSelectionI
nComposedTree*); | |
| 217 }; | |
| 218 | |
| 219 // TODO(yosin): We should use |operator==()| instead of | 210 // TODO(yosin): We should use |operator==()| instead of |
| 220 // |equalSelectionsInDOMTree()|. | 211 // |equalSelectionsInDOMTree()|. |
| 221 bool equalSelectionsInDOMTree(const VisibleSelection&, const VisibleSelection&); | 212 bool equalSelectionsInDOMTree(const VisibleSelection&, const VisibleSelection&); |
| 222 | 213 |
| 223 // We don't yet support multi-range selections, so we only ever have one range | 214 // We don't yet support multi-range selections, so we only ever have one range |
| 224 // to return. | 215 // to return. |
| 225 CORE_EXPORT EphemeralRange firstEphemeralRangeOf(const VisibleSelection&); | 216 CORE_EXPORT EphemeralRange firstEphemeralRangeOf(const VisibleSelection&); |
| 226 | 217 |
| 227 // TODO(sof): move more firstRangeOf() uses to be over EphemeralRange instead. | 218 // TODO(sof): move more firstRangeOf() uses to be over EphemeralRange instead. |
| 228 CORE_EXPORT PassRefPtrWillBeRawPtr<Range> firstRangeOf(const VisibleSelection&); | 219 CORE_EXPORT PassRefPtrWillBeRawPtr<Range> firstRangeOf(const VisibleSelection&); |
| 229 | 220 |
| 230 } // namespace blink | 221 } // namespace blink |
| 231 | 222 |
| 232 #ifndef NDEBUG | 223 #ifndef NDEBUG |
| 233 // Outside the WebCore namespace for ease of invocation from gdb. | 224 // Outside the WebCore namespace for ease of invocation from gdb. |
| 234 void showTree(const blink::VisibleSelection&); | 225 void showTree(const blink::VisibleSelection&); |
| 235 void showTree(const blink::VisibleSelection*); | 226 void showTree(const blink::VisibleSelection*); |
| 236 void showTree(const blink::VisibleSelectionInComposedTree&); | 227 void showTree(const blink::VisibleSelectionInComposedTree&); |
| 237 void showTree(const blink::VisibleSelectionInComposedTree*); | 228 void showTree(const blink::VisibleSelectionInComposedTree*); |
| 238 #endif | 229 #endif |
| 239 | 230 |
| 240 #endif // VisibleSelection_h | 231 #endif // VisibleSelection_h |
| OLD | NEW |