Commit 53549f0a authored by Maksim Sisov's avatar Maksim Sisov Committed by Commit Bot

Move and rename ConvertEventToDifferentHost to event_utils.h

This patch doesn't bring any functionality changes,but
moves ConvertEventToDifferentHost to event_utils and makes
it also available for ozone x11 builds.

Bug: 707406
Change-Id: Iab9a034904d22464cb6d3e90f8511979f1932fdd
Reviewed-on: https://chromium-review.googlesource.com/790771
Commit-Queue: Maksim Sisov <msisov@igalia.com>
Reviewed-by: default avatarSadrul Chowdhury <sadrul@chromium.org>
Reviewed-by: default avatarRobert Kroeger <rjkroege@chromium.org>
Cr-Commit-Position: refs/heads/master@{#520527}
parent 03d083a8
...@@ -130,4 +130,19 @@ void ComputeEventLatencyOS(const base::NativeEvent& native_event) { ...@@ -130,4 +130,19 @@ void ComputeEventLatencyOS(const base::NativeEvent& native_event) {
} }
} }
void ConvertEventLocationToTargetWindowLocation(
const gfx::Point& target_window_origin,
const gfx::Point& current_window_origin,
ui::LocatedEvent* located_event) {
if (current_window_origin == target_window_origin)
return;
DCHECK(located_event);
gfx::Vector2d offset = current_window_origin - target_window_origin;
gfx::PointF location_in_pixel_in_host =
located_event->location_f() + gfx::Vector2dF(offset);
located_event->set_location_f(location_in_pixel_in_host);
located_event->set_root_location_f(location_in_pixel_in_host);
}
} // namespace ui } // namespace ui
...@@ -180,6 +180,14 @@ EVENTS_EXPORT void UpdateX11EventForChangedButtonFlags(MouseEvent* event); ...@@ -180,6 +180,14 @@ EVENTS_EXPORT void UpdateX11EventForChangedButtonFlags(MouseEvent* event);
// Registers a custom event type. // Registers a custom event type.
EVENTS_EXPORT int RegisterCustomEventType(); EVENTS_EXPORT int RegisterCustomEventType();
// Updates the location of |located_event| from |current_window_origin| to be in
// |target_window_origin|'s coordinate system so that it can be dispatched to a
// window based on |target_window_origin|.
EVENTS_EXPORT void ConvertEventLocationToTargetWindowLocation(
const gfx::Point& target_window_origin,
const gfx::Point& current_window_origin,
ui::LocatedEvent* located_event);
} // namespace ui } // namespace ui
#endif // UI_EVENTS_EVENT_UTILS_H_ #endif // UI_EVENTS_EVENT_UTILS_H_
...@@ -1768,7 +1768,11 @@ void DesktopWindowTreeHostX11::DispatchMouseEvent(ui::MouseEvent* event) { ...@@ -1768,7 +1768,11 @@ void DesktopWindowTreeHostX11::DispatchMouseEvent(ui::MouseEvent* event) {
} else { } else {
// Another DesktopWindowTreeHostX11 has installed itself as // Another DesktopWindowTreeHostX11 has installed itself as
// capture. Translate the event's location and dispatch to the other. // capture. Translate the event's location and dispatch to the other.
ConvertEventToDifferentHost(event, g_current_capture); DCHECK_EQ(ui::GetScaleFactorForNativeView(window()),
ui::GetScaleFactorForNativeView(g_current_capture->window()));
ConvertEventLocationToTargetWindowLocation(
g_current_capture->GetLocationOnScreenInPixels(),
GetLocationOnScreenInPixels(), event->AsLocatedEvent());
g_current_capture->SendEventToSink(event); g_current_capture->SendEventToSink(event);
} }
} }
...@@ -1776,7 +1780,11 @@ void DesktopWindowTreeHostX11::DispatchMouseEvent(ui::MouseEvent* event) { ...@@ -1776,7 +1780,11 @@ void DesktopWindowTreeHostX11::DispatchMouseEvent(ui::MouseEvent* event) {
void DesktopWindowTreeHostX11::DispatchTouchEvent(ui::TouchEvent* event) { void DesktopWindowTreeHostX11::DispatchTouchEvent(ui::TouchEvent* event) {
if (g_current_capture && g_current_capture != this && if (g_current_capture && g_current_capture != this &&
event->type() == ui::ET_TOUCH_PRESSED) { event->type() == ui::ET_TOUCH_PRESSED) {
ConvertEventToDifferentHost(event, g_current_capture); DCHECK_EQ(ui::GetScaleFactorForNativeView(window()),
ui::GetScaleFactorForNativeView(g_current_capture->window()));
ConvertEventLocationToTargetWindowLocation(
g_current_capture->GetLocationOnScreenInPixels(),
GetLocationOnScreenInPixels(), event->AsLocatedEvent());
g_current_capture->SendEventToSink(event); g_current_capture->SendEventToSink(event);
} else { } else {
SendEventToSink(event); SendEventToSink(event);
...@@ -1788,20 +1796,6 @@ void DesktopWindowTreeHostX11::DispatchKeyEvent(ui::KeyEvent* event) { ...@@ -1788,20 +1796,6 @@ void DesktopWindowTreeHostX11::DispatchKeyEvent(ui::KeyEvent* event) {
SendEventToSink(event); SendEventToSink(event);
} }
void DesktopWindowTreeHostX11::ConvertEventToDifferentHost(
ui::LocatedEvent* located_event,
DesktopWindowTreeHostX11* host) {
DCHECK_NE(this, host);
DCHECK_EQ(ui::GetScaleFactorForNativeView(window()),
ui::GetScaleFactorForNativeView(host->window()));
gfx::Vector2d offset =
GetLocationOnScreenInPixels() - host->GetLocationOnScreenInPixels();
gfx::PointF location_in_pixel_in_host =
located_event->location_f() + gfx::Vector2dF(offset);
located_event->set_location_f(location_in_pixel_in_host);
located_event->set_root_location_f(location_in_pixel_in_host);
}
void DesktopWindowTreeHostX11::ResetWindowRegion() { void DesktopWindowTreeHostX11::ResetWindowRegion() {
// If a custom window shape was supplied then apply it. // If a custom window shape was supplied then apply it.
if (custom_window_shape_) { if (custom_window_shape_) {
......
...@@ -245,11 +245,6 @@ class VIEWS_EXPORT DesktopWindowTreeHostX11 ...@@ -245,11 +245,6 @@ class VIEWS_EXPORT DesktopWindowTreeHostX11
// Dispatches a key event. // Dispatches a key event.
void DispatchKeyEvent(ui::KeyEvent* event); void DispatchKeyEvent(ui::KeyEvent* event);
// Updates the location of |located_event| to be in |host|'s coordinate system
// so that it can be dispatched to |host|.
void ConvertEventToDifferentHost(ui::LocatedEvent* located_event,
DesktopWindowTreeHostX11* host);
// Resets the window region for the current widget bounds if necessary. // Resets the window region for the current widget bounds if necessary.
void ResetWindowRegion(); void ResetWindowRegion();
......
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