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