Remove RootWindow reference from DragDropTracker. RootWindow reference in
DragDropTracker seems unnecessary. After this change, the capture_window will be parented to the currently active RootWindow which seems fine. BUG=none Review URL: https://chromiumcodereview.appspot.com/11031026 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@160457 0039d316-1c4b-4281-b951-d872f2087c98
This commit is contained in:
@ -62,7 +62,7 @@ int DragDropController::StartDragAndDrop(const ui::OSExchangeData& data,
|
|||||||
int operation) {
|
int operation) {
|
||||||
DCHECK(!IsDragDropInProgress());
|
DCHECK(!IsDragDropInProgress());
|
||||||
|
|
||||||
drag_drop_tracker_.reset(new DragDropTracker(root_window));
|
drag_drop_tracker_.reset(new DragDropTracker);
|
||||||
|
|
||||||
drag_data_ = &data;
|
drag_data_ = &data;
|
||||||
drag_operation_ = operation;
|
drag_operation_ = operation;
|
||||||
|
@ -14,14 +14,11 @@
|
|||||||
namespace {
|
namespace {
|
||||||
|
|
||||||
// Creates a window for capturing drag events.
|
// Creates a window for capturing drag events.
|
||||||
aura::Window* CreateCaptureWindow(aura::RootWindow* root_window) {
|
aura::Window* CreateCaptureWindow() {
|
||||||
aura::Window* window = new aura::Window(NULL);
|
aura::Window* window = new aura::Window(NULL);
|
||||||
window->SetType(aura::client::WINDOW_TYPE_NORMAL);
|
window->SetType(aura::client::WINDOW_TYPE_NORMAL);
|
||||||
window->Init(ui::LAYER_NOT_DRAWN);
|
window->Init(ui::LAYER_NOT_DRAWN);
|
||||||
window->SetParent(NULL);
|
window->SetParent(NULL);
|
||||||
window->SetBoundsInScreen(gfx::Rect(root_window->GetBoundsInScreen().origin(),
|
|
||||||
gfx::Size()),
|
|
||||||
gfx::Screen::GetDisplayNearestWindow(root_window));
|
|
||||||
window->Show();
|
window->Show();
|
||||||
return window;
|
return window;
|
||||||
}
|
}
|
||||||
@ -31,8 +28,8 @@ aura::Window* CreateCaptureWindow(aura::RootWindow* root_window) {
|
|||||||
namespace ash {
|
namespace ash {
|
||||||
namespace internal {
|
namespace internal {
|
||||||
|
|
||||||
DragDropTracker::DragDropTracker(aura::RootWindow* root_window)
|
DragDropTracker::DragDropTracker()
|
||||||
: capture_window_(CreateCaptureWindow(root_window)) {
|
: capture_window_(CreateCaptureWindow()) {
|
||||||
capture_window_->SetCapture();
|
capture_window_->SetCapture();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -11,7 +11,6 @@
|
|||||||
#include "ui/base/events/event.h"
|
#include "ui/base/events/event.h"
|
||||||
|
|
||||||
namespace aura {
|
namespace aura {
|
||||||
class RootWindow;
|
|
||||||
class Window;
|
class Window;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -25,15 +24,15 @@ namespace internal {
|
|||||||
// is supported for now.
|
// is supported for now.
|
||||||
class ASH_EXPORT DragDropTracker {
|
class ASH_EXPORT DragDropTracker {
|
||||||
public:
|
public:
|
||||||
explicit DragDropTracker(aura::RootWindow* root_window);
|
DragDropTracker();
|
||||||
~DragDropTracker();
|
~DragDropTracker();
|
||||||
|
|
||||||
// Gets the target located at |event| in the coordinates of the root window
|
// Gets the target located at |event| in the coordinates of the active root
|
||||||
// given to the constructor.
|
// window.
|
||||||
aura::Window* GetTarget(const ui::LocatedEvent& event);
|
aura::Window* GetTarget(const ui::LocatedEvent& event);
|
||||||
|
|
||||||
// Converts the locations of |event| in the coordinates of the root window
|
// Converts the locations of |event| in the coordinates of the active root
|
||||||
// given to the constructor to the ones in |target|'s coordinates.
|
// window to the ones in |target|'s coordinates.
|
||||||
// Caller takes ownership of the returned object.
|
// Caller takes ownership of the returned object.
|
||||||
ui::MouseEvent* ConvertMouseEvent(aura::Window* target,
|
ui::MouseEvent* ConvertMouseEvent(aura::Window* target,
|
||||||
const ui::MouseEvent& event);
|
const ui::MouseEvent& event);
|
||||||
|
@ -32,10 +32,9 @@ class DragDropTrackerTest : public test::AshTestBase {
|
|||||||
parent);
|
parent);
|
||||||
}
|
}
|
||||||
|
|
||||||
static aura::Window* GetTarget(aura::RootWindow* root_window,
|
static aura::Window* GetTarget(const gfx::Point& location) {
|
||||||
const gfx::Point& location) {
|
|
||||||
scoped_ptr<internal::DragDropTracker> tracker(
|
scoped_ptr<internal::DragDropTracker> tracker(
|
||||||
new internal::DragDropTracker(root_window));
|
new internal::DragDropTracker);
|
||||||
ui::MouseEvent e(ui::ET_MOUSE_DRAGGED,
|
ui::MouseEvent e(ui::ET_MOUSE_DRAGGED,
|
||||||
location,
|
location,
|
||||||
location,
|
location,
|
||||||
@ -44,11 +43,10 @@ class DragDropTrackerTest : public test::AshTestBase {
|
|||||||
return target;
|
return target;
|
||||||
}
|
}
|
||||||
|
|
||||||
static ui::MouseEvent* ConvertMouseEvent(aura::RootWindow* root_window,
|
static ui::MouseEvent* ConvertMouseEvent(aura::Window* target,
|
||||||
aura::Window* target,
|
|
||||||
const ui::MouseEvent& event) {
|
const ui::MouseEvent& event) {
|
||||||
scoped_ptr<internal::DragDropTracker> tracker(
|
scoped_ptr<internal::DragDropTracker> tracker(
|
||||||
new internal::DragDropTracker(root_window));
|
new internal::DragDropTracker);
|
||||||
ui::MouseEvent* converted = tracker->ConvertMouseEvent(target, event);
|
ui::MouseEvent* converted = tracker->ConvertMouseEvent(target, event);
|
||||||
return converted;
|
return converted;
|
||||||
}
|
}
|
||||||
@ -78,41 +76,47 @@ TEST_F(DragDropTrackerTest, MAYBE_GetTarget) {
|
|||||||
CreateTestWindow(gfx::Rect(100, 100, 100, 100), NULL));
|
CreateTestWindow(gfx::Rect(100, 100, 100, 100), NULL));
|
||||||
window1->Show();
|
window1->Show();
|
||||||
|
|
||||||
// Start tracking from the RootWindow0 and check the point on RootWindow0 that
|
// Make RootWindow0 active so that capture window is parented to it.
|
||||||
// |window0| covers.
|
Shell::GetInstance()->set_active_root_window(root_windows[0]);
|
||||||
EXPECT_EQ(window0.get(), GetTarget(root_windows[0], gfx::Point(50, 50)));
|
|
||||||
|
|
||||||
// Start tracking from the RootWindow0 and check the point on RootWindow0 that
|
|
||||||
// neither |window0| nor |window1| covers.
|
|
||||||
EXPECT_NE(window0.get(), GetTarget(root_windows[0], gfx::Point(150, 150)));
|
|
||||||
EXPECT_NE(window1.get(), GetTarget(root_windows[0], gfx::Point(150, 150)));
|
|
||||||
|
|
||||||
// Start tracking from the RootWindow0 and check the point on RootWindow1 that
|
|
||||||
// |window1| covers.
|
|
||||||
EXPECT_EQ(window1.get(), GetTarget(root_windows[0], gfx::Point(350, 150)));
|
|
||||||
|
|
||||||
// Start tracking from the RootWindow0 and check the point on RootWindow1 that
|
|
||||||
// neither |window0| nor |window1| covers.
|
|
||||||
EXPECT_NE(window0.get(), GetTarget(root_windows[0], gfx::Point(50, 250)));
|
|
||||||
EXPECT_NE(window1.get(), GetTarget(root_windows[0], gfx::Point(50, 250)));
|
|
||||||
|
|
||||||
// Start tracking from the RootWindow1 and check the point on RootWindow0 that
|
// Start tracking from the RootWindow1 and check the point on RootWindow0 that
|
||||||
// |window0| covers.
|
// |window0| covers.
|
||||||
EXPECT_EQ(window0.get(), GetTarget(root_windows[1], gfx::Point(-150, 50)));
|
EXPECT_EQ(window0.get(), GetTarget(gfx::Point(50, 50)));
|
||||||
|
|
||||||
|
// Start tracking from the RootWindow0 and check the point on RootWindow0 that
|
||||||
|
// neither |window0| nor |window1| covers.
|
||||||
|
EXPECT_NE(window0.get(), GetTarget(gfx::Point(150, 150)));
|
||||||
|
EXPECT_NE(window1.get(), GetTarget(gfx::Point(150, 150)));
|
||||||
|
|
||||||
|
// Start tracking from the RootWindow0 and check the point on RootWindow1 that
|
||||||
|
// |window1| covers.
|
||||||
|
EXPECT_EQ(window1.get(), GetTarget(gfx::Point(350, 150)));
|
||||||
|
|
||||||
|
// Start tracking from the RootWindow0 and check the point on RootWindow1 that
|
||||||
|
// neither |window0| nor |window1| covers.
|
||||||
|
EXPECT_NE(window0.get(), GetTarget(gfx::Point(50, 250)));
|
||||||
|
EXPECT_NE(window1.get(), GetTarget(gfx::Point(50, 250)));
|
||||||
|
|
||||||
|
// Make RootWindow1 active so that capture window is parented to it.
|
||||||
|
Shell::GetInstance()->set_active_root_window(root_windows[1]);
|
||||||
|
|
||||||
|
// Start tracking from the RootWindow1 and check the point on RootWindow0 that
|
||||||
|
// |window0| covers.
|
||||||
|
EXPECT_EQ(window0.get(), GetTarget(gfx::Point(-150, 50)));
|
||||||
|
|
||||||
// Start tracking from the RootWindow1 and check the point on RootWindow0 that
|
// Start tracking from the RootWindow1 and check the point on RootWindow0 that
|
||||||
// neither |window0| nor |window1| covers.
|
// neither |window0| nor |window1| covers.
|
||||||
EXPECT_NE(window0.get(), GetTarget(root_windows[1], gfx::Point(150, -50)));
|
EXPECT_NE(window0.get(), GetTarget(gfx::Point(150, -50)));
|
||||||
EXPECT_NE(window1.get(), GetTarget(root_windows[1], gfx::Point(150, -50)));
|
EXPECT_NE(window1.get(), GetTarget(gfx::Point(150, -50)));
|
||||||
|
|
||||||
// Start tracking from the RootWindow1 and check the point on RootWindow1 that
|
// Start tracking from the RootWindow1 and check the point on RootWindow1 that
|
||||||
// |window1| covers.
|
// |window1| covers.
|
||||||
EXPECT_EQ(window1.get(), GetTarget(root_windows[1], gfx::Point(150, 150)));
|
EXPECT_EQ(window1.get(), GetTarget(gfx::Point(150, 150)));
|
||||||
|
|
||||||
// Start tracking from the RootWindow1 and check the point on RootWindow1 that
|
// Start tracking from the RootWindow1 and check the point on RootWindow1 that
|
||||||
// neither |window0| nor |window1| covers.
|
// neither |window0| nor |window1| covers.
|
||||||
EXPECT_NE(window0.get(), GetTarget(root_windows[1], gfx::Point(50, 50)));
|
EXPECT_NE(window0.get(), GetTarget(gfx::Point(50, 50)));
|
||||||
EXPECT_NE(window1.get(), GetTarget(root_windows[1], gfx::Point(50, 50)));
|
EXPECT_NE(window1.get(), GetTarget(gfx::Point(50, 50)));
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO(mazda): Remove this once ash/wm/coordinate_conversion.h supports
|
// TODO(mazda): Remove this once ash/wm/coordinate_conversion.h supports
|
||||||
@ -137,14 +141,16 @@ TEST_F(DragDropTrackerTest, MAYBE_ConvertMouseEvent) {
|
|||||||
CreateTestWindow(gfx::Rect(100, 100, 100, 100), NULL));
|
CreateTestWindow(gfx::Rect(100, 100, 100, 100), NULL));
|
||||||
window1->Show();
|
window1->Show();
|
||||||
|
|
||||||
|
// Make RootWindow0 active so that capture window is parented to it.
|
||||||
|
Shell::GetInstance()->set_active_root_window(root_windows[0]);
|
||||||
|
|
||||||
// Start tracking from the RootWindow0 and converts the mouse event into
|
// Start tracking from the RootWindow0 and converts the mouse event into
|
||||||
// |window0|'s coodinates.
|
// |window0|'s coodinates.
|
||||||
ui::MouseEvent original00(ui::ET_MOUSE_DRAGGED,
|
ui::MouseEvent original00(ui::ET_MOUSE_DRAGGED,
|
||||||
gfx::Point(50, 50),
|
gfx::Point(50, 50),
|
||||||
gfx::Point(50, 50),
|
gfx::Point(50, 50),
|
||||||
ui::EF_NONE);
|
ui::EF_NONE);
|
||||||
scoped_ptr<ui::MouseEvent> converted00(ConvertMouseEvent(root_windows[0],
|
scoped_ptr<ui::MouseEvent> converted00(ConvertMouseEvent(window0.get(),
|
||||||
window0.get(),
|
|
||||||
original00));
|
original00));
|
||||||
EXPECT_EQ(original00.type(), converted00->type());
|
EXPECT_EQ(original00.type(), converted00->type());
|
||||||
EXPECT_EQ("50,50", converted00->location().ToString());
|
EXPECT_EQ("50,50", converted00->location().ToString());
|
||||||
@ -157,22 +163,23 @@ TEST_F(DragDropTrackerTest, MAYBE_ConvertMouseEvent) {
|
|||||||
gfx::Point(350, 150),
|
gfx::Point(350, 150),
|
||||||
gfx::Point(350, 150),
|
gfx::Point(350, 150),
|
||||||
ui::EF_NONE);
|
ui::EF_NONE);
|
||||||
scoped_ptr<ui::MouseEvent> converted01(ConvertMouseEvent(root_windows[0],
|
scoped_ptr<ui::MouseEvent> converted01(ConvertMouseEvent(window1.get(),
|
||||||
window1.get(),
|
|
||||||
original01));
|
original01));
|
||||||
EXPECT_EQ(original01.type(), converted01->type());
|
EXPECT_EQ(original01.type(), converted01->type());
|
||||||
EXPECT_EQ("50,50", converted01->location().ToString());
|
EXPECT_EQ("50,50", converted01->location().ToString());
|
||||||
EXPECT_EQ("150,150", converted01->root_location().ToString());
|
EXPECT_EQ("150,150", converted01->root_location().ToString());
|
||||||
EXPECT_EQ(original01.flags(), converted01->flags());
|
EXPECT_EQ(original01.flags(), converted01->flags());
|
||||||
|
|
||||||
|
// Make RootWindow1 active so that capture window is parented to it.
|
||||||
|
Shell::GetInstance()->set_active_root_window(root_windows[1]);
|
||||||
|
|
||||||
// Start tracking from the RootWindow1 and converts the mouse event into
|
// Start tracking from the RootWindow1 and converts the mouse event into
|
||||||
// |window0|'s coodinates.
|
// |window0|'s coodinates.
|
||||||
ui::MouseEvent original10(ui::ET_MOUSE_DRAGGED,
|
ui::MouseEvent original10(ui::ET_MOUSE_DRAGGED,
|
||||||
gfx::Point(-150, 50),
|
gfx::Point(-150, 50),
|
||||||
gfx::Point(-150, 50),
|
gfx::Point(-150, 50),
|
||||||
ui::EF_NONE);
|
ui::EF_NONE);
|
||||||
scoped_ptr<ui::MouseEvent> converted10(ConvertMouseEvent(root_windows[1],
|
scoped_ptr<ui::MouseEvent> converted10(ConvertMouseEvent(window0.get(),
|
||||||
window0.get(),
|
|
||||||
original10));
|
original10));
|
||||||
EXPECT_EQ(original10.type(), converted10->type());
|
EXPECT_EQ(original10.type(), converted10->type());
|
||||||
EXPECT_EQ("50,50", converted10->location().ToString());
|
EXPECT_EQ("50,50", converted10->location().ToString());
|
||||||
@ -185,8 +192,7 @@ TEST_F(DragDropTrackerTest, MAYBE_ConvertMouseEvent) {
|
|||||||
gfx::Point(150, 150),
|
gfx::Point(150, 150),
|
||||||
gfx::Point(150, 150),
|
gfx::Point(150, 150),
|
||||||
ui::EF_NONE);
|
ui::EF_NONE);
|
||||||
scoped_ptr<ui::MouseEvent> converted11(ConvertMouseEvent(root_windows[1],
|
scoped_ptr<ui::MouseEvent> converted11(ConvertMouseEvent(window1.get(),
|
||||||
window1.get(),
|
|
||||||
original11));
|
original11));
|
||||||
EXPECT_EQ(original11.type(), converted11->type());
|
EXPECT_EQ(original11.type(), converted11->type());
|
||||||
EXPECT_EQ("50,50", converted11->location().ToString());
|
EXPECT_EQ("50,50", converted11->location().ToString());
|
||||||
|
Reference in New Issue
Block a user