Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(418)

Unified Diff: third_party/WebKit/Source/core/inspector/InspectorPageAgent.cpp

Issue 2438023003: devtools: Adds Page.getLayoutMetrics. (Closed)
Patch Set: address comments. Created 4 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: third_party/WebKit/Source/core/inspector/InspectorPageAgent.cpp
diff --git a/third_party/WebKit/Source/core/inspector/InspectorPageAgent.cpp b/third_party/WebKit/Source/core/inspector/InspectorPageAgent.cpp
index 0e9e59125c415510332b050f0fc3e2f23be002ac..b2cf4e9ef9bfbce2244c7d4a97079f34cdfc9190 100644
--- a/third_party/WebKit/Source/core/inspector/InspectorPageAgent.cpp
+++ b/third_party/WebKit/Source/core/inspector/InspectorPageAgent.cpp
@@ -44,8 +44,10 @@
#include "core/fetch/ResourceFetcher.h"
#include "core/fetch/ScriptResource.h"
#include "core/frame/FrameHost.h"
+#include "core/frame/FrameView.h"
#include "core/frame/LocalFrame.h"
#include "core/frame/Settings.h"
+#include "core/frame/VisualViewport.h"
#include "core/html/HTMLFrameOwnerElement.h"
#include "core/html/VoidCallback.h"
#include "core/html/imports/HTMLImportLoader.h"
@@ -858,6 +860,43 @@ void InspectorPageAgent::setBlockedEventsWarningThreshold(ErrorString*,
host->settings().setBlockedMainThreadEventsWarningThreshold(threshold);
}
+void InspectorPageAgent::getLayoutMetrics(
+ ErrorString*,
+ std::unique_ptr<protocol::Page::LayoutViewport>* outLayoutViewport,
+ std::unique_ptr<protocol::Page::VisualViewport>* outVisualViewport) {
+ LocalFrame* mainFrame = m_inspectedFrames->root();
+ VisualViewport& visualViewport = mainFrame->host()->visualViewport();
+
+ mainFrame->document()->updateStyleAndLayoutIgnorePendingStylesheets();
+
+ IntRect visibleContents = mainFrame->view()->visibleContentRect();
+ *outLayoutViewport = protocol::Page::LayoutViewport::create()
+ .setPageX(visibleContents.x())
+ .setPageY(visibleContents.y())
+ .setClientWidth(visibleContents.width())
+ .setClientHeight(visibleContents.height())
+ .build();
+
+ FrameView* frameView = mainFrame->view();
+ ScrollOffset pageOffset = frameView->getScrollableArea()->scrollOffset();
+ float pageZoom = mainFrame->pageZoomFactor();
+ FloatRect visibleRect = visualViewport.visibleRect();
+ float scale = visualViewport.scale();
+ float scrollbarWidth = frameView->verticalScrollbarWidth() / scale;
+ float scrollbarHeight = frameView->horizontalScrollbarHeight() / scale;
+
+ *outVisualViewport =
+ protocol::Page::VisualViewport::create()
+ .setOffsetX(adjustScrollForAbsoluteZoom(visibleRect.x(), pageZoom))
+ .setOffsetY(adjustScrollForAbsoluteZoom(visibleRect.y(), pageZoom))
+ .setPageX(adjustScrollForAbsoluteZoom(pageOffset.width(), pageZoom))
+ .setPageY(adjustScrollForAbsoluteZoom(pageOffset.height(), pageZoom))
+ .setClientWidth(visibleRect.width() - scrollbarWidth)
+ .setClientHeight(visibleRect.height() - scrollbarHeight)
+ .setScale(scale)
+ .build();
+}
+
DEFINE_TRACE(InspectorPageAgent) {
visitor->trace(m_inspectedFrames);
visitor->trace(m_inspectorResourceContentLoader);

Powered by Google App Engine
This is Rietveld 408576698