Commit 40451659 authored by Michael Spang's avatar Michael Spang Committed by Commit Bot

ui: ozone: Remove casts from PlatformEvent to ui::Event*

These are no longer necessary since PlatformEvent is now a typedef to
ui::Event*.

BUG=none
TEST=compile

Change-Id: I49749511c7db8d0f2f96add58201ad6d288445f3
Reviewed-on: https://chromium-review.googlesource.com/978468
Commit-Queue: Michael Spang <spang@chromium.org>
Reviewed-by: default avatarScott Violet <sky@chromium.org>
Cr-Commit-Position: refs/heads/master@{#545807}
parent 9f8faccf
...@@ -110,8 +110,7 @@ class TestEventFactoryEvdev : public EventFactoryEvdev { ...@@ -110,8 +110,7 @@ class TestEventFactoryEvdev : public EventFactoryEvdev {
~TestEventFactoryEvdev() override {} ~TestEventFactoryEvdev() override {}
private: private:
uint32_t DispatchEvent(PlatformEvent platform_event) override { uint32_t DispatchEvent(PlatformEvent event) override {
Event* event = static_cast<Event*>(platform_event);
callback_.Run(event); callback_.Run(event);
return POST_DISPATCH_NONE; return POST_DISPATCH_NONE;
} }
......
...@@ -9,28 +9,31 @@ ...@@ -9,28 +9,31 @@
namespace ui { namespace ui {
void DispatchEventFromNativeUiEvent( void DispatchEventFromNativeUiEvent(
const PlatformEvent& native_event, const PlatformEvent& event,
base::OnceCallback<void(ui::Event*)> callback) { base::OnceCallback<void(ui::Event*)> callback) {
ui::Event* native_ui_event = static_cast<ui::Event*>(native_event); // NB: ui::Events are constructed here using the overload that takes a
if (native_ui_event->IsKeyEvent()) { // const PlatformEvent& (here ui::Event* const&) rather than the copy
ui::KeyEvent key_event(native_event); // constructor. This has side effects and cannot be changed to use the
// copy constructor or Event::Clone.
if (event->IsKeyEvent()) {
ui::KeyEvent key_event(event);
std::move(callback).Run(&key_event); std::move(callback).Run(&key_event);
} else if (native_ui_event->IsMouseWheelEvent()) { } else if (event->IsMouseWheelEvent()) {
ui::MouseWheelEvent wheel_event(native_event); ui::MouseWheelEvent wheel_event(event);
std::move(callback).Run(&wheel_event); std::move(callback).Run(&wheel_event);
} else if (native_ui_event->IsMouseEvent()) { } else if (event->IsMouseEvent()) {
ui::MouseEvent mouse_event(native_event); ui::MouseEvent mouse_event(event);
std::move(callback).Run(&mouse_event); std::move(callback).Run(&mouse_event);
} else if (native_ui_event->IsTouchEvent()) { } else if (event->IsTouchEvent()) {
ui::TouchEvent touch_event(native_event); ui::TouchEvent touch_event(event);
std::move(callback).Run(&touch_event); std::move(callback).Run(&touch_event);
} else if (native_ui_event->IsScrollEvent()) { } else if (event->IsScrollEvent()) {
ui::ScrollEvent scroll_event(native_event); ui::ScrollEvent scroll_event(event);
std::move(callback).Run(&scroll_event); std::move(callback).Run(&scroll_event);
} else if (native_ui_event->IsGestureEvent()) { } else if (event->IsGestureEvent()) {
std::move(callback).Run(native_ui_event); std::move(callback).Run(event);
// TODO(mohsen): Use the same pattern for scroll/touch/wheel events. // TODO(mohsen): Use the same pattern for scroll/touch/wheel events.
// Apparently, there is no need for them to wrap the |native_event|. // Apparently, there is no need for them to wrap the |event|.
} else { } else {
NOTREACHED(); NOTREACHED();
} }
......
...@@ -129,9 +129,8 @@ PlatformImeController* DrmWindowHost::GetPlatformImeController() { ...@@ -129,9 +129,8 @@ PlatformImeController* DrmWindowHost::GetPlatformImeController() {
return nullptr; return nullptr;
} }
bool DrmWindowHost::CanDispatchEvent(const PlatformEvent& ne) { bool DrmWindowHost::CanDispatchEvent(const PlatformEvent& event) {
DCHECK(ne); DCHECK(event);
Event* event = static_cast<Event*>(ne);
// If there is a grab, capture events here. // If there is a grab, capture events here.
gfx::AcceleratedWidget grabber = window_manager_->event_grabber(); gfx::AcceleratedWidget grabber = window_manager_->event_grabber();
...@@ -170,10 +169,9 @@ bool DrmWindowHost::CanDispatchEvent(const PlatformEvent& ne) { ...@@ -170,10 +169,9 @@ bool DrmWindowHost::CanDispatchEvent(const PlatformEvent& ne) {
return true; return true;
} }
uint32_t DrmWindowHost::DispatchEvent(const PlatformEvent& native_event) { uint32_t DrmWindowHost::DispatchEvent(const PlatformEvent& event) {
DCHECK(native_event); DCHECK(event);
Event* event = static_cast<Event*>(native_event);
if (event->IsLocatedEvent()) { if (event->IsLocatedEvent()) {
// Make the event location relative to this window's origin. // Make the event location relative to this window's origin.
LocatedEvent* located_event = event->AsLocatedEvent(); LocatedEvent* located_event = event->AsLocatedEvent();
...@@ -183,7 +181,7 @@ uint32_t DrmWindowHost::DispatchEvent(const PlatformEvent& native_event) { ...@@ -183,7 +181,7 @@ uint32_t DrmWindowHost::DispatchEvent(const PlatformEvent& native_event) {
located_event->set_root_location_f(location); located_event->set_root_location_f(location);
} }
DispatchEventFromNativeUiEvent( DispatchEventFromNativeUiEvent(
native_event, base::BindOnce(&PlatformWindowDelegate::DispatchEvent, event, base::BindOnce(&PlatformWindowDelegate::DispatchEvent,
base::Unretained(delegate_))); base::Unretained(delegate_)));
return POST_DISPATCH_STOP_PROPAGATION; return POST_DISPATCH_STOP_PROPAGATION;
} }
......
...@@ -234,8 +234,7 @@ PlatformImeController* WaylandWindow::GetPlatformImeController() { ...@@ -234,8 +234,7 @@ PlatformImeController* WaylandWindow::GetPlatformImeController() {
return nullptr; return nullptr;
} }
bool WaylandWindow::CanDispatchEvent(const PlatformEvent& native_event) { bool WaylandWindow::CanDispatchEvent(const PlatformEvent& event) {
Event* event = static_cast<Event*>(native_event);
if (event->IsMouseEvent()) if (event->IsMouseEvent())
return has_pointer_focus_; return has_pointer_focus_;
if (event->IsKeyEvent()) if (event->IsKeyEvent())
......
...@@ -69,12 +69,11 @@ bool X11WindowOzone::DispatchXEvent(XEvent* xev) { ...@@ -69,12 +69,11 @@ bool X11WindowOzone::DispatchXEvent(XEvent* xev) {
return true; return true;
} }
bool X11WindowOzone::CanDispatchEvent(const PlatformEvent& platform_event) { bool X11WindowOzone::CanDispatchEvent(const PlatformEvent& event) {
return handle_next_event_; return handle_next_event_;
} }
uint32_t X11WindowOzone::DispatchEvent(const PlatformEvent& platform_event) { uint32_t X11WindowOzone::DispatchEvent(const PlatformEvent& event) {
auto* event = static_cast<Event*>(platform_event);
if (!window_manager_->event_grabber() || if (!window_manager_->event_grabber() ||
window_manager_->event_grabber() == this) { window_manager_->event_grabber() == this) {
// This is unfortunately needed otherwise events that depend on global state // This is unfortunately needed otherwise events that depend on global state
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment