Title: [197502] trunk/Source/WebCore
Revision
197502
Author
an...@apple.com
Date
2016-03-03 02:48:10 -0800 (Thu, 03 Mar 2016)

Log Message

Slider thumb style should not depend on renderers
https://bugs.webkit.org/show_bug.cgi?id=154961

Reviewed by Andreas Kling.

Currently slider thumb pseudo id is computed based on host element renderer.
Style is the input for building a render tree and should be computable without having one.

* html/shadow/SliderThumbElement.cpp:
(WebCore::SliderThumbElement::hostInput):
(WebCore::SliderThumbElement::customStyleForRenderer):

    Compute pseudo id based on the host style.
    Return nullptr so style recalc will otherwise proceed normally.

(WebCore::SliderThumbElement::shadowPseudoId):
(WebCore::SliderThumbElement::cloneElementWithoutAttributesAndChildren):
(WebCore::SliderContainerElement::SliderContainerElement):
(WebCore::SliderContainerElement::create):
(WebCore::SliderContainerElement::createElementRenderer):
(WebCore::SliderContainerElement::customStyleForRenderer):

    Here too.

(WebCore::SliderContainerElement::shadowPseudoId):
(WebCore::sliderThumbShadowPseudoId): Deleted.
(WebCore::mediaSliderThumbShadowPseudoId): Deleted.
* html/shadow/SliderThumbElement.h:

Modified Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (197501 => 197502)


--- trunk/Source/WebCore/ChangeLog	2016-03-03 10:23:35 UTC (rev 197501)
+++ trunk/Source/WebCore/ChangeLog	2016-03-03 10:48:10 UTC (rev 197502)
@@ -1,3 +1,34 @@
+2016-03-03  Antti Koivisto  <an...@apple.com>
+
+        Slider thumb style should not depend on renderers
+        https://bugs.webkit.org/show_bug.cgi?id=154961
+
+        Reviewed by Andreas Kling.
+
+        Currently slider thumb pseudo id is computed based on host element renderer.
+        Style is the input for building a render tree and should be computable without having one.
+
+        * html/shadow/SliderThumbElement.cpp:
+        (WebCore::SliderThumbElement::hostInput):
+        (WebCore::SliderThumbElement::customStyleForRenderer):
+
+            Compute pseudo id based on the host style.
+            Return nullptr so style recalc will otherwise proceed normally.
+
+        (WebCore::SliderThumbElement::shadowPseudoId):
+        (WebCore::SliderThumbElement::cloneElementWithoutAttributesAndChildren):
+        (WebCore::SliderContainerElement::SliderContainerElement):
+        (WebCore::SliderContainerElement::create):
+        (WebCore::SliderContainerElement::createElementRenderer):
+        (WebCore::SliderContainerElement::customStyleForRenderer):
+
+            Here too.
+
+        (WebCore::SliderContainerElement::shadowPseudoId):
+        (WebCore::sliderThumbShadowPseudoId): Deleted.
+        (WebCore::mediaSliderThumbShadowPseudoId): Deleted.
+        * html/shadow/SliderThumbElement.h:
+
 2016-03-03  Manuel Rego Casasnovas  <r...@igalia.com>
 
         [css-grid] Simplify method to resolve auto-placed items

Modified: trunk/Source/WebCore/html/shadow/SliderThumbElement.cpp (197501 => 197502)


--- trunk/Source/WebCore/html/shadow/SliderThumbElement.cpp	2016-03-03 10:23:35 UTC (rev 197501)
+++ trunk/Source/WebCore/html/shadow/SliderThumbElement.cpp	2016-03-03 10:48:10 UTC (rev 197502)
@@ -573,45 +573,37 @@
     return downcast<HTMLInputElement>(shadowHost());
 }
 
-static const AtomicString& sliderThumbShadowPseudoId()
+RefPtr<RenderStyle> SliderThumbElement::customStyleForRenderer(RenderStyle&, RenderStyle* hostStyle)
 {
-    static NeverDestroyed<const AtomicString> sliderThumb("-webkit-slider-thumb", AtomicString::ConstructFromLiteral);
-    return sliderThumb;
-}
+    // This doesn't actually compute style. This is just a hack to pick shadow pseudo id when host style is known.
 
-static const AtomicString& mediaSliderThumbShadowPseudoId()
-{
-    static NeverDestroyed<const AtomicString> mediaSliderThumb("-webkit-media-slider-thumb", AtomicString::ConstructFromLiteral);
-    return mediaSliderThumb;
-}
+    static NeverDestroyed<const AtomicString> sliderThumbShadowPseudoId("-webkit-slider-thumb", AtomicString::ConstructFromLiteral);
+    static NeverDestroyed<const AtomicString> mediaSliderThumbShadowPseudoId("-webkit-media-slider-thumb", AtomicString::ConstructFromLiteral);
 
