| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (C) 2008, 2011 Apple Inc. All Rights Reserved. | 2 * Copyright (C) 2008, 2011 Apple Inc. All Rights Reserved. |
| 3 * | 3 * |
| 4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
| 5 * modification, are permitted provided that the following conditions | 5 * modification, are permitted provided that the following conditions |
| 6 * are met: | 6 * are met: |
| 7 * 1. Redistributions of source code must retain the above copyright | 7 * 1. Redistributions of source code must retain the above copyright |
| 8 * notice, this list of conditions and the following disclaimer. | 8 * notice, this list of conditions and the following disclaimer. |
| 9 * 2. Redistributions in binary form must reproduce the above copyright | 9 * 2. Redistributions in binary form must reproduce the above copyright |
| 10 * notice, this list of conditions and the following disclaimer in the | 10 * notice, this list of conditions and the following disclaimer in the |
| (...skipping 21 matching lines...) Expand all Loading... |
| 32 #include "core/platform/ScrollView.h" | 32 #include "core/platform/ScrollView.h" |
| 33 #include "core/platform/graphics/Gradient.h" | 33 #include "core/platform/graphics/Gradient.h" |
| 34 #include "core/platform/graphics/GraphicsContext.h" | 34 #include "core/platform/graphics/GraphicsContext.h" |
| 35 #include "core/platform/graphics/GraphicsContextStateSaver.h" | 35 #include "core/platform/graphics/GraphicsContextStateSaver.h" |
| 36 #include "core/platform/graphics/GraphicsLayer.h" | 36 #include "core/platform/graphics/GraphicsLayer.h" |
| 37 #include "core/platform/graphics/ImageBuffer.h" | 37 #include "core/platform/graphics/ImageBuffer.h" |
| 38 #include "core/platform/graphics/mac/ColorMac.h" | 38 #include "core/platform/graphics/mac/ColorMac.h" |
| 39 #include "core/platform/mac/LocalCurrentGraphicsContext.h" | 39 #include "core/platform/mac/LocalCurrentGraphicsContext.h" |
| 40 #include "core/platform/mac/NSScrollerImpDetails.h" | 40 #include "core/platform/mac/NSScrollerImpDetails.h" |
| 41 #include "core/platform/mac/ScrollAnimatorMac.h" | 41 #include "core/platform/mac/ScrollAnimatorMac.h" |
| 42 #include "core/platform/mac/ScrollbarThemeMacNonOverlayAPI.h" |
| 43 #include "core/platform/mac/ScrollbarThemeMacOverlayAPI.h" |
| 42 #include "public/platform/mac/WebThemeEngine.h" | 44 #include "public/platform/mac/WebThemeEngine.h" |
| 43 #include "public/platform/Platform.h" | 45 #include "public/platform/Platform.h" |
| 44 #include "public/platform/WebRect.h" | 46 #include "public/platform/WebRect.h" |
| 45 #include "skia/ext/skia_utils_mac.h" | 47 #include "skia/ext/skia_utils_mac.h" |
| 46 #include "wtf/HashMap.h" | 48 #include "wtf/HashMap.h" |
| 47 #include "wtf/StdLibExtras.h" | 49 #include "wtf/StdLibExtras.h" |
| 48 #include "wtf/TemporaryChange.h" | 50 #include "wtf/TemporaryChange.h" |
| 49 #include "wtf/UnusedParam.h" | 51 #include "wtf/UnusedParam.h" |
| 50 | 52 |
| 51 // FIXME: There are repainting problems due to Aqua scroll bar buttons' visual o
verflow. | 53 // FIXME: There are repainting problems due to Aqua scroll bar buttons' visual o
verflow. |
| 52 | 54 |
| 53 using namespace std; | 55 using namespace std; |
| 54 using namespace WebCore; | 56 using namespace WebCore; |
| 55 | 57 |
| 56 @interface NSColor (WebNSColorDetails) | 58 @interface NSColor (WebNSColorDetails) |
| 57 + (NSImage *)_linenPatternImage; | 59 + (NSImage *)_linenPatternImage; |
| 58 @end | 60 @end |
| 59 | 61 |
| 60 namespace WebCore { | 62 namespace WebCore { |
| 61 | 63 |
| 62 typedef HashMap<ScrollbarThemeClient*, ScrollbarThemeClient*> ScrollbarMap; | 64 typedef HashMap<ScrollbarThemeClient*, ScrollbarThemeClient*> ScrollbarMap; |
| 63 | 65 |
| 64 static ScrollbarMap* scrollbarMap() | 66 static ScrollbarMap* scrollbarMap() |
| 65 { | 67 { |
| 66 static ScrollbarMap* map = new ScrollbarMap; | 68 static ScrollbarMap* map = new ScrollbarMap; |
| 67 return map; | 69 return map; |
| 68 } | 70 } |
| 69 | 71 |
| 70 typedef HashMap<ScrollbarThemeClient*, RetainPtr<ScrollbarPainter> > ScrollbarPa
interMap; | |
| 71 | |
| 72 static ScrollbarPainterMap* scrollbarPainterMap() | |
| 73 { | |
| 74 static ScrollbarPainterMap* map = new ScrollbarPainterMap; | |
| 75 return map; | |
| 76 } | |
| 77 | |
| 78 } | 72 } |
| 79 | 73 |
| 80 @interface WebScrollbarPrefsObserver : NSObject | 74 @interface WebScrollbarPrefsObserver : NSObject |
| 81 { | 75 { |
| 82 } | 76 } |
| 83 | 77 |
| 84 + (void)registerAsObserver; | 78 + (void)registerAsObserver; |
| 85 + (void)appearancePrefsChanged:(NSNotification*)theNotification; | 79 + (void)appearancePrefsChanged:(NSNotification*)theNotification; |
| 86 + (void)behaviorPrefsChanged:(NSNotification*)theNotification; | 80 + (void)behaviorPrefsChanged:(NSNotification*)theNotification; |
| 87 | 81 |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 121 + (void)registerAsObserver | 115 + (void)registerAsObserver |
| 122 { | 116 { |
| 123 [[NSDistributedNotificationCenter defaultCenter] addObserver:self selector:@
selector(appearancePrefsChanged:) name:@"AppleAquaScrollBarVariantChanged" objec
t:nil suspensionBehavior:NSNotificationSuspensionBehaviorDeliverImmediately]; | 117 [[NSDistributedNotificationCenter defaultCenter] addObserver:self selector:@
selector(appearancePrefsChanged:) name:@"AppleAquaScrollBarVariantChanged" objec
t:nil suspensionBehavior:NSNotificationSuspensionBehaviorDeliverImmediately]; |
| 124 [[NSDistributedNotificationCenter defaultCenter] addObserver:self selector:@
selector(behaviorPrefsChanged:) name:@"AppleNoRedisplayAppearancePreferenceChang
ed" object:nil suspensionBehavior:NSNotificationSuspensionBehaviorCoalesce]; | 118 [[NSDistributedNotificationCenter defaultCenter] addObserver:self selector:@
selector(behaviorPrefsChanged:) name:@"AppleNoRedisplayAppearancePreferenceChang
ed" object:nil suspensionBehavior:NSNotificationSuspensionBehaviorCoalesce]; |
| 125 } | 119 } |
| 126 | 120 |
| 127 @end | 121 @end |
| 128 | 122 |
| 129 namespace WebCore { | 123 namespace WebCore { |
| 130 | 124 |
| 131 // FIXME: Get these numbers from CoreUI. | |
| 132 static int cRealButtonLength[] = { 28, 21 }; | |
| 133 static int cButtonHitInset[] = { 3, 2 }; | |
| 134 // cRealButtonLength - cButtonInset | |
| 135 static int cButtonLength[] = { 14, 10 }; | |
| 136 static int cScrollbarThickness[] = { 15, 11 }; | |
| 137 static int cButtonInset[] = { 14, 11 }; | |
| 138 static int cThumbMinLength[] = { 26, 20 }; | |
| 139 | |
| 140 static int cOuterButtonLength[] = { 16, 14 }; // The outer button in a double bu
tton pair is a bit bigger. | |
| 141 static int cOuterButtonOverlap = 2; | |
| 142 | |
| 143 static float gInitialButtonDelay = 0.5f; | 125 static float gInitialButtonDelay = 0.5f; |
| 144 static float gAutoscrollButtonDelay = 0.05f; | 126 static float gAutoscrollButtonDelay = 0.05f; |
| 145 static bool gJumpOnTrackClick = false; | 127 static bool gJumpOnTrackClick = false; |
| 146 | 128 |
| 147 static ScrollbarButtonsPlacement gButtonPlacement = ScrollbarButtonsDoubleEnd; | |
| 148 | |
| 149 static bool supportsExpandedScrollbars() | |
| 150 { | |
| 151 // FIXME: This is temporary until all platforms that support ScrollbarPainte
r support this part of the API. | |
| 152 static bool globalSupportsExpandedScrollbars = [NSClassFromString(@"NSScroll
erImp") instancesRespondToSelector:@selector(setExpanded:)]; | |
| 153 return globalSupportsExpandedScrollbars; | |
| 154 } | |
| 155 | |
| 156 void ScrollbarThemeMacNonOverlayAPI::updateButtonPlacement() | |
| 157 { | |
| 158 NSString *buttonPlacement = [[NSUserDefaults standardUserDefaults] objectFor
Key:@"AppleScrollBarVariant"]; | |
| 159 if ([buttonPlacement isEqualToString:@"Single"]) | |
| 160 gButtonPlacement = ScrollbarButtonsSingle; | |
| 161 else if ([buttonPlacement isEqualToString:@"DoubleMin"]) | |
| 162 gButtonPlacement = ScrollbarButtonsDoubleStart; | |
| 163 else if ([buttonPlacement isEqualToString:@"DoubleBoth"]) | |
| 164 gButtonPlacement = ScrollbarButtonsDoubleBoth; | |
| 165 else { | |
| 166 gButtonPlacement = ScrollbarButtonsDoubleEnd; | |
| 167 } | |
| 168 } | |
| 169 | |
| 170 ScrollbarTheme* ScrollbarTheme::nativeTheme() | 129 ScrollbarTheme* ScrollbarTheme::nativeTheme() |
| 171 { | 130 { |
| 172 if (isScrollbarOverlayAPIAvailable()) { | 131 if (isScrollbarOverlayAPIAvailable()) { |
| 173 DEFINE_STATIC_LOCAL(ScrollbarThemeMacOverlayAPI, theme, ()); | 132 DEFINE_STATIC_LOCAL(ScrollbarThemeMacOverlayAPI, theme, ()); |
| 174 return &theme; | 133 return &theme; |
| 175 } else { | 134 } else { |
| 176 DEFINE_STATIC_LOCAL(ScrollbarThemeMacNonOverlayAPI, theme, ()); | 135 DEFINE_STATIC_LOCAL(ScrollbarThemeMacNonOverlayAPI, theme, ()); |
| 177 return &theme; | 136 return &theme; |
| 178 } | 137 } |
| 179 return NULL; | 138 return NULL; |
| 180 } | 139 } |
| 181 | 140 |
| 182 static WebKit::WebThemeEngine::State scrollbarStateToThemeState(ScrollbarThemeCl
ient* scrollbar) | |
| 183 { | |
| 184 if (!scrollbar->enabled()) | |
| 185 return WebKit::WebThemeEngine::StateDisabled; | |
| 186 if (!scrollbar->isScrollableAreaActive()) | |
| 187 return WebKit::WebThemeEngine::StateInactive; | |
| 188 if (scrollbar->pressedPart() == ThumbPart) | |
| 189 return WebKit::WebThemeEngine::StatePressed; | |
| 190 | |
| 191 return WebKit::WebThemeEngine::StateActive; | |
| 192 } | |
| 193 | |
| 194 void ScrollbarThemeMacOverlayAPI::registerScrollbar(ScrollbarThemeClient* scroll
bar) | |
| 195 { | |
| 196 ScrollbarThemeMacCommon::registerScrollbar(scrollbar); | |
| 197 | |
| 198 bool isHorizontal = scrollbar->orientation() == HorizontalScrollbar; | |
| 199 ScrollbarPainter scrollbarPainter = [NSClassFromString(@"NSScrollerImp") scr
ollerImpWithStyle:recommendedScrollerStyle() controlSize:(NSControlSize)scrollba
r->controlSize() horizontal:isHorizontal replacingScrollerImp:nil]; | |
| 200 scrollbarPainterMap()->add(scrollbar, scrollbarPainter); | |
| 201 updateEnabledState(scrollbar); | |
| 202 updateScrollbarOverlayStyle(scrollbar); | |
| 203 } | |
| 204 | |
| 205 void ScrollbarThemeMacCommon::registerScrollbar(ScrollbarThemeClient* scrollbar) | 141 void ScrollbarThemeMacCommon::registerScrollbar(ScrollbarThemeClient* scrollbar) |
| 206 { | 142 { |
| 207 scrollbarMap()->add(scrollbar, scrollbar); | 143 scrollbarMap()->add(scrollbar, scrollbar); |
| 208 } | 144 } |
| 209 | 145 |
| 210 void ScrollbarThemeMacOverlayAPI::unregisterScrollbar(ScrollbarThemeClient* scro
llbar) | |
| 211 { | |
| 212 scrollbarPainterMap()->remove(scrollbar); | |
| 213 | |
| 214 ScrollbarThemeMacCommon::unregisterScrollbar(scrollbar); | |
| 215 } | |
| 216 | |
| 217 void ScrollbarThemeMacCommon::unregisterScrollbar(ScrollbarThemeClient* scrollba
r) | 146 void ScrollbarThemeMacCommon::unregisterScrollbar(ScrollbarThemeClient* scrollba
r) |
| 218 { | 147 { |
| 219 scrollbarMap()->remove(scrollbar); | 148 scrollbarMap()->remove(scrollbar); |
| 220 } | 149 } |
| 221 | 150 |
| 222 void ScrollbarThemeMacOverlayAPI::setNewPainterForScrollbar(ScrollbarThemeClient
* scrollbar, ScrollbarPainter newPainter) | |
| 223 { | |
| 224 scrollbarPainterMap()->set(scrollbar, newPainter); | |
| 225 updateEnabledState(scrollbar); | |
| 226 updateScrollbarOverlayStyle(scrollbar); | |
| 227 } | |
| 228 | |
| 229 ScrollbarPainter ScrollbarThemeMacOverlayAPI::painterForScrollbar(ScrollbarTheme
Client* scrollbar) | |
| 230 { | |
| 231 return scrollbarPainterMap()->get(scrollbar).get(); | |
| 232 } | |
| 233 | |
| 234 // Override ScrollbarThemeMacCommon::paint() to add support for the following: | |
| 235 // - drawing using WebThemeEngine functions | |
| 236 // - drawing tickmarks | |
| 237 // - Skia specific changes | |
| 238 bool ScrollbarThemeMacNonOverlayAPI::paint(ScrollbarThemeClient* scrollbar, Grap
hicsContext* context, const IntRect& damageRect) | |
| 239 { | |
| 240 // Get the tickmarks for the frameview. | |
| 241 Vector<IntRect> tickmarks; | |
| 242 scrollbar->getTickmarks(tickmarks); | |
| 243 | |
| 244 HIThemeTrackDrawInfo trackInfo; | |
| 245 trackInfo.version = 0; | |
| 246 trackInfo.kind = scrollbar->controlSize() == RegularScrollbar ? kThemeMedium
ScrollBar : kThemeSmallScrollBar; | |
| 247 trackInfo.bounds = scrollbar->frameRect(); | |
| 248 trackInfo.min = 0; | |
| 249 trackInfo.max = scrollbar->maximum(); | |
| 250 trackInfo.value = scrollbar->currentPos(); | |
| 251 trackInfo.trackInfo.scrollbar.viewsize = scrollbar->visibleSize(); | |
| 252 trackInfo.attributes = 0; | |
| 253 if (scrollbar->orientation() == HorizontalScrollbar) | |
| 254 trackInfo.attributes |= kThemeTrackHorizontal; | |
| 255 | |
| 256 if (!scrollbar->enabled()) | |
| 257 trackInfo.enableState = kThemeTrackDisabled; | |
| 258 else | |
| 259 trackInfo.enableState = scrollbar->isScrollableAreaActive() ? kThemeTrac
kActive : kThemeTrackInactive; | |
| 260 | |
| 261 if (!hasButtons(scrollbar)) | |
| 262 trackInfo.enableState = kThemeTrackNothingToScroll; | |
| 263 trackInfo.trackInfo.scrollbar.pressState = scrollbarPartToHIPressedState(scr
ollbar->pressedPart()); | |
| 264 | |
| 265 SkCanvas* canvas = context->canvas(); | |
| 266 CGAffineTransform currentCTM = gfx::SkMatrixToCGAffineTransform(canvas->getT
otalMatrix()); | |
| 267 | |
| 268 // The Aqua scrollbar is buggy when rotated and scaled. We will just draw i
nto a bitmap if we detect a scale or rotation. | |
| 269 bool canDrawDirectly = currentCTM.a == 1.0f && currentCTM.b == 0.0f && curre
ntCTM.c == 0.0f && (currentCTM.d == 1.0f || currentCTM.d == -1.0f); | |
| 270 GraphicsContext* drawingContext = context; | |
| 271 OwnPtr<ImageBuffer> imageBuffer; | |
| 272 if (!canDrawDirectly) { | |
| 273 trackInfo.bounds = IntRect(IntPoint(), scrollbar->frameRect().size()); | |
| 274 | |
| 275 IntRect bufferRect(scrollbar->frameRect()); | |
| 276 bufferRect.intersect(damageRect); | |
| 277 bufferRect.move(-scrollbar->frameRect().x(), -scrollbar->frameRect().y()
); | |
| 278 | |
| 279 imageBuffer = ImageBuffer::create(bufferRect.size()); | |
| 280 if (!imageBuffer) | |
| 281 return true; | |
| 282 | |
| 283 drawingContext = imageBuffer->context(); | |
| 284 } | |
| 285 | |
| 286 // Draw thumbless. | |
| 287 gfx::SkiaBitLocker bitLocker(drawingContext->canvas()); | |
| 288 CGContextRef cgContext = bitLocker.cgContext(); | |
| 289 HIThemeDrawTrack(&trackInfo, 0, cgContext, kHIThemeOrientationNormal); | |
| 290 | |
| 291 IntRect tickmarkTrackRect = trackRect(scrollbar, false); | |
| 292 if (!canDrawDirectly) { | |
| 293 tickmarkTrackRect.setX(0); | |
| 294 tickmarkTrackRect.setY(0); | |
| 295 } | |
| 296 // The ends are rounded and the thumb doesn't go there. | |
| 297 tickmarkTrackRect.inflateY(-tickmarkTrackRect.width()); | |
| 298 // Inset a bit. | |
| 299 tickmarkTrackRect.setX(tickmarkTrackRect.x() + 2); | |
| 300 tickmarkTrackRect.setWidth(tickmarkTrackRect.width() - 5); | |
| 301 paintGivenTickmarks(drawingContext, scrollbar, tickmarkTrackRect, tickmarks)
; | |
| 302 | |
| 303 if (hasThumb(scrollbar)) { | |
| 304 WebKit::WebThemeEngine::ScrollbarInfo scrollbarInfo; | |
| 305 scrollbarInfo.orientation = scrollbar->orientation() == HorizontalScroll
bar ? WebKit::WebThemeEngine::ScrollbarOrientationHorizontal : WebKit::WebThemeE
ngine::ScrollbarOrientationVertical; | |
| 306 scrollbarInfo.parent = scrollbar->isScrollViewScrollbar() ? WebKit::WebT
hemeEngine::ScrollbarParentScrollView : WebKit::WebThemeEngine::ScrollbarParentR
enderLayer; | |
| 307 scrollbarInfo.maxValue = scrollbar->maximum(); | |
| 308 scrollbarInfo.currentValue = scrollbar->currentPos(); | |
| 309 scrollbarInfo.visibleSize = scrollbar->visibleSize(); | |
| 310 scrollbarInfo.totalSize = scrollbar->totalSize(); | |
| 311 | |
| 312 WebKit::WebCanvas* webCanvas = drawingContext->canvas(); | |
| 313 WebKit::Platform::current()->themeEngine()->paintScrollbarThumb( | |
| 314 webCanvas, | |
| 315 scrollbarStateToThemeState(scrollbar), | |
| 316 scrollbar->controlSize() == RegularScrollbar ? WebKit::WebThemeEngin
e::SizeRegular : WebKit::WebThemeEngine::SizeSmall, | |
| 317 WebKit::WebRect(scrollbar->frameRect()), | |
| 318 scrollbarInfo); | |
| 319 } | |
| 320 | |
| 321 if (!canDrawDirectly) | |
| 322 context->drawImageBuffer(imageBuffer.get(), scrollbar->frameRect().locat
ion()); | |
| 323 | |
| 324 return true; | |
| 325 } | |
| 326 | |
| 327 void ScrollbarThemeMacCommon::paintGivenTickmarks(GraphicsContext* context, Scro
llbarThemeClient* scrollbar, const IntRect& rect, const Vector<IntRect>& tickmar
ks) | 151 void ScrollbarThemeMacCommon::paintGivenTickmarks(GraphicsContext* context, Scro
llbarThemeClient* scrollbar, const IntRect& rect, const Vector<IntRect>& tickmar
ks) |
| 328 { | 152 { |
| 329 if (scrollbar->orientation() != VerticalScrollbar) | 153 if (scrollbar->orientation() != VerticalScrollbar) |
| 330 return; | 154 return; |
| 331 | 155 |
| 332 if (rect.height() <= 0 || rect.width() <= 0) | 156 if (rect.height() <= 0 || rect.width() <= 0) |
| 333 return; // nothing to draw on. | 157 return; // nothing to draw on. |
| 334 | 158 |
| 335 if (!tickmarks.size()) | 159 if (!tickmarks.size()) |
| 336 return; | 160 return; |
| (...skipping 155 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 492 if (!tickmarks.size()) | 316 if (!tickmarks.size()) |
| 493 return; | 317 return; |
| 494 | 318 |
| 495 // Inset a bit. | 319 // Inset a bit. |
| 496 IntRect tickmarkTrackRect = rect; | 320 IntRect tickmarkTrackRect = rect; |
| 497 tickmarkTrackRect.setX(tickmarkTrackRect.x() + 1); | 321 tickmarkTrackRect.setX(tickmarkTrackRect.x() + 1); |
| 498 tickmarkTrackRect.setWidth(tickmarkTrackRect.width() - 2); | 322 tickmarkTrackRect.setWidth(tickmarkTrackRect.width() - 2); |
| 499 paintGivenTickmarks(context, scrollbar, tickmarkTrackRect, tickmarks); | 323 paintGivenTickmarks(context, scrollbar, tickmarkTrackRect, tickmarks); |
| 500 } | 324 } |
| 501 | 325 |
| 502 void ScrollbarThemeMacOverlayAPI::paintTrackBackground(GraphicsContext* context,
ScrollbarThemeClient* scrollbar, const IntRect& rect) { | |
| 503 ASSERT(isScrollbarOverlayAPIAvailable()); | |
| 504 | |
| 505 GraphicsContextStateSaver stateSaver(*context); | |
| 506 context->translate(rect.x(), rect.y()); | |
| 507 LocalCurrentGraphicsContext localContext(context); | |
| 508 | |
| 509 CGRect frameRect = scrollbar->frameRect(); | |
| 510 ScrollbarPainter scrollbarPainter = painterForScrollbar(scrollbar); | |
| 511 [scrollbarPainter setEnabled:scrollbar->enabled()]; | |
| 512 [scrollbarPainter setBoundsSize: NSSizeFromCGSize(frameRect.size)]; | |
| 513 | |
| 514 NSRect trackRect = NSMakeRect(0, 0, frameRect.size.width, frameRect.size.hei
ght); | |
| 515 [scrollbarPainter drawKnobSlotInRect:trackRect highlight:NO]; | |
| 516 } | |
| 517 | |
| 518 void ScrollbarThemeMacOverlayAPI::paintThumb(GraphicsContext* context, Scrollbar
ThemeClient* scrollbar, const IntRect& rect) { | |
| 519 ASSERT(isScrollbarOverlayAPIAvailable()); | |
| 520 | |
| 521 GraphicsContextStateSaver stateSaver(*context); | |
| 522 context->translate(rect.x(), rect.y()); | |
| 523 LocalCurrentGraphicsContext localContext(context); | |
| 524 | |
| 525 ScrollbarPainter scrollbarPainter = painterForScrollbar(scrollbar); | |
| 526 CGRect frameRect = scrollbar->frameRect(); | |
| 527 [scrollbarPainter setEnabled:scrollbar->enabled()]; | |
| 528 [scrollbarPainter setBoundsSize:NSSizeFromCGSize(rect.size())]; | |
| 529 [scrollbarPainter setDoubleValue:0]; | |
| 530 [scrollbarPainter setKnobProportion:1]; | |
| 531 if (scrollbar->enabled()) | |
| 532 [scrollbarPainter drawKnob]; | |
| 533 | |
| 534 // If this state is not set, then moving the cursor over the scrollbar area
will only cause the | |
| 535 // scrollbar to engorge when moved over the top of the scrollbar area. | |
| 536 [scrollbarPainter setBoundsSize: NSSizeFromCGSize(scrollbar->frameRect().siz
e())]; | |
| 537 } | |
| 538 | |
| 539 ScrollbarThemeMacCommon::ScrollbarThemeMacCommon() | 326 ScrollbarThemeMacCommon::ScrollbarThemeMacCommon() |
| 540 { | 327 { |
| 541 static bool initialized; | 328 static bool initialized; |
| 542 if (!initialized) { | 329 if (!initialized) { |
| 543 initialized = true; | 330 initialized = true; |
| 544 [WebScrollbarPrefsObserver registerAsObserver]; | 331 [WebScrollbarPrefsObserver registerAsObserver]; |
| 545 preferencesChanged(); | 332 preferencesChanged(); |
| 546 } | 333 } |
| 547 | 334 |
| 548 // Load the linen pattern image used for overhang drawing. | 335 // Load the linen pattern image used for overhang drawing. |
| 549 RefPtr<Image> patternImage = Image::loadPlatformResource("overhangPattern"); | 336 RefPtr<Image> patternImage = Image::loadPlatformResource("overhangPattern"); |
| 550 m_overhangPattern = Pattern::create(patternImage, true, true); | 337 m_overhangPattern = Pattern::create(patternImage, true, true); |
| 551 } | 338 } |
| 552 | 339 |
| 553 ScrollbarThemeMacCommon::~ScrollbarThemeMacCommon() | 340 ScrollbarThemeMacCommon::~ScrollbarThemeMacCommon() |
| 554 { | 341 { |
| 555 } | 342 } |
| 556 | 343 |
| 557 void ScrollbarThemeMacCommon::preferencesChanged() | 344 void ScrollbarThemeMacCommon::preferencesChanged() |
| 558 { | 345 { |
| 559 NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults]; | 346 NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults]; |
| 560 [defaults synchronize]; | 347 [defaults synchronize]; |
| 561 updateButtonPlacement(); | 348 updateButtonPlacement(); |
| 562 gInitialButtonDelay = [defaults floatForKey:@"NSScrollerButtonDelay"]; | 349 gInitialButtonDelay = [defaults floatForKey:@"NSScrollerButtonDelay"]; |
| 563 gAutoscrollButtonDelay = [defaults floatForKey:@"NSScrollerButtonPeriod"]; | 350 gAutoscrollButtonDelay = [defaults floatForKey:@"NSScrollerButtonPeriod"]; |
| 564 gJumpOnTrackClick = [defaults boolForKey:@"AppleScrollerPagingBehavior"]; | 351 gJumpOnTrackClick = [defaults boolForKey:@"AppleScrollerPagingBehavior"]; |
| 565 } | 352 } |
| 566 | 353 |
| 567 int ScrollbarThemeMacOverlayAPI::scrollbarThickness(ScrollbarControlSize control
Size) | |
| 568 { | |
| 569 ScrollbarPainter scrollbarPainter = [NSClassFromString(@"NSScrollerImp") scr
ollerImpWithStyle:recommendedScrollerStyle() controlSize:controlSize horizontal:
NO replacingScrollerImp:nil]; | |
| 570 if (supportsExpandedScrollbars()) | |
| 571 [scrollbarPainter setExpanded:YES]; | |
| 572 return [scrollbarPainter trackBoxWidth]; | |
| 573 } | |
| 574 | |
| 575 int ScrollbarThemeMacNonOverlayAPI::scrollbarThickness(ScrollbarControlSize cont
rolSize) | |
| 576 { | |
| 577 return cScrollbarThickness[controlSize]; | |
| 578 } | |
| 579 | |
| 580 bool ScrollbarThemeMacOverlayAPI::usesOverlayScrollbars() const | |
| 581 { | |
| 582 return recommendedScrollerStyle() == NSScrollerStyleOverlay; | |
| 583 } | |
| 584 | |
| 585 void ScrollbarThemeMacOverlayAPI::updateScrollbarOverlayStyle(ScrollbarThemeClie
nt* scrollbar) | |
| 586 { | |
| 587 ScrollbarPainter painter = painterForScrollbar(scrollbar); | |
| 588 switch (scrollbar->scrollbarOverlayStyle()) { | |
| 589 case ScrollbarOverlayStyleDefault: | |
| 590 [painter setKnobStyle:NSScrollerKnobStyleDefault]; | |
| 591 break; | |
| 592 case ScrollbarOverlayStyleDark: | |
| 593 [painter setKnobStyle:NSScrollerKnobStyleDark]; | |
| 594 break; | |
| 595 case ScrollbarOverlayStyleLight: | |
| 596 [painter setKnobStyle:NSScrollerKnobStyleLight]; | |
| 597 break; | |
| 598 } | |
| 599 } | |
| 600 | |
| 601 double ScrollbarThemeMacCommon::initialAutoscrollTimerDelay() | 354 double ScrollbarThemeMacCommon::initialAutoscrollTimerDelay() |
| 602 { | 355 { |
| 603 return gInitialButtonDelay; | 356 return gInitialButtonDelay; |
| 604 } | 357 } |
| 605 | 358 |
| 606 double ScrollbarThemeMacCommon::autoscrollTimerDelay() | 359 double ScrollbarThemeMacCommon::autoscrollTimerDelay() |
| 607 { | 360 { |
| 608 return gAutoscrollButtonDelay; | 361 return gAutoscrollButtonDelay; |
| 609 } | 362 } |
| 610 | 363 |
| 611 ScrollbarButtonsPlacement ScrollbarThemeMacOverlayAPI::buttonsPlacement() const | |
| 612 { | |
| 613 return ScrollbarButtonsNone; | |
| 614 } | |
| 615 | |
| 616 ScrollbarButtonsPlacement ScrollbarThemeMacNonOverlayAPI::buttonsPlacement() con
st | |
| 617 { | |
| 618 return gButtonPlacement; | |
| 619 } | |
| 620 | |
| 621 bool ScrollbarThemeMacNonOverlayAPI::hasButtons(ScrollbarThemeClient* scrollbar) | |
| 622 { | |
| 623 return scrollbar->enabled() && buttonsPlacement() != ScrollbarButtonsNone | |
| 624 && (scrollbar->orientation() == HorizontalScrollbar | |
| 625 ? scrollbar->width() | |
| 626 : scrollbar->height()) >= 2 * (cRealButtonLength[scrollbar->control
Size()] - cButtonHitInset[scrollbar->controlSize()]); | |
| 627 } | |
| 628 | |
| 629 bool ScrollbarThemeMacOverlayAPI::hasThumb(ScrollbarThemeClient* scrollbar) | |
| 630 { | |
| 631 ScrollbarPainter painter = painterForScrollbar(scrollbar); | |
| 632 int minLengthForThumb = [painter knobMinLength] + [painter trackOverlapEndIn
set] + [painter knobOverlapEndInset] | |
| 633 + 2 * ([painter trackEndInset] + [painter knobEndInset]); | |
| 634 return scrollbar->enabled() && (scrollbar->orientation() == HorizontalScroll
bar ? | |
| 635 scrollbar->width() : | |
| 636 scrollbar->height()) >= minLengthForThumb; | |
| 637 } | |
| 638 | |
| 639 bool ScrollbarThemeMacNonOverlayAPI::hasThumb(ScrollbarThemeClient* scrollbar) | |
| 640 { | |
| 641 int minLengthForThumb = 2 * cButtonInset[scrollbar->controlSize()] + cThumbM
inLength[scrollbar->controlSize()] + 1; | |
| 642 return scrollbar->enabled() && (scrollbar->orientation() == HorizontalScroll
bar ? | |
| 643 scrollbar->width() : | |
| 644 scrollbar->height()) >= minLengthForThumb; | |
| 645 } | |
| 646 | |
| 647 static IntRect buttonRepaintRect(const IntRect& buttonRect, ScrollbarOrientation
orientation, ScrollbarControlSize controlSize, bool start) | |
| 648 { | |
| 649 ASSERT(gButtonPlacement != ScrollbarButtonsNone); | |
| 650 | |
| 651 IntRect paintRect(buttonRect); | |
| 652 if (orientation == HorizontalScrollbar) { | |
| 653 paintRect.setWidth(cRealButtonLength[controlSize]); | |
| 654 if (!start) | |
| 655 paintRect.setX(buttonRect.x() - (cRealButtonLength[controlSize] - bu
ttonRect.width())); | |
| 656 } else { | |
| 657 paintRect.setHeight(cRealButtonLength[controlSize]); | |
| 658 if (!start) | |
| 659 paintRect.setY(buttonRect.y() - (cRealButtonLength[controlSize] - bu
ttonRect.height())); | |
| 660 } | |
| 661 | |
| 662 return paintRect; | |
| 663 } | |
| 664 | |
| 665 IntRect ScrollbarThemeMacOverlayAPI::backButtonRect(ScrollbarThemeClient* scroll
bar, ScrollbarPart part, bool painting) | |
| 666 { | |
| 667 ASSERT(buttonsPlacement() == ScrollbarButtonsNone); | |
| 668 return IntRect(); | |
| 669 } | |
| 670 | |
| 671 IntRect ScrollbarThemeMacNonOverlayAPI::backButtonRect(ScrollbarThemeClient* scr
ollbar, ScrollbarPart part, bool painting) | |
| 672 { | |
| 673 IntRect result; | |
| 674 | |
| 675 if (part == BackButtonStartPart && (buttonsPlacement() == ScrollbarButtonsNo
ne || buttonsPlacement() == ScrollbarButtonsDoubleEnd)) | |
| 676 return result; | |
| 677 | |
| 678 if (part == BackButtonEndPart && (buttonsPlacement() == ScrollbarButtonsNone
|| buttonsPlacement() == ScrollbarButtonsDoubleStart || buttonsPlacement() == S
crollbarButtonsSingle)) | |
| 679 return result; | |
| 680 | |
| 681 int thickness = scrollbarThickness(scrollbar->controlSize()); | |
| 682 bool outerButton = part == BackButtonStartPart && (buttonsPlacement() == Scr
ollbarButtonsDoubleStart || buttonsPlacement() == ScrollbarButtonsDoubleBoth); | |
| 683 if (outerButton) { | |
| 684 if (scrollbar->orientation() == HorizontalScrollbar) | |
| 685 result = IntRect(scrollbar->x(), scrollbar->y(), cOuterButtonLength[
scrollbar->controlSize()] + (painting ? cOuterButtonOverlap : 0), thickness); | |
| 686 else | |
| 687 result = IntRect(scrollbar->x(), scrollbar->y(), thickness, cOuterBu
ttonLength[scrollbar->controlSize()] + (painting ? cOuterButtonOverlap : 0)); | |
| 688 return result; | |
| 689 } | |
| 690 | |
| 691 // Our repaint rect is slightly larger, since we are a button that is adjace
nt to the track. | |
| 692 if (scrollbar->orientation() == HorizontalScrollbar) { | |
| 693 int start = part == BackButtonStartPart ? scrollbar->x() : scrollbar->x(
) + scrollbar->width() - cOuterButtonLength[scrollbar->controlSize()] - cButtonL
ength[scrollbar->controlSize()]; | |
| 694 result = IntRect(start, scrollbar->y(), cButtonLength[scrollbar->control
Size()], thickness); | |
| 695 } else { | |
| 696 int start = part == BackButtonStartPart ? scrollbar->y() : scrollbar->y(
) + scrollbar->height() - cOuterButtonLength[scrollbar->controlSize()] - cButton
Length[scrollbar->controlSize()]; | |
| 697 result = IntRect(scrollbar->x(), start, thickness, cButtonLength[scrollb
ar->controlSize()]); | |
| 698 } | |
| 699 | |
| 700 if (painting) | |
| 701 return buttonRepaintRect(result, scrollbar->orientation(), scrollbar->co
ntrolSize(), part == BackButtonStartPart); | |
| 702 return result; | |
| 703 } | |
| 704 | |
| 705 IntRect ScrollbarThemeMacOverlayAPI::forwardButtonRect(ScrollbarThemeClient* scr
ollbar, ScrollbarPart part, bool painting) | |
| 706 { | |
| 707 ASSERT(buttonsPlacement() == ScrollbarButtonsNone); | |
| 708 return IntRect(); | |
| 709 } | |
| 710 | |
| 711 IntRect ScrollbarThemeMacNonOverlayAPI::forwardButtonRect(ScrollbarThemeClient*
scrollbar, ScrollbarPart part, bool painting) | |
| 712 { | |
| 713 IntRect result; | |
| 714 | |
| 715 if (part == ForwardButtonEndPart && (buttonsPlacement() == ScrollbarButtonsN
one || buttonsPlacement() == ScrollbarButtonsDoubleStart)) | |
| 716 return result; | |
| 717 | |
| 718 if (part == ForwardButtonStartPart && (buttonsPlacement() == ScrollbarButton
sNone || buttonsPlacement() == ScrollbarButtonsDoubleEnd || buttonsPlacement() =
= ScrollbarButtonsSingle)) | |
| 719 return result; | |
| 720 | |
| 721 int thickness = scrollbarThickness(scrollbar->controlSize()); | |
| 722 int outerButtonLength = cOuterButtonLength[scrollbar->controlSize()]; | |
| 723 int buttonLength = cButtonLength[scrollbar->controlSize()]; | |
| 724 | |
| 725 bool outerButton = part == ForwardButtonEndPart && (buttonsPlacement() == Sc
rollbarButtonsDoubleEnd || buttonsPlacement() == ScrollbarButtonsDoubleBoth); | |
| 726 if (outerButton) { | |
| 727 if (scrollbar->orientation() == HorizontalScrollbar) { | |
| 728 result = IntRect(scrollbar->x() + scrollbar->width() - outerButtonLe
ngth, scrollbar->y(), outerButtonLength, thickness); | |
| 729 if (painting) | |
| 730 result.inflateX(cOuterButtonOverlap); | |
| 731 } else { | |
| 732 result = IntRect(scrollbar->x(), scrollbar->y() + scrollbar->height(
) - outerButtonLength, thickness, outerButtonLength); | |
| 733 if (painting) | |
| 734 result.inflateY(cOuterButtonOverlap); | |
| 735 } | |
| 736 return result; | |
| 737 } | |
| 738 | |
| 739 if (scrollbar->orientation() == HorizontalScrollbar) { | |
| 740 int start = part == ForwardButtonEndPart ? scrollbar->x() + scrollbar->w
idth() - buttonLength : scrollbar->x() + outerButtonLength; | |
| 741 result = IntRect(start, scrollbar->y(), buttonLength, thickness); | |
| 742 } else { | |
| 743 int start = part == ForwardButtonEndPart ? scrollbar->y() + scrollbar->h
eight() - buttonLength : scrollbar->y() + outerButtonLength; | |
| 744 result = IntRect(scrollbar->x(), start, thickness, buttonLength); | |
| 745 } | |
| 746 if (painting) | |
| 747 return buttonRepaintRect(result, scrollbar->orientation(), scrollbar->co
ntrolSize(), part == ForwardButtonStartPart); | |
| 748 return result; | |
| 749 } | |
| 750 | |
| 751 IntRect ScrollbarThemeMacOverlayAPI::trackRect(ScrollbarThemeClient* scrollbar,
bool painting) | |
| 752 { | |
| 753 ASSERT(!hasButtons(scrollbar)); | |
| 754 return scrollbar->frameRect(); | |
| 755 } | |
| 756 | |
| 757 IntRect ScrollbarThemeMacNonOverlayAPI::trackRect(ScrollbarThemeClient* scrollba
r, bool painting) | |
| 758 { | |
| 759 if (painting || !hasButtons(scrollbar)) | |
| 760 return scrollbar->frameRect(); | |
| 761 | |
| 762 IntRect result; | |
| 763 int thickness = scrollbarThickness(scrollbar->controlSize()); | |
| 764 int startWidth = 0; | |
| 765 int endWidth = 0; | |
| 766 int outerButtonLength = cOuterButtonLength[scrollbar->controlSize()]; | |
| 767 int buttonLength = cButtonLength[scrollbar->controlSize()]; | |
| 768 int doubleButtonLength = outerButtonLength + buttonLength; | |
| 769 switch (buttonsPlacement()) { | |
| 770 case ScrollbarButtonsSingle: | |
| 771 startWidth = buttonLength; | |
| 772 endWidth = buttonLength; | |
| 773 break; | |
| 774 case ScrollbarButtonsDoubleStart: | |
| 775 startWidth = doubleButtonLength; | |
| 776 break; | |
| 777 case ScrollbarButtonsDoubleEnd: | |
| 778 endWidth = doubleButtonLength; | |
| 779 break; | |
| 780 case ScrollbarButtonsDoubleBoth: | |
| 781 startWidth = doubleButtonLength; | |
| 782 endWidth = doubleButtonLength; | |
| 783 break; | |
| 784 default: | |
| 785 break; | |
| 786 } | |
| 787 | |
| 788 int totalWidth = startWidth + endWidth; | |
| 789 if (scrollbar->orientation() == HorizontalScrollbar) | |
| 790 return IntRect(scrollbar->x() + startWidth, scrollbar->y(), scrollbar->w
idth() - totalWidth, thickness); | |
| 791 return IntRect(scrollbar->x(), scrollbar->y() + startWidth, thickness, scrol
lbar->height() - totalWidth); | |
| 792 } | |
| 793 | |
| 794 int ScrollbarThemeMacOverlayAPI::minimumThumbLength(ScrollbarThemeClient* scroll
bar) | |
| 795 { | |
| 796 return [painterForScrollbar(scrollbar) knobMinLength]; | |
| 797 } | |
| 798 | |
| 799 int ScrollbarThemeMacNonOverlayAPI::minimumThumbLength(ScrollbarThemeClient* scr
ollbar) | |
| 800 { | |
| 801 return cThumbMinLength[scrollbar->controlSize()]; | |
| 802 } | |
| 803 | |
| 804 bool ScrollbarThemeMacCommon::shouldCenterOnThumb(ScrollbarThemeClient*, const P
latformMouseEvent& evt) | 364 bool ScrollbarThemeMacCommon::shouldCenterOnThumb(ScrollbarThemeClient*, const P
latformMouseEvent& evt) |
| 805 { | 365 { |
| 806 if (evt.button() != LeftButton) | 366 if (evt.button() != LeftButton) |
| 807 return false; | 367 return false; |
| 808 if (gJumpOnTrackClick) | 368 if (gJumpOnTrackClick) |
| 809 return !evt.altKey(); | 369 return !evt.altKey(); |
| 810 return evt.altKey(); | 370 return evt.altKey(); |
| 811 } | 371 } |
| 812 | 372 |
| 813 bool ScrollbarThemeMacCommon::shouldDragDocumentInsteadOfThumb(ScrollbarThemeCli
ent*, const PlatformMouseEvent& event) | 373 bool ScrollbarThemeMacCommon::shouldDragDocumentInsteadOfThumb(ScrollbarThemeCli
ent*, const PlatformMouseEvent& event) |
| (...skipping 12 matching lines...) Expand all Loading... |
| 826 return kThemeTopInsideArrowPressed; | 386 return kThemeTopInsideArrowPressed; |
| 827 case ForwardButtonEndPart: | 387 case ForwardButtonEndPart: |
| 828 return kThemeBottomOutsideArrowPressed; | 388 return kThemeBottomOutsideArrowPressed; |
| 829 case ThumbPart: | 389 case ThumbPart: |
| 830 return kThemeThumbPressed; | 390 return kThemeThumbPressed; |
| 831 default: | 391 default: |
| 832 return 0; | 392 return 0; |
| 833 } | 393 } |
| 834 } | 394 } |
| 835 | 395 |
| 836 void ScrollbarThemeMacOverlayAPI::updateEnabledState(ScrollbarThemeClient* scrol
lbar) | |
| 837 { | |
| 838 [painterForScrollbar(scrollbar) setEnabled:scrollbar->enabled()]; | |
| 839 } | |
| 840 | |
| 841 } // namespace WebCore | 396 } // namespace WebCore |
| OLD | NEW |