void CSSStyleRule::setSelectorText(const String& selectorText)
{
    Document* doc = 0;
    StyleSheet* ownerStyleSheet = m_style->stylesheet();
    if (ownerStyleSheet) {
        if (ownerStyleSheet->isCSSStyleSheet())
            doc = static_cast<CSSStyleSheet*>(ownerStyleSheet)->document();
        if (!doc)
            doc = ownerStyleSheet->ownerNode() ? ownerStyleSheet->ownerNode()->document() : 0;
    }
    if (!doc)
        doc = m_style->node() ? m_style->node()->document() : 0;

    if (!doc)
        return;

    CSSParser p;
    CSSSelectorList selectorList;
    p.parseSelector(selectorText, doc, selectorList);
    if (!selectorList.first())
        return;

    String oldSelectorText = this->selectorText();
    m_selectorList.adopt(selectorList);
    if (this->selectorText() == oldSelectorText)
        return;

    doc->styleSelectorChanged(DeferRecalcStyle);
}
예제 #2
0
void HTMLStyleElementImp::handleMutation(EventListenerImp* listener, events::Event event)
{
    // TODO: update type, media, and scoped. Then check type.

    events::MutationEvent mutation(interface_cast<events::MutationEvent>(event));

    DocumentImp* document = getOwnerDocumentImp();
    if (!document)
        return;

    if (mutation.getType() == u"DOMNodeRemoved" && event.getTarget().self() == this)
        styleSheet = 0;
    else {
        std::u16string content;
        for (Node node = getFirstChild(); node; node = node.getNextSibling()) {
            if (TextImp* text = dynamic_cast<TextImp*>(node.self()))  // TODO better to avoid imp call?
                content += text->getData();
        }
        CSSParser parser;
        styleSheet = parser.parse(document, content);
        if (auto imp = dynamic_cast<CSSStyleSheetImp*>(styleSheet.self())) {
            imp->setOwnerNode(this);
            if (4 <= getLogLevel())
                dumpStyleSheet(std::cerr, imp);
        }
    }
    if (WindowImp* view = document->getDefaultWindow())
        view->setFlags(Box::NEED_SELECTOR_REMATCHING);
    document->resetStyleSheets();
}
예제 #3
0
bool InspectorStyleSheet::ensureSourceData(Node* ownerNode)
{
    if (m_parsedStyleSheet->hasSourceData())
        return true;

    if (!m_parsedStyleSheet->hasText())
        return false;

    RefPtr<CSSStyleSheet> newStyleSheet = CSSStyleSheet::create(ownerNode);
    CSSParser p;
    StyleRuleRangeMap ruleRangeMap;
    p.parseSheet(newStyleSheet.get(), m_parsedStyleSheet->text(), 0, &ruleRangeMap);
    OwnPtr<ParsedStyleSheet::SourceData> rangesVector(new ParsedStyleSheet::SourceData());

    for (unsigned i = 0, length = newStyleSheet->length(); i < length; ++i) {
        CSSStyleRule* rule = InspectorCSSAgent::asCSSStyleRule(newStyleSheet->item(i));
        if (!rule)
            continue;
        StyleRuleRangeMap::iterator it = ruleRangeMap.find(rule);
        if (it != ruleRangeMap.end())
            rangesVector->append(it->second);
    }

    m_parsedStyleSheet->setSourceData(rangesVector.release());
    return m_parsedStyleSheet->hasSourceData();
}
void MediaListImp::setMediaText(const std::u16string& mediaText)
{
    clear();
    if (!mediaText.empty()) {
        CSSParser parser;
        *this = *parser.parseMediaList(mediaText);
    }
}
void HTMLElementImp::eval()
{
    DocumentWindowPtr window = getOwnerDocumentImp()->activate();
    Nullable<std::u16string> attr = getAttribute(u"style");
    if (attr.hasValue()) {
        CSSParser parser;
        style = parser.parseDeclarations(attr.value());
        parser.getStyleDeclaration()->setOwner(this);
    }
    attr = getAttribute(u"onclick");
    if (attr.hasValue())
        setOnclick(window->getContext()->compileFunction(attr.value()));
    attr = getAttribute(u"onload");
    if (attr.hasValue())
        setOnload(window->getContext()->compileFunction(attr.value()));
}
css::CSSStyleSheet loadStyleSheet(const char* path)
{
    char url[PATH_MAX + 7];
    strcpy(url, "file://");
    realpath(path, url + 7);
    std::ifstream stream(path);
    if (!stream) {
        std::cerr << "error: cannot open " << path << ".\n";
        exit(EXIT_FAILURE);
    }
    CSSParser parser;
    CSSInputStream cssStream(stream, "utf-8");
    css::CSSStyleSheet sheet = parser.parse(0, cssStream);
    if (auto imp = dynamic_cast<CSSStyleSheetImp*>(sheet.self()))
        imp->setHref(toString(url));
    return sheet;
}
예제 #7
0
bool InspectorStyleSheetForInlineStyle::getStyleAttributeRanges(RefPtr<CSSStyleSourceData>* result)
{
    DEFINE_STATIC_LOCAL(String, styleAttributeName, ("style"));

    if (!m_element->isStyledElement())
        return false;

    String styleText = static_cast<StyledElement*>(m_element)->getAttribute(styleAttributeName);
    if (styleText.isEmpty()) {
        (*result)->styleBodyRange.start = 0;
        (*result)->styleBodyRange.end = 0;
        return true;
    }

    RefPtr<CSSMutableStyleDeclaration> tempDeclaration = CSSMutableStyleDeclaration::create();
    CSSParser p;
    p.parseDeclaration(tempDeclaration.get(), styleText, result);
    return true;
}
예제 #8
0
HashMap<long, SourceRange> InspectorCSSStore::getRuleRangesForStyleSheet(CSSStyleSheet* styleSheet)
{
    if (!styleSheet)
        return HashMap<long, SourceRange>();
    RefPtr<CSSRuleList> originalRuleList = CSSRuleList::create(styleSheet, false);
    StyleSheetToOffsetsMap::iterator it = m_styleSheetToOffsets.find(styleSheet);
    HashMap<long, SourceRange> result;
    Vector<SourceRange>* offsetVector = 0;
    if (it == m_styleSheetToOffsets.end()) {
        InspectorResource* resource = m_inspectorController->resourceForURL(styleSheet->finalURL().string());
        if (resource) {
            offsetVector = new Vector<SourceRange>;
            RefPtr<CSSStyleSheet> newStyleSheet = CSSStyleSheet::create(styleSheet->ownerNode());
            CSSParser p;
            CSSParser::StyleRuleRanges ruleRangeMap;
            p.parseSheet(newStyleSheet.get(), resource->sourceString(), &ruleRangeMap);
            for (unsigned i = 0, length = newStyleSheet->length(); i < length; ++i) {
                CSSStyleRule* rule = asCSSStyleRule(newStyleSheet->item(i));
                if (!rule)
                    continue;
                HashMap<CSSStyleRule*, std::pair<unsigned, unsigned> >::iterator it = ruleRangeMap.find(rule);
                if (it != ruleRangeMap.end())
                    offsetVector->append(it->second);
            }
            m_styleSheetToOffsets.set(styleSheet, offsetVector);
        }
    } else
        offsetVector = it->second;
    if (!offsetVector)
        return HashMap<long, SourceRange>();
    unsigned ruleIndex = 0;
    for (unsigned i = 0, length = styleSheet->length(); i < length; ++i) {
        ASSERT(ruleIndex < offsetVector->size());
        CSSStyleRule* rule = asCSSStyleRule(styleSheet->item(i));
        if (!rule)
            continue;
        result.set(bindRule(rule), offsetVector->at(ruleIndex));
        ruleIndex++;
    }
    return result;
}
예제 #9
0
void CSSPageRule::setSelectorText(const String& selectorText)
{
    Document* doc = 0;
    if (CSSStyleSheet* styleSheet = parentStyleSheet())
        doc = styleSheet->findDocument();
    if (!doc)
        return;
    
    CSSParser p;
    CSSSelectorList selectorList;
    p.parseSelector(selectorText, doc, selectorList);
    if (!selectorList.first())
        return;
    
    String oldSelectorText = this->selectorText();
    m_selectorList.adopt(selectorList);
    
    if (this->selectorText() == oldSelectorText)
        return;
    doc->styleSelectorChanged(DeferRecalcStyle);
}
예제 #10
0
////////////////////
// Load a column style
void CListview::LoadColumnStyle(CListviewColumn::CColumnStyle &style, const CSSParser &css, const std::string &id, const std::string cl, const std::string &psclass)
{
	CSSParser::Selector sel = css.getStyleForElement("column", id, cl, psclass, getMyContext());
	style.ApplySelector(sel);
}
예제 #11
0
///////////////////
// Loads an item style
void CListview::LoadItemStyle(CItem::CItemStyle &style, const CSSParser &css, const std::string &element, const std::string &id, const std::string cl, const std::string &psclass)
{
	CSSParser::Selector sel = css.getStyleForElement(element, id, cl, psclass, getMyContext());
	style.ApplySelector(sel);
}
예제 #12
0
css::CSSStyleSheet loadStyleSheet(std::istream& stream)
{
    CSSParser parser;
    CSSInputStream cssStream(stream, "utf-8");
    return parser.parse(0, cssStream);
}