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