| 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 524 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 535 int used_width) { | 535 int used_width) { |
| 536 const gfx::Font font; | 536 const gfx::Font font; |
| 537 const gfx::Size link_size = learn_more_->GetPreferredSize(); | 537 const gfx::Size link_size = learn_more_->GetPreferredSize(); |
| 538 const int space_width = font.GetStringWidth(ASCIIToUTF16(" ")); | 538 const int space_width = font.GetStringWidth(ASCIIToUTF16(" ")); |
| 539 const gfx::Insets insets = GetInsets(); | 539 const gfx::Insets insets = GetInsets(); |
| 540 views::TrayBubbleView* bubble_view = | 540 views::TrayBubbleView* bubble_view = |
| 541 owner->system_tray()->GetSystemBubble()->bubble_view(); | 541 owner->system_tray()->GetSystemBubble()->bubble_view(); |
| 542 int min_width = std::max( | 542 int min_width = std::max( |
| 543 link_size.width(), | 543 link_size.width(), |
| 544 bubble_view->GetPreferredSize().width() - (used_width + insets.width())); | 544 bubble_view->GetPreferredSize().width() - (used_width + insets.width())); |
| 545 int max_width = std::min( | 545 int max_width = std::min<int>( |
| 546 font.GetStringWidth(text_) + space_width + link_size.width(), | 546 font.GetStringWidth(text_) + space_width + link_size.width(), |
| 547 bubble_view->GetMaximumSize().width() - (used_width + insets.width())); | 547 bubble_view->GetMaximumSize().width() - (used_width + insets.width())); |
| 548 // Do a binary search for the minimum width that ensures no more than three | 548 // Do a binary search for the minimum width that ensures no more than three |
| 549 // lines are needed. The lower bound is the minimum of the current bubble | 549 // lines are needed. The lower bound is the minimum of the current bubble |
| 550 // width and the width of the link (as no wrapping is permitted inside the | 550 // width and the width of the link (as no wrapping is permitted inside the |
| 551 // link). The upper bound is the maximum of the largest allowed bubble width | 551 // link). The upper bound is the maximum of the largest allowed bubble width |
| 552 // and the sum of the label text and link widths when put on a single line. | 552 // and the sum of the label text and link widths when put on a single line. |
| 553 std::vector<base::string16> lines; | 553 std::vector<base::string16> lines; |
| 554 while (min_width < max_width) { | 554 while (min_width < max_width) { |
| 555 lines.clear(); | 555 lines.clear(); |
| 556 const int width = (min_width + max_width) / 2; | 556 const int width = (min_width + max_width) / 2; |
| 557 const bool too_narrow = gfx::ElideRectangleText( | 557 const bool too_narrow = gfx::ElideRectangleText( |
| 558 text_, font, width, INT_MAX, gfx::TRUNCATE_LONG_WORDS, &lines) != 0; | 558 text_, font, width, FLT_MAX, gfx::TRUNCATE_LONG_WORDS, &lines) != 0; |
| 559 int line_count = lines.size(); | 559 int line_count = lines.size(); |
| 560 if (!too_narrow && line_count == 3 && | 560 if (!too_narrow && line_count == 3 && |
| 561 width - font.GetStringWidth(lines.back()) <= | 561 width - font.GetStringWidth(lines.back()) <= |
| 562 space_width + link_size.width()) { | 562 space_width + link_size.width()) { |
| 563 ++line_count; | 563 ++line_count; |
| 564 } | 564 } |
| 565 if (too_narrow || line_count > 3) | 565 if (too_narrow || line_count > 3) |
| 566 min_width = width + 1; | 566 min_width = width + 1; |
| 567 else | 567 else |
| 568 max_width = width; | 568 max_width = width; |
| 569 } | 569 } |
| 570 | 570 |
| 571 // Calculate the corresponding height and set the preferred size. | 571 // Calculate the corresponding height and set the preferred size. |
| 572 lines.clear(); | 572 lines.clear(); |
| 573 gfx::ElideRectangleText( | 573 gfx::ElideRectangleText( |
| 574 text_, font, min_width, INT_MAX, gfx::TRUNCATE_LONG_WORDS, &lines); | 574 text_, font, min_width, FLT_MAX, gfx::TRUNCATE_LONG_WORDS, &lines); |
| 575 int line_count = lines.size(); | 575 int line_count = lines.size(); |
| 576 if (min_width - font.GetStringWidth(lines.back()) <= | 576 if (min_width - font.GetStringWidth(lines.back()) <= |
| 577 space_width + link_size.width()) { | 577 space_width + link_size.width()) { |
| 578 ++line_count; | 578 ++line_count; |
| 579 } | 579 } |
| 580 const int line_height = font.GetHeight(); | 580 const int line_height = font.GetHeight(); |
| 581 const int link_extra_height = std::max( | 581 const int link_extra_height = std::max( |
| 582 link_size.height() - learn_more_->GetInsets().top() - line_height, 0); | 582 link_size.height() - learn_more_->GetInsets().top() - line_height, 0); |
| 583 preferred_size_ = gfx::Size( | 583 preferred_size_ = gfx::Size( |
| 584 min_width + insets.width(), | 584 min_width + insets.width(), |
| (...skipping 706 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1291 kUserIconLargeSize : kUserIconSize; | 1291 kUserIconLargeSize : kUserIconSize; |
| 1292 | 1292 |
| 1293 avatar_->SetImage( | 1293 avatar_->SetImage( |
| 1294 ash::Shell::GetInstance()->session_state_delegate()->GetUserImage( | 1294 ash::Shell::GetInstance()->session_state_delegate()->GetUserImage( |
| 1295 multiprofile_index_), | 1295 multiprofile_index_), |
| 1296 gfx::Size(icon_size, icon_size)); | 1296 gfx::Size(icon_size, icon_size)); |
| 1297 } | 1297 } |
| 1298 | 1298 |
| 1299 } // namespace internal | 1299 } // namespace internal |
| 1300 } // namespace ash | 1300 } // namespace ash |
| OLD | NEW |