Skip to content

Commit

Permalink
Merge ScrollbarThemeNonMacCommon and ScrollbarThemeAura.
Browse files Browse the repository at this point in the history
ScrollbarThemeAura has been the only subclass since http://crrev.com/145353011
removed ScrollbarThemeWin.

Review URL: https://codereview.chromium.org/1763213003

Cr-Commit-Position: refs/heads/master@{#379973}
  • Loading branch information
skobes-chromium authored and Commit bot committed Mar 8, 2016
1 parent bf33633 commit 4d90c49
Show file tree
Hide file tree
Showing 7 changed files with 135 additions and 219 deletions.
4 changes: 0 additions & 4 deletions third_party/WebKit/Source/platform/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -352,10 +352,6 @@ component("platform") {
"scroll/ScrollAnimator.cpp",
"scroll/ScrollAnimator.h",

# Mac uses only ScrollAnimatorMac.
"scroll/ScrollbarThemeNonMacCommon.cpp",
"scroll/ScrollbarThemeNonMacCommon.h",

# Uses LocaleMac instead.
"text/LocaleICU.cpp",
"text/LocaleICU.h",
Expand Down
1 change: 0 additions & 1 deletion third_party/WebKit/Source/platform/blink_platform.gyp
Original file line number Diff line number Diff line change
Expand Up @@ -290,7 +290,6 @@
['include', 'scroll/ScrollbarThemeMac\\.mm$'],

# Mac uses only ScrollAnimatorMac.
['exclude', 'scroll/ScrollbarThemeNonMacCommon\\.(cpp|h)$'],
['exclude', 'scroll/ScrollAnimator\\.cpp$'],
['exclude', 'scroll/ScrollAnimator\\.h$'],

Expand Down
4 changes: 1 addition & 3 deletions third_party/WebKit/Source/platform/blink_platform.gypi
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@
'animation/CompositorAnimation.h',
'animation/CompositorAnimationCurve.cpp',
'animation/CompositorAnimationCurve.h',
'animation/CompositorAnimationDelegate.h',
'animation/CompositorAnimationDelegate.h',
'animation/CompositorAnimationPlayer.cpp',
'animation/CompositorAnimationPlayer.h',
'animation/CompositorAnimationPlayerClient.cpp',
Expand Down Expand Up @@ -934,8 +934,6 @@
'scroll/ScrollbarThemeMac.mm',
'scroll/ScrollbarThemeMock.cpp',
'scroll/ScrollbarThemeMock.h',
'scroll/ScrollbarThemeNonMacCommon.cpp',
'scroll/ScrollbarThemeNonMacCommon.h',
'scroll/ScrollbarThemeOverlay.cpp',
'scroll/ScrollbarThemeOverlay.h',
'scroll/ScrollbarThemeOverlayMock.h',
Expand Down
138 changes: 116 additions & 22 deletions third_party/WebKit/Source/platform/scroll/ScrollbarThemeAura.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,9 @@
#include "platform/PlatformMouseEvent.h"
#include "platform/RuntimeEnabledFeatures.h"
#include "platform/graphics/GraphicsContext.h"
#include "platform/graphics/GraphicsContextStateSaver.h"
#include "platform/graphics/paint/DrawingRecorder.h"
#include "platform/scroll/ScrollableArea.h"
#include "platform/scroll/ScrollbarThemeClient.h"
#include "platform/scroll/ScrollbarThemeOverlay.h"
#include "public/platform/Platform.h"
Expand Down Expand Up @@ -147,22 +149,107 @@ int ScrollbarThemeAura::scrollbarThickness(ScrollbarControlSize controlSize)
return scrollbarSize.width();
}

bool ScrollbarThemeAura::shouldRepaintAllPartsOnInvalidation() const
bool ScrollbarThemeAura::hasThumb(const ScrollbarThemeClient& scrollbar)
{
// This theme can separately handle thumb invalidation.
return false;
// This method is just called as a paint-time optimization to see if
// painting the thumb can be skipped. We don't have to be exact here.
return thumbLength(scrollbar) > 0;
}

ScrollbarPart ScrollbarThemeAura::invalidateOnThumbPositionChange(const ScrollbarThemeClient& scrollbar, float oldPosition, float newPosition) const
IntRect ScrollbarThemeAura::backButtonRect(const ScrollbarThemeClient& scrollbar, ScrollbarPart part, bool)
{
ScrollbarPart invalidParts = NoPart;
ASSERT(buttonsPlacement() == WebScrollbarButtonsPlacementSingle);
static const ScrollbarPart kButtonParts[] = {BackButtonStartPart, ForwardButtonEndPart};
for (ScrollbarPart part : kButtonParts) {
if (buttonPartPaintingParams(scrollbar, oldPosition, part) != buttonPartPaintingParams(scrollbar, newPosition, part))
invalidParts = static_cast<ScrollbarPart>(invalidParts | part);
// Windows and Linux just have single arrows.
if (part == BackButtonEndPart)
return IntRect();

IntSize size = buttonSize(scrollbar);
return IntRect(scrollbar.x(), scrollbar.y(), size.width(), size.height());
}

IntRect ScrollbarThemeAura::forwardButtonRect(const ScrollbarThemeClient& scrollbar, ScrollbarPart part, bool)
{
// Windows and Linux just have single arrows.
if (part == ForwardButtonStartPart)
return IntRect();

IntSize size = buttonSize(scrollbar);
int x, y;
if (scrollbar.orientation() == HorizontalScrollbar) {
x = scrollbar.x() + scrollbar.width() - size.width();
y = scrollbar.y();
} else {
x = scrollbar.x();
y = scrollbar.y() + scrollbar.height() - size.height();
}
return IntRect(x, y, size.width(), size.height());
}

IntRect ScrollbarThemeAura::trackRect(const ScrollbarThemeClient& scrollbar, bool)
{
// The track occupies all space between the two buttons.
IntSize bs = buttonSize(scrollbar);
if (scrollbar.orientation() == HorizontalScrollbar) {
if (scrollbar.width() <= 2 * bs.width())
return IntRect();
return IntRect(scrollbar.x() + bs.width(), scrollbar.y(), scrollbar.width() - 2 * bs.width(), scrollbar.height());
}
if (scrollbar.height() <= 2 * bs.height())
return IntRect();
return IntRect(scrollbar.x(), scrollbar.y() + bs.height(), scrollbar.width(), scrollbar.height() - 2 * bs.height());
}

int ScrollbarThemeAura::minimumThumbLength(const ScrollbarThemeClient& scrollbar)
{
if (scrollbar.orientation() == VerticalScrollbar) {
IntSize size = Platform::current()->themeEngine()->getSize(WebThemeEngine::PartScrollbarVerticalThumb);
return size.height();
}

IntSize size = Platform::current()->themeEngine()->getSize(WebThemeEngine::PartScrollbarHorizontalThumb);
return size.width();
}

void ScrollbarThemeAura::paintTickmarks(GraphicsContext& context, const ScrollbarThemeClient& scrollbar, const IntRect& rect)
{
if (scrollbar.orientation() != VerticalScrollbar)
return;

if (rect.height() <= 0 || rect.width() <= 0)
return;

// Get the tickmarks for the frameview.
Vector<IntRect> tickmarks;
scrollbar.getTickmarks(tickmarks);
if (!tickmarks.size())
return;

if (DrawingRecorder::useCachedDrawingIfPossible(context, scrollbar, DisplayItem::ScrollbarTickmarks))
return;

DrawingRecorder recorder(context, scrollbar, DisplayItem::ScrollbarTickmarks, rect);
GraphicsContextStateSaver stateSaver(context);
context.setShouldAntialias(false);

for (Vector<IntRect>::const_iterator i = tickmarks.begin(); i != tickmarks.end(); ++i) {
// Calculate how far down (in %) the tick-mark should appear.
const float percent = static_cast<float>(i->y()) / scrollbar.totalSize();

// Calculate how far down (in pixels) the tick-mark should appear.
const int yPos = rect.y() + (rect.height() * percent);

FloatRect tickRect(rect.x(), yPos, rect.width(), 3);
context.fillRect(tickRect, Color(0xCC, 0xAA, 0x00, 0xFF));

FloatRect tickStroke(rect.x(), yPos + 1, rect.width(), 1);
context.fillRect(tickStroke, Color(0xFF, 0xDD, 0x00, 0xFF));
}
return invalidParts;
}

void ScrollbarThemeAura::paintTrackBackground(GraphicsContext& context, const ScrollbarThemeClient& scrollbar, const IntRect& rect)
{
// Just assume a forward track part. We only paint the track as a single piece when there is no thumb.
if (!hasThumb(scrollbar))
paintTrackPiece(context, scrollbar, rect, ForwardTrackPart);
}

void ScrollbarThemeAura::paintTrackPiece(GraphicsContext& gc, const ScrollbarThemeClient& scrollbar, const IntRect& rect, ScrollbarPart partType)
Expand Down Expand Up @@ -218,6 +305,24 @@ void ScrollbarThemeAura::paintThumb(GraphicsContext& gc, const ScrollbarThemeCli
Platform::current()->themeEngine()->paint(canvas, scrollbar.orientation() == HorizontalScrollbar ? WebThemeEngine::PartScrollbarHorizontalThumb : WebThemeEngine::PartScrollbarVerticalThumb, state, WebRect(rect), 0);
}

bool ScrollbarThemeAura::shouldRepaintAllPartsOnInvalidation() const
{
// This theme can separately handle thumb invalidation.
return false;
}

ScrollbarPart ScrollbarThemeAura::invalidateOnThumbPositionChange(const ScrollbarThemeClient& scrollbar, float oldPosition, float newPosition) const
{
ScrollbarPart invalidParts = NoPart;
ASSERT(buttonsPlacement() == WebScrollbarButtonsPlacementSingle);
static const ScrollbarPart kButtonParts[] = {BackButtonStartPart, ForwardButtonEndPart};
for (ScrollbarPart part : kButtonParts) {
if (buttonPartPaintingParams(scrollbar, oldPosition, part) != buttonPartPaintingParams(scrollbar, newPosition, part))
invalidParts = static_cast<ScrollbarPart>(invalidParts | part);
}
return invalidParts;
}

IntSize ScrollbarThemeAura::buttonSize(const ScrollbarThemeClient& scrollbar)
{
if (scrollbar.orientation() == VerticalScrollbar) {
Expand All @@ -230,15 +335,4 @@ IntSize ScrollbarThemeAura::buttonSize(const ScrollbarThemeClient& scrollbar)
return IntSize(scrollbar.width() < 2 * size.width() ? scrollbar.width() / 2 : size.width(), size.height());
}

int ScrollbarThemeAura::minimumThumbLength(const ScrollbarThemeClient& scrollbar)
{
if (scrollbar.orientation() == VerticalScrollbar) {
IntSize size = Platform::current()->themeEngine()->getSize(WebThemeEngine::PartScrollbarVerticalThumb);
return size.height();
}

IntSize size = Platform::current()->themeEngine()->getSize(WebThemeEngine::PartScrollbarHorizontalThumb);
return size.width();
}

} // namespace blink
24 changes: 18 additions & 6 deletions third_party/WebKit/Source/platform/scroll/ScrollbarThemeAura.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,22 +31,34 @@
#ifndef ScrollbarThemeAura_h
#define ScrollbarThemeAura_h

#include "platform/scroll/ScrollbarThemeNonMacCommon.h"
#include "platform/scroll/ScrollbarTheme.h"

namespace blink {

class PLATFORM_EXPORT ScrollbarThemeAura : public ScrollbarThemeNonMacCommon {
class PLATFORM_EXPORT ScrollbarThemeAura : public ScrollbarTheme {
public:
int scrollbarThickness(ScrollbarControlSize) override;

protected:
bool shouldRepaintAllPartsOnInvalidation() const override;
ScrollbarPart invalidateOnThumbPositionChange(const ScrollbarThemeClient&, float oldPosition, float newPosition) const override;
bool hasButtons(const ScrollbarThemeClient&) override { return true; }
bool hasThumb(const ScrollbarThemeClient&) override;

IntRect backButtonRect(const ScrollbarThemeClient&, ScrollbarPart, bool painting = false) override;
IntRect forwardButtonRect(const ScrollbarThemeClient&, ScrollbarPart, bool painting = false) override;
IntRect trackRect(const ScrollbarThemeClient&, bool painting = false) override;
int minimumThumbLength(const ScrollbarThemeClient&) override;

void paintTickmarks(GraphicsContext&, const ScrollbarThemeClient&, const IntRect&) override;
void paintTrackBackground(GraphicsContext&, const ScrollbarThemeClient&, const IntRect&) override;
void paintTrackPiece(GraphicsContext&, const ScrollbarThemeClient&, const IntRect&, ScrollbarPart) override;
void paintButton(GraphicsContext&, const ScrollbarThemeClient&, const IntRect&, ScrollbarPart) override;
void paintThumb(GraphicsContext&, const ScrollbarThemeClient&, const IntRect&) override;
IntSize buttonSize(const ScrollbarThemeClient&) override;
int minimumThumbLength(const ScrollbarThemeClient&) override;

bool shouldRepaintAllPartsOnInvalidation() const override;
ScrollbarPart invalidateOnThumbPositionChange(const ScrollbarThemeClient&, float oldPosition, float newPosition) const override;

private:
IntSize buttonSize(const ScrollbarThemeClient&);
};

} // namespace blink
Expand Down

This file was deleted.

Loading

0 comments on commit 4d90c49

Please sign in to comment.