Exemplo n.º 1
0
void ClientHandler::OnAfterCreated(CefRefPtr<CefBrowser> browser) {
  REQUIRE_UI_THREAD();
  AutoLock lock_scope(this);

  if (!browser->IsPopup()) {
    if (!mainBrowserHandle.get()) {
      mainBrowserHandle = browser;
    }
    windowCount++;
    NativeWindow* window = NativeWindow::GetWindow(browser);
    window->SetBrowser(browser);
    window->Emit("create");
  }
}
Exemplo n.º 2
0
// Processes messages for the main window.
LRESULT CALLBACK WndProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam) {
  NativeWindow* window = NativeWindow::GetWindow(hwnd);
  CefRefPtr<CefBrowser> browser;
  if (window) {
    browser = window->GetBrowser();
  }

  switch (message) {
    case WM_CREATE: {
      RECT rect;
      GetClientRect(hwnd, &rect);
      Cef::AddWebView(hwnd, rect, url_, browserSettings);
      return 0;
    }
    case WM_PAINT: {
      PAINTSTRUCT ps;
      HDC hdc;
      hdc = BeginPaint(hwnd, &ps);
      EndPaint(hwnd, &ps);
      return 0;
    }
    case WM_SETFOCUS:
      if (browser.get()) {
        PostMessage(browser->GetWindowHandle(), WM_SETFOCUS, wParam, NULL);
        return 0;
      }
    case WM_SIZE: {
      window->UpdatePosition();
      if (browser.get()) {
        RECT rect;
        GetClientRect(hwnd, &rect);
        HDWP hdwp = BeginDeferWindowPos(1);
        hdwp = DeferWindowPos(hdwp, browser->GetWindowHandle(), NULL,
                              rect.left, rect.top, rect.right - rect.left,
                              rect.bottom - rect.top, SWP_NOZORDER);
        EndDeferWindowPos(hdwp);
        if (emitFullscreen) {
          emitFullscreen = false;
          window->Emit("fullscreen");
        } else {
          window->Emit("resize", (int)LOWORD(lParam), (int)HIWORD(lParam));
        }
      }
      break;
    }
    case WM_WINDOWPOSCHANGING: {
      WINDOWPOS *position;
      position = (WINDOWPOS*)lParam;
      if (position->flags & SWP_STATECHANGED) {
        if (IsIconic(window->handle_)) {
          window->Emit("minimize");
        } else if (IsZoomed(window->handle_)) {
          window->Emit("maximize");
        } else {
          window->Emit("restore");
        }
      }
      break;
    }
    case WM_MOVE:
      window->UpdatePosition();
      if (browser.get()) {
        window->Emit("move", (int)LOWORD(lParam), (int)HIWORD(lParam));
      }
      break;
    case WM_NCHITTEST: {
      LRESULT result;
      if (DwmDefWindowProc != NULL) {
        if (DwmDefWindowProc(hwnd, message, wParam, lParam, &result)) {
          return result;
        }
      }
      break;
    }
    case WM_ERASEBKGND:
      if (browser.get()) {
        return 0;
      }
      break;
    case WM_CLOSE:
      if (browser.get()) {
        browser->ParentWindowWillClose();
      }
      break;
    //case WM_DESTROY:
    //  PostQuitMessage(0);

  }

  return DefWindowProc(hwnd, message, wParam, lParam);
}