Skip to content

Commit

Permalink
Revert "Updating CommandBarFlyout's CommandBar to take monitor inform…
Browse files Browse the repository at this point in the history
…ation into account when its popup is windowed."

This reverts commit 564a099.
  • Loading branch information
llongley committed Apr 26, 2021
1 parent 0e1b81d commit 624ba45
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 36 deletions.
35 changes: 10 additions & 25 deletions dev/CommandBarFlyout/CommandBarFlyoutCommandBar.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -491,43 +491,28 @@ void CommandBarFlyoutCommandBar::UpdateVisualState(

// If there isn't enough space to display the overflow below the command bar,
// and if there is enough space above, then we'll display it above instead.
if (m_secondaryItemsRoot)
if (auto window = winrt::Window::Current() && m_secondaryItemsRoot)
{
double availableHeight = -1;
bool isConstrainedToRootBounds = true;
auto controlBounds = TransformToVisual(nullptr).TransformBounds({ 0, 0, static_cast<float>(ActualWidth()), static_cast<float>(ActualHeight()) });
const auto controlBounds = TransformToVisual(nullptr).TransformBounds({ 0, 0, static_cast<float>(ActualWidth()), static_cast<float>(ActualHeight()) });

if (winrt::IFlyoutBase6 owningFlyoutAsFlyoutBase6 = m_owningFlyout.get())
{
isConstrainedToRootBounds = owningFlyoutAsFlyoutBase6.IsConstrainedToRootBounds();
}

if (isConstrainedToRootBounds)
try
{
try
{
auto view = winrt::ApplicationView::GetForCurrentView();
availableHeight = view.VisibleBounds().Height;
}
catch (winrt::hresult_error)
{
// Calling GetForCurrentView on threads without a CoreWindow throws an error. This comes up in places like LogonUI.
// In this circumstance, we'll just always expand down, since we can't get bounds information.
}
// Note: this doesn't work right for islands scenarios
// Bug 19617460: CommandBarFlyoutCommandBar isn't able to decide whether to open up or down because it doesn't know where it is relative to the monitor
auto view = winrt::ApplicationView::GetForCurrentView();
availableHeight = view.VisibleBounds().Height;
}
else
catch (winrt::hresult_error)
{
winrt::IUIElement11 thisAsUIElement11 = try_as<winrt::IUIElement11>();

if (thisAsUIElement11)
{
winrt::Rect monitorBounds = {};
winrt::Point screenOffset = {};
thisAsUIElement11.GetMonitorInformation(monitorBounds, screenOffset);
availableHeight = monitorBounds.Height;
controlBounds.X += screenOffset.X;
controlBounds.Y += screenOffset.Y;
}
// Calling GetForCurrentView on threads without a CoreWindow throws an error. This comes up in places like LogonUI.
// In this circumstance, we'll just always expand down, since we can't get bounds information.
}

if (availableHeight >= 0)
Expand Down
13 changes: 2 additions & 11 deletions dev/CommandBarFlyout/CommandBarFlyoutCommandBar.idl
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
namespace MU_XCP_NAMESPACE
namespace MU_XCP_NAMESPACE
{

[MUX_PUBLIC]
Expand Down Expand Up @@ -39,13 +39,4 @@ unsealed runtimeclass CommandBarFlyoutCommandBar : Windows.UI.Xaml.Controls.Comm
CommandBarFlyoutCommandBarTemplateSettings FlyoutTemplateSettings { get; };
};

// Needed so we can access this interface until it ships in the official SDK.
[MUX_INTERNAL]
[webhosthidden]
[uuid(9e8f35fd-98a5-59ed-bc56-51b565acb335)]
interface IUIElement11
{
void GetMonitorInformation(out Windows.Foundation.Rect monitorBounds, out Windows.Foundation.Point screenPosition);
};

}
}

0 comments on commit 624ba45

Please sign in to comment.