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

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

Issue 147245: Linux web drag first cut.... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: connect once 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/string_util.h"
11 #include "base/gfx/point.h" 10 #include "base/gfx/point.h"
12 #include "base/gfx/rect.h" 11 #include "base/gfx/rect.h"
13 #include "base/gfx/size.h" 12 #include "base/gfx/size.h"
13 #include "base/string_util.h"
14 #include "build/build_config.h" 14 #include "build/build_config.h"
15 #include "chrome/browser/download/download_shelf.h" 15 #include "chrome/browser/download/download_shelf.h"
16 #include "chrome/browser/gtk/blocked_popup_container_view_gtk.h" 16 #include "chrome/browser/gtk/blocked_popup_container_view_gtk.h"
17 #include "chrome/browser/gtk/browser_window_gtk.h" 17 #include "chrome/browser/gtk/browser_window_gtk.h"
18 #include "chrome/browser/gtk/constrained_window_gtk.h" 18 #include "chrome/browser/gtk/constrained_window_gtk.h"
19 #include "chrome/browser/gtk/dnd_registry.h"
19 #include "chrome/browser/gtk/gtk_floating_container.h" 20 #include "chrome/browser/gtk/gtk_floating_container.h"
20 #include "chrome/browser/gtk/sad_tab_gtk.h" 21 #include "chrome/browser/gtk/sad_tab_gtk.h"
21 #include "chrome/browser/renderer_host/render_view_host.h" 22 #include "chrome/browser/renderer_host/render_view_host.h"
22 #include "chrome/browser/renderer_host/render_view_host_factory.h" 23 #include "chrome/browser/renderer_host/render_view_host_factory.h"
23 #include "chrome/browser/renderer_host/render_widget_host_view_gtk.h" 24 #include "chrome/browser/renderer_host/render_widget_host_view_gtk.h"
24 #include "chrome/browser/tab_contents/interstitial_page.h" 25 #include "chrome/browser/tab_contents/interstitial_page.h"
25 #include "chrome/browser/tab_contents/render_view_context_menu_gtk.h" 26 #include "chrome/browser/tab_contents/render_view_context_menu_gtk.h"
26 #include "chrome/browser/tab_contents/tab_contents.h" 27 #include "chrome/browser/tab_contents/tab_contents.h"
27 #include "chrome/browser/tab_contents/tab_contents_delegate.h" 28 #include "chrome/browser/tab_contents/tab_contents_delegate.h"
28 #include "chrome/common/gtk_util.h" 29 #include "chrome/common/gtk_util.h"
29 #include "chrome/common/notification_source.h" 30 #include "chrome/common/notification_source.h"
30 #include "chrome/common/notification_type.h" 31 #include "chrome/common/notification_type.h"
32 #include "webkit/glue/webdropdata.h"
31 33
32 namespace { 34 namespace {
33 35
34 // TODO(erg): I have no idea how to progromatically figure out how wide the 36 // TODO(erg): I have no idea how to progromatically figure out how wide the
35 // vertical scrollbar is. Hack it with a hardcoded value for now. 37 // vertical scrollbar is. Hack it with a hardcoded value for now.
36 const int kScrollbarWidthHack = 25; 38 const int kScrollbarWidthHack = 25;
37 39
38 // Called when the content view gtk widget is tabbed to, or after the call to 40 // Called when the content view gtk widget is tabbed to, or after the call to
39 // gtk_widget_child_focus() in TakeFocus(). We return true 41 // gtk_widget_child_focus() in TakeFocus(). We return true
40 // and grab focus if we don't have it. The call to 42 // and grab focus if we don't have it. The call to
(...skipping 148 matching lines...) Expand 10 before | Expand all | Expand 10 after
189 G_CALLBACK(OnLeaveNotify), tab_contents()); 191 G_CALLBACK(OnLeaveNotify), tab_contents());
190 g_signal_connect(content_view, "motion-notify-event", 192 g_signal_connect(content_view, "motion-notify-event",
191 G_CALLBACK(OnMouseMove), tab_contents()); 193 G_CALLBACK(OnMouseMove), tab_contents());
192 g_signal_connect(content_view, "scroll-event", 194 g_signal_connect(content_view, "scroll-event",
193 G_CALLBACK(OnMouseScroll), tab_contents()); 195 G_CALLBACK(OnMouseScroll), tab_contents());
194 gtk_widget_add_events(content_view, GDK_LEAVE_NOTIFY_MASK | 196 gtk_widget_add_events(content_view, GDK_LEAVE_NOTIFY_MASK |
195 GDK_POINTER_MOTION_MASK); 197 GDK_POINTER_MOTION_MASK);
196 g_signal_connect(content_view, "button-press-event", 198 g_signal_connect(content_view, "button-press-event",
197 G_CALLBACK(OnMouseDown), this); 199 G_CALLBACK(OnMouseDown), this);
198 200
201 // DnD signals.
202 g_signal_connect(content_view, "drag-end", G_CALLBACK(OnDragEnd), this);
203 g_signal_connect(content_view, "drag-data-get", G_CALLBACK(OnDragDataGet),
204 this);
205
199 InsertIntoContentArea(content_view); 206 InsertIntoContentArea(content_view);
200 return view; 207 return view;
201 } 208 }
202 209
203 gfx::NativeView TabContentsViewGtk::GetNativeView() const { 210 gfx::NativeView TabContentsViewGtk::GetNativeView() const {
204 return floating_.get(); 211 return floating_.get();
205 } 212 }
206 213
207 gfx::NativeView TabContentsViewGtk::GetContentNativeView() const { 214 gfx::NativeView TabContentsViewGtk::GetContentNativeView() const {
208 if (!tab_contents()->render_widget_host_view()) 215 if (!tab_contents()->render_widget_host_view())
(...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after
340 } 347 }
341 } 348 }
342 349
343 void TabContentsViewGtk::ShowContextMenu(const ContextMenuParams& params) { 350 void TabContentsViewGtk::ShowContextMenu(const ContextMenuParams& params) {
344 context_menu_.reset(new RenderViewContextMenuGtk(tab_contents(), params, 351 context_menu_.reset(new RenderViewContextMenuGtk(tab_contents(), params,
345 last_mouse_down_time_)); 352 last_mouse_down_time_));
346 context_menu_->Init(); 353 context_menu_->Init();
347 context_menu_->Popup(); 354 context_menu_->Popup();
348 } 355 }
349 356
350 void TabContentsViewGtk::StartDragging(const WebDropData& drop_data) { 357 // Webkit DnD ------------------------------------------------------------------
351 NOTIMPLEMENTED();
352 358
353 // Until we have d'n'd implemented, just immediately pretend we're 359 void TabContentsViewGtk::DragEnded() {
354 // already done with the drag and drop so we don't get stuck
355 // thinking we're in mid-drag.
356 // TODO(port): remove me when the above NOTIMPLEMENTED is fixed.
357 if (tab_contents()->render_view_host()) 360 if (tab_contents()->render_view_host())
358 tab_contents()->render_view_host()->DragSourceSystemDragEnded(); 361 tab_contents()->render_view_host()->DragSourceSystemDragEnded();
359 } 362 }
360 363
364 void TabContentsViewGtk::StartDragging(const WebDropData& drop_data) {
365 DCHECK(GetContentNativeView());
366
367 if (drop_data.plain_text.empty()) {
368 NOTIMPLEMENTED() << "Only plain text drags supported, sorry!";
369 DragEnded();
370 return;
371 }
372
373 drop_data_.reset(new WebDropData(drop_data));
374
375 GtkTargetList* list = gtk_target_list_new(NULL, 0);
376 gtk_target_list_add_text_targets(list, dnd::X_CHROME_TEXT_PLAIN);
377 gtk_drag_begin(GetContentNativeView(), list, GDK_ACTION_COPY, 1, NULL);
378 // The drag adds a ref; let it own the list.
379 gtk_target_list_unref(list);
380 }
381
382 // static
383 void TabContentsViewGtk::OnDragDataGet(
384 GtkWidget* drag_widget,
385 GdkDragContext* context, GtkSelectionData* selection_data,
386 guint target_type, guint time, TabContentsViewGtk* view) {
387 std::string utf8_text(UTF16ToUTF8(view->drop_data_->plain_text));
388 gtk_selection_data_set_text(selection_data, utf8_text.c_str(),
389 utf8_text.length());
390 }
391
392 // static
393 void TabContentsViewGtk::OnDragEnd(GtkWidget* widget,
394 GdkDragContext* drag_context, TabContentsViewGtk* view) {
395 view->DragEnded();
396 view->drop_data_.reset();
397 }
398
399 // -----------------------------------------------------------------------------
400
361 void TabContentsViewGtk::InsertIntoContentArea(GtkWidget* widget) { 401 void TabContentsViewGtk::InsertIntoContentArea(GtkWidget* widget) {
362 gtk_fixed_put(GTK_FIXED(fixed_), widget, 0, 0); 402 gtk_fixed_put(GTK_FIXED(fixed_), widget, 0, 0);
363 } 403 }
364 404
365 gboolean TabContentsViewGtk::OnMouseDown(GtkWidget* widget, 405 gboolean TabContentsViewGtk::OnMouseDown(GtkWidget* widget,
366 GdkEventButton* event, TabContentsViewGtk* view) { 406 GdkEventButton* event, TabContentsViewGtk* view) {
367 view->last_mouse_down_time_ = event->time; 407 view->last_mouse_down_time_ = event->time;
368 return FALSE; 408 return FALSE;
369 } 409 }
370 410
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
434 gtk_container_child_set_property(GTK_CONTAINER(floating_container), 474 gtk_container_child_set_property(GTK_CONTAINER(floating_container),
435 widget, "x", &value); 475 widget, "x", &value);
436 476
437 int child_y = std::max(half_view_height - (requisition.height / 2), 0); 477 int child_y = std::max(half_view_height - (requisition.height / 2), 0);
438 g_value_set_int(&value, child_y); 478 g_value_set_int(&value, child_y);
439 gtk_container_child_set_property(GTK_CONTAINER(floating_container), 479 gtk_container_child_set_property(GTK_CONTAINER(floating_container),
440 widget, "y", &value); 480 widget, "y", &value);
441 g_value_unset(&value); 481 g_value_unset(&value);
442 } 482 }
443 } 483 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698