#include "config.h"
#include "MainFrame.h"
#include "Element.h"
#include "EmptyClients.h"
#include "PageConfiguration.h"
#include "PageOverlayController.h"
#include "ScrollLatchingState.h"
#include "Settings.h"
#include "WheelEventDeltaTracker.h"
#include <wtf/NeverDestroyed.h>
#if PLATFORM(MAC)
#include "ServicesOverlayController.h"
#endif
namespace WebCore {
inline MainFrame::MainFrame(Page& page, PageConfiguration& configuration)
: Frame(page, nullptr, *configuration.loaderClientForMainFrame)
, m_selfOnlyRefCount(0)
#if PLATFORM(MAC)
#if ENABLE(SERVICE_CONTROLS) || ENABLE(TELEPHONE_NUMBER_DETECTION)
, m_servicesOverlayController(std::make_unique<ServicesOverlayController>(*this))
#endif
#endif
, m_recentWheelEventDeltaTracker(std::make_unique<WheelEventDeltaTracker>())
, m_pageOverlayController(std::make_unique<PageOverlayController>(*this))
, m_diagnosticLoggingClient(configuration.diagnosticLoggingClient)
{
}
MainFrame::~MainFrame()
{
if (m_diagnosticLoggingClient)
m_diagnosticLoggingClient->mainFrameDestroyed();
}
Ref<MainFrame> MainFrame::create(Page& page, PageConfiguration& configuration)
{
return adoptRef(*new MainFrame(page, configuration));
}
void MainFrame::selfOnlyRef()
{
if (m_selfOnlyRefCount++)
return;
ref();
}
void MainFrame::selfOnlyDeref()
{
ASSERT(m_selfOnlyRefCount);
if (--m_selfOnlyRefCount)
return;
if (hasOneRef())
dropChildren();
deref();
}
DiagnosticLoggingClient& MainFrame::diagnosticLoggingClient() const
{
static NeverDestroyed<EmptyDiagnosticLoggingClient> dummyClient;
if (!settings().diagnosticLoggingEnabled() || !m_diagnosticLoggingClient)
return dummyClient;
return *m_diagnosticLoggingClient;
}
void MainFrame::dropChildren()
{
while (Frame* child = tree().firstChild())
tree().removeChild(child);
}
#if PLATFORM(MAC)
ScrollLatchingState* MainFrame::latchingState()
{
if (m_latchingState.isEmpty())
return nullptr;
return &m_latchingState.last();
}
void MainFrame::pushNewLatchingState()
{
m_latchingState.append(ScrollLatchingState());
}
void MainFrame::resetLatchingState()
{
m_latchingState.clear();
}
void MainFrame::popLatchingState()
{
m_latchingState.removeLast();
}
#endif
}