mirror of
https://github.com/flutter/flutter.git
synced 2026-02-20 02:29:02 +08:00
This CL moves KeyboardEvents from the old event model to NewEventHandler. This CL keeps the basic structure of keydown, keypress, keyup events even though that's a bit wacky. As with pointer and gesture events, this CL removes PlatformKeyboardEvent in favor of just using WebKeyboardEvent. I've also made WebKeyboardEvent align more closely with Mojo's keyboard event. The CL does change one important aspect of key event handling: on the web the "keyCode" property of KeyboardEvent changes its meaning depending on whether the event is a keydown or a keypress event. For the former events, keyCode is the "virtual" (i.e., windows) key code where for the latter events, keyCode is the character code. To be more precise, I've renamed keyCode to virtualKeyCode and I've given it a zero (unknown key code) value during keypress events. R=ojan@chromium.org, eseidel@chromium.org Review URL: https://codereview.chromium.org/872233002
74 lines
2.0 KiB
C++
74 lines
2.0 KiB
C++
// 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_
|