| OLD | NEW |
| 1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "chrome/browser/gtk/nine_box.h" | 5 #include "chrome/browser/gtk/nine_box.h" |
| 6 | 6 |
| 7 #include "app/gfx/gtk_util.h" | 7 #include "app/gfx/gtk_util.h" |
| 8 #include "app/l10n_util.h" | 8 #include "app/l10n_util.h" |
| 9 #include "app/resource_bundle.h" | 9 #include "app/resource_bundle.h" |
| 10 #include "app/theme_provider.h" | 10 #include "app/theme_provider.h" |
| (...skipping 14 matching lines...) Expand all Loading... |
| 25 int x, int y, int width, int height) { | 25 int x, int y, int width, int height) { |
| 26 gdk_cairo_set_source_pixbuf(cr, src, x, y); | 26 gdk_cairo_set_source_pixbuf(cr, src, x, y); |
| 27 cairo_pattern_set_extend(cairo_get_source(cr), CAIRO_EXTEND_REPEAT); | 27 cairo_pattern_set_extend(cairo_get_source(cr), CAIRO_EXTEND_REPEAT); |
| 28 cairo_rectangle(cr, x, y, width, height); | 28 cairo_rectangle(cr, x, y, width, height); |
| 29 cairo_fill(cr); | 29 cairo_fill(cr); |
| 30 } | 30 } |
| 31 | 31 |
| 32 } // namespace | 32 } // namespace |
| 33 | 33 |
| 34 NineBox::NineBox(int top_left, int top, int top_right, int left, int center, | 34 NineBox::NineBox(int top_left, int top, int top_right, int left, int center, |
| 35 int right, int bottom_left, int bottom, int bottom_right) { | 35 int right, int bottom_left, int bottom, int bottom_right) |
| 36 : unref_pixbufs_on_destroy_(false) { |
| 36 ResourceBundle& rb = ResourceBundle::GetSharedInstance(); | 37 ResourceBundle& rb = ResourceBundle::GetSharedInstance(); |
| 37 images_[0] = top_left ? rb.GetPixbufNamed(top_left) : NULL; | 38 images_[0] = top_left ? rb.GetPixbufNamed(top_left) : NULL; |
| 38 images_[1] = top ? rb.GetPixbufNamed(top) : NULL; | 39 images_[1] = top ? rb.GetPixbufNamed(top) : NULL; |
| 39 images_[2] = top_right ? rb.GetPixbufNamed(top_right) : NULL; | 40 images_[2] = top_right ? rb.GetPixbufNamed(top_right) : NULL; |
| 40 images_[3] = left ? rb.GetPixbufNamed(left) : NULL; | 41 images_[3] = left ? rb.GetPixbufNamed(left) : NULL; |
| 41 images_[4] = center ? rb.GetPixbufNamed(center) : NULL; | 42 images_[4] = center ? rb.GetPixbufNamed(center) : NULL; |
| 42 images_[5] = right ? rb.GetPixbufNamed(right) : NULL; | 43 images_[5] = right ? rb.GetPixbufNamed(right) : NULL; |
| 43 images_[6] = bottom_left ? rb.GetPixbufNamed(bottom_left) : NULL; | 44 images_[6] = bottom_left ? rb.GetPixbufNamed(bottom_left) : NULL; |
| 44 images_[7] = bottom ? rb.GetPixbufNamed(bottom) : NULL; | 45 images_[7] = bottom ? rb.GetPixbufNamed(bottom) : NULL; |
| 45 images_[8] = bottom_right ? rb.GetPixbufNamed(bottom_right) : NULL; | 46 images_[8] = bottom_right ? rb.GetPixbufNamed(bottom_right) : NULL; |
| 46 } | 47 } |
| 47 | 48 |
| 49 NineBox::NineBox(int image, int top_margin, int bottom_margin, int left_margin, |
| 50 int right_margin) |
| 51 : unref_pixbufs_on_destroy_(true) { |
| 52 ResourceBundle& rb = ResourceBundle::GetSharedInstance(); |
| 53 GdkPixbuf* pixbuf = rb.GetPixbufNamed(image); |
| 54 int width = gdk_pixbuf_get_width(pixbuf); |
| 55 int height = gdk_pixbuf_get_height(pixbuf); |
| 56 int inset_width = left_margin + right_margin; |
| 57 int inset_height = top_margin + bottom_margin; |
| 58 |
| 59 images_[0] = gdk_pixbuf_new_subpixbuf(pixbuf, 0, 0, left_margin, top_margin); |
| 60 images_[1] = gdk_pixbuf_new_subpixbuf(pixbuf, left_margin, 0, |
| 61 width - inset_width, top_margin); |
| 62 images_[2] = gdk_pixbuf_new_subpixbuf(pixbuf, width - right_margin, 0, |
| 63 right_margin, top_margin); |
| 64 images_[3] = gdk_pixbuf_new_subpixbuf(pixbuf, 0, top_margin, |
| 65 left_margin, height - inset_height); |
| 66 images_[4] = gdk_pixbuf_new_subpixbuf(pixbuf, left_margin, top_margin, |
| 67 width - inset_width, |
| 68 height - inset_height); |
| 69 images_[5] = gdk_pixbuf_new_subpixbuf(pixbuf, width - right_margin, |
| 70 top_margin, right_margin, |
| 71 height - inset_height); |
| 72 images_[6] = gdk_pixbuf_new_subpixbuf(pixbuf, 0, height - bottom_margin, |
| 73 left_margin, bottom_margin); |
| 74 images_[7] = gdk_pixbuf_new_subpixbuf(pixbuf, left_margin, |
| 75 height - bottom_margin, |
| 76 width - inset_width, bottom_margin); |
| 77 images_[8] = gdk_pixbuf_new_subpixbuf(pixbuf, width - right_margin, |
| 78 height - bottom_margin, |
| 79 right_margin, bottom_margin); |
| 80 } |
| 81 |
| 48 NineBox::~NineBox() { | 82 NineBox::~NineBox() { |
| 83 if (unref_pixbufs_on_destroy_) { |
| 84 for (int i = 0; i < 9; i++) { |
| 85 g_object_unref(images_[i]); |
| 86 } |
| 87 } |
| 49 } | 88 } |
| 50 | 89 |
| 51 void NineBox::RenderToWidget(GtkWidget* dst) const { | 90 void NineBox::RenderToWidget(GtkWidget* dst) const { |
| 52 int dst_width = dst->allocation.width; | 91 int dst_width = dst->allocation.width; |
| 53 int dst_height = dst->allocation.height; | 92 int dst_height = dst->allocation.height; |
| 54 | 93 |
| 55 // The upper-left and lower-right corners of the center square in the | 94 // The upper-left and lower-right corners of the center square in the |
| 56 // rendering of the ninebox. | 95 // rendering of the ninebox. |
| 57 int x1 = gdk_pixbuf_get_width(images_[0]); | 96 int x1 = gdk_pixbuf_get_width(images_[0]); |
| 58 int y1 = gdk_pixbuf_get_height(images_[0]); | 97 int y1 = gdk_pixbuf_get_height(images_[0]); |
| (...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 183 cairo_paint(flipped_cr); | 222 cairo_paint(flipped_cr); |
| 184 cairo_destroy(flipped_cr); | 223 cairo_destroy(flipped_cr); |
| 185 | 224 |
| 186 // Mask the widget. | 225 // Mask the widget. |
| 187 gtk_widget_shape_combine_mask(widget, flipped_mask, 0, 0); | 226 gtk_widget_shape_combine_mask(widget, flipped_mask, 0, 0); |
| 188 g_object_unref(flipped_mask); | 227 g_object_unref(flipped_mask); |
| 189 } | 228 } |
| 190 | 229 |
| 191 g_object_unref(mask); | 230 g_object_unref(mask); |
| 192 } | 231 } |
| OLD | NEW |