| OLD | NEW |
| 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 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 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 }; | 48 }; |
| 49 | 49 |
| 50 SelectionModel(); | 50 SelectionModel(); |
| 51 explicit SelectionModel(size_t pos); | 51 explicit SelectionModel(size_t pos); |
| 52 SelectionModel(size_t start, size_t end); | |
| 53 SelectionModel(size_t end, size_t pos, CaretPlacement status); | 52 SelectionModel(size_t end, size_t pos, CaretPlacement status); |
| 54 SelectionModel(size_t start, size_t end, size_t pos, CaretPlacement status); | 53 SelectionModel(size_t start, size_t end, size_t pos, CaretPlacement status); |
| 55 | 54 |
| 56 virtual ~SelectionModel(); | 55 virtual ~SelectionModel(); |
| 57 | 56 |
| 58 size_t selection_start() const { return selection_start_; } | 57 size_t selection_start() const { return selection_start_; } |
| 58 size_t selection_end() const { return selection_end_; } |
| 59 size_t caret_pos() const { return caret_pos_; } |
| 60 CaretPlacement caret_placement() const { return caret_placement_; } |
| 61 |
| 62 bool Equals(const SelectionModel& sel) const; |
| 63 |
| 64 private: |
| 65 friend class RenderText; |
| 66 |
| 67 void Init(size_t start, size_t end, size_t pos, CaretPlacement status); |
| 68 |
| 59 void set_selection_start(size_t pos) { selection_start_ = pos; } | 69 void set_selection_start(size_t pos) { selection_start_ = pos; } |
| 60 | |
| 61 size_t selection_end() const { return selection_end_; } | |
| 62 void set_selection_end(size_t pos) { selection_end_ = pos; } | 70 void set_selection_end(size_t pos) { selection_end_ = pos; } |
| 63 | |
| 64 size_t caret_pos() const { return caret_pos_; } | |
| 65 void set_caret_pos(size_t pos) { caret_pos_ = pos; } | 71 void set_caret_pos(size_t pos) { caret_pos_ = pos; } |
| 66 | |
| 67 CaretPlacement caret_placement() const { return caret_placement_; } | |
| 68 void set_caret_placement(CaretPlacement placement) { | 72 void set_caret_placement(CaretPlacement placement) { |
| 69 caret_placement_ = placement; | 73 caret_placement_ = placement; |
| 70 } | 74 } |
| 71 | 75 |
| 72 bool Equals(const SelectionModel& sel) const; | |
| 73 | |
| 74 private: | |
| 75 void Init(size_t start, size_t end, size_t pos, CaretPlacement status); | |
| 76 | |
| 77 // Logical selection start. If there is non-empty selection, if | 76 // Logical selection start. If there is non-empty selection, if |
| 78 // selection_start_ is less than selection_end_, the selection starts visually | 77 // 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 | 78 // 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 | 79 // 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 | 80 // selection_start_'s previous grapheme. So, we do not need extra information |
| 82 // for visual bounding. | 81 // for visual bounding. |
| 83 size_t selection_start_; | 82 size_t selection_start_; |
| 84 | 83 |
| 85 // The logical cursor position that next character will be inserted into. | 84 // The logical cursor position that next character will be inserted into. |
| 86 // It is also the end of the selection. | 85 // It is also the end of the selection. |
| 87 size_t selection_end_; | 86 size_t selection_end_; |
| 88 | 87 |
| 89 // The following two fields are used to guide cursor visual position. | 88 // The following two fields are used to guide cursor visual position. |
| 90 // The index of the character that cursor is visually attached to. | 89 // The index of the character that cursor is visually attached to. |
| 91 size_t caret_pos_; | 90 size_t caret_pos_; |
| 92 // The visual placement of the cursor, relative to its associated character. | 91 // The visual placement of the cursor, relative to its associated character. |
| 93 CaretPlacement caret_placement_; | 92 CaretPlacement caret_placement_; |
| 94 }; | 93 }; |
| 95 | 94 |
| 96 } // namespace gfx | 95 } // namespace gfx |
| 97 | 96 |
| 98 #endif // UI_GFX_SELECTION_MODEL_H_ | 97 #endif // UI_GFX_SELECTION_MODEL_H_ |
| OLD | NEW |