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

Side by Side Diff: ui/aura/root_window_host_linux.cc

Issue 9958152: Consolidate win/x dispatchers (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: sync Created 8 years, 8 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 | Annotate | Revision Log
OLDNEW
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/root_window_host_linux.h" 5 #include "ui/aura/root_window_host_linux.h"
6 6
7 #include <X11/cursorfont.h> 7 #include <X11/cursorfont.h>
8 #include <X11/extensions/XInput2.h> 8 #include <X11/extensions/XInput2.h>
9 #include <X11/extensions/Xfixes.h> 9 #include <X11/extensions/Xfixes.h>
10 #include <X11/extensions/Xrandr.h> 10 #include <X11/extensions/Xrandr.h>
(...skipping 339 matching lines...) Expand 10 before | Expand all | Expand 10 after
350 UnConfineCursor(); 350 UnConfineCursor();
351 351
352 XDestroyWindow(xdisplay_, xwindow_); 352 XDestroyWindow(xdisplay_, xwindow_);
353 353
354 // Clears XCursorCache. 354 // Clears XCursorCache.
355 ui::GetXCursor(ui::kCursorClearXCursorCache); 355 ui::GetXCursor(ui::kCursorClearXCursorCache);
356 356
357 XFreeCursor(xdisplay_, invisible_cursor_); 357 XFreeCursor(xdisplay_, invisible_cursor_);
358 } 358 }
359 359
360 base::MessagePumpDispatcher::DispatchStatus RootWindowHostLinux::Dispatch( 360 bool RootWindowHostLinux::Dispatch(const base::NativeEvent& event) {
361 XEvent* xev) { 361 XEvent* xev = event;
362 bool handled = false;
363 362
364 // See crbug.com/109884. 363 // See crbug.com/109884.
365 // CheckXEventForConsistency(xev); 364 // CheckXEventForConsistency(xev);
366 365
367 switch (xev->type) { 366 switch (xev->type) {
368 case Expose: 367 case Expose:
369 root_window_->ScheduleFullDraw(); 368 root_window_->ScheduleFullDraw();
370 handled = true;
371 break; 369 break;
372 case KeyPress: { 370 case KeyPress: {
373 KeyEvent keydown_event(xev, false); 371 KeyEvent keydown_event(xev, false);
374 handled = root_window_->DispatchKeyEvent(&keydown_event); 372 root_window_->DispatchKeyEvent(&keydown_event);
375 break; 373 break;
376 } 374 }
377 case KeyRelease: { 375 case KeyRelease: {
378 KeyEvent keyup_event(xev, false); 376 KeyEvent keyup_event(xev, false);
379 handled = root_window_->DispatchKeyEvent(&keyup_event); 377 root_window_->DispatchKeyEvent(&keyup_event);
380 break; 378 break;
381 } 379 }
382 case ButtonPress: 380 case ButtonPress:
383 case ButtonRelease: { 381 case ButtonRelease: {
384 MouseEvent mouseev(xev); 382 MouseEvent mouseev(xev);
385 handled = root_window_->DispatchMouseEvent(&mouseev); 383 root_window_->DispatchMouseEvent(&mouseev);
386 break; 384 break;
387 } 385 }
388 case FocusOut: 386 case FocusOut:
389 if (xev->xfocus.mode != NotifyGrab) 387 if (xev->xfocus.mode != NotifyGrab)
390 root_window_->SetCapture(NULL); 388 root_window_->SetCapture(NULL);
391 break; 389 break;
392 case ConfigureNotify: { 390 case ConfigureNotify: {
393 DCHECK_EQ(xwindow_, xev->xconfigure.window); 391 DCHECK_EQ(xwindow_, xev->xconfigure.window);
394 DCHECK_EQ(xwindow_, xev->xconfigure.event); 392 DCHECK_EQ(xwindow_, xev->xconfigure.event);
395 // Update barrier and mouse location when the root window has 393 // Update barrier and mouse location when the root window has
396 // moved/resized. 394 // moved/resized.
397 if (pointer_barriers_.get()) { 395 if (pointer_barriers_.get()) {
398 UnConfineCursor(); 396 UnConfineCursor();
399 gfx::Point p = root_window_->last_mouse_location(); 397 gfx::Point p = root_window_->last_mouse_location();
400 XWarpPointer(xdisplay_, None, xwindow_, 0, 0, 0, 0, p.x(), p.y()); 398 XWarpPointer(xdisplay_, None, xwindow_, 0, 0, 0, 0, p.x(), p.y());
401 ConfineCursorToRootWindow(); 399 ConfineCursorToRootWindow();
402 } 400 }
403 // It's possible that the X window may be resized by some other means than 401 // It's possible that the X window may be resized by some other means than
404 // from within aura (e.g. the X window manager can change the size). Make 402 // from within aura (e.g. the X window manager can change the size). Make
405 // sure the root window size is maintained properly. 403 // sure the root window size is maintained properly.
406 gfx::Rect bounds(xev->xconfigure.x, xev->xconfigure.y, 404 gfx::Rect bounds(xev->xconfigure.x, xev->xconfigure.y,
407 xev->xconfigure.width, xev->xconfigure.height); 405 xev->xconfigure.width, xev->xconfigure.height);
408 bool size_changed = bounds_.size() != bounds.size(); 406 bool size_changed = bounds_.size() != bounds.size();
409 bounds_ = bounds; 407 bounds_ = bounds;
410 if (size_changed) 408 if (size_changed)
411 root_window_->OnHostResized(bounds.size()); 409 root_window_->OnHostResized(bounds.size());
412 handled = true;
413 break; 410 break;
414 } 411 }
415 case GenericEvent: { 412 case GenericEvent: {
416 ui::TouchFactory* factory = ui::TouchFactory::GetInstance(); 413 ui::TouchFactory* factory = ui::TouchFactory::GetInstance();
417 if (!factory->ShouldProcessXI2Event(xev)) 414 if (!factory->ShouldProcessXI2Event(xev))
418 break; 415 break;
419 416
420 ui::EventType type = ui::EventTypeFromNative(xev); 417 ui::EventType type = ui::EventTypeFromNative(xev);
421 // If this is a motion event we want to coalesce all pending motion 418 // If this is a motion event we want to coalesce all pending motion
422 // events that are at the top of the queue. 419 // events that are at the top of the queue.
423 XEvent last_event; 420 XEvent last_event;
424 int num_coalesced = 0; 421 int num_coalesced = 0;
425 422
426 switch (type) { 423 switch (type) {
427 case ui::ET_TOUCH_PRESSED: 424 case ui::ET_TOUCH_PRESSED:
428 case ui::ET_TOUCH_RELEASED: 425 case ui::ET_TOUCH_RELEASED:
429 case ui::ET_TOUCH_MOVED: { 426 case ui::ET_TOUCH_MOVED: {
430 TouchEvent touchev(xev); 427 TouchEvent touchev(xev);
431 handled = root_window_->DispatchTouchEvent(&touchev); 428 root_window_->DispatchTouchEvent(&touchev);
432 break; 429 break;
433 } 430 }
434 case ui::ET_MOUSE_MOVED: 431 case ui::ET_MOUSE_MOVED:
435 case ui::ET_MOUSE_DRAGGED: { 432 case ui::ET_MOUSE_DRAGGED: {
436 // If this is a motion event we want to coalesce all pending motion 433 // If this is a motion event we want to coalesce all pending motion
437 // events that are at the top of the queue. 434 // events that are at the top of the queue.
438 num_coalesced = CoalescePendingXIMotionEvents(xev, &last_event); 435 num_coalesced = CoalescePendingXIMotionEvents(xev, &last_event);
439 if (num_coalesced > 0) 436 if (num_coalesced > 0)
440 xev = &last_event; 437 xev = &last_event;
441 } 438 }
442 case ui::ET_MOUSE_PRESSED: 439 case ui::ET_MOUSE_PRESSED:
443 case ui::ET_MOUSE_RELEASED: 440 case ui::ET_MOUSE_RELEASED:
444 case ui::ET_MOUSEWHEEL: 441 case ui::ET_MOUSEWHEEL:
445 case ui::ET_MOUSE_ENTERED: 442 case ui::ET_MOUSE_ENTERED:
446 case ui::ET_MOUSE_EXITED: { 443 case ui::ET_MOUSE_EXITED: {
447 MouseEvent mouseev(xev); 444 MouseEvent mouseev(xev);
448 handled = root_window_->DispatchMouseEvent(&mouseev); 445 root_window_->DispatchMouseEvent(&mouseev);
449 break; 446 break;
450 } 447 }
451 case ui::ET_SCROLL_FLING_START: 448 case ui::ET_SCROLL_FLING_START:
452 case ui::ET_SCROLL_FLING_CANCEL: 449 case ui::ET_SCROLL_FLING_CANCEL:
453 case ui::ET_SCROLL: { 450 case ui::ET_SCROLL: {
454 ScrollEvent scrollev(xev); 451 ScrollEvent scrollev(xev);
455 handled = root_window_->DispatchScrollEvent(&scrollev); 452 root_window_->DispatchScrollEvent(&scrollev);
456 break; 453 break;
457 } 454 }
458 case ui::ET_UNKNOWN: 455 case ui::ET_UNKNOWN:
459 handled = false;
460 break; 456 break;
461 default: 457 default:
462 NOTREACHED(); 458 NOTREACHED();
463 } 459 }
464 460
465 // If we coalesced an event we need to free its cookie. 461 // If we coalesced an event we need to free its cookie.
466 if (num_coalesced > 0) 462 if (num_coalesced > 0)
467 XFreeEventData(xev->xgeneric.display, &last_event.xcookie); 463 XFreeEventData(xev->xgeneric.display, &last_event.xcookie);
468 break; 464 break;
469 } 465 }
470 case MapNotify: { 466 case MapNotify: {
471 // If there's no window manager running, we need to assign the X input 467 // If there's no window manager running, we need to assign the X input
472 // focus to our host window. 468 // focus to our host window.
473 if (!IsWindowManagerPresent() && focus_when_shown_) 469 if (!IsWindowManagerPresent() && focus_when_shown_)
474 XSetInputFocus(xdisplay_, xwindow_, RevertToNone, CurrentTime); 470 XSetInputFocus(xdisplay_, xwindow_, RevertToNone, CurrentTime);
475 handled = true;
476 break; 471 break;
477 } 472 }
478 case ClientMessage: { 473 case ClientMessage: {
479 Atom message_type = static_cast<Atom>(xev->xclient.data.l[0]); 474 Atom message_type = static_cast<Atom>(xev->xclient.data.l[0]);
480 if (message_type == wm_delete_window_atom_) { 475 if (message_type == wm_delete_window_atom_) {
481 // We have received a close message from the window manager. 476 // We have received a close message from the window manager.
482 root_window_->OnRootWindowHostClosed(); 477 root_window_->OnRootWindowHostClosed();
483 handled = true;
484 } 478 }
485 break; 479 break;
486 } 480 }
487 case MappingNotify: { 481 case MappingNotify: {
488 switch (xev->xmapping.request) { 482 switch (xev->xmapping.request) {
489 case MappingModifier: 483 case MappingModifier:
490 case MappingKeyboard: 484 case MappingKeyboard:
491 XRefreshKeyboardMapping(&xev->xmapping); 485 XRefreshKeyboardMapping(&xev->xmapping);
492 root_window_->OnKeyboardMappingChanged(); 486 root_window_->OnKeyboardMappingChanged();
493 break; 487 break;
(...skipping 18 matching lines...) Expand all
512 next_event.xmotion.subwindow == xev->xmotion.subwindow && 506 next_event.xmotion.subwindow == xev->xmotion.subwindow &&
513 next_event.xmotion.state == xev->xmotion.state) { 507 next_event.xmotion.state == xev->xmotion.state) {
514 XNextEvent(xev->xany.display, &last_event); 508 XNextEvent(xev->xany.display, &last_event);
515 xev = &last_event; 509 xev = &last_event;
516 } else { 510 } else {
517 break; 511 break;
518 } 512 }
519 } 513 }
520 514
521 MouseEvent mouseev(xev); 515 MouseEvent mouseev(xev);
522 handled = root_window_->DispatchMouseEvent(&mouseev); 516 root_window_->DispatchMouseEvent(&mouseev);
523 break; 517 break;
524 } 518 }
525 } 519 }
526 return handled ? base::MessagePumpDispatcher::EVENT_PROCESSED : 520 return true;
527 base::MessagePumpDispatcher::EVENT_IGNORED;
528 } 521 }
529 522
530 void RootWindowHostLinux::SetRootWindow(RootWindow* root_window) { 523 void RootWindowHostLinux::SetRootWindow(RootWindow* root_window) {
531 root_window_ = root_window; 524 root_window_ = root_window;
532 } 525 }
533 526
534 gfx::AcceleratedWidget RootWindowHostLinux::GetAcceleratedWidget() { 527 gfx::AcceleratedWidget RootWindowHostLinux::GetAcceleratedWidget() {
535 return xwindow_; 528 return xwindow_;
536 } 529 }
537 530
(...skipping 189 matching lines...) Expand 10 before | Expand all | Expand 10 after
727 return new RootWindowHostLinux(bounds); 720 return new RootWindowHostLinux(bounds);
728 } 721 }
729 722
730 // static 723 // static
731 gfx::Size RootWindowHost::GetNativeScreenSize() { 724 gfx::Size RootWindowHost::GetNativeScreenSize() {
732 ::Display* xdisplay = base::MessagePumpX::GetDefaultXDisplay(); 725 ::Display* xdisplay = base::MessagePumpX::GetDefaultXDisplay();
733 return gfx::Size(DisplayWidth(xdisplay, 0), DisplayHeight(xdisplay, 0)); 726 return gfx::Size(DisplayWidth(xdisplay, 0), DisplayHeight(xdisplay, 0));
734 } 727 }
735 728
736 } // namespace aura 729 } // namespace aura
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698