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 309 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
320 return true; | 320 return true; |
321 } | 321 } |
322 | 322 |
323 return false; | 323 return false; |
324 } | 324 } |
325 | 325 |
326 void Label::OnEnabledChanged() { | 326 void Label::OnEnabledChanged() { |
327 RecalculateColors(); | 327 RecalculateColors(); |
328 } | 328 } |
329 | 329 |
| 330 scoped_ptr<gfx::RenderText> Label::CreateRenderText( |
| 331 const base::string16& text, |
| 332 gfx::HorizontalAlignment alignment, |
| 333 gfx::DirectionalityMode directionality, |
| 334 gfx::ElideBehavior elide_behavior) { |
| 335 scoped_ptr<gfx::RenderText> render_text( |
| 336 render_text_->CreateInstanceOfSameType()); |
| 337 render_text->SetHorizontalAlignment(alignment); |
| 338 render_text->SetDirectionalityMode(directionality); |
| 339 render_text->SetElideBehavior(elide_behavior); |
| 340 render_text->SetObscured(obscured()); |
| 341 render_text->SetMinLineHeight(line_height()); |
| 342 render_text->SetFontList(font_list()); |
| 343 render_text->set_shadows(shadows()); |
| 344 render_text->SetCursorEnabled(false); |
| 345 render_text->SetText(text); |
| 346 return render_text.Pass(); |
| 347 } |
| 348 |
330 void Label::PaintText(gfx::Canvas* canvas) { | 349 void Label::PaintText(gfx::Canvas* canvas) { |
331 MaybeBuildRenderTextLines(); | 350 MaybeBuildRenderTextLines(); |
332 for (size_t i = 0; i < lines_.size(); ++i) | 351 for (size_t i = 0; i < lines_.size(); ++i) |
333 lines_[i]->Draw(canvas); | 352 lines_[i]->Draw(canvas); |
334 } | 353 } |
335 | 354 |
336 void Label::OnBoundsChanged(const gfx::Rect& previous_bounds) { | 355 void Label::OnBoundsChanged(const gfx::Rect& previous_bounds) { |
337 if (previous_bounds.size() != size()) | 356 if (previous_bounds.size() != size()) |
338 InvalidateLayout(); | 357 InvalidateLayout(); |
339 } | 358 } |
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
399 SetText(text); | 418 SetText(text); |
400 } | 419 } |
401 | 420 |
402 void Label::ResetLayout() { | 421 void Label::ResetLayout() { |
403 InvalidateLayout(); | 422 InvalidateLayout(); |
404 PreferredSizeChanged(); | 423 PreferredSizeChanged(); |
405 SchedulePaint(); | 424 SchedulePaint(); |
406 lines_.clear(); | 425 lines_.clear(); |
407 } | 426 } |
408 | 427 |
409 scoped_ptr<gfx::RenderText> Label::CreateRenderText( | |
410 const base::string16& text, | |
411 gfx::HorizontalAlignment alignment, | |
412 gfx::DirectionalityMode directionality, | |
413 gfx::ElideBehavior elide_behavior) { | |
414 scoped_ptr<gfx::RenderText> render_text( | |
415 render_text_->CreateInstanceOfSameType()); | |
416 render_text->SetHorizontalAlignment(alignment); | |
417 render_text->SetDirectionalityMode(directionality); | |
418 render_text->SetElideBehavior(elide_behavior); | |
419 render_text->SetObscured(obscured()); | |
420 render_text->SetMinLineHeight(line_height()); | |
421 render_text->SetFontList(font_list()); | |
422 render_text->set_shadows(shadows()); | |
423 render_text->SetCursorEnabled(false); | |
424 render_text->SetText(text); | |
425 return render_text.Pass(); | |
426 } | |
427 | |
428 void Label::MaybeBuildRenderTextLines() { | 428 void Label::MaybeBuildRenderTextLines() { |
429 if (!lines_.empty()) | 429 if (!lines_.empty()) |
430 return; | 430 return; |
431 | 431 |
432 gfx::Rect rect = GetContentsBounds(); | 432 gfx::Rect rect = GetContentsBounds(); |
433 if (focusable()) | 433 if (focusable()) |
434 rect.Inset(kFocusBorderPadding, kFocusBorderPadding); | 434 rect.Inset(kFocusBorderPadding, kFocusBorderPadding); |
435 if (rect.IsEmpty()) | 435 if (rect.IsEmpty()) |
436 return; | 436 return; |
437 | 437 |
(...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
581 } | 581 } |
582 | 582 |
583 bool Label::ShouldShowDefaultTooltip() const { | 583 bool Label::ShouldShowDefaultTooltip() const { |
584 const gfx::Size text_size = GetTextSize(); | 584 const gfx::Size text_size = GetTextSize(); |
585 const gfx::Size size = GetContentsBounds().size(); | 585 const gfx::Size size = GetContentsBounds().size(); |
586 return !obscured() && (text_size.width() > size.width() || | 586 return !obscured() && (text_size.width() > size.width() || |
587 (multi_line() && text_size.height() > size.height())); | 587 (multi_line() && text_size.height() > size.height())); |
588 } | 588 } |
589 | 589 |
590 } // namespace views | 590 } // namespace views |
OLD | NEW |