OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "ui/aura/window_tree_host_x11.h" | 5 #include "ui/aura/window_tree_host_x11.h" |
6 | 6 |
7 #include <strings.h> | 7 #include <strings.h> |
8 #include <X11/cursorfont.h> | 8 #include <X11/cursorfont.h> |
9 #include <X11/extensions/XInput2.h> | 9 #include <X11/extensions/XInput2.h> |
10 #include <X11/extensions/Xrandr.h> | 10 #include <X11/extensions/Xrandr.h> |
(...skipping 26 matching lines...) Expand all Loading... |
37 #include "ui/compositor/layer.h" | 37 #include "ui/compositor/layer.h" |
38 #include "ui/events/event.h" | 38 #include "ui/events/event.h" |
39 #include "ui/events/event_switches.h" | 39 #include "ui/events/event_switches.h" |
40 #include "ui/events/event_utils.h" | 40 #include "ui/events/event_utils.h" |
41 #include "ui/events/keycodes/keyboard_codes.h" | 41 #include "ui/events/keycodes/keyboard_codes.h" |
42 #include "ui/events/platform/x11/x11_event_source.h" | 42 #include "ui/events/platform/x11/x11_event_source.h" |
43 #include "ui/events/x/device_data_manager.h" | 43 #include "ui/events/x/device_data_manager.h" |
44 #include "ui/events/x/device_list_cache_x.h" | 44 #include "ui/events/x/device_list_cache_x.h" |
45 #include "ui/events/x/touch_factory_x11.h" | 45 #include "ui/events/x/touch_factory_x11.h" |
46 #include "ui/gfx/screen.h" | 46 #include "ui/gfx/screen.h" |
| 47 #include "ui/window/platform_window.h" |
47 | 48 |
48 using std::max; | 49 using std::max; |
49 using std::min; | 50 using std::min; |
50 | 51 |
51 namespace aura { | 52 namespace aura { |
52 | 53 |
53 namespace { | 54 namespace { |
54 | 55 |
55 const char* kAtomsToCache[] = { | 56 const char* kAtomsToCache[] = { |
56 "WM_DELETE_WINDOW", | 57 "WM_DELETE_WINDOW", |
(...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
168 xwindow_, | 169 xwindow_, |
169 atom_cache_.GetAtom("_NET_WM_PID"), | 170 atom_cache_.GetAtom("_NET_WM_PID"), |
170 XA_CARDINAL, | 171 XA_CARDINAL, |
171 32, | 172 32, |
172 PropModeReplace, | 173 PropModeReplace, |
173 reinterpret_cast<unsigned char*>(&pid), 1); | 174 reinterpret_cast<unsigned char*>(&pid), 1); |
174 | 175 |
175 XRRSelectInput(xdisplay_, x_root_window_, | 176 XRRSelectInput(xdisplay_, x_root_window_, |
176 RRScreenChangeNotifyMask | RROutputChangeNotifyMask); | 177 RRScreenChangeNotifyMask | RROutputChangeNotifyMask); |
177 CreateCompositor(GetAcceleratedWidget()); | 178 CreateCompositor(GetAcceleratedWidget()); |
| 179 |
| 180 platform_window_ = ui::CreateDefaultPlatformWindow(this); |
| 181 platform_window_->SetBounds(bounds); |
178 } | 182 } |
179 | 183 |
180 WindowTreeHostX11::~WindowTreeHostX11() { | 184 WindowTreeHostX11::~WindowTreeHostX11() { |
181 if (ui::PlatformEventSource::GetInstance()) | 185 if (ui::PlatformEventSource::GetInstance()) |
182 ui::PlatformEventSource::GetInstance()->RemovePlatformEventDispatcher(this); | 186 ui::PlatformEventSource::GetInstance()->RemovePlatformEventDispatcher(this); |
183 | 187 |
184 DestroyCompositor(); | 188 DestroyCompositor(); |
185 DestroyDispatcher(); | 189 DestroyDispatcher(); |
186 XDestroyWindow(xdisplay_, xwindow_); | 190 XDestroyWindow(xdisplay_, xwindow_); |
187 } | 191 } |
(...skipping 178 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
366 | 370 |
367 XMapWindow(xdisplay_, xwindow_); | 371 XMapWindow(xdisplay_, xwindow_); |
368 | 372 |
369 // We now block until our window is mapped. Some X11 APIs will crash and | 373 // We now block until our window is mapped. Some X11 APIs will crash and |
370 // burn if passed |xwindow_| before the window is mapped, and XMapWindow is | 374 // burn if passed |xwindow_| before the window is mapped, and XMapWindow is |
371 // asynchronous. | 375 // asynchronous. |
372 if (ui::X11EventSource::GetInstance()) | 376 if (ui::X11EventSource::GetInstance()) |
373 ui::X11EventSource::GetInstance()->BlockUntilWindowMapped(xwindow_); | 377 ui::X11EventSource::GetInstance()->BlockUntilWindowMapped(xwindow_); |
374 window_mapped_ = true; | 378 window_mapped_ = true; |
375 } | 379 } |
| 380 platform_window_->Show(); |
376 } | 381 } |
377 | 382 |
378 void WindowTreeHostX11::Hide() { | 383 void WindowTreeHostX11::Hide() { |
| 384 platform_window_->Hide(); |
379 if (window_mapped_) { | 385 if (window_mapped_) { |
380 XWithdrawWindow(xdisplay_, xwindow_, 0); | 386 XWithdrawWindow(xdisplay_, xwindow_, 0); |
381 window_mapped_ = false; | 387 window_mapped_ = false; |
382 } | 388 } |
383 } | 389 } |
384 | 390 |
385 gfx::Rect WindowTreeHostX11::GetBounds() const { | 391 gfx::Rect WindowTreeHostX11::GetBounds() const { |
386 return bounds_; | 392 return bounds_; |
387 } | 393 } |
388 | 394 |
(...skipping 28 matching lines...) Expand all Loading... |
417 // (possibly synthetic) ConfigureNotify about the actual size and correct | 423 // (possibly synthetic) ConfigureNotify about the actual size and correct |
418 // |bounds_| later. | 424 // |bounds_| later. |
419 bounds_ = bounds; | 425 bounds_ = bounds; |
420 if (origin_changed) | 426 if (origin_changed) |
421 OnHostMoved(bounds.origin()); | 427 OnHostMoved(bounds.origin()); |
422 if (size_changed || current_scale != new_scale) { | 428 if (size_changed || current_scale != new_scale) { |
423 OnHostResized(bounds.size()); | 429 OnHostResized(bounds.size()); |
424 } else { | 430 } else { |
425 window()->SchedulePaintInRect(window()->bounds()); | 431 window()->SchedulePaintInRect(window()->bounds()); |
426 } | 432 } |
| 433 platform_window_->SetBounds(bounds); |
427 } | 434 } |
428 | 435 |
429 gfx::Point WindowTreeHostX11::GetLocationOnNativeScreen() const { | 436 gfx::Point WindowTreeHostX11::GetLocationOnNativeScreen() const { |
430 return bounds_.origin(); | 437 return bounds_.origin(); |
431 } | 438 } |
432 | 439 |
433 void WindowTreeHostX11::SetCapture() { | 440 void WindowTreeHostX11::SetCapture() { |
434 // TODO(oshima): Grab x input. | 441 // TODO(oshima): Grab x input. |
435 } | 442 } |
436 | 443 |
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
513 bounds_.y() + location.y()); | 520 bounds_.y() + location.y()); |
514 } | 521 } |
515 | 522 |
516 void WindowTreeHostX11::OnCursorVisibilityChangedNative(bool show) { | 523 void WindowTreeHostX11::OnCursorVisibilityChangedNative(bool show) { |
517 } | 524 } |
518 | 525 |
519 ui::EventProcessor* WindowTreeHostX11::GetEventProcessor() { | 526 ui::EventProcessor* WindowTreeHostX11::GetEventProcessor() { |
520 return dispatcher(); | 527 return dispatcher(); |
521 } | 528 } |
522 | 529 |
| 530 void WindowTreeHostX11::OnBoundsChanged(const gfx::Rect& new_bounds) { |
| 531 bool size_changed = bounds_.size() != new_bounds.size(); |
| 532 bool origin_changed = bounds_.origin() != new_bounds.origin(); |
| 533 bounds_ = new_bounds; |
| 534 OnConfigureNotify(); |
| 535 if (size_changed) |
| 536 OnHostResized(new_bounds.size()); |
| 537 if (origin_changed) |
| 538 OnHostMoved(bounds_.origin()); |
| 539 } |
| 540 |
| 541 void WindowTreeHostX11::OnDamageRect(const gfx::Rect& damaged_rect) { |
| 542 compositor()->ScheduleRedrawRect(damaged_rect); |
| 543 } |
| 544 |
| 545 void WindowTreeHostX11::DispatchEvent(ui::Event* event) { |
| 546 LOG(ERROR) << "X: " << event->name(); |
| 547 if (event->type() == ui::ET_MOUSE_MOVED && |
| 548 (event->flags() & ui::EF_IS_SYNTHESIZED)) { |
| 549 aura::Window* root_window = window(); |
| 550 client::CursorClient* cursor_client = client::GetCursorClient(root_window); |
| 551 if (cursor_client) { |
| 552 const gfx::Display display = gfx::Screen::GetScreenFor(root_window) |
| 553 ->GetDisplayNearestWindow(root_window); |
| 554 cursor_client->SetDisplay(display); |
| 555 } |
| 556 } |
| 557 } |
| 558 |
| 559 void WindowTreeHostX11::OnCloseRequest() { |
| 560 } |
| 561 |
| 562 void WindowTreeHostX11::OnClosed() { |
| 563 } |
| 564 |
| 565 void WindowTreeHostX11::OnWindowStateChanged( |
| 566 ui::PlatformWindowState new_state) { |
| 567 } |
| 568 |
| 569 void WindowTreeHostX11::OnLostCapture() { |
| 570 OnHostLostWindowCapture(); |
| 571 } |
| 572 |
523 void WindowTreeHostX11::DispatchXI2Event(const base::NativeEvent& event) { | 573 void WindowTreeHostX11::DispatchXI2Event(const base::NativeEvent& event) { |
524 ui::TouchFactory* factory = ui::TouchFactory::GetInstance(); | 574 ui::TouchFactory* factory = ui::TouchFactory::GetInstance(); |
525 XEvent* xev = event; | 575 XEvent* xev = event; |
526 if (!factory->ShouldProcessXI2Event(xev)) | 576 if (!factory->ShouldProcessXI2Event(xev)) |
527 return; | 577 return; |
528 | 578 |
529 TRACE_EVENT1("input", "WindowTreeHostX11::DispatchXI2Event", | 579 TRACE_EVENT1("input", "WindowTreeHostX11::DispatchXI2Event", |
530 "event_latency_us", | 580 "event_latency_us", |
531 (ui::EventTimeForNow() - ui::EventTimeFromNative(event)). | 581 (ui::EventTimeForNow() - ui::EventTimeFromNative(event)). |
532 InMicroseconds()); | 582 InMicroseconds()); |
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
628 } | 678 } |
629 | 679 |
630 namespace test { | 680 namespace test { |
631 | 681 |
632 void SetUseOverrideRedirectWindowByDefault(bool override_redirect) { | 682 void SetUseOverrideRedirectWindowByDefault(bool override_redirect) { |
633 default_override_redirect = override_redirect; | 683 default_override_redirect = override_redirect; |
634 } | 684 } |
635 | 685 |
636 } // namespace test | 686 } // namespace test |
637 } // namespace aura | 687 } // namespace aura |
OLD | NEW |