Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(78)

Side by Side Diff: components/exo/wayland/server.cc

Issue 1975533002: Change ui::Event::time_stamp from TimeDelta to TimeTicks (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix gesture recognizer tests Created 4 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "components/exo/wayland/server.h" 5 #include "components/exo/wayland/server.h"
6 6
7 #include <alpha-compositing-unstable-v1-server-protocol.h> 7 #include <alpha-compositing-unstable-v1-server-protocol.h>
8 #include <grp.h> 8 #include <grp.h>
9 #include <linux/input.h> 9 #include <linux/input.h>
10 #include <scaler-server-protocol.h> 10 #include <scaler-server-protocol.h>
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after
94 } 94 }
95 95
96 template <class T> 96 template <class T>
97 void SetImplementation(wl_resource* resource, 97 void SetImplementation(wl_resource* resource,
98 const void* implementation, 98 const void* implementation,
99 std::unique_ptr<T> user_data) { 99 std::unique_ptr<T> user_data) {
100 wl_resource_set_implementation(resource, implementation, user_data.release(), 100 wl_resource_set_implementation(resource, implementation, user_data.release(),
101 DestroyUserData<T>); 101 DestroyUserData<T>);
102 } 102 }
103 103
104 int64_t InMilliseconds(base::TimeTicks ticks) {
105 return (ticks - base::TimeTicks()).InMilliseconds();
106 }
107
104 // A property key containing the surface resource that is associated with 108 // A property key containing the surface resource that is associated with
105 // window. If unset, no surface resource is associated with window. 109 // window. If unset, no surface resource is associated with window.
106 DEFINE_WINDOW_PROPERTY_KEY(wl_resource*, kSurfaceResourceKey, nullptr); 110 DEFINE_WINDOW_PROPERTY_KEY(wl_resource*, kSurfaceResourceKey, nullptr);
107 111
108 // A property key containing a boolean set to true if a viewport is associated 112 // A property key containing a boolean set to true if a viewport is associated
109 // with window. 113 // with window.
110 DEFINE_WINDOW_PROPERTY_KEY(bool, kSurfaceHasViewportKey, false); 114 DEFINE_WINDOW_PROPERTY_KEY(bool, kSurfaceHasViewportKey, false);
111 115
112 // A property key containing a boolean set to true if a security object is 116 // A property key containing a boolean set to true if a security object is
113 // associated with window. 117 // associated with window.
(...skipping 1325 matching lines...) Expand 10 before | Expand all | Expand 10 after
1439 // if client's pressed button state is different from |button_flags|? 1443 // if client's pressed button state is different from |button_flags|?
1440 wl_pointer_send_enter(pointer_resource_, next_serial(), surface_resource, 1444 wl_pointer_send_enter(pointer_resource_, next_serial(), surface_resource,
1441 wl_fixed_from_double(location.x()), 1445 wl_fixed_from_double(location.x()),
1442 wl_fixed_from_double(location.y())); 1446 wl_fixed_from_double(location.y()));
1443 } 1447 }
1444 void OnPointerLeave(Surface* surface) override { 1448 void OnPointerLeave(Surface* surface) override {
1445 wl_resource* surface_resource = surface->GetProperty(kSurfaceResourceKey); 1449 wl_resource* surface_resource = surface->GetProperty(kSurfaceResourceKey);
1446 DCHECK(surface_resource); 1450 DCHECK(surface_resource);
1447 wl_pointer_send_leave(pointer_resource_, next_serial(), surface_resource); 1451 wl_pointer_send_leave(pointer_resource_, next_serial(), surface_resource);
1448 } 1452 }
1449 void OnPointerMotion(base::TimeDelta time_stamp, 1453 void OnPointerMotion(base::TimeTicks time_stamp,
1450 const gfx::PointF& location) override { 1454 const gfx::PointF& location) override {
1451 wl_pointer_send_motion(pointer_resource_, time_stamp.InMilliseconds(), 1455 wl_pointer_send_motion(pointer_resource_, InMilliseconds(time_stamp),
1452 wl_fixed_from_double(location.x()), 1456 wl_fixed_from_double(location.x()),
1453 wl_fixed_from_double(location.y())); 1457 wl_fixed_from_double(location.y()));
1454 } 1458 }
1455 void OnPointerButton(base::TimeDelta time_stamp, 1459 void OnPointerButton(base::TimeTicks time_stamp,
1456 int button_flags, 1460 int button_flags,
1457 bool pressed) override { 1461 bool pressed) override {
1458 struct { 1462 struct {
1459 ui::EventFlags flag; 1463 ui::EventFlags flag;
1460 uint32_t value; 1464 uint32_t value;
1461 } buttons[] = { 1465 } buttons[] = {
1462 {ui::EF_LEFT_MOUSE_BUTTON, BTN_LEFT}, 1466 {ui::EF_LEFT_MOUSE_BUTTON, BTN_LEFT},
1463 {ui::EF_RIGHT_MOUSE_BUTTON, BTN_RIGHT}, 1467 {ui::EF_RIGHT_MOUSE_BUTTON, BTN_RIGHT},
1464 {ui::EF_MIDDLE_MOUSE_BUTTON, BTN_MIDDLE}, 1468 {ui::EF_MIDDLE_MOUSE_BUTTON, BTN_MIDDLE},
1465 {ui::EF_FORWARD_MOUSE_BUTTON, BTN_FORWARD}, 1469 {ui::EF_FORWARD_MOUSE_BUTTON, BTN_FORWARD},
1466 {ui::EF_BACK_MOUSE_BUTTON, BTN_BACK}, 1470 {ui::EF_BACK_MOUSE_BUTTON, BTN_BACK},
1467 }; 1471 };
1468 uint32_t serial = next_serial(); 1472 uint32_t serial = next_serial();
1469 for (auto button : buttons) { 1473 for (auto button : buttons) {
1470 if (button_flags & button.flag) { 1474 if (button_flags & button.flag) {
1471 wl_pointer_send_button(pointer_resource_, serial, 1475 wl_pointer_send_button(pointer_resource_, serial,
1472 time_stamp.InMilliseconds(), button.value, 1476 InMilliseconds(time_stamp), button.value,
1473 pressed ? WL_POINTER_BUTTON_STATE_PRESSED 1477 pressed ? WL_POINTER_BUTTON_STATE_PRESSED
1474 : WL_POINTER_BUTTON_STATE_RELEASED); 1478 : WL_POINTER_BUTTON_STATE_RELEASED);
1475 } 1479 }
1476 } 1480 }
1477 } 1481 }
1478 1482
1479 void OnPointerScroll(base::TimeDelta time_stamp, 1483 void OnPointerScroll(base::TimeTicks time_stamp,
1480 const gfx::Vector2dF& offset, 1484 const gfx::Vector2dF& offset,
1481 bool discrete) override { 1485 bool discrete) override {
1482 // Same as Weston, the reference compositor. 1486 // Same as Weston, the reference compositor.
1483 const double kAxisStepDistance = 10.0 / ui::MouseWheelEvent::kWheelDelta; 1487 const double kAxisStepDistance = 10.0 / ui::MouseWheelEvent::kWheelDelta;
1484 1488
1485 if (wl_resource_get_version(pointer_resource_) >= 1489 if (wl_resource_get_version(pointer_resource_) >=
1486 WL_POINTER_AXIS_SOURCE_SINCE_VERSION) { 1490 WL_POINTER_AXIS_SOURCE_SINCE_VERSION) {
1487 int32_t axis_source = discrete ? WL_POINTER_AXIS_SOURCE_WHEEL 1491 int32_t axis_source = discrete ? WL_POINTER_AXIS_SOURCE_WHEEL
1488 : WL_POINTER_AXIS_SOURCE_FINGER; 1492 : WL_POINTER_AXIS_SOURCE_FINGER;
1489 wl_pointer_send_axis_source(pointer_resource_, axis_source); 1493 wl_pointer_send_axis_source(pointer_resource_, axis_source);
1490 } 1494 }
1491 1495
1492 double x_value = offset.x() * kAxisStepDistance; 1496 double x_value = offset.x() * kAxisStepDistance;
1493 wl_pointer_send_axis(pointer_resource_, time_stamp.InMilliseconds(), 1497 wl_pointer_send_axis(pointer_resource_, InMilliseconds(time_stamp),
1494 WL_POINTER_AXIS_HORIZONTAL_SCROLL, 1498 WL_POINTER_AXIS_HORIZONTAL_SCROLL,
1495 wl_fixed_from_double(-x_value)); 1499 wl_fixed_from_double(-x_value));
1496 1500
1497 double y_value = offset.y() * kAxisStepDistance; 1501 double y_value = offset.y() * kAxisStepDistance;
1498 wl_pointer_send_axis(pointer_resource_, time_stamp.InMilliseconds(), 1502 wl_pointer_send_axis(pointer_resource_, InMilliseconds(time_stamp),
1499 WL_POINTER_AXIS_VERTICAL_SCROLL, 1503 WL_POINTER_AXIS_VERTICAL_SCROLL,
1500 wl_fixed_from_double(-y_value)); 1504 wl_fixed_from_double(-y_value));
1501 } 1505 }
1502 1506
1503 void OnPointerScrollCancel(base::TimeDelta time_stamp) override { 1507 void OnPointerScrollCancel(base::TimeTicks time_stamp) override {
1504 // Wayland doesn't know the concept of a canceling kinetic scrolling. 1508 // Wayland doesn't know the concept of a canceling kinetic scrolling.
1505 // But we can send a 0 distance scroll to emulate this behavior. 1509 // But we can send a 0 distance scroll to emulate this behavior.
1506 OnPointerScroll(time_stamp, gfx::Vector2dF(0, 0), false); 1510 OnPointerScroll(time_stamp, gfx::Vector2dF(0, 0), false);
1507 OnPointerScrollStop(time_stamp); 1511 OnPointerScrollStop(time_stamp);
1508 } 1512 }
1509 1513
1510 void OnPointerScrollStop(base::TimeDelta time_stamp) override { 1514 void OnPointerScrollStop(base::TimeTicks time_stamp) override {
1511 if (wl_resource_get_version(pointer_resource_) >= 1515 if (wl_resource_get_version(pointer_resource_) >=
1512 WL_POINTER_AXIS_STOP_SINCE_VERSION) { 1516 WL_POINTER_AXIS_STOP_SINCE_VERSION) {
1513 wl_pointer_send_axis_stop(pointer_resource_, time_stamp.InMilliseconds(), 1517 wl_pointer_send_axis_stop(pointer_resource_, InMilliseconds(time_stamp),
1514 WL_POINTER_AXIS_HORIZONTAL_SCROLL); 1518 WL_POINTER_AXIS_HORIZONTAL_SCROLL);
1515 wl_pointer_send_axis_stop(pointer_resource_, time_stamp.InMilliseconds(), 1519 wl_pointer_send_axis_stop(pointer_resource_, InMilliseconds(time_stamp),
1516 WL_POINTER_AXIS_VERTICAL_SCROLL); 1520 WL_POINTER_AXIS_VERTICAL_SCROLL);
1517 } 1521 }
1518 } 1522 }
1519 1523
1520 void OnPointerFrame() override { 1524 void OnPointerFrame() override {
1521 if (wl_resource_get_version(pointer_resource_) >= 1525 if (wl_resource_get_version(pointer_resource_) >=
1522 WL_POINTER_FRAME_SINCE_VERSION) { 1526 WL_POINTER_FRAME_SINCE_VERSION) {
1523 wl_pointer_send_frame(pointer_resource_); 1527 wl_pointer_send_frame(pointer_resource_);
1524 } 1528 }
1525 wl_client_flush(client()); 1529 wl_client_flush(client());
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after
1616 &keys); 1620 &keys);
1617 wl_array_release(&keys); 1621 wl_array_release(&keys);
1618 wl_client_flush(client()); 1622 wl_client_flush(client());
1619 } 1623 }
1620 void OnKeyboardLeave(Surface* surface) override { 1624 void OnKeyboardLeave(Surface* surface) override {
1621 wl_resource* surface_resource = surface->GetProperty(kSurfaceResourceKey); 1625 wl_resource* surface_resource = surface->GetProperty(kSurfaceResourceKey);
1622 DCHECK(surface_resource); 1626 DCHECK(surface_resource);
1623 wl_keyboard_send_leave(keyboard_resource_, next_serial(), surface_resource); 1627 wl_keyboard_send_leave(keyboard_resource_, next_serial(), surface_resource);
1624 wl_client_flush(client()); 1628 wl_client_flush(client());
1625 } 1629 }
1626 void OnKeyboardKey(base::TimeDelta time_stamp, 1630 void OnKeyboardKey(base::TimeTicks time_stamp,
1627 ui::DomCode key, 1631 ui::DomCode key,
1628 bool pressed) override { 1632 bool pressed) override {
1629 wl_keyboard_send_key(keyboard_resource_, next_serial(), 1633 wl_keyboard_send_key(keyboard_resource_, next_serial(),
1630 time_stamp.InMilliseconds(), DomCodeToKey(key), 1634 InMilliseconds(time_stamp), DomCodeToKey(key),
1631 pressed ? WL_KEYBOARD_KEY_STATE_PRESSED 1635 pressed ? WL_KEYBOARD_KEY_STATE_PRESSED
1632 : WL_KEYBOARD_KEY_STATE_RELEASED); 1636 : WL_KEYBOARD_KEY_STATE_RELEASED);
1633 wl_client_flush(client()); 1637 wl_client_flush(client());
1634 } 1638 }
1635 void OnKeyboardModifiers(int modifier_flags) override { 1639 void OnKeyboardModifiers(int modifier_flags) override {
1636 xkb_state_update_mask(xkb_state_.get(), 1640 xkb_state_update_mask(xkb_state_.get(),
1637 ModifierFlagsToXkbModifiers(modifier_flags), 0, 0, 0, 1641 ModifierFlagsToXkbModifiers(modifier_flags), 0, 0, 0,
1638 0, 0); 1642 0, 0);
1639 wl_keyboard_send_modifiers( 1643 wl_keyboard_send_modifiers(
1640 keyboard_resource_, next_serial(), 1644 keyboard_resource_, next_serial(),
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after
1725 // Overridden from TouchDelegate: 1729 // Overridden from TouchDelegate:
1726 void OnTouchDestroying(Touch* touch) override { delete this; } 1730 void OnTouchDestroying(Touch* touch) override { delete this; }
1727 bool CanAcceptTouchEventsForSurface(Surface* surface) const override { 1731 bool CanAcceptTouchEventsForSurface(Surface* surface) const override {
1728 wl_resource* surface_resource = surface->GetProperty(kSurfaceResourceKey); 1732 wl_resource* surface_resource = surface->GetProperty(kSurfaceResourceKey);
1729 // We can accept events for this surface if the client is the same as the 1733 // We can accept events for this surface if the client is the same as the
1730 // touch resource. 1734 // touch resource.
1731 return surface_resource && 1735 return surface_resource &&
1732 wl_resource_get_client(surface_resource) == client(); 1736 wl_resource_get_client(surface_resource) == client();
1733 } 1737 }
1734 void OnTouchDown(Surface* surface, 1738 void OnTouchDown(Surface* surface,
1735 base::TimeDelta time_stamp, 1739 base::TimeTicks time_stamp,
1736 int id, 1740 int id,
1737 const gfx::Point& location) override { 1741 const gfx::Point& location) override {
1738 wl_resource* surface_resource = surface->GetProperty(kSurfaceResourceKey); 1742 wl_resource* surface_resource = surface->GetProperty(kSurfaceResourceKey);
1739 DCHECK(surface_resource); 1743 DCHECK(surface_resource);
1740 wl_touch_send_down(touch_resource_, next_serial(), 1744 wl_touch_send_down(touch_resource_, next_serial(),
1741 time_stamp.InMilliseconds(), surface_resource, id, 1745 InMilliseconds(time_stamp), surface_resource, id,
1742 wl_fixed_from_int(location.x()), 1746 wl_fixed_from_int(location.x()),
1743 wl_fixed_from_int(location.y())); 1747 wl_fixed_from_int(location.y()));
1744 wl_client_flush(client()); 1748 wl_client_flush(client());
1745 } 1749 }
1746 void OnTouchUp(base::TimeDelta time_stamp, int id) override { 1750 void OnTouchUp(base::TimeTicks time_stamp, int id) override {
1747 wl_touch_send_up(touch_resource_, next_serial(), 1751 wl_touch_send_up(touch_resource_, next_serial(), InMilliseconds(time_stamp),
1748 time_stamp.InMilliseconds(), id); 1752 id);
1749 wl_client_flush(client()); 1753 wl_client_flush(client());
1750 } 1754 }
1751 void OnTouchMotion(base::TimeDelta time_stamp, 1755 void OnTouchMotion(base::TimeTicks time_stamp,
1752 int id, 1756 int id,
1753 const gfx::Point& location) override { 1757 const gfx::Point& location) override {
1754 wl_touch_send_motion(touch_resource_, time_stamp.InMilliseconds(), id, 1758 wl_touch_send_motion(touch_resource_, InMilliseconds(time_stamp), id,
1755 wl_fixed_from_int(location.x()), 1759 wl_fixed_from_int(location.x()),
1756 wl_fixed_from_int(location.y())); 1760 wl_fixed_from_int(location.y()));
1757 wl_client_flush(client()); 1761 wl_client_flush(client());
1758 } 1762 }
1759 void OnTouchCancel() override { 1763 void OnTouchCancel() override {
1760 wl_touch_send_cancel(touch_resource_); 1764 wl_touch_send_cancel(touch_resource_);
1761 wl_client_flush(client()); 1765 wl_client_flush(client());
1762 } 1766 }
1763 1767
1764 private: 1768 private:
(...skipping 509 matching lines...) Expand 10 before | Expand all | Expand 10 after
2274 DCHECK(event_loop); 2278 DCHECK(event_loop);
2275 wl_event_loop_dispatch(event_loop, timeout.InMilliseconds()); 2279 wl_event_loop_dispatch(event_loop, timeout.InMilliseconds());
2276 } 2280 }
2277 2281
2278 void Server::Flush() { 2282 void Server::Flush() {
2279 wl_display_flush_clients(wl_display_.get()); 2283 wl_display_flush_clients(wl_display_.get());
2280 } 2284 }
2281 2285
2282 } // namespace wayland 2286 } // namespace wayland
2283 } // namespace exo 2287 } // namespace exo
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698