Example #1
0
int main(int argc, char** argv)
{
    css::CSSStyleSheet defaultStyleSheet;
    Document document;

    // Load the default CSS file
    if (1 < argc) {
        std::ifstream stream(argv[1]);
        if (!stream) {
            std::cerr << "error: cannot open " << argv[1] << ".\n";
            return EXIT_FAILURE;
        }
        defaultStyleSheet = loadStyleSheet(stream);
        getDOMImplementation()->setDefaultStyleSheet(defaultStyleSheet);
    }

    document = loadDocument(htmlDocument);
    assert(document);

    // create the default view
    WindowPtr window = std::make_shared<WindowImp>();
    window->setDocument(std::static_pointer_cast<bootstrap::DocumentImp>(document.self()));
    ViewCSSImp* view = new ViewCSSImp(window);
    view->constructComputedStyles();
    view->calculateComputedStyles();
    printComputedValues(document, view);

    std::cout << "done.\n";
    return 0;
}
Example #2
0
int main(int argc, char** argv)
{
    css::CSSStyleSheet defaultStyleSheet(0);
    Document document(0);

    // Load the default CSS file
    if (1 < argc) {
        std::ifstream stream(argv[1]);
        if (!stream) {
            std::cerr << "error: cannot open " << argv[1] << ".\n";
            return EXIT_FAILURE;
        }
        defaultStyleSheet = loadStyleSheet(stream);
        getDOMImplementation()->setDefaultStyleSheet(defaultStyleSheet);
    }

    document = loadDocument(htmlDocument);
    assert(document);

    // Each HTML element will have a style attribute if there's the style content attribute.
    // Each HTML style element will have a style sheet.
    eval(document);

    dumpTree(std::cout, document);

    // create the default view
    DocumentWindowPtr window = new(std::nothrow) DocumentWindow;
    window->setDocument(document);
    ViewCSSImp* view = new ViewCSSImp(window);
    view->setSize(8.5f * 96, 11.0f * 96);  // US letter size, 96 DPI
    view->constructComputedStyles();
    view->calculateComputedStyles();

    Box* boxTree = view->constructBlocks();
    if (!boxTree)
        return EXIT_FAILURE;

    boxTree->dump();

    std::cout << "done.\n";
    return 0;
}
Example #3
0
void DocumentWindow::handleMouseMove(EventListenerImp* listener, events::Event event)
{
    if (event.getDefaultPrevented())
        return;
    html::Window defaultView = document.getDefaultView();
    if (!defaultView)
        return;
    WindowImp* imp = dynamic_cast<WindowImp*>(defaultView.self());
    if (!imp)
        return;
    ViewCSSImp* view = imp->getView();
    if (!view)
        return;
    bool canScroll = view->canScroll();

    events::MouseEvent mouse = interface_cast<events::MouseEvent>(event);
    unsigned short buttons = mouse.getButtons();

    if ((buttons & 1) && canScroll)
        defaultView.scrollBy(moveX - mouse.getScreenX(), moveY - mouse.getScreenY());

    moveX = mouse.getScreenX();
    moveY = mouse.getScreenY();
}