drag_drop_types.cc 1.2 KB

123456789101112131415161718192021222324252627282930313233
  1. // Copyright 2021 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. #include "ui/base/dragdrop/drag_drop_types.h"
  5. #include "ui/base/dragdrop/mojom/drag_drop_types.mojom.h"
  6. namespace ui {
  7. using mojom::DragOperation;
  8. // Ensure that the DragDropTypes::DragOperation enum values stay in sync with
  9. // mojom::DragOperation.
  10. #define STATIC_ASSERT_ENUM(a, b) \
  11. static_assert(static_cast<int>(a) == static_cast<int>(b), \
  12. "enum mismatch: " #a)
  13. STATIC_ASSERT_ENUM(DragDropTypes::DRAG_NONE, DragOperation::kNone);
  14. STATIC_ASSERT_ENUM(DragDropTypes::DRAG_COPY, DragOperation::kCopy);
  15. STATIC_ASSERT_ENUM(DragDropTypes::DRAG_LINK, DragOperation::kLink);
  16. STATIC_ASSERT_ENUM(DragDropTypes::DRAG_MOVE, DragOperation::kMove);
  17. DragOperation PreferredDragOperation(int operations) {
  18. if (operations & DragDropTypes::DRAG_COPY)
  19. return DragOperation::kCopy;
  20. if (operations & DragDropTypes::DRAG_MOVE)
  21. return DragOperation::kMove;
  22. if (operations & DragDropTypes::DRAG_LINK)
  23. return DragOperation::kLink;
  24. return DragOperation::kNone;
  25. }
  26. } // namespace ui