| 1 |
|
|---|
| 2 |
|
|---|
| 3 |
|
|---|
| 4 |
|
|---|
| 5 |
|
|---|
| 6 |
|
|---|
| 7 |
|
|---|
| 8 |
|
|---|
| 9 |
|
|---|
| 10 |
|
|---|
| 11 |
|
|---|
| 12 |
|
|---|
| 13 |
|
|---|
| 14 |
|
|---|
| 15 |
|
|---|
| 16 |
|
|---|
| 17 |
|
|---|
| 18 |
|
|---|
| 19 |
|
|---|
| 20 |
|
|---|
| 21 |
|
|---|
| 22 |
|
|---|
| 23 |
|
|---|
| 24 |
|
|---|
| 25 |
|
|---|
| 26 |
|
|---|
| 27 |
|
|---|
| 28 |
#include "config.h" |
|---|
| 29 |
|
|---|
| 30 |
#include "GraphicsContext.h" |
|---|
| 31 |
#include "WebWindow.h" |
|---|
| 32 |
#include "WebView.h" |
|---|
| 33 |
#include "SDL/SDL.h" |
|---|
| 34 |
#include <signal.h> |
|---|
| 35 |
#include <unistd.h> |
|---|
| 36 |
|
|---|
| 37 |
using namespace WebCore; |
|---|
| 38 |
static bool quit = false; |
|---|
| 39 |
|
|---|
| 40 |
void WebWindow::createPlatformWindow() |
|---|
| 41 |
{ |
|---|
| 42 |
#if PLATFORM(SDLCAIRO) |
|---|
| 43 |
m_surface = cairo_image_surface_create_for_data ( |
|---|
| 44 |
(unsigned char*)m_mainSurface->pixels, |
|---|
| 45 |
CAIRO_FORMAT_ARGB32, |
|---|
| 46 |
m_mainSurface->w, |
|---|
| 47 |
m_mainSurface->h, |
|---|
| 48 |
m_mainSurface->pitch); |
|---|
| 49 |
#else |
|---|
| 50 |
Uint32 rmask, gmask, bmask, amask; |
|---|
| 51 |
rmask = 0x00ff0000; |
|---|
| 52 |
gmask = 0x0000ff00; |
|---|
| 53 |
bmask = 0x000000ff; |
|---|
| 54 |
amask = 0xff000000; |
|---|
| 55 |
m_surface = SDL_CreateRGBSurface(SDL_HWSURFACE | SDL_SRCALPHA, m_mainSurface->w, m_mainSurface->h, 32, |
|---|
| 56 |
rmask, gmask, bmask, amask); |
|---|
| 57 |
#endif |
|---|
| 58 |
} |
|---|
| 59 |
|
|---|
| 60 |
GraphicsContext* WebWindow::createContext() |
|---|
| 61 |
{ |
|---|
| 62 |
#if PLATFORM(SDLCAIRO) |
|---|
| 63 |
cairo_t* cr = cairo_create(m_surface); |
|---|
| 64 |
GraphicsContext *ctx = new GraphicsContext(cr); |
|---|
| 65 |
#else |
|---|
| 66 |
GraphicsContext *ctx = new GraphicsContext(m_surface); |
|---|
| 67 |
#endif |
|---|
| 68 |
return ctx; |
|---|
| 69 |
} |
|---|
| 70 |
|
|---|
| 71 |
void WebWindow::releaseContext(GraphicsContext* ctx) |
|---|
| 72 |
{ |
|---|
| 73 |
#if PLATFORM(SDLCAIRO) |
|---|
| 74 |
cairo_t* cr = ctx->platformContext(); |
|---|
| 75 |
cairo_destroy(cr); |
|---|
| 76 |
#endif |
|---|
| 77 |
delete ctx; |
|---|
| 78 |
} |
|---|
| 79 |
|
|---|
| 80 |
void WebWindow::updateRect(BalRectangle src, BalRectangle dest) |
|---|
| 81 |
{ |
|---|
| 82 |
#if !PLATFORM(SDLCAIRO) |
|---|
| 83 |
SDL_BlitSurface(m_surface, &src, m_mainSurface, &src); |
|---|
| 84 |
SDL_BlitSurface(m_mainSurface, &src, SDL_GetVideoSurface(), &dest); |
|---|
| 85 |
#else |
|---|
| 86 |
if (SDL_GetVideoSurface()->flags & SDL_DOUBLEBUF) |
|---|
| 87 |
SDL_Flip(SDL_GetVideoSurface()); |
|---|
| 88 |
else |
|---|
| 89 |
SDL_UpdateRect(SDL_GetVideoSurface(), dest.x, dest.y, dest.w, dest.h); |
|---|
| 90 |
#endif |
|---|
| 91 |
} |
|---|
| 92 |
|
|---|
| 93 |
static void quitCatcher(int) |
|---|
| 94 |
{ |
|---|
| 95 |
SDL_Quit(); |
|---|
| 96 |
exit(1); |
|---|
| 97 |
} |
|---|
| 98 |
|
|---|
| 99 |
void WebWindow::runMainLoop() |
|---|
| 100 |
{ |
|---|
| 101 |
quit = false; |
|---|
| 102 |
|
|---|
| 103 |
signal(SIGKILL, &quitCatcher); |
|---|
| 104 |
signal(SIGINT, &quitCatcher); |
|---|
| 105 |
signal(SIGTERM, &quitCatcher); |
|---|
| 106 |
|
|---|
| 107 |
SDL_Event event; |
|---|
| 108 |
while (!quit) { |
|---|
| 109 |
if (SDL_PollEvent(&event) != 0) |
|---|
| 110 |
{ |
|---|
| 111 |
switch (event.type) { |
|---|
| 112 |
case SDL_ACTIVEEVENT: |
|---|
| 113 |
{ |
|---|
| 114 |
SDL_ExposeEvent ev; |
|---|
| 115 |
memset(&ev, 0, sizeof(SDL_ExposeEvent)); |
|---|
| 116 |
BalRectangle rect = m_webView->frameRect(); |
|---|
| 117 |
onExpose(ev, rect); |
|---|
| 118 |
break; |
|---|
| 119 |
} |
|---|
| 120 |
case SDL_KEYDOWN: |
|---|
| 121 |
onKeyDown(event.key); |
|---|
| 122 |
break; |
|---|
| 123 |
case SDL_KEYUP: |
|---|
| 124 |
onKeyUp(event.key); |
|---|
| 125 |
break; |
|---|
| 126 |
case SDL_MOUSEMOTION: |
|---|
| 127 |
onMouseMotion(event.motion); |
|---|
| 128 |
break; |
|---|
| 129 |
case SDL_MOUSEBUTTONDOWN: |
|---|
| 130 |
if(event.button.button == SDL_BUTTON_WHEELUP || event.button.button == SDL_BUTTON_WHEELDOWN) |
|---|
| 131 |
onScroll(event.button); |
|---|
| 132 |
else |
|---|
| 133 |
onMouseButtonDown(event.button); |
|---|
| 134 |
break; |
|---|
| 135 |
case SDL_MOUSEBUTTONUP: |
|---|
| 136 |
if(event.button.button == SDL_BUTTON_WHEELUP || event.button.button == SDL_BUTTON_WHEELDOWN) { |
|---|
| 137 |
onScroll(event.button); |
|---|
| 138 |
} |
|---|
| 139 |
else |
|---|
| 140 |
onMouseButtonUp(event.button); |
|---|
| 141 |
case SDL_VIDEORESIZE: |
|---|
| 142 |
break; |
|---|
| 143 |
case SDL_VIDEOEXPOSE: |
|---|
| 144 |
{ |
|---|
| 145 |
BalRectangle rect = m_webView->frameRect(); |
|---|
| 146 |
onExpose(event.expose, rect); |
|---|
| 147 |
break; |
|---|
| 148 |
} |
|---|
| 149 |
case SDL_USEREVENT: |
|---|
| 150 |
onUserEvent(event.user); |
|---|
| 151 |
break; |
|---|
| 152 |
case SDL_SYSWMEVENT: |
|---|
| 153 |
break; |
|---|
| 154 |
default: |
|---|
| 155 |
; |
|---|
| 156 |
} |
|---|
| 157 |
} else |
|---|
| 158 |
onIdle(); |
|---|
| 159 |
} |
|---|
| 160 |
} |
|---|
| 161 |
|
|---|
| 162 |
void WebWindow::stopMainLoop() |
|---|
| 163 |
{ |
|---|
| 164 |
quit = true; |
|---|
| 165 |
} |
|---|