[go: nahoru, domu]

[Reland] Add `snap_action_source_` variable in WindowSnapWMEvent

There is no change with the original CL and the reland CL. The fix is in
the parent CL. Please see https://crrev.com/c/4491584 for the fix.

In this CL:
- Move the `snap_action_source_` from WindowState to WindowSnapWMEvent.
The `snap_action_source_` was a member variable in WindowState before,
but WindowSnapWMEvent should be a better place since we can log the
metrics more accurately when the WindowState handles the event and
the window state changes to a snapped window state.
- Add more different snap action sources so that the distribution is
more accurate.
- Note kSnapByWindowLayoutMenu and kLongPressCaptionButtonToSnap are
used to record snap usage from the window layout menu and the caption
snap buttons for ash browser window. Lacros window usage will be
handled separately in a future CL.

Bug: b/278761433
Change-Id: I25818a5ef614d5b4841410449ef07c14290cb0a1
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/4447659
Commit-Queue: Xiaoqian Dai <xdai@chromium.org>
Reviewed-by: Yulun Wu <yulunwu@chromium.org>
Reviewed-by: Mitsuru Oshima <oshima@chromium.org>
Reviewed-by: Scott Violet <sky@chromium.org>
Code-Coverage: Findit <findit-for-me@appspot.gserviceaccount.com>
Cr-Original-Commit-Position: refs/heads/main@{#1135067}
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/4491312
Reviewed-by: Sammie Quon <sammiequon@chromium.org>
Reviewed-by: Sophie Wen <sophiewen@chromium.org>
Cr-Commit-Position: refs/heads/main@{#1137471}
diff --git a/ash/frame/snap_controller_impl.cc b/ash/frame/snap_controller_impl.cc
index 2e4a908b..c53e61d0 100644
--- a/ash/frame/snap_controller_impl.cc
+++ b/ash/frame/snap_controller_impl.cc
@@ -8,6 +8,7 @@
 #include "ash/wm/window_positioning_utils.h"
 #include "ash/wm/window_state.h"
 #include "ash/wm/wm_event.h"
+#include "ash/wm/wm_metrics.h"
 #include "ash/wm/workspace/phantom_window_controller.h"
 #include "ui/aura/window.h"
 #include "ui/events/devices/haptic_touchpad_effects.h"
@@ -59,19 +60,33 @@
 
 void SnapControllerImpl::CommitSnap(aura::Window* window,
                                     chromeos::SnapDirection snap,
-                                    float snap_ratio) {
+                                    float snap_ratio,
+                                    SnapRequestSource snap_request_source) {
   phantom_window_controller_.reset();
-  if (snap == chromeos::SnapDirection::kNone)
+  if (snap == chromeos::SnapDirection::kNone) {
     return;
+  }
 
-  WindowState* window_state = WindowState::Get(window);
-  window_state->set_snap_action_source(
-      WindowSnapActionSource::kUseCaptionButtonToSnap);
+  WindowSnapActionSource snap_action_source =
+      WindowSnapActionSource::kNotSpecified;
+  switch (snap_request_source) {
+    case SnapRequestSource::kSnapButton:
+      snap_action_source =
+          WindowSnapActionSource::kLongPressCaptionButtonToSnap;
+      break;
+    case SnapRequestSource::kWindowLayoutMenu:
+      snap_action_source = WindowSnapActionSource::kSnapByWindowLayoutMenu;
+      break;
+    case SnapRequestSource::kFromLacrosSnapButtonOrWindowLayoutMenu:
+      // TODO: handle the lacros snap request.
+      break;
+  }
+
   const WindowSnapWMEvent snap_event(snap == chromeos::SnapDirection::kPrimary
                                          ? WM_EVENT_SNAP_PRIMARY
                                          : WM_EVENT_SNAP_SECONDARY,
-                                     snap_ratio);
-  window_state->OnWMEvent(&snap_event);
+                                     snap_ratio, snap_action_source);
+  WindowState::Get(window)->OnWMEvent(&snap_event);
 }
 
 }  // namespace ash