Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(198)

Side by Side Diff: third_party/WebKit/WebCore/css/CSSStyleSelector.cpp

Issue 56198: Roll out dominantScript, getGenericFontForScript patches to unfork a bunch of... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 11 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | third_party/WebKit/WebCore/dom/Document.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright (C) 1999 Lars Knoll (knoll@kde.org) 2 * Copyright (C) 1999 Lars Knoll (knoll@kde.org)
3 * (C) 2004-2005 Allan Sandfeld Jensen (kde@carewolf.com) 3 * (C) 2004-2005 Allan Sandfeld Jensen (kde@carewolf.com)
4 * Copyright (C) 2006, 2007 Nicholas Shanks (webkit@nickshanks.com) 4 * Copyright (C) 2006, 2007 Nicholas Shanks (webkit@nickshanks.com)
5 * Copyright (C) 2005, 2006, 2007, 2008 Apple Inc. All rights reserved. 5 * Copyright (C) 2005, 2006, 2007, 2008 Apple Inc. All rights reserved.
6 * Copyright (C) 2007 Alexey Proskuryakov <ap@webkit.org> 6 * Copyright (C) 2007 Alexey Proskuryakov <ap@webkit.org>
7 * Copyright (C) 2007, 2008 Eric Seidel <eric@webkit.org> 7 * Copyright (C) 2007, 2008 Eric Seidel <eric@webkit.org>
8 * Copyright (C) 2008, 2009 Torch Mobile Inc. All rights reserved. (http://www.t orchmobile.com/) 8 * Copyright (C) 2008, 2009 Torch Mobile Inc. All rights reserved. (http://www.t orchmobile.com/)
9 * 9 *
10 * This library is free software; you can redistribute it and/or 10 * This library is free software; you can redistribute it and/or
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
45 #include "CSSStyleSheet.h" 45 #include "CSSStyleSheet.h"
46 #include "CSSTimingFunctionValue.h" 46 #include "CSSTimingFunctionValue.h"
47 #include "CSSValueList.h" 47 #include "CSSValueList.h"
48 #include "CSSVariableDependentValue.h" 48 #include "CSSVariableDependentValue.h"
49 #include "CSSVariablesDeclaration.h" 49 #include "CSSVariablesDeclaration.h"
50 #include "CSSVariablesRule.h" 50 #include "CSSVariablesRule.h"
51 #include "CachedImage.h" 51 #include "CachedImage.h"
52 #include "Counter.h" 52 #include "Counter.h"
53 #include "CounterContent.h" 53 #include "CounterContent.h"
54 #include "FocusController.h" 54 #include "FocusController.h"
55 #include "FontCache.h"
56 #include "FontFamilyValue.h" 55 #include "FontFamilyValue.h"
57 #include "FontValue.h" 56 #include "FontValue.h"
58 #include "Frame.h" 57 #include "Frame.h"
59 #include "FrameView.h" 58 #include "FrameView.h"
60 #include "HTMLDocument.h" 59 #include "HTMLDocument.h"
61 #include "HTMLElement.h" 60 #include "HTMLElement.h"
62 #include "HTMLInputElement.h" 61 #include "HTMLInputElement.h"
63 #include "HTMLNames.h" 62 #include "HTMLNames.h"
64 #include "HTMLTextAreaElement.h" 63 #include "HTMLTextAreaElement.h"
65 #include "LinkHash.h" 64 #include "LinkHash.h"
(...skipping 2742 matching lines...) Expand 10 before | Expand all | Expand 10 after
2808 if (directives.m_increment) 2807 if (directives.m_increment)
2809 directives.m_incrementValue += value; 2808 directives.m_incrementValue += value;
2810 else { 2809 else {
2811 directives.m_increment = true; 2810 directives.m_increment = true;
2812 directives.m_incrementValue = value; 2811 directives.m_incrementValue = value;
2813 } 2812 }
2814 } 2813 }
2815 } 2814 }
2816 } 2815 }
2817 2816
2818 struct ScriptFamilyState {
2819 bool isGenericAdded;
2820 bool isPerScriptGenericChecked;
2821 ScriptFamilyState() : isGenericAdded(false), isPerScriptGenericChecked(false)
2822 {}
2823 };
2824
2825 inline static void handleScriptFamily(const char* webkitFamily, UScriptCode scri pt,
2826 FontDescription::GenericFamilyType generic ,
2827 AtomicString& face, ScriptFamilyState& sta te, FontDescription& fontDescription,
2828 int& familyIndex)
2829 {
2830 if (!state.isGenericAdded) {
2831 face = webkitFamily;
2832 state.isGenericAdded = true;
2833 fontDescription.setGenericFamily(generic);
2834 // go through this once more to add per-script generic family.
2835 --familyIndex;
2836 } else if (!state.isPerScriptGenericChecked) {
2837 face = FontCache::getGenericFontForScript(script, fontDescription);
2838 state.isPerScriptGenericChecked = true;
2839 }
2840 }
2841
2842 void CSSStyleSelector::applyPropertyToStyle(int id, CSSValue *value, RenderStyle * style) 2817 void CSSStyleSelector::applyPropertyToStyle(int id, CSSValue *value, RenderStyle * style)
2843 { 2818 {
2844 initElementAndPseudoState(0); 2819 initElementAndPseudoState(0);
2845 initForStyleResolve(0, style); 2820 initForStyleResolve(0, style);
2846 m_style = style; 2821 m_style = style;
2847 applyProperty(id, value); 2822 applyProperty(id, value);
2848 } 2823 }
2849 2824
2850 void CSSStyleSelector::applyProperty(int id, CSSValue *value) 2825 void CSSStyleSelector::applyProperty(int id, CSSValue *value)
2851 { 2826 {
(...skipping 1252 matching lines...) Expand 10 before | Expand all | Expand 10 after
4104 FontDescription fontDescription = m_style->fontDescription(); 4079 FontDescription fontDescription = m_style->fontDescription();
4105 CSSValueList *list = static_cast<CSSValueList*>(value); 4080 CSSValueList *list = static_cast<CSSValueList*>(value);
4106 int len = list->length(); 4081 int len = list->length();
4107 FontFamily& firstFamily = fontDescription.firstFamily(); 4082 FontFamily& firstFamily = fontDescription.firstFamily();
4108 FontFamily *currFamily = 0; 4083 FontFamily *currFamily = 0;
4109 4084
4110 // Before mapping in a new font-family property, we should reset the gen eric family. 4085 // Before mapping in a new font-family property, we should reset the gen eric family.
4111 bool oldFamilyIsMonospace = fontDescription.genericFamily() == FontDescr iption::MonospaceFamily; 4086 bool oldFamilyIsMonospace = fontDescription.genericFamily() == FontDescr iption::MonospaceFamily;
4112 fontDescription.setGenericFamily(FontDescription::NoFamily); 4087 fontDescription.setGenericFamily(FontDescription::NoFamily);
4113 4088
4114 // |script| is used to add a font per script and per CSS generic family.
4115 // Adding it here is not very efficient because we may never use it
4116 // if all the characters are covered by fonts specified for this element .
4117 // TODO(jungshik): Currently, it's document-wide constant inferred from
4118 // the document charset, but we should infer it from the value of
4119 // xml:lang or lang for |m_element|.
4120 UScriptCode script = m_checker.m_document->dominantScript();
4121 // serif, sans-serif, cursive, fantasy, monospace
4122 ScriptFamilyState scriptFamilyStates[5];
4123 Settings* settings = m_checker.m_document->settings();
4124 for (int i = 0; i < len; i++) { 4089 for (int i = 0; i < len; i++) {
4125 CSSValue *item = list->itemWithoutBoundsCheck(i); 4090 CSSValue *item = list->itemWithoutBoundsCheck(i);
4126 if (!item->isPrimitiveValue()) continue; 4091 if (!item->isPrimitiveValue()) continue;
4127 CSSPrimitiveValue *val = static_cast<CSSPrimitiveValue*>(item); 4092 CSSPrimitiveValue *val = static_cast<CSSPrimitiveValue*>(item);
4128 AtomicString face; 4093 AtomicString face;
4094 Settings* settings = m_checker.m_document->settings();
4129 if (val->primitiveType() == CSSPrimitiveValue::CSS_STRING) 4095 if (val->primitiveType() == CSSPrimitiveValue::CSS_STRING)
4130 face = static_cast<FontFamilyValue*>(val)->familyName(); 4096 face = static_cast<FontFamilyValue*>(val)->familyName();
4131 else if (val->primitiveType() == CSSPrimitiveValue::CSS_IDENT && set tings) { 4097 else if (val->primitiveType() == CSSPrimitiveValue::CSS_IDENT && set tings) {
4132 switch (val->getIdent()) { 4098 switch (val->getIdent()) {
4133 case CSSValueWebkitBody: 4099 case CSSValueWebkitBody:
4134 face = settings->standardFontFamily(); 4100 face = settings->standardFontFamily();
4135 break; 4101 break;
4136 // For each of 5 CSS generic families,
4137 // we add '-webkit-FOO' and a per-script generic family.
4138 // When |Settings| becomes expressive enough to support
4139 // per-script&per-generic family and we have a UI for
4140 // that, we'd just add the latter. Even without that,
4141 // I'm tempted to add per-script generic first, but I can't.
4142 // If I did, our font-selection UI would be all but
4143 // non-functional. Another issue is that we're adding
4144 // these fonts without regard for actual need in page
4145 // rendering. That is, it's not done in a lazy manner.
4146 // Somewhere in getGlyphDataForCharacter() could be
4147 // a better place in terms of performance.
4148 // See https://bugs.webkit.org/show_bug.cgi?id=18085
4149 // and http://bugs.webkit.org/show_bug.cgi?id=10874
4150 case CSSValueSerif: 4102 case CSSValueSerif:
4151 handleScriptFamily("-webkit-serif", script, 4103 face = "-webkit-serif";
4152 FontDescription::SerifFamily, face, 4104 fontDescription.setGenericFamily(FontDescription::SerifF amily);
4153 scriptFamilyStates[0], fontDescription, i);
4154 break; 4105 break;
4155 case CSSValueSansSerif: 4106 case CSSValueSansSerif:
4156 handleScriptFamily("-webkit-sans-serif", script, 4107 face = "-webkit-sans-serif";
4157 FontDescription::SansSerifFamily, face, 4108 fontDescription.setGenericFamily(FontDescription::SansSe rifFamily);
4158 scriptFamilyStates[1], fontDescription, i);
4159 break; 4109 break;
4160 case CSSValueCursive: 4110 case CSSValueCursive:
4161 handleScriptFamily("-webkit-cursive", script, 4111 face = "-webkit-cursive";
4162 FontDescription::CursiveFamily, face, 4112 fontDescription.setGenericFamily(FontDescription::Cursiv eFamily);
4163 scriptFamilyStates[2], fontDescription, i);
4164 break; 4113 break;
4165 case CSSValueFantasy: 4114 case CSSValueFantasy:
4166 handleScriptFamily("-webkit-fantasy", script, 4115 face = "-webkit-fantasy";
4167 FontDescription::FantasyFamily, face, 4116 fontDescription.setGenericFamily(FontDescription::Fantas yFamily);
4168 scriptFamilyStates[3], fontDescription, i);
4169 break; 4117 break;
4170 case CSSValueMonospace: 4118 case CSSValueMonospace:
4171 handleScriptFamily("-webkit-monospace", script, 4119 face = "-webkit-monospace";
4172 FontDescription::MonospaceFamily, face, 4120 fontDescription.setGenericFamily(FontDescription::Monosp aceFamily);
4173 scriptFamilyStates[4], fontDescription, i);
4174 break; 4121 break;
4175 } 4122 }
4176 } 4123 }
4177 4124
4178 if (!face.isEmpty()) { 4125 if (!face.isEmpty()) {
4179 if (!currFamily) { 4126 if (!currFamily) {
4180 // Filling in the first family. 4127 // Filling in the first family.
4181 firstFamily.setFamily(face); 4128 firstFamily.setFamily(face);
4182 currFamily = &firstFamily; 4129 currFamily = &firstFamily;
4183 } 4130 }
4184 else { 4131 else {
4185 RefPtr<SharedFontFamily> newFamily = SharedFontFamily::creat e(); 4132 RefPtr<SharedFontFamily> newFamily = SharedFontFamily::creat e();
4186 newFamily->setFamily(face); 4133 newFamily->setFamily(face);
4187 currFamily->appendFamily(newFamily); 4134 currFamily->appendFamily(newFamily);
4188 currFamily = newFamily.get(); 4135 currFamily = newFamily.get();
4189 } 4136 }
4190 4137
4191 if (fontDescription.keywordSize() && (fontDescription.genericFam ily() == FontDescription::MonospaceFamily) != oldFamilyIsMonospace) 4138 if (fontDescription.keywordSize() && (fontDescription.genericFam ily() == FontDescription::MonospaceFamily) != oldFamilyIsMonospace)
4192 setFontSize(fontDescription, fontSizeForKeyword(CSSValueXxSm all + fontDescription.keywordSize() - 1, m_style->htmlHacks(), !oldFamilyIsMonos pace)); 4139 setFontSize(fontDescription, fontSizeForKeyword(CSSValueXxSm all + fontDescription.keywordSize() - 1, m_style->htmlHacks(), !oldFamilyIsMonos pace));
4193 4140
4194 if (m_style->setFontDescription(fontDescription)) 4141 if (m_style->setFontDescription(fontDescription))
4195 m_fontDirty = true; 4142 m_fontDirty = true;
4196 } 4143 }
4197 } 4144 }
4198
4199 if (fontDescription.genericFamily() == FontDescription::NoFamily && curr Family) {
4200 FontDescription::GenericFamilyType generic;
4201 // TODO(jungshik) : Perhaps, we'd better add isStandardSerif()
4202 // method to |Settings| which will be set via WebPreference.
4203 if (settings) {
4204 if (settings->serifFontFamily() == settings->standardFontFamily( ))
4205 generic = FontDescription::SerifFamily ;
4206 else
4207 generic = FontDescription::SansSerifFamily;
4208 } else
4209 generic = FontDescription::StandardFamily;
4210 fontDescription.setGenericFamily(generic);
4211 AtomicString face = FontCache::getGenericFontForScript(script, fontD escription);
4212 if (!face.isEmpty()) {
4213 RefPtr<SharedFontFamily> newFamily = SharedFontFamily::create();
4214 newFamily->setFamily(face);
4215 currFamily->appendFamily(newFamily);
4216 currFamily = newFamily.get();
4217 if (m_style->setFontDescription(fontDescription))
4218 m_fontDirty = true;
4219 }
4220 }
4221 return; 4145 return;
4222 } 4146 }
4223 case CSSPropertyTextDecoration: { 4147 case CSSPropertyTextDecoration: {
4224 // list of ident 4148 // list of ident
4225 HANDLE_INHERIT_AND_INITIAL(textDecoration, TextDecoration) 4149 HANDLE_INHERIT_AND_INITIAL(textDecoration, TextDecoration)
4226 int t = RenderStyle::initialTextDecoration(); 4150 int t = RenderStyle::initialTextDecoration();
4227 if (primitiveValue && primitiveValue->getIdent() == CSSValueNone) { 4151 if (primitiveValue && primitiveValue->getIdent() == CSSValueNone) {
4228 // do nothing 4152 // do nothing
4229 } else { 4153 } else {
4230 if (!value->isValueList()) return; 4154 if (!value->isValueList()) return;
(...skipping 205 matching lines...) Expand 10 before | Expand all | Expand 10 after
4436 setFontSize(fontDescription, fontSizeForKeyword(CSSValueMedium, m_st yle->htmlHacks(), false)); 4360 setFontSize(fontDescription, fontSizeForKeyword(CSSValueMedium, m_st yle->htmlHacks(), false));
4437 m_style->setLineHeight(RenderStyle::initialLineHeight()); 4361 m_style->setLineHeight(RenderStyle::initialLineHeight());
4438 m_lineHeightValue = 0; 4362 m_lineHeightValue = 0;
4439 if (m_style->setFontDescription(fontDescription)) 4363 if (m_style->setFontDescription(fontDescription))
4440 m_fontDirty = true; 4364 m_fontDirty = true;
4441 } else if (primitiveValue) { 4365 } else if (primitiveValue) {
4442 m_style->setLineHeight(RenderStyle::initialLineHeight()); 4366 m_style->setLineHeight(RenderStyle::initialLineHeight());
4443 m_lineHeightValue = 0; 4367 m_lineHeightValue = 0;
4444 4368
4445 FontDescription fontDescription; 4369 FontDescription fontDescription;
4446 theme()->systemFont(primitiveValue->getIdent(), m_checker.m_document , fontDescription); 4370 theme()->systemFont(primitiveValue->getIdent(), fontDescription);
4447 4371
4448 // Double-check and see if the theme did anything. If not, don't bo ther updating the font. 4372 // Double-check and see if the theme did anything. If not, don't bo ther updating the font.
4449 if (fontDescription.isAbsoluteSize()) { 4373 if (fontDescription.isAbsoluteSize()) {
4450 // Make sure the rendering mode and printer font settings are up dated. 4374 // Make sure the rendering mode and printer font settings are up dated.
4451 Settings* settings = m_checker.m_document->settings(); 4375 Settings* settings = m_checker.m_document->settings();
4452 ASSERT(settings); // If we're doing style resolution, this docum ent should always be in a frame and thus have settings 4376 ASSERT(settings); // If we're doing style resolution, this docum ent should always be in a frame and thus have settings
4453 if (!settings) 4377 if (!settings)
4454 return; 4378 return;
4455 fontDescription.setRenderingMode(settings->fontRenderingMode()); 4379 fontDescription.setRenderingMode(settings->fontRenderingMode());
4456 fontDescription.setUsePrinterFont(m_checker.m_document->printing ()); 4380 fontDescription.setUsePrinterFont(m_checker.m_document->printing ());
(...skipping 1759 matching lines...) Expand 10 before | Expand all | Expand 10 after
6216 ASSERT_NOT_REACHED(); 6140 ASSERT_NOT_REACHED();
6217 break; 6141 break;
6218 } 6142 }
6219 } 6143 }
6220 } 6144 }
6221 outOperations = operations; 6145 outOperations = operations;
6222 return true; 6146 return true;
6223 } 6147 }
6224 6148
6225 } // namespace WebCore 6149 } // namespace WebCore
OLDNEW
« no previous file with comments | « no previous file | third_party/WebKit/WebCore/dom/Document.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698