| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (c) 2010, Google Inc. All rights reserved. | 2 * Copyright (c) 2010, Google Inc. All rights reserved. |
| 3 * Copyright (C) 2008, 2011 Apple Inc. All Rights Reserved. | 3 * Copyright (C) 2008, 2011 Apple Inc. All Rights Reserved. |
| 4 * | 4 * |
| 5 * Redistribution and use in source and binary forms, with or without | 5 * Redistribution and use in source and binary forms, with or without |
| 6 * modification, are permitted provided that the following conditions are | 6 * modification, are permitted provided that the following conditions are |
| 7 * met: | 7 * met: |
| 8 * | 8 * |
| 9 * * Redistributions of source code must retain the above copyright | 9 * * Redistributions of source code must retain the above copyright |
| 10 * notice, this list of conditions and the following disclaimer. | 10 * notice, this list of conditions and the following disclaimer. |
| (...skipping 195 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 206 if (scrollBehavior == ScrollBehaviorSmooth) | 206 if (scrollBehavior == ScrollBehaviorSmooth) |
| 207 programmaticScrollAnimator()->animateToOffset(toFloatPoint(position)); | 207 programmaticScrollAnimator()->animateToOffset(toFloatPoint(position)); |
| 208 else | 208 else |
| 209 programmaticScrollAnimator()->scrollToOffsetWithoutAnimation(toFloatPoin
t(position)); | 209 programmaticScrollAnimator()->scrollToOffsetWithoutAnimation(toFloatPoin
t(position)); |
| 210 } | 210 } |
| 211 | 211 |
| 212 void ScrollableArea::userScrollHelper(const DoublePoint& position, ScrollBehavio
r scrollBehavior) | 212 void ScrollableArea::userScrollHelper(const DoublePoint& position, ScrollBehavio
r scrollBehavior) |
| 213 { | 213 { |
| 214 cancelProgrammaticScrollAnimation(); | 214 cancelProgrammaticScrollAnimation(); |
| 215 | 215 |
| 216 double x = userInputScrollable(HorizontalScrollbar) ? position.x() : scroll
Animator()->currentPosition().x(); |
| 217 double y = userInputScrollable(VerticalScrollbar) ? position.y() : scrollAn
imator()->currentPosition().y(); |
| 218 DoublePoint newPosition(x, y); |
| 219 |
| 216 // Smooth user scrolls (keyboard, wheel clicks) are handled via the userScro
ll method. | 220 // Smooth user scrolls (keyboard, wheel clicks) are handled via the userScro
ll method. |
| 217 // TODO(bokan): The userScroll method should probably be modified to call th
is method | 221 // TODO(bokan): The userScroll method should probably be modified to call th
is method |
| 218 // and ScrollAnimator to have a simpler animateToOffset method
like the | 222 // and ScrollAnimator to have a simpler animateToOffset method
like the |
| 219 // ProgrammaticScrollAnimator. | 223 // ProgrammaticScrollAnimator. |
| 220 ASSERT(scrollBehavior == ScrollBehaviorInstant); | 224 ASSERT(scrollBehavior == ScrollBehaviorInstant); |
| 221 scrollAnimator()->scrollToOffsetWithoutAnimation(toFloatPoint(position)); | 225 scrollAnimator()->scrollToOffsetWithoutAnimation(toFloatPoint(newPosition)); |
| 222 } | 226 } |
| 223 | 227 |
| 224 void ScrollableArea::scrollIntoRect(const LayoutRect& rectInContent, const Float
Rect& targetRectInFrame) | 228 void ScrollableArea::scrollIntoRect(const LayoutRect& rectInContent, const Float
Rect& targetRectInFrame) |
| 225 { | 229 { |
| 226 // Use |pixelSnappedIntRect| for rounding to pixel as opposed to |enclosingI
ntRect|. It gives a better | 230 // Use |pixelSnappedIntRect| for rounding to pixel as opposed to |enclosingI
ntRect|. It gives a better |
| 227 // combined (location and size) rounding error resulting in a more accurate
scroll offset. | 231 // combined (location and size) rounding error resulting in a more accurate
scroll offset. |
| 228 // FIXME: It would probably be best to do the whole calculation in LayoutUni
ts but contentsToRootFrame | 232 // FIXME: It would probably be best to do the whole calculation in LayoutUni
ts but contentsToRootFrame |
| 229 // and friends don't have LayoutRect/Point versions yet. | 233 // and friends don't have LayoutRect/Point versions yet. |
| 230 IntRect boundsInContent = pixelSnappedIntRect(rectInContent); | 234 IntRect boundsInContent = pixelSnappedIntRect(rectInContent); |
| 231 IntRect boundsInFrame(boundsInContent.location() - toIntSize(scrollPosition(
)), boundsInContent.size()); | 235 IntRect boundsInFrame(boundsInContent.location() - toIntSize(scrollPosition(
)), boundsInContent.size()); |
| 232 | 236 |
| 233 int centeringOffsetX = (targetRectInFrame.width() - boundsInFrame.width()) /
2; | 237 int centeringOffsetX = (targetRectInFrame.width() - boundsInFrame.width()) /
2; |
| 234 int centeringOffsetY = (targetRectInFrame.height() - boundsInFrame.height())
/ 2; | 238 int centeringOffsetY = (targetRectInFrame.height() - boundsInFrame.height())
/ 2; |
| 235 | 239 |
| 236 IntSize scrollDelta( | 240 IntSize scrollDelta( |
| 237 boundsInFrame.x() - centeringOffsetX - targetRectInFrame.x(), | 241 boundsInFrame.x() - centeringOffsetX - targetRectInFrame.x(), |
| 238 boundsInFrame.y() - centeringOffsetY - targetRectInFrame.y()); | 242 boundsInFrame.y() - centeringOffsetY - targetRectInFrame.y()); |
| 239 | 243 |
| 240 DoublePoint targetOffset = DoublePoint(scrollPosition() + scrollDelta); | 244 DoublePoint targetOffset = DoublePoint(scrollPosition() + scrollDelta); |
| 241 | 245 |
| 242 setScrollPosition(targetOffset, ProgrammaticScroll); | 246 setScrollPosition(targetOffset, ProgrammaticScroll); |
| 243 } | 247 } |
| 244 | 248 |
| 245 LayoutRect ScrollableArea::scrollIntoView(const LayoutRect& rectInContent, const
ScrollAlignment& alignX, const ScrollAlignment& alignY) | 249 LayoutRect ScrollableArea::scrollIntoView(const LayoutRect& rectInContent, const
ScrollAlignment& alignX, const ScrollAlignment& alignY, ScrollType) |
| 246 { | 250 { |
| 247 // TODO(bokan): This should really be implemented here but ScrollAlignment i
s in Core which is a dependency violation. | 251 // TODO(bokan): This should really be implemented here but ScrollAlignment i
s in Core which is a dependency violation. |
| 248 ASSERT_NOT_REACHED(); | 252 ASSERT_NOT_REACHED(); |
| 249 return LayoutRect(); | 253 return LayoutRect(); |
| 250 } | 254 } |
| 251 | 255 |
| 252 void ScrollableArea::scrollPositionChanged(const DoublePoint& position, ScrollTy
pe scrollType) | 256 void ScrollableArea::scrollPositionChanged(const DoublePoint& position, ScrollTy
pe scrollType) |
| 253 { | 257 { |
| 254 TRACE_EVENT0("blink", "ScrollableArea::scrollPositionChanged"); | 258 TRACE_EVENT0("blink", "ScrollableArea::scrollPositionChanged"); |
| 255 | 259 |
| (...skipping 344 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 600 verticalScrollbarWidth = !verticalBar->isOverlayScrollbar() ? verticalBa
r->width() : 0; | 604 verticalScrollbarWidth = !verticalBar->isOverlayScrollbar() ? verticalBa
r->width() : 0; |
| 601 if (Scrollbar* horizontalBar = horizontalScrollbar()) | 605 if (Scrollbar* horizontalBar = horizontalScrollbar()) |
| 602 horizontalScrollbarHeight = !horizontalBar->isOverlayScrollbar() ? horiz
ontalBar->height() : 0; | 606 horizontalScrollbarHeight = !horizontalBar->isOverlayScrollbar() ? horiz
ontalBar->height() : 0; |
| 603 | 607 |
| 604 return IntSize(std::max(0, size.width() - verticalScrollbarWidth), | 608 return IntSize(std::max(0, size.width() - verticalScrollbarWidth), |
| 605 std::max(0, size.height() - horizontalScrollbarHeight)); | 609 std::max(0, size.height() - horizontalScrollbarHeight)); |
| 606 | 610 |
| 607 } | 611 } |
| 608 | 612 |
| 609 } // namespace blink | 613 } // namespace blink |
| OLD | NEW |