| 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" |
| 11 #include "chrome/browser/ui/browser.h" | 11 #include "chrome/browser/ui/browser.h" |
| 12 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h" | 12 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h" |
| 13 #include "chrome/browser/ui/title_prefix_matcher.h" |
| 13 #include "chrome/browser/ui/view_ids.h" | 14 #include "chrome/browser/ui/view_ids.h" |
| 14 #include "chrome/browser/ui/views/tabs/tab_controller.h" | 15 #include "chrome/browser/ui/views/tabs/tab_controller.h" |
| 15 #include "chrome/common/chrome_switches.h" | 16 #include "chrome/common/chrome_switches.h" |
| 16 #include "content/browser/tab_contents/tab_contents.h" | 17 #include "content/browser/tab_contents/tab_contents.h" |
| 17 #include "grit/app_resources.h" | 18 #include "grit/app_resources.h" |
| 18 #include "grit/generated_resources.h" | 19 #include "grit/generated_resources.h" |
| 19 #include "grit/theme_resources.h" | 20 #include "grit/theme_resources.h" |
| 20 #include "ui/base/accessibility/accessible_view_state.h" | 21 #include "ui/base/accessibility/accessible_view_state.h" |
| 21 #include "ui/base/animation/animation_container.h" | 22 #include "ui/base/animation/animation_container.h" |
| 22 #include "ui/base/animation/slide_animation.h" | 23 #include "ui/base/animation/slide_animation.h" |
| (...skipping 449 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 472 const gfx::Rect& title_bounds = GetTitleBounds(); | 473 const gfx::Rect& title_bounds = GetTitleBounds(); |
| 473 string16 title = data().title; | 474 string16 title = data().title; |
| 474 if (title.empty()) { | 475 if (title.empty()) { |
| 475 title = data().loading ? | 476 title = data().loading ? |
| 476 l10n_util::GetStringUTF16(IDS_TAB_LOADING_TITLE) : | 477 l10n_util::GetStringUTF16(IDS_TAB_LOADING_TITLE) : |
| 477 TabContentsWrapper::GetDefaultTitle(); | 478 TabContentsWrapper::GetDefaultTitle(); |
| 478 } else { | 479 } else { |
| 479 Browser::FormatTitleForDisplay(&title); | 480 Browser::FormatTitleForDisplay(&title); |
| 480 // If we'll need to truncate, check if we should also truncate | 481 // 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. | 482 // a common prefix, but only if there is enough room for it. |
| 482 // We arbitrarily choose to request enough room for 10 average chars. | 483 // We arbitrarily choose to request enough room for 6 average chars. |
| 483 if (data().common_prefix_length > 0 && | 484 if (data().common_prefix_length > TitlePrefixMatcher::kMinElidingLength && |
| 484 font_->GetExpectedTextWidth(10) < title_bounds.width() && | 485 font_->GetExpectedTextWidth(6) < title_bounds.width() && |
| 485 font_->GetStringWidth(title) > title_bounds.width()) { | 486 font_->GetStringWidth(title) > title_bounds.width()) { |
| 486 title.replace(0, data().common_prefix_length, UTF8ToUTF16(ui::kEllipsis)); | 487 title.replace(0, |
| 488 data().common_prefix_length - |
| 489 TitlePrefixMatcher::kCommonCharsToShow, |
| 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 |