Commit 7f90af2d authored by avi@chromium.org's avatar avi@chromium.org

Split Mac WebDropTarget into two, content and chrome.

BUG=95573
TEST=no visible change

Review URL: http://codereview.chromium.org/8430013

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@108113 0039d316-1c4b-4281-b951-d872f2087c98
parent 0750fade
......@@ -27,6 +27,7 @@ class RenderViewContextMenuMac;
@class SadTabController;
class SkBitmap;
class TabContentsViewMac;
class WebDragBookmarkHandlerMac;
@class WebDragSource;
@class WebDropTarget;
namespace gfx {
......@@ -38,6 +39,7 @@ class Point;
TabContentsViewMac* tabContentsView_; // WEAK; owns us
scoped_nsobject<WebDragSource> dragSource_;
scoped_nsobject<WebDropTarget> dropTarget_;
scoped_ptr<WebDragBookmarkHandlerMac> bookmarkHandler_;
}
// Expose this, since sometimes one needs both the NSView and the TabContents.
......
......@@ -11,6 +11,7 @@
#include "chrome/browser/browser_shutdown.h"
#import "chrome/browser/renderer_host/chrome_render_widget_host_view_mac_delegate.h"
#include "chrome/browser/tab_contents/render_view_context_menu_mac.h"
#include "chrome/browser/tab_contents/web_drag_bookmark_handler_mac.h"
#import "chrome/browser/ui/cocoa/focus_tracker.h"
#import "chrome/browser/ui/cocoa/tab_contents/sad_tab_controller.h"
#import "chrome/browser/ui/cocoa/tab_contents/web_drop_target.h"
......@@ -420,6 +421,9 @@ void TabContentsViewMac::Observe(int type,
tabContentsView_ = w;
dropTarget_.reset(
[[WebDropTarget alloc] initWithTabContents:[self tabContents]]);
bookmarkHandler_.reset(new WebDragBookmarkHandlerMac);
[dropTarget_ setDragDelegate:
static_cast<content::WebDragDestDelegate*>(bookmarkHandler_.get())];
[self registerDragTypes];
// TabContentsViewCocoa's ViewID may be changed to VIEW_ID_DEV_TOOLS_DOCKED
// by TabContentsController, so we can't just override -viewID method to
......
......@@ -25,6 +25,7 @@ void WebDragBookmarkHandlerGtk::DragInitialize(TabContents* contents) {
// the constructor. We cannot do that as the WebDragDestGtk object is
// created during the construction of the TabContents object. The
// TabContentsWrapper is created much later.
DCHECK(tab_ ? (tab_->tab_contents() == contents) : true);
if (!tab_)
tab_ = TabContentsWrapper::GetCurrentWrapperForContents(contents);
}
......@@ -54,17 +55,19 @@ void WebDragBookmarkHandlerGtk::OnReceiveProcessedData(const GURL& url,
}
void WebDragBookmarkHandlerGtk::OnDragOver() {
if (tab_ && tab_->bookmark_tab_helper()->GetBookmarkDragDelegate())
if (tab_ && tab_->bookmark_tab_helper()->GetBookmarkDragDelegate()) {
tab_->bookmark_tab_helper()->GetBookmarkDragDelegate()->OnDragOver(
bookmark_drag_data_);
}
}
void WebDragBookmarkHandlerGtk::OnDragEnter() {
// This is non-null if tab_contents_ is showing an ExtensionWebUI with
// support for (at the moment experimental) drag and drop extensions.
if (tab_ && tab_->bookmark_tab_helper()->GetBookmarkDragDelegate())
if (tab_ && tab_->bookmark_tab_helper()->GetBookmarkDragDelegate()) {
tab_->bookmark_tab_helper()->GetBookmarkDragDelegate()->OnDragEnter(
bookmark_drag_data_);
}
}
void WebDragBookmarkHandlerGtk::OnDrop() {
......@@ -85,7 +88,8 @@ void WebDragBookmarkHandlerGtk::OnDrop() {
}
void WebDragBookmarkHandlerGtk::OnDragLeave() {
if (tab_ && tab_->bookmark_tab_helper()->GetBookmarkDragDelegate())
if (tab_ && tab_->bookmark_tab_helper()->GetBookmarkDragDelegate()) {
tab_->bookmark_tab_helper()->GetBookmarkDragDelegate()->OnDragLeave(
bookmark_drag_data_);
}
}
......@@ -19,7 +19,7 @@ class WebDragBookmarkHandlerGtk : public content::WebDragDestDelegate {
WebDragBookmarkHandlerGtk();
virtual ~WebDragBookmarkHandlerGtk();
// Overridden from WebDragBookmarkDelegate:
// Overridden from content::WebDragDestDelegate:
virtual void DragInitialize(TabContents* contents) OVERRIDE;
virtual GdkAtom GetBookmarkTargetAtom() const OVERRIDE;
virtual void OnReceiveDataFromGtk(GtkSelectionData* data) OVERRIDE;
......@@ -39,6 +39,8 @@ class WebDragBookmarkHandlerGtk : public content::WebDragDestDelegate {
// The bookmark data for the current tab. This will be empty if there is not
// a native bookmark drag (or we haven't gotten the data from the source yet).
BookmarkNodeData bookmark_drag_data_;
DISALLOW_COPY_AND_ASSIGN(WebDragBookmarkHandlerGtk);
};
#endif // CHROME_BROWSER_TAB_CONTENTS_WEB_DRAG_BOOKMARK_HANDLER_GTK_H_
// Copyright (c) 2011 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 CHROME_BROWSER_TAB_CONTENTS_WEB_DRAG_BOOKMARK_HANDLER_MAC_H_
#define CHROME_BROWSER_TAB_CONTENTS_WEB_DRAG_BOOKMARK_HANDLER_MAC_H_
#pragma once
#include "base/compiler_specific.h"
#include "chrome/browser/bookmarks/bookmark_node_data.h"
#include "content/browser/tab_contents/web_drag_dest_delegate.h"
class TabContentsWrapper;
// Chrome needs to intercept content drag events so it can dispatch them to the
// bookmarks and extensions system.
class WebDragBookmarkHandlerMac : public content::WebDragDestDelegate {
public:
WebDragBookmarkHandlerMac();
virtual ~WebDragBookmarkHandlerMac();
// Overridden from content::WebDragDestDelegate:
virtual void DragInitialize(TabContents* contents) OVERRIDE;
virtual void OnDragOver() OVERRIDE;
virtual void OnDragEnter() OVERRIDE;
virtual void OnDrop() OVERRIDE;
virtual void OnDragLeave() OVERRIDE;
private:
// The TabContentsWrapper for |tab_contents_|.
// Weak reference; may be NULL if the contents aren't contained in a wrapper
// (e.g. WebUI dialogs).
TabContentsWrapper* tab_;
// The bookmark data for the current tab. This will be empty if there is not
// a native bookmark drag.
BookmarkNodeData bookmark_drag_data_;
DISALLOW_COPY_AND_ASSIGN(WebDragBookmarkHandlerMac);
};
#endif // CHROME_BROWSER_TAB_CONTENTS_WEB_DRAG_BOOKMARK_HANDLER_MAC_H_
// Copyright (c) 2011 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 "chrome/browser/tab_contents/web_drag_bookmark_handler_mac.h"
#include "chrome/browser/ui/browser.h"
#include "chrome/browser/ui/browser_window.h"
#include "chrome/browser/ui/bookmarks/bookmark_tab_helper.h"
#include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h"
WebDragBookmarkHandlerMac::WebDragBookmarkHandlerMac()
: tab_(NULL) {
}
WebDragBookmarkHandlerMac::~WebDragBookmarkHandlerMac() {}
void WebDragBookmarkHandlerMac::DragInitialize(TabContents* contents) {
DCHECK(tab_ ? (tab_->tab_contents() == contents) : true);
if (!tab_)
tab_ = TabContentsWrapper::GetCurrentWrapperForContents(contents);
bookmark_drag_data_.ReadFromDragClipboard();
}
void WebDragBookmarkHandlerMac::OnDragOver() {
if (tab_ && tab_->bookmark_tab_helper()->GetBookmarkDragDelegate()) {
tab_->bookmark_tab_helper()->GetBookmarkDragDelegate()->OnDragOver(
bookmark_drag_data_);
}
}
void WebDragBookmarkHandlerMac::OnDragEnter() {
if (tab_ && tab_->bookmark_tab_helper()->GetBookmarkDragDelegate()) {
tab_->bookmark_tab_helper()->GetBookmarkDragDelegate()->OnDragEnter(
bookmark_drag_data_);
}
}
void WebDragBookmarkHandlerMac::OnDrop() {
// This is non-null if tab_contents_ is showing an ExtensionWebUI with
// support for (at the moment experimental) drag and drop extensions.
if (tab_) {
if (tab_->bookmark_tab_helper()->GetBookmarkDragDelegate()) {
tab_->bookmark_tab_helper()->GetBookmarkDragDelegate()->OnDrop(
bookmark_drag_data_);
}
// Focus the target browser.
Browser* browser = Browser::GetBrowserForController(
&tab_->controller(), NULL);
if (browser)
browser->window()->Show();
}
}
void WebDragBookmarkHandlerMac::OnDragLeave() {
if (tab_ && tab_->bookmark_tab_helper()->GetBookmarkDragDelegate()) {
tab_->bookmark_tab_helper()->GetBookmarkDragDelegate()->OnDragLeave(
bookmark_drag_data_);
}
}
......@@ -9,9 +9,12 @@
class GURL;
class RenderViewHost;
class TabContents;
class TabContentsWrapper;
struct WebDropData;
namespace content {
class WebDragDestDelegate;
}
// A typedef for a RenderViewHost used for comparison purposes only.
typedef RenderViewHost* RenderViewHostIdentifier;
......@@ -24,10 +27,8 @@ typedef RenderViewHost* RenderViewHostIdentifier;
// Our associated TabContents. Weak reference.
TabContents* tabContents_;
// The TabContentsWrapper for |tab_contents_|.
// Weak reference; may be NULL if the contents aren't contained in a wrapper
// (e.g. WebUI dialogs).
TabContentsWrapper* tab_;
// Delegate; weak.
content::WebDragDestDelegate* delegate_;
// Updated asynchronously during a drag to tell us whether or not we should
// allow the drop.
......@@ -43,6 +44,8 @@ typedef RenderViewHost* RenderViewHostIdentifier;
// (if necessary).
- (id)initWithTabContents:(TabContents*)contents;
- (void)setDragDelegate:(content::WebDragDestDelegate*)delegate;
// Sets the current operation negotiated by the source and destination,
// which determines whether or not we should allow the drop. Takes effect the
// next time |-draggingUpdated:| is called.
......
......@@ -5,13 +5,9 @@
#import "chrome/browser/ui/cocoa/tab_contents/web_drop_target.h"
#include "base/sys_string_conversions.h"
#include "chrome/browser/bookmarks/bookmark_node_data.h"
#include "chrome/browser/ui/bookmarks/bookmark_tab_helper.h"
#include "chrome/browser/ui/browser.h"
#include "chrome/browser/ui/browser_window.h"
#include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h"
#include "content/browser/renderer_host/render_view_host.h"
#include "content/browser/tab_contents/tab_contents.h"
#include "content/browser/tab_contents/web_drag_dest_delegate.h"
#import "third_party/mozilla/NSPasteboard+Utils.h"
#import "ui/base/dragdrop/cocoa_dnd_util.h"
#include "webkit/glue/webdropdata.h"
......@@ -31,6 +27,10 @@ using WebKit::WebDragOperationsMask;
return self;
}
- (void)setDragDelegate:(content::WebDragDestDelegate*)delegate {
delegate_ = delegate;
}
// Call to set whether or not we should allow the drop. Takes effect the
// next time |-draggingUpdated:| is called.
- (void)setCurrentOperation: (NSDragOperation)operation {
......@@ -84,15 +84,10 @@ using WebKit::WebDragOperationsMask;
return NSDragOperationNone;
}
if (!tab_)
tab_ = TabContentsWrapper::GetCurrentWrapperForContents(tabContents_);
// If the tab is showing the bookmark manager, send BookmarkDrag events
BookmarkTabHelper::BookmarkDrag* dragDelegate =
tab_ ? tab_->bookmark_tab_helper()->GetBookmarkDragDelegate() : NULL;
BookmarkNodeData dragData;
if(dragDelegate && dragData.ReadFromDragClipboard())
dragDelegate->OnDragEnter(dragData);
if (delegate_) {
delegate_->DragInitialize(tabContents_);
delegate_->OnDragEnter();
}
// Fill out a WebDropData from pasteboard.
WebDropData data;
......@@ -122,6 +117,9 @@ using WebKit::WebDragOperationsMask;
// Nothing to do in the interstitial case.
if (delegate_)
delegate_->OnDragLeave();
tabContents_->render_view_host()->DragTargetDragLeave();
}
......@@ -148,12 +146,9 @@ using WebKit::WebDragOperationsMask;
gfx::Point(screenPoint.x, screenPoint.y),
static_cast<WebDragOperationsMask>(mask));
// If the tab is showing the bookmark manager, send BookmarkDrag events
BookmarkTabHelper::BookmarkDrag* dragDelegate =
tab_ ? tab_->bookmark_tab_helper()->GetBookmarkDragDelegate() : NULL;
BookmarkNodeData dragData;
if(dragDelegate && dragData.ReadFromDragClipboard())
dragDelegate->OnDragOver(dragData);
if (delegate_)
delegate_->OnDragOver();
return current_operation_;
}
......@@ -175,12 +170,8 @@ using WebKit::WebDragOperationsMask;
return NO;
}
// If the tab is showing the bookmark manager, send BookmarkDrag events
BookmarkTabHelper::BookmarkDrag* dragDelegate =
tab_ ? tab_->bookmark_tab_helper()->GetBookmarkDragDelegate() : NULL;
BookmarkNodeData dragData;
if(dragDelegate && dragData.ReadFromDragClipboard())
dragDelegate->OnDrop(dragData);
if (delegate_)
delegate_->OnDrop();
currentRVH_ = NULL;
......@@ -193,12 +184,6 @@ using WebKit::WebDragOperationsMask;
gfx::Point(viewPoint.x, viewPoint.y),
gfx::Point(screenPoint.x, screenPoint.y));
// Focus the target browser.
Browser* browser = Browser::GetBrowserForController(
&tabContents_->controller(), NULL);
if (browser)
browser->window()->Show();
return YES;
}
......
......@@ -2338,6 +2338,8 @@
'browser/tab_contents/spelling_menu_observer.h',
'browser/tab_contents/web_drag_bookmark_handler_gtk.cc',
'browser/tab_contents/web_drag_bookmark_handler_gtk.h',
'browser/tab_contents/web_drag_bookmark_handler_mac.h',
'browser/tab_contents/web_drag_bookmark_handler_mac.mm',
'browser/tab_contents/web_drag_source_win.cc',
'browser/tab_contents/web_drag_source_win.h',
'browser/tab_contents/web_drag_utils_win.cc',
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment