Skip to content

Commit

Permalink
Adopt dynamicDowncast<> in InjectedBundle
Browse files Browse the repository at this point in the history
https://bugs.webkit.org/show_bug.cgi?id=267576

Reviewed by Chris Dumez.

The only InjectedBundle-related unqualified downcasts that remain for
Apple platforms are in WKDOMDocument, WKDOMElement, and WKDOMText.

* Source/WebKit/WebProcess/InjectedBundle/DOM/InjectedBundleNodeHandle.cpp:
(WebKit::InjectedBundleNodeHandle::elementBounds):
(WebKit::InjectedBundleNodeHandle::setHTMLInputElementValueForUser):
(WebKit::InjectedBundleNodeHandle::setHTMLInputElementSpellcheckEnabled):
(WebKit::InjectedBundleNodeHandle::isHTMLInputElementAutoFilled const):
(WebKit::InjectedBundleNodeHandle::isHTMLInputElementAutoFilledAndViewable const):
(WebKit::InjectedBundleNodeHandle::isHTMLInputElementAutoFilledAndObscured const):
(WebKit::InjectedBundleNodeHandle::setHTMLInputElementAutoFilled):
(WebKit::InjectedBundleNodeHandle::setHTMLInputElementAutoFilledAndViewable):
(WebKit::InjectedBundleNodeHandle::setHTMLInputElementAutoFilledAndObscured):
(WebKit::InjectedBundleNodeHandle::isHTMLInputElementAutoFillButtonEnabled const):
(WebKit::InjectedBundleNodeHandle::setHTMLInputElementAutoFillButtonEnabled):
(WebKit::InjectedBundleNodeHandle::htmlInputElementAutoFillButtonType const):
(WebKit::InjectedBundleNodeHandle::htmlInputElementLastAutoFillButtonType const):
(WebKit::InjectedBundleNodeHandle::isAutoFillAvailable const):
(WebKit::InjectedBundleNodeHandle::setAutoFillAvailable):
(WebKit::InjectedBundleNodeHandle::htmlInputElementAutoFillButtonBounds):
(WebKit::InjectedBundleNodeHandle::htmlInputElementLastChangeWasUserEdit):
(WebKit::InjectedBundleNodeHandle::htmlTextAreaElementLastChangeWasUserEdit):
(WebKit::InjectedBundleNodeHandle::isTextField const):
(WebKit::InjectedBundleNodeHandle::htmlTableCellElementCellAbove):
(WebKit::InjectedBundleNodeHandle::documentFrame):
* Source/WebKit/WebProcess/InjectedBundle/InjectedBundleHitTestResult.cpp:
(WebKit::InjectedBundleHitTestResult::image const):

Canonical link: https://commits.webkit.org/273074@main
  • Loading branch information
annevk committed Jan 16, 2024
1 parent d08bfd7 commit eb1578b
Show file tree
Hide file tree
Showing 2 changed files with 69 additions and 47 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -134,10 +134,11 @@ RefPtr<InjectedBundleNodeHandle> InjectedBundleNodeHandle::document()

IntRect InjectedBundleNodeHandle::elementBounds()
{
if (!is<Element>(m_node))
RefPtr element = dynamicDowncast<Element>(m_node);
if (!element)
return IntRect();

return downcast<Element>(*m_node).boundsInRootViewSpace();
return element->boundsInRootViewSpace();
}

IntRect InjectedBundleNodeHandle::absoluteBoundingRect(bool* isReplaced)
Expand Down Expand Up @@ -243,120 +244,137 @@ RefPtr<InjectedBundleRangeHandle> InjectedBundleNodeHandle::visibleRange()

void InjectedBundleNodeHandle::setHTMLInputElementValueForUser(const String& value)
{
if (!is<HTMLInputElement>(m_node))
RefPtr input = dynamicDowncast<HTMLInputElement>(m_node);
if (!input)
return;

downcast<HTMLInputElement>(*m_node).setValueForUser(value);
input->setValueForUser(value);
}

void InjectedBundleNodeHandle::setHTMLInputElementSpellcheckEnabled(bool enabled)
{
if (!is<HTMLInputElement>(m_node))
RefPtr input = dynamicDowncast<HTMLInputElement>(m_node);
if (!input)
return;

downcast<HTMLInputElement>(*m_node).setSpellcheckDisabledExceptTextReplacement(!enabled);
input->setSpellcheckDisabledExceptTextReplacement(!enabled);
}

