MCPcopy Create free account
hub / github.com/MicrosoftEdge/WebView2Samples / ResizeWebView

Method ResizeWebView

SampleApps/WebView2APISample/ViewComponent.cpp:574–616  ·  view source on GitHub ↗

[ResizeWebView] Update the bounds of the WebView window to fit available space.

Source from the content-addressed store, hash-verified

572//! [ResizeWebView]
573// Update the bounds of the WebView window to fit available space.
574void ViewComponent::ResizeWebView()
575{
576 SIZE webViewSize = {
577 LONG((m_webViewBounds.right - m_webViewBounds.left) * m_webViewRatio * m_webViewScale),
578 LONG((m_webViewBounds.bottom - m_webViewBounds.top) * m_webViewRatio * m_webViewScale) };
579
580 RECT desiredBounds = m_webViewBounds;
581 desiredBounds.bottom = LONG(
582 webViewSize.cy + m_webViewBounds.top);
583 desiredBounds.right = LONG(
584 webViewSize.cx + m_webViewBounds.left);
585
586 m_controller->put_Bounds(desiredBounds);
587 if (m_compositionController)
588 {
589 POINT webViewOffset = {m_webViewBounds.left, m_webViewBounds.top};
590
591 if (m_dcompDevice)
592 {
593 CHECK_FAILURE(m_dcompRootVisual->SetOffsetX(float(webViewOffset.x)));
594 CHECK_FAILURE(m_dcompRootVisual->SetOffsetY(float(webViewOffset.y)));
595 CHECK_FAILURE(m_dcompRootVisual->SetClip(
596 {0, 0, float(webViewSize.cx), float(webViewSize.cy)}));
597 CHECK_FAILURE(m_dcompDevice->Commit());
598 }
599 else if (m_wincompCompositor)
600 {
601 if (m_wincompRootVisual != nullptr)
602 {
603 numerics::float2 size = {static_cast<float>(webViewSize.cx),
604 static_cast<float>(webViewSize.cy)};
605 m_wincompRootVisual.Size(size);
606
607 numerics::float3 offset = {static_cast<float>(webViewOffset.x),
608 static_cast<float>(webViewOffset.y), 0.0f};
609 m_wincompRootVisual.Offset(offset);
610
611 winrtComp::IInsetClip insetClip = m_wincompCompositor.CreateInsetClip();
612 m_wincompRootVisual.Clip(insetClip.as<winrtComp::CompositionClip>());
613 }
614 }
615 }
616}
617//! [ResizeWebView]
618
619// Show the current bounds of the WebView.

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected