| 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_RENDER_TEXT_H_ | 5 #ifndef UI_GFX_RENDER_TEXT_H_ |
| 6 #define UI_GFX_RENDER_TEXT_H_ | 6 #define UI_GFX_RENDER_TEXT_H_ |
| 7 #pragma once | 7 #pragma once |
| 8 | 8 |
| 9 #include <algorithm> | 9 #include <algorithm> |
| 10 #include <vector> | 10 #include <vector> |
| (...skipping 153 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 164 bool insert_mode() const { return insert_mode_; } | 164 bool insert_mode() const { return insert_mode_; } |
| 165 void toggle_insert_mode() { insert_mode_ = !insert_mode_; } | 165 void toggle_insert_mode() { insert_mode_ = !insert_mode_; } |
| 166 | 166 |
| 167 bool focused() const { return focused_; } | 167 bool focused() const { return focused_; } |
| 168 void set_focused(bool focused) { focused_ = focused; } | 168 void set_focused(bool focused) { focused_ = focused; } |
| 169 | 169 |
| 170 const StyleRange& default_style() const { return default_style_; } | 170 const StyleRange& default_style() const { return default_style_; } |
| 171 void set_default_style(StyleRange style) { default_style_ = style; } | 171 void set_default_style(StyleRange style) { default_style_ = style; } |
| 172 | 172 |
| 173 const Rect& display_rect() const { return display_rect_; } | 173 const Rect& display_rect() const { return display_rect_; } |
| 174 virtual void set_display_rect(const Rect& r); | 174 virtual void SetDisplayRect(const Rect& r); |
| 175 | |
| 176 const Point& display_offset() const { return display_offset_; } | |
| 177 | 175 |
| 178 // This cursor position corresponds to SelectionModel::selection_end. In | 176 // This cursor position corresponds to SelectionModel::selection_end. In |
| 179 // addition to representing the selection end, it's also where logical text | 177 // addition to representing the selection end, it's also where logical text |
| 180 // edits take place, and doesn't necessarily correspond to | 178 // edits take place, and doesn't necessarily correspond to |
| 181 // SelectionModel::caret_pos. | 179 // SelectionModel::caret_pos. |
| 182 size_t GetCursorPosition() const; | 180 size_t GetCursorPosition() const; |
| 183 void SetCursorPosition(const size_t position); | 181 void SetCursorPosition(const size_t position); |
| 184 | 182 |
| 185 void SetCaretPlacement(SelectionModel::CaretPlacement placement) { | 183 void SetCaretPlacement(SelectionModel::CaretPlacement placement) { |
| 186 selection_model_.set_caret_placement(placement); | 184 selection_model_.set_caret_placement(placement); |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 235 // Get the width of the entire string. | 233 // Get the width of the entire string. |
| 236 virtual int GetStringWidth(); | 234 virtual int GetStringWidth(); |
| 237 | 235 |
| 238 virtual void Draw(Canvas* canvas); | 236 virtual void Draw(Canvas* canvas); |
| 239 | 237 |
| 240 // Gets the SelectionModel from a visual point in local coordinates. | 238 // Gets the SelectionModel from a visual point in local coordinates. |
| 241 virtual SelectionModel FindCursorPosition(const Point& point); | 239 virtual SelectionModel FindCursorPosition(const Point& point); |
| 242 | 240 |
| 243 // Get the visual bounds containing the logical substring within |from| to | 241 // Get the visual bounds containing the logical substring within |from| to |
| 244 // |to|. These bounds could be visually discontinuous if the logical | 242 // |to|. These bounds could be visually discontinuous if the logical |
| 245 // selection range is split by an odd number of LTR/RTL level change. | 243 // selection range is split by an odd number of LTR/RTL level change. These |
| 244 // bounds are offset by the text's display rect and display offset. |
| 246 virtual std::vector<Rect> GetSubstringBounds( | 245 virtual std::vector<Rect> GetSubstringBounds( |
| 247 size_t from, size_t to) const; | 246 size_t from, size_t to); |
| 248 | 247 |
| 249 // Get the visual bounds describing the cursor at |selection|. These bounds | 248 // Get the visual bounds describing the cursor at |selection|. These bounds |
| 250 // typically represent a vertical line, but if |insert_mode| is true they | 249 // typically represent a vertical line, but if |insert_mode| is true they |
| 251 // contain the bounds of the associated glyph. | 250 // contain the bounds of the associated glyph. These bounds are offset by the |
| 251 // text's display rect and display offset. |
| 252 virtual Rect GetCursorBounds(const SelectionModel& selection, | 252 virtual Rect GetCursorBounds(const SelectionModel& selection, |
| 253 bool insert_mode); | 253 bool insert_mode); |
| 254 | 254 |
| 255 // Compute cursor_bounds_ and update display_offset_ when necessary. Cache | 255 // Get the current cursor bounds, updating the cached rect if necessary. These |
| 256 // the values for later use and return cursor_bounds_. | 256 // bounds are offset by the text's display rect and display offset. |
| 257 const Rect& CursorBounds(); | 257 const Rect& GetUpdatedCursorBounds(); |
| 258 | 258 |
| 259 protected: | 259 protected: |
| 260 RenderText(); | 260 RenderText(); |
| 261 | 261 |
| 262 void set_cursor_bounds_valid(bool valid) { cursor_bounds_valid_ = valid; } | 262 const Point& GetUpdatedDisplayOffset(); |
| 263 |
| 264 void set_cached_bounds_and_offset_valid(bool valid) { |
| 265 cached_bounds_and_offset_valid_ = valid; |
| 266 } |
| 263 | 267 |
| 264 const StyleRanges& style_ranges() const { return style_ranges_; } | 268 const StyleRanges& style_ranges() const { return style_ranges_; } |
| 265 | 269 |
| 266 // Get the selection model that visually neighbors |position| by |break_type|. | 270 // Get the selection model that visually neighbors |position| by |break_type|. |
| 267 // The returned value represents a cursor/caret position without a selection. | 271 // The returned value represents a cursor/caret position without a selection. |
| 268 virtual SelectionModel GetLeftSelectionModel(const SelectionModel& current, | 272 virtual SelectionModel GetLeftSelectionModel(const SelectionModel& current, |
| 269 BreakType break_type); | 273 BreakType break_type); |
| 270 virtual SelectionModel GetRightSelectionModel(const SelectionModel& current, | 274 virtual SelectionModel GetRightSelectionModel(const SelectionModel& current, |
| 271 BreakType break_type); | 275 BreakType break_type); |
| 272 | 276 |
| (...skipping 10 matching lines...) Expand all Loading... |
| 283 FRIEND_TEST_ALL_PREFIXES(RenderTextTest, DefaultStyle); | 287 FRIEND_TEST_ALL_PREFIXES(RenderTextTest, DefaultStyle); |
| 284 FRIEND_TEST_ALL_PREFIXES(RenderTextTest, CustomDefaultStyle); | 288 FRIEND_TEST_ALL_PREFIXES(RenderTextTest, CustomDefaultStyle); |
| 285 FRIEND_TEST_ALL_PREFIXES(RenderTextTest, ApplyStyleRange); | 289 FRIEND_TEST_ALL_PREFIXES(RenderTextTest, ApplyStyleRange); |
| 286 FRIEND_TEST_ALL_PREFIXES(RenderTextTest, StyleRangesAdjust); | 290 FRIEND_TEST_ALL_PREFIXES(RenderTextTest, StyleRangesAdjust); |
| 287 | 291 |
| 288 // Clear out |style_ranges_|. | 292 // Clear out |style_ranges_|. |
| 289 void ClearStyleRanges(); | 293 void ClearStyleRanges(); |
| 290 | 294 |
| 291 bool IsPositionAtWordSelectionBoundary(size_t pos); | 295 bool IsPositionAtWordSelectionBoundary(size_t pos); |
| 292 | 296 |
| 293 void UpdateCursorBoundsAndDisplayOffset(); | 297 // Update the cached bounds and display offset to ensure that the current |
| 298 // cursor is within the visible display area. |
| 299 void UpdateCachedBoundsAndOffset(); |
| 294 | 300 |
| 295 // Logical UTF-16 string data to be drawn. | 301 // Logical UTF-16 string data to be drawn. |
| 296 string16 text_; | 302 string16 text_; |
| 297 | 303 |
| 298 // Logical selection range and visual cursor position. | 304 // Logical selection range and visual cursor position. |
| 299 SelectionModel selection_model_; | 305 SelectionModel selection_model_; |
| 300 | 306 |
| 301 // The cached cursor bounds. | 307 // The cached cursor bounds; get these bounds with GetUpdatedCursorBounds. |
| 302 Rect cursor_bounds_; | 308 Rect cursor_bounds_; |
| 303 // cursor_bounds_ is computed when needed and cached afterwards. And it is | |
| 304 // invalidated in operations such as SetCursorPosition, SetSelection, Font | |
| 305 // related style change, and other operations that trigger re-layout. | |
| 306 bool cursor_bounds_valid_; | |
| 307 | 309 |
| 308 // The cursor visibility and insert mode. | 310 // The cursor visibility and insert mode. |
| 309 bool cursor_visible_; | 311 bool cursor_visible_; |
| 310 bool insert_mode_; | 312 bool insert_mode_; |
| 311 | 313 |
| 312 // The focus state of the text. | 314 // The focus state of the text. |
| 313 bool focused_; | 315 bool focused_; |
| 314 | 316 |
| 315 // Composition text range. | 317 // Composition text range. |
| 316 ui::Range composition_range_; | 318 ui::Range composition_range_; |
| 317 | 319 |
| 318 // List of style ranges. Elements in the list never overlap each other. | 320 // List of style ranges. Elements in the list never overlap each other. |
| 319 StyleRanges style_ranges_; | 321 StyleRanges style_ranges_; |
| 320 // The default text style. | 322 // The default text style. |
| 321 StyleRange default_style_; | 323 StyleRange default_style_; |
| 322 | 324 |
| 323 // The local display area for rendering the text. | 325 // The local display area for rendering the text. |
| 324 Rect display_rect_; | 326 Rect display_rect_; |
| 325 // The offset for the text to be drawn, relative to the display area. | 327 // The offset for the text to be drawn, relative to the display area. |
| 328 // Get this point with GetUpdatedDisplayOffset (or risk using a stale value). |
| 326 Point display_offset_; | 329 Point display_offset_; |
| 327 | 330 |
| 331 // The cached bounds and offset are invalidated by operations such as |
| 332 // SetCursorPosition, SetSelection, Font related style change, and other |
| 333 // operations that adjust the visible text bounds. |
| 334 bool cached_bounds_and_offset_valid_; |
| 335 |
| 328 DISALLOW_COPY_AND_ASSIGN(RenderText); | 336 DISALLOW_COPY_AND_ASSIGN(RenderText); |
| 329 }; | 337 }; |
| 330 | 338 |
| 331 } // namespace gfx | 339 } // namespace gfx |
| 332 | 340 |
| 333 #endif // UI_GFX_RENDER_TEXT_H_ | 341 #endif // UI_GFX_RENDER_TEXT_H_ |
| OLD | NEW |