Skip to content

Commit

Permalink
Use ui::Event instead of mojom::EventPtr in mash/wm.
Browse files Browse the repository at this point in the history
We want to get rid of mojom::EventPtr and use ui::Event instead at some point.
This CL removes mojom::EventPtr from one more layer in mus+ash.

BUG=578206

Review URL: https://codereview.chromium.org/1814533002

Cr-Commit-Position: refs/heads/master@{#381841}
  • Loading branch information
moshayedi authored and Commit bot committed Mar 18, 2016
1 parent 4ecae6c commit d41e5ab
Show file tree
Hide file tree
Showing 15 changed files with 82 additions and 75 deletions.
3 changes: 2 additions & 1 deletion components/mus/public/cpp/lib/window_tree_client_impl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -947,7 +947,8 @@ void WindowTreeClientImpl::WmCreateTopLevelWindow(
}

void WindowTreeClientImpl::OnAccelerator(uint32_t id, mojom::EventPtr event) {
window_manager_delegate_->OnAccelerator(id, std::move(event));
window_manager_delegate_->OnAccelerator(
id, *event.To<scoped_ptr<ui::Event>>().get());
}

void WindowTreeClientImpl::SetFrameDecorationValues(
Expand Down
4 changes: 2 additions & 2 deletions components/mus/public/cpp/tests/window_server_test_base.cc
Original file line number Diff line number Diff line change
Expand Up @@ -113,9 +113,9 @@ Window* WindowServerTestBase::OnWmCreateTopLevelWindow(
: nullptr;
}

void WindowServerTestBase::OnAccelerator(uint32_t id, mojom::EventPtr event) {
void WindowServerTestBase::OnAccelerator(uint32_t id, const ui::Event& event) {
if (window_manager_delegate_)
window_manager_delegate_->OnAccelerator(id, std::move(event));
window_manager_delegate_->OnAccelerator(id, event);
}

void WindowServerTestBase::Create(
Expand Down
2 changes: 1 addition & 1 deletion components/mus/public/cpp/tests/window_server_test_base.h
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ class WindowServerTestBase
scoped_ptr<std::vector<uint8_t>>* new_data) override;
Window* OnWmCreateTopLevelWindow(
std::map<std::string, std::vector<uint8_t>>* properties) override;
void OnAccelerator(uint32_t id, mojom::EventPtr event) override;
void OnAccelerator(uint32_t id, const ui::Event& event) override;

// InterfaceFactory<WindowTreeClient>:
void Create(mojo::Connection* connection,
Expand Down
6 changes: 5 additions & 1 deletion components/mus/public/cpp/window_manager_delegate.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,10 @@ class Rect;
class Vector2d;
}

namespace ui {
class Event;
}

namespace mus {

class Window;
Expand Down Expand Up @@ -81,7 +85,7 @@ class WindowManagerDelegate {
virtual Window* OnWmCreateTopLevelWindow(
std::map<std::string, std::vector<uint8_t>>* properties) = 0;

virtual void OnAccelerator(uint32_t id, mus::mojom::EventPtr event) = 0;
virtual void OnAccelerator(uint32_t id, const ui::Event& event) = 0;

protected:
virtual ~WindowManagerDelegate() {}
Expand Down
2 changes: 1 addition & 1 deletion components/mus/ws/window_manager_client_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ class TestWindowManagerDelegate : public WindowManagerDelegate {
std::map<std::string, std::vector<uint8_t>>* properties) override {
return nullptr;
}
void OnAccelerator(uint32_t id, mojom::EventPtr event) override {}
void OnAccelerator(uint32_t id, const ui::Event& event) override {}

private:
DISALLOW_COPY_AND_ASSIGN(TestWindowManagerDelegate);
Expand Down
27 changes: 17 additions & 10 deletions mash/wm/frame/move_event_handler.cc
Original file line number Diff line number Diff line change
Expand Up @@ -56,20 +56,27 @@ MoveEventHandler::~MoveEventHandler() {

void MoveEventHandler::ProcessLocatedEvent(ui::LocatedEvent* event) {
const bool had_move_loop = move_loop_.get() != nullptr;
ui::Event* ui_event = static_cast<ui::Event*>(event);
DCHECK(event->IsMouseEvent() || event->IsTouchEvent());

// TODO(moshayedi): no need for this once MoveEventHandler directly receives
// pointer events.
scoped_ptr<ui::PointerEvent> pointer_event;
if (event->IsMouseEvent())
pointer_event.reset(new ui::PointerEvent(*event->AsMouseEvent()));
else
pointer_event.reset(new ui::PointerEvent(*event->AsTouchEvent()));

if (move_loop_) {
if (move_loop_->Move(*mus::mojom::Event::From(*ui_event)) == MoveLoop::DONE)
if (move_loop_->Move(*pointer_event.get()) == MoveLoop::DONE)
move_loop_.reset();
} else if (event->type() == ui::ET_MOUSE_PRESSED ||
event->type() == ui::ET_TOUCH_PRESSED) {
const int ht_location = GetNonClientComponentForEvent(event);
} else if (pointer_event->type() == ui::ET_POINTER_DOWN) {
const int ht_location = GetNonClientComponentForEvent(pointer_event.get());
if (ht_location != HTNOWHERE) {
// TODO(sky): convert MoveLoop to take ui::Event.
move_loop_ = MoveLoop::Create(mus_window_, ht_location,
*mus::mojom::Event::From(*ui_event));
move_loop_ =
MoveLoop::Create(mus_window_, ht_location, *pointer_event.get());
}
} else if (event->type() == ui::ET_MOUSE_MOVED) {
const int ht_location = GetNonClientComponentForEvent(event);
} else if (pointer_event->type() == ui::ET_POINTER_MOVED) {
const int ht_location = GetNonClientComponentForEvent(pointer_event.get());
mus_window_->SetPredefinedCursor(CursorForWindowComponent(ht_location));
}
if (had_move_loop || move_loop_)
Expand Down
47 changes: 20 additions & 27 deletions mash/wm/frame/move_loop.cc
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#include "components/mus/public/interfaces/input_event_constants.mojom.h"
#include "mash/wm/property_util.h"
#include "ui/base/hit_test.h"
#include "ui/events/event.h"
#include "ui/gfx/geometry/point_conversions.h"
#include "ui/gfx/geometry/rect.h"

Expand All @@ -17,16 +18,9 @@ namespace wm {

namespace {

gfx::Point EventScreenLocationToPoint(const mus::mojom::Event& event) {
return gfx::ToFlooredPoint(
gfx::PointF(event.pointer_data->location->screen_x,
event.pointer_data->location->screen_y));
}

int MouseOnlyEventFlags(int flags) {
return flags & (mus::mojom::kEventFlagLeftMouseButton |
mus::mojom::kEventFlagMiddleMouseButton |
mus::mojom::kEventFlagRightMouseButton);
return flags & (ui::EF_LEFT_MOUSE_BUTTON | ui::EF_MIDDLE_MOUSE_BUTTON |
ui::EF_RIGHT_MOUSE_BUTTON);
}

} // namespace
Expand All @@ -39,12 +33,11 @@ MoveLoop::~MoveLoop() {
// static
scoped_ptr<MoveLoop> MoveLoop::Create(mus::Window* target,
int ht_location,
const mus::mojom::Event& event) {
DCHECK_EQ(event.action, mus::mojom::EventType::POINTER_DOWN);
const ui::PointerEvent& event) {
DCHECK_EQ(event.type(), ui::ET_POINTER_DOWN);
// Start a move on left mouse, or any other type of pointer.
if (event.pointer_data->kind == mus::mojom::PointerKind::MOUSE &&
MouseOnlyEventFlags(event.flags) !=
mus::mojom::kEventFlagLeftMouseButton) {
if (event.IsMousePointerEvent() &&
MouseOnlyEventFlags(event.flags()) != ui::EF_LEFT_MOUSE_BUTTON) {
return nullptr;
}

Expand All @@ -57,23 +50,23 @@ scoped_ptr<MoveLoop> MoveLoop::Create(mus::Window* target,
return make_scoped_ptr(new MoveLoop(target, event, type, h_loc, v_loc));
}

MoveLoop::MoveResult MoveLoop::Move(const mus::mojom::Event& event) {
switch (event.action) {
case mus::mojom::EventType::POINTER_CANCEL:
if (event.pointer_data->pointer_id == pointer_id_) {
MoveLoop::MoveResult MoveLoop::Move(const ui::PointerEvent& event) {
switch (event.type()) {
case ui::ET_POINTER_CANCELLED:
if (event.pointer_id() == pointer_id_) {
if (target_)
Revert();
return MoveResult::DONE;
}
return MoveResult::CONTINUE;

case mus::mojom::EventType::POINTER_MOVE:
if (target_ && event.pointer_data->pointer_id == pointer_id_)
case ui::ET_POINTER_MOVED:
if (target_ && event.pointer_id() == pointer_id_)
MoveImpl(event);
return MoveResult::CONTINUE;

case mus::mojom::EventType::POINTER_UP:
if (event.pointer_data->pointer_id == pointer_id_) {
case ui::ET_POINTER_UP:
if (event.pointer_id() == pointer_id_) {
// TODO(sky): need to support changed_flags.
if (target_)
MoveImpl(event);
Expand All @@ -98,16 +91,16 @@ void MoveLoop::Revert() {
}

MoveLoop::MoveLoop(mus::Window* target,
const mus::mojom::Event& event,
const ui::PointerEvent& event,
Type type,
HorizontalLocation h_loc,
VerticalLocation v_loc)
: target_(target),
type_(type),
h_loc_(h_loc),
v_loc_(v_loc),
pointer_id_(event.pointer_data->pointer_id),
initial_event_screen_location_(EventScreenLocationToPoint(event)),
pointer_id_(event.pointer_id()),
initial_event_screen_location_(event.root_location()),
initial_window_bounds_(target->bounds()),
initial_user_set_bounds_(GetWindowUserSetBounds(target)),
changing_bounds_(false) {
Expand Down Expand Up @@ -168,9 +161,9 @@ bool MoveLoop::DetermineType(int ht_location,
return false;
}

void MoveLoop::MoveImpl(const mus::mojom::Event& event) {
void MoveLoop::MoveImpl(const ui::PointerEvent& event) {
const gfx::Vector2d delta =
EventScreenLocationToPoint(event) - initial_event_screen_location_;
event.root_location() - initial_event_screen_location_;
const gfx::Rect new_bounds(DetermineBoundsFromDelta(delta));
base::AutoReset<bool> resetter(&changing_bounds_, true);
target_->SetBounds(new_bounds);
Expand Down
12 changes: 8 additions & 4 deletions mash/wm/frame/move_loop.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@
#include "ui/gfx/geometry/point.h"
#include "ui/gfx/geometry/rect.h"

namespace ui {
class PointerEvent;
}

namespace mash {
namespace wm {

Expand Down Expand Up @@ -48,10 +52,10 @@ class MoveLoop : public mus::WindowObserver {
// HitTestCompat.
static scoped_ptr<MoveLoop> Create(mus::Window* target,
int ht_location,
const mus::mojom::Event& event);
const ui::PointerEvent& event);

// Processes an event for a move/resize loop.
MoveResult Move(const mus::mojom::Event& event);
MoveResult Move(const ui::PointerEvent& event);

// If possible reverts any changes made during the move loop.
void Revert();
Expand All @@ -63,7 +67,7 @@ class MoveLoop : public mus::WindowObserver {
};

MoveLoop(mus::Window* target,
const mus::mojom::Event& event,
const ui::PointerEvent& event,
Type type,
HorizontalLocation h_loc,
VerticalLocation v_loc);
Expand All @@ -76,7 +80,7 @@ class MoveLoop : public mus::WindowObserver {
VerticalLocation* v_loc);

// Does the actual move/resize.
void MoveImpl(const mus::mojom::Event& event);
void MoveImpl(const ui::PointerEvent& event);

// Cancels the loop. This sets |target_| to null and removes the observer.
// After this the MoveLoop is still ongoing and won't stop until the
Expand Down
27 changes: 8 additions & 19 deletions mash/wm/frame/move_loop_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -20,22 +20,6 @@ using MoveLoopTest = testing::Test;
namespace mash {
namespace wm {

namespace {

mus::mojom::EventPtr CreatePointerDownEvent(const gfx::Point& location) {
const ui::TouchEvent event(ui::ET_TOUCH_PRESSED, location, 1,
base::TimeDelta());
return mus::mojom::Event::From(static_cast<const ui::Event&>(event));
}

mus::mojom::EventPtr CreatePointerMove(const gfx::Point& location) {
const ui::TouchEvent event(ui::ET_TOUCH_MOVED, location, 1,
base::TimeDelta());
return mus::mojom::Event::From(static_cast<const ui::Event&>(event));
}

} // namespace

TEST_F(MoveLoopTest, Move) {
struct TestData {
// One of the HitTestCompat values.
Expand All @@ -62,13 +46,18 @@ TEST_F(MoveLoopTest, Move) {
mus::TestWindow window;
window.SetBounds(gfx::Rect(100, 200, 300, 400));
gfx::Point pointer_location(51, 52);
ui::PointerEvent pointer_down_event(
ui::ET_POINTER_DOWN, ui::EventPointerType::POINTER_TYPE_TOUCH,
pointer_location, pointer_location, ui::EF_NONE, 1, base::TimeDelta());
scoped_ptr<MoveLoop> move_loop =
MoveLoop::Create(&window, data[i].ht_location,
*CreatePointerDownEvent(pointer_location));
MoveLoop::Create(&window, data[i].ht_location, pointer_down_event);
ASSERT_TRUE(move_loop.get()) << i;
pointer_location.Offset(data[i].delta_x, data[i].delta_y);
ui::PointerEvent pointer_move_event(
ui::ET_POINTER_MOVED, ui::EventPointerType::POINTER_TYPE_TOUCH,
pointer_location, pointer_location, ui::EF_NONE, 1, base::TimeDelta());
ASSERT_EQ(MoveLoop::MoveResult::CONTINUE,
move_loop->Move(*CreatePointerMove(pointer_location)))
move_loop->Move(pointer_move_event))
<< i;
ASSERT_EQ(data[i].expected_bounds, window.bounds());
}
Expand Down
5 changes: 2 additions & 3 deletions mash/wm/root_window_controller.cc
Original file line number Diff line number Diff line change
Expand Up @@ -82,14 +82,13 @@ mus::WindowManagerClient* RootWindowController::window_manager_client() {
return window_manager_->window_manager_client();
}

void RootWindowController::OnAccelerator(uint32_t id,
mus::mojom::EventPtr event) {
void RootWindowController::OnAccelerator(uint32_t id, const ui::Event& event) {
switch (id) {
case kWindowSwitchAccelerator:
window_manager_client()->ActivateNextWindow();
break;
default:
app_->OnAccelerator(id, std::move(event));
app_->OnAccelerator(id, event);
break;
}
}
Expand Down
6 changes: 5 additions & 1 deletion mash/wm/root_window_controller.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@ namespace mus {
class WindowManagerClient;
}

namespace ui {
class Event;
}

namespace mash {
namespace wm {

Expand Down Expand Up @@ -58,7 +62,7 @@ class RootWindowController : public mus::WindowObserver,

mus::WindowManagerClient* window_manager_client();

void OnAccelerator(uint32_t id, mus::mojom::EventPtr event);
void OnAccelerator(uint32_t id, const ui::Event& event);

private:
explicit RootWindowController(WindowManagerApplication* app);
Expand Down
2 changes: 1 addition & 1 deletion mash/wm/window_manager.cc
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ mus::Window* WindowManager::OnWmCreateTopLevelWindow(
return NewTopLevelWindow(properties);
}

void WindowManager::OnAccelerator(uint32_t id, mus::mojom::EventPtr event) {
void WindowManager::OnAccelerator(uint32_t id, const ui::Event& event) {
root_controller_->OnAccelerator(id, std::move(event));
}

Expand Down
2 changes: 1 addition & 1 deletion mash/wm/window_manager.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ class WindowManager : public mus::WindowObserver,
scoped_ptr<std::vector<uint8_t>>* new_data) override;
mus::Window* OnWmCreateTopLevelWindow(
std::map<std::string, std::vector<uint8_t>>* properties) override;
void OnAccelerator(uint32_t id, mus::mojom::EventPtr event) override;
void OnAccelerator(uint32_t id, const ui::Event& event) override;

// mash::shell::mojom::ScreenlockStateListener:
void ScreenlockStateChanged(bool locked) override;
Expand Down
6 changes: 4 additions & 2 deletions mash/wm/window_manager_application.cc
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,11 @@
#include "mash/wm/root_window_controller.h"
#include "mash/wm/root_windows_observer.h"
#include "mash/wm/user_window_controller_impl.h"
#include "mojo/converters/input_events/input_events_type_converters.h"
#include "mojo/services/tracing/public/cpp/tracing_impl.h"
#include "mojo/shell/public/cpp/connection.h"
#include "mojo/shell/public/cpp/connector.h"
#include "ui/events/event.h"
#include "ui/mojo/init/ui_init.h"
#include "ui/views/mus/aura_init.h"
#include "ui/views/mus/display_converter.h"
Expand Down Expand Up @@ -79,10 +81,10 @@ void WindowManagerApplication::OnRootWindowDestroyed(
}

void WindowManagerApplication::OnAccelerator(uint32_t id,
mus::mojom::EventPtr event) {
const ui::Event& event) {
for (auto* registrar : accelerator_registrars_) {
if (registrar->OwnsAccelerator(id)) {
registrar->ProcessAccelerator(id, std::move(event));
registrar->ProcessAccelerator(id, mus::mojom::Event::From(event));
break;
}
}
Expand Down
6 changes: 5 additions & 1 deletion mash/wm/window_manager_application.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,10 @@ namespace views {
class AuraInit;
}

namespace ui {
class Event;
}

namespace mash {
namespace wm {

Expand Down Expand Up @@ -70,7 +74,7 @@ class WindowManagerApplication
void OnRootWindowDestroyed(RootWindowController* root_controller);

// TODO(sky): figure out right place for this code.
void OnAccelerator(uint32_t id, mus::mojom::EventPtr event);
void OnAccelerator(uint32_t id, const ui::Event& event);

void AddRootWindowsObserver(RootWindowsObserver* observer);
void RemoveRootWindowsObserver(RootWindowsObserver* observer);
Expand Down

0 comments on commit d41e5ab

Please sign in to comment.