You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 

33 lines
1.4 KiB

#include "AElement.h"
#include "../../parsers/markup/TagNode.h"
#include <iostream>
#include "../../browser.h"
extern const std::unique_ptr<Browser> browser;
AElement::AElement() {
isInline = true;
}
std::unique_ptr<Component> AElement::renderer(const ElementRenderRequest &request) {
TextNode *textNode = dynamic_cast<TextNode*>(request.node.get());
if (textNode) {
std::unique_ptr<Component> component = std::make_unique<TextComponent>(textNode->text, 0, 0, 12, false, 0x00FFFF, request.parentComponent->win->windowWidth, request.parentComponent->win->windowHeight);
TagNode *tagNode = dynamic_cast<TagNode*>(textNode->parent.get());
if (tagNode) {
std::map<std::string, std::string>::const_iterator hrefPair = tagNode->properties.find("href");
if (hrefPair != tagNode->properties.end()) {
component->onClick = [request, hrefPair]() {
std::cout << "AElement::renderer:::onClick - Direct to: " << hrefPair->second << std::endl;
// new window
// new tab
// same documentComponent (iframe, document, tab)
browser->getActiveDocumentComponent()->focusedComponent = nullptr;
browser->getActiveDocumentComponent()->navTo(hrefPair->second);
};
}
}
return component;
}
return nullptr;
}