提交 9f2d7230 编写于 作者: J Jason Simmons

Replace the legacy pointer input event handling with PointerPackets

With this change we no longer need engine/core/events and its IDL bindings.
上级 ca55eb11
......@@ -31,58 +31,6 @@ int EventFlagsToWebInputEventModifiers(mojo::EventFlags event_flags) {
blink::WebInputEvent::RightButtonDown : 0);
}
scoped_ptr<blink::WebInputEvent> BuildWebPointerEvent(
const mojo::EventPtr& event, float device_pixel_ratio) {
scoped_ptr<blink::WebPointerEvent> web_event(new blink::WebPointerEvent);
web_event->modifiers = EventFlagsToWebInputEventModifiers(event->flags);
web_event->timeStampMS =
base::TimeDelta::FromInternalValue(event->time_stamp).InMillisecondsF();
switch (event->action) {
case mojo::EventType::POINTER_DOWN:
web_event->type = blink::WebInputEvent::PointerDown;
break;
case mojo::EventType::POINTER_MOVE:
web_event->type = blink::WebInputEvent::PointerMove;
break;
case mojo::EventType::POINTER_UP:
web_event->type = blink::WebInputEvent::PointerUp;
break;
case mojo::EventType::POINTER_CANCEL:
// FIXME: What mouse event should we listen to in order to learn when the
// mouse moves out of the mojo::View?
web_event->type = blink::WebInputEvent::PointerCancel;
break;
default:
NOTIMPLEMENTED() << "Received unexpected event: " << event->action;
break;
}
if (event->pointer_data->kind == mojo::PointerKind::TOUCH) {
web_event->kind = blink::WebPointerEvent::Touch;
web_event->pointer = event->pointer_data->pointer_id;
} else {
web_event->kind = blink::WebPointerEvent::Mouse;
// Set the buttons according to http://www.w3.org/TR/pointerevents/
int buttons = 0;
int modifiers = web_event->modifiers;
buttons |= modifiers & blink::WebInputEvent::LeftButtonDown ? 1 << 0 : 0;
buttons |= modifiers & blink::WebInputEvent::RightButtonDown ? 1 << 1 : 0;
buttons |= modifiers & blink::WebInputEvent::MiddleButtonDown ? 1 << 2 : 0;
web_event->buttons = buttons;
}
web_event->x = event->pointer_data->x / device_pixel_ratio;
web_event->y = event->pointer_data->y / device_pixel_ratio;
web_event->pressure = event->pointer_data->pressure;
web_event->radiusMajor = event->pointer_data->radius_major;
web_event->radiusMinor = event->pointer_data->radius_minor;
web_event->orientation = event->pointer_data->orientation;
return web_event.Pass();
}
scoped_ptr<blink::WebInputEvent> BuildWebKeyboardEvent(
const mojo::EventPtr& event,
float device_pixel_ratio) {
......@@ -135,6 +83,15 @@ scoped_ptr<blink::WebInputEvent> BuildWebWheelEvent(
} // namespace
bool IsPointerEvent(const mojo::EventPtr& event) {
return ((event->action == mojo::EventType::POINTER_DOWN ||
event->action == mojo::EventType::POINTER_UP ||
event->action == mojo::EventType::POINTER_CANCEL ||
event->action == mojo::EventType::POINTER_MOVE) &&
event->pointer_data->horizontal_wheel == 0 &&
event->pointer_data->vertical_wheel == 0);
}
scoped_ptr<blink::WebInputEvent> ConvertEvent(const mojo::EventPtr& event,
float device_pixel_ratio) {
if (event->action == mojo::EventType::POINTER_DOWN ||
......@@ -145,7 +102,6 @@ scoped_ptr<blink::WebInputEvent> ConvertEvent(const mojo::EventPtr& event,
event->pointer_data->vertical_wheel != 0) {
return BuildWebWheelEvent(event, device_pixel_ratio);
}
return BuildWebPointerEvent(event, device_pixel_ratio);
} else if ((event->action == mojo::EventType::KEY_PRESSED ||
event->action == mojo::EventType::KEY_RELEASED) &&
event->key_data) {
......@@ -155,4 +111,61 @@ scoped_ptr<blink::WebInputEvent> ConvertEvent(const mojo::EventPtr& event,
return nullptr;
}
pointer::PointerPacketPtr ConvertPointerEvent(const mojo::EventPtr& event,
float device_pixel_ratio) {
pointer::PointerPacketPtr packet = pointer::PointerPacket::New();
pointer::PointerPtr pointer = pointer::Pointer::New();
pointer->time_stamp =
base::TimeDelta::FromInternalValue(event->time_stamp).InMillisecondsF();
switch (event->action) {
case mojo::EventType::POINTER_DOWN:
pointer->type = pointer::PointerType::DOWN;
break;
case mojo::EventType::POINTER_MOVE:
pointer->type = pointer::PointerType::MOVE;
break;
case mojo::EventType::POINTER_UP:
pointer->type = pointer::PointerType::UP;
break;
case mojo::EventType::POINTER_CANCEL:
// FIXME: What mouse event should we listen to in order to learn when the
// mouse moves out of the mojo::View?
pointer->type = pointer::PointerType::CANCEL;
break;
default:
NOTIMPLEMENTED() << "Received unexpected event: " << event->action;
break;
}
if (event->pointer_data->kind == mojo::PointerKind::TOUCH) {
pointer->kind = pointer::PointerKind::TOUCH;
pointer->pointer = event->pointer_data->pointer_id;
} else {
pointer->kind = pointer::PointerKind::MOUSE;
// Set the buttons according to http://www.w3.org/TR/pointerevents/
int buttons = 0;
int flags = static_cast<int>(event->flags);
if (flags & static_cast<int>(mojo::EventFlags::LEFT_MOUSE_BUTTON))
buttons |= (1 << 0);
if (flags & static_cast<int>(mojo::EventFlags::RIGHT_MOUSE_BUTTON))
buttons |= (1 << 1);
if (flags & static_cast<int>(mojo::EventFlags::MIDDLE_MOUSE_BUTTON))
buttons |= (1 << 2);
pointer->buttons = buttons;
}
pointer->x = event->pointer_data->x / device_pixel_ratio;
pointer->y = event->pointer_data->y / device_pixel_ratio;
pointer->pressure = event->pointer_data->pressure;
pointer->radius_major = event->pointer_data->radius_major;
pointer->radius_minor = event->pointer_data->radius_minor;
pointer->orientation = event->pointer_data->orientation;
packet->pointers.push_back(pointer.Pass());
return packet;
}
} // namespace mojo
......@@ -7,14 +7,20 @@
#include "base/memory/scoped_ptr.h"
#include "mojo/services/input_events/interfaces/input_events.mojom.h"
#include "sky/services/pointer/pointer.mojom.h"
namespace blink {
class WebInputEvent;
}
namespace sky {
bool IsPointerEvent(const mojo::EventPtr& event);
scoped_ptr<blink::WebInputEvent> ConvertEvent(const mojo::EventPtr& event,
float device_pixel_ratio);
pointer::PointerPacketPtr ConvertPointerEvent(const mojo::EventPtr& event,
float device_pixel_ratio);
}
#endif // SKY_VIEWER_CONVERTERS_INPUT_EVENT_TYPES_H_
......@@ -268,13 +268,20 @@ void DocumentView::HandleInputEvent(mojo::EventPtr event) {
if (!viewport_metrics_)
return;
float device_pixel_ratio = viewport_metrics_->device_pixel_ratio;
scoped_ptr<blink::WebInputEvent> web_event =
ConvertEvent(event, device_pixel_ratio);
if (!web_event)
return;
if (sky_view_)
sky_view_->HandleInputEvent(*web_event);
if (IsPointerEvent(event)) {
pointer::PointerPacketPtr packet =
ConvertPointerEvent(event, device_pixel_ratio);
sky_view_->HandlePointerPacket(packet);
} else {
scoped_ptr<blink::WebInputEvent> web_event =
ConvertEvent(event, device_pixel_ratio);
if (!web_event)
return;
if (sky_view_)
sky_view_->HandleInputEvent(*web_event);
}
}
void DocumentView::StartDebuggerInspectorBackend() {
......
......@@ -376,7 +376,6 @@ source_set("generated_bindings") {
"//mojo/public/cpp/utility",
"//mojo/public/interfaces/application",
"//skia",
"//sky/engine/core:core_names",
"//sky/engine/wtf",
"//third_party/iccjpeg",
"//third_party/libpng",
......
......@@ -2,6 +2,7 @@ dart:io,::,_setupHooks
dart:mojo.internal,MojoHandleWatcher,_start
dart:ui,::,_beginFrame
dart:ui,::,_dispatchEvent
dart:ui,::,_dispatchPointerPacket
dart:ui,::,_getCreateTimerClosure
dart:ui,::,_getGetBaseURLClosure
dart:ui,::,_getMainClosure
......
......@@ -34,7 +34,6 @@ source_set("libraries") {
source_set("prerequisites") {
deps = [
":libraries",
":make_core_generated",
"//sky/engine/platform",
]
......@@ -67,12 +66,12 @@ static_library("core") {
output_name = "sky_core"
deps = [
":core_generated",
":generate_sky_embedder_service_isolate_resources_cc",
":libraries",
":prerequisites",
"//sky/engine/platform",
"//sky/engine/bindings",
"//sky/services/pointer:interfaces",
"//dart/runtime/bin:embedded_dart_io",
"//dart/runtime:libdart",
"//dart/runtime/vm:libdart_platform",
......@@ -92,125 +91,6 @@ static_library("core") {
# core and core_generated are really the same thing.
allow_circular_includes_from = [
":core_generated",
"//sky/engine/bindings",
]
}
source_set("core_generated") {
configs += [ "..:inside_blink" ]
deps = [
":make_core_generated",
":prerequisites",
"//skia",
"//sky/engine/platform",
"//sky/engine/wtf",
"//third_party/iccjpeg",
"//third_party/libpng",
"//third_party/qcms",
"//url",
]
include_dirs = [ "$root_build_dir" ]
}
# core_event_interfaces --------------------------------------------------------
# Calls generate_event_interfaces
#
# Parameters:
# sources = A list of IDL files to process.
# output_file = The .in file to write, relative to the sky_gen_dir.
# suffix = (Optional) String to be passed to script via --suffix
template("generate_event_interfaces") {
action(target_name) {
# Write the file list to a unique temp file to avoid blowing out the
# command line length limit.
idl_files_list = "$target_gen_dir/${target_name}_file_list.tmp"
write_file(idl_files_list, rebase_path(invoker.sources, root_build_dir))
inputs = [
"//sky/engine/bindings/scripts/utilities.py",
idl_files_list,
] + invoker.sources
output_file = "$root_gen_dir/sky/" + invoker.output_file
outputs = [
output_file,
]
script = "//sky/engine/bindings/scripts/generate_event_interfaces.py"
args = [
"--event-idl-files-list",
rebase_path(idl_files_list, root_build_dir),
"--event-interfaces-file",
rebase_path(output_file, root_build_dir),
"--write-file-only-if-changed=1", # Always true for Ninja.
]
if (defined(invoker.suffix)) {
args += [
"--suffix",
invoker.suffix,
]
}
}
}
generate_event_interfaces("core_event_interfaces") {
sources = core_event_idl_files
output_file = "core/EventInterfaces.in"
}
# make_core_generated ----------------------------------------------------------
group("core_names") {
deps = [
":make_core_generated_event_names",
":make_core_generated_event_type_names",
]
}
group("make_core_generated") {
deps = [
":core_names",
":make_core_generated_event_factory",
]
}
process_in_files("make_core_generated_event_factory") {
script = "../build/scripts/make_event_factory.py"
in_files = [
"$sky_core_output_dir/EventInterfaces.in",
"events/EventAliases.in",
]
other_inputs = make_event_factory_files
outputs = [
"$sky_core_output_dir/EventHeaders.h",
"$sky_core_output_dir/EventInterfaces.h",
]
deps = [
":core_names",
":libraries",
]
}
# make_names -------------------------------------------------------------------
make_names("make_core_generated_event_names") {
in_files = [ "$sky_core_output_dir/EventInterfaces.in" ]
outputs = [
"$sky_core_output_dir/EventNames.cpp",
"$sky_core_output_dir/EventNames.h",
]
}
make_names("make_core_generated_event_type_names") {
in_files = [ "events/EventTypeNames.in" ]
outputs = [
"$sky_core_output_dir/EventTypeNames.cpp",
"$sky_core_output_dir/EventTypeNames.h",
]
}
......@@ -30,8 +30,6 @@
#include "sky/engine/core/Init.h"
#include "gen/sky/core/EventNames.h"
#include "gen/sky/core/EventTypeNames.h"
#include "gen/sky/platform/FontFamilyNames.h"
#include "sky/engine/platform/Partitions.h"
#include "sky/engine/platform/PlatformThreadData.h"
......@@ -44,8 +42,6 @@ void CoreInitializer::init()
ASSERT(!m_isInited);
m_isInited = true;
EventNames::init();
EventTypeNames::init();
FontFamilyNames::init();
// It would make logical sense to do this in WTF::initialize() but there are
......
......@@ -27,19 +27,6 @@ sky_core_files = [
"editing/CompositionUnderline.h",
"editing/CompositionUnderlineRangeFilter.cpp",
"editing/CompositionUnderlineRangeFilter.h",
"events/Event.cpp",
"events/Event.h",
"events/EventSender.h",
"events/GestureVelocity.cpp",
"events/GestureVelocity.h",
"events/KeyboardEvent.cpp",
"events/KeyboardEvent.h",
"events/PointerEvent.cpp",
"events/PointerEvent.h",
"events/VelocityTracker.cpp",
"events/VelocityTracker.h",
"events/WheelEvent.cpp",
"events/WheelEvent.h",
"painting/Canvas.cpp",
"painting/Canvas.h",
"painting/CanvasColor.cpp",
......@@ -253,12 +240,6 @@ sky_core_files = [
core_idl_files = get_path_info([
"compositing/Scene.idl",
"compositing/SceneBuilder.idl",
"events/Event.idl",
"events/GestureVelocity.idl",
"events/KeyboardEvent.idl",
"events/PointerEvent.idl",
"events/VelocityTracker.idl",
"events/WheelEvent.idl",
"painting/Canvas.idl",
"painting/ColorFilter.idl",
"painting/Drawable.idl",
......@@ -306,12 +287,3 @@ core_dart_files = get_path_info([
"painting/VertexMode.dart",
],
"abspath")
# interfaces that inherit from Event, including Event itself
core_event_idl_files = get_path_info([
"events/Event.idl",
"events/KeyboardEvent.idl",
"events/PointerEvent.idl",
"events/WheelEvent.idl",
],
"abspath")
......@@ -20,9 +20,14 @@ void _updateWindowMetrics(double devicePixelRatio,
window.onMetricsChanged();
}
void _dispatchEvent(Event event) {
void _dispatchEvent(String eventType, double timeStamp) {
if (window.onEvent != null)
window.onEvent(event);
window.onEvent(eventType, timeStamp);
}
void _dispatchPointerPacket(ByteData serializedPacket) {
if (window.onPointerPacket != null)
window.onPointerPacket(serializedPacket);
}
void _beginFrame(int microseconds) {
......
......@@ -6,7 +6,8 @@ part of dart_ui;
typedef void VoidCallback();
typedef void _FrameCallback(Duration duration);
typedef void _EventCallback(Event event);
typedef void _EventCallback(String eventType, double timeStamp);
typedef void _PointerPacketCallback(ByteData serializedPacket);
class WindowPadding {
const WindowPadding._({ this.top, this.right, this.bottom, this.left });
......@@ -31,6 +32,7 @@ class Window {
_FrameCallback onBeginFrame;
_EventCallback onEvent;
_PointerPacketCallback onPointerPacket;
VoidCallback onMetricsChanged;
void scheduleFrame() native "Window_scheduleFrame";
......
/*
* Copyright (C) 2001 Peter Kelly (pmk@post.com)
* Copyright (C) 2001 Tobias Anton (anton@stud.fbi.fh-darmstadt.de)
* Copyright (C) 2006 Samuel Weinig (sam.weinig@gmail.com)
* Copyright (C) 2003, 2005, 2006, 2008 Apple Inc. All rights reserved.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Library General Public License for more details.
*
* You should have received a copy of the GNU Library General Public License
* along with this library; see the file COPYING.LIB. If not, write to
* the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
* Boston, MA 02110-1301, USA.
*/
#include "sky/engine/core/events/Event.h"
#include "gen/sky/core/EventHeaders.h"
#include "gen/sky/core/EventInterfaces.h"
#include "gen/sky/core/EventNames.h"
#include "sky/engine/wtf/CurrentTime.h"
namespace blink {
Event::Event()
: m_timeStamp(currentTimeMS())
, m_canBubble(false)
, m_cancelable(false)
, m_propagationStopped(false)
, m_immediatePropagationStopped(false)
, m_defaultPrevented(false)
, m_defaultHandled(false)
, m_cancelBubble(false)
, m_eventPhase(0)
{
}
Event::Event(const AtomicString& eventType, bool canBubbleArg, bool cancelableArg)
: m_timeStamp(currentTimeMS())
, m_type(eventType)
, m_canBubble(canBubbleArg)
, m_cancelable(cancelableArg)
, m_propagationStopped(false)
, m_immediatePropagationStopped(false)
, m_defaultPrevented(false)
, m_defaultHandled(false)
, m_cancelBubble(false)
, m_eventPhase(0)
{
}
Event::Event(const AtomicString& eventType, const EventInit& initializer)
: m_timeStamp(currentTimeMS())
, m_type(eventType)
, m_canBubble(initializer.bubbles)
, m_cancelable(initializer.cancelable)
, m_propagationStopped(false)
, m_immediatePropagationStopped(false)
, m_defaultPrevented(false)
, m_defaultHandled(false)
, m_cancelBubble(false)
, m_eventPhase(0)
{
}
Event::~Event()
{
}
void Event::initEvent(const AtomicString& eventTypeArg, bool canBubbleArg, bool cancelableArg)
{
m_propagationStopped = false;
m_immediatePropagationStopped = false;
m_defaultPrevented = false;
m_type = eventTypeArg;
m_canBubble = canBubbleArg;
m_cancelable = cancelableArg;
}
bool Event::legacyReturnValue() const
{
return !defaultPrevented();
}
void Event::setLegacyReturnValue(bool returnValue)
{
setDefaultPrevented(!returnValue);
}
const AtomicString& Event::interfaceName() const
{
return EventNames::Event;
}
bool Event::isKeyboardEvent() const
{
return false;
}
bool Event::isDragEvent() const
{
return false;
}
bool Event::isClipboardEvent() const
{
return false;
}
void Event::setUnderlyingEvent(PassRefPtr<Event> ue)
{
// Prohibit creation of a cycle -- just do nothing in that case.
for (Event* e = ue.get(); e; e = e->underlyingEvent())
if (e == this)
return;
m_underlyingEvent = ue;
}
} // namespace blink
/*
* Copyright (C) 2001 Peter Kelly (pmk@post.com)
* Copyright (C) 2001 Tobias Anton (anton@stud.fbi.fh-darmstadt.de)
* Copyright (C) 2006 Samuel Weinig (sam.weinig@gmail.com)
* Copyright (C) 2003, 2004, 2005, 2006, 2007, 2008 Apple Inc. All rights reserved.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Library General Public License for more details.
*
* You should have received a copy of the GNU Library General Public License
* along with this library; see the file COPYING.LIB. If not, write to
* the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
* Boston, MA 02110-1301, USA.
*
*/
#ifndef SKY_ENGINE_CORE_EVENTS_EVENT_H_
#define SKY_ENGINE_CORE_EVENTS_EVENT_H_
#include "sky/engine/tonic/dart_wrappable.h"
#include "sky/engine/platform/heap/Handle.h"
#include "sky/engine/wtf/RefCounted.h"
#include "sky/engine/wtf/text/AtomicString.h"
namespace blink {
class EventDispatcher;
class ExecutionContext;
struct EventInit {
bool bubbles = false;
bool cancelable = false;
private:
STACK_ALLOCATED();
};
class Event : public RefCounted<Event>, public DartWrappable {
DEFINE_WRAPPERTYPEINFO();
public:
enum PhaseType {
NONE = 0,
CAPTURING_PHASE = 1,
AT_TARGET = 2,
BUBBLING_PHASE = 3
};
static PassRefPtr<Event> create()
{
return adoptRef(new Event);
}
// A factory for a simple event. The event doesn't bubble, and isn't
// cancelable.
// http://www.whatwg.org/specs/web-apps/current-work/multipage/webappapis.html#fire-a-simple-event
static PassRefPtr<Event> create(const AtomicString& type, bool bubbles = false, bool cancelable = false)
{
return adoptRef(new Event(type, bubbles, cancelable));
}
static PassRefPtr<Event> createCancelable(const AtomicString& type)
{
return adoptRef(new Event(type, false, true));
}
static PassRefPtr<Event> createBubble(const AtomicString& type)
{
return adoptRef(new Event(type, true, false));
}
static PassRefPtr<Event> createCancelableBubble(const AtomicString& type)
{
return adoptRef(new Event(type, true, true));
}
static PassRefPtr<Event> create(const AtomicString& type, const EventInit& initializer)
{
return adoptRef(new Event(type, initializer));
}
virtual ~Event();
void initEvent(const AtomicString& type, bool canBubble, bool cancelable);
const AtomicString& type() const { return m_type; }
void setType(const AtomicString& type) { m_type = type; }
unsigned short eventPhase() const { return m_eventPhase; }
void setEventPhase(unsigned short eventPhase) { m_eventPhase = eventPhase; }
bool bubbles() const { return m_canBubble; }
bool cancelable() const { return m_cancelable; }
double timeStamp() const { return m_timeStamp; }
void stopPropagation() { m_propagationStopped = true; }
void stopImmediatePropagation() { m_immediatePropagationStopped = true; }
bool legacyReturnValue() const;
void setLegacyReturnValue(bool returnValue);
virtual const AtomicString& interfaceName() const;
// These events are general classes of events.
virtual bool isKeyboardEvent() const;
// Drag events are a subset of mouse events.
virtual bool isDragEvent() const;
// These events lack a DOM interface.
virtual bool isClipboardEvent() const;
bool propagationStopped() const { return m_propagationStopped || m_immediatePropagationStopped; }
bool immediatePropagationStopped() const { return m_immediatePropagationStopped; }
bool defaultPrevented() const { return m_defaultPrevented; }
virtual void preventDefault()
{
if (m_cancelable)
m_defaultPrevented = true;
}
void setDefaultPrevented(bool defaultPrevented) { m_defaultPrevented = defaultPrevented; }
bool defaultHandled() const { return m_defaultHandled; }
void setDefaultHandled() { m_defaultHandled = true; }
bool cancelBubble() const { return m_cancelBubble; }
void setCancelBubble(bool cancel) { m_cancelBubble = cancel; }
Event* underlyingEvent() const { return m_underlyingEvent.get(); }
void setUnderlyingEvent(PassRefPtr<Event>);
bool isBeingDispatched() const { return eventPhase(); }
protected:
Event();
Event(const AtomicString& type, bool canBubble, bool cancelable);
Event(const AtomicString& type, const EventInit&);
double m_timeStamp;
private:
AtomicString m_type;
bool m_canBubble;
bool m_cancelable;
bool m_propagationStopped;
bool m_immediatePropagationStopped;
bool m_defaultPrevented;
bool m_defaultHandled;
bool m_cancelBubble;
unsigned short m_eventPhase;
RefPtr<Event> m_underlyingEvent;
};
#define DEFINE_EVENT_TYPE_CASTS(typeName) \
DEFINE_TYPE_CASTS(typeName, Event, event, event->is##typeName(), event.is##typeName())
} // namespace blink
#endif // SKY_ENGINE_CORE_EVENTS_EVENT_H_
/*
* Copyright (C) 2006, 2007, 2009, 2011 Apple Inc. All rights reserved.
* Copyright (C) 2006 Samuel Weinig <sam.weinig@gmail.com>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Library General Public License for more details.
*
* You should have received a copy of the GNU Library General Public License
* along with this library; see the file COPYING.LIB. If not, write to
* the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
* Boston, MA 02110-1301, USA.
*/
// This is the object that Sky's C++ code uses to send events to Sky's
// Dart code.
// TODO(ianh): It needs much work still.
[
// TODO(eseidel): Type is optional to appease dart analyzer:
// The class 'Event' does not have a default constructor
Constructor([Named] optional DOMString type, [Named] optional boolean bubbles, [Named] optional boolean cancelable),
] interface Event {
readonly attribute DOMString type;
readonly attribute double timeStamp;
};
# Aliases
Events ImplementedAs=Event
HTMLEvents ImplementedAs=Event
KeyboardEvents ImplementedAs=KeyboardEvent
OrientationEvent ImplementedAs=Event, RuntimeEnabled=OrientationEventEnabled
SVGEvents ImplementedAs=Event
/*
* Copyright (C) 2012 Apple Inc. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
* THE POSSIBILITY OF SUCH DAMAGE.
*/
#ifndef SKY_ENGINE_CORE_EVENTS_EVENTSENDER_H_
#define SKY_ENGINE_CORE_EVENTS_EVENTSENDER_H_
#include "sky/engine/platform/Timer.h"
#include "sky/engine/wtf/Vector.h"
#include "sky/engine/wtf/text/AtomicString.h"
namespace blink {
template<typename T> class EventSender {
WTF_MAKE_NONCOPYABLE(EventSender); WTF_MAKE_FAST_ALLOCATED;
public:
explicit EventSender(const AtomicString& eventType);
const AtomicString& eventType() const { return m_eventType; }
void dispatchEventSoon(T*);
void cancelEvent(T*);
void dispatchPendingEvents();
#if ENABLE(ASSERT)
bool hasPendingEvents(T* sender) const
{
return m_dispatchSoonList.find(sender) != kNotFound || m_dispatchingList.find(sender) != kNotFound;
}
#endif
private:
void timerFired(Timer<EventSender<T> >*) { dispatchPendingEvents(); }
AtomicString m_eventType;
Timer<EventSender<T> > m_timer;
Vector<RawPtr<T> > m_dispatchSoonList;
Vector<RawPtr<T> > m_dispatchingList;
};
template<typename T> EventSender<T>::EventSender(const AtomicString& eventType)
: m_eventType(eventType)
, m_timer(this, &EventSender::timerFired)
{
}
template<typename T> void EventSender<T>::dispatchEventSoon(T* sender)
{
m_dispatchSoonList.append(sender);
if (!m_timer.isActive())
m_timer.startOneShot(0, FROM_HERE);
}
template<typename T> void EventSender<T>::cancelEvent(T* sender)
{
// Remove instances of this sender from both lists.
// Use loops because we allow multiple instances to get into the lists.
size_t size = m_dispatchSoonList.size();
for (size_t i = 0; i < size; ++i) {
if (m_dispatchSoonList[i] == sender)
m_dispatchSoonList[i] = nullptr;
}
size = m_dispatchingList.size();
for (size_t i = 0; i < size; ++i) {
if (m_dispatchingList[i] == sender)
m_dispatchingList[i] = nullptr;
}
}
template<typename T> void EventSender<T>::dispatchPendingEvents()
{
// Need to avoid re-entering this function; if new dispatches are
// scheduled before the parent finishes processing the list, they
// will set a timer and eventually be processed.
if (!m_dispatchingList.isEmpty())
return;
m_timer.stop();
m_dispatchingList.swap(m_dispatchSoonList);
size_t size = m_dispatchingList.size();
for (size_t i = 0; i < size; ++i) {
if (T* sender = m_dispatchingList[i]) {
m_dispatchingList[i] = nullptr;
sender->dispatchPendingEvent(this);
}
}
m_dispatchingList.clear();
}
} // namespace blink
#endif // SKY_ENGINE_CORE_EVENTS_EVENTSENDER_H_
namespace="EventType"
DOMActivate
DOMContentLoaded
abort
animationend
animationiteration
animationstart
beforecopy
beforecut
beforepaste
boundary
cached
cancel
candidatewindowhide
candidatewindowshow
candidatewindowupdate
change
click
compositionend
compositionstart
compositionupdate
contextlost
contextrestored
copy
cut
dblclick
disconnect
display
downloading
drag
dragend
dragenter
dragleave
dragover
dragstart
drop
enter
error
exit
fetch
finish
gesturescrollend
gesturescrollstart
gesturescrollupdate
gestureflingstart
gestureflingcancel
gestureshowpress
gesturetap
gesturetapdown
gesturetapunconfirmed
gesturetapcancel
gesturedoubletap
gesturetwofingertap
gesturelongpress
gesturelongtap
gesturepinchstart
gesturepinchend
gesturepinchupdate
hashchange
input
invalid
keydown
keypress
keyup
languagechange
load
loading
loadingdone
loadingerror
message
mute
offline
online
open
orientationchange
overflowchanged
pagehide
pageshow
paste
pointercancel
pointerdown
pointermove
pointerup
popstate
progress
push
ready
readystatechange
reset
resize
result
resume
scroll
search
securitypolicyviolation
select
selectionchange
selectstart
show
submit
success
textInput
timeout
toggle
tonechange
transitionend
unload
visibilitychange
webglcontextcreationerror
webglcontextlost
webglcontextrestored
webkitBeforeTextInserted
webkitEditableContentChanged
webkitkeyadded
webkitkeyerror
webkitkeymessage
webkitneedkey
webkitvisibilitychange
wheel
// Copyright 2015 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "sky/engine/core/events/GestureVelocity.h"
namespace blink {
GestureVelocity::GestureVelocity(bool valid, float x, float y)
: m_is_valid(valid), m_x(x), m_y(y)
{
}
} // namespace blink
// Copyright 2014 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef SKY_ENGINE_CORE_EVENTS_GESTURE_VELOCITY_H_
#define SKY_ENGINE_CORE_EVENTS_GESTURE_VELOCITY_H_
#include "sky/engine/tonic/dart_wrappable.h"
#include "sky/engine/wtf/PassRefPtr.h"
#include "sky/engine/wtf/RefCounted.h"
namespace blink {
class GestureVelocity final : public RefCounted<GestureVelocity>, public DartWrappable {
DEFINE_WRAPPERTYPEINFO();
public:
static PassRefPtr<GestureVelocity> create(bool valid, float x, float y)
{
return adoptRef(new GestureVelocity(valid, x, y));
}
bool isValid() const { return m_is_valid; }
float x() const { return m_x; }
float y() const { return m_y; }
private:
GestureVelocity(bool valid, float x, float y);
bool m_is_valid;
float m_x;
float m_y;
};
} // namespace blink
#endif // SKY_ENGINE_CORE_EVENTS_GESTURE_VELOCITY_H_
// Copyright 2015 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
interface GestureVelocity {
readonly attribute boolean isValid; // If false, x,y = 0
readonly attribute float x; // logical pixels / second
readonly attribute float y; // logical pixels / second
};
// Copyright 2015 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "sky/engine/core/events/KeyboardEvent.h"
#include "gen/sky/core/EventNames.h"
#include "gen/sky/core/EventTypeNames.h"
namespace blink {
static AtomicString stringForType(WebInputEvent::Type type)
{
if (type == WebInputEvent::KeyDown)
return EventTypeNames::keydown;
if (type == WebInputEvent::Char)
return EventTypeNames::keypress;
if (type == WebInputEvent::KeyUp)
return EventTypeNames::keyup;
ASSERT_NOT_REACHED();
return AtomicString();
}
static String locationFromModifiers(int modifiers)
{
if (modifiers & WebInputEvent::IsKeyPad)
return "numpad";
if (modifiers & WebInputEvent::IsLeft)
return "left";
if (modifiers & WebInputEvent::IsRight)
return "right";
return "standard";
}
KeyboardEvent::~KeyboardEvent()
{
}
const AtomicString& KeyboardEvent::interfaceName() const
{
return EventNames::KeyboardEvent;
}
bool KeyboardEvent::isKeyboardEvent() const
{
return true;
}
KeyboardEvent::KeyboardEvent()
: KeyboardEvent(AtomicString(), KeyboardEventInit())
{
}
KeyboardEvent::KeyboardEvent(const WebKeyboardEvent& event)
: Event(stringForType(event.type), true, true)
, m_key(event.key)
, m_location(locationFromModifiers(event.modifiers))
, m_charCode(event.charCode)
, m_ctrlKey(event.modifiers & WebInputEvent::ControlKey)
, m_shiftKey(event.modifiers & WebInputEvent::ShiftKey)
, m_altKey(event.modifiers & WebInputEvent::AltKey)
, m_metaKey(event.modifiers & WebInputEvent::MetaKey)
, m_repeat(event.modifiers & WebInputEvent::IsAutoRepeat)
{
m_timeStamp = event.timeStampMS;
if (event.type == WebInputEvent::KeyDown || event.type == WebInputEvent::KeyUp) {
m_charCode = 0;
} else if (event.type == WebInputEvent::Char) {
m_key = 0;
m_location = String();
}
}
KeyboardEvent::KeyboardEvent(const AtomicString& type, const KeyboardEventInit& initializer)
: Event(type, initializer)
, m_key(initializer.key)
, m_location(initializer.location)
, m_charCode(initializer.charCode)
, m_ctrlKey(initializer.ctrlKey)
, m_shiftKey(initializer.shiftKey)
, m_altKey(initializer.altKey)
, m_metaKey(initializer.metaKey)
, m_repeat(initializer.repeat)
{
}
} // namespace blink
// Copyright 2015 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef SKY_ENGINE_CORE_EVENTS_KEYBOARDEVENT_H_
#define SKY_ENGINE_CORE_EVENTS_KEYBOARDEVENT_H_
#include "sky/engine/core/events/Event.h"
#include "sky/engine/public/platform/WebInputEvent.h"
namespace blink {
struct KeyboardEventInit : public EventInit {
unsigned key = 0;
String location;
unsigned charCode = 0;
bool ctrlKey = false;
bool shiftKey = false;
bool altKey = false;
bool metaKey = false;
bool repeat = false;
};
class KeyboardEvent : public Event {
DEFINE_WRAPPERTYPEINFO();
public:
static PassRefPtr<KeyboardEvent> create()
{
return adoptRef(new KeyboardEvent);
}
static PassRefPtr<KeyboardEvent> create(const WebKeyboardEvent& event)
{
return adoptRef(new KeyboardEvent(event));
}
static PassRefPtr<KeyboardEvent> create(const AtomicString& type, const KeyboardEventInit& initializer)
{
return adoptRef(new KeyboardEvent(type, initializer));
}
~KeyboardEvent() override;
const AtomicString& interfaceName() const override;
bool isKeyboardEvent() const override;
unsigned key() const { return m_key; }
const String& location() const { return m_location; }
unsigned charCode() const { return m_charCode; }
bool ctrlKey() const { return m_ctrlKey; }
bool shiftKey() const { return m_shiftKey; }
bool altKey() const { return m_altKey; }
bool metaKey() const { return m_metaKey; }
bool repeat() const { return m_repeat; }
private:
KeyboardEvent();
explicit KeyboardEvent(const WebKeyboardEvent& event);
KeyboardEvent(const AtomicString&, const KeyboardEventInit&);
unsigned m_key;
String m_location;
unsigned m_charCode;
bool m_ctrlKey;
bool m_shiftKey;
bool m_altKey;
bool m_metaKey;
bool m_repeat;
};
DEFINE_EVENT_TYPE_CASTS(KeyboardEvent);
} // namespace blink
#endif // SKY_ENGINE_CORE_EVENTS_KEYBOARDEVENT_H_
// Copyright 2015 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
[
EventConstructor,
] interface KeyboardEvent : Event {
// For keydown and keyup events:
[InitializedByEventConstructor] readonly attribute long key;
[InitializedByEventConstructor] readonly attribute DOMString location;
// For keypress events:
[InitializedByEventConstructor] readonly attribute long charCode;
[InitializedByEventConstructor] readonly attribute boolean ctrlKey;
[InitializedByEventConstructor] readonly attribute boolean shiftKey;
[InitializedByEventConstructor] readonly attribute boolean altKey;
[InitializedByEventConstructor] readonly attribute boolean metaKey;
[InitializedByEventConstructor] readonly attribute boolean repeat;
};
// Copyright 2015 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "sky/engine/core/events/PointerEvent.h"
#include "gen/sky/core/EventNames.h"
#include "gen/sky/core/EventTypeNames.h"
namespace blink {
static AtomicString stringForType(WebInputEvent::Type type)
{
if (type == WebInputEvent::PointerDown)
return EventTypeNames::pointerdown;
if (type == WebInputEvent::PointerUp)
return EventTypeNames::pointerup;
if (type == WebInputEvent::PointerMove)
return EventTypeNames::pointermove;
if (type == WebInputEvent::PointerCancel)
return EventTypeNames::pointercancel;
ASSERT_NOT_REACHED();
return AtomicString();
}
static String stringForKind(WebPointerEvent::Kind kind)
{
switch (kind) {
case WebPointerEvent::Touch:
return "touch";
case WebPointerEvent::Mouse:
return "mouse";
case WebPointerEvent::Stylus:
return "stylus";
}
ASSERT_NOT_REACHED();
return String();
}
PointerEvent::~PointerEvent()
{
}
const AtomicString& PointerEvent::interfaceName() const
{
return EventNames::PointerEvent;
}
PointerEvent::PointerEvent()
: PointerEvent(AtomicString(), PointerEventInit())
{
}
PointerEvent::PointerEvent(const WebPointerEvent& event)
: Event(stringForType(event.type), true, true)
, m_pointer(event.pointer)
, m_kind(stringForKind(event.kind))
, m_x(event.x)
, m_y(event.y)
, m_dx(0)
, m_dy(0)
, m_buttons(event.buttons)
, m_down(false)
, m_primary(false)
, m_obscured(false)
, m_pressure(event.pressure)
, m_pressureMin(event.pressureMin)
, m_pressureMax(event.pressureMax)
, m_distance(event.distance)
, m_distanceMin(event.distanceMin)
, m_distanceMax(event.distanceMax)
, m_radiusMajor(event.radiusMajor)
, m_radiusMinor(event.radiusMinor)
, m_radiusMin(event.radiusMin)
, m_radiusMax(event.radiusMax)
, m_orientation(event.orientation)
, m_tilt(event.tilt)
{
m_timeStamp = event.timeStampMS;
}
PointerEvent::PointerEvent(const AtomicString& type, const PointerEventInit& initializer)
: Event(type, initializer)
, m_pointer(initializer.pointer)
, m_kind(initializer.kind)
, m_x(initializer.x)
, m_y(initializer.y)
, m_dx(initializer.dx)
, m_dy(initializer.dy)
, m_buttons(initializer.buttons)
, m_down(initializer.down)
, m_primary(initializer.primary)
, m_obscured(initializer.obscured)
, m_pressure(initializer.pressure)
, m_pressureMin(initializer.pressureMin)
, m_pressureMax(initializer.pressureMax)
, m_distance(initializer.distance)
, m_distanceMin(initializer.distanceMin)
, m_distanceMax(initializer.distanceMax)
, m_radiusMajor(initializer.radiusMajor)
, m_radiusMinor(initializer.radiusMinor)
, m_radiusMin(initializer.radiusMin)
, m_radiusMax(initializer.radiusMax)
, m_orientation(initializer.orientation)
, m_tilt(initializer.tilt)
{
}
} // namespace blink
// Copyright 2015 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef SKY_ENGINE_CORE_EVENTS_POINTEREVENT_H_
#define SKY_ENGINE_CORE_EVENTS_POINTEREVENT_H_
#include "sky/engine/core/events/Event.h"
#include "sky/engine/public/platform/WebInputEvent.h"
namespace blink {
struct PointerEventInit : public EventInit {
int pointer = 0;
String kind;
double x = 0;
double y = 0;
double dx = 0;
double dy = 0;
int buttons = 0;
bool down = false;
bool primary = false;
bool obscured = false;
double pressure = 0;
double pressureMin = 0;
double pressureMax = 0;
double distance = 0;
double distanceMin = 0;
double distanceMax = 0;
double radiusMajor = 0;
double radiusMinor = 0;
double radiusMin = 0;
double radiusMax = 0;
double orientation = 0;
double tilt = 0;
};
class PointerEvent : public Event {
DEFINE_WRAPPERTYPEINFO();
public:
static PassRefPtr<PointerEvent> create()
{
return adoptRef(new PointerEvent);
}
static PassRefPtr<PointerEvent> create(const WebPointerEvent& event)
{
return adoptRef(new PointerEvent(event));
}
static PassRefPtr<PointerEvent> create(const AtomicString& type, const PointerEventInit& initializer)
{
return adoptRef(new PointerEvent(type, initializer));
}
~PointerEvent() override;
const AtomicString& interfaceName() const override;
int pointer() const { return m_pointer; }
const String& kind() const { return m_kind; }
double x() const { return m_x; }
double y() const { return m_y; }
double dx() const { return m_dx; }
double dy() const { return m_dy; }
int buttons() const { return m_buttons; }
bool down() const { return m_down; }
bool primary() const { return m_primary; }
bool obscured() const { return m_obscured; }
double pressure() const { return m_pressure; }
double pressureMin() const { return m_pressureMin; }
double pressureMax() const { return m_pressureMax; }
double distance() const { return m_distance; }
double distanceMin() const { return m_distanceMin; }
double distanceMax() const { return m_distanceMax; }
double radiusMajor() const { return m_radiusMajor; }
double radiusMinor() const { return m_radiusMinor; }
double radiusMin() const { return m_radiusMin; }
double radiusMax() const { return m_radiusMax; }
double orientation() const { return m_orientation; }
double tilt() const { return m_tilt; }
void setDx(double dx) { m_dx = dx; }
void setDy(double dy) { m_dy = dy; }
private:
PointerEvent();
explicit PointerEvent(const WebPointerEvent& event);
PointerEvent(const AtomicString&, const PointerEventInit&);
int m_pointer;
String m_kind;
double m_x;
double m_y;
double m_dx;
double m_dy;
int m_buttons;
bool m_down;
bool m_primary;
bool m_obscured;
double m_pressure;
double m_pressureMin;
double m_pressureMax;
double m_distance;
double m_distanceMin;
double m_distanceMax;
double m_radiusMajor;
double m_radiusMinor;
double m_radiusMin;
double m_radiusMax;
double m_orientation;
double m_tilt;
};
} // namespace blink
#endif // SKY_ENGINE_CORE_EVENTS_POINTEREVENT_H_
// Copyright 2015 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
[
EventConstructor,
] interface PointerEvent : Event {
[InitializedByEventConstructor] readonly attribute long pointer;
[InitializedByEventConstructor] readonly attribute DOMString kind;
[InitializedByEventConstructor] readonly attribute double x;
[InitializedByEventConstructor] readonly attribute double y;
[InitializedByEventConstructor] attribute double dx;
[InitializedByEventConstructor] attribute double dy;
[InitializedByEventConstructor] readonly attribute long buttons;
[InitializedByEventConstructor] readonly attribute boolean down;
[InitializedByEventConstructor] readonly attribute boolean primary;
[InitializedByEventConstructor] readonly attribute boolean obscured;
[InitializedByEventConstructor] readonly attribute double pressure;
[InitializedByEventConstructor] readonly attribute double pressureMin;
[InitializedByEventConstructor] readonly attribute double pressureMax;
[InitializedByEventConstructor] readonly attribute double distance;
[InitializedByEventConstructor] readonly attribute double distanceMin;
[InitializedByEventConstructor] readonly attribute double distanceMax;
[InitializedByEventConstructor] readonly attribute double radiusMajor;
[InitializedByEventConstructor] readonly attribute double radiusMinor;
[InitializedByEventConstructor] readonly attribute double radiusMin;
[InitializedByEventConstructor] readonly attribute double radiusMax;
[InitializedByEventConstructor] readonly attribute double orientation;
[InitializedByEventConstructor] readonly attribute double tilt;
};
此差异已折叠。
// Copyright 2014 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// This file is a largely a copy of ui/events/gesture_detection/velocity_tracker.h
// and ui/events/gesture_detection/bitset_32.h from https://chromium.googlesource.com.
// The VelocityTracker::AddMovement(const MotionEvent& event) method and a
// few of its supporting definitions have been removed.
#ifndef SKY_ENGINE_CORE_EVENTS_VELOCITY_TRACKER_H_
#define SKY_ENGINE_CORE_EVENTS_VELOCITY_TRACKER_H_
#include <stdint.h>
#include "base/memory/scoped_ptr.h"
#include "base/time/time.h"
#include "sky/engine/core/events/GestureVelocity.h"
#include "sky/engine/tonic/dart_wrappable.h"
#include "sky/engine/wtf/OwnPtr.h"
#include "sky/engine/wtf/PassRefPtr.h"
#include "sky/engine/wtf/RefCounted.h"
namespace blink {
class PointerEvent;
class VelocityTrackerStrategy;
namespace {
struct Estimator;
struct PointerXY;
}
// Port of VelocityTracker from Android
// * platform/frameworks/native/include/input/VelocityTracker.h
// * Change-Id: I4983db61b53e28479fc90d9211fafff68f7f49a6
// * Please update the Change-Id as upstream Android changes are pulled.
class VelocityTracker : public RefCounted<VelocityTracker>, public DartWrappable {
DEFINE_WRAPPERTYPEINFO();
public:
enum Strategy {
// 1st order least squares. Quality: POOR.
// Frequently underfits the touch data especially when the finger
// accelerates or changes direction. Often underestimates velocity. The
// direction is overly influenced by historical touch points.
LSQ1,
// 2nd order least squares. Quality: VERY GOOD.
// Pretty much ideal, but can be confused by certain kinds of touch data,
// particularly if the panel has a tendency to generate delayed,
// duplicate or jittery touch coordinates when the finger is released.
LSQ2,
// 3rd order least squares. Quality: UNUSABLE.
// Frequently overfits the touch data yielding wildly divergent estimates
// of the velocity when the finger is released.
LSQ3,
// 2nd order weighted least squares, delta weighting.
// Quality: EXPERIMENTAL
WLSQ2_DELTA,
// 2nd order weighted least squares, central weighting.
// Quality: EXPERIMENTAL
WLSQ2_CENTRAL,
// 2nd order weighted least squares, recent weighting.
// Quality: EXPERIMENTAL
WLSQ2_RECENT,
// 1st order integrating filter. Quality: GOOD.
// Not as good as 'lsq2' because it cannot estimate acceleration but it is
// more tolerant of errors. Like 'lsq1', this strategy tends to
// underestimate
// the velocity of a fling but this strategy tends to respond to changes in
// direction more quickly and accurately.
INT1,
// 2nd order integrating filter. Quality: EXPERIMENTAL.
// For comparison purposes only. Unlike 'int1' this strategy can compensate
// for acceleration but it typically overestimates the effect.
INT2,
STRATEGY_MAX = INT2,
// The default velocity tracker strategy.
// Although other strategies are available for testing and comparison
// purposes, this is the strategy that applications will actually use. Be
// very careful when adjusting the default strategy because it can
// dramatically affect (often in a bad way) the user experience.
STRATEGY_DEFAULT = LSQ2,
};
// VelocityTracker IDL implementation
static PassRefPtr<VelocityTracker> create() {
return adoptRef(new VelocityTracker());
}
void reset();
void addPosition(int timeStamp, float x, float y);
PassRefPtr<GestureVelocity> getVelocity();
// Creates a velocity tracker using the default strategy for the platform.
VelocityTracker();
// Creates a velocity tracker using the specified strategy.
// If strategy is NULL, uses the default strategy for the platform.
explicit VelocityTracker(Strategy strategy);
~VelocityTracker();
// Resets the velocity tracker state.
void Clear();
// Adds movement information for all pointers in a PointerEvent, including
// historical samples.
// void AddMovement(const PointerEvent& event);
// Gets the velocity of the specified pointer id in position units per second.
// Returns false and sets the velocity components to zero if there is
// insufficient movement information for the pointer.
bool GetVelocity(float* outVx, float* outVy) const;
private:
// Adds movement information for a pointer.
// The id specifies the pointer id of the pointer whose position is included
// in the movement.
// position specifies the position information for the pointer.
void AddMovement(const base::TimeTicks& event_time,
const PointerXY &position);
// Gets an estimator for the recent movements of the specified pointer id.
// Returns false and clears the estimator if there is no information available
// about the pointer.
bool GetEstimator(Estimator* out_estimator) const;
base::TimeTicks last_event_time_;
scoped_ptr<VelocityTrackerStrategy> strategy_;
DISALLOW_COPY_AND_ASSIGN(VelocityTracker);
};
} // namespace blink
#endif // SKY_ENGINE_CORE_EVENTS_VELOCITY_TRACKER_H_
// Copyright 2014 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
[
Constructor(),
] interface VelocityTracker {
void addPosition(long timeStamp, float x, float y);
GestureVelocity getVelocity();
void reset();
};
// Copyright 2015 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "sky/engine/core/events/WheelEvent.h"
#include "gen/sky/core/EventNames.h"
#include "gen/sky/core/EventTypeNames.h"
namespace blink {
WheelEvent::~WheelEvent()
{
}
const AtomicString& WheelEvent::interfaceName() const
{
return EventNames::WheelEvent;
}
WheelEvent::WheelEvent()
: WheelEvent(AtomicString(), WheelEventInit())
{
}
WheelEvent::WheelEvent(const WebWheelEvent& event)
: Event(EventTypeNames::wheel, true, true)
, m_x(event.x)
, m_y(event.y)
, m_offsetX(event.offsetX)
, m_offsetY(event.offsetY)
{
m_timeStamp = event.timeStampMS;
}
WheelEvent::WheelEvent(const AtomicString& type, const WheelEventInit& initializer)
: Event(type, initializer)
, m_x(initializer.x)
, m_y(initializer.y)
, m_offsetX(initializer.offsetX)
, m_offsetY(initializer.offsetY)
{
}
} // namespace blink
// Copyright 2015 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef SKY_ENGINE_CORE_EVENTS_WHEELEVENT_H_
#define SKY_ENGINE_CORE_EVENTS_WHEELEVENT_H_
#include "sky/engine/core/events/Event.h"
#include "sky/engine/public/platform/WebInputEvent.h"
namespace blink {
struct WheelEventInit : public EventInit {
double x = 0;
double y = 0;
double offsetX = 0;
double offsetY = 0;
};
class WheelEvent : public Event {
DEFINE_WRAPPERTYPEINFO();
public:
static PassRefPtr<WheelEvent> create()
{
return adoptRef(new WheelEvent);
}
static PassRefPtr<WheelEvent> create(const WebWheelEvent& event)
{
return adoptRef(new WheelEvent(event));
}
static PassRefPtr<WheelEvent> create(const AtomicString& type, const WheelEventInit& initializer)
{
return adoptRef(new WheelEvent(type, initializer));
}
~WheelEvent() override;
const AtomicString& interfaceName() const override;
double x() const { return m_x; }
double y() const { return m_y; }
double offsetX() const { return m_offsetX; }
double offsetY() const { return m_offsetY; }
private:
WheelEvent();
explicit WheelEvent(const WebWheelEvent& event);
WheelEvent(const AtomicString&, const WheelEventInit&);
double m_x;
double m_y;
double m_offsetX;
double m_offsetY;
};
} // namespace blink
#endif // SKY_ENGINE_CORE_EVENTS_WHEELEVENT_H_
// Copyright 2015 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
[
EventConstructor,
] interface WheelEvent : Event {
[InitializedByEventConstructor] readonly attribute double x;
[InitializedByEventConstructor] readonly attribute double y;
[InitializedByEventConstructor] readonly attribute double offsetX;
[InitializedByEventConstructor] readonly attribute double offsetY;
};
......@@ -5,7 +5,6 @@
#include "sky/engine/core/window/window.h"
#include "sky/engine/core/compositing/Scene.h"
#include "sky/engine/core/events/Event.h"
#include "sky/engine/core/script/dom_dart_state.h"
#include "sky/engine/public/platform/sky_display_metrics.h"
#include "sky/engine/tonic/dart_converter.h"
......@@ -67,17 +66,42 @@ void Window::UpdateWindowMetrics(const SkyDisplayMetrics& metrics) {
});
}
void Window::DispatchEvent(Event* event) {
void Window::DispatchEvent(const String& event_type, double time_stamp) {
DartState* dart_state = library_.dart_state().get();
if (!dart_state)
return;
DartState::Scope scope(dart_state);
DartInvokeField(library_.value(), "_dispatchEvent", {
ToDart(event),
DartConverter<String>::ToDart(dart_state, event_type),
ToDart(time_stamp)
});
}
void Window::DispatchPointerPacket(const pointer::PointerPacketPtr& packet) {
DartState* dart_state = library_.dart_state().get();
if (!dart_state)
return;
DartState::Scope scope(dart_state);
Dart_Handle data_handle = Dart_NewTypedData(Dart_TypedData_kByteData,
packet->GetSerializedSize());
if (Dart_IsError(data_handle))
return;
Dart_TypedData_Type type;
void* data;
intptr_t len;
if (Dart_IsError(Dart_TypedDataAcquireData(data_handle, &type, &data, &len)))
return;
packet->Serialize(data, len);
Dart_TypedDataReleaseData(data_handle);
DartInvokeField(library_.value(), "_dispatchPointerPacket", {data_handle});
}
void Window::BeginFrame(base::TimeTicks frameTime) {
DartState* dart_state = library_.dart_state().get();
if (!dart_state)
......
......@@ -7,9 +7,10 @@
#include "base/time/time.h"
#include "sky/engine/tonic/dart_persistent_value.h"
#include "sky/engine/wtf/text/WTFString.h"
#include "sky/services/pointer/pointer.mojom.h"
namespace blink {
class Event;
class Scene;
struct SkyDisplayMetrics;
class DartLibraryNatives;
......@@ -32,7 +33,8 @@ class Window {
void DidCreateIsolate();
void UpdateWindowMetrics(const SkyDisplayMetrics& metrics);
void DispatchEvent(Event* event);
void DispatchEvent(const String& event_type, double time_stamp);
void DispatchPointerPacket(const pointer::PointerPacketPtr& packet);
void BeginFrame(base::TimeTicks frameTime);
static void RegisterNatives(DartLibraryNatives* natives);
......
......@@ -12,6 +12,7 @@ source_set("sky") {
"//sky/engine/core",
"//sky/engine/platform",
"//sky/engine/wtf",
"//sky/services/pointer:interfaces",
]
configs += [
......
......@@ -7,9 +7,6 @@
#include "base/bind.h"
#include "base/trace_event/trace_event.h"
#include "sky/engine/core/compositing/Scene.h"
#include "sky/engine/core/events/KeyboardEvent.h"
#include "sky/engine/core/events/PointerEvent.h"
#include "sky/engine/core/events/WheelEvent.h"
#include "sky/engine/core/script/dart_controller.h"
#include "sky/engine/core/script/dom_dart_state.h"
#include "sky/engine/core/window/window.h"
......@@ -74,23 +71,14 @@ std::unique_ptr<sky::compositor::LayerTree> SkyView::BeginFrame(
void SkyView::HandleInputEvent(const WebInputEvent& inputEvent) {
TRACE_EVENT0("input", "SkyView::HandleInputEvent");
RefPtr<Event> event;
if (WebInputEvent::isPointerEventType(inputEvent.type)) {
const WebPointerEvent& webEvent = static_cast<const WebPointerEvent&>(inputEvent);
event = PointerEvent::create(webEvent);
} else if (WebInputEvent::isKeyboardEventType(inputEvent.type)) {
const WebKeyboardEvent& webEvent = static_cast<const WebKeyboardEvent&>(inputEvent);
event = KeyboardEvent::create(webEvent);
} else if (WebInputEvent::isWheelEventType(inputEvent.type)) {
const WebWheelEvent& webEvent = static_cast<const WebWheelEvent&>(inputEvent);
event = WheelEvent::create(webEvent);
} else if (inputEvent.type == WebInputEvent::Back) {
event = Event::create("back");
if (inputEvent.type == WebInputEvent::Back) {
GetWindow()->DispatchEvent("back", inputEvent.timeStampMS);
}
}
if (event)
GetWindow()->DispatchEvent(event.get());
void SkyView::HandlePointerPacket(const pointer::PointerPacketPtr& packet) {
TRACE_EVENT0("input", "SkyView::HandlePointerPacket");
GetWindow()->DispatchPointerPacket(packet);
}
Window* SkyView::GetWindow() {
......
......@@ -19,6 +19,7 @@
#include "sky/engine/wtf/OwnPtr.h"
#include "sky/engine/wtf/RefPtr.h"
#include "sky/engine/wtf/text/WTFString.h"
#include "sky/services/pointer/pointer.mojom.h"
#include "third_party/skia/include/core/SkPicture.h"
namespace blink {
......@@ -50,6 +51,7 @@ class SkyView : public WindowClient {
mojo::ScopedDataPipeConsumerHandle snapshot);
void HandleInputEvent(const WebInputEvent& event);
void HandlePointerPacket(const pointer::PointerPacketPtr& packet);
void StartDartTracing();
void StopDartTracing(mojo::ScopedDataPipeProducerHandle producer);
......
......@@ -7,41 +7,12 @@ module sky;
enum EventType {
UNKNOWN,
POINTER_CANCEL,
POINTER_DOWN,
POINTER_MOVE,
POINTER_UP,
BACK,
};
enum PointerKind {
TOUCH,
};
struct PointerData {
int32 pointer;
PointerKind kind;
float x;
float y;
int32 buttons;
float pressure;
float pressure_min;
float pressure_max;
float distance;
float distance_min;
float distance_max;
float radius_major;
float radius_minor;
float radius_min;
float radius_max;
float orientation;
float tilt;
};
// TODO(abarth): Should we have a malloc-free way of creating an input event
// message? What we have now could stress out the Android Java GC.
struct InputEvent {
EventType type;
int64 time_stamp;
PointerData? pointer_data;
};
......@@ -67,8 +67,6 @@ source_set("common") {
"ui/animator.h",
"ui/engine.cc",
"ui/engine.h",
"ui/input_event_converter.cc",
"ui/input_event_converter.h",
"ui/internals.cc",
"ui/internals.h",
"ui/platform_impl.cc",
......@@ -152,6 +150,7 @@ if (is_android) {
"//sky/services/media:interfaces_java",
"//sky/services/media:media_lib",
"//sky/services/oknet",
"//sky/services/pointer:interfaces_java",
"//sky/services/updater:interfaces_java",
"//sky/services/vsync:interfaces_java",
"//sky/services/vsync:vsync_lib",
......
......@@ -21,13 +21,16 @@ import org.chromium.mojo.keyboard.KeyboardServiceState;
import org.chromium.mojo.system.Core;
import org.chromium.mojo.system.Pair;
import org.chromium.mojo.system.impl.CoreImpl;
import org.chromium.mojom.sky.EventType;
import org.chromium.mojom.sky.InputEvent;
import org.chromium.mojom.sky.PointerData;
import org.chromium.mojom.sky.PointerKind;
import org.chromium.mojom.pointer.Pointer;
import org.chromium.mojom.pointer.PointerKind;
import org.chromium.mojom.pointer.PointerPacket;
import org.chromium.mojom.pointer.PointerType;
import org.chromium.mojom.sky.SkyEngine;
import org.chromium.mojom.sky.ViewportMetrics;
import java.util.ArrayList;
import java.util.List;
/**
* A view containing Sky
*/
......@@ -124,50 +127,71 @@ public class PlatformViewAndroid extends SurfaceView {
return mKeyboardState.createInputConnection(outAttrs);
}
private int getTypeForAction(int maskedAction) {
private Integer getPointerTypeForAction(int maskedAction) {
// Primary pointer:
if (maskedAction == MotionEvent.ACTION_DOWN) {
return EventType.POINTER_DOWN;
return PointerType.DOWN;
}
if (maskedAction == MotionEvent.ACTION_UP) {
return EventType.POINTER_UP;
return PointerType.UP;
}
// Secondary pointer:
if (maskedAction == MotionEvent.ACTION_POINTER_DOWN) {
return EventType.POINTER_DOWN;
return PointerType.DOWN;
}
if (maskedAction == MotionEvent.ACTION_POINTER_UP) {
return EventType.POINTER_UP;
return PointerType.UP;
}
// All pointers:
if (maskedAction == MotionEvent.ACTION_MOVE) {
return EventType.POINTER_MOVE;
return PointerType.MOVE;
}
if (maskedAction == MotionEvent.ACTION_CANCEL) {
return EventType.POINTER_CANCEL;
return PointerType.CANCEL;
}
return EventType.UNKNOWN;
return null;
}
private void sendInputEventForIndex(MotionEvent event, int pointerIndex) {
PointerData pointerData = new PointerData();
pointerData.pointer = event.getPointerId(pointerIndex);
pointerData.kind = PointerKind.TOUCH;
pointerData.x = event.getX(pointerIndex);
pointerData.y = event.getY(pointerIndex);
private void addPointerForIndex(MotionEvent event, int pointerIndex,
List<Pointer> result) {
Integer pointerType = getPointerTypeForAction(event.getActionMasked());
if (pointerType == null) {
return;
}
Pointer pointer = new Pointer();
pointer.timeStamp = event.getEventTime();
pointer.pointer = event.getPointerId(pointerIndex);
pointer.type = pointerType;
pointer.kind = PointerKind.TOUCH;
pointer.x = event.getX(pointerIndex);
pointer.y = event.getY(pointerIndex);
pointer.buttons = 0;
pointer.down = false;
pointer.primary = false;
pointer.obscured = false;
pointerData.pressure = event.getPressure(pointerIndex);
// TODO(eseidel): Could get the calibrated range if necessary:
// event.getDevice().getMotionRange(MotionEvent.AXIS_PRESSURE)
pointerData.pressureMin = 0.0f;
pointerData.pressureMax = 1.0f;
pointer.pressure = event.getPressure(pointerIndex);
pointer.pressureMin = 0.0f;
pointer.pressureMax = 1.0f;
InputEvent inputEvent = new InputEvent();
inputEvent.type = getTypeForAction(event.getActionMasked());
inputEvent.timeStamp = event.getEventTime();
inputEvent.pointerData = pointerData;
pointer.distance = 0.0f;
pointer.distanceMin = 0.0f;
pointer.distanceMax = 0.0f;
mSkyEngine.onInputEvent(inputEvent);
pointer.radiusMajor = 0.0f;
pointer.radiusMinor = 0.0f;
pointer.radiusMin = 0.0f;
pointer.radiusMax = 0.0f;
pointer.orientation = 0.0f;
pointer.tilt = 0.0f;
result.add(pointer);
}
@Override
......@@ -181,6 +205,8 @@ public class PlatformViewAndroid extends SurfaceView {
requestUnbufferedDispatch(event);
}
ArrayList<Pointer> pointers = new ArrayList<Pointer>();
// TODO(abarth): Rather than unpacking these events here, we should
// probably send them in one packet to the engine.
int maskedAction = event.getActionMasked();
......@@ -190,15 +216,20 @@ public class PlatformViewAndroid extends SurfaceView {
|| maskedAction == MotionEvent.ACTION_POINTER_UP
|| maskedAction == MotionEvent.ACTION_DOWN
|| maskedAction == MotionEvent.ACTION_POINTER_DOWN) {
sendInputEventForIndex(event, event.getActionIndex());
addPointerForIndex(event, event.getActionIndex(), pointers);
} else {
// ACTION_MOVE may not actually mean all pointers have moved
// but it's the responsibility of a later part of the system to
// ignore 0-deltas if desired.
for (int p = 0; p < event.getPointerCount(); p++) {
sendInputEventForIndex(event, p);
addPointerForIndex(event, p, pointers);
}
}
PointerPacket packet = new PointerPacket();
packet.pointers = pointers.toArray(new Pointer[0]);
mSkyEngine.onPointerPacket(packet);
return true;
}
......
......@@ -23,7 +23,6 @@
#include "sky/shell/service_provider.h"
#include "sky/shell/switches.h"
#include "sky/shell/ui/animator.h"
#include "sky/shell/ui/input_event_converter.h"
#include "sky/shell/ui/internals.h"
#include "sky/shell/ui/platform_impl.h"
#include "third_party/skia/include/core/SkCanvas.h"
......@@ -152,16 +151,28 @@ void Engine::OnViewportMetricsChanged(ViewportMetricsPtr metrics) {
void Engine::OnInputEvent(InputEventPtr event) {
TRACE_EVENT0("sky", "Engine::OnInputEvent");
scoped_ptr<blink::WebInputEvent> web_event =
ConvertEvent(event, display_metrics_.device_pixel_ratio);
if (!web_event)
if (event->type != EventType::BACK)
return;
scoped_ptr<blink::WebInputEvent> web_event(blink::WebInputEvent::create());
web_event->type = blink::WebInputEvent::Back;
web_event->timeStampMS = currentTimeMS();
if (sky_view_)
sky_view_->HandleInputEvent(*web_event);
}
void Engine::OnPointerPacket(pointer::PointerPacketPtr packet) {
// TODO(abarth): Process pointer events in packets.
TRACE_EVENT0("sky", "Engine::OnPointerPacket");
// Convert the pointers' x and y coordinates to logical pixels.
for (auto it = packet->pointers.begin(); it != packet->pointers.end(); ++it) {
(*it)->x /= display_metrics_.device_pixel_ratio;
(*it)->y /= display_metrics_.device_pixel_ratio;
}
if (sky_view_)
sky_view_->HandlePointerPacket(packet);
}
void Engine::RunFromLibrary(const std::string& name) {
......
// Copyright 2014 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "sky/shell/ui/input_event_converter.h"
#include "base/logging.h"
#include "base/time/time.h"
#include "sky/engine/public/platform/WebInputEvent.h"
namespace sky {
namespace {
scoped_ptr<blink::WebInputEvent> BuildWebPointerEvent(
const InputEventPtr& event, float device_pixel_ratio) {
scoped_ptr<blink::WebPointerEvent> web_event(new blink::WebPointerEvent);
web_event->timeStampMS = event->time_stamp;
switch (event->type) {
case EventType::POINTER_DOWN:
web_event->type = blink::WebInputEvent::PointerDown;
break;
case EventType::POINTER_UP:
web_event->type = blink::WebInputEvent::PointerUp;
break;
case EventType::POINTER_MOVE:
web_event->type = blink::WebInputEvent::PointerMove;
break;
case EventType::POINTER_CANCEL:
web_event->type = blink::WebInputEvent::PointerCancel;
break;
default:
NOTIMPLEMENTED() << "Received unexpected event: " << event->type;
break;
}
if (event->pointer_data) {
if (event->pointer_data->kind == PointerKind::TOUCH)
web_event->kind = blink::WebPointerEvent::Touch;
web_event->pointer = event->pointer_data->pointer;
web_event->x = event->pointer_data->x / device_pixel_ratio;
web_event->y = event->pointer_data->y / device_pixel_ratio;
web_event->pressure = event->pointer_data->pressure;
web_event->pressureMin = event->pointer_data->pressure_min;
web_event->pressureMax = event->pointer_data->pressure_max;
}
return web_event.Pass();
}
scoped_ptr<blink::WebInputEvent> BuildWebBackEvent(const InputEventPtr& event) {
scoped_ptr<blink::WebInputEvent> web_event(blink::WebInputEvent::create());
web_event->type = blink::WebInputEvent::Back;
return web_event.Pass();
}
} // namespace
scoped_ptr<blink::WebInputEvent> ConvertEvent(const InputEventPtr& event,
float device_pixel_ratio) {
switch (event->type) {
case EventType::POINTER_DOWN:
case EventType::POINTER_UP:
case EventType::POINTER_MOVE:
case EventType::POINTER_CANCEL:
return BuildWebPointerEvent(event, device_pixel_ratio);
case EventType::BACK:
return BuildWebBackEvent(event);
case EventType::UNKNOWN:
NOTIMPLEMENTED() << "ConvertEvent received unexpected EventType::UNKNOWN";
}
return scoped_ptr<blink::WebInputEvent>();
}
} // namespace mojo
// Copyright 2015 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef SKY_SHELL_UI_INPUT_EVENT_CONVERTER_H_
#define SKY_SHELL_UI_INPUT_EVENT_CONVERTER_H_
#include "base/memory/scoped_ptr.h"
#include "sky/services/engine/input_event.mojom.h"
namespace blink {
class WebInputEvent;
}
namespace sky {
scoped_ptr<blink::WebInputEvent> ConvertEvent(const InputEventPtr& event,
float device_pixel_ratio);
}
#endif // SKY_SHELL_UI_INPUT_EVENT_CONVERTER_H_
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册