Chromium Code Reviews| 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 | 32 |
| 33 namespace WebCore { | 33 namespace WebCore { |
| 34 | 34 |
| 35 class LayoutPoint; | 35 class LayoutPoint; |
| 36 class Position; | 36 class Position; |
| 37 | 37 |
| 38 const EAffinity SEL_DEFAULT_AFFINITY = DOWNSTREAM; | 38 const EAffinity SEL_DEFAULT_AFFINITY = DOWNSTREAM; |
| 39 enum SelectionDirection { DirectionForward, DirectionBackward, DirectionRight, D irectionLeft }; | 39 enum SelectionDirection { DirectionForward, DirectionBackward, DirectionRight, D irectionLeft }; |
| 40 | 40 |
| 41 class VisibleSelection { | 41 class VisibleSelection { |
| 42 ALLOW_ONLY_INLINE_ALLOCATION(); | |
|
haraken
2014/05/28 15:35:25
Just help me understand: Who uses VisibleSelection
sof
2014/05/28 22:06:06
Yes, no more than DISALLOW_ALLOCATION() is needed.
| |
| 42 public: | 43 public: |
| 43 VisibleSelection(); | 44 VisibleSelection(); |
| 44 | 45 |
| 45 VisibleSelection(const Position&, EAffinity, bool isDirectional = false); | 46 VisibleSelection(const Position&, EAffinity, bool isDirectional = false); |
| 46 VisibleSelection(const Position&, const Position&, EAffinity = SEL_DEFAULT_A FFINITY, bool isDirectional = false); | 47 VisibleSelection(const Position&, const Position&, EAffinity = SEL_DEFAULT_A FFINITY, bool isDirectional = false); |
| 47 | 48 |
| 48 explicit VisibleSelection(const Range*, EAffinity = SEL_DEFAULT_AFFINITY, bo ol isDirectional = false); | 49 explicit VisibleSelection(const Range*, EAffinity = SEL_DEFAULT_AFFINITY, bo ol isDirectional = false); |
| 49 | 50 |
| 50 explicit VisibleSelection(const VisiblePosition&, bool isDirectional = false ); | 51 explicit VisibleSelection(const VisiblePosition&, bool isDirectional = false ); |
| 51 VisibleSelection(const VisiblePosition&, const VisiblePosition&, bool isDire ctional = false); | 52 VisibleSelection(const VisiblePosition&, const VisiblePosition&, bool isDire ctional = false); |
| (...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 121 public: | 122 public: |
| 122 ChangeObserver(); | 123 ChangeObserver(); |
| 123 virtual ~ChangeObserver(); | 124 virtual ~ChangeObserver(); |
| 124 virtual void didChangeVisibleSelection() = 0; | 125 virtual void didChangeVisibleSelection() = 0; |
| 125 }; | 126 }; |
| 126 | 127 |
| 127 void setChangeObserver(ChangeObserver&); | 128 void setChangeObserver(ChangeObserver&); |
| 128 void clearChangeObserver(); | 129 void clearChangeObserver(); |
| 129 void didChange(); // Fire the change observer, if any. | 130 void didChange(); // Fire the change observer, if any. |
| 130 | 131 |
| 132 void trace(Visitor*); | |
| 133 | |
| 131 #ifndef NDEBUG | 134 #ifndef NDEBUG |
| 132 void debugPosition() const; | 135 void debugPosition() const; |
| 133 void formatForDebugger(char* buffer, unsigned length) const; | 136 void formatForDebugger(char* buffer, unsigned length) const; |
| 134 void showTreeForThis() const; | 137 void showTreeForThis() const; |
| 135 #endif | 138 #endif |
| 136 | 139 |
| 137 private: | 140 private: |
| 138 void validate(TextGranularity = CharacterGranularity); | 141 void validate(TextGranularity = CharacterGranularity); |
| 139 | 142 |
| 140 // Support methods for validate() | 143 // Support methods for validate() |
| 141 void setBaseAndExtentToDeepEquivalents(); | 144 void setBaseAndExtentToDeepEquivalents(); |
| 142 void setStartAndEndFromBaseAndExtentRespectingGranularity(TextGranularity); | 145 void setStartAndEndFromBaseAndExtentRespectingGranularity(TextGranularity); |
| 143 void adjustSelectionToAvoidCrossingShadowBoundaries(); | 146 void adjustSelectionToAvoidCrossingShadowBoundaries(); |
| 144 void adjustSelectionToAvoidCrossingEditingBoundaries(); | 147 void adjustSelectionToAvoidCrossingEditingBoundaries(); |
| 145 void updateSelectionType(); | 148 void updateSelectionType(); |
| 146 | 149 |
| 147 // We need to store these as Positions because VisibleSelection is | 150 // We need to store these as Positions because VisibleSelection is |
| 148 // used to store values in editing commands for use when | 151 // used to store values in editing commands for use when |
| 149 // undoing the command. We need to be able to create a selection that, while currently | 152 // undoing the command. We need to be able to create a selection that, while currently |
| 150 // invalid, will be valid once the changes are undone. | 153 // invalid, will be valid once the changes are undone. |
| 151 | 154 |
| 152 Position m_base; // Where the first click happened | 155 Position m_base; // Where the first click happened |
| 153 Position m_extent; // Where the end click happened | 156 Position m_extent; // Where the end click happened |
| 154 Position m_start; // Leftmost position when expanded to respect granularity | 157 Position m_start; // Leftmost position when expanded to respect granularity |
| 155 Position m_end; // Rightmost position when expanded to respect granularit y | 158 Position m_end; // Rightmost position when expanded to respect granularit y |
| 156 | 159 |
| 157 EAffinity m_affinity; // the upstream/downstream affinity of the c aret | 160 EAffinity m_affinity; // the upstream/downstream affinity of the c aret |
| 158 | 161 |
| 159 ChangeObserver* m_changeObserver; | 162 ChangeObserver* m_changeObserver; |
|
haraken
2014/05/28 15:35:25
I think this should be a WeakMember.
| |
| 160 | 163 |
| 161 // these are cached, can be recalculated by validate() | 164 // these are cached, can be recalculated by validate() |
| 162 SelectionType m_selectionType; // None, Caret, Range | 165 SelectionType m_selectionType; // None, Caret, Range |
| 163 bool m_baseIsFirst : 1; // True if base is before the extent | 166 bool m_baseIsFirst : 1; // True if base is before the extent |
| 164 bool m_isDirectional : 1; // Non-directional ignores m_baseIsFirst and selec tion always extends on shift + arrow key. | 167 bool m_isDirectional : 1; // Non-directional ignores m_baseIsFirst and selec tion always extends on shift + arrow key. |
| 165 }; | 168 }; |
| 166 | 169 |
| 167 inline bool operator==(const VisibleSelection& a, const VisibleSelection& b) | 170 inline bool operator==(const VisibleSelection& a, const VisibleSelection& b) |
| 168 { | 171 { |
| 169 return a.start() == b.start() && a.end() == b.end() && a.affinity() == b.aff inity() && a.isBaseFirst() == b.isBaseFirst() | 172 return a.start() == b.start() && a.end() == b.end() && a.affinity() == b.aff inity() && a.isBaseFirst() == b.isBaseFirst() |
| 170 && a.isDirectional() == b.isDirectional(); | 173 && a.isDirectional() == b.isDirectional(); |
| 171 } | 174 } |
| 172 | 175 |
| 173 inline bool operator!=(const VisibleSelection& a, const VisibleSelection& b) | 176 inline bool operator!=(const VisibleSelection& a, const VisibleSelection& b) |
| 174 { | 177 { |
| 175 return !(a == b); | 178 return !(a == b); |
| 176 } | 179 } |
| 177 | 180 |
| 178 } // namespace WebCore | 181 } // namespace WebCore |
| 179 | 182 |
| 180 #ifndef NDEBUG | 183 #ifndef NDEBUG |
| 181 // Outside the WebCore namespace for ease of invocation from gdb. | 184 // Outside the WebCore namespace for ease of invocation from gdb. |
| 182 void showTree(const WebCore::VisibleSelection&); | 185 void showTree(const WebCore::VisibleSelection&); |
| 183 void showTree(const WebCore::VisibleSelection*); | 186 void showTree(const WebCore::VisibleSelection*); |
| 184 #endif | 187 #endif |
| 185 | 188 |
| 186 #endif // VisibleSelection_h | 189 #endif // VisibleSelection_h |
| OLD | NEW |