| 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/tab_contents/tab_contents_view_aura.h" | 5 // This is just a placeholder - TabContentsViewAura is not yet implemented |
| 6 // (instead chrome has it's own TabContentsViewViews that is used for Aura). |
| 6 | 7 |
| 7 #include "base/utf_string_conversions.h" | 8 // We need to make sure the compiler sees this interface declaration somewhere |
| 8 #include "content/browser/renderer_host/render_view_host_factory.h" | 9 // so that it can emit exported versions of the inline ctor/dtor functions, |
| 9 #include "content/browser/tab_contents/interstitial_page_impl.h" | 10 // otherwise chrome.dll will get a linker error on Windows Aura builds. |
| 10 #include "content/browser/tab_contents/tab_contents.h" | |
| 11 #include "content/public/browser/render_view_host.h" | |
| 12 #include "content/public/browser/render_widget_host.h" | |
| 13 #include "content/public/browser/render_widget_host_view.h" | |
| 14 #include "content/public/browser/web_contents_delegate.h" | |
| 15 #include "content/public/browser/web_contents_view_delegate.h" | 11 #include "content/public/browser/web_contents_view_delegate.h" |
| 16 #include "content/public/browser/web_drag_dest_delegate.h" | |
| 17 #include "ui/aura/client/drag_drop_client.h" | |
| 18 #include "ui/aura/client/drag_drop_delegate.h" | |
| 19 #include "ui/aura/event.h" | |
| 20 #include "ui/aura/root_window.h" | |
| 21 #include "ui/aura/window.h" | |
| 22 #include "ui/base/clipboard/custom_data_helper.h" | |
| 23 #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_provider_aura.h" | |
| 26 #include "ui/base/hit_test.h" | |
| 27 #include "ui/gfx/compositor/layer.h" | |
| 28 #include "ui/gfx/screen.h" | |
| 29 #include "webkit/glue/webdropdata.h" | |
| 30 | |
| 31 namespace { | |
| 32 | |
| 33 // Listens to all mouse drag events during a drag and drop and sends them to | |
| 34 // the renderer. | |
| 35 class WebDragSourceAura : public MessageLoopForUI::Observer { | |
| 36 public: | |
| 37 explicit WebDragSourceAura(TabContents* contents) | |
| 38 : contents_(contents) { | |
| 39 MessageLoopForUI::current()->AddObserver(this); | |
| 40 } | |
| 41 | |
| 42 virtual ~WebDragSourceAura() { | |
| 43 MessageLoopForUI::current()->RemoveObserver(this); | |
| 44 } | |
| 45 | |
| 46 // MessageLoop::Observer implementation: | |
| 47 virtual base::EventStatus WillProcessEvent( | |
| 48 const base::NativeEvent& event) OVERRIDE { | |
| 49 return base::EVENT_CONTINUE; | |
| 50 } | |
| 51 virtual void DidProcessEvent(const base::NativeEvent& event) OVERRIDE { | |
| 52 ui::EventType type = ui::EventTypeFromNative(event); | |
| 53 content::RenderViewHost* rvh = NULL; | |
| 54 switch (type) { | |
| 55 case ui::ET_MOUSE_DRAGGED: | |
| 56 rvh = contents_->GetRenderViewHost(); | |
| 57 if (rvh) { | |
| 58 gfx::Point screen_loc = ui::EventLocationFromNative(event); | |
| 59 gfx::Point client_loc = screen_loc; | |
| 60 aura::Window* window = rvh->GetView()->GetNativeView(); | |
| 61 aura::Window::ConvertPointToWindow(window->GetRootWindow(), | |
| 62 window, &client_loc); | |
| 63 rvh->DragSourceMovedTo(client_loc.x(), client_loc.y(), | |
| 64 screen_loc.x(), screen_loc.y()); | |
| 65 } | |
| 66 break; | |
| 67 default: | |
| 68 break; | |
| 69 } | |
| 70 } | |
| 71 | |
| 72 | |
| 73 private: | |
| 74 TabContents* contents_; | |
| 75 | |
| 76 DISALLOW_COPY_AND_ASSIGN(WebDragSourceAura); | |
| 77 }; | |
| 78 | |
| 79 // Utility to fill a ui::OSExchangeDataProviderAura object from WebDropData. | |
| 80 void PrepareDragData(const WebDropData& drop_data, | |
| 81 ui::OSExchangeDataProviderAura* provider) { | |
| 82 if (!drop_data.plain_text.empty()) | |
| 83 provider->SetString(drop_data.plain_text); | |
| 84 if (drop_data.url.is_valid()) | |
| 85 provider->SetURL(drop_data.url, drop_data.url_title); | |
| 86 if (!drop_data.text_html.empty()) | |
| 87 provider->SetHtml(drop_data.text_html, drop_data.html_base_url); | |
| 88 if (!drop_data.filenames.empty()) { | |
| 89 std::vector<FilePath> paths; | |
| 90 for (std::vector<string16>::const_iterator it = drop_data.filenames.begin(); | |
| 91 it != drop_data.filenames.end(); ++it) | |
| 92 paths.push_back(FilePath::FromUTF8Unsafe(UTF16ToUTF8(*it))); | |
| 93 provider->SetFilenames(paths); | |
| 94 } | |
| 95 if (!drop_data.custom_data.empty()) { | |
| 96 Pickle pickle; | |
| 97 ui::WriteCustomDataToPickle(drop_data.custom_data, &pickle); | |
| 98 provider->SetPickledData(ui::Clipboard::GetWebCustomDataFormatType(), | |
| 99 pickle); | |
| 100 } | |
| 101 } | |
| 102 | |
| 103 // Utility to fill a WebDropData object from ui::OSExchangeData. | |
| 104 void PrepareWebDropData(WebDropData* drop_data, | |
| 105 const ui::OSExchangeData& data) { | |
| 106 string16 plain_text, url_title; | |
| 107 GURL url; | |
| 108 | |
| 109 data.GetString(&plain_text); | |
| 110 if (!plain_text.empty()) | |
| 111 drop_data->plain_text = plain_text; | |
| 112 | |
| 113 data.GetURLAndTitle(&url, &url_title); | |
| 114 if (url.is_valid()) { | |
| 115 drop_data->url = url; | |
| 116 drop_data->url_title = url_title; | |
| 117 } | |
| 118 | |
| 119 data.GetHtml(&drop_data->text_html, &drop_data->html_base_url); | |
| 120 | |
| 121 std::vector<FilePath> files; | |
| 122 if (data.GetFilenames(&files) && !files.empty()) { | |
| 123 for (std::vector<FilePath>::const_iterator it = files.begin(); | |
| 124 it != files.end(); ++it) | |
| 125 drop_data->filenames.push_back(UTF8ToUTF16(it->AsUTF8Unsafe())); | |
| 126 } | |
| 127 | |
| 128 Pickle pickle; | |
| 129 if (data.GetPickledData(ui::Clipboard::GetWebCustomDataFormatType(), | |
| 130 &pickle)) | |
| 131 ui::ReadCustomDataIntoMap(pickle.data(), pickle.size(), | |
| 132 &drop_data->custom_data); | |
| 133 } | |
| 134 | |
| 135 // Utilities to convert between WebKit::WebDragOperationsMask and | |
| 136 // ui::DragDropTypes. | |
| 137 int ConvertFromWeb(WebKit::WebDragOperationsMask ops) { | |
| 138 int drag_op = ui::DragDropTypes::DRAG_NONE; | |
| 139 if (ops & WebKit::WebDragOperationCopy) | |
| 140 drag_op |= ui::DragDropTypes::DRAG_COPY; | |
| 141 if (ops & WebKit::WebDragOperationMove) | |
| 142 drag_op |= ui::DragDropTypes::DRAG_MOVE; | |
| 143 if (ops & WebKit::WebDragOperationLink) | |
| 144 drag_op |= ui::DragDropTypes::DRAG_LINK; | |
| 145 return drag_op; | |
| 146 } | |
| 147 | |
| 148 WebKit::WebDragOperationsMask ConvertToWeb(int drag_op) { | |
| 149 int web_drag_op = WebKit::WebDragOperationNone; | |
| 150 if (drag_op & ui::DragDropTypes::DRAG_COPY) | |
| 151 web_drag_op |= WebKit::WebDragOperationCopy; | |
| 152 if (drag_op & ui::DragDropTypes::DRAG_MOVE) | |
| 153 web_drag_op |= WebKit::WebDragOperationMove; | |
| 154 if (drag_op & ui::DragDropTypes::DRAG_LINK) | |
| 155 web_drag_op |= WebKit::WebDragOperationLink; | |
| 156 return (WebKit::WebDragOperationsMask) web_drag_op; | |
| 157 } | |
| 158 | |
| 159 } // namespace | |
| 160 | |
| 161 | |
| 162 //////////////////////////////////////////////////////////////////////////////// | |
| 163 // TabContentsViewAura, public: | |
| 164 | |
| 165 TabContentsViewAura::TabContentsViewAura( | |
| 166 TabContents* tab_contents, | |
| 167 content::WebContentsViewDelegate* delegate) | |
| 168 : tab_contents_(tab_contents), | |
| 169 view_(NULL), | |
| 170 delegate_(delegate), | |
| 171 current_drag_op_(WebKit::WebDragOperationNone), | |
| 172 close_tab_after_drag_ends_(false) { | |
| 173 } | |
| 174 | |
| 175 TabContentsViewAura::~TabContentsViewAura() { | |
| 176 } | |
| 177 | |
| 178 //////////////////////////////////////////////////////////////////////////////// | |
| 179 // TabContentsViewAura, private: | |
| 180 | |
| 181 void TabContentsViewAura::SizeChangedCommon(const gfx::Size& size) { | |
| 182 if (tab_contents_->GetInterstitialPage()) | |
| 183 tab_contents_->GetInterstitialPage()->SetSize(size); | |
| 184 content::RenderWidgetHostView* rwhv = | |
| 185 tab_contents_->GetRenderWidgetHostView(); | |
| 186 if (rwhv) | |
| 187 rwhv->SetSize(size); | |
| 188 } | |
| 189 | |
| 190 void TabContentsViewAura::EndDrag(WebKit::WebDragOperationsMask ops) { | |
| 191 aura::RootWindow* root_window = GetNativeView()->GetRootWindow(); | |
| 192 gfx::Point screen_loc = root_window->last_mouse_location(); | |
| 193 gfx::Point client_loc = screen_loc; | |
| 194 content::RenderViewHost* rvh = tab_contents_->GetRenderViewHost(); | |
| 195 aura::Window* window = rvh->GetView()->GetNativeView(); | |
| 196 aura::Window::ConvertPointToWindow(root_window, window, &client_loc); | |
| 197 rvh->DragSourceEndedAt(client_loc.x(), client_loc.y(), screen_loc.x(), | |
| 198 screen_loc.y(), ops); | |
| 199 } | |
| 200 | |
| 201 content::WebDragDestDelegate* TabContentsViewAura::GetDragDestDelegate() { | |
| 202 return delegate_.get() ? delegate_->GetDragDestDelegate() : NULL; | |
| 203 } | |
| 204 | |
| 205 //////////////////////////////////////////////////////////////////////////////// | |
| 206 // TabContentsViewAura, WebContentsView implementation: | |
| 207 | |
| 208 void TabContentsViewAura::CreateView(const gfx::Size& initial_size) { | |
| 209 initial_size_ = initial_size; | |
| 210 | |
| 211 window_.reset(new aura::Window(this)); | |
| 212 window_->SetType(aura::client::WINDOW_TYPE_CONTROL); | |
| 213 window_->SetTransparent(false); | |
| 214 window_->Init(ui::LAYER_TEXTURED); | |
| 215 window_->layer()->SetMasksToBounds(true); | |
| 216 window_->SetName("TabContentsViewAura"); | |
| 217 | |
| 218 // TODO(beng): allow for delegate init step. | |
| 219 | |
| 220 // TODO(beng): drag & drop init. | |
| 221 } | |
| 222 | |
| 223 content::RenderWidgetHostView* TabContentsViewAura::CreateViewForWidget( | |
| 224 content::RenderWidgetHost* render_widget_host) { | |
| 225 if (render_widget_host->GetView()) { | |
| 226 // 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 | |
| 228 // 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 | |
| 230 // making special ones (which go along with the special views). | |
| 231 DCHECK(RenderViewHostFactory::has_factory()); | |
| 232 return render_widget_host->GetView(); | |
| 233 } | |
| 234 | |
| 235 view_ = content::RenderWidgetHostView::CreateViewForWidget( | |
| 236 render_widget_host); | |
| 237 view_->InitAsChild(NULL); | |
| 238 GetNativeView()->AddChild(view_->GetNativeView()); | |
| 239 view_->Show(); | |
| 240 | |
| 241 // We listen to drag drop events in the newly created view's window. | |
| 242 aura::client::SetDragDropDelegate(view_->GetNativeView(), this); | |
| 243 return view_; | |
| 244 } | |
| 245 | |
| 246 gfx::NativeView TabContentsViewAura::GetNativeView() const { | |
| 247 return window_.get(); | |
| 248 } | |
| 249 | |
| 250 gfx::NativeView TabContentsViewAura::GetContentNativeView() const { | |
| 251 return view_->GetNativeView(); | |
| 252 } | |
| 253 | |
| 254 gfx::NativeWindow TabContentsViewAura::GetTopLevelNativeWindow() const { | |
| 255 return window_->GetToplevelWindow(); | |
| 256 } | |
| 257 | |
| 258 void TabContentsViewAura::GetContainerBounds(gfx::Rect *out) const { | |
| 259 *out = window_->GetScreenBounds(); | |
| 260 } | |
| 261 | |
| 262 void TabContentsViewAura::SetPageTitle(const string16& title) { | |
| 263 window_->set_title(title); | |
| 264 } | |
| 265 | |
| 266 void TabContentsViewAura::OnTabCrashed(base::TerminationStatus status, | |
| 267 int error_code) { | |
| 268 view_ = NULL; | |
| 269 } | |
| 270 | |
| 271 void TabContentsViewAura::SizeContents(const gfx::Size& size) { | |
| 272 gfx::Rect bounds = window_->bounds(); | |
| 273 if (bounds.size() != size) { | |
| 274 bounds.set_size(size); | |
| 275 window_->SetBounds(bounds); | |
| 276 } else { | |
| 277 // Our size matches what we want but the renderers size may not match. | |
| 278 // Pretend we were resized so that the renderers size is updated too. | |
| 279 SizeChangedCommon(size); | |
| 280 | |
| 281 } | |
| 282 } | |
| 283 | |
| 284 void TabContentsViewAura::RenderViewCreated(content::RenderViewHost* host) { | |
| 285 } | |
| 286 | |
| 287 void TabContentsViewAura::Focus() { | |
| 288 if (tab_contents_->GetInterstitialPage()) { | |
| 289 tab_contents_->GetInterstitialPage()->Focus(); | |
| 290 return; | |
| 291 } | |
| 292 | |
| 293 if (delegate_.get() && delegate_->Focus()) | |
| 294 return; | |
| 295 | |
| 296 content::RenderWidgetHostView* rwhv = | |
| 297 tab_contents_->GetRenderWidgetHostView(); | |
| 298 if (rwhv) | |
| 299 rwhv->Focus(); | |
| 300 } | |
| 301 | |
| 302 void TabContentsViewAura::SetInitialFocus() { | |
| 303 if (tab_contents_->FocusLocationBarByDefault()) | |
| 304 tab_contents_->SetFocusToLocationBar(false); | |
| 305 else | |
| 306 Focus(); | |
| 307 } | |
| 308 | |
| 309 void TabContentsViewAura::StoreFocus() { | |
| 310 if (delegate_.get()) | |
| 311 delegate_->StoreFocus(); | |
| 312 } | |
| 313 | |
| 314 void TabContentsViewAura::RestoreFocus() { | |
| 315 if (delegate_.get()) | |
| 316 delegate_->RestoreFocus(); | |
| 317 } | |
| 318 | |
| 319 bool TabContentsViewAura::IsDoingDrag() const { | |
| 320 aura::RootWindow* root_window = GetNativeView()->GetRootWindow(); | |
| 321 if (aura::client::GetDragDropClient(root_window)) | |
| 322 return aura::client::GetDragDropClient(root_window)->IsDragDropInProgress(); | |
| 323 return false; | |
| 324 } | |
| 325 | |
| 326 void TabContentsViewAura::CancelDragAndCloseTab() { | |
| 327 DCHECK(IsDoingDrag()); | |
| 328 // We can't close the tab while we're in the drag and | |
| 329 // |drag_handler_->CancelDrag()| is async. Instead, set a flag to cancel | |
| 330 // the drag and when the drag nested message loop ends, close the tab. | |
| 331 aura::RootWindow* root_window = GetNativeView()->GetRootWindow(); | |
| 332 if (aura::client::GetDragDropClient(root_window)) | |
| 333 aura::client::GetDragDropClient(root_window)->DragCancel(); | |
| 334 | |
| 335 close_tab_after_drag_ends_ = true; | |
| 336 } | |
| 337 | |
| 338 bool TabContentsViewAura::IsEventTracking() const { | |
| 339 return false; | |
| 340 } | |
| 341 | |
| 342 void TabContentsViewAura::CloseTabAfterEventTracking() { | |
| 343 } | |
| 344 | |
| 345 void TabContentsViewAura::GetViewBounds(gfx::Rect* out) const { | |
| 346 *out = window_->GetScreenBounds(); | |
| 347 } | |
| 348 | |
| 349 //////////////////////////////////////////////////////////////////////////////// | |
| 350 // TabContentsViewAura, RenderViewHostDelegate::View implementation: | |
| 351 | |
| 352 void TabContentsViewAura::CreateNewWindow( | |
| 353 int route_id, | |
| 354 const ViewHostMsg_CreateWindow_Params& params) { | |
| 355 tab_contents_view_helper_.CreateNewWindow(tab_contents_, route_id, params); | |
| 356 } | |
| 357 | |
| 358 void TabContentsViewAura::CreateNewWidget(int route_id, | |
| 359 WebKit::WebPopupType popup_type) { | |
| 360 tab_contents_view_helper_.CreateNewWidget(tab_contents_, | |
| 361 route_id, | |
| 362 false, | |
| 363 popup_type); | |
| 364 } | |
| 365 | |
| 366 void TabContentsViewAura::CreateNewFullscreenWidget(int route_id) { | |
| 367 tab_contents_view_helper_.CreateNewWidget(tab_contents_, | |
| 368 route_id, | |
| 369 true, | |
| 370 WebKit::WebPopupTypeNone); | |
| 371 } | |
| 372 | |
| 373 void TabContentsViewAura::ShowCreatedWindow(int route_id, | |
| 374 WindowOpenDisposition disposition, | |
| 375 const gfx::Rect& initial_pos, | |
| 376 bool user_gesture) { | |
| 377 tab_contents_view_helper_.ShowCreatedWindow( | |
| 378 tab_contents_, route_id, disposition, initial_pos, user_gesture); | |
| 379 } | |
| 380 | |
| 381 void TabContentsViewAura::ShowCreatedWidget(int route_id, | |
| 382 const gfx::Rect& initial_pos) { | |
| 383 tab_contents_view_helper_.ShowCreatedWidget(tab_contents_, | |
| 384 route_id, | |
| 385 false, | |
| 386 initial_pos); | |
| 387 } | |
| 388 | |
| 389 void TabContentsViewAura::ShowCreatedFullscreenWidget(int route_id) { | |
| 390 tab_contents_view_helper_.ShowCreatedWidget(tab_contents_, | |
| 391 route_id, | |
| 392 true, | |
| 393 gfx::Rect()); | |
| 394 } | |
| 395 | |
| 396 void TabContentsViewAura::ShowContextMenu( | |
| 397 const content::ContextMenuParams& params) { | |
| 398 // Allow WebContentsDelegates to handle the context menu operation first. | |
| 399 if (tab_contents_->GetDelegate() && | |
| 400 tab_contents_->GetDelegate()->HandleContextMenu(params)) { | |
| 401 return; | |
| 402 } | |
| 403 | |
| 404 if (delegate_.get()) | |
| 405 delegate_->ShowContextMenu(params); | |
| 406 } | |
| 407 | |
| 408 void TabContentsViewAura::ShowPopupMenu(const gfx::Rect& bounds, | |
| 409 int item_height, | |
| 410 double item_font_size, | |
| 411 int selected_item, | |
| 412 const std::vector<WebMenuItem>& items, | |
| 413 bool right_aligned) { | |
| 414 // External popup menus are only used on Mac. | |
| 415 NOTIMPLEMENTED(); | |
| 416 } | |
| 417 | |
| 418 void TabContentsViewAura::StartDragging( | |
| 419 const WebDropData& drop_data, | |
| 420 WebKit::WebDragOperationsMask operations, | |
| 421 const SkBitmap& image, | |
| 422 const gfx::Point& image_offset) { | |
| 423 aura::RootWindow* root_window = GetNativeView()->GetRootWindow(); | |
| 424 if (!aura::client::GetDragDropClient(root_window)) | |
| 425 return; | |
| 426 | |
| 427 ui::OSExchangeDataProviderAura* provider = new ui::OSExchangeDataProviderAura; | |
| 428 PrepareDragData(drop_data, provider); | |
| 429 if (!image.isNull()) | |
| 430 provider->set_drag_image(image); | |
| 431 ui::OSExchangeData data(provider); // takes ownership of |provider|. | |
| 432 | |
| 433 scoped_ptr<WebDragSourceAura> drag_source( | |
| 434 new WebDragSourceAura(tab_contents_)); | |
| 435 | |
| 436 // We need to enable recursive tasks on the message loop so we can get | |
| 437 // updates while in the system DoDragDrop loop. | |
| 438 int result_op = 0; | |
| 439 { | |
| 440 // TODO(sad): Avoid using last_mouse_location here, since the drag may not | |
| 441 // always start from a mouse-event (e.g. a touch or gesture event could | |
| 442 // initiate the drag). The location information should be carried over from | |
| 443 // webkit. http://crbug.com/114754 | |
| 444 gfx::Point location(root_window->last_mouse_location()); | |
| 445 location.Offset(-image_offset.x(), -image_offset.y()); | |
| 446 MessageLoop::ScopedNestableTaskAllower allow(MessageLoop::current()); | |
| 447 result_op = aura::client::GetDragDropClient(root_window)->StartDragAndDrop( | |
| 448 data, location, ConvertFromWeb(operations)); | |
| 449 } | |
| 450 | |
| 451 EndDrag(ConvertToWeb(result_op)); | |
| 452 tab_contents_->GetRenderViewHost()->DragSourceSystemDragEnded();} | |
| 453 | |
| 454 void TabContentsViewAura::UpdateDragCursor(WebKit::WebDragOperation operation) { | |
| 455 current_drag_op_ = operation; | |
| 456 } | |
| 457 | |
| 458 void TabContentsViewAura::GotFocus() { | |
| 459 if (tab_contents_->GetDelegate()) | |
| 460 tab_contents_->GetDelegate()->WebContentsFocused(tab_contents_); | |
| 461 } | |
| 462 | |
| 463 void TabContentsViewAura::TakeFocus(bool reverse) { | |
| 464 if (tab_contents_->GetDelegate() && | |
| 465 !tab_contents_->GetDelegate()->TakeFocus(reverse) && | |
| 466 delegate_.get()) { | |
| 467 delegate_->TakeFocus(reverse); | |
| 468 } | |
| 469 } | |
| 470 | |
| 471 //////////////////////////////////////////////////////////////////////////////// | |
| 472 // TabContentsViewAura, aura::WindowDelegate implementation: | |
| 473 | |
| 474 gfx::Size TabContentsViewAura::GetMinimumSize() const { | |
| 475 return gfx::Size(); | |
| 476 } | |
| 477 | |
| 478 void TabContentsViewAura::OnBoundsChanged(const gfx::Rect& old_bounds, | |
| 479 const gfx::Rect& new_bounds) { | |
| 480 SizeChangedCommon(new_bounds.size()); | |
| 481 if (delegate_.get()) | |
| 482 delegate_->SizeChanged(new_bounds.size()); | |
| 483 } | |
| 484 | |
| 485 void TabContentsViewAura::OnFocus() { | |
| 486 } | |
| 487 | |
| 488 void TabContentsViewAura::OnBlur() { | |
| 489 } | |
| 490 | |
| 491 bool TabContentsViewAura::OnKeyEvent(aura::KeyEvent* event) { | |
| 492 return false; | |
| 493 } | |
| 494 | |
| 495 gfx::NativeCursor TabContentsViewAura::GetCursor(const gfx::Point& point) { | |
| 496 return NULL; | |
| 497 } | |
| 498 | |
| 499 int TabContentsViewAura::GetNonClientComponent(const gfx::Point& point) const { | |
| 500 return HTCLIENT; | |
| 501 } | |
| 502 | |
| 503 bool TabContentsViewAura::OnMouseEvent(aura::MouseEvent* event) { | |
| 504 if (!tab_contents_->GetDelegate()) | |
| 505 return false; | |
| 506 | |
| 507 switch (event->type()) { | |
| 508 case ui::ET_MOUSE_PRESSED: | |
| 509 tab_contents_->GetDelegate()->ActivateContents(tab_contents_); | |
| 510 break; | |
| 511 case ui::ET_MOUSE_MOVED: | |
| 512 tab_contents_->GetDelegate()->ContentsMouseEvent( | |
| 513 tab_contents_, gfx::Screen::GetCursorScreenPoint(), true); | |
| 514 break; | |
| 515 default: | |
| 516 break; | |
| 517 } | |
| 518 return false; | |
| 519 } | |
| 520 | |
| 521 ui::TouchStatus TabContentsViewAura::OnTouchEvent(aura::TouchEvent* event) { | |
| 522 return ui::TOUCH_STATUS_UNKNOWN; | |
| 523 } | |
| 524 | |
| 525 ui::GestureStatus TabContentsViewAura::OnGestureEvent( | |
| 526 aura::GestureEvent* event) { | |
| 527 return ui::GESTURE_STATUS_UNKNOWN; | |
| 528 } | |
| 529 | |
| 530 bool TabContentsViewAura::CanFocus() { | |
| 531 return false; | |
| 532 } | |
| 533 | |
| 534 void TabContentsViewAura::OnCaptureLost() { | |
| 535 } | |
| 536 | |
| 537 void TabContentsViewAura::OnPaint(gfx::Canvas* canvas) { | |
| 538 } | |
| 539 | |
| 540 void TabContentsViewAura::OnWindowDestroying() { | |
| 541 } | |
| 542 | |
| 543 void TabContentsViewAura::OnWindowDestroyed() { | |
| 544 } | |
| 545 | |
| 546 void TabContentsViewAura::OnWindowVisibilityChanged(bool visible) { | |
| 547 if (visible) | |
| 548 tab_contents_->ShowContents(); | |
| 549 else | |
| 550 tab_contents_->HideContents(); | |
| 551 } | |
| 552 //////////////////////////////////////////////////////////////////////////////// | |
| 553 // TabContentsViewAura, aura::client::DragDropDelegate implementation: | |
| 554 | |
| 555 void TabContentsViewAura::OnDragEntered(const aura::DropTargetEvent& event) { | |
| 556 if (GetDragDestDelegate()) | |
| 557 GetDragDestDelegate()->DragInitialize(tab_contents_); | |
| 558 | |
| 559 WebDropData drop_data; | |
| 560 PrepareWebDropData(&drop_data, event.data()); | |
| 561 WebKit::WebDragOperationsMask op = ConvertToWeb(event.source_operations()); | |
| 562 | |
| 563 gfx::Point screen_pt = | |
| 564 GetNativeView()->GetRootWindow()->last_mouse_location(); | |
| 565 tab_contents_->GetRenderViewHost()->DragTargetDragEnter( | |
| 566 drop_data, event.location(), screen_pt, op); | |
| 567 | |
| 568 if (GetDragDestDelegate()) { | |
| 569 GetDragDestDelegate()->OnReceiveDragData(event.data()); | |
| 570 GetDragDestDelegate()->OnDragEnter(); | |
| 571 } | |
| 572 } | |
| 573 | |
| 574 int TabContentsViewAura::OnDragUpdated(const aura::DropTargetEvent& event) { | |
| 575 WebKit::WebDragOperationsMask op = ConvertToWeb(event.source_operations()); | |
| 576 gfx::Point screen_pt = | |
| 577 GetNativeView()->GetRootWindow()->last_mouse_location(); | |
| 578 tab_contents_->GetRenderViewHost()->DragTargetDragOver( | |
| 579 event.location(), screen_pt, op); | |
| 580 | |
| 581 if (GetDragDestDelegate()) | |
| 582 GetDragDestDelegate()->OnDragOver(); | |
| 583 | |
| 584 return ConvertFromWeb(current_drag_op_); | |
| 585 } | |
| 586 | |
| 587 void TabContentsViewAura::OnDragExited() { | |
| 588 tab_contents_->GetRenderViewHost()->DragTargetDragLeave(); | |
| 589 if (GetDragDestDelegate()) | |
| 590 GetDragDestDelegate()->OnDragLeave(); | |
| 591 } | |
| 592 | |
| 593 int TabContentsViewAura::OnPerformDrop(const aura::DropTargetEvent& event) { | |
| 594 tab_contents_->GetRenderViewHost()->DragTargetDrop( | |
| 595 event.location(), | |
| 596 GetNativeView()->GetRootWindow()->last_mouse_location()); | |
| 597 if (GetDragDestDelegate()) | |
| 598 GetDragDestDelegate()->OnDrop(); | |
| 599 return current_drag_op_; | |
| 600 } | |
| OLD | NEW |