OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 "ui/views/widget/desktop_aura/desktop_drop_target_win.h" | 5 #include "ui/views/widget/desktop_aura/desktop_drop_target_win.h" |
6 | 6 |
7 #include "base/metrics/histogram.h" | 7 #include "base/metrics/histogram.h" |
8 #include "base/win/win_util.h" | 8 #include "base/win/win_util.h" |
9 #include "ui/aura/window.h" | 9 #include "ui/aura/window.h" |
10 #include "ui/aura/window_tree_host.h" | 10 #include "ui/aura/window_tree_host.h" |
11 #include "ui/base/dragdrop/drag_drop_types.h" | 11 #include "ui/base/dragdrop/drag_drop_types.h" |
12 #include "ui/base/dragdrop/drop_target_event.h" | 12 #include "ui/base/dragdrop/drop_target_event.h" |
13 #include "ui/base/dragdrop/os_exchange_data_provider_win.h" | 13 #include "ui/base/dragdrop/os_exchange_data_provider_win.h" |
14 #include "ui/events/event_constants.h" | 14 #include "ui/events/event_constants.h" |
15 #include "ui/wm/public/drag_drop_client.h" | 15 #include "ui/wm/public/drag_drop_client.h" |
16 #include "ui/wm/public/drag_drop_delegate.h" | 16 #include "ui/wm/public/drag_drop_delegate.h" |
17 | 17 |
18 using aura::client::DragDropClient; | 18 using aura::client::DragDropClient; |
19 using aura::client::DragDropDelegate; | 19 using aura::client::DragDropDelegate; |
20 using ui::OSExchangeData; | 20 using ui::OSExchangeData; |
21 using ui::OSExchangeDataProviderWin; | 21 using ui::OSExchangeDataProviderWin; |
22 | 22 |
| 23 namespace { |
| 24 |
| 25 int ConvertKeyStateToAuraEventFlags(DWORD key_state) |
| 26 { |
| 27 int flags = 0; |
| 28 |
| 29 if (key_state & MK_CONTROL) |
| 30 flags |= ui::EF_CONTROL_DOWN; |
| 31 if (key_state & MK_ALT) |
| 32 flags |= ui::EF_ALT_DOWN; |
| 33 if (key_state & MK_SHIFT) |
| 34 flags |= ui::EF_SHIFT_DOWN; |
| 35 if (key_state & MK_LBUTTON) |
| 36 flags |= ui::EF_LEFT_MOUSE_BUTTON; |
| 37 if (key_state & MK_MBUTTON) |
| 38 flags |= ui::EF_MIDDLE_MOUSE_BUTTON; |
| 39 if (key_state & MK_RBUTTON) |
| 40 flags |= ui::EF_RIGHT_MOUSE_BUTTON; |
| 41 |
| 42 return flags; |
| 43 } |
| 44 |
| 45 } // namespace |
| 46 |
23 namespace views { | 47 namespace views { |
24 | 48 |
25 DesktopDropTargetWin::DesktopDropTargetWin(aura::Window* root_window, | 49 DesktopDropTargetWin::DesktopDropTargetWin(aura::Window* root_window, |
26 HWND window) | 50 HWND window) |
27 : ui::DropTargetWin(window), | 51 : ui::DropTargetWin(window), |
28 root_window_(root_window), | 52 root_window_(root_window), |
29 target_window_(NULL) { | 53 target_window_(NULL) { |
30 } | 54 } |
31 | 55 |
32 DesktopDropTargetWin::~DesktopDropTargetWin() { | 56 DesktopDropTargetWin::~DesktopDropTargetWin() { |
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
125 return; | 149 return; |
126 | 150 |
127 data->reset(new OSExchangeData(new OSExchangeDataProviderWin(data_object))); | 151 data->reset(new OSExchangeData(new OSExchangeDataProviderWin(data_object))); |
128 location = root_location; | 152 location = root_location; |
129 aura::Window::ConvertPointToTarget(root_window_, target_window_, &location); | 153 aura::Window::ConvertPointToTarget(root_window_, target_window_, &location); |
130 event->reset(new ui::DropTargetEvent( | 154 event->reset(new ui::DropTargetEvent( |
131 *(data->get()), | 155 *(data->get()), |
132 location, | 156 location, |
133 root_location, | 157 root_location, |
134 ui::DragDropTypes::DropEffectToDragOperation(effect))); | 158 ui::DragDropTypes::DropEffectToDragOperation(effect))); |
135 int flags = 0; | 159 (*event)->set_flags(ConvertKeyStateToAuraEventFlags(key_state)); |
136 flags |= base::win::IsAltPressed() ? ui::EF_ALT_DOWN : ui::EF_NONE; | |
137 flags |= base::win::IsShiftPressed() ? ui::EF_SHIFT_DOWN : ui::EF_NONE; | |
138 flags |= base::win::IsCtrlPressed() ? ui::EF_CONTROL_DOWN : ui::EF_NONE; | |
139 (*event)->set_flags(flags); | |
140 if (target_window_changed) | 160 if (target_window_changed) |
141 (*delegate)->OnDragEntered(*event->get()); | 161 (*delegate)->OnDragEntered(*event->get()); |
142 } | 162 } |
143 | 163 |
144 void DesktopDropTargetWin::NotifyDragLeave() { | 164 void DesktopDropTargetWin::NotifyDragLeave() { |
145 if (!target_window_) | 165 if (!target_window_) |
146 return; | 166 return; |
147 DragDropDelegate* delegate = | 167 DragDropDelegate* delegate = |
148 aura::client::GetDragDropDelegate(target_window_); | 168 aura::client::GetDragDropDelegate(target_window_); |
149 if (delegate) | 169 if (delegate) |
150 delegate->OnDragExited(); | 170 delegate->OnDragExited(); |
151 target_window_->RemoveObserver(this); | 171 target_window_->RemoveObserver(this); |
152 target_window_ = NULL; | 172 target_window_ = NULL; |
153 } | 173 } |
154 | 174 |
155 } // namespace views | 175 } // namespace views |
OLD | NEW |