+2009-03-02 Adam Langley <agl@google.com>
+
+ Reviewed by Darin Fisher.
+
+ Chromium Linux: Switch to using Skia to render widgets.
+
+ In order to sandbox the Chromium renderer on Linux we need to remove
+ the X connection. GTK cannot render without an X connection so, for
+ now, we render widgets ourselves.
+
+ Previously didn't use anti-alias fonts in order to match Windows font
+ rendering exactly. This was helpful when bootstrapping our layout
+ tests. Now, however, we are ready to enable it.
+
+ https://bugs.webkit.org/show_bug.cgi?id=24244
+
+ * platform/chromium/ScrollbarThemeChromium.cpp:
+ (WebCore::ScrollbarThemeChromium::buttonSize):
+ * platform/chromium/ScrollbarThemeChromiumLinux.cpp:
+ (WebCore::ScrollbarThemeChromium::scrollbarThickness):
+ (WebCore::ScrollbarThemeChromium::paintTrackPiece):
+ (WebCore::ScrollbarThemeChromium::paintButton):
+ (WebCore::ScrollbarThemeChromium::paintThumb):
+ * platform/graphics/chromium/FontPlatformDataLinux.cpp:
+ (WebCore::FontPlatformData::setupPaint):
+ * platform/graphics/skia/PlatformContextSkia.cpp:
+ (PlatformContextSkia::PlatformContextSkia):
+ (PlatformContextSkia::~PlatformContextSkia):
+ * platform/graphics/skia/PlatformContextSkia.h:
+ * rendering/RenderThemeChromiumGtk.cpp: Removed.
+ * rendering/RenderThemeChromiumGtk.h: Removed.
+ * rendering/RenderThemeChromiumLinux.cpp: Added.
+ * rendering/RenderThemeChromiumLinux.h: Added.
+
2009-03-03 Dimitri Glazkov <dglazkov@chromium.org>
Reviewed by Darin Fisher.
IntSize ScrollbarThemeChromium::buttonSize(Scrollbar* scrollbar)
{
+#if defined(__linux__)
+ // On Linux, we don't use buttons
+ return IntSize(0, 0);
+#endif
+
// Our desired rect is essentially thickness by thickness.
// Our actual rect will shrink to half the available space when we have < 2
int thickness = scrollbarThickness(scrollbar->controlSize());
-#if !defined(__linux__)
// In layout test mode, we force the button "girth" (i.e., the length of
// the button along the axis of the scrollbar) to be a fixed size.
// FIXME: This is retarded! scrollbarThickness is already fixed in layout
// test mode so that should be enough to result in repeatable results, but
// preserving this hack avoids having to rebaseline pixel tests.
const int kLayoutTestModeGirth = 17;
-
int girth = ChromiumBridge::layoutTestMode() ? kLayoutTestModeGirth : thickness;
-#else
- int girth = thickness;
-#endif
if (scrollbar->orientation() == HorizontalScrollbar) {
int width = scrollbar->width() < 2 * girth ? scrollbar->width() / 2 : girth;
#include "Scrollbar.h"
#include "TransformationMatrix.h"
-#include "gtkdrawing.h"
-#include <gtk/gtk.h>
-#include "skia/ext/GdkSkia.h"
-
namespace WebCore {
int ScrollbarThemeChromium::scrollbarThickness(ScrollbarControlSize controlSize)
{
- static int size = 0;
- if (!size) {
- MozGtkScrollbarMetrics metrics;
- moz_gtk_get_scrollbar_metrics(&metrics);
- size = metrics.slider_width;
- }
- return size;
+ return 15;
}
bool ScrollbarThemeChromium::invalidateOnMouseEnterExit()
return false;
}
-// Given an uninitialised widget state object, set the members such that it's
-// sane for drawing scrollbars
-static void initMozState(GtkWidgetState* mozState)
-{
- mozState->active = true;
- mozState->focused = false;
- mozState->inHover = false;
- mozState->disabled = false;
- mozState->isDefault = false;
- mozState->canDefault = false;
- mozState->depressed = false;
- mozState->curpos = 0;
- mozState->maxpos = 0;
-}
-
-// Paint a GTK widget
-// gc: context to draw onto
-// rect: the area of the widget
-// widget_type: the type of widget to draw
-// flags: widget dependent flags (e.g. direction of scrollbar arrows etc)
-//
-// See paintMozWiget in RenderThemeGtk.cpp for an explanation of the clipping.
-static void paintScrollbarWidget(GraphicsContext* gc, const IntRect& rect,
- GtkThemeWidgetType widget_type, gint flags)
-{
- PlatformContextSkia* pcs = gc->platformContext();
-
- GdkRectangle gdkRect = { rect.x(), rect.y(), rect.width(), rect.height() };
-
- const SkIRect clip_region = pcs->canvas()->getTotalClip().getBounds();
- TransformationMatrix ctm = gc->getCTM().inverse();
- IntPoint pos = ctm.mapPoint(
- IntPoint(SkScalarRound(clip_region.fLeft), SkScalarRound(clip_region.fTop)));
- GdkRectangle gdkClipRect;
- gdkClipRect.x = pos.x();
- gdkClipRect.y = pos.y();
- gdkClipRect.width = clip_region.width();
- gdkClipRect.height = clip_region.height();
-
- gdk_rectangle_intersect(&gdkRect, &gdkClipRect, &gdkClipRect);
-
- GtkWidgetState mozState;
- initMozState(&mozState);
-
- moz_gtk_widget_paint(widget_type, pcs->gdk_skia(), &gdkRect, &gdkClipRect,
- &mozState, flags, GTK_TEXT_DIR_LTR);
-}
-
void ScrollbarThemeChromium::paintTrackPiece(GraphicsContext* gc, Scrollbar* scrollbar,
const IntRect& rect, ScrollbarPart partType)
{
- const bool horz = scrollbar->orientation() == HorizontalScrollbar;
- const GtkThemeWidgetType track_type =
- horz ? MOZ_GTK_SCROLLBAR_TRACK_HORIZONTAL : MOZ_GTK_SCROLLBAR_TRACK_VERTICAL;
- paintScrollbarWidget(gc, rect, track_type, 0);
-}
+ const int right = rect.x() + rect.width();
+ const int bottom = rect.y() + rect.height();
+ SkCanvas* const canvas = gc->platformContext()->canvas();
-void ScrollbarThemeChromium::paintButton(GraphicsContext* gc, Scrollbar* scrollbar,
- const IntRect& rect, ScrollbarPart part)
-{
- // FIXME: It appears the either we're upsetting GTK by forcing WebKit sizes
- // on it, or the buttons expect the track to be drawn under them. Either
- // way, we end up with unpainted pixels which are upsetting the pixel
- // tests. Thus we paint green under the buttons to, at least, make the
- // pixel output the same between debug and opt builds.
SkPaint paint;
- paint.setARGB(255, 0, 255, 128);
+ paint.setARGB(0xff, 0xe3, 0xdd, 0xd8);
SkRect skrect;
- skrect.set(rect.x(), rect.y(), rect.x() + rect.width() - 1, rect.y() + rect.height() - 1);
- gc->platformContext()->canvas()->drawRect(skrect, paint);
+ skrect.set(rect.x(), rect.y(), right, bottom);
+ canvas->drawRect(skrect, paint);
+
+ paint.setARGB(0xff, 0xc5, 0xba, 0xb0);
+ canvas->drawLine(rect.x(), rect.y(), rect.x(), bottom, paint);
+ canvas->drawLine(right, rect.y(), right, bottom, paint);
+ canvas->drawLine(rect.x(), rect.y(), right, rect.y(), paint);
+ canvas->drawLine(rect.x(), bottom, right, bottom, paint);
+}
- const bool horz = scrollbar->orientation() == HorizontalScrollbar;
- gint flags = horz ? 0 : MOZ_GTK_STEPPER_VERTICAL;
- flags |= ForwardButtonEndPart == part ? MOZ_GTK_STEPPER_DOWN : 0;
- paintScrollbarWidget(gc, rect, MOZ_GTK_SCROLLBAR_BUTTON, flags);
+void ScrollbarThemeChromium::paintButton(GraphicsContext* gc, Scrollbar* scrollbar,
+ const IntRect& rect, ScrollbarPart part)
+{
+ // We don't use buttons
}
void ScrollbarThemeChromium::paintThumb(GraphicsContext* gc, Scrollbar* scrollbar, const IntRect& rect)
{
- const bool horz = scrollbar->orientation() == HorizontalScrollbar;
- const GtkThemeWidgetType thumb_type =
- horz ? MOZ_GTK_SCROLLBAR_THUMB_HORIZONTAL : MOZ_GTK_SCROLLBAR_THUMB_VERTICAL;
- paintScrollbarWidget(gc, rect, thumb_type, 0);
+ const bool hovered = scrollbar->hoveredPart() == ThumbPart;
+ const int right = rect.x() + rect.width();
+ const int bottom = rect.y() + rect.height();
+ const int midx = rect.x() + rect.width() / 2;
+ const int midy = rect.y() + rect.height() / 2;
+ const bool vertical = scrollbar->orientation() == VerticalScrollbar;
+ SkCanvas* const canvas = gc->platformContext()->canvas();
+
+ SkPaint paint;
+ if (hovered)
+ paint.setARGB(0xff, 0xff, 0xff, 0xff);
+ else
+ paint.setARGB(0xff, 0xf4, 0xf2, 0xef);
+
+ SkRect skrect;
+ if (vertical) {
+ skrect.set(rect.x(), rect.y(), midx + 1, bottom);
+ } else {
+ skrect.set(rect.x(), rect.y(), right, midy + 1);
+ }
+ canvas->drawRect(skrect, paint);
+
+ if (hovered) {
+ paint.setARGB(0xff, 0xf4, 0xf2, 0xef);
+ } else {
+ paint.setARGB(0xff, 0xea, 0xe5, 0xe0);
+ }
+ if (vertical) {
+ skrect.set(midx + 1, rect.y(), right, bottom);
+ } else {
+ skrect.set(rect.x(), midy + 1, right, bottom);
+ }
+ canvas->drawRect(skrect, paint);
+
+ paint.setARGB(0xff, 0x9d, 0x96, 0x8e);
+ canvas->drawLine(rect.x(), rect.y(), rect.x(), bottom, paint);
+ canvas->drawLine(right, rect.y(), right, bottom, paint);
+ canvas->drawLine(rect.x(), rect.y(), right, rect.y(), paint);
+ canvas->drawLine(rect.x(), bottom, right, bottom, paint);
+
+ if (rect.height() > 10 && rect.width() > 10) {
+ paint.setARGB(0xff, 0x9d, 0x96, 0x8e);
+ canvas->drawLine(midx - 1, midy, midx + 3, midy, paint);
+ canvas->drawLine(midx - 1, midy - 3, midx + 3, midy - 3, paint);
+ canvas->drawLine(midx - 1, midy + 3, midx + 3, midy + 3, paint);
+ }
}
} // namespace WebCore
{
const float ts = m_textSize > 0 ? m_textSize : 12;
- paint->setAntiAlias(false);
+ paint->setAntiAlias(true);
paint->setSubpixelText(false);
paint->setTextSize(SkFloatToScalar(ts));
paint->setTypeface(m_typeface);
#include <wtf/MathExtras.h>
-#if defined(__linux__)
-#include "GdkSkia.h"
-#endif
-
// State -----------------------------------------------------------------------
// Encapsulates the additional painting state information we store for each
{
m_stateStack.append(State());
m_state = &m_stateStack.last();
-#if defined(OS_LINUX)
- m_gdkskia = m_canvas ? gdk_skia_new(m_canvas) : 0;
-#endif
}
PlatformContextSkia::~PlatformContextSkia()
{
-#if defined(OS_LINUX)
- if (m_gdkskia) {
- g_object_unref(m_gdkskia);
- m_gdkskia = 0;
- }
-#endif
}
void PlatformContextSkia::setCanvas(skia::PlatformCanvas* canvas)
#include <wtf/Vector.h>
-typedef struct _GdkDrawable GdkSkia;
-
// This class holds the platform-specific state for GraphicsContext. We put
// most of our Skia wrappers on this class. In theory, a lot of this stuff could
// be moved to GraphicsContext directly, except that some code external to this
// possible quality.
bool isPrinting();
-#if defined(__linux__)
- // FIXME: should be camelCase.
- GdkSkia* gdk_skia() const { return m_gdkskia; }
-#endif
-
private:
#if defined(__linux__) || PLATFORM(WIN_OS)
// Used when restoring and the state has an image clip. Only shows the pixels in
// Current path in global coordinates.
SkPath m_path;
-#if defined(__linux__)
- // A pointer to a GDK Drawable wrapping of this Skia canvas
- GdkSkia* m_gdkskia;
-#endif
-
#if PLATFORM(WIN_OS)
bool m_drawingToImageBuffer;
#endif
+++ /dev/null
-/*
- * Copyright (C) 2007 Apple Inc.
- * Copyright (C) 2007 Alp Toker <alp@atoker.com>
- * Copyright (C) 2008 Collabora Ltd.
- * Copyright (C) 2008, 2009 Google Inc.
- *
- * 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 "RenderThemeChromiumGtk.h"
-
-#include "ChromiumBridge.h"
-#include "CSSValueKeywords.h"
-#include "GraphicsContext.h"
-#include "NotImplemented.h"
-#include "PlatformContextSkia.h"
-#include "RenderObject.h"
-#include "ScrollbarTheme.h"
-#include "gtkdrawing.h"
-#include "GdkSkia.h"
-#include "TransformationMatrix.h"
-#include "UserAgentStyleSheets.h"
-
-#include <gdk/gdk.h>
-
-namespace WebCore {
-
-enum PaddingType {
- TopPadding,
- RightPadding,
- BottomPadding,
- LeftPadding
-};
-
-static const int styledMenuListInternalPadding[4] = { 1, 4, 1, 4 };
-
-// The default variable-width font size. We use this as the default font
-// size for the "system font", and as a base size (which we then shrink) for
-// form control fonts.
-static float DefaultFontSize = 16.0;
-
-static Color makeColor(const GdkColor& c)
-{
- return Color(makeRGB(c.red >> 8, c.green >> 8, c.blue >> 8));
-}
-
-// We aim to match IE here.
-// -IE uses a font based on the encoding as the default font for form controls.
-// -Gecko uses MS Shell Dlg (actually calls GetStockObject(DEFAULT_GUI_FONT),
-// which returns MS Shell Dlg)
-// -Safari uses Lucida Grande.
-//
-// FIXME: The only case where we know we don't match IE is for ANSI encodings.
-// IE uses MS Shell Dlg there, which we render incorrectly at certain pixel
-// sizes (e.g. 15px). So, for now we just use Arial.
-static const char* defaultGUIFont(Document* document)
-{
- return "Arial";
-}
-
-// Converts points to pixels. One point is 1/72 of an inch.
-static float pointsToPixels(float points)
-{
- static float pixelsPerInch = 0.0f;
- if (!pixelsPerInch) {
- GdkScreen* screen = gdk_screen_get_default();
- // FIXME: I'm getting floating point values of ~75 and ~100,
- // and it's making my fonts look all wrong. Figure this out.
-#if 0
- if (screen)
- pixelsPerInch = gdk_screen_get_resolution(screen);
- else
-#endif
- pixelsPerInch = 96.0f; // Match the default we set on Windows.
- }
-
- static const float pointsPerInch = 72.0f;
- return points / pointsPerInch * pixelsPerInch;
-}
-
-static void setSizeIfAuto(RenderStyle* style, const IntSize& size)
-{
- if (style->width().isIntrinsicOrAuto())
- style->setWidth(Length(size.width(), Fixed));
- if (style->height().isAuto())
- style->setHeight(Length(size.height(), Fixed));
-}
-
-static bool supportsFocus(ControlPart appearance)
-{
- switch (appearance) {
- case PushButtonPart:
- case ButtonPart:
- case TextFieldPart:
- case TextAreaPart:
- case SearchFieldPart:
- case MenulistPart:
- case RadioPart:
- case CheckboxPart:
- return true;
- default:
- return false;
- }
-}
-
-static GtkTextDirection gtkTextDirection(TextDirection direction)
-{
- switch (direction) {
- case RTL:
- return GTK_TEXT_DIR_RTL;
- case LTR:
- return GTK_TEXT_DIR_LTR;
- default:
- return GTK_TEXT_DIR_NONE;
- }
-}
-
-static void setMozState(RenderTheme* theme, GtkWidgetState* state, RenderObject* o)
-{
- state->active = theme->isPressed(o);
- state->focused = theme->isFocused(o);
- state->inHover = theme->isHovered(o);
- // FIXME: Disabled does not always give the correct appearance for ReadOnly
- state->disabled = !theme->isEnabled(o) || theme->isReadOnlyControl(o);
- state->isDefault = false;
- state->canDefault = false;
- state->depressed = false;
-}
-
-static bool paintMozWidget(RenderTheme* theme, GtkThemeWidgetType type, RenderObject* o, const RenderObject::PaintInfo& i, const IntRect& rect)
-{
- // Painting is disabled so just claim to have succeeded
- if (i.context->paintingDisabled())
- return false;
-
- GtkWidgetState mozState;
- setMozState(theme, &mozState, o);
-
- int flags;
-
- // We might want to make setting flags the caller's job at some point rather than doing it here.
- switch (type) {
- case MOZ_GTK_BUTTON:
- flags = GTK_RELIEF_NORMAL;
- break;
- case MOZ_GTK_CHECKBUTTON:
- case MOZ_GTK_RADIOBUTTON:
- flags = theme->isChecked(o);
- break;
- default:
- flags = 0;
- break;
- }
-
- PlatformContextSkia* pcs = i.context->platformContext();
- SkCanvas* canvas = pcs->canvas();
- if (!canvas)
- return false;
-
- GdkRectangle gdkRect;
- gdkRect.x = rect.x();
- gdkRect.y = rect.y();
- gdkRect.width = rect.width();
- gdkRect.height = rect.height();
-
- // getTotalClip returns the currently set clip region in device coordinates,
- // so we have to apply the current transform (actually we only support translations)
- // to get the page coordinates that our gtk widget rendering expects.
- // We invert it because we want to map from device coordinates to page coordinates.
- const SkIRect clipRegion = canvas->getTotalClip().getBounds();
- TransformationMatrix ctm = i.context->getCTM().inverse();
- IntPoint pos = ctm.mapPoint(IntPoint(SkScalarRound(clipRegion.fLeft), SkScalarRound(clipRegion.fTop)));
- GdkRectangle gdkClipRect;
- gdkClipRect.x = pos.x();
- gdkClipRect.y = pos.y();
- gdkClipRect.width = clipRegion.width();
- gdkClipRect.height = clipRegion.height();
-
- // moz_gtk_widget_paint will paint outside the bounds of gdkRect unless we further restrict |gdkClipRect|.
- gdk_rectangle_intersect(&gdkRect, &gdkClipRect, &gdkClipRect);
-
- GtkTextDirection direction = gtkTextDirection(o->style()->direction());
-
- return moz_gtk_widget_paint(type, pcs->gdk_skia(), &gdkRect, &gdkClipRect, &mozState, flags, direction) != MOZ_GTK_SUCCESS;
-}
-
-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();
-}
-
-static double querySystemBlinkInterval(double defaultInterval)
-{
- GtkSettings* settings = gtk_settings_get_default();
-
- gboolean shouldBlink;
- gint time;
-
- g_object_get(settings, "gtk-cursor-blink", &shouldBlink, "gtk-cursor-blink-time", &time, NULL);
-
- if (!shouldBlink)
- return 0;
-
- return time / 1000.0;
-}
-
-// Implement WebCore::theme() for getting the global RenderTheme.
-RenderTheme* theme()
-{
- static RenderThemeChromiumGtk gtkTheme;
- return >kTheme;
-}
-
-RenderThemeChromiumGtk::RenderThemeChromiumGtk()
- : m_gtkWindow(0)
- , m_gtkContainer(0)
- , m_gtkEntry(0)
- , m_gtkTreeView(0)
-{
-}
-
-// Use the Windows style sheets to match their metrics.
-String RenderThemeChromiumGtk::extraDefaultStyleSheet()
-{
- return String(themeWinUserAgentStyleSheet, sizeof(themeWinUserAgentStyleSheet));
-}
-
-String RenderThemeChromiumGtk::extraQuirksStyleSheet()
-{
- return String(themeWinQuirksUserAgentStyleSheet, sizeof(themeWinQuirksUserAgentStyleSheet));
-}
-
-bool RenderThemeChromiumGtk::supportsFocusRing(const RenderStyle* style) const
-{
- return supportsFocus(style->appearance());
-}
-
-Color RenderThemeChromiumGtk::platformActiveSelectionBackgroundColor() const
-{
- GtkWidget* widget = gtkEntry();
- return makeColor(widget->style->base[GTK_STATE_SELECTED]);
-}
-
-Color RenderThemeChromiumGtk::platformInactiveSelectionBackgroundColor() const
-{
- GtkWidget* widget = gtkEntry();
- return makeColor(widget->style->base[GTK_STATE_ACTIVE]);
-}
-
-Color RenderThemeChromiumGtk::platformActiveSelectionForegroundColor() const
-{
- GtkWidget* widget = gtkEntry();
- return makeColor(widget->style->text[GTK_STATE_SELECTED]);
-}
-
-Color RenderThemeChromiumGtk::platformInactiveSelectionForegroundColor() const
-{
- GtkWidget* widget = gtkEntry();
- return makeColor(widget->style->text[GTK_STATE_ACTIVE]);
-}
-
-Color RenderThemeChromiumGtk::platformTextSearchHighlightColor() const
-{
- return Color(255, 255, 150);
-}
-
-double RenderThemeChromiumGtk::caretBlinkInterval() const
-{
- // Disable the blinking caret in layout test mode, as it introduces
- // a race condition for the pixel tests. http://b/1198440
- if (ChromiumBridge::layoutTestMode())
- return 0;
-
- // We cache the interval so we don't have to repeatedly request it from gtk.
- static double blinkInterval = querySystemBlinkInterval(RenderTheme::caretBlinkInterval());
- return blinkInterval;
-}
-
-void RenderThemeChromiumGtk::systemFont(int propId, Document* document, FontDescription& fontDescription) const
-{
- const char* faceName = 0;
- float fontSize = 0;
- // FIXME: see also RenderThemeChromiumWin.cpp
- switch (propId) {
- case CSSValueMenu:
- case CSSValueStatusBar:
- case CSSValueSmallCaption:
- // triggered by LayoutTests/fast/css/css2-system-fonts.html
- notImplemented();
- break;
- case CSSValueWebkitMiniControl:
- case CSSValueWebkitSmallControl:
- case CSSValueWebkitControl:
- faceName = defaultGUIFont(document);
- // Why 2 points smaller? Because that's what Gecko does.
- fontSize = DefaultFontSize - pointsToPixels(2);
- break;
- default:
- faceName = defaultGUIFont(document);
- fontSize = DefaultFontSize;
- }
-
- // Only update if the size makes sense.
- if (fontSize > 0) {
- fontDescription.firstFamily().setFamily(faceName);
- fontDescription.setSpecifiedSize(fontSize);
- fontDescription.setIsAbsoluteSize(true);
- fontDescription.setGenericFamily(FontDescription::NoFamily);
- fontDescription.setWeight(FontWeightNormal);
- fontDescription.setItalic(false);
- }
-}
-
-int RenderThemeChromiumGtk::minimumMenuListSize(RenderStyle* style) const
-{
- return 0;
-}
-
-bool RenderThemeChromiumGtk::paintCheckbox(RenderObject* o, const RenderObject::PaintInfo& i, const IntRect& rect)
-{
- return paintMozWidget(this, MOZ_GTK_CHECKBUTTON, o, i, rect);
-}
-
-void RenderThemeChromiumGtk::setCheckboxSize(RenderStyle* style) const
-{
- // If the width and height are both specified, then we have nothing to do.
- if (!style->width().isIntrinsicOrAuto() && !style->height().isAuto())
- return;
-
- // FIXME: A hard-coded size of 13 is used. This is wrong but necessary for now. It matches Firefox.
- // At different DPI settings on Windows, querying the theme gives you a larger size that accounts for
- // the higher DPI. Until our entire engine honors a DPI setting other than 96, we can't rely on the theme's
- // metrics.
- const IntSize size(13, 13);
- setSizeIfAuto(style, size);
-}
-
-bool RenderThemeChromiumGtk::paintRadio(RenderObject* o, const RenderObject::PaintInfo& i, const IntRect& rect)
-{
- return paintMozWidget(this, MOZ_GTK_RADIOBUTTON, o, i, rect);
-}
-
-void RenderThemeChromiumGtk::setRadioSize(RenderStyle* style) const
-{
- // Use same sizing for radio box as checkbox.
- setCheckboxSize(style);
-}
-
-bool RenderThemeChromiumGtk::paintButton(RenderObject* o, const RenderObject::PaintInfo& i, const IntRect& rect)
-{
- return paintMozWidget(this, MOZ_GTK_BUTTON, o, i, rect);
-}
-
-bool RenderThemeChromiumGtk::paintTextField(RenderObject* o, const RenderObject::PaintInfo& i, const IntRect& rect)
-{
- return paintMozWidget(this, MOZ_GTK_ENTRY, o, i, rect);
-}
-
-bool RenderThemeChromiumGtk::paintSearchField(RenderObject* o, const RenderObject::PaintInfo& i, const IntRect& rect)
-{
- return paintTextField(o, i, rect);
-}
-
-bool RenderThemeChromiumGtk::paintSearchFieldResultsDecoration(RenderObject* o, const RenderObject::PaintInfo& i, const IntRect& rect)
-{
- return paintMozWidget(this, MOZ_GTK_CHECKMENUITEM, o, i, rect);
-}
-
-bool RenderThemeChromiumGtk::paintSearchFieldResultsButton(RenderObject* o, const RenderObject::PaintInfo& i, const IntRect& rect)
-{
- return paintMozWidget(this, MOZ_GTK_DROPDOWN_ARROW, o, i, rect);
-}
-
-bool RenderThemeChromiumGtk::paintSearchFieldCancelButton(RenderObject* o, const RenderObject::PaintInfo& i, const IntRect& rect)
-{
- return paintMozWidget(this, MOZ_GTK_CHECKMENUITEM, o, i, rect);
-}
-
-void RenderThemeChromiumGtk::adjustMenuListStyle(CSSStyleSelector* selector, RenderStyle* style, WebCore::Element* e) const
-{
- // Height is locked to auto on all browsers.
- style->setLineHeight(RenderStyle::initialLineHeight());
-}
-
-bool RenderThemeChromiumGtk::paintMenuList(RenderObject* o, const RenderObject::PaintInfo& i, const IntRect& rect)
-{
- return paintMozWidget(this, MOZ_GTK_DROPDOWN, o, i, rect);
-}
-
-void RenderThemeChromiumGtk::adjustMenuListButtonStyle(CSSStyleSelector* selector, RenderStyle* style, Element* e) const
-{
- adjustMenuListStyle(selector, style, e);
-}
-
-// Used to paint styled menulists (i.e. with a non-default border)
-bool RenderThemeChromiumGtk::paintMenuListButton(RenderObject* o, const RenderObject::PaintInfo& i, const IntRect& r)
-{
- return paintMenuList(o, i, r);
-}
-
-int RenderThemeChromiumGtk::popupInternalPaddingLeft(RenderStyle* style) const
-{
- return menuListInternalPadding(style, LeftPadding);
-}
-
-int RenderThemeChromiumGtk::popupInternalPaddingRight(RenderStyle* style) const
-{
- return menuListInternalPadding(style, RightPadding);
-}
-
-int RenderThemeChromiumGtk::popupInternalPaddingTop(RenderStyle* style) const
-{
- return menuListInternalPadding(style, TopPadding);
-}
-
-int RenderThemeChromiumGtk::popupInternalPaddingBottom(RenderStyle* style) const
-{
- return menuListInternalPadding(style, BottomPadding);
-}
-
-int RenderThemeWin::buttonInternalPaddingLeft() const
-{
- return 3;
-}
-
-int RenderThemeWin::buttonInternalPaddingRight() const
-{
- return 3;
-}
-
-int RenderThemeWin::buttonInternalPaddingTop() const
-{
- return 1;
-}
-
-int RenderThemeWin::buttonInternalPaddingBottom() const
-{
- return 1;
-}
-
-bool RenderThemeChromiumGtk::controlSupportsTints(const RenderObject* o) const
-{
- return isEnabled(o);
-}
-
-Color RenderThemeChromiumGtk::activeListBoxSelectionBackgroundColor() const
-{
- GtkWidget* widget = gtkTreeView();
- return makeColor(widget->style->base[GTK_STATE_SELECTED]);
-}
-
-Color RenderThemeChromiumGtk::activeListBoxSelectionForegroundColor() const
-{
- GtkWidget* widget = gtkTreeView();
- return makeColor(widget->style->text[GTK_STATE_SELECTED]);
-}
-
-Color RenderThemeChromiumGtk::inactiveListBoxSelectionBackgroundColor() const
-{
- GtkWidget* widget = gtkTreeView();
- return makeColor(widget->style->base[GTK_STATE_ACTIVE]);
-}
-
-Color RenderThemeChromiumGtk::inactiveListBoxSelectionForegroundColor() const
-{
- GtkWidget* widget = gtkTreeView();
- return makeColor(widget->style->text[GTK_STATE_ACTIVE]);
-}
-
-GtkWidget* RenderThemeChromiumGtk::gtkEntry() const
-{
- if (m_gtkEntry)
- return m_gtkEntry;
-
- m_gtkEntry = gtk_entry_new();
- g_signal_connect(m_gtkEntry, "style-set", G_CALLBACK(gtkStyleSetCallback), theme());
- gtk_container_add(gtkContainer(), m_gtkEntry);
- gtk_widget_realize(m_gtkEntry);
-
- return m_gtkEntry;
-}
-
-GtkWidget* RenderThemeChromiumGtk::gtkTreeView() const
-{
- if (m_gtkTreeView)
- return m_gtkTreeView;
-
- m_gtkTreeView = gtk_tree_view_new();
- g_signal_connect(m_gtkTreeView, "style-set", G_CALLBACK(gtkStyleSetCallback), theme());
- gtk_container_add(gtkContainer(), m_gtkTreeView);
- gtk_widget_realize(m_gtkTreeView);
-
- return m_gtkTreeView;
-}
-
-GtkContainer* RenderThemeChromiumGtk::gtkContainer() const
-{
- if (m_gtkContainer)
- return m_gtkContainer;
-
- m_gtkWindow = gtk_window_new(GTK_WINDOW_POPUP);
- m_gtkContainer = GTK_CONTAINER(gtk_fixed_new());
- gtk_container_add(GTK_CONTAINER(m_gtkWindow), GTK_WIDGET(m_gtkContainer));
- gtk_widget_realize(m_gtkWindow);
-
- return m_gtkContainer;
-}
-
-int RenderThemeChromiumGtk::menuListInternalPadding(RenderStyle* style, int paddingType) const
-{
- // This internal padding is in addition to the user-supplied padding.
- // Matches the FF behavior.
- int padding = styledMenuListInternalPadding[paddingType];
-
- // Reserve the space for right arrow here. The rest of the padding is
- // set by adjustMenuListStyle, since PopMenuWin.cpp uses the padding from
- // RenderMenuList to lay out the individual items in the popup.
- // If the MenuList actually has appearance "NoAppearance", then that means
- // we don't draw a button, so don't reserve space for it.
- const int bar_type = style->direction() == LTR ? RightPadding : LeftPadding;
- if (paddingType == bar_type && style->appearance() != NoControlPart)
- padding += ScrollbarTheme::nativeTheme()->scrollbarThickness();
-
- return padding;
-}
-
-} // namespace WebCore
--- /dev/null
+/*
+ * Copyright (C) 2007 Apple Inc.
+ * Copyright (C) 2007 Alp Toker <alp@atoker.com>
+ * Copyright (C) 2008 Collabora Ltd.
+ * Copyright (C) 2008, 2009 Google Inc.
+ *
+ * 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 "RenderThemeChromiumLinux.h"
+
+#include "ChromiumBridge.h"
+#include "CSSValueKeywords.h"
+#include "GraphicsContext.h"
+#include "Image.h"
+#include "NotImplemented.h"
+#include "PlatformContextSkia.h"
+#include "RenderObject.h"
+#include "ScrollbarTheme.h"
+#include "TransformationMatrix.h"
+#include "UserAgentStyleSheets.h"
+
+#include "SkShader.h"
+#include "SkGradientShader.h"
+
+namespace WebCore {
+
+enum PaddingType {
+ TopPadding,
+ RightPadding,
+ BottomPadding,
+ LeftPadding
+};
+
+static const int styledMenuListInternalPadding[4] = { 1, 16, 1, 4 };
+
+static bool supportsFocus(ControlPart appearance)
+{
+ // This causes WebKit to draw the focus rings for us.
+ return false;
+}
+
+static void setSizeIfAuto(RenderStyle* style, const IntSize& size)
+{
+ if (style->width().isIntrinsicOrAuto())
+ style->setWidth(Length(size.width(), Fixed));
+ if (style->height().isAuto())
+ style->setHeight(Length(size.height(), Fixed));
+}
+
+// We aim to match IE here.
+// -IE uses a font based on the encoding as the default font for form controls.
+// -Gecko uses MS Shell Dlg (actually calls GetStockObject(DEFAULT_GUI_FONT),
+// which returns MS Shell Dlg)
+// -Safari uses Lucida Grande.
+//
+// FIXME: The only case where we know we don't match IE is for ANSI encodings.
+// IE uses MS Shell Dlg there, which we render incorrectly at certain pixel
+// sizes (e.g. 15px). So, for now we just use Arial.
+static const char* defaultGUIFont(Document* document)
+{
+ return "Arial";
+}
+
+RenderTheme* theme()
+{
+ static RenderThemeChromiumLinux theme;
+ return &theme;
+}
+
+RenderThemeChromiumLinux::RenderThemeChromiumLinux()
+{
+}
+
+// Use the Windows style sheets to match their metrics.
+String RenderThemeChromiumLinux::extraDefaultStyleSheet()
+{
+ return String(themeWinUserAgentStyleSheet, sizeof(themeWinUserAgentStyleSheet));
+}
+
+String RenderThemeChromiumLinux::extraQuirksStyleSheet()
+{
+ return String(themeWinQuirksUserAgentStyleSheet, sizeof(themeWinQuirksUserAgentStyleSheet));
+}
+
+bool RenderThemeChromiumLinux::supportsFocusRing(const RenderStyle* style) const
+{
+ return supportsFocus(style->appearance());
+}
+
+Color RenderThemeChromiumLinux::platformActiveSelectionBackgroundColor() const
+{
+ return Color(0x1e, 0x90, 0xff);
+}
+
+Color RenderThemeChromiumLinux::platformInactiveSelectionBackgroundColor() const
+{
+ return Color(0xc8, 0xc8, 0xc8);
+}
+
+Color RenderThemeChromiumLinux::platformActiveSelectionForegroundColor() const
+{
+ return Color(0, 0, 0);
+}
+
+Color RenderThemeChromiumLinux::platformInactiveSelectionForegroundColor() const
+{
+ return Color(0x32, 0x32, 0x32);
+}
+
+Color RenderThemeChromiumLinux::platformTextSearchHighlightColor() const
+{
+ return Color(0xff, 0xff, 0x96);
+}
+
+double RenderThemeChromiumLinux::caretBlinkInterval() const
+{
+ // Disable the blinking caret in layout test mode, as it introduces
+ // a race condition for the pixel tests. http://b/1198440
+ if (ChromiumBridge::layoutTestMode())
+ return 0;
+
+ // We cache the interval so we don't have to repeatedly request it from gtk.
+ return 0.5;
+}
+
+void RenderThemeChromiumLinux::systemFont(int propId, Document* document, FontDescription& fontDescription) const
+{
+ fontDescription.firstFamily().setFamily(defaultGUIFont(NULL));
+ fontDescription.setSpecifiedSize(12);
+ fontDescription.setIsAbsoluteSize(true);
+ fontDescription.setGenericFamily(FontDescription::NoFamily);
+ fontDescription.setWeight(FontWeightNormal);
+ fontDescription.setItalic(false);
+}
+
+int RenderThemeChromiumLinux::minimumMenuListSize(RenderStyle* style) const
+{
+ return 0;
+}
+
+bool RenderThemeChromiumLinux::paintCheckbox(RenderObject* o, const RenderObject::PaintInfo& i, const IntRect& rect)
+{
+ static Image* const checkedImage = Image::loadPlatformResource("linuxCheckboxOn").releaseRef();
+ static Image* const uncheckedImage = Image::loadPlatformResource("linuxCheckboxOff").releaseRef();
+
+ Image* image = this->isChecked(o) ? checkedImage : uncheckedImage;
+ i.context->drawImage(image, rect);
+ return false;
+}
+
+void RenderThemeChromiumLinux::setCheckboxSize(RenderStyle* style) const
+{
+ // If the width and height are both specified, then we have nothing to do.
+ if (!style->width().isIntrinsicOrAuto() && !style->height().isAuto())
+ return;
+
+ // FIXME: A hard-coded size of 13 is used. This is wrong but necessary
+ // for now. It matches Firefox. At different DPI settings on Windows,
+ // querying the theme gives you a larger size that accounts for the higher
+ // DPI. Until our entire engine honors a DPI setting other than 96, we
+ // can't rely on the theme's metrics.
+ const IntSize size(13, 13);
+ setSizeIfAuto(style, size);
+}
+
+bool RenderThemeChromiumLinux::paintRadio(RenderObject* o, const RenderObject::PaintInfo& i, const IntRect& rect)
+{
+ static Image* const checkedImage = Image::loadPlatformResource("linuxRadioOn").releaseRef();
+ static Image* const uncheckedImage = Image::loadPlatformResource("linuxRadioOff").releaseRef();
+
+ Image* image = this->isChecked(o) ? checkedImage : uncheckedImage;
+ i.context->drawImage(image, rect);
+ return false;
+}
+
+void RenderThemeChromiumLinux::setRadioSize(RenderStyle* style) const
+{
+ // Use same sizing for radio box as checkbox.
+ setCheckboxSize(style);
+}
+
+static void paintButtonLike(RenderTheme* theme, RenderObject* o, const RenderObject::PaintInfo& i, const IntRect& rect) {
+ SkCanvas* const canvas = i.context->platformContext()->canvas();
+ SkPaint paint;
+ SkRect skrect;
+ const int right = rect.x() + rect.width();
+ const int bottom = rect.y() + rect.height();
+
+ // If the button is too small, fallback to drawing a single, solid color
+ if (rect.width() < 5 || rect.height() < 5) {
+ paint.setARGB(0xff, 0xe9, 0xe9, 0xe9);
+ skrect.set(rect.x(), rect.y(), right, bottom);
+ canvas->drawRect(skrect, paint);
+ return;
+ }
+
+ const int borderAlpha = theme->isHovered(o) ? 0x80 : 0x55;
+ paint.setARGB(borderAlpha, 0, 0, 0);
+ canvas->drawLine(rect.x() + 1, rect.y(), right - 1, rect.y(), paint);
+ canvas->drawLine(right - 1, rect.y() + 1, right - 1, bottom - 1, paint);
+ canvas->drawLine(rect.x() + 1, bottom - 1, right - 1, bottom - 1, paint);
+ canvas->drawLine(rect.x(), rect.y() + 1, rect.x(), bottom - 1, paint);
+
+ paint.setARGB(0xff, 0, 0, 0);
+ SkPoint p[2];
+ const int lightEnd = theme->isPressed(o) ? 1 : 0;
+ const int darkEnd = !lightEnd;
+ p[lightEnd].set(SkIntToScalar(rect.x()), SkIntToScalar(rect.y()));
+ p[darkEnd].set(SkIntToScalar(rect.x()), SkIntToScalar(bottom - 1));
+ SkColor colors[2];
+ colors[0] = SkColorSetARGB(0xff, 0xf8, 0xf8, 0xf8);
+ colors[1] = SkColorSetARGB(0xff, 0xdd, 0xdd, 0xdd);
+
+ SkShader* s = SkGradientShader::CreateLinear(
+ p, colors, NULL, 2, SkShader::kClamp_TileMode, NULL);
+ paint.setStyle(SkPaint::kFill_Style);
+ paint.setShader(s);
+ s->unref();
+
+ skrect.set(rect.x() + 1, rect.y() + 1, right - 1, bottom - 1);
+ canvas->drawRect(skrect, paint);
+
+ paint.setShader(NULL);
+ paint.setARGB(0xff, 0xce, 0xce, 0xce);
+ canvas->drawPoint(rect.x() + 1, rect.y() + 1, paint);
+ canvas->drawPoint(right - 2, rect.y() + 1, paint);
+ canvas->drawPoint(rect.x() + 1, bottom - 2, paint);
+ canvas->drawPoint(right - 2, bottom - 2, paint);
+}
+
+bool RenderThemeChromiumLinux::paintButton(RenderObject* o, const RenderObject::PaintInfo& i, const IntRect& rect)
+{
+ paintButtonLike(this, o, i, rect);
+ return false;
+}
+
+bool RenderThemeChromiumLinux::paintTextField(RenderObject* o, const RenderObject::PaintInfo& i, const IntRect& rect)
+{
+ return true;
+}
+
+bool RenderThemeChromiumLinux::paintSearchField(RenderObject* o, const RenderObject::PaintInfo& i, const IntRect& rect)
+{
+ return true;
+}
+
+bool RenderThemeChromiumLinux::paintSearchFieldResultsDecoration(RenderObject* o, const RenderObject::PaintInfo& i, const IntRect& rect)
+{
+ return true;
+}
+
+bool RenderThemeChromiumLinux::paintSearchFieldResultsButton(RenderObject* o, const RenderObject::PaintInfo& i, const IntRect& rect)
+{
+ return true;
+}
+
+bool RenderThemeChromiumLinux::paintSearchFieldCancelButton(RenderObject* o, const RenderObject::PaintInfo& i, const IntRect& rect)
+{
+ return true;
+}
+
+void RenderThemeChromiumLinux::adjustMenuListStyle(CSSStyleSelector* selector, RenderStyle* style, WebCore::Element* e) const
+{
+ // Height is locked to auto on all browsers.
+ style->setLineHeight(RenderStyle::initialLineHeight());
+}
+
+bool RenderThemeChromiumLinux::paintMenuList(RenderObject* o, const RenderObject::PaintInfo& i, const IntRect& rect)
+{
+ SkCanvas* const canvas = i.context->platformContext()->canvas();
+ const int right = rect.x() + rect.width();
+ const int middle = rect.y() + rect.height() / 2;
+
+ paintButtonLike(this, o, i, rect);
+
+ SkPaint paint;
+ paint.setARGB(0xff, 0, 0, 0);
+ paint.setAntiAlias(true);
+ paint.setStyle(SkPaint::kFill_Style);
+
+ SkPath path;
+ path.moveTo(right - 13, middle - 3);
+ path.rLineTo(6, 0);
+ path.rLineTo(-3, 6);
+ path.close();
+ canvas->drawPath(path, paint);
+
+ return false;
+}
+
+void RenderThemeChromiumLinux::adjustMenuListButtonStyle(CSSStyleSelector* selector, RenderStyle* style, Element* e) const
+{
+ adjustMenuListStyle(selector, style, e);
+}
+
+// Used to paint styled menulists (i.e. with a non-default border)
+bool RenderThemeChromiumLinux::paintMenuListButton(RenderObject* o, const RenderObject::PaintInfo& i, const IntRect& rect)
+{
+ return paintMenuList(o, i, rect);
+}
+
+int RenderThemeChromiumLinux::popupInternalPaddingLeft(RenderStyle* style) const
+{
+ return menuListInternalPadding(style, LeftPadding);
+}
+
+int RenderThemeChromiumLinux::popupInternalPaddingRight(RenderStyle* style) const
+{
+ return menuListInternalPadding(style, RightPadding);
+}
+
+int RenderThemeChromiumLinux::popupInternalPaddingTop(RenderStyle* style) const
+{
+ return menuListInternalPadding(style, TopPadding);
+}
+
+int RenderThemeChromiumLinux::popupInternalPaddingBottom(RenderStyle* style) const
+{
+ return menuListInternalPadding(style, BottomPadding);
+}
+
+void RenderThemeChromiumLinux::buttonInternalPaddingLeft() const
+{
+ return 3;
+}
+
+void RenderThemeChromiumLinux::buttonInternalPaddingRight() const
+{
+ return 3;
+}
+
+void RenderThemeChromiumLinux::buttonInternalPaddingTop() const
+{
+ return 1;
+}
+
+void RenderThemeChromiumLinux::buttonInternalPaddingBottom() const
+{
+ return 1;
+}
+
+bool RenderThemeChromiumLinux::controlSupportsTints(const RenderObject* o) const
+{
+ return isEnabled(o);
+}
+
+Color RenderThemeChromiumLinux::activeListBoxSelectionBackgroundColor() const
+{
+ return Color(0x28, 0x28, 0x28);
+}
+
+Color RenderThemeChromiumLinux::activeListBoxSelectionForegroundColor() const
+{
+ return Color(0, 0, 0);
+}
+
+Color RenderThemeChromiumLinux::inactiveListBoxSelectionBackgroundColor() const
+{
+ return Color(0xc8, 0xc8, 0xc8);
+}
+
+Color RenderThemeChromiumLinux::inactiveListBoxSelectionForegroundColor() const
+{
+ return Color(0x32, 0x32, 0x32);
+}
+
+int RenderThemeChromiumLinux::menuListInternalPadding(RenderStyle* style, int paddingType) const
+{
+ // This internal padding is in addition to the user-supplied padding.
+ // Matches the FF behavior.
+ int padding = styledMenuListInternalPadding[paddingType];
+
+ // Reserve the space for right arrow here. The rest of the padding is
+ // set by adjustMenuListStyle, since PopMenuWin.cpp uses the padding from
+ // RenderMenuList to lay out the individual items in the popup.
+ // If the MenuList actually has appearance "NoAppearance", then that means
+ // we don't draw a button, so don't reserve space for it.
+ const int bar_type = style->direction() == LTR ? RightPadding : LeftPadding;
+ if (paddingType == bar_type && style->appearance() != NoControlPart)
+ padding += ScrollbarTheme::nativeTheme()->scrollbarThickness();
+
+ return padding;
+}
+
+} // namespace WebCore
*
*/
-#ifndef RenderThemeChromiumGtk_h
-#define RenderThemeChromiumGtk_h
+#ifndef RenderThemeChromiumLinux_h
+#define RenderThemeChromiumLinux_h
#include "RenderTheme.h"
-#include <gtk/gtk.h>
-
namespace WebCore {
- class RenderThemeChromiumGtk : public RenderTheme {
+ class RenderThemeChromiumLinux : public RenderTheme {
public:
- RenderThemeChromiumGtk();
- ~RenderThemeChromiumGtk() { }
+ RenderThemeChromiumLinux();
+ ~RenderThemeChromiumLinux() { }
virtual String extraDefaultStyleSheet();
virtual String extraQuirksStyleSheet();
virtual Color inactiveListBoxSelectionBackgroundColor() const;
virtual Color inactiveListBoxSelectionForegroundColor() const;
- private:
- // Hold the state
- GtkWidget* gtkEntry() const;
- GtkWidget* gtkTreeView() const;
-
- // Unmapped GdkWindow having a container. This is holding all our fake widgets
- GtkContainer* gtkContainer() const;
-
private:
int menuListInternalPadding(RenderStyle*, int paddingType) const;
-
- mutable GtkWidget* m_gtkWindow;
- mutable GtkContainer* m_gtkContainer;
- mutable GtkWidget* m_gtkEntry;
- mutable GtkWidget* m_gtkTreeView;
};
} // namespace WebCore