| 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 "ash/system/user/tray_user.h" | 5 #include "ash/system/user/tray_user.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 #include <climits> | 8 #include <climits> |
| 9 #include <vector> | 9 #include <vector> |
| 10 | 10 |
| (...skipping 522 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 533 } | 533 } |
| 534 | 534 |
| 535 void PublicAccountUserDetails::CalculatePreferredSize(SystemTrayItem* owner, | 535 void PublicAccountUserDetails::CalculatePreferredSize(SystemTrayItem* owner, |
| 536 int used_width) { | 536 int used_width) { |
| 537 const gfx::Font font; | 537 const gfx::Font font; |
| 538 const gfx::Size link_size = learn_more_->GetPreferredSize(); | 538 const gfx::Size link_size = learn_more_->GetPreferredSize(); |
| 539 const int space_width = font.GetStringWidth(ASCIIToUTF16(" ")); | 539 const int space_width = font.GetStringWidth(ASCIIToUTF16(" ")); |
| 540 const gfx::Insets insets = GetInsets(); | 540 const gfx::Insets insets = GetInsets(); |
| 541 views::TrayBubbleView* bubble_view = | 541 views::TrayBubbleView* bubble_view = |
| 542 owner->system_tray()->GetSystemBubble()->bubble_view(); | 542 owner->system_tray()->GetSystemBubble()->bubble_view(); |
| 543 int min_width = std::max( | 543 float min_width = std::max( |
| 544 link_size.width(), | 544 link_size.width(), |
| 545 bubble_view->GetPreferredSize().width() - (used_width + insets.width())); | 545 bubble_view->GetPreferredSize().width() - (used_width + insets.width())); |
| 546 int max_width = std::min( | 546 float max_width = std::min<float>( |
| 547 font.GetStringWidth(text_) + space_width + link_size.width(), | 547 font.GetStringWidth(text_) + space_width + link_size.width(), |
| 548 bubble_view->GetMaximumSize().width() - (used_width + insets.width())); | 548 bubble_view->GetMaximumSize().width() - (used_width + insets.width())); |
| 549 // Do a binary search for the minimum width that ensures no more than three | 549 // Do a binary search for the minimum width that ensures no more than three |
| 550 // lines are needed. The lower bound is the minimum of the current bubble | 550 // lines are needed. The lower bound is the minimum of the current bubble |
| 551 // width and the width of the link (as no wrapping is permitted inside the | 551 // width and the width of the link (as no wrapping is permitted inside the |
| 552 // link). The upper bound is the maximum of the largest allowed bubble width | 552 // link). The upper bound is the maximum of the largest allowed bubble width |
| 553 // and the sum of the label text and link widths when put on a single line. | 553 // and the sum of the label text and link widths when put on a single line. |
| 554 std::vector<base::string16> lines; | 554 std::vector<base::string16> lines; |
| 555 while (min_width < max_width) { | 555 while (min_width < max_width) { |
| 556 lines.clear(); | 556 lines.clear(); |
| 557 const int width = (min_width + max_width) / 2; | 557 const float width = (min_width + max_width) / 2; |
| 558 const bool too_narrow = gfx::ElideRectangleText( | 558 const bool too_narrow = gfx::ElideRectangleText( |
| 559 text_, font, width, INT_MAX, gfx::TRUNCATE_LONG_WORDS, &lines) != 0; | 559 text_, font, width, FLT_MAX, gfx::TRUNCATE_LONG_WORDS, &lines) != 0; |
| 560 int line_count = lines.size(); | 560 int line_count = lines.size(); |
| 561 if (!too_narrow && line_count == 3 && | 561 if (!too_narrow && line_count == 3 && |
| 562 width - font.GetStringWidth(lines.back()) <= | 562 width - font.GetStringWidth(lines.back()) <= |
| 563 space_width + link_size.width()) { | 563 space_width + link_size.width()) { |
| 564 ++line_count; | 564 ++line_count; |
| 565 } | 565 } |
| 566 if (too_narrow || line_count > 3) | 566 if (too_narrow || line_count > 3) |
| 567 min_width = width + 1; | 567 min_width = width + 1; |
| 568 else | 568 else |
| 569 max_width = width; | 569 max_width = width; |
| 570 } | 570 } |
| 571 | 571 |
| 572 // Calculate the corresponding height and set the preferred size. | 572 // Calculate the corresponding height and set the preferred size. |
| 573 lines.clear(); | 573 lines.clear(); |
| 574 gfx::ElideRectangleText( | 574 gfx::ElideRectangleText( |
| 575 text_, font, min_width, INT_MAX, gfx::TRUNCATE_LONG_WORDS, &lines); | 575 text_, font, min_width, FLT_MAX, gfx::TRUNCATE_LONG_WORDS, &lines); |
| 576 int line_count = lines.size(); | 576 int line_count = lines.size(); |
| 577 if (min_width - font.GetStringWidth(lines.back()) <= | 577 if (min_width - font.GetStringWidth(lines.back()) <= |
| 578 space_width + link_size.width()) { | 578 space_width + link_size.width()) { |
| 579 ++line_count; | 579 ++line_count; |
| 580 } | 580 } |
| 581 const int line_height = font.GetHeight(); | 581 const int line_height = font.GetHeight(); |
| 582 const int link_extra_height = std::max( | 582 const int link_extra_height = std::max( |
| 583 link_size.height() - learn_more_->GetInsets().top() - line_height, 0); | 583 link_size.height() - learn_more_->GetInsets().top() - line_height, 0); |
| 584 preferred_size_ = gfx::Size( | 584 preferred_size_ = gfx::Size( |
| 585 min_width + insets.width(), | 585 std::ceil(min_width + insets.width()), |
| 586 line_count * line_height + link_extra_height + insets.height()); | 586 line_count * line_height + link_extra_height + insets.height()); |
| 587 | 587 |
| 588 bubble_view->SetWidth(preferred_size_.width() + used_width); | 588 bubble_view->SetWidth(preferred_size_.width() + used_width); |
| 589 } | 589 } |
| 590 | 590 |
| 591 UserCard::UserCard(views::ButtonListener* listener, bool active_user) | 591 UserCard::UserCard(views::ButtonListener* listener, bool active_user) |
| 592 : CustomButton(listener), | 592 : CustomButton(listener), |
| 593 is_active_user_(active_user), | 593 is_active_user_(active_user), |
| 594 button_hovered_(false), | 594 button_hovered_(false), |
| 595 show_border_(false) { | 595 show_border_(false) { |
| (...skipping 699 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1295 kUserIconLargeSize : kUserIconSize; | 1295 kUserIconLargeSize : kUserIconSize; |
| 1296 | 1296 |
| 1297 avatar_->SetImage( | 1297 avatar_->SetImage( |
| 1298 ash::Shell::GetInstance()->session_state_delegate()->GetUserImage( | 1298 ash::Shell::GetInstance()->session_state_delegate()->GetUserImage( |
| 1299 multiprofile_index_), | 1299 multiprofile_index_), |
| 1300 gfx::Size(icon_size, icon_size)); | 1300 gfx::Size(icon_size, icon_size)); |
| 1301 } | 1301 } |
| 1302 | 1302 |
| 1303 } // namespace internal | 1303 } // namespace internal |
| 1304 } // namespace ash | 1304 } // namespace ash |
| OLD | NEW |