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 "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/views/tab_contents/native_tab_contents_view_delegate
.h" | 9 #include "chrome/browser/ui/views/tab_contents/native_tab_contents_view_delegate
.h" |
10 #include "content/browser/renderer_host/render_view_host.h" | 10 #include "content/browser/renderer_host/render_view_host.h" |
11 #include "content/browser/renderer_host/render_widget_host_view_aura.h" | 11 #include "content/browser/renderer_host/render_widget_host_view_aura.h" |
12 #include "content/browser/tab_contents/tab_contents.h" | 12 #include "content/browser/tab_contents/tab_contents.h" |
13 #include "content/browser/tab_contents/tab_contents_view.h" | 13 #include "content/browser/tab_contents/tab_contents_view.h" |
14 #include "ui/aura/client/aura_constants.h" | |
15 #include "ui/aura/client/drag_drop_client.h" | 14 #include "ui/aura/client/drag_drop_client.h" |
| 15 #include "ui/aura/client/drag_drop_delegate.h" |
16 #include "ui/aura/root_window.h" | 16 #include "ui/aura/root_window.h" |
17 #include "ui/aura/event.h" | 17 #include "ui/aura/event.h" |
18 #include "ui/aura/window.h" | 18 #include "ui/aura/window.h" |
19 #include "ui/base/dragdrop/drag_drop_types.h" | 19 #include "ui/base/dragdrop/drag_drop_types.h" |
20 #include "ui/base/dragdrop/os_exchange_data.h" | 20 #include "ui/base/dragdrop/os_exchange_data.h" |
21 #include "ui/base/dragdrop/os_exchange_data_provider_aura.h" | 21 #include "ui/base/dragdrop/os_exchange_data_provider_aura.h" |
22 #include "ui/views/views_delegate.h" | 22 #include "ui/views/views_delegate.h" |
23 #include "ui/views/widget/widget.h" | 23 #include "ui/views/widget/widget.h" |
24 #include "webkit/glue/webdropdata.h" | 24 #include "webkit/glue/webdropdata.h" |
25 | 25 |
(...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
166 | 166 |
167 RenderWidgetHostView* NativeTabContentsViewAura::CreateRenderWidgetHostView( | 167 RenderWidgetHostView* NativeTabContentsViewAura::CreateRenderWidgetHostView( |
168 RenderWidgetHost* render_widget_host) { | 168 RenderWidgetHost* render_widget_host) { |
169 RenderWidgetHostViewAura* view = | 169 RenderWidgetHostViewAura* view = |
170 new RenderWidgetHostViewAura(render_widget_host); | 170 new RenderWidgetHostViewAura(render_widget_host); |
171 view->InitAsChild(); | 171 view->InitAsChild(); |
172 GetNativeView()->AddChild(view->GetNativeView()); | 172 GetNativeView()->AddChild(view->GetNativeView()); |
173 view->Show(); | 173 view->Show(); |
174 | 174 |
175 // We listen to drag drop events in the newly created view's window. | 175 // We listen to drag drop events in the newly created view's window. |
176 aura::Window* window = static_cast<aura::Window*>(view->GetNativeView()); | 176 aura::client::SetDragDropDelegate(view->GetNativeView(), this); |
177 DCHECK(window); | |
178 window->SetProperty(aura::kDragDropDelegateKey, | |
179 static_cast<aura::WindowDragDropDelegate*>(this)); | |
180 return view; | 177 return view; |
181 } | 178 } |
182 | 179 |
183 gfx::NativeWindow NativeTabContentsViewAura::GetTopLevelNativeWindow() const { | 180 gfx::NativeWindow NativeTabContentsViewAura::GetTopLevelNativeWindow() const { |
184 // TODO(beng): | 181 // TODO(beng): |
185 NOTIMPLEMENTED(); | 182 NOTIMPLEMENTED(); |
186 return NULL; | 183 return NULL; |
187 } | 184 } |
188 | 185 |
189 void NativeTabContentsViewAura::SetPageTitle(const string16& title) { | 186 void NativeTabContentsViewAura::SetPageTitle(const string16& title) { |
190 GetNativeView()->set_title(title); | 187 GetNativeView()->set_title(title); |
191 } | 188 } |
192 | 189 |
193 void NativeTabContentsViewAura::StartDragging(const WebDropData& drop_data, | 190 void NativeTabContentsViewAura::StartDragging(const WebDropData& drop_data, |
194 WebKit::WebDragOperationsMask ops, | 191 WebKit::WebDragOperationsMask ops, |
195 const SkBitmap& image, | 192 const SkBitmap& image, |
196 const gfx::Point& image_offset) { | 193 const gfx::Point& image_offset) { |
197 aura::DragDropClient* client = static_cast<aura::DragDropClient*>( | 194 if (!aura::client::GetDragDropClient()) |
198 aura::RootWindow::GetInstance()->GetProperty( | |
199 aura::kRootWindowDragDropClientKey)); | |
200 if (!client) | |
201 return; | 195 return; |
202 | 196 |
203 ui::OSExchangeDataProviderAura* provider = new ui::OSExchangeDataProviderAura; | 197 ui::OSExchangeDataProviderAura* provider = new ui::OSExchangeDataProviderAura; |
204 PrepareDragData(drop_data, provider); | 198 PrepareDragData(drop_data, provider); |
205 if (!image.isNull()) | 199 if (!image.isNull()) |
206 provider->set_drag_image(image); | 200 provider->set_drag_image(image); |
207 ui::OSExchangeData data(provider); // takes ownership of |provider|. | 201 ui::OSExchangeData data(provider); // takes ownership of |provider|. |
208 | 202 |
209 scoped_ptr<WebDragSourceAura> drag_source(new WebDragSourceAura(this)); | 203 scoped_ptr<WebDragSourceAura> drag_source(new WebDragSourceAura(this)); |
210 | 204 |
211 // We need to enable recursive tasks on the message loop so we can get | 205 // We need to enable recursive tasks on the message loop so we can get |
212 // updates while in the system DoDragDrop loop. | 206 // updates while in the system DoDragDrop loop. |
213 bool old_state = MessageLoop::current()->NestableTasksAllowed(); | 207 bool old_state = MessageLoop::current()->NestableTasksAllowed(); |
214 MessageLoop::current()->SetNestableTasksAllowed(true); | 208 MessageLoop::current()->SetNestableTasksAllowed(true); |
215 int result_op = client->StartDragAndDrop(data, ConvertFromWeb(ops)); | 209 int result_op = aura::client::GetDragDropClient()->StartDragAndDrop( |
| 210 data, ConvertFromWeb(ops)); |
216 MessageLoop::current()->SetNestableTasksAllowed(old_state); | 211 MessageLoop::current()->SetNestableTasksAllowed(old_state); |
217 | 212 |
218 EndDrag(ConvertToWeb(result_op)); | 213 EndDrag(ConvertToWeb(result_op)); |
219 GetTabContents()->render_view_host()->DragSourceSystemDragEnded(); | 214 GetTabContents()->render_view_host()->DragSourceSystemDragEnded(); |
220 } | 215 } |
221 | 216 |
222 void NativeTabContentsViewAura::CancelDrag() { | 217 void NativeTabContentsViewAura::CancelDrag() { |
223 aura::DragDropClient* client = static_cast<aura::DragDropClient*>( | 218 if (aura::client::GetDragDropClient()) |
224 aura::RootWindow::GetInstance()->GetProperty( | 219 aura::client::GetDragDropClient()->DragCancel(); |
225 aura::kRootWindowDragDropClientKey)); | |
226 if (client) | |
227 client->DragCancel(); | |
228 } | 220 } |
229 | 221 |
230 bool NativeTabContentsViewAura::IsDoingDrag() const { | 222 bool NativeTabContentsViewAura::IsDoingDrag() const { |
231 aura::DragDropClient* client = static_cast<aura::DragDropClient*>( | 223 if (aura::client::GetDragDropClient()) |
232 aura::RootWindow::GetInstance()->GetProperty( | 224 return aura::client::GetDragDropClient()->IsDragDropInProgress(); |
233 aura::kRootWindowDragDropClientKey)); | |
234 if (client) | |
235 return client->IsDragDropInProgress(); | |
236 return false; | 225 return false; |
237 } | 226 } |
238 | 227 |
239 void NativeTabContentsViewAura::SetDragCursor( | 228 void NativeTabContentsViewAura::SetDragCursor( |
240 WebKit::WebDragOperation operation) { | 229 WebKit::WebDragOperation operation) { |
241 current_drag_op_ = operation; | 230 current_drag_op_ = operation; |
242 } | 231 } |
243 | 232 |
244 views::NativeWidget* NativeTabContentsViewAura::AsNativeWidget() { | 233 views::NativeWidget* NativeTabContentsViewAura::AsNativeWidget() { |
245 return this; | 234 return this; |
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
319 } | 308 } |
320 | 309 |
321 //////////////////////////////////////////////////////////////////////////////// | 310 //////////////////////////////////////////////////////////////////////////////// |
322 // NativeTabContentsView, public: | 311 // NativeTabContentsView, public: |
323 | 312 |
324 // static | 313 // static |
325 NativeTabContentsView* NativeTabContentsView::CreateNativeTabContentsView( | 314 NativeTabContentsView* NativeTabContentsView::CreateNativeTabContentsView( |
326 internal::NativeTabContentsViewDelegate* delegate) { | 315 internal::NativeTabContentsViewDelegate* delegate) { |
327 return new NativeTabContentsViewAura(delegate); | 316 return new NativeTabContentsViewAura(delegate); |
328 } | 317 } |
OLD | NEW |