Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(134)

Side by Side Diff: chrome/browser/gtk/nine_box.cc

Issue 149102: Fix a crash that happens when changing themes. (Closed)
Patch Set: Created 11 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « chrome/browser/gtk/nine_box.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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/resource_bundle.h" 7 #include "app/resource_bundle.h"
8 #include "app/theme_provider.h" 8 #include "app/theme_provider.h"
9 #include "base/basictypes.h"
9 #include "base/gfx/gtk_util.h" 10 #include "base/gfx/gtk_util.h"
10 #include "base/gfx/point.h" 11 #include "base/gfx/point.h"
11 #include "base/logging.h" 12 #include "base/logging.h"
13 #include "chrome/common/notification_service.h"
12 14
13 namespace { 15 namespace {
14 16
15 // Draw pixbuf |src| into |dst| at position (x, y). 17 // Draw pixbuf |src| into |dst| at position (x, y).
16 void DrawPixbuf(cairo_t* cr, GdkPixbuf* src, int x, int y) { 18 void DrawPixbuf(cairo_t* cr, GdkPixbuf* src, int x, int y) {
17 gdk_cairo_set_source_pixbuf(cr, src, x, y); 19 gdk_cairo_set_source_pixbuf(cr, src, x, y);
18 cairo_paint(cr); 20 cairo_paint(cr);
19 } 21 }
20 22
21 // 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 16 matching lines...) Expand all
38 images_[3] = left ? rb.GetPixbufNamed(left) : NULL; 40 images_[3] = left ? rb.GetPixbufNamed(left) : NULL;
39 images_[4] = center ? rb.GetPixbufNamed(center) : NULL; 41 images_[4] = center ? rb.GetPixbufNamed(center) : NULL;
40 images_[5] = right ? rb.GetPixbufNamed(right) : NULL; 42 images_[5] = right ? rb.GetPixbufNamed(right) : NULL;
41 images_[6] = bottom_left ? rb.GetPixbufNamed(bottom_left) : NULL; 43 images_[6] = bottom_left ? rb.GetPixbufNamed(bottom_left) : NULL;
42 images_[7] = bottom ? rb.GetPixbufNamed(bottom) : NULL; 44 images_[7] = bottom ? rb.GetPixbufNamed(bottom) : NULL;
43 images_[8] = bottom_right ? rb.GetPixbufNamed(bottom_right) : NULL; 45 images_[8] = bottom_right ? rb.GetPixbufNamed(bottom_right) : NULL;
44 } 46 }
45 47
46 NineBox::NineBox(ThemeProvider* theme_provider, 48 NineBox::NineBox(ThemeProvider* theme_provider,
47 int top_left, int top, int top_right, int left, int center, 49 int top_left, int top, int top_right, int left, int center,
48 int right, int bottom_left, int bottom, int bottom_right) { 50 int right, int bottom_left, int bottom, int bottom_right)
49 images_[0] = top_left ? 51 : theme_provider_(theme_provider) {
50 theme_provider->GetPixbufNamed(top_left) : NULL; 52 image_ids_[0] = top_left;
51 images_[1] = top ? 53 image_ids_[1] = top;
52 theme_provider->GetPixbufNamed(top) : NULL; 54 image_ids_[2] = top_right;
53 images_[2] = top_right ? 55 image_ids_[3] = left;
54 theme_provider->GetPixbufNamed(top_right) : NULL; 56 image_ids_[4] = center;
55 images_[3] = left ? 57 image_ids_[5] = right;
56 theme_provider->GetPixbufNamed(left) : NULL; 58 image_ids_[6] = bottom_left;
57 images_[4] = center ? 59 image_ids_[7] = bottom;
58 theme_provider->GetPixbufNamed(center) : NULL; 60 image_ids_[8] = bottom_right;
59 images_[5] = right ? 61
60 theme_provider->GetPixbufNamed(right) : NULL; 62 // Load images by pretending that we got a BROWSER_THEME_CHANGED
61 images_[6] = bottom_left ? 63 // notification.
62 theme_provider->GetPixbufNamed(bottom_left) : NULL; 64 Observe(NotificationType::BROWSER_THEME_CHANGED,
63 images_[7] = bottom ? 65 NotificationService::AllSources(),
64 theme_provider->GetPixbufNamed(bottom) : NULL; 66 NotificationService::NoDetails());
65 images_[8] = bottom_right ? 67 registrar_.Add(this, NotificationType::BROWSER_THEME_CHANGED,
66 theme_provider->GetPixbufNamed(bottom_right) : NULL; 68 NotificationService::AllSources());
67 } 69 }
68 70
69 NineBox::~NineBox() { 71 NineBox::~NineBox() {
70 } 72 }
71 73
72 void NineBox::RenderToWidget(GtkWidget* dst) const { 74 void NineBox::RenderToWidget(GtkWidget* dst) const {
73 int dst_width = dst->allocation.width; 75 int dst_width = dst->allocation.width;
74 int dst_height = dst->allocation.height; 76 int dst_height = dst->allocation.height;
75 77
76 // The upper-left and lower-right corners of the center square in the 78 // The upper-left and lower-right corners of the center square in the
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after
170 cairo_t* cr = gdk_cairo_create(mask); 172 cairo_t* cr = gdk_cairo_create(mask);
171 cairo_rectangle(cr, x1, 0, x2 - x1, widget->allocation.height); 173 cairo_rectangle(cr, x1, 0, x2 - x1, widget->allocation.height);
172 cairo_fill(cr); 174 cairo_fill(cr);
173 175
174 // Mask the widget's window's shape. 176 // Mask the widget's window's shape.
175 gtk_widget_shape_combine_mask(widget, mask, 0, 0); 177 gtk_widget_shape_combine_mask(widget, mask, 0, 0);
176 178
177 g_object_unref(mask); 179 g_object_unref(mask);
178 cairo_destroy(cr); 180 cairo_destroy(cr);
179 } 181 }
182
183 void NineBox::Observe(NotificationType type, const NotificationSource& source,
184 const NotificationDetails& details) {
185 if (NotificationType::BROWSER_THEME_CHANGED != type) {
186 NOTREACHED();
187 return;
188 }
189
190 // Reload images.
191 for (size_t i = 0; i < arraysize(image_ids_); ++i) {
192 images_[i] = image_ids_[i] ?
193 theme_provider_->GetPixbufNamed(image_ids_[i]) : NULL;
194 }
195 }
OLDNEW
« no previous file with comments | « chrome/browser/gtk/nine_box.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698