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

Unified Diff: chrome/browser/ui/views/tabs/tab.cc

Issue 327273005: Revert of Use labels to display views tab titles. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 6 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « chrome/browser/ui/views/tabs/tab.h ('k') | chrome/browser/ui/views/tabs/tab_unittest.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/browser/ui/views/tabs/tab.cc
diff --git a/chrome/browser/ui/views/tabs/tab.cc b/chrome/browser/ui/views/tabs/tab.cc
index d5c252c7c883e28d0612b7500956254e12f134f9..ff64038d66a9a274103338c77e8c3abfd468707d 100644
--- a/chrome/browser/ui/views/tabs/tab.cc
+++ b/chrome/browser/ui/views/tabs/tab.cc
@@ -35,6 +35,7 @@
#include "ui/gfx/canvas.h"
#include "ui/gfx/color_analysis.h"
#include "ui/gfx/favicon_size.h"
+#include "ui/gfx/font.h"
#include "ui/gfx/image/image_skia_operations.h"
#include "ui/gfx/path.h"
#include "ui/gfx/rect_conversions.h"
@@ -42,7 +43,6 @@
#include "ui/gfx/text_elider.h"
#include "ui/views/border.h"
#include "ui/views/controls/button/image_button.h"
-#include "ui/views/controls/label.h"
#include "ui/views/rect_based_targeting_utils.h"
#include "ui/views/widget/tooltip_manager.h"
#include "ui/views/widget/widget.h"
@@ -375,6 +375,10 @@
Tab::TabImage Tab::tab_active_ = {0};
Tab::TabImage Tab::tab_inactive_ = {0};
// static
+gfx::Font* Tab::font_ = NULL;
+// static
+int Tab::font_height_ = 0;
+// static
Tab::ImageCache* Tab::image_cache_ = NULL;
////////////////////////////////////////////////////////////////////////////////
@@ -389,8 +393,6 @@
immersive_loading_step_(0),
should_display_crashed_favicon_(false),
animating_media_state_(TAB_MEDIA_STATE_NONE),
- close_button_(NULL),
- title_(new views::Label()),
tab_activated_with_last_gesture_begin_(false),
hover_controller_(this),
showing_icon_(false),
@@ -405,10 +407,6 @@
set_notify_enter_exit_on_child(true);
set_id(VIEW_ID_TAB);
-
- title_->set_directionality_mode(gfx::DIRECTIONALITY_FROM_TEXT);
- title_->SetHorizontalAlignment(gfx::ALIGN_TO_HEAD);
- title_->SetElideBehavior(gfx::FADE_TAIL);
// Add the Close Button.
close_button_ = new TabCloseButton(this);
@@ -451,16 +449,6 @@
TabRendererData old(data_);
data_ = data;
-
- base::string16 title = data_.title;
- if (title.empty()) {
- title = data_.loading ?
- l10n_util::GetStringUTF16(IDS_TAB_LOADING_TITLE) :
- CoreTabHelper::GetDefaultTitle();
- } else {
- Browser::FormatTitleForDisplay(&title);
- }
- title_->SetText(title);
if (data_.IsCrashed()) {
if (!should_display_crashed_favicon_ && !IsPerformingCrashAnimation()) {
@@ -698,8 +686,7 @@
// The height of the content of the Tab is the largest of the favicon,
// the title text and the close button graphic.
const int kTabIconSize = gfx::kFaviconSize;
- const int font_height = title_->font_list().GetHeight();
- int content_height = std::max(kTabIconSize, font_height);
+ int content_height = std::max(kTabIconSize, font_height_);
close_button_->SetBorder(views::Border::NullBorder());
gfx::Size close_button_size(close_button_->GetPreferredSize());
content_height = std::max(content_height, close_button_size.height());
@@ -771,15 +758,14 @@
kTitleTextOffsetYAsh : kTitleTextOffsetY;
int title_left = favicon_bounds_.right() + kFaviconTitleSpacing;
int title_top = kTopPadding + title_text_offset +
- (content_height - font_height) / 2;
- gfx::Rect title_bounds(title_left, title_top, 0, 0);
+ (content_height - font_height_) / 2;
// Size the Title text to fill the remaining space.
if (!data().mini || width() >= kMiniTabRendererAsNormalTabWidth) {
// If the user has big fonts, the title will appear rendered too far down
// on the y-axis if we use the regular top padding, so we need to adjust it
// so that the text appears centered.
gfx::Size minimum_size = GetMinimumUnselectedSize();
- int text_height = title_top + font_height + kBottomPadding;
+ int text_height = title_top + font_height_ + kBottomPadding;
if (text_height > minimum_size.height())
title_top -= (text_height - minimum_size.height()) / 2;
@@ -797,11 +783,19 @@
title_width = lb.width() - title_left;
}
title_width = std::max(title_width, 0);
- title_bounds.SetRect(title_left, title_top, title_width, font_height);
- }
-
- title_bounds.set_x(GetMirroredXForRect(title_bounds));
- title_->SetBoundsRect(title_bounds);
+ title_bounds_.SetRect(title_left, title_top, title_width, font_height_);
+ } else {
+ title_bounds_.SetRect(title_left, title_top, 0, 0);
+ }
+
+ // Certain UI elements within the Tab (the favicon, etc.) are not represented
+ // as child Views (which is the preferred method). Instead, these UI elements
+ // are drawn directly on the canvas from within Tab::OnPaint(). The Tab's
+ // child Views (for example, the Tab's close button which is a views::Button
+ // instance) are automatically mirrored by the mirroring infrastructure in
+ // views. The elements Tab draws directly on the canvas need to be manually
+ // mirrored if the View's layout is right-to-left.
+ title_bounds_.set_x(GetMirroredXForRect(title_bounds_));
}
void Tab::OnThemeChanged() {
@@ -846,7 +840,7 @@
}
bool Tab::GetTooltipTextOrigin(const gfx::Point& p, gfx::Point* origin) const {
- origin->set_x(title_->x() + 10);
+ origin->set_x(title_bounds_.x() + 10);
origin->set_y(-views::TooltipManager::GetTooltipHeight() - 4);
return true;
}
@@ -989,6 +983,14 @@
////////////////////////////////////////////////////////////////////////////////
// Tab, private
+const gfx::Rect& Tab::GetTitleBounds() const {
+ return title_bounds_;
+}
+
+const gfx::Rect& Tab::GetIconBounds() const {
+ return favicon_bounds_;
+}
+
void Tab::MaybeAdjustLeftForMiniTab(gfx::Rect* bounds) const {
if (!data().mini || width() >= kMiniTabRendererAsNormalTabWidth)
return;
@@ -1026,13 +1028,13 @@
PaintTabBackground(canvas);
- const SkColor title_color = GetThemeProvider()->GetColor(IsSelected() ?
- ThemeProperties::COLOR_TAB_TEXT :
- ThemeProperties::COLOR_BACKGROUND_TAB_TEXT);
- if (!data().mini || width() > kMiniTabRendererAsNormalTabWidth) {
- title_->SetEnabledColor(title_color);
- title_->Paint(canvas, views::CullSet());
- }
+ SkColor title_color = GetThemeProvider()->
+ GetColor(IsSelected() ?
+ ThemeProperties::COLOR_TAB_TEXT :
+ ThemeProperties::COLOR_BACKGROUND_TAB_TEXT);
+
+ if (!data().mini || width() > kMiniTabRendererAsNormalTabWidth)
+ PaintTitle(canvas, title_color);
if (show_icon)
PaintIcon(canvas);
@@ -1329,7 +1331,7 @@
}
void Tab::PaintIcon(gfx::Canvas* canvas) {
- gfx::Rect bounds = favicon_bounds_;
+ gfx::Rect bounds = GetIconBounds();
if (bounds.IsEmpty())
return;
@@ -1353,9 +1355,9 @@
gfx::ImageSkia crashed_favicon(*rb.GetImageSkiaNamed(IDR_SAD_FAVICON));
bounds.set_y(bounds.y() + favicon_hiding_offset_);
DrawIconCenter(canvas, crashed_favicon, 0,
- crashed_favicon.width(),
- crashed_favicon.height(),
- bounds, true, SkPaint());
+ crashed_favicon.width(),
+ crashed_favicon.height(),
+ bounds, true, SkPaint());
} else if (!data().favicon.isNull()) {
// Paint the normal favicon.
DrawIconCenter(canvas, data().favicon, 0,
@@ -1385,6 +1387,21 @@
DrawIconAtLocation(canvas, media_indicator_image, 0,
bounds.x(), bounds.y(), media_indicator_image.width(),
media_indicator_image.height(), true, paint);
+}
+
+void Tab::PaintTitle(gfx::Canvas* canvas, SkColor title_color) {
+ // Paint the Title.
+ base::string16 title = data().title;
+ if (title.empty()) {
+ title = data().loading ?
+ l10n_util::GetStringUTF16(IDS_TAB_LOADING_TITLE) :
+ CoreTabHelper::GetDefaultTitle();
+ } else {
+ Browser::FormatTitleForDisplay(&title);
+ }
+
+ canvas->DrawFadedString(title, gfx::FontList(*font_), title_color,
+ GetTitleBounds(), 0);
}
void Tab::AdvanceLoadingAnimation(TabRendererData::NetworkState old_state,
@@ -1529,11 +1546,12 @@
}
void Tab::ScheduleIconPaint() {
- gfx::Rect bounds = favicon_bounds_;
+ gfx::Rect bounds = GetIconBounds();
if (bounds.IsEmpty())
return;
- // Extends the area to the bottom when sad_favicon is animating.
+ // Extends the area to the bottom when sad_favicon is
+ // animating.
if (IsPerformingCrashAnimation())
bounds.set_height(height() - bounds.y());
bounds.set_x(GetMirroredXForRect(bounds));
@@ -1577,6 +1595,11 @@
return;
initialized = true;
+
+ ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance();
+ font_ = new gfx::Font(rb.GetFont(ui::ResourceBundle::BaseFont));
+ font_height_ = font_->GetHeight();
+
image_cache_ = new ImageCache();
// Load the tab images once now, and maybe again later if the theme changes.
« no previous file with comments | « chrome/browser/ui/views/tabs/tab.h ('k') | chrome/browser/ui/views/tabs/tab_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698