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

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: Reorder RenderText::Elide impl to match decl. 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 | « 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) 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 10 matching lines...) Expand all
21 #include "third_party/skia/include/core/SkRect.h" 21 #include "third_party/skia/include/core/SkRect.h"
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/point.h" 24 #include "ui/gfx/point.h"
25 #include "ui/gfx/range/range.h" 25 #include "ui/gfx/range/range.h"
26 #include "ui/gfx/rect.h" 26 #include "ui/gfx/rect.h"
27 #include "ui/gfx/selection_model.h" 27 #include "ui/gfx/selection_model.h"
28 #include "ui/gfx/shadow_value.h" 28 #include "ui/gfx/shadow_value.h"
29 #include "ui/gfx/size_f.h" 29 #include "ui/gfx/size_f.h"
30 #include "ui/gfx/text_constants.h" 30 #include "ui/gfx/text_constants.h"
31 #include "ui/gfx/text_elider.h"
32 #include "ui/gfx/vector2d.h" 31 #include "ui/gfx/vector2d.h"
33 32
34 class SkCanvas; 33 class SkCanvas;
35 class SkDrawLooper; 34 class SkDrawLooper;
36 struct SkPoint; 35 struct SkPoint;
37 class SkShader; 36 class SkShader;
38 class SkTypeface; 37 class SkTypeface;
39 38
40 namespace gfx { 39 namespace gfx {
41 40
(...skipping 206 matching lines...) Expand 10 before | Expand all | Expand 10 after
248 // Windows. Support other platforms. 247 // Windows. Support other platforms.
249 bool multiline() const { return multiline_; } 248 bool multiline() const { return multiline_; }
250 void SetMultiline(bool multiline); 249 void SetMultiline(bool multiline);
251 250
252 // Set the maximum length of the displayed layout text, not the actual text. 251 // Set the maximum length of the displayed layout text, not the actual text.
253 // A |length| of 0 forgoes a hard limit, but does not guarantee proper 252 // A |length| of 0 forgoes a hard limit, but does not guarantee proper
254 // functionality of very long strings. Applies to subsequent SetText calls. 253 // functionality of very long strings. Applies to subsequent SetText calls.
255 // WARNING: Only use this for system limits, it lacks complex text support. 254 // WARNING: Only use this for system limits, it lacks complex text support.
256 void set_truncate_length(size_t length) { truncate_length_ = length; } 255 void set_truncate_length(size_t length) { truncate_length_ = length; }
257 256
258 // Elides the text to fit in |display_rect| according to the specified 257 // The layout text will be elided to fit |display_rect| using this behavior.
259 // |elide_behavior|. |ELIDE_MIDDLE| is not supported. If a truncate length and 258 // The layout text may be shortened further by the truncate length.
260 // an elide mode are specified, the shorter of the two will be applicable.
261 void SetElideBehavior(ElideBehavior elide_behavior); 259 void SetElideBehavior(ElideBehavior elide_behavior);
262 260
263 const Rect& display_rect() const { return display_rect_; } 261 const Rect& display_rect() const { return display_rect_; }
264 void SetDisplayRect(const Rect& r); 262 void SetDisplayRect(const Rect& r);
265 263
266 bool background_is_transparent() const { return background_is_transparent_; } 264 bool background_is_transparent() const { return background_is_transparent_; }
267 void set_background_is_transparent(bool transparent) { 265 void set_background_is_transparent(bool transparent) {
268 background_is_transparent_ = transparent; 266 background_is_transparent_ = transparent;
269 } 267 }
270 268
(...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after
415 // specifies the character range for which the corresponding font has been 413 // specifies the character range for which the corresponding font has been
416 // chosen. 414 // chosen.
417 virtual std::vector<FontSpan> GetFontSpansForTesting() = 0; 415 virtual std::vector<FontSpan> GetFontSpansForTesting() = 0;
418 416
419 // Gets the horizontal bounds (relative to the left of the text, not the view) 417 // Gets the horizontal bounds (relative to the left of the text, not the view)
420 // of the glyph starting at |index|. If the glyph is RTL then the returned 418 // of the glyph starting at |index|. If the glyph is RTL then the returned
421 // Range will have is_reversed() true. (This does not return a Rect because a 419 // Range will have is_reversed() true. (This does not return a Rect because a
422 // Rect can't have a negative width.) 420 // Rect can't have a negative width.)
423 virtual Range GetGlyphBounds(size_t index) = 0; 421 virtual Range GetGlyphBounds(size_t index) = 0;
424 422
423 // Elides |text| as needed to fit in the |available_width| using |behavior|.
424 base::string16 Elide(const base::string16& text,
Alexei Svitkine (slow) 2014/06/27 21:54:33 It seems more natural to me to be able to set Elid
msw 2014/06/27 23:51:49 Done; this required disambiguating a new ElideBeha
425 float available_width,
426 ElideBehavior behavior);
427
425 protected: 428 protected:
426 RenderText(); 429 RenderText();
427 430
428 const BreakList<SkColor>& colors() const { return colors_; } 431 const BreakList<SkColor>& colors() const { return colors_; }
429 const std::vector<BreakList<bool> >& styles() const { return styles_; } 432 const std::vector<BreakList<bool> >& styles() const { return styles_; }
430 433
431 const std::vector<internal::Line>& lines() const { return lines_; } 434 const std::vector<internal::Line>& lines() const { return lines_; }
432 void set_lines(std::vector<internal::Line>* lines) { lines_.swap(*lines); } 435 void set_lines(std::vector<internal::Line>* lines) { lines_.swap(*lines); }
433 436
434 // Returns the baseline of the current text. The return value depends on 437 // Returns the baseline of the current text. The return value depends on
(...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after
574 // Set the cursor to |position|, with the caret trailing the previous 577 // Set the cursor to |position|, with the caret trailing the previous
575 // grapheme, or if there is no previous grapheme, leading the cursor position. 578 // 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. 579 // 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), 580 // If the |position| is not a cursorable position (not on grapheme boundary),
578 // it is a NO-OP. 581 // it is a NO-OP.
579 void MoveCursorTo(size_t position, bool select); 582 void MoveCursorTo(size_t position, bool select);
580 583
581 // Updates |layout_text_| if the text is obscured or truncated. 584 // Updates |layout_text_| if the text is obscured or truncated.
582 void UpdateLayoutText(); 585 void UpdateLayoutText();
583 586
584 // Elides |text| to fit in the |display_rect_| with given |elide_behavior_|. 587 // Elides |email| as needed to fit the |available_width|.
585 // See ElideText in ui/gfx/text_elider.cc for reference. 588 base::string16 ElideEmail(const base::string16& email, float available_width);
586 base::string16 ElideText(const base::string16& text);
587 589
588 // Update the cached bounds and display offset to ensure that the current 590 // Update the cached bounds and display offset to ensure that the current
589 // cursor is within the visible display area. 591 // cursor is within the visible display area.
590 void UpdateCachedBoundsAndOffset(); 592 void UpdateCachedBoundsAndOffset();
591 593
592 // Draw the selection. 594 // Draw the selection.
593 void DrawSelection(Canvas* canvas); 595 void DrawSelection(Canvas* canvas);
594 596
595 // Logical UTF-16 string data to be drawn. 597 // Logical UTF-16 string data to be drawn.
596 base::string16 text_; 598 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 703 // Lines computed by EnsureLayout. These should be invalidated with
702 // ResetLayout and on |display_rect_| changes. 704 // ResetLayout and on |display_rect_| changes.
703 std::vector<internal::Line> lines_; 705 std::vector<internal::Line> lines_;
704 706
705 DISALLOW_COPY_AND_ASSIGN(RenderText); 707 DISALLOW_COPY_AND_ASSIGN(RenderText);
706 }; 708 };
707 709
708 } // namespace gfx 710 } // namespace gfx
709 711
710 #endif // UI_GFX_RENDER_TEXT_H_ 712 #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