| OLD | NEW |
| 1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2009 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/tab_contents/tab_contents_view_gtk.h" | 5 #include "chrome/browser/tab_contents/tab_contents_view_gtk.h" |
| 6 | 6 |
| 7 #include <gdk/gdk.h> | 7 #include <gdk/gdk.h> |
| 8 #include <gtk/gtk.h> | 8 #include <gtk/gtk.h> |
| 9 | 9 |
| 10 #include "base/mime_util.h" |
| 10 #include "base/gfx/point.h" | 11 #include "base/gfx/point.h" |
| 11 #include "base/gfx/rect.h" | 12 #include "base/gfx/rect.h" |
| 12 #include "base/gfx/size.h" | 13 #include "base/gfx/size.h" |
| 13 #include "base/string_util.h" | 14 #include "base/string_util.h" |
| 14 #include "build/build_config.h" | 15 #include "build/build_config.h" |
| 15 #include "chrome/browser/download/download_shelf.h" | 16 #include "chrome/browser/download/download_shelf.h" |
| 16 #include "chrome/browser/gtk/blocked_popup_container_view_gtk.h" | 17 #include "chrome/browser/gtk/blocked_popup_container_view_gtk.h" |
| 17 #include "chrome/browser/gtk/browser_window_gtk.h" | 18 #include "chrome/browser/gtk/browser_window_gtk.h" |
| 18 #include "chrome/browser/gtk/constrained_window_gtk.h" | 19 #include "chrome/browser/gtk/constrained_window_gtk.h" |
| 19 #include "chrome/browser/gtk/dnd_registry.h" | 20 #include "chrome/browser/gtk/gtk_dnd_util.h" |
| 20 #include "chrome/browser/gtk/gtk_floating_container.h" | 21 #include "chrome/browser/gtk/gtk_floating_container.h" |
| 21 #include "chrome/browser/gtk/sad_tab_gtk.h" | 22 #include "chrome/browser/gtk/sad_tab_gtk.h" |
| 22 #include "chrome/browser/renderer_host/render_view_host.h" | 23 #include "chrome/browser/renderer_host/render_view_host.h" |
| 23 #include "chrome/browser/renderer_host/render_view_host_factory.h" | 24 #include "chrome/browser/renderer_host/render_view_host_factory.h" |
| 24 #include "chrome/browser/renderer_host/render_widget_host_view_gtk.h" | 25 #include "chrome/browser/renderer_host/render_widget_host_view_gtk.h" |
| 25 #include "chrome/browser/tab_contents/interstitial_page.h" | 26 #include "chrome/browser/tab_contents/interstitial_page.h" |
| 26 #include "chrome/browser/tab_contents/render_view_context_menu_gtk.h" | 27 #include "chrome/browser/tab_contents/render_view_context_menu_gtk.h" |
| 27 #include "chrome/browser/tab_contents/tab_contents.h" | 28 #include "chrome/browser/tab_contents/tab_contents.h" |
| 28 #include "chrome/browser/tab_contents/tab_contents_delegate.h" | 29 #include "chrome/browser/tab_contents/tab_contents_delegate.h" |
| 29 #include "chrome/common/gtk_util.h" | 30 #include "chrome/common/gtk_util.h" |
| (...skipping 327 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 357 // Render view DnD ------------------------------------------------------------- | 358 // Render view DnD ------------------------------------------------------------- |
| 358 | 359 |
| 359 void TabContentsViewGtk::DragEnded() { | 360 void TabContentsViewGtk::DragEnded() { |
| 360 if (tab_contents()->render_view_host()) | 361 if (tab_contents()->render_view_host()) |
| 361 tab_contents()->render_view_host()->DragSourceSystemDragEnded(); | 362 tab_contents()->render_view_host()->DragSourceSystemDragEnded(); |
| 362 } | 363 } |
| 363 | 364 |
| 364 void TabContentsViewGtk::StartDragging(const WebDropData& drop_data) { | 365 void TabContentsViewGtk::StartDragging(const WebDropData& drop_data) { |
| 365 DCHECK(GetContentNativeView()); | 366 DCHECK(GetContentNativeView()); |
| 366 | 367 |
| 367 if (drop_data.plain_text.empty()) { | 368 int targets_mask = 0; |
| 368 NOTIMPLEMENTED() << "Only plain text drags supported, sorry!"; | 369 |
| 370 if (!drop_data.plain_text.empty()) |
| 371 targets_mask |= GtkDndUtil::X_CHROME_TEXT_PLAIN; |
| 372 if (drop_data.url.is_valid()) |
| 373 targets_mask |= GtkDndUtil::X_CHROME_TEXT_URI_LIST; |
| 374 if (!drop_data.text_html.empty()) |
| 375 targets_mask |= GtkDndUtil::X_CHROME_TEXT_HTML; |
| 376 if (!drop_data.file_contents.empty()) |
| 377 targets_mask |= GtkDndUtil::X_CHROME_WEBDROP_FILE_CONTENTS; |
| 378 |
| 379 if (targets_mask == 0) { |
| 380 NOTIMPLEMENTED(); |
| 369 DragEnded(); | 381 DragEnded(); |
| 370 return; | 382 return; |
| 371 } | 383 } |
| 372 | 384 |
| 373 drop_data_.reset(new WebDropData(drop_data)); | 385 drop_data_.reset(new WebDropData(drop_data)); |
| 374 | 386 |
| 375 GtkTargetList* list = gtk_target_list_new(NULL, 0); | 387 GtkTargetList* list = GtkDndUtil::GetTargetListFromCodeMask(targets_mask); |
| 376 gtk_target_list_add_text_targets(list, dnd::X_CHROME_TEXT_PLAIN); | 388 if (targets_mask & GtkDndUtil::X_CHROME_WEBDROP_FILE_CONTENTS) { |
| 389 drag_file_mime_type_ = gdk_atom_intern( |
| 390 mime_util::GetDataMimeType(drop_data.file_contents).c_str(), FALSE); |
| 391 gtk_target_list_add(list, drag_file_mime_type_, |
| 392 0, GtkDndUtil::X_CHROME_WEBDROP_FILE_CONTENTS); |
| 393 } |
| 394 |
| 377 gtk_drag_begin(GetContentNativeView(), list, GDK_ACTION_COPY, 1, NULL); | 395 gtk_drag_begin(GetContentNativeView(), list, GDK_ACTION_COPY, 1, NULL); |
| 378 // The drag adds a ref; let it own the list. | 396 // The drag adds a ref; let it own the list. |
| 379 gtk_target_list_unref(list); | 397 gtk_target_list_unref(list); |
| 380 } | 398 } |
| 381 | 399 |
| 382 // static | 400 // static |
| 383 void TabContentsViewGtk::OnDragDataGet( | 401 void TabContentsViewGtk::OnDragDataGet( |
| 384 GtkWidget* drag_widget, | 402 GtkWidget* drag_widget, |
| 385 GdkDragContext* context, GtkSelectionData* selection_data, | 403 GdkDragContext* context, GtkSelectionData* selection_data, |
| 386 guint target_type, guint time, TabContentsViewGtk* view) { | 404 guint target_type, guint time, TabContentsViewGtk* view) { |
| 387 std::string utf8_text(UTF16ToUTF8(view->drop_data_->plain_text)); | 405 const int bits_per_byte = 8; |
| 388 gtk_selection_data_set_text(selection_data, utf8_text.c_str(), | 406 // We must make this initialization here or gcc complains about jumping past |
| 389 utf8_text.length()); | 407 // it in the switch statement. |
| 408 std::string utf8_text; |
| 409 |
| 410 switch (target_type) { |
| 411 case GtkDndUtil::X_CHROME_TEXT_PLAIN: |
| 412 utf8_text = UTF16ToUTF8(view->drop_data_->plain_text); |
| 413 gtk_selection_data_set_text(selection_data, utf8_text.c_str(), |
| 414 utf8_text.length()); |
| 415 break; |
| 416 case GtkDndUtil::X_CHROME_TEXT_URI_LIST: |
| 417 gchar* uri_array[2]; |
| 418 uri_array[0] = strdup(view->drop_data_->url.spec().c_str()); |
| 419 uri_array[1] = NULL; |
| 420 gtk_selection_data_set_uris(selection_data, uri_array); |
| 421 free(uri_array[0]); |
| 422 break; |
| 423 case GtkDndUtil::X_CHROME_TEXT_HTML: |
| 424 // TODO(estade): change relative links to be absolute using |
| 425 // |html_base_url|. |
| 426 utf8_text = UTF16ToUTF8(view->drop_data_->text_html); |
| 427 gtk_selection_data_set(selection_data, |
| 428 GtkDndUtil::GetAtomForTarget(GtkDndUtil::X_CHROME_TEXT_HTML), |
| 429 bits_per_byte, |
| 430 reinterpret_cast<const guchar*>(utf8_text.c_str()), |
| 431 utf8_text.length()); |
| 432 break; |
| 433 |
| 434 case GtkDndUtil::X_CHROME_WEBDROP_FILE_CONTENTS: |
| 435 gtk_selection_data_set(selection_data, |
| 436 view->drag_file_mime_type_, bits_per_byte, |
| 437 reinterpret_cast<const guchar*>( |
| 438 view->drop_data_->file_contents.data()), |
| 439 view->drop_data_->file_contents.length()); |
| 440 break; |
| 441 |
| 442 default: |
| 443 NOTREACHED(); |
| 444 } |
| 390 } | 445 } |
| 391 | 446 |
| 392 // static | 447 // static |
| 393 void TabContentsViewGtk::OnDragEnd(GtkWidget* widget, | 448 void TabContentsViewGtk::OnDragEnd(GtkWidget* widget, |
| 394 GdkDragContext* drag_context, TabContentsViewGtk* view) { | 449 GdkDragContext* drag_context, TabContentsViewGtk* view) { |
| 395 view->DragEnded(); | 450 view->DragEnded(); |
| 396 view->drop_data_.reset(); | 451 view->drop_data_.reset(); |
| 397 } | 452 } |
| 398 | 453 |
| 399 // ----------------------------------------------------------------------------- | 454 // ----------------------------------------------------------------------------- |
| (...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 474 gtk_container_child_set_property(GTK_CONTAINER(floating_container), | 529 gtk_container_child_set_property(GTK_CONTAINER(floating_container), |
| 475 widget, "x", &value); | 530 widget, "x", &value); |
| 476 | 531 |
| 477 int child_y = std::max(half_view_height - (requisition.height / 2), 0); | 532 int child_y = std::max(half_view_height - (requisition.height / 2), 0); |
| 478 g_value_set_int(&value, child_y); | 533 g_value_set_int(&value, child_y); |
| 479 gtk_container_child_set_property(GTK_CONTAINER(floating_container), | 534 gtk_container_child_set_property(GTK_CONTAINER(floating_container), |
| 480 widget, "y", &value); | 535 widget, "y", &value); |
| 481 g_value_unset(&value); | 536 g_value_unset(&value); |
| 482 } | 537 } |
| 483 } | 538 } |
| OLD | NEW |