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

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

Issue 329813003: Reland: Use labels to display views tab titles. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Call AddChildView(title_) on Tab to prevent leaks. Created 6 years, 6 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 | « ui/views/controls/button/label_button.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
11 #include "base/compiler_specific.h" 11 #include "base/compiler_specific.h"
12 #include "base/gtest_prod_util.h" 12 #include "base/gtest_prod_util.h"
13 #include "base/strings/string16.h" 13 #include "base/strings/string16.h"
14 #include "third_party/skia/include/core/SkColor.h" 14 #include "third_party/skia/include/core/SkColor.h"
15 #include "ui/gfx/font_list.h" 15 #include "ui/gfx/font_list.h"
16 #include "ui/gfx/text_constants.h" 16 #include "ui/gfx/text_constants.h"
17 #include "ui/views/view.h" 17 #include "ui/views/view.h"
18 18
19 namespace views { 19 namespace views {
20 20
21 ///////////////////////////////////////////////////////////////////////////// 21 // A view subclass that can display a string.
22 //
23 // Label class
24 //
25 // A label is a view subclass that can display a string.
26 //
27 /////////////////////////////////////////////////////////////////////////////
28 class VIEWS_EXPORT Label : public View { 22 class VIEWS_EXPORT Label : public View {
29 public: 23 public:
30 // The following enum is used to indicate whether using the Chrome UI's
31 // directionality as the label's directionality, or auto-detecting the label's
32 // directionality.
33 //
34 // If the label text originates from the Chrome UI, we should use the Chrome
35 // UI's directionality as the label's directionality.
36 //
37 // If the text originates from a web page, its directionality is determined
38 // based on its first character with strong directionality, disregarding what
39 // directionality the Chrome UI is.
40 enum DirectionalityMode {
41 USE_UI_DIRECTIONALITY = 0,
42 AUTO_DETECT_DIRECTIONALITY
43 };
44
45 // Internal class name. 24 // Internal class name.
46 static const char kViewClassName[]; 25 static const char kViewClassName[];
47 26
48 // The padding for the focus border when rendering focused text. 27 // The padding for the focus border when rendering focused text.
49 static const int kFocusBorderPadding; 28 static const int kFocusBorderPadding;
50 29
51 Label(); 30 Label();
52 explicit Label(const base::string16& text); 31 explicit Label(const base::string16& text);
53 Label(const base::string16& text, const gfx::FontList& font_list); 32 Label(const base::string16& text, const gfx::FontList& font_list);
54 virtual ~Label(); 33 virtual ~Label();
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
87 66
88 // Sets the shadow blur. Default is zero. 67 // Sets the shadow blur. Default is zero.
89 void set_shadow_blur(double shadow_blur) { shadow_blur_ = shadow_blur; } 68 void set_shadow_blur(double shadow_blur) { shadow_blur_ = shadow_blur; }
90 69
91 // Disables shadows. 70 // Disables shadows.
92 void ClearEmbellishing(); 71 void ClearEmbellishing();
93 72
94 // Set the color of a halo on the painted text (use transparent for none). 73 // Set the color of a halo on the painted text (use transparent for none).
95 void set_halo_color(SkColor halo_color) { halo_color_ = halo_color; } 74 void set_halo_color(SkColor halo_color) { halo_color_ = halo_color; }
96 75
97 // Sets horizontal alignment. If the locale is RTL, and the directionality 76 // Sets the horizontal alignment; the argument value is mirrored in RTL UI.
98 // mode is USE_UI_DIRECTIONALITY, the alignment is flipped around.
99 //
100 // Caveat: for labels originating from a web page, the directionality mode
101 // should be reset to AUTO_DETECT_DIRECTIONALITY before the horizontal
102 // alignment is set. Otherwise, the label's alignment specified as a parameter
103 // will be flipped in RTL locales.
104 void SetHorizontalAlignment(gfx::HorizontalAlignment alignment); 77 void SetHorizontalAlignment(gfx::HorizontalAlignment alignment);
105 78 gfx::HorizontalAlignment GetHorizontalAlignment() const;
106 gfx::HorizontalAlignment horizontal_alignment() const { 79
107 return horizontal_alignment_; 80 // Sets the directionality mode. The default value is DIRECTIONALITY_FROM_UI,
108 } 81 // which should be suitable for most text originating from UI string assets.
109 82 // Most text originating from web content should use DIRECTIONALITY_FROM_TEXT.
110 // Sets the directionality mode. The directionality mode is initialized to 83 void set_directionality_mode(gfx::DirectionalityMode mode) {
111 // USE_UI_DIRECTIONALITY when the label is constructed. USE_UI_DIRECTIONALITY
112 // applies to every label that originates from the Chrome UI. However, if the
113 // label originates from a web page, its directionality is auto-detected.
114 void set_directionality_mode(DirectionalityMode mode) {
115 directionality_mode_ = mode; 84 directionality_mode_ = mode;
116 } 85 }
117 86 gfx::DirectionalityMode directionality_mode() const {
118 DirectionalityMode directionality_mode() const {
119 return directionality_mode_; 87 return directionality_mode_;
120 } 88 }
121 89
122 // Get or set the distance in pixels between baselines of multi-line text. 90 // Get or set the distance in pixels between baselines of multi-line text.
123 // Default is 0, indicating the distance between lines should be the standard 91 // Default is 0, indicating the distance between lines should be the standard
124 // one for the label's text, font list, and platform. 92 // one for the label's text, font list, and platform.
125 int line_height() const { return line_height_; } 93 int line_height() const { return line_height_; }
126 void SetLineHeight(int height); 94 void SetLineHeight(int height);
127 95
128 // Get or set if the label text can wrap on multiple lines; default is false. 96 // Get or set if the label text can wrap on multiple lines; default is false.
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after
205 virtual void OnPaint(gfx::Canvas* canvas) OVERRIDE; 173 virtual void OnPaint(gfx::Canvas* canvas) OVERRIDE;
206 virtual void OnNativeThemeChanged(const ui::NativeTheme* theme) OVERRIDE; 174 virtual void OnNativeThemeChanged(const ui::NativeTheme* theme) OVERRIDE;
207 175
208 private: 176 private:
209 // These tests call CalculateDrawStringParams in order to verify the 177 // These tests call CalculateDrawStringParams in order to verify the
210 // calculations done for drawing text. 178 // calculations done for drawing text.
211 FRIEND_TEST_ALL_PREFIXES(LabelTest, DrawSingleLineString); 179 FRIEND_TEST_ALL_PREFIXES(LabelTest, DrawSingleLineString);
212 FRIEND_TEST_ALL_PREFIXES(LabelTest, DrawMultiLineString); 180 FRIEND_TEST_ALL_PREFIXES(LabelTest, DrawMultiLineString);
213 FRIEND_TEST_ALL_PREFIXES(LabelTest, DrawSingleLineStringInRTL); 181 FRIEND_TEST_ALL_PREFIXES(LabelTest, DrawSingleLineStringInRTL);
214 FRIEND_TEST_ALL_PREFIXES(LabelTest, DrawMultiLineStringInRTL); 182 FRIEND_TEST_ALL_PREFIXES(LabelTest, DrawMultiLineStringInRTL);
215 FRIEND_TEST_ALL_PREFIXES(LabelTest, AutoDetectDirectionality); 183 FRIEND_TEST_ALL_PREFIXES(LabelTest, DirectionalityFromText);
216
217 // Calls ComputeDrawStringFlags().
218 FRIEND_TEST_ALL_PREFIXES(LabelTest, DisableSubpixelRendering); 184 FRIEND_TEST_ALL_PREFIXES(LabelTest, DisableSubpixelRendering);
219 185
220 // Sets both |text_| and |layout_text_| to appropriate values, taking 186 // Sets both |text_| and |layout_text_| to appropriate values, taking
221 // the label's 'obscured' status into account. 187 // the label's 'obscured' status into account.
222 void SetTextInternal(const base::string16& text); 188 void SetTextInternal(const base::string16& text);
223 189
224 void Init(const base::string16& text, const gfx::FontList& font_list); 190 void Init(const base::string16& text, const gfx::FontList& font_list);
225 191
226 void RecalculateColors(); 192 void RecalculateColors();
227 193
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
265 mutable bool text_size_valid_; 231 mutable bool text_size_valid_;
266 int line_height_; 232 int line_height_;
267 bool is_multi_line_; 233 bool is_multi_line_;
268 bool is_obscured_; 234 bool is_obscured_;
269 bool allow_character_break_; 235 bool allow_character_break_;
270 gfx::ElideBehavior elide_behavior_; 236 gfx::ElideBehavior elide_behavior_;
271 gfx::HorizontalAlignment horizontal_alignment_; 237 gfx::HorizontalAlignment horizontal_alignment_;
272 base::string16 tooltip_text_; 238 base::string16 tooltip_text_;
273 // Whether to collapse the label when it's not visible. 239 // Whether to collapse the label when it's not visible.
274 bool collapse_when_hidden_; 240 bool collapse_when_hidden_;
275 // The following member variable is used to control whether the 241 // Controls whether the directionality is auto-detected based on first strong
276 // directionality is auto-detected based on first strong directionality 242 // directionality character or is determined by the application UI's locale.
277 // character or is determined by chrome UI's locale. 243 gfx::DirectionalityMode directionality_mode_;
278 DirectionalityMode directionality_mode_;
279 244
280 // Colors for shadow. 245 // Colors for shadow.
281 SkColor enabled_shadow_color_; 246 SkColor enabled_shadow_color_;
282 SkColor disabled_shadow_color_; 247 SkColor disabled_shadow_color_;
283 248
284 // Space between text and shadow. 249 // Space between text and shadow.
285 gfx::Point shadow_offset_; 250 gfx::Point shadow_offset_;
286 251
287 // Should a shadow be drawn behind the text? 252 // Should a shadow be drawn behind the text?
288 bool has_shadow_; 253 bool has_shadow_;
289 254
290 // Indicates the level of shadow blurring. Default is zero. 255 // Indicates the level of shadow blurring. Default is zero.
291 double shadow_blur_; 256 double shadow_blur_;
292 257
293 // The halo color drawn around the text if it is not transparent. 258 // The halo color drawn around the text if it is not transparent.
294 SkColor halo_color_; 259 SkColor halo_color_;
295 260
296 // The cached heights to avoid recalculation in GetHeightForWidth(). 261 // The cached heights to avoid recalculation in GetHeightForWidth().
297 mutable std::vector<gfx::Size> cached_heights_; 262 mutable std::vector<gfx::Size> cached_heights_;
298 mutable int cached_heights_cursor_; 263 mutable int cached_heights_cursor_;
299 264
300 DISALLOW_COPY_AND_ASSIGN(Label); 265 DISALLOW_COPY_AND_ASSIGN(Label);
301 }; 266 };
302 267
303 } // namespace views 268 } // namespace views
304 269
305 #endif // UI_VIEWS_CONTROLS_LABEL_H_ 270 #endif // UI_VIEWS_CONTROLS_LABEL_H_
OLDNEW
« no previous file with comments | « ui/views/controls/button/label_button.cc ('k') | ui/views/controls/label.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698