Author: Mason Wright
Email:
[email protected]
Date: Thu, 3 Jul 2025 14:50:33 -0600
include/grim.h
6c3ae0e31eb0893f20e3872117f92cc6b9a942af
Random
Clone
-
.gitignore
-
Makefile
-
config
-
include/catch_amalgamated.cpp
-
include/catch_amalgamated.hpp
M
include/grim.h
-
include/parser.h
-
index.html
-
main.cc
-
src/adapter.cc
-
src/events.cc
M
src/grim.cc
-
src/parser.cc
-
style.css
M
tests/css_selector.cc
A
tests/html_node.cc
-
tests/html_parser.cc
Commits
b966b2a517365074e5c381dbdea05b3221dc0198
e840f1eeb0ae26af69e1ae146ea9938e28e9f1af
e4e05418a640eaed08cd1ec7cd8644eb1dbcca50
4e01ba8ad2c3361fa4be3d896288020948b58b5e
aae562ac1350480e4889aabb35899f776c5b59e9
6c3ae0e31eb0893f20e3872117f92cc6b9a942af
350e7d88bb2feb9db00c6e032cc6623f215b7adf
95e6c70d23e99ffcf70e5bbe12503496e5d8f232
e188783659b9bc3b9993a647e93ed110e7f41db6
5e4c38ff3c212cdd9881427ef3f8c2706539a190
e50ea9e1356a74af18fdd171337ef9dc931e1f4e
8f2e83556d12aaebe8e8597ea6923804b0eb7a43
1627c585128af263181053ab2cf1a4cdcd14ee21
def3513f75b325464ad88a33c741c4ca80572b77
a21501590980a905fa9b902897d700a42a08b7f0
56074a6bfe4498d092f3a227297c8c20e2bb962c
d9cf1485b7ae0614130494f0e73237921323b9a1
80f04b134ae32ad8a9d526007b33dd02f6600f05
23d6c65f9368d3c622a55a3068a6b2f1efa0c8d4
09c195df02536b6a796bd648fce9669397b96109
f2b5c8202fbc904e2ed78260e3fdbd55164799d2
4bfba076120f389994fc46a98e8b7a2622314400
e36ac5417e10ee9b9f94f340e1ccf28afc5705ea
d00dc89a86dd7e2fcfd4618bc3a1c8cfba9e3c3d
d9eef16adaf292f3748db5fb5aa98463de10d712
18ff2ec1bfc1cf9fcd17c1acb05c3b41f8f0ed83
9e7fd2980d723437ea621b78d395fa72ca3f4922
Diff
diff --git a/include/grim.h b/include/grim.h index 3e87987..edae26d 100644 --- a/include/grim.h +++ b/include/grim.h @@ -12,3 +12,3 @@ struct Styles { - std::vector
> stylesheets; - std::unordered_map
inlineStyles; - std::unordered_map
> psuedoStyles; + std::vector
> stylesheets; + std::unordered_map
inlineStyles; + std::unordered_map
> psuedoStyles; @@ -18,4 +18,22 @@ struct Bounds { - int top; - int right; - int bottom; - int left; + int top; + int right; + int bottom; + int left; +}; + +struct State { + int width; + int height; + int z; + bool hidden; + int tabIndex; +}; + +class ClassList { +private: + std::vector
classes; +public: + std::string value() const; + std::vector
values(); + void add(std::string value); + void remove(std::string value); @@ -25,70 +43,48 @@ class Node { - private: - std::string TagName; - std::unordered_map
Attributes; - - template
- void setAttribute(const std::string& name, const T& value); - - template
- T getAttribute(const std::string& name) const; - - public: - Node* parent; - std::vector
> children; - struct ClassList { - private: - Node* self; - std::vector
> indexes; - size_t len; - // No return, modifies indexes directly - void createIndex(); - bool checkIndex(); - - public: - ClassList(Node* node) : self(node) {} - std::string value() const; - void add(std::string value); - void remove(std::string value); - void toggle(std::string value); - void replace(std::string key, std::string value); - bool contains(std::string value); - std::string item(size_t key); - size_t length(); - }; - - ClassList classList; - - Node() : parent(nullptr), classList(this) { - } - std::string getTagName() const; - void setTagName(const std::string& name); - const std::unordered_map
& getAttributes() const; - - // --- Define Getters and Setters - // !TODO: Add all global attributes - // + Src: https://developer.mozilla.org/en-US/docs/Web/HTML/Reference/Global_attributes - // The macro should stay here as it's part of the class definition -#define GENERATE_ATTRIBUTE_ACCESSORS(_Type, _FuncNameSuffix, _AttrKeyString) \ - _Type get##_FuncNameSuffix() const; \ - void set##_FuncNameSuffix(_Type value); - - GENERATE_ATTRIBUTE_ACCESSORS(std::string, Id, "id") - GENERATE_ATTRIBUTE_ACCESSORS(std::string, InnerText, "innerText") - GENERATE_ATTRIBUTE_ACCESSORS(bool, ContentEditable, "contenteditable") - GENERATE_ATTRIBUTE_ACCESSORS(std::string, Href, "href") - GENERATE_ATTRIBUTE_ACCESSORS(std::string, Src, "src") - GENERATE_ATTRIBUTE_ACCESSORS(std::string, Title, "title") - GENERATE_ATTRIBUTE_ACCESSORS(std::string, Value, "value") - GENERATE_ATTRIBUTE_ACCESSORS(int, TabIndex, "tabindex") - GENERATE_ATTRIBUTE_ACCESSORS(bool, Disabled, "disabled") - GENERATE_ATTRIBUTE_ACCESSORS(bool, Required, "required") - GENERATE_ATTRIBUTE_ACCESSORS(bool, Checked, "checked") - - Node* createElement(std::string name); - - void setAttribute(const std::string& name, const std::string& value); - std::string getAttribute(const std::string& name) const; - - std::vector
getAttributeKeys(); - - std::string print(int indent = 0); +private: + std::string TagName; + std::unordered_map
Attributes; + + template
+ void setAttribute(const std::string& name, const T& value); + + template
+ T getAttribute(const std::string& name) const; + +public: + Node* parent; + std::vector
> children; + ClassList classList; + + Node(); + std::string getTagName() const; + void setTagName(const std::string& name); + const std::unordered_map
& getAttributes() const; + + // --- Define Getters and Setters + // !TODO: Add all global attributes + // + Src: https://developer.mozilla.org/en-US/docs/Web/HTML/Reference/Global_attributes + // The macro should stay here as it's part of the class definition + #define GENERATE_ATTRIBUTE_ACCESSORS(_Type, _FuncNameSuffix, _AttrKeyString) \ + _Type get##_FuncNameSuffix() const; \ + void set##_FuncNameSuffix(_Type value); + + GENERATE_ATTRIBUTE_ACCESSORS(std::string, Id, "id") + GENERATE_ATTRIBUTE_ACCESSORS(std::string, InnerText, "innerText") + GENERATE_ATTRIBUTE_ACCESSORS(bool, ContentEditable, "contenteditable") + GENERATE_ATTRIBUTE_ACCESSORS(std::string, Href, "href") + GENERATE_ATTRIBUTE_ACCESSORS(std::string, Src, "src") + GENERATE_ATTRIBUTE_ACCESSORS(std::string, Title, "title") + GENERATE_ATTRIBUTE_ACCESSORS(std::string, Value, "value") + GENERATE_ATTRIBUTE_ACCESSORS(int, TabIndex, "tabindex") + GENERATE_ATTRIBUTE_ACCESSORS(bool, Disabled, "disabled") + GENERATE_ATTRIBUTE_ACCESSORS(bool, Required, "required") + GENERATE_ATTRIBUTE_ACCESSORS(bool, Checked, "checked") + + Node* createElement(std::string name); + + void setAttribute(const std::string& name, const std::string& value); + std::string getAttribute(const std::string& name) const; + + std::vector
getAttributeKeys(); + + std::string print(int indent = 0); @@ -102 +98 @@ class Node { - */ +*/
// Grim.h #ifndef GRIM_H #define GRIM_H #include
#include
#include
#include
#include
struct Styles { std::vector
> stylesheets; std::unordered_map
inlineStyles; std::unordered_map
> psuedoStyles; }; struct Bounds { int top; int right; int bottom; int left; }; class Node { private: std::string TagName; std::unordered_map
Attributes; template
void setAttribute(const std::string& name, const T& value); template
T getAttribute(const std::string& name) const; public: Node* parent; std::vector
> children; struct ClassList { private: Node* self; std::vector
> indexes; size_t len; // No return, modifies indexes directly void createIndex(); bool checkIndex(); public: ClassList(Node* node) : self(node) {} std::string value() const; void add(std::string value); void remove(std::string value); void toggle(std::string value); void replace(std::string key, std::string value); bool contains(std::string value); std::string item(size_t key); size_t length(); }; ClassList classList; Node() : parent(nullptr), classList(this) { } std::string getTagName() const; void setTagName(const std::string& name); const std::unordered_map
& getAttributes() const; // --- Define Getters and Setters // !TODO: Add all global attributes // + Src: https://developer.mozilla.org/en-US/docs/Web/HTML/Reference/Global_attributes // The macro should stay here as it's part of the class definition #define GENERATE_ATTRIBUTE_ACCESSORS(_Type, _FuncNameSuffix, _AttrKeyString) \ _Type get##_FuncNameSuffix() const; \ void set##_FuncNameSuffix(_Type value); GENERATE_ATTRIBUTE_ACCESSORS(std::string, Id, "id") GENERATE_ATTRIBUTE_ACCESSORS(std::string, InnerText, "innerText") GENERATE_ATTRIBUTE_ACCESSORS(bool, ContentEditable, "contenteditable") GENERATE_ATTRIBUTE_ACCESSORS(std::string, Href, "href") GENERATE_ATTRIBUTE_ACCESSORS(std::string, Src, "src") GENERATE_ATTRIBUTE_ACCESSORS(std::string, Title, "title") GENERATE_ATTRIBUTE_ACCESSORS(std::string, Value, "value") GENERATE_ATTRIBUTE_ACCESSORS(int, TabIndex, "tabindex") GENERATE_ATTRIBUTE_ACCESSORS(bool, Disabled, "disabled") GENERATE_ATTRIBUTE_ACCESSORS(bool, Required, "required") GENERATE_ATTRIBUTE_ACCESSORS(bool, Checked, "checked") Node* createElement(std::string name); void setAttribute(const std::string& name, const std::string& value); std::string getAttribute(const std::string& name) const; std::vector
getAttributeKeys(); std::string print(int indent = 0); }; /*! * Parse the parts of a CSS selector * * @param selector A CSS selector * @return */ std::vector
> parseSelectorParts(std::string); bool testSelector(Node*, std::vector
>); #endif // NODE_H