diff --git a/DEPS b/DEPS
index 2d52db01..b35d767f 100644
--- a/DEPS
+++ b/DEPS
@@ -44,7 +44,7 @@
   # Three lines of non-changing comments so that
   # the commit queue can handle CLs rolling V8
   # and whatever else without interference from each other.
-  'v8_revision': 'd9b95e9cafba1c5e9e55a6b43fb269c5123ca3d6',
+  'v8_revision': '5f2d10c258707666a6ad256bd18a81cfcd9d8e61',
   # Three lines of non-changing comments so that
   # the commit queue can handle CLs rolling swarming_client
   # and whatever else without interference from each other.
diff --git a/chrome/VERSION b/chrome/VERSION
index a323f14..e6e5fc0 100644
--- a/chrome/VERSION
+++ b/chrome/VERSION
@@ -1,4 +1,4 @@
 MAJOR=57
 MINOR=0
-BUILD=2983
+BUILD=2984
 PATCH=0
diff --git a/chrome/browser/sync_file_system/drive_backend/sync_engine_initializer_unittest.cc b/chrome/browser/sync_file_system/drive_backend/sync_engine_initializer_unittest.cc
index ec2f2ec..38d9d48 100644
--- a/chrome/browser/sync_file_system/drive_backend/sync_engine_initializer_unittest.cc
+++ b/chrome/browser/sync_file_system/drive_backend/sync_engine_initializer_unittest.cc
@@ -7,6 +7,7 @@
 #include <stddef.h>
 #include <stdint.h>
 #include <utility>
+#include <vector>
 
 #include "base/bind.h"
 #include "base/files/scoped_temp_dir.h"
@@ -107,32 +108,16 @@
 
   SyncStatusCode PopulateDatabase(
       const google_apis::FileResource& sync_root,
-      const google_apis::FileResource** app_roots,
-      size_t app_roots_count) {
+      const std::vector<std::unique_ptr<google_apis::FileResource>>&
+          app_root_list) {
     SyncStatusCode status = SYNC_STATUS_UNKNOWN;
     std::unique_ptr<MetadataDatabase> database = MetadataDatabase::Create(
         database_path(), in_memory_env_.get(), &status);
     if (status != SYNC_STATUS_OK)
       return status;
 
-    // |app_root_list| must not own the resources here. Be sure to release
-    // ownership of all elements later.
-    // TODO(leonhsl) Need follow up: having two owners for a pointer is a
-    // dangerous pattern that we don't want to keep around.
-    std::vector<std::unique_ptr<google_apis::FileResource>> app_root_list;
-    for (size_t i = 0; i < app_roots_count; ++i) {
-      app_root_list.push_back(base::WrapUnique(
-          const_cast<google_apis::FileResource*>(app_roots[i])));
-    }
-
     status = database->PopulateInitialData(
         kInitialLargestChangeID, sync_root, app_root_list);
-
-    for_each(app_root_list.begin(), app_root_list.end(),
-             [](std::unique_ptr<google_apis::FileResource>& entry) {
-               entry.release();
-             });
-    app_root_list.clear();
     return status;
   }
 
