Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(873)

Side by Side Diff: ui/views/controls/label.cc

Issue 1868363002: Replace scoped_ptr with std::unique_ptr in //ui (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@scopedptrcc
Patch Set: scopedptrui: rebase-make_scoped_ptr Created 4 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « ui/views/controls/label.h ('k') | ui/views/controls/label_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 <stddef.h> 7 #include <stddef.h>
8 8
9 #include <algorithm> 9 #include <algorithm>
10 #include <cmath> 10 #include <cmath>
(...skipping 317 matching lines...) Expand 10 before | Expand all | Expand 10 after
328 return true; 328 return true;
329 } 329 }
330 330
331 return false; 331 return false;
332 } 332 }
333 333
334 void Label::OnEnabledChanged() { 334 void Label::OnEnabledChanged() {
335 RecalculateColors(); 335 RecalculateColors();
336 } 336 }
337 337
338 scoped_ptr<gfx::RenderText> Label::CreateRenderText( 338 std::unique_ptr<gfx::RenderText> Label::CreateRenderText(
339 const base::string16& text, 339 const base::string16& text,
340 gfx::HorizontalAlignment alignment, 340 gfx::HorizontalAlignment alignment,
341 gfx::DirectionalityMode directionality, 341 gfx::DirectionalityMode directionality,
342 gfx::ElideBehavior elide_behavior) { 342 gfx::ElideBehavior elide_behavior) {
343 scoped_ptr<gfx::RenderText> render_text( 343 std::unique_ptr<gfx::RenderText> render_text(
344 render_text_->CreateInstanceOfSameType()); 344 render_text_->CreateInstanceOfSameType());
345 render_text->SetHorizontalAlignment(alignment); 345 render_text->SetHorizontalAlignment(alignment);
346 render_text->SetDirectionalityMode(directionality); 346 render_text->SetDirectionalityMode(directionality);
347 render_text->SetElideBehavior(elide_behavior); 347 render_text->SetElideBehavior(elide_behavior);
348 render_text->SetObscured(obscured()); 348 render_text->SetObscured(obscured());
349 render_text->SetMinLineHeight(line_height()); 349 render_text->SetMinLineHeight(line_height());
350 render_text->SetFontList(font_list()); 350 render_text->SetFontList(font_list());
351 render_text->set_shadows(shadows()); 351 render_text->set_shadows(shadows());
352 render_text->SetCursorEnabled(false); 352 render_text->SetCursorEnabled(false);
353 render_text->SetText(text); 353 render_text->SetText(text);
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after
451 alignment = rtl ? gfx::ALIGN_RIGHT : gfx::ALIGN_LEFT; 451 alignment = rtl ? gfx::ALIGN_RIGHT : gfx::ALIGN_LEFT;
452 directionality = 452 directionality =
453 rtl ? gfx::DIRECTIONALITY_FORCE_RTL : gfx::DIRECTIONALITY_FORCE_LTR; 453 rtl ? gfx::DIRECTIONALITY_FORCE_RTL : gfx::DIRECTIONALITY_FORCE_LTR;
454 } 454 }
455 455
456 // Text eliding is not supported for multi-lined Labels. 456 // Text eliding is not supported for multi-lined Labels.
457 // TODO(mukai): Add multi-lined elided text support. 457 // TODO(mukai): Add multi-lined elided text support.
458 gfx::ElideBehavior elide_behavior = 458 gfx::ElideBehavior elide_behavior =
459 multi_line() ? gfx::NO_ELIDE : elide_behavior_; 459 multi_line() ? gfx::NO_ELIDE : elide_behavior_;
460 if (!multi_line() || render_text_->MultilineSupported()) { 460 if (!multi_line() || render_text_->MultilineSupported()) {
461 scoped_ptr<gfx::RenderText> render_text = 461 std::unique_ptr<gfx::RenderText> render_text =
462 CreateRenderText(text(), alignment, directionality, elide_behavior); 462 CreateRenderText(text(), alignment, directionality, elide_behavior);
463 render_text->SetDisplayRect(rect); 463 render_text->SetDisplayRect(rect);
464 render_text->SetMultiline(multi_line()); 464 render_text->SetMultiline(multi_line());
465 render_text->SetWordWrapBehavior(render_text_->word_wrap_behavior()); 465 render_text->SetWordWrapBehavior(render_text_->word_wrap_behavior());
466 lines_.push_back(std::move(render_text)); 466 lines_.push_back(std::move(render_text));
467 } else { 467 } else {
468 std::vector<base::string16> lines = GetLinesForWidth(rect.width()); 468 std::vector<base::string16> lines = GetLinesForWidth(rect.width());
469 if (lines.size() > 1) 469 if (lines.size() > 1)
470 rect.set_height(std::max(line_height(), font_list().GetHeight())); 470 rect.set_height(std::max(line_height(), font_list().GetHeight()));
471 471
472 const int bottom = GetContentsBounds().bottom(); 472 const int bottom = GetContentsBounds().bottom();
473 for (size_t i = 0; i < lines.size() && rect.y() <= bottom; ++i) { 473 for (size_t i = 0; i < lines.size() && rect.y() <= bottom; ++i) {
474 scoped_ptr<gfx::RenderText> line = 474 std::unique_ptr<gfx::RenderText> line =
475 CreateRenderText(lines[i], alignment, directionality, elide_behavior); 475 CreateRenderText(lines[i], alignment, directionality, elide_behavior);
476 line->SetDisplayRect(rect); 476 line->SetDisplayRect(rect);
477 lines_.push_back(std::move(line)); 477 lines_.push_back(std::move(line));
478 rect.set_y(rect.y() + rect.height()); 478 rect.set_y(rect.y() + rect.height());
479 } 479 }
480 // Append the remaining text to the last visible line. 480 // Append the remaining text to the last visible line.
481 for (size_t i = lines_.size(); i < lines.size(); ++i) 481 for (size_t i = lines_.size(); i < lines.size(); ++i)
482 lines_.back()->SetText(lines_.back()->text() + lines[i]); 482 lines_.back()->SetText(lines_.back()->text() + lines[i]);
483 } 483 }
484 RecalculateColors(); 484 RecalculateColors();
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
528 // specified in GetHeightForWidth(), and specifying empty Rect cancels 528 // specified in GetHeightForWidth(), and specifying empty Rect cancels
529 // its effect. See also the comment in GetHeightForWidth(). 529 // its effect. See also the comment in GetHeightForWidth().
530 // TODO(mukai): use gfx::Rect() to compute the ideal size rather than 530 // TODO(mukai): use gfx::Rect() to compute the ideal size rather than
531 // the current width(). See crbug.com/468494, crbug.com/467526, and 531 // the current width(). See crbug.com/468494, crbug.com/467526, and
532 // the comment for MultilinePreferredSizeTest in label_unittest.cc. 532 // the comment for MultilinePreferredSizeTest in label_unittest.cc.
533 render_text_->SetDisplayRect(gfx::Rect(0, 0, width(), 0)); 533 render_text_->SetDisplayRect(gfx::Rect(0, 0, width(), 0));
534 size = render_text_->GetStringSize(); 534 size = render_text_->GetStringSize();
535 } else { 535 } else {
536 // Get the natural text size, unelided and only wrapped on newlines. 536 // Get the natural text size, unelided and only wrapped on newlines.
537 std::vector<base::string16> lines = GetLinesForWidth(width()); 537 std::vector<base::string16> lines = GetLinesForWidth(width());
538 scoped_ptr<gfx::RenderText> render_text(gfx::RenderText::CreateInstance()); 538 std::unique_ptr<gfx::RenderText> render_text(
539 gfx::RenderText::CreateInstance());
539 render_text->SetFontList(font_list()); 540 render_text->SetFontList(font_list());
540 for (size_t i = 0; i < lines.size(); ++i) { 541 for (size_t i = 0; i < lines.size(); ++i) {
541 render_text->SetText(lines[i]); 542 render_text->SetText(lines[i]);
542 const gfx::Size line = render_text->GetStringSize(); 543 const gfx::Size line = render_text->GetStringSize();
543 size.set_width(std::max(size.width(), line.width())); 544 size.set_width(std::max(size.width(), line.width()));
544 size.set_height(std::max(line_height(), size.height() + line.height())); 545 size.set_height(std::max(line_height(), size.height() + line.height()));
545 } 546 }
546 } 547 }
547 const gfx::Insets shadow_margin = -gfx::ShadowValue::GetMargin(shadows()); 548 const gfx::Insets shadow_margin = -gfx::ShadowValue::GetMargin(shadows());
548 size.Enlarge(shadow_margin.width(), shadow_margin.height()); 549 size.Enlarge(shadow_margin.width(), shadow_margin.height());
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
586 } 587 }
587 588
588 bool Label::ShouldShowDefaultTooltip() const { 589 bool Label::ShouldShowDefaultTooltip() const {
589 const gfx::Size text_size = GetTextSize(); 590 const gfx::Size text_size = GetTextSize();
590 const gfx::Size size = GetContentsBounds().size(); 591 const gfx::Size size = GetContentsBounds().size();
591 return !obscured() && (text_size.width() > size.width() || 592 return !obscured() && (text_size.width() > size.width() ||
592 (multi_line() && text_size.height() > size.height())); 593 (multi_line() && text_size.height() > size.height()));
593 } 594 }
594 595
595 } // namespace views 596 } // namespace views
OLDNEW
« no previous file with comments | « ui/views/controls/label.h ('k') | ui/views/controls/label_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698