| OLD | NEW |
| 1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2008 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 CHROME_VIEWS_LABEL_H__ | 5 #ifndef CHROME_VIEWS_LABEL_H__ |
| 6 #define CHROME_VIEWS_LABEL_H__ | 6 #define CHROME_VIEWS_LABEL_H__ |
| 7 | 7 |
| 8 #include "chrome/common/gfx/chrome_font.h" | 8 #include "chrome/common/gfx/chrome_font.h" |
| 9 #include "chrome/views/view.h" | 9 #include "chrome/views/view.h" |
| 10 #include "googleurl/src/gurl.h" | 10 #include "googleurl/src/gurl.h" |
| 11 #include "skia/include/SkColor.h" | 11 #include "skia/include/SkColor.h" |
| 12 #include "testing/gtest/include/gtest/gtest_prod.h" | 12 #include "testing/gtest/include/gtest/gtest_prod.h" |
| 13 | 13 |
| 14 namespace views { | 14 namespace views { |
| 15 | 15 |
| 16 ///////////////////////////////////////////////////////////////////////////// | 16 ///////////////////////////////////////////////////////////////////////////// |
| 17 // | 17 // |
| 18 // Label class | 18 // Label class |
| 19 // | 19 // |
| 20 // A label is a view subclass that can display a string. | 20 // A label is a view subclass that can display a string. |
| 21 // | 21 // |
| 22 ///////////////////////////////////////////////////////////////////////////// | 22 ///////////////////////////////////////////////////////////////////////////// |
| 23 class Label : public View { | 23 class Label : public View { |
| 24 public: | 24 public: |
| 25 enum Alignment { ALIGN_LEFT = 0, | 25 enum Alignment { ALIGN_LEFT = 0, |
| 26 ALIGN_CENTER, | 26 ALIGN_CENTER, |
| 27 ALIGN_RIGHT }; | 27 ALIGN_RIGHT }; |
| 28 | 28 |
| 29 // The following enum is used to indicate whether using the Chrome UI's |
| 30 // alignment as the label's alignment, or autodetecting the label's |
| 31 // alignment. |
| 32 // |
| 33 // If the label text originates from the Chrome UI, we should use the Chrome |
| 34 // UI's alignment as the label's alignment. |
| 35 // |
| 36 // If the text originates from a web page, the text's alignment is determined |
| 37 // based on the first character with strong directionality, disregarding what |
| 38 // directionality the Chrome UI is. And its alignment will not be flipped |
| 39 // around in RTL locales. |
| 40 enum RTLAlignmentMode { |
| 41 USE_UI_ALIGNMENT = 0, |
| 42 AUTO_DETECT_ALIGNMENT |
| 43 }; |
| 44 |
| 29 // The view class name. | 45 // The view class name. |
| 30 static const char kViewClassName[]; | 46 static const char kViewClassName[]; |
| 31 | 47 |
| 32 // Create a new label with a default font and empty value | 48 // Create a new label with a default font and empty value |
| 33 Label(); | 49 Label(); |
| 34 | 50 |
| 35 // Create a new label with a default font | 51 // Create a new label with a default font |
| 36 explicit Label(const std::wstring& text); | 52 explicit Label(const std::wstring& text); |
| 37 | 53 |
| 38 Label(const std::wstring& text, const ChromeFont& font); | 54 Label(const std::wstring& text, const ChromeFont& font); |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 74 | 90 |
| 75 // Return the label URL. | 91 // Return the label URL. |
| 76 const GURL GetURL() const; | 92 const GURL GetURL() const; |
| 77 | 93 |
| 78 // Set the color | 94 // Set the color |
| 79 virtual void SetColor(const SkColor& color); | 95 virtual void SetColor(const SkColor& color); |
| 80 | 96 |
| 81 // Return a reference to the currently used color | 97 // Return a reference to the currently used color |
| 82 virtual const SkColor GetColor() const; | 98 virtual const SkColor GetColor() const; |
| 83 | 99 |
| 84 // Alignment | 100 // Set horizontal alignment. If the locale is RTL, and the RTL alignment |
| 101 // setting is set as USE_UI_ALIGNMENT, the alignment is flipped around. |
| 102 // |
| 103 // Caveat: for labels originating from a web page, the RTL alignment mode |
| 104 // should be reset to AUTO_DETECT_ALIGNMENT before the horizontal alignment |
| 105 // is set. Otherwise, the label's alignment specified as a parameter will be |
| 106 // flipped in RTL locales. Please see the comments in SetRTLAlignmentMode for |
| 107 // more information. |
| 85 void SetHorizontalAlignment(Alignment a); | 108 void SetHorizontalAlignment(Alignment a); |
| 109 |
| 86 Alignment GetHorizontalAlignment() const; | 110 Alignment GetHorizontalAlignment() const; |
| 87 | 111 |
| 112 // Set the RTL alignment mode. The RTL alignment mode is initialized to |
| 113 // USE_UI_ALIGNMENT when the label is constructed. USE_UI_ALIGNMENT applies |
| 114 // to every label that originates from the Chrome UI. However, if the label |
| 115 // originates from a web page, its alignment should not be flipped around for |
| 116 // RTL locales. For such labels, we need to set the RTL alignment mode to |
| 117 // AUTO_DETECT_ALIGNMENT so that subsequent SetHorizontalAlignment() calls |
| 118 // will not flip the label's alignment around. |
| 119 void SetRTLAlignmentMode(RTLAlignmentMode mode); |
| 120 |
| 121 RTLAlignmentMode GetRTLAlignmentMode() const; |
| 122 |
| 88 // Set whether the label text can wrap on multiple lines. | 123 // Set whether the label text can wrap on multiple lines. |
| 89 // Default is false | 124 // Default is false |
| 90 void SetMultiLine(bool f); | 125 void SetMultiLine(bool f); |
| 91 | 126 |
| 92 // Return whether the label text can wrap on multiple lines | 127 // Return whether the label text can wrap on multiple lines |
| 93 bool IsMultiLine(); | 128 bool IsMultiLine(); |
| 94 | 129 |
| 95 // Sets the tooltip text. Default behavior for a label (single-line) is to | 130 // Sets the tooltip text. Default behavior for a label (single-line) is to |
| 96 // show the full text if it is wider than its bounds. Calling this overrides | 131 // show the full text if it is wider than its bounds. Calling this overrides |
| 97 // the default behavior and lets you set a custom tooltip. To revert to | 132 // the default behavior and lets you set a custom tooltip. To revert to |
| (...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 185 bool text_size_valid_; | 220 bool text_size_valid_; |
| 186 bool is_multi_line_; | 221 bool is_multi_line_; |
| 187 bool url_set_; | 222 bool url_set_; |
| 188 Alignment horiz_alignment_; | 223 Alignment horiz_alignment_; |
| 189 std::wstring tooltip_text_; | 224 std::wstring tooltip_text_; |
| 190 // Whether the mouse is over this label. | 225 // Whether the mouse is over this label. |
| 191 bool contains_mouse_; | 226 bool contains_mouse_; |
| 192 scoped_ptr<Background> mouse_over_background_; | 227 scoped_ptr<Background> mouse_over_background_; |
| 193 // Whether to collapse the label when it's not visible. | 228 // Whether to collapse the label when it's not visible. |
| 194 bool collapse_when_hidden_; | 229 bool collapse_when_hidden_; |
| 230 // The following member variable is used to control whether the alignment |
| 231 // needs to be flipped around for RTL locales. Please refer to the definition |
| 232 // of RTLAlignmentMode for more information. |
| 233 RTLAlignmentMode rtl_alignment_mode_; |
| 195 | 234 |
| 196 DISALLOW_COPY_AND_ASSIGN(Label); | 235 DISALLOW_COPY_AND_ASSIGN(Label); |
| 197 }; | 236 }; |
| 198 | 237 |
| 199 } // namespace views | 238 } // namespace views |
| 200 | 239 |
| 201 #endif // CHROME_VIEWS_VIEW_H__ | 240 #endif // CHROME_VIEWS_VIEW_H__ |
| OLD | NEW |