x11_drag_context.h 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. // Copyright 2019 The Chromium Authors. All rights reserved.
  2. // Use of this source code is governed by a BSD-style license that can be
  3. // found in the LICENSE file.
  4. #ifndef UI_BASE_X_X11_DRAG_CONTEXT_H_
  5. #define UI_BASE_X_X11_DRAG_CONTEXT_H_
  6. #include <memory>
  7. #include <vector>
  8. #include "base/component_export.h"
  9. #include "base/memory/raw_ptr.h"
  10. #include "ui/base/x/selection_utils.h"
  11. #include "ui/gfx/geometry/point.h"
  12. #include "ui/gfx/x/event.h"
  13. #include "ui/gfx/x/xproto.h"
  14. namespace ui {
  15. class XDragDropClient;
  16. class COMPONENT_EXPORT(UI_BASE_X) XDragContext {
  17. public:
  18. XDragContext(x11::Window local_window,
  19. const x11::ClientMessageEvent& event,
  20. const SelectionFormatMap& data);
  21. ~XDragContext();
  22. XDragContext(const XDragContext&) = delete;
  23. XDragContext& operator=(const XDragContext&) = delete;
  24. x11::Window source_window() const { return source_window_; }
  25. const SelectionFormatMap& fetched_targets() const { return fetched_targets_; }
  26. // When we receive an XdndPosition message, we need to have all the data
  27. // copied from the other window before we process the XdndPosition
  28. // message. If we have that data already, dispatch immediately. Otherwise,
  29. // delay dispatching until we do.
  30. void OnXdndPositionMessage(XDragDropClient* client,
  31. x11::Atom suggested_action,
  32. x11::Window source_window,
  33. x11::Time time_stamp,
  34. const gfx::Point& screen_point);
  35. // Called when XSelection data has been copied to our process.
  36. void OnSelectionNotify(const x11::SelectionNotifyEvent& xselection);
  37. // Reads the kXdndActionList property from |source_window_| and copies it
  38. // into |actions_|.
  39. void ReadActions();
  40. // Creates a DragDropTypes::DragOperation representation of the current
  41. // action list.
  42. int GetDragOperation() const;
  43. bool DispatchPropertyNotifyEvent(const x11::PropertyNotifyEvent& event);
  44. private:
  45. // Called to request the next target from the source window. This is only
  46. // done on the first XdndPosition; after that, we cache the data offered by
  47. // the source window.
  48. void RequestNextTarget();
  49. // Masks the X11 atom |xdnd_operation|'s views representation onto
  50. // |drag_operation|.
  51. void MaskOperation(x11::Atom xdnd_operation, int* drag_operation) const;
  52. // The x11::Window of our chrome local aura window handling our events.
  53. x11::Window local_window_;
  54. // The x11::Window of the window that initiated the drag.
  55. x11::Window source_window_;
  56. // The client we inform once we're done with requesting data.
  57. raw_ptr<XDragDropClient> drag_drop_client_ = nullptr;
  58. // Whether we're blocking the handling of an XdndPosition message by waiting
  59. // for |unfetched_targets_| to be fetched.
  60. bool waiting_to_handle_position_ = false;
  61. // Where the cursor is on screen.
  62. gfx::Point screen_point_;
  63. // The time stamp of the last XdndPosition event we received. The XDND
  64. // specification mandates that we use this time stamp when querying the source
  65. // about the drag and drop data.
  66. x11::Time position_time_stamp_;
  67. // A SelectionFormatMap of data that we have in our process.
  68. SelectionFormatMap fetched_targets_;
  69. // The names of various data types offered by the other window that we
  70. // haven't fetched and put in |fetched_targets_| yet.
  71. std::vector<x11::Atom> unfetched_targets_;
  72. // XdndPosition messages have a suggested action. Qt applications exclusively
  73. // use this, instead of the XdndActionList which is backed by |actions_|.
  74. x11::Atom suggested_action_ = x11::Atom::None;
  75. // Possible actions.
  76. std::vector<x11::Atom> actions_;
  77. };
  78. } // namespace ui
  79. #endif // UI_BASE_X_X11_DRAG_CONTEXT_H_