| 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 19 matching lines...) Expand all Loading... |
| 30 */ | 30 */ |
| 31 | 31 |
| 32 #include "platform/scroll/ScrollableArea.h" | 32 #include "platform/scroll/ScrollableArea.h" |
| 33 | 33 |
| 34 #include "platform/PlatformChromeClient.h" | 34 #include "platform/PlatformChromeClient.h" |
| 35 #include "platform/graphics/GraphicsLayer.h" | 35 #include "platform/graphics/GraphicsLayer.h" |
| 36 #include "platform/instrumentation/tracing/TraceEvent.h" | 36 #include "platform/instrumentation/tracing/TraceEvent.h" |
| 37 #include "platform/scroll/MainThreadScrollingReason.h" | 37 #include "platform/scroll/MainThreadScrollingReason.h" |
| 38 #include "platform/scroll/ProgrammaticScrollAnimator.h" | 38 #include "platform/scroll/ProgrammaticScrollAnimator.h" |
| 39 #include "platform/scroll/ScrollbarTheme.h" | 39 #include "platform/scroll/ScrollbarTheme.h" |
| 40 #include "platform/scroll/SmoothScrollSequencer.h" |
| 40 | 41 |
| 41 static const int kPixelsPerLineStep = 40; | 42 static const int kPixelsPerLineStep = 40; |
| 42 static const float kMinFractionToStepWhenPaging = 0.875f; | 43 static const float kMinFractionToStepWhenPaging = 0.875f; |
| 43 | 44 |
| 44 namespace blink { | 45 namespace blink { |
| 45 | 46 |
| 46 int ScrollableArea::PixelsPerLineStep(PlatformChromeClient* host) { | 47 int ScrollableArea::PixelsPerLineStep(PlatformChromeClient* host) { |
| 47 if (!host) | 48 if (!host) |
| 48 return kPixelsPerLineStep; | 49 return kPixelsPerLineStep; |
| 49 return host->WindowToViewportScalar(kPixelsPerLineStep); | 50 return host->WindowToViewportScalar(kPixelsPerLineStep); |
| (...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 147 ScrollOffset scrollable_axis_delta( | 148 ScrollOffset scrollable_axis_delta( |
| 148 UserInputScrollable(kHorizontalScrollbar) ? pixel_delta.Width() : 0, | 149 UserInputScrollable(kHorizontalScrollbar) ? pixel_delta.Width() : 0, |
| 149 UserInputScrollable(kVerticalScrollbar) ? pixel_delta.Height() : 0); | 150 UserInputScrollable(kVerticalScrollbar) ? pixel_delta.Height() : 0); |
| 150 | 151 |
| 151 if (scrollable_axis_delta.IsZero()) { | 152 if (scrollable_axis_delta.IsZero()) { |
| 152 return ScrollResult(false, false, pixel_delta.Width(), | 153 return ScrollResult(false, false, pixel_delta.Width(), |
| 153 pixel_delta.Height()); | 154 pixel_delta.Height()); |
| 154 } | 155 } |
| 155 | 156 |
| 156 CancelProgrammaticScrollAnimation(); | 157 CancelProgrammaticScrollAnimation(); |
| 158 if (SmoothScrollSequencer* sequencer = GetSmoothScrollSequencer()) |
| 159 sequencer->AbortAnimations(); |
| 157 | 160 |
| 158 ScrollResult result = | 161 ScrollResult result = |
| 159 GetScrollAnimator().UserScroll(granularity, pixel_delta); | 162 GetScrollAnimator().UserScroll(granularity, pixel_delta); |
| 160 | 163 |
| 161 // Delta that wasn't scrolled because the axis is !userInputScrollable | 164 // Delta that wasn't scrolled because the axis is !userInputScrollable |
| 162 // should count as unusedScrollDelta. | 165 // should count as unusedScrollDelta. |
| 163 ScrollOffset unscrollable_axis_delta = pixel_delta - scrollable_axis_delta; | 166 ScrollOffset unscrollable_axis_delta = pixel_delta - scrollable_axis_delta; |
| 164 result.unused_scroll_delta_x += unscrollable_axis_delta.Width(); | 167 result.unused_scroll_delta_x += unscrollable_axis_delta.Width(); |
| 165 result.unused_scroll_delta_y += unscrollable_axis_delta.Height(); | 168 result.unused_scroll_delta_y += unscrollable_axis_delta.Height(); |
| 166 | 169 |
| 167 return result; | 170 return result; |
| 168 } | 171 } |
| 169 | 172 |
| 170 void ScrollableArea::SetScrollOffset(const ScrollOffset& offset, | 173 void ScrollableArea::SetScrollOffset(const ScrollOffset& offset, |
| 171 ScrollType scroll_type, | 174 ScrollType scroll_type, |
| 172 ScrollBehavior behavior) { | 175 ScrollBehavior behavior) { |
| 176 if (scroll_type != kSequencedSmoothScroll && scroll_type != kClampingScroll && |
| 177 scroll_type != kAnchoringScroll) { |
| 178 if (SmoothScrollSequencer* sequencer = GetSmoothScrollSequencer()) |
| 179 sequencer->AbortAnimations(); |
| 180 } |
| 181 |
| 173 ScrollOffset clamped_offset = ClampScrollOffset(offset); | 182 ScrollOffset clamped_offset = ClampScrollOffset(offset); |
| 174 if (clamped_offset == GetScrollOffset()) | 183 if (clamped_offset == GetScrollOffset()) |
| 175 return; | 184 return; |
| 176 | 185 |
| 177 if (behavior == kScrollBehaviorAuto) | 186 if (behavior == kScrollBehaviorAuto) |
| 178 behavior = ScrollBehaviorStyle(); | 187 behavior = ScrollBehaviorStyle(); |
| 179 | 188 |
| 180 switch (scroll_type) { | 189 switch (scroll_type) { |
| 181 case kCompositorScroll: | 190 case kCompositorScroll: |
| 182 case kClampingScroll: | 191 case kClampingScroll: |
| 183 ScrollOffsetChanged(clamped_offset, scroll_type); | 192 ScrollOffsetChanged(clamped_offset, scroll_type); |
| 184 break; | 193 break; |
| 185 case kAnchoringScroll: | 194 case kAnchoringScroll: |
| 186 GetScrollAnimator().AdjustAnimationAndSetScrollOffset(clamped_offset, | 195 GetScrollAnimator().AdjustAnimationAndSetScrollOffset(clamped_offset, |
| 187 scroll_type); | 196 scroll_type); |
| 188 break; | 197 break; |
| 189 case kProgrammaticScroll: | 198 case kProgrammaticScroll: |
| 190 ProgrammaticScrollHelper(clamped_offset, behavior); | 199 ProgrammaticScrollHelper(clamped_offset, behavior, false); |
| 200 break; |
| 201 case kSequencedSmoothScroll: |
| 202 ProgrammaticScrollHelper(clamped_offset, behavior, true); |
| 191 break; | 203 break; |
| 192 case kUserScroll: | 204 case kUserScroll: |
| 193 UserScrollHelper(clamped_offset, behavior); | 205 UserScrollHelper(clamped_offset, behavior); |
| 194 break; | 206 break; |
| 195 default: | 207 default: |
| 196 NOTREACHED(); | 208 NOTREACHED(); |
| 197 } | 209 } |
| 198 } | 210 } |
| 199 | 211 |
| 200 void ScrollableArea::ScrollBy(const ScrollOffset& delta, | 212 void ScrollableArea::ScrollBy(const ScrollOffset& delta, |
| (...skipping 14 matching lines...) Expand all Loading... |
| 215 new_offset = | 227 new_offset = |
| 216 ScrollOffset(GetScrollAnimator().CurrentOffset().Width(), offset); | 228 ScrollOffset(GetScrollAnimator().CurrentOffset().Width(), offset); |
| 217 | 229 |
| 218 // TODO(bokan): Note, this doesn't use the derived class versions since this | 230 // TODO(bokan): Note, this doesn't use the derived class versions since this |
| 219 // method is currently used exclusively by code that adjusts the position by | 231 // method is currently used exclusively by code that adjusts the position by |
| 220 // the scroll origin and the derived class versions differ on whether they | 232 // the scroll origin and the derived class versions differ on whether they |
| 221 // take that into account or not. | 233 // take that into account or not. |
| 222 ScrollableArea::SetScrollOffset(new_offset, scroll_type, behavior); | 234 ScrollableArea::SetScrollOffset(new_offset, scroll_type, behavior); |
| 223 } | 235 } |
| 224 | 236 |
| 225 void ScrollableArea::ProgrammaticScrollHelper(const ScrollOffset& offset, | 237 void ScrollableArea::ProgrammaticScrollHelper( |
| 226 ScrollBehavior scroll_behavior) { | 238 const ScrollOffset& offset, |
| 239 ScrollBehavior scroll_behavior, |
| 240 bool sequenced_for_smooth_scroll) { |
| 227 CancelScrollAnimation(); | 241 CancelScrollAnimation(); |
| 228 | 242 |
| 229 if (scroll_behavior == kScrollBehaviorSmooth) | 243 if (scroll_behavior == kScrollBehaviorSmooth) { |
| 230 GetProgrammaticScrollAnimator().AnimateToOffset(offset); | 244 GetProgrammaticScrollAnimator().AnimateToOffset( |
| 231 else | 245 offset, sequenced_for_smooth_scroll); |
| 246 } else { |
| 232 GetProgrammaticScrollAnimator().ScrollToOffsetWithoutAnimation(offset); | 247 GetProgrammaticScrollAnimator().ScrollToOffsetWithoutAnimation(offset); |
| 248 } |
| 233 } | 249 } |
| 234 | 250 |
| 235 void ScrollableArea::UserScrollHelper(const ScrollOffset& offset, | 251 void ScrollableArea::UserScrollHelper(const ScrollOffset& offset, |
| 236 ScrollBehavior scroll_behavior) { | 252 ScrollBehavior scroll_behavior) { |
| 237 CancelProgrammaticScrollAnimation(); | 253 CancelProgrammaticScrollAnimation(); |
| 254 if (SmoothScrollSequencer* sequencer = GetSmoothScrollSequencer()) |
| 255 sequencer->AbortAnimations(); |
| 238 | 256 |
| 239 float x = UserInputScrollable(kHorizontalScrollbar) | 257 float x = UserInputScrollable(kHorizontalScrollbar) |
| 240 ? offset.Width() | 258 ? offset.Width() |
| 241 : GetScrollAnimator().CurrentOffset().Width(); | 259 : GetScrollAnimator().CurrentOffset().Width(); |
| 242 float y = UserInputScrollable(kVerticalScrollbar) | 260 float y = UserInputScrollable(kVerticalScrollbar) |
| 243 ? offset.Height() | 261 ? offset.Height() |
| 244 : GetScrollAnimator().CurrentOffset().Height(); | 262 : GetScrollAnimator().CurrentOffset().Height(); |
| 245 | 263 |
| 246 // Smooth user scrolls (keyboard, wheel clicks) are handled via the userScroll | 264 // Smooth user scrolls (keyboard, wheel clicks) are handled via the userScroll |
| 247 // method. | 265 // method. |
| 248 // TODO(bokan): The userScroll method should probably be modified to call this | 266 // TODO(bokan): The userScroll method should probably be modified to call this |
| 249 // method and ScrollAnimatorBase to have a simpler | 267 // method and ScrollAnimatorBase to have a simpler |
| 250 // animateToOffset method like the ProgrammaticScrollAnimator. | 268 // animateToOffset method like the ProgrammaticScrollAnimator. |
| 251 DCHECK_EQ(scroll_behavior, kScrollBehaviorInstant); | 269 DCHECK_EQ(scroll_behavior, kScrollBehaviorInstant); |
| 252 GetScrollAnimator().ScrollToOffsetWithoutAnimation(ScrollOffset(x, y)); | 270 GetScrollAnimator().ScrollToOffsetWithoutAnimation(ScrollOffset(x, y)); |
| 253 } | 271 } |
| 254 | 272 |
| 255 LayoutRect ScrollableArea::ScrollIntoView(const LayoutRect& rect_in_content, | 273 LayoutRect ScrollableArea::ScrollIntoView(const LayoutRect& rect_in_content, |
| 256 const ScrollAlignment& align_x, | 274 const ScrollAlignment& align_x, |
| 257 const ScrollAlignment& align_y, | 275 const ScrollAlignment& align_y, |
| 276 bool is_smooth, |
| 258 ScrollType) { | 277 ScrollType) { |
| 259 // TODO(bokan): This should really be implemented here but ScrollAlignment is | 278 // TODO(bokan): This should really be implemented here but ScrollAlignment is |
| 260 // in Core which is a dependency violation. | 279 // in Core which is a dependency violation. |
| 261 NOTREACHED(); | 280 NOTREACHED(); |
| 262 return LayoutRect(); | 281 return LayoutRect(); |
| 263 } | 282 } |
| 264 | 283 |
| 265 void ScrollableArea::ScrollOffsetChanged(const ScrollOffset& offset, | 284 void ScrollableArea::ScrollOffsetChanged(const ScrollOffset& offset, |
| 266 ScrollType scroll_type) { | 285 ScrollType scroll_type) { |
| 267 TRACE_EVENT0("blink", "ScrollableArea::scrollOffsetChanged"); | 286 TRACE_EVENT0("blink", "ScrollableArea::scrollOffsetChanged"); |
| (...skipping 403 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 671 offset.y() - ScrollOrigin().Y()); | 690 offset.y() - ScrollOrigin().Y()); |
| 672 SetScrollOffset(new_offset, kCompositorScroll); | 691 SetScrollOffset(new_offset, kCompositorScroll); |
| 673 } | 692 } |
| 674 | 693 |
| 675 DEFINE_TRACE(ScrollableArea) { | 694 DEFINE_TRACE(ScrollableArea) { |
| 676 visitor->Trace(scroll_animator_); | 695 visitor->Trace(scroll_animator_); |
| 677 visitor->Trace(programmatic_scroll_animator_); | 696 visitor->Trace(programmatic_scroll_animator_); |
| 678 } | 697 } |
| 679 | 698 |
| 680 } // namespace blink | 699 } // namespace blink |
| OLD | NEW |