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 int text_context() const { return text_context_; } |
| 232 |
233 // View: | 233 // View: |
234 void OnBoundsChanged(const gfx::Rect& previous_bounds) override; | 234 void OnBoundsChanged(const gfx::Rect& previous_bounds) override; |
235 void VisibilityChanged(View* starting_from, bool is_visible) override; | 235 void VisibilityChanged(View* starting_from, bool is_visible) override; |
236 void OnPaint(gfx::Canvas* canvas) override; | 236 void OnPaint(gfx::Canvas* canvas) override; |
237 void OnDeviceScaleFactorChanged(float device_scale_factor) override; | 237 void OnDeviceScaleFactorChanged(float device_scale_factor) override; |
238 void OnNativeThemeChanged(const ui::NativeTheme* theme) override; | 238 void OnNativeThemeChanged(const ui::NativeTheme* theme) override; |
239 gfx::NativeCursor GetCursor(const ui::MouseEvent& event) override; | 239 gfx::NativeCursor GetCursor(const ui::MouseEvent& event) override; |
240 void OnFocus() override; | 240 void OnFocus() override; |
241 void OnBlur() override; | 241 void OnBlur() override; |
242 bool OnMousePressed(const ui::MouseEvent& event) override; | 242 bool OnMousePressed(const ui::MouseEvent& event) override; |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
295 | 295 |
296 // Set up |lines_| to actually be painted. | 296 // Set up |lines_| to actually be painted. |
297 void MaybeBuildRenderTextLines() const; | 297 void MaybeBuildRenderTextLines() const; |
298 | 298 |
299 // Get the text broken into lines as needed to fit the given |width|. | 299 // Get the text broken into lines as needed to fit the given |width|. |
300 std::vector<base::string16> GetLinesForWidth(int width) const; | 300 std::vector<base::string16> GetLinesForWidth(int width) const; |
301 | 301 |
302 // Get the text size for the current layout. | 302 // Get the text size for the current layout. |
303 gfx::Size GetTextSize() const; | 303 gfx::Size GetTextSize() const; |
304 | 304 |
305 // Updates |actual_{enabled,disabled}_color_| from requested colors. | 305 // Updates text and selection colors from requested colors. |
306 void RecalculateColors(); | 306 void RecalculateColors(); |
307 | 307 |
308 // Applies |actual_{enabled,disabled}_color_| to |lines_|. | 308 // Applies the foreground color to |lines_|. |
309 void ApplyTextColors() const; | 309 void ApplyTextColors() const; |
310 | 310 |
311 // Updates any colors that have not been explicitly set from the theme. | 311 // Updates any colors that have not been explicitly set from the theme. |
312 void UpdateColorsFromTheme(const ui::NativeTheme* theme); | 312 void UpdateColorsFromTheme(const ui::NativeTheme* theme); |
313 | 313 |
314 bool ShouldShowDefaultTooltip() const; | 314 bool ShouldShowDefaultTooltip() const; |
315 | 315 |
316 // Empties |lines_| and updates |stored_selection_range_|. | 316 // Empties |lines_| and updates |stored_selection_range_|. |
317 void ClearRenderTextLines() const; | 317 void ClearRenderTextLines() const; |
318 | 318 |
(...skipping 16 matching lines...) Expand all Loading... |
335 // The RenderText instances used to display elided and multi-line text. | 335 // The RenderText instances used to display elided and multi-line text. |
336 mutable std::vector<std::unique_ptr<gfx::RenderText>> lines_; | 336 mutable std::vector<std::unique_ptr<gfx::RenderText>> lines_; |
337 | 337 |
338 // Persists the current selection range between the calls to | 338 // Persists the current selection range between the calls to |
339 // ClearRenderTextLines() and MaybeBuildRenderTextLines(). Holds an | 339 // ClearRenderTextLines() and MaybeBuildRenderTextLines(). Holds an |
340 // InvalidRange when not in use. | 340 // InvalidRange when not in use. |
341 mutable gfx::Range stored_selection_range_; | 341 mutable gfx::Range stored_selection_range_; |
342 | 342 |
343 SkColor requested_enabled_color_ = SK_ColorRED; | 343 SkColor requested_enabled_color_ = SK_ColorRED; |
344 SkColor actual_enabled_color_ = SK_ColorRED; | 344 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; | 345 SkColor background_color_ = SK_ColorRED; |
348 SkColor requested_selection_text_color_ = SK_ColorRED; | 346 SkColor requested_selection_text_color_ = SK_ColorRED; |
349 SkColor actual_selection_text_color_ = SK_ColorRED; | 347 SkColor actual_selection_text_color_ = SK_ColorRED; |
350 SkColor selection_background_color_ = SK_ColorRED; | 348 SkColor selection_background_color_ = SK_ColorRED; |
351 | 349 |
352 // Set to true once the corresponding setter is invoked. | 350 // Set to true once the corresponding setter is invoked. |
353 bool enabled_color_set_; | 351 bool enabled_color_set_; |
354 bool disabled_color_set_; | |
355 bool background_color_set_; | 352 bool background_color_set_; |
356 bool selection_text_color_set_; | 353 bool selection_text_color_set_; |
357 bool selection_background_color_set_; | 354 bool selection_background_color_set_; |
358 | 355 |
359 gfx::ElideBehavior elide_behavior_; | 356 gfx::ElideBehavior elide_behavior_; |
360 | 357 |
361 bool subpixel_rendering_enabled_; | 358 bool subpixel_rendering_enabled_; |
362 bool auto_color_readability_; | 359 bool auto_color_readability_; |
363 // TODO(mukai): remove |multi_line_| when all RenderText can render multiline. | 360 // TODO(mukai): remove |multi_line_| when all RenderText can render multiline. |
364 bool multi_line_; | 361 bool multi_line_; |
(...skipping 13 matching lines...) Expand all Loading... |
378 // Context menu related members. | 375 // Context menu related members. |
379 ui::SimpleMenuModel context_menu_contents_; | 376 ui::SimpleMenuModel context_menu_contents_; |
380 std::unique_ptr<views::MenuRunner> context_menu_runner_; | 377 std::unique_ptr<views::MenuRunner> context_menu_runner_; |
381 | 378 |
382 DISALLOW_COPY_AND_ASSIGN(Label); | 379 DISALLOW_COPY_AND_ASSIGN(Label); |
383 }; | 380 }; |
384 | 381 |
385 } // namespace views | 382 } // namespace views |
386 | 383 |
387 #endif // UI_VIEWS_CONTROLS_LABEL_H_ | 384 #endif // UI_VIEWS_CONTROLS_LABEL_H_ |
OLD | NEW |