| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #ifndef GranularityStrategy_h | 5 #ifndef GranularityStrategy_h |
| 6 #define GranularityStrategy_h | 6 #define GranularityStrategy_h |
| 7 | 7 |
| 8 #include "core/editing/SelectionStrategy.h" | 8 #include "core/editing/SelectionStrategy.h" |
| 9 #include "core/editing/VisibleSelection.h" | 9 #include "core/editing/VisibleSelection.h" |
| 10 | 10 |
| 11 namespace blink { | 11 namespace blink { |
| 12 | 12 |
| 13 class GranularityStrategy { | 13 class GranularityStrategy { |
| 14 public: | 14 public: |
| 15 virtual ~GranularityStrategy(); | 15 virtual ~GranularityStrategy(); |
| 16 virtual SelectionStrategy GetType() const = 0; | 16 virtual SelectionStrategy GetType() const = 0; |
| 17 virtual void Clear() = 0; | 17 virtual void Clear() = 0; |
| 18 | 18 |
| 19 // Calculates and returns the new selection based on the updated user | 19 // Calculates and returns the new selection based on the updated user |
| 20 // selection extent |extentPosition| and the granularity strategy. | 20 // selection extent |extentPosition| and the granularity strategy. |
| 21 virtual VisibleSelection updateExtent(const VisiblePosition& extentPosition,
const VisibleSelection&) = 0; | 21 virtual VisibleSelection updateExtent(const IntPoint&, LocalFrame*) = 0; |
| 22 | 22 |
| 23 protected: | 23 protected: |
| 24 GranularityStrategy(); | 24 GranularityStrategy(); |
| 25 }; | 25 }; |
| 26 | 26 |
| 27 // Always uses character granularity. | 27 // Always uses character granularity. |
| 28 class CharacterGranularityStrategy final : public GranularityStrategy { | 28 class CharacterGranularityStrategy final : public GranularityStrategy { |
| 29 public: | 29 public: |
| 30 CharacterGranularityStrategy(); | 30 CharacterGranularityStrategy(); |
| 31 ~CharacterGranularityStrategy() final; | 31 ~CharacterGranularityStrategy() final; |
| 32 | 32 |
| 33 // GranularityStrategy: | 33 // GranularityStrategy: |
| 34 SelectionStrategy GetType() const final; | 34 SelectionStrategy GetType() const final; |
| 35 void Clear() final; | 35 void Clear() final; |
| 36 VisibleSelection updateExtent(const VisiblePosition& extentPosition, const V
isibleSelection&) final; | 36 VisibleSelection updateExtent(const IntPoint&, LocalFrame*) final; |
| 37 }; | 37 }; |
| 38 | 38 |
| 39 // "Expand by word, shrink by character" selection strategy. | 39 // "Expand by word, shrink by character" selection strategy. |
| 40 // Uses character granularity when selection is shrinking. If the selection is | 40 // Uses character granularity when selection is shrinking. If the selection is |
| 41 // expanding, granularity doesn't change until a word boundary is passed, after | 41 // expanding, granularity doesn't change until a word boundary is passed, after |
| 42 // which the granularity switches to "word". | 42 // which the granularity switches to "word". |
| 43 class DirectionGranularityStrategy final : public GranularityStrategy { | 43 class DirectionGranularityStrategy final : public GranularityStrategy { |
| 44 public: | 44 public: |
| 45 DirectionGranularityStrategy(); | 45 DirectionGranularityStrategy(); |
| 46 ~DirectionGranularityStrategy() final; | 46 ~DirectionGranularityStrategy() final; |
| 47 | 47 |
| 48 // GranularityStrategy: | 48 // GranularityStrategy: |
| 49 SelectionStrategy GetType() const final; | 49 SelectionStrategy GetType() const final; |
| 50 void Clear() final; | 50 void Clear() final; |
| 51 VisibleSelection updateExtent(const VisiblePosition&, const VisibleSelection
&) final; | 51 VisibleSelection updateExtent(const IntPoint&, LocalFrame*) final; |
| 52 | 52 |
| 53 private: | 53 private: |
| 54 enum class BoundAdjust {CurrentPosIfOnBound, NextBoundIfOnBound}; | 54 enum class BoundAdjust {CurrentPosIfOnBound, NextBoundIfOnBound}; |
| 55 enum class SearchDirection {SearchBackwards, SearchForward}; | 55 enum class SearchDirection {SearchBackwards, SearchForward}; |
| 56 | 56 |
| 57 // Returns the next word boundary starting from |pos|. |direction| specifies | 57 // Returns the next word boundary starting from |pos|. |direction| specifies |
| 58 // the direction in which to search for the next bound. nextIfOnBound | 58 // the direction in which to search for the next bound. nextIfOnBound |
| 59 // controls whether |pos| or the next boundary is returned when |pos| is | 59 // controls whether |pos| or the next boundary is returned when |pos| is |
| 60 // located exactly on word boundary. | 60 // located exactly on word boundary. |
| 61 VisiblePosition nextWordBound(const VisiblePosition& /*pos*/, SearchDirectio
n /*direction*/, BoundAdjust /*nextIfOnBound*/); | 61 VisiblePosition nextWordBound(const VisiblePosition& /*pos*/, SearchDirectio
n /*direction*/, BoundAdjust /*nextIfOnBound*/); |
| 62 | 62 |
| 63 // Current selection granularity being used | 63 // Current selection granularity being used |
| 64 TextGranularity m_granularity; | 64 TextGranularity m_granularity; |
| 65 // Set to true if the selection was shrunk (without changing relative | 65 // Set to true if the selection was shrunk (without changing relative |
| 66 // base/extent order) as a result of the most recent updateExtent call. | 66 // base/extent order) as a result of the most recent updateExtent call. |
| 67 bool m_lastMoveShrunkSelection; | 67 bool m_lastMoveShrunkSelection; |
| 68 IntPoint m_extentPoint; |
| 69 int m_offset; |
| 68 }; | 70 }; |
| 69 | 71 |
| 70 } // namespace blink | 72 } // namespace blink |
| 71 | 73 |
| 72 #endif // GranularityStrategy_h | 74 #endif // GranularityStrategy_h |
| OLD | NEW |