Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(153)

Unified Diff: ui/views/mus/window_manager_connection.cc

Issue 2180683003: NOSUBMIT: PointerWatcher observes all pointer events, with moves optional (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « ui/views/mus/window_manager_connection.h ('k') | ui/views/mus/window_manager_connection_unittest.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: ui/views/mus/window_manager_connection.cc
diff --git a/ui/views/mus/window_manager_connection.cc b/ui/views/mus/window_manager_connection.cc
index 6ad419589a43415de1d3844bf96a35fe703cff41..d927a9982f51f97ab2b71b03e606df431d13b4da 100644
--- a/ui/views/mus/window_manager_connection.cc
+++ b/ui/views/mus/window_manager_connection.cc
@@ -21,7 +21,6 @@
#include "ui/views/mus/native_widget_mus.h"
#include "ui/views/mus/screen_mus.h"
#include "ui/views/pointer_watcher.h"
-#include "ui/views/touch_event_watcher.h"
#include "ui/views/views_delegate.h"
namespace views {
@@ -95,48 +94,31 @@ NativeWidget* WindowManagerConnection::CreateNativeWidgetMus(
ui::mojom::SurfaceType::DEFAULT);
}
-void WindowManagerConnection::AddPointerWatcher(PointerWatcher* watcher) {
- // TODO(riajiang): Support multiple event matchers (crbug.com/627146).
- DCHECK(!HasTouchEventWatcher());
+void WindowManagerConnection::AddPointerWatcher(PointerWatcher* watcher,
+ bool want_moves) {
+ // Pointer watchers cannot be added multiple times.
+ DCHECK(!pointer_watchers_.HasObserver(watcher));
+ // TODO(jamescook): Support adding pointer watchers with different
+ // |want_moves| values by tracking whether the set as a whole wants moves.
+ // This will involve sending observed move events to a subset of the
+ // watchers.
+ DCHECK(!HasPointerWatcher() || want_moves == pointer_watcher_want_moves_);
+ pointer_watcher_want_moves_ = want_moves;
+
bool had_watcher = HasPointerWatcher();
pointer_watchers_.AddObserver(watcher);
if (!had_watcher) {
- // Start a watcher for pointer down.
- // TODO(jamescook): Extend event observers to handle multiple event types.
- ui::mojom::EventMatcherPtr matcher = ui::mojom::EventMatcher::New();
- matcher->type_matcher = ui::mojom::EventTypeMatcher::New();
- matcher->type_matcher->type = ui::mojom::EventType::POINTER_DOWN;
- client_->SetEventObserver(std::move(matcher));
+ // First PointerWatcher added, start the watcher on the window server.
+ client_->StartPointerWatcher(want_moves);
}
}
void WindowManagerConnection::RemovePointerWatcher(PointerWatcher* watcher) {
pointer_watchers_.RemoveObserver(watcher);
if (!HasPointerWatcher()) {
- // Last PointerWatcher removed, stop the event observer.
- client_->SetEventObserver(nullptr);
- }
-}
-
-void WindowManagerConnection::AddTouchEventWatcher(TouchEventWatcher* watcher) {
- // TODO(riajiang): Support multiple event matchers (crbug.com/627146).
- DCHECK(!HasPointerWatcher());
- bool had_watcher = HasTouchEventWatcher();
- touch_event_watchers_.AddObserver(watcher);
- if (!had_watcher) {
- ui::mojom::EventMatcherPtr matcher = ui::mojom::EventMatcher::New();
- matcher->pointer_kind_matcher = ui::mojom::PointerKindMatcher::New();
- matcher->pointer_kind_matcher->pointer_kind = ui::mojom::PointerKind::TOUCH;
- client_->SetEventObserver(std::move(matcher));
- }
-}
-
-void WindowManagerConnection::RemoveTouchEventWatcher(
- TouchEventWatcher* watcher) {
- touch_event_watchers_.RemoveObserver(watcher);
- if (!HasTouchEventWatcher()) {
- // Last TouchEventWatcher removed, stop the event observer.
- client_->SetEventObserver(nullptr);
+ // Last PointerWatcher removed, stop the watcher on the window server.
+ client_->StopPointerWatcher();
+ pointer_watcher_want_moves_ = false;
}
}
@@ -147,7 +129,9 @@ const std::set<ui::Window*>& WindowManagerConnection::GetRoots() const {
WindowManagerConnection::WindowManagerConnection(
shell::Connector* connector,
const shell::Identity& identity)
- : connector_(connector), identity_(identity) {
+ : connector_(connector),
+ identity_(identity),
+ pointer_watcher_want_moves_(false) {
lazy_tls_ptr.Pointer()->Set(this);
ui::GpuService::Initialize(connector);
@@ -176,15 +160,6 @@ bool WindowManagerConnection::HasPointerWatcher() {
return !!iterator.GetNext();
}
-bool WindowManagerConnection::HasTouchEventWatcher() {
- // Check to see if we really have any observers left. This doesn't use
- // base::ObserverList<>::might_have_observers() because that returns true
- // during iteration over the list even when the last observer is removed.
- base::ObserverList<TouchEventWatcher>::Iterator iterator(
- &touch_event_watchers_);
- return !!iterator.GetNext();
-}
-
void WindowManagerConnection::OnEmbed(ui::Window* root) {}
void WindowManagerConnection::OnDidDestroyClient(ui::WindowTreeClient* client) {
@@ -209,23 +184,11 @@ void WindowManagerConnection::OnEventObserved(const ui::Event& event,
// to store screen coordinates. Screen coordinates really should be returned
// separately. See http://crbug.com/608547
gfx::Point location_in_screen = event.AsLocatedEvent()->root_location();
- if (HasPointerWatcher()) {
- if (event.type() == ui::ET_MOUSE_PRESSED) {
- FOR_EACH_OBSERVER(PointerWatcher, pointer_watchers_,
- OnMousePressed(*event.AsMouseEvent(),
- location_in_screen, target_widget));
- } else if (event.type() == ui::ET_TOUCH_PRESSED) {
- FOR_EACH_OBSERVER(PointerWatcher, pointer_watchers_,
- OnTouchPressed(*event.AsTouchEvent(),
- location_in_screen, target_widget));
- }
- } else if (HasTouchEventWatcher()) {
- if (event.IsTouchEvent() || event.IsTouchPointerEvent()) {
- FOR_EACH_OBSERVER(
- TouchEventWatcher, touch_event_watchers_,
- OnTouchEventObserved(*event.AsLocatedEvent(), target_widget));
- }
- }
+
+ LOG(ERROR) << "JAMES event observed " << event.name();
+ FOR_EACH_OBSERVER(PointerWatcher, pointer_watchers_,
+ OnPointerEventObserved(*event.AsLocatedEvent(),
+ location_in_screen, target_widget));
}
void WindowManagerConnection::OnWindowManagerFrameValuesChanged() {
« no previous file with comments | « ui/views/mus/window_manager_connection.h ('k') | ui/views/mus/window_manager_connection_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698