| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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/web_contents/aura/gesture_nav_simple.h" | 5 #include "content/browser/web_contents/aura/gesture_nav_simple.h" |
| 6 | 6 |
| 7 #include "cc/layers/layer.h" | 7 #include "cc/layers/layer.h" |
| 8 #include "content/browser/frame_host/navigation_controller_impl.h" | 8 #include "content/browser/frame_host/navigation_controller_impl.h" |
| 9 #include "content/browser/renderer_host/overscroll_controller.h" | 9 #include "content/browser/renderer_host/overscroll_controller.h" |
| 10 #include "content/browser/web_contents/web_contents_impl.h" | 10 #include "content/browser/web_contents/web_contents_impl.h" |
| (...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 138 } | 138 } |
| 139 | 139 |
| 140 void GestureNavSimple::CompleteGestureAnimation() { | 140 void GestureNavSimple::CompleteGestureAnimation() { |
| 141 if (!arrow_) | 141 if (!arrow_) |
| 142 return; | 142 return; |
| 143 // Make sure the fade-out starts from the complete state. | 143 // Make sure the fade-out starts from the complete state. |
| 144 ApplyEffectsForDelta(completion_threshold_); | 144 ApplyEffectsForDelta(completion_threshold_); |
| 145 ApplyEffectsAndDestroy(arrow_->transform(), 0.f); | 145 ApplyEffectsAndDestroy(arrow_->transform(), 0.f); |
| 146 } | 146 } |
| 147 | 147 |
| 148 void GestureNavSimple::ApplyEffectsForDelta(float delta_x) { | 148 bool GestureNavSimple::ApplyEffectsForDelta(float delta_x) { |
| 149 if (!arrow_) | 149 if (!arrow_) |
| 150 return; | 150 return false; |
| 151 CHECK_GT(completion_threshold_, 0.f); | 151 CHECK_GT(completion_threshold_, 0.f); |
| 152 CHECK_GE(delta_x, 0.f); | 152 CHECK_GE(delta_x, 0.f); |
| 153 double complete = std::min(1.f, delta_x / completion_threshold_); | 153 double complete = std::min(1.f, delta_x / completion_threshold_); |
| 154 float translate_x = gfx::Tween::FloatValueBetween(complete, -kArrowWidth, 0); | 154 float translate_x = gfx::Tween::FloatValueBetween(complete, -kArrowWidth, 0); |
| 155 gfx::Transform transform; | 155 gfx::Transform transform; |
| 156 transform.Translate(arrow_delegate_->left() ? translate_x : -translate_x, | 156 transform.Translate(arrow_delegate_->left() ? translate_x : -translate_x, |
| 157 0.f); | 157 0.f); |
| 158 arrow_->SetTransform(transform); | 158 arrow_->SetTransform(transform); |
| 159 arrow_->SetOpacity(gfx::Tween::FloatValueBetween(complete, kMinOpacity, 1.f)); | 159 arrow_->SetOpacity(gfx::Tween::FloatValueBetween(complete, kMinOpacity, 1.f)); |
| 160 return true; |
| 160 } | 161 } |
| 161 | 162 |
| 162 gfx::Rect GestureNavSimple::GetVisibleBounds() const { | 163 gfx::Rect GestureNavSimple::GetVisibleBounds() const { |
| 163 return web_contents_->GetNativeView()->bounds(); | 164 return web_contents_->GetNativeView()->bounds(); |
| 164 } | 165 } |
| 165 | 166 |
| 166 void GestureNavSimple::OnOverscrollUpdate(float delta_x, float delta_y) { | 167 bool GestureNavSimple::OnOverscrollUpdate(float delta_x, float delta_y) { |
| 167 ApplyEffectsForDelta(std::abs(delta_x) + 50.f); | 168 return ApplyEffectsForDelta(std::abs(delta_x) + 50.f); |
| 168 } | 169 } |
| 169 | 170 |
| 170 void GestureNavSimple::OnOverscrollComplete(OverscrollMode overscroll_mode) { | 171 void GestureNavSimple::OnOverscrollComplete(OverscrollMode overscroll_mode) { |
| 171 CompleteGestureAnimation(); | 172 CompleteGestureAnimation(); |
| 172 | 173 |
| 173 NavigationControllerImpl& controller = web_contents_->GetController(); | 174 NavigationControllerImpl& controller = web_contents_->GetController(); |
| 174 if (ShouldNavigateForward(controller, overscroll_mode)) | 175 if (ShouldNavigateForward(controller, overscroll_mode)) |
| 175 controller.GoForward(); | 176 controller.GoForward(); |
| 176 else if (ShouldNavigateBack(controller, overscroll_mode)) | 177 else if (ShouldNavigateBack(controller, overscroll_mode)) |
| 177 controller.GoBack(); | 178 controller.GoBack(); |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 223 clip_layer_->SetBounds(window->layer()->bounds()); | 224 clip_layer_->SetBounds(window->layer()->bounds()); |
| 224 clip_layer_->SetMasksToBounds(true); | 225 clip_layer_->SetMasksToBounds(true); |
| 225 clip_layer_->Add(arrow_.get()); | 226 clip_layer_->Add(arrow_.get()); |
| 226 | 227 |
| 227 ui::Layer* parent = window->layer()->parent(); | 228 ui::Layer* parent = window->layer()->parent(); |
| 228 parent->Add(clip_layer_.get()); | 229 parent->Add(clip_layer_.get()); |
| 229 parent->StackAtTop(clip_layer_.get()); | 230 parent->StackAtTop(clip_layer_.get()); |
| 230 } | 231 } |
| 231 | 232 |
| 232 } // namespace content | 233 } // namespace content |
| OLD | NEW |