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

Unified Diff: ui/gfx/render_text.h

Issue 112063003: Implement eliding/truncating at end in RenderText (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Addresss comments, update bugs Created 7 years 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 side-by-side diff with in-line comments
Download patch
Index: ui/gfx/render_text.h
diff --git a/ui/gfx/render_text.h b/ui/gfx/render_text.h
index 8696d690560e6fddc28da3a59740d725c88a8e57..308b6737064740c7952b264dfa394a3905080267 100644
--- a/ui/gfx/render_text.h
+++ b/ui/gfx/render_text.h
@@ -27,6 +27,7 @@
#include "ui/gfx/shadow_value.h"
#include "ui/gfx/size_f.h"
#include "ui/gfx/text_constants.h"
+#include "ui/gfx/text_elider.h"
#include "ui/gfx/vector2d.h"
class SkCanvas;
@@ -227,6 +228,12 @@ class GFX_EXPORT RenderText {
// WARNING: Only use this for system limits, it lacks complex text support.
void set_truncate_length(size_t length) { truncate_length_ = length; }
+ // Elides the text to fit in |display_rect| according to the specified
+ // |elide_behavior|. |ELIDE_IN_MIDDLE| is not supported.
+ // If both truncate and elide are specified, the shorter of the two will be
+ // applicable.
+ void SetElideBehavior(ElideBehavior elide_behavior);
+
const Rect& display_rect() const { return display_rect_; }
void SetDisplayRect(const Rect& r);
@@ -535,6 +542,8 @@ class GFX_EXPORT RenderText {
FRIEND_TEST_ALL_PREFIXES(RenderTextTest, ApplyColorAndStyle);
FRIEND_TEST_ALL_PREFIXES(RenderTextTest, ObscuredText);
FRIEND_TEST_ALL_PREFIXES(RenderTextTest, RevealObscuredText);
+ FRIEND_TEST_ALL_PREFIXES(RenderTextTest, ElidedText);
+ FRIEND_TEST_ALL_PREFIXES(RenderTextTest, ElidedObscuredText);
FRIEND_TEST_ALL_PREFIXES(RenderTextTest, TruncatedText);
FRIEND_TEST_ALL_PREFIXES(RenderTextTest, TruncatedObscuredText);
FRIEND_TEST_ALL_PREFIXES(RenderTextTest, GraphemePositions);
@@ -556,6 +565,10 @@ class GFX_EXPORT RenderText {
// Updates |layout_text_| if the text is obscured or truncated.
void UpdateLayoutText();
+ // Elides |text| to fit in the |display_rect_| with given |elide_behavior_|.
+ // See ElideText in ui/gfx/text_elider.cc for reference.
+ base::string16 ElideText(const base::string16& text);
+
// Update the cached bounds and display offset to ensure that the current
// cursor is within the visible display area.
void UpdateCachedBoundsAndOffset();
@@ -628,6 +641,9 @@ class GFX_EXPORT RenderText {
// The maximum length of text to display, 0 forgoes a hard limit.
size_t truncate_length_;
+ // The behavior for eliding or truncating.
+ ElideBehavior elide_behavior_;
+
// The obscured and/or truncated text that will be displayed.
base::string16 layout_text_;

Powered by Google App Engine
This is Rietveld 408576698