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

Side by Side Diff: components/mus/ws/event_dispatcher_unittest.cc

Issue 2089023002: Promotes remaining global window manager state into WindowManagerState (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: override Created 4 years, 6 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 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 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 "components/mus/ws/event_dispatcher.h" 5 #include "components/mus/ws/event_dispatcher.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 #include <stdint.h> 8 #include <stdint.h>
9 9
10 #include <queue> 10 #include <queue>
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
63 ui::Event* last_event_target_not_found() { 63 ui::Event* last_event_target_not_found() {
64 return last_event_target_not_found_.get(); 64 return last_event_target_not_found_.get();
65 } 65 }
66 66
67 uint32_t GetAndClearLastAccelerator() { 67 uint32_t GetAndClearLastAccelerator() {
68 uint32_t return_value = last_accelerator_; 68 uint32_t return_value = last_accelerator_;
69 last_accelerator_ = 0; 69 last_accelerator_ = 0;
70 return return_value; 70 return return_value;
71 } 71 }
72 72
73 void set_root(ServerWindow* root) { root_ = root; }
74
73 // Returns the last dispatched event, or null if there are no more. 75 // Returns the last dispatched event, or null if there are no more.
74 std::unique_ptr<DispatchedEventDetails> 76 std::unique_ptr<DispatchedEventDetails>
75 GetAndAdvanceDispatchedEventDetails() { 77 GetAndAdvanceDispatchedEventDetails() {
76 if (dispatched_event_queue_.empty()) 78 if (dispatched_event_queue_.empty())
77 return nullptr; 79 return nullptr;
78 80
79 std::unique_ptr<DispatchedEventDetails> details = 81 std::unique_ptr<DispatchedEventDetails> details =
80 std::move(dispatched_event_queue_.front()); 82 std::move(dispatched_event_queue_.front());
81 dispatched_event_queue_.pop(); 83 dispatched_event_queue_.pop();
82 return details; 84 return details;
(...skipping 15 matching lines...) Expand all
98 100
99 private: 101 private:
100 // EventDispatcherDelegate: 102 // EventDispatcherDelegate:
101 void OnAccelerator(uint32_t accelerator, const ui::Event& event) override { 103 void OnAccelerator(uint32_t accelerator, const ui::Event& event) override {
102 EXPECT_EQ(0u, last_accelerator_); 104 EXPECT_EQ(0u, last_accelerator_);
103 last_accelerator_ = accelerator; 105 last_accelerator_ = accelerator;
104 } 106 }
105 ServerWindow* GetFocusedWindowForEventDispatcher() override { 107 ServerWindow* GetFocusedWindowForEventDispatcher() override {
106 return focused_window_; 108 return focused_window_;
107 } 109 }
108 void SetNativeCapture() override {} 110 void SetNativeCapture(ServerWindow* window) override {}
109 void ReleaseNativeCapture() override { 111 void ReleaseNativeCapture() override {
110 if (delegate_) 112 if (delegate_)
111 delegate_->ReleaseCapture(); 113 delegate_->ReleaseCapture();
112 } 114 }
113 void OnServerWindowCaptureLost(ServerWindow* window) override { 115 void OnServerWindowCaptureLost(ServerWindow* window) override {
114 lost_capture_window_ = window; 116 lost_capture_window_ = window;
115 } 117 }
116 void OnMouseCursorLocationChanged(const gfx::Point& point) override {} 118 void OnMouseCursorLocationChanged(const gfx::Point& point) override {}
117 void DispatchInputEventToWindow(ServerWindow* target, 119 void DispatchInputEventToWindow(ServerWindow* target,
118 ClientSpecificId client_id, 120 ClientSpecificId client_id,
119 const ui::Event& event, 121 const ui::Event& event,
120 Accelerator* accelerator) override { 122 Accelerator* accelerator) override {
121 std::unique_ptr<DispatchedEventDetails> details(new DispatchedEventDetails); 123 std::unique_ptr<DispatchedEventDetails> details(new DispatchedEventDetails);
122 details->window = target; 124 details->window = target;
123 details->client_id = client_id; 125 details->client_id = client_id;
124 details->event = ui::Event::Clone(event); 126 details->event = ui::Event::Clone(event);
125 details->accelerator = accelerator; 127 details->accelerator = accelerator;
126 dispatched_event_queue_.push(std::move(details)); 128 dispatched_event_queue_.push(std::move(details));
127 } 129 }
128 void OnEventTargetNotFound(const ui::Event& event) override {
129 last_event_target_not_found_ = ui::Event::Clone(event);
130 }
131 ClientSpecificId GetEventTargetClientId(const ServerWindow* window, 130 ClientSpecificId GetEventTargetClientId(const ServerWindow* window,
132 bool in_nonclient_area) override { 131 bool in_nonclient_area) override {
133 return in_nonclient_area ? kNonclientAreaId : kClientAreaId; 132 return in_nonclient_area ? kNonclientAreaId : kClientAreaId;
134 } 133 }
134 ServerWindow* GetRootWindowContaining(const gfx::Point& location) override {
135 return root_;
136 }
137 void OnEventTargetNotFound(const ui::Event& event) override {
138 last_event_target_not_found_ = ui::Event::Clone(event);
139 }
135 140
136 Delegate* delegate_; 141 Delegate* delegate_;
137 ServerWindow* focused_window_; 142 ServerWindow* focused_window_;
138 ServerWindow* lost_capture_window_; 143 ServerWindow* lost_capture_window_;
139 uint32_t last_accelerator_; 144 uint32_t last_accelerator_;
140 std::queue<std::unique_ptr<DispatchedEventDetails>> dispatched_event_queue_; 145 std::queue<std::unique_ptr<DispatchedEventDetails>> dispatched_event_queue_;
146 ServerWindow* root_ = nullptr;
141 std::unique_ptr<ui::Event> last_event_target_not_found_; 147 std::unique_ptr<ui::Event> last_event_target_not_found_;
142 148
143 DISALLOW_COPY_AND_ASSIGN(TestEventDispatcherDelegate); 149 DISALLOW_COPY_AND_ASSIGN(TestEventDispatcherDelegate);
144 }; 150 };
145 151
146 // Used by RunMouseEventTests(). Can identify up to two generated events. The 152 // Used by RunMouseEventTests(). Can identify up to two generated events. The
147 // first ServerWindow and two points identify the first event, the second 153 // first ServerWindow and two points identify the first event, the second
148 // ServerWindow and points identify the second event. If only one event is 154 // ServerWindow and points identify the second event. If only one event is
149 // generated set the second window to null. 155 // generated set the second window to null.
150 struct MouseEventTest { 156 struct MouseEventTest {
(...skipping 154 matching lines...) Expand 10 before | Expand all | Expand 10 after
305 testing::Test::SetUp(); 311 testing::Test::SetUp();
306 312
307 window_delegate_.reset(new TestServerWindowDelegate()); 313 window_delegate_.reset(new TestServerWindowDelegate());
308 root_window_.reset(new ServerWindow(window_delegate_.get(), WindowId(1, 2))); 314 root_window_.reset(new ServerWindow(window_delegate_.get(), WindowId(1, 2)));
309 window_delegate_->set_root_window(root_window_.get()); 315 window_delegate_->set_root_window(root_window_.get());
310 root_window_->SetVisible(true); 316 root_window_->SetVisible(true);
311 317
312 test_event_dispatcher_delegate_.reset(new TestEventDispatcherDelegate(this)); 318 test_event_dispatcher_delegate_.reset(new TestEventDispatcherDelegate(this));
313 event_dispatcher_.reset( 319 event_dispatcher_.reset(
314 new EventDispatcher(test_event_dispatcher_delegate_.get())); 320 new EventDispatcher(test_event_dispatcher_delegate_.get()));
315 event_dispatcher_->set_root(root_window_.get()); 321 test_event_dispatcher_delegate_->set_root(root_window_.get());
316 } 322 }
317 323
318 TEST_F(EventDispatcherTest, ProcessEvent) { 324 TEST_F(EventDispatcherTest, ProcessEvent) {
319 std::unique_ptr<ServerWindow> child = CreateChildWindow(WindowId(1, 3)); 325 std::unique_ptr<ServerWindow> child = CreateChildWindow(WindowId(1, 3));
320 326
321 root_window()->SetBounds(gfx::Rect(0, 0, 100, 100)); 327 root_window()->SetBounds(gfx::Rect(0, 0, 100, 100));
322 child->SetBounds(gfx::Rect(10, 10, 20, 20)); 328 child->SetBounds(gfx::Rect(10, 10, 20, 20));
323 329
324 // Send event that is over child. 330 // Send event that is over child.
325 const ui::PointerEvent ui_event(ui::MouseEvent( 331 const ui::PointerEvent ui_event(ui::MouseEvent(
(...skipping 1273 matching lines...) Expand 10 before | Expand all | Expand 10 after
1599 // The delegate can decide if it really wants to forward the event or not. 1605 // The delegate can decide if it really wants to forward the event or not.
1600 EXPECT_EQ(child.get(), 1606 EXPECT_EQ(child.get(),
1601 test_event_dispatcher_delegate()->lost_capture_window()); 1607 test_event_dispatcher_delegate()->lost_capture_window());
1602 EXPECT_EQ(child.get(), event_dispatcher()->capture_window()); 1608 EXPECT_EQ(child.get(), event_dispatcher()->capture_window());
1603 EXPECT_EQ(kClientAreaId, event_dispatcher()->capture_window_client_id()); 1609 EXPECT_EQ(kClientAreaId, event_dispatcher()->capture_window_client_id());
1604 } 1610 }
1605 1611
1606 } // namespace test 1612 } // namespace test
1607 } // namespace ws 1613 } // namespace ws
1608 } // namespace mus 1614 } // namespace mus
OLDNEW
« no previous file with comments | « components/mus/ws/event_dispatcher_delegate.h ('k') | components/mus/ws/global_window_manager_state.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698