@@ -279,26 +264,23 @@
 
 TEST_F(SyncEngineInitializerTest, DatabaseAlreadyInitialized) {
   std::unique_ptr<google_apis::FileResource> sync_root(CreateRemoteSyncRoot());
-  std::unique_ptr<google_apis::FileResource> app_root_1(
+  std::vector<std::unique_ptr<google_apis::FileResource>> app_root_list;
+  app_root_list.push_back(
       CreateRemoteFolder(sync_root->file_id(), "app-root 1"));
-  std::unique_ptr<google_apis::FileResource> app_root_2(
+  app_root_list.push_back(
       CreateRemoteFolder(sync_root->file_id(), "app-root 2"));
 
-  const google_apis::FileResource* app_roots[] = {
-    app_root_1.get(), app_root_2.get()
-  };
-  EXPECT_EQ(SYNC_STATUS_OK,
-            PopulateDatabase(*sync_root, app_roots, arraysize(app_roots)));
+  EXPECT_EQ(SYNC_STATUS_OK, PopulateDatabase(*sync_root, app_root_list));
 
   EXPECT_EQ(SYNC_STATUS_OK, RunInitializer());
 
   EXPECT_EQ(1u, CountTrackersForFile(sync_root->file_id()));
-  EXPECT_EQ(1u, CountTrackersForFile(app_root_1->file_id()));
-  EXPECT_EQ(1u, CountTrackersForFile(app_root_2->file_id()));
+  EXPECT_EQ(1u, CountTrackersForFile(app_root_list[0]->file_id()));
+  EXPECT_EQ(1u, CountTrackersForFile(app_root_list[1]->file_id()));
 
   EXPECT_TRUE(HasActiveTracker(sync_root->file_id()));
-  EXPECT_FALSE(HasActiveTracker(app_root_1->file_id()));
-  EXPECT_FALSE(HasActiveTracker(app_root_2->file_id()));
+  EXPECT_FALSE(HasActiveTracker(app_root_list[0]->file_id()));
+  EXPECT_FALSE(HasActiveTracker(app_root_list[1]->file_id()));
 
   EXPECT_EQ(3u, CountFileMetadata());
   EXPECT_EQ(3u, CountFileTracker());
diff --git a/third_party/WebKit/LayoutTests/W3CImportExpectations b/third_party/WebKit/LayoutTests/W3CImportExpectations
index b3bb53c..bf5e4ec 100644
--- a/third_party/WebKit/LayoutTests/W3CImportExpectations
+++ b/third_party/WebKit/LayoutTests/W3CImportExpectations
@@ -236,7 +236,8 @@
 # imported/wpt/domxpath [ Pass ]
 imported/wpt/dpub-aam [ Skip ]
 imported/wpt/dpub-aria [ Skip ]
-imported/wpt/editing [ Skip ]
+## Owners: dom-dev@chromium.org
+# imported/wpt/editing [ Pass ]
 ## Owners: jsbell@chromium.org
 # imported/wpt/encoding [ Pass ]
 ## Owners: jrummell@chromium.org
@@ -308,7 +309,8 @@
 imported/wpt/resources/webidl2/test [ Skip ]
 imported/wpt/screen-orientation [ Skip ]
 imported/wpt/secure-contexts [ Skip ]
-imported/wpt/selection [ Skip ]
+## Owners: dom-dev@chromium.org
+# imported/wpt/selection [ Pass ]
 imported/wpt/selectors [ Skip ]
 imported/wpt/selectors-api [ Skip ]
 imported/wpt/serve [ Skip ]
diff --git a/third_party/WebKit/LayoutTests/custom-properties/registered-property-initial.html b/third_party/WebKit/LayoutTests/custom-properties/registered-property-initial.html
index 6a6ada6..91dcd4b 100644
--- a/third_party/WebKit/LayoutTests/custom-properties/registered-property-initial.html
+++ b/third_party/WebKit/LayoutTests/custom-properties/registered-property-initial.html
@@ -9,11 +9,15 @@
 </style>
 <div id=target></div>
 <script>
+CSS.registerProperty({name: '--length', syntax: '<length>', initialValue: 'calc(10px + 15px)'});
+CSS.registerProperty({name: '--length-percentage', syntax: '<length-percentage>', initialValue: 'calc(1in + 10% + 4px)'});
 CSS.registerProperty({name: '--inherited-color', syntax: '<color>', initialValue: 'pink', inherits: true});
 CSS.registerProperty({name: '--non-inherited-color', syntax: '<color>', initialValue: 'purple'});
 
 test(function() {
     computedStyle = getComputedStyle(target);
+    assert_equals(computedStyle.getPropertyValue('--length'), '25px');
+    assert_equals(computedStyle.getPropertyValue('--length-percentage'), 'calc(100px + 10%)');
     assert_equals(computedStyle.getPropertyValue('--inherited-color'), 'pink');
     assert_equals(computedStyle.getPropertyValue('--non-inherited-color'), 'purple');
 
diff --git a/third_party/WebKit/Source/build/scripts/css_properties.py b/third_party/WebKit/Source/build/scripts/css_properties.py
index e201550..88727eb 100755
--- a/third_party/WebKit/Source/build/scripts/css_properties.py
+++ b/third_party/WebKit/Source/build/scripts/css_properties.py
@@ -31,6 +31,7 @@
         'custom_value': False,
         'builder_skip': False,
         'direction_aware': False,
+        'priority': 'Low',
         'api_class': None,
         # Generated ComputedStyle annotations.
         'field_storage_type': None,
@@ -55,6 +56,7 @@
         'custom_value': (True, False),
         'builder_skip': (True, False),
         'direction_aware': (True, False),
+        'priority': ('Animation', 'High', 'Low'),
         'keyword_only': (True, False),
     }
 
@@ -62,6 +64,24 @@
         in_generator.Writer.__init__(self, file_paths)
 
         properties = self.in_file.name_dictionaries
+
+        # Sort properties by priority, then alphabetically.
+        for property in properties:
+            # This order must match the order in CSSPropertyPriority.h.
+            priority_numbers = {'Animation': 0, 'High': 1, 'Low': 2}
+            priority = priority_numbers[property['priority']]
+            name_without_leading_dash = property['name']
+            if property['name'].startswith('-'):
+                name_without_leading_dash = property['name'][1:]
+            property['sorting_key'] = (priority, name_without_leading_dash)
+
+        # Assert there are no key collisions.
+        sorting_keys = [p['sorting_key'] for p in properties]
+        assert len(sorting_keys) == len(set(sorting_keys)), \
+            ('Collision detected - two properties have the same name and priority, '
+             'a potentially non-deterministic ordering can occur.')
+        properties.sort(key=lambda p: p['sorting_key'])
+
         self._aliases = [property for property in properties if property['alias_for']]
         properties = [property for property in properties if not property['alias_for']]
 
diff --git a/third_party/WebKit/Source/core/css/CSSProperties.in b/third_party/WebKit/Source/core/css/CSSProperties.in
index 83fda27..68f3635 100644
--- a/third_party/WebKit/Source/core/css/CSSProperties.in
+++ b/third_party/WebKit/Source/core/css/CSSProperties.in
@@ -142,47 +142,52 @@
 // This property resolves to a different property based on the current direction
 // and writing mode.
 
+// - priority=High
+// The priority level for computing the property. Valid values are
+// "Animation" (highest), "High" and "Low". Properties with the same
+// priority level are grouped and computed in alphabetical order. The
+// default value is "Low".
 
 // Properties with StyleBuilder handling
 
 // Animation Priority properties
-animation-delay custom_all
-animation-direction keywords=[normal|reverse|alternate|alternate-reverse], repeated, custom_all
-animation-duration custom_all
-animation-fill-mode custom_all
-animation-iteration-count keywords=[infinite], repeated, custom_all
-animation-name custom_all
-animation-play-state custom_all
-animation-timing-function custom_all
-transition-delay custom_all
-transition-duration custom_all
-transition-property custom_all
-transition-timing-function custom_all
+animation-delay custom_all, priority=Animation
+animation-direction keywords=[normal|reverse|alternate|alternate-reverse], repeated, custom_all, priority=Animation
+animation-duration custom_all, priority=Animation
+animation-fill-mode custom_all, priority=Animation
+animation-iteration-count keywords=[infinite], repeated, custom_all, priority=Animation
+animation-name custom_all, priority=Animation
+animation-play-state custom_all, priority=Animation
+animation-timing-function custom_all, priority=Animation
+transition-delay custom_all, priority=Animation
+transition-duration custom_all, priority=Animation
+transition-property custom_all, priority=Animation
+transition-timing-function custom_all, priority=Animation
 
 // High Priority and all other font properties.
 // Other properties can depend upon high priority properties (e.g. font-size / ems)
-color interpolable, inherited, custom_all
-direction inherited, custom_value, keyword_only, keywords=[ltr|rtl], initial_keyword=ltr, field_storage_type=platform/text/TextDirection
-font-family inherited, font, type_name=FontDescription::FamilyDescription, name_for_methods=FamilyDescription, converter=convertFontFamily
-font-kerning inherited, font, type_name=FontDescription::Kerning, name_for_methods=Kerning
-font-size interpolable, inherited, font, name_for_methods=Size, getter=getSize, converter=convertFontSize
-font-size-adjust runtime_flag=CSSFontSizeAdjust, interpolable, inherited, font, name_for_methods=SizeAdjust, converter=convertFontSizeAdjust, api_class
-font-stretch inherited, font, type_name=FontStretch, name_for_methods=Stretch
-font-style inherited, font, type_name=FontStyle, name_for_methods=Style
-font-variant-ligatures inherited, font, type_name=VariantLigatures, name_for_methods=VariantLigatures, converter=convertFontVariantLigatures
-font-variant-caps inherited, font, name_for_methods=VariantCaps, converter=convertFontVariantCaps
-font-variant-numeric inherited, font, name_for_methods=VariantNumeric, converter=convertFontVariantNumeric
-font-weight interpolable, inherited, font, type_name=FontWeight, name_for_methods=Weight, converter=convertFontWeight
-font-feature-settings inherited, font, name_for_methods=FeatureSettings, converter=convertFontFeatureSettings
-font-variation-settings runtime_flag=CSSVariableFonts, inherited, font, name_for_methods=VariationSettings, converter=convertFontVariationSettings, api_class
--webkit-font-smoothing inherited, font, type_name=FontSmoothingMode
--webkit-locale inherited, font, custom_value
-text-orientation inherited, custom_value, type_name=TextOrientation
--webkit-text-orientation inherited, custom_value, type_name=TextOrientation
-writing-mode inherited, custom_value, type_name=WritingMode, keyword_only, keywords=[horizontal-tb|vertical-rl|vertical-lr], initial_keyword=horizontal-tb, field_storage_type=platform/text/WritingMode
--webkit-writing-mode inherited, custom_value, type_name=WritingMode
-text-rendering inherited, font, type_name=TextRenderingMode
-zoom custom_all, api_class
+color interpolable, inherited, custom_all, priority=High
+direction inherited, custom_value, keyword_only, keywords=[ltr|rtl], initial_keyword=ltr, field_storage_type=platform/text/TextDirection, priority=High
+font-family inherited, font, type_name=FontDescription::FamilyDescription, name_for_methods=FamilyDescription, converter=convertFontFamily, priority=High
+font-kerning inherited, font, type_name=FontDescription::Kerning, name_for_methods=Kerning, priority=High
+font-size interpolable, inherited, font, name_for_methods=Size, getter=getSize, converter=convertFontSize, priority=High
+font-size-adjust runtime_flag=CSSFontSizeAdjust, interpolable, inherited, font, name_for_methods=SizeAdjust, converter=convertFontSizeAdjust, api_class, priority=High
+font-stretch inherited, font, type_name=FontStretch, name_for_methods=Stretch, priority=High
+font-style inherited, font, type_name=FontStyle, name_for_methods=Style, priority=High
+font-variant-ligatures inherited, font, type_name=VariantLigatures, name_for_methods=VariantLigatures, converter=convertFontVariantLigatures, priority=High
+font-variant-caps inherited, font, name_for_methods=VariantCaps, converter=convertFontVariantCaps, priority=High
+font-variant-numeric inherited, font, name_for_methods=VariantNumeric, converter=convertFontVariantNumeric, priority=High
+font-weight interpolable, inherited, font, type_name=FontWeight, name_for_methods=Weight, converter=convertFontWeight, priority=High
+font-feature-settings inherited, font, name_for_methods=FeatureSettings, converter=convertFontFeatureSettings, priority=High
+font-variation-settings runtime_flag=CSSVariableFonts, inherited, font, name_for_methods=VariationSettings, converter=convertFontVariationSettings, api_class, priority=High
+-webkit-font-smoothing inherited, font, type_name=FontSmoothingMode, priority=High
+-webkit-locale inherited, font, custom_value, priority=High
+text-orientation inherited, custom_value, type_name=TextOrientation, priority=High
+-webkit-text-orientation inherited, custom_value, type_name=TextOrientation, priority=High
+writing-mode inherited, custom_value, type_name=WritingMode, keyword_only, keywords=[horizontal-tb|vertical-rl|vertical-lr], initial_keyword=horizontal-tb, field_storage_type=platform/text/WritingMode, priority=High
+-webkit-writing-mode inherited, custom_value, type_name=WritingMode, priority=High
+text-rendering inherited, font, type_name=TextRenderingMode, priority=High
+zoom custom_all, api_class, priority=High
 
 align-content initial=initialContentAlignment, converter=convertContentAlignmentData
 align-items initial=initialDefaultAlignment, converter=convertSelfOrDefaultAlignmentData
diff --git a/third_party/WebKit/Source/core/css/CSSToLengthConversionData.cpp b/third_party/WebKit/Source/core/css/CSSToLengthConversionData.cpp
index e1f3d7f..5b73defd 100644
--- a/third_party/WebKit/Source/core/css/CSSToLengthConversionData.cpp
+++ b/third_party/WebKit/Source/core/css/CSSToLengthConversionData.cpp
@@ -85,7 +85,6 @@
       m_fontSizes(fontSizes),
       m_viewportSize(viewportSize),
       m_zoom(clampTo<float>(zoom, std::numeric_limits<float>::denorm_min())) {
-  ASSERT(m_style);
 }
 
 CSSToLengthConversionData::CSSToLengthConversionData(
diff --git a/third_party/WebKit/Source/core/css/CSSToLengthConversionData.h b/third_party/WebKit/Source/core/css/CSSToLengthConversionData.h
index d77764e..efdb1c7 100644
--- a/third_party/WebKit/Source/core/css/CSSToLengthConversionData.h
+++ b/third_party/WebKit/Source/core/css/CSSToLengthConversionData.h
@@ -83,7 +83,7 @@
     DoubleSize m_size;
   };
 
-  CSSToLengthConversionData() {}
+  CSSToLengthConversionData() : m_style(nullptr), m_zoom(1) {}
   CSSToLengthConversionData(const ComputedStyle*,
                             const FontSizes&,
                             const ViewportSize&,
diff --git a/third_party/WebKit/Source/core/css/PropertyRegistration.cpp b/third_party/WebKit/Source/core/css/PropertyRegistration.cpp
index ed25ec77..09683e1 100644
--- a/third_party/WebKit/Source/core/css/PropertyRegistration.cpp
+++ b/third_party/WebKit/Source/core/css/PropertyRegistration.cpp
@@ -12,6 +12,7 @@
 #include "core/css/PropertyRegistry.h"
 #include "core/css/parser/CSSTokenizer.h"
 #include "core/css/parser/CSSVariableParser.h"
+#include "core/css/resolver/StyleBuilderConverter.h"
 #include "core/dom/Document.h"
 #include "core/dom/ExceptionCode.h"
 #include "core/dom/StyleChangeReason.h"
@@ -121,6 +122,8 @@
           "The initial value provided is not computationally independent.");
       return;
     }
+    initial =
+        &StyleBuilderConverter::convertRegisteredPropertyInitialValue(*initial);
     RefPtr<CSSVariableData> initialVariableData = CSSVariableData::create(
         tokenizer.tokenRange(), isAnimationTainted, false);
     registry.registerProperty(
diff --git a/third_party/WebKit/Source/core/css/resolver/CSSPropertyPriority.h b/third_party/WebKit/Source/core/css/resolver/CSSPropertyPriority.h
index c8df161..8d4c216 100644
--- a/third_party/WebKit/Source/core/css/resolver/CSSPropertyPriority.h
+++ b/third_party/WebKit/Source/core/css/resolver/CSSPropertyPriority.h
@@ -14,6 +14,8 @@
 // properties. For example, the value of the high priority property 'font-size'
 // decides the pixel value of low priority properties with 'em' units.
 
+// TODO(sashab): Generate the methods in this file.
+
 enum CSSPropertyPriority {
   ResolveVariables = 0,
   AnimationPropertyPriority,
@@ -82,9 +84,9 @@
   static_assert(
       CSSPropertyZoom == CSSPropertyColor + 21,
       "CSSPropertyZoom should be the end of the high priority property range");
-  static_assert(
-      CSSPropertyTextRendering == CSSPropertyZoom - 1,
-      "CSSPropertyTextRendering should be immediately before CSSPropertyZoom");
+  static_assert(CSSPropertyWritingMode == CSSPropertyZoom - 1,
+                "CSSPropertyWritingMode should be immediately before "
+                "CSSPropertyZoom");
   return CSSPropertyZoom;
 }
 
diff --git a/third_party/WebKit/Source/core/css/resolver/StyleBuilderConverter.cpp b/third_party/WebKit/Source/core/css/resolver/StyleBuilderConverter.cpp
index 0311e4d..5523851 100644
--- a/third_party/WebKit/Source/core/css/resolver/StyleBuilderConverter.cpp
+++ b/third_party/WebKit/Source/core/css/resolver/StyleBuilderConverter.cpp
@@ -1284,30 +1284,46 @@
   return nullptr;
 }
 
-const CSSValue& StyleBuilderConverter::convertRegisteredPropertyValue(
-    const StyleResolverState& state,
+static const CSSValue& computeRegisteredPropertyValue(
+    const CSSToLengthConversionData& cssToLengthConversionData,
     const CSSValue& value) {
   // TODO(timloh): Images and transform-function values can also contain
   // lengths.
   if (value.isValueList()) {
     CSSValueList* newList = CSSValueList::createSpaceSeparated();
-    for (const CSSValue* innerValue : toCSSValueList(value))
-      newList->append(convertRegisteredPropertyValue(state, *innerValue));
+    for (const CSSValue* innerValue : toCSSValueList(value)) {
+      newList->append(computeRegisteredPropertyValue(cssToLengthConversionData,
+                                                     *innerValue));
+    }
     return *newList;
   }
 
   if (value.isPrimitiveValue()) {
     const CSSPrimitiveValue& primitiveValue = toCSSPrimitiveValue(value);
-    if (primitiveValue.isCalculated() ||
+    if ((primitiveValue.isCalculated() &&
+         (primitiveValue.isCalculatedPercentageWithLength() ||
+          primitiveValue.isLength() || primitiveValue.isPercentage())) ||
         CSSPrimitiveValue::isRelativeUnit(
             primitiveValue.typeWithCalcResolved())) {
       // Instead of the actual zoom, use 1 to avoid potential rounding errors
       Length length = primitiveValue.convertToLength(
-          state.cssToLengthConversionData().copyWithAdjustedZoom(1));
+          cssToLengthConversionData.copyWithAdjustedZoom(1));
       return *CSSPrimitiveValue::create(length, 1);
     }
   }
   return value;
 }
 
+const CSSValue& StyleBuilderConverter::convertRegisteredPropertyInitialValue(
+    const CSSValue& value) {
+  return computeRegisteredPropertyValue(CSSToLengthConversionData(), value);
+}
+
+const CSSValue& StyleBuilderConverter::convertRegisteredPropertyValue(
+    const StyleResolverState& state,
+    const CSSValue& value) {
+  return computeRegisteredPropertyValue(state.cssToLengthConversionData(),
+                                        value);
+}
+
 }  // namespace blink
diff --git a/third_party/WebKit/Source/core/css/resolver/StyleBuilderConverter.h b/third_party/WebKit/Source/core/css/resolver/StyleBuilderConverter.h
index 56b4bbb..33f31ae7 100644
--- a/third_party/WebKit/Source/core/css/resolver/StyleBuilderConverter.h
+++ b/third_party/WebKit/Source/core/css/resolver/StyleBuilderConverter.h
@@ -194,6 +194,7 @@
   static Length convertPositionLength(StyleResolverState&, const CSSValue&);
   static Rotation convertRotation(const CSSValue&);
 
+  static const CSSValue& convertRegisteredPropertyInitialValue(const CSSValue&);
   static const CSSValue& convertRegisteredPropertyValue(
       const StyleResolverState&,
       const CSSValue&);
diff --git a/third_party/WebKit/Source/core/dom/Document.cpp b/third_party/WebKit/Source/core/dom/Document.cpp
index 0ce8353..ed4d6b5 100644
--- a/third_party/WebKit/Source/core/dom/Document.cpp
+++ b/third_party/WebKit/Source/core/dom/Document.cpp
@@ -435,7 +435,6 @@
       m_gotoAnchorNeededAfterStylesheetsLoad(false),
       m_containsValidityStyleRules(false),
       m_containsPlugins(false),
-      m_updateFocusAppearanceSelectionBahavior(SelectionBehaviorOnFocus::Reset),
       m_ignoreDestructiveWriteCount(0),
       m_throwOnDynamicMarkupInsertionCount(0),
       m_markers(new DocumentMarkerController(*this)),
@@ -5591,9 +5590,7 @@
   return isMainThread();
 }
 
-void Document::updateFocusAppearanceSoon(
-    SelectionBehaviorOnFocus selectionbehavioronfocus) {
-  m_updateFocusAppearanceSelectionBahavior = selectionbehavioronfocus;
+void Document::updateFocusAppearanceLater() {
   if (!m_updateFocusAppearanceTimer.isActive())
     m_updateFocusAppearanceTimer.startOneShot(0, BLINK_FROM_HERE);
 }
@@ -5608,7 +5605,7 @@
     return;
   updateStyleAndLayout();
   if (element->isFocusable())
-    element->updateFocusAppearance(m_updateFocusAppearanceSelectionBahavior);
+    element->updateFocusAppearance(SelectionBehaviorOnFocus::Restore);
 }
 
 void Document::attachRange(Range* range) {
diff --git a/third_party/WebKit/Source/core/dom/Document.h b/third_party/WebKit/Source/core/dom/Document.h
index d8ffbab..19e980fe 100644
--- a/third_party/WebKit/Source/core/dom/Document.h
+++ b/third_party/WebKit/Source/core/dom/Document.h
@@ -172,7 +172,6 @@
 class TransformSource;
 class TreeWalker;
 class VisitedLinkState;
-enum class SelectionBehaviorOnFocus;
 struct AnnotatedRegionValue;
 struct FocusParams;
 struct IconURL;
@@ -979,7 +978,7 @@
   // Returns null if there is no such element.
   HTMLLinkElement* linkManifest() const;
 
-  void updateFocusAppearanceSoon(SelectionBehaviorOnFocus);
+  void updateFocusAppearanceLater();
   void cancelFocusAppearanceUpdate();
 
   bool isDNSPrefetchEnabled() const { return m_isDNSPrefetchEnabled; }
@@ -1525,7 +1524,6 @@
   bool m_haveExplicitlyDisabledDNSPrefetch;
   bool m_containsValidityStyleRules;
   bool m_containsPlugins;
-  SelectionBehaviorOnFocus m_updateFocusAppearanceSelectionBahavior;
 
   // http://www.whatwg.org/specs/web-apps/current-work/#ignore-destructive-writes-counter
   unsigned m_ignoreDestructiveWriteCount;
diff --git a/third_party/WebKit/Source/core/editing/FrameSelection.cpp b/third_party/WebKit/Source/core/editing/FrameSelection.cpp
index 78531bc..5cf29222 100644
--- a/third_party/WebKit/Source/core/editing/FrameSelection.cpp
+++ b/third_party/WebKit/Source/core/editing/FrameSelection.cpp
@@ -104,6 +104,11 @@
 
 FrameSelection::~FrameSelection() {}
 
+const DisplayItemClient& FrameSelection::caretDisplayItemClientForTesting()
+    const {
+  return *m_frameCaret;
+}
+
 const Document& FrameSelection::document() const {
   DCHECK(m_document);
   return *m_document;
diff --git a/third_party/WebKit/Source/core/editing/FrameSelection.h b/third_party/WebKit/Source/core/editing/FrameSelection.h
index 4b609af..d5caa17 100644
--- a/third_party/WebKit/Source/core/editing/FrameSelection.h
+++ b/third_party/WebKit/Source/core/editing/FrameSelection.h
@@ -45,6 +45,7 @@
 namespace blink {
 
 class CharacterData;
+class DisplayItemClient;
 class LayoutBlock;
 class LocalFrame;
 class FrameCaret;
@@ -288,6 +289,9 @@
 
   explicit FrameSelection(LocalFrame&);
 
+  // For |PaintControllerPaintTestForSlimmingPaintV1AndV2|.
+  const DisplayItemClient& caretDisplayItemClientForTesting() const;
+
   // Note: We have |selectionInFlatTree()| for unit tests, we should
   // use |visibleSelection<EditingInFlatTreeStrategy>()|.
   const VisibleSelectionInFlatTree& selectionInFlatTree() const;
diff --git a/third_party/WebKit/Source/core/html/HTMLInputElement.cpp b/third_party/WebKit/Source/core/html/HTMLInputElement.cpp
index 17b847a7..07ee1a29 100644
--- a/third_party/WebKit/Source/core/html/HTMLInputElement.cpp
+++ b/third_party/WebKit/Source/core/html/HTMLInputElement.cpp
@@ -501,8 +501,10 @@
     }
   }
 
+  // UA Shadow tree was recreated. We need to set selection again. We do it
+  // later in order to avoid force layout.
   if (document().focusedElement() == this)
-    document().updateFocusAppearanceSoon(SelectionBehaviorOnFocus::Restore);
+    document().updateFocusAppearanceLater();
 
   setTextAsOfLastFormControlChangeEvent(value());
   setChangedSinceLastFormControlChangeEvent(false);
@@ -854,9 +856,6 @@
 
   m_inputTypeView->startResourceLoading();
   m_inputType->countUsage();
-
-  if (document().focusedElement() == this)
-    document().updateFocusAppearanceSoon(SelectionBehaviorOnFocus::Restore);
 }
 
 void HTMLInputElement::detachLayoutTree(const AttachContext& context) {
diff --git a/third_party/WebKit/Source/core/paint/PaintControllerPaintTest.cpp b/third_party/WebKit/Source/core/paint/PaintControllerPaintTest.cpp
index a7561a22..8bb3ea1 100644
--- a/third_party/WebKit/Source/core/paint/PaintControllerPaintTest.cpp
+++ b/third_party/WebKit/Source/core/paint/PaintControllerPaintTest.cpp
@@ -72,7 +72,10 @@
           TestDisplayItem(*layoutView().layer(), DisplayItem::kSubsequence),
           TestDisplayItem(layoutView(), documentBackgroundType),
           TestDisplayItem(textInlineBox, foregroundType),
-          TestDisplayItem(*document().frame()->selection().m_frameCaret,
+          TestDisplayItem(document()
+                              .frame()
+                              ->selection()
+                              .caretDisplayItemClientForTesting(),
                           DisplayItem::kCaret),  // New!
           TestDisplayItem(*layoutView().layer(), DisplayItem::kEndSubsequence));
     } else {
@@ -83,7 +86,10 @@
           TestDisplayItem(*layoutView().layer(), DisplayItem::kSubsequence),
           TestDisplayItem(layoutView(), documentBackgroundType),
           TestDisplayItem(textInlineBox, foregroundType),
-          TestDisplayItem(*document().frame()->selection().m_frameCaret,
+          TestDisplayItem(document()
+                              .frame()
+                              ->selection()
+                              .caretDisplayItemClientForTesting(),
                           DisplayItem::kCaret),  // New!
           TestDisplayItem(*layoutView().layer(), DisplayItem::kEndSubsequence),
           TestDisplayItem(layoutView(),
@@ -95,8 +101,9 @@
         rootPaintController().getDisplayItemList(), 3,
         TestDisplayItem(layoutView(), documentBackgroundType),
         TestDisplayItem(textInlineBox, foregroundType),
-        TestDisplayItem(*document().frame()->selection().m_frameCaret,
-                        DisplayItem::kCaret));  // New!
+        TestDisplayItem(
+            document().frame()->selection().caretDisplayItemClientForTesting(),
+            DisplayItem::kCaret));  // New!
   }
 }