| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (C) 2008 Apple Inc. All Rights Reserved. | 2 * Copyright (C) 2008 Apple Inc. All Rights Reserved. |
| 3 * Copyright (C) 2009 Google Inc. All Rights Reserved. | 3 * Copyright (C) 2009 Google Inc. All Rights Reserved. |
| 4 * | 4 * |
| 5 * Redistribution and use in source and binary forms, with or without | 5 * Redistribution and use in source and binary forms, with or without |
| 6 * modification, are permitted provided that the following conditions | 6 * modification, are permitted provided that the following conditions |
| 7 * are met: | 7 * are met: |
| 8 * 1. Redistributions of source code must retain the above copyright | 8 * 1. Redistributions of source code must retain the above copyright |
| 9 * notice, this list of conditions and the following disclaimer. | 9 * notice, this list of conditions and the following disclaimer. |
| 10 * 2. Redistributions in binary form must reproduce the above copyright | 10 * 2. Redistributions in binary form must reproduce the above copyright |
| (...skipping 11 matching lines...) Expand all Loading... |
| 22 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | 22 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 23 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | 23 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 24 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 24 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 25 */ | 25 */ |
| 26 | 26 |
| 27 #include "config.h" | 27 #include "config.h" |
| 28 #include "ScrollbarThemeChromiumMac.h" | 28 #include "ScrollbarThemeChromiumMac.h" |
| 29 | 29 |
| 30 #include "FrameView.h" | 30 #include "FrameView.h" |
| 31 #include "ImageBuffer.h" | 31 #include "ImageBuffer.h" |
| 32 #include "LocalCurrentGraphicsContext.h" |
| 32 #include "PlatformBridge.h" | 33 #include "PlatformBridge.h" |
| 33 #include "PlatformMouseEvent.h" | 34 #include "PlatformMouseEvent.h" |
| 35 #include "ScrollAnimatorChromiumMac.h" |
| 34 #include "ScrollView.h" | 36 #include "ScrollView.h" |
| 35 #include <Carbon/Carbon.h> | 37 #include <Carbon/Carbon.h> |
| 38 #include <wtf/HashMap.h> |
| 36 #include <wtf/StdLibExtras.h> | 39 #include <wtf/StdLibExtras.h> |
| 37 #include <wtf/UnusedParam.h> | 40 #include <wtf/UnusedParam.h> |
| 38 | 41 |
| 39 | 42 |
| 40 // FIXME: There are repainting problems due to Aqua scroll bar buttons' visual o
verflow. | 43 // FIXME: There are repainting problems due to Aqua scroll bar buttons' visual o
verflow. |
| 41 | 44 |
| 42 using namespace std; | 45 using namespace std; |
| 43 using namespace WebCore; | 46 using namespace WebCore; |
| 44 | 47 |
| 45 // This file (and its associated .h file) is a clone of ScrollbarThemeMac.mm. | 48 // This file (and its associated .h file) is a clone of ScrollbarThemeMac.mm. |
| 46 // Because we want to draw tickmarks in the scrollbar, we must maintain a fork. | 49 // Because we want to draw tickmarks in the scrollbar, we must maintain a fork. |
| 47 // Please maintain this file by performing parallel changes to it. | 50 // Please maintain this file by performing parallel changes to it. |
| 48 // | 51 // |
| 49 // The only changes from ScrollbarThemeMac should be: | 52 // The only changes from ScrollbarThemeMac should be: |
| 50 // - The classname change from ScrollbarThemeMac to ScrollbarThemeChromiumMac. | 53 // - The classname change from ScrollbarThemeMac to ScrollbarThemeChromiumMac. |
| 51 // - In paint() the code to paint the track, tickmarks, and thumb separately. | 54 // - In paint() the code to paint the track, tickmarks, and thumb separately. |
| 52 // - In paint() the thumb is drawn via ChromeBridge/WebThemeEngine. | 55 // - In paint() the thumb is drawn via ChromeBridge/WebThemeEngine. |
| 56 // - Various functions that were split using #if USE(WK_SCROLLBAR_PAINTER) |
| 57 // have been combined using runtime checks instead. |
| 53 // | 58 // |
| 54 // For all other differences, if it was introduced in this file, then the | 59 // For all other differences, if it was introduced in this file, then the |
| 55 // maintainer forgot to include it in the list; otherwise it is an update that | 60 // maintainer forgot to include it in the list; otherwise it is an update that |
| 56 // should have been applied to this file but was not. | 61 // should have been applied to this file but was not. |
| 57 | 62 |
| 58 static HashSet<Scrollbar*>* gScrollbars; | 63 namespace WebCore { |
| 64 |
| 65 typedef HashMap<Scrollbar*, RetainPtr<WKScrollbarPainterRef> > ScrollbarPainterM
ap; |
| 66 |
| 67 static ScrollbarPainterMap* scrollbarMap() |
| 68 { |
| 69 static ScrollbarPainterMap* map = new ScrollbarPainterMap; |
| 70 return map; |
| 71 } |
| 72 |
| 73 } |
| 59 | 74 |
| 60 @interface ScrollbarPrefsObserver : NSObject | 75 @interface ScrollbarPrefsObserver : NSObject |
| 61 { | 76 { |
| 62 | |
| 63 } | 77 } |
| 64 | 78 |
| 65 + (void)registerAsObserver; | 79 + (void)registerAsObserver; |
| 66 + (void)appearancePrefsChanged:(NSNotification*)theNotification; | 80 + (void)appearancePrefsChanged:(NSNotification*)theNotification; |
| 67 + (void)behaviorPrefsChanged:(NSNotification*)theNotification; | 81 + (void)behaviorPrefsChanged:(NSNotification*)theNotification; |
| 68 | 82 |
| 69 @end | 83 @end |
| 70 | 84 |
| 71 @implementation ScrollbarPrefsObserver | 85 @implementation ScrollbarPrefsObserver |
| 72 | 86 |
| 73 + (void)appearancePrefsChanged:(NSNotification*)unusedNotification | 87 + (void)appearancePrefsChanged:(NSNotification*)unusedNotification |
| 74 { | 88 { |
| 75 UNUSED_PARAM(unusedNotification); | 89 UNUSED_PARAM(unusedNotification); |
| 76 | 90 |
| 77 static_cast<ScrollbarThemeChromiumMac*>(ScrollbarTheme::nativeTheme())->pref
erencesChanged(); | 91 static_cast<ScrollbarThemeChromiumMac*>(ScrollbarTheme::nativeTheme())->pref
erencesChanged(); |
| 78 if (!gScrollbars) | 92 if (scrollbarMap()->isEmpty()) |
| 79 return; | 93 return; |
| 80 HashSet<Scrollbar*>::iterator end = gScrollbars->end(); | 94 ScrollbarPainterMap::iterator end = scrollbarMap()->end(); |
| 81 for (HashSet<Scrollbar*>::iterator it = gScrollbars->begin(); it != end; ++i
t) { | 95 for (ScrollbarPainterMap::iterator it = scrollbarMap()->begin(); it != end;
++it) { |
| 82 (*it)->styleChanged(); | 96 it->first->styleChanged(); |
| 83 (*it)->invalidate(); | 97 it->first->invalidate(); |
| 84 } | 98 } |
| 85 } | 99 } |
| 86 | 100 |
| 87 + (void)behaviorPrefsChanged:(NSNotification*)unusedNotification | 101 + (void)behaviorPrefsChanged:(NSNotification*)unusedNotification |
| 88 { | 102 { |
| 89 UNUSED_PARAM(unusedNotification); | 103 UNUSED_PARAM(unusedNotification); |
| 90 | 104 |
| 91 static_cast<ScrollbarThemeChromiumMac*>(ScrollbarTheme::nativeTheme())->pref
erencesChanged(); | 105 static_cast<ScrollbarThemeChromiumMac*>(ScrollbarTheme::nativeTheme())->pref
erencesChanged(); |
| 92 } | 106 } |
| 93 | 107 |
| (...skipping 21 matching lines...) Expand all Loading... |
| 115 // cRealButtonLength - cButtonInset | 129 // cRealButtonLength - cButtonInset |
| 116 static int cButtonLength[] = { 14, 10 }; | 130 static int cButtonLength[] = { 14, 10 }; |
| 117 static int cThumbMinLength[] = { 26, 20 }; | 131 static int cThumbMinLength[] = { 26, 20 }; |
| 118 | 132 |
| 119 static int cOuterButtonLength[] = { 16, 14 }; // The outer button in a double bu
tton pair is a bit bigger. | 133 static int cOuterButtonLength[] = { 16, 14 }; // The outer button in a double bu
tton pair is a bit bigger. |
| 120 static int cOuterButtonOverlap = 2; | 134 static int cOuterButtonOverlap = 2; |
| 121 | 135 |
| 122 static float gInitialButtonDelay = 0.5f; | 136 static float gInitialButtonDelay = 0.5f; |
| 123 static float gAutoscrollButtonDelay = 0.05f; | 137 static float gAutoscrollButtonDelay = 0.05f; |
| 124 static bool gJumpOnTrackClick = false; | 138 static bool gJumpOnTrackClick = false; |
| 125 static ScrollbarButtonsPlacement gButtonPlacement = ScrollbarButtonsDoubleEnd; | 139 static ScrollbarButtonsPlacement gButtonPlacement = isScrollbarOverlayAPIAvailab
le() ? ScrollbarButtonsNone : ScrollbarButtonsDoubleEnd; |
| 126 | 140 |
| 127 static void updateArrowPlacement() | 141 static void updateArrowPlacement() |
| 128 { | 142 { |
| 143 if (isScrollbarOverlayAPIAvailable()) |
| 144 return; |
| 145 |
| 129 NSString *buttonPlacement = [[NSUserDefaults standardUserDefaults] objectFor
Key:@"AppleScrollBarVariant"]; | 146 NSString *buttonPlacement = [[NSUserDefaults standardUserDefaults] objectFor
Key:@"AppleScrollBarVariant"]; |
| 130 if ([buttonPlacement isEqualToString:@"Single"]) | 147 if ([buttonPlacement isEqualToString:@"Single"]) |
| 131 gButtonPlacement = ScrollbarButtonsSingle; | 148 gButtonPlacement = ScrollbarButtonsSingle; |
| 132 else if ([buttonPlacement isEqualToString:@"DoubleMin"]) | 149 else if ([buttonPlacement isEqualToString:@"DoubleMin"]) |
| 133 gButtonPlacement = ScrollbarButtonsDoubleStart; | 150 gButtonPlacement = ScrollbarButtonsDoubleStart; |
| 134 else if ([buttonPlacement isEqualToString:@"DoubleBoth"]) | 151 else if ([buttonPlacement isEqualToString:@"DoubleBoth"]) |
| 135 gButtonPlacement = ScrollbarButtonsDoubleBoth; | 152 gButtonPlacement = ScrollbarButtonsDoubleBoth; |
| 136 else | 153 else |
| 137 gButtonPlacement = ScrollbarButtonsDoubleEnd; // The default is Scrollba
rButtonsDoubleEnd. | 154 gButtonPlacement = ScrollbarButtonsDoubleEnd; |
| 138 } | 155 } |
| 139 | 156 |
| 140 void ScrollbarThemeChromiumMac::registerScrollbar(Scrollbar* scrollbar) | 157 void ScrollbarThemeChromiumMac::registerScrollbar(Scrollbar* scrollbar) |
| 141 { | 158 { |
| 142 if (!gScrollbars) | 159 bool isHorizontal = scrollbar->orientation() == HorizontalScrollbar; |
| 143 gScrollbars = new HashSet<Scrollbar*>; | 160 WKScrollbarPainterRef scrollbarPainter = wkMakeScrollbarPainter(scrollbar->c
ontrolSize(), isHorizontal); |
| 144 gScrollbars->add(scrollbar); | 161 scrollbarMap()->add(scrollbar, scrollbarPainter); |
| 145 } | 162 } |
| 146 | 163 |
| 147 void ScrollbarThemeChromiumMac::unregisterScrollbar(Scrollbar* scrollbar) | 164 void ScrollbarThemeChromiumMac::unregisterScrollbar(Scrollbar* scrollbar) |
| 148 { | 165 { |
| 149 gScrollbars->remove(scrollbar); | 166 scrollbarMap()->remove(scrollbar); |
| 150 if (gScrollbars->isEmpty()) { | 167 } |
| 151 delete gScrollbars; | 168 |
| 152 gScrollbars = 0; | 169 void ScrollbarThemeChromiumMac::setNewPainterForScrollbar(Scrollbar* scrollbar,
WKScrollbarPainterRef newPainter) |
| 153 } | 170 { |
| 171 scrollbarMap()->set(scrollbar, newPainter); |
| 172 } |
| 173 |
| 174 WKScrollbarPainterRef ScrollbarThemeChromiumMac::painterForScrollbar(Scrollbar*
scrollbar) |
| 175 { |
| 176 return scrollbarMap()->get(scrollbar).get(); |
| 154 } | 177 } |
| 155 | 178 |
| 156 ScrollbarThemeChromiumMac::ScrollbarThemeChromiumMac() | 179 ScrollbarThemeChromiumMac::ScrollbarThemeChromiumMac() |
| 157 { | 180 { |
| 158 static bool initialized; | 181 static bool initialized; |
| 159 if (!initialized) { | 182 if (!initialized) { |
| 160 initialized = true; | 183 initialized = true; |
| 161 [ScrollbarPrefsObserver registerAsObserver]; | 184 [ScrollbarPrefsObserver registerAsObserver]; |
| 162 preferencesChanged(); | 185 preferencesChanged(); |
| 163 } | 186 } |
| 164 } | 187 } |
| 165 | 188 |
| 166 ScrollbarThemeChromiumMac::~ScrollbarThemeChromiumMac() | 189 ScrollbarThemeChromiumMac::~ScrollbarThemeChromiumMac() |
| 167 { | 190 { |
| 168 } | 191 } |
| 169 | 192 |
| 170 void ScrollbarThemeChromiumMac::preferencesChanged() | 193 void ScrollbarThemeChromiumMac::preferencesChanged() |
| 171 { | 194 { |
| 172 NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults]; | 195 NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults]; |
| 173 [defaults synchronize]; | 196 [defaults synchronize]; |
| 174 updateArrowPlacement(); | 197 updateArrowPlacement(); |
| 175 gInitialButtonDelay = [defaults floatForKey:@"NSScrollerButtonDelay"]; | 198 gInitialButtonDelay = [defaults floatForKey:@"NSScrollerButtonDelay"]; |
| 176 gAutoscrollButtonDelay = [defaults floatForKey:@"NSScrollerButtonPeriod"]; | 199 gAutoscrollButtonDelay = [defaults floatForKey:@"NSScrollerButtonPeriod"]; |
| 177 gJumpOnTrackClick = [defaults boolForKey:@"AppleScrollerPagingBehavior"]; | 200 gJumpOnTrackClick = [defaults boolForKey:@"AppleScrollerPagingBehavior"]; |
| 178 } | 201 } |
| 179 | 202 |
| 180 int ScrollbarThemeChromiumMac::scrollbarThickness(ScrollbarControlSize controlSi
ze) | 203 int ScrollbarThemeChromiumMac::scrollbarThickness(ScrollbarControlSize controlSi
ze) |
| 181 { | 204 { |
| 182 return cScrollbarThickness[controlSize]; | 205 if (isScrollbarOverlayAPIAvailable()) |
| 206 return wkScrollbarThickness(controlSize); |
| 207 else |
| 208 return cScrollbarThickness[controlSize]; |
| 209 } |
| 210 |
| 211 bool ScrollbarThemeChromiumMac::usesOverlayScrollbars() const |
| 212 { |
| 213 if (isScrollbarOverlayAPIAvailable()) |
| 214 return wkScrollbarPainterUsesOverlayScrollers(); |
| 215 else |
| 216 return false; |
| 183 } | 217 } |
| 184 | 218 |
| 185 double ScrollbarThemeChromiumMac::initialAutoscrollTimerDelay() | 219 double ScrollbarThemeChromiumMac::initialAutoscrollTimerDelay() |
| 186 { | 220 { |
| 187 return gInitialButtonDelay; | 221 return gInitialButtonDelay; |
| 188 } | 222 } |
| 189 | 223 |
| 190 double ScrollbarThemeChromiumMac::autoscrollTimerDelay() | 224 double ScrollbarThemeChromiumMac::autoscrollTimerDelay() |
| 191 { | 225 { |
| 192 return gAutoscrollButtonDelay; | 226 return gAutoscrollButtonDelay; |
| 193 } | 227 } |
| 194 | 228 |
| 195 ScrollbarButtonsPlacement ScrollbarThemeChromiumMac::buttonsPlacement() const | 229 ScrollbarButtonsPlacement ScrollbarThemeChromiumMac::buttonsPlacement() const |
| 196 { | 230 { |
| 197 return gButtonPlacement; | 231 return gButtonPlacement; |
| 198 } | 232 } |
| 199 | 233 |
| 200 bool ScrollbarThemeChromiumMac::hasButtons(Scrollbar* scrollbar) | 234 bool ScrollbarThemeChromiumMac::hasButtons(Scrollbar* scrollbar) |
| 201 { | 235 { |
| 202 return scrollbar->enabled() && (scrollbar->orientation() == HorizontalScroll
bar ? | 236 return scrollbar->enabled() && gButtonPlacement != ScrollbarButtonsNone |
| 203 scrollbar->width() : | 237 && (scrollbar->orientation() == HorizontalScrollbar |
| 204 scrollbar->height()) >= 2 * (cRealButtonLength[scrollbar->controlSi
ze()] - cButtonHitInset[scrollbar->controlSize()]); | 238 ? scrollbar->width() |
| 239 : scrollbar->height()) >= 2 * (cRealButtonLength[scrollbar->control
Size()] - cButtonHitInset[scrollbar->controlSize()]); |
| 205 } | 240 } |
| 206 | 241 |
| 207 bool ScrollbarThemeChromiumMac::hasThumb(Scrollbar* scrollbar) | 242 bool ScrollbarThemeChromiumMac::hasThumb(Scrollbar* scrollbar) |
| 208 { | 243 { |
| 244 int minLengthForThumb; |
| 245 if (isScrollbarOverlayAPIAvailable()) |
| 246 minLengthForThumb = wkScrollbarMinimumTotalLengthNeededForThumb(scrollba
rMap()->get(scrollbar).get()); |
| 247 else |
| 248 minLengthForThumb = 2 * cButtonInset[scrollbar->controlSize()] + cThumbM
inLength[scrollbar->controlSize()] + 1; |
| 209 return scrollbar->enabled() && (scrollbar->orientation() == HorizontalScroll
bar ? | 249 return scrollbar->enabled() && (scrollbar->orientation() == HorizontalScroll
bar ? |
| 210 scrollbar->width() : | 250 scrollbar->width() : |
| 211 scrollbar->height()) >= 2 * cButtonInset[scrollbar->controlSize()]
+ cThumbMinLength[scrollbar->controlSize()] + 1; | 251 scrollbar->height()) >= minLengthForThumb; |
| 212 } | 252 } |
| 213 | 253 |
| 214 static IntRect buttonRepaintRect(const IntRect& buttonRect, ScrollbarOrientation
orientation, ScrollbarControlSize controlSize, bool start) | 254 static IntRect buttonRepaintRect(const IntRect& buttonRect, ScrollbarOrientation
orientation, ScrollbarControlSize controlSize, bool start) |
| 215 { | 255 { |
| 256 ASSERT(gButtonPlacement != ScrollbarButtonsNone); |
| 257 |
| 216 IntRect paintRect(buttonRect); | 258 IntRect paintRect(buttonRect); |
| 217 if (orientation == HorizontalScrollbar) { | 259 if (orientation == HorizontalScrollbar) { |
| 218 paintRect.setWidth(cRealButtonLength[controlSize]); | 260 paintRect.setWidth(cRealButtonLength[controlSize]); |
| 219 if (!start) | 261 if (!start) |
| 220 paintRect.setX(buttonRect.x() - (cRealButtonLength[controlSize] - bu
ttonRect.width())); | 262 paintRect.setX(buttonRect.x() - (cRealButtonLength[controlSize] - bu
ttonRect.width())); |
| 221 } else { | 263 } else { |
| 222 paintRect.setHeight(cRealButtonLength[controlSize]); | 264 paintRect.setHeight(cRealButtonLength[controlSize]); |
| 223 if (!start) | 265 if (!start) |
| 224 paintRect.setY(buttonRect.y() - (cRealButtonLength[controlSize] - bu
ttonRect.height())); | 266 paintRect.setY(buttonRect.y() - (cRealButtonLength[controlSize] - bu
ttonRect.height())); |
| 225 } | 267 } |
| (...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 333 } | 375 } |
| 334 | 376 |
| 335 int totalWidth = startWidth + endWidth; | 377 int totalWidth = startWidth + endWidth; |
| 336 if (scrollbar->orientation() == HorizontalScrollbar) | 378 if (scrollbar->orientation() == HorizontalScrollbar) |
| 337 return IntRect(scrollbar->x() + startWidth, scrollbar->y(), scrollbar->w
idth() - totalWidth, thickness); | 379 return IntRect(scrollbar->x() + startWidth, scrollbar->y(), scrollbar->w
idth() - totalWidth, thickness); |
| 338 return IntRect(scrollbar->x(), scrollbar->y() + startWidth, thickness, scrol
lbar->height() - totalWidth); | 380 return IntRect(scrollbar->x(), scrollbar->y() + startWidth, thickness, scrol
lbar->height() - totalWidth); |
| 339 } | 381 } |
| 340 | 382 |
| 341 int ScrollbarThemeChromiumMac::minimumThumbLength(Scrollbar* scrollbar) | 383 int ScrollbarThemeChromiumMac::minimumThumbLength(Scrollbar* scrollbar) |
| 342 { | 384 { |
| 343 return cThumbMinLength[scrollbar->controlSize()]; | 385 if (isScrollbarOverlayAPIAvailable()) |
| 386 return wkScrollbarMinimumThumbLength(scrollbarMap()->get(scrollbar).get(
)); |
| 387 else |
| 388 return cThumbMinLength[scrollbar->controlSize()]; |
| 344 } | 389 } |
| 345 | 390 |
| 346 bool ScrollbarThemeChromiumMac::shouldCenterOnThumb(Scrollbar*, const PlatformMo
useEvent& evt) | 391 bool ScrollbarThemeChromiumMac::shouldCenterOnThumb(Scrollbar*, const PlatformMo
useEvent& evt) |
| 347 { | 392 { |
| 348 if (evt.button() != LeftButton) | 393 if (evt.button() != LeftButton) |
| 349 return false; | 394 return false; |
| 350 if (gJumpOnTrackClick) | 395 if (gJumpOnTrackClick) |
| 351 return !evt.altKey(); | 396 return !evt.altKey(); |
| 352 return evt.altKey(); | 397 return evt.altKey(); |
| 353 } | 398 } |
| 354 | 399 |
| 400 bool ScrollbarThemeChromiumMac::shouldDragDocumentInsteadOfThumb(Scrollbar*, con
st PlatformMouseEvent& event) |
| 401 { |
| 402 return event.altKey(); |
| 403 } |
| 404 |
| 355 static int scrollbarPartToHIPressedState(ScrollbarPart part) | 405 static int scrollbarPartToHIPressedState(ScrollbarPart part) |
| 356 { | 406 { |
| 357 switch (part) { | 407 switch (part) { |
| 358 case BackButtonStartPart: | 408 case BackButtonStartPart: |
| 359 return kThemeTopOutsideArrowPressed; | 409 return kThemeTopOutsideArrowPressed; |
| 360 case BackButtonEndPart: | 410 case BackButtonEndPart: |
| 361 return kThemeTopOutsideArrowPressed; // This does not make much sens
e. For some reason the outside constant is required. | 411 return kThemeTopOutsideArrowPressed; // This does not make much sens
e. For some reason the outside constant is required. |
| 362 case ForwardButtonStartPart: | 412 case ForwardButtonStartPart: |
| 363 return kThemeTopInsideArrowPressed; | 413 return kThemeTopInsideArrowPressed; |
| 364 case ForwardButtonEndPart: | 414 case ForwardButtonEndPart: |
| 365 return kThemeBottomOutsideArrowPressed; | 415 return kThemeBottomOutsideArrowPressed; |
| 366 case ThumbPart: | 416 case ThumbPart: |
| 367 return kThemeThumbPressed; | 417 return kThemeThumbPressed; |
| 368 default: | 418 default: |
| 369 return 0; | 419 return 0; |
| 370 } | 420 } |
| 371 } | 421 } |
| 372 | 422 |
| 423 static inline wkScrollerKnobStyle toScrollbarPainterKnobStyle(ScrollbarOverlaySt
yle style) |
| 424 { |
| 425 switch (style) { |
| 426 case ScrollbarOverlayStyleDark: |
| 427 return wkScrollerKnobStyleDark; |
| 428 case ScrollbarOverlayStyleLight: |
| 429 return wkScrollerKnobStyleLight; |
| 430 default: |
| 431 return wkScrollerKnobStyleDefault; |
| 432 } |
| 433 } |
| 434 |
| 373 static PlatformBridge::ThemePaintState scrollbarStateToThemeState(Scrollbar* scr
ollbar) { | 435 static PlatformBridge::ThemePaintState scrollbarStateToThemeState(Scrollbar* scr
ollbar) { |
| 374 if (!scrollbar->enabled()) | 436 if (!scrollbar->enabled()) |
| 375 return PlatformBridge::StateDisabled; | 437 return PlatformBridge::StateDisabled; |
| 376 if (!scrollbar->scrollableArea()->isActive()) | 438 if (!scrollbar->scrollableArea()->isActive()) |
| 377 return PlatformBridge::StateInactive; | 439 return PlatformBridge::StateInactive; |
| 378 if (scrollbar->pressedPart() == ThumbPart) | 440 if (scrollbar->pressedPart() == ThumbPart) |
| 379 return PlatformBridge::StatePressed; | 441 return PlatformBridge::StatePressed; |
| 380 | 442 |
| 381 return PlatformBridge::StateActive; | 443 return PlatformBridge::StateActive; |
| 382 } | 444 } |
| 383 | 445 |
| 384 bool ScrollbarThemeChromiumMac::paint(Scrollbar* scrollbar, GraphicsContext* con
text, const IntRect& damageRect) | 446 bool ScrollbarThemeChromiumMac::paint(Scrollbar* scrollbar, GraphicsContext* con
text, const IntRect& damageRect) |
| 385 { | 447 { |
| 448 if (isScrollbarOverlayAPIAvailable()) { |
| 449 float value = 0; |
| 450 float overhang = 0; |
| 451 |
| 452 if (scrollbar->currentPos() < 0) { |
| 453 // Scrolled past the top. |
| 454 value = 0; |
| 455 overhang = -scrollbar->currentPos(); |
| 456 } else if (scrollbar->visibleSize() + scrollbar->currentPos() > scrollba
r->totalSize()) { |
| 457 // Scrolled past the bottom. |
| 458 value = 1; |
| 459 overhang = scrollbar->currentPos() + scrollbar->visibleSize() - scro
llbar->totalSize(); |
| 460 } else { |
| 461 // Within the bounds of the scrollable area. |
| 462 int maximum = scrollbar->maximum(); |
| 463 if (maximum > 0) |
| 464 value = scrollbar->currentPos() / maximum; |
| 465 else |
| 466 value = 0; |
| 467 } |
| 468 |
| 469 ScrollAnimatorChromiumMac* scrollAnimator = static_cast<ScrollAnimatorCh
romiumMac*>(scrollbar->scrollableArea()->scrollAnimator()); |
| 470 scrollAnimator->setIsDrawingIntoLayer(context->isCALayerContext()); |
| 471 |
| 472 wkSetScrollbarPainterKnobStyle(painterForScrollbar(scrollbar), toScrollb
arPainterKnobStyle(scrollbar->scrollableArea()->recommendedScrollbarOverlayStyle
())); |
| 473 |
| 474 GraphicsContextStateSaver stateSaver(*context); |
| 475 context->clip(damageRect); |
| 476 context->translate(scrollbar->frameRect().x(), scrollbar->frameRect().y(
)); |
| 477 LocalCurrentGraphicsContext localContext(context); |
| 478 wkScrollbarPainterPaint(scrollbarMap()->get(scrollbar).get(), |
| 479 scrollbar->enabled(), |
| 480 value, |
| 481 (static_cast<CGFloat>(scrollbar->visibleSize())
- overhang) / scrollbar->totalSize(), |
| 482 scrollbar->frameRect()); |
| 483 |
| 484 scrollAnimator->setIsDrawingIntoLayer(false); |
| 485 return true; |
| 486 } |
| 487 |
| 386 HIThemeTrackDrawInfo trackInfo; | 488 HIThemeTrackDrawInfo trackInfo; |
| 387 trackInfo.version = 0; | 489 trackInfo.version = 0; |
| 388 trackInfo.kind = scrollbar->controlSize() == RegularScrollbar ? kThemeMedium
ScrollBar : kThemeSmallScrollBar; | 490 trackInfo.kind = scrollbar->controlSize() == RegularScrollbar ? kThemeMedium
ScrollBar : kThemeSmallScrollBar; |
| 389 trackInfo.bounds = scrollbar->frameRect(); | 491 trackInfo.bounds = scrollbar->frameRect(); |
| 390 trackInfo.min = 0; | 492 trackInfo.min = 0; |
| 391 trackInfo.max = scrollbar->maximum(); | 493 trackInfo.max = scrollbar->maximum(); |
| 392 trackInfo.value = scrollbar->currentPos(); | 494 trackInfo.value = scrollbar->currentPos(); |
| 393 trackInfo.trackInfo.scrollbar.viewsize = scrollbar->visibleSize(); | 495 trackInfo.trackInfo.scrollbar.viewsize = scrollbar->visibleSize(); |
| 394 trackInfo.attributes = 0; | 496 trackInfo.attributes = 0; |
| 395 if (scrollbar->orientation() == HorizontalScrollbar) | 497 if (scrollbar->orientation() == HorizontalScrollbar) |
| (...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 479 scrollbarInfo); | 581 scrollbarInfo); |
| 480 } | 582 } |
| 481 | 583 |
| 482 if (!canDrawDirectly) | 584 if (!canDrawDirectly) |
| 483 context->drawImageBuffer(imageBuffer.get(), ColorSpaceDeviceRGB, scrollb
ar->frameRect().location()); | 585 context->drawImageBuffer(imageBuffer.get(), ColorSpaceDeviceRGB, scrollb
ar->frameRect().location()); |
| 484 | 586 |
| 485 return true; | 587 return true; |
| 486 } | 588 } |
| 487 | 589 |
| 488 } | 590 } |
| 489 | |
| OLD | NEW |