1// Copyright (c) 2010 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
5#include "content/browser/web_contents/web_drag_utils_win.h"
6
7#include <oleidl.h>
8#include "base/logging.h"
9
10using blink::WebDragOperation;
11using blink::WebDragOperationsMask;
12using blink::WebDragOperationNone;
13using blink::WebDragOperationCopy;
14using blink::WebDragOperationLink;
15using blink::WebDragOperationMove;
16using blink::WebDragOperationGeneric;
17
18namespace content {
19
20WebDragOperation WinDragOpToWebDragOp(DWORD effect) {
21  DCHECK(effect == DROPEFFECT_NONE || effect == DROPEFFECT_COPY ||
22         effect == DROPEFFECT_LINK || effect == DROPEFFECT_MOVE);
23
24  return WinDragOpMaskToWebDragOpMask(effect);
25}
26
27WebDragOperationsMask WinDragOpMaskToWebDragOpMask(DWORD effects) {
28  WebDragOperationsMask ops = WebDragOperationNone;
29  if (effects & DROPEFFECT_COPY)
30    ops = static_cast<WebDragOperationsMask>(ops | WebDragOperationCopy);
31  if (effects & DROPEFFECT_LINK)
32    ops = static_cast<WebDragOperationsMask>(ops | WebDragOperationLink);
33  if (effects & DROPEFFECT_MOVE)
34    ops = static_cast<WebDragOperationsMask>(ops | WebDragOperationMove |
35                                             WebDragOperationGeneric);
36  return ops;
37}
38
39DWORD WebDragOpToWinDragOp(WebDragOperation op) {
40  DCHECK(op == WebDragOperationNone ||
41         op == WebDragOperationCopy ||
42         op == WebDragOperationLink ||
43         op == WebDragOperationMove ||
44         op == (WebDragOperationMove | WebDragOperationGeneric));
45
46  return WebDragOpMaskToWinDragOpMask(op);
47}
48
49DWORD WebDragOpMaskToWinDragOpMask(WebDragOperationsMask ops) {
50  DWORD win_ops = DROPEFFECT_NONE;
51  if (ops & WebDragOperationCopy)
52    win_ops |= DROPEFFECT_COPY;
53  if (ops & WebDragOperationLink)
54    win_ops |= DROPEFFECT_LINK;
55  if (ops & (WebDragOperationMove | WebDragOperationGeneric))
56    win_ops |= DROPEFFECT_MOVE;
57  return win_ops;
58}
59
60}  // namespace content
61