diff options
Diffstat (limited to 'Source/WebKit2/WebProcess/WebCoreSupport/WebInspectorClient.cpp')
-rw-r--r-- | Source/WebKit2/WebProcess/WebCoreSupport/WebInspectorClient.cpp | 185 |
1 files changed, 130 insertions, 55 deletions
diff --git a/Source/WebKit2/WebProcess/WebCoreSupport/WebInspectorClient.cpp b/Source/WebKit2/WebProcess/WebCoreSupport/WebInspectorClient.cpp index 76e0b8d48..02ee1c7bd 100644 --- a/Source/WebKit2/WebProcess/WebCoreSupport/WebInspectorClient.cpp +++ b/Source/WebKit2/WebProcess/WebCoreSupport/WebInspectorClient.cpp @@ -1,5 +1,5 @@ /* - * Copyright (C) 2010 Apple Inc. All rights reserved. + * Copyright (C) 2010, 2014, 2015 Apple Inc. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions @@ -26,133 +26,208 @@ #include "config.h" #include "WebInspectorClient.h" -#if ENABLE(INSPECTOR) - +#include "DrawingArea.h" #include "WebInspector.h" #include "WebPage.h" #include <WebCore/InspectorController.h> +#include <WebCore/MainFrame.h> #include <WebCore/Page.h> +#include <WebCore/PageOverlayController.h> +#include <WebCore/Settings.h> +#include <wtf/CurrentTime.h> -#if ENABLE(REMOTE_INSPECTOR) -#include "WebProcess.h" +#if PLATFORM(IOS) +#include <WebCore/InspectorOverlay.h> #endif using namespace WebCore; namespace WebKit { -void WebInspectorClient::inspectorDestroyed() +class RepaintIndicatorLayerClient final : public GraphicsLayerClient { +public: + RepaintIndicatorLayerClient(WebInspectorClient& inspectorClient) + : m_inspectorClient(inspectorClient) + { + } + virtual ~RepaintIndicatorLayerClient() { } +private: + void notifyAnimationEnded(const GraphicsLayer* layer, const String&) override + { + m_inspectorClient.animationEndedForLayer(layer); + } + + WebInspectorClient& m_inspectorClient; +}; + +WebInspectorClient::WebInspectorClient(WebPage* page) + : m_page(page) + , m_highlightOverlay(nullptr) { - closeInspectorFrontend(); - delete this; } -WebCore::InspectorFrontendChannel* WebInspectorClient::openInspectorFrontend(InspectorController*) +WebInspectorClient::~WebInspectorClient() { - WebPage* inspectorPage = m_page->inspector()->createInspectorPage(); - ASSERT_UNUSED(inspectorPage, inspectorPage); - return this; + for (auto layer : m_paintRectLayers) { + layer->removeFromParent(); + delete layer; + } + + if (m_paintRectOverlay && m_page->mainFrame()) + m_page->mainFrame()->pageOverlayController().uninstallPageOverlay(*m_paintRectOverlay, PageOverlay::FadeMode::Fade); } -void WebInspectorClient::closeInspectorFrontend() +void WebInspectorClient::inspectedPageDestroyed() { - if (m_page->inspector()) - m_page->inspector()->didClose(); + if (WebInspector* inspector = m_page->inspector(WebPage::LazyCreationPolicy::UseExistingOnly)) + inspector->close(); + + delete this; } -void WebInspectorClient::bringFrontendToFront() +Inspector::FrontendChannel* WebInspectorClient::openLocalFrontend(InspectorController* controller) { - m_page->inspector()->bringToFront(); + m_page->inspector()->openFrontendConnection(controller->isUnderTest()); + + return m_page->inspector(); } -void WebInspectorClient::didResizeMainFrame(Frame*) +void WebInspectorClient::bringFrontendToFront() { if (m_page->inspector()) - m_page->inspector()->updateDockingAvailability(); + m_page->inspector()->bringToFront(); } -#if ENABLE(REMOTE_INSPECTOR) -pid_t WebInspectorClient::parentProcessIdentifier() const +void WebInspectorClient::didResizeMainFrame(Frame*) { - return WebProcess::shared().presenterApplicationPid(); + if (m_page->inspector()) + m_page->inspector()->updateDockingAvailability(); } -#endif void WebInspectorClient::highlight() { + if (!m_page->corePage()->settings().acceleratedCompositingEnabled()) + return; + +#if !PLATFORM(IOS) if (!m_highlightOverlay) { - RefPtr<PageOverlay> highlightOverlay = PageOverlay::create(this); - m_highlightOverlay = highlightOverlay.get(); - m_page->installPageOverlay(highlightOverlay.release(), true); + auto highlightOverlay = PageOverlay::create(*this); + m_highlightOverlay = highlightOverlay.ptr(); + m_page->mainFrame()->pageOverlayController().installPageOverlay(WTFMove(highlightOverlay), PageOverlay::FadeMode::Fade); m_highlightOverlay->setNeedsDisplay(); } else { m_highlightOverlay->stopFadeOutAnimation(); m_highlightOverlay->setNeedsDisplay(); } +#else + Highlight highlight; + m_page->corePage()->inspectorController().getHighlight(highlight, InspectorOverlay::CoordinateSystem::Document); + m_page->showInspectorHighlight(highlight); +#endif } void WebInspectorClient::hideHighlight() { - if (m_highlightOverlay) - m_page->uninstallPageOverlay(m_highlightOverlay, true); +#if !PLATFORM(IOS) + if (m_highlightOverlay && m_page->mainFrame()) + m_page->mainFrame()->pageOverlayController().uninstallPageOverlay(*m_highlightOverlay, PageOverlay::FadeMode::Fade); +#else + m_page->hideInspectorHighlight(); +#endif } -bool WebInspectorClient::sendMessageToFrontend(const String& message) +void WebInspectorClient::showPaintRect(const FloatRect& rect) { - WebInspector* inspector = m_page->inspector(); - if (!inspector) - return false; + if (!m_page->corePage()->settings().acceleratedCompositingEnabled()) + return; -#if ENABLE(INSPECTOR_SERVER) - if (inspector->hasRemoteFrontendConnected()) { - inspector->sendMessageToRemoteFrontend(message); - return true; + if (!m_paintRectOverlay) { + m_paintRectOverlay = PageOverlay::create(*this, PageOverlay::OverlayType::Document); + m_page->mainFrame()->pageOverlayController().installPageOverlay(*m_paintRectOverlay, PageOverlay::FadeMode::DoNotFade); } -#endif - WebPage* inspectorPage = inspector->inspectorPage(); - if (inspectorPage) - return doDispatchMessageOnFrontendPage(inspectorPage->corePage(), message); + if (!m_paintIndicatorLayerClient) + m_paintIndicatorLayerClient = std::make_unique<RepaintIndicatorLayerClient>(*this); - return false; + std::unique_ptr<GraphicsLayer> paintLayer = GraphicsLayer::create(m_page->drawingArea()->graphicsLayerFactory(), *m_paintIndicatorLayerClient); + + paintLayer->setName("paint rect"); + paintLayer->setAnchorPoint(FloatPoint3D()); + paintLayer->setPosition(rect.location()); + paintLayer->setSize(rect.size()); + paintLayer->setBackgroundColor(Color(1.0f, 0.0f, 0.0f, 0.2f)); + + KeyframeValueList fadeKeyframes(AnimatedPropertyOpacity); + fadeKeyframes.insert(std::make_unique<FloatAnimationValue>(0, 1)); + + fadeKeyframes.insert(std::make_unique<FloatAnimationValue>(0.25, 0)); + + RefPtr<Animation> opacityAnimation = Animation::create(); + opacityAnimation->setDuration(0.25); + + paintLayer->addAnimation(fadeKeyframes, FloatSize(), opacityAnimation.get(), ASCIILiteral("opacity"), 0); + + m_paintRectLayers.add(paintLayer.get()); + + GraphicsLayer& overlayRootLayer = m_paintRectOverlay->layer(); + overlayRootLayer.addChild(paintLayer.release()); } -bool WebInspectorClient::supportsFrameInstrumentation() +void WebInspectorClient::animationEndedForLayer(const GraphicsLayer* layer) { -#if USE(COORDINATED_GRAPHICS) - return true; -#endif - return false; + const_cast<GraphicsLayer*>(layer)->removeFromParent(); + m_paintRectLayers.remove(const_cast<GraphicsLayer*>(layer)); + delete layer; +} + +#if PLATFORM(IOS) +void WebInspectorClient::showInspectorIndication() +{ + m_page->showInspectorIndication(); +} + +void WebInspectorClient::hideInspectorIndication() +{ + m_page->hideInspectorIndication(); } -void WebInspectorClient::pageOverlayDestroyed(PageOverlay*) +void WebInspectorClient::didSetSearchingForNode(bool enabled) { + if (enabled) + m_page->enableInspectorNodeSearch(); + else + m_page->disableInspectorNodeSearch(); } +#endif -void WebInspectorClient::willMoveToWebPage(PageOverlay*, WebPage* webPage) +void WebInspectorClient::elementSelectionChanged(bool active) { - if (webPage) + if (m_page->inspector()) + m_page->inspector()->elementSelectionChanged(active); +} + +void WebInspectorClient::willMoveToPage(PageOverlay&, Page* page) +{ + if (page) return; // The page overlay is moving away from the web page, reset it. ASSERT(m_highlightOverlay); - m_highlightOverlay = 0; + m_highlightOverlay = nullptr; } -void WebInspectorClient::didMoveToWebPage(PageOverlay*, WebPage*) +void WebInspectorClient::didMoveToPage(PageOverlay&, Page*) { } -void WebInspectorClient::drawRect(PageOverlay*, WebCore::GraphicsContext& context, const WebCore::IntRect& /*dirtyRect*/) +void WebInspectorClient::drawRect(PageOverlay&, WebCore::GraphicsContext& context, const WebCore::IntRect& /*dirtyRect*/) { m_page->corePage()->inspectorController().drawHighlight(context); } -bool WebInspectorClient::mouseEvent(PageOverlay*, const WebMouseEvent&) +bool WebInspectorClient::mouseEvent(PageOverlay&, const PlatformMouseEvent&) { return false; } } // namespace WebKit - -#endif // ENABLE(INSPECTOR) |