Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(289)

Side by Side Diff: Source/platform/scroll/ScrollbarTheme.cpp

Issue 1093383003: Remove mainthread overhang painting code (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Created 5 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 203 matching lines...) Expand 10 before | Expand all | Expand 10 after
214 if (recorder.canUseCachedDrawing()) 214 if (recorder.canUseCachedDrawing())
215 return; 215 return;
216 216
217 #if OS(MACOSX) 217 #if OS(MACOSX)
218 context->fillRect(cornerRect, Color::white); 218 context->fillRect(cornerRect, Color::white);
219 #else 219 #else
220 Platform::current()->themeEngine()->paint(context->canvas(), WebThemeEngine: :PartScrollbarCorner, WebThemeEngine::StateNormal, WebRect(cornerRect), 0); 220 Platform::current()->themeEngine()->paint(context->canvas(), WebThemeEngine: :PartScrollbarCorner, WebThemeEngine::StateNormal, WebRect(cornerRect), 0);
221 #endif 221 #endif
222 } 222 }
223 223
224 void ScrollbarTheme::paintOverhangBackground(GraphicsContext* context, const Int Rect& horizontalOverhangRect, const IntRect& verticalOverhangRect, const IntRect & dirtyRect)
225 {
226 context->setFillColor(Color::white);
227 if (!horizontalOverhangRect.isEmpty())
228 context->fillRect(intersection(horizontalOverhangRect, dirtyRect));
229 if (!verticalOverhangRect.isEmpty())
230 context->fillRect(intersection(verticalOverhangRect, dirtyRect));
231 }
232
233 bool ScrollbarTheme::shouldCenterOnThumb(ScrollbarThemeClient* scrollbar, const PlatformMouseEvent& evt) 224 bool ScrollbarTheme::shouldCenterOnThumb(ScrollbarThemeClient* scrollbar, const PlatformMouseEvent& evt)
234 { 225 {
235 return Platform::current()->scrollbarBehavior()->shouldCenterOnThumb(static_ cast<WebScrollbarBehavior::Button>(evt.button()), evt.shiftKey(), evt.altKey()); 226 return Platform::current()->scrollbarBehavior()->shouldCenterOnThumb(static_ cast<WebScrollbarBehavior::Button>(evt.button()), evt.shiftKey(), evt.altKey());
236 } 227 }
237 228
238 bool ScrollbarTheme::shouldSnapBackToDragOrigin(ScrollbarThemeClient* scrollbar, const PlatformMouseEvent& evt) 229 bool ScrollbarTheme::shouldSnapBackToDragOrigin(ScrollbarThemeClient* scrollbar, const PlatformMouseEvent& evt)
239 { 230 {
240 IntPoint mousePosition = scrollbar->convertFromContainingWindow(evt.position ()); 231 IntPoint mousePosition = scrollbar->convertFromContainingWindow(evt.position ());
241 mousePosition.move(scrollbar->x(), scrollbar->y()); 232 mousePosition.move(scrollbar->x(), scrollbar->y());
242 return Platform::current()->scrollbarBehavior()->shouldSnapBackToDragOrigin( mousePosition, trackRect(scrollbar), scrollbar->orientation() == HorizontalScrol lbar); 233 return Platform::current()->scrollbarBehavior()->shouldSnapBackToDragOrigin( mousePosition, trackRect(scrollbar), scrollbar->orientation() == HorizontalScrol lbar);
243 } 234 }
244 235
245 // Returns the size represented by track taking into account scrolling past
246 // the end of the document.
247 static float usedTotalSize(ScrollbarThemeClient* scrollbar)
248 {
249 float overhangAtStart = -scrollbar->currentPos();
250 float overhangAtEnd = scrollbar->currentPos() + scrollbar->visibleSize() - s crollbar->totalSize();
251 float overhang = std::max(0.0f, std::max(overhangAtStart, overhangAtEnd));
252 return scrollbar->totalSize() + overhang;
253 }
254
255 int ScrollbarTheme::thumbPosition(ScrollbarThemeClient* scrollbar) 236 int ScrollbarTheme::thumbPosition(ScrollbarThemeClient* scrollbar)
256 { 237 {
257 if (scrollbar->enabled()) { 238 if (scrollbar->enabled()) {
258 float size = usedTotalSize(scrollbar) - scrollbar->visibleSize(); 239 float size = scrollbar->totalSize() - scrollbar->visibleSize();
259 // Avoid doing a floating point divide by zero and return 1 when usedTot alSize == visibleSize. 240 // Avoid doing a floating point divide by zero and return 1 when usedTot alSize == visibleSize.
260 if (!size) 241 if (!size)
261 return 1; 242 return 1;
262 float pos = std::max(0.0f, scrollbar->currentPos()) * (trackLength(scrol lbar) - thumbLength(scrollbar)) / size; 243 float pos = std::max(0.0f, scrollbar->currentPos()) * (trackLength(scrol lbar) - thumbLength(scrollbar)) / size;
263 return (pos < 1 && pos > 0) ? 1 : pos; 244 return (pos < 1 && pos > 0) ? 1 : pos;
264 } 245 }
265 return 0; 246 return 0;
266 } 247 }
267 248
268 int ScrollbarTheme::thumbLength(ScrollbarThemeClient* scrollbar) 249 int ScrollbarTheme::thumbLength(ScrollbarThemeClient* scrollbar)
269 { 250 {
270 if (!scrollbar->enabled()) 251 if (!scrollbar->enabled())
271 return 0; 252 return 0;
272 253
273 // It is safe to compute the overhang by adding the result from the main 254 float overhang = fabsf(scrollbar->elasticOverscroll());
274 // thread overscroll mode (first) and then adding the result from compositor
275 // thread overscroll (second) because the modes are mutually exclusive (and
276 // determining which mode is in use here will require lots of temporary
277 // plumbing, and the main thread mode is to be deleted).
278 float overhang = 0;
279 if (scrollbar->currentPos() < 0)
280 overhang = -scrollbar->currentPos();
281 else if (scrollbar->visibleSize() + scrollbar->currentPos() > scrollbar->tot alSize())
282 overhang = scrollbar->currentPos() + scrollbar->visibleSize() - scrollba r->totalSize();
283 overhang += fabsf(scrollbar->elasticOverscroll());
284 float proportion = 0.0f; 255 float proportion = 0.0f;
285 float totalSize = usedTotalSize(scrollbar); 256 float totalSize = scrollbar->totalSize();
286 if (totalSize > 0.0f) { 257 if (totalSize > 0.0f) {
287 proportion = (scrollbar->visibleSize() - overhang) / totalSize; 258 proportion = (scrollbar->visibleSize() - overhang) / totalSize;
288 } 259 }
289 int trackLen = trackLength(scrollbar); 260 int trackLen = trackLength(scrollbar);
290 int length = round(proportion * trackLen); 261 int length = round(proportion * trackLen);
291 length = std::max(length, minimumThumbLength(scrollbar)); 262 length = std::max(length, minimumThumbLength(scrollbar));
292 if (length > trackLen) 263 if (length > trackLen)
293 length = 0; // Once the thumb is below the track length, it just goes aw ay (to make more room for the track). 264 length = 0; // Once the thumb is below the track length, it just goes aw ay (to make more room for the track).
294 return length; 265 return length;
295 } 266 }
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after
396 return DisplayItem::ScrollbarBackTrack; 367 return DisplayItem::ScrollbarBackTrack;
397 case ForwardTrackPart: 368 case ForwardTrackPart:
398 return DisplayItem::ScrollbarForwardTrack; 369 return DisplayItem::ScrollbarForwardTrack;
399 default: 370 default:
400 ASSERT_NOT_REACHED(); 371 ASSERT_NOT_REACHED();
401 return DisplayItem::ScrollbarBackTrack; 372 return DisplayItem::ScrollbarBackTrack;
402 } 373 }
403 } 374 }
404 375
405 } // namespace blink 376 } // namespace blink
OLDNEW
« no previous file with comments | « Source/platform/scroll/ScrollbarTheme.h ('k') | Source/platform/scroll/ScrollbarThemeMacCommon.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698