edge_effect.h revision eb525c5499e34cc9c4b825d6d9e75bb07cc06ace
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 3// found in the LICENSE file. 4 5#ifndef CONTENT_BROWSER_ANDROID_EDGE_EFFECT_H_ 6#define CONTENT_BROWSER_ANDROID_EDGE_EFFECT_H_ 7 8#include "base/basictypes.h" 9#include "base/memory/ref_counted.h" 10#include "base/time/time.h" 11#include "ui/gfx/size_f.h" 12 13namespace cc { 14class Layer; 15} 16 17namespace content { 18 19/* |EdgeEffect| mirrors its Android counterpart, EdgeEffect.java. 20 * The primary difference is ownership; the Android version manages render 21 * resources directly, while this version simply applies the effect to 22 * existing resources. Conscious tradeoffs were made to align this as closely 23 * as possible with the original Android java version. 24 */ 25class EdgeEffect { 26public: 27 enum Edge { 28 EDGE_TOP = 0, 29 EDGE_LEFT, 30 EDGE_BOTTOM, 31 EDGE_RIGHT, 32 EDGE_COUNT 33 }; 34 35 EdgeEffect(scoped_refptr<cc::Layer> edge, scoped_refptr<cc::Layer> glow); 36 ~EdgeEffect(); 37 38 void Pull(base::TimeTicks current_time, float delta_distance); 39 void Absorb(base::TimeTicks current_time, float velocity); 40 bool Update(base::TimeTicks current_time); 41 void Release(base::TimeTicks current_time); 42 43 void Finish(); 44 bool IsFinished() const; 45 46 void ApplyToLayers(gfx::SizeF size, Edge edge); 47 48private: 49 50 enum State { 51 STATE_IDLE = 0, 52 STATE_PULL, 53 STATE_ABSORB, 54 STATE_RECEDE, 55 STATE_PULL_DECAY 56 }; 57 58 scoped_refptr<cc::Layer> edge_; 59 scoped_refptr<cc::Layer> glow_; 60 61 float edge_alpha_; 62 float edge_scale_y_; 63 float glow_alpha_; 64 float glow_scale_y_; 65 66 float edge_alpha_start_; 67 float edge_alpha_finish_; 68 float edge_scale_y_start_; 69 float edge_scale_y_finish_; 70 float glow_alpha_start_; 71 float glow_alpha_finish_; 72 float glow_scale_y_start_; 73 float glow_scale_y_finish_; 74 75 base::TimeTicks start_time_; 76 base::TimeDelta duration_; 77 78 State state_; 79 80 float pull_distance_; 81 82 float dpi_scale_; 83 84 DISALLOW_COPY_AND_ASSIGN(EdgeEffect); 85}; 86 87} // namespace content 88 89#endif // CONTENT_BROWSER_ANDROID_EDGE_EFFECT_H_ 90