OLD | NEW |
1 // Copyright (c) 2009 The Chromium OS Authors. All rights reserved. | 1 // Copyright (c) 2009 The Chromium OS 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 <algorithm> | 5 #include <algorithm> |
6 #include <cairo.h> | 6 #include <cairo.h> |
7 #include <math.h> | 7 #include <math.h> |
8 #include <gmodule.h> | 8 #include <gmodule.h> |
9 #include <gtk/gtk.h> | 9 #include <gtk/gtk.h> |
10 #include <string.h> | 10 #include <string.h> |
(...skipping 200 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
211 static const double TEXT_GRADIENT_G0 = static_cast<double>(0xC5) / 255.0; | 211 static const double TEXT_GRADIENT_G0 = static_cast<double>(0xC5) / 255.0; |
212 static const double TEXT_GRADIENT_B0 = static_cast<double>(0xC5) / 255.0; | 212 static const double TEXT_GRADIENT_B0 = static_cast<double>(0xC5) / 255.0; |
213 static const double TEXT_GRADIENT_R1 = 1; | 213 static const double TEXT_GRADIENT_R1 = 1; |
214 static const double TEXT_GRADIENT_G1 = 1; | 214 static const double TEXT_GRADIENT_G1 = 1; |
215 static const double TEXT_GRADIENT_B1 = 1; | 215 static const double TEXT_GRADIENT_B1 = 1; |
216 static const double TEXT_GRADIENT_R2 = 1; | 216 static const double TEXT_GRADIENT_R2 = 1; |
217 static const double TEXT_GRADIENT_G2 = 1; | 217 static const double TEXT_GRADIENT_G2 = 1; |
218 static const double TEXT_GRADIENT_B2 = 1; | 218 static const double TEXT_GRADIENT_B2 = 1; |
219 | 219 |
220 static const double TEXT_GRADIENT_STOP_0 = 0; | 220 static const double TEXT_GRADIENT_STOP_0 = 0; |
221 static const double TEXT_GRADIENT_STOP_1 = .2; | 221 static const double TEXT_GRADIENT_STOP_1_PIXEL = 4; |
222 static const double TEXT_GRADIENT_STOP_2 = 1; | 222 static const double TEXT_GRADIENT_STOP_2 = 1; |
223 | 223 |
224 static const double TREE_ITEM_BG_R = 1; | 224 static const double TREE_ITEM_BG_R = 1; |
225 static const double TREE_ITEM_BG_G = 1; | 225 static const double TREE_ITEM_BG_G = 1; |
226 static const double TREE_ITEM_BG_B = 1; | 226 static const double TREE_ITEM_BG_B = 1; |
227 | 227 |
228 static const double TREE_ITEM_SELECTED_BG_R = SELECTED_TEXT_BG_R; | 228 static const double TREE_ITEM_SELECTED_BG_R = SELECTED_TEXT_BG_R; |
229 static const double TREE_ITEM_SELECTED_BG_G = SELECTED_TEXT_BG_G; | 229 static const double TREE_ITEM_SELECTED_BG_G = SELECTED_TEXT_BG_G; |
230 static const double TREE_ITEM_SELECTED_BG_B = SELECTED_TEXT_BG_B; | 230 static const double TREE_ITEM_SELECTED_BG_B = SELECTED_TEXT_BG_B; |
231 | 231 |
(...skipping 202 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
434 h -= 2; | 434 h -= 2; |
435 } | 435 } |
436 cairo_translate(cr, x, y); | 436 cairo_translate(cr, x, y); |
437 | 437 |
438 int stroke_width = GTK_WIDGET_HAS_FOCUS(widget) | 438 int stroke_width = GTK_WIDGET_HAS_FOCUS(widget) |
439 ? FOCUSED_STROKE_WIDTH : STROKE_WIDTH; | 439 ? FOCUSED_STROKE_WIDTH : STROKE_WIDTH; |
440 cairo_set_line_width(cr, stroke_width); | 440 cairo_set_line_width(cr, stroke_width); |
441 | 441 |
442 AddRoundedRectPath(cr, w, h, stroke_width, BORDER_CORNER_RADIUS); | 442 AddRoundedRectPath(cr, w, h, stroke_width, BORDER_CORNER_RADIUS); |
443 | 443 |
| 444 double text_gradient_stop_1 = h ? TEXT_GRADIENT_STOP_1_PIXEL / h : 0; |
| 445 |
444 ScopedPattern pattern(cairo_pattern_create_linear(0, 0, 0, h)); | 446 ScopedPattern pattern(cairo_pattern_create_linear(0, 0, 0, h)); |
445 cairo_pattern_add_color_stop_rgb(pattern.get(), TEXT_GRADIENT_STOP_0, | 447 cairo_pattern_add_color_stop_rgb(pattern.get(), TEXT_GRADIENT_STOP_0, |
446 TEXT_GRADIENT_R0, TEXT_GRADIENT_G0, | 448 TEXT_GRADIENT_R0, TEXT_GRADIENT_G0, |
447 TEXT_GRADIENT_B0); | 449 TEXT_GRADIENT_B0); |
448 cairo_pattern_add_color_stop_rgb(pattern.get(), TEXT_GRADIENT_STOP_1, | 450 cairo_pattern_add_color_stop_rgb(pattern.get(), text_gradient_stop_1, |
449 TEXT_GRADIENT_R1, TEXT_GRADIENT_G1, | 451 TEXT_GRADIENT_R1, TEXT_GRADIENT_G1, |
450 TEXT_GRADIENT_B1); | 452 TEXT_GRADIENT_B1); |
451 cairo_pattern_add_color_stop_rgb(pattern.get(), TEXT_GRADIENT_STOP_2, | 453 cairo_pattern_add_color_stop_rgb(pattern.get(), TEXT_GRADIENT_STOP_2, |
452 TEXT_GRADIENT_R2, TEXT_GRADIENT_G2, | 454 TEXT_GRADIENT_R2, TEXT_GRADIENT_G2, |
453 TEXT_GRADIENT_B2); | 455 TEXT_GRADIENT_B2); |
454 | 456 |
455 cairo_set_source(cr, pattern.get()); | 457 cairo_set_source(cr, pattern.get()); |
456 cairo_fill_preserve(cr); | 458 cairo_fill_preserve(cr); |
457 | 459 |
458 SetStrokeColor(cr, GTK_WIDGET_SENSITIVE(widget), | 460 SetStrokeColor(cr, GTK_WIDGET_SENSITIVE(widget), |
(...skipping 688 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1147 static void DrawTextFieldBackground(GtkStyle* style, | 1149 static void DrawTextFieldBackground(GtkStyle* style, |
1148 GdkWindow* window, | 1150 GdkWindow* window, |
1149 GtkStateType state_type, | 1151 GtkStateType state_type, |
1150 GtkShadowType shadow_type, | 1152 GtkShadowType shadow_type, |
1151 GdkRectangle* area, | 1153 GdkRectangle* area, |
1152 GtkWidget* widget, | 1154 GtkWidget* widget, |
1153 gint x, | 1155 gint x, |
1154 gint y, | 1156 gint y, |
1155 gint w, | 1157 gint w, |
1156 gint h) { | 1158 gint h) { |
1157 if (!gtk_entry_get_has_frame(GTK_ENTRY(widget))) | 1159 if (GTK_IS_ENTRY(widget) && !gtk_entry_get_has_frame(GTK_ENTRY(widget))) |
1158 return; | 1160 return; |
1159 | 1161 |
1160 ScopedSurface cr(window, area); | 1162 ScopedSurface cr(window, area); |
1161 DrawTextBorder(cr.get(), widget, -(widget->allocation.width - w) / 2, | 1163 DrawTextBorder(cr.get(), widget, -(widget->allocation.width - w) / 2, |
1162 -(widget->allocation.height - h) / 2, | 1164 -(widget->allocation.height - h) / 2, |
1163 widget->allocation.width, | 1165 widget->allocation.width, |
1164 widget->allocation.height); | 1166 widget->allocation.height); |
1165 } | 1167 } |
1166 | 1168 |
1167 static void DrawTextFieldBorder(GtkStyle* style, | 1169 static void DrawTextFieldBorder(GtkStyle* style, |
1168 GdkWindow* window, | 1170 GdkWindow* window, |
1169 GtkStateType state_type, | 1171 GtkStateType state_type, |
1170 GtkShadowType shadow_type, | 1172 GtkShadowType shadow_type, |
1171 GdkRectangle* area, | 1173 GdkRectangle* area, |
1172 GtkWidget* widget, | 1174 GtkWidget* widget, |
1173 gint x, | 1175 gint x, |
1174 gint y, | 1176 gint y, |
1175 gint w, | 1177 gint w, |
1176 gint h) { | 1178 gint h) { |
1177 if (!gtk_entry_get_has_frame(GTK_ENTRY(widget))) | 1179 if (GTK_IS_ENTRY(widget) && !gtk_entry_get_has_frame(GTK_ENTRY(widget))) |
1178 return; | 1180 return; |
1179 | 1181 |
1180 ScopedSurface cr(window, area); | 1182 ScopedSurface cr(window, area); |
1181 DrawTextBorder(cr.get(), widget, x, y, w, h); | 1183 DrawTextBorder(cr.get(), widget, x, y, w, h); |
1182 } | 1184 } |
1183 | 1185 |
1184 static void DrawTooltipBorder(GtkStyle* style, | 1186 static void DrawTooltipBorder(GtkStyle* style, |
1185 GdkWindow* window, | 1187 GdkWindow* window, |
1186 GtkStateType state_type, | 1188 GtkStateType state_type, |
1187 GtkShadowType shadow_type, | 1189 GtkShadowType shadow_type, |
(...skipping 216 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1404 GdkWindow* window, | 1406 GdkWindow* window, |
1405 GtkStateType state_type, | 1407 GtkStateType state_type, |
1406 GtkShadowType shadow_type, | 1408 GtkShadowType shadow_type, |
1407 GdkRectangle* area, | 1409 GdkRectangle* area, |
1408 GtkWidget* widget, | 1410 GtkWidget* widget, |
1409 const gchar* detail, | 1411 const gchar* detail, |
1410 gint x, | 1412 gint x, |
1411 gint y, | 1413 gint y, |
1412 gint w, | 1414 gint w, |
1413 gint h) { | 1415 gint h) { |
1414 if (GTK_IS_ENTRY(widget) && detail && !strcmp(detail, "entry_bg")) { | 1416 if ((GTK_IS_ENTRY(widget) && detail && !strcmp(detail, "entry_bg")) || |
| 1417 (GTK_IS_TEXT_VIEW(widget) && detail && !strcmp(detail, "textview"))) { |
1415 DrawTextFieldBackground(style, window, state_type, shadow_type, area, | 1418 DrawTextFieldBackground(style, window, state_type, shadow_type, area, |
1416 widget, x, y, w, h); | 1419 widget, x, y, w, h); |
1417 } else if (GTK_IS_WINDOW(widget) && detail && !strcmp(detail, "tooltip")) { | 1420 } else if (GTK_IS_WINDOW(widget) && detail && !strcmp(detail, "tooltip")) { |
1418 // NOTE: the if checks GTK_IS_WINDOW as that is what GtkTooltip supplies to | 1421 // NOTE: the if checks GTK_IS_WINDOW as that is what GtkTooltip supplies to |
1419 // this function. | 1422 // this function. |
1420 | 1423 |
1421 DrawTooltipBorder(style, window, state_type, shadow_type, area, widget, | 1424 DrawTooltipBorder(style, window, state_type, shadow_type, area, widget, |
1422 x, y, w, h); | 1425 x, y, w, h); |
1423 } else if (GTK_IS_TREE_VIEW(widget)) { | 1426 } else if (GTK_IS_TREE_VIEW(widget)) { |
1424 DrawTreeItemBackground(style, window, state_type, shadow_type, area, widget, | 1427 DrawTreeItemBackground(style, window, state_type, shadow_type, area, widget, |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1479 GdkWindow* window, | 1482 GdkWindow* window, |
1480 GtkStateType state_type, | 1483 GtkStateType state_type, |
1481 GtkShadowType shadow_type, | 1484 GtkShadowType shadow_type, |
1482 GdkRectangle* area, | 1485 GdkRectangle* area, |
1483 GtkWidget* widget, | 1486 GtkWidget* widget, |
1484 const gchar* detail, | 1487 const gchar* detail, |
1485 gint x, | 1488 gint x, |
1486 gint y, | 1489 gint y, |
1487 gint w, | 1490 gint w, |
1488 gint h) { | 1491 gint h) { |
1489 if (GTK_IS_ENTRY(widget) && detail && !strcmp(detail, "entry")) { | 1492 if ((GTK_IS_ENTRY(widget) && detail && !strcmp(detail, "entry")) || |
| 1493 (GTK_IS_TEXT_VIEW(widget) && detail && !strcmp(detail, "textview"))) { |
1490 DrawTextFieldBorder(style, window, state_type, shadow_type, area, widget, x, | 1494 DrawTextFieldBorder(style, window, state_type, shadow_type, area, widget, x, |
1491 y, w, h); | 1495 y, w, h); |
1492 } else if (GTK_IS_SCROLLED_WINDOW(widget) && detail && | 1496 } else if (GTK_IS_SCROLLED_WINDOW(widget) && detail && |
1493 !strcmp(detail, "scrolled_window")) { | 1497 !strcmp(detail, "scrolled_window")) { |
1494 DrawScrollbarBorder(style, window, state_type, shadow_type, area, widget, | 1498 DrawScrollbarBorder(style, window, state_type, shadow_type, area, widget, |
1495 x, y, w, h); | 1499 x, y, w, h); |
1496 } else if (GTK_IS_VIEWPORT(widget) && detail && | 1500 } else if (GTK_IS_VIEWPORT(widget) && detail && |
1497 !strcmp(detail, "viewport")) { | 1501 !strcmp(detail, "viewport")) { |
1498 DrawViewportBorder(style, window, state_type, shadow_type, area, widget, x, | 1502 DrawViewportBorder(style, window, state_type, shadow_type, area, widget, x, |
1499 y, w, h); | 1503 y, w, h); |
(...skipping 26 matching lines...) Expand all Loading... |
1526 GtkStateType state_type, | 1530 GtkStateType state_type, |
1527 GdkRectangle* area, | 1531 GdkRectangle* area, |
1528 GtkWidget* widget, | 1532 GtkWidget* widget, |
1529 const gchar* detail, | 1533 const gchar* detail, |
1530 gint y1, | 1534 gint y1, |
1531 gint y2, | 1535 gint y2, |
1532 gint x) { | 1536 gint x) { |
1533 // We currently don't have any vertical separators. If we do need them, be | 1537 // We currently don't have any vertical separators. If we do need them, be |
1534 // sure and special case so that we don't draw the separator for comboboxs: | 1538 // sure and special case so that we don't draw the separator for comboboxs: |
1535 } | 1539 } |
OLD | NEW |