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 "base/compiler_specific.h" | 8 #include "base/compiler_specific.h" |
9 #include "base/gtest_prod_util.h" | 9 #include "base/gtest_prod_util.h" |
10 #include "base/macros.h" | 10 #include "base/macros.h" |
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
75 | 75 |
76 // Enables or disables auto-color-readability (enabled by default). If this | 76 // Enables or disables auto-color-readability (enabled by default). If this |
77 // is enabled, then calls to set any foreground or background color will | 77 // is enabled, then calls to set any foreground or background color will |
78 // trigger an automatic mapper that uses color_utils::GetReadableColor() to | 78 // trigger an automatic mapper that uses color_utils::GetReadableColor() to |
79 // ensure that the foreground colors are readable over the background color. | 79 // ensure that the foreground colors are readable over the background color. |
80 void SetAutoColorReadabilityEnabled(bool enabled); | 80 void SetAutoColorReadabilityEnabled(bool enabled); |
81 | 81 |
82 // Sets the color. This will automatically force the color to be readable | 82 // Sets the color. This will automatically force the color to be readable |
83 // over the current background color, if auto color readability is enabled. | 83 // over the current background color, if auto color readability is enabled. |
84 virtual void SetEnabledColor(SkColor color); | 84 virtual void SetEnabledColor(SkColor color); |
85 void SetDisabledColorForLabelButton(SkColor color); | |
86 | 85 |
87 SkColor enabled_color() const { return actual_enabled_color_; } | 86 SkColor enabled_color() const { return actual_enabled_color_; } |
88 | 87 |
89 // Sets the background color. This won't be explicitly drawn, but the label | 88 // Sets the background color. This won't be explicitly drawn, but the label |
90 // will force the text color to be readable over it. | 89 // will force the text color to be readable over it. |
91 void SetBackgroundColor(SkColor color); | 90 void SetBackgroundColor(SkColor color); |
92 SkColor background_color() const { return background_color_; } | 91 SkColor background_color() const { return background_color_; } |
93 | 92 |
94 // Sets the selection text color. This will automatically force the color to | 93 // Sets the selection text color. This will automatically force the color to |
95 // be readable over the selection background color, if auto color readability | 94 // be readable over the selection background color, if auto color readability |
(...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
207 gfx::Size GetMinimumSize() const override; | 206 gfx::Size GetMinimumSize() const override; |
208 int GetHeightForWidth(int w) const override; | 207 int GetHeightForWidth(int w) const override; |
209 void Layout() override; | 208 void Layout() override; |
210 const char* GetClassName() const override; | 209 const char* GetClassName() const override; |
211 View* GetTooltipHandlerForPoint(const gfx::Point& point) override; | 210 View* GetTooltipHandlerForPoint(const gfx::Point& point) override; |
212 bool CanProcessEventsWithinSubtree() const override; | 211 bool CanProcessEventsWithinSubtree() const override; |
213 WordLookupClient* GetWordLookupClient() override; | 212 WordLookupClient* GetWordLookupClient() override; |
214 void GetAccessibleNodeData(ui::AXNodeData* node_data) override; | 213 void GetAccessibleNodeData(ui::AXNodeData* node_data) override; |
215 bool GetTooltipText(const gfx::Point& p, | 214 bool GetTooltipText(const gfx::Point& p, |
216 base::string16* tooltip) const override; | 215 base::string16* tooltip) const override; |
217 void OnEnabledChanged() override; | |
218 | 216 |
219 protected: | 217 protected: |
220 // Create a single RenderText instance to actually be painted. | 218 // Create a single RenderText instance to actually be painted. |
221 virtual std::unique_ptr<gfx::RenderText> CreateRenderText( | 219 virtual std::unique_ptr<gfx::RenderText> CreateRenderText( |
222 const base::string16& text, | 220 const base::string16& text, |
223 gfx::HorizontalAlignment alignment, | 221 gfx::HorizontalAlignment alignment, |
224 gfx::DirectionalityMode directionality, | 222 gfx::DirectionalityMode directionality, |
225 gfx::ElideBehavior elide_behavior) const; | 223 gfx::ElideBehavior elide_behavior) const; |
226 | 224 |
227 // Draw a focus ring. The default implementation does nothing. | 225 // Draw a focus ring. The default implementation does nothing. |
228 virtual void PaintFocusRing(gfx::Canvas* canvas) const; | 226 virtual void PaintFocusRing(gfx::Canvas* canvas) const; |
229 gfx::Rect GetFocusRingBounds() const; | 227 gfx::Rect GetFocusRingBounds() const; |
230 | 228 |
231 void PaintText(gfx::Canvas* canvas); | 229 void PaintText(gfx::Canvas* canvas); |
232 | 230 |
231 // Returns a color that is readable against the current background color; | |
232 SkColor EnsureTextColorReadable(SkColor color) const; | |
233 | |
234 // Returns the color to use for foreground text. | |
235 virtual SkColor GetForegroundColor() const; | |
sky
2017/06/06 17:12:24
I would prefer not to have this virtual. With this
tapted
2017/06/08 04:11:32
Done. Also added a test (seemed almost too simple
| |
236 | |
237 // Called when the background color changes. | |
238 virtual void OnBackgroundColorChanged(); | |
239 | |
240 // Applies the foreground color to |lines_|. | |
241 void ApplyTextColors() const; | |
242 | |
243 int text_context() const { return text_context_; } | |
244 | |
233 // View: | 245 // View: |
234 void OnBoundsChanged(const gfx::Rect& previous_bounds) override; | 246 void OnBoundsChanged(const gfx::Rect& previous_bounds) override; |
235 void VisibilityChanged(View* starting_from, bool is_visible) override; | 247 void VisibilityChanged(View* starting_from, bool is_visible) override; |
236 void OnPaint(gfx::Canvas* canvas) override; | 248 void OnPaint(gfx::Canvas* canvas) override; |
237 void OnDeviceScaleFactorChanged(float device_scale_factor) override; | 249 void OnDeviceScaleFactorChanged(float device_scale_factor) override; |
238 void OnNativeThemeChanged(const ui::NativeTheme* theme) override; | 250 void OnNativeThemeChanged(const ui::NativeTheme* theme) override; |
239 gfx::NativeCursor GetCursor(const ui::MouseEvent& event) override; | 251 gfx::NativeCursor GetCursor(const ui::MouseEvent& event) override; |
240 void OnFocus() override; | 252 void OnFocus() override; |
241 void OnBlur() override; | 253 void OnBlur() override; |
242 bool OnMousePressed(const ui::MouseEvent& event) override; | 254 bool OnMousePressed(const ui::MouseEvent& event) override; |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
295 | 307 |
296 // Set up |lines_| to actually be painted. | 308 // Set up |lines_| to actually be painted. |
297 void MaybeBuildRenderTextLines() const; | 309 void MaybeBuildRenderTextLines() const; |
298 | 310 |
299 // Get the text broken into lines as needed to fit the given |width|. | 311 // Get the text broken into lines as needed to fit the given |width|. |
300 std::vector<base::string16> GetLinesForWidth(int width) const; | 312 std::vector<base::string16> GetLinesForWidth(int width) const; |
301 | 313 |
302 // Get the text size for the current layout. | 314 // Get the text size for the current layout. |
303 gfx::Size GetTextSize() const; | 315 gfx::Size GetTextSize() const; |
304 | 316 |
305 // Updates |actual_{enabled,disabled}_color_| from requested colors. | 317 // Updates text and selection colors from requested colors. |
306 void RecalculateColors(); | 318 void RecalculateColors(); |
307 | 319 |
308 // Applies |actual_{enabled,disabled}_color_| to |lines_|. | |
309 void ApplyTextColors() const; | |
310 | |
311 // Updates any colors that have not been explicitly set from the theme. | 320 // Updates any colors that have not been explicitly set from the theme. |
312 void UpdateColorsFromTheme(const ui::NativeTheme* theme); | 321 void UpdateColorsFromTheme(const ui::NativeTheme* theme); |
313 | 322 |
314 bool ShouldShowDefaultTooltip() const; | 323 bool ShouldShowDefaultTooltip() const; |
315 | 324 |
316 // Empties |lines_| and updates |stored_selection_range_|. | 325 // Empties |lines_| and updates |stored_selection_range_|. |
317 void ClearRenderTextLines() const; | 326 void ClearRenderTextLines() const; |
318 | 327 |
319 // Returns the currently selected text. | 328 // Returns the currently selected text. |
320 base::string16 GetSelectedText() const; | 329 base::string16 GetSelectedText() const; |
(...skipping 14 matching lines...) Expand all Loading... | |
335 // The RenderText instances used to display elided and multi-line text. | 344 // The RenderText instances used to display elided and multi-line text. |
336 mutable std::vector<std::unique_ptr<gfx::RenderText>> lines_; | 345 mutable std::vector<std::unique_ptr<gfx::RenderText>> lines_; |
337 | 346 |
338 // Persists the current selection range between the calls to | 347 // Persists the current selection range between the calls to |
339 // ClearRenderTextLines() and MaybeBuildRenderTextLines(). Holds an | 348 // ClearRenderTextLines() and MaybeBuildRenderTextLines(). Holds an |
340 // InvalidRange when not in use. | 349 // InvalidRange when not in use. |
341 mutable gfx::Range stored_selection_range_; | 350 mutable gfx::Range stored_selection_range_; |
342 | 351 |
343 SkColor requested_enabled_color_ = SK_ColorRED; | 352 SkColor requested_enabled_color_ = SK_ColorRED; |
344 SkColor actual_enabled_color_ = SK_ColorRED; | 353 SkColor actual_enabled_color_ = SK_ColorRED; |
345 SkColor requested_disabled_color_ = SK_ColorRED; | |
346 SkColor actual_disabled_color_ = SK_ColorRED; | |
347 SkColor background_color_ = SK_ColorRED; | 354 SkColor background_color_ = SK_ColorRED; |
348 SkColor requested_selection_text_color_ = SK_ColorRED; | 355 SkColor requested_selection_text_color_ = SK_ColorRED; |
349 SkColor actual_selection_text_color_ = SK_ColorRED; | 356 SkColor actual_selection_text_color_ = SK_ColorRED; |
350 SkColor selection_background_color_ = SK_ColorRED; | 357 SkColor selection_background_color_ = SK_ColorRED; |
351 | 358 |
352 // Set to true once the corresponding setter is invoked. | 359 // Set to true once the corresponding setter is invoked. |
353 bool enabled_color_set_; | 360 bool enabled_color_set_; |
354 bool disabled_color_set_; | |
355 bool background_color_set_; | 361 bool background_color_set_; |
356 bool selection_text_color_set_; | 362 bool selection_text_color_set_; |
357 bool selection_background_color_set_; | 363 bool selection_background_color_set_; |
358 | 364 |
359 gfx::ElideBehavior elide_behavior_; | 365 gfx::ElideBehavior elide_behavior_; |
360 | 366 |
361 bool subpixel_rendering_enabled_; | 367 bool subpixel_rendering_enabled_; |
362 bool auto_color_readability_; | 368 bool auto_color_readability_; |
363 // TODO(mukai): remove |multi_line_| when all RenderText can render multiline. | 369 // TODO(mukai): remove |multi_line_| when all RenderText can render multiline. |
364 bool multi_line_; | 370 bool multi_line_; |
(...skipping 13 matching lines...) Expand all Loading... | |
378 // Context menu related members. | 384 // Context menu related members. |
379 ui::SimpleMenuModel context_menu_contents_; | 385 ui::SimpleMenuModel context_menu_contents_; |
380 std::unique_ptr<views::MenuRunner> context_menu_runner_; | 386 std::unique_ptr<views::MenuRunner> context_menu_runner_; |
381 | 387 |
382 DISALLOW_COPY_AND_ASSIGN(Label); | 388 DISALLOW_COPY_AND_ASSIGN(Label); |
383 }; | 389 }; |
384 | 390 |
385 } // namespace views | 391 } // namespace views |
386 | 392 |
387 #endif // UI_VIEWS_CONTROLS_LABEL_H_ | 393 #endif // UI_VIEWS_CONTROLS_LABEL_H_ |
OLD | NEW |