| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright 2009, Google Inc. | 2 * Copyright 2009, Google Inc. |
| 3 * All rights reserved. | 3 * All rights reserved. |
| 4 * | 4 * |
| 5 * Redistribution and use in source and binary forms, with or without | 5 * Redistribution and use in source and binary forms, with or without |
| 6 * modification, are permitted provided that the following conditions are | 6 * modification, are permitted provided that the following conditions are |
| 7 * met: | 7 * met: |
| 8 * | 8 * |
| 9 * * Redistributions of source code must retain the above copyright | 9 * * Redistributions of source code must retain the above copyright |
| 10 * notice, this list of conditions and the following disclaimer. | 10 * notice, this list of conditions and the following disclaimer. |
| (...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 70 if (!obj->draw_) return; | 70 if (!obj->draw_) return; |
| 71 // Don't allow re-entrant rendering (can happen in Chrome) | 71 // Don't allow re-entrant rendering (can happen in Chrome) |
| 72 if (obj->client()->IsRendering()) return; | 72 if (obj->client()->IsRendering()) return; |
| 73 obj->client()->RenderClient(true); | 73 obj->client()->RenderClient(true); |
| 74 obj->draw_ = false; | 74 obj->draw_ = false; |
| 75 } | 75 } |
| 76 | 76 |
| 77 // Xt support functions | 77 // Xt support functions |
| 78 | 78 |
| 79 void LinuxTimer(XtPointer data, XtIntervalId* id) { | 79 void LinuxTimer(XtPointer data, XtIntervalId* id) { |
| 80 HANDLE_CRASHES; |
| 80 PluginObject *obj = static_cast<PluginObject *>(data); | 81 PluginObject *obj = static_cast<PluginObject *>(data); |
| 81 DCHECK(obj->xt_interval_ == *id); | 82 DCHECK(obj->xt_interval_ == *id); |
| 82 obj->client()->Tick(); | 83 obj->client()->Tick(); |
| 83 obj->draw_ = true; | 84 obj->draw_ = true; |
| 84 if (obj->renderer()) { | 85 if (obj->renderer()) { |
| 85 if (obj->client()->NeedsRender()) { | 86 if (obj->client()->NeedsRender()) { |
| 86 // NOTE: this draws no matter what instead of just invalidating the | 87 // NOTE: this draws no matter what instead of just invalidating the |
| 87 // region, which means it will execute even if the plug-in window is | 88 // region, which means it will execute even if the plug-in window is |
| 88 // invisible. | 89 // invisible. |
| 89 DrawPlugin(obj); | 90 DrawPlugin(obj); |
| 90 } | 91 } |
| 91 } | 92 } |
| 92 obj->xt_interval_ = | 93 obj->xt_interval_ = |
| 93 XtAppAddTimeOut(obj->xt_app_context_, 8, LinuxTimer, obj); | 94 XtAppAddTimeOut(obj->xt_app_context_, 8, LinuxTimer, obj); |
| 94 } | 95 } |
| 95 | 96 |
| 96 void LinuxExposeHandler(Widget w, | 97 void LinuxExposeHandler(Widget w, |
| 97 XtPointer user_data, | 98 XtPointer user_data, |
| 98 XEvent *event, | 99 XEvent *event, |
| 99 Boolean *cont) { | 100 Boolean *cont) { |
| 101 HANDLE_CRASHES; |
| 100 PluginObject *obj = static_cast<PluginObject *>(user_data); | 102 PluginObject *obj = static_cast<PluginObject *>(user_data); |
| 101 if (event->type != Expose) return; | 103 if (event->type != Expose) return; |
| 102 DrawPlugin(obj); | 104 DrawPlugin(obj); |
| 103 } | 105 } |
| 104 | 106 |
| 105 static int KeySymToDOMKeyCode(KeySym key_sym) { | 107 static int KeySymToDOMKeyCode(KeySym key_sym) { |
| 106 // See https://developer.mozilla.org/en/DOM/Event/UIEvent/KeyEvent for the | 108 // See https://developer.mozilla.org/en/DOM/Event/UIEvent/KeyEvent for the |
| 107 // DOM values. | 109 // DOM values. |
| 108 // X keycodes are not useful, because they describe the geometry, not the | 110 // X keycodes are not useful, because they describe the geometry, not the |
| 109 // associated symbol, so a 'Q' on a QWERTY (US) keyboard has the same keycode | 111 // associated symbol, so a 'Q' on a QWERTY (US) keyboard has the same keycode |
| (...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 245 if (x_state & Mod2Mask) { | 247 if (x_state & Mod2Mask) { |
| 246 modifier_state |= Event::MODIFIER_META; | 248 modifier_state |= Event::MODIFIER_META; |
| 247 } | 249 } |
| 248 return modifier_state; | 250 return modifier_state; |
| 249 } | 251 } |
| 250 | 252 |
| 251 void LinuxKeyHandler(Widget w, | 253 void LinuxKeyHandler(Widget w, |
| 252 XtPointer user_data, | 254 XtPointer user_data, |
| 253 XEvent *xevent, | 255 XEvent *xevent, |
| 254 Boolean *cont) { | 256 Boolean *cont) { |
| 257 HANDLE_CRASHES; |
| 255 PluginObject *obj = static_cast<PluginObject *>(user_data); | 258 PluginObject *obj = static_cast<PluginObject *>(user_data); |
| 256 XKeyEvent *key_event = &xevent->xkey; | 259 XKeyEvent *key_event = &xevent->xkey; |
| 257 Event::Type type; | 260 Event::Type type; |
| 258 switch (xevent->type) { | 261 switch (xevent->type) { |
| 259 case KeyPress: | 262 case KeyPress: |
| 260 type = Event::TYPE_KEYDOWN; | 263 type = Event::TYPE_KEYDOWN; |
| 261 break; | 264 break; |
| 262 case KeyRelease: | 265 case KeyRelease: |
| 263 type = Event::TYPE_KEYUP; | 266 type = Event::TYPE_KEYUP; |
| 264 break; | 267 break; |
| (...skipping 19 matching lines...) Expand all Loading... |
| 284 | 287 |
| 285 // TODO: Any way to query the system for the correct value ? According to | 288 // TODO: Any way to query the system for the correct value ? According to |
| 286 // http://library.gnome.org/devel/gdk/stable/gdk-Event-Structures.html GTK uses | 289 // http://library.gnome.org/devel/gdk/stable/gdk-Event-Structures.html GTK uses |
| 287 // 250ms. | 290 // 250ms. |
| 288 const unsigned int kDoubleClickTime = 250; // in ms | 291 const unsigned int kDoubleClickTime = 250; // in ms |
| 289 | 292 |
| 290 void LinuxMouseButtonHandler(Widget w, | 293 void LinuxMouseButtonHandler(Widget w, |
| 291 XtPointer user_data, | 294 XtPointer user_data, |
| 292 XEvent *xevent, | 295 XEvent *xevent, |
| 293 Boolean *cont) { | 296 Boolean *cont) { |
| 297 HANDLE_CRASHES; |
| 294 PluginObject *obj = static_cast<PluginObject *>(user_data); | 298 PluginObject *obj = static_cast<PluginObject *>(user_data); |
| 295 XButtonEvent *button_event = &xevent->xbutton; | 299 XButtonEvent *button_event = &xevent->xbutton; |
| 296 Event::Type type; | 300 Event::Type type; |
| 297 switch (xevent->type) { | 301 switch (xevent->type) { |
| 298 case ButtonPress: | 302 case ButtonPress: |
| 299 type = Event::TYPE_MOUSEDOWN; | 303 type = Event::TYPE_MOUSEDOWN; |
| 300 break; | 304 break; |
| 301 case ButtonRelease: | 305 case ButtonRelease: |
| 302 type = Event::TYPE_MOUSEUP; | 306 type = Event::TYPE_MOUSEUP; |
| 303 break; | 307 break; |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 342 } else { | 346 } else { |
| 343 obj->set_last_click_time(button_event->time); | 347 obj->set_last_click_time(button_event->time); |
| 344 } | 348 } |
| 345 } | 349 } |
| 346 } | 350 } |
| 347 | 351 |
| 348 void LinuxMouseMoveHandler(Widget w, | 352 void LinuxMouseMoveHandler(Widget w, |
| 349 XtPointer user_data, | 353 XtPointer user_data, |
| 350 XEvent *xevent, | 354 XEvent *xevent, |
| 351 Boolean *cont) { | 355 Boolean *cont) { |
| 356 HANDLE_CRASHES; |
| 352 PluginObject *obj = static_cast<PluginObject *>(user_data); | 357 PluginObject *obj = static_cast<PluginObject *>(user_data); |
| 353 if (xevent->type != MotionNotify) | 358 if (xevent->type != MotionNotify) |
| 354 return; | 359 return; |
| 355 XMotionEvent *motion_event = &xevent->xmotion; | 360 XMotionEvent *motion_event = &xevent->xmotion; |
| 356 Event event(Event::TYPE_MOUSEMOVE); | 361 Event event(Event::TYPE_MOUSEMOVE); |
| 357 int modifier_state = GetXModifierState(motion_event->state); | 362 int modifier_state = GetXModifierState(motion_event->state); |
| 358 event.set_modifier_state(modifier_state); | 363 event.set_modifier_state(modifier_state); |
| 359 event.set_position(motion_event->x, motion_event->y, | 364 event.set_position(motion_event->x, motion_event->y, |
| 360 motion_event->x_root, motion_event->y_root, | 365 motion_event->x_root, motion_event->y_root, |
| 361 obj->in_plugin()); | 366 obj->in_plugin()); |
| 362 obj->client()->AddEventToQueue(event); | 367 obj->client()->AddEventToQueue(event); |
| 363 } | 368 } |
| 364 | 369 |
| 365 void LinuxEnterLeaveHandler(Widget w, | 370 void LinuxEnterLeaveHandler(Widget w, |
| 366 XtPointer user_data, | 371 XtPointer user_data, |
| 367 XEvent *xevent, | 372 XEvent *xevent, |
| 368 Boolean *cont) { | 373 Boolean *cont) { |
| 374 HANDLE_CRASHES; |
| 369 PluginObject *obj = static_cast<PluginObject *>(user_data); | 375 PluginObject *obj = static_cast<PluginObject *>(user_data); |
| 370 switch (xevent->type) { | 376 switch (xevent->type) { |
| 371 case EnterNotify: | 377 case EnterNotify: |
| 372 obj->set_in_plugin(true); | 378 obj->set_in_plugin(true); |
| 373 break; | 379 break; |
| 374 case LeaveNotify: | 380 case LeaveNotify: |
| 375 obj->set_in_plugin(false); | 381 obj->set_in_plugin(false); |
| 376 break; | 382 break; |
| 377 default: | 383 default: |
| 378 return; | 384 return; |
| (...skipping 167 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 546 static_cast<int>(scroll_event->x_root), | 552 static_cast<int>(scroll_event->x_root), |
| 547 static_cast<int>(scroll_event->y_root), | 553 static_cast<int>(scroll_event->y_root), |
| 548 obj->in_plugin()); | 554 obj->in_plugin()); |
| 549 obj->client()->AddEventToQueue(event); | 555 obj->client()->AddEventToQueue(event); |
| 550 return TRUE; | 556 return TRUE; |
| 551 } | 557 } |
| 552 | 558 |
| 553 static gboolean GtkEventCallback(GtkWidget *widget, | 559 static gboolean GtkEventCallback(GtkWidget *widget, |
| 554 GdkEvent *event, | 560 GdkEvent *event, |
| 555 gpointer user_data) { | 561 gpointer user_data) { |
| 562 HANDLE_CRASHES; |
| 556 PluginObject *obj = static_cast<PluginObject *>(user_data); | 563 PluginObject *obj = static_cast<PluginObject *>(user_data); |
| 557 DLOG_ASSERT(widget == obj->gtk_event_source_); | 564 DLOG_ASSERT(widget == obj->gtk_event_source_); |
| 558 switch (event->type) { | 565 switch (event->type) { |
| 559 case GDK_EXPOSE: | 566 case GDK_EXPOSE: |
| 560 if (GTK_WIDGET_DRAWABLE(widget)) { | 567 if (GTK_WIDGET_DRAWABLE(widget)) { |
| 561 obj->draw_ = true; | 568 obj->draw_ = true; |
| 562 DrawPlugin(obj); | 569 DrawPlugin(obj); |
| 563 } | 570 } |
| 564 return TRUE; | 571 return TRUE; |
| 565 case GDK_ENTER_NOTIFY: | 572 case GDK_ENTER_NOTIFY: |
| (...skipping 14 matching lines...) Expand all Loading... |
| 580 case GDK_SCROLL: | 587 case GDK_SCROLL: |
| 581 return GtkHandleScroll(widget, &event->scroll, obj); | 588 return GtkHandleScroll(widget, &event->scroll, obj); |
| 582 default: | 589 default: |
| 583 return FALSE; | 590 return FALSE; |
| 584 } | 591 } |
| 585 } | 592 } |
| 586 | 593 |
| 587 static gboolean GtkConfigureEventCallback(GtkWidget *widget, | 594 static gboolean GtkConfigureEventCallback(GtkWidget *widget, |
| 588 GdkEventConfigure *configure_event, | 595 GdkEventConfigure *configure_event, |
| 589 gpointer user_data) { | 596 gpointer user_data) { |
| 597 HANDLE_CRASHES; |
| 590 PluginObject *obj = static_cast<PluginObject *>(user_data); | 598 PluginObject *obj = static_cast<PluginObject *>(user_data); |
| 591 return obj->OnGtkConfigure(widget, configure_event); | 599 return obj->OnGtkConfigure(widget, configure_event); |
| 592 } | 600 } |
| 593 | 601 |
| 594 static gboolean GtkDeleteEventCallback(GtkWidget *widget, | 602 static gboolean GtkDeleteEventCallback(GtkWidget *widget, |
| 595 GdkEvent *event, | 603 GdkEvent *event, |
| 596 gpointer user_data) { | 604 gpointer user_data) { |
| 605 HANDLE_CRASHES; |
| 597 PluginObject *obj = static_cast<PluginObject *>(user_data); | 606 PluginObject *obj = static_cast<PluginObject *>(user_data); |
| 598 return obj->OnGtkDelete(widget, event); | 607 return obj->OnGtkDelete(widget, event); |
| 599 } | 608 } |
| 600 | 609 |
| 601 static gboolean GtkTimeoutCallback(gpointer user_data) { | 610 static gboolean GtkTimeoutCallback(gpointer user_data) { |
| 611 HANDLE_CRASHES; |
| 602 PluginObject *obj = static_cast<PluginObject *>(user_data); | 612 PluginObject *obj = static_cast<PluginObject *>(user_data); |
| 603 obj->draw_ = true; | 613 obj->draw_ = true; |
| 604 obj->client()->Tick(); | 614 obj->client()->Tick(); |
| 605 if (obj->renderer()) { | 615 if (obj->renderer()) { |
| 606 if (obj->client()->NeedsRender()) { | 616 if (obj->client()->NeedsRender()) { |
| 607 GtkWidget *widget; | 617 GtkWidget *widget; |
| 608 if (obj->fullscreen()) { | 618 if (obj->fullscreen()) { |
| 609 widget = obj->gtk_fullscreen_container_; | 619 widget = obj->gtk_fullscreen_container_; |
| 610 } else { | 620 } else { |
| 611 widget = obj->gtk_container_; | 621 widget = obj->gtk_container_; |
| (...skipping 340 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 952 client()->SendResizeEvent(renderer()->width(), renderer()->height(), | 962 client()->SendResizeEvent(renderer()->width(), renderer()->height(), |
| 953 false); | 963 false); |
| 954 SetGtkEventSource(gtk_container_); | 964 SetGtkEventSource(gtk_container_); |
| 955 gtk_widget_destroy(gtk_fullscreen_container_); | 965 gtk_widget_destroy(gtk_fullscreen_container_); |
| 956 gtk_fullscreen_container_ = NULL; | 966 gtk_fullscreen_container_ = NULL; |
| 957 fullscreen_window_ = 0; | 967 fullscreen_window_ = 0; |
| 958 fullscreen_ = false; | 968 fullscreen_ = false; |
| 959 } | 969 } |
| 960 } // namespace _o3d | 970 } // namespace _o3d |
| 961 } // namespace glue | 971 } // namespace glue |
| OLD | NEW |