summaryrefslogtreecommitdiffstats
path: root/chrome/browser
diff options
context:
space:
mode:
authorerg@google.com <erg@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2009-07-10 19:55:30 +0000
committererg@google.com <erg@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2009-07-10 19:55:30 +0000
commitd995479a4149e65e23f5651a79cf605711ea081d (patch)
treebcb9e82f68beff680aca8f4eec794705d248b102 /chrome/browser
parentaf62bb4afd0dba5e607643f818a08a2aec642a80 (diff)
downloadchromium_src-d995479a4149e65e23f5651a79cf605711ea081d.zip
chromium_src-d995479a4149e65e23f5651a79cf605711ea081d.tar.gz
chromium_src-d995479a4149e65e23f5651a79cf605711ea081d.tar.bz2
GTK Themes: Set bg/text colors for the download shelf.
(This does not change the button image.) Review URL: http://codereview.chromium.org/155365 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@20403 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser')
-rw-r--r--chrome/browser/download/download_shelf.h2
-rw-r--r--chrome/browser/gtk/browser_window_gtk.cc3
-rw-r--r--chrome/browser/gtk/download_item_gtk.cc61
-rw-r--r--chrome/browser/gtk/download_item_gtk.h17
-rw-r--r--chrome/browser/gtk/download_shelf_gtk.cc25
-rw-r--r--chrome/browser/gtk/download_shelf_gtk.h7
6 files changed, 95 insertions, 20 deletions
diff --git a/chrome/browser/download/download_shelf.h b/chrome/browser/download/download_shelf.h
index 1ad0b71..c0d3c09 100644
--- a/chrome/browser/download/download_shelf.h
+++ b/chrome/browser/download/download_shelf.h
@@ -47,6 +47,8 @@ class DownloadShelf {
// Closes the shelf.
virtual void Close() = 0;
+ Browser* browser() { return browser_; }
+
protected:
Browser* browser_;
diff --git a/chrome/browser/gtk/browser_window_gtk.cc b/chrome/browser/gtk/browser_window_gtk.cc
index 7331f3d..8240747 100644
--- a/chrome/browser/gtk/browser_window_gtk.cc
+++ b/chrome/browser/gtk/browser_window_gtk.cc
@@ -766,6 +766,9 @@ void BrowserWindowGtk::UserChangedTheme() {
bookmark_bar_->UserChangedTheme(&properties);
status_bubble_->UserChangedTheme(&properties);
tabstrip_->UserChangedTheme(&properties);
+ if (download_shelf_.get()) {
+ download_shelf_->UserChangedTheme(&properties);
+ }
}
int BrowserWindowGtk::GetExtraRenderViewHeight() const {
diff --git a/chrome/browser/gtk/download_item_gtk.cc b/chrome/browser/gtk/download_item_gtk.cc
index a442685..4e32462 100644
--- a/chrome/browser/gtk/download_item_gtk.cc
+++ b/chrome/browser/gtk/download_item_gtk.cc
@@ -13,12 +13,14 @@
#include "base/basictypes.h"
#include "base/string_util.h"
#include "base/time.h"
+#include "chrome/browser/browser.h"
#include "chrome/browser/browser_process.h"
#include "chrome/browser/download/download_item_model.h"
#include "chrome/browser/download/download_manager.h"
#include "chrome/browser/download/download_shelf.h"
#include "chrome/browser/download/download_util.h"
#include "chrome/browser/gtk/download_shelf_gtk.h"
+#include "chrome/browser/gtk/gtk_theme_provider.h"
#include "chrome/browser/gtk/menu_gtk.h"
#include "chrome/browser/gtk/nine_box.h"
#include "chrome/browser/gtk/standard_menus.h"
@@ -167,6 +169,8 @@ DownloadItemGtk::DownloadItemGtk(DownloadShelfGtk* parent_shelf,
BaseDownloadItemModel* download_model)
: parent_shelf_(parent_shelf),
menu_showing_(false),
+ use_gtk_colors_(GtkThemeProvider::UseSystemThemeGraphics(
+ parent_shelf->browser()->profile())),
progress_angle_(download_util::kStartAngleDegrees),
download_model_(download_model),
bounding_widget_(parent_shelf->GetRightBoundingWidget()),
@@ -195,14 +199,7 @@ DownloadItemGtk::DownloadItemGtk(DownloadShelfGtk* parent_shelf,
// use gfx::Font() to draw the text. This is why we need to add so
// much padding when we set the size request. We need to either use gfx::Font
// or somehow extend TextElider.
- std::wstring elided_filename = gfx::ElideFilename(
- get_download()->GetFileName(),
- gfx::Font(), kTextWidth);
- gchar* label_markup =
- g_markup_printf_escaped(kLabelColorMarkup, kFilenameColor,
- WideToUTF8(elided_filename).c_str());
- gtk_label_set_markup(GTK_LABEL(name_label_), label_markup);
- g_free(label_markup);
+ UpdateNameLabel();
status_label_ = gtk_label_new(NULL);
// Left align and vertically center the labels.
@@ -394,6 +391,7 @@ void DownloadItemGtk::OnDownloadUpdated(DownloadItem* download) {
}
std::wstring status_text = download_model_->GetStatusText();
+ status_text_ = WideToUTF8(status_text);
// Remove the status text label.
if (status_text.empty()) {
gtk_widget_destroy(status_label_);
@@ -401,11 +399,7 @@ void DownloadItemGtk::OnDownloadUpdated(DownloadItem* download) {
return;
}
- gchar* label_markup =
- g_markup_printf_escaped(kLabelColorMarkup, kStatusColor,
- WideToUTF8(status_text).c_str());
- gtk_label_set_markup(GTK_LABEL(status_label_), label_markup);
- g_free(label_markup);
+ UpdateStatusLabel(status_label_, status_text_);
}
void DownloadItemGtk::AnimationProgressed(const Animation* animation) {
@@ -460,6 +454,13 @@ void DownloadItemGtk::StopDownloadProgress() {
progress_timer_.Stop();
}
+void DownloadItemGtk::UserChangedTheme(GtkThemeProperties* properties) {
+ use_gtk_colors_ = properties->use_gtk_rendering;
+
+ UpdateNameLabel();
+ UpdateStatusLabel(status_label_, status_text_);
+}
+
// Icon loading functions.
void DownloadItemGtk::OnLoadIconComplete(IconManager::Handle handle,
@@ -475,6 +476,40 @@ void DownloadItemGtk::LoadIcon() {
NewCallback(this, &DownloadItemGtk::OnLoadIconComplete));
}
+void DownloadItemGtk::UpdateNameLabel() {
+ std::wstring elided_filename = gfx::ElideFilename(
+ get_download()->GetFileName(),
+ gfx::Font(), kTextWidth);
+ if (use_gtk_colors_) {
+ gtk_label_set_markup(GTK_LABEL(name_label_),
+ WideToUTF8(elided_filename).c_str());
+ } else {
+ gchar* label_markup =
+ g_markup_printf_escaped(kLabelColorMarkup, kFilenameColor,
+ WideToUTF8(elided_filename).c_str());
+ gtk_label_set_markup(GTK_LABEL(name_label_), label_markup);
+ g_free(label_markup);
+ }
+}
+
+void DownloadItemGtk::UpdateStatusLabel(GtkWidget* status_label,
+ const std::string& status_text) {
+ if (status_label) {
+ if (use_gtk_colors_) {
+ gtk_label_set_label(GTK_LABEL(status_label), status_text.c_str());
+ } else {
+ // TODO(erg): I am not sure which ThemeProvider color I'm supposed to use
+ // here. I am also not sure if using set_markup is the correct course of
+ // action compared to modifying the GtkStyle->text[].
+ gchar* label_markup =
+ g_markup_printf_escaped(kLabelColorMarkup, kStatusColor,
+ status_text.c_str());
+ gtk_label_set_markup(GTK_LABEL(status_label), label_markup);
+ g_free(label_markup);
+ }
+ }
+}
+
// static
void DownloadItemGtk::InitNineBoxes() {
if (body_nine_box_normal_)
diff --git a/chrome/browser/gtk/download_item_gtk.h b/chrome/browser/gtk/download_item_gtk.h
index 832302e..bae5cbd 100644
--- a/chrome/browser/gtk/download_item_gtk.h
+++ b/chrome/browser/gtk/download_item_gtk.h
@@ -16,6 +16,7 @@
class BaseDownloadItemModel;
class DownloadShelfContextMenuGtk;
class DownloadShelfGtk;
+class GtkThemeProperties;
class NineBox;
class SkBitmap;
class SlideAnimation;
@@ -37,6 +38,9 @@ class DownloadItemGtk : public DownloadItem::Observer,
// AnimationDelegate implementation.
virtual void AnimationProgressed(const Animation* animation);
+ // Changes the color of the background shelf.
+ void UserChangedTheme(GtkThemeProperties* properties);
+
// Called when the icon manager has finished loading the icon. We take
// ownership of |icon_bitmap|.
void OnLoadIconComplete(IconManager::Handle handle, SkBitmap* icon_bitmap);
@@ -62,6 +66,13 @@ class DownloadItemGtk : public DownloadItem::Observer,
// Ask the icon manager to asynchronously start loading the icon for the file.
void LoadIcon();
+ // Sets the name label to the correct color.
+ void UpdateNameLabel();
+
+ // Sets the text with the correct color if |status_label| exists.
+ void UpdateStatusLabel(GtkWidget* status_label,
+ const std::string& status_text);
+
static void InitNineBoxes();
// Used for the download item's body and menu button.
@@ -121,6 +132,9 @@ class DownloadItemGtk : public DownloadItem::Observer,
// The GtkLabel that holds the status text.
GtkWidget* status_label_;
+ // The current text of status label
+ std::string status_text_;
+
// The widget that creates a dropdown menu when pressed.
GtkWidget* menu_button_;
@@ -128,6 +142,9 @@ class DownloadItemGtk : public DownloadItem::Observer,
// draw the button.
bool menu_showing_;
+ // Whether we should use the GTK text color
+ bool use_gtk_colors_;
+
// The widget that contains the animation progress and the file's icon
// (as well as the complete animation).
OwnedWidgetGtk progress_area_;
diff --git a/chrome/browser/gtk/download_shelf_gtk.cc b/chrome/browser/gtk/download_shelf_gtk.cc
index ceb8979..a0f523c 100644
--- a/chrome/browser/gtk/download_shelf_gtk.cc
+++ b/chrome/browser/gtk/download_shelf_gtk.cc
@@ -14,6 +14,7 @@
#include "chrome/browser/gtk/custom_button.h"
#include "chrome/browser/gtk/download_item_gtk.h"
#include "chrome/browser/gtk/gtk_chrome_link_button.h"
+#include "chrome/browser/gtk/gtk_theme_provider.h"
#include "chrome/browser/gtk/slide_animator_gtk.h"
#include "chrome/browser/tab_contents/tab_contents.h"
#include "chrome/common/gtk_util.h"
@@ -38,9 +39,6 @@ const int kLeftPadding = 2;
// Padding between the right side of the shelf and the close button.
const int kRightPadding = 10;
-// The background color of the shelf.
-const GdkColor kBackgroundColor = GDK_COLOR_RGB(230, 237, 244);
-
// Border color (the top pixel of the shelf).
const GdkColor kBorderColor = GDK_COLOR_RGB(214, 214, 214);
@@ -74,14 +72,13 @@ DownloadShelfGtk::DownloadShelfGtk(Browser* browser, GtkWidget* parent)
// Subtract 1 from top spacing to account for top border.
gtk_alignment_set_padding(GTK_ALIGNMENT(padding),
kTopBottomPadding - 1, kTopBottomPadding, kLeftPadding, kRightPadding);
- GtkWidget* padding_bg = gtk_event_box_new();
- gtk_container_add(GTK_CONTAINER(padding_bg), padding);
+ padding_bg_ = gtk_event_box_new();
+ gtk_container_add(GTK_CONTAINER(padding_bg_), padding);
gtk_container_add(GTK_CONTAINER(padding), hbox_.get());
- gtk_widget_modify_bg(padding_bg, GTK_STATE_NORMAL, &kBackgroundColor);
GtkWidget* vbox = gtk_vbox_new(FALSE, 0);
gtk_box_pack_start(GTK_BOX(vbox), top_border, FALSE, FALSE, 0);
- gtk_box_pack_start(GTK_BOX(vbox), padding_bg, FALSE, FALSE, 0);
+ gtk_box_pack_start(GTK_BOX(vbox), padding_bg_, FALSE, FALSE, 0);
// Put the shelf in an event box so it gets its own window, which makes it
// easier to get z-ordering right.
@@ -120,6 +117,10 @@ DownloadShelfGtk::DownloadShelfGtk(Browser* browser, GtkWidget* parent)
SlideAnimatorGtk::UP,
kShelfAnimationDurationMs,
false, NULL));
+
+ GtkThemeProperties properties(browser->profile());
+ UserChangedTheme(&properties);
+
gtk_widget_show_all(shelf_.get());
// Stick ourselves at the bottom of the parent browser.
@@ -169,6 +170,16 @@ int DownloadShelfGtk::GetHeight() const {
return slide_widget_->widget()->allocation.height;
}
+void DownloadShelfGtk::UserChangedTheme(GtkThemeProperties* properties) {
+ GdkColor color = properties->GetGdkColor(BrowserThemeProvider::COLOR_TOOLBAR);
+ gtk_widget_modify_bg(padding_bg_, GTK_STATE_NORMAL, &color);
+
+ for (std::vector<DownloadItemGtk*>::iterator it = download_items_.begin();
+ it != download_items_.end(); ++it) {
+ (*it)->UserChangedTheme(properties);
+ }
+}
+
void DownloadShelfGtk::RemoveDownloadItem(DownloadItemGtk* download_item) {
DCHECK(download_item);
std::vector<DownloadItemGtk*>::iterator i =
diff --git a/chrome/browser/gtk/download_shelf_gtk.h b/chrome/browser/gtk/download_shelf_gtk.h
index afafd27..9c8e382 100644
--- a/chrome/browser/gtk/download_shelf_gtk.h
+++ b/chrome/browser/gtk/download_shelf_gtk.h
@@ -18,6 +18,7 @@ class BaseDownloadItemModel;
class Browser;
class CustomDrawButton;
class DownloadItemGtk;
+class GtkThemeProperties;
class SlideAnimatorGtk;
class DownloadShelfGtk : public DownloadShelf {
@@ -36,6 +37,9 @@ class DownloadShelfGtk : public DownloadShelf {
// Returns the current height of the shelf.
int GetHeight() const;
+ // Changes the color of the background shelf.
+ void UserChangedTheme(GtkThemeProperties* properties);
+
private:
// Remove |download_item| from the download shelf and delete it.
void RemoveDownloadItem(DownloadItemGtk* download_item);
@@ -58,6 +62,9 @@ class DownloadShelfGtk : public DownloadShelf {
// for an explanation of the widget layout.
OwnedWidgetGtk shelf_;
+ // A GtkEventBox which we color.
+ GtkWidget* padding_bg_;
+
// This hbox holds the link text and download icon. It also holds the
// distinction of being the leftmost non-download item widget on the shelf.
GtkWidget* link_hbox_;