Don't assume so easily that RenderStyle data can be shared.

An element can only share RenderStyle data with another element if
BOTH are cacheable. The element that's already in the cache is
obviously cacheable, but we also need to figure out whether the
element that wants to use data from the cache is cachable.

Additionally, get rid of the Element* argument from
applyMatchedProperties(), since it's already part of the state object
passed to that method.

BUG=236329

Review URL: https://chromiumcodereview.appspot.com/20560008

git-svn-id: svn://svn.chromium.org/blink/trunk@154999 bbb929c8-8fbe-4397-9dbb-9b2b20218538
diff --git a/LayoutTests/fast/css/identical-logical-height-decl-expected.html b/LayoutTests/fast/css/identical-logical-height-decl-expected.html
new file mode 100644
index 0000000..fd1cd8b
--- /dev/null
+++ b/LayoutTests/fast/css/identical-logical-height-decl-expected.html
@@ -0,0 +1,9 @@
+<!DOCTYPE html>
+<html>
+  <head>
+    <title>Identical style declaration on elements with different writing modes</title>
+  </head>
+  <body style="overflow:hidden;">
+    <p>There should be no red on this page.</p>
+  </body>
+</html>
diff --git a/LayoutTests/fast/css/identical-logical-height-decl.html b/LayoutTests/fast/css/identical-logical-height-decl.html
new file mode 100644
index 0000000..20888a1
--- /dev/null
+++ b/LayoutTests/fast/css/identical-logical-height-decl.html
@@ -0,0 +1,15 @@
+<!DOCTYPE html>
+<html>
+  <head>
+    <title>Identical style declaration on elements with different writing modes</title>
+  </head>
+  <body style="overflow:hidden;">
+    <p>There should be no red on this page.</p>
+    <div style="-webkit-logical-height:10px;"></div> <!-- set height -->
+    <div style="-webkit-writing-mode:vertical-lr; width:100px; height:100px; background:red;">
+      <div style="-webkit-logical-height:10px;"> <!-- set width! -->
+        <div style="width:100px; background:white;"></div>
+      </div>
+    </div>
+  </body>
+</html>
diff --git a/Source/core/css/resolver/StyleResolver.cpp b/Source/core/css/resolver/StyleResolver.cpp
index d5bbca9..30d450d 100644
--- a/Source/core/css/resolver/StyleResolver.cpp
+++ b/Source/core/css/resolver/StyleResolver.cpp
@@ -605,7 +605,7 @@
         else
             matchAllRules(state, collector, m_matchAuthorAndUserStyles, matchingBehavior != MatchAllRulesExcludingSMIL);
 
-        applyMatchedProperties(state, collector.matchedResult(), element);
+        applyMatchedProperties(state, collector.matchedResult());
     }
     {
         StyleAdjuster adjuster(state.cachedUAStyle(), m_document->inQuirksMode());
@@ -800,7 +800,7 @@
 
         state.style()->setStyleType(pseudoStyleRequest.pseudoId);
 
-        applyMatchedProperties(state, collector.matchedResult(), e);
+        applyMatchedProperties(state, collector.matchedResult());
     }
     {
         StyleAdjuster adjuster(state.cachedUAStyle(), m_document->inQuirksMode());
@@ -1188,8 +1188,9 @@
     m_matchedPropertiesCache.clear();
 }
 
-void StyleResolver::applyMatchedProperties(StyleResolverState& state, const MatchResult& matchResult, const Element* element)
+void StyleResolver::applyMatchedProperties(StyleResolverState& state, const MatchResult& matchResult)
 {
+    const Element* element = state.element();
     ASSERT(element);
     STYLE_STATS_ADD_MATCHED_PROPERTIES_SEARCH();
 
@@ -1197,7 +1198,8 @@
     bool applyInheritedOnly = false;
     const CachedMatchedProperties* cachedMatchedProperties = 0;
 
-    if (cacheHash && (cachedMatchedProperties = m_matchedPropertiesCache.find(cacheHash, state, matchResult))) {
+    if (cacheHash && (cachedMatchedProperties = m_matchedPropertiesCache.find(cacheHash, state, matchResult))
+        && MatchedPropertiesCache::isCacheable(element, state.style(), state.parentStyle())) {
         STYLE_STATS_ADD_MATCHED_PROPERTIES_HIT();
         // We can build up the style by copying non-inherited properties from an earlier style object built using the same exact
         // style declarations. We then only need to apply the inherited properties, if any, as their values can depend on the
@@ -1286,7 +1288,7 @@
 
     if (cachedMatchedProperties || !cacheHash)
         return;
-    if (!MatchedPropertiesCache::isCacheable(state.element(), state.style(), state.parentStyle()))
+    if (!MatchedPropertiesCache::isCacheable(element, state.style(), state.parentStyle()))
         return;
     STYLE_STATS_ADD_MATCHED_PROPERTIES_ENTERED_INTO_CACHE();
     m_matchedPropertiesCache.add(state.style(), state.parentStyle(), cacheHash, matchResult);
diff --git a/Source/core/css/resolver/StyleResolver.h b/Source/core/css/resolver/StyleResolver.h
index 88670be..3c5a8b3 100644
--- a/Source/core/css/resolver/StyleResolver.h
+++ b/Source/core/css/resolver/StyleResolver.h
@@ -288,7 +288,7 @@
 
     bool fastRejectSelector(const RuleData&) const;
 
-    void applyMatchedProperties(StyleResolverState&, const MatchResult&, const Element*);
+    void applyMatchedProperties(StyleResolverState&, const MatchResult&);
 
     enum StyleApplicationPass {
         VariableDefinitions,