[SCM] WebKit Debian packaging branch, debian/experimental, updated. debian/1.3.8-1-1049-g2e11a8e
mrobinson at webkit.org
mrobinson at webkit.org
Fri Jan 21 15:17:04 UTC 2011
The following commit has been merged in the debian/experimental branch:
commit 725be8dfd8041475a5eb38d1b2ee99f61446d58e
Author: mrobinson at webkit.org <mrobinson at webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Date: Mon Jan 10 20:22:07 2011 +0000
2011-01-10 Carlos Garcia Campos <cgarcia at igalia.com>
Reviewed by Xan Lopez.
[GTK] Port combo box painting to GtkStyleContext
https://bugs.webkit.org/show_bug.cgi?id=51828
Use GtkStyleContext API to paint combo boxes when building with
GTK+ 3.x. Method paintButton() has been factored out and the new
static method renderButton() is used by both paintButton() and
paintMenuList().
No new tests. This should not change functionality.
* platform/gtk/RenderThemeGtk3.cpp:
(WebCore::RenderThemeGtk::adjustRepaintRect):
(WebCore::renderButton):
(WebCore::RenderThemeGtk::paintButton):
(WebCore::getComboBoxMetrics):
(WebCore::RenderThemeGtk::popupInternalPaddingLeft):
(WebCore::RenderThemeGtk::popupInternalPaddingRight):
(WebCore::RenderThemeGtk::popupInternalPaddingTop):
(WebCore::RenderThemeGtk::popupInternalPaddingBottom):
(WebCore::RenderThemeGtk::paintMenuList):
git-svn-id: http://svn.webkit.org/repository/webkit/trunk@75409 268f45cc-cd09-0410-ab3c-d52691b4dbfc
diff --git a/Source/WebCore/ChangeLog b/Source/WebCore/ChangeLog
index 44f57a1..df1b29a 100644
--- a/Source/WebCore/ChangeLog
+++ b/Source/WebCore/ChangeLog
@@ -1,3 +1,28 @@
+2011-01-10 Carlos Garcia Campos <cgarcia at igalia.com>
+
+ Reviewed by Xan Lopez.
+
+ [GTK] Port combo box painting to GtkStyleContext
+ https://bugs.webkit.org/show_bug.cgi?id=51828
+
+ Use GtkStyleContext API to paint combo boxes when building with
+ GTK+ 3.x. Method paintButton() has been factored out and the new
+ static method renderButton() is used by both paintButton() and
+ paintMenuList().
+
+ No new tests. This should not change functionality.
+
+ * platform/gtk/RenderThemeGtk3.cpp:
+ (WebCore::RenderThemeGtk::adjustRepaintRect):
+ (WebCore::renderButton):
+ (WebCore::RenderThemeGtk::paintButton):
+ (WebCore::getComboBoxMetrics):
+ (WebCore::RenderThemeGtk::popupInternalPaddingLeft):
+ (WebCore::RenderThemeGtk::popupInternalPaddingRight):
+ (WebCore::RenderThemeGtk::popupInternalPaddingTop):
+ (WebCore::RenderThemeGtk::popupInternalPaddingBottom):
+ (WebCore::RenderThemeGtk::paintMenuList):
+
2011-01-10 Evan Martin <evan at chromium.org>
Reviewed by Tony Chang.
diff --git a/Source/WebCore/platform/gtk/RenderThemeGtk3.cpp b/Source/WebCore/platform/gtk/RenderThemeGtk3.cpp
index 6d414b7..270a03b 100644
--- a/Source/WebCore/platform/gtk/RenderThemeGtk3.cpp
+++ b/Source/WebCore/platform/gtk/RenderThemeGtk3.cpp
@@ -38,6 +38,7 @@
#include "UserAgentStyleSheets.h"
#include "WidgetRenderingContext.h"
#include "gtkdrawing.h"
+#include <cmath>
#include <gdk/gdk.h>
#include <gtk/gtk.h>
@@ -47,6 +48,9 @@
namespace WebCore {
+// This is the default value defined by GTK+, where it was defined as MIN_ARROW_SIZE in gtkarrow.c.
+static const int minArrowSize = 15;
+
typedef HashMap<GType, GRefPtr<GtkStyleContext> > StyleContextMap;
static StyleContextMap& styleContextMap();
@@ -130,6 +134,8 @@ void RenderThemeGtk::adjustRepaintRect(const RenderObject* renderObject, IntRect
context = getStyleContext(part == SliderThumbHorizontalPart ? GTK_TYPE_HSCALE : GTK_TYPE_VSCALE);
break;
case ButtonPart:
+ case MenulistButtonPart:
+ case MenulistPart:
context = getStyleContext(GTK_TYPE_BUTTON);
checkInteriorFocus = true;
break;
@@ -274,17 +280,20 @@ bool RenderThemeGtk::paintRadio(RenderObject* renderObject, const PaintInfo& pai
return false;
}
-bool RenderThemeGtk::paintButton(RenderObject* renderObject, const PaintInfo& paintInfo, const IntRect& rect)
+static void renderButton(RenderTheme* theme, GtkStyleContext* context, RenderObject* renderObject, const PaintInfo& paintInfo, const IntRect& rect)
{
- GtkStyleContext* context = getStyleContext(GTK_TYPE_BUTTON);
- gtk_style_context_save(context);
-
- gtk_style_context_set_direction(context, static_cast<GtkTextDirection>(gtkTextDirection(renderObject->style()->direction())));
- gtk_style_context_add_class(context, GTK_STYLE_CLASS_BUTTON);
-
IntRect buttonRect(rect);
- if (isDefault(renderObject)) {
+ guint flags = 0;
+ if (!theme->isEnabled(renderObject) || theme->isReadOnlyControl(renderObject))
+ flags |= GTK_STATE_FLAG_INSENSITIVE;
+ else if (theme->isHovered(renderObject))
+ flags |= GTK_STATE_FLAG_PRELIGHT;
+ if (theme->isPressed(renderObject))
+ flags |= GTK_STATE_FLAG_ACTIVE;
+ gtk_style_context_set_state(context, static_cast<GtkStateFlags>(flags));
+
+ if (theme->isDefault(renderObject)) {
GtkBorder* borderPtr = 0;
GtkBorder border = { 1, 1, 1, 1 };
@@ -301,19 +310,10 @@ bool RenderThemeGtk::paintButton(RenderObject* renderObject, const PaintInfo& pa
gtk_style_context_add_class(context, GTK_STYLE_CLASS_DEFAULT);
}
- guint flags = 0;
- if (!isEnabled(renderObject) || isReadOnlyControl(renderObject))
- flags |= GTK_STATE_FLAG_INSENSITIVE;
- else if (isHovered(renderObject))
- flags |= GTK_STATE_FLAG_PRELIGHT;
- if (isPressed(renderObject))
- flags |= GTK_STATE_FLAG_ACTIVE;
- gtk_style_context_set_state(context, static_cast<GtkStateFlags>(flags));
-
gtk_render_background(context, paintInfo.context->platformContext(), buttonRect.x(), buttonRect.y(), buttonRect.width(), buttonRect.height());
gtk_render_frame(context, paintInfo.context->platformContext(), buttonRect.x(), buttonRect.y(), buttonRect.width(), buttonRect.height());
- if (isFocused(renderObject)) {
+ if (theme->isFocused(renderObject)) {
gint focusWidth, focusPad;
gboolean displaceFocus, interiorFocus;
gtk_style_context_get_style(context,
@@ -333,7 +333,7 @@ bool RenderThemeGtk::paintButton(RenderObject* renderObject, const PaintInfo& pa
} else
buttonRect.inflate(focusWidth + focusPad);
- if (displaceFocus && isPressed(renderObject)) {
+ if (displaceFocus && theme->isPressed(renderObject)) {
gint childDisplacementX;
gint childDisplacementY;
gtk_style_context_get_style(context,
@@ -345,53 +345,238 @@ bool RenderThemeGtk::paintButton(RenderObject* renderObject, const PaintInfo& pa
gtk_render_focus(context, paintInfo.context->platformContext(), buttonRect.x(), buttonRect.y(), buttonRect.width(), buttonRect.height());
}
+}
+bool RenderThemeGtk::paintButton(RenderObject* renderObject, const PaintInfo& paintInfo, const IntRect& rect)
+{
+ GtkStyleContext* context = getStyleContext(GTK_TYPE_BUTTON);
+ gtk_style_context_save(context);
+
+ gtk_style_context_set_direction(context, static_cast<GtkTextDirection>(gtkTextDirection(renderObject->style()->direction())));
+ gtk_style_context_add_class(context, GTK_STYLE_CLASS_BUTTON);
+
+ renderButton(this, context, renderObject, paintInfo, rect);
gtk_style_context_restore(context);
return false;
}
-static void getComboBoxPadding(RenderStyle* style, int& left, int& top, int& right, int& bottom)
+static void getComboBoxMetrics(RenderStyle* style, GtkBorder& border, int& focus, int& separator)
{
// If this menu list button isn't drawn using the native theme, we
// don't add any extra padding beyond what WebCore already uses.
if (style->appearance() == NoControlPart)
return;
- moz_gtk_get_widget_border(MOZ_GTK_DROPDOWN, &left, &top, &right, &bottom,
- gtkTextDirection(style->direction()), TRUE);
+
+ GtkStyleContext* context = getStyleContext(GTK_TYPE_BUTTON);
+ gtk_style_context_save(context);
+
+ gtk_style_context_add_class(context, GTK_STYLE_CLASS_BUTTON);
+ gtk_style_context_set_direction(context, static_cast<GtkTextDirection>(gtkTextDirection(style->direction())));
+
+ gtk_style_context_get_border(context, static_cast<GtkStateFlags>(0), &border);
+
+ gboolean interiorFocus;
+ gint focusWidth, focusPad;
+ gtk_style_context_get_style(context,
+ "interior-focus", &interiorFocus,
+ "focus-line-width", &focusWidth,
+ "focus-padding", &focusPad, NULL);
+ focus = interiorFocus ? focusWidth + focusPad : 0;
+
+ gtk_style_context_restore(context);
+
+ context = getStyleContext(GTK_TYPE_SEPARATOR);
+ gtk_style_context_save(context);
+
+ GtkTextDirection direction = static_cast<GtkTextDirection>(gtkTextDirection(style->direction()));
+ gtk_style_context_set_direction(context, direction);
+ gtk_style_context_add_class(context, "separator");
+
+ gboolean wideSeparators;
+ gint separatorWidth;
+ gtk_style_context_get_style(context,
+ "wide-separators", &wideSeparators,
+ "separator-width", &separatorWidth,
+ NULL);
+
+ // GTK+ always uses border.left, regardless of text direction. See gtkseperator.c.
+ if (!wideSeparators)
+ separatorWidth = border.left;
+
+ separator = separatorWidth;
+
+ gtk_style_context_restore(context);
}
int RenderThemeGtk::popupInternalPaddingLeft(RenderStyle* style) const
{
- int left = 0, top = 0, right = 0, bottom = 0;
- getComboBoxPadding(style, left, top, right, bottom);
+ GtkBorder borderWidth = { 0, 0, 0, 0 };
+ int focusWidth = 0, separatorWidth = 0;
+ getComboBoxMetrics(style, borderWidth, focusWidth, separatorWidth);
+ int left = borderWidth.left + focusWidth;
+ if (style->direction() == RTL)
+ left += separatorWidth + minArrowSize;
return left;
}
int RenderThemeGtk::popupInternalPaddingRight(RenderStyle* style) const
{
- int left = 0, top = 0, right = 0, bottom = 0;
- getComboBoxPadding(style, left, top, right, bottom);
+ GtkBorder borderWidth = { 0, 0, 0, 0 };
+ int focusWidth = 0, separatorWidth = 0;
+ getComboBoxMetrics(style, borderWidth, focusWidth, separatorWidth);
+ int right = borderWidth.right + focusWidth;
+ if (style->direction() == LTR)
+ right += separatorWidth + minArrowSize;
return right;
}
int RenderThemeGtk::popupInternalPaddingTop(RenderStyle* style) const
{
- int left = 0, top = 0, right = 0, bottom = 0;
- getComboBoxPadding(style, left, top, right, bottom);
- return top;
+ GtkBorder borderWidth = { 0, 0, 0, 0 };
+ int focusWidth = 0, separatorWidth = 0;
+ getComboBoxMetrics(style, borderWidth, focusWidth, separatorWidth);
+ return borderWidth.top + focusWidth;
}
int RenderThemeGtk::popupInternalPaddingBottom(RenderStyle* style) const
{
- int left = 0, top = 0, right = 0, bottom = 0;
- getComboBoxPadding(style, left, top, right, bottom);
- return bottom;
+ GtkBorder borderWidth = { 0, 0, 0, 0 };
+ int focusWidth = 0, separatorWidth = 0;
+ getComboBoxMetrics(style, borderWidth, focusWidth, separatorWidth);
+ return borderWidth.bottom + focusWidth;
}
-bool RenderThemeGtk::paintMenuList(RenderObject* object, const PaintInfo& info, const IntRect& rect)
+bool RenderThemeGtk::paintMenuList(RenderObject* renderObject, const PaintInfo& paintInfo, const IntRect& rect)
{
- return paintRenderObject(MOZ_GTK_DROPDOWN, object, info.context, rect);
+ cairo_t* cairoContext = paintInfo.context->platformContext();
+ GtkTextDirection direction = static_cast<GtkTextDirection>(gtkTextDirection(renderObject->style()->direction()));
+
+ // Paint the button.
+ GtkStyleContext* buttonStyleContext = getStyleContext(GTK_TYPE_BUTTON);
+ gtk_style_context_save(buttonStyleContext);
+ gtk_style_context_set_direction(buttonStyleContext, direction);
+ gtk_style_context_add_class(buttonStyleContext, GTK_STYLE_CLASS_BUTTON);
+ renderButton(this, buttonStyleContext, renderObject, paintInfo, rect);
+
+ // Get the inner rectangle.
+ gint focusWidth, focusPad;
+ GtkBorder* innerBorderPtr = 0;
+ GtkBorder innerBorder = { 1, 1, 1, 1 };
+ gtk_style_context_get_style(buttonStyleContext,
+ "inner-border", &innerBorderPtr,
+ "focus-line-width", &focusWidth,
+ "focus-padding", &focusPad,
+ NULL);
+ if (innerBorderPtr) {
+ innerBorder = *innerBorderPtr;
+ gtk_border_free(innerBorderPtr);
+ }
+
+ GtkBorder borderWidth;
+ GtkStateFlags state = gtk_style_context_get_state(buttonStyleContext);
+ gtk_style_context_get_border(buttonStyleContext, state, &borderWidth);
+
+ focusWidth += focusPad;
+ IntRect innerRect(rect.x() + innerBorder.left + borderWidth.left + focusWidth,
+ rect.y() + innerBorder.top + borderWidth.top + focusWidth,
+ rect.width() - borderWidth.left - borderWidth.right - innerBorder.left - innerBorder.right - (2 * focusWidth),
+ rect.height() - borderWidth.top - borderWidth.bottom - innerBorder.top - innerBorder.bottom - (2 * focusWidth));
+
+ if (isPressed(renderObject)) {
+ gint childDisplacementX;
+ gint childDisplacementY;
+ gtk_style_context_get_style(buttonStyleContext,
+ "child-displacement-x", &childDisplacementX,
+ "child-displacement-y", &childDisplacementY,
+ NULL);
+ innerRect.move(childDisplacementX, childDisplacementY);
+ }
+ innerRect.setWidth(max(1, innerRect.width()));
+ innerRect.setHeight(max(1, innerRect.height()));
+
+ gtk_style_context_restore(buttonStyleContext);
+
+ // Paint the arrow.
+ GtkStyleContext* arrowStyleContext = getStyleContext(GTK_TYPE_ARROW);
+ gtk_style_context_save(arrowStyleContext);
+
+ gtk_style_context_set_direction(arrowStyleContext, direction);
+ gtk_style_context_add_class(arrowStyleContext, "arrow");
+ gtk_style_context_add_class(arrowStyleContext, GTK_STYLE_CLASS_BUTTON);
+
+ gfloat arrowScaling;
+ gtk_style_context_get_style(arrowStyleContext, "arrow-scaling", &arrowScaling, NULL);
+
+ IntSize arrowSize(minArrowSize, innerRect.height());
+ IntPoint 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));
+
+ gtk_style_context_set_state(arrowStyleContext, state);
+ gtk_render_arrow(arrowStyleContext, cairoContext, G_PI, arrowPosition.x(), arrowPosition.y(), extent);
+
+ gtk_style_context_restore(arrowStyleContext);
+
+ // Paint the separator if needed.
+ GtkStyleContext* separatorStyleContext = getStyleContext(GTK_TYPE_SEPARATOR);
+ gtk_style_context_save(separatorStyleContext);
+
+ gtk_style_context_set_direction(separatorStyleContext, direction);
+ gtk_style_context_add_class(separatorStyleContext, "separator");
+ gtk_style_context_add_class(separatorStyleContext, GTK_STYLE_CLASS_BUTTON);
+
+ gboolean wideSeparators;
+ gint separatorWidth;
+ gtk_style_context_get_style(separatorStyleContext,
+ "wide-separators", &wideSeparators,
+ "separator-width", &separatorWidth,
+ NULL);
+ if (wideSeparators && !separatorWidth) {
+ gtk_style_context_restore(separatorStyleContext);
+ return false;
+ }
+
+ gtk_style_context_set_state(separatorStyleContext, state);
+ IntPoint separatorPosition(arrowPosition.x(), innerRect.y());
+ if (wideSeparators) {
+ if (direction == GTK_TEXT_DIR_LTR)
+ separatorPosition.move(-separatorWidth, 0);
+ else
+ separatorPosition.move(arrowSize.width(), 0);
+
+ gtk_render_frame(separatorStyleContext, cairoContext,
+ separatorPosition.x(), separatorPosition.y(),
+ separatorWidth, innerRect.height());
+ } else {
+ GtkBorder padding;
+ gtk_style_context_get_padding(separatorStyleContext, state, &padding);
+ GtkBorder border;
+ gtk_style_context_get_border(separatorStyleContext, state, &border);
+
+ if (direction == GTK_TEXT_DIR_LTR)
+ separatorPosition.move(-(padding.left + border.left), 0);
+ else
+ separatorPosition.move(arrowSize.width(), 0);
+
+ cairo_save(cairoContext);
+
+ // An extra clip prevents the separator bleeding outside of the specified rectangle because of subpixel positioning.
+ cairo_rectangle(cairoContext, separatorPosition.x(), separatorPosition.y(), border.left, innerRect.height());
+ cairo_clip(cairoContext);
+ gtk_render_line(separatorStyleContext, cairoContext,
+ separatorPosition.x(), separatorPosition.y(),
+ separatorPosition.x(), innerRect.bottom());
+ cairo_restore(cairoContext);
+ }
+
+ gtk_style_context_restore(separatorStyleContext);
+ return false;
}
bool RenderThemeGtk::paintTextField(RenderObject* renderObject, const PaintInfo& paintInfo, const IntRect& rect)
--
WebKit Debian packaging
More information about the Pkg-webkit-commits
mailing list