| Index: chrome/browser/views/tabs/base_tab.cc
|
| ===================================================================
|
| --- chrome/browser/views/tabs/base_tab.cc (revision 53716)
|
| +++ chrome/browser/views/tabs/base_tab.cc (working copy)
|
| @@ -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 @@
|
| // 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 @@
|
| } // 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 @@
|
| 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 @@
|
|
|
| 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 @@
|
| 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,11 +444,6 @@
|
| controller()->ShowContextMenu(this, p);
|
| }
|
|
|
| -void BaseTab::ThemeChanged() {
|
| - views::View::ThemeChanged();
|
| - LoadThemeImages();
|
| -}
|
| -
|
| void BaseTab::SetFavIconHidingOffset(int offset) {
|
| fav_icon_hiding_offset_ = offset;
|
| SchedulePaint();
|
| @@ -482,50 +477,10 @@
|
| // 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();
|
| + if (!initialized) {
|
| + initialized = true;
|
| + font_ = new gfx::Font(
|
| + ResourceBundle::GetSharedInstance().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();
|
| -}
|
|
|