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

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

Issue 10807082: Add RenderText DirectionalityMode enum and support; etc. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Restore Label::SetURL; derive the direction from display text. Created 8 years, 4 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
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 9
10 #include "base/compiler_specific.h" 10 #include "base/compiler_specific.h"
11 #include "base/gtest_prod_util.h" 11 #include "base/gtest_prod_util.h"
12 #include "base/string16.h" 12 #include "base/string16.h"
13 #include "googleurl/src/gurl.h" 13 #include "googleurl/src/gurl.h"
14 #include "third_party/skia/include/core/SkColor.h" 14 #include "third_party/skia/include/core/SkColor.h"
15 #include "ui/gfx/font.h" 15 #include "ui/gfx/font.h"
16 #include "ui/gfx/render_text.h"
16 #include "ui/views/view.h" 17 #include "ui/views/view.h"
17 18
18 namespace views { 19 namespace views {
19 20
20 ///////////////////////////////////////////////////////////////////////////// 21 /////////////////////////////////////////////////////////////////////////////
21 // 22 //
22 // Label class 23 // Label class
23 // 24 //
24 // A label is a view subclass that can display a string. 25 // A label is a view subclass that can display a string.
25 // 26 //
26 ///////////////////////////////////////////////////////////////////////////// 27 /////////////////////////////////////////////////////////////////////////////
27 class VIEWS_EXPORT Label : public View { 28 class VIEWS_EXPORT Label : public View {
28 public: 29 public:
29 enum Alignment { ALIGN_LEFT = 0, 30 enum Alignment { ALIGN_LEFT = 0,
30 ALIGN_CENTER, 31 ALIGN_CENTER,
31 ALIGN_RIGHT }; 32 ALIGN_RIGHT };
32 33
33 // The following enum is used to indicate whether using the Chrome UI's
34 // directionality as the label's directionality, or auto-detecting the label's
35 // directionality.
36 //
37 // If the label text originates from the Chrome UI, we should use the Chrome
38 // UI's directionality as the label's directionality.
39 //
40 // If the text originates from a web page, its directionality is determined
41 // based on its first character with strong directionality, disregarding what
42 // directionality the Chrome UI is.
43 enum DirectionalityMode {
44 USE_UI_DIRECTIONALITY = 0,
45 AUTO_DETECT_DIRECTIONALITY
46 };
47
48 // The view class name. 34 // The view class name.
49 static const char kViewClassName[]; 35 static const char kViewClassName[];
50 36
51 // The padding for the focus border when rendering focused text. 37 // The padding for the focus border when rendering focused text.
52 static const int kFocusBorderPadding; 38 static const int kFocusBorderPadding;
53 39
54 Label(); 40 Label();
55 explicit Label(const string16& text); 41 explicit Label(const string16& text);
56 Label(const string16& text, const gfx::Font& font); 42 Label(const string16& text, const gfx::Font& font);
57 virtual ~Label(); 43 virtual ~Label();
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
94 // Enables a drop shadow underneath the text. 80 // Enables a drop shadow underneath the text.
95 void SetShadowColors(SkColor enabled_color, SkColor disabled_color); 81 void SetShadowColors(SkColor enabled_color, SkColor disabled_color);
96 82
97 // Sets the drop shadow's offset from the text. 83 // Sets the drop shadow's offset from the text.
98 void SetShadowOffset(int x, int y); 84 void SetShadowOffset(int x, int y);
99 85
100 // Disables shadows. 86 // Disables shadows.
101 void ClearEmbellishing(); 87 void ClearEmbellishing();
102 88
103 // Sets horizontal alignment. If the locale is RTL, and the directionality 89 // Sets horizontal alignment. If the locale is RTL, and the directionality
104 // mode is USE_UI_DIRECTIONALITY, the alignment is flipped around. 90 // mode is gfx::DERIVE_FROM_UI, the alignment is flipped around.
105 // 91 //
106 // Caveat: for labels originating from a web page, the directionality mode 92 // Caveat: for labels originating from a web page, the directionality mode
107 // should be reset to AUTO_DETECT_DIRECTIONALITY before the horizontal 93 // should be reset to gfx::DERIVE_FROM_TEXT before the horizontal alignment is
108 // alignment is set. Otherwise, the label's alignment specified as a parameter 94 // set. Otherwise, the label's alignment specified as a parameter will be
109 // will be flipped in RTL locales. 95 // flipped in RTL locales.
110 void SetHorizontalAlignment(Alignment alignment); 96 void SetHorizontalAlignment(Alignment alignment);
111 97
112 Alignment horizontal_alignment() const { return horiz_alignment_; } 98 Alignment horizontal_alignment() const { return horiz_alignment_; }
113 99
114 // Sets the directionality mode. The directionality mode is initialized to 100 // Sets the directionality mode. The directionality mode is initialized to
115 // USE_UI_DIRECTIONALITY when the label is constructed. USE_UI_DIRECTIONALITY 101 // gfx::DERIVE_FROM_UI when the label is constructed. gfx::DERIVE_FROM_UI
116 // applies to every label that originates from the Chrome UI. However, if the 102 // applies to every label that originates from the Chrome UI. However, if the
117 // label originates from a web page, its directionality is auto-detected. 103 // label originates from a web page, its directionality is auto-detected.
118 void set_directionality_mode(DirectionalityMode mode) { 104 void set_directionality_mode(gfx::DirectionalityMode mode) {
119 directionality_mode_ = mode; 105 directionality_mode_ = mode;
120 } 106 }
121 107
122 DirectionalityMode directionality_mode() const { 108 gfx::DirectionalityMode directionality_mode() const {
123 return directionality_mode_; 109 return directionality_mode_;
124 } 110 }
125 111
126 // Sets whether the label text can wrap on multiple lines. 112 // Sets whether the label text can wrap on multiple lines.
127 // Default is false. 113 // Default is false.
128 void SetMultiLine(bool multi_line); 114 void SetMultiLine(bool multi_line);
129 115
130 // Returns whether the label text can wrap on multiple lines. 116 // Returns whether the label text can wrap on multiple lines.
131 bool is_multi_line() const { return is_multi_line_; } 117 bool is_multi_line() const { return is_multi_line_; }
132 118
(...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after
272 bool allow_character_break_; 258 bool allow_character_break_;
273 bool elide_in_middle_; 259 bool elide_in_middle_;
274 bool is_email_; 260 bool is_email_;
275 Alignment horiz_alignment_; 261 Alignment horiz_alignment_;
276 string16 tooltip_text_; 262 string16 tooltip_text_;
277 // Whether the mouse is over this label. 263 // Whether the mouse is over this label.
278 bool contains_mouse_; 264 bool contains_mouse_;
279 scoped_ptr<Background> mouse_over_background_; 265 scoped_ptr<Background> mouse_over_background_;
280 // Whether to collapse the label when it's not visible. 266 // Whether to collapse the label when it's not visible.
281 bool collapse_when_hidden_; 267 bool collapse_when_hidden_;
282 // The following member variable is used to control whether the 268 // Controls whether the base text directionality is inherited from the text's
283 // directionality is auto-detected based on first strong directionality 269 // first strong directionality character or from the UI's locale.
284 // character or is determined by chrome UI's locale. 270 gfx::DirectionalityMode directionality_mode_;
285 DirectionalityMode directionality_mode_;
286 // When embedded in a larger control that is focusable, setting this flag 271 // When embedded in a larger control that is focusable, setting this flag
287 // allows this view to be painted as focused even when it is itself not. 272 // allows this view to be painted as focused even when it is itself not.
288 bool paint_as_focused_; 273 bool paint_as_focused_;
289 // When embedded in a larger control that is focusable, setting this flag 274 // When embedded in a larger control that is focusable, setting this flag
290 // allows this view to reserve space for a focus border that it otherwise 275 // allows this view to reserve space for a focus border that it otherwise
291 // might not have because it is not itself focusable. 276 // might not have because it is not itself focusable.
292 bool has_focus_border_; 277 bool has_focus_border_;
293 278
294 // Colors for shadow. 279 // Colors for shadow.
295 SkColor enabled_shadow_color_; 280 SkColor enabled_shadow_color_;
296 SkColor disabled_shadow_color_; 281 SkColor disabled_shadow_color_;
297 282
298 // Space between text and shadow. 283 // Space between text and shadow.
299 gfx::Point shadow_offset_; 284 gfx::Point shadow_offset_;
300 285
301 // Should a shadow be drawn behind the text? 286 // Should a shadow be drawn behind the text?
302 bool has_shadow_; 287 bool has_shadow_;
303 288
304 289
305 DISALLOW_COPY_AND_ASSIGN(Label); 290 DISALLOW_COPY_AND_ASSIGN(Label);
306 }; 291 };
307 292
308 } // namespace views 293 } // namespace views
309 294
310 #endif // UI_VIEWS_CONTROLS_LABEL_H_ 295 #endif // UI_VIEWS_CONTROLS_LABEL_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698