Beispiel #1
0
    void t2LayoutController::update()
    {
        t2DivController* divController = t2DivController::getInstance();
        t2Div* root = divController->getRoot();

        // --!层序遍历
        static t3Queue<t2Div*> queue;
        if(!root) return;
        queue.push(root);

        for(;;)
        {
            t2Div* temp;

            if(queue.isEmpty()) temp = NULL;
            else temp = queue.pop();

            if(temp)
            {
                int restoreStatus = temp->getStatus();

                // 三种状态全权更新
                for(int i = T2_NORMAL; i <= T2_ACTIVE; i++)
                {
                    temp->setStatus(i);
                    updateDiv(temp, false);

                    //if(temp->hasCondition())
                    updateDiv(temp, true);
                }

                temp->setStatus(restoreStatus);

                // 将所有兄弟结点入队列
                for(t2Div* c = temp->child; c != NULL; c = c->next)
                    queue.push(c);
            }
            else break;
        }
    }
Beispiel #2
0
    void t2HTMLParser::t2LabelParser::body(GumboNode *b)
    {
        static t3Queue<t2Element*> queue;
        t2Element* element = new t2Element(b);

        // --!这里body下有一个隐藏的div,长宽与窗口一致
        string rootID = getRootDivGlobalID();
        t2DivController::getInstance()->addDiv(rootID, element->div);
        t2DivController::getInstance()->setRoot(rootID);
        element->div->normal.width = t2GetWindowWidth();
        element->div->normal.height = t2GetWindowHeight();
        element->div->hover = element->div->normal;
        element->div->active = element->div->normal;

        queue.push(element);
        for(;;)
        {
            t2Element* e;
            if(queue.isEmpty()) e = NULL;
            else e = queue.pop();

            if(e)
            {
                GumboNode* child = e->node;
                // find div
                if(child->type == GUMBO_NODE_ELEMENT && child->v.element.tag == GUMBO_TAG_DIV)
                {
                    t2Div *div = e->div;

                    // find className
                    GumboAttribute *className = gumbo_get_attribute(&child->v.element.attributes, "class");
                    div->className = className->value;
                    
                    // text
                    GumboNode *content = (GumboNode *) child->v.element.children.data[0];
                    if(content->type == GUMBO_NODE_TEXT || content->type == GUMBO_NODE_WHITESPACE)
                    {
                        div->normal.text = content->v.text.text;
                        div->hover.text = content->v.text.text;
                        div->active.text = content->v.text.text;

                        div->normalCondition.text = content->v.text.text;
                        div->hoverCondition.text = content->v.text.text;
                        div->activeCondition.text = content->v.text.text;
                    }
                    
                    // find id
                    // not supported
                    string id;
                    GumboAttribute *idName = gumbo_get_attribute(&child->v.element.attributes, "id");
                    if(idName)
                        div->className = idName->value;
                    else
                        id = getDivGlobalID();

                    // 新增div
                    t2DivController::getInstance()->addDiv(id, div);
                }

                t2Div *brother = NULL;
                // 将所有兄弟结点入队列
                for(int i = 0; i < child->v.element.children.length; i++)
                {
                    GumboNode *c = (GumboNode *) child->v.element.children.data[i];
                    if(c->type == GUMBO_NODE_ELEMENT && 
                        c->v.element.tag == GUMBO_TAG_DIV)
                    {
                        // 多叉树的复制
                        t2Element* element = new t2Element(c);
                        // 第一个兄弟结点
                        if(!brother)
                        {
                            // 子节点
                            e->div->child = element->div;
                            element->div->parent = e->div;
                        }
                        else
                        {
                            // 父节点
                            element->div->parent = e->div;
                            brother->next = element->div;
                        }

                        // 更新兄弟结点
                        brother = element->div;
                        queue.push(element);
                    }
                }
            }
            else
                break;
        }
    }