Exemplo n.º 1
0
CSSStyleSheet* InspectorCSSStore::inspectorStyleSheet(Document* ownerDocument, bool createIfAbsent, long callId)
{
    DocumentToStyleSheetMap::iterator it = m_documentNodeToInspectorStyleSheetMap.find(ownerDocument);
    if (it != m_documentNodeToInspectorStyleSheetMap.end())
        return it->second.get();
    if (!createIfAbsent)
        return 0;
    ExceptionCode ec = 0;
    RefPtr<Element> styleElement = ownerDocument->createElement("style", ec);
    if (!ec)
        styleElement->setAttribute("type", "text/css", ec);
    if (!ec)
        ownerDocument->head()->appendChild(styleElement, ec);
    if (ec) {
        m_inspectorController->inspectorFrontend()->didAddRule(callId, ScriptValue::undefined(), false);
        return 0;
    }
    StyleSheetList* styleSheets = ownerDocument->styleSheets();
    StyleSheet* styleSheet = styleSheets->item(styleSheets->length() - 1);
    if (!styleSheet->isCSSStyleSheet()) {
        m_inspectorController->inspectorFrontend()->didAddRule(callId, ScriptValue::undefined(), false);
        return 0;
    }
    CSSStyleSheet* inspectorStyleSheet = static_cast<CSSStyleSheet*>(styleSheet);
    m_documentNodeToInspectorStyleSheetMap.set(ownerDocument, inspectorStyleSheet);
    return inspectorStyleSheet;
}
static GroupId calculateGroupId(StyleBase* styleBase)
{
    ASSERT(styleBase);
    StyleBase* current = styleBase;
    StyleSheet* styleSheet = 0;
    while (true) {
        // Special case: CSSStyleDeclarations might be either inline and in this case
        // we need to group them with their node or regular ones.
        if (current->isMutableStyleDeclaration()) {
            CSSMutableStyleDeclaration* cssMutableStyleDeclaration = static_cast<CSSMutableStyleDeclaration*>(current);
            if (cssMutableStyleDeclaration->isInlineStyleDeclaration()) {
                ASSERT(cssMutableStyleDeclaration->parent()->isStyleSheet());
                return calculateGroupId(cssMutableStyleDeclaration->node());
            }
            // Either we have no parent, or this parent is a CSSRule.
            ASSERT(cssMutableStyleDeclaration->parent() == cssMutableStyleDeclaration->parentRule());
        }

        if (current->isStyleSheet())
            styleSheet = static_cast<StyleSheet*>(current);

        StyleBase* parent = current->parent();
        if (!parent)
            break;
        current = parent;
    }

    if (styleSheet) {
        if (Node* ownerNode = styleSheet->ownerNode())
            return calculateGroupId(ownerNode);
        return GroupId(styleSheet);
    }

    return GroupId(current);
}
static void disabledAttrSetter(v8::Local<v8::String> name, v8::Local<v8::Value> value, const v8::AccessorInfo& info)
{
    StyleSheet* imp = V8StyleSheet::toNative(info.Holder());
    bool v = value->BooleanValue();
    imp->setDisabled(v);
    return;
}
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);
}
void* V8StyleSheet::opaqueRootForGC(void* object, v8::Persistent<v8::Object> wrapper)
{
    ASSERT(!wrapper.IsIndependent());
    StyleSheet* impl = static_cast<StyleSheet*>(object);
    if (Node* owner = impl->ownerNode())
        return V8GCController::opaqueRootForGC(owner);
    return object;
}
Exemplo n.º 6
0
bool HTMLStyleElement::disabled() const
{
    StyleSheet* styleSheet = sheet();
    if (!styleSheet)
        return false;

    return styleSheet->disabled();
}
Exemplo n.º 7
0
void JSStyleSheet::putValueProperty(ExecState* exec, int token, JSValue* value)
{
    switch (token) {
    case DisabledAttrNum: {
        StyleSheet* imp = static_cast<StyleSheet*>(impl());
        imp->setDisabled(value->toBoolean(exec));
        break;
    }
    }
}
// static
CSSStyleSheet* InspectorCSSAgent::parentStyleSheet(StyleBase* styleBase)
{
    if (!styleBase)
        return 0;

    StyleSheet* styleSheet = styleBase->stylesheet();
    if (styleSheet && styleSheet->isCSSStyleSheet())
        return static_cast<CSSStyleSheet*>(styleSheet);

    return 0;
}
Exemplo n.º 9
0
void JSStyleSheet::markChildren(MarkStack& markStack)
{
    Base::markChildren(markStack);

    StyleSheet* sheet = impl();
    JSGlobalData& globalData = *Heap::heap(this)->globalData();

    unsigned length = sheet->length();
    for (unsigned i = 0; i < length; ++i)
        markDOMObjectWrapper(markStack, globalData, sheet->item(i));
}
Exemplo n.º 10
0
void HTMLStyleElement::getSubresourceAttributeStrings(Vector<String>& urls) const
{    
    HashSet<String> styleURLs;
    StyleSheet* styleSheet = const_cast<HTMLStyleElement*>(this)->sheet();
    if (styleSheet)
        styleSheet->addSubresourceURLStrings(styleURLs, ownerDocument()->baseURL());
    
    HashSet<String>::iterator end = styleURLs.end();
    for (HashSet<String>::iterator i = styleURLs.begin(); i != end; ++i)
        urls.append(*i);
}
static v8::Handle<v8::Value> mediaAttrGetter(v8::Local<v8::String> name, const v8::AccessorInfo& info)
{
    StyleSheet* imp = V8StyleSheet::toNative(info.Holder());
    RefPtr<MediaList> result = imp->media();
    v8::Handle<v8::Value> wrapper = result.get() ? v8::Handle<v8::Value>(DOMDataStore::getWrapper(result.get(), info.GetIsolate())) : v8Undefined();
    if (wrapper.IsEmpty()) {
        wrapper = toV8(result.get(), info.Holder(), info.GetIsolate());
        if (!wrapper.IsEmpty())
            V8DOMWrapper::setNamedHiddenReference(info.Holder(), "media", wrapper);
    }
    return wrapper;
}
Exemplo n.º 12
0
bool StyleSheetCandidate::canBeActivated(const String& currentPreferrableName) const
{
    StyleSheet* sheet = this->sheet();
    if (!sheet || sheet->disabled() || !sheet->isCSSStyleSheet())
        return false;
    const AtomicString& title = this->title();
    if (!isEnabledViaScript() && !title.isEmpty() && title != currentPreferrableName)
        return false;
    if (isAlternate() && title.isEmpty())
        return false;

    return true;
}
Exemplo n.º 13
0
static v8::Handle<v8::Value> mediaAttrGetter(v8::Local<v8::String> name, const v8::AccessorInfo& info)
{
    INC_STATS("DOM.StyleSheet.media._get");
    StyleSheet* imp = V8StyleSheet::toNative(info.Holder());
    RefPtr<MediaList> result = imp->media();
    v8::Handle<v8::Value> wrapper = result.get() ? getDOMObjectMap().get(result.get()) : v8::Handle<v8::Value>();
    if (wrapper.IsEmpty()) {
        wrapper = toV8(result.get());
        if (!wrapper.IsEmpty())
            V8DOMWrapper::setHiddenReference(info.Holder(), wrapper);
    }
    return wrapper;
}
Exemplo n.º 14
0
OleMainStream::Style OleMainStream::getStyleFromStylesheet(unsigned int styleId, const StyleSheet &stylesheet) {
	//TODO optimize it: StyleSheet can be map structure with styleId key
	Style style;
	if (styleId != Style::STYLE_INVALID && styleId != Style::STYLE_NIL && styleId != Style::STYLE_USER) {
		for (std::size_t index = 0; index < stylesheet.size(); ++index) {
			if (stylesheet.at(index).StyleIdCurrent == styleId) {
				return stylesheet.at(index);
			}
		}
	}
	style.StyleIdCurrent = styleId;
	return style;
}
Exemplo n.º 15
0
int OleMainStream::getStyleIndex(unsigned int styleId, const std::vector<bool> &isFilled, const StyleSheet &stylesheet) {
	//TODO optimize it: StyleSheet can be map structure with styleId key
	//in that case, this method will be excess
	if (styleId == Style::STYLE_INVALID) {
		return -1;
	}
	for (int index = 0; index < (int)stylesheet.size(); ++index) {
		if (isFilled.at(index) && stylesheet.at(index).StyleIdCurrent == styleId) {
			return index;
		}
	}
	return -1;
}
void InspectorCSSAgent::getAllStyles(RefPtr<InspectorArray>* styles)
{
    Vector<Document*> documents = m_domAgent->documents();
    for (Vector<Document*>::iterator it = documents.begin(); it != documents.end(); ++it) {
        StyleSheetList* list = (*it)->styleSheets();
        for (unsigned i = 0; i < list->length(); ++i) {
            StyleSheet* styleSheet = list->item(i);
            if (styleSheet->isCSSStyleSheet()) {
                InspectorStyleSheet* inspectorStyleSheet = bindStyleSheet(static_cast<CSSStyleSheet*>(styleSheet));
                (*styles)->pushString(inspectorStyleSheet->id());
            }
        }
    }
}
CSSStyleSheet::CSSStyleSheet(const StyleSheet &other)
{
    if (!other.isCSSStyleSheet())
	impl = 0;
    else
	operator=(other);
}
void ShadowTreeStyleSheetCollection::collectStyleSheets(StyleEngine* collections, Vector<RefPtr<StyleSheet> >& styleSheets, Vector<RefPtr<CSSStyleSheet> >& activeSheets)
{
    if (document()->settings() && !document()->settings()->authorAndUserStylesEnabled())
        return;

    DocumentOrderedList::iterator begin = m_styleSheetCandidateNodes.begin();
    DocumentOrderedList::iterator end = m_styleSheetCandidateNodes.end();
    for (DocumentOrderedList::iterator it = begin; it != end; ++it) {
        Node* node = *it;
        StyleSheet* sheet = 0;
        CSSStyleSheet* activeSheet = 0;

        if (!node->isHTMLElement() || !node->hasTagName(styleTag))
            continue;

        Element* element = toElement(node);
        AtomicString title = element->getAttribute(titleAttr);
        bool enabledViaScript = false;

        sheet = toHTMLStyleElement(node)->sheet();
        if (sheet && !sheet->disabled() && sheet->isCSSStyleSheet())
            activeSheet = static_cast<CSSStyleSheet*>(sheet);

        // FIXME: clarify how PREFERRED or ALTERNATE works in shadow trees.
        // Should we set preferred/selected stylesheets name in shadow trees and
        // use the name in document?
        AtomicString rel = element->getAttribute(relAttr);
        if (!enabledViaScript && sheet && !title.isEmpty()) {
            if (collections->preferredStylesheetSetName().isEmpty()) {
                if (element->hasLocalName(styleTag) || !rel.contains("alternate")) {
                    collections->setPreferredStylesheetSetName(title);
                    collections->setSelectedStylesheetSetName(title);
                }
            }
            if (title != collections->preferredStylesheetSetName())
                activeSheet = 0;
        }

        if (rel.contains("alternate") && title.isEmpty())
            activeSheet = 0;

        if (sheet)
            styleSheets.append(sheet);
        if (activeSheet)
            activeSheets.append(activeSheet);
    }
}
nsresult nsXBLPrototypeResources::FlushSkinSheets() {
  if (mStyleSheetList.Length() == 0) return NS_OK;

  nsCOMPtr<Document> doc = mLoader->mBinding->XBLDocumentInfo()->GetDocument();

  // If doc is null, we're in the process of tearing things down, so just
  // return without rebuilding anything.
  if (!doc) {
    return NS_OK;
  }

  // We have scoped stylesheets.  Reload any chrome stylesheets we
  // encounter.  (If they aren't skin sheets, it doesn't matter, since
  // they'll still be in the chrome cache.  Skip inline sheets, which
  // skin sheets can't be, and which in any case don't have a usable
  // URL to reload.)

  nsTArray<RefPtr<StyleSheet>> oldSheets;

  oldSheets.SwapElements(mStyleSheetList);

  mozilla::css::Loader* cssLoader = doc->CSSLoader();

  for (size_t i = 0, count = oldSheets.Length(); i < count; ++i) {
    StyleSheet* oldSheet = oldSheets[i];

    nsIURI* uri = oldSheet->GetSheetURI();

    RefPtr<StyleSheet> newSheet;
    if (!oldSheet->IsInline() && IsChromeURI(uri)) {
      if (NS_FAILED(cssLoader->LoadSheetSync(uri, &newSheet))) continue;
    } else {
      newSheet = oldSheet;
    }

    mStyleSheetList.AppendElement(newSheet);
  }

  // There may be no shell during unlink.
  if (auto* shell = doc->GetShell()) {
    MOZ_ASSERT(shell->GetPresContext());
    ComputeServoStyles(*shell->StyleSet());
  }

  return NS_OK;
}
StyleSheet* buildStyleSheet( const osg::Vec4 &color, float width )
{
    // Define a style for the feature data. Since we are going to render the
    // vectors as lines, configure the line symbolizer:
    Style style;

    LineSymbol* ls = style.getOrCreateSymbol<LineSymbol>();
    ls->stroke()->color() = color;
    ls->stroke()->width() = width;

    //AltitudeSymbol* as = style.getOrCreate<AltitudeSymbol>();
    //as->clamping() = AltitudeSymbol::CLAMP_TO_TERRAIN;

    StyleSheet* styleSheet = new StyleSheet();
    styleSheet->addStyle( style );
    return styleSheet;
}
Exemplo n.º 21
0
void JSStyleSheet::markChildren(MarkStack& markStack)
{
    Base::markChildren(markStack);

    StyleSheet* sheet = impl();
    JSGlobalData& globalData = *Heap::heap(this)->globalData();

    unsigned length = sheet->length();
    for (unsigned i = 0; i < length; ++i)
        markDOMObjectWrapper(markStack, globalData, sheet->item(i));

    // This prevents us from having a style sheet with a dangling ownerNode pointer.
    // A better solution would be to handle this on the DOM side -- if the style sheet
    // is kept around, then we want the node to stay around too. One possibility would
    // be to make ref/deref on the style sheet ref/deref the node instead, but there's
    // a lot of disentangling of the CSS DOM objects that would need to happen first.
    if (Node* ownerNode = sheet->ownerNode())
        markDOMNodeWrapper(markStack, ownerNode->document(), ownerNode);
}
void ShadowTreeStyleSheetCollection::collectStyleSheets(StyleEngine* engine, StyleSheetCollection& collection)
{
    DocumentOrderedList::iterator begin = m_styleSheetCandidateNodes.begin();
    DocumentOrderedList::iterator end = m_styleSheetCandidateNodes.end();
    for (DocumentOrderedList::iterator it = begin; it != end; ++it) {
        Node* node = *it;
        StyleSheet* sheet = 0;
        CSSStyleSheet* activeSheet = 0;

        if (!isHTMLStyleElement(*node))
            continue;

        HTMLStyleElement* element = toHTMLStyleElement(node);
        const AtomicString& title = element->fastGetAttribute(titleAttr);
        bool enabledViaScript = false;

        sheet = element->sheet();
        if (sheet && !sheet->disabled() && sheet->isCSSStyleSheet())
            activeSheet = toCSSStyleSheet(sheet);

        // FIXME: clarify how PREFERRED or ALTERNATE works in shadow trees.
        // Should we set preferred/selected stylesheets name in shadow trees and
        // use the name in document?
        if (!enabledViaScript && sheet && !title.isEmpty()) {
            if (engine->preferredStylesheetSetName().isEmpty()) {
                engine->setPreferredStylesheetSetName(title);
                engine->setSelectedStylesheetSetName(title);
            }
            if (title != engine->preferredStylesheetSetName())
                activeSheet = 0;
        }

        const AtomicString& rel = element->fastGetAttribute(relAttr);
        if (rel.contains("alternate") && title.isEmpty())
            activeSheet = 0;

        if (sheet)
            collection.appendSheetForList(sheet);
        if (activeSheet)
            collection.appendActiveStyleSheet(activeSheet);
    }
}
InspectorStyleSheet* InspectorCSSAgent::viaInspectorStyleSheet(Document* document, bool createIfAbsent)
{
    if (!document) {
        ASSERT(!createIfAbsent);
        return 0;
    }

    RefPtr<InspectorStyleSheet> inspectorStyleSheet = m_documentToInspectorStyleSheet.get(document);
    if (inspectorStyleSheet || !createIfAbsent)
        return inspectorStyleSheet.get();

    ExceptionCode ec = 0;
    RefPtr<Element> styleElement = document->createElement("style", ec);
    if (!ec)
        styleElement->setAttribute("type", "text/css", ec);
    if (!ec) {
        ContainerNode* targetNode;
        // HEAD is absent in ImageDocuments, for example.
        if (document->head())
            targetNode = document->head();
        else if (document->body())
            targetNode = document->body();
        else
            return 0;
        targetNode->appendChild(styleElement, ec);
    }
    if (ec)
        return 0;
    StyleSheetList* styleSheets = document->styleSheets();
    StyleSheet* styleSheet = styleSheets->item(styleSheets->length() - 1);
    if (!styleSheet->isCSSStyleSheet())
        return 0;
    CSSStyleSheet* cssStyleSheet = static_cast<CSSStyleSheet*>(styleSheet);
    String id = String::number(m_lastStyleSheetId++);
    inspectorStyleSheet = InspectorStyleSheet::create(id, cssStyleSheet, "inspector", m_domAgent->documentURLString(document));
    m_idToInspectorStyleSheet.set(id, inspectorStyleSheet);
    m_cssStyleSheetToInspectorStyleSheet.set(cssStyleSheet, inspectorStyleSheet);
    m_documentToInspectorStyleSheet.set(document, inspectorStyleSheet);
    return inspectorStyleSheet.get();
}
Exemplo n.º 24
0
void HTMLLinkElement::getSubresourceAttributeStrings(Vector<String>& urls) const
{    
    if (m_isIcon) {
        urls.append(href().string());
        return;
    }
    
    if (!m_isStyleSheet)
        return;
        
    // Append the URL of this link element.
    urls.append(href().string());
    
    // Walk the URLs linked by the linked-to stylesheet.
    HashSet<String> styleURLs;
    StyleSheet* styleSheet = const_cast<HTMLLinkElement*>(this)->sheet();
    if (styleSheet)
        styleSheet->addSubresourceURLStrings(styleURLs, href());
    
    HashSet<String>::iterator end = styleURLs.end();
    for (HashSet<String>::iterator i = styleURLs.begin(); i != end; ++i)
        urls.append(*i);
}
Exemplo n.º 25
0
KURL StyleBase::baseURL() const
{
    // Try to find the style sheet. If found look for its URL.
    // If it has none, get the URL from the parent sheet or the parent node.

    StyleSheet* sheet = const_cast<StyleBase*>(this)->stylesheet();
    if (!sheet)
        return KURL();
    if (!sheet->href().isNull())
        return KURL(sheet->href());
    if (sheet->parent()) 
        return sheet->parent()->baseURL();
    if (!sheet->ownerNode()) 
        return KURL();
    return sheet->ownerNode()->document()->baseURL();
}
Exemplo n.º 26
0
void setJSStyleSheetDisabled(ExecState* exec, JSObject* thisObject, JSValue value)
{
    StyleSheet* imp = static_cast<StyleSheet*>(static_cast<JSStyleSheet*>(thisObject)->impl());
    imp->setDisabled(value.toBoolean(exec));
}
Exemplo n.º 27
0
JSValue jsStyleSheetMedia(ExecState* exec, const Identifier&, const PropertySlot& slot)
{
    UNUSED_PARAM(exec);
    StyleSheet* imp = static_cast<StyleSheet*>(static_cast<JSStyleSheet*>(asObject(slot.slotBase()))->impl());
    return toJS(exec, WTF::getPtr(imp->media()));
}
Exemplo n.º 28
0
JSValue jsStyleSheetTitle(ExecState* exec, const Identifier&, const PropertySlot& slot)
{
    UNUSED_PARAM(exec);
    StyleSheet* imp = static_cast<StyleSheet*>(static_cast<JSStyleSheet*>(asObject(slot.slotBase()))->impl());
    return jsStringOrNull(exec, imp->title());
}
Exemplo n.º 29
0
void
nsLayoutStylesheetCache::BuildPreferenceSheet(RefPtr<StyleSheet>* aSheet,
                                              nsPresContext* aPresContext)
{
  if (mBackendType == StyleBackendType::Gecko) {
    *aSheet = new CSSStyleSheet(eAgentSheetFeatures, CORS_NONE,
                                mozilla::net::RP_Default);
  } else {
    *aSheet = new ServoStyleSheet(eAgentSheetFeatures, CORS_NONE,
                                  mozilla::net::RP_Default, dom::SRIMetadata());
  }

  StyleSheet* sheet = *aSheet;

  nsCOMPtr<nsIURI> uri;
  NS_NewURI(getter_AddRefs(uri), "about:PreferenceStyleSheet", nullptr);
  MOZ_ASSERT(uri, "URI creation shouldn't fail");

  sheet->SetURIs(uri, uri, uri);
  sheet->SetComplete();

  static const uint32_t kPreallocSize = 1024;

  nsString sheetText;
  sheetText.SetCapacity(kPreallocSize);

#define NS_GET_R_G_B(color_) \
  NS_GET_R(color_), NS_GET_G(color_), NS_GET_B(color_)

  sheetText.AppendLiteral(
      "@namespace url(http://www.w3.org/1999/xhtml);\n"
      "@namespace svg url(http://www.w3.org/2000/svg);\n");

  // Rules for link styling.
  nscolor linkColor = aPresContext->DefaultLinkColor();
  nscolor activeColor = aPresContext->DefaultActiveLinkColor();
  nscolor visitedColor = aPresContext->DefaultVisitedLinkColor();

  sheetText.AppendPrintf(
      "*|*:link { color: #%02x%02x%02x; }\n"
      "*|*:any-link:active { color: #%02x%02x%02x; }\n"
      "*|*:visited { color: #%02x%02x%02x; }\n",
      NS_GET_R_G_B(linkColor),
      NS_GET_R_G_B(activeColor),
      NS_GET_R_G_B(visitedColor));

  bool underlineLinks =
    aPresContext->GetCachedBoolPref(kPresContext_UnderlineLinks);
  sheetText.AppendPrintf(
      "*|*:any-link%s { text-decoration: %s; }\n",
      underlineLinks ? ":not(svg|a)" : "",
      underlineLinks ? "underline" : "none");

  // Rules for focus styling.

  bool focusRingOnAnything = aPresContext->GetFocusRingOnAnything();
  uint8_t focusRingWidth = aPresContext->FocusRingWidth();
  uint8_t focusRingStyle = aPresContext->GetFocusRingStyle();

  if ((focusRingWidth != 1 && focusRingWidth <= 4) || focusRingOnAnything) {
    if (focusRingWidth != 1) {
      // If the focus ring width is different from the default, fix buttons
      // with rings.
      sheetText.AppendPrintf(
          "button::-moz-focus-inner, input[type=\"reset\"]::-moz-focus-inner, "
          "input[type=\"button\"]::-moz-focus-inner, "
          "input[type=\"submit\"]::-moz-focus-inner { "
          "padding: 1px 2px 1px 2px; "
          "border: %dpx %s transparent !important; }\n",
          focusRingWidth,
          focusRingStyle == 0 ? "solid" : "dotted");

      sheetText.AppendLiteral(
          "button:focus::-moz-focus-inner, "
          "input[type=\"reset\"]:focus::-moz-focus-inner, "
          "input[type=\"button\"]:focus::-moz-focus-inner, "
          "input[type=\"submit\"]:focus::-moz-focus-inner { "
          "border-color: ButtonText !important; }\n");
    }

    sheetText.AppendPrintf(
        "%s { outline: %dpx %s !important; %s}\n",
        focusRingOnAnything ?
          ":focus" :
          "*|*:link:focus, *|*:visited:focus",
        focusRingWidth,
        focusRingStyle == 0 ? // solid
          "solid -moz-mac-focusring" : "dotted WindowText",
        focusRingStyle == 0 ? // solid
          "-moz-outline-radius: 3px; outline-offset: 1px; " : "");
  }

  if (aPresContext->GetUseFocusColors()) {
    nscolor focusText = aPresContext->FocusTextColor();
    nscolor focusBG = aPresContext->FocusBackgroundColor();
    sheetText.AppendPrintf(
        "*:focus, *:focus > font { color: #%02x%02x%02x !important; "
        "background-color: #%02x%02x%02x !important; }\n",
        NS_GET_R_G_B(focusText),
        NS_GET_R_G_B(focusBG));
  }

  NS_ASSERTION(sheetText.Length() <= kPreallocSize,
               "kPreallocSize should be big enough to build preference style "
               "sheet without reallocation");

  if (sheet->IsGecko()) {
    sheet->AsGecko()->ReparseSheet(sheetText);
  } else {
    nsresult rv = sheet->AsServo()->ParseSheet(sheetText, uri, uri, nullptr, 0);
    // Parsing the about:PreferenceStyleSheet URI can only fail on OOM. If we
    // are OOM before we parsed any documents we might as well abort.
    MOZ_RELEASE_ASSERT(NS_SUCCEEDED(rv));
  }

#undef NS_GET_R_G_B
}
Exemplo n.º 30
0
StyleSheet QStyleSheetStyle::getDefaultStyleSheet() const
{
    StyleSheet sheet;
    StyleRule styleRule;
    BasicSelector bSelector;
    Selector selector;
    Declaration decl;
    Value value;
    Pseudo pseudo;
    AttributeSelector attr;

    // pixmap based style doesn't support any features
    bool styleIsPixmapBased = baseStyle()->inherits("QMacStyle")
                           || baseStyle()->inherits("QWindowsXPStyle")
                           || baseStyle()->inherits("QGtkStyle")
                           || baseStyle()->inherits("QS60Style");


    /*QLineEdit {
        -qt-background-role: base;
        border: native;
        -qt-style-features: background-color;
    }*/
    {
        SET_ELEMENT_NAME(QLatin1String("QLineEdit"));
        ADD_BASIC_SELECTOR;
        ADD_SELECTOR;

        SET_PROPERTY(QLatin1String("-qt-background-role"), QtBackgroundRole);
        ADD_VALUE(Value::KnownIdentifier, Value_Base);
        ADD_DECLARATION;

        SET_PROPERTY(QLatin1String("border"), Border);
        ADD_VALUE(Value::KnownIdentifier, Value_Native);
        ADD_DECLARATION;

        SET_PROPERTY(QLatin1String("-qt-style-features"), QtStyleFeatures);
        ADD_VALUE(Value::Identifier, QString::fromLatin1("background-color"));
        ADD_DECLARATION;

        ADD_STYLE_RULE;
    }

    /*QLineEdit:no-frame {
        border: none;
    }*/
    {
        SET_ELEMENT_NAME(QLatin1String("QLineEdit"));
        ADD_PSEUDO(QLatin1String("no-frame"), PseudoClass_Frameless);
        ADD_BASIC_SELECTOR;
        ADD_SELECTOR;

        SET_PROPERTY(QLatin1String("border"), Border);
        ADD_VALUE(Value::KnownIdentifier, Value_None);
        ADD_DECLARATION;

        ADD_STYLE_RULE;
    }

    /*QFrame {
        border: native;
    }*/
    {
        SET_ELEMENT_NAME(QLatin1String("QFrame"));
        ADD_BASIC_SELECTOR;
        ADD_SELECTOR;

        SET_PROPERTY(QLatin1String("border"), Border);
        ADD_VALUE(Value::KnownIdentifier, Value_Native);
        ADD_DECLARATION;

        ADD_STYLE_RULE;
    }

    /*QLabel, QToolBox {
        background: none;
        border-image: none;
    }*/
    {
        SET_ELEMENT_NAME(QLatin1String("QLabel"));
        ADD_BASIC_SELECTOR;
        ADD_SELECTOR;

        SET_ELEMENT_NAME(QLatin1String("QToolBox"));
        ADD_BASIC_SELECTOR;
        ADD_SELECTOR;

        SET_PROPERTY(QLatin1String("background"), Background);
        ADD_VALUE(Value::KnownIdentifier, Value_None);
        ADD_DECLARATION;

        SET_PROPERTY(QLatin1String("border-image"), BorderImage);
        ADD_VALUE(Value::KnownIdentifier, Value_None);
        ADD_DECLARATION;

        ADD_STYLE_RULE;
    }

    /*QGroupBox {
        border: native;
    }*/
    {
        SET_ELEMENT_NAME(QLatin1String("QGroupBox"));
        ADD_BASIC_SELECTOR;
        ADD_SELECTOR;

        SET_PROPERTY(QLatin1String("border"), Border);
        ADD_VALUE(Value::KnownIdentifier, Value_Native);
        ADD_DECLARATION;

        ADD_STYLE_RULE;
    }


    /*QToolTip {
        -qt-background-role: window;
        border: native;
    }*/
    {
        SET_ELEMENT_NAME(QLatin1String("QToolTip"));
        ADD_BASIC_SELECTOR;
        ADD_SELECTOR;

        SET_PROPERTY(QLatin1String("-qt-background-role"), QtBackgroundRole);
        ADD_VALUE(Value::KnownIdentifier, Value_Window);
        ADD_DECLARATION;

        SET_PROPERTY(QLatin1String("border"), Border);
        ADD_VALUE(Value::KnownIdentifier, Value_Native);
        ADD_DECLARATION;

        ADD_STYLE_RULE;
    }

    /*QPushButton, QToolButton {
        border-style: native;
        -qt-style-features: background-color;  //only for not pixmap based styles
    }*/
    {
        SET_ELEMENT_NAME(QLatin1String("QPushButton"));
        ADD_BASIC_SELECTOR;
        ADD_SELECTOR;

        SET_ELEMENT_NAME(QLatin1String("QToolButton"));
        ADD_BASIC_SELECTOR;
        ADD_SELECTOR;

        SET_PROPERTY(QLatin1String("border-style"), BorderStyles);
        ADD_VALUE(Value::KnownIdentifier, Value_Native);
        ADD_DECLARATION;

        if (!styleIsPixmapBased) {
            SET_PROPERTY(QLatin1String("-qt-style-features"), QtStyleFeatures);
            ADD_VALUE(Value::Identifier, QString::fromLatin1("background-color"));
            ADD_DECLARATION;
        }


        ADD_STYLE_RULE;
    }


    /*QComboBox {
        border: native;
        -qt-style-features: background-color background-gradient;   //only for not pixmap based styles
        -qt-background-role: base;
    }*/

    {
        SET_ELEMENT_NAME(QLatin1String("QComboBox"));
        ADD_BASIC_SELECTOR;
        ADD_SELECTOR;

        SET_PROPERTY(QLatin1String("border"), Border);
        ADD_VALUE(Value::KnownIdentifier, Value_Native);
        ADD_DECLARATION;

        if (!styleIsPixmapBased) {
            SET_PROPERTY(QLatin1String("-qt-style-features"), QtStyleFeatures);
            ADD_VALUE(Value::Identifier, QString::fromLatin1("background-color"));
            ADD_VALUE(Value::Identifier, QString::fromLatin1("background-gradient"));
            ADD_DECLARATION;
        }

        SET_PROPERTY(QLatin1String("-qt-background-role"), QtBackgroundRole);
        ADD_VALUE(Value::KnownIdentifier, Value_Base);
        ADD_DECLARATION;

        ADD_STYLE_RULE;
    }

    /*QComboBox[style="QPlastiqueStyle"][readOnly="true"],
    QComboBox[style="QCleanlooksStyle"][readOnly="true"]
    {
        -qt-background-role: button;
    }*/
    if (baseStyle()->inherits("QPlastiqueStyle")  || baseStyle()->inherits("QCleanlooksStyle"))
    {
        SET_ELEMENT_NAME(QLatin1String("QComboBox"));
        ADD_ATTRIBUTE_SELECTOR(QLatin1String("readOnly"), QLatin1String("true"), AttributeSelector::MatchEqual);
        ADD_BASIC_SELECTOR;
        ADD_SELECTOR;

        SET_PROPERTY(QLatin1String("-qt-background-role"), QtBackgroundRole);
        ADD_VALUE(Value::KnownIdentifier, Value_Button);
        ADD_DECLARATION;

        ADD_STYLE_RULE;
    }

    /*QAbstractSpinBox {
        border: native;
        -qt-style-features: background-color;
        -qt-background-role: base;
    }*/
    {
        SET_ELEMENT_NAME(QLatin1String("QAbstractSpinBox"));
        ADD_BASIC_SELECTOR;
        ADD_SELECTOR;

        SET_PROPERTY(QLatin1String("border"), Border);
        ADD_VALUE(Value::KnownIdentifier, Value_Native);
        ADD_DECLARATION;

        SET_PROPERTY(QLatin1String("-qt-style-features"), QtStyleFeatures);
        ADD_VALUE(Value::Identifier, QString::fromLatin1("background-color"));
        ADD_DECLARATION;

        SET_PROPERTY(QLatin1String("-qt-background-role"), QtBackgroundRole);
        ADD_VALUE(Value::KnownIdentifier, Value_Base);
        ADD_DECLARATION;

        ADD_STYLE_RULE;
    }

    /*QMenu {
        -qt-background-role: window;
    }*/
    {
        SET_ELEMENT_NAME(QLatin1String("QMenu"));
        ADD_BASIC_SELECTOR;
        ADD_SELECTOR;

        SET_PROPERTY(QLatin1String("-qt-background-role"), QtBackgroundRole);
        ADD_VALUE(Value::KnownIdentifier, Value_Window);
        ADD_DECLARATION;

        ADD_STYLE_RULE;
    }
    /*QMenu::item {
        -qt-style-features: background-color;
    }*/
    if (!styleIsPixmapBased) {
        SET_ELEMENT_NAME(QLatin1String("QMenu"));
        ADD_PSEUDO(QLatin1String("item"), PseudoClass_Unknown);
        ADD_BASIC_SELECTOR;
        ADD_SELECTOR;

        SET_PROPERTY(QLatin1String("-qt-style-features"), QtStyleFeatures);
        ADD_VALUE(Value::Identifier, QString::fromLatin1("background-color"));
        ADD_DECLARATION;

        ADD_STYLE_RULE;
    }

    /*QHeaderView {
        -qt-background-role: window;
    }*/
    {
        SET_ELEMENT_NAME(QLatin1String("QHeaderView"));
        ADD_BASIC_SELECTOR;
        ADD_SELECTOR;

        SET_PROPERTY(QLatin1String("-qt-background-role"), QtBackgroundRole);
        ADD_VALUE(Value::KnownIdentifier, Value_Window);
        ADD_DECLARATION;

        ADD_STYLE_RULE;
    }

    /*QTableCornerButton::section, QHeaderView::section {
        -qt-background-role: button;
        -qt-style-features: background-color; //if style is not pixmap based
        border: native;
    }*/
    {
        SET_ELEMENT_NAME(QLatin1String("QTableCornerButton"));
        ADD_PSEUDO(QLatin1String("section"), PseudoClass_Unknown);
        ADD_BASIC_SELECTOR;
        ADD_SELECTOR;

        SET_ELEMENT_NAME(QLatin1String("QHeaderView"));
        ADD_PSEUDO(QLatin1String("section"), PseudoClass_Unknown);
        ADD_BASIC_SELECTOR;
        ADD_SELECTOR;

        SET_PROPERTY(QLatin1String("-qt-background-role"), QtBackgroundRole);
        ADD_VALUE(Value::KnownIdentifier, Value_Button);
        ADD_DECLARATION;

        if (!styleIsPixmapBased) {
            SET_PROPERTY(QLatin1String("-qt-style-features"), QtStyleFeatures);
            ADD_VALUE(Value::Identifier, QString::fromLatin1("background-color"));
            ADD_DECLARATION;
        }

        SET_PROPERTY(QLatin1String("border"), Border);
        ADD_VALUE(Value::KnownIdentifier, Value_Native);
        ADD_DECLARATION;

        ADD_STYLE_RULE;
    }

    /*QProgressBar {
        -qt-background-role: base;
    }*/
    {
        SET_ELEMENT_NAME(QLatin1String("QProgressBar"));
        ADD_BASIC_SELECTOR;
        ADD_SELECTOR;

        SET_PROPERTY(QLatin1String("-qt-background-role"), QtBackgroundRole);
        ADD_VALUE(Value::KnownIdentifier, Value_Base);
        ADD_DECLARATION;

        ADD_STYLE_RULE;
    }

    /*QScrollBar {
        -qt-background-role: window;
    }*/
    {
        SET_ELEMENT_NAME(QLatin1String("QScrollBar"));
        ADD_BASIC_SELECTOR;
        ADD_SELECTOR;

        SET_PROPERTY(QLatin1String("-qt-background-role"), QtBackgroundRole);
        ADD_VALUE(Value::KnownIdentifier, Value_Window);
        ADD_DECLARATION;

        ADD_STYLE_RULE;
    }

    /*QDockWidget {
        border: native;
    }*/
    {
        SET_ELEMENT_NAME(QLatin1String("QDockWidget"));
        ADD_BASIC_SELECTOR;
        ADD_SELECTOR;

        SET_PROPERTY(QLatin1String("border"), Border);
        ADD_VALUE(Value::KnownIdentifier, Value_Native);
        ADD_DECLARATION;

        ADD_STYLE_RULE;
    }

    sheet.origin = StyleSheetOrigin_UserAgent;
    sheet.buildIndexes();
    return sheet;
}