OLD | NEW |
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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" | |
8 #include "app/resource_bundle.h" | 7 #include "app/resource_bundle.h" |
9 #include "app/theme_provider.h" | 8 #include "app/theme_provider.h" |
10 #include "base/basictypes.h" | 9 #include "base/basictypes.h" |
| 10 #include "base/i18n/rtl.h" |
11 #include "base/logging.h" | 11 #include "base/logging.h" |
12 #include "gfx/gtk_util.h" | 12 #include "gfx/gtk_util.h" |
13 #include "gfx/point.h" | 13 #include "gfx/point.h" |
14 | 14 |
15 namespace { | 15 namespace { |
16 | 16 |
17 // Draw pixbuf |src| into |dst| at position (x, y). | 17 // Draw pixbuf |src| into |dst| at position (x, y). |
18 void DrawPixbuf(cairo_t* cr, GdkPixbuf* src, int x, int y, double alpha) { | 18 void DrawPixbuf(cairo_t* cr, GdkPixbuf* src, int x, int y, double alpha) { |
19 gdk_cairo_set_source_pixbuf(cr, src, x, y); | 19 gdk_cairo_set_source_pixbuf(cr, src, x, y); |
20 cairo_paint_with_alpha(cr, alpha); | 20 cairo_paint_with_alpha(cr, alpha); |
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
125 | 125 |
126 cairo_t* cr = gdk_cairo_create(GDK_DRAWABLE(dst->window)); | 126 cairo_t* cr = gdk_cairo_create(GDK_DRAWABLE(dst->window)); |
127 // For widgets that have their own window, the allocation (x,y) coordinates | 127 // For widgets that have their own window, the allocation (x,y) coordinates |
128 // are GdkWindow relative. For other widgets, the coordinates are relative | 128 // are GdkWindow relative. For other widgets, the coordinates are relative |
129 // to their container. | 129 // to their container. |
130 if (GTK_WIDGET_NO_WINDOW(dst)) { | 130 if (GTK_WIDGET_NO_WINDOW(dst)) { |
131 // Transform our cairo from window to widget coordinates. | 131 // Transform our cairo from window to widget coordinates. |
132 cairo_translate(cr, dst->allocation.x, dst->allocation.y); | 132 cairo_translate(cr, dst->allocation.x, dst->allocation.y); |
133 } | 133 } |
134 | 134 |
135 if (l10n_util::GetTextDirection() == l10n_util::RIGHT_TO_LEFT) { | 135 if (base::i18n::IsRTL()) { |
136 cairo_translate(cr, dst_width, 0.0f); | 136 cairo_translate(cr, dst_width, 0.0f); |
137 cairo_scale(cr, -1.0f, 1.0f); | 137 cairo_scale(cr, -1.0f, 1.0f); |
138 } | 138 } |
139 | 139 |
140 // Top row, center image is horizontally tiled. | 140 // Top row, center image is horizontally tiled. |
141 if (images_[0]) | 141 if (images_[0]) |
142 DrawPixbuf(cr, images_[0], 0, 0, opacity); | 142 DrawPixbuf(cr, images_[0], 0, 0, opacity); |
143 if (images_[1]) | 143 if (images_[1]) |
144 TileImage(cr, images_[1], x1, 0, x2 - x1, y1, opacity); | 144 TileImage(cr, images_[1], x1, 0, x2 - x1, y1, opacity); |
145 if (images_[2]) | 145 if (images_[2]) |
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
217 x2, 0, -1, -1, | 217 x2, 0, -1, -1, |
218 1); | 218 1); |
219 | 219 |
220 // Assume no transparency in the middle rectangle. | 220 // Assume no transparency in the middle rectangle. |
221 cairo_t* cr = gdk_cairo_create(mask); | 221 cairo_t* cr = gdk_cairo_create(mask); |
222 cairo_rectangle(cr, x1, 0, x2 - x1, height); | 222 cairo_rectangle(cr, x1, 0, x2 - x1, height); |
223 cairo_fill(cr); | 223 cairo_fill(cr); |
224 cairo_destroy(cr); | 224 cairo_destroy(cr); |
225 | 225 |
226 // Mask the widget's window's shape. | 226 // Mask the widget's window's shape. |
227 if (l10n_util::GetTextDirection() == l10n_util::LEFT_TO_RIGHT) { | 227 if (!base::i18n::IsRTL()) { |
228 gtk_widget_shape_combine_mask(widget, mask, 0, 0); | 228 gtk_widget_shape_combine_mask(widget, mask, 0, 0); |
229 } else { | 229 } else { |
230 GdkBitmap* flipped_mask = gdk_pixmap_new(NULL, width, height, 1); | 230 GdkBitmap* flipped_mask = gdk_pixmap_new(NULL, width, height, 1); |
231 cairo_t* flipped_cr = gdk_cairo_create(flipped_mask); | 231 cairo_t* flipped_cr = gdk_cairo_create(flipped_mask); |
232 | 232 |
233 // Clear the target bitmap. | 233 // Clear the target bitmap. |
234 cairo_set_operator(flipped_cr, CAIRO_OPERATOR_CLEAR); | 234 cairo_set_operator(flipped_cr, CAIRO_OPERATOR_CLEAR); |
235 cairo_paint(flipped_cr); | 235 cairo_paint(flipped_cr); |
236 | 236 |
237 // Apply flipping transformation. | 237 // Apply flipping transformation. |
238 cairo_translate(flipped_cr, width, 0.0f); | 238 cairo_translate(flipped_cr, width, 0.0f); |
239 cairo_scale(flipped_cr, -1.0f, 1.0f); | 239 cairo_scale(flipped_cr, -1.0f, 1.0f); |
240 | 240 |
241 // Paint the source bitmap onto the target. | 241 // Paint the source bitmap onto the target. |
242 cairo_set_operator(flipped_cr, CAIRO_OPERATOR_SOURCE); | 242 cairo_set_operator(flipped_cr, CAIRO_OPERATOR_SOURCE); |
243 gdk_cairo_set_source_pixmap(flipped_cr, mask, 0, 0); | 243 gdk_cairo_set_source_pixmap(flipped_cr, mask, 0, 0); |
244 cairo_paint(flipped_cr); | 244 cairo_paint(flipped_cr); |
245 cairo_destroy(flipped_cr); | 245 cairo_destroy(flipped_cr); |
246 | 246 |
247 // Mask the widget. | 247 // Mask the widget. |
248 gtk_widget_shape_combine_mask(widget, flipped_mask, 0, 0); | 248 gtk_widget_shape_combine_mask(widget, flipped_mask, 0, 0); |
249 g_object_unref(flipped_mask); | 249 g_object_unref(flipped_mask); |
250 } | 250 } |
251 | 251 |
252 g_object_unref(mask); | 252 g_object_unref(mask); |
253 } | 253 } |
OLD | NEW |