Changeset 75259 in webkit
- Timestamp:
- Jan 7, 2011 11:32:53 AM (13 years ago)
- Location:
- trunk
- Files:
-
- 9 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Source/JavaScriptCore/ChangeLog
r75247 r75259 1 2011-01-07 Carlos Garcia Campos <cgarcia@igalia.com> 2 3 Reviewed by Martin Robinson. 4 5 [GTK] Port scrollbar painting to GtkStyleContext 6 https://bugs.webkit.org/show_bug.cgi?id=52051 7 8 * wtf/gobject/GTypedefs.h: Add GtkStyleContext forward 9 declaration. 10 1 11 2011-01-07 Daniel Bates <dbates@rim.com> 2 12 -
trunk/Source/JavaScriptCore/wtf/gobject/GTypedefs.h
r73330 r75259 90 90 typedef struct _cairo_rectangle_int cairo_rectangle_int_t; 91 91 typedef cairo_rectangle_int_t GdkRectangle; 92 typedef struct _GtkStyleContext GtkStyleContext; 92 93 #endif 93 94 -
trunk/WebCore/ChangeLog
r75257 r75259 1 2011-01-07 Carlos Garcia Campos <cgarcia@igalia.com> 2 3 Reviewed by Martin Robinson. 4 5 [GTK] Port scrollbar painting to GtkStyleContext 6 https://bugs.webkit.org/show_bug.cgi?id=52051 7 8 Use GtkStyleContext API to paint scrollbars when building with 9 GTK+ 3.x. 10 11 No new tests. This should not change functionality. 12 13 * platform/gtk/RenderThemeGtk.h: 14 * platform/gtk/RenderThemeGtk3.cpp: 15 (WebCore::RenderThemeGtk::gtkScrollbarStyle): 16 * platform/gtk/ScrollbarThemeGtk.cpp: 17 * platform/gtk/ScrollbarThemeGtk.h: 18 * platform/gtk/ScrollbarThemeGtk2.cpp: 19 (WebCore::gtkStyleSetCallback): 20 (WebCore::ScrollbarThemeGtk::ScrollbarThemeGtk): 21 * platform/gtk/ScrollbarThemeGtk3.cpp: 22 (WebCore::gtkStyleChangedCallback): 23 (WebCore::ScrollbarThemeGtk::ScrollbarThemeGtk): 24 (WebCore::ScrollbarThemeGtk::updateThemeProperties): 25 (WebCore::ScrollbarThemeGtk::paintTrackBackground): 26 (WebCore::ScrollbarThemeGtk::paintScrollbarBackground): 27 (WebCore::ScrollbarThemeGtk::paintThumb): 28 (WebCore::ScrollbarThemeGtk::paintButton): 29 1 30 2011-01-07 Dan Bernstein <mitz@apple.com> 2 31 -
trunk/WebCore/platform/gtk/RenderThemeGtk.h
r75241 r75259 89 89 void getIndicatorMetrics(ControlPart, int& indicatorSize, int& indicatorSpacing) const; 90 90 91 #ifdef GTK_API_VERSION_2 91 92 GtkWidget* gtkScrollbar(); 93 #else 94 GtkStyleContext* gtkScrollbarStyle(); 95 #endif 92 96 93 97 protected: -
trunk/WebCore/platform/gtk/RenderThemeGtk3.cpp
r75255 r75259 634 634 } 635 635 636 Gtk Widget* RenderThemeGtk::gtkScrollbar()637 { 638 return moz_gtk_get_scrollbar_widget();636 GtkStyleContext* RenderThemeGtk::gtkScrollbarStyle() 637 { 638 return getStyleContext(GTK_TYPE_SCROLLBAR); 639 639 } 640 640 -
trunk/WebCore/platform/gtk/ScrollbarThemeGtk.cpp
r75070 r75259 35 35 36 36 static HashSet<Scrollbar*>* gScrollbars; 37 static void gtkStyleSetCallback(GtkWidget*, GtkStyle*, ScrollbarThemeGtk*);38 37 39 38 ScrollbarTheme* ScrollbarTheme::nativeTheme() … … 41 40 static ScrollbarThemeGtk theme; 42 41 return &theme; 43 }44 45 ScrollbarThemeGtk::ScrollbarThemeGtk()46 {47 updateThemeProperties();48 g_signal_connect(static_cast<RenderThemeGtk*>(RenderTheme::defaultTheme().get())->gtkScrollbar(),49 "style-set", G_CALLBACK(gtkStyleSetCallback), this);50 42 } 51 43 … … 93 85 scrollbar->setFrameRect(IntRect(scrollbar->parent()->width() - thickness, 0, thickness, scrollbar->height())); 94 86 } 95 }96 97 static void gtkStyleSetCallback(GtkWidget* widget, GtkStyle* previous, ScrollbarThemeGtk* scrollbarTheme)98 {99 scrollbarTheme->updateThemeProperties();100 87 } 101 88 -
trunk/WebCore/platform/gtk/ScrollbarThemeGtk.h
r75070 r75259 64 64 65 65 protected: 66 #ifndef GTK_API_VERSION_2 67 GtkStyleContext* m_context; 68 #endif 66 69 int m_thumbFatness; 67 70 int m_troughBorderWidth; … … 69 72 int m_stepperSpacing; 70 73 int m_minThumbLength; 71 boolm_troughUnderSteppers;72 boolm_hasForwardButtonStartPart;73 boolm_hasBackButtonEndPart;74 gboolean m_troughUnderSteppers; 75 gboolean m_hasForwardButtonStartPart; 76 gboolean m_hasBackButtonEndPart; 74 77 }; 75 78 -
trunk/WebCore/platform/gtk/ScrollbarThemeGtk2.cpp
r75070 r75259 38 38 39 39 namespace WebCore { 40 41 static void gtkStyleSetCallback(GtkWidget* widget, GtkStyle* previous, ScrollbarThemeGtk* scrollbarTheme) 42 { 43 scrollbarTheme->updateThemeProperties(); 44 } 45 46 ScrollbarThemeGtk::ScrollbarThemeGtk() 47 { 48 updateThemeProperties(); 49 g_signal_connect(static_cast<RenderThemeGtk*>(RenderTheme::defaultTheme().get())->gtkScrollbar(), 50 "style-set", G_CALLBACK(gtkStyleSetCallback), this); 51 } 40 52 41 53 void ScrollbarThemeGtk::updateThemeProperties() -
trunk/WebCore/platform/gtk/ScrollbarThemeGtk3.cpp
r75070 r75259 33 33 #include "ScrollView.h" 34 34 #include "Scrollbar.h" 35 #include "WidgetRenderingContext.h"36 #include "gtkdrawing.h"37 35 #include <gtk/gtk.h> 38 36 39 37 namespace WebCore { 40 38 39 static void gtkStyleChangedCallback(GtkWidget*, ScrollbarThemeGtk* scrollbarTheme) 40 { 41 scrollbarTheme->updateThemeProperties(); 42 } 43 44 ScrollbarThemeGtk::ScrollbarThemeGtk() 45 : m_context(static_cast<RenderThemeGtk*>(RenderTheme::defaultTheme().get())->gtkScrollbarStyle()) 46 { 47 updateThemeProperties(); 48 g_signal_connect(m_context, "changed", G_CALLBACK(gtkStyleChangedCallback), this); 49 } 50 41 51 void ScrollbarThemeGtk::updateThemeProperties() 42 52 { 43 MozGtkScrollbarMetrics metrics; 44 moz_gtk_get_scrollbar_metrics(&metrics); 45 46 m_thumbFatness = metrics.slider_width; 47 m_troughBorderWidth = metrics.trough_border; 48 m_stepperSize = metrics.stepper_size; 49 m_stepperSpacing = metrics.stepper_spacing; 50 m_minThumbLength = metrics.min_slider_size; 51 m_troughUnderSteppers = metrics.trough_under_steppers; 52 m_hasForwardButtonStartPart = metrics.has_secondary_forward_stepper; 53 m_hasBackButtonEndPart = metrics.has_secondary_backward_stepper; 54 53 gtk_style_context_get_style(m_context, 54 "min-slider-length", &m_minThumbLength, 55 "slider-width", &m_thumbFatness, 56 "trough-border", &m_troughBorderWidth, 57 "stepper-size", &m_stepperSize, 58 "stepper-spacing", &m_stepperSpacing, 59 "trough-under-steppers", &m_troughUnderSteppers, 60 "has-secondary-backward-stepper", &m_hasBackButtonEndPart, 61 "has-secondary-forward-stepper", &m_hasForwardButtonStartPart, 62 NULL); 55 63 updateScrollbarsFrameThickness(); 56 64 } … … 58 66 void ScrollbarThemeGtk::paintTrackBackground(GraphicsContext* context, Scrollbar* scrollbar, const IntRect& rect) 59 67 { 60 GtkWidgetState state;61 state.focused = FALSE;62 state.isDefault = FALSE;63 state.canDefault = FALSE;64 state.disabled = FALSE;65 state.active = FALSE;66 state.inHover = FALSE;67 68 68 // Paint the track background. If the trough-under-steppers property is true, this 69 69 // should be the full size of the scrollbar, but if is false, it should only be the 70 70 // track rect. 71 IntRect fullScrollbarRect = rect;71 IntRect fullScrollbarRect(rect); 72 72 if (m_troughUnderSteppers) 73 73 fullScrollbarRect = IntRect(scrollbar->x(), scrollbar->y(), scrollbar->width(), scrollbar->height()); 74 74 75 GtkThemeWidgetType type = scrollbar->orientation() == VerticalScrollbar ? MOZ_GTK_SCROLLBAR_TRACK_VERTICAL : MOZ_GTK_SCROLLBAR_TRACK_HORIZONTAL; 76 WidgetRenderingContext widgetContext(context, fullScrollbarRect); 77 widgetContext.paintMozillaWidget(type, &state, 0); 75 gtk_style_context_save(m_context); 76 77 gtk_style_context_add_class(m_context, GTK_STYLE_CLASS_SCROLLBAR); 78 gtk_style_context_add_class(m_context, GTK_STYLE_CLASS_TROUGH); 79 80 gtk_render_background(m_context, context->platformContext(), 81 fullScrollbarRect.x(), fullScrollbarRect.y(), fullScrollbarRect.width(), fullScrollbarRect.height()); 82 gtk_render_frame(m_context, context->platformContext(), 83 fullScrollbarRect.x(), fullScrollbarRect.y(), fullScrollbarRect.width(), fullScrollbarRect.height()); 84 85 gtk_style_context_restore(m_context); 78 86 } 79 87 80 88 void ScrollbarThemeGtk::paintScrollbarBackground(GraphicsContext* context, Scrollbar* scrollbar) 81 89 { 82 // This is unused by the moz_gtk_scrollecd_window_paint. 83 GtkWidgetState state; 84 IntRect fullScrollbarRect = IntRect(scrollbar->x(), scrollbar->y(), scrollbar->width(), scrollbar->height()); 85 WidgetRenderingContext widgetContext(context, fullScrollbarRect); 86 widgetContext.paintMozillaWidget(MOZ_GTK_SCROLLED_WINDOW, &state, 0); 90 gtk_style_context_save(m_context); 91 92 gtk_style_context_add_class(m_context, GTK_STYLE_CLASS_SCROLLBAR); 93 gtk_style_context_add_class(m_context, "scrolled-window"); 94 gtk_render_frame(m_context, context->platformContext(), scrollbar->x(), scrollbar->y(), scrollbar->width(), scrollbar->height()); 95 96 gtk_style_context_restore(m_context); 87 97 } 88 98 89 99 void ScrollbarThemeGtk::paintThumb(GraphicsContext* context, Scrollbar* scrollbar, const IntRect& rect) 90 100 { 91 GtkWidgetState state; 92 state.focused = FALSE; 93 state.isDefault = FALSE; 94 state.canDefault = FALSE; 95 state.disabled = FALSE; 96 state.active = scrollbar->pressedPart() == ThumbPart; 97 state.inHover = scrollbar->hoveredPart() == ThumbPart; 98 state.maxpos = scrollbar->maximum(); 99 state.curpos = scrollbar->currentPos(); 101 gtk_style_context_save(m_context); 100 102 101 GtkThemeWidgetType type = scrollbar->orientation() == VerticalScrollbar ? MOZ_GTK_SCROLLBAR_THUMB_VERTICAL : MOZ_GTK_SCROLLBAR_THUMB_HORIZONTAL; 102 WidgetRenderingContext widgetContext(context, rect); 103 widgetContext.paintMozillaWidget(type, &state, 0); 103 gtk_style_context_add_class(m_context, GTK_STYLE_CLASS_SCROLLBAR); 104 gtk_style_context_add_class(m_context, GTK_STYLE_CLASS_SLIDER); 105 106 guint flags = 0; 107 if (scrollbar->pressedPart() == ThumbPart) 108 flags |= GTK_STATE_FLAG_ACTIVE; 109 if (scrollbar->hoveredPart() == ThumbPart) 110 flags |= GTK_STATE_FLAG_PRELIGHT; 111 gtk_style_context_set_state(m_context, static_cast<GtkStateFlags>(flags)); 112 113 gtk_render_slider(m_context, context->platformContext(), rect.x(), rect.y(), rect.width(), rect.height(), 114 scrollbar->orientation() == VerticalScrollbar ? GTK_ORIENTATION_VERTICAL : GTK_ORIENTATION_HORIZONTAL); 115 116 gtk_style_context_restore(m_context); 104 117 } 105 118 106 119 void ScrollbarThemeGtk::paintButton(GraphicsContext* context, Scrollbar* scrollbar, const IntRect& rect, ScrollbarPart part) 107 120 { 108 int flags = 0; 109 if (scrollbar->orientation() == VerticalScrollbar) 110 flags |= MOZ_GTK_STEPPER_VERTICAL; 121 gtk_style_context_save(m_context); 111 122 112 if (part == ForwardButtonEndPart) 113 flags |= (MOZ_GTK_STEPPER_DOWN | MOZ_GTK_STEPPER_BOTTOM); 114 if (part == ForwardButtonStartPart) 115 flags |= MOZ_GTK_STEPPER_DOWN; 123 gtk_style_context_add_class(m_context, GTK_STYLE_CLASS_SCROLLBAR); 116 124 117 GtkWidgetState state; 118 state.focused = TRUE; 119 state.isDefault = TRUE; 120 state.canDefault = TRUE; 121 state.depressed = FALSE; 122 125 guint flags = 0; 123 126 if ((BackButtonStartPart == part && scrollbar->currentPos()) 124 127 || (BackButtonEndPart == part && scrollbar->currentPos()) 125 128 || (ForwardButtonEndPart == part && scrollbar->currentPos() != scrollbar->maximum()) 126 129 || (ForwardButtonStartPart == part && scrollbar->currentPos() != scrollbar->maximum())) { 127 state.disabled = FALSE; 128 state.active = part == scrollbar->pressedPart(); 129 state.inHover = part == scrollbar->hoveredPart(); 130 } else { 131 state.disabled = TRUE; 132 state.active = FALSE; 133 state.inHover = FALSE; 130 if (part == scrollbar->pressedPart()) 131 flags |= GTK_STATE_FLAG_ACTIVE; 132 if (part == scrollbar->hoveredPart()) 133 flags |= GTK_STATE_FLAG_PRELIGHT; 134 } else 135 flags |= GTK_STATE_FLAG_INSENSITIVE; 136 gtk_style_context_set_state(m_context, static_cast<GtkStateFlags>(flags)); 137 138 guint sides = gtk_style_context_get_junction_sides(m_context); 139 if (scrollbar->orientation() == VerticalScrollbar) 140 sides &= ~(GTK_JUNCTION_TOP | GTK_JUNCTION_BOTTOM); 141 else 142 sides &= ~(GTK_JUNCTION_LEFT | GTK_JUNCTION_RIGHT); 143 144 switch (part) { 145 case BackButtonStartPart: 146 sides |= (scrollbar->orientation() == VerticalScrollbar) ? GTK_JUNCTION_BOTTOM : GTK_JUNCTION_RIGHT; 147 break; 148 case BackButtonEndPart: 149 case ForwardButtonEndPart: 150 sides |= (scrollbar->orientation() == VerticalScrollbar) ? 151 GTK_JUNCTION_TOP | GTK_JUNCTION_BOTTOM : GTK_JUNCTION_RIGHT | GTK_JUNCTION_LEFT; 152 break; 153 case ForwardButtonStartPart: 154 sides |= (scrollbar->orientation() == VerticalScrollbar) ? GTK_JUNCTION_TOP : GTK_JUNCTION_LEFT; 155 break; 156 default: 157 ASSERT_NOT_REACHED(); 158 } 159 gtk_style_context_set_junction_sides(m_context, static_cast<GtkJunctionSides>(sides)); 160 gtk_style_context_add_class(m_context, GTK_STYLE_CLASS_BUTTON); 161 162 gtk_render_background(m_context, context->platformContext(), rect.x(), rect.y(), rect.width(), rect.height()); 163 gtk_render_frame(m_context, context->platformContext(), rect.x(), rect.y(), rect.width(), rect.height()); 164 165 gfloat arrowScaling; 166 gtk_style_context_get_style(m_context, "arrow-scaling", &arrowScaling, NULL); 167 168 IntSize arrowSize = rect.size(); 169 arrowSize.scale(arrowScaling); 170 IntPoint arrowPoint(rect.x() + (rect.width() - arrowSize.width()) / 2, 171 rect.y() + (rect.height() - arrowSize.height()) / 2); 172 173 if (flags & GTK_STATE_FLAG_ACTIVE) { 174 gint arrowDisplacementX, arrowDisplacementY; 175 gtk_style_context_get_style(m_context, 176 "arrow-displacement-x", &arrowDisplacementX, 177 "arrow-displacement-y", &arrowDisplacementY, 178 NULL); 179 arrowPoint.move(arrowDisplacementX, arrowDisplacementY); 134 180 } 135 181 136 WidgetRenderingContext widgetContext(context, rect); 137 widgetContext.paintMozillaWidget(MOZ_GTK_SCROLLBAR_BUTTON, &state, flags); 182 gdouble angle, size; 183 if (scrollbar->orientation() == VerticalScrollbar) { 184 size = arrowSize.width(); 185 angle = (part == ForwardButtonEndPart || part == ForwardButtonStartPart) ? G_PI : 0; 186 } else { 187 size = arrowSize.height(); 188 angle = (part == ForwardButtonEndPart || part == ForwardButtonStartPart) ? G_PI / 2 : 3 * (G_PI / 2); 189 } 190 191 gtk_render_arrow(m_context, context->platformContext(), angle, arrowPoint.x(), arrowPoint.y(), size); 192 193 gtk_style_context_restore(m_context); 138 194 } 139 195
Note: See TracChangeset
for help on using the changeset viewer.