Bug 1040668 part 15 - Make the default value of text-emphasis-position aware of the language. r=dbaron
authorXidorn Quan <quanxunzhen@gmail.com>
Sat, 28 Nov 2015 11:56:33 +1100
changeset 308697 9d967e504363d8b9962f578a23a3369ffb8c4090
parent 308696 06856fda5ac15c16c14115295fdbdd1fd8c14003
child 308698 2c2e3685fa13186a53a90c6f0cbb9bbaff6858dd
push id5513
push userraliiev@mozilla.com
push dateMon, 25 Jan 2016 13:55:34 +0000
treeherdermozilla-beta@5ee97dd05b5c [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersdbaron
bugs1040668
milestone45.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1040668 part 15 - Make the default value of text-emphasis-position aware of the language. r=dbaron
dom/html/nsGenericHTMLElement.cpp
layout/style/nsStyleConsts.h
layout/style/nsStyleStruct.cpp
--- a/dom/html/nsGenericHTMLElement.cpp
+++ b/dom/html/nsGenericHTMLElement.cpp
@@ -47,16 +47,17 @@
 #include "nsPresContext.h"
 #include "nsIDocShell.h"
 #include "nsNameSpaceManager.h"
 #include "nsError.h"
 #include "nsScriptLoader.h"
 #include "nsRuleData.h"
 #include "nsIPrincipal.h"
 #include "nsContainerFrame.h"
+#include "nsStyleUtil.h"
 
 #include "nsPresState.h"
 #include "nsILayoutHistoryState.h"
 
 #include "nsHTMLParts.h"
 #include "nsContentUtils.h"
 #include "mozilla/dom/DirectionalityUtils.h"
 #include "nsString.h"
@@ -1321,22 +1322,38 @@ nsGenericHTMLElement::MapCommonAttribute
         else if (value->Equals(nsGkAtoms::_false, eIgnoreCase)) {
             userModify->SetIntValue(NS_STYLE_USER_MODIFY_READ_ONLY,
                                     eCSSUnit_Enumerated);
         }
       }
     }
   }
 
