Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reimplement the progress display in wide-layout attachments #12424

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
40 changes: 38 additions & 2 deletions Source/WebCore/html/HTMLAttachmentElement.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,18 @@ static const AtomString& attachmentPreviewIdentifier()
return identifier;
}

static const AtomString& attachmentProgressIdentifier()
{
static MainThreadNeverDestroyed<const AtomString> identifier("attachment-progress"_s);
return identifier;
}

static const AtomString& attachmentProgressCircleIdentifier()
{
static MainThreadNeverDestroyed<const AtomString> identifier("attachment-progress-circle"_s);
return identifier;
}

static const AtomString& attachmentInformationAreaIdentifier()
{
static MainThreadNeverDestroyed<const AtomString> identifier("attachment-information-area"_s);
Expand Down Expand Up @@ -226,6 +238,11 @@ void HTMLAttachmentElement::ensureModernShadowTree(ShadowRoot& root)
m_innerLegacyAttachment->setIdAttribute(attachmentPreviewIdentifier());
previewArea->appendChild(*m_innerLegacyAttachment);

m_progressElement = createContainedElement<HTMLDivElement>(previewArea, attachmentProgressIdentifier());
updateProgress(attributeWithoutSynchronization(progressAttr));

createContainedElement<HTMLDivElement>(*m_progressElement, attachmentProgressCircleIdentifier());

auto informationArea = createContainedElement<HTMLDivElement>(*m_containerElement, attachmentInformationAreaIdentifier());

m_informationBlock = createContainedElement<HTMLDivElement>(informationArea, attachmentInformationBlockIdentifier());
Expand Down Expand Up @@ -275,6 +292,21 @@ class AttachmentSaveEventListener final : public EventListener {
WeakPtr<HTMLAttachmentElement, WeakPtrImplWithEventTargetData> m_attachment;
};

void HTMLAttachmentElement::updateProgress(const AtomString& progress)
{
if (!m_progressElement)
return;

bool validProgress = false;
float value = progress.toFloat(&validProgress);
if (validProgress && std::isfinite(value)) {
m_progressElement->setAttributeWithoutSynchronization(styleAttr, makeAtomString("--progress: ", (value < 0.0) ? "0"_s : (value > 1.0) ? "1"_s : progress));
return;
}

m_progressElement->setAttributeWithoutSynchronization(styleAttr, "display: none;"_s);
}

void HTMLAttachmentElement::updateSaveButton(bool show)
{
if (!show) {
Expand Down Expand Up @@ -425,10 +457,12 @@ RefPtr<HTMLImageElement> HTMLAttachmentElement::enclosingImageElement() const

void HTMLAttachmentElement::parseAttribute(const QualifiedName& name, const AtomString& value)
{
if (name == actionAttr || name == progressAttr || name == subtitleAttr() || name == titleAttr || name == typeAttr) {
if (name == actionAttr || name == subtitleAttr() || name == titleAttr || name == typeAttr) {
if (m_innerLegacyAttachment)
m_innerLegacyAttachment->setAttributeWithoutSynchronization(name, value);
invalidateRendering();
} else if (name == progressAttr && m_implementation == Implementation::Legacy) {
invalidateRendering();
}

HTMLElement::parseAttribute(name, value);
Expand All @@ -442,7 +476,9 @@ void HTMLAttachmentElement::parseAttribute(const QualifiedName& name, const Atom
} else if (name == subtitleAttr()) {
if (m_subtitleElement)
m_subtitleElement->setTextContent(String(value.string()));
} else if (name == saveAttr())
} else if (name == progressAttr)
updateProgress(value);
else if (name == saveAttr())
updateSaveButton(!value.isNull());

#if ENABLE(SERVICE_CONTROLS)
Expand Down
2 changes: 2 additions & 0 deletions Source/WebCore/html/HTMLAttachmentElement.h
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ class HTMLAttachmentElement final : public HTMLElement {

void didAddUserAgentShadowRoot(ShadowRoot&) final;
void ensureModernShadowTree(ShadowRoot&);
void updateProgress(const AtomString&);
void updateSaveButton(bool);

RenderPtr<RenderElement> createElementRenderer(RenderStyle&&, const RenderTreePosition&) final;
Expand Down Expand Up @@ -126,6 +127,7 @@ class HTMLAttachmentElement final : public HTMLElement {

RefPtr<HTMLAttachmentElement> m_innerLegacyAttachment;
RefPtr<HTMLElement> m_containerElement;
RefPtr<HTMLElement> m_progressElement;
RefPtr<HTMLElement> m_informationBlock;
RefPtr<HTMLElement> m_actionTextElement;
RefPtr<HTMLElement> m_titleElement;
Expand Down
19 changes: 19 additions & 0 deletions Source/WebCore/html/shadow/attachmentElementShadow.css
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,25 @@ attachment#attachment-preview {
overflow: hidden;
}

div#attachment-progress {
grid-row: 1;
grid-column: 1;
width: 100%;
aspect-ratio: 1;
border-radius: 50%;
color: -apple-system-secondary-label;
background: conic-gradient(currentcolor calc(var(--progress) * 100%), transparent 0);
}

/* FIXME: Move the border into attachment-progress above, and remove this div, when rdar://107621207 is fixed (currently it produces artifacts at the edges). */
div#attachment-progress-circle {
width: 100%;
aspect-ratio: 1;
border-radius: 50%;
border: 4px solid currentcolor;
box-sizing: border-box;
}

div#attachment-information-area {
grid-row: 1;
grid-column: 2;
Expand Down