Merge pull request #6661 from MaxWhere/minor-fixes
A minor fix for sendInputEvent and improvements related to cursor-changed event
This commit is contained in:
commit
1d33275374
7 changed files with 42 additions and 9 deletions
|
@ -1299,7 +1299,9 @@ void WebContents::OnCursorChange(const content::WebCursor& cursor) {
|
||||||
if (cursor.IsCustom()) {
|
if (cursor.IsCustom()) {
|
||||||
Emit("cursor-changed", CursorTypeToString(info),
|
Emit("cursor-changed", CursorTypeToString(info),
|
||||||
gfx::Image::CreateFrom1xBitmap(info.custom_image),
|
gfx::Image::CreateFrom1xBitmap(info.custom_image),
|
||||||
info.image_scale_factor);
|
info.image_scale_factor,
|
||||||
|
gfx::Size(info.custom_image.width(), info.custom_image.height()),
|
||||||
|
info.hotspot);
|
||||||
} else {
|
} else {
|
||||||
Emit("cursor-changed", CursorTypeToString(info));
|
Emit("cursor-changed", CursorTypeToString(info));
|
||||||
}
|
}
|
||||||
|
|
|
@ -25,6 +25,7 @@
|
||||||
#include "ui/gfx/geometry/size.h"
|
#include "ui/gfx/geometry/size.h"
|
||||||
#include "ui/gfx/image/image_skia.h"
|
#include "ui/gfx/image/image_skia.h"
|
||||||
#include "ui/gfx/image/image_util.h"
|
#include "ui/gfx/image/image_util.h"
|
||||||
|
#include "third_party/skia/include/core/SkPixelRef.h"
|
||||||
|
|
||||||
#if defined(OS_WIN)
|
#if defined(OS_WIN)
|
||||||
#include "atom/common/asar/archive.h"
|
#include "atom/common/asar/archive.h"
|
||||||
|
@ -219,6 +220,14 @@ v8::Local<v8::Value> NativeImage::ToPNG(v8::Isolate* isolate) {
|
||||||
static_cast<size_t>(png->size())).ToLocalChecked();
|
static_cast<size_t>(png->size())).ToLocalChecked();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
v8::Local<v8::Value> NativeImage::ToBitmap(v8::Isolate* isolate) {
|
||||||
|
const SkBitmap* bitmap = image_.ToSkBitmap();
|
||||||
|
SkPixelRef* ref = bitmap->pixelRef();
|
||||||
|
return node::Buffer::Copy(isolate,
|
||||||
|
reinterpret_cast<const char*>(ref->pixels()),
|
||||||
|
bitmap->getSafeSize()).ToLocalChecked();
|
||||||
|
}
|
||||||
|
|
||||||
v8::Local<v8::Value> NativeImage::ToJPEG(v8::Isolate* isolate, int quality) {
|
v8::Local<v8::Value> NativeImage::ToJPEG(v8::Isolate* isolate, int quality) {
|
||||||
std::vector<unsigned char> output;
|
std::vector<unsigned char> output;
|
||||||
gfx::JPEG1xEncodedDataFromImage(image_, quality, &output);
|
gfx::JPEG1xEncodedDataFromImage(image_, quality, &output);
|
||||||
|
@ -350,6 +359,7 @@ void NativeImage::BuildPrototype(
|
||||||
mate::ObjectTemplateBuilder(isolate, prototype)
|
mate::ObjectTemplateBuilder(isolate, prototype)
|
||||||
.SetMethod("toPNG", &NativeImage::ToPNG)
|
.SetMethod("toPNG", &NativeImage::ToPNG)
|
||||||
.SetMethod("toJPEG", &NativeImage::ToJPEG)
|
.SetMethod("toJPEG", &NativeImage::ToJPEG)
|
||||||
|
.SetMethod("toBitmap", &NativeImage::ToBitmap)
|
||||||
.SetMethod("getNativeHandle", &NativeImage::GetNativeHandle)
|
.SetMethod("getNativeHandle", &NativeImage::GetNativeHandle)
|
||||||
.SetMethod("toDataURL", &NativeImage::ToDataURL)
|
.SetMethod("toDataURL", &NativeImage::ToDataURL)
|
||||||
.SetMethod("isEmpty", &NativeImage::IsEmpty)
|
.SetMethod("isEmpty", &NativeImage::IsEmpty)
|
||||||
|
|
|
@ -70,6 +70,7 @@ class NativeImage : public mate::Wrappable<NativeImage> {
|
||||||
private:
|
private:
|
||||||
v8::Local<v8::Value> ToPNG(v8::Isolate* isolate);
|
v8::Local<v8::Value> ToPNG(v8::Isolate* isolate);
|
||||||
v8::Local<v8::Value> ToJPEG(v8::Isolate* isolate, int quality);
|
v8::Local<v8::Value> ToJPEG(v8::Isolate* isolate, int quality);
|
||||||
|
v8::Local<v8::Value> ToBitmap(v8::Isolate* isolate);
|
||||||
v8::Local<v8::Value> GetNativeHandle(
|
v8::Local<v8::Value> GetNativeHandle(
|
||||||
v8::Isolate* isolate,
|
v8::Isolate* isolate,
|
||||||
mate::Arguments* args);
|
mate::Arguments* args);
|
||||||
|
|
|
@ -159,7 +159,8 @@ ui::KeyboardCode KeyboardCodeFromKeyIdentifier(const std::string& s,
|
||||||
return ui::VKEY_UNKNOWN;
|
return ui::VKEY_UNKNOWN;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
LOG(WARNING) << "Invalid accelerator token: " << str;
|
if (str.size() > 2)
|
||||||
|
LOG(WARNING) << "Invalid accelerator token: " << str;
|
||||||
return ui::VKEY_UNKNOWN;
|
return ui::VKEY_UNKNOWN;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,6 +4,7 @@
|
||||||
|
|
||||||
#include "atom/common/native_mate_converters/blink_converter.h"
|
#include "atom/common/native_mate_converters/blink_converter.h"
|
||||||
|
|
||||||
|
#include <algorithm>
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
|
@ -175,10 +176,18 @@ bool Converter<blink::WebKeyboardEvent>::FromV8(
|
||||||
out->modifiers |= blink::WebInputEvent::ShiftKey;
|
out->modifiers |= blink::WebInputEvent::ShiftKey;
|
||||||
out->setKeyIdentifierFromWindowsKeyCode();
|
out->setKeyIdentifierFromWindowsKeyCode();
|
||||||
if ((out->type == blink::WebInputEvent::Char ||
|
if ((out->type == blink::WebInputEvent::Char ||
|
||||||
out->type == blink::WebInputEvent::RawKeyDown) &&
|
out->type == blink::WebInputEvent::RawKeyDown)) {
|
||||||
str.size() == 1) {
|
// Make sure to not read beyond the buffer in case some bad code doesn't
|
||||||
out->text[0] = str[0];
|
// NULL-terminate it (this is called from plugins).
|
||||||
out->unmodifiedText[0] = str[0];
|
size_t text_length_cap = blink::WebKeyboardEvent::textLengthCap;
|
||||||
|
base::string16 text16 = base::UTF8ToUTF16(str);
|
||||||
|
|
||||||
|
memset(out->text, 0, text_length_cap);
|
||||||
|
memset(out->unmodifiedText, 0, text_length_cap);
|
||||||
|
for (size_t i = 0; i < std::min(text_length_cap, text16.size()); ++i) {
|
||||||
|
out->text[i] = text16[i];
|
||||||
|
out->unmodifiedText[i] = text16[i];
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
|
@ -152,6 +152,10 @@ Returns a [Buffer][buffer] that contains the image's `PNG` encoded data.
|
||||||
|
|
||||||
Returns a [Buffer][buffer] that contains the image's `JPEG` encoded data.
|
Returns a [Buffer][buffer] that contains the image's `JPEG` encoded data.
|
||||||
|
|
||||||
|
#### `image.toBitmap()`
|
||||||
|
|
||||||
|
Returns a [Buffer][buffer] that contains the image's raw pixel data.
|
||||||
|
|
||||||
#### `image.toDataURL()`
|
#### `image.toDataURL()`
|
||||||
|
|
||||||
Returns the data URL of the image.
|
Returns the data URL of the image.
|
||||||
|
|
|
@ -334,7 +334,13 @@ Returns:
|
||||||
* `event` Event
|
* `event` Event
|
||||||
* `type` String
|
* `type` String
|
||||||
* `image` NativeImage (optional)
|
* `image` NativeImage (optional)
|
||||||
* `scale` Float (optional)
|
* `scale` Float (optional) - scaling factor for the custom cursor
|
||||||
|
* `size` Object (optional) - the size of the `image`
|
||||||
|
* `width` Integer
|
||||||
|
* `height` Integer
|
||||||
|
* `hotspot` Object (optional) - coordinates of the custom cursor's hotspot
|
||||||
|
* `x` Integer - x coordinate
|
||||||
|
* `y` Integer - y coordinate
|
||||||
|
|
||||||
Emitted when the cursor's type changes. The `type` parameter can be `default`,
|
Emitted when the cursor's type changes. The `type` parameter can be `default`,
|
||||||
`crosshair`, `pointer`, `text`, `wait`, `help`, `e-resize`, `n-resize`,
|
`crosshair`, `pointer`, `text`, `wait`, `help`, `e-resize`, `n-resize`,
|
||||||
|
@ -346,8 +352,8 @@ Emitted when the cursor's type changes. The `type` parameter can be `default`,
|
||||||
`not-allowed`, `zoom-in`, `zoom-out`, `grab`, `grabbing`, `custom`.
|
`not-allowed`, `zoom-in`, `zoom-out`, `grab`, `grabbing`, `custom`.
|
||||||
|
|
||||||
If the `type` parameter is `custom`, the `image` parameter will hold the 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
|
cursor image in a `NativeImage`, and `scale`, `size` and `hotspot` will hold
|
||||||
for the image.
|
additional information about the custom cursor.
|
||||||
|
|
||||||
#### Event: 'context-menu'
|
#### Event: 'context-menu'
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue