Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 /* | 1 /* |
| 2 * Copyright (C) 2011 Apple Inc. All Rights Reserved. | 2 * Copyright (C) 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 219 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 230 mousePosition.move(scrollbar.x(), scrollbar.y()); | 230 mousePosition.move(scrollbar.x(), scrollbar.y()); |
| 231 return Platform::current()->scrollbarBehavior()->shouldSnapBackToDragOrigin( | 231 return Platform::current()->scrollbarBehavior()->shouldSnapBackToDragOrigin( |
| 232 mousePosition, trackRect(scrollbar), | 232 mousePosition, trackRect(scrollbar), |
| 233 scrollbar.orientation() == HorizontalScrollbar); | 233 scrollbar.orientation() == HorizontalScrollbar); |
| 234 } | 234 } |
| 235 | 235 |
| 236 int ScrollbarTheme::thumbPosition(const ScrollbarThemeClient& scrollbar, | 236 int ScrollbarTheme::thumbPosition(const ScrollbarThemeClient& scrollbar, |
| 237 float scrollPosition) { | 237 float scrollPosition) { |
| 238 if (scrollbar.enabled()) { | 238 if (scrollbar.enabled()) { |
| 239 float size = scrollbar.totalSize() - scrollbar.visibleSize(); | 239 float size = scrollbar.totalSize() - scrollbar.visibleSize(); |
| 240 // Avoid doing a floating point divide by zero and return 1 when usedTotalSi ze == visibleSize. | 240 // Avoid doing a floating point divide by zero and return 1 when |
| 241 // usedTotalSize == visibleSize. | |
| 241 if (!size) | 242 if (!size) |
| 242 return 0; | 243 return 0; |
| 243 float pos = std::max(0.0f, scrollPosition) * | 244 float pos = std::max(0.0f, scrollPosition) * |
| 244 (trackLength(scrollbar) - thumbLength(scrollbar)) / size; | 245 (trackLength(scrollbar) - thumbLength(scrollbar)) / size; |
| 245 return (pos < 1 && pos > 0) ? 1 : pos; | 246 return (pos < 1 && pos > 0) ? 1 : pos; |
| 246 } | 247 } |
| 247 return 0; | 248 return 0; |
| 248 } | 249 } |
| 249 | 250 |
| 250 int ScrollbarTheme::thumbLength(const ScrollbarThemeClient& scrollbar) { | 251 int ScrollbarTheme::thumbLength(const ScrollbarThemeClient& scrollbar) { |
| 251 if (!scrollbar.enabled()) | 252 if (!scrollbar.enabled()) |
| 252 return 0; | 253 return 0; |
| 253 | 254 |
| 254 float overhang = fabsf(scrollbar.elasticOverscroll()); | 255 float overhang = fabsf(scrollbar.elasticOverscroll()); |
| 255 float proportion = 0.0f; | 256 float proportion = 0.0f; |
| 256 float totalSize = scrollbar.totalSize(); | 257 float totalSize = scrollbar.totalSize(); |
| 257 if (totalSize > 0.0f) { | 258 if (totalSize > 0.0f) { |
| 258 proportion = (scrollbar.visibleSize() - overhang) / totalSize; | 259 proportion = (scrollbar.visibleSize() - overhang) / totalSize; |
| 259 } | 260 } |
| 260 int trackLen = trackLength(scrollbar); | 261 int trackLen = trackLength(scrollbar); |
| 261 int length = round(proportion * trackLen); | 262 int length = round(proportion * trackLen); |
| 262 length = std::max(length, minimumThumbLength(scrollbar)); | 263 length = std::max(length, minimumThumbLength(scrollbar)); |
| 263 if (length > trackLen) | 264 if (length > trackLen) |
| 264 length = | 265 length = 0; // Once the thumb is below the track length, it just goes away |
| 265 0; // Once the thumb is below the track length, it just goes away (to m ake more room for the track). | 266 // (to make more room for the track). |
|
pdr.
2016/10/03 21:30:50
This looks like it was an edge-case mistake in the
Nico
2016/10/03 21:34:42
I think "ReflowComments: false" triggers this. Whe
| |
| 266 return length; | 267 return length; |
| 267 } | 268 } |
| 268 | 269 |
| 269 int ScrollbarTheme::trackPosition(const ScrollbarThemeClient& scrollbar) { | 270 int ScrollbarTheme::trackPosition(const ScrollbarThemeClient& scrollbar) { |
| 270 IntRect constrainedTrackRect = | 271 IntRect constrainedTrackRect = |
| 271 constrainTrackRectToTrackPieces(scrollbar, trackRect(scrollbar)); | 272 constrainTrackRectToTrackPieces(scrollbar, trackRect(scrollbar)); |
| 272 return (scrollbar.orientation() == HorizontalScrollbar) | 273 return (scrollbar.orientation() == HorizontalScrollbar) |
| 273 ? constrainedTrackRect.x() - scrollbar.x() | 274 ? constrainedTrackRect.x() - scrollbar.x() |
| 274 : constrainedTrackRect.y() - scrollbar.y(); | 275 : constrainedTrackRect.y() - scrollbar.y(); |
| 275 } | 276 } |
| (...skipping 27 matching lines...) Expand all Loading... | |
| 303 | 304 |
| 304 int ScrollbarTheme::minimumThumbLength(const ScrollbarThemeClient& scrollbar) { | 305 int ScrollbarTheme::minimumThumbLength(const ScrollbarThemeClient& scrollbar) { |
| 305 return scrollbarThickness(scrollbar.controlSize()); | 306 return scrollbarThickness(scrollbar.controlSize()); |
| 306 } | 307 } |
| 307 | 308 |
| 308 void ScrollbarTheme::splitTrack(const ScrollbarThemeClient& scrollbar, | 309 void ScrollbarTheme::splitTrack(const ScrollbarThemeClient& scrollbar, |
| 309 const IntRect& unconstrainedTrackRect, | 310 const IntRect& unconstrainedTrackRect, |
| 310 IntRect& beforeThumbRect, | 311 IntRect& beforeThumbRect, |
| 311 IntRect& thumbRect, | 312 IntRect& thumbRect, |
| 312 IntRect& afterThumbRect) { | 313 IntRect& afterThumbRect) { |
| 313 // This function won't even get called unless we're big enough to have some co mbination of these three rects where at least | 314 // This function won't even get called unless we're big enough to have some |
| 314 // one of them is non-empty. | 315 // combination of these three rects where at least one of them is non-empty. |
| 315 IntRect trackRect = | 316 IntRect trackRect = |
| 316 constrainTrackRectToTrackPieces(scrollbar, unconstrainedTrackRect); | 317 constrainTrackRectToTrackPieces(scrollbar, unconstrainedTrackRect); |
| 317 int thumbPos = thumbPosition(scrollbar); | 318 int thumbPos = thumbPosition(scrollbar); |
| 318 if (scrollbar.orientation() == HorizontalScrollbar) { | 319 if (scrollbar.orientation() == HorizontalScrollbar) { |
| 319 thumbRect = IntRect(trackRect.x() + thumbPos, trackRect.y(), | 320 thumbRect = IntRect(trackRect.x() + thumbPos, trackRect.y(), |
| 320 thumbLength(scrollbar), scrollbar.height()); | 321 thumbLength(scrollbar), scrollbar.height()); |
| 321 beforeThumbRect = | 322 beforeThumbRect = |
| 322 IntRect(trackRect.x(), trackRect.y(), thumbPos + thumbRect.width() / 2, | 323 IntRect(trackRect.x(), trackRect.y(), thumbPos + thumbRect.width() / 2, |
| 323 trackRect.height()); | 324 trackRect.height()); |
| 324 afterThumbRect = | 325 afterThumbRect = |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 380 return DisplayItem::kScrollbarBackTrack; | 381 return DisplayItem::kScrollbarBackTrack; |
| 381 case ForwardTrackPart: | 382 case ForwardTrackPart: |
| 382 return DisplayItem::kScrollbarForwardTrack; | 383 return DisplayItem::kScrollbarForwardTrack; |
| 383 default: | 384 default: |
| 384 ASSERT_NOT_REACHED(); | 385 ASSERT_NOT_REACHED(); |
| 385 return DisplayItem::kScrollbarBackTrack; | 386 return DisplayItem::kScrollbarBackTrack; |
| 386 } | 387 } |
| 387 } | 388 } |
| 388 | 389 |
| 389 } // namespace blink | 390 } // namespace blink |
| OLD | NEW |