Commit 458b365c authored by ben@chromium.org's avatar ben@chromium.org

Rename WindowDragDropDelegate->DragDropDelegate

Move D&D client stuff into client namespace.
Provide some convenient getters/setters.

BUG=none
TEST=existing automation
TBR=sky
Review URL: http://codereview.chromium.org/8949010

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@114595 0039d316-1c4b-4281-b951-d872f2087c98
parent c6d03e02
...@@ -11,8 +11,8 @@ ...@@ -11,8 +11,8 @@
#include "content/browser/renderer_host/render_widget_host_view_aura.h" #include "content/browser/renderer_host/render_widget_host_view_aura.h"
#include "content/browser/tab_contents/tab_contents.h" #include "content/browser/tab_contents/tab_contents.h"
#include "content/browser/tab_contents/tab_contents_view.h" #include "content/browser/tab_contents/tab_contents_view.h"
#include "ui/aura/client/aura_constants.h"
#include "ui/aura/client/drag_drop_client.h" #include "ui/aura/client/drag_drop_client.h"
#include "ui/aura/client/drag_drop_delegate.h"
#include "ui/aura/root_window.h" #include "ui/aura/root_window.h"
#include "ui/aura/event.h" #include "ui/aura/event.h"
#include "ui/aura/window.h" #include "ui/aura/window.h"
...@@ -173,10 +173,7 @@ RenderWidgetHostView* NativeTabContentsViewAura::CreateRenderWidgetHostView( ...@@ -173,10 +173,7 @@ RenderWidgetHostView* NativeTabContentsViewAura::CreateRenderWidgetHostView(
view->Show(); view->Show();
// We listen to drag drop events in the newly created view's window. // We listen to drag drop events in the newly created view's window.
aura::Window* window = static_cast<aura::Window*>(view->GetNativeView()); aura::client::SetDragDropDelegate(view->GetNativeView(), this);
DCHECK(window);
window->SetProperty(aura::kDragDropDelegateKey,
static_cast<aura::WindowDragDropDelegate*>(this));
return view; return view;
} }
...@@ -194,10 +191,7 @@ void NativeTabContentsViewAura::StartDragging(const WebDropData& drop_data, ...@@ -194,10 +191,7 @@ void NativeTabContentsViewAura::StartDragging(const WebDropData& drop_data,
WebKit::WebDragOperationsMask ops, WebKit::WebDragOperationsMask ops,
const SkBitmap& image, const SkBitmap& image,
const gfx::Point& image_offset) { const gfx::Point& image_offset) {
aura::DragDropClient* client = static_cast<aura::DragDropClient*>( if (!aura::client::GetDragDropClient())
aura::RootWindow::GetInstance()->GetProperty(
aura::kRootWindowDragDropClientKey));
if (!client)
return; return;
ui::OSExchangeDataProviderAura* provider = new ui::OSExchangeDataProviderAura; ui::OSExchangeDataProviderAura* provider = new ui::OSExchangeDataProviderAura;
...@@ -212,7 +206,8 @@ void NativeTabContentsViewAura::StartDragging(const WebDropData& drop_data, ...@@ -212,7 +206,8 @@ void NativeTabContentsViewAura::StartDragging(const WebDropData& drop_data,
// updates while in the system DoDragDrop loop. // updates while in the system DoDragDrop loop.
bool old_state = MessageLoop::current()->NestableTasksAllowed(); bool old_state = MessageLoop::current()->NestableTasksAllowed();
MessageLoop::current()->SetNestableTasksAllowed(true); MessageLoop::current()->SetNestableTasksAllowed(true);
int result_op = client->StartDragAndDrop(data, ConvertFromWeb(ops)); int result_op = aura::client::GetDragDropClient()->StartDragAndDrop(
data, ConvertFromWeb(ops));
MessageLoop::current()->SetNestableTasksAllowed(old_state); MessageLoop::current()->SetNestableTasksAllowed(old_state);
EndDrag(ConvertToWeb(result_op)); EndDrag(ConvertToWeb(result_op));
...@@ -220,19 +215,13 @@ void NativeTabContentsViewAura::StartDragging(const WebDropData& drop_data, ...@@ -220,19 +215,13 @@ void NativeTabContentsViewAura::StartDragging(const WebDropData& drop_data,
} }
void NativeTabContentsViewAura::CancelDrag() { void NativeTabContentsViewAura::CancelDrag() {
aura::DragDropClient* client = static_cast<aura::DragDropClient*>( if (aura::client::GetDragDropClient())
aura::RootWindow::GetInstance()->GetProperty( aura::client::GetDragDropClient()->DragCancel();
aura::kRootWindowDragDropClientKey));
if (client)
client->DragCancel();
} }
bool NativeTabContentsViewAura::IsDoingDrag() const { bool NativeTabContentsViewAura::IsDoingDrag() const {
aura::DragDropClient* client = static_cast<aura::DragDropClient*>( if (aura::client::GetDragDropClient())
aura::RootWindow::GetInstance()->GetProperty( return aura::client::GetDragDropClient()->IsDragDropInProgress();
aura::kRootWindowDragDropClientKey));
if (client)
return client->IsDragDropInProgress();
return false; return false;
} }
......
...@@ -31,11 +31,13 @@ ...@@ -31,11 +31,13 @@
'client/activation_delegate.h', 'client/activation_delegate.h',
'client/aura_constants.cc', 'client/aura_constants.cc',
'client/aura_constants.h', 'client/aura_constants.h',
'client/drag_drop_client.cc',
'client/drag_drop_client.h', 'client/drag_drop_client.h',
'client/stacking_client.cc', 'client/stacking_client.cc',
'client/stacking_client.h', 'client/stacking_client.h',
'client/tooltip_client.h', 'client/tooltip_client.h',
'client/window_drag_drop_delegate.h', 'client/drag_drop_delegate.cc',
'client/drag_drop_delegate.h',
'cursor.h', 'cursor.h',
'root_window_host.h', 'root_window_host.h',
'root_window_host_linux.cc', 'root_window_host_linux.cc',
......
// 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 "ui/aura/client/drag_drop_client.h"
#include "ui/aura/client/aura_constants.h"
#include "ui/aura/root_window.h"
namespace aura {
namespace client {
void SetDragDropClient(DragDropClient* client) {
RootWindow::GetInstance()->SetProperty(kRootWindowDragDropClientKey, client);
}
DragDropClient* GetDragDropClient() {
return reinterpret_cast<DragDropClient*>(
RootWindow::GetInstance()->GetProperty(kRootWindowDragDropClientKey));
}
} // namespace client
} // namespace aura
...@@ -14,8 +14,8 @@ class OSExchangeData; ...@@ -14,8 +14,8 @@ class OSExchangeData;
} }
namespace aura { namespace aura {
class Window; class Window;
namespace client {
// An interface implemented by an object that controls a drag and drop session. // An interface implemented by an object that controls a drag and drop session.
class AURA_EXPORT DragDropClient { class AURA_EXPORT DragDropClient {
...@@ -40,6 +40,10 @@ class AURA_EXPORT DragDropClient { ...@@ -40,6 +40,10 @@ class AURA_EXPORT DragDropClient {
virtual bool IsDragDropInProgress() = 0; virtual bool IsDragDropInProgress() = 0;
}; };
AURA_EXPORT void SetDragDropClient(DragDropClient* client);
AURA_EXPORT DragDropClient* GetDragDropClient();
} // namespace client
} // namespace aura } // namespace aura
#endif // UI_AURA_CLIENT_DRAG_DROP_CLIENT_H_ #endif // UI_AURA_CLIENT_DRAG_DROP_CLIENT_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 "ui/aura/client/drag_drop_delegate.h"
#include "ui/aura/client/aura_constants.h"
#include "ui/aura/window.h"
namespace aura {
namespace client {
void SetDragDropDelegate(Window* window, DragDropDelegate* delegate) {
window->SetProperty(kDragDropDelegateKey, delegate);
}
DragDropDelegate* GetDragDropDelegate(Window* window) {
return reinterpret_cast<DragDropDelegate*>(
window->GetProperty(kDragDropDelegateKey));
}
} // namespace client
} // namespace aura
\ No newline at end of file
...@@ -2,18 +2,19 @@ ...@@ -2,18 +2,19 @@
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
#ifndef UI_AURA_CLIENT_WINDOW_DRAG_DROP_DELEGATE_H_ #ifndef UI_AURA_CLIENT_DRAG_DROP_DELEGATE_H_
#define UI_AURA_CLIENT_WINDOW_DRAG_DROP_DELEGATE_H_ #define UI_AURA_CLIENT_DRAG_DROP_DELEGATE_H_
#pragma once #pragma once
#include "ui/aura/aura_export.h" #include "ui/aura/aura_export.h"
namespace aura { namespace aura {
class DropTargetEvent; class DropTargetEvent;
class Window;
namespace client {
// Delegate interface for drag and drop actions on aura::Window. // Delegate interface for drag and drop actions on aura::Window.
class AURA_EXPORT WindowDragDropDelegate { class AURA_EXPORT DragDropDelegate {
public: public:
// OnDragEntered is invoked when the mouse enters this window during a drag & // OnDragEntered is invoked when the mouse enters this window during a drag &
// drop session. This is immediately followed by an invocation of // drop session. This is immediately followed by an invocation of
...@@ -35,9 +36,14 @@ class AURA_EXPORT WindowDragDropDelegate { ...@@ -35,9 +36,14 @@ class AURA_EXPORT WindowDragDropDelegate {
virtual int OnPerformDrop(const DropTargetEvent& event) = 0; virtual int OnPerformDrop(const DropTargetEvent& event) = 0;
protected: protected:
virtual ~WindowDragDropDelegate() {} virtual ~DragDropDelegate() {}
}; };
AURA_EXPORT void SetDragDropDelegate(Window* window,
DragDropDelegate* delegate);
AURA_EXPORT DragDropDelegate* GetDragDropDelegate(Window* window);
} // namespace client
} // namespace aura } // namespace aura
#endif // UI_AURA_CLIENT_WINDOW_DRAG_DROP_DELEGATE_H_ #endif // UI_AURA_CLIENT_DRAG_DROP_DELEGATE_H_
...@@ -6,7 +6,7 @@ ...@@ -6,7 +6,7 @@
#include "base/message_loop.h" #include "base/message_loop.h"
#include "ui/aura/client/aura_constants.h" #include "ui/aura/client/aura_constants.h"
#include "ui/aura/client/window_drag_drop_delegate.h" #include "ui/aura/client/drag_drop_delegate.h"
#include "ui/aura/root_window.h" #include "ui/aura/root_window.h"
#include "ui/aura/window.h" #include "ui/aura/window.h"
#include "ui/aura_shell/drag_image_view.h" #include "ui/aura_shell/drag_image_view.h"
...@@ -23,17 +23,7 @@ namespace internal { ...@@ -23,17 +23,7 @@ namespace internal {
using aura::RootWindow; using aura::RootWindow;
namespace { namespace {
aura::WindowDragDropDelegate* GetDragDropDelegate(aura::Window* window) {
if (!window)
return NULL;
void* prop = window->GetProperty(aura::kDragDropDelegateKey);
if (!prop)
return NULL;
return static_cast<aura::WindowDragDropDelegate*>(prop);
}
const gfx::Point kDragDropWidgetOffset(0, 0); const gfx::Point kDragDropWidgetOffset(0, 0);
} }
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
...@@ -48,6 +38,7 @@ DragDropController::DragDropController() ...@@ -48,6 +38,7 @@ DragDropController::DragDropController()
drag_drop_in_progress_(false), drag_drop_in_progress_(false),
should_block_during_drag_drop_(true) { should_block_during_drag_drop_(true) {
Shell::GetInstance()->AddRootWindowEventFilter(this); Shell::GetInstance()->AddRootWindowEventFilter(this);
aura::client::SetDragDropClient(this);
} }
DragDropController::~DragDropController() { DragDropController::~DragDropController() {
...@@ -86,17 +77,19 @@ int DragDropController::StartDragAndDrop(const ui::OSExchangeData& data, ...@@ -86,17 +77,19 @@ int DragDropController::StartDragAndDrop(const ui::OSExchangeData& data,
void DragDropController::DragUpdate(aura::Window* target, void DragDropController::DragUpdate(aura::Window* target,
const aura::MouseEvent& event) { const aura::MouseEvent& event) {
aura::WindowDragDropDelegate* delegate = NULL; aura::client::DragDropDelegate* delegate = NULL;
if (target != dragged_window_) { if (target != dragged_window_) {
if ((delegate = GetDragDropDelegate(dragged_window_))) if (dragged_window_ &&
(delegate = aura::client::GetDragDropDelegate(dragged_window_))) {
delegate->OnDragExited(); delegate->OnDragExited();
}
dragged_window_ = target; dragged_window_ = target;
if ((delegate = GetDragDropDelegate(dragged_window_))) { if ((delegate = aura::client::GetDragDropDelegate(dragged_window_))) {
aura::DropTargetEvent e(*drag_data_, event.location(), drag_operation_); aura::DropTargetEvent e(*drag_data_, event.location(), drag_operation_);
delegate->OnDragEntered(e); delegate->OnDragEntered(e);
} }
} else { } else {
if ((delegate = GetDragDropDelegate(dragged_window_))) { if ((delegate = aura::client::GetDragDropDelegate(dragged_window_))) {
aura::DropTargetEvent e(*drag_data_, event.location(), drag_operation_); aura::DropTargetEvent e(*drag_data_, event.location(), drag_operation_);
int op = delegate->OnDragUpdated(e); int op = delegate->OnDragUpdated(e);
gfx::NativeCursor cursor = (op == ui::DragDropTypes::DRAG_NONE)? gfx::NativeCursor cursor = (op == ui::DragDropTypes::DRAG_NONE)?
...@@ -114,9 +107,9 @@ void DragDropController::DragUpdate(aura::Window* target, ...@@ -114,9 +107,9 @@ void DragDropController::DragUpdate(aura::Window* target,
void DragDropController::Drop(aura::Window* target, void DragDropController::Drop(aura::Window* target,
const aura::MouseEvent& event) { const aura::MouseEvent& event) {
aura::WindowDragDropDelegate* delegate = NULL; aura::client::DragDropDelegate* delegate = NULL;
DCHECK(target == dragged_window_); DCHECK(target == dragged_window_);
if ((delegate = GetDragDropDelegate(dragged_window_))) { if ((delegate = aura::client::GetDragDropDelegate(dragged_window_))) {
aura::DropTargetEvent e(*drag_data_, event.location(), drag_operation_); aura::DropTargetEvent e(*drag_data_, event.location(), drag_operation_);
drag_operation_ = delegate->OnPerformDrop(e); drag_operation_ = delegate->OnPerformDrop(e);
// TODO(varunjain): if drag_op is 0, do drag widget flying back animation // TODO(varunjain): if drag_op is 0, do drag widget flying back animation
......
...@@ -28,8 +28,9 @@ namespace internal { ...@@ -28,8 +28,9 @@ namespace internal {
class DragImageView; class DragImageView;
class AURA_SHELL_EXPORT DragDropController : public aura::DragDropClient, class AURA_SHELL_EXPORT DragDropController
public aura::EventFilter { : public aura::client::DragDropClient,
public aura::EventFilter {
public: public:
DragDropController(); DragDropController();
virtual ~DragDropController(); virtual ~DragDropController();
...@@ -38,7 +39,7 @@ class AURA_SHELL_EXPORT DragDropController : public aura::DragDropClient, ...@@ -38,7 +39,7 @@ class AURA_SHELL_EXPORT DragDropController : public aura::DragDropClient,
should_block_during_drag_drop_ = should_block_during_drag_drop; should_block_during_drag_drop_ = should_block_during_drag_drop;
} }
// Overridden from aura::DragDropClient: // Overridden from aura::client::DragDropClient:
virtual int StartDragAndDrop(const ui::OSExchangeData& data, virtual int StartDragAndDrop(const ui::OSExchangeData& data,
int operation) OVERRIDE; int operation) OVERRIDE;
virtual void DragUpdate(aura::Window* target, virtual void DragUpdate(aura::Window* target,
......
...@@ -172,27 +172,19 @@ void AddViewToWidgetAndResize(views::Widget* widget, views::View* view) { ...@@ -172,27 +172,19 @@ void AddViewToWidgetAndResize(views::Widget* widget, views::View* view) {
class DragDropControllerTest : public AuraShellTestBase { class DragDropControllerTest : public AuraShellTestBase {
public: public:
DragDropControllerTest() : AuraShellTestBase() { DragDropControllerTest() : AuraShellTestBase() {}
} virtual ~DragDropControllerTest() {}
virtual ~DragDropControllerTest() {
aura::RootWindow::GetInstance()->SetProperty(
aura::kRootWindowDragDropClientKey,
NULL);
}
void SetUp() OVERRIDE { void SetUp() OVERRIDE {
AuraShellTestBase::SetUp(); AuraShellTestBase::SetUp();
drag_drop_controller_ = new TestDragDropController; drag_drop_controller_.reset(new TestDragDropController);
drag_drop_controller_->set_should_block_during_drag_drop(false); drag_drop_controller_->set_should_block_during_drag_drop(false);
aura::RootWindow::GetInstance()->SetProperty( aura::client::SetDragDropClient(drag_drop_controller_.get());
aura::kRootWindowDragDropClientKey,
drag_drop_controller_);
} }
void TearDown() OVERRIDE { void TearDown() OVERRIDE {
delete drag_drop_controller_; aura::client::SetDragDropClient(NULL);
drag_drop_controller_ = NULL; drag_drop_controller_.reset();
AuraShellTestBase::TearDown(); AuraShellTestBase::TearDown();
} }
...@@ -201,7 +193,7 @@ class DragDropControllerTest : public AuraShellTestBase { ...@@ -201,7 +193,7 @@ class DragDropControllerTest : public AuraShellTestBase {
} }
protected: protected:
TestDragDropController* drag_drop_controller_; scoped_ptr<TestDragDropController> drag_drop_controller_;
private: private:
DISALLOW_COPY_AND_ASSIGN(DragDropControllerTest); DISALLOW_COPY_AND_ASSIGN(DragDropControllerTest);
......
...@@ -218,9 +218,6 @@ void Shell::Init() { ...@@ -218,9 +218,6 @@ void Shell::Init() {
// Initialize drag drop controller. // Initialize drag drop controller.
drag_drop_controller_.reset(new internal::DragDropController); drag_drop_controller_.reset(new internal::DragDropController);
aura::RootWindow::GetInstance()->SetProperty(
aura::kRootWindowDragDropClientKey,
static_cast<aura::DragDropClient*>(drag_drop_controller_.get()));
} }
void Shell::InitLayoutManagers(aura::RootWindow* root_window) { void Shell::InitLayoutManagers(aura::RootWindow* root_window) {
......
...@@ -184,8 +184,7 @@ void NativeWidgetAura::InitNativeWidget(const Widget::InitParams& params) { ...@@ -184,8 +184,7 @@ void NativeWidgetAura::InitNativeWidget(const Widget::InitParams& params) {
drop_helper_.reset(new DropHelper(GetWidget()->GetRootView())); drop_helper_.reset(new DropHelper(GetWidget()->GetRootView()));
if (params.type != Widget::InitParams::TYPE_TOOLTIP && if (params.type != Widget::InitParams::TYPE_TOOLTIP &&
params.type != Widget::InitParams::TYPE_POPUP) { params.type != Widget::InitParams::TYPE_POPUP) {
window_->SetProperty(aura::kDragDropDelegateKey, aura::client::SetDragDropDelegate(window_, this);
static_cast<aura::WindowDragDropDelegate*>(this));
} }
aura::ActivationDelegate::SetActivationDelegate(window_, this); aura::ActivationDelegate::SetActivationDelegate(window_, this);
...@@ -510,11 +509,8 @@ bool NativeWidgetAura::IsAccessibleWidget() const { ...@@ -510,11 +509,8 @@ bool NativeWidgetAura::IsAccessibleWidget() const {
void NativeWidgetAura::RunShellDrag(View* view, void NativeWidgetAura::RunShellDrag(View* view,
const ui::OSExchangeData& data, const ui::OSExchangeData& data,
int operation) { int operation) {
aura::DragDropClient* client = static_cast<aura::DragDropClient*>( if (aura::client::GetDragDropClient())
aura::RootWindow::GetInstance()->GetProperty( aura::client::GetDragDropClient()->StartDragAndDrop(data, operation);
aura::kRootWindowDragDropClientKey));
if (client)
client->StartDragAndDrop(data, operation);
} }
void NativeWidgetAura::SchedulePaintInRect(const gfx::Rect& rect) { void NativeWidgetAura::SchedulePaintInRect(const gfx::Rect& rect) {
...@@ -681,7 +677,6 @@ void NativeWidgetAura::OnPaint(gfx::Canvas* canvas) { ...@@ -681,7 +677,6 @@ void NativeWidgetAura::OnPaint(gfx::Canvas* canvas) {
} }
void NativeWidgetAura::OnWindowDestroying() { void NativeWidgetAura::OnWindowDestroying() {
window_->SetProperty(aura::kDragDropDelegateKey, NULL);
delegate_->OnNativeWidgetDestroying(); delegate_->OnNativeWidgetDestroying();
// If the aura::Window is destroyed, we can no longer show tooltips. // If the aura::Window is destroyed, we can no longer show tooltips.
......
...@@ -9,7 +9,7 @@ ...@@ -9,7 +9,7 @@
#include "base/memory/scoped_vector.h" #include "base/memory/scoped_vector.h"
#include "base/memory/weak_ptr.h" #include "base/memory/weak_ptr.h"
#include "ui/aura/client/activation_delegate.h" #include "ui/aura/client/activation_delegate.h"
#include "ui/aura/client/window_drag_drop_delegate.h" #include "ui/aura/client/drag_drop_delegate.h"
#include "ui/aura/window_delegate.h" #include "ui/aura/window_delegate.h"
#include "ui/base/events.h" #include "ui/base/events.h"
#include "ui/views/views_export.h" #include "ui/views/views_export.h"
...@@ -30,7 +30,7 @@ class TooltipManagerAura; ...@@ -30,7 +30,7 @@ class TooltipManagerAura;
class VIEWS_EXPORT NativeWidgetAura : public internal::NativeWidgetPrivate, class VIEWS_EXPORT NativeWidgetAura : public internal::NativeWidgetPrivate,
public aura::WindowDelegate, public aura::WindowDelegate,
public aura::ActivationDelegate, public aura::ActivationDelegate,
public aura::WindowDragDropDelegate { public aura::client::DragDropDelegate {
public: public:
explicit NativeWidgetAura(internal::NativeWidgetDelegate* delegate); explicit NativeWidgetAura(internal::NativeWidgetDelegate* delegate);
virtual ~NativeWidgetAura(); virtual ~NativeWidgetAura();
...@@ -145,7 +145,7 @@ class VIEWS_EXPORT NativeWidgetAura : public internal::NativeWidgetPrivate, ...@@ -145,7 +145,7 @@ class VIEWS_EXPORT NativeWidgetAura : public internal::NativeWidgetPrivate,
virtual void OnActivated() OVERRIDE; virtual void OnActivated() OVERRIDE;
virtual void OnLostActive() OVERRIDE; virtual void OnLostActive() OVERRIDE;
// Overridden from aura::WindowDragDropDelegate: // Overridden from aura::client::DragDropDelegate:
virtual void OnDragEntered(const aura::DropTargetEvent& event) OVERRIDE; virtual void OnDragEntered(const aura::DropTargetEvent& event) OVERRIDE;
virtual int OnDragUpdated(const aura::DropTargetEvent& event) OVERRIDE; virtual int OnDragUpdated(const aura::DropTargetEvent& event) OVERRIDE;
virtual void OnDragExited() OVERRIDE; virtual void OnDragExited() OVERRIDE;
......
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