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/views/tab_contents/native_tab_contents_view_gtk.h" | 5 #include "chrome/browser/ui/views/tab_contents/native_tab_contents_view_gtk.h" |
6 | 6 |
7 #include "base/utf_string_conversions.h" | 7 #include "base/utf_string_conversions.h" |
8 #include "chrome/browser/tab_contents/web_drag_dest_gtk.h" | 8 #include "chrome/browser/tab_contents/web_drag_dest_gtk.h" |
9 #include "chrome/browser/ui/gtk/constrained_window_gtk.h" | 9 #include "chrome/browser/ui/gtk/constrained_window_gtk.h" |
10 #include "chrome/browser/ui/gtk/tab_contents_drag_source.h" | 10 #include "chrome/browser/ui/gtk/tab_contents_drag_source.h" |
| 11 #include "chrome/browser/tab_contents/web_drag_bookmark_handler_gtk.h" |
11 #include "chrome/browser/ui/views/tab_contents/native_tab_contents_view_delegate
.h" | 12 #include "chrome/browser/ui/views/tab_contents/native_tab_contents_view_delegate
.h" |
12 #include "chrome/browser/ui/views/tab_contents/native_tab_contents_view_views.h" | 13 #include "chrome/browser/ui/views/tab_contents/native_tab_contents_view_views.h" |
13 #include "content/browser/renderer_host/render_widget_host_view_gtk.h" | 14 #include "content/browser/renderer_host/render_widget_host_view_gtk.h" |
14 #include "content/browser/tab_contents/tab_contents.h" | 15 #include "content/browser/tab_contents/tab_contents.h" |
15 #include "content/browser/tab_contents/tab_contents_view.h" | 16 #include "content/browser/tab_contents/tab_contents_view.h" |
16 #include "third_party/WebKit/Source/WebKit/chromium/public/WebDragData.h" | 17 #include "third_party/WebKit/Source/WebKit/chromium/public/WebDragData.h" |
17 #include "third_party/WebKit/Source/WebKit/chromium/public/WebInputEvent.h" | 18 #include "third_party/WebKit/Source/WebKit/chromium/public/WebInputEvent.h" |
18 | 19 |
19 #if defined(OS_CHROMEOS) | 20 #if defined(OS_CHROMEOS) |
20 #include "chrome/browser/chromeos/login/user_manager.h" | 21 #include "chrome/browser/chromeos/login/user_manager.h" |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
56 } | 57 } |
57 if (event->direction == GDK_SCROLL_UP) { | 58 if (event->direction == GDK_SCROLL_UP) { |
58 delegate->OnNativeTabContentsViewWheelZoom(true); | 59 delegate->OnNativeTabContentsViewWheelZoom(true); |
59 return TRUE; | 60 return TRUE; |
60 } | 61 } |
61 } | 62 } |
62 | 63 |
63 return FALSE; | 64 return FALSE; |
64 } | 65 } |
65 | 66 |
| 67 // Our dragging needs to use views datatypes instead of the default GTK ones. |
| 68 class WebDragBookmarkHandlerViewGtk : public WebDragBookmarkHandlerGtk { |
| 69 public: |
| 70 virtual GdkAtom GetBookmarkTargetAtom() const { |
| 71 // For Views, bookmark drag data is encoded in the same format, and |
| 72 // associated with a custom format. See BookmarkNodeData::Write() for |
| 73 // details. |
| 74 return BookmarkNodeData::GetBookmarkCustomFormat(); |
| 75 } |
| 76 }; |
| 77 |
66 } // namespace | 78 } // namespace |
67 | 79 |
68 //////////////////////////////////////////////////////////////////////////////// | 80 //////////////////////////////////////////////////////////////////////////////// |
69 // NativeTabContentsViewGtk, public: | 81 // NativeTabContentsViewGtk, public: |
70 | 82 |
71 NativeTabContentsViewGtk::NativeTabContentsViewGtk( | 83 NativeTabContentsViewGtk::NativeTabContentsViewGtk( |
72 internal::NativeTabContentsViewDelegate* delegate) | 84 internal::NativeTabContentsViewDelegate* delegate) |
73 : views::NativeWidgetGtk(delegate->AsNativeWidgetDelegate()), | 85 : views::NativeWidgetGtk(delegate->AsNativeWidgetDelegate()), |
74 delegate_(delegate), | 86 delegate_(delegate), |
75 ignore_next_char_event_(false), | 87 ignore_next_char_event_(false), |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
128 view->InitAsChild(); | 140 view->InitAsChild(); |
129 g_signal_connect(view->native_view(), "focus", | 141 g_signal_connect(view->native_view(), "focus", |
130 G_CALLBACK(OnFocus), delegate_->GetTabContents()); | 142 G_CALLBACK(OnFocus), delegate_->GetTabContents()); |
131 g_signal_connect(view->native_view(), "scroll-event", | 143 g_signal_connect(view->native_view(), "scroll-event", |
132 G_CALLBACK(OnMouseScroll), delegate_); | 144 G_CALLBACK(OnMouseScroll), delegate_); |
133 | 145 |
134 // Let widget know that the tab contents has been painted. | 146 // Let widget know that the tab contents has been painted. |
135 views::NativeWidgetGtk::RegisterChildExposeHandler(view->native_view()); | 147 views::NativeWidgetGtk::RegisterChildExposeHandler(view->native_view()); |
136 | 148 |
137 // Renderer target DnD. | 149 // Renderer target DnD. |
138 if (delegate_->GetTabContents()->ShouldAcceptDragAndDrop()) | 150 if (delegate_->GetTabContents()->ShouldAcceptDragAndDrop()) { |
139 drag_dest_.reset(new WebDragDestGtk(delegate_->GetTabContents(), | 151 drag_dest_.reset(new WebDragDestGtk(delegate_->GetTabContents(), |
140 view->native_view())); | 152 view->native_view())); |
| 153 bookmark_handler_gtk_.reset(new WebDragBookmarkHandlerGtk); |
| 154 drag_dest_->set_delegate(bookmark_handler_gtk_.get()); |
| 155 } |
141 | 156 |
142 gtk_fixed_put(GTK_FIXED(GetWidget()->GetNativeView()), view->native_view(), 0, | 157 gtk_fixed_put(GTK_FIXED(GetWidget()->GetNativeView()), view->native_view(), 0, |
143 0); | 158 0); |
144 return view; | 159 return view; |
145 } | 160 } |
146 | 161 |
147 gfx::NativeWindow NativeTabContentsViewGtk::GetTopLevelNativeWindow() const { | 162 gfx::NativeWindow NativeTabContentsViewGtk::GetTopLevelNativeWindow() const { |
148 GtkWidget* window = gtk_widget_get_ancestor(GetWidget()->GetNativeView(), | 163 GtkWidget* window = gtk_widget_get_ancestor(GetWidget()->GetNativeView(), |
149 GTK_TYPE_WINDOW); | 164 GTK_TYPE_WINDOW); |
150 return window ? GTK_WINDOW(window) : NULL; | 165 return window ? GTK_WINDOW(window) : NULL; |
(...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
270 //////////////////////////////////////////////////////////////////////////////// | 285 //////////////////////////////////////////////////////////////////////////////// |
271 // NativeTabContentsView, public: | 286 // NativeTabContentsView, public: |
272 | 287 |
273 // static | 288 // static |
274 NativeTabContentsView* NativeTabContentsView::CreateNativeTabContentsView( | 289 NativeTabContentsView* NativeTabContentsView::CreateNativeTabContentsView( |
275 internal::NativeTabContentsViewDelegate* delegate) { | 290 internal::NativeTabContentsViewDelegate* delegate) { |
276 if (views::Widget::IsPureViews()) | 291 if (views::Widget::IsPureViews()) |
277 return new NativeTabContentsViewViews(delegate); | 292 return new NativeTabContentsViewViews(delegate); |
278 return new NativeTabContentsViewGtk(delegate); | 293 return new NativeTabContentsViewGtk(delegate); |
279 } | 294 } |
OLD | NEW |