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 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
49 #include "core/cross/event.h" | 49 #include "core/cross/event.h" |
50 #include "statsreport/metrics.h" | 50 #include "statsreport/metrics.h" |
51 #include "plugin/cross/config.h" | 51 #include "plugin/cross/config.h" |
52 #include "plugin/cross/plugin_logging.h" | 52 #include "plugin/cross/plugin_logging.h" |
53 #include "plugin/cross/plugin_metrics.h" | 53 #include "plugin/cross/plugin_metrics.h" |
54 #include "plugin/cross/o3d_glue.h" | 54 #include "plugin/cross/o3d_glue.h" |
55 #include "plugin/cross/out_of_memory.h" | 55 #include "plugin/cross/out_of_memory.h" |
56 #include "plugin/cross/whitelist.h" | 56 #include "plugin/cross/whitelist.h" |
57 #include "plugin/mac/plugin_mac.h" | 57 #include "plugin/mac/plugin_mac.h" |
58 #include "plugin/mac/graphics_utils_mac.h" | 58 #include "plugin/mac/graphics_utils_mac.h" |
| 59 #include "plugin/mac/fullscreen_window_mac.h" |
59 #import "plugin/mac/o3d_layer.h" | 60 #import "plugin/mac/o3d_layer.h" |
60 | 61 |
61 | 62 |
62 #if !defined(O3D_INTERNAL_PLUGIN) | 63 #if !defined(O3D_INTERNAL_PLUGIN) |
63 o3d::PluginLogging* g_logger = NULL; | 64 o3d::PluginLogging* g_logger = NULL; |
64 bool g_logging_initialized = false; | 65 bool g_logging_initialized = false; |
65 #endif | 66 #endif |
66 | 67 |
67 using glue::_o3d::PluginObject; | 68 using glue::_o3d::PluginObject; |
68 using glue::StreamManager; | 69 using glue::StreamManager; |
69 using o3d::Bitmap; | 70 using o3d::Bitmap; |
70 using o3d::DisplayWindowMac; | 71 using o3d::DisplayWindowMac; |
71 using o3d::Event; | 72 using o3d::Event; |
| 73 using o3d::FullscreenWindowMac; |
72 using o3d::Renderer; | 74 using o3d::Renderer; |
73 | 75 |
74 namespace { | 76 namespace { |
75 // We would normally make this a stack variable in main(), but in a | 77 // We would normally make this a stack variable in main(), but in a |
76 // plugin, that's not possible, so we make it a global. When the DLL is loaded | 78 // plugin, that's not possible, so we make it a global. When the DLL is loaded |
77 // this it gets constructed and when it is unlooaded it is destructed. Note | 79 // this it gets constructed and when it is unlooaded it is destructed. Note |
78 // that this cannot be done in NP_Initialize and NP_Shutdown because those | 80 // that this cannot be done in NP_Initialize and NP_Shutdown because those |
79 // calls do not necessarily signify the DLL being loaded and unloaded. If the | 81 // calls do not necessarily signify the DLL being loaded and unloaded. If the |
80 // DLL is not unloaded then the values of global variables are preserved. | 82 // DLL is not unloaded then the values of global variables are preserved. |
81 base::AtExitManager g_at_exit_manager; | 83 base::AtExitManager g_at_exit_manager; |
(...skipping 216 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
298 LOG(FATAL) << "Unknown mouse event: " << the_event->what; | 300 LOG(FATAL) << "Unknown mouse event: " << the_event->what; |
299 return; | 301 return; |
300 } | 302 } |
301 | 303 |
302 last_mouse_loc = the_event->where; | 304 last_mouse_loc = the_event->where; |
303 bool in_plugin = false; // Did the event happen within our drawing region? | 305 bool in_plugin = false; // Did the event happen within our drawing region? |
304 | 306 |
305 int x, y; | 307 int x, y; |
306 // now make x and y plugin relative coords | 308 // now make x and y plugin relative coords |
307 if (obj->GetFullscreenMacWindow()) { | 309 if (obj->GetFullscreenMacWindow()) { |
308 Rect wBounds; | 310 Rect wBounds = o3d::CGRect2Rect( |
309 GetWindowBounds(obj->GetFullscreenMacWindow(), kWindowGlobalPortRgn, | 311 obj->GetFullscreenMacWindow()->GetWindowBounds()); |
310 &wBounds); | |
311 x = screen_x - wBounds.left; | 312 x = screen_x - wBounds.left; |
312 y = screen_y - wBounds.top; | 313 y = screen_y - wBounds.top; |
313 in_plugin = true; | 314 in_plugin = true; |
314 } else { | 315 } else { |
315 Rect wBounds; | 316 Rect wBounds; |
316 GetWindowBounds(obj->mac_window_, kWindowGlobalPortRgn, &wBounds); | 317 GetWindowBounds(obj->mac_window_, kWindowGlobalPortRgn, &wBounds); |
317 x = screen_x - wBounds.left - obj->last_plugin_loc_.h; | 318 x = screen_x - wBounds.left - obj->last_plugin_loc_.h; |
318 y = screen_y - wBounds.top - obj->last_plugin_loc_.v; | 319 y = screen_y - wBounds.top - obj->last_plugin_loc_.v; |
319 in_plugin = x >=0 && y >= 0 && x < obj->width() && y < obj->height(); | 320 in_plugin = x >=0 && y >= 0 && x < obj->width() && y < obj->height(); |
320 } | 321 } |
(...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
463 } | 464 } |
464 | 465 |
465 // Handle an NPCocoaEvent style event. The Cocoa event interface is | 466 // Handle an NPCocoaEvent style event. The Cocoa event interface is |
466 // a recent addition to the NAPI spec. | 467 // a recent addition to the NAPI spec. |
467 // See https://wiki.mozilla.org/Mac:NPAPI_Event_Models for further details. | 468 // See https://wiki.mozilla.org/Mac:NPAPI_Event_Models for further details. |
468 // The principle advantages are that we can get scrollwheel messages, | 469 // The principle advantages are that we can get scrollwheel messages, |
469 // mouse-moved messages, and can tell which mouse button was pressed. | 470 // mouse-moved messages, and can tell which mouse button was pressed. |
470 // This API will also be required for a carbon-free 64 bit version for 10.6. | 471 // This API will also be required for a carbon-free 64 bit version for 10.6. |
471 bool HandleCocoaEvent(NPP instance, NPCocoaEvent* the_event) { | 472 bool HandleCocoaEvent(NPP instance, NPCocoaEvent* the_event) { |
472 PluginObject* obj = static_cast<PluginObject*>(instance->pdata); | 473 PluginObject* obj = static_cast<PluginObject*>(instance->pdata); |
473 WindowRef fullscreen_window = obj->GetFullscreenMacWindow(); | 474 FullscreenWindowMac* fullscreen_window = obj->GetFullscreenMacWindow(); |
474 bool handled = false; | 475 bool handled = false; |
475 | 476 |
476 if (g_logger) g_logger->UpdateLogging(); | 477 if (g_logger) g_logger->UpdateLogging(); |
477 | 478 |
478 obj->MacEventReceived(); | 479 obj->MacEventReceived(); |
479 switch (the_event->type) { | 480 switch (the_event->type) { |
480 case NPCocoaEventDrawRect: | 481 case NPCocoaEventDrawRect: |
481 // We need to call the render callback from here if we are rendering | 482 // We need to call the render callback from here if we are rendering |
482 // off-screen because it doesn't get called anywhere else. | 483 // off-screen because it doesn't get called anywhere else. |
483 if (obj->drawing_model_ == NPDrawingModelCoreAnimation) { | 484 if (obj->drawing_model_ == NPDrawingModelCoreAnimation) { |
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
545 obj->mac_surface_hidden_ = false; | 546 obj->mac_surface_hidden_ = false; |
546 NPN_ForceRedraw(instance); // invalidate to cause a redraw | 547 NPN_ForceRedraw(instance); // invalidate to cause a redraw |
547 } | 548 } |
548 | 549 |
549 // Auto-recovery for any situation where another window comes in front | 550 // Auto-recovery for any situation where another window comes in front |
550 // of the fullscreen window and we need to exit fullscreen mode. | 551 // of the fullscreen window and we need to exit fullscreen mode. |
551 // This can happen because another browser window has come forward, or | 552 // This can happen because another browser window has come forward, or |
552 // because another app has been called to the front. | 553 // because another app has been called to the front. |
553 // TODO: We'll have problems with this when dealing with e.g. | 554 // TODO: We'll have problems with this when dealing with e.g. |
554 // Japanese text input IME windows. | 555 // Japanese text input IME windows. |
555 if (fullscreen_window && fullscreen_window != ActiveNonFloatingWindow()) { | 556 if (fullscreen_window && !fullscreen_window->IsActive()) { |
556 obj->CancelFullscreenDisplay(); | 557 obj->CancelFullscreenDisplay(); |
557 } | 558 } |
558 | 559 |
559 break; | 560 break; |
560 case NPCocoaEventTextInput: | 561 case NPCocoaEventTextInput: |
561 break; | 562 break; |
562 } | 563 } |
563 | 564 |
564 return handled; | 565 return handled; |
565 } | 566 } |
(...skipping 273 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
839 default: | 840 default: |
840 return NPERR_INVALID_PARAM; | 841 return NPERR_INVALID_PARAM; |
841 } | 842 } |
842 | 843 |
843 return NPERR_INVALID_PARAM; | 844 return NPERR_INVALID_PARAM; |
844 } | 845 } |
845 | 846 |
846 bool HandleMacEvent(EventRecord* the_event, NPP instance) { | 847 bool HandleMacEvent(EventRecord* the_event, NPP instance) { |
847 PluginObject* obj = static_cast<PluginObject*>(instance->pdata); | 848 PluginObject* obj = static_cast<PluginObject*>(instance->pdata); |
848 bool handled = false; | 849 bool handled = false; |
849 WindowRef fullscreen_window = obj->GetFullscreenMacWindow(); | 850 FullscreenWindowMac* fullscreen_window = obj->GetFullscreenMacWindow(); |
850 | 851 |
851 if (g_logger) g_logger->UpdateLogging(); | 852 if (g_logger) g_logger->UpdateLogging(); |
852 | 853 |
853 // Help the plugin keep track of when we last saw an event so the CFTimer can | 854 // Help the plugin keep track of when we last saw an event so the CFTimer can |
854 // notice if we get cut off, eg by our tab being hidden by Safari, which there | 855 // notice if we get cut off, eg by our tab being hidden by Safari, which there |
855 // is no other way for us to detect. | 856 // is no other way for us to detect. |
856 obj->MacEventReceived(); | 857 obj->MacEventReceived(); |
857 | 858 |
858 switch (the_event->what) { | 859 switch (the_event->what) { |
859 case nullEvent: | 860 case nullEvent: |
(...skipping 10 matching lines...) Expand all Loading... |
870 // Safari tab switching recovery code. | 871 // Safari tab switching recovery code. |
871 if (obj->mac_surface_hidden_) { | 872 if (obj->mac_surface_hidden_) { |
872 obj->mac_surface_hidden_ = false; | 873 obj->mac_surface_hidden_ = false; |
873 NPN_ForceRedraw(instance); // invalidate to cause a redraw | 874 NPN_ForceRedraw(instance); // invalidate to cause a redraw |
874 } | 875 } |
875 | 876 |
876 // Auto-recovery for any situation where another window comes in front | 877 // Auto-recovery for any situation where another window comes in front |
877 // of the fullscreen window and we need to exit fullscreen mode. | 878 // of the fullscreen window and we need to exit fullscreen mode. |
878 // This can happen because another browser window has come forward, or | 879 // This can happen because another browser window has come forward, or |
879 // because another app has been called to the front. | 880 // because another app has been called to the front. |
880 if (fullscreen_window && fullscreen_window != ActiveNonFloatingWindow()) { | 881 if (fullscreen_window && !fullscreen_window->IsActive()) { |
881 obj->CancelFullscreenDisplay(); | 882 obj->CancelFullscreenDisplay(); |
882 } | 883 } |
883 | 884 |
884 // Send nullEvents to HandleMouseEvent so they can be used to simulate | 885 // Send nullEvents to HandleMouseEvent so they can be used to simulate |
885 // mouse moved events. Not needed in fullscreen mode, where we really do | 886 // mouse moved events. Not needed in fullscreen mode, where we really do |
886 // get mouse moved events. See the osEvt case below. | 887 // get mouse moved events. See the osEvt case below. |
887 if (!fullscreen_window) | 888 if (!fullscreen_window) |
888 HandleMouseEvent(obj, the_event); | 889 HandleMouseEvent(obj, the_event); |
889 | 890 |
890 handled = true; | 891 handled = true; |
(...skipping 473 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1364 if (obj->event_model_ == NPEventModelCarbon) { | 1365 if (obj->event_model_ == NPEventModelCarbon) { |
1365 EventRecord* theEvent = static_cast<EventRecord*>(event); | 1366 EventRecord* theEvent = static_cast<EventRecord*>(event); |
1366 return HandleMacEvent(theEvent, instance) ? 1 : 0; | 1367 return HandleMacEvent(theEvent, instance) ? 1 : 0; |
1367 } else if (obj->event_model_ == NPEventModelCocoa){ | 1368 } else if (obj->event_model_ == NPEventModelCocoa){ |
1368 return HandleCocoaEvent(instance, (NPCocoaEvent*)event) ? 1 : 0; | 1369 return HandleCocoaEvent(instance, (NPCocoaEvent*)event) ? 1 : 0; |
1369 } | 1370 } |
1370 return 0; | 1371 return 0; |
1371 } | 1372 } |
1372 | 1373 |
1373 } // namespace o3d | 1374 } // namespace o3d |
OLD | NEW |