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

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

Issue 354963003: Move gfx::ElideText functionality to RenderText. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: sync and rebase. Created 6 years, 5 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 | « chrome/browser/ui/views/omnibox/omnibox_result_view.cc ('k') | 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) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 7
8 #include <algorithm> 8 #include <algorithm>
9 #include <cstring> 9 #include <cstring>
10 #include <string> 10 #include <string>
(...skipping 11 matching lines...) Expand all
22 #include "ui/gfx/break_list.h" 22 #include "ui/gfx/break_list.h"
23 #include "ui/gfx/font_list.h" 23 #include "ui/gfx/font_list.h"
24 #include "ui/gfx/font_render_params.h" 24 #include "ui/gfx/font_render_params.h"
25 #include "ui/gfx/point.h" 25 #include "ui/gfx/point.h"
26 #include "ui/gfx/range/range.h" 26 #include "ui/gfx/range/range.h"
27 #include "ui/gfx/rect.h" 27 #include "ui/gfx/rect.h"
28 #include "ui/gfx/selection_model.h" 28 #include "ui/gfx/selection_model.h"
29 #include "ui/gfx/shadow_value.h" 29 #include "ui/gfx/shadow_value.h"
30 #include "ui/gfx/size_f.h" 30 #include "ui/gfx/size_f.h"
31 #include "ui/gfx/text_constants.h" 31 #include "ui/gfx/text_constants.h"
32 #include "ui/gfx/text_elider.h"
33 #include "ui/gfx/vector2d.h" 32 #include "ui/gfx/vector2d.h"
34 33
35 class SkCanvas; 34 class SkCanvas;
36 class SkDrawLooper; 35 class SkDrawLooper;
37 struct SkPoint; 36 struct SkPoint;
38 class SkShader; 37 class SkShader;
39 class SkTypeface; 38 class SkTypeface;
40 39
41 namespace gfx { 40 namespace gfx {
42 41
(...skipping 204 matching lines...) Expand 10 before | Expand all | Expand 10 after
247 // Windows. Support other platforms. 246 // Windows. Support other platforms.
248 bool multiline() const { return multiline_; } 247 bool multiline() const { return multiline_; }
249 void SetMultiline(bool multiline); 248 void SetMultiline(bool multiline);
250 249
251 // Set the maximum length of the displayed layout text, not the actual text. 250 // Set the maximum length of the displayed layout text, not the actual text.
252 // A |length| of 0 forgoes a hard limit, but does not guarantee proper 251 // A |length| of 0 forgoes a hard limit, but does not guarantee proper
253 // functionality of very long strings. Applies to subsequent SetText calls. 252 // functionality of very long strings. Applies to subsequent SetText calls.
254 // WARNING: Only use this for system limits, it lacks complex text support. 253 // WARNING: Only use this for system limits, it lacks complex text support.
255 void set_truncate_length(size_t length) { truncate_length_ = length; } 254 void set_truncate_length(size_t length) { truncate_length_ = length; }
256 255
257 // Elides the text to fit in |display_rect| according to the specified 256 // The layout text will be elided to fit |display_rect| using this behavior.
258 // |elide_behavior|. |ELIDE_MIDDLE| is not supported. If a truncate length and 257 // The layout text may be shortened further by the truncate length.
259 // an elide mode are specified, the shorter of the two will be applicable.
260 void SetElideBehavior(ElideBehavior elide_behavior); 258 void SetElideBehavior(ElideBehavior elide_behavior);
261 259
260 const base::string16& layout_text() const { return layout_text_; }
261
262 const Rect& display_rect() const { return display_rect_; } 262 const Rect& display_rect() const { return display_rect_; }
263 void SetDisplayRect(const Rect& r); 263 void SetDisplayRect(const Rect& r);
264 264
265 bool background_is_transparent() const { return background_is_transparent_; } 265 bool background_is_transparent() const { return background_is_transparent_; }
266 void set_background_is_transparent(bool transparent) { 266 void set_background_is_transparent(bool transparent) {
267 background_is_transparent_ = transparent; 267 background_is_transparent_ = transparent;
268 } 268 }
269 269
270 const SelectionModel& selection_model() const { return selection_model_; } 270 const SelectionModel& selection_model() const { return selection_model_; }
271 271
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after
348 348
349 // This is same as GetStringSize except that fractional size is returned. 349 // This is same as GetStringSize except that fractional size is returned.
350 // The default implementation is same as GetStringSize. Certain platforms that 350 // The default implementation is same as GetStringSize. Certain platforms that
351 // compute the text size as floating-point values, like Mac, will override 351 // compute the text size as floating-point values, like Mac, will override
352 // this method. 352 // this method.
353 // See comment in Canvas::GetStringWidthF for its usage. 353 // See comment in Canvas::GetStringWidthF for its usage.
354 virtual SizeF GetStringSizeF(); 354 virtual SizeF GetStringSizeF();
355 355
356 // Returns the width of the content (which is the wrapped width in multiline 356 // Returns the width of the content (which is the wrapped width in multiline
357 // mode). Reserves room for the cursor if |cursor_enabled_| is true. 357 // mode). Reserves room for the cursor if |cursor_enabled_| is true.
358 int GetContentWidth(); 358 float GetContentWidth();
359 359
360 // Returns the common baseline of the text. The return value is the vertical 360 // Returns the common baseline of the text. The return value is the vertical
361 // offset from the top of |display_rect_| to the text baseline, in pixels. 361 // offset from the top of |display_rect_| to the text baseline, in pixels.
362 // The baseline is determined from the font list and display rect, and does 362 // The baseline is determined from the font list and display rect, and does
363 // not depend on the text. 363 // not depend on the text.
364 int GetBaseline(); 364 int GetBaseline();
365 365
366 void Draw(Canvas* canvas); 366 void Draw(Canvas* canvas);
367 367
368 // Draws a cursor at |position|. 368 // Draws a cursor at |position|.
(...skipping 205 matching lines...) Expand 10 before | Expand all | Expand 10 after
574 // Set the cursor to |position|, with the caret trailing the previous 574 // Set the cursor to |position|, with the caret trailing the previous
575 // grapheme, or if there is no previous grapheme, leading the cursor position. 575 // grapheme, or if there is no previous grapheme, leading the cursor position.
576 // If |select| is false, the selection start is moved to the same position. 576 // If |select| is false, the selection start is moved to the same position.
577 // If the |position| is not a cursorable position (not on grapheme boundary), 577 // If the |position| is not a cursorable position (not on grapheme boundary),
578 // it is a NO-OP. 578 // it is a NO-OP.
579 void MoveCursorTo(size_t position, bool select); 579 void MoveCursorTo(size_t position, bool select);
580 580
581 // Updates |layout_text_| if the text is obscured or truncated. 581 // Updates |layout_text_| if the text is obscured or truncated.
582 void UpdateLayoutText(); 582 void UpdateLayoutText();
583 583
584 // Elides |text| to fit in the |display_rect_| with given |elide_behavior_|. 584 // Elides |text| as needed to fit in the |available_width| using |behavior|.
585 // See ElideText in ui/gfx/text_elider.cc for reference. 585 base::string16 Elide(const base::string16& text,
586 base::string16 ElideText(const base::string16& text); 586 float available_width,
587 ElideBehavior behavior);
588
589 // Elides |email| as needed to fit the |available_width|.
590 base::string16 ElideEmail(const base::string16& email, float available_width);
587 591
588 // Update the cached bounds and display offset to ensure that the current 592 // Update the cached bounds and display offset to ensure that the current
589 // cursor is within the visible display area. 593 // cursor is within the visible display area.
590 void UpdateCachedBoundsAndOffset(); 594 void UpdateCachedBoundsAndOffset();
591 595
592 // Draw the selection. 596 // Draw the selection.
593 void DrawSelection(Canvas* canvas); 597 void DrawSelection(Canvas* canvas);
594 598
595 // Logical UTF-16 string data to be drawn. 599 // Logical UTF-16 string data to be drawn.
596 base::string16 text_; 600 base::string16 text_;
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after
701 // Lines computed by EnsureLayout. These should be invalidated with 705 // Lines computed by EnsureLayout. These should be invalidated with
702 // ResetLayout and on |display_rect_| changes. 706 // ResetLayout and on |display_rect_| changes.
703 std::vector<internal::Line> lines_; 707 std::vector<internal::Line> lines_;
704 708
705 DISALLOW_COPY_AND_ASSIGN(RenderText); 709 DISALLOW_COPY_AND_ASSIGN(RenderText);
706 }; 710 };
707 711
708 } // namespace gfx 712 } // namespace gfx
709 713
710 #endif // UI_GFX_RENDER_TEXT_H_ 714 #endif // UI_GFX_RENDER_TEXT_H_
OLDNEW
« no previous file with comments | « chrome/browser/ui/views/omnibox/omnibox_result_view.cc ('k') | ui/gfx/render_text.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698