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

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

Issue 1158673006: Replace various ScrollableArea scroll methods with setScrollPosition (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Build fix Created 5 years, 6 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
« no previous file with comments | « Source/platform/scroll/ScrollableAreaTest.cpp ('k') | Source/web/ResizeViewportAnchor.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 279 matching lines...) Expand 10 before | Expand all | Expand 10 after
290 290
291 int delta = pos - m_pressedPos; 291 int delta = pos - m_pressedPos;
292 292
293 if (draggingDocument) { 293 if (draggingDocument) {
294 if (m_draggingDocument) 294 if (m_draggingDocument)
295 delta = pos - m_documentDragPos; 295 delta = pos - m_documentDragPos;
296 m_draggingDocument = true; 296 m_draggingDocument = true;
297 FloatPoint currentPosition = m_scrollableArea->scrollAnimator()->current Position(); 297 FloatPoint currentPosition = m_scrollableArea->scrollAnimator()->current Position();
298 float destinationPosition = (m_orientation == HorizontalScrollbar ? curr entPosition.x() : currentPosition.y()) + delta; 298 float destinationPosition = (m_orientation == HorizontalScrollbar ? curr entPosition.x() : currentPosition.y()) + delta;
299 destinationPosition = m_scrollableArea->clampScrollPosition(m_orientatio n, destinationPosition); 299 destinationPosition = m_scrollableArea->clampScrollPosition(m_orientatio n, destinationPosition);
300 m_scrollableArea->scrollToOffsetWithoutAnimation(m_orientation, destinat ionPosition); 300 m_scrollableArea->setScrollPositionSingleAxis(m_orientation, destination Position, UserScroll);
301 m_documentDragPos = pos; 301 m_documentDragPos = pos;
302 return; 302 return;
303 } 303 }
304 304
305 if (m_draggingDocument) { 305 if (m_draggingDocument) {
306 delta += m_pressedPos - m_documentDragPos; 306 delta += m_pressedPos - m_documentDragPos;
307 m_draggingDocument = false; 307 m_draggingDocument = false;
308 } 308 }
309 309
310 // Drag the thumb. 310 // Drag the thumb.
311 int thumbPos = theme()->thumbPosition(this); 311 int thumbPos = theme()->thumbPosition(this);
312 int thumbLen = theme()->thumbLength(this); 312 int thumbLen = theme()->thumbLength(this);
313 int trackLen = theme()->trackLength(this); 313 int trackLen = theme()->trackLength(this);
314 if (delta > 0) 314 if (delta > 0)
315 delta = std::min(trackLen - thumbLen - thumbPos, delta); 315 delta = std::min(trackLen - thumbLen - thumbPos, delta);
316 else if (delta < 0) 316 else if (delta < 0)
317 delta = std::max(-thumbPos, delta); 317 delta = std::max(-thumbPos, delta);
318 318
319 float minPos = m_scrollableArea->minimumScrollPosition(m_orientation); 319 float minPos = m_scrollableArea->minimumScrollPosition(m_orientation);
320 float maxPos = m_scrollableArea->maximumScrollPosition(m_orientation); 320 float maxPos = m_scrollableArea->maximumScrollPosition(m_orientation);
321 if (delta) { 321 if (delta) {
322 float newPosition = static_cast<float>(thumbPos + delta) * (maxPos - min Pos) / (trackLen - thumbLen) + minPos; 322 float newPosition = static_cast<float>(thumbPos + delta) * (maxPos - min Pos) / (trackLen - thumbLen) + minPos;
323 m_scrollableArea->scrollToOffsetWithoutAnimation(m_orientation, newPosit ion); 323 m_scrollableArea->setScrollPositionSingleAxis(m_orientation, newPosition , UserScroll);
324 } 324 }
325 } 325 }
326 326
327 void Scrollbar::setHoveredPart(ScrollbarPart part) 327 void Scrollbar::setHoveredPart(ScrollbarPart part)
328 { 328 {
329 if (part == m_hoveredPart) 329 if (part == m_hoveredPart)
330 return; 330 return;
331 331
332 if ((m_hoveredPart == NoPart || part == NoPart) && theme()->invalidateOnMous eEnterExit()) 332 if ((m_hoveredPart == NoPart || part == NoPart) && theme()->invalidateOnMous eEnterExit())
333 invalidate(); // Just invalidate the whole scrollbar, since the buttons at either end change anyway. 333 invalidate(); // Just invalidate the whole scrollbar, since the buttons at either end change anyway.
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
388 default: 388 default:
389 // By default, we assume that gestures don't deselect the scrollbar. 389 // By default, we assume that gestures don't deselect the scrollbar.
390 return true; 390 return true;
391 } 391 }
392 } 392 }
393 393
394 void Scrollbar::mouseMoved(const PlatformMouseEvent& evt) 394 void Scrollbar::mouseMoved(const PlatformMouseEvent& evt)
395 { 395 {
396 if (m_pressedPart == ThumbPart) { 396 if (m_pressedPart == ThumbPart) {
397 if (theme()->shouldSnapBackToDragOrigin(this, evt)) { 397 if (theme()->shouldSnapBackToDragOrigin(this, evt)) {
398 if (m_scrollableArea) 398 if (m_scrollableArea) {
399 m_scrollableArea->scrollToOffsetWithoutAnimation(m_orientation, m_dragOrigin + m_scrollableArea->minimumScrollPosition(m_orientation)); 399 m_scrollableArea->setScrollPositionSingleAxis(m_orientation, m_d ragOrigin + m_scrollableArea->minimumScrollPosition(m_orientation), UserScroll);
400 }
400 } else { 401 } else {
401 moveThumb(m_orientation == HorizontalScrollbar ? 402 moveThumb(m_orientation == HorizontalScrollbar ?
402 convertFromContainingWindow(evt.position()).x() : 403 convertFromContainingWindow(evt.position()).x() :
403 convertFromContainingWindow(evt.position()).y(), theme()-> shouldDragDocumentInsteadOfThumb(this, evt)); 404 convertFromContainingWindow(evt.position()).y(), theme()-> shouldDragDocumentInsteadOfThumb(this, evt));
404 } 405 }
405 return; 406 return;
406 } 407 }
407 408
408 if (m_pressedPart != NoPart) 409 if (m_pressedPart != NoPart)
409 m_pressedPos = orientation() == HorizontalScrollbar ? convertFromContain ingWindow(evt.position()).x() : convertFromContainingWindow(evt.position()).y(); 410 m_pressedPos = orientation() == HorizontalScrollbar ? convertFromContain ingWindow(evt.position()).x() : convertFromContainingWindow(evt.position()).y();
(...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after
560 if (!m_scrollableArea) 561 if (!m_scrollableArea)
561 return 0; 562 return 0;
562 563
563 if (m_orientation == HorizontalScrollbar) 564 if (m_orientation == HorizontalScrollbar)
564 return m_scrollableArea->scrollPosition().x() - m_scrollableArea->minimu mScrollPosition().x(); 565 return m_scrollableArea->scrollPosition().x() - m_scrollableArea->minimu mScrollPosition().x();
565 566
566 return m_scrollableArea->scrollPosition().y() - m_scrollableArea->minimumScr ollPosition().y(); 567 return m_scrollableArea->scrollPosition().y() - m_scrollableArea->minimumScr ollPosition().y();
567 } 568 }
568 569
569 } // namespace blink 570 } // namespace blink
OLDNEW
« no previous file with comments | « Source/platform/scroll/ScrollableAreaTest.cpp ('k') | Source/web/ResizeViewportAnchor.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698