Commit 61fc82e5 authored by Abhijeet Kandalkar's avatar Abhijeet Kandalkar Committed by Commit Bot

Use new downcast helper for blink::HTMLPictureElement

This CL has two goals,
1. Use To<HTMLPictureElement> and DynamicTo<HTMLPictureElement> as new
   downcast helper
2. Use IsA<HTMLPictureElement>(element) in place of
   IsHTMLPictureElement(element)

Bug: 891908
Change-Id: I1e4a3a63e326bf9c93c0dd170907cb58f0a4722b
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1846429Reviewed-by: default avatarChristian Biesinger <cbiesinger@chromium.org>
Commit-Queue: Abhijeet Kandalkar <abhijeet@igalia.com>
Cr-Commit-Position: refs/heads/master@{#703757}
parent 6ebf5965
...@@ -384,7 +384,7 @@ void FrameSerializer::AddResourceForElement(Document& document, ...@@ -384,7 +384,7 @@ void FrameSerializer::AddResourceForElement(Document& document,
if (const auto* image = ToHTMLImageElementOrNull(element)) { if (const auto* image = ToHTMLImageElementOrNull(element)) {
AtomicString image_url_value; AtomicString image_url_value;
const Element* parent = element.parentElement(); const Element* parent = element.parentElement();
if (parent && IsHTMLPictureElement(parent)) { if (parent && IsA<HTMLPictureElement>(parent)) {
// If parent element is <picture>, use ImageSourceURL() to get best fit // If parent element is <picture>, use ImageSourceURL() to get best fit
// image URL from sibling source. // image URL from sibling source.
image_url_value = image->ImageSourceURL(); image_url_value = image->ImageSourceURL();
......
...@@ -328,7 +328,7 @@ ImageCandidate HTMLImageElement::FindBestFitImageFromPictureParent() { ...@@ -328,7 +328,7 @@ ImageCandidate HTMLImageElement::FindBestFitImageFromPictureParent() {
DCHECK(IsMainThread()); DCHECK(IsMainThread());
Node* parent = parentNode(); Node* parent = parentNode();
source_ = nullptr; source_ = nullptr;
if (!parent || !IsHTMLPictureElement(*parent)) if (!parent || !IsA<HTMLPictureElement>(*parent))
return ImageCandidate(); return ImageCandidate();
for (Node* child = parent->firstChild(); child; for (Node* child = parent->firstChild(); child;
child = child->nextSibling()) { child = child->nextSibling()) {
...@@ -418,7 +418,7 @@ Node::InsertionNotificationRequest HTMLImageElement::InsertedInto( ...@@ -418,7 +418,7 @@ Node::InsertionNotificationRequest HTMLImageElement::InsertedInto(
if (listener_) if (listener_)
GetDocument().GetMediaQueryMatcher().AddViewportListener(listener_); GetDocument().GetMediaQueryMatcher().AddViewportListener(listener_);
bool was_added_to_picture_parent = false; bool was_added_to_picture_parent = false;
if (auto* picture_parent = ToHTMLPictureElementOrNull(parentNode())) { if (auto* picture_parent = DynamicTo<HTMLPictureElement>(parentNode())) {
picture_parent->AddListenerToSourceChildren(); picture_parent->AddListenerToSourceChildren();
was_added_to_picture_parent = picture_parent == insertion_point; was_added_to_picture_parent = picture_parent == insertion_point;
} }
...@@ -446,7 +446,7 @@ void HTMLImageElement::RemovedFrom(ContainerNode& insertion_point) { ...@@ -446,7 +446,7 @@ void HTMLImageElement::RemovedFrom(ContainerNode& insertion_point) {
ResetFormOwner(); ResetFormOwner();
if (listener_) { if (listener_) {
GetDocument().GetMediaQueryMatcher().RemoveViewportListener(listener_); GetDocument().GetMediaQueryMatcher().RemoveViewportListener(listener_);
if (auto* picture_parent = ToHTMLPictureElementOrNull(parentNode())) if (auto* picture_parent = DynamicTo<HTMLPictureElement>(parentNode()))
picture_parent->RemoveListenerFromSourceChildren(); picture_parent->RemoveListenerFromSourceChildren();
} }
HTMLElement::RemovedFrom(insertion_point); HTMLElement::RemovedFrom(insertion_point);
......
...@@ -100,8 +100,13 @@ Node::InsertionNotificationRequest HTMLSourceElement::InsertedInto( ...@@ -100,8 +100,13 @@ Node::InsertionNotificationRequest HTMLSourceElement::InsertedInto(
Element* parent = parentElement(); Element* parent = parentElement();
if (auto* media = ToHTMLMediaElementOrNull(parent)) if (auto* media = ToHTMLMediaElementOrNull(parent))
media->SourceWasAdded(this); media->SourceWasAdded(this);
if (parent == insertion_point && IsHTMLPictureElement(parent))
ToHTMLPictureElement(parent)->SourceOrMediaChanged(); auto* html_picture_element = parent == insertion_point
? DynamicTo<HTMLPictureElement>(parent)
: nullptr;
if (html_picture_element)
html_picture_element->SourceOrMediaChanged();
return kInsertionDone; return kInsertionDone;
} }
...@@ -112,7 +117,7 @@ void HTMLSourceElement::RemovedFrom(ContainerNode& removal_root) { ...@@ -112,7 +117,7 @@ void HTMLSourceElement::RemovedFrom(ContainerNode& removal_root) {
parent = DynamicTo<Element>(&removal_root); parent = DynamicTo<Element>(&removal_root);
if (auto* media = ToHTMLMediaElementOrNull(parent)) if (auto* media = ToHTMLMediaElementOrNull(parent))
media->SourceWasRemoved(this); media->SourceWasRemoved(this);
if (auto* picture = ToHTMLPictureElementOrNull(parent)) { if (auto* picture = DynamicTo<HTMLPictureElement>(parent)) {
RemoveMediaQueryListListener(); RemoveMediaQueryListListener();
if (was_removed_from_parent) if (was_removed_from_parent)
picture->SourceOrMediaChanged(); picture->SourceOrMediaChanged();
...@@ -177,13 +182,13 @@ void HTMLSourceElement::ParseAttribute( ...@@ -177,13 +182,13 @@ void HTMLSourceElement::ParseAttribute(
CreateMediaQueryList(params.new_value); CreateMediaQueryList(params.new_value);
if (name == kSrcsetAttr || name == kSizesAttr || name == kMediaAttr || if (name == kSrcsetAttr || name == kSizesAttr || name == kMediaAttr ||
name == kTypeAttr) { name == kTypeAttr) {
if (auto* picture = ToHTMLPictureElementOrNull(parentElement())) if (auto* picture = DynamicTo<HTMLPictureElement>(parentElement()))
picture->SourceOrMediaChanged(); picture->SourceOrMediaChanged();
} }
} }
void HTMLSourceElement::NotifyMediaQueryChanged() { void HTMLSourceElement::NotifyMediaQueryChanged() {
if (auto* picture = ToHTMLPictureElementOrNull(parentElement())) if (auto* picture = DynamicTo<HTMLPictureElement>(parentElement()))
picture->SourceOrMediaChanged(); picture->SourceOrMediaChanged();
} }
......
...@@ -264,7 +264,7 @@ bool GetColorsFromRect(PhysicalRect rect, ...@@ -264,7 +264,7 @@ bool GetColorsFromRect(PhysicalRect rect,
if (IsA<HTMLCanvasElement>(element) || IsHTMLEmbedElement(element) || if (IsA<HTMLCanvasElement>(element) || IsHTMLEmbedElement(element) ||
IsHTMLImageElement(element) || IsHTMLObjectElement(element) || IsHTMLImageElement(element) || IsHTMLObjectElement(element) ||
IsHTMLPictureElement(element) || element->IsSVGElement() || IsA<HTMLPictureElement>(element) || element->IsSVGElement() ||
IsHTMLVideoElement(element)) { IsHTMLVideoElement(element)) {
colors.clear(); colors.clear();
found_opaque_color = false; found_opaque_color = false;
......
...@@ -486,7 +486,7 @@ void ImageLoader::DoUpdateFromElement( ...@@ -486,7 +486,7 @@ void ImageLoader::DoUpdateFromElement(
resource_request.SetReferrerPolicy(referrer_policy); resource_request.SetReferrerPolicy(referrer_policy);
// Correct the RequestContext if necessary. // Correct the RequestContext if necessary.
if (IsHTMLPictureElement(GetElement()->parentNode()) || if (IsA<HTMLPictureElement>(GetElement()->parentNode()) ||
!GetElement()->FastGetAttribute(html_names::kSrcsetAttr).IsNull()) { !GetElement()->FastGetAttribute(html_names::kSrcsetAttr).IsNull()) {
resource_request.SetRequestContext(mojom::RequestContextType::IMAGE_SET); resource_request.SetRequestContext(mojom::RequestContextType::IMAGE_SET);
} else if (IsHTMLObjectElement(GetElement())) { } else if (IsHTMLObjectElement(GetElement())) {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment