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 "content/browser/web_contents/web_contents_view_aura.h" | 5 #include "content/browser/web_contents/web_contents_view_aura.h" |
6 | 6 |
7 #include "base/utf_string_conversions.h" | 7 #include "base/utf_string_conversions.h" |
8 #include "content/browser/renderer_host/render_view_host_factory.h" | 8 #include "content/browser/renderer_host/render_view_host_factory.h" |
9 #include "content/browser/web_contents/interstitial_page_impl.h" | 9 #include "content/browser/web_contents/interstitial_page_impl.h" |
10 #include "content/browser/web_contents/web_contents_impl.h" | 10 #include "content/browser/web_contents/web_contents_impl.h" |
(...skipping 151 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
162 //////////////////////////////////////////////////////////////////////////////// | 162 //////////////////////////////////////////////////////////////////////////////// |
163 // WebContentsViewAura, public: | 163 // WebContentsViewAura, public: |
164 | 164 |
165 WebContentsViewAura::WebContentsViewAura( | 165 WebContentsViewAura::WebContentsViewAura( |
166 WebContentsImpl* web_contents, | 166 WebContentsImpl* web_contents, |
167 content::WebContentsViewDelegate* delegate) | 167 content::WebContentsViewDelegate* delegate) |
168 : web_contents_(web_contents), | 168 : web_contents_(web_contents), |
169 view_(NULL), | 169 view_(NULL), |
170 delegate_(delegate), | 170 delegate_(delegate), |
171 current_drag_op_(WebKit::WebDragOperationNone), | 171 current_drag_op_(WebKit::WebDragOperationNone), |
172 close_tab_after_drag_ends_(false) { | 172 close_tab_after_drag_ends_(false), |
| 173 drag_dest_delegate_(NULL) { |
173 } | 174 } |
174 | 175 |
175 WebContentsViewAura::~WebContentsViewAura() { | 176 WebContentsViewAura::~WebContentsViewAura() { |
176 } | 177 } |
177 | 178 |
178 //////////////////////////////////////////////////////////////////////////////// | 179 //////////////////////////////////////////////////////////////////////////////// |
179 // WebContentsViewAura, private: | 180 // WebContentsViewAura, private: |
180 | 181 |
181 void WebContentsViewAura::SizeChangedCommon(const gfx::Size& size) { | 182 void WebContentsViewAura::SizeChangedCommon(const gfx::Size& size) { |
182 if (web_contents_->GetInterstitialPage()) | 183 if (web_contents_->GetInterstitialPage()) |
183 web_contents_->GetInterstitialPage()->SetSize(size); | 184 web_contents_->GetInterstitialPage()->SetSize(size); |
184 content::RenderWidgetHostView* rwhv = | 185 content::RenderWidgetHostView* rwhv = |
185 web_contents_->GetRenderWidgetHostView(); | 186 web_contents_->GetRenderWidgetHostView(); |
186 if (rwhv) | 187 if (rwhv) |
187 rwhv->SetSize(size); | 188 rwhv->SetSize(size); |
188 } | 189 } |
189 | 190 |
190 void WebContentsViewAura::EndDrag(WebKit::WebDragOperationsMask ops) { | 191 void WebContentsViewAura::EndDrag(WebKit::WebDragOperationsMask ops) { |
191 aura::RootWindow* root_window = GetNativeView()->GetRootWindow(); | 192 aura::RootWindow* root_window = GetNativeView()->GetRootWindow(); |
192 gfx::Point screen_loc = root_window->last_mouse_location(); | 193 gfx::Point screen_loc = root_window->last_mouse_location(); |
193 gfx::Point client_loc = screen_loc; | 194 gfx::Point client_loc = screen_loc; |
194 content::RenderViewHost* rvh = web_contents_->GetRenderViewHost(); | 195 content::RenderViewHost* rvh = web_contents_->GetRenderViewHost(); |
195 aura::Window* window = rvh->GetView()->GetNativeView(); | 196 aura::Window* window = rvh->GetView()->GetNativeView(); |
196 aura::Window::ConvertPointToWindow(root_window, window, &client_loc); | 197 aura::Window::ConvertPointToWindow(root_window, window, &client_loc); |
197 rvh->DragSourceEndedAt(client_loc.x(), client_loc.y(), screen_loc.x(), | 198 rvh->DragSourceEndedAt(client_loc.x(), client_loc.y(), screen_loc.x(), |
198 screen_loc.y(), ops); | 199 screen_loc.y(), ops); |
199 } | 200 } |
200 | 201 |
201 content::WebDragDestDelegate* WebContentsViewAura::GetDragDestDelegate() { | |
202 return delegate_.get() ? delegate_->GetDragDestDelegate() : NULL; | |
203 } | |
204 | |
205 //////////////////////////////////////////////////////////////////////////////// | 202 //////////////////////////////////////////////////////////////////////////////// |
206 // WebContentsViewAura, WebContentsView implementation: | 203 // WebContentsViewAura, WebContentsView implementation: |
207 | 204 |
208 void WebContentsViewAura::CreateView(const gfx::Size& initial_size) { | 205 void WebContentsViewAura::CreateView(const gfx::Size& initial_size) { |
209 initial_size_ = initial_size; | 206 initial_size_ = initial_size; |
210 | 207 |
211 window_.reset(new aura::Window(this)); | 208 window_.reset(new aura::Window(this)); |
212 window_->set_owned_by_parent(false); | 209 window_->set_owned_by_parent(false); |
213 window_->SetType(aura::client::WINDOW_TYPE_CONTROL); | 210 window_->SetType(aura::client::WINDOW_TYPE_CONTROL); |
214 window_->SetTransparent(false); | 211 window_->SetTransparent(false); |
215 window_->Init(ui::LAYER_NOT_DRAWN); | 212 window_->Init(ui::LAYER_NOT_DRAWN); |
216 #if defined(USE_ASH) | 213 #if defined(USE_ASH) |
217 window_->SetParent(NULL); | 214 window_->SetParent(NULL); |
218 #endif | 215 #endif |
219 window_->layer()->SetMasksToBounds(true); | 216 window_->layer()->SetMasksToBounds(true); |
220 window_->SetName("WebContentsViewAura"); | 217 window_->SetName("WebContentsViewAura"); |
| 218 |
| 219 // delegate_->GetDragDestDelegate() creates a new delegate on every call. |
| 220 // Hence, we save a reference to it locally. Similar model is used on other |
| 221 // platforms as well. |
| 222 if (delegate_.get()) |
| 223 drag_dest_delegate_ = delegate_->GetDragDestDelegate(); |
221 } | 224 } |
222 | 225 |
223 content::RenderWidgetHostView* WebContentsViewAura::CreateViewForWidget( | 226 content::RenderWidgetHostView* WebContentsViewAura::CreateViewForWidget( |
224 content::RenderWidgetHost* render_widget_host) { | 227 content::RenderWidgetHost* render_widget_host) { |
225 if (render_widget_host->GetView()) { | 228 if (render_widget_host->GetView()) { |
226 // During testing, the view will already be set up in most cases to the | 229 // During testing, the view will already be set up in most cases to the |
227 // test view, so we don't want to clobber it with a real one. To verify that | 230 // test view, so we don't want to clobber it with a real one. To verify that |
228 // this actually is happening (and somebody isn't accidentally creating the | 231 // this actually is happening (and somebody isn't accidentally creating the |
229 // view twice), we check for the RVH Factory, which will be set when we're | 232 // view twice), we check for the RVH Factory, which will be set when we're |
230 // making special ones (which go along with the special views). | 233 // making special ones (which go along with the special views). |
(...skipping 212 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
443 // always start from a mouse-event (e.g. a touch or gesture event could | 446 // always start from a mouse-event (e.g. a touch or gesture event could |
444 // initiate the drag). The location information should be carried over from | 447 // initiate the drag). The location information should be carried over from |
445 // webkit. http://crbug.com/114754 | 448 // webkit. http://crbug.com/114754 |
446 gfx::Point location(root_window->last_mouse_location()); | 449 gfx::Point location(root_window->last_mouse_location()); |
447 MessageLoop::ScopedNestableTaskAllower allow(MessageLoop::current()); | 450 MessageLoop::ScopedNestableTaskAllower allow(MessageLoop::current()); |
448 result_op = aura::client::GetDragDropClient(root_window)->StartDragAndDrop( | 451 result_op = aura::client::GetDragDropClient(root_window)->StartDragAndDrop( |
449 data, location, ConvertFromWeb(operations)); | 452 data, location, ConvertFromWeb(operations)); |
450 } | 453 } |
451 | 454 |
452 EndDrag(ConvertToWeb(result_op)); | 455 EndDrag(ConvertToWeb(result_op)); |
453 web_contents_->GetRenderViewHost()->DragSourceSystemDragEnded();} | 456 web_contents_->GetRenderViewHost()->DragSourceSystemDragEnded(); |
| 457 } |
454 | 458 |
455 void WebContentsViewAura::UpdateDragCursor(WebKit::WebDragOperation operation) { | 459 void WebContentsViewAura::UpdateDragCursor(WebKit::WebDragOperation operation) { |
456 current_drag_op_ = operation; | 460 current_drag_op_ = operation; |
457 } | 461 } |
458 | 462 |
459 void WebContentsViewAura::GotFocus() { | 463 void WebContentsViewAura::GotFocus() { |
460 if (web_contents_->GetDelegate()) | 464 if (web_contents_->GetDelegate()) |
461 web_contents_->GetDelegate()->WebContentsFocused(web_contents_); | 465 web_contents_->GetDelegate()->WebContentsFocused(web_contents_); |
462 } | 466 } |
463 | 467 |
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
547 void WebContentsViewAura::OnWindowVisibilityChanged(bool visible) { | 551 void WebContentsViewAura::OnWindowVisibilityChanged(bool visible) { |
548 if (visible) | 552 if (visible) |
549 web_contents_->ShowContents(); | 553 web_contents_->ShowContents(); |
550 else | 554 else |
551 web_contents_->HideContents(); | 555 web_contents_->HideContents(); |
552 } | 556 } |
553 //////////////////////////////////////////////////////////////////////////////// | 557 //////////////////////////////////////////////////////////////////////////////// |
554 // WebContentsViewAura, aura::client::DragDropDelegate implementation: | 558 // WebContentsViewAura, aura::client::DragDropDelegate implementation: |
555 | 559 |
556 void WebContentsViewAura::OnDragEntered(const aura::DropTargetEvent& event) { | 560 void WebContentsViewAura::OnDragEntered(const aura::DropTargetEvent& event) { |
557 if (GetDragDestDelegate()) | 561 if (drag_dest_delegate_) |
558 GetDragDestDelegate()->DragInitialize(web_contents_); | 562 drag_dest_delegate_->DragInitialize(web_contents_); |
559 | 563 |
560 WebDropData drop_data; | 564 WebDropData drop_data; |
561 PrepareWebDropData(&drop_data, event.data()); | 565 PrepareWebDropData(&drop_data, event.data()); |
562 WebKit::WebDragOperationsMask op = ConvertToWeb(event.source_operations()); | 566 WebKit::WebDragOperationsMask op = ConvertToWeb(event.source_operations()); |
563 | 567 |
564 gfx::Point screen_pt = | 568 gfx::Point screen_pt = |
565 GetNativeView()->GetRootWindow()->last_mouse_location(); | 569 GetNativeView()->GetRootWindow()->last_mouse_location(); |
566 web_contents_->GetRenderViewHost()->DragTargetDragEnter( | 570 web_contents_->GetRenderViewHost()->DragTargetDragEnter( |
567 drop_data, event.location(), screen_pt, op); | 571 drop_data, event.location(), screen_pt, op); |
568 | 572 |
569 if (GetDragDestDelegate()) { | 573 if (drag_dest_delegate_) { |
570 GetDragDestDelegate()->OnReceiveDragData(event.data()); | 574 drag_dest_delegate_->OnReceiveDragData(event.data()); |
571 GetDragDestDelegate()->OnDragEnter(); | 575 drag_dest_delegate_->OnDragEnter(); |
572 } | 576 } |
573 } | 577 } |
574 | 578 |
575 int WebContentsViewAura::OnDragUpdated(const aura::DropTargetEvent& event) { | 579 int WebContentsViewAura::OnDragUpdated(const aura::DropTargetEvent& event) { |
576 WebKit::WebDragOperationsMask op = ConvertToWeb(event.source_operations()); | 580 WebKit::WebDragOperationsMask op = ConvertToWeb(event.source_operations()); |
577 gfx::Point screen_pt = | 581 gfx::Point screen_pt = |
578 GetNativeView()->GetRootWindow()->last_mouse_location(); | 582 GetNativeView()->GetRootWindow()->last_mouse_location(); |
579 web_contents_->GetRenderViewHost()->DragTargetDragOver( | 583 web_contents_->GetRenderViewHost()->DragTargetDragOver( |
580 event.location(), screen_pt, op); | 584 event.location(), screen_pt, op); |
581 | 585 |
582 if (GetDragDestDelegate()) | 586 if (drag_dest_delegate_) |
583 GetDragDestDelegate()->OnDragOver(); | 587 drag_dest_delegate_->OnDragOver(); |
584 | 588 |
585 return ConvertFromWeb(current_drag_op_); | 589 return ConvertFromWeb(current_drag_op_); |
586 } | 590 } |
587 | 591 |
588 void WebContentsViewAura::OnDragExited() { | 592 void WebContentsViewAura::OnDragExited() { |
589 web_contents_->GetRenderViewHost()->DragTargetDragLeave(); | 593 web_contents_->GetRenderViewHost()->DragTargetDragLeave(); |
590 if (GetDragDestDelegate()) | 594 if (drag_dest_delegate_) |
591 GetDragDestDelegate()->OnDragLeave(); | 595 drag_dest_delegate_->OnDragLeave(); |
592 } | 596 } |
593 | 597 |
594 int WebContentsViewAura::OnPerformDrop(const aura::DropTargetEvent& event) { | 598 int WebContentsViewAura::OnPerformDrop(const aura::DropTargetEvent& event) { |
595 web_contents_->GetRenderViewHost()->DragTargetDrop( | 599 web_contents_->GetRenderViewHost()->DragTargetDrop( |
596 event.location(), | 600 event.location(), |
597 GetNativeView()->GetRootWindow()->last_mouse_location()); | 601 GetNativeView()->GetRootWindow()->last_mouse_location()); |
598 if (GetDragDestDelegate()) | 602 if (drag_dest_delegate_) |
599 GetDragDestDelegate()->OnDrop(); | 603 drag_dest_delegate_->OnDrop(); |
600 return current_drag_op_; | 604 return current_drag_op_; |
601 } | 605 } |
OLD | NEW |