mirror of
https://github.com/pbek/QOwnNotes.git
synced 2025-06-28 21:09:52 +00:00
lint: format a lot more files
Signed-off-by: Patrizio Bekerle <patrizio@bekerle.com>
This commit is contained in:
parent
9c033736de
commit
097caef2ec
222 changed files with 52271 additions and 62384 deletions
File diff suppressed because it is too large
Load diff
|
@ -37,23 +37,23 @@ else()
|
|||
message("Non-debug build configuration detected")
|
||||
endif()
|
||||
|
||||
set_target_properties(QOwnNotes PROPERTIES
|
||||
CXX_STANDARD 11
|
||||
set_target_properties(
|
||||
QOwnNotes
|
||||
PROPERTIES CXX_STANDARD 11
|
||||
CXX_STANDARD_REQUIRED ON
|
||||
AUTOMOC ON
|
||||
AUTOUIC ON
|
||||
AUTORCC ON
|
||||
)
|
||||
AUTORCC ON)
|
||||
|
||||
if(UNIX AND DEV_MODE)
|
||||
if(CMAKE_CXX_COMPILER_ID MATCHES "Clang")
|
||||
target_compile_options(QOwnNotes PRIVATE
|
||||
-Wall -Wextra -pedantic -Wno-gnu-zero-variadic-macro-arguments -Wno-error=deprecated-declarations
|
||||
)
|
||||
target_compile_options(
|
||||
QOwnNotes
|
||||
PRIVATE -Wall -Wextra -pedantic -Wno-gnu-zero-variadic-macro-arguments
|
||||
-Wno-error=deprecated-declarations)
|
||||
else()
|
||||
target_compile_options(QOwnNotes PRIVATE
|
||||
-Wall -Wextra -pedantic -Wno-error=deprecated-declarations
|
||||
)
|
||||
target_compile_options(QOwnNotes PRIVATE -Wall -Wextra -pedantic
|
||||
-Wno-error=deprecated-declarations)
|
||||
endif()
|
||||
|
||||
# enable werror on linux
|
||||
|
@ -63,15 +63,12 @@ if (UNIX AND DEV_MODE)
|
|||
endif()
|
||||
endif()
|
||||
|
||||
target_include_directories(QOwnNotes PRIVATE
|
||||
${CMAKE_CURRENT_LIST_DIR}
|
||||
${CMAKE_CURRENT_BINARY_DIR}
|
||||
)
|
||||
target_include_directories(QOwnNotes PRIVATE ${CMAKE_CURRENT_LIST_DIR}
|
||||
${CMAKE_CURRENT_BINARY_DIR})
|
||||
|
||||
# Disable shared library building of libraries
|
||||
set(BUILD_SHARED_LIBS OFF)
|
||||
# QHotKey library
|
||||
# Disable building tests inside QHotKey library
|
||||
# QHotKey library Disable building tests inside QHotKey library
|
||||
set(CMAKE_POLICY_DEFAULT_CMP0077 NEW)
|
||||
set(QHOTKEY_EXAMPLES OFF)
|
||||
add_subdirectory(libraries/qhotkey EXCLUDE_FROM_ALL)
|
||||
|
@ -93,7 +90,10 @@ endif()
|
|||
message("Using Qt version ${QT_VERSION_MAJOR}")
|
||||
set(QT_NO_CREATE_VERSIONLESS_FUNCTIONS ON)
|
||||
|
||||
find_package(Qt${QT_VERSION_MAJOR} COMPONENTS REQUIRED
|
||||
find_package(
|
||||
Qt${QT_VERSION_MAJOR}
|
||||
COMPONENTS
|
||||
REQUIRED
|
||||
LinguistTools
|
||||
Core
|
||||
Widgets
|
||||
|
@ -105,8 +105,7 @@ find_package(Qt${QT_VERSION_MAJOR} COMPONENTS REQUIRED
|
|||
PrintSupport
|
||||
WebSockets
|
||||
Qml
|
||||
Concurrent
|
||||
)
|
||||
Concurrent)
|
||||
|
||||
find_program(CCACHE_FOUND ccache)
|
||||
|
||||
|
@ -126,8 +125,7 @@ set(RESOURCE_FILES
|
|||
configurations.qrc
|
||||
libraries/qmarkdowntextedit/media.qrc
|
||||
libraries/qdarkstyle/style.qrc
|
||||
libraries/qkeysequencewidget/qkeysequencewidget/qkeysequencewidget.qrc
|
||||
)
|
||||
libraries/qkeysequencewidget/qkeysequencewidget/qkeysequencewidget.qrc)
|
||||
|
||||
set(SOURCE_FILES
|
||||
dialogs/welcomedialog.cpp
|
||||
|
@ -347,10 +345,8 @@ set(SOURCE_FILES
|
|||
libraries/fuzzy/kfuzzymatcher.cpp
|
||||
libraries/qr-code-generator/QrCode.hpp
|
||||
libraries/qr-code-generator/QrCode.cpp
|
||||
|
||||
threads/scriptthread.cpp
|
||||
threads/scriptthread.h
|
||||
|
||||
widgets/qownnotesmarkdowntextedit.cpp
|
||||
widgets/qownnotesmarkdowntextedit.h
|
||||
widgets/navigationwidget.cpp
|
||||
|
@ -428,11 +424,15 @@ set(SOURCE_FILES
|
|||
services/websocketserverservice.h
|
||||
services/webappclientservice.cpp
|
||||
services/webappclientservice.h
|
||||
entities/bookmark.h entities/bookmark.cpp
|
||||
entities/commandsnippet.h entities/commandsnippet.cpp)
|
||||
entities/bookmark.h
|
||||
entities/bookmark.cpp
|
||||
entities/commandsnippet.h
|
||||
entities/commandsnippet.cpp)
|
||||
|
||||
# spellchecker
|
||||
list(APPEND SOURCE_FILES
|
||||
list(
|
||||
APPEND
|
||||
SOURCE_FILES
|
||||
libraries/sonnet/src/plugins/hunspell/hunspellclient.cpp
|
||||
libraries/sonnet/src/plugins/hunspell/hunspellclient.h
|
||||
libraries/sonnet/src/plugins/hunspell/hunspelldebug.cpp
|
||||
|
@ -481,18 +481,14 @@ list(APPEND SOURCE_FILES
|
|||
libraries/sonnet/src/plugins/hunspell/hunspell/src/parsers/textparser.cxx
|
||||
libraries/sonnet/src/plugins/hunspell/hunspell/src/parsers/textparser.hxx
|
||||
libraries/sonnet/src/plugins/hunspell/hunspell/src/parsers/xmlparser.cxx
|
||||
libraries/sonnet/src/plugins/hunspell/hunspell/src/parsers/xmlparser.hxx
|
||||
)
|
||||
libraries/sonnet/src/plugins/hunspell/hunspell/src/parsers/xmlparser.hxx)
|
||||
|
||||
# md4c
|
||||
list(APPEND SOURCE_FILES
|
||||
libraries/md4c/src/md4c.c
|
||||
libraries/md4c/src/md4c-html.c
|
||||
libraries/md4c/src/entity.c
|
||||
)
|
||||
list(APPEND SOURCE_FILES libraries/md4c/src/md4c.c
|
||||
libraries/md4c/src/md4c-html.c libraries/md4c/src/entity.c)
|
||||
|
||||
# Translation files
|
||||
SET(QON_TS_FILES
|
||||
set(QON_TS_FILES
|
||||
languages/QOwnNotes_en.ts
|
||||
languages/QOwnNotes_de.ts
|
||||
languages/QOwnNotes_fr.ts
|
||||
|
@ -557,8 +553,7 @@ SET(QON_TS_FILES
|
|||
languages/QOwnNotes_bs.ts
|
||||
languages/QOwnNotes_mk.ts
|
||||
languages/QOwnNotes_ko.ts
|
||||
languages/QOwnNotes_et.ts
|
||||
)
|
||||
languages/QOwnNotes_et.ts)
|
||||
|
||||
if(QON_QT6_BUILD)
|
||||
qt6_add_translation(QON_QM_FILES ${QON_TS_FILES})
|
||||
|
@ -568,15 +563,13 @@ endif()
|
|||
|
||||
add_custom_target(translations DEPENDS ${QON_QM_FILES})
|
||||
|
||||
target_sources(QOwnNotes PRIVATE
|
||||
${SOURCE_FILES}
|
||||
${RESOURCE_FILES}
|
||||
${QON_QM_FILES}
|
||||
)
|
||||
target_sources(QOwnNotes PRIVATE ${SOURCE_FILES} ${RESOURCE_FILES}
|
||||
${QON_QM_FILES})
|
||||
|
||||
# The Qt5::Widgets target will also link Qt::Gui and Qt::Core targets
|
||||
target_link_libraries(QOwnNotes PRIVATE
|
||||
Qt${QT_VERSION_MAJOR}::Widgets
|
||||
target_link_libraries(
|
||||
QOwnNotes
|
||||
PRIVATE Qt${QT_VERSION_MAJOR}::Widgets
|
||||
Qt${QT_VERSION_MAJOR}::Sql
|
||||
Qt${QT_VERSION_MAJOR}::Svg
|
||||
Qt${QT_VERSION_MAJOR}::Network
|
||||
|
@ -588,32 +581,25 @@ target_link_libraries(QOwnNotes PRIVATE
|
|||
QHotkey::QHotkey
|
||||
Botan::Botan
|
||||
fakevim
|
||||
Google::DiffMatchPatch
|
||||
)
|
||||
Google::DiffMatchPatch)
|
||||
|
||||
if(USE_QLITEHTML)
|
||||
target_link_libraries(QOwnNotes PRIVATE
|
||||
qlitehtml::qlitehtml
|
||||
)
|
||||
target_link_libraries(QOwnNotes PRIVATE qlitehtml::qlitehtml)
|
||||
endif()
|
||||
|
||||
if(MINGW OR MSVC)
|
||||
# Qt 5 does not define UNICODE for CMake
|
||||
# only qmake automatically define UNICODE
|
||||
target_compile_definitions(QOwnNotes PRIVATE
|
||||
UNICODE _UNICODE
|
||||
)
|
||||
# Qt 5 does not define UNICODE for CMake only qmake automatically define
|
||||
# UNICODE
|
||||
target_compile_definitions(QOwnNotes PRIVATE UNICODE _UNICODE)
|
||||
endif()
|
||||
|
||||
if(MSVC)
|
||||
target_compile_definitions(QOwnNotes PRIVATE
|
||||
NOMINMAX
|
||||
)
|
||||
target_compile_definitions(QOwnNotes PRIVATE NOMINMAX)
|
||||
endif()
|
||||
|
||||
add_compile_definitions(QAPPLICATION_CLASS=QApplication)
|
||||
|
||||
## Installation
|
||||
# Installation
|
||||
|
||||
install(TARGETS QOwnNotes DESTINATION bin)
|
||||
install(DIRECTORY images/icons DESTINATION share/icons/hicolor)
|
||||
|
|
|
@ -1,15 +1,13 @@
|
|||
cmake_minimum_required(VERSION 3.5)
|
||||
project(Botan)
|
||||
|
||||
option(BUILD_WITH_SYSTEM_BOTAN "Build using system installed Botan 2 crypto library" OFF)
|
||||
option(BUILD_WITH_SYSTEM_BOTAN
|
||||
"Build using system installed Botan 2 crypto library" OFF)
|
||||
|
||||
add_library(botan STATIC "")
|
||||
add_library(Botan::Botan ALIAS botan)
|
||||
|
||||
target_sources(botan PRIVATE
|
||||
botanwrapper.h
|
||||
botanwrapper.cpp
|
||||
)
|
||||
target_sources(botan PRIVATE botanwrapper.h botanwrapper.cpp)
|
||||
|
||||
find_package(Qt${QT_VERSION_MAJOR} REQUIRED COMPONENTS Core)
|
||||
|
||||
|
@ -27,38 +25,25 @@ if(BUILD_WITH_SYSTEM_BOTAN)
|
|||
|
||||
target_compile_definitions(botan PUBLIC USE_SYSTEM_BOTAN)
|
||||
|
||||
# Instead of put next lines into else() block
|
||||
# it is better to just return
|
||||
# Instead of put next lines into else() block it is better to just return
|
||||
return()
|
||||
endif()
|
||||
|
||||
|
||||
target_sources(botan PRIVATE
|
||||
botan.h
|
||||
botan.cpp
|
||||
botan_internal.h
|
||||
)
|
||||
|
||||
target_sources(botan PRIVATE botan.h botan.cpp botan_internal.h)
|
||||
|
||||
# add some Botan defines for Linux
|
||||
if(UNIX)
|
||||
# Append some definitions as PRIVATE only
|
||||
# if they used only in cpp and botan_internal header
|
||||
target_compile_definitions(botan PRIVATE
|
||||
BOTAN_HAS_ENTROPY_SRC_DEV_RANDOM
|
||||
)
|
||||
# Append some definitions as PRIVATE only if they used only in cpp and
|
||||
# botan_internal header
|
||||
target_compile_definitions(botan PRIVATE BOTAN_HAS_ENTROPY_SRC_DEV_RANDOM)
|
||||
endif()
|
||||
if(CMAKE_SYSTEM_NAME MATCHES "Linux")
|
||||
target_compile_definitions(botan PRIVATE
|
||||
BOTAN_TARGET_OS_HAS_CLOCK_GETTIME
|
||||
BOTAN_TARGET_OS_HAS_POSIX_MLOCK
|
||||
BOTAN_TARGET_OS_HAS_POSIX1
|
||||
)
|
||||
target_compile_definitions(
|
||||
botan PRIVATE BOTAN_TARGET_OS_HAS_CLOCK_GETTIME
|
||||
BOTAN_TARGET_OS_HAS_POSIX_MLOCK BOTAN_TARGET_OS_HAS_POSIX1)
|
||||
endif()
|
||||
if(APPLE)
|
||||
target_compile_definitions(botan PRIVATE
|
||||
BOTAN_TARGET_OS_HAS_POSIX1
|
||||
)
|
||||
target_compile_definitions(botan PRIVATE BOTAN_TARGET_OS_HAS_POSIX1)
|
||||
endif()
|
||||
|
||||
if(CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
|
||||
|
@ -69,69 +54,44 @@ elseif (CMAKE_CXX_COMPILER_ID STREQUAL "Intel")
|
|||
target_compile_definitions(botan PRIVATE BOTAN_BUILD_COMPILER_IS_INTEL)
|
||||
endif()
|
||||
|
||||
|
||||
if(CMAKE_SYSTEM_PROCESSOR MATCHES "(i386|i686|x86_64|AMD64)")
|
||||
if(CMAKE_SIZEOF_VOID_P EQUAL 4)
|
||||
target_compile_definitions(botan PUBLIC
|
||||
BOTAN_TARGET_CPU_IS_X86_FAMILY
|
||||
BOTAN_TARGET_ARCH_IS_X86_32
|
||||
)
|
||||
target_compile_definitions(botan PUBLIC BOTAN_TARGET_CPU_IS_X86_FAMILY
|
||||
BOTAN_TARGET_ARCH_IS_X86_32)
|
||||
elseif(CMAKE_SIZEOF_VOID_P EQUAL 8)
|
||||
target_compile_definitions(botan PUBLIC
|
||||
BOTAN_TARGET_CPU_IS_X86_FAMILY
|
||||
BOTAN_TARGET_ARCH_IS_X86_64
|
||||
BOTAN_TARGET_CPU_HAS_NATIVE_64BIT
|
||||
)
|
||||
target_compile_definitions(
|
||||
botan PUBLIC BOTAN_TARGET_CPU_IS_X86_FAMILY BOTAN_TARGET_ARCH_IS_X86_64
|
||||
BOTAN_TARGET_CPU_HAS_NATIVE_64BIT)
|
||||
endif()
|
||||
endif()
|
||||
|
||||
if(WIN32)
|
||||
target_compile_definitions(botan PRIVATE
|
||||
BOTAN_TARGET_OS_IS_WINDOWS
|
||||
BOTAN_TARGET_OS_HAS_WIN32
|
||||
BOTAN_HAS_ENTROPY_SRC_WIN32
|
||||
)
|
||||
target_compile_definitions(
|
||||
botan PRIVATE BOTAN_TARGET_OS_IS_WINDOWS BOTAN_TARGET_OS_HAS_WIN32
|
||||
BOTAN_HAS_ENTROPY_SRC_WIN32)
|
||||
if(MSVC)
|
||||
# TODO Find analog for:
|
||||
# QMAKE_CXXFLAGS_EXCEPTIONS_ON = -EHs
|
||||
target_compile_options(botan PUBLIC
|
||||
"-EHs" "-wd4251" "-wd4290" "-wd4250"
|
||||
)
|
||||
target_compile_definitions(botan PRIVATE
|
||||
_SCL_SECURE_NO_WARNINGS
|
||||
_CRT_SECURE_NO_WARNINGS
|
||||
)
|
||||
target_compile_definitions(botan PUBLIC
|
||||
BOTAN_BUILD_COMPILER_IS_MSVC
|
||||
)
|
||||
# TODO Find analog for: QMAKE_CXXFLAGS_EXCEPTIONS_ON = -EHs
|
||||
target_compile_options(botan PUBLIC "-EHs" "-wd4251" "-wd4290" "-wd4250")
|
||||
target_compile_definitions(botan PRIVATE _SCL_SECURE_NO_WARNINGS
|
||||
_CRT_SECURE_NO_WARNINGS)
|
||||
target_compile_definitions(botan PUBLIC BOTAN_BUILD_COMPILER_IS_MSVC)
|
||||
if(NOT (MSVC_VERSION LESS 1900))
|
||||
# For included library binary ABI does not matter
|
||||
# so disable warning
|
||||
target_compile_definitions(botan PRIVATE
|
||||
_ENABLE_EXTENDED_ALIGNED_STORAGE
|
||||
)
|
||||
# For included library binary ABI does not matter so disable warning
|
||||
target_compile_definitions(botan PRIVATE _ENABLE_EXTENDED_ALIGNED_STORAGE)
|
||||
endif()
|
||||
else()
|
||||
target_compile_options(botan PRIVATE
|
||||
"-fpermissive" "-finline-functions" "-Wno-long-long"
|
||||
)
|
||||
target_compile_options(botan PRIVATE "-fpermissive" "-finline-functions"
|
||||
"-Wno-long-long")
|
||||
endif()
|
||||
endif()
|
||||
|
||||
if(UNIX AND CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
|
||||
set_target_properties(botan PROPERTIES
|
||||
POSITION_INDEPENDENT_CODE ON
|
||||
)
|
||||
target_compile_options(botan PRIVATE
|
||||
"-fpermissive" "-finline-functions" "-Wno-long-long"
|
||||
)
|
||||
set_target_properties(botan PROPERTIES POSITION_INDEPENDENT_CODE ON)
|
||||
target_compile_options(botan PRIVATE "-fpermissive" "-finline-functions"
|
||||
"-Wno-long-long")
|
||||
endif()
|
||||
|
||||
if(CMAKE_SYSTEM_NAME MATCHES "(Linux|FreeBSD)")
|
||||
target_link_libraries(botan PRIVATE
|
||||
rt
|
||||
)
|
||||
target_compile_definitions(botan PRIVATE
|
||||
BOTAN_TARGET_OS_HAS_GETAUXVAL
|
||||
)
|
||||
target_link_libraries(botan PRIVATE rt)
|
||||
target_compile_definitions(botan PRIVATE BOTAN_TARGET_OS_HAS_GETAUXVAL)
|
||||
endif()
|
||||
|
|
File diff suppressed because it is too large
Load diff
File diff suppressed because it is too large
Load diff
File diff suppressed because it is too large
Load diff
|
@ -3,16 +3,16 @@
|
|||
#include <QDebug>
|
||||
|
||||
#ifdef USE_SYSTEM_BOTAN
|
||||
#include <botan/pipe.h>
|
||||
#include <botan/cipher_mode.h>
|
||||
#include <botan/base64.h>
|
||||
#include <botan/cipher_mode.h>
|
||||
#include <botan/filters.h>
|
||||
#include <botan/pbkdf2.h>
|
||||
#include <botan/kdf.h>
|
||||
#include <botan/hmac.h>
|
||||
#include <botan/kdf.h>
|
||||
#include <botan/pbkdf2.h>
|
||||
#include <botan/pipe.h>
|
||||
#include <botan/secmem.h>
|
||||
#include <botan/sha160.h>
|
||||
#include <botan/types.h>
|
||||
#include <botan/secmem.h>
|
||||
#else
|
||||
#include "botan.h"
|
||||
#endif
|
||||
|
@ -54,11 +54,10 @@ QString BotanWrapper::Encrypt(const QString &Data) {
|
|||
mSalt.data();
|
||||
|
||||
// Create the master key
|
||||
Botan::SecureVector<Botan::byte> mMaster = pbkdf2.derive_key(
|
||||
48,
|
||||
mPassword.toStdString(),
|
||||
&mSalt[0], mSalt.size(),
|
||||
PBKDF2_ITERATIONS).bits_of();
|
||||
Botan::SecureVector<Botan::byte> mMaster =
|
||||
pbkdf2
|
||||
.derive_key(48, mPassword.toStdString(), &mSalt[0], mSalt.size(), PBKDF2_ITERATIONS)
|
||||
.bits_of();
|
||||
Botan::SymmetricKey mKey = kdf->derive_key(32, mMaster, "salt1");
|
||||
Botan::InitializationVector mIV = kdf->derive_key(16, mMaster, "salt2");
|
||||
|
||||
|
@ -83,11 +82,10 @@ QString BotanWrapper::Decrypt(const QString &Data) {
|
|||
Botan::KDF *kdf = Botan::get_kdf("KDF2(SHA-1)");
|
||||
|
||||
// Create the master key
|
||||
Botan::SecureVector<Botan::byte> mMaster = pbkdf2.derive_key(
|
||||
48,
|
||||
mPassword.toStdString(),
|
||||
&mSalt[0], mSalt.size(),
|
||||
PBKDF2_ITERATIONS).bits_of();
|
||||
Botan::SecureVector<Botan::byte> mMaster =
|
||||
pbkdf2
|
||||
.derive_key(48, mPassword.toStdString(), &mSalt[0], mSalt.size(), PBKDF2_ITERATIONS)
|
||||
.bits_of();
|
||||
Botan::SymmetricKey mKey = kdf->derive_key(32, mMaster, "salt1");
|
||||
Botan::InitializationVector mIV = kdf->derive_key(16, mMaster, "salt2");
|
||||
|
||||
|
@ -96,8 +94,7 @@ QString BotanWrapper::Decrypt(const QString &Data) {
|
|||
pipe.process_msg(Data.toStdString());
|
||||
QString Value = QString::fromStdString(pipe.read_all_as_string(0));
|
||||
return Value;
|
||||
}
|
||||
catch (Botan::Exception &e) {
|
||||
} catch (Botan::Exception &e) {
|
||||
qWarning() << "[Botan Error] " << e.what();
|
||||
return QString();
|
||||
}
|
||||
|
@ -111,8 +108,7 @@ void BotanWrapper::setPassword(const QString &Password) {
|
|||
void BotanWrapper::setSalt(const QString &Salt) {
|
||||
QByteArray cBytes = Salt.toLatin1();
|
||||
|
||||
if (cBytes.size() > 48)
|
||||
cBytes.resize(48);
|
||||
if (cBytes.size() > 48) cBytes.resize(48);
|
||||
|
||||
mSalt.fill(0);
|
||||
std::copy(cBytes.cbegin(), cBytes.cend(), mSalt.begin());
|
||||
|
|
|
@ -4,8 +4,7 @@
|
|||
#include <QString>
|
||||
#include <QVector>
|
||||
|
||||
class BotanWrapper
|
||||
{
|
||||
class BotanWrapper {
|
||||
public:
|
||||
BotanWrapper();
|
||||
|
||||
|
|
|
@ -1,19 +1,12 @@
|
|||
cmake_minimum_required(VERSION 3.5)
|
||||
project(DiffMatchPatchLib)
|
||||
|
||||
add_library(diff_match_patch STATIC
|
||||
diff_match_patch.h
|
||||
diff_match_patch.cpp
|
||||
)
|
||||
add_library(diff_match_patch STATIC diff_match_patch.h diff_match_patch.cpp)
|
||||
|
||||
add_library(Google::DiffMatchPatch ALIAS diff_match_patch)
|
||||
|
||||
find_package(Qt${QT_VERSION_MAJOR} REQUIRED COMPONENTS Core)
|
||||
|
||||
target_include_directories(diff_match_patch PUBLIC
|
||||
${CMAKE_CURRENT_LIST_DIR}
|
||||
)
|
||||
target_include_directories(diff_match_patch PUBLIC ${CMAKE_CURRENT_LIST_DIR})
|
||||
|
||||
target_link_libraries(diff_match_patch PUBLIC
|
||||
Qt${QT_VERSION_MAJOR}::Core
|
||||
)
|
||||
target_link_libraries(diff_match_patch PUBLIC Qt${QT_VERSION_MAJOR}::Core)
|
||||
|
|
|
@ -5,20 +5,13 @@ project(fakevim VERSION 0.0.1)
|
|||
set(bin fakevim)
|
||||
|
||||
# Public headers
|
||||
set(${bin}_public_headers
|
||||
fakevim/fakevimactions.h
|
||||
fakevim/fakevimhandler.h
|
||||
)
|
||||
set(${bin}_public_headers fakevim/fakevimactions.h fakevim/fakevimhandler.h)
|
||||
|
||||
# Source files common for all platforms
|
||||
set(${bin}_sources
|
||||
fakevim/fakevimactions.cpp
|
||||
fakevim/fakevimhandler.cpp
|
||||
fakevim/utils/hostosinfo.cpp
|
||||
fakevim/utils/osspecificaspects.h
|
||||
fakevim/utils/qtcassert.cpp
|
||||
${${bin}_public_headers}
|
||||
)
|
||||
fakevim/fakevimactions.cpp fakevim/fakevimhandler.cpp
|
||||
fakevim/utils/hostosinfo.cpp fakevim/utils/osspecificaspects.h
|
||||
fakevim/utils/qtcassert.cpp ${${bin}_public_headers})
|
||||
|
||||
# Required pkg-config packages
|
||||
set(${bin}_pkg_config_requires)
|
||||
|
@ -37,11 +30,9 @@ else()
|
|||
endif()
|
||||
target_sources(${bin} PRIVATE ${${bin}_mocced})
|
||||
|
||||
target_compile_definitions(${bin} PRIVATE
|
||||
QT_NO_CAST_TO_ASCII
|
||||
QT_RESTRICTED_CAST_FROM_ASCII
|
||||
QTCREATOR_UTILS_STATIC_LIB
|
||||
)
|
||||
target_compile_definitions(
|
||||
${bin} PRIVATE QT_NO_CAST_TO_ASCII QT_RESTRICTED_CAST_FROM_ASCII
|
||||
QTCREATOR_UTILS_STATIC_LIB)
|
||||
|
||||
option(BUILD_TESTS "Build tests")
|
||||
if(BUILD_TESTS)
|
||||
|
@ -49,18 +40,13 @@ if (BUILD_TESTS)
|
|||
|
||||
find_package(Qt5Test REQUIRED)
|
||||
|
||||
add_executable(fakevim_test
|
||||
tests/fakevim_test.cpp
|
||||
tests/fakevimplugin.h
|
||||
example/editor.cpp
|
||||
)
|
||||
add_executable(fakevim_test tests/fakevim_test.cpp tests/fakevimplugin.h
|
||||
example/editor.cpp)
|
||||
set_property(TARGET fakevim_test PROPERTY AUTOMOC ON)
|
||||
target_link_libraries(fakevim_test fakevim Qt5::Widgets Qt5::Test)
|
||||
|
||||
target_include_directories(fakevim_test PRIVATE
|
||||
${CMAKE_SOURCE_DIR}/fakevim
|
||||
${CMAKE_SOURCE_DIR}
|
||||
)
|
||||
target_include_directories(fakevim_test PRIVATE ${CMAKE_SOURCE_DIR}/fakevim
|
||||
${CMAKE_SOURCE_DIR})
|
||||
|
||||
add_test(fakevim_test fakevim_test)
|
||||
enable_testing()
|
||||
|
|
|
@ -1,11 +1,15 @@
|
|||
set(INSTALL_LIB_DIR "lib${LIB_SUFFIX}" CACHE PATH
|
||||
"Installation directory for libraries")
|
||||
set(INSTALL_BIN_DIR "bin" CACHE PATH
|
||||
"Installation directory for executables")
|
||||
set(INSTALL_INCLUDE_DIR "include/${bin}" CACHE PATH
|
||||
"Installation directory for header files")
|
||||
set(INSTALL_CMAKE_DIR "lib${LIB_SUFFIX}/cmake/${bin}" CACHE PATH
|
||||
"Installation directory for CMake files")
|
||||
set(INSTALL_LIB_DIR
|
||||
"lib${LIB_SUFFIX}"
|
||||
CACHE PATH "Installation directory for libraries")
|
||||
set(INSTALL_BIN_DIR
|
||||
"bin"
|
||||
CACHE PATH "Installation directory for executables")
|
||||
set(INSTALL_INCLUDE_DIR
|
||||
"include/${bin}"
|
||||
CACHE PATH "Installation directory for header files")
|
||||
set(INSTALL_CMAKE_DIR
|
||||
"lib${LIB_SUFFIX}/cmake/${bin}"
|
||||
CACHE PATH "Installation directory for CMake files")
|
||||
|
||||
# Shared or static library
|
||||
option(CREATE_STATIC_LIBRARY "Create static library" OFF)
|
||||
|
@ -16,33 +20,31 @@ else()
|
|||
endif()
|
||||
|
||||
add_library(${bin} ${libtype} ${${bin}_sources})
|
||||
set_target_properties(${bin} PROPERTIES
|
||||
VERSION ${PROJECT_VERSION}
|
||||
SOVERSION ${PROJECT_VERSION_MAJOR}
|
||||
)
|
||||
set_target_properties(${bin} PROPERTIES VERSION ${PROJECT_VERSION}
|
||||
SOVERSION ${PROJECT_VERSION_MAJOR})
|
||||
|
||||
# Headers
|
||||
set(export_header "${CMAKE_CURRENT_BINARY_DIR}/private/${bin}_export.h")
|
||||
set_target_properties(${bin} PROPERTIES
|
||||
PUBLIC_HEADER "${${bin}_public_headers}"
|
||||
set_target_properties(${bin} PROPERTIES PUBLIC_HEADER "${${bin}_public_headers}"
|
||||
PRIVATE_HEADER "${export_header}")
|
||||
|
||||
target_include_directories(${bin}
|
||||
target_include_directories(
|
||||
${bin}
|
||||
PRIVATE $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/${bin}>
|
||||
INTERFACE $<INSTALL_INTERFACE:include/${bin}>
|
||||
)
|
||||
INTERFACE $<INSTALL_INTERFACE:include/${bin}>)
|
||||
|
||||
install(
|
||||
TARGETS ${bin} EXPORT ${bin}Targets
|
||||
TARGETS ${bin}
|
||||
EXPORT ${bin}Targets
|
||||
RUNTIME DESTINATION "${INSTALL_BIN_DIR}" COMPONENT bin
|
||||
LIBRARY DESTINATION "${INSTALL_LIB_DIR}" COMPONENT lib
|
||||
ARCHIVE DESTINATION "${INSTALL_LIB_DIR}" COMPONENT lib
|
||||
PUBLIC_HEADER DESTINATION "${INSTALL_INCLUDE_DIR}" COMPONENT dev
|
||||
PRIVATE_HEADER DESTINATION "${INSTALL_INCLUDE_DIR}/private" COMPONENT dev
|
||||
)
|
||||
PRIVATE_HEADER DESTINATION "${INSTALL_INCLUDE_DIR}/private" COMPONENT dev)
|
||||
|
||||
# Generate and install CMake files for the library so `find_package(<Library>)` can be used with CMake.
|
||||
# For more info: https://cmake.org/cmake/help/v3.0/manual/cmake-packages.7.html#creating-packages
|
||||
# Generate and install CMake files for the library so `find_package(<Library>)`
|
||||
# can be used with CMake. For more info:
|
||||
# https://cmake.org/cmake/help/v3.0/manual/cmake-packages.7.html#creating-packages
|
||||
include(GenerateExportHeader)
|
||||
generate_export_header(${bin} EXPORT_FILE_NAME "${export_header}")
|
||||
|
||||
|
@ -50,34 +52,20 @@ include(CMakePackageConfigHelpers)
|
|||
write_basic_package_version_file(
|
||||
"${CMAKE_CURRENT_BINARY_DIR}/${bin}ConfigVersion.cmake"
|
||||
VERSION ${PROJECT_VERSION}
|
||||
COMPATIBILITY AnyNewerVersion
|
||||
)
|
||||
COMPATIBILITY AnyNewerVersion)
|
||||
|
||||
export(
|
||||
EXPORT ${bin}Targets
|
||||
FILE "${CMAKE_CURRENT_BINARY_DIR}/${bin}Targets.cmake"
|
||||
)
|
||||
configure_file(
|
||||
cmake/${bin}Config.cmake
|
||||
"${CMAKE_CURRENT_BINARY_DIR}/${bin}Config.cmake"
|
||||
COPYONLY
|
||||
)
|
||||
export(EXPORT ${bin}Targets
|
||||
FILE "${CMAKE_CURRENT_BINARY_DIR}/${bin}Targets.cmake")
|
||||
configure_file(cmake/${bin}Config.cmake
|
||||
"${CMAKE_CURRENT_BINARY_DIR}/${bin}Config.cmake" COPYONLY)
|
||||
|
||||
install(
|
||||
EXPORT ${bin}Targets
|
||||
FILE
|
||||
${bin}Targets.cmake
|
||||
DESTINATION
|
||||
"${INSTALL_CMAKE_DIR}"
|
||||
COMPONENT
|
||||
dev
|
||||
)
|
||||
FILE ${bin}Targets.cmake
|
||||
DESTINATION "${INSTALL_CMAKE_DIR}"
|
||||
COMPONENT dev)
|
||||
install(
|
||||
FILES
|
||||
"${CMAKE_CURRENT_BINARY_DIR}/${bin}Config.cmake"
|
||||
FILES "${CMAKE_CURRENT_BINARY_DIR}/${bin}Config.cmake"
|
||||
"${CMAKE_CURRENT_BINARY_DIR}/${bin}ConfigVersion.cmake"
|
||||
DESTINATION
|
||||
"${INSTALL_CMAKE_DIR}"
|
||||
COMPONENT
|
||||
dev
|
||||
)
|
||||
DESTINATION "${INSTALL_CMAKE_DIR}"
|
||||
COMPONENT dev)
|
||||
|
|
|
@ -4,19 +4,14 @@ set(PKG_CONFIG_INCLUDEDIR "\${prefix}/include/${bin}")
|
|||
set(PKG_CONFIG_LIBS "-L\${libdir} -l${bin}")
|
||||
set(PKG_CONFIG_CFLAGS "-I\${includedir}")
|
||||
|
||||
#configure_file(
|
||||
# "${CMAKE_CURRENT_SOURCE_DIR}/pkg-config.pc.in"
|
||||
# "${CMAKE_CURRENT_BINARY_DIR}/${bin}.pc"
|
||||
# )
|
||||
# configure_file( "${CMAKE_CURRENT_SOURCE_DIR}/pkg-config.pc.in"
|
||||
# "${CMAKE_CURRENT_BINARY_DIR}/${bin}.pc" )
|
||||
|
||||
set(INSTALL_PKG_CONFIG_DIR "${CMAKE_INSTALL_PREFIX}/lib/pkgconfig"
|
||||
set(INSTALL_PKG_CONFIG_DIR
|
||||
"${CMAKE_INSTALL_PREFIX}/lib/pkgconfig"
|
||||
CACHE PATH "Installation directory for pkg-config files")
|
||||
|
||||
install(
|
||||
FILES
|
||||
"${CMAKE_CURRENT_BINARY_DIR}/${bin}.pc"
|
||||
DESTINATION
|
||||
"${INSTALL_PKG_CONFIG_DIR}"
|
||||
COMPONENT
|
||||
dev
|
||||
)
|
||||
FILES "${CMAKE_CURRENT_BINARY_DIR}/${bin}.pc"
|
||||
DESTINATION "${INSTALL_PKG_CONFIG_DIR}"
|
||||
COMPONENT dev)
|
||||
|
|
|
@ -3,4 +3,5 @@ find_package(Qt${QT_VERSION_MAJOR}Widgets REQUIRED)
|
|||
# include_directories(${Qt5Gui_PRIVATE_INCLUDE_DIRS})
|
||||
target_link_libraries(${bin} Qt${QT_VERSION_MAJOR}::Widgets)
|
||||
|
||||
set(${bin}_pkg_config_requires ${${bin}_pkg_config_requires} Qt${QT_VERSION_MAJOR}::Widgets)
|
||||
set(${bin}_pkg_config_requires ${${bin}_pkg_config_requires}
|
||||
Qt${QT_VERSION_MAJOR}::Widgets)
|
||||
|
|
|
@ -24,6 +24,7 @@
|
|||
****************************************************************************/
|
||||
|
||||
#include "fakevimactions.h"
|
||||
|
||||
#include "fakevimhandler.h"
|
||||
|
||||
// Please do not add any direct dependencies to other Qt Creator code here.
|
||||
|
@ -41,45 +42,28 @@ namespace FakeVim {
|
|||
namespace Internal {
|
||||
|
||||
#ifdef FAKEVIM_STANDALONE
|
||||
FvBaseAspect::FvBaseAspect()
|
||||
{
|
||||
}
|
||||
FvBaseAspect::FvBaseAspect() {}
|
||||
|
||||
void FvBaseAspect::setValue(const QVariant &value)
|
||||
{
|
||||
m_value = value;
|
||||
}
|
||||
void FvBaseAspect::setValue(const QVariant &value) { m_value = value; }
|
||||
|
||||
QVariant FvBaseAspect::value() const
|
||||
{
|
||||
return m_value;
|
||||
}
|
||||
QVariant FvBaseAspect::value() const { return m_value; }
|
||||
|
||||
void FvBaseAspect::setDefaultValue(const QVariant &value)
|
||||
{
|
||||
void FvBaseAspect::setDefaultValue(const QVariant &value) {
|
||||
m_defaultValue = value;
|
||||
m_value = value;
|
||||
}
|
||||
|
||||
QVariant FvBaseAspect::defaultValue() const
|
||||
{
|
||||
return m_defaultValue;
|
||||
}
|
||||
QVariant FvBaseAspect::defaultValue() const { return m_defaultValue; }
|
||||
|
||||
void FvBaseAspect::setSettingsKey(const QString &group, const QString &key)
|
||||
{
|
||||
void FvBaseAspect::setSettingsKey(const QString &group, const QString &key) {
|
||||
m_settingsGroup = group;
|
||||
m_settingsKey = key;
|
||||
}
|
||||
|
||||
QString FvBaseAspect::settingsKey() const
|
||||
{
|
||||
return m_settingsKey;
|
||||
}
|
||||
QString FvBaseAspect::settingsKey() const { return m_settingsKey; }
|
||||
#endif
|
||||
|
||||
FakeVimSettings::FakeVimSettings()
|
||||
{
|
||||
FakeVimSettings::FakeVimSettings() {
|
||||
#ifndef FAKEVIM_STANDALONE
|
||||
setup(&useFakeVim, false, "UseFakeVim", {}, tr("Use FakeVim"));
|
||||
#endif
|
||||
|
@ -106,13 +90,12 @@ FakeVimSettings::FakeVimSettings()
|
|||
setup(&wrapScan, true, "WrapScan", "ws", tr("Use wrapscan"));
|
||||
setup(&tildeOp, false, "TildeOp", "top", tr("Use tildeop"));
|
||||
setup(&showCmd, true, "ShowCmd", "sc", tr("Show partial command"));
|
||||
setup(&relativeNumber, false, "RelativeNumber", "rnu", tr("Show line numbers relative to cursor"));
|
||||
setup(&relativeNumber, false, "RelativeNumber", "rnu",
|
||||
tr("Show line numbers relative to cursor"));
|
||||
setup(&blinkingCursor, false, "BlinkingCursor", "bc", tr("Blinking cursor"));
|
||||
setup(&scrollOff, 0, "ScrollOff", "so", tr("Scroll offset:"));
|
||||
setup(&backspace, "indent,eol,start",
|
||||
"Backspace", "bs", tr("Backspace:"));
|
||||
setup(&isKeyword, "@,48-57,_,192-255,a-z,A-Z",
|
||||
"IsKeyword", "isk", tr("Keyword characters:"));
|
||||
setup(&backspace, "indent,eol,start", "Backspace", "bs", tr("Backspace:"));
|
||||
setup(&isKeyword, "@,48-57,_,192-255,a-z,A-Z", "IsKeyword", "isk", tr("Keyword characters:"));
|
||||
setup(&clipboard, {}, "Clipboard", "cb", tr(""));
|
||||
setup(&formatOptions, {}, "formatoptions", "fo", tr(""));
|
||||
|
||||
|
@ -126,14 +109,17 @@ FakeVimSettings::FakeVimSettings()
|
|||
// Some polish
|
||||
useFakeVim.setDisplayName(tr("Use Vim-style Editing"));
|
||||
|
||||
relativeNumber.setToolTip(tr("Displays line numbers relative to the line containing "
|
||||
relativeNumber.setToolTip(
|
||||
tr("Displays line numbers relative to the line containing "
|
||||
"text cursor."));
|
||||
|
||||
passControlKey.setToolTip(tr("Does not interpret key sequences like Ctrl-S in FakeVim "
|
||||
passControlKey.setToolTip(
|
||||
tr("Does not interpret key sequences like Ctrl-S in FakeVim "
|
||||
"but handles them as regular shortcuts. This gives easier access to core functionality "
|
||||
"at the price of losing some features of FakeVim."));
|
||||
|
||||
passKeys.setToolTip(tr("Does not interpret some key presses in insert mode so that "
|
||||
passKeys.setToolTip(
|
||||
tr("Does not interpret some key presses in insert mode so that "
|
||||
"code can be properly completed and expanded."));
|
||||
|
||||
tabStop.setToolTip(tr("Vim tabstop option."));
|
||||
|
@ -142,10 +128,11 @@ FakeVimSettings::FakeVimSettings()
|
|||
backspace.setDisplayStyle(FvStringAspect::LineEditDisplay);
|
||||
isKeyword.setDisplayStyle(FvStringAspect::LineEditDisplay);
|
||||
|
||||
const QString vimrcDefault = QLatin1String(HostOsInfo::isAnyUnixHost()
|
||||
? "$HOME/.vimrc" : "%USERPROFILE%\\_vimrc");
|
||||
const QString vimrcDefault =
|
||||
QLatin1String(HostOsInfo::isAnyUnixHost() ? "$HOME/.vimrc" : "%USERPROFILE%\\_vimrc");
|
||||
vimRcPath.setExpectedKind(PathChooser::File);
|
||||
vimRcPath.setToolTip(tr("Keep empty to use the default path, i.e. "
|
||||
vimRcPath.setToolTip(
|
||||
tr("Keep empty to use the default path, i.e. "
|
||||
"%USERPROFILE%\\_vimrc on Windows, ~/.vimrc otherwise."));
|
||||
vimRcPath.setPlaceHolderText(tr("Default: %1").arg(vimrcDefault));
|
||||
vimRcPath.setDisplayStyle(FvStringAspect::PathChooserDisplay);
|
||||
|
@ -154,31 +141,22 @@ FakeVimSettings::FakeVimSettings()
|
|||
|
||||
FakeVimSettings::~FakeVimSettings() = default;
|
||||
|
||||
FvBaseAspect *FakeVimSettings::item(const QString &name)
|
||||
{
|
||||
FvBaseAspect *FakeVimSettings::item(const QString &name) {
|
||||
return m_nameToAspect.value(name, nullptr);
|
||||
}
|
||||
|
||||
QString FakeVimSettings::trySetValue(const QString &name, const QString &value)
|
||||
{
|
||||
QString FakeVimSettings::trySetValue(const QString &name, const QString &value) {
|
||||
FvBaseAspect *aspect = m_nameToAspect.value(name, nullptr);
|
||||
if (!aspect)
|
||||
return tr("Unknown option: %1").arg(name);
|
||||
if (!aspect) return tr("Unknown option: %1").arg(name);
|
||||
if (aspect == &tabStop || aspect == &shiftWidth) {
|
||||
if (value.toInt() <= 0)
|
||||
return tr("Argument must be positive: %1=%2")
|
||||
.arg(name).arg(value);
|
||||
if (value.toInt() <= 0) return tr("Argument must be positive: %1=%2").arg(name).arg(value);
|
||||
}
|
||||
aspect->setValue(value);
|
||||
return QString();
|
||||
}
|
||||
|
||||
void FakeVimSettings::setup(FvBaseAspect *aspect,
|
||||
const QVariant &value,
|
||||
const QString &settingsKey,
|
||||
const QString &shortName,
|
||||
const QString &labelText)
|
||||
{
|
||||
void FakeVimSettings::setup(FvBaseAspect *aspect, const QVariant &value, const QString &settingsKey,
|
||||
const QString &shortName, const QString &labelText) {
|
||||
aspect->setSettingsKey("FakeVim", settingsKey);
|
||||
aspect->setDefaultValue(value);
|
||||
#ifndef FAKEVIM_STANDALONE
|
||||
|
@ -197,12 +175,10 @@ void FakeVimSettings::setup(FvBaseAspect *aspect,
|
|||
m_nameToAspect[longName] = aspect;
|
||||
m_aspectToName[aspect] = longName;
|
||||
}
|
||||
if (!shortName.isEmpty())
|
||||
m_nameToAspect[shortName] = aspect;
|
||||
if (!shortName.isEmpty()) m_nameToAspect[shortName] = aspect;
|
||||
}
|
||||
|
||||
FakeVimSettings *fakeVimSettings()
|
||||
{
|
||||
FakeVimSettings *fakeVimSettings() {
|
||||
static FakeVimSettings s;
|
||||
return &s;
|
||||
}
|
||||
|
|
|
@ -43,8 +43,7 @@ namespace FakeVim {
|
|||
namespace Internal {
|
||||
|
||||
#ifdef FAKEVIM_STANDALONE
|
||||
class FvBaseAspect
|
||||
{
|
||||
class FvBaseAspect {
|
||||
public:
|
||||
FvBaseAspect();
|
||||
virtual ~FvBaseAspect() {}
|
||||
|
@ -66,26 +65,22 @@ private:
|
|||
QString m_settingsKey;
|
||||
};
|
||||
|
||||
class FvBoolAspect : public FvBaseAspect
|
||||
{
|
||||
class FvBoolAspect : public FvBaseAspect {
|
||||
public:
|
||||
bool value() const { return FvBaseAspect::value().toBool(); }
|
||||
};
|
||||
|
||||
class FvIntegerAspect : public FvBaseAspect
|
||||
{
|
||||
class FvIntegerAspect : public FvBaseAspect {
|
||||
public:
|
||||
qint64 value() const { return FvBaseAspect::value().toLongLong(); }
|
||||
};
|
||||
|
||||
class FvStringAspect : public FvBaseAspect
|
||||
{
|
||||
class FvStringAspect : public FvBaseAspect {
|
||||
public:
|
||||
QString value() const { return FvBaseAspect::value().toString(); }
|
||||
};
|
||||
|
||||
class FvAspectContainer : public FvBaseAspect
|
||||
{
|
||||
class FvAspectContainer : public FvBaseAspect {
|
||||
public:
|
||||
};
|
||||
|
||||
|
@ -99,8 +94,7 @@ using FvStringAspect = Utils::StringAspect;
|
|||
|
||||
#endif
|
||||
|
||||
class FakeVimSettings final : public FvAspectContainer
|
||||
{
|
||||
class FakeVimSettings final : public FvAspectContainer {
|
||||
Q_DECLARE_TR_FUNCTIONS(FakeVim)
|
||||
|
||||
public:
|
||||
|
@ -161,10 +155,8 @@ public:
|
|||
FvBoolAspect blinkingCursor;
|
||||
|
||||
private:
|
||||
void setup(FvBaseAspect *aspect, const QVariant &value,
|
||||
const QString &settingsKey,
|
||||
const QString &shortName,
|
||||
const QString &label);
|
||||
void setup(FvBaseAspect *aspect, const QVariant &value, const QString &settingsKey,
|
||||
const QString &shortName, const QString &label);
|
||||
|
||||
QHash<QString, FvBaseAspect *> m_nameToAspect;
|
||||
QHash<FvBaseAspect *, QString> m_aspectToName;
|
||||
|
|
File diff suppressed because it is too large
Load diff
|
@ -33,15 +33,13 @@
|
|||
|
||||
#include <QObject>
|
||||
#include <QTextEdit>
|
||||
|
||||
#include <functional>
|
||||
#include <vector>
|
||||
|
||||
namespace FakeVim {
|
||||
namespace Internal {
|
||||
|
||||
enum RangeMode
|
||||
{
|
||||
enum RangeMode {
|
||||
// Reordering first three enum items here will break
|
||||
// compatibility with clipboard format stored by Vim.
|
||||
RangeCharMode, // v
|
||||
|
@ -51,8 +49,7 @@ enum RangeMode
|
|||
RangeBlockAndTailMode // Ctrl-v for D and X
|
||||
};
|
||||
|
||||
struct Range
|
||||
{
|
||||
struct Range {
|
||||
Range() = default;
|
||||
Range(int b, int e, RangeMode m = RangeCharMode);
|
||||
QString toString() const;
|
||||
|
@ -63,11 +60,9 @@ struct Range
|
|||
RangeMode rangemode = RangeCharMode;
|
||||
};
|
||||
|
||||
struct ExCommand
|
||||
{
|
||||
struct ExCommand {
|
||||
ExCommand() = default;
|
||||
ExCommand(const QString &cmd, const QString &args = QString(),
|
||||
const Range &range = Range());
|
||||
ExCommand(const QString &cmd, const QString &args = QString(), const Range &range = Range());
|
||||
|
||||
bool matches(const QString &min, const QString &full) const;
|
||||
|
||||
|
@ -79,8 +74,7 @@ struct ExCommand
|
|||
};
|
||||
|
||||
// message levels sorted by severity
|
||||
enum MessageLevel
|
||||
{
|
||||
enum MessageLevel {
|
||||
MessageMode, // show current mode (format "-- %1 --")
|
||||
MessageCommand, // show last Ex command or search
|
||||
MessageInfo, // result of a command
|
||||
|
@ -90,26 +84,22 @@ enum MessageLevel
|
|||
};
|
||||
|
||||
template <typename Type>
|
||||
class Signal
|
||||
{
|
||||
class Signal {
|
||||
public:
|
||||
using Callable = std::function<Type>;
|
||||
|
||||
void connect(const Callable &callable) { m_callables.push_back(callable); }
|
||||
|
||||
template <typename... Args>
|
||||
void operator()(Args ...args) const
|
||||
{
|
||||
for (const Callable &callable : m_callables)
|
||||
callable(args...);
|
||||
void operator()(Args... args) const {
|
||||
for (const Callable &callable : m_callables) callable(args...);
|
||||
}
|
||||
|
||||
private:
|
||||
std::vector<Callable> m_callables;
|
||||
};
|
||||
|
||||
class FakeVimHandler : public QObject
|
||||
{
|
||||
class FakeVimHandler : public QObject {
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
|
@ -159,7 +149,8 @@ public:
|
|||
|
||||
bool eventFilter(QObject *ob, QEvent *ev) override;
|
||||
|
||||
Signal<void(const QString &msg, int cursorPos, int anchorPos, int messageLevel)> commandBufferChanged;
|
||||
Signal<void(const QString &msg, int cursorPos, int anchorPos, int messageLevel)>
|
||||
commandBufferChanged;
|
||||
Signal<void(const QString &msg)> statusDataChanged;
|
||||
Signal<void(const QString &msg)> extraInformationChanged;
|
||||
Signal<void(const QList<QTextEdit::ExtraSelection> &selection)> selectionChanged;
|
||||
|
|
|
@ -29,8 +29,7 @@
|
|||
|
||||
namespace FakeVim {
|
||||
|
||||
struct Tr
|
||||
{
|
||||
struct Tr {
|
||||
Q_DECLARE_TR_FUNCTIONS(FakeVim)
|
||||
};
|
||||
|
||||
|
|
|
@ -32,13 +32,11 @@ using namespace Utils;
|
|||
Qt::CaseSensitivity HostOsInfo::m_overrideFileNameCaseSensitivity = Qt::CaseSensitive;
|
||||
bool HostOsInfo::m_useOverrideFileNameCaseSensitivity = false;
|
||||
|
||||
void HostOsInfo::setOverrideFileNameCaseSensitivity(Qt::CaseSensitivity sensitivity)
|
||||
{
|
||||
void HostOsInfo::setOverrideFileNameCaseSensitivity(Qt::CaseSensitivity sensitivity) {
|
||||
m_useOverrideFileNameCaseSensitivity = true;
|
||||
m_overrideFileNameCaseSensitivity = sensitivity;
|
||||
}
|
||||
|
||||
void HostOsInfo::unsetOverrideFileNameCaseSensitivity()
|
||||
{
|
||||
void HostOsInfo::unsetOverrideFileNameCaseSensitivity() {
|
||||
m_useOverrideFileNameCaseSensitivity = false;
|
||||
}
|
||||
|
|
|
@ -25,10 +25,10 @@
|
|||
|
||||
#pragma once
|
||||
|
||||
#include "osspecificaspects.h"
|
||||
|
||||
#include <QString>
|
||||
|
||||
#include "osspecificaspects.h"
|
||||
|
||||
#ifdef Q_OS_WIN
|
||||
#define QTC_HOST_EXE_SUFFIX QTC_WIN_EXE_SUFFIX
|
||||
#else
|
||||
|
@ -37,11 +37,9 @@
|
|||
|
||||
namespace Utils {
|
||||
|
||||
class HostOsInfo
|
||||
{
|
||||
class HostOsInfo {
|
||||
public:
|
||||
static constexpr OsType hostOs()
|
||||
{
|
||||
static constexpr OsType hostOs() {
|
||||
#if defined(Q_OS_WIN)
|
||||
return OsTypeWindows;
|
||||
#elif defined(Q_OS_LINUX)
|
||||
|
@ -58,8 +56,7 @@ public:
|
|||
static constexpr bool isWindowsHost() { return hostOs() == OsTypeWindows; }
|
||||
static constexpr bool isLinuxHost() { return hostOs() == OsTypeLinux; }
|
||||
static constexpr bool isMacHost() { return hostOs() == OsTypeMac; }
|
||||
static constexpr bool isAnyUnixHost()
|
||||
{
|
||||
static constexpr bool isAnyUnixHost() {
|
||||
#ifdef Q_OS_UNIX
|
||||
return true;
|
||||
#else
|
||||
|
@ -67,28 +64,22 @@ public:
|
|||
#endif
|
||||
}
|
||||
|
||||
static QString withExecutableSuffix(const QString &executable)
|
||||
{
|
||||
static QString withExecutableSuffix(const QString &executable) {
|
||||
return OsSpecificAspects::withExecutableSuffix(hostOs(), executable);
|
||||
}
|
||||
|
||||
static void setOverrideFileNameCaseSensitivity(Qt::CaseSensitivity sensitivity);
|
||||
static void unsetOverrideFileNameCaseSensitivity();
|
||||
|
||||
static Qt::CaseSensitivity fileNameCaseSensitivity()
|
||||
{
|
||||
static Qt::CaseSensitivity fileNameCaseSensitivity() {
|
||||
return m_useOverrideFileNameCaseSensitivity
|
||||
? m_overrideFileNameCaseSensitivity
|
||||
: OsSpecificAspects::fileNameCaseSensitivity(hostOs());
|
||||
}
|
||||
|
||||
static QChar pathListSeparator()
|
||||
{
|
||||
return OsSpecificAspects::pathListSeparator(hostOs());
|
||||
}
|
||||
static QChar pathListSeparator() { return OsSpecificAspects::pathListSeparator(hostOs()); }
|
||||
|
||||
static Qt::KeyboardModifier controlModifier()
|
||||
{
|
||||
static Qt::KeyboardModifier controlModifier() {
|
||||
return OsSpecificAspects::controlModifier(hostOs());
|
||||
}
|
||||
|
||||
|
|
|
@ -83,17 +83,15 @@ using std::experimental::in_place;
|
|||
|
||||
// TODO: make_optional is a copy, since there is no sensible way to import functions in C++
|
||||
template <class T>
|
||||
constexpr optional<typename std::decay<T>::type> make_optional(T&& v)
|
||||
{
|
||||
constexpr optional<typename std::decay<T>::type> make_optional(T&& v) {
|
||||
return optional<typename std::decay<T>::type>(std::experimental::constexpr_forward<T>(v));
|
||||
}
|
||||
|
||||
template <class X>
|
||||
constexpr optional<X&> make_optional(std::reference_wrapper<X> v)
|
||||
{
|
||||
constexpr optional<X&> make_optional(std::reference_wrapper<X> v) {
|
||||
return optional<X&>(v.get());
|
||||
}
|
||||
|
||||
} // Utils
|
||||
} // namespace Utils
|
||||
|
||||
// #endif
|
||||
|
|
|
@ -36,31 +36,25 @@ enum OsType { OsTypeWindows, OsTypeLinux, OsTypeMac, OsTypeOtherUnix, OsTypeOthe
|
|||
|
||||
namespace OsSpecificAspects {
|
||||
|
||||
inline QString withExecutableSuffix(OsType osType, const QString &executable)
|
||||
{
|
||||
inline QString withExecutableSuffix(OsType osType, const QString &executable) {
|
||||
QString finalName = executable;
|
||||
if (osType == OsTypeWindows)
|
||||
finalName += QLatin1String(QTC_WIN_EXE_SUFFIX);
|
||||
if (osType == OsTypeWindows) finalName += QLatin1String(QTC_WIN_EXE_SUFFIX);
|
||||
return finalName;
|
||||
}
|
||||
|
||||
inline Qt::CaseSensitivity fileNameCaseSensitivity(OsType osType)
|
||||
{
|
||||
inline Qt::CaseSensitivity fileNameCaseSensitivity(OsType osType) {
|
||||
return osType == OsTypeWindows || osType == OsTypeMac ? Qt::CaseInsensitive : Qt::CaseSensitive;
|
||||
}
|
||||
|
||||
inline Qt::CaseSensitivity envVarCaseSensitivity(OsType osType)
|
||||
{
|
||||
inline Qt::CaseSensitivity envVarCaseSensitivity(OsType osType) {
|
||||
return fileNameCaseSensitivity(osType);
|
||||
}
|
||||
|
||||
inline QChar pathListSeparator(OsType osType)
|
||||
{
|
||||
inline QChar pathListSeparator(OsType osType) {
|
||||
return QLatin1Char(osType == OsTypeWindows ? ';' : ':');
|
||||
}
|
||||
|
||||
inline Qt::KeyboardModifier controlModifier(OsType osType)
|
||||
{
|
||||
inline Qt::KeyboardModifier controlModifier(OsType osType) {
|
||||
return osType == OsTypeMac ? Qt::MetaModifier : Qt::ControlModifier;
|
||||
}
|
||||
|
||||
|
|
|
@ -29,8 +29,7 @@
|
|||
|
||||
namespace Utils {
|
||||
|
||||
void writeAssertLocation(const char *msg)
|
||||
{
|
||||
void writeAssertLocation(const char *msg) {
|
||||
static bool goBoom = qEnvironmentVariableIsSet("QTC_FATAL_ASSERTS");
|
||||
if (goBoom)
|
||||
qFatal("SOFT ASSERT made fatal: %s", msg);
|
||||
|
|
|
@ -25,16 +25,32 @@
|
|||
|
||||
#pragma once
|
||||
|
||||
namespace Utils { void writeAssertLocation(const char *msg); }
|
||||
namespace Utils {
|
||||
void writeAssertLocation(const char *msg);
|
||||
}
|
||||
|
||||
#define QTC_ASSERT_STRINGIFY_HELPER(x) #x
|
||||
#define QTC_ASSERT_STRINGIFY(x) QTC_ASSERT_STRINGIFY_HELPER(x)
|
||||
#define QTC_ASSERT_STRING(cond) ::Utils::writeAssertLocation(\
|
||||
"\"" cond"\" in file " __FILE__ ", line " QTC_ASSERT_STRINGIFY(__LINE__))
|
||||
#define QTC_ASSERT_STRING(cond) \
|
||||
::Utils::writeAssertLocation("\"" cond "\" in file " __FILE__ \
|
||||
", line " QTC_ASSERT_STRINGIFY(__LINE__))
|
||||
|
||||
// The 'do {...} while (0)' idiom is not used for the main block here to be
|
||||
// able to use 'break' and 'continue' as 'actions'.
|
||||
|
||||
#define QTC_ASSERT(cond, action) if (Q_LIKELY(cond)) {} else { QTC_ASSERT_STRING(#cond); action; } do {} while (0)
|
||||
#define QTC_CHECK(cond) if (Q_LIKELY(cond)) {} else { QTC_ASSERT_STRING(#cond); } do {} while (0)
|
||||
#define QTC_ASSERT(cond, action) \
|
||||
if (Q_LIKELY(cond)) { \
|
||||
} else { \
|
||||
QTC_ASSERT_STRING(#cond); \
|
||||
action; \
|
||||
} \
|
||||
do { \
|
||||
} while (0)
|
||||
#define QTC_CHECK(cond) \
|
||||
if (Q_LIKELY(cond)) { \
|
||||
} else { \
|
||||
QTC_ASSERT_STRING(#cond); \
|
||||
} \
|
||||
do { \
|
||||
} while (0)
|
||||
#define QTC_GUARD(cond) ((Q_LIKELY(cond)) ? true : (QTC_ASSERT_STRING(#cond), false))
|
||||
|
|
|
@ -4,12 +4,12 @@
|
|||
class SomeClass {
|
||||
public:
|
||||
SomeClass(const std::string &var) : m_var(var) {}
|
||||
|
||||
private:
|
||||
std::string m_var;
|
||||
};
|
||||
|
||||
int main(int argc, const char *argv[])
|
||||
{
|
||||
int main(int argc, const char *argv[]) {
|
||||
using namespace std;
|
||||
cout << "TESTING...";
|
||||
cout << "1";
|
||||
|
|
|
@ -21,10 +21,7 @@ using String = QString;
|
|||
* Custom toLower function which is much faster than
|
||||
* c.toLower() directly
|
||||
*/
|
||||
static inline QChar toLower(QChar c)
|
||||
{
|
||||
return c.isLower() ? c : c.toLower();
|
||||
}
|
||||
static inline QChar toLower(QChar c) { return c.isLower() ? c : c.toLower(); }
|
||||
|
||||
// internal
|
||||
// clang-format off
|
||||
|
@ -191,8 +188,8 @@ static bool match_recursive(String::const_iterator pattern,
|
|||
}
|
||||
// clang-format on
|
||||
|
||||
static bool match_internal(StringType pattern, StringType str, int &outScore, unsigned char *matches)
|
||||
{
|
||||
static bool match_internal(StringType pattern, StringType str, int &outScore,
|
||||
unsigned char *matches) {
|
||||
if (pattern.isEmpty()) {
|
||||
return true;
|
||||
}
|
||||
|
@ -204,14 +201,13 @@ static bool match_internal(StringType pattern, StringType str, int &outScore, un
|
|||
const auto patternEnd = pattern.cend();
|
||||
const auto strEnd = str.cend();
|
||||
|
||||
return match_recursive(patternIt, strIt, outScore, strIt, strEnd, patternEnd,
|
||||
nullptr, matches, 0, recursionCount);
|
||||
return match_recursive(patternIt, strIt, outScore, strIt, strEnd, patternEnd, nullptr, matches,
|
||||
0, recursionCount);
|
||||
}
|
||||
|
||||
/**************************************************************/
|
||||
|
||||
bool KFuzzyMatcher::matchSimple(StringType pattern, StringType str)
|
||||
{
|
||||
bool KFuzzyMatcher::matchSimple(StringType pattern, StringType str) {
|
||||
auto patternIt = pattern.cbegin();
|
||||
for (auto strIt = str.cbegin(); strIt != str.cend() && patternIt != pattern.cend(); ++strIt) {
|
||||
if (strIt->toLower() == patternIt->toLower()) {
|
||||
|
@ -221,8 +217,7 @@ bool KFuzzyMatcher::matchSimple(StringType pattern, StringType str)
|
|||
return patternIt == pattern.cend();
|
||||
}
|
||||
|
||||
KFuzzyMatcher::Result KFuzzyMatcher::match(StringType pattern, StringType str)
|
||||
{
|
||||
KFuzzyMatcher::Result KFuzzyMatcher::match(StringType pattern, StringType str) {
|
||||
uint8_t matches[256];
|
||||
int score = 0;
|
||||
const bool matched = match_internal(pattern, str, score, matches);
|
||||
|
@ -232,12 +227,9 @@ KFuzzyMatcher::Result KFuzzyMatcher::match(StringType pattern, StringType str)
|
|||
return result;
|
||||
}
|
||||
|
||||
|
||||
QString KFuzzyMatcher::toFuzzyMatchedDisplayString(const QString &pattern,
|
||||
const QString &str,
|
||||
QString KFuzzyMatcher::toFuzzyMatchedDisplayString(const QString &pattern, const QString &str,
|
||||
const QString &htmlTag,
|
||||
const QString &htmlTagClose)
|
||||
{
|
||||
const QString &htmlTagClose) {
|
||||
if (pattern.isEmpty()) {
|
||||
return str;
|
||||
}
|
||||
|
@ -263,5 +255,4 @@ QString KFuzzyMatcher::toFuzzyMatchedDisplayString(const QString &pattern,
|
|||
offset += htmlTagClose.size();
|
||||
}
|
||||
return string;
|
||||
|
||||
}
|
||||
|
|
|
@ -74,14 +74,12 @@ using StringType = const QString&;
|
|||
* @short Namespace for fuzzy matching of strings
|
||||
* @author Waqar Ahmed <waqar.17a@gmail.com>
|
||||
*/
|
||||
namespace KFuzzyMatcher
|
||||
{
|
||||
namespace KFuzzyMatcher {
|
||||
|
||||
/**
|
||||
* @brief The result of a fuzzy match
|
||||
*/
|
||||
struct Result
|
||||
{
|
||||
struct Result {
|
||||
/** Score of this match. This can be negative. if matched is @c false
|
||||
then the score will be zero.
|
||||
*/
|
||||
|
@ -126,9 +124,7 @@ bool matchSimple(StringType pattern, StringType str);
|
|||
*/
|
||||
Result match(StringType pattern, StringType str);
|
||||
|
||||
QString toFuzzyMatchedDisplayString(const QString& pattern,
|
||||
const QString& str,
|
||||
const QString& htmlTag,
|
||||
const QString& htmlTagClose);
|
||||
QString toFuzzyMatchedDisplayString(const QString& pattern, const QString& str,
|
||||
const QString& htmlTag, const QString& htmlTagClose);
|
||||
|
||||
} // namespace KFuzzyMatcher
|
||||
|
|
|
@ -1,5 +1,8 @@
|
|||
cmake_minimum_required(VERSION 3.7)
|
||||
project(qlitehtml VERSION 1.0 LANGUAGES CXX)
|
||||
project(
|
||||
qlitehtml
|
||||
VERSION 1.0
|
||||
LANGUAGES CXX)
|
||||
|
||||
set(CMAKE_AUTOMOC ON)
|
||||
set(CMAKE_AUTORCC ON)
|
||||
|
@ -23,8 +26,14 @@ else()
|
|||
set(QLITEHTML_HEADER_PATH include/qlitehtml)
|
||||
endif()
|
||||
|
||||
find_package(QT 5.11 NAMES Qt6 Qt5 COMPONENTS Widgets REQUIRED)
|
||||
find_package(Qt${QT_VERSION_MAJOR} COMPONENTS Widgets REQUIRED)
|
||||
find_package(
|
||||
QT 5.11 NAMES Qt6 Qt5
|
||||
COMPONENTS Widgets
|
||||
REQUIRED)
|
||||
find_package(
|
||||
Qt${QT_VERSION_MAJOR}
|
||||
COMPONENTS Widgets
|
||||
REQUIRED)
|
||||
set(Qt Qt${QT_VERSION_MAJOR})
|
||||
|
||||
set(QLITEHTML_BUILD_TESTS OFF)
|
||||
|
|
|
@ -4,13 +4,13 @@ project(litehtml LANGUAGES C CXX)
|
|||
include(CTest)
|
||||
enable_testing()
|
||||
|
||||
# Soname
|
||||
# MAJOR is incremented when symbols are removed or changed in an incompatible way
|
||||
# MINOR is incremented when new symbols are added
|
||||
# Soname MAJOR is incremented when symbols are removed or changed in an
|
||||
# incompatible way MINOR is incremented when new symbols are added
|
||||
set(PROJECT_MAJOR 0)
|
||||
set(PROJECT_MINOR 0)
|
||||
|
||||
option(EXTERNAL_GUMBO "Link against external gumbo instead of shipping a bundled copy" OFF)
|
||||
option(EXTERNAL_GUMBO
|
||||
"Link against external gumbo instead of shipping a bundled copy" OFF)
|
||||
if(WIN32)
|
||||
option(EXTERNAL_XXD "Use external xxd" OFF)
|
||||
else()
|
||||
|
@ -64,8 +64,7 @@ set(SOURCE_LITEHTML
|
|||
src/utf8_strings.cpp
|
||||
src/web_color.cpp
|
||||
src/num_cvt.cpp
|
||||
src/strtod.cpp
|
||||
)
|
||||
src/strtod.cpp)
|
||||
|
||||
set(HEADER_LITEHTML
|
||||
include/litehtml.h
|
||||
|
@ -116,8 +115,7 @@ set(HEADER_LITEHTML
|
|||
include/litehtml/url_path.h
|
||||
include/litehtml/utf8_strings.h
|
||||
include/litehtml/web_color.h
|
||||
include/litehtml/num_cvt.h
|
||||
)
|
||||
include/litehtml/num_cvt.h)
|
||||
|
||||
set(TEST_LITEHTML
|
||||
containers/test/container_test.cpp
|
||||
|
@ -130,24 +128,26 @@ set(TEST_LITEHTML
|
|||
test/tstring_view_test.cpp
|
||||
test/url_test.cpp
|
||||
test/url_path_test.cpp
|
||||
test/webColorTest.cpp
|
||||
)
|
||||
test/webColorTest.cpp)
|
||||
|
||||
set(PROJECT_LIB_VERSION ${PROJECT_MAJOR}.${PROJECT_MINOR}.0)
|
||||
set(PROJECT_SO_VERSION ${PROJECT_MAJOR})
|
||||
|
||||
add_library(${PROJECT_NAME} ${SOURCE_LITEHTML})
|
||||
set_target_properties(${PROJECT_NAME} PROPERTIES VERSION ${PROJECT_LIB_VERSION} SOVERSION ${PROJECT_SO_VERSION})
|
||||
set_target_properties(
|
||||
${PROJECT_NAME} PROPERTIES VERSION ${PROJECT_LIB_VERSION}
|
||||
SOVERSION ${PROJECT_SO_VERSION})
|
||||
|
||||
set_target_properties(${PROJECT_NAME} PROPERTIES
|
||||
CXX_STANDARD 11
|
||||
set_target_properties(
|
||||
${PROJECT_NAME}
|
||||
PROPERTIES CXX_STANDARD 11
|
||||
C_STANDARD 99
|
||||
PUBLIC_HEADER "${HEADER_LITEHTML}"
|
||||
)
|
||||
PUBLIC_HEADER "${HEADER_LITEHTML}")
|
||||
|
||||
# Export litehtml includes.
|
||||
target_include_directories(${PROJECT_NAME} PUBLIC
|
||||
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/src>
|
||||
target_include_directories(
|
||||
${PROJECT_NAME}
|
||||
PUBLIC $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/src>
|
||||
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
|
||||
$<INSTALL_INTERFACE:include/${PROJECT_NAME}>)
|
||||
target_include_directories(${PROJECT_NAME} PRIVATE include/${PROJECT_NAME})
|
||||
|
@ -161,15 +161,19 @@ endif()
|
|||
target_link_libraries(${PROJECT_NAME} PUBLIC gumbo)
|
||||
|
||||
# install and export
|
||||
install(TARGETS ${PROJECT_NAME}
|
||||
install(
|
||||
TARGETS ${PROJECT_NAME}
|
||||
EXPORT litehtmlTargets
|
||||
RUNTIME DESTINATION bin COMPONENT libraries
|
||||
ARCHIVE DESTINATION lib${LIB_SUFFIX} COMPONENT libraries
|
||||
LIBRARY DESTINATION lib${LIB_SUFFIX} COMPONENT libraries
|
||||
PUBLIC_HEADER DESTINATION include/litehtml
|
||||
)
|
||||
install(FILES cmake/litehtmlConfig.cmake DESTINATION lib${LIB_SUFFIX}/cmake/litehtml)
|
||||
install(EXPORT litehtmlTargets FILE litehtmlTargets.cmake DESTINATION lib${LIB_SUFFIX}/cmake/litehtml)
|
||||
PUBLIC_HEADER DESTINATION include/litehtml)
|
||||
install(FILES cmake/litehtmlConfig.cmake
|
||||
DESTINATION lib${LIB_SUFFIX}/cmake/litehtml)
|
||||
install(
|
||||
EXPORT litehtmlTargets
|
||||
FILE litehtmlTargets.cmake
|
||||
DESTINATION lib${LIB_SUFFIX}/cmake/litehtml)
|
||||
|
||||
# Binary Master.css
|
||||
if(NOT EXTERNAL_XXD)
|
||||
|
@ -180,14 +184,20 @@ else()
|
|||
endif()
|
||||
if(WIN32)
|
||||
file(TO_NATIVE_PATH ${XXD_COMMAND} XXD_COMMAND)
|
||||
file(TO_NATIVE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/include/master.css MASTER_FILE)
|
||||
add_custom_command(OUTPUT ${CMAKE_CURRENT_SOURCE_DIR}/src/master.css.inc
|
||||
COMMAND type ${MASTER_FILE} | "${XXD_COMMAND}" -i > ${CMAKE_CURRENT_SOURCE_DIR}/src/master.css.inc)
|
||||
file(TO_NATIVE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/include/master.css
|
||||
MASTER_FILE)
|
||||
add_custom_command(
|
||||
OUTPUT ${CMAKE_CURRENT_SOURCE_DIR}/src/master.css.inc
|
||||
COMMAND type ${MASTER_FILE} | "${XXD_COMMAND}" -i >
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/src/master.css.inc)
|
||||
else()
|
||||
add_custom_command(OUTPUT ${CMAKE_CURRENT_SOURCE_DIR}/src/master.css.inc
|
||||
COMMAND cat ${CMAKE_CURRENT_SOURCE_DIR}/include/master.css | xxd -i > ${CMAKE_CURRENT_SOURCE_DIR}/src/master.css.inc)
|
||||
add_custom_command(
|
||||
OUTPUT ${CMAKE_CURRENT_SOURCE_DIR}/src/master.css.inc
|
||||
COMMAND cat ${CMAKE_CURRENT_SOURCE_DIR}/include/master.css | xxd -i >
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/src/master.css.inc)
|
||||
endif()
|
||||
set_source_files_properties(${CMAKE_CURRENT_SOURCE_DIR}/src/master.css.inc PROPERTIES GENERATED TRUE)
|
||||
set_source_files_properties(${CMAKE_CURRENT_SOURCE_DIR}/src/master.css.inc
|
||||
PROPERTIES GENERATED TRUE)
|
||||
|
||||
# Tests
|
||||
|
||||
|
@ -198,8 +208,11 @@ if (BUILD_TESTING)
|
|||
googletest
|
||||
URL https://github.com/google/googletest/archive/609281088cfefc76f9d0ce82e1ff6c30cc3591e5.zip
|
||||
)
|
||||
# For Windows: Prevent overriding the parent project's compiler/linker settings
|
||||
set(gtest_force_shared_crt ON CACHE BOOL "" FORCE)
|
||||
# For Windows: Prevent overriding the parent project's compiler/linker
|
||||
# settings
|
||||
set(gtest_force_shared_crt
|
||||
ON
|
||||
CACHE BOOL "" FORCE)
|
||||
FetchContent_GetProperties(googletest)
|
||||
if(NOT googletest_POPULATED)
|
||||
FetchContent_Populate(googletest)
|
||||
|
@ -210,47 +223,32 @@ if (BUILD_TESTING)
|
|||
|
||||
set(TEST_NAME ${PROJECT_NAME}_tests)
|
||||
|
||||
add_executable(
|
||||
${TEST_NAME}
|
||||
${TEST_LITEHTML}
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/src/master.css.inc
|
||||
)
|
||||
add_executable(${TEST_NAME} ${TEST_LITEHTML}
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/src/master.css.inc)
|
||||
|
||||
set_target_properties(${TEST_NAME} PROPERTIES
|
||||
CXX_STANDARD 11
|
||||
set_target_properties(
|
||||
${TEST_NAME}
|
||||
PROPERTIES CXX_STANDARD 11
|
||||
C_STANDARD 99
|
||||
PUBLIC_HEADER "${HEADER_LITEHTML}"
|
||||
)
|
||||
PUBLIC_HEADER "${HEADER_LITEHTML}")
|
||||
|
||||
target_include_directories(
|
||||
${TEST_NAME}
|
||||
PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/containers
|
||||
)
|
||||
target_include_directories(${TEST_NAME}
|
||||
PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/containers)
|
||||
|
||||
target_link_libraries(
|
||||
${TEST_NAME}
|
||||
${PROJECT_NAME}
|
||||
gtest_main
|
||||
)
|
||||
target_link_libraries(${TEST_NAME} ${PROJECT_NAME} gtest_main)
|
||||
|
||||
include(GoogleTest)
|
||||
gtest_discover_tests(${TEST_NAME})
|
||||
endif()
|
||||
|
||||
# set(TEST_NAME ${PROJECT_NAME}_tests)
|
||||
# add_executable(${TEST_NAME} ${TEST_LITEHTML} ${CMAKE_CURRENT_SOURCE_DIR}/src/master.css.inc)
|
||||
# set_target_properties(${TEST_NAME} PROPERTIES
|
||||
# CXX_STANDARD 11
|
||||
# C_STANDARD 99
|
||||
# PUBLIC_HEADER "${HEADER_LITEHTML}"
|
||||
# )
|
||||
# target_include_directories(${TEST_NAME} PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/containers)
|
||||
# target_link_libraries(${TEST_NAME} PRIVATE ${PROJECT_NAME})
|
||||
# # tests
|
||||
# add_test(NAME contextTest COMMAND ${TEST_NAME} 1)
|
||||
# add_test(NAME cssTest COMMAND ${TEST_NAME} 2)
|
||||
# add_test(NAME documentTest COMMAND ${TEST_NAME} 3)
|
||||
# add_test(NAME layoutGlobalTest COMMAND ${TEST_NAME} 4)
|
||||
# add_test(NAME mediaQueryTest COMMAND ${TEST_NAME} 5)
|
||||
# add_test(NAME webColorTest COMMAND ${TEST_NAME} 6)
|
||||
# endif()
|
||||
# set(TEST_NAME ${PROJECT_NAME}_tests) add_executable(${TEST_NAME}
|
||||
# ${TEST_LITEHTML} ${CMAKE_CURRENT_SOURCE_DIR}/src/master.css.inc)
|
||||
# set_target_properties(${TEST_NAME} PROPERTIES CXX_STANDARD 11 C_STANDARD 99
|
||||
# PUBLIC_HEADER "${HEADER_LITEHTML}" ) target_include_directories(${TEST_NAME}
|
||||
# PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/containers)
|
||||
# target_link_libraries(${TEST_NAME} PRIVATE ${PROJECT_NAME}) # tests
|
||||
# add_test(NAME contextTest COMMAND ${TEST_NAME} 1) add_test(NAME cssTest
|
||||
# COMMAND ${TEST_NAME} 2) add_test(NAME documentTest COMMAND ${TEST_NAME} 3)
|
||||
# add_test(NAME layoutGlobalTest COMMAND ${TEST_NAME} 4) add_test(NAME
|
||||
# mediaQueryTest COMMAND ${TEST_NAME} 5) add_test(NAME webColorTest COMMAND
|
||||
# ${TEST_NAME} 6) endif()
|
||||
|
|
File diff suppressed because it is too large
Load diff
|
@ -1,17 +1,17 @@
|
|||
#pragma once
|
||||
#include <windows.h>
|
||||
#include <mlang.h>
|
||||
#include <stdlib.h>
|
||||
#include <cairo-win32.h>
|
||||
#include <cairo.h>
|
||||
#include <dib.h>
|
||||
#include <litehtml.h>
|
||||
#include <malloc.h>
|
||||
#include <memory.h>
|
||||
#include <tchar.h>
|
||||
#include <mlang.h>
|
||||
#include <vector>
|
||||
#include <cairo.h>
|
||||
#include <cairo-win32.h>
|
||||
#include <litehtml.h>
|
||||
#include <dib.h>
|
||||
#include <stdlib.h>
|
||||
#include <tchar.h>
|
||||
#include <txdib.h>
|
||||
#include <windows.h>
|
||||
|
||||
#include <vector>
|
||||
|
||||
#ifdef LITEHTML_UTF8
|
||||
#define t_make_url make_url_utf8
|
||||
|
@ -19,33 +19,28 @@
|
|||
#define t_make_url make_url
|
||||
#endif
|
||||
|
||||
struct cairo_clip_box
|
||||
{
|
||||
struct cairo_clip_box {
|
||||
typedef std::vector<cairo_clip_box> vector;
|
||||
litehtml::position box;
|
||||
litehtml::border_radiuses radius;
|
||||
|
||||
cairo_clip_box(const litehtml::position& vBox, litehtml::border_radiuses vRad)
|
||||
{
|
||||
cairo_clip_box(const litehtml::position& vBox, litehtml::border_radiuses vRad) {
|
||||
box = vBox;
|
||||
radius = vRad;
|
||||
}
|
||||
|
||||
cairo_clip_box(const cairo_clip_box& val)
|
||||
{
|
||||
cairo_clip_box(const cairo_clip_box& val) {
|
||||
box = val.box;
|
||||
radius = val.radius;
|
||||
}
|
||||
cairo_clip_box& operator=(const cairo_clip_box& val)
|
||||
{
|
||||
cairo_clip_box& operator=(const cairo_clip_box& val) {
|
||||
box = val.box;
|
||||
radius = val.radius;
|
||||
return *this;
|
||||
}
|
||||
};
|
||||
|
||||
class cairo_container : public litehtml::document_container
|
||||
{
|
||||
class cairo_container : public litehtml::document_container {
|
||||
public:
|
||||
typedef std::shared_ptr<CTxDIB> image_ptr;
|
||||
typedef std::map<std::wstring, image_ptr> images_map;
|
||||
|
@ -57,6 +52,7 @@ protected:
|
|||
cairo_clip_box::vector m_clips;
|
||||
IMLangFontLink2* m_font_link;
|
||||
CRITICAL_SECTION m_img_sync;
|
||||
|
||||
public:
|
||||
cairo_container(void);
|
||||
virtual ~cairo_container(void);
|
||||
|
@ -85,7 +81,6 @@ public:
|
|||
virtual void link(const std::shared_ptr<litehtml::document>& doc, const litehtml::element::ptr& el) override;
|
||||
virtual litehtml::tstring resolve_color(const litehtml::tstring& color) const override;
|
||||
|
||||
|
||||
virtual void make_url(LPCWSTR url, LPCWSTR basepath, std::wstring& out) = 0;
|
||||
virtual image_ptr get_image(LPCWSTR url, bool redraw_on_ready) = 0;
|
||||
void clear_images();
|
||||
|
@ -99,6 +94,7 @@ protected:
|
|||
virtual void rounded_rectangle(cairo_t* cr, const litehtml::position& pos, const litehtml::border_radiuses& radius);
|
||||
|
||||
void set_color(cairo_t* cr, litehtml::web_color color) { cairo_set_source_rgba(cr, color.red / 255.0, color.green / 255.0, color.blue / 255.0, color.alpha / 255.0); }
|
||||
|
||||
private:
|
||||
simpledib::dib* get_dib(litehtml::uint_ptr hdc) { return (simpledib::dib*)hdc; }
|
||||
void apply_clip(cairo_t* cr);
|
||||
|
|
|
@ -1,46 +1,36 @@
|
|||
#include "cairo_font.h"
|
||||
|
||||
cairo_font::cairo_font(IMLangFontLink2* fl, HFONT hFont, int size )
|
||||
{
|
||||
cairo_font::cairo_font(IMLangFontLink2* fl, HFONT hFont, int size) {
|
||||
init();
|
||||
m_font_link = fl;
|
||||
if(m_font_link)
|
||||
{
|
||||
if (m_font_link) {
|
||||
m_font_link->AddRef();
|
||||
}
|
||||
m_size = size;
|
||||
set_font(hFont);
|
||||
}
|
||||
|
||||
cairo_font::cairo_font(IMLangFontLink2* fl, LPCWSTR facename, int size, int weight, BOOL italic, BOOL strikeout, BOOL underline )
|
||||
{
|
||||
cairo_font::cairo_font(IMLangFontLink2* fl, LPCWSTR facename, int size, int weight, BOOL italic, BOOL strikeout, BOOL underline) {
|
||||
init();
|
||||
m_size = size;
|
||||
m_font_link = fl;
|
||||
if(m_font_link)
|
||||
{
|
||||
if (m_font_link) {
|
||||
m_font_link->AddRef();
|
||||
}
|
||||
|
||||
LOGFONT lf;
|
||||
ZeroMemory(&lf, sizeof(lf));
|
||||
if(!lstrcmpi(facename, L"monospace"))
|
||||
{
|
||||
if (!lstrcmpi(facename, L"monospace")) {
|
||||
wcscpy_s(lf.lfFaceName, LF_FACESIZE, L"Courier New");
|
||||
} else if(!lstrcmpi(facename, L"serif"))
|
||||
{
|
||||
} else if (!lstrcmpi(facename, L"serif")) {
|
||||
wcscpy_s(lf.lfFaceName, LF_FACESIZE, L"Times New Roman");
|
||||
} else if(!lstrcmpi(facename, L"sans-serif"))
|
||||
{
|
||||
} else if (!lstrcmpi(facename, L"sans-serif")) {
|
||||
wcscpy_s(lf.lfFaceName, LF_FACESIZE, L"Arial");
|
||||
} else if(!lstrcmpi(facename, L"fantasy"))
|
||||
{
|
||||
} else if (!lstrcmpi(facename, L"fantasy")) {
|
||||
wcscpy_s(lf.lfFaceName, LF_FACESIZE, L"Impact");
|
||||
} else if(!lstrcmpi(facename, L"cursive"))
|
||||
{
|
||||
} else if (!lstrcmpi(facename, L"cursive")) {
|
||||
wcscpy_s(lf.lfFaceName, LF_FACESIZE, L"Comic Sans MS");
|
||||
} else
|
||||
{
|
||||
} else {
|
||||
wcscpy_s(lf.lfFaceName, LF_FACESIZE, facename);
|
||||
}
|
||||
|
||||
|
@ -58,56 +48,44 @@ cairo_font::cairo_font(IMLangFontLink2* fl, LPCWSTR facename, int size, int weig
|
|||
set_font(fnt);
|
||||
}
|
||||
|
||||
cairo_font::~cairo_font()
|
||||
{
|
||||
if(m_font_face)
|
||||
{
|
||||
cairo_font::~cairo_font() {
|
||||
if (m_font_face) {
|
||||
cairo_font_face_destroy(m_font_face);
|
||||
}
|
||||
for(size_t i = 0; i < m_linked_fonts.size(); i++)
|
||||
{
|
||||
if(m_linked_fonts[i]->hFont)
|
||||
{
|
||||
for (size_t i = 0; i < m_linked_fonts.size(); i++) {
|
||||
if (m_linked_fonts[i]->hFont) {
|
||||
m_font_link->ReleaseFont(m_linked_fonts[i]->hFont);
|
||||
}
|
||||
if(m_linked_fonts[i]->font_face)
|
||||
{
|
||||
if (m_linked_fonts[i]->font_face) {
|
||||
cairo_font_face_destroy(m_linked_fonts[i]->font_face);
|
||||
}
|
||||
}
|
||||
m_linked_fonts.clear();
|
||||
if(m_font_link)
|
||||
{
|
||||
if (m_font_link) {
|
||||
m_font_link->AddRef();
|
||||
}
|
||||
if(m_hFont)
|
||||
{
|
||||
if (m_hFont) {
|
||||
DeleteObject(m_hFont);
|
||||
}
|
||||
}
|
||||
|
||||
void cairo_font::show_text( cairo_t* cr, int x, int y, const litehtml::tchar_t* str )
|
||||
{
|
||||
void cairo_font::show_text(cairo_t* cr, int x, int y, const litehtml::tchar_t* str) {
|
||||
lock();
|
||||
text_chunk::vector chunks;
|
||||
split_text(str, chunks);
|
||||
cairo_set_font_size(cr, m_size);
|
||||
cairo_move_to(cr, x, y);
|
||||
for(size_t i = 0; i < chunks.size(); i++)
|
||||
{
|
||||
if(chunks[i]->font)
|
||||
{
|
||||
for (size_t i = 0; i < chunks.size(); i++) {
|
||||
if (chunks[i]->font) {
|
||||
cairo_set_font_face(cr, chunks[i]->font->font_face);
|
||||
} else
|
||||
{
|
||||
} else {
|
||||
cairo_set_font_face(cr, m_font_face);
|
||||
}
|
||||
cairo_show_text(cr, chunks[i]->text);
|
||||
}
|
||||
unlock();
|
||||
|
||||
if(m_bUnderline)
|
||||
{
|
||||
if (m_bUnderline) {
|
||||
int tw = text_width(cr, chunks);
|
||||
|
||||
lock();
|
||||
|
@ -117,8 +95,7 @@ void cairo_font::show_text( cairo_t* cr, int x, int y, const litehtml::tchar_t*
|
|||
cairo_stroke(cr);
|
||||
unlock();
|
||||
}
|
||||
if(m_bStrikeOut)
|
||||
{
|
||||
if (m_bStrikeOut) {
|
||||
int tw = text_width(cr, chunks);
|
||||
|
||||
cairo_font_metrics fm;
|
||||
|
@ -137,8 +114,7 @@ void cairo_font::show_text( cairo_t* cr, int x, int y, const litehtml::tchar_t*
|
|||
free_text_chunks(chunks);
|
||||
}
|
||||
|
||||
void cairo_font::split_text( const litehtml::tchar_t* src, text_chunk::vector& chunks )
|
||||
{
|
||||
void cairo_font::split_text(const litehtml::tchar_t* src, text_chunk::vector& chunks) {
|
||||
wchar_t* str;
|
||||
#ifdef LITEHTML_UTF8
|
||||
str = cairo_font::utf8_to_wchar(src);
|
||||
|
@ -152,20 +128,16 @@ void cairo_font::split_text( const litehtml::tchar_t* src, text_chunk::vector& c
|
|||
HDC hdc = GetDC(NULL);
|
||||
SelectObject(hdc, m_hFont);
|
||||
HRESULT hr = S_OK;
|
||||
while(cch > 0)
|
||||
{
|
||||
while (cch > 0) {
|
||||
DWORD dwActualCodePages;
|
||||
long cchActual;
|
||||
if(m_font_link)
|
||||
{
|
||||
if (m_font_link) {
|
||||
hr = m_font_link->GetStrCodePages(str, cch, m_font_code_pages, &dwActualCodePages, &cchActual);
|
||||
} else
|
||||
{
|
||||
} else {
|
||||
hr = S_FALSE;
|
||||
}
|
||||
|
||||
if(hr != S_OK)
|
||||
{
|
||||
if (hr != S_OK) {
|
||||
break;
|
||||
}
|
||||
|
||||
|
@ -177,29 +149,22 @@ void cairo_font::split_text( const litehtml::tchar_t* src, text_chunk::vector& c
|
|||
chk->text[sz] = 0;
|
||||
chk->font = NULL;
|
||||
|
||||
if(!(dwActualCodePages & m_font_code_pages))
|
||||
{
|
||||
for(linked_font::vector::iterator i = m_linked_fonts.begin(); i != m_linked_fonts.end(); i++)
|
||||
{
|
||||
if((*i)->code_pages == dwActualCodePages)
|
||||
{
|
||||
if (!(dwActualCodePages & m_font_code_pages)) {
|
||||
for (linked_font::vector::iterator i = m_linked_fonts.begin(); i != m_linked_fonts.end(); i++) {
|
||||
if ((*i)->code_pages == dwActualCodePages) {
|
||||
chk->font = (*i);
|
||||
break;
|
||||
}
|
||||
}
|
||||
if(!chk->font)
|
||||
{
|
||||
if (!chk->font) {
|
||||
linked_font* lkf = new linked_font;
|
||||
lkf->code_pages = dwActualCodePages;
|
||||
lkf->hFont = NULL;
|
||||
m_font_link->MapFont(hdc, dwActualCodePages, 0, &lkf->hFont);
|
||||
if (lkf->hFont)
|
||||
{
|
||||
if (lkf->hFont) {
|
||||
lkf->font_face = create_font_face(lkf->hFont);
|
||||
m_linked_fonts.push_back(lkf);
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
delete lkf;
|
||||
lkf = NULL;
|
||||
}
|
||||
|
@ -213,8 +178,7 @@ void cairo_font::split_text( const litehtml::tchar_t* src, text_chunk::vector& c
|
|||
str += cchActual;
|
||||
}
|
||||
|
||||
if(hr != S_OK)
|
||||
{
|
||||
if (hr != S_OK) {
|
||||
text_chunk* chk = new text_chunk;
|
||||
|
||||
int sz = WideCharToMultiByte(CP_UTF8, 0, str, -1, chk->text, 0, NULL, NULL) + 1;
|
||||
|
@ -232,24 +196,20 @@ void cairo_font::split_text( const litehtml::tchar_t* src, text_chunk::vector& c
|
|||
#endif
|
||||
}
|
||||
|
||||
void cairo_font::free_text_chunks( text_chunk::vector& chunks )
|
||||
{
|
||||
for(size_t i = 0; i < chunks.size(); i++)
|
||||
{
|
||||
void cairo_font::free_text_chunks(text_chunk::vector& chunks) {
|
||||
for (size_t i = 0; i < chunks.size(); i++) {
|
||||
delete chunks[i];
|
||||
}
|
||||
chunks.clear();
|
||||
}
|
||||
|
||||
cairo_font_face_t* cairo_font::create_font_face( HFONT fnt )
|
||||
{
|
||||
cairo_font_face_t* cairo_font::create_font_face(HFONT fnt) {
|
||||
LOGFONT lf;
|
||||
GetObject(fnt, sizeof(LOGFONT), &lf);
|
||||
return cairo_win32_font_face_create_for_logfontw(&lf);
|
||||
}
|
||||
|
||||
int cairo_font::text_width( cairo_t* cr, const litehtml::tchar_t* str )
|
||||
{
|
||||
int cairo_font::text_width(cairo_t* cr, const litehtml::tchar_t* str) {
|
||||
text_chunk::vector chunks;
|
||||
split_text(str, chunks);
|
||||
|
||||
|
@ -260,18 +220,14 @@ int cairo_font::text_width( cairo_t* cr, const litehtml::tchar_t* str )
|
|||
return (int)ret;
|
||||
}
|
||||
|
||||
int cairo_font::text_width( cairo_t* cr, text_chunk::vector& chunks )
|
||||
{
|
||||
int cairo_font::text_width(cairo_t* cr, text_chunk::vector& chunks) {
|
||||
lock();
|
||||
cairo_set_font_size(cr, m_size);
|
||||
double ret = 0;
|
||||
for(size_t i = 0; i < chunks.size(); i++)
|
||||
{
|
||||
if(chunks[i]->font)
|
||||
{
|
||||
for (size_t i = 0; i < chunks.size(); i++) {
|
||||
if (chunks[i]->font) {
|
||||
cairo_set_font_face(cr, chunks[i]->font->font_face);
|
||||
} else
|
||||
{
|
||||
} else {
|
||||
cairo_set_font_face(cr, m_font_face);
|
||||
}
|
||||
cairo_text_extents_t ext;
|
||||
|
@ -283,8 +239,7 @@ int cairo_font::text_width( cairo_t* cr, text_chunk::vector& chunks )
|
|||
return (int)ret;
|
||||
}
|
||||
|
||||
void cairo_font::get_metrics(cairo_t* cr, cairo_font_metrics* fm )
|
||||
{
|
||||
void cairo_font::get_metrics(cairo_t* cr, cairo_font_metrics* fm) {
|
||||
lock();
|
||||
cairo_set_font_face(cr, m_font_face);
|
||||
cairo_set_font_size(cr, m_size);
|
||||
|
@ -301,15 +256,13 @@ void cairo_font::get_metrics(cairo_t* cr, cairo_font_metrics* fm )
|
|||
unlock();
|
||||
}
|
||||
|
||||
void cairo_font::set_font( HFONT hFont )
|
||||
{
|
||||
void cairo_font::set_font(HFONT hFont) {
|
||||
clear();
|
||||
|
||||
m_hFont = hFont;
|
||||
m_font_face = create_font_face(m_hFont);
|
||||
m_font_code_pages = 0;
|
||||
if(m_font_link)
|
||||
{
|
||||
if (m_font_link) {
|
||||
HDC hdc = GetDC(NULL);
|
||||
SelectObject(hdc, m_hFont);
|
||||
m_font_link->GetFontCodePages(hdc, m_hFont, &m_font_code_pages);
|
||||
|
@ -321,34 +274,27 @@ void cairo_font::set_font( HFONT hFont )
|
|||
m_bStrikeOut = lf.lfStrikeOut;
|
||||
}
|
||||
|
||||
void cairo_font::clear()
|
||||
{
|
||||
if(m_font_face)
|
||||
{
|
||||
void cairo_font::clear() {
|
||||
if (m_font_face) {
|
||||
cairo_font_face_destroy(m_font_face);
|
||||
m_font_face = NULL;
|
||||
}
|
||||
for(size_t i = 0; i < m_linked_fonts.size(); i++)
|
||||
{
|
||||
if(m_linked_fonts[i]->hFont && m_font_link)
|
||||
{
|
||||
for (size_t i = 0; i < m_linked_fonts.size(); i++) {
|
||||
if (m_linked_fonts[i]->hFont && m_font_link) {
|
||||
m_font_link->ReleaseFont(m_linked_fonts[i]->hFont);
|
||||
}
|
||||
if(m_linked_fonts[i]->font_face)
|
||||
{
|
||||
if (m_linked_fonts[i]->font_face) {
|
||||
cairo_font_face_destroy(m_linked_fonts[i]->font_face);
|
||||
}
|
||||
}
|
||||
m_linked_fonts.clear();
|
||||
if(m_hFont)
|
||||
{
|
||||
if (m_hFont) {
|
||||
DeleteObject(m_hFont);
|
||||
m_hFont = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
void cairo_font::init()
|
||||
{
|
||||
void cairo_font::init() {
|
||||
m_hFont = NULL;
|
||||
m_font_face = NULL;
|
||||
m_font_link = NULL;
|
||||
|
@ -358,8 +304,7 @@ void cairo_font::init()
|
|||
m_bStrikeOut = FALSE;
|
||||
}
|
||||
|
||||
wchar_t* cairo_font::utf8_to_wchar( const char* src )
|
||||
{
|
||||
wchar_t* cairo_font::utf8_to_wchar(const char* src) {
|
||||
if (!src) return NULL;
|
||||
|
||||
int len = (int)strlen(src);
|
||||
|
@ -368,8 +313,7 @@ wchar_t* cairo_font::utf8_to_wchar( const char* src )
|
|||
return ret;
|
||||
}
|
||||
|
||||
char* cairo_font::wchar_to_utf8( const wchar_t* src )
|
||||
{
|
||||
char* cairo_font::wchar_to_utf8(const wchar_t* src) {
|
||||
if (!src) return NULL;
|
||||
|
||||
int len = WideCharToMultiByte(CP_UTF8, 0, src, -1, NULL, 0, NULL, NULL);
|
||||
|
|
|
@ -1,18 +1,18 @@
|
|||
#pragma once
|
||||
|
||||
#include <windows.h>
|
||||
#include <stdlib.h>
|
||||
#include <cairo-win32.h>
|
||||
#include <cairo.h>
|
||||
#include <litehtml.h>
|
||||
#include <malloc.h>
|
||||
#include <memory.h>
|
||||
#include <tchar.h>
|
||||
#include <mlang.h>
|
||||
#include <vector>
|
||||
#include <cairo.h>
|
||||
#include <cairo-win32.h>
|
||||
#include <litehtml.h>
|
||||
#include <stdlib.h>
|
||||
#include <tchar.h>
|
||||
#include <windows.h>
|
||||
|
||||
struct linked_font
|
||||
{
|
||||
#include <vector>
|
||||
|
||||
struct linked_font {
|
||||
typedef std::vector<linked_font*> vector;
|
||||
|
||||
DWORD code_pages;
|
||||
|
@ -20,33 +20,27 @@ struct linked_font
|
|||
cairo_font_face_t* font_face;
|
||||
};
|
||||
|
||||
struct text_chunk
|
||||
{
|
||||
struct text_chunk {
|
||||
typedef std::vector<text_chunk*> vector;
|
||||
|
||||
char* text;
|
||||
linked_font* font;
|
||||
|
||||
~text_chunk()
|
||||
{
|
||||
if(text)
|
||||
{
|
||||
~text_chunk() {
|
||||
if (text) {
|
||||
delete text;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
struct cairo_font_metrics
|
||||
{
|
||||
struct cairo_font_metrics {
|
||||
int height;
|
||||
int ascent;
|
||||
int descent;
|
||||
int x_height;
|
||||
};
|
||||
|
||||
|
||||
class cairo_font
|
||||
{
|
||||
class cairo_font {
|
||||
HFONT m_hFont;
|
||||
cairo_font_face_t* m_font_face;
|
||||
IMLangFontLink2* m_font_link;
|
||||
|
@ -56,6 +50,7 @@ class cairo_font
|
|||
BOOL m_bUnderline;
|
||||
BOOL m_bStrikeOut;
|
||||
cairo_font_metrics m_metrics;
|
||||
|
||||
public:
|
||||
// fonts are not thread safe :(
|
||||
// you have to declare and initialize cairo_font::m_sync before the first using.
|
||||
|
@ -73,6 +68,7 @@ public:
|
|||
cairo_font_metrics& metrics();
|
||||
static wchar_t* utf8_to_wchar(const char* src);
|
||||
static char* wchar_to_utf8(const wchar_t* src);
|
||||
|
||||
private:
|
||||
void split_text(const litehtml::tchar_t* str, text_chunk::vector& chunks);
|
||||
void free_text_chunks(text_chunk::vector& chunks);
|
||||
|
@ -86,32 +82,18 @@ private:
|
|||
void get_metrics(cairo_t* cr, cairo_font_metrics* fm);
|
||||
};
|
||||
|
||||
inline void cairo_font::lock()
|
||||
{
|
||||
EnterCriticalSection(&m_sync);
|
||||
}
|
||||
inline void cairo_font::lock() { EnterCriticalSection(&m_sync); }
|
||||
|
||||
inline void cairo_font::unlock()
|
||||
{
|
||||
LeaveCriticalSection(&m_sync);
|
||||
}
|
||||
inline void cairo_font::unlock() { LeaveCriticalSection(&m_sync); }
|
||||
|
||||
inline int cairo_font::round_d(double val)
|
||||
{
|
||||
inline int cairo_font::round_d(double val) {
|
||||
int int_val = (int)val;
|
||||
if(val - int_val >= 0.5)
|
||||
{
|
||||
if (val - int_val >= 0.5) {
|
||||
int_val++;
|
||||
}
|
||||
return int_val;
|
||||
}
|
||||
|
||||
inline cairo_font_metrics& cairo_font::metrics()
|
||||
{
|
||||
return m_metrics;
|
||||
}
|
||||
inline cairo_font_metrics& cairo_font::metrics() { return m_metrics; }
|
||||
|
||||
inline void cairo_font::load_metrics(cairo_t* cr)
|
||||
{
|
||||
get_metrics(cr, &m_metrics);
|
||||
}
|
||||
inline void cairo_font::load_metrics(cairo_t* cr) { get_metrics(cr, &m_metrics); }
|
||||
|
|
|
@ -1,15 +1,10 @@
|
|||
#include "gdiplus_container.h"
|
||||
|
||||
gdiplus_container::gdiplus_container(void)
|
||||
{
|
||||
}
|
||||
gdiplus_container::gdiplus_container(void) {}
|
||||
|
||||
gdiplus_container::~gdiplus_container(void)
|
||||
{
|
||||
}
|
||||
gdiplus_container::~gdiplus_container(void) {}
|
||||
|
||||
void gdiplus_container::draw_ellipse( HDC hdc, int x, int y, int width, int height, const litehtml::web_color& color, int line_width )
|
||||
{
|
||||
void gdiplus_container::draw_ellipse(HDC hdc, int x, int y, int width, int height, const litehtml::web_color& color, int line_width) {
|
||||
Gdiplus::Graphics graphics(hdc);
|
||||
Gdiplus::LinearGradientBrush* brush = NULL;
|
||||
|
||||
|
@ -20,8 +15,7 @@ void gdiplus_container::draw_ellipse( HDC hdc, int x, int y, int width, int heig
|
|||
graphics.DrawEllipse(&pen, x, y, width, height);
|
||||
}
|
||||
|
||||
void gdiplus_container::fill_ellipse( HDC hdc, int x, int y, int width, int height, const litehtml::web_color& color )
|
||||
{
|
||||
void gdiplus_container::fill_ellipse(HDC hdc, int x, int y, int width, int height, const litehtml::web_color& color) {
|
||||
Gdiplus::Graphics graphics(hdc);
|
||||
|
||||
graphics.SetCompositingQuality(Gdiplus::CompositingQualityHighQuality);
|
||||
|
@ -31,29 +25,24 @@ void gdiplus_container::fill_ellipse( HDC hdc, int x, int y, int width, int heig
|
|||
graphics.FillEllipse(&brush, x, y, width, height);
|
||||
}
|
||||
|
||||
void gdiplus_container::fill_rect( HDC hdc, int x, int y, int width, int height, const litehtml::web_color& color, const litehtml::css_border_radius& radius )
|
||||
{
|
||||
void gdiplus_container::fill_rect(HDC hdc, int x, int y, int width, int height, const litehtml::web_color& color, const litehtml::css_border_radius& radius) {
|
||||
Gdiplus::Graphics graphics(hdc);
|
||||
|
||||
Gdiplus::SolidBrush brush(Gdiplus::Color(color.alpha, color.red, color.green, color.blue));
|
||||
graphics.FillRectangle(&brush, x, y, width, height);
|
||||
}
|
||||
|
||||
void gdiplus_container::get_img_size( litehtml::uint_ptr img, litehtml::size& sz )
|
||||
{
|
||||
void gdiplus_container::get_img_size(litehtml::uint_ptr img, litehtml::size& sz) {
|
||||
Gdiplus::Bitmap* bmp = (Gdiplus::Bitmap*)img;
|
||||
if(bmp)
|
||||
{
|
||||
if (bmp) {
|
||||
sz.width = bmp->GetWidth();
|
||||
sz.height = bmp->GetHeight();
|
||||
}
|
||||
}
|
||||
|
||||
void gdiplus_container::draw_img(HDC hdc, litehtml::uint_ptr img, const litehtml::position& pos )
|
||||
{
|
||||
void gdiplus_container::draw_img(HDC hdc, litehtml::uint_ptr img, const litehtml::position& pos) {
|
||||
Gdiplus::Bitmap* bmp = (Gdiplus::Bitmap*)img;
|
||||
if(bmp)
|
||||
{
|
||||
if (bmp) {
|
||||
Gdiplus::Graphics graphics(hdc);
|
||||
graphics.SetInterpolationMode(Gdiplus::InterpolationModeNearestNeighbor);
|
||||
graphics.SetPixelOffsetMode(Gdiplus::PixelOffsetModeHalf);
|
||||
|
@ -61,17 +50,14 @@ void gdiplus_container::draw_img(HDC hdc, litehtml::uint_ptr img, const litehtml
|
|||
}
|
||||
}
|
||||
|
||||
void gdiplus_container::free_image( litehtml::uint_ptr img )
|
||||
{
|
||||
void gdiplus_container::free_image(litehtml::uint_ptr img) {
|
||||
Gdiplus::Bitmap* bmp = (Gdiplus::Bitmap*)img;
|
||||
if(bmp)
|
||||
{
|
||||
if (bmp) {
|
||||
delete bmp;
|
||||
}
|
||||
}
|
||||
|
||||
void gdiplus_container::draw_img_bg( HDC hdc, litehtml::uint_ptr img, const litehtml::position& draw_pos, const litehtml::position& pos, litehtml::background_repeat repeat, litehtml::background_attachment attachment )
|
||||
{
|
||||
void gdiplus_container::draw_img_bg(HDC hdc, litehtml::uint_ptr img, const litehtml::position& draw_pos, const litehtml::position& pos, litehtml::background_repeat repeat, litehtml::background_attachment attachment) {
|
||||
Gdiplus::Bitmap* bgbmp = (Gdiplus::Bitmap*)img;
|
||||
|
||||
int img_width = bgbmp->GetWidth();
|
||||
|
@ -84,70 +70,51 @@ void gdiplus_container::draw_img_bg( HDC hdc, litehtml::uint_ptr img, const lite
|
|||
Gdiplus::Region reg(Gdiplus::Rect(draw_pos.left(), draw_pos.top(), draw_pos.width, draw_pos.height));
|
||||
graphics.SetClip(®);
|
||||
|
||||
switch(repeat)
|
||||
{
|
||||
case litehtml::background_repeat_no_repeat:
|
||||
{
|
||||
switch (repeat) {
|
||||
case litehtml::background_repeat_no_repeat: {
|
||||
graphics.DrawImage(bgbmp, pos.x, pos.y, bgbmp->GetWidth(), bgbmp->GetHeight());
|
||||
}
|
||||
break;
|
||||
case litehtml::background_repeat_repeat_x:
|
||||
{
|
||||
} break;
|
||||
case litehtml::background_repeat_repeat_x: {
|
||||
Gdiplus::CachedBitmap bmp(bgbmp, &graphics);
|
||||
for(int x = pos.left(); x < pos.right(); x += bgbmp->GetWidth())
|
||||
{
|
||||
for (int x = pos.left(); x < pos.right(); x += bgbmp->GetWidth()) {
|
||||
graphics.DrawCachedBitmap(&bmp, x, pos.top());
|
||||
}
|
||||
|
||||
for(int x = pos.left() - bgbmp->GetWidth(); x + (int) bgbmp->GetWidth() > draw_pos.left(); x -= bgbmp->GetWidth())
|
||||
{
|
||||
for (int x = pos.left() - bgbmp->GetWidth(); x + (int)bgbmp->GetWidth() > draw_pos.left(); x -= bgbmp->GetWidth()) {
|
||||
graphics.DrawCachedBitmap(&bmp, x, pos.top());
|
||||
}
|
||||
}
|
||||
break;
|
||||
case litehtml::background_repeat_repeat_y:
|
||||
{
|
||||
} break;
|
||||
case litehtml::background_repeat_repeat_y: {
|
||||
Gdiplus::CachedBitmap bmp(bgbmp, &graphics);
|
||||
for(int y = pos.top(); y < pos.bottom(); y += bgbmp->GetHeight())
|
||||
{
|
||||
for (int y = pos.top(); y < pos.bottom(); y += bgbmp->GetHeight()) {
|
||||
graphics.DrawCachedBitmap(&bmp, pos.left(), y);
|
||||
}
|
||||
|
||||
for(int y = pos.top() - bgbmp->GetHeight(); y + (int) bgbmp->GetHeight() > draw_pos.top(); y -= bgbmp->GetHeight())
|
||||
{
|
||||
for (int y = pos.top() - bgbmp->GetHeight(); y + (int)bgbmp->GetHeight() > draw_pos.top(); y -= bgbmp->GetHeight()) {
|
||||
graphics.DrawCachedBitmap(&bmp, pos.left(), y);
|
||||
}
|
||||
}
|
||||
break;
|
||||
case litehtml::background_repeat_repeat:
|
||||
{
|
||||
} break;
|
||||
case litehtml::background_repeat_repeat: {
|
||||
Gdiplus::CachedBitmap bmp(bgbmp, &graphics);
|
||||
if(bgbmp->GetHeight() >= 0)
|
||||
{
|
||||
for(int x = pos.left(); x < pos.right(); x += bgbmp->GetWidth())
|
||||
{
|
||||
for(int y = pos.top(); y < pos.bottom(); y += bgbmp->GetHeight())
|
||||
{
|
||||
if (bgbmp->GetHeight() >= 0) {
|
||||
for (int x = pos.left(); x < pos.right(); x += bgbmp->GetWidth()) {
|
||||
for (int y = pos.top(); y < pos.bottom(); y += bgbmp->GetHeight()) {
|
||||
graphics.DrawCachedBitmap(&bmp, x, y);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
break;
|
||||
} break;
|
||||
}
|
||||
}
|
||||
|
||||
void gdiplus_container::draw_borders( litehtml::uint_ptr hdc, const litehtml::css_borders& borders, const litehtml::position& draw_pos )
|
||||
{
|
||||
void gdiplus_container::draw_borders(litehtml::uint_ptr hdc, const litehtml::css_borders& borders, const litehtml::position& draw_pos) {
|
||||
apply_clip((HDC)hdc);
|
||||
|
||||
// draw left border
|
||||
if(borders.left.width.val() != 0 && borders.left.style > litehtml::border_style_hidden)
|
||||
{
|
||||
if (borders.left.width.val() != 0 && borders.left.style > litehtml::border_style_hidden) {
|
||||
HPEN pen = CreatePen(PS_SOLID, 1, RGB(borders.left.color.red, borders.left.color.green, borders.left.color.blue));
|
||||
HPEN oldPen = (HPEN)SelectObject((HDC)hdc, pen);
|
||||
for(int x = 0; x < borders.left.width.val(); x++)
|
||||
{
|
||||
for (int x = 0; x < borders.left.width.val(); x++) {
|
||||
MoveToEx((HDC)hdc, draw_pos.left() + x, draw_pos.top(), NULL);
|
||||
LineTo((HDC)hdc, draw_pos.left() + x, draw_pos.bottom());
|
||||
}
|
||||
|
@ -155,12 +122,10 @@ void gdiplus_container::draw_borders( litehtml::uint_ptr hdc, const litehtml::cs
|
|||
DeleteObject(pen);
|
||||
}
|
||||
// draw right border
|
||||
if(borders.right.width.val() != 0 && borders.right.style > litehtml::border_style_hidden)
|
||||
{
|
||||
if (borders.right.width.val() != 0 && borders.right.style > litehtml::border_style_hidden) {
|
||||
HPEN pen = CreatePen(PS_SOLID, 1, RGB(borders.right.color.red, borders.right.color.green, borders.right.color.blue));
|
||||
HPEN oldPen = (HPEN)SelectObject((HDC)hdc, pen);
|
||||
for(int x = 0; x < borders.right.width.val(); x++)
|
||||
{
|
||||
for (int x = 0; x < borders.right.width.val(); x++) {
|
||||
MoveToEx((HDC)hdc, draw_pos.right() - x - 1, draw_pos.top(), NULL);
|
||||
LineTo((HDC)hdc, draw_pos.right() - x - 1, draw_pos.bottom());
|
||||
}
|
||||
|
@ -168,12 +133,10 @@ void gdiplus_container::draw_borders( litehtml::uint_ptr hdc, const litehtml::cs
|
|||
DeleteObject(pen);
|
||||
}
|
||||
// draw top border
|
||||
if(borders.top.width.val() != 0 && borders.top.style > litehtml::border_style_hidden)
|
||||
{
|
||||
if (borders.top.width.val() != 0 && borders.top.style > litehtml::border_style_hidden) {
|
||||
HPEN pen = CreatePen(PS_SOLID, 1, RGB(borders.top.color.red, borders.top.color.green, borders.top.color.blue));
|
||||
HPEN oldPen = (HPEN)SelectObject((HDC)hdc, pen);
|
||||
for(int y = 0; y < borders.top.width.val(); y++)
|
||||
{
|
||||
for (int y = 0; y < borders.top.width.val(); y++) {
|
||||
MoveToEx((HDC)hdc, draw_pos.left(), draw_pos.top() + y, NULL);
|
||||
LineTo((HDC)hdc, draw_pos.right(), draw_pos.top() + y);
|
||||
}
|
||||
|
@ -181,12 +144,10 @@ void gdiplus_container::draw_borders( litehtml::uint_ptr hdc, const litehtml::cs
|
|||
DeleteObject(pen);
|
||||
}
|
||||
// draw bottom border
|
||||
if(borders.bottom.width.val() != 0 && borders.bottom.style > litehtml::border_style_hidden)
|
||||
{
|
||||
if (borders.bottom.width.val() != 0 && borders.bottom.style > litehtml::border_style_hidden) {
|
||||
HPEN pen = CreatePen(PS_SOLID, 1, RGB(borders.bottom.color.red, borders.bottom.color.green, borders.bottom.color.blue));
|
||||
HPEN oldPen = (HPEN)SelectObject((HDC)hdc, pen);
|
||||
for(int y = 0; y < borders.bottom.width.val(); y++)
|
||||
{
|
||||
for (int y = 0; y < borders.bottom.width.val(); y++) {
|
||||
MoveToEx((HDC)hdc, draw_pos.left(), draw_pos.bottom() - y - 1, NULL);
|
||||
LineTo((HDC)hdc, draw_pos.right(), draw_pos.bottom() - y - 1);
|
||||
}
|
||||
|
|
|
@ -1,18 +1,18 @@
|
|||
#pragma once
|
||||
#include <windows.h>
|
||||
#include <mlang.h>
|
||||
#include <stdlib.h>
|
||||
#include <GdiPlus.h>
|
||||
#include <litehtml.h>
|
||||
#include <malloc.h>
|
||||
#include <memory.h>
|
||||
#include <tchar.h>
|
||||
#include <mlang.h>
|
||||
#include <stdlib.h>
|
||||
#include <tchar.h>
|
||||
#include <windows.h>
|
||||
|
||||
#include <vector>
|
||||
#include <litehtml.h>
|
||||
#include <GdiPlus.h>
|
||||
|
||||
#include "..\win32\win32_container.h"
|
||||
|
||||
class gdiplus_container : public litehtml::win32_container
|
||||
{
|
||||
class gdiplus_container : public litehtml::win32_container {
|
||||
public:
|
||||
gdiplus_container(void);
|
||||
virtual ~gdiplus_container(void);
|
||||
|
|
|
@ -6,32 +6,22 @@
|
|||
*/
|
||||
#include "container_haiku.h"
|
||||
|
||||
#include <string>
|
||||
#include <iostream>
|
||||
#include <fstream>
|
||||
#include <streambuf>
|
||||
#include <map>
|
||||
|
||||
#include <Bitmap.h>
|
||||
#include <String.h>
|
||||
#include <Entry.h>
|
||||
#include <Path.h>
|
||||
#include <String.h>
|
||||
#include <TranslationUtils.h>
|
||||
|
||||
LiteHtmlView::LiteHtmlView(BRect frame, const char *name)
|
||||
: BView(frame, name, B_FOLLOW_ALL, B_WILL_DRAW),
|
||||
fContext(NULL),
|
||||
m_html(NULL),
|
||||
m_images(),
|
||||
m_base_url(),
|
||||
m_url()
|
||||
{
|
||||
#include <fstream>
|
||||
#include <iostream>
|
||||
#include <map>
|
||||
#include <streambuf>
|
||||
#include <string>
|
||||
|
||||
LiteHtmlView::LiteHtmlView(BRect frame, const char* name) : BView(frame, name, B_FOLLOW_ALL, B_WILL_DRAW), fContext(NULL), m_html(NULL), m_images(), m_base_url(), m_url() {
|
||||
BRect bounds(Bounds());
|
||||
BPoint topLeft = bounds.LeftTop();
|
||||
std::cout << "Initial bounds: topLeft x: " << +topLeft.x << ", y: "
|
||||
<< +topLeft.y << ", width: " << +bounds.Width() << ", height: "
|
||||
<< +bounds.Height() << std::endl;
|
||||
std::cout << "Initial bounds: topLeft x: " << +topLeft.x << ", y: " << +topLeft.y << ", width: " << +bounds.Width() << ", height: " << +bounds.Height() << std::endl;
|
||||
|
||||
SetDrawingMode(B_OP_OVER);
|
||||
SetFont(be_plain_font);
|
||||
|
@ -42,25 +32,16 @@ LiteHtmlView::LiteHtmlView(BRect frame, const char *name)
|
|||
// FillRect(rect);
|
||||
}
|
||||
|
||||
LiteHtmlView::~LiteHtmlView()
|
||||
{
|
||||
}
|
||||
LiteHtmlView::~LiteHtmlView() {}
|
||||
|
||||
void
|
||||
LiteHtmlView::SetContext(litehtml::context* ctx)
|
||||
{
|
||||
fContext = ctx;
|
||||
}
|
||||
void LiteHtmlView::SetContext(litehtml::context* ctx) { fContext = ctx; }
|
||||
|
||||
void
|
||||
LiteHtmlView::RenderFile(const char* localFilePath)
|
||||
{
|
||||
void LiteHtmlView::RenderFile(const char* localFilePath) {
|
||||
std::cout << "RenderFile" << std::endl;
|
||||
// BUrlRequest req;
|
||||
// assume a local file for now, that is HTML
|
||||
std::ifstream t(localFilePath);
|
||||
std::string html((std::istreambuf_iterator<char>(t)),
|
||||
std::istreambuf_iterator<char>());
|
||||
std::string html((std::istreambuf_iterator<char>(t)), std::istreambuf_iterator<char>());
|
||||
|
||||
// std::cout << "HTML output:-" << std::endl << html << std::endl;
|
||||
|
||||
|
@ -76,16 +57,12 @@ LiteHtmlView::RenderFile(const char* localFilePath)
|
|||
RenderHTML(html);
|
||||
}
|
||||
|
||||
void
|
||||
LiteHtmlView::RenderHTML(const std::string& htmlText)
|
||||
{
|
||||
void LiteHtmlView::RenderHTML(const std::string& htmlText) {
|
||||
std::cout << "RenderHTML" << std::endl;
|
||||
|
||||
// now use this string
|
||||
m_html = litehtml::document::createFromString(
|
||||
htmlText.c_str(), this, fContext);
|
||||
if (m_html)
|
||||
{
|
||||
m_html = litehtml::document::createFromString(htmlText.c_str(), this, fContext);
|
||||
if (m_html) {
|
||||
std::cout << "Successfully read html" << std::endl;
|
||||
// success
|
||||
// post-parse render operations, if required.
|
||||
|
@ -97,9 +74,7 @@ LiteHtmlView::RenderHTML(const std::string& htmlText)
|
|||
std::cout << "Sending html rendered message: " << M_HTML_RENDERED << std::endl;
|
||||
}
|
||||
|
||||
void
|
||||
LiteHtmlView::Draw(BRect b)
|
||||
{
|
||||
void LiteHtmlView::Draw(BRect b) {
|
||||
std::cout << "DRAW CALLED" << std::endl;
|
||||
|
||||
BRect bounds(Bounds());
|
||||
|
@ -109,19 +84,15 @@ LiteHtmlView::Draw(BRect b)
|
|||
|
||||
if (NULL != m_html) {
|
||||
BPoint leftTop = bounds.LeftTop();
|
||||
litehtml::position clip(leftTop.x,leftTop.y,
|
||||
bounds.Width(),bounds.Height());
|
||||
litehtml::position clip(leftTop.x, leftTop.y, bounds.Width(), bounds.Height());
|
||||
m_html->render(bounds.Width());
|
||||
m_html->draw((litehtml::uint_ptr)this, 0, 0, &clip);
|
||||
}
|
||||
SendNotices(M_HTML_RENDERED, new BMessage(M_HTML_RENDERED));
|
||||
}
|
||||
|
||||
void
|
||||
LiteHtmlView::GetPreferredSize(float* width,float* height)
|
||||
{
|
||||
if (NULL == m_html)
|
||||
{
|
||||
void LiteHtmlView::GetPreferredSize(float* width, float* height) {
|
||||
if (NULL == m_html) {
|
||||
BRect bounds(Bounds());
|
||||
*width = bounds.Width();
|
||||
*height = bounds.Height();
|
||||
|
@ -131,67 +102,65 @@ LiteHtmlView::GetPreferredSize(float* width,float* height)
|
|||
}
|
||||
}
|
||||
|
||||
litehtml::uint_ptr
|
||||
LiteHtmlView::create_font( const litehtml::tchar_t* faceName, int size,
|
||||
int weight, litehtml::font_style italic, unsigned int decoration,
|
||||
litehtml::font_metrics* fm )
|
||||
{
|
||||
litehtml::uint_ptr LiteHtmlView::create_font(const litehtml::tchar_t* faceName, int size, int weight, litehtml::font_style italic, unsigned int decoration, litehtml::font_metrics* fm) {
|
||||
// std::cout << "create_font" << std::endl;
|
||||
litehtml::string_vector fonts;
|
||||
litehtml::split_string(faceName, fonts, ",");
|
||||
litehtml::trim(fonts[0]);
|
||||
|
||||
uint16 face = B_REGULAR_FACE; // default
|
||||
if (italic == litehtml::fontStyleItalic)
|
||||
{
|
||||
if (italic == litehtml::fontStyleItalic) {
|
||||
face |= B_ITALIC_FACE;
|
||||
}
|
||||
if (decoration & litehtml::font_decoration_underline)
|
||||
{
|
||||
if (decoration & litehtml::font_decoration_underline) {
|
||||
face |= B_UNDERSCORE_FACE;
|
||||
}
|
||||
if (decoration & litehtml::font_decoration_linethrough)
|
||||
{
|
||||
if (decoration & litehtml::font_decoration_linethrough) {
|
||||
face |= B_STRIKEOUT_FACE;
|
||||
}
|
||||
// Note: LIGHT, HEAVY, CONDENSED not supported in BeOS R5
|
||||
#ifdef __HAIKU__
|
||||
if(weight >= 0 && weight < 150) face |= B_LIGHT_FACE;
|
||||
else if(weight >= 150 && weight < 250) face |= B_LIGHT_FACE;
|
||||
else if(weight >= 250 && weight < 350) face |= B_LIGHT_FACE;
|
||||
if (weight >= 0 && weight < 150)
|
||||
face |= B_LIGHT_FACE;
|
||||
else if (weight >= 150 && weight < 250)
|
||||
face |= B_LIGHT_FACE;
|
||||
else if (weight >= 250 && weight < 350)
|
||||
face |= B_LIGHT_FACE;
|
||||
// else if(weight >= 350 && weight < 450) face |= B_REGULAR_FACE;
|
||||
// else if(weight >= 450 && weight < 550) face |= B_REGULAR_FACE;
|
||||
else if(weight >= 550 && weight < 650) face |= B_CONDENSED_FACE;
|
||||
else if (weight >= 550 && weight < 650)
|
||||
face |= B_CONDENSED_FACE;
|
||||
#else
|
||||
else if(weight >= 550 && weight < 650) face |= B_BOLD_FACE;
|
||||
else if (weight >= 550 && weight < 650)
|
||||
face |= B_BOLD_FACE;
|
||||
#endif
|
||||
else if(weight >= 650 && weight < 750) face |= B_BOLD_FACE;
|
||||
else if (weight >= 650 && weight < 750)
|
||||
face |= B_BOLD_FACE;
|
||||
#ifndef __HAIKU__
|
||||
else if(weight >= 750 && weight < 850) face |= B_BOLD_FACE;
|
||||
else if(weight >= 950) face |= B_BOLD_FACE;
|
||||
else if (weight >= 750 && weight < 850)
|
||||
face |= B_BOLD_FACE;
|
||||
else if (weight >= 950)
|
||||
face |= B_BOLD_FACE;
|
||||
#else
|
||||
else if(weight >= 750 && weight < 850) face |= B_HEAVY_FACE;
|
||||
else if(weight >= 950) face |= B_HEAVY_FACE;
|
||||
else if (weight >= 750 && weight < 850)
|
||||
face |= B_HEAVY_FACE;
|
||||
else if (weight >= 950)
|
||||
face |= B_HEAVY_FACE;
|
||||
#endif
|
||||
|
||||
BFont* tempFont = new BFont();
|
||||
bool found = false;
|
||||
for(litehtml::string_vector::iterator i = fonts.begin();
|
||||
i != fonts.end(); i++)
|
||||
{
|
||||
if (B_OK == tempFont->SetFamilyAndFace(i->c_str(),face))
|
||||
{
|
||||
for (litehtml::string_vector::iterator i = fonts.begin(); i != fonts.end(); i++) {
|
||||
if (B_OK == tempFont->SetFamilyAndFace(i->c_str(), face)) {
|
||||
found = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (!found)
|
||||
{
|
||||
if (!found) {
|
||||
// default to the Be plain font
|
||||
tempFont = new BFont(be_plain_font);
|
||||
if (weight >= 550)
|
||||
{
|
||||
if (weight >= 550) {
|
||||
tempFont = new BFont(be_bold_font);
|
||||
}
|
||||
tempFont->SetFace(face); // chooses closest
|
||||
|
@ -209,16 +178,9 @@ LiteHtmlView::create_font( const litehtml::tchar_t* faceName, int size,
|
|||
return (litehtml::uint_ptr)tempFont;
|
||||
}
|
||||
|
||||
void
|
||||
LiteHtmlView::delete_font( litehtml::uint_ptr hFont )
|
||||
{
|
||||
std::cout << "delete_font" << std::endl;
|
||||
}
|
||||
void LiteHtmlView::delete_font(litehtml::uint_ptr hFont) { std::cout << "delete_font" << std::endl; }
|
||||
|
||||
int
|
||||
LiteHtmlView::text_width( const litehtml::tchar_t* text,
|
||||
litehtml::uint_ptr hFont )
|
||||
{
|
||||
int LiteHtmlView::text_width(const litehtml::tchar_t* text, litehtml::uint_ptr hFont) {
|
||||
// std::cout << "text_width" << std::endl;
|
||||
BFont* fnt = (BFont*)hFont;
|
||||
int width = fnt->StringWidth(text);
|
||||
|
@ -226,11 +188,7 @@ LiteHtmlView::text_width( const litehtml::tchar_t* text,
|
|||
return width;
|
||||
}
|
||||
|
||||
void
|
||||
LiteHtmlView::draw_text( litehtml::uint_ptr hdc, const litehtml::tchar_t* text,
|
||||
litehtml::uint_ptr hFont, litehtml::web_color color,
|
||||
const litehtml::position& pos )
|
||||
{
|
||||
void LiteHtmlView::draw_text(litehtml::uint_ptr hdc, const litehtml::tchar_t* text, litehtml::uint_ptr hFont, litehtml::web_color color, const litehtml::position& pos) {
|
||||
// std::cout << "draw_text" << std::endl;
|
||||
if (!text) return;
|
||||
if (0 == strlen(text)) return;
|
||||
|
@ -276,23 +234,17 @@ LiteHtmlView::draw_text( litehtml::uint_ptr hdc, const litehtml::tchar_t* text,
|
|||
DrawString(mystr);
|
||||
}
|
||||
|
||||
int
|
||||
LiteHtmlView::pt_to_px( int pt )
|
||||
{
|
||||
int LiteHtmlView::pt_to_px(int pt) {
|
||||
std::cout << "pt_to_px" << std::endl;
|
||||
return (int)((double)pt * 1.3333333333);
|
||||
}
|
||||
|
||||
int
|
||||
LiteHtmlView::get_default_font_size() const
|
||||
{
|
||||
int LiteHtmlView::get_default_font_size() const {
|
||||
// std::cout << "get_default_font_size" << std::endl;
|
||||
return 12;
|
||||
}
|
||||
|
||||
const litehtml::tchar_t*
|
||||
LiteHtmlView::get_default_font_name() const
|
||||
{
|
||||
const litehtml::tchar_t* LiteHtmlView::get_default_font_name() const {
|
||||
// std::cout << "get_default_font_name" << std::endl;
|
||||
font_family fam;
|
||||
font_style style;
|
||||
|
@ -301,27 +253,19 @@ LiteHtmlView::get_default_font_name() const
|
|||
return (litehtml::tchar_t*)cp;
|
||||
}
|
||||
|
||||
void
|
||||
LiteHtmlView::draw_list_marker( litehtml::uint_ptr hdc,
|
||||
const litehtml::list_marker& marker )
|
||||
{
|
||||
void LiteHtmlView::draw_list_marker(litehtml::uint_ptr hdc, const litehtml::list_marker& marker) {
|
||||
std::cout << "draw_list_marker" << std::endl;
|
||||
if (!marker.image.empty())
|
||||
{
|
||||
if (!marker.image.empty()) {
|
||||
std::cout << " image marker" << std::endl;
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
LiteHtmlView::load_image( const litehtml::tchar_t* src,
|
||||
const litehtml::tchar_t* baseurl, bool redraw_on_ready )
|
||||
{
|
||||
void LiteHtmlView::load_image(const litehtml::tchar_t* src, const litehtml::tchar_t* baseurl, bool redraw_on_ready) {
|
||||
std::cout << "load_image" << std::endl;
|
||||
|
||||
std::string url;
|
||||
make_url(src, baseurl, url);
|
||||
if(m_images.find(url.c_str()) == m_images.end())
|
||||
{
|
||||
if (m_images.find(url.c_str()) == m_images.end()) {
|
||||
BEntry entry(url.c_str(), true);
|
||||
if (entry.Exists()) {
|
||||
std::cout << " Loading bitmap from file" << std::endl;
|
||||
|
@ -331,27 +275,20 @@ LiteHtmlView::load_image( const litehtml::tchar_t* src,
|
|||
}
|
||||
}
|
||||
|
||||
void
|
||||
LiteHtmlView::make_url(const litehtml::tchar_t* url,
|
||||
const litehtml::tchar_t* basepath, litehtml::tstring& out)
|
||||
{
|
||||
void LiteHtmlView::make_url(const litehtml::tchar_t* url, const litehtml::tchar_t* basepath, litehtml::tstring& out) {
|
||||
std::cout << "make_url" << std::endl;
|
||||
std::cout << " url: " << url << std::endl;
|
||||
if(!basepath || (basepath && !basepath[0]))
|
||||
{
|
||||
if(!m_base_url.empty())
|
||||
{
|
||||
if (!basepath || (basepath && !basepath[0])) {
|
||||
if (!m_base_url.empty()) {
|
||||
// out = urljoin(m_base_url, std::string(url));
|
||||
std::string ns(m_base_url);
|
||||
ns += "/";
|
||||
ns += url;
|
||||
out = ns;
|
||||
} else
|
||||
{
|
||||
} else {
|
||||
out = url;
|
||||
}
|
||||
} else
|
||||
{
|
||||
} else {
|
||||
std::cout << " basepath: " << basepath << std::endl;
|
||||
// out = urljoin(std::string(basepath), std::string(url));
|
||||
std::string ns(basepath);
|
||||
|
@ -362,9 +299,7 @@ LiteHtmlView::make_url(const litehtml::tchar_t* url,
|
|||
std::cout << " Output url: " << out << std::endl;
|
||||
}
|
||||
|
||||
void
|
||||
LiteHtmlView::set_base_url(const litehtml::tchar_t* base_url)
|
||||
{
|
||||
void LiteHtmlView::set_base_url(const litehtml::tchar_t* base_url) {
|
||||
std::cout << "set_base_url" << std::endl;
|
||||
/*
|
||||
if(base_url)
|
||||
|
@ -378,17 +313,12 @@ LiteHtmlView::set_base_url(const litehtml::tchar_t* base_url)
|
|||
//}
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
LiteHtmlView::get_image_size( const litehtml::tchar_t* src,
|
||||
const litehtml::tchar_t* baseurl, litehtml::size& sz )
|
||||
{
|
||||
void LiteHtmlView::get_image_size(const litehtml::tchar_t* src, const litehtml::tchar_t* baseurl, litehtml::size& sz) {
|
||||
std::cout << "get_image_size" << std::endl;
|
||||
std::string url;
|
||||
make_url(src, NULL, url);
|
||||
const auto& miter(m_images.find(url.c_str()));
|
||||
if (m_images.end() != miter)
|
||||
{
|
||||
if (m_images.end() != miter) {
|
||||
BBitmap* img = (BBitmap*)miter->second;
|
||||
BRect size = img->Bounds();
|
||||
sz.width = size.Width();
|
||||
|
@ -397,38 +327,27 @@ LiteHtmlView::get_image_size( const litehtml::tchar_t* src,
|
|||
}
|
||||
}
|
||||
|
||||
void
|
||||
LiteHtmlView::draw_image( litehtml::uint_ptr hdc, const litehtml::tchar_t* src,
|
||||
const litehtml::tchar_t* baseurl, const litehtml::position& pos )
|
||||
{
|
||||
void LiteHtmlView::draw_image(litehtml::uint_ptr hdc, const litehtml::tchar_t* src, const litehtml::tchar_t* baseurl, const litehtml::position& pos) {
|
||||
std::string url;
|
||||
make_url(src, baseurl, url);
|
||||
const auto& img = m_images.find(url.c_str());
|
||||
if(img != m_images.end())
|
||||
{
|
||||
if(img->second)
|
||||
{
|
||||
if (img != m_images.end()) {
|
||||
if (img->second) {
|
||||
DrawBitmap(img->second, BPoint(pos.x, pos.y)); // TODO support scaling
|
||||
// draw_txdib(cr, img->second.get(), pos.x, pos.y, pos.width, pos.height);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
LiteHtmlView::draw_background( litehtml::uint_ptr hdc,
|
||||
const litehtml::background_paint& bg )
|
||||
{
|
||||
void LiteHtmlView::draw_background(litehtml::uint_ptr hdc, const litehtml::background_paint& bg) {
|
||||
std::cout << "draw_background" << std::endl;
|
||||
if (0 < bg.image.length())
|
||||
{
|
||||
if (0 < bg.image.length()) {
|
||||
std::cout << " background includes an image!" << std::endl;
|
||||
draw_image(hdc, bg.image.c_str(), m_base_url.c_str(), litehtml::position(bg.position_x, bg.position_y, bg.image_size.width, bg.image_size.height));
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
LiteHtmlView::draw_borders(litehtml::uint_ptr hdc, const litehtml::borders& borders, const litehtml::position& draw_pos, bool root)
|
||||
{
|
||||
void LiteHtmlView::draw_borders(litehtml::uint_ptr hdc, const litehtml::borders& borders, const litehtml::position& draw_pos, bool root) {
|
||||
std::cout << "draw_borders" << std::endl;
|
||||
int bdr_top = 0;
|
||||
int bdr_bottom = 0;
|
||||
|
@ -438,72 +357,41 @@ LiteHtmlView::draw_borders(litehtml::uint_ptr hdc, const litehtml::borders& bord
|
|||
// std::cout << " uint ptr: " << +hdc << std::endl;
|
||||
// std::cout << " this ptr: " << +this << std::endl;
|
||||
|
||||
if(borders.top.width != 0 && borders.top.style > litehtml::border_style_hidden)
|
||||
{
|
||||
if (borders.top.width != 0 && borders.top.style > litehtml::border_style_hidden) {
|
||||
bdr_top = (int)borders.top.width;
|
||||
std::cout << " Border top: " << bdr_right << std::endl;
|
||||
}
|
||||
if(borders.bottom.width != 0 && borders.bottom.style > litehtml::border_style_hidden)
|
||||
{
|
||||
if (borders.bottom.width != 0 && borders.bottom.style > litehtml::border_style_hidden) {
|
||||
bdr_bottom = (int)borders.bottom.width;
|
||||
std::cout << " Border bottom: " << bdr_right << std::endl;
|
||||
}
|
||||
if(borders.left.width != 0 && borders.left.style > litehtml::border_style_hidden)
|
||||
{
|
||||
if (borders.left.width != 0 && borders.left.style > litehtml::border_style_hidden) {
|
||||
bdr_left = (int)borders.left.width;
|
||||
std::cout << " Border left: " << bdr_right << std::endl;
|
||||
}
|
||||
if(borders.right.width != 0 && borders.right.style > litehtml::border_style_hidden)
|
||||
{
|
||||
if (borders.right.width != 0 && borders.right.style > litehtml::border_style_hidden) {
|
||||
bdr_right = (int)borders.right.width;
|
||||
std::cout << " Border right: " << bdr_right << std::endl;
|
||||
}
|
||||
|
||||
|
||||
if (bdr_bottom)
|
||||
{
|
||||
if (bdr_bottom) {
|
||||
// draw rectangle for now - no check for radius
|
||||
StrokeRect(
|
||||
BRect(
|
||||
BPoint(draw_pos.left(), draw_pos.bottom()),
|
||||
BPoint(draw_pos.left() + bdr_left, draw_pos.bottom() - bdr_bottom)
|
||||
)
|
||||
);
|
||||
StrokeRect(BRect(BPoint(draw_pos.left(), draw_pos.bottom()), BPoint(draw_pos.left() + bdr_left, draw_pos.bottom() - bdr_bottom)));
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
LiteHtmlView::transform_text(litehtml::tstring& text, litehtml::text_transform tt)
|
||||
{
|
||||
std::cout << "transform_text" << std::endl;
|
||||
}
|
||||
void LiteHtmlView::transform_text(litehtml::tstring& text, litehtml::text_transform tt) { std::cout << "transform_text" << std::endl; }
|
||||
|
||||
void
|
||||
LiteHtmlView::set_clip( const litehtml::position& pos, const litehtml::border_radiuses& bdr_radius, bool valid_x, bool valid_y )
|
||||
{
|
||||
std::cout << "set_clip" << std::endl;
|
||||
}
|
||||
void LiteHtmlView::set_clip(const litehtml::position& pos, const litehtml::border_radiuses& bdr_radius, bool valid_x, bool valid_y) { std::cout << "set_clip" << std::endl; }
|
||||
|
||||
void
|
||||
LiteHtmlView::del_clip()
|
||||
{
|
||||
std::cout << "del_clip" << std::endl;
|
||||
}
|
||||
void LiteHtmlView::del_clip() { std::cout << "del_clip" << std::endl; }
|
||||
|
||||
|
||||
|
||||
std::shared_ptr<litehtml::element>
|
||||
LiteHtmlView::create_element(const litehtml::tchar_t *tag_name,
|
||||
const litehtml::string_map &attributes,
|
||||
const std::shared_ptr<litehtml::document> &doc)
|
||||
{
|
||||
std::shared_ptr<litehtml::element> LiteHtmlView::create_element(const litehtml::tchar_t* tag_name, const litehtml::string_map& attributes, const std::shared_ptr<litehtml::document>& doc) {
|
||||
// std::cout << "create_element" << std::endl;
|
||||
return 0;
|
||||
}
|
||||
|
||||
void
|
||||
LiteHtmlView::get_media_features(litehtml::media_features& media) const
|
||||
{
|
||||
void LiteHtmlView::get_media_features(litehtml::media_features& media) const {
|
||||
std::cout << "get_media_features" << std::endl;
|
||||
litehtml::position client;
|
||||
get_client_rect(client);
|
||||
|
@ -519,21 +407,11 @@ LiteHtmlView::get_media_features(litehtml::media_features& media) const
|
|||
media.resolution = 96;
|
||||
}
|
||||
|
||||
void
|
||||
LiteHtmlView::link(const std::shared_ptr<litehtml::document> &ptr, const litehtml::element::ptr& el)
|
||||
{
|
||||
std::cout << "link" << std::endl;
|
||||
}
|
||||
void LiteHtmlView::link(const std::shared_ptr<litehtml::document>& ptr, const litehtml::element::ptr& el) { std::cout << "link" << std::endl; }
|
||||
|
||||
void
|
||||
LiteHtmlView::set_caption(const char* caption)
|
||||
{
|
||||
std::cout << "set_caption" << std::endl;
|
||||
}
|
||||
void LiteHtmlView::set_caption(const char* caption) { std::cout << "set_caption" << std::endl; }
|
||||
|
||||
void
|
||||
LiteHtmlView::get_client_rect(litehtml::position& client) const
|
||||
{
|
||||
void LiteHtmlView::get_client_rect(litehtml::position& client) const {
|
||||
// std::cout << "get_client_rect" << std::endl;
|
||||
BRect bounds(Bounds());
|
||||
BPoint leftTop = bounds.LeftTop();
|
||||
|
@ -543,26 +421,10 @@ LiteHtmlView::get_client_rect(litehtml::position& client) const
|
|||
client.y = leftTop.y;
|
||||
}
|
||||
|
||||
void
|
||||
LiteHtmlView::on_anchor_click(const char* base, const litehtml::element::ptr& anchor)
|
||||
{
|
||||
std::cout << "on_anchor_click" << std::endl;
|
||||
}
|
||||
void LiteHtmlView::on_anchor_click(const char* base, const litehtml::element::ptr& anchor) { std::cout << "on_anchor_click" << std::endl; }
|
||||
|
||||
void
|
||||
LiteHtmlView::set_cursor(const char* cursor)
|
||||
{
|
||||
std::cout << "set_cursor" << std::endl;
|
||||
}
|
||||
void LiteHtmlView::set_cursor(const char* cursor) { std::cout << "set_cursor" << std::endl; }
|
||||
|
||||
void
|
||||
LiteHtmlView::import_css(litehtml::tstring& s1, const litehtml::tstring& s2, litehtml::tstring& s3)
|
||||
{
|
||||
std::cout << "import_css" << std::endl;
|
||||
}
|
||||
void LiteHtmlView::import_css(litehtml::tstring& s1, const litehtml::tstring& s2, litehtml::tstring& s3) { std::cout << "import_css" << std::endl; }
|
||||
|
||||
void
|
||||
LiteHtmlView::get_language(litehtml::tstring& s1, litehtml::tstring& s2) const
|
||||
{
|
||||
std::cout << "get_language" << std::endl;
|
||||
}
|
||||
void LiteHtmlView::get_language(litehtml::tstring& s1, litehtml::tstring& s2) const { std::cout << "get_language" << std::endl; }
|
||||
|
|
|
@ -7,22 +7,18 @@
|
|||
#ifndef LITEHTMLVIEW_H
|
||||
#define LITEHTMLVIEW_H
|
||||
|
||||
#include "../../include/litehtml.h"
|
||||
#include <View.h>
|
||||
|
||||
#include <map>
|
||||
#include <string>
|
||||
|
||||
#include <View.h>
|
||||
#include "../../include/litehtml.h"
|
||||
|
||||
class BBitmap;
|
||||
|
||||
enum { M_HTML_RENDERED = 'hrnd' };
|
||||
|
||||
enum {
|
||||
M_HTML_RENDERED = 'hrnd'
|
||||
};
|
||||
|
||||
class LiteHtmlView : public BView, public litehtml::document_container
|
||||
{
|
||||
class LiteHtmlView : public BView, public litehtml::document_container {
|
||||
public:
|
||||
// LiteHtmlView(BMessage *archive);
|
||||
LiteHtmlView(BRect frame, const char* name);
|
||||
|
@ -34,7 +30,6 @@ public:
|
|||
void RenderFile(const char* localFilePath);
|
||||
void RenderHTML(const std::string& htmlText);
|
||||
|
||||
|
||||
virtual litehtml::uint_ptr create_font(const litehtml::tchar_t* faceName, int size, int weight, litehtml::font_style italic, unsigned int decoration, litehtml::font_metrics* fm) override;
|
||||
virtual void delete_font(litehtml::uint_ptr hFont) override;
|
||||
virtual int text_width(const litehtml::tchar_t* text, litehtml::uint_ptr hFont) override;
|
||||
|
@ -47,14 +42,11 @@ public:
|
|||
virtual void draw_background(litehtml::uint_ptr hdc, const litehtml::background_paint& bg) override;
|
||||
virtual void draw_borders(litehtml::uint_ptr hdc, const litehtml::borders& borders, const litehtml::position& draw_pos, bool root) override;
|
||||
virtual void draw_list_marker(litehtml::uint_ptr hdc, const litehtml::list_marker& marker) override;
|
||||
virtual std::shared_ptr<litehtml::element> create_element(const litehtml::tchar_t *tag_name,
|
||||
const litehtml::string_map &attributes,
|
||||
const std::shared_ptr<litehtml::document> &doc) override;
|
||||
virtual std::shared_ptr<litehtml::element> create_element(const litehtml::tchar_t* tag_name, const litehtml::string_map& attributes, const std::shared_ptr<litehtml::document>& doc) override;
|
||||
virtual void get_media_features(litehtml::media_features& media) const override;
|
||||
// virtual void get_language(litehtml::tstring& language, litehtml::tstring & culture) const override;
|
||||
virtual void link(const std::shared_ptr<litehtml::document>& ptr, const litehtml::element::ptr& el) override;
|
||||
|
||||
|
||||
virtual void transform_text(litehtml::tstring& text, litehtml::text_transform tt) override;
|
||||
virtual void set_clip(const litehtml::position& pos, const litehtml::border_radiuses& bdr_radius, bool valid_x, bool valid_y) override;
|
||||
virtual void del_clip() override;
|
||||
|
|
|
@ -1,51 +1,55 @@
|
|||
#include "container_linux.h"
|
||||
|
||||
#include <cmath>
|
||||
|
||||
#ifndef M_PI
|
||||
#define M_PI 3.14159265358979323846
|
||||
#endif
|
||||
|
||||
container_linux::container_linux()
|
||||
{
|
||||
container_linux::container_linux() {
|
||||
m_temp_surface = cairo_image_surface_create(CAIRO_FORMAT_ARGB32, 2, 2);
|
||||
m_temp_cr = cairo_create(m_temp_surface);
|
||||
}
|
||||
|
||||
container_linux::~container_linux()
|
||||
{
|
||||
container_linux::~container_linux() {
|
||||
clear_images();
|
||||
cairo_surface_destroy(m_temp_surface);
|
||||
cairo_destroy(m_temp_cr);
|
||||
}
|
||||
|
||||
litehtml::uint_ptr container_linux::create_font( const litehtml::tchar_t* faceName, int size, int weight, litehtml::font_style italic, unsigned int decoration, litehtml::font_metrics* fm )
|
||||
{
|
||||
litehtml::uint_ptr container_linux::create_font(const litehtml::tchar_t* faceName, int size, int weight, litehtml::font_style italic, unsigned int decoration, litehtml::font_metrics* fm) {
|
||||
PangoFontDescription* desc = pango_font_description_from_string(faceName);
|
||||
pango_font_description_set_absolute_size(desc, size * PANGO_SCALE);
|
||||
if(italic == litehtml::fontStyleItalic )
|
||||
{
|
||||
if (italic == litehtml::fontStyleItalic) {
|
||||
pango_font_description_set_style(desc, PANGO_STYLE_ITALIC);
|
||||
} else
|
||||
{
|
||||
} else {
|
||||
pango_font_description_set_style(desc, PANGO_STYLE_NORMAL);
|
||||
}
|
||||
PangoWeight fnt_weight;
|
||||
if(weight >= 0 && weight < 150) fnt_weight = PANGO_WEIGHT_THIN;
|
||||
else if(weight >= 150 && weight < 250) fnt_weight = PANGO_WEIGHT_ULTRALIGHT;
|
||||
else if(weight >= 250 && weight < 350) fnt_weight = PANGO_WEIGHT_LIGHT;
|
||||
else if(weight >= 350 && weight < 450) fnt_weight = PANGO_WEIGHT_NORMAL;
|
||||
else if(weight >= 450 && weight < 550) fnt_weight = PANGO_WEIGHT_MEDIUM;
|
||||
else if(weight >= 550 && weight < 650) fnt_weight = PANGO_WEIGHT_SEMIBOLD;
|
||||
else if(weight >= 650 && weight < 750) fnt_weight = PANGO_WEIGHT_BOLD;
|
||||
else if(weight >= 750 && weight < 850) fnt_weight = PANGO_WEIGHT_ULTRABOLD;
|
||||
else fnt_weight = PANGO_WEIGHT_HEAVY;
|
||||
if (weight >= 0 && weight < 150)
|
||||
fnt_weight = PANGO_WEIGHT_THIN;
|
||||
else if (weight >= 150 && weight < 250)
|
||||
fnt_weight = PANGO_WEIGHT_ULTRALIGHT;
|
||||
else if (weight >= 250 && weight < 350)
|
||||
fnt_weight = PANGO_WEIGHT_LIGHT;
|
||||
else if (weight >= 350 && weight < 450)
|
||||
fnt_weight = PANGO_WEIGHT_NORMAL;
|
||||
else if (weight >= 450 && weight < 550)
|
||||
fnt_weight = PANGO_WEIGHT_MEDIUM;
|
||||
else if (weight >= 550 && weight < 650)
|
||||
fnt_weight = PANGO_WEIGHT_SEMIBOLD;
|
||||
else if (weight >= 650 && weight < 750)
|
||||
fnt_weight = PANGO_WEIGHT_BOLD;
|
||||
else if (weight >= 750 && weight < 850)
|
||||
fnt_weight = PANGO_WEIGHT_ULTRABOLD;
|
||||
else
|
||||
fnt_weight = PANGO_WEIGHT_HEAVY;
|
||||
|
||||
pango_font_description_set_weight(desc, fnt_weight);
|
||||
|
||||
cairo_font* ret = nullptr;
|
||||
|
||||
if(fm)
|
||||
{
|
||||
if (fm) {
|
||||
cairo_save(m_temp_cr);
|
||||
PangoLayout* layout = pango_cairo_create_layout(m_temp_cr);
|
||||
PangoContext* context = pango_layout_get_context(layout);
|
||||
|
@ -94,18 +98,15 @@ litehtml::uint_ptr container_linux::create_font( const litehtml::tchar_t* faceNa
|
|||
return (litehtml::uint_ptr)ret;
|
||||
}
|
||||
|
||||
void container_linux::delete_font( litehtml::uint_ptr hFont )
|
||||
{
|
||||
void container_linux::delete_font(litehtml::uint_ptr hFont) {
|
||||
auto* fnt = (cairo_font*)hFont;
|
||||
if(fnt)
|
||||
{
|
||||
if (fnt) {
|
||||
pango_font_description_free(fnt->font);
|
||||
delete fnt;
|
||||
}
|
||||
}
|
||||
|
||||
int container_linux::text_width( const litehtml::tchar_t* text, litehtml::uint_ptr hFont )
|
||||
{
|
||||
int container_linux::text_width(const litehtml::tchar_t* text, litehtml::uint_ptr hFont) {
|
||||
auto* fnt = (cairo_font*)hFont;
|
||||
|
||||
cairo_save(m_temp_cr);
|
||||
|
@ -124,8 +125,7 @@ int container_linux::text_width( const litehtml::tchar_t* text, litehtml::uint_p
|
|||
return (int)x_width;
|
||||
}
|
||||
|
||||
void container_linux::draw_text( litehtml::uint_ptr hdc, const litehtml::tchar_t* text, litehtml::uint_ptr hFont, litehtml::web_color color, const litehtml::position& pos )
|
||||
{
|
||||
void container_linux::draw_text(litehtml::uint_ptr hdc, const litehtml::tchar_t* text, litehtml::uint_ptr hFont, litehtml::web_color color, const litehtml::position& pos) {
|
||||
auto* fnt = (cairo_font*)hFont;
|
||||
auto* cr = (cairo_t*)hdc;
|
||||
cairo_save(cr);
|
||||
|
@ -154,20 +154,17 @@ void container_linux::draw_text( litehtml::uint_ptr hdc, const litehtml::tchar_t
|
|||
|
||||
int tw = 0;
|
||||
|
||||
if(fnt->underline || fnt->strikeout)
|
||||
{
|
||||
if (fnt->underline || fnt->strikeout) {
|
||||
tw = text_width(text, hFont);
|
||||
}
|
||||
|
||||
if(fnt->underline)
|
||||
{
|
||||
if (fnt->underline) {
|
||||
cairo_set_line_width(cr, fnt->underline_thickness);
|
||||
cairo_move_to(cr, x, pos.top() + text_baseline - fnt->underline_position + 0.5);
|
||||
cairo_line_to(cr, x + tw, pos.top() + text_baseline - fnt->underline_position + 0.5);
|
||||
cairo_stroke(cr);
|
||||
}
|
||||
if(fnt->strikeout)
|
||||
{
|
||||
if (fnt->strikeout) {
|
||||
cairo_set_line_width(cr, fnt->strikethrough_thickness);
|
||||
cairo_move_to(cr, x, pos.top() + text_baseline - fnt->strikethrough_position - 0.5);
|
||||
cairo_line_to(cr, x + tw, pos.top() + text_baseline - fnt->strikethrough_position - 0.5);
|
||||
|
@ -179,23 +176,17 @@ void container_linux::draw_text( litehtml::uint_ptr hdc, const litehtml::tchar_t
|
|||
g_object_unref(layout);
|
||||
}
|
||||
|
||||
int container_linux::pt_to_px( int pt ) const
|
||||
{
|
||||
int container_linux::pt_to_px(int pt) const {
|
||||
GdkScreen* screen = gdk_screen_get_default();
|
||||
double dpi = gdk_screen_get_resolution(screen);
|
||||
|
||||
return (int)((double)pt * dpi / 72.0);
|
||||
}
|
||||
|
||||
int container_linux::get_default_font_size() const
|
||||
{
|
||||
return pt_to_px(12);
|
||||
}
|
||||
int container_linux::get_default_font_size() const { return pt_to_px(12); }
|
||||
|
||||
void container_linux::draw_list_marker( litehtml::uint_ptr hdc, const litehtml::list_marker& marker )
|
||||
{
|
||||
if(!marker.image.empty())
|
||||
{
|
||||
void container_linux::draw_list_marker(litehtml::uint_ptr hdc, const litehtml::list_marker& marker) {
|
||||
if (!marker.image.empty()) {
|
||||
/*litehtml::tstring url;
|
||||
make_url(marker.image.c_str(), marker.baseurl, url);
|
||||
|
||||
|
@ -209,23 +200,16 @@ void container_linux::draw_list_marker( litehtml::uint_ptr hdc, const litehtml::
|
|||
}
|
||||
}
|
||||
unlock_images_cache();*/
|
||||
} else
|
||||
{
|
||||
switch(marker.marker_type)
|
||||
{
|
||||
case litehtml::list_style_type_circle:
|
||||
{
|
||||
} else {
|
||||
switch (marker.marker_type) {
|
||||
case litehtml::list_style_type_circle: {
|
||||
draw_ellipse((cairo_t*)hdc, marker.pos.x, marker.pos.y, marker.pos.width, marker.pos.height, marker.color, 1);
|
||||
}
|
||||
break;
|
||||
case litehtml::list_style_type_disc:
|
||||
{
|
||||
} break;
|
||||
case litehtml::list_style_type_disc: {
|
||||
fill_ellipse((cairo_t*)hdc, marker.pos.x, marker.pos.y, marker.pos.width, marker.pos.height, marker.color);
|
||||
}
|
||||
break;
|
||||
} break;
|
||||
case litehtml::list_style_type_square:
|
||||
if(hdc)
|
||||
{
|
||||
if (hdc) {
|
||||
auto* cr = (cairo_t*)hdc;
|
||||
cairo_save(cr);
|
||||
|
||||
|
@ -244,52 +228,41 @@ void container_linux::draw_list_marker( litehtml::uint_ptr hdc, const litehtml::
|
|||
}
|
||||
}
|
||||
|
||||
void container_linux::load_image( const litehtml::tchar_t* src, const litehtml::tchar_t* baseurl, bool redraw_on_ready )
|
||||
{
|
||||
void container_linux::load_image(const litehtml::tchar_t* src, const litehtml::tchar_t* baseurl, bool redraw_on_ready) {
|
||||
litehtml::tstring url;
|
||||
make_url(src, baseurl, url);
|
||||
if(m_images.find(url) == m_images.end())
|
||||
{
|
||||
try
|
||||
{
|
||||
if (m_images.find(url) == m_images.end()) {
|
||||
try {
|
||||
Glib::RefPtr<Gdk::Pixbuf> img = get_image(url.c_str(), true);
|
||||
if(img)
|
||||
{
|
||||
if (img) {
|
||||
m_images[url.c_str()] = img;
|
||||
}
|
||||
} catch(...)
|
||||
{
|
||||
} catch (...) {
|
||||
m_images[url.c_str()] = Glib::RefPtr<Gdk::Pixbuf>(nullptr);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void container_linux::get_image_size( const litehtml::tchar_t* src, const litehtml::tchar_t* baseurl, litehtml::size& sz )
|
||||
{
|
||||
void container_linux::get_image_size(const litehtml::tchar_t* src, const litehtml::tchar_t* baseurl, litehtml::size& sz) {
|
||||
litehtml::tstring url;
|
||||
make_url(src, baseurl, url);
|
||||
|
||||
auto img = m_images.find(url);
|
||||
if(img != m_images.end())
|
||||
{
|
||||
if(img->second)
|
||||
{
|
||||
if (img != m_images.end()) {
|
||||
if (img->second) {
|
||||
sz.width = img->second->get_width();
|
||||
sz.height = img->second->get_height();
|
||||
} else
|
||||
{
|
||||
} else {
|
||||
sz.width = 0;
|
||||
sz.height = 0;
|
||||
}
|
||||
} else
|
||||
{
|
||||
} else {
|
||||
sz.width = 0;
|
||||
sz.height = 0;
|
||||
}
|
||||
}
|
||||
|
||||
void container_linux::draw_background( litehtml::uint_ptr hdc, const litehtml::background_paint& bg )
|
||||
{
|
||||
void container_linux::draw_background(litehtml::uint_ptr hdc, const litehtml::background_paint& bg) {
|
||||
auto* cr = (cairo_t*)hdc;
|
||||
cairo_save(cr);
|
||||
apply_clip(cr);
|
||||
|
@ -300,8 +273,7 @@ void container_linux::draw_background( litehtml::uint_ptr hdc, const litehtml::b
|
|||
cairo_rectangle(cr, bg.clip_box.x, bg.clip_box.y, bg.clip_box.width, bg.clip_box.height);
|
||||
cairo_clip(cr);
|
||||
|
||||
if(bg.color.alpha)
|
||||
{
|
||||
if (bg.color.alpha) {
|
||||
set_color(cr, bg.color);
|
||||
cairo_paint(cr);
|
||||
}
|
||||
|
@ -311,13 +283,11 @@ void container_linux::draw_background( litehtml::uint_ptr hdc, const litehtml::b
|
|||
|
||||
// lock_images_cache();
|
||||
auto img_i = m_images.find(url);
|
||||
if(img_i != m_images.end() && img_i->second)
|
||||
{
|
||||
if (img_i != m_images.end() && img_i->second) {
|
||||
Glib::RefPtr<Gdk::Pixbuf> bgbmp = img_i->second;
|
||||
|
||||
Glib::RefPtr<Gdk::Pixbuf> new_img;
|
||||
if(bg.image_size.width != bgbmp->get_width() || bg.image_size.height != bgbmp->get_height())
|
||||
{
|
||||
if (bg.image_size.width != bgbmp->get_width() || bg.image_size.height != bgbmp->get_height()) {
|
||||
new_img = bgbmp->scale_simple(bg.image_size.width, bg.image_size.height, Gdk::INTERP_BILINEAR);
|
||||
bgbmp = new_img;
|
||||
}
|
||||
|
@ -330,8 +300,7 @@ void container_linux::draw_background( litehtml::uint_ptr hdc, const litehtml::b
|
|||
cairo_pattern_set_extend(pattern, CAIRO_EXTEND_REPEAT);
|
||||
cairo_pattern_set_matrix(pattern, &flib_m);
|
||||
|
||||
switch(bg.repeat)
|
||||
{
|
||||
switch (bg.repeat) {
|
||||
case litehtml::background_repeat_no_repeat:
|
||||
draw_pixbuf(cr, bgbmp, bg.position_x, bg.position_y, bgbmp->get_width(), bgbmp->get_height());
|
||||
break;
|
||||
|
@ -357,45 +326,34 @@ void container_linux::draw_background( litehtml::uint_ptr hdc, const litehtml::b
|
|||
|
||||
cairo_pattern_destroy(pattern);
|
||||
cairo_surface_destroy(img);
|
||||
|
||||
}
|
||||
// unlock_images_cache();
|
||||
cairo_restore(cr);
|
||||
}
|
||||
|
||||
void container_linux::make_url(const litehtml::tchar_t* url, const litehtml::tchar_t* basepath, litehtml::tstring& out)
|
||||
{
|
||||
out = url;
|
||||
}
|
||||
|
||||
void container_linux::add_path_arc(cairo_t* cr, double x, double y, double rx, double ry, double a1, double a2, bool neg)
|
||||
{
|
||||
if(rx > 0 && ry > 0)
|
||||
{
|
||||
void container_linux::make_url(const litehtml::tchar_t* url, const litehtml::tchar_t* basepath, litehtml::tstring& out) { out = url; }
|
||||
|
||||
void container_linux::add_path_arc(cairo_t* cr, double x, double y, double rx, double ry, double a1, double a2, bool neg) {
|
||||
if (rx > 0 && ry > 0) {
|
||||
cairo_save(cr);
|
||||
|
||||
cairo_translate(cr, x, y);
|
||||
cairo_scale(cr, 1, ry / rx);
|
||||
cairo_translate(cr, -x, -y);
|
||||
|
||||
if(neg)
|
||||
{
|
||||
if (neg) {
|
||||
cairo_arc_negative(cr, x, y, rx, a1, a2);
|
||||
} else
|
||||
{
|
||||
} else {
|
||||
cairo_arc(cr, x, y, rx, a1, a2);
|
||||
}
|
||||
|
||||
cairo_restore(cr);
|
||||
} else
|
||||
{
|
||||
} else {
|
||||
cairo_move_to(cr, x, y);
|
||||
}
|
||||
}
|
||||
|
||||
void container_linux::draw_borders(litehtml::uint_ptr hdc, const litehtml::borders& borders, const litehtml::position& draw_pos, bool root)
|
||||
{
|
||||
void container_linux::draw_borders(litehtml::uint_ptr hdc, const litehtml::borders& borders, const litehtml::position& draw_pos, bool root) {
|
||||
auto* cr = (cairo_t*)hdc;
|
||||
cairo_save(cr);
|
||||
apply_clip(cr);
|
||||
|
@ -407,81 +365,48 @@ void container_linux::draw_borders(litehtml::uint_ptr hdc, const litehtml::borde
|
|||
int bdr_left = 0;
|
||||
int bdr_right = 0;
|
||||
|
||||
if(borders.top.width != 0 && borders.top.style > litehtml::border_style_hidden)
|
||||
{
|
||||
if (borders.top.width != 0 && borders.top.style > litehtml::border_style_hidden) {
|
||||
bdr_top = (int)borders.top.width;
|
||||
}
|
||||
if(borders.bottom.width != 0 && borders.bottom.style > litehtml::border_style_hidden)
|
||||
{
|
||||
if (borders.bottom.width != 0 && borders.bottom.style > litehtml::border_style_hidden) {
|
||||
bdr_bottom = (int)borders.bottom.width;
|
||||
}
|
||||
if(borders.left.width != 0 && borders.left.style > litehtml::border_style_hidden)
|
||||
{
|
||||
if (borders.left.width != 0 && borders.left.style > litehtml::border_style_hidden) {
|
||||
bdr_left = (int)borders.left.width;
|
||||
}
|
||||
if(borders.right.width != 0 && borders.right.style > litehtml::border_style_hidden)
|
||||
{
|
||||
if (borders.right.width != 0 && borders.right.style > litehtml::border_style_hidden) {
|
||||
bdr_right = (int)borders.right.width;
|
||||
}
|
||||
|
||||
// draw right border
|
||||
if(bdr_right)
|
||||
{
|
||||
if (bdr_right) {
|
||||
set_color(cr, borders.right.color);
|
||||
|
||||
double r_top = borders.radius.top_right_x;
|
||||
double r_bottom = borders.radius.bottom_right_x;
|
||||
|
||||
if(r_top)
|
||||
{
|
||||
if (r_top) {
|
||||
double end_angle = 2 * M_PI;
|
||||
double start_angle = end_angle - M_PI / 2.0 / ((double)bdr_top / (double)bdr_right + 1);
|
||||
|
||||
add_path_arc(cr,
|
||||
draw_pos.right() - r_top,
|
||||
draw_pos.top() + r_top,
|
||||
r_top - bdr_right,
|
||||
r_top - bdr_right + (bdr_right - bdr_top),
|
||||
end_angle,
|
||||
start_angle, true);
|
||||
add_path_arc(cr, draw_pos.right() - r_top, draw_pos.top() + r_top, r_top - bdr_right, r_top - bdr_right + (bdr_right - bdr_top), end_angle, start_angle, true);
|
||||
|
||||
add_path_arc(cr,
|
||||
draw_pos.right() - r_top,
|
||||
draw_pos.top() + r_top,
|
||||
r_top,
|
||||
r_top,
|
||||
start_angle,
|
||||
end_angle, false);
|
||||
} else
|
||||
{
|
||||
add_path_arc(cr, draw_pos.right() - r_top, draw_pos.top() + r_top, r_top, r_top, start_angle, end_angle, false);
|
||||
} else {
|
||||
cairo_move_to(cr, draw_pos.right() - bdr_right, draw_pos.top() + bdr_top);
|
||||
cairo_line_to(cr, draw_pos.right(), draw_pos.top());
|
||||
}
|
||||
|
||||
if(r_bottom)
|
||||
{
|
||||
if (r_bottom) {
|
||||
cairo_line_to(cr, draw_pos.right(), draw_pos.bottom() - r_bottom);
|
||||
|
||||
double start_angle = 0;
|
||||
double end_angle = start_angle + M_PI / 2.0 / ((double)bdr_bottom / (double)bdr_right + 1);
|
||||
|
||||
add_path_arc(cr,
|
||||
draw_pos.right() - r_bottom,
|
||||
draw_pos.bottom() - r_bottom,
|
||||
r_bottom,
|
||||
r_bottom,
|
||||
start_angle,
|
||||
end_angle, false);
|
||||
add_path_arc(cr, draw_pos.right() - r_bottom, draw_pos.bottom() - r_bottom, r_bottom, r_bottom, start_angle, end_angle, false);
|
||||
|
||||
add_path_arc(cr,
|
||||
draw_pos.right() - r_bottom,
|
||||
draw_pos.bottom() - r_bottom,
|
||||
r_bottom - bdr_right,
|
||||
r_bottom - bdr_right + (bdr_right - bdr_bottom),
|
||||
end_angle,
|
||||
start_angle, true);
|
||||
} else
|
||||
{
|
||||
add_path_arc(cr, draw_pos.right() - r_bottom, draw_pos.bottom() - r_bottom, r_bottom - bdr_right, r_bottom - bdr_right + (bdr_right - bdr_bottom), end_angle, start_angle, true);
|
||||
} else {
|
||||
cairo_line_to(cr, draw_pos.right(), draw_pos.bottom());
|
||||
cairo_line_to(cr, draw_pos.right() - bdr_right, draw_pos.bottom() - bdr_bottom);
|
||||
}
|
||||
|
@ -490,63 +415,34 @@ void container_linux::draw_borders(litehtml::uint_ptr hdc, const litehtml::borde
|
|||
}
|
||||
|
||||
// draw bottom border
|
||||
if(bdr_bottom)
|
||||
{
|
||||
if (bdr_bottom) {
|
||||
set_color(cr, borders.bottom.color);
|
||||
|
||||
double r_left = borders.radius.bottom_left_x;
|
||||
double r_right = borders.radius.bottom_right_x;
|
||||
|
||||
if(r_left)
|
||||
{
|
||||
if (r_left) {
|
||||
double start_angle = M_PI / 2.0;
|
||||
double end_angle = start_angle + M_PI / 2.0 / ((double)bdr_left / (double)bdr_bottom + 1);
|
||||
|
||||
add_path_arc(cr,
|
||||
draw_pos.left() + r_left,
|
||||
draw_pos.bottom() - r_left,
|
||||
r_left - bdr_bottom + (bdr_bottom - bdr_left),
|
||||
r_left - bdr_bottom,
|
||||
start_angle,
|
||||
end_angle, false);
|
||||
add_path_arc(cr, draw_pos.left() + r_left, draw_pos.bottom() - r_left, r_left - bdr_bottom + (bdr_bottom - bdr_left), r_left - bdr_bottom, start_angle, end_angle, false);
|
||||
|
||||
add_path_arc(cr,
|
||||
draw_pos.left() + r_left,
|
||||
draw_pos.bottom() - r_left,
|
||||
r_left,
|
||||
r_left,
|
||||
end_angle,
|
||||
start_angle, true);
|
||||
} else
|
||||
{
|
||||
add_path_arc(cr, draw_pos.left() + r_left, draw_pos.bottom() - r_left, r_left, r_left, end_angle, start_angle, true);
|
||||
} else {
|
||||
cairo_move_to(cr, draw_pos.left(), draw_pos.bottom());
|
||||
cairo_line_to(cr, draw_pos.left() + bdr_left, draw_pos.bottom() - bdr_bottom);
|
||||
}
|
||||
|
||||
if(r_right)
|
||||
{
|
||||
if (r_right) {
|
||||
cairo_line_to(cr, draw_pos.right() - r_right, draw_pos.bottom());
|
||||
|
||||
double end_angle = M_PI / 2.0;
|
||||
double start_angle = end_angle - M_PI / 2.0 / ((double)bdr_right / (double)bdr_bottom + 1);
|
||||
|
||||
add_path_arc(cr,
|
||||
draw_pos.right() - r_right,
|
||||
draw_pos.bottom() - r_right,
|
||||
r_right,
|
||||
r_right,
|
||||
end_angle,
|
||||
start_angle, true);
|
||||
add_path_arc(cr, draw_pos.right() - r_right, draw_pos.bottom() - r_right, r_right, r_right, end_angle, start_angle, true);
|
||||
|
||||
add_path_arc(cr,
|
||||
draw_pos.right() - r_right,
|
||||
draw_pos.bottom() - r_right,
|
||||
r_right - bdr_bottom + (bdr_bottom - bdr_right),
|
||||
r_right - bdr_bottom,
|
||||
start_angle,
|
||||
end_angle, false);
|
||||
} else
|
||||
{
|
||||
add_path_arc(cr, draw_pos.right() - r_right, draw_pos.bottom() - r_right, r_right - bdr_bottom + (bdr_bottom - bdr_right), r_right - bdr_bottom, start_angle, end_angle, false);
|
||||
} else {
|
||||
cairo_line_to(cr, draw_pos.right() - bdr_right, draw_pos.bottom() - bdr_bottom);
|
||||
cairo_line_to(cr, draw_pos.right(), draw_pos.bottom());
|
||||
}
|
||||
|
@ -555,63 +451,34 @@ void container_linux::draw_borders(litehtml::uint_ptr hdc, const litehtml::borde
|
|||
}
|
||||
|
||||
// draw top border
|
||||
if(bdr_top)
|
||||
{
|
||||
if (bdr_top) {
|
||||
set_color(cr, borders.top.color);
|
||||
|
||||
double r_left = borders.radius.top_left_x;
|
||||
double r_right = borders.radius.top_right_x;
|
||||
|
||||
if(r_left)
|
||||
{
|
||||
if (r_left) {
|
||||
double end_angle = M_PI * 3.0 / 2.0;
|
||||
double start_angle = end_angle - M_PI / 2.0 / ((double)bdr_left / (double)bdr_top + 1);
|
||||
|
||||
add_path_arc(cr,
|
||||
draw_pos.left() + r_left,
|
||||
draw_pos.top() + r_left,
|
||||
r_left,
|
||||
r_left,
|
||||
end_angle,
|
||||
start_angle, true);
|
||||
add_path_arc(cr, draw_pos.left() + r_left, draw_pos.top() + r_left, r_left, r_left, end_angle, start_angle, true);
|
||||
|
||||
add_path_arc(cr,
|
||||
draw_pos.left() + r_left,
|
||||
draw_pos.top() + r_left,
|
||||
r_left - bdr_top + (bdr_top - bdr_left),
|
||||
r_left - bdr_top,
|
||||
start_angle,
|
||||
end_angle, false);
|
||||
} else
|
||||
{
|
||||
add_path_arc(cr, draw_pos.left() + r_left, draw_pos.top() + r_left, r_left - bdr_top + (bdr_top - bdr_left), r_left - bdr_top, start_angle, end_angle, false);
|
||||
} else {
|
||||
cairo_move_to(cr, draw_pos.left(), draw_pos.top());
|
||||
cairo_line_to(cr, draw_pos.left() + bdr_left, draw_pos.top() + bdr_top);
|
||||
}
|
||||
|
||||
if(r_right)
|
||||
{
|
||||
if (r_right) {
|
||||
cairo_line_to(cr, draw_pos.right() - r_right, draw_pos.top() + bdr_top);
|
||||
|
||||
double start_angle = M_PI * 3.0 / 2.0;
|
||||
double end_angle = start_angle + M_PI / 2.0 / ((double)bdr_right / (double)bdr_top + 1);
|
||||
|
||||
add_path_arc(cr,
|
||||
draw_pos.right() - r_right,
|
||||
draw_pos.top() + r_right,
|
||||
r_right - bdr_top + (bdr_top - bdr_right),
|
||||
r_right - bdr_top,
|
||||
start_angle,
|
||||
end_angle, false);
|
||||
add_path_arc(cr, draw_pos.right() - r_right, draw_pos.top() + r_right, r_right - bdr_top + (bdr_top - bdr_right), r_right - bdr_top, start_angle, end_angle, false);
|
||||
|
||||
add_path_arc(cr,
|
||||
draw_pos.right() - r_right,
|
||||
draw_pos.top() + r_right,
|
||||
r_right,
|
||||
r_right,
|
||||
end_angle,
|
||||
start_angle, true);
|
||||
} else
|
||||
{
|
||||
add_path_arc(cr, draw_pos.right() - r_right, draw_pos.top() + r_right, r_right, r_right, end_angle, start_angle, true);
|
||||
} else {
|
||||
cairo_line_to(cr, draw_pos.right() - bdr_right, draw_pos.top() + bdr_top);
|
||||
cairo_line_to(cr, draw_pos.right(), draw_pos.top());
|
||||
}
|
||||
|
@ -620,63 +487,34 @@ void container_linux::draw_borders(litehtml::uint_ptr hdc, const litehtml::borde
|
|||
}
|
||||
|
||||
// draw left border
|
||||
if(bdr_left)
|
||||
{
|
||||
if (bdr_left) {
|
||||
set_color(cr, borders.left.color);
|
||||
|
||||
double r_top = borders.radius.top_left_x;
|
||||
double r_bottom = borders.radius.bottom_left_x;
|
||||
|
||||
if(r_top)
|
||||
{
|
||||
if (r_top) {
|
||||
double start_angle = M_PI;
|
||||
double end_angle = start_angle + M_PI / 2.0 / ((double)bdr_top / (double)bdr_left + 1);
|
||||
|
||||
add_path_arc(cr,
|
||||
draw_pos.left() + r_top,
|
||||
draw_pos.top() + r_top,
|
||||
r_top - bdr_left,
|
||||
r_top - bdr_left + (bdr_left - bdr_top),
|
||||
start_angle,
|
||||
end_angle, false);
|
||||
add_path_arc(cr, draw_pos.left() + r_top, draw_pos.top() + r_top, r_top - bdr_left, r_top - bdr_left + (bdr_left - bdr_top), start_angle, end_angle, false);
|
||||
|
||||
add_path_arc(cr,
|
||||
draw_pos.left() + r_top,
|
||||
draw_pos.top() + r_top,
|
||||
r_top,
|
||||
r_top,
|
||||
end_angle,
|
||||
start_angle, true);
|
||||
} else
|
||||
{
|
||||
add_path_arc(cr, draw_pos.left() + r_top, draw_pos.top() + r_top, r_top, r_top, end_angle, start_angle, true);
|
||||
} else {
|
||||
cairo_move_to(cr, draw_pos.left() + bdr_left, draw_pos.top() + bdr_top);
|
||||
cairo_line_to(cr, draw_pos.left(), draw_pos.top());
|
||||
}
|
||||
|
||||
if(r_bottom)
|
||||
{
|
||||
if (r_bottom) {
|
||||
cairo_line_to(cr, draw_pos.left(), draw_pos.bottom() - r_bottom);
|
||||
|
||||
double end_angle = M_PI;
|
||||
double start_angle = end_angle - M_PI / 2.0 / ((double)bdr_bottom / (double)bdr_left + 1);
|
||||
|
||||
add_path_arc(cr,
|
||||
draw_pos.left() + r_bottom,
|
||||
draw_pos.bottom() - r_bottom,
|
||||
r_bottom,
|
||||
r_bottom,
|
||||
end_angle,
|
||||
start_angle, true);
|
||||
add_path_arc(cr, draw_pos.left() + r_bottom, draw_pos.bottom() - r_bottom, r_bottom, r_bottom, end_angle, start_angle, true);
|
||||
|
||||
add_path_arc(cr,
|
||||
draw_pos.left() + r_bottom,
|
||||
draw_pos.bottom() - r_bottom,
|
||||
r_bottom - bdr_left,
|
||||
r_bottom - bdr_left + (bdr_left - bdr_bottom),
|
||||
start_angle,
|
||||
end_angle, false);
|
||||
} else
|
||||
{
|
||||
add_path_arc(cr, draw_pos.left() + r_bottom, draw_pos.bottom() - r_bottom, r_bottom - bdr_left, r_bottom - bdr_left + (bdr_left - bdr_bottom), start_angle, end_angle, false);
|
||||
} else {
|
||||
cairo_line_to(cr, draw_pos.left(), draw_pos.bottom());
|
||||
cairo_line_to(cr, draw_pos.left() + bdr_left, draw_pos.bottom() - bdr_bottom);
|
||||
}
|
||||
|
@ -686,48 +524,37 @@ void container_linux::draw_borders(litehtml::uint_ptr hdc, const litehtml::borde
|
|||
cairo_restore(cr);
|
||||
}
|
||||
|
||||
void container_linux::transform_text(litehtml::tstring& text, litehtml::text_transform tt)
|
||||
{
|
||||
void container_linux::transform_text(litehtml::tstring& text, litehtml::text_transform tt) {}
|
||||
|
||||
}
|
||||
|
||||
void container_linux::set_clip( const litehtml::position& pos, const litehtml::border_radiuses& bdr_radius, bool valid_x, bool valid_y )
|
||||
{
|
||||
void container_linux::set_clip(const litehtml::position& pos, const litehtml::border_radiuses& bdr_radius, bool valid_x, bool valid_y) {
|
||||
litehtml::position clip_pos = pos;
|
||||
litehtml::position client_pos;
|
||||
get_client_rect(client_pos);
|
||||
if(!valid_x)
|
||||
{
|
||||
if (!valid_x) {
|
||||
clip_pos.x = client_pos.x;
|
||||
clip_pos.width = client_pos.width;
|
||||
}
|
||||
if(!valid_y)
|
||||
{
|
||||
if (!valid_y) {
|
||||
clip_pos.y = client_pos.y;
|
||||
clip_pos.height = client_pos.height;
|
||||
}
|
||||
m_clips.emplace_back(clip_pos, bdr_radius);
|
||||
}
|
||||
|
||||
void container_linux::del_clip()
|
||||
{
|
||||
if(!m_clips.empty())
|
||||
{
|
||||
void container_linux::del_clip() {
|
||||
if (!m_clips.empty()) {
|
||||
m_clips.pop_back();
|
||||
}
|
||||
}
|
||||
|
||||
void container_linux::apply_clip( cairo_t* cr )
|
||||
{
|
||||
for(const auto& clip_box : m_clips)
|
||||
{
|
||||
void container_linux::apply_clip(cairo_t* cr) {
|
||||
for (const auto& clip_box : m_clips) {
|
||||
rounded_rectangle(cr, clip_box.box, clip_box.radius);
|
||||
cairo_clip(cr);
|
||||
}
|
||||
}
|
||||
|
||||
void container_linux::draw_ellipse( cairo_t* cr, int x, int y, int width, int height, const litehtml::web_color& color, int line_width )
|
||||
{
|
||||
void container_linux::draw_ellipse(cairo_t* cr, int x, int y, int width, int height, const litehtml::web_color& color, int line_width) {
|
||||
if (!cr || !width || !height) return;
|
||||
cairo_save(cr);
|
||||
|
||||
|
@ -746,8 +573,7 @@ void container_linux::draw_ellipse( cairo_t* cr, int x, int y, int width, int he
|
|||
cairo_restore(cr);
|
||||
}
|
||||
|
||||
void container_linux::fill_ellipse( cairo_t* cr, int x, int y, int width, int height, const litehtml::web_color& color )
|
||||
{
|
||||
void container_linux::fill_ellipse(cairo_t* cr, int x, int y, int width, int height, const litehtml::web_color& color) {
|
||||
if (!cr || !width || !height) return;
|
||||
cairo_save(cr);
|
||||
|
||||
|
@ -765,8 +591,7 @@ void container_linux::fill_ellipse( cairo_t* cr, int x, int y, int width, int he
|
|||
cairo_restore(cr);
|
||||
}
|
||||
|
||||
void container_linux::clear_images()
|
||||
{
|
||||
void container_linux::clear_images() {
|
||||
/* for(images_map::iterator i = m_images.begin(); i != m_images.end(); i++)
|
||||
{
|
||||
if(i->second)
|
||||
|
@ -778,53 +603,38 @@ void container_linux::clear_images()
|
|||
*/
|
||||
}
|
||||
|
||||
const litehtml::tchar_t* container_linux::get_default_font_name() const
|
||||
{
|
||||
return "Times New Roman";
|
||||
}
|
||||
const litehtml::tchar_t* container_linux::get_default_font_name() const { return "Times New Roman"; }
|
||||
|
||||
std::shared_ptr<litehtml::element> container_linux::create_element(const litehtml::tchar_t *tag_name,
|
||||
const litehtml::string_map &attributes,
|
||||
const std::shared_ptr<litehtml::document> &doc)
|
||||
{
|
||||
return nullptr;
|
||||
}
|
||||
std::shared_ptr<litehtml::element> container_linux::create_element(const litehtml::tchar_t* tag_name, const litehtml::string_map& attributes, const std::shared_ptr<litehtml::document>& doc) { return nullptr; }
|
||||
|
||||
void container_linux::rounded_rectangle( cairo_t* cr, const litehtml::position &pos, const litehtml::border_radiuses &radius )
|
||||
{
|
||||
void container_linux::rounded_rectangle(cairo_t* cr, const litehtml::position& pos, const litehtml::border_radiuses& radius) {
|
||||
cairo_new_path(cr);
|
||||
if(radius.top_left_x)
|
||||
{
|
||||
if (radius.top_left_x) {
|
||||
cairo_arc(cr, pos.left() + radius.top_left_x, pos.top() + radius.top_left_x, radius.top_left_x, M_PI, M_PI * 3.0 / 2.0);
|
||||
} else
|
||||
{
|
||||
} else {
|
||||
cairo_move_to(cr, pos.left(), pos.top());
|
||||
}
|
||||
|
||||
cairo_line_to(cr, pos.right() - radius.top_right_x, pos.top());
|
||||
|
||||
if(radius.top_right_x)
|
||||
{
|
||||
if (radius.top_right_x) {
|
||||
cairo_arc(cr, pos.right() - radius.top_right_x, pos.top() + radius.top_right_x, radius.top_right_x, M_PI * 3.0 / 2.0, 2.0 * M_PI);
|
||||
}
|
||||
|
||||
cairo_line_to(cr, pos.right(), pos.bottom() - radius.bottom_right_x);
|
||||
|
||||
if(radius.bottom_right_x)
|
||||
{
|
||||
if (radius.bottom_right_x) {
|
||||
cairo_arc(cr, pos.right() - radius.bottom_right_x, pos.bottom() - radius.bottom_right_x, radius.bottom_right_x, 0, M_PI / 2.0);
|
||||
}
|
||||
|
||||
cairo_line_to(cr, pos.left() - radius.bottom_left_x, pos.bottom());
|
||||
|
||||
if(radius.bottom_left_x)
|
||||
{
|
||||
if (radius.bottom_left_x) {
|
||||
cairo_arc(cr, pos.left() + radius.bottom_left_x, pos.bottom() - radius.bottom_left_x, radius.bottom_left_x, M_PI / 2.0, M_PI);
|
||||
}
|
||||
}
|
||||
|
||||
void container_linux::draw_pixbuf(cairo_t* cr, const Glib::RefPtr<Gdk::Pixbuf>& bmp, int x, int y, int cx, int cy)
|
||||
{
|
||||
void container_linux::draw_pixbuf(cairo_t* cr, const Glib::RefPtr<Gdk::Pixbuf>& bmp, int x, int y, int cx, int cy) {
|
||||
cairo_save(cr);
|
||||
|
||||
{
|
||||
|
@ -833,13 +643,11 @@ void container_linux::draw_pixbuf(cairo_t* cr, const Glib::RefPtr<Gdk::Pixbuf>&
|
|||
cairo_matrix_t flib_m;
|
||||
cairo_matrix_init(&flib_m, 1, 0, 0, -1, 0, 0);
|
||||
|
||||
if(cx != bmp->get_width() || cy != bmp->get_height())
|
||||
{
|
||||
if (cx != bmp->get_width() || cy != bmp->get_height()) {
|
||||
Glib::RefPtr<Gdk::Pixbuf> new_img = bmp->scale_simple(cx, cy, Gdk::INTERP_BILINEAR);
|
||||
Gdk::Cairo::set_source_pixbuf(crobj, new_img, x, y);
|
||||
crobj->paint();
|
||||
} else
|
||||
{
|
||||
} else {
|
||||
Gdk::Cairo::set_source_pixbuf(crobj, bmp, x, y);
|
||||
crobj->paint();
|
||||
}
|
||||
|
@ -848,15 +656,12 @@ void container_linux::draw_pixbuf(cairo_t* cr, const Glib::RefPtr<Gdk::Pixbuf>&
|
|||
cairo_restore(cr);
|
||||
}
|
||||
|
||||
cairo_surface_t* container_linux::surface_from_pixbuf(const Glib::RefPtr<Gdk::Pixbuf>& bmp)
|
||||
{
|
||||
cairo_surface_t* container_linux::surface_from_pixbuf(const Glib::RefPtr<Gdk::Pixbuf>& bmp) {
|
||||
cairo_surface_t* ret;
|
||||
|
||||
if(bmp->get_has_alpha())
|
||||
{
|
||||
if (bmp->get_has_alpha()) {
|
||||
ret = cairo_image_surface_create(CAIRO_FORMAT_ARGB32, bmp->get_width(), bmp->get_height());
|
||||
} else
|
||||
{
|
||||
} else {
|
||||
ret = cairo_image_surface_create(CAIRO_FORMAT_RGB24, bmp->get_width(), bmp->get_height());
|
||||
}
|
||||
|
||||
|
@ -868,8 +673,7 @@ cairo_surface_t* container_linux::surface_from_pixbuf(const Glib::RefPtr<Gdk::Pi
|
|||
return ret;
|
||||
}
|
||||
|
||||
void container_linux::get_media_features(litehtml::media_features& media) const
|
||||
{
|
||||
void container_linux::get_media_features(litehtml::media_features& media) const {
|
||||
litehtml::position client;
|
||||
get_client_rect(client);
|
||||
media.type = litehtml::media_type_screen;
|
||||
|
@ -883,13 +687,9 @@ void container_linux::get_media_features(litehtml::media_features& media) const
|
|||
media.resolution = 96;
|
||||
}
|
||||
|
||||
void container_linux::get_language(litehtml::tstring& language, litehtml::tstring& culture) const
|
||||
{
|
||||
void container_linux::get_language(litehtml::tstring& language, litehtml::tstring& culture) const {
|
||||
language = _t("en");
|
||||
culture = _t("");
|
||||
}
|
||||
|
||||
void container_linux::link(const std::shared_ptr<litehtml::document> &ptr, const litehtml::element::ptr& el)
|
||||
{
|
||||
|
||||
}
|
||||
void container_linux::link(const std::shared_ptr<litehtml::document>& ptr, const litehtml::element::ptr& el) {}
|
||||
|
|
|
@ -1,38 +1,34 @@
|
|||
#ifndef LH_CONTAINER_LINUX_H
|
||||
#define LH_CONTAINER_LINUX_H
|
||||
|
||||
#include "../../include/litehtml.h"
|
||||
#include <cairo.h>
|
||||
#include <gtkmm.h>
|
||||
#include <pango/pangocairo.h>
|
||||
|
||||
struct cairo_clip_box
|
||||
{
|
||||
#include "../../include/litehtml.h"
|
||||
|
||||
struct cairo_clip_box {
|
||||
typedef std::vector<cairo_clip_box> vector;
|
||||
litehtml::position box;
|
||||
litehtml::border_radiuses radius;
|
||||
|
||||
cairo_clip_box(const litehtml::position& vBox, const litehtml::border_radiuses& vRad)
|
||||
{
|
||||
cairo_clip_box(const litehtml::position& vBox, const litehtml::border_radiuses& vRad) {
|
||||
box = vBox;
|
||||
radius = vRad;
|
||||
}
|
||||
|
||||
cairo_clip_box(const cairo_clip_box& val)
|
||||
{
|
||||
cairo_clip_box(const cairo_clip_box& val) {
|
||||
box = val.box;
|
||||
radius = val.radius;
|
||||
}
|
||||
cairo_clip_box& operator=(const cairo_clip_box& val)
|
||||
{
|
||||
cairo_clip_box& operator=(const cairo_clip_box& val) {
|
||||
box = val.box;
|
||||
radius = val.radius;
|
||||
return *this;
|
||||
}
|
||||
};
|
||||
|
||||
struct cairo_font
|
||||
{
|
||||
struct cairo_font {
|
||||
PangoFontDescription* font;
|
||||
int size;
|
||||
bool underline;
|
||||
|
@ -45,8 +41,7 @@ struct cairo_font
|
|||
int strikethrough_position;
|
||||
};
|
||||
|
||||
class container_linux : public litehtml::document_container
|
||||
{
|
||||
class container_linux : public litehtml::document_container {
|
||||
typedef std::map<litehtml::tstring, Glib::RefPtr<Gdk::Pixbuf> > images_map;
|
||||
|
||||
protected:
|
||||
|
@ -54,6 +49,7 @@ protected:
|
|||
cairo_t* m_temp_cr;
|
||||
images_map m_images;
|
||||
cairo_clip_box::vector m_clips;
|
||||
|
||||
public:
|
||||
container_linux();
|
||||
virtual ~container_linux();
|
||||
|
@ -70,14 +66,11 @@ public:
|
|||
void draw_background(litehtml::uint_ptr hdc, const litehtml::background_paint& bg) override;
|
||||
void draw_borders(litehtml::uint_ptr hdc, const litehtml::borders& borders, const litehtml::position& draw_pos, bool root) override;
|
||||
void draw_list_marker(litehtml::uint_ptr hdc, const litehtml::list_marker& marker) override;
|
||||
std::shared_ptr<litehtml::element> create_element(const litehtml::tchar_t *tag_name,
|
||||
const litehtml::string_map &attributes,
|
||||
const std::shared_ptr<litehtml::document> &doc) override;
|
||||
std::shared_ptr<litehtml::element> create_element(const litehtml::tchar_t* tag_name, const litehtml::string_map& attributes, const std::shared_ptr<litehtml::document>& doc) override;
|
||||
void get_media_features(litehtml::media_features& media) const override;
|
||||
void get_language(litehtml::tstring& language, litehtml::tstring& culture) const override;
|
||||
void link(const std::shared_ptr<litehtml::document>& ptr, const litehtml::element::ptr& el) override;
|
||||
|
||||
|
||||
void transform_text(litehtml::tstring& text, litehtml::text_transform tt) override;
|
||||
void set_clip(const litehtml::position& pos, const litehtml::border_radiuses& bdr_radius, bool valid_x, bool valid_y) override;
|
||||
void del_clip() override;
|
||||
|
|
|
@ -2,8 +2,7 @@
|
|||
|
||||
#include "../../include/litehtml.h"
|
||||
|
||||
class container_test : public litehtml::document_container
|
||||
{
|
||||
class container_test : public litehtml::document_container {
|
||||
public:
|
||||
container_test();
|
||||
virtual ~container_test();
|
||||
|
@ -20,21 +19,17 @@ public:
|
|||
virtual void draw_background(litehtml::uint_ptr hdc, const litehtml::background_paint& bg) override;
|
||||
virtual void draw_borders(litehtml::uint_ptr hdc, const litehtml::borders& borders, const litehtml::position& draw_pos, bool root) override;
|
||||
virtual void draw_list_marker(litehtml::uint_ptr hdc, const litehtml::list_marker& marker) override;
|
||||
virtual std::shared_ptr<litehtml::element> create_element(const litehtml::tchar_t *tag_name,
|
||||
const litehtml::string_map &attributes,
|
||||
const std::shared_ptr<litehtml::document> &doc) override;
|
||||
virtual std::shared_ptr<litehtml::element> create_element(const litehtml::tchar_t* tag_name, const litehtml::string_map& attributes, const std::shared_ptr<litehtml::document>& doc) override;
|
||||
virtual void get_media_features(litehtml::media_features& media) const override;
|
||||
virtual void get_language(litehtml::tstring& language, litehtml::tstring& culture) const override;
|
||||
virtual void link(const std::shared_ptr<litehtml::document>& ptr, const litehtml::element::ptr& el) override;
|
||||
|
||||
|
||||
virtual void transform_text(litehtml::tstring& text, litehtml::text_transform tt) override;
|
||||
virtual void set_clip(const litehtml::position& pos, const litehtml::border_radiuses& bdr_radius, bool valid_x, bool valid_y) override;
|
||||
virtual void del_clip() override;
|
||||
|
||||
virtual void make_url(const litehtml::tchar_t* url, const litehtml::tchar_t* basepath, litehtml::tstring& out);
|
||||
|
||||
|
||||
virtual void set_caption(const litehtml::tchar_t* caption) override;
|
||||
virtual void set_base_url(const litehtml::tchar_t* base_url) override;
|
||||
virtual void on_anchor_click(const litehtml::tchar_t* url, const litehtml::element::ptr& el) override;
|
||||
|
|
|
@ -1,22 +1,16 @@
|
|||
#include <litehtml.h>
|
||||
#include "win32_container.h"
|
||||
|
||||
#include <litehtml.h>
|
||||
|
||||
litehtml::win32_container::win32_container()
|
||||
{
|
||||
m_hClipRgn = NULL;
|
||||
}
|
||||
litehtml::win32_container::win32_container() { m_hClipRgn = NULL; }
|
||||
|
||||
litehtml::win32_container::~win32_container()
|
||||
{
|
||||
if(m_hClipRgn)
|
||||
{
|
||||
litehtml::win32_container::~win32_container() {
|
||||
if (m_hClipRgn) {
|
||||
DeleteObject(m_hClipRgn);
|
||||
}
|
||||
}
|
||||
|
||||
litehtml::uint_ptr litehtml::win32_container::create_font( const wchar_t* faceName, int size, int weight, font_style italic, unsigned int decoration )
|
||||
{
|
||||
litehtml::uint_ptr litehtml::win32_container::create_font(const wchar_t* faceName, int size, int weight, font_style italic, unsigned int decoration) {
|
||||
litehtml::string_vector fonts;
|
||||
tokenize(faceName, fonts, L",");
|
||||
litehtml::trim(fonts[0]);
|
||||
|
@ -39,13 +33,9 @@ litehtml::uint_ptr litehtml::win32_container::create_font( const wchar_t* faceNa
|
|||
return (uint_ptr)hFont;
|
||||
}
|
||||
|
||||
void litehtml::win32_container::delete_font( uint_ptr hFont )
|
||||
{
|
||||
DeleteObject((HFONT) hFont);
|
||||
}
|
||||
void litehtml::win32_container::delete_font(uint_ptr hFont) { DeleteObject((HFONT)hFont); }
|
||||
|
||||
int litehtml::win32_container::line_height( uint_ptr hdc, uint_ptr hFont )
|
||||
{
|
||||
int litehtml::win32_container::line_height(uint_ptr hdc, uint_ptr hFont) {
|
||||
HFONT oldFont = (HFONT)SelectObject((HDC)hdc, (HFONT)hFont);
|
||||
TEXTMETRIC tm;
|
||||
GetTextMetrics((HDC)hdc, &tm);
|
||||
|
@ -53,8 +43,7 @@ int litehtml::win32_container::line_height( uint_ptr hdc, uint_ptr hFont )
|
|||
return (int)tm.tmHeight;
|
||||
}
|
||||
|
||||
int litehtml::win32_container::text_width( uint_ptr hdc, const wchar_t* text, uint_ptr hFont )
|
||||
{
|
||||
int litehtml::win32_container::text_width(uint_ptr hdc, const wchar_t* text, uint_ptr hFont) {
|
||||
HFONT oldFont = (HFONT)SelectObject((HDC)hdc, (HFONT)hFont);
|
||||
|
||||
SIZE sz = {0, 0};
|
||||
|
@ -66,8 +55,7 @@ int litehtml::win32_container::text_width( uint_ptr hdc, const wchar_t* text, ui
|
|||
return (int)sz.cx;
|
||||
}
|
||||
|
||||
void litehtml::win32_container::draw_text( uint_ptr hdc, const wchar_t* text, uint_ptr hFont, litehtml::web_color color, const litehtml::position& pos )
|
||||
{
|
||||
void litehtml::win32_container::draw_text(uint_ptr hdc, const wchar_t* text, uint_ptr hFont, litehtml::web_color color, const litehtml::position& pos) {
|
||||
apply_clip((HDC)hdc);
|
||||
|
||||
HFONT oldFont = (HFONT)SelectObject((HDC)hdc, (HFONT)hFont);
|
||||
|
@ -84,169 +72,130 @@ void litehtml::win32_container::draw_text( uint_ptr hdc, const wchar_t* text, ui
|
|||
release_clip((HDC)hdc);
|
||||
}
|
||||
|
||||
void litehtml::win32_container::fill_rect( uint_ptr hdc, const litehtml::position& pos, const litehtml::web_color color, const litehtml::css_border_radius& radius )
|
||||
{
|
||||
void litehtml::win32_container::fill_rect(uint_ptr hdc, const litehtml::position& pos, const litehtml::web_color color, const litehtml::css_border_radius& radius) {
|
||||
apply_clip((HDC)hdc);
|
||||
fill_rect((HDC)hdc, pos.x, pos.y, pos.width, pos.height, color, radius);
|
||||
release_clip((HDC)hdc);
|
||||
}
|
||||
|
||||
litehtml::uint_ptr litehtml::win32_container::get_temp_dc()
|
||||
{
|
||||
return (litehtml::uint_ptr) GetDC(NULL);
|
||||
}
|
||||
litehtml::uint_ptr litehtml::win32_container::get_temp_dc() { return (litehtml::uint_ptr)GetDC(NULL); }
|
||||
|
||||
void litehtml::win32_container::release_temp_dc( uint_ptr hdc )
|
||||
{
|
||||
ReleaseDC(NULL, (HDC) hdc);
|
||||
}
|
||||
void litehtml::win32_container::release_temp_dc(uint_ptr hdc) { ReleaseDC(NULL, (HDC)hdc); }
|
||||
|
||||
int litehtml::win32_container::pt_to_px( int pt )
|
||||
{
|
||||
int litehtml::win32_container::pt_to_px(int pt) {
|
||||
HDC dc = GetDC(NULL);
|
||||
int ret = MulDiv(pt, GetDeviceCaps(dc, LOGPIXELSY), 72);
|
||||
ReleaseDC(NULL, dc);
|
||||
return ret;
|
||||
}
|
||||
|
||||
int litehtml::win32_container::get_text_base_line( uint_ptr hdc, uint_ptr hFont )
|
||||
{
|
||||
int litehtml::win32_container::get_text_base_line(uint_ptr hdc, uint_ptr hFont) {
|
||||
HDC dc = (HDC)hdc;
|
||||
if(!dc)
|
||||
{
|
||||
if (!dc) {
|
||||
dc = GetDC(NULL);
|
||||
}
|
||||
HFONT oldFont = (HFONT)SelectObject(dc, (HFONT)hFont);
|
||||
TEXTMETRIC tm;
|
||||
GetTextMetrics(dc, &tm);
|
||||
SelectObject(dc, oldFont);
|
||||
if(!hdc)
|
||||
{
|
||||
if (!hdc) {
|
||||
ReleaseDC(NULL, dc);
|
||||
}
|
||||
return (int)tm.tmDescent;
|
||||
}
|
||||
|
||||
void litehtml::win32_container::draw_list_marker(uint_ptr hdc, const litehtml::list_marker& marker)
|
||||
{
|
||||
void litehtml::win32_container::draw_list_marker(uint_ptr hdc, const litehtml::list_marker& marker) {
|
||||
apply_clip((HDC)hdc);
|
||||
|
||||
int top_margin = marker.pos.height / 3;
|
||||
if (top_margin < 4)
|
||||
top_margin = 0;
|
||||
if (top_margin < 4) top_margin = 0;
|
||||
|
||||
int draw_x = marker.pos.x;
|
||||
int draw_y = marker.pos.y + top_margin;
|
||||
int draw_width = marker.pos.height - top_margin * 2;
|
||||
int draw_height = marker.pos.height - top_margin * 2;
|
||||
|
||||
switch (marker.marker_type)
|
||||
{
|
||||
case list_style_type_circle:
|
||||
{
|
||||
switch (marker.marker_type) {
|
||||
case list_style_type_circle: {
|
||||
draw_ellipse((HDC)hdc, draw_x, draw_y, draw_width, draw_height, marker.color, 1);
|
||||
}
|
||||
break;
|
||||
case list_style_type_disc:
|
||||
{
|
||||
} break;
|
||||
case list_style_type_disc: {
|
||||
fill_ellipse((HDC)hdc, draw_x, draw_y, draw_width, draw_height, marker.color);
|
||||
}
|
||||
break;
|
||||
case list_style_type_square:
|
||||
{
|
||||
} break;
|
||||
case list_style_type_square: {
|
||||
fill_rect((HDC)hdc, draw_x, draw_y, draw_width, draw_height, marker.color, css_border_radius());
|
||||
}
|
||||
break;
|
||||
} break;
|
||||
}
|
||||
release_clip((HDC)hdc);
|
||||
}
|
||||
|
||||
void litehtml::win32_container::load_image( const wchar_t* src, const wchar_t* baseurl, bool redraw_on_ready )
|
||||
{
|
||||
void litehtml::win32_container::load_image(const wchar_t* src, const wchar_t* baseurl, bool redraw_on_ready) {
|
||||
std::wstring url;
|
||||
make_url(src, baseurl, url);
|
||||
if(m_images.find(url.c_str()) == m_images.end())
|
||||
{
|
||||
if (m_images.find(url.c_str()) == m_images.end()) {
|
||||
uint_ptr img = get_image(url.c_str());
|
||||
if(img)
|
||||
{
|
||||
if (img) {
|
||||
m_images[url.c_str()] = img;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void litehtml::win32_container::get_image_size( const wchar_t* src, const wchar_t* baseurl, litehtml::size& sz )
|
||||
{
|
||||
void litehtml::win32_container::get_image_size(const wchar_t* src, const wchar_t* baseurl, litehtml::size& sz) {
|
||||
std::wstring url;
|
||||
make_url(src, baseurl, url);
|
||||
|
||||
images_map::iterator img = m_images.find(url.c_str());
|
||||
if(img != m_images.end())
|
||||
{
|
||||
if (img != m_images.end()) {
|
||||
get_img_size(img->second, sz);
|
||||
}
|
||||
}
|
||||
|
||||
void litehtml::win32_container::draw_image( uint_ptr hdc, const wchar_t* src, const wchar_t* baseurl, const litehtml::position& pos )
|
||||
{
|
||||
void litehtml::win32_container::draw_image(uint_ptr hdc, const wchar_t* src, const wchar_t* baseurl, const litehtml::position& pos) {
|
||||
apply_clip((HDC)hdc);
|
||||
|
||||
std::wstring url;
|
||||
make_url(src, baseurl, url);
|
||||
images_map::iterator img = m_images.find(url.c_str());
|
||||
if(img != m_images.end())
|
||||
{
|
||||
if (img != m_images.end()) {
|
||||
draw_img((HDC)hdc, img->second, pos);
|
||||
}
|
||||
|
||||
release_clip((HDC)hdc);
|
||||
}
|
||||
|
||||
void litehtml::win32_container::clear_images()
|
||||
{
|
||||
for(images_map::iterator i = m_images.begin(); i != m_images.end(); i++)
|
||||
{
|
||||
if(i->second)
|
||||
{
|
||||
void litehtml::win32_container::clear_images() {
|
||||
for (images_map::iterator i = m_images.begin(); i != m_images.end(); i++) {
|
||||
if (i->second) {
|
||||
free_image(i->second);
|
||||
}
|
||||
}
|
||||
m_images.clear();
|
||||
}
|
||||
|
||||
int litehtml::win32_container::get_default_font_size() const
|
||||
{
|
||||
return 16;
|
||||
}
|
||||
int litehtml::win32_container::get_default_font_size() const { return 16; }
|
||||
|
||||
void litehtml::win32_container::draw_background( uint_ptr hdc, const wchar_t* image, const wchar_t* baseurl, const litehtml::position& draw_pos, const litehtml::css_position& bg_pos, litehtml::background_repeat repeat, litehtml::background_attachment attachment )
|
||||
{
|
||||
void litehtml::win32_container::draw_background(uint_ptr hdc, const wchar_t* image, const wchar_t* baseurl, const litehtml::position& draw_pos, const litehtml::css_position& bg_pos, litehtml::background_repeat repeat, litehtml::background_attachment attachment) {
|
||||
apply_clip((HDC)hdc);
|
||||
|
||||
std::wstring url;
|
||||
make_url(image, baseurl, url);
|
||||
|
||||
images_map::iterator img = m_images.find(url.c_str());
|
||||
if(img != m_images.end())
|
||||
{
|
||||
if (img != m_images.end()) {
|
||||
litehtml::size img_sz;
|
||||
get_img_size(img->second, img_sz);
|
||||
|
||||
litehtml::position pos = draw_pos;
|
||||
|
||||
if(bg_pos.x.units() != css_units_percentage)
|
||||
{
|
||||
if (bg_pos.x.units() != css_units_percentage) {
|
||||
pos.x += (int)bg_pos.x.val();
|
||||
} else
|
||||
{
|
||||
} else {
|
||||
pos.x += (int)((float)(draw_pos.width - img_sz.width) * bg_pos.x.val() / 100.0);
|
||||
}
|
||||
|
||||
if(bg_pos.y.units() != css_units_percentage)
|
||||
{
|
||||
if (bg_pos.y.units() != css_units_percentage) {
|
||||
pos.y += (int)bg_pos.y.val();
|
||||
} else
|
||||
{
|
||||
} else {
|
||||
pos.y += (int)((float)(draw_pos.height - img_sz.height) * bg_pos.y.val() / 100.0);
|
||||
}
|
||||
|
||||
|
@ -256,56 +205,41 @@ void litehtml::win32_container::draw_background( uint_ptr hdc, const wchar_t* im
|
|||
release_clip((HDC)hdc);
|
||||
}
|
||||
|
||||
wchar_t litehtml::win32_container::toupper( const wchar_t c )
|
||||
{
|
||||
return (wchar_t) CharUpper((LPWSTR) c);
|
||||
}
|
||||
wchar_t litehtml::win32_container::toupper(const wchar_t c) { return (wchar_t)CharUpper((LPWSTR)c); }
|
||||
|
||||
wchar_t litehtml::win32_container::tolower( const wchar_t c )
|
||||
{
|
||||
return (wchar_t) CharLower((LPWSTR) c);
|
||||
}
|
||||
wchar_t litehtml::win32_container::tolower(const wchar_t c) { return (wchar_t)CharLower((LPWSTR)c); }
|
||||
|
||||
void litehtml::win32_container::set_clip( const litehtml::position& pos, bool valid_x, bool valid_y )
|
||||
{
|
||||
void litehtml::win32_container::set_clip(const litehtml::position& pos, bool valid_x, bool valid_y) {
|
||||
litehtml::position clip_pos = pos;
|
||||
litehtml::position client_pos;
|
||||
get_client_rect(client_pos);
|
||||
if(!valid_x)
|
||||
{
|
||||
if (!valid_x) {
|
||||
clip_pos.x = client_pos.x;
|
||||
clip_pos.width = client_pos.width;
|
||||
}
|
||||
if(!valid_y)
|
||||
{
|
||||
if (!valid_y) {
|
||||
clip_pos.y = client_pos.y;
|
||||
clip_pos.height = client_pos.height;
|
||||
}
|
||||
m_clips.push_back(clip_pos);
|
||||
}
|
||||
|
||||
void litehtml::win32_container::del_clip()
|
||||
{
|
||||
if(!m_clips.empty())
|
||||
{
|
||||
void litehtml::win32_container::del_clip() {
|
||||
if (!m_clips.empty()) {
|
||||
m_clips.pop_back();
|
||||
if(!m_clips.empty())
|
||||
{
|
||||
if (!m_clips.empty()) {
|
||||
litehtml::position clip_pos = m_clips.back();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void litehtml::win32_container::apply_clip(HDC hdc)
|
||||
{
|
||||
if(m_hClipRgn)
|
||||
{
|
||||
void litehtml::win32_container::apply_clip(HDC hdc) {
|
||||
if (m_hClipRgn) {
|
||||
DeleteObject(m_hClipRgn);
|
||||
m_hClipRgn = NULL;
|
||||
}
|
||||
|
||||
if(!m_clips.empty())
|
||||
{
|
||||
if (!m_clips.empty()) {
|
||||
POINT ptView = {0, 0};
|
||||
GetWindowOrgEx(hdc, &ptView);
|
||||
|
||||
|
@ -315,12 +249,10 @@ void litehtml::win32_container::apply_clip(HDC hdc)
|
|||
}
|
||||
}
|
||||
|
||||
void litehtml::win32_container::release_clip(HDC hdc)
|
||||
{
|
||||
void litehtml::win32_container::release_clip(HDC hdc) {
|
||||
SelectClipRgn(hdc, NULL);
|
||||
|
||||
if(m_hClipRgn)
|
||||
{
|
||||
if (m_hClipRgn) {
|
||||
DeleteObject(m_hClipRgn);
|
||||
m_hClipRgn = NULL;
|
||||
}
|
||||
|
|
|
@ -1,15 +1,12 @@
|
|||
#pragma once
|
||||
#include <Windows.h>
|
||||
|
||||
namespace litehtml
|
||||
{
|
||||
class win32_container : public document_container
|
||||
{
|
||||
namespace litehtml {
|
||||
class win32_container : public document_container {
|
||||
public:
|
||||
typedef std::map<std::wstring, litehtml::uint_ptr> images_map;
|
||||
|
||||
protected:
|
||||
|
||||
images_map m_images;
|
||||
litehtml::position::vector m_clips;
|
||||
HRGN m_hClipRgn;
|
||||
|
@ -33,13 +30,7 @@ namespace litehtml
|
|||
virtual void load_image(const wchar_t* src, const wchar_t* baseurl, bool redraw_on_ready);
|
||||
virtual void get_image_size(const wchar_t* src, const wchar_t* baseurl, litehtml::size& sz);
|
||||
virtual void draw_image(uint_ptr hdc, const wchar_t* src, const wchar_t* baseurl, const litehtml::position& pos);
|
||||
virtual void draw_background(uint_ptr hdc,
|
||||
const wchar_t* image,
|
||||
const wchar_t* baseurl,
|
||||
const litehtml::position& draw_pos,
|
||||
const litehtml::css_position& bg_pos,
|
||||
litehtml::background_repeat repeat,
|
||||
litehtml::background_attachment attachment);
|
||||
virtual void draw_background(uint_ptr hdc, const wchar_t* image, const wchar_t* baseurl, const litehtml::position& draw_pos, const litehtml::css_position& bg_pos, litehtml::background_repeat repeat, litehtml::background_attachment attachment);
|
||||
|
||||
virtual int get_default_font_size() const;
|
||||
virtual wchar_t toupper(const wchar_t c);
|
||||
|
@ -62,4 +53,4 @@ namespace litehtml
|
|||
virtual void draw_img(HDC hdc, litehtml::uint_ptr img, const litehtml::position& pos) = 0;
|
||||
virtual void draw_img_bg(HDC hdc, litehtml::uint_ptr img, const litehtml::position& draw_pos, const litehtml::position& pos, litehtml::background_repeat repeat, litehtml::background_attachment attachment) = 0;
|
||||
};
|
||||
}
|
||||
} // namespace litehtml
|
|
@ -1,10 +1,10 @@
|
|||
#ifndef LITEHTML_H
|
||||
#define LITEHTML_H
|
||||
|
||||
#include <litehtml/html.h>
|
||||
#include <litehtml/document.h>
|
||||
#include <litehtml/element.h>
|
||||
#include <litehtml/html.h>
|
||||
#include <litehtml/html_tag.h>
|
||||
#include <litehtml/stylesheet.h>
|
||||
#include <litehtml/element.h>
|
||||
|
||||
#endif // LITEHTML_H
|
||||
|
|
|
@ -1,16 +1,13 @@
|
|||
#ifndef LH_ATTRIBUTES_H
|
||||
#define LH_ATTRIBUTES_H
|
||||
|
||||
namespace litehtml
|
||||
{
|
||||
struct attr_color
|
||||
{
|
||||
namespace litehtml {
|
||||
struct attr_color {
|
||||
unsigned char rgbBlue;
|
||||
unsigned char rgbGreen;
|
||||
unsigned char rgbRed;
|
||||
unsigned char rgbAlpha;
|
||||
attr_color()
|
||||
{
|
||||
attr_color() {
|
||||
rgbAlpha = 255;
|
||||
rgbBlue = 0;
|
||||
rgbGreen = 0;
|
||||
|
@ -18,18 +15,16 @@ namespace litehtml
|
|||
}
|
||||
};
|
||||
|
||||
struct attr_border
|
||||
{
|
||||
struct attr_border {
|
||||
style_border border;
|
||||
int width;
|
||||
attr_color color;
|
||||
|
||||
attr_border()
|
||||
{
|
||||
attr_border() {
|
||||
border = borderNone;
|
||||
width = 0;
|
||||
}
|
||||
};
|
||||
}
|
||||
} // namespace litehtml
|
||||
|
||||
#endif // LH_ATTRIBUTES_H
|
||||
|
|
|
@ -1,17 +1,15 @@
|
|||
#ifndef LH_BACKGROUND_H
|
||||
#define LH_BACKGROUND_H
|
||||
|
||||
#include "types.h"
|
||||
#include "attributes.h"
|
||||
#include "borders.h"
|
||||
#include "css_length.h"
|
||||
#include "css_position.h"
|
||||
#include "types.h"
|
||||
#include "web_color.h"
|
||||
#include "borders.h"
|
||||
|
||||
namespace litehtml
|
||||
{
|
||||
class background
|
||||
{
|
||||
namespace litehtml {
|
||||
class background {
|
||||
public:
|
||||
tstring m_image;
|
||||
tstring m_baseurl;
|
||||
|
@ -31,8 +29,7 @@ namespace litehtml
|
|||
background& operator=(const background& val);
|
||||
};
|
||||
|
||||
class background_paint
|
||||
{
|
||||
class background_paint {
|
||||
public:
|
||||
tstring image;
|
||||
tstring baseurl;
|
||||
|
@ -47,12 +44,13 @@ namespace litehtml
|
|||
int position_x;
|
||||
int position_y;
|
||||
bool is_root;
|
||||
|
||||
public:
|
||||
background_paint();
|
||||
background_paint(const background_paint& val);
|
||||
background_paint& operator=(const background& val);
|
||||
};
|
||||
|
||||
}
|
||||
} // namespace litehtml
|
||||
|
||||
#endif // LH_BACKGROUND_H
|
||||
|
|
|
@ -4,28 +4,21 @@
|
|||
#include "css_length.h"
|
||||
#include "types.h"
|
||||
|
||||
namespace litehtml
|
||||
{
|
||||
struct css_border
|
||||
{
|
||||
namespace litehtml {
|
||||
struct css_border {
|
||||
css_length width;
|
||||
border_style style;
|
||||
web_color color;
|
||||
|
||||
css_border()
|
||||
{
|
||||
style = border_style_none;
|
||||
}
|
||||
css_border() { style = border_style_none; }
|
||||
|
||||
css_border(const css_border& val)
|
||||
{
|
||||
css_border(const css_border& val) {
|
||||
width = val.width;
|
||||
style = val.style;
|
||||
color = val.color;
|
||||
}
|
||||
|
||||
css_border& operator=(const css_border& val)
|
||||
{
|
||||
css_border& operator=(const css_border& val) {
|
||||
width = val.width;
|
||||
style = val.style;
|
||||
color = val.color;
|
||||
|
@ -33,37 +26,29 @@ namespace litehtml
|
|||
}
|
||||
};
|
||||
|
||||
struct border
|
||||
{
|
||||
struct border {
|
||||
int width;
|
||||
border_style style;
|
||||
web_color color;
|
||||
|
||||
border()
|
||||
{
|
||||
width = 0;
|
||||
}
|
||||
border(const border& val)
|
||||
{
|
||||
border() { width = 0; }
|
||||
border(const border& val) {
|
||||
width = val.width;
|
||||
style = val.style;
|
||||
color = val.color;
|
||||
}
|
||||
border(const css_border& val)
|
||||
{
|
||||
border(const css_border& val) {
|
||||
width = (int)val.width.val();
|
||||
style = val.style;
|
||||
color = val.color;
|
||||
}
|
||||
border& operator=(const border& val)
|
||||
{
|
||||
border& operator=(const border& val) {
|
||||
width = val.width;
|
||||
style = val.style;
|
||||
color = val.color;
|
||||
return *this;
|
||||
}
|
||||
border& operator=(const css_border& val)
|
||||
{
|
||||
border& operator=(const css_border& val) {
|
||||
width = (int)val.width.val();
|
||||
style = val.style;
|
||||
color = val.color;
|
||||
|
@ -71,8 +56,7 @@ namespace litehtml
|
|||
}
|
||||
};
|
||||
|
||||
struct border_radiuses
|
||||
{
|
||||
struct border_radiuses {
|
||||
int top_left_x;
|
||||
int top_left_y;
|
||||
|
||||
|
@ -85,8 +69,7 @@ namespace litehtml
|
|||
int bottom_left_x;
|
||||
int bottom_left_y;
|
||||
|
||||
border_radiuses()
|
||||
{
|
||||
border_radiuses() {
|
||||
top_left_x = 0;
|
||||
top_left_y = 0;
|
||||
top_right_x = 0;
|
||||
|
@ -96,8 +79,7 @@ namespace litehtml
|
|||
bottom_left_x = 0;
|
||||
bottom_left_y = 0;
|
||||
}
|
||||
border_radiuses(const border_radiuses& val)
|
||||
{
|
||||
border_radiuses(const border_radiuses& val) {
|
||||
top_left_x = val.top_left_x;
|
||||
top_left_y = val.top_left_y;
|
||||
top_right_x = val.top_right_x;
|
||||
|
@ -107,8 +89,7 @@ namespace litehtml
|
|||
bottom_left_x = val.bottom_left_x;
|
||||
bottom_left_y = val.bottom_left_y;
|
||||
}
|
||||
border_radiuses& operator = (const border_radiuses& val)
|
||||
{
|
||||
border_radiuses& operator=(const border_radiuses& val) {
|
||||
top_left_x = val.top_left_x;
|
||||
top_left_y = val.top_left_y;
|
||||
top_right_x = val.top_right_x;
|
||||
|
@ -119,8 +100,7 @@ namespace litehtml
|
|||
bottom_left_y = val.bottom_left_y;
|
||||
return *this;
|
||||
}
|
||||
void operator += (const margins& mg)
|
||||
{
|
||||
void operator+=(const margins& mg) {
|
||||
top_left_x += mg.left;
|
||||
top_left_y += mg.top;
|
||||
top_right_x += mg.right;
|
||||
|
@ -131,8 +111,7 @@ namespace litehtml
|
|||
bottom_left_y += mg.bottom;
|
||||
fix_values();
|
||||
}
|
||||
void operator -= (const margins& mg)
|
||||
{
|
||||
void operator-=(const margins& mg) {
|
||||
top_left_x -= mg.left;
|
||||
top_left_y -= mg.top;
|
||||
top_right_x -= mg.right;
|
||||
|
@ -143,8 +122,7 @@ namespace litehtml
|
|||
bottom_left_y -= mg.bottom;
|
||||
fix_values();
|
||||
}
|
||||
void fix_values()
|
||||
{
|
||||
void fix_values() {
|
||||
if (top_left_x < 0) top_left_x = 0;
|
||||
if (top_left_y < 0) top_left_y = 0;
|
||||
if (top_right_x < 0) top_right_x = 0;
|
||||
|
@ -156,8 +134,7 @@ namespace litehtml
|
|||
}
|
||||
};
|
||||
|
||||
struct css_border_radius
|
||||
{
|
||||
struct css_border_radius {
|
||||
css_length top_left_x;
|
||||
css_length top_left_y;
|
||||
|
||||
|
@ -170,13 +147,9 @@ namespace litehtml
|
|||
css_length bottom_left_x;
|
||||
css_length bottom_left_y;
|
||||
|
||||
css_border_radius()
|
||||
{
|
||||
css_border_radius() {}
|
||||
|
||||
}
|
||||
|
||||
css_border_radius(const css_border_radius& val)
|
||||
{
|
||||
css_border_radius(const css_border_radius& val) {
|
||||
top_left_x = val.top_left_x;
|
||||
top_left_y = val.top_left_y;
|
||||
top_right_x = val.top_right_x;
|
||||
|
@ -187,8 +160,7 @@ namespace litehtml
|
|||
bottom_right_y = val.bottom_right_y;
|
||||
}
|
||||
|
||||
css_border_radius& operator=(const css_border_radius& val)
|
||||
{
|
||||
css_border_radius& operator=(const css_border_radius& val) {
|
||||
top_left_x = val.top_left_x;
|
||||
top_left_y = val.top_left_y;
|
||||
top_right_x = val.top_right_x;
|
||||
|
@ -199,8 +171,7 @@ namespace litehtml
|
|||
bottom_right_y = val.bottom_right_y;
|
||||
return *this;
|
||||
}
|
||||
border_radiuses calc_percents(int width, int height)
|
||||
{
|
||||
border_radiuses calc_percents(int width, int height) {
|
||||
border_radiuses ret;
|
||||
ret.bottom_left_x = bottom_left_x.calc_percent(width);
|
||||
ret.bottom_left_y = bottom_left_y.calc_percent(height);
|
||||
|
@ -214,8 +185,7 @@ namespace litehtml
|
|||
}
|
||||
};
|
||||
|
||||
struct css_borders
|
||||
{
|
||||
struct css_borders {
|
||||
css_border left;
|
||||
css_border top;
|
||||
css_border right;
|
||||
|
@ -224,13 +194,9 @@ namespace litehtml
|
|||
|
||||
css_borders() = default;
|
||||
|
||||
bool is_visible() const
|
||||
{
|
||||
return left.width.val() != 0 || right.width.val() != 0 || top.width.val() != 0 || bottom.width.val() != 0;
|
||||
}
|
||||
bool is_visible() const { return left.width.val() != 0 || right.width.val() != 0 || top.width.val() != 0 || bottom.width.val() != 0; }
|
||||
|
||||
css_borders(const css_borders& val)
|
||||
{
|
||||
css_borders(const css_borders& val) {
|
||||
left = val.left;
|
||||
right = val.right;
|
||||
top = val.top;
|
||||
|
@ -238,8 +204,7 @@ namespace litehtml
|
|||
radius = val.radius;
|
||||
}
|
||||
|
||||
css_borders& operator=(const css_borders& val)
|
||||
{
|
||||
css_borders& operator=(const css_borders& val) {
|
||||
left = val.left;
|
||||
right = val.right;
|
||||
top = val.top;
|
||||
|
@ -249,8 +214,7 @@ namespace litehtml
|
|||
}
|
||||
};
|
||||
|
||||
struct borders
|
||||
{
|
||||
struct borders {
|
||||
border left;
|
||||
border top;
|
||||
border right;
|
||||
|
@ -259,8 +223,7 @@ namespace litehtml
|
|||
|
||||
borders() = default;
|
||||
|
||||
borders(const borders& val)
|
||||
{
|
||||
borders(const borders& val) {
|
||||
left = val.left;
|
||||
right = val.right;
|
||||
top = val.top;
|
||||
|
@ -268,21 +231,16 @@ namespace litehtml
|
|||
radius = val.radius;
|
||||
}
|
||||
|
||||
borders(const css_borders& val)
|
||||
{
|
||||
borders(const css_borders& val) {
|
||||
left = val.left;
|
||||
right = val.right;
|
||||
top = val.top;
|
||||
bottom = val.bottom;
|
||||
}
|
||||
|
||||
bool is_visible() const
|
||||
{
|
||||
return left.width != 0 || right.width != 0 || top.width != 0 || bottom.width != 0;
|
||||
}
|
||||
bool is_visible() const { return left.width != 0 || right.width != 0 || top.width != 0 || bottom.width != 0; }
|
||||
|
||||
borders& operator=(const borders& val)
|
||||
{
|
||||
borders& operator=(const borders& val) {
|
||||
left = val.left;
|
||||
right = val.right;
|
||||
top = val.top;
|
||||
|
@ -291,8 +249,7 @@ namespace litehtml
|
|||
return *this;
|
||||
}
|
||||
|
||||
borders& operator=(const css_borders& val)
|
||||
{
|
||||
borders& operator=(const css_borders& val) {
|
||||
left = val.left;
|
||||
right = val.right;
|
||||
top = val.top;
|
||||
|
@ -300,6 +257,6 @@ namespace litehtml
|
|||
return *this;
|
||||
}
|
||||
};
|
||||
}
|
||||
} // namespace litehtml
|
||||
|
||||
#endif // LH_BORDERS_H
|
||||
|
|
|
@ -1,28 +1,23 @@
|
|||
#ifndef LH_BOX_H
|
||||
#define LH_BOX_H
|
||||
|
||||
namespace litehtml
|
||||
{
|
||||
namespace litehtml {
|
||||
class html_tag;
|
||||
|
||||
enum box_type
|
||||
{
|
||||
box_block,
|
||||
box_line
|
||||
};
|
||||
enum box_type { box_block, box_line };
|
||||
|
||||
class box
|
||||
{
|
||||
class box {
|
||||
public:
|
||||
typedef std::unique_ptr<litehtml::box> ptr;
|
||||
typedef std::vector<box::ptr> vector;
|
||||
|
||||
protected:
|
||||
int m_box_top;
|
||||
int m_box_left;
|
||||
int m_box_right;
|
||||
|
||||
public:
|
||||
box(int top, int left, int right)
|
||||
{
|
||||
box(int top, int left, int right) {
|
||||
m_box_top = top;
|
||||
m_box_left = left;
|
||||
m_box_right = right;
|
||||
|
@ -51,14 +46,11 @@ namespace litehtml
|
|||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
|
||||
class block_box : public box
|
||||
{
|
||||
class block_box : public box {
|
||||
element::ptr m_element;
|
||||
|
||||
public:
|
||||
block_box(int top, int left, int right) : box(top, left, right)
|
||||
{
|
||||
m_element = nullptr;
|
||||
}
|
||||
block_box(int top, int left, int right) : box(top, left, right) { m_element = nullptr; }
|
||||
|
||||
litehtml::box_type get_type() const override;
|
||||
int height() const override;
|
||||
|
@ -77,8 +69,7 @@ namespace litehtml
|
|||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
|
||||
class line_box : public box
|
||||
{
|
||||
class line_box : public box {
|
||||
elements_vector m_items;
|
||||
int m_height;
|
||||
int m_width;
|
||||
|
@ -86,9 +77,9 @@ namespace litehtml
|
|||
font_metrics m_font_metrics;
|
||||
int m_baseline;
|
||||
text_align m_text_align;
|
||||
|
||||
public:
|
||||
line_box(int top, int left, int right, int line_height, font_metrics& fm, text_align align) : box(top, left, right)
|
||||
{
|
||||
line_box(int top, int left, int right, int line_height, font_metrics& fm, text_align align) : box(top, left, right) {
|
||||
m_height = 0;
|
||||
m_width = 0;
|
||||
m_font_metrics = fm;
|
||||
|
@ -115,6 +106,6 @@ namespace litehtml
|
|||
bool have_last_space() const;
|
||||
bool is_break_only() const;
|
||||
};
|
||||
}
|
||||
} // namespace litehtml
|
||||
|
||||
#endif // LH_BOX_H
|
||||
|
|
|
@ -3,18 +3,14 @@
|
|||
|
||||
#include "stylesheet.h"
|
||||
|
||||
namespace litehtml
|
||||
{
|
||||
class context
|
||||
{
|
||||
namespace litehtml {
|
||||
class context {
|
||||
litehtml::css m_master_css;
|
||||
|
||||
public:
|
||||
void load_master_stylesheet(const tchar_t* str);
|
||||
litehtml::css& master_css()
|
||||
{
|
||||
return m_master_css;
|
||||
}
|
||||
litehtml::css& master_css() { return m_master_css; }
|
||||
};
|
||||
}
|
||||
} // namespace litehtml
|
||||
|
||||
#endif // LH_CONTEXT_H
|
||||
|
|
|
@ -3,17 +3,15 @@
|
|||
|
||||
#include "types.h"
|
||||
|
||||
namespace litehtml
|
||||
{
|
||||
class css_length
|
||||
{
|
||||
union
|
||||
{
|
||||
namespace litehtml {
|
||||
class css_length {
|
||||
union {
|
||||
float m_value;
|
||||
int m_predef;
|
||||
};
|
||||
css_units m_units;
|
||||
bool m_is_predefined;
|
||||
|
||||
public:
|
||||
css_length();
|
||||
css_length(const css_length& val);
|
||||
|
@ -32,34 +30,27 @@ namespace litehtml
|
|||
|
||||
// css_length inlines
|
||||
|
||||
inline css_length::css_length()
|
||||
{
|
||||
inline css_length::css_length() {
|
||||
m_value = 0;
|
||||
m_predef = 0;
|
||||
m_units = css_units_none;
|
||||
m_is_predefined = false;
|
||||
}
|
||||
|
||||
inline css_length::css_length(const css_length& val)
|
||||
{
|
||||
if(val.is_predefined())
|
||||
{
|
||||
inline css_length::css_length(const css_length& val) {
|
||||
if (val.is_predefined()) {
|
||||
m_predef = val.m_predef;
|
||||
} else
|
||||
{
|
||||
} else {
|
||||
m_value = val.m_value;
|
||||
}
|
||||
m_units = val.m_units;
|
||||
m_is_predefined = val.m_is_predefined;
|
||||
}
|
||||
|
||||
inline css_length& css_length::operator=(const css_length& val)
|
||||
{
|
||||
if(val.is_predefined())
|
||||
{
|
||||
inline css_length& css_length::operator=(const css_length& val) {
|
||||
if (val.is_predefined()) {
|
||||
m_predef = val.m_predef;
|
||||
} else
|
||||
{
|
||||
} else {
|
||||
m_value = val.m_value;
|
||||
}
|
||||
m_units = val.m_units;
|
||||
|
@ -67,69 +58,52 @@ namespace litehtml
|
|||
return *this;
|
||||
}
|
||||
|
||||
inline css_length& css_length::operator=(float val)
|
||||
{
|
||||
inline css_length& css_length::operator=(float val) {
|
||||
m_value = val;
|
||||
m_units = css_units_px;
|
||||
m_is_predefined = false;
|
||||
return *this;
|
||||
}
|
||||
|
||||
inline bool css_length::is_predefined() const
|
||||
{
|
||||
return m_is_predefined;
|
||||
}
|
||||
inline bool css_length::is_predefined() const { return m_is_predefined; }
|
||||
|
||||
inline void css_length::predef(int val)
|
||||
{
|
||||
inline void css_length::predef(int val) {
|
||||
m_predef = val;
|
||||
m_is_predefined = true;
|
||||
}
|
||||
|
||||
inline int css_length::predef() const
|
||||
{
|
||||
if(m_is_predefined)
|
||||
{
|
||||
inline int css_length::predef() const {
|
||||
if (m_is_predefined) {
|
||||
return m_predef;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
inline void css_length::set_value(float val, css_units units)
|
||||
{
|
||||
inline void css_length::set_value(float val, css_units units) {
|
||||
m_value = val;
|
||||
m_is_predefined = false;
|
||||
m_units = units;
|
||||
}
|
||||
|
||||
inline float css_length::val() const
|
||||
{
|
||||
if(!m_is_predefined)
|
||||
{
|
||||
inline float css_length::val() const {
|
||||
if (!m_is_predefined) {
|
||||
return m_value;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
inline css_units css_length::units() const
|
||||
{
|
||||
return m_units;
|
||||
}
|
||||
inline css_units css_length::units() const { return m_units; }
|
||||
|
||||
inline int css_length::calc_percent(int width) const
|
||||
{
|
||||
if(!is_predefined())
|
||||
{
|
||||
if(units() == css_units_percentage)
|
||||
{
|
||||
inline int css_length::calc_percent(int width) const {
|
||||
if (!is_predefined()) {
|
||||
if (units() == css_units_percentage) {
|
||||
return (int)((double)width * (double)m_value / 100.0);
|
||||
} else
|
||||
{
|
||||
} else {
|
||||
return (int)val();
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
} // namespace litehtml
|
||||
|
||||
#endif // LH_CSS_LENGTH_H
|
||||
|
|
|
@ -3,10 +3,8 @@
|
|||
|
||||
#include "css_length.h"
|
||||
|
||||
namespace litehtml
|
||||
{
|
||||
struct css_margins
|
||||
{
|
||||
namespace litehtml {
|
||||
struct css_margins {
|
||||
css_length left;
|
||||
css_length right;
|
||||
css_length top;
|
||||
|
@ -14,16 +12,14 @@ namespace litehtml
|
|||
|
||||
css_margins() = default;
|
||||
|
||||
css_margins(const css_margins& val)
|
||||
{
|
||||
css_margins(const css_margins& val) {
|
||||
left = val.left;
|
||||
right = val.right;
|
||||
top = val.top;
|
||||
bottom = val.bottom;
|
||||
}
|
||||
|
||||
css_margins& operator=(const css_margins& val)
|
||||
{
|
||||
css_margins& operator=(const css_margins& val) {
|
||||
left = val.left;
|
||||
right = val.right;
|
||||
top = val.top;
|
||||
|
@ -31,6 +27,6 @@ namespace litehtml
|
|||
return *this;
|
||||
}
|
||||
};
|
||||
}
|
||||
} // namespace litehtml
|
||||
|
||||
#endif // LH_CSS_MARGINS_H
|
||||
|
|
|
@ -3,10 +3,8 @@
|
|||
|
||||
#include "css_length.h"
|
||||
|
||||
namespace litehtml
|
||||
{
|
||||
struct css_offsets
|
||||
{
|
||||
namespace litehtml {
|
||||
struct css_offsets {
|
||||
css_length left;
|
||||
css_length top;
|
||||
css_length right;
|
||||
|
@ -14,16 +12,14 @@ namespace litehtml
|
|||
|
||||
css_offsets() = default;
|
||||
|
||||
css_offsets(const css_offsets& val)
|
||||
{
|
||||
css_offsets(const css_offsets& val) {
|
||||
left = val.left;
|
||||
top = val.top;
|
||||
right = val.right;
|
||||
bottom = val.bottom;
|
||||
}
|
||||
|
||||
css_offsets& operator=(const css_offsets& val)
|
||||
{
|
||||
css_offsets& operator=(const css_offsets& val) {
|
||||
left = val.left;
|
||||
top = val.top;
|
||||
right = val.right;
|
||||
|
@ -31,6 +27,6 @@ namespace litehtml
|
|||
return *this;
|
||||
}
|
||||
};
|
||||
}
|
||||
} // namespace litehtml
|
||||
|
||||
#endif // LH_CSS_OFFSETS_H
|
||||
|
|
|
@ -3,10 +3,8 @@
|
|||
|
||||
#include "css_length.h"
|
||||
|
||||
namespace litehtml
|
||||
{
|
||||
struct css_position
|
||||
{
|
||||
namespace litehtml {
|
||||
struct css_position {
|
||||
css_length x;
|
||||
css_length y;
|
||||
css_length width;
|
||||
|
@ -14,16 +12,14 @@ namespace litehtml
|
|||
|
||||
css_position() = default;
|
||||
|
||||
css_position(const css_position& val)
|
||||
{
|
||||
css_position(const css_position& val) {
|
||||
x = val.x;
|
||||
y = val.y;
|
||||
width = val.width;
|
||||
height = val.height;
|
||||
}
|
||||
|
||||
css_position& operator=(const css_position& val)
|
||||
{
|
||||
css_position& operator=(const css_position& val) {
|
||||
x = val.x;
|
||||
y = val.y;
|
||||
width = val.width;
|
||||
|
@ -31,6 +27,6 @@ namespace litehtml
|
|||
return *this;
|
||||
}
|
||||
};
|
||||
}
|
||||
} // namespace litehtml
|
||||
|
||||
#endif // LH_CSS_POSITION_H
|
||||
|
|
|
@ -1,85 +1,65 @@
|
|||
#ifndef LH_CSS_SELECTOR_H
|
||||
#define LH_CSS_SELECTOR_H
|
||||
|
||||
#include "style.h"
|
||||
#include "media_query.h"
|
||||
#include "style.h"
|
||||
|
||||
namespace litehtml
|
||||
{
|
||||
namespace litehtml {
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
|
||||
struct selector_specificity
|
||||
{
|
||||
struct selector_specificity {
|
||||
int a;
|
||||
int b;
|
||||
int c;
|
||||
int d;
|
||||
|
||||
explicit selector_specificity(int va = 0, int vb = 0, int vc = 0, int vd = 0)
|
||||
{
|
||||
explicit selector_specificity(int va = 0, int vb = 0, int vc = 0, int vd = 0) {
|
||||
a = va;
|
||||
b = vb;
|
||||
c = vc;
|
||||
d = vd;
|
||||
}
|
||||
|
||||
void operator += (const selector_specificity& val)
|
||||
{
|
||||
void operator+=(const selector_specificity& val) {
|
||||
a += val.a;
|
||||
b += val.b;
|
||||
c += val.c;
|
||||
d += val.d;
|
||||
}
|
||||
|
||||
bool operator==(const selector_specificity& val) const
|
||||
{
|
||||
if(a == val.a && b == val.b && c == val.c && d == val.d)
|
||||
{
|
||||
bool operator==(const selector_specificity& val) const {
|
||||
if (a == val.a && b == val.b && c == val.c && d == val.d) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
bool operator!=(const selector_specificity& val) const
|
||||
{
|
||||
if(a != val.a || b != val.b || c != val.c || d != val.d)
|
||||
{
|
||||
bool operator!=(const selector_specificity& val) const {
|
||||
if (a != val.a || b != val.b || c != val.c || d != val.d) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
bool operator > (const selector_specificity& val) const
|
||||
{
|
||||
if(a > val.a)
|
||||
{
|
||||
bool operator>(const selector_specificity& val) const {
|
||||
if (a > val.a) {
|
||||
return true;
|
||||
} else if(a < val.a)
|
||||
{
|
||||
} else if (a < val.a) {
|
||||
return false;
|
||||
} else
|
||||
{
|
||||
if(b > val.b)
|
||||
{
|
||||
} else {
|
||||
if (b > val.b) {
|
||||
return true;
|
||||
} else if(b < val.b)
|
||||
{
|
||||
} else if (b < val.b) {
|
||||
return false;
|
||||
} else
|
||||
{
|
||||
if(c > val.c)
|
||||
{
|
||||
} else {
|
||||
if (c > val.c) {
|
||||
return true;
|
||||
} else if(c < val.c)
|
||||
{
|
||||
} else if (c < val.c) {
|
||||
return false;
|
||||
} else
|
||||
{
|
||||
if(d > val.d)
|
||||
{
|
||||
} else {
|
||||
if (d > val.d) {
|
||||
return true;
|
||||
} else if(d < val.d)
|
||||
{
|
||||
} else if (d < val.d) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
@ -88,37 +68,30 @@ namespace litehtml
|
|||
return false;
|
||||
}
|
||||
|
||||
bool operator >= (const selector_specificity& val) const
|
||||
{
|
||||
bool operator>=(const selector_specificity& val) const {
|
||||
if ((*this) == val) return true;
|
||||
if ((*this) > val) return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
bool operator <= (const selector_specificity& val) const
|
||||
{
|
||||
if((*this) > val)
|
||||
{
|
||||
bool operator<=(const selector_specificity& val) const {
|
||||
if ((*this) > val) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
bool operator < (const selector_specificity& val) const
|
||||
{
|
||||
if((*this) <= val && (*this) != val)
|
||||
{
|
||||
bool operator<(const selector_specificity& val) const {
|
||||
if ((*this) <= val && (*this) != val) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
|
||||
enum attr_select_condition
|
||||
{
|
||||
enum attr_select_condition {
|
||||
select_exists,
|
||||
select_equal,
|
||||
select_contain_str,
|
||||
|
@ -130,8 +103,7 @@ namespace litehtml
|
|||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
|
||||
struct css_attribute_selector
|
||||
{
|
||||
struct css_attribute_selector {
|
||||
typedef std::vector<css_attribute_selector> vector;
|
||||
|
||||
tstring attribute;
|
||||
|
@ -139,41 +111,31 @@ namespace litehtml
|
|||
string_vector class_val;
|
||||
attr_select_condition condition;
|
||||
|
||||
css_attribute_selector()
|
||||
{
|
||||
condition = select_exists;
|
||||
}
|
||||
css_attribute_selector() { condition = select_exists; }
|
||||
};
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
|
||||
class css_element_selector
|
||||
{
|
||||
class css_element_selector {
|
||||
public:
|
||||
tstring m_tag;
|
||||
css_attribute_selector::vector m_attrs;
|
||||
public:
|
||||
|
||||
public:
|
||||
void parse(const tstring& txt);
|
||||
};
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
|
||||
enum css_combinator
|
||||
{
|
||||
combinator_descendant,
|
||||
combinator_child,
|
||||
combinator_adjacent_sibling,
|
||||
combinator_general_sibling
|
||||
};
|
||||
enum css_combinator { combinator_descendant, combinator_child, combinator_adjacent_sibling, combinator_general_sibling };
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
|
||||
class css_selector
|
||||
{
|
||||
class css_selector {
|
||||
public:
|
||||
typedef std::shared_ptr<css_selector> ptr;
|
||||
typedef std::vector<css_selector::ptr> vector;
|
||||
|
||||
public:
|
||||
selector_specificity m_specificity;
|
||||
css_element_selector m_right;
|
||||
|
@ -182,9 +144,9 @@ namespace litehtml
|
|||
style::ptr m_style;
|
||||
int m_order;
|
||||
media_query_list::ptr m_media_query;
|
||||
|
||||
public:
|
||||
explicit css_selector(const media_query_list::ptr& media)
|
||||
{
|
||||
explicit css_selector(const media_query_list::ptr& media) {
|
||||
m_media_query = media;
|
||||
m_combinator = combinator_descendant;
|
||||
m_order = 0;
|
||||
|
@ -192,14 +154,11 @@ namespace litehtml
|
|||
|
||||
~css_selector() = default;
|
||||
|
||||
css_selector(const css_selector& val)
|
||||
{
|
||||
css_selector(const css_selector& val) {
|
||||
m_right = val.m_right;
|
||||
if(val.m_left)
|
||||
{
|
||||
if (val.m_left) {
|
||||
m_left = std::make_shared<css_selector>(*val.m_left);
|
||||
} else
|
||||
{
|
||||
} else {
|
||||
m_left = nullptr;
|
||||
}
|
||||
m_combinator = val.m_combinator;
|
||||
|
@ -214,50 +173,36 @@ namespace litehtml
|
|||
void add_media_to_doc(document* doc) const;
|
||||
};
|
||||
|
||||
inline bool css_selector::is_media_valid() const
|
||||
{
|
||||
if(!m_media_query)
|
||||
{
|
||||
inline bool css_selector::is_media_valid() const {
|
||||
if (!m_media_query) {
|
||||
return true;
|
||||
}
|
||||
return m_media_query->is_used();
|
||||
}
|
||||
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
|
||||
inline bool operator > (const css_selector& v1, const css_selector& v2)
|
||||
{
|
||||
if(v1.m_specificity == v2.m_specificity)
|
||||
{
|
||||
inline bool operator>(const css_selector& v1, const css_selector& v2) {
|
||||
if (v1.m_specificity == v2.m_specificity) {
|
||||
return (v1.m_order > v2.m_order);
|
||||
}
|
||||
return (v1.m_specificity > v2.m_specificity);
|
||||
}
|
||||
|
||||
inline bool operator < (const css_selector& v1, const css_selector& v2)
|
||||
{
|
||||
if(v1.m_specificity == v2.m_specificity)
|
||||
{
|
||||
inline bool operator<(const css_selector& v1, const css_selector& v2) {
|
||||
if (v1.m_specificity == v2.m_specificity) {
|
||||
return (v1.m_order < v2.m_order);
|
||||
}
|
||||
return (v1.m_specificity < v2.m_specificity);
|
||||
}
|
||||
|
||||
inline bool operator >(const css_selector::ptr& v1, const css_selector::ptr& v2)
|
||||
{
|
||||
return (*v1 > *v2);
|
||||
}
|
||||
inline bool operator>(const css_selector::ptr& v1, const css_selector::ptr& v2) { return (*v1 > *v2); }
|
||||
|
||||
inline bool operator < (const css_selector::ptr& v1, const css_selector::ptr& v2)
|
||||
{
|
||||
return (*v1 < *v2);
|
||||
}
|
||||
inline bool operator<(const css_selector::ptr& v1, const css_selector::ptr& v2) { return (*v1 < *v2); }
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
|
||||
class used_selector
|
||||
{
|
||||
class used_selector {
|
||||
public:
|
||||
typedef std::unique_ptr<used_selector> ptr;
|
||||
typedef std::vector<used_selector::ptr> vector;
|
||||
|
@ -265,12 +210,11 @@ namespace litehtml
|
|||
css_selector::ptr m_selector;
|
||||
bool m_used;
|
||||
|
||||
used_selector(const css_selector::ptr& selector, bool used)
|
||||
{
|
||||
used_selector(const css_selector::ptr& selector, bool used) {
|
||||
m_used = used;
|
||||
m_selector = selector;
|
||||
}
|
||||
};
|
||||
}
|
||||
} // namespace litehtml
|
||||
|
||||
#endif // LH_CSS_SELECTOR_H
|
||||
|
|
|
@ -1,14 +1,12 @@
|
|||
#ifndef LH_DOCUMENT_H
|
||||
#define LH_DOCUMENT_H
|
||||
|
||||
#include "context.h"
|
||||
#include "style.h"
|
||||
#include "types.h"
|
||||
#include "context.h"
|
||||
|
||||
namespace litehtml
|
||||
{
|
||||
struct css_text
|
||||
{
|
||||
namespace litehtml {
|
||||
struct css_text {
|
||||
typedef std::vector<css_text> vector;
|
||||
|
||||
tstring text;
|
||||
|
@ -17,15 +15,13 @@ namespace litehtml
|
|||
|
||||
css_text() = default;
|
||||
|
||||
css_text(const tchar_t* txt, const tchar_t* url, const tchar_t* media_str)
|
||||
{
|
||||
css_text(const tchar_t* txt, const tchar_t* url, const tchar_t* media_str) {
|
||||
text = txt ? txt : _t("");
|
||||
baseurl = url ? url : _t("");
|
||||
media = media_str ? media_str : _t("");
|
||||
}
|
||||
|
||||
css_text(const css_text& val)
|
||||
{
|
||||
css_text(const css_text& val) {
|
||||
text = val.text;
|
||||
baseurl = val.baseurl;
|
||||
media = val.media;
|
||||
|
@ -34,11 +30,11 @@ namespace litehtml
|
|||
|
||||
class html_tag;
|
||||
|
||||
class document : public std::enable_shared_from_this<document>
|
||||
{
|
||||
class document : public std::enable_shared_from_this<document> {
|
||||
public:
|
||||
typedef std::shared_ptr<document> ptr;
|
||||
typedef std::weak_ptr<document> weak_ptr;
|
||||
|
||||
private:
|
||||
std::shared_ptr<element> m_root;
|
||||
document_container* m_container;
|
||||
|
@ -55,6 +51,7 @@ namespace litehtml
|
|||
media_features m_media;
|
||||
tstring m_lang;
|
||||
tstring m_culture;
|
||||
|
||||
public:
|
||||
document(litehtml::document_container* objContainer, litehtml::context* ctx);
|
||||
virtual ~document();
|
||||
|
@ -100,18 +97,9 @@ namespace litehtml
|
|||
void fix_table_parent(element::ptr& el_ptr, style_display disp, const tchar_t* disp_str);
|
||||
};
|
||||
|
||||
inline element::ptr document::root()
|
||||
{
|
||||
return m_root;
|
||||
}
|
||||
inline void document::add_tabular(const element::ptr& el)
|
||||
{
|
||||
m_tabular_elements.push_back(el);
|
||||
}
|
||||
inline bool document::match_lang(const tstring & lang)
|
||||
{
|
||||
return lang == m_lang || lang == m_culture;
|
||||
}
|
||||
}
|
||||
inline element::ptr document::root() { return m_root; }
|
||||
inline void document::add_tabular(const element::ptr& el) { m_tabular_elements.push_back(el); }
|
||||
inline bool document::match_lang(const tstring& lang) { return lang == m_lang || lang == m_culture; }
|
||||
} // namespace litehtml
|
||||
|
||||
#endif // LH_DOCUMENT_H
|
||||
|
|
|
@ -3,16 +3,14 @@
|
|||
|
||||
#include "html_tag.h"
|
||||
|
||||
namespace litehtml
|
||||
{
|
||||
class el_anchor : public html_tag
|
||||
{
|
||||
namespace litehtml {
|
||||
class el_anchor : public html_tag {
|
||||
public:
|
||||
explicit el_anchor(const std::shared_ptr<litehtml::document>& doc);
|
||||
|
||||
void on_click() override;
|
||||
void apply_stylesheet(const litehtml::css& stylesheet) override;
|
||||
};
|
||||
}
|
||||
} // namespace litehtml
|
||||
|
||||
#endif // LH_EL_ANCHOR_H
|
||||
|
|
|
@ -3,15 +3,13 @@
|
|||
|
||||
#include "html_tag.h"
|
||||
|
||||
namespace litehtml
|
||||
{
|
||||
class el_base : public html_tag
|
||||
{
|
||||
namespace litehtml {
|
||||
class el_base : public html_tag {
|
||||
public:
|
||||
explicit el_base(const std::shared_ptr<litehtml::document>& doc);
|
||||
|
||||
void parse_attributes() override;
|
||||
};
|
||||
}
|
||||
} // namespace litehtml
|
||||
|
||||
#endif // LH_EL_BASE_H
|
||||
|
|
|
@ -3,38 +3,29 @@
|
|||
|
||||
#include "html_tag.h"
|
||||
|
||||
namespace litehtml
|
||||
{
|
||||
class el_before_after_base : public html_tag
|
||||
{
|
||||
namespace litehtml {
|
||||
class el_before_after_base : public html_tag {
|
||||
public:
|
||||
el_before_after_base(const std::shared_ptr<litehtml::document>& doc, bool before);
|
||||
|
||||
void add_style(const litehtml::style& st) override;
|
||||
void apply_stylesheet(const litehtml::css& stylesheet) override;
|
||||
|
||||
private:
|
||||
void add_text(const tstring& txt);
|
||||
void add_function(const tstring& fnc, const tstring& params);
|
||||
static tstring convert_escape(const tchar_t* txt);
|
||||
};
|
||||
|
||||
class el_before : public el_before_after_base
|
||||
{
|
||||
class el_before : public el_before_after_base {
|
||||
public:
|
||||
explicit el_before(const std::shared_ptr<litehtml::document>& doc) : el_before_after_base(doc, true)
|
||||
{
|
||||
|
||||
}
|
||||
explicit el_before(const std::shared_ptr<litehtml::document>& doc) : el_before_after_base(doc, true) {}
|
||||
};
|
||||
|
||||
class el_after : public el_before_after_base
|
||||
{
|
||||
class el_after : public el_before_after_base {
|
||||
public:
|
||||
explicit el_after(const std::shared_ptr<litehtml::document>& doc) : el_before_after_base(doc, false)
|
||||
{
|
||||
|
||||
}
|
||||
explicit el_after(const std::shared_ptr<litehtml::document>& doc) : el_before_after_base(doc, false) {}
|
||||
};
|
||||
}
|
||||
} // namespace litehtml
|
||||
|
||||
#endif // LH_EL_BEFORE_AFTER_H
|
||||
|
|
|
@ -3,15 +3,13 @@
|
|||
|
||||
#include "html_tag.h"
|
||||
|
||||
namespace litehtml
|
||||
{
|
||||
class el_body : public html_tag
|
||||
{
|
||||
namespace litehtml {
|
||||
class el_body : public html_tag {
|
||||
public:
|
||||
explicit el_body(const std::shared_ptr<litehtml::document>& doc);
|
||||
|
||||
bool is_body() const override;
|
||||
};
|
||||
}
|
||||
} // namespace litehtml
|
||||
|
||||
#endif // LH_EL_BODY_H
|
||||
|
|
|
@ -3,15 +3,13 @@
|
|||
|
||||
#include "html_tag.h"
|
||||
|
||||
namespace litehtml
|
||||
{
|
||||
class el_break : public html_tag
|
||||
{
|
||||
namespace litehtml {
|
||||
class el_break : public html_tag {
|
||||
public:
|
||||
explicit el_break(const std::shared_ptr<litehtml::document>& doc);
|
||||
|
||||
bool is_break() const override;
|
||||
};
|
||||
}
|
||||
} // namespace litehtml
|
||||
|
||||
#endif // LH_EL_BREAK_H
|
||||
|
|
|
@ -3,17 +3,16 @@
|
|||
|
||||
#include "html_tag.h"
|
||||
|
||||
namespace litehtml
|
||||
{
|
||||
class el_cdata : public element
|
||||
{
|
||||
namespace litehtml {
|
||||
class el_cdata : public element {
|
||||
tstring m_text;
|
||||
|
||||
public:
|
||||
explicit el_cdata(const std::shared_ptr<litehtml::document>& doc);
|
||||
|
||||
void get_text(tstring& text) override;
|
||||
void set_data(const tchar_t* data) override;
|
||||
};
|
||||
}
|
||||
} // namespace litehtml
|
||||
|
||||
#endif // LH_EL_CDATA_H
|
||||
|
|
|
@ -3,17 +3,16 @@
|
|||
|
||||
#include "html_tag.h"
|
||||
|
||||
namespace litehtml
|
||||
{
|
||||
class el_comment : public element
|
||||
{
|
||||
namespace litehtml {
|
||||
class el_comment : public element {
|
||||
tstring m_text;
|
||||
|
||||
public:
|
||||
explicit el_comment(const std::shared_ptr<litehtml::document>& doc);
|
||||
|
||||
void get_text(tstring& text) override;
|
||||
void set_data(const tchar_t* data) override;
|
||||
};
|
||||
}
|
||||
} // namespace litehtml
|
||||
|
||||
#endif // LH_EL_COMMENT_H
|
||||
|
|
|
@ -3,15 +3,13 @@
|
|||
|
||||
#include "html_tag.h"
|
||||
|
||||
namespace litehtml
|
||||
{
|
||||
class el_div : public html_tag
|
||||
{
|
||||
namespace litehtml {
|
||||
class el_div : public html_tag {
|
||||
public:
|
||||
explicit el_div(const std::shared_ptr<litehtml::document>& doc);
|
||||
|
||||
void parse_attributes() override;
|
||||
};
|
||||
}
|
||||
} // namespace litehtml
|
||||
|
||||
#endif // LH_EL_DIV_H
|
||||
|
|
|
@ -3,15 +3,13 @@
|
|||
|
||||
#include "html_tag.h"
|
||||
|
||||
namespace litehtml
|
||||
{
|
||||
class el_font : public html_tag
|
||||
{
|
||||
namespace litehtml {
|
||||
class el_font : public html_tag {
|
||||
public:
|
||||
explicit el_font(const std::shared_ptr<litehtml::document>& doc);
|
||||
|
||||
void parse_attributes() override;
|
||||
};
|
||||
}
|
||||
} // namespace litehtml
|
||||
|
||||
#endif // LH_EL_FONT_H
|
||||
|
|
|
@ -3,12 +3,11 @@
|
|||
|
||||
#include "html_tag.h"
|
||||
|
||||
namespace litehtml
|
||||
{
|
||||
namespace litehtml {
|
||||
|
||||
class el_image : public html_tag
|
||||
{
|
||||
class el_image : public html_tag {
|
||||
tstring m_src;
|
||||
|
||||
public:
|
||||
el_image(const std::shared_ptr<litehtml::document>& doc);
|
||||
virtual ~el_image(void);
|
||||
|
@ -20,9 +19,10 @@ namespace litehtml
|
|||
virtual void parse_styles(bool is_reparse = false) override;
|
||||
virtual void draw(uint_ptr hdc, int x, int y, const position* clip) override;
|
||||
virtual void get_content_size(size& sz, int max_width) override;
|
||||
|
||||
private:
|
||||
int calc_max_height(int image_height);
|
||||
};
|
||||
}
|
||||
} // namespace litehtml
|
||||
|
||||
#endif // LH_EL_IMAGE_H
|
||||
|
|
|
@ -3,10 +3,8 @@
|
|||
|
||||
#include "html_tag.h"
|
||||
|
||||
namespace litehtml
|
||||
{
|
||||
class el_li : public html_tag
|
||||
{
|
||||
namespace litehtml {
|
||||
class el_li : public html_tag {
|
||||
public:
|
||||
explicit el_li(const std::shared_ptr<litehtml::document>& doc);
|
||||
|
||||
|
@ -15,6 +13,6 @@ namespace litehtml
|
|||
private:
|
||||
bool m_index_initialized = false;
|
||||
};
|
||||
}
|
||||
} // namespace litehtml
|
||||
|
||||
#endif // LH_EL_LI_H
|
||||
|
|
|
@ -3,16 +3,14 @@
|
|||
|
||||
#include "html_tag.h"
|
||||
|
||||
namespace litehtml
|
||||
{
|
||||
class el_link : public html_tag
|
||||
{
|
||||
namespace litehtml {
|
||||
class el_link : public html_tag {
|
||||
public:
|
||||
explicit el_link(const std::shared_ptr<litehtml::document>& doc);
|
||||
|
||||
protected:
|
||||
void parse_attributes() override;
|
||||
};
|
||||
}
|
||||
} // namespace litehtml
|
||||
|
||||
#endif // LH_EL_LINK_H
|
||||
|
|
|
@ -3,16 +3,13 @@
|
|||
|
||||
#include "html_tag.h"
|
||||
|
||||
namespace litehtml
|
||||
{
|
||||
class el_para : public html_tag
|
||||
{
|
||||
namespace litehtml {
|
||||
class el_para : public html_tag {
|
||||
public:
|
||||
explicit el_para(const std::shared_ptr<litehtml::document>& doc);
|
||||
|
||||
void parse_attributes() override;
|
||||
|
||||
};
|
||||
}
|
||||
} // namespace litehtml
|
||||
|
||||
#endif // LH_EL_PARA_H
|
||||
|
|
|
@ -3,11 +3,10 @@
|
|||
|
||||
#include "html_tag.h"
|
||||
|
||||
namespace litehtml
|
||||
{
|
||||
class el_script : public element
|
||||
{
|
||||
namespace litehtml {
|
||||
class el_script : public element {
|
||||
tstring m_text;
|
||||
|
||||
public:
|
||||
explicit el_script(const std::shared_ptr<litehtml::document>& doc);
|
||||
|
||||
|
@ -15,6 +14,6 @@ namespace litehtml
|
|||
bool appendChild(const ptr& el) override;
|
||||
const tchar_t* get_tagName() const override;
|
||||
};
|
||||
}
|
||||
} // namespace litehtml
|
||||
|
||||
#endif // LH_EL_SCRIPT_H
|
||||
|
|
|
@ -1,19 +1,17 @@
|
|||
#ifndef LH_EL_SPACE_H
|
||||
#define LH_EL_SPACE_H
|
||||
|
||||
#include "html_tag.h"
|
||||
#include "el_text.h"
|
||||
#include "html_tag.h"
|
||||
|
||||
namespace litehtml
|
||||
{
|
||||
class el_space : public el_text
|
||||
{
|
||||
namespace litehtml {
|
||||
class el_space : public el_text {
|
||||
public:
|
||||
el_space(const tchar_t* text, const std::shared_ptr<litehtml::document>& doc);
|
||||
|
||||
bool is_white_space() const override;
|
||||
bool is_break() const override;
|
||||
};
|
||||
}
|
||||
} // namespace litehtml
|
||||
|
||||
#endif // LH_EL_SPACE_H
|
||||
|
|
|
@ -3,11 +3,10 @@
|
|||
|
||||
#include "html_tag.h"
|
||||
|
||||
namespace litehtml
|
||||
{
|
||||
class el_style : public element
|
||||
{
|
||||
namespace litehtml {
|
||||
class el_style : public element {
|
||||
elements_vector m_children;
|
||||
|
||||
public:
|
||||
explicit el_style(const std::shared_ptr<litehtml::document>& doc);
|
||||
|
||||
|
@ -15,6 +14,6 @@ namespace litehtml
|
|||
bool appendChild(const ptr& el) override;
|
||||
const tchar_t* get_tagName() const override;
|
||||
};
|
||||
}
|
||||
} // namespace litehtml
|
||||
|
||||
#endif // LH_EL_STYLE_H
|
||||
|
|
|
@ -3,17 +3,13 @@
|
|||
|
||||
#include "html_tag.h"
|
||||
|
||||
namespace litehtml
|
||||
{
|
||||
struct col_info
|
||||
{
|
||||
namespace litehtml {
|
||||
struct col_info {
|
||||
int width;
|
||||
bool is_auto;
|
||||
};
|
||||
|
||||
|
||||
class el_table : public html_tag
|
||||
{
|
||||
class el_table : public html_tag {
|
||||
public:
|
||||
explicit el_table(const std::shared_ptr<litehtml::document>& doc);
|
||||
|
||||
|
@ -21,6 +17,6 @@ namespace litehtml
|
|||
void parse_styles(bool is_reparse = false) override;
|
||||
void parse_attributes() override;
|
||||
};
|
||||
}
|
||||
} // namespace litehtml
|
||||
|
||||
#endif // LH_EL_TABLE_H
|
||||
|
|
|
@ -3,15 +3,13 @@
|
|||
|
||||
#include "html_tag.h"
|
||||
|
||||
namespace litehtml
|
||||
{
|
||||
class el_td : public html_tag
|
||||
{
|
||||
namespace litehtml {
|
||||
class el_td : public html_tag {
|
||||
public:
|
||||
explicit el_td(const std::shared_ptr<litehtml::document>& doc);
|
||||
|
||||
void parse_attributes() override;
|
||||
};
|
||||
}
|
||||
} // namespace litehtml
|
||||
|
||||
#endif // LH_EL_TD_H
|
||||
|
|
|
@ -3,10 +3,8 @@
|
|||
|
||||
#include "html_tag.h"
|
||||
|
||||
namespace litehtml
|
||||
{
|
||||
class el_text : public element
|
||||
{
|
||||
namespace litehtml {
|
||||
class el_text : public element {
|
||||
protected:
|
||||
tstring m_text;
|
||||
tstring m_transformed_text;
|
||||
|
@ -14,6 +12,7 @@ namespace litehtml
|
|||
text_transform m_text_transform;
|
||||
bool m_use_transformed;
|
||||
bool m_draw_spaces;
|
||||
|
||||
public:
|
||||
el_text(const tchar_t* text, const std::shared_ptr<litehtml::document>& doc);
|
||||
|
||||
|
@ -32,6 +31,6 @@ namespace litehtml
|
|||
protected:
|
||||
void get_content_size(size& sz, int max_width) override;
|
||||
};
|
||||
}
|
||||
} // namespace litehtml
|
||||
|
||||
#endif // LH_EL_TEXT_H
|
||||
|
|
|
@ -3,16 +3,14 @@
|
|||
|
||||
#include "html_tag.h"
|
||||
|
||||
namespace litehtml
|
||||
{
|
||||
class el_title : public html_tag
|
||||
{
|
||||
namespace litehtml {
|
||||
class el_title : public html_tag {
|
||||
public:
|
||||
explicit el_title(const std::shared_ptr<litehtml::document>& doc);
|
||||
|
||||
protected:
|
||||
void parse_attributes() override;
|
||||
};
|
||||
}
|
||||
} // namespace litehtml
|
||||
|
||||
#endif // LH_EL_TITLE_H
|
||||
|
|
|
@ -3,16 +3,14 @@
|
|||
|
||||
#include "html_tag.h"
|
||||
|
||||
namespace litehtml
|
||||
{
|
||||
class el_tr : public html_tag
|
||||
{
|
||||
namespace litehtml {
|
||||
class el_tr : public html_tag {
|
||||
public:
|
||||
explicit el_tr(const std::shared_ptr<litehtml::document>& doc);
|
||||
|
||||
void parse_attributes() override;
|
||||
void get_inline_boxes(position::vector& boxes) override;
|
||||
};
|
||||
}
|
||||
} // namespace litehtml
|
||||
|
||||
#endif // LH_EL_TR_H
|
||||
|
|
|
@ -2,24 +2,25 @@
|
|||
#define LH_ELEMENT_H
|
||||
|
||||
#include <memory>
|
||||
#include "stylesheet.h"
|
||||
#include "css_offsets.h"
|
||||
|
||||
namespace litehtml
|
||||
{
|
||||
#include "css_offsets.h"
|
||||
#include "stylesheet.h"
|
||||
|
||||
namespace litehtml {
|
||||
class box;
|
||||
|
||||
class element : public std::enable_shared_from_this<element>
|
||||
{
|
||||
class element : public std::enable_shared_from_this<element> {
|
||||
friend class block_box;
|
||||
friend class line_box;
|
||||
friend class html_tag;
|
||||
friend class el_table;
|
||||
friend class document;
|
||||
|
||||
public:
|
||||
typedef std::shared_ptr<litehtml::element> ptr;
|
||||
typedef std::shared_ptr<const litehtml::element> const_ptr;
|
||||
typedef std::weak_ptr<litehtml::element> weak_ptr;
|
||||
|
||||
protected:
|
||||
std::weak_ptr<element> m_parent;
|
||||
std::weak_ptr<litehtml::document> m_doc;
|
||||
|
@ -32,6 +33,7 @@ namespace litehtml
|
|||
bool m_skip;
|
||||
|
||||
virtual void select_all(const css_selector& selector, elements_vector& res);
|
||||
|
||||
public:
|
||||
explicit element(const std::shared_ptr<litehtml::document>& doc);
|
||||
virtual ~element() = default;
|
||||
|
@ -205,172 +207,76 @@ namespace litehtml
|
|||
// INLINE FUNCTIONS //
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
|
||||
inline int litehtml::element::right() const
|
||||
{
|
||||
return left() + width();
|
||||
}
|
||||
inline int litehtml::element::right() const { return left() + width(); }
|
||||
|
||||
inline int litehtml::element::left() const
|
||||
{
|
||||
return m_pos.left() - margin_left() - m_padding.left - m_borders.left;
|
||||
}
|
||||
inline int litehtml::element::left() const { return m_pos.left() - margin_left() - m_padding.left - m_borders.left; }
|
||||
|
||||
inline int litehtml::element::top() const
|
||||
{
|
||||
return m_pos.top() - margin_top() - m_padding.top - m_borders.top;
|
||||
}
|
||||
inline int litehtml::element::top() const { return m_pos.top() - margin_top() - m_padding.top - m_borders.top; }
|
||||
|
||||
inline int litehtml::element::bottom() const
|
||||
{
|
||||
return top() + height();
|
||||
}
|
||||
inline int litehtml::element::bottom() const { return top() + height(); }
|
||||
|
||||
inline int litehtml::element::height() const
|
||||
{
|
||||
return m_pos.height + margin_top() + margin_bottom() + m_padding.height() + m_borders.height();
|
||||
}
|
||||
inline int litehtml::element::height() const { return m_pos.height + margin_top() + margin_bottom() + m_padding.height() + m_borders.height(); }
|
||||
|
||||
inline int litehtml::element::width() const
|
||||
{
|
||||
return m_pos.width + margin_left() + margin_right() + m_padding.width() + m_borders.width();
|
||||
}
|
||||
inline int litehtml::element::width() const { return m_pos.width + margin_left() + margin_right() + m_padding.width() + m_borders.width(); }
|
||||
|
||||
inline int litehtml::element::content_margins_top() const
|
||||
{
|
||||
return margin_top() + m_padding.top + m_borders.top;
|
||||
}
|
||||
inline int litehtml::element::content_margins_top() const { return margin_top() + m_padding.top + m_borders.top; }
|
||||
|
||||
inline int litehtml::element::content_margins_bottom() const
|
||||
{
|
||||
return margin_bottom() + m_padding.bottom + m_borders.bottom;
|
||||
}
|
||||
inline int litehtml::element::content_margins_bottom() const { return margin_bottom() + m_padding.bottom + m_borders.bottom; }
|
||||
|
||||
inline int litehtml::element::content_margins_left() const
|
||||
{
|
||||
return margin_left() + m_padding.left + m_borders.left;
|
||||
}
|
||||
inline int litehtml::element::content_margins_left() const { return margin_left() + m_padding.left + m_borders.left; }
|
||||
|
||||
inline int litehtml::element::content_margins_right() const
|
||||
{
|
||||
return margin_right() + m_padding.right + m_borders.right;
|
||||
}
|
||||
inline int litehtml::element::content_margins_right() const { return margin_right() + m_padding.right + m_borders.right; }
|
||||
|
||||
inline int litehtml::element::content_margins_width() const
|
||||
{
|
||||
return content_margins_left() + content_margins_right();
|
||||
}
|
||||
inline int litehtml::element::content_margins_width() const { return content_margins_left() + content_margins_right(); }
|
||||
|
||||
inline int litehtml::element::content_margins_height() const
|
||||
{
|
||||
return content_margins_top() + content_margins_bottom();
|
||||
}
|
||||
inline int litehtml::element::content_margins_height() const { return content_margins_top() + content_margins_bottom(); }
|
||||
|
||||
inline litehtml::margins litehtml::element::get_paddings() const
|
||||
{
|
||||
return m_padding;
|
||||
}
|
||||
inline litehtml::margins litehtml::element::get_paddings() const { return m_padding; }
|
||||
|
||||
inline litehtml::margins litehtml::element::get_borders() const
|
||||
{
|
||||
return m_borders;
|
||||
}
|
||||
inline litehtml::margins litehtml::element::get_borders() const { return m_borders; }
|
||||
|
||||
inline int litehtml::element::padding_top() const
|
||||
{
|
||||
return m_padding.top;
|
||||
}
|
||||
inline int litehtml::element::padding_top() const { return m_padding.top; }
|
||||
|
||||
inline int litehtml::element::padding_bottom() const
|
||||
{
|
||||
return m_padding.bottom;
|
||||
}
|
||||
inline int litehtml::element::padding_bottom() const { return m_padding.bottom; }
|
||||
|
||||
inline int litehtml::element::padding_left() const
|
||||
{
|
||||
return m_padding.left;
|
||||
}
|
||||
inline int litehtml::element::padding_left() const { return m_padding.left; }
|
||||
|
||||
inline int litehtml::element::padding_right() const
|
||||
{
|
||||
return m_padding.right;
|
||||
}
|
||||
inline int litehtml::element::padding_right() const { return m_padding.right; }
|
||||
|
||||
inline bool litehtml::element::in_normal_flow() const
|
||||
{
|
||||
if(get_element_position() != element_position_absolute && get_display() != display_none)
|
||||
{
|
||||
inline bool litehtml::element::in_normal_flow() const {
|
||||
if (get_element_position() != element_position_absolute && get_display() != display_none) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
inline int litehtml::element::border_top() const
|
||||
{
|
||||
return m_borders.top;
|
||||
}
|
||||
inline int litehtml::element::border_top() const { return m_borders.top; }
|
||||
|
||||
inline int litehtml::element::border_bottom() const
|
||||
{
|
||||
return m_borders.bottom;
|
||||
}
|
||||
inline int litehtml::element::border_bottom() const { return m_borders.bottom; }
|
||||
|
||||
inline int litehtml::element::border_left() const
|
||||
{
|
||||
return m_borders.left;
|
||||
}
|
||||
inline int litehtml::element::border_left() const { return m_borders.left; }
|
||||
|
||||
inline int litehtml::element::border_right() const
|
||||
{
|
||||
return m_borders.right;
|
||||
}
|
||||
inline int litehtml::element::border_right() const { return m_borders.right; }
|
||||
|
||||
inline bool litehtml::element::skip() const
|
||||
{
|
||||
return m_skip;
|
||||
}
|
||||
inline bool litehtml::element::skip() const { return m_skip; }
|
||||
|
||||
inline void litehtml::element::skip(bool val)
|
||||
{
|
||||
m_skip = val;
|
||||
}
|
||||
inline void litehtml::element::skip(bool val) { m_skip = val; }
|
||||
|
||||
inline bool litehtml::element::have_parent() const
|
||||
{
|
||||
return !m_parent.expired();
|
||||
}
|
||||
inline bool litehtml::element::have_parent() const { return !m_parent.expired(); }
|
||||
|
||||
inline element::ptr litehtml::element::parent() const
|
||||
{
|
||||
return m_parent.lock();
|
||||
}
|
||||
inline element::ptr litehtml::element::parent() const { return m_parent.lock(); }
|
||||
|
||||
inline void litehtml::element::parent(const element::ptr& par)
|
||||
{
|
||||
m_parent = par;
|
||||
}
|
||||
inline void litehtml::element::parent(const element::ptr& par) { m_parent = par; }
|
||||
|
||||
inline int litehtml::element::margin_top() const
|
||||
{
|
||||
return m_margins.top;
|
||||
}
|
||||
inline int litehtml::element::margin_top() const { return m_margins.top; }
|
||||
|
||||
inline int litehtml::element::margin_bottom() const
|
||||
{
|
||||
return m_margins.bottom;
|
||||
}
|
||||
inline int litehtml::element::margin_bottom() const { return m_margins.bottom; }
|
||||
|
||||
inline int litehtml::element::margin_left() const
|
||||
{
|
||||
return m_margins.left;
|
||||
}
|
||||
inline int litehtml::element::margin_left() const { return m_margins.left; }
|
||||
|
||||
inline int litehtml::element::margin_right() const
|
||||
{
|
||||
return m_margins.right;
|
||||
}
|
||||
inline int litehtml::element::margin_right() const { return m_margins.right; }
|
||||
|
||||
inline litehtml::margins litehtml::element::get_margins() const
|
||||
{
|
||||
inline litehtml::margins litehtml::element::get_margins() const {
|
||||
margins ret;
|
||||
ret.left = margin_left();
|
||||
ret.right = margin_right();
|
||||
|
@ -380,25 +286,13 @@ namespace litehtml
|
|||
return ret;
|
||||
}
|
||||
|
||||
inline bool litehtml::element::is_positioned() const
|
||||
{
|
||||
return (get_element_position() > element_position_static);
|
||||
}
|
||||
inline bool litehtml::element::is_positioned() const { return (get_element_position() > element_position_static); }
|
||||
|
||||
inline bool litehtml::element::is_visible() const
|
||||
{
|
||||
return !(m_skip || get_display() == display_none || get_visibility() != visibility_visible);
|
||||
}
|
||||
inline bool litehtml::element::is_visible() const { return !(m_skip || get_display() == display_none || get_visibility() != visibility_visible); }
|
||||
|
||||
inline position& litehtml::element::get_position()
|
||||
{
|
||||
return m_pos;
|
||||
}
|
||||
inline position& litehtml::element::get_position() { return m_pos; }
|
||||
|
||||
inline std::shared_ptr<document> element::get_document() const
|
||||
{
|
||||
return m_doc.lock();
|
||||
}
|
||||
}
|
||||
inline std::shared_ptr<document> element::get_document() const { return m_doc.lock(); }
|
||||
} // namespace litehtml
|
||||
|
||||
#endif // LH_ELEMENT_H
|
||||
|
|
|
@ -1,27 +1,27 @@
|
|||
#ifndef LH_HTML_H
|
||||
#define LH_HTML_H
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <string>
|
||||
#include <ctype.h>
|
||||
#include <vector>
|
||||
#include <map>
|
||||
#include <cstring>
|
||||
#include <stdlib.h>
|
||||
|
||||
#include <algorithm>
|
||||
#include <sstream>
|
||||
#include <cstring>
|
||||
#include <functional>
|
||||
#include "os_types.h"
|
||||
#include "types.h"
|
||||
#include <map>
|
||||
#include <sstream>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
#include "background.h"
|
||||
#include "borders.h"
|
||||
#include "html_tag.h"
|
||||
#include "web_color.h"
|
||||
#include "media_query.h"
|
||||
#include "os_types.h"
|
||||
#include "types.h"
|
||||
#include "web_color.h"
|
||||
|
||||
namespace litehtml
|
||||
{
|
||||
struct list_marker
|
||||
{
|
||||
namespace litehtml {
|
||||
struct list_marker {
|
||||
tstring image;
|
||||
const tchar_t* baseurl;
|
||||
list_style_type marker_type;
|
||||
|
@ -32,8 +32,7 @@ namespace litehtml
|
|||
};
|
||||
|
||||
// call back interface to draw text, images and other elements
|
||||
class document_container
|
||||
{
|
||||
class document_container {
|
||||
public:
|
||||
virtual litehtml::uint_ptr create_font(const litehtml::tchar_t* faceName, int size, int weight, litehtml::font_style italic, unsigned int decoration, litehtml::font_metrics* fm) = 0;
|
||||
virtual void delete_font(litehtml::uint_ptr hFont) = 0;
|
||||
|
@ -58,9 +57,7 @@ namespace litehtml
|
|||
virtual void set_clip(const litehtml::position& pos, const litehtml::border_radiuses& bdr_radius, bool valid_x, bool valid_y) = 0;
|
||||
virtual void del_clip() = 0;
|
||||
virtual void get_client_rect(litehtml::position& client) const = 0;
|
||||
virtual std::shared_ptr<litehtml::element> create_element(const litehtml::tchar_t *tag_name,
|
||||
const litehtml::string_map &attributes,
|
||||
const std::shared_ptr<litehtml::document> &doc) = 0;
|
||||
virtual std::shared_ptr<litehtml::element> create_element(const litehtml::tchar_t* tag_name, const litehtml::string_map& attributes, const std::shared_ptr<litehtml::document>& doc) = 0;
|
||||
|
||||
virtual void get_media_features(litehtml::media_features& media) const = 0;
|
||||
virtual void get_language(litehtml::tstring& language, litehtml::tstring& culture) const = 0;
|
||||
|
@ -83,35 +80,25 @@ namespace litehtml
|
|||
int t_strcasecmp(const tchar_t* s1, const tchar_t* s2);
|
||||
int t_strncasecmp(const tchar_t* s1, const tchar_t* s2, size_t n);
|
||||
|
||||
inline int t_isdigit(int c)
|
||||
{
|
||||
return (c >= '0' && c <= '9');
|
||||
}
|
||||
inline int t_isdigit(int c) { return (c >= '0' && c <= '9'); }
|
||||
|
||||
inline int t_tolower(int c)
|
||||
{
|
||||
return (c >= 'A' && c <= 'Z' ? c + 'a' - 'A' : c);
|
||||
}
|
||||
inline int t_tolower(int c) { return (c >= 'A' && c <= 'Z' ? c + 'a' - 'A' : c); }
|
||||
|
||||
inline int round_f(float val)
|
||||
{
|
||||
inline int round_f(float val) {
|
||||
int int_val = (int)val;
|
||||
if(val - int_val >= 0.5)
|
||||
{
|
||||
if (val - int_val >= 0.5) {
|
||||
int_val++;
|
||||
}
|
||||
return int_val;
|
||||
}
|
||||
|
||||
inline int round_d(double val)
|
||||
{
|
||||
inline int round_d(double val) {
|
||||
int int_val = (int)val;
|
||||
if(val - int_val >= 0.5)
|
||||
{
|
||||
if (val - int_val >= 0.5) {
|
||||
int_val++;
|
||||
}
|
||||
return int_val;
|
||||
}
|
||||
}
|
||||
} // namespace litehtml
|
||||
|
||||
#endif // LH_HTML_H
|
||||
|
|
|
@ -1,44 +1,37 @@
|
|||
#ifndef LH_HTML_TAG_H
|
||||
#define LH_HTML_TAG_H
|
||||
|
||||
#include "background.h"
|
||||
#include "borders.h"
|
||||
#include "box.h"
|
||||
#include "css_margins.h"
|
||||
#include "css_selector.h"
|
||||
#include "element.h"
|
||||
#include "style.h"
|
||||
#include "background.h"
|
||||
#include "css_margins.h"
|
||||
#include "borders.h"
|
||||
#include "css_selector.h"
|
||||
#include "stylesheet.h"
|
||||
#include "box.h"
|
||||
#include "table.h"
|
||||
|
||||
namespace litehtml
|
||||
{
|
||||
struct line_context
|
||||
{
|
||||
namespace litehtml {
|
||||
struct line_context {
|
||||
int calculatedTop;
|
||||
int top;
|
||||
int left;
|
||||
int right;
|
||||
|
||||
int width() const
|
||||
{
|
||||
return right - left;
|
||||
}
|
||||
void fix_top()
|
||||
{
|
||||
calculatedTop = top;
|
||||
}
|
||||
int width() const { return right - left; }
|
||||
void fix_top() { calculatedTop = top; }
|
||||
};
|
||||
|
||||
class html_tag : public element
|
||||
{
|
||||
class html_tag : public element {
|
||||
friend class elements_iterator;
|
||||
friend class el_table;
|
||||
friend class table_grid;
|
||||
friend class block_box;
|
||||
friend class line_box;
|
||||
|
||||
public:
|
||||
typedef std::shared_ptr<litehtml::html_tag> ptr;
|
||||
|
||||
protected:
|
||||
box::vector m_boxes;
|
||||
string_vector m_class_values;
|
||||
|
@ -239,10 +232,7 @@ namespace litehtml
|
|||
/* Inline Functions */
|
||||
/************************************************************************/
|
||||
|
||||
inline elements_vector& litehtml::html_tag::children()
|
||||
{
|
||||
return m_children;
|
||||
}
|
||||
}
|
||||
inline elements_vector& litehtml::html_tag::children() { return m_children; }
|
||||
} // namespace litehtml
|
||||
|
||||
#endif // LH_HTML_TAG_H
|
||||
|
|
|
@ -3,12 +3,10 @@
|
|||
|
||||
#include "types.h"
|
||||
|
||||
namespace litehtml
|
||||
{
|
||||
namespace litehtml {
|
||||
class element;
|
||||
|
||||
class iterator_selector
|
||||
{
|
||||
class iterator_selector {
|
||||
public:
|
||||
virtual bool select(const element::ptr& el) = 0;
|
||||
|
||||
|
@ -16,23 +14,17 @@ namespace litehtml
|
|||
~iterator_selector() = default;
|
||||
};
|
||||
|
||||
class elements_iterator
|
||||
{
|
||||
class elements_iterator {
|
||||
private:
|
||||
struct stack_item
|
||||
{
|
||||
struct stack_item {
|
||||
int idx;
|
||||
element::ptr el;
|
||||
stack_item() : idx(0)
|
||||
{
|
||||
}
|
||||
stack_item(const stack_item& val)
|
||||
{
|
||||
stack_item() : idx(0) {}
|
||||
stack_item(const stack_item& val) {
|
||||
idx = val.idx;
|
||||
el = val.el;
|
||||
}
|
||||
stack_item(stack_item&& val)
|
||||
{
|
||||
stack_item(stack_item&& val) {
|
||||
idx = val.idx;
|
||||
el = std::move(val.el);
|
||||
}
|
||||
|
@ -43,10 +35,9 @@ namespace litehtml
|
|||
int m_idx;
|
||||
iterator_selector* m_go_inside;
|
||||
iterator_selector* m_select;
|
||||
public:
|
||||
|
||||
elements_iterator(const element::ptr& el, iterator_selector* go_inside, iterator_selector* select)
|
||||
{
|
||||
public:
|
||||
elements_iterator(const element::ptr& el, iterator_selector* go_inside, iterator_selector* select) {
|
||||
m_el = el;
|
||||
m_idx = -1;
|
||||
m_go_inside = go_inside;
|
||||
|
@ -61,29 +52,25 @@ namespace litehtml
|
|||
void next_idx();
|
||||
};
|
||||
|
||||
class go_inside_inline final : public iterator_selector
|
||||
{
|
||||
class go_inside_inline final : public iterator_selector {
|
||||
public:
|
||||
bool select(const element::ptr& el) override;
|
||||
};
|
||||
|
||||
class go_inside_table final : public iterator_selector
|
||||
{
|
||||
class go_inside_table final : public iterator_selector {
|
||||
public:
|
||||
bool select(const element::ptr& el) override;
|
||||
};
|
||||
|
||||
class table_rows_selector final : public iterator_selector
|
||||
{
|
||||
class table_rows_selector final : public iterator_selector {
|
||||
public:
|
||||
bool select(const element::ptr& el) override;
|
||||
};
|
||||
|
||||
class table_cells_selector final : public iterator_selector
|
||||
{
|
||||
class table_cells_selector final : public iterator_selector {
|
||||
public:
|
||||
bool select(const element::ptr& el) override;
|
||||
};
|
||||
}
|
||||
} // namespace litehtml
|
||||
|
||||
#endif // LH_ITERATORS_H
|
||||
|
|
|
@ -1,18 +1,15 @@
|
|||
#ifndef LH_MEDIA_QUERY_H
|
||||
#define LH_MEDIA_QUERY_H
|
||||
|
||||
namespace litehtml
|
||||
{
|
||||
struct media_query_expression
|
||||
{
|
||||
namespace litehtml {
|
||||
struct media_query_expression {
|
||||
typedef std::vector<media_query_expression> vector;
|
||||
media_feature feature;
|
||||
int val;
|
||||
int val2;
|
||||
bool check_as_bool;
|
||||
|
||||
media_query_expression()
|
||||
{
|
||||
media_query_expression() {
|
||||
check_as_bool = false;
|
||||
feature = media_feature_none;
|
||||
val = 0;
|
||||
|
@ -22,15 +19,16 @@ namespace litehtml
|
|||
bool check(const media_features& features) const;
|
||||
};
|
||||
|
||||
class media_query
|
||||
{
|
||||
class media_query {
|
||||
public:
|
||||
typedef std::shared_ptr<media_query> ptr;
|
||||
typedef std::vector<media_query::ptr> vector;
|
||||
|
||||
private:
|
||||
media_query_expression::vector m_expressions;
|
||||
bool m_not;
|
||||
media_type m_media_type;
|
||||
|
||||
public:
|
||||
media_query();
|
||||
media_query(const media_query& val);
|
||||
|
@ -39,14 +37,15 @@ namespace litehtml
|
|||
bool check(const media_features& features) const;
|
||||
};
|
||||
|
||||
class media_query_list
|
||||
{
|
||||
class media_query_list {
|
||||
public:
|
||||
typedef std::shared_ptr<media_query_list> ptr;
|
||||
typedef std::vector<media_query_list::ptr> vector;
|
||||
|
||||
private:
|
||||
media_query::vector m_queries;
|
||||
bool m_is_used;
|
||||
|
||||
public:
|
||||
media_query_list();
|
||||
media_query_list(const media_query_list& val);
|
||||
|
@ -56,22 +55,15 @@ namespace litehtml
|
|||
bool apply_media_features(const media_features& features); // returns true if the m_is_used changed
|
||||
};
|
||||
|
||||
inline media_query_list::media_query_list(const media_query_list& val)
|
||||
{
|
||||
inline media_query_list::media_query_list(const media_query_list& val) {
|
||||
m_is_used = val.m_is_used;
|
||||
m_queries = val.m_queries;
|
||||
}
|
||||
|
||||
inline media_query_list::media_query_list()
|
||||
{
|
||||
m_is_used = false;
|
||||
}
|
||||
inline media_query_list::media_query_list() { m_is_used = false; }
|
||||
|
||||
inline bool media_query_list::is_used() const
|
||||
{
|
||||
return m_is_used;
|
||||
}
|
||||
inline bool media_query_list::is_used() const { return m_is_used; }
|
||||
|
||||
}
|
||||
} // namespace litehtml
|
||||
|
||||
#endif // LH_MEDIA_QUERY_H
|
||||
|
|
|
@ -2,18 +2,17 @@
|
|||
#define NUM_CVT_H
|
||||
|
||||
#include <string>
|
||||
|
||||
#include "os_types.h"
|
||||
|
||||
namespace litehtml
|
||||
{
|
||||
namespace num_cvt
|
||||
{
|
||||
namespace litehtml {
|
||||
namespace num_cvt {
|
||||
litehtml::tstring to_latin_lower(int val);
|
||||
litehtml::tstring to_latin_upper(int val);
|
||||
litehtml::tstring to_greek_lower(int val);
|
||||
litehtml::tstring to_roman_lower(int value);
|
||||
litehtml::tstring to_roman_upper(int value);
|
||||
}
|
||||
}
|
||||
} // namespace num_cvt
|
||||
} // namespace litehtml
|
||||
|
||||
#endif // NUM_CVT_H
|
|
@ -1,11 +1,10 @@
|
|||
#ifndef LH_OS_TYPES_H
|
||||
#define LH_OS_TYPES_H
|
||||
|
||||
#include <string>
|
||||
#include <cstdint>
|
||||
#include <string>
|
||||
|
||||
namespace litehtml
|
||||
{
|
||||
namespace litehtml {
|
||||
#if defined(WIN32) || defined(_WIN32) || defined(WINCE)
|
||||
|
||||
// noexcept appeared since Visual Studio 2013
|
||||
|
@ -80,6 +79,6 @@ namespace litehtml
|
|||
#define t_to_string(val) std::to_string(val)
|
||||
|
||||
#endif
|
||||
}
|
||||
} // namespace litehtml
|
||||
|
||||
#endif // LH_OS_TYPES_H
|
||||
|
|
|
@ -1,34 +1,27 @@
|
|||
#ifndef LH_STYLE_H
|
||||
#define LH_STYLE_H
|
||||
|
||||
#include "attributes.h"
|
||||
#include <string>
|
||||
|
||||
namespace litehtml
|
||||
{
|
||||
class property_value
|
||||
{
|
||||
#include "attributes.h"
|
||||
|
||||
namespace litehtml {
|
||||
class property_value {
|
||||
public:
|
||||
tstring m_value;
|
||||
bool m_important;
|
||||
|
||||
property_value()
|
||||
{
|
||||
m_important = false;
|
||||
}
|
||||
property_value(const tchar_t* val, bool imp)
|
||||
{
|
||||
property_value() { m_important = false; }
|
||||
property_value(const tchar_t* val, bool imp) {
|
||||
m_important = imp;
|
||||
m_value = val;
|
||||
}
|
||||
property_value(const property_value& val)
|
||||
{
|
||||
property_value(const property_value& val) {
|
||||
m_value = val.m_value;
|
||||
m_important = val.m_important;
|
||||
}
|
||||
|
||||
property_value& operator=(const property_value& val)
|
||||
{
|
||||
property_value& operator=(const property_value& val) {
|
||||
m_value = val.m_value;
|
||||
m_important = val.m_important;
|
||||
return *this;
|
||||
|
@ -37,38 +30,32 @@ namespace litehtml
|
|||
|
||||
typedef std::map<tstring, property_value> props_map;
|
||||
|
||||
class style
|
||||
{
|
||||
class style {
|
||||
public:
|
||||
typedef std::shared_ptr<style> ptr;
|
||||
typedef std::vector<style::ptr> vector;
|
||||
|
||||
private:
|
||||
props_map m_properties;
|
||||
static string_map m_valid_values;
|
||||
|
||||
public:
|
||||
style() = default;
|
||||
style(const style& val);
|
||||
|
||||
style& operator=(const style& val)
|
||||
{
|
||||
style& operator=(const style& val) {
|
||||
m_properties = val.m_properties;
|
||||
return *this;
|
||||
}
|
||||
|
||||
void add(const tchar_t* txt, const tchar_t* baseurl)
|
||||
{
|
||||
parse(txt, baseurl);
|
||||
}
|
||||
void add(const tchar_t* txt, const tchar_t* baseurl) { parse(txt, baseurl); }
|
||||
|
||||
void add_property(const tchar_t* name, const tchar_t* val, const tchar_t* baseurl, bool important);
|
||||
|
||||
const tchar_t* get_property(const tchar_t* name) const
|
||||
{
|
||||
if(name)
|
||||
{
|
||||
const tchar_t* get_property(const tchar_t* name) const {
|
||||
if (name) {
|
||||
auto f = m_properties.find(name);
|
||||
if(f != m_properties.end())
|
||||
{
|
||||
if (f != m_properties.end()) {
|
||||
return f->second.m_value.c_str();
|
||||
}
|
||||
}
|
||||
|
@ -76,10 +63,7 @@ namespace litehtml
|
|||
}
|
||||
|
||||
void combine(const litehtml::style& src);
|
||||
void clear()
|
||||
{
|
||||
m_properties.clear();
|
||||
}
|
||||
void clear() { m_properties.clear(); }
|
||||
|
||||
private:
|
||||
void parse_property(const tstring& txt, const tchar_t* baseurl);
|
||||
|
@ -90,6 +74,6 @@ namespace litehtml
|
|||
void add_parsed_property(const tstring& name, const tstring& val, bool important);
|
||||
void remove_property(const tstring& name, bool important);
|
||||
};
|
||||
}
|
||||
} // namespace litehtml
|
||||
|
||||
#endif // LH_STYLE_H
|
||||
|
|
|
@ -1,29 +1,22 @@
|
|||
#ifndef LH_STYLESHEET_H
|
||||
#define LH_STYLESHEET_H
|
||||
|
||||
#include "style.h"
|
||||
#include "css_selector.h"
|
||||
#include "style.h"
|
||||
|
||||
namespace litehtml
|
||||
{
|
||||
namespace litehtml {
|
||||
class document_container;
|
||||
|
||||
class css
|
||||
{
|
||||
class css {
|
||||
css_selector::vector m_selectors;
|
||||
|
||||
public:
|
||||
css() = default;
|
||||
~css() = default;
|
||||
|
||||
const css_selector::vector& selectors() const
|
||||
{
|
||||
return m_selectors;
|
||||
}
|
||||
const css_selector::vector& selectors() const { return m_selectors; }
|
||||
|
||||
void clear()
|
||||
{
|
||||
m_selectors.clear();
|
||||
}
|
||||
void clear() { m_selectors.clear(); }
|
||||
|
||||
void parse_stylesheet(const tchar_t* str, const tchar_t* baseurl, const std::shared_ptr<document>& doc, const media_query_list::ptr& media);
|
||||
void sort_selectors();
|
||||
|
@ -33,15 +26,13 @@ namespace litehtml
|
|||
void parse_atrule(const tstring& text, const tchar_t* baseurl, const std::shared_ptr<document>& doc, const media_query_list::ptr& media);
|
||||
void add_selector(const css_selector::ptr& selector);
|
||||
bool parse_selectors(const tstring& txt, const litehtml::style::ptr& styles, const media_query_list::ptr& media);
|
||||
|
||||
};
|
||||
|
||||
inline void litehtml::css::add_selector( const css_selector::ptr& selector )
|
||||
{
|
||||
inline void litehtml::css::add_selector(const css_selector::ptr& selector) {
|
||||
selector->m_order = (int)m_selectors.size();
|
||||
m_selectors.push_back(selector);
|
||||
}
|
||||
|
||||
}
|
||||
} // namespace litehtml
|
||||
|
||||
#endif // LH_STYLESHEET_H
|
||||
|
|
|
@ -1,10 +1,8 @@
|
|||
#ifndef LH_TABLE_H
|
||||
#define LH_TABLE_H
|
||||
|
||||
namespace litehtml
|
||||
{
|
||||
struct table_row
|
||||
{
|
||||
namespace litehtml {
|
||||
struct table_row {
|
||||
typedef std::vector<table_row> vector;
|
||||
|
||||
int height;
|
||||
|
@ -16,8 +14,7 @@ namespace litehtml
|
|||
css_length css_height;
|
||||
int min_height;
|
||||
|
||||
table_row()
|
||||
{
|
||||
table_row() {
|
||||
min_height = 0;
|
||||
top = 0;
|
||||
bottom = 0;
|
||||
|
@ -28,8 +25,7 @@ namespace litehtml
|
|||
css_height.predef(0);
|
||||
}
|
||||
|
||||
table_row(int h, element::ptr& row)
|
||||
{
|
||||
table_row(int h, element::ptr& row) {
|
||||
min_height = 0;
|
||||
height = h;
|
||||
el_row = row;
|
||||
|
@ -37,14 +33,12 @@ namespace litehtml
|
|||
border_top = 0;
|
||||
top = 0;
|
||||
bottom = 0;
|
||||
if (row)
|
||||
{
|
||||
if (row) {
|
||||
css_height = row->get_css_height();
|
||||
}
|
||||
}
|
||||
|
||||
table_row(const table_row& val)
|
||||
{
|
||||
table_row(const table_row& val) {
|
||||
min_height = val.min_height;
|
||||
top = val.top;
|
||||
bottom = val.bottom;
|
||||
|
@ -55,8 +49,7 @@ namespace litehtml
|
|||
el_row = val.el_row;
|
||||
}
|
||||
|
||||
table_row(table_row&& val) noexcept
|
||||
{
|
||||
table_row(table_row&& val) noexcept {
|
||||
min_height = val.min_height;
|
||||
top = val.top;
|
||||
bottom = val.bottom;
|
||||
|
@ -68,8 +61,7 @@ namespace litehtml
|
|||
}
|
||||
};
|
||||
|
||||
struct table_column
|
||||
{
|
||||
struct table_column {
|
||||
typedef std::vector<table_column> vector;
|
||||
|
||||
int min_width;
|
||||
|
@ -81,8 +73,7 @@ namespace litehtml
|
|||
int left;
|
||||
int right;
|
||||
|
||||
table_column()
|
||||
{
|
||||
table_column() {
|
||||
left = 0;
|
||||
right = 0;
|
||||
border_left = 0;
|
||||
|
@ -93,8 +84,7 @@ namespace litehtml
|
|||
css_width.predef(0);
|
||||
}
|
||||
|
||||
table_column(int min_w, int max_w)
|
||||
{
|
||||
table_column(int min_w, int max_w) {
|
||||
left = 0;
|
||||
right = 0;
|
||||
border_left = 0;
|
||||
|
@ -105,8 +95,7 @@ namespace litehtml
|
|||
css_width.predef(0);
|
||||
}
|
||||
|
||||
table_column(const table_column& val)
|
||||
{
|
||||
table_column(const table_column& val) {
|
||||
left = val.left;
|
||||
right = val.right;
|
||||
border_left = val.border_left;
|
||||
|
@ -118,8 +107,7 @@ namespace litehtml
|
|||
}
|
||||
};
|
||||
|
||||
class table_column_accessor
|
||||
{
|
||||
class table_column_accessor {
|
||||
public:
|
||||
virtual int& get(table_column& col) = 0;
|
||||
|
||||
|
@ -127,26 +115,22 @@ namespace litehtml
|
|||
~table_column_accessor() = default;
|
||||
};
|
||||
|
||||
class table_column_accessor_max_width final : public table_column_accessor
|
||||
{
|
||||
class table_column_accessor_max_width final : public table_column_accessor {
|
||||
public:
|
||||
int& get(table_column& col) override;
|
||||
};
|
||||
|
||||
class table_column_accessor_min_width final : public table_column_accessor
|
||||
{
|
||||
class table_column_accessor_min_width final : public table_column_accessor {
|
||||
public:
|
||||
int& get(table_column& col) override;
|
||||
};
|
||||
|
||||
class table_column_accessor_width final : public table_column_accessor
|
||||
{
|
||||
class table_column_accessor_width final : public table_column_accessor {
|
||||
public:
|
||||
int& get(table_column& col) override;
|
||||
};
|
||||
|
||||
struct table_cell
|
||||
{
|
||||
struct table_cell {
|
||||
element::ptr el;
|
||||
int colspan;
|
||||
int rowspan;
|
||||
|
@ -158,8 +142,7 @@ namespace litehtml
|
|||
int height;
|
||||
margins borders;
|
||||
|
||||
table_cell()
|
||||
{
|
||||
table_cell() {
|
||||
min_width = 0;
|
||||
min_height = 0;
|
||||
max_width = 0;
|
||||
|
@ -171,8 +154,7 @@ namespace litehtml
|
|||
el = nullptr;
|
||||
}
|
||||
|
||||
table_cell(const table_cell& val)
|
||||
{
|
||||
table_cell(const table_cell& val) {
|
||||
el = val.el;
|
||||
colspan = val.colspan;
|
||||
rowspan = val.rowspan;
|
||||
|
@ -185,8 +167,7 @@ namespace litehtml
|
|||
borders = val.borders;
|
||||
}
|
||||
|
||||
table_cell(table_cell&& val) noexcept
|
||||
{
|
||||
table_cell(table_cell&& val) noexcept {
|
||||
el = std::move(val.el);
|
||||
colspan = val.colspan;
|
||||
rowspan = val.rowspan;
|
||||
|
@ -200,10 +181,10 @@ namespace litehtml
|
|||
}
|
||||
};
|
||||
|
||||
class table_grid
|
||||
{
|
||||
class table_grid {
|
||||
public:
|
||||
typedef std::vector<std::vector<table_cell> > rows;
|
||||
|
||||
private:
|
||||
int m_rows_count;
|
||||
int m_cols_count;
|
||||
|
@ -212,10 +193,9 @@ namespace litehtml
|
|||
table_row::vector m_rows;
|
||||
elements_vector m_captions;
|
||||
int m_captions_height;
|
||||
public:
|
||||
|
||||
table_grid()
|
||||
{
|
||||
public:
|
||||
table_grid() {
|
||||
m_rows_count = 0;
|
||||
m_cols_count = 0;
|
||||
m_captions_height = 0;
|
||||
|
@ -246,6 +226,6 @@ namespace litehtml
|
|||
void calc_vertical_positions(margins& table_borders, border_collapse bc, int bdr_space_y);
|
||||
void calc_rows_height(int blockHeight, int borderSpacingY);
|
||||
};
|
||||
}
|
||||
} // namespace litehtml
|
||||
|
||||
#endif // LH_TABLE_H
|
||||
|
|
|
@ -70,56 +70,25 @@ public:
|
|||
|
||||
tstring_view(const tstring_view& other) = default;
|
||||
|
||||
tstring_view(const_pointer s, size_type size)
|
||||
: data_(s)
|
||||
, size_(size)
|
||||
{
|
||||
}
|
||||
tstring_view(const_pointer s, size_type size) : data_(s), size_(size) {}
|
||||
|
||||
constexpr const_iterator begin() const
|
||||
{
|
||||
return data_;
|
||||
}
|
||||
constexpr const_iterator begin() const { return data_; }
|
||||
|
||||
constexpr const_iterator cbegin() const
|
||||
{
|
||||
return data_;
|
||||
}
|
||||
constexpr const_iterator cbegin() const { return data_; }
|
||||
|
||||
constexpr const_iterator end() const
|
||||
{
|
||||
return data_ + size_;
|
||||
}
|
||||
constexpr const_iterator end() const { return data_ + size_; }
|
||||
|
||||
constexpr const_iterator cend() const
|
||||
{
|
||||
return data_ + size_;
|
||||
}
|
||||
constexpr const_iterator cend() const { return data_ + size_; }
|
||||
|
||||
constexpr const_reference operator[](size_type offset) const
|
||||
{
|
||||
return *(data_ + offset);
|
||||
}
|
||||
constexpr const_reference operator[](size_type offset) const { return *(data_ + offset); }
|
||||
|
||||
constexpr const_pointer data() const
|
||||
{
|
||||
return data_;
|
||||
}
|
||||
constexpr const_pointer data() const { return data_; }
|
||||
|
||||
size_type size() const
|
||||
{
|
||||
return size_;
|
||||
}
|
||||
size_type size() const { return size_; }
|
||||
|
||||
size_type length() const
|
||||
{
|
||||
return size_;
|
||||
}
|
||||
size_type length() const { return size_; }
|
||||
|
||||
bool empty() const
|
||||
{
|
||||
return (size_ == 0);
|
||||
}
|
||||
bool empty() const { return (size_ == 0); }
|
||||
|
||||
private:
|
||||
const_pointer data_ = nullptr;
|
||||
|
@ -127,9 +96,7 @@ private:
|
|||
size_type size_ = 0;
|
||||
};
|
||||
|
||||
std::basic_ostream<tstring_view::value_type>& operator<<(
|
||||
std::basic_ostream<tstring_view::value_type>&,
|
||||
tstring_view str);
|
||||
std::basic_ostream<tstring_view::value_type>& operator<<(std::basic_ostream<tstring_view::value_type>&, tstring_view str);
|
||||
|
||||
} // namespace litehtml
|
||||
|
||||
|
|
|
@ -2,12 +2,12 @@
|
|||
#define LH_TYPES_H
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <memory>
|
||||
|
||||
#include <map>
|
||||
#include <memory>
|
||||
#include <vector>
|
||||
|
||||
namespace litehtml
|
||||
{
|
||||
namespace litehtml {
|
||||
class document;
|
||||
class element;
|
||||
|
||||
|
@ -24,36 +24,29 @@ namespace litehtml
|
|||
typedef unsigned char byte;
|
||||
typedef unsigned int ucode_t;
|
||||
|
||||
struct margins
|
||||
{
|
||||
struct margins {
|
||||
int left;
|
||||
int right;
|
||||
int top;
|
||||
int bottom;
|
||||
|
||||
margins()
|
||||
{
|
||||
left = right = top = bottom = 0;
|
||||
}
|
||||
margins() { left = right = top = bottom = 0; }
|
||||
|
||||
int width() const { return left + right; }
|
||||
int height() const { return top + bottom; }
|
||||
};
|
||||
|
||||
struct size
|
||||
{
|
||||
struct size {
|
||||
int width;
|
||||
int height;
|
||||
|
||||
size()
|
||||
{
|
||||
size() {
|
||||
width = 0;
|
||||
height = 0;
|
||||
}
|
||||
};
|
||||
|
||||
struct position
|
||||
{
|
||||
struct position {
|
||||
typedef std::vector<position> vector;
|
||||
|
||||
int x;
|
||||
|
@ -61,13 +54,9 @@ namespace litehtml
|
|||
int width;
|
||||
int height;
|
||||
|
||||
position()
|
||||
{
|
||||
x = y = width = height = 0;
|
||||
}
|
||||
position() { x = y = width = height = 0; }
|
||||
|
||||
position(int x, int y, int width, int height)
|
||||
{
|
||||
position(int x, int y, int width, int height) {
|
||||
this->x = x;
|
||||
this->y = y;
|
||||
this->width = width;
|
||||
|
@ -79,83 +68,60 @@ namespace litehtml
|
|||
int left() const { return x; }
|
||||
int top() const { return y; }
|
||||
|
||||
void operator+=(const margins& mg)
|
||||
{
|
||||
void operator+=(const margins& mg) {
|
||||
x -= mg.left;
|
||||
y -= mg.top;
|
||||
width += mg.left + mg.right;
|
||||
height += mg.top + mg.bottom;
|
||||
}
|
||||
void operator-=(const margins& mg)
|
||||
{
|
||||
void operator-=(const margins& mg) {
|
||||
x += mg.left;
|
||||
y += mg.top;
|
||||
width -= mg.left + mg.right;
|
||||
height -= mg.top + mg.bottom;
|
||||
}
|
||||
|
||||
void clear()
|
||||
{
|
||||
x = y = width = height = 0;
|
||||
}
|
||||
void clear() { x = y = width = height = 0; }
|
||||
|
||||
void operator=(const size& sz)
|
||||
{
|
||||
void operator=(const size& sz) {
|
||||
width = sz.width;
|
||||
height = sz.height;
|
||||
}
|
||||
|
||||
void move_to(int x, int y)
|
||||
{
|
||||
void move_to(int x, int y) {
|
||||
this->x = x;
|
||||
this->y = y;
|
||||
}
|
||||
|
||||
bool does_intersect(const position* val) const
|
||||
{
|
||||
bool does_intersect(const position* val) const {
|
||||
if (!val) return true;
|
||||
|
||||
return (
|
||||
left() <= val->right() &&
|
||||
right() >= val->left() &&
|
||||
bottom() >= val->top() &&
|
||||
top() <= val->bottom() )
|
||||
|| (
|
||||
val->left() <= right() &&
|
||||
val->right() >= left() &&
|
||||
val->bottom() >= top() &&
|
||||
val->top() <= bottom() );
|
||||
return (left() <= val->right() && right() >= val->left() && bottom() >= val->top() && top() <= val->bottom()) || (val->left() <= right() && val->right() >= left() && val->bottom() >= top() && val->top() <= bottom());
|
||||
}
|
||||
|
||||
bool empty() const
|
||||
{
|
||||
if(!width && !height)
|
||||
{
|
||||
bool empty() const {
|
||||
if (!width && !height) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
bool is_point_inside(int x, int y) const
|
||||
{
|
||||
if(x >= left() && x <= right() && y >= top() && y <= bottom())
|
||||
{
|
||||
bool is_point_inside(int x, int y) const {
|
||||
if (x >= left() && x <= right() && y >= top() && y <= bottom()) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
};
|
||||
|
||||
struct font_metrics
|
||||
{
|
||||
struct font_metrics {
|
||||
int height;
|
||||
int ascent;
|
||||
int descent;
|
||||
int x_height;
|
||||
bool draw_spaces;
|
||||
|
||||
font_metrics()
|
||||
{
|
||||
font_metrics() {
|
||||
height = 0;
|
||||
ascent = 0;
|
||||
descent = 0;
|
||||
|
@ -165,16 +131,14 @@ namespace litehtml
|
|||
int base_line() { return descent; }
|
||||
};
|
||||
|
||||
struct font_item
|
||||
{
|
||||
struct font_item {
|
||||
uint_ptr font;
|
||||
font_metrics metrics;
|
||||
};
|
||||
|
||||
typedef std::map<tstring, font_item> fonts_map;
|
||||
|
||||
enum draw_flag
|
||||
{
|
||||
enum draw_flag {
|
||||
draw_root,
|
||||
draw_block,
|
||||
draw_floats,
|
||||
|
@ -184,8 +148,7 @@ namespace litehtml
|
|||
|
||||
#define style_display_strings _t("none;block;inline;inline-block;inline-table;list-item;table;table-caption;table-cell;table-column;table-column-group;table-footer-group;table-header-group;table-row;table-row-group;inline-text")
|
||||
|
||||
enum style_display
|
||||
{
|
||||
enum style_display {
|
||||
display_none,
|
||||
display_block,
|
||||
display_inline,
|
||||
|
@ -204,21 +167,11 @@ namespace litehtml
|
|||
display_inline_text,
|
||||
};
|
||||
|
||||
enum style_border
|
||||
{
|
||||
borderNope,
|
||||
borderNone,
|
||||
borderHidden,
|
||||
borderDotted,
|
||||
borderDashed,
|
||||
borderSolid,
|
||||
borderDouble
|
||||
};
|
||||
enum style_border { borderNope, borderNone, borderHidden, borderDotted, borderDashed, borderSolid, borderDouble };
|
||||
|
||||
#define font_size_strings _t("xx-small;x-small;small;medium;large;x-large;xx-large;smaller;larger")
|
||||
|
||||
enum font_size
|
||||
{
|
||||
enum font_size {
|
||||
fontSize_xx_small,
|
||||
fontSize_x_small,
|
||||
fontSize_small,
|
||||
|
@ -232,41 +185,19 @@ namespace litehtml
|
|||
|
||||
#define font_style_strings _t("normal;italic")
|
||||
|
||||
enum font_style
|
||||
{
|
||||
fontStyleNormal,
|
||||
fontStyleItalic
|
||||
};
|
||||
enum font_style { fontStyleNormal, fontStyleItalic };
|
||||
|
||||
#define font_variant_strings _t("normal;small-caps")
|
||||
|
||||
enum font_variant
|
||||
{
|
||||
font_variant_normal,
|
||||
font_variant_italic
|
||||
};
|
||||
enum font_variant { font_variant_normal, font_variant_italic };
|
||||
|
||||
#define font_weight_strings _t("normal;bold;bolder;lighter;100;200;300;400;500;600;700")
|
||||
|
||||
enum font_weight
|
||||
{
|
||||
fontWeightNormal,
|
||||
fontWeightBold,
|
||||
fontWeightBolder,
|
||||
fontWeightLighter,
|
||||
fontWeight100,
|
||||
fontWeight200,
|
||||
fontWeight300,
|
||||
fontWeight400,
|
||||
fontWeight500,
|
||||
fontWeight600,
|
||||
fontWeight700
|
||||
};
|
||||
enum font_weight { fontWeightNormal, fontWeightBold, fontWeightBolder, fontWeightLighter, fontWeight100, fontWeight200, fontWeight300, fontWeight400, fontWeight500, fontWeight600, fontWeight700 };
|
||||
|
||||
#define list_style_type_strings _t("none;circle;disc;square;armenian;cjk-ideographic;decimal;decimal-leading-zero;georgian;hebrew;hiragana;hiragana-iroha;katakana;katakana-iroha;lower-alpha;lower-greek;lower-latin;lower-roman;upper-alpha;upper-latin;upper-roman")
|
||||
|
||||
enum list_style_type
|
||||
{
|
||||
enum list_style_type {
|
||||
list_style_type_none,
|
||||
list_style_type_circle,
|
||||
list_style_type_disc,
|
||||
|
@ -292,74 +223,31 @@ namespace litehtml
|
|||
|
||||
#define list_style_position_strings _t("inside;outside")
|
||||
|
||||
enum list_style_position
|
||||
{
|
||||
list_style_position_inside,
|
||||
list_style_position_outside
|
||||
};
|
||||
enum list_style_position { list_style_position_inside, list_style_position_outside };
|
||||
|
||||
#define vertical_align_strings _t("baseline;sub;super;top;text-top;middle;bottom;text-bottom")
|
||||
|
||||
enum vertical_align
|
||||
{
|
||||
va_baseline,
|
||||
va_sub,
|
||||
va_super,
|
||||
va_top,
|
||||
va_text_top,
|
||||
va_middle,
|
||||
va_bottom,
|
||||
va_text_bottom
|
||||
};
|
||||
enum vertical_align { va_baseline, va_sub, va_super, va_top, va_text_top, va_middle, va_bottom, va_text_bottom };
|
||||
|
||||
#define border_width_strings _t("thin;medium;thick")
|
||||
|
||||
enum border_width
|
||||
{
|
||||
border_width_thin,
|
||||
border_width_medium,
|
||||
border_width_thick
|
||||
};
|
||||
enum border_width { border_width_thin, border_width_medium, border_width_thick };
|
||||
|
||||
#define border_style_strings _t("none;hidden;dotted;dashed;solid;double;groove;ridge;inset;outset")
|
||||
|
||||
enum border_style
|
||||
{
|
||||
border_style_none,
|
||||
border_style_hidden,
|
||||
border_style_dotted,
|
||||
border_style_dashed,
|
||||
border_style_solid,
|
||||
border_style_double,
|
||||
border_style_groove,
|
||||
border_style_ridge,
|
||||
border_style_inset,
|
||||
border_style_outset
|
||||
};
|
||||
enum border_style { border_style_none, border_style_hidden, border_style_dotted, border_style_dashed, border_style_solid, border_style_double, border_style_groove, border_style_ridge, border_style_inset, border_style_outset };
|
||||
|
||||
#define element_float_strings _t("none;left;right")
|
||||
|
||||
enum element_float
|
||||
{
|
||||
float_none,
|
||||
float_left,
|
||||
float_right
|
||||
};
|
||||
enum element_float { float_none, float_left, float_right };
|
||||
|
||||
#define element_clear_strings _t("none;left;right;both")
|
||||
|
||||
enum element_clear
|
||||
{
|
||||
clear_none,
|
||||
clear_left,
|
||||
clear_right,
|
||||
clear_both
|
||||
};
|
||||
enum element_clear { clear_none, clear_left, clear_right, clear_both };
|
||||
|
||||
#define css_units_strings _t("none;%;in;cm;mm;em;ex;pt;pc;px;dpi;dpcm;vw;vh;vmin;vmax;rem")
|
||||
|
||||
enum css_units
|
||||
{
|
||||
enum css_units {
|
||||
css_units_none,
|
||||
css_units_percentage,
|
||||
css_units_in,
|
||||
|
@ -381,35 +269,19 @@ namespace litehtml
|
|||
|
||||
#define background_attachment_strings _t("scroll;fixed")
|
||||
|
||||
enum background_attachment
|
||||
{
|
||||
background_attachment_scroll,
|
||||
background_attachment_fixed
|
||||
};
|
||||
enum background_attachment { background_attachment_scroll, background_attachment_fixed };
|
||||
|
||||
#define background_repeat_strings _t("repeat;repeat-x;repeat-y;no-repeat")
|
||||
|
||||
enum background_repeat
|
||||
{
|
||||
background_repeat_repeat,
|
||||
background_repeat_repeat_x,
|
||||
background_repeat_repeat_y,
|
||||
background_repeat_no_repeat
|
||||
};
|
||||
enum background_repeat { background_repeat_repeat, background_repeat_repeat_x, background_repeat_repeat_y, background_repeat_no_repeat };
|
||||
|
||||
#define background_box_strings _t("border-box;padding-box;content-box")
|
||||
|
||||
enum background_box
|
||||
{
|
||||
background_box_border,
|
||||
background_box_padding,
|
||||
background_box_content
|
||||
};
|
||||
enum background_box { background_box_border, background_box_padding, background_box_content };
|
||||
|
||||
#define element_position_strings _t("static;relative;absolute;fixed")
|
||||
|
||||
enum element_position
|
||||
{
|
||||
enum element_position {
|
||||
element_position_static,
|
||||
element_position_relative,
|
||||
element_position_absolute,
|
||||
|
@ -418,51 +290,23 @@ namespace litehtml
|
|||
|
||||
#define text_align_strings _t("left;right;center;justify")
|
||||
|
||||
enum text_align
|
||||
{
|
||||
text_align_left,
|
||||
text_align_right,
|
||||
text_align_center,
|
||||
text_align_justify
|
||||
};
|
||||
enum text_align { text_align_left, text_align_right, text_align_center, text_align_justify };
|
||||
|
||||
#define text_transform_strings _t("none;capitalize;uppercase;lowercase")
|
||||
|
||||
enum text_transform
|
||||
{
|
||||
text_transform_none,
|
||||
text_transform_capitalize,
|
||||
text_transform_uppercase,
|
||||
text_transform_lowercase
|
||||
};
|
||||
enum text_transform { text_transform_none, text_transform_capitalize, text_transform_uppercase, text_transform_lowercase };
|
||||
|
||||
#define white_space_strings _t("normal;nowrap;pre;pre-line;pre-wrap")
|
||||
|
||||
enum white_space
|
||||
{
|
||||
white_space_normal,
|
||||
white_space_nowrap,
|
||||
white_space_pre,
|
||||
white_space_pre_line,
|
||||
white_space_pre_wrap
|
||||
};
|
||||
enum white_space { white_space_normal, white_space_nowrap, white_space_pre, white_space_pre_line, white_space_pre_wrap };
|
||||
|
||||
#define overflow_strings _t("visible;hidden;scroll;auto;no-display;no-content")
|
||||
|
||||
enum overflow
|
||||
{
|
||||
overflow_visible,
|
||||
overflow_hidden,
|
||||
overflow_scroll,
|
||||
overflow_auto,
|
||||
overflow_no_display,
|
||||
overflow_no_content
|
||||
};
|
||||
enum overflow { overflow_visible, overflow_hidden, overflow_scroll, overflow_auto, overflow_no_display, overflow_no_content };
|
||||
|
||||
#define background_size_strings _t("auto;cover;contain")
|
||||
|
||||
enum background_size
|
||||
{
|
||||
enum background_size {
|
||||
background_size_auto,
|
||||
background_size_cover,
|
||||
background_size_contain,
|
||||
|
@ -470,8 +314,7 @@ namespace litehtml
|
|||
|
||||
#define visibility_strings _t("visible;hidden;collapse")
|
||||
|
||||
enum visibility
|
||||
{
|
||||
enum visibility {
|
||||
visibility_visible,
|
||||
visibility_hidden,
|
||||
visibility_collapse,
|
||||
|
@ -479,17 +322,14 @@ namespace litehtml
|
|||
|
||||
#define border_collapse_strings _t("collapse;separate")
|
||||
|
||||
enum border_collapse
|
||||
{
|
||||
enum border_collapse {
|
||||
border_collapse_collapse,
|
||||
border_collapse_separate,
|
||||
};
|
||||
|
||||
|
||||
#define pseudo_class_strings _t("only-child;only-of-type;first-child;first-of-type;last-child;last-of-type;nth-child;nth-of-type;nth-last-child;nth-last-of-type;not;lang")
|
||||
|
||||
enum pseudo_class
|
||||
{
|
||||
enum pseudo_class {
|
||||
pseudo_class_only_child,
|
||||
pseudo_class_only_of_type,
|
||||
pseudo_class_first_child,
|
||||
|
@ -506,8 +346,7 @@ namespace litehtml
|
|||
|
||||
#define content_property_string _t("none;normal;open-quote;close-quote;no-open-quote;no-close-quote")
|
||||
|
||||
enum content_property
|
||||
{
|
||||
enum content_property {
|
||||
content_property_none,
|
||||
content_property_normal,
|
||||
content_property_open_quote,
|
||||
|
@ -516,9 +355,7 @@ namespace litehtml
|
|||
content_property_no_close_quote,
|
||||
};
|
||||
|
||||
|
||||
struct floated_box
|
||||
{
|
||||
struct floated_box {
|
||||
typedef std::vector<floated_box> vector;
|
||||
|
||||
position pos;
|
||||
|
@ -527,30 +364,26 @@ namespace litehtml
|
|||
std::shared_ptr<element> el;
|
||||
|
||||
floated_box() = default;
|
||||
floated_box(const floated_box& val)
|
||||
{
|
||||
floated_box(const floated_box& val) {
|
||||
pos = val.pos;
|
||||
float_side = val.float_side;
|
||||
clear_floats = val.clear_floats;
|
||||
el = val.el;
|
||||
}
|
||||
floated_box& operator=(const floated_box& val)
|
||||
{
|
||||
floated_box& operator=(const floated_box& val) {
|
||||
pos = val.pos;
|
||||
float_side = val.float_side;
|
||||
clear_floats = val.clear_floats;
|
||||
el = val.el;
|
||||
return *this;
|
||||
}
|
||||
floated_box(floated_box&& val)
|
||||
{
|
||||
floated_box(floated_box&& val) {
|
||||
pos = val.pos;
|
||||
float_side = val.float_side;
|
||||
clear_floats = val.clear_floats;
|
||||
el = std::move(val.el);
|
||||
}
|
||||
void operator=(floated_box&& val)
|
||||
{
|
||||
void operator=(floated_box&& val) {
|
||||
pos = val.pos;
|
||||
float_side = val.float_side;
|
||||
clear_floats = val.clear_floats;
|
||||
|
@ -558,35 +391,30 @@ namespace litehtml
|
|||
}
|
||||
};
|
||||
|
||||
struct int_int_cache
|
||||
{
|
||||
struct int_int_cache {
|
||||
int hash;
|
||||
int val;
|
||||
bool is_valid;
|
||||
bool is_default;
|
||||
|
||||
int_int_cache()
|
||||
{
|
||||
int_int_cache() {
|
||||
hash = 0;
|
||||
val = 0;
|
||||
is_valid = false;
|
||||
is_default = false;
|
||||
}
|
||||
void invalidate()
|
||||
{
|
||||
void invalidate() {
|
||||
is_valid = false;
|
||||
is_default = false;
|
||||
}
|
||||
void set_value(int vHash, int vVal)
|
||||
{
|
||||
void set_value(int vHash, int vVal) {
|
||||
hash = vHash;
|
||||
val = vVal;
|
||||
is_valid = true;
|
||||
}
|
||||
};
|
||||
|
||||
enum select_result
|
||||
{
|
||||
enum select_result {
|
||||
select_no_match = 0x00,
|
||||
select_match = 0x01,
|
||||
select_match_pseudo_class = 0x02,
|
||||
|
@ -595,50 +423,38 @@ namespace litehtml
|
|||
};
|
||||
|
||||
template <class T>
|
||||
class def_value
|
||||
{
|
||||
class def_value {
|
||||
T m_val;
|
||||
bool m_is_default;
|
||||
|
||||
public:
|
||||
def_value(T def_val)
|
||||
{
|
||||
def_value(T def_val) {
|
||||
m_is_default = true;
|
||||
m_val = def_val;
|
||||
}
|
||||
void reset(T def_val)
|
||||
{
|
||||
void reset(T def_val) {
|
||||
m_is_default = true;
|
||||
m_val = def_val;
|
||||
}
|
||||
bool is_default()
|
||||
{
|
||||
return m_is_default;
|
||||
}
|
||||
T operator=(T new_val)
|
||||
{
|
||||
bool is_default() { return m_is_default; }
|
||||
T operator=(T new_val) {
|
||||
m_val = new_val;
|
||||
m_is_default = false;
|
||||
return m_val;
|
||||
}
|
||||
operator T()
|
||||
{
|
||||
return m_val;
|
||||
}
|
||||
operator T() { return m_val; }
|
||||
};
|
||||
|
||||
|
||||
#define media_orientation_strings _t("portrait;landscape")
|
||||
|
||||
enum media_orientation
|
||||
{
|
||||
enum media_orientation {
|
||||
media_orientation_portrait,
|
||||
media_orientation_landscape,
|
||||
};
|
||||
|
||||
#define media_feature_strings _t("none;width;min-width;max-width;height;min-height;max-height;device-width;min-device-width;max-device-width;device-height;min-device-height;max-device-height;orientation;aspect-ratio;min-aspect-ratio;max-aspect-ratio;device-aspect-ratio;min-device-aspect-ratio;max-device-aspect-ratio;color;min-color;max-color;color-index;min-color-index;max-color-index;monochrome;min-monochrome;max-monochrome;resolution;min-resolution;max-resolution")
|
||||
|
||||
enum media_feature
|
||||
{
|
||||
enum media_feature {
|
||||
media_feature_none,
|
||||
|
||||
media_feature_width,
|
||||
|
@ -686,17 +502,14 @@ namespace litehtml
|
|||
|
||||
#define box_sizing_strings _t("content-box;border-box")
|
||||
|
||||
enum box_sizing
|
||||
{
|
||||
enum box_sizing {
|
||||
box_sizing_content_box,
|
||||
box_sizing_border_box,
|
||||
};
|
||||
|
||||
|
||||
#define media_type_strings _t("none;all;screen;print;braille;embossed;handheld;projection;speech;tty;tv")
|
||||
|
||||
enum media_type
|
||||
{
|
||||
enum media_type {
|
||||
media_type_none,
|
||||
media_type_all,
|
||||
media_type_screen,
|
||||
|
@ -710,8 +523,7 @@ namespace litehtml
|
|||
media_type_tv,
|
||||
};
|
||||
|
||||
struct media_features
|
||||
{
|
||||
struct media_features {
|
||||
media_type type;
|
||||
int width; // (pixels) For continuous media, this is the width of the viewport including the size of a rendered scroll bar (if any). For paged media, this is the width of the page box.
|
||||
int height; // (pixels) The height of the targeted display area of the output device. For continuous media, this is the height of the viewport including the size of a rendered scroll bar (if any). For paged media, this is the height of the page box.
|
||||
|
@ -722,10 +534,8 @@ namespace litehtml
|
|||
int monochrome; // The number of bits per pixel in a monochrome frame buffer. If the device is not a monochrome device, the output device value will be 0.
|
||||
int resolution; // The resolution of the output device (in DPI)
|
||||
|
||||
media_features()
|
||||
{
|
||||
type = media_type::media_type_none,
|
||||
width =0;
|
||||
media_features() {
|
||||
type = media_type::media_type_none, width = 0;
|
||||
height = 0;
|
||||
device_width = 0;
|
||||
device_height = 0;
|
||||
|
@ -736,8 +546,7 @@ namespace litehtml
|
|||
}
|
||||
};
|
||||
|
||||
enum render_type
|
||||
{
|
||||
enum render_type {
|
||||
render_all,
|
||||
render_no_fixed,
|
||||
render_fixed_only,
|
||||
|
@ -745,6 +554,6 @@ namespace litehtml
|
|||
|
||||
// List of the Void Elements (can't have any contents)
|
||||
const litehtml::tchar_t* const void_elements = _t("area;base;br;col;command;embed;hr;img;input;keygen;link;meta;param;source;track;wbr");
|
||||
}
|
||||
} // namespace litehtml
|
||||
|
||||
#endif // LH_TYPES_H
|
||||
|
|
|
@ -44,66 +44,29 @@ public:
|
|||
|
||||
explicit url(const tstring& str);
|
||||
|
||||
url(const tstring& scheme,
|
||||
const tstring& authority,
|
||||
const tstring& path,
|
||||
const tstring& query,
|
||||
const tstring& fragment);
|
||||
url(const tstring& scheme, const tstring& authority, const tstring& path, const tstring& query, const tstring& fragment);
|
||||
|
||||
const tstring& string() const
|
||||
{
|
||||
return str_;
|
||||
}
|
||||
const tstring& string() const { return str_; }
|
||||
|
||||
const tstring& scheme() const
|
||||
{
|
||||
return scheme_;
|
||||
}
|
||||
const tstring& scheme() const { return scheme_; }
|
||||
|
||||
bool has_scheme() const
|
||||
{
|
||||
return !scheme_.empty();
|
||||
}
|
||||
bool has_scheme() const { return !scheme_.empty(); }
|
||||
|
||||
const tstring& authority() const
|
||||
{
|
||||
return authority_;
|
||||
}
|
||||
const tstring& authority() const { return authority_; }
|
||||
|
||||
bool has_authority() const
|
||||
{
|
||||
return !authority_.empty();
|
||||
}
|
||||
bool has_authority() const { return !authority_.empty(); }
|
||||
|
||||
const tstring& path() const
|
||||
{
|
||||
return path_;
|
||||
}
|
||||
const tstring& path() const { return path_; }
|
||||
|
||||
bool has_path() const
|
||||
{
|
||||
return !path_.empty();
|
||||
}
|
||||
bool has_path() const { return !path_.empty(); }
|
||||
|
||||
const tstring& query() const
|
||||
{
|
||||
return query_;
|
||||
}
|
||||
const tstring& query() const { return query_; }
|
||||
|
||||
bool has_query() const
|
||||
{
|
||||
return !query_.empty();
|
||||
}
|
||||
bool has_query() const { return !query_.empty(); }
|
||||
|
||||
const tstring& fragment() const
|
||||
{
|
||||
return fragment_;
|
||||
}
|
||||
const tstring& fragment() const { return fragment_; }
|
||||
|
||||
bool has_fragment() const
|
||||
{
|
||||
return !fragment_.empty();
|
||||
}
|
||||
bool has_fragment() const { return !fragment_.empty(); }
|
||||
|
||||
protected:
|
||||
tstring str_;
|
||||
|
|
|
@ -4,45 +4,32 @@
|
|||
#include "os_types.h"
|
||||
#include "types.h"
|
||||
|
||||
namespace litehtml
|
||||
{
|
||||
class utf8_to_wchar
|
||||
{
|
||||
namespace litehtml {
|
||||
class utf8_to_wchar {
|
||||
const byte* m_utf8;
|
||||
std::wstring m_str;
|
||||
|
||||
public:
|
||||
utf8_to_wchar(const char* val);
|
||||
operator const wchar_t*() const
|
||||
{
|
||||
return m_str.c_str();
|
||||
}
|
||||
operator const wchar_t*() const { return m_str.c_str(); }
|
||||
|
||||
private:
|
||||
ucode_t getb()
|
||||
{
|
||||
ucode_t getb() {
|
||||
if (!(*m_utf8)) return 0;
|
||||
return *m_utf8++;
|
||||
}
|
||||
ucode_t get_next_utf8(ucode_t val)
|
||||
{
|
||||
return (val & 0x3f);
|
||||
}
|
||||
ucode_t get_next_utf8(ucode_t val) { return (val & 0x3f); }
|
||||
ucode_t get_char();
|
||||
};
|
||||
|
||||
class wchar_to_utf8
|
||||
{
|
||||
class wchar_to_utf8 {
|
||||
std::string m_str;
|
||||
|
||||
public:
|
||||
wchar_to_utf8(const std::wstring& val);
|
||||
operator const char*() const
|
||||
{
|
||||
return m_str.c_str();
|
||||
}
|
||||
operator const char*() const { return m_str.c_str(); }
|
||||
|
||||
const char* c_str() const
|
||||
{
|
||||
return m_str.c_str();
|
||||
}
|
||||
const char* c_str() const { return m_str.c_str(); }
|
||||
};
|
||||
|
||||
#ifdef LITEHTML_UTF8
|
||||
|
@ -54,6 +41,6 @@ namespace litehtml
|
|||
#define litehtml_from_wchar(str) str
|
||||
#define litehtml_to_utf8(str) litehtml::wchar_to_utf8(str)
|
||||
#endif
|
||||
}
|
||||
} // namespace litehtml
|
||||
|
||||
#endif // LH_UTF8_STRINGS_H
|
||||
|
|
|
@ -1,10 +1,8 @@
|
|||
#ifndef LH_WEB_COLOR_H
|
||||
#define LH_WEB_COLOR_H
|
||||
|
||||
namespace litehtml
|
||||
{
|
||||
struct def_color
|
||||
{
|
||||
namespace litehtml {
|
||||
struct def_color {
|
||||
const tchar_t* name;
|
||||
const tchar_t* rgb;
|
||||
};
|
||||
|
@ -13,39 +11,34 @@ namespace litehtml
|
|||
|
||||
class document_container;
|
||||
|
||||
struct web_color
|
||||
{
|
||||
struct web_color {
|
||||
byte blue;
|
||||
byte green;
|
||||
byte red;
|
||||
byte alpha;
|
||||
|
||||
web_color(byte r, byte g, byte b, byte a = 255)
|
||||
{
|
||||
web_color(byte r, byte g, byte b, byte a = 255) {
|
||||
blue = b;
|
||||
green = g;
|
||||
red = r;
|
||||
alpha = a;
|
||||
}
|
||||
|
||||
web_color()
|
||||
{
|
||||
web_color() {
|
||||
blue = 0;
|
||||
green = 0;
|
||||
red = 0;
|
||||
alpha = 0xFF;
|
||||
}
|
||||
|
||||
web_color(const web_color& val)
|
||||
{
|
||||
web_color(const web_color& val) {
|
||||
blue = val.blue;
|
||||
green = val.green;
|
||||
red = val.red;
|
||||
alpha = val.alpha;
|
||||
}
|
||||
|
||||
web_color& operator=(const web_color& val)
|
||||
{
|
||||
web_color& operator=(const web_color& val) {
|
||||
blue = val.blue;
|
||||
green = val.green;
|
||||
red = val.red;
|
||||
|
@ -56,6 +49,6 @@ namespace litehtml
|
|||
static litehtml::tstring resolve_name(const tchar_t* name, litehtml::document_container* callback);
|
||||
static bool is_color(const tchar_t* str);
|
||||
};
|
||||
}
|
||||
} // namespace litehtml
|
||||
|
||||
#endif // LH_WEB_COLOR_H
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
#include "html.h"
|
||||
#include "background.h"
|
||||
|
||||
litehtml::background::background()
|
||||
{
|
||||
#include "html.h"
|
||||
|
||||
litehtml::background::background() {
|
||||
m_attachment = background_attachment_scroll;
|
||||
m_repeat = background_repeat_repeat;
|
||||
m_clip = background_box_border;
|
||||
|
@ -13,8 +13,7 @@ litehtml::background::background()
|
|||
m_color.blue = 0;
|
||||
}
|
||||
|
||||
litehtml::background::background( const background& val )
|
||||
{
|
||||
litehtml::background::background(const background& val) {
|
||||
m_image = val.m_image;
|
||||
m_baseurl = val.m_baseurl;
|
||||
m_color = val.m_color;
|
||||
|
@ -25,8 +24,7 @@ litehtml::background::background( const background& val )
|
|||
m_origin = val.m_origin;
|
||||
}
|
||||
|
||||
litehtml::background& litehtml::background::operator=( const background& val )
|
||||
{
|
||||
litehtml::background& litehtml::background::operator=(const background& val) {
|
||||
m_image = val.m_image;
|
||||
m_baseurl = val.m_baseurl;
|
||||
m_color = val.m_color;
|
||||
|
@ -38,9 +36,7 @@ litehtml::background& litehtml::background::operator=( const background& val )
|
|||
return *this;
|
||||
}
|
||||
|
||||
|
||||
litehtml::background_paint::background_paint() : color(0, 0, 0, 0)
|
||||
{
|
||||
litehtml::background_paint::background_paint() : color(0, 0, 0, 0) {
|
||||
position_x = 0;
|
||||
position_y = 0;
|
||||
attachment = background_attachment_scroll;
|
||||
|
@ -48,8 +44,7 @@ litehtml::background_paint::background_paint() : color(0, 0, 0, 0)
|
|||
is_root = false;
|
||||
}
|
||||
|
||||
litehtml::background_paint::background_paint( const background_paint& val )
|
||||
{
|
||||
litehtml::background_paint::background_paint(const background_paint& val) {
|
||||
image = val.image;
|
||||
baseurl = val.baseurl;
|
||||
attachment = val.attachment;
|
||||
|
@ -65,8 +60,7 @@ litehtml::background_paint::background_paint( const background_paint& val )
|
|||
is_root = val.is_root;
|
||||
}
|
||||
|
||||
litehtml::background_paint& litehtml::background_paint::operator=( const background& val )
|
||||
{
|
||||
litehtml::background_paint& litehtml::background_paint::operator=(const background& val) {
|
||||
attachment = val.m_attachment;
|
||||
baseurl = val.m_baseurl;
|
||||
image = val.m_image;
|
||||
|
|
|
@ -1,140 +1,96 @@
|
|||
#include "html.h"
|
||||
#include "box.h"
|
||||
|
||||
#include "html.h"
|
||||
#include "html_tag.h"
|
||||
|
||||
litehtml::box_type litehtml::block_box::get_type() const { return box_block; }
|
||||
|
||||
litehtml::box_type litehtml::block_box::get_type() const
|
||||
{
|
||||
return box_block;
|
||||
}
|
||||
int litehtml::block_box::height() const { return m_element->height(); }
|
||||
|
||||
int litehtml::block_box::height() const
|
||||
{
|
||||
return m_element->height();
|
||||
}
|
||||
int litehtml::block_box::width() const { return m_element->width(); }
|
||||
|
||||
int litehtml::block_box::width() const
|
||||
{
|
||||
return m_element->width();
|
||||
}
|
||||
|
||||
void litehtml::block_box::add_element(const element::ptr &el)
|
||||
{
|
||||
void litehtml::block_box::add_element(const element::ptr& el) {
|
||||
m_element = el;
|
||||
el->m_box = this;
|
||||
}
|
||||
|
||||
void litehtml::block_box::finish(bool last_box)
|
||||
{
|
||||
void litehtml::block_box::finish(bool last_box) {
|
||||
if (!m_element) return;
|
||||
m_element->apply_relative_shift(m_box_right - m_box_left);
|
||||
}
|
||||
|
||||
bool litehtml::block_box::can_hold(const element::ptr &el, white_space ws) const
|
||||
{
|
||||
if(m_element || el->is_inline_box())
|
||||
{
|
||||
bool litehtml::block_box::can_hold(const element::ptr& el, white_space ws) const {
|
||||
if (m_element || el->is_inline_box()) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
bool litehtml::block_box::is_empty() const
|
||||
{
|
||||
if(m_element)
|
||||
{
|
||||
bool litehtml::block_box::is_empty() const {
|
||||
if (m_element) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
int litehtml::block_box::baseline() const
|
||||
{
|
||||
if(m_element)
|
||||
{
|
||||
int litehtml::block_box::baseline() const {
|
||||
if (m_element) {
|
||||
return m_element->get_base_line();
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
void litehtml::block_box::get_elements( elements_vector& els )
|
||||
{
|
||||
els.push_back(m_element);
|
||||
}
|
||||
void litehtml::block_box::get_elements(elements_vector& els) { els.push_back(m_element); }
|
||||
|
||||
int litehtml::block_box::top_margin() const
|
||||
{
|
||||
if(m_element && m_element->collapse_top_margin())
|
||||
{
|
||||
int litehtml::block_box::top_margin() const {
|
||||
if (m_element && m_element->collapse_top_margin()) {
|
||||
return m_element->m_margins.top;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
int litehtml::block_box::bottom_margin() const
|
||||
{
|
||||
if(m_element && m_element->collapse_bottom_margin())
|
||||
{
|
||||
int litehtml::block_box::bottom_margin() const {
|
||||
if (m_element && m_element->collapse_bottom_margin()) {
|
||||
return m_element->m_margins.bottom;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
void litehtml::block_box::y_shift( int shift )
|
||||
{
|
||||
void litehtml::block_box::y_shift(int shift) {
|
||||
m_box_top += shift;
|
||||
if(m_element)
|
||||
{
|
||||
if (m_element) {
|
||||
m_element->m_pos.y += shift;
|
||||
}
|
||||
}
|
||||
|
||||
void litehtml::block_box::new_width( int left, int right, elements_vector& els )
|
||||
{
|
||||
|
||||
}
|
||||
void litehtml::block_box::new_width(int left, int right, elements_vector& els) {}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
|
||||
litehtml::box_type litehtml::line_box::get_type() const
|
||||
{
|
||||
return box_line;
|
||||
}
|
||||
litehtml::box_type litehtml::line_box::get_type() const { return box_line; }
|
||||
|
||||
int litehtml::line_box::height() const
|
||||
{
|
||||
return m_height;
|
||||
}
|
||||
int litehtml::line_box::height() const { return m_height; }
|
||||
|
||||
int litehtml::line_box::width() const
|
||||
{
|
||||
return m_width;
|
||||
}
|
||||
int litehtml::line_box::width() const { return m_width; }
|
||||
|
||||
void litehtml::line_box::add_element(const element::ptr &el)
|
||||
{
|
||||
void litehtml::line_box::add_element(const element::ptr& el) {
|
||||
el->m_skip = false;
|
||||
el->m_box = nullptr;
|
||||
bool add = true;
|
||||
if( (m_items.empty() && el->is_white_space()) || el->is_break() )
|
||||
{
|
||||
if ((m_items.empty() && el->is_white_space()) || el->is_break()) {
|
||||
el->m_skip = true;
|
||||
} else if(el->is_white_space())
|
||||
{
|
||||
if (have_last_space())
|
||||
{
|
||||
} else if (el->is_white_space()) {
|
||||
if (have_last_space()) {
|
||||
add = false;
|
||||
el->m_skip = true;
|
||||
}
|
||||
}
|
||||
|
||||
if(add)
|
||||
{
|
||||
if (add) {
|
||||
el->m_box = this;
|
||||
m_items.push_back(el);
|
||||
|
||||
if(!el->m_skip)
|
||||
{
|
||||
if (!el->m_skip) {
|
||||
int el_shift_left = el->get_inline_shift_left();
|
||||
int el_shift_right = el->get_inline_shift_right();
|
||||
|
||||
|
@ -145,25 +101,19 @@ void litehtml::line_box::add_element(const element::ptr &el)
|
|||
}
|
||||
}
|
||||
|
||||
void litehtml::line_box::finish(bool last_box)
|
||||
{
|
||||
if( is_empty() || (!is_empty() && last_box && is_break_only()) )
|
||||
{
|
||||
void litehtml::line_box::finish(bool last_box) {
|
||||
if (is_empty() || (!is_empty() && last_box && is_break_only())) {
|
||||
m_height = 0;
|
||||
return;
|
||||
}
|
||||
|
||||
for(auto i = m_items.rbegin(); i != m_items.rend(); i++)
|
||||
{
|
||||
if((*i)->is_white_space() || (*i)->is_break())
|
||||
{
|
||||
if(!(*i)->m_skip)
|
||||
{
|
||||
for (auto i = m_items.rbegin(); i != m_items.rend(); i++) {
|
||||
if ((*i)->is_white_space() || (*i)->is_break()) {
|
||||
if (!(*i)->m_skip) {
|
||||
(*i)->m_skip = true;
|
||||
m_width -= (*i)->width();
|
||||
}
|
||||
} else
|
||||
{
|
||||
} else {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
@ -172,17 +122,14 @@ void litehtml::line_box::finish(bool last_box)
|
|||
int line_height = m_line_height;
|
||||
|
||||
int add_x = 0;
|
||||
switch(m_text_align)
|
||||
{
|
||||
switch (m_text_align) {
|
||||
case text_align_right:
|
||||
if(m_width < (m_box_right - m_box_left))
|
||||
{
|
||||
if (m_width < (m_box_right - m_box_left)) {
|
||||
add_x = (m_box_right - m_box_left) - m_width;
|
||||
}
|
||||
break;
|
||||
case text_align_center:
|
||||
if(m_width < (m_box_right - m_box_left))
|
||||
{
|
||||
if (m_width < (m_box_right - m_box_left)) {
|
||||
add_x = ((m_box_right - m_box_left) - m_width) / 2;
|
||||
}
|
||||
break;
|
||||
|
@ -192,10 +139,8 @@ void litehtml::line_box::finish(bool last_box)
|
|||
|
||||
m_height = 0;
|
||||
// find line box baseline and line-height
|
||||
for(const auto& el : m_items)
|
||||
{
|
||||
if(el->get_display() == display_inline_text)
|
||||
{
|
||||
for (const auto& el : m_items) {
|
||||
if (el->get_display() == display_inline_text) {
|
||||
font_metrics fm;
|
||||
el->get_font(&fm);
|
||||
base_line = std::max(base_line, fm.base_line());
|
||||
|
@ -205,8 +150,7 @@ void litehtml::line_box::finish(bool last_box)
|
|||
el->m_pos.x += add_x;
|
||||
}
|
||||
|
||||
if(m_height)
|
||||
{
|
||||
if (m_height) {
|
||||
base_line += (line_height - m_height) / 2;
|
||||
}
|
||||
|
||||
|
@ -215,17 +159,13 @@ void litehtml::line_box::finish(bool last_box)
|
|||
int y1 = 0;
|
||||
int y2 = m_height;
|
||||
|
||||
for (const auto& el : m_items)
|
||||
{
|
||||
if(el->get_display() == display_inline_text)
|
||||
{
|
||||
for (const auto& el : m_items) {
|
||||
if (el->get_display() == display_inline_text) {
|
||||
font_metrics fm;
|
||||
el->get_font(&fm);
|
||||
el->m_pos.y = m_height - base_line - fm.ascent;
|
||||
} else
|
||||
{
|
||||
switch(el->get_vertical_align())
|
||||
{
|
||||
} else {
|
||||
switch (el->get_vertical_align()) {
|
||||
case va_super:
|
||||
case va_sub:
|
||||
case va_baseline:
|
||||
|
@ -252,14 +192,11 @@ void litehtml::line_box::finish(bool last_box)
|
|||
}
|
||||
}
|
||||
|
||||
for (const auto& el : m_items)
|
||||
{
|
||||
for (const auto& el : m_items) {
|
||||
el->m_pos.y -= y1;
|
||||
el->m_pos.y += m_box_top;
|
||||
if(el->get_display() != display_inline_text)
|
||||
{
|
||||
switch(el->get_vertical_align())
|
||||
{
|
||||
if (el->get_display() != display_inline_text) {
|
||||
switch (el->get_vertical_align()) {
|
||||
case va_top:
|
||||
el->m_pos.y = m_box_top + el->content_margins_top();
|
||||
break;
|
||||
|
@ -293,96 +230,67 @@ void litehtml::line_box::finish(bool last_box)
|
|||
m_baseline = (base_line - y1) - (m_height - line_height);
|
||||
}
|
||||
|
||||
bool litehtml::line_box::can_hold(const element::ptr &el, white_space ws) const
|
||||
{
|
||||
bool litehtml::line_box::can_hold(const element::ptr& el, white_space ws) const {
|
||||
if (!el->is_inline_box()) return false;
|
||||
|
||||
if(el->is_break())
|
||||
{
|
||||
if (el->is_break()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if(ws == white_space_nowrap || ws == white_space_pre)
|
||||
{
|
||||
if (ws == white_space_nowrap || ws == white_space_pre) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if(m_box_left + m_width + el->width() + el->get_inline_shift_left() + el->get_inline_shift_right() > m_box_right)
|
||||
{
|
||||
if (m_box_left + m_width + el->width() + el->get_inline_shift_left() + el->get_inline_shift_right() > m_box_right) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool litehtml::line_box::have_last_space() const
|
||||
{
|
||||
bool litehtml::line_box::have_last_space() const {
|
||||
bool ret = false;
|
||||
for (auto i = m_items.rbegin(); i != m_items.rend() && !ret; i++)
|
||||
{
|
||||
if((*i)->is_white_space() || (*i)->is_break())
|
||||
{
|
||||
for (auto i = m_items.rbegin(); i != m_items.rend() && !ret; i++) {
|
||||
if ((*i)->is_white_space() || (*i)->is_break()) {
|
||||
ret = true;
|
||||
} else
|
||||
{
|
||||
} else {
|
||||
break;
|
||||
}
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
bool litehtml::line_box::is_empty() const
|
||||
{
|
||||
bool litehtml::line_box::is_empty() const {
|
||||
if (m_items.empty()) return true;
|
||||
for (auto i = m_items.rbegin(); i != m_items.rend(); i++)
|
||||
{
|
||||
if(!(*i)->m_skip || (*i)->is_break())
|
||||
{
|
||||
for (auto i = m_items.rbegin(); i != m_items.rend(); i++) {
|
||||
if (!(*i)->m_skip || (*i)->is_break()) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
int litehtml::line_box::baseline() const
|
||||
{
|
||||
return m_baseline;
|
||||
}
|
||||
int litehtml::line_box::baseline() const { return m_baseline; }
|
||||
|
||||
void litehtml::line_box::get_elements( elements_vector& els )
|
||||
{
|
||||
els.insert(els.begin(), m_items.begin(), m_items.end());
|
||||
}
|
||||
void litehtml::line_box::get_elements(elements_vector& els) { els.insert(els.begin(), m_items.begin(), m_items.end()); }
|
||||
|
||||
int litehtml::line_box::top_margin() const
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
int litehtml::line_box::top_margin() const { return 0; }
|
||||
|
||||
int litehtml::line_box::bottom_margin() const
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
int litehtml::line_box::bottom_margin() const { return 0; }
|
||||
|
||||
void litehtml::line_box::y_shift( int shift )
|
||||
{
|
||||
void litehtml::line_box::y_shift(int shift) {
|
||||
m_box_top += shift;
|
||||
for (auto& el : m_items)
|
||||
{
|
||||
for (auto& el : m_items) {
|
||||
el->m_pos.y += shift;
|
||||
}
|
||||
}
|
||||
|
||||
bool litehtml::line_box::is_break_only() const
|
||||
{
|
||||
bool litehtml::line_box::is_break_only() const {
|
||||
if (m_items.empty()) return true;
|
||||
|
||||
if(m_items.front()->is_break())
|
||||
{
|
||||
for (auto& el : m_items)
|
||||
{
|
||||
if(!el->m_skip)
|
||||
{
|
||||
if (m_items.front()->is_break()) {
|
||||
for (auto& el : m_items) {
|
||||
if (!el->m_skip) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
@ -391,42 +299,33 @@ bool litehtml::line_box::is_break_only() const
|
|||
return false;
|
||||
}
|
||||
|
||||
void litehtml::line_box::new_width( int left, int right, elements_vector& els )
|
||||
{
|
||||
void litehtml::line_box::new_width(int left, int right, elements_vector& els) {
|
||||
int add = left - m_box_left;
|
||||
if(add)
|
||||
{
|
||||
if (add) {
|
||||
m_box_left = left;
|
||||
m_box_right = right;
|
||||
m_width = 0;
|
||||
auto remove_begin = m_items.end();
|
||||
for (auto i = m_items.begin() + 1; i != m_items.end(); i++)
|
||||
{
|
||||
for (auto i = m_items.begin() + 1; i != m_items.end(); i++) {
|
||||
element::ptr el = (*i);
|
||||
|
||||
if(!el->m_skip)
|
||||
{
|
||||
if(m_box_left + m_width + el->width() + el->get_inline_shift_right() + el->get_inline_shift_left() > m_box_right)
|
||||
{
|
||||
if (!el->m_skip) {
|
||||
if (m_box_left + m_width + el->width() + el->get_inline_shift_right() + el->get_inline_shift_left() > m_box_right) {
|
||||
remove_begin = i;
|
||||
break;
|
||||
} else
|
||||
{
|
||||
} else {
|
||||
el->m_pos.x += add;
|
||||
m_width += el->width() + el->get_inline_shift_right() + el->get_inline_shift_left();
|
||||
}
|
||||
}
|
||||
}
|
||||
if(remove_begin != m_items.end())
|
||||
{
|
||||
if (remove_begin != m_items.end()) {
|
||||
els.insert(els.begin(), remove_begin, m_items.end());
|
||||
m_items.erase(remove_begin, m_items.end());
|
||||
|
||||
for(const auto& el : els)
|
||||
{
|
||||
for (const auto& el : els) {
|
||||
el->m_box = nullptr;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -33,29 +33,17 @@
|
|||
|
||||
namespace {
|
||||
|
||||
bool lookup(const uint32_t* table, litehtml::tchar_t c)
|
||||
{
|
||||
return table[c >> 5] & (1 << (c & 0x1f));
|
||||
}
|
||||
bool lookup(const uint32_t* table, litehtml::tchar_t c) { return table[c >> 5] & (1 << (c & 0x1f)); }
|
||||
|
||||
} // namespace
|
||||
|
||||
namespace litehtml {
|
||||
|
||||
bool is_ascii_codepoint(litehtml::tchar_t c)
|
||||
{
|
||||
return (c < 128);
|
||||
}
|
||||
bool is_ascii_codepoint(litehtml::tchar_t c) { return (c < 128); }
|
||||
|
||||
// https://datatracker.ietf.org/doc/html/rfc3986#section-2.2
|
||||
bool is_url_reserved_codepoint(litehtml::tchar_t c)
|
||||
{
|
||||
static const uint32_t reserved_lookup[] = {
|
||||
0x00000000,
|
||||
0xac009fda,
|
||||
0x28000001,
|
||||
0x00000000
|
||||
};
|
||||
bool is_url_reserved_codepoint(litehtml::tchar_t c) {
|
||||
static const uint32_t reserved_lookup[] = {0x00000000, 0xac009fda, 0x28000001, 0x00000000};
|
||||
|
||||
if (!is_ascii_codepoint(c)) {
|
||||
return false;
|
||||
|
@ -64,8 +52,7 @@ bool is_url_reserved_codepoint(litehtml::tchar_t c)
|
|||
}
|
||||
|
||||
// https://datatracker.ietf.org/doc/html/rfc3986#section-3.1
|
||||
bool is_url_scheme_codepoint(litehtml::tchar_t c)
|
||||
{
|
||||
bool is_url_scheme_codepoint(litehtml::tchar_t c) {
|
||||
static const uint32_t scheme_lookup[] = {
|
||||
0x00000000,
|
||||
0x03ff6800,
|
||||
|
|
|
@ -1,10 +1,9 @@
|
|||
#include "html.h"
|
||||
#include "context.h"
|
||||
|
||||
#include "html.h"
|
||||
#include "stylesheet.h"
|
||||
|
||||
|
||||
void litehtml::context::load_master_stylesheet( const tchar_t* str )
|
||||
{
|
||||
void litehtml::context::load_master_stylesheet(const tchar_t* str) {
|
||||
media_query_list::ptr media;
|
||||
|
||||
m_master_css.parse_stylesheet(str, nullptr, std::shared_ptr<litehtml::document>(), media_query_list::ptr());
|
||||
|
|
|
@ -1,51 +1,41 @@
|
|||
#include "html.h"
|
||||
#include "css_length.h"
|
||||
|
||||
void litehtml::css_length::fromString( const tstring& str, const tstring& predefs, int defValue )
|
||||
{
|
||||
#include "html.h"
|
||||
|
||||
void litehtml::css_length::fromString(const tstring& str, const tstring& predefs, int defValue) {
|
||||
// TODO: Make support for calc
|
||||
if(str.substr(0, 4) == _t("calc"))
|
||||
{
|
||||
if (str.substr(0, 4) == _t("calc")) {
|
||||
m_is_predefined = true;
|
||||
m_predef = 0;
|
||||
return;
|
||||
}
|
||||
|
||||
int predef = value_index(str, predefs, -1);
|
||||
if(predef >= 0)
|
||||
{
|
||||
if (predef >= 0) {
|
||||
m_is_predefined = true;
|
||||
m_predef = predef;
|
||||
} else
|
||||
{
|
||||
} else {
|
||||
m_is_predefined = false;
|
||||
|
||||
tstring num;
|
||||
tstring un;
|
||||
bool is_unit = false;
|
||||
for(tchar_t chr : str)
|
||||
{
|
||||
if(!is_unit)
|
||||
{
|
||||
if(t_isdigit(chr) || chr == _t('.') || chr == _t('+') || chr == _t('-'))
|
||||
{
|
||||
for (tchar_t chr : str) {
|
||||
if (!is_unit) {
|
||||
if (t_isdigit(chr) || chr == _t('.') || chr == _t('+') || chr == _t('-')) {
|
||||
num += chr;
|
||||
} else
|
||||
{
|
||||
} else {
|
||||
is_unit = true;
|
||||
}
|
||||
}
|
||||
if(is_unit)
|
||||
{
|
||||
if (is_unit) {
|
||||
un += chr;
|
||||
}
|
||||
}
|
||||
if(!num.empty())
|
||||
{
|
||||
if (!num.empty()) {
|
||||
m_value = (float)t_strtod(num.c_str(), nullptr);
|
||||
m_units = (css_units)value_index(un, css_units_strings, css_units_none);
|
||||
} else
|
||||
{
|
||||
} else {
|
||||
// not a number so it is predefined
|
||||
m_is_predefined = true;
|
||||
m_predef = defValue;
|
||||
|
|
|
@ -1,17 +1,15 @@
|
|||
#include "html.h"
|
||||
#include "css_selector.h"
|
||||
#include "document.h"
|
||||
|
||||
void litehtml::css_element_selector::parse( const tstring& txt )
|
||||
{
|
||||
#include "document.h"
|
||||
#include "html.h"
|
||||
|
||||
void litehtml::css_element_selector::parse(const tstring& txt) {
|
||||
tstring::size_type el_end = txt.find_first_of(_t(".#[:"));
|
||||
m_tag = txt.substr(0, el_end);
|
||||
litehtml::lcase(m_tag);
|
||||
m_attrs.clear();
|
||||
while(el_end != tstring::npos)
|
||||
{
|
||||
if(txt[el_end] == _t('.'))
|
||||
{
|
||||
while (el_end != tstring::npos) {
|
||||
if (txt[el_end] == _t('.')) {
|
||||
css_attribute_selector attribute;
|
||||
|
||||
tstring::size_type pos = txt.find_first_of(_t(".#[:"), el_end + 1);
|
||||
|
@ -21,12 +19,10 @@ void litehtml::css_element_selector::parse( const tstring& txt )
|
|||
attribute.attribute = _t("class");
|
||||
m_attrs.push_back(attribute);
|
||||
el_end = pos;
|
||||
} else if(txt[el_end] == _t(':'))
|
||||
{
|
||||
} else if (txt[el_end] == _t(':')) {
|
||||
css_attribute_selector attribute;
|
||||
|
||||
if(txt[el_end + 1] == _t(':'))
|
||||
{
|
||||
if (txt[el_end + 1] == _t(':')) {
|
||||
tstring::size_type pos = txt.find_first_of(_t(".#[:"), el_end + 2);
|
||||
attribute.val = txt.substr(el_end + 2, pos - el_end - 2);
|
||||
attribute.condition = select_pseudo_element;
|
||||
|
@ -34,38 +30,30 @@ void litehtml::css_element_selector::parse( const tstring& txt )
|
|||
attribute.attribute = _t("pseudo-el");
|
||||
m_attrs.push_back(attribute);
|
||||
el_end = pos;
|
||||
} else
|
||||
{
|
||||
} else {
|
||||
tstring::size_type pos = txt.find_first_of(_t(".#[:("), el_end + 1);
|
||||
if(pos != tstring::npos && txt.at(pos) == _t('('))
|
||||
{
|
||||
if (pos != tstring::npos && txt.at(pos) == _t('(')) {
|
||||
pos = find_close_bracket(txt, pos);
|
||||
if(pos != tstring::npos)
|
||||
{
|
||||
if (pos != tstring::npos) {
|
||||
pos++;
|
||||
}
|
||||
}
|
||||
if(pos != tstring::npos)
|
||||
{
|
||||
if (pos != tstring::npos) {
|
||||
attribute.val = txt.substr(el_end + 1, pos - el_end - 1);
|
||||
} else
|
||||
{
|
||||
} else {
|
||||
attribute.val = txt.substr(el_end + 1);
|
||||
}
|
||||
litehtml::lcase(attribute.val);
|
||||
if(attribute.val == _t("after") || attribute.val == _t("before"))
|
||||
{
|
||||
if (attribute.val == _t("after") || attribute.val == _t("before")) {
|
||||
attribute.condition = select_pseudo_element;
|
||||
} else
|
||||
{
|
||||
} else {
|
||||
attribute.condition = select_pseudo_class;
|
||||
}
|
||||
attribute.attribute = _t("pseudo");
|
||||
m_attrs.push_back(attribute);
|
||||
el_end = pos;
|
||||
}
|
||||
} else if(txt[el_end] == _t('#'))
|
||||
{
|
||||
} else if (txt[el_end] == _t('#')) {
|
||||
css_attribute_selector attribute;
|
||||
|
||||
tstring::size_type pos = txt.find_first_of(_t(".#[:"), el_end + 1);
|
||||
|
@ -74,94 +62,74 @@ void litehtml::css_element_selector::parse( const tstring& txt )
|
|||
attribute.attribute = _t("id");
|
||||
m_attrs.push_back(attribute);
|
||||
el_end = pos;
|
||||
} else if(txt[el_end] == _t('['))
|
||||
{
|
||||
} else if (txt[el_end] == _t('[')) {
|
||||
css_attribute_selector attribute;
|
||||
|
||||
tstring::size_type pos = txt.find_first_of(_t("]~=|$*^"), el_end + 1);
|
||||
tstring attr = txt.substr(el_end + 1, pos - el_end - 1);
|
||||
trim(attr);
|
||||
litehtml::lcase(attr);
|
||||
if(pos != tstring::npos)
|
||||
{
|
||||
if(txt[pos] == _t(']'))
|
||||
{
|
||||
if (pos != tstring::npos) {
|
||||
if (txt[pos] == _t(']')) {
|
||||
attribute.condition = select_exists;
|
||||
} else if(txt[pos] == _t('='))
|
||||
{
|
||||
} else if (txt[pos] == _t('=')) {
|
||||
attribute.condition = select_equal;
|
||||
pos++;
|
||||
} else if(txt.substr(pos, 2) == _t("~="))
|
||||
{
|
||||
} else if (txt.substr(pos, 2) == _t("~=")) {
|
||||
attribute.condition = select_contain_str;
|
||||
pos += 2;
|
||||
} else if(txt.substr(pos, 2) == _t("|="))
|
||||
{
|
||||
} else if (txt.substr(pos, 2) == _t("|=")) {
|
||||
attribute.condition = select_start_str;
|
||||
pos += 2;
|
||||
} else if(txt.substr(pos, 2) == _t("^="))
|
||||
{
|
||||
} else if (txt.substr(pos, 2) == _t("^=")) {
|
||||
attribute.condition = select_start_str;
|
||||
pos += 2;
|
||||
} else if(txt.substr(pos, 2) == _t("$="))
|
||||
{
|
||||
} else if (txt.substr(pos, 2) == _t("$=")) {
|
||||
attribute.condition = select_end_str;
|
||||
pos += 2;
|
||||
} else if(txt.substr(pos, 2) == _t("*="))
|
||||
{
|
||||
} else if (txt.substr(pos, 2) == _t("*=")) {
|
||||
attribute.condition = select_contain_str;
|
||||
pos += 2;
|
||||
} else
|
||||
{
|
||||
} else {
|
||||
attribute.condition = select_exists;
|
||||
pos += 1;
|
||||
}
|
||||
pos = txt.find_first_not_of(_t(" \t"), pos);
|
||||
if(pos != tstring::npos)
|
||||
{
|
||||
if(txt[pos] == _t('"'))
|
||||
{
|
||||
if (pos != tstring::npos) {
|
||||
if (txt[pos] == _t('"')) {
|
||||
tstring::size_type pos2 = txt.find_first_of(_t('\"'), pos + 1);
|
||||
attribute.val = txt.substr(pos + 1, pos2 == tstring::npos ? pos2 : (pos2 - pos - 1));
|
||||
pos = pos2 == tstring::npos ? pos2 : (pos2 + 1);
|
||||
} else if(txt[pos] == _t(']'))
|
||||
{
|
||||
} else if (txt[pos] == _t(']')) {
|
||||
pos++;
|
||||
} else
|
||||
{
|
||||
} else {
|
||||
tstring::size_type pos2 = txt.find_first_of(_t(']'), pos + 1);
|
||||
attribute.val = txt.substr(pos, pos2 == tstring::npos ? pos2 : (pos2 - pos));
|
||||
trim(attribute.val);
|
||||
pos = pos2 == tstring::npos ? pos2 : (pos2 + 1);
|
||||
}
|
||||
}
|
||||
} else
|
||||
{
|
||||
} else {
|
||||
attribute.condition = select_exists;
|
||||
}
|
||||
attribute.attribute = attr;
|
||||
m_attrs.push_back(attribute);
|
||||
el_end = pos;
|
||||
} else
|
||||
{
|
||||
} else {
|
||||
el_end++;
|
||||
}
|
||||
el_end = txt.find_first_of(_t(".#[:"), el_end);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
bool litehtml::css_selector::parse( const tstring& text )
|
||||
{
|
||||
if(text.empty())
|
||||
{
|
||||
bool litehtml::css_selector::parse(const tstring& text) {
|
||||
if (text.empty()) {
|
||||
return false;
|
||||
}
|
||||
string_vector tokens;
|
||||
split_string(text, tokens, _t(""), _t(" \t>+~"), _t("(["));
|
||||
|
||||
if(tokens.empty())
|
||||
{
|
||||
if (tokens.empty()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -170,32 +138,27 @@ bool litehtml::css_selector::parse( const tstring& text )
|
|||
tchar_t combinator = 0;
|
||||
|
||||
tokens.pop_back();
|
||||
while(!tokens.empty() && (tokens.back() == _t(" ") || tokens.back() == _t("\t") || tokens.back() == _t("+") || tokens.back() == _t("~") || tokens.back() == _t(">")))
|
||||
{
|
||||
if(combinator == _t(' ') || combinator == 0)
|
||||
{
|
||||
while (!tokens.empty() && (tokens.back() == _t(" ") || tokens.back() == _t("\t") || tokens.back() == _t("+") || tokens.back() == _t("~") || tokens.back() == _t(">"))) {
|
||||
if (combinator == _t(' ') || combinator == 0) {
|
||||
combinator = tokens.back()[0];
|
||||
}
|
||||
tokens.pop_back();
|
||||
}
|
||||
|
||||
for(const auto & token : tokens)
|
||||
{
|
||||
for (const auto& token : tokens) {
|
||||
left += token;
|
||||
}
|
||||
|
||||
trim(left);
|
||||
trim(right);
|
||||
|
||||
if(right.empty())
|
||||
{
|
||||
if (right.empty()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
m_right.parse(right);
|
||||
|
||||
switch(combinator)
|
||||
{
|
||||
switch (combinator) {
|
||||
case _t('>'):
|
||||
m_combinator = combinator_child;
|
||||
break;
|
||||
|
@ -212,11 +175,9 @@ bool litehtml::css_selector::parse( const tstring& text )
|
|||
|
||||
m_left = nullptr;
|
||||
|
||||
if(!left.empty())
|
||||
{
|
||||
if (!left.empty()) {
|
||||
m_left = std::make_shared<css_selector>(media_query_list::ptr(nullptr));
|
||||
if(!m_left->parse(left))
|
||||
{
|
||||
if (!m_left->parse(left)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
@ -224,40 +185,29 @@ bool litehtml::css_selector::parse( const tstring& text )
|
|||
return true;
|
||||
}
|
||||
|
||||
void litehtml::css_selector::calc_specificity()
|
||||
{
|
||||
if(!m_right.m_tag.empty() && m_right.m_tag != _t("*"))
|
||||
{
|
||||
void litehtml::css_selector::calc_specificity() {
|
||||
if (!m_right.m_tag.empty() && m_right.m_tag != _t("*")) {
|
||||
m_specificity.d = 1;
|
||||
}
|
||||
for(const auto& attr : m_right.m_attrs)
|
||||
{
|
||||
if(attr.attribute == _t("id"))
|
||||
{
|
||||
for (const auto& attr : m_right.m_attrs) {
|
||||
if (attr.attribute == _t("id")) {
|
||||
m_specificity.b++;
|
||||
} else
|
||||
{
|
||||
if(attr.attribute == _t("class"))
|
||||
{
|
||||
} else {
|
||||
if (attr.attribute == _t("class")) {
|
||||
m_specificity.c += (int)attr.class_val.size();
|
||||
} else
|
||||
{
|
||||
} else {
|
||||
m_specificity.c++;
|
||||
}
|
||||
}
|
||||
}
|
||||
if(m_left)
|
||||
{
|
||||
if (m_left) {
|
||||
m_left->calc_specificity();
|
||||
m_specificity += m_left->m_specificity;
|
||||
}
|
||||
}
|
||||
|
||||
void litehtml::css_selector::add_media_to_doc( document* doc ) const
|
||||
{
|
||||
if(m_media_query && doc)
|
||||
{
|
||||
void litehtml::css_selector::add_media_to_doc(document* doc) const {
|
||||
if (m_media_query && doc) {
|
||||
doc->add_media_list(m_media_query);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
File diff suppressed because it is too large
Load diff
|
@ -1,25 +1,20 @@
|
|||
#include "html.h"
|
||||
#include "el_anchor.h"
|
||||
|
||||
#include "document.h"
|
||||
#include "html.h"
|
||||
|
||||
litehtml::el_anchor::el_anchor(const std::shared_ptr<litehtml::document>& doc) : html_tag(doc)
|
||||
{
|
||||
}
|
||||
litehtml::el_anchor::el_anchor(const std::shared_ptr<litehtml::document>& doc) : html_tag(doc) {}
|
||||
|
||||
void litehtml::el_anchor::on_click()
|
||||
{
|
||||
void litehtml::el_anchor::on_click() {
|
||||
const tchar_t* href = get_attr(_t("href"));
|
||||
|
||||
if(href)
|
||||
{
|
||||
if (href) {
|
||||
get_document()->container()->on_anchor_click(href, shared_from_this());
|
||||
}
|
||||
}
|
||||
|
||||
void litehtml::el_anchor::apply_stylesheet( const litehtml::css& stylesheet )
|
||||
{
|
||||
if( get_attr(_t("href")) )
|
||||
{
|
||||
void litehtml::el_anchor::apply_stylesheet(const litehtml::css& stylesheet) {
|
||||
if (get_attr(_t("href"))) {
|
||||
m_pseudo_classes.push_back(_t("link"));
|
||||
}
|
||||
html_tag::apply_stylesheet(stylesheet);
|
||||
|
|
|
@ -1,13 +1,8 @@
|
|||
#include "html.h"
|
||||
#include "el_base.h"
|
||||
|
||||
#include "document.h"
|
||||
#include "html.h"
|
||||
|
||||
litehtml::el_base::el_base(const std::shared_ptr<litehtml::document>& doc) : html_tag(doc)
|
||||
{
|
||||
litehtml::el_base::el_base(const std::shared_ptr<litehtml::document>& doc) : html_tag(doc) {}
|
||||
|
||||
}
|
||||
|
||||
void litehtml::el_base::parse_attributes()
|
||||
{
|
||||
get_document()->container()->set_base_url(get_attr(_t("href")));
|
||||
}
|
||||
void litehtml::el_base::parse_attributes() { get_document()->container()->set_base_url(get_attr(_t("href"))); }
|
||||
|
|
|
@ -1,71 +1,58 @@
|
|||
#include "html.h"
|
||||
#include "el_before_after.h"
|
||||
#include "el_text.h"
|
||||
#include "el_space.h"
|
||||
|
||||
#include "el_image.h"
|
||||
#include "el_space.h"
|
||||
#include "el_text.h"
|
||||
#include "html.h"
|
||||
#include "utf8_strings.h"
|
||||
|
||||
litehtml::el_before_after_base::el_before_after_base(const std::shared_ptr<litehtml::document>& doc, bool before) : html_tag(doc)
|
||||
{
|
||||
if(before)
|
||||
{
|
||||
litehtml::el_before_after_base::el_before_after_base(const std::shared_ptr<litehtml::document>& doc, bool before) : html_tag(doc) {
|
||||
if (before) {
|
||||
m_tag = _t("::before");
|
||||
} else
|
||||
{
|
||||
} else {
|
||||
m_tag = _t("::after");
|
||||
}
|
||||
}
|
||||
|
||||
void litehtml::el_before_after_base::add_style(const litehtml::style& st)
|
||||
{
|
||||
void litehtml::el_before_after_base::add_style(const litehtml::style& st) {
|
||||
html_tag::add_style(st);
|
||||
|
||||
tstring content = get_style_property(_t("content"), false, _t(""));
|
||||
if(!content.empty())
|
||||
{
|
||||
if (!content.empty()) {
|
||||
int idx = value_index(content, content_property_string);
|
||||
if(idx < 0)
|
||||
{
|
||||
if (idx < 0) {
|
||||
tstring fnc;
|
||||
tstring::size_type i = 0;
|
||||
while(i < content.length() && i != tstring::npos)
|
||||
{
|
||||
if(content.at(i) == _t('"'))
|
||||
{
|
||||
while (i < content.length() && i != tstring::npos) {
|
||||
if (content.at(i) == _t('"')) {
|
||||
fnc.clear();
|
||||
i++;
|
||||
tstring::size_type pos = content.find(_t('"'), i);
|
||||
tstring txt;
|
||||
if(pos == tstring::npos)
|
||||
{
|
||||
if (pos == tstring::npos) {
|
||||
txt = content.substr(i);
|
||||
i = tstring::npos;
|
||||
} else
|
||||
{
|
||||
} else {
|
||||
txt = content.substr(i, pos - i);
|
||||
i = pos + 1;
|
||||
}
|
||||
add_text(txt);
|
||||
} else if(content.at(i) == _t('('))
|
||||
{
|
||||
} else if (content.at(i) == _t('(')) {
|
||||
i++;
|
||||
litehtml::trim(fnc);
|
||||
litehtml::lcase(fnc);
|
||||
tstring::size_type pos = content.find(_t(')'), i);
|
||||
tstring params;
|
||||
if(pos == tstring::npos)
|
||||
{
|
||||
if (pos == tstring::npos) {
|
||||
params = content.substr(i);
|
||||
i = tstring::npos;
|
||||
} else
|
||||
{
|
||||
} else {
|
||||
params = content.substr(i, pos - i);
|
||||
i = pos + 1;
|
||||
}
|
||||
add_function(fnc, params);
|
||||
fnc.clear();
|
||||
} else
|
||||
{
|
||||
} else {
|
||||
fnc += content.at(i);
|
||||
i++;
|
||||
}
|
||||
|
@ -74,18 +61,13 @@ void litehtml::el_before_after_base::add_style(const litehtml::style& st)
|
|||
}
|
||||
}
|
||||
|
||||
void litehtml::el_before_after_base::add_text( const tstring& txt )
|
||||
{
|
||||
void litehtml::el_before_after_base::add_text(const tstring& txt) {
|
||||
tstring word;
|
||||
tstring esc;
|
||||
for(tstring::size_type i = 0; i < txt.length(); i++)
|
||||
{
|
||||
if( (txt.at(i) == _t(' ')) || (txt.at(i) == _t('\t')) || (txt.at(i) == _t('\\') && !esc.empty()) )
|
||||
{
|
||||
if(esc.empty())
|
||||
{
|
||||
if(!word.empty())
|
||||
{
|
||||
for (tstring::size_type i = 0; i < txt.length(); i++) {
|
||||
if ((txt.at(i) == _t(' ')) || (txt.at(i) == _t('\t')) || (txt.at(i) == _t('\\') && !esc.empty())) {
|
||||
if (esc.empty()) {
|
||||
if (!word.empty()) {
|
||||
element::ptr el = std::make_shared<el_text>(word.c_str(), get_document());
|
||||
appendChild(el);
|
||||
word.clear();
|
||||
|
@ -93,85 +75,66 @@ void litehtml::el_before_after_base::add_text( const tstring& txt )
|
|||
|
||||
element::ptr el = std::make_shared<el_space>(txt.substr(i, 1).c_str(), get_document());
|
||||
appendChild(el);
|
||||
} else
|
||||
{
|
||||
} else {
|
||||
word += convert_escape(esc.c_str() + 1);
|
||||
esc.clear();
|
||||
if(txt.at(i) == _t('\\'))
|
||||
{
|
||||
if (txt.at(i) == _t('\\')) {
|
||||
esc += txt.at(i);
|
||||
}
|
||||
}
|
||||
} else
|
||||
{
|
||||
if(!esc.empty() || txt.at(i) == _t('\\'))
|
||||
{
|
||||
} else {
|
||||
if (!esc.empty() || txt.at(i) == _t('\\')) {
|
||||
esc += txt.at(i);
|
||||
} else
|
||||
{
|
||||
} else {
|
||||
word += txt.at(i);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if(!esc.empty())
|
||||
{
|
||||
if (!esc.empty()) {
|
||||
word += convert_escape(esc.c_str() + 1);
|
||||
}
|
||||
if(!word.empty())
|
||||
{
|
||||
if (!word.empty()) {
|
||||
element::ptr el = std::make_shared<el_text>(word.c_str(), get_document());
|
||||
appendChild(el);
|
||||
word.clear();
|
||||
}
|
||||
}
|
||||
|
||||
void litehtml::el_before_after_base::add_function( const tstring& fnc, const tstring& params )
|
||||
{
|
||||
void litehtml::el_before_after_base::add_function(const tstring& fnc, const tstring& params) {
|
||||
int idx = value_index(fnc, _t("attr;counter;url"));
|
||||
switch(idx)
|
||||
{
|
||||
switch (idx) {
|
||||
// attr
|
||||
case 0:
|
||||
{
|
||||
case 0: {
|
||||
tstring p_name = params;
|
||||
trim(p_name);
|
||||
lcase(p_name);
|
||||
element::ptr el_parent = parent();
|
||||
if (el_parent)
|
||||
{
|
||||
if (el_parent) {
|
||||
const tchar_t* attr_value = el_parent->get_attr(p_name.c_str());
|
||||
if (attr_value)
|
||||
{
|
||||
if (attr_value) {
|
||||
add_text(attr_value);
|
||||
}
|
||||
}
|
||||
}
|
||||
break;
|
||||
} break;
|
||||
// counter
|
||||
case 1:
|
||||
break;
|
||||
// url
|
||||
case 2:
|
||||
{
|
||||
case 2: {
|
||||
tstring p_url = params;
|
||||
trim(p_url);
|
||||
if(!p_url.empty())
|
||||
{
|
||||
if(p_url.at(0) == _t('\'') || p_url.at(0) == _t('\"'))
|
||||
{
|
||||
if (!p_url.empty()) {
|
||||
if (p_url.at(0) == _t('\'') || p_url.at(0) == _t('\"')) {
|
||||
p_url.erase(0, 1);
|
||||
}
|
||||
}
|
||||
if(!p_url.empty())
|
||||
{
|
||||
if(p_url.at(p_url.length() - 1) == _t('\'') || p_url.at(p_url.length() - 1) == _t('\"'))
|
||||
{
|
||||
if (!p_url.empty()) {
|
||||
if (p_url.at(p_url.length() - 1) == _t('\'') || p_url.at(p_url.length() - 1) == _t('\"')) {
|
||||
p_url.erase(p_url.length() - 1, 1);
|
||||
}
|
||||
}
|
||||
if(!p_url.empty())
|
||||
{
|
||||
if (!p_url.empty()) {
|
||||
element::ptr el = std::make_shared<el_image>(get_document());
|
||||
el->set_attr(_t("src"), p_url.c_str());
|
||||
el->set_attr(_t("style"), _t("display:inline-block"));
|
||||
|
@ -179,13 +142,11 @@ void litehtml::el_before_after_base::add_function( const tstring& fnc, const tst
|
|||
appendChild(el);
|
||||
el->parse_attributes();
|
||||
}
|
||||
}
|
||||
break;
|
||||
} break;
|
||||
}
|
||||
}
|
||||
|
||||
litehtml::tstring litehtml::el_before_after_base::convert_escape( const tchar_t* txt )
|
||||
{
|
||||
litehtml::tstring litehtml::el_before_after_base::convert_escape(const tchar_t* txt) {
|
||||
tchar_t* str_end;
|
||||
wchar_t u_str[2];
|
||||
u_str[0] = (wchar_t)t_strtol(txt, &str_end, 16);
|
||||
|
@ -193,7 +154,4 @@ litehtml::tstring litehtml::el_before_after_base::convert_escape( const tchar_t*
|
|||
return litehtml::tstring(litehtml_from_wchar(u_str));
|
||||
}
|
||||
|
||||
void litehtml::el_before_after_base::apply_stylesheet( const litehtml::css& stylesheet )
|
||||
{
|
||||
|
||||
}
|
||||
void litehtml::el_before_after_base::apply_stylesheet(const litehtml::css& stylesheet) {}
|
||||
|
|
Some files were not shown because too many files have changed in this diff Show more
Loading…
Add table
Add a link
Reference in a new issue