Chromium Code Reviews| 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" | |
| 14 #include "chrome/browser/ui/view_ids.h" | 13 #include "chrome/browser/ui/view_ids.h" |
| 15 #include "chrome/browser/ui/views/tabs/tab_controller.h" | 14 #include "chrome/browser/ui/views/tabs/tab_controller.h" |
| 16 #include "chrome/common/chrome_switches.h" | 15 #include "chrome/common/chrome_switches.h" |
| 17 #include "content/browser/tab_contents/tab_contents.h" | 16 #include "content/browser/tab_contents/tab_contents.h" |
| 18 #include "grit/app_resources.h" | 17 #include "grit/app_resources.h" |
| 19 #include "grit/generated_resources.h" | 18 #include "grit/generated_resources.h" |
| 20 #include "grit/theme_resources.h" | 19 #include "grit/theme_resources.h" |
| 21 #include "grit/theme_resources_standard.h" | 20 #include "grit/theme_resources_standard.h" |
| 22 #include "ui/base/accessibility/accessible_view_state.h" | 21 #include "ui/base/accessibility/accessible_view_state.h" |
| 23 #include "ui/base/animation/animation_container.h" | 22 #include "ui/base/animation/animation_container.h" |
| (...skipping 444 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 468 } | 467 } |
| 469 } | 468 } |
| 470 canvas->Restore(); | 469 canvas->Restore(); |
| 471 } | 470 } |
| 472 } | 471 } |
| 473 | 472 |
| 474 void BaseTab::PaintTitle(gfx::Canvas* canvas, SkColor title_color) { | 473 void BaseTab::PaintTitle(gfx::Canvas* canvas, SkColor title_color) { |
| 475 // Paint the Title. | 474 // Paint the Title. |
| 476 const gfx::Rect& title_bounds = GetTitleBounds(); | 475 const gfx::Rect& title_bounds = GetTitleBounds(); |
| 477 string16 title = data().title; | 476 string16 title = data().title; |
| 478 bool should_truncate = false; | |
| 479 int prefix_length = 0; | |
| 480 | 477 |
| 481 if (title.empty()) { | 478 if (title.empty()) { |
| 482 title = data().loading ? | 479 title = data().loading ? |
| 483 l10n_util::GetStringUTF16(IDS_TAB_LOADING_TITLE) : | 480 l10n_util::GetStringUTF16(IDS_TAB_LOADING_TITLE) : |
| 484 TabContentsWrapper::GetDefaultTitle(); | 481 TabContentsWrapper::GetDefaultTitle(); |
| 485 } else { | 482 } else { |
| 486 Browser::FormatTitleForDisplay(&title); | 483 Browser::FormatTitleForDisplay(&title); |
| 487 // If we'll need to truncate, check if we should also truncate | |
| 488 // a common prefix, but only if there is enough room for it. | |
| 489 // We arbitrarily choose to request enough room for 6 average chars. | |
| 490 should_truncate = | |
| 491 data().common_prefix_length > TitlePrefixMatcher::kMinElidingLength && | |
| 492 font_->GetExpectedTextWidth(6) < title_bounds.width() && | |
| 493 font_->GetStringWidth(title) > title_bounds.width(); | |
| 494 prefix_length = data().common_prefix_length - | |
| 495 TitlePrefixMatcher::kCommonCharsToShow; | |
| 496 } | 484 } |
| 497 | 485 |
| 498 #if defined(OS_WIN) | 486 #if defined(OS_WIN) |
| 499 canvas->AsCanvasSkia()->DrawFadeTruncatingString(title, | 487 canvas->AsCanvasSkia()->DrawFadeTruncatingString(title, |
|
Peter Kasting
2011/05/23 23:06:43
Nit: I think we should also simplify this API. Le
sail
2011/05/23 23:25:36
Sounds good. I'll send that out separately. I'm tr
| |
| 500 should_truncate ? gfx::CanvasSkia::TruncateFadeHeadAndTail : | 488 gfx::CanvasSkia::TruncateFadeTail, 0, *font_, title_color, title_bounds); |
| 501 gfx::CanvasSkia::TruncateFadeTail, | |
| 502 prefix_length, *font_, title_color, title_bounds); | |
| 503 #else | 489 #else |
| 504 if (should_truncate) | |
| 505 title.replace(0, prefix_length, UTF8ToUTF16(ui::kEllipsis)); | |
| 506 canvas->DrawStringInt(title, *font_, title_color, | 490 canvas->DrawStringInt(title, *font_, title_color, |
| 507 title_bounds.x(), title_bounds.y(), | 491 title_bounds.x(), title_bounds.y(), |
| 508 title_bounds.width(), title_bounds.height()); | 492 title_bounds.width(), title_bounds.height()); |
| 509 #endif | 493 #endif |
| 510 } | 494 } |
| 511 | 495 |
| 512 void BaseTab::AnimationProgressed(const ui::Animation* animation) { | 496 void BaseTab::AnimationProgressed(const ui::Animation* animation) { |
| 513 SchedulePaint(); | 497 SchedulePaint(); |
| 514 } | 498 } |
| 515 | 499 |
| (...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 591 // static | 575 // static |
| 592 void BaseTab::InitResources() { | 576 void BaseTab::InitResources() { |
| 593 static bool initialized = false; | 577 static bool initialized = false; |
| 594 if (!initialized) { | 578 if (!initialized) { |
| 595 initialized = true; | 579 initialized = true; |
| 596 font_ = new gfx::Font( | 580 font_ = new gfx::Font( |
| 597 ResourceBundle::GetSharedInstance().GetFont(ResourceBundle::BaseFont)); | 581 ResourceBundle::GetSharedInstance().GetFont(ResourceBundle::BaseFont)); |
| 598 font_height_ = font_->GetHeight(); | 582 font_height_ = font_->GetHeight(); |
| 599 } | 583 } |
| 600 } | 584 } |
| OLD | NEW |