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

Side by Side Diff: services/ui/public/cpp/lib/window_tree_client.cc

Issue 2183163002: mus: Change PointerWatcher to observe all pointer events, with moves optional. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: DCHECK Created 4 years, 4 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 unified diff | Download patch
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "services/ui/public/cpp/window_tree_client.h" 5 #include "services/ui/public/cpp/window_tree_client.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 8
9 #include <string> 9 #include <string>
10 #include <utility> 10 #include <utility>
(...skipping 608 matching lines...) Expand 10 before | Expand all | Expand 10 after
619 // We raced initialization. Return (0, 0). 619 // We raced initialization. Return (0, 0).
620 if (!cursor_location_memory()) 620 if (!cursor_location_memory())
621 return gfx::Point(); 621 return gfx::Point();
622 622
623 base::subtle::Atomic32 location = 623 base::subtle::Atomic32 location =
624 base::subtle::NoBarrier_Load(cursor_location_memory()); 624 base::subtle::NoBarrier_Load(cursor_location_memory());
625 return gfx::Point(static_cast<int16_t>(location >> 16), 625 return gfx::Point(static_cast<int16_t>(location >> 16),
626 static_cast<int16_t>(location & 0xFFFF)); 626 static_cast<int16_t>(location & 0xFFFF));
627 } 627 }
628 628
629 void WindowTreeClient::SetEventObserver(mojom::EventMatcherPtr matcher) { 629 void WindowTreeClient::StartPointerWatcher(bool want_moves) {
630 if (matcher.is_null()) { 630 DCHECK(!has_pointer_watcher_);
sky 2016/08/04 20:40:25 I don't think this should be a DCHECK. I think cli
riajiang 2016/08/04 21:22:06 They can call AddPointerWatcher multiple times in
sky 2016/08/04 23:08:44 You shouldn't assume this code is only ever used t
riajiang 2016/08/05 17:36:02 True makes sense. Is it correct that when clients
631 has_event_observer_ = false; 631 has_pointer_watcher_ = true;
632 tree_->SetEventObserver(nullptr, 0u); 632 pointer_watcher_id_++;
633 } else { 633 tree_->StartPointerWatcher(want_moves, pointer_watcher_id_);
634 has_event_observer_ = true; 634 }
635 event_observer_id_++; 635
636 tree_->SetEventObserver(std::move(matcher), event_observer_id_); 636 void WindowTreeClient::StopPointerWatcher() {
637 } 637 DCHECK(has_pointer_watcher_);
638 tree_->StopPointerWatcher();
639 has_pointer_watcher_ = false;
638 } 640 }
639 641
640 void WindowTreeClient::PerformWindowMove( 642 void WindowTreeClient::PerformWindowMove(
641 Window* window, 643 Window* window,
642 ui::mojom::MoveLoopSource source, 644 ui::mojom::MoveLoopSource source,
643 const gfx::Point& cursor_location, 645 const gfx::Point& cursor_location,
644 const base::Callback<void(bool)>& callback) { 646 const base::Callback<void(bool)>& callback) {
645 DCHECK(on_current_move_finished_.is_null()); 647 DCHECK(on_current_move_finished_.is_null());
646 on_current_move_finished_ = callback; 648 on_current_move_finished_ = callback;
647 649
(...skipping 317 matching lines...) Expand 10 before | Expand all | Expand 10 after
965 InFlightPropertyChange new_change(window, name, new_data); 967 InFlightPropertyChange new_change(window, name, new_data);
966 if (ApplyServerChangeToExistingInFlightChange(new_change)) 968 if (ApplyServerChangeToExistingInFlightChange(new_change))
967 return; 969 return;
968 970
969 WindowPrivate(window).LocalSetSharedProperty(name, std::move(new_data)); 971 WindowPrivate(window).LocalSetSharedProperty(name, std::move(new_data));
970 } 972 }
971 973
972 void WindowTreeClient::OnWindowInputEvent(uint32_t event_id, 974 void WindowTreeClient::OnWindowInputEvent(uint32_t event_id,
973 Id window_id, 975 Id window_id,
974 std::unique_ptr<ui::Event> event, 976 std::unique_ptr<ui::Event> event,
975 uint32_t event_observer_id) { 977 uint32_t pointer_watcher_id) {
976 DCHECK(event); 978 DCHECK(event);
977 Window* window = GetWindowByServerId(window_id); // May be null. 979 Window* window = GetWindowByServerId(window_id); // May be null.
978 980
979 // Non-zero event_observer_id means it matched an event observer on the 981 // Non-zero pointer_watcher_id means it matched a pointer watcher on the
980 // server. 982 // server.
981 if (event_observer_id != 0 && has_event_observer_ && 983 if (pointer_watcher_id_ != 0 && has_pointer_watcher_ &&
982 event_observer_id == event_observer_id_) 984 pointer_watcher_id == pointer_watcher_id_ && event->IsPointerEvent()) {
sky 2016/08/04 20:40:25 Shouldn't event->IsPointerEvent() be a DCHECK? Whe
riajiang 2016/08/04 21:22:06 Moved it to be a DCHECK inside this if.
983 delegate_->OnEventObserved(*event.get(), window); 985 delegate_->OnPointerEventObserved(*event->AsPointerEvent(), window);
986 }
984 987
985 if (!window || !window->input_event_handler_) { 988 if (!window || !window->input_event_handler_) {
986 tree_->OnWindowInputEventAck(event_id, mojom::EventResult::UNHANDLED); 989 tree_->OnWindowInputEventAck(event_id, mojom::EventResult::UNHANDLED);
987 return; 990 return;
988 } 991 }
989 992
990 std::unique_ptr<base::Callback<void(mojom::EventResult)>> ack_callback( 993 std::unique_ptr<base::Callback<void(mojom::EventResult)>> ack_callback(
991 new base::Callback<void(mojom::EventResult)>( 994 new base::Callback<void(mojom::EventResult)>(
992 base::Bind(&mojom::WindowTree::OnWindowInputEventAck, 995 base::Bind(&mojom::WindowTree::OnWindowInputEventAck,
993 base::Unretained(tree_), event_id))); 996 base::Unretained(tree_), event_id)));
(...skipping 10 matching lines...) Expand all
1004 window->input_event_handler_->OnWindowInputEvent(window, *event.get(), 1007 window->input_event_handler_->OnWindowInputEvent(window, *event.get(),
1005 &ack_callback); 1008 &ack_callback);
1006 } 1009 }
1007 1010
1008 // The handler did not take ownership of the callback, so we send the ack, 1011 // The handler did not take ownership of the callback, so we send the ack,
1009 // marking the event as not consumed. 1012 // marking the event as not consumed.
1010 if (ack_callback) 1013 if (ack_callback)
1011 ack_callback->Run(mojom::EventResult::UNHANDLED); 1014 ack_callback->Run(mojom::EventResult::UNHANDLED);
1012 } 1015 }
1013 1016
1014 void WindowTreeClient::OnEventObserved(std::unique_ptr<ui::Event> event, 1017 void WindowTreeClient::OnPointerEventObserved(std::unique_ptr<ui::Event> event,
1015 uint32_t event_observer_id) { 1018 uint32_t pointer_watcher_id) {
1016 DCHECK(event); 1019 DCHECK(event);
1017 if (has_event_observer_ && event_observer_id == event_observer_id_) 1020 DCHECK(event->IsPointerEvent());
1018 delegate_->OnEventObserved(*event.get(), nullptr /* target */); 1021 if (has_pointer_watcher_ && pointer_watcher_id == pointer_watcher_id_)
1022 delegate_->OnPointerEventObserved(*event->AsPointerEvent(),
1023 nullptr /* target */);
1019 } 1024 }
1020 1025
1021 void WindowTreeClient::OnWindowFocused(Id focused_window_id) { 1026 void WindowTreeClient::OnWindowFocused(Id focused_window_id) {
1022 Window* focused_window = GetWindowByServerId(focused_window_id); 1027 Window* focused_window = GetWindowByServerId(focused_window_id);
1023 InFlightFocusChange new_change(this, focused_window); 1028 InFlightFocusChange new_change(this, focused_window);
1024 if (ApplyServerChangeToExistingInFlightChange(new_change)) 1029 if (ApplyServerChangeToExistingInFlightChange(new_change))
1025 return; 1030 return;
1026 1031
1027 LocalSetFocus(focused_window); 1032 LocalSetFocus(focused_window);
1028 } 1033 }
(...skipping 221 matching lines...) Expand 10 before | Expand all | Expand 10 after
1250 Window* window, 1255 Window* window,
1251 const gfx::Vector2d& offset, 1256 const gfx::Vector2d& offset,
1252 const gfx::Insets& hit_area) { 1257 const gfx::Insets& hit_area) {
1253 if (window_manager_internal_client_) { 1258 if (window_manager_internal_client_) {
1254 window_manager_internal_client_->SetUnderlaySurfaceOffsetAndExtendedHitArea( 1259 window_manager_internal_client_->SetUnderlaySurfaceOffsetAndExtendedHitArea(
1255 server_id(window), offset.x(), offset.y(), hit_area); 1260 server_id(window), offset.x(), offset.y(), hit_area);
1256 } 1261 }
1257 } 1262 }
1258 1263
1259 } // namespace ui 1264 } // namespace ui
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698