summaryrefslogtreecommitdiffstats
path: root/chrome/browser/views
diff options
context:
space:
mode:
authorpkasting@chromium.org <pkasting@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-07-27 01:47:01 +0000
committerpkasting@chromium.org <pkasting@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-07-27 01:47:01 +0000
commit156d00064f752ed3f73204403b0a3ca71a8ac913 (patch)
treef9eaa29affe1c64ae4e08ca7bfd4404e35b02dcf /chrome/browser/views
parentfaca1b885f186dccda7b750f8f15bbf0a1cf8687 (diff)
downloadchromium_src-156d00064f752ed3f73204403b0a3ca71a8ac913.zip
chromium_src-156d00064f752ed3f73204403b0a3ca71a8ac913.tar.gz
chromium_src-156d00064f752ed3f73204403b0a3ca71a8ac913.tar.bz2
Make the throbber and tab close button correctly respond to theme changes. This is partly using GetThemeProvider() instead of ResourceBundle::GetSharedInstance(), and partly not caching SkBitmaps (which we used to do long ago but stopped because it's pointless).
BUG=50107 TEST=Throbber responds to theme changes Review URL: http://codereview.chromium.org/3064006 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@53740 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/views')
-rw-r--r--chrome/browser/views/tab_icon_view.cc40
-rw-r--r--chrome/browser/views/tabs/base_tab.cc138
-rw-r--r--chrome/browser/views/tabs/base_tab.h20
-rw-r--r--chrome/browser/views/tabs/tab.cc12
4 files changed, 73 insertions, 137 deletions
diff --git a/chrome/browser/views/tab_icon_view.cc b/chrome/browser/views/tab_icon_view.cc
index a43e0ac..db8a8e8 100644
--- a/chrome/browser/views/tab_icon_view.cc
+++ b/chrome/browser/views/tab_icon_view.cc
@@ -1,4 +1,4 @@
-// Copyright (c) 2006-2008 The Chromium Authors. All rights reserved.
+// Copyright (c) 2010 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
@@ -10,6 +10,7 @@
#endif
#include "app/resource_bundle.h"
+#include "app/theme_provider.h"
#include "base/file_util.h"
#include "base/logging.h"
#include "chrome/app/chrome_dll_resource.h"
@@ -26,14 +27,11 @@
static bool g_initialized = false;
static SkBitmap* g_default_fav_icon = NULL;
-static SkBitmap* g_throbber_frames = NULL;
-static SkBitmap* g_throbber_frames_light = NULL;
-static int g_throbber_frame_count;
// static
void TabIconView::InitializeIfNeeded() {
if (!g_initialized) {
- ResourceBundle &rb = ResourceBundle::GetSharedInstance();
+ g_initialized = true;
#if defined(OS_WIN)
// The default window icon is the application icon, not the default
@@ -43,18 +41,9 @@ void TabIconView::InitializeIfNeeded() {
IconUtil::CreateSkBitmapFromHICON(app_icon, gfx::Size(16, 16));
DestroyIcon(app_icon);
#else
- g_default_fav_icon = rb.GetBitmapNamed(IDR_PRODUCT_LOGO_16);
+ g_default_fav_icon =
+ ResourceBundle::GetSharedInstance().GetBitmapNamed(IDR_PRODUCT_LOGO_16);
#endif
-
- g_throbber_frames = rb.GetBitmapNamed(IDR_THROBBER);
- g_throbber_frames_light = rb.GetBitmapNamed(IDR_THROBBER_LIGHT);
- g_throbber_frame_count = g_throbber_frames->width() /
- g_throbber_frames->height();
-
- // Verify that our light and dark styles have the same number of frames.
- DCHECK(g_throbber_frame_count ==
- g_throbber_frames_light->width() / g_throbber_frames_light->height());
- g_initialized = true;
}
}
@@ -70,6 +59,15 @@ TabIconView::~TabIconView() {
}
void TabIconView::Update() {
+ static bool initialized = false;
+ static int throbber_frame_count = 0;
+ if (!initialized) {
+ initialized = true;
+ SkBitmap throbber(
+ *ResourceBundle::GetSharedInstance().GetBitmapNamed(IDR_THROBBER));
+ throbber_frame_count = throbber.width() / throbber.height();
+ }
+
if (throbber_running_) {
// We think the tab is loading.
if (!model_->ShouldTabIconViewAnimate()) {
@@ -79,7 +77,7 @@ void TabIconView::Update() {
SchedulePaint();
} else {
// The tab is still loading, increment the frame.
- throbber_frame_ = (throbber_frame_ + 1) % g_throbber_frame_count;
+ throbber_frame_ = (throbber_frame_ + 1) % throbber_frame_count;
SchedulePaint();
}
} else if (model_->ShouldTabIconViewAnimate()) {
@@ -92,9 +90,11 @@ void TabIconView::Update() {
}
void TabIconView::PaintThrobber(gfx::Canvas* canvas) {
- int image_size = g_throbber_frames->height();
- PaintIcon(canvas, is_light_ ? *g_throbber_frames_light : *g_throbber_frames,
- throbber_frame_ * image_size, 0, image_size, image_size, false);
+ SkBitmap throbber(*GetThemeProvider()->GetBitmapNamed(
+ is_light_ ? IDR_THROBBER_LIGHT : IDR_THROBBER));
+ int image_size = throbber.height();
+ PaintIcon(canvas, throbber, throbber_frame_ * image_size, 0, image_size,
+ image_size, false);
}
void TabIconView::PaintFavIcon(gfx::Canvas* canvas, const SkBitmap& bitmap) {
diff --git a/chrome/browser/views/tabs/base_tab.cc b/chrome/browser/views/tabs/base_tab.cc
index 42169ad..7545c72 100644
--- a/chrome/browser/views/tabs/base_tab.cc
+++ b/chrome/browser/views/tabs/base_tab.cc
@@ -10,6 +10,7 @@
#include "app/l10n_util.h"
#include "app/resource_bundle.h"
#include "app/slide_animation.h"
+#include "app/theme_provider.h"
#include "app/throb_animation.h"
#include "base/command_line.h"
#include "base/utf_string_conversions.h"
@@ -36,19 +37,6 @@ static const int kPulseDurationMs = 200;
// How long the hover state takes.
static const int kHoverDurationMs = 90;
-static SkBitmap* waiting_animation_frames = NULL;
-static SkBitmap* loading_animation_frames = NULL;
-static int loading_animation_frame_count = 0;
-static int waiting_animation_frame_count = 0;
-static int waiting_to_loading_frame_count_ratio = 0;
-
-// Close button images.
-static SkBitmap* close_button_n = NULL;
-static SkBitmap* close_button_h = NULL;
-static SkBitmap* close_button_p = NULL;
-
-static SkBitmap* crashed_fav_icon = NULL;
-
namespace {
////////////////////////////////////////////////////////////////////////////////
@@ -90,13 +78,6 @@ class TabCloseButton : public views::ImageButton {
} // namespace
// static
-int BaseTab::close_button_width_ = 0;
-// static
-int BaseTab::close_button_height_ = 0;
-// static
-int BaseTab::loading_animation_size_ = 0;
-
-// static
gfx::Font* BaseTab::font_ = NULL;
// static
int BaseTab::font_height_ = 0;
@@ -154,17 +135,20 @@ BaseTab::BaseTab(TabController* controller)
SetID(VIEW_ID_TAB);
// Add the Close Button.
- TabCloseButton* close_button = new TabCloseButton(this);
- close_button_ = close_button;
- close_button->SetImage(views::CustomButton::BS_NORMAL, close_button_n);
- close_button->SetImage(views::CustomButton::BS_HOT, close_button_h);
- close_button->SetImage(views::CustomButton::BS_PUSHED, close_button_p);
- close_button->SetTooltipText(l10n_util::GetString(IDS_TOOLTIP_CLOSE_TAB));
- close_button->SetAccessibleName(l10n_util::GetString(IDS_ACCNAME_CLOSE));
+ close_button_ = new TabCloseButton(this);
+ ResourceBundle& rb = ResourceBundle::GetSharedInstance();
+ close_button_->SetImage(views::CustomButton::BS_NORMAL,
+ rb.GetBitmapNamed(IDR_TAB_CLOSE));
+ close_button_->SetImage(views::CustomButton::BS_HOT,
+ rb.GetBitmapNamed(IDR_TAB_CLOSE_H));
+ close_button_->SetImage(views::CustomButton::BS_PUSHED,
+ rb.GetBitmapNamed(IDR_TAB_CLOSE_P));
+ close_button_->SetTooltipText(l10n_util::GetString(IDS_TOOLTIP_CLOSE_TAB));
+ close_button_->SetAccessibleName(l10n_util::GetString(IDS_ACCNAME_CLOSE));
// Disable animation so that the red danger sign shows up immediately
// to help avoid mis-clicks.
- close_button->SetAnimationDuration(0);
- AddChildView(close_button);
+ close_button_->SetAnimationDuration(0);
+ AddChildView(close_button_);
SetContextMenuController(this);
}
@@ -335,6 +319,23 @@ ThemeProvider* BaseTab::GetThemeProvider() {
void BaseTab::AdvanceLoadingAnimation(TabRendererData::NetworkState old_state,
TabRendererData::NetworkState state) {
+ static bool initialized = false;
+ static int loading_animation_frame_count = 0,
+ waiting_animation_frame_count = 0,
+ waiting_to_loading_frame_count_ratio = 0;
+ if (!initialized) {
+ initialized = true;
+ ResourceBundle& rb = ResourceBundle::GetSharedInstance();
+ SkBitmap loading_animation(*rb.GetBitmapNamed(IDR_THROBBER));
+ loading_animation_frame_count =
+ loading_animation.width() / loading_animation.height();
+ SkBitmap waiting_animation(*rb.GetBitmapNamed(IDR_THROBBER_WAITING));
+ waiting_animation_frame_count =
+ waiting_animation.width() / waiting_animation.height();
+ waiting_to_loading_frame_count_ratio =
+ waiting_animation_frame_count / loading_animation_frame_count;
+ }
+
// The waiting animation is the reverse of the loading animation, but at a
// different rate - the following reverses and scales the animation_frame_
// so that the frame is at an equivalent position when going from one
@@ -367,27 +368,26 @@ void BaseTab::PaintIcon(gfx::Canvas* canvas, int x, int y) {
favicon_x += (data().favicon.width() - kFavIconSize) / 2;
if (data().network_state != TabRendererData::NETWORK_STATE_NONE) {
- SkBitmap* frames =
+ ThemeProvider* tp = GetThemeProvider();
+ SkBitmap frames(*tp->GetBitmapNamed(
(data().network_state == TabRendererData::NETWORK_STATE_WAITING) ?
- waiting_animation_frames : loading_animation_frames;
- int image_size = frames->height();
+ IDR_THROBBER_WAITING : IDR_THROBBER));
+ int image_size = frames.height();
int image_offset = loading_animation_frame_ * image_size;
int dst_y = (height() - image_size) / 2;
- canvas->DrawBitmapInt(*frames, image_offset, 0, image_size,
+ canvas->DrawBitmapInt(frames, image_offset, 0, image_size,
image_size, favicon_x, dst_y, image_size, image_size,
false);
} else {
canvas->Save();
canvas->ClipRectInt(0, 0, width(), height());
if (should_display_crashed_favicon_) {
- canvas->DrawBitmapInt(*crashed_fav_icon, 0, 0,
- crashed_fav_icon->width(),
- crashed_fav_icon->height(),
- favicon_x,
- (height() - crashed_fav_icon->height()) / 2 +
- fav_icon_hiding_offset_,
- kFavIconSize, kFavIconSize,
- true);
+ ResourceBundle& rb = ResourceBundle::GetSharedInstance();
+ SkBitmap crashed_fav_icon(*rb.GetBitmapNamed(IDR_SAD_FAVICON));
+ canvas->DrawBitmapInt(crashed_fav_icon, 0, 0, crashed_fav_icon.width(),
+ crashed_fav_icon.height(), favicon_x,
+ (height() - crashed_fav_icon.height()) / 2 + fav_icon_hiding_offset_,
+ kFavIconSize, kFavIconSize, true);
} else {
if (!data().favicon.isNull()) {
// TODO(pkasting): Use code in tab_icon_view.cc:PaintIcon() (or switch
@@ -444,10 +444,6 @@ void BaseTab::ShowContextMenu(views::View* source,
controller()->ShowContextMenu(this, p);
}
-void BaseTab::OnThemeChanged() {
- LoadThemeImages();
-}
-
void BaseTab::SetFavIconHidingOffset(int offset) {
fav_icon_hiding_offset_ = offset;
SchedulePaint();
@@ -481,50 +477,10 @@ bool BaseTab::IsPerformingCrashAnimation() const {
// static
void BaseTab::InitResources() {
static bool initialized = false;
- if (initialized)
- return;
-
- initialized = true;
-
- ResourceBundle& rb = ResourceBundle::GetSharedInstance();
-
- crashed_fav_icon = rb.GetBitmapNamed(IDR_SAD_FAVICON);
-
- close_button_n = rb.GetBitmapNamed(IDR_TAB_CLOSE);
- close_button_h = rb.GetBitmapNamed(IDR_TAB_CLOSE_H);
- close_button_p = rb.GetBitmapNamed(IDR_TAB_CLOSE_P);
-
- close_button_width_ = close_button_n->width();
- close_button_height_ = close_button_n->height();
-
- // The loading animation image is a strip of states. Each state must be
- // square, so the height must divide the width evenly.
- loading_animation_frames = rb.GetBitmapNamed(IDR_THROBBER);
- loading_animation_size_ = loading_animation_frames->height();
- DCHECK(loading_animation_frames);
- DCHECK(loading_animation_frames->width() %
- loading_animation_frames->height() == 0);
- loading_animation_frame_count =
- loading_animation_frames->width() / loading_animation_frames->height();
-
- waiting_animation_frames = rb.GetBitmapNamed(IDR_THROBBER_WAITING);
- DCHECK(waiting_animation_frames);
- DCHECK(waiting_animation_frames->width() %
- waiting_animation_frames->height() == 0);
- waiting_animation_frame_count =
- waiting_animation_frames->width() / waiting_animation_frames->height();
-
- waiting_to_loading_frame_count_ratio =
- waiting_animation_frame_count / loading_animation_frame_count;
-
- font_ = new gfx::Font(rb.GetFont(ResourceBundle::BaseFont));
- font_height_ = font_->height();
-}
-
-// static
-void BaseTab::LoadThemeImages() {
- ResourceBundle& rb = ResourceBundle::GetSharedInstance();
- loading_animation_frames = rb.GetBitmapNamed(IDR_THROBBER);
- waiting_animation_frames = rb.GetBitmapNamed(IDR_THROBBER_WAITING);
- loading_animation_size_ = loading_animation_frames->height();
+ if (!initialized) {
+ initialized = true;
+ font_ = new gfx::Font(
+ ResourceBundle::GetSharedInstance().GetFont(ResourceBundle::BaseFont));
+ font_height_ = font_->height();
+ }
}
diff --git a/chrome/browser/views/tabs/base_tab.h b/chrome/browser/views/tabs/base_tab.h
index 8bf19ee..02a1362 100644
--- a/chrome/browser/views/tabs/base_tab.h
+++ b/chrome/browser/views/tabs/base_tab.h
@@ -128,19 +128,9 @@ class BaseTab : public AnimationDelegate,
const gfx::Point& p,
bool is_mouse_gesture);
- // views::View overrides:
- virtual void OnThemeChanged();
-
// Returns the bounds of the title.
virtual const gfx::Rect& title_bounds() const = 0;
- // Close button size.
- static int close_button_height() { return close_button_height_; }
- static int close_button_width() { return close_button_width_; }
-
- // Size (width/height) of the loading animation.
- static int loading_animation_size() { return loading_animation_size_; }
-
static gfx::Font* font() { return font_; }
static int font_height() { return font_height_; }
@@ -164,9 +154,6 @@ class BaseTab : public AnimationDelegate,
static void InitResources();
- // Invoked when the theme changes to reload theme images.
- static void LoadThemeImages();
-
// The controller.
// WARNING: this is null during detached tab dragging.
TabController* controller_;
@@ -208,13 +195,6 @@ class BaseTab : public AnimationDelegate,
bool should_display_crashed_favicon_;
- // Size of the close button.
- static int close_button_width_;
- static int close_button_height_;
-
- // Size of the loading animation frames.
- static int loading_animation_size_;
-
static gfx::Font* font_;
static int font_height_;
diff --git a/chrome/browser/views/tabs/tab.cc b/chrome/browser/views/tabs/tab.cc
index f2e9a97..974be4a 100644
--- a/chrome/browser/views/tabs/tab.cc
+++ b/chrome/browser/views/tabs/tab.cc
@@ -235,7 +235,8 @@ void Tab::Layout() {
// The height of the content of the Tab is the largest of the favicon,
// the title text and the close button graphic.
int content_height = std::max(kFavIconSize, font_height());
- content_height = std::max(content_height, close_button_height());
+ gfx::Size close_button_size(close_button()->GetPreferredSize());
+ content_height = std::max(content_height, close_button_size.height());
// Size the Favicon.
showing_icon_ = ShouldShowIcon();
@@ -272,13 +273,12 @@ void Tab::Layout() {
// Size the Close button.
showing_close_button_ = ShouldShowCloseBox();
if (showing_close_button_) {
- int close_button_top =
- kTopPadding + kCloseButtonVertFuzz +
- (content_height - close_button_height()) / 2;
+ int close_button_top = kTopPadding + kCloseButtonVertFuzz +
+ (content_height - close_button_size.height()) / 2;
// If the ratio of the close button size to tab width exceeds the maximum.
close_button()->SetBounds(lb.width() + kCloseButtonHorzFuzz,
- close_button_top, close_button_width(),
- close_button_height());
+ close_button_top, close_button_size.width(),
+ close_button_size.height());
close_button()->SetVisible(true);
} else {
close_button()->SetBounds(0, 0, 0, 0);