summaryrefslogtreecommitdiffstats
path: root/chrome/browser/gtk/nine_box.cc
diff options
context:
space:
mode:
authorestade@chromium.org <estade@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-03-31 20:13:38 +0000
committerestade@chromium.org <estade@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-03-31 20:13:38 +0000
commit4d041e362415549ddb4a9b03563fe6b466fc3b4b (patch)
tree7bf246cc859cc33197aec9953f01ce20b1e6ad0d /chrome/browser/gtk/nine_box.cc
parent3cebf7049265693f09bbd401ab20d3ff022ffc2c (diff)
downloadchromium_src-4d041e362415549ddb4a9b03563fe6b466fc3b4b.zip
chromium_src-4d041e362415549ddb4a9b03563fe6b466fc3b4b.tar.gz
chromium_src-4d041e362415549ddb4a9b03563fe6b466fc3b4b.tar.bz2
Fix ninebox rendering.
- Correct some wrong x/y coords. - Get rid of FillWidget. We can't paint the widget with a debugging color because some of our images are partially translucent, so the debug color will shine through. TEST=CustomContainerButton hover-over should now appear properly. Download items in the shelf should appear properly. Review URL: http://codereview.chromium.org/56091 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@12898 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/gtk/nine_box.cc')
-rw-r--r--chrome/browser/gtk/nine_box.cc38
1 files changed, 15 insertions, 23 deletions
diff --git a/chrome/browser/gtk/nine_box.cc b/chrome/browser/gtk/nine_box.cc
index 2c6c88d..5b8e45f 100644
--- a/chrome/browser/gtk/nine_box.cc
+++ b/chrome/browser/gtk/nine_box.cc
@@ -5,30 +5,32 @@
#include "chrome/browser/gtk/nine_box.h"
#include "base/gfx/gtk_util.h"
+#include "base/gfx/point.h"
#include "base/logging.h"
namespace {
+// Get the (x,y) coordinates of the widget relative to its GdkWindow.
+gfx::Point GetWindowRelativeCoords(GtkWidget* widget) {
+ // GtkAllocation (x, y) is relative to widget->window for NO_WINDOW widgets.
+ if (GTK_WIDGET_NO_WINDOW(widget))
+ return gfx::Point(widget->allocation.x, widget->allocation.y);
+
+ return gfx::Point();
+}
+
// Draw pixbuf |src| into |dst| at position (x, y).
void DrawPixbuf(GtkWidget* dst, GdkPixbuf* src, int x, int y) {
+ gfx::Point offset = GetWindowRelativeCoords(dst);
+
GdkGC* gc = dst->style->fg_gc[GTK_WIDGET_STATE(dst)];
gdk_draw_pixbuf(dst->window, // The destination drawable.
gc, // Graphics context.
src, 0, 0, // Source image and x,y offset.
- x, y, -1, -1, // x, y, width, height.
+ offset.x() + x, offset.y() + y, -1, -1, // x, y, width, height.
GDK_RGB_DITHER_NONE, 0, 0); // Dithering mode, x,y offsets.
}
-// Fills the widget with |color|.
-void FillWidget(GtkWidget* dst, const GdkColor& color) {
- GdkGC* copy = gdk_gc_new(dst->window);
- gdk_gc_set_foreground(copy, &color);
- gdk_draw_rectangle(dst->window, copy, TRUE, 0, 0,
- dst->allocation.width,
- dst->allocation.height);
- g_object_unref(copy);
-}
-
} // anonymous namespace
NineBox::NineBox(GdkPixbuf* images[9]) {
@@ -49,13 +51,6 @@ void NineBox::RenderToWidget(GtkWidget* dst) {
int dst_width = dst->allocation.width;
int dst_height = dst->allocation.height;
-#ifndef NDEBUG
- // Start by filling with a bright color so we can see any pixels
- // we're missing.
- GdkColor bright = GDK_COLOR_RGB(0x00, 0xFF, 0xFF);
- FillWidget(dst, bright);
-#endif
-
// This function paints one row at a time.
// To make indexing sane, |images| points at the current row of images,
// so images[0] always refers to the left-most image of the current row.
@@ -125,10 +120,7 @@ void NineBox::TileImage(GtkWidget* dst, GdkPixbuf* src,
const int dst_width = dst->allocation.width;
const int dst_height = dst->allocation.height;
- x1 += dst->allocation.x;
- y1 += dst->allocation.y;
- x2 += dst->allocation.x;
- y2 += dst->allocation.y;
+ gfx::Point offset = GetWindowRelativeCoords(dst);
// We only tile along one axis (see above TODO about nuking all this code),
// dx or dy will be nonzero along that axis.
@@ -141,7 +133,7 @@ void NineBox::TileImage(GtkWidget* dst, GdkPixbuf* src,
for (int x = x1, y = y1; x < x2 || y < y2; x += dx, y += dy) {
gdk_draw_pixbuf(dst->window, gc, src, 0, 0,
- x, y,
+ offset.x() + x, offset.y() + y,
dx ? std::min(src_width, dst_width - x) : src_width,
dy ? std::min(src_height, dst_height - y) : src_height,
GDK_RGB_DITHER_NONE, 0, 0);