|
|
|
@ -1,13 +1,11 @@
@@ -1,13 +1,11 @@
|
|
|
|
|
#include "CommandLineParams.h" |
|
|
|
|
#include "graphics/opengl/Window.h" |
|
|
|
|
#include "graphics/components/TabbedComponent.h" |
|
|
|
|
#include "graphics/components/InputComponent.h" |
|
|
|
|
#include "environment/Environment.h" |
|
|
|
|
#include "html/HTMLParser.h" |
|
|
|
|
#include "Log.h" |
|
|
|
|
#include "URL.h" |
|
|
|
|
#include "WebResource.h" |
|
|
|
|
#include "tlsf.h" |
|
|
|
|
//#include "scheduler.h"
|
|
|
|
|
#include "browser.h" |
|
|
|
|
|
|
|
|
|
#include <ctime> |
|
|
|
@ -28,65 +26,21 @@ extern "C"{
@@ -28,65 +26,21 @@ extern "C"{
|
|
|
|
|
#define PLATFORM "amd64-pc-winnt" |
|
|
|
|
#endif |
|
|
|
|
|
|
|
|
|
//const std::unique_ptr<Window> window = std::make_unique<Window>();
|
|
|
|
|
// global
|
|
|
|
|
// to remove this
|
|
|
|
|
// window uses this to make windows and get window count (can be just be passed in when creating a window)
|
|
|
|
|
// AElement uses it to getActiveDocumentComponent and navTo on that
|
|
|
|
|
//
|
|
|
|
|
std::unique_ptr<Browser> browser = nullptr; |
|
|
|
|
// why can't I const this?
|
|
|
|
|
//std::unique_ptr<Scheduler> scheduler = std::make_unique<Scheduler>();
|
|
|
|
|
//URL currentURL;
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
bool setWindowContent(URL const& url) { |
|
|
|
|
logDebug() << "main::setWindowContent - " << url << std::endl; |
|
|
|
|
|
|
|
|
|
// download URL
|
|
|
|
|
WebResource res = getWebResource(url); |
|
|
|
|
if (res.resourceType == ResourceType::INVALID) { |
|
|
|
|
logError() << "Invalid resource type: " << res.raw << std::endl; |
|
|
|
|
return false; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// 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; |
|
|
|
|
|
|
|
|
|
// send NodeTree to window
|
|
|
|
|
window->setDOM(rootNode); |
|
|
|
|
} else if (res.resourceType == ResourceType::TXT) { |
|
|
|
|
std::cout << "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"; |
|
|
|
|
// bind tag to root
|
|
|
|
|
tagNode->parent = rootNode; |
|
|
|
|
rootNode->children.push_back(tagNode); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
std::shared_ptr<TextNode> textNode = std::make_shared<TextNode>(); |
|
|
|
|
textNode->text = res.raw; |
|
|
|
|
|
|
|
|
|
// bind text to tag
|
|
|
|
|
textNode->parent = tagNode; |
|
|
|
|
tagNode->children.push_back(textNode); |
|
|
|
|
|
|
|
|
|
// send NodeTree to window
|
|
|
|
|
window->setDOM(rootNode); |
|
|
|
|
} else { |
|
|
|
|
std::cout << "setWindowContent() - I don't know how to render non-html files" << std::endl; |
|
|
|
|
} |
|
|
|
|
return true; |
|
|
|
|
} |
|
|
|
|
*/ |
|
|
|
|
|
|
|
|
|
// forward declaration
|
|
|
|
|
bool isAbsolutePath(const std::string s); |
|
|
|
|
bool fileExists(const std::string s); |
|
|
|
|
|
|
|
|
|
bool isAbsolutePath(const std::string s) { |
|
|
|
|
return (s.length() > 0 && s[0] == '/'); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
bool fileExists(const std::string s); |
|
|
|
|
bool fileExists(const std::string s) { |
|
|
|
|
struct stat buf; |
|
|
|
|
return stat(s.c_str(), &buf) != -1; |
|
|
|
@ -113,16 +67,8 @@ int main(int argc, char *argv[]) {
@@ -113,16 +67,8 @@ int main(int argc, char *argv[]) {
|
|
|
|
|
#endif |
|
|
|
|
Environment::init(); |
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
// we need to set up OGL before we can setDOM (because component can't be constructed (currently) without OGL)
|
|
|
|
|
// but should be after CommandLineParams incase we need to change some type of window config
|
|
|
|
|
window->windowWidth = 1024; |
|
|
|
|
window->windowHeight = 640; |
|
|
|
|
window->init(); |
|
|
|
|
if (!window->window) { |
|
|
|
|
return 1; |
|
|
|
|
} |
|
|
|
|
*/ |
|
|
|
|
browser = std::make_unique<Browser>(); |
|
|
|
|
browser->addWindow(); |
|
|
|
|
if (!browser->windows.front().get()->window) { |
|
|
|
@ -133,61 +79,46 @@ int main(int argc, char *argv[]) {
@@ -133,61 +79,46 @@ int main(int argc, char *argv[]) {
|
|
|
|
|
if (argc > 1) { |
|
|
|
|
// this isn't going to work
|
|
|
|
|
std::string rawUrl = getCLParamByIndex(1); |
|
|
|
|
// if we do this here, shouldn't we do this in parseUri too?
|
|
|
|
|
if (rawUrl.find("://") == rawUrl.npos) { |
|
|
|
|
// Path should always be absolute for file://
|
|
|
|
|
if (isAbsolutePath(rawUrl)) { |
|
|
|
|
rawUrl = "file://" + rawUrl; |
|
|
|
|
} else { |
|
|
|
|
auto absolutePath = std::string(getenv("PWD")) + '/' + rawUrl; |
|
|
|
|
if (fileExists(absolutePath)) { |
|
|
|
|
rawUrl = "file://" + absolutePath; |
|
|
|
|
if (rawUrl != "-log") { |
|
|
|
|
// if we do this here, shouldn't we do this in parseUri too?
|
|
|
|
|
if (rawUrl.find("://") == rawUrl.npos) { |
|
|
|
|
// Path should always be absolute for file://
|
|
|
|
|
if (isAbsolutePath(rawUrl)) { |
|
|
|
|
rawUrl = "file://" + rawUrl; |
|
|
|
|
} else { |
|
|
|
|
// Default to http if the file wasn't found
|
|
|
|
|
rawUrl = "http://" + rawUrl; |
|
|
|
|
auto absolutePath = std::string(getenv("PWD")) + '/' + rawUrl; |
|
|
|
|
if (fileExists(absolutePath)) { |
|
|
|
|
rawUrl = "file://" + absolutePath; |
|
|
|
|
} else { |
|
|
|
|
// Default to http if the file wasn't found
|
|
|
|
|
rawUrl = "http://" + rawUrl; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
//logDebug() << "pre URL parse [" << url << "]" << std::endl;
|
|
|
|
|
//window->currentURL = URL(rawUrl);
|
|
|
|
|
logDebug() << "loading [" << rawUrl << "]" << std::endl; |
|
|
|
|
TabbedComponent *tabComponent = dynamic_cast<TabbedComponent*>(browser->windows.front().get()->tabComponent.get()); |
|
|
|
|
if (tabComponent) { |
|
|
|
|
tabComponent->addTab("Start Tab, Loading..."); |
|
|
|
|
tabComponent->selectTab(tabComponent->tabs.front()); |
|
|
|
|
browser->render(); |
|
|
|
|
} |
|
|
|
|
/*
|
|
|
|
|
if (!setWindowContent(window->currentURL)) { |
|
|
|
|
return 1; |
|
|
|
|
} |
|
|
|
|
*/ |
|
|
|
|
std::shared_ptr<DocumentComponent> docComponent = browser->getActiveDocumentComponent(); |
|
|
|
|
if (docComponent) { |
|
|
|
|
// now tell it to navigate somewhere
|
|
|
|
|
docComponent->navTo(rawUrl); |
|
|
|
|
//logDebug() << "pre URL parse [" << url << "]" << std::endl;
|
|
|
|
|
//window->currentURL = URL(rawUrl);
|
|
|
|
|
logDebug() << "loading [" << rawUrl << "]" << std::endl; |
|
|
|
|
TabbedComponent *tabComponent = dynamic_cast<TabbedComponent*>(browser->windows.front().get()->tabComponent.get()); |
|
|
|
|
if (tabComponent) { |
|
|
|
|
tabComponent->addTab("Start Tab, Loading..."); |
|
|
|
|
tabComponent->selectTab(tabComponent->tabs.front()); |
|
|
|
|
browser->render(); |
|
|
|
|
} |
|
|
|
|
/*
|
|
|
|
|
if (!setWindowContent(window->currentURL)) { |
|
|
|
|
return 1; |
|
|
|
|
} |
|
|
|
|
*/ |
|
|
|
|
std::shared_ptr<DocumentComponent> docComponent = browser->getActiveDocumentComponent(); |
|
|
|
|
if (docComponent) { |
|
|
|
|
// now tell it to navigate somewhere
|
|
|
|
|
docComponent->navTo(rawUrl); |
|
|
|
|
} |
|
|
|
|
} else { |
|
|
|
|
// be nice if we could put http:// in the address bar
|
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
browser->loop(); |
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
while (!glfwWindowShouldClose(window->window)) { |
|
|
|
|
//const std::clock_t begin = clock();
|
|
|
|
|
window->render(); |
|
|
|
|
scheduler->fireTimers(); // render may have taken some time
|
|
|
|
|
double next = scheduler->getNext(); |
|
|
|
|
//std::cout << "next timer at " << next << std::endl;
|
|
|
|
|
if (next == LONG_MAX) { |
|
|
|
|
glfwWaitEvents(); // block until something changes
|
|
|
|
|
} else { |
|
|
|
|
glfwWaitEventsTimeout(next / 1000); |
|
|
|
|
} |
|
|
|
|
scheduler->fireTimers(); // check before we go into render again
|
|
|
|
|
//glfwWaitEventsTimeout(1.0 / 60.0); // increase the cpu from 0% to 2% on idle
|
|
|
|
|
//const std::clock_t end = clock();
|
|
|
|
|
//std::cout << '\r' << std::fixed << (((static_cast<double>(end - begin)) / CLOCKS_PER_SEC) * 1000) << std::scientific << " ms/f " << std::flush;
|
|
|
|
|
} |
|
|
|
|
*/ |
|
|
|
|
return 0; |
|
|
|
|
} |
|
|
|
|