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> |
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
94 } | 94 } |
95 | 95 |
96 void Label::SetShadowOffset(int x, int y) { | 96 void Label::SetShadowOffset(int x, int y) { |
97 shadow_offset_.SetPoint(x, y); | 97 shadow_offset_.SetPoint(x, y); |
98 } | 98 } |
99 | 99 |
100 void Label::ClearEmbellishing() { | 100 void Label::ClearEmbellishing() { |
101 has_shadow_ = false; | 101 has_shadow_ = false; |
102 } | 102 } |
103 | 103 |
104 void Label::SetHorizontalAlignment(Alignment alignment) { | 104 void Label::SetHorizontalAlignment(gfx::HorizontalAlignment alignment) { |
105 // If the View's UI layout is right-to-left and directionality_mode_ is | 105 // If the View's UI layout is right-to-left and directionality_mode_ is |
106 // USE_UI_DIRECTIONALITY, we need to flip the alignment so that the alignment | 106 // USE_UI_DIRECTIONALITY, we need to flip the alignment so that the alignment |
107 // settings take into account the text directionality. | 107 // settings take into account the text directionality. |
108 if (base::i18n::IsRTL() && (directionality_mode_ == USE_UI_DIRECTIONALITY) && | 108 if (base::i18n::IsRTL() && (directionality_mode_ == USE_UI_DIRECTIONALITY) && |
109 (alignment != ALIGN_CENTER)) | 109 (alignment != gfx::ALIGN_CENTER)) { |
110 alignment = (alignment == ALIGN_LEFT) ? ALIGN_RIGHT : ALIGN_LEFT; | 110 alignment = (alignment == gfx::ALIGN_LEFT) ? |
111 if (horiz_alignment_ != alignment) { | 111 gfx::ALIGN_RIGHT : gfx::ALIGN_LEFT; |
112 horiz_alignment_ = alignment; | 112 } |
| 113 if (horizontal_alignment_ != alignment) { |
| 114 horizontal_alignment_ = alignment; |
113 SchedulePaint(); | 115 SchedulePaint(); |
114 } | 116 } |
115 } | 117 } |
116 | 118 |
117 void Label::SetMultiLine(bool multi_line) { | 119 void Label::SetMultiLine(bool multi_line) { |
118 DCHECK(!multi_line || elide_behavior_ != ELIDE_IN_MIDDLE); | 120 DCHECK(!multi_line || elide_behavior_ != ELIDE_IN_MIDDLE); |
119 if (multi_line != is_multi_line_) { | 121 if (multi_line != is_multi_line_) { |
120 is_multi_line_ = multi_line; | 122 is_multi_line_ = multi_line; |
121 text_size_valid_ = false; | 123 text_size_valid_ = false; |
122 PreferredSizeChanged(); | 124 PreferredSizeChanged(); |
(...skipping 191 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
314 font_ = font; | 316 font_ = font; |
315 text_size_valid_ = false; | 317 text_size_valid_ = false; |
316 requested_enabled_color_ = ui::NativeTheme::instance()->GetSystemColor( | 318 requested_enabled_color_ = ui::NativeTheme::instance()->GetSystemColor( |
317 ui::NativeTheme::kColorId_LabelEnabledColor); | 319 ui::NativeTheme::kColorId_LabelEnabledColor); |
318 requested_disabled_color_ = ui::NativeTheme::instance()->GetSystemColor( | 320 requested_disabled_color_ = ui::NativeTheme::instance()->GetSystemColor( |
319 ui::NativeTheme::kColorId_LabelDisabledColor); | 321 ui::NativeTheme::kColorId_LabelDisabledColor); |
320 background_color_ = ui::NativeTheme::instance()->GetSystemColor( | 322 background_color_ = ui::NativeTheme::instance()->GetSystemColor( |
321 ui::NativeTheme::kColorId_LabelBackgroundColor); | 323 ui::NativeTheme::kColorId_LabelBackgroundColor); |
322 auto_color_readability_ = true; | 324 auto_color_readability_ = true; |
323 RecalculateColors(); | 325 RecalculateColors(); |
324 horiz_alignment_ = ALIGN_CENTER; | 326 horizontal_alignment_ = gfx::ALIGN_CENTER; |
325 is_multi_line_ = false; | 327 is_multi_line_ = false; |
326 allow_character_break_ = false; | 328 allow_character_break_ = false; |
327 elide_behavior_ = NO_ELIDE; | 329 elide_behavior_ = NO_ELIDE; |
328 collapse_when_hidden_ = false; | 330 collapse_when_hidden_ = false; |
329 directionality_mode_ = USE_UI_DIRECTIONALITY; | 331 directionality_mode_ = USE_UI_DIRECTIONALITY; |
330 has_focus_border_ = false; | 332 has_focus_border_ = false; |
331 enabled_shadow_color_ = 0; | 333 enabled_shadow_color_ = 0; |
332 disabled_shadow_color_ = 0; | 334 disabled_shadow_color_ = 0; |
333 shadow_offset_.SetPoint(1, 1); | 335 shadow_offset_.SetPoint(1, 1); |
334 has_shadow_ = false; | 336 has_shadow_ = false; |
(...skipping 12 matching lines...) Expand all Loading... |
347 requested_disabled_color_; | 349 requested_disabled_color_; |
348 } | 350 } |
349 | 351 |
350 gfx::Rect Label::GetTextBounds() const { | 352 gfx::Rect Label::GetTextBounds() const { |
351 gfx::Rect available_rect(GetAvailableRect()); | 353 gfx::Rect available_rect(GetAvailableRect()); |
352 gfx::Size text_size(GetTextSize()); | 354 gfx::Size text_size(GetTextSize()); |
353 text_size.set_width(std::min(available_rect.width(), text_size.width())); | 355 text_size.set_width(std::min(available_rect.width(), text_size.width())); |
354 | 356 |
355 gfx::Insets insets = GetInsets(); | 357 gfx::Insets insets = GetInsets(); |
356 gfx::Point text_origin(insets.left(), insets.top()); | 358 gfx::Point text_origin(insets.left(), insets.top()); |
357 switch (horiz_alignment_) { | 359 switch (horizontal_alignment_) { |
358 case ALIGN_LEFT: | 360 case gfx::ALIGN_LEFT: |
359 break; | 361 break; |
360 case ALIGN_CENTER: | 362 case gfx::ALIGN_CENTER: |
361 // We put any extra margin pixel on the left rather than the right. We | 363 // We put any extra margin pixel on the left rather than the right. We |
362 // used to do this because measurement on Windows used | 364 // used to do this because measurement on Windows used |
363 // GetTextExtentPoint32(), which could report a value one too large on the | 365 // GetTextExtentPoint32(), which could report a value one too large on the |
364 // right; we now use DrawText(), and who knows if it can also do this. | 366 // right; we now use DrawText(), and who knows if it can also do this. |
365 text_origin.Offset((available_rect.width() + 1 - text_size.width()) / 2, | 367 text_origin.Offset((available_rect.width() + 1 - text_size.width()) / 2, |
366 0); | 368 0); |
367 break; | 369 break; |
368 case ALIGN_RIGHT: | 370 case gfx::ALIGN_RIGHT: |
369 text_origin.set_x(available_rect.right() - text_size.width()); | 371 text_origin.set_x(available_rect.right() - text_size.width()); |
370 break; | 372 break; |
371 default: | 373 default: |
372 NOTREACHED(); | 374 NOTREACHED(); |
373 break; | 375 break; |
374 } | 376 } |
375 text_origin.Offset(0, | 377 text_origin.Offset(0, |
376 std::max(0, (available_rect.height() - text_size.height())) / 2); | 378 std::max(0, (available_rect.height() - text_size.height())) / 2); |
377 return gfx::Rect(text_origin, text_size); | 379 return gfx::Rect(text_origin, text_size); |
378 } | 380 } |
(...skipping 21 matching lines...) Expand all Loading... |
400 #if !defined(OS_WIN) | 402 #if !defined(OS_WIN) |
401 // Don't elide multiline labels on Linux. | 403 // Don't elide multiline labels on Linux. |
402 // Todo(davemoore): Do we depend on eliding multiline text? | 404 // Todo(davemoore): Do we depend on eliding multiline text? |
403 // Pango insists on limiting the number of lines to one if text is | 405 // Pango insists on limiting the number of lines to one if text is |
404 // elided. You can get around this if you can pass a maximum height | 406 // elided. You can get around this if you can pass a maximum height |
405 // but we don't currently have that data when we call the pango code. | 407 // but we don't currently have that data when we call the pango code. |
406 flags |= gfx::Canvas::NO_ELLIPSIS; | 408 flags |= gfx::Canvas::NO_ELLIPSIS; |
407 #endif | 409 #endif |
408 if (allow_character_break_) | 410 if (allow_character_break_) |
409 flags |= gfx::Canvas::CHARACTER_BREAK; | 411 flags |= gfx::Canvas::CHARACTER_BREAK; |
410 switch (horiz_alignment_) { | 412 switch (horizontal_alignment_) { |
411 case ALIGN_LEFT: | 413 case gfx::ALIGN_LEFT: |
412 flags |= gfx::Canvas::TEXT_ALIGN_LEFT; | 414 flags |= gfx::Canvas::TEXT_ALIGN_LEFT; |
413 break; | 415 break; |
414 case ALIGN_CENTER: | 416 case gfx::ALIGN_CENTER: |
415 flags |= gfx::Canvas::TEXT_ALIGN_CENTER; | 417 flags |= gfx::Canvas::TEXT_ALIGN_CENTER; |
416 break; | 418 break; |
417 case ALIGN_RIGHT: | 419 case gfx::ALIGN_RIGHT: |
418 flags |= gfx::Canvas::TEXT_ALIGN_RIGHT; | 420 flags |= gfx::Canvas::TEXT_ALIGN_RIGHT; |
419 break; | 421 break; |
420 } | 422 } |
421 | 423 |
422 return flags; | 424 return flags; |
423 } | 425 } |
424 | 426 |
425 gfx::Rect Label::GetAvailableRect() const { | 427 gfx::Rect Label::GetAvailableRect() const { |
426 gfx::Rect bounds(size()); | 428 gfx::Rect bounds(size()); |
427 bounds.Inset(GetInsets()); | 429 bounds.Inset(GetInsets()); |
(...skipping 16 matching lines...) Expand all Loading... |
444 ui::ELIDE_AT_END); | 446 ui::ELIDE_AT_END); |
445 } else { | 447 } else { |
446 *paint_text = text_; | 448 *paint_text = text_; |
447 } | 449 } |
448 | 450 |
449 *text_bounds = GetTextBounds(); | 451 *text_bounds = GetTextBounds(); |
450 *flags = ComputeDrawStringFlags(); | 452 *flags = ComputeDrawStringFlags(); |
451 } | 453 } |
452 | 454 |
453 } // namespace views | 455 } // namespace views |
OLD | NEW |