void RenderSnapshottedPlugIn::handleEvent(Event* event) { if (!is<MouseEvent>(*event)) return; MouseEvent& mouseEvent = downcast<MouseEvent>(*event); // If we're a snapshotted plugin, we want to make sure we activate on // clicks even if the page is preventing our default behaviour. Otherwise // we can never restart. One we do restart, then the page will happily // block the new plugin in the normal renderer. All this means we have to // be on the lookout for a mouseup event that comes after a mousedown // event. The code below is not completely foolproof, but the worst that // could happen is that a snapshotted plugin restarts. if (mouseEvent.type() == eventNames().mouseoutEvent) m_isPotentialMouseActivation = false; if (mouseEvent.button() != LeftButton) return; if (mouseEvent.type() == eventNames().clickEvent || (m_isPotentialMouseActivation && mouseEvent.type() == eventNames().mouseupEvent)) { m_isPotentialMouseActivation = false; bool clickWasOnOverlay = plugInImageElement().partOfSnapshotOverlay(mouseEvent.target()->toNode()); plugInImageElement().userDidClickSnapshot(&mouseEvent, !clickWasOnOverlay); mouseEvent.setDefaultHandled(); } else if (mouseEvent.type() == eventNames().mousedownEvent) { m_isPotentialMouseActivation = true; mouseEvent.setDefaultHandled(); } }
CursorDirective RenderSnapshottedPlugIn::getCursor(const LayoutPoint& point, Cursor& overrideCursor) const { if (plugInImageElement().displayState() < HTMLPlugInElement::Restarting) { overrideCursor = handCursor(); return SetCursor; } return RenderEmbeddedObject::getCursor(point, overrideCursor); }
CursorDirective RenderSnapshottedPlugIn::getCursor(const LayoutPoint& point, Cursor& overrideCursor) const { if (plugInImageElement()->displayState() < HTMLPlugInElement::PlayingWithPendingMouseClick) { overrideCursor = handCursor(); return SetCursor; } return RenderEmbeddedObject::getCursor(point, overrideCursor); }
void RenderSnapshottedPlugIn::handleEvent(Event* event) { if (!event->isMouseEvent()) return; MouseEvent* mouseEvent = static_cast<MouseEvent*>(event); if (event->type() == eventNames().clickEvent) { if (mouseEvent->button() != LeftButton) return; plugInImageElement()->setDisplayState(HTMLPlugInElement::PlayingWithPendingMouseClick); plugInImageElement()->userDidClickSnapshot(mouseEvent); if (widget()) { if (Frame* frame = document()->frame()) frame->loader()->client()->recreatePlugin(widget()); repaint(); } event->setDefaultHandled(); } else if (event->type() == eventNames().mousedownEvent) { if (mouseEvent->button() != LeftButton) return; if (m_showLabelDelayTimer.isActive()) m_showLabelDelayTimer.stop(); event->setDefaultHandled(); } else if (event->type() == eventNames().mouseoverEvent) { if (!m_showedLabelOnce || m_showReason != ShouldShowAutomatically) resetDelayTimer(UserMousedOver); event->setDefaultHandled(); } else if (event->type() == eventNames().mouseoutEvent) { if (m_showLabelDelayTimer.isActive()) m_showLabelDelayTimer.stop(); if (m_shouldShowLabel) { if (m_showReason == UserMousedOver) { m_shouldShowLabel = false; repaintLabel(); } } else if (m_shouldShowLabelAutomatically) resetDelayTimer(ShouldShowAutomatically); event->setDefaultHandled(); } }
void RenderSnapshottedPlugIn::paint(PaintInfo& paintInfo, const LayoutPoint& paintOffset) { if (plugInImageElement()->displayState() < HTMLPlugInElement::PlayingWithPendingMouseClick) { RenderReplaced::paint(paintInfo, paintOffset); return; } RenderEmbeddedObject::paint(paintInfo, paintOffset); }
void RenderSnapshottedPlugIn::paintReplaced(PaintInfo& paintInfo, const LayoutPoint& paintOffset) { if (plugInImageElement()->displayState() < HTMLPlugInElement::PlayingWithPendingMouseClick) { if (m_shouldShowLabel) paintReplacedSnapshotWithLabel(paintInfo, paintOffset); else paintReplacedSnapshot(paintInfo, paintOffset); return; } RenderEmbeddedObject::paintReplaced(paintInfo, paintOffset); }
void RenderSnapshottedPlugIn::paintReplacedSnapshotWithLabel(PaintInfo& paintInfo, const LayoutPoint& paintOffset) { if (contentBoxRect().isEmpty()) return; if (!plugInImageElement()->hovered() && m_showReason == UserMousedOver) return; m_showedLabelOnce = true; LayoutRect rect = contentBoxRect(); LayoutRect labelRect = tryToFitStartLabel(LabelSizeLarge, rect); LabelSize size = NoLabel; if (!labelRect.isEmpty()) size = LabelSizeLarge; else { labelRect = tryToFitStartLabel(LabelSizeSmall, rect); if (!labelRect.isEmpty()) size = LabelSizeSmall; else return; } Image* labelImage = startLabelImage(size); if (!labelImage) return; RefPtr<Image> snapshotImage = m_snapshotResource->image(); if (!snapshotImage || snapshotImage->isNull()) return; #if ENABLE(FILTERS) RefPtr<Image> blurredSnapshotImage = m_snapshotResourceForLabel->image(); if (!blurredSnapshotImage || blurredSnapshotImage->isNull()) { blurredSnapshotImage = snapshottedPluginImageForLabelDisplay(snapshotImage, labelRect); m_snapshotResourceForLabel->setCachedImage(new CachedImage(blurredSnapshotImage.get())); } snapshotImage = blurredSnapshotImage; #endif paintSnapshot(snapshotImage.get(), paintInfo, paintOffset); // Remember that the labelRect includes the label inset, so we need to adjust for it. paintInfo.context->drawImage(labelImage, ColorSpaceDeviceRGB, IntRect(roundedIntPoint(paintOffset + labelRect.location() - IntSize(startLabelInset, startLabelInset)), roundedIntSize(labelRect.size() + IntSize(2 * startLabelInset, 2 * startLabelInset))), labelImage->rect()); }
void RenderSnapshottedPlugIn::paint(PaintInfo& paintInfo, const LayoutPoint& paintOffset) { if (paintInfo.phase == PaintPhaseForeground && plugInImageElement().displayState() < HTMLPlugInElement::Restarting) { paintSnapshot(paintInfo, paintOffset); } PaintPhase newPhase = (paintInfo.phase == PaintPhaseChildOutlines) ? PaintPhaseOutline : paintInfo.phase; newPhase = (newPhase == PaintPhaseChildBlockBackgrounds) ? PaintPhaseChildBlockBackground : newPhase; PaintInfo paintInfoForChild(paintInfo); paintInfoForChild.phase = newPhase; paintInfoForChild.updateSubtreePaintRootForChildren(this); for (auto& child : childrenOfType<RenderBox>(*this)) { LayoutPoint childPoint = flipForWritingModeForChild(&child, paintOffset); if (!child.hasSelfPaintingLayer() && !child.isFloating()) child.paint(paintInfoForChild, childPoint); } RenderEmbeddedObject::paint(paintInfo, paintOffset); }