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

Side by Side Diff: third_party/WebKit/Source/core/editing/EditingStyle.cpp

Issue 1986563002: Apply vertical-align style of <sub> and <sup> to child elements. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Update the test case Created 4 years, 7 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
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2007, 2008, 2009 Apple Computer, Inc. 2 * Copyright (C) 2007, 2008, 2009 Apple Computer, Inc.
3 * Copyright (C) 2010, 2011 Google Inc. All rights reserved. 3 * Copyright (C) 2010, 2011 Google Inc. All rights reserved.
4 * 4 *
5 * Redistribution and use in source and binary forms, with or without 5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions 6 * modification, are permitted provided that the following conditions
7 * are met: 7 * are met:
8 * 1. Redistributions of source code must retain the above copyright 8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer. 9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright 10 * 2. Redistributions in binary form must reproduce the above copyright
(...skipping 12 matching lines...) Expand all
23 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 23 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
24 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 24 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
25 */ 25 */
26 26
27 #include "core/editing/EditingStyle.h" 27 #include "core/editing/EditingStyle.h"
28 28
29 #include "bindings/core/v8/ExceptionStatePlaceholder.h" 29 #include "bindings/core/v8/ExceptionStatePlaceholder.h"
30 #include "core/HTMLNames.h" 30 #include "core/HTMLNames.h"
31 #include "core/css/CSSColorValue.h" 31 #include "core/css/CSSColorValue.h"
32 #include "core/css/CSSComputedStyleDeclaration.h" 32 #include "core/css/CSSComputedStyleDeclaration.h"
33 #include "core/css/CSSPrimitiveValueMappings.h"
33 #include "core/css/CSSPropertyMetadata.h" 34 #include "core/css/CSSPropertyMetadata.h"
34 #include "core/css/CSSRuleList.h" 35 #include "core/css/CSSRuleList.h"
35 #include "core/css/CSSStyleRule.h" 36 #include "core/css/CSSStyleRule.h"
36 #include "core/css/CSSValueList.h" 37 #include "core/css/CSSValueList.h"
37 #include "core/css/CSSValuePool.h" 38 #include "core/css/CSSValuePool.h"
38 #include "core/css/FontSize.h" 39 #include "core/css/FontSize.h"
39 #include "core/css/StylePropertySet.h" 40 #include "core/css/StylePropertySet.h"
40 #include "core/css/StyleRule.h" 41 #include "core/css/StyleRule.h"
41 #include "core/css/parser/CSSParser.h" 42 #include "core/css/parser/CSSParser.h"
42 #include "core/css/resolver/StyleResolver.h" 43 #include "core/css/resolver/StyleResolver.h"
43 #include "core/dom/Document.h" 44 #include "core/dom/Document.h"
44 #include "core/dom/Element.h" 45 #include "core/dom/Element.h"
45 #include "core/dom/Node.h" 46 #include "core/dom/Node.h"
47 #include "core/dom/NodeComputedStyle.h"
46 #include "core/dom/NodeTraversal.h" 48 #include "core/dom/NodeTraversal.h"
47 #include "core/dom/QualifiedName.h" 49 #include "core/dom/QualifiedName.h"
48 #include "core/editing/EditingUtilities.h" 50 #include "core/editing/EditingUtilities.h"
49 #include "core/editing/Editor.h" 51 #include "core/editing/Editor.h"
50 #include "core/editing/FrameSelection.h" 52 #include "core/editing/FrameSelection.h"
51 #include "core/editing/Position.h" 53 #include "core/editing/Position.h"
52 #include "core/editing/commands/ApplyStyleCommand.h" 54 #include "core/editing/commands/ApplyStyleCommand.h"
53 #include "core/editing/serializers/HTMLInterchange.h" 55 #include "core/editing/serializers/HTMLInterchange.h"
54 #include "core/frame/LocalFrame.h" 56 #include "core/frame/LocalFrame.h"
55 #include "core/html/HTMLFontElement.h" 57 #include "core/html/HTMLFontElement.h"
(...skipping 292 matching lines...) Expand 10 before | Expand all | Expand 10 after
348 if (!HTMLFontElement::cssValueFromFontSizeNumber(value, size)) 350 if (!HTMLFontElement::cssValueFromFontSizeNumber(value, size))
349 return nullptr; 351 return nullptr;
350 return CSSPrimitiveValue::createIdentifier(size); 352 return CSSPrimitiveValue::createIdentifier(size);
351 } 353 }
352 354
353 float EditingStyle::NoFontDelta = 0.0f; 355 float EditingStyle::NoFontDelta = 0.0f;
354 356
355 EditingStyle::EditingStyle() 357 EditingStyle::EditingStyle()
356 : m_isMonospaceFont(false) 358 : m_isMonospaceFont(false)
357 , m_fontSizeDelta(NoFontDelta) 359 , m_fontSizeDelta(NoFontDelta)
360 , m_isVerticalAlign(false)
358 { 361 {
359 } 362 }
360 363
361 EditingStyle::EditingStyle(ContainerNode* node, PropertiesToInclude propertiesTo Include) 364 EditingStyle::EditingStyle(ContainerNode* node, PropertiesToInclude propertiesTo Include)
362 : m_isMonospaceFont(false) 365 : m_isMonospaceFont(false)
363 , m_fontSizeDelta(NoFontDelta) 366 , m_fontSizeDelta(NoFontDelta)
367 , m_isVerticalAlign(false)
364 { 368 {
365 init(node, propertiesToInclude); 369 init(node, propertiesToInclude);
366 } 370 }
367 371
368 EditingStyle::EditingStyle(const Position& position, PropertiesToInclude propert iesToInclude) 372 EditingStyle::EditingStyle(const Position& position, PropertiesToInclude propert iesToInclude)
369 : m_isMonospaceFont(false) 373 : m_isMonospaceFont(false)
370 , m_fontSizeDelta(NoFontDelta) 374 , m_fontSizeDelta(NoFontDelta)
375 , m_isVerticalAlign(false)
371 { 376 {
372 init(position.anchorNode(), propertiesToInclude); 377 init(position.anchorNode(), propertiesToInclude);
373 } 378 }
374 379
375 EditingStyle::EditingStyle(const StylePropertySet* style) 380 EditingStyle::EditingStyle(const StylePropertySet* style)
376 : m_mutableStyle(style ? style->mutableCopy() : nullptr) 381 : m_mutableStyle(style ? style->mutableCopy() : nullptr)
377 , m_isMonospaceFont(false) 382 , m_isMonospaceFont(false)
378 , m_fontSizeDelta(NoFontDelta) 383 , m_fontSizeDelta(NoFontDelta)
384 , m_isVerticalAlign(false)
379 { 385 {
380 extractFontSizeDelta(); 386 extractFontSizeDelta();
381 } 387 }
382 388
383 EditingStyle::EditingStyle(CSSPropertyID propertyID, const String& value) 389 EditingStyle::EditingStyle(CSSPropertyID propertyID, const String& value)
384 : m_mutableStyle(nullptr) 390 : m_mutableStyle(nullptr)
385 , m_isMonospaceFont(false) 391 , m_isMonospaceFont(false)
386 , m_fontSizeDelta(NoFontDelta) 392 , m_fontSizeDelta(NoFontDelta)
393 , m_isVerticalAlign(false)
387 { 394 {
388 setProperty(propertyID, value); 395 setProperty(propertyID, value);
396 if (propertyID == CSSPropertyVerticalAlign) {
yosin_UTC9 2016/05/17 01:15:48 nit: Can we simplify this? m_isVerticalAlign = pr
joone 2016/05/17 23:01:33 Done.
397 if (value == "sub" || value == "super")
398 m_isVerticalAlign = true;
399 }
389 } 400 }
390 401
391 static Color cssValueToColor(CSSValue* colorValue) 402 static Color cssValueToColor(CSSValue* colorValue)
392 { 403 {
393 if (!colorValue || (!colorValue->isColorValue() && !colorValue->isPrimitiveV alue())) 404 if (!colorValue || (!colorValue->isColorValue() && !colorValue->isPrimitiveV alue()))
394 return Color::transparent; 405 return Color::transparent;
395 406
396 if (colorValue->isColorValue()) 407 if (colorValue->isColorValue())
397 return toCSSColorValue(colorValue)->value(); 408 return toCSSColorValue(colorValue)->value();
398 409
(...skipping 331 matching lines...) Expand 10 before | Expand all | Expand 10 after
730 difference->removePropertiesInSet(textOnlyProperties, WTF_ARRAY_LENGTH(t extOnlyProperties)); 741 difference->removePropertiesInSet(textOnlyProperties, WTF_ARRAY_LENGTH(t extOnlyProperties));
731 742
732 if (difference->isEmpty()) 743 if (difference->isEmpty())
733 return TrueTriState; 744 return TrueTriState;
734 if (difference->propertyCount() == m_mutableStyle->propertyCount()) 745 if (difference->propertyCount() == m_mutableStyle->propertyCount())
735 return FalseTriState; 746 return FalseTriState;
736 747
737 return MixedTriState; 748 return MixedTriState;
738 } 749 }
739 750
751 static void applyAncestorVerticalAlignStyle(StylePropertySet* stylePropertyToApp ly, Node* node)
752 {
753 for (Node* ancestor = node; ancestor; ancestor = ancestor->parentNode()) {
yosin_UTC9 2016/05/17 01:15:48 nit: Please use range-for for (Node* runner : Nod
joone 2016/05/17 23:01:33 Done.
754 CSSComputedStyleDeclaration* ancestorStyle = CSSComputedStyleDeclaration ::create(ancestor);
755 CSSPrimitiveValue* verticalAlign = toCSSPrimitiveValue(stylePropertyToAp ply->getPropertyCSSValue(CSSPropertyVerticalAlign));
756 if (getIdentifierValue(ancestorStyle, CSSPropertyVerticalAlign) == verti calAlign->getValueID()) {
757 node->mutableComputedStyle()->setVerticalAlign(verticalAlign->conver tTo<EVerticalAlign>());
758 break;
759 }
760 }
761 }
762
740 TriState EditingStyle::triStateOfStyle(const VisibleSelection& selection) const 763 TriState EditingStyle::triStateOfStyle(const VisibleSelection& selection) const
741 { 764 {
742 if (!selection.isCaretOrRange()) 765 if (!selection.isCaretOrRange())
743 return FalseTriState; 766 return FalseTriState;
744 767
745 if (selection.isCaret()) 768 if (selection.isCaret())
746 return triStateOfStyle(EditingStyle::styleAtSelectionStart(selection)); 769 return triStateOfStyle(EditingStyle::styleAtSelectionStart(selection));
747 770
748 TriState state = FalseTriState; 771 TriState state = FalseTriState;
749 bool nodeIsStart = true; 772 bool nodeIsStart = true;
750 for (Node& node : NodeTraversal::startsAt(selection.start().anchorNode())) { 773 for (Node& node : NodeTraversal::startsAt(selection.start().anchorNode())) {
751 if (node.layoutObject() && node.hasEditableStyle()) { 774 if (node.layoutObject() && node.hasEditableStyle()) {
752 CSSComputedStyleDeclaration* nodeStyle = CSSComputedStyleDeclaration ::create(&node); 775 CSSComputedStyleDeclaration* nodeStyle = CSSComputedStyleDeclaration ::create(&node);
753 if (nodeStyle) { 776 if (nodeStyle) {
777 // If the selected element has <sub> or <sup> ancestor element, apply the corrsponding
778 // style(vertical-align) to it so that document.queryCommandStat e() works with the sytle.
779 // See bug http://crbug.com/582225.
780 if (m_isVerticalAlign && getIdentifierValue(nodeStyle, CSSProper tyVerticalAlign) == CSSValueBaseline)
781 applyAncestorVerticalAlignStyle(m_mutableStyle, &node);
782
754 // Pass EditingStyle::DoNotIgnoreTextOnlyProperties without chec king if node.isTextNode() 783 // Pass EditingStyle::DoNotIgnoreTextOnlyProperties without chec king if node.isTextNode()
755 // because the node can be an element node. See bug http://crbug .com/584939. 784 // because the node can be an element node. See bug http://crbug .com/584939.
756 TriState nodeState = triStateOfStyle(nodeStyle, EditingStyle::Do NotIgnoreTextOnlyProperties); 785 TriState nodeState = triStateOfStyle(nodeStyle, EditingStyle::Do NotIgnoreTextOnlyProperties);
757 if (nodeIsStart) { 786 if (nodeIsStart) {
758 state = nodeState; 787 state = nodeState;
759 nodeIsStart = false; 788 nodeIsStart = false;
760 } else if (state != nodeState && node.isTextNode()) { 789 } else if (state != nodeState && node.isTextNode()) {
761 state = MixedTriState; 790 state = MixedTriState;
762 break; 791 break;
763 } 792 }
(...skipping 966 matching lines...) Expand 10 before | Expand all | Expand 10 after
1730 { 1759 {
1731 for (Node* ancestor = node; ancestor; ancestor = ancestor->parentNode()) { 1760 for (Node* ancestor = node; ancestor; ancestor = ancestor->parentNode()) {
1732 CSSComputedStyleDeclaration* ancestorStyle = CSSComputedStyleDeclaration ::create(ancestor); 1761 CSSComputedStyleDeclaration* ancestorStyle = CSSComputedStyleDeclaration ::create(ancestor);
1733 if (!hasTransparentBackgroundColor(ancestorStyle)) 1762 if (!hasTransparentBackgroundColor(ancestorStyle))
1734 return ancestorStyle->getPropertyCSSValue(CSSPropertyBackgroundColor ); 1763 return ancestorStyle->getPropertyCSSValue(CSSPropertyBackgroundColor );
1735 } 1764 }
1736 return nullptr; 1765 return nullptr;
1737 } 1766 }
1738 1767
1739 } // namespace blink 1768 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698