OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/ui/gtk/tabs/tab_gtk.h" | 5 #include "chrome/browser/ui/gtk/tabs/tab_gtk.h" |
6 | 6 |
7 #include <gdk/gdkkeysyms.h> | 7 #include <gdk/gdkkeysyms.h> |
8 | 8 |
9 #include "app/gtk_dnd_util.h" | |
10 #include "base/singleton.h" | 9 #include "base/singleton.h" |
11 #include "base/utf_string_conversions.h" | 10 #include "base/utf_string_conversions.h" |
12 #include "chrome/app/chrome_command_ids.h" | 11 #include "chrome/app/chrome_command_ids.h" |
13 #include "chrome/browser/ui/gtk/accelerators_gtk.h" | 12 #include "chrome/browser/ui/gtk/accelerators_gtk.h" |
14 #include "chrome/browser/ui/gtk/menu_gtk.h" | 13 #include "chrome/browser/ui/gtk/menu_gtk.h" |
15 #include "chrome/browser/ui/tabs/tab_menu_model.h" | 14 #include "chrome/browser/ui/tabs/tab_menu_model.h" |
16 #include "gfx/path.h" | 15 #include "gfx/path.h" |
17 #include "grit/generated_resources.h" | 16 #include "grit/generated_resources.h" |
18 #include "grit/theme_resources.h" | 17 #include "grit/theme_resources.h" |
| 18 #include "ui/base/dragdrop/gtk_dnd_util.h" |
19 #include "ui/base/models/accelerator_gtk.h" | 19 #include "ui/base/models/accelerator_gtk.h" |
20 | 20 |
21 namespace { | 21 namespace { |
22 | 22 |
23 // Returns the width of the title for the current font, in pixels. | 23 // Returns the width of the title for the current font, in pixels. |
24 int GetTitleWidth(gfx::Font* font, string16 title) { | 24 int GetTitleWidth(gfx::Font* font, string16 title) { |
25 DCHECK(font); | 25 DCHECK(font); |
26 if (title.empty()) | 26 if (title.empty()) |
27 return 0; | 27 return 0; |
28 | 28 |
(...skipping 329 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
358 void TabGtk::DestroyDragWidget() { | 358 void TabGtk::DestroyDragWidget() { |
359 if (drag_widget_) { | 359 if (drag_widget_) { |
360 gtk_widget_destroy(drag_widget_); | 360 gtk_widget_destroy(drag_widget_); |
361 drag_widget_ = NULL; | 361 drag_widget_ = NULL; |
362 } | 362 } |
363 } | 363 } |
364 | 364 |
365 void TabGtk::StartDragging(gfx::Point drag_offset) { | 365 void TabGtk::StartDragging(gfx::Point drag_offset) { |
366 CreateDragWidget(); | 366 CreateDragWidget(); |
367 | 367 |
368 GtkTargetList* list = gtk_dnd_util::GetTargetListFromCodeMask( | 368 GtkTargetList* list = ui::GetTargetListFromCodeMask(ui::CHROME_TAB); |
369 gtk_dnd_util::CHROME_TAB); | |
370 gtk_drag_begin(drag_widget_, list, GDK_ACTION_MOVE, | 369 gtk_drag_begin(drag_widget_, list, GDK_ACTION_MOVE, |
371 1, // Drags are always initiated by the left button. | 370 1, // Drags are always initiated by the left button. |
372 last_mouse_down_); | 371 last_mouse_down_); |
373 | 372 |
374 delegate_->MaybeStartDrag(this, drag_offset); | 373 delegate_->MaybeStartDrag(this, drag_offset); |
375 } | 374 } |
376 | 375 |
377 void TabGtk::EndDrag(bool canceled) { | 376 void TabGtk::EndDrag(bool canceled) { |
378 // Make sure we only run EndDrag once by canceling any tasks that want | 377 // Make sure we only run EndDrag once by canceling any tasks that want |
379 // to call EndDrag. | 378 // to call EndDrag. |
380 drag_end_factory_.RevokeAll(); | 379 drag_end_factory_.RevokeAll(); |
381 | 380 |
382 // We must let gtk clean up after we handle the drag operation, otherwise | 381 // We must let gtk clean up after we handle the drag operation, otherwise |
383 // there will be outstanding references to the drag widget when we try to | 382 // there will be outstanding references to the drag widget when we try to |
384 // destroy it. | 383 // destroy it. |
385 MessageLoop::current()->PostTask(FROM_HERE, | 384 MessageLoop::current()->PostTask(FROM_HERE, |
386 destroy_factory_.NewRunnableMethod(&TabGtk::DestroyDragWidget)); | 385 destroy_factory_.NewRunnableMethod(&TabGtk::DestroyDragWidget)); |
387 | 386 |
388 if (last_mouse_down_) { | 387 if (last_mouse_down_) { |
389 gdk_event_free(last_mouse_down_); | 388 gdk_event_free(last_mouse_down_); |
390 last_mouse_down_ = NULL; | 389 last_mouse_down_ = NULL; |
391 } | 390 } |
392 | 391 |
393 // Notify the drag helper that we're done with any potential drag operations. | 392 // Notify the drag helper that we're done with any potential drag operations. |
394 // Clean up the drag helper, which is re-created on the next mouse press. | 393 // Clean up the drag helper, which is re-created on the next mouse press. |
395 delegate_->EndDrag(canceled); | 394 delegate_->EndDrag(canceled); |
396 | 395 |
397 observer_.reset(); | 396 observer_.reset(); |
398 } | 397 } |
OLD | NEW |