Browse Source

refactor: remove IPC from mouse_util (#38183)

Shelley Vohr 1 year ago
parent
commit
35a03a6bc1
4 changed files with 95 additions and 146 deletions
  1. 0 2
      filenames.gni
  2. 95 1
      shell/browser/api/electron_api_web_contents.cc
  3. 0 109
      shell/common/mouse_util.cc
  4. 0 34
      shell/common/mouse_util.h

+ 0 - 2
filenames.gni

@@ -637,8 +637,6 @@ filenames = {
     "shell/common/language_util.h",
     "shell/common/logging.cc",
     "shell/common/logging.h",
-    "shell/common/mouse_util.cc",
-    "shell/common/mouse_util.h",
     "shell/common/node_bindings.cc",
     "shell/common/node_bindings.h",
     "shell/common/node_includes.h",

+ 95 - 1
shell/browser/api/electron_api_web_contents.cc

@@ -118,7 +118,6 @@
 #include "shell/common/gin_helper/dictionary.h"
 #include "shell/common/gin_helper/object_template_builder.h"
 #include "shell/common/language_util.h"
-#include "shell/common/mouse_util.h"
 #include "shell/common/node_includes.h"
 #include "shell/common/options_switches.h"
 #include "shell/common/process_util.h"
@@ -382,6 +381,101 @@ namespace electron::api {
 
 namespace {
 
+std::string CursorTypeToString(const ui::Cursor& cursor) {
+  switch (cursor.type()) {
+    case ui::mojom::CursorType::kPointer:
+      return "default";
+    case ui::mojom::CursorType::kCross:
+      return "crosshair";
+    case ui::mojom::CursorType::kHand:
+      return "pointer";
+    case ui::mojom::CursorType::kIBeam:
+      return "text";
+    case ui::mojom::CursorType::kWait:
+      return "wait";
+    case ui::mojom::CursorType::kHelp:
+      return "help";
+    case ui::mojom::CursorType::kEastResize:
+      return "e-resize";
+    case ui::mojom::CursorType::kNorthResize:
+      return "n-resize";
+    case ui::mojom::CursorType::kNorthEastResize:
+      return "ne-resize";
+    case ui::mojom::CursorType::kNorthWestResize:
+      return "nw-resize";
+    case ui::mojom::CursorType::kSouthResize:
+      return "s-resize";
+    case ui::mojom::CursorType::kSouthEastResize:
+      return "se-resize";
+    case ui::mojom::CursorType::kSouthWestResize:
+      return "sw-resize";
+    case ui::mojom::CursorType::kWestResize:
+      return "w-resize";
+    case ui::mojom::CursorType::kNorthSouthResize:
+      return "ns-resize";
+    case ui::mojom::CursorType::kEastWestResize:
+      return "ew-resize";
+    case ui::mojom::CursorType::kNorthEastSouthWestResize:
+      return "nesw-resize";
+    case ui::mojom::CursorType::kNorthWestSouthEastResize:
+      return "nwse-resize";
+    case ui::mojom::CursorType::kColumnResize:
+      return "col-resize";
+    case ui::mojom::CursorType::kRowResize:
+      return "row-resize";
+    case ui::mojom::CursorType::kMiddlePanning:
+      return "m-panning";
+    case ui::mojom::CursorType::kEastPanning:
+      return "e-panning";
+    case ui::mojom::CursorType::kNorthPanning:
+      return "n-panning";
+    case ui::mojom::CursorType::kNorthEastPanning:
+      return "ne-panning";
+    case ui::mojom::CursorType::kNorthWestPanning:
+      return "nw-panning";
+    case ui::mojom::CursorType::kSouthPanning:
+      return "s-panning";
+    case ui::mojom::CursorType::kSouthEastPanning:
+      return "se-panning";
+    case ui::mojom::CursorType::kSouthWestPanning:
+      return "sw-panning";
+    case ui::mojom::CursorType::kWestPanning:
+      return "w-panning";
+    case ui::mojom::CursorType::kMove:
+      return "move";
+    case ui::mojom::CursorType::kVerticalText:
+      return "vertical-text";
+    case ui::mojom::CursorType::kCell:
+      return "cell";
+    case ui::mojom::CursorType::kContextMenu:
+      return "context-menu";
+    case ui::mojom::CursorType::kAlias:
+      return "alias";
+    case ui::mojom::CursorType::kProgress:
+      return "progress";
+    case ui::mojom::CursorType::kNoDrop:
+      return "nodrop";
+    case ui::mojom::CursorType::kCopy:
+      return "copy";
+    case ui::mojom::CursorType::kNone:
+      return "none";
+    case ui::mojom::CursorType::kNotAllowed:
+      return "not-allowed";
+    case ui::mojom::CursorType::kZoomIn:
+      return "zoom-in";
+    case ui::mojom::CursorType::kZoomOut:
+      return "zoom-out";
+    case ui::mojom::CursorType::kGrab:
+      return "grab";
+    case ui::mojom::CursorType::kGrabbing:
+      return "grabbing";
+    case ui::mojom::CursorType::kCustom:
+      return "custom";
+    default:
+      return "default";
+  }
+}
+
 base::IDMap<WebContents*>& GetAllWebContents() {
   static base::NoDestructor<base::IDMap<WebContents*>> s_all_web_contents;
   return *s_all_web_contents;

+ 0 - 109
shell/common/mouse_util.cc

@@ -1,109 +0,0 @@
-// Copyright (c) 2015 GitHub, Inc.
-// Use of this source code is governed by the MIT license that can be
-// found in the LICENSE file.
-
-#include <string>
-
-#include "shell/common/mouse_util.h"
-#include "ui/base/cursor/mojom/cursor_type.mojom-shared.h"
-
-using Cursor = ui::mojom::CursorType;
-
-namespace electron {
-
-std::string CursorTypeToString(const ui::Cursor& cursor) {
-  switch (cursor.type()) {
-    case Cursor::kPointer:
-      return "default";
-    case Cursor::kCross:
-      return "crosshair";
-    case Cursor::kHand:
-      return "pointer";
-    case Cursor::kIBeam:
-      return "text";
-    case Cursor::kWait:
-      return "wait";
-    case Cursor::kHelp:
-      return "help";
-    case Cursor::kEastResize:
-      return "e-resize";
-    case Cursor::kNorthResize:
-      return "n-resize";
-    case Cursor::kNorthEastResize:
-      return "ne-resize";
-    case Cursor::kNorthWestResize:
-      return "nw-resize";
-    case Cursor::kSouthResize:
-      return "s-resize";
-    case Cursor::kSouthEastResize:
-      return "se-resize";
-    case Cursor::kSouthWestResize:
-      return "sw-resize";
-    case Cursor::kWestResize:
-      return "w-resize";
-    case Cursor::kNorthSouthResize:
-      return "ns-resize";
-    case Cursor::kEastWestResize:
-      return "ew-resize";
-    case Cursor::kNorthEastSouthWestResize:
-      return "nesw-resize";
-    case Cursor::kNorthWestSouthEastResize:
-      return "nwse-resize";
-    case Cursor::kColumnResize:
-      return "col-resize";
-    case Cursor::kRowResize:
-      return "row-resize";
-    case Cursor::kMiddlePanning:
-      return "m-panning";
-    case Cursor::kEastPanning:
-      return "e-panning";
-    case Cursor::kNorthPanning:
-      return "n-panning";
-    case Cursor::kNorthEastPanning:
-      return "ne-panning";
-    case Cursor::kNorthWestPanning:
-      return "nw-panning";
-    case Cursor::kSouthPanning:
-      return "s-panning";
-    case Cursor::kSouthEastPanning:
-      return "se-panning";
-    case Cursor::kSouthWestPanning:
-      return "sw-panning";
-    case Cursor::kWestPanning:
-      return "w-panning";
-    case Cursor::kMove:
-      return "move";
-    case Cursor::kVerticalText:
-      return "vertical-text";
-    case Cursor::kCell:
-      return "cell";
-    case Cursor::kContextMenu:
-      return "context-menu";
-    case Cursor::kAlias:
-      return "alias";
-    case Cursor::kProgress:
-      return "progress";
-    case Cursor::kNoDrop:
-      return "nodrop";
-    case Cursor::kCopy:
-      return "copy";
-    case Cursor::kNone:
-      return "none";
-    case Cursor::kNotAllowed:
-      return "not-allowed";
-    case Cursor::kZoomIn:
-      return "zoom-in";
-    case Cursor::kZoomOut:
-      return "zoom-out";
-    case Cursor::kGrab:
-      return "grab";
-    case Cursor::kGrabbing:
-      return "grabbing";
-    case Cursor::kCustom:
-      return "custom";
-    default:
-      return "default";
-  }
-}
-
-}  // namespace electron

+ 0 - 34
shell/common/mouse_util.h

@@ -1,34 +0,0 @@
-// Copyright (c) 2015 GitHub, Inc.
-// Use of this source code is governed by the MIT license that can be
-// found in the LICENSE file.
-
-#ifndef ELECTRON_SHELL_COMMON_MOUSE_UTIL_H_
-#define ELECTRON_SHELL_COMMON_MOUSE_UTIL_H_
-
-#include <string>
-#include "ipc/ipc_message_macros.h"
-#include "ui/base/cursor/cursor.h"
-
-// IPC macros similar to the already existing ones in the chromium source.
-// We need these to listen to the cursor change IPC message while still
-// letting chromium handle the actual cursor change by setting handled = false.
-#define IPC_MESSAGE_HANDLER_CODE(msg_class, member_func, code) \
-  IPC_MESSAGE_FORWARD_CODE(msg_class, this,                    \
-                           _IpcMessageHandlerClass::member_func, code)
-
-#define IPC_MESSAGE_FORWARD_CODE(msg_class, obj, member_func, code) \
-  case msg_class::ID: {                                             \
-    if (!msg_class::Dispatch(&ipc_message__, obj, this, param__,    \
-                             &member_func))                         \
-      ipc_message__.set_dispatch_error();                           \
-    code;                                                           \
-  } break;
-
-namespace electron {
-
-// Returns the cursor's type as a string.
-std::string CursorTypeToString(const ui::Cursor& cursor);
-
-}  // namespace electron
-
-#endif  // ELECTRON_SHELL_COMMON_MOUSE_UTIL_H_