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

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

Issue 7458014: Implement Uniscribe RenderText for Windows. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Add Skia drawPosText support. Created 9 years, 3 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
« no previous file with comments | « no previous file | ui/gfx/render_text.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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_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 136 matching lines...) Expand 10 before | Expand all | Expand 10 after
147 public: 147 public:
148 virtual ~RenderText(); 148 virtual ~RenderText();
149 149
150 // Creates a platform-specific RenderText instance. 150 // Creates a platform-specific RenderText instance.
151 static RenderText* CreateRenderText(); 151 static RenderText* CreateRenderText();
152 152
153 const string16& text() const { return text_; } 153 const string16& text() const { return text_; }
154 virtual void SetText(const string16& text); 154 virtual void SetText(const string16& text);
155 155
156 const SelectionModel& selection_model() const { return selection_model_; } 156 const SelectionModel& selection_model() const { return selection_model_; }
157 void SetSelectionModel(const SelectionModel& sel);
158 157
159 bool cursor_visible() const { return cursor_visible_; } 158 bool cursor_visible() const { return cursor_visible_; }
160 void set_cursor_visible(bool visible) { cursor_visible_ = visible; } 159 void set_cursor_visible(bool visible) { cursor_visible_ = visible; }
161 160
162 bool insert_mode() const { return insert_mode_; } 161 bool insert_mode() const { return insert_mode_; }
163 void toggle_insert_mode() { insert_mode_ = !insert_mode_; } 162 void ToggleInsertMode();
164 163
165 bool focused() const { return focused_; } 164 bool focused() const { return focused_; }
166 void set_focused(bool focused) { focused_ = focused; } 165 void set_focused(bool focused) { focused_ = focused; }
167 166
168 const StyleRange& default_style() const { return default_style_; } 167 const StyleRange& default_style() const { return default_style_; }
169 void set_default_style(StyleRange style) { default_style_ = style; } 168 void set_default_style(StyleRange style) { default_style_ = style; }
170 169
171 const Rect& display_rect() const { return display_rect_; } 170 const Rect& display_rect() const { return display_rect_; }
172 virtual void SetDisplayRect(const Rect& r); 171 virtual void SetDisplayRect(const Rect& r);
173 172
174 // This cursor position corresponds to SelectionModel::selection_end. In 173 // This cursor position corresponds to SelectionModel::selection_end. In
175 // addition to representing the selection end, it's also where logical text 174 // addition to representing the selection end, it's also where logical text
176 // edits take place, and doesn't necessarily correspond to 175 // edits take place, and doesn't necessarily correspond to
177 // SelectionModel::caret_pos. 176 // SelectionModel::caret_pos.
178 size_t GetCursorPosition() const; 177 size_t GetCursorPosition() const;
179 void SetCursorPosition(const size_t position); 178 void SetCursorPosition(size_t position);
180 179
181 void SetCaretPlacement(SelectionModel::CaretPlacement placement) { 180 void SetCaretPlacement(SelectionModel::CaretPlacement placement) {
182 selection_model_.set_caret_placement(placement); 181 selection_model_.set_caret_placement(placement);
183 } 182 }
184 183
185 // Moves the cursor left or right. Cursor movement is visual, meaning that 184 // Moves the cursor left or right. Cursor movement is visual, meaning that
186 // left and right are relative to screen, not the directionality of the text. 185 // left and right are relative to screen, not the directionality of the text.
187 // If |select| is false, the selection range is emptied at the new position. 186 // If |select| is false, the selection start is moved to the same position.
188 void MoveCursorLeft(BreakType break_type, bool select); 187 void MoveCursorLeft(BreakType break_type, bool select);
189 void MoveCursorRight(BreakType break_type, bool select); 188 void MoveCursorRight(BreakType break_type, bool select);
190 189
191 // Set the selection_model_ to the value of |selection|. 190 // Set the selection_model_ to the value of |selection|.
191 // The selection model components are modified if invalid.
192 // Returns true if the cursor position or selection range changed. 192 // Returns true if the cursor position or selection range changed.
193 bool MoveCursorTo(const SelectionModel& selection); 193 bool MoveCursorTo(const SelectionModel& selection_model);
194 194
195 // Move the cursor to the position associated with the clicked point. 195 // Move the cursor to the position associated with the clicked point.
196 // If |select| is false, the selection range is emptied at the new position. 196 // If |select| is false, the selection start is moved to the same position.
197 // Returns true if the cursor position or selection range changed.
197 bool MoveCursorTo(const Point& point, bool select); 198 bool MoveCursorTo(const Point& point, bool select);
198 199
199 size_t GetSelectionStart() const { 200 size_t GetSelectionStart() const {
200 return selection_model_.selection_start(); 201 return selection_model_.selection_start();
201 } 202 }
202 size_t MinOfSelection() const { 203 size_t MinOfSelection() const {
203 return std::min(GetSelectionStart(), GetCursorPosition()); 204 return std::min(GetSelectionStart(), GetCursorPosition());
204 } 205 }
205 size_t MaxOfSelection() const { 206 size_t MaxOfSelection() const {
206 return std::max(GetSelectionStart(), GetCursorPosition()); 207 return std::max(GetSelectionStart(), GetCursorPosition());
(...skipping 22 matching lines...) Expand all
229 base::i18n::TextDirection GetTextDirection() const; 230 base::i18n::TextDirection GetTextDirection() const;
230 231
231 // Get the width of the entire string. 232 // Get the width of the entire string.
232 virtual int GetStringWidth(); 233 virtual int GetStringWidth();
233 234
234 virtual void Draw(Canvas* canvas); 235 virtual void Draw(Canvas* canvas);
235 236
236 // Gets the SelectionModel from a visual point in local coordinates. 237 // Gets the SelectionModel from a visual point in local coordinates.
237 virtual SelectionModel FindCursorPosition(const Point& point); 238 virtual SelectionModel FindCursorPosition(const Point& point);
238 239
239 // Get the visual bounds containing the logical substring within |from| to
240 // |to|. These bounds could be visually discontinuous if the substring is
241 // split by a LTR/RTL level change. These bounds are in local coordinates, but
242 // may be outside the visible region if the text is longer than the textfield.
243 // Subsequent text, cursor, or bounds changes may invalidate returned values.
244 virtual std::vector<Rect> GetSubstringBounds(size_t from, size_t to);
245
246 // Get the visual bounds of a cursor at |selection|. These bounds typically 240 // Get the visual bounds of a cursor at |selection|. These bounds typically
247 // represent a vertical line, but if |insert_mode| is true they contain the 241 // represent a vertical line, but if |insert_mode| is true they contain the
248 // bounds of the associated glyph. These bounds are in local coordinates, but 242 // bounds of the associated glyph. These bounds are in local coordinates, but
249 // may be outside the visible region if the text is longer than the textfield. 243 // may be outside the visible region if the text is longer than the textfield.
250 // Subsequent text, cursor, or bounds changes may invalidate returned values. 244 // Subsequent text, cursor, or bounds changes may invalidate returned values.
251 virtual Rect GetCursorBounds(const SelectionModel& selection, 245 virtual Rect GetCursorBounds(const SelectionModel& selection,
252 bool insert_mode); 246 bool insert_mode);
253 247
254 // Compute the current cursor bounds, panning the text to show the cursor in 248 // Compute the current cursor bounds, panning the text to show the cursor in
255 // the display rect if necessary. These bounds are in local coordinates. 249 // the display rect if necessary. These bounds are in local coordinates.
(...skipping 11 matching lines...) Expand all
267 261
268 const StyleRanges& style_ranges() const { return style_ranges_; } 262 const StyleRanges& style_ranges() const { return style_ranges_; }
269 263
270 // Get the selection model that visually neighbors |position| by |break_type|. 264 // Get the selection model that visually neighbors |position| by |break_type|.
271 // The returned value represents a cursor/caret position without a selection. 265 // The returned value represents a cursor/caret position without a selection.
272 virtual SelectionModel GetLeftSelectionModel(const SelectionModel& current, 266 virtual SelectionModel GetLeftSelectionModel(const SelectionModel& current,
273 BreakType break_type); 267 BreakType break_type);
274 virtual SelectionModel GetRightSelectionModel(const SelectionModel& current, 268 virtual SelectionModel GetRightSelectionModel(const SelectionModel& current,
275 BreakType break_type); 269 BreakType break_type);
276 270
271 // Get the SelectionModels corresponding to visual text ends.
272 // The returned value represents a cursor/caret position without a selection.
273 virtual SelectionModel LeftEndSelectionModel();
274 virtual SelectionModel RightEndSelectionModel();
275
277 // Get the logical index of the grapheme preceeding the argument |position|. 276 // Get the logical index of the grapheme preceeding the argument |position|.
278 virtual size_t GetIndexOfPreviousGrapheme(size_t position); 277 virtual size_t GetIndexOfPreviousGrapheme(size_t position);
279 278
279 // Get the visual bounds containing the logical substring within |from| to
280 // |to|. These bounds could be visually discontinuous if the substring is
281 // split by a LTR/RTL level change. These bounds are in local coordinates, but
282 // may be outside the visible region if the text is longer than the textfield.
283 // Subsequent text, cursor, or bounds changes may invalidate returned values.
284 // TODO(msw) Re-evaluate this function's necessity and signature.
285 virtual std::vector<Rect> GetSubstringBounds(size_t from, size_t to);
286
280 // Apply composition style (underline) to composition range and selection 287 // Apply composition style (underline) to composition range and selection
281 // style (foreground) to selection range. 288 // style (foreground) to selection range.
282 void ApplyCompositionAndSelectionStyles(StyleRanges* style_ranges) const; 289 void ApplyCompositionAndSelectionStyles(StyleRanges* style_ranges) const;
283 290
291 // Convert points from the text space to the view space and back.
292 // Handles the display area, display offset, and the application LTR/RTL mode.
293 Point ToTextPoint(const Point& point);
294 Point ToViewPoint(const Point& point);
295
284 private: 296 private:
285 friend class RenderTextTest; 297 friend class RenderTextTest;
286 298
287 FRIEND_TEST_ALL_PREFIXES(RenderTextTest, DefaultStyle); 299 FRIEND_TEST_ALL_PREFIXES(RenderTextTest, DefaultStyle);
288 FRIEND_TEST_ALL_PREFIXES(RenderTextTest, CustomDefaultStyle); 300 FRIEND_TEST_ALL_PREFIXES(RenderTextTest, CustomDefaultStyle);
289 FRIEND_TEST_ALL_PREFIXES(RenderTextTest, ApplyStyleRange); 301 FRIEND_TEST_ALL_PREFIXES(RenderTextTest, ApplyStyleRange);
290 FRIEND_TEST_ALL_PREFIXES(RenderTextTest, StyleRangesAdjust); 302 FRIEND_TEST_ALL_PREFIXES(RenderTextTest, StyleRangesAdjust);
291 303
292 // Clear out |style_ranges_|. 304 // Sets the selection model, the argument is assumed to be valid.
293 void ClearStyleRanges(); 305 void SetSelectionModel(const SelectionModel& selection_model);
306
307 // Set the cursor to |position|, with the caret trailing the previous
308 // grapheme, or if there is no previous grapheme, leading the cursor position.
309 // If |select| is false, the selection start is moved to the same position.
310 void MoveCursorTo(size_t position, bool select);
294 311
295 bool IsPositionAtWordSelectionBoundary(size_t pos); 312 bool IsPositionAtWordSelectionBoundary(size_t pos);
296 313
297 // Update the cached bounds and display offset to ensure that the current 314 // Update the cached bounds and display offset to ensure that the current
298 // cursor is within the visible display area. 315 // cursor is within the visible display area.
299 void UpdateCachedBoundsAndOffset(); 316 void UpdateCachedBoundsAndOffset();
300 317
301 // Logical UTF-16 string data to be drawn. 318 // Logical UTF-16 string data to be drawn.
302 string16 text_; 319 string16 text_;
303 320
(...skipping 17 matching lines...) Expand all
321 StyleRanges style_ranges_; 338 StyleRanges style_ranges_;
322 // The default text style. 339 // The default text style.
323 StyleRange default_style_; 340 StyleRange default_style_;
324 341
325 // The local display area for rendering the text. 342 // The local display area for rendering the text.
326 Rect display_rect_; 343 Rect display_rect_;
327 // The offset for the text to be drawn, relative to the display area. 344 // 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). 345 // Get this point with GetUpdatedDisplayOffset (or risk using a stale value).
329 Point display_offset_; 346 Point display_offset_;
330 347
331 // The cached bounds and offset are invalidated by operations such as 348 // The cached bounds and offset are invalidated by changes to the cursor,
332 // SetCursorPosition, SetSelectionModel, Font related style change, and other 349 // selection, font, and other operations that adjust the visible text bounds.
333 // operations that adjust the visible text bounds.
334 bool cached_bounds_and_offset_valid_; 350 bool cached_bounds_and_offset_valid_;
335 351
336 DISALLOW_COPY_AND_ASSIGN(RenderText); 352 DISALLOW_COPY_AND_ASSIGN(RenderText);
337 }; 353 };
338 354
339 } // namespace gfx 355 } // namespace gfx
340 356
341 #endif // UI_GFX_RENDER_TEXT_H_ 357 #endif // UI_GFX_RENDER_TEXT_H_
OLDNEW
« no previous file with comments | « no previous file | ui/gfx/render_text.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698