~ubuntu-branches/ubuntu/lucid/webkit/lucid-updates

« back to all changes in this revision

Viewing changes to WebCore/css/CSSStyleSelector.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Gustavo Noronha Silva
  • Date: 2010-02-04 19:30:57 UTC
  • mfrom: (1.2.8 upstream) (4.3.9 sid)
  • Revision ID: james.westby@ubuntu.com-20100204193057-d3018lm1fipb0703
* New upstream release
* debian/copyright:
- Updated with changes since 1.1.19.

Show diffs side-by-side

added added

removed removed

Lines of Context:
361
361
    void addToRuleSet(AtomicStringImpl* key, AtomRuleMap& map,
362
362
                      CSSStyleRule* rule, CSSSelector* sel);
363
363
    
364
 
    CSSRuleDataList* getIDRules(AtomicStringImpl* key) { return m_idRules.get(key); }
365
 
    CSSRuleDataList* getClassRules(AtomicStringImpl* key) { return m_classRules.get(key); }
366
 
    CSSRuleDataList* getTagRules(AtomicStringImpl* key) { return m_tagRules.get(key); }
 
364
    CSSRuleDataList* getIDRules(AtomicStringImpl* key) { m_idRules.checkConsistency(); return m_idRules.get(key); }
 
365
    CSSRuleDataList* getClassRules(AtomicStringImpl* key) { m_classRules.checkConsistency(); return m_classRules.get(key); }
 
366
    CSSRuleDataList* getTagRules(AtomicStringImpl* key) { m_tagRules.checkConsistency(); return m_tagRules.get(key); }
367
367
    CSSRuleDataList* getUniversalRules() { return m_universalRules; }
368
368
    
369
369
public:
414
414
    , m_fontSelector(CSSFontSelector::create(doc))
415
415
{
416
416
    init();
417
 
 
 
417
        
418
418
    m_matchAuthorAndUserStyles = matchAuthorAndUserStyles;
419
419
    
420
420
    Element* root = doc->documentElement();
441
441
        m_medium = new MediaQueryEvaluator("all");
442
442
 
443
443
    if (root)
444
 
        m_rootDefaultStyle = styleForElement(root, 0, false, true); // dont ref, because the RenderStyle is allocated from global heap
 
444
        m_rootDefaultStyle = styleForElement(root, 0, false, true); // don't ref, because the RenderStyle is allocated from global heap
445
445
 
446
446
    if (m_rootDefaultStyle && view) {
447
447
        delete m_medium;
463
463
    // add stylesheets from document
464
464
    m_authorStyle = new CSSRuleSet();
465
465
    
466
 
    // Add rules from elments like SVG's <font-face>
 
466
    // Add rules from elements like SVG's <font-face>
467
467
    if (mappedElementSheet)
468
468
        m_authorStyle->addRulesFromSheet(mappedElementSheet, *m_medium, this);
469
469
 
473
473
        if (sheet->isCSSStyleSheet() && !sheet->disabled())
474
474
            m_authorStyle->addRulesFromSheet(static_cast<CSSStyleSheet*>(sheet), *m_medium, this);
475
475
    }
 
476
    
 
477
    if (doc->renderer() && doc->renderer()->style())
 
478
        doc->renderer()->style()->font().update(fontSelector());
476
479
}
477
480
 
478
481
// This is a simplified style setting function for keyframe styles
759
762
        return;
760
763
    }
761
764
 
762
 
    // Peform a merge sort for larger lists.
 
765
    // Perform a merge sort for larger lists.
763
766
    unsigned mid = (start + end) / 2;
764
767
    sortMatchedRules(start, mid);
765
768
    sortMatchedRules(mid, end);
1001
1004
 
1002
1005
                if (s->isDefaultButtonForForm() != m_element->isDefaultButtonForForm())
1003
1006
                    return false;
1004
 
 
1005
 
                if ((s->willValidate() && s->isValidFormControlElement()) !=
1006
 
                    (m_element->willValidate() && m_element->isValidFormControlElement()))
 
1007
                
 
1008
                if (!m_element->document()->containsValidityStyleRules())
 
1009
                    return false;
 
1010
                
 
1011
                bool willValidate = s->willValidate();
 
1012
                if (willValidate != m_element->willValidate())
 
1013
                    return false;
 
1014
                
 
1015
                if (willValidate && (s->isValidFormControlElement() != m_element->isValidFormControlElement()))
