| 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 234 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 245 [o3dLayer setNeedsDisplay]; | 245 [o3dLayer setNeedsDisplay]; |
| 246 } | 246 } |
| 247 return; | 247 return; |
| 248 } | 248 } |
| 249 | 249 |
| 250 ManageSafariTabSwitching(obj); | 250 ManageSafariTabSwitching(obj); |
| 251 obj->client()->Tick(); | 251 obj->client()->Tick(); |
| 252 | 252 |
| 253 bool in_fullscreen = obj->GetFullscreenMacWindow(); | 253 bool in_fullscreen = obj->GetFullscreenMacWindow(); |
| 254 | 254 |
| 255 #ifdef O3D_PLUGIN_ENABLE_FULLSCREEN_MSG | |
| 256 if (in_fullscreen) { | 255 if (in_fullscreen) { |
| 257 obj->FullscreenIdle(); | 256 obj->GetFullscreenMacWindow()->IdleCallback(); |
| 258 } | 257 } |
| 259 #endif | |
| 260 | 258 |
| 261 // We're visible if (a) we are in fullscreen mode, (b) our cliprect | 259 // We're visible if (a) we are in fullscreen mode, (b) our cliprect |
| 262 // height and width are both a sensible size, ie > 1 pixel, or (c) if | 260 // height and width are both a sensible size, ie > 1 pixel, or (c) if |
| 263 // we are rendering to render surfaces (CoreGraphics drawing model, | 261 // we are rendering to render surfaces (CoreGraphics drawing model, |
| 264 // essentially offscreen rendering). | 262 // essentially offscreen rendering). |
| 265 // | 263 // |
| 266 // We don't check for 0 as we have to size to 1 x 1 on occasion rather than | 264 // We don't check for 0 as we have to size to 1 x 1 on occasion rather than |
| 267 // 0 x 0 to avoid crashing the Apple software renderer, but do not want to | 265 // 0 x 0 to avoid crashing the Apple software renderer, but do not want to |
| 268 // actually draw to a 1 x 1 pixel area. | 266 // actually draw to a 1 x 1 pixel area. |
| 269 bool plugin_visible = in_fullscreen || | 267 bool plugin_visible = in_fullscreen || |
| (...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 363 } | 361 } |
| 364 } | 362 } |
| 365 CFReleaseIfNotNull(cfHFSPath); | 363 CFReleaseIfNotNull(cfHFSPath); |
| 366 CFReleaseIfNotNull(cfPosixPath); | 364 CFReleaseIfNotNull(cfPosixPath); |
| 367 CFReleaseIfNotNull(cfHFSURL); | 365 CFReleaseIfNotNull(cfHFSURL); |
| 368 return posix_path; | 366 return posix_path; |
| 369 } | 367 } |
| 370 | 368 |
| 371 | 369 |
| 372 | 370 |
| 373 // Convenience function for fetching SInt32 parameters from Carbon EventRefs. | |
| 374 static SInt32 GetIntEventParam(EventRef inEvent, EventParamName inName) { | |
| 375 SInt32 value = 0; | |
| 376 return (GetEventParameter(inEvent, inName, typeSInt32, NULL, sizeof(value), | |
| 377 NULL, &value) == noErr) ? value : 0; | |
| 378 } | |
| 379 | |
| 380 | |
| 381 #pragma mark ____OVERLAY_WINDOW | |
| 382 | |
| 383 #ifdef O3D_PLUGIN_ENABLE_FULLSCREEN_MSG | |
| 384 | |
| 385 // A little wrapper for ATSUSetAttributes to make calling it with one attribute | |
| 386 // less annoying. | |
| 387 static void MySetAttribute(ATSUStyle style, | |
| 388 ATSUAttributeTag tag, | |
| 389 ByteCount size, | |
| 390 ATSUAttributeValuePtr value) { | |
| 391 | |
| 392 ATSUAttributeTag tags[2] = {tag, 0}; | |
| 393 ByteCount sizes[2] = {size, 0}; | |
| 394 ATSUAttributeValuePtr values[2] = {value, 0}; | |
| 395 | |
| 396 ATSUSetAttributes(style, 1, tags, sizes, values); | |
| 397 } | |
| 398 | |
| 399 // A little wrapper for ATSUSetLayoutControls to make calling it with one | |
| 400 // attribute less annoying. | |
| 401 static void MySetLayoutControl(ATSUTextLayout layout, | |
| 402 ATSUAttributeTag tag, | |
| 403 ByteCount size, | |
| 404 ATSUAttributeValuePtr value) { | |
| 405 | |
| 406 ATSUAttributeTag tags[2] = {tag, 0}; | |
| 407 ByteCount sizes[2] = {size, 0}; | |
| 408 ATSUAttributeValuePtr values[2] = {value, 0}; | |
| 409 | |
| 410 ATSUSetLayoutControls(layout, 1, tags, sizes, values); | |
| 411 } | |
| 412 | |
| 413 // Returns the unicode 16 chars that we need to display as the fullscreen | |
| 414 // message. Should be disposed with free() after use. | |
| 415 static UniChar * GetFullscreenDisplayText(int *returned_length) { | |
| 416 // TODO this will need to be a localized string. | |
| 417 NSString* ns_display_text = @"Press ESC to exit fullscreen"; | |
| 418 int count = [ns_display_text length]; | |
| 419 UniChar* display_text_16 = (UniChar*) calloc(count, sizeof(UniChar)); | |
| 420 | |
| 421 [ns_display_text getCharacters:display_text_16]; | |
| 422 *returned_length = count; | |
| 423 return display_text_16; | |
| 424 } | |
| 425 | |
| 426 | |
| 427 static void DrawToOverlayWindow(WindowRef overlayWindow) { | |
| 428 CGContextRef overlayContext = NULL; | |
| 429 CGFloat kWhiteOpaque[] = {1.0, 1.0, 1.0, 1.0}; | |
| 430 CGFloat kBlackNotOpaque[] = {0.0, 0.0, 0.0, 0.5}; | |
| 431 Rect bounds = {0, 0, 0, 0}; | |
| 432 const char* kOverlayWindowFontName = "Arial"; | |
| 433 const int kPointSize = 22; | |
| 434 const float kShadowRadius = 5.0; | |
| 435 const float kRoundRectRadius = 9.0; | |
| 436 const float kTextLeftMargin = 15.0; | |
| 437 const float kTextBottomMargin = 22.0; | |
| 438 | |
| 439 QDBeginCGContext(GetWindowPort(overlayWindow), &overlayContext); | |
| 440 GetWindowBounds(overlayWindow, kWindowContentRgn, &bounds); | |
| 441 | |
| 442 // Make the global rect local. | |
| 443 bounds.right -= bounds.left; | |
| 444 bounds.left = 0; | |
| 445 bounds.bottom -= bounds.top; | |
| 446 bounds.top = 0; | |
| 447 | |
| 448 CGRect cgTotalRect = Rect2CGRect(bounds); | |
| 449 CGContextSetShouldSmoothFonts(overlayContext, true); | |
| 450 CGContextClearRect(overlayContext, cgTotalRect); | |
| 451 | |
| 452 CGColorSpaceRef myColorSpace = CGColorSpaceCreateDeviceRGB(); | |
| 453 CGColorRef shadow = CGColorCreate(myColorSpace, kBlackNotOpaque); | |
| 454 CGColorRef roundRectBackColor = CGColorCreate(myColorSpace, kBlackNotOpaque); | |
| 455 CGSize shadowOffset = {0.0,0.0}; | |
| 456 | |
| 457 CGContextSetFillColor(overlayContext, kWhiteOpaque); | |
| 458 CGContextSetStrokeColor(overlayContext, kWhiteOpaque); | |
| 459 | |
| 460 // Draw the round rect background. | |
| 461 CGContextSaveGState(overlayContext); | |
| 462 CGContextSetFillColorWithColor(overlayContext, roundRectBackColor); | |
| 463 CGRect cg_rounded_area = | |
| 464 CGRectMake(// Offset from left and bottom to give shadow its space. | |
| 465 kShadowRadius, kShadowRadius, | |
| 466 // Increase width and height so rounded corners | |
| 467 // will be clipped out, except at bottom left. | |
| 468 (bounds.right - bounds.left) + 30, | |
| 469 (bounds.bottom - bounds.top) + 30); | |
| 470 // Save state before applying shadow. | |
| 471 CGContextSetShadowWithColor(overlayContext, shadowOffset, | |
| 472 kShadowRadius, shadow); | |
| 473 PaintRoundedCGRect(overlayContext, cg_rounded_area, kRoundRectRadius, true); | |
| 474 // Restore graphics state to remove shadow. | |
| 475 CGContextRestoreGState(overlayContext); | |
| 476 | |
| 477 // Draw the text. | |
| 478 int text_length = 0; | |
| 479 UniChar* display_text = GetFullscreenDisplayText(&text_length); | |
| 480 | |
| 481 if ((text_length > 0) && (display_text != NULL)) { | |
| 482 ATSUStyle style; | |
| 483 ATSUTextLayout layout; | |
| 484 ATSUFontID font; | |
| 485 Fixed pointSize = Long2Fix(kPointSize); | |
| 486 Boolean is_bold = true; | |
| 487 | |
| 488 ATSUCreateStyle(&style); | |
| 489 ATSUFindFontFromName(kOverlayWindowFontName, strlen(kOverlayWindowFontName), | |
| 490 kFontFullName, kFontNoPlatformCode, kFontNoScriptCode, | |
| 491 kFontNoLanguageCode, &font); | |
| 492 | |
| 493 MySetAttribute(style, kATSUFontTag, sizeof(font), &font); | |
| 494 MySetAttribute(style, kATSUSizeTag, sizeof(pointSize), &pointSize); | |
| 495 MySetAttribute(style, kATSUQDBoldfaceTag, sizeof(Boolean), &is_bold); | |
| 496 | |
| 497 | |
| 498 ATSUCreateTextLayout(&layout); | |
| 499 ATSUSetTextPointerLocation(layout, display_text, | |
| 500 kATSUFromTextBeginning, kATSUToTextEnd, | |
| 501 text_length); | |
| 502 ATSUSetRunStyle(layout, style, kATSUFromTextBeginning, kATSUToTextEnd); | |
| 503 | |
| 504 MySetLayoutControl(layout, kATSUCGContextTag, | |
| 505 sizeof(CGContextRef), &overlayContext); | |
| 506 | |
| 507 // Need to enable this for languages like Japanese to draw as something | |
| 508 // other than a series of squares. | |
| 509 ATSUSetTransientFontMatching(layout, true); | |
| 510 | |
| 511 | |
| 512 CGContextSetFillColor(overlayContext, kWhiteOpaque); | |
| 513 ATSUDrawText(layout, kATSUFromTextBeginning, kATSUToTextEnd, | |
| 514 X2Fix(kShadowRadius + kTextLeftMargin), | |
| 515 X2Fix(kShadowRadius + kTextBottomMargin)); | |
| 516 ATSUDisposeStyle(style); | |
| 517 ATSUDisposeTextLayout(layout); | |
| 518 free(display_text); | |
| 519 } | |
| 520 | |
| 521 CGColorRelease(roundRectBackColor); | |
| 522 CGColorRelease(shadow); | |
| 523 CGColorSpaceRelease (myColorSpace); | |
| 524 | |
| 525 QDEndCGContext(GetWindowPort(overlayWindow), &overlayContext); | |
| 526 } | |
| 527 | |
| 528 static OSStatus HandleOverlayWindow(EventHandlerCallRef inHandlerCallRef, | |
| 529 EventRef inEvent, | |
| 530 void *inUserData) { | |
| 531 OSType event_class = GetEventClass(inEvent); | |
| 532 OSType event_kind = GetEventKind(inEvent); | |
| 533 | |
| 534 if (event_class == kEventClassWindow && | |
| 535 event_kind == kEventWindowPaint) { | |
| 536 WindowRef theWindow = NULL; | |
| 537 GetEventParameter(inEvent, kEventParamDirectObject, | |
| 538 typeWindowRef, NULL, | |
| 539 sizeof(theWindow), NULL, | |
| 540 &theWindow); | |
| 541 if (theWindow) { | |
| 542 CallNextEventHandler(inHandlerCallRef, inEvent); | |
| 543 DrawToOverlayWindow(theWindow); | |
| 544 } | |
| 545 } | |
| 546 | |
| 547 return noErr; | |
| 548 } | |
| 549 | |
| 550 | |
| 551 | |
| 552 static Rect GetOverlayWindowRect(bool visible) { | |
| 553 #define kOverlayHeight 60 | |
| 554 #define kOverlayWidth 340 | |
| 555 Rect screen_bounds = CGRect2Rect(CGDisplayBounds(CGMainDisplayID())); | |
| 556 Rect hidden_window_bounds = {screen_bounds.top - kOverlayHeight, | |
| 557 screen_bounds.right - kOverlayWidth, | |
| 558 screen_bounds.top, | |
| 559 screen_bounds.right}; | |
| 560 Rect visible_window_bounds = {screen_bounds.top, | |
| 561 screen_bounds.right - kOverlayWidth, | |
| 562 screen_bounds.top + kOverlayHeight, | |
| 563 screen_bounds.right}; | |
| 564 | |
| 565 return (visible) ? visible_window_bounds : hidden_window_bounds; | |
| 566 } | |
| 567 | |
| 568 | |
| 569 static WindowRef CreateOverlayWindow(void) { | |
| 570 Rect window_bounds = GetOverlayWindowRect(false); | |
| 571 WindowClass wClass = kOverlayWindowClass; | |
| 572 WindowRef window = NULL; | |
| 573 OSStatus err = noErr; | |
| 574 WindowAttributes overlayAttributes = kWindowNoShadowAttribute | | |
| 575 kWindowIgnoreClicksAttribute | | |
| 576 kWindowNoActivatesAttribute | | |
| 577 kWindowStandardHandlerAttribute; | |
| 578 EventTypeSpec eventTypes[] = { | |
| 579 {kEventClassWindow, kEventWindowPaint}, | |
| 580 {kEventClassWindow, kEventWindowShown} | |
| 581 }; | |
| 582 | |
| 583 err = CreateNewWindow(wClass, | |
| 584 overlayAttributes, | |
| 585 &window_bounds, | |
| 586 &window); | |
| 587 if (err) | |
| 588 return NULL; | |
| 589 | |
| 590 SetWindowLevel(window, CGShieldingWindowLevel() + 1); | |
| 591 InstallEventHandler(GetWindowEventTarget(window), HandleOverlayWindow, | |
| 592 sizeof(eventTypes)/sizeof(eventTypes[0]), eventTypes, | |
| 593 NULL, NULL); | |
| 594 ShowWindow(window); | |
| 595 | |
| 596 return window; | |
| 597 } | |
| 598 | |
| 599 #endif // O3D_PLUGIN_ENABLE_FULLSCREEN_MSG | |
| 600 | |
| 601 | |
| 602 // Maps the MacOS button numbers to the constants used by our | |
| 603 // event mechanism. Not quite as obvious as you might think, as the Mac | |
| 604 // thinks the numbering should go left, right, middle and our W3C-influenced | |
| 605 // system goes left, middle, right. | |
| 606 // Defaults to left-button if passed a strange value. Pass Cocoa mouse button | |
| 607 // codes as-is (they start at 0), pass Carbon button codes - 1. | |
| 608 o3d::Event::Button MacOSMouseButtonNumberToO3DButton(int inButton) { | |
| 609 | |
| 610 switch(inButton) { | |
| 611 case 0: | |
| 612 return o3d::Event::BUTTON_LEFT; | |
| 613 case 1: | |
| 614 return o3d::Event::BUTTON_RIGHT; | |
| 615 case 2: | |
| 616 return o3d::Event::BUTTON_MIDDLE; | |
| 617 case 3: | |
| 618 return o3d::Event::BUTTON_4; | |
| 619 case 4: | |
| 620 return o3d::Event::BUTTON_5; | |
| 621 } | |
| 622 | |
| 623 return o3d::Event::BUTTON_LEFT; | |
| 624 } | |
| 625 | |
| 626 | |
| 627 #pragma mark ____FULLSCREEN_WINDOW | |
| 628 | |
| 629 | |
| 630 // Handles the CarbonEvents that we get sent for the fullscreen mode window. | |
| 631 // Most of these can be converted to EventRecord events and handled by the | |
| 632 // HandleMacEvent() function in main_mac.mm, but some have no equivalent in | |
| 633 // that space, scroll-wheel events for example, and so must be handled here. | |
| 634 static OSStatus HandleFullscreenWindow(EventHandlerCallRef inHandlerCallRef, | |
| 635 EventRef inEvent, | |
| 636 void *inUserData) { | |
| 637 OSType event_class = GetEventClass(inEvent); | |
| 638 OSType event_kind = GetEventKind(inEvent); | |
| 639 NPP instance = (NPP)inUserData; | |
| 640 PluginObject* obj = (PluginObject*)(instance->pdata); | |
| 641 HIPoint mouse_loc = { 0.0, 0.0 }; | |
| 642 bool is_scroll_event = event_class == kEventClassMouse && | |
| 643 (event_kind == kEventMouseScroll || | |
| 644 event_kind == kEventMouseWheelMoved); | |
| 645 | |
| 646 // If it's any kind of mouse event, get the global mouse loc. | |
| 647 if (event_class == kEventClassMouse) { | |
| 648 GetEventParameter(inEvent, kEventParamMouseLocation, | |
| 649 typeHIPoint, NULL, | |
| 650 sizeof(mouse_loc), NULL, | |
| 651 &mouse_loc); | |
| 652 } | |
| 653 | |
| 654 // Handle the two kinds of scroll message we understand. | |
| 655 if (is_scroll_event) { | |
| 656 SInt32 x_scroll = 0; | |
| 657 SInt32 y_scroll = 0; | |
| 658 EventMouseWheelAxis axis = kEventMouseWheelAxisY; | |
| 659 | |
| 660 switch (event_kind) { | |
| 661 // The newer kind of scroll event, as sent when two-finger | |
| 662 // dragging on a touchpad. | |
| 663 case kEventMouseScroll: | |
| 664 x_scroll = GetIntEventParam(inEvent, | |
| 665 kEventParamMouseWheelSmoothHorizontalDelta); | |
| 666 y_scroll = GetIntEventParam(inEvent, | |
| 667 kEventParamMouseWheelSmoothVerticalDelta); | |
| 668 | |
| 669 // only pass x or y value - pass whichever is larger | |
| 670 if (x_scroll && y_scroll) { | |
| 671 if (abs(x_scroll) > abs(y_scroll)) | |
| 672 y_scroll = 0; | |
| 673 else | |
| 674 x_scroll = 0; | |
| 675 } | |
| 676 break; | |
| 677 // The older kind of scroll event, as sent when using the wheel on | |
| 678 // a third-party mouse. | |
| 679 case kEventMouseWheelMoved: | |
| 680 GetEventParameter(inEvent, kEventParamMouseWheelAxis, | |
| 681 typeMouseWheelAxis, NULL, | |
| 682 sizeof(axis), NULL, | |
| 683 &axis); | |
| 684 | |
| 685 if (axis == kEventMouseWheelAxisY) { | |
| 686 y_scroll = GetIntEventParam(inEvent, | |
| 687 kEventParamMouseWheelDelta); | |
| 688 } else { | |
| 689 x_scroll = GetIntEventParam(inEvent, | |
| 690 kEventParamMouseWheelDelta); | |
| 691 } | |
| 692 break; | |
| 693 } | |
| 694 | |
| 695 // Dispatch the event now that we have all the data. | |
| 696 if (x_scroll || y_scroll) { | |
| 697 o3d::Event event(o3d::Event::TYPE_WHEEL); | |
| 698 event.set_delta(x_scroll, y_scroll); | |
| 699 // Global and local locs are the same, in this case, | |
| 700 // as we have a fullscreen window at 0,0. | |
| 701 event.set_position(mouse_loc.x, mouse_loc.y, | |
| 702 mouse_loc.x, mouse_loc.y, true); | |
| 703 obj->client()->AddEventToQueue(event); | |
| 704 } | |
| 705 return noErr; | |
| 706 } else if (event_class == kEventClassMouse && | |
| 707 (event_kind == kEventMouseDown || event_kind == kEventMouseUp)) { | |
| 708 | |
| 709 o3d::Event::Type type = (event_kind == kEventMouseDown) ? | |
| 710 o3d::Event::TYPE_MOUSEDOWN : | |
| 711 o3d::Event::TYPE_MOUSEUP; | |
| 712 o3d::Event event(type); | |
| 713 event.set_position(mouse_loc.x, mouse_loc.y, | |
| 714 mouse_loc.x, mouse_loc.y, true); | |
| 715 | |
| 716 EventMouseButton button = 0; | |
| 717 GetEventParameter(inEvent, kEventParamMouseButton, | |
| 718 typeMouseButton, NULL, | |
| 719 sizeof(button), NULL, | |
| 720 &button); | |
| 721 // Carbon mouse button numbers start at 1, so subtract 1 here - | |
| 722 // Cocoa mouse buttons, by contrast, start at 0). | |
| 723 event.set_button(MacOSMouseButtonNumberToO3DButton(button - 1)); | |
| 724 | |
| 725 // add the modifiers to the event, if any | |
| 726 UInt32 carbonMods = GetIntEventParam(inEvent, | |
| 727 kEventParamKeyModifiers); | |
| 728 if (carbonMods) { | |
| 729 int modifier_state = 0; | |
| 730 if (carbonMods & controlKey) { | |
| 731 modifier_state |= o3d::Event::MODIFIER_CTRL; | |
| 732 } | |
| 733 if (carbonMods & shiftKey) { | |
| 734 modifier_state |= o3d::Event::MODIFIER_SHIFT; | |
| 735 } | |
| 736 if (carbonMods & optionKey) { | |
| 737 modifier_state |= o3d::Event::MODIFIER_ALT; | |
| 738 } | |
| 739 if (carbonMods & cmdKey) { | |
| 740 modifier_state |= o3d::Event::MODIFIER_META; | |
| 741 } | |
| 742 | |
| 743 event.set_modifier_state(modifier_state); | |
| 744 } | |
| 745 | |
| 746 obj->client()->AddEventToQueue(event); | |
| 747 } else { // not a scroll event or a click | |
| 748 | |
| 749 // All other events are currently handled by being converted to an | |
| 750 // old-style EventRecord as passed by the classic NPAPI interface | |
| 751 // and dispatched through our common routine. | |
| 752 EventRecord eventRecord; | |
| 753 | |
| 754 if (ConvertEventRefToEventRecord(inEvent, &eventRecord)) { | |
| 755 HandleMacEvent(&eventRecord, (NPP)inUserData); | |
| 756 return noErr; | |
| 757 } else { | |
| 758 return eventNotHandledErr; | |
| 759 } | |
| 760 } | |
| 761 return noErr; | |
| 762 } | |
| 763 | |
| 764 | |
| 765 static WindowRef CreateFullscreenWindow(WindowRef window, | |
| 766 PluginObject *obj, | |
| 767 int mode_id) { | |
| 768 Rect bounds = CGRect2Rect(CGDisplayBounds(CGMainDisplayID())); | |
| 769 OSStatus err = noErr; | |
| 770 EventTypeSpec eventTypes[] = { | |
| 771 {kEventClassKeyboard, kEventRawKeyDown}, | |
| 772 {kEventClassKeyboard, kEventRawKeyRepeat}, | |
| 773 {kEventClassKeyboard, kEventRawKeyUp}, | |
| 774 {kEventClassMouse, kEventMouseDown}, | |
| 775 {kEventClassMouse, kEventMouseUp}, | |
| 776 {kEventClassMouse, kEventMouseMoved}, | |
| 777 {kEventClassMouse, kEventMouseDragged}, | |
| 778 {kEventClassMouse, kEventMouseScroll}, | |
| 779 {kEventClassMouse, kEventMouseWheelMoved} | |
| 780 }; | |
| 781 | |
| 782 if (window == NULL) | |
| 783 err = CreateNewWindow(kSimpleWindowClass, | |
| 784 kWindowStandardHandlerAttribute, | |
| 785 &bounds, | |
| 786 &window); | |
| 787 if (err) | |
| 788 return NULL; | |
| 789 | |
| 790 SetWindowLevel(window, CGShieldingWindowLevel() + 1); | |
| 791 | |
| 792 InstallEventHandler(GetWindowEventTarget(window), HandleFullscreenWindow, | |
| 793 sizeof(eventTypes)/sizeof(eventTypes[0]), eventTypes, | |
| 794 obj->npp(), NULL); | |
| 795 ShowWindow(window); | |
| 796 return window; | |
| 797 } | |
| 798 | |
| 799 void CleanupFullscreenWindow(PluginObject *obj) { | |
| 800 WindowRef fs_window = obj->GetFullscreenMacWindow(); | |
| 801 #ifdef O3D_PLUGIN_ENABLE_FULLSCREEN_MSG | |
| 802 WindowRef fs_o_window = obj->GetFullscreenOverlayMacWindow(); | |
| 803 #endif | |
| 804 | |
| 805 obj->SetFullscreenMacWindow(NULL); | |
| 806 #ifdef O3D_PLUGIN_ENABLE_FULLSCREEN_MSG | |
| 807 obj->SetFullscreenOverlayMacWindow(NULL); | |
| 808 #endif | |
| 809 | |
| 810 if (fs_window) { | |
| 811 HideWindow(fs_window); | |
| 812 ReleaseWindowGroup(GetWindowGroup(fs_window)); | |
| 813 DisposeWindow(fs_window); | |
| 814 } | |
| 815 | |
| 816 #ifdef O3D_PLUGIN_ENABLE_FULLSCREEN_MSG | |
| 817 if(fs_o_window) { | |
| 818 HideWindow(fs_o_window); | |
| 819 ReleaseWindowGroup(GetWindowGroup(fs_o_window)); | |
| 820 DisposeWindow(fs_o_window); | |
| 821 } | |
| 822 #endif | |
| 823 } | |
| 824 | |
| 825 #pragma mark ____SCREEN_RESOLUTION_MANAGEMENT | 371 #pragma mark ____SCREEN_RESOLUTION_MANAGEMENT |
| 826 | 372 |
| 827 | 373 |
| 828 // Constant kO3D_MODE_OFFSET is added to the position in the array returned by | 374 // Constant kO3D_MODE_OFFSET is added to the position in the array returned by |
| 829 // CGDisplayAvailableModes to make it an ID. This makes IDs distinguishable from | 375 // CGDisplayAvailableModes to make it an ID. This makes IDs distinguishable from |
| 830 // array positions when debugging, and also means that ID 0 can have a special | 376 // array positions when debugging, and also means that ID 0 can have a special |
| 831 // meaning (current mode) rather than meaning the first resolution in the list. | 377 // meaning (current mode) rather than meaning the first resolution in the list. |
| 832 const int kO3D_MODE_OFFSET = 100; | 378 const int kO3D_MODE_OFFSET = 100; |
| 833 | 379 |
| 834 // Extracts data from the Core Graphics screen mode data passed in. | 380 // Extracts data from the Core Graphics screen mode data passed in. |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 882 | 428 |
| 883 return false; | 429 return false; |
| 884 } | 430 } |
| 885 | 431 |
| 886 | 432 |
| 887 static int GetCGDisplayModeID(NSDictionary* mode_dict) { | 433 static int GetCGDisplayModeID(NSDictionary* mode_dict) { |
| 888 return [[mode_dict valueForKey:@"Mode"] intValue]; | 434 return [[mode_dict valueForKey:@"Mode"] intValue]; |
| 889 } | 435 } |
| 890 | 436 |
| 891 // Returns DisplayMode data for the current state of the main display. | 437 // Returns DisplayMode data for the current state of the main display. |
| 892 static void GetCurrentDisplayMode(o3d::DisplayMode *mode) { | 438 void GetCurrentDisplayMode(o3d::DisplayMode *mode) { |
| 893 int width = 0; | 439 int width = 0; |
| 894 int height = 0; | 440 int height = 0; |
| 895 int refresh_rate = 0; | 441 int refresh_rate = 0; |
| 896 int bpp = 0; | 442 int bpp = 0; |
| 897 int mode_id = 0; | 443 int mode_id = 0; |
| 898 | 444 |
| 899 NSDictionary* current_mode = | 445 NSDictionary* current_mode = |
| 900 (NSDictionary*)CGDisplayCurrentMode(CGMainDisplayID()); | 446 (NSDictionary*)CGDisplayCurrentMode(CGMainDisplayID()); |
| 901 | 447 |
| 902 // To get the O3D mode id of the current mode, we need to find it in the list | 448 // To get the O3D mode id of the current mode, we need to find it in the list |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 955 modes_found.push_back(o3d::DisplayMode(width, height, refresh_rate, | 501 modes_found.push_back(o3d::DisplayMode(width, height, refresh_rate, |
| 956 i + o3d::kO3D_MODE_OFFSET)); | 502 i + o3d::kO3D_MODE_OFFSET)); |
| 957 } | 503 } |
| 958 | 504 |
| 959 modes->swap(modes_found); | 505 modes->swap(modes_found); |
| 960 } | 506 } |
| 961 | 507 |
| 962 | 508 |
| 963 #pragma mark ____FULLSCREEN_SWITCHING | 509 #pragma mark ____FULLSCREEN_SWITCHING |
| 964 | 510 |
| 965 #define kTransitionTime 1.0 | |
| 966 | |
| 967 namespace glue { | 511 namespace glue { |
| 968 namespace _o3d { | 512 namespace _o3d { |
| 969 | 513 |
| 970 bool PluginObject::RequestFullscreenDisplay() { | 514 bool PluginObject::RequestFullscreenDisplay() { |
| 971 // If already in fullscreen mode, do nothing. | 515 // If already in fullscreen mode, do nothing. |
| 972 if (GetFullscreenMacWindow()) | 516 if (GetFullscreenMacWindow()) |
| 973 return false; | 517 return false; |
| 974 | 518 |
| 975 int target_width = 0; | 519 int target_width = 0; |
| 976 int target_height = 0; | 520 int target_height = 0; |
| 977 | 521 |
| 978 if (fullscreen_region_valid_ && | 522 if (fullscreen_region_valid_ && |
| 979 fullscreen_region_mode_id_ != Renderer::DISPLAY_MODE_DEFAULT) { | 523 fullscreen_region_mode_id_ != Renderer::DISPLAY_MODE_DEFAULT) { |
| 980 o3d::DisplayMode the_mode; | 524 o3d::DisplayMode the_mode; |
| 981 if (GetDisplayMode(fullscreen_region_mode_id_, &the_mode)) { | 525 if (GetDisplayMode(fullscreen_region_mode_id_, &the_mode)) { |
| 982 target_width = the_mode.width(); | 526 target_width = the_mode.width(); |
| 983 target_height = the_mode.height(); | 527 target_height = the_mode.height(); |
| 984 } | 528 } |
| 985 } | 529 } |
| 986 | 530 |
| 987 // check which mode we are in now | 531 FullscreenWindowMac* fullscreen_window = |
| 988 o3d::DisplayMode current_mode; | 532 FullscreenWindowMac::Create(this, target_width, target_height); |
| 989 GetCurrentDisplayMode(¤t_mode); | 533 SetFullscreenMacWindow(fullscreen_window); |
| 534 Rect bounds = o3d::CGRect2Rect(fullscreen_window->GetWindowBounds()); |
| 990 | 535 |
| 991 WindowRef fullscreen_window = NULL; | |
| 992 | |
| 993 // Determine if screen mode switching is actually required. | |
| 994 if (target_width != 0 && | |
| 995 target_height != 0 && | |
| 996 target_width != current_mode.width() && | |
| 997 target_height != current_mode.height()) { | |
| 998 short short_target_width = target_width; | |
| 999 short short_target_height = target_height; | |
| 1000 BeginFullScreen(&mac_fullscreen_state_, | |
| 1001 nil, // Value of nil selects the main screen. | |
| 1002 &short_target_width, | |
| 1003 &short_target_height, | |
| 1004 &fullscreen_window, | |
| 1005 NULL, | |
| 1006 fullScreenCaptureAllDisplays); | |
| 1007 } else { | |
| 1008 SetSystemUIMode(kUIModeAllSuppressed, kUIOptionAutoShowMenuBar); | |
| 1009 mac_fullscreen_state_ = NULL; | |
| 1010 } | |
| 1011 | |
| 1012 SetFullscreenMacWindow(o3d::CreateFullscreenWindow( | |
| 1013 NULL, | |
| 1014 this, | |
| 1015 fullscreen_region_mode_id_)); | |
| 1016 Rect bounds = {0,0,0,0}; | |
| 1017 GetWindowBounds(GetFullscreenMacWindow(), kWindowContentRgn, &bounds); | |
| 1018 | |
| 1019 o3d::SetWindowForAGLContext(mac_agl_context_, GetFullscreenMacWindow()); | |
| 1020 aglDisable(mac_agl_context_, AGL_BUFFER_RECT); | |
| 1021 renderer()->SetClientOriginOffset(0, 0); | 536 renderer()->SetClientOriginOffset(0, 0); |
| 1022 renderer_->Resize(bounds.right - bounds.left, bounds.bottom - bounds.top); | 537 renderer_->Resize(bounds.right - bounds.left, bounds.bottom - bounds.top); |
| 1023 | 538 |
| 1024 fullscreen_ = true; | 539 fullscreen_ = true; |
| 1025 client()->SendResizeEvent(renderer_->width(), renderer_->height(), true); | 540 client()->SendResizeEvent(renderer_->width(), renderer_->height(), true); |
| 1026 | 541 |
| 1027 #ifdef O3D_PLUGIN_ENABLE_FULLSCREEN_MSG | |
| 1028 SetFullscreenOverlayMacWindow(o3d::CreateOverlayWindow()); | |
| 1029 ShowWindow(mac_fullscreen_overlay_window_); | |
| 1030 o3d::SlideWindowToRect(mac_fullscreen_overlay_window_, | |
| 1031 o3d::Rect2CGRect(o3d::GetOverlayWindowRect(true)), | |
| 1032 kTransitionTime); | |
| 1033 | |
| 1034 // Hide the overlay text 4 seconds from now. | |
| 1035 time_to_hide_overlay_ = [NSDate timeIntervalSinceReferenceDate] + 4.0; | |
| 1036 #endif | |
| 1037 | |
| 1038 return true; | 542 return true; |
| 1039 } | 543 } |
| 1040 | 544 |
| 1041 void PluginObject::CancelFullscreenDisplay() { | 545 void PluginObject::CancelFullscreenDisplay() { |
| 1042 // if not in fullscreen mode, do nothing | 546 // if not in fullscreen mode, do nothing |
| 1043 if (!GetFullscreenMacWindow()) | 547 if (!GetFullscreenMacWindow()) |
| 1044 return; | 548 return; |
| 1045 | 549 |
| 1046 o3d::SetWindowForAGLContext(mac_agl_context_, mac_window_); | 550 GetFullscreenMacWindow()->Shutdown(last_buffer_rect_); |
| 1047 | 551 SetFullscreenMacWindow(NULL); |
| 1048 o3d::CleanupFullscreenWindow(this); | |
| 1049 | |
| 1050 renderer_->Resize(prev_width_, prev_height_); | 552 renderer_->Resize(prev_width_, prev_height_); |
| 1051 aglSetInteger(mac_agl_context_, AGL_BUFFER_RECT, last_buffer_rect_); | |
| 1052 aglEnable(mac_agl_context_, AGL_BUFFER_RECT); | |
| 1053 | |
| 1054 if (mac_fullscreen_state_) { | |
| 1055 EndFullScreen(mac_fullscreen_state_, 0); | |
| 1056 mac_fullscreen_state_ = NULL; | |
| 1057 } else { | |
| 1058 SetSystemUIMode(kUIModeNormal, 0); | |
| 1059 } | |
| 1060 fullscreen_ = false; | 553 fullscreen_ = false; |
| 1061 client()->SendResizeEvent(prev_width_, prev_height_, false); | 554 client()->SendResizeEvent(prev_width_, prev_height_, false); |
| 1062 | 555 |
| 1063 | |
| 1064 // Somehow the browser window does not automatically activate again | 556 // Somehow the browser window does not automatically activate again |
| 1065 // when we close the fullscreen window, so explicitly reactivate it. | 557 // when we close the fullscreen window, so explicitly reactivate it. |
| 1066 if (mac_cocoa_window_) { | 558 if (mac_cocoa_window_) { |
| 1067 NSWindow* browser_window = (NSWindow*) mac_cocoa_window_; | 559 NSWindow* browser_window = (NSWindow*) mac_cocoa_window_; |
| 1068 [browser_window makeKeyAndOrderFront:browser_window]; | 560 [browser_window makeKeyAndOrderFront:browser_window]; |
| 1069 } else if (mac_window_) { | 561 } else if (mac_window_) { |
| 1070 SelectWindow(mac_window_); | 562 SelectWindow(mac_window_); |
| 1071 } | 563 } |
| 1072 } | 564 } |
| 1073 | 565 |
| 1074 #ifdef O3D_PLUGIN_ENABLE_FULLSCREEN_MSG | |
| 1075 void PluginObject::FullscreenIdle() { | |
| 1076 if ((mac_fullscreen_overlay_window_ != NULL) && | |
| 1077 (time_to_hide_overlay_ != 0.0) && | |
| 1078 (time_to_hide_overlay_ < [NSDate timeIntervalSinceReferenceDate])) { | |
| 1079 time_to_hide_overlay_ = 0.0; | |
| 1080 o3d::SlideWindowToRect(mac_fullscreen_overlay_window_, | |
| 1081 o3d::Rect2CGRect(o3d::GetOverlayWindowRect(false)), | |
| 1082 kTransitionTime); | |
| 1083 } | |
| 1084 } | |
| 1085 #endif | |
| 1086 | |
| 1087 } // namespace glue | 566 } // namespace glue |
| 1088 } // namespace o3d | 567 } // namespace o3d |
| OLD | NEW |