bool InjectedBundleNodeHandle::isHTMLInputElementAutoFilled() const
{
if (!is<HTMLInputElement>(m_node))
RefPtr input = dynamicDowncast<HTMLInputElement>(m_node);
if (!input)
return false;

return downcast<HTMLInputElement>(*m_node).isAutoFilled();
return input->isAutoFilled();
}

bool InjectedBundleNodeHandle::isHTMLInputElementAutoFilledAndViewable() const
{
if (!is<HTMLInputElement>(m_node))
RefPtr input = dynamicDowncast<HTMLInputElement>(m_node);
if (!input)
return false;

return downcast<HTMLInputElement>(*m_node).isAutoFilledAndViewable();
return input->isAutoFilledAndViewable();
}

bool InjectedBundleNodeHandle::isHTMLInputElementAutoFilledAndObscured() const
{
if (!is<HTMLInputElement>(m_node))
RefPtr input = dynamicDowncast<HTMLInputElement>(m_node);
if (!input)
return false;

return downcast<HTMLInputElement>(*m_node).isAutoFilledAndObscured();
return input->isAutoFilledAndObscured();
}

void InjectedBundleNodeHandle::setHTMLInputElementAutoFilled(bool filled)
{
if (!is<HTMLInputElement>(m_node))
RefPtr input = dynamicDowncast<HTMLInputElement>(m_node);
if (!input)
return;

downcast<HTMLInputElement>(*m_node).setAutoFilled(filled);
input->setAutoFilled(filled);
}

void InjectedBundleNodeHandle::setHTMLInputElementAutoFilledAndViewable(bool autoFilledAndViewable)
{
if (!is<HTMLInputElement>(m_node))
RefPtr input = dynamicDowncast<HTMLInputElement>(m_node);
if (!input)
return;

downcast<HTMLInputElement>(*m_node).setAutoFilledAndViewable(autoFilledAndViewable);
input->setAutoFilledAndViewable(autoFilledAndViewable);
}

void InjectedBundleNodeHandle::setHTMLInputElementAutoFilledAndObscured(bool autoFilledAndObscured)
{
if (!is<HTMLInputElement>(m_node))
RefPtr input = dynamicDowncast<HTMLInputElement>(m_node);
if (!input)
return;

downcast<HTMLInputElement>(*m_node).setAutoFilledAndObscured(autoFilledAndObscured);
input->setAutoFilledAndObscured(autoFilledAndObscured);
}

bool InjectedBundleNodeHandle::isHTMLInputElementAutoFillButtonEnabled() const
{
if (!is<HTMLInputElement>(m_node))
RefPtr input = dynamicDowncast<HTMLInputElement>(m_node);
if (!input)
return false;

return downcast<HTMLInputElement>(*m_node).autoFillButtonType() != AutoFillButtonType::None;
return input->autoFillButtonType() != AutoFillButtonType::None;
}

void InjectedBundleNodeHandle::setHTMLInputElementAutoFillButtonEnabled(AutoFillButtonType autoFillButtonType)
{
if (!is<HTMLInputElement>(m_node))
RefPtr input = dynamicDowncast<HTMLInputElement>(m_node);
if (!input)
return;

downcast<HTMLInputElement>(*m_node).setShowAutoFillButton(autoFillButtonType);
input->setShowAutoFillButton(autoFillButtonType);
}

AutoFillButtonType InjectedBundleNodeHandle::htmlInputElementAutoFillButtonType() const
{
if (!is<HTMLInputElement>(m_node))
RefPtr input = dynamicDowncast<HTMLInputElement>(m_node);
if (!input)
return AutoFillButtonType::None;
return downcast<HTMLInputElement>(*m_node).autoFillButtonType();

return input->autoFillButtonType();
}

AutoFillButtonType InjectedBundleNodeHandle::htmlInputElementLastAutoFillButtonType() const
{
if (!is<HTMLInputElement>(m_node))
RefPtr input = dynamicDowncast<HTMLInputElement>(m_node);
if (!input)
return AutoFillButtonType::None;
return downcast<HTMLInputElement>(*m_node).lastAutoFillButtonType();

return input->lastAutoFillButtonType();
}

bool InjectedBundleNodeHandle::isAutoFillAvailable() const
{
if (!is<HTMLInputElement>(m_node))
RefPtr input = dynamicDowncast<HTMLInputElement>(m_node);
if (!input)
return false;

return downcast<HTMLInputElement>(*m_node).isAutoFillAvailable();
return input->isAutoFillAvailable();
}

