Index: third_party/WebKit/Source/core/editing/EditingStyle.cpp |
diff --git a/third_party/WebKit/Source/core/editing/EditingStyle.cpp b/third_party/WebKit/Source/core/editing/EditingStyle.cpp |
index 3f7fd86fc1223ddbe7fbc11cc4ec8dbf2d54d00b..4770800ef79acca50d30dea6d49e59f4cb38ad71 100644 |
--- a/third_party/WebKit/Source/core/editing/EditingStyle.cpp |
+++ b/third_party/WebKit/Source/core/editing/EditingStyle.cpp |
@@ -30,6 +30,7 @@ |
#include "core/HTMLNames.h" |
#include "core/css/CSSColorValue.h" |
#include "core/css/CSSComputedStyleDeclaration.h" |
+#include "core/css/CSSPrimitiveValueMappings.h" |
#include "core/css/CSSPropertyMetadata.h" |
#include "core/css/CSSRuleList.h" |
#include "core/css/CSSStyleRule.h" |
@@ -43,6 +44,7 @@ |
#include "core/dom/Document.h" |
#include "core/dom/Element.h" |
#include "core/dom/Node.h" |
+#include "core/dom/NodeComputedStyle.h" |
#include "core/dom/NodeTraversal.h" |
#include "core/dom/QualifiedName.h" |
#include "core/editing/EditingUtilities.h" |
@@ -355,12 +357,14 @@ float EditingStyle::NoFontDelta = 0.0f; |
EditingStyle::EditingStyle() |
: m_isMonospaceFont(false) |
, m_fontSizeDelta(NoFontDelta) |
+ , m_isVerticalAlign(false) |
{ |
} |
EditingStyle::EditingStyle(ContainerNode* node, PropertiesToInclude propertiesToInclude) |
: m_isMonospaceFont(false) |
, m_fontSizeDelta(NoFontDelta) |
+ , m_isVerticalAlign(false) |
{ |
init(node, propertiesToInclude); |
} |
@@ -368,6 +372,7 @@ EditingStyle::EditingStyle(ContainerNode* node, PropertiesToInclude propertiesTo |
EditingStyle::EditingStyle(const Position& position, PropertiesToInclude propertiesToInclude) |
: m_isMonospaceFont(false) |
, m_fontSizeDelta(NoFontDelta) |
+ , m_isVerticalAlign(false) |
{ |
init(position.anchorNode(), propertiesToInclude); |
} |
@@ -376,6 +381,7 @@ EditingStyle::EditingStyle(const StylePropertySet* style) |
: m_mutableStyle(style ? style->mutableCopy() : nullptr) |
, m_isMonospaceFont(false) |
, m_fontSizeDelta(NoFontDelta) |
+ , m_isVerticalAlign(false) |
{ |
extractFontSizeDelta(); |
} |
@@ -384,8 +390,13 @@ EditingStyle::EditingStyle(CSSPropertyID propertyID, const String& value) |
: m_mutableStyle(nullptr) |
, m_isMonospaceFont(false) |
, m_fontSizeDelta(NoFontDelta) |
+ , m_isVerticalAlign(false) |
{ |
setProperty(propertyID, value); |
+ 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.
|
+ if (value == "sub" || value == "super") |
+ m_isVerticalAlign = true; |
+ } |
} |
static Color cssValueToColor(CSSValue* colorValue) |
@@ -737,6 +748,18 @@ TriState EditingStyle::triStateOfStyle(CSSStyleDeclaration* styleToCompare, Shou |
return MixedTriState; |
} |
+static void applyAncestorVerticalAlignStyle(StylePropertySet* stylePropertyToApply, Node* node) |
+{ |
+ 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.
|
+ CSSComputedStyleDeclaration* ancestorStyle = CSSComputedStyleDeclaration::create(ancestor); |
+ CSSPrimitiveValue* verticalAlign = toCSSPrimitiveValue(stylePropertyToApply->getPropertyCSSValue(CSSPropertyVerticalAlign)); |
+ if (getIdentifierValue(ancestorStyle, CSSPropertyVerticalAlign) == verticalAlign->getValueID()) { |
+ node->mutableComputedStyle()->setVerticalAlign(verticalAlign->convertTo<EVerticalAlign>()); |
+ break; |
+ } |
+ } |
+} |
+ |
TriState EditingStyle::triStateOfStyle(const VisibleSelection& selection) const |
{ |
if (!selection.isCaretOrRange()) |
@@ -751,6 +774,12 @@ TriState EditingStyle::triStateOfStyle(const VisibleSelection& selection) const |
if (node.layoutObject() && node.hasEditableStyle()) { |
CSSComputedStyleDeclaration* nodeStyle = CSSComputedStyleDeclaration::create(&node); |
if (nodeStyle) { |
+ // If the selected element has <sub> or <sup> ancestor element, apply the corrsponding |
+ // style(vertical-align) to it so that document.queryCommandState() works with the sytle. |
+ // See bug http://crbug.com/582225. |
+ if (m_isVerticalAlign && getIdentifierValue(nodeStyle, CSSPropertyVerticalAlign) == CSSValueBaseline) |
+ applyAncestorVerticalAlignStyle(m_mutableStyle, &node); |
+ |
// Pass EditingStyle::DoNotIgnoreTextOnlyProperties without checking if node.isTextNode() |
// because the node can be an element node. See bug http://crbug.com/584939. |
TriState nodeState = triStateOfStyle(nodeStyle, EditingStyle::DoNotIgnoreTextOnlyProperties); |