OLD | NEW |
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 131 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
142 virtual gfx::Size GetTextSize() const; | 142 virtual gfx::Size GetTextSize() const; |
143 | 143 |
144 SkColor disabled_color() const { return actual_disabled_color_; } | 144 SkColor disabled_color() const { return actual_disabled_color_; } |
145 | 145 |
146 // View: | 146 // View: |
147 void OnBoundsChanged(const gfx::Rect& previous_bounds) override; | 147 void OnBoundsChanged(const gfx::Rect& previous_bounds) override; |
148 void OnPaint(gfx::Canvas* canvas) override; | 148 void OnPaint(gfx::Canvas* canvas) override; |
149 void OnNativeThemeChanged(const ui::NativeTheme* theme) override; | 149 void OnNativeThemeChanged(const ui::NativeTheme* theme) override; |
150 | 150 |
151 private: | 151 private: |
| 152 struct DrawStringParams { |
| 153 DrawStringParams() : flags(0) {} |
| 154 |
| 155 base::string16 text; |
| 156 gfx::Rect bounds; |
| 157 int flags; |
| 158 }; |
| 159 |
152 // These tests call CalculateDrawStringParams in order to verify the | 160 // These tests call CalculateDrawStringParams in order to verify the |
153 // calculations done for drawing text. | 161 // calculations done for drawing text. |
154 FRIEND_TEST_ALL_PREFIXES(LabelTest, DrawSingleLineString); | 162 FRIEND_TEST_ALL_PREFIXES(LabelTest, DrawSingleLineString); |
155 FRIEND_TEST_ALL_PREFIXES(LabelTest, DrawMultiLineString); | 163 FRIEND_TEST_ALL_PREFIXES(LabelTest, DrawMultiLineString); |
156 FRIEND_TEST_ALL_PREFIXES(LabelTest, DrawSingleLineStringInRTL); | 164 FRIEND_TEST_ALL_PREFIXES(LabelTest, DrawSingleLineStringInRTL); |
157 FRIEND_TEST_ALL_PREFIXES(LabelTest, DrawMultiLineStringInRTL); | 165 FRIEND_TEST_ALL_PREFIXES(LabelTest, DrawMultiLineStringInRTL); |
158 FRIEND_TEST_ALL_PREFIXES(LabelTest, DirectionalityFromText); | 166 FRIEND_TEST_ALL_PREFIXES(LabelTest, DirectionalityFromText); |
159 FRIEND_TEST_ALL_PREFIXES(LabelTest, DisableSubpixelRendering); | 167 FRIEND_TEST_ALL_PREFIXES(LabelTest, DisableSubpixelRendering); |
160 | 168 |
161 // Sets both |text_| and |layout_text_| to appropriate values, taking | 169 // Sets both |text_| and |layout_text_| to appropriate values, taking |
162 // the label's 'obscured' status into account. | 170 // the label's 'obscured' status into account. |
163 void SetTextInternal(const base::string16& text); | 171 void SetTextInternal(const base::string16& text); |
164 | 172 |
165 void Init(const base::string16& text, const gfx::FontList& font_list); | 173 void Init(const base::string16& text, const gfx::FontList& font_list); |
166 | 174 |
167 void RecalculateColors(); | 175 void RecalculateColors(); |
168 | 176 |
169 // Returns where the text is drawn, in the receivers coordinate system. | 177 // Returns where the text is drawn, in the receivers coordinate system. |
170 gfx::Rect GetTextBounds() const; | 178 gfx::Rect GetTextBounds() const; |
171 | 179 |
172 int ComputeDrawStringFlags() const; | 180 int ComputeDrawStringFlags() const; |
173 | 181 |
174 gfx::Rect GetAvailableRect() const; | 182 gfx::Rect GetAvailableRect() const; |
175 | 183 |
176 // Returns parameters to be used for the DrawString call. | 184 // Returns parameters to be used for the DrawString call. Returned value is a |
177 void CalculateDrawStringParams(base::string16* paint_text, | 185 // weak pointer, owned by and scoped to the label. |
178 gfx::Rect* text_bounds, | 186 const DrawStringParams* CalculateDrawStringParams() const; |
179 int* flags) const; | |
180 | 187 |
181 // Updates any colors that have not been explicitly set from the theme. | 188 // Updates any colors that have not been explicitly set from the theme. |
182 void UpdateColorsFromTheme(const ui::NativeTheme* theme); | 189 void UpdateColorsFromTheme(const ui::NativeTheme* theme); |
183 | 190 |
184 // Resets |cached_heights_| and |cached_heights_cursor_| and mark | 191 // Resets |cached_heights_|, |cached_heights_cursor_|, |cached_draw_params_| |
185 // |text_size_valid_| as false. | 192 // and mark |text_size_valid_| as false. |
186 void ResetCachedSize(); | 193 void ResetLayoutCache(); |
187 | 194 |
188 bool ShouldShowDefaultTooltip() const; | 195 bool ShouldShowDefaultTooltip() const; |
189 | 196 |
190 base::string16 text_; | 197 base::string16 text_; |
191 base::string16 layout_text_; | 198 base::string16 layout_text_; |
192 gfx::FontList font_list_; | 199 gfx::FontList font_list_; |
193 SkColor requested_enabled_color_; | 200 SkColor requested_enabled_color_; |
194 SkColor actual_enabled_color_; | 201 SkColor actual_enabled_color_; |
195 SkColor requested_disabled_color_; | 202 SkColor requested_disabled_color_; |
196 SkColor actual_disabled_color_; | 203 SkColor actual_disabled_color_; |
(...skipping 17 matching lines...) Expand all Loading... |
214 base::string16 tooltip_text_; | 221 base::string16 tooltip_text_; |
215 bool handles_tooltips_; | 222 bool handles_tooltips_; |
216 // Whether to collapse the label when it's not visible. | 223 // Whether to collapse the label when it's not visible. |
217 bool collapse_when_hidden_; | 224 bool collapse_when_hidden_; |
218 gfx::ShadowValues shadows_; | 225 gfx::ShadowValues shadows_; |
219 | 226 |
220 // The cached heights to avoid recalculation in GetHeightForWidth(). | 227 // The cached heights to avoid recalculation in GetHeightForWidth(). |
221 mutable std::vector<gfx::Size> cached_heights_; | 228 mutable std::vector<gfx::Size> cached_heights_; |
222 mutable int cached_heights_cursor_; | 229 mutable int cached_heights_cursor_; |
223 | 230 |
| 231 // The cached results of CalculateDrawStringParams(). |
| 232 mutable DrawStringParams cached_draw_params_; |
| 233 |
224 // TODO(vadimt): Remove is_first_paint_text_ before crbug.com/431326 is | 234 // TODO(vadimt): Remove is_first_paint_text_ before crbug.com/431326 is |
225 // closed. | 235 // closed. |
226 bool is_first_paint_text_; | 236 bool is_first_paint_text_; |
227 | 237 |
228 DISALLOW_COPY_AND_ASSIGN(Label); | 238 DISALLOW_COPY_AND_ASSIGN(Label); |
229 }; | 239 }; |
230 | 240 |
231 } // namespace views | 241 } // namespace views |
232 | 242 |
233 #endif // UI_VIEWS_CONTROLS_LABEL_H_ | 243 #endif // UI_VIEWS_CONTROLS_LABEL_H_ |
OLD | NEW |