| OLD | NEW |
| 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 <gdk/gdkkeysyms.h> | 8 #include <gdk/gdkkeysyms.h> |
| 9 #include <gtk/gtk.h> | 9 #include <gtk/gtk.h> |
| 10 | 10 |
| (...skipping 18 matching lines...) Expand all Loading... |
| 29 #include "chrome/browser/tab_contents/interstitial_page.h" | 29 #include "chrome/browser/tab_contents/interstitial_page.h" |
| 30 #include "chrome/browser/tab_contents/render_view_context_menu_gtk.h" | 30 #include "chrome/browser/tab_contents/render_view_context_menu_gtk.h" |
| 31 #include "chrome/browser/tab_contents/tab_contents.h" | 31 #include "chrome/browser/tab_contents/tab_contents.h" |
| 32 #include "chrome/browser/tab_contents/tab_contents_delegate.h" | 32 #include "chrome/browser/tab_contents/tab_contents_delegate.h" |
| 33 #include "chrome/common/gtk_util.h" | 33 #include "chrome/common/gtk_util.h" |
| 34 #include "chrome/common/notification_service.h" | 34 #include "chrome/common/notification_service.h" |
| 35 #include "chrome/common/notification_source.h" | 35 #include "chrome/common/notification_source.h" |
| 36 #include "chrome/common/notification_type.h" | 36 #include "chrome/common/notification_type.h" |
| 37 #include "webkit/glue/webdropdata.h" | 37 #include "webkit/glue/webdropdata.h" |
| 38 | 38 |
| 39 using WebKit::WebDragOperation; |
| 40 using WebKit::WebDragOperationCopy; |
| 41 using WebKit::WebDragOperationNone; |
| 42 using WebKit::WebDragOperationsMask; |
| 43 |
| 39 namespace { | 44 namespace { |
| 40 | 45 |
| 41 // TODO(erg): I have no idea how to programatically figure out how wide the | 46 // TODO(erg): I have no idea how to programatically figure out how wide the |
| 42 // vertical scrollbar is. Hack it with a hardcoded value for now. | 47 // vertical scrollbar is. Hack it with a hardcoded value for now. |
| 43 const int kScrollbarWidthHack = 25; | 48 const int kScrollbarWidthHack = 25; |
| 44 | 49 |
| 45 // Called when the content view gtk widget is tabbed to, or after the call to | 50 // Called when the content view gtk widget is tabbed to, or after the call to |
| 46 // gtk_widget_child_focus() in TakeFocus(). We return true | 51 // gtk_widget_child_focus() in TakeFocus(). We return true |
| 47 // and grab focus if we don't have it. The call to | 52 // and grab focus if we don't have it. The call to |
| 48 // FocusThroughTabTraversal(bool) forwards the "move focus forward" effect to | 53 // FocusThroughTabTraversal(bool) forwards the "move focus forward" effect to |
| (...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 132 | 137 |
| 133 ~WebDragDest() { | 138 ~WebDragDest() { |
| 134 if (widget_) { | 139 if (widget_) { |
| 135 gtk_drag_dest_unset(widget_); | 140 gtk_drag_dest_unset(widget_); |
| 136 g_signal_handler_disconnect(widget_, destroy_handler_); | 141 g_signal_handler_disconnect(widget_, destroy_handler_); |
| 137 } | 142 } |
| 138 } | 143 } |
| 139 | 144 |
| 140 // This is called when the renderer responds to a drag motion event. We must | 145 // This is called when the renderer responds to a drag motion event. We must |
| 141 // update the system drag cursor. | 146 // update the system drag cursor. |
| 142 void UpdateDragStatus(bool is_drop_target) { | 147 void UpdateDragStatus(WebDragOperation operation) { |
| 143 if (context_) { | 148 if (context_) { |
| 144 // TODO(estade): we might want to support other actions besides copy, | 149 // TODO(estade): we might want to support other actions besides copy, |
| 145 // but that would increase the cost of getting our drag success guess | 150 // but that would increase the cost of getting our drag success guess |
| 146 // wrong. | 151 // wrong. |
| 147 gdk_drag_status(context_, is_drop_target ? GDK_ACTION_COPY : | 152 is_drop_target_ = operation != WebDragOperationNone; |
| 153 // TODO(snej): Pass appropriate GDK action instead of hardcoding COPY |
| 154 gdk_drag_status(context_, is_drop_target_ ? GDK_ACTION_COPY : |
| 148 static_cast<GdkDragAction>(0), | 155 static_cast<GdkDragAction>(0), |
| 149 drag_over_time_); | 156 drag_over_time_); |
| 150 is_drop_target_ = false; | |
| 151 } | 157 } |
| 152 } | 158 } |
| 153 | 159 |
| 154 // Informs the renderer when a system drag has left the render view. | 160 // Informs the renderer when a system drag has left the render view. |
| 155 // See OnDragLeave(). | 161 // See OnDragLeave(). |
| 156 void DragLeave() { | 162 void DragLeave() { |
| 157 tab_contents_->render_view_host()->DragTargetDragLeave(); | 163 tab_contents_->render_view_host()->DragTargetDragLeave(); |
| 158 } | 164 } |
| 159 | 165 |
| 160 private: | 166 private: |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 196 | 202 |
| 197 data_requests_ = arraysize(supported_targets); | 203 data_requests_ = arraysize(supported_targets); |
| 198 for (size_t i = 0; i < arraysize(supported_targets); ++i) { | 204 for (size_t i = 0; i < arraysize(supported_targets); ++i) { |
| 199 gtk_drag_get_data(widget_, context, | 205 gtk_drag_get_data(widget_, context, |
| 200 GtkDndUtil::GetAtomForTarget(supported_targets[i]), | 206 GtkDndUtil::GetAtomForTarget(supported_targets[i]), |
| 201 time); | 207 time); |
| 202 } | 208 } |
| 203 } else if (data_requests_ == 0) { | 209 } else if (data_requests_ == 0) { |
| 204 tab_contents_->render_view_host()-> | 210 tab_contents_->render_view_host()-> |
| 205 DragTargetDragOver(gtk_util::ClientPoint(widget_), | 211 DragTargetDragOver(gtk_util::ClientPoint(widget_), |
| 206 gtk_util::ScreenPoint(widget_)); | 212 gtk_util::ScreenPoint(widget_), |
| 213 WebDragOperationCopy); |
| 214 // TODO(snej): Pass appropriate DragOperation instead of hardcoding |
| 207 drag_over_time_ = time; | 215 drag_over_time_ = time; |
| 208 } | 216 } |
| 209 | 217 |
| 210 // Pretend we are a drag destination because we don't want to wait for | 218 // Pretend we are a drag destination because we don't want to wait for |
| 211 // the renderer to tell us if we really are or not. | 219 // the renderer to tell us if we really are or not. |
| 212 return TRUE; | 220 return TRUE; |
| 213 } | 221 } |
| 214 | 222 |
| 215 // We make a series of requests for the drag data when the drag first enters | 223 // We make a series of requests for the drag data when the drag first enters |
| 216 // the render view. This is the callback that is used to give us the data | 224 // the render view. This is the callback that is used to give us the data |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 259 // We leave the base URL empty. | 267 // We leave the base URL empty. |
| 260 } | 268 } |
| 261 } | 269 } |
| 262 | 270 |
| 263 if (data_requests_ == 0) { | 271 if (data_requests_ == 0) { |
| 264 // Tell the renderer about the drag. | 272 // Tell the renderer about the drag. |
| 265 // |x| and |y| are seemingly arbitrary at this point. | 273 // |x| and |y| are seemingly arbitrary at this point. |
| 266 tab_contents_->render_view_host()-> | 274 tab_contents_->render_view_host()-> |
| 267 DragTargetDragEnter(*drop_data_.get(), | 275 DragTargetDragEnter(*drop_data_.get(), |
| 268 gtk_util::ClientPoint(widget_), | 276 gtk_util::ClientPoint(widget_), |
| 269 gtk_util::ScreenPoint(widget_)); | 277 gtk_util::ScreenPoint(widget_), |
| 278 WebDragOperationCopy); |
| 279 // TODO(snej): Pass appropriate DragOperation instead of hardcoding |
| 270 drag_over_time_ = time; | 280 drag_over_time_ = time; |
| 271 } | 281 } |
| 272 } | 282 } |
| 273 | 283 |
| 274 // The drag has left our widget; forward this information to the renderer. | 284 // The drag has left our widget; forward this information to the renderer. |
| 275 void OnDragLeave(GdkDragContext* context, guint time) { | 285 void OnDragLeave(GdkDragContext* context, guint time) { |
| 276 // Set |context_| to NULL to make sure we will recognize the next DragMotion | 286 // Set |context_| to NULL to make sure we will recognize the next DragMotion |
| 277 // as an enter. | 287 // as an enter. |
| 278 context_ = NULL; | 288 context_ = NULL; |
| 279 drop_data_.reset(); | 289 drop_data_.reset(); |
| (...skipping 246 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 526 focus_store_.Store(GetNativeView()); | 536 focus_store_.Store(GetNativeView()); |
| 527 } | 537 } |
| 528 | 538 |
| 529 void TabContentsViewGtk::RestoreFocus() { | 539 void TabContentsViewGtk::RestoreFocus() { |
| 530 if (focus_store_.widget()) | 540 if (focus_store_.widget()) |
| 531 gtk_widget_grab_focus(focus_store_.widget()); | 541 gtk_widget_grab_focus(focus_store_.widget()); |
| 532 else | 542 else |
| 533 SetInitialFocus(); | 543 SetInitialFocus(); |
| 534 } | 544 } |
| 535 | 545 |
| 536 void TabContentsViewGtk::UpdateDragCursor(bool is_drop_target) { | 546 void TabContentsViewGtk::UpdateDragCursor(WebDragOperation operation) { |
| 537 drag_dest_->UpdateDragStatus(is_drop_target); | 547 drag_dest_->UpdateDragStatus(operation); |
| 538 } | 548 } |
| 539 | 549 |
| 540 void TabContentsViewGtk::GotFocus() { | 550 void TabContentsViewGtk::GotFocus() { |
| 541 NOTIMPLEMENTED(); | 551 NOTIMPLEMENTED(); |
| 542 } | 552 } |
| 543 | 553 |
| 544 // This is called when we the renderer asks us to take focus back (i.e., it has | 554 // This is called when we the renderer asks us to take focus back (i.e., it has |
| 545 // iterated past the last focusable element on the page). | 555 // iterated past the last focusable element on the page). |
| 546 void TabContentsViewGtk::TakeFocus(bool reverse) { | 556 void TabContentsViewGtk::TakeFocus(bool reverse) { |
| 547 gtk_widget_child_focus(GTK_WIDGET(GetTopLevelNativeWindow()), | 557 gtk_widget_child_focus(GTK_WIDGET(GetTopLevelNativeWindow()), |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 591 | 601 |
| 592 void TabContentsViewGtk::ShowContextMenu(const ContextMenuParams& params) { | 602 void TabContentsViewGtk::ShowContextMenu(const ContextMenuParams& params) { |
| 593 context_menu_.reset(new RenderViewContextMenuGtk(tab_contents(), params, | 603 context_menu_.reset(new RenderViewContextMenuGtk(tab_contents(), params, |
| 594 last_mouse_down_.time)); | 604 last_mouse_down_.time)); |
| 595 context_menu_->Init(); | 605 context_menu_->Init(); |
| 596 context_menu_->Popup(); | 606 context_menu_->Popup(); |
| 597 } | 607 } |
| 598 | 608 |
| 599 // Render view DnD ------------------------------------------------------------- | 609 // Render view DnD ------------------------------------------------------------- |
| 600 | 610 |
| 601 void TabContentsViewGtk::StartDragging(const WebDropData& drop_data) { | 611 void TabContentsViewGtk::StartDragging(const WebDropData& drop_data, |
| 612 WebDragOperationsMask ops) { |
| 602 DCHECK(GetContentNativeView()); | 613 DCHECK(GetContentNativeView()); |
| 603 | 614 |
| 604 drag_source_->StartDragging(drop_data, &last_mouse_down_); | 615 drag_source_->StartDragging(drop_data, &last_mouse_down_); |
| 616 // TODO(snej): Make use of the WebDragOperationsMask somehow |
| 605 } | 617 } |
| 606 | 618 |
| 607 // ----------------------------------------------------------------------------- | 619 // ----------------------------------------------------------------------------- |
| 608 | 620 |
| 609 void TabContentsViewGtk::InsertIntoContentArea(GtkWidget* widget) { | 621 void TabContentsViewGtk::InsertIntoContentArea(GtkWidget* widget) { |
| 610 gtk_fixed_put(GTK_FIXED(fixed_), widget, 0, 0); | 622 gtk_fixed_put(GTK_FIXED(fixed_), widget, 0, 0); |
| 611 } | 623 } |
| 612 | 624 |
| 613 gboolean TabContentsViewGtk::OnMouseDown(GtkWidget* widget, | 625 gboolean TabContentsViewGtk::OnMouseDown(GtkWidget* widget, |
| 614 GdkEventButton* event, TabContentsViewGtk* view) { | 626 GdkEventButton* event, TabContentsViewGtk* view) { |
| (...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 682 gtk_container_child_set_property(GTK_CONTAINER(floating_container), | 694 gtk_container_child_set_property(GTK_CONTAINER(floating_container), |
| 683 widget, "x", &value); | 695 widget, "x", &value); |
| 684 | 696 |
| 685 int child_y = std::max(half_view_height - (requisition.height / 2), 0); | 697 int child_y = std::max(half_view_height - (requisition.height / 2), 0); |
| 686 g_value_set_int(&value, child_y); | 698 g_value_set_int(&value, child_y); |
| 687 gtk_container_child_set_property(GTK_CONTAINER(floating_container), | 699 gtk_container_child_set_property(GTK_CONTAINER(floating_container), |
| 688 widget, "y", &value); | 700 widget, "y", &value); |
| 689 g_value_unset(&value); | 701 g_value_unset(&value); |
| 690 } | 702 } |
| 691 } | 703 } |
| OLD | NEW |