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 #include "ui/views/controls/label.h" | 5 #include "ui/views/controls/label.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 #include <cmath> | 8 #include <cmath> |
9 #include <limits> | 9 #include <limits> |
10 #include <vector> | 10 #include <vector> |
11 | 11 |
12 #include "base/i18n/rtl.h" | 12 #include "base/i18n/rtl.h" |
13 #include "base/logging.h" | 13 #include "base/logging.h" |
14 #include "base/string_split.h" | 14 #include "base/string_split.h" |
15 #include "base/string_util.h" | 15 #include "base/string_util.h" |
16 #include "base/utf_string_conversions.h" | 16 #include "base/utf_string_conversions.h" |
17 #include "ui/base/accessibility/accessible_view_state.h" | 17 #include "ui/base/accessibility/accessible_view_state.h" |
18 #include "ui/base/resource/resource_bundle.h" | 18 #include "ui/base/resource/resource_bundle.h" |
19 #include "ui/base/text/text_elider.h" | 19 #include "ui/base/text/text_elider.h" |
20 #include "ui/gfx/canvas.h" | 20 #include "ui/gfx/canvas.h" |
21 #include "ui/gfx/color_utils.h" | 21 #include "ui/gfx/color_utils.h" |
22 #include "ui/gfx/font.h" | 22 #include "ui/gfx/font.h" |
23 #include "ui/gfx/insets.h" | 23 #include "ui/gfx/insets.h" |
24 #include "ui/gfx/native_theme.h" | |
24 #include "ui/views/background.h" | 25 #include "ui/views/background.h" |
25 | 26 |
26 namespace views { | 27 namespace views { |
27 | 28 |
28 // static | 29 // static |
29 const char Label::kViewClassName[] = "views/Label"; | 30 const char Label::kViewClassName[] = "views/Label"; |
30 | 31 |
31 const int Label::kFocusBorderPadding = 1; | 32 const int Label::kFocusBorderPadding = 1; |
32 | 33 |
33 Label::Label() { | 34 Label::Label() { |
(...skipping 319 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
353 gfx::Font Label::GetDefaultFont() { | 354 gfx::Font Label::GetDefaultFont() { |
354 return ResourceBundle::GetSharedInstance().GetFont(ResourceBundle::BaseFont); | 355 return ResourceBundle::GetSharedInstance().GetFont(ResourceBundle::BaseFont); |
355 } | 356 } |
356 | 357 |
357 void Label::Init(const string16& text, const gfx::Font& font) { | 358 void Label::Init(const string16& text, const gfx::Font& font) { |
358 static bool initialized = false; | 359 static bool initialized = false; |
359 static SkColor kDefaultEnabledColor; | 360 static SkColor kDefaultEnabledColor; |
360 static SkColor kDefaultDisabledColor; | 361 static SkColor kDefaultDisabledColor; |
361 static SkColor kDefaultBackgroundColor; | 362 static SkColor kDefaultBackgroundColor; |
362 if (!initialized) { | 363 if (!initialized) { |
363 #if defined(OS_WIN) | 364 kDefaultEnabledColor = gfx::NativeTheme::instance()->GetSystemColor( |
sky
2012/04/30 20:52:05
Do we really need to cache these values here and i
jennyz
2012/04/30 21:23:09
Done.
| |
364 kDefaultEnabledColor = color_utils::GetSysSkColor(COLOR_WINDOWTEXT); | 365 gfx::NativeTheme::kColorId_LabelEnabledColor); |
365 kDefaultDisabledColor = color_utils::GetSysSkColor(COLOR_GRAYTEXT); | 366 kDefaultDisabledColor = gfx::NativeTheme::instance()->GetSystemColor( |
366 kDefaultBackgroundColor = color_utils::GetSysSkColor(COLOR_WINDOW); | 367 gfx::NativeTheme::kColorId_LabelDisabledColor); |
367 #else | 368 kDefaultBackgroundColor = gfx::NativeTheme::instance()->GetSystemColor( |
368 // TODO(beng): source from theme provider. | 369 gfx::NativeTheme::kColorId_LabelBackgroundColor); |
369 kDefaultEnabledColor = SK_ColorBLACK; | |
370 kDefaultDisabledColor = SK_ColorGRAY; | |
371 kDefaultBackgroundColor = SK_ColorWHITE; | |
372 #endif | |
373 | |
374 initialized = true; | 370 initialized = true; |
375 } | 371 } |
376 | 372 |
377 contains_mouse_ = false; | 373 contains_mouse_ = false; |
378 font_ = font; | 374 font_ = font; |
379 text_size_valid_ = false; | 375 text_size_valid_ = false; |
380 requested_enabled_color_ = kDefaultEnabledColor; | 376 requested_enabled_color_ = kDefaultEnabledColor; |
381 requested_disabled_color_ = kDefaultDisabledColor; | 377 requested_disabled_color_ = kDefaultDisabledColor; |
382 background_color_ = kDefaultBackgroundColor; | 378 background_color_ = kDefaultBackgroundColor; |
383 auto_color_readability_ = true; | 379 auto_color_readability_ = true; |
(...skipping 149 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
533 ui::ELIDE_IN_MIDDLE); | 529 ui::ELIDE_IN_MIDDLE); |
534 } else { | 530 } else { |
535 *paint_text = text_; | 531 *paint_text = text_; |
536 } | 532 } |
537 | 533 |
538 *text_bounds = GetTextBounds(); | 534 *text_bounds = GetTextBounds(); |
539 *flags = ComputeDrawStringFlags(); | 535 *flags = ComputeDrawStringFlags(); |
540 } | 536 } |
541 | 537 |
542 } // namespace views | 538 } // namespace views |
OLD | NEW |