Skip to content

Includes refactoring using clangd #400

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 6, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
53 changes: 53 additions & 0 deletions .clang-format
Original file line number Diff line number Diff line change
@@ -1,7 +1,60 @@
# Options are listed here:
# https://clang.llvm.org/docs/ClangFormatStyleOptions.html
---
Language: Cpp
BasedOnStyle: Microsoft
Standard: c++17
TabWidth: 4
UseTab: Always
IndentWidth: 4
PointerAlignment: Left
SpaceAfterCStyleCast: true
SpaceBeforeParens: false
BraceWrapping:
AfterCaseLabel: false
AfterClass: true
AfterControlStatement: Always
AfterEnum: true
AfterFunction: true
AfterNamespace: true
AfterObjCDeclaration: true
AfterStruct: true
AfterUnion: false
AfterExternBlock: true
BeforeCatch: true
BeforeElse: false
BeforeLambdaBody: false
BeforeWhile: false
IndentBraces: false
SplitEmptyFunction: true
SplitEmptyRecord: true
SplitEmptyNamespace: true
NamespaceIndentation: All
AlignConsecutiveDeclarations:
Enabled: true
AcrossEmptyLines: true
AcrossComments: false
AlignConsecutiveAssignments:
Enabled: true
AcrossEmptyLines: true
AcrossComments: true
AlignCompound: true
AlignFunctionPointers: true
PadOperators: true
AlignConsecutiveMacros:
Enabled: true
AcrossEmptyLines: true
AcrossComments: true
AlignCompound: true
AlignFunctionPointers: true
PadOperators: true
SortIncludes: false
IndentCaseBlocks: true
InsertNewlineAtEOF: true
BreakConstructorInitializers: AfterColon
PackConstructorInitializers: Never
AllowShortLambdasOnASingleLine: true
AllowShortIfStatementsOnASingleLine: WithoutElse
AllowShortFunctionsOnASingleLine: Inline
AlignArrayOfStructures: Left
AllowShortBlocksOnASingleLine: true
1 change: 1 addition & 0 deletions containers/cairo/cairo_borders.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#ifndef LITEHTML_CAIRO_BORDERS_H
#define LITEHTML_CAIRO_BORDERS_H

#include <litehtml.h>
#include <cairo.h>

namespace cairo
Expand Down
3 changes: 2 additions & 1 deletion containers/cairo/container_cairo.h
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
#ifndef LH_CONTAINER_LINUX_H
#define LH_CONTAINER_LINUX_H

#include "../../include/litehtml.h"
#include <litehtml.h>
#include <cairo.h>
#include <vector>

