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
Esse commit está contido em:
erg@google.com
2009-07-10 19:55:30 +00:00
commit be7629a8bd
6 arquivos alterados com 95 adições e 20 exclusões
+2
Ver Arquivo
@@ -47,6 +47,8 @@ class DownloadShelf {
// Closes the shelf.
virtual void Close() = 0;
Browser* browser() { return browser_; }
protected:
Browser* browser_;
+3
Ver Arquivo
@@ -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 {
+48 -13
Ver Arquivo
@@ -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_)
+17
Ver Arquivo
@@ -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_;
+18 -7
Ver Arquivo
@@ -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 =
+7
Ver Arquivo
@@ -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_;