mirror of https://github.com/ImVexed/muon.git
Remove unecessary headers
This commit is contained in:
parent
3b10823c7c
commit
221a9e372c
|
@ -1,162 +0,0 @@
|
||||||
///
|
|
||||||
/// @file App.h
|
|
||||||
///
|
|
||||||
/// @brief The header for the App class.
|
|
||||||
///
|
|
||||||
/// @author
|
|
||||||
///
|
|
||||||
/// This file is a part of Ultralight, a fast, lightweight, HTML UI engine
|
|
||||||
///
|
|
||||||
/// Website: <http://ultralig.ht>
|
|
||||||
///
|
|
||||||
/// Copyright (C) 2019 Ultralight, Inc. All rights reserved.
|
|
||||||
///
|
|
||||||
#pragma once
|
|
||||||
#include "Defines.h"
|
|
||||||
#include <Ultralight/RefPtr.h>
|
|
||||||
#include <Ultralight/Renderer.h>
|
|
||||||
#include <Ultralight/platform/Config.h>
|
|
||||||
|
|
||||||
namespace ultralight {
|
|
||||||
|
|
||||||
class Monitor;
|
|
||||||
class Window;
|
|
||||||
|
|
||||||
///
|
|
||||||
/// Interface for all App-related events. @see App::set_listener
|
|
||||||
///
|
|
||||||
class AExport AppListener {
|
|
||||||
public:
|
|
||||||
virtual ~AppListener() {}
|
|
||||||
|
|
||||||
///
|
|
||||||
/// Called whenever the App updates. You should update all app logic here.
|
|
||||||
///
|
|
||||||
/// @note This event is fired right before the run loop calls
|
|
||||||
/// Renderer::Update and Renderer::Render.
|
|
||||||
///
|
|
||||||
virtual void OnUpdate() {}
|
|
||||||
};
|
|
||||||
|
|
||||||
///
|
|
||||||
/// App-specific settings.
|
|
||||||
///
|
|
||||||
struct AExport Settings {
|
|
||||||
///
|
|
||||||
/// The root file path for our file system. You should set this to the
|
|
||||||
/// relative path where all of your app data is.
|
|
||||||
///
|
|
||||||
/// This will be used to resolve all file URLs, eg file:///page.html
|
|
||||||
///
|
|
||||||
/// @note By default, on macOS we use the app bundle's @resource_path,
|
|
||||||
/// on all other platforms we use the "./assets/" directory relative
|
|
||||||
/// to the executable's directory.
|
|
||||||
///
|
|
||||||
#ifdef __APPLE__
|
|
||||||
String file_system_path = "@resource_path";
|
|
||||||
#else
|
|
||||||
String file_system_path = "./assets/";
|
|
||||||
#endif
|
|
||||||
|
|
||||||
///
|
|
||||||
/// Whether or not we should load and compile shaders from the file system
|
|
||||||
/// (eg, from the /shaders/ path, relative to file_system_path).
|
|
||||||
///
|
|
||||||
/// If this is false (the default), we will instead load pre-compiled shaders
|
|
||||||
/// from memory which speeds up application startup time.
|
|
||||||
///
|
|
||||||
bool load_shaders_from_file_system = false;
|
|
||||||
};
|
|
||||||
|
|
||||||
///
|
|
||||||
/// Main application class.
|
|
||||||
///
|
|
||||||
class AExport App : public RefCounted {
|
|
||||||
public:
|
|
||||||
///
|
|
||||||
/// Create the App singleton.
|
|
||||||
///
|
|
||||||
/// @param settings Settings to customize App runtime behavior.
|
|
||||||
///
|
|
||||||
/// @param config Config options for the Ultralight renderer.
|
|
||||||
///
|
|
||||||
/// @return Returns a ref-pointer to the created App instance.
|
|
||||||
///
|
|
||||||
/// @note You should only create one of these per application lifetime.
|
|
||||||
///
|
|
||||||
/// @note Certain Config options may be overridden during App creation,
|
|
||||||
/// most commonly Config::face_winding and Config::device_scale_hint.
|
|
||||||
///
|
|
||||||
static Ref<App> Create(Settings settings = Settings(), Config config = Config());
|
|
||||||
|
|
||||||
///
|
|
||||||
/// Get the App singleton.
|
|
||||||
///
|
|
||||||
static App* instance();
|
|
||||||
|
|
||||||
///
|
|
||||||
/// Get the settings this App was created with.
|
|
||||||
///
|
|
||||||
virtual const Settings& settings() const = 0;
|
|
||||||
|
|
||||||
///
|
|
||||||
/// Set the main window. You must set this before calling Run.
|
|
||||||
///
|
|
||||||
/// @param window The window to use for all rendering.
|
|
||||||
///
|
|
||||||
/// @note We currently only support one Window per App, this will change
|
|
||||||
/// later once we add support for multiple driver instances.
|
|
||||||
///
|
|
||||||
virtual void set_window(Ref<Window> window) = 0;
|
|
||||||
|
|
||||||
///
|
|
||||||
/// Get the main window.
|
|
||||||
///
|
|
||||||
virtual RefPtr<Window> window() = 0;
|
|
||||||
|
|
||||||
///
|
|
||||||
/// Set an AppListener to receive callbacks for app-related events.
|
|
||||||
///
|
|
||||||
/// @note Ownership remains with the caller.
|
|
||||||
///
|
|
||||||
virtual void set_listener(AppListener* listener) = 0;
|
|
||||||
|
|
||||||
///
|
|
||||||
/// Get the AppListener, if any.
|
|
||||||
///
|
|
||||||
virtual AppListener* listener() = 0;
|
|
||||||
|
|
||||||
///
|
|
||||||
/// Whether or not the App is running.
|
|
||||||
///
|
|
||||||
virtual bool is_running() const = 0;
|
|
||||||
|
|
||||||
///
|
|
||||||
/// Get the main monitor (this is never NULL).
|
|
||||||
///
|
|
||||||
/// @note We'll add monitor enumeration later.
|
|
||||||
///
|
|
||||||
virtual Monitor* main_monitor() = 0;
|
|
||||||
|
|
||||||
///
|
|
||||||
/// Get the underlying Renderer instance.
|
|
||||||
///
|
|
||||||
virtual Ref<Renderer> renderer() = 0;
|
|
||||||
|
|
||||||
///
|
|
||||||
/// Run the main loop.
|
|
||||||
///
|
|
||||||
/// @note Make sure to call set_window before calling this.
|
|
||||||
///
|
|
||||||
virtual void Run() = 0;
|
|
||||||
|
|
||||||
///
|
|
||||||
/// Quit the application.
|
|
||||||
///
|
|
||||||
virtual void Quit() = 0;
|
|
||||||
|
|
||||||
protected:
|
|
||||||
virtual ~App();
|
|
||||||
};
|
|
||||||
|
|
||||||
} // namespace ultralight
|
|
|
@ -1,5 +0,0 @@
|
||||||
#include <AppCore/App.h>
|
|
||||||
#include <AppCore/Monitor.h>
|
|
||||||
#include <AppCore/Window.h>
|
|
||||||
#include <AppCore/Overlay.h>
|
|
||||||
#include <AppCore/JSHelpers.h>
|
|
|
@ -1,42 +0,0 @@
|
||||||
// Copyright 2018 Ultralight, Inc. All rights reserved.
|
|
||||||
#pragma once
|
|
||||||
|
|
||||||
// Needed for limit defines, like INTMAX_MAX, which is used by the std C++ library
|
|
||||||
#ifndef __STDC_LIMIT_MACROS
|
|
||||||
#define __STDC_LIMIT_MACROS
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#include <cstdint>
|
|
||||||
#include <cstddef>
|
|
||||||
#include <limits.h>
|
|
||||||
|
|
||||||
#ifdef SWIG
|
|
||||||
#define AExport
|
|
||||||
#else
|
|
||||||
|
|
||||||
// Require C++11 Support
|
|
||||||
#if defined(_MSC_VER)
|
|
||||||
# if _MSC_VER < 1800
|
|
||||||
# error This project needs at least Visual Studio 2013 to build
|
|
||||||
# endif
|
|
||||||
#elif __cplusplus <= 199711L
|
|
||||||
# error This project can only be compiled with a compiler that supports C++11
|
|
||||||
#endif
|
|
||||||
|
|
||||||
|
|
||||||
#if defined(__WIN32__) || defined(_WIN32)
|
|
||||||
# if defined(APPCORE_IMPLEMENTATION)
|
|
||||||
# define AExport __declspec(dllexport)
|
|
||||||
# else
|
|
||||||
# define AExport __declspec(dllimport)
|
|
||||||
# endif
|
|
||||||
#define _thread_local __declspec(thread)
|
|
||||||
#ifndef _NATIVE_WCHAR_T_DEFINED
|
|
||||||
#define DISABLE_NATIVE_WCHAR_T
|
|
||||||
#endif
|
|
||||||
#else
|
|
||||||
# define AExport __attribute__((visibility("default")))
|
|
||||||
#define _thread_local __thread
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#endif
|
|
|
@ -1,415 +0,0 @@
|
||||||
#pragma once
|
|
||||||
#include <AppCore/Defines.h>
|
|
||||||
#include <JavaScriptCore/JavaScript.h>
|
|
||||||
#include <JavaScriptCore/JSStringRef.h>
|
|
||||||
#include <Ultralight/String.h>
|
|
||||||
#include <functional>
|
|
||||||
#include <memory>
|
|
||||||
|
|
||||||
/**
|
|
||||||
* This is a set of common JavaScriptCore Helper functions
|
|
||||||
* to simplify sample code.
|
|
||||||
*/
|
|
||||||
|
|
||||||
namespace ultralight {
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Set the current JSContext.
|
|
||||||
*
|
|
||||||
* NOTE: You MUST set this before using most of the classes/functions below.
|
|
||||||
*
|
|
||||||
* The only things you can create without a JSContext are JSString's and
|
|
||||||
* the empty JSFunction constructor.
|
|
||||||
*/
|
|
||||||
void AExport SetJSContext(JSContextRef ctx);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get the current JSContext.
|
|
||||||
*/
|
|
||||||
JSContextRef AExport GetJSContext();
|
|
||||||
|
|
||||||
/**
|
|
||||||
* JSString wrapper that automatically manages lifetime
|
|
||||||
* and provides helpful conversions.
|
|
||||||
*/
|
|
||||||
class AExport JSString {
|
|
||||||
public:
|
|
||||||
// Create empty string
|
|
||||||
JSString();
|
|
||||||
|
|
||||||
// Create from C-string
|
|
||||||
JSString(const char* str);
|
|
||||||
|
|
||||||
// Create from Ultralight String
|
|
||||||
JSString(const String& str);
|
|
||||||
|
|
||||||
// Take ownership of existing JSStringRef
|
|
||||||
JSString(JSStringRef str);
|
|
||||||
|
|
||||||
// Copy constructor
|
|
||||||
JSString(const JSString& other);
|
|
||||||
|
|
||||||
~JSString();
|
|
||||||
|
|
||||||
// Assignment operator
|
|
||||||
JSString& operator=(const JSString& other);
|
|
||||||
|
|
||||||
// Cast to String
|
|
||||||
operator String();
|
|
||||||
|
|
||||||
// Cast to JSStringRef
|
|
||||||
operator JSStringRef() const { return instance_; }
|
|
||||||
|
|
||||||
protected:
|
|
||||||
JSStringRef instance_;
|
|
||||||
};
|
|
||||||
|
|
||||||
class JSArray;
|
|
||||||
class JSObject;
|
|
||||||
class JSFunction;
|
|
||||||
|
|
||||||
// Used with the JSValue constructor to create "Null" types
|
|
||||||
struct AExport JSValueNullTag {};
|
|
||||||
|
|
||||||
// Used with the JSValue constructor to create "Undefined" types
|
|
||||||
struct AExport JSValueUndefinedTag {};
|
|
||||||
|
|
||||||
/**
|
|
||||||
* JSValue wrapper that automatically manages lifetime and
|
|
||||||
* provides helpful conversions.
|
|
||||||
*/
|
|
||||||
class AExport JSValue {
|
|
||||||
public:
|
|
||||||
// Create null (empty) JSValue
|
|
||||||
JSValue();
|
|
||||||
|
|
||||||
// Create null JSValue explicitly
|
|
||||||
JSValue(JSValueNullTag);
|
|
||||||
|
|
||||||
// Create undefined JSValue
|
|
||||||
JSValue(JSValueUndefinedTag);
|
|
||||||
|
|
||||||
// Create boolean JSValue
|
|
||||||
JSValue(bool val);
|
|
||||||
|
|
||||||
// Create unsigned integer JSValue (aka, Number) [will be cast to double]
|
|
||||||
JSValue(uint32_t val);
|
|
||||||
|
|
||||||
// Create integer JSValue (aka, Number) [will be cast to double]
|
|
||||||
JSValue(int32_t val);
|
|
||||||
|
|
||||||
// Create unsigned integer JSValue (aka, Number) [will be cast to double]
|
|
||||||
JSValue(uint64_t val);
|
|
||||||
|
|
||||||
// Create integer JSValue (aka, Number) [will be cast to double]
|
|
||||||
JSValue(int64_t val);
|
|
||||||
|
|
||||||
// Create double JSValue (aka, Number)
|
|
||||||
JSValue(double val);
|
|
||||||
|
|
||||||
// Create string JSValue
|
|
||||||
JSValue(const char* val);
|
|
||||||
|
|
||||||
// Create string JSValue
|
|
||||||
JSValue(const String& val);
|
|
||||||
|
|
||||||
// Create string JSValue
|
|
||||||
JSValue(JSString val);
|
|
||||||
|
|
||||||
// Create from existing JSValueRef
|
|
||||||
JSValue(JSValueRef val);
|
|
||||||
|
|
||||||
// Create object JSValue
|
|
||||||
JSValue(JSObjectRef obj);
|
|
||||||
|
|
||||||
// Copy constructor, a shallow copy is made, will end up pointing to same instance
|
|
||||||
JSValue(const JSValue& other);
|
|
||||||
|
|
||||||
virtual ~JSValue();
|
|
||||||
|
|
||||||
// A shallow copy is made, will end up pointing to same instance
|
|
||||||
virtual JSValue& operator=(const JSValue& other);
|
|
||||||
|
|
||||||
bool IsNull() const;
|
|
||||||
|
|
||||||
bool IsUndefined() const;
|
|
||||||
|
|
||||||
bool IsBoolean() const;
|
|
||||||
|
|
||||||
bool IsNumber() const;
|
|
||||||
|
|
||||||
bool IsString() const;
|
|
||||||
|
|
||||||
bool IsObject() const;
|
|
||||||
|
|
||||||
bool IsArray() const;
|
|
||||||
|
|
||||||
bool IsFunction() const;
|
|
||||||
|
|
||||||
// Convert to Boolean
|
|
||||||
bool ToBoolean() const;
|
|
||||||
|
|
||||||
// Convert to Number (Double)
|
|
||||||
double ToNumber() const;
|
|
||||||
|
|
||||||
// Convert to Number (Integer)
|
|
||||||
int64_t ToInteger() const { return static_cast<int64_t>(ToNumber()); }
|
|
||||||
|
|
||||||
// Convert to String
|
|
||||||
JSString ToString() const;
|
|
||||||
|
|
||||||
// Convert to Object (will debug assert if not an Object)
|
|
||||||
JSObject ToObject() const;
|
|
||||||
|
|
||||||
// Convert to Array (will debug asset if not an Array)
|
|
||||||
JSArray ToArray() const;
|
|
||||||
|
|
||||||
// Convert to Function (will debug asset if not a Function)
|
|
||||||
JSFunction ToFunction() const;
|
|
||||||
|
|
||||||
operator bool() const { return ToBoolean(); }
|
|
||||||
|
|
||||||
operator double() const { return ToNumber(); }
|
|
||||||
|
|
||||||
operator uint32_t() const { return static_cast<uint32_t>(ToNumber()); }
|
|
||||||
|
|
||||||
operator int32_t() const { return static_cast<uint32_t>(ToNumber()); }
|
|
||||||
|
|
||||||
operator uint64_t() const { return static_cast<uint64_t>(ToNumber()); }
|
|
||||||
|
|
||||||
operator int64_t() const { return ToInteger(); }
|
|
||||||
|
|
||||||
operator String() const { return ToString(); }
|
|
||||||
|
|
||||||
operator JSString() const { return ToString(); }
|
|
||||||
|
|
||||||
operator JSObject() const;
|
|
||||||
|
|
||||||
operator JSObjectRef() const;
|
|
||||||
|
|
||||||
operator JSArray() const;
|
|
||||||
|
|
||||||
operator JSFunction() const;
|
|
||||||
|
|
||||||
// Get the underlying JSValueRef
|
|
||||||
operator JSValueRef() const { return instance(); }
|
|
||||||
|
|
||||||
protected:
|
|
||||||
JSValue(JSContextRef ctx);
|
|
||||||
JSValue(JSContextRef ctx, JSValueRef val);
|
|
||||||
virtual JSValueRef instance() const;
|
|
||||||
|
|
||||||
JSContextRef ctx_;
|
|
||||||
JSValueRef instance_ = nullptr;
|
|
||||||
friend class JSFunction;
|
|
||||||
};
|
|
||||||
|
|
||||||
/**
|
|
||||||
* A vector of JSValues, used for passing around arguments in JSCallback.
|
|
||||||
* We don't expose std::vector directly because of ABI concerns.
|
|
||||||
*/
|
|
||||||
class AExport JSArgs {
|
|
||||||
public:
|
|
||||||
JSArgs();
|
|
||||||
JSArgs(const std::initializer_list<JSValue>& values);
|
|
||||||
JSArgs(const JSArgs& other);
|
|
||||||
~JSArgs();
|
|
||||||
|
|
||||||
JSArgs& operator=(const JSArgs& other);
|
|
||||||
|
|
||||||
JSValue operator[](size_t pos);
|
|
||||||
const JSValue operator[](size_t pos) const;
|
|
||||||
|
|
||||||
bool empty() const;
|
|
||||||
|
|
||||||
size_t size() const;
|
|
||||||
|
|
||||||
void clear();
|
|
||||||
|
|
||||||
void push_back(const JSValue& val);
|
|
||||||
void pop_back();
|
|
||||||
|
|
||||||
JSValue* data();
|
|
||||||
const JSValue* data() const;
|
|
||||||
protected:
|
|
||||||
void* instance_;
|
|
||||||
};
|
|
||||||
|
|
||||||
typedef std::function<void(const JSObject&, const JSArgs&)> JSCallback;
|
|
||||||
typedef std::function<JSValue(const JSObject&, const JSArgs&)> JSCallbackWithRetval;
|
|
||||||
|
|
||||||
// Macro to help bind JSCallback member function to JSPropertyValue
|
|
||||||
#define BindJSCallback(fn) (JSCallback)std::bind(fn, this, std::placeholders::_1, std::placeholders::_2)
|
|
||||||
#define BindJSCallbackWithRetval(fn) (JSCallbackWithRetval)std::bind(fn, this, std::placeholders::_1, std::placeholders::_2)
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Wrapper for JSObject property value (JSValue subclass). Allows new value assignment
|
|
||||||
* to object property, binding C++ callbacks to object properties via function objects,
|
|
||||||
* as well as value query via the JSValue interface.
|
|
||||||
*/
|
|
||||||
class AExport JSPropertyValue : public JSValue {
|
|
||||||
public:
|
|
||||||
virtual ~JSPropertyValue();
|
|
||||||
|
|
||||||
// Assign a new value to the property (internally calls JSObjectSetProperty)
|
|
||||||
virtual JSPropertyValue& operator=(const JSValue& value);
|
|
||||||
|
|
||||||
// Bind to native C++ callback (creates a Function object that can be called from JS)
|
|
||||||
JSPropertyValue& operator=(const JSCallback& callback);
|
|
||||||
|
|
||||||
// Bind to native C++ callback with return value (creates a Function object that can be called from JS)
|
|
||||||
JSPropertyValue& operator=(const JSCallbackWithRetval& callback);
|
|
||||||
|
|
||||||
protected:
|
|
||||||
virtual JSValueRef instance() const;
|
|
||||||
JSPropertyValue(JSContextRef ctx, JSObjectRef proxy_obj, unsigned idx);
|
|
||||||
JSPropertyValue(JSContextRef ctx, JSObjectRef proxy_obj, JSString idx);
|
|
||||||
JSPropertyValue(const JSPropertyValue&) = default;
|
|
||||||
JSPropertyValue& operator=(const JSPropertyValue&) = delete;
|
|
||||||
|
|
||||||
JSObject* proxyObj_;
|
|
||||||
bool using_numeric_idx_;
|
|
||||||
unsigned numeric_idx_;
|
|
||||||
JSString string_idx_;
|
|
||||||
friend class JSArray;
|
|
||||||
friend class JSObject;
|
|
||||||
};
|
|
||||||
|
|
||||||
/**
|
|
||||||
* JSArray wrapper that automatically manages lifetime and provides
|
|
||||||
* convenient access to indices and Array functions.
|
|
||||||
*/
|
|
||||||
class AExport JSArray {
|
|
||||||
public:
|
|
||||||
// Create empty Array
|
|
||||||
JSArray();
|
|
||||||
|
|
||||||
// Create Array from list of JSValues
|
|
||||||
JSArray(const std::initializer_list<JSValue>& values);
|
|
||||||
|
|
||||||
// Create Array from existing JSObjectRef (JavaScriptCore C API)
|
|
||||||
JSArray(JSObjectRef array_obj);
|
|
||||||
|
|
||||||
// Copy constructor (shallow copy, will point to same instance)
|
|
||||||
JSArray(const JSArray& other);
|
|
||||||
|
|
||||||
~JSArray();
|
|
||||||
|
|
||||||
// Assignment (shallow assignment, will point to same instance)
|
|
||||||
JSArray& operator=(const JSArray& other);
|
|
||||||
|
|
||||||
// Get number of elements in the Array
|
|
||||||
unsigned length();
|
|
||||||
|
|
||||||
// Push an element to back of Array
|
|
||||||
void push(const JSValue& val);
|
|
||||||
|
|
||||||
// Find the index (location) of a certain value, will return -1 if not found
|
|
||||||
int indexOf(const JSValue& val, int start = 0) const;
|
|
||||||
|
|
||||||
// Get a property by array index (numbering starts at 0)
|
|
||||||
JSPropertyValue operator[](unsigned idx) const;
|
|
||||||
|
|
||||||
// Get the underlying JSObjectRef (JavaScriptCore C API)
|
|
||||||
operator JSObjectRef() const { return instance_; }
|
|
||||||
|
|
||||||
protected:
|
|
||||||
JSArray(JSContextRef ctx, JSValueRef val);
|
|
||||||
|
|
||||||
JSContextRef ctx_;
|
|
||||||
JSObjectRef instance_;
|
|
||||||
friend class JSValue;
|
|
||||||
};
|
|
||||||
|
|
||||||
/**
|
|
||||||
* JSObject wrapper that automatically manages lifetime and provides
|
|
||||||
* convenient access to properties.
|
|
||||||
*/
|
|
||||||
class AExport JSObject {
|
|
||||||
public:
|
|
||||||
// Create empty Object
|
|
||||||
JSObject();
|
|
||||||
|
|
||||||
// Create from existing JSObjectRef from JavaScriptCore C API
|
|
||||||
JSObject(JSObjectRef obj);
|
|
||||||
|
|
||||||
// Copy constructor (shallow copy, will point to same instance)
|
|
||||||
JSObject(const JSObject& other);
|
|
||||||
|
|
||||||
~JSObject();
|
|
||||||
|
|
||||||
// Assignment (shallow assignment, will point to same instance)
|
|
||||||
JSObject& operator=(const JSObject& other);
|
|
||||||
|
|
||||||
// Get a property by name
|
|
||||||
JSPropertyValue operator[](JSString propertyName) const;
|
|
||||||
|
|
||||||
// Check if a property exists
|
|
||||||
bool HasProperty(JSString propertyName) const;
|
|
||||||
|
|
||||||
// Remove a property
|
|
||||||
bool DeleteProperty(JSString propertyName);
|
|
||||||
|
|
||||||
// Get the underlying JSObjectRef (JavaScriptCore C API)
|
|
||||||
operator JSObjectRef() const { return instance_; }
|
|
||||||
|
|
||||||
protected:
|
|
||||||
JSObject(JSContextRef ctx, JSValueRef val);
|
|
||||||
JSObject(JSContextRef ctx, JSObjectRef obj);
|
|
||||||
|
|
||||||
JSContextRef ctx_;
|
|
||||||
JSObjectRef instance_;
|
|
||||||
friend class JSValue;
|
|
||||||
friend class JSPropertyValue;
|
|
||||||
};
|
|
||||||
|
|
||||||
/**
|
|
||||||
* JSFunction wrapper that automatically manages lifetime and provides
|
|
||||||
* convenient function invocation operators.
|
|
||||||
*/
|
|
||||||
class AExport JSFunction {
|
|
||||||
public:
|
|
||||||
// Create an empty Function.
|
|
||||||
// NOTE: It is OKAY to create this without calling SetJSContext() first.
|
|
||||||
JSFunction();
|
|
||||||
|
|
||||||
// Copy constructor (shallow copy, will point to same instance)
|
|
||||||
JSFunction(const JSFunction& other);
|
|
||||||
|
|
||||||
~JSFunction();
|
|
||||||
|
|
||||||
// Assignment (shallow assignment, will point to same instance)
|
|
||||||
JSFunction& operator=(const JSFunction& other);
|
|
||||||
|
|
||||||
// Whether or not this is a valid, callable Function object.
|
|
||||||
bool IsValid() const;
|
|
||||||
|
|
||||||
// Call function (using Global Object for 'this') and return the result.
|
|
||||||
JSValue operator()(const JSArgs& args);
|
|
||||||
|
|
||||||
// Call function (with explicit object for 'this') and return the result
|
|
||||||
JSValue operator()(const JSObject& thisObject, const JSArgs& args);
|
|
||||||
|
|
||||||
// Get the underlying JSObjectRef (JavaScriptCore C API)
|
|
||||||
operator JSObjectRef() const { return instance_; }
|
|
||||||
|
|
||||||
protected:
|
|
||||||
JSFunction(JSContextRef ctx, JSValueRef val);
|
|
||||||
|
|
||||||
JSContextRef ctx_;
|
|
||||||
JSObjectRef instance_;
|
|
||||||
friend class JSValue;
|
|
||||||
};
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get the Global Object for the current JSContext.
|
|
||||||
* In JavaScript, this would be equivalent to the "window" object.
|
|
||||||
*/
|
|
||||||
JSObject AExport JSGlobalObject();
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Evaluate a string of JavaScript and return a result.
|
|
||||||
*/
|
|
||||||
JSValue AExport JSEval(const JSString& str);
|
|
||||||
|
|
||||||
} // namespace ultralight
|
|
|
@ -1,41 +0,0 @@
|
||||||
///
|
|
||||||
/// @file Monitor.h
|
|
||||||
///
|
|
||||||
/// @brief The header for the Monitor class.
|
|
||||||
///
|
|
||||||
/// @author
|
|
||||||
///
|
|
||||||
/// This file is a part of Ultralight, a fast, lightweight, HTML UI engine
|
|
||||||
///
|
|
||||||
/// Website: <http://ultralig.ht>
|
|
||||||
///
|
|
||||||
/// Copyright (C) 2019 Ultralight, Inc. All rights reserved.
|
|
||||||
///
|
|
||||||
#pragma once
|
|
||||||
#include "Defines.h"
|
|
||||||
|
|
||||||
namespace ultralight {
|
|
||||||
|
|
||||||
///
|
|
||||||
/// Monitor class, represents a platform monitor.
|
|
||||||
///
|
|
||||||
class AExport Monitor {
|
|
||||||
public:
|
|
||||||
virtual ~Monitor() {}
|
|
||||||
|
|
||||||
///
|
|
||||||
/// Get the DPI scale (1.0 = 100%)
|
|
||||||
///
|
|
||||||
virtual double scale() const = 0;
|
|
||||||
|
|
||||||
///
|
|
||||||
/// Get the width of the monitor.
|
|
||||||
///
|
|
||||||
virtual uint32_t width() const = 0;
|
|
||||||
|
|
||||||
/// Get the height of the monitor.
|
|
||||||
///
|
|
||||||
virtual uint32_t height() const = 0;
|
|
||||||
};
|
|
||||||
|
|
||||||
} // namespace ultralight
|
|
|
@ -1,137 +0,0 @@
|
||||||
///
|
|
||||||
/// @file Overlay.h
|
|
||||||
///
|
|
||||||
/// @brief The header for the Overlay class.
|
|
||||||
///
|
|
||||||
/// @author
|
|
||||||
///
|
|
||||||
/// This file is a part of Ultralight, a fast, lightweight, HTML UI engine
|
|
||||||
///
|
|
||||||
/// Website: <http://ultralig.ht>
|
|
||||||
///
|
|
||||||
/// Copyright (C) 2019 Ultralight, Inc. All rights reserved.
|
|
||||||
///
|
|
||||||
#pragma once
|
|
||||||
#include "Window.h"
|
|
||||||
#include <Ultralight/View.h>
|
|
||||||
|
|
||||||
namespace ultralight {
|
|
||||||
|
|
||||||
///
|
|
||||||
/// Web-content overlay. Displays a web-page within an area of the main window.
|
|
||||||
///
|
|
||||||
/// @note Each Overlay is essentially a View and an on-screen quad. You should
|
|
||||||
/// create the Overlay then load content into the underlying View.
|
|
||||||
///
|
|
||||||
class AExport Overlay : public RefCounted {
|
|
||||||
public:
|
|
||||||
///
|
|
||||||
/// Create a new Overlay.
|
|
||||||
///
|
|
||||||
/// @param window The window to create the Overlay in. (we currently only
|
|
||||||
/// support one window per application)
|
|
||||||
///
|
|
||||||
/// @param width The width in device coordinates.
|
|
||||||
///
|
|
||||||
/// @param height The height in device coordinates.
|
|
||||||
///
|
|
||||||
/// @param x The x-position (offset from the left of the Window), in
|
|
||||||
/// device coordinates.
|
|
||||||
///
|
|
||||||
/// @param y The y-position (offset from the top of the Window), in
|
|
||||||
/// device coordinates.
|
|
||||||
///
|
|
||||||
static Ref<Overlay> Create(Ref<Window> window, uint32_t width,
|
|
||||||
uint32_t height, int x, int y);
|
|
||||||
|
|
||||||
///
|
|
||||||
/// Create a new Overlay, wrapping an existing View.
|
|
||||||
///
|
|
||||||
/// @param window The window to create the Overlay in. (we currently only
|
|
||||||
/// support one window per application)
|
|
||||||
///
|
|
||||||
/// @param view The View to wrap (will use its width and height).
|
|
||||||
///
|
|
||||||
/// @param x The x-position (offset from the left of the Window), in
|
|
||||||
/// device coordinates.
|
|
||||||
///
|
|
||||||
/// @param y The y-position (offset from the top of the Window), in
|
|
||||||
/// device coordinates.
|
|
||||||
///
|
|
||||||
static Ref<Overlay> Create(Ref<Window> window, Ref<View> view, int x, int y);
|
|
||||||
|
|
||||||
///
|
|
||||||
/// Get the underlying View.
|
|
||||||
///
|
|
||||||
virtual ultralight::Ref<ultralight::View> view() = 0;
|
|
||||||
|
|
||||||
///
|
|
||||||
/// Get the width (in device coordinates).
|
|
||||||
///
|
|
||||||
virtual uint32_t width() const = 0;
|
|
||||||
|
|
||||||
///
|
|
||||||
/// Get the height (in device coordinates).
|
|
||||||
///
|
|
||||||
virtual uint32_t height() const = 0;
|
|
||||||
|
|
||||||
///
|
|
||||||
/// Get the x-position (offset from the left of the Window), in device
|
|
||||||
/// coordinates.
|
|
||||||
///
|
|
||||||
virtual int x() const = 0;
|
|
||||||
|
|
||||||
///
|
|
||||||
/// Get the y-position (offset from the top of the Window), in device
|
|
||||||
/// coordinates.
|
|
||||||
///
|
|
||||||
virtual int y() const = 0;
|
|
||||||
|
|
||||||
///
|
|
||||||
/// Whether or not the overlay is hidden (not drawn).
|
|
||||||
///
|
|
||||||
virtual bool is_hidden() const = 0;
|
|
||||||
|
|
||||||
///
|
|
||||||
/// Hide the overlay (will no longer be drawn)
|
|
||||||
///
|
|
||||||
virtual void Hide() = 0;
|
|
||||||
|
|
||||||
///
|
|
||||||
/// Show the overlay.
|
|
||||||
///
|
|
||||||
virtual void Show() = 0;
|
|
||||||
|
|
||||||
///
|
|
||||||
/// Whether or not this overlay has keyboard focus.
|
|
||||||
///
|
|
||||||
virtual bool has_focus() const = 0;
|
|
||||||
|
|
||||||
///
|
|
||||||
/// Grant this overlay exclusive keyboard focus.
|
|
||||||
///
|
|
||||||
virtual void Focus() = 0;
|
|
||||||
|
|
||||||
///
|
|
||||||
/// Remove keyboard focus.
|
|
||||||
///
|
|
||||||
virtual void Unfocus() = 0;
|
|
||||||
|
|
||||||
///
|
|
||||||
/// Move the overlay to a new position (in device coordinates).
|
|
||||||
///
|
|
||||||
virtual void MoveTo(int x, int y) = 0;
|
|
||||||
|
|
||||||
///
|
|
||||||
/// Resize the overlay (and underlying View), dimensions should be
|
|
||||||
/// specified in device coordinates.
|
|
||||||
///
|
|
||||||
virtual void Resize(uint32_t width, uint32_t height) = 0;
|
|
||||||
|
|
||||||
protected:
|
|
||||||
virtual ~Overlay();
|
|
||||||
virtual void Draw() = 0;
|
|
||||||
friend class OverlayManager;
|
|
||||||
};
|
|
||||||
|
|
||||||
} // namespace framework
|
|
|
@ -1,141 +0,0 @@
|
||||||
///
|
|
||||||
/// @file Window.h
|
|
||||||
///
|
|
||||||
/// @brief The header for the Window class.
|
|
||||||
///
|
|
||||||
/// @author
|
|
||||||
///
|
|
||||||
/// This file is a part of Ultralight, a fast, lightweight, HTML UI engine
|
|
||||||
///
|
|
||||||
/// Website: <http://ultralig.ht>
|
|
||||||
///
|
|
||||||
/// Copyright (C) 2019 Ultralight, Inc. All rights reserved.
|
|
||||||
///
|
|
||||||
#pragma once
|
|
||||||
#include "Defines.h"
|
|
||||||
#include <Ultralight/RefPtr.h>
|
|
||||||
#include <Ultralight/Listener.h>
|
|
||||||
|
|
||||||
namespace ultralight {
|
|
||||||
|
|
||||||
class Monitor;
|
|
||||||
class OverlayManager;
|
|
||||||
|
|
||||||
///
|
|
||||||
/// Interface for all Window-related events. @see Window::set_listener
|
|
||||||
///
|
|
||||||
class WindowListener {
|
|
||||||
public:
|
|
||||||
virtual ~WindowListener() {}
|
|
||||||
|
|
||||||
///
|
|
||||||
/// Called when the Window is closed.
|
|
||||||
///
|
|
||||||
virtual void OnClose() = 0;
|
|
||||||
|
|
||||||
///
|
|
||||||
/// Called when the Window is resized.
|
|
||||||
///
|
|
||||||
/// @param width The new width (in device coordinates).
|
|
||||||
///
|
|
||||||
/// @param height The new height (in device coordinates).
|
|
||||||
///
|
|
||||||
virtual void OnResize(uint32_t width, uint32_t height) = 0;
|
|
||||||
};
|
|
||||||
|
|
||||||
///
|
|
||||||
/// Window creation flags. @see Window::Create
|
|
||||||
///
|
|
||||||
enum WindowFlags : uint8_t {
|
|
||||||
kWindowFlags_Borderless = 1 << 0,
|
|
||||||
kWindowFlags_Titled = 1 << 1,
|
|
||||||
kWindowFlags_Resizable = 1 << 2,
|
|
||||||
kWindowFlags_Maximizable = 1 << 3,
|
|
||||||
};
|
|
||||||
|
|
||||||
///
|
|
||||||
/// Window class, represents a platform window.
|
|
||||||
///
|
|
||||||
class AExport Window : public RefCounted {
|
|
||||||
public:
|
|
||||||
///
|
|
||||||
/// Create a new Window.
|
|
||||||
///
|
|
||||||
/// @param monitor The monitor to create the Window on.
|
|
||||||
///
|
|
||||||
/// @param width The width (in device coordinates).
|
|
||||||
///
|
|
||||||
/// @param height The height (in device coordinates).
|
|
||||||
///
|
|
||||||
/// @param fullscreen Whether or not the window is fullscreen.
|
|
||||||
///
|
|
||||||
/// @param window_flags Various window flags.
|
|
||||||
///
|
|
||||||
static Ref<Window> Create(Monitor* monitor, uint32_t width, uint32_t height,
|
|
||||||
bool fullscreen, unsigned int window_flags);
|
|
||||||
|
|
||||||
///
|
|
||||||
/// Set a WindowListener to receive callbacks for window-related events.
|
|
||||||
///
|
|
||||||
/// @note Ownership remains with the caller.
|
|
||||||
///
|
|
||||||
virtual void set_listener(WindowListener* listener) = 0;
|
|
||||||
|
|
||||||
///
|
|
||||||
/// Get the WindowListener, if any.
|
|
||||||
///
|
|
||||||
virtual WindowListener* listener() = 0;
|
|
||||||
|
|
||||||
///
|
|
||||||
/// Get the window width (in device coordinates).
|
|
||||||
///
|
|
||||||
virtual uint32_t width() const = 0;
|
|
||||||
|
|
||||||
///
|
|
||||||
/// Get the window height (in device coordinates).
|
|
||||||
///
|
|
||||||
virtual uint32_t height() const = 0;
|
|
||||||
|
|
||||||
///
|
|
||||||
/// Whether or not the window is fullscreen.
|
|
||||||
///
|
|
||||||
virtual bool is_fullscreen() const = 0;
|
|
||||||
|
|
||||||
///
|
|
||||||
/// The DPI scale of the window.
|
|
||||||
///
|
|
||||||
virtual double scale() const = 0;
|
|
||||||
|
|
||||||
///
|
|
||||||
/// Set the window title.
|
|
||||||
///
|
|
||||||
virtual void SetTitle(const char* title) = 0;
|
|
||||||
|
|
||||||
///
|
|
||||||
/// Set the cursor.
|
|
||||||
///
|
|
||||||
virtual void SetCursor(ultralight::Cursor cursor) = 0;
|
|
||||||
|
|
||||||
///
|
|
||||||
/// Close the window.
|
|
||||||
///
|
|
||||||
virtual void Close() = 0;
|
|
||||||
|
|
||||||
///
|
|
||||||
/// Convert device coordinates to pixels using the current DPI scale.
|
|
||||||
///
|
|
||||||
virtual int DeviceToPixels(int val) const = 0;
|
|
||||||
|
|
||||||
///
|
|
||||||
/// Convert pixels to device coordinates using the current DPI scale.
|
|
||||||
///
|
|
||||||
virtual int PixelsToDevice(int val) const = 0;
|
|
||||||
|
|
||||||
protected:
|
|
||||||
virtual ~Window();
|
|
||||||
virtual OverlayManager* overlay_manager() const = 0;
|
|
||||||
|
|
||||||
friend class OverlayImpl;
|
|
||||||
};
|
|
||||||
|
|
||||||
} // namespace ultralight
|
|
|
@ -1,269 +0,0 @@
|
||||||
///
|
|
||||||
/// @file Bitmap.h
|
|
||||||
///
|
|
||||||
/// @brief The header for the Bitmap class.
|
|
||||||
///
|
|
||||||
/// @author
|
|
||||||
///
|
|
||||||
/// This file is a part of Ultralight, a fast, lightweight, HTML UI engine
|
|
||||||
///
|
|
||||||
/// Website: <http://ultralig.ht>
|
|
||||||
///
|
|
||||||
/// Copyright (C) 2019 Ultralight, Inc. All rights reserved.
|
|
||||||
///
|
|
||||||
#pragma once
|
|
||||||
#include <Ultralight/Defines.h>
|
|
||||||
#include <Ultralight/RefPtr.h>
|
|
||||||
#include <Ultralight/Geometry.h>
|
|
||||||
|
|
||||||
namespace ultralight {
|
|
||||||
|
|
||||||
#pragma pack(push, 1)
|
|
||||||
|
|
||||||
///
|
|
||||||
/// The various Bitmap formats.
|
|
||||||
///
|
|
||||||
enum UExport BitmapFormat {
|
|
||||||
/**
|
|
||||||
* Alpha channel only, 8-bits per pixel.
|
|
||||||
*
|
|
||||||
* Encoding: 8-bits per channel, unsigned normalized.
|
|
||||||
*
|
|
||||||
* Color-space: Linear (no gamma), alpha-coverage only.
|
|
||||||
*/
|
|
||||||
kBitmapFormat_A8_UNORM,
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Blue Green Red Alpha channels, 32-bits per pixel.
|
|
||||||
*
|
|
||||||
* Encoding: 8-bits per channel, unsigned normalized.
|
|
||||||
*
|
|
||||||
* Color-space: sRGB gamma with premultiplied linear alpha channel.
|
|
||||||
*
|
|
||||||
* NOTE: Alpha is premultiplied with BGR channels _before_ sRGB gamma is
|
|
||||||
* applied so we can use sRGB conversion hardware and perform all
|
|
||||||
* blending in linear space on GPU.
|
|
||||||
*/
|
|
||||||
kBitmapFormat_BGRA8_UNORM_SRGB,
|
|
||||||
};
|
|
||||||
|
|
||||||
///
|
|
||||||
/// Macro to get the bytes per pixel from a BitmapFormat
|
|
||||||
///
|
|
||||||
#define GetBytesPerPixel(x) (x == kBitmapFormat_A8_UNORM? 1 : 4)
|
|
||||||
|
|
||||||
///
|
|
||||||
/// @brief Bitmap container with basic blitting and conversion routines.
|
|
||||||
///
|
|
||||||
class UExport Bitmap : public RefCounted {
|
|
||||||
public:
|
|
||||||
///
|
|
||||||
/// Create an empty Bitmap. No pixels will be allocated.
|
|
||||||
///
|
|
||||||
static Ref<Bitmap> Create();
|
|
||||||
|
|
||||||
///
|
|
||||||
/// Create a Bitmap with a certain configuration. Pixels will be allocated
|
|
||||||
/// but not initialized.
|
|
||||||
///
|
|
||||||
/// @param width The width in pixels.
|
|
||||||
///
|
|
||||||
/// @param height The height in pixels.
|
|
||||||
///
|
|
||||||
/// @param format The pixel format to use.
|
|
||||||
///
|
|
||||||
/// @return A ref-pointer to a new Bitmap instance.
|
|
||||||
///
|
|
||||||
static Ref<Bitmap> Create(uint32_t width, uint32_t height,
|
|
||||||
BitmapFormat format);
|
|
||||||
|
|
||||||
///
|
|
||||||
/// Create a Bitmap with existing pixels and configuration.
|
|
||||||
///
|
|
||||||
/// @param width The width in pixels.
|
|
||||||
///
|
|
||||||
/// @param height The height in pixels.
|
|
||||||
///
|
|
||||||
/// @param format The pixel format to use.
|
|
||||||
///
|
|
||||||
/// @param row_bytes The number of bytes between each row (note that this
|
|
||||||
/// value should be >= width * bytes_per_pixel).
|
|
||||||
///
|
|
||||||
/// @param pixels Pointer to raw pixel buffer.
|
|
||||||
///
|
|
||||||
/// @param size Size of the raw pixel buffer.
|
|
||||||
///
|
|
||||||
/// @param should_copy Whether or not a copy should be made of the pixels.
|
|
||||||
/// If this is false, the returned Bitmap will use the
|
|
||||||
/// raw pixels passed in as its own, but you are still
|
|
||||||
/// responsible for destroying your buffer afterwards.
|
|
||||||
///
|
|
||||||
/// @param fixup_gamma Whether or not we should reinterpret the source
|
|
||||||
/// as an sRGB bitmap with premultiplied alpha applied
|
|
||||||
/// after the gamma function (typical of PNGs). We
|
|
||||||
/// expect all premultiplication to be applied before
|
|
||||||
/// the gamma function so we can blend properly in
|
|
||||||
/// linear space. Only valid for
|
|
||||||
/// kBitmapFormat_BGRA8_UNORM_SRGB.
|
|
||||||
///
|
|
||||||
/// @return A ref-pointer to a new Bitmap instance.
|
|
||||||
///
|
|
||||||
static Ref<Bitmap> Create(uint32_t width, uint32_t height,
|
|
||||||
BitmapFormat format, uint32_t row_bytes,
|
|
||||||
const void* pixels, size_t size,
|
|
||||||
bool should_copy = true, bool fixup_gamma = false);
|
|
||||||
|
|
||||||
///
|
|
||||||
/// Create a bitmap from a deep copy of another Bitmap.
|
|
||||||
///
|
|
||||||
static Ref<Bitmap> Create(const Bitmap& bitmap);
|
|
||||||
|
|
||||||
///
|
|
||||||
/// Get the width in pixels.
|
|
||||||
///
|
|
||||||
virtual uint32_t width() const = 0;
|
|
||||||
|
|
||||||
///
|
|
||||||
/// Get the height in pixels.
|
|
||||||
///
|
|
||||||
virtual uint32_t height() const = 0;
|
|
||||||
|
|
||||||
///
|
|
||||||
/// Get the bounds as an IntRect
|
|
||||||
///
|
|
||||||
virtual IntRect bounds() const = 0;
|
|
||||||
|
|
||||||
///
|
|
||||||
/// Get the pixel format.
|
|
||||||
///
|
|
||||||
virtual BitmapFormat format() const = 0;
|
|
||||||
|
|
||||||
///
|
|
||||||
/// Get the number of bytes per pixel.
|
|
||||||
///
|
|
||||||
virtual uint32_t bpp() const = 0;
|
|
||||||
|
|
||||||
///
|
|
||||||
/// Get the number of bytes between each row (this is always >= width * bpp)
|
|
||||||
///
|
|
||||||
virtual uint32_t row_bytes() const = 0;
|
|
||||||
|
|
||||||
///
|
|
||||||
/// Get the size in bytes of the pixel buffer.
|
|
||||||
///
|
|
||||||
virtual size_t size() const = 0;
|
|
||||||
|
|
||||||
///
|
|
||||||
/// Whether or not this Bitmap owns the pixel buffer and will destroy it
|
|
||||||
/// at the end of its lifetime.
|
|
||||||
///
|
|
||||||
virtual bool owns_pixels() const = 0;
|
|
||||||
|
|
||||||
///
|
|
||||||
/// Lock the pixel buffer for reading/writing.
|
|
||||||
///
|
|
||||||
/// @return A pointer to the pixel buffer.
|
|
||||||
///
|
|
||||||
virtual void* LockPixels() = 0;
|
|
||||||
|
|
||||||
///
|
|
||||||
/// Unlock the pixel buffer.
|
|
||||||
///
|
|
||||||
virtual void UnlockPixels() = 0;
|
|
||||||
|
|
||||||
///
|
|
||||||
/// Lock the pixel buffer for reading/writing. (const)
|
|
||||||
///
|
|
||||||
/// @return A const pointer to the pixel buffer.
|
|
||||||
///
|
|
||||||
virtual const void* LockPixels() const = 0;
|
|
||||||
|
|
||||||
///
|
|
||||||
/// Unlock the pixel buffer. (const)
|
|
||||||
///
|
|
||||||
virtual void UnlockPixels() const = 0;
|
|
||||||
|
|
||||||
///
|
|
||||||
/// Get the raw pixel buffer.
|
|
||||||
///
|
|
||||||
/// @note You should only call this if pixels are already locked.
|
|
||||||
///
|
|
||||||
virtual void* raw_pixels() = 0;
|
|
||||||
|
|
||||||
///
|
|
||||||
/// Whether or not this Bitmap is empty (no pixels allocated).
|
|
||||||
///
|
|
||||||
virtual bool IsEmpty() const = 0;
|
|
||||||
|
|
||||||
///
|
|
||||||
/// Erase the Bitmap (set all pixels to 0).
|
|
||||||
///
|
|
||||||
virtual void Erase() = 0;
|
|
||||||
|
|
||||||
///
|
|
||||||
/// Assign another bitmap to this one.
|
|
||||||
///
|
|
||||||
/// @param bitmap The bitmap to copy from.
|
|
||||||
///
|
|
||||||
virtual void Set(Ref<Bitmap> bitmap) = 0;
|
|
||||||
|
|
||||||
///
|
|
||||||
/// Draw another bitmap to this bitmap.
|
|
||||||
///
|
|
||||||
/// @note Formats do not need to match. Bitmap formats will be converted
|
|
||||||
/// to one another automatically. Note that when converting from
|
|
||||||
/// BGRA8 to A8, only the Blue channel will be used.
|
|
||||||
///
|
|
||||||
/// @param src_rect The source rectangle, relative to src bitmap.
|
|
||||||
///
|
|
||||||
/// @param dest_rect The destination rectangle, relative to this bitmap.
|
|
||||||
///
|
|
||||||
/// @param src The source bitmap.
|
|
||||||
///
|
|
||||||
/// @param pad_repeat Whether or not we should pad the drawn bitmap by one
|
|
||||||
/// pixel of repeated edge pixels from the source bitmap.
|
|
||||||
///
|
|
||||||
/// @return Whether or not the operation succeeded (this can fail if the
|
|
||||||
/// src_rect and/or dest_rect are invalid, or if their total
|
|
||||||
/// dimensions do not match).
|
|
||||||
///
|
|
||||||
virtual bool DrawBitmap(IntRect src_rect, IntRect dest_rect,
|
|
||||||
Ref<Bitmap> src, bool pad_repeat) = 0;
|
|
||||||
|
|
||||||
///
|
|
||||||
/// Write this Bitmap out to a PNG image. (mainly used for Debug)
|
|
||||||
///
|
|
||||||
/// @param path The filepath to write to (opened with fopen())
|
|
||||||
///
|
|
||||||
/// @return Whether or not the operation succeeded.
|
|
||||||
///
|
|
||||||
virtual bool WritePNG(const char* path) = 0;
|
|
||||||
|
|
||||||
|
|
||||||
///
|
|
||||||
/// Make a resized copy of this bitmap by writing to a pre-allocated
|
|
||||||
/// destination bitmap.
|
|
||||||
///
|
|
||||||
/// @param destination The bitmap to store the result in, the width and
|
|
||||||
/// height of the destination will be used.
|
|
||||||
///
|
|
||||||
/// @param high_quality Whether or not a high quality resampling will be
|
|
||||||
/// used during the resize. (Otherwise, just uses fast
|
|
||||||
/// nearest-neighbor sampling)
|
|
||||||
///
|
|
||||||
/// @return Whether or not the operation succeeded. This operation is only
|
|
||||||
/// valid if both formats are kBitmapFormat_BGRA8_UNORM_SRGB and
|
|
||||||
/// both the source and destination are non-empty.
|
|
||||||
///
|
|
||||||
virtual bool Resample(Ref<Bitmap> destination, bool high_quality) = 0;
|
|
||||||
|
|
||||||
protected:
|
|
||||||
Bitmap();
|
|
||||||
virtual ~Bitmap();
|
|
||||||
Bitmap(const Bitmap&);
|
|
||||||
void operator=(const Bitmap&);
|
|
||||||
};
|
|
||||||
|
|
||||||
#pragma pack(pop)
|
|
||||||
|
|
||||||
} // namespace ultralight
|
|
|
@ -1,47 +0,0 @@
|
||||||
///
|
|
||||||
/// @file Buffer.h
|
|
||||||
///
|
|
||||||
/// @brief The header for the Buffer class.
|
|
||||||
///
|
|
||||||
/// @author
|
|
||||||
///
|
|
||||||
/// This file is a part of Ultralight, a fast, lightweight, HTML UI engine
|
|
||||||
///
|
|
||||||
/// Website: <http://ultralig.ht>
|
|
||||||
///
|
|
||||||
/// Copyright (C) 2019 Ultralight, Inc. All rights reserved.
|
|
||||||
///
|
|
||||||
#pragma once
|
|
||||||
#include <Ultralight/Defines.h>
|
|
||||||
#include <Ultralight/RefPtr.h>
|
|
||||||
|
|
||||||
namespace ultralight {
|
|
||||||
|
|
||||||
///
|
|
||||||
/// A fixed-size byte container for passing data around.
|
|
||||||
///
|
|
||||||
class UExport Buffer : public RefCounted {
|
|
||||||
public:
|
|
||||||
///
|
|
||||||
/// Create a Buffer, a copy of data is made.
|
|
||||||
///
|
|
||||||
static Ref<Buffer> Create(const void* data, size_t size);
|
|
||||||
|
|
||||||
///
|
|
||||||
/// Get a pointer to raw byte data.
|
|
||||||
///
|
|
||||||
virtual void* data() = 0;
|
|
||||||
|
|
||||||
///
|
|
||||||
/// Get the size in bytes.
|
|
||||||
///
|
|
||||||
virtual size_t size() const = 0;
|
|
||||||
|
|
||||||
protected:
|
|
||||||
Buffer();
|
|
||||||
virtual ~Buffer();
|
|
||||||
Buffer(const Buffer&);
|
|
||||||
void operator=(const Buffer&);
|
|
||||||
};
|
|
||||||
|
|
||||||
} // namespace ultralight
|
|
|
@ -1,79 +0,0 @@
|
||||||
///
|
|
||||||
/// @file Defines.h
|
|
||||||
///
|
|
||||||
/// @brief Common platform definitions
|
|
||||||
///
|
|
||||||
/// @author
|
|
||||||
///
|
|
||||||
/// This file is a part of Ultralight, a fast, lightweight, HTML UI engine
|
|
||||||
///
|
|
||||||
/// Website: <http://ultralig.ht>
|
|
||||||
///
|
|
||||||
/// Copyright (C) 2019 Ultralight, Inc. All rights reserved.
|
|
||||||
///
|
|
||||||
#pragma once
|
|
||||||
|
|
||||||
// Needed for limit defines, like INTMAX_MAX, which is used by the std C++ library
|
|
||||||
#ifndef __STDC_LIMIT_MACROS
|
|
||||||
#define __STDC_LIMIT_MACROS
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#include <cstdint>
|
|
||||||
#include <cstddef>
|
|
||||||
#include <limits.h>
|
|
||||||
|
|
||||||
#ifdef SWIG
|
|
||||||
#define UExport
|
|
||||||
#else
|
|
||||||
|
|
||||||
// Require C++11 Support
|
|
||||||
#if defined(_MSC_VER)
|
|
||||||
# if _MSC_VER < 1800
|
|
||||||
# error This project needs at least Visual Studio 2013 to build
|
|
||||||
# endif
|
|
||||||
#elif __cplusplus <= 199711L
|
|
||||||
# error This project can only be compiled with a compiler that supports C++11
|
|
||||||
#endif
|
|
||||||
|
|
||||||
|
|
||||||
#if defined(__WIN32__) || defined(_WIN32)
|
|
||||||
# if defined(ULTRALIGHT_IMPLEMENTATION)
|
|
||||||
# define UExport __declspec(dllexport)
|
|
||||||
# else
|
|
||||||
# define UExport __declspec(dllimport)
|
|
||||||
# endif
|
|
||||||
#define _thread_local __declspec(thread)
|
|
||||||
#ifndef _NATIVE_WCHAR_T_DEFINED
|
|
||||||
#define DISABLE_NATIVE_WCHAR_T
|
|
||||||
#endif
|
|
||||||
#else
|
|
||||||
# define UExport __attribute__((visibility("default")))
|
|
||||||
#define _thread_local __thread
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#define ULTRALIGHT_VERSION "1.0.0"
|
|
||||||
|
|
||||||
///
|
|
||||||
/// @mainpage Ultralight C++ API Reference
|
|
||||||
///
|
|
||||||
/// @section intro_sec Introduction
|
|
||||||
///
|
|
||||||
/// Hi there, welcome to the C++ API Reference for Ultralight!
|
|
||||||
///
|
|
||||||
/// Ultralight is a fast, lightweight HTML UI engine for desktop apps.
|
|
||||||
///
|
|
||||||
/// If this is your first time exploring the API, we recommend
|
|
||||||
/// starting with ultralight::Renderer and ultralight::View.
|
|
||||||
///
|
|
||||||
///
|
|
||||||
/// @section usefullinks_sec Useful Links
|
|
||||||
/// - Home: <https://ultralig.ht> -- Get the latest binaries
|
|
||||||
/// - Docs: <https://docs.ultralig.ht> -- API overview, code snippets, tutorials and more!
|
|
||||||
/// - Slack: <http://chat.ultralig.ht/> -- Stuck? Have questions? Come chat with us!
|
|
||||||
/// - GitHub: <https://github.com/ultralight-ux/ultralight> -- Report issues and browse code
|
|
||||||
///
|
|
||||||
/// @section copyright_sec Copyright
|
|
||||||
/// Documentation is copyright (C) 2019 Ultralight, Inc. All rights reserved.
|
|
||||||
///
|
|
|
@ -1,676 +0,0 @@
|
||||||
///
|
|
||||||
/// @file Geometry.h
|
|
||||||
///
|
|
||||||
/// @brief The header for various geometry definitions and helpers
|
|
||||||
///
|
|
||||||
/// @author
|
|
||||||
///
|
|
||||||
/// This file is a part of Ultralight, a fast, lightweight, HTML UI engine
|
|
||||||
///
|
|
||||||
/// Website: <http://ultralig.ht>
|
|
||||||
///
|
|
||||||
/// Copyright (C) 2019 Ultralight, Inc. All rights reserved.
|
|
||||||
///
|
|
||||||
#pragma once
|
|
||||||
#include <Ultralight/Defines.h>
|
|
||||||
#include <memory.h>
|
|
||||||
#include <cmath>
|
|
||||||
#include <algorithm>
|
|
||||||
|
|
||||||
namespace ultralight {
|
|
||||||
|
|
||||||
///
|
|
||||||
/// 2D Vector Helper
|
|
||||||
///
|
|
||||||
struct UExport vec2 {
|
|
||||||
union {
|
|
||||||
float value[2];
|
|
||||||
struct { float x, y; };
|
|
||||||
};
|
|
||||||
|
|
||||||
inline vec2() {}
|
|
||||||
|
|
||||||
inline vec2(float x, float y) : x(x), y(y) {}
|
|
||||||
|
|
||||||
inline vec2(float x) : x(x), y(x) {}
|
|
||||||
|
|
||||||
inline vec2 yx() const { return { y, x }; }
|
|
||||||
|
|
||||||
inline vec2 xx() const { return { x, x }; }
|
|
||||||
|
|
||||||
inline vec2 yy() const { return { y, y }; }
|
|
||||||
|
|
||||||
inline friend vec2 operator+(vec2 lhs, const vec2& rhs) { lhs += rhs; return lhs; }
|
|
||||||
|
|
||||||
inline friend vec2 operator-(vec2 lhs, const vec2& rhs) { lhs -= rhs; return lhs; }
|
|
||||||
|
|
||||||
inline friend vec2 operator*(vec2 lhs, const vec2& rhs) { lhs *= rhs; return lhs; }
|
|
||||||
|
|
||||||
inline friend vec2 operator/(vec2 lhs, const vec2& rhs) { lhs /= rhs; return lhs; }
|
|
||||||
|
|
||||||
inline friend vec2 operator+(vec2 lhs, float rhs) { lhs += rhs; return lhs; }
|
|
||||||
|
|
||||||
inline friend vec2 operator-(vec2 lhs, float rhs) { lhs -= rhs; return lhs; }
|
|
||||||
|
|
||||||
inline friend vec2 operator*(vec2 lhs, float rhs) { lhs *= rhs; return lhs; }
|
|
||||||
|
|
||||||
inline friend vec2 operator/(vec2 lhs, float rhs) { lhs /= rhs; return lhs; }
|
|
||||||
|
|
||||||
inline vec2& operator+=(const vec2& rhs) {
|
|
||||||
value[0] += rhs.value[0];
|
|
||||||
value[1] += rhs.value[1];
|
|
||||||
return *this;
|
|
||||||
}
|
|
||||||
|
|
||||||
inline vec2& operator-=(const vec2& rhs) {
|
|
||||||
value[0] -= rhs.value[0];
|
|
||||||
value[1] -= rhs.value[1];
|
|
||||||
return *this;
|
|
||||||
}
|
|
||||||
|
|
||||||
inline vec2& operator*=(const vec2& rhs) {
|
|
||||||
value[0] *= rhs.value[0];
|
|
||||||
value[1] *= rhs.value[1];
|
|
||||||
return *this;
|
|
||||||
}
|
|
||||||
|
|
||||||
inline vec2& operator/=(const vec2& rhs) {
|
|
||||||
value[0] /= rhs.value[0];
|
|
||||||
value[1] /= rhs.value[1];
|
|
||||||
return *this;
|
|
||||||
}
|
|
||||||
|
|
||||||
inline vec2& operator+=(float rhs) {
|
|
||||||
value[0] += rhs;
|
|
||||||
value[1] += rhs;
|
|
||||||
return *this;
|
|
||||||
}
|
|
||||||
|
|
||||||
inline vec2& operator-=(float rhs) {
|
|
||||||
value[0] -= rhs;
|
|
||||||
value[1] -= rhs;
|
|
||||||
return *this;
|
|
||||||
}
|
|
||||||
|
|
||||||
inline vec2& operator*=(float rhs) {
|
|
||||||
value[0] *= rhs;
|
|
||||||
value[1] *= rhs;
|
|
||||||
return *this;
|
|
||||||
}
|
|
||||||
|
|
||||||
inline vec2& operator/=(float rhs) {
|
|
||||||
value[0] /= rhs;
|
|
||||||
value[1] /= rhs;
|
|
||||||
return *this;
|
|
||||||
}
|
|
||||||
|
|
||||||
inline friend bool operator==(const vec2& a, const vec2& b) {
|
|
||||||
return !memcmp(&a, &b, sizeof(a));
|
|
||||||
}
|
|
||||||
|
|
||||||
inline friend bool operator!=(const vec2& a, const vec2& b) {
|
|
||||||
return !(a == b);
|
|
||||||
}
|
|
||||||
|
|
||||||
inline friend vec2 min_(const vec2& a, const vec2& b) {
|
|
||||||
return{ (b.x < a.x) ? b.x : a.x,
|
|
||||||
(b.y < a.y) ? b.y : a.y };
|
|
||||||
}
|
|
||||||
|
|
||||||
inline friend vec2 max_(const vec2& a, const vec2& b) {
|
|
||||||
return{ (a.x < b.x) ? b.x : a.x,
|
|
||||||
(a.y < b.y) ? b.y : a.y };
|
|
||||||
}
|
|
||||||
|
|
||||||
inline friend vec2 clamp(const vec2& x, const vec2& minVal, const vec2& maxVal) {
|
|
||||||
return min_(max_(x, minVal), maxVal);
|
|
||||||
}
|
|
||||||
|
|
||||||
inline friend vec2 mix(const vec2& a, const vec2& b, float t) {
|
|
||||||
return a * (1.0f - t) + b * t;
|
|
||||||
}
|
|
||||||
|
|
||||||
inline friend float length(const vec2& a) {
|
|
||||||
return sqrtf(a.x * a.x + a.y * a.y);
|
|
||||||
}
|
|
||||||
|
|
||||||
// squared length
|
|
||||||
inline friend float length2(const vec2& a) {
|
|
||||||
return dot(a, a);
|
|
||||||
}
|
|
||||||
|
|
||||||
inline friend float distance(const vec2& a, const vec2& b) {
|
|
||||||
return length(a - b);
|
|
||||||
}
|
|
||||||
|
|
||||||
// squared distance
|
|
||||||
inline friend float distance2(const vec2& a, const vec2& b) {
|
|
||||||
return length2(a - b);
|
|
||||||
}
|
|
||||||
|
|
||||||
inline friend vec2 normalize(const vec2& a) {
|
|
||||||
return a / length(a);
|
|
||||||
}
|
|
||||||
|
|
||||||
inline friend float dot(const vec2& a, const vec2& b) {
|
|
||||||
return a.x * b.x + a.y * b.y;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
///
|
|
||||||
/// 3D Vector Helper
|
|
||||||
///
|
|
||||||
struct UExport vec3 {
|
|
||||||
union {
|
|
||||||
float value[3];
|
|
||||||
struct { float x, y, z; };
|
|
||||||
};
|
|
||||||
|
|
||||||
inline vec3() {}
|
|
||||||
|
|
||||||
inline vec3(float x, float y, float z) : x(x), y(y), z(z) {}
|
|
||||||
|
|
||||||
inline vec3(float x) : x(x), y(x), z(x) {}
|
|
||||||
|
|
||||||
inline friend vec3 operator+(vec3 lhs, const vec3& rhs) { lhs += rhs; return lhs; }
|
|
||||||
|
|
||||||
inline friend vec3 operator-(vec3 lhs, const vec3& rhs) { lhs -= rhs; return lhs; }
|
|
||||||
|
|
||||||
inline friend vec3 operator*(vec3 lhs, const vec3& rhs) { lhs *= rhs; return lhs; }
|
|
||||||
|
|
||||||
inline friend vec3 operator/(vec3 lhs, const vec3& rhs) { lhs /= rhs; return lhs; }
|
|
||||||
|
|
||||||
inline friend vec3 operator+(vec3 lhs, float rhs) { lhs += rhs; return lhs; }
|
|
||||||
|
|
||||||
inline friend vec3 operator-(vec3 lhs, float rhs) { lhs -= rhs; return lhs; }
|
|
||||||
|
|
||||||
inline friend vec3 operator*(vec3 lhs, float rhs) { lhs *= rhs; return lhs; }
|
|
||||||
|
|
||||||
inline friend vec3 operator/(vec3 lhs, float rhs) { lhs /= rhs; return lhs; }
|
|
||||||
|
|
||||||
inline vec3& operator+=(const vec3& rhs) {
|
|
||||||
value[0] += rhs.value[0];
|
|
||||||
value[1] += rhs.value[1];
|
|
||||||
value[2] += rhs.value[2];
|
|
||||||
return *this;
|
|
||||||
}
|
|
||||||
|
|
||||||
inline vec3& operator-=(const vec3& rhs) {
|
|
||||||
value[0] -= rhs.value[0];
|
|
||||||
value[1] -= rhs.value[1];
|
|
||||||
value[2] -= rhs.value[2];
|
|
||||||
return *this;
|
|
||||||
}
|
|
||||||
|
|
||||||
inline vec3& operator*=(const vec3& rhs) {
|
|
||||||
value[0] *= rhs.value[0];
|
|
||||||
value[1] *= rhs.value[1];
|
|
||||||
value[2] *= rhs.value[2];
|
|
||||||
return *this;
|
|
||||||
}
|
|
||||||
|
|
||||||
inline vec3& operator/=(const vec3& rhs) {
|
|
||||||
value[0] /= rhs.value[0];
|
|
||||||
value[1] /= rhs.value[1];
|
|
||||||
value[2] /= rhs.value[2];
|
|
||||||
return *this;
|
|
||||||
}
|
|
||||||
|
|
||||||
inline vec3& operator+=(float rhs) {
|
|
||||||
value[0] += rhs;
|
|
||||||
value[1] += rhs;
|
|
||||||
value[2] += rhs;
|
|
||||||
return *this;
|
|
||||||
}
|
|
||||||
|
|
||||||
inline vec3& operator-=(float rhs) {
|
|
||||||
value[0] -= rhs;
|
|
||||||
value[1] -= rhs;
|
|
||||||
value[2] -= rhs;
|
|
||||||
return *this;
|
|
||||||
}
|
|
||||||
|
|
||||||
inline vec3& operator*=(float rhs) {
|
|
||||||
value[0] *= rhs;
|
|
||||||
value[1] *= rhs;
|
|
||||||
value[2] *= rhs;
|
|
||||||
return *this;
|
|
||||||
}
|
|
||||||
|
|
||||||
inline vec3& operator/=(float rhs) {
|
|
||||||
value[0] /= rhs;
|
|
||||||
value[1] /= rhs;
|
|
||||||
value[2] /= rhs;
|
|
||||||
return *this;
|
|
||||||
}
|
|
||||||
|
|
||||||
inline friend bool operator==(const vec3& a, const vec3& b) {
|
|
||||||
return !memcmp(&a, &b, sizeof(a));
|
|
||||||
}
|
|
||||||
|
|
||||||
inline friend bool operator!=(const vec3& a, const vec3& b) {
|
|
||||||
return !(a == b);
|
|
||||||
}
|
|
||||||
|
|
||||||
inline friend vec3 min_(const vec3& a, const vec3& b) {
|
|
||||||
return{ (b.x < a.x) ? b.x : a.x,
|
|
||||||
(b.y < a.y) ? b.y : a.y,
|
|
||||||
(b.z < a.z) ? b.z : a.z };
|
|
||||||
}
|
|
||||||
|
|
||||||
inline friend vec3 max_(const vec3& a, const vec3& b) {
|
|
||||||
return{ (a.x < b.x) ? b.x : a.x,
|
|
||||||
(a.y < b.y) ? b.y : a.y,
|
|
||||||
(a.z < b.z) ? b.z : a.z };
|
|
||||||
}
|
|
||||||
inline friend vec3 clamp(const vec3& x, const vec3& minVal, const vec3& maxVal) {
|
|
||||||
return min_(max_(x, minVal), maxVal);
|
|
||||||
}
|
|
||||||
|
|
||||||
inline friend vec3 mix(const vec3& a, const vec3& b, float t) {
|
|
||||||
return a * (1.0f - t) + b * t;
|
|
||||||
}
|
|
||||||
|
|
||||||
inline friend float length(const vec3& a) {
|
|
||||||
return sqrtf(a.x * a.x + a.y * a.y + a.z * a.z);
|
|
||||||
}
|
|
||||||
|
|
||||||
inline friend float distance(const vec3& a, const vec3& b) {
|
|
||||||
return length(a - b);
|
|
||||||
}
|
|
||||||
|
|
||||||
inline friend vec3 normalize(const vec3& a) {
|
|
||||||
return a / length(a);
|
|
||||||
}
|
|
||||||
|
|
||||||
inline friend float dot(const vec3& a, const vec3& b) {
|
|
||||||
return a.x * b.x + a.y * b.y + a.z * b.z;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
///
|
|
||||||
/// 4D Vector Helper
|
|
||||||
///
|
|
||||||
struct UExport vec4 {
|
|
||||||
union {
|
|
||||||
float value[4];
|
|
||||||
struct { float x, y, z, w; };
|
|
||||||
};
|
|
||||||
|
|
||||||
inline vec4() {}
|
|
||||||
|
|
||||||
inline vec4(float x, float y, float z, float w) : x(x), y(y), z(z), w(w) {}
|
|
||||||
|
|
||||||
inline vec4(float x) : x(x), y(x), z(x), w(x) {}
|
|
||||||
|
|
||||||
inline vec4(const float x[4]) { memcpy(value, x, sizeof(value)); }
|
|
||||||
|
|
||||||
inline friend bool operator==(const vec4& a, const vec4& b) {
|
|
||||||
return !memcmp(&a, &b, sizeof(a));
|
|
||||||
}
|
|
||||||
|
|
||||||
inline friend bool operator!=(const vec4& a, const vec4& b) {
|
|
||||||
return !(a == b);
|
|
||||||
}
|
|
||||||
|
|
||||||
inline friend vec4 operator+(vec4 lhs, const vec4& rhs) { lhs += rhs; return lhs; }
|
|
||||||
|
|
||||||
inline friend vec4 operator-(vec4 lhs, const vec4& rhs) { lhs -= rhs; return lhs; }
|
|
||||||
|
|
||||||
inline friend vec4 operator*(vec4 lhs, const vec4& rhs) { lhs *= rhs; return lhs; }
|
|
||||||
|
|
||||||
inline friend vec4 operator/(vec4 lhs, const vec4& rhs) { lhs /= rhs; return lhs; }
|
|
||||||
|
|
||||||
inline friend vec4 operator+(vec4 lhs, float rhs) { lhs += rhs; return lhs; }
|
|
||||||
|
|
||||||
inline friend vec4 operator-(vec4 lhs, float rhs) { lhs -= rhs; return lhs; }
|
|
||||||
|
|
||||||
inline friend vec4 operator*(vec4 lhs, float rhs) { lhs *= rhs; return lhs; }
|
|
||||||
|
|
||||||
inline friend vec4 operator/(vec4 lhs, float rhs) { lhs /= rhs; return lhs; }
|
|
||||||
|
|
||||||
inline vec4& operator+=(const vec4& rhs) {
|
|
||||||
value[0] += rhs.value[0];
|
|
||||||
value[1] += rhs.value[1];
|
|
||||||
value[2] += rhs.value[2];
|
|
||||||
value[3] += rhs.value[3];
|
|
||||||
return *this;
|
|
||||||
}
|
|
||||||
|
|
||||||
inline vec4& operator-=(const vec4& rhs) {
|
|
||||||
value[0] -= rhs.value[0];
|
|
||||||
value[1] -= rhs.value[1];
|
|
||||||
value[2] -= rhs.value[2];
|
|
||||||
value[3] -= rhs.value[3];
|
|
||||||
return *this;
|
|
||||||
}
|
|
||||||
|
|
||||||
inline vec4& operator*=(const vec4& rhs) {
|
|
||||||
value[0] *= rhs.value[0];
|
|
||||||
value[1] *= rhs.value[1];
|
|
||||||
value[2] *= rhs.value[2];
|
|
||||||
value[3] *= rhs.value[3];
|
|
||||||
return *this;
|
|
||||||
}
|
|
||||||
|
|
||||||
inline vec4& operator/=(const vec4& rhs) {
|
|
||||||
value[0] /= rhs.value[0];
|
|
||||||
value[1] /= rhs.value[1];
|
|
||||||
value[2] /= rhs.value[2];
|
|
||||||
value[3] /= rhs.value[3];
|
|
||||||
return *this;
|
|
||||||
}
|
|
||||||
|
|
||||||
inline vec4& operator+=(float rhs) {
|
|
||||||
value[0] += rhs;
|
|
||||||
value[1] += rhs;
|
|
||||||
value[2] += rhs;
|
|
||||||
value[3] += rhs;
|
|
||||||
return *this;
|
|
||||||
}
|
|
||||||
|
|
||||||
inline vec4& operator-=(float rhs) {
|
|
||||||
value[0] -= rhs;
|
|
||||||
value[1] -= rhs;
|
|
||||||
value[2] -= rhs;
|
|
||||||
value[3] -= rhs;
|
|
||||||
return *this;
|
|
||||||
}
|
|
||||||
|
|
||||||
inline vec4& operator*=(float rhs) {
|
|
||||||
value[0] *= rhs;
|
|
||||||
value[1] *= rhs;
|
|
||||||
value[2] *= rhs;
|
|
||||||
value[3] *= rhs;
|
|
||||||
return *this;
|
|
||||||
}
|
|
||||||
|
|
||||||
inline vec4& operator/=(float rhs) {
|
|
||||||
value[0] /= rhs;
|
|
||||||
value[1] /= rhs;
|
|
||||||
value[2] /= rhs;
|
|
||||||
value[3] /= rhs;
|
|
||||||
return *this;
|
|
||||||
}
|
|
||||||
|
|
||||||
inline friend vec4 min_(const vec4& a, const vec4& b) {
|
|
||||||
return{ (b.x < a.x) ? b.x : a.x,
|
|
||||||
(b.y < a.y) ? b.y : a.y,
|
|
||||||
(b.z < a.z) ? b.z : a.z,
|
|
||||||
(b.w < a.w) ? b.w : a.w };
|
|
||||||
}
|
|
||||||
|
|
||||||
inline friend vec4 max_(const vec4& a, const vec4& b) {
|
|
||||||
return{ (a.x < b.x) ? b.x : a.x,
|
|
||||||
(a.y < b.y) ? b.y : a.y,
|
|
||||||
(a.z < b.z) ? b.z : a.z,
|
|
||||||
(a.w < b.w) ? b.w : a.w };
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
///
|
|
||||||
/// Point is typedef'd to a 2D vector
|
|
||||||
///
|
|
||||||
typedef vec2 Point;
|
|
||||||
|
|
||||||
///
|
|
||||||
/// Float Rectangle Helper
|
|
||||||
///
|
|
||||||
struct UExport Rect {
|
|
||||||
union {
|
|
||||||
float value[4];
|
|
||||||
struct { float left, top, right, bottom; };
|
|
||||||
};
|
|
||||||
|
|
||||||
static inline Rect MakeEmpty() {
|
|
||||||
Rect result;
|
|
||||||
result.SetEmpty();
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
inline float width() const { return right - left; }
|
|
||||||
inline float height() const { return bottom - top; }
|
|
||||||
inline float x() const { return left; }
|
|
||||||
inline float y() const { return top; }
|
|
||||||
inline float center_x() const { return (left + right) * 0.5f; }
|
|
||||||
inline float center_y() const { return (top + bottom) * 0.5f; }
|
|
||||||
|
|
||||||
inline Point origin() const { return { left, top }; }
|
|
||||||
|
|
||||||
inline void SetEmpty() {
|
|
||||||
memset(this, 0, sizeof(*this));
|
|
||||||
}
|
|
||||||
|
|
||||||
inline bool IsEmpty() const {
|
|
||||||
return *this == MakeEmpty();
|
|
||||||
}
|
|
||||||
|
|
||||||
inline bool IsValid() const {
|
|
||||||
return width() > 0 && height() > 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
inline void Inset(float dx, float dy) {
|
|
||||||
value[0] += dx;
|
|
||||||
value[1] += dy;
|
|
||||||
value[2] -= dx;
|
|
||||||
value[3] -= dy;
|
|
||||||
}
|
|
||||||
|
|
||||||
inline void Outset(float dx, float dy) {
|
|
||||||
Inset(-dx, -dy);
|
|
||||||
}
|
|
||||||
|
|
||||||
inline void Move(float dx, float dy) {
|
|
||||||
value[0] += dx;
|
|
||||||
value[1] += dy;
|
|
||||||
value[2] += dx;
|
|
||||||
value[3] += dy;
|
|
||||||
}
|
|
||||||
|
|
||||||
inline float area() const {
|
|
||||||
return width() * height();
|
|
||||||
}
|
|
||||||
|
|
||||||
inline void Join(const Rect& rhs) {
|
|
||||||
// if we are empty, just assign
|
|
||||||
if (IsEmpty()) {
|
|
||||||
*this = rhs;
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
if (rhs.value[0] < value[0]) value[0] = rhs.value[0];
|
|
||||||
if (rhs.value[1] < value[1]) value[1] = rhs.value[1];
|
|
||||||
if (rhs.value[2] > value[2]) value[2] = rhs.value[2];
|
|
||||||
if (rhs.value[3] > value[3]) value[3] = rhs.value[3];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
inline void Join(const Point& p) {
|
|
||||||
// if we are empty, just assign
|
|
||||||
if (IsEmpty()) {
|
|
||||||
*this = { p.x, p.y, p.x, p.y };
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
if (p.x < value[0]) value[0] = p.x;
|
|
||||||
if (p.y < value[1]) value[1] = p.y;
|
|
||||||
if (p.x > value[2]) value[2] = p.x;
|
|
||||||
if (p.y > value[3]) value[3] = p.y;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
inline bool Contains(const Point& p) const {
|
|
||||||
return p.x >= left && p.x <= right &&
|
|
||||||
p.y >= top && p.y <= bottom;
|
|
||||||
}
|
|
||||||
|
|
||||||
inline bool Contains(const Rect& r) const {
|
|
||||||
return left <= r.left && top <= r.top &&
|
|
||||||
right >= r.right && bottom >= r.bottom;
|
|
||||||
}
|
|
||||||
|
|
||||||
inline bool Intersects(const Rect& rhs) const {
|
|
||||||
return !(rhs.left > right ||
|
|
||||||
rhs.right < left ||
|
|
||||||
rhs.top > bottom ||
|
|
||||||
rhs.bottom < top);
|
|
||||||
}
|
|
||||||
|
|
||||||
inline Rect Intersect(const Rect& other) const {
|
|
||||||
return{ (left < other.left) ? other.left : left,
|
|
||||||
(top < other.top) ? other.top : top,
|
|
||||||
(other.right < right) ? other.right : right,
|
|
||||||
(other.bottom < bottom) ? other.bottom : bottom };
|
|
||||||
}
|
|
||||||
|
|
||||||
friend inline bool operator==(const Rect& a, const Rect& b) {
|
|
||||||
return !memcmp(&a, &b, sizeof(a));
|
|
||||||
}
|
|
||||||
|
|
||||||
friend inline bool operator!=(const Rect& a, const Rect& b) {
|
|
||||||
return !(a == b);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
///
|
|
||||||
/// Integer Rectangle Helper
|
|
||||||
///
|
|
||||||
struct UExport IntRect {
|
|
||||||
union {
|
|
||||||
int value[4];
|
|
||||||
struct { int left, top, right, bottom; };
|
|
||||||
};
|
|
||||||
|
|
||||||
static inline IntRect MakeEmpty() {
|
|
||||||
IntRect result;
|
|
||||||
result.SetEmpty();
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
inline int width() const { return right - left; }
|
|
||||||
inline int height() const { return bottom - top; }
|
|
||||||
inline int x() const { return left; }
|
|
||||||
inline int y() const { return top; }
|
|
||||||
inline int center_x() const { return (int)std::round((left + right) * 0.5f); }
|
|
||||||
inline int center_y() const { return (int)std::round((top + bottom) * 0.5f); }
|
|
||||||
|
|
||||||
inline Point origin() const { return{ (float)left, (float)top }; }
|
|
||||||
|
|
||||||
inline void SetEmpty() {
|
|
||||||
memset(this, 0, sizeof(*this));
|
|
||||||
}
|
|
||||||
|
|
||||||
inline bool IsEmpty() const {
|
|
||||||
return *this == MakeEmpty();
|
|
||||||
}
|
|
||||||
|
|
||||||
inline bool IsValid() const {
|
|
||||||
return width() > 0 && height() > 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
inline void Inset(int dx, int dy) {
|
|
||||||
value[0] += dx;
|
|
||||||
value[1] += dy;
|
|
||||||
value[2] -= dx;
|
|
||||||
value[3] -= dy;
|
|
||||||
}
|
|
||||||
|
|
||||||
inline void Outset(int dx, int dy) {
|
|
||||||
Inset(-dx, -dy);
|
|
||||||
}
|
|
||||||
|
|
||||||
inline void Move(int dx, int dy) {
|
|
||||||
value[0] += dx;
|
|
||||||
value[1] += dy;
|
|
||||||
value[2] += dx;
|
|
||||||
value[3] += dy;
|
|
||||||
}
|
|
||||||
|
|
||||||
inline int area() const {
|
|
||||||
return width() * height();
|
|
||||||
}
|
|
||||||
|
|
||||||
inline void Join(const IntRect& rhs) {
|
|
||||||
// if we are empty, just assign
|
|
||||||
if (IsEmpty()) {
|
|
||||||
*this = rhs;
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
if (rhs.value[0] < value[0]) value[0] = rhs.value[0];
|
|
||||||
if (rhs.value[1] < value[1]) value[1] = rhs.value[1];
|
|
||||||
if (rhs.value[2] > value[2]) value[2] = rhs.value[2];
|
|
||||||
if (rhs.value[3] > value[3]) value[3] = rhs.value[3];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
inline void Join(const Point& p) {
|
|
||||||
// if we are empty, just assign
|
|
||||||
if (IsEmpty()) {
|
|
||||||
*this = { (int)std::floor(p.x), (int)std::floor(p.y), (int)std::ceil(p.x), (int)std::ceil(p.y) };
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
if ((int)std::floor(p.x) < value[0]) value[0] = (int)std::floor(p.x);
|
|
||||||
if ((int)std::floor(p.y) < value[1]) value[1] = (int)std::floor(p.y);
|
|
||||||
if ((int)std::ceil(p.x) > value[2]) value[2] = (int)std::ceil(p.x);
|
|
||||||
if ((int)std::ceil(p.y) > value[3]) value[3] = (int)std::ceil(p.y);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
inline bool Contains(const Point& p) const {
|
|
||||||
return p.x >= left && p.x <= right &&
|
|
||||||
p.y >= top && p.y <= bottom;
|
|
||||||
}
|
|
||||||
|
|
||||||
inline bool Contains(const IntRect& r) const {
|
|
||||||
return left <= r.left && top <= r.top &&
|
|
||||||
right >= r.right && bottom >= r.bottom;
|
|
||||||
}
|
|
||||||
|
|
||||||
inline bool Intersects(const IntRect& rhs) const {
|
|
||||||
// Since this is mostly used for pixel operations, we only count
|
|
||||||
// intersections that have width and height >= 1.
|
|
||||||
return !(rhs.left > right - 1 ||
|
|
||||||
rhs.right < left ||
|
|
||||||
rhs.top > bottom - 1 ||
|
|
||||||
rhs.bottom < top);
|
|
||||||
}
|
|
||||||
|
|
||||||
inline IntRect Intersect(const IntRect& other) const {
|
|
||||||
return{ (left < other.left) ? other.left : left,
|
|
||||||
(top < other.top) ? other.top : top,
|
|
||||||
(other.right < right) ? other.right : right,
|
|
||||||
(other.bottom < bottom) ? other.bottom : bottom };
|
|
||||||
}
|
|
||||||
|
|
||||||
friend inline bool operator==(const IntRect& a, const IntRect& b) {
|
|
||||||
return !memcmp(&a, &b, sizeof(a));
|
|
||||||
}
|
|
||||||
|
|
||||||
friend inline bool operator!=(const IntRect& a, const IntRect& b) {
|
|
||||||
return !(a == b);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
///
|
|
||||||
/// Rounded Rectangle Helper
|
|
||||||
///
|
|
||||||
struct UExport RoundedRect {
|
|
||||||
Rect rect;
|
|
||||||
float radii_x[4];
|
|
||||||
float radii_y[4];
|
|
||||||
|
|
||||||
void SetEmpty();
|
|
||||||
|
|
||||||
bool IsRounded() const;
|
|
||||||
|
|
||||||
// Negative is inside, positive is outside.
|
|
||||||
float GetSignedDistance(const Point& p) const;
|
|
||||||
|
|
||||||
// Returns whether or not intersection is found. Can fail if the resulting
|
|
||||||
// geometry is not a rounded rectangle.
|
|
||||||
bool Intersect(const RoundedRect& other, RoundedRect& result) const;
|
|
||||||
|
|
||||||
void SnapToPixels();
|
|
||||||
|
|
||||||
Rect CalculateInterior() const;
|
|
||||||
};
|
|
||||||
|
|
||||||
} // namespace ultralight
|
|
|
@ -1,527 +0,0 @@
|
||||||
///
|
|
||||||
/// @file KeyCodes.h
|
|
||||||
///
|
|
||||||
/// @brief The header for the KeyCodes definitions.
|
|
||||||
///
|
|
||||||
/// @author
|
|
||||||
///
|
|
||||||
/// This file is a part of Ultralight, a fast, lightweight, HTML UI engine
|
|
||||||
///
|
|
||||||
/// Website: <http://ultralig.ht>
|
|
||||||
///
|
|
||||||
/// Copyright (C) 2019 Ultralight, Inc. All rights reserved.
|
|
||||||
///
|
|
||||||
#pragma once
|
|
||||||
|
|
||||||
namespace ultralight {
|
|
||||||
|
|
||||||
///
|
|
||||||
/// Namespace containing all the key-code definitions for KeyboardEvent.
|
|
||||||
/// Most of these correspond directly to the key-code values on Windows.
|
|
||||||
///
|
|
||||||
namespace KeyCodes {
|
|
||||||
|
|
||||||
// GK_BACK (08) BACKSPACE key
|
|
||||||
const int GK_BACK = 0x08;
|
|
||||||
|
|
||||||
// GK_TAB (09) TAB key
|
|
||||||
const int GK_TAB = 0x09;
|
|
||||||
|
|
||||||
// GK_CLEAR (0C) CLEAR key
|
|
||||||
const int GK_CLEAR = 0x0C;
|
|
||||||
|
|
||||||
// GK_RETURN (0D)
|
|
||||||
const int GK_RETURN = 0x0D;
|
|
||||||
|
|
||||||
// GK_SHIFT (10) SHIFT key
|
|
||||||
const int GK_SHIFT = 0x10;
|
|
||||||
|
|
||||||
// GK_CONTROL (11) CTRL key
|
|
||||||
const int GK_CONTROL = 0x11;
|
|
||||||
|
|
||||||
// GK_MENU (12) ALT key
|
|
||||||
const int GK_MENU = 0x12;
|
|
||||||
|
|
||||||
// GK_PAUSE (13) PAUSE key
|
|
||||||
const int GK_PAUSE = 0x13;
|
|
||||||
|
|
||||||
// GK_CAPITAL (14) CAPS LOCK key
|
|
||||||
const int GK_CAPITAL = 0x14;
|
|
||||||
|
|
||||||
// GK_KANA (15) Input Method Editor (IME) Kana mode
|
|
||||||
const int GK_KANA = 0x15;
|
|
||||||
|
|
||||||
// GK_HANGUEL (15) IME Hanguel mode (maintained for compatibility; use GK_HANGUL)
|
|
||||||
// GK_HANGUL (15) IME Hangul mode
|
|
||||||
const int GK_HANGUL = 0x15;
|
|
||||||
|
|
||||||
// GK_JUNJA (17) IME Junja mode
|
|
||||||
const int GK_JUNJA = 0x17;
|
|
||||||
|
|
||||||
// GK_FINAL (18) IME final mode
|
|
||||||
const int GK_FINAL = 0x18;
|
|
||||||
|
|
||||||
// GK_HANJA (19) IME Hanja mode
|
|
||||||
const int GK_HANJA = 0x19;
|
|
||||||
|
|
||||||
// GK_KANJI (19) IME Kanji mode
|
|
||||||
const int GK_KANJI = 0x19;
|
|
||||||
|
|
||||||
// GK_ESCAPE (1B) ESC key
|
|
||||||
const int GK_ESCAPE = 0x1B;
|
|
||||||
|
|
||||||
// GK_CONVERT (1C) IME convert
|
|
||||||
const int GK_CONVERT = 0x1C;
|
|
||||||
|
|
||||||
// GK_NONCONVERT (1D) IME nonconvert
|
|
||||||
const int GK_NONCONVERT = 0x1D;
|
|
||||||
|
|
||||||
// GK_ACCEPT (1E) IME accept
|
|
||||||
const int GK_ACCEPT = 0x1E;
|
|
||||||
|
|
||||||
// GK_MODECHANGE (1F) IME mode change request
|
|
||||||
const int GK_MODECHANGE = 0x1F;
|
|
||||||
|
|
||||||
// GK_SPACE (20) SPACEBAR
|
|
||||||
const int GK_SPACE = 0x20;
|
|
||||||
|
|
||||||
// GK_PRIOR (21) PAGE UP key
|
|
||||||
const int GK_PRIOR = 0x21;
|
|
||||||
|
|
||||||
// GK_NEXT (22) PAGE DOWN key
|
|
||||||
const int GK_NEXT = 0x22;
|
|
||||||
|
|
||||||
// GK_END (23) END key
|
|
||||||
const int GK_END = 0x23;
|
|
||||||
|
|
||||||
// GK_HOME (24) HOME key
|
|
||||||
const int GK_HOME = 0x24;
|
|
||||||
|
|
||||||
// GK_LEFT (25) LEFT ARROW key
|
|
||||||
const int GK_LEFT = 0x25;
|
|
||||||
|
|
||||||
// GK_UP (26) UP ARROW key
|
|
||||||
const int GK_UP = 0x26;
|
|
||||||
|
|
||||||
// GK_RIGHT (27) RIGHT ARROW key
|
|
||||||
const int GK_RIGHT = 0x27;
|
|
||||||
|
|
||||||
// GK_DOWN (28) DOWN ARROW key
|
|
||||||
const int GK_DOWN = 0x28;
|
|
||||||
|
|
||||||
// GK_SELECT (29) SELECT key
|
|
||||||
const int GK_SELECT = 0x29;
|
|
||||||
|
|
||||||
// GK_PRINT (2A) PRINT key
|
|
||||||
const int GK_PRINT = 0x2A;
|
|
||||||
|
|
||||||
// GK_EXECUTE (2B) EXECUTE key
|
|
||||||
const int GK_EXECUTE = 0x2B;
|
|
||||||
|
|
||||||
// GK_SNAPSHOT (2C) PRINT SCREEN key
|
|
||||||
const int GK_SNAPSHOT = 0x2C;
|
|
||||||
|
|
||||||
// GK_INSERT (2D) INS key
|
|
||||||
const int GK_INSERT = 0x2D;
|
|
||||||
|
|
||||||
// GK_DELETE (2E) DEL key
|
|
||||||
const int GK_DELETE = 0x2E;
|
|
||||||
|
|
||||||
// GK_HELP (2F) HELP key
|
|
||||||
const int GK_HELP = 0x2F;
|
|
||||||
|
|
||||||
// (30) 0 key
|
|
||||||
const int GK_0 = 0x30;
|
|
||||||
|
|
||||||
// (31) 1 key
|
|
||||||
const int GK_1 = 0x31;
|
|
||||||
|
|
||||||
// (32) 2 key
|
|
||||||
const int GK_2 = 0x32;
|
|
||||||
|
|
||||||
// (33) 3 key
|
|
||||||
const int GK_3 = 0x33;
|
|
||||||
|
|
||||||
// (34) 4 key
|
|
||||||
const int GK_4 = 0x34;
|
|
||||||
|
|
||||||
// (35) 5 key;
|
|
||||||
const int GK_5 = 0x35;
|
|
||||||
|
|
||||||
// (36) 6 key
|
|
||||||
const int GK_6 = 0x36;
|
|
||||||
|
|
||||||
// (37) 7 key
|
|
||||||
const int GK_7 = 0x37;
|
|
||||||
|
|
||||||
// (38) 8 key
|
|
||||||
const int GK_8 = 0x38;
|
|
||||||
|
|
||||||
// (39) 9 key
|
|
||||||
const int GK_9 = 0x39;
|
|
||||||
|
|
||||||
// (41) A key
|
|
||||||
const int GK_A = 0x41;
|
|
||||||
|
|
||||||
// (42) B key
|
|
||||||
const int GK_B = 0x42;
|
|
||||||
|
|
||||||
// (43) C key
|
|
||||||
const int GK_C = 0x43;
|
|
||||||
|
|
||||||
// (44) D key
|
|
||||||
const int GK_D = 0x44;
|
|
||||||
|
|
||||||
// (45) E key
|
|
||||||
const int GK_E = 0x45;
|
|
||||||
|
|
||||||
// (46) F key
|
|
||||||
const int GK_F = 0x46;
|
|
||||||
|
|
||||||
// (47) G key
|
|
||||||
const int GK_G = 0x47;
|
|
||||||
|
|
||||||
// (48) H key
|
|
||||||
const int GK_H = 0x48;
|
|
||||||
|
|
||||||
// (49) I key
|
|
||||||
const int GK_I = 0x49;
|
|
||||||
|
|
||||||
// (4A) J key
|
|
||||||
const int GK_J = 0x4A;
|
|
||||||
|
|
||||||
// (4B) K key
|
|
||||||
const int GK_K = 0x4B;
|
|
||||||
|
|
||||||
// (4C) L key
|
|
||||||
const int GK_L = 0x4C;
|
|
||||||
|
|
||||||
// (4D) M key
|
|
||||||
const int GK_M = 0x4D;
|
|
||||||
|
|
||||||
// (4E) N key
|
|
||||||
const int GK_N = 0x4E;
|
|
||||||
|
|
||||||
// (4F) O key
|
|
||||||
const int GK_O = 0x4F;
|
|
||||||
|
|
||||||
// (50) P key
|
|
||||||
const int GK_P = 0x50;
|
|
||||||
|
|
||||||
// (51) Q key
|
|
||||||
const int GK_Q = 0x51;
|
|
||||||
|
|
||||||
// (52) R key
|
|
||||||
const int GK_R = 0x52;
|
|
||||||
|
|
||||||
// (53) S key
|
|
||||||
const int GK_S = 0x53;
|
|
||||||
|
|
||||||
// (54) T key
|
|
||||||
const int GK_T = 0x54;
|
|
||||||
|
|
||||||
// (55) U key
|
|
||||||
const int GK_U = 0x55;
|
|
||||||
|
|
||||||
// (56) V key
|
|
||||||
const int GK_V = 0x56;
|
|
||||||
|
|
||||||
// (57) W key
|
|
||||||
const int GK_W = 0x57;
|
|
||||||
|
|
||||||
// (58) X key
|
|
||||||
const int GK_X = 0x58;
|
|
||||||
|
|
||||||
// (59) Y key
|
|
||||||
const int GK_Y = 0x59;
|
|
||||||
|
|
||||||
// (5A) Z key
|
|
||||||
const int GK_Z = 0x5A;
|
|
||||||
|
|
||||||
// GK_LWIN (5B) Left Windows key (Microsoft Natural keyboard)
|
|
||||||
const int GK_LWIN = 0x5B;
|
|
||||||
|
|
||||||
// GK_RWIN (5C) Right Windows key (Natural keyboard)
|
|
||||||
const int GK_RWIN = 0x5C;
|
|
||||||
|
|
||||||
// GK_APPS (5D) Applications key (Natural keyboard)
|
|
||||||
const int GK_APPS = 0x5D;
|
|
||||||
|
|
||||||
// GK_SLEEP (5F) Computer Sleep key
|
|
||||||
const int GK_SLEEP = 0x5F;
|
|
||||||
|
|
||||||
// GK_NUMPAD0 (60) Numeric keypad 0 key
|
|
||||||
const int GK_NUMPAD0 = 0x60;
|
|
||||||
|
|
||||||
// GK_NUMPAD1 (61) Numeric keypad 1 key
|
|
||||||
const int GK_NUMPAD1 = 0x61;
|
|
||||||
|
|
||||||
// GK_NUMPAD2 (62) Numeric keypad 2 key
|
|
||||||
const int GK_NUMPAD2 = 0x62;
|
|
||||||
|
|
||||||
// GK_NUMPAD3 (63) Numeric keypad 3 key
|
|
||||||
const int GK_NUMPAD3 = 0x63;
|
|
||||||
|
|
||||||
// GK_NUMPAD4 (64) Numeric keypad 4 key
|
|
||||||
const int GK_NUMPAD4 = 0x64;
|
|
||||||
|
|
||||||
// GK_NUMPAD5 (65) Numeric keypad 5 key
|
|
||||||
const int GK_NUMPAD5 = 0x65;
|
|
||||||
|
|
||||||
// GK_NUMPAD6 (66) Numeric keypad 6 key
|
|
||||||
const int GK_NUMPAD6 = 0x66;
|
|
||||||
|
|
||||||
// GK_NUMPAD7 (67) Numeric keypad 7 key
|
|
||||||
const int GK_NUMPAD7 = 0x67;
|
|
||||||
|
|
||||||
// GK_NUMPAD8 (68) Numeric keypad 8 key
|
|
||||||
const int GK_NUMPAD8 = 0x68;
|
|
||||||
|
|
||||||
// GK_NUMPAD9 (69) Numeric keypad 9 key
|
|
||||||
const int GK_NUMPAD9 = 0x69;
|
|
||||||
|
|
||||||
// GK_MULTIPLY (6A) Multiply key
|
|
||||||
const int GK_MULTIPLY = 0x6A;
|
|
||||||
|
|
||||||
// GK_ADD (6B) Add key
|
|
||||||
const int GK_ADD = 0x6B;
|
|
||||||
|
|
||||||
// GK_SEPARATOR (6C) Separator key
|
|
||||||
const int GK_SEPARATOR = 0x6C;
|
|
||||||
|
|
||||||
// GK_SUBTRACT (6D) Subtract key
|
|
||||||
const int GK_SUBTRACT = 0x6D;
|
|
||||||
|
|
||||||
// GK_DECIMAL (6E) Decimal key
|
|
||||||
const int GK_DECIMAL = 0x6E;
|
|
||||||
|
|
||||||
// GK_DIVIDE (6F) Divide key
|
|
||||||
const int GK_DIVIDE = 0x6F;
|
|
||||||
|
|
||||||
// GK_F1 (70) F1 key
|
|
||||||
const int GK_F1 = 0x70;
|
|
||||||
|
|
||||||
// GK_F2 (71) F2 key
|
|
||||||
const int GK_F2 = 0x71;
|
|
||||||
|
|
||||||
// GK_F3 (72) F3 key
|
|
||||||
const int GK_F3 = 0x72;
|
|
||||||
|
|
||||||
// GK_F4 (73) F4 key
|
|
||||||
const int GK_F4 = 0x73;
|
|
||||||
|
|
||||||
// GK_F5 (74) F5 key
|
|
||||||
const int GK_F5 = 0x74;
|
|
||||||
|
|
||||||
// GK_F6 (75) F6 key
|
|
||||||
const int GK_F6 = 0x75;
|
|
||||||
|
|
||||||
// GK_F7 (76) F7 key
|
|
||||||
const int GK_F7 = 0x76;
|
|
||||||
|
|
||||||
// GK_F8 (77) F8 key
|
|
||||||
const int GK_F8 = 0x77;
|
|
||||||
|
|
||||||
// GK_F9 (78) F9 key
|
|
||||||
const int GK_F9 = 0x78;
|
|
||||||
|
|
||||||
// GK_F10 (79) F10 key
|
|
||||||
const int GK_F10 = 0x79;
|
|
||||||
|
|
||||||
// GK_F11 (7A) F11 key
|
|
||||||
const int GK_F11 = 0x7A;
|
|
||||||
|
|
||||||
// GK_F12 (7B) F12 key
|
|
||||||
const int GK_F12 = 0x7B;
|
|
||||||
|
|
||||||
// GK_F13 (7C) F13 key
|
|
||||||
const int GK_F13 = 0x7C;
|
|
||||||
|
|
||||||
// GK_F14 (7D) F14 key
|
|
||||||
const int GK_F14 = 0x7D;
|
|
||||||
|
|
||||||
// GK_F15 (7E) F15 key
|
|
||||||
const int GK_F15 = 0x7E;
|
|
||||||
|
|
||||||
// GK_F16 (7F) F16 key
|
|
||||||
const int GK_F16 = 0x7F;
|
|
||||||
|
|
||||||
// GK_F17 (80H) F17 key
|
|
||||||
const int GK_F17 = 0x80;
|
|
||||||
|
|
||||||
// GK_F18 (81H) F18 key
|
|
||||||
const int GK_F18 = 0x81;
|
|
||||||
|
|
||||||
// GK_F19 (82H) F19 key
|
|
||||||
const int GK_F19 = 0x82;
|
|
||||||
|
|
||||||
// GK_F20 (83H) F20 key
|
|
||||||
const int GK_F20 = 0x83;
|
|
||||||
|
|
||||||
// GK_F21 (84H) F21 key
|
|
||||||
const int GK_F21 = 0x84;
|
|
||||||
|
|
||||||
// GK_F22 (85H) F22 key
|
|
||||||
const int GK_F22 = 0x85;
|
|
||||||
|
|
||||||
// GK_F23 (86H) F23 key
|
|
||||||
const int GK_F23 = 0x86;
|
|
||||||
|
|
||||||
// GK_F24 (87H) F24 key
|
|
||||||
const int GK_F24 = 0x87;
|
|
||||||
|
|
||||||
// GK_NUMLOCK (90) NUM LOCK key
|
|
||||||
const int GK_NUMLOCK = 0x90;
|
|
||||||
|
|
||||||
// GK_SCROLL (91) SCROLL LOCK key
|
|
||||||
const int GK_SCROLL = 0x91;
|
|
||||||
|
|
||||||
// GK_LSHIFT (A0) Left SHIFT key
|
|
||||||
const int GK_LSHIFT = 0xA0;
|
|
||||||
|
|
||||||
// GK_RSHIFT (A1) Right SHIFT key
|
|
||||||
const int GK_RSHIFT = 0xA1;
|
|
||||||
|
|
||||||
// GK_LCONTROL (A2) Left CONTROL key
|
|
||||||
const int GK_LCONTROL = 0xA2;
|
|
||||||
|
|
||||||
// GK_RCONTROL (A3) Right CONTROL key
|
|
||||||
const int GK_RCONTROL = 0xA3;
|
|
||||||
|
|
||||||
// GK_LMENU (A4) Left MENU key
|
|
||||||
const int GK_LMENU = 0xA4;
|
|
||||||
|
|
||||||
// GK_RMENU (A5) Right MENU key
|
|
||||||
const int GK_RMENU = 0xA5;
|
|
||||||
|
|
||||||
// GK_BROWSER_BACK (A6) Windows 2000/XP: Browser Back key
|
|
||||||
const int GK_BROWSER_BACK = 0xA6;
|
|
||||||
|
|
||||||
// GK_BROWSER_FORWARD (A7) Windows 2000/XP: Browser Forward key
|
|
||||||
const int GK_BROWSER_FORWARD = 0xA7;
|
|
||||||
|
|
||||||
// GK_BROWSER_REFRESH (A8) Windows 2000/XP: Browser Refresh key
|
|
||||||
const int GK_BROWSER_REFRESH = 0xA8;
|
|
||||||
|
|
||||||
// GK_BROWSER_STOP (A9) Windows 2000/XP: Browser Stop key
|
|
||||||
const int GK_BROWSER_STOP = 0xA9;
|
|
||||||
|
|
||||||
// GK_BROWSER_SEARCH (AA) Windows 2000/XP: Browser Search key
|
|
||||||
const int GK_BROWSER_SEARCH = 0xAA;
|
|
||||||
|
|
||||||
// GK_BROWSER_FAVORITES (AB) Windows 2000/XP: Browser Favorites key
|
|
||||||
const int GK_BROWSER_FAVORITES = 0xAB;
|
|
||||||
|
|
||||||
// GK_BROWSER_HOME (AC) Windows 2000/XP: Browser Start and Home key
|
|
||||||
const int GK_BROWSER_HOME = 0xAC;
|
|
||||||
|
|
||||||
// GK_VOLUME_MUTE (AD) Windows 2000/XP: Volume Mute key
|
|
||||||
const int GK_VOLUME_MUTE = 0xAD;
|
|
||||||
|
|
||||||
// GK_VOLUME_DOWN (AE) Windows 2000/XP: Volume Down key
|
|
||||||
const int GK_VOLUME_DOWN = 0xAE;
|
|
||||||
|
|
||||||
// GK_VOLUME_UP (AF) Windows 2000/XP: Volume Up key
|
|
||||||
const int GK_VOLUME_UP = 0xAF;
|
|
||||||
|
|
||||||
// GK_MEDIA_NEXT_TRACK (B0) Windows 2000/XP: Next Track key
|
|
||||||
const int GK_MEDIA_NEXT_TRACK = 0xB0;
|
|
||||||
|
|
||||||
// GK_MEDIA_PREV_TRACK (B1) Windows 2000/XP: Previous Track key
|
|
||||||
const int GK_MEDIA_PREV_TRACK = 0xB1;
|
|
||||||
|
|
||||||
// GK_MEDIA_STOP (B2) Windows 2000/XP: Stop Media key
|
|
||||||
const int GK_MEDIA_STOP = 0xB2;
|
|
||||||
|
|
||||||
// GK_MEDIA_PLAY_PAUSE (B3) Windows 2000/XP: Play/Pause Media key
|
|
||||||
const int GK_MEDIA_PLAY_PAUSE = 0xB3;
|
|
||||||
|
|
||||||
// GK_LAUNCH_MAIL (B4) Windows 2000/XP: Start Mail key
|
|
||||||
const int GK_MEDIA_LAUNCH_MAIL = 0xB4;
|
|
||||||
|
|
||||||
// GK_LAUNCH_MEDIA_SELECT (B5) Windows 2000/XP: Select Media key
|
|
||||||
const int GK_MEDIA_LAUNCH_MEDIA_SELECT = 0xB5;
|
|
||||||
|
|
||||||
// GK_LAUNCH_APP1 (B6) Windows 2000/XP: Start Application 1 key
|
|
||||||
const int GK_MEDIA_LAUNCH_APP1 = 0xB6;
|
|
||||||
|
|
||||||
// GK_LAUNCH_APP2 (B7) Windows 2000/XP: Start Application 2 key
|
|
||||||
const int GK_MEDIA_LAUNCH_APP2 = 0xB7;
|
|
||||||
|
|
||||||
// GK_OEM_1 (BA) Used for miscellaneous characters; it can vary by keyboard. Windows 2000/XP: For the US standard keyboard, the ';:' key
|
|
||||||
const int GK_OEM_1 = 0xBA;
|
|
||||||
|
|
||||||
// GK_OEM_PLUS (BB) Windows 2000/XP: For any country/region, the '+' key
|
|
||||||
const int GK_OEM_PLUS = 0xBB;
|
|
||||||
|
|
||||||
// GK_OEM_COMMA (BC) Windows 2000/XP: For any country/region, the ',' key
|
|
||||||
const int GK_OEM_COMMA = 0xBC;
|
|
||||||
|
|
||||||
// GK_OEM_MINUS (BD) Windows 2000/XP: For any country/region, the '-' key
|
|
||||||
const int GK_OEM_MINUS = 0xBD;
|
|
||||||
|
|
||||||
// GK_OEM_PERIOD (BE) Windows 2000/XP: For any country/region, the '.' key
|
|
||||||
const int GK_OEM_PERIOD = 0xBE;
|
|
||||||
|
|
||||||
// GK_OEM_2 (BF) Used for miscellaneous characters; it can vary by keyboard. Windows 2000/XP: For the US standard keyboard, the '/?' key
|
|
||||||
const int GK_OEM_2 = 0xBF;
|
|
||||||
|
|
||||||
// GK_OEM_3 (C0) Used for miscellaneous characters; it can vary by keyboard. Windows 2000/XP: For the US standard keyboard, the '`~' key
|
|
||||||
const int GK_OEM_3 = 0xC0;
|
|
||||||
|
|
||||||
// GK_OEM_4 (DB) Used for miscellaneous characters; it can vary by keyboard. Windows 2000/XP: For the US standard keyboard, the '[{' key
|
|
||||||
const int GK_OEM_4 = 0xDB;
|
|
||||||
|
|
||||||
// GK_OEM_5 (DC) Used for miscellaneous characters; it can vary by keyboard. Windows 2000/XP: For the US standard keyboard, the '\|' key
|
|
||||||
const int GK_OEM_5 = 0xDC;
|
|
||||||
|
|
||||||
// GK_OEM_6 (DD) Used for miscellaneous characters; it can vary by keyboard. Windows 2000/XP: For the US standard keyboard, the ']}' key
|
|
||||||
const int GK_OEM_6 = 0xDD;
|
|
||||||
|
|
||||||
// GK_OEM_7 (DE) Used for miscellaneous characters; it can vary by keyboard. Windows 2000/XP: For the US standard keyboard, the 'single-quote/double-quote' key
|
|
||||||
const int GK_OEM_7 = 0xDE;
|
|
||||||
|
|
||||||
// GK_OEM_8 (DF) Used for miscellaneous characters; it can vary by keyboard.
|
|
||||||
const int GK_OEM_8 = 0xDF;
|
|
||||||
|
|
||||||
// GK_OEM_102 (E2) Windows 2000/XP: Either the angle bracket key or the backslash key on the RT 102-key keyboard
|
|
||||||
const int GK_OEM_102 = 0xE2;
|
|
||||||
|
|
||||||
// GK_PROCESSKEY (E5) Windows 95/98/Me, Windows NT 4.0, Windows 2000/XP: IME PROCESS key
|
|
||||||
const int GK_PROCESSKEY = 0xE5;
|
|
||||||
|
|
||||||
// GK_PACKET (E7) Windows 2000/XP: Used to pass Unicode characters as if they were keystrokes. The GK_PACKET key is the low word of a 32-bit Virtual Key value used for non-keyboard input methods. For more information, see Remark in KEYBDINPUT,SendInput, WM_KEYDOWN, and WM_KEYUP
|
|
||||||
const int GK_PACKET = 0xE7;
|
|
||||||
|
|
||||||
// GK_ATTN (F6) Attn key
|
|
||||||
const int GK_ATTN = 0xF6;
|
|
||||||
|
|
||||||
// GK_CRSEL (F7) CrSel key
|
|
||||||
const int GK_CRSEL = 0xF7;
|
|
||||||
|
|
||||||
// GK_EXSEL (F8) ExSel key
|
|
||||||
const int GK_EXSEL = 0xF8;
|
|
||||||
|
|
||||||
// GK_EREOF (F9) Erase EOF key
|
|
||||||
const int GK_EREOF = 0xF9;
|
|
||||||
|
|
||||||
// GK_PLAY (FA) Play key
|
|
||||||
const int GK_PLAY = 0xFA;
|
|
||||||
|
|
||||||
// GK_ZOOM (FB) Zoom key
|
|
||||||
const int GK_ZOOM = 0xFB;
|
|
||||||
|
|
||||||
// GK_NONAME (FC) Reserved for future use
|
|
||||||
const int GK_NONAME = 0xFC;
|
|
||||||
|
|
||||||
// GK_PA1 (FD) PA1 key
|
|
||||||
const int GK_PA1 = 0xFD;
|
|
||||||
|
|
||||||
// GK_OEM_CLEAR (FE) Clear key
|
|
||||||
const int GK_OEM_CLEAR = 0xFE;
|
|
||||||
|
|
||||||
const int GK_UNKNOWN = 0;
|
|
||||||
|
|
||||||
} // namespace KeyCodes
|
|
||||||
|
|
||||||
} // namespace ultralight
|
|
|
@ -1,164 +0,0 @@
|
||||||
///
|
|
||||||
/// @file KeyEvent.h
|
|
||||||
///
|
|
||||||
/// @brief The header for the KeyEvent class.
|
|
||||||
///
|
|
||||||
/// @author
|
|
||||||
///
|
|
||||||
/// This file is a part of Ultralight, a fast, lightweight, HTML UI engine
|
|
||||||
///
|
|
||||||
/// Website: <http://ultralig.ht>
|
|
||||||
///
|
|
||||||
/// Copyright (C) 2019 Ultralight, Inc. All rights reserved.
|
|
||||||
///
|
|
||||||
#pragma once
|
|
||||||
#include <Ultralight/Defines.h>
|
|
||||||
#include <Ultralight/KeyCodes.h>
|
|
||||||
#include <Ultralight/String.h>
|
|
||||||
#ifdef __OBJC__
|
|
||||||
#import <AppKit/NSEvent.h>
|
|
||||||
#endif
|
|
||||||
|
|
||||||
namespace ultralight {
|
|
||||||
|
|
||||||
///
|
|
||||||
/// @brief A generic keyboard event that can be created from a platform event
|
|
||||||
/// or synthesized from scratch.
|
|
||||||
///
|
|
||||||
/// @see View::FireKeyEvent
|
|
||||||
///
|
|
||||||
class UExport KeyEvent {
|
|
||||||
public:
|
|
||||||
///
|
|
||||||
/// The various KeyEvent types.
|
|
||||||
///
|
|
||||||
enum Type {
|
|
||||||
/// Key-Down type
|
|
||||||
kType_KeyDown,
|
|
||||||
|
|
||||||
/// Key-Up type
|
|
||||||
kType_KeyUp,
|
|
||||||
|
|
||||||
/// Raw Key-Down type
|
|
||||||
kType_RawKeyDown,
|
|
||||||
|
|
||||||
/// Character input type (this event generates text in input fields)
|
|
||||||
kType_Char,
|
|
||||||
};
|
|
||||||
|
|
||||||
///
|
|
||||||
/// Creates an empty KeyEvent, you will need to initialize its members
|
|
||||||
/// yourself. This is useful for synthesizing your own keyboard events.
|
|
||||||
///
|
|
||||||
KeyEvent();
|
|
||||||
|
|
||||||
#ifdef _WIN32
|
|
||||||
///
|
|
||||||
/// Create a KeyEvent directly from a Windows keyboard event.
|
|
||||||
///
|
|
||||||
KeyEvent(Type type, uintptr_t wparam, intptr_t lparam, bool is_system_key);
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#ifdef __OBJC__
|
|
||||||
///
|
|
||||||
/// Create a KeyEvent directly from a macOS NSEvent.
|
|
||||||
///
|
|
||||||
KeyEvent(NSEvent* evt);
|
|
||||||
#endif
|
|
||||||
|
|
||||||
///
|
|
||||||
/// An enumeration of the different keyboard modifiers.
|
|
||||||
///
|
|
||||||
enum Modifiers : uint8_t {
|
|
||||||
/// Whether or not an ALT key is down
|
|
||||||
kMod_AltKey = 1 << 0,
|
|
||||||
|
|
||||||
/// Whether or not a Control key is down
|
|
||||||
kMod_CtrlKey = 1 << 1,
|
|
||||||
|
|
||||||
/// Whether or not a meta key (Command-key on Mac, Windows-key on Win) is down
|
|
||||||
kMod_MetaKey = 1 << 2,
|
|
||||||
|
|
||||||
/// Whether or not a Shift key is down
|
|
||||||
kMod_ShiftKey = 1 << 3,
|
|
||||||
};
|
|
||||||
|
|
||||||
///
|
|
||||||
// The type of this KeyEvent
|
|
||||||
///
|
|
||||||
Type type;
|
|
||||||
|
|
||||||
///
|
|
||||||
/// The current state of the keyboard. Modifiers may be OR'd together to
|
|
||||||
/// represent multiple values.
|
|
||||||
///
|
|
||||||
unsigned modifiers;
|
|
||||||
|
|
||||||
///
|
|
||||||
// The virtual key-code associated with this keyboard event. This is either
|
|
||||||
// directly from the event (ie, WPARAM on Windows) or via a mapping function.
|
|
||||||
// You can see a full list of the possible virtual key-codes in
|
|
||||||
// KeyboardCodes.h
|
|
||||||
///
|
|
||||||
int virtual_key_code;
|
|
||||||
|
|
||||||
///
|
|
||||||
/// The actual key-code generated by the platform. The DOM spec primarily
|
|
||||||
/// uses Windows-equivalent codes (hence virtualKeyCode above) but it helps to
|
|
||||||
/// also specify the platform-specific key-code as well.
|
|
||||||
///
|
|
||||||
int native_key_code;
|
|
||||||
|
|
||||||
///
|
|
||||||
/// This is a string identifying the key that was pressed. This can be
|
|
||||||
/// generated from the virtual_key_code via the GetKeyIdentifierFromVirtualKeyCode()
|
|
||||||
/// utility function. You can find the full list of key identifiers at:
|
|
||||||
/// <http://www.w3.org/TR/DOM-Level-3-Events/keyset.html>
|
|
||||||
///
|
|
||||||
String key_identifier;
|
|
||||||
|
|
||||||
///
|
|
||||||
/// The actual text generated by this keyboard event. This is usually only a
|
|
||||||
/// single character.
|
|
||||||
///
|
|
||||||
String text;
|
|
||||||
|
|
||||||
///
|
|
||||||
/// The text generated by this keyboard event before all modifiers except
|
|
||||||
/// shift are applied. This is used internally for working out shortcut keys.
|
|
||||||
/// This is usually only a single character.
|
|
||||||
///
|
|
||||||
String unmodified_text;
|
|
||||||
|
|
||||||
///
|
|
||||||
/// Whether or not this is a keypad event.
|
|
||||||
///
|
|
||||||
bool is_keypad;
|
|
||||||
|
|
||||||
///
|
|
||||||
/// Whether or not this was generated as the result of an auto-repeat
|
|
||||||
/// (eg, holding down a key).
|
|
||||||
///
|
|
||||||
bool is_auto_repeat;
|
|
||||||
|
|
||||||
///
|
|
||||||
/// Whether or not the pressed key is a "system key". This is a Windows-only
|
|
||||||
/// concept and should be "false" for all non-Windows platforms. For more
|
|
||||||
/// information, see the following link:
|
|
||||||
/// <http://msdn.microsoft.com/en-us/library/ms646286(VS.85).aspx>
|
|
||||||
bool is_system_key;
|
|
||||||
};
|
|
||||||
|
|
||||||
///
|
|
||||||
/// Utility function for generating a key identifier string from a virtual
|
|
||||||
/// key-code.
|
|
||||||
///
|
|
||||||
/// @param virtual_key_code The virtual key-code to generate the key
|
|
||||||
/// identifier from.
|
|
||||||
///
|
|
||||||
/// @param key_identifier_result The string to store the result in.
|
|
||||||
///
|
|
||||||
void UExport GetKeyIdentifierFromVirtualKeyCode(int virtual_key_code,
|
|
||||||
String& key_identifier_result);
|
|
||||||
|
|
||||||
} // namespace ultralight
|
|
|
@ -1,176 +0,0 @@
|
||||||
///
|
|
||||||
/// @file Listener.h
|
|
||||||
///
|
|
||||||
/// @brief The header for View listener interfaces.
|
|
||||||
///
|
|
||||||
/// @author
|
|
||||||
///
|
|
||||||
/// This file is a part of Ultralight, a fast, lightweight, HTML UI engine
|
|
||||||
///
|
|
||||||
/// Website: <http://ultralig.ht>
|
|
||||||
///
|
|
||||||
/// Copyright (C) 2019 Ultralight, Inc. All rights reserved.
|
|
||||||
///
|
|
||||||
#pragma once
|
|
||||||
#include <Ultralight/Defines.h>
|
|
||||||
#include <Ultralight/String.h>
|
|
||||||
|
|
||||||
namespace ultralight {
|
|
||||||
|
|
||||||
class View;
|
|
||||||
|
|
||||||
///
|
|
||||||
/// MessageSource types, @see ViewListener::OnAddConsoleMessage
|
|
||||||
///
|
|
||||||
enum MessageSource {
|
|
||||||
kMessageSource_XML = 0,
|
|
||||||
kMessageSource_JS,
|
|
||||||
kMessageSource_Network,
|
|
||||||
kMessageSource_ConsoleAPI,
|
|
||||||
kMessageSource_Storage,
|
|
||||||
kMessageSource_AppCache,
|
|
||||||
kMessageSource_Rendering,
|
|
||||||
kMessageSource_CSS,
|
|
||||||
kMessageSource_Security,
|
|
||||||
kMessageSource_ContentBlocker,
|
|
||||||
kMessageSource_Other,
|
|
||||||
};
|
|
||||||
|
|
||||||
///
|
|
||||||
/// MessageLevel types, @see ViewListener::OnAddConsoleMessage
|
|
||||||
///
|
|
||||||
enum MessageLevel {
|
|
||||||
kMessageLevel_Log = 1,
|
|
||||||
kMessageLevel_Warning = 2,
|
|
||||||
kMessageLevel_Error = 3,
|
|
||||||
kMessageLevel_Debug = 4,
|
|
||||||
kMessageLevel_Info = 5,
|
|
||||||
};
|
|
||||||
|
|
||||||
///
|
|
||||||
/// Cursor types, @see ViewListener::OnChangeCursor
|
|
||||||
///
|
|
||||||
enum Cursor {
|
|
||||||
kCursor_Pointer = 0,
|
|
||||||
kCursor_Cross,
|
|
||||||
kCursor_Hand,
|
|
||||||
kCursor_IBeam,
|
|
||||||
kCursor_Wait,
|
|
||||||
kCursor_Help,
|
|
||||||
kCursor_EastResize,
|
|
||||||
kCursor_NorthResize,
|
|
||||||
kCursor_NorthEastResize,
|
|
||||||
kCursor_NorthWestResize,
|
|
||||||
kCursor_SouthResize,
|
|
||||||
kCursor_SouthEastResize,
|
|
||||||
kCursor_SouthWestResize,
|
|
||||||
kCursor_WestResize,
|
|
||||||
kCursor_NorthSouthResize,
|
|
||||||
kCursor_EastWestResize,
|
|
||||||
kCursor_NorthEastSouthWestResize,
|
|
||||||
kCursor_NorthWestSouthEastResize,
|
|
||||||
kCursor_ColumnResize,
|
|
||||||
kCursor_RowResize,
|
|
||||||
kCursor_MiddlePanning,
|
|
||||||
kCursor_EastPanning,
|
|
||||||
kCursor_NorthPanning,
|
|
||||||
kCursor_NorthEastPanning,
|
|
||||||
kCursor_NorthWestPanning,
|
|
||||||
kCursor_SouthPanning,
|
|
||||||
kCursor_SouthEastPanning,
|
|
||||||
kCursor_SouthWestPanning,
|
|
||||||
kCursor_WestPanning,
|
|
||||||
kCursor_Move,
|
|
||||||
kCursor_VerticalText,
|
|
||||||
kCursor_Cell,
|
|
||||||
kCursor_ContextMenu,
|
|
||||||
kCursor_Alias,
|
|
||||||
kCursor_Progress,
|
|
||||||
kCursor_NoDrop,
|
|
||||||
kCursor_Copy,
|
|
||||||
kCursor_None,
|
|
||||||
kCursor_NotAllowed,
|
|
||||||
kCursor_ZoomIn,
|
|
||||||
kCursor_ZoomOut,
|
|
||||||
kCursor_Grab,
|
|
||||||
kCursor_Grabbing,
|
|
||||||
kCursor_Custom
|
|
||||||
};
|
|
||||||
|
|
||||||
///
|
|
||||||
/// @brief Interface for View-related events
|
|
||||||
///
|
|
||||||
/// @note For more info @see View::set_view_listener
|
|
||||||
///
|
|
||||||
class UExport ViewListener {
|
|
||||||
public:
|
|
||||||
virtual ~ViewListener() {}
|
|
||||||
|
|
||||||
///
|
|
||||||
/// Called when the page title changes
|
|
||||||
///
|
|
||||||
virtual void OnChangeTitle(ultralight::View* caller,
|
|
||||||
const String& title) {}
|
|
||||||
|
|
||||||
///
|
|
||||||
/// Called when the page URL changes
|
|
||||||
///
|
|
||||||
virtual void OnChangeURL(ultralight::View* caller,
|
|
||||||
const String& url) {}
|
|
||||||
|
|
||||||
///
|
|
||||||
/// Called when the tooltip changes (usually as result of a mouse hover)
|
|
||||||
///
|
|
||||||
virtual void OnChangeTooltip(ultralight::View* caller,
|
|
||||||
const String& tooltip) {}
|
|
||||||
|
|
||||||
///
|
|
||||||
/// Called when the mouse cursor changes
|
|
||||||
///
|
|
||||||
virtual void OnChangeCursor(ultralight::View* caller,
|
|
||||||
Cursor cursor) {}
|
|
||||||
|
|
||||||
///
|
|
||||||
/// Called when a message is added to the console (useful for errors / debug)
|
|
||||||
///
|
|
||||||
virtual void OnAddConsoleMessage(ultralight::View* caller,
|
|
||||||
MessageSource source,
|
|
||||||
MessageLevel level,
|
|
||||||
const String& message,
|
|
||||||
uint32_t line_number,
|
|
||||||
uint32_t column_number,
|
|
||||||
const String& source_id) {}
|
|
||||||
};
|
|
||||||
|
|
||||||
///
|
|
||||||
/// @brief Interface for Load-related events
|
|
||||||
///
|
|
||||||
/// @note For more info @see View::set_load_listener
|
|
||||||
///
|
|
||||||
class UExport LoadListener {
|
|
||||||
public:
|
|
||||||
virtual ~LoadListener() {}
|
|
||||||
|
|
||||||
///
|
|
||||||
/// Called when the page begins loading new URL into main frame
|
|
||||||
///
|
|
||||||
virtual void OnBeginLoading(ultralight::View* caller) {}
|
|
||||||
|
|
||||||
///
|
|
||||||
/// Called when the page finishes loading URL into main frame
|
|
||||||
///
|
|
||||||
virtual void OnFinishLoading(ultralight::View* caller) {}
|
|
||||||
|
|
||||||
///
|
|
||||||
/// Called when the history (back/forward state) is modified
|
|
||||||
///
|
|
||||||
virtual void OnUpdateHistory(ultralight::View* caller) {}
|
|
||||||
|
|
||||||
///
|
|
||||||
/// Called when all JavaScript has been parsed and the document is ready.
|
|
||||||
/// This is the best time to make any initial JavaScript calls to your page.
|
|
||||||
///
|
|
||||||
virtual void OnDOMReady(ultralight::View* caller) {}
|
|
||||||
};
|
|
||||||
|
|
||||||
} // namespace ultralight
|
|
|
@ -1,190 +0,0 @@
|
||||||
///
|
|
||||||
/// @file Matrix.h
|
|
||||||
///
|
|
||||||
/// @brief The header for Matrix helpers
|
|
||||||
///
|
|
||||||
/// @author
|
|
||||||
///
|
|
||||||
/// This file is a part of Ultralight, a fast, lightweight, HTML UI engine
|
|
||||||
///
|
|
||||||
/// Website: <http://ultralig.ht>
|
|
||||||
///
|
|
||||||
/// Copyright (C) 2019 Ultralight, Inc. All rights reserved.
|
|
||||||
///
|
|
||||||
#pragma once
|
|
||||||
#include <Ultralight/Defines.h>
|
|
||||||
#include <Ultralight/RefPtr.h>
|
|
||||||
#include <Ultralight/Geometry.h>
|
|
||||||
|
|
||||||
namespace ultralight {
|
|
||||||
|
|
||||||
///
|
|
||||||
/// 4x4 Matrix Helper
|
|
||||||
///
|
|
||||||
struct UExport Matrix4x4 {
|
|
||||||
///
|
|
||||||
/// Raw 4x4 matrix as an array
|
|
||||||
///
|
|
||||||
float data[16];
|
|
||||||
|
|
||||||
///
|
|
||||||
/// Set to identity matrix.
|
|
||||||
///
|
|
||||||
void SetIdentity();
|
|
||||||
};
|
|
||||||
|
|
||||||
///
|
|
||||||
/// Transformation Matrix helper
|
|
||||||
///
|
|
||||||
struct UExport Matrix {
|
|
||||||
#if defined(__x86_64__) || defined(_M_X64)
|
|
||||||
#if defined(_MSC_VER)
|
|
||||||
__declspec(align(16)) typedef double Aligned4x4[4][4];
|
|
||||||
#else
|
|
||||||
typedef double Aligned4x4[4][4] __attribute__((aligned(16)));
|
|
||||||
#endif
|
|
||||||
#else
|
|
||||||
typedef double Aligned4x4[4][4];
|
|
||||||
#endif
|
|
||||||
|
|
||||||
Aligned4x4 data;
|
|
||||||
|
|
||||||
///
|
|
||||||
/// Set to identity matrix.
|
|
||||||
///
|
|
||||||
void SetIdentity();
|
|
||||||
|
|
||||||
///
|
|
||||||
/// Set to an orthographic projection matrix suitable for use with our
|
|
||||||
/// vertex shaders. Optionally flip the y-coordinate space (eg, for OpenGL).
|
|
||||||
///
|
|
||||||
void SetOrthographicProjection(double screen_width, double screen_height,
|
|
||||||
bool flip_y);
|
|
||||||
|
|
||||||
///
|
|
||||||
/// Set to another matrix.
|
|
||||||
///
|
|
||||||
void Set(const Matrix& other);
|
|
||||||
|
|
||||||
///
|
|
||||||
/// Set to another matrix.
|
|
||||||
///
|
|
||||||
void Set(const Matrix4x4& other);
|
|
||||||
|
|
||||||
///
|
|
||||||
/// Set from raw affine members.
|
|
||||||
///
|
|
||||||
void Set(double a, double b, double c, double d, double e, double f);
|
|
||||||
|
|
||||||
///
|
|
||||||
/// Set from raw 4x4 components.
|
|
||||||
///
|
|
||||||
void Set(double m11, double m12, double m13, double m14,
|
|
||||||
double m21, double m22, double m23, double m24,
|
|
||||||
double m31, double m32, double m33, double m34,
|
|
||||||
double m41, double m42, double m43, double m44);
|
|
||||||
|
|
||||||
inline double m11() const { return data[0][0]; }
|
|
||||||
inline double m12() const { return data[0][1]; }
|
|
||||||
inline double m13() const { return data[0][2]; }
|
|
||||||
inline double m14() const { return data[0][3]; }
|
|
||||||
inline double m21() const { return data[1][0]; }
|
|
||||||
inline double m22() const { return data[1][1]; }
|
|
||||||
inline double m23() const { return data[1][2]; }
|
|
||||||
inline double m24() const { return data[1][3]; }
|
|
||||||
inline double m31() const { return data[2][0]; }
|
|
||||||
inline double m32() const { return data[2][1]; }
|
|
||||||
inline double m33() const { return data[2][2]; }
|
|
||||||
inline double m34() const { return data[2][3]; }
|
|
||||||
inline double m41() const { return data[3][0]; }
|
|
||||||
inline double m42() const { return data[3][1]; }
|
|
||||||
inline double m43() const { return data[3][2]; }
|
|
||||||
inline double m44() const { return data[3][3]; }
|
|
||||||
|
|
||||||
inline double a() const { return data[0][0]; }
|
|
||||||
inline double b() const { return data[0][1]; }
|
|
||||||
inline double c() const { return data[1][0]; }
|
|
||||||
inline double d() const { return data[1][1]; }
|
|
||||||
inline double e() const { return data[3][0]; }
|
|
||||||
inline double f() const { return data[3][1]; }
|
|
||||||
|
|
||||||
///
|
|
||||||
/// Whether or not this is an identity matrix.
|
|
||||||
///
|
|
||||||
bool IsIdentity() const;
|
|
||||||
|
|
||||||
///
|
|
||||||
/// Whether or not this is an identity matrix or translation.
|
|
||||||
///
|
|
||||||
bool IsIdentityOrTranslation() const;
|
|
||||||
|
|
||||||
///
|
|
||||||
/// Whether or not this matrix uses only affine transformations.
|
|
||||||
///
|
|
||||||
bool IsAffine() const;
|
|
||||||
|
|
||||||
///
|
|
||||||
/// Whether or not this is an identity, translation, or non-negative
|
|
||||||
/// uniform scale.
|
|
||||||
///
|
|
||||||
bool IsSimple() const;
|
|
||||||
|
|
||||||
///
|
|
||||||
/// Translate by x and y.
|
|
||||||
///
|
|
||||||
void Translate(double x, double y);
|
|
||||||
|
|
||||||
///
|
|
||||||
/// Scale by x and y.
|
|
||||||
///
|
|
||||||
void Scale(double x, double y);
|
|
||||||
|
|
||||||
///
|
|
||||||
/// Rotate matrix by theta (in degrees)
|
|
||||||
///
|
|
||||||
void Rotate(double theta);
|
|
||||||
|
|
||||||
///
|
|
||||||
/// Rotate matrix by x and y
|
|
||||||
///
|
|
||||||
void Rotate(double x, double y);
|
|
||||||
|
|
||||||
///
|
|
||||||
/// Transform (multiply) by another Matrix
|
|
||||||
///
|
|
||||||
void Transform(const Matrix& other);
|
|
||||||
|
|
||||||
///
|
|
||||||
/// Get the inverse of this matrix. May return false if not invertible.
|
|
||||||
///
|
|
||||||
bool GetInverse(Matrix& result) const;
|
|
||||||
|
|
||||||
///
|
|
||||||
/// Transform point by this matrix and get the result.
|
|
||||||
///
|
|
||||||
Point Apply(const Point& p) const;
|
|
||||||
|
|
||||||
///
|
|
||||||
/// Transform rect by this matrix and get the result as an axis-aligned rect.
|
|
||||||
///
|
|
||||||
Rect Apply(const Rect& r) const;
|
|
||||||
|
|
||||||
///
|
|
||||||
/// Get an integer hash of this matrix's members.
|
|
||||||
///
|
|
||||||
uint32_t Hash() const;
|
|
||||||
|
|
||||||
///
|
|
||||||
/// Get this matrix as unaligned 4x4 float components (for use passing to
|
|
||||||
/// GPU driver APIs).
|
|
||||||
///
|
|
||||||
Matrix4x4 GetMatrix4x4() const;
|
|
||||||
};
|
|
||||||
|
|
||||||
bool UExport operator==(const Matrix& a, const Matrix& b);
|
|
||||||
bool UExport operator!=(const Matrix& a, const Matrix& b);
|
|
||||||
|
|
||||||
bool UExport operator==(const Matrix4x4& a, const Matrix4x4& b);
|
|
||||||
bool UExport operator!=(const Matrix4x4& a, const Matrix4x4& b);
|
|
||||||
|
|
||||||
} // namespace ultralight
|
|
|
@ -1,77 +0,0 @@
|
||||||
///
|
|
||||||
/// @file MouseEvent.h
|
|
||||||
///
|
|
||||||
/// @brief The header for the MouseEvent class.
|
|
||||||
///
|
|
||||||
/// @author
|
|
||||||
///
|
|
||||||
/// This file is a part of Ultralight, a fast, lightweight, HTML UI engine
|
|
||||||
///
|
|
||||||
/// Website: <http://ultralig.ht>
|
|
||||||
///
|
|
||||||
/// Copyright (C) 2019 Ultralight, Inc. All rights reserved.
|
|
||||||
///
|
|
||||||
#pragma once
|
|
||||||
#include <Ultralight/Defines.h>
|
|
||||||
|
|
||||||
namespace ultralight {
|
|
||||||
|
|
||||||
///
|
|
||||||
/// @brief A generic mouse event.
|
|
||||||
///
|
|
||||||
/// @note @see View::FireMouseEvent
|
|
||||||
///
|
|
||||||
class MouseEvent {
|
|
||||||
public:
|
|
||||||
///
|
|
||||||
/// The various MouseEvent types.
|
|
||||||
///
|
|
||||||
enum Type {
|
|
||||||
///
|
|
||||||
/// Mouse moved type
|
|
||||||
///
|
|
||||||
kType_MouseMoved,
|
|
||||||
|
|
||||||
///
|
|
||||||
/// Mouse button pressed type
|
|
||||||
///
|
|
||||||
kType_MouseDown,
|
|
||||||
|
|
||||||
///
|
|
||||||
/// Mouse button released type
|
|
||||||
///
|
|
||||||
kType_MouseUp,
|
|
||||||
};
|
|
||||||
|
|
||||||
///
|
|
||||||
/// The various mouse button types.
|
|
||||||
///
|
|
||||||
enum Button {
|
|
||||||
kButton_None = 0,
|
|
||||||
kButton_Left,
|
|
||||||
kButton_Middle,
|
|
||||||
kButton_Right,
|
|
||||||
};
|
|
||||||
|
|
||||||
///
|
|
||||||
/// The type of this MouseEvent
|
|
||||||
///
|
|
||||||
Type type;
|
|
||||||
|
|
||||||
///
|
|
||||||
/// The current x-position of the mouse, relative to the View
|
|
||||||
///
|
|
||||||
int x;
|
|
||||||
|
|
||||||
///
|
|
||||||
/// The current y-position of the mouse, relative to the View
|
|
||||||
///
|
|
||||||
int y;
|
|
||||||
|
|
||||||
///
|
|
||||||
/// The mouse button that was pressed/released, if any.
|
|
||||||
///
|
|
||||||
Button button;
|
|
||||||
};
|
|
||||||
|
|
||||||
} // namespace ultralight
|
|
|
@ -1,537 +0,0 @@
|
||||||
///
|
|
||||||
/// @file RefPtr.h
|
|
||||||
///
|
|
||||||
/// @brief The header for all ref-counting utilities.
|
|
||||||
///
|
|
||||||
/// @author
|
|
||||||
///
|
|
||||||
/// This file is a part of Ultralight, a fast, lightweight, HTML UI engine
|
|
||||||
///
|
|
||||||
/// Website: <http://ultralig.ht>
|
|
||||||
///
|
|
||||||
/// Copyright (C) 2019 Ultralight, Inc. All rights reserved.
|
|
||||||
///
|
|
||||||
/*
|
|
||||||
* Portions of the below code are derived from 'RefPtr.h' from Apple's WTF,
|
|
||||||
* with the following license header:
|
|
||||||
*
|
|
||||||
* Copyright (C) 2013-2014 Apple Inc. All rights reserved.
|
|
||||||
*
|
|
||||||
* Redistribution and use in source and binary forms, with or without
|
|
||||||
* modification, are permitted provided that the following conditions
|
|
||||||
* are met:
|
|
||||||
* 1. Redistributions of source code must retain the above copyright
|
|
||||||
* notice, this list of conditions and the following disclaimer.
|
|
||||||
* 2. Redistributions in binary form must reproduce the above copyright
|
|
||||||
* notice, this list of conditions and the following disclaimer in the
|
|
||||||
* documentation and/or other materials provided with the distribution.
|
|
||||||
*
|
|
||||||
* THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
|
|
||||||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
|
|
||||||
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
|
||||||
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
|
|
||||||
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
|
||||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
|
||||||
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
|
||||||
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
|
||||||
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
|
||||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
|
|
||||||
* THE POSSIBILITY OF SUCH DAMAGE.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#pragma once
|
|
||||||
#include <Ultralight/Defines.h>
|
|
||||||
#include <assert.h>
|
|
||||||
#include <utility>
|
|
||||||
|
|
||||||
namespace ultralight {
|
|
||||||
|
|
||||||
///
|
|
||||||
/// @brief Interface for all ref-counted objects that will be managed using
|
|
||||||
/// the Ref<> and RefPtr<> smart pointers.
|
|
||||||
///
|
|
||||||
class UExport RefCounted {
|
|
||||||
public:
|
|
||||||
virtual void AddRef() const = 0;
|
|
||||||
virtual void Release() const = 0;
|
|
||||||
virtual int ref_count() const = 0;
|
|
||||||
protected:
|
|
||||||
virtual ~RefCounted();
|
|
||||||
};
|
|
||||||
|
|
||||||
inline void adopted(const void*) { }
|
|
||||||
|
|
||||||
template<typename T> class Ref;
|
|
||||||
|
|
||||||
///
|
|
||||||
/// @brief Helper for wrapping new objects with the Ref smart pointer.
|
|
||||||
///
|
|
||||||
/// All ref-counted object are created with an initial ref-count of '1'.
|
|
||||||
/// The AdoptRef() helper returns a Ref<T> without calling AddRef().
|
|
||||||
/// This is used for creating new objects, like so:
|
|
||||||
///
|
|
||||||
/// Ref<Object> ref = AdoptRef(*new ObjectImpl());
|
|
||||||
///
|
|
||||||
template<typename T> Ref<T> AdoptRef(T&);
|
|
||||||
|
|
||||||
///
|
|
||||||
/// @brief A non-nullable smart pointer.
|
|
||||||
///
|
|
||||||
/// This smart pointer automatically manages the lifetime of a RefCounted
|
|
||||||
/// object. Also guarantees that the managed instance is not NULL.
|
|
||||||
///
|
|
||||||
template<typename T> class Ref {
|
|
||||||
public:
|
|
||||||
///
|
|
||||||
/// Destroy Ref (wll decrement ref-count by one)
|
|
||||||
///
|
|
||||||
~Ref()
|
|
||||||
{
|
|
||||||
if (instance_)
|
|
||||||
instance_->Release();
|
|
||||||
}
|
|
||||||
|
|
||||||
///
|
|
||||||
/// Construct Ref from a reference. (Will increment ref-count by one)
|
|
||||||
///
|
|
||||||
Ref(T& object)
|
|
||||||
: instance_(&object)
|
|
||||||
{
|
|
||||||
instance_->AddRef();
|
|
||||||
}
|
|
||||||
|
|
||||||
///
|
|
||||||
/// Copy constructor.
|
|
||||||
///
|
|
||||||
Ref(const Ref& other)
|
|
||||||
: instance_(other.instance_)
|
|
||||||
{
|
|
||||||
instance_->AddRef();
|
|
||||||
}
|
|
||||||
|
|
||||||
///
|
|
||||||
/// Copy constructor with internal type conversion.
|
|
||||||
///
|
|
||||||
template<typename U>
|
|
||||||
Ref(Ref<U>& other)
|
|
||||||
: instance_(other.ptr())
|
|
||||||
{
|
|
||||||
instance_->AddRef();
|
|
||||||
}
|
|
||||||
|
|
||||||
///
|
|
||||||
/// Copy constructor with internal type conversion.
|
|
||||||
///
|
|
||||||
template<typename U>
|
|
||||||
Ref(const Ref<U>& other)
|
|
||||||
: instance_(other.ptr())
|
|
||||||
{
|
|
||||||
instance_->AddRef();
|
|
||||||
}
|
|
||||||
|
|
||||||
///
|
|
||||||
/// Move constructor.
|
|
||||||
///
|
|
||||||
Ref(Ref&& other)
|
|
||||||
: instance_(&other.LeakRef())
|
|
||||||
{
|
|
||||||
assert(instance_);
|
|
||||||
}
|
|
||||||
|
|
||||||
///
|
|
||||||
/// Move constructor.
|
|
||||||
///
|
|
||||||
template<typename U>
|
|
||||||
Ref(Ref<U>&& other)
|
|
||||||
: instance_(&other.LeakRef())
|
|
||||||
{
|
|
||||||
assert(instance_);
|
|
||||||
}
|
|
||||||
|
|
||||||
Ref& operator=(T& object)
|
|
||||||
{
|
|
||||||
assert(instance_);
|
|
||||||
object.AddRef();
|
|
||||||
instance_->Release();
|
|
||||||
instance_ = &object;
|
|
||||||
assert(instance_);
|
|
||||||
return *this;
|
|
||||||
}
|
|
||||||
|
|
||||||
Ref& operator=(const Ref& other)
|
|
||||||
{
|
|
||||||
assert(instance_);
|
|
||||||
other.instance_->AddRef();
|
|
||||||
instance_->Release();
|
|
||||||
instance_ = other.instance_;
|
|
||||||
assert(instance_);
|
|
||||||
return *this;
|
|
||||||
}
|
|
||||||
|
|
||||||
template<typename U>
|
|
||||||
Ref& operator=(const Ref<U>& other)
|
|
||||||
{
|
|
||||||
assert(instance_);
|
|
||||||
other.instance_->AddRef();
|
|
||||||
instance_->Release();
|
|
||||||
instance_ = other.instance_;
|
|
||||||
assert(instance_);
|
|
||||||
return *this;
|
|
||||||
}
|
|
||||||
|
|
||||||
Ref& operator=(Ref&& reference)
|
|
||||||
{
|
|
||||||
assert(instance_);
|
|
||||||
instance_->Release();
|
|
||||||
instance_ = &reference.LeakRef();
|
|
||||||
assert(instance_);
|
|
||||||
return *this;
|
|
||||||
}
|
|
||||||
|
|
||||||
template<typename U> Ref& operator=(Ref<U>&& reference)
|
|
||||||
{
|
|
||||||
assert(instance_);
|
|
||||||
instance_->Release();
|
|
||||||
instance_ = &reference.LeakRef();
|
|
||||||
assert(instance_);
|
|
||||||
return *this;
|
|
||||||
}
|
|
||||||
|
|
||||||
const T* operator->() const { assert(instance_); return instance_; }
|
|
||||||
T* operator->() { assert(instance_); return instance_; }
|
|
||||||
|
|
||||||
///
|
|
||||||
/// Get a pointer to wrapped object.
|
|
||||||
///
|
|
||||||
const T* ptr() const { assert(instance_); return instance_; }
|
|
||||||
|
|
||||||
///
|
|
||||||
/// Get a pointer to wrapped object.
|
|
||||||
///
|
|
||||||
T* ptr() { assert(instance_); return instance_; }
|
|
||||||
|
|
||||||
///
|
|
||||||
/// Get a reference to wrapped object.
|
|
||||||
///
|
|
||||||
const T& get() const { assert(instance_); return *instance_; }
|
|
||||||
|
|
||||||
///
|
|
||||||
/// Get a reference to wrapped object.
|
|
||||||
///
|
|
||||||
T& get() { assert(instance_); return *instance_; }
|
|
||||||
|
|
||||||
operator T&() { assert(instance_); return *instance_; }
|
|
||||||
operator const T&() const { assert(instance_); return *instance_; }
|
|
||||||
|
|
||||||
template<typename U> Ref<T> Replace(Ref<U>&&);
|
|
||||||
|
|
||||||
T& LeakRef() {
|
|
||||||
assert(instance_);
|
|
||||||
|
|
||||||
T* result = std::move(instance_);
|
|
||||||
instance_ = std::forward<T*>(nullptr);
|
|
||||||
return *result;
|
|
||||||
}
|
|
||||||
|
|
||||||
friend inline bool operator==(const Ref& a, const Ref& b) {
|
|
||||||
return a.instance_ == b.instance_;
|
|
||||||
}
|
|
||||||
|
|
||||||
friend inline bool operator!=(const Ref& a, const Ref& b) {
|
|
||||||
return a.instance_ != b.instance_;
|
|
||||||
}
|
|
||||||
|
|
||||||
friend inline bool operator<(const Ref& a, const Ref& b) {
|
|
||||||
return a.instance_ < b.instance_;
|
|
||||||
}
|
|
||||||
|
|
||||||
protected:
|
|
||||||
friend Ref AdoptRef<T>(T&);
|
|
||||||
template<typename U> friend class RefPtr;
|
|
||||||
|
|
||||||
enum AdoptTag { Adopt };
|
|
||||||
Ref(T& object, AdoptTag)
|
|
||||||
: instance_(&object)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
T* instance_;
|
|
||||||
};
|
|
||||||
|
|
||||||
template<typename T> template<typename U> Ref<T> Ref<T>::Replace(Ref<U>&& reference)
|
|
||||||
{
|
|
||||||
auto oldReference = AdoptRef(*instance_);
|
|
||||||
instance_ = &reference.LeakRef();
|
|
||||||
return oldReference;
|
|
||||||
}
|
|
||||||
|
|
||||||
template<typename T>
|
|
||||||
Ref<T> AdoptRef(T& reference)
|
|
||||||
{
|
|
||||||
adopted(&reference);
|
|
||||||
return Ref<T>(reference, Ref<T>::Adopt);
|
|
||||||
}
|
|
||||||
|
|
||||||
///
|
|
||||||
/// @brief A nullable smart pointer.
|
|
||||||
///
|
|
||||||
/// This smart pointer automatically manages the lifetime of a RefCounted
|
|
||||||
/// object. The managed instance may be NULL.
|
|
||||||
///
|
|
||||||
template<typename T> class RefPtr {
|
|
||||||
public:
|
|
||||||
///
|
|
||||||
/// Construct a NULL ref-pointer.
|
|
||||||
///
|
|
||||||
RefPtr()
|
|
||||||
: instance_(nullptr)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
///
|
|
||||||
/// Construct a NULL ref-pointer.
|
|
||||||
///
|
|
||||||
RefPtr(std::nullptr_t)
|
|
||||||
: instance_(nullptr)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
///
|
|
||||||
/// Construct from a pointer. (Will increment ref-count by one)
|
|
||||||
///
|
|
||||||
RefPtr(T* other)
|
|
||||||
: instance_(other)
|
|
||||||
{
|
|
||||||
if (instance_)
|
|
||||||
instance_->AddRef();
|
|
||||||
}
|
|
||||||
|
|
||||||
///
|
|
||||||
/// Copy constructor.
|
|
||||||
///
|
|
||||||
RefPtr(const RefPtr& other)
|
|
||||||
: instance_(other.instance_)
|
|
||||||
{
|
|
||||||
if (instance_)
|
|
||||||
instance_->AddRef();
|
|
||||||
}
|
|
||||||
|
|
||||||
///
|
|
||||||
/// Copy constructor with internal type conversion.
|
|
||||||
///
|
|
||||||
template<typename U>
|
|
||||||
RefPtr(const RefPtr<U>& other)
|
|
||||||
: instance_(other.instance_)
|
|
||||||
{
|
|
||||||
if (instance_)
|
|
||||||
instance_->AddRef();
|
|
||||||
}
|
|
||||||
|
|
||||||
///
|
|
||||||
/// Move constructor.
|
|
||||||
///
|
|
||||||
RefPtr(RefPtr&& other)
|
|
||||||
: instance_(other.LeakRef())
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
///
|
|
||||||
/// Move constructor.
|
|
||||||
///
|
|
||||||
template<typename U>
|
|
||||||
RefPtr(RefPtr<U>&& other)
|
|
||||||
: instance_(other.LeakRef())
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
///
|
|
||||||
/// Construct from a Ref
|
|
||||||
///
|
|
||||||
template<typename U>
|
|
||||||
RefPtr(const Ref<U>& other)
|
|
||||||
: instance_(other.instance_)
|
|
||||||
{
|
|
||||||
if (instance_)
|
|
||||||
instance_->AddRef();
|
|
||||||
}
|
|
||||||
|
|
||||||
///
|
|
||||||
/// Construct by moving from a Ref
|
|
||||||
///
|
|
||||||
template<typename U>
|
|
||||||
RefPtr(Ref<U>&& other);
|
|
||||||
|
|
||||||
///
|
|
||||||
/// Destroy RefPtr (wll decrement ref-count by one)
|
|
||||||
///
|
|
||||||
~RefPtr()
|
|
||||||
{
|
|
||||||
T* old_value = std::move(instance_);
|
|
||||||
instance_ = std::forward<T*>(nullptr);
|
|
||||||
if (old_value)
|
|
||||||
old_value->Release();
|
|
||||||
}
|
|
||||||
|
|
||||||
///
|
|
||||||
/// Get a pointer to wrapped object.
|
|
||||||
///
|
|
||||||
T* get() const { return instance_; }
|
|
||||||
|
|
||||||
T* LeakRef() {
|
|
||||||
T* result = std::move(instance_);
|
|
||||||
instance_ = std::forward<T*>(nullptr);
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
T& operator*() const { assert(instance_); return *instance_; }
|
|
||||||
T* operator->() const { return instance_; }
|
|
||||||
|
|
||||||
bool operator!() const { return !instance_; }
|
|
||||||
|
|
||||||
// This conversion operator allows implicit conversion to bool but not to other integer types.
|
|
||||||
typedef T* (RefPtr::*UnspecifiedBoolType);
|
|
||||||
operator UnspecifiedBoolType() const { return instance_ ? &RefPtr::instance_ : nullptr; }
|
|
||||||
|
|
||||||
RefPtr& operator=(const RefPtr&);
|
|
||||||
RefPtr& operator=(T*);
|
|
||||||
RefPtr& operator=(std::nullptr_t);
|
|
||||||
template<typename U> RefPtr& operator=(const RefPtr<U>&);
|
|
||||||
RefPtr& operator=(RefPtr&&);
|
|
||||||
template<typename U> RefPtr& operator=(RefPtr<U>&&);
|
|
||||||
template<typename U> RefPtr& operator=(Ref<U>&&);
|
|
||||||
|
|
||||||
friend inline bool operator==(const RefPtr& a, const RefPtr& b) {
|
|
||||||
return a.instance_ == b.instance_;
|
|
||||||
}
|
|
||||||
|
|
||||||
friend inline bool operator!=(const RefPtr& a, const RefPtr& b) {
|
|
||||||
return a.instance_ != b.instance_;
|
|
||||||
}
|
|
||||||
|
|
||||||
friend inline bool operator<(const RefPtr& a, const RefPtr& b) {
|
|
||||||
return a.instance_ < b.instance_;
|
|
||||||
}
|
|
||||||
|
|
||||||
void Swap(RefPtr&);
|
|
||||||
|
|
||||||
private:
|
|
||||||
T* instance_;
|
|
||||||
};
|
|
||||||
|
|
||||||
template<typename T>
|
|
||||||
template<typename U>
|
|
||||||
RefPtr<T>::RefPtr(Ref<U>&& reference)
|
|
||||||
: instance_(&reference.LeakRef())
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
template<typename T>
|
|
||||||
RefPtr<T>& RefPtr<T>::operator=(const RefPtr& other)
|
|
||||||
{
|
|
||||||
RefPtr ptr = other;
|
|
||||||
Swap(ptr);
|
|
||||||
return *this;
|
|
||||||
}
|
|
||||||
|
|
||||||
template<typename T>
|
|
||||||
template<typename U>
|
|
||||||
RefPtr<T>& RefPtr<T>::operator=(const RefPtr<U>& other)
|
|
||||||
{
|
|
||||||
RefPtr ptr = other;
|
|
||||||
Swap(ptr);
|
|
||||||
return *this;
|
|
||||||
}
|
|
||||||
|
|
||||||
template<typename T>
|
|
||||||
RefPtr<T>& RefPtr<T>::operator=(T* object)
|
|
||||||
{
|
|
||||||
RefPtr ptr = object;
|
|
||||||
Swap(ptr);
|
|
||||||
return *this;
|
|
||||||
}
|
|
||||||
|
|
||||||
template<typename T>
|
|
||||||
RefPtr<T>& RefPtr<T>::operator=(std::nullptr_t)
|
|
||||||
{
|
|
||||||
T* old_instance = std::move(instance_);
|
|
||||||
instance_ = std::forward<T*>(nullptr);
|
|
||||||
if (old_instance)
|
|
||||||
old_instance->Release();
|
|
||||||
return *this;
|
|
||||||
}
|
|
||||||
|
|
||||||
template<typename T>
|
|
||||||
RefPtr<T>& RefPtr<T>::operator=(RefPtr&& other)
|
|
||||||
{
|
|
||||||
RefPtr ptr = std::move(other);
|
|
||||||
Swap(ptr);
|
|
||||||
return *this;
|
|
||||||
}
|
|
||||||
|
|
||||||
template<typename T>
|
|
||||||
template<typename U>
|
|
||||||
RefPtr<T>& RefPtr<T>::operator=(RefPtr<U>&& other)
|
|
||||||
{
|
|
||||||
RefPtr ptr = std::move(other);
|
|
||||||
Swap(ptr);
|
|
||||||
return *this;
|
|
||||||
}
|
|
||||||
|
|
||||||
template<typename T>
|
|
||||||
template<typename U>
|
|
||||||
RefPtr<T>& RefPtr<T>::operator=(Ref<U>&& other)
|
|
||||||
{
|
|
||||||
RefPtr ptr = std::move(other);
|
|
||||||
Swap(ptr);
|
|
||||||
return *this;
|
|
||||||
}
|
|
||||||
|
|
||||||
template<typename T>
|
|
||||||
void RefPtr<T>::Swap(RefPtr& other)
|
|
||||||
{
|
|
||||||
std::swap(instance_, other.instance_);
|
|
||||||
}
|
|
||||||
|
|
||||||
template<class T>
|
|
||||||
void Swap(RefPtr<T>& a, RefPtr<T>& b)
|
|
||||||
{
|
|
||||||
a.Swap(b);
|
|
||||||
}
|
|
||||||
|
|
||||||
template<typename T, typename U>
|
|
||||||
bool operator==(const RefPtr<T>& a, const RefPtr<U>& b)
|
|
||||||
{
|
|
||||||
return a.get() == b.get();
|
|
||||||
}
|
|
||||||
|
|
||||||
template<typename T, typename U>
|
|
||||||
bool operator==(const RefPtr<T>& a, U* b)
|
|
||||||
{
|
|
||||||
return a.get() == b;
|
|
||||||
}
|
|
||||||
|
|
||||||
template<typename T, typename U>
|
|
||||||
bool operator==(T* a, const RefPtr<U>& b)
|
|
||||||
{
|
|
||||||
return a == b.get();
|
|
||||||
}
|
|
||||||
|
|
||||||
template<typename T, typename U>
|
|
||||||
bool operator!=(const RefPtr<T>& a, const RefPtr<U>& b)
|
|
||||||
{
|
|
||||||
return a.get() != b.get();
|
|
||||||
}
|
|
||||||
|
|
||||||
template<typename T, typename U>
|
|
||||||
bool operator!=(const RefPtr<T>& a, U* b)
|
|
||||||
{
|
|
||||||
return a.get() != b;
|
|
||||||
}
|
|
||||||
|
|
||||||
template<typename T, typename U>
|
|
||||||
bool operator!=(T* a, const RefPtr<U>& b)
|
|
||||||
{
|
|
||||||
return a != b.get();
|
|
||||||
}
|
|
||||||
|
|
||||||
} // namespace ultralight
|
|
|
@ -1,84 +0,0 @@
|
||||||
///
|
|
||||||
/// @file RenderTarget.h
|
|
||||||
///
|
|
||||||
/// @brief The header for the RenderTarget struct.
|
|
||||||
///
|
|
||||||
/// @author
|
|
||||||
///
|
|
||||||
/// This file is a part of Ultralight, a fast, lightweight, HTML UI engine
|
|
||||||
///
|
|
||||||
/// Website: <http://ultralig.ht>
|
|
||||||
///
|
|
||||||
/// Copyright (C) 2019 Ultralight, Inc. All rights reserved.
|
|
||||||
///
|
|
||||||
#pragma once
|
|
||||||
#include <Ultralight/Defines.h>
|
|
||||||
#include <Ultralight/Bitmap.h>
|
|
||||||
#include <Ultralight/Geometry.h>
|
|
||||||
|
|
||||||
namespace ultralight {
|
|
||||||
|
|
||||||
#pragma pack(push, 1)
|
|
||||||
|
|
||||||
///
|
|
||||||
/// @brief Rendering details for a View, to be used with your own GPUDriver
|
|
||||||
///
|
|
||||||
/// When using your own GPUDriver, each View is rendered to an offscreen
|
|
||||||
/// texture that you must display on a quad in your engine. This struct
|
|
||||||
/// provides all the details you need to render the View texture in your
|
|
||||||
/// engine.
|
|
||||||
///
|
|
||||||
struct UExport RenderTarget {
|
|
||||||
///
|
|
||||||
/// Whether this target is empty (null texture)
|
|
||||||
///
|
|
||||||
bool is_empty;
|
|
||||||
|
|
||||||
///
|
|
||||||
/// The viewport width (in device coordinates).
|
|
||||||
///
|
|
||||||
uint32_t width;
|
|
||||||
|
|
||||||
///
|
|
||||||
/// The viewport height (in device coordinates).
|
|
||||||
///
|
|
||||||
uint32_t height;
|
|
||||||
|
|
||||||
///
|
|
||||||
/// The GPUDriver-specific texture ID (you should bind the texture using
|
|
||||||
/// your implementation of GPUDriver::BindTexture before drawing a quad).
|
|
||||||
///
|
|
||||||
uint32_t texture_id;
|
|
||||||
|
|
||||||
///
|
|
||||||
/// The texture width (in pixels). This may be padded.
|
|
||||||
///
|
|
||||||
uint32_t texture_width;
|
|
||||||
|
|
||||||
///
|
|
||||||
/// The texture height (in pixels). This may be padded.
|
|
||||||
///
|
|
||||||
uint32_t texture_height;
|
|
||||||
|
|
||||||
///
|
|
||||||
/// The pixel format of the texture.
|
|
||||||
///
|
|
||||||
BitmapFormat texture_format;
|
|
||||||
|
|
||||||
///
|
|
||||||
/// UV coordinates of the texture (this is needed because the texture may
|
|
||||||
/// be padded).
|
|
||||||
///
|
|
||||||
Rect uv_coords;
|
|
||||||
|
|
||||||
///
|
|
||||||
/// The GPUDriver-specific render buffer ID.
|
|
||||||
///
|
|
||||||
uint32_t render_buffer_id;
|
|
||||||
|
|
||||||
RenderTarget();
|
|
||||||
};
|
|
||||||
|
|
||||||
#pragma pack(pop)
|
|
||||||
|
|
||||||
} // namespace ultralight
|
|
|
@ -1,90 +0,0 @@
|
||||||
///
|
|
||||||
/// @file Renderer.h
|
|
||||||
///
|
|
||||||
/// @brief The header for the Renderer class.
|
|
||||||
///
|
|
||||||
/// @author
|
|
||||||
///
|
|
||||||
/// This file is a part of Ultralight, a fast, lightweight, HTML UI engine
|
|
||||||
///
|
|
||||||
/// Website: <http://ultralig.ht>
|
|
||||||
///
|
|
||||||
/// Copyright (C) 2019 Ultralight, Inc. All rights reserved.
|
|
||||||
///
|
|
||||||
#pragma once
|
|
||||||
#include <Ultralight/Defines.h>
|
|
||||||
#include <Ultralight/RefPtr.h>
|
|
||||||
#include <Ultralight/View.h>
|
|
||||||
|
|
||||||
namespace ultralight {
|
|
||||||
|
|
||||||
///
|
|
||||||
/// @brief The core of Ultralight. You should initialize it after setting up
|
|
||||||
/// your Platform config and drivers.
|
|
||||||
///
|
|
||||||
/// This singleton class manages the lifetime of all Views (@see View) and
|
|
||||||
/// coordinates all painting, rendering, network requests, and event dispatch.
|
|
||||||
///
|
|
||||||
/// @note You don't have to create this instance directly if you use the
|
|
||||||
/// AppCore API. The App class will automatically create a Renderer and
|
|
||||||
/// perform all rendering within its run loop. @see App::Create
|
|
||||||
///
|
|
||||||
class UExport Renderer : public RefCounted {
|
|
||||||
public:
|
|
||||||
///
|
|
||||||
/// Create the Renderer singleton. You should set up all your Platform config,
|
|
||||||
/// file-system, and drivers before calling this function. @see Platform
|
|
||||||
///
|
|
||||||
/// @note You should only create one Renderer per application lifetime.
|
|
||||||
///
|
|
||||||
/// @return Returns a ref-pointer to a new Renderer instance. You should
|
|
||||||
/// assign it to either a Ref<Renderer> (non-nullable) or
|
|
||||||
/// RefPtr<Renderer> (nullable).
|
|
||||||
///
|
|
||||||
static Ref<Renderer> Create();
|
|
||||||
|
|
||||||
///
|
|
||||||
/// Create a new View.
|
|
||||||
///
|
|
||||||
/// @param width The initial width, in device coordinates.
|
|
||||||
///
|
|
||||||
/// @param height The initial height, in device coordinates.
|
|
||||||
///
|
|
||||||
/// @param transparent Whether or not the view background is transparent.
|
|
||||||
///
|
|
||||||
/// @return Returns a ref-pointer to a new View instance. You should assign
|
|
||||||
/// it to either a Ref<View> (non-nullable) or RefPtr<View>
|
|
||||||
/// (nullable).
|
|
||||||
///
|
|
||||||
/// @note The device coordinates are scaled to pixels by multiplying them
|
|
||||||
/// with the current DPI scale (@see Config::device_scale_hint) and
|
|
||||||
/// rounding to the nearest integer value.
|
|
||||||
///
|
|
||||||
virtual Ref<View> CreateView(uint32_t width, uint32_t height,
|
|
||||||
bool transparent) = 0;
|
|
||||||
|
|
||||||
///
|
|
||||||
/// Update timers and dispatch internal callbacks. You should call this often
|
|
||||||
/// from your main application loop.
|
|
||||||
///
|
|
||||||
virtual void Update() = 0;
|
|
||||||
|
|
||||||
///
|
|
||||||
/// Render all active views to display lists and dispatch calls to GPUDriver.
|
|
||||||
///
|
|
||||||
/// @note If you're using the default, offscreen GL driver, this updates the
|
|
||||||
/// internal bitmap of each View (@see View::bitmap).
|
|
||||||
///
|
|
||||||
virtual void Render() = 0;
|
|
||||||
|
|
||||||
///
|
|
||||||
/// Attempt to release as much memory as possible. Don't call this from any
|
|
||||||
/// callbacks or driver code.
|
|
||||||
///
|
|
||||||
virtual void PurgeMemory() = 0;
|
|
||||||
|
|
||||||
protected:
|
|
||||||
virtual ~Renderer();
|
|
||||||
};
|
|
||||||
|
|
||||||
} // namespace ultralight
|
|
|
@ -1,53 +0,0 @@
|
||||||
///
|
|
||||||
/// @file ScrollEvent.h
|
|
||||||
///
|
|
||||||
/// @brief The header for the ScrollEvent class.
|
|
||||||
///
|
|
||||||
/// @author
|
|
||||||
///
|
|
||||||
/// This file is a part of Ultralight, a fast, lightweight, HTML UI engine
|
|
||||||
///
|
|
||||||
/// Website: <http://ultralig.ht>
|
|
||||||
///
|
|
||||||
/// Copyright (C) 2019 Ultralight, Inc. All rights reserved.
|
|
||||||
///
|
|
||||||
#pragma once
|
|
||||||
#include <Ultralight/Defines.h>
|
|
||||||
|
|
||||||
namespace ultralight {
|
|
||||||
|
|
||||||
///
|
|
||||||
/// @brief A generic scroll event.
|
|
||||||
///
|
|
||||||
/// @note @see View::FireScrollEvent
|
|
||||||
///
|
|
||||||
class ScrollEvent {
|
|
||||||
public:
|
|
||||||
///
|
|
||||||
/// The scroll event granularity type
|
|
||||||
///
|
|
||||||
enum Type {
|
|
||||||
/// The delta value is interpreted as number of pixels
|
|
||||||
kType_ScrollByPixel,
|
|
||||||
|
|
||||||
/// The delta value is interpreted as number of pages
|
|
||||||
kType_ScrollByPage,
|
|
||||||
};
|
|
||||||
|
|
||||||
///
|
|
||||||
/// Scroll granularity type
|
|
||||||
///
|
|
||||||
Type type;
|
|
||||||
|
|
||||||
///
|
|
||||||
/// Horizontal scroll amount
|
|
||||||
///
|
|
||||||
int delta_x;
|
|
||||||
|
|
||||||
///
|
|
||||||
/// Vertical scroll amount
|
|
||||||
///
|
|
||||||
int delta_y;
|
|
||||||
};
|
|
||||||
|
|
||||||
} // namespace ultralight
|
|
|
@ -1,120 +0,0 @@
|
||||||
///
|
|
||||||
/// @file String.h
|
|
||||||
///
|
|
||||||
/// @brief The header for the String class.
|
|
||||||
///
|
|
||||||
/// @author
|
|
||||||
///
|
|
||||||
/// This file is a part of Ultralight, a fast, lightweight, HTML UI engine
|
|
||||||
///
|
|
||||||
/// Website: <http://ultralig.ht>
|
|
||||||
///
|
|
||||||
/// Copyright (C) 2019 Ultralight, Inc. All rights reserved.
|
|
||||||
///
|
|
||||||
#pragma once
|
|
||||||
#include <Ultralight/Defines.h>
|
|
||||||
#include <Ultralight/String8.h>
|
|
||||||
#include <Ultralight/String16.h>
|
|
||||||
#include <Ultralight/String32.h>
|
|
||||||
|
|
||||||
namespace ultralight {
|
|
||||||
|
|
||||||
///
|
|
||||||
/// @brief UTF-16 String container with conversions for UTF-8 and UTF-32.
|
|
||||||
///
|
|
||||||
/// @note Internally, all strings are represented as UTF-16.
|
|
||||||
///
|
|
||||||
class UExport String {
|
|
||||||
public:
|
|
||||||
///
|
|
||||||
/// Create empty string
|
|
||||||
///
|
|
||||||
String();
|
|
||||||
|
|
||||||
///
|
|
||||||
/// Create from null-terminated, ASCII C-string
|
|
||||||
///
|
|
||||||
String(const char* str);
|
|
||||||
|
|
||||||
///
|
|
||||||
/// Create from raw, UTF-8 string with certain length
|
|
||||||
///
|
|
||||||
String(const char* str, size_t len);
|
|
||||||
|
|
||||||
///
|
|
||||||
/// Create from existing String8 (UTF-8).
|
|
||||||
///
|
|
||||||
String(const String8& str);
|
|
||||||
|
|
||||||
///
|
|
||||||
/// Create from raw UTF-16 string with certain length
|
|
||||||
///
|
|
||||||
String(const Char16* str, size_t len);
|
|
||||||
|
|
||||||
///
|
|
||||||
/// Create from existing String16 (UTF-16)
|
|
||||||
///
|
|
||||||
String(const String16& str);
|
|
||||||
|
|
||||||
///
|
|
||||||
/// Create from existing String32 (UTF-32)
|
|
||||||
///
|
|
||||||
String(const String32& str);
|
|
||||||
|
|
||||||
///
|
|
||||||
/// Copy constructor
|
|
||||||
///
|
|
||||||
String(const String& other);
|
|
||||||
|
|
||||||
///
|
|
||||||
/// Destructor
|
|
||||||
///
|
|
||||||
~String();
|
|
||||||
|
|
||||||
///
|
|
||||||
/// Assign string from another, copy is made
|
|
||||||
///
|
|
||||||
String& operator=(const String& other);
|
|
||||||
|
|
||||||
///
|
|
||||||
/// Append string with another
|
|
||||||
///
|
|
||||||
String& operator+=(const String& other);
|
|
||||||
|
|
||||||
///
|
|
||||||
/// Concatenation operator
|
|
||||||
///
|
|
||||||
inline friend String operator+(String lhs, const String& rhs) { lhs += rhs; return lhs; }
|
|
||||||
|
|
||||||
///
|
|
||||||
/// Get native UTF-16 string
|
|
||||||
///
|
|
||||||
String16& utf16() { return str_; }
|
|
||||||
|
|
||||||
///
|
|
||||||
/// Get native UTF-16 string
|
|
||||||
///
|
|
||||||
const String16& utf16() const { return str_; }
|
|
||||||
|
|
||||||
///
|
|
||||||
/// Convert to UTF-8 string
|
|
||||||
///
|
|
||||||
String8 utf8() const;
|
|
||||||
|
|
||||||
///
|
|
||||||
/// Convert to UTF-32 string
|
|
||||||
///
|
|
||||||
String32 utf32() const;
|
|
||||||
|
|
||||||
///
|
|
||||||
/// Check if string is empty or not
|
|
||||||
///
|
|
||||||
bool empty() const { return utf16().empty(); }
|
|
||||||
|
|
||||||
private:
|
|
||||||
String16 str_;
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
} // namespace ultralight
|
|
||||||
|
|
|
@ -1,130 +0,0 @@
|
||||||
///
|
|
||||||
/// @file String16.h
|
|
||||||
///
|
|
||||||
/// @brief The header for the String16 class.
|
|
||||||
///
|
|
||||||
/// @author
|
|
||||||
///
|
|
||||||
/// This file is a part of Ultralight, a fast, lightweight, HTML UI engine
|
|
||||||
///
|
|
||||||
/// Website: <http://ultralig.ht>
|
|
||||||
///
|
|
||||||
/// Copyright (C) 2019 Ultralight, Inc. All rights reserved.
|
|
||||||
///
|
|
||||||
#pragma once
|
|
||||||
#include <Ultralight/Defines.h>
|
|
||||||
#include <Ultralight/RefPtr.h>
|
|
||||||
#include <stddef.h>
|
|
||||||
|
|
||||||
namespace ultralight {
|
|
||||||
|
|
||||||
namespace detail {
|
|
||||||
template<int> struct selector;
|
|
||||||
template<> struct selector<4> { typedef char16_t Char16; };
|
|
||||||
template<> struct selector<2> { typedef wchar_t Char16; };
|
|
||||||
}
|
|
||||||
|
|
||||||
#ifdef DISABLE_NATIVE_WCHAR_T
|
|
||||||
// Force Char16 type to use char16_t, used on Windows when native wchar_t support is disabled.
|
|
||||||
typedef char16_t Char16;
|
|
||||||
#else
|
|
||||||
// We use wchar_t if size == 2, otherwise use char16_t
|
|
||||||
typedef detail::selector<sizeof(wchar_t)>::Char16 Char16;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
///
|
|
||||||
/// @brief A UTF-16 string container.
|
|
||||||
///
|
|
||||||
class UExport String16 {
|
|
||||||
public:
|
|
||||||
// Make an empty String16
|
|
||||||
String16();
|
|
||||||
|
|
||||||
// Make a String16 from null-terminated ASCII C-string
|
|
||||||
String16(const char* c_str);
|
|
||||||
|
|
||||||
// Make a String16 from ASCII C-string with certain length
|
|
||||||
String16(const char* c_str, size_t len);
|
|
||||||
|
|
||||||
// Make a String16 from raw UTF-16 buffer with certain length
|
|
||||||
String16(const Char16* str, size_t len);
|
|
||||||
|
|
||||||
// Make a String16 from raw unsigned short UTF-16 buffer with certain length. Useful on Windows
|
|
||||||
// when native support for wchar_t is disabled (eg, /Zc:wchar_t-).
|
|
||||||
String16(const unsigned short* str, size_t len);
|
|
||||||
|
|
||||||
// Make a deep copy of String16
|
|
||||||
String16(const String16& other);
|
|
||||||
|
|
||||||
~String16();
|
|
||||||
|
|
||||||
// Assign a String16 to this one, deep copy is made
|
|
||||||
String16& operator=(const String16& other);
|
|
||||||
|
|
||||||
// Append a String16 to this one.
|
|
||||||
String16& operator+=(const String16& other);
|
|
||||||
|
|
||||||
// Concatenation operator
|
|
||||||
inline friend String16 operator+(String16 lhs, const String16& rhs) { lhs += rhs; return lhs; }
|
|
||||||
|
|
||||||
// Get raw UTF-16 data
|
|
||||||
Char16* data() { return data_; }
|
|
||||||
|
|
||||||
// Get raw UTF-16 data (const)
|
|
||||||
const Char16* data() const { return data_; }
|
|
||||||
|
|
||||||
// Get raw UTF-16 data as unsigned short. This is useful on Windows if you compile without native
|
|
||||||
// support for wchar_t (eg, /Zc:wchar_t-)
|
|
||||||
unsigned short* udata() { return reinterpret_cast<unsigned short*>(data_); }
|
|
||||||
|
|
||||||
// Get raw UTF-16 data as unsigned short (const).
|
|
||||||
const unsigned short* udata() const { return reinterpret_cast<const unsigned short*>(data_); }
|
|
||||||
|
|
||||||
// Get length in characters.
|
|
||||||
size_t length() const { return length_; }
|
|
||||||
|
|
||||||
// Get size in characters (synonym for length)
|
|
||||||
size_t size() const { return length_; }
|
|
||||||
|
|
||||||
// Check if string is empty.
|
|
||||||
bool empty() const { return !data_ || length_ == 0; }
|
|
||||||
|
|
||||||
// Get character at specific position
|
|
||||||
Char16& operator[](size_t pos) { return data_[pos]; }
|
|
||||||
|
|
||||||
// Get character at specific position (const)
|
|
||||||
const Char16& operator[](size_t pos) const { return data_[pos]; }
|
|
||||||
|
|
||||||
private:
|
|
||||||
Char16* data_;
|
|
||||||
size_t length_;
|
|
||||||
};
|
|
||||||
|
|
||||||
///
|
|
||||||
/// @brief A UTF-16 string vector.
|
|
||||||
///
|
|
||||||
class UExport String16Vector : public RefCounted {
|
|
||||||
public:
|
|
||||||
// Create an empty string vector
|
|
||||||
static Ref<String16Vector> Create();
|
|
||||||
|
|
||||||
// Create a string vector from an existing array (a deep copy is made)
|
|
||||||
static Ref<String16Vector> Create(const String16* stringArray, size_t len);
|
|
||||||
|
|
||||||
// Add an element to the back of the string vector
|
|
||||||
virtual void push_back(const String16& val) = 0;
|
|
||||||
|
|
||||||
// Get raw String16 vector array
|
|
||||||
virtual String16* data() = 0;
|
|
||||||
|
|
||||||
// Get the number of elements in vector
|
|
||||||
virtual size_t size() const = 0;
|
|
||||||
|
|
||||||
protected:
|
|
||||||
String16Vector();
|
|
||||||
virtual ~String16Vector();
|
|
||||||
String16Vector(const String16Vector&);
|
|
||||||
void operator=(const String16Vector&);
|
|
||||||
};
|
|
||||||
|
|
||||||
} // namespace ultralight
|
|
|
@ -1,71 +0,0 @@
|
||||||
///
|
|
||||||
/// @file String32.h
|
|
||||||
///
|
|
||||||
/// @brief The header for the String32 class.
|
|
||||||
///
|
|
||||||
/// @author
|
|
||||||
///
|
|
||||||
/// This file is a part of Ultralight, a fast, lightweight, HTML UI engine
|
|
||||||
///
|
|
||||||
/// Website: <http://ultralig.ht>
|
|
||||||
///
|
|
||||||
/// Copyright (C) 2019 Ultralight, Inc. All rights reserved.
|
|
||||||
///
|
|
||||||
#pragma once
|
|
||||||
#include <Ultralight/Defines.h>
|
|
||||||
#include <stddef.h>
|
|
||||||
|
|
||||||
namespace ultralight {
|
|
||||||
|
|
||||||
///
|
|
||||||
/// @brief A UTF-32 string container.
|
|
||||||
///
|
|
||||||
class UExport String32 {
|
|
||||||
public:
|
|
||||||
// Make an empty String32
|
|
||||||
String32();
|
|
||||||
|
|
||||||
// Make a String32 from raw UTF-32 string with certain length
|
|
||||||
String32(const char32_t* c_str, size_t len);
|
|
||||||
|
|
||||||
// Make a deep copy of String32
|
|
||||||
String32(const String32& other);
|
|
||||||
|
|
||||||
~String32();
|
|
||||||
|
|
||||||
// Assign a String32 to this one, deep copy is made
|
|
||||||
String32& operator=(const String32& other);
|
|
||||||
|
|
||||||
// Append a String32 to this one.
|
|
||||||
String32& operator+=(const String32& other);
|
|
||||||
|
|
||||||
// Concatenation operator
|
|
||||||
inline friend String32 operator+(String32 lhs, const String32& rhs) { lhs += rhs; return lhs; }
|
|
||||||
|
|
||||||
// Get raw UTF-32 data
|
|
||||||
char32_t* data() { return data_; }
|
|
||||||
|
|
||||||
// Get raw UTF-32 data (const)
|
|
||||||
const char32_t* data() const { return data_; }
|
|
||||||
|
|
||||||
// Get length in characters.
|
|
||||||
size_t length() const { return length_; }
|
|
||||||
|
|
||||||
// Get size in characters (synonym for length)
|
|
||||||
size_t size() const { return length_; }
|
|
||||||
|
|
||||||
// Check if string is empty.
|
|
||||||
bool empty() const { return !data_ || length_ == 0; }
|
|
||||||
|
|
||||||
// Get character at specific position
|
|
||||||
char32_t& operator[](size_t pos) { return data_[pos]; }
|
|
||||||
|
|
||||||
// Get character at specific position (const)
|
|
||||||
const char32_t& operator[](size_t pos) const { return data_[pos]; }
|
|
||||||
|
|
||||||
private:
|
|
||||||
char32_t* data_;
|
|
||||||
size_t length_;
|
|
||||||
};
|
|
||||||
|
|
||||||
} // namespace ultralight
|
|
|
@ -1,74 +0,0 @@
|
||||||
///
|
|
||||||
/// @file String8.h
|
|
||||||
///
|
|
||||||
/// @brief The header for the String8 class.
|
|
||||||
///
|
|
||||||
/// @author
|
|
||||||
///
|
|
||||||
/// This file is a part of Ultralight, a fast, lightweight, HTML UI engine
|
|
||||||
///
|
|
||||||
/// Website: <http://ultralig.ht>
|
|
||||||
///
|
|
||||||
/// Copyright (C) 2019 Ultralight, Inc. All rights reserved.
|
|
||||||
///
|
|
||||||
#pragma once
|
|
||||||
#include <Ultralight/Defines.h>
|
|
||||||
#include <stddef.h>
|
|
||||||
|
|
||||||
namespace ultralight {
|
|
||||||
|
|
||||||
///
|
|
||||||
/// @brief A UTF-8 string container.
|
|
||||||
//
|
|
||||||
class UExport String8 {
|
|
||||||
public:
|
|
||||||
// Make an empty String8
|
|
||||||
String8();
|
|
||||||
|
|
||||||
// Make a String8 from raw, null-terminated UTF-8 string
|
|
||||||
String8(const char* c_str);
|
|
||||||
|
|
||||||
// Make a String8 from raw UTF-8 string with certain length
|
|
||||||
String8(const char* c_str, size_t len);
|
|
||||||
|
|
||||||
// Make a deep copy of String8
|
|
||||||
String8(const String8& other);
|
|
||||||
|
|
||||||
~String8();
|
|
||||||
|
|
||||||
// Assign a String8 to this one, deep copy is made
|
|
||||||
String8& operator=(const String8& other);
|
|
||||||
|
|
||||||
// Append a String8 to this one.
|
|
||||||
String8& operator+=(const String8& other);
|
|
||||||
|
|
||||||
// Concatenation operator
|
|
||||||
inline friend String8 operator+(String8 lhs, const String8& rhs) { lhs += rhs; return lhs; }
|
|
||||||
|
|
||||||
// Get raw UTF-8 data
|
|
||||||
char* data() { return data_; }
|
|
||||||
|
|
||||||
// Get raw UTF-8 data (const)
|
|
||||||
const char* data() const { return data_; }
|
|
||||||
|
|
||||||
// Get length in characters.
|
|
||||||
size_t length() const { return length_; }
|
|
||||||
|
|
||||||
// Get size in characters (synonym for length)
|
|
||||||
size_t size() const { return length_; }
|
|
||||||
|
|
||||||
// Check if string is empty.
|
|
||||||
bool empty() const { return !data_ || length_ == 0; }
|
|
||||||
|
|
||||||
// Get character at specific position
|
|
||||||
char& operator[](size_t pos) { return data_[pos]; }
|
|
||||||
|
|
||||||
// Get character at specific position (const)
|
|
||||||
const char& operator[](size_t pos) const { return data_[pos]; }
|
|
||||||
|
|
||||||
private:
|
|
||||||
char* data_;
|
|
||||||
size_t length_;
|
|
||||||
};
|
|
||||||
|
|
||||||
} // namespace ultralight
|
|
|
@ -1,24 +0,0 @@
|
||||||
// Copyright 2019 Ultralight, Inc. All rights reserved.
|
|
||||||
#pragma once
|
|
||||||
#include <Ultralight/Defines.h>
|
|
||||||
#include <Ultralight/RefPtr.h>
|
|
||||||
#include <Ultralight/String16.h>
|
|
||||||
#include <Ultralight/String8.h>
|
|
||||||
#include <Ultralight/String.h>
|
|
||||||
#include <Ultralight/Bitmap.h>
|
|
||||||
#include <Ultralight/Buffer.h>
|
|
||||||
#include <Ultralight/View.h>
|
|
||||||
#include <Ultralight/KeyCodes.h>
|
|
||||||
#include <Ultralight/KeyEvent.h>
|
|
||||||
#include <Ultralight/Listener.h>
|
|
||||||
#include <Ultralight/Matrix.h>
|
|
||||||
#include <Ultralight/MouseEvent.h>
|
|
||||||
#include <Ultralight/Renderer.h>
|
|
||||||
#include <Ultralight/Geometry.h>
|
|
||||||
#include <Ultralight/RenderTarget.h>
|
|
||||||
#include <Ultralight/ScrollEvent.h>
|
|
||||||
#include <Ultralight/platform/Platform.h>
|
|
||||||
#include <Ultralight/platform/Config.h>
|
|
||||||
#include <Ultralight/platform/GPUDriver.h>
|
|
||||||
#include <Ultralight/platform/FileSystem.h>
|
|
||||||
#include <Ultralight/platform/FontLoader.h>
|
|
|
@ -1,244 +0,0 @@
|
||||||
///
|
|
||||||
/// @file View.h
|
|
||||||
///
|
|
||||||
/// @brief The header for the View class.
|
|
||||||
///
|
|
||||||
/// @author
|
|
||||||
///
|
|
||||||
/// This file is a part of Ultralight, a fast, lightweight, HTML UI engine
|
|
||||||
///
|
|
||||||
/// Website: <http://ultralig.ht>
|
|
||||||
///
|
|
||||||
/// Copyright (C) 2019 Ultralight, Inc. All rights reserved.
|
|
||||||
///
|
|
||||||
#pragma once
|
|
||||||
#include <JavaScriptCore/JavaScript.h>
|
|
||||||
#include <Ultralight/Defines.h>
|
|
||||||
#include <Ultralight/RefPtr.h>
|
|
||||||
#include <Ultralight/KeyEvent.h>
|
|
||||||
#include <Ultralight/MouseEvent.h>
|
|
||||||
#include <Ultralight/ScrollEvent.h>
|
|
||||||
#include <Ultralight/RenderTarget.h>
|
|
||||||
#include <Ultralight/Bitmap.h>
|
|
||||||
#include <Ultralight/Listener.h>
|
|
||||||
|
|
||||||
namespace ultralight {
|
|
||||||
|
|
||||||
///
|
|
||||||
/// @brief A View is similar to a tab in a browser-- you load web content into
|
|
||||||
/// it and display it however you want. @see Renderer::CreateView
|
|
||||||
///
|
|
||||||
/// @note The API is currently not thread-safe, all calls must be made on the
|
|
||||||
/// main thread.
|
|
||||||
///
|
|
||||||
class UExport View : public RefCounted {
|
|
||||||
public:
|
|
||||||
///
|
|
||||||
/// Get the URL of the current page loaded into this View, if any.
|
|
||||||
///
|
|
||||||
virtual String url() = 0;
|
|
||||||
|
|
||||||
///
|
|
||||||
/// Get the title of the current page loaded into this View, if any.
|
|
||||||
///
|
|
||||||
virtual String title() = 0;
|
|
||||||
|
|
||||||
///
|
|
||||||
/// Get the width of the View, in device coordinates.
|
|
||||||
///
|
|
||||||
virtual uint32_t width() const = 0;
|
|
||||||
|
|
||||||
///
|
|
||||||
/// Get the height of the View, in device coordinates.
|
|
||||||
///
|
|
||||||
virtual uint32_t height() const = 0;
|
|
||||||
|
|
||||||
///
|
|
||||||
/// Check if the main frame of the page is currently loading.
|
|
||||||
///
|
|
||||||
virtual bool is_loading() = 0;
|
|
||||||
|
|
||||||
///
|
|
||||||
/// Get the RenderTarget for the View.
|
|
||||||
///
|
|
||||||
/// @note The RenderTarget is only used when you define a custom GPUDriver.
|
|
||||||
///
|
|
||||||
/// During each call to Renderer::Render, each View will be drawn to
|
|
||||||
/// an offscreen texture/render-buffer. You should use RenderTarget
|
|
||||||
/// to obtain the internal texture ID for the View and then display
|
|
||||||
/// it in some quad (eg, call GPUDriver::BindTexture with the texture
|
|
||||||
/// ID, then draw a textured quad in your 3D engine, making sure to
|
|
||||||
/// use the UV coords specified in the RenderTarget).
|
|
||||||
///
|
|
||||||
/// @see Overlay.cpp within the AppCore source for an example.
|
|
||||||
///
|
|
||||||
virtual RenderTarget render_target() = 0;
|
|
||||||
|
|
||||||
///
|
|
||||||
/// Check if bitmap is dirty (has changed since last call to View::bitmap)
|
|
||||||
///
|
|
||||||
/// @note Only valid when using the default, offscreen GPUDriver.
|
|
||||||
///
|
|
||||||
virtual bool is_bitmap_dirty() = 0;
|
|
||||||
|
|
||||||
///
|
|
||||||
/// Get the bitmap for the View (calling this resets the dirty state).
|
|
||||||
///
|
|
||||||
// @note Only valid when using the default, offscreen GPUDriver.
|
|
||||||
///
|
|
||||||
virtual RefPtr<Bitmap> bitmap() = 0;
|
|
||||||
|
|
||||||
///
|
|
||||||
/// Load a raw string of HTML, the View will navigate to it as a new page.
|
|
||||||
///
|
|
||||||
virtual void LoadHTML(const String& html) = 0;
|
|
||||||
|
|
||||||
///
|
|
||||||
/// Load a URL, the View will navigate to it as a new page.
|
|
||||||
///
|
|
||||||
/// @note You can use File URLs (eg, file:///page.html) but you must define
|
|
||||||
/// your own FileSystem implementation. @see Platform::set_file_system
|
|
||||||
///
|
|
||||||
virtual void LoadURL(const String& url) = 0;
|
|
||||||
|
|
||||||
///
|
|
||||||
/// Resize View to a certain size.
|
|
||||||
///
|
|
||||||
/// @param width The initial width, in device coordinates.
|
|
||||||
///
|
|
||||||
/// @param height The initial height, in device coordinates.
|
|
||||||
///
|
|
||||||
/// @note The device coordinates are scaled to pixels by multiplying them
|
|
||||||
/// with the current DPI scale (@see Config::device_scale_hint) and
|
|
||||||
/// rounding to the nearest integer value.
|
|
||||||
///
|
|
||||||
virtual void Resize(uint32_t width, uint32_t height) = 0;
|
|
||||||
|
|
||||||
///
|
|
||||||
/// Get the page's JSContext for use with the JavaScriptCore API
|
|
||||||
///
|
|
||||||
/// @note We expose the entire JavaScriptCore API to users for maximum
|
|
||||||
/// flexibility. Each page has its own JSContext that gets reset
|
|
||||||
/// after each page navigation. You should make all your initial
|
|
||||||
/// JavaScript calls to the page within the DOMReady event,
|
|
||||||
/// @see ViewListener::OnDOMReady
|
|
||||||
///
|
|
||||||
virtual JSContextRef js_context() = 0;
|
|
||||||
|
|
||||||
///
|
|
||||||
/// Evaluate a raw string of JavaScript and return results as a native
|
|
||||||
/// JavaScriptCore JSValueRef (@see <JavaScriptCore/JSValueRef.h>)
|
|
||||||
///
|
|
||||||
/// @note This is just a wrapper for JSEvaluateScript() in JavaScriptCore
|
|
||||||
///
|
|
||||||
virtual JSValueRef EvaluateScript(const String& script) = 0;
|
|
||||||
|
|
||||||
///
|
|
||||||
/// Whether or not we can navigate backwards in history
|
|
||||||
///
|
|
||||||
virtual bool CanGoBack() = 0;
|
|
||||||
|
|
||||||
///
|
|
||||||
/// Whether or not we can navigate forwards in history
|
|
||||||
///
|
|
||||||
virtual bool CanGoForward() = 0;
|
|
||||||
|
|
||||||
///
|
|
||||||
/// Navigate backwards in history
|
|
||||||
///
|
|
||||||
virtual void GoBack() = 0;
|
|
||||||
|
|
||||||
///
|
|
||||||
/// Navigate forwards in history
|
|
||||||
///
|
|
||||||
virtual void GoForward() = 0;
|
|
||||||
|
|
||||||
///
|
|
||||||
/// Navigate to an arbitrary offset in history
|
|
||||||
///
|
|
||||||
virtual void GoToHistoryOffset(int offset) = 0;
|
|
||||||
|
|
||||||
///
|
|
||||||
/// Reload current page
|
|
||||||
///
|
|
||||||
virtual void Reload() = 0;
|
|
||||||
|
|
||||||
///
|
|
||||||
/// Stop all page loads
|
|
||||||
///
|
|
||||||
virtual void Stop() = 0;
|
|
||||||
|
|
||||||
///
|
|
||||||
/// Fire a keyboard event
|
|
||||||
///
|
|
||||||
/// @note Only 'Char' events actually generate text in input fields.
|
|
||||||
///
|
|
||||||
virtual void FireKeyEvent(const KeyEvent& evt) = 0;
|
|
||||||
|
|
||||||
///
|
|
||||||
/// Fire a mouse event
|
|
||||||
///
|
|
||||||
virtual void FireMouseEvent(const MouseEvent& evt) = 0;
|
|
||||||
|
|
||||||
///
|
|
||||||
/// Fire a scroll event
|
|
||||||
///
|
|
||||||
virtual void FireScrollEvent(const ScrollEvent& evt) = 0;
|
|
||||||
|
|
||||||
///
|
|
||||||
/// Set a ViewListener to receive callbacks for View-related events.
|
|
||||||
///
|
|
||||||
/// @note Ownership remains with the caller.
|
|
||||||
///
|
|
||||||
virtual void set_view_listener(ViewListener* listener) = 0;
|
|
||||||
|
|
||||||
///
|
|
||||||
/// Get the active ViewListener, if any
|
|
||||||
///
|
|
||||||
virtual ViewListener* view_listener() const = 0;
|
|
||||||
|
|
||||||
///
|
|
||||||
/// Set a LoadListener to receive callbacks for Load-related events.
|
|
||||||
///
|
|
||||||
/// @note Ownership remains with the caller.
|
|
||||||
///
|
|
||||||
virtual void set_load_listener(LoadListener* listener) = 0;
|
|
||||||
|
|
||||||
///
|
|
||||||
/// Get the active LoadListener, if any
|
|
||||||
///
|
|
||||||
virtual LoadListener* load_listener() const = 0;
|
|
||||||
|
|
||||||
///
|
|
||||||
/// Set whether or not this View should be repainted during the next
|
|
||||||
/// call to Renderer::Render
|
|
||||||
///
|
|
||||||
/// @note This flag is automatically set whenever the page content changes
|
|
||||||
/// but you can set it directly in case you need to force a repaint.
|
|
||||||
///
|
|
||||||
virtual void set_needs_paint(bool needs_paint) = 0;
|
|
||||||
|
|
||||||
///
|
|
||||||
/// Whether or not this View should be repainted during the next call to
|
|
||||||
/// Renderer::Render.
|
|
||||||
///
|
|
||||||
virtual bool needs_paint() const = 0;
|
|
||||||
|
|
||||||
///
|
|
||||||
/// Get the inspector for this View, this is useful for debugging and
|
|
||||||
/// inspecting pages locally. This will only succeed if you have the
|
|
||||||
/// inspector assets in your filesystem-- the inspector will look for
|
|
||||||
/// file:///inspector/Main.html when it first loads.
|
|
||||||
///
|
|
||||||
/// @note The inspector View is owned by the View and lazily-created on
|
|
||||||
/// first call. The initial dimensions are 10x10, you should call
|
|
||||||
/// View::Resize() on the returned View to resize it to your desired
|
|
||||||
/// dimensions.
|
|
||||||
///
|
|
||||||
virtual RefPtr<View> inspector() = 0;
|
|
||||||
|
|
||||||
protected:
|
|
||||||
virtual ~View();
|
|
||||||
};
|
|
||||||
|
|
||||||
} // namespace ultralight
|
|
|
@ -1,142 +0,0 @@
|
||||||
///
|
|
||||||
/// @file Config.h
|
|
||||||
///
|
|
||||||
/// @brief The header for the Config struct.
|
|
||||||
///
|
|
||||||
/// @author
|
|
||||||
///
|
|
||||||
/// This file is a part of Ultralight, a fast, lightweight, HTML UI engine
|
|
||||||
///
|
|
||||||
/// Website: <http://ultralig.ht>
|
|
||||||
///
|
|
||||||
/// Copyright (C) 2019 Ultralight, Inc. All rights reserved.
|
|
||||||
///
|
|
||||||
#pragma once
|
|
||||||
#include <Ultralight/Defines.h>
|
|
||||||
#include <Ultralight/String16.h>
|
|
||||||
|
|
||||||
namespace ultralight {
|
|
||||||
|
|
||||||
///
|
|
||||||
/// The winding order for front-facing triangles.
|
|
||||||
///
|
|
||||||
/// @note In most 3D engines, there is the concept that triangles have a
|
|
||||||
/// a "front" and a "back". All the front-facing triangles (eg, those
|
|
||||||
/// that are facing the camera) are rendered, and all back-facing
|
|
||||||
/// triangles are culled (ignored). The winding-order of the triangle's
|
|
||||||
/// vertices is used to determine which side is front and back. You
|
|
||||||
/// should tell Ultralight which winding-order your 3D engine uses.
|
|
||||||
///
|
|
||||||
enum FaceWinding {
|
|
||||||
///
|
|
||||||
/// Clockwise Winding (Direct3D, etc.)
|
|
||||||
///
|
|
||||||
kFaceWinding_Clockwise,
|
|
||||||
|
|
||||||
///
|
|
||||||
/// Counter-Clockwise Winding (OpenGL, etc.)
|
|
||||||
///
|
|
||||||
kFaceWinding_CounterClockwise,
|
|
||||||
};
|
|
||||||
|
|
||||||
///
|
|
||||||
/// @brief Configurations settings for Ultralight.
|
|
||||||
///
|
|
||||||
/// This is intended to be implemented by users and defined before creating the
|
|
||||||
/// Renderer. @see Platform::set_config.
|
|
||||||
///
|
|
||||||
struct UExport Config {
|
|
||||||
///
|
|
||||||
/// The winding order for front-facing triangles. @see FaceWinding
|
|
||||||
///
|
|
||||||
FaceWinding face_winding = kFaceWinding_CounterClockwise;
|
|
||||||
|
|
||||||
///
|
|
||||||
/// Whether or not images should be enabled.
|
|
||||||
///
|
|
||||||
bool enable_images = true;
|
|
||||||
|
|
||||||
///
|
|
||||||
/// Whether or not JavaScript should be enabled.
|
|
||||||
///
|
|
||||||
bool enable_javascript = true;
|
|
||||||
|
|
||||||
///
|
|
||||||
/// When using the default, offscreen GPU driver, whether or not we
|
|
||||||
/// should use BGRA byte order (instead of RGBA). @see View::bitmap
|
|
||||||
///
|
|
||||||
bool use_bgra_for_offscreen_rendering = false;
|
|
||||||
|
|
||||||
///
|
|
||||||
/// The amount that the application DPI has been scaled (200% = 2.0).
|
|
||||||
/// Used for scaling device coordinates to pixels and oversampling raster
|
|
||||||
/// shapes.
|
|
||||||
///
|
|
||||||
double device_scale_hint = 1.0;
|
|
||||||
|
|
||||||
///
|
|
||||||
/// Default font-family to use.
|
|
||||||
///
|
|
||||||
String16 font_family_standard = "Times New Roman";
|
|
||||||
|
|
||||||
///
|
|
||||||
/// Default font-family to use for fixed fonts. (pre/code)
|
|
||||||
///
|
|
||||||
String16 font_family_fixed = "Courier New";
|
|
||||||
|
|
||||||
///
|
|
||||||
/// Default font-family to use for serif fonts.
|
|
||||||
///
|
|
||||||
String16 font_family_serif = "Times New Roman";
|
|
||||||
|
|
||||||
///
|
|
||||||
/// Default font-family to use for sans-serif fonts.
|
|
||||||
///
|
|
||||||
String16 font_family_sans_serif = "Arial";
|
|
||||||
|
|
||||||
///
|
|
||||||
/// Default user-agent string.
|
|
||||||
///
|
|
||||||
String16 user_agent = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) "
|
|
||||||
"AppleWebKit/602.1 (KHTML, like Gecko) "
|
|
||||||
"Ultralight/0.9.2 Safari/602.1";
|
|
||||||
|
|
||||||
///
|
|
||||||
/// Default user stylesheet. You should set this to your own custom CSS
|
|
||||||
/// string to define default styles for various DOM elements, scrollbars,
|
|
||||||
/// and platform input widgets.
|
|
||||||
///
|
|
||||||
String16 user_stylesheet;
|
|
||||||
|
|
||||||
///
|
|
||||||
/// Whether or not we should continuously repaint any Views or compositor
|
|
||||||
/// layers, regardless if they are dirty or not. This is mainly used to
|
|
||||||
/// diagnose painting/shader issues.
|
|
||||||
///
|
|
||||||
bool force_repaint = false;
|
|
||||||
|
|
||||||
///
|
|
||||||
/// When a CSS animation is active, the amount of time to wait before
|
|
||||||
/// triggering another repaint.
|
|
||||||
///
|
|
||||||
double animation_timer_delay = 1.0 / 60.0;
|
|
||||||
|
|
||||||
///
|
|
||||||
/// Size of WebCore's memory cache in bytes.
|
|
||||||
///
|
|
||||||
/// @note You should increase this if you anticipate handling pages with
|
|
||||||
/// large resources, Safari typically uses 128+ MiB for its cache.
|
|
||||||
///
|
|
||||||
uint32_t memory_cache_size = 64 * 1024 * 1024;
|
|
||||||
|
|
||||||
///
|
|
||||||
/// Number of pages to keep in the cache. Defaults to 0 (none).
|
|
||||||
///
|
|
||||||
/// @note Safari typically caches about 5 pages and maintains an on-disk
|
|
||||||
/// cache to support typical web-browsing activities. If you increase
|
|
||||||
/// this, you should probably increase the memory cache size as well.
|
|
||||||
///
|
|
||||||
uint32_t page_cache_size = 0;
|
|
||||||
};
|
|
||||||
|
|
||||||
} // namespace ultralight
|
|
|
@ -1,208 +0,0 @@
|
||||||
///
|
|
||||||
/// @file FileSystem.h
|
|
||||||
///
|
|
||||||
/// @brief The header for the FileSystem interface.
|
|
||||||
///
|
|
||||||
/// @author
|
|
||||||
///
|
|
||||||
/// This file is a part of Ultralight, a fast, lightweight, HTML UI engine
|
|
||||||
///
|
|
||||||
/// Website: <http://ultralig.ht>
|
|
||||||
///
|
|
||||||
/// Copyright (C) 2019 Ultralight, Inc. All rights reserved.
|
|
||||||
///
|
|
||||||
#pragma once
|
|
||||||
#include <Ultralight/Defines.h>
|
|
||||||
#include <Ultralight/String16.h>
|
|
||||||
#include <time.h>
|
|
||||||
|
|
||||||
namespace ultralight {
|
|
||||||
|
|
||||||
///
|
|
||||||
/// File Handle type used as unique ID for opened files.
|
|
||||||
///
|
|
||||||
#if defined(__WIN32__) || defined(_WIN32)
|
|
||||||
typedef size_t FileHandle;
|
|
||||||
#else
|
|
||||||
typedef int FileHandle;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
///
|
|
||||||
/// Handle used to denote an invalid file.
|
|
||||||
///
|
|
||||||
const FileHandle invalidFileHandle = (FileHandle)-1;
|
|
||||||
|
|
||||||
///
|
|
||||||
/// The position to seek from in a file, @see FileSystem::SeekFile
|
|
||||||
///
|
|
||||||
enum FileSeekOrigin {
|
|
||||||
kFileSeekOrigin_Beginning = 0,
|
|
||||||
kFileSeekOrigin_Current,
|
|
||||||
kFileSeekOrigin_End
|
|
||||||
};
|
|
||||||
|
|
||||||
///
|
|
||||||
/// The type of path, @see FileSystem::GetMetadata
|
|
||||||
///
|
|
||||||
enum MetadataType {
|
|
||||||
kMetadataType_Unknown = 0,
|
|
||||||
kMetadataType_File,
|
|
||||||
kMetadataType_Directory,
|
|
||||||
};
|
|
||||||
|
|
||||||
///
|
|
||||||
/// @brief FileSystem interface, used for all file system operations.
|
|
||||||
///
|
|
||||||
/// This is used for things like loading File URLs (eg, <file:///page.html> and
|
|
||||||
/// the JavaScript FileSystem API. If you don't implement this interface, you
|
|
||||||
/// will not be able to load any File URLs.
|
|
||||||
///
|
|
||||||
///
|
|
||||||
/// This is intended to be implemented by users and defined before creating the
|
|
||||||
/// Renderer. @see Platform::set_file_system.
|
|
||||||
///
|
|
||||||
/// @note To support File URL loading, you ONLY need to implement the
|
|
||||||
/// following functions:
|
|
||||||
/// - FileSystem::FileExists
|
|
||||||
/// - FileSystem::GetFileSize
|
|
||||||
/// - FileSystem::GetFileMimeType
|
|
||||||
/// - FileSystem::OpenFile
|
|
||||||
/// - FileSystem::ReadFromFile
|
|
||||||
/// - FileSystem::CloseFile
|
|
||||||
///
|
|
||||||
class UExport FileSystem {
|
|
||||||
public:
|
|
||||||
virtual ~FileSystem();
|
|
||||||
|
|
||||||
///
|
|
||||||
/// Check if file path exists, return true if exists.
|
|
||||||
///
|
|
||||||
virtual bool FileExists(const String16& path) = 0;
|
|
||||||
|
|
||||||
///
|
|
||||||
/// Delete file, return true on success.
|
|
||||||
///
|
|
||||||
virtual bool DeleteFile_(const String16& path) = 0;
|
|
||||||
|
|
||||||
///
|
|
||||||
/// Delete empty directory, return true on success.
|
|
||||||
///
|
|
||||||
virtual bool DeleteEmptyDirectory(const String16& path) = 0;
|
|
||||||
|
|
||||||
///
|
|
||||||
/// Move file, return true on success.
|
|
||||||
///
|
|
||||||
virtual bool MoveFile_(const String16& old_path, const String16& new_path) = 0;
|
|
||||||
|
|
||||||
///
|
|
||||||
/// Get file size, store result in 'result'. Return true on success.
|
|
||||||
///
|
|
||||||
virtual bool GetFileSize(const String16& path, int64_t& result) = 0;
|
|
||||||
|
|
||||||
///
|
|
||||||
/// Get file size of previously opened file, store result in 'result'. Return true on success.
|
|
||||||
///
|
|
||||||
virtual bool GetFileSize(FileHandle handle, int64_t& result) = 0;
|
|
||||||
|
|
||||||
///
|
|
||||||
/// Get file mime type (eg "text/html"), store result in 'result'. Return true on success.
|
|
||||||
///
|
|
||||||
virtual bool GetFileMimeType(const String16& path, String16& result) = 0;
|
|
||||||
|
|
||||||
///
|
|
||||||
/// Get file last modification time, store result in 'result'. Return true on success.
|
|
||||||
///
|
|
||||||
virtual bool GetFileModificationTime(const String16& path, time_t& result) = 0;
|
|
||||||
|
|
||||||
///
|
|
||||||
/// Get file creation time, store result in 'result'. Return true on success.
|
|
||||||
///
|
|
||||||
virtual bool GetFileCreationTime(const String16& path, time_t& result) = 0;
|
|
||||||
|
|
||||||
///
|
|
||||||
/// Get path type (file or directory).
|
|
||||||
///
|
|
||||||
virtual MetadataType GetMetadataType(const String16& path) = 0;
|
|
||||||
|
|
||||||
///
|
|
||||||
/// Concatenate path with another path component. Return concatenated result.
|
|
||||||
///
|
|
||||||
virtual String16 GetPathByAppendingComponent(const String16& path, const String16& component) = 0;
|
|
||||||
|
|
||||||
///
|
|
||||||
/// Create directory, return true on success.
|
|
||||||
///
|
|
||||||
virtual bool CreateDirectory_(const String16& path) = 0;
|
|
||||||
|
|
||||||
///
|
|
||||||
/// Get home directory path.
|
|
||||||
///
|
|
||||||
virtual String16 GetHomeDirectory() = 0;
|
|
||||||
|
|
||||||
///
|
|
||||||
/// Get filename component from path.
|
|
||||||
///
|
|
||||||
virtual String16 GetFilenameFromPath(const String16& path) = 0;
|
|
||||||
|
|
||||||
///
|
|
||||||
/// Get directory name from path.
|
|
||||||
///
|
|
||||||
virtual String16 GetDirectoryNameFromPath(const String16& path) = 0;
|
|
||||||
|
|
||||||
///
|
|
||||||
/// Get volume from path and store free space in 'result'. Return true on success.
|
|
||||||
///
|
|
||||||
virtual bool GetVolumeFreeSpace(const String16& path, uint64_t& result) = 0;
|
|
||||||
|
|
||||||
///
|
|
||||||
/// Get volume from path and return its unique volume id.
|
|
||||||
///
|
|
||||||
virtual int32_t GetVolumeId(const String16& path) = 0;
|
|
||||||
|
|
||||||
///
|
|
||||||
/// Get file listing for directory path with optional filter, return vector of file paths.
|
|
||||||
///
|
|
||||||
virtual Ref<String16Vector> ListDirectory(const String16& path, const String16& filter) = 0;
|
|
||||||
|
|
||||||
///
|
|
||||||
/// Open a temporary file with suggested prefix, store handle in 'handle'. Return path of temporary file.
|
|
||||||
///
|
|
||||||
virtual String16 OpenTemporaryFile(const String16& prefix, FileHandle& handle) = 0;
|
|
||||||
|
|
||||||
///
|
|
||||||
/// Open file path for reading or writing. Return file handle on success, or invalidFileHandle on failure.
|
|
||||||
///
|
|
||||||
virtual FileHandle OpenFile(const String16& path, bool open_for_writing) = 0;
|
|
||||||
|
|
||||||
///
|
|
||||||
/// Close previously-opened file.
|
|
||||||
///
|
|
||||||
virtual void CloseFile(FileHandle& handle) = 0;
|
|
||||||
|
|
||||||
///
|
|
||||||
/// Seek currently-opened file, with offset relative to certain origin. Return new file offset.
|
|
||||||
///
|
|
||||||
virtual int64_t SeekFile(FileHandle handle, int64_t offset, FileSeekOrigin origin) = 0;
|
|
||||||
|
|
||||||
///
|
|
||||||
/// Truncate currently-opened file with offset, return true on success.
|
|
||||||
///
|
|
||||||
virtual bool TruncateFile(FileHandle handle, int64_t offset) = 0;
|
|
||||||
|
|
||||||
///
|
|
||||||
/// Write to currently-opened file, return number of bytes written or -1 on failure.
|
|
||||||
///
|
|
||||||
virtual int64_t WriteToFile(FileHandle handle, const char* data, int64_t length) = 0;
|
|
||||||
|
|
||||||
///
|
|
||||||
/// Read from currently-opened file, return number of bytes read or -1 on failure.
|
|
||||||
///
|
|
||||||
virtual int64_t ReadFromFile(FileHandle handle, char* data, int64_t length) = 0;
|
|
||||||
|
|
||||||
///
|
|
||||||
/// Copy file from source to destination, return true on success.
|
|
||||||
///
|
|
||||||
virtual bool CopyFile_(const String16& source_path, const String16& destination_path) = 0;
|
|
||||||
};
|
|
||||||
|
|
||||||
} // namespace ultralight
|
|
|
@ -1,86 +0,0 @@
|
||||||
///
|
|
||||||
/// @file FontLoader.h
|
|
||||||
///
|
|
||||||
/// @brief The header for the FontLoader interface.
|
|
||||||
///
|
|
||||||
/// @author
|
|
||||||
///
|
|
||||||
/// This file is a part of Ultralight, a fast, lightweight, HTML UI engine
|
|
||||||
///
|
|
||||||
/// Website: <http://ultralig.ht>
|
|
||||||
///
|
|
||||||
/// Copyright (C) 2019 Ultralight, Inc. All rights reserved.
|
|
||||||
///
|
|
||||||
#pragma once
|
|
||||||
#include <Ultralight/Defines.h>
|
|
||||||
#include <Ultralight/String16.h>
|
|
||||||
#include <Ultralight/Buffer.h>
|
|
||||||
|
|
||||||
namespace ultralight {
|
|
||||||
|
|
||||||
///
|
|
||||||
/// @brief Font Loader interface, used for all font lookup operations.
|
|
||||||
///
|
|
||||||
/// Every operating system has its own library of installed system fonts. The
|
|
||||||
/// FontLoader interface is used to lookup these fonts and fetch the actual
|
|
||||||
/// font data (raw TTF/OTF file data) given a certain font description.
|
|
||||||
///
|
|
||||||
/// You can override this interface to bundle your own fonts or override the
|
|
||||||
/// default system font loading behavior.
|
|
||||||
///
|
|
||||||
/// This is intended to be implemented by users and defined before creating the
|
|
||||||
/// Renderer. @see Platform::set_font_loader
|
|
||||||
///
|
|
||||||
class UExport FontLoader {
|
|
||||||
public:
|
|
||||||
virtual ~FontLoader();
|
|
||||||
|
|
||||||
///
|
|
||||||
/// Fallback font family name. Will be used if all other fonts fail to load.
|
|
||||||
///
|
|
||||||
/// @note This font should be GUARANTEED to exist (eg, FontLoader::Load
|
|
||||||
/// won't fail when passed this font family name).
|
|
||||||
///
|
|
||||||
virtual String16 fallback_font() const = 0;
|
|
||||||
|
|
||||||
///
|
|
||||||
/// Fallback font family name that can render the specified characters. This
|
|
||||||
/// is mainly used to support CJK (Chinese, Japanese, Korean) text display.
|
|
||||||
///
|
|
||||||
/// @param characters One or more UTF-16 characters. This is almost ALWAYS
|
|
||||||
/// a single character.
|
|
||||||
///
|
|
||||||
/// @param weight Font weight.
|
|
||||||
///
|
|
||||||
/// @param italic Whether or not italic is requested.
|
|
||||||
///
|
|
||||||
/// @param size Font size.
|
|
||||||
///
|
|
||||||
/// @return Should return a font family name that can render the text.
|
|
||||||
///
|
|
||||||
virtual String16 fallback_font_for_characters(const String16& characters,
|
|
||||||
int weight, bool italic,
|
|
||||||
float size) const = 0;
|
|
||||||
|
|
||||||
///
|
|
||||||
/// Get the actual font file data (TTF/OTF) for a given font description.
|
|
||||||
///
|
|
||||||
/// @param family Font family name.
|
|
||||||
///
|
|
||||||
/// @param weight Font weight.
|
|
||||||
///
|
|
||||||
/// @param italic Whether or not italic is requested.
|
|
||||||
///
|
|
||||||
/// @param size Font size.
|
|
||||||
///
|
|
||||||
/// @return A buffer of bytes containing raw font file contents of the
|
|
||||||
/// font matching the given description.
|
|
||||||
///
|
|
||||||
/// @note As an example of usage, when given the family "Arial", this
|
|
||||||
/// function should return the raw file contents for "ARIAL.TTF"
|
|
||||||
///
|
|
||||||
virtual Ref<Buffer> Load(const String16& family, int weight, bool italic,
|
|
||||||
float size) = 0;
|
|
||||||
};
|
|
||||||
|
|
||||||
} // namespace ultralight
|
|
|
@ -1,285 +0,0 @@
|
||||||
///
|
|
||||||
/// @file GPUDriver.h
|
|
||||||
///
|
|
||||||
/// @brief The header for the GPUDriver interface.
|
|
||||||
///
|
|
||||||
/// @author
|
|
||||||
///
|
|
||||||
/// This file is a part of Ultralight, a fast, lightweight, HTML UI engine
|
|
||||||
///
|
|
||||||
/// Website: <http://ultralig.ht>
|
|
||||||
///
|
|
||||||
/// Copyright (C) 2019 Ultralight, Inc. All rights reserved.
|
|
||||||
///
|
|
||||||
#pragma once
|
|
||||||
#pragma warning(disable: 4251)
|
|
||||||
#include <Ultralight/Defines.h>
|
|
||||||
#include <Ultralight/Geometry.h>
|
|
||||||
#include <Ultralight/Matrix.h>
|
|
||||||
#include <Ultralight/Bitmap.h>
|
|
||||||
|
|
||||||
namespace ultralight {
|
|
||||||
|
|
||||||
///
|
|
||||||
/// @note This pragma pack(push, 1) command is important! Vertex layouts
|
|
||||||
/// should not be padded with any bytes.
|
|
||||||
///
|
|
||||||
#pragma pack(push, 1)
|
|
||||||
|
|
||||||
///
|
|
||||||
/// RenderBuffer description, @see GPUDriver::CreateRenderBuffer.
|
|
||||||
///
|
|
||||||
struct UExport RenderBuffer {
|
|
||||||
uint32_t texture_id;
|
|
||||||
uint32_t width;
|
|
||||||
uint32_t height;
|
|
||||||
bool has_stencil_buffer;
|
|
||||||
bool has_depth_buffer;
|
|
||||||
};
|
|
||||||
|
|
||||||
///
|
|
||||||
/// Vertex layout for path vertices, useful for synthesizing or modifying
|
|
||||||
/// vertex data.
|
|
||||||
///
|
|
||||||
struct Vertex_2f_4ub_2f {
|
|
||||||
float pos[2];
|
|
||||||
unsigned char color[4];
|
|
||||||
float obj[2];
|
|
||||||
};
|
|
||||||
|
|
||||||
///
|
|
||||||
/// Vertex layout for quad vertices, useful for synthesizing or modifying
|
|
||||||
/// vertex data.
|
|
||||||
///
|
|
||||||
struct Vertex_2f_4ub_2f_2f_28f {
|
|
||||||
float pos[2];
|
|
||||||
unsigned char color[4];
|
|
||||||
float tex[2];
|
|
||||||
float obj[2];
|
|
||||||
float data0[4];
|
|
||||||
float data1[4];
|
|
||||||
float data2[4];
|
|
||||||
float data3[4];
|
|
||||||
float data4[4];
|
|
||||||
float data5[4];
|
|
||||||
float data6[4];
|
|
||||||
};
|
|
||||||
|
|
||||||
///
|
|
||||||
/// Vertex formats
|
|
||||||
///
|
|
||||||
enum UExport VertexBufferFormat {
|
|
||||||
kVertexBufferFormat_2f_4ub_2f,
|
|
||||||
kVertexBufferFormat_2f_4ub_2f_2f_28f,
|
|
||||||
};
|
|
||||||
|
|
||||||
///
|
|
||||||
/// Vertex buffer, @see GPUDriver::CreateGeometry
|
|
||||||
///
|
|
||||||
struct UExport VertexBuffer {
|
|
||||||
VertexBufferFormat format;
|
|
||||||
uint32_t size;
|
|
||||||
uint8_t* data;
|
|
||||||
};
|
|
||||||
|
|
||||||
///
|
|
||||||
/// Vertex index type
|
|
||||||
///
|
|
||||||
typedef uint32_t IndexType;
|
|
||||||
|
|
||||||
///
|
|
||||||
/// Vertex index buffer, @see GPUDriver::CreateGeometry
|
|
||||||
///
|
|
||||||
struct UExport IndexBuffer {
|
|
||||||
uint32_t size;
|
|
||||||
uint8_t* data;
|
|
||||||
};
|
|
||||||
|
|
||||||
///
|
|
||||||
/// Shader types, used by GPUState::shader_type
|
|
||||||
///
|
|
||||||
enum UExport ShaderType {
|
|
||||||
kShaderType_Fill,
|
|
||||||
kShaderType_FillPath,
|
|
||||||
};
|
|
||||||
|
|
||||||
///
|
|
||||||
/// GPU state description.
|
|
||||||
///
|
|
||||||
struct UExport GPUState {
|
|
||||||
float viewport_width;
|
|
||||||
float viewport_height;
|
|
||||||
Matrix4x4 transform;
|
|
||||||
bool enable_texturing;
|
|
||||||
bool enable_blend;
|
|
||||||
uint8_t shader_type;
|
|
||||||
uint32_t render_buffer_id;
|
|
||||||
uint32_t texture_1_id;
|
|
||||||
uint32_t texture_2_id;
|
|
||||||
uint32_t texture_3_id;
|
|
||||||
float uniform_scalar[8];
|
|
||||||
vec4 uniform_vector[8];
|
|
||||||
uint8_t clip_size;
|
|
||||||
Matrix4x4 clip[8];
|
|
||||||
bool enable_scissor;
|
|
||||||
Rect scissor_rect;
|
|
||||||
};
|
|
||||||
|
|
||||||
///
|
|
||||||
/// Command types, used by Command::command_type
|
|
||||||
///
|
|
||||||
enum UExport CommandType {
|
|
||||||
kCommandType_ClearRenderBuffer,
|
|
||||||
kCommandType_DrawGeometry,
|
|
||||||
};
|
|
||||||
|
|
||||||
///
|
|
||||||
/// Command description, handling one of these should result in either a call to
|
|
||||||
/// GPUDriver::ClearRenderBuffer or GPUDriver::DrawGeometry.
|
|
||||||
///
|
|
||||||
struct UExport Command {
|
|
||||||
uint8_t command_type;
|
|
||||||
GPUState gpu_state;
|
|
||||||
uint32_t geometry_id;
|
|
||||||
uint32_t indices_count;
|
|
||||||
uint32_t indices_offset;
|
|
||||||
};
|
|
||||||
|
|
||||||
///
|
|
||||||
/// Command list, @see GPUDriver::UpdateCommandList
|
|
||||||
///
|
|
||||||
struct UExport CommandList {
|
|
||||||
uint32_t size;
|
|
||||||
Command* commands;
|
|
||||||
};
|
|
||||||
|
|
||||||
#pragma pack(pop)
|
|
||||||
|
|
||||||
///
|
|
||||||
/// @brief GPUDriver interface, dispatches GPU calls to the native driver.
|
|
||||||
///
|
|
||||||
/// By default, Ultralight uses an offscreen, OpenGL GPUDriver that draws each
|
|
||||||
/// View to an offscreen Bitmap (@see View::bitmap). You can override this to
|
|
||||||
/// provide your own GPUDriver and integrate directly with your own 3D engine.
|
|
||||||
///
|
|
||||||
/// This is intended to be implemented by users and defined before creating the
|
|
||||||
/// Renderer. @see Platform::set_gpu_driver
|
|
||||||
///
|
|
||||||
class UExport GPUDriver {
|
|
||||||
public:
|
|
||||||
virtual ~GPUDriver();
|
|
||||||
|
|
||||||
///
|
|
||||||
/// Called before any commands are dispatched during a frame.
|
|
||||||
///
|
|
||||||
virtual void BeginSynchronize() = 0;
|
|
||||||
|
|
||||||
///
|
|
||||||
/// Called after any commands are dispatched during a frame.
|
|
||||||
///
|
|
||||||
virtual void EndSynchronize() = 0;
|
|
||||||
|
|
||||||
///
|
|
||||||
/// Get the next available texture ID.
|
|
||||||
///
|
|
||||||
virtual uint32_t NextTextureId() = 0;
|
|
||||||
|
|
||||||
/// Create a texture with a certain ID and optional bitmap. If the Bitmap is
|
|
||||||
/// empty (Bitmap::IsEmpty), then a RTT Texture should be created instead.
|
|
||||||
///
|
|
||||||
virtual void CreateTexture(uint32_t texture_id,
|
|
||||||
Ref<Bitmap> bitmap) = 0;
|
|
||||||
|
|
||||||
///
|
|
||||||
/// Update an existing non-RTT texture with new bitmap data.
|
|
||||||
///
|
|
||||||
virtual void UpdateTexture(uint32_t texture_id,
|
|
||||||
Ref<Bitmap> bitmap) = 0;
|
|
||||||
|
|
||||||
///
|
|
||||||
/// Bind a texture to a certain texture unit.
|
|
||||||
///
|
|
||||||
virtual void BindTexture(uint8_t texture_unit,
|
|
||||||
uint32_t texture_id) = 0;
|
|
||||||
|
|
||||||
///
|
|
||||||
/// Destroy a texture.
|
|
||||||
///
|
|
||||||
virtual void DestroyTexture(uint32_t texture_id) = 0;
|
|
||||||
|
|
||||||
///
|
|
||||||
/// Generate the next available render buffer ID.
|
|
||||||
///
|
|
||||||
virtual uint32_t NextRenderBufferId() = 0;
|
|
||||||
|
|
||||||
///
|
|
||||||
/// Create a render buffer with certain ID and buffer description.
|
|
||||||
///
|
|
||||||
virtual void CreateRenderBuffer(uint32_t render_buffer_id,
|
|
||||||
const RenderBuffer& buffer) = 0;
|
|
||||||
|
|
||||||
///
|
|
||||||
/// Bind a render buffer
|
|
||||||
///
|
|
||||||
virtual void BindRenderBuffer(uint32_t render_buffer_id) = 0;
|
|
||||||
|
|
||||||
///
|
|
||||||
/// Clear a render buffer (flush pixels to 0).
|
|
||||||
///
|
|
||||||
virtual void ClearRenderBuffer(uint32_t render_buffer_id) = 0;
|
|
||||||
|
|
||||||
///
|
|
||||||
/// Destroy a render buffer
|
|
||||||
///
|
|
||||||
virtual void DestroyRenderBuffer(uint32_t render_buffer_id) = 0;
|
|
||||||
|
|
||||||
///
|
|
||||||
/// Generate the next available geometry ID.
|
|
||||||
///
|
|
||||||
virtual uint32_t NextGeometryId() = 0;
|
|
||||||
|
|
||||||
///
|
|
||||||
/// Create geometry with certain ID and vertex/index data.
|
|
||||||
///
|
|
||||||
virtual void CreateGeometry(uint32_t geometry_id,
|
|
||||||
const VertexBuffer& vertices,
|
|
||||||
const IndexBuffer& indices) = 0;
|
|
||||||
|
|
||||||
///
|
|
||||||
/// Update existing geometry with new vertex/index data.
|
|
||||||
///
|
|
||||||
virtual void UpdateGeometry(uint32_t geometry_id,
|
|
||||||
const VertexBuffer& vertices,
|
|
||||||
const IndexBuffer& indices) = 0;
|
|
||||||
|
|
||||||
///
|
|
||||||
/// Draw geometry using the specific index count/offset and GPUState.
|
|
||||||
///
|
|
||||||
virtual void DrawGeometry(uint32_t geometry_id,
|
|
||||||
uint32_t indices_count,
|
|
||||||
uint32_t indices_offset,
|
|
||||||
const GPUState& state) = 0;
|
|
||||||
|
|
||||||
///
|
|
||||||
/// Destroy geometry.
|
|
||||||
///
|
|
||||||
virtual void DestroyGeometry(uint32_t geometry_id) = 0;
|
|
||||||
|
|
||||||
///
|
|
||||||
/// Update command list (you should copy the commands to your own structure).
|
|
||||||
///
|
|
||||||
virtual void UpdateCommandList(const CommandList& list) = 0;
|
|
||||||
|
|
||||||
///
|
|
||||||
/// Check if any commands need drawing.
|
|
||||||
///
|
|
||||||
virtual bool HasCommandsPending() = 0;
|
|
||||||
|
|
||||||
///
|
|
||||||
/// Iterate through stored command list and dispatch to ClearRenderBuffer or
|
|
||||||
/// DrawGeometry, respectively. Command list should be cleared at end of call.
|
|
||||||
///
|
|
||||||
virtual void DrawCommandList() = 0;
|
|
||||||
};
|
|
||||||
|
|
||||||
} // namespace ultralight
|
|
|
@ -1,116 +0,0 @@
|
||||||
///
|
|
||||||
/// @file Platform.h
|
|
||||||
///
|
|
||||||
/// @brief The header for the Platform singleton.
|
|
||||||
///
|
|
||||||
/// @author
|
|
||||||
///
|
|
||||||
/// This file is a part of Ultralight, a fast, lightweight, HTML UI engine
|
|
||||||
///
|
|
||||||
/// Website: <http://ultralig.ht>
|
|
||||||
///
|
|
||||||
/// Copyright (C) 2019 Ultralight, Inc. All rights reserved.
|
|
||||||
///
|
|
||||||
#pragma once
|
|
||||||
#include <Ultralight/Defines.h>
|
|
||||||
|
|
||||||
namespace ultralight {
|
|
||||||
|
|
||||||
struct Config;
|
|
||||||
class GPUDriver;
|
|
||||||
class FontLoader;
|
|
||||||
class FileSystem;
|
|
||||||
|
|
||||||
///
|
|
||||||
/// @brief Platform singleton to configure Ultralight and provide user-defined
|
|
||||||
/// implementations for various platform operations.
|
|
||||||
///
|
|
||||||
/// @note All of these settings and user-defined interfaces should be set
|
|
||||||
/// BEFORE creating the Renderer.
|
|
||||||
///
|
|
||||||
/// A default GPUDriver and FontLoader are provided, you must provide
|
|
||||||
/// your own FileSystem interface if you want to load local files.
|
|
||||||
///
|
|
||||||
/// For more info about the defaults @see DefaultGPUDriver and
|
|
||||||
/// @see DefaultFontLoader.
|
|
||||||
///
|
|
||||||
class UExport Platform {
|
|
||||||
public:
|
|
||||||
///
|
|
||||||
/// Get the Platform singleton
|
|
||||||
///
|
|
||||||
static Platform& instance();
|
|
||||||
|
|
||||||
virtual ~Platform();
|
|
||||||
|
|
||||||
///
|
|
||||||
/// Set the Config
|
|
||||||
///
|
|
||||||
virtual void set_config(const Config& config) = 0;
|
|
||||||
|
|
||||||
///
|
|
||||||
/// Get the Config
|
|
||||||
///
|
|
||||||
virtual const Config& config() const = 0;
|
|
||||||
|
|
||||||
///
|
|
||||||
/// Set the GPU Driver (will handle all rendering)
|
|
||||||
///
|
|
||||||
/// @param gpu_driver A user-defined GPUDriver implementation, ownership
|
|
||||||
/// remains with the caller.
|
|
||||||
///
|
|
||||||
/// @note If you never call this, the default driver will be used instead.
|
|
||||||
/// @see DefaultGPUDriver
|
|
||||||
///
|
|
||||||
virtual void set_gpu_driver(GPUDriver* gpu_driver) = 0;
|
|
||||||
|
|
||||||
///
|
|
||||||
/// Get the GPU Driver
|
|
||||||
///
|
|
||||||
virtual GPUDriver* gpu_driver() const = 0;
|
|
||||||
|
|
||||||
///
|
|
||||||
/// Set the Font Loader (will be used to map font families to actual fonts)
|
|
||||||
///
|
|
||||||
/// @param font_loader A user-defined FontLoader implementation, ownership
|
|
||||||
/// remains with the caller.
|
|
||||||
///
|
|
||||||
/// @note If you never call this, the default font loader will be used
|
|
||||||
/// instead. @see DefaultFontLoader
|
|
||||||
///
|
|
||||||
virtual void set_font_loader(FontLoader* font_loader) = 0;
|
|
||||||
|
|
||||||
///
|
|
||||||
/// Get the Font Loader
|
|
||||||
///
|
|
||||||
virtual FontLoader* font_loader() const = 0;
|
|
||||||
|
|
||||||
///
|
|
||||||
/// Set the File System (will be used for all file system operations)
|
|
||||||
///
|
|
||||||
/// @param file_system A user-defined FileSystem implementation, ownership
|
|
||||||
/// remains with the caller.
|
|
||||||
///
|
|
||||||
virtual void set_file_system(FileSystem* file_system) = 0;
|
|
||||||
|
|
||||||
///
|
|
||||||
/// Get the File System
|
|
||||||
///
|
|
||||||
virtual FileSystem* file_system() const = 0;
|
|
||||||
};
|
|
||||||
|
|
||||||
///
|
|
||||||
/// The default GPU driver is an OpenGL driver that paints each View to an
|
|
||||||
/// offscreen bitmap (@see View::bitmap). This is lazily-initialized.
|
|
||||||
///
|
|
||||||
UExport GPUDriver* DefaultGPUDriver();
|
|
||||||
|
|
||||||
///
|
|
||||||
/// The default Font Loader uses the native font loader API for the platform.
|
|
||||||
///
|
|
||||||
/// @note Windows and macOS font loading is implemented but Linux is still in
|
|
||||||
/// progress-- currently just loads an embedded Roboto font.
|
|
||||||
///
|
|
||||||
UExport FontLoader* DefaultFontLoader();
|
|
||||||
|
|
||||||
} // namespace ultralight
|
|
Loading…
Reference in New Issue