-  if (aData->mSIDs & NS_STYLE_INHERIT_BIT(Font)) {
-    nsCSSValue* lang = aData->ValueForLang();
-    if (lang->GetUnit() == eCSSUnit_Null) {
-      const nsAttrValue* value = aAttributes->GetAttr(nsGkAtoms::lang);
-      if (value && value->Type() == nsAttrValue::eString) {
-        lang->SetStringValue(value->GetStringValue(), eCSSUnit_Ident);
+  const nsAttrValue* langValue = aAttributes->GetAttr(nsGkAtoms::lang);
+  if (langValue && langValue->Type() == nsAttrValue::eString) {
+    if (aData->mSIDs & NS_STYLE_INHERIT_BIT(Font)) {
+      nsCSSValue* lang = aData->ValueForLang();
+      if (lang->GetUnit() == eCSSUnit_Null) {
+        lang->SetStringValue(langValue->GetStringValue(), eCSSUnit_Ident);
+      }
+    }
+    if (aData->mSIDs & NS_STYLE_INHERIT_BIT(Text)) {
+      nsCSSValue* emphasisPos = aData->ValueForTextEmphasisPosition();
+      if (emphasisPos->GetUnit() == eCSSUnit_Null) {
+        const nsAString& lang = langValue->GetStringValue();
+        if (nsStyleUtil::MatchesLanguagePrefix(lang, MOZ_UTF16("zh"))) {
+          emphasisPos->SetIntValue(NS_STYLE_TEXT_EMPHASIS_POSITION_DEFAULT_ZH,
+                                   eCSSUnit_Enumerated);
+        } else if (nsStyleUtil::MatchesLanguagePrefix(lang, MOZ_UTF16("ja")) ||
+                   nsStyleUtil::MatchesLanguagePrefix(lang, MOZ_UTF16("mn"))) {
+          // This branch is currently no part of the spec.
+          // See bug 1040668 comment 69 and comment 75.
+          emphasisPos->SetIntValue(NS_STYLE_TEXT_EMPHASIS_POSITION_DEFAULT,
+                                   eCSSUnit_Enumerated);
+        }
       }
     }
   }
 }
 
 void
 nsGenericHTMLElement::MapCommonAttributesInto(const nsMappedAttributes* aAttributes,
                                               nsRuleData* aData)
--- a/layout/style/nsStyleConsts.h
+++ b/layout/style/nsStyleConsts.h
@@ -1068,16 +1068,22 @@ enum class FillMode : uint32_t;
 #define NS_STYLE_TEXT_ANCHOR_MIDDLE             1
 #define NS_STYLE_TEXT_ANCHOR_END                2
 
 // text-emphasis-position
 #define NS_STYLE_TEXT_EMPHASIS_POSITION_OVER    (1 << 0)
 #define NS_STYLE_TEXT_EMPHASIS_POSITION_UNDER   (1 << 1)
 #define NS_STYLE_TEXT_EMPHASIS_POSITION_LEFT    (1 << 2)
 #define NS_STYLE_TEXT_EMPHASIS_POSITION_RIGHT   (1 << 3)
+#define NS_STYLE_TEXT_EMPHASIS_POSITION_DEFAULT \
+  (NS_STYLE_TEXT_EMPHASIS_POSITION_OVER | \
+   NS_STYLE_TEXT_EMPHASIS_POSITION_RIGHT)
+#define NS_STYLE_TEXT_EMPHASIS_POSITION_DEFAULT_ZH \
+  (NS_STYLE_TEXT_EMPHASIS_POSITION_UNDER | \
+   NS_STYLE_TEXT_EMPHASIS_POSITION_RIGHT)
 
 // text-emphasis-style
 // Note that filled and none here both have zero as their value. This is
 // not an problem because:
 // * In specified style, none is represented as eCSSUnit_None.
 // * In computed style, 'filled' always has its shape computed, and thus
 //   the combined value is never zero.
 #define NS_STYLE_TEXT_EMPHASIS_STYLE_NONE           0
--- a/layout/style/nsStyleStruct.cpp
+++ b/layout/style/nsStyleStruct.cpp
@@ -3606,18 +3606,21 @@ nsStyleText::nsStyleText(nsPresContext* 
   mWordBreak = NS_STYLE_WORDBREAK_NORMAL;
   mWordWrap = NS_STYLE_WORDWRAP_NORMAL;
   mHyphens = NS_STYLE_HYPHENS_MANUAL;
   mRubyAlign = NS_STYLE_RUBY_ALIGN_SPACE_AROUND;
   mRubyPosition = NS_STYLE_RUBY_POSITION_OVER;
   mTextSizeAdjust = NS_STYLE_TEXT_SIZE_ADJUST_AUTO;
   mTextCombineUpright = NS_STYLE_TEXT_COMBINE_UPRIGHT_NONE;
   mTextEmphasisStyle = NS_STYLE_TEXT_EMPHASIS_STYLE_NONE;
-  mTextEmphasisPosition = NS_STYLE_TEXT_EMPHASIS_POSITION_OVER |
-    NS_STYLE_TEXT_EMPHASIS_POSITION_RIGHT;
+  nsCOMPtr<nsIAtom> language = aPresContext->GetContentLanguage();
+  mTextEmphasisPosition = language &&
+    nsStyleUtil::MatchesLanguagePrefix(language, MOZ_UTF16("zh")) ?
+    NS_STYLE_TEXT_EMPHASIS_POSITION_DEFAULT_ZH :
+    NS_STYLE_TEXT_EMPHASIS_POSITION_DEFAULT;
   mTextEmphasisColor = aPresContext->DefaultColor();
   mControlCharacterVisibility = nsCSSParser::ControlCharVisibilityDefault();
 
   mWordSpacing.SetCoordValue(0);
   mLetterSpacing.SetNormalValue();
   mLineHeight.SetNormalValue();
   mTextIndent.SetCoordValue(0);