diff options
Diffstat (limited to 'WebCore/platform/mac')
-rw-r--r-- | WebCore/platform/mac/ContextMenuMac.mm | 76 | ||||
-rw-r--r-- | WebCore/platform/mac/GeolocationServiceMac.h | 77 | ||||
-rw-r--r-- | WebCore/platform/mac/GeolocationServiceMac.mm | 221 | ||||
-rw-r--r-- | WebCore/platform/mac/ScrollAnimatorMac.cpp | 60 | ||||
-rw-r--r-- | WebCore/platform/mac/ScrollAnimatorMac.h | 17 | ||||
-rw-r--r-- | WebCore/platform/mac/ScrollAnimatorMac.mm | 185 | ||||
-rw-r--r-- | WebCore/platform/mac/ScrollViewMac.mm | 7 | ||||
-rw-r--r-- | WebCore/platform/mac/WebCoreSystemInterface.h | 7 | ||||
-rw-r--r-- | WebCore/platform/mac/WebCoreSystemInterface.mm | 3 |
9 files changed, 218 insertions, 435 deletions
diff --git a/WebCore/platform/mac/ContextMenuMac.mm b/WebCore/platform/mac/ContextMenuMac.mm index 7c91028..c9451b9 100644 --- a/WebCore/platform/mac/ContextMenuMac.mm +++ b/WebCore/platform/mac/ContextMenuMac.mm @@ -28,92 +28,27 @@ #if ENABLE(CONTEXT_MENUS) -#include "ContextMenuController.h" - -@interface WebCoreMenuTarget : NSObject { - WebCore::ContextMenuController* _menuController; -} -+ (WebCoreMenuTarget*)sharedMenuTarget; -- (WebCore::ContextMenuController*)menuController; -- (void)setMenuController:(WebCore::ContextMenuController*)menuController; -- (void)forwardContextMenuAction:(id)sender; -- (BOOL)validateMenuItem:(NSMenuItem *)item; -@end - -static WebCoreMenuTarget* target; - -@implementation WebCoreMenuTarget - -+ (WebCoreMenuTarget*)sharedMenuTarget -{ - if (!target) - target = [[WebCoreMenuTarget alloc] init]; - return target; -} - -- (WebCore::ContextMenuController*)menuController -{ - return _menuController; -} - -- (void)setMenuController:(WebCore::ContextMenuController*)menuController -{ - _menuController = menuController; -} - -- (void)forwardContextMenuAction:(id)sender -{ - WebCore::ContextMenuItem item(WebCore::ActionType, static_cast<WebCore::ContextMenuAction>([sender tag]), [sender title]); - _menuController->contextMenuItemSelected(&item); -} - -- (BOOL)validateMenuItem:(NSMenuItem *)item -{ - WebCore::ContextMenuItem coreItem(item); - ASSERT(_menuController->contextMenu()); - _menuController->contextMenu()->checkOrEnableIfNeeded(coreItem); - return coreItem.enabled(); -} - -@end - namespace WebCore { -ContextMenu::ContextMenu(const HitTestResult& result) - : m_hitTestResult(result) +ContextMenu::ContextMenu() { NSMutableArray* array = [[NSMutableArray alloc] init]; m_platformDescription = array; [array release]; - - [[WebCoreMenuTarget sharedMenuTarget] setMenuController:controller()]; } -ContextMenu::ContextMenu(const HitTestResult& result, const PlatformMenuDescription menu) - : m_hitTestResult(result) - , m_platformDescription(menu) +ContextMenu::ContextMenu(const PlatformMenuDescription menu) + : m_platformDescription(menu) { - [[WebCoreMenuTarget sharedMenuTarget] setMenuController:controller()]; } ContextMenu::~ContextMenu() { } - -static void setMenuItemTarget(NSMenuItem* menuItem) -{ - [menuItem setTarget:[WebCoreMenuTarget sharedMenuTarget]]; - [menuItem setAction:@selector(forwardContextMenuAction:)]; -} void ContextMenu::appendItem(ContextMenuItem& item) { - checkOrEnableIfNeeded(item); - - ContextMenuItemType type = item.type(); NSMenuItem* platformItem = item.releasePlatformDescription(); - if (type == ActionType) - setMenuItemTarget(platformItem); [m_platformDescription.get() addObject:platformItem]; [platformItem release]; @@ -121,12 +56,7 @@ void ContextMenu::appendItem(ContextMenuItem& item) void ContextMenu::insertItem(unsigned position, ContextMenuItem& item) { - checkOrEnableIfNeeded(item); - - ContextMenuItemType type = item.type(); NSMenuItem* platformItem = item.releasePlatformDescription(); - if (type == ActionType) - setMenuItemTarget(platformItem); [m_platformDescription.get() insertObject:platformItem atIndex:position]; [platformItem release]; diff --git a/WebCore/platform/mac/GeolocationServiceMac.h b/WebCore/platform/mac/GeolocationServiceMac.h deleted file mode 100644 index 4beefca..0000000 --- a/WebCore/platform/mac/GeolocationServiceMac.h +++ /dev/null @@ -1,77 +0,0 @@ -/* - * Copyright (C) 2009 Apple 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: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. 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. - * - * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``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 APPLE INC. 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 GeolocationServiceMac_h -#define GeolocationServiceMac_h - -#if ENABLE(GEOLOCATION) - -#include "GeolocationService.h" -#include <wtf/PassRefPtr.h> -#include <wtf/RefPtr.h> -#include <wtf/RetainPtr.h> - -#ifdef __OBJC__ -@class CLLocationManager; -@class WebCoreCoreLocationObserver; -#else -class CLLocationManager; -class WebCoreCoreLocationObserver; -#endif - -namespace WebCore { - -class GeolocationServiceMac : public GeolocationService { -public: - static GeolocationService* create(GeolocationServiceClient*); - virtual ~GeolocationServiceMac(); - - virtual bool startUpdating(PositionOptions*); - virtual void stopUpdating(); - - virtual void suspend(); - virtual void resume(); - - virtual Geoposition* lastPosition() const { return m_lastPosition.get(); } - virtual PositionError* lastError() const { return m_lastError.get(); } - - void positionChanged(PassRefPtr<Geoposition>); - void errorOccurred(PassRefPtr<PositionError>); - -private: - GeolocationServiceMac(GeolocationServiceClient*); - - RetainPtr<CLLocationManager> m_locationManager; - RetainPtr<WebCoreCoreLocationObserver> m_objcObserver; - - RefPtr<Geoposition> m_lastPosition; - RefPtr<PositionError> m_lastError; -}; - -} // namespace WebCore - -#endif // ENABLE(GEOLOCATION) - -#endif // GeolocationServiceMac_h diff --git a/WebCore/platform/mac/GeolocationServiceMac.mm b/WebCore/platform/mac/GeolocationServiceMac.mm deleted file mode 100644 index 9c781ad..0000000 --- a/WebCore/platform/mac/GeolocationServiceMac.mm +++ /dev/null @@ -1,221 +0,0 @@ -/* - * Copyright (C) 2009 Apple 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: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. 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. - * - * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``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 APPLE INC. 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. - */ - -#import "config.h" - -#if ENABLE(GEOLOCATION) && !ENABLE(CLIENT_BASED_GEOLOCATION) - -#import "GeolocationServiceMac.h" - -#import "Geoposition.h" -#import "PositionError.h" -#import "PositionOptions.h" -#import "SoftLinking.h" -#import <CoreLocation/CoreLocation.h> -#import <objc/objc-runtime.h> -#import <wtf/RefPtr.h> -#import <wtf/UnusedParam.h> - -SOFT_LINK_FRAMEWORK(CoreLocation) - -SOFT_LINK_CLASS(CoreLocation, CLLocationManager) -SOFT_LINK_CLASS(CoreLocation, CLLocation) - -SOFT_LINK_CONSTANT(CoreLocation, kCLLocationAccuracyBest, double) -SOFT_LINK_CONSTANT(CoreLocation, kCLLocationAccuracyHundredMeters, double) - -#define kCLLocationAccuracyBest getkCLLocationAccuracyBest() -#define kCLLocationAccuracyHundredMeters getkCLLocationAccuracyHundredMeters() - -using namespace WebCore; - -@interface WebCoreCoreLocationObserver : NSObject<CLLocationManagerDelegate> -{ - GeolocationServiceMac* m_callback; -} - -- (id)initWithCallback:(GeolocationServiceMac*)callback; - -- (void)locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation; -- (void)locationManager:(CLLocationManager *)manager didFailWithError:(NSError *)error; - -@end - -namespace WebCore { - -GeolocationService* GeolocationServiceMac::create(GeolocationServiceClient* client) -{ - return new GeolocationServiceMac(client); -} - -GeolocationService::FactoryFunction* GeolocationService::s_factoryFunction = &GeolocationServiceMac::create; - -GeolocationServiceMac::GeolocationServiceMac(GeolocationServiceClient* client) - : GeolocationService(client) - , m_objcObserver(AdoptNS, [[WebCoreCoreLocationObserver alloc] initWithCallback:this]) -{ -} - -GeolocationServiceMac::~GeolocationServiceMac() -{ - [m_locationManager.get() stopUpdatingLocation]; - m_locationManager.get().delegate = nil; -} - -bool GeolocationServiceMac::startUpdating(PositionOptions* options) -{ - #define CLLocationManager getCLLocationManagerClass() - if (!m_locationManager.get()) { - m_locationManager.adoptNS([[CLLocationManager alloc] init]); - m_locationManager.get().delegate = m_objcObserver.get(); - } - - if (!m_locationManager.get().locationServicesEnabled) - return false; - - if (options) { - // CLLocationAccuracy values suggested by Ron Huang. - CLLocationAccuracy accuracy = options->enableHighAccuracy() ? kCLLocationAccuracyBest : kCLLocationAccuracyHundredMeters; - m_locationManager.get().desiredAccuracy = accuracy; - } - - // This can safely be called multiple times. - [m_locationManager.get() startUpdatingLocation]; - - return true; - #undef CLLocationManager -} - -void GeolocationServiceMac::stopUpdating() -{ - [m_locationManager.get() stopUpdatingLocation]; -} - -void GeolocationServiceMac::suspend() -{ - [m_locationManager.get() stopUpdatingLocation]; -} - -void GeolocationServiceMac::resume() -{ - [m_locationManager.get() startUpdatingLocation]; -} - -void GeolocationServiceMac::positionChanged(PassRefPtr<Geoposition> position) -{ - m_lastPosition = position; - GeolocationService::positionChanged(); -} - -void GeolocationServiceMac::errorOccurred(PassRefPtr<PositionError> error) -{ - m_lastError = error; - GeolocationService::errorOccurred(); -} - -} // namespace WebCore - -@implementation WebCoreCoreLocationObserver - -- (id)initWithCallback:(GeolocationServiceMac *)callback -{ - self = [super init]; - if (self) - m_callback = callback; - return self; -} - -- (void)locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation -{ - ASSERT(m_callback); - ASSERT(newLocation); - UNUSED_PARAM(manager); - UNUSED_PARAM(oldLocation); - - // Normalize - bool canProvideAltitude = true; - bool canProvideAltitudeAccuracy = true; - double altitude = newLocation.altitude; - double altitudeAccuracy = newLocation.verticalAccuracy; - if (altitudeAccuracy < 0.0) { - canProvideAltitude = false; - canProvideAltitudeAccuracy = false; - } - - bool canProvideSpeed = true; - double speed = newLocation.speed; - if (speed < 0.0) - canProvideSpeed = false; - - bool canProvideHeading = true; - double heading = newLocation.course; - if (heading < 0.0) - canProvideHeading = false; - - WTF::RefPtr<WebCore::Coordinates> newCoordinates = WebCore::Coordinates::create( - newLocation.coordinate.latitude, - newLocation.coordinate.longitude, - canProvideAltitude, - altitude, - newLocation.horizontalAccuracy, - canProvideAltitudeAccuracy, - altitudeAccuracy, - canProvideHeading, - heading, - canProvideSpeed, - speed); - WTF::RefPtr<WebCore::Geoposition> newPosition = WebCore::Geoposition::create( - newCoordinates.release(), - [newLocation.timestamp timeIntervalSince1970] * 1000.0); // seconds -> milliseconds - - m_callback->positionChanged(newPosition.release()); -} - -- (void)locationManager:(CLLocationManager *)manager didFailWithError:(NSError *)error -{ - ASSERT(m_callback); - ASSERT(error); - - UNUSED_PARAM(manager); - - PositionError::ErrorCode code; - switch ([error code]) { - case kCLErrorDenied: - code = PositionError::PERMISSION_DENIED; - break; - case kCLErrorLocationUnknown: - code = PositionError::POSITION_UNAVAILABLE; - break; - default: - code = PositionError::POSITION_UNAVAILABLE; - break; - } - - m_callback->errorOccurred(PositionError::create(code, [error localizedDescription])); -} - -@end - -#endif // ENABLE(GEOLOCATION) diff --git a/WebCore/platform/mac/ScrollAnimatorMac.cpp b/WebCore/platform/mac/ScrollAnimatorMac.cpp deleted file mode 100644 index f127a62..0000000 --- a/WebCore/platform/mac/ScrollAnimatorMac.cpp +++ /dev/null @@ -1,60 +0,0 @@ -/* - * Copyright (C) 2010 Apple 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: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. 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. - * - * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS 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 APPLE INC. OR ITS 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. - */ - -#include "config.h" - -#if ENABLE(SMOOTH_SCROLLING) - -#include "ScrollAnimatorMac.h" - -namespace WebCore { - -ScrollAnimator* ScrollAnimator::create(ScrollbarClient* client) -{ - return new ScrollAnimatorMac(client); -} - -ScrollAnimatorMac::ScrollAnimatorMac(ScrollbarClient* client) - : ScrollAnimator(client) -{ -} - -ScrollAnimatorMac::~ScrollAnimatorMac() -{ -} - -bool ScrollAnimatorMac::scroll(ScrollbarOrientation orientation, ScrollGranularity granularity, float step, float multiplier) -{ - return ScrollAnimator::scroll(orientation, granularity, step, multiplier); -} - -void ScrollAnimatorMac::setScrollPositionAndStopAnimation(ScrollbarOrientation orientation, float pos) -{ - return ScrollAnimator::setScrollPositionAndStopAnimation(orientation, pos); -} - -} // namespace WebCore - -#endif // ENABLE(SMOOTH_SCROLLING) diff --git a/WebCore/platform/mac/ScrollAnimatorMac.h b/WebCore/platform/mac/ScrollAnimatorMac.h index 3beaa4e..234e43c 100644 --- a/WebCore/platform/mac/ScrollAnimatorMac.h +++ b/WebCore/platform/mac/ScrollAnimatorMac.h @@ -28,8 +28,15 @@ #if ENABLE(SMOOTH_SCROLLING) +#include "FloatPoint.h" #include "ScrollAnimator.h" -#include "Timer.h" +#include <wtf/RetainPtr.h> + +#ifdef __OBJC__ +@class ScrollAnimationHelperDelegate; +#else +class ScrollAnimationHelperDelegate; +#endif namespace WebCore { @@ -40,6 +47,14 @@ public: virtual bool scroll(ScrollbarOrientation, ScrollGranularity, float step, float multiplier); virtual void setScrollPositionAndStopAnimation(ScrollbarOrientation, float position); + + // Called by the ScrollAnimationHelperDelegate. + FloatPoint currentPosition() const; + void immediateScrollToPoint(const FloatPoint& newPosition); + +private: + RetainPtr<id> m_scrollAnimationHelper; + RetainPtr<ScrollAnimationHelperDelegate> m_scrollAnimationHelperDelegate; }; } // namespace WebCore diff --git a/WebCore/platform/mac/ScrollAnimatorMac.mm b/WebCore/platform/mac/ScrollAnimatorMac.mm new file mode 100644 index 0000000..ca71bd3 --- /dev/null +++ b/WebCore/platform/mac/ScrollAnimatorMac.mm @@ -0,0 +1,185 @@ +/* + * Copyright (C) 2010 Apple 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: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. 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. + * + * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS 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 APPLE INC. OR ITS 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. + */ + +#include "config.h" + +#if ENABLE(SMOOTH_SCROLLING) + +#include "ScrollAnimatorMac.h" +#include "ScrollbarClient.h" + +@interface NSObject (NSScrollAnimationHelperDetails) +- (id)initWithDelegate:(id)delegate; +- (void)_stopRun; +- (BOOL)_isAnimating; +- (NSPoint)targetOrigin; +@end + +@interface ScrollAnimationHelperDelegate : NSObject +{ + WebCore::ScrollAnimatorMac* _animator; +} + +- (id)initWithScrollAnimator:(WebCore::ScrollAnimatorMac*)scrollAnimator; + +- (NSRect)bounds; +- (void)_immediateScrollToPoint:(NSPoint)newPosition; +- (NSSize)convertSizeToBase:(NSSize)size; +- (NSSize)convertSizeFromBase:(NSSize)size; + +- (id)superview; // Return nil. +- (id)documentView; // Return nil. +- (id)window; // Return nil. +- (void)_recursiveRecomputeToolTips; // No-op. +@end + +static NSSize abs(NSSize size) +{ + NSSize finalSize = size; + if (finalSize.width < 0) + finalSize.width = -finalSize.width; + if (finalSize.height < 0) + finalSize.height = -finalSize.height; + return finalSize; +} + +@implementation ScrollAnimationHelperDelegate + +- (id)initWithScrollAnimator:(WebCore::ScrollAnimatorMac*)scrollAnimator +{ + self = [super init]; + if (!self) + return nil; + + _animator = scrollAnimator; + return self; +} + +- (NSRect)bounds +{ + WebCore::FloatPoint currentPosition = _animator->currentPosition(); + return NSMakeRect(currentPosition.x(), currentPosition.y(), 0, 0); +} + +- (void)_immediateScrollToPoint:(NSPoint)newPosition +{ + _animator->immediateScrollToPoint(newPosition); +} + +- (NSSize)convertSizeToBase:(NSSize)size +{ + return abs(size); +} + +- (NSSize)convertSizeFromBase:(NSSize)size +{ + return abs(size); +} + +- (id)superview +{ + return nil; +} + +- (id)documentView +{ + return nil; +} + +- (id)window +{ + return nil; +} + +- (void)_recursiveRecomputeToolTips +{ +} + +@end + +namespace WebCore { + +ScrollAnimator* ScrollAnimator::create(ScrollbarClient* client) +{ + return new ScrollAnimatorMac(client); +} + +ScrollAnimatorMac::ScrollAnimatorMac(ScrollbarClient* client) + : ScrollAnimator(client) +{ + m_scrollAnimationHelperDelegate.adoptNS([[ScrollAnimationHelperDelegate alloc] initWithScrollAnimator:this]); + m_scrollAnimationHelper.adoptNS([[NSClassFromString(@"NSScrollAnimationHelper") alloc] initWithDelegate:m_scrollAnimationHelperDelegate.get()]); +} + +ScrollAnimatorMac::~ScrollAnimatorMac() +{ +} + +bool ScrollAnimatorMac::scroll(ScrollbarOrientation orientation, ScrollGranularity granularity, float step, float multiplier) +{ + if (![[NSUserDefaults standardUserDefaults] boolForKey:@"AppleScrollAnimationEnabled"]) + return ScrollAnimator::scroll(orientation, granularity, step, multiplier); + + if (granularity == ScrollByPixel) + 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); + if (currentPos == newPos) + return false; + + NSPoint newPoint; + if ([m_scrollAnimationHelper.get() _isAnimating]) { + NSPoint targetOrigin = [m_scrollAnimationHelper.get() targetOrigin]; + newPoint = orientation == HorizontalScrollbar ? NSMakePoint(newPos, targetOrigin.y) : NSMakePoint(targetOrigin.x, newPos); + } else + newPoint = orientation == HorizontalScrollbar ? NSMakePoint(newPos, m_currentPosY) : NSMakePoint(m_currentPosX, newPos); + + [m_scrollAnimationHelper.get() scrollToPoint:newPoint]; + return true; +} + +void ScrollAnimatorMac::setScrollPositionAndStopAnimation(ScrollbarOrientation orientation, float pos) +{ + [m_scrollAnimationHelper.get() _stopRun]; + ScrollAnimator::setScrollPositionAndStopAnimation(orientation, pos); +} + +FloatPoint ScrollAnimatorMac::currentPosition() const +{ + return FloatPoint(m_currentPosX, m_currentPosY); +} + +void ScrollAnimatorMac::immediateScrollToPoint(const FloatPoint& newPosition) +{ + m_currentPosX = newPosition.x(); + m_currentPosY = newPosition.y(); + + m_client->setScrollOffsetFromAnimation(IntPoint(m_currentPosX, m_currentPosY)); +} + +} // namespace WebCore + +#endif // ENABLE(SMOOTH_SCROLLING) diff --git a/WebCore/platform/mac/ScrollViewMac.mm b/WebCore/platform/mac/ScrollViewMac.mm index 7e415da..93ec971 100644 --- a/WebCore/platform/mac/ScrollViewMac.mm +++ b/WebCore/platform/mac/ScrollViewMac.mm @@ -147,7 +147,8 @@ void ScrollView::platformSetScrollbarsSuppressed(bool repaintOnUnsuppress) void ScrollView::platformSetScrollPosition(const IntPoint& scrollPoint) { BEGIN_BLOCK_OBJC_EXCEPTIONS; - NSPoint tempPoint = { max(-[scrollView() scrollOriginX], scrollPoint.x()), max(0, scrollPoint.y()) }; // Don't use NSMakePoint to work around 4213314. + NSPoint floatPoint = scrollPoint; + NSPoint tempPoint = { max(-[scrollView() scrollOrigin].x, floatPoint.x), max(-[scrollView() scrollOrigin].y, floatPoint.y) }; // Don't use NSMakePoint to work around 4213314. [documentView() scrollPoint:tempPoint]; END_BLOCK_OBJC_EXCEPTIONS; } @@ -202,10 +203,10 @@ bool ScrollView::platformIsOffscreen() const return ![platformWidget() window] || ![[platformWidget() window] isVisible]; } -void ScrollView::platformSetScrollOriginX(int x) +void ScrollView::platformSetScrollOrigin(const IntPoint& origin, bool updatePosition) { BEGIN_BLOCK_OBJC_EXCEPTIONS; - [scrollView() setScrollOriginX:x]; + [scrollView() setScrollOrigin:origin updatePosition:updatePosition]; END_BLOCK_OBJC_EXCEPTIONS; } diff --git a/WebCore/platform/mac/WebCoreSystemInterface.h b/WebCore/platform/mac/WebCoreSystemInterface.h index 201266e..0c78c23 100644 --- a/WebCore/platform/mac/WebCoreSystemInterface.h +++ b/WebCore/platform/mac/WebCoreSystemInterface.h @@ -29,6 +29,10 @@ #include <ApplicationServices/ApplicationServices.h> #include <objc/objc.h> +#if PLATFORM(MAC) && PLATFORM(CA) && !defined(BUILDING_ON_TIGER) && !defined(BUILDING_ON_LEOPARD) && !defined(BUILDING_ON_SNOW_LEOPARD) +#include <IOSurface/IOSurface.h> +#endif + typedef struct _NSRange NSRange; #ifdef NSGEOMETRY_TYPES_SAME_AS_CGGEOMETRY_TYPES @@ -179,6 +183,9 @@ extern CFIndex (*wkGetHyphenationLocationBeforeIndex)(CFStringRef string, CFInde extern CTLineRef (*wkCreateCTLineWithUniCharProvider)(const UniChar* (*provide)(CFIndex stringIndex, CFIndex* charCount, CFDictionaryRef* attributes, void*), void (*dispose)(const UniChar* chars, void*), void*); #if !defined(BUILDING_ON_TIGER) && !defined(BUILDING_ON_LEOPARD) && !defined(BUILDING_ON_SNOW_LEOPARD) extern CTTypesetterRef (*wkCreateCTTypesetterWithUniCharProviderAndOptions)(const UniChar* (*provide)(CFIndex stringIndex, CFIndex* charCount, CFDictionaryRef* attributes, void*), void (*dispose)(const UniChar* chars, void*), void*, CFDictionaryRef options); + +extern CGContextRef (*wkIOSurfaceContextCreate)(IOSurfaceRef surface, unsigned width, unsigned height, CGColorSpaceRef colorSpace); +extern CGImageRef (*wkIOSurfaceContextCreateImage)(CGContextRef context); #endif } diff --git a/WebCore/platform/mac/WebCoreSystemInterface.mm b/WebCore/platform/mac/WebCoreSystemInterface.mm index 9c0c441..df3c77c 100644 --- a/WebCore/platform/mac/WebCoreSystemInterface.mm +++ b/WebCore/platform/mac/WebCoreSystemInterface.mm @@ -122,4 +122,7 @@ CFIndex (*wkGetHyphenationLocationBeforeIndex)(CFStringRef string, CFIndex index CTLineRef (*wkCreateCTLineWithUniCharProvider)(const UniChar* (*provide)(CFIndex stringIndex, CFIndex* charCount, CFDictionaryRef* attributes, void*), void (*dispose)(const UniChar* chars, void*), void*); #if !defined(BUILDING_ON_TIGER) && !defined(BUILDING_ON_LEOPARD) && !defined(BUILDING_ON_SNOW_LEOPARD) CTTypesetterRef (*wkCreateCTTypesetterWithUniCharProviderAndOptions)(const UniChar* (*provide)(CFIndex stringIndex, CFIndex* charCount, CFDictionaryRef* attributes, void*), void (*dispose)(const UniChar* chars, void*), void*, CFDictionaryRef options); + +CGContextRef (*wkIOSurfaceContextCreate)(IOSurfaceRef surface, unsigned width, unsigned height, CGColorSpaceRef colorSpace); +CGImageRef (*wkIOSurfaceContextCreateImage)(CGContextRef context); #endif |