diff options
Diffstat (limited to 'Source/WebCore/platform/mac')
8 files changed, 88 insertions, 33 deletions
diff --git a/Source/WebCore/platform/mac/ClipboardMac.h b/Source/WebCore/platform/mac/ClipboardMac.h index 7187ecf..39eadda 100644 --- a/Source/WebCore/platform/mac/ClipboardMac.h +++ b/Source/WebCore/platform/mac/ClipboardMac.h @@ -44,6 +44,7 @@ class Frame; class FileList; class ClipboardMac : public Clipboard, public CachedResourceClient { + WTF_MAKE_FAST_ALLOCATED; public: static PassRefPtr<ClipboardMac> create(ClipboardType clipboardType, NSPasteboard *pasteboard, ClipboardAccessPolicy policy, Frame* frame) { diff --git a/Source/WebCore/platform/mac/LocalCurrentGraphicsContext.h b/Source/WebCore/platform/mac/LocalCurrentGraphicsContext.h index 90beb40..8fde2cf 100644 --- a/Source/WebCore/platform/mac/LocalCurrentGraphicsContext.h +++ b/Source/WebCore/platform/mac/LocalCurrentGraphicsContext.h @@ -31,7 +31,8 @@ class GraphicsContext; // This class automatically saves and restores the current NSGraphicsContext for // functions which call out into AppKit and rely on the currentContext being set -class LocalCurrentGraphicsContext : public Noncopyable { +class LocalCurrentGraphicsContext { + WTF_MAKE_NONCOPYABLE(LocalCurrentGraphicsContext); public: LocalCurrentGraphicsContext(GraphicsContext* graphicsContext); ~LocalCurrentGraphicsContext(); diff --git a/Source/WebCore/platform/mac/ScrollAnimatorMac.h b/Source/WebCore/platform/mac/ScrollAnimatorMac.h index 234e43c..f05db40 100644 --- a/Source/WebCore/platform/mac/ScrollAnimatorMac.h +++ b/Source/WebCore/platform/mac/ScrollAnimatorMac.h @@ -28,7 +28,6 @@ #if ENABLE(SMOOTH_SCROLLING) -#include "FloatPoint.h" #include "ScrollAnimator.h" #include <wtf/RetainPtr.h> @@ -42,14 +41,13 @@ namespace WebCore { class ScrollAnimatorMac : public ScrollAnimator { public: - ScrollAnimatorMac(ScrollbarClient*); + ScrollAnimatorMac(ScrollableArea*); virtual ~ScrollAnimatorMac(); virtual bool scroll(ScrollbarOrientation, ScrollGranularity, float step, float multiplier); - virtual void setScrollPositionAndStopAnimation(ScrollbarOrientation, float position); + virtual void scrollToOffsetWithoutAnimation(const FloatPoint&); // Called by the ScrollAnimationHelperDelegate. - FloatPoint currentPosition() const; void immediateScrollToPoint(const FloatPoint& newPosition); private: diff --git a/Source/WebCore/platform/mac/ScrollAnimatorMac.mm b/Source/WebCore/platform/mac/ScrollAnimatorMac.mm index ca71bd3..59b333b 100644 --- a/Source/WebCore/platform/mac/ScrollAnimatorMac.mm +++ b/Source/WebCore/platform/mac/ScrollAnimatorMac.mm @@ -28,7 +28,10 @@ #if ENABLE(SMOOTH_SCROLLING) #include "ScrollAnimatorMac.h" -#include "ScrollbarClient.h" + +#include "FloatPoint.h" +#include "ScrollableArea.h" +#include <wtf/PassOwnPtr.h> @interface NSObject (NSScrollAnimationHelperDetails) - (id)initWithDelegate:(id)delegate; @@ -121,13 +124,13 @@ static NSSize abs(NSSize size) namespace WebCore { -ScrollAnimator* ScrollAnimator::create(ScrollbarClient* client) +PassOwnPtr<ScrollAnimator> ScrollAnimator::create(ScrollableArea* scrollableArea) { - return new ScrollAnimatorMac(client); + return adoptPtr(new ScrollAnimatorMac(scrollableArea)); } -ScrollAnimatorMac::ScrollAnimatorMac(ScrollbarClient* client) - : ScrollAnimator(client) +ScrollAnimatorMac::ScrollAnimatorMac(ScrollableArea* scrollableArea) + : ScrollAnimator(scrollableArea) { m_scrollAnimationHelperDelegate.adoptNS([[ScrollAnimationHelperDelegate alloc] initWithScrollAnimator:this]); m_scrollAnimationHelper.adoptNS([[NSClassFromString(@"NSScrollAnimationHelper") alloc] initWithDelegate:m_scrollAnimationHelperDelegate.get()]); @@ -146,7 +149,7 @@ bool ScrollAnimatorMac::scroll(ScrollbarOrientation orientation, ScrollGranulari return ScrollAnimator::scroll(orientation, granularity, step, multiplier); float currentPos = orientation == HorizontalScrollbar ? m_currentPosX : m_currentPosY; - float newPos = std::max<float>(std::min<float>(currentPos + (step * multiplier), static_cast<float>(m_client->scrollSize(orientation))), 0); + float newPos = std::max<float>(std::min<float>(currentPos + (step * multiplier), static_cast<float>(m_scrollableArea->scrollSize(orientation))), 0); if (currentPos == newPos) return false; @@ -161,23 +164,17 @@ bool ScrollAnimatorMac::scroll(ScrollbarOrientation orientation, ScrollGranulari return true; } -void ScrollAnimatorMac::setScrollPositionAndStopAnimation(ScrollbarOrientation orientation, float pos) +void ScrollAnimatorMac::scrollToOffsetWithoutAnimation(const FloatPoint& offset) { [m_scrollAnimationHelper.get() _stopRun]; - ScrollAnimator::setScrollPositionAndStopAnimation(orientation, pos); -} - -FloatPoint ScrollAnimatorMac::currentPosition() const -{ - return FloatPoint(m_currentPosX, m_currentPosY); + ScrollAnimator::scrollToOffsetWithoutAnimation(offset); } void ScrollAnimatorMac::immediateScrollToPoint(const FloatPoint& newPosition) { m_currentPosX = newPosition.x(); m_currentPosY = newPosition.y(); - - m_client->setScrollOffsetFromAnimation(IntPoint(m_currentPosX, m_currentPosY)); + notityPositionChanged(); } } // namespace WebCore diff --git a/Source/WebCore/platform/mac/ScrollbarThemeMac.h b/Source/WebCore/platform/mac/ScrollbarThemeMac.h index c833ee7..8b5412d 100644 --- a/Source/WebCore/platform/mac/ScrollbarThemeMac.h +++ b/Source/WebCore/platform/mac/ScrollbarThemeMac.h @@ -40,6 +40,7 @@ public: virtual int scrollbarThickness(ScrollbarControlSize = RegularScrollbar); virtual bool supportsControlTints() const { return true; } + virtual bool usesOverlayScrollbars() const; virtual double initialAutoscrollTimerDelay(); virtual double autoscrollTimerDelay(); diff --git a/Source/WebCore/platform/mac/ScrollbarThemeMac.mm b/Source/WebCore/platform/mac/ScrollbarThemeMac.mm index ce3be1a..032d9f3 100644 --- a/Source/WebCore/platform/mac/ScrollbarThemeMac.mm +++ b/Source/WebCore/platform/mac/ScrollbarThemeMac.mm @@ -27,18 +27,39 @@ #include "ScrollbarThemeMac.h" #include "ImageBuffer.h" +#include "LocalCurrentGraphicsContext.h" #include "PlatformMouseEvent.h" #include "ScrollView.h" +#include "WebCoreSystemInterface.h" #include <Carbon/Carbon.h> +#include <wtf/HashMap.h> #include <wtf/StdLibExtras.h> #include <wtf/UnusedParam.h> +#if !defined(BUILDING_ON_TIGER) && !defined(BUILDING_ON_LEOPARD) && !defined(BUILDING_ON_SNOW_LEOPARD) +#define USE_WK_SCROLLBAR_PAINTER +#endif + // FIXME: There are repainting problems due to Aqua scroll bar buttons' visual overflow. using namespace std; using namespace WebCore; -static HashSet<Scrollbar*>* gScrollbars; +namespace WebCore { + +#if defined(USE_WK_SCROLLBAR_PAINTER) +typedef HashMap<Scrollbar*, RetainPtr<WKScrollbarPainterRef> > ScrollbarPainterMap; +#else +typedef HashSet<Scrollbar*> ScrollbarPainterMap; +#endif + +static ScrollbarPainterMap* scrollbarMap() +{ + static ScrollbarPainterMap* map = new ScrollbarPainterMap; + return map; +} + +} @interface ScrollbarPrefsObserver : NSObject { @@ -58,12 +79,17 @@ static HashSet<Scrollbar*>* gScrollbars; UNUSED_PARAM(unusedNotification); static_cast<ScrollbarThemeMac*>(ScrollbarTheme::nativeTheme())->preferencesChanged(); - if (!gScrollbars) + if (scrollbarMap()->isEmpty()) return; - HashSet<Scrollbar*>::iterator end = gScrollbars->end(); - for (HashSet<Scrollbar*>::iterator it = gScrollbars->begin(); it != end; ++it) { + ScrollbarPainterMap::iterator end = scrollbarMap()->end(); + for (ScrollbarPainterMap::iterator it = scrollbarMap()->begin(); it != end; ++it) { +#if defined(USE_WK_SCROLLBAR_PAINTER) + it->first->styleChanged(); + it->first->invalidate(); +#else (*it)->styleChanged(); (*it)->invalidate(); +#endif } } @@ -109,6 +135,9 @@ static ScrollbarButtonsPlacement gButtonPlacement = ScrollbarButtonsDoubleEnd; static void updateArrowPlacement() { +#if defined(USE_WK_SCROLLBAR_PAINTER) + gButtonPlacement = ScrollbarButtonsNone; +#else NSString *buttonPlacement = [[NSUserDefaults standardUserDefaults] objectForKey:@"AppleScrollBarVariant"]; if ([buttonPlacement isEqualToString:@"Single"]) gButtonPlacement = ScrollbarButtonsSingle; @@ -118,22 +147,23 @@ static void updateArrowPlacement() gButtonPlacement = ScrollbarButtonsDoubleBoth; else gButtonPlacement = ScrollbarButtonsDoubleEnd; // The default is ScrollbarButtonsDoubleEnd. +#endif } void ScrollbarThemeMac::registerScrollbar(Scrollbar* scrollbar) { - if (!gScrollbars) - gScrollbars = new HashSet<Scrollbar*>; - gScrollbars->add(scrollbar); +#if defined(USE_WK_SCROLLBAR_PAINTER) + WKScrollbarPainterRef scrollbarPainter = wkMakeScrollbarPainter(scrollbar->controlSize(), + scrollbar->orientation() == HorizontalScrollbar); + scrollbarMap()->add(scrollbar, scrollbarPainter); +#else + scrollbarMap()->add(scrollbar); +#endif } void ScrollbarThemeMac::unregisterScrollbar(Scrollbar* scrollbar) { - gScrollbars->remove(scrollbar); - if (gScrollbars->isEmpty()) { - delete gScrollbars; - gScrollbars = 0; - } + scrollbarMap()->remove(scrollbar); } ScrollbarThemeMac::ScrollbarThemeMac() @@ -165,6 +195,12 @@ int ScrollbarThemeMac::scrollbarThickness(ScrollbarControlSize controlSize) return cScrollbarThickness[controlSize]; } +bool ScrollbarThemeMac::usesOverlayScrollbars() const +{ + // FIXME: This should be enabled when <rdar://problem/8492788> is resolved. + return false; +} + double ScrollbarThemeMac::initialAutoscrollTimerDelay() { return gInitialButtonDelay; @@ -355,6 +391,20 @@ static int scrollbarPartToHIPressedState(ScrollbarPart part) bool ScrollbarThemeMac::paint(Scrollbar* scrollbar, GraphicsContext* context, const IntRect& damageRect) { +#if defined(USE_WK_SCROLLBAR_PAINTER) + context->save(); + context->clip(damageRect); + context->translate(scrollbar->frameRect().x(), scrollbar->frameRect().y()); + LocalCurrentGraphicsContext localContext(context); + wkScrollbarPainterPaint(scrollbarMap()->get(scrollbar).get(), + scrollbar->enabled(), + scrollbar->currentPos() / scrollbar->maximum(), + static_cast<CGFloat>(scrollbar->visibleSize()) / scrollbar->totalSize(), + scrollbar->frameRect()); + context->restore(); + return true; +#endif + HIThemeTrackDrawInfo trackInfo; trackInfo.version = 0; trackInfo.kind = scrollbar->controlSize() == RegularScrollbar ? kThemeMediumScrollBar : kThemeSmallScrollBar; @@ -370,7 +420,7 @@ bool ScrollbarThemeMac::paint(Scrollbar* scrollbar, GraphicsContext* context, co if (!scrollbar->enabled()) trackInfo.enableState = kThemeTrackDisabled; else - trackInfo.enableState = scrollbar->client()->isActive() ? kThemeTrackActive : kThemeTrackInactive; + trackInfo.enableState = scrollbar->scrollableArea()->isActive() ? kThemeTrackActive : kThemeTrackInactive; if (hasThumb(scrollbar)) trackInfo.attributes |= kThemeTrackShowThumb; diff --git a/Source/WebCore/platform/mac/WebCoreSystemInterface.h b/Source/WebCore/platform/mac/WebCoreSystemInterface.h index 0c78c23..045864a 100644 --- a/Source/WebCore/platform/mac/WebCoreSystemInterface.h +++ b/Source/WebCore/platform/mac/WebCoreSystemInterface.h @@ -186,6 +186,10 @@ extern CTTypesetterRef (*wkCreateCTTypesetterWithUniCharProviderAndOptions)(cons extern CGContextRef (*wkIOSurfaceContextCreate)(IOSurfaceRef surface, unsigned width, unsigned height, CGColorSpaceRef colorSpace); extern CGImageRef (*wkIOSurfaceContextCreateImage)(CGContextRef context); + +typedef struct __WKScrollbarPainter *WKScrollbarPainterRef; +extern WKScrollbarPainterRef (*wkMakeScrollbarPainter)(int controlSize, bool isHorizontal); +extern void (*wkScrollbarPainterPaint)(WKScrollbarPainterRef, bool enabled, double value, CGFloat proportion, CGRect frameRect); #endif } diff --git a/Source/WebCore/platform/mac/WebCoreSystemInterface.mm b/Source/WebCore/platform/mac/WebCoreSystemInterface.mm index df3c77c..047827f 100644 --- a/Source/WebCore/platform/mac/WebCoreSystemInterface.mm +++ b/Source/WebCore/platform/mac/WebCoreSystemInterface.mm @@ -125,4 +125,7 @@ CTTypesetterRef (*wkCreateCTTypesetterWithUniCharProviderAndOptions)(const UniCh CGContextRef (*wkIOSurfaceContextCreate)(IOSurfaceRef surface, unsigned width, unsigned height, CGColorSpaceRef colorSpace); CGImageRef (*wkIOSurfaceContextCreateImage)(CGContextRef context); + +WKScrollbarPainterRef (*wkMakeScrollbarPainter)(int controlSize, bool isHorizontal); +void (*wkScrollbarPainterPaint)(WKScrollbarPainterRef, bool enabled, double value, CGFloat proportion, CGRect frameRect); #endif |