| OLD | NEW |
| 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 236 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 247 void Scrollbar::moveThumb(int pos, bool draggingDocument) { | 247 void Scrollbar::moveThumb(int pos, bool draggingDocument) { |
| 248 if (!m_scrollableArea) | 248 if (!m_scrollableArea) |
| 249 return; | 249 return; |
| 250 | 250 |
| 251 int delta = pos - m_pressedPos; | 251 int delta = pos - m_pressedPos; |
| 252 | 252 |
| 253 if (draggingDocument) { | 253 if (draggingDocument) { |
| 254 if (m_draggingDocument) | 254 if (m_draggingDocument) |
| 255 delta = pos - m_documentDragPos; | 255 delta = pos - m_documentDragPos; |
| 256 m_draggingDocument = true; | 256 m_draggingDocument = true; |
| 257 FloatPoint currentPosition = | 257 ScrollOffset currentPosition = |
| 258 m_scrollableArea->scrollAnimator().currentPosition(); | 258 m_scrollableArea->scrollAnimator().currentOffset(); |
| 259 float destinationPosition = | 259 float destinationPosition = |
| 260 (m_orientation == HorizontalScrollbar ? currentPosition.x() | 260 (m_orientation == HorizontalScrollbar ? currentPosition.width() |
| 261 : currentPosition.y()) + | 261 : currentPosition.height()) + |
| 262 delta; | 262 delta; |
| 263 destinationPosition = m_scrollableArea->clampScrollPosition( | 263 destinationPosition = |
| 264 m_orientation, destinationPosition); | 264 m_scrollableArea->clampScrollOffset(m_orientation, destinationPosition); |
| 265 m_scrollableArea->setScrollPositionSingleAxis( | 265 m_scrollableArea->setScrollOffsetSingleAxis( |
| 266 m_orientation, destinationPosition, UserScroll); | 266 m_orientation, destinationPosition, UserScroll); |
| 267 m_documentDragPos = pos; | 267 m_documentDragPos = pos; |
| 268 return; | 268 return; |
| 269 } | 269 } |
| 270 | 270 |
| 271 if (m_draggingDocument) { | 271 if (m_draggingDocument) { |
| 272 delta += m_pressedPos - m_documentDragPos; | 272 delta += m_pressedPos - m_documentDragPos; |
| 273 m_draggingDocument = false; | 273 m_draggingDocument = false; |
| 274 } | 274 } |
| 275 | 275 |
| 276 // Drag the thumb. | 276 // Drag the thumb. |
| 277 int thumbPos = theme().thumbPosition(*this); | 277 int thumbPos = theme().thumbPosition(*this); |
| 278 int thumbLen = theme().thumbLength(*this); | 278 int thumbLen = theme().thumbLength(*this); |
| 279 int trackLen = theme().trackLength(*this); | 279 int trackLen = theme().trackLength(*this); |
| 280 ASSERT(thumbLen <= trackLen); | 280 ASSERT(thumbLen <= trackLen); |
| 281 if (thumbLen == trackLen) | 281 if (thumbLen == trackLen) |
| 282 return; | 282 return; |
| 283 | 283 |
| 284 if (delta > 0) | 284 if (delta > 0) |
| 285 delta = std::min(trackLen - thumbLen - thumbPos, delta); | 285 delta = std::min(trackLen - thumbLen - thumbPos, delta); |
| 286 else if (delta < 0) | 286 else if (delta < 0) |
| 287 delta = std::max(-thumbPos, delta); | 287 delta = std::max(-thumbPos, delta); |
| 288 | 288 |
| 289 float minPos = m_scrollableArea->minimumScrollPosition(m_orientation); | 289 float minOffset = m_scrollableArea->minimumScrollOffset(m_orientation); |
| 290 float maxPos = m_scrollableArea->maximumScrollPosition(m_orientation); | 290 float maxOffset = m_scrollableArea->maximumScrollOffset(m_orientation); |
| 291 if (delta) { | 291 if (delta) { |
| 292 float newPosition = static_cast<float>(thumbPos + delta) * | 292 float newOffset = static_cast<float>(thumbPos + delta) * |
| 293 (maxPos - minPos) / (trackLen - thumbLen) + | 293 (maxOffset - minOffset) / (trackLen - thumbLen) + |
| 294 minPos; | 294 minOffset; |
| 295 m_scrollableArea->setScrollPositionSingleAxis(m_orientation, newPosition, | 295 m_scrollableArea->setScrollOffsetSingleAxis(m_orientation, newOffset, |
| 296 UserScroll); | 296 UserScroll); |
| 297 } | 297 } |
| 298 } | 298 } |
| 299 | 299 |
| 300 void Scrollbar::setHoveredPart(ScrollbarPart part) { | 300 void Scrollbar::setHoveredPart(ScrollbarPart part) { |
| 301 if (part == m_hoveredPart) | 301 if (part == m_hoveredPart) |
| 302 return; | 302 return; |
| 303 | 303 |
| 304 if (((m_hoveredPart == NoPart || part == NoPart) && | 304 if (((m_hoveredPart == NoPart || part == NoPart) && |
| 305 theme().invalidateOnMouseEnterExit()) | 305 theme().invalidateOnMouseEnterExit()) |
| 306 // When there's a pressed part, we don't draw a hovered state, so there's | 306 // When there's a pressed part, we don't draw a hovered state, so there's |
| (...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 405 default: | 405 default: |
| 406 // By default, we assume that gestures don't deselect the scrollbar. | 406 // By default, we assume that gestures don't deselect the scrollbar. |
| 407 return true; | 407 return true; |
| 408 } | 408 } |
| 409 } | 409 } |
| 410 | 410 |
| 411 void Scrollbar::mouseMoved(const PlatformMouseEvent& evt) { | 411 void Scrollbar::mouseMoved(const PlatformMouseEvent& evt) { |
| 412 if (m_pressedPart == ThumbPart) { | 412 if (m_pressedPart == ThumbPart) { |
| 413 if (theme().shouldSnapBackToDragOrigin(*this, evt)) { | 413 if (theme().shouldSnapBackToDragOrigin(*this, evt)) { |
| 414 if (m_scrollableArea) { | 414 if (m_scrollableArea) { |
| 415 m_scrollableArea->setScrollPositionSingleAxis( | 415 m_scrollableArea->setScrollOffsetSingleAxis( |
| 416 m_orientation, | 416 m_orientation, |
| 417 m_dragOrigin + | 417 m_dragOrigin + m_scrollableArea->minimumScrollOffset(m_orientation), |
| 418 m_scrollableArea->minimumScrollPosition(m_orientation), | |
| 419 UserScroll); | 418 UserScroll); |
| 420 } | 419 } |
| 421 } else { | 420 } else { |
| 422 moveThumb(m_orientation == HorizontalScrollbar | 421 moveThumb(m_orientation == HorizontalScrollbar |
| 423 ? convertFromRootFrame(evt.position()).x() | 422 ? convertFromRootFrame(evt.position()).x() |
| 424 : convertFromRootFrame(evt.position()).y(), | 423 : convertFromRootFrame(evt.position()).y(), |
| 425 theme().shouldDragDocumentInsteadOfThumb(*this, evt)); | 424 theme().shouldDragDocumentInsteadOfThumb(*this, evt)); |
| 426 } | 425 } |
| 427 return; | 426 return; |
| 428 } | 427 } |
| (...skipping 152 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 581 return m_scrollableArea->convertFromContainingWidgetToScrollbar( | 580 return m_scrollableArea->convertFromContainingWidgetToScrollbar( |
| 582 *this, parentPoint); | 581 *this, parentPoint); |
| 583 | 582 |
| 584 return Widget::convertFromContainingWidget(parentPoint); | 583 return Widget::convertFromContainingWidget(parentPoint); |
| 585 } | 584 } |
| 586 | 585 |
| 587 float Scrollbar::scrollableAreaCurrentPos() const { | 586 float Scrollbar::scrollableAreaCurrentPos() const { |
| 588 if (!m_scrollableArea) | 587 if (!m_scrollableArea) |
| 589 return 0; | 588 return 0; |
| 590 | 589 |
| 591 if (m_orientation == HorizontalScrollbar) | 590 if (m_orientation == HorizontalScrollbar) { |
| 592 return m_scrollableArea->scrollPosition().x() - | 591 return m_scrollableArea->scrollOffset().width() - |
| 593 m_scrollableArea->minimumScrollPosition().x(); | 592 m_scrollableArea->minimumScrollOffset().width(); |
| 593 } |
| 594 | 594 |
| 595 return m_scrollableArea->scrollPosition().y() - | 595 return m_scrollableArea->scrollOffset().height() - |
| 596 m_scrollableArea->minimumScrollPosition().y(); | 596 m_scrollableArea->minimumScrollOffset().height(); |
| 597 } | 597 } |
| 598 | 598 |
| 599 float Scrollbar::scrollableAreaTargetPos() const { | 599 float Scrollbar::scrollableAreaTargetPos() const { |
| 600 if (!m_scrollableArea) | 600 if (!m_scrollableArea) |
| 601 return 0; | 601 return 0; |
| 602 | 602 |
| 603 if (m_orientation == HorizontalScrollbar) | 603 if (m_orientation == HorizontalScrollbar) { |
| 604 return m_scrollableArea->scrollAnimator().desiredTargetPosition().x() - | 604 return m_scrollableArea->scrollAnimator().desiredTargetOffset().width() - |
| 605 m_scrollableArea->minimumScrollPosition().x(); | 605 m_scrollableArea->minimumScrollOffset().width(); |
| 606 } |
| 606 | 607 |
| 607 return m_scrollableArea->scrollAnimator().desiredTargetPosition().y() - | 608 return m_scrollableArea->scrollAnimator().desiredTargetOffset().height() - |
| 608 m_scrollableArea->minimumScrollPosition().y(); | 609 m_scrollableArea->minimumScrollOffset().height(); |
| 609 } | 610 } |
| 610 | 611 |
| 611 LayoutRect Scrollbar::visualRect() const { | 612 LayoutRect Scrollbar::visualRect() const { |
| 612 return m_scrollableArea ? m_scrollableArea->visualRectForScrollbarParts() | 613 return m_scrollableArea ? m_scrollableArea->visualRectForScrollbarParts() |
| 613 : LayoutRect(); | 614 : LayoutRect(); |
| 614 } | 615 } |
| 615 | 616 |
| 616 void Scrollbar::setNeedsPaintInvalidation(ScrollbarPart invalidParts) { | 617 void Scrollbar::setNeedsPaintInvalidation(ScrollbarPart invalidParts) { |
| 617 if (m_theme.shouldRepaintAllPartsOnInvalidation()) | 618 if (m_theme.shouldRepaintAllPartsOnInvalidation()) |
| 618 invalidParts = AllParts; | 619 invalidParts = AllParts; |
| 619 if (invalidParts & ~ThumbPart) | 620 if (invalidParts & ~ThumbPart) |
| 620 m_trackNeedsRepaint = true; | 621 m_trackNeedsRepaint = true; |
| 621 if (invalidParts & ThumbPart) | 622 if (invalidParts & ThumbPart) |
| 622 m_thumbNeedsRepaint = true; | 623 m_thumbNeedsRepaint = true; |
| 623 if (m_scrollableArea) | 624 if (m_scrollableArea) |
| 624 m_scrollableArea->setScrollbarNeedsPaintInvalidation(orientation()); | 625 m_scrollableArea->setScrollbarNeedsPaintInvalidation(orientation()); |
| 625 } | 626 } |
| 626 | 627 |
| 627 } // namespace blink | 628 } // namespace blink |
| OLD | NEW |