OLD | NEW |
---|---|
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 "services/ui/ws/display.h" | 5 #include "services/ui/ws/display.h" |
6 | 6 |
7 #include <set> | 7 #include <set> |
8 #include <utility> | 8 #include <utility> |
9 #include <vector> | 9 #include <vector> |
10 | 10 |
(...skipping 18 matching lines...) Expand all Loading... | |
29 #include "ui/base/cursor/cursor.h" | 29 #include "ui/base/cursor/cursor.h" |
30 #include "ui/display/screen.h" | 30 #include "ui/display/screen.h" |
31 | 31 |
32 #if defined(USE_OZONE) | 32 #if defined(USE_OZONE) |
33 #include "ui/ozone/public/ozone_platform.h" | 33 #include "ui/ozone/public/ozone_platform.h" |
34 #endif | 34 #endif |
35 | 35 |
36 namespace ui { | 36 namespace ui { |
37 namespace ws { | 37 namespace ws { |
38 | 38 |
39 class Display::CursorState { | |
40 public: | |
41 CursorState() | |
42 : cursor_data_(ui::CursorData(ui::CursorType::kNull)), visible_(true) {} | |
43 CursorState(const CursorState& rhs) = default; | |
44 ~CursorState() {} | |
45 | |
46 const base::Optional<ui::CursorData>& global_override_cursor() const { | |
47 return global_override_cursor_; | |
48 } | |
49 void SetGlobalOverrideCursor(const base::Optional<ui::CursorData>& cursor) { | |
50 global_override_cursor_ = cursor; | |
51 } | |
52 | |
53 const ui::CursorData& cursor_data() const { return cursor_data_; } | |
54 void SetCursorData(const ui::CursorData& data) { cursor_data_ = data; } | |
55 | |
56 bool visible() const { return visible_; } | |
57 void set_visible(bool visible) { visible_ = visible; } | |
58 | |
59 private: | |
60 // An optional cursor set by the window manager which overrides per-window | |
61 // requests. | |
62 base::Optional<ui::CursorData> global_override_cursor_; | |
63 | |
64 // The last cursor set. Used to track whether we need to change the cursor. | |
65 ui::CursorData cursor_data_; | |
66 | |
67 // Whether the cursor is visible. | |
68 bool visible_; | |
69 }; | |
70 | |
39 Display::Display(WindowServer* window_server) | 71 Display::Display(WindowServer* window_server) |
40 : window_server_(window_server), | 72 : window_server_(window_server), |
41 last_cursor_(ui::CursorData(ui::CursorType::kNull)) { | 73 current_state_(base::MakeUnique<CursorState>()), |
74 state_on_unlock_(base::MakeUnique<CursorState>()) { | |
42 window_server_->window_manager_window_tree_factory_set()->AddObserver(this); | 75 window_server_->window_manager_window_tree_factory_set()->AddObserver(this); |
43 window_server_->user_id_tracker()->AddObserver(this); | 76 window_server_->user_id_tracker()->AddObserver(this); |
44 } | 77 } |
45 | 78 |
46 Display::~Display() { | 79 Display::~Display() { |
47 window_server_->user_id_tracker()->RemoveObserver(this); | 80 window_server_->user_id_tracker()->RemoveObserver(this); |
48 | 81 |
49 window_server_->window_manager_window_tree_factory_set()->RemoveObserver( | 82 window_server_->window_manager_window_tree_factory_set()->RemoveObserver( |
50 this); | 83 this); |
51 | 84 |
(...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
192 it != window_manager_display_root_map_.end(); ++it) { | 225 it != window_manager_display_root_map_.end(); ++it) { |
193 if (it->second == display_root) { | 226 if (it->second == display_root) { |
194 window_manager_display_root_map_.erase(it); | 227 window_manager_display_root_map_.erase(it); |
195 return; | 228 return; |
196 } | 229 } |
197 } | 230 } |
198 NOTREACHED(); | 231 NOTREACHED(); |
199 } | 232 } |
200 | 233 |
201 void Display::UpdateNativeCursor(const ui::CursorData& cursor) { | 234 void Display::UpdateNativeCursor(const ui::CursorData& cursor) { |
202 if (!last_cursor_.IsSameAs(cursor)) { | 235 if (!state_on_unlock_->cursor_data().IsSameAs(cursor)) |
203 platform_display_->SetCursor(cursor); | 236 state_on_unlock_->SetCursorData(cursor); |
204 last_cursor_ = cursor; | 237 |
238 if (cursor_lock_count_ == 0 && | |
239 !current_state_->cursor_data().IsSameAs(cursor)) { | |
240 current_state_->SetCursorData(cursor); | |
241 SetPlatformCursor(); | |
205 } | 242 } |
206 } | 243 } |
207 | 244 |
245 void Display::LockCursor() { | |
246 cursor_lock_count_++; | |
247 } | |
248 | |
249 void Display::UnlockCursor() { | |
250 cursor_lock_count_--; | |
sky
2017/05/12 13:40:01
Having each Display track this state is rather dup
Elliot Glaysher
2017/05/12 23:02:44
Created CursorState class, which is owned by windo
| |
251 DCHECK_GE(cursor_lock_count_, 0); | |
252 if (cursor_lock_count_ > 0) | |
253 return; | |
254 | |
255 *current_state_ = *state_on_unlock_; | |
256 SetPlatformCursor(); | |
257 } | |
258 | |
259 void Display::ShowCursor() { | |
260 state_on_unlock_->set_visible(true); | |
261 if (cursor_lock_count_ == 0 && | |
262 current_state_->visible() != state_on_unlock_->visible()) { | |
263 current_state_->set_visible(true); | |
264 SetPlatformCursor(); | |
265 } | |
266 } | |
267 | |
268 void Display::HideCursor() { | |
269 state_on_unlock_->set_visible(false); | |
270 if (cursor_lock_count_ == 0 && | |
271 current_state_->visible() != state_on_unlock_->visible()) { | |
272 platform_display_->SetCursor(ui::CursorData(ui::CursorType::kNone)); | |
273 current_state_->set_visible(false); | |
274 } | |
275 } | |
276 | |
277 void Display::SetGlobalOverrideCursor( | |
278 const base::Optional<ui::CursorData>& cursor) { | |
279 state_on_unlock_->SetGlobalOverrideCursor(cursor); | |
280 if (cursor_lock_count_ == 0) { | |
281 current_state_->SetGlobalOverrideCursor(cursor); | |
282 SetPlatformCursor(); | |
283 } | |
284 } | |
285 | |
208 void Display::SetSize(const gfx::Size& size) { | 286 void Display::SetSize(const gfx::Size& size) { |
209 platform_display_->SetViewportSize(size); | 287 platform_display_->SetViewportSize(size); |
210 } | 288 } |
211 | 289 |
212 void Display::SetTitle(const std::string& title) { | 290 void Display::SetTitle(const std::string& title) { |
213 platform_display_->SetTitle(base::UTF8ToUTF16(title)); | 291 platform_display_->SetTitle(base::UTF8ToUTF16(title)); |
214 } | 292 } |
215 | 293 |
216 void Display::InitWindowManagerDisplayRoots() { | 294 void Display::InitWindowManagerDisplayRoots() { |
217 if (binding_) { | 295 if (binding_) { |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
266 display_manager()->GetAndAdvanceNextRootId(), | 344 display_manager()->GetAndAdvanceNextRootId(), |
267 ServerWindow::Properties())); | 345 ServerWindow::Properties())); |
268 root_->set_event_targeting_policy( | 346 root_->set_event_targeting_policy( |
269 mojom::EventTargetingPolicy::DESCENDANTS_ONLY); | 347 mojom::EventTargetingPolicy::DESCENDANTS_ONLY); |
270 root_->SetBounds(gfx::Rect(size), allocator_.GenerateId()); | 348 root_->SetBounds(gfx::Rect(size), allocator_.GenerateId()); |
271 root_->SetVisible(true); | 349 root_->SetVisible(true); |
272 focus_controller_ = base::MakeUnique<FocusController>(this, root_.get()); | 350 focus_controller_ = base::MakeUnique<FocusController>(this, root_.get()); |
273 focus_controller_->AddObserver(this); | 351 focus_controller_->AddObserver(this); |
274 } | 352 } |
275 | 353 |
354 void Display::SetPlatformCursor() { | |
355 if (current_state_->visible()) { | |
356 if (current_state_->global_override_cursor().has_value()) { | |
357 platform_display_->SetCursor( | |
358 current_state_->global_override_cursor().value()); | |
359 } else { | |
360 platform_display_->SetCursor(current_state_->cursor_data()); | |
361 } | |
362 } else { | |
363 platform_display_->SetCursor(ui::CursorData(ui::CursorType::kNone)); | |
364 } | |
365 } | |
366 | |
276 ServerWindow* Display::GetRootWindow() { | 367 ServerWindow* Display::GetRootWindow() { |
277 return root_.get(); | 368 return root_.get(); |
278 } | 369 } |
279 | 370 |
280 EventSink* Display::GetEventSink() { | 371 EventSink* Display::GetEventSink() { |
281 return this; | 372 return this; |
282 } | 373 } |
283 | 374 |
284 void Display::OnAcceleratedWidgetAvailable() { | 375 void Display::OnAcceleratedWidgetAvailable() { |
285 display_manager()->OnDisplayAcceleratedWidgetAvailable(this); | 376 display_manager()->OnDisplayAcceleratedWidgetAvailable(this); |
(...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
412 | 503 |
413 UserActivityMonitor* activity_monitor = | 504 UserActivityMonitor* activity_monitor = |
414 window_server_->GetUserActivityMonitorForUser( | 505 window_server_->GetUserActivityMonitorForUser( |
415 window_server_->user_id_tracker()->active_id()); | 506 window_server_->user_id_tracker()->active_id()); |
416 activity_monitor->OnUserActivity(); | 507 activity_monitor->OnUserActivity(); |
417 return EventDispatchDetails(); | 508 return EventDispatchDetails(); |
418 } | 509 } |
419 | 510 |
420 } // namespace ws | 511 } // namespace ws |
421 } // namespace ui | 512 } // namespace ui |
OLD | NEW |