Changeset 67102 in webkit
- Timestamp:
- Sep 9, 2010 11:55:13 AM (14 years ago)
- Location:
- trunk
- Files:
-
- 2 added
- 9 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/LayoutTests/ChangeLog
r67101 r67102 1 2010-09-09 Ryosuke Niwa <rniwa@webkit.org> 2 3 Reviewed by Darin Adler. 4 5 queryCommandValue('FontSize') returns pixel values instead of IE font numbers 6 https://bugs.webkit.org/show_bug.cgi?id=21033 7 8 Added a test to ensure queryCommandValue('fontSize') returns legacy font size 9 for both variable width and fixed width fonts. 10 11 * editing/execCommand/query-font-size-expected.txt: Added. 12 * editing/execCommand/query-font-size.html: Added. 13 * fast/serializer: Added. 14 1 15 2010-09-09 Tony Chang <tony@chromium.org> 2 16 -
trunk/WebCore/ChangeLog
r67100 r67102 1 2010-09-09 Ryosuke Niwa <rniwa@webkit.org> 2 3 Reviewed by Darin Adler. 4 5 QueryCommandValue('FontSize') returns pixel values instead of IE font numbers 6 https://bugs.webkit.org/show_bug.cgi?id=21033 7 8 Modified selectionStartCSSPropertyValue to return legacy font size instead of pixel size. 9 To implement the conversion between pixel font size and legacy font size, 10 added legacyFontSize to CSSStyleSelector with a helper static function findNearestLegacyFontSize. 11 12 Fixed a bug in selectionComputedStyle where it obtains the style of the previous editing position 13 even when the selection is a range. This change revealed a crash in executeToggleStyleInList, 14 which was also fixed. 15 16 Test: editing/execCommand/query-font-size.html 17 18 * css/CSSComputedStyleDeclaration.cpp: 19 (WebCore::CSSComputedStyleDeclaration::getFontSizeCSSValuePreferringKeyword): Corrected style. 20 (WebCore::CSSComputedStyleDeclaration::useFixedFontDefaultSize): Added. 21 * css/CSSComputedStyleDeclaration.h: 22 * css/CSSStyleSelector.cpp: 23 (WebCore::CSSStyleSelector::fontSizeForKeyword): Renamed fixed/monospace to shouldUseFixedDefaultSize. 24 (WebCore::findNearestLegacyFontSize): Added, a helper for legacyFontSize. 25 (WebCore::CSSStyleSelector::legacyFontSize): Added. 26 * css/CSSStyleSelector.h: 27 * editing/Editor.cpp: 28 (WebCore::Editor::selectionStartCSSPropertyValue): Added a conversion from pixel to legacy font size. 29 * editing/EditorCommand.cpp: 30 (WebCore::executeToggleStyleInList): Crash fix. 31 * page/Frame.cpp: 32 (WebCore::Frame::selectionComputedStyle): See above. 33 1 34 2010-09-09 Robert Hogan <robert@webkit.org> 2 35 -
trunk/WebCore/css/CSSComputedStyleDeclaration.cpp
r67032 r67102 572 572 PassRefPtr<CSSValue> CSSComputedStyleDeclaration::getFontSizeCSSValuePreferringKeyword() const 573 573 { 574 Node* node = m_node.get(); 575 if (!node) 574 if (!m_node) 576 575 return 0; 577 576 578 node->document()->updateLayoutIgnorePendingStylesheets();579 580 RefPtr<RenderStyle> style = node->computedStyle(m_pseudoElementSpecifier);577 m_node->document()->updateLayoutIgnorePendingStylesheets(); 578 579 RefPtr<RenderStyle> style = m_node->computedStyle(m_pseudoElementSpecifier); 581 580 if (!style) 582 581 return 0; … … 586 585 587 586 return CSSPrimitiveValue::create(style->fontDescription().computedPixelSize(), CSSPrimitiveValue::CSS_PX); 587 } 588 589 bool CSSComputedStyleDeclaration::useFixedFontDefaultSize() const 590 { 591 if (!m_node) 592 return false; 593 594 RefPtr<RenderStyle> style = m_node->computedStyle(m_pseudoElementSpecifier); 595 if (!style) 596 return false; 597 598 return style->fontDescription().useFixedDefaultSize(); 588 599 } 589 600 -
trunk/WebCore/css/CSSComputedStyleDeclaration.h
r63014 r67102 59 59 PassRefPtr<CSSValue> getPropertyCSSValue(int propertyID, EUpdateLayout) const; 60 60 PassRefPtr<CSSValue> getFontSizeCSSValuePreferringKeyword() const; 61 bool useFixedFontDefaultSize() const; 61 62 #if ENABLE(SVG) 62 63 PassRefPtr<CSSValue> getSVGPropertyCSSValue(int propertyID, EUpdateLayout) const; -
trunk/WebCore/css/CSSStyleSelector.cpp
r67032 r67102 6312 6312 static const float fontSizeFactors[totalKeywords] = { 0.60f, 0.75f, 0.89f, 1.0f, 1.2f, 1.5f, 2.0f, 3.0f }; 6313 6313 6314 float CSSStyleSelector::fontSizeForKeyword(Document* document, int keyword, bool fixed)6314 float CSSStyleSelector::fontSizeForKeyword(Document* document, int keyword, bool shouldUseFixedDefaultSize) 6315 6315 { 6316 6316 Settings* settings = document->settings(); … … 6319 6319 6320 6320 bool quirksMode = document->inQuirksMode(); 6321 int mediumSize = fixed? settings->defaultFixedFontSize() : settings->defaultFontSize();6321 int mediumSize = shouldUseFixedDefaultSize ? settings->defaultFixedFontSize() : settings->defaultFontSize(); 6322 6322 if (mediumSize >= fontSizeTableMin && mediumSize <= fontSizeTableMax) { 6323 6323 // Look up the entry in the table. … … 6330 6330 float minLogicalSize = max(settings->minimumLogicalFontSize(), 1); 6331 6331 return max(fontSizeFactors[keyword - CSSValueXxSmall]*mediumSize, minLogicalSize); 6332 } 6333 6334 template<typename T> 6335 static int findNearestLegacyFontSize(int pixelFontSize, const T* table, int multiplier) 6336 { 6337 // Ignore table[0] because xx-small does not correspond to any legacy font size. 6338 for (int i = 1; i < totalKeywords - 1; i++) { 6339 if (pixelFontSize * 2 < (table[i] + table[i + 1]) * multiplier) 6340 return i; 6341 } 6342 return totalKeywords - 1; 6343 } 6344 6345 int CSSStyleSelector::legacyFontSize(Document* document, int pixelFontSize, bool shouldUseFixedDefaultSize) 6346 { 6347 Settings* settings = document->settings(); 6348 if (!settings) 6349 return 1; 6350 6351 bool quirksMode = document->inQuirksMode(); 6352 int mediumSize = shouldUseFixedDefaultSize ? settings->defaultFixedFontSize() : settings->defaultFontSize(); 6353 if (mediumSize >= fontSizeTableMin && mediumSize <= fontSizeTableMax) { 6354 int row = mediumSize - fontSizeTableMin; 6355 return findNearestLegacyFontSize<int>(pixelFontSize, quirksMode ? quirksFontSizeTable[row] : strictFontSizeTable[row], 1); 6356 } 6357 6358 return findNearestLegacyFontSize<float>(pixelFontSize, fontSizeFactors, mediumSize); 6332 6359 } 6333 6360 -
trunk/WebCore/css/CSSStyleSelector.h
r66339 r67102 123 123 PassRefPtr<CSSRuleList> pseudoStyleRulesForElement(Element*, PseudoId, bool authorOnly); 124 124 125 // Given a font size in pixel, this function will return legacy font size between 1 and 7. 126 static int legacyFontSize(Document*, int pixelFontSize, bool shouldUseFixedDefaultSize); 127 125 128 private: 126 129 // Given a CSS keyword in the range (xx-small to -webkit-xxx-large), this function will return 127 130 // the correct font size scaled relative to the user's default (medium). 128 static float fontSizeForKeyword(Document*, int keyword, bool monospace);131 static float fontSizeForKeyword(Document*, int keyword, bool shouldUseFixedDefaultSize); 129 132 130 133 // When the CSS keyword "larger" is used, this function will attempt to match within the keyword -
trunk/WebCore/editing/Editor.cpp
r67049 r67102 34 34 #include "CSSProperty.h" 35 35 #include "CSSPropertyNames.h" 36 #include "CSSStyleSelector.h" 36 37 #include "CSSValueKeywords.h" 37 38 #include "CharacterNames.h" … … 939 940 { 940 941 Node* nodeToRemove; 941 RefPtr<CSS StyleDeclaration> selectionStyle = m_frame->selectionComputedStyle(nodeToRemove);942 RefPtr<CSSComputedStyleDeclaration> selectionStyle = m_frame->selectionComputedStyle(nodeToRemove); 942 943 if (!selectionStyle) 943 944 return String(); … … 964 965 } 965 966 } 967 } 968 969 if (propertyID == CSSPropertyFontSize) { 970 RefPtr<CSSValue> value = selectionStyle->getPropertyCSSValue(CSSPropertyFontSize); 971 ASSERT(value->isPrimitiveValue()); 972 int fontPixelSize = static_cast<CSSPrimitiveValue*>(value.get())->getIntValue(CSSPrimitiveValue::CSS_PX); 973 int size = CSSStyleSelector::legacyFontSize(m_frame->document(), fontPixelSize, selectionStyle->useFixedFontDefaultSize()); 974 return String::number(size); 966 975 } 967 976 -
trunk/WebCore/editing/EditorCommand.cpp
r66643 r67102 134 134 Node* nodeToRemove = 0; 135 135 RefPtr<CSSComputedStyleDeclaration> selectionStyle = frame->selectionComputedStyle(nodeToRemove); 136 if (!selectionStyle) 137 return false; 138 136 139 RefPtr<CSSValue> selectedCSSValue = selectionStyle->getPropertyCSSValue(propertyID); 137 140 String newStyle = "none"; -
trunk/WebCore/page/Frame.cpp
r66963 r67102 746 746 Position pos = range->editingStartPosition(); 747 747 748 // If the pos is at the end of a text node, then this node is not fully selected. 749 // Move it to the next deep equivalent position to avoid removing the style from this node. 750 // e.g. if pos was at Position("hello", 5) in <b>hello<div>world</div></b>, we want Position("world", 0) instead. 751 // We only do this for range because caret at Position("hello", 5) in <b>hello</b>world should give you font-weight: bold. 752 Node* posNode = pos.containerNode(); 753 if (selection()->isRange() && posNode && posNode->isTextNode() && pos.computeOffsetInContainerNode() == posNode->maxCharacterOffset()) 754 pos = nextVisuallyDistinctCandidate(pos); 755 748 756 Element *elem = pos.element(); 749 757 if (!elem)
Note: See TracChangeset
for help on using the changeset viewer.