struct cairo_clip_box
{
Expand Down
1 change: 1 addition & 0 deletions include/litehtml.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,6 @@
#include <litehtml/stylesheet.h>
#include <litehtml/element.h>
#include <litehtml/utf8_strings.h>
#include <litehtml/document_container.h>

#endif // LITEHTML_H
4 changes: 0 additions & 4 deletions include/litehtml/codepoint.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,6 @@
#ifndef LITEHTML_CODEPOINT_H__
#define LITEHTML_CODEPOINT_H__

#include <string>

#include "os_types.h"

namespace litehtml {

bool is_ascii_codepoint(char c);
Expand Down
1 change: 1 addition & 0 deletions include/litehtml/css_parser.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

#include "css_tokenizer.h"
#include "stylesheet.h"
#include <functional>

namespace litehtml
{
Expand Down
2 changes: 1 addition & 1 deletion include/litehtml/css_properties.h
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#ifndef LITEHTML_CSS_PROPERTIES_H
#define LITEHTML_CSS_PROPERTIES_H

#include "os_types.h"
#include "string_id.h"
#include "types.h"
#include "css_margins.h"
#include "borders.h"
Expand Down
3 changes: 2 additions & 1 deletion include/litehtml/css_selector.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#ifndef LH_CSS_SELECTOR_H
#define LH_CSS_SELECTOR_H

#include "string_id.h"
#include "style.h"
#include "media_query.h"
#include "css_tokenizer.h"
Expand Down Expand Up @@ -154,7 +155,7 @@ namespace litehtml
string_id prefix; // [prefix|name]
string_id name; // .name, #name, [name], :name
string value; // [name=value], :lang(value)

attr_matcher matcher; // <attr-matcher> = ~= |= ^= $= *=
bool caseless_match; // value is matched ASCII case-insensitively

Expand Down
31 changes: 17 additions & 14 deletions include/litehtml/css_tokenizer.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
#ifndef LH_CSS_TOKENIZER_H
#define LH_CSS_TOKENIZER_H

#include "types.h"
#include <cstdio>

namespace litehtml
{

Expand All @@ -11,7 +14,7 @@ namespace litehtml
enum css_token_type
{
WHITESPACE = ' ',

// Giving EOF and some chars explicit names to facilitate debugging and to get rid of warning C4063: case '41' is not a valid value for switch of enum 'litehtml::css_token_type'
_EOF = EOF,
LEFT_BRACE = '{',
Expand All @@ -26,7 +29,7 @@ enum css_token_type
BANG = '!',
DOT = '.',
AMPERSAND = '&',

IDENT = -20, // do not collide with any unicode chars
FUNCTION, // calc(
AT_KEYWORD, // @media
Expand Down Expand Up @@ -62,12 +65,12 @@ enum css_hash_type
};

// css_token: CSS token or component value ("fat" token)
// Tokens exist in uncomponentized form only a short time after tokenization, most of the time they are "fat".
// Tokens exist in uncomponentized form only a short time after tokenization, most of the time they are "fat".
// All functions in css_parser work regardless of whether tokens are fat or not, as per standard.
// All functions outside of css_parser that parse media queries, selectors, property values assume tokens are componentized.
struct css_token
{
css_token(css_token_type type = css_token_type(),
css_token(css_token_type type = css_token_type(),
float number = 0, css_number_type number_type = css_number_integer, string str = "")
: type(type), str(str), n{number, number_type}
{
Expand All @@ -87,13 +90,13 @@ struct css_token
case HASH:
hash_type = token.hash_type;
break;

case NUMBER:
case PERCENTAGE:
case DIMENSION:
n = token.n;
break;

case CV_FUNCTION:
case CURLY_BLOCK:
case ROUND_BLOCK:
Expand All @@ -104,17 +107,17 @@ struct css_token
default:;
}
}

css_token& operator=(const css_token& token)
{
this->~css_token();
new(this) css_token(token);
return *this;
}

~css_token()
{
str.~string();
{
str.~string();
if (is_component_value()) value.~vector();
}

Expand All @@ -132,7 +135,7 @@ struct css_token
};
union {
string str; // STRING, URL
string name; // HASH, IDENT, AT_KEYWORD, FUNCTION, CV_FUNCTION
string name; // HASH, IDENT, AT_KEYWORD, FUNCTION, CV_FUNCTION
string unit; // DIMENSION
};
struct number {
Expand All @@ -144,7 +147,7 @@ struct css_token
number n;
vector<css_token> value; // CV_FUNCTION, XXX_BLOCK
};

string repr; // https://www.w3.org/TR/css-syntax-3/#representation
};

Expand All @@ -155,7 +158,7 @@ class css_tokenizer
{
public:
css_tokenizer(const string& input) : str(input), index(0), current_char(0) {}

css_token_vector tokenize();

private:
Expand Down Expand Up @@ -188,7 +191,7 @@ class css_tokenizer
void consume_comments();
int consume_escaped_code_point();
css_token consume_string_token(int ending_code_point);

static bool would_start_ident_sequence(three_chars chars);
string consume_ident_sequence();

Expand Down
14 changes: 7 additions & 7 deletions include/litehtml/document.h
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#ifndef LH_DOCUMENT_H
#define LH_DOCUMENT_H

#include "style.h"
#include "stylesheet.h"
#include "types.h"
#include "master_css.h"
#include "encodings.h"
Expand Down Expand Up @@ -61,8 +61,8 @@ namespace litehtml
litehtml::size m_size;
litehtml::size m_content_size;
position::vector m_fixed_boxes;
element::ptr m_over_element;
element::ptr m_active_element;
std::shared_ptr<element> m_over_element;
std::shared_ptr<element> m_active_element;
std::list<shared_ptr<render_item>> m_tabular_elements;
media_query_list_list::vector m_media_lists;
media_features m_media;
Expand Down Expand Up @@ -92,8 +92,8 @@ namespace litehtml
bool on_lbutton_up(int x, int y, int client_x, int client_y, position::vector& redraw_boxes);
bool on_button_cancel(position::vector& redraw_boxes);
bool on_mouse_leave(position::vector& redraw_boxes);
element::ptr create_element(const char* tag_name, const string_map& attributes);
element::ptr root();
std::shared_ptr<element> create_element(const char* tag_name, const string_map& attributes);
std::shared_ptr<element> root();
std::shared_ptr<render_item> root_render();
void get_fixed_boxes(position::vector& fixed_boxes);
void add_fixed_box(const position& pos);
Expand All @@ -102,7 +102,7 @@ namespace litehtml
bool lang_changed();
bool match_lang(const string& lang);
void add_tabular(const std::shared_ptr<render_item>& el);
element::const_ptr get_over_element() const { return m_over_element; }
std::shared_ptr<const element> get_over_element() const { return m_over_element; }

void append_children_from_string(element& parent, const char* str);
void dump(dumper& cout);
Expand All @@ -125,7 +125,7 @@ namespace litehtml
void fix_table_parent(const std::shared_ptr<render_item> & el_ptr, style_display disp, const char* disp_str);
};

inline element::ptr document::root()
inline std::shared_ptr<element> document::root()
{
return m_root;
}
Expand Down
1 change: 0 additions & 1 deletion include/litehtml/document_container.h
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
#ifndef LH_DOCUMENT_CONTAINER_H
#define LH_DOCUMENT_CONTAINER_H

#include "os_types.h"
#include "types.h"
#include "web_color.h"
#include "background.h"
Expand Down
2 changes: 1 addition & 1 deletion include/litehtml/el_cdata.h
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#ifndef LH_EL_CDATA_H
#define LH_EL_CDATA_H

#include "html_tag.h"
#include "element.h"

namespace litehtml
{
Expand Down
2 changes: 1 addition & 1 deletion include/litehtml/el_comment.h
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#ifndef LH_EL_COMMENT_H
#define LH_EL_COMMENT_H

#include "html_tag.h"
#include "element.h"

namespace litehtml
{
Expand Down
1 change: 1 addition & 0 deletions include/litehtml/el_image.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
#define LH_EL_IMAGE_H

#include "html_tag.h"
#include "document.h"

namespace litehtml
{
Expand Down
2 changes: 1 addition & 1 deletion include/litehtml/el_script.h
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#ifndef LH_EL_SCRIPT_H
#define LH_EL_SCRIPT_H

#include "html_tag.h"
#include "element.h"

namespace litehtml
{
Expand Down
1 change: 0 additions & 1 deletion include/litehtml/el_space.h
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
#ifndef LH_EL_SPACE_H
#define LH_EL_SPACE_H

#include "html_tag.h"
#include "el_text.h"

namespace litehtml
Expand Down
2 changes: 1 addition & 1 deletion include/litehtml/el_style.h
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#ifndef LH_EL_STYLE_H
#define LH_EL_STYLE_H

#include "html_tag.h"
#include "element.h"

namespace litehtml
{
Expand Down
3 changes: 2 additions & 1 deletion include/litehtml/el_text.h
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
#ifndef LH_EL_TEXT_H
#define LH_EL_TEXT_H

#include "html_tag.h"
#include "element.h"
#include "document.h"

namespace litehtml
{
Expand Down
3 changes: 1 addition & 2 deletions include/litehtml/element.h
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
#ifndef LH_ELEMENT_H
#define LH_ELEMENT_H

#include <functional>
#include <memory>
#include <tuple>
#include <list>
#include "stylesheet.h"
#include "css_offsets.h"
#include "css_margins.h"
#include "css_properties.h"

namespace litehtml
Expand Down
1 change: 1 addition & 0 deletions include/litehtml/encodings.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#ifndef LH_ENCODINGS_H
#define LH_ENCODINGS_H

#include "types.h"
namespace litehtml
{

Expand Down
2 changes: 1 addition & 1 deletion include/litehtml/flex_item.h
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
#ifndef LITEHTML_FLEX_ITEM_H
#define LITEHTML_FLEX_ITEM_H

#include <functional>
#include "formatting_context.h"
#include "render_item.h"

namespace litehtml
{
Expand Down
Loading