OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 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 #ifndef CHROME_BROWSER_UI_VIEWS_FRAME_SCROLL_END_EFFECT_CONTROLLER_ASH_H_ | 5 #ifndef CHROME_BROWSER_UI_VIEWS_FRAME_SCROLL_END_EFFECT_CONTROLLER_ASH_H_ |
6 #define CHROME_BROWSER_UI_VIEWS_FRAME_SCROLL_END_EFFECT_CONTROLLER_ASH_H_ | 6 #define CHROME_BROWSER_UI_VIEWS_FRAME_SCROLL_END_EFFECT_CONTROLLER_ASH_H_ |
7 | 7 |
8 #include "base/compiler_specific.h" | 8 #include "base/compiler_specific.h" |
| 9 #include "base/memory/scoped_ptr.h" |
9 #include "chrome/browser/ui/views/frame/scroll_end_effect_controller.h" | 10 #include "chrome/browser/ui/views/frame/scroll_end_effect_controller.h" |
| 11 #include "ui/base/animation/animation_delegate.h" |
| 12 #include "ui/base/animation/slide_animation.h" |
| 13 #include "ui/compositor/layer.h" |
| 14 #include "ui/gfx/rect.h" |
| 15 #include "ui/gfx/transform.h" |
10 | 16 |
11 class ScrollEndEffectControllerAsh : public ScrollEndEffectController { | 17 namespace views { |
| 18 class View; |
| 19 } |
| 20 |
| 21 // Class that implements the scroll end effect by controlling the layout of |
| 22 // layers and the transforms applied to them. This class depends heavily on |
| 23 // ScrollEndEffectControllerDelegate, which is implemented in BrowserView. |
| 24 class ScrollEndEffectControllerAsh : public ScrollEndEffectController, |
| 25 public ui::AnimationDelegate { |
12 public: | 26 public: |
13 ScrollEndEffectControllerAsh(); | 27 explicit ScrollEndEffectControllerAsh( |
| 28 ScrollEndEffectControllerDelegate* delegate); |
14 virtual ~ScrollEndEffectControllerAsh(); | 29 virtual ~ScrollEndEffectControllerAsh(); |
15 | 30 |
16 // ScrollEndEffectController overides: | 31 // ScrollEndEffectController overrides: |
17 virtual void OverscrollUpdate(int delta_y) OVERRIDE; | 32 virtual void OverscrollUpdate(int delta_y) OVERRIDE; |
18 | 33 |
| 34 // ui::AnimationDelegate overrides: |
| 35 virtual void AnimationEnded(const ui::Animation* animation) OVERRIDE; |
| 36 virtual void AnimationProgressed(const ui::Animation* animation) OVERRIDE; |
| 37 |
19 private: | 38 private: |
| 39 // Sets up the layer hierarchy for showing the effect. This involves making |
| 40 // sure everything is on a layer and inserting clipping layers into the |
| 41 // hierarchy. |
| 42 void ActivateEffect(); |
| 43 |
| 44 // Utility methods used to create needed layers. |
| 45 ui::Layer* CreateClippingLayer(std::string name); |
| 46 ui::Layer* CreateViewLayer(views::View* view); |
| 47 |
| 48 // Restores the layer hierarchy and states to what they were before the effect |
| 49 // was actived. |
| 50 void DeactivateEffect(); |
| 51 |
| 52 // Computes the transforms and counter transforms that are needed to produce |
| 53 // the desired effect then applies them. The bounds of the layers may be |
| 54 // adjusted due to a call to SetBoundsForEffect, so need to be stored before |
| 55 // calling. The entire window is scaled and possibly translated to produce the |
| 56 // squishing effect. The non-client area and the content are counter scaled to |
| 57 // preserve their size and translated/clipped to fit in the smaller window. |
| 58 void ApplyDelta(int delta_y); |
| 59 |
| 60 // Adjusts the bounds for the layers of interest, so that the scroll end |
| 61 // effect appears correctly. It is the responsibility of the caller to save |
| 62 // and restore the bounds as needed. |
| 63 void SetBoundsForEffect(); |
| 64 |
| 65 // For layers not at the origin they need to be translated to/from the origin |
| 66 // in the transform for the simple inverse transform to be the correct counter |
| 67 // tranformation. This is a utility method encapsulates this operation. |
| 68 gfx::Transform CounterTransfromAboutPoint(int x, int y); |
| 69 |
| 70 ScrollEndEffectControllerDelegate* delegate_; // non-owned |
| 71 bool is_effect_active_; |
| 72 |
| 73 scoped_ptr<ui::Layer> frame_clipping_layer_; |
| 74 scoped_ptr<ui::Layer> web_clipping_layer_; |
| 75 ui::Layer* non_client_layer_; |
| 76 ui::Layer* web_contents_layer_; // non-owned |
| 77 ui::Layer* devtools_layer_; // non-owned |
| 78 ui::Layer* download_layer_; |
| 79 |
| 80 // Used to reparent |web_contents_layer_| when deactivating the effect. |
| 81 ui::Layer* web_contents_parent_; // non-owned |
| 82 |
| 83 // Used to reparent |devtools_layer_| when deactivating the effect. |
| 84 ui::Layer* devtools_parent_; // non-owned |
| 85 |
| 86 // Saved when the effect is activated, so it can be restored when the |
| 87 // effect is deactivated. |
| 88 gfx::Rect web_contents_bounds_; |
| 89 |
| 90 // Saved when the effect is activated, so it can be restored when the |
| 91 // effect is deactivated. |
| 92 gfx::Rect devtools_bounds_; |
| 93 |
| 94 // Used to turn off being on a layer when deactivating the effect. |
| 95 views::View* non_client_view_; // non-owned |
| 96 |
| 97 // Used to turn off being on a layer when deactivating the effect. |
| 98 views::View* download_view_; // non-owned |
| 99 |
| 100 // Inverse of the transform that is being applied at the top of the hiearchy |
| 101 // for the effect. |
| 102 gfx::Transform counter_transform_; |
| 103 |
| 104 int start_delta_y_; |
| 105 int end_delta_y_; |
| 106 |
| 107 scoped_ptr<ui::SlideAnimation> animation_; |
| 108 |
20 DISALLOW_COPY_AND_ASSIGN(ScrollEndEffectControllerAsh); | 109 DISALLOW_COPY_AND_ASSIGN(ScrollEndEffectControllerAsh); |
21 }; | 110 }; |
22 | 111 |
23 #endif // CHROME_BROWSER_UI_VIEWS_FRAME_SCROLL_END_EFFECT_CONTROLLER_ASH_H_ | 112 #endif // CHROME_BROWSER_UI_VIEWS_FRAME_SCROLL_END_EFFECT_CONTROLLER_ASH_H_ |
OLD | NEW |