Changeset 76577 in webkit
- Timestamp:
- Jan 25, 2011 12:33:59 AM (13 years ago)
- Location:
- trunk/Source/WebCore
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Source/WebCore/ChangeLog
r76576 r76577 1 2011-01-25 Carlos Garcia Campos <cgarcia@igalia.com> 2 3 Reviewed by Martin Robinson. 4 5 [GTK] Implement spin buttons in RenderThemeGtk 6 https://bugs.webkit.org/show_bug.cgi?id=51454 7 8 Paint inner up/down buttons for spin button elements when building 9 with GTK+ 3.x. 10 11 Test results will land with the GTK+ 2.x version of this patch. 12 13 * platform/gtk/RenderThemeGtk.h: 14 * platform/gtk/RenderThemeGtk2.cpp: 15 (WebCore::RenderThemeGtk::adjustInnerSpinButtonStyle): 16 (WebCore::RenderThemeGtk::paintInnerSpinButton): 17 * platform/gtk/RenderThemeGtk3.cpp: 18 (WebCore::spinButtonArrowSize): 19 (WebCore::RenderThemeGtk::adjustInnerSpinButtonStyle): 20 (WebCore::paintSpinArrowButton): 21 (WebCore::RenderThemeGtk::paintInnerSpinButton): 22 1 23 2011-01-24 Mihai Parparita <mihaip@chromium.org> 2 24 -
trunk/Source/WebCore/platform/gtk/RenderThemeGtk.h
r76388 r76577 171 171 172 172 virtual bool paintCapsLockIndicator(RenderObject*, const PaintInfo&, const IntRect&); 173 174 virtual void adjustInnerSpinButtonStyle(CSSStyleSelector*, RenderStyle*, Element*) const; 175 virtual bool paintInnerSpinButton(RenderObject*, const PaintInfo&, const IntRect&); 173 176 174 177 private: -
trunk/Source/WebCore/platform/gtk/RenderThemeGtk2.cpp
r76388 r76577 609 609 #endif 610 610 611 void RenderThemeGtk::adjustInnerSpinButtonStyle(CSSStyleSelector*, RenderStyle*, Element*) const 612 { 613 } 614 615 bool RenderThemeGtk::paintInnerSpinButton(RenderObject*, const PaintInfo&, const IntRect&) 616 { 617 return true; 618 } 619 611 620 GRefPtr<GdkPixbuf> RenderThemeGtk::getStockIcon(GType widgetType, const char* iconName, gint direction, gint state, gint iconSize) 612 621 { -
trunk/Source/WebCore/platform/gtk/RenderThemeGtk3.cpp
r76192 r76577 46 46 // This is the default value defined by GTK+, where it was defined as MIN_ARROW_SIZE in gtkarrow.c. 47 47 static const int minArrowSize = 15; 48 // This is the default value defined by GTK+, where it was defined as MIN_ARROW_WIDTH in gtkspinbutton.c. 49 static const int minSpinButtonArrowSize = 6; 48 50 49 51 typedef HashMap<GType, GRefPtr<GtkStyleContext> > StyleContextMap; … … 721 723 #endif 722 724 725 static gint spinButtonArrowSize(GtkStyleContext* context) 726 { 727 const PangoFontDescription* fontDescription = gtk_style_context_get_font(context, static_cast<GtkStateFlags>(0)); 728 gint fontSize = pango_font_description_get_size(fontDescription); 729 gint arrowSize = max(PANGO_PIXELS(fontSize), minSpinButtonArrowSize); 730 731 return arrowSize - arrowSize % 2; // Force even. 732 } 733 734 void RenderThemeGtk::adjustInnerSpinButtonStyle(CSSStyleSelector*, RenderStyle* style, Element*) const 735 { 736 GtkStyleContext* context = getStyleContext(GTK_TYPE_SPIN_BUTTON); 737 738 GtkBorder padding; 739 gtk_style_context_get_padding(context, static_cast<GtkStateFlags>(0), &padding); 740 741 int width = spinButtonArrowSize(context) + padding.left + padding.right; 742 style->setWidth(Length(width, Fixed)); 743 style->setMinWidth(Length(width, Fixed)); 744 } 745 746 static void paintSpinArrowButton(RenderTheme* theme, GtkStyleContext* context, RenderObject* renderObject, const PaintInfo& paintInfo, const IntRect& rect, GtkArrowType arrowType) 747 { 748 ASSERT(arrowType == GTK_ARROW_UP || arrowType == GTK_ARROW_DOWN); 749 750 gtk_style_context_save(context); 751 gtk_style_context_add_class(context, GTK_STYLE_CLASS_BUTTON); 752 753 GtkTextDirection direction = gtk_style_context_get_direction(context); 754 guint state = static_cast<guint>(gtk_style_context_get_state(context)); 755 if (!(state & GTK_STATE_FLAG_INSENSITIVE)) { 756 if (theme->isPressed(renderObject)) { 757 if ((arrowType == GTK_ARROW_UP && theme->isSpinUpButtonPartPressed(renderObject)) 758 || (arrowType == GTK_ARROW_DOWN && !theme->isSpinUpButtonPartPressed(renderObject))) 759 state |= GTK_STATE_FLAG_ACTIVE; 760 } else if (theme->isHovered(renderObject)) { 761 if ((arrowType == GTK_ARROW_UP && theme->isSpinUpButtonPartHovered(renderObject)) 762 || (arrowType == GTK_ARROW_DOWN && !theme->isSpinUpButtonPartHovered(renderObject))) 763 state |= GTK_STATE_FLAG_PRELIGHT; 764 } 765 } 766 gtk_style_context_set_state(context, static_cast<GtkStateFlags>(state)); 767 768 // Paint button. 769 IntRect buttonRect(rect); 770 guint junction = gtk_style_context_get_junction_sides(context); 771 if (arrowType == GTK_ARROW_UP) 772 junction |= GTK_JUNCTION_BOTTOM; 773 else { 774 junction |= GTK_JUNCTION_TOP; 775 buttonRect.move(0, rect.height() / 2); 776 } 777 buttonRect.setHeight(rect.height() / 2); 778 gtk_style_context_set_junction_sides(context, static_cast<GtkJunctionSides>(junction)); 779 780 gtk_render_background(context, paintInfo.context->platformContext(), buttonRect.x(), buttonRect.y(), buttonRect.width(), buttonRect.height()); 781 gtk_render_frame(context, paintInfo.context->platformContext(), buttonRect.x(), buttonRect.y(), buttonRect.width(), buttonRect.height()); 782 783 // Paint arrow centered inside button. 784 // This code is based on gtkspinbutton.c code. 785 IntRect arrowRect; 786 gdouble angle; 787 if (arrowType == GTK_ARROW_UP) { 788 angle = 0; 789 arrowRect.setY(rect.y()); 790 arrowRect.setHeight(rect.height() / 2 - 2); 791 } else { 792 angle = G_PI; 793 arrowRect.setY(rect.y() + buttonRect.y()); 794 arrowRect.setHeight(rect.height() - arrowRect.y() - 2); 795 } 796 arrowRect.setWidth(rect.width() - 3); 797 if (direction == GTK_TEXT_DIR_LTR) 798 arrowRect.setX(rect.x() + 1); 799 else 800 arrowRect.setX(rect.x() + 2); 801 802 gint width = arrowRect.width() / 2; 803 width -= width % 2 - 1; // Force odd. 804 gint height = (width + 1) / 2; 805 806 arrowRect.move((arrowRect.width() - width) / 2, (arrowRect.height() - height) / 2); 807 gtk_render_arrow(context, paintInfo.context->platformContext(), angle, arrowRect.x(), arrowRect.y(), width); 808 809 gtk_style_context_restore(context); 810 } 811 812 bool RenderThemeGtk::paintInnerSpinButton(RenderObject* renderObject, const PaintInfo& paintInfo, const IntRect& rect) 813 { 814 GtkStyleContext* context = getStyleContext(GTK_TYPE_SPIN_BUTTON); 815 gtk_style_context_save(context); 816 817 GtkTextDirection direction = static_cast<GtkTextDirection>(gtkTextDirection(renderObject->style()->direction())); 818 gtk_style_context_set_direction(context, direction); 819 820 guint flags = 0; 821 if (!isEnabled(renderObject) || isReadOnlyControl(renderObject)) 822 flags |= GTK_STATE_FLAG_INSENSITIVE; 823 else if (isFocused(renderObject)) 824 flags |= GTK_STATE_FLAG_FOCUSED; 825 gtk_style_context_set_state(context, static_cast<GtkStateFlags>(flags)); 826 gtk_style_context_remove_class(context, GTK_STYLE_CLASS_ENTRY); 827 828 paintSpinArrowButton(this, context, renderObject, paintInfo, rect, GTK_ARROW_UP); 829 paintSpinArrowButton(this, context, renderObject, paintInfo, rect, GTK_ARROW_DOWN); 830 831 gtk_style_context_restore(context); 832 833 return false; 834 } 835 723 836 GRefPtr<GdkPixbuf> RenderThemeGtk::getStockIcon(GType widgetType, const char* iconName, gint direction, gint state, gint iconSize) 724 837 {
Note: See TracChangeset
for help on using the changeset viewer.