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.

AElement.cpp 1.4KB

123456789101112131415161718192021222324252627282930313233
  1. #include "AElement.h"
  2. #include "../../parsers/markup/TagNode.h"
  3. #include <iostream>
  4. #include "../../app/browser/browser.h"
  5. extern const std::unique_ptr<Browser> browser;
  6. AElement::AElement() {
  7. isInline = true;
  8. }
  9. std::unique_ptr<Component> AElement::renderer(const ElementRenderRequest &request) {
  10. TextNode *textNode = dynamic_cast<TextNode*>(request.node.get());
  11. if (textNode) {
  12. std::unique_ptr<Component> component = std::make_unique<TextComponent>(textNode->text, 0, 0, 12, false, 0x00FFFF, request.parentComponent->win->windowWidth, request.parentComponent->win->windowHeight);
  13. TagNode *tagNode = dynamic_cast<TagNode*>(textNode->parent.get());
  14. if (tagNode) {
  15. std::map<std::string, std::string>::const_iterator hrefPair = tagNode->properties.find("href");
  16. if (hrefPair != tagNode->properties.end()) {
  17. component->onClick = [request, hrefPair]() {
  18. std::cout << "AElement::renderer:::onClick - Direct to: " << hrefPair->second << std::endl;
  19. // new window
  20. // new tab
  21. // same documentComponent (iframe, document, tab)
  22. browser->getActiveDocumentComponent()->focusedComponent = nullptr;
  23. browser->getActiveDocumentComponent()->navTo(hrefPair->second);
  24. };
  25. }
  26. }
  27. return component;
  28. }
  29. return nullptr;
  30. }