diff options
-rw-r--r-- | chrome/browser/gtk/browser_toolbar_gtk.cc | 24 | ||||
-rw-r--r-- | chrome/browser/gtk/download_item_gtk.cc | 122 | ||||
-rw-r--r-- | chrome/browser/gtk/gtk_chrome_button.cc | 64 | ||||
-rw-r--r-- | chrome/browser/gtk/nine_box.cc | 15 | ||||
-rw-r--r-- | chrome/browser/gtk/nine_box.h | 7 |
5 files changed, 103 insertions, 129 deletions
diff --git a/chrome/browser/gtk/browser_toolbar_gtk.cc b/chrome/browser/gtk/browser_toolbar_gtk.cc index 798c2f7..0ceba4b 100644 --- a/chrome/browser/gtk/browser_toolbar_gtk.cc +++ b/chrome/browser/gtk/browser_toolbar_gtk.cc @@ -401,18 +401,14 @@ CustomDrawButton* BrowserToolbarGtk::MakeHomeButton() { } void BrowserToolbarGtk::InitNineBox() { - ResourceBundle &rb = ResourceBundle::GetSharedInstance(); - - GdkPixbuf* images[9] = { - rb.GetPixbufNamed(IDR_CONTENT_TOP_LEFT_CORNER), - rb.GetPixbufNamed(IDR_CONTENT_TOP_CENTER), - rb.GetPixbufNamed(IDR_CONTENT_TOP_RIGHT_CORNER), - rb.GetPixbufNamed(IDR_CONTENT_LEFT_SIDE), - NULL, - rb.GetPixbufNamed(IDR_CONTENT_RIGHT_SIDE), - rb.GetPixbufNamed(IDR_CONTENT_BOTTOM_LEFT_CORNER), - rb.GetPixbufNamed(IDR_CONTENT_BOTTOM_CENTER), - rb.GetPixbufNamed(IDR_CONTENT_BOTTOM_RIGHT_CORNER) - }; - background_ninebox_.reset(new NineBox(images)); + background_ninebox_.reset(new NineBox( + IDR_CONTENT_TOP_LEFT_CORNER, + IDR_CONTENT_TOP_CENTER, + IDR_CONTENT_TOP_RIGHT_CORNER, + IDR_CONTENT_LEFT_SIDE, + 0, + IDR_CONTENT_RIGHT_SIDE, + IDR_CONTENT_BOTTOM_LEFT_CORNER, + IDR_CONTENT_BOTTOM_CENTER, + IDR_CONTENT_BOTTOM_RIGHT_CORNER)); } diff --git a/chrome/browser/gtk/download_item_gtk.cc b/chrome/browser/gtk/download_item_gtk.cc index e877590..1d06469 100644 --- a/chrome/browser/gtk/download_item_gtk.cc +++ b/chrome/browser/gtk/download_item_gtk.cc @@ -13,7 +13,6 @@ #include "chrome/browser/gtk/nine_box.h" #include "chrome/common/gfx/chrome_font.h" #include "chrome/common/gfx/text_elider.h" -#include "chrome/common/resource_bundle.h" #include "grit/generated_resources.h" #include "grit/theme_resources.h" @@ -222,80 +221,53 @@ void DownloadItemGtk::InitNineBoxes() { if (body_nine_box_normal_) return; - GdkPixbuf* images[9]; - ResourceBundle &rb = ResourceBundle::GetSharedInstance(); - - int i = 0; - images[i++] = rb.GetPixbufNamed(IDR_DOWNLOAD_BUTTON_LEFT_TOP); - images[i++] = rb.GetPixbufNamed(IDR_DOWNLOAD_BUTTON_CENTER_TOP); - images[i++] = rb.GetPixbufNamed(IDR_DOWNLOAD_BUTTON_RIGHT_TOP); - images[i++] = rb.GetPixbufNamed(IDR_DOWNLOAD_BUTTON_LEFT_MIDDLE); - images[i++] = rb.GetPixbufNamed(IDR_DOWNLOAD_BUTTON_CENTER_MIDDLE); - images[i++] = rb.GetPixbufNamed(IDR_DOWNLOAD_BUTTON_RIGHT_MIDDLE); - images[i++] = rb.GetPixbufNamed(IDR_DOWNLOAD_BUTTON_LEFT_BOTTOM); - images[i++] = rb.GetPixbufNamed(IDR_DOWNLOAD_BUTTON_CENTER_BOTTOM); - images[i++] = rb.GetPixbufNamed(IDR_DOWNLOAD_BUTTON_RIGHT_BOTTOM); - body_nine_box_normal_ = new NineBox(images); - - i = 0; - images[i++] = rb.GetPixbufNamed(IDR_DOWNLOAD_BUTTON_LEFT_TOP_H); - images[i++] = rb.GetPixbufNamed(IDR_DOWNLOAD_BUTTON_CENTER_TOP_H); - images[i++] = rb.GetPixbufNamed(IDR_DOWNLOAD_BUTTON_RIGHT_TOP_H); - images[i++] = rb.GetPixbufNamed(IDR_DOWNLOAD_BUTTON_LEFT_MIDDLE_H); - images[i++] = rb.GetPixbufNamed(IDR_DOWNLOAD_BUTTON_CENTER_MIDDLE_H); - images[i++] = rb.GetPixbufNamed(IDR_DOWNLOAD_BUTTON_RIGHT_MIDDLE_H); - images[i++] = rb.GetPixbufNamed(IDR_DOWNLOAD_BUTTON_LEFT_BOTTOM_H); - images[i++] = rb.GetPixbufNamed(IDR_DOWNLOAD_BUTTON_CENTER_BOTTOM_H); - images[i++] = rb.GetPixbufNamed(IDR_DOWNLOAD_BUTTON_RIGHT_BOTTOM_H); - body_nine_box_prelight_ = new NineBox(images); - - i = 0; - images[i++] = rb.GetPixbufNamed(IDR_DOWNLOAD_BUTTON_LEFT_TOP_P); - images[i++] = rb.GetPixbufNamed(IDR_DOWNLOAD_BUTTON_CENTER_TOP_P); - images[i++] = rb.GetPixbufNamed(IDR_DOWNLOAD_BUTTON_RIGHT_TOP_P); - images[i++] = rb.GetPixbufNamed(IDR_DOWNLOAD_BUTTON_LEFT_MIDDLE_P); - images[i++] = rb.GetPixbufNamed(IDR_DOWNLOAD_BUTTON_CENTER_MIDDLE_P); - images[i++] = rb.GetPixbufNamed(IDR_DOWNLOAD_BUTTON_RIGHT_MIDDLE_P); - images[i++] = rb.GetPixbufNamed(IDR_DOWNLOAD_BUTTON_LEFT_BOTTOM_P); - images[i++] = rb.GetPixbufNamed(IDR_DOWNLOAD_BUTTON_CENTER_BOTTOM_P); - images[i++] = rb.GetPixbufNamed(IDR_DOWNLOAD_BUTTON_RIGHT_BOTTOM_P); - body_nine_box_active_ = new NineBox(images); - - i = 0; - images[i++] = rb.GetPixbufNamed(IDR_DOWNLOAD_BUTTON_MENU_TOP); - images[i++] = NULL; - images[i++] = NULL; - images[i++] = rb.GetPixbufNamed(IDR_DOWNLOAD_BUTTON_MENU_MIDDLE); - images[i++] = NULL; - images[i++] = NULL; - images[i++] = rb.GetPixbufNamed(IDR_DOWNLOAD_BUTTON_MENU_BOTTOM); - images[i++] = NULL; - images[i++] = NULL; - menu_nine_box_normal_ = new NineBox(images); - - i = 0; - images[i++] = rb.GetPixbufNamed(IDR_DOWNLOAD_BUTTON_MENU_TOP_H); - images[i++] = NULL; - images[i++] = NULL; - images[i++] = rb.GetPixbufNamed(IDR_DOWNLOAD_BUTTON_MENU_MIDDLE_H); - images[i++] = NULL; - images[i++] = NULL; - images[i++] = rb.GetPixbufNamed(IDR_DOWNLOAD_BUTTON_MENU_BOTTOM_H); - images[i++] = NULL; - images[i++] = NULL; - menu_nine_box_prelight_ = new NineBox(images); - - i = 0; - images[i++] = rb.GetPixbufNamed(IDR_DOWNLOAD_BUTTON_MENU_TOP_P); - images[i++] = NULL; - images[i++] = NULL; - images[i++] = rb.GetPixbufNamed(IDR_DOWNLOAD_BUTTON_MENU_MIDDLE_P); - images[i++] = NULL; - images[i++] = NULL; - images[i++] = rb.GetPixbufNamed(IDR_DOWNLOAD_BUTTON_MENU_BOTTOM_P); - images[i++] = NULL; - images[i++] = NULL; - menu_nine_box_active_ = new NineBox(images); + body_nine_box_normal_ = new NineBox( + IDR_DOWNLOAD_BUTTON_LEFT_TOP, + IDR_DOWNLOAD_BUTTON_CENTER_TOP, + IDR_DOWNLOAD_BUTTON_RIGHT_TOP, + IDR_DOWNLOAD_BUTTON_LEFT_MIDDLE, + IDR_DOWNLOAD_BUTTON_CENTER_MIDDLE, + IDR_DOWNLOAD_BUTTON_RIGHT_MIDDLE, + IDR_DOWNLOAD_BUTTON_LEFT_BOTTOM, + IDR_DOWNLOAD_BUTTON_CENTER_BOTTOM, + IDR_DOWNLOAD_BUTTON_RIGHT_BOTTOM); + + body_nine_box_prelight_ = new NineBox( + IDR_DOWNLOAD_BUTTON_LEFT_TOP_H, + IDR_DOWNLOAD_BUTTON_CENTER_TOP_H, + IDR_DOWNLOAD_BUTTON_RIGHT_TOP_H, + IDR_DOWNLOAD_BUTTON_LEFT_MIDDLE_H, + IDR_DOWNLOAD_BUTTON_CENTER_MIDDLE_H, + IDR_DOWNLOAD_BUTTON_RIGHT_MIDDLE_H, + IDR_DOWNLOAD_BUTTON_LEFT_BOTTOM_H, + IDR_DOWNLOAD_BUTTON_CENTER_BOTTOM_H, + IDR_DOWNLOAD_BUTTON_RIGHT_BOTTOM_H); + + body_nine_box_active_ = new NineBox( + IDR_DOWNLOAD_BUTTON_LEFT_TOP_P, + IDR_DOWNLOAD_BUTTON_CENTER_TOP_P, + IDR_DOWNLOAD_BUTTON_RIGHT_TOP_P, + IDR_DOWNLOAD_BUTTON_LEFT_MIDDLE_P, + IDR_DOWNLOAD_BUTTON_CENTER_MIDDLE_P, + IDR_DOWNLOAD_BUTTON_RIGHT_MIDDLE_P, + IDR_DOWNLOAD_BUTTON_LEFT_BOTTOM_P, + IDR_DOWNLOAD_BUTTON_CENTER_BOTTOM_P, + IDR_DOWNLOAD_BUTTON_RIGHT_BOTTOM_P); + + menu_nine_box_normal_ = new NineBox( + IDR_DOWNLOAD_BUTTON_MENU_TOP, 0, 0, + IDR_DOWNLOAD_BUTTON_MENU_MIDDLE, 0, 0, + IDR_DOWNLOAD_BUTTON_MENU_BOTTOM, 0, 0); + + menu_nine_box_prelight_ = new NineBox( + IDR_DOWNLOAD_BUTTON_MENU_TOP_H, 0, 0, + IDR_DOWNLOAD_BUTTON_MENU_MIDDLE_H, 0, 0, + IDR_DOWNLOAD_BUTTON_MENU_BOTTOM_H, 0, 0); + + menu_nine_box_active_ = new NineBox( + IDR_DOWNLOAD_BUTTON_MENU_TOP_P, 0, 0, + IDR_DOWNLOAD_BUTTON_MENU_MIDDLE_P, 0, 0, + IDR_DOWNLOAD_BUTTON_MENU_BOTTOM_P, 0, 0); } // static diff --git a/chrome/browser/gtk/gtk_chrome_button.cc b/chrome/browser/gtk/gtk_chrome_button.cc index 193a295..3206e9f 100644 --- a/chrome/browser/gtk/gtk_chrome_button.cc +++ b/chrome/browser/gtk/gtk_chrome_button.cc @@ -5,7 +5,6 @@ #include "chrome/browser/gtk/gtk_chrome_button.h" #include "base/basictypes.h" -#include "chrome/common/resource_bundle.h" #include "chrome/browser/gtk/nine_box.h" #include "grit/theme_resources.h" @@ -13,61 +12,56 @@ namespace { // The theme graphics for when the mouse is over the button. -scoped_ptr<NineBox> nine_box_prelight; +static NineBox* g_nine_box_prelight; // The theme graphics for when the button is clicked. -scoped_ptr<NineBox> nine_box_active; +static NineBox* g_nine_box_active; } G_BEGIN_DECLS G_DEFINE_TYPE (GtkChromeButton, gtk_chrome_button, GTK_TYPE_BUTTON) -static gboolean gtk_chrome_button_expose (GtkWidget *widget, - GdkEventExpose *event); +static gboolean gtk_chrome_button_expose(GtkWidget* widget, + GdkEventExpose* event); static void gtk_chrome_button_class_init(GtkChromeButtonClass *button_class) { GtkWidgetClass* widget_class = (GtkWidgetClass*)button_class; widget_class->expose_event = gtk_chrome_button_expose; - GdkPixbuf* images[9]; - int i = 0; - - ResourceBundle& rb = ResourceBundle::GetSharedInstance(); - images[i++] = rb.GetPixbufNamed(IDR_TEXTBUTTON_TOP_LEFT_H); - images[i++] = rb.GetPixbufNamed(IDR_TEXTBUTTON_TOP_H); - images[i++] = rb.GetPixbufNamed(IDR_TEXTBUTTON_TOP_RIGHT_H); - images[i++] = rb.GetPixbufNamed(IDR_TEXTBUTTON_LEFT_H); - images[i++] = rb.GetPixbufNamed(IDR_TEXTBUTTON_CENTER_H); - images[i++] = rb.GetPixbufNamed(IDR_TEXTBUTTON_RIGHT_H); - images[i++] = rb.GetPixbufNamed(IDR_TEXTBUTTON_BOTTOM_LEFT_H); - images[i++] = rb.GetPixbufNamed(IDR_TEXTBUTTON_BOTTOM_H); - images[i++] = rb.GetPixbufNamed(IDR_TEXTBUTTON_BOTTOM_RIGHT_H); - nine_box_prelight.reset(new NineBox(images)); - - i = 0; - images[i++] = rb.GetPixbufNamed(IDR_TEXTBUTTON_TOP_LEFT_P); - images[i++] = rb.GetPixbufNamed(IDR_TEXTBUTTON_TOP_P); - images[i++] = rb.GetPixbufNamed(IDR_TEXTBUTTON_TOP_RIGHT_P); - images[i++] = rb.GetPixbufNamed(IDR_TEXTBUTTON_LEFT_P); - images[i++] = rb.GetPixbufNamed(IDR_TEXTBUTTON_CENTER_P); - images[i++] = rb.GetPixbufNamed(IDR_TEXTBUTTON_RIGHT_P); - images[i++] = rb.GetPixbufNamed(IDR_TEXTBUTTON_BOTTOM_LEFT_P); - images[i++] = rb.GetPixbufNamed(IDR_TEXTBUTTON_BOTTOM_P); - images[i++] = rb.GetPixbufNamed(IDR_TEXTBUTTON_BOTTOM_RIGHT_P); - nine_box_active.reset(new NineBox(images)); + g_nine_box_prelight = new NineBox( + IDR_TEXTBUTTON_TOP_LEFT_H, + IDR_TEXTBUTTON_TOP_H, + IDR_TEXTBUTTON_TOP_RIGHT_H, + IDR_TEXTBUTTON_LEFT_H, + IDR_TEXTBUTTON_CENTER_H, + IDR_TEXTBUTTON_RIGHT_H, + IDR_TEXTBUTTON_BOTTOM_LEFT_H, + IDR_TEXTBUTTON_BOTTOM_H, + IDR_TEXTBUTTON_BOTTOM_RIGHT_H); + + g_nine_box_active = new NineBox( + IDR_TEXTBUTTON_TOP_LEFT_P, + IDR_TEXTBUTTON_TOP_P, + IDR_TEXTBUTTON_TOP_RIGHT_P, + IDR_TEXTBUTTON_LEFT_P, + IDR_TEXTBUTTON_CENTER_P, + IDR_TEXTBUTTON_RIGHT_P, + IDR_TEXTBUTTON_BOTTOM_LEFT_P, + IDR_TEXTBUTTON_BOTTOM_P, + IDR_TEXTBUTTON_BOTTOM_RIGHT_P); } static void gtk_chrome_button_init(GtkChromeButton* button) { gtk_widget_set_app_paintable(GTK_WIDGET(button), TRUE); } -static gboolean gtk_chrome_button_expose (GtkWidget *widget, - GdkEventExpose *event) { +static gboolean gtk_chrome_button_expose(GtkWidget* widget, + GdkEventExpose* event) { NineBox* nine_box = NULL; if (GTK_WIDGET_STATE(widget) == GTK_STATE_PRELIGHT) - nine_box = nine_box_prelight.get(); + nine_box = g_nine_box_prelight; else if (GTK_WIDGET_STATE(widget) == GTK_STATE_ACTIVE) - nine_box = nine_box_active.get(); + nine_box = g_nine_box_active; // Only draw theme graphics if we have some. if (nine_box) diff --git a/chrome/browser/gtk/nine_box.cc b/chrome/browser/gtk/nine_box.cc index c1147c7..677d8fb 100644 --- a/chrome/browser/gtk/nine_box.cc +++ b/chrome/browser/gtk/nine_box.cc @@ -7,6 +7,7 @@ #include "base/gfx/gtk_util.h" #include "base/gfx/point.h" #include "base/logging.h" +#include "chrome/common/resource_bundle.h" namespace { @@ -33,8 +34,18 @@ void DrawPixbuf(GtkWidget* dst, GdkPixbuf* src, int x, int y) { } // anonymous namespace -NineBox::NineBox(GdkPixbuf* images[9]) { - memcpy(images_, images, 9*sizeof(GdkPixbuf*)); +NineBox::NineBox(int top_left, int top, int top_right, int left, int center, + int right, int bottom_left, int bottom, int bottom_right) { + ResourceBundle& rb = ResourceBundle::GetSharedInstance(); + images_[0] = top_left ? rb.GetPixbufNamed(top_left) : NULL; + images_[1] = top ? rb.GetPixbufNamed(top) : NULL; + images_[2] = top_right ? rb.GetPixbufNamed(top_right) : NULL; + images_[3] = left ? rb.GetPixbufNamed(left) : NULL; + images_[4] = center ? rb.GetPixbufNamed(center) : NULL; + images_[5] = right ? rb.GetPixbufNamed(right) : NULL; + images_[6] = bottom_left ? rb.GetPixbufNamed(bottom_left) : NULL; + images_[7] = bottom ? rb.GetPixbufNamed(bottom) : NULL; + images_[8] = bottom_right ? rb.GetPixbufNamed(bottom_right) : NULL; } NineBox::~NineBox() { diff --git a/chrome/browser/gtk/nine_box.h b/chrome/browser/gtk/nine_box.h index cf15b81..c4c5414 100644 --- a/chrome/browser/gtk/nine_box.h +++ b/chrome/browser/gtk/nine_box.h @@ -20,9 +20,10 @@ // nineboxes. class NineBox { public: - // Construct a NineBox with nine images. NULL images are allowed. - // Takes ownership of each image, but not the |images| array. - NineBox(GdkPixbuf* images[9]); + // Construct a NineBox with nine images. Images are specified using resource + // ids that will be passed to the resource bundle. Use 0 for no image. + NineBox(int top_left, int top, int top_right, int left, int center, int right, + int bottom_left, int bottom, int bottom_right); ~NineBox(); // Render the NineBox to |dst|. |