| 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) | 
| (...skipping 13 matching lines...) Expand all  Loading... | 
|   52   virtual void DidProcessEvent(const base::NativeEvent& event) OVERRIDE { |   54   virtual void DidProcessEvent(const base::NativeEvent& event) OVERRIDE { | 
|   53     ui::EventType type = ui::EventTypeFromNative(event); |   55     ui::EventType type = ui::EventTypeFromNative(event); | 
|   54     RenderViewHost* rvh = NULL; |   56     RenderViewHost* rvh = NULL; | 
|   55     switch (type) { |   57     switch (type) { | 
|   56       case ui::ET_MOUSE_DRAGGED: |   58       case ui::ET_MOUSE_DRAGGED: | 
|   57         rvh = view_->GetWebContents()->GetRenderViewHost(); |   59         rvh = view_->GetWebContents()->GetRenderViewHost(); | 
|   58         if (rvh) { |   60         if (rvh) { | 
|   59           gfx::Point screen_loc = ui::EventLocationFromNative(event); |   61           gfx::Point screen_loc = ui::EventLocationFromNative(event); | 
|   60           gfx::Point client_loc = screen_loc; |   62           gfx::Point client_loc = screen_loc; | 
|   61           aura::Window* window = rvh->view()->GetNativeView(); |   63           aura::Window* window = rvh->view()->GetNativeView(); | 
|   62           aura::Window::ConvertPointToWindow(ash::Shell::GetRootWindow(), |   64           aura::Window::ConvertPointToWindow(window->GetRootWindow(), | 
|   63               window, &client_loc); |   65               window, &client_loc); | 
|   64           rvh->DragSourceMovedTo(client_loc.x(), client_loc.y(), |   66           rvh->DragSourceMovedTo(client_loc.x(), client_loc.y(), | 
|   65               screen_loc.x(), screen_loc.y()); |   67               screen_loc.x(), screen_loc.y()); | 
|   66         } |   68         } | 
|   67         break; |   69         break; | 
|   68       default: |   70       default: | 
|   69         break; |   71         break; | 
|   70     } |   72     } | 
|   71   } |   73   } | 
|   72  |   74  | 
 |   75  | 
|   73  private: |   76  private: | 
|   74   NativeTabContentsViewAura* view_; |   77   NativeTabContentsViewAura* view_; | 
|   75  |   78  | 
|   76   DISALLOW_COPY_AND_ASSIGN(WebDragSourceAura); |   79   DISALLOW_COPY_AND_ASSIGN(WebDragSourceAura); | 
|   77 }; |   80 }; | 
|   78  |   81  | 
|   79 // Utility to fill a ui::OSExchangeDataProviderAura object from WebDropData. |   82 // Utility to fill a ui::OSExchangeDataProviderAura object from WebDropData. | 
|   80 void PrepareDragData(const WebDropData& drop_data, |   83 void PrepareDragData(const WebDropData& drop_data, | 
|   81                      ui::OSExchangeDataProviderAura* provider) { |   84                      ui::OSExchangeDataProviderAura* provider) { | 
|   82   if (!drop_data.plain_text.empty()) |   85   if (!drop_data.plain_text.empty()) | 
| (...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
|  150  |  153  | 
|  151 void NativeTabContentsViewAura::InitNativeTabContentsView() { |  154 void NativeTabContentsViewAura::InitNativeTabContentsView() { | 
|  152   views::Widget::InitParams params(views::Widget::InitParams::TYPE_CONTROL); |  155   views::Widget::InitParams params(views::Widget::InitParams::TYPE_CONTROL); | 
|  153   params.native_widget = this; |  156   params.native_widget = this; | 
|  154   // We don't draw anything so we don't need a texture. |  157   // We don't draw anything so we don't need a texture. | 
|  155   params.create_texture_for_layer = false; |  158   params.create_texture_for_layer = false; | 
|  156   params.ownership = views::Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET; |  159   params.ownership = views::Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET; | 
|  157   params.parent = NULL; |  160   params.parent = NULL; | 
|  158   params.can_activate = true; |  161   params.can_activate = true; | 
|  159   GetWidget()->Init(params); |  162   GetWidget()->Init(params); | 
 |  163 #if defined(USE_ASH) | 
|  160   ash::SetChildWindowVisibilityChangesAnimated(GetWidget()->GetNativeView()); |  164   ash::SetChildWindowVisibilityChangesAnimated(GetWidget()->GetNativeView()); | 
 |  165 #else | 
 |  166   NOTIMPLEMENTED() << "Need to animate in"; | 
 |  167 #endif | 
|  161  |  168  | 
|  162   // Hide the widget to prevent it from showing up on the root window. This is |  169   // 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, |  170   // needed for TabContentses that aren't immediately added to the tabstrip, | 
|  164   // e.g. the Instant preview contents. |  171   // e.g. the Instant preview contents. | 
|  165   // TODO(beng): investigate if control-type windows shouldn't be hidden by |  172   // TODO(beng): investigate if control-type windows shouldn't be hidden by | 
|  166   //             default if they are created with no parent. Pending oshima's |  173   //             default if they are created with no parent. Pending oshima's | 
|  167   //             change to reflect Widget types onto a ViewProp. |  174   //             change to reflect Widget types onto a ViewProp. | 
|  168   GetWidget()->Hide(); |  175   GetWidget()->Hide(); | 
|  169 } |  176 } | 
|  170  |  177  | 
| (...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
|  279   // Pass all mouse event to renderer. |  286   // Pass all mouse event to renderer. | 
|  280   return views::NativeWidgetAura::OnMouseEvent(event); |  287   return views::NativeWidgetAura::OnMouseEvent(event); | 
|  281 } |  288 } | 
|  282  |  289  | 
|  283 void NativeTabContentsViewAura::OnDragEntered( |  290 void NativeTabContentsViewAura::OnDragEntered( | 
|  284     const aura::DropTargetEvent& event) { |  291     const aura::DropTargetEvent& event) { | 
|  285   WebDropData drop_data; |  292   WebDropData drop_data; | 
|  286   PrepareWebDropData(&drop_data, event.data()); |  293   PrepareWebDropData(&drop_data, event.data()); | 
|  287   WebKit::WebDragOperationsMask op = ConvertToWeb(event.source_operations()); |  294   WebKit::WebDragOperationsMask op = ConvertToWeb(event.source_operations()); | 
|  288  |  295  | 
|  289   gfx::Point screen_pt = ash::Shell::GetRootWindow()->last_mouse_location(); |  296   gfx::Point screen_pt = | 
 |  297       GetNativeView()->GetRootWindow()->last_mouse_location(); | 
|  290   GetWebContents()->GetRenderViewHost()->DragTargetDragEnter( |  298   GetWebContents()->GetRenderViewHost()->DragTargetDragEnter( | 
|  291       drop_data, event.location(), screen_pt, op); |  299       drop_data, event.location(), screen_pt, op); | 
|  292 } |  300 } | 
|  293  |  301  | 
|  294 int NativeTabContentsViewAura::OnDragUpdated( |  302 int NativeTabContentsViewAura::OnDragUpdated( | 
|  295     const aura::DropTargetEvent& event) { |  303     const aura::DropTargetEvent& event) { | 
|  296   WebKit::WebDragOperationsMask op = ConvertToWeb(event.source_operations()); |  304   WebKit::WebDragOperationsMask op = ConvertToWeb(event.source_operations()); | 
|  297   gfx::Point screen_pt = ash::Shell::GetRootWindow()->last_mouse_location(); |  305   gfx::Point screen_pt = | 
 |  306       GetNativeView()->GetRootWindow()->last_mouse_location(); | 
|  298   GetWebContents()->GetRenderViewHost()->DragTargetDragOver( |  307   GetWebContents()->GetRenderViewHost()->DragTargetDragOver( | 
|  299       event.location(), screen_pt, op); |  308       event.location(), screen_pt, op); | 
|  300   return ConvertFromWeb(current_drag_op_); |  309   return ConvertFromWeb(current_drag_op_); | 
|  301 } |  310 } | 
|  302  |  311  | 
|  303 void NativeTabContentsViewAura::OnDragExited() { |  312 void NativeTabContentsViewAura::OnDragExited() { | 
|  304   GetWebContents()->GetRenderViewHost()->DragTargetDragLeave(); |  313   GetWebContents()->GetRenderViewHost()->DragTargetDragLeave(); | 
|  305 } |  314 } | 
|  306  |  315  | 
|  307 int NativeTabContentsViewAura::OnPerformDrop( |  316 int NativeTabContentsViewAura::OnPerformDrop( | 
|  308     const aura::DropTargetEvent& event) { |  317     const aura::DropTargetEvent& event) { | 
|  309   GetWebContents()->GetRenderViewHost()->DragTargetDrop( |  318   GetWebContents()->GetRenderViewHost()->DragTargetDrop( | 
|  310       event.location(), ash::Shell::GetRootWindow()->last_mouse_location()); |  319       event.location(), | 
 |  320       GetNativeView()->GetRootWindow()->last_mouse_location()); | 
|  311   return current_drag_op_; |  321   return current_drag_op_; | 
|  312 } |  322 } | 
|  313  |  323  | 
|  314 //////////////////////////////////////////////////////////////////////////////// |  324 //////////////////////////////////////////////////////////////////////////////// | 
|  315 // NativeTabContentsViewAura, private: |  325 // NativeTabContentsViewAura, private: | 
|  316  |  326  | 
|  317 void NativeTabContentsViewAura::EndDrag(WebKit::WebDragOperationsMask ops) { |  327 void NativeTabContentsViewAura::EndDrag(WebKit::WebDragOperationsMask ops) { | 
|  318   gfx::Point screen_loc = |  328   aura::RootWindow* root_window = GetNativeView()->GetRootWindow(); | 
|  319       ash::Shell::GetRootWindow()->last_mouse_location(); |  329   gfx::Point screen_loc = root_window->last_mouse_location(); | 
|  320   gfx::Point client_loc = screen_loc; |  330   gfx::Point client_loc = screen_loc; | 
|  321   RenderViewHost* rvh = GetWebContents()->GetRenderViewHost(); |  331   RenderViewHost* rvh = GetWebContents()->GetRenderViewHost(); | 
|  322   aura::Window* window = rvh->view()->GetNativeView(); |  332   aura::Window* window = rvh->view()->GetNativeView(); | 
|  323   aura::Window::ConvertPointToWindow(ash::Shell::GetRootWindow(), |  333   aura::Window::ConvertPointToWindow(root_window, window, &client_loc); | 
|  324       window, &client_loc); |  | 
|  325   rvh->DragSourceEndedAt(client_loc.x(), client_loc.y(), screen_loc.x(), |  334   rvh->DragSourceEndedAt(client_loc.x(), client_loc.y(), screen_loc.x(), | 
|  326       screen_loc.y(), ops); |  335       screen_loc.y(), ops); | 
|  327 } |  336 } | 
|  328  |  337  | 
|  329 //////////////////////////////////////////////////////////////////////////////// |  338 //////////////////////////////////////////////////////////////////////////////// | 
|  330 // NativeTabContentsView, public: |  339 // NativeTabContentsView, public: | 
|  331  |  340  | 
|  332 // static |  341 // static | 
|  333 NativeTabContentsView* NativeTabContentsView::CreateNativeTabContentsView( |  342 NativeTabContentsView* NativeTabContentsView::CreateNativeTabContentsView( | 
|  334     internal::NativeTabContentsViewDelegate* delegate) { |  343     internal::NativeTabContentsViewDelegate* delegate) { | 
|  335   return new NativeTabContentsViewAura(delegate); |  344   return new NativeTabContentsViewAura(delegate); | 
|  336 } |  345 } | 
| OLD | NEW |