Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 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 | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #ifndef GranularityStrategy_h | |
| 6 #define GranularityStrategy_h | |
| 7 | |
| 8 #include "core/editing/SelectionStrategy.h" | |
| 9 #include "core/editing/VisibleSelection.h" | |
| 10 | |
| 11 namespace blink { | |
| 12 | |
| 13 class GranularityStrategy { | |
| 14 public: | |
| 15 virtual ~GranularityStrategy(); | |
| 16 virtual SelectionStrategy GetType() const = 0; | |
| 17 virtual void Clear() = 0; | |
| 18 | |
| 19 // Calculates and returns the new selection based on the updated user select ion extent |extentPosition| and the granularity strategy. | |
| 20 virtual VisibleSelection updateExtent(const VisiblePosition& extentPosition, const VisibleSelection&) = 0; | |
| 21 protected: | |
|
yosin_UTC9
2015/04/23 03:38:47
nit: Please insert a blank line before |protected:
mfomitchev
2015/04/23 15:08:11
Done.
| |
| 22 GranularityStrategy(); | |
| 23 }; | |
| 24 | |
| 25 // Always uses character granularity. | |
| 26 class CharacterGranularityStrategy final : public GranularityStrategy { | |
| 27 public: | |
| 28 CharacterGranularityStrategy(); | |
| 29 ~CharacterGranularityStrategy() final; | |
| 30 | |
| 31 // GranularityStrategy: | |
| 32 SelectionStrategy GetType() const final; | |
| 33 void Clear() final; | |
| 34 VisibleSelection updateExtent(const VisiblePosition& extentPosition, const V isibleSelection&) final; | |
| 35 }; | |
| 36 | |
| 37 // "Expand by word, shrink by character" selection strategy. | |
| 38 // Uses character granularity when selection is shrinking. If the selection is e xpanding, | |
| 39 // granularity doesn't change until a word boundary is passed, after which the g ranularity | |
| 40 // switches to "word". | |
| 41 class DirectionGranularityStrategy final : public GranularityStrategy { | |
| 42 public: | |
| 43 DirectionGranularityStrategy(); | |
| 44 ~DirectionGranularityStrategy() final; | |
| 45 | |
| 46 // GranularityStrategy: | |
| 47 SelectionStrategy GetType() const final; | |
| 48 void Clear() final; | |
| 49 VisibleSelection updateExtent(const VisiblePosition&, const VisibleSelection &) final; | |
| 50 private: | |
|
yosin_UTC9
2015/04/23 03:38:47
nit: Please insert a blank line before |private:|
mfomitchev
2015/04/23 15:08:11
Done.
| |
| 51 enum class BoundAdjust {CurrentPosIfOnBound, NextBoundIfOnBound}; | |
| 52 enum class SearchDirection {SearchBackwards, SearchForward}; | |
| 53 | |
| 54 // Returns the next word boundary starting from |pos|. |direction| specifies the direction | |
| 55 // in which to search for the next bound. nextIfOnBound controls whether |po s| or the next boundary | |
| 56 // is returned when |pos| is located exactly on word boundary. | |
| 57 VisiblePosition nextWordBound(const VisiblePosition& /*pos*/, SearchDirectio n /*direction*/, BoundAdjust /*nextIfOnBound*/); | |
| 58 | |
| 59 // Current selection granularity being used | |
| 60 TextGranularity m_granularity; | |
| 61 // Set to true if the selection was shrunk (without changing relative base/e xtent order) | |
| 62 // as a result of the most recent updateExtent call. | |
| 63 bool m_lastMoveShrunkSelection; | |
| 64 }; | |
| 65 | |
| 66 } // namespace blink | |
| 67 | |
| 68 #endif // GranularityStrategy_h | |
| OLD | NEW |