Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(285)

Unified Diff: third_party/WebKit/Source/core/html/HTMLMeterElement.cpp

Issue 1877763002: METER with -webkit-appearance:none should be rendered with the normal CSS way. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Drop LayoutTheme change, add TODO comments Created 4 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « third_party/WebKit/Source/core/html/HTMLMeterElement.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: third_party/WebKit/Source/core/html/HTMLMeterElement.cpp
diff --git a/third_party/WebKit/Source/core/html/HTMLMeterElement.cpp b/third_party/WebKit/Source/core/html/HTMLMeterElement.cpp
index d84e2ea9d99c7a2b996679a13459c363920b7a05..ad35299d849654315f3037b0326df0a9604b05be 100644
--- a/third_party/WebKit/Source/core/html/HTMLMeterElement.cpp
+++ b/third_party/WebKit/Source/core/html/HTMLMeterElement.cpp
@@ -24,8 +24,10 @@
#include "bindings/core/v8/ExceptionState.h"
#include "bindings/core/v8/ExceptionStatePlaceholder.h"
#include "core/HTMLNames.h"
+#include "core/dom/NodeComputedStyle.h"
#include "core/dom/shadow/ShadowRoot.h"
#include "core/frame/UseCounter.h"
+#include "core/html/HTMLContentElement.h"
#include "core/html/HTMLDivElement.h"
#include "core/html/parser/HTMLParserIdioms.h"
#include "core/layout/LayoutObject.h"
@@ -35,6 +37,70 @@ namespace blink {
using namespace HTMLNames;
+// ----------------------------------------------------------------
+
+class MeterFallbackElement final : public HTMLDivElement {
+public:
+ DECLARE_NODE_FACTORY(MeterFallbackElement);
+
+private:
+ explicit MeterFallbackElement(Document& doc)
+ : HTMLDivElement(doc)
+ {
+ setHasCustomStyleCallbacks();
+ }
+
+ PassRefPtr<ComputedStyle> customStyleForLayoutObject() override
+ {
+ // We can't use setInlineStyleProperty() because it updates the DOM
+ // tree. We shouldn't do it during style calculation.
+ // TODO(tkent): Injecting a CSS variable by host is a better approach?
+ Element* host = shadowHost();
+ RefPtr<ComputedStyle> style = originalStyleForLayoutObject();
+ if (!host || !host->computedStyle() || host->computedStyle()->appearance() != MeterPart || style->display() == NONE)
+ return style.release();
+ RefPtr<ComputedStyle> newStyle = ComputedStyle::clone(*style);
+ newStyle->setDisplay(NONE);
+ newStyle->setUnique();
+ return newStyle.release();
+ }
+};
+
+DEFINE_NODE_FACTORY(MeterFallbackElement)
+
+// ----------------------------------------------------------------
+
+class MeterInnerElement final : public HTMLDivElement {
+public:
+ DECLARE_NODE_FACTORY(MeterInnerElement);
+
+private:
+ explicit MeterInnerElement(Document& doc)
+ : HTMLDivElement(doc)
+ {
+ setHasCustomStyleCallbacks();
+ }
+
+ PassRefPtr<ComputedStyle> customStyleForLayoutObject() override
+ {
+ // We can't use setInlineStyleProperty() because it updates the DOM
+ // tree. We shouldn't do it during style calculation.
+ // TODO(tkent): Injecting a CSS variable by host is a better approach?
+ Element* host = shadowHost();
+ RefPtr<ComputedStyle> style = originalStyleForLayoutObject();
+ if (!host || !host->computedStyle() || host->computedStyle()->appearance() == MeterPart || style->display() == NONE)
+ return style.release();
+ RefPtr<ComputedStyle> newStyle = ComputedStyle::clone(*style);
+ newStyle->setDisplay(NONE);
+ newStyle->setUnique();
+ return newStyle.release();
+ }
+};
+
+DEFINE_NODE_FACTORY(MeterInnerElement)
+
+// ----------------------------------------------------------------
+
HTMLMeterElement::HTMLMeterElement(Document& document)
: LabelableElement(meterTag, document)
{
@@ -192,7 +258,7 @@ void HTMLMeterElement::didAddUserAgentShadowRoot(ShadowRoot& root)
{
ASSERT(!m_value);
- HTMLDivElement* inner = HTMLDivElement::create(document());
+ MeterInnerElement* inner = MeterInnerElement::create(document());
inner->setShadowPseudoId(AtomicString("-webkit-meter-inner-element"));
root.appendChild(inner);
@@ -204,6 +270,10 @@ void HTMLMeterElement::didAddUserAgentShadowRoot(ShadowRoot& root)
bar->appendChild(m_value);
inner->appendChild(bar);
+
+ MeterFallbackElement* fallback = MeterFallbackElement::create(document());
+ fallback->appendChild(HTMLContentElement::create(document()));
+ root.appendChild(fallback);
}
void HTMLMeterElement::updateValueAppearance(double percentage)
@@ -226,6 +296,12 @@ void HTMLMeterElement::updateValueAppearance(double percentage)
}
}
+bool HTMLMeterElement::canContainRangeEndPoint() const
+{
+ document().updateLayoutTreeForNode(this);
+ return computedStyle() && !computedStyle()->hasAppearance();
+}
+
DEFINE_TRACE(HTMLMeterElement)
{
visitor->trace(m_value);
« no previous file with comments | « third_party/WebKit/Source/core/html/HTMLMeterElement.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698