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 <utility> | 7 #include <utility> |
8 | 8 |
9 #include "base/macros.h" | 9 #include "base/macros.h" |
| 10 #include "base/metrics/histogram_macros.h" |
| 11 #include "base/metrics/user_metrics.h" |
10 #include "cc/paint/paint_flags.h" | 12 #include "cc/paint/paint_flags.h" |
11 #include "components/vector_icons/vector_icons.h" | 13 #include "components/vector_icons/vector_icons.h" |
12 #include "content/browser/frame_host/navigation_controller_impl.h" | 14 #include "content/browser/frame_host/navigation_controller_impl.h" |
13 #include "content/browser/renderer_host/overscroll_controller.h" | 15 #include "content/browser/renderer_host/overscroll_controller.h" |
14 #include "content/browser/web_contents/web_contents_impl.h" | 16 #include "content/browser/web_contents/web_contents_impl.h" |
15 #include "content/public/browser/overscroll_configuration.h" | 17 #include "content/public/browser/overscroll_configuration.h" |
16 #include "third_party/skia/include/core/SkDrawLooper.h" | 18 #include "third_party/skia/include/core/SkDrawLooper.h" |
17 #include "ui/aura/window.h" | 19 #include "ui/aura/window.h" |
18 #include "ui/compositor/layer.h" | 20 #include "ui/compositor/layer.h" |
19 #include "ui/compositor/layer_delegate.h" | 21 #include "ui/compositor/layer_delegate.h" |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
73 return mode == (base::i18n::IsRTL() ? OVERSCROLL_EAST : OVERSCROLL_WEST) && | 75 return mode == (base::i18n::IsRTL() ? OVERSCROLL_EAST : OVERSCROLL_WEST) && |
74 controller.CanGoForward(); | 76 controller.CanGoForward(); |
75 } | 77 } |
76 | 78 |
77 bool ShouldNavigateBack(const NavigationController& controller, | 79 bool ShouldNavigateBack(const NavigationController& controller, |
78 OverscrollMode mode) { | 80 OverscrollMode mode) { |
79 return mode == (base::i18n::IsRTL() ? OVERSCROLL_WEST : OVERSCROLL_EAST) && | 81 return mode == (base::i18n::IsRTL() ? OVERSCROLL_WEST : OVERSCROLL_EAST) && |
80 controller.CanGoBack(); | 82 controller.CanGoBack(); |
81 } | 83 } |
82 | 84 |
| 85 // Records UMA historgram and also user action for the cancelled overscroll. |
| 86 void RecordCancelled(NavigationDirection direction, OverscrollSource source) { |
| 87 UMA_HISTOGRAM_ENUMERATION("Overscroll.Cancelled3", |
| 88 GetUmaNavigationType(direction, source), |
| 89 NAVIGATION_TYPE_COUNT); |
| 90 if (direction == NavigationDirection::BACK) |
| 91 RecordAction(base::UserMetricsAction("Overscroll_Cancelled.Back")); |
| 92 else |
| 93 RecordAction(base::UserMetricsAction("Overscroll_Cancelled.Forward")); |
| 94 } |
| 95 |
83 } // namespace | 96 } // namespace |
84 | 97 |
85 // This class is responsible for creating, painting, and positioning the layer | 98 // This class is responsible for creating, painting, and positioning the layer |
86 // for the gesture nav affordance. | 99 // for the gesture nav affordance. |
87 class Affordance : public ui::LayerDelegate, public gfx::AnimationDelegate { | 100 class Affordance : public ui::LayerDelegate, public gfx::AnimationDelegate { |
88 public: | 101 public: |
89 Affordance(GestureNavSimple* owner, | 102 Affordance(GestureNavSimple* owner, |
90 OverscrollMode mode, | 103 OverscrollMode mode, |
91 const gfx::Rect& content_bounds); | 104 const gfx::Rect& content_bounds); |
92 ~Affordance() override; | 105 ~Affordance() override; |
(...skipping 291 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
384 return true; | 397 return true; |
385 } | 398 } |
386 | 399 |
387 void GestureNavSimple::OnOverscrollComplete(OverscrollMode overscroll_mode) { | 400 void GestureNavSimple::OnOverscrollComplete(OverscrollMode overscroll_mode) { |
388 if (!affordance_ || affordance_->IsFinishing()) | 401 if (!affordance_ || affordance_->IsFinishing()) |
389 return; | 402 return; |
390 | 403 |
391 CompleteGestureAnimation(); | 404 CompleteGestureAnimation(); |
392 | 405 |
393 NavigationControllerImpl& controller = web_contents_->GetController(); | 406 NavigationControllerImpl& controller = web_contents_->GetController(); |
394 if (ShouldNavigateForward(controller, overscroll_mode)) | 407 bool navigated = false; |
| 408 if (ShouldNavigateForward(controller, overscroll_mode)) { |
395 controller.GoForward(); | 409 controller.GoForward(); |
396 else if (ShouldNavigateBack(controller, overscroll_mode)) | 410 navigated = true; |
| 411 } else if (ShouldNavigateBack(controller, overscroll_mode)) { |
397 controller.GoBack(); | 412 controller.GoBack(); |
| 413 navigated = true; |
| 414 } |
| 415 |
| 416 if (navigated) { |
| 417 UMA_HISTOGRAM_ENUMERATION("Overscroll.Navigated3", |
| 418 GetUmaNavigationType(direction_, source_), |
| 419 UmaNavigationType::NAVIGATION_TYPE_COUNT); |
| 420 if (direction_ == NavigationDirection::BACK) |
| 421 RecordAction(base::UserMetricsAction("Overscroll_Navigated.Back")); |
| 422 else |
| 423 RecordAction(base::UserMetricsAction("Overscroll_Navigated.Forward")); |
| 424 } else { |
| 425 RecordCancelled(direction_, source_); |
| 426 } |
| 427 |
| 428 direction_ = NavigationDirection::NONE; |
| 429 source_ = OverscrollSource::NONE; |
398 } | 430 } |
399 | 431 |
400 void GestureNavSimple::OnOverscrollModeChange(OverscrollMode old_mode, | 432 void GestureNavSimple::OnOverscrollModeChange(OverscrollMode old_mode, |
401 OverscrollMode new_mode, | 433 OverscrollMode new_mode, |
402 OverscrollSource source) { | 434 OverscrollSource source) { |
403 NavigationControllerImpl& controller = web_contents_->GetController(); | 435 NavigationControllerImpl& controller = web_contents_->GetController(); |
404 if (!ShouldNavigateForward(controller, new_mode) && | 436 if (ShouldNavigateForward(controller, new_mode)) { |
405 !ShouldNavigateBack(controller, new_mode)) { | 437 direction_ = NavigationDirection::FORWARD; |
| 438 } else if (ShouldNavigateBack(controller, new_mode)) { |
| 439 direction_ = NavigationDirection::BACK; |
| 440 } else { |
| 441 // If there is an overscoll in progress - record its cancellation. |
| 442 if (direction_ != NavigationDirection::NONE) |
| 443 RecordCancelled(direction_, source_); |
| 444 direction_ = NavigationDirection::NONE; |
| 445 source_ = OverscrollSource::NONE; |
406 AbortGestureAnimation(); | 446 AbortGestureAnimation(); |
407 return; | 447 return; |
408 } | 448 } |
409 | 449 |
410 DCHECK_NE(source, OverscrollSource::NONE); | 450 DCHECK_NE(source, OverscrollSource::NONE); |
| 451 source_ = source; |
| 452 |
| 453 UMA_HISTOGRAM_ENUMERATION("Overscroll.Started3", |
| 454 GetUmaNavigationType(direction_, source_), |
| 455 UmaNavigationType::NAVIGATION_TYPE_COUNT); |
| 456 |
411 const float start_threshold = GetOverscrollConfig( | 457 const float start_threshold = GetOverscrollConfig( |
412 source == OverscrollSource::TOUCHPAD | 458 source == OverscrollSource::TOUCHPAD |
413 ? OVERSCROLL_CONFIG_HORIZ_THRESHOLD_START_TOUCHPAD | 459 ? OVERSCROLL_CONFIG_HORIZ_THRESHOLD_START_TOUCHPAD |
414 : OVERSCROLL_CONFIG_HORIZ_THRESHOLD_START_TOUCHSCREEN); | 460 : OVERSCROLL_CONFIG_HORIZ_THRESHOLD_START_TOUCHSCREEN); |
415 const int width = source == OverscrollSource::TOUCHPAD | 461 const int width = source == OverscrollSource::TOUCHPAD |
416 ? GetDisplaySize().width() | 462 ? GetDisplaySize().width() |
417 : GetVisibleSize().width(); | 463 : GetVisibleSize().width(); |
418 completion_threshold_ = | 464 completion_threshold_ = |
419 width * GetOverscrollConfig(OVERSCROLL_CONFIG_HORIZ_THRESHOLD_COMPLETE) - | 465 width * GetOverscrollConfig(OVERSCROLL_CONFIG_HORIZ_THRESHOLD_COMPLETE) - |
420 start_threshold; | 466 start_threshold; |
(...skipping 12 matching lines...) Expand all Loading... |
433 parent->StackAtTop(affordance_->root_layer()); | 479 parent->StackAtTop(affordance_->root_layer()); |
434 } | 480 } |
435 | 481 |
436 base::Optional<float> GestureNavSimple::GetMaxOverscrollDelta() const { | 482 base::Optional<float> GestureNavSimple::GetMaxOverscrollDelta() const { |
437 if (affordance_) | 483 if (affordance_) |
438 return completion_threshold_; | 484 return completion_threshold_; |
439 return base::nullopt; | 485 return base::nullopt; |
440 } | 486 } |
441 | 487 |
442 } // namespace content | 488 } // namespace content |
OLD | NEW |