summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorerg@google.com <erg@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2009-07-15 23:36:05 +0000
committererg@google.com <erg@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2009-07-15 23:36:05 +0000
commit1caa3c45a35a72ba3cae29c277d34b44de8b1138 (patch)
treed581f1aaeecb0451748c702e6d22ecdfad4ca03d
parent4cab04d8c4c0c45ce63e03b5f255da4a92d70ff0 (diff)
downloadchromium_src-1caa3c45a35a72ba3cae29c277d34b44de8b1138.zip
chromium_src-1caa3c45a35a72ba3cae29c277d34b44de8b1138.tar.gz
chromium_src-1caa3c45a35a72ba3cae29c277d34b44de8b1138.tar.bz2
GTK Themes: Tint throbbers like we tint all other buttons in the interface.
Relanding with fixes for unit tests. Run through trybot this time... http://crbug.com/13967 Original Review URL: http://codereview.chromium.org/155588 TBR=estade Review URL: http://codereview.chromium.org/155601 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@20809 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r--chrome/browser/browser_theme_provider.cc2
-rw-r--r--chrome/browser/gtk/tabs/dragged_tab_gtk.cc3
-rw-r--r--chrome/browser/gtk/tabs/tab_gtk.cc2
-rw-r--r--chrome/browser/gtk/tabs/tab_gtk.h8
-rw-r--r--chrome/browser/gtk/tabs/tab_renderer_gtk.cc93
-rw-r--r--chrome/browser/gtk/tabs/tab_renderer_gtk.h27
-rw-r--r--chrome/browser/gtk/tabs/tab_renderer_gtk_unittest.cc17
-rw-r--r--chrome/browser/gtk/tabs/tab_strip_gtk.cc4
-rw-r--r--chrome/browser/gtk/tabs/tab_strip_gtk.h1
9 files changed, 106 insertions, 51 deletions
diff --git a/chrome/browser/browser_theme_provider.cc b/chrome/browser/browser_theme_provider.cc
index 5bf91fe..14a4f6e 100644
--- a/chrome/browser/browser_theme_provider.cc
+++ b/chrome/browser/browser_theme_provider.cc
@@ -132,7 +132,7 @@ static const int kToolbarButtonIDs[] = {
IDR_MENU_PAGE, IDR_MENU_PAGE_RTL,
IDR_MENU_CHROME, IDR_MENU_CHROME_RTL,
IDR_MENU_DROPARROW,
- IDR_THROBBER,
+ IDR_THROBBER, IDR_THROBBER_WAITING, IDR_THROBBER_LIGHT
};
// A map for kToolbarButtonIDs.
diff --git a/chrome/browser/gtk/tabs/dragged_tab_gtk.cc b/chrome/browser/gtk/tabs/dragged_tab_gtk.cc
index 124f6eb..afe79c7 100644
--- a/chrome/browser/gtk/tabs/dragged_tab_gtk.cc
+++ b/chrome/browser/gtk/tabs/dragged_tab_gtk.cc
@@ -10,6 +10,7 @@
#include "app/gfx/canvas_paint.h"
#include "base/gfx/gtk_util.h"
+#include "chrome/browser/profile.h"
#include "chrome/browser/tab_contents/tab_contents.h"
#include "chrome/browser/tabs/tab_strip_model.h"
#include "chrome/browser/gtk/tabs/tab_renderer_gtk.h"
@@ -43,7 +44,7 @@ DraggedTabGtk::DraggedTabGtk(TabContents* datasource,
const gfx::Point& mouse_tab_offset,
const gfx::Size& contents_size)
: backing_store_(NULL),
- renderer_(new TabRendererGtk),
+ renderer_(new TabRendererGtk(datasource->profile()->GetThemeProvider())),
attached_(false),
mouse_tab_offset_(mouse_tab_offset),
attached_tab_size_(TabRendererGtk::GetMinimumSelectedSize()),
diff --git a/chrome/browser/gtk/tabs/tab_gtk.cc b/chrome/browser/gtk/tabs/tab_gtk.cc
index 34ffee1..bd63a5e 100644
--- a/chrome/browser/gtk/tabs/tab_gtk.cc
+++ b/chrome/browser/gtk/tabs/tab_gtk.cc
@@ -108,7 +108,7 @@ class TabGtk::ContextMenuController : public MenuGtk::Delegate {
// TabGtk, public:
TabGtk::TabGtk(TabDelegate* delegate)
- : TabRendererGtk(),
+ : TabRendererGtk(delegate->GetThemeProvider()),
delegate_(delegate),
closing_(false),
dragging_(false) {
diff --git a/chrome/browser/gtk/tabs/tab_gtk.h b/chrome/browser/gtk/tabs/tab_gtk.h
index 9abe929..384f7f6 100644
--- a/chrome/browser/gtk/tabs/tab_gtk.h
+++ b/chrome/browser/gtk/tabs/tab_gtk.h
@@ -5,6 +5,7 @@
#ifndef CHROME_BROWSER_GTK_TABS_TAB_GTK_H_
#define CHROME_BROWSER_GTK_TABS_TAB_GTK_H_
+#include "app/theme_provider.h"
#include "base/basictypes.h"
#include "base/message_loop.h"
#include "chrome/browser/gtk/tabs/tab_renderer_gtk.h"
@@ -14,6 +15,8 @@ namespace gfx {
class Path;
}
+class ThemeProvider;
+
class TabGtk : public TabRendererGtk,
public MessageLoopForUI::Observer {
public:
@@ -64,9 +67,12 @@ class TabGtk : public TabRendererGtk,
// itself should move the window in cases where there's only one
// non drag-able Tab.
virtual bool HasAvailableDragActions() const = 0;
+
+ // Returns the theme provider for icons and colors.
+ virtual ThemeProvider* GetThemeProvider() = 0;
};
- explicit TabGtk(TabDelegate* delegate);
+ TabGtk(TabDelegate* delegate);
virtual ~TabGtk();
// Access the delegate.
diff --git a/chrome/browser/gtk/tabs/tab_renderer_gtk.cc b/chrome/browser/gtk/tabs/tab_renderer_gtk.cc
index 55e4b32..3c5ebd9 100644
--- a/chrome/browser/gtk/tabs/tab_renderer_gtk.cc
+++ b/chrome/browser/gtk/tabs/tab_renderer_gtk.cc
@@ -14,6 +14,7 @@
#include "chrome/browser/profile.h"
#include "chrome/browser/tab_contents/tab_contents.h"
#include "chrome/common/gtk_util.h"
+#include "chrome/common/notification_service.h"
#include "grit/app_resources.h"
#include "grit/generated_resources.h"
#include "grit/theme_resources.h"
@@ -51,42 +52,47 @@ const int kCloseButtonHorzFuzz = 5;
SkBitmap* crashed_fav_icon = NULL;
-TabRendererGtk::LoadingAnimation::Data loading_animation_data;
+} // namespace
-// Loads the loading animation images and data.
-void InitializeLoadingAnimationData(
- ResourceBundle* rb, TabRendererGtk::LoadingAnimation::Data* data) {
+TabRendererGtk::LoadingAnimation::Data::Data(ThemeProvider* theme_provider) {
// The loading animation image is a strip of states. Each state must be
// square, so the height must divide the width evenly.
- data->loading_animation_frames = rb->GetBitmapNamed(IDR_THROBBER);
- DCHECK(data->loading_animation_frames);
- DCHECK_EQ(data->loading_animation_frames->width() %
- data->loading_animation_frames->height(), 0);
- data->loading_animation_frame_count =
- data->loading_animation_frames->width() /
- data->loading_animation_frames->height();
-
- data->waiting_animation_frames =
- rb->GetBitmapNamed(IDR_THROBBER_WAITING);
- DCHECK(data->waiting_animation_frames);
- DCHECK_EQ(data->waiting_animation_frames->width() %
- data->waiting_animation_frames->height(), 0);
- data->waiting_animation_frame_count =
- data->waiting_animation_frames->width() /
- data->waiting_animation_frames->height();
-
- data->waiting_to_loading_frame_count_ratio =
- data->waiting_animation_frame_count /
- data->loading_animation_frame_count;
+ loading_animation_frames = theme_provider->GetBitmapNamed(IDR_THROBBER);
+ DCHECK(loading_animation_frames);
+ DCHECK_EQ(loading_animation_frames->width() %
+ loading_animation_frames->height(), 0);
+ loading_animation_frame_count =
+ loading_animation_frames->width() /
+ loading_animation_frames->height();
+
+ waiting_animation_frames =
+ theme_provider->GetBitmapNamed(IDR_THROBBER_WAITING);
+ DCHECK(waiting_animation_frames);
+ DCHECK_EQ(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;
// TODO(beng): eventually remove this when we have a proper themeing system.
// themes not supporting IDR_THROBBER_WAITING are causing this
// value to be 0 which causes DIV0 crashes. The value of 5
// matches the current bitmaps in our source.
- if (data->waiting_to_loading_frame_count_ratio == 0)
- data->waiting_to_loading_frame_count_ratio = 5;
+ if (waiting_to_loading_frame_count_ratio == 0)
+ waiting_to_loading_frame_count_ratio = 5;
}
-} // namespace
+TabRendererGtk::LoadingAnimation::Data::Data(
+ int loading, int waiting, int waiting_to_loading)
+ : waiting_animation_frames(NULL),
+ loading_animation_frames(NULL),
+ loading_animation_frame_count(loading),
+ waiting_animation_frame_count(waiting),
+ waiting_to_loading_frame_count_ratio(waiting_to_loading) {
+}
bool TabRendererGtk::initialized_ = false;
TabRendererGtk::TabImage TabRendererGtk::tab_active_ = {0};
@@ -104,8 +110,23 @@ int TabRendererGtk::pinned_tab_pref_width_ = 0;
////////////////////////////////////////////////////////////////////////////////
// TabRendererGtk::LoadingAnimation, public:
//
-TabRendererGtk::LoadingAnimation::LoadingAnimation(const Data* data)
- : data_(data), animation_state_(ANIMATION_NONE), animation_frame_(0) {
+TabRendererGtk::LoadingAnimation::LoadingAnimation(
+ ThemeProvider* theme_provider)
+ : data_(new Data(theme_provider)),
+ theme_provider_(theme_provider),
+ animation_state_(ANIMATION_NONE),
+ animation_frame_(0) {
+ registrar_.Add(this,
+ NotificationType::BROWSER_THEME_CHANGED,
+ NotificationService::AllSources());
+}
+
+TabRendererGtk::LoadingAnimation::LoadingAnimation(
+ const LoadingAnimation::Data& data)
+ : data_(new Data(data)),
+ theme_provider_(NULL),
+ animation_state_(ANIMATION_NONE),
+ animation_frame_(0) {
}
void TabRendererGtk::LoadingAnimation::ValidateLoadingAnimation(
@@ -133,6 +154,14 @@ void TabRendererGtk::LoadingAnimation::ValidateLoadingAnimation(
}
}
+void TabRendererGtk::LoadingAnimation::Observe(
+ NotificationType type,
+ const NotificationSource& source,
+ const NotificationDetails& details) {
+ DCHECK(type == NotificationType::BROWSER_THEME_CHANGED);
+ data_.reset(new Data(theme_provider_));
+}
+
////////////////////////////////////////////////////////////////////////////////
// FaviconCrashAnimation
//
@@ -175,12 +204,12 @@ class TabRendererGtk::FavIconCrashAnimation : public Animation,
////////////////////////////////////////////////////////////////////////////////
// TabRendererGtk, public:
-TabRendererGtk::TabRendererGtk()
+TabRendererGtk::TabRendererGtk(ThemeProvider* theme_provider)
: showing_icon_(false),
showing_close_button_(false),
fav_icon_hiding_offset_(0),
should_display_crashed_favicon_(false),
- loading_animation_(&loading_animation_data) {
+ loading_animation_(theme_provider) {
InitResources();
data_.pinned = false;
@@ -795,8 +824,6 @@ void TabRendererGtk::InitResources() {
title_font_ = new gfx::Font(gfx::Font::CreateFont(base_font.FontName(), 10));
title_font_height_ = title_font_->height();
- InitializeLoadingAnimationData(&rb, &loading_animation_data);
-
crashed_fav_icon = rb.GetBitmapNamed(IDR_SAD_FAVICON);
initialized_ = true;
diff --git a/chrome/browser/gtk/tabs/tab_renderer_gtk.h b/chrome/browser/gtk/tabs/tab_renderer_gtk.h
index 9f52a6c..0168bbe 100644
--- a/chrome/browser/gtk/tabs/tab_renderer_gtk.h
+++ b/chrome/browser/gtk/tabs/tab_renderer_gtk.h
@@ -14,6 +14,8 @@
#include "base/basictypes.h"
#include "base/gfx/rect.h"
#include "base/string16.h"
+#include "chrome/common/notification_observer.h"
+#include "chrome/common/notification_registrar.h"
#include "chrome/common/owned_widget_gtk.h"
#include "third_party/skia/include/core/SkBitmap.h"
@@ -34,9 +36,12 @@ class TabRendererGtk : public AnimationDelegate {
ANIMATION_LOADING
};
- class LoadingAnimation {
+ class LoadingAnimation : public NotificationObserver {
public:
struct Data {
+ explicit Data(ThemeProvider* theme_provider);
+ Data(int loading, int waiting, int waiting_to_loading);
+
SkBitmap* waiting_animation_frames;
SkBitmap* loading_animation_frames;
int loading_animation_frame_count;
@@ -44,7 +49,10 @@ class TabRendererGtk : public AnimationDelegate {
int waiting_to_loading_frame_count_ratio;
};
- explicit LoadingAnimation(const Data* data);
+ explicit LoadingAnimation(ThemeProvider* theme_provider);
+
+ // Used in unit tests to inject specific data.
+ explicit LoadingAnimation(const LoadingAnimation::Data& data);
// Advance the loading animation to the next frame, or hide the animation if
// the tab isn't loading.
@@ -60,8 +68,19 @@ class TabRendererGtk : public AnimationDelegate {
return data_->loading_animation_frames;
}
+ // Provide NotificationObserver implementation.
+ virtual void Observe(NotificationType type,
+ const NotificationSource& source,
+ const NotificationDetails& details);
+
private:
- const Data* const data_;
+ scoped_ptr<Data> data_;
+
+ // Used to listen for theme change notifications.
+ NotificationRegistrar registrar_;
+
+ // Gives us our throbber images.
+ ThemeProvider* theme_provider_;
// Current state of the animation.
AnimationState animation_state_;
@@ -72,7 +91,7 @@ class TabRendererGtk : public AnimationDelegate {
DISALLOW_COPY_AND_ASSIGN(LoadingAnimation);
};
- TabRendererGtk();
+ explicit TabRendererGtk(ThemeProvider* theme_provider);
virtual ~TabRendererGtk();
// TabContents. If only the loading state was updated, the loading_only flag
diff --git a/chrome/browser/gtk/tabs/tab_renderer_gtk_unittest.cc b/chrome/browser/gtk/tabs/tab_renderer_gtk_unittest.cc
index 0304d26..10189da 100644
--- a/chrome/browser/gtk/tabs/tab_renderer_gtk_unittest.cc
+++ b/chrome/browser/gtk/tabs/tab_renderer_gtk_unittest.cc
@@ -14,23 +14,20 @@ const int kTestLoadingAnimationFrameCount = 10;
const int kTestWaitingAnimationFrameCount = 40;
const int kTestWaitingToLoadingFrameCountRatio = 4;
-const LoadingAnimation::Data kMockAnimationData = {
- NULL, // waiting_animation_frames
- NULL, // loading_animation_frames
- kTestLoadingAnimationFrameCount,
- kTestWaitingAnimationFrameCount,
- kTestWaitingToLoadingFrameCountRatio,
-};
+const LoadingAnimation::Data kMockAnimationData =
+ LoadingAnimation::Data(kTestLoadingAnimationFrameCount,
+ kTestWaitingAnimationFrameCount,
+ kTestWaitingToLoadingFrameCountRatio);
TEST(LoadingAnimationTest, InitialState) {
- LoadingAnimation loading_animation(&kMockAnimationData);
+ LoadingAnimation loading_animation(kMockAnimationData);
EXPECT_EQ(TabRendererGtk::ANIMATION_NONE,
loading_animation.animation_state());
EXPECT_EQ(0, loading_animation.animation_frame());
}
TEST(LoadingAnimationTest, AdvanceWaitingFrames) {
- LoadingAnimation loading_animation(&kMockAnimationData);
+ LoadingAnimation loading_animation(kMockAnimationData);
loading_animation.ValidateLoadingAnimation(TabRendererGtk::ANIMATION_WAITING);
EXPECT_EQ(TabRendererGtk::ANIMATION_WAITING,
loading_animation.animation_state());
@@ -57,7 +54,7 @@ TEST(LoadingAnimationTest, AdvanceWaitingFrames) {
}
TEST(LoadingAnimationTest, AdvanceFromWaitingToLoading) {
- LoadingAnimation loading_animation(&kMockAnimationData);
+ LoadingAnimation loading_animation(kMockAnimationData);
for (int i = 0; i < 2 * kTestWaitingToLoadingFrameCountRatio; ++i) {
loading_animation.ValidateLoadingAnimation(
TabRendererGtk::ANIMATION_WAITING);
diff --git a/chrome/browser/gtk/tabs/tab_strip_gtk.cc b/chrome/browser/gtk/tabs/tab_strip_gtk.cc
index 67e94d1..ed28ffc 100644
--- a/chrome/browser/gtk/tabs/tab_strip_gtk.cc
+++ b/chrome/browser/gtk/tabs/tab_strip_gtk.cc
@@ -1088,6 +1088,10 @@ bool TabStripGtk::HasAvailableDragActions() const {
return model_->delegate()->GetDragActions() != 0;
}
+ThemeProvider* TabStripGtk::GetThemeProvider() {
+ return theme_provider_;
+}
+
///////////////////////////////////////////////////////////////////////////////
// TabStripGtk, MessageLoop::Observer implementation:
diff --git a/chrome/browser/gtk/tabs/tab_strip_gtk.h b/chrome/browser/gtk/tabs/tab_strip_gtk.h
index 44bc870..94328ba 100644
--- a/chrome/browser/gtk/tabs/tab_strip_gtk.h
+++ b/chrome/browser/gtk/tabs/tab_strip_gtk.h
@@ -121,6 +121,7 @@ class TabStripGtk : public TabStripModelObserver,
virtual void ContinueDrag(GdkDragContext* context);
virtual bool EndDrag(bool canceled);
virtual bool HasAvailableDragActions() const;
+ virtual ThemeProvider* GetThemeProvider();
// MessageLoop::Observer implementation:
virtual void WillProcessEvent(GdkEvent* event);