Changeset 103291 in webkit


Ignore:
Timestamp:
Dec 19, 2011 6:01:16 PM (12 years ago)
Author:
commit-queue@webkit.org
Message:

Merge ScrollAnimatorChromiumMac.mm back to ScrollAnimatorMac
https://bugs.webkit.org/show_bug.cgi?id=61144

Patch by Sailesh Agrawal <sail@chromium.org> on 2011-12-19
Reviewed by Beth Dakin.

At a high level the main changes are:

  • replace #ifdefs in ScrollAnimatorMac and ScrollbarThemeMac with run time checks
  • delete duplicate code in ScrollbarThemeChromiumMac. Keep the paint code since it does tickmarks and SKIA stuff.
  • delete ScrollAnimatorChromiumMac since ScrollAnimatorMac does the exact same thing
  • delete ScrollbarOverlayUtilitiesChromiumMac since NSScrollerImpDetails does the same thing

No new tests. Just refactoring.

  • WebCore.gyp/WebCore.gyp:
  • WebCore.gypi:
  • WebCore.xcodeproj/project.pbxproj:
  • platform/chromium/ScrollAnimatorChromiumMac.h: Removed.
  • platform/chromium/ScrollAnimatorChromiumMac.mm: Removed.
  • platform/chromium/ScrollbarOverlayUtilitiesChromiumMac.h: Removed.
  • platform/chromium/ScrollbarOverlayUtilitiesChromiumMac.mm: Removed.
  • platform/chromium/ScrollbarThemeChromiumMac.h:
  • platform/chromium/ScrollbarThemeChromiumMac.mm:

(WebCore::ScrollbarThemeChromiumMac::ScrollbarThemeChromiumMac):
(WebCore::scrollbarPainterPaintTrack):
(WebCore::ScrollbarThemeChromiumMac::paint):

  • platform/mac/EmptyProtocolDefinitions.h:
  • platform/mac/NSScrollerImpDetails.h:

(WebCore::isScrollbarOverlayAPIAvailable):

  • platform/mac/NSScrollerImpDetails.mm: Added.

(WebCore::isScrollbarOverlayAPIAvailable):
(WebCore::recommendedScrollerStyle):

  • platform/mac/ScrollAnimatorMac.h:
  • platform/mac/ScrollAnimatorMac.mm:

(scrollbarPainterForScrollbar):
(WebCore::ScrollAnimatorMac::ScrollAnimatorMac):
(WebCore::ScrollAnimatorMac::~ScrollAnimatorMac):
(WebCore::ScrollAnimatorMac::notifyPositionChanged):
(WebCore::ScrollAnimatorMac::contentAreaWillPaint):
(WebCore::ScrollAnimatorMac::mouseEnteredContentArea):
(WebCore::ScrollAnimatorMac::mouseExitedContentArea):
(WebCore::ScrollAnimatorMac::mouseMovedInContentArea):
(WebCore::ScrollAnimatorMac::mouseEnteredScrollbar):
(WebCore::ScrollAnimatorMac::mouseExitedScrollbar):
(WebCore::ScrollAnimatorMac::willStartLiveResize):
(WebCore::ScrollAnimatorMac::contentsResized):
(WebCore::ScrollAnimatorMac::willEndLiveResize):
(WebCore::ScrollAnimatorMac::contentAreaDidShow):
(WebCore::ScrollAnimatorMac::contentAreaDidHide):
(WebCore::ScrollAnimatorMac::didBeginScrollGesture):
(WebCore::ScrollAnimatorMac::didEndScrollGesture):
(WebCore::ScrollAnimatorMac::didAddVerticalScrollbar):
(WebCore::ScrollAnimatorMac::willRemoveVerticalScrollbar):
(WebCore::ScrollAnimatorMac::didAddHorizontalScrollbar):
(WebCore::ScrollAnimatorMac::willRemoveHorizontalScrollbar):
(WebCore::ScrollAnimatorMac::cancelAnimations):
(WebCore::ScrollAnimatorMac::setIsActive):
(WebCore::ScrollAnimatorMac::updateScrollerStyle):
(WebCore::ScrollAnimatorMac::initialScrollbarPaintTimerFired):

  • platform/mac/ScrollElasticityController.h:
  • platform/mac/ScrollbarThemeMac.h:
  • platform/mac/ScrollbarThemeMac.mm:

(+[WebScrollbarPrefsObserver appearancePrefsChanged:]):
(+[WebScrollbarPrefsObserver behaviorPrefsChanged:]):
(WebCore::updateArrowPlacement):
(WebCore::ScrollbarThemeMac::registerScrollbar):
(WebCore::ScrollbarThemeMac::setIsCurrentlyDrawingIntoLayer):
(WebCore::ScrollbarThemeMac::ScrollbarThemeMac):
(WebCore::ScrollbarThemeMac::scrollbarThickness):
(WebCore::ScrollbarThemeMac::usesOverlayScrollbars):
(WebCore::ScrollbarThemeMac::updateScrollbarOverlayStyle):
(WebCore::ScrollbarThemeMac::hasButtons):
(WebCore::ScrollbarThemeMac::hasThumb):
(WebCore::ScrollbarThemeMac::minimumThumbLength):
(WebCore::ScrollbarThemeMac::scrollbarPartToHIPressedState):
(WebCore::ScrollbarThemeMac::updateEnabledState):
(WebCore::scrollbarPainterPaint):
(WebCore::ScrollbarThemeMac::paint):

Location:
trunk/Source/WebCore
Files:
4 deleted
13 edited
1 copied

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r103290 r103291  
     12011-12-19  Sailesh Agrawal <sail@chromium.org>
     2
     3        Merge ScrollAnimatorChromiumMac.mm back to ScrollAnimatorMac
     4        https://bugs.webkit.org/show_bug.cgi?id=61144
     5
     6        Reviewed by Beth Dakin.
     7
     8        At a high level the main changes are:
     9            - replace #ifdefs in ScrollAnimatorMac and ScrollbarThemeMac with run time checks
     10            - delete duplicate code in ScrollbarThemeChromiumMac. Keep the paint code since it does tickmarks and SKIA stuff.
     11            - delete ScrollAnimatorChromiumMac since ScrollAnimatorMac does the exact same thing
     12            - delete ScrollbarOverlayUtilitiesChromiumMac since NSScrollerImpDetails does the same thing
     13
     14        No new tests. Just refactoring.
     15
     16        * WebCore.gyp/WebCore.gyp:
     17        * WebCore.gypi:
     18        * WebCore.xcodeproj/project.pbxproj:
     19        * platform/chromium/ScrollAnimatorChromiumMac.h: Removed.
     20        * platform/chromium/ScrollAnimatorChromiumMac.mm: Removed.
     21        * platform/chromium/ScrollbarOverlayUtilitiesChromiumMac.h: Removed.
     22        * platform/chromium/ScrollbarOverlayUtilitiesChromiumMac.mm: Removed.
     23        * platform/chromium/ScrollbarThemeChromiumMac.h:
     24        * platform/chromium/ScrollbarThemeChromiumMac.mm:
     25        (WebCore::ScrollbarThemeChromiumMac::ScrollbarThemeChromiumMac):
     26        (WebCore::scrollbarPainterPaintTrack):
     27        (WebCore::ScrollbarThemeChromiumMac::paint):
     28        * platform/mac/EmptyProtocolDefinitions.h:
     29        * platform/mac/NSScrollerImpDetails.h:
     30        (WebCore::isScrollbarOverlayAPIAvailable):
     31        * platform/mac/NSScrollerImpDetails.mm: Added.
     32        (WebCore::isScrollbarOverlayAPIAvailable):
     33        (WebCore::recommendedScrollerStyle):
     34        * platform/mac/ScrollAnimatorMac.h:
     35        * platform/mac/ScrollAnimatorMac.mm:
     36        (scrollbarPainterForScrollbar):
     37        (WebCore::ScrollAnimatorMac::ScrollAnimatorMac):
     38        (WebCore::ScrollAnimatorMac::~ScrollAnimatorMac):
     39        (WebCore::ScrollAnimatorMac::notifyPositionChanged):
     40        (WebCore::ScrollAnimatorMac::contentAreaWillPaint):
     41        (WebCore::ScrollAnimatorMac::mouseEnteredContentArea):
     42        (WebCore::ScrollAnimatorMac::mouseExitedContentArea):
     43        (WebCore::ScrollAnimatorMac::mouseMovedInContentArea):
     44        (WebCore::ScrollAnimatorMac::mouseEnteredScrollbar):
     45        (WebCore::ScrollAnimatorMac::mouseExitedScrollbar):
     46        (WebCore::ScrollAnimatorMac::willStartLiveResize):
     47        (WebCore::ScrollAnimatorMac::contentsResized):
     48        (WebCore::ScrollAnimatorMac::willEndLiveResize):
     49        (WebCore::ScrollAnimatorMac::contentAreaDidShow):
     50        (WebCore::ScrollAnimatorMac::contentAreaDidHide):
     51        (WebCore::ScrollAnimatorMac::didBeginScrollGesture):
     52        (WebCore::ScrollAnimatorMac::didEndScrollGesture):
     53        (WebCore::ScrollAnimatorMac::didAddVerticalScrollbar):
     54        (WebCore::ScrollAnimatorMac::willRemoveVerticalScrollbar):
     55        (WebCore::ScrollAnimatorMac::didAddHorizontalScrollbar):
     56        (WebCore::ScrollAnimatorMac::willRemoveHorizontalScrollbar):
     57        (WebCore::ScrollAnimatorMac::cancelAnimations):
     58        (WebCore::ScrollAnimatorMac::setIsActive):
     59        (WebCore::ScrollAnimatorMac::updateScrollerStyle):
     60        (WebCore::ScrollAnimatorMac::initialScrollbarPaintTimerFired):
     61        * platform/mac/ScrollElasticityController.h:
     62        * platform/mac/ScrollbarThemeMac.h:
     63        * platform/mac/ScrollbarThemeMac.mm:
     64        (+[WebScrollbarPrefsObserver appearancePrefsChanged:]):
     65        (+[WebScrollbarPrefsObserver behaviorPrefsChanged:]):
     66        (WebCore::updateArrowPlacement):
     67        (WebCore::ScrollbarThemeMac::registerScrollbar):
     68        (WebCore::ScrollbarThemeMac::setIsCurrentlyDrawingIntoLayer):
     69        (WebCore::ScrollbarThemeMac::ScrollbarThemeMac):
     70        (WebCore::ScrollbarThemeMac::scrollbarThickness):
     71        (WebCore::ScrollbarThemeMac::usesOverlayScrollbars):
     72        (WebCore::ScrollbarThemeMac::updateScrollbarOverlayStyle):
     73        (WebCore::ScrollbarThemeMac::hasButtons):
     74        (WebCore::ScrollbarThemeMac::hasThumb):
     75        (WebCore::ScrollbarThemeMac::minimumThumbLength):
     76        (WebCore::ScrollbarThemeMac::scrollbarPartToHIPressedState):
     77        (WebCore::ScrollbarThemeMac::updateEnabledState):
     78        (WebCore::scrollbarPainterPaint):
     79        (WebCore::ScrollbarThemeMac::paint):
     80
    1812011-12-19  James Robinson  <jamesr@chromium.org>
    282
  • trunk/Source/WebCore/WebCore.gyp/WebCore.gyp

    r102663 r103291  
    13001300              # com.google.Chrome[] objc[]: Class ScrollbarPrefsObserver is implemented in both .../Google Chrome.app/Contents/Versions/.../Google Chrome Helper.app/Contents/MacOS/../../../Google Chrome Framework.framework/Google Chrome Framework and /System/Library/Frameworks/WebKit.framework/Versions/A/Frameworks/WebCore.framework/Versions/A/WebCore. One of the two will be used. Which one is undefined.
    13011301              'WebCascadeList=ChromiumWebCoreObjCWebCascadeList',
    1302               'ScrollbarPrefsObserver=ChromiumWebCoreObjCScrollbarPrefsObserver',
     1302              'WebScrollbarPrefsObserver=ChromiumWebCoreObjCWebScrollbarPrefsObserver',
    13031303              'WebCoreRenderThemeNotificationObserver=ChromiumWebCoreObjCWebCoreRenderThemeNotificationObserver',
    13041304              'WebFontCache=ChromiumWebCoreObjCWebFontCache',
    1305               'ScrollAnimationHelperDelegate=ChromiumWebCoreObjCScrollAnimationHelperDelegate',
    1306               'ScrollbarPainterControllerDelegate=ChromiumWebCoreObjCScrollbarPainterControllerDelegate',
    1307               'ScrollbarPainterDelegate=ChromiumWebCoreObjCScrollbarPainterDelegate',
    1308               'ScrollbarPartAnimation=ChromiumWebCoreObjCScrollbarPartAnimation',
     1305              'WebScrollAnimationHelperDelegate=ChromiumWebCoreObjCWebScrollAnimationHelperDelegate',
     1306              'WebScrollbarPainterControllerDelegate=ChromiumWebCoreObjCWebScrollbarPainterControllerDelegate',
     1307              'WebScrollbarPainterDelegate=ChromiumWebCoreObjCWebScrollbarPainterDelegate',
     1308              'WebScrollbarPartAnimation=ChromiumWebCoreObjCWebScrollbarPartAnimation',
    13091309            ],
    13101310            'include_dirs': [
     
    15661566            ['include', 'platform/mac/KillRingMac\\.mm$'],
    15671567            ['include', 'platform/mac/LocalCurrentGraphicsContext\\.mm$'],
     1568            ['include', 'platform/mac/NSScrollerImpDetails\\.mm$'],
    15681569            ['include', 'platform/mac/PurgeableBufferMac\\.cpp$'],
     1570            ['include', 'platform/mac/ScrollbarThemeMac\\.mm$'],
     1571            ['include', 'platform/mac/ScrollAnimatorMac\\.mm$'],
     1572            ['include', 'platform/mac/ScrollElasticityController\\.mm$'],
    15691573            ['include', 'platform/mac/WebCoreSystemInterface\\.mm$'],
    15701574            ['include', 'platform/mac/WebCoreTextRenderer\\.mm$'],
  • trunk/Source/WebCore/WebCore.gypi

    r103274 r103291  
    33093309            'platform/chromium/PopupMenuPrivate.h',
    33103310            'platform/chromium/SSLKeyGeneratorChromium.cpp',
    3311             'platform/chromium/ScrollAnimatorChromiumMac.h',
    3312             'platform/chromium/ScrollAnimatorChromiumMac.mm',
    3313             'platform/chromium/ScrollbarOverlayUtilitiesChromiumMac.h',
    3314             'platform/chromium/ScrollbarOverlayUtilitiesChromiumMac.mm',
    33153311            'platform/chromium/ScrollbarThemeChromium.cpp',
    33163312            'platform/chromium/ScrollbarThemeChromium.h',
     
    41564152            'platform/mac/LoggingMac.mm',
    41574153            'platform/mac/MIMETypeRegistryMac.mm',
     4154            'platform/mac/NSScrollerImpDetails.h',
     4155            'platform/mac/NSScrollerImpDetails.mm',
    41584156            'platform/mac/PasteboardHelper.h',
    41594157            'platform/mac/PasteboardMac.mm',
     
    41674165            'platform/mac/ScrollAnimatorMac.h',
    41684166            'platform/mac/ScrollAnimatorMac.mm',
     4167            'platform/mac/ScrollElasticityController.h',
     4168            'platform/mac/ScrollElasticityController.mm',
    41694169            'platform/mac/ScrollViewMac.mm',
    41704170            'platform/mac/ScrollbarThemeMac.h',
  • trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj

    r103274 r103291  
    15521552                521D46F611AEC98100514613 /* KillRingMac.mm in Sources */ = {isa = PBXBuildFile; fileRef = 521D46F511AEC98100514613 /* KillRingMac.mm */; };
    15531553                521D46F811AEC9B100514613 /* KillRing.h in Headers */ = {isa = PBXBuildFile; fileRef = 521D46F711AEC9B100514613 /* KillRing.h */; };
     1554                52F52E1114A0134F00ACC397 /* NSScrollerImpDetails.mm in Sources */ = {isa = PBXBuildFile; fileRef = 52F52E1014A0134F00ACC397 /* NSScrollerImpDetails.mm */; };
    15541555                5317612213C516690026E454 /* StyleFlexibleBoxData.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 5317612013C516690026E454 /* StyleFlexibleBoxData.cpp */; };
    15551556                5317612313C516690026E454 /* StyleFlexibleBoxData.h in Headers */ = {isa = PBXBuildFile; fileRef = 5317612113C516690026E454 /* StyleFlexibleBoxData.h */; settings = {ATTRIBUTES = (Private, ); }; };
     
    88248825                521D46F511AEC98100514613 /* KillRingMac.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = KillRingMac.mm; sourceTree = "<group>"; };
    88258826                521D46F711AEC9B100514613 /* KillRing.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = KillRing.h; sourceTree = "<group>"; };
     8827                52F52E1014A0134F00ACC397 /* NSScrollerImpDetails.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = NSScrollerImpDetails.mm; sourceTree = "<group>"; };
    88268828                5317612013C516690026E454 /* StyleFlexibleBoxData.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = StyleFlexibleBoxData.cpp; path = style/StyleFlexibleBoxData.cpp; sourceTree = "<group>"; };
    88278829                5317612113C516690026E454 /* StyleFlexibleBoxData.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = StyleFlexibleBoxData.h; path = style/StyleFlexibleBoxData.h; sourceTree = "<group>"; };
     
    1560215604                                BC772C5D0C4EB3440083285F /* MIMETypeRegistryMac.mm */,
    1560315605                                93500F3113FDE3BE0099EC24 /* NSScrollerImpDetails.h */,
     15606                                52F52E1014A0134F00ACC397 /* NSScrollerImpDetails.mm */,
    1560415607                                A7D3C5230B576B4B002CA450 /* PasteboardHelper.h */,
    1560515608                                4B2709810AF2E5E00065127F /* PasteboardMac.mm */,
     
    2785127854                                A80A9423149F225E00989291 /* JSDOMWindowWebAudioCustom.cpp in Sources */,
    2785227855                                A80A9425149F227100989291 /* JSDOMWindowWebSocketCustom.cpp in Sources */,
     27856                                52F52E1114A0134F00ACC397 /* NSScrollerImpDetails.mm in Sources */,
    2785327857                        );
    2785427858                        runOnlyForDeploymentPostprocessing = 0;
  • trunk/Source/WebCore/platform/chromium/ScrollbarThemeChromiumMac.h

    r95901 r103291  
    2828#define ScrollbarThemeChromiumMac_h
    2929
    30 #include "ScrollbarOverlayUtilitiesChromiumMac.h"
    31 #include "ScrollbarThemeComposite.h"
    32 
    33 // This file (and its associated .mm file) is a clone of ScrollbarThemeMac.h.
    34 // See the .mm file for details.
     30#include "ScrollbarThemeMac.h"
    3531
    3632namespace WebCore {
    3733
    38 class ScrollbarThemeChromiumMac : public ScrollbarThemeComposite {
     34class ScrollbarThemeChromiumMac : public ScrollbarThemeMac {
    3935public:
    4036    ScrollbarThemeChromiumMac();
    4137    virtual ~ScrollbarThemeChromiumMac();
    4238
    43     void preferencesChanged();
    44 
    45     virtual void updateEnabledState(Scrollbar*);
    46 
    4739    virtual bool paint(Scrollbar*, GraphicsContext* context, const IntRect& damageRect);
    48 
    49     virtual int scrollbarThickness(ScrollbarControlSize = RegularScrollbar);
    50 
    51     virtual bool supportsControlTints() const { return true; }
    52     virtual bool usesOverlayScrollbars() const;
    53     virtual void updateScrollbarOverlayStyle(Scrollbar*);
    54 
    55     virtual double initialAutoscrollTimerDelay();
    56     virtual double autoscrollTimerDelay();
    57 
    58     virtual ScrollbarButtonsPlacement buttonsPlacement() const;
    59 
    60     virtual void registerScrollbar(Scrollbar*);
    61     virtual void unregisterScrollbar(Scrollbar*);
    62 
    63     void setNewPainterForScrollbar(Scrollbar*, WKScrollbarPainterRef);
    64     WKScrollbarPainterRef painterForScrollbar(Scrollbar*);
    6540
    6641    virtual void paintOverhangAreas(ScrollView*, GraphicsContext*, const IntRect& horizontalOverhangArea, const IntRect& verticalOverhangArea, const IntRect& dirtyRect);
    6742   
    68 protected:
    69     virtual bool hasButtons(Scrollbar*);
    70     virtual bool hasThumb(Scrollbar*);
    71 
    72     virtual IntRect backButtonRect(Scrollbar*, ScrollbarPart, bool painting = false);
    73     virtual IntRect forwardButtonRect(Scrollbar*, ScrollbarPart, bool painting = false);
    74     virtual IntRect trackRect(Scrollbar*, bool painting = false);
    75 
    76     virtual int maxOverlapBetweenPages() { return 40; }
    77 
    78     virtual int minimumThumbLength(Scrollbar*);
    79 
    80     virtual bool shouldCenterOnThumb(Scrollbar*, const PlatformMouseEvent&);
    81     virtual bool shouldDragDocumentInsteadOfThumb(Scrollbar*, const PlatformMouseEvent&);
    82 
    8343private:
    8444    void paintGivenTickmarks(GraphicsContext*, Scrollbar*, const IntRect&, const Vector<IntRect>&);
    8545
    86 private:
    8746    RefPtr<Pattern> m_overhangPattern;
    8847};
  • trunk/Source/WebCore/platform/chromium/ScrollbarThemeChromiumMac.mm

    r97237 r103291  
    2828#include "ScrollbarThemeChromiumMac.h"
    2929
    30 #include "BitmapImage.h"
    3130#include "FrameView.h"
    3231#include "Gradient.h"
    3332#include "ImageBuffer.h"
    3433#include "LocalCurrentGraphicsContext.h"
    35 #include "PlatformMouseEvent.h"
     34#include "NSScrollerImpDetails.h"
    3635#include "PlatformSupport.h"
    37 #include "ScrollAnimatorChromiumMac.h"
     36#include "ScrollAnimatorMac.h"
    3837#include "ScrollView.h"
    3938#include <Carbon/Carbon.h>
    40 #include <wtf/HashMap.h>
    41 #include <wtf/StdLibExtras.h>
    42 #include <wtf/UnusedParam.h>
    4339
    4440#if USE(SKIA)
     
    4743#endif
    4844
    49 
    50 
    51 // FIXME: There are repainting problems due to Aqua scroll bar buttons' visual overflow.
    52 
    53 using namespace std;
    54 using namespace WebCore;
    55 
    56 // This file (and its associated .h file) is a clone of ScrollbarThemeMac.mm.
    57 // Because we want to draw tickmarks in the scrollbar, we must maintain a fork.
    58 // Please maintain this file by performing parallel changes to it.
    59 //
    60 // The only changes from ScrollbarThemeMac should be:
    61 // - The classname change from ScrollbarThemeMac to ScrollbarThemeChromiumMac.
    62 // - In paint() the code to paint the track, tickmarks, and thumb separately.
    63 // - In paint() the thumb is drawn via ChromeBridge/WebThemeEngine.
    64 // - Various functions that were split using #if USE(WK_SCROLLBAR_PAINTER)
    65 //   have been combined using runtime checks instead.
    66 //
    67 // For all other differences, if it was introduced in this file, then the
    68 // maintainer forgot to include it in the list; otherwise it is an update that
    69 // should have been applied to this file but was not.
    70 
    71 namespace WebCore {
    72 
    73 typedef HashMap<Scrollbar*, RetainPtr<WKScrollbarPainterRef> > ScrollbarPainterMap;
    74 
    75 static ScrollbarPainterMap* scrollbarMap()
    76 {
    77     static ScrollbarPainterMap* map = new ScrollbarPainterMap;
    78     return map;
    79 }
    80 
    81 }
    82 
    83 @interface ScrollbarPrefsObserver : NSObject
    84 {
    85 }
    86 
    87 + (void)registerAsObserver;
    88 + (void)appearancePrefsChanged:(NSNotification*)theNotification;
    89 + (void)behaviorPrefsChanged:(NSNotification*)theNotification;
    90 
    91 @end
    92 
    93 @implementation ScrollbarPrefsObserver
    94 
    95 + (void)appearancePrefsChanged:(NSNotification*)unusedNotification
    96 {
    97     UNUSED_PARAM(unusedNotification);
    98 
    99     ScrollbarTheme* theme = ScrollbarTheme::theme();
    100     if (theme->isMockTheme())
    101         return;
    102 
    103     static_cast<ScrollbarThemeChromiumMac*>(theme)->preferencesChanged();
    104     if (scrollbarMap()->isEmpty())
    105         return;
    106     ScrollbarPainterMap::iterator end = scrollbarMap()->end();
    107     for (ScrollbarPainterMap::iterator it = scrollbarMap()->begin(); it != end; ++it) {
    108         it->first->styleChanged();
    109         it->first->invalidate();
    110     }
    111 }
    112 
    113 + (void)behaviorPrefsChanged:(NSNotification*)unusedNotification
    114 {
    115     UNUSED_PARAM(unusedNotification);
    116 
    117     ScrollbarTheme* theme = ScrollbarTheme::theme();
    118     if (theme->isMockTheme())
    119         return;
    120 
    121     static_cast<ScrollbarThemeChromiumMac*>(theme)->preferencesChanged();
    122 }
    123 
    124 + (void)registerAsObserver
    125 {
    126     [[NSDistributedNotificationCenter defaultCenter] addObserver:self selector:@selector(appearancePrefsChanged:) name:@"AppleAquaScrollBarVariantChanged" object:nil suspensionBehavior:NSNotificationSuspensionBehaviorDeliverImmediately];
    127     [[NSDistributedNotificationCenter defaultCenter] addObserver:self selector:@selector(behaviorPrefsChanged:) name:@"AppleNoRedisplayAppearancePreferenceChanged" object:nil suspensionBehavior:NSNotificationSuspensionBehaviorCoalesce];
    128 }
    129 
    130 @end
    131 
    13245namespace WebCore {
    13346
     
    13851}
    13952
    140 // FIXME: Get these numbers from CoreUI.
    141 static int cScrollbarThickness[] = { 15, 11 };
    142 static int cRealButtonLength[] = { 28, 21 };
    143 static int cButtonInset[] = { 14, 11 };
    144 static int cButtonHitInset[] = { 3, 2 };
    145 // cRealButtonLength - cButtonInset
    146 static int cButtonLength[] = { 14, 10 };
    147 static int cThumbMinLength[] = { 26, 20 };
    148 
    149 static int cOuterButtonLength[] = { 16, 14 }; // The outer button in a double button pair is a bit bigger.
    150 static int cOuterButtonOverlap = 2;
    151 
    152 static float gInitialButtonDelay = 0.5f;
    153 static float gAutoscrollButtonDelay = 0.05f;
    154 static bool gJumpOnTrackClick = false;
    155 static ScrollbarButtonsPlacement gButtonPlacement = isScrollbarOverlayAPIAvailable() ? ScrollbarButtonsNone : ScrollbarButtonsDoubleEnd;
    156 
    157 static void updateArrowPlacement()
    158 {
    159     if (isScrollbarOverlayAPIAvailable())
    160         return;
    161 
    162     NSString *buttonPlacement = [[NSUserDefaults standardUserDefaults] objectForKey:@"AppleScrollBarVariant"];
    163     if ([buttonPlacement isEqualToString:@"Single"])
    164         gButtonPlacement = ScrollbarButtonsSingle;
    165     else if ([buttonPlacement isEqualToString:@"DoubleMin"])
    166         gButtonPlacement = ScrollbarButtonsDoubleStart;
    167     else if ([buttonPlacement isEqualToString:@"DoubleBoth"])
    168         gButtonPlacement = ScrollbarButtonsDoubleBoth;
    169     else
    170         gButtonPlacement = ScrollbarButtonsDoubleEnd;
    171 }
    172 
    173 void ScrollbarThemeChromiumMac::registerScrollbar(Scrollbar* scrollbar)
    174 {
    175     bool isHorizontal = scrollbar->orientation() == HorizontalScrollbar;
    176     WKScrollbarPainterRef scrollbarPainter = wkMakeScrollbarPainter(scrollbar->controlSize(), isHorizontal);
    177     scrollbarMap()->add(scrollbar, scrollbarPainter);
    178     updateEnabledState(scrollbar);
    179     updateScrollbarOverlayStyle(scrollbar);
    180 }
    181 
    182 void ScrollbarThemeChromiumMac::unregisterScrollbar(Scrollbar* scrollbar)
    183 {
    184     scrollbarMap()->remove(scrollbar);
    185 }
    186 
    187 void ScrollbarThemeChromiumMac::setNewPainterForScrollbar(Scrollbar* scrollbar, WKScrollbarPainterRef newPainter)
    188 {
    189     scrollbarMap()->set(scrollbar, newPainter);
    190     updateEnabledState(scrollbar);
    191     updateScrollbarOverlayStyle(scrollbar);
    192 }
    193 
    194 WKScrollbarPainterRef ScrollbarThemeChromiumMac::painterForScrollbar(Scrollbar* scrollbar)
    195 {
    196     return scrollbarMap()->get(scrollbar).get();
    197 }
    198 
    19953ScrollbarThemeChromiumMac::ScrollbarThemeChromiumMac()
    20054{
    201     static bool initialized;
    202     if (!initialized) {
    203         initialized = true;
    204 
    205         // Load the linen pattern image used for overhang drawing.
    206         RefPtr<Image> patternImage = Image::loadPlatformResource("overhangPattern");
    207         m_overhangPattern = Pattern::create(patternImage, true, true);
    208 
    209         [ScrollbarPrefsObserver registerAsObserver];
    210         preferencesChanged();
    211     }
     55    // Load the linen pattern image used for overhang drawing.
     56    RefPtr<Image> patternImage = Image::loadPlatformResource("overhangPattern");
     57    m_overhangPattern = Pattern::create(patternImage, true, true);
    21258}
    21359
    21460ScrollbarThemeChromiumMac::~ScrollbarThemeChromiumMac()
    21561{
    216 }
    217 
    218 void ScrollbarThemeChromiumMac::preferencesChanged()
    219 {
    220     NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
    221     [defaults synchronize];
    222     updateArrowPlacement();
    223     gInitialButtonDelay = [defaults floatForKey:@"NSScrollerButtonDelay"];
    224     gAutoscrollButtonDelay = [defaults floatForKey:@"NSScrollerButtonPeriod"];
    225     gJumpOnTrackClick = [defaults boolForKey:@"AppleScrollerPagingBehavior"];
    226 }
    227 
    228 int ScrollbarThemeChromiumMac::scrollbarThickness(ScrollbarControlSize controlSize)
    229 {
    230     if (isScrollbarOverlayAPIAvailable())
    231         return wkScrollbarThickness(controlSize);
    232     else
    233         return cScrollbarThickness[controlSize];
    234 }
    235 
    236 bool ScrollbarThemeChromiumMac::usesOverlayScrollbars() const
    237 {
    238     if (isScrollbarOverlayAPIAvailable())
    239         return wkScrollbarPainterUsesOverlayScrollers();
    240     else
    241         return false;
    242 }
    243 
    244 static inline wkScrollerKnobStyle toScrollbarPainterKnobStyle(ScrollbarOverlayStyle style)
    245 {
    246     switch (style) {
    247     case ScrollbarOverlayStyleDark:
    248         return wkScrollerKnobStyleDark;
    249     case ScrollbarOverlayStyleLight:
    250         return wkScrollerKnobStyleLight;
    251     default:
    252         return wkScrollerKnobStyleDefault;
    253     }
    254 }
    255 
    256 void ScrollbarThemeChromiumMac::updateScrollbarOverlayStyle(Scrollbar* scrollbar)
    257 {
    258     if (isScrollbarOverlayAPIAvailable()) {
    259         wkSetScrollbarPainterKnobStyle(painterForScrollbar(scrollbar), toScrollbarPainterKnobStyle(scrollbar->scrollableArea()->scrollbarOverlayStyle()));
    260     }
    261 }
    262 
    263 double ScrollbarThemeChromiumMac::initialAutoscrollTimerDelay()
    264 {
    265     return gInitialButtonDelay;
    266 }
    267 
    268 double ScrollbarThemeChromiumMac::autoscrollTimerDelay()
    269 {
    270     return gAutoscrollButtonDelay;
    271 }
    272 
    273 ScrollbarButtonsPlacement ScrollbarThemeChromiumMac::buttonsPlacement() const
    274 {
    275     return gButtonPlacement;
    276 }
    277 
    278 bool ScrollbarThemeChromiumMac::hasButtons(Scrollbar* scrollbar)
    279 {
    280     return scrollbar->enabled() && gButtonPlacement != ScrollbarButtonsNone
    281              && (scrollbar->orientation() == HorizontalScrollbar
    282              ? scrollbar->width()
    283              : scrollbar->height()) >= 2 * (cRealButtonLength[scrollbar->controlSize()] - cButtonHitInset[scrollbar->controlSize()]);
    284 }
    285 
    286 bool ScrollbarThemeChromiumMac::hasThumb(Scrollbar* scrollbar)
    287 {
    288     int minLengthForThumb;
    289     if (isScrollbarOverlayAPIAvailable())
    290         minLengthForThumb = wkScrollbarMinimumTotalLengthNeededForThumb(scrollbarMap()->get(scrollbar).get());
    291     else
    292         minLengthForThumb = 2 * cButtonInset[scrollbar->controlSize()] + cThumbMinLength[scrollbar->controlSize()] + 1;
    293     return scrollbar->enabled() && (scrollbar->orientation() == HorizontalScrollbar ?
    294              scrollbar->width() :
    295              scrollbar->height()) >= minLengthForThumb;
    296 }
    297 
    298 static IntRect buttonRepaintRect(const IntRect& buttonRect, ScrollbarOrientation orientation, ScrollbarControlSize controlSize, bool start)
    299 {
    300     ASSERT(gButtonPlacement != ScrollbarButtonsNone);
    301 
    302     IntRect paintRect(buttonRect);
    303     if (orientation == HorizontalScrollbar) {
    304         paintRect.setWidth(cRealButtonLength[controlSize]);
    305         if (!start)
    306             paintRect.setX(buttonRect.x() - (cRealButtonLength[controlSize] - buttonRect.width()));
    307     } else {
    308         paintRect.setHeight(cRealButtonLength[controlSize]);
    309         if (!start)
    310             paintRect.setY(buttonRect.y() - (cRealButtonLength[controlSize] - buttonRect.height()));
    311     }
    312 
    313     return paintRect;
    314 }
    315 
    316 IntRect ScrollbarThemeChromiumMac::backButtonRect(Scrollbar* scrollbar, ScrollbarPart part, bool painting)
    317 {
    318     IntRect result;
    319 
    320     if (part == BackButtonStartPart && (buttonsPlacement() == ScrollbarButtonsNone || buttonsPlacement() == ScrollbarButtonsDoubleEnd))
    321         return result;
    322 
    323     if (part == BackButtonEndPart && (buttonsPlacement() == ScrollbarButtonsNone || buttonsPlacement() == ScrollbarButtonsDoubleStart || buttonsPlacement() == ScrollbarButtonsSingle))
    324         return result;
    325 
    326     int thickness = scrollbarThickness(scrollbar->controlSize());
    327     bool outerButton = part == BackButtonStartPart && (buttonsPlacement() == ScrollbarButtonsDoubleStart || buttonsPlacement() == ScrollbarButtonsDoubleBoth);
    328     if (outerButton) {
    329         if (scrollbar->orientation() == HorizontalScrollbar)
    330             result = IntRect(scrollbar->x(), scrollbar->y(), cOuterButtonLength[scrollbar->controlSize()] + (painting ? cOuterButtonOverlap : 0), thickness);
    331         else
    332             result = IntRect(scrollbar->x(), scrollbar->y(), thickness, cOuterButtonLength[scrollbar->controlSize()] + (painting ? cOuterButtonOverlap : 0));
    333         return result;
    334     }
    335 
    336     // Our repaint rect is slightly larger, since we are a button that is adjacent to the track.
    337     if (scrollbar->orientation() == HorizontalScrollbar) {
    338         int start = part == BackButtonStartPart ? scrollbar->x() : scrollbar->x() + scrollbar->width() - cOuterButtonLength[scrollbar->controlSize()] - cButtonLength[scrollbar->controlSize()];
    339         result = IntRect(start, scrollbar->y(), cButtonLength[scrollbar->controlSize()], thickness);
    340     } else {
    341         int start = part == BackButtonStartPart ? scrollbar->y() : scrollbar->y() + scrollbar->height() - cOuterButtonLength[scrollbar->controlSize()] - cButtonLength[scrollbar->controlSize()];
    342         result = IntRect(scrollbar->x(), start, thickness, cButtonLength[scrollbar->controlSize()]);
    343     }
    344 
    345     if (painting)
    346         return buttonRepaintRect(result, scrollbar->orientation(), scrollbar->controlSize(), part == BackButtonStartPart);
    347     return result;
    348 }
    349 
    350 IntRect ScrollbarThemeChromiumMac::forwardButtonRect(Scrollbar* scrollbar, ScrollbarPart part, bool painting)
    351 {
    352     IntRect result;
    353 
    354     if (part == ForwardButtonEndPart && (buttonsPlacement() == ScrollbarButtonsNone || buttonsPlacement() == ScrollbarButtonsDoubleStart))
    355         return result;
    356 
    357     if (part == ForwardButtonStartPart && (buttonsPlacement() == ScrollbarButtonsNone || buttonsPlacement() == ScrollbarButtonsDoubleEnd || buttonsPlacement() == ScrollbarButtonsSingle))
    358         return result;
    359 
    360     int thickness = scrollbarThickness(scrollbar->controlSize());
    361     int outerButtonLength = cOuterButtonLength[scrollbar->controlSize()];
    362     int buttonLength = cButtonLength[scrollbar->controlSize()];
    363 
    364     bool outerButton = part == ForwardButtonEndPart && (buttonsPlacement() == ScrollbarButtonsDoubleEnd || buttonsPlacement() == ScrollbarButtonsDoubleBoth);
    365     if (outerButton) {
    366         if (scrollbar->orientation() == HorizontalScrollbar) {
    367             result = IntRect(scrollbar->x() + scrollbar->width() - outerButtonLength, scrollbar->y(), outerButtonLength, thickness);
    368             if (painting)
    369                 result.inflateX(cOuterButtonOverlap);
    370         } else {
    371             result = IntRect(scrollbar->x(), scrollbar->y() + scrollbar->height() - outerButtonLength, thickness, outerButtonLength);
    372             if (painting)
    373                 result.inflateY(cOuterButtonOverlap);
    374         }
    375         return result;
    376     }
    377 
    378     if (scrollbar->orientation() == HorizontalScrollbar) {
    379         int start = part == ForwardButtonEndPart ? scrollbar->x() + scrollbar->width() - buttonLength : scrollbar->x() + outerButtonLength;
    380         result = IntRect(start, scrollbar->y(), buttonLength, thickness);
    381     } else {
    382         int start = part == ForwardButtonEndPart ? scrollbar->y() + scrollbar->height() - buttonLength : scrollbar->y() + outerButtonLength;
    383         result = IntRect(scrollbar->x(), start, thickness, buttonLength);
    384     }
    385     if (painting)
    386         return buttonRepaintRect(result, scrollbar->orientation(), scrollbar->controlSize(), part == ForwardButtonStartPart);
    387     return result;
    388 }
    389 
    390 IntRect ScrollbarThemeChromiumMac::trackRect(Scrollbar* scrollbar, bool painting)
    391 {
    392     if (painting || !hasButtons(scrollbar))
    393         return scrollbar->frameRect();
    394 
    395     IntRect result;
    396     int thickness = scrollbarThickness(scrollbar->controlSize());
    397     int startWidth = 0;
    398     int endWidth = 0;
    399     int outerButtonLength = cOuterButtonLength[scrollbar->controlSize()];
    400     int buttonLength = cButtonLength[scrollbar->controlSize()];
    401     int doubleButtonLength = outerButtonLength + buttonLength;
    402     switch (buttonsPlacement()) {
    403         case ScrollbarButtonsSingle:
    404             startWidth = buttonLength;
    405             endWidth = buttonLength;
    406             break;
    407         case ScrollbarButtonsDoubleStart:
    408             startWidth = doubleButtonLength;
    409             break;
    410         case ScrollbarButtonsDoubleEnd:
    411             endWidth = doubleButtonLength;
    412             break;
    413         case ScrollbarButtonsDoubleBoth:
    414             startWidth = doubleButtonLength;
    415             endWidth = doubleButtonLength;
    416             break;
    417         default:
    418             break;
    419     }
    420 
    421     int totalWidth = startWidth + endWidth;
    422     if (scrollbar->orientation() == HorizontalScrollbar)
    423         return IntRect(scrollbar->x() + startWidth, scrollbar->y(), scrollbar->width() - totalWidth, thickness);
    424     return IntRect(scrollbar->x(), scrollbar->y() + startWidth, thickness, scrollbar->height() - totalWidth);
    425 }
    426 
    427 int ScrollbarThemeChromiumMac::minimumThumbLength(Scrollbar* scrollbar)
    428 {
    429     if (isScrollbarOverlayAPIAvailable())
    430         return wkScrollbarMinimumThumbLength(scrollbarMap()->get(scrollbar).get());
    431     else
    432         return cThumbMinLength[scrollbar->controlSize()];
    433 }
    434 
    435 bool ScrollbarThemeChromiumMac::shouldCenterOnThumb(Scrollbar*, const PlatformMouseEvent& evt)
    436 {
    437     if (evt.button() != LeftButton)
    438         return false;
    439     if (gJumpOnTrackClick)
    440         return !evt.altKey();
    441     return evt.altKey();
    442 }
    443 
    444 bool ScrollbarThemeChromiumMac::shouldDragDocumentInsteadOfThumb(Scrollbar*, const PlatformMouseEvent& event)
    445 {
    446     return event.altKey();
    447 }
    448 
    449 static int scrollbarPartToHIPressedState(ScrollbarPart part)
    450 {
    451     switch (part) {
    452         case BackButtonStartPart:
    453             return kThemeTopOutsideArrowPressed;
    454         case BackButtonEndPart:
    455             return kThemeTopOutsideArrowPressed; // This does not make much sense.  For some reason the outside constant is required.
    456         case ForwardButtonStartPart:
    457             return kThemeTopInsideArrowPressed;
    458         case ForwardButtonEndPart:
    459             return kThemeBottomOutsideArrowPressed;
    460         case ThumbPart:
    461             return kThemeThumbPressed;
    462         default:
    463             return 0;
    464     }
    46562}
    46663
     
    47774}
    47875
    479 void ScrollbarThemeChromiumMac::updateEnabledState(Scrollbar* scrollbar)
    480 {
    481     if (isScrollbarOverlayAPIAvailable()) {
    482         wkScrollbarPainterSetEnabled(scrollbarMap()->get(scrollbar).get(), scrollbar->enabled());
    483     }
    484 }
    485 
     76static void scrollbarPainterPaintTrack(ScrollbarPainter scrollbarPainter, bool enabled, double value, CGFloat proportion, CGRect frameRect)
     77{
     78    [scrollbarPainter setEnabled:enabled];
     79    [scrollbarPainter setBoundsSize: NSSizeFromCGSize(frameRect.size)];
     80    [scrollbarPainter setDoubleValue:value];
     81    [scrollbarPainter setKnobProportion:proportion];
     82
     83    // The scrollbar's frameRect includes a side inset for overlay scrollers, so we have to use the
     84    // trackWidth for drawKnobSlotInRect
     85    NSRect trackRect;
     86    if ([scrollbarPainter isHorizontal])
     87        trackRect = NSMakeRect(0, 0, frameRect.size.width, [scrollbarPainter trackWidth]);
     88    else
     89        trackRect = NSMakeRect(0, 0, [scrollbarPainter trackWidth], frameRect.size.height);
     90    [scrollbarPainter drawKnobSlotInRect:trackRect highlight:NO];
     91}
     92
     93// Override ScrollbarThemeMac::paint() to add support for the following:
     94//     - drawing using PlatformSupport functions
     95//     - drawing tickmarks
     96//     - Skia specific changes
    48697bool ScrollbarThemeChromiumMac::paint(Scrollbar* scrollbar, GraphicsContext* context, const IntRect& damageRect)
    48798{
     
    511122        }
    512123
    513         ScrollAnimatorChromiumMac* scrollAnimator = static_cast<ScrollAnimatorChromiumMac*>(scrollbar->scrollableArea()->scrollAnimator());
    514124#if !USE(SKIA)
    515         scrollAnimator->setIsDrawingIntoLayer(context->isCALayerContext());
     125        setIsCurrentlyDrawingIntoLayer(context->isCALayerContext());
    516126#else
    517         scrollAnimator->setIsDrawingIntoLayer(false);
     127        setIsCurrentlyDrawingIntoLayer(false);
    518128#endif
    519129
     
    521131        CGFloat oldTrackAlpha = 0;
    522132        bool hasTickmarks = tickmarks.size() > 0 && scrollbar->orientation() == VerticalScrollbar;
     133        ScrollbarPainter scrollbarPainter = painterForScrollbar(scrollbar);
    523134        if (hasTickmarks) {
    524           oldKnobAlpha = wkScrollbarPainterKnobAlpha(painterForScrollbar(scrollbar));
    525           wkSetScrollbarPainterKnobAlpha(painterForScrollbar(scrollbar), 1.0);
    526           oldTrackAlpha = wkScrollbarPainterTrackAlpha(painterForScrollbar(scrollbar));
    527           wkSetScrollbarPainterTrackAlpha(painterForScrollbar(scrollbar), 1.0);
     135            oldKnobAlpha = [scrollbarPainter knobAlpha];
     136            [scrollbarPainter setKnobAlpha:1.0];
     137            oldTrackAlpha = [scrollbarPainter trackAlpha];
     138            [scrollbarPainter setTrackAlpha:1.0];
    528139        }
    529140
     
    532143        context->translate(scrollbar->frameRect().x(), scrollbar->frameRect().y());
    533144        LocalCurrentGraphicsContext localContext(context);
    534         WKScrollbarPainterRef scrollbarPainter = scrollbarMap()->get(scrollbar).get();
    535         wkScrollbarPainterPaintTrack(scrollbarPainter,
    536                                      scrollbar->enabled(),
    537                                      value,
    538                                      (static_cast<CGFloat>(scrollbar->visibleSize()) - overhang) / scrollbar->totalSize(),
    539                                      scrollbar->frameRect());
     145        scrollbarPainterPaintTrack(scrollbarPainter,
     146                                   scrollbar->enabled(),
     147                                   value,
     148                                   (static_cast<CGFloat>(scrollbar->visibleSize()) - overhang) / scrollbar->totalSize(),
     149                                   scrollbar->frameRect());
    540150
    541151        IntRect tickmarkTrackRect(IntPoint(), trackRect(scrollbar, false).size());
     
    551161        paintGivenTickmarks(context, scrollbar, tickmarkTrackRect, tickmarks);
    552162
    553         wkScrollbarPainterPaintKnob(scrollbarPainter);
    554 
    555         scrollAnimator->setIsDrawingIntoLayer(false);
     163        if (scrollbar->enabled())
     164            [scrollbarPainter drawKnob];
     165
     166        setIsCurrentlyDrawingIntoLayer(false);
    556167
    557168        if (hasTickmarks) {
    558           wkSetScrollbarPainterKnobAlpha(scrollbarPainter, oldKnobAlpha);
    559           wkSetScrollbarPainterTrackAlpha(scrollbarPainter, oldTrackAlpha);
     169            [scrollbarPainter setKnobAlpha:oldKnobAlpha];
     170            [scrollbarPainter setTrackAlpha:oldTrackAlpha];
    560171        }
    561172
  • trunk/Source/WebCore/platform/mac/EmptyProtocolDefinitions.h

    r95901 r103291  
    3535EMPTY_PROTOCOL(NSTableViewDelegate)
    3636EMPTY_PROTOCOL(NSWindowDelegate)
     37EMPTY_PROTOCOL(NSAnimationDelegate)
    3738
    3839#endif
  • trunk/Source/WebCore/platform/mac/NSScrollerImpDetails.h

    r99493 r103291  
    2929#include "config.h"
    3030
    31 #if USE(SCROLLBAR_PAINTER)
     31// Public APIs not available on versions of Mac on which we build
     32#if (defined(BUILDING_ON_LEOPARD) || defined(BUILDING_ON_SNOW_LEOPARD))
     33enum {
     34    NSScrollerStyleLegacy       = 0,
     35    NSScrollerStyleOverlay      = 1
     36};
     37typedef NSInteger NSScrollerStyle;
     38
     39enum {
     40    NSScrollerKnobStyleDefault = 0,
     41    NSScrollerKnobStyleDark = 1,
     42    NSScrollerKnobStyleLight = 2
     43};
     44typedef NSInteger NSScrollerKnobStyle;
     45#endif
     46
     47#if (defined(BUILDING_ON_LEOPARD) || defined(BUILDING_ON_SNOW_LEOPARD))
     48@interface NSScroller(NSObject)
     49+ (NSScrollerStyle)preferredScrollerStyle;
     50@end
     51#endif
     52
    3253@interface NSObject (ScrollbarPainter)
    3354+ (id)scrollerImpWithStyle:(NSScrollerStyle)newScrollerStyle controlSize:(NSControlSize)newControlSize horizontal:(BOOL)horizontal replacingScrollerImp:(id)previous;
     
    82103- (void)endScrollGesture;
    83104@end
     105
     106namespace WebCore {
     107
     108#if PLATFORM(CHROMIUM)
     109bool isScrollbarOverlayAPIAvailable();
     110#else
     111static inline bool isScrollbarOverlayAPIAvailable()
     112{
     113#if USE(SCROLLBAR_PAINTER)
     114    return true;
     115#else
     116    return false;
     117#endif
     118}
    84119#endif
    85120
     121NSScrollerStyle recommendedScrollerStyle();
     122
     123}
     124
    86125#endif
  • trunk/Source/WebCore/platform/mac/NSScrollerImpDetails.mm

    r103290 r103291  
    11/*
    2  * Copyright (C) 2008, 2010 Apple Inc. All rights reserved.
     2 * Copyright (C) 2011 Apple Inc. All Rights Reserved.
     3 * Copyright (C) 2011 Google Inc. All Rights Reserved.
    34 *
    45 * Redistribution and use in source and binary forms, with or without
     
    2425 */
    2526
    26 #if defined(__OBJC__)
    2727
    28 #define EMPTY_PROTOCOL(NAME) \
    29 @protocol NAME <NSObject> \
    30 @end
     28#include "config.h"
     29#include "NSScrollerImpDetails.h"
    3130
    32 #ifdef BUILDING_ON_LEOPARD
     31namespace WebCore {
    3332
    34 EMPTY_PROTOCOL(NSTableViewDataSource)
    35 EMPTY_PROTOCOL(NSTableViewDelegate)
    36 EMPTY_PROTOCOL(NSWindowDelegate)
    37 
     33#if PLATFORM(CHROMIUM)
     34bool isScrollbarOverlayAPIAvailable()
     35{
     36    static bool apiAvailable;
     37    static bool shouldInitialize = true;
     38    if (shouldInitialize) {
     39        shouldInitialize = false;
     40        Class scrollerImpClass = NSClassFromString(@"NSScrollerImp");
     41        Class scrollerImpPairClass = NSClassFromString(@"NSScrollerImpPair");
     42        apiAvailable = [scrollerImpClass respondsToSelector:@selector(scrollerImpWithStyle:controlSize:horizontal:replacingScrollerImp:)]
     43                       && [scrollerImpPairClass instancesRespondToSelector:@selector(scrollerStyle)];
     44    }
     45    return apiAvailable;
     46}
    3847#endif
    3948
    40 #if defined(BUILDING_ON_LEOPARD) || defined(BUILDING_ON_SNOW_LEOPARD)
     49NSScrollerStyle recommendedScrollerStyle() {
     50    if ([NSScroller respondsToSelector:@selector(preferredScrollerStyle)])
     51        return [NSScroller preferredScrollerStyle];
     52    return NSScrollerStyleLegacy;
     53}
    4154
    42 EMPTY_PROTOCOL(NSURLConnectionDelegate)
    43 EMPTY_PROTOCOL(NSURLDownloadDelegate)
    44 
    45 #endif
    46 
    47 #undef EMPTY_PROTOCOL
    48 
    49 #endif /* defined(__OBJC__) */
     55}
  • trunk/Source/WebCore/platform/mac/ScrollAnimatorMac.h

    r102476 r103291  
    4747#endif
    4848
    49 #if USE(SCROLLBAR_PAINTER)
    5049typedef id ScrollbarPainterController;
    51 #endif
    5250
    5351#if !ENABLE(RUBBER_BANDING)
     
    8785    virtual void setIsActive();
    8886
    89 #if USE(SCROLLBAR_PAINTER)
    9087    void updateScrollerStyle();
    9188
     
    9390    void startScrollbarPaintTimer();
    9491    void stopScrollbarPaintTimer();
    95 #endif
    9692
    9793    void setVisibleScrollerThumbRect(const IntRect&);
     
    10197    RetainPtr<WebScrollAnimationHelperDelegate> m_scrollAnimationHelperDelegate;
    10298
    103 #if USE(SCROLLBAR_PAINTER)
    10499    RetainPtr<ScrollbarPainterController> m_scrollbarPainterController;
    105100    RetainPtr<WebScrollbarPainterControllerDelegate> m_scrollbarPainterControllerDelegate;
     
    109104    void initialScrollbarPaintTimerFired(Timer<ScrollAnimatorMac>*);
    110105    Timer<ScrollAnimatorMac> m_initialScrollbarPaintTimer;
    111 #endif
    112106   
    113107    virtual void notifyPositionChanged();
  • trunk/Source/WebCore/platform/mac/ScrollAnimatorMac.mm

    r103112 r103291  
    3131
    3232#include "BlockExceptions.h"
     33#include "EmptyProtocolDefinitions.h"
    3334#include "FloatPoint.h"
    3435#include "NSScrollerImpDetails.h"
     
    4647using namespace std;
    4748
    48 #if USE(SCROLLBAR_PAINTER)
     49#ifdef BUILDING_ON_LEOPARD
     50@interface NSProcessInfo (ScrollAnimatorMacExt)
     51- (NSTimeInterval)systemUptime;
     52@end
     53#endif
     54
    4955static bool supportsUIStateTransitionProgress()
    5056{
     
    6773    return nil;
    6874}
    69 #endif
    7075
    7176@interface NSObject (ScrollAnimationHelperDetails)
     
    172177
    173178@end
    174 
    175 #if USE(SCROLLBAR_PAINTER)
    176179
    177180@interface WebScrollbarPainterControllerDelegate : NSObject
     
    410413}
    411414
     415#if !PLATFORM(CHROMIUM)
    412416- (CALayer *)layer
    413417{
     
    422426    return dummyLayer;
    423427}
     428#endif
    424429
    425430- (NSPoint)mouseLocationInScrollerForScrollerImp:(id)scrollerImp
     
    542547@end
    543548
    544 #endif // USE(SCROLLBAR_PAINTER)
    545 
    546549namespace WebCore {
    547550
     
    553556ScrollAnimatorMac::ScrollAnimatorMac(ScrollableArea* scrollableArea)
    554557    : ScrollAnimator(scrollableArea)
    555 #if USE(SCROLLBAR_PAINTER)
    556558    , m_initialScrollbarPaintTimer(this, &ScrollAnimatorMac::initialScrollbarPaintTimerFired)
    557 #endif
    558559#if ENABLE(RUBBER_BANDING)
    559560    , m_scrollElasticityController(this)
     
    566567    m_scrollAnimationHelper.adoptNS([[NSClassFromString(@"NSScrollAnimationHelper") alloc] initWithDelegate:m_scrollAnimationHelperDelegate.get()]);
    567568
    568 #if USE(SCROLLBAR_PAINTER)
    569     m_scrollbarPainterControllerDelegate.adoptNS([[WebScrollbarPainterControllerDelegate alloc] initWithScrollableArea:scrollableArea]);
    570     m_scrollbarPainterController = [[[NSClassFromString(@"NSScrollerImpPair") alloc] init] autorelease];
    571     [m_scrollbarPainterController.get() setDelegate:m_scrollbarPainterControllerDelegate.get()];
    572     [m_scrollbarPainterController.get() setScrollerStyle:wkRecommendedScrollerStyle()];
    573 #endif
     569    if (isScrollbarOverlayAPIAvailable()) {
     570        m_scrollbarPainterControllerDelegate.adoptNS([[WebScrollbarPainterControllerDelegate alloc] initWithScrollableArea:scrollableArea]);
     571        m_scrollbarPainterController = [[[NSClassFromString(@"NSScrollerImpPair") alloc] init] autorelease];
     572        [m_scrollbarPainterController.get() setDelegate:m_scrollbarPainterControllerDelegate.get()];
     573        [m_scrollbarPainterController.get() setScrollerStyle:recommendedScrollerStyle()];
     574    }
    574575}
    575576
    576577ScrollAnimatorMac::~ScrollAnimatorMac()
    577578{
    578 #if USE(SCROLLBAR_PAINTER)
    579     BEGIN_BLOCK_OBJC_EXCEPTIONS;
    580     [m_scrollbarPainterControllerDelegate.get() invalidate];
    581     [m_scrollbarPainterController.get() setDelegate:nil];
    582     [m_horizontalScrollbarPainterDelegate.get() invalidate];
    583     [m_verticalScrollbarPainterDelegate.get() invalidate];
    584     [m_scrollAnimationHelperDelegate.get() invalidate];
    585     END_BLOCK_OBJC_EXCEPTIONS;
    586 #endif
     579    if (isScrollbarOverlayAPIAvailable()) {
     580        BEGIN_BLOCK_OBJC_EXCEPTIONS;
     581        [m_scrollbarPainterControllerDelegate.get() invalidate];
     582        [m_scrollbarPainterController.get() setDelegate:nil];
     583        [m_horizontalScrollbarPainterDelegate.get() invalidate];
     584        [m_verticalScrollbarPainterDelegate.get() invalidate];
     585        [m_scrollAnimationHelperDelegate.get() invalidate];
     586        END_BLOCK_OBJC_EXCEPTIONS;
     587    }
    587588}
    588589
     
    696697void ScrollAnimatorMac::notifyPositionChanged()
    697698{
    698 #if USE(SCROLLBAR_PAINTER)
    699     // This function is called when a page is going into the page cache, but the page
    700     // isn't really scrolling in that case. We should only pass the message on to the
    701     // ScrollbarPainterController when we're really scrolling on an active page.
    702     if (scrollableArea()->isOnActivePage())
    703         [m_scrollbarPainterController.get() contentAreaScrolled];
    704 #endif
     699    if (isScrollbarOverlayAPIAvailable()) {
     700        // This function is called when a page is going into the page cache, but the page
     701        // isn't really scrolling in that case. We should only pass the message on to the
     702        // ScrollbarPainterController when we're really scrolling on an active page.
     703        if (scrollableArea()->isOnActivePage())
     704            [m_scrollbarPainterController.get() contentAreaScrolled];
     705    }
    705706    ScrollAnimator::notifyPositionChanged();
    706707}
     
    710711    if (!scrollableArea()->isOnActivePage())
    711712        return;
    712 #if USE(SCROLLBAR_PAINTER)
    713     [m_scrollbarPainterController.get() contentAreaWillDraw];
    714 #endif
     713    if (isScrollbarOverlayAPIAvailable())
     714        [m_scrollbarPainterController.get() contentAreaWillDraw];
    715715}
    716716
     
    719719    if (!scrollableArea()->isOnActivePage())
    720720        return;
    721 #if USE(SCROLLBAR_PAINTER)
    722     [m_scrollbarPainterController.get() mouseEnteredContentArea];
    723 #endif
     721    if (isScrollbarOverlayAPIAvailable())
     722        [m_scrollbarPainterController.get() mouseEnteredContentArea];
    724723}
    725724
     
    728727    if (!scrollableArea()->isOnActivePage())
    729728        return;
    730 #if USE(SCROLLBAR_PAINTER)
    731     [m_scrollbarPainterController.get() mouseExitedContentArea];
    732 #endif
     729    if (isScrollbarOverlayAPIAvailable())
     730        [m_scrollbarPainterController.get() mouseExitedContentArea];
    733731}
    734732
     
    737735    if (!scrollableArea()->isOnActivePage())
    738736        return;
    739 #if USE(SCROLLBAR_PAINTER)
    740     [m_scrollbarPainterController.get() mouseMovedInContentArea];
    741 #endif
     737    if (isScrollbarOverlayAPIAvailable())
     738        [m_scrollbarPainterController.get() mouseMovedInContentArea];
    742739}
    743740
     
    746743    if (!scrollableArea()->isOnActivePage())
    747744        return;
    748 #if USE(SCROLLBAR_PAINTER)
    749     if (!supportsUIStateTransitionProgress())
    750         return;
    751     if (ScrollbarPainter painter = scrollbarPainterForScrollbar(scrollbar))
    752         [painter mouseEnteredScroller];
    753 #else
    754     UNUSED_PARAM(scrollbar);
    755 #endif
     745    if (isScrollbarOverlayAPIAvailable()) {
     746        if (!supportsUIStateTransitionProgress())
     747            return;
     748        if (ScrollbarPainter painter = scrollbarPainterForScrollbar(scrollbar))
     749            [painter mouseEnteredScroller];
     750    }
    756751}
    757752
     
    760755    if (!scrollableArea()->isOnActivePage())
    761756        return;
    762 #if USE(SCROLLBAR_PAINTER)
    763     if (!supportsUIStateTransitionProgress())
    764         return;
    765     if (ScrollbarPainter painter = scrollbarPainterForScrollbar(scrollbar))
    766         [painter mouseExitedScroller];
    767 #else
    768     UNUSED_PARAM(scrollbar);
    769 #endif
     757    if (isScrollbarOverlayAPIAvailable()) {
     758        if (!supportsUIStateTransitionProgress())
     759            return;
     760        if (ScrollbarPainter painter = scrollbarPainterForScrollbar(scrollbar))
     761            [painter mouseExitedScroller];
     762    }
    770763}
    771764
     
    774767    if (!scrollableArea()->isOnActivePage())
    775768        return;
    776 #if USE(SCROLLBAR_PAINTER)
    777     [m_scrollbarPainterController.get() startLiveResize];
    778 #endif
     769    if (isScrollbarOverlayAPIAvailable())
     770        [m_scrollbarPainterController.get() startLiveResize];
    779771}
    780772
     
    783775    if (!scrollableArea()->isOnActivePage())
    784776        return;
    785 #if USE(SCROLLBAR_PAINTER)
    786     [m_scrollbarPainterController.get() contentAreaDidResize];
    787 #endif
     777    if (isScrollbarOverlayAPIAvailable())
     778        [m_scrollbarPainterController.get() contentAreaDidResize];
    788779}
    789780
     
    792783    if (!scrollableArea()->isOnActivePage())
    793784        return;
    794 #if USE(SCROLLBAR_PAINTER)
    795     [m_scrollbarPainterController.get() endLiveResize];
    796 #endif
     785    if (isScrollbarOverlayAPIAvailable())
     786        [m_scrollbarPainterController.get() endLiveResize];
    797787}
    798788
     
    801791    if (!scrollableArea()->isOnActivePage())
    802792        return;
    803 #if USE(SCROLLBAR_PAINTER)
    804     [m_scrollbarPainterController.get() windowOrderedIn];
    805 #endif
     793    if (isScrollbarOverlayAPIAvailable())
     794        [m_scrollbarPainterController.get() windowOrderedIn];
    806795}
    807796
     
    810799    if (!scrollableArea()->isOnActivePage())
    811800        return;
    812 #if USE(SCROLLBAR_PAINTER)
    813     [m_scrollbarPainterController.get() windowOrderedOut];
    814 #endif
     801    if (isScrollbarOverlayAPIAvailable())
     802        [m_scrollbarPainterController.get() windowOrderedOut];
    815803}
    816804
     
    819807    if (!scrollableArea()->isOnActivePage())
    820808        return;
    821 #if USE(SCROLLBAR_PAINTER)
    822     [m_scrollbarPainterController.get() beginScrollGesture];
    823 #endif
     809    if (isScrollbarOverlayAPIAvailable())
     810        [m_scrollbarPainterController.get() beginScrollGesture];
    824811}
    825812
     
    828815    if (!scrollableArea()->isOnActivePage())
    829816        return;
    830 #if USE(SCROLLBAR_PAINTER)
    831     [m_scrollbarPainterController.get() endScrollGesture];
    832 #endif
     817    if (isScrollbarOverlayAPIAvailable())
     818        [m_scrollbarPainterController.get() endScrollGesture];
    833819}
    834820
    835821void ScrollAnimatorMac::didAddVerticalScrollbar(Scrollbar* scrollbar)
    836822{
    837 #if USE(SCROLLBAR_PAINTER)
    838     ScrollbarPainter painter = scrollbarPainterForScrollbar(scrollbar);
    839     if (!painter)
    840         return;
    841 
    842     ASSERT(!m_verticalScrollbarPainterDelegate);
    843     m_verticalScrollbarPainterDelegate.adoptNS([[WebScrollbarPainterDelegate alloc] initWithScrollbar:scrollbar]);
    844 
    845     [painter setDelegate:m_verticalScrollbarPainterDelegate.get()];
    846     [m_scrollbarPainterController.get() setVerticalScrollerImp:painter];
    847     if (scrollableArea()->inLiveResize())
    848         [painter setKnobAlpha:1];
    849 
    850 #else
    851     UNUSED_PARAM(scrollbar);
    852 #endif
     823    if (isScrollbarOverlayAPIAvailable()) {
     824        ScrollbarPainter painter = scrollbarPainterForScrollbar(scrollbar);
     825        if (!painter)
     826            return;
     827
     828        ASSERT(!m_verticalScrollbarPainterDelegate);
     829        m_verticalScrollbarPainterDelegate.adoptNS([[WebScrollbarPainterDelegate alloc] initWithScrollbar:scrollbar]);
     830
     831        [painter setDelegate:m_verticalScrollbarPainterDelegate.get()];
     832        [m_scrollbarPainterController.get() setVerticalScrollerImp:painter];
     833        if (scrollableArea()->inLiveResize())
     834            [painter setKnobAlpha:1];
     835    }
    853836}
    854837
    855838void ScrollAnimatorMac::willRemoveVerticalScrollbar(Scrollbar* scrollbar)
    856839{
    857 #if USE(SCROLLBAR_PAINTER)
    858     ScrollbarPainter painter = scrollbarPainterForScrollbar(scrollbar);
    859     if (!painter)
    860         return;
    861 
    862     ASSERT(m_verticalScrollbarPainterDelegate);
    863     [m_verticalScrollbarPainterDelegate.get() invalidate];
    864     m_verticalScrollbarPainterDelegate = nullptr;
    865 
    866     [painter setDelegate:nil];
    867     [m_scrollbarPainterController.get() setVerticalScrollerImp:nil];
    868 #else
    869     UNUSED_PARAM(scrollbar);
    870 #endif
     840    if (isScrollbarOverlayAPIAvailable()) {
     841        ScrollbarPainter painter = scrollbarPainterForScrollbar(scrollbar);
     842        if (!painter)
     843            return;
     844
     845        ASSERT(m_verticalScrollbarPainterDelegate);
     846        [m_verticalScrollbarPainterDelegate.get() invalidate];
     847        m_verticalScrollbarPainterDelegate = nullptr;
     848
     849        [painter setDelegate:nil];
     850        [m_scrollbarPainterController.get() setVerticalScrollerImp:nil];
     851    }
    871852}
    872853
    873854void ScrollAnimatorMac::didAddHorizontalScrollbar(Scrollbar* scrollbar)
    874855{
    875 #if USE(SCROLLBAR_PAINTER)
    876     ScrollbarPainter painter = scrollbarPainterForScrollbar(scrollbar);
    877     if (!painter)
    878         return;
    879 
    880     ASSERT(!m_horizontalScrollbarPainterDelegate);
    881     m_horizontalScrollbarPainterDelegate.adoptNS([[WebScrollbarPainterDelegate alloc] initWithScrollbar:scrollbar]);
    882 
    883     [painter setDelegate:m_horizontalScrollbarPainterDelegate.get()];
    884     [m_scrollbarPainterController.get() setHorizontalScrollerImp:painter];
    885     if (scrollableArea()->inLiveResize())
    886         [painter setKnobAlpha:1];
    887 #else
    888     UNUSED_PARAM(scrollbar);
    889 #endif
     856    if (isScrollbarOverlayAPIAvailable()) {
     857        ScrollbarPainter painter = scrollbarPainterForScrollbar(scrollbar);
     858        if (!painter)
     859            return;
     860
     861        ASSERT(!m_horizontalScrollbarPainterDelegate);
     862        m_horizontalScrollbarPainterDelegate.adoptNS([[WebScrollbarPainterDelegate alloc] initWithScrollbar:scrollbar]);
     863
     864        [painter setDelegate:m_horizontalScrollbarPainterDelegate.get()];
     865        [m_scrollbarPainterController.get() setHorizontalScrollerImp:painter];
     866        if (scrollableArea()->inLiveResize())
     867            [painter setKnobAlpha:1];
     868    }
    890869}
    891870
    892871void ScrollAnimatorMac::willRemoveHorizontalScrollbar(Scrollbar* scrollbar)
    893872{
    894 #if USE(SCROLLBAR_PAINTER)
    895     ScrollbarPainter painter = scrollbarPainterForScrollbar(scrollbar);
    896     if (!painter)
    897         return;
    898 
    899     ASSERT(m_horizontalScrollbarPainterDelegate);
    900     [m_horizontalScrollbarPainterDelegate.get() invalidate];
    901     m_horizontalScrollbarPainterDelegate = nullptr;
    902 
    903     [painter setDelegate:nil];
    904     [m_scrollbarPainterController.get() setHorizontalScrollerImp:nil];
    905 #else
    906     UNUSED_PARAM(scrollbar);
    907 #endif
     873    if (isScrollbarOverlayAPIAvailable()) {
     874        ScrollbarPainter painter = scrollbarPainterForScrollbar(scrollbar);
     875        if (!painter)
     876            return;
     877
     878        ASSERT(m_horizontalScrollbarPainterDelegate);
     879        [m_horizontalScrollbarPainterDelegate.get() invalidate];
     880        m_horizontalScrollbarPainterDelegate = nullptr;
     881
     882        [painter setDelegate:nil];
     883        [m_scrollbarPainterController.get() setHorizontalScrollerImp:nil];
     884    }
    908885}
    909886
     
    912889    m_haveScrolledSincePageLoad = false;
    913890
    914 #if USE(SCROLLBAR_PAINTER)
    915     if (scrollbarPaintTimerIsActive())
    916         stopScrollbarPaintTimer();
    917     [m_horizontalScrollbarPainterDelegate.get() cancelAnimations];
    918     [m_verticalScrollbarPainterDelegate.get() cancelAnimations];
    919 #endif
     891    if (isScrollbarOverlayAPIAvailable()) {
     892        if (scrollbarPaintTimerIsActive())
     893            stopScrollbarPaintTimer();
     894        [m_horizontalScrollbarPainterDelegate.get() cancelAnimations];
     895        [m_verticalScrollbarPainterDelegate.get() cancelAnimations];
     896    }
    920897}
    921898
     
    14051382void ScrollAnimatorMac::setIsActive()
    14061383{
    1407 #if USE(SCROLLBAR_PAINTER)
    1408     if (needsScrollerStyleUpdate())
    1409         updateScrollerStyle();
    1410 #endif
    1411 }
    1412 
    1413 #if USE(SCROLLBAR_PAINTER)
     1384    if (isScrollbarOverlayAPIAvailable()) {
     1385        if (needsScrollerStyleUpdate())
     1386            updateScrollerStyle();
     1387    }
     1388}
     1389
    14141390void ScrollAnimatorMac::updateScrollerStyle()
    14151391{
     1392    if (!isScrollbarOverlayAPIAvailable())
     1393        return;
     1394
    14161395    if (!scrollableArea()->isOnActivePage()) {
    14171396        setNeedsScrollerStyleUpdate(true);
     
    14871466void ScrollAnimatorMac::initialScrollbarPaintTimerFired(Timer<ScrollAnimatorMac>*)
    14881467{
    1489     // To force the scrollbars to flash, we have to call hide first. Otherwise, the ScrollbarPainterController
    1490     // might think that the scrollbars are already showing and bail early.
    1491     [m_scrollbarPainterController.get() hideOverlayScrollers];
    1492     [m_scrollbarPainterController.get() flashScrollers];
    1493 }
    1494 #endif
     1468    if (isScrollbarOverlayAPIAvailable()) {
     1469        // To force the scrollbars to flash, we have to call hide first. Otherwise, the ScrollbarPainterController
     1470        // might think that the scrollbars are already showing and bail early.
     1471        [m_scrollbarPainterController.get() hideOverlayScrollers];
     1472        [m_scrollbarPainterController.get() flashScrollers];
     1473    }
     1474}
    14951475
    14961476void ScrollAnimatorMac::setVisibleScrollerThumbRect(const IntRect& scrollerThumb)
  • trunk/Source/WebCore/platform/mac/ScrollElasticityController.h

    r96663 r103291  
    2929#if ENABLE(RUBBER_BANDING)
    3030
    31 #include <WebCore/FloatPoint.h>
    32 #include <WebCore/FloatSize.h>
     31#include "FloatPoint.h"
     32#include "FloatSize.h"
    3333#include <wtf/Noncopyable.h>
    3434
  • trunk/Source/WebCore/platform/mac/ScrollbarThemeMac.h

    r102476 r103291  
    2929#include "ScrollbarThemeComposite.h"
    3030
    31 #if USE(SCROLLBAR_PAINTER)
    3231typedef id ScrollbarPainter;
    33 #endif
    3432
    3533namespace WebCore {
     
    4442    virtual void updateEnabledState(Scrollbar*);
    4543
     44#if !PLATFORM(CHROMIUM)
    4645    virtual bool paint(Scrollbar*, GraphicsContext* context, const IntRect& damageRect);
     46#endif
    4747
    4848    virtual int scrollbarThickness(ScrollbarControlSize = RegularScrollbar);
     
    6060    virtual void unregisterScrollbar(Scrollbar*);
    6161
    62 #if USE(SCROLLBAR_PAINTER)
    6362    void setNewPainterForScrollbar(Scrollbar*, ScrollbarPainter);
    6463    ScrollbarPainter painterForScrollbar(Scrollbar*);
    6564
    6665    static bool isCurrentlyDrawingIntoLayer();
    67 #endif
     66    static void setIsCurrentlyDrawingIntoLayer(bool);
    6867
    6968protected:
     
    8180    virtual bool shouldCenterOnThumb(Scrollbar*, const PlatformMouseEvent&);
    8281    virtual bool shouldDragDocumentInsteadOfThumb(Scrollbar*, const PlatformMouseEvent&);
     82    int scrollbarPartToHIPressedState(ScrollbarPart);
    8383};
    8484
  • trunk/Source/WebCore/platform/mac/ScrollbarThemeMac.mm

    r102476 r103291  
    4747namespace WebCore {
    4848
    49 #if USE(SCROLLBAR_PAINTER)
    5049typedef HashMap<Scrollbar*, RetainPtr<ScrollbarPainter> > ScrollbarPainterMap;
    51 #else
    52 typedef HashSet<Scrollbar*> ScrollbarPainterMap;
    53 #endif
    5450
    5551static ScrollbarPainterMap* scrollbarMap()
     
    7672{
    7773    UNUSED_PARAM(unusedNotification);
     74
     75    ScrollbarTheme* theme = ScrollbarTheme::theme();
     76    if (theme->isMockTheme())
     77        return;
    7878
    7979    static_cast<ScrollbarThemeMac*>(ScrollbarTheme::theme())->preferencesChanged();
     
    8282    ScrollbarPainterMap::iterator end = scrollbarMap()->end();
    8383    for (ScrollbarPainterMap::iterator it = scrollbarMap()->begin(); it != end; ++it) {
    84 #if USE(SCROLLBAR_PAINTER)
    8584        it->first->styleChanged();
    8685        it->first->invalidate();
    87 #else
    88         (*it)->styleChanged();
    89         (*it)->invalidate();
    90 #endif
    9186    }
    9287}
     
    9590{
    9691    UNUSED_PARAM(unusedNotification);
     92
     93    ScrollbarTheme* theme = ScrollbarTheme::theme();
     94    if (theme->isMockTheme())
     95        return;
    9796
    9897    static_cast<ScrollbarThemeMac*>(ScrollbarTheme::theme())->preferencesChanged();
     
    109108namespace WebCore {
    110109
     110#if !PLATFORM(CHROMIUM)
    111111ScrollbarTheme* ScrollbarTheme::nativeTheme()
    112112{
     
    114114    return &theme;
    115115}
     116#endif
    116117
    117118// FIXME: Get these numbers from CoreUI.
     
    120121// cRealButtonLength - cButtonInset
    121122static int cButtonLength[] = { 14, 10 };
    122 #if !USE(SCROLLBAR_PAINTER)
    123123static int cScrollbarThickness[] = { 15, 11 };
    124124static int cButtonInset[] = { 14, 11 };
    125125static int cThumbMinLength[] = { 26, 20 };
    126 #endif
    127126
    128127static int cOuterButtonLength[] = { 16, 14 }; // The outer button in a double button pair is a bit bigger.
     
    133132static bool gJumpOnTrackClick = false;
    134133
    135 #if USE(SCROLLBAR_PAINTER)
    136 static ScrollbarButtonsPlacement gButtonPlacement = ScrollbarButtonsNone;
    137 #else
    138134static ScrollbarButtonsPlacement gButtonPlacement = ScrollbarButtonsDoubleEnd;
    139 #endif
    140135
    141136static void updateArrowPlacement()
    142137{
    143 #if USE(SCROLLBAR_PAINTER)
    144     return;
    145 #endif
     138    if (isScrollbarOverlayAPIAvailable())
     139        return;
     140
    146141    NSString *buttonPlacement = [[NSUserDefaults standardUserDefaults] objectForKey:@"AppleScrollBarVariant"];
    147142    if ([buttonPlacement isEqualToString:@"Single"])
     
    159154void ScrollbarThemeMac::registerScrollbar(Scrollbar* scrollbar)
    160155{
    161 #if USE(SCROLLBAR_PAINTER)
    162     bool isHorizontal = scrollbar->orientation() == HorizontalScrollbar;
    163     ScrollbarPainter scrollbarPainter = [NSClassFromString(@"NSScrollerImp") scrollerImpWithStyle:wkRecommendedScrollerStyle() controlSize:(NSControlSize)scrollbar->controlSize() horizontal:isHorizontal replacingScrollerImp:nil];
    164     scrollbarMap()->add(scrollbar, scrollbarPainter);
    165     updateEnabledState(scrollbar);
    166     updateScrollbarOverlayStyle(scrollbar);
    167 #else
    168     scrollbarMap()->add(scrollbar);
    169 #endif
     156    if (isScrollbarOverlayAPIAvailable()) {
     157        bool isHorizontal = scrollbar->orientation() == HorizontalScrollbar;
     158        ScrollbarPainter scrollbarPainter = [NSClassFromString(@"NSScrollerImp") scrollerImpWithStyle:recommendedScrollerStyle() controlSize:(NSControlSize)scrollbar->controlSize() horizontal:isHorizontal replacingScrollerImp:nil];
     159        scrollbarMap()->add(scrollbar, scrollbarPainter);
     160        updateEnabledState(scrollbar);
     161        updateScrollbarOverlayStyle(scrollbar);
     162    } else {
     163        scrollbarMap()->add(scrollbar, nil);
     164    }
    170165}
    171166
     
    175170}
    176171
    177 #if USE(SCROLLBAR_PAINTER)
    178172void ScrollbarThemeMac::setNewPainterForScrollbar(Scrollbar* scrollbar, ScrollbarPainter newPainter)
    179173{
     
    195189}
    196190
    197 #endif
     191void ScrollbarThemeMac::setIsCurrentlyDrawingIntoLayer(bool b)
     192{
     193    g_isCurrentlyDrawingIntoLayer = b;
     194}
    198195
    199196ScrollbarThemeMac::ScrollbarThemeMac()
     
    202199    if (!initialized) {
    203200        initialized = true;
     201        gButtonPlacement = isScrollbarOverlayAPIAvailable() ? ScrollbarButtonsNone : ScrollbarButtonsDoubleEnd;
    204202        [WebScrollbarPrefsObserver registerAsObserver];
    205203        preferencesChanged();
     
    223221int ScrollbarThemeMac::scrollbarThickness(ScrollbarControlSize controlSize)
    224222{
    225 #if USE(SCROLLBAR_PAINTER)
    226     ScrollbarPainter scrollbarPainter = [NSClassFromString(@"NSScrollerImp") scrollerImpWithStyle:wkRecommendedScrollerStyle() controlSize:controlSize horizontal:NO replacingScrollerImp:nil];
    227     return [scrollbarPainter trackBoxWidth];
    228 #else
    229     return cScrollbarThickness[controlSize];
    230 #endif
     223    if (isScrollbarOverlayAPIAvailable()) {
     224        ScrollbarPainter scrollbarPainter = [NSClassFromString(@"NSScrollerImp") scrollerImpWithStyle:recommendedScrollerStyle() controlSize:controlSize horizontal:NO replacingScrollerImp:nil];
     225        return [scrollbarPainter trackBoxWidth];
     226    } else
     227        return cScrollbarThickness[controlSize];
    231228}
    232229
    233230bool ScrollbarThemeMac::usesOverlayScrollbars() const
    234231{
    235 #if USE(SCROLLBAR_PAINTER)
    236     return wkRecommendedScrollerStyle() == NSScrollerStyleOverlay;
    237 #else
    238     return false;
    239 #endif
     232    if (isScrollbarOverlayAPIAvailable())
     233        return recommendedScrollerStyle() == NSScrollerStyleOverlay;
     234    else
     235        return false;
    240236}
    241237
    242238void ScrollbarThemeMac::updateScrollbarOverlayStyle(Scrollbar* scrollbar)
    243239{
    244 #if USE(SCROLLBAR_PAINTER)
    245240    ScrollbarPainter painter = painterForScrollbar(scrollbar);
    246241    switch (scrollbar->scrollableArea()->scrollbarOverlayStyle()) {
     
    255250        break;
    256251    }
    257 #else
    258     UNUSED_PARAM(scrollbar);
    259 #endif
    260252}
    261253
     
    277269bool ScrollbarThemeMac::hasButtons(Scrollbar* scrollbar)
    278270{
    279     return scrollbar->enabled() && gButtonPlacement != ScrollbarButtonsNone
     271    return scrollbar->enabled() && buttonsPlacement() != ScrollbarButtonsNone
    280272             && (scrollbar->orientation() == HorizontalScrollbar
    281273             ? scrollbar->width()
     
    286278{
    287279    int minLengthForThumb;
    288 #if USE(SCROLLBAR_PAINTER)
    289     ScrollbarPainter painter = scrollbarMap()->get(scrollbar).get();
    290     minLengthForThumb = [painter knobMinLength] + [painter trackOverlapEndInset] + [painter knobOverlapEndInset]
    291         + 2 * ([painter trackEndInset] + [painter knobEndInset]);
    292 #else
    293     minLengthForThumb = 2 * cButtonInset[scrollbar->controlSize()] + cThumbMinLength[scrollbar->controlSize()] + 1;
    294 #endif
     280    if (isScrollbarOverlayAPIAvailable()) {
     281        ScrollbarPainter painter = scrollbarMap()->get(scrollbar).get();
     282        minLengthForThumb = [painter knobMinLength] + [painter trackOverlapEndInset] + [painter knobOverlapEndInset]
     283            + 2 * ([painter trackEndInset] + [painter knobEndInset]);
     284    } else
     285        minLengthForThumb = 2 * cButtonInset[scrollbar->controlSize()] + cThumbMinLength[scrollbar->controlSize()] + 1;
    295286    return scrollbar->enabled() && (scrollbar->orientation() == HorizontalScrollbar ?
    296287             scrollbar->width() :
     
    429420int ScrollbarThemeMac::minimumThumbLength(Scrollbar* scrollbar)
    430421{
    431 #if USE(SCROLLBAR_PAINTER)
    432     return [scrollbarMap()->get(scrollbar).get() knobMinLength];
    433 #else
    434     return cThumbMinLength[scrollbar->controlSize()];
    435 #endif
     422    if (isScrollbarOverlayAPIAvailable())
     423        return [scrollbarMap()->get(scrollbar).get() knobMinLength];
     424    else
     425        return cThumbMinLength[scrollbar->controlSize()];
    436426}
    437427
     
    450440}
    451441
    452 static int scrollbarPartToHIPressedState(ScrollbarPart part)
     442int ScrollbarThemeMac::scrollbarPartToHIPressedState(ScrollbarPart part)
    453443{
    454444    switch (part) {
     
    470460void ScrollbarThemeMac::updateEnabledState(Scrollbar* scrollbar)
    471461{
    472 #if USE(SCROLLBAR_PAINTER)
    473     [scrollbarMap()->get(scrollbar).get() setEnabled:scrollbar->enabled()];
    474 #else
    475     UNUSED_PARAM(scrollbar);
    476 #endif
    477 }
    478 
    479 #if USE(SCROLLBAR_PAINTER)
     462    if (isScrollbarOverlayAPIAvailable())
     463        [scrollbarMap()->get(scrollbar).get() setEnabled:scrollbar->enabled()];
     464}
     465
    480466static void scrollbarPainterPaint(ScrollbarPainter scrollbarPainter, bool enabled, double value, CGFloat proportion, CGRect frameRect)
    481467{
     
    499485        [scrollbarPainter drawKnob];
    500486}
    501 #endif
    502 
     487
     488#if !PLATFORM(CHROMIUM)
    503489bool ScrollbarThemeMac::paint(Scrollbar* scrollbar, GraphicsContext* context, const IntRect& damageRect)
    504490{
    505 #if USE(SCROLLBAR_PAINTER)
    506     float value = 0;
    507     float overhang = 0;
    508 
    509     if (scrollbar->currentPos() < 0) {
    510         // Scrolled past the top.
    511         value = 0;
    512         overhang = -scrollbar->currentPos();
    513     } else if (scrollbar->visibleSize() + scrollbar->currentPos() > scrollbar->totalSize()) {
    514         // Scrolled past the bottom.
    515         value = 1;
    516         overhang = scrollbar->currentPos() + scrollbar->visibleSize() - scrollbar->totalSize();
    517     } else {
    518         // Within the bounds of the scrollable area.
    519         int maximum = scrollbar->maximum();
    520         if (maximum > 0)
    521             value = scrollbar->currentPos() / maximum;
    522         else
     491    if (isScrollbarOverlayAPIAvailable()) {
     492        float value = 0;
     493        float overhang = 0;
     494
     495        if (scrollbar->currentPos() < 0) {
     496            // Scrolled past the top.
    523497            value = 0;
    524     }
    525 
    526     TemporaryChange<bool> isCurrentlyDrawingIntoLayer(g_isCurrentlyDrawingIntoLayer, context->isCALayerContext());
    527    
    528     GraphicsContextStateSaver stateSaver(*context);
    529     context->clip(damageRect);
    530     context->translate(scrollbar->frameRect().x(), scrollbar->frameRect().y());
    531     LocalCurrentGraphicsContext localContext(context);
    532     scrollbarPainterPaint(scrollbarMap()->get(scrollbar).get(),
    533                             scrollbar->enabled(),
    534                             value,
    535                             (static_cast<CGFloat>(scrollbar->visibleSize()) - overhang) / scrollbar->totalSize(),
    536                             scrollbar->frameRect());
    537 
    538     return true;
    539 #endif
     498            overhang = -scrollbar->currentPos();
     499        } else if (scrollbar->visibleSize() + scrollbar->currentPos() > scrollbar->totalSize()) {
     500            // Scrolled past the bottom.
     501            value = 1;
     502            overhang = scrollbar->currentPos() + scrollbar->visibleSize() - scrollbar->totalSize();
     503        } else {
     504            // Within the bounds of the scrollable area.
     505            int maximum = scrollbar->maximum();
     506            if (maximum > 0)
     507                value = scrollbar->currentPos() / maximum;
     508            else
     509                value = 0;
     510        }
     511
     512        TemporaryChange<bool> isCurrentlyDrawingIntoLayer(g_isCurrentlyDrawingIntoLayer, context->isCALayerContext());
     513       
     514        GraphicsContextStateSaver stateSaver(*context);
     515        context->clip(damageRect);
     516        context->translate(scrollbar->frameRect().x(), scrollbar->frameRect().y());
     517        LocalCurrentGraphicsContext localContext(context);
     518        scrollbarPainterPaint(scrollbarMap()->get(scrollbar).get(),
     519                                scrollbar->enabled(),
     520                                value,
     521                                (static_cast<CGFloat>(scrollbar->visibleSize()) - overhang) / scrollbar->totalSize(),
     522                                scrollbar->frameRect());
     523
     524        return true;
     525    }
    540526
    541527    HIThemeTrackDrawInfo trackInfo;
     
    602588    return true;
    603589}
    604 
    605 }
    606 
     590#endif
     591
     592}
     593
Note: See TracChangeset for help on using the changeset viewer.