<commit_before>/*
 * Copyright 2010-2012 Esrille Inc.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

#ifndef ES_CSSBOX_H
#define ES_CSSBOX_H

#include <Object.h>
#include <org/w3c/dom/Text.h>

#include <algorithm>
#include <list>
#include <string>

#include <boost/intrusive_ptr.hpp>

#include "http/HTTPRequest.h"
#include "CSSStyleDeclarationImp.h"
#include "FormattingContext.h"

class FontGlyph;
class FontTexture;

namespace org { namespace w3c { namespace dom {

class Element;

namespace bootstrap {

class Box;
class BoxImage;
class FormattingContext;
class LineBox;
class BlockLevelBox;
class StackingContext;
class TableWrapperBox;
class ViewCSSImp;
class WindowImp;

class ContainingBlock : public ObjectMixin<ContainingBlock>
{
public:
    ContainingBlock() :
        width(0.0f),
        height(0.0f)
    {
    }
    virtual ~ContainingBlock() {}

    float width;
    float height;

    float getWidth() const {
        return width;
    }
    float getHeight() const {
        return height;
    }
};

class Box : public ContainingBlock
{
    friend class ViewCSSImp;
    friend class BlockLevelBox;
    friend class LineBox;
    friend class FormattingContext;
    friend class BoxImage;
    friend class StackingContext;

public:
    static const unsigned short BLOCK_LEVEL_BOX = 1;
    static const unsigned short LINE_BOX = 2;
    static const unsigned short INLINE_LEVEL_BOX = 3;

    // flags
    static const unsigned short NEED_SELECTOR_MATCHING = 1;
    static const unsigned short NEED_REFLOW = 2;
    static const unsigned short NEED_REPAINT = 4;
    static const unsigned short NEED_CHILD_LAYOUT = 8;
    static const unsigned short NEED_SELECTOR_REMATCHING = 16;

protected:
    Node node;
    Box* parentBox;
    Box* firstChild;
    Box* lastChild;
    Box* previousSibling;
    Box* nextSibling;
    unsigned int childCount;

    float clearance;
    float marginTop;
    float marginRight;
    float marginBottom;
    float marginLeft;
    float paddingTop;
    float paddingRight;
    float paddingBottom;
    float paddingLeft;
    float borderTop;
    float borderRight;
    float borderBottom;
    float borderLeft;

    unsigned position;
    float offsetH;
    float offsetV;

    StackingContext* stackingContext;
    Box* nextBase;

    bool intrinsic;  // do not change width and height

    float x;  // in screen coord
    float y;  // in screen coord

    unsigned visibility;

    BlockLevelBox* clipBox;

    // background
    unsigned backgroundColor;
    BoxImage* backgroundImage;
    float backgroundLeft;
    float backgroundTop;
    unsigned backgroundStart;

    CSSStyleDeclarationPtr style;
    FormattingContext* formattingContext;

    unsigned short flags;
    unsigned short state;

    WindowImp* childWindow;

    void renderBorderEdge(ViewCSSImp* view, int edge, unsigned borderStyle, unsigned color,
                          float a, float b, float c, float d,
                          float e, float f, float g, float h);
public:
    Box(Node node);
    virtual ~Box();

    virtual unsigned getBoxType() const = 0;

    virtual bool isAnonymous() const {
        return !node;
    }

    Node getNode() const {
        return node;
    }
    WindowImp* getChildWindow() const {
        return childWindow;
    }

    Node getTargetNode() const {
        const Box* box = this;
        do {
            if (box->node)
                return box->node;
        } while (box = box->parentBox);<commit_msg>(Box::state) : Remove<commit_after>/*
 * Copyright 2010-2012 Esrille Inc.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

#ifndef ES_CSSBOX_H
#define ES_CSSBOX_H

#include <Object.h>
#include <org/w3c/dom/Text.h>

#include <algorithm>
#include <list>
#include <string>

#include <boost/intrusive_ptr.hpp>

#include "http/HTTPRequest.h"
#include "CSSStyleDeclarationImp.h"
#include "FormattingContext.h"

class FontGlyph;
class FontTexture;

namespace org { namespace w3c { namespace dom {

class Element;

namespace bootstrap {

class Box;
class BoxImage;
class FormattingContext;
class LineBox;
class BlockLevelBox;
class StackingContext;
class TableWrapperBox;
class ViewCSSImp;
class WindowImp;

class ContainingBlock : public ObjectMixin<ContainingBlock>
{
public:
    ContainingBlock() :
        width(0.0f),
        height(0.0f)
    {
    }
    virtual ~ContainingBlock() {}

    float width;
    float height;

    float getWidth() const {
        return width;
    }
    float getHeight() const {
        return height;
    }
};

class Box : public ContainingBlock
{
    friend class ViewCSSImp;
    friend class BlockLevelBox;
    friend class LineBox;
    friend class FormattingContext;
    friend class BoxImage;
    friend class StackingContext;

public:
    static const unsigned short BLOCK_LEVEL_BOX = 1;
    static const unsigned short LINE_BOX = 2;
    static const unsigned short INLINE_LEVEL_BOX = 3;

    // flags
    static const unsigned short NEED_SELECTOR_MATCHING = 1;
    static const unsigned short NEED_REFLOW = 2;
    static const unsigned short NEED_REPAINT = 4;
    static const unsigned short NEED_CHILD_LAYOUT = 8;
    static const unsigned short NEED_SELECTOR_REMATCHING = 16;

protected:
    Node node;
    Box* parentBox;
    Box* firstChild;
    Box* lastChild;
    Box* previousSibling;
    Box* nextSibling;
    unsigned int childCount;

    float clearance;
    float marginTop;
    float marginRight;
    float marginBottom;
    float marginLeft;
    float paddingTop;
    float paddingRight;
    float paddingBottom;
    float paddingLeft;
    float borderTop;
    float borderRight;
    float borderBottom;
    float borderLeft;

    unsigned position;
    float offsetH;
    float offsetV;

    StackingContext* stackingContext;
    Box* nextBase;

    bool intrinsic;  // do not change width and height

    float x;  // in screen coord
    float y;  // in screen coord

    unsigned visibility;

    BlockLevelBox* clipBox;

    // background
    unsigned backgroundColor;
    BoxImage* backgroundImage;
    float backgroundLeft;
    float backgroundTop;
    unsigned backgroundStart;

    CSSStyleDeclarationPtr style;
    FormattingContext* formattingContext;

    unsigned short flags;

    WindowImp* childWindow;

    void renderBorderEdge(ViewCSSImp* view, int edge, unsigned borderStyle, unsigned color,
                          float a, float b, float c, float d,
                          float e, float f, float g, float h);
public:
    Box(Node node);
    virtual ~Box();

    virtual unsigned getBoxType() const = 0;

    virtual bool isAnonymous() const {
        return !node;
    }

    Node getNode() const {
        return node;
    }
    WindowImp* getChildWindow() const {
        return childWindow;
    }

    Node getTargetNode() const {
        const Box* box = this;
        do {
            if (box->node)
                return box->node;
        } while (box = box->parentBox);
{'fraction_non_alphanumeric': 0.07344064386317907, 'fraction_numerical': 0.007042253521126761, 'mean_word_length': 2.925468904244817, 'pattern_counts': {'":': 0, '<': 17, '<?xml version=': 0, '>': 23, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1145338', 'n_tokens_mistral': 2310, 'n_tokens_neox': 2211, 'n_words': 789}