-const AtomicString& SliderThumbElement::shadowPseudoId() const
-{
-    // FIXME: this code needs to go away, it is very very wrong.
-    // The value of shadowPseudoId() is needed to resolve the style of the shadow tree. In this case,
-    // that value depends on the style, which means the style needs to be computed twice to get
-    // a correct value: once to get the Input's appearance, then a second time to style the shadow tree correctly.
+    if (!hostStyle)
+        return nullptr;
 
-    HTMLInputElement* input = hostInput();
-    if (!input)
-        return sliderThumbShadowPseudoId();
-    if (!input->renderer())
-        return emptyAtom;
-
-    const RenderStyle& sliderStyle = input->renderer()->style();
-    switch (sliderStyle.appearance()) {
+    switch (hostStyle->appearance()) {
     case MediaSliderPart:
     case MediaSliderThumbPart:
     case MediaVolumeSliderPart:
     case MediaVolumeSliderThumbPart:
     case MediaFullScreenVolumeSliderPart:
     case MediaFullScreenVolumeSliderThumbPart:
-        return mediaSliderThumbShadowPseudoId();
+        m_shadowPseudoId = mediaSliderThumbShadowPseudoId;
+        break;
     default:
-        return sliderThumbShadowPseudoId();
+        m_shadowPseudoId = sliderThumbShadowPseudoId;
     }
+
+    return nullptr;
 }
 
+const AtomicString& SliderThumbElement::shadowPseudoId() const
+{
+    return m_shadowPseudoId;
+}
+
 Ref<Element> SliderThumbElement::cloneElementWithoutAttributesAndChildren(Document& targetDocument)
 {
     return create(targetDocument);
@@ -622,6 +614,7 @@
 inline SliderContainerElement::SliderContainerElement(Document& document)
     : HTMLDivElement(HTMLNames::divTag, document)
 {
+    setHasCustomStyleResolveCallbacks();
 }
 
 Ref<SliderContainerElement> SliderContainerElement::create(Document& document)
@@ -634,35 +627,35 @@
     return createRenderer<RenderSliderContainer>(*this, WTFMove(style));
 }
 
-const AtomicString& SliderContainerElement::shadowPseudoId() const
+RefPtr<RenderStyle> SliderContainerElement::customStyleForRenderer(RenderStyle&, RenderStyle* hostStyle)
 {
-    // FIXME: this code needs to go away, it is very very wrong.
-    // The value of shadowPseudoId() is needed to resolve the style of the shadow tree. In this case,
-    // that value depends on the style, which means the style needs to be computed twice to get
-    // a correct value: once to get the Input's appearance, then a second time to style the shadow tree correctly.
+    // This doesn't actually compute style. This is just a hack to pick shadow pseudo id when host style is known.
 
     static NeverDestroyed<const AtomicString> mediaSliderContainer("-webkit-media-slider-container", AtomicString::ConstructFromLiteral);
     static NeverDestroyed<const AtomicString> sliderContainer("-webkit-slider-container", AtomicString::ConstructFromLiteral);
 
-    if (!is<HTMLInputElement>(*shadowHost()))
-        return sliderContainer;
+    if (!hostStyle)
+        return nullptr;
 
-    auto& input = downcast<HTMLInputElement>(*shadowHost());
-    if (!input.renderer())
-        return emptyAtom;
-
-    const RenderStyle& sliderStyle = input.renderer()->style();
-    switch (sliderStyle.appearance()) {
+    switch (hostStyle->appearance()) {
     case MediaSliderPart:
     case MediaSliderThumbPart:
     case MediaVolumeSliderPart:
     case MediaVolumeSliderThumbPart:
     case MediaFullScreenVolumeSliderPart:
     case MediaFullScreenVolumeSliderThumbPart:
-        return mediaSliderContainer;
+        m_shadowPseudoId = mediaSliderContainer;
+        break;
     default:
-        return sliderContainer;
+        m_shadowPseudoId = sliderContainer;
     }
+
+    return nullptr;
 }
 
+const AtomicString& SliderContainerElement::shadowPseudoId() const
+{
+    return m_shadowPseudoId;
 }
+
+}

Modified: trunk/Source/WebCore/html/shadow/SliderThumbElement.h (197501 => 197502)


--- trunk/Source/WebCore/html/shadow/SliderThumbElement.h	2016-03-03 10:23:35 UTC (rev 197501)
+++ trunk/Source/WebCore/html/shadow/SliderThumbElement.h	2016-03-03 10:48:10 UTC (rev 197502)
@@ -62,6 +62,7 @@
     SliderThumbElement(Document&);
 
     virtual RenderPtr<RenderElement> createElementRenderer(Ref<RenderStyle>&&, const RenderTreePosition&) override;
+
     virtual Ref<Element> cloneElementWithoutAttributesAndChildren(Document&) override;
     virtual bool isDisabledFormControl() const override;
     virtual bool matchesReadWritePseudoClass() const override;
@@ -77,6 +78,7 @@
 #endif
     virtual void willDetachRenderers() override;
 
+    virtual RefPtr<RenderStyle> customStyleForRenderer(RenderStyle&, RenderStyle*) override;
     virtual const AtomicString& shadowPseudoId() const override;
 
     void startDragging();
@@ -96,6 +98,7 @@
     void unregisterForTouchEvents();
 #endif
 
+    AtomicString m_shadowPseudoId;
     bool m_inDragMode;
 
 #if ENABLE(IOS_TOUCH_EVENTS)
@@ -132,7 +135,10 @@
 private:
     SliderContainerElement(Document&);
     virtual RenderPtr<RenderElement> createElementRenderer(Ref<RenderStyle>&&, const RenderTreePosition&) override;
+    virtual RefPtr<RenderStyle> customStyleForRenderer(RenderStyle&, RenderStyle*) override;
     virtual const AtomicString& shadowPseudoId() const override;
+
+    AtomicString m_shadowPseudoId;
 };
 
 }
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to