summaryrefslogtreecommitdiffstats
path: root/Source/WebCore/platform/gtk
diff options
context:
space:
mode:
authorBen Murdoch <benm@google.com>2011-05-13 16:23:25 +0100
committerBen Murdoch <benm@google.com>2011-05-16 11:35:02 +0100
commit65f03d4f644ce73618e5f4f50dd694b26f55ae12 (patch)
treef478babb801e720de7bfaee23443ffe029f58731 /Source/WebCore/platform/gtk
parent47de4a2fb7262c7ebdb9cd133ad2c54c187454d0 (diff)
downloadexternal_webkit-65f03d4f644ce73618e5f4f50dd694b26f55ae12.zip
external_webkit-65f03d4f644ce73618e5f4f50dd694b26f55ae12.tar.gz
external_webkit-65f03d4f644ce73618e5f4f50dd694b26f55ae12.tar.bz2
Merge WebKit at r75993: Initial merge by git.
Change-Id: I602bbdc3974787a3b0450456a30a7868286921c3
Diffstat (limited to 'Source/WebCore/platform/gtk')
-rw-r--r--Source/WebCore/platform/gtk/ContextMenuGtk.cpp17
-rw-r--r--Source/WebCore/platform/gtk/ContextMenuItemGtk.cpp55
-rw-r--r--Source/WebCore/platform/gtk/DragDataGtk.cpp13
-rw-r--r--Source/WebCore/platform/gtk/FileSystemGtk.cpp48
-rw-r--r--Source/WebCore/platform/gtk/GRefPtrGtk.cpp2
-rw-r--r--Source/WebCore/platform/gtk/GRefPtrGtk.h2
-rw-r--r--Source/WebCore/platform/gtk/GtkVersioning.h10
-rw-r--r--Source/WebCore/platform/gtk/RenderThemeGtk.cpp110
-rw-r--r--Source/WebCore/platform/gtk/RenderThemeGtk.h53
-rw-r--r--Source/WebCore/platform/gtk/RenderThemeGtk2.cpp108
-rw-r--r--Source/WebCore/platform/gtk/RenderThemeGtk3.cpp610
-rw-r--r--Source/WebCore/platform/gtk/WidgetRenderingContext.cpp (renamed from Source/WebCore/platform/gtk/WidgetRenderingContextGtk2.cpp)3
-rw-r--r--Source/WebCore/platform/gtk/WidgetRenderingContext.h10
-rw-r--r--Source/WebCore/platform/gtk/WidgetRenderingContextGtk3.cpp73
-rw-r--r--Source/WebCore/platform/gtk/gtk3drawing.c1288
-rw-r--r--Source/WebCore/platform/gtk/gtkdrawing.h9
16 files changed, 663 insertions, 1748 deletions
diff --git a/Source/WebCore/platform/gtk/ContextMenuGtk.cpp b/Source/WebCore/platform/gtk/ContextMenuGtk.cpp
index 423959a..b34631d 100644
--- a/Source/WebCore/platform/gtk/ContextMenuGtk.cpp
+++ b/Source/WebCore/platform/gtk/ContextMenuGtk.cpp
@@ -1,5 +1,6 @@
/*
* Copyright (C) 2007 Holger Hans Peter Freyther
+ * Portions Copyright (c) 2010 Motorola Mobility, Inc. All rights reserved.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
@@ -19,6 +20,7 @@
#include "config.h"
#include "ContextMenu.h"
+#include "NotImplemented.h"
#include <gtk/gtk.h>
namespace WebCore {
@@ -26,14 +28,12 @@ namespace WebCore {
ContextMenu::ContextMenu()
{
m_platformDescription = GTK_MENU(gtk_menu_new());
-
- g_object_ref_sink(G_OBJECT(m_platformDescription));
}
ContextMenu::~ContextMenu()
{
if (m_platformDescription)
- g_object_unref(m_platformDescription);
+ gtk_widget_destroy(GTK_WIDGET(m_platformDescription));
}
void ContextMenu::appendItem(ContextMenuItem& item)
@@ -50,10 +50,9 @@ void ContextMenu::setPlatformDescription(PlatformMenuDescription menu)
{
ASSERT(menu);
if (m_platformDescription)
- g_object_unref(m_platformDescription);
+ gtk_widget_destroy(GTK_WIDGET(m_platformDescription));
m_platformDescription = menu;
- g_object_ref(m_platformDescription);
}
PlatformMenuDescription ContextMenu::platformDescription() const
@@ -69,4 +68,12 @@ PlatformMenuDescription ContextMenu::releasePlatformDescription()
return description;
}
+Vector<ContextMenuItem> contextMenuItemVector(const PlatformMenuDescription)
+{
+ notImplemented();
+
+ Vector<ContextMenuItem> menuItemVector;
+ return menuItemVector;
+}
+
}
diff --git a/Source/WebCore/platform/gtk/ContextMenuItemGtk.cpp b/Source/WebCore/platform/gtk/ContextMenuItemGtk.cpp
index 4d79f13..fee7a14 100644
--- a/Source/WebCore/platform/gtk/ContextMenuItemGtk.cpp
+++ b/Source/WebCore/platform/gtk/ContextMenuItemGtk.cpp
@@ -1,6 +1,7 @@
/*
* Copyright (C) 2007 Holger Hans Peter Freyther
* Copyright (C) 2010 Igalia S.L
+ * Portions Copyright (c) 2010 Motorola Mobility, Inc. All rights reserved.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
@@ -144,28 +145,42 @@ ContextMenuItem::ContextMenuItem(ContextMenuItemType type, ContextMenuAction act
m_platformDescription = GTK_MENU_ITEM(gtk_action_create_menu_item(platformAction));
g_object_unref(platformAction);
- g_object_set_data(G_OBJECT(m_platformDescription.get()), WEBKIT_CONTEXT_MENU_ACTION, GINT_TO_POINTER(action));
+ g_object_set_data(G_OBJECT(m_platformDescription), WEBKIT_CONTEXT_MENU_ACTION, GINT_TO_POINTER(action));
if (subMenu)
setSubMenu(subMenu);
}
+ContextMenuItem::ContextMenuItem(ContextMenuItemType, ContextMenuAction, const String&, bool, bool)
+{
+ // FIXME: Implement with WebKit2 ContextMenu changes.
+ notImplemented();
+}
+
+ContextMenuItem::ContextMenuItem(ContextMenuAction, const String&, bool, bool, Vector<ContextMenuItem>&)
+{
+ // FIXME: Implement with WebKit2 ContextMenu changes.
+ notImplemented();
+}
+
ContextMenuItem::~ContextMenuItem()
{
}
PlatformMenuItemDescription ContextMenuItem::releasePlatformDescription()
{
- return m_platformDescription.leakRef();
+ PlatformMenuItemDescription platformDescription = m_platformDescription;
+ m_platformDescription = 0;
+ return platformDescription;
}
ContextMenuItemType ContextMenuItem::type() const
{
- if (GTK_IS_SEPARATOR_MENU_ITEM(m_platformDescription.get()))
+ if (GTK_IS_SEPARATOR_MENU_ITEM(m_platformDescription))
return SeparatorType;
- if (GTK_IS_CHECK_MENU_ITEM(m_platformDescription.get()))
+ if (GTK_IS_CHECK_MENU_ITEM(m_platformDescription))
return CheckableActionType;
- if (gtk_menu_item_get_submenu(m_platformDescription.get()))
+ if (gtk_menu_item_get_submenu(m_platformDescription))
return SubmenuType;
return ActionType;
}
@@ -178,48 +193,62 @@ void ContextMenuItem::setType(ContextMenuItemType type)
ContextMenuAction ContextMenuItem::action() const
{
- return static_cast<ContextMenuAction>(GPOINTER_TO_INT(g_object_get_data(G_OBJECT(m_platformDescription.get()), WEBKIT_CONTEXT_MENU_ACTION)));
+ return static_cast<ContextMenuAction>(GPOINTER_TO_INT(g_object_get_data(G_OBJECT(m_platformDescription), WEBKIT_CONTEXT_MENU_ACTION)));
}
void ContextMenuItem::setAction(ContextMenuAction action)
{
- g_object_set_data(G_OBJECT(m_platformDescription.get()), WEBKIT_CONTEXT_MENU_ACTION, GINT_TO_POINTER(action));
+ g_object_set_data(G_OBJECT(m_platformDescription), WEBKIT_CONTEXT_MENU_ACTION, GINT_TO_POINTER(action));
}
String ContextMenuItem::title() const
{
- GtkAction* action = gtk_activatable_get_related_action(GTK_ACTIVATABLE(m_platformDescription.get()));
+ GtkAction* action = gtk_activatable_get_related_action(GTK_ACTIVATABLE(m_platformDescription));
return action ? String(gtk_action_get_label(action)) : String();
}
void ContextMenuItem::setTitle(const String& title)
{
- GtkAction* action = gtk_activatable_get_related_action(GTK_ACTIVATABLE(m_platformDescription.get()));
+ GtkAction* action = gtk_activatable_get_related_action(GTK_ACTIVATABLE(m_platformDescription));
if (action)
gtk_action_set_label(action, title.utf8().data());
}
PlatformMenuDescription ContextMenuItem::platformSubMenu() const
{
- GtkWidget* subMenu = gtk_menu_item_get_submenu(m_platformDescription.get());
+ GtkWidget* subMenu = gtk_menu_item_get_submenu(m_platformDescription);
return subMenu ? GTK_MENU(subMenu) : 0;
}
void ContextMenuItem::setSubMenu(ContextMenu* menu)
{
- gtk_menu_item_set_submenu(m_platformDescription.get(), GTK_WIDGET(menu->platformDescription()));
+ gtk_menu_item_set_submenu(m_platformDescription, GTK_WIDGET(menu->platformDescription()));
}
void ContextMenuItem::setChecked(bool shouldCheck)
{
- GtkAction* action = gtk_activatable_get_related_action(GTK_ACTIVATABLE(m_platformDescription.get()));
+ GtkAction* action = gtk_activatable_get_related_action(GTK_ACTIVATABLE(m_platformDescription));
if (action && GTK_IS_TOGGLE_ACTION(action))
gtk_toggle_action_set_active(GTK_TOGGLE_ACTION(action), shouldCheck);
}
+bool ContextMenuItem::checked() const
+{
+ // FIXME: Implement with WebKit2 ContextMenu changes.
+ notImplemented();
+ return false;
+}
+
+bool ContextMenuItem::enabled() const
+{
+ // FIXME: Implement with WebKit2 ContextMenu changes.
+ notImplemented();
+ return false;
+}
+
void ContextMenuItem::setEnabled(bool shouldEnable)
{
- GtkAction* action = gtk_activatable_get_related_action(GTK_ACTIVATABLE(m_platformDescription.get()));
+ GtkAction* action = gtk_activatable_get_related_action(GTK_ACTIVATABLE(m_platformDescription));
if (action)
gtk_action_set_sensitive(action, shouldEnable);
}
diff --git a/Source/WebCore/platform/gtk/DragDataGtk.cpp b/Source/WebCore/platform/gtk/DragDataGtk.cpp
index 42ddb16..3a1daf1 100644
--- a/Source/WebCore/platform/gtk/DragDataGtk.cpp
+++ b/Source/WebCore/platform/gtk/DragDataGtk.cpp
@@ -21,6 +21,7 @@
#include "ClipboardGtk.h"
#include "Document.h"
#include "DocumentFragment.h"
+#include "Frame.h"
#include "markup.h"
namespace WebCore {
@@ -50,7 +51,7 @@ bool DragData::containsPlainText() const
return m_platformDragData->hasText();
}
-String DragData::asPlainText() const
+String DragData::asPlainText(Frame*) const
{
return m_platformDragData->text();
}
@@ -62,15 +63,15 @@ Color DragData::asColor() const
bool DragData::containsCompatibleContent() const
{
- return containsPlainText() || containsURL() || m_platformDragData->hasMarkup() || containsColor() || containsFiles();
+ return containsPlainText() || containsURL(0) || m_platformDragData->hasMarkup() || containsColor() || containsFiles();
}
-bool DragData::containsURL(FilenameConversionPolicy filenamePolicy) const
+bool DragData::containsURL(Frame*, FilenameConversionPolicy filenamePolicy) const
{
return m_platformDragData->hasURL();
}
-String DragData::asURL(FilenameConversionPolicy filenamePolicy, String* title) const
+String DragData::asURL(Frame*, FilenameConversionPolicy filenamePolicy, String* title) const
{
String url(m_platformDragData->url());
if (title)
@@ -79,12 +80,12 @@ String DragData::asURL(FilenameConversionPolicy filenamePolicy, String* title) c
}
-PassRefPtr<DocumentFragment> DragData::asFragment(Document* document) const
+PassRefPtr<DocumentFragment> DragData::asFragment(Frame* frame, PassRefPtr<Range>, bool, bool&) const
{
if (!m_platformDragData->hasMarkup())
return 0;
- return createFragmentFromMarkup(document, m_platformDragData->markup(), "");
+ return createFragmentFromMarkup(frame->document(), m_platformDragData->markup(), "");
}
}
diff --git a/Source/WebCore/platform/gtk/FileSystemGtk.cpp b/Source/WebCore/platform/gtk/FileSystemGtk.cpp
index b8aa102..b3c4c9f 100644
--- a/Source/WebCore/platform/gtk/FileSystemGtk.cpp
+++ b/Source/WebCore/platform/gtk/FileSystemGtk.cpp
@@ -2,6 +2,7 @@
* Copyright (C) 2007, 2009 Holger Hans Peter Freyther
* Copyright (C) 2008 Collabora, Ltd.
* Copyright (C) 2008 Apple Inc. All rights reserved.
+ * Portions Copyright (c) 2010 Motorola Mobility, Inc. All rights reserved.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
@@ -45,10 +46,8 @@ String filenameToString(const char* filename)
#if OS(WINDOWS)
return String::fromUTF8(filename);
#else
- gchar* escapedString = g_uri_escape_string(filename, "/:", false);
- String string(escapedString);
- g_free(escapedString);
- return string;
+ GOwnPtr<gchar> escapedString(g_uri_escape_string(filename, "/:", false));
+ return escapedString.get();
#endif
}
@@ -57,10 +56,8 @@ CString fileSystemRepresentation(const String& path)
#if OS(WINDOWS)
return path.utf8();
#else
- char* filename = g_uri_unescape_string(path.utf8().data(), 0);
- CString cfilename(filename);
- g_free(filename);
- return cfilename;
+ GOwnPtr<gchar> filename(g_uri_unescape_string(path.utf8().data(), 0));
+ return filename.get();
#endif
}
@@ -71,14 +68,11 @@ String filenameForDisplay(const String& string)
return string;
#else
CString filename = fileSystemRepresentation(string);
- gchar* display = g_filename_to_utf8(filename.data(), 0, 0, 0, 0);
+ GOwnPtr<gchar> display(g_filename_to_utf8(filename.data(), 0, 0, 0, 0));
if (!display)
return string;
- String displayString = String::fromUTF8(display);
- g_free(display);
-
- return displayString;
+ return String::fromUTF8(display.get());
#endif
}
@@ -176,11 +170,31 @@ String pathGetFileName(const String& pathName)
return pathName;
CString tmpFilename = fileSystemRepresentation(pathName);
- char* baseName = g_path_get_basename(tmpFilename.data());
- String fileName = String::fromUTF8(baseName);
- g_free(baseName);
+ GOwnPtr<gchar> baseName(g_path_get_basename(tmpFilename.data()));
+ return String::fromUTF8(baseName.get());
+}
+
+CString applicationDirectoryPath()
+{
+#if OS(LINUX)
+ // Handle the /proc filesystem case.
+ char pathFromProc[PATH_MAX] = {0};
+ if (readlink("/proc/self/exe", pathFromProc, sizeof(pathFromProc) - 1) == -1)
+ return CString();
+
+ GOwnPtr<char> dirname(g_path_get_dirname(pathFromProc));
+ return dirname.get();
+#elif OS(UNIX)
+ // If the above fails, check the PATH env variable.
+ GOwnPtr<char> currentExePath(g_find_program_in_path(g_get_prgname()));
+ if (!currentExePath.get())
+ return CString();
- return fileName;
+ GOwnPtr<char> dirname(g_path_get_dirname(currentExePath.get()));
+ return dirname.get();
+#else
+ return CString();
+#endif
}
String directoryName(const String& path)
diff --git a/Source/WebCore/platform/gtk/GRefPtrGtk.cpp b/Source/WebCore/platform/gtk/GRefPtrGtk.cpp
index 6647b99..9a9d679 100644
--- a/Source/WebCore/platform/gtk/GRefPtrGtk.cpp
+++ b/Source/WebCore/platform/gtk/GRefPtrGtk.cpp
@@ -38,6 +38,7 @@ template <> void derefGPtr(GtkTargetList* ptr)
gtk_target_list_unref(ptr);
}
+#ifdef GTK_API_VERSION_2
template <> GdkCursor* refGPtr(GdkCursor* ptr)
{
if (ptr)
@@ -50,5 +51,6 @@ template <> void derefGPtr(GdkCursor* ptr)
if (ptr)
gdk_cursor_unref(ptr);
}
+#endif
}
diff --git a/Source/WebCore/platform/gtk/GRefPtrGtk.h b/Source/WebCore/platform/gtk/GRefPtrGtk.h
index 1fb9772..a9f491f 100644
--- a/Source/WebCore/platform/gtk/GRefPtrGtk.h
+++ b/Source/WebCore/platform/gtk/GRefPtrGtk.h
@@ -28,8 +28,10 @@ namespace WTF {
template <> GtkTargetList* refGPtr(GtkTargetList* ptr);
template <> void derefGPtr(GtkTargetList* ptr);
+#ifdef GTK_API_VERSION_2
template <> GdkCursor* refGPtr(GdkCursor* ptr);
template <> void derefGPtr(GdkCursor* ptr);
+#endif
}
diff --git a/Source/WebCore/platform/gtk/GtkVersioning.h b/Source/WebCore/platform/gtk/GtkVersioning.h
index 11d1f8a..7e9fcd1 100644
--- a/Source/WebCore/platform/gtk/GtkVersioning.h
+++ b/Source/WebCore/platform/gtk/GtkVersioning.h
@@ -37,12 +37,14 @@ GdkPixbuf* gdk_pixbuf_get_from_surface(cairo_surface_t* surface, int srcX, int s
int width, int height);
#endif
-#if !GTK_CHECK_VERSION(2, 24, 0)
+#if !GTK_CHECK_VERSION(2, 23, 4)
+#define gdk_pixmap_get_size gdk_drawable_get_size
+#endif // GTK_CHECK_VERSION(2, 23, 4)
+
+#if !GTK_CHECK_VERSION(2, 23, 0)
#define gdk_window_get_display(window) gdk_drawable_get_display(window)
-#ifdef GDK_DISABLE_DEPRECATED
#define gdk_window_get_visual gdk_drawable_get_visual
-#endif
-#endif // GTK_CHECK_VERSION(2, 24, 0)
+#endif // GTK_CHECK_VERSION(2, 23, 0)
#if !GTK_CHECK_VERSION(2, 21, 2)
#define gdk_visual_get_depth(visual) (visual)->depth
diff --git a/Source/WebCore/platform/gtk/RenderThemeGtk.cpp b/Source/WebCore/platform/gtk/RenderThemeGtk.cpp
index c194946..97c966d 100644
--- a/Source/WebCore/platform/gtk/RenderThemeGtk.cpp
+++ b/Source/WebCore/platform/gtk/RenderThemeGtk.cpp
@@ -33,6 +33,7 @@
#include "HTMLMediaElement.h"
#include "HTMLNames.h"
#include "MediaControlElements.h"
+#include "PaintInfo.h"
#include "RenderBox.h"
#include "RenderObject.h"
#include "TimeRanges.h"
@@ -101,73 +102,22 @@ PassRefPtr<RenderTheme> RenderTheme::themeForPage(Page* page)
return rt;
}
-static int mozGtkRefCount = 0;
-
RenderThemeGtk::RenderThemeGtk()
- : m_gtkWindow(0)
- , m_gtkContainer(0)
- , m_gtkButton(0)
- , m_gtkEntry(0)
- , m_gtkTreeView(0)
- , m_gtkVScale(0)
- , m_gtkHScale(0)
- , m_panelColor(Color::white)
+ : m_panelColor(Color::white)
, m_sliderColor(Color::white)
, m_sliderThumbColor(Color::white)
, m_mediaIconSize(16)
, m_mediaSliderHeight(14)
, m_mediaSliderThumbWidth(12)
, m_mediaSliderThumbHeight(12)
-#ifdef GTK_API_VERSION_2
- , m_themePartsHaveRGBAColormap(true)
-#endif
{
-
- memset(&m_themeParts, 0, sizeof(GtkThemeParts));
-#ifdef GTK_API_VERSION_2
- GdkColormap* colormap = gdk_screen_get_rgba_colormap(gdk_screen_get_default());
- if (!colormap) {
- m_themePartsHaveRGBAColormap = false;
- colormap = gdk_screen_get_default_colormap(gdk_screen_get_default());
- }
- m_themeParts.colormap = colormap;
-#endif
-
- // Initialize the Mozilla theme drawing code.
- if (!mozGtkRefCount) {
- moz_gtk_init();
- moz_gtk_use_theme_parts(&m_themeParts);
- }
- ++mozGtkRefCount;
-
+ platformInit();
#if ENABLE(VIDEO)
initMediaColors();
initMediaButtons();
#endif
}
-RenderThemeGtk::~RenderThemeGtk()
-{
- --mozGtkRefCount;
-
- if (!mozGtkRefCount)
- moz_gtk_shutdown();
-
- gtk_widget_destroy(m_gtkWindow);
-}
-
-void RenderThemeGtk::getIndicatorMetrics(ControlPart part, int& indicatorSize, int& indicatorSpacing) const
-{
- ASSERT(part == CheckboxPart || part == RadioPart);
- if (part == CheckboxPart) {
- moz_gtk_checkbox_get_metrics(&indicatorSize, &indicatorSpacing);
- return;
- }
-
- // RadioPart
- moz_gtk_radio_get_metrics(&indicatorSize, &indicatorSpacing);
-}
-
static bool supportsFocus(ControlPart appearance)
{
switch (appearance) {
@@ -227,13 +177,13 @@ GtkTextDirection gtkTextDirection(TextDirection direction)
}
}
-GtkStateType RenderThemeGtk::gtkIconState(RenderObject* renderObject)
+static GtkStateType gtkIconState(RenderTheme* theme, RenderObject* renderObject)
{
- if (!isEnabled(renderObject))
+ if (!theme->isEnabled(renderObject))
return GTK_STATE_INSENSITIVE;
- if (isPressed(renderObject))
+ if (theme->isPressed(renderObject))
return GTK_STATE_ACTIVE;
- if (isHovered(renderObject))
+ if (theme->isHovered(renderObject))
return GTK_STATE_PRELIGHT;
return GTK_STATE_NORMAL;
@@ -318,7 +268,7 @@ bool RenderThemeGtk::paintSearchFieldResultsDecoration(RenderObject* renderObjec
{
GRefPtr<GdkPixbuf> icon = getStockIcon(GTK_TYPE_ENTRY, GTK_STOCK_FIND,
gtkTextDirection(renderObject->style()->direction()),
- gtkIconState(renderObject), GTK_ICON_SIZE_MENU);
+ gtkIconState(this, renderObject), GTK_ICON_SIZE_MENU);
paintGdkPixbuf(paintInfo.context, icon.get(), centerRectVerticallyInParentInputElement(renderObject, rect));
return false;
}
@@ -338,7 +288,7 @@ bool RenderThemeGtk::paintSearchFieldCancelButton(RenderObject* renderObject, co
{
GRefPtr<GdkPixbuf> icon = getStockIcon(GTK_TYPE_ENTRY, GTK_STOCK_CLEAR,
gtkTextDirection(renderObject->style()->direction()),
- gtkIconState(renderObject), GTK_ICON_SIZE_MENU);
+ gtkIconState(this, renderObject), GTK_ICON_SIZE_MENU);
paintGdkPixbuf(paintInfo.context, icon.get(), centerRectVerticallyInParentInputElement(renderObject, rect));
return false;
}
@@ -438,19 +388,16 @@ String RenderThemeGtk::extraMediaControlsStyleSheet()
void RenderThemeGtk::adjustMediaSliderThumbSize(RenderObject* renderObject) const
{
- ControlPart part = renderObject->style()->appearance();
-
- if (part == MediaSliderThumbPart) {
- renderObject->style()->setWidth(Length(m_mediaSliderThumbWidth, Fixed));
- renderObject->style()->setHeight(Length(m_mediaSliderThumbHeight, Fixed));
- }
+ ASSERT(renderObject->style()->appearance() == MediaSliderThumbPart);
+ renderObject->style()->setWidth(Length(m_mediaSliderThumbWidth, Fixed));
+ renderObject->style()->setHeight(Length(m_mediaSliderThumbHeight, Fixed));
}
bool RenderThemeGtk::paintMediaButton(RenderObject* renderObject, GraphicsContext* context, const IntRect& rect, const char* iconName)
{
GRefPtr<GdkPixbuf> icon = getStockIcon(GTK_TYPE_CONTAINER, iconName,
gtkTextDirection(renderObject->style()->direction()),
- gtkIconState(renderObject),
+ gtkIconState(this, renderObject),
getMediaButtonIconSize(m_mediaIconSize));
IntPoint iconPoint(rect.x() + (rect.width() - m_mediaIconSize) / 2,
rect.y() + (rect.height() - m_mediaIconSize) / 2);
@@ -560,6 +507,23 @@ bool RenderThemeGtk::paintMediaSliderThumb(RenderObject* o, const PaintInfo& pai
return false;
}
+bool RenderThemeGtk::paintMediaVolumeSliderContainer(RenderObject*, const PaintInfo& paintInfo, const IntRect& rect)
+{
+ GraphicsContext* context = paintInfo.context;
+ context->fillRect(FloatRect(rect), m_panelColor, ColorSpaceDeviceRGB);
+ return false;
+}
+
+bool RenderThemeGtk::paintMediaVolumeSliderTrack(RenderObject* renderObject, const PaintInfo& paintInfo, const IntRect& rect)
+{
+ return paintSliderTrack(renderObject, paintInfo, rect);
+}
+
+bool RenderThemeGtk::paintMediaVolumeSliderThumb(RenderObject* renderObject, const PaintInfo& paintInfo, const IntRect& rect)
+{
+ return paintSliderThumb(renderObject, paintInfo, rect);
+}
+
String RenderThemeGtk::formatMediaControlsCurrentTime(float currentTime, float duration) const
{
return formatMediaControlsTime(currentTime) + " / " + formatMediaControlsTime(duration);
@@ -575,20 +539,6 @@ bool RenderThemeGtk::paintMediaCurrentTime(RenderObject* renderObject, const Pai
#endif
#if ENABLE(PROGRESS_TAG)
-double RenderThemeGtk::animationRepeatIntervalForProgressBar(RenderProgress*) const
-{
- // FIXME: It doesn't look like there is a good way yet to support animated
- // progress bars with the Mozilla theme drawing code.
- return 0;
-}
-
-double RenderThemeGtk::animationDurationForProgressBar(RenderProgress*) const
-{
- // FIXME: It doesn't look like there is a good way yet to support animated
- // progress bars with the Mozilla theme drawing code.
- return 0;
-}
-
void RenderThemeGtk::adjustProgressBarStyle(CSSStyleSelector*, RenderStyle* style, Element*) const
{
style->setBoxShadow(0);
diff --git a/Source/WebCore/platform/gtk/RenderThemeGtk.h b/Source/WebCore/platform/gtk/RenderThemeGtk.h
index ef1df05..90113e5 100644
--- a/Source/WebCore/platform/gtk/RenderThemeGtk.h
+++ b/Source/WebCore/platform/gtk/RenderThemeGtk.h
@@ -29,9 +29,14 @@
#define RenderThemeGtk_h
#include "GRefPtr.h"
-#include "gtkdrawing.h"
#include "RenderTheme.h"
+#ifdef GTK_API_VERSION_2
+#include "gtkdrawing.h"
+#endif
+
+typedef gulong GType;
+
namespace WebCore {
class RenderThemeGtk : public RenderTheme {
@@ -86,10 +91,9 @@ public:
virtual String formatMediaControlsCurrentTime(float currentTime, float duration) const;
#endif
- void getIndicatorMetrics(ControlPart, int& indicatorSize, int& indicatorSpacing) const;
-
#ifdef GTK_API_VERSION_2
GtkWidget* gtkScrollbar();
+ static void getIndicatorMetrics(ControlPart, int& indicatorSize, int& indicatorSpacing);
#else
GtkStyleContext* gtkScrollbarStyle();
#endif
@@ -152,6 +156,9 @@ protected:
virtual bool paintMediaSeekForwardButton(RenderObject*, const PaintInfo&, const IntRect&);
virtual bool paintMediaSliderTrack(RenderObject*, const PaintInfo&, const IntRect&);
virtual bool paintMediaSliderThumb(RenderObject*, const PaintInfo&, const IntRect&);
+ virtual bool paintMediaVolumeSliderContainer(RenderObject*, const PaintInfo&, const IntRect&);
+ virtual bool paintMediaVolumeSliderTrack(RenderObject*, const PaintInfo&, const IntRect&);
+ virtual bool paintMediaVolumeSliderThumb(RenderObject*, const PaintInfo&, const IntRect&);
virtual bool paintMediaCurrentTime(RenderObject*, const PaintInfo&, const IntRect&);
#endif
@@ -163,45 +170,41 @@ protected:
#endif
private:
- GtkWidget* gtkButton() const;
- GtkWidget* gtkEntry() const;
- GtkWidget* gtkTreeView() const;
- GtkWidget* gtkVScale() const;
- GtkWidget* gtkHScale() const;
- GtkWidget* gtkContainer() const;
-
- void setupWidgetAndAddToContainer(GtkWidget*, GtkWidget*) const;
- GtkStateType getGtkStateType(RenderObject* object);
- bool paintRenderObject(GtkThemeWidgetType, RenderObject*, GraphicsContext*, const IntRect& rect, int flags = 0);
+ void platformInit();
#if ENABLE(VIDEO)
bool paintMediaButton(RenderObject*, GraphicsContext*, const IntRect&, const char* iconName);
#endif
- GtkStateType gtkIconState(RenderObject*);
static void setTextInputBorders(RenderStyle*);
GRefPtr<GdkPixbuf> getStockIcon(GType, const char* iconName, gint direction, gint state, gint iconSize);
- mutable GtkWidget* m_gtkWindow;
- mutable GtkWidget* m_gtkContainer;
- mutable GtkWidget* m_gtkButton;
- mutable GtkWidget* m_gtkEntry;
- mutable GtkWidget* m_gtkTreeView;
- mutable GtkWidget* m_gtkVScale;
- mutable GtkWidget* m_gtkHScale;
-
mutable Color m_panelColor;
mutable Color m_sliderColor;
mutable Color m_sliderThumbColor;
-
const int m_mediaIconSize;
const int m_mediaSliderHeight;
const int m_mediaSliderThumbWidth;
const int m_mediaSliderThumbHeight;
- GtkThemeParts m_themeParts;
#ifdef GTK_API_VERSION_2
+ void setupWidgetAndAddToContainer(GtkWidget*, GtkWidget*) const;
+ bool paintRenderObject(GtkThemeWidgetType, RenderObject*, GraphicsContext*, const IntRect&, int flags = 0);
+ GtkThemeParts m_themeParts;
+ GtkWidget* gtkButton() const;
+ GtkWidget* gtkEntry() const;
+ GtkWidget* gtkTreeView() const;
+ GtkWidget* gtkVScale() const;
+ GtkWidget* gtkHScale() const;
+ GtkWidget* gtkContainer() const;
+ mutable GtkWidget* m_gtkWindow;
+ mutable GtkWidget* m_gtkContainer;
+ mutable GtkWidget* m_gtkButton;
+ mutable GtkWidget* m_gtkEntry;
+ mutable GtkWidget* m_gtkTreeView;
+ mutable GtkWidget* m_gtkVScale;
+ mutable GtkWidget* m_gtkHScale;
bool m_themePartsHaveRGBAColormap;
-#endif
friend class WidgetRenderingContext;
+#endif
};
}
diff --git a/Source/WebCore/platform/gtk/RenderThemeGtk2.cpp b/Source/WebCore/platform/gtk/RenderThemeGtk2.cpp
index fd391b7..e01508e 100644
--- a/Source/WebCore/platform/gtk/RenderThemeGtk2.cpp
+++ b/Source/WebCore/platform/gtk/RenderThemeGtk2.cpp
@@ -32,6 +32,7 @@
#include "GtkVersioning.h"
#include "HTMLNames.h"
#include "MediaControlElements.h"
+#include "PaintInfo.h"
#include "RenderObject.h"
#include "TextDirection.h"
#include "UserAgentStyleSheets.h"
@@ -49,6 +50,45 @@ namespace WebCore {
// This is not a static method, because we want to avoid having GTK+ headers in RenderThemeGtk.h.
extern GtkTextDirection gtkTextDirection(TextDirection);
+static int mozGtkRefCount = 0;
+void RenderThemeGtk::platformInit()
+{
+ m_themePartsHaveRGBAColormap = true;
+ m_gtkWindow = 0;
+ m_gtkContainer = 0;
+ m_gtkButton = 0;
+ m_gtkEntry = 0;
+ m_gtkTreeView = 0;
+ m_gtkVScale = 0;
+ m_gtkHScale = 0;
+
+ memset(&m_themeParts, 0, sizeof(GtkThemeParts));
+ GdkColormap* colormap = gdk_screen_get_rgba_colormap(gdk_screen_get_default());
+ if (!colormap) {
+ m_themePartsHaveRGBAColormap = false;
+ colormap = gdk_screen_get_default_colormap(gdk_screen_get_default());
+ }
+ m_themeParts.colormap = colormap;
+
+ // Initialize the Mozilla theme drawing code.
+ if (!mozGtkRefCount) {
+ moz_gtk_init();
+ moz_gtk_use_theme_parts(&m_themeParts);
+ }
+ ++mozGtkRefCount;
+}
+
+RenderThemeGtk::~RenderThemeGtk()
+{
+ --mozGtkRefCount;
+
+ if (!mozGtkRefCount)
+ moz_gtk_shutdown();
+
+ if (m_gtkWindow)
+ gtk_widget_destroy(m_gtkWindow);
+}
+
#if ENABLE(VIDEO)
void RenderThemeGtk::initMediaColors()
{
@@ -63,13 +103,13 @@ void RenderThemeGtk::adjustRepaintRect(const RenderObject*, IntRect&)
{
}
-GtkStateType RenderThemeGtk::getGtkStateType(RenderObject* object)
+static GtkStateType getGtkStateType(RenderThemeGtk* theme, RenderObject* object)
{
- if (!isEnabled(object) || isReadOnlyControl(object))
+ if (!theme->isEnabled(object) || theme->isReadOnlyControl(object))
return GTK_STATE_INSENSITIVE;
- if (isPressed(object))
+ if (theme->isPressed(object))
return GTK_STATE_ACTIVE;
- if (isHovered(object))
+ if (theme->isHovered(object))
return GTK_STATE_PRELIGHT;
return GTK_STATE_NORMAL;
}
@@ -102,6 +142,18 @@ bool RenderThemeGtk::paintRenderObject(GtkThemeWidgetType type, RenderObject* re
gtkTextDirection(renderObject->style()->direction()));
}
+void RenderThemeGtk::getIndicatorMetrics(ControlPart part, int& indicatorSize, int& indicatorSpacing)
+{
+ ASSERT(part == CheckboxPart || part == RadioPart);
+ if (part == CheckboxPart) {
+ moz_gtk_checkbox_get_metrics(&indicatorSize, &indicatorSpacing);
+ return;
+ }
+
+ // RadioPart
+ moz_gtk_radio_get_metrics(&indicatorSize, &indicatorSpacing);
+}
+
static void setToggleSize(const RenderThemeGtk* theme, RenderStyle* style, ControlPart appearance)
{
// The width and height are both specified, so we shouldn't change them.
@@ -110,7 +162,7 @@ static void setToggleSize(const RenderThemeGtk* theme, RenderStyle* style, Contr
// FIXME: This is probably not correct use of indicatorSize and indicatorSpacing.
gint indicatorSize, indicatorSpacing;
- theme->getIndicatorMetrics(appearance, indicatorSize, indicatorSpacing);
+ RenderThemeGtk::getIndicatorMetrics(appearance, indicatorSize, indicatorSpacing);
// Other ports hard-code this to 13, but GTK+ users tend to demand the native look.
// It could be made a configuration option values other than 13 actually break site compatibility.
@@ -151,7 +203,7 @@ bool RenderThemeGtk::paintButton(RenderObject* object, const PaintInfo& info, co
IntRect buttonRect(IntPoint(), rect.size());
IntRect focusRect(buttonRect);
- GtkStateType state = getGtkStateType(object);
+ GtkStateType state = getGtkStateType(this, object);
gtk_widget_set_state(widget, state);
gtk_widget_set_direction(widget, gtkTextDirection(object->style()->direction()));
@@ -248,24 +300,24 @@ bool RenderThemeGtk::paintSliderTrack(RenderObject* object, const PaintInfo& inf
return false;
ControlPart part = object->style()->appearance();
- ASSERT(part == SliderHorizontalPart || part == SliderVerticalPart);
+ ASSERT(part == SliderHorizontalPart || part == SliderVerticalPart || part == MediaVolumeSliderPart);
// We shrink the trough rect slightly to make room for the focus indicator.
IntRect troughRect(IntPoint(), rect.size()); // This is relative to rect.
GtkWidget* widget = 0;
- if (part == SliderVerticalPart) {
- widget = gtkVScale();
- troughRect.inflateY(-gtk_widget_get_style(widget)->ythickness);
- } else {
+ if (part == SliderHorizontalPart) {
widget = gtkHScale();
troughRect.inflateX(-gtk_widget_get_style(widget)->xthickness);
+ } else {
+ widget = gtkVScale();
+ troughRect.inflateY(-gtk_widget_get_style(widget)->ythickness);
}
gtk_widget_set_direction(widget, gtkTextDirection(object->style()->direction()));
WidgetRenderingContext widgetContext(info.context, rect);
widgetContext.gtkPaintBox(troughRect, widget, GTK_STATE_ACTIVE, GTK_SHADOW_OUT, "trough");
if (isFocused(object))
- widgetContext.gtkPaintFocus(IntRect(IntPoint(), rect.size()), widget, getGtkStateType(object), "trough");
+ widgetContext.gtkPaintFocus(IntRect(IntPoint(), rect.size()), widget, getGtkStateType(this, object), "trough");
return false;
}
@@ -276,19 +328,19 @@ bool RenderThemeGtk::paintSliderThumb(RenderObject* object, const PaintInfo& inf
return false;
ControlPart part = object->style()->appearance();
- ASSERT(part == SliderThumbHorizontalPart || part == SliderThumbVerticalPart);
+ ASSERT(part == SliderThumbHorizontalPart || part == SliderThumbVerticalPart || part == MediaVolumeSliderThumbPart);
GtkWidget* widget = 0;
const char* detail = 0;
GtkOrientation orientation;
- if (part == SliderThumbVerticalPart) {
- widget = gtkVScale();
- detail = "vscale";
- orientation = GTK_ORIENTATION_VERTICAL;
- } else {
+ if (part == SliderThumbHorizontalPart) {
widget = gtkHScale();
detail = "hscale";
orientation = GTK_ORIENTATION_HORIZONTAL;
+ } else {
+ widget = gtkVScale();
+ detail = "vscale";
+ orientation = GTK_ORIENTATION_VERTICAL;
}
gtk_widget_set_direction(widget, gtkTextDirection(object->style()->direction()));
@@ -298,7 +350,7 @@ bool RenderThemeGtk::paintSliderThumb(RenderObject* object, const PaintInfo& inf
// on them.
IntRect thumbRect(IntPoint(), rect.size());
WidgetRenderingContext widgetContext(info.context, rect);
- widgetContext.gtkPaintSlider(thumbRect, widget, getGtkStateType(object), GTK_SHADOW_OUT, detail, orientation);
+ widgetContext.gtkPaintSlider(thumbRect, widget, getGtkStateType(this, object), GTK_SHADOW_OUT, detail, orientation);
return false;
}
@@ -306,7 +358,7 @@ void RenderThemeGtk::adjustSliderThumbSize(RenderObject* o) const
{
ControlPart part = o->style()->appearance();
#if ENABLE(VIDEO)
- if (part == MediaSliderThumbPart || part == MediaVolumeSliderThumbPart) {
+ if (part == MediaSliderThumbPart) {
adjustMediaSliderThumbSize(o);
return;
}
@@ -324,12 +376,26 @@ void RenderThemeGtk::adjustSliderThumbSize(RenderObject* o) const
o->style()->setHeight(Length(width, Fixed));
return;
}
- ASSERT(part == SliderThumbVerticalPart);
+ ASSERT(part == SliderThumbVerticalPart || part == MediaVolumeSliderThumbPart);
o->style()->setWidth(Length(width, Fixed));
o->style()->setHeight(Length(length, Fixed));
}
#if ENABLE(PROGRESS_TAG)
+double RenderThemeGtk::animationRepeatIntervalForProgressBar(RenderProgress*) const
+{
+ // FIXME: It doesn't look like there is a good way yet to support animated
+ // progress bars with the Mozilla theme drawing code.
+ return 0;
+}
+
+double RenderThemeGtk::animationDurationForProgressBar(RenderProgress*) const
+{
+ // FIXME: It doesn't look like there is a good way yet to support animated
+ // progress bars with the Mozilla theme drawing code.
+ return 0;
+}
+
bool RenderThemeGtk::paintProgressBar(RenderObject* renderObject, const PaintInfo& paintInfo, const IntRect& rect)
{
if (!renderObject->isProgress())
diff --git a/Source/WebCore/platform/gtk/RenderThemeGtk3.cpp b/Source/WebCore/platform/gtk/RenderThemeGtk3.cpp
index 663404d..212e29d 100644
--- a/Source/WebCore/platform/gtk/RenderThemeGtk3.cpp
+++ b/Source/WebCore/platform/gtk/RenderThemeGtk3.cpp
@@ -33,11 +33,11 @@
#include "HTMLNames.h"
#include "MediaControlElements.h"
#include "Page.h"
+#include "PaintInfo.h"
#include "RenderObject.h"
#include "TextDirection.h"
#include "UserAgentStyleSheets.h"
-#include "WidgetRenderingContext.h"
-#include "gtkdrawing.h"
+#include <cmath>
#include <gdk/gdk.h>
#include <gtk/gtk.h>
@@ -47,6 +47,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();
@@ -90,16 +93,36 @@ static GtkStyleContext* getStyleContext(GType widgetType)
return context.get();
}
+GtkStyleContext* RenderThemeGtk::gtkScrollbarStyle()
+{
+ return getStyleContext(GTK_TYPE_SCROLLBAR);
+}
+
// This is not a static method, because we want to avoid having GTK+ headers in RenderThemeGtk.h.
extern GtkTextDirection gtkTextDirection(TextDirection);
+void RenderThemeGtk::platformInit()
+{
+}
+
+RenderThemeGtk::~RenderThemeGtk()
+{
+}
+
+#if ENABLE(VIDEO)
void RenderThemeGtk::initMediaColors()
{
- GtkStyle* style = gtk_widget_get_style(GTK_WIDGET(gtkContainer()));
- m_panelColor = style->bg[GTK_STATE_NORMAL];
- m_sliderColor = style->bg[GTK_STATE_ACTIVE];
- m_sliderThumbColor = style->bg[GTK_STATE_SELECTED];
+ GdkRGBA color;
+ GtkStyleContext* containerContext = getStyleContext(GTK_TYPE_CONTAINER);
+
+ gtk_style_context_get_background_color(containerContext, GTK_STATE_FLAG_NORMAL, &color);
+ m_panelColor = color;
+ gtk_style_context_get_background_color(containerContext, GTK_STATE_FLAG_ACTIVE, &color);
+ m_sliderColor = color;
+ gtk_style_context_get_background_color(containerContext, GTK_STATE_FLAG_SELECTED, &color);
+ m_sliderThumbColor = color;
}
+#endif
static void adjustRectForFocus(GtkStyleContext* context, IntRect& rect)
{
@@ -113,119 +136,140 @@ static void adjustRectForFocus(GtkStyleContext* context, IntRect& rect)
void RenderThemeGtk::adjustRepaintRect(const RenderObject* renderObject, IntRect& rect)
{
GtkStyleContext* context = 0;
+ bool checkInteriorFocus = false;
ControlPart part = renderObject->style()->appearance();
switch (part) {
+ case CheckboxPart:
+ case RadioPart:
+ context = getStyleContext(part == CheckboxPart ? GTK_TYPE_CHECK_BUTTON : GTK_TYPE_RADIO_BUTTON);
+
+ gint indicatorSpacing;
+ gtk_style_context_get_style(context, "indicator-spacing", &indicatorSpacing, NULL);
+ rect.inflate(indicatorSpacing);
+
+ return;
case SliderVerticalPart:
case SliderHorizontalPart:
context = getStyleContext(part == SliderThumbHorizontalPart ? GTK_TYPE_HSCALE : GTK_TYPE_VSCALE);
break;
case ButtonPart:
+ case MenulistButtonPart:
+ case MenulistPart:
context = getStyleContext(GTK_TYPE_BUTTON);
-
- gboolean interiorFocus;
- gtk_style_context_get_style(context, "interior-focus", &interiorFocus, NULL);
- if (interiorFocus)
- return;
-
+ checkInteriorFocus = true;
+ break;
+ case TextFieldPart:
+ case TextAreaPart:
+ context = getStyleContext(GTK_TYPE_ENTRY);
+ checkInteriorFocus = true;
break;
default:
return;
}
ASSERT(context);
+ if (checkInteriorFocus) {
+ gboolean interiorFocus;
+ gtk_style_context_get_style(context, "interior-focus", &interiorFocus, NULL);
+ if (interiorFocus)
+ return;
+ }
adjustRectForFocus(context, rect);
}
-GtkStateType RenderThemeGtk::getGtkStateType(RenderObject* object)
+static void setToggleSize(GtkStyleContext* context, RenderStyle* style)
{
- if (!isEnabled(object) || isReadOnlyControl(object))
- return GTK_STATE_INSENSITIVE;
- if (isPressed(object))
- return GTK_STATE_ACTIVE;
- if (isHovered(object))
- return GTK_STATE_PRELIGHT;
- return GTK_STATE_NORMAL;
-}
-
-bool RenderThemeGtk::paintRenderObject(GtkThemeWidgetType type, RenderObject* renderObject, GraphicsContext* context, const IntRect& rect, int flags)
-{
- // Painting is disabled so just claim to have succeeded
- if (context->paintingDisabled())
- return false;
-
- GtkWidgetState widgetState;
- widgetState.active = isPressed(renderObject);
- widgetState.focused = isFocused(renderObject);
+ // The width and height are both specified, so we shouldn't change them.
+ if (!style->width().isIntrinsicOrAuto() && !style->height().isAuto())
+ return;
- // https://bugs.webkit.org/show_bug.cgi?id=18364
- // The Mozilla theme drawing code, only paints a button as pressed when it's pressed
- // while hovered. Until we move away from the Mozila code, work-around the issue by
- // forcing a pressed button into the hovered state. This ensures that buttons activated
- // via the keyboard have the proper rendering.
- widgetState.inHover = isHovered(renderObject) || (type == MOZ_GTK_BUTTON && isPressed(renderObject));
+ // Other ports hard-code this to 13 which is also the default value defined by GTK+.
+ // GTK+ users tend to demand the native look.
+ // It could be made a configuration option values other than 13 actually break site compatibility.
+ gint indicatorSize;
+ gtk_style_context_get_style(context, "indicator-size", &indicatorSize, NULL);
- // FIXME: Disabled does not always give the correct appearance for ReadOnly
- widgetState.disabled = !isEnabled(renderObject) || isReadOnlyControl(renderObject);
- widgetState.isDefault = false;
- widgetState.canDefault = false;
- widgetState.depressed = false;
+ if (style->width().isIntrinsicOrAuto())
+ style->setWidth(Length(indicatorSize, Fixed));
- WidgetRenderingContext widgetContext(context, rect);
- return !widgetContext.paintMozillaWidget(type, &widgetState, flags,
- gtkTextDirection(renderObject->style()->direction()));
+ if (style->height().isAuto())
+ style->setHeight(Length(indicatorSize, Fixed));
}
-static void setToggleSize(const RenderThemeGtk* theme, RenderStyle* style, ControlPart appearance)
+static void paintToggle(const RenderThemeGtk* theme, GType widgetType, RenderObject* renderObject, const PaintInfo& paintInfo, const IntRect& rect)
{
- // The width and height are both specified, so we shouldn't change them.
- if (!style->width().isIntrinsicOrAuto() && !style->height().isAuto())
- return;
+ GtkStyleContext* context = getStyleContext(widgetType);
+ gtk_style_context_save(context);
- // FIXME: This is probably not correct use of indicatorSize and indicatorSpacing.
- gint indicatorSize, indicatorSpacing;
- theme->getIndicatorMetrics(appearance, indicatorSize, indicatorSpacing);
+ gtk_style_context_set_direction(context, static_cast<GtkTextDirection>(gtkTextDirection(renderObject->style()->direction())));
+ gtk_style_context_add_class(context, widgetType == GTK_TYPE_CHECK_BUTTON ? GTK_STYLE_CLASS_CHECK : GTK_STYLE_CLASS_RADIO);
- // Other ports hard-code this to 13, but GTK+ users tend to demand the native look.
- // It could be made a configuration option values other than 13 actually break site compatibility.
- int length = indicatorSize + indicatorSpacing;
- if (style->width().isIntrinsicOrAuto())
- style->setWidth(Length(length, Fixed));
+ 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->isIndeterminate(renderObject))
+ flags |= GTK_STATE_FLAG_INCONSISTENT;
+ else if (theme->isChecked(renderObject))
+ flags |= GTK_STATE_FLAG_ACTIVE;
+ if (theme->isPressed(renderObject))
+ flags |= GTK_STATE_FLAG_SELECTED;
+ gtk_style_context_set_state(context, static_cast<GtkStateFlags>(flags));
- if (style->height().isAuto())
- style->setHeight(Length(length, Fixed));
+ if (widgetType == GTK_TYPE_CHECK_BUTTON)
+ gtk_render_check(context, paintInfo.context->platformContext(), rect.x(), rect.y(), rect.width(), rect.height());
+ else
+ gtk_render_option(context, paintInfo.context->platformContext(), rect.x(), rect.y(), rect.width(), rect.height());
+
+ if (theme->isFocused(renderObject)) {
+ IntRect indicatorRect(rect);
+ gint indicatorSpacing;
+ gtk_style_context_get_style(context, "indicator-spacing", &indicatorSpacing, NULL);
+ indicatorRect.inflate(indicatorSpacing);
+ gtk_render_focus(context, paintInfo.context->platformContext(), indicatorRect.x(), indicatorRect.y(),
+ indicatorRect.width(), indicatorRect.height());
+ }
+
+ gtk_style_context_restore(context);
}
void RenderThemeGtk::setCheckboxSize(RenderStyle* style) const
{
- setToggleSize(this, style, RadioPart);
+ setToggleSize(getStyleContext(GTK_TYPE_CHECK_BUTTON), style);
}
-bool RenderThemeGtk::paintCheckbox(RenderObject* object, const PaintInfo& info, const IntRect& rect)
+bool RenderThemeGtk::paintCheckbox(RenderObject* renderObject, const PaintInfo& paintInfo, const IntRect& rect)
{
- return paintRenderObject(MOZ_GTK_CHECKBUTTON, object, info.context, rect, isChecked(object));
+ paintToggle(this, GTK_TYPE_CHECK_BUTTON, renderObject, paintInfo, rect);
+ return false;
}
void RenderThemeGtk::setRadioSize(RenderStyle* style) const
{
- setToggleSize(this, style, RadioPart);
+ setToggleSize(getStyleContext(GTK_TYPE_RADIO_BUTTON), style);
}
-bool RenderThemeGtk::paintRadio(RenderObject* object, const PaintInfo& info, const IntRect& rect)
+bool RenderThemeGtk::paintRadio(RenderObject* renderObject, const PaintInfo& paintInfo, const IntRect& rect)
{
- return paintRenderObject(MOZ_GTK_RADIOBUTTON, object, info.context, rect, isChecked(object));
+ paintToggle(this, GTK_TYPE_RADIO_BUTTON, renderObject, paintInfo, rect);
+ 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 };
@@ -242,19 +286,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,
@@ -274,7 +309,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,
@@ -286,64 +321,283 @@ 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* object, const PaintInfo& info, const IntRect& rect)
+bool RenderThemeGtk::paintTextField(RenderObject* renderObject, const PaintInfo& paintInfo, const IntRect& rect)
{
- return paintRenderObject(MOZ_GTK_ENTRY, object, info.context, rect);
+ GtkStyleContext* context = getStyleContext(GTK_TYPE_ENTRY);
+ 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_ENTRY);
+
+ guint flags = 0;
+ if (!isEnabled(renderObject) || isReadOnlyControl(renderObject))
+ flags |= GTK_STATE_FLAG_INSENSITIVE;
+ else if (isFocused(renderObject))
+ flags |= GTK_STATE_FLAG_FOCUSED;
+ gtk_style_context_set_state(context, static_cast<GtkStateFlags>(flags));
+
+ gtk_render_background(context, paintInfo.context->platformContext(), rect.x(), rect.y(), rect.width(), rect.height());
+ gtk_render_frame(context, paintInfo.context->platformContext(), rect.x(), rect.y(), rect.width(), rect.height());
+
+ if (isFocused(renderObject) && isEnabled(renderObject)) {
+ gboolean interiorFocus;
+ gint focusWidth, focusPad;
+ gtk_style_context_get_style(context,
+ "interior-focus", &interiorFocus,
+ "focus-line-width", &focusWidth,
+ "focus-padding", &focusPad,
+ NULL);
+ if (!interiorFocus) {
+ IntRect focusRect(rect);
+ focusRect.inflate(focusWidth + focusPad);
+ gtk_render_focus(context, paintInfo.context->platformContext(),
+ focusRect.x(), focusRect.y(), focusRect.width(), focusRect.height());
+ }
+ }
+
+ gtk_style_context_restore(context);
+
+ return false;
}
bool RenderThemeGtk::paintSliderTrack(RenderObject* renderObject, const PaintInfo& paintInfo, const IntRect& rect)
{
ControlPart part = renderObject->style()->appearance();
- ASSERT(part == SliderHorizontalPart || part == SliderVerticalPart);
+ ASSERT(part == SliderHorizontalPart || part == SliderVerticalPart || part == MediaVolumeSliderPart);
GtkStyleContext* context = getStyleContext(part == SliderThumbHorizontalPart ? GTK_TYPE_HSCALE : GTK_TYPE_VSCALE);
gtk_style_context_save(context);
@@ -378,7 +632,7 @@ bool RenderThemeGtk::paintSliderTrack(RenderObject* renderObject, const PaintInf
bool RenderThemeGtk::paintSliderThumb(RenderObject* renderObject, const PaintInfo& paintInfo, const IntRect& rect)
{
ControlPart part = renderObject->style()->appearance();
- ASSERT(part == SliderThumbHorizontalPart || part == SliderThumbVerticalPart);
+ ASSERT(part == SliderThumbHorizontalPart || part == SliderThumbVerticalPart || part == MediaVolumeSliderThumbPart);
GtkStyleContext* context = getStyleContext(part == SliderThumbHorizontalPart ? GTK_TYPE_HSCALE : GTK_TYPE_VSCALE);
gtk_style_context_save(context);
@@ -414,7 +668,7 @@ void RenderThemeGtk::adjustSliderThumbSize(RenderObject* renderObject) const
{
ControlPart part = renderObject->style()->appearance();
#if ENABLE(VIDEO)
- if (part == MediaSliderThumbPart || part == MediaVolumeSliderThumbPart) {
+ if (part == MediaSliderThumbPart) {
adjustMediaSliderThumbSize(renderObject);
return;
}
@@ -430,37 +684,73 @@ void RenderThemeGtk::adjustSliderThumbSize(RenderObject* renderObject) const
renderObject->style()->setHeight(Length(sliderWidth, Fixed));
return;
}
- ASSERT(part == SliderThumbVerticalPart);
+ ASSERT(part == SliderThumbVerticalPart || part == MediaVolumeSliderThumbPart);
renderObject->style()->setWidth(Length(sliderWidth, Fixed));
renderObject->style()->setHeight(Length(sliderLength, Fixed));
}
#if ENABLE(PROGRESS_TAG)
+// These values have been copied from RenderThemeChromiumSkia.cpp
+static const int progressActivityBlocks = 5;
+static const int progressAnimationFrames = 10;
+static const double progressAnimationInterval = 0.125;
+double RenderThemeGtk::animationRepeatIntervalForProgressBar(RenderProgress*) const
+{
+ return progressAnimationInterval;
+}
+
+double RenderThemeGtk::animationDurationForProgressBar(RenderProgress*) const
+{
+ return progressAnimationInterval * progressAnimationFrames * 2; // "2" for back and forth;
+}
+
bool RenderThemeGtk::paintProgressBar(RenderObject* renderObject, const PaintInfo& paintInfo, const IntRect& rect)
{
if (!renderObject->isProgress())
return true;
- GtkWidget* progressBarWidget = moz_gtk_get_progress_widget();
- if (!progressBarWidget)
- return true;
+ GtkStyleContext* context = getStyleContext(GTK_TYPE_PROGRESS_BAR);
+ gtk_style_context_save(context);
- if (paintRenderObject(MOZ_GTK_PROGRESSBAR, renderObject, paintInfo.context, rect))
- return true;
+ gtk_style_context_add_class(context, GTK_STYLE_CLASS_TROUGH);
+
+ gtk_render_background(context, paintInfo.context->platformContext(), rect.x(), rect.y(), rect.width(), rect.height());
+ gtk_render_frame(context, paintInfo.context->platformContext(), rect.x(), rect.y(), rect.width(), rect.height());
+
+ gtk_style_context_restore(context);
+
+ gtk_style_context_save(context);
+ gtk_style_context_add_class(context, GTK_STYLE_CLASS_PROGRESSBAR);
- IntRect chunkRect(rect);
RenderProgress* renderProgress = toRenderProgress(renderObject);
- GtkStyle* style = gtk_widget_get_style(progressBarWidget);
- chunkRect.setHeight(chunkRect.height() - (2 * style->ythickness));
- chunkRect.setY(chunkRect.y() + style->ythickness);
- chunkRect.setWidth((chunkRect.width() - (2 * style->xthickness)) * renderProgress->position());
- if (renderObject->style()->direction() == RTL)
- chunkRect.setX(rect.x() + rect.width() - chunkRect.width() - style->xthickness);
- else
- chunkRect.setX(chunkRect.x() + style->xthickness);
+ GtkBorder padding;
+ gtk_style_context_get_padding(context, static_cast<GtkStateFlags>(0), &padding);
+ IntRect progressRect(rect.x() + padding.left, rect.y() + padding.top,
+ rect.width() - (padding.left + padding.right),
+ rect.height() - (padding.top + padding.bottom));
+
+ if (renderProgress->isDeterminate()) {
+ progressRect.setWidth(progressRect.width() * renderProgress->position());
+ if (renderObject->style()->direction() == RTL)
+ progressRect.setX(rect.x() + rect.width() - progressRect.width() - padding.right);
+ } else {
+ double animationProgress = renderProgress->animationProgress();
+
+ progressRect.setWidth(max(2, progressRect.width() / progressActivityBlocks));
+ int movableWidth = rect.width() - progressRect.width();
+ if (animationProgress < 0.5)
+ progressRect.setX(progressRect.x() + (animationProgress * 2 * movableWidth));
+ else
+ progressRect.setX(progressRect.x() + ((1.0 - animationProgress) * 2 * movableWidth));
+ }
+
+ if (!progressRect.isEmpty())
+ gtk_render_activity(context, paintInfo.context->platformContext(), progressRect.x(), progressRect.y(), progressRect.width(), progressRect.height());
+
+ gtk_style_context_restore(context);
- return paintRenderObject(MOZ_GTK_PROGRESS_CHUNK, renderObject, paintInfo.context, chunkRect);
+ return false;
}
#endif
@@ -558,86 +848,6 @@ Color RenderThemeGtk::systemColor(int cssValueId) const
}
}
-static void gtkStyleSetCallback(GtkWidget* widget, GtkStyle* previous, RenderTheme* renderTheme)
-{
- // FIXME: Make sure this function doesn't get called many times for a single GTK+ style change signal.
- renderTheme->platformColorsDidChange();
-}
-
-void RenderThemeGtk::setupWidgetAndAddToContainer(GtkWidget* widget, GtkWidget* window) const
-{
- gtk_container_add(GTK_CONTAINER(window), widget);
- gtk_widget_realize(widget);
- g_object_set_data(G_OBJECT(widget), "transparent-bg-hint", GINT_TO_POINTER(TRUE));
-
- // FIXME: Perhaps this should only be called for the containing window or parent container.
- g_signal_connect(widget, "style-set", G_CALLBACK(gtkStyleSetCallback), const_cast<RenderThemeGtk*>(this));
-}
-
-GtkWidget* RenderThemeGtk::gtkContainer() const
-{
- if (m_gtkContainer)
- return m_gtkContainer;
-
- m_gtkWindow = gtk_window_new(GTK_WINDOW_POPUP);
- gtk_widget_realize(m_gtkWindow);
- gtk_widget_set_name(m_gtkWindow, "MozillaGtkWidget");
-
- m_gtkContainer = gtk_fixed_new();
- setupWidgetAndAddToContainer(m_gtkContainer, m_gtkWindow);
- return m_gtkContainer;
-}
-
-GtkWidget* RenderThemeGtk::gtkButton() const
-{
- if (m_gtkButton)
- return m_gtkButton;
- m_gtkButton = gtk_button_new();
- setupWidgetAndAddToContainer(m_gtkButton, gtkContainer());
- return m_gtkButton;
-}
-
-GtkWidget* RenderThemeGtk::gtkEntry() const
-{
- if (m_gtkEntry)
- return m_gtkEntry;
- m_gtkEntry = gtk_entry_new();
- setupWidgetAndAddToContainer(m_gtkEntry, gtkContainer());
- return m_gtkEntry;
-}
-
-GtkWidget* RenderThemeGtk::gtkTreeView() const
-{
- if (m_gtkTreeView)
- return m_gtkTreeView;
- m_gtkTreeView = gtk_tree_view_new();
- setupWidgetAndAddToContainer(m_gtkTreeView, gtkContainer());
- return m_gtkTreeView;
-}
-
-GtkWidget* RenderThemeGtk::gtkVScale() const
-{
- if (m_gtkVScale)
- return m_gtkVScale;
- m_gtkVScale = gtk_vscale_new(0);
- setupWidgetAndAddToContainer(m_gtkVScale, gtkContainer());
- return m_gtkVScale;
-}
-
-GtkWidget* RenderThemeGtk::gtkHScale() const
-{
- if (m_gtkHScale)
- return m_gtkHScale;
- m_gtkHScale = gtk_hscale_new(0);
- setupWidgetAndAddToContainer(m_gtkHScale, gtkContainer());
- return m_gtkHScale;
-}
-
-GtkStyleContext* RenderThemeGtk::gtkScrollbarStyle()
-{
- return getStyleContext(GTK_TYPE_SCROLLBAR);
-}
-
} // namespace WebCore
#endif // !GTK_API_VERSION_2
diff --git a/Source/WebCore/platform/gtk/WidgetRenderingContextGtk2.cpp b/Source/WebCore/platform/gtk/WidgetRenderingContext.cpp
index e85c570..6d1be31 100644
--- a/Source/WebCore/platform/gtk/WidgetRenderingContextGtk2.cpp
+++ b/Source/WebCore/platform/gtk/WidgetRenderingContext.cpp
@@ -32,6 +32,7 @@
#include "WidgetRenderingContext.h"
#include "GraphicsContext.h"
+#include "GtkVersioning.h"
#include "RefPtrCairo.h"
#include "RenderThemeGtk.h"
#include "Timer.h"
@@ -107,7 +108,7 @@ WidgetRenderingContext::WidgetRenderingContext(GraphicsContext* graphicsContext,
int scratchWidth = 0;
int scratchHeight = 0;
if (gScratchBuffer)
- gdk_drawable_get_size(gScratchBuffer, &scratchWidth, &scratchHeight);
+ gdk_pixmap_get_size(gScratchBuffer, &scratchWidth, &scratchHeight);
// We do not need to recreate the buffer if the current buffer is large enough.
if (!gScratchBuffer || scratchWidth < width || scratchHeight < height) {
diff --git a/Source/WebCore/platform/gtk/WidgetRenderingContext.h b/Source/WebCore/platform/gtk/WidgetRenderingContext.h
index 7334656..8b2a0e2 100644
--- a/Source/WebCore/platform/gtk/WidgetRenderingContext.h
+++ b/Source/WebCore/platform/gtk/WidgetRenderingContext.h
@@ -22,6 +22,8 @@
#ifndef WidgetRenderingContext_h
#define WidgetRenderingContext_h
+#ifdef GTK_API_VERSION_2
+
#include "IntRect.h"
#include "gtkdrawing.h"
@@ -46,15 +48,11 @@ private:
GdkRectangle m_paintRect;
IntSize m_extraSpace;
bool m_hadError;
-
-#ifdef GTK_API_VERSION_2
GdkDrawable* m_target;
-#else
- cairo_t* m_target;
-#endif
};
}
-#endif
+#endif // GTK_API_VERSION_2
+#endif // WidgetRenderingContext_h
diff --git a/Source/WebCore/platform/gtk/WidgetRenderingContextGtk3.cpp b/Source/WebCore/platform/gtk/WidgetRenderingContextGtk3.cpp
deleted file mode 100644
index 69c4af5..0000000
--- a/Source/WebCore/platform/gtk/WidgetRenderingContextGtk3.cpp
+++ /dev/null
@@ -1,73 +0,0 @@
-/*
- * Copyright (C) 2010 Igalia S.L.
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Library General Public
- * License as published by the Free Software Foundation; either
- * version 2 of the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Library General Public License for more details.
- *
- * You should have received a copy of the GNU Library General Public License
- * along with this library; see the file COPYING.LIB. If not, write to
- * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
- * Boston, MA 02110-1301, USA.
- *
- */
-
-#include "config.h"
-#include "WidgetRenderingContext.h"
-
-#include "GraphicsContext.h"
-#include "IntRect.h"
-
-#ifndef GTK_API_VERSION_2
-
-namespace WebCore {
-
-WidgetRenderingContext::WidgetRenderingContext(GraphicsContext* context, const IntRect& targetRect)
- : m_graphicsContext(context)
- , m_targetRect(targetRect)
- , m_paintRect(targetRect)
- , m_hadError(false)
- , m_target(context->platformContext())
-{
-}
-
-WidgetRenderingContext::~WidgetRenderingContext()
-{
-}
-
-bool WidgetRenderingContext::paintMozillaWidget(GtkThemeWidgetType type, GtkWidgetState* state, int flags, GtkTextDirection textDirection)
-{
- m_hadError = moz_gtk_widget_paint(type, m_target, &m_paintRect, state, flags, textDirection) != MOZ_GTK_SUCCESS;
- return !m_hadError;
-}
-
-void WidgetRenderingContext::gtkPaintBox(const IntRect& rect, GtkWidget* widget, GtkStateType stateType, GtkShadowType shadowType, const gchar* detail)
-{
- GdkRectangle paintRect = { m_paintRect.x + rect.x(), m_paintRect.y + rect.y(), rect.width(), rect.height() };
- gtk_paint_box(gtk_widget_get_style(widget), m_target, stateType, shadowType, widget,
- detail, paintRect.x, paintRect.y, paintRect.width, paintRect.height);
-}
-
-void WidgetRenderingContext::gtkPaintFocus(const IntRect& rect, GtkWidget* widget, GtkStateType stateType, const gchar* detail)
-{
- GdkRectangle paintRect = { m_paintRect.x + rect.x(), m_paintRect.y + rect.y(), rect.width(), rect.height() };
- gtk_paint_focus(gtk_widget_get_style(widget), m_target, stateType, widget,
- detail, paintRect.x, paintRect.y, paintRect.width, paintRect.height);
-}
-
-void WidgetRenderingContext::gtkPaintSlider(const IntRect& rect, GtkWidget* widget, GtkStateType stateType, GtkShadowType shadowType, const gchar* detail, GtkOrientation orientation)
-{
- GdkRectangle paintRect = { m_paintRect.x + rect.x(), m_paintRect.y + rect.y(), rect.width(), rect.height() };
- gtk_paint_slider(gtk_widget_get_style(widget), m_target, stateType, shadowType, widget,
- detail, paintRect.x, paintRect.y, paintRect.width, paintRect.height, orientation);
-}
-
-}
-
-#endif // !GTK_API_VERSION_2
diff --git a/Source/WebCore/platform/gtk/gtk3drawing.c b/Source/WebCore/platform/gtk/gtk3drawing.c
deleted file mode 100644
index d3bdd56..0000000
--- a/Source/WebCore/platform/gtk/gtk3drawing.c
+++ /dev/null
@@ -1,1288 +0,0 @@
-/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
-/* ***** BEGIN LICENSE BLOCK *****
- * Version: MPL 1.1/GPL 2.0/LGPL 2.1
- *
- * The contents of this file are subject to the Mozilla Public License Version
- * 1.1 (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- * http://www.mozilla.org/MPL/
- *
- * Software distributed under the License is distributed on an "AS IS" basis,
- * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
- * for the specific language governing rights and limitations under the
- * License.
- *
- * The Original Code is mozilla.org code.
- *
- * The Initial Developer of the Original Code is
- * Netscape Communications Corporation.
- * Portions created by the Initial Developer are Copyright (C) 2002
- * the Initial Developer. All Rights Reserved.
- *
- * Contributor(s):
- * Brian Ryner <bryner@brianryner.com> (Original Author)
- * Pierre Chanial <p_ch@verizon.net>
- * Michael Ventnor <m.ventnor@gmail.com>
- * Alp Toker <alp@nuanti.com>
- *
- * Alternatively, the contents of this file may be used under the terms of
- * either the GNU General Public License Version 2 or later (the "GPL"), or
- * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
- * in which case the provisions of the GPL or the LGPL are applicable instead
- * of those above. If you wish to allow use of your version of this file only
- * under the terms of either the GPL or the LGPL, and not to allow others to
- * use your version of this file under the terms of the MPL, indicate your
- * decision by deleting the provisions above and replace them with the notice
- * and other provisions required by the GPL or the LGPL. If you do not delete
- * the provisions above, a recipient may use your version of this file under
- * the terms of any one of the MPL, the GPL or the LGPL.
- *
- * ***** END LICENSE BLOCK ***** */
-
-/*
- * This file contains painting functions for each of the gtk2 widgets.
- * Adapted from the gtkdrawing.c, and gtk+2.0 source.
- */
-
-#ifndef GTK_API_VERSION_2
-
-#include <gdk/gdkprivate.h>
-#include "gtkdrawing.h"
-#include "GtkVersioning.h"
-#include <math.h>
-#include <string.h>
-
-#define XTHICKNESS(style) (style->xthickness)
-#define YTHICKNESS(style) (style->ythickness)
-
-static GtkThemeParts *gParts = NULL;
-static style_prop_t style_prop_func;
-static gboolean have_arrow_scaling;
-static gboolean is_initialized;
-
-void
-moz_gtk_use_theme_parts(GtkThemeParts* parts)
-{
- gParts = parts;
-}
-
-/* Because we have such an unconventional way of drawing widgets, signal to the GTK theme engine
- that they are drawing for Mozilla instead of a conventional GTK app so they can do any specific
- things they may want to do. */
-static void
-moz_gtk_set_widget_name(GtkWidget* widget)
-{
- gtk_widget_set_name(widget, "MozillaGtkWidget");
-}
-
-gint
-moz_gtk_enable_style_props(style_prop_t styleGetProp)
-{
- style_prop_func = styleGetProp;
- return MOZ_GTK_SUCCESS;
-}
-
-static gint
-ensure_window_widget()
-{
- if (!gParts->protoWindow) {
- gParts->protoWindow = gtk_window_new(GTK_WINDOW_POPUP);
- gtk_widget_realize(gParts->protoWindow);
- moz_gtk_set_widget_name(gParts->protoWindow);
- }
- return MOZ_GTK_SUCCESS;
-}
-
-static gint
-setup_widget_prototype(GtkWidget* widget)
-{
- ensure_window_widget();
- if (!gParts->protoLayout) {
- gParts->protoLayout = gtk_fixed_new();
- gtk_container_add(GTK_CONTAINER(gParts->protoWindow), gParts->protoLayout);
- }
-
- gtk_container_add(GTK_CONTAINER(gParts->protoLayout), widget);
- gtk_widget_realize(widget);
- g_object_set_data(G_OBJECT(widget), "transparent-bg-hint", GINT_TO_POINTER(TRUE));
- return MOZ_GTK_SUCCESS;
-}
-
-static gint
-ensure_button_widget()
-{
- if (!gParts->buttonWidget) {
- gParts->buttonWidget = gtk_button_new_with_label("M");
- setup_widget_prototype(gParts->buttonWidget);
- }
- return MOZ_GTK_SUCCESS;
-}
-
-static gint
-ensure_toggle_button_widget()
-{
- if (!gParts->toggleButtonWidget) {
- gParts->toggleButtonWidget = gtk_toggle_button_new();
- setup_widget_prototype(gParts->toggleButtonWidget);
- /* toggle button must be set active to get the right style on hover. */
- gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(gParts->toggleButtonWidget), TRUE);
- }
- return MOZ_GTK_SUCCESS;
-}
-
-static gint
-ensure_button_arrow_widget()
-{
- if (!gParts->buttonArrowWidget) {
- ensure_toggle_button_widget();
-
- gParts->buttonArrowWidget = gtk_arrow_new(GTK_ARROW_DOWN, GTK_SHADOW_OUT);
- gtk_container_add(GTK_CONTAINER(gParts->toggleButtonWidget), gParts->buttonArrowWidget);
- gtk_widget_realize(gParts->buttonArrowWidget);
- }
- return MOZ_GTK_SUCCESS;
-}
-
-static gint
-ensure_checkbox_widget()
-{
- if (!gParts->checkboxWidget) {
- gParts->checkboxWidget = gtk_check_button_new_with_label("M");
- setup_widget_prototype(gParts->checkboxWidget);
- }
- return MOZ_GTK_SUCCESS;
-}
-
-static gint
-ensure_radiobutton_widget()
-{
- if (!gParts->radiobuttonWidget) {
- gParts->radiobuttonWidget = gtk_radio_button_new_with_label(NULL, "M");
- setup_widget_prototype(gParts->radiobuttonWidget);
- }
- return MOZ_GTK_SUCCESS;
-}
-
-static gint
-ensure_scrollbar_widget()
-{
- if (!gParts->vertScrollbarWidget) {
- gParts->vertScrollbarWidget = gtk_vscrollbar_new(NULL);
- setup_widget_prototype(gParts->vertScrollbarWidget);
- }
- if (!gParts->horizScrollbarWidget) {
- gParts->horizScrollbarWidget = gtk_hscrollbar_new(NULL);
- setup_widget_prototype(gParts->horizScrollbarWidget);
- }
- return MOZ_GTK_SUCCESS;
-}
-
-static gint
-ensure_entry_widget()
-{
- if (!gParts->entryWidget) {
- gParts->entryWidget = gtk_entry_new();
- setup_widget_prototype(gParts->entryWidget);
- }
- return MOZ_GTK_SUCCESS;
-}
-
-/* We need to have pointers to the inner widgets (button, separator, arrow)
- * of the ComboBox to get the correct rendering from theme engines which
- * special cases their look. Since the inner layout can change, we ask GTK
- * to NULL our pointers when they are about to become invalid because the
- * corresponding widgets don't exist anymore. It's the role of
- * g_object_add_weak_pointer().
- * Note that if we don't find the inner widgets (which shouldn't happen), we
- * fallback to use generic "non-inner" widgets, and they don't need that kind
- * of weak pointer since they are explicit children of gParts->protoWindow and as
- * such GTK holds a strong reference to them. */
-static void
-moz_gtk_get_combo_box_inner_button(GtkWidget *widget, gpointer client_data)
-{
- if (GTK_IS_TOGGLE_BUTTON(widget)) {
- gParts->comboBoxButtonWidget = widget;
- g_object_add_weak_pointer(G_OBJECT(widget),
- (gpointer) &gParts->comboBoxButtonWidget);
- gtk_widget_realize(widget);
- g_object_set_data(G_OBJECT(widget), "transparent-bg-hint", GINT_TO_POINTER(TRUE));
- }
-}
-
-static void
-moz_gtk_get_combo_box_button_inner_widgets(GtkWidget *widget,
- gpointer client_data)
-{
- if (GTK_IS_SEPARATOR(widget)) {
- gParts->comboBoxSeparatorWidget = widget;
- g_object_add_weak_pointer(G_OBJECT(widget),
- (gpointer) &gParts->comboBoxSeparatorWidget);
- } else if (GTK_IS_ARROW(widget)) {
- gParts->comboBoxArrowWidget = widget;
- g_object_add_weak_pointer(G_OBJECT(widget),
- (gpointer) &gParts->comboBoxArrowWidget);
- } else
- return;
- gtk_widget_realize(widget);
- g_object_set_data(G_OBJECT(widget), "transparent-bg-hint", GINT_TO_POINTER(TRUE));
-}
-
-static gint
-ensure_combo_box_widgets()
-{
- GtkWidget* buttonChild;
-
- if (gParts->comboBoxButtonWidget && gParts->comboBoxArrowWidget)
- return MOZ_GTK_SUCCESS;
-
- /* Create a ComboBox if needed */
- if (!gParts->comboBoxWidget) {
- gParts->comboBoxWidget = gtk_combo_box_new();
- setup_widget_prototype(gParts->comboBoxWidget);
- }
-
- /* Get its inner Button */
- gtk_container_forall(GTK_CONTAINER(gParts->comboBoxWidget),
- moz_gtk_get_combo_box_inner_button,
- NULL);
-
- if (gParts->comboBoxButtonWidget) {
- /* Get the widgets inside the Button */
- buttonChild = gtk_bin_get_child(GTK_BIN(gParts->comboBoxButtonWidget));
- if (GTK_IS_HBOX(buttonChild)) {
- /* appears-as-list = FALSE, cell-view = TRUE; the button
- * contains an hbox. This hbox is there because the ComboBox
- * needs to place a cell renderer, a separator, and an arrow in
- * the button when appears-as-list is FALSE. */
- gtk_container_forall(GTK_CONTAINER(buttonChild),
- moz_gtk_get_combo_box_button_inner_widgets,
- NULL);
- } else if(GTK_IS_ARROW(buttonChild)) {
- /* appears-as-list = TRUE, or cell-view = FALSE;
- * the button only contains an arrow */
- gParts->comboBoxArrowWidget = buttonChild;
- g_object_add_weak_pointer(G_OBJECT(buttonChild), (gpointer)
- &gParts->comboBoxArrowWidget);
- gtk_widget_realize(gParts->comboBoxArrowWidget);
- g_object_set_data(G_OBJECT(gParts->comboBoxArrowWidget),
- "transparent-bg-hint", GINT_TO_POINTER(TRUE));
- }
- } else {
- /* Shouldn't be reached with current internal gtk implementation; we
- * use a generic toggle button as last resort fallback to avoid
- * crashing. */
- ensure_toggle_button_widget();
- gParts->comboBoxButtonWidget = gParts->toggleButtonWidget;
- }
-
- if (!gParts->comboBoxArrowWidget) {
- /* Shouldn't be reached with current internal gtk implementation;
- * we gParts->buttonArrowWidget as last resort fallback to avoid
- * crashing. */
- ensure_button_arrow_widget();
- gParts->comboBoxArrowWidget = gParts->buttonArrowWidget;
- }
-
- /* We don't test the validity of gParts->comboBoxSeparatorWidget since there
- * is none when "appears-as-list" = TRUE or "cell-view" = FALSE; if it
- * is invalid we just won't paint it. */
-
- return MOZ_GTK_SUCCESS;
-}
-
-static gint
-ensure_progress_widget()
-{
- if (!gParts->progresWidget) {
- gParts->progresWidget = gtk_progress_bar_new();
- setup_widget_prototype(gParts->progresWidget);
- }
- return MOZ_GTK_SUCCESS;
-}
-
-static gint
-ensure_scrolled_window_widget()
-{
- if (!gParts->scrolledWindowWidget) {
- gParts->scrolledWindowWidget = gtk_scrolled_window_new(NULL, NULL);
- setup_widget_prototype(gParts->scrolledWindowWidget);
- }
- return MOZ_GTK_SUCCESS;
-}
-
-static GtkStateType
-ConvertGtkState(GtkWidgetState* state)
-{
- if (state->disabled)
- return GTK_STATE_INSENSITIVE;
- else if (state->depressed)
- return (state->inHover ? GTK_STATE_PRELIGHT : GTK_STATE_ACTIVE);
- else if (state->inHover)
- return (state->active ? GTK_STATE_ACTIVE : GTK_STATE_PRELIGHT);
- else
- return GTK_STATE_NORMAL;
-}
-
-static gint
-moz_gtk_button_paint(cairo_t* cr, GdkRectangle* rect,
- GtkWidgetState* state, GtkReliefStyle relief,
- GtkWidget* widget, GtkTextDirection direction)
-{
- GtkShadowType shadow_type;
- GtkStyle* style = gtk_widget_get_style(widget);
- GtkStateType button_state = ConvertGtkState(state);
- gint x = rect->x, y=rect->y, width=rect->width, height=rect->height;
- GdkWindow* window = gtk_widget_get_window(widget);
-
- gboolean interior_focus;
- gint focus_width, focus_pad;
-
- moz_gtk_widget_get_focus(widget, &interior_focus, &focus_width, &focus_pad);
-
- if (window && gdk_window_is_visible(window)) {
- gdk_window_set_background_pattern(window, NULL);
- }
-
- gtk_widget_set_state(widget, button_state);
- gtk_widget_set_direction(widget, direction);
- gtk_button_set_relief(GTK_BUTTON(widget), relief);
-
- if (!interior_focus && state->focused) {
- x += focus_width + focus_pad;
- y += focus_width + focus_pad;
- width -= 2 * (focus_width + focus_pad);
- height -= 2 * (focus_width + focus_pad);
- }
-
- shadow_type = button_state == GTK_STATE_ACTIVE ||
- state->depressed ? GTK_SHADOW_IN : GTK_SHADOW_OUT;
-
- if (state->isDefault && relief == GTK_RELIEF_NORMAL) {
- gtk_paint_box(style, cr, button_state, shadow_type,
- widget, "buttondefault", x, y, width, height);
- }
-
- if (relief != GTK_RELIEF_NONE || state->depressed ||
- (button_state != GTK_STATE_NORMAL &&
- button_state != GTK_STATE_INSENSITIVE)) {
- /* the following line can trigger an assertion (Crux theme)
- file ../../gdk/gdkwindow.c: line 1846 (gdk_window_clear_area):
- assertion `GDK_IS_WINDOW (window)' failed */
- gtk_paint_box(style, cr, button_state, shadow_type,
- widget, "button", x, y, width, height);
- }
-
- if (state->focused) {
- if (interior_focus) {
- GtkStyle* style = gtk_widget_get_style(widget);
- x += style->xthickness + focus_pad;
- y += style->ythickness + focus_pad;
- width -= 2 * (style->xthickness + focus_pad);
- height -= 2 * (style->ythickness + focus_pad);
- } else {
- x -= focus_width + focus_pad;
- y -= focus_width + focus_pad;
- width += 2 * (focus_width + focus_pad);
- height += 2 * (focus_width + focus_pad);
- }
-
- gtk_paint_focus(style, cr, button_state,
- widget, "button", x, y, width, height);
- }
-
- return MOZ_GTK_SUCCESS;
-}
-
-gint
-moz_gtk_init()
-{
- GtkWidgetClass *entry_class;
-
- is_initialized = TRUE;
- have_arrow_scaling = (gtk_major_version > 2 ||
- (gtk_major_version == 2 && gtk_minor_version >= 12));
-
- /* Add style property to GtkEntry.
- * Adding the style property to the normal GtkEntry class means that it
- * will work without issues inside GtkComboBox and for Spinbuttons. */
- entry_class = g_type_class_ref(GTK_TYPE_ENTRY);
- gtk_widget_class_install_style_property(entry_class,
- g_param_spec_boolean("honors-transparent-bg-hint",
- "Transparent BG enabling flag",
- "If TRUE, the theme is able to draw the GtkEntry on non-prefilled background.",
- FALSE,
- G_PARAM_READWRITE));
-
- return MOZ_GTK_SUCCESS;
-}
-
-gint
-moz_gtk_checkbox_get_metrics(gint* indicator_size, gint* indicator_spacing)
-{
- ensure_checkbox_widget();
-
- gtk_widget_style_get (gParts->checkboxWidget,
- "indicator_size", indicator_size,
- "indicator_spacing", indicator_spacing,
- NULL);
-
- return MOZ_GTK_SUCCESS;
-}
-
-gint
-moz_gtk_radio_get_metrics(gint* indicator_size, gint* indicator_spacing)
-{
- ensure_radiobutton_widget();
-
- gtk_widget_style_get (gParts->radiobuttonWidget,
- "indicator_size", indicator_size,
- "indicator_spacing", indicator_spacing,
- NULL);
-
- return MOZ_GTK_SUCCESS;
-}
-
-gint
-moz_gtk_widget_get_focus(GtkWidget* widget, gboolean* interior_focus,
- gint* focus_width, gint* focus_pad)
-{
- gtk_widget_style_get (widget,
- "interior-focus", interior_focus,
- "focus-line-width", focus_width,
- "focus-padding", focus_pad,
- NULL);
-
- return MOZ_GTK_SUCCESS;
-}
-
-gint
-moz_gtk_button_get_inner_border(GtkWidget* widget, GtkBorder* inner_border)
-{
- static const GtkBorder default_inner_border = { 1, 1, 1, 1 };
- GtkBorder *tmp_border;
-
- gtk_widget_style_get (widget, "inner-border", &tmp_border, NULL);
-
- if (tmp_border) {
- *inner_border = *tmp_border;
- gtk_border_free(tmp_border);
- }
- else
- *inner_border = default_inner_border;
-
- return MOZ_GTK_SUCCESS;
-}
-
-static gint
-moz_gtk_toggle_paint(cairo_t* cr, GdkRectangle* rect,
- GtkWidgetState* state, gboolean selected,
- gboolean inconsistent, gboolean isradio,
- GtkTextDirection direction)
-{
- GtkStateType state_type = ConvertGtkState(state);
- GtkShadowType shadow_type = (selected)?GTK_SHADOW_IN:GTK_SHADOW_OUT;
- gint indicator_size, indicator_spacing;
- gint x, y, width, height;
- gint focus_x, focus_y, focus_width, focus_height;
- GtkWidget *w;
- GtkStyle *style;
-
- if (isradio) {
- moz_gtk_radio_get_metrics(&indicator_size, &indicator_spacing);
- w = gParts->radiobuttonWidget;
- } else {
- moz_gtk_checkbox_get_metrics(&indicator_size, &indicator_spacing);
- w = gParts->checkboxWidget;
- }
-
- // "GetMinimumWidgetSize was ignored"
- // FIXME: This assert causes a build failure in WebKitGTK+ debug
- // builds, because it uses 'false' in its definition. We may want
- // to force this file to be built with g++, by renaming it.
- // ASSERT(rect->width == indicator_size);
-
- /*
- * vertically center in the box, since XUL sometimes ignores our
- * GetMinimumWidgetSize in the vertical dimension
- */
- x = rect->x;
- y = rect->y + (rect->height - indicator_size) / 2;
- width = indicator_size;
- height = indicator_size;
-
- focus_x = x - indicator_spacing;
- focus_y = y - indicator_spacing;
- focus_width = width + 2 * indicator_spacing;
- focus_height = height + 2 * indicator_spacing;
-
- style = gtk_widget_get_style(w);
-
- gtk_widget_set_sensitive(w, !state->disabled);
- gtk_widget_set_direction(w, direction);
- gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(w), selected);
-
- if (isradio) {
- gtk_paint_option(style, cr, state_type, shadow_type,
- gParts->radiobuttonWidget, "radiobutton", x, y,
- width, height);
- if (state->focused) {
- gtk_paint_focus(style, cr, GTK_STATE_ACTIVE,
- gParts->radiobuttonWidget, "radiobutton", focus_x, focus_y,
- focus_width, focus_height);
- }
- }
- else {
- /*
- * 'indeterminate' type on checkboxes. In GTK, the shadow type
- * must also be changed for the state to be drawn.
- */
- if (inconsistent) {
- gtk_toggle_button_set_inconsistent(GTK_TOGGLE_BUTTON(gParts->checkboxWidget), TRUE);
- shadow_type = GTK_SHADOW_ETCHED_IN;
- } else {
- gtk_toggle_button_set_inconsistent(GTK_TOGGLE_BUTTON(gParts->checkboxWidget), FALSE);
- }
-
- gtk_paint_check(style, cr, state_type, shadow_type,
- gParts->checkboxWidget, "checkbutton", x, y, width, height);
- if (state->focused) {
- gtk_paint_focus(style, cr, GTK_STATE_ACTIVE,
- gParts->checkboxWidget, "checkbutton", focus_x, focus_y,
- focus_width, focus_height);
- }
- }
-
- return MOZ_GTK_SUCCESS;
-}
-
-static gint
-calculate_button_inner_rect(GtkWidget* button, GdkRectangle* rect,
- GdkRectangle* inner_rect,
- GtkTextDirection direction,
- gboolean ignore_focus)
-{
- GtkBorder inner_border;
- gboolean interior_focus;
- gint focus_width, focus_pad;
- GtkStyle* style;
-
- style = gtk_widget_get_style(button);
-
- /* This mirrors gtkbutton's child positioning */
- moz_gtk_button_get_inner_border(button, &inner_border);
- moz_gtk_widget_get_focus(button, &interior_focus,
- &focus_width, &focus_pad);
-
- if (ignore_focus)
- focus_width = focus_pad = 0;
-
- inner_rect->x = rect->x + XTHICKNESS(style) + focus_width + focus_pad;
- inner_rect->x += direction == GTK_TEXT_DIR_LTR ?
- inner_border.left : inner_border.right;
- inner_rect->y = rect->y + inner_border.top + YTHICKNESS(style) +
- focus_width + focus_pad;
- inner_rect->width = MAX(1, rect->width - inner_border.left -
- inner_border.right - (XTHICKNESS(style) + focus_pad + focus_width) * 2);
- inner_rect->height = MAX(1, rect->height - inner_border.top -
- inner_border.bottom - (YTHICKNESS(style) + focus_pad + focus_width) * 2);
-
- return MOZ_GTK_SUCCESS;
-}
-
-
-static gint
-calculate_arrow_rect(GtkWidget* arrow, GdkRectangle* rect,
- GdkRectangle* arrow_rect, GtkTextDirection direction)
-{
- /* defined in gtkarrow.c */
- gfloat arrow_scaling = 0.7;
- gfloat xalign, xpad;
- gint extent;
- GtkMisc* misc = GTK_MISC(arrow);
- gfloat misc_xalign, misc_yalign;
- gint misc_xpad, misc_ypad;
-
- if (have_arrow_scaling)
- gtk_widget_style_get(arrow, "arrow_scaling", &arrow_scaling, NULL);
-
- gtk_misc_get_padding(misc, &misc_xpad, &misc_ypad);
- gtk_misc_get_alignment(misc, &misc_xalign, &misc_yalign);
-
- extent = MIN((rect->width - misc_xpad * 2),
- (rect->height - misc_ypad * 2)) * arrow_scaling;
-
- xalign = direction == GTK_TEXT_DIR_LTR ? misc_xalign : 1.0 - misc_xalign;
- xpad = misc_xpad + (rect->width - extent) * xalign;
-
- arrow_rect->x = direction == GTK_TEXT_DIR_LTR ?
- floor(rect->x + xpad) : ceil(rect->x + xpad);
- arrow_rect->y = floor(rect->y + misc_ypad +
- ((rect->height - extent) * misc_yalign));
-
- arrow_rect->width = arrow_rect->height = extent;
-
- return MOZ_GTK_SUCCESS;
-}
-
-static gint
-moz_gtk_scrolled_window_paint(cairo_t* cr, GdkRectangle* rect,
- GtkWidgetState* state)
-{
- GtkStyle* style;
- GtkAllocation allocation;
- GtkWidget* widget;
-
- ensure_scrolled_window_widget();
- widget = gParts->scrolledWindowWidget;
-
- gtk_widget_get_allocation(widget, &allocation);
- allocation.x = rect->x;
- allocation.y = rect->y;
- allocation.width = rect->width;
- allocation.height = rect->height;
- gtk_widget_set_allocation(widget, &allocation);
-
- style = gtk_widget_get_style(widget);
- gtk_paint_shadow(style, cr, GTK_STATE_NORMAL, GTK_SHADOW_IN,
- widget, "scrolled_window", rect->x , rect->y,
- rect->width, rect->height);
- return MOZ_GTK_SUCCESS;
-}
-
-static gint
-moz_gtk_scrollbar_button_paint(cairo_t* cr, GdkRectangle* rect,
- GtkWidgetState* state,
- GtkScrollbarButtonFlags flags,
- GtkTextDirection direction)
-{
- GtkStateType state_type = ConvertGtkState(state);
- GtkShadowType shadow_type = (state->active) ?
- GTK_SHADOW_IN : GTK_SHADOW_OUT;
- GdkRectangle arrow_rect;
- GtkStyle* style;
- GtkWidget *scrollbar;
- GtkAllocation allocation;
- GtkArrowType arrow_type;
- gint arrow_displacement_x, arrow_displacement_y;
- const char* detail = (flags & MOZ_GTK_STEPPER_VERTICAL) ?
- "vscrollbar" : "hscrollbar";
-
- ensure_scrollbar_widget();
-
- if (flags & MOZ_GTK_STEPPER_VERTICAL)
- scrollbar = gParts->vertScrollbarWidget;
- else
- scrollbar = gParts->horizScrollbarWidget;
-
- gtk_widget_set_direction(scrollbar, direction);
-
- /* Some theme engines (i.e., ClearLooks) check the scrollbar's allocation
- to determine where it should paint rounded corners on the buttons.
- We need to trick them into drawing the buttons the way we want them. */
-
- gtk_widget_get_allocation(scrollbar, &allocation);
- allocation.x = rect->x;
- allocation.y = rect->y;
- allocation.width = rect->width;
- allocation.height = rect->height;
-
- if (flags & MOZ_GTK_STEPPER_VERTICAL) {
- allocation.height *= 5;
- if (flags & MOZ_GTK_STEPPER_DOWN) {
- arrow_type = GTK_ARROW_DOWN;
- if (flags & MOZ_GTK_STEPPER_BOTTOM)
- allocation.y -= 4 * rect->height;
- else
- allocation.y -= rect->height;
-
- } else {
- arrow_type = GTK_ARROW_UP;
- if (flags & MOZ_GTK_STEPPER_BOTTOM)
- allocation.y -= 3 * rect->height;
- }
- } else {
- allocation.width *= 5;
- if (flags & MOZ_GTK_STEPPER_DOWN) {
- arrow_type = GTK_ARROW_RIGHT;
- if (flags & MOZ_GTK_STEPPER_BOTTOM)
- allocation.x -= 4 * rect->width;
- else
- allocation.x -= rect->width;
- } else {
- arrow_type = GTK_ARROW_LEFT;
- if (flags & MOZ_GTK_STEPPER_BOTTOM)
- allocation.x -= 3 * rect->width;
- }
- }
-
- gtk_widget_set_allocation(scrollbar, &allocation);
- style = gtk_widget_get_style(scrollbar);
-
- gtk_paint_box(style, cr, state_type, shadow_type,
- scrollbar, detail, rect->x, rect->y,
- rect->width, rect->height);
-
- arrow_rect.width = rect->width / 2;
- arrow_rect.height = rect->height / 2;
- arrow_rect.x = rect->x + (rect->width - arrow_rect.width) / 2;
- arrow_rect.y = rect->y + (rect->height - arrow_rect.height) / 2;
-
- if (state_type == GTK_STATE_ACTIVE) {
- gtk_widget_style_get(scrollbar,
- "arrow-displacement-x", &arrow_displacement_x,
- "arrow-displacement-y", &arrow_displacement_y,
- NULL);
-
- arrow_rect.x += arrow_displacement_x;
- arrow_rect.y += arrow_displacement_y;
- }
-
- gtk_paint_arrow(style, cr, state_type, shadow_type,
- scrollbar, detail, arrow_type, TRUE, arrow_rect.x,
- arrow_rect.y, arrow_rect.width, arrow_rect.height);
-
- return MOZ_GTK_SUCCESS;
-}
-
-static gint
-moz_gtk_scrollbar_trough_paint(GtkThemeWidgetType widget,
- cairo_t* cr, GdkRectangle* rect,
- GtkWidgetState* state,
- GtkTextDirection direction)
-{
- GtkStyle* style;
- GtkScrollbar *scrollbar;
-
- ensure_scrollbar_widget();
-
- if (widget == MOZ_GTK_SCROLLBAR_TRACK_HORIZONTAL)
- scrollbar = GTK_SCROLLBAR(gParts->horizScrollbarWidget);
- else
- scrollbar = GTK_SCROLLBAR(gParts->vertScrollbarWidget);
-
- gtk_widget_set_direction(GTK_WIDGET(scrollbar), direction);
-
- style = gtk_widget_get_style(GTK_WIDGET(scrollbar));
-
- gtk_paint_box(style, cr, GTK_STATE_ACTIVE, GTK_SHADOW_IN,
- GTK_WIDGET(scrollbar), "trough", rect->x, rect->y,
- rect->width, rect->height);
-
- if (state->focused) {
- gtk_paint_focus(style, cr, GTK_STATE_ACTIVE,
- GTK_WIDGET(scrollbar), "trough",
- rect->x, rect->y, rect->width, rect->height);
- }
-
- return MOZ_GTK_SUCCESS;
-}
-
-static gint
-moz_gtk_scrollbar_thumb_paint(GtkThemeWidgetType widget,
- cairo_t* cr, GdkRectangle* rect,
- GtkWidgetState* state,
- GtkTextDirection direction)
-{
- GtkStateType state_type = (state->inHover || state->active) ?
- GTK_STATE_PRELIGHT : GTK_STATE_NORMAL;
- GtkShadowType shadow_type = GTK_SHADOW_OUT;
- GtkStyle* style;
- GtkScrollbar *scrollbar;
- GtkAdjustment *adj;
-
- ensure_scrollbar_widget();
-
- if (widget == MOZ_GTK_SCROLLBAR_THUMB_HORIZONTAL)
- scrollbar = GTK_SCROLLBAR(gParts->horizScrollbarWidget);
- else
- scrollbar = GTK_SCROLLBAR(gParts->vertScrollbarWidget);
-
- gtk_widget_set_direction(GTK_WIDGET(scrollbar), direction);
-
- /* Make sure to set the scrollbar range before painting so that
- everything is drawn properly. At least the bluecurve (and
- maybe other) themes don't draw the top or bottom black line
- surrounding the scrollbar if the theme thinks that it's butted
- up against the scrollbar arrows. Note the increases of the
- clip rect below. */
- adj = gtk_range_get_adjustment(GTK_RANGE(scrollbar));
-
- if (widget == MOZ_GTK_SCROLLBAR_THUMB_HORIZONTAL) {
- gtk_adjustment_set_page_size(adj, rect->width);
- }
- else {
- gtk_adjustment_set_page_size(adj, rect->height);
- }
-
- gtk_adjustment_configure(adj,
- state->curpos,
- 0,
- state->maxpos,
- gtk_adjustment_get_step_increment(adj),
- gtk_adjustment_get_page_increment(adj),
- gtk_adjustment_get_page_size(adj));
-
- style = gtk_widget_get_style(GTK_WIDGET(scrollbar));
-
- gtk_paint_slider(style, cr, state_type, shadow_type,
- GTK_WIDGET(scrollbar), "slider", rect->x, rect->y,
- rect->width, rect->height,
- (widget == MOZ_GTK_SCROLLBAR_THUMB_HORIZONTAL) ?
- GTK_ORIENTATION_HORIZONTAL : GTK_ORIENTATION_VERTICAL);
-
- return MOZ_GTK_SUCCESS;
-}
-
-static gint
-moz_gtk_entry_paint(cairo_t* cr, GdkRectangle* rect,
- GtkWidgetState* state, GtkWidget* widget,
- GtkTextDirection direction)
-{
- GtkStateType bg_state = state->disabled ?
- GTK_STATE_INSENSITIVE : GTK_STATE_NORMAL;
- gint x, y, width = rect->width, height = rect->height;
- GtkStyle* style;
- gboolean interior_focus;
- gboolean theme_honors_transparency = FALSE;
- gint focus_width;
-
- gtk_widget_set_direction(widget, direction);
-
- style = gtk_widget_get_style(widget);
-
- gtk_widget_style_get(widget,
- "interior-focus", &interior_focus,
- "focus-line-width", &focus_width,
- "honors-transparent-bg-hint", &theme_honors_transparency,
- NULL);
-
- /* gtkentry.c uses two windows, one for the entire widget and one for the
- * text area inside it. The background of both windows is set to the "base"
- * color of the new state in gtk_entry_state_changed, but only the inner
- * textarea window uses gtk_paint_flat_box when exposed */
-
- /* This gets us a lovely greyish disabledish look */
- gtk_widget_set_sensitive(widget, !state->disabled);
-
- /* GTK fills the outer widget window with the base color before drawing the widget.
- * Some older themes rely on this behavior, but many themes nowadays use rounded
- * corners on their widgets. While most GTK apps are blissfully unaware of this
- * problem due to their use of the default window background, we render widgets on
- * many kinds of backgrounds on the web.
- * If the theme is able to cope with transparency, then we can skip pre-filling
- * and notify the theme it will paint directly on the canvas. */
- if (theme_honors_transparency) {
- g_object_set_data(G_OBJECT(widget), "transparent-bg-hint", GINT_TO_POINTER(TRUE));
- } else {
- cairo_save(cr);
- gdk_cairo_set_source_color(cr, (const GdkColor*)&style->base[bg_state]);
- cairo_pattern_set_extend(cairo_get_source(cr), CAIRO_EXTEND_REPEAT);
- cairo_fill(cr);
- cairo_restore(cr);
- g_object_set_data(G_OBJECT(widget), "transparent-bg-hint", GINT_TO_POINTER(FALSE));
- }
-
- /* Get the position of the inner window, see _gtk_entry_get_borders */
- x = XTHICKNESS(style);
- y = YTHICKNESS(style);
-
- if (!interior_focus) {
- x += focus_width;
- y += focus_width;
- }
-
- /* Simulate an expose of the inner window */
- gtk_paint_flat_box(style, cr, bg_state, GTK_SHADOW_NONE,
- widget, "entry_bg", rect->x + x,
- rect->y + y, rect->width - 2*x, rect->height - 2*y);
-
- /* Now paint the shadow and focus border.
- * We do like in gtk_entry_draw_frame, we first draw the shadow, a tad
- * smaller when focused if the focus is not interior, then the focus. */
- x = rect->x;
- y = rect->y;
-
- if (state->focused && !state->disabled) {
- /* This will get us the lit borders that focused textboxes enjoy on
- * some themes. */
- if (!interior_focus) {
- /* Indent the border a little bit if we have exterior focus
- (this is what GTK does to draw native entries) */
- x += focus_width;
- y += focus_width;
- width -= 2 * focus_width;
- height -= 2 * focus_width;
- }
- }
-
- gtk_paint_shadow(style, cr, GTK_STATE_NORMAL, GTK_SHADOW_IN,
- widget, "entry", x, y, width, height);
-
- if (state->focused && !state->disabled) {
- if (!interior_focus) {
- gtk_paint_focus(style, cr, GTK_STATE_NORMAL,
- widget, "entry",
- rect->x, rect->y, rect->width, rect->height);
- }
- }
-
- return MOZ_GTK_SUCCESS;
-}
-
-static gint
-moz_gtk_combo_box_paint(cairo_t* cr, GdkRectangle* rect,
- GtkWidgetState* state, gboolean ishtml,
- GtkTextDirection direction)
-{
- GdkRectangle arrow_rect, real_arrow_rect;
- gint /* arrow_size, */ separator_width;
- gboolean wide_separators;
- GtkStateType state_type = ConvertGtkState(state);
- GtkShadowType shadow_type = state->active ? GTK_SHADOW_IN : GTK_SHADOW_OUT;
- GtkStyle* style;
- GtkRequisition arrow_req;
-
- ensure_combo_box_widgets();
-
- /* Also sets the direction on gParts->comboBoxButtonWidget, which is then
- * inherited by the separator and arrow */
- moz_gtk_button_paint(cr, rect, state, GTK_RELIEF_NORMAL,
- gParts->comboBoxButtonWidget, direction);
-
- calculate_button_inner_rect(gParts->comboBoxButtonWidget,
- rect, &arrow_rect, direction, ishtml);
- /* Now arrow_rect contains the inner rect ; we want to correct the width
- * to what the arrow needs (see gtk_combo_box_size_allocate) */
- gtk_widget_get_preferred_size(gParts->comboBoxArrowWidget, &arrow_req, NULL);
- if (direction == GTK_TEXT_DIR_LTR)
- arrow_rect.x += arrow_rect.width - arrow_req.width;
- arrow_rect.width = arrow_req.width;
-
- calculate_arrow_rect(gParts->comboBoxArrowWidget,
- &arrow_rect, &real_arrow_rect, direction);
-
- style = gtk_widget_get_style(gParts->comboBoxArrowWidget);
-
- gtk_widget_size_allocate(gParts->comboBoxWidget, rect);
-
- gtk_paint_arrow(style, cr, state_type, shadow_type,
- gParts->comboBoxArrowWidget, "arrow", GTK_ARROW_DOWN, TRUE,
- real_arrow_rect.x, real_arrow_rect.y,
- real_arrow_rect.width, real_arrow_rect.height);
-
-
- /* If there is no separator in the theme, there's nothing left to do. */
- if (!gParts->comboBoxSeparatorWidget)
- return MOZ_GTK_SUCCESS;
-
- style = gtk_widget_get_style(gParts->comboBoxSeparatorWidget);
-
- gtk_widget_style_get(gParts->comboBoxSeparatorWidget,
- "wide-separators", &wide_separators,
- "separator-width", &separator_width,
- NULL);
-
- if (wide_separators) {
- if (direction == GTK_TEXT_DIR_LTR)
- arrow_rect.x -= separator_width;
- else
- arrow_rect.x += arrow_rect.width;
-
- gtk_paint_box(style, cr,
- GTK_STATE_NORMAL, GTK_SHADOW_ETCHED_OUT,
- gParts->comboBoxSeparatorWidget, "vseparator",
- arrow_rect.x, arrow_rect.y,
- separator_width, arrow_rect.height);
- } else {
- if (direction == GTK_TEXT_DIR_LTR)
- arrow_rect.x -= XTHICKNESS(style);
- else
- arrow_rect.x += arrow_rect.width;
-
- gtk_paint_vline(style, cr, GTK_STATE_NORMAL,
- gParts->comboBoxSeparatorWidget, "vseparator",
- arrow_rect.y, arrow_rect.y + arrow_rect.height,
- arrow_rect.x);
- }
-
- return MOZ_GTK_SUCCESS;
-}
-
-static gint
-moz_gtk_progressbar_paint(cairo_t* cr, GdkRectangle* rect,
- GtkTextDirection direction)
-{
- GtkStyle* style;
-
- ensure_progress_widget();
- gtk_widget_set_direction(gParts->progresWidget, direction);
-
- style = gtk_widget_get_style(gParts->progresWidget);
-
- gtk_paint_box(style, cr, GTK_STATE_NORMAL, GTK_SHADOW_IN,
- gParts->progresWidget, "trough", rect->x, rect->y,
- rect->width, rect->height);
-
- return MOZ_GTK_SUCCESS;
-}
-
-static gint
-moz_gtk_progress_chunk_paint(cairo_t* cr, GdkRectangle* rect,
- GtkTextDirection direction)
-{
- GtkStyle* style;
-
- ensure_progress_widget();
- gtk_widget_set_direction(gParts->progresWidget, direction);
-
- style = gtk_widget_get_style(gParts->progresWidget);
-
- gtk_paint_box(style, cr, GTK_STATE_PRELIGHT, GTK_SHADOW_OUT,
- gParts->progresWidget, "bar", rect->x, rect->y,
- rect->width, rect->height);
-
- return MOZ_GTK_SUCCESS;
-}
-
-gint
-moz_gtk_get_widget_border(GtkThemeWidgetType widget, gint* left, gint* top,
- gint* right, gint* bottom, GtkTextDirection direction,
- gboolean inhtml)
-{
- GtkWidget* w;
- GtkStyle *style;
-
- switch (widget) {
- case MOZ_GTK_BUTTON:
- {
- GtkBorder inner_border;
- gboolean interior_focus;
- gint focus_width, focus_pad;
- GtkStyle *style;
-
- ensure_button_widget();
- *left = *top = *right = *bottom = gtk_container_get_border_width(GTK_CONTAINER(gParts->buttonWidget));
-
- /* Don't add this padding in HTML, otherwise the buttons will
- become too big and stuff the layout. */
- if (!inhtml) {
- moz_gtk_widget_get_focus(gParts->buttonWidget, &interior_focus, &focus_width, &focus_pad);
- moz_gtk_button_get_inner_border(gParts->buttonWidget, &inner_border);
- *left += focus_width + focus_pad + inner_border.left;
- *right += focus_width + focus_pad + inner_border.right;
- *top += focus_width + focus_pad + inner_border.top;
- *bottom += focus_width + focus_pad + inner_border.bottom;
- }
-
- style = gtk_widget_get_style(gParts->buttonWidget);
- *left += style->xthickness;
- *right += style->xthickness;
- *top += style->ythickness;
- *bottom += style->ythickness;
- return MOZ_GTK_SUCCESS;
- }
- case MOZ_GTK_ENTRY:
- ensure_entry_widget();
- w = gParts->entryWidget;
- break;
- case MOZ_GTK_DROPDOWN:
- {
- /* We need to account for the arrow on the dropdown, so text
- * doesn't come too close to the arrow, or in some cases spill
- * into the arrow. */
- gboolean ignored_interior_focus, wide_separators;
- gint focus_width, focus_pad, separator_width;
- GtkRequisition arrow_req;
- GtkStyle* style;
-
- ensure_combo_box_widgets();
-
- *left = gtk_container_get_border_width(GTK_CONTAINER(gParts->comboBoxButtonWidget));
-
- if (!inhtml) {
- moz_gtk_widget_get_focus(gParts->comboBoxButtonWidget,
- &ignored_interior_focus,
- &focus_width, &focus_pad);
- *left += focus_width + focus_pad;
- }
-
- style = gtk_widget_get_style(gParts->comboBoxButtonWidget);
- *top = *left + style->ythickness;
- *left += style->xthickness;
-
- *right = *left; *bottom = *top;
-
- /* If there is no separator, don't try to count its width. */
- separator_width = 0;
- if (gParts->comboBoxSeparatorWidget) {
- gtk_widget_style_get(gParts->comboBoxSeparatorWidget,
- "wide-separators", &wide_separators,
- "separator-width", &separator_width,
- NULL);
-
- if (!wide_separators)
- separator_width =
- XTHICKNESS(style);
- }
-
- gtk_widget_get_preferred_size(gParts->comboBoxArrowWidget, &arrow_req, NULL);
- if (direction == GTK_TEXT_DIR_RTL)
- *left += separator_width + arrow_req.width;
- else
- *right += separator_width + arrow_req.width;
-
- return MOZ_GTK_SUCCESS;
- }
- case MOZ_GTK_PROGRESSBAR:
- ensure_progress_widget();
- w = gParts->progresWidget;
- break;
- /* These widgets have no borders, since they are not containers. */
- case MOZ_GTK_CHECKBUTTON:
- case MOZ_GTK_RADIOBUTTON:
- case MOZ_GTK_SCROLLBAR_BUTTON:
- case MOZ_GTK_SCROLLBAR_TRACK_HORIZONTAL:
- case MOZ_GTK_SCROLLBAR_TRACK_VERTICAL:
- case MOZ_GTK_SCROLLBAR_THUMB_HORIZONTAL:
- case MOZ_GTK_SCROLLBAR_THUMB_VERTICAL:
- case MOZ_GTK_PROGRESS_CHUNK:
- *left = *top = *right = *bottom = 0;
- return MOZ_GTK_SUCCESS;
- default:
- g_warning("Unsupported widget type: %d", widget);
- return MOZ_GTK_UNKNOWN_WIDGET;
- }
-
- style = gtk_widget_get_style(w);
- *right = *left = XTHICKNESS(style);
- *bottom = *top = YTHICKNESS(style);
-
- return MOZ_GTK_SUCCESS;
-}
-
-gint
-moz_gtk_get_scrollbar_metrics(MozGtkScrollbarMetrics *metrics)
-{
- ensure_scrollbar_widget();
-
- gtk_widget_style_get (gParts->horizScrollbarWidget,
- "slider_width", &metrics->slider_width,
- "trough_border", &metrics->trough_border,
- "stepper_size", &metrics->stepper_size,
- "stepper_spacing", &metrics->stepper_spacing,
- "trough_under_steppers", &metrics->trough_under_steppers,
- "has_secondary_forward_stepper", &metrics->has_secondary_forward_stepper,
- "has_secondary_backward_stepper", &metrics->has_secondary_backward_stepper,
- NULL);
-
- metrics->min_slider_size = gtk_range_get_min_slider_size(GTK_RANGE(gParts->horizScrollbarWidget));
-
- return MOZ_GTK_SUCCESS;
-}
-
-gint
-moz_gtk_widget_paint(GtkThemeWidgetType widget, cairo_t* cr,
- GdkRectangle* rect, GtkWidgetState* state,
- gint flags, GtkTextDirection direction)
-{
- switch (widget) {
- case MOZ_GTK_BUTTON:
- if (state->depressed) {
- ensure_toggle_button_widget();
- return moz_gtk_button_paint(cr, rect, state,
- (GtkReliefStyle) flags,
- gParts->toggleButtonWidget, direction);
- }
- ensure_button_widget();
- return moz_gtk_button_paint(cr, rect, state,
- (GtkReliefStyle) flags, gParts->buttonWidget,
- direction);
- break;
- case MOZ_GTK_CHECKBUTTON:
- case MOZ_GTK_RADIOBUTTON:
- return moz_gtk_toggle_paint(cr, rect, state,
- !!(flags & MOZ_GTK_WIDGET_CHECKED),
- !!(flags & MOZ_GTK_WIDGET_INCONSISTENT),
- (widget == MOZ_GTK_RADIOBUTTON),
- direction);
- break;
- case MOZ_GTK_SCROLLBAR_BUTTON:
- return moz_gtk_scrollbar_button_paint(cr, rect, state,
- (GtkScrollbarButtonFlags) flags,
- direction);
- break;
- case MOZ_GTK_SCROLLBAR_TRACK_HORIZONTAL:
- case MOZ_GTK_SCROLLBAR_TRACK_VERTICAL:
- return moz_gtk_scrollbar_trough_paint(widget, cr, rect,
- state, direction);
- break;
- case MOZ_GTK_SCROLLBAR_THUMB_HORIZONTAL:
- case MOZ_GTK_SCROLLBAR_THUMB_VERTICAL:
- return moz_gtk_scrollbar_thumb_paint(widget, cr, rect,
- state, direction);
- break;
- case MOZ_GTK_SCROLLED_WINDOW:
- return moz_gtk_scrolled_window_paint(cr, rect, state);
- break;
- case MOZ_GTK_ENTRY:
- ensure_entry_widget();
- return moz_gtk_entry_paint(cr, rect, state,
- gParts->entryWidget, direction);
- break;
- case MOZ_GTK_DROPDOWN:
- return moz_gtk_combo_box_paint(cr, rect, state,
- (gboolean) flags, direction);
- break;
- case MOZ_GTK_PROGRESSBAR:
- return moz_gtk_progressbar_paint(cr, rect, direction);
- break;
- case MOZ_GTK_PROGRESS_CHUNK:
- return moz_gtk_progress_chunk_paint(cr, rect, direction);
- break;
- default:
- g_warning("Unknown widget type: %d", widget);
- }
-
- return MOZ_GTK_UNKNOWN_WIDGET;
-}
-
-GtkWidget* moz_gtk_get_scrollbar_widget(void)
-{
- if (!is_initialized)
- return NULL;
- ensure_scrollbar_widget();
- return gParts->horizScrollbarWidget;
-}
-
-gint
-moz_gtk_shutdown()
-{
- GtkWidgetClass *entry_class;
- entry_class = g_type_class_peek(GTK_TYPE_ENTRY);
- g_type_class_unref(entry_class);
-
- is_initialized = FALSE;
-
- return MOZ_GTK_SUCCESS;
-}
-
-void moz_gtk_destroy_theme_parts_widgets(GtkThemeParts* parts)
-{
- if (!parts)
- return;
-
- if (parts->protoWindow) {
- gtk_widget_destroy(parts->protoWindow);
- parts->protoWindow = NULL;
- }
-}
-
-GtkWidget* moz_gtk_get_progress_widget()
-{
- if (!is_initialized)
- return NULL;
- ensure_progress_widget();
- return gParts->progresWidget;
-}
-
-#endif // GTK_API_VERSION_2
diff --git a/Source/WebCore/platform/gtk/gtkdrawing.h b/Source/WebCore/platform/gtk/gtkdrawing.h
index 9d13a07..412a1f7 100644
--- a/Source/WebCore/platform/gtk/gtkdrawing.h
+++ b/Source/WebCore/platform/gtk/gtkdrawing.h
@@ -81,9 +81,7 @@ typedef struct {
} MozGtkScrollbarMetrics;
typedef struct _GtkThemeParts {
-#ifdef GTK_API_VERSION_2
GdkColormap* colormap;
-#endif // GTK_API_VERSION_2
GtkWidget* protoWindow;
GtkWidget* protoLayout;
GtkWidget* buttonWidget;
@@ -205,18 +203,11 @@ void moz_gtk_destroy_theme_parts_widgets(GtkThemeParts* parts);
* flags: widget-dependant flags; see the GtkThemeWidgetType definition.
* direction: the text direction, to draw the widget correctly LTR and RTL.
*/
-#ifdef GTK_API_VERSION_2
gint
moz_gtk_widget_paint(GtkThemeWidgetType widget, GdkDrawable* drawable,
GdkRectangle* rect, GdkRectangle* cliprect,
GtkWidgetState* state, gint flags,
GtkTextDirection direction);
-#else
-gint
-moz_gtk_widget_paint(GtkThemeWidgetType widget, cairo_t* cr,
- GdkRectangle* rect, GtkWidgetState* state,
- gint flags, GtkTextDirection direction);
-#endif
/*** Widget metrics ***/
/**