Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(479)

Side by Side Diff: content/browser/web_contents/aura/gesture_nav_simple.cc

Issue 2986483002: Adding metrics logging for Simplified Gesture Navigation. (Closed)
Patch Set: Rebase Created 3 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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/memory/ptr_util.h" 10 #include "base/memory/ptr_util.h"
11 #include "base/metrics/histogram_macros.h"
12 #include "base/metrics/user_metrics.h"
11 #include "cc/paint/paint_flags.h" 13 #include "cc/paint/paint_flags.h"
12 #include "components/vector_icons/vector_icons.h" 14 #include "components/vector_icons/vector_icons.h"
13 #include "content/browser/frame_host/navigation_controller_impl.h" 15 #include "content/browser/frame_host/navigation_controller_impl.h"
14 #include "content/browser/renderer_host/overscroll_controller.h" 16 #include "content/browser/renderer_host/overscroll_controller.h"
17 #include "content/browser/web_contents/aura/types.h"
15 #include "content/browser/web_contents/web_contents_impl.h" 18 #include "content/browser/web_contents/web_contents_impl.h"
16 #include "content/public/browser/overscroll_configuration.h" 19 #include "content/public/browser/overscroll_configuration.h"
17 #include "third_party/skia/include/core/SkDrawLooper.h" 20 #include "third_party/skia/include/core/SkDrawLooper.h"
18 #include "ui/aura/window.h" 21 #include "ui/aura/window.h"
19 #include "ui/compositor/layer.h" 22 #include "ui/compositor/layer.h"
20 #include "ui/compositor/layer_delegate.h" 23 #include "ui/compositor/layer_delegate.h"
21 #include "ui/compositor/paint_recorder.h" 24 #include "ui/compositor/paint_recorder.h"
22 #include "ui/display/display.h" 25 #include "ui/display/display.h"
23 #include "ui/display/screen.h" 26 #include "ui/display/screen.h"
24 #include "ui/gfx/animation/animation_delegate.h" 27 #include "ui/gfx/animation/animation_delegate.h"
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
84 return mode == (base::i18n::IsRTL() ? OVERSCROLL_EAST : OVERSCROLL_WEST) && 87 return mode == (base::i18n::IsRTL() ? OVERSCROLL_EAST : OVERSCROLL_WEST) &&
85 controller.CanGoForward(); 88 controller.CanGoForward();
86 } 89 }
87 90
88 bool ShouldNavigateBack(const NavigationController& controller, 91 bool ShouldNavigateBack(const NavigationController& controller,
89 OverscrollMode mode) { 92 OverscrollMode mode) {
90 return mode == (base::i18n::IsRTL() ? OVERSCROLL_WEST : OVERSCROLL_EAST) && 93 return mode == (base::i18n::IsRTL() ? OVERSCROLL_WEST : OVERSCROLL_EAST) &&
91 controller.CanGoBack(); 94 controller.CanGoBack();
92 } 95 }
93 96
97 NavigationDirection GetDirectionFromMode(OverscrollMode mode) {
98 if (mode == (base::i18n::IsRTL() ? OVERSCROLL_WEST : OVERSCROLL_EAST))
99 return NavigationDirection::BACK;
100 if (mode == (base::i18n::IsRTL() ? OVERSCROLL_EAST : OVERSCROLL_WEST))
101 return NavigationDirection::FORWARD;
102 return NavigationDirection::NONE;
103 }
104
105 // Records UMA historgram and also user action for the cancelled overscroll.
106 void RecordCancelled(NavigationDirection direction, OverscrollSource source) {
107 DCHECK_NE(direction, NavigationDirection::NONE);
108 DCHECK_NE(source, OverscrollSource::NONE);
109 UMA_HISTOGRAM_ENUMERATION("Overscroll.Cancelled3",
110 GetUmaNavigationType(direction, source),
111 NAVIGATION_TYPE_COUNT);
112 if (direction == NavigationDirection::BACK)
113 RecordAction(base::UserMetricsAction("Overscroll_Cancelled.Back"));
114 else
115 RecordAction(base::UserMetricsAction("Overscroll_Cancelled.Forward"));
116 }
117
94 } // namespace 118 } // namespace
95 119
96 // This class is responsible for creating, painting, and positioning the layer 120 // This class is responsible for creating, painting, and positioning the layer
97 // for the gesture nav affordance. 121 // for the gesture nav affordance.
98 class Affordance : public ui::LayerDelegate, public gfx::AnimationDelegate { 122 class Affordance : public ui::LayerDelegate, public gfx::AnimationDelegate {
99 public: 123 public:
100 Affordance(GestureNavSimple* owner, 124 Affordance(GestureNavSimple* owner,
101 OverscrollMode mode, 125 OverscrollMode mode,
102 const gfx::Rect& content_bounds, 126 const gfx::Rect& content_bounds,
103 float max_drag_progress); 127 float max_drag_progress);
(...skipping 322 matching lines...) Expand 10 before | Expand all | Expand 10 after
426 return true; 450 return true;
427 } 451 }
428 452
429 void GestureNavSimple::OnOverscrollComplete(OverscrollMode overscroll_mode) { 453 void GestureNavSimple::OnOverscrollComplete(OverscrollMode overscroll_mode) {
430 if (!affordance_ || affordance_->IsFinishing()) 454 if (!affordance_ || affordance_->IsFinishing())
431 return; 455 return;
432 456
433 CompleteGestureAnimation(); 457 CompleteGestureAnimation();
434 458
435 NavigationControllerImpl& controller = web_contents_->GetController(); 459 NavigationControllerImpl& controller = web_contents_->GetController();
436 if (ShouldNavigateForward(controller, overscroll_mode)) 460 NavigationDirection direction = NavigationDirection::NONE;
461 if (ShouldNavigateForward(controller, overscroll_mode)) {
437 controller.GoForward(); 462 controller.GoForward();
438 else if (ShouldNavigateBack(controller, overscroll_mode)) 463 direction = NavigationDirection::FORWARD;
464 } else if (ShouldNavigateBack(controller, overscroll_mode)) {
439 controller.GoBack(); 465 controller.GoBack();
466 direction = NavigationDirection::BACK;
467 }
468
469 if (direction != NavigationDirection::NONE) {
470 UMA_HISTOGRAM_ENUMERATION("Overscroll.Navigated3",
471 GetUmaNavigationType(direction, source_),
472 UmaNavigationType::NAVIGATION_TYPE_COUNT);
473 if (direction == NavigationDirection::BACK)
474 RecordAction(base::UserMetricsAction("Overscroll_Navigated.Back"));
475 else
476 RecordAction(base::UserMetricsAction("Overscroll_Navigated.Forward"));
477 } else {
478 RecordCancelled(GetDirectionFromMode(overscroll_mode), source_);
479 }
480
481 source_ = OverscrollSource::NONE;
440 } 482 }
441 483
442 void GestureNavSimple::OnOverscrollModeChange(OverscrollMode old_mode, 484 void GestureNavSimple::OnOverscrollModeChange(OverscrollMode old_mode,
443 OverscrollMode new_mode, 485 OverscrollMode new_mode,
444 OverscrollSource source) { 486 OverscrollSource source) {
445 NavigationControllerImpl& controller = web_contents_->GetController(); 487 NavigationControllerImpl& controller = web_contents_->GetController();
446 if (!ShouldNavigateForward(controller, new_mode) && 488 if (!ShouldNavigateForward(controller, new_mode) &&
447 !ShouldNavigateBack(controller, new_mode)) { 489 !ShouldNavigateBack(controller, new_mode)) {
448 AbortGestureAnimation(); 490 // If there is an overscroll in progress - record its cancellation.
491 if (affordance_) {
492 RecordCancelled(GetDirectionFromMode(old_mode), source_);
493 AbortGestureAnimation();
494 }
495 source_ = OverscrollSource::NONE;
449 return; 496 return;
450 } 497 }
451 498
452 DCHECK_NE(source, OverscrollSource::NONE); 499 DCHECK_NE(source, OverscrollSource::NONE);
500 source_ = source;
501
502 UMA_HISTOGRAM_ENUMERATION(
503 "Overscroll.Started3",
504 GetUmaNavigationType(GetDirectionFromMode(new_mode), source_),
505 UmaNavigationType::NAVIGATION_TYPE_COUNT);
506
453 const float start_threshold = GetOverscrollConfig( 507 const float start_threshold = GetOverscrollConfig(
454 source == OverscrollSource::TOUCHPAD 508 source == OverscrollSource::TOUCHPAD
455 ? OVERSCROLL_CONFIG_HORIZ_THRESHOLD_START_TOUCHPAD 509 ? OVERSCROLL_CONFIG_HORIZ_THRESHOLD_START_TOUCHPAD
456 : OVERSCROLL_CONFIG_HORIZ_THRESHOLD_START_TOUCHSCREEN); 510 : OVERSCROLL_CONFIG_HORIZ_THRESHOLD_START_TOUCHSCREEN);
457 const int width = GetDisplaySize().width(); 511 const int width = GetDisplaySize().width();
458 completion_threshold_ = 512 completion_threshold_ =
459 width * GetOverscrollConfig(OVERSCROLL_CONFIG_HORIZ_THRESHOLD_COMPLETE) - 513 width * GetOverscrollConfig(OVERSCROLL_CONFIG_HORIZ_THRESHOLD_COMPLETE) -
460 start_threshold; 514 start_threshold;
461 DCHECK_LE(0, completion_threshold_); 515 DCHECK_LE(0, completion_threshold_);
462 516
(...skipping 15 matching lines...) Expand all
478 parent->StackAtTop(affordance_->root_layer()); 532 parent->StackAtTop(affordance_->root_layer());
479 } 533 }
480 534
481 base::Optional<float> GestureNavSimple::GetMaxOverscrollDelta() const { 535 base::Optional<float> GestureNavSimple::GetMaxOverscrollDelta() const {
482 if (affordance_) 536 if (affordance_)
483 return max_delta_; 537 return max_delta_;
484 return base::nullopt; 538 return base::nullopt;
485 } 539 }
486 540
487 } // namespace content 541 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698