Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(42)

Side by Side Diff: Source/core/editing/GranularityStrategy.h

Issue 988023005: Implementing directional selection strategy in Blink. (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Putting GranularityStrategy into separate files. Created 5 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
1 /*
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.
2 * Copyright 2015, Google Inc. All rights reserved.
3 *
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are
6 * met:
7 *
8 * * Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * * Redistributions in binary form must reproduce the above
11 * copyright notice, this list of conditions and the following disclaimer
12 * in the documentation and/or other materials provided with the
13 * distribution.
14 * * Neither the name of Google Inc. nor the names of its
15 * contributors may be used to endorse or promote products derived from
16 * this software without specific prior written permission.
17 *
18 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
20 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
21 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
22 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
23 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 */
30
31 #ifndef GranularityStrategy_h
32 #define GranularityStrategy_h
33
34 #include "core/editing/SelectionStrategy.h"
35 #include "core/editing/VisibleSelection.h"
36
37 namespace blink {
38
39 class GranularityStrategy {
40 public:
41 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.
42 virtual SelectionStrategy GetType() const = 0;
43 virtual void Clear() = 0;
44
45 // Calculates and returns the new selection based on the updated user select ion extent |extentPosition| and the granularity strategy.
46 virtual VisibleSelection updateExtent(const VisiblePosition& extentPosition, const VisibleSelection&) = 0;
47 protected:
48 GranularityStrategy() { };
49 };
50
51 // Always uses character granularity.
52 class CharacterGranularityStrategy final : public GranularityStrategy {
53 public:
54 CharacterGranularityStrategy() { };
55 ~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.
56
57 // GranularityStrategy:
58 SelectionStrategy GetType() const override { return StrategyCharacter; }
59 void Clear() override { };
60 VisibleSelection updateExtent(const VisiblePosition& extentPosition, const V isibleSelection&) override;
61 };
62
63 // "Expand by word, shrink by character" selection strategy.
64 // Uses character granularity when selection is shrinking. If the selection is e xpanding,
65 // granularity doesn't change until a word boundary is passed, after which the g ranularity
66 // switches to "word".
67 class DirectionGranularityStrategy final : public GranularityStrategy {
68 public:
69 DirectionGranularityStrategy();
70 ~DirectionGranularityStrategy() override { };
71
72 // GranularityStrategy:
73 SelectionStrategy GetType() const override { return StrategyDirection; }
74 void Clear() override;
75 VisibleSelection updateExtent(const VisiblePosition&, const VisibleSelection &) override;
76 private:
77 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.
78 enum class ESearchDirection {SearchBackwards, SearchForward};
79
80 // Returns the next word boundary starting from |pos|. |direction| specifies the direction
81 // in which to search for the next bound. nextIfOnBound controls whether |po s| or the next boundary
82 // is returned when |pos| is located exactly on word boundary.
83 VisiblePosition nextWordBound(const VisiblePosition& /*pos*/, ESearchDirecti on /*direction*/, EBoundAdjust /*nextIfOnBound*/);
84
85 // Current selection granularity being used
86 TextGranularity m_granularity;
87 // Set to true if the selection was shrunk (without changing relative base/e xtent order)
88 // as a result of the most recent updateExtent call.
89 bool m_lastMoveShrunkSelection;
90 };
91
92 } // namespace blink
93
94 #endif // GranularityStrategy_h
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698