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

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: Addressing feedback Created 3 years, 5 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/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"
16 #include "content/browser/web_contents/aura/types.h"
14 #include "content/browser/web_contents/web_contents_impl.h" 17 #include "content/browser/web_contents/web_contents_impl.h"
15 #include "content/public/browser/overscroll_configuration.h" 18 #include "content/public/browser/overscroll_configuration.h"
16 #include "third_party/skia/include/core/SkDrawLooper.h" 19 #include "third_party/skia/include/core/SkDrawLooper.h"
17 #include "ui/aura/window.h" 20 #include "ui/aura/window.h"
18 #include "ui/compositor/layer.h" 21 #include "ui/compositor/layer.h"
19 #include "ui/compositor/layer_delegate.h" 22 #include "ui/compositor/layer_delegate.h"
20 #include "ui/compositor/paint_recorder.h" 23 #include "ui/compositor/paint_recorder.h"
21 #include "ui/display/display.h" 24 #include "ui/display/display.h"
22 #include "ui/display/screen.h" 25 #include "ui/display/screen.h"
23 #include "ui/gfx/animation/animation_delegate.h" 26 #include "ui/gfx/animation/animation_delegate.h"
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
73 return mode == (base::i18n::IsRTL() ? OVERSCROLL_EAST : OVERSCROLL_WEST) && 76 return mode == (base::i18n::IsRTL() ? OVERSCROLL_EAST : OVERSCROLL_WEST) &&
74 controller.CanGoForward(); 77 controller.CanGoForward();
75 } 78 }
76 79
77 bool ShouldNavigateBack(const NavigationController& controller, 80 bool ShouldNavigateBack(const NavigationController& controller,
78 OverscrollMode mode) { 81 OverscrollMode mode) {
79 return mode == (base::i18n::IsRTL() ? OVERSCROLL_WEST : OVERSCROLL_EAST) && 82 return mode == (base::i18n::IsRTL() ? OVERSCROLL_WEST : OVERSCROLL_EAST) &&
80 controller.CanGoBack(); 83 controller.CanGoBack();
81 } 84 }
82 85
86 NavigationDirection GetDirectionFromMode(OverscrollMode mode) {
87 if (mode == (base::i18n::IsRTL() ? OVERSCROLL_WEST : OVERSCROLL_EAST))
88 return NavigationDirection::BACK;
89 if (mode == (base::i18n::IsRTL() ? OVERSCROLL_EAST : OVERSCROLL_WEST))
90 return NavigationDirection::FORWARD;
91 return NavigationDirection::NONE;
92 }
93
94 // Records UMA historgram and also user action for the cancelled overscroll.
95 void RecordCancelled(NavigationDirection direction, OverscrollSource source) {
96 DCHECK_NE(direction, NavigationDirection::NONE);
97 DCHECK_NE(source, OverscrollSource::NONE);
98 UMA_HISTOGRAM_ENUMERATION("Overscroll.Cancelled3",
99 GetUmaNavigationType(direction, source),
100 NAVIGATION_TYPE_COUNT);
101 if (direction == NavigationDirection::BACK)
102 RecordAction(base::UserMetricsAction("Overscroll_Cancelled.Back"));
103 else
104 RecordAction(base::UserMetricsAction("Overscroll_Cancelled.Forward"));
105 }
106
83 } // namespace 107 } // namespace
84 108
85 // This class is responsible for creating, painting, and positioning the layer 109 // This class is responsible for creating, painting, and positioning the layer
86 // for the gesture nav affordance. 110 // for the gesture nav affordance.
87 class Affordance : public ui::LayerDelegate, public gfx::AnimationDelegate { 111 class Affordance : public ui::LayerDelegate, public gfx::AnimationDelegate {
88 public: 112 public:
89 Affordance(GestureNavSimple* owner, 113 Affordance(GestureNavSimple* owner,
90 OverscrollMode mode, 114 OverscrollMode mode,
91 const gfx::Rect& content_bounds); 115 const gfx::Rect& content_bounds);
92 ~Affordance() override; 116 ~Affordance() override;
(...skipping 291 matching lines...) Expand 10 before | Expand all | Expand 10 after
384 return true; 408 return true;
385 } 409 }
386 410
387 void GestureNavSimple::OnOverscrollComplete(OverscrollMode overscroll_mode) { 411 void GestureNavSimple::OnOverscrollComplete(OverscrollMode overscroll_mode) {
388 if (!affordance_ || affordance_->IsFinishing()) 412 if (!affordance_ || affordance_->IsFinishing())
389 return; 413 return;
390 414
391 CompleteGestureAnimation(); 415 CompleteGestureAnimation();
392 416
393 NavigationControllerImpl& controller = web_contents_->GetController(); 417 NavigationControllerImpl& controller = web_contents_->GetController();
394 if (ShouldNavigateForward(controller, overscroll_mode)) 418 NavigationDirection direction = NavigationDirection::NONE;
419 if (ShouldNavigateForward(controller, overscroll_mode)) {
395 controller.GoForward(); 420 controller.GoForward();
396 else if (ShouldNavigateBack(controller, overscroll_mode)) 421 direction = NavigationDirection::FORWARD;
422 } else if (ShouldNavigateBack(controller, overscroll_mode)) {
397 controller.GoBack(); 423 controller.GoBack();
424 direction = NavigationDirection::BACK;
425 }
426
427 if (direction != NavigationDirection::NONE) {
428 UMA_HISTOGRAM_ENUMERATION("Overscroll.Navigated3",
429 GetUmaNavigationType(direction, source_),
430 UmaNavigationType::NAVIGATION_TYPE_COUNT);
431 if (direction == NavigationDirection::BACK)
432 RecordAction(base::UserMetricsAction("Overscroll_Navigated.Back"));
433 else
434 RecordAction(base::UserMetricsAction("Overscroll_Navigated.Forward"));
435 } else {
436 RecordCancelled(GetDirectionFromMode(overscroll_mode), source_);
437 }
438
439 source_ = OverscrollSource::NONE;
398 } 440 }
399 441
400 void GestureNavSimple::OnOverscrollModeChange(OverscrollMode old_mode, 442 void GestureNavSimple::OnOverscrollModeChange(OverscrollMode old_mode,
401 OverscrollMode new_mode, 443 OverscrollMode new_mode,
402 OverscrollSource source) { 444 OverscrollSource source) {
403 NavigationControllerImpl& controller = web_contents_->GetController(); 445 NavigationControllerImpl& controller = web_contents_->GetController();
404 if (!ShouldNavigateForward(controller, new_mode) && 446 if (!ShouldNavigateForward(controller, new_mode) &&
405 !ShouldNavigateBack(controller, new_mode)) { 447 !ShouldNavigateBack(controller, new_mode)) {
406 AbortGestureAnimation(); 448 // If there is an overscroll in progress - record its cancellation.
449 if (affordance_) {
450 RecordCancelled(GetDirectionFromMode(old_mode), source_);
451 AbortGestureAnimation();
452 }
453 source_ = OverscrollSource::NONE;
407 return; 454 return;
408 } 455 }
409 456
410 DCHECK_NE(source, OverscrollSource::NONE); 457 DCHECK_NE(source, OverscrollSource::NONE);
458 source_ = source;
459
460 UMA_HISTOGRAM_ENUMERATION(
461 "Overscroll.Started3",
462 GetUmaNavigationType(GetDirectionFromMode(new_mode), source_),
463 UmaNavigationType::NAVIGATION_TYPE_COUNT);
464
411 const float start_threshold = GetOverscrollConfig( 465 const float start_threshold = GetOverscrollConfig(
412 source == OverscrollSource::TOUCHPAD 466 source == OverscrollSource::TOUCHPAD
413 ? OVERSCROLL_CONFIG_HORIZ_THRESHOLD_START_TOUCHPAD 467 ? OVERSCROLL_CONFIG_HORIZ_THRESHOLD_START_TOUCHPAD
414 : OVERSCROLL_CONFIG_HORIZ_THRESHOLD_START_TOUCHSCREEN); 468 : OVERSCROLL_CONFIG_HORIZ_THRESHOLD_START_TOUCHSCREEN);
415 const int width = source == OverscrollSource::TOUCHPAD 469 const int width = source == OverscrollSource::TOUCHPAD
416 ? GetDisplaySize().width() 470 ? GetDisplaySize().width()
417 : GetVisibleSize().width(); 471 : GetVisibleSize().width();
418 completion_threshold_ = 472 completion_threshold_ =
419 width * GetOverscrollConfig(OVERSCROLL_CONFIG_HORIZ_THRESHOLD_COMPLETE) - 473 width * GetOverscrollConfig(OVERSCROLL_CONFIG_HORIZ_THRESHOLD_COMPLETE) -
420 start_threshold; 474 start_threshold;
(...skipping 12 matching lines...) Expand all
433 parent->StackAtTop(affordance_->root_layer()); 487 parent->StackAtTop(affordance_->root_layer());
434 } 488 }
435 489
436 base::Optional<float> GestureNavSimple::GetMaxOverscrollDelta() const { 490 base::Optional<float> GestureNavSimple::GetMaxOverscrollDelta() const {
437 if (affordance_) 491 if (affordance_)
438 return completion_threshold_; 492 return completion_threshold_;
439 return base::nullopt; 493 return base::nullopt;
440 } 494 }
441 495
442 } // namespace content 496 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698