Renamed some cursor types to their CSS names and added a way to handle custom cursors...
authorHeilig Benedek <benecene@gmail.com>
Sun, 31 Jan 2016 16:00:14 +0000 (17:00 +0100)
committerHeilig Benedek <benecene@gmail.com>
Sun, 31 Jan 2016 16:00:14 +0000 (17:00 +0100)
atom/browser/api/atom_api_web_contents.cc
atom/common/mouse_util.cc
atom/common/mouse_util.h
docs/api/web-contents.md

index 091c44e..ba067da 100644 (file)
@@ -1043,7 +1043,16 @@ void WebContents::EndFrameSubscription() {
 }
 
 void WebContents::OnCursorChange(const content::WebCursor& cursor) {
-  Emit("cursor-changed", CursorTypeToString(cursor));
+  content::WebCursor::CursorInfo* info = new content::WebCursor::CursorInfo();
+  cursor.GetCursorInfo(info);
+
+  if (cursor.IsCustom()) {
+    Emit("cursor-changed", CursorTypeToString(info),
+      gfx::Image::CreateFrom1xBitmap(info->custom_image),
+      info->image_scale_factor);
+  } else {
+    Emit("cursor-changed", CursorTypeToString(info));
+  }
 }
 
 void WebContents::SetSize(const SetSizeParams& params) {
index 8178668..8b7e4bb 100644 (file)
@@ -9,42 +9,37 @@ using Cursor = blink::WebCursorInfo::Type;
 
 namespace atom {
 
-std::string CursorTypeToString(const content::WebCursor& cursor) {
-  content::WebCursor::CursorInfo* info = new content::WebCursor::CursorInfo();
-  cursor.GetCursorInfo(info);
-
+std::string CursorTypeToString(const content::WebCursor::CursorInfo* info) {
   switch (info->type) {
-    case Cursor::TypePointer: return "pointer";
-    case Cursor::TypeCross: return "cross";
-    case Cursor::TypeHand: return "hand";
-    case Cursor::TypeIBeam: return "i-beam";
+    case Cursor::TypePointer: return "default";
+    case Cursor::TypeCross: return "crosshair";
+    case Cursor::TypeHand: return "pointer";
+    case Cursor::TypeIBeam: return "text";
     case Cursor::TypeWait: return "wait";
     case Cursor::TypeHelp: return "help";
-    case Cursor::TypeEastResize: return "east-resize";
-    case Cursor::TypeNorthResize: return "north-resize";
-    case Cursor::TypeNorthEastResize: return "north-east-resize";
-    case Cursor::TypeNorthWestResize: return "north-west-resize";
-    case Cursor::TypeSouthResize: return "south-resize";
-    case Cursor::TypeSouthEastResize: return "south-east-resize";
-    case Cursor::TypeSouthWestResize: return "south-west-resize";
-    case Cursor::TypeWestResize: return "west-resize";
-    case Cursor::TypeNorthSouthResize: return "north-south-resize";
-    case Cursor::TypeEastWestResize: return "east-west-resize";
-    case Cursor::TypeNorthEastSouthWestResize:
-      return "north-east-south-west-resize";
-    case Cursor::TypeNorthWestSouthEastResize:
-      return "north-west-south-east-resize";
-    case Cursor::TypeColumnResize: return "column-resize";
+    case Cursor::TypeEastResize: return "e-resize";
+    case Cursor::TypeNorthResize: return "n-resize";
+    case Cursor::TypeNorthEastResize: return "ne-resize";
+    case Cursor::TypeNorthWestResize: return "nw-resize";
+    case Cursor::TypeSouthResize: return "s-resize";
+    case Cursor::TypeSouthEastResize: return "se-resize";
+    case Cursor::TypeSouthWestResize: return "sw-resize";
+    case Cursor::TypeWestResize: return "w-resize";
+    case Cursor::TypeNorthSouthResize: return "ns-resize";
+    case Cursor::TypeEastWestResize: return "ew-resize";
+    case Cursor::TypeNorthEastSouthWestResize: return "nesw-resize";
+    case Cursor::TypeNorthWestSouthEastResize: return "nwse-resize";
+    case Cursor::TypeColumnResize: return "col-resize";
     case Cursor::TypeRowResize: return "row-resize";
-    case Cursor::TypeMiddlePanning: return "middle-panning";
-    case Cursor::TypeEastPanning: return "east-panning";
-    case Cursor::TypeNorthPanning: return "north-panning";
-    case Cursor::TypeNorthEastPanning: return "north-east-panning";
-    case Cursor::TypeNorthWestPanning: return "north-west-panning";
-    case Cursor::TypeSouthPanning: return "south-panning";
-    case Cursor::TypeSouthEastPanning: return "south-east-panning";
-    case Cursor::TypeSouthWestPanning: return "south-west-panning";
-    case Cursor::TypeWestPanning: return "west-panning";
+    case Cursor::TypeMiddlePanning: return "m-panning";
+    case Cursor::TypeEastPanning: return "e-panning";
+    case Cursor::TypeNorthPanning: return "n-panning";
+    case Cursor::TypeNorthEastPanning: return "ne-panning";
+    case Cursor::TypeNorthWestPanning: return "nw-panning";
+    case Cursor::TypeSouthPanning: return "s-panning";
+    case Cursor::TypeSouthEastPanning: return "se-panning";
+    case Cursor::TypeSouthWestPanning: return "sw-panning";
+    case Cursor::TypeWestPanning: return "w-panning";
     case Cursor::TypeMove: return "move";
     case Cursor::TypeVerticalText: return "vertical-text";
     case Cursor::TypeCell: return "cell";
@@ -60,7 +55,7 @@ std::string CursorTypeToString(const content::WebCursor& cursor) {
     case Cursor::TypeGrab: return "grab";
     case Cursor::TypeGrabbing: return "grabbing";
     case Cursor::TypeCustom: return "custom";
-    default: return "pointer";
+    default: return "default";
   }
 }
 
index 9ea1308..f754f9a 100644 (file)
@@ -29,7 +29,7 @@
 namespace atom {
 
 // Returns the cursor's type as a string.
-std::string CursorTypeToString(const content::WebCursor& cursor);
+std::string CursorTypeToString(const content::WebCursor::CursorInfo* info);
 
 }  // namespace atom
 
index a3fcc37..2dded8a 100644 (file)
@@ -287,17 +287,21 @@ Returns:
 
 * `event` Event
 * `type` String
-
-Emitted when the cursor's type changes. The `type` parameter can be `pointer`,
-`cross`, `hand`, `i-beam`, `wait`, `help`, `east-resize`, `north-resize`,
-`north-east-resize`, `north-west-resize`, `south-resize`, `south-east-resize`,
-`south-west-resize`, `west-resize`, `north-south-resize`, `east-west-resize`,
-`north-east-south-west-resize`, `north-west-south-east-resize`, `column-resize`,
-`row-resize`, `middle-panning`, `east-panning`, `north-panning`,
-`north-east-panning`, `north-west-panning`, `south-panning`,
-`south-east-panning`, `south-west-panning`, `west-panning`, `move`,
-`vertical-text`, `cell`, `context-menu`, `alias`, `progress`, `nodrop`, `copy`,
-`none`, `not-allowed`, `zoom-in`, `zoom-out`, `grab`, `grabbing`, `custom`.
+* `image` NativeImage
+* `scale` Float
+
+Emitted when the cursor's type changes. The `type` parameter can be `default`,
+`crosshair`, `pointer`, `text`, `wait`, `help`, `e-resize`, `n-resize`,
+`ne-resize`, `nw-resize`, `s-resize`, `se-resize`, `sw-resize`, `w-resize`,
+`ns-resize`, `ew-resize`, `nesw-resize`, `nwse-resize`, `col-resize`,
+`row-resize`, `m-panning`, `e-panning`, `n-panning`, `ne-panning`, `nw-panning`,
+`s-panning`, `se-panning`, `sw-panning`, `w-panning`, `move`, `vertical-text`,
+`cell`, `context-menu`, `alias`, `progress`, `nodrop`, `copy`, `none`,
+`not-allowed`, `zoom-in`, `zoom-out`, `grab`, `grabbing`, `custom`.
+
+If the `type` parameter is `custom`, the `image` parameter will hold the custom
+cursor image in a `NativeImage`, and the `scale` will hold scaling information
+for the image.
 
 ## Instance Methods