src/video/emscripten/SDL_emscriptenevents.c
changeset 10317 4a45690d5d82
parent 10316 76bcc22dc5e4
child 10318 7b9ae714c507
     1.1 --- a/src/video/emscripten/SDL_emscriptenevents.c	Mon Sep 12 23:58:08 2016 -0700
     1.2 +++ b/src/video/emscripten/SDL_emscriptenevents.c	Tue Sep 13 00:03:28 2016 -0700
     1.3 @@ -472,59 +472,19 @@
     1.4  EM_BOOL
     1.5  Emscripten_HandleFullscreenChange(int eventType, const EmscriptenFullscreenChangeEvent *fullscreenChangeEvent, void *userData)
     1.6  {
     1.7 -    /*make sure this is actually our element going fullscreen*/
     1.8 -    if(SDL_strcmp(fullscreenChangeEvent->id, "SDLFullscreenElement") != 0)
     1.9 -        return 0;
    1.10 -
    1.11      SDL_WindowData *window_data = userData;
    1.12      if(fullscreenChangeEvent->isFullscreen)
    1.13      {
    1.14          SDL_bool is_desktop_fullscreen;
    1.15          window_data->window->flags |= window_data->requested_fullscreen_mode;
    1.16  
    1.17 -        if(!window_data->requested_fullscreen_mode)
    1.18 -            window_data->window->flags |= SDL_WINDOW_FULLSCREEN_DESKTOP; /*we didn't reqest fullscreen*/
    1.19 -
    1.20          window_data->requested_fullscreen_mode = 0;
    1.21  
    1.22 -        is_desktop_fullscreen = (window_data->window->flags & SDL_WINDOW_FULLSCREEN_DESKTOP) == SDL_WINDOW_FULLSCREEN_DESKTOP;
    1.23 -
    1.24 -        /*update size*/
    1.25 -        if(window_data->window->flags & SDL_WINDOW_RESIZABLE || is_desktop_fullscreen)
    1.26 -        {
    1.27 -            emscripten_set_canvas_size(fullscreenChangeEvent->screenWidth, fullscreenChangeEvent->screenHeight);
    1.28 -            SDL_SendWindowEvent(window_data->window, SDL_WINDOWEVENT_RESIZED, fullscreenChangeEvent->screenWidth, fullscreenChangeEvent->screenHeight);
    1.29 -        }
    1.30 -        else
    1.31 -        {
    1.32 -            /*preserve ratio*/
    1.33 -            double w = window_data->window->w;
    1.34 -            double h = window_data->window->h;
    1.35 -            double factor = SDL_min(fullscreenChangeEvent->screenWidth / w, fullscreenChangeEvent->screenHeight / h);
    1.36 -            emscripten_set_element_css_size(NULL, w * factor, h * factor);
    1.37 -        }
    1.38 +        if(!window_data->requested_fullscreen_mode)
    1.39 +            window_data->window->flags |= SDL_WINDOW_FULLSCREEN; /*we didn't reqest fullscreen*/
    1.40      }
    1.41      else
    1.42      {
    1.43 -        EM_ASM({
    1.44 -            //un-reparent canvas (similar to Module.requestFullscreen)
    1.45 -            var canvas = Module['canvas'];
    1.46 -            if(canvas.parentNode.id == "SDLFullscreenElement") {
    1.47 -                var canvasContainer = canvas.parentNode;
    1.48 -                canvasContainer.parentNode.insertBefore(canvas, canvasContainer);
    1.49 -                canvasContainer.parentNode.removeChild(canvasContainer);
    1.50 -            }
    1.51 -        });
    1.52 -        double unscaled_w = window_data->windowed_width / window_data->pixel_ratio;
    1.53 -        double unscaled_h = window_data->windowed_height / window_data->pixel_ratio;
    1.54 -        emscripten_set_canvas_size(window_data->windowed_width, window_data->windowed_height);
    1.55 -
    1.56 -        if (!window_data->external_size && window_data->pixel_ratio != 1.0f) {
    1.57 -            emscripten_set_element_css_size(NULL, unscaled_w, unscaled_h);
    1.58 -        }
    1.59 -
    1.60 -        SDL_SendWindowEvent(window_data->window, SDL_WINDOWEVENT_RESIZED, unscaled_w, unscaled_h);
    1.61 -
    1.62          window_data->window->flags &= ~FULLSCREEN_MASK;
    1.63      }
    1.64  
    1.65 @@ -535,17 +495,7 @@
    1.66  Emscripten_HandleResize(int eventType, const EmscriptenUiEvent *uiEvent, void *userData)
    1.67  {
    1.68      SDL_WindowData *window_data = userData;
    1.69 -    if(window_data->window->flags & FULLSCREEN_MASK)
    1.70 -    {
    1.71 -        SDL_bool is_desktop_fullscreen = (window_data->window->flags & SDL_WINDOW_FULLSCREEN_DESKTOP) == SDL_WINDOW_FULLSCREEN_DESKTOP;
    1.72 -
    1.73 -        if(window_data->window->flags & SDL_WINDOW_RESIZABLE || is_desktop_fullscreen)
    1.74 -        {
    1.75 -            emscripten_set_canvas_size(uiEvent->windowInnerWidth * window_data->pixel_ratio, uiEvent->windowInnerHeight * window_data->pixel_ratio);
    1.76 -            SDL_SendWindowEvent(window_data->window, SDL_WINDOWEVENT_RESIZED, uiEvent->windowInnerWidth, uiEvent->windowInnerHeight);
    1.77 -        }
    1.78 -    }
    1.79 -    else
    1.80 +    if(!(window_data->window->flags & FULLSCREEN_MASK))
    1.81      {
    1.82          /* this will only work if the canvas size is set through css */
    1.83          if(window_data->window->flags & SDL_WINDOW_RESIZABLE)
    1.84 @@ -572,6 +522,22 @@
    1.85  }
    1.86  
    1.87  EM_BOOL
    1.88 +Emscripten_HandleCanvasResize(int eventType, const void *reserved, void *userData)
    1.89 +{
    1.90 +    /*this is used during fullscreen changes*/
    1.91 +    SDL_WindowData *window_data = userData;
    1.92 +
    1.93 +    if(window_data->fullscreen_resize)
    1.94 +    {
    1.95 +        double css_w, css_h;
    1.96 +        emscripten_get_element_css_size(NULL, &css_w, &css_h);
    1.97 +        SDL_SendWindowEvent(window_data->window, SDL_WINDOWEVENT_RESIZED, css_w, css_h);
    1.98 +    }
    1.99 +
   1.100 +    return 0;
   1.101 +}
   1.102 +
   1.103 +EM_BOOL
   1.104  Emscripten_HandleVisibilityChange(int eventType, const EmscriptenVisibilityChangeEvent *visEvent, void *userData)
   1.105  {
   1.106      SDL_WindowData *window_data = userData;