Index: Source/core/editing/GranularityStrategy.h |
diff --git a/Source/core/editing/GranularityStrategy.h b/Source/core/editing/GranularityStrategy.h |
new file mode 100644 |
index 0000000000000000000000000000000000000000..0ad8b0b8c6ec7457093ffd0e5365763bfe83f3cf |
--- /dev/null |
+++ b/Source/core/editing/GranularityStrategy.h |
@@ -0,0 +1,94 @@ |
+/* |
yosin_UTC9
2015/04/21 01:59:52
nit: Let's use the short version of licence commen
mfomitchev
2015/04/21 18:44:25
Done - for all 3 new files.
|
+ * Copyright 2015, Google Inc. All rights reserved. |
+ * |
+ * Redistribution and use in source and binary forms, with or without |
+ * modification, are permitted provided that the following conditions are |
+ * met: |
+ * |
+ * * Redistributions of source code must retain the above copyright |
+ * notice, this list of conditions and the following disclaimer. |
+ * * Redistributions in binary form must reproduce the above |
+ * copyright notice, this list of conditions and the following disclaimer |
+ * in the documentation and/or other materials provided with the |
+ * distribution. |
+ * * Neither the name of Google Inc. nor the names of its |
+ * contributors may be used to endorse or promote products derived from |
+ * this software without specific prior written permission. |
+ * |
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
+ */ |
+ |
+#ifndef GranularityStrategy_h |
+#define GranularityStrategy_h |
+ |
+#include "core/editing/SelectionStrategy.h" |
+#include "core/editing/VisibleSelection.h" |
+ |
+namespace blink { |
+ |
+class GranularityStrategy { |
+public: |
+ virtual ~GranularityStrategy() { }; |
yosin_UTC9
2015/04/21 01:59:52
Let's move inline virtual functions into .cpp file
mfomitchev
2015/04/21 18:44:25
Done.
|
+ virtual SelectionStrategy GetType() const = 0; |
+ virtual void Clear() = 0; |
+ |
+ // Calculates and returns the new selection based on the updated user selection extent |extentPosition| and the granularity strategy. |
+ virtual VisibleSelection updateExtent(const VisiblePosition& extentPosition, const VisibleSelection&) = 0; |
+protected: |
+ GranularityStrategy() { }; |
+}; |
+ |
+// Always uses character granularity. |
+class CharacterGranularityStrategy final : public GranularityStrategy { |
+public: |
+ CharacterGranularityStrategy() { }; |
+ ~CharacterGranularityStrategy() override { }; |
yosin_UTC9
2015/04/21 01:59:52
nit: |final|.
This comment is applied rest of |ove
mfomitchev
2015/04/21 18:44:25
Done.
|
+ |
+ // GranularityStrategy: |
+ SelectionStrategy GetType() const override { return StrategyCharacter; } |
+ void Clear() override { }; |
+ VisibleSelection updateExtent(const VisiblePosition& extentPosition, const VisibleSelection&) override; |
+}; |
+ |
+// "Expand by word, shrink by character" selection strategy. |
+// Uses character granularity when selection is shrinking. If the selection is expanding, |
+// granularity doesn't change until a word boundary is passed, after which the granularity |
+// switches to "word". |
+class DirectionGranularityStrategy final : public GranularityStrategy { |
+public: |
+ DirectionGranularityStrategy(); |
+ ~DirectionGranularityStrategy() override { }; |
+ |
+ // GranularityStrategy: |
+ SelectionStrategy GetType() const override { return StrategyDirection; } |
+ void Clear() override; |
+ VisibleSelection updateExtent(const VisiblePosition&, const VisibleSelection&) override; |
+private: |
+ enum class EBoundAdjust {CurrentPosIfOnBound, NextBoundIfOnBound}; |
yosin_UTC9
2015/04/21 01:59:52
I think we don't need to have prefix "E". Since, t
mfomitchev
2015/04/21 18:44:25
Done.
|
+ enum class ESearchDirection {SearchBackwards, SearchForward}; |
+ |
+ // Returns the next word boundary starting from |pos|. |direction| specifies the direction |
+ // in which to search for the next bound. nextIfOnBound controls whether |pos| or the next boundary |
+ // is returned when |pos| is located exactly on word boundary. |
+ VisiblePosition nextWordBound(const VisiblePosition& /*pos*/, ESearchDirection /*direction*/, EBoundAdjust /*nextIfOnBound*/); |
+ |
+ // Current selection granularity being used |
+ TextGranularity m_granularity; |
+ // Set to true if the selection was shrunk (without changing relative base/extent order) |
+ // as a result of the most recent updateExtent call. |
+ bool m_lastMoveShrunkSelection; |
+}; |
+ |
+} // namespace blink |
+ |
+#endif // GranularityStrategy_h |