OLD | NEW |
---|---|
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "chrome/browser/ui/views/tab_contents/native_tab_contents_view_aura.h" | 5 #include "chrome/browser/ui/views/tab_contents/native_tab_contents_view_aura.h" |
6 | 6 |
7 // TODO(beng): USE_ASH | |
8 #include "ash/shell.h" | |
9 #include "ash/wm/visibility_controller.h" | |
10 #include "base/event_types.h" | 7 #include "base/event_types.h" |
11 #include "base/message_loop.h" | 8 #include "base/message_loop.h" |
12 #include "chrome/browser/ui/views/tab_contents/native_tab_contents_view_delegate .h" | 9 #include "chrome/browser/ui/views/tab_contents/native_tab_contents_view_delegate .h" |
13 #include "content/browser/renderer_host/render_view_host.h" | 10 #include "content/browser/renderer_host/render_view_host.h" |
14 #include "content/public/browser/render_widget_host_view.h" | 11 #include "content/public/browser/render_widget_host_view.h" |
15 #include "content/public/browser/web_contents.h" | 12 #include "content/public/browser/web_contents.h" |
16 #include "content/public/browser/web_contents_view.h" | 13 #include "content/public/browser/web_contents_view.h" |
17 #include "ui/aura/client/drag_drop_client.h" | 14 #include "ui/aura/client/drag_drop_client.h" |
18 #include "ui/aura/client/drag_drop_delegate.h" | 15 #include "ui/aura/client/drag_drop_delegate.h" |
19 #include "ui/aura/event.h" | 16 #include "ui/aura/event.h" |
20 #include "ui/aura/root_window.h" | 17 #include "ui/aura/root_window.h" |
21 #include "ui/aura/window.h" | 18 #include "ui/aura/window.h" |
22 #include "ui/base/dragdrop/drag_drop_types.h" | 19 #include "ui/base/dragdrop/drag_drop_types.h" |
23 #include "ui/base/dragdrop/os_exchange_data.h" | 20 #include "ui/base/dragdrop/os_exchange_data.h" |
24 #include "ui/base/dragdrop/os_exchange_data_provider_aura.h" | 21 #include "ui/base/dragdrop/os_exchange_data_provider_aura.h" |
25 #include "ui/views/views_delegate.h" | 22 #include "ui/views/views_delegate.h" |
26 #include "ui/views/widget/widget.h" | 23 #include "ui/views/widget/widget.h" |
27 #include "webkit/glue/webdropdata.h" | 24 #include "webkit/glue/webdropdata.h" |
28 | 25 |
26 #if defined(USE_ASH) | |
27 #include "ash/shell.h" | |
28 #include "ash/wm/visibility_controller.h" | |
29 #endif | |
30 | |
29 using content::RenderWidgetHostView; | 31 using content::RenderWidgetHostView; |
30 using content::WebContents; | 32 using content::WebContents; |
31 | 33 |
32 namespace { | 34 namespace { |
33 | 35 |
34 // Listens to all mouse drag events during a drag and drop and sends them to | 36 // Listens to all mouse drag events during a drag and drop and sends them to |
35 // the renderer. | 37 // the renderer. |
36 class WebDragSourceAura : public MessageLoopForUI::Observer { | 38 class WebDragSourceAura : public MessageLoopForUI::Observer { |
37 public: | 39 public: |
38 explicit WebDragSourceAura(NativeTabContentsViewAura* view) | 40 explicit WebDragSourceAura(NativeTabContentsViewAura* view) |
39 : view_(view) { | 41 : view_(view) { |
40 MessageLoopForUI::current()->AddObserver(this); | 42 MessageLoopForUI::current()->AddObserver(this); |
41 } | 43 } |
42 | 44 |
43 virtual ~WebDragSourceAura() { | 45 virtual ~WebDragSourceAura() { |
44 MessageLoopForUI::current()->RemoveObserver(this); | 46 MessageLoopForUI::current()->RemoveObserver(this); |
45 } | 47 } |
46 | 48 |
47 // MessageLoop::Observer implementation: | 49 // MessageLoop::Observer implementation: |
48 virtual base::EventStatus WillProcessEvent( | 50 virtual base::EventStatus WillProcessEvent( |
49 const base::NativeEvent& event) OVERRIDE { | 51 const base::NativeEvent& event) OVERRIDE { |
50 return base::EVENT_CONTINUE; | 52 return base::EVENT_CONTINUE; |
51 } | 53 } |
52 virtual void DidProcessEvent(const base::NativeEvent& event) OVERRIDE { | 54 virtual void DidProcessEvent(const base::NativeEvent& event) OVERRIDE { |
55 #if defined(USE_ASH) | |
53 ui::EventType type = ui::EventTypeFromNative(event); | 56 ui::EventType type = ui::EventTypeFromNative(event); |
54 RenderViewHost* rvh = NULL; | 57 RenderViewHost* rvh = NULL; |
55 switch (type) { | 58 switch (type) { |
56 case ui::ET_MOUSE_DRAGGED: | 59 case ui::ET_MOUSE_DRAGGED: |
57 rvh = view_->GetWebContents()->GetRenderViewHost(); | 60 rvh = view_->GetWebContents()->GetRenderViewHost(); |
58 if (rvh) { | 61 if (rvh) { |
59 gfx::Point screen_loc = ui::EventLocationFromNative(event); | 62 gfx::Point screen_loc = ui::EventLocationFromNative(event); |
60 gfx::Point client_loc = screen_loc; | 63 gfx::Point client_loc = screen_loc; |
61 aura::Window* window = rvh->view()->GetNativeView(); | 64 aura::Window* window = rvh->view()->GetNativeView(); |
62 aura::Window::ConvertPointToWindow(ash::Shell::GetRootWindow(), | 65 aura::Window::ConvertPointToWindow(ash::Shell::GetRootWindow(), |
Ben Goodger (Google)
2012/02/28 20:12:06
if you rewrite this slightly, replacing ash::Shell
| |
63 window, &client_loc); | 66 window, &client_loc); |
64 rvh->DragSourceMovedTo(client_loc.x(), client_loc.y(), | 67 rvh->DragSourceMovedTo(client_loc.x(), client_loc.y(), |
65 screen_loc.x(), screen_loc.y()); | 68 screen_loc.x(), screen_loc.y()); |
66 } | 69 } |
67 break; | 70 break; |
68 default: | 71 default: |
69 break; | 72 break; |
70 } | 73 } |
74 #else | |
75 NOTIMPLEMENTED(); | |
76 #endif | |
71 } | 77 } |
72 | 78 |
79 | |
73 private: | 80 private: |
74 NativeTabContentsViewAura* view_; | 81 NativeTabContentsViewAura* view_; |
75 | 82 |
76 DISALLOW_COPY_AND_ASSIGN(WebDragSourceAura); | 83 DISALLOW_COPY_AND_ASSIGN(WebDragSourceAura); |
77 }; | 84 }; |
78 | 85 |
79 // Utility to fill a ui::OSExchangeDataProviderAura object from WebDropData. | 86 // Utility to fill a ui::OSExchangeDataProviderAura object from WebDropData. |
80 void PrepareDragData(const WebDropData& drop_data, | 87 void PrepareDragData(const WebDropData& drop_data, |
81 ui::OSExchangeDataProviderAura* provider) { | 88 ui::OSExchangeDataProviderAura* provider) { |
82 if (!drop_data.plain_text.empty()) | 89 if (!drop_data.plain_text.empty()) |
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
150 | 157 |
151 void NativeTabContentsViewAura::InitNativeTabContentsView() { | 158 void NativeTabContentsViewAura::InitNativeTabContentsView() { |
152 views::Widget::InitParams params(views::Widget::InitParams::TYPE_CONTROL); | 159 views::Widget::InitParams params(views::Widget::InitParams::TYPE_CONTROL); |
153 params.native_widget = this; | 160 params.native_widget = this; |
154 // We don't draw anything so we don't need a texture. | 161 // We don't draw anything so we don't need a texture. |
155 params.create_texture_for_layer = false; | 162 params.create_texture_for_layer = false; |
156 params.ownership = views::Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET; | 163 params.ownership = views::Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET; |
157 params.parent = NULL; | 164 params.parent = NULL; |
158 params.can_activate = true; | 165 params.can_activate = true; |
159 GetWidget()->Init(params); | 166 GetWidget()->Init(params); |
167 #if defined(USE_ASH) | |
160 ash::SetChildWindowVisibilityChangesAnimated(GetWidget()->GetNativeView()); | 168 ash::SetChildWindowVisibilityChangesAnimated(GetWidget()->GetNativeView()); |
169 #else | |
170 NOTIMPLEMENTED() << "Need to animate in"; | |
171 #endif | |
161 | 172 |
162 // Hide the widget to prevent it from showing up on the root window. This is | 173 // Hide the widget to prevent it from showing up on the root window. This is |
163 // needed for TabContentses that aren't immediately added to the tabstrip, | 174 // needed for TabContentses that aren't immediately added to the tabstrip, |
164 // e.g. the Instant preview contents. | 175 // e.g. the Instant preview contents. |
165 // TODO(beng): investigate if control-type windows shouldn't be hidden by | 176 // TODO(beng): investigate if control-type windows shouldn't be hidden by |
166 // default if they are created with no parent. Pending oshima's | 177 // default if they are created with no parent. Pending oshima's |
167 // change to reflect Widget types onto a ViewProp. | 178 // change to reflect Widget types onto a ViewProp. |
168 GetWidget()->Hide(); | 179 GetWidget()->Hide(); |
169 } | 180 } |
170 | 181 |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
205 return; | 216 return; |
206 | 217 |
207 ui::OSExchangeDataProviderAura* provider = new ui::OSExchangeDataProviderAura; | 218 ui::OSExchangeDataProviderAura* provider = new ui::OSExchangeDataProviderAura; |
208 PrepareDragData(drop_data, provider); | 219 PrepareDragData(drop_data, provider); |
209 if (!image.isNull()) | 220 if (!image.isNull()) |
210 provider->set_drag_image(image); | 221 provider->set_drag_image(image); |
211 ui::OSExchangeData data(provider); // takes ownership of |provider|. | 222 ui::OSExchangeData data(provider); // takes ownership of |provider|. |
212 | 223 |
213 scoped_ptr<WebDragSourceAura> drag_source(new WebDragSourceAura(this)); | 224 scoped_ptr<WebDragSourceAura> drag_source(new WebDragSourceAura(this)); |
214 | 225 |
226 #if defined(USE_ASH) | |
Ben Goodger (Google)
2012/02/28 20:12:06
I don't see why this is Ash-specific?
| |
215 // We need to enable recursive tasks on the message loop so we can get | 227 // We need to enable recursive tasks on the message loop so we can get |
216 // updates while in the system DoDragDrop loop. | 228 // updates while in the system DoDragDrop loop. |
217 int result_op = 0; | 229 int result_op = 0; |
218 { | 230 { |
219 // TODO(sad): Avoid using last_mouse_location here, since the drag may not | 231 // TODO(sad): Avoid using last_mouse_location here, since the drag may not |
220 // always start from a mouse-event (e.g. a touch or gesture event could | 232 // always start from a mouse-event (e.g. a touch or gesture event could |
221 // initiate the drag). The location information should be carried over from | 233 // initiate the drag). The location information should be carried over from |
222 // webkit. http://crbug.com/114754 | 234 // webkit. http://crbug.com/114754 |
223 gfx::Point location(root_window->last_mouse_location()); | 235 gfx::Point location(root_window->last_mouse_location()); |
224 location.Offset(-image_offset.x(), -image_offset.y()); | 236 location.Offset(-image_offset.x(), -image_offset.y()); |
225 MessageLoop::ScopedNestableTaskAllower allow(MessageLoop::current()); | 237 MessageLoop::ScopedNestableTaskAllower allow(MessageLoop::current()); |
226 result_op = aura::client::GetDragDropClient(root_window)->StartDragAndDrop( | 238 result_op = aura::client::GetDragDropClient(root_window)->StartDragAndDrop( |
227 data, location, ConvertFromWeb(ops)); | 239 data, location, ConvertFromWeb(ops)); |
228 } | 240 } |
241 EndDrag(ConvertToWeb(result_op)); | |
242 #else | |
243 NOTIMPLEMENTED() << "Drops without ash aren't implemented."; | |
244 #endif | |
229 | 245 |
230 EndDrag(ConvertToWeb(result_op)); | |
231 GetWebContents()->GetRenderViewHost()->DragSourceSystemDragEnded(); | 246 GetWebContents()->GetRenderViewHost()->DragSourceSystemDragEnded(); |
232 } | 247 } |
233 | 248 |
234 void NativeTabContentsViewAura::CancelDrag() { | 249 void NativeTabContentsViewAura::CancelDrag() { |
235 aura::RootWindow* root_window = GetNativeView()->GetRootWindow(); | 250 aura::RootWindow* root_window = GetNativeView()->GetRootWindow(); |
236 if (aura::client::GetDragDropClient(root_window)) | 251 if (aura::client::GetDragDropClient(root_window)) |
237 aura::client::GetDragDropClient(root_window)->DragCancel(); | 252 aura::client::GetDragDropClient(root_window)->DragCancel(); |
238 } | 253 } |
239 | 254 |
240 bool NativeTabContentsViewAura::IsDoingDrag() const { | 255 bool NativeTabContentsViewAura::IsDoingDrag() const { |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
277 } | 292 } |
278 } | 293 } |
279 // Pass all mouse event to renderer. | 294 // Pass all mouse event to renderer. |
280 return views::NativeWidgetAura::OnMouseEvent(event); | 295 return views::NativeWidgetAura::OnMouseEvent(event); |
281 } | 296 } |
282 | 297 |
283 void NativeTabContentsViewAura::OnDragEntered( | 298 void NativeTabContentsViewAura::OnDragEntered( |
284 const aura::DropTargetEvent& event) { | 299 const aura::DropTargetEvent& event) { |
285 WebDropData drop_data; | 300 WebDropData drop_data; |
286 PrepareWebDropData(&drop_data, event.data()); | 301 PrepareWebDropData(&drop_data, event.data()); |
302 #if defined(USE_ASH) | |
287 WebKit::WebDragOperationsMask op = ConvertToWeb(event.source_operations()); | 303 WebKit::WebDragOperationsMask op = ConvertToWeb(event.source_operations()); |
288 | 304 |
289 gfx::Point screen_pt = ash::Shell::GetRootWindow()->last_mouse_location(); | 305 gfx::Point screen_pt = ash::Shell::GetRootWindow()->last_mouse_location(); |
Ben Goodger (Google)
2012/02/28 20:12:06
replace ash::Shell::GetRootWindow() with:
GetNati
| |
290 GetWebContents()->GetRenderViewHost()->DragTargetDragEnter( | 306 GetWebContents()->GetRenderViewHost()->DragTargetDragEnter( |
291 drop_data, event.location(), screen_pt, op); | 307 drop_data, event.location(), screen_pt, op); |
308 #else | |
309 NOTIMPLEMENTED(); | |
310 #endif | |
292 } | 311 } |
293 | 312 |
294 int NativeTabContentsViewAura::OnDragUpdated( | 313 int NativeTabContentsViewAura::OnDragUpdated( |
295 const aura::DropTargetEvent& event) { | 314 const aura::DropTargetEvent& event) { |
315 #if defined(USE_ASH) | |
296 WebKit::WebDragOperationsMask op = ConvertToWeb(event.source_operations()); | 316 WebKit::WebDragOperationsMask op = ConvertToWeb(event.source_operations()); |
297 gfx::Point screen_pt = ash::Shell::GetRootWindow()->last_mouse_location(); | 317 gfx::Point screen_pt = ash::Shell::GetRootWindow()->last_mouse_location(); |
Ben Goodger (Google)
2012/02/28 20:12:06
same here
| |
298 GetWebContents()->GetRenderViewHost()->DragTargetDragOver( | 318 GetWebContents()->GetRenderViewHost()->DragTargetDragOver( |
299 event.location(), screen_pt, op); | 319 event.location(), screen_pt, op); |
300 return ConvertFromWeb(current_drag_op_); | 320 return ConvertFromWeb(current_drag_op_); |
321 #else | |
322 NOTIMPLEMENTED(); | |
323 return -1; | |
324 #endif | |
301 } | 325 } |
302 | 326 |
303 void NativeTabContentsViewAura::OnDragExited() { | 327 void NativeTabContentsViewAura::OnDragExited() { |
304 GetWebContents()->GetRenderViewHost()->DragTargetDragLeave(); | 328 GetWebContents()->GetRenderViewHost()->DragTargetDragLeave(); |
305 } | 329 } |
306 | 330 |
307 int NativeTabContentsViewAura::OnPerformDrop( | 331 int NativeTabContentsViewAura::OnPerformDrop( |
308 const aura::DropTargetEvent& event) { | 332 const aura::DropTargetEvent& event) { |
333 #if defined(USE_ASH) | |
309 GetWebContents()->GetRenderViewHost()->DragTargetDrop( | 334 GetWebContents()->GetRenderViewHost()->DragTargetDrop( |
310 event.location(), ash::Shell::GetRootWindow()->last_mouse_location()); | 335 event.location(), ash::Shell::GetRootWindow()->last_mouse_location()); |
Ben Goodger (Google)
2012/02/28 20:12:06
and here
| |
311 return current_drag_op_; | 336 return current_drag_op_; |
337 #else | |
338 NOTIMPLEMENTED(); | |
339 return -1; | |
340 #endif | |
312 } | 341 } |
313 | 342 |
314 //////////////////////////////////////////////////////////////////////////////// | 343 //////////////////////////////////////////////////////////////////////////////// |
315 // NativeTabContentsViewAura, private: | 344 // NativeTabContentsViewAura, private: |
316 | 345 |
317 void NativeTabContentsViewAura::EndDrag(WebKit::WebDragOperationsMask ops) { | 346 void NativeTabContentsViewAura::EndDrag(WebKit::WebDragOperationsMask ops) { |
347 #if defined(USE_ASH) | |
318 gfx::Point screen_loc = | 348 gfx::Point screen_loc = |
319 ash::Shell::GetRootWindow()->last_mouse_location(); | 349 ash::Shell::GetRootWindow()->last_mouse_location(); |
Ben Goodger (Google)
2012/02/28 20:12:06
and here
| |
320 gfx::Point client_loc = screen_loc; | 350 gfx::Point client_loc = screen_loc; |
321 RenderViewHost* rvh = GetWebContents()->GetRenderViewHost(); | 351 RenderViewHost* rvh = GetWebContents()->GetRenderViewHost(); |
322 aura::Window* window = rvh->view()->GetNativeView(); | 352 aura::Window* window = rvh->view()->GetNativeView(); |
323 aura::Window::ConvertPointToWindow(ash::Shell::GetRootWindow(), | 353 aura::Window::ConvertPointToWindow(ash::Shell::GetRootWindow(), |
324 window, &client_loc); | 354 window, &client_loc); |
325 rvh->DragSourceEndedAt(client_loc.x(), client_loc.y(), screen_loc.x(), | 355 rvh->DragSourceEndedAt(client_loc.x(), client_loc.y(), screen_loc.x(), |
326 screen_loc.y(), ops); | 356 screen_loc.y(), ops); |
357 #else | |
358 NOTIMPLEMENTED(); | |
359 #endif | |
327 } | 360 } |
328 | 361 |
329 //////////////////////////////////////////////////////////////////////////////// | 362 //////////////////////////////////////////////////////////////////////////////// |
330 // NativeTabContentsView, public: | 363 // NativeTabContentsView, public: |
331 | 364 |
332 // static | 365 // static |
333 NativeTabContentsView* NativeTabContentsView::CreateNativeTabContentsView( | 366 NativeTabContentsView* NativeTabContentsView::CreateNativeTabContentsView( |
334 internal::NativeTabContentsViewDelegate* delegate) { | 367 internal::NativeTabContentsViewDelegate* delegate) { |
335 return new NativeTabContentsViewAura(delegate); | 368 return new NativeTabContentsViewAura(delegate); |
336 } | 369 } |
OLD | NEW |