| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 "chrome/browser/ui/views/tabs/base_tab.h" | 5 #include "chrome/browser/ui/views/tabs/base_tab.h" |
| 6 | 6 |
| 7 #include <limits> | 7 #include <limits> |
| 8 | 8 |
| 9 #include "base/command_line.h" | 9 #include "base/command_line.h" |
| 10 #include "base/utf_string_conversions.h" | 10 #include "base/utf_string_conversions.h" |
| (...skipping 461 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 472 const gfx::Rect& title_bounds = GetTitleBounds(); | 472 const gfx::Rect& title_bounds = GetTitleBounds(); |
| 473 string16 title = data().title; | 473 string16 title = data().title; |
| 474 if (title.empty()) { | 474 if (title.empty()) { |
| 475 title = data().loading ? | 475 title = data().loading ? |
| 476 l10n_util::GetStringUTF16(IDS_TAB_LOADING_TITLE) : | 476 l10n_util::GetStringUTF16(IDS_TAB_LOADING_TITLE) : |
| 477 TabContentsWrapper::GetDefaultTitle(); | 477 TabContentsWrapper::GetDefaultTitle(); |
| 478 } else { | 478 } else { |
| 479 Browser::FormatTitleForDisplay(&title); | 479 Browser::FormatTitleForDisplay(&title); |
| 480 // If we'll need to truncate, check if we should also truncate | 480 // If we'll need to truncate, check if we should also truncate |
| 481 // a common prefix, but only if there is enough room for it. | 481 // a common prefix, but only if there is enough room for it. |
| 482 // We arbitrarily choose to request enough room for 10 average chars. | 482 // We arbitrarily choose to request enough room for 6 average chars. |
| 483 if (data().common_prefix_length > 0 && | 483 // Also, we want to show the last 4 common chars, so we only do it if |
| 484 font_->GetExpectedTextWidth(10) < title_bounds.width() && | 484 // the common prefix is at least 7 characters long, otherwise, we would be |
| 485 // replacing 3 or less characters with a 3 dot ellipsis... not worth it. |
| 486 if (data().common_prefix_length > 7 && |
| 487 font_->GetExpectedTextWidth(6) < title_bounds.width() && |
| 485 font_->GetStringWidth(title) > title_bounds.width()) { | 488 font_->GetStringWidth(title) > title_bounds.width()) { |
| 486 title.replace(0, data().common_prefix_length, UTF8ToUTF16(ui::kEllipsis)); | 489 title.replace(0, data().common_prefix_length - 4, |
| 490 UTF8ToUTF16(ui::kEllipsis)); |
| 487 } | 491 } |
| 488 } | 492 } |
| 489 canvas->DrawStringInt(title, *font_, title_color, | 493 canvas->DrawStringInt(title, *font_, title_color, |
| 490 title_bounds.x(), title_bounds.y(), | 494 title_bounds.x(), title_bounds.y(), |
| 491 title_bounds.width(), title_bounds.height()); | 495 title_bounds.width(), title_bounds.height()); |
| 492 } | 496 } |
| 493 | 497 |
| 494 void BaseTab::AnimationProgressed(const ui::Animation* animation) { | 498 void BaseTab::AnimationProgressed(const ui::Animation* animation) { |
| 495 SchedulePaint(); | 499 SchedulePaint(); |
| 496 } | 500 } |
| (...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 573 // static | 577 // static |
| 574 void BaseTab::InitResources() { | 578 void BaseTab::InitResources() { |
| 575 static bool initialized = false; | 579 static bool initialized = false; |
| 576 if (!initialized) { | 580 if (!initialized) { |
| 577 initialized = true; | 581 initialized = true; |
| 578 font_ = new gfx::Font( | 582 font_ = new gfx::Font( |
| 579 ResourceBundle::GetSharedInstance().GetFont(ResourceBundle::BaseFont)); | 583 ResourceBundle::GetSharedInstance().GetFont(ResourceBundle::BaseFont)); |
| 580 font_height_ = font_->GetHeight(); | 584 font_height_ = font_->GetHeight(); |
| 581 } | 585 } |
| 582 } | 586 } |
| OLD | NEW |