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

Side by Side Diff: sky/engine/platform/scroll/Scrollbar.cpp

Issue 842113005: Delete a bunch of noop paint invalidation code. (Closed) Base URL: git@github.com:domokit/mojo.git@master
Patch Set: fix comment Created 5 years, 11 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
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 89 matching lines...) Expand 10 before | Expand all | Expand 10 after
100 void Scrollbar::offsetDidChange() 100 void Scrollbar::offsetDidChange()
101 { 101 {
102 ASSERT(m_scrollableArea); 102 ASSERT(m_scrollableArea);
103 103
104 float position = scrollableAreaCurrentPos(); 104 float position = scrollableAreaCurrentPos();
105 if (position == m_currentPos) 105 if (position == m_currentPos)
106 return; 106 return;
107 107
108 int oldThumbPosition = thumbPosition(); 108 int oldThumbPosition = thumbPosition();
109 m_currentPos = position; 109 m_currentPos = position;
110 updateThumb();
111 if (m_pressedPart == ThumbPart) 110 if (m_pressedPart == ThumbPart)
112 setPressedPos(m_pressedPos + thumbPosition() - oldThumbPosition); 111 setPressedPos(m_pressedPos + thumbPosition() - oldThumbPosition);
113 } 112 }
114 113
115 void Scrollbar::setProportion(int visibleSize, int totalSize) 114 void Scrollbar::setProportion(int visibleSize, int totalSize)
116 { 115 {
117 if (visibleSize == m_visibleSize && totalSize == m_totalSize) 116 if (visibleSize == m_visibleSize && totalSize == m_totalSize)
118 return; 117 return;
119 118
120 m_visibleSize = visibleSize; 119 m_visibleSize = visibleSize;
121 m_totalSize = totalSize; 120 m_totalSize = totalSize;
122
123 updateThumb();
124 }
125
126 void Scrollbar::updateThumb()
127 {
128 #ifdef THUMB_POSITION_AFFECTS_BUTTONS
129 invalidate();
130 #else
131 invalidateParts();
132 #endif
133 } 121 }
134 122
135 void Scrollbar::paint(GraphicsContext* context, const IntRect& damageRect) 123 void Scrollbar::paint(GraphicsContext* context, const IntRect& damageRect)
136 { 124 {
137 if (!frameRect().intersects(damageRect)) 125 if (!frameRect().intersects(damageRect))
138 return; 126 return;
139 127
140 IntRect startTrackRect; 128 IntRect startTrackRect;
141 IntRect thumbRect; 129 IntRect thumbRect;
142 IntRect endTrackRect; 130 IntRect endTrackRect;
(...skipping 15 matching lines...) Expand all
158 } 146 }
159 147
160 void Scrollbar::autoscrollPressedPart(double delay) 148 void Scrollbar::autoscrollPressedPart(double delay)
161 { 149 {
162 // Don't do anything for the thumb or if nothing was pressed. 150 // Don't do anything for the thumb or if nothing was pressed.
163 if (m_pressedPart == ThumbPart || m_pressedPart == NoPart) 151 if (m_pressedPart == ThumbPart || m_pressedPart == NoPart)
164 return; 152 return;
165 153
166 // Handle the track. 154 // Handle the track.
167 if ((m_pressedPart == BackTrackPart || m_pressedPart == ForwardTrackPart) && thumbUnderMouse(this)) { 155 if ((m_pressedPart == BackTrackPart || m_pressedPart == ForwardTrackPart) && thumbUnderMouse(this)) {
168 invalidatePart(m_pressedPart);
169 setHoveredPart(ThumbPart); 156 setHoveredPart(ThumbPart);
170 return; 157 return;
171 } 158 }
172 159
173 // Handle the arrows and track. 160 // Handle the arrows and track.
174 if (m_scrollableArea && m_scrollableArea->scroll(pressedPartScrollDirection( ), pressedPartScrollGranularity())) 161 if (m_scrollableArea && m_scrollableArea->scroll(pressedPartScrollDirection( ), pressedPartScrollGranularity()))
175 startTimerIfNeeded(delay); 162 startTimerIfNeeded(delay);
176 } 163 }
177 164
178 void Scrollbar::startTimerIfNeeded(double delay) 165 void Scrollbar::startTimerIfNeeded(double delay)
179 { 166 {
180 // Don't do anything for the thumb. 167 // Don't do anything for the thumb.
181 if (m_pressedPart == ThumbPart) 168 if (m_pressedPart == ThumbPart)
182 return; 169 return;
183 170
184 // Handle the track. We halt track scrolling once the thumb is level 171 // Handle the track. We halt track scrolling once the thumb is level
185 // with us. 172 // with us.
186 if ((m_pressedPart == BackTrackPart || m_pressedPart == ForwardTrackPart) && thumbUnderMouse(this)) { 173 if ((m_pressedPart == BackTrackPart || m_pressedPart == ForwardTrackPart) && thumbUnderMouse(this)) {
187 invalidatePart(m_pressedPart);
188 setHoveredPart(ThumbPart); 174 setHoveredPart(ThumbPart);
189 return; 175 return;
190 } 176 }
191 177
192 // We can't scroll if we've hit the beginning or end. 178 // We can't scroll if we've hit the beginning or end.
193 ScrollDirection dir = pressedPartScrollDirection(); 179 ScrollDirection dir = pressedPartScrollDirection();
194 if (dir == ScrollUp || dir == ScrollLeft) { 180 if (dir == ScrollUp || dir == ScrollLeft) {
195 if (m_currentPos == 0) 181 if (m_currentPos == 0)
196 return; 182 return;
197 } else { 183 } else {
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
248 if (delta) { 234 if (delta) {
249 float newPosition = static_cast<float>(thumbPos + delta) * (maxPos - min Pos) / (trackLen - thumbLen) + minPos; 235 float newPosition = static_cast<float>(thumbPos + delta) * (maxPos - min Pos) / (trackLen - thumbLen) + minPos;
250 m_scrollableArea->scrollToOffsetWithoutAnimation(m_orientation, newPosit ion); 236 m_scrollableArea->scrollToOffsetWithoutAnimation(m_orientation, newPosit ion);
251 } 237 }
252 } 238 }
253 239
254 void Scrollbar::setHoveredPart(ScrollbarPart part) 240 void Scrollbar::setHoveredPart(ScrollbarPart part)
255 { 241 {
256 if (part == m_hoveredPart) 242 if (part == m_hoveredPart)
257 return; 243 return;
258
259 if (m_pressedPart == NoPart) { // When there's a pressed part, we don't dra w a hovered state, so there's no reason to invalidate.
260 invalidatePart(part);
261 invalidatePart(m_hoveredPart);
262 }
263 m_hoveredPart = part; 244 m_hoveredPart = part;
264 } 245 }
265 246
266 void Scrollbar::setPressedPart(ScrollbarPart part) 247 void Scrollbar::setPressedPart(ScrollbarPart part)
267 { 248 {
268 if (m_pressedPart != NoPart)
269 invalidatePart(m_pressedPart);
270 m_pressedPart = part; 249 m_pressedPart = part;
271 if (m_pressedPart != NoPart)
272 invalidatePart(m_pressedPart);
273 else if (m_hoveredPart != NoPart) // When we no longer have a pressed part, we can start drawing a hovered state on the hovered part.
274 invalidatePart(m_hoveredPart);
275 } 250 }
276 251
277 bool Scrollbar::gestureEvent(const PlatformGestureEvent& evt) 252 bool Scrollbar::gestureEvent(const PlatformGestureEvent& evt)
278 { 253 {
279 switch (evt.type()) { 254 switch (evt.type()) {
280 case PlatformEvent::GestureTapDown: 255 case PlatformEvent::GestureTapDown:
281 // FIXME(sky): Is setting the pressed part needed since we only have ove rlay scrollbars? 256 // FIXME(sky): Is setting the pressed part needed since we only have ove rlay scrollbars?
282 setPressedPart(NoPart); 257 setPressedPart(NoPart);
283 m_pressedPos = orientation() == HorizontalScrollbar ? convertFromContain ingView(evt.position()).x() : convertFromContainingView(evt.position()).y(); 258 m_pressedPos = orientation() == HorizontalScrollbar ? convertFromContain ingView(evt.position()).x() : convertFromContainingView(evt.position()).y();
284 return true; 259 return true;
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
331 m_pressedPos = orientation() == HorizontalScrollbar ? convertFromContain ingView(evt.position()).x() : convertFromContainingView(evt.position()).y(); 306 m_pressedPos = orientation() == HorizontalScrollbar ? convertFromContain ingView(evt.position()).x() : convertFromContainingView(evt.position()).y();
332 307
333 // FIXME(sky): Cleanup this code now that part is always NoPart. 308 // FIXME(sky): Cleanup this code now that part is always NoPart.
334 ScrollbarPart part = NoPart; 309 ScrollbarPart part = NoPart;
335 if (part != m_hoveredPart) { 310 if (part != m_hoveredPart) {
336 if (m_pressedPart != NoPart) { 311 if (m_pressedPart != NoPart) {
337 if (part == m_pressedPart) { 312 if (part == m_pressedPart) {
338 // The mouse is moving back over the pressed part. We 313 // The mouse is moving back over the pressed part. We
339 // need to start up the timer action again. 314 // need to start up the timer action again.
340 startTimerIfNeeded(autoscrollTimerDelay()); 315 startTimerIfNeeded(autoscrollTimerDelay());
341 invalidatePart(m_pressedPart);
342 } else if (m_hoveredPart == m_pressedPart) { 316 } else if (m_hoveredPart == m_pressedPart) {
343 // The mouse is leaving the pressed part. Kill our timer 317 // The mouse is leaving the pressed part. Kill our timer
344 // if needed. 318 // if needed.
345 stopTimerIfNeeded(); 319 stopTimerIfNeeded();
346 invalidatePart(m_pressedPart);
347 } 320 }
348 } 321 }
349 322
350 setHoveredPart(part); 323 setHoveredPart(part);
351 } 324 }
352 325
353 return; 326 return;
354 } 327 }
355 328
356 void Scrollbar::mouseEntered() 329 void Scrollbar::mouseEntered()
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
412 } 385 }
413 386
414 bool Scrollbar::shouldParticipateInHitTesting() 387 bool Scrollbar::shouldParticipateInHitTesting()
415 { 388 {
416 // Non-overlay scrollbars should always participate in hit testing. 389 // Non-overlay scrollbars should always participate in hit testing.
417 if (!isOverlayScrollbar()) 390 if (!isOverlayScrollbar())
418 return true; 391 return true;
419 return m_scrollableArea->scrollAnimator()->shouldScrollbarParticipateInHitTe sting(this); 392 return m_scrollableArea->scrollAnimator()->shouldScrollbarParticipateInHitTe sting(this);
420 } 393 }
421 394
422 void Scrollbar::invalidateRect(const IntRect& rect)
423 {
424 if (m_scrollableArea)
425 m_scrollableArea->invalidateScrollbar(this, rect);
426 }
427
428 IntRect Scrollbar::convertToContainingView(const IntRect& localRect) const 395 IntRect Scrollbar::convertToContainingView(const IntRect& localRect) const
429 { 396 {
430 if (m_scrollableArea) 397 if (m_scrollableArea)
431 return m_scrollableArea->convertFromScrollbarToContainingView(this, loca lRect); 398 return m_scrollableArea->convertFromScrollbarToContainingView(this, loca lRect);
432 399
433 return Widget::convertToContainingView(localRect); 400 return Widget::convertToContainingView(localRect);
434 } 401 }
435 402
436 IntRect Scrollbar::convertFromContainingView(const IntRect& parentRect) const 403 IntRect Scrollbar::convertFromContainingView(const IntRect& parentRect) const
437 { 404 {
(...skipping 28 matching lines...) Expand all
466 return m_scrollableArea->scrollPosition().x() - m_scrollableArea->minimu mScrollPosition().x(); 433 return m_scrollableArea->scrollPosition().x() - m_scrollableArea->minimu mScrollPosition().x();
467 434
468 return m_scrollableArea->scrollPosition().y() - m_scrollableArea->minimumScr ollPosition().y(); 435 return m_scrollableArea->scrollPosition().y() - m_scrollableArea->minimumScr ollPosition().y();
469 } 436 }
470 437
471 int Scrollbar::scrollbarThickness() 438 int Scrollbar::scrollbarThickness()
472 { 439 {
473 return kThumbThickness + kScrollbarMargin; 440 return kThumbThickness + kScrollbarMargin;
474 } 441 }
475 442
476 void Scrollbar::invalidatePart(ScrollbarPart part)
477 {
478 if (part == NoPart)
479 return;
480
481 IntRect result;
482
483 IntRect beforeThumbRect, thumbRect, afterThumbRect;
484 splitTrack(trackRect(), beforeThumbRect, thumbRect, afterThumbRect);
485 if (part == BackTrackPart)
486 result = beforeThumbRect;
487 else if (part == ForwardTrackPart)
488 result = afterThumbRect;
489 else
490 result = thumbRect;
491
492 result.moveBy(-location());
493 invalidateRect(result);
494 }
495
496 int Scrollbar::thumbPosition() 443 int Scrollbar::thumbPosition()
497 { 444 {
498 if (!totalSize()) 445 if (!totalSize())
499 return 0; 446 return 0;
500 447
501 int trackLen = trackLength(); 448 int trackLen = trackLength();
502 float proportion = static_cast<float>(currentPos()) / totalSize(); 449 float proportion = static_cast<float>(currentPos()) / totalSize();
503 return round(proportion * trackLen); 450 return round(proportion * trackLen);
504 } 451 }
505 452
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after
585 thumbRect.setWidth(thumbRect.width() - kScrollbarMargin); 532 thumbRect.setWidth(thumbRect.width() - kScrollbarMargin);
586 if (isLeftSideVerticalScrollbar()) 533 if (isLeftSideVerticalScrollbar())
587 thumbRect.setX(thumbRect.x() + kScrollbarMargin); 534 thumbRect.setX(thumbRect.x() + kScrollbarMargin);
588 } 535 }
589 536
590 DEFINE_STATIC_LOCAL(Color, color, (128, 128, 128, 128)); 537 DEFINE_STATIC_LOCAL(Color, color, (128, 128, 128, 128));
591 context->fillRect(thumbRect, color); 538 context->fillRect(thumbRect, color);
592 } 539 }
593 540
594 } // namespace blink 541 } // namespace blink
OLDNEW
« no previous file with comments | « sky/engine/platform/scroll/Scrollbar.h ('k') | sky/engine/public/platform/WebExternalTextureLayer.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698