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/l10n_util.h" | 7 #include "app/l10n_util.h" |
8 #include "app/resource_bundle.h" | 8 #include "app/resource_bundle.h" |
9 #include "app/theme_provider.h" | 9 #include "app/theme_provider.h" |
10 #include "base/basictypes.h" | 10 #include "base/basictypes.h" |
11 #include "base/gfx/gtk_util.h" | 11 #include "base/gfx/gtk_util.h" |
12 #include "base/gfx/point.h" | 12 #include "base/gfx/point.h" |
13 #include "base/logging.h" | 13 #include "base/logging.h" |
14 #include "chrome/common/notification_service.h" | |
15 | 14 |
16 namespace { | 15 namespace { |
17 | 16 |
18 // Draw pixbuf |src| into |dst| at position (x, y). | 17 // Draw pixbuf |src| into |dst| at position (x, y). |
19 void DrawPixbuf(cairo_t* cr, GdkPixbuf* src, int x, int y) { | 18 void DrawPixbuf(cairo_t* cr, GdkPixbuf* src, int x, int y) { |
20 gdk_cairo_set_source_pixbuf(cr, src, x, y); | 19 gdk_cairo_set_source_pixbuf(cr, src, x, y); |
21 cairo_paint(cr); | 20 cairo_paint(cr); |
22 } | 21 } |
23 | 22 |
24 // Tile pixbuf |src| across |cr| at |x|, |y| for |width| and |height|. | 23 // Tile pixbuf |src| across |cr| at |x|, |y| for |width| and |height|. |
(...skipping 14 matching lines...) Expand all Loading... |
39 images_[1] = top ? rb.GetPixbufNamed(top) : NULL; | 38 images_[1] = top ? rb.GetPixbufNamed(top) : NULL; |
40 images_[2] = top_right ? rb.GetPixbufNamed(top_right) : NULL; | 39 images_[2] = top_right ? rb.GetPixbufNamed(top_right) : NULL; |
41 images_[3] = left ? rb.GetPixbufNamed(left) : NULL; | 40 images_[3] = left ? rb.GetPixbufNamed(left) : NULL; |
42 images_[4] = center ? rb.GetPixbufNamed(center) : NULL; | 41 images_[4] = center ? rb.GetPixbufNamed(center) : NULL; |
43 images_[5] = right ? rb.GetPixbufNamed(right) : NULL; | 42 images_[5] = right ? rb.GetPixbufNamed(right) : NULL; |
44 images_[6] = bottom_left ? rb.GetPixbufNamed(bottom_left) : NULL; | 43 images_[6] = bottom_left ? rb.GetPixbufNamed(bottom_left) : NULL; |
45 images_[7] = bottom ? rb.GetPixbufNamed(bottom) : NULL; | 44 images_[7] = bottom ? rb.GetPixbufNamed(bottom) : NULL; |
46 images_[8] = bottom_right ? rb.GetPixbufNamed(bottom_right) : NULL; | 45 images_[8] = bottom_right ? rb.GetPixbufNamed(bottom_right) : NULL; |
47 } | 46 } |
48 | 47 |
49 NineBox::NineBox(ThemeProvider* theme_provider, | |
50 int top_left, int top, int top_right, int left, int center, | |
51 int right, int bottom_left, int bottom, int bottom_right) | |
52 : theme_provider_(theme_provider) { | |
53 image_ids_[0] = top_left; | |
54 image_ids_[1] = top; | |
55 image_ids_[2] = top_right; | |
56 image_ids_[3] = left; | |
57 image_ids_[4] = center; | |
58 image_ids_[5] = right; | |
59 image_ids_[6] = bottom_left; | |
60 image_ids_[7] = bottom; | |
61 image_ids_[8] = bottom_right; | |
62 | |
63 // Load images by pretending that we got a BROWSER_THEME_CHANGED | |
64 // notification. | |
65 Observe(NotificationType::BROWSER_THEME_CHANGED, | |
66 NotificationService::AllSources(), | |
67 NotificationService::NoDetails()); | |
68 registrar_.Add(this, NotificationType::BROWSER_THEME_CHANGED, | |
69 NotificationService::AllSources()); | |
70 } | |
71 | |
72 NineBox::~NineBox() { | 48 NineBox::~NineBox() { |
73 } | 49 } |
74 | 50 |
75 void NineBox::RenderToWidget(GtkWidget* dst) const { | 51 void NineBox::RenderToWidget(GtkWidget* dst) const { |
76 int dst_width = dst->allocation.width; | 52 int dst_width = dst->allocation.width; |
77 int dst_height = dst->allocation.height; | 53 int dst_height = dst->allocation.height; |
78 | 54 |
79 // The upper-left and lower-right corners of the center square in the | 55 // The upper-left and lower-right corners of the center square in the |
80 // rendering of the ninebox. | 56 // rendering of the ninebox. |
81 int x1 = gdk_pixbuf_get_width(images_[0]); | 57 int x1 = gdk_pixbuf_get_width(images_[0]); |
(...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
207 cairo_paint(flipped_cr); | 183 cairo_paint(flipped_cr); |
208 cairo_destroy(flipped_cr); | 184 cairo_destroy(flipped_cr); |
209 | 185 |
210 // Mask the widget. | 186 // Mask the widget. |
211 gtk_widget_shape_combine_mask(widget, flipped_mask, 0, 0); | 187 gtk_widget_shape_combine_mask(widget, flipped_mask, 0, 0); |
212 g_object_unref(flipped_mask); | 188 g_object_unref(flipped_mask); |
213 } | 189 } |
214 | 190 |
215 g_object_unref(mask); | 191 g_object_unref(mask); |
216 } | 192 } |
217 | |
218 void NineBox::Observe(NotificationType type, const NotificationSource& source, | |
219 const NotificationDetails& details) { | |
220 if (NotificationType::BROWSER_THEME_CHANGED != type) { | |
221 NOTREACHED(); | |
222 return; | |
223 } | |
224 | |
225 // Reload images. | |
226 for (size_t i = 0; i < arraysize(image_ids_); ++i) { | |
227 images_[i] = image_ids_[i] ? | |
228 theme_provider_->GetPixbufNamed(image_ids_[i]) : NULL; | |
229 } | |
230 } | |
OLD | NEW |