Chromium Code Reviews| 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 base::string16 text; | |
| 154 gfx::Rect bounds; | |
| 155 int flags; | |
| 156 | |
| 157 DrawStringParams() : flags(0) {} | |
| 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. |
| 177 void CalculateDrawStringParams(base::string16* paint_text, | 185 const DrawStringParams* CalculateDrawStringParams() const; |
| 178 gfx::Rect* text_bounds, | |
| 179 int* flags) const; | |
| 180 | 186 |
| 181 // Updates any colors that have not been explicitly set from the theme. | 187 // Updates any colors that have not been explicitly set from the theme. |
| 182 void UpdateColorsFromTheme(const ui::NativeTheme* theme); | 188 void UpdateColorsFromTheme(const ui::NativeTheme* theme); |
| 183 | 189 |
| 184 // Resets |cached_heights_| and |cached_heights_cursor_| and mark | 190 // Resets |cached_heights_|, |cached_heights_cursor_|, |cached_paint_params_| |
|
msw
2015/01/07 20:35:56
Do you mean |cached_draw_params_|?
ckocagil
2015/01/07 22:55:08
Yes, done. (leftovers from a rename...)
| |
| 185 // |text_size_valid_| as false. | 191 // and mark |text_size_valid_| as false. |
| 186 void ResetCachedSize(); | 192 void ResetLayoutCache(); |
| 187 | 193 |
| 188 bool ShouldShowDefaultTooltip() const; | 194 bool ShouldShowDefaultTooltip() const; |
| 189 | 195 |
| 190 base::string16 text_; | 196 base::string16 text_; |
| 191 base::string16 layout_text_; | 197 base::string16 layout_text_; |
| 192 gfx::FontList font_list_; | 198 gfx::FontList font_list_; |
| 193 SkColor requested_enabled_color_; | 199 SkColor requested_enabled_color_; |
| 194 SkColor actual_enabled_color_; | 200 SkColor actual_enabled_color_; |
| 195 SkColor requested_disabled_color_; | 201 SkColor requested_disabled_color_; |
| 196 SkColor actual_disabled_color_; | 202 SkColor actual_disabled_color_; |
| (...skipping 17 matching lines...) Expand all Loading... | |
| 214 base::string16 tooltip_text_; | 220 base::string16 tooltip_text_; |
| 215 bool handles_tooltips_; | 221 bool handles_tooltips_; |
| 216 // Whether to collapse the label when it's not visible. | 222 // Whether to collapse the label when it's not visible. |
| 217 bool collapse_when_hidden_; | 223 bool collapse_when_hidden_; |
| 218 gfx::ShadowValues shadows_; | 224 gfx::ShadowValues shadows_; |
| 219 | 225 |
| 220 // The cached heights to avoid recalculation in GetHeightForWidth(). | 226 // The cached heights to avoid recalculation in GetHeightForWidth(). |
| 221 mutable std::vector<gfx::Size> cached_heights_; | 227 mutable std::vector<gfx::Size> cached_heights_; |
| 222 mutable int cached_heights_cursor_; | 228 mutable int cached_heights_cursor_; |
| 223 | 229 |
| 230 // The cached results of CalculateDrawStringParams(). | |
| 231 mutable scoped_ptr<const DrawStringParams> cached_draw_params_; | |
| 232 | |
| 224 // TODO(vadimt): Remove is_first_paint_text_ before crbug.com/431326 is | 233 // TODO(vadimt): Remove is_first_paint_text_ before crbug.com/431326 is |
| 225 // closed. | 234 // closed. |
| 226 bool is_first_paint_text_; | 235 bool is_first_paint_text_; |
| 227 | 236 |
| 228 DISALLOW_COPY_AND_ASSIGN(Label); | 237 DISALLOW_COPY_AND_ASSIGN(Label); |
| 229 }; | 238 }; |
| 230 | 239 |
| 231 } // namespace views | 240 } // namespace views |
| 232 | 241 |
| 233 #endif // UI_VIEWS_CONTROLS_LABEL_H_ | 242 #endif // UI_VIEWS_CONTROLS_LABEL_H_ |
| OLD | NEW |