void InjectedBundleNodeHandle::setAutoFillAvailable(bool autoFillAvailable)
{
if (!is<HTMLInputElement>(m_node))
RefPtr input = dynamicDowncast<HTMLInputElement>(m_node);
if (!input)
return;

downcast<HTMLInputElement>(*m_node).setAutoFillAvailable(autoFillAvailable);
input->setAutoFillAvailable(autoFillAvailable);
}

IntRect InjectedBundleNodeHandle::htmlInputElementAutoFillButtonBounds()
{
if (!is<HTMLInputElement>(m_node))
RefPtr input = dynamicDowncast<HTMLInputElement>(m_node);
if (!input)
return IntRect();

auto autoFillButton = downcast<HTMLInputElement>(*m_node).autoFillButtonElement();
auto autoFillButton = input->autoFillButtonElement();
if (!autoFillButton)
return IntRect();

Expand All @@ -365,26 +383,29 @@ IntRect InjectedBundleNodeHandle::htmlInputElementAutoFillButtonBounds()

bool InjectedBundleNodeHandle::htmlInputElementLastChangeWasUserEdit()
{
if (!is<HTMLInputElement>(m_node))
RefPtr input = dynamicDowncast<HTMLInputElement>(m_node);
if (!input)
return false;

return downcast<HTMLInputElement>(*m_node).lastChangeWasUserEdit();
return input->lastChangeWasUserEdit();
}

bool InjectedBundleNodeHandle::htmlTextAreaElementLastChangeWasUserEdit()
{
if (!is<HTMLTextAreaElement>(m_node))
RefPtr textarea = dynamicDowncast<HTMLTextAreaElement>(m_node);
if (!textarea)
return false;

return downcast<HTMLTextAreaElement>(*m_node).lastChangeWasUserEdit();
return textarea->lastChangeWasUserEdit();
}

bool InjectedBundleNodeHandle::isTextField() const
{
if (!is<HTMLInputElement>(m_node))
RefPtr input = dynamicDowncast<HTMLInputElement>(m_node);
if (!input)
return false;

return downcast<HTMLInputElement>(*m_node).isTextField();
return input->isTextField();
}

bool InjectedBundleNodeHandle::isSelectElement() const
Expand All @@ -403,18 +424,20 @@ bool InjectedBundleNodeHandle::isSelectableTextNode() const

RefPtr<InjectedBundleNodeHandle> InjectedBundleNodeHandle::htmlTableCellElementCellAbove()
{
if (!is<HTMLTableCellElement>(m_node))
RefPtr tableCell = dynamicDowncast<HTMLTableCellElement>(m_node);
if (!tableCell)
return nullptr;

return getOrCreate(downcast<HTMLTableCellElement>(*m_node).cellAbove());
return getOrCreate(tableCell->cellAbove());
}

RefPtr<WebFrame> InjectedBundleNodeHandle::documentFrame()
{
if (!m_node || !m_node->isDocumentNode())
RefPtr document = dynamicDowncast<Document>(m_node);
if (!document)
return nullptr;

auto* frame = downcast<Document>(*m_node).frame();
auto* frame = document->frame();
if (!frame)
return nullptr;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -167,20 +167,19 @@ IntRect InjectedBundleHitTestResult::imageRect() const

RefPtr<WebImage> InjectedBundleHitTestResult::image() const
{
Image* image = m_hitTestResult.image();
// For now, we only handle bitmap images.
if (!is<BitmapImage>(image))
auto* bitmapImage = dynamicDowncast<BitmapImage>(m_hitTestResult.image());
if (!bitmapImage)
return nullptr;

BitmapImage& bitmapImage = downcast<BitmapImage>(*image);
IntSize size(bitmapImage.size());
IntSize size(bitmapImage->size());
auto webImage = WebImage::create(size, static_cast<ImageOptions>(0), DestinationColorSpace::SRGB());
if (!webImage->context())
return nullptr;

// FIXME: need to handle EXIF rotation.
auto& graphicsContext = *webImage->context();
graphicsContext.drawImage(bitmapImage, { { }, size });
graphicsContext.drawImage(*bitmapImage, { { }, size });

return webImage;
}
Expand Down

0 comments on commit eb1578b

Please sign in to comment.