| 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 #include "base/event_types.h" | 7 #include "base/event_types.h" |
| 8 #include "base/message_loop.h" | 8 #include "base/message_loop.h" |
| 9 #include "chrome/browser/ui/sad_tab_helper.h" | 9 #include "chrome/browser/ui/sad_tab_helper.h" |
| 10 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h" | 10 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h" |
| 11 #include "chrome/browser/ui/views/tab_contents/native_tab_contents_view_delegate
.h" | 11 #include "chrome/browser/ui/views/tab_contents/native_tab_contents_view_delegate
.h" |
| 12 #include "content/public/browser/render_view_host.h" | 12 #include "content/public/browser/render_view_host.h" |
| 13 #include "content/public/browser/render_widget_host_view.h" | 13 #include "content/public/browser/render_widget_host_view.h" |
| 14 #include "content/public/browser/web_contents.h" | 14 #include "content/public/browser/web_contents.h" |
| 15 #include "content/public/browser/web_contents_view.h" | 15 #include "content/public/browser/web_contents_view.h" |
| 16 #include "content/public/browser/web_drag_dest_delegate.h" |
| 16 #include "ui/aura/client/drag_drop_client.h" | 17 #include "ui/aura/client/drag_drop_client.h" |
| 17 #include "ui/aura/client/drag_drop_delegate.h" | 18 #include "ui/aura/client/drag_drop_delegate.h" |
| 18 #include "ui/aura/event.h" | 19 #include "ui/aura/event.h" |
| 19 #include "ui/aura/root_window.h" | 20 #include "ui/aura/root_window.h" |
| 20 #include "ui/aura/window.h" | 21 #include "ui/aura/window.h" |
| 21 #include "ui/base/clipboard/clipboard.h" | 22 #include "ui/base/clipboard/clipboard.h" |
| 22 #include "ui/base/clipboard/custom_data_helper.h" | 23 #include "ui/base/clipboard/custom_data_helper.h" |
| 23 #include "ui/base/dragdrop/drag_drop_types.h" | 24 #include "ui/base/dragdrop/drag_drop_types.h" |
| 24 #include "ui/base/dragdrop/os_exchange_data.h" | 25 #include "ui/base/dragdrop/os_exchange_data.h" |
| 25 #include "ui/base/dragdrop/os_exchange_data_provider_aura.h" | 26 #include "ui/base/dragdrop/os_exchange_data_provider_aura.h" |
| (...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 156 | 157 |
| 157 } // namespace | 158 } // namespace |
| 158 | 159 |
| 159 //////////////////////////////////////////////////////////////////////////////// | 160 //////////////////////////////////////////////////////////////////////////////// |
| 160 // NativeTabContentsViewAura, public: | 161 // NativeTabContentsViewAura, public: |
| 161 | 162 |
| 162 NativeTabContentsViewAura::NativeTabContentsViewAura( | 163 NativeTabContentsViewAura::NativeTabContentsViewAura( |
| 163 internal::NativeTabContentsViewDelegate* delegate) | 164 internal::NativeTabContentsViewDelegate* delegate) |
| 164 : views::NativeWidgetAura(delegate->AsNativeWidgetDelegate()), | 165 : views::NativeWidgetAura(delegate->AsNativeWidgetDelegate()), |
| 165 delegate_(delegate), | 166 delegate_(delegate), |
| 166 current_drag_op_(WebKit::WebDragOperationNone) { | 167 current_drag_op_(WebKit::WebDragOperationNone), |
| 168 drag_dest_delegate_(NULL) { |
| 167 } | 169 } |
| 168 | 170 |
| 169 NativeTabContentsViewAura::~NativeTabContentsViewAura() { | 171 NativeTabContentsViewAura::~NativeTabContentsViewAura() { |
| 170 } | 172 } |
| 171 | 173 |
| 172 WebContents* NativeTabContentsViewAura::GetWebContents() const { | 174 WebContents* NativeTabContentsViewAura::GetWebContents() const { |
| 173 return delegate_->GetWebContents(); | 175 return delegate_->GetWebContents(); |
| 174 } | 176 } |
| 175 | 177 |
| 176 //////////////////////////////////////////////////////////////////////////////// | 178 //////////////////////////////////////////////////////////////////////////////// |
| 177 // NativeTabContentsViewAura, NativeTabContentsView implementation: | 179 // NativeTabContentsViewAura, NativeTabContentsView implementation: |
| 178 | 180 |
| 179 void NativeTabContentsViewAura::InitNativeTabContentsView() { | 181 void NativeTabContentsViewAura::InitNativeTabContentsView() { |
| 180 views::Widget::InitParams params(views::Widget::InitParams::TYPE_CONTROL); | 182 views::Widget::InitParams params(views::Widget::InitParams::TYPE_CONTROL); |
| 181 params.native_widget = this; | 183 params.native_widget = this; |
| 182 // We don't draw anything so we don't need a texture. | 184 // We don't draw anything so we don't need a texture. |
| 183 params.create_texture_for_layer = false; | 185 params.create_texture_for_layer = false; |
| 184 params.ownership = views::Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET; | 186 params.ownership = views::Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET; |
| 185 params.parent = NULL; | 187 params.parent = NULL; |
| 186 params.can_activate = true; | 188 params.can_activate = true; |
| 187 GetWidget()->Init(params); | 189 GetWidget()->Init(params); |
| 188 GetNativeView()->layer()->SetMasksToBounds(true); | 190 GetNativeView()->layer()->SetMasksToBounds(true); |
| 189 GetNativeWindow()->SetName("NativeTabContentsViewAura"); | 191 GetNativeWindow()->SetName("NativeTabContentsViewAura"); |
| 190 #if defined(USE_ASH) | 192 #if defined(USE_ASH) |
| 191 ash::SetChildWindowVisibilityChangesAnimated(GetWidget()->GetNativeView()); | 193 ash::SetChildWindowVisibilityChangesAnimated(GetWidget()->GetNativeView()); |
| 192 #else | 194 #else |
| 193 NOTIMPLEMENTED() << "Need to animate in"; | 195 NOTIMPLEMENTED() << "Need to animate in"; |
| 194 #endif | 196 #endif |
| 195 | 197 |
| 198 if (delegate_) |
| 199 drag_dest_delegate_ = delegate_->GetDragDestDelegate(); |
| 200 |
| 196 // Hide the widget to prevent it from showing up on the root window. This is | 201 // Hide the widget to prevent it from showing up on the root window. This is |
| 197 // needed for TabContentses that aren't immediately added to the tabstrip, | 202 // needed for TabContentses that aren't immediately added to the tabstrip, |
| 198 // e.g. the Instant preview contents. | 203 // e.g. the Instant preview contents. |
| 199 // TODO(beng): investigate if control-type windows shouldn't be hidden by | 204 // TODO(beng): investigate if control-type windows shouldn't be hidden by |
| 200 // default if they are created with no parent. Pending oshima's | 205 // default if they are created with no parent. Pending oshima's |
| 201 // change to reflect Widget types onto a ViewProp. | 206 // change to reflect Widget types onto a ViewProp. |
| 202 GetWidget()->Hide(); | 207 GetWidget()->Hide(); |
| 203 } | 208 } |
| 204 | 209 |
| 205 RenderWidgetHostView* NativeTabContentsViewAura::CreateRenderWidgetHostView( | 210 RenderWidgetHostView* NativeTabContentsViewAura::CreateRenderWidgetHostView( |
| (...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 307 // TODO(oshima): mouse wheel | 312 // TODO(oshima): mouse wheel |
| 308 break; | 313 break; |
| 309 } | 314 } |
| 310 } | 315 } |
| 311 // Pass all mouse event to renderer. | 316 // Pass all mouse event to renderer. |
| 312 return views::NativeWidgetAura::OnMouseEvent(event); | 317 return views::NativeWidgetAura::OnMouseEvent(event); |
| 313 } | 318 } |
| 314 | 319 |
| 315 void NativeTabContentsViewAura::OnDragEntered( | 320 void NativeTabContentsViewAura::OnDragEntered( |
| 316 const aura::DropTargetEvent& event) { | 321 const aura::DropTargetEvent& event) { |
| 322 if (drag_dest_delegate_) |
| 323 drag_dest_delegate_->DragInitialize(GetWebContents()); |
| 324 |
| 317 WebDropData drop_data; | 325 WebDropData drop_data; |
| 318 PrepareWebDropData(&drop_data, event.data()); | 326 PrepareWebDropData(&drop_data, event.data()); |
| 319 WebKit::WebDragOperationsMask op = ConvertToWeb(event.source_operations()); | 327 WebKit::WebDragOperationsMask op = ConvertToWeb(event.source_operations()); |
| 320 | 328 |
| 321 gfx::Point screen_pt = | 329 gfx::Point screen_pt = |
| 322 GetNativeView()->GetRootWindow()->last_mouse_location(); | 330 GetNativeView()->GetRootWindow()->last_mouse_location(); |
| 323 GetWebContents()->GetRenderViewHost()->DragTargetDragEnter( | 331 GetWebContents()->GetRenderViewHost()->DragTargetDragEnter( |
| 324 drop_data, event.location(), screen_pt, op); | 332 drop_data, event.location(), screen_pt, op); |
| 333 |
| 334 if (drag_dest_delegate_) { |
| 335 drag_dest_delegate_->OnReceiveDragData(event.data()); |
| 336 drag_dest_delegate_->OnDragEnter(); |
| 337 } |
| 325 } | 338 } |
| 326 | 339 |
| 327 int NativeTabContentsViewAura::OnDragUpdated( | 340 int NativeTabContentsViewAura::OnDragUpdated( |
| 328 const aura::DropTargetEvent& event) { | 341 const aura::DropTargetEvent& event) { |
| 329 WebKit::WebDragOperationsMask op = ConvertToWeb(event.source_operations()); | 342 WebKit::WebDragOperationsMask op = ConvertToWeb(event.source_operations()); |
| 330 gfx::Point screen_pt = | 343 gfx::Point screen_pt = |
| 331 GetNativeView()->GetRootWindow()->last_mouse_location(); | 344 GetNativeView()->GetRootWindow()->last_mouse_location(); |
| 332 GetWebContents()->GetRenderViewHost()->DragTargetDragOver( | 345 GetWebContents()->GetRenderViewHost()->DragTargetDragOver( |
| 333 event.location(), screen_pt, op); | 346 event.location(), screen_pt, op); |
| 347 |
| 348 if (drag_dest_delegate_) |
| 349 drag_dest_delegate_->OnDragOver(); |
| 350 |
| 334 return ConvertFromWeb(current_drag_op_); | 351 return ConvertFromWeb(current_drag_op_); |
| 335 } | 352 } |
| 336 | 353 |
| 337 void NativeTabContentsViewAura::OnDragExited() { | 354 void NativeTabContentsViewAura::OnDragExited() { |
| 338 GetWebContents()->GetRenderViewHost()->DragTargetDragLeave(); | 355 GetWebContents()->GetRenderViewHost()->DragTargetDragLeave(); |
| 356 if (drag_dest_delegate_) |
| 357 drag_dest_delegate_->OnDragLeave(); |
| 339 } | 358 } |
| 340 | 359 |
| 341 int NativeTabContentsViewAura::OnPerformDrop( | 360 int NativeTabContentsViewAura::OnPerformDrop( |
| 342 const aura::DropTargetEvent& event) { | 361 const aura::DropTargetEvent& event) { |
| 343 GetWebContents()->GetRenderViewHost()->DragTargetDrop( | 362 GetWebContents()->GetRenderViewHost()->DragTargetDrop( |
| 344 event.location(), | 363 event.location(), |
| 345 GetNativeView()->GetRootWindow()->last_mouse_location()); | 364 GetNativeView()->GetRootWindow()->last_mouse_location()); |
| 365 if (drag_dest_delegate_) |
| 366 drag_dest_delegate_->OnDrop(); |
| 346 return current_drag_op_; | 367 return current_drag_op_; |
| 347 } | 368 } |
| 348 | 369 |
| 349 //////////////////////////////////////////////////////////////////////////////// | 370 //////////////////////////////////////////////////////////////////////////////// |
| 350 // NativeTabContentsViewAura, private: | 371 // NativeTabContentsViewAura, private: |
| 351 | 372 |
| 352 void NativeTabContentsViewAura::EndDrag(WebKit::WebDragOperationsMask ops) { | 373 void NativeTabContentsViewAura::EndDrag(WebKit::WebDragOperationsMask ops) { |
| 353 aura::RootWindow* root_window = GetNativeView()->GetRootWindow(); | 374 aura::RootWindow* root_window = GetNativeView()->GetRootWindow(); |
| 354 gfx::Point screen_loc = root_window->last_mouse_location(); | 375 gfx::Point screen_loc = root_window->last_mouse_location(); |
| 355 gfx::Point client_loc = screen_loc; | 376 gfx::Point client_loc = screen_loc; |
| 356 RenderViewHost* rvh = GetWebContents()->GetRenderViewHost(); | 377 RenderViewHost* rvh = GetWebContents()->GetRenderViewHost(); |
| 357 aura::Window* window = rvh->GetView()->GetNativeView(); | 378 aura::Window* window = rvh->GetView()->GetNativeView(); |
| 358 aura::Window::ConvertPointToWindow(root_window, window, &client_loc); | 379 aura::Window::ConvertPointToWindow(root_window, window, &client_loc); |
| 359 rvh->DragSourceEndedAt(client_loc.x(), client_loc.y(), screen_loc.x(), | 380 rvh->DragSourceEndedAt(client_loc.x(), client_loc.y(), screen_loc.x(), |
| 360 screen_loc.y(), ops); | 381 screen_loc.y(), ops); |
| 361 } | 382 } |
| 362 | 383 |
| 363 //////////////////////////////////////////////////////////////////////////////// | 384 //////////////////////////////////////////////////////////////////////////////// |
| 364 // NativeTabContentsView, public: | 385 // NativeTabContentsView, public: |
| 365 | 386 |
| 366 // static | 387 // static |
| 367 NativeTabContentsView* NativeTabContentsView::CreateNativeTabContentsView( | 388 NativeTabContentsView* NativeTabContentsView::CreateNativeTabContentsView( |
| 368 internal::NativeTabContentsViewDelegate* delegate) { | 389 internal::NativeTabContentsViewDelegate* delegate) { |
| 369 return new NativeTabContentsViewAura(delegate); | 390 return new NativeTabContentsViewAura(delegate); |
| 370 } | 391 } |
| OLD | NEW |