| 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 VIEWS_CONTROLS_TEXTFIELD_TEXTFIELD_VIEWS_MODEL_H_ | 5 #ifndef VIEWS_CONTROLS_TEXTFIELD_TEXTFIELD_VIEWS_MODEL_H_ |
| 6 #define VIEWS_CONTROLS_TEXTFIELD_TEXTFIELD_VIEWS_MODEL_H_ | 6 #define VIEWS_CONTROLS_TEXTFIELD_TEXTFIELD_VIEWS_MODEL_H_ |
| 7 #pragma once | 7 #pragma once |
| 8 | 8 |
| 9 #include <vector> | 9 #include <vector> |
| 10 | 10 |
| 11 #include "base/string16.h" | 11 #include "base/string16.h" |
| 12 #include "gfx/rect.h" | 12 #include "gfx/rect.h" |
| 13 #include "third_party/skia/include/core/SkColor.h" | 13 #include "third_party/skia/include/core/SkColor.h" |
| 14 | 14 |
| 15 namespace gfx { | 15 namespace gfx { |
| 16 class Font; | 16 class Font; |
| 17 } // namespace gfx | 17 } // namespace gfx |
| 18 | 18 |
| 19 namespace views { | 19 namespace views { |
| 20 | 20 |
| 21 class TextRange; |
| 22 |
| 21 // A model that represents a text content for TextfieldViews. | 23 // A model that represents a text content for TextfieldViews. |
| 22 // It supports editing, selection and cursor manipulation. | 24 // It supports editing, selection and cursor manipulation. |
| 23 class TextfieldViewsModel { | 25 class TextfieldViewsModel { |
| 24 public: | 26 public: |
| 25 TextfieldViewsModel(); | 27 TextfieldViewsModel(); |
| 26 virtual ~TextfieldViewsModel(); | 28 virtual ~TextfieldViewsModel(); |
| 27 | 29 |
| 28 // Text fragment info. Used to draw selected text. | 30 // Text fragment info. Used to draw selected text. |
| 29 // We may replace this with TextAttribute class | 31 // We may replace this with TextAttribute class |
| 30 // in the future to support multi-color text | 32 // in the future to support multi-color text |
| (...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 107 bool MoveCursorTo(size_t position, bool select); | 109 bool MoveCursorTo(size_t position, bool select); |
| 108 | 110 |
| 109 // Returns the bounds of character at the current cursor. | 111 // Returns the bounds of character at the current cursor. |
| 110 gfx::Rect GetCursorBounds(const gfx::Font& font) const; | 112 gfx::Rect GetCursorBounds(const gfx::Font& font) const; |
| 111 | 113 |
| 112 // Selection related method | 114 // Selection related method |
| 113 | 115 |
| 114 // Returns the selected text. | 116 // Returns the selected text. |
| 115 string16 GetSelectedText() const; | 117 string16 GetSelectedText() const; |
| 116 | 118 |
| 119 void GetSelectedRange(TextRange* range) const; |
| 120 |
| 121 void SelectRange(const TextRange& range); |
| 122 |
| 117 // Selects all text. | 123 // Selects all text. |
| 118 void SelectAll(); | 124 void SelectAll(); |
| 119 | 125 |
| 120 // Clears selection. | 126 // Clears selection. |
| 121 void ClearSelection(); | 127 void ClearSelection(); |
| 122 | 128 |
| 123 // Returns visible text. If the field is password, it returns the | 129 // Returns visible text. If the field is password, it returns the |
| 124 // sequence of "*". | 130 // sequence of "*". |
| 125 string16 GetVisibleText() const { | 131 string16 GetVisibleText() const { |
| 126 return GetVisibleText(0U, text_.length()); | 132 return GetVisibleText(0U, text_.length()); |
| (...skipping 15 matching lines...) Expand all Loading... |
| 142 | 148 |
| 143 private: | 149 private: |
| 144 friend class NativeTextfieldViews; | 150 friend class NativeTextfieldViews; |
| 145 | 151 |
| 146 // Deletes the selected text. | 152 // Deletes the selected text. |
| 147 void DeleteSelection(); | 153 void DeleteSelection(); |
| 148 | 154 |
| 149 // Returns the visible text given |start| and |end|. | 155 // Returns the visible text given |start| and |end|. |
| 150 string16 GetVisibleText(size_t start, size_t end) const; | 156 string16 GetVisibleText(size_t start, size_t end) const; |
| 151 | 157 |
| 158 // Returns the normalized cursor position that does not exceed the |
| 159 // text length. |
| 160 size_t GetSafePosition(size_t position) const; |
| 161 |
| 152 // The text in utf16 format. | 162 // The text in utf16 format. |
| 153 string16 text_; | 163 string16 text_; |
| 154 | 164 |
| 155 // Current cursor position. | 165 // Current cursor position. |
| 156 size_t cursor_pos_; | 166 size_t cursor_pos_; |
| 157 | 167 |
| 158 // Selection range. | 168 // Selection range. |
| 159 size_t selection_begin_; | 169 size_t selection_begin_; |
| 160 | 170 |
| 161 // True if the text is the password. | 171 // True if the text is the password. |
| 162 bool is_password_; | 172 bool is_password_; |
| 163 | 173 |
| 164 DISALLOW_COPY_AND_ASSIGN(TextfieldViewsModel); | 174 DISALLOW_COPY_AND_ASSIGN(TextfieldViewsModel); |
| 165 }; | 175 }; |
| 166 | 176 |
| 167 } // namespace views | 177 } // namespace views |
| 168 | 178 |
| 169 #endif // VIEWS_CONTROLS_TEXTFIELD_TEXTFIELD_VIEWS_MODEL_H_ | 179 #endif // VIEWS_CONTROLS_TEXTFIELD_TEXTFIELD_VIEWS_MODEL_H_ |
| OLD | NEW |