+2009-06-03 Adam Langley <agl@google.com>
+
+ Reviewed by Eric Seidel.
+
+ Change Chromium scrollbar theme code to use different classes on
+ Windows and Linux rather than suppling symbols. The ScrollbarTheme
+ class is already using virtual dispatch, so there's no reason not to.
+
+ This should not affect any layout tests.
+
+ https://bugs.webkit.org/show_bug.cgi?id=26174
+
+ * platform/chromium/ScrollbarThemeChromium.cpp:
+ * platform/chromium/ScrollbarThemeChromium.h:
+ * platform/chromium/ScrollbarThemeChromiumLinux.cpp:
+ (WebCore::ScrollbarTheme::nativeTheme):
+ (WebCore::ScrollbarThemeChromiumLinux::scrollbarThickness):
+ (WebCore::ScrollbarThemeChromiumLinux::paintTrackPiece):
+ (WebCore::ScrollbarThemeChromiumLinux::paintButton):
+ (WebCore::ScrollbarThemeChromiumLinux::paintThumb):
+ (WebCore::ScrollbarThemeChromiumLinux::buttonSize):
+ * platform/chromium/ScrollbarThemeChromiumLinux.h: Added.
+ * platform/chromium/ScrollbarThemeChromiumWin.cpp:
+ (WebCore::ScrollbarTheme::nativeTheme):
+ (WebCore::ScrollbarThemeChromiumWin::scrollbarThickness):
+ (WebCore::ScrollbarThemeChromiumWin::invalidateOnMouseEnterExit):
+ (WebCore::ScrollbarThemeChromiumWin::shouldSnapBackToDragOrigin):
+ (WebCore::ScrollbarThemeChromiumWin::paintTrackPiece):
+ (WebCore::ScrollbarThemeChromiumWin::paintButton):
+ (WebCore::ScrollbarThemeChromiumWin::paintThumb):
+ (WebCore::ScrollbarThemeChromiumWin::getThemeState):
+ (WebCore::ScrollbarThemeChromiumWin::getThemeArrowState):
+ (WebCore::ScrollbarThemeChromiumWin::getClassicThemeState):
+ (WebCore::ScrollbarThemeChromiumWin::buttonSize):
+ * platform/chromium/ScrollbarThemeChromiumWin.h: Added.
+
2009-06-03 Pavel Feldman <pfeldman@chromium.org>
Reviewed by Timothy Hatcher.
namespace WebCore {
-ScrollbarTheme* ScrollbarTheme::nativeTheme()
-{
- static ScrollbarThemeChromium theme;
- return &theme;
-}
-
-ScrollbarThemeChromium::ScrollbarThemeChromium()
-{
-}
-
-ScrollbarThemeChromium::~ScrollbarThemeChromium()
-{
-}
-
-void ScrollbarThemeChromium::themeChanged()
-{
-}
-
bool ScrollbarThemeChromium::hasThumb(Scrollbar* scrollbar)
{
// This method is just called as a paint-time optimization to see if
return evt.shiftKey() && evt.button() == LeftButton;
}
-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
- // times thickness pixels left. This allows the scrollbar to scale down
- // and function even at tiny sizes.
-
- int thickness = scrollbarThickness(scrollbar->controlSize());
-
- // 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;
-
- if (scrollbar->orientation() == HorizontalScrollbar) {
- int width = scrollbar->width() < 2 * girth ? scrollbar->width() / 2 : girth;
- return IntSize(width, thickness);
- }
-
- int height = scrollbar->height() < 2 * girth ? scrollbar->height() / 2 : girth;
- return IntSize(thickness, height);
-}
-
} // namespace WebCore
/*
* Copyright (c) 2008, 2009, Google Inc. All rights reserved.
- *
+ *
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are
* met:
- *
+ *
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above
* * Neither the name of Google Inc. nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
- *
+ *
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
class PlatformMouseEvent;
- // This class contains the Chromium scrollbar implementations for Windows
- // and Linux. All of the symbols here in must be defined somewhere in the
- // code and we manage the platform specific parts by linking in different,
- // platform specific, files. Methods that we shared across platforms are
- // implemented in ScrollbarThemeChromium.cpp
+ // This class contains the scrollbar code which is shared between Chromium
+ // Windows and Linux.
class ScrollbarThemeChromium : public ScrollbarThemeComposite {
- public:
- ScrollbarThemeChromium();
- virtual ~ScrollbarThemeChromium();
-
- virtual int scrollbarThickness(ScrollbarControlSize = RegularScrollbar);
-
- virtual void themeChanged();
-
- virtual bool invalidateOnMouseEnterExit();
-
protected:
virtual bool hasButtons(Scrollbar*) { return true; }
virtual bool hasThumb(Scrollbar*);
virtual void paintScrollCorner(ScrollView*, GraphicsContext*, const IntRect&);
virtual bool shouldCenterOnThumb(Scrollbar*, const PlatformMouseEvent&);
- virtual bool shouldSnapBackToDragOrigin(Scrollbar*, const PlatformMouseEvent&);
virtual void paintTrackBackground(GraphicsContext*, Scrollbar*, const IntRect&);
- virtual void paintTrackPiece(GraphicsContext*, Scrollbar*, const IntRect&, ScrollbarPart);
- virtual void paintButton(GraphicsContext*, Scrollbar*, const IntRect&, ScrollbarPart);
- virtual void paintThumb(GraphicsContext*, Scrollbar*, const IntRect&);
virtual void paintTickmarks(GraphicsContext*, Scrollbar*, const IntRect&);
- private:
- IntSize buttonSize(Scrollbar*);
-
- int getThemeState(Scrollbar*, ScrollbarPart) const;
- int getThemeArrowState(Scrollbar*, ScrollbarPart) const;
- int getClassicThemeState(Scrollbar*, ScrollbarPart) const;
+ virtual IntSize buttonSize(Scrollbar*) = 0;
};
-
} // namespace WebCore
#endif
*/
#include "config.h"
-#include "ScrollbarThemeChromium.h"
+#include "ScrollbarThemeChromiumLinux.h"
#include "PlatformContextSkia.h"
#include "PlatformMouseEvent.h"
namespace WebCore {
-int ScrollbarThemeChromium::scrollbarThickness(ScrollbarControlSize controlSize)
+ScrollbarTheme* ScrollbarTheme::nativeTheme()
{
- return 15;
+ static ScrollbarThemeChromiumLinux theme;
+ return &theme;
}
-bool ScrollbarThemeChromium::invalidateOnMouseEnterExit()
+int ScrollbarThemeChromiumLinux::scrollbarThickness(ScrollbarControlSize controlSize)
{
- return false;
+ return 15;
}
static void drawVertLine(SkCanvas* canvas, int x, int y1, int y2, const SkPaint& paint)
return IntRect(scrollbar->x(), scrollbar->y() + bs.height(), thickness, scrollbar->height());
}
-bool ScrollbarThemeChromium::shouldSnapBackToDragOrigin(Scrollbar*, const PlatformMouseEvent&)
-{
- return false;
-}
-
-void ScrollbarThemeChromium::paintTrackPiece(GraphicsContext* gc, Scrollbar* scrollbar,
- const IntRect& rect, ScrollbarPart partType)
+void ScrollbarThemeChromiumLinux::paintTrackPiece(GraphicsContext* gc, Scrollbar* scrollbar, const IntRect& rect, ScrollbarPart partType)
{
SkCanvas* const canvas = gc->platformContext()->canvas();
SkPaint paint;
drawBox(canvas, rect, paint);
}
-void ScrollbarThemeChromium::paintButton(GraphicsContext* gc, Scrollbar* scrollbar,
- const IntRect& rect, ScrollbarPart part)
+void ScrollbarThemeChromiumLinux::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)
+void ScrollbarThemeChromiumLinux::paintThumb(GraphicsContext* gc, Scrollbar* scrollbar, const IntRect& rect)
{
const bool hovered = scrollbar->hoveredPart() == ThumbPart;
const int midx = rect.x() + rect.width() / 2;
}
}
+IntSize ScrollbarThemeChromiumLinux::buttonSize(Scrollbar* scrollbar)
+{
+ // On Linux, we don't use buttons
+ return IntSize(0, 0);
+}
+
} // namespace WebCore
--- /dev/null
+/*
+ * Copyright (c) 2009, Google Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ *
+ * * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above
+ * copyright notice, this list of conditions and the following disclaimer
+ * in the documentation and/or other materials provided with the
+ * distribution.
+ * * Neither the name of Google Inc. nor the names of its
+ * contributors may be used to endorse or promote products derived from
+ * this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#ifndef ScrollbarThemeChromiumLinux_h
+#define ScrollbarThemeChromiumLinux_h
+
+#include "ScrollbarThemeChromium.h"
+
+namespace WebCore {
+ class ScrollbarThemeChromiumLinux : public ScrollbarThemeChromium {
+ public:
+ virtual int scrollbarThickness(ScrollbarControlSize);
+
+ protected:
+ virtual void paintTrackPiece(GraphicsContext*, Scrollbar*, const IntRect&, ScrollbarPart);
+ virtual void paintButton(GraphicsContext*, Scrollbar*, const IntRect&, ScrollbarPart);
+ virtual void paintThumb(GraphicsContext*, Scrollbar*, const IntRect&);
+
+ virtual IntSize buttonSize(Scrollbar*);
+ };
+} // namespace WebCore
+
+#endif
*/
#include "config.h"
-#include "ScrollbarThemeChromium.h"
+#include "ScrollbarThemeChromiumWin.h"
#include <windows.h>
#include <vsstyle.h>
namespace WebCore {
+ScrollbarTheme* ScrollbarTheme::nativeTheme()
+{
+ static ScrollbarThemeChromiumWin theme;
+ return &theme;
+}
+
// The scrollbar size in DumpRenderTree on the Mac - so we can match their
// layout results. Entries are for regular, small, and mini scrollbars.
// Metrics obtained using [NSScroller scrollerWidthForControlSize:]
return IntRect(scrollbar->x(), scrollbar->y() + bs.height(), thickness, scrollbar->height() - 2 * bs.height());
}
-int ScrollbarThemeChromium::scrollbarThickness(ScrollbarControlSize controlSize)
+int ScrollbarThemeChromiumWin::scrollbarThickness(ScrollbarControlSize controlSize)
{
static int thickness;
if (!thickness) {
return thickness;
}
-bool ScrollbarThemeChromium::invalidateOnMouseEnterExit()
+bool ScrollbarThemeChromiumWin::invalidateOnMouseEnterExit()
{
return isVistaOrNewer();
}
-bool ScrollbarThemeChromium::shouldSnapBackToDragOrigin(Scrollbar* scrollbar, const PlatformMouseEvent& evt)
+bool ScrollbarThemeChromiumWin::shouldSnapBackToDragOrigin(Scrollbar* scrollbar, const PlatformMouseEvent& evt)
{
// Find the rect within which we shouldn't snap, by expanding the track rect
// in both dimensions.
return !rect.contains(mousePosition);
}
-void ScrollbarThemeChromium::paintTrackPiece(GraphicsContext* gc, Scrollbar* scrollbar, const IntRect& rect, ScrollbarPart partType)
+void ScrollbarThemeChromiumWin::paintTrackPiece(GraphicsContext* gc, Scrollbar* scrollbar, const IntRect& rect, ScrollbarPart partType)
{
bool horz = scrollbar->orientation() == HorizontalScrollbar;
alignRect);
}
-void ScrollbarThemeChromium::paintButton(GraphicsContext* gc, Scrollbar* scrollbar, const IntRect& rect, ScrollbarPart part)
+void ScrollbarThemeChromiumWin::paintButton(GraphicsContext* gc, Scrollbar* scrollbar, const IntRect& rect, ScrollbarPart part)
{
bool horz = scrollbar->orientation() == HorizontalScrollbar;
rect);
}
-void ScrollbarThemeChromium::paintThumb(GraphicsContext* gc, Scrollbar* scrollbar, const IntRect& rect)
+void ScrollbarThemeChromiumWin::paintThumb(GraphicsContext* gc, Scrollbar* scrollbar, const IntRect& rect)
{
bool horz = scrollbar->orientation() == HorizontalScrollbar;
rect);
}
-int ScrollbarThemeChromium::getThemeState(Scrollbar* scrollbar, ScrollbarPart part) const
+int ScrollbarThemeChromiumWin::getThemeState(Scrollbar* scrollbar, ScrollbarPart part) const
{
// When dragging the thumb, draw thumb pressed and other segments normal
// regardless of where the cursor actually is. See also four places in
return (scrollbar->pressedPart() == part) ? SCRBS_PRESSED : SCRBS_NORMAL;
}
-int ScrollbarThemeChromium::getThemeArrowState(Scrollbar* scrollbar, ScrollbarPart part) const
+int ScrollbarThemeChromiumWin::getThemeArrowState(Scrollbar* scrollbar, ScrollbarPart part) const
{
// We could take advantage of knowing the values in the state enum to write
// some simpler code, but treating the state enum as a black box seems
return (scrollbar->pressedPart() == part) ? ABS_DOWNPRESSED : ABS_DOWNNORMAL;
}
-int ScrollbarThemeChromium::getClassicThemeState(Scrollbar* scrollbar, ScrollbarPart part) const
+int ScrollbarThemeChromiumWin::getClassicThemeState(Scrollbar* scrollbar, ScrollbarPart part) const
{
// When dragging the thumb, draw the buttons normal even when hovered.
if (scrollbar->pressedPart() == ThumbPart)
return (scrollbar->pressedPart() == part) ? (DFCS_PUSHED | DFCS_FLAT) : 0;
}
+IntSize ScrollbarThemeChromiumWin::buttonSize(Scrollbar* scrollbar)
+{
+ // Our desired rect is essentially thickness by thickness.
+
+ // Our actual rect will shrink to half the available space when we have < 2
+ // times thickness pixels left. This allows the scrollbar to scale down
+ // and function even at tiny sizes.
+
+ int thickness = scrollbarThickness(scrollbar->controlSize());
+
+ // 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;
+
+ if (scrollbar->orientation() == HorizontalScrollbar) {
+ int width = scrollbar->width() < 2 * girth ? scrollbar->width() / 2 : girth;
+ return IntSize(width, thickness);
+ }
+
+ int height = scrollbar->height() < 2 * girth ? scrollbar->height() / 2 : girth;
+ return IntSize(thickness, height);
+}
+
+
} // namespace WebCore
--- /dev/null
+/*
+ * Copyright (c) 2009, Google Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ *
+ * * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above
+ * copyright notice, this list of conditions and the following disclaimer
+ * in the documentation and/or other materials provided with the
+ * distribution.
+ * * Neither the name of Google Inc. nor the names of its
+ * contributors may be used to endorse or promote products derived from
+ * this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#ifndef ScrollbarThemeChromiumWin_h
+#define ScrollbarThemeChromiumWin_h
+
+#include "ScrollbarThemeChromium.h"
+
+namespace WebCore {
+ class ScrollbarThemeChromiumWin : public ScrollbarThemeChromium {
+ public:
+ virtual int scrollbarThickness(ScrollbarControlSize);
+ virtual bool invalidateOnMouseEnterExit();
+ virtual bool shouldSnapBackToDragOrigin(Scrollbar*, const PlatformMouseEvent&);
+
+ protected:
+ virtual void paintTrackPiece(GraphicsContext*, Scrollbar*, const IntRect&, ScrollbarPart);
+ virtual void paintButton(GraphicsContext*, Scrollbar*, const IntRect&, ScrollbarPart);
+ virtual void paintThumb(GraphicsContext*, Scrollbar*, const IntRect&);
+ virtual IntSize buttonSize(Scrollbar*);
+
+ private:
+ int getThemeState(Scrollbar*, ScrollbarPart) const;
+ int getThemeArrowState(Scrollbar*, ScrollbarPart) const;
+ int getClassicThemeState(Scrollbar*, ScrollbarPart) const;
+ };
+} // namespace WebCore
+
+#endif