diff options
Diffstat (limited to 'Source/WebCore/platform/gtk')
| -rw-r--r-- | Source/WebCore/platform/gtk/FileSystemGtk.cpp | 8 | ||||
| -rw-r--r-- | Source/WebCore/platform/gtk/LocalizedStringsGtk.cpp | 2 | ||||
| -rw-r--r-- | Source/WebCore/platform/gtk/RenderThemeGtk.cpp | 3 | ||||
| -rw-r--r-- | Source/WebCore/platform/gtk/RenderThemeGtk.h | 2 | ||||
| -rw-r--r-- | Source/WebCore/platform/gtk/RenderThemeGtk2.cpp | 94 | ||||
| -rw-r--r-- | Source/WebCore/platform/gtk/RenderThemeGtk3.cpp | 4 | ||||
| -rw-r--r-- | Source/WebCore/platform/gtk/ScrollViewGtk.cpp | 5 | ||||
| -rw-r--r-- | Source/WebCore/platform/gtk/ScrollbarThemeGtk3.cpp | 36 | ||||
| -rw-r--r-- | Source/WebCore/platform/gtk/WidgetGtk.cpp | 7 | ||||
| -rw-r--r-- | Source/WebCore/platform/gtk/WidgetRenderingContext.cpp | 3 |
10 files changed, 113 insertions, 51 deletions
diff --git a/Source/WebCore/platform/gtk/FileSystemGtk.cpp b/Source/WebCore/platform/gtk/FileSystemGtk.cpp index b3c4c9f..e2b1642 100644 --- a/Source/WebCore/platform/gtk/FileSystemGtk.cpp +++ b/Source/WebCore/platform/gtk/FileSystemGtk.cpp @@ -227,16 +227,16 @@ Vector<String> listDirectory(const String& path, const String& filter) return entries; } -CString openTemporaryFile(const char* prefix, PlatformFileHandle& handle) +String openTemporaryFile(const String& prefix, PlatformFileHandle& handle) { - GOwnPtr<gchar> filename(g_strdup_printf("%s%s", prefix, createCanonicalUUIDString().utf8().data())); + GOwnPtr<gchar> filename(g_strdup_printf("%s%s", prefix.utf8().data(), createCanonicalUUIDString().utf8().data())); GOwnPtr<gchar> tempPath(g_build_filename(g_get_tmp_dir(), filename.get(), NULL)); GRefPtr<GFile> file = adoptGRef(g_file_new_for_path(tempPath.get())); handle = g_file_create_readwrite(file.get(), G_FILE_CREATE_NONE, 0, 0); if (!isHandleValid(handle)) - return CString(); - return tempPath.get(); + return String(); + return String::fromUTF8(tempPath.get()); } PlatformFileHandle openFile(const String& path, FileOpenMode mode) diff --git a/Source/WebCore/platform/gtk/LocalizedStringsGtk.cpp b/Source/WebCore/platform/gtk/LocalizedStringsGtk.cpp index eab0ac6..02f6c47 100644 --- a/Source/WebCore/platform/gtk/LocalizedStringsGtk.cpp +++ b/Source/WebCore/platform/gtk/LocalizedStringsGtk.cpp @@ -259,7 +259,7 @@ String contextMenuItemTagSearchWeb() return String::fromUTF8(_("_Search the Web")); } -String contextMenuItemTagLookUpInDictionary() +String contextMenuItemTagLookUpInDictionary(const String&) { return String::fromUTF8(_("_Look Up in Dictionary")); } diff --git a/Source/WebCore/platform/gtk/RenderThemeGtk.cpp b/Source/WebCore/platform/gtk/RenderThemeGtk.cpp index 1e9f159..9b11c27 100644 --- a/Source/WebCore/platform/gtk/RenderThemeGtk.cpp +++ b/Source/WebCore/platform/gtk/RenderThemeGtk.cpp @@ -34,6 +34,7 @@ #include "HTMLNames.h" #include "MediaControlElements.h" #include "PaintInfo.h" +#include "PlatformContextCairo.h" #include "RenderBox.h" #include "RenderObject.h" #include "TimeRanges.h" @@ -234,7 +235,7 @@ static void paintGdkPixbuf(GraphicsContext* context, const GdkPixbuf* icon, cons icon = scaledIcon.get(); } - cairo_t* cr = context->platformContext(); + cairo_t* cr = context->platformContext()->cr(); cairo_save(cr); gdk_cairo_set_source_pixbuf(cr, icon, iconRect.x(), iconRect.y()); cairo_paint(cr); diff --git a/Source/WebCore/platform/gtk/RenderThemeGtk.h b/Source/WebCore/platform/gtk/RenderThemeGtk.h index f5e03a9..191a34b 100644 --- a/Source/WebCore/platform/gtk/RenderThemeGtk.h +++ b/Source/WebCore/platform/gtk/RenderThemeGtk.h @@ -214,6 +214,7 @@ private: GtkWidget* gtkComboBoxButton() const; GtkWidget* gtkComboBoxArrow() const; GtkWidget* gtkComboBoxSeparator() const; + GtkWidget* gtkSpinButton() const; GdkColormap* m_colormap; mutable GtkWidget* m_gtkWindow; @@ -232,6 +233,7 @@ private: mutable GtkWidget* m_gtkComboBoxSeparator; mutable GtkWidget* m_gtkVScrollbar; mutable GtkWidget* m_gtkHScrollbar; + mutable GtkWidget* m_gtkSpinButton; bool m_themePartsHaveRGBAColormap; friend class WidgetRenderingContext; #endif diff --git a/Source/WebCore/platform/gtk/RenderThemeGtk2.cpp b/Source/WebCore/platform/gtk/RenderThemeGtk2.cpp index 534aa97..5149bea 100644 --- a/Source/WebCore/platform/gtk/RenderThemeGtk2.cpp +++ b/Source/WebCore/platform/gtk/RenderThemeGtk2.cpp @@ -46,6 +46,9 @@ namespace WebCore { +// This is the default value defined by GTK+, where it was defined as MIN_ARROW_WIDTH in gtkspinbutton.c. +static const int minSpinButtonArrowSize = 6; + // This is not a static method, because we want to avoid having GTK+ headers in RenderThemeGtk.h. extern GtkTextDirection gtkTextDirection(TextDirection); @@ -68,6 +71,7 @@ void RenderThemeGtk::platformInit() m_gtkComboBoxSeparator = 0; m_gtkVScrollbar = 0; m_gtkHScrollbar = 0; + m_gtkSpinButton = 0; m_colormap = gdk_screen_get_rgba_colormap(gdk_screen_get_default()); if (!m_colormap) { @@ -117,6 +121,10 @@ void RenderThemeGtk::adjustRepaintRect(const RenderObject* renderObject, IntRect adjustRectForFocus(part == CheckboxPart ? gtkCheckButton() : gtkRadioButton(), rect, true); return; } + case InnerSpinButtonPart: + // See paintInnerSpinButton for an explanation of why we expand the painting rect. + rect.inflateY(2); + rect.setWidth(rect.width() + 2); default: return; } @@ -566,13 +574,84 @@ bool RenderThemeGtk::paintProgressBar(RenderObject* renderObject, const PaintInf } #endif -void RenderThemeGtk::adjustInnerSpinButtonStyle(CSSStyleSelector*, RenderStyle*, Element*) const +void RenderThemeGtk::adjustInnerSpinButtonStyle(CSSStyleSelector*, RenderStyle* style, Element*) const { + GtkStyle* gtkStyle = gtk_widget_get_style(gtkSpinButton()); + const PangoFontDescription* fontDescription = gtkStyle->font_desc; + gint fontSize = pango_font_description_get_size(fontDescription); + + // Force an odd arrow size here. GTK+ 3.x forces even in this case, but + // Nodoka-based themes look incorrect with an even arrow size. + int width = max(PANGO_PIXELS(fontSize), minSpinButtonArrowSize); + width += -((width % 2) - 1) + gtkStyle->xthickness; + + style->setWidth(Length(width, Fixed)); + style->setMinWidth(Length(width, Fixed)); } -bool RenderThemeGtk::paintInnerSpinButton(RenderObject*, const PaintInfo&, const IntRect&) +bool RenderThemeGtk::paintInnerSpinButton(RenderObject* renderObject, const PaintInfo& paintInfo, const IntRect& rect) { - return true; + // We expand the painted area by 2 pixels on the top and bottom and 2 pixels on the right. This + // is because GTK+ themes want to draw over the text box borders, but WebCore renders the inner + // spin button inside the text box. + IntRect expandedRect(rect); + expandedRect.inflateY(2); + expandedRect.setWidth(rect.width() + 2); + + WidgetRenderingContext widgetContext(paintInfo.context, expandedRect); + GtkWidget* widget = gtkSpinButton(); + gtk_widget_set_direction(widget, gtkTextDirection(renderObject->style()->direction())); + + IntRect fullSpinButtonRect(IntPoint(), expandedRect.size()); + widgetContext.gtkPaintBox(fullSpinButtonRect, widget, GTK_STATE_NORMAL, GTK_SHADOW_IN, "spinbutton"); + + bool upPressed = isSpinUpButtonPartPressed(renderObject); + bool upHovered = isSpinUpButtonPartHovered(renderObject); + bool controlActive = isEnabled(renderObject) && !isReadOnlyControl(renderObject); + GtkShadowType shadowType = upPressed ? GTK_SHADOW_IN : GTK_SHADOW_OUT; + + GtkStateType stateType = GTK_STATE_INSENSITIVE; + if (controlActive) { + if (isPressed(renderObject) && upPressed) + stateType = GTK_STATE_ACTIVE; + else if (isHovered(renderObject) && upHovered) + stateType = GTK_STATE_PRELIGHT; + else + stateType = GTK_STATE_NORMAL; + } + IntRect topRect(IntPoint(), expandedRect.size()); + topRect.setHeight(expandedRect.height() / 2); + widgetContext.gtkPaintBox(topRect, widget, stateType, shadowType, "spinbutton_up"); + + // The arrow size/position calculation here is based on the arbitrary gymnastics that happen + // in gtkspinbutton.c. It isn't pretty there and it isn't pretty here. This manages to make + // the button look native for many themes though. + IntRect arrowRect; + int arrowSize = (expandedRect.width() - 3) / 2; + arrowSize -= (arrowSize % 2) - 1; // Force odd. + arrowRect.setWidth(arrowSize); + arrowRect.setHeight(arrowSize); + arrowRect.move((expandedRect.width() - arrowRect.width()) / 2, + (topRect.height() - arrowRect.height()) / 2 + 1); + widgetContext.gtkPaintArrow(arrowRect, widget, stateType, shadowType, GTK_ARROW_UP, "spinbutton"); + + shadowType = isPressed(renderObject) && !upPressed ? GTK_SHADOW_IN : GTK_SHADOW_OUT; + if (controlActive) { + if (isPressed(renderObject) && !upPressed) + stateType = GTK_STATE_ACTIVE; + else if (isHovered(renderObject) && !upHovered) + stateType = GTK_STATE_PRELIGHT; + else + stateType = GTK_STATE_NORMAL; + } + IntRect bottomRect(IntPoint(0, expandedRect.height() / 2), expandedRect.size()); + bottomRect.setHeight(expandedRect.height() - bottomRect.y()); + widgetContext.gtkPaintBox(bottomRect, widget, stateType, shadowType, "spinbutton_down"); + + arrowRect.setY(arrowRect.y() + bottomRect.y() - 1); + widgetContext.gtkPaintArrow(arrowRect, widget, stateType, shadowType, GTK_ARROW_DOWN, "spinbutton"); + + return false; } GRefPtr<GdkPixbuf> RenderThemeGtk::getStockIcon(GType widgetType, const char* iconName, gint direction, gint state, gint iconSize) @@ -867,6 +946,15 @@ GtkWidget* RenderThemeGtk::gtkVScrollbar() const return m_gtkVScrollbar; } +GtkWidget* RenderThemeGtk::gtkSpinButton() const +{ + if (m_gtkSpinButton) + return m_gtkSpinButton; + m_gtkSpinButton = gtk_spin_button_new_with_range(0, 10, 1); + setupWidgetAndAddToContainer(m_gtkSpinButton, gtkContainer()); + return m_gtkSpinButton; +} + } // namespace WebCore #endif // GTK_API_VERSION_2 diff --git a/Source/WebCore/platform/gtk/RenderThemeGtk3.cpp b/Source/WebCore/platform/gtk/RenderThemeGtk3.cpp index 7fa0f04..527de1a 100644 --- a/Source/WebCore/platform/gtk/RenderThemeGtk3.cpp +++ b/Source/WebCore/platform/gtk/RenderThemeGtk3.cpp @@ -483,14 +483,14 @@ bool RenderThemeGtk::paintMenuList(RenderObject* renderObject, const PaintInfo& gtk_style_context_get_style(arrowStyleContext, "arrow-scaling", &arrowScaling, NULL); IntSize arrowSize(minArrowSize, innerRect.height()); - IntPoint arrowPosition = innerRect.location(); + FloatPoint arrowPosition(innerRect.location()); if (direction == GTK_TEXT_DIR_LTR) arrowPosition.move(innerRect.width() - arrowSize.width(), 0); // GTK+ actually fetches the xalign and valign values from the widget, but since we // don't have a widget here, we are just using the default xalign and valign values of 0.5. gint extent = std::min(arrowSize.width(), arrowSize.height()) * arrowScaling; - arrowPosition.move(std::floor((arrowSize.width() - extent) / 2), std::floor((arrowSize.height() - extent) / 2)); + arrowPosition.move((arrowSize.width() - extent) / 2, (arrowSize.height() - extent) / 2); gtk_style_context_set_state(arrowStyleContext, state); gtk_render_arrow(arrowStyleContext, cairoContext, G_PI, arrowPosition.x(), arrowPosition.y(), extent); diff --git a/Source/WebCore/platform/gtk/ScrollViewGtk.cpp b/Source/WebCore/platform/gtk/ScrollViewGtk.cpp index c5f32f3..53cacf7 100644 --- a/Source/WebCore/platform/gtk/ScrollViewGtk.cpp +++ b/Source/WebCore/platform/gtk/ScrollViewGtk.cpp @@ -31,6 +31,8 @@ #include "config.h" #include "ScrollView.h" +#if USE(NATIVE_GTK_MAIN_FRAME_SCROLLBAR) + #include "ChromeClient.h" #include "FloatRect.h" #include "Frame.h" @@ -44,7 +46,6 @@ #include "PlatformMouseEvent.h" #include "PlatformWheelEvent.h" #include "ScrollbarTheme.h" - #include <gtk/gtk.h> using namespace std; @@ -228,3 +229,5 @@ void ScrollView::setScrollbarModes(ScrollbarMode horizontalMode, ScrollbarMode v } } + +#endif // USE(NATIVE_GTK_MAIN_FRAME_SCROLLBAR) diff --git a/Source/WebCore/platform/gtk/ScrollbarThemeGtk3.cpp b/Source/WebCore/platform/gtk/ScrollbarThemeGtk3.cpp index d000063..b0b5146 100644 --- a/Source/WebCore/platform/gtk/ScrollbarThemeGtk3.cpp +++ b/Source/WebCore/platform/gtk/ScrollbarThemeGtk3.cpp @@ -135,40 +135,16 @@ void ScrollbarThemeGtk::paintButton(GraphicsContext* context, Scrollbar* scrollb flags |= GTK_STATE_FLAG_INSENSITIVE; gtk_style_context_set_state(m_context, static_cast<GtkStateFlags>(flags)); - guint sides = gtk_style_context_get_junction_sides(m_context); - if (scrollbar->orientation() == VerticalScrollbar) - sides &= ~(GTK_JUNCTION_TOP | GTK_JUNCTION_BOTTOM); - else - sides &= ~(GTK_JUNCTION_LEFT | GTK_JUNCTION_RIGHT); - - switch (part) { - case BackButtonStartPart: - sides |= (scrollbar->orientation() == VerticalScrollbar) ? GTK_JUNCTION_BOTTOM : GTK_JUNCTION_RIGHT; - break; - case BackButtonEndPart: - case ForwardButtonEndPart: - sides |= (scrollbar->orientation() == VerticalScrollbar) ? - GTK_JUNCTION_TOP | GTK_JUNCTION_BOTTOM : GTK_JUNCTION_RIGHT | GTK_JUNCTION_LEFT; - break; - case ForwardButtonStartPart: - sides |= (scrollbar->orientation() == VerticalScrollbar) ? GTK_JUNCTION_TOP : GTK_JUNCTION_LEFT; - break; - default: - ASSERT_NOT_REACHED(); - } - gtk_style_context_set_junction_sides(m_context, static_cast<GtkJunctionSides>(sides)); gtk_style_context_add_class(m_context, GTK_STYLE_CLASS_BUTTON); - gtk_render_background(m_context, context->platformContext(), rect.x(), rect.y(), rect.width(), rect.height()); gtk_render_frame(m_context, context->platformContext(), rect.x(), rect.y(), rect.width(), rect.height()); gfloat arrowScaling; gtk_style_context_get_style(m_context, "arrow-scaling", &arrowScaling, NULL); - IntSize arrowSize = rect.size(); - arrowSize.scale(arrowScaling); - IntPoint arrowPoint(rect.x() + (rect.width() - arrowSize.width()) / 2, - rect.y() + (rect.height() - arrowSize.height()) / 2); + double arrowSize = std::min(rect.width(), rect.height()) * arrowScaling; + FloatPoint arrowPoint(rect.x() + (rect.width() - arrowSize) / 2, + rect.y() + (rect.height() - arrowSize) / 2); if (flags & GTK_STATE_FLAG_ACTIVE) { gint arrowDisplacementX, arrowDisplacementY; @@ -179,16 +155,14 @@ void ScrollbarThemeGtk::paintButton(GraphicsContext* context, Scrollbar* scrollb arrowPoint.move(arrowDisplacementX, arrowDisplacementY); } - gdouble angle, size; + gdouble angle; if (scrollbar->orientation() == VerticalScrollbar) { - size = arrowSize.width(); angle = (part == ForwardButtonEndPart || part == ForwardButtonStartPart) ? G_PI : 0; } else { - size = arrowSize.height(); angle = (part == ForwardButtonEndPart || part == ForwardButtonStartPart) ? G_PI / 2 : 3 * (G_PI / 2); } - gtk_render_arrow(m_context, context->platformContext(), angle, arrowPoint.x(), arrowPoint.y(), size); + gtk_render_arrow(m_context, context->platformContext(), angle, arrowPoint.x(), arrowPoint.y(), arrowSize); gtk_style_context_restore(m_context); } diff --git a/Source/WebCore/platform/gtk/WidgetGtk.cpp b/Source/WebCore/platform/gtk/WidgetGtk.cpp index f251772..0ab3940 100644 --- a/Source/WebCore/platform/gtk/WidgetGtk.cpp +++ b/Source/WebCore/platform/gtk/WidgetGtk.cpp @@ -41,8 +41,6 @@ namespace WebCore { -static GdkCursor* lastSetCursor; - Widget::Widget(PlatformWidget widget) { init(widget); @@ -60,11 +58,6 @@ void Widget::setFocus(bool focused) gtk_widget_grab_focus(platformWidget() ? platformWidget() : GTK_WIDGET(root()->hostWindow()->platformPageClient())); } -static GdkWindow* gdkWindow(PlatformWidget widget) -{ - return widget ? gtk_widget_get_window(widget) : 0; -} - void Widget::setCursor(const Cursor& cursor) { ScrollView* view = root(); diff --git a/Source/WebCore/platform/gtk/WidgetRenderingContext.cpp b/Source/WebCore/platform/gtk/WidgetRenderingContext.cpp index 9e640f6..6f7389d 100644 --- a/Source/WebCore/platform/gtk/WidgetRenderingContext.cpp +++ b/Source/WebCore/platform/gtk/WidgetRenderingContext.cpp @@ -33,6 +33,7 @@ #include "GraphicsContext.h" #include "GtkVersioning.h" +#include "PlatformContextCairo.h" #include "RefPtrCairo.h" #include "RenderThemeGtk.h" #include "Timer.h" @@ -128,7 +129,7 @@ WidgetRenderingContext::~WidgetRenderingContext() } // FIXME: It's unclear if it is necessary to preserve the current source here. - cairo_t* cairoContext = m_graphicsContext->platformContext(); + cairo_t* cairoContext = m_graphicsContext->platformContext()->cr(); RefPtr<cairo_pattern_t> previousSource(cairo_get_source(cairoContext)); // The blit rectangle is the original target rectangle adjusted for any extra space. |
