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

Side by Side Diff: ui/views/controls/label.h

Issue 117983002: Prefix string16 with base:: in ui/. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: merge 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « ui/views/controls/image_view.cc ('k') | ui/views/controls/label.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_VIEWS_CONTROLS_LABEL_H_ 5 #ifndef UI_VIEWS_CONTROLS_LABEL_H_
6 #define UI_VIEWS_CONTROLS_LABEL_H_ 6 #define UI_VIEWS_CONTROLS_LABEL_H_
7 7
8 #include <string> 8 #include <string>
9 #include <vector> 9 #include <vector>
10 10
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
46 }; 46 };
47 47
48 enum ElideBehavior { 48 enum ElideBehavior {
49 NO_ELIDE, // Do not elide the label text; truncate as needed. 49 NO_ELIDE, // Do not elide the label text; truncate as needed.
50 ELIDE_IN_MIDDLE, // Add ellipsis in the middle of the string as needed. 50 ELIDE_IN_MIDDLE, // Add ellipsis in the middle of the string as needed.
51 ELIDE_AT_END, // Add ellipsis at the end of the string as needed. 51 ELIDE_AT_END, // Add ellipsis at the end of the string as needed.
52 ELIDE_AS_EMAIL, // Elide while retaining username/domain chars as needed. 52 ELIDE_AS_EMAIL, // Elide while retaining username/domain chars as needed.
53 }; 53 };
54 54
55 Label(); 55 Label();
56 explicit Label(const string16& text); 56 explicit Label(const base::string16& text);
57 Label(const string16& text, const gfx::FontList& font_list); 57 Label(const base::string16& text, const gfx::FontList& font_list);
58 Label(const string16& text, const gfx::Font& font); // OBSOLETE 58 Label(const base::string16& text, const gfx::Font& font); // OBSOLETE
59 virtual ~Label(); 59 virtual ~Label();
60 60
61 // Gets or sets the fonts used by this label. 61 // Gets or sets the fonts used by this label.
62 const gfx::FontList& font_list() const { return font_list_; } 62 const gfx::FontList& font_list() const { return font_list_; }
63 virtual void SetFontList(const gfx::FontList& font_list); 63 virtual void SetFontList(const gfx::FontList& font_list);
64 // Obsolete gfx::Font version. Should use gfx::FontList version instead. 64 // Obsolete gfx::Font version. Should use gfx::FontList version instead.
65 const gfx::Font& font() const; // OBSOLETE 65 const gfx::Font& font() const; // OBSOLETE
66 virtual void SetFont(const gfx::Font& font); // OBSOLETE 66 virtual void SetFont(const gfx::Font& font); // OBSOLETE
67 67
68 // Get or set the label text. 68 // Get or set the label text.
69 const string16& text() const { return text_; } 69 const base::string16& text() const { return text_; }
70 void SetText(const string16& text); 70 void SetText(const base::string16& text);
71 71
72 // Enables or disables auto-color-readability (enabled by default). If this 72 // Enables or disables auto-color-readability (enabled by default). If this
73 // is enabled, then calls to set any foreground or background color will 73 // is enabled, then calls to set any foreground or background color will
74 // trigger an automatic mapper that uses color_utils::GetReadableColor() to 74 // trigger an automatic mapper that uses color_utils::GetReadableColor() to
75 // ensure that the foreground colors are readable over the background color. 75 // ensure that the foreground colors are readable over the background color.
76 void SetAutoColorReadabilityEnabled(bool enabled); 76 void SetAutoColorReadabilityEnabled(bool enabled);
77 77
78 // Sets the color. This will automatically force the color to be readable 78 // Sets the color. This will automatically force the color to be readable
79 // over the current background color. 79 // over the current background color.
80 virtual void SetEnabledColor(SkColor color); 80 virtual void SetEnabledColor(SkColor color);
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
137 137
138 // Sets whether the label text should be elided in the middle or end (if 138 // Sets whether the label text should be elided in the middle or end (if
139 // necessary). The default is to elide at the end. 139 // necessary). The default is to elide at the end.
140 // NOTE: Eliding in the middle is not supported for multi-line strings. 140 // NOTE: Eliding in the middle is not supported for multi-line strings.
141 void SetElideBehavior(ElideBehavior elide_behavior); 141 void SetElideBehavior(ElideBehavior elide_behavior);
142 142
143 // Sets the tooltip text. Default behavior for a label (single-line) is to 143 // Sets the tooltip text. Default behavior for a label (single-line) is to
144 // show the full text if it is wider than its bounds. Calling this overrides 144 // show the full text if it is wider than its bounds. Calling this overrides
145 // the default behavior and lets you set a custom tooltip. To revert to 145 // the default behavior and lets you set a custom tooltip. To revert to
146 // default behavior, call this with an empty string. 146 // default behavior, call this with an empty string.
147 void SetTooltipText(const string16& tooltip_text); 147 void SetTooltipText(const base::string16& tooltip_text);
148 148
149 // Resizes the label so its width is set to the width of the longest line and 149 // Resizes the label so its width is set to the width of the longest line and
150 // its height deduced accordingly. 150 // its height deduced accordingly.
151 // This is only intended for multi-line labels and is useful when the label's 151 // This is only intended for multi-line labels and is useful when the label's
152 // text contains several lines separated with \n. 152 // text contains several lines separated with \n.
153 // |max_width| is the maximum width that will be used (longer lines will be 153 // |max_width| is the maximum width that will be used (longer lines will be
154 // wrapped). If 0, no maximum width is enforced. 154 // wrapped). If 0, no maximum width is enforced.
155 void SizeToFit(int max_width); 155 void SizeToFit(int max_width);
156 156
157 // Gets/sets the flag to determine whether the label should be collapsed when 157 // Gets/sets the flag to determine whether the label should be collapsed when
(...skipping 15 matching lines...) Expand all
173 virtual int GetHeightForWidth(int w) OVERRIDE; 173 virtual int GetHeightForWidth(int w) OVERRIDE;
174 virtual const char* GetClassName() const OVERRIDE; 174 virtual const char* GetClassName() const OVERRIDE;
175 virtual View* GetTooltipHandlerForPoint(const gfx::Point& point) OVERRIDE; 175 virtual View* GetTooltipHandlerForPoint(const gfx::Point& point) OVERRIDE;
176 virtual bool HitTestRect(const gfx::Rect& rect) const OVERRIDE; 176 virtual bool HitTestRect(const gfx::Rect& rect) const OVERRIDE;
177 virtual void GetAccessibleState(ui::AccessibleViewState* state) OVERRIDE; 177 virtual void GetAccessibleState(ui::AccessibleViewState* state) OVERRIDE;
178 // Gets the tooltip text for labels that are wider than their bounds, except 178 // Gets the tooltip text for labels that are wider than their bounds, except
179 // when the label is multiline, in which case it just returns false (no 179 // when the label is multiline, in which case it just returns false (no
180 // tooltip). If a custom tooltip has been specified with SetTooltipText() 180 // tooltip). If a custom tooltip has been specified with SetTooltipText()
181 // it is returned instead. 181 // it is returned instead.
182 virtual bool GetTooltipText(const gfx::Point& p, 182 virtual bool GetTooltipText(const gfx::Point& p,
183 string16* tooltip) const OVERRIDE; 183 base::string16* tooltip) const OVERRIDE;
184 184
185 protected: 185 protected:
186 // Called by Paint to paint the text. Override this to change how 186 // Called by Paint to paint the text. Override this to change how
187 // text is painted. 187 // text is painted.
188 virtual void PaintText(gfx::Canvas* canvas, 188 virtual void PaintText(gfx::Canvas* canvas,
189 const string16& text, 189 const base::string16& text,
190 const gfx::Rect& text_bounds, 190 const gfx::Rect& text_bounds,
191 int flags); 191 int flags);
192 192
193 virtual gfx::Size GetTextSize() const; 193 virtual gfx::Size GetTextSize() const;
194 194
195 SkColor disabled_color() const { return actual_disabled_color_; } 195 SkColor disabled_color() const { return actual_disabled_color_; }
196 196
197 // Overridden from View: 197 // Overridden from View:
198 // Overridden to dirty our text bounds if we're multi-line. 198 // Overridden to dirty our text bounds if we're multi-line.
199 virtual void OnBoundsChanged(const gfx::Rect& previous_bounds) OVERRIDE; 199 virtual void OnBoundsChanged(const gfx::Rect& previous_bounds) OVERRIDE;
200 virtual void OnPaint(gfx::Canvas* canvas) OVERRIDE; 200 virtual void OnPaint(gfx::Canvas* canvas) OVERRIDE;
201 virtual void OnNativeThemeChanged(const ui::NativeTheme* theme) OVERRIDE; 201 virtual void OnNativeThemeChanged(const ui::NativeTheme* theme) OVERRIDE;
202 202
203 private: 203 private:
204 // These tests call CalculateDrawStringParams in order to verify the 204 // These tests call CalculateDrawStringParams in order to verify the
205 // calculations done for drawing text. 205 // calculations done for drawing text.
206 FRIEND_TEST_ALL_PREFIXES(LabelTest, DrawSingleLineString); 206 FRIEND_TEST_ALL_PREFIXES(LabelTest, DrawSingleLineString);
207 FRIEND_TEST_ALL_PREFIXES(LabelTest, DrawMultiLineString); 207 FRIEND_TEST_ALL_PREFIXES(LabelTest, DrawMultiLineString);
208 FRIEND_TEST_ALL_PREFIXES(LabelTest, DrawSingleLineStringInRTL); 208 FRIEND_TEST_ALL_PREFIXES(LabelTest, DrawSingleLineStringInRTL);
209 FRIEND_TEST_ALL_PREFIXES(LabelTest, DrawMultiLineStringInRTL); 209 FRIEND_TEST_ALL_PREFIXES(LabelTest, DrawMultiLineStringInRTL);
210 FRIEND_TEST_ALL_PREFIXES(LabelTest, AutoDetectDirectionality); 210 FRIEND_TEST_ALL_PREFIXES(LabelTest, AutoDetectDirectionality);
211 211
212 // Calls ComputeDrawStringFlags(). 212 // Calls ComputeDrawStringFlags().
213 FRIEND_TEST_ALL_PREFIXES(LabelTest, DisableSubpixelRendering); 213 FRIEND_TEST_ALL_PREFIXES(LabelTest, DisableSubpixelRendering);
214 214
215 void Init(const string16& text, const gfx::FontList& font_list); 215 void Init(const base::string16& text, const gfx::FontList& font_list);
216 216
217 void RecalculateColors(); 217 void RecalculateColors();
218 218
219 // Returns where the text is drawn, in the receivers coordinate system. 219 // Returns where the text is drawn, in the receivers coordinate system.
220 gfx::Rect GetTextBounds() const; 220 gfx::Rect GetTextBounds() const;
221 221
222 int ComputeDrawStringFlags() const; 222 int ComputeDrawStringFlags() const;
223 223
224 gfx::Rect GetAvailableRect() const; 224 gfx::Rect GetAvailableRect() const;
225 225
226 // Returns parameters to be used for the DrawString call. 226 // Returns parameters to be used for the DrawString call.
227 void CalculateDrawStringParams(string16* paint_text, 227 void CalculateDrawStringParams(base::string16* paint_text,
228 gfx::Rect* text_bounds, 228 gfx::Rect* text_bounds,
229 int* flags) const; 229 int* flags) const;
230 230
231 // Updates any colors that have not been explicitly set from the theme. 231 // Updates any colors that have not been explicitly set from the theme.
232 void UpdateColorsFromTheme(const ui::NativeTheme* theme); 232 void UpdateColorsFromTheme(const ui::NativeTheme* theme);
233 233
234 // Resets |cached_heights_| and |cached_heights_cursor_| and mark 234 // Resets |cached_heights_| and |cached_heights_cursor_| and mark
235 // |text_size_valid_| as false. 235 // |text_size_valid_| as false.
236 void ResetCachedSize(); 236 void ResetCachedSize();
237 237
238 bool ShouldShowDefaultTooltip() const; 238 bool ShouldShowDefaultTooltip() const;
239 239
240 string16 text_; 240 base::string16 text_;
241 gfx::FontList font_list_; 241 gfx::FontList font_list_;
242 SkColor requested_enabled_color_; 242 SkColor requested_enabled_color_;
243 SkColor actual_enabled_color_; 243 SkColor actual_enabled_color_;
244 SkColor requested_disabled_color_; 244 SkColor requested_disabled_color_;
245 SkColor actual_disabled_color_; 245 SkColor actual_disabled_color_;
246 SkColor background_color_; 246 SkColor background_color_;
247 247
248 // Set to true once the corresponding setter is invoked. 248 // Set to true once the corresponding setter is invoked.
249 bool enabled_color_set_; 249 bool enabled_color_set_;
250 bool disabled_color_set_; 250 bool disabled_color_set_;
251 bool background_color_set_; 251 bool background_color_set_;
252 252
253 bool auto_color_readability_; 253 bool auto_color_readability_;
254 mutable gfx::Size text_size_; 254 mutable gfx::Size text_size_;
255 mutable bool text_size_valid_; 255 mutable bool text_size_valid_;
256 int line_height_; 256 int line_height_;
257 bool is_multi_line_; 257 bool is_multi_line_;
258 bool allow_character_break_; 258 bool allow_character_break_;
259 ElideBehavior elide_behavior_; 259 ElideBehavior elide_behavior_;
260 gfx::HorizontalAlignment horizontal_alignment_; 260 gfx::HorizontalAlignment horizontal_alignment_;
261 string16 tooltip_text_; 261 base::string16 tooltip_text_;
262 // Whether to collapse the label when it's not visible. 262 // Whether to collapse the label when it's not visible.
263 bool collapse_when_hidden_; 263 bool collapse_when_hidden_;
264 // The following member variable is used to control whether the 264 // The following member variable is used to control whether the
265 // directionality is auto-detected based on first strong directionality 265 // directionality is auto-detected based on first strong directionality
266 // character or is determined by chrome UI's locale. 266 // character or is determined by chrome UI's locale.
267 DirectionalityMode directionality_mode_; 267 DirectionalityMode directionality_mode_;
268 // When embedded in a larger control that is focusable, setting this flag 268 // When embedded in a larger control that is focusable, setting this flag
269 // allows this view to reserve space for a focus border that it otherwise 269 // allows this view to reserve space for a focus border that it otherwise
270 // might not have because it is not itself focusable. 270 // might not have because it is not itself focusable.
271 bool has_focus_border_; 271 bool has_focus_border_;
(...skipping 11 matching lines...) Expand all
283 // The cached heights to avoid recalculation in GetHeightForWidth(). 283 // The cached heights to avoid recalculation in GetHeightForWidth().
284 std::vector<gfx::Size> cached_heights_; 284 std::vector<gfx::Size> cached_heights_;
285 int cached_heights_cursor_; 285 int cached_heights_cursor_;
286 286
287 DISALLOW_COPY_AND_ASSIGN(Label); 287 DISALLOW_COPY_AND_ASSIGN(Label);
288 }; 288 };
289 289
290 } // namespace views 290 } // namespace views
291 291
292 #endif // UI_VIEWS_CONTROLS_LABEL_H_ 292 #endif // UI_VIEWS_CONTROLS_LABEL_H_
OLDNEW
« no previous file with comments | « ui/views/controls/image_view.cc ('k') | ui/views/controls/label.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698