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

Side by Side Diff: third_party/WebKit/Source/platform/scroll/Scrollbar.cpp

Issue 1456953003: Revert of Calculate paint invalidation rect for scrollbars (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 1 month 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
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2004, 2006, 2008 Apple Inc. All rights reserved. 2 * Copyright (C) 2004, 2006, 2008 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 16 matching lines...) Expand all
27 #include "platform/scroll/Scrollbar.h" 27 #include "platform/scroll/Scrollbar.h"
28 28
29 #include <algorithm> 29 #include <algorithm>
30 #include "platform/PlatformGestureEvent.h" 30 #include "platform/PlatformGestureEvent.h"
31 #include "platform/PlatformMouseEvent.h" 31 #include "platform/PlatformMouseEvent.h"
32 #include "platform/graphics/paint/CullRect.h" 32 #include "platform/graphics/paint/CullRect.h"
33 #include "platform/scroll/ScrollAnimatorBase.h" 33 #include "platform/scroll/ScrollAnimatorBase.h"
34 #include "platform/scroll/ScrollableArea.h" 34 #include "platform/scroll/ScrollableArea.h"
35 #include "platform/scroll/ScrollbarTheme.h" 35 #include "platform/scroll/ScrollbarTheme.h"
36 36
37 #if ((OS(POSIX) && !OS(MACOSX)) || OS(WIN))
38 // The position of the scrollbar thumb affects the appearance of the steppers, s o
39 // when the thumb moves, we have to invalidate them for painting.
40 #define THUMB_POSITION_AFFECTS_BUTTONS
41 #endif
42
37 namespace blink { 43 namespace blink {
38 44
39 PassRefPtrWillBeRawPtr<Scrollbar> Scrollbar::create(ScrollableArea* scrollableAr ea, ScrollbarOrientation orientation, ScrollbarControlSize size) 45 PassRefPtrWillBeRawPtr<Scrollbar> Scrollbar::create(ScrollableArea* scrollableAr ea, ScrollbarOrientation orientation, ScrollbarControlSize size)
40 { 46 {
41 return adoptRefWillBeNoop(new Scrollbar(scrollableArea, orientation, size)); 47 return adoptRefWillBeNoop(new Scrollbar(scrollableArea, orientation, size));
42 } 48 }
43 49
44 Scrollbar::Scrollbar(ScrollableArea* scrollableArea, ScrollbarOrientation orient ation, ScrollbarControlSize controlSize, ScrollbarTheme* theme) 50 Scrollbar::Scrollbar(ScrollableArea* scrollableArea, ScrollbarOrientation orient ation, ScrollbarControlSize controlSize, ScrollbarTheme* theme)
45 : m_scrollableArea(scrollableArea) 51 : m_scrollableArea(scrollableArea)
46 , m_orientation(orientation) 52 , m_orientation(orientation)
47 , m_controlSize(controlSize) 53 , m_controlSize(controlSize)
48 , m_theme(theme) 54 , m_theme(theme)
49 , m_visibleSize(0) 55 , m_visibleSize(0)
50 , m_totalSize(0) 56 , m_totalSize(0)
51 , m_currentPos(0) 57 , m_currentPos(0)
52 , m_dragOrigin(0) 58 , m_dragOrigin(0)
53 , m_hoveredPart(NoPart) 59 , m_hoveredPart(NoPart)
54 , m_pressedPart(NoPart) 60 , m_pressedPart(NoPart)
55 , m_pressedPos(0) 61 , m_pressedPos(0)
56 , m_scrollPos(0) 62 , m_scrollPos(0)
57 , m_draggingDocument(false) 63 , m_draggingDocument(false)
58 , m_documentDragPos(0) 64 , m_documentDragPos(0)
59 , m_enabled(true) 65 , m_enabled(true)
60 , m_scrollTimer(this, &Scrollbar::autoscrollTimerFired) 66 , m_scrollTimer(this, &Scrollbar::autoscrollTimerFired)
61 , m_overlapsResizer(false) 67 , m_overlapsResizer(false)
68 , m_suppressInvalidation(false)
62 , m_isAlphaLocked(false) 69 , m_isAlphaLocked(false)
63 , m_elasticOverscroll(0) 70 , m_elasticOverscroll(0)
64 { 71 {
65 if (!m_theme) 72 if (!m_theme)
66 m_theme = ScrollbarTheme::theme(); 73 m_theme = ScrollbarTheme::theme();
67 74
68 m_theme->registerScrollbar(this); 75 m_theme->registerScrollbar(this);
69 76
70 // FIXME: This is ugly and would not be necessary if we fix cross-platform c ode to actually query for 77 // FIXME: This is ugly and would not be necessary if we fix cross-platform c ode to actually query for
71 // scrollbar thickness and use it when sizing scrollbars (rather than leavin g one dimension of the scrollbar 78 // scrollbar thickness and use it when sizing scrollbars (rather than leavin g one dimension of the scrollbar
(...skipping 13 matching lines...) Expand all
85 { 92 {
86 visitor->trace(m_scrollableArea); 93 visitor->trace(m_scrollableArea);
87 Widget::trace(visitor); 94 Widget::trace(visitor);
88 } 95 }
89 96
90 void Scrollbar::setFrameRect(const IntRect& frameRect) 97 void Scrollbar::setFrameRect(const IntRect& frameRect)
91 { 98 {
92 if (frameRect == this->frameRect()) 99 if (frameRect == this->frameRect())
93 return; 100 return;
94 101
102 invalidate();
95 Widget::setFrameRect(frameRect); 103 Widget::setFrameRect(frameRect);
96 setNeedsPaintInvalidation(); 104 invalidate();
97 } 105 }
98 106
99 ScrollbarOverlayStyle Scrollbar::scrollbarOverlayStyle() const 107 ScrollbarOverlayStyle Scrollbar::scrollbarOverlayStyle() const
100 { 108 {
101 return m_scrollableArea ? m_scrollableArea->scrollbarOverlayStyle() : Scroll barOverlayStyleDefault; 109 return m_scrollableArea ? m_scrollableArea->scrollbarOverlayStyle() : Scroll barOverlayStyleDefault;
102 } 110 }
103 111
104 void Scrollbar::getTickmarks(Vector<IntRect>& tickmarks) const 112 void Scrollbar::getTickmarks(Vector<IntRect>& tickmarks) const
105 { 113 {
106 if (m_scrollableArea) 114 if (m_scrollableArea)
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
145 return; 153 return;
146 154
147 m_visibleSize = visibleSize; 155 m_visibleSize = visibleSize;
148 m_totalSize = totalSize; 156 m_totalSize = totalSize;
149 157
150 updateThumbProportion(); 158 updateThumbProportion();
151 } 159 }
152 160
153 void Scrollbar::updateThumb() 161 void Scrollbar::updateThumb()
154 { 162 {
155 setNeedsPaintInvalidation(); 163 #ifdef THUMB_POSITION_AFFECTS_BUTTONS
164 invalidate();
165 #else
166 theme()->invalidateParts(this, ForwardTrackPart | BackTrackPart | ThumbPart) ;
167 #endif
156 } 168 }
157 169
158 void Scrollbar::updateThumbPosition() 170 void Scrollbar::updateThumbPosition()
159 { 171 {
160 updateThumb(); 172 updateThumb();
161 } 173 }
162 174
163 void Scrollbar::updateThumbProportion() 175 void Scrollbar::updateThumbProportion()
164 { 176 {
165 updateThumb(); 177 updateThumb();
(...skipping 21 matching lines...) Expand all
187 } 199 }
188 200
189 void Scrollbar::autoscrollPressedPart(double delay) 201 void Scrollbar::autoscrollPressedPart(double delay)
190 { 202 {
191 // Don't do anything for the thumb or if nothing was pressed. 203 // Don't do anything for the thumb or if nothing was pressed.
192 if (m_pressedPart == ThumbPart || m_pressedPart == NoPart) 204 if (m_pressedPart == ThumbPart || m_pressedPart == NoPart)
193 return; 205 return;
194 206
195 // Handle the track. 207 // Handle the track.
196 if ((m_pressedPart == BackTrackPart || m_pressedPart == ForwardTrackPart) && thumbUnderMouse(this)) { 208 if ((m_pressedPart == BackTrackPart || m_pressedPart == ForwardTrackPart) && thumbUnderMouse(this)) {
197 setNeedsPaintInvalidation(); 209 theme()->invalidatePart(this, m_pressedPart);
198 setHoveredPart(ThumbPart); 210 setHoveredPart(ThumbPart);
199 return; 211 return;
200 } 212 }
201 213
202 // Handle the arrows and track. 214 // Handle the arrows and track.
203 if (m_scrollableArea && m_scrollableArea->userScroll(pressedPartScrollDirect ionPhysical(), pressedPartScrollGranularity()).didScroll) 215 if (m_scrollableArea && m_scrollableArea->userScroll(pressedPartScrollDirect ionPhysical(), pressedPartScrollGranularity()).didScroll)
204 startTimerIfNeeded(delay); 216 startTimerIfNeeded(delay);
205 } 217 }
206 218
207 void Scrollbar::startTimerIfNeeded(double delay) 219 void Scrollbar::startTimerIfNeeded(double delay)
208 { 220 {
209 // Don't do anything for the thumb. 221 // Don't do anything for the thumb.
210 if (m_pressedPart == ThumbPart) 222 if (m_pressedPart == ThumbPart)
211 return; 223 return;
212 224
213 // Handle the track. We halt track scrolling once the thumb is level 225 // Handle the track. We halt track scrolling once the thumb is level
214 // with us. 226 // with us.
215 if ((m_pressedPart == BackTrackPart || m_pressedPart == ForwardTrackPart) && thumbUnderMouse(this)) { 227 if ((m_pressedPart == BackTrackPart || m_pressedPart == ForwardTrackPart) && thumbUnderMouse(this)) {
216 setNeedsPaintInvalidation(); 228 theme()->invalidatePart(this, m_pressedPart);
217 setHoveredPart(ThumbPart); 229 setHoveredPart(ThumbPart);
218 return; 230 return;
219 } 231 }
220 232
221 // We can't scroll if we've hit the beginning or end. 233 // We can't scroll if we've hit the beginning or end.
222 ScrollDirectionPhysical dir = pressedPartScrollDirectionPhysical(); 234 ScrollDirectionPhysical dir = pressedPartScrollDirectionPhysical();
223 if (dir == ScrollUp || dir == ScrollLeft) { 235 if (dir == ScrollUp || dir == ScrollLeft) {
224 if (m_currentPos == 0) 236 if (m_currentPos == 0)
225 return; 237 return;
226 } else { 238 } else {
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after
300 float newPosition = static_cast<float>(thumbPos + delta) * (maxPos - min Pos) / (trackLen - thumbLen) + minPos; 312 float newPosition = static_cast<float>(thumbPos + delta) * (maxPos - min Pos) / (trackLen - thumbLen) + minPos;
301 m_scrollableArea->setScrollPositionSingleAxis(m_orientation, newPosition , UserScroll); 313 m_scrollableArea->setScrollPositionSingleAxis(m_orientation, newPosition , UserScroll);
302 } 314 }
303 } 315 }
304 316
305 void Scrollbar::setHoveredPart(ScrollbarPart part) 317 void Scrollbar::setHoveredPart(ScrollbarPart part)
306 { 318 {
307 if (part == m_hoveredPart) 319 if (part == m_hoveredPart)
308 return; 320 return;
309 321
310 if (((m_hoveredPart == NoPart || part == NoPart) && theme()->invalidateOnMou seEnterExit()) 322 if ((m_hoveredPart == NoPart || part == NoPart) && theme()->invalidateOnMous eEnterExit())
311 // When there's a pressed part, we don't draw a hovered state, so there' s no reason to invalidate. 323 invalidate(); // Just invalidate the whole scrollbar, since the buttons at either end change anyway.
312 || m_pressedPart == NoPart) 324 else if (m_pressedPart == NoPart) { // When there's a pressed part, we don' t draw a hovered state, so there's no reason to invalidate.
313 setNeedsPaintInvalidation(); 325 theme()->invalidatePart(this, part);
314 326 theme()->invalidatePart(this, m_hoveredPart);
327 }
315 m_hoveredPart = part; 328 m_hoveredPart = part;
316 } 329 }
317 330
318 void Scrollbar::setPressedPart(ScrollbarPart part) 331 void Scrollbar::setPressedPart(ScrollbarPart part)
319 { 332 {
320 if (m_pressedPart != NoPart 333 if (m_pressedPart != NoPart)
321 // When we no longer have a pressed part, we can start drawing a hovered state on the hovered part. 334 theme()->invalidatePart(this, m_pressedPart);
322 || m_hoveredPart != NoPart)
323 setNeedsPaintInvalidation();
324 m_pressedPart = part; 335 m_pressedPart = part;
336 if (m_pressedPart != NoPart)
337 theme()->invalidatePart(this, m_pressedPart);
338 else if (m_hoveredPart != NoPart) // When we no longer have a pressed part, we can start drawing a hovered state on the hovered part.
339 theme()->invalidatePart(this, m_hoveredPart);
325 } 340 }
326 341
327 bool Scrollbar::gestureEvent(const PlatformGestureEvent& evt) 342 bool Scrollbar::gestureEvent(const PlatformGestureEvent& evt)
328 { 343 {
329 switch (evt.type()) { 344 switch (evt.type()) {
330 case PlatformEvent::GestureTapDown: 345 case PlatformEvent::GestureTapDown:
331 setPressedPart(theme()->hitTest(this, evt.position())); 346 setPressedPart(theme()->hitTest(this, evt.position()));
332 m_pressedPos = orientation() == HorizontalScrollbar ? convertFromContain ingWindow(evt.position()).x() : convertFromContainingWindow(evt.position()).y(); 347 m_pressedPos = orientation() == HorizontalScrollbar ? convertFromContain ingWindow(evt.position()).x() : convertFromContainingWindow(evt.position()).y();
333 return true; 348 return true;
334 case PlatformEvent::GestureTapDownCancel: 349 case PlatformEvent::GestureTapDownCancel:
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
384 if (m_pressedPart != NoPart) 399 if (m_pressedPart != NoPart)
385 m_pressedPos = orientation() == HorizontalScrollbar ? convertFromContain ingWindow(evt.position()).x() : convertFromContainingWindow(evt.position()).y(); 400 m_pressedPos = orientation() == HorizontalScrollbar ? convertFromContain ingWindow(evt.position()).x() : convertFromContainingWindow(evt.position()).y();
386 401
387 ScrollbarPart part = theme()->hitTest(this, evt.position()); 402 ScrollbarPart part = theme()->hitTest(this, evt.position());
388 if (part != m_hoveredPart) { 403 if (part != m_hoveredPart) {
389 if (m_pressedPart != NoPart) { 404 if (m_pressedPart != NoPart) {
390 if (part == m_pressedPart) { 405 if (part == m_pressedPart) {
391 // The mouse is moving back over the pressed part. We 406 // The mouse is moving back over the pressed part. We
392 // need to start up the timer action again. 407 // need to start up the timer action again.
393 startTimerIfNeeded(theme()->autoscrollTimerDelay()); 408 startTimerIfNeeded(theme()->autoscrollTimerDelay());
394 setNeedsPaintInvalidation(); 409 theme()->invalidatePart(this, m_pressedPart);
395 } else if (m_hoveredPart == m_pressedPart) { 410 } else if (m_hoveredPart == m_pressedPart) {
396 // The mouse is leaving the pressed part. Kill our timer 411 // The mouse is leaving the pressed part. Kill our timer
397 // if needed. 412 // if needed.
398 stopTimerIfNeeded(); 413 stopTimerIfNeeded();
399 setNeedsPaintInvalidation(); 414 theme()->invalidatePart(this, m_pressedPart);
400 } 415 }
401 } 416 }
402 417
403 setHoveredPart(part); 418 setHoveredPart(part);
404 } 419 }
405 420
406 return; 421 return;
407 } 422 }
408 423
409 void Scrollbar::mouseEntered() 424 void Scrollbar::mouseEntered()
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
468 if (m_scrollableArea) 483 if (m_scrollableArea)
469 m_scrollableArea->scrollbarVisibilityChanged(); 484 m_scrollableArea->scrollbarVisibilityChanged();
470 } 485 }
471 486
472 void Scrollbar::setEnabled(bool e) 487 void Scrollbar::setEnabled(bool e)
473 { 488 {
474 if (m_enabled == e) 489 if (m_enabled == e)
475 return; 490 return;
476 m_enabled = e; 491 m_enabled = e;
477 theme()->updateEnabledState(this); 492 theme()->updateEnabledState(this);
478 setNeedsPaintInvalidation(); 493 invalidate();
479 } 494 }
480 495
481 bool Scrollbar::isOverlayScrollbar() const 496 bool Scrollbar::isOverlayScrollbar() const
482 { 497 {
483 return m_theme->usesOverlayScrollbars(); 498 return m_theme->usesOverlayScrollbars();
484 } 499 }
485 500
486 bool Scrollbar::shouldParticipateInHitTesting() 501 bool Scrollbar::shouldParticipateInHitTesting()
487 { 502 {
488 // Non-overlay scrollbars should always participate in hit testing. 503 // Non-overlay scrollbars should always participate in hit testing.
489 if (!isOverlayScrollbar()) 504 if (!isOverlayScrollbar())
490 return true; 505 return true;
491 return m_scrollableArea->scrollAnimator()->shouldScrollbarParticipateInHitTe sting(this); 506 return m_scrollableArea->scrollAnimator()->shouldScrollbarParticipateInHitTe sting(this);
492 } 507 }
493 508
494 bool Scrollbar::isWindowActive() const 509 bool Scrollbar::isWindowActive() const
495 { 510 {
496 return m_scrollableArea && m_scrollableArea->isActive(); 511 return m_scrollableArea && m_scrollableArea->isActive();
497 } 512 }
498 513
514 void Scrollbar::invalidateRect(const IntRect& rect)
515 {
516 if (suppressInvalidation())
517 return;
518
519 if (m_scrollableArea)
520 m_scrollableArea->invalidateScrollbar(this, rect);
521 }
522
499 IntRect Scrollbar::convertToContainingView(const IntRect& localRect) const 523 IntRect Scrollbar::convertToContainingView(const IntRect& localRect) const
500 { 524 {
501 if (m_scrollableArea) 525 if (m_scrollableArea)
502 return m_scrollableArea->convertFromScrollbarToContainingView(this, loca lRect); 526 return m_scrollableArea->convertFromScrollbarToContainingView(this, loca lRect);
503 527
504 return Widget::convertToContainingView(localRect); 528 return Widget::convertToContainingView(localRect);
505 } 529 }
506 530
507 IntRect Scrollbar::convertFromContainingView(const IntRect& parentRect) const 531 IntRect Scrollbar::convertFromContainingView(const IntRect& parentRect) const
508 { 532 {
(...skipping 23 matching lines...) Expand all
532 { 556 {
533 if (!m_scrollableArea) 557 if (!m_scrollableArea)
534 return 0; 558 return 0;
535 559
536 if (m_orientation == HorizontalScrollbar) 560 if (m_orientation == HorizontalScrollbar)
537 return m_scrollableArea->scrollPosition().x() - m_scrollableArea->minimu mScrollPosition().x(); 561 return m_scrollableArea->scrollPosition().x() - m_scrollableArea->minimu mScrollPosition().x();
538 562
539 return m_scrollableArea->scrollPosition().y() - m_scrollableArea->minimumScr ollPosition().y(); 563 return m_scrollableArea->scrollPosition().y() - m_scrollableArea->minimumScr ollPosition().y();
540 } 564 }
541 565
542 void Scrollbar::setNeedsPaintInvalidation()
543 {
544 if (m_scrollableArea)
545 m_scrollableArea->setScrollbarNeedsPaintInvalidation(this);
546 }
547
548 } // namespace blink 566 } // namespace blink
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/platform/scroll/Scrollbar.h ('k') | third_party/WebKit/Source/platform/scroll/ScrollbarTheme.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698