Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(334)

Side by Side Diff: chrome/browser/ui/views/tabs/base_tab.cc

Issue 6579050: Elides the beginning of tab titles that have common prefixes. ... (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Elides the beginning of tab titles that have common prefixes. ... Created 9 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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/view_ids.h" 12 #include "chrome/browser/ui/view_ids.h"
13 #include "chrome/browser/ui/views/tabs/tab_controller.h" 13 #include "chrome/browser/ui/views/tabs/tab_controller.h"
14 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h" 14 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.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/animation/slide_animation.h" 20 #include "ui/base/animation/slide_animation.h"
21 #include "ui/base/animation/throb_animation.h" 21 #include "ui/base/animation/throb_animation.h"
22 #include "ui/base/l10n/l10n_util.h" 22 #include "ui/base/l10n/l10n_util.h"
23 #include "ui/base/resource/resource_bundle.h" 23 #include "ui/base/resource/resource_bundle.h"
24 #include "ui/base/text/text_elider.h"
24 #include "ui/base/theme_provider.h" 25 #include "ui/base/theme_provider.h"
25 #include "ui/gfx/canvas_skia.h" 26 #include "ui/gfx/canvas_skia.h"
26 #include "ui/gfx/favicon_size.h" 27 #include "ui/gfx/favicon_size.h"
27 #include "ui/gfx/font.h" 28 #include "ui/gfx/font.h"
28 #include "views/controls/button/image_button.h" 29 #include "views/controls/button/image_button.h"
29 30
30 // How long the pulse throb takes. 31 // How long the pulse throb takes.
31 static const int kPulseDurationMs = 200; 32 static const int kPulseDurationMs = 200;
32 33
33 // How long the hover state takes. 34 // How long the hover state takes.
(...skipping 401 matching lines...) Expand 10 before | Expand all | Expand 10 after
435 data().favicon.height(), 436 data().favicon.height(),
436 bounds, true); 437 bounds, true);
437 } 438 }
438 } 439 }
439 canvas->Restore(); 440 canvas->Restore();
440 } 441 }
441 } 442 }
442 443
443 void BaseTab::PaintTitle(gfx::Canvas* canvas, SkColor title_color) { 444 void BaseTab::PaintTitle(gfx::Canvas* canvas, SkColor title_color) {
444 // Paint the Title. 445 // Paint the Title.
446 const gfx::Rect& title_bounds = GetTitleBounds();
445 string16 title = data().title; 447 string16 title = data().title;
446 if (title.empty()) { 448 if (title.empty()) {
447 title = data().loading ? 449 title = data().loading ?
448 l10n_util::GetStringUTF16(IDS_TAB_LOADING_TITLE) : 450 l10n_util::GetStringUTF16(IDS_TAB_LOADING_TITLE) :
449 TabContentsWrapper::GetDefaultTitle(); 451 TabContentsWrapper::GetDefaultTitle();
450 } else { 452 } else {
451 Browser::FormatTitleForDisplay(&title); 453 Browser::FormatTitleForDisplay(&title);
454 // If we'll need to truncate, check if we should also truncate
455 // a common prefix, but only if there is enough room for it.
456 // We arbitrarily choose to request enough room for 10 average chars.
457 if (data().common_prefix_length > 0 &&
458 font_->GetExpectedTextWidth(10) < title_bounds.width() &&
459 font_->GetStringWidth(title) > title_bounds.width()) {
460 title.replace(0, data().common_prefix_length, UTF8ToUTF16(ui::kEllipsis));
461 }
452 } 462 }
453 const gfx::Rect& title_bounds = GetTitleBounds();
454 canvas->DrawStringInt(title, *font_, title_color, 463 canvas->DrawStringInt(title, *font_, title_color,
455 title_bounds.x(), title_bounds.y(), 464 title_bounds.x(), title_bounds.y(),
456 title_bounds.width(), title_bounds.height()); 465 title_bounds.width(), title_bounds.height());
457 } 466 }
458 467
459 void BaseTab::AnimationProgressed(const ui::Animation* animation) { 468 void BaseTab::AnimationProgressed(const ui::Animation* animation) {
460 SchedulePaint(); 469 SchedulePaint();
461 } 470 }
462 471
463 void BaseTab::AnimationCanceled(const ui::Animation* animation) { 472 void BaseTab::AnimationCanceled(const ui::Animation* animation) {
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after
538 // static 547 // static
539 void BaseTab::InitResources() { 548 void BaseTab::InitResources() {
540 static bool initialized = false; 549 static bool initialized = false;
541 if (!initialized) { 550 if (!initialized) {
542 initialized = true; 551 initialized = true;
543 font_ = new gfx::Font( 552 font_ = new gfx::Font(
544 ResourceBundle::GetSharedInstance().GetFont(ResourceBundle::BaseFont)); 553 ResourceBundle::GetSharedInstance().GetFont(ResourceBundle::BaseFont));
545 font_height_ = font_->GetHeight(); 554 font_height_ = font_->GetHeight();
546 } 555 }
547 } 556 }
OLDNEW
« no previous file with comments | « chrome/browser/ui/title_prefix_matcher_unittest.cc ('k') | chrome/browser/ui/views/tabs/base_tab_strip.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698