summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorsky@chromium.org <sky@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-08-18 21:44:19 +0000
committersky@chromium.org <sky@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-08-18 21:44:19 +0000
commit302e0e1a827df92e6eba995ce589a871954f5bf2 (patch)
tree0dd29c01c54948b297e258828b91f2776c18f08c
parent3af66ca4e22b15e29a96794f5a9f4ab356d17b87 (diff)
downloadchromium_src-302e0e1a827df92e6eba995ce589a871954f5bf2.zip
chromium_src-302e0e1a827df92e6eba995ce589a871954f5bf2.tar.gz
chromium_src-302e0e1a827df92e6eba995ce589a871954f5bf2.tar.bz2
Reverts recent patch as broke build on toolkit_views.
TBR=ben BUG=none TEST=none Review URL: http://codereview.chromium.org/174023 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@23658 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r--chrome/browser/browser_focus_uitest.cc11
-rw-r--r--chrome/browser/browser_init_browsertest.cc1
-rw-r--r--chrome/browser/renderer_host/render_widget_host.cc5
-rw-r--r--chrome/browser/views/bookmark_bar_view.cc14
-rw-r--r--chrome/browser/views/bookmark_bar_view.h4
-rw-r--r--chrome/browser/views/bookmark_menu_button.cc16
-rw-r--r--chrome/browser/views/bookmark_menu_button.h4
-rw-r--r--chrome/browser/views/frame/browser_root_view.cc41
-rw-r--r--chrome/browser/views/frame/browser_root_view.h6
-rw-r--r--chrome/test/automated_ui_tests/automated_ui_test_base.cc3
-rw-r--r--chrome/test/automated_ui_tests/automated_ui_tests.cc3
-rw-r--r--views/view.cc11
-rw-r--r--views/view.h28
-rw-r--r--views/views.gyp2
-rw-r--r--views/widget/drop_helper.cc20
-rw-r--r--views/widget/drop_target_gtk.cc329
-rw-r--r--views/widget/drop_target_gtk.h113
-rw-r--r--views/widget/widget_gtk.cc152
-rw-r--r--views/widget/widget_gtk.h53
19 files changed, 45 insertions, 771 deletions
diff --git a/chrome/browser/browser_focus_uitest.cc b/chrome/browser/browser_focus_uitest.cc
index 4007ebd..1c1c012 100644
--- a/chrome/browser/browser_focus_uitest.cc
+++ b/chrome/browser/browser_focus_uitest.cc
@@ -7,11 +7,12 @@
#include "base/ref_counted.h"
#include "chrome/browser/automation/ui_controls.h"
#include "chrome/browser/browser.h"
-#include "chrome/browser/browser_window.h"
-#include "chrome/browser/renderer_host/render_view_host.h"
#include "chrome/browser/renderer_host/render_widget_host_view.h"
#include "chrome/browser/tab_contents/interstitial_page.h"
#include "chrome/browser/view_ids.h"
+#include "chrome/browser/views/frame/browser_view.h"
+#include "chrome/browser/views/location_bar_view.h"
+#include "chrome/browser/views/tab_contents/tab_contents_container.h"
#include "chrome/common/chrome_paths.h"
#include "chrome/test/in_process_browser_test.h"
#include "chrome/test/ui_test_utils.h"
@@ -19,12 +20,6 @@
#include "views/view.h"
#include "views/window/window.h"
-#if defined(TOOLKIT_VIEWS)
-#include "chrome/browser/views/frame/browser_view.h"
-#include "chrome/browser/views/location_bar_view.h"
-#include "chrome/browser/views/tab_contents/tab_contents_container.h"
-#endif
-
#if defined(OS_LINUX)
#include "chrome/browser/gtk/view_id_util.h"
#endif
diff --git a/chrome/browser/browser_init_browsertest.cc b/chrome/browser/browser_init_browsertest.cc
index f5337f4..a343caf 100644
--- a/chrome/browser/browser_init_browsertest.cc
+++ b/chrome/browser/browser_init_browsertest.cc
@@ -6,6 +6,7 @@
#include "chrome/browser/browser_init.h"
#include "chrome/browser/browser_list.h"
#include "chrome/browser/browser_window.h"
+#include "chrome/browser/views/frame/browser_view.h"
#include "chrome/test/in_process_browser_test.h"
#include "testing/gtest/include/gtest/gtest.h"
diff --git a/chrome/browser/renderer_host/render_widget_host.cc b/chrome/browser/renderer_host/render_widget_host.cc
index c7d7e19..996f63f 100644
--- a/chrome/browser/renderer_host/render_widget_host.cc
+++ b/chrome/browser/renderer_host/render_widget_host.cc
@@ -15,11 +15,8 @@
#include "chrome/browser/renderer_host/render_widget_host_view.h"
#include "chrome/common/notification_service.h"
#include "chrome/common/render_messages.h"
-#include "webkit/glue/webcursor.h"
-
-#if defined(TOOLKIT_VIEWS)
#include "views/view.h"
-#endif
+#include "webkit/glue/webcursor.h"
#if defined(OS_WIN)
#include "base/gfx/gdi_util.h"
diff --git a/chrome/browser/views/bookmark_bar_view.cc b/chrome/browser/views/bookmark_bar_view.cc
index 4afe926..28bdec8 100644
--- a/chrome/browser/views/bookmark_bar_view.cc
+++ b/chrome/browser/views/bookmark_bar_view.cc
@@ -870,20 +870,6 @@ void BookmarkBarView::PaintChildren(gfx::Canvas* canvas) {
}
}
-bool BookmarkBarView::GetDropFormats(
- int* formats,
- std::set<OSExchangeData::CustomFormat>* custom_formats) {
- if (!model_ || !model_->IsLoaded())
- return false;
- *formats = OSExchangeData::URL;
- custom_formats->insert(BookmarkDragData::GetBookmarkCustomFormat());
- return true;
-}
-
-bool BookmarkBarView::AreDropTypesRequired() {
- return true;
-}
-
bool BookmarkBarView::CanDrop(const OSExchangeData& data) {
if (!model_ || !model_->IsLoaded())
return false;
diff --git a/chrome/browser/views/bookmark_bar_view.h b/chrome/browser/views/bookmark_bar_view.h
index caca1aa..b82b669 100644
--- a/chrome/browser/views/bookmark_bar_view.h
+++ b/chrome/browser/views/bookmark_bar_view.h
@@ -97,10 +97,6 @@ class BookmarkBarView : public views::View,
virtual void ViewHierarchyChanged(bool is_add, View* parent, View* child);
virtual void Paint(gfx::Canvas* canvas);
virtual void PaintChildren(gfx::Canvas* canvas);
- virtual bool GetDropFormats(
- int* formats,
- std::set<OSExchangeData::CustomFormat>* custom_formats);
- virtual bool AreDropTypesRequired();
virtual bool CanDrop(const OSExchangeData& data);
virtual void OnDragEntered(const views::DropTargetEvent& event);
virtual int OnDragUpdated(const views::DropTargetEvent& event);
diff --git a/chrome/browser/views/bookmark_menu_button.cc b/chrome/browser/views/bookmark_menu_button.cc
index 577189e..4a4889b 100644
--- a/chrome/browser/views/bookmark_menu_button.cc
+++ b/chrome/browser/views/bookmark_menu_button.cc
@@ -40,22 +40,6 @@ BookmarkMenuButton::~BookmarkMenuButton() {
bookmark_drop_menu_->set_observer(NULL);
}
-bool BookmarkMenuButton::GetDropFormats(
- int* formats,
- std::set<OSExchangeData::CustomFormat>* custom_formats) {
- BookmarkModel* bookmark_model = GetBookmarkModel();
- if (!bookmark_model || !bookmark_model->IsLoaded())
- return false;
-
- *formats = OSExchangeData::URL;
- custom_formats->insert(BookmarkDragData::GetBookmarkCustomFormat());
- return true;
-}
-
-bool BookmarkMenuButton::AreDropTypesRequired() {
- return true;
-}
-
bool BookmarkMenuButton::CanDrop(const OSExchangeData& data) {
BookmarkModel* bookmark_model = GetBookmarkModel();
if (!bookmark_model || !bookmark_model->IsLoaded())
diff --git a/chrome/browser/views/bookmark_menu_button.h b/chrome/browser/views/bookmark_menu_button.h
index 7a7fd7e..aeed549 100644
--- a/chrome/browser/views/bookmark_menu_button.h
+++ b/chrome/browser/views/bookmark_menu_button.h
@@ -26,10 +26,6 @@ class BookmarkMenuButton : public views::MenuButton,
virtual ~BookmarkMenuButton();
// View drop methods.
- virtual bool GetDropFormats(
- int* formats,
- std::set<OSExchangeData::CustomFormat>* custom_formats);
- virtual bool AreDropTypesRequired();
virtual bool CanDrop(const OSExchangeData& data);
virtual int OnDragUpdated(const views::DropTargetEvent& event);
virtual void OnDragExited();
diff --git a/chrome/browser/views/frame/browser_root_view.cc b/chrome/browser/views/frame/browser_root_view.cc
index 753a3314..5e471c6 100644
--- a/chrome/browser/views/frame/browser_root_view.cc
+++ b/chrome/browser/views/frame/browser_root_view.cc
@@ -13,27 +13,18 @@
BrowserRootView::BrowserRootView(views::Widget* widget)
: views::RootView(widget),
tabstrip_(NULL),
+ can_drop_(false),
forwarding_to_tab_strip_(false) {
}
-bool BrowserRootView::GetDropFormats(
- int* formats,
- std::set<OSExchangeData::CustomFormat>* custom_formats) {
- if (tabstrip_ && tabstrip_->GetView()->IsVisible() &&
- !tabstrip_->IsAnimating()) {
- *formats = OSExchangeData::URL;
- return true;
- }
- return false;
-}
-
bool BrowserRootView::CanDrop(const OSExchangeData& data) {
- return (tabstrip_ && tabstrip_->GetView()->IsVisible() &&
- !tabstrip_->IsAnimating());
+ can_drop_ = (tabstrip_ && tabstrip_->GetView()->IsVisible() &&
+ !tabstrip_->IsAnimating() && data.HasURL());
+ return can_drop_;
}
void BrowserRootView::OnDragEntered(const views::DropTargetEvent& event) {
- if (ShouldForwardToTabStrip(event)) {
+ if (can_drop_ && ShouldForwardToTabStrip(event)) {
forwarding_to_tab_strip_ = true;
scoped_ptr<views::DropTargetEvent> mapped_event(MapEventToTabStrip(event));
tabstrip_->GetView()->OnDragEntered(*mapped_event.get());
@@ -41,17 +32,19 @@ void BrowserRootView::OnDragEntered(const views::DropTargetEvent& event) {
}
int BrowserRootView::OnDragUpdated(const views::DropTargetEvent& event) {
- if (ShouldForwardToTabStrip(event)) {
- scoped_ptr<views::DropTargetEvent> mapped_event(
- MapEventToTabStrip(event));
- if (!forwarding_to_tab_strip_) {
- tabstrip_->GetView()->OnDragEntered(*mapped_event.get());
- forwarding_to_tab_strip_ = true;
+ if (can_drop_) {
+ if (ShouldForwardToTabStrip(event)) {
+ scoped_ptr<views::DropTargetEvent> mapped_event(
+ MapEventToTabStrip(event));
+ if (!forwarding_to_tab_strip_) {
+ tabstrip_->GetView()->OnDragEntered(*mapped_event.get());
+ forwarding_to_tab_strip_ = true;
+ }
+ return tabstrip_->GetView()->OnDragUpdated(*mapped_event.get());
+ } else if (forwarding_to_tab_strip_) {
+ forwarding_to_tab_strip_ = false;
+ tabstrip_->GetView()->OnDragExited();
}
- return tabstrip_->GetView()->OnDragUpdated(*mapped_event.get());
- } else if (forwarding_to_tab_strip_) {
- forwarding_to_tab_strip_ = false;
- tabstrip_->GetView()->OnDragExited();
}
return DragDropTypes::DRAG_NONE;
}
diff --git a/chrome/browser/views/frame/browser_root_view.h b/chrome/browser/views/frame/browser_root_view.h
index 5ead7cc..370ef5f 100644
--- a/chrome/browser/views/frame/browser_root_view.h
+++ b/chrome/browser/views/frame/browser_root_view.h
@@ -25,9 +25,6 @@ class BrowserRootView : public views::RootView {
// tabstrip set.
void set_tabstrip(TabStripWrapper* tabstrip) { tabstrip_ = tabstrip; }
- virtual bool GetDropFormats(
- int* formats,
- std::set<OSExchangeData::CustomFormat>* custom_formats);
virtual bool CanDrop(const OSExchangeData& data);
virtual void OnDragEntered(const views::DropTargetEvent& event);
virtual int OnDragUpdated(const views::DropTargetEvent& event);
@@ -46,6 +43,9 @@ class BrowserRootView : public views::RootView {
// The TabStrip.
TabStripWrapper* tabstrip_;
+ // Is a drop allowed? This is set by CanDrop.
+ bool can_drop_;
+
// If true, drag and drop events are being forwarded to the tab strip.
// This is used to determine when to send OnDragEntered and OnDragExited
// to the tab strip.
diff --git a/chrome/test/automated_ui_tests/automated_ui_test_base.cc b/chrome/test/automated_ui_tests/automated_ui_test_base.cc
index 981965d..4e842a2 100644
--- a/chrome/test/automated_ui_tests/automated_ui_test_base.cc
+++ b/chrome/test/automated_ui_tests/automated_ui_test_base.cc
@@ -9,10 +9,7 @@
#include "chrome/test/automation/tab_proxy.h"
#include "chrome/test/automation/window_proxy.h"
#include "chrome/test/ui/ui_test.h"
-
-#if defined(TOOLKIT_VIEWS)
#include "views/view.h"
-#endif
AutomatedUITestBase::AutomatedUITestBase() {}
diff --git a/chrome/test/automated_ui_tests/automated_ui_tests.cc b/chrome/test/automated_ui_tests/automated_ui_tests.cc
index a2b6611..c29e2aa 100644
--- a/chrome/test/automated_ui_tests/automated_ui_tests.cc
+++ b/chrome/test/automated_ui_tests/automated_ui_tests.cc
@@ -26,10 +26,7 @@
#include "chrome/test/automation/window_proxy.h"
#include "chrome/test/ui/ui_test.h"
#include "googleurl/src/gurl.h"
-
-#if defined(TOOLKIT_VIEWS)
#include "views/view.h"
-#endif
namespace {
diff --git a/views/view.cc b/views/view.cc
index 30a6e74..4adef5b 100644
--- a/views/view.cc
+++ b/views/view.cc
@@ -1238,18 +1238,7 @@ DragController* View::GetDragController() {
return drag_controller_;
}
-bool View::GetDropFormats(
- int* formats,
- std::set<OSExchangeData::CustomFormat>* custom_formats) {
- return false;
-}
-
-bool View::AreDropTypesRequired() {
- return false;
-}
-
bool View::CanDrop(const OSExchangeData& data) {
- // TODO(sky): when I finish up migration, this should default to true.
return false;
}
diff --git a/views/view.h b/views/view.h
index 66ef76f..ba892c1 100644
--- a/views/view.h
+++ b/views/view.h
@@ -9,11 +9,9 @@
#include <algorithm>
#include <map>
-#include <set>
#include <string>
#include <vector>
-#include "app/os_exchange_data.h"
#include "base/gfx/native_widget_types.h"
#include "base/gfx/rect.h"
#include "base/scoped_ptr.h"
@@ -22,12 +20,17 @@
#include "views/background.h"
#include "views/border.h"
+#if defined(OS_WIN)
+struct IDataObject;
+#endif // defined(OS_WIN)
+
namespace gfx {
class Canvas;
class Insets;
class Path;
}
+class OSExchangeData;
class ViewAccessibilityWrapper;
class ThemeProvider;
@@ -739,12 +742,9 @@ class View : public AcceleratorTarget {
DragController* GetDragController();
// During a drag and drop session when the mouse moves the view under the
- // mouse is queried for the drop types it supports by way of the
- // GetDropFormats methods. If the view returns true and the drag site can
- // provide data in one of the formats, the view is asked if the drop data
- // is required before any other drop events are sent. Once the
- // data is available the view is asked if it supports the drop (by way of
- // the CanDrop method). If a view returns true from CanDrop,
+ // mouse is queried to see if it should be a target for the drag and drop
+ // session. A view indicates it is a valid target by returning true from
+ // CanDrop. If a view returns true from CanDrop,
// OnDragEntered is sent to the view when the mouse first enters the view,
// as the mouse moves around within the view OnDragUpdated is invoked.
// If the user releases the mouse over the view and OnDragUpdated returns a
@@ -756,18 +756,6 @@ class View : public AcceleratorTarget {
// the mouse does not support the drop, the ancestors are walked until one
// is found that supports the drop.
- // Override and return the set of formats that can be dropped on this view.
- // |formats| is a bitmask of the formats defined bye OSExchangeData::Format.
- // The default implementation returns false, which means the view doesn't
- // support dropping.
- virtual bool GetDropFormats(
- int* formats,
- std::set<OSExchangeData::CustomFormat>* custom_formats);
-
- // Override and return true if the data must be available before any drop
- // methods should be invoked. The default is false.
- virtual bool AreDropTypesRequired();
-
// A view that supports drag and drop must override this and return true if
// data contains a type that may be dropped on this view.
virtual bool CanDrop(const OSExchangeData& data);
diff --git a/views/views.gyp b/views/views.gyp
index 3e57c01..7c458a9 100644
--- a/views/views.gyp
+++ b/views/views.gyp
@@ -214,8 +214,6 @@
'widget/default_theme_provider.h',
'widget/drop_helper.cc',
'widget/drop_helper.h',
- 'widget/drop_target_gtk.cc',
- 'widget/drop_target_gtk.h',
'widget/drop_target_win.cc',
'widget/drop_target_win.h',
'widget/root_view.cc',
diff --git a/views/widget/drop_helper.cc b/views/widget/drop_helper.cc
index 19b70b71..35dcbd0 100644
--- a/views/widget/drop_helper.cc
+++ b/views/widget/drop_helper.cc
@@ -87,10 +87,6 @@ View* DropHelper::CalculateTargetViewImpl(
}
if (deepest_view)
*deepest_view = view;
- // TODO(sky): for the time being these are separate. Once I port chrome menu
- // I can switch to the #else implementation and nuke the OS_WIN
- // implementation.
-#if defined(OS_WIN)
// View under mouse changed, which means a new view may want the drop.
// Walk the tree, stopping at target_view_ as we know it'll accept the
// drop.
@@ -98,22 +94,6 @@ View* DropHelper::CalculateTargetViewImpl(
(!view->IsEnabled() || !view->CanDrop(data))) {
view = view->GetParent();
}
-#else
- int formats = 0;
- std::set<OSExchangeData::CustomFormat> custom_formats;
- while (view && view != target_view_) {
- if (view->IsEnabled() &&
- view->GetDropFormats(&formats, &custom_formats) &&
- data.HasAnyFormat(formats, custom_formats) &&
- (!check_can_drop || view->CanDrop(data))) {
- // Found the view.
- return view;
- }
- formats = 0;
- custom_formats.clear();
- view = view->GetParent();
- }
-#endif
return view;
}
diff --git a/views/widget/drop_target_gtk.cc b/views/widget/drop_target_gtk.cc
deleted file mode 100644
index 4c7dae7..0000000
--- a/views/widget/drop_target_gtk.cc
+++ /dev/null
@@ -1,329 +0,0 @@
-// Copyright (c) 2009 The Chromium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-#include "views/widget/drop_target_gtk.h"
-
-#include <algorithm>
-#include <iterator>
-
-#include "app/drag_drop_types.h"
-#include "app/gtk_dnd_util.h"
-#include "app/os_exchange_data_provider_gtk.h"
-#include "base/gfx/point.h"
-#include "base/string_util.h"
-#include "views/widget/root_view.h"
-#include "views/widget/widget_gtk.h"
-
-namespace {
-
-std::string GdkAtomToString(GdkAtom atom) {
- gchar* c_name = gdk_atom_name(atom);
- std::string name(c_name);
- g_free(c_name);
- return name;
-}
-
-// Returns true if |name| is a known name of plain text.
-bool IsTextType(const std::string& name) {
- return name == "text/plain" || name == "TEXT" ||
- name == "STRING" || name == "UTF8_STRING";
-}
-
-// Returns the OSExchangeData::Formats in |targets| and all the
-// OSExchangeData::CustomFormats in |type_set|.
-int CalculateTypes(GList* targets, std::set<GdkAtom>* type_set) {
- int types = 0;
- NOTIMPLEMENTED(); // Need to support FILE_NAME, FILE_CONTENTS
- for (GList* element = targets; element;
- element = g_list_next(element)) {
- GdkAtom atom = static_cast<GdkAtom>(element->data);
- type_set->insert(atom);
- if (atom == GDK_TARGET_STRING) {
- types |= OSExchangeData::STRING;
- } else if (atom == GtkDndUtil::GetAtomForTarget(
- GtkDndUtil::CHROME_NAMED_URL) ||
- atom == GtkDndUtil::GetAtomForTarget(
- GtkDndUtil::TEXT_URI_LIST)) {
- types |= OSExchangeData::URL;
- } else {
- std::string target_name = GdkAtomToString(atom);
- if (target_name == "text/html") {
- types |= OSExchangeData::HTML;
- } else if (IsTextType(target_name)) {
- types |= OSExchangeData::STRING;
- } else {
- // Assume any unknown data is pickled.
- types |= OSExchangeData::PICKLED_DATA;
- }
- }
- }
- return types;
-}
-
-} // namespace
-
-namespace views {
-
-DropTargetGtk::DropTargetGtk(RootView* root_view,
- GdkDragContext* context)
- : helper_(root_view),
- requested_formats_(0),
- waiting_for_data_(false),
- received_drop_(false),
- pending_view_(NULL) {
- std::set<GdkAtom> all_formats;
- int source_formats = CalculateTypes(context->targets, &all_formats);
- data_.reset(new OSExchangeData(new OSExchangeDataProviderGtk(
- source_formats, all_formats)));
-}
-
-DropTargetGtk::~DropTargetGtk() {
-}
-
-void DropTargetGtk::ResetTargetViewIfEquals(View* view) {
- helper_.ResetTargetViewIfEquals(view);
-}
-
-void DropTargetGtk::OnDragDataReceived(GdkDragContext* context,
- gint x,
- gint y,
- GtkSelectionData* data,
- guint info,
- guint time) {
- std::string target_name = GdkAtomToString(atom);
- if (data->type == GDK_TARGET_STRING || IsTextType(target_name)) {
- guchar* text_data = gtk_selection_data_get_text(data);
- string16 result;
- if (text_data) {
- char* as_char = reinterpret_cast<char*>(text_data);
- UTF8ToUTF16(as_char, strlen(as_char), &result);
- g_free(text_data);
- }
- data_provider().SetString(UTF16ToWideHack(result));
- } else if (requested_custom_formats_.find(data->type) !=
- requested_custom_formats_.end()) {
- Pickle result;
- if (data->length > 0)
- result = Pickle(reinterpret_cast<char*>(data->data), data->length);
- data_provider().SetPickledData(data->type, result);
- } else if (data->type == GtkDndUtil::GetAtomForTarget(
- GtkDndUtil::CHROME_NAMED_URL)) {
- GURL url;
- string16 title;
- GtkDndUtil::ExtractNamedURL(data, &url, &title);
- data_provider().SetURL(url, UTF16ToWideHack(title));
- } else if (data->type == GtkDndUtil::GetAtomForTarget(
- GtkDndUtil::TEXT_URI_LIST)) {
- std::vector<GURL> urls;
- GtkDndUtil::ExtractURIList(data, &urls);
- if (urls.size() == 1) {
- data_provider().SetURL(urls[0], std::wstring());
- } else {
- // Consumers of OSExchangeData will see this as an invalid URL. That is,
- // when GetURL is invoked on the OSExchangeData this triggers false to
- // be returned.
- data_provider().SetURL(GURL(), std::wstring());
- }
- } else {
- NOTIMPLEMENTED(); // Need to support FILE_NAME, FILE_CONTENTS, HTML.
- }
-
- if (!data_->HasAllFormats(requested_formats_, requested_custom_formats_))
- return; // Waiting on more data.
-
- int drag_operation = DragDropTypes::GdkDragActionToDragOperation(
- context->actions);
- gfx::Point root_view_location(x, y);
- drag_operation = helper_.OnDragOver(*data_, root_view_location,
- drag_operation);
- GdkDragAction gdk_action = static_cast<GdkDragAction>(
- DragDropTypes::DragOperationToGdkDragAction(drag_operation));
- if (!received_drop_)
- gdk_drag_status(context, gdk_action, time);
-
- waiting_for_data_ = false;
-
- if (pending_view_ && received_drop_) {
- FinishDrop(context, x, y, time);
- // WARNING: we've been deleted.
- return;
- }
-}
-
-gboolean DropTargetGtk::OnDragDrop(GdkDragContext* context,
- gint x,
- gint y,
- guint time) {
- received_drop_ = true;
- OnDragMotion(context, x, y, time);
- if (!pending_view_) {
- // User isn't over a view, no drop can occur.
- static_cast<WidgetGtk*>(
- helper_.root_view()->GetWidget())->ResetDropTarget();
- // WARNING: we've been deleted.
- return FALSE;
- }
-
- if (!waiting_for_data_) {
- // We've got all the data now.
- FinishDrop(context, x, y, time);
- // WARNING: we've been deleted.
- return TRUE;
- }
- // We're waiting on data.
- return TRUE;
-}
-
-void DropTargetGtk::OnDragLeave(GdkDragContext* context, guint time) {
- helper_.OnDragExit();
-}
-
-gboolean DropTargetGtk::OnDragMotion(GdkDragContext* context,
- gint x,
- gint y,
- guint time) {
- waiting_for_data_ = false;
- gfx::Point root_view_location(x, y);
- pending_view_ =
- helper_.CalculateTargetView(root_view_location, *data_, false);
- if (pending_view_ &&
- (received_drop_ || (pending_view_ != helper_.target_view() &&
- pending_view_->AreDropTypesRequired()))) {
- // The target requires drop types before it can answer CanDrop,
- // ask for the data now.
- int formats = 0;
- std::set<GdkAtom> custom_formats;
- pending_view_->GetDropFormats(&formats, &custom_formats);
- IntersectFormats(data_provider().known_formats(),
- data_provider().known_custom_formats(),
- &formats, &custom_formats);
- if (!data_provider().HasDataForAllFormats(formats, custom_formats)) {
- if (!received_drop_)
- helper_.OnDragExit();
-
- // The target needs data for all the types before it can test if the
- // drop is valid, but we don't have all the data. Request the data
- // now. When we get back the data we'll update the target.
- RequestFormats(context, formats, custom_formats, time);
-
- waiting_for_data_ = true;
-
- return TRUE;
- }
- }
-
- int drag_operation = DragDropTypes::GdkDragActionToDragOperation(
- context->actions);
- drag_operation = helper_.OnDragOver(*data_, root_view_location,
- drag_operation);
- if (!received_drop_) {
- GdkDragAction gdk_action =
- static_cast<GdkDragAction>(
- DragDropTypes::DragOperationToGdkDragAction(drag_operation));
- gdk_drag_status(context, gdk_action, time);
- }
- return TRUE;
-}
-
-void DropTargetGtk::FinishDrop(GdkDragContext* context,
- gint x, gint y, guint time) {
- gfx::Point root_view_location(x, y);
- int drag_operation = DragDropTypes::GdkDragActionToDragOperation(
- context->actions);
- drag_operation = helper_.OnDrop(*data_, root_view_location,
- drag_operation);
- GdkDragAction gdk_action =
- static_cast<GdkDragAction>(
- DragDropTypes::DragOperationToGdkDragAction(drag_operation));
- gtk_drag_finish(context, gdk_action != 0, (gdk_action & GDK_ACTION_MOVE),
- time);
-
- static_cast<WidgetGtk*>(helper_.root_view()->GetWidget())->ResetDropTarget();
- // WARNING: we've been deleted.
-}
-
-void DropTargetGtk::IntersectFormats(int f1, const std::set<GdkAtom>& cf1,
- int* f2, std::set<GdkAtom>* cf2) {
- *f2 = (*f2 & f1);
- std::set<GdkAtom> cf;
- std::set_intersection(
- cf1.begin(), cf1.end(), cf2->begin(), cf2->end(),
- std::insert_iterator<std::set<GdkAtom> >(cf, cf.begin()));
- cf.swap(*cf2);
-}
-
-void DropTargetGtk::RequestFormats(GdkDragContext* context,
- int formats,
- const std::set<GdkAtom>& custom_formats,
- guint time) {
- GtkWidget* widget =
- static_cast<WidgetGtk*>(helper_.root_view()->GetWidget())->
- window_contents();
-
- const std::set<GdkAtom>& known_formats =
- data_provider().known_custom_formats();
- if ((formats & OSExchangeData::STRING) != 0 &&
- (requested_formats_ & OSExchangeData::STRING) == 0) {
- requested_formats_ |= OSExchangeData::STRING;
- if (known_formats.count(GDK_TARGET_STRING)) {
- gtk_drag_get_data(widget, context, GDK_TARGET_STRING, time);
- } else if (known_formats.count(gdk_atom_intern("text/plain", false))) {
- gtk_drag_get_data(widget, context, gdk_atom_intern("text/plain", false),
- time);
- } else if (known_formats.count(gdk_atom_intern("TEXT", false))) {
- gtk_drag_get_data(widget, context, gdk_atom_intern("TEXT", false),
- time);
- } else if (known_formats.count(gdk_atom_intern("STRING", false))) {
- gtk_drag_get_data(widget, context, gdk_atom_intern("STRING", false),
- time);
- } else if (known_formats.count(gdk_atom_intern("UTF8_STRING", false))) {
- gtk_drag_get_data(widget, context,
- gdk_atom_intern("UTF8_STRING", false), time);
- }
- }
- if ((formats & OSExchangeData::URL) != 0 &&
- (requested_formats_ & OSExchangeData::URL) == 0) {
- requested_formats_ |= OSExchangeData::URL;
- if (known_formats.count(
- GtkDndUtil::GetAtomForTarget(GtkDndUtil::CHROME_NAMED_URL))) {
- gtk_drag_get_data(widget, context,
- GtkDndUtil::GetAtomForTarget(
- GtkDndUtil::CHROME_NAMED_URL), time);
- } else if (known_formats.count(
- GtkDndUtil::GetAtomForTarget(GtkDndUtil::TEXT_URI_LIST))) {
- gtk_drag_get_data(widget, context,
- GtkDndUtil::GetAtomForTarget(
- GtkDndUtil::TEXT_URI_LIST), time);
- }
- }
- if ((formats & OSExchangeData::FILE_CONTENTS) != 0 &&
- (requested_formats_ & OSExchangeData::FILE_CONTENTS) == 0) {
- requested_formats_ |= OSExchangeData::FILE_CONTENTS;
- NOTIMPLEMENTED();
- }
- if ((formats & OSExchangeData::FILE_NAME != 0) &&
- (requested_formats_ & OSExchangeData::FILE_NAME) == 0) {
- requested_formats_ |= OSExchangeData::FILE_NAME;
- NOTIMPLEMENTED();
- }
- if ((formats & OSExchangeData::HTML) != 0 &&
- (requested_formats_ & OSExchangeData::HTML) == 0) {
- requested_formats_ |= OSExchangeData::HTML;
- NOTIMPLEMENTED();
- }
- for (std::set<GdkAtom>::const_iterator i = custom_formats.begin();
- i != custom_formats.end(); ++i) {
- if (requested_custom_formats_.find(*i) ==
- requested_custom_formats_.end()) {
- requested_custom_formats_.insert(*i);
- gtk_drag_get_data(widget, context, *i, time);
- }
- }
-}
-
-OSExchangeDataProviderGtk& DropTargetGtk::data_provider() const {
- return static_cast<OSExchangeDataProviderGtk&>(data_->provider());
-}
-
-} // namespace views
diff --git a/views/widget/drop_target_gtk.h b/views/widget/drop_target_gtk.h
deleted file mode 100644
index b4a5c56..0000000
--- a/views/widget/drop_target_gtk.h
+++ /dev/null
@@ -1,113 +0,0 @@
-// Copyright (c) 2009 The Chromium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-#ifndef VIEWS_WIDGET_DROP_TARGET_GTK_H_
-#define VIEWS_WIDGET_DROP_TARGET_GTK_H_
-
-#include <gtk/gtk.h>
-#include <set>
-
-#include "app/os_exchange_data.h"
-#include "base/scoped_ptr.h"
-#include "views/widget/drop_helper.h"
-
-class OSExchangeDataProviderGtk;
-
-namespace views {
-
-class RootView;
-class View;
-
-// DropTarget implementation for Gtk.
-//
-// The data for a drop is not immediately available on X. As such we lazily
-// ask for data as necessary. Some Views require data before they can determine
-// if the drop is going to be allowed. When such a View is encountered the
-// relevant data is requested from the drag source. When the data is available
-// the target is notified. Similarly if the drop completes and the data has
-// not yet been fetched, it is fetched and the target then notified.
-//
-// When a drop finishes this class calls back to the containing WidgetGtk
-// which results in deleting the DropTargetGtk.
-class DropTargetGtk {
- public:
- explicit DropTargetGtk(RootView* root_view,
- GdkDragContext* context);
- ~DropTargetGtk();
-
- // If a drag and drop is underway and |view| is the current drop target, the
- // drop target is set to null.
- // This is invoked when a View is removed from the RootView to make sure
- // we don't target a view that was removed during dnd.
- void ResetTargetViewIfEquals(View* view);
-
- // Drop methods from Gtk. These are forwarded from the containing WidgetGtk.
- void OnDragDataReceived(GdkDragContext* context,
- gint x,
- gint y,
- GtkSelectionData* data,
- guint info,
- guint time);
- gboolean OnDragDrop(GdkDragContext* context,
- gint x,
- gint y,
- guint time);
- void OnDragLeave(GdkDragContext* context, guint time);
- gboolean OnDragMotion(GdkDragContext* context,
- gint x,
- gint y,
- guint time);
-
- private:
- // Invoked when the drop finishes AND all the data is available.
- void FinishDrop(GdkDragContext* context, gint x, gint y, guint time);
-
- // Returns in |f2| and |cf2| the intersection of |f1| |f2| and
- // |cf1|, |cf2|.
- void IntersectFormats(int f1, const std::set<GdkAtom>& cf1,
- int* f2, std::set<GdkAtom>* cf2);
-
- // Requests the formats in |formats| and the custom formats in
- // |custom_formats|.
- void RequestFormats(GdkDragContext* context,
- int formats,
- const std::set<GdkAtom>& custom_formats,
- guint time);
-
- // Reutrns the Provider of the OSExchangeData we created.
- OSExchangeDataProviderGtk& data_provider() const;
-
- // Manages sending the appropriate drop methods to the view the drop is over.
- DropHelper helper_;
-
- // The formats we've requested from the drag source.
- //
- // NOTE: these formats are the intersection of the formats requested by the
- // drop target and the formats provided by the source.
- int requested_formats_;
- std::set<GdkAtom> requested_custom_formats_;
-
- // The data.
- scoped_ptr<OSExchangeData> data_;
-
- // Are we waiting for data from the source before we can notify the view?
- // This is set in two distinct ways: when the view requires the data before
- // it can answer Can Drop (that is, AreDropTypesRequired returns true) and
- // when the user dropped the data but we didn't get it all yet.
- bool waiting_for_data_;
-
- // Has OnDragDrop been invoked?
- bool received_drop_;
-
- // The view under the mouse. This is not necessarily the same as
- // helper_.target_view(). The two differ if the view under the mouse requires
- // the data.
- View* pending_view_;
-
- DISALLOW_COPY_AND_ASSIGN(DropTargetGtk);
-};
-
-} // namespace views
-
-#endif // VIEWS_WIDGET_DROP_TARGET_GTK_H_
diff --git a/views/widget/widget_gtk.cc b/views/widget/widget_gtk.cc
index d75ccf1..6534cca 100644
--- a/views/widget/widget_gtk.cc
+++ b/views/widget/widget_gtk.cc
@@ -7,44 +7,12 @@
#include "app/gfx/path.h"
#include "base/compiler_specific.h"
#include "views/widget/default_theme_provider.h"
-#include "views/widget/drop_target_gtk.h"
#include "views/widget/root_view.h"
#include "views/widget/tooltip_manager_gtk.h"
#include "views/window/window_gtk.h"
namespace views {
-// During drag and drop GTK sends a drag-leave during a drop. This means we
-// have no way to tell the difference between a normal drag leave and a drop.
-// To work around that we listen for DROP_START, then ignore the subsequent
-// drag-leave that GTK generates.
-class WidgetGtk::DropObserver : public MessageLoopForUI::Observer {
- public:
- DropObserver() { }
-
- virtual void WillProcessEvent(GdkEvent* event) {
- if (event->type == GDK_DROP_START) {
- WidgetGtk* widget = GetWidgetGtkForEvent(event);
- if (widget)
- widget->ignore_drag_leave_ = true;
- }
- }
-
- virtual void DidProcessEvent(GdkEvent* event) {
- }
-
- private:
- WidgetGtk* GetWidgetGtkForEvent(GdkEvent* event) {
- GtkWidget* gtk_widget = gtk_get_event_widget(event);
- if (!gtk_widget)
- return NULL;
-
- return WidgetGtk::GetViewForNative(gtk_widget);
- }
-
- DISALLOW_COPY_AND_ASSIGN(DropObserver);
-};
-
// Returns the position of a widget on screen.
static void GetWidgetPositionOnScreen(GtkWidget* widget, int* x, int *y) {
while (widget) {
@@ -101,16 +69,7 @@ WidgetGtk::WidgetGtk(Type type)
ALLOW_THIS_IN_INITIALIZER_LIST(close_widget_factory_(this)),
delete_on_destroy_(true),
transparent_(false),
- ignore_drag_leave_(false),
opacity_(255) {
- static bool installed_message_loop_observer = false;
- if (!installed_message_loop_observer) {
- installed_message_loop_observer = true;
- MessageLoopForUI* loop = MessageLoopForUI::current();
- if (loop)
- loop->AddObserver(new DropObserver());
- }
-
if (type_ != TYPE_CHILD)
focus_manager_.reset(new FocusManager(this));
}
@@ -245,17 +204,16 @@ void WidgetGtk::Init(GtkWidget* parent,
G_CALLBACK(CallWindowPaint), this);
}
- // Drag and drop.
- gtk_drag_dest_set(window_contents_, static_cast<GtkDestDefaults>(0),
- NULL, 0, GDK_ACTION_COPY);
- g_signal_connect(G_OBJECT(window_contents_), "drag_motion",
- G_CALLBACK(CallDragMotion), this);
- g_signal_connect(G_OBJECT(window_contents_), "drag_data_received",
- G_CALLBACK(CallDragDataReceived), this);
- g_signal_connect(G_OBJECT(window_contents_), "drag_drop",
- G_CALLBACK(CallDragDrop), this);
- g_signal_connect(G_OBJECT(window_contents_), "drag_leave",
- G_CALLBACK(CallDragLeave), this);
+ // TODO(erg): Ignore these signals for now because they're such a drag.
+ //
+ // g_signal_connect(G_OBJECT(widget_), "drag_motion",
+ // G_CALLBACK(drag_motion_event_cb), NULL);
+ // g_signal_connect(G_OBJECT(widget_), "drag_leave",
+ // G_CALLBACK(drag_leave_event_cb), NULL);
+ // g_signal_connect(G_OBJECT(widget_), "drag_drop",
+ // G_CALLBACK(drag_drop_event_cb), NULL);
+ // g_signal_connect(G_OBJECT(widget_), "drag_data_received",
+ // G_CALLBACK(drag_data_received_event_cb), NULL);
tooltip_manager_.reset(new TooltipManagerGtk(this));
@@ -431,8 +389,8 @@ FocusManager* WidgetGtk::GetFocusManager() {
void WidgetGtk::ViewHierarchyChanged(bool is_add, View *parent,
View *child) {
- if (drop_target_.get())
- drop_target_->ResetTargetViewIfEquals(child);
+ // Needs dnd support (see WidgetWin::ViewHierarchyChanged).
+ NOTIMPLEMENTED();
}
////////////////////////////////////////////////////////////////////////////////
@@ -546,47 +504,6 @@ void WidgetGtk::OnPaint(GtkWidget* widget, GdkEventExpose* event) {
root_view_->OnPaint(event);
}
-void WidgetGtk::OnDragDataReceived(GdkDragContext* context,
- gint x,
- gint y,
- GtkSelectionData* data,
- guint info,
- guint time) {
- if (drop_target_.get())
- drop_target_->OnDragDataReceived(context, x, y, data, info, time);
-}
-
-gboolean WidgetGtk::OnDragDrop(GdkDragContext* context,
- gint x,
- gint y,
- guint time) {
- if (drop_target_.get()) {
- return drop_target_->OnDragDrop(context, x, y, time);
- }
- return FALSE;
-}
-
-void WidgetGtk::OnDragLeave(GdkDragContext* context,
- guint time) {
- if (ignore_drag_leave_) {
- ignore_drag_leave_ = false;
- return;
- }
- if (drop_target_.get()) {
- drop_target_->OnDragLeave(context, time);
- drop_target_.reset(NULL);
- }
-}
-
-gboolean WidgetGtk::OnDragMotion(GdkDragContext* context,
- gint x,
- gint y,
- guint time) {
- if (!drop_target_.get())
- drop_target_.reset(new DropTargetGtk(GetRootView(), context));
- return drop_target_->OnDragMotion(context, x, y, time);
-}
-
gboolean WidgetGtk::OnEnterNotify(GtkWidget* widget, GdkEventCrossing* event) {
return false;
}
@@ -706,11 +623,6 @@ WidgetGtk* WidgetGtk::GetViewForNative(GtkWidget* widget) {
return static_cast<WidgetGtk*>(user_data);
}
-void WidgetGtk::ResetDropTarget() {
- ignore_drag_leave_ = false;
- drop_target_.reset(NULL);
-}
-
// static
void WidgetGtk::SetViewForNative(GtkWidget* widget, WidgetGtk* view) {
g_object_set_data(G_OBJECT(widget), "chrome-views", view);
@@ -752,46 +664,6 @@ gboolean WidgetGtk::CallWindowPaint(GtkWidget* widget,
return false; // False indicates other widgets should get the event as well.
}
-// static
-void WidgetGtk::CallDragDataReceived(GtkWidget* widget,
- GdkDragContext* context,
- gint x,
- gint y,
- GtkSelectionData* data,
- guint info,
- guint time,
- WidgetGtk* host) {
- return host->OnDragDataReceived(context, x, y, data, info, time);
-}
-
-// static
-gboolean WidgetGtk::CallDragDrop(GtkWidget* widget,
- GdkDragContext* context,
- gint x,
- gint y,
- guint time,
- WidgetGtk* host) {
- return host->OnDragDrop(context, x, y, time);
-}
-
-// static
-void WidgetGtk::CallDragLeave(GtkWidget* widget,
- GdkDragContext* context,
- guint time,
- WidgetGtk* host) {
- host->OnDragLeave(context, time);
-}
-
-// static
-gboolean WidgetGtk::CallDragMotion(GtkWidget* widget,
- GdkDragContext* context,
- gint x,
- gint y,
- guint time,
- WidgetGtk* host) {
- return host->OnDragMotion(context, x, y, time);
-}
-
gboolean WidgetGtk::CallEnterNotify(GtkWidget* widget, GdkEventCrossing* event) {
WidgetGtk* widget_gtk = GetViewForNative(widget);
if (!widget_gtk)
diff --git a/views/widget/widget_gtk.h b/views/widget/widget_gtk.h
index f8bc57f..f8c6a20 100644
--- a/views/widget/widget_gtk.h
+++ b/views/widget/widget_gtk.h
@@ -17,7 +17,6 @@ class Rect;
namespace views {
class DefaultThemeProvider;
-class DropTargetGtk;
class TooltipManagerGtk;
class View;
class WindowGtk;
@@ -107,29 +106,9 @@ class WidgetGtk : public Widget, public MessageLoopForUI::Observer {
// Retrieves the WindowGtk associated with |widget|.
static WindowGtk* GetWindowForNative(GtkWidget* widget);
- // Sets the drop target to NULL. This is invoked by DropTargetGTK when the
- // drop is done.
- void ResetDropTarget();
-
protected:
virtual void OnSizeAllocate(GtkWidget* widget, GtkAllocation* allocation);
virtual void OnPaint(GtkWidget* widget, GdkEventExpose* event);
- virtual void OnDragDataReceived(GdkDragContext* context,
- gint x,
- gint y,
- GtkSelectionData* data,
- guint info,
- guint time);
- virtual gboolean OnDragDrop(GdkDragContext* context,
- gint x,
- gint y,
- guint time);
- virtual void OnDragLeave(GdkDragContext* context,
- guint time);
- virtual gboolean OnDragMotion(GdkDragContext* context,
- gint x,
- gint y,
- guint time);
virtual gboolean OnEnterNotify(GtkWidget* widget, GdkEventCrossing* event);
virtual gboolean OnLeaveNotify(GtkWidget* widget, GdkEventCrossing* event);
virtual gboolean OnMotionNotify(GtkWidget* widget, GdkEventMotion* event);
@@ -165,9 +144,6 @@ class WidgetGtk : public Widget, public MessageLoopForUI::Observer {
bool is_window_;
private:
- class DropObserver;
- friend class DropObserver;
-
virtual RootView* CreateRootView();
void OnWindowPaint(GtkWidget* widget, GdkEventExpose* event);
@@ -190,30 +166,6 @@ class WidgetGtk : public Widget, public MessageLoopForUI::Observer {
static gboolean CallWindowPaint(GtkWidget* widget,
GdkEventExpose* event,
WidgetGtk* widget_gtk);
- static void CallDragDataReceived(GtkWidget* widget,
- GdkDragContext* context,
- gint x,
- gint y,
- GtkSelectionData* data,
- guint info,
- guint time,
- WidgetGtk* host);
- static gboolean CallDragDrop(GtkWidget* widget,
- GdkDragContext* context,
- gint x,
- gint y,
- guint time,
- WidgetGtk* host);
- static void CallDragLeave(GtkWidget* widget,
- GdkDragContext* context,
- guint time,
- WidgetGtk* host);
- static gboolean CallDragMotion(GtkWidget* widget,
- GdkDragContext* context,
- gint x,
- gint y,
- guint time,
- WidgetGtk* host);
static gboolean CallEnterNotify(GtkWidget* widget, GdkEventCrossing* event);
static gboolean CallLeaveNotify(GtkWidget* widget, GdkEventCrossing* event);
static gboolean CallMotionNotify(GtkWidget* widget, GdkEventMotion* event);
@@ -264,8 +216,6 @@ class WidgetGtk : public Widget, public MessageLoopForUI::Observer {
// must be destroyed AFTER root_view_.
scoped_ptr<TooltipManagerGtk> tooltip_manager_;
- scoped_ptr<DropTargetGtk> drop_target_;
-
// The focus manager keeping track of focus for this Widget and any of its
// children. NULL for non top-level widgets.
// WARNING: RootView's destructor calls into the FocusManager. As such, this
@@ -303,9 +253,6 @@ class WidgetGtk : public Widget, public MessageLoopForUI::Observer {
scoped_ptr<DefaultThemeProvider> default_theme_provider_;
- // See note in DropObserver for details on this.
- bool ignore_drag_leave_;
-
unsigned char opacity_;
DISALLOW_COPY_AND_ASSIGN(WidgetGtk);