1007
1016
                    return false;
1008
1017
            }
1009
1018
 
1089
1098
    }
1090
1099
}
1091
1100
 
 
1101
PassRefPtr<RenderStyle> CSSStyleSelector::styleForDocument(Document* document)
 
1102
{
 
1103
    RefPtr<RenderStyle> documentStyle = RenderStyle::create();
 
1104
    documentStyle->setDisplay(BLOCK);
 
1105
    documentStyle->setVisuallyOrdered(document->visuallyOrdered());
 
1106
    documentStyle->setZoom(document->frame()->pageZoomFactor());
 
1107
    
 
1108
    FontDescription fontDescription;
 
1109
    fontDescription.setUsePrinterFont(document->printing());
 
1110
    if (Settings* settings = document->settings()) {
 
1111
        fontDescription.setRenderingMode(settings->fontRenderingMode());
 
1112
        if (document->printing() && !settings->shouldPrintBackgrounds())
 
1113
            documentStyle->setForceBackgroundsToWhite(true);
 
1114
        const AtomicString& stdfont = settings->standardFontFamily();
 
1115
        if (!stdfont.isEmpty()) {
 
1116
            fontDescription.firstFamily().setFamily(stdfont);
 
1117
            fontDescription.firstFamily().appendFamily(0);
 
1118
        }
 
1119
        fontDescription.setKeywordSize(CSSValueMedium - CSSValueXxSmall + 1);
 
1120
        int size = CSSStyleSelector::fontSizeForKeyword(document, CSSValueMedium, false);
 
1121
        fontDescription.setSpecifiedSize(size);
 
1122
        fontDescription.setComputedSize(CSSStyleSelector::getComputedSizeFromSpecifiedSize(document, fontDescription.isAbsoluteSize(), size, documentStyle->effectiveZoom()));
 
1123
    }
 
1124
 
 
1125
    documentStyle->setFontDescription(fontDescription);
 
1126
    documentStyle->font().update(0);
 
1127
    if (document->inCompatMode())
 
1128
        documentStyle->setHtmlHacks(true); // enable html specific rendering tricks
 
1129
        
 
1130
    return documentStyle.release();
 
1131
}
 
1132
 
1092
1133
// If resolveForRootDefault is true, style based on user agent style sheet only. This is used in media queries, where
1093
1134
// relative units are interpreted according to document root element style, styled only with UA stylesheet
1094
1135
 
1295
1336
    // Get the keyframesRule for this name
1296
1337
    if (!e || list.animationName().isEmpty())
1297
1338
        return;
1298
 
            
 
1339
 
 
1340
    m_keyframesRuleMap.checkConsistency();
 
1341
   
1299
1342
    if (!m_keyframesRuleMap.contains(list.animationName().impl()))
1300
1343
        return;
1301
1344
        
2407
2450
                return e && e->isOptionalFormControl();
2408
2451
            case CSSSelector::PseudoRequired:
2409
2452
                return e && e->isRequiredFormControl();
2410
 
            case CSSSelector::PseudoValid:
2411
 
                return e && e->willValidate() && e->isValidFormControlElement();
2412
 
            case CSSSelector::PseudoInvalid:
2413
 
                return e && e->willValidate() && !e->isValidFormControlElement();
2414
 
            case CSSSelector::PseudoChecked: {
 
2453
            case CSSSelector::PseudoValid: {
 
2454
                if (!e)
 
2455
                    return false;
 
2456
                e->document()->setContainsValidityStyleRules();
 
2457
                return e->willValidate() && e->isValidFormControlElement();
 
2458
            } case CSSSelector::PseudoInvalid: {
 
2459
                if (!e)
 
2460
                    return false;
 
2461
                e->document()->setContainsValidityStyleRules();
 
2462
                return e->willValidate() && !e->isValidFormControlElement();
 
2463
            } case CSSSelector::PseudoChecked: {
2415
2464
                if (!e || !e->isFormControlElement())
2416
2465
                    break;
2417
2466
                // Even though WinIE allows checked and indeterminate to co-exist, the CSS selector spec says that
2871
2920
                    case CSSPropertyFontVariant:
2872
2921
                    case CSSPropertyZoom:
2873
2922
                        // these have to be applied first, because other properties use the computed
2874
 
                        // values of these porperties.
 
2923
                        // values of these properties.
2875
2924
                        first = true;
2876
2925
                        break;
2877
2926
                    default:
3036
3085
#if ENABLE(WCSS)
3037
3086
        if (primitiveValue) {
3038
3087
            if (primitiveValue->getIdent() == CSSValueWapMarquee) {
3039
 
                // Initialize Wap Marquee style
 
3088
                // Initialize WAP Marquee style
3040
3089
                m_style->setOverflowX(OMARQUEE);
3041
3090
                m_style->setOverflowY(OMARQUEE);
3042
3091
                m_style->setWhiteSpace(NOWRAP);
3885
3934
            if (m_parentNode)
3886
3935
                fontDescription.setKeywordSize(m_parentStyle->fontDescription().keywordSize());
3887
3936
        } else if (isInitial) {
3888
 
            size = fontSizeForKeyword(CSSValueMedium, m_style->htmlHacks(), fontDescription.useFixedDefaultSize());
 
3937
            size = fontSizeForKeyword(m_checker.m_document, CSSValueMedium, fontDescription.useFixedDefaultSize());
3889
3938
            fontDescription.setKeywordSize(CSSValueMedium - CSSValueXxSmall + 1);
3890
3939
        } else if (primitiveValue->getIdent()) {
3891
3940
            // Keywords are being used.
3898
3947
                case CSSValueXLarge:
3899
3948
                case CSSValueXxLarge:
3900
3949
                case CSSValueWebkitXxxLarge:
3901
 
                    size = fontSizeForKeyword(primitiveValue->getIdent(), m_style->htmlHacks(), fontDescription.useFixedDefaultSize());
 
3950
                    size = fontSizeForKeyword(m_checker.m_document, primitiveValue->getIdent(), fontDescription.useFixedDefaultSize());
3902
3951
                    fontDescription.setKeywordSize(primitiveValue->getIdent() - CSSValueXxSmall + 1);
3903
3952
                    break;
3904
3953
                case CSSValueLarger:
4147
4196
            // We need to adjust the size to account for the generic family change from monospace
4148
4197
            // to non-monospace.
4149
4198
            if (fontDescription.keywordSize() && fontDescription.useFixedDefaultSize())
4150
 
                setFontSize(fontDescription, fontSizeForKeyword(CSSValueXxSmall + fontDescription.keywordSize() - 1, m_style->htmlHacks(), false));
 
4199
                setFontSize(fontDescription, fontSizeForKeyword(m_checker.m_document, CSSValueXxSmall + fontDescription.keywordSize() - 1, false));
4151
4200
            fontDescription.setGenericFamily(initialDesc.genericFamily());
4152
4201
            if (!initialDesc.firstFamily().familyIsEmpty())
4153
4202
                fontDescription.setFamily(initialDesc.firstFamily());
4224
4273
        // If currFamily is non-zero then we set at least one family on this description.
4225
4274
        if (currFamily) {
4226
4275
            if (fontDescription.keywordSize() && fontDescription.useFixedDefaultSize() != oldFamilyUsedFixedDefaultSize)
4227
 
                setFontSize(fontDescription, fontSizeForKeyword(CSSValueXxSmall + fontDescription.keywordSize() - 1, m_style->htmlHacks(), !oldFamilyUsedFixedDefaultSize));
 
4276
                setFontSize(fontDescription, fontSizeForKeyword(m_checker.m_document, CSSValueXxSmall + fontDescription.keywordSize() - 1, !oldFamilyUsedFixedDefaultSize));
4228
4277
 
4229
4278
            if (m_style->setFontDescription(fontDescription))
4230
4279
                m_fontDirty = true;
4444
4493
                fontDescription.firstFamily().appendFamily(0);
4445
4494
            }
4446
4495
            fontDescription.setKeywordSize(CSSValueMedium - CSSValueXxSmall + 1);
4447
 
            setFontSize(fontDescription, fontSizeForKeyword(CSSValueMedium, m_style->htmlHacks(), false));
 
4496
            setFontSize(fontDescription, fontSizeForKeyword(m_checker.m_document, CSSValueMedium, false));
4448
4497
            m_style->setLineHeight(RenderStyle::initialLineHeight());
4449
4498
            m_lineHeightValue = 0;
4450
4499
            if (m_style->setFontDescription(fontDescription))
4467
4516
                fontDescription.setUsePrinterFont(m_checker.m_document->printing());
4468
4517
           
4469
4518
                // Handle the zoom factor.
4470
 
                fontDescription.setComputedSize(getComputedSizeFromSpecifiedSize(fontDescription.isAbsoluteSize(), fontDescription.specifiedSize()));
 
4519
                fontDescription.setComputedSize(getComputedSizeFromSpecifiedSize(m_checker.m_document, fontDescription.isAbsoluteSize(), fontDescription.specifiedSize(), m_style->effectiveZoom()));
4471
4520
                if (m_style->setFontDescription(fontDescription))
4472
4521
                    m_fontDirty = true;
4473
4522
            }
5789
5838
    // multiplying by our scale factor.
5790
5839
    float size;
5791
5840
    if (childFont.keywordSize())
5792
 
        size = fontSizeForKeyword(CSSValueXxSmall + childFont.keywordSize() - 1, style->htmlHacks(), childFont.useFixedDefaultSize());
 
5841
        size = fontSizeForKeyword(m_checker.m_document, CSSValueXxSmall + childFont.keywordSize() - 1, childFont.useFixedDefaultSize());
5793
5842
    else {
5794
5843
        Settings* settings = m_checker.m_document->settings();
5795
5844
        float fixedScaleFactor = settings
5808
5857
void CSSStyleSelector::setFontSize(FontDescription& fontDescription, float size)
5809
5858
{
5810
5859
    fontDescription.setSpecifiedSize(size);
5811
 
    fontDescription.setComputedSize(getComputedSizeFromSpecifiedSize(fontDescription.isAbsoluteSize(), size));
 
5860
    fontDescription.setComputedSize(getComputedSizeFromSpecifiedSize(m_checker.m_document, fontDescription.isAbsoluteSize(), size, m_style->effectiveZoom()));
5812
5861
}
5813
5862
 
5814
 
float CSSStyleSelector::getComputedSizeFromSpecifiedSize(bool isAbsoluteSize, float specifiedSize)
 
5863
float CSSStyleSelector::getComputedSizeFromSpecifiedSize(Document* document, bool isAbsoluteSize, float specifiedSize, float zoomFactor)
5815
5864
{
5816
5865
    // We support two types of minimum font size.  The first is a hard override that applies to
5817
5866
    // all fonts.  This is "minSize."  The second type of minimum font size is a "smart minimum"
5823
5872
    // However we always allow the page to set an explicit pixel size that is smaller,
5824
5873
    // since sites will mis-render otherwise (e.g., http://www.gamespot.com with a 9px minimum).
5825
5874
    
5826
 
    Settings* settings = m_checker.m_document->settings();
 
5875
    Settings* settings = document->settings();
5827
5876
    if (!settings)
5828
5877
        return 1.0f;
5829
5878
 
5830
5879
    int minSize = settings->minimumFontSize();
5831
5880
    int minLogicalSize = settings->minimumLogicalFontSize();
5832
5881
 
5833
 
    float zoomFactor = m_style->effectiveZoom();
5834
 
    if (m_checker.m_document->frame() && m_checker.m_document->frame()->shouldApplyTextZoom())
5835
 
        zoomFactor *= m_checker.m_document->frame()->textZoomFactor();
 
5882
    if (document->frame() && document->frame()->shouldApplyTextZoom())
 
5883
        zoomFactor *= document->frame()->textZoomFactor();
5836
5884
 
5837
5885
    float zoomedSize = specifiedSize * zoomFactor;
5838
5886
 
5894
5942
// factors for each keyword value.
5895
5943
static const float fontSizeFactors[totalKeywords] = { 0.60f, 0.75f, 0.89f, 1.0f, 1.2f, 1.5f, 2.0f, 3.0f };
5896
5944
 
5897
 
float CSSStyleSelector::fontSizeForKeyword(int keyword, bool quirksMode, bool fixed) const
 
5945
float CSSStyleSelector::fontSizeForKeyword(Document* document, int keyword, bool fixed)
5898
5946
{
5899
 
    Settings* settings = m_checker.m_document->settings();
 
5947
    Settings* settings = document->settings();
5900
5948
    if (!settings)
5901
5949
        return 1.0f;
5902
5950
 
 
5951
    bool quirksMode = document->inCompatMode();
5903
5952
    int mediumSize = fixed ? settings->defaultFixedFontSize() : settings->defaultFontSize();
5904
5953
    if (mediumSize >= fontSizeTableMin && mediumSize <= fontSizeTableMax) {
5905
5954
        // Look up the entry in the table.