Merge pull request #4288 from MaxWhere/master

Adding cursor-changed event to webContents
This commit is contained in:
Cheng Zhao 2016-02-01 17:03:16 +08:00
commit e450d1586e
10 changed files with 150 additions and 8 deletions

View file

@ -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"
@ -619,6 +620,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 +1042,19 @@ void WebContents::EndFrameSubscription() {
view->EndFrameSubscription();
}
void WebContents::OnCursorChange(const content::WebCursor& cursor) {
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);
} else {
Emit("cursor-changed", CursorTypeToString(info));
}
}
void WebContents::SetSize(const SetSizeParams& params) {
if (guest_delegate_)
guest_delegate_->SetSize(params);

View file

@ -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,9 @@ class WebContents : public mate::TrackableObject<WebContents>,
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.
void OnRendererMessage(const base::string16& channel,
const base::ListValue& args);

View file

@ -9,7 +9,7 @@
#include <string>
#include <vector>
#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"