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

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

Issue 14807003: Unifies ScrollView and RenderLayer to use non-shifted [minPos, maxPos] scroll offset (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Created 7 years, 7 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) 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 270 matching lines...) Expand 10 before | Expand all | Expand 10 after
281 if (m_pressedPart == BackButtonStartPart || m_pressedPart == BackButtonEndPa rt || m_pressedPart == ForwardButtonStartPart || m_pressedPart == ForwardButton EndPart) 281 if (m_pressedPart == BackButtonStartPart || m_pressedPart == BackButtonEndPa rt || m_pressedPart == ForwardButtonStartPart || m_pressedPart == ForwardButton EndPart)
282 return ScrollByLine; 282 return ScrollByLine;
283 return ScrollByPage; 283 return ScrollByPage;
284 } 284 }
285 285
286 void Scrollbar::moveThumb(int pos, bool draggingDocument) 286 void Scrollbar::moveThumb(int pos, bool draggingDocument)
287 { 287 {
288 if (!m_scrollableArea) 288 if (!m_scrollableArea)
289 return; 289 return;
290 290
291 float minPos = (m_orientation == HorizontalScrollbar) ? m_scrollableArea->mi nimumScrollPosition().x() : m_scrollableArea->minimumScrollPosition().y();
292 float maxPos = (m_orientation == HorizontalScrollbar) ? m_scrollableArea->ma ximumScrollPosition().x() : m_scrollableArea->maximumScrollPosition().y();
jamesr 2013/05/03 05:59:22 I think I've seen these lines before - can we shar
293
291 int delta = pos - m_pressedPos; 294 int delta = pos - m_pressedPos;
292 295
293 if (draggingDocument) { 296 if (draggingDocument) {
294 if (m_draggingDocument) 297 if (m_draggingDocument)
295 delta = pos - m_documentDragPos; 298 delta = pos - m_documentDragPos;
296 m_draggingDocument = true; 299 m_draggingDocument = true;
297 FloatPoint currentPosition = m_scrollableArea->scrollAnimator()->current Position(); 300 FloatPoint currentPosition = m_scrollableArea->scrollAnimator()->current Position();
298 int destinationPosition = (m_orientation == HorizontalScrollbar ? curren tPosition.x() : currentPosition.y()) + delta; 301 float destinationPosition = (m_orientation == HorizontalScrollbar ? curr entPosition.x() : currentPosition.y()) + delta;
299 if (delta > 0) 302 destinationPosition = max(min(destinationPosition, maxPos), minPos);
300 destinationPosition = min(destinationPosition + delta, maximum());
301 else if (delta < 0)
302 destinationPosition = max(destinationPosition + delta, 0);
303 m_scrollableArea->scrollToOffsetWithoutAnimation(m_orientation, destinat ionPosition); 303 m_scrollableArea->scrollToOffsetWithoutAnimation(m_orientation, destinat ionPosition);
304 m_documentDragPos = pos; 304 m_documentDragPos = pos;
305 return; 305 return;
306 } 306 }
307 307
308 if (m_draggingDocument) { 308 if (m_draggingDocument) {
309 delta += m_pressedPos - m_documentDragPos; 309 delta += m_pressedPos - m_documentDragPos;
310 m_draggingDocument = false; 310 m_draggingDocument = false;
311 } 311 }
312 312
313 // Drag the thumb. 313 // Drag the thumb.
314 int thumbPos = theme()->thumbPosition(this); 314 int thumbPos = theme()->thumbPosition(this);
315 int thumbLen = theme()->thumbLength(this); 315 int thumbLen = theme()->thumbLength(this);
316 int trackLen = theme()->trackLength(this); 316 int trackLen = theme()->trackLength(this);
317 int maxPos = trackLen - thumbLen;
318 if (delta > 0) 317 if (delta > 0)
319 delta = min(maxPos - thumbPos, delta); 318 delta = min(trackLen - thumbLen - thumbPos, delta);
320 else if (delta < 0) 319 else if (delta < 0)
321 delta = max(-thumbPos, delta); 320 delta = max(-thumbPos, delta);
322 321
323 if (delta) { 322 if (delta) {
324 float newPosition = static_cast<float>(thumbPos + delta) * maximum() / ( trackLen - thumbLen); 323 float newPosition = static_cast<float>(thumbPos + delta) * (maxPos - min Pos) / (trackLen - thumbLen) + minPos;
325 m_scrollableArea->scrollToOffsetWithoutAnimation(m_orientation, newPosit ion); 324 m_scrollableArea->scrollToOffsetWithoutAnimation(m_orientation, newPosit ion);
326 } 325 }
327 } 326 }
328 327
329 void Scrollbar::setHoveredPart(ScrollbarPart part) 328 void Scrollbar::setHoveredPart(ScrollbarPart part)
330 { 329 {
331 if (part == m_hoveredPart) 330 if (part == m_hoveredPart)
332 return; 331 return;
333 332
334 if ((m_hoveredPart == NoPart || part == NoPart) && theme()->invalidateOnMous eEnterExit()) 333 if ((m_hoveredPart == NoPart || part == NoPart) && theme()->invalidateOnMous eEnterExit())
(...skipping 264 matching lines...) Expand 10 before | Expand all | Expand 10 after
599 598
600 IntPoint Scrollbar::convertFromContainingView(const IntPoint& parentPoint) const 599 IntPoint Scrollbar::convertFromContainingView(const IntPoint& parentPoint) const
601 { 600 {
602 if (m_scrollableArea) 601 if (m_scrollableArea)
603 return m_scrollableArea->convertFromContainingViewToScrollbar(this, pare ntPoint); 602 return m_scrollableArea->convertFromContainingViewToScrollbar(this, pare ntPoint);
604 603
605 return Widget::convertFromContainingView(parentPoint); 604 return Widget::convertFromContainingView(parentPoint);
606 } 605 }
607 606
608 } // namespace WebCore 607 } // namespace WebCore
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698