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 | |
Peter Kasting
2011/04/01 20:19:20
Nit: Don't remove this blank line
MAD
2011/04/05 16:13:12
D'Ho...ne. :-)
| |
9 #include "base/command_line.h" | 8 #include "base/command_line.h" |
10 #include "base/utf_string_conversions.h" | 9 #include "base/utf_string_conversions.h" |
11 #include "chrome/browser/ui/browser.h" | 10 #include "chrome/browser/ui/browser.h" |
12 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h" | 11 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h" |
12 #include "chrome/browser/ui/title_prefix_matcher.h" | |
13 #include "chrome/browser/ui/view_ids.h" | 13 #include "chrome/browser/ui/view_ids.h" |
14 #include "chrome/browser/ui/views/tabs/tab_controller.h" | 14 #include "chrome/browser/ui/views/tabs/tab_controller.h" |
15 #include "chrome/common/chrome_switches.h" | 15 #include "chrome/common/chrome_switches.h" |
16 #include "content/browser/tab_contents/tab_contents.h" | 16 #include "content/browser/tab_contents/tab_contents.h" |
17 #include "grit/app_resources.h" | 17 #include "grit/app_resources.h" |
18 #include "grit/generated_resources.h" | 18 #include "grit/generated_resources.h" |
19 #include "grit/theme_resources.h" | 19 #include "grit/theme_resources.h" |
20 #include "ui/base/accessibility/accessible_view_state.h" | 20 #include "ui/base/accessibility/accessible_view_state.h" |
21 #include "ui/base/animation/animation_container.h" | 21 #include "ui/base/animation/animation_container.h" |
22 #include "ui/base/animation/slide_animation.h" | 22 #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(); | 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. |
Peter Kasting
2011/04/01 20:19:20
Nit: These comments are more useful than the ones
MAD
2011/04/05 16:13:12
Good idea..
Done.
| |
483 if (data().common_prefix_length > 0 && | 483 // Also, we want to show the last few common chars, so we only do it if |
484 font_->GetExpectedTextWidth(10) < title_bounds.width() && | 484 // the common prefix is long enough, otherwise, we could be |
485 // replacing less characters than the ellipsis take... not worth it. | |
486 if (data().common_prefix_length > TitlePrefixMatcher::kMinElidingLength && | |
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, |
490 data().common_prefix_length - | |
491 TitlePrefixMatcher::kCommonCharsToShow, | |
492 UTF8ToUTF16(ui::kEllipsis)); | |
487 } | 493 } |
488 } | 494 } |
489 canvas->DrawStringInt(title, *font_, title_color, | 495 canvas->DrawStringInt(title, *font_, title_color, |
490 title_bounds.x(), title_bounds.y(), | 496 title_bounds.x(), title_bounds.y(), |
491 title_bounds.width(), title_bounds.height()); | 497 title_bounds.width(), title_bounds.height()); |
492 } | 498 } |
493 | 499 |
494 void BaseTab::AnimationProgressed(const ui::Animation* animation) { | 500 void BaseTab::AnimationProgressed(const ui::Animation* animation) { |
495 SchedulePaint(); | 501 SchedulePaint(); |
496 } | 502 } |
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
573 // static | 579 // static |
574 void BaseTab::InitResources() { | 580 void BaseTab::InitResources() { |
575 static bool initialized = false; | 581 static bool initialized = false; |
576 if (!initialized) { | 582 if (!initialized) { |
577 initialized = true; | 583 initialized = true; |
578 font_ = new gfx::Font( | 584 font_ = new gfx::Font( |
579 ResourceBundle::GetSharedInstance().GetFont(ResourceBundle::BaseFont)); | 585 ResourceBundle::GetSharedInstance().GetFont(ResourceBundle::BaseFont)); |
580 font_height_ = font_->GetHeight(); | 586 font_height_ = font_->GetHeight(); |
581 } | 587 } |
582 } | 588 } |
OLD | NEW |