Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(28)

Side by Side Diff: chrome/browser/tab_contents/tab_contents_view_gtk.cc

Issue 150204: GTK: when doing a drag from a web page, pass a recent mouse down to gtk_drag_... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: Created 11 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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/mime_util.h"
(...skipping 332 matching lines...) Expand 10 before | Expand all | Expand 10 after
343 break; 343 break;
344 } 344 }
345 default: 345 default:
346 NOTREACHED() << "Got a notification we didn't register for."; 346 NOTREACHED() << "Got a notification we didn't register for.";
347 break; 347 break;
348 } 348 }
349 } 349 }
350 350
351 void TabContentsViewGtk::ShowContextMenu(const ContextMenuParams& params) { 351 void TabContentsViewGtk::ShowContextMenu(const ContextMenuParams& params) {
352 context_menu_.reset(new RenderViewContextMenuGtk(tab_contents(), params, 352 context_menu_.reset(new RenderViewContextMenuGtk(tab_contents(), params,
353 last_mouse_down_time_)); 353 last_mouse_down_.time));
354 context_menu_->Init(); 354 context_menu_->Init();
355 context_menu_->Popup(); 355 context_menu_->Popup();
356 } 356 }
357 357
358 // Render view DnD ------------------------------------------------------------- 358 // Render view DnD -------------------------------------------------------------
359 359
360 void TabContentsViewGtk::DragEnded() { 360 void TabContentsViewGtk::DragEnded() {
361 if (tab_contents()->render_view_host()) 361 if (tab_contents()->render_view_host())
362 tab_contents()->render_view_host()->DragSourceSystemDragEnded(); 362 tab_contents()->render_view_host()->DragSourceSystemDragEnded();
363 } 363 }
(...skipping 21 matching lines...) Expand all
385 drop_data_.reset(new WebDropData(drop_data)); 385 drop_data_.reset(new WebDropData(drop_data));
386 386
387 GtkTargetList* list = GtkDndUtil::GetTargetListFromCodeMask(targets_mask); 387 GtkTargetList* list = GtkDndUtil::GetTargetListFromCodeMask(targets_mask);
388 if (targets_mask & GtkDndUtil::X_CHROME_WEBDROP_FILE_CONTENTS) { 388 if (targets_mask & GtkDndUtil::X_CHROME_WEBDROP_FILE_CONTENTS) {
389 drag_file_mime_type_ = gdk_atom_intern( 389 drag_file_mime_type_ = gdk_atom_intern(
390 mime_util::GetDataMimeType(drop_data.file_contents).c_str(), FALSE); 390 mime_util::GetDataMimeType(drop_data.file_contents).c_str(), FALSE);
391 gtk_target_list_add(list, drag_file_mime_type_, 391 gtk_target_list_add(list, drag_file_mime_type_,
392 0, GtkDndUtil::X_CHROME_WEBDROP_FILE_CONTENTS); 392 0, GtkDndUtil::X_CHROME_WEBDROP_FILE_CONTENTS);
393 } 393 }
394 394
395 gtk_drag_begin(GetContentNativeView(), list, GDK_ACTION_COPY, 1, NULL); 395 // If we don't pass an event, GDK won't know what event time to start grabbing
396 // mouse events. Technically it's the mouse motion event and not the mouse
397 // down event that causes the drag, but there's no reliable way to know
398 // *which* motion event initiated the drag, so this will have to do.
399 gtk_drag_begin(GetContentNativeView(), list, GDK_ACTION_COPY,
400 last_mouse_down_.button,
401 reinterpret_cast<GdkEvent*>(&last_mouse_down_));
396 // The drag adds a ref; let it own the list. 402 // The drag adds a ref; let it own the list.
397 gtk_target_list_unref(list); 403 gtk_target_list_unref(list);
398 } 404 }
399 405
400 // static 406 // static
401 void TabContentsViewGtk::OnDragDataGet( 407 void TabContentsViewGtk::OnDragDataGet(
402 GtkWidget* drag_widget, 408 GtkWidget* drag_widget,
403 GdkDragContext* context, GtkSelectionData* selection_data, 409 GdkDragContext* context, GtkSelectionData* selection_data,
404 guint target_type, guint time, TabContentsViewGtk* view) { 410 guint target_type, guint time, TabContentsViewGtk* view) {
405 const int bits_per_byte = 8; 411 const int bits_per_byte = 8;
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
452 } 458 }
453 459
454 // ----------------------------------------------------------------------------- 460 // -----------------------------------------------------------------------------
455 461
456 void TabContentsViewGtk::InsertIntoContentArea(GtkWidget* widget) { 462 void TabContentsViewGtk::InsertIntoContentArea(GtkWidget* widget) {
457 gtk_fixed_put(GTK_FIXED(fixed_), widget, 0, 0); 463 gtk_fixed_put(GTK_FIXED(fixed_), widget, 0, 0);
458 } 464 }
459 465
460 gboolean TabContentsViewGtk::OnMouseDown(GtkWidget* widget, 466 gboolean TabContentsViewGtk::OnMouseDown(GtkWidget* widget,
461 GdkEventButton* event, TabContentsViewGtk* view) { 467 GdkEventButton* event, TabContentsViewGtk* view) {
462 view->last_mouse_down_time_ = event->time; 468 view->last_mouse_down_ = *event;
463 return FALSE; 469 return FALSE;
464 } 470 }
465 471
466 gboolean TabContentsViewGtk::OnSizeAllocate(GtkWidget* widget, 472 gboolean TabContentsViewGtk::OnSizeAllocate(GtkWidget* widget,
467 GtkAllocation* allocation, 473 GtkAllocation* allocation,
468 TabContentsViewGtk* view) { 474 TabContentsViewGtk* view) {
469 int width = allocation->width; 475 int width = allocation->width;
470 int height = allocation->height; 476 int height = allocation->height;
471 // |delegate()| can be NULL here during browser teardown. 477 // |delegate()| can be NULL here during browser teardown.
472 if (view->tab_contents()->delegate()) 478 if (view->tab_contents()->delegate())
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
529 gtk_container_child_set_property(GTK_CONTAINER(floating_container), 535 gtk_container_child_set_property(GTK_CONTAINER(floating_container),
530 widget, "x", &value); 536 widget, "x", &value);
531 537
532 int child_y = std::max(half_view_height - (requisition.height / 2), 0); 538 int child_y = std::max(half_view_height - (requisition.height / 2), 0);
533 g_value_set_int(&value, child_y); 539 g_value_set_int(&value, child_y);
534 gtk_container_child_set_property(GTK_CONTAINER(floating_container), 540 gtk_container_child_set_property(GTK_CONTAINER(floating_container),
535 widget, "y", &value); 541 widget, "y", &value);
536 g_value_unset(&value); 542 g_value_unset(&value);
537 } 543 }
538 } 544 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698