From 0c9174bc7ca28e6e879704f69a5c7d24bbe674bb Mon Sep 17 00:00:00 2001 From: Heilig Benedek Date: Sat, 30 Jan 2016 06:33:55 +0100 Subject: [PATCH 1/4] Introduced the cursor-changed event with one parameter - the name of the cursor type --- atom/browser/api/atom_api_web_contents.cc | 9 ++ atom/browser/api/atom_api_web_contents.h | 3 + filenames.gypi | 2 + mw/cursor/cursor_event_filter.cc | 150 ++++++++++++++++++++++ mw/cursor/cursor_event_filter.h | 30 +++++ 5 files changed, 194 insertions(+) create mode 100644 mw/cursor/cursor_event_filter.cc create mode 100644 mw/cursor/cursor_event_filter.h diff --git a/atom/browser/api/atom_api_web_contents.cc b/atom/browser/api/atom_api_web_contents.cc index 2b14bdc60d83..0b557f2dfc4b 100644 --- a/atom/browser/api/atom_api_web_contents.cc +++ b/atom/browser/api/atom_api_web_contents.cc @@ -56,9 +56,12 @@ #include "net/url_request/url_request_context.h" #include "third_party/WebKit/public/web/WebInputEvent.h" #include "ui/base/l10n/l10n_util.h" +#include "mw/cursor/cursor_event_filter.h" #include "atom/common/node_includes.h" +#include + namespace { struct PrintSettings { @@ -619,6 +622,8 @@ bool WebContents::OnMessageReceived(const IPC::Message& message) { IPC_MESSAGE_HANDLER(AtomViewHostMsg_Message, OnRendererMessage) IPC_MESSAGE_HANDLER_DELAY_REPLY(AtomViewHostMsg_Message_Sync, OnRendererMessageSync) + IPC_MESSAGE_HANDLER_CODE(ViewHostMsg_SetCursor, OnCursorChange, + handled = false) IPC_MESSAGE_UNHANDLED(handled = false) IPC_END_MESSAGE_MAP() @@ -1039,6 +1044,10 @@ void WebContents::EndFrameSubscription() { view->EndFrameSubscription(); } +void WebContents::OnCursorChange(const content::WebCursor& cursor) { + Emit("cursor-changed", CursorChangeEvent::toString(cursor)); +} + void WebContents::SetSize(const SetSizeParams& params) { if (guest_delegate_) guest_delegate_->SetSize(params); diff --git a/atom/browser/api/atom_api_web_contents.h b/atom/browser/api/atom_api_web_contents.h index 10ac7a4f7695..21e201c7af16 100644 --- a/atom/browser/api/atom_api_web_contents.h +++ b/atom/browser/api/atom_api_web_contents.h @@ -14,6 +14,7 @@ #include "atom/browser/common_web_contents_delegate.h" #include "content/public/browser/web_contents_observer.h" #include "content/public/common/favicon_url.h" +#include "content/common/cursors/webcursor.h" #include "native_mate/handle.h" #include "ui/gfx/image/image.h" @@ -255,6 +256,8 @@ class WebContents : public mate::TrackableObject, return ++request_id_; } + void OnCursorChange(const content::WebCursor& cursor); + // Called when received a message from renderer. void OnRendererMessage(const base::string16& channel, const base::ListValue& args); diff --git a/filenames.gypi b/filenames.gypi index 4aa47fc3580f..b94d2b752cff 100644 --- a/filenames.gypi +++ b/filenames.gypi @@ -371,6 +371,8 @@ 'atom/renderer/node_array_buffer_bridge.h', 'atom/utility/atom_content_utility_client.cc', 'atom/utility/atom_content_utility_client.h', + 'mw/cursor/cursor_event_filter.cc', + 'mw/cursor/cursor_event_filter.h', 'chromium_src/chrome/browser/browser_process.cc', 'chromium_src/chrome/browser/browser_process.h', 'chromium_src/chrome/browser/chrome_process_finder_win.cc', diff --git a/mw/cursor/cursor_event_filter.cc b/mw/cursor/cursor_event_filter.cc new file mode 100644 index 000000000000..00c6d58bdfe8 --- /dev/null +++ b/mw/cursor/cursor_event_filter.cc @@ -0,0 +1,150 @@ +#include "mw/cursor/cursor_event_filter.h" +#include "content/common/view_messages.h" + +namespace atom { + +std::string CursorChangeEvent::toString( + const content::WebCursor& cursor) { + content::WebCursor::CursorInfo* info = new content::WebCursor::CursorInfo(); + cursor.GetCursorInfo(info); + + switch(info->type){ + case blink::WebCursorInfo::Type::TypePointer: + return "Pointer"; + break; + case blink::WebCursorInfo::Type::TypeCross: + return "Cross"; + break; + case blink::WebCursorInfo::Type::TypeHand: + return "Hand"; + break; + case blink::WebCursorInfo::Type::TypeIBeam: + return "IBeam"; + break; + case blink::WebCursorInfo::Type::TypeWait: + return "Wait"; + break; + case blink::WebCursorInfo::Type::TypeHelp: + return "Help"; + break; + case blink::WebCursorInfo::Type::TypeEastResize: + return "EastResize"; + break; + case blink::WebCursorInfo::Type::TypeNorthResize: + return "NorthResize"; + break; + case blink::WebCursorInfo::Type::TypeNorthEastResize: + return "NorthEastResize"; + break; + case blink::WebCursorInfo::Type::TypeNorthWestResize: + return "NorthWestResize"; + break; + case blink::WebCursorInfo::Type::TypeSouthResize: + return "SouthResize"; + break; + case blink::WebCursorInfo::Type::TypeSouthEastResize: + return "SouthEastResize"; + break; + case blink::WebCursorInfo::Type::TypeSouthWestResize: + return "SouthWestResize"; + break; + case blink::WebCursorInfo::Type::TypeWestResize: + return "WestResize"; + break; + case blink::WebCursorInfo::Type::TypeNorthSouthResize: + return "NorthSouthResize"; + break; + case blink::WebCursorInfo::Type::TypeEastWestResize: + return "EastWestResize"; + break; + case blink::WebCursorInfo::Type::TypeNorthEastSouthWestResize: + return "NorthEastSouthWestResize"; + break; + case blink::WebCursorInfo::Type::TypeNorthWestSouthEastResize: + return "NorthWestSouthEastResize"; + break; + case blink::WebCursorInfo::Type::TypeColumnResize: + return "ColumnResize"; + break; + case blink::WebCursorInfo::Type::TypeRowResize: + return "RowResize"; + break; + case blink::WebCursorInfo::Type::TypeMiddlePanning: + return "MiddlePanning"; + break; + case blink::WebCursorInfo::Type::TypeEastPanning: + return "EastPanning"; + break; + case blink::WebCursorInfo::Type::TypeNorthPanning: + return "NorthPanning"; + break; + case blink::WebCursorInfo::Type::TypeNorthEastPanning: + return "NorthEastPanning"; + break; + case blink::WebCursorInfo::Type::TypeNorthWestPanning: + return "NorthWestPanning"; + break; + case blink::WebCursorInfo::Type::TypeSouthPanning: + return "SouthPanning"; + break; + case blink::WebCursorInfo::Type::TypeSouthEastPanning: + return "SouthEastPanning"; + break; + case blink::WebCursorInfo::Type::TypeSouthWestPanning: + return "SouthWestPanning"; + break; + case blink::WebCursorInfo::Type::TypeWestPanning: + return "WestPanning"; + break; + case blink::WebCursorInfo::Type::TypeMove: + return "Move"; + break; + case blink::WebCursorInfo::Type::TypeVerticalText: + return "VerticalText"; + break; + case blink::WebCursorInfo::Type::TypeCell: + return "Cell"; + break; + case blink::WebCursorInfo::Type::TypeContextMenu: + return "ContextMenu"; + break; + case blink::WebCursorInfo::Type::TypeAlias: + return "Alias"; + break; + case blink::WebCursorInfo::Type::TypeProgress: + return "Progress"; + break; + case blink::WebCursorInfo::Type::TypeNoDrop: + return "NoDrop"; + break; + case blink::WebCursorInfo::Type::TypeCopy: + return "Copy"; + break; + case blink::WebCursorInfo::Type::TypeNone: + return "None"; + break; + case blink::WebCursorInfo::Type::TypeNotAllowed: + return "NotAllowed"; + break; + case blink::WebCursorInfo::Type::TypeZoomIn: + return "ZoomIn"; + break; + case blink::WebCursorInfo::Type::TypeZoomOut: + return "ZoomOut"; + break; + case blink::WebCursorInfo::Type::TypeGrab: + return "Grab"; + break; + case blink::WebCursorInfo::Type::TypeGrabbing: + return "Grabbing"; + break; + case blink::WebCursorInfo::Type::TypeCustom: + return "Custom"; + break; + default: + return "Pointer"; + break; + } +} + +} diff --git a/mw/cursor/cursor_event_filter.h b/mw/cursor/cursor_event_filter.h new file mode 100644 index 000000000000..31bc74498f4a --- /dev/null +++ b/mw/cursor/cursor_event_filter.h @@ -0,0 +1,30 @@ +#ifndef MW_CURSOR_EVENT_H_ +#define MW_CURSOR_EVENT_H_ + +#include "content/common/cursors/webcursor.h" +#include "ipc/ipc_message_macros.h" + +#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: { \ + TRACK_RUN_IN_THIS_SCOPED_REGION(member_func); \ + if (!msg_class::Dispatch(&ipc_message__, obj, this, param__, \ + &member_func)) \ + ipc_message__.set_dispatch_error(); \ + code; \ + } \ + break; + +namespace atom { + +class CursorChangeEvent { + public: + static std::string toString(const content::WebCursor& cursor); +}; + +} + +#endif // MW_CURSOR_EVENT_H_ From 61e0219e9124e409916ccac6a6118407edac4854 Mon Sep 17 00:00:00 2001 From: Heilig Benedek Date: Sun, 31 Jan 2016 02:27:14 +0100 Subject: [PATCH 2/4] Added documentation, restructured the files to fit better with electron's style and fixed a typo in keyboard_util's name. --- atom/browser/api/atom_api_web_contents.cc | 6 +- atom/browser/api/atom_api_web_contents.h | 1 + atom/browser/ui/accelerator_util.cc | 2 +- .../{keyboad_util.cc => keyboard_util.cc} | 2 +- .../{keyboad_util.h => keyboard_util.h} | 6 +- atom/common/mouse_util.cc | 67 ++++++++ atom/common/mouse_util.h | 36 +++++ .../native_mate_converters/blink_converter.cc | 2 +- docs/api/web-contents.md | 18 +++ filenames.gypi | 8 +- mw/cursor/cursor_event_filter.cc | 150 ------------------ mw/cursor/cursor_event_filter.h | 30 ---- 12 files changed, 134 insertions(+), 194 deletions(-) rename atom/common/{keyboad_util.cc => keyboard_util.cc} (98%) rename atom/common/{keyboad_util.h => keyboard_util.h} (83%) create mode 100644 atom/common/mouse_util.cc create mode 100644 atom/common/mouse_util.h delete mode 100644 mw/cursor/cursor_event_filter.cc delete mode 100644 mw/cursor/cursor_event_filter.h diff --git a/atom/browser/api/atom_api_web_contents.cc b/atom/browser/api/atom_api_web_contents.cc index 0b557f2dfc4b..091c44ed5179 100644 --- a/atom/browser/api/atom_api_web_contents.cc +++ b/atom/browser/api/atom_api_web_contents.cc @@ -27,6 +27,7 @@ #include "atom/common/native_mate_converters/image_converter.h" #include "atom/common/native_mate_converters/string16_converter.h" #include "atom/common/native_mate_converters/value_converter.h" +#include "atom/common/mouse_util.h" #include "base/strings/string_util.h" #include "base/strings/utf_string_conversions.h" #include "brightray/browser/inspectable_web_contents.h" @@ -56,12 +57,9 @@ #include "net/url_request/url_request_context.h" #include "third_party/WebKit/public/web/WebInputEvent.h" #include "ui/base/l10n/l10n_util.h" -#include "mw/cursor/cursor_event_filter.h" #include "atom/common/node_includes.h" -#include - namespace { struct PrintSettings { @@ -1045,7 +1043,7 @@ void WebContents::EndFrameSubscription() { } void WebContents::OnCursorChange(const content::WebCursor& cursor) { - Emit("cursor-changed", CursorChangeEvent::toString(cursor)); + Emit("cursor-changed", CursorTypeToString(cursor)); } void WebContents::SetSize(const SetSizeParams& params) { diff --git a/atom/browser/api/atom_api_web_contents.h b/atom/browser/api/atom_api_web_contents.h index 21e201c7af16..e00798b6c137 100644 --- a/atom/browser/api/atom_api_web_contents.h +++ b/atom/browser/api/atom_api_web_contents.h @@ -256,6 +256,7 @@ class WebContents : public mate::TrackableObject, return ++request_id_; } + // Called when we receive a CursorChange message from chromium. void OnCursorChange(const content::WebCursor& cursor); // Called when received a message from renderer. diff --git a/atom/browser/ui/accelerator_util.cc b/atom/browser/ui/accelerator_util.cc index a0b90e0c7e58..39138d8e49b5 100644 --- a/atom/browser/ui/accelerator_util.cc +++ b/atom/browser/ui/accelerator_util.cc @@ -9,7 +9,7 @@ #include #include -#include "atom/common/keyboad_util.h" +#include "atom/common/keyboard_util.h" #include "base/stl_util.h" #include "base/strings/string_number_conversions.h" #include "base/strings/string_split.h" diff --git a/atom/common/keyboad_util.cc b/atom/common/keyboard_util.cc similarity index 98% rename from atom/common/keyboad_util.cc rename to atom/common/keyboard_util.cc index 7d7c5d99fabe..e5dedd84dedd 100644 --- a/atom/common/keyboad_util.cc +++ b/atom/common/keyboard_util.cc @@ -3,7 +3,7 @@ // found in the LICENSE file. #include -#include "atom/common/keyboad_util.h" +#include "atom/common/keyboard_util.h" namespace atom { diff --git a/atom/common/keyboad_util.h b/atom/common/keyboard_util.h similarity index 83% rename from atom/common/keyboad_util.h rename to atom/common/keyboard_util.h index 4a85c190635d..d3168d4447e0 100644 --- a/atom/common/keyboad_util.h +++ b/atom/common/keyboard_util.h @@ -2,8 +2,8 @@ // Use of this source code is governed by the MIT license that can be // found in the LICENSE file. -#ifndef ATOM_COMMON_KEYBOAD_UTIL_H_ -#define ATOM_COMMON_KEYBOAD_UTIL_H_ +#ifndef ATOM_COMMON_KEYBOARD_UTIL_H_ +#define ATOM_COMMON_KEYBOARD_UTIL_H_ #include #include "ui/events/keycodes/keyboard_codes.h" @@ -20,4 +20,4 @@ ui::KeyboardCode KeyboardCodeFromKeyIdentifier(const std::string& chr); } // namespace atom -#endif // ATOM_COMMON_KEYBOAD_UTIL_H_ +#endif // ATOM_COMMON_KEYBOARD_UTIL_H_ diff --git a/atom/common/mouse_util.cc b/atom/common/mouse_util.cc new file mode 100644 index 000000000000..8178668ca15d --- /dev/null +++ b/atom/common/mouse_util.cc @@ -0,0 +1,67 @@ +// 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 +#include "atom/common/mouse_util.h" + +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); + + 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::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::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::TypeMove: return "move"; + case Cursor::TypeVerticalText: return "vertical-text"; + case Cursor::TypeCell: return "cell"; + case Cursor::TypeContextMenu: return "context-menu"; + case Cursor::TypeAlias: return "alias"; + case Cursor::TypeProgress: return "progress"; + case Cursor::TypeNoDrop: return "nodrop"; + case Cursor::TypeCopy: return "copy"; + case Cursor::TypeNone: return "none"; + case Cursor::TypeNotAllowed: return "not-allowed"; + case Cursor::TypeZoomIn: return "zoom-in"; + case Cursor::TypeZoomOut: return "zoom-out"; + case Cursor::TypeGrab: return "grab"; + case Cursor::TypeGrabbing: return "grabbing"; + case Cursor::TypeCustom: return "custom"; + default: return "pointer"; + } +} + +} // namespace atom diff --git a/atom/common/mouse_util.h b/atom/common/mouse_util.h new file mode 100644 index 000000000000..9ea130821eb0 --- /dev/null +++ b/atom/common/mouse_util.h @@ -0,0 +1,36 @@ +// 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 ATOM_COMMON_MOUSE_UTIL_H_ +#define ATOM_COMMON_MOUSE_UTIL_H_ + +#include +#include "content/common/cursors/webcursor.h" +#include "ipc/ipc_message_macros.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: { \ + TRACK_RUN_IN_THIS_SCOPED_REGION(member_func); \ + if (!msg_class::Dispatch(&ipc_message__, obj, this, param__, \ + &member_func)) \ + ipc_message__.set_dispatch_error(); \ + code; \ + } \ + break; + +namespace atom { + +// Returns the cursor's type as a string. +std::string CursorTypeToString(const content::WebCursor& cursor); + +} // namespace atom + +#endif // ATOM_COMMON_MOUSE_UTIL_H_ diff --git a/atom/common/native_mate_converters/blink_converter.cc b/atom/common/native_mate_converters/blink_converter.cc index 095490ab883c..fdb894b33462 100644 --- a/atom/common/native_mate_converters/blink_converter.cc +++ b/atom/common/native_mate_converters/blink_converter.cc @@ -7,7 +7,7 @@ #include #include -#include "atom/common/keyboad_util.h" +#include "atom/common/keyboard_util.h" #include "base/strings/string_util.h" #include "base/strings/utf_string_conversions.h" #include "content/public/browser/native_web_keyboard_event.h" diff --git a/docs/api/web-contents.md b/docs/api/web-contents.md index 939a09629973..a3fcc37da3c4 100644 --- a/docs/api/web-contents.md +++ b/docs/api/web-contents.md @@ -281,6 +281,24 @@ Emitted when a page's theme color changes. This is usually due to encountering a ``` +### Event: 'cursor-changed' + +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`. + ## Instance Methods The `webContents` object has the following instance methods: diff --git a/filenames.gypi b/filenames.gypi index b94d2b752cff..748b3b9252cd 100644 --- a/filenames.gypi +++ b/filenames.gypi @@ -317,8 +317,10 @@ 'atom/common/google_api_key.h', 'atom/common/id_weak_map.cc', 'atom/common/id_weak_map.h', - 'atom/common/keyboad_util.cc', - 'atom/common/keyboad_util.h', + 'atom/common/keyboard_util.cc', + 'atom/common/keyboard_util.h', + 'atom/common/mouse_util.cc', + 'atom/common/mouse_util.h', 'atom/common/linux/application_info.cc', 'atom/common/native_mate_converters/accelerator_converter.cc', 'atom/common/native_mate_converters/accelerator_converter.h', @@ -371,8 +373,6 @@ 'atom/renderer/node_array_buffer_bridge.h', 'atom/utility/atom_content_utility_client.cc', 'atom/utility/atom_content_utility_client.h', - 'mw/cursor/cursor_event_filter.cc', - 'mw/cursor/cursor_event_filter.h', 'chromium_src/chrome/browser/browser_process.cc', 'chromium_src/chrome/browser/browser_process.h', 'chromium_src/chrome/browser/chrome_process_finder_win.cc', diff --git a/mw/cursor/cursor_event_filter.cc b/mw/cursor/cursor_event_filter.cc deleted file mode 100644 index 00c6d58bdfe8..000000000000 --- a/mw/cursor/cursor_event_filter.cc +++ /dev/null @@ -1,150 +0,0 @@ -#include "mw/cursor/cursor_event_filter.h" -#include "content/common/view_messages.h" - -namespace atom { - -std::string CursorChangeEvent::toString( - const content::WebCursor& cursor) { - content::WebCursor::CursorInfo* info = new content::WebCursor::CursorInfo(); - cursor.GetCursorInfo(info); - - switch(info->type){ - case blink::WebCursorInfo::Type::TypePointer: - return "Pointer"; - break; - case blink::WebCursorInfo::Type::TypeCross: - return "Cross"; - break; - case blink::WebCursorInfo::Type::TypeHand: - return "Hand"; - break; - case blink::WebCursorInfo::Type::TypeIBeam: - return "IBeam"; - break; - case blink::WebCursorInfo::Type::TypeWait: - return "Wait"; - break; - case blink::WebCursorInfo::Type::TypeHelp: - return "Help"; - break; - case blink::WebCursorInfo::Type::TypeEastResize: - return "EastResize"; - break; - case blink::WebCursorInfo::Type::TypeNorthResize: - return "NorthResize"; - break; - case blink::WebCursorInfo::Type::TypeNorthEastResize: - return "NorthEastResize"; - break; - case blink::WebCursorInfo::Type::TypeNorthWestResize: - return "NorthWestResize"; - break; - case blink::WebCursorInfo::Type::TypeSouthResize: - return "SouthResize"; - break; - case blink::WebCursorInfo::Type::TypeSouthEastResize: - return "SouthEastResize"; - break; - case blink::WebCursorInfo::Type::TypeSouthWestResize: - return "SouthWestResize"; - break; - case blink::WebCursorInfo::Type::TypeWestResize: - return "WestResize"; - break; - case blink::WebCursorInfo::Type::TypeNorthSouthResize: - return "NorthSouthResize"; - break; - case blink::WebCursorInfo::Type::TypeEastWestResize: - return "EastWestResize"; - break; - case blink::WebCursorInfo::Type::TypeNorthEastSouthWestResize: - return "NorthEastSouthWestResize"; - break; - case blink::WebCursorInfo::Type::TypeNorthWestSouthEastResize: - return "NorthWestSouthEastResize"; - break; - case blink::WebCursorInfo::Type::TypeColumnResize: - return "ColumnResize"; - break; - case blink::WebCursorInfo::Type::TypeRowResize: - return "RowResize"; - break; - case blink::WebCursorInfo::Type::TypeMiddlePanning: - return "MiddlePanning"; - break; - case blink::WebCursorInfo::Type::TypeEastPanning: - return "EastPanning"; - break; - case blink::WebCursorInfo::Type::TypeNorthPanning: - return "NorthPanning"; - break; - case blink::WebCursorInfo::Type::TypeNorthEastPanning: - return "NorthEastPanning"; - break; - case blink::WebCursorInfo::Type::TypeNorthWestPanning: - return "NorthWestPanning"; - break; - case blink::WebCursorInfo::Type::TypeSouthPanning: - return "SouthPanning"; - break; - case blink::WebCursorInfo::Type::TypeSouthEastPanning: - return "SouthEastPanning"; - break; - case blink::WebCursorInfo::Type::TypeSouthWestPanning: - return "SouthWestPanning"; - break; - case blink::WebCursorInfo::Type::TypeWestPanning: - return "WestPanning"; - break; - case blink::WebCursorInfo::Type::TypeMove: - return "Move"; - break; - case blink::WebCursorInfo::Type::TypeVerticalText: - return "VerticalText"; - break; - case blink::WebCursorInfo::Type::TypeCell: - return "Cell"; - break; - case blink::WebCursorInfo::Type::TypeContextMenu: - return "ContextMenu"; - break; - case blink::WebCursorInfo::Type::TypeAlias: - return "Alias"; - break; - case blink::WebCursorInfo::Type::TypeProgress: - return "Progress"; - break; - case blink::WebCursorInfo::Type::TypeNoDrop: - return "NoDrop"; - break; - case blink::WebCursorInfo::Type::TypeCopy: - return "Copy"; - break; - case blink::WebCursorInfo::Type::TypeNone: - return "None"; - break; - case blink::WebCursorInfo::Type::TypeNotAllowed: - return "NotAllowed"; - break; - case blink::WebCursorInfo::Type::TypeZoomIn: - return "ZoomIn"; - break; - case blink::WebCursorInfo::Type::TypeZoomOut: - return "ZoomOut"; - break; - case blink::WebCursorInfo::Type::TypeGrab: - return "Grab"; - break; - case blink::WebCursorInfo::Type::TypeGrabbing: - return "Grabbing"; - break; - case blink::WebCursorInfo::Type::TypeCustom: - return "Custom"; - break; - default: - return "Pointer"; - break; - } -} - -} diff --git a/mw/cursor/cursor_event_filter.h b/mw/cursor/cursor_event_filter.h deleted file mode 100644 index 31bc74498f4a..000000000000 --- a/mw/cursor/cursor_event_filter.h +++ /dev/null @@ -1,30 +0,0 @@ -#ifndef MW_CURSOR_EVENT_H_ -#define MW_CURSOR_EVENT_H_ - -#include "content/common/cursors/webcursor.h" -#include "ipc/ipc_message_macros.h" - -#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: { \ - TRACK_RUN_IN_THIS_SCOPED_REGION(member_func); \ - if (!msg_class::Dispatch(&ipc_message__, obj, this, param__, \ - &member_func)) \ - ipc_message__.set_dispatch_error(); \ - code; \ - } \ - break; - -namespace atom { - -class CursorChangeEvent { - public: - static std::string toString(const content::WebCursor& cursor); -}; - -} - -#endif // MW_CURSOR_EVENT_H_ From 066c189249f6392945d8c8a2e7373df705d6e983 Mon Sep 17 00:00:00 2001 From: Heilig Benedek Date: Sun, 31 Jan 2016 17:00:14 +0100 Subject: [PATCH 3/4] Renamed some cursor types to their CSS names and added a way to handle custom cursors properly. --- atom/browser/api/atom_api_web_contents.cc | 11 +++- atom/common/mouse_util.cc | 61 +++++++++++------------ atom/common/mouse_util.h | 2 +- docs/api/web-contents.md | 24 +++++---- 4 files changed, 53 insertions(+), 45 deletions(-) diff --git a/atom/browser/api/atom_api_web_contents.cc b/atom/browser/api/atom_api_web_contents.cc index 091c44ed5179..ba067dac496f 100644 --- a/atom/browser/api/atom_api_web_contents.cc +++ b/atom/browser/api/atom_api_web_contents.cc @@ -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) { diff --git a/atom/common/mouse_util.cc b/atom/common/mouse_util.cc index 8178668ca15d..8b7e4bbbc228 100644 --- a/atom/common/mouse_util.cc +++ b/atom/common/mouse_util.cc @@ -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"; } } diff --git a/atom/common/mouse_util.h b/atom/common/mouse_util.h index 9ea130821eb0..f754f9a066ad 100644 --- a/atom/common/mouse_util.h +++ b/atom/common/mouse_util.h @@ -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 diff --git a/docs/api/web-contents.md b/docs/api/web-contents.md index a3fcc37da3c4..2dded8a042f5 100644 --- a/docs/api/web-contents.md +++ b/docs/api/web-contents.md @@ -287,17 +287,21 @@ Returns: * `event` Event * `type` String +* `image` NativeImage +* `scale` Float -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`. +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 From 745253a36943b613eb737b5bd85a2012dfbd4441 Mon Sep 17 00:00:00 2001 From: Heilig Benedek Date: Mon, 1 Feb 2016 07:17:58 +0100 Subject: [PATCH 4/4] Quick fix for the memory leak + docs --- atom/browser/api/atom_api_web_contents.cc | 8 ++++---- atom/common/mouse_util.cc | 4 ++-- atom/common/mouse_util.h | 2 +- docs/api/web-contents.md | 4 ++-- 4 files changed, 9 insertions(+), 9 deletions(-) diff --git a/atom/browser/api/atom_api_web_contents.cc b/atom/browser/api/atom_api_web_contents.cc index ba067dac496f..b7b0576d8bfa 100644 --- a/atom/browser/api/atom_api_web_contents.cc +++ b/atom/browser/api/atom_api_web_contents.cc @@ -1043,13 +1043,13 @@ void WebContents::EndFrameSubscription() { } void WebContents::OnCursorChange(const content::WebCursor& cursor) { - content::WebCursor::CursorInfo* info = new content::WebCursor::CursorInfo(); - cursor.GetCursorInfo(info); + content::WebCursor::CursorInfo info; + cursor.GetCursorInfo(&info); if (cursor.IsCustom()) { Emit("cursor-changed", CursorTypeToString(info), - gfx::Image::CreateFrom1xBitmap(info->custom_image), - info->image_scale_factor); + gfx::Image::CreateFrom1xBitmap(info.custom_image), + info.image_scale_factor); } else { Emit("cursor-changed", CursorTypeToString(info)); } diff --git a/atom/common/mouse_util.cc b/atom/common/mouse_util.cc index 8b7e4bbbc228..69aadaa7a046 100644 --- a/atom/common/mouse_util.cc +++ b/atom/common/mouse_util.cc @@ -9,8 +9,8 @@ using Cursor = blink::WebCursorInfo::Type; namespace atom { -std::string CursorTypeToString(const content::WebCursor::CursorInfo* info) { - switch (info->type) { +std::string CursorTypeToString(const content::WebCursor::CursorInfo& info) { + switch (info.type) { case Cursor::TypePointer: return "default"; case Cursor::TypeCross: return "crosshair"; case Cursor::TypeHand: return "pointer"; diff --git a/atom/common/mouse_util.h b/atom/common/mouse_util.h index f754f9a066ad..2fd937422dac 100644 --- a/atom/common/mouse_util.h +++ b/atom/common/mouse_util.h @@ -29,7 +29,7 @@ namespace atom { // Returns the cursor's type as a string. -std::string CursorTypeToString(const content::WebCursor::CursorInfo* info); +std::string CursorTypeToString(const content::WebCursor::CursorInfo& info); } // namespace atom diff --git a/docs/api/web-contents.md b/docs/api/web-contents.md index 2dded8a042f5..afdd08c4d005 100644 --- a/docs/api/web-contents.md +++ b/docs/api/web-contents.md @@ -287,8 +287,8 @@ Returns: * `event` Event * `type` String -* `image` NativeImage -* `scale` Float +* `image` NativeImage (optional) +* `scale` Float (optional) Emitted when the cursor's type changes. The `type` parameter can be `default`, `crosshair`, `pointer`, `text`, `wait`, `help`, `e-resize`, `n-resize`,