| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "content/browser/web_contents/web_drag_dest_gtk.h" | 5 #include "content/browser/web_contents/web_drag_dest_gtk.h" |
| 6 | 6 |
| 7 #include <string> | 7 #include <string> |
| 8 | 8 |
| 9 #include "base/bind.h" | 9 #include "base/bind.h" |
| 10 #include "base/file_path.h" | 10 #include "base/file_path.h" |
| 11 #include "base/message_loop.h" | 11 #include "base/message_loop.h" |
| 12 #include "base/utf_string_conversions.h" | 12 #include "base/utf_string_conversions.h" |
| 13 #include "content/browser/renderer_host/render_view_host_impl.h" | 13 #include "content/browser/renderer_host/render_view_host_impl.h" |
| 14 #include "content/browser/web_contents/drag_utils_gtk.h" | 14 #include "content/browser/web_contents/drag_utils_gtk.h" |
| 15 #include "content/browser/web_contents/web_contents_impl.h" | 15 #include "content/browser/web_contents/web_contents_impl.h" |
| 16 #include "content/public/browser/web_drag_dest_delegate.h" | 16 #include "content/public/browser/web_drag_dest_delegate.h" |
| 17 #include "content/public/common/url_constants.h" | 17 #include "content/public/common/url_constants.h" |
| 18 #include "net/base/net_util.h" | 18 #include "net/base/net_util.h" |
| 19 #include "third_party/WebKit/Source/WebKit/chromium/public/WebInputEvent.h" |
| 19 #include "ui/base/clipboard/custom_data_helper.h" | 20 #include "ui/base/clipboard/custom_data_helper.h" |
| 20 #include "ui/base/dragdrop/gtk_dnd_util.h" | 21 #include "ui/base/dragdrop/gtk_dnd_util.h" |
| 21 #include "ui/base/gtk/gtk_screen_util.h" | 22 #include "ui/base/gtk/gtk_screen_util.h" |
| 22 | 23 |
| 23 using content::RenderViewHostImpl; | 24 using content::RenderViewHostImpl; |
| 24 using WebKit::WebDragOperation; | 25 using WebKit::WebDragOperation; |
| 25 using WebKit::WebDragOperationNone; | 26 using WebKit::WebDragOperationNone; |
| 26 | 27 |
| 27 namespace content { | 28 namespace content { |
| 28 | 29 |
| 30 namespace { |
| 31 |
| 32 int GetModifierFlags(GtkWidget* widget) { |
| 33 int modifier_state = 0; |
| 34 GdkModifierType state; |
| 35 gdk_window_get_pointer(gtk_widget_get_window(widget), NULL, NULL, &state); |
| 36 |
| 37 if (state & GDK_SHIFT_MASK) |
| 38 modifier_state |= WebKit::WebInputEvent::ShiftKey; |
| 39 if (state & GDK_CONTROL_MASK) |
| 40 modifier_state |= WebKit::WebInputEvent::ControlKey; |
| 41 if (state & GDK_MOD1_MASK) |
| 42 modifier_state |= WebKit::WebInputEvent::AltKey; |
| 43 if (state & GDK_META_MASK) |
| 44 modifier_state |= WebKit::WebInputEvent::MetaKey; |
| 45 return modifier_state; |
| 46 } |
| 47 |
| 48 } // namespace |
| 49 |
| 29 WebDragDestGtk::WebDragDestGtk(WebContents* web_contents, GtkWidget* widget) | 50 WebDragDestGtk::WebDragDestGtk(WebContents* web_contents, GtkWidget* widget) |
| 30 : web_contents_(web_contents), | 51 : web_contents_(web_contents), |
| 31 widget_(widget), | 52 widget_(widget), |
| 32 context_(NULL), | 53 context_(NULL), |
| 33 data_requests_(0), | 54 data_requests_(0), |
| 34 delegate_(NULL), | 55 delegate_(NULL), |
| 35 method_factory_(this) { | 56 method_factory_(this) { |
| 36 gtk_drag_dest_set(widget, static_cast<GtkDestDefaults>(0), | 57 gtk_drag_dest_set(widget, static_cast<GtkDestDefaults>(0), |
| 37 NULL, 0, | 58 NULL, 0, |
| 38 static_cast<GdkDragAction>(GDK_ACTION_COPY | | 59 static_cast<GdkDragAction>(GDK_ACTION_COPY | |
| (...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 114 } | 135 } |
| 115 | 136 |
| 116 if (delegate()) { | 137 if (delegate()) { |
| 117 gtk_drag_get_data(widget_, context, delegate()->GetBookmarkTargetAtom(), | 138 gtk_drag_get_data(widget_, context, delegate()->GetBookmarkTargetAtom(), |
| 118 time); | 139 time); |
| 119 } | 140 } |
| 120 } else if (data_requests_ == 0) { | 141 } else if (data_requests_ == 0) { |
| 121 GetRenderViewHost()->DragTargetDragOver( | 142 GetRenderViewHost()->DragTargetDragOver( |
| 122 ui::ClientPoint(widget_), | 143 ui::ClientPoint(widget_), |
| 123 ui::ScreenPoint(widget_), | 144 ui::ScreenPoint(widget_), |
| 124 content::GdkDragActionToWebDragOp(context->actions)); | 145 content::GdkDragActionToWebDragOp(context->actions), |
| 146 GetModifierFlags(widget_)); |
| 125 | 147 |
| 126 if (delegate()) | 148 if (delegate()) |
| 127 delegate()->OnDragOver(); | 149 delegate()->OnDragOver(); |
| 128 | 150 |
| 129 drag_over_time_ = time; | 151 drag_over_time_ = time; |
| 130 } | 152 } |
| 131 | 153 |
| 132 // Pretend we are a drag destination because we don't want to wait for | 154 // Pretend we are a drag destination because we don't want to wait for |
| 133 // the renderer to tell us if we really are or not. | 155 // the renderer to tell us if we really are or not. |
| 134 return TRUE; | 156 return TRUE; |
| (...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 222 } | 244 } |
| 223 } | 245 } |
| 224 | 246 |
| 225 if (data_requests_ == 0) { | 247 if (data_requests_ == 0) { |
| 226 // Tell the renderer about the drag. | 248 // Tell the renderer about the drag. |
| 227 // |x| and |y| are seemingly arbitrary at this point. | 249 // |x| and |y| are seemingly arbitrary at this point. |
| 228 GetRenderViewHost()->DragTargetDragEnter( | 250 GetRenderViewHost()->DragTargetDragEnter( |
| 229 *drop_data_.get(), | 251 *drop_data_.get(), |
| 230 ui::ClientPoint(widget_), | 252 ui::ClientPoint(widget_), |
| 231 ui::ScreenPoint(widget_), | 253 ui::ScreenPoint(widget_), |
| 232 content::GdkDragActionToWebDragOp(context->actions)); | 254 content::GdkDragActionToWebDragOp(context->actions), |
| 255 GetModifierFlags(widget_)); |
| 233 | 256 |
| 234 if (delegate()) | 257 if (delegate()) |
| 235 delegate()->OnDragEnter(); | 258 delegate()->OnDragEnter(); |
| 236 | 259 |
| 237 drag_over_time_ = time; | 260 drag_over_time_ = time; |
| 238 } | 261 } |
| 239 } | 262 } |
| 240 | 263 |
| 241 // The drag has left our widget; forward this information to the renderer. | 264 // The drag has left our widget; forward this information to the renderer. |
| 242 void WebDragDestGtk::OnDragLeave(GtkWidget* sender, GdkDragContext* context, | 265 void WebDragDestGtk::OnDragLeave(GtkWidget* sender, GdkDragContext* context, |
| (...skipping 10 matching lines...) Expand all Loading... |
| 253 base::Bind(&WebDragDestGtk::DragLeave, method_factory_.GetWeakPtr())); | 276 base::Bind(&WebDragDestGtk::DragLeave, method_factory_.GetWeakPtr())); |
| 254 } | 277 } |
| 255 | 278 |
| 256 // Called by GTK when the user releases the mouse, executing a drop. | 279 // Called by GTK when the user releases the mouse, executing a drop. |
| 257 gboolean WebDragDestGtk::OnDragDrop(GtkWidget* sender, GdkDragContext* context, | 280 gboolean WebDragDestGtk::OnDragDrop(GtkWidget* sender, GdkDragContext* context, |
| 258 gint x, gint y, guint time) { | 281 gint x, gint y, guint time) { |
| 259 // Cancel that drag leave! | 282 // Cancel that drag leave! |
| 260 method_factory_.InvalidateWeakPtrs(); | 283 method_factory_.InvalidateWeakPtrs(); |
| 261 | 284 |
| 262 GetRenderViewHost()-> | 285 GetRenderViewHost()-> |
| 263 DragTargetDrop(ui::ClientPoint(widget_), ui::ScreenPoint(widget_)); | 286 DragTargetDrop(ui::ClientPoint(widget_), ui::ScreenPoint(widget_), |
| 287 GetModifierFlags(widget_)); |
| 264 | 288 |
| 265 if (delegate()) | 289 if (delegate()) |
| 266 delegate()->OnDrop(); | 290 delegate()->OnDrop(); |
| 267 | 291 |
| 268 // The second parameter is just an educated guess as to whether or not the | 292 // The second parameter is just an educated guess as to whether or not the |
| 269 // drag succeeded, but at least we will get the drag-end animation right | 293 // drag succeeded, but at least we will get the drag-end animation right |
| 270 // sometimes. | 294 // sometimes. |
| 271 gtk_drag_finish(context, is_drop_target_, FALSE, time); | 295 gtk_drag_finish(context, is_drop_target_, FALSE, time); |
| 272 | 296 |
| 273 return TRUE; | 297 return TRUE; |
| 274 } | 298 } |
| 275 | 299 |
| 276 RenderViewHostImpl* WebDragDestGtk::GetRenderViewHost() const { | 300 RenderViewHostImpl* WebDragDestGtk::GetRenderViewHost() const { |
| 277 return static_cast<RenderViewHostImpl*>(web_contents_->GetRenderViewHost()); | 301 return static_cast<RenderViewHostImpl*>(web_contents_->GetRenderViewHost()); |
| 278 } | 302 } |
| 279 | 303 |
| 280 } // namespace content | 304 } // namespace content |
| OLD | NEW |