forked from chromium/chromium
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chromeos: wires up pointer event observers for ws2
When a client is notified of events it's told if the event matches a pointer observer. If the event does match a pointer observer, a single event is sent to the client. This implies I need a post event processing hook to determine if the client was notified already and not send if appropriate. This is why I added WindowEventDispatcherObserver as a way to deal with this. I'll be more obvious in a following patch. BUG=837692 TEST=covered by test Change-Id: Ifb3e332466b3e6a6ee09c625020d6dbf9ed1a54e Reviewed-on: https://chromium-review.googlesource.com/1054413 Commit-Queue: Scott Violet <sky@chromium.org> Reviewed-by: Michael Wasserman <msw@chromium.org> Cr-Commit-Position: refs/heads/master@{#557797}
- Loading branch information
Scott Violet
authored and
Commit Bot
committed
May 11, 2018
1 parent
5b3c55b
commit 39c503d
Showing
17 changed files
with
427 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
// Copyright 2018 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 "services/ui/ws2/pointer_watcher.h" | ||
|
||
#include "services/ui/ws2/window_service_client.h" | ||
#include "ui/aura/env.h" | ||
#include "ui/aura/window_event_dispatcher.h" | ||
#include "ui/aura/window_tree_host.h" | ||
#include "ui/events/event.h" | ||
#include "ui/events/event_constants.h" | ||
|
||
namespace ui { | ||
namespace ws2 { | ||
|
||
PointerWatcher::PointerWatcher(WindowServiceClient* client) : client_(client) { | ||
aura::Env::GetInstance()->AddWindowEventDispatcherObserver(this); | ||
} | ||
|
||
PointerWatcher::~PointerWatcher() { | ||
aura::Env::GetInstance()->RemoveWindowEventDispatcherObserver(this); | ||
} | ||
|
||
bool PointerWatcher::ShouldSendEventToClient(const ui::Event& event) const { | ||
switch (event.type()) { | ||
case ui::ET_MOUSE_PRESSED: | ||
case ui::ET_MOUSE_RELEASED: | ||
case ui::ET_TOUCH_PRESSED: | ||
case ui::ET_TOUCH_RELEASED: | ||
return true; | ||
|
||
case ui::ET_MOUSE_MOVED: | ||
case ui::ET_TOUCH_MOVED: | ||
case ui::ET_MOUSEWHEEL: | ||
return types_to_watch_ == TypesToWatch::kUpDownMoveWheel; | ||
|
||
default: | ||
break; | ||
} | ||
return false; | ||
} | ||
|
||
void PointerWatcher::OnWindowEventDispatcherStartedProcessing( | ||
aura::WindowEventDispatcher* dispatcher, | ||
const ui::Event& event) { | ||
if (!ShouldSendEventToClient(event)) | ||
return; | ||
|
||
// TODO(sky): this needs to interact with actual event sending so that we | ||
// only send pointer events if an event wasn't also sent to the client. | ||
// Part of https://crbug.com/837692 | ||
std::unique_ptr<ui::Event> event_to_send; | ||
// Client code expects to get PointerEvents. | ||
if (event.IsMouseEvent()) | ||
event_to_send = std::make_unique<ui::PointerEvent>(*event.AsMouseEvent()); | ||
else if (event.IsTouchEvent()) | ||
event_to_send = std::make_unique<ui::PointerEvent>(*event.AsTouchEvent()); | ||
else | ||
NOTREACHED(); | ||
client_->SendPointerWatcherEventToClient(dispatcher->host()->GetDisplayId(), | ||
std::move(event_to_send)); | ||
} | ||
|
||
} // namespace ws2 | ||
} // namespace ui |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
// Copyright 2018 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 SERVICES_UI_WS2_POINTER_WATCHER_H_ | ||
#define SERVICES_UI_WS2_POINTER_WATCHER_H_ | ||
|
||
#include "base/macros.h" | ||
#include "ui/aura/window_event_dispatcher_observer.h" | ||
|
||
namespace ui { | ||
namespace ws2 { | ||
|
||
class WindowServiceClient; | ||
|
||
// PointerWatcher is used when a client has requested to observe pointer events | ||
// that the client would not normally receive. PointerWatcher observes events | ||
// by way of aura::WindowEventDispatcherObserver and forwards them to the | ||
// client. | ||
// | ||
// This class provides the server implementation of | ||
// ui::mojom::WindowTree::StartPointerWatcher(), see it for more information. | ||
class PointerWatcher : public aura::WindowEventDispatcherObserver { | ||
public: | ||
enum class TypesToWatch { | ||
// Pointer up/down events. | ||
kUpDown, | ||
|
||
// Pointer up, down, move (including drag) and wheel events. | ||
kUpDownMoveWheel, | ||
}; | ||
|
||
explicit PointerWatcher(WindowServiceClient* client); | ||
~PointerWatcher() override; | ||
|
||
void set_types_to_watch(TypesToWatch types) { types_to_watch_ = types; } | ||
|
||
private: | ||
// Returns true if |event| matches the types the PointerWatcher has been | ||
// configured to monitor. | ||
bool ShouldSendEventToClient(const ui::Event& event) const; | ||
|
||
// aura::WindowEventDispatcherObserver: | ||
void OnWindowEventDispatcherStartedProcessing( | ||
aura::WindowEventDispatcher* dispatcher, | ||
const ui::Event& event) override; | ||
|
||
TypesToWatch types_to_watch_ = TypesToWatch::kUpDown; | ||
|
||
WindowServiceClient* client_; | ||
|
||
DISALLOW_COPY_AND_ASSIGN(PointerWatcher); | ||
}; | ||
|
||
} // namespace ws2 | ||
} // namespace ui | ||
|
||
#endif // SERVICES_UI_WS2_POINTER_WATCHER_H_ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.