コード例 #1
0
ファイル: appjs_window.cpp プロジェクト: chorfa672m/appjs
// synchronously send a string from Node to browser, then return string result from browser to Node
Handle<Value> Window::SendSync(const Arguments& args) {
  HandleScope scope;

  NativeWindow *window = ObjectWrap::Unwrap<NativeWindow> (args.This());

  if (window->GetBrowser()) {
    // find browser's v8 context
    CefRefPtr<CefV8Context> context = window->GetBrowser()->GetMainFrame()->GetV8Context();

    // ensure it's usable and enter
    if (context.get() && context->Enter()) {
      // try to get "appjs.onmessage" function
      CefRefPtr<CefV8Value> appjsObject = context->GetGlobal()->GetValue("appjs");
      CefRefPtr<CefV8Value> callback = appjsObject->GetValue("onmessage");
      if (callback.get()) {

        // convert Node V8 string to Cef V8 string
        CefV8ValueList argsOut;
        argsOut.push_back(CefV8Value::CreateString(V8StringToChar(args[0]->ToString())));

        // execute window.appjs fuction, passing in the string,
        // then convert the return value from a CefValue to a Node V8 string
        Handle<String> ret = CefStringToV8(callback->ExecuteFunction(appjsObject, argsOut)->GetStringValue());

        // exit browser v8 context, return string result to Node caller
        context->Exit();
        return scope.Close(ret);
      }
    }
  }
  // likely error condition
  return scope.Close(Undefined());
}
コード例 #2
0
ファイル: appjs_window.cpp プロジェクト: chorfa672m/appjs
Handle<Value> Window::Destroy(const Arguments& args) {
  HandleScope scope;

  NativeWindow *window = ObjectWrap::Unwrap<NativeWindow> (args.This());
  window->Destroy();

  return scope.Close(args.This());
}
コード例 #3
0
ファイル: cef_handler.cpp プロジェクト: 276361270/appjs
void ClientHandler::OnContentsSizeChange(CefRefPtr<CefBrowser> browser, CefRefPtr<CefFrame> frame, int width, int height) {
  REQUIRE_UI_THREAD();
  if (!browser->IsPopup() && frame->IsMain()) {
    NativeWindow* window = NativeWindow::GetWindow(browser);
    if (window != NULL && window->GetAutoResize()) {
      window->Resize(width, height);
    }
  }
}
コード例 #4
0
ファイル: appjs_window.cpp プロジェクト: chorfa672m/appjs
Handle<Value> Window::Resize(const Arguments& args) {
  HandleScope scope;
  NativeWindow *window = ObjectWrap::Unwrap<NativeWindow>(args.This());

  int width = args[0]->Int32Value();
  int height = args[1]->Int32Value();
  window->Resize(width, height);

  return scope.Close(args.This());
}
コード例 #5
0
ファイル: appjs_window.cpp プロジェクト: chorfa672m/appjs
Handle<Value> Window::RunInBrowser(const Arguments& args) {
  HandleScope scope;

  if(!args[0]->IsFunction())
    THROW_BAD_ARGS;

  NativeWindow *window = ObjectWrap::Unwrap<NativeWindow> (args.This());
  window->RunInBrowser(V8StringToFunctionChar(args[0]->ToString()));

  return scope.Close(args.This());
}
コード例 #6
0
ファイル: cef_handler.cpp プロジェクト: 276361270/appjs
void ClientHandler::OnBeforeClose(CefRefPtr<CefBrowser> browser) {
  REQUIRE_UI_THREAD();

  if(!browser->IsPopup()) {
    NativeWindow* window = NativeWindow::GetWindow(browser);
    window->PrepareClose();
    DoClose(browser);
#ifdef __WIN__
    delete window;
#endif
  }
}
コード例 #7
0
ファイル: appjs_window.cpp プロジェクト: Neverland/appjs
Handle<Value> Window::New(const Arguments& args) {
  HandleScope scope;

  Persistent<Object> options = Persistent<Object>::New(args[0]->ToObject());
  Settings* settings = new Settings(options);
  NativeWindow* window = new NativeWindow(settings);

  Persistent<Object> self = Persistent<Object>::New(args.This());
  window->SetV8Handle(self);
  self->SetPointerInInternalField(0, window);

  return scope.Close(args.This());
}
コード例 #8
0
ファイル: appjs_window.cpp プロジェクト: chorfa672m/appjs
void Window::SetState(Local<String> property, Local<Value> value, const AccessorInfo& info) {
  NativeWindow *window = ObjectWrap::Unwrap<NativeWindow>(info.Holder());
  Local<String> val = value->ToString();
  if (val->Equals(String::New("normal"))) {
    window->SetState(NW_STATE_NORMAL);
  } else if (val->Equals(String::New("minimized"))) {
    window->SetState(NW_STATE_MINIMIZED);
  } else if (val->Equals(String::New("maximized"))) {
    window->SetState(NW_STATE_MAXIMIZED);
  } else if (val->Equals(String::New("fullscreen"))) {
    window->SetState(NW_STATE_FULLSCREEN);
  }
}
コード例 #9
0
ファイル: cef_handler.cpp プロジェクト: 276361270/appjs
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");
  }
}
コード例 #10
0
ファイル: appjs_window.cpp プロジェクト: chorfa672m/appjs
Handle<Value> Window::Move(const Arguments& args) {
  HandleScope scope;
  NativeWindow *window = ObjectWrap::Unwrap<NativeWindow>(args.This());

  int top = args[0]->Int32Value();
  int left = args[1]->Int32Value();
  if (args[2]->IsNumber()) {
    int width = args[2]->Int32Value();
    int height = args[3]->Int32Value();
    window->Move(top, left, width, height);
  } else {
    window->Move(top, left);
  }

  return scope.Close(args.This());
}
コード例 #11
0
ファイル: appjs_window.cpp プロジェクト: chorfa672m/appjs
Handle<Value> Window::New(const Arguments& args) {
  HandleScope scope;

  Handle<Object> self = Persistent<Object>::New(args.This());

  char* url = (args[0]->IsString()) ? V8StringToChar(args[0]->ToString()) : (char*) "/";
  Persistent<Object> windowSettings = Persistent<Object>::New((args[1]->IsObject()) ? args[1]->ToObject() : Object::New());

  Settings* settings = new Settings(windowSettings);
  NativeWindow* window = new NativeWindow(url, settings);
  window->SetV8Handle(self);

  self->SetPointerInInternalField (0, window);

  return scope.Close(args.This());
}
コード例 #12
0
ファイル: appjs_window.cpp プロジェクト: jasperla/appjs
Handle<Value> Window::SetNonclientWidth(const Arguments& args) {
  HandleScope scope;
  NativeWindow *window = ObjectWrap::Unwrap<NativeWindow>(args.This());

  if (args.Length() == 4) {
    int top = args[0]->Int32Value();
    int left = args[1]->Int32Value();
    int right = args[2]->Int32Value();
    int bottom = args[3]->Int32Value();
    window->SetNonclientWidth(top, left, right, bottom);
  } else {
    window->SetNonclientWidth(args[0]->Int32Value());
  }

  return scope.Close(args.This());
}
コード例 #13
0
ファイル: appjs_window.cpp プロジェクト: chorfa672m/appjs
Handle<Value> Window::Style(const Arguments& args) {
  HandleScope scope;
  NativeWindow *window = ObjectWrap::Unwrap<NativeWindow>(args.This());
  switch (args.Length()) {
    case 0:
      return scope.Close(Integer::New(window->GetStyle(false)));
    case 1:
      if (args[0]->IsBoolean()) {
        return scope.Close(Integer::New(window->GetStyle(args[0]->BooleanValue())));
      } else {
        window->SetStyle(args[0]->Int32Value(), false);
      }
      break;
    case 2:
      window->SetStyle(args[0]->Int32Value(), args[1]->BooleanValue());
      break;
  }
  return scope.Close(args.This());
}
コード例 #14
0
ファイル: appjs_window.cpp プロジェクト: chorfa672m/appjs
Handle<Value> Window::GetState(Local<String> property, const AccessorInfo &info) {
  HandleScope scope;
  NativeWindow *window = ObjectWrap::Unwrap<NativeWindow>(info.Holder());
  Handle<Value> state = String::New("normal");

  switch (window->GetState()) {
    case NW_STATE_NORMAL:
      state = String::New("normal");
      break;
    case NW_STATE_MINIMIZED:
      state = String::New("minimized");
      break;
    case NW_STATE_MAXIMIZED:
      state = String::New("maximized");
      break;
    case NW_STATE_FULLSCREEN:
      state = String::New("fullscreen");
  }

  return scope.Close(state);
}
コード例 #15
0
ファイル: egluUtil.cpp プロジェクト: crucible/deqp
//! Create EGL window surface using eglCreateWindowSurface() or eglCreatePlatformWindowSurfaceEXT()
EGLSurface createWindowSurface (NativeDisplay& nativeDisplay, NativeWindow& window, EGLDisplay display, EGLConfig config, const EGLAttrib* attribList)
{
	const Library&	egl							= nativeDisplay.getLibrary();
	const bool		supportsLegacyCreate		= (window.getCapabilities() & NativeWindow::CAPABILITY_CREATE_SURFACE_LEGACY) != 0;
	const bool		supportsPlatformCreate		= (window.getCapabilities() & NativeWindow::CAPABILITY_CREATE_SURFACE_PLATFORM) != 0;
	bool			usePlatformExt				= false;
	EGLSurface		surface						= EGL_NO_SURFACE;

	TCU_CHECK_INTERNAL(supportsLegacyCreate || supportsPlatformCreate);

	if (supportsPlatformCreate)
	{
		const vector<string> platformExts = getPlatformExtensions(egl);
		usePlatformExt = de::contains(platformExts.begin(), platformExts.end(), string("EGL_EXT_platform_base")) &&
						 de::contains(platformExts.begin(), platformExts.end(), string(nativeDisplay.getPlatformExtensionName()));
	}

	// \todo [2014-03-13 pyry] EGL 1.5 core support
	if (usePlatformExt)
	{
		const vector<EGLint>	legacyAttribs	= toLegacyAttribList(attribList);

		surface = egl.createPlatformWindowSurfaceEXT(display, config, window.getPlatformNative(), &legacyAttribs[0]);
		EGLU_CHECK_MSG(egl, "eglCreatePlatformWindowSurfaceEXT()");
		TCU_CHECK(surface != EGL_NO_SURFACE);
	}
	else if (supportsLegacyCreate)
	{
		const vector<EGLint> legacyAttribs = toLegacyAttribList(attribList);
		surface = egl.createWindowSurface(display, config, window.getLegacyNative(), &legacyAttribs[0]);
		EGLU_CHECK_MSG(egl, "eglCreateWindowSurface()");
		TCU_CHECK(surface != EGL_NO_SURFACE);
	}
	else
		throw tcu::InternalError("No supported way to create EGL window surface", DE_NULL, __FILE__, __LINE__);

	DE_ASSERT(surface != EGL_NO_SURFACE);
	return surface;
}
コード例 #16
0
ファイル: appjs_window.cpp プロジェクト: chorfa672m/appjs
void Window::SetTopmost(Local<String> property, Local<Value> value, const AccessorInfo& info) {
  NativeWindow *window = ObjectWrap::Unwrap<NativeWindow>(info.Holder());
  window->SetTopmost(value->BooleanValue());
}
コード例 #17
0
ファイル: appjs_window.cpp プロジェクト: chorfa672m/appjs
void Window::SetTitle(Local<String> property, Local<Value> value, const AccessorInfo& info) {
  NativeWindow *window = ObjectWrap::Unwrap<NativeWindow>(info.Holder());
  window->SetTitle(V8StringToChar(value->ToString()));
}
コード例 #18
0
ファイル: appjs_window.cpp プロジェクト: chorfa672m/appjs
Handle<Value> Window::GetTopmost(Local<String> property, const AccessorInfo &info) {
  HandleScope scope;
  NativeWindow *window = ObjectWrap::Unwrap<NativeWindow>(info.Holder());
  return scope.Close(Boolean::New(window->GetTopmost()));
}
コード例 #19
0
ファイル: appjs_window.cpp プロジェクト: jasperla/appjs
Handle<Value> Window::GetExStyle(Local<String> property, const AccessorInfo &info) {
  HandleScope scope;
  NativeWindow *window = ObjectWrap::Unwrap<NativeWindow>(info.Holder());
  return scope.Close(Integer::New(window->GetExStyle()));
}
コード例 #20
0
ファイル: Ui.cpp プロジェクト: godlikepanos/anki-3d-engine
ANKI_TEST(Ui, Ui)
{
	Config cfg;
	initConfig(cfg);
	cfg.set("window.vsync", 1);
	cfg.set("window.debugContext", 0);
	cfg.set("width", 1024);
	cfg.set("height", 760);
	cfg.set("rsrc.dataPaths", "engine_data");

	NativeWindow* win = createWindow(cfg);
	Input* in = new Input();
	GrManager* gr = createGrManager(cfg, win);
	PhysicsWorld* physics;
	ResourceFilesystem* fs;
	ResourceManager* resource = createResourceManager(cfg, gr, physics, fs);
	UiManager* ui = new UiManager();

	ANKI_TEST_EXPECT_NO_ERR(in->init(win));

	StagingGpuMemoryManager* stagingMem = new StagingGpuMemoryManager();
	ANKI_TEST_EXPECT_NO_ERR(stagingMem->init(gr, cfg));

	HeapAllocator<U8> alloc(allocAligned, nullptr);
	ANKI_TEST_EXPECT_NO_ERR(ui->init(allocAligned, nullptr, resource, gr, stagingMem, in));

	{
		FontPtr font;
		ANKI_TEST_EXPECT_NO_ERR(ui->newInstance(font, "UbuntuRegular.ttf", std::initializer_list<U32>{10, 20, 30, 60}));

		CanvasPtr canvas;
		ANKI_TEST_EXPECT_NO_ERR(ui->newInstance(canvas, font, 20, win->getWidth(), win->getHeight()));

		IntrusivePtr<Label> label;
		ANKI_TEST_EXPECT_NO_ERR(ui->newInstance(label));

		Bool done = false;
		while(!done)
		{
			ANKI_TEST_EXPECT_NO_ERR(in->handleEvents());
			HighRezTimer timer;
			timer.start();

			canvas->handleInput();
			if(in->getKey(KeyCode::ESCAPE))
			{
				done = true;
			}

			canvas->beginBuilding();
			label->build(canvas);

			TexturePtr presentTex = gr->acquireNextPresentableTexture();
			FramebufferPtr fb;
			{
				TextureViewInitInfo init;
				init.m_texture = presentTex;
				TextureViewPtr view = gr->newTextureView(init);

				FramebufferInitInfo fbinit;
				fbinit.m_colorAttachmentCount = 1;
				fbinit.m_colorAttachments[0].m_clearValue.m_colorf = {{1.0, 0.0, 1.0, 1.0}};
				fbinit.m_colorAttachments[0].m_textureView = view;

				fb = gr->newFramebuffer(fbinit);
			}

			CommandBufferInitInfo cinit;
			cinit.m_flags = CommandBufferFlag::GRAPHICS_WORK | CommandBufferFlag::SMALL_BATCH;
			CommandBufferPtr cmdb = gr->newCommandBuffer(cinit);

			cmdb->setTextureBarrier(presentTex,
				TextureUsageBit::NONE,
				TextureUsageBit::FRAMEBUFFER_ATTACHMENT_WRITE,
				TextureSubresourceInfo());

			cmdb->beginRenderPass(fb, {{TextureUsageBit::FRAMEBUFFER_ATTACHMENT_WRITE}}, {});
			canvas->appendToCommandBuffer(cmdb);
			cmdb->endRenderPass();

			cmdb->setTextureBarrier(presentTex,
				TextureUsageBit::FRAMEBUFFER_ATTACHMENT_WRITE,
				TextureUsageBit::PRESENT,
				TextureSubresourceInfo());

			cmdb->flush();

			gr->swapBuffers();
			stagingMem->endFrame();

			timer.stop();
			const F32 TICK = 1.0 / 30.0;
			if(timer.getElapsedTime() < TICK)
			{
				HighRezTimer::sleep(TICK - timer.getElapsedTime());
			}
		}
	}

	delete ui;
	delete stagingMem;
	delete resource;
	delete physics;
	delete fs;
	GrManager::deleteInstance(gr);
	delete in;
	delete win;
}
コード例 #21
0
ファイル: native_window_win.cpp プロジェクト: aredridel/appjs
// Processes messages for the main window.
LRESULT CALLBACK WndProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam) {

  // Callback for the main window
  switch (message) {
    case WM_CREATE: {
      NativeWindow* window = ClientHandler::GetWindow(hwnd);
      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 (g_handler.get() && g_handler->GetBrowserHwnd()) {
        // Pass focus to the browser window
        PostMessage(g_handler->GetBrowserHwnd(), WM_SETFOCUS, wParam, NULL);
      }
      return 0;*/

    case WM_SIZE: {
      NativeWindow* window = ClientHandler::GetWindow(hwnd);
      if (window->GetBrowser()) {
        RECT r;
        GetClientRect(hwnd, &r);
        HDWP hdwp = BeginDeferWindowPos(1);
        hdwp = DeferWindowPos(hdwp, window->GetBrowser()->GetWindowHandle(), NULL, r.left, r.top, r.right - r.left, r.bottom - r.top, SWP_NOZORDER);
        EndDeferWindowPos(hdwp);
      }
      window->UpdatePosition();
      break;
    }
    case WM_MOVE:
      ClientHandler::GetWindow(hwnd)->UpdatePosition();
      break;
    case WM_ERASEBKGND:
      return 1;
    // case WM_ERASEBKGND: {
    //   NativeWindow* window = ClientHandler::GetWindow(hwnd);
    //   if (window->GetBrowser()) {
    //     // Dont erase the background if the browser window has been loaded
    //     // (this avoids flashing)
    //     return 0;
    //   }
    case WM_CLOSE: {
      NativeWindow* window = ClientHandler::GetWindow(hwnd);
      if (window->GetBrowser()) {
        window->GetBrowser()->ParentWindowWillClose();
      }
    }
    break;
    //case WM_DESTROY:
    //  PostQuitMessage(0);

  }

  return DefWindowProc(hwnd, message, wParam, lParam);
}
コード例 #22
0
ファイル: appjs_window.cpp プロジェクト: chorfa672m/appjs
void Window::SetWidth(Local<String> property, Local<Value> value, const AccessorInfo& info) {
  NativeWindow *window = ObjectWrap::Unwrap<NativeWindow>(info.Holder());
  window->SetWidth(value->Int32Value());
}
コード例 #23
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);
}
コード例 #24
0
ファイル: cef_handler.cpp プロジェクト: dshaw/appjs
Handle<Object> ClientHandler::CreatedBrowser(CefRefPtr<CefBrowser> browser) {
  NativeWindow* window = GetWindow(browser);
  window->SetBrowser(browser);
  return window->GetV8Handle();
}