Chromium Code Reviews| 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 140 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 151 step = pixelStep(orientation); | 151 step = pixelStep(orientation); |
| 152 break; | 152 break; |
| 153 } | 153 } |
| 154 | 154 |
| 155 if (direction == ScrollUp || direction == ScrollLeft) | 155 if (direction == ScrollUp || direction == ScrollLeft) |
| 156 delta = -delta; | 156 delta = -delta; |
| 157 | 157 |
| 158 return scrollAnimator()->userScroll(orientation, granularity, step, delta).d idScroll; | 158 return scrollAnimator()->userScroll(orientation, granularity, step, delta).d idScroll; |
| 159 } | 159 } |
| 160 | 160 |
| 161 void ScrollableArea::setScrollPosition(const DoublePoint& position, ScrollBehavi or behavior) | 161 void ScrollableArea::setScrollPosition(const DoublePoint& position, ScrollType s crollType, ScrollBehavior behavior) |
| 162 { | 162 { |
| 163 // FIXME(417782): This should be unified with LayerScrollableArea::scrollToO ffset. | 163 if (behavior == ScrollBehaviorAuto) |
| 164 ASSERT_NOT_REACHED(); | 164 behavior = scrollBehaviorStyle(); |
| 165 | |
| 166 if (scrollType == CompositorScroll) | |
| 167 scrollAnimator()->scrollToOffsetWithoutAnimation(toFloatPoint(position), CompositorScroll); | |
| 168 else if (scrollType == ProgrammaticScroll) | |
| 169 programmaticScrollHelper(position, behavior); | |
| 170 else if (scrollType == UserScroll) | |
| 171 userScrollHelper(position, behavior); | |
| 172 else | |
| 173 ASSERT_NOT_REACHED(); | |
| 165 } | 174 } |
| 166 | 175 |
| 167 void ScrollableArea::scrollToOffsetWithoutAnimation(const FloatPoint& offset, bo ol cancelProgrammaticAnimations) | 176 void ScrollableArea::scrollBy(const DoubleSize& delta, ScrollType type, ScrollBe havior behavior) |
| 168 { | 177 { |
| 169 if (cancelProgrammaticAnimations) | 178 setScrollPosition(scrollPositionDouble() + delta, type, behavior); |
| 170 cancelProgrammaticScrollAnimation(); | |
| 171 scrollAnimator()->scrollToOffsetWithoutAnimation(offset); | |
| 172 } | 179 } |
| 173 | 180 |
| 174 void ScrollableArea::scrollToOffsetWithoutAnimation(ScrollbarOrientation orienta tion, float offset) | 181 void ScrollableArea::setScrollPositionSingleAxis(ScrollbarOrientation orientatio n, double position, ScrollType scrollType, ScrollBehavior behavior) |
| 175 { | 182 { |
| 183 DoublePoint newPosition; | |
| 176 if (orientation == HorizontalScrollbar) | 184 if (orientation == HorizontalScrollbar) |
| 177 scrollToOffsetWithoutAnimation(FloatPoint(offset, scrollAnimator()->curr entPosition().y())); | 185 newPosition = DoublePoint(position, scrollAnimator()->currentPosition(). y()); |
| 178 else | 186 else |
| 179 scrollToOffsetWithoutAnimation(FloatPoint(scrollAnimator()->currentPosit ion().x(), offset)); | 187 newPosition = DoublePoint(scrollAnimator()->currentPosition().x(), posit ion); |
| 188 | |
| 189 // TODO(bokan): Note, this doesn't use the derived class versions since this method is currently used | |
| 190 // exclusively by code that adjusts the position by the scroll origin and th e derived class versions | |
| 191 // differ on whether they take that into account or not. | |
| 192 ScrollableArea::setScrollPosition(newPosition, scrollType, behavior); | |
| 193 } | |
| 194 | |
| 195 void ScrollableArea::programmaticScrollHelper(const DoublePoint& position, Scrol lBehavior scrollBehavior) | |
| 196 { | |
| 197 if (scrollBehavior == ScrollBehaviorSmooth) { | |
| 198 if (ScrollAnimator* scrollAnimator = existingScrollAnimator()) | |
| 199 scrollAnimator->cancelAnimations(); | |
| 200 programmaticScrollAnimator()->animateToOffset(toFloatPoint(position)); | |
| 201 } else { | |
| 202 // TODO(bokan): This should probably use programmaticScrollAnimator. | |
| 203 cancelProgrammaticScrollAnimation(); | |
| 204 scrollAnimator()->scrollToOffsetWithoutAnimation(toFloatPoint(position), ProgrammaticScroll); | |
| 205 } | |
| 206 } | |
| 207 | |
| 208 void ScrollableArea::userScrollHelper(const DoublePoint& position, ScrollBehavio r scrollBehavior) | |
| 209 { | |
| 210 if (scrollBehavior == ScrollBehaviorSmooth) { | |
| 211 // TODO(bokan) | |
|
skobes
2015/06/04 23:35:47
Is ScrollableArea::userScroll eventually going to
bokan
2015/06/05 15:15:24
That's my hope. It can't right now since it doesn'
| |
| 212 } else { | |
| 213 cancelProgrammaticScrollAnimation(); | |
| 214 scrollAnimator()->scrollToOffsetWithoutAnimation(toFloatPoint(position), UserScroll); | |
| 215 } | |
| 180 } | 216 } |
| 181 | 217 |
| 182 void ScrollableArea::scrollIntoRect(const LayoutRect& rectInContent, const Float Rect& targetRectInFrame) | 218 void ScrollableArea::scrollIntoRect(const LayoutRect& rectInContent, const Float Rect& targetRectInFrame) |
| 183 { | 219 { |
| 184 // Use |pixelSnappedIntRect| for rounding to pixel as opposed to |enclosingI ntRect|. It gives a better | 220 // Use |pixelSnappedIntRect| for rounding to pixel as opposed to |enclosingI ntRect|. It gives a better |
| 185 // combined (location and size) rounding error resulting in a more accurate scroll offset. | 221 // combined (location and size) rounding error resulting in a more accurate scroll offset. |
| 186 // FIXME: It would probably be best to do the whole calculation in LayoutUni ts but contentsToRootFrame | 222 // FIXME: It would probably be best to do the whole calculation in LayoutUni ts but contentsToRootFrame |
| 187 // and friends don't have LayoutRect/Point versions yet. | 223 // and friends don't have LayoutRect/Point versions yet. |
| 188 IntRect boundsInContent = pixelSnappedIntRect(rectInContent); | 224 IntRect boundsInContent = pixelSnappedIntRect(rectInContent); |
| 189 IntRect boundsInFrame(boundsInContent.location() - toIntSize(scrollPosition( )), boundsInContent.size()); | 225 IntRect boundsInFrame(boundsInContent.location() - toIntSize(scrollPosition( )), boundsInContent.size()); |
| 190 | 226 |
| 191 int centeringOffsetX = (targetRectInFrame.width() - boundsInFrame.width()) / 2; | 227 int centeringOffsetX = (targetRectInFrame.width() - boundsInFrame.width()) / 2; |
| 192 int centeringOffsetY = (targetRectInFrame.height() - boundsInFrame.height()) / 2; | 228 int centeringOffsetY = (targetRectInFrame.height() - boundsInFrame.height()) / 2; |
| 193 | 229 |
| 194 IntSize scrollDelta( | 230 IntSize scrollDelta( |
| 195 boundsInFrame.x() - centeringOffsetX - targetRectInFrame.x(), | 231 boundsInFrame.x() - centeringOffsetX - targetRectInFrame.x(), |
| 196 boundsInFrame.y() - centeringOffsetY - targetRectInFrame.y()); | 232 boundsInFrame.y() - centeringOffsetY - targetRectInFrame.y()); |
| 197 | 233 |
| 198 DoublePoint targetOffset = DoublePoint(scrollPosition() + scrollDelta); | 234 DoublePoint targetOffset = DoublePoint(scrollPosition() + scrollDelta); |
| 199 | 235 |
| 200 setScrollPosition(targetOffset); | 236 setScrollPosition(targetOffset, ProgrammaticScroll); |
| 201 } | 237 } |
| 202 | 238 |
| 203 LayoutRect ScrollableArea::scrollIntoView(const LayoutRect& rectInContent, const ScrollAlignment& alignX, const ScrollAlignment& alignY) | 239 LayoutRect ScrollableArea::scrollIntoView(const LayoutRect& rectInContent, const ScrollAlignment& alignX, const ScrollAlignment& alignY) |
| 204 { | 240 { |
| 205 // TODO(bokan): This should really be implemented here but ScrollAlignment i s in Core which is a dependency violation. | 241 // TODO(bokan): This should really be implemented here but ScrollAlignment i s in Core which is a dependency violation. |
| 206 ASSERT_NOT_REACHED(); | 242 ASSERT_NOT_REACHED(); |
| 207 return LayoutRect(); | 243 return LayoutRect(); |
| 208 } | 244 } |
| 209 | 245 |
| 210 void ScrollableArea::programmaticallyScrollSmoothlyToOffset(const FloatPoint& of fset) | |
| 211 { | |
| 212 if (ScrollAnimator* scrollAnimator = existingScrollAnimator()) | |
| 213 scrollAnimator->cancelAnimations(); | |
| 214 programmaticScrollAnimator()->animateToOffset(offset); | |
| 215 } | |
| 216 | |
| 217 void ScrollableArea::notifyScrollPositionChanged(const DoublePoint& position) | 246 void ScrollableArea::notifyScrollPositionChanged(const DoublePoint& position) |
| 218 { | 247 { |
| 219 scrollPositionChanged(position); | 248 // TODO(bokan): This should probably be something other than CompositorScrol l. |
| 249 scrollPositionChanged(position, CompositorScroll); | |
| 220 scrollAnimator()->setCurrentPosition(toFloatPoint(scrollPositionDouble())); | 250 scrollAnimator()->setCurrentPosition(toFloatPoint(scrollPositionDouble())); |
| 221 } | 251 } |
| 222 | 252 |
| 223 void ScrollableArea::scrollPositionChanged(const DoublePoint& position) | 253 void ScrollableArea::scrollPositionChanged(const DoublePoint& position, ScrollTy pe scrollType) |
| 224 { | 254 { |
| 225 TRACE_EVENT0("blink", "ScrollableArea::scrollPositionChanged"); | 255 TRACE_EVENT0("blink", "ScrollableArea::scrollPositionChanged"); |
| 226 | 256 |
| 227 DoublePoint oldPosition = scrollPositionDouble(); | 257 DoublePoint oldPosition = scrollPositionDouble(); |
| 228 // Tell the derived class to scroll its contents. | 258 // Tell the derived class to scroll its contents. |
| 229 setScrollOffset(position); | 259 setScrollOffset(position, scrollType); |
| 230 | 260 |
| 231 Scrollbar* verticalScrollbar = this->verticalScrollbar(); | 261 Scrollbar* verticalScrollbar = this->verticalScrollbar(); |
| 232 | 262 |
| 233 // Tell the scrollbars to update their thumb postions. | 263 // Tell the scrollbars to update their thumb postions. |
| 234 if (Scrollbar* horizontalScrollbar = this->horizontalScrollbar()) { | 264 if (Scrollbar* horizontalScrollbar = this->horizontalScrollbar()) { |
| 235 horizontalScrollbar->offsetDidChange(); | 265 horizontalScrollbar->offsetDidChange(); |
| 236 if (horizontalScrollbar->isOverlayScrollbar() && !hasLayerForHorizontalS crollbar()) { | 266 if (horizontalScrollbar->isOverlayScrollbar() && !hasLayerForHorizontalS crollbar()) { |
| 237 if (!verticalScrollbar) | 267 if (!verticalScrollbar) |
| 238 horizontalScrollbar->invalidate(); | 268 horizontalScrollbar->invalidate(); |
| 239 else { | 269 else { |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 296 if (!constrainsScrollingToContentEdge()) | 326 if (!constrainsScrollingToContentEdge()) |
| 297 return scrollPoint; | 327 return scrollPoint; |
| 298 DoublePoint newScrollPosition = scrollPoint.shrunkTo(maximumScrollPositionDo uble()); | 328 DoublePoint newScrollPosition = scrollPoint.shrunkTo(maximumScrollPositionDo uble()); |
| 299 newScrollPosition = newScrollPosition.expandedTo(minimumScrollPositionDouble ()); | 329 newScrollPosition = newScrollPosition.expandedTo(minimumScrollPositionDouble ()); |
| 300 return newScrollPosition; | 330 return newScrollPosition; |
| 301 } | 331 } |
| 302 | 332 |
| 303 // NOTE: Only called from Internals for testing. | 333 // NOTE: Only called from Internals for testing. |
| 304 void ScrollableArea::setScrollOffsetFromInternals(const IntPoint& offset) | 334 void ScrollableArea::setScrollOffsetFromInternals(const IntPoint& offset) |
| 305 { | 335 { |
| 306 setScrollOffsetFromAnimation(DoublePoint(offset)); | 336 setScrollOffsetFromAnimation(DoublePoint(offset), ProgrammaticScroll); |
| 307 } | 337 } |
| 308 | 338 |
| 309 void ScrollableArea::setScrollOffsetFromAnimation(const DoublePoint& offset) | 339 void ScrollableArea::setScrollOffsetFromAnimation(const DoublePoint& offset, Scr ollType scrollType) |
| 310 { | 340 { |
| 311 scrollPositionChanged(offset); | 341 scrollPositionChanged(offset, scrollType); |
| 312 } | 342 } |
| 313 | 343 |
| 314 void ScrollableArea::willStartLiveResize() | 344 void ScrollableArea::willStartLiveResize() |
| 315 { | 345 { |
| 316 if (m_inLiveResize) | 346 if (m_inLiveResize) |
| 317 return; | 347 return; |
| 318 m_inLiveResize = true; | 348 m_inLiveResize = true; |
| 319 if (ScrollAnimator* scrollAnimator = existingScrollAnimator()) | 349 if (ScrollAnimator* scrollAnimator = existingScrollAnimator()) |
| 320 scrollAnimator->willStartLiveResize(); | 350 scrollAnimator->willStartLiveResize(); |
| 321 } | 351 } |
| (...skipping 273 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 595 verticalScrollbarWidth = !verticalBar->isOverlayScrollbar() ? verticalBa r->width() : 0; | 625 verticalScrollbarWidth = !verticalBar->isOverlayScrollbar() ? verticalBa r->width() : 0; |
| 596 if (Scrollbar* horizontalBar = horizontalScrollbar()) | 626 if (Scrollbar* horizontalBar = horizontalScrollbar()) |
| 597 horizontalScrollbarHeight = !horizontalBar->isOverlayScrollbar() ? horiz ontalBar->height() : 0; | 627 horizontalScrollbarHeight = !horizontalBar->isOverlayScrollbar() ? horiz ontalBar->height() : 0; |
| 598 | 628 |
| 599 return IntSize(std::max(0, size.width() - verticalScrollbarWidth), | 629 return IntSize(std::max(0, size.width() - verticalScrollbarWidth), |
| 600 std::max(0, size.height() - horizontalScrollbarHeight)); | 630 std::max(0, size.height() - horizontalScrollbarHeight)); |
| 601 | 631 |
| 602 } | 632 } |
| 603 | 633 |
| 604 } // namespace blink | 634 } // namespace blink |
| OLD | NEW |