Browse Source

handleResource() refactor, enter support on multiLine inputComponents

master
Odilitime 5 years ago
parent
commit
e1a3dad8b9
  1. 28
      src/graphics/components/DocumentComponent.cpp
  2. 2
      src/graphics/components/DocumentComponent.h

28
src/graphics/components/DocumentComponent.cpp

@ -184,7 +184,14 @@ DocumentComponent::DocumentComponent(const float rawX, const float rawY, const f @@ -184,7 +184,14 @@ DocumentComponent::DocumentComponent(const float rawX, const float rawY, const f
if (key == 259) {
focusedInputComponent->backSpace();
} else if (key == 257) {
std::cout << "enter!" << std::endl;
//std::cout << "DocumentComponent::onKeyUp - enter!" << std::endl;
if (focusedInputComponent->multiLine) {
// harfbuzz or freetype2 (something?) doesn't like \n
focusedInputComponent->value += "\r";
focusedInputComponent->updateText();
} else {
std::cout << "should submit form!" << std::endl;
}
} else {
if (key < 256) {
if (mods & GLFW_MOD_SHIFT) {
@ -310,7 +317,7 @@ void DocumentComponent::setDOM(const std::shared_ptr<Node> rootNode) { @@ -310,7 +317,7 @@ void DocumentComponent::setDOM(const std::shared_ptr<Node> rootNode) {
rootComponent->y = y;
domRootNode = rootNode;
//printNode(domRootNode, 0);
printNode(domRootNode, 0);
domDirty = true;
}
@ -386,6 +393,7 @@ void DocumentComponent::createComponentTree(const std::shared_ptr<Node> node, co @@ -386,6 +393,7 @@ void DocumentComponent::createComponentTree(const std::shared_ptr<Node> node, co
ButtonComponent *buttonComponent = dynamic_cast<ButtonComponent*>(component.get());
if (buttonComponent) {
buttonComponent->value = textNode->text;
buttonComponent->resizeToTextSize();
buttonComponent->updateText();
}
}
@ -447,18 +455,25 @@ void DocumentComponent::navTo(const std::string url) { @@ -447,18 +455,25 @@ void DocumentComponent::navTo(const std::string url) {
// download URL
WebResource res = getWebResource(this->currentURL);
this->handleResource(res, currentURL.toString());
}
void DocumentComponent::handleResource(WebResource &res, std::string url) {
if (res.resourceType == ResourceType::INVALID) {
logError() << "Invalid resource type: " << res.raw << std::endl;
logError() << "DocumentComponent::handleResource - Invalid resource type: " << res.raw << std::endl;
return;
}
//std::cout << "body: " << res.raw << std::endl;
//std::cout << "type: " << res.resourceType << std::endl;
// parse HTML
if (res.resourceType == ResourceType::HTML) {
HTMLParser parser;
const std::clock_t begin = clock();
std::shared_ptr<Node> rootNode = parser.parse(res.raw);
const std::clock_t end = clock();
logDebug() << "main::setWindowContent - Parsed document in: " << std::fixed << ((static_cast<double>(end - begin)) / CLOCKS_PER_SEC) << std::scientific << " seconds" << std::endl;
logDebug() << "INPUTElement.handleResource - Parsed document in: " << std::fixed << ((static_cast<double>(end - begin)) / CLOCKS_PER_SEC) << std::scientific << " seconds" << std::endl;
// send NodeTree to window
//this->win->setDOM(rootNode);
@ -471,7 +486,7 @@ void DocumentComponent::navTo(const std::string url) { @@ -471,7 +486,7 @@ void DocumentComponent::navTo(const std::string url) {
}
this->setDOM(rootNode);
} else if (res.resourceType == ResourceType::TXT) {
std::cout << "Rendering text document" << std::endl;
std::cout << "INPUTElement.handleResource - Rendering text document" << std::endl;
std::shared_ptr<Node> rootNode = std::make_shared<Node>(NodeType::ROOT);
std::shared_ptr<TagNode> tagNode = std::make_shared<TagNode>();
tagNode->tag="p";
@ -491,7 +506,6 @@ void DocumentComponent::navTo(const std::string url) { @@ -491,7 +506,6 @@ void DocumentComponent::navTo(const std::string url) {
//this->win->setDOM(rootNode);
this->setDOM(rootNode);
} else {
std::cout << "setWindowContent() - I don't know how to render non-html files" << std::endl;
std::cout << "INPUTElement.handleResource - I don't know how to render non-html files" << std::endl;
}
}

2
src/graphics/components/DocumentComponent.h

@ -8,6 +8,7 @@ @@ -8,6 +8,7 @@
#include "../../html/Node.h"
#include "../../URL.h"
#include "../../networking/HTTPResponse.h"
#include "../../WebResource.h"
// document is scrollable until multicomponent
class DocumentComponent : public MultiComponent {
@ -18,6 +19,7 @@ public: @@ -18,6 +19,7 @@ public:
void createComponentTree(const std::shared_ptr<Node> node, const std::shared_ptr<Component> &parentComponent);
std::shared_ptr<Component> searchComponentTree(const std::shared_ptr<Component> &component, const int x, const int y);
void navTo(const std::string url);
void handleResource(WebResource &res, std::string url);
void setDOM(const std::shared_ptr<Node> rootNode);
std::shared_ptr<Node> domRootNode = nullptr;
ComponentBuilder componentBuilder;

Loading…
Cancel
Save