提交 67109ce3 编写于 作者: A Adam Barth

Plumb input events into SkyView

Clients can now register a callback that gets called whenever we have an event
for the view. We'll need to update the Event class at some point, but this is a
start.

R=eseidel@chromium.org

Review URL: https://codereview.chromium.org/1129333005
上级 f31e6ec0
......@@ -1109,6 +1109,7 @@ core_idl_files = get_path_info([
"painting/PaintingContext.idl",
"painting/Picture.idl",
"painting/PictureRecorder.idl",
"view/EventCallback.idl",
"view/View.idl",
],
"abspath")
......
// 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_VIEW_EVENTCALLBACK_H_
#define SKY_ENGINE_CORE_VIEW_EVENTCALLBACK_H_
namespace blink {
class Event;
class EventCallback {
public:
virtual ~EventCallback() { }
virtual bool handleEvent(Event* event) = 0;
};
}
#endif // SKY_ENGINE_CORE_VIEW_EVENTCALLBACK_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.
callback interface EventCallback {
boolean handleEvent(Event event);
};
......@@ -38,9 +38,19 @@ void View::schedulePaint()
m_schedulePaintCallback.Run();
}
void View::setEventCallback(PassOwnPtr<EventCallback> callback)
{
m_eventCallback = callback;
}
void View::setDisplayMetrics(const SkyDisplayMetrics& metrics)
{
m_displayMetrics = metrics;
}
bool View::handleInputEvent(PassRefPtr<Event> event)
{
return m_eventCallback && m_eventCallback->handleEvent(event.get());
}
} // namespace blink
......@@ -7,6 +7,7 @@
#include "base/callback.h"
#include "sky/engine/core/painting/Picture.h"
#include "sky/engine/core/view/EventCallback.h"
#include "sky/engine/public/platform/sky_display_metrics.h"
#include "sky/engine/tonic/dart_wrappable.h"
#include "sky/engine/wtf/PassRefPtr.h"
......@@ -27,15 +28,19 @@ public:
Picture* picture() const { return m_picture.get(); }
void setPicture(Picture* picture) { m_picture = picture; }
void setEventCallback(PassOwnPtr<EventCallback> callback);
void schedulePaint();
void setDisplayMetrics(const SkyDisplayMetrics& metrics);
bool handleInputEvent(PassRefPtr<Event> event);
private:
explicit View(const base::Closure& schedulePaintCallback);
base::Closure m_schedulePaintCallback;
SkyDisplayMetrics m_displayMetrics;
OwnPtr<EventCallback> m_eventCallback;
RefPtr<Picture> m_picture;
};
......
......@@ -9,5 +9,6 @@ interface View {
attribute Picture picture;
void setEventCallback(EventCallback callback);
void schedulePaint();
};
......@@ -6,10 +6,16 @@
#include "sky/engine/public/sky/sky_view.h"
#include "base/bind.h"
#include "base/trace_event/trace_event.h"
#include "sky/engine/core/events/GestureEvent.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/view/View.h"
#include "sky/engine/platform/weborigin/KURL.h"
#include "sky/engine/public/platform/WebInputEvent.h"
#include "sky/engine/public/sky/sky_view_client.h"
namespace blink {
......@@ -58,7 +64,29 @@ skia::RefPtr<SkPicture> SkyView::Paint() {
return skia::RefPtr<SkPicture>();
}
bool SkyView::HandleInputEvent(const WebInputEvent& event) {
bool SkyView::HandleInputEvent(const WebInputEvent& inputEvent) {
TRACE_EVENT0("input", "SkyView::HandleInputEvent");
if (WebInputEvent::isPointerEventType(inputEvent.type)) {
const WebPointerEvent& event = static_cast<const WebPointerEvent&>(inputEvent);
return data_->view_->handleInputEvent(PointerEvent::create(event));
}
if (WebInputEvent::isGestureEventType(inputEvent.type)) {
const WebGestureEvent& event = static_cast<const WebGestureEvent&>(inputEvent);
return data_->view_->handleInputEvent(GestureEvent::create(event));
}
if (WebInputEvent::isKeyboardEventType(inputEvent.type)) {
const WebKeyboardEvent& event = static_cast<const WebKeyboardEvent&>(inputEvent);
return data_->view_->handleInputEvent(KeyboardEvent::create(event));
}
if (WebInputEvent::isWheelEventType(inputEvent.type)) {
const WebWheelEvent& event = static_cast<const WebWheelEvent&>(inputEvent);
return data_->view_->handleInputEvent(WheelEvent::create(event));
}
return false;
}
......
......@@ -5,22 +5,38 @@
import "dart:math";
import 'dart:sky';
void main() {
print("Hello, world");
Picture draw(int a, int r, int g, int b) {
double width = view.width;
double height = view.height;
PictureRecorder recorder = new PictureRecorder(width, height);
double radius = min(width, height) * 0.45;
Paint paint = new Paint()..setARGB(255, 0, 255, 0);
Paint paint = new Paint()..setARGB(a, r, g, b);
recorder.drawCircle(width / 2, height / 2, radius, paint);
return recorder.endRecording();
}
print("Storing picture");
view.picture = recorder.endRecording();
bool handleEvent(Event event) {
if (event.type == "pointerdown") {
view.picture = draw(255, 0, 0, 255);
view.schedulePaint();
return true;
}
print("Scheduling paint");
if (event.type == "pointerup") {
view.picture = draw(255, 0, 255, 0);
view.schedulePaint();
return true;
}
return false;
}
void main() {
print("Hello, world");
view.picture = draw(255, 0, 255, 0);
view.schedulePaint();
view.setEventCallback(handleEvent);
}
......@@ -161,6 +161,8 @@ void Engine::OnInputEvent(InputEventPtr event) {
ConvertEvent(event, device_pixel_ratio_);
if (!web_event)
return;
if (sky_view_)
sky_view_->HandleInputEvent(*web_event);
if (web_view_)
web_view_->handleInputEvent(*web_event);
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册