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

Side by Side Diff: ui/gfx/selection_model.h

Issue 8044004: Clean up of SelectionModel (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: '' Created 9 years, 2 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 | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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 UI_GFX_SELECTION_MODEL_H_ 5 #ifndef UI_GFX_SELECTION_MODEL_H_
6 #define UI_GFX_SELECTION_MODEL_H_ 6 #define UI_GFX_SELECTION_MODEL_H_
7 #pragma once 7 #pragma once
8 8
9 #include <stdlib.h> 9 #include <stdlib.h>
10 10
(...skipping 27 matching lines...) Expand all
38 // information to specify to which character and on which edge of the character 38 // information to specify to which character and on which edge of the character
39 // the visual cursor is bound to. For example, the visual cursor is bound to 39 // the visual cursor is bound to. For example, the visual cursor is bound to
40 // the trailing side of the 2nd character 'c' when pointing to right half of 40 // the trailing side of the 2nd character 'c' when pointing to right half of
41 // 'c'. And it is bound to the leading edge of the 3rd character 'D' when 41 // 'c'. And it is bound to the leading edge of the 3rd character 'D' when
42 // pointing to right of 'D'. 42 // pointing to right of 'D'.
43 class UI_EXPORT SelectionModel { 43 class UI_EXPORT SelectionModel {
44 public: 44 public:
45 enum CaretPlacement { 45 enum CaretPlacement {
46 LEADING, 46 LEADING,
47 TRAILING, 47 TRAILING,
48 // TRAILING_OF_PREVIOUS_GRAPHEME means cursor is visually at the trailing
49 // edge of |selection_end_|'s previous grapheme. It is used when create a
msw 2011/09/29 02:20:21 Grammar: "means *that the* cursor". Grammar: "It i
xji 2011/10/03 23:18:57 it is removed.
50 // SelectionModel with non-empty selection and the selection's start is less
51 // than the selection's end. When SelectionModel is used in RenderText, in
52 // SetSelectionModel(), in case of TRAILING_OF_PREVIOUS_GRAPHEME,
53 // |caret_pos_| will be set as the index of |selection_end_|'s previous
54 // grapheme, and |caret_placement_| will be set as TRAILING.
55 TRAILING_OF_PREVIOUS_GRAPHEME,
msw 2011/09/29 02:20:21 I like your old name (TRAILING_PREIVOUS_GRAPHEME)
48 }; 56 };
49 57
50 SelectionModel(); 58 SelectionModel();
51 explicit SelectionModel(size_t pos); 59 explicit SelectionModel(size_t pos);
52 SelectionModel(size_t start, size_t end); 60 SelectionModel(size_t start, size_t end);
53 SelectionModel(size_t end, size_t pos, CaretPlacement status); 61 SelectionModel(size_t end, size_t pos, CaretPlacement status);
54 SelectionModel(size_t start, size_t end, size_t pos, CaretPlacement status); 62 SelectionModel(size_t start, size_t end, size_t pos, CaretPlacement status);
55 63
56 virtual ~SelectionModel(); 64 virtual ~SelectionModel();
57 65
58 size_t selection_start() const { return selection_start_; } 66 size_t selection_start() const { return selection_start_; }
59 void set_selection_start(size_t pos) { selection_start_ = pos; } 67 void set_selection_start(size_t pos) { selection_start_ = pos; }
msw 2011/09/29 02:20:21 Should set_selection_start also be made private?
xji 2011/10/03 23:18:57 Done.
60 68
61 size_t selection_end() const { return selection_end_; } 69 size_t selection_end() const { return selection_end_; }
62 void set_selection_end(size_t pos) { selection_end_ = pos; }
63
64 size_t caret_pos() const { return caret_pos_; } 70 size_t caret_pos() const { return caret_pos_; }
65 void set_caret_pos(size_t pos) { caret_pos_ = pos; }
66
67 CaretPlacement caret_placement() const { return caret_placement_; } 71 CaretPlacement caret_placement() const { return caret_placement_; }
68 void set_caret_placement(CaretPlacement placement) {
69 caret_placement_ = placement;
70 }
71 72
72 bool Equals(const SelectionModel& sel) const; 73 bool Equals(const SelectionModel& sel) const;
73 74
74 private: 75 private:
76 friend class RenderText;
msw 2011/09/29 02:20:21 I don't know that making RenderText a friend and m
77
75 void Init(size_t start, size_t end, size_t pos, CaretPlacement status); 78 void Init(size_t start, size_t end, size_t pos, CaretPlacement status);
76 79
80 void set_selection_end(size_t pos) { selection_end_ = pos; }
81 void set_caret_pos(size_t pos) { caret_pos_ = pos; }
82
msw 2011/09/29 02:20:21 You can remove this blank line.
xji 2011/10/03 23:18:57 Done.
83 void set_caret_placement(CaretPlacement placement) {
84 caret_placement_ = placement;
85 }
msw 2011/09/29 02:20:21 You should add a blank line after this function, b
xji 2011/10/03 23:18:57 Done.
77 // Logical selection start. If there is non-empty selection, if 86 // Logical selection start. If there is non-empty selection, if
78 // selection_start_ is less than selection_end_, the selection starts visually 87 // selection_start_ is less than selection_end_, the selection starts visually
79 // at the leading edge of the selection_start_. If selection_start_ is greater 88 // at the leading edge of the selection_start_. If selection_start_ is greater
80 // than selection_end_, the selection starts visually at the trailing edge of 89 // than selection_end_, the selection starts visually at the trailing edge of
81 // selection_start_'s previous grapheme. So, we do not need extra information 90 // selection_start_'s previous grapheme. So, we do not need extra information
82 // for visual bounding. 91 // for visual bounding.
83 size_t selection_start_; 92 size_t selection_start_;
84 93
85 // The logical cursor position that next character will be inserted into. 94 // The logical cursor position that next character will be inserted into.
86 // It is also the end of the selection. 95 // It is also the end of the selection.
87 size_t selection_end_; 96 size_t selection_end_;
88 97
89 // The following two fields are used to guide cursor visual position. 98 // The following two fields are used to guide cursor visual position.
90 // The index of the character that cursor is visually attached to. 99 // The index of the character that cursor is visually attached to.
91 size_t caret_pos_; 100 size_t caret_pos_;
92 // The visual placement of the cursor, relative to its associated character. 101 // The visual placement of the cursor, relative to its associated character.
93 CaretPlacement caret_placement_; 102 CaretPlacement caret_placement_;
94 }; 103 };
95 104
96 } // namespace gfx 105 } // namespace gfx
97 106
98 #endif // UI_GFX_SELECTION_MODEL_H_ 107 #endif // UI_GFX_SELECTION_MODEL_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698