| OLD | NEW | 
|    1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. |    1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 
|    2 // Use of this source code is governed by a BSD-style license that can be |    2 // Use of this source code is governed by a BSD-style license that can be | 
|    3 // found in the LICENSE file. |    3 // found in the LICENSE file. | 
|    4  |    4  | 
|    5 #include "content/browser/android/overscroll_glow.h" |    5 #include "content/browser/android/overscroll_glow.h" | 
|    6  |    6  | 
|    7 #include "cc/layers/layer.h" |    7 #include "cc/layers/layer.h" | 
|    8 #include "content/browser/android/edge_effect_base.h" |    8 #include "content/browser/android/edge_effect_base.h" | 
|    9 #include "content/public/browser/android/compositor.h" |    9 #include "content/public/browser/android/compositor.h" | 
|   10  |   10  | 
| (...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
|   70       return gfx::SizeF(window_size.height(), window_size.width()); |   70       return gfx::SizeF(window_size.height(), window_size.width()); | 
|   71     default: |   71     default: | 
|   72       NOTREACHED() << "Invalid edge: " << edge; |   72       NOTREACHED() << "Invalid edge: " << edge; | 
|   73       return gfx::SizeF(); |   73       return gfx::SizeF(); | 
|   74   }; |   74   }; | 
|   75 } |   75 } | 
|   76  |   76  | 
|   77 }  // namespace |   77 }  // namespace | 
|   78  |   78  | 
|   79 OverscrollGlow::OverscrollGlow(OverscrollGlowClient* client) |   79 OverscrollGlow::OverscrollGlow(OverscrollGlowClient* client) | 
|   80     : client_(client), edge_offsets_(), initialized_(false) { |   80     : client_(client), | 
 |   81       edge_offsets_(), | 
 |   82       initialized_(false), | 
 |   83       allow_horizontal_overscroll_(true), | 
 |   84       allow_vertical_overscroll_(true) { | 
|   81   DCHECK(client); |   85   DCHECK(client); | 
|   82 } |   86 } | 
|   83  |   87  | 
|   84 OverscrollGlow::~OverscrollGlow() { |   88 OverscrollGlow::~OverscrollGlow() { | 
|   85   Detach(); |   89   Detach(); | 
|   86 } |   90 } | 
|   87  |   91  | 
|   88 void OverscrollGlow::Reset() { |   92 void OverscrollGlow::Reset() { | 
|   89   if (!initialized_) |   93   if (!initialized_) | 
|   90     return; |   94     return; | 
| (...skipping 18 matching lines...) Expand all  Loading... | 
|  109     if (!edge_effects_[i]->IsFinished()) |  113     if (!edge_effects_[i]->IsFinished()) | 
|  110       max_alpha = std::max(max_alpha, edge_effects_[i]->GetAlpha()); |  114       max_alpha = std::max(max_alpha, edge_effects_[i]->GetAlpha()); | 
|  111   } |  115   } | 
|  112   return std::min(max_alpha, 1.f); |  116   return std::min(max_alpha, 1.f); | 
|  113 } |  117 } | 
|  114  |  118  | 
|  115 bool OverscrollGlow::OnOverscrolled(base::TimeTicks current_time, |  119 bool OverscrollGlow::OnOverscrolled(base::TimeTicks current_time, | 
|  116           const gfx::Vector2dF& accumulated_overscroll, |  120           const gfx::Vector2dF& accumulated_overscroll, | 
|  117           gfx::Vector2dF overscroll_delta, |  121           gfx::Vector2dF overscroll_delta, | 
|  118           gfx::Vector2dF velocity, |  122           gfx::Vector2dF velocity, | 
|  119           const gfx::Vector2dF& displacement) { |  123           const gfx::Vector2dF& overscroll_location) { | 
|  120   // The size of the glow determines the relative effect of the inputs; an |  124   // The size of the glow determines the relative effect of the inputs; an | 
|  121   // empty-sized effect is effectively disabled. |  125   // empty-sized effect is effectively disabled. | 
|  122   if (viewport_size_.IsEmpty()) |  126   if (viewport_size_.IsEmpty()) | 
|  123     return false; |  127     return false; | 
|  124  |  128  | 
 |  129   if (!allow_horizontal_overscroll_) { | 
 |  130     overscroll_delta.set_x(0); | 
 |  131     velocity.set_x(0); | 
 |  132   } | 
 |  133   if (!allow_vertical_overscroll_) { | 
 |  134     overscroll_delta.set_y(0); | 
 |  135     velocity.set_y(0); | 
 |  136   } | 
 |  137  | 
|  125   // Ignore sufficiently small values that won't meaningfuly affect animation. |  138   // Ignore sufficiently small values that won't meaningfuly affect animation. | 
|  126   overscroll_delta = ZeroSmallComponents(overscroll_delta); |  139   overscroll_delta = ZeroSmallComponents(overscroll_delta); | 
|  127   if (overscroll_delta.IsZero()) { |  140   if (overscroll_delta.IsZero()) { | 
|  128     if (initialized_) |  141     if (initialized_) | 
|  129       Release(current_time); |  142       Release(current_time); | 
|  130     return CheckNeedsAnimate(); |  143     return CheckNeedsAnimate(); | 
|  131   } |  144   } | 
|  132  |  145  | 
|  133   if (!InitializeIfNecessary()) |  146   if (!InitializeIfNecessary()) | 
|  134     return false; |  147     return false; | 
|  135  |  148  | 
|  136   gfx::Vector2dF old_overscroll = accumulated_overscroll - overscroll_delta; |  149   gfx::Vector2dF old_overscroll = accumulated_overscroll - overscroll_delta; | 
|  137   bool x_overscroll_started = |  150   bool x_overscroll_started = | 
|  138       !IsApproxZero(overscroll_delta.x()) && IsApproxZero(old_overscroll.x()); |  151       !IsApproxZero(overscroll_delta.x()) && IsApproxZero(old_overscroll.x()); | 
|  139   bool y_overscroll_started = |  152   bool y_overscroll_started = | 
|  140       !IsApproxZero(overscroll_delta.y()) && IsApproxZero(old_overscroll.y()); |  153       !IsApproxZero(overscroll_delta.y()) && IsApproxZero(old_overscroll.y()); | 
|  141  |  154  | 
|  142   velocity = ZeroSmallComponents(velocity); |  155   velocity = ZeroSmallComponents(velocity); | 
|  143   if (!velocity.IsZero()) |  156   if (!velocity.IsZero()) | 
|  144     Absorb(current_time, velocity, x_overscroll_started, y_overscroll_started); |  157     Absorb(current_time, velocity, x_overscroll_started, y_overscroll_started); | 
|  145   else |  158   else | 
|  146     Pull(current_time, overscroll_delta, displacement); |  159     Pull(current_time, overscroll_delta, overscroll_location); | 
|  147  |  160  | 
|  148   return CheckNeedsAnimate(); |  161   return CheckNeedsAnimate(); | 
|  149 } |  162 } | 
|  150  |  163  | 
|  151 bool OverscrollGlow::Animate(base::TimeTicks current_time, |  164 bool OverscrollGlow::Animate(base::TimeTicks current_time, | 
|  152                              cc::Layer* parent_layer) { |  165                              cc::Layer* parent_layer) { | 
|  153   DCHECK(parent_layer); |  166   DCHECK(parent_layer); | 
|  154   if (!CheckNeedsAnimate()) |  167   if (!CheckNeedsAnimate()) | 
|  155     return false; |  168     return false; | 
|  156  |  169  | 
| (...skipping 16 matching lines...) Expand all  Loading... | 
|  173     const gfx::SizeF& content_size, |  186     const gfx::SizeF& content_size, | 
|  174     const gfx::Vector2dF& content_scroll_offset) { |  187     const gfx::Vector2dF& content_scroll_offset) { | 
|  175   viewport_size_ = viewport_size; |  188   viewport_size_ = viewport_size; | 
|  176   edge_offsets_[OverscrollGlow::EDGE_TOP] = -content_scroll_offset.y(); |  189   edge_offsets_[OverscrollGlow::EDGE_TOP] = -content_scroll_offset.y(); | 
|  177   edge_offsets_[OverscrollGlow::EDGE_LEFT] = -content_scroll_offset.x(); |  190   edge_offsets_[OverscrollGlow::EDGE_LEFT] = -content_scroll_offset.x(); | 
|  178   edge_offsets_[OverscrollGlow::EDGE_BOTTOM] = content_size.height() - |  191   edge_offsets_[OverscrollGlow::EDGE_BOTTOM] = content_size.height() - | 
|  179                                                content_scroll_offset.y() - |  192                                                content_scroll_offset.y() - | 
|  180                                                viewport_size.height(); |  193                                                viewport_size.height(); | 
|  181   edge_offsets_[OverscrollGlow::EDGE_RIGHT] = |  194   edge_offsets_[OverscrollGlow::EDGE_RIGHT] = | 
|  182       content_size.width() - content_scroll_offset.x() - viewport_size.width(); |  195       content_size.width() - content_scroll_offset.x() - viewport_size.width(); | 
 |  196  | 
 |  197   // Only allow overscroll on scrollable axes, matching platform behavior. | 
 |  198   allow_horizontal_overscroll_ = | 
 |  199       std::ceil(viewport_size_.width()) < std::floor(content_size.width()); | 
 |  200   allow_vertical_overscroll_ = | 
 |  201       std::ceil(viewport_size_.height()) < std::floor(content_size.height()); | 
|  183 } |  202 } | 
|  184  |  203  | 
|  185 bool OverscrollGlow::CheckNeedsAnimate() { |  204 bool OverscrollGlow::CheckNeedsAnimate() { | 
|  186   if (!initialized_) { |  205   if (!initialized_) { | 
|  187     Detach(); |  206     Detach(); | 
|  188     return false; |  207     return false; | 
|  189   } |  208   } | 
|  190  |  209  | 
|  191   if (IsActive()) |  210   if (IsActive()) | 
|  192     return true; |  211     return true; | 
| (...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
|  298   for (size_t i = 0; i < EDGE_COUNT; ++i) |  317   for (size_t i = 0; i < EDGE_COUNT; ++i) | 
|  299     edge_effects_[i]->Release(current_time); |  318     edge_effects_[i]->Release(current_time); | 
|  300 } |  319 } | 
|  301  |  320  | 
|  302 EdgeEffectBase* OverscrollGlow::GetOppositeEdge(int edge_index) { |  321 EdgeEffectBase* OverscrollGlow::GetOppositeEdge(int edge_index) { | 
|  303   DCHECK(initialized_); |  322   DCHECK(initialized_); | 
|  304   return edge_effects_[(edge_index + 2) % EDGE_COUNT].get(); |  323   return edge_effects_[(edge_index + 2) % EDGE_COUNT].get(); | 
|  305 } |  324 } | 
|  306  |  325  | 
|  307 }  // namespace content |  326 }  // namespace content | 
| OLD | NEW |