From e5054a873eec5b8d2d481447e7830b87c277e6bc Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?R=C3=A9gis=20Brid?=
<36547063+RBrid@users.noreply.github.com>
Date: Tue, 12 Apr 2022 13:04:31 -0700
Subject: [PATCH] TabView continuous expansions fix (#6954)
* Reverting product change made for 'TabView gap between active tab and active content fix #6644'
* TabView expansions fix
---
dev/TabView/TabView.cpp | 10 +-
dev/TabView/TabView.h | 3 +-
dev/TabView/TabView.vcxitems | 1 +
dev/TabView/TabViewItem.cpp | 9 +-
dev/TabView/TabViewItem.h | 1 +
dev/TabView/TabViewTrace.h | 155 +++++++++++++++++++
dev/TabView/TestUI/TabViewPage.xaml | 202 +++++++++++++------------
dev/Telemetry/TraceLogging.h | 5 +-
dev/TestHooks/MUXControlsTestHooks.cpp | 6 +
9 files changed, 283 insertions(+), 109 deletions(-)
create mode 100644 dev/TabView/TabViewTrace.h
diff --git a/dev/TabView/TabView.cpp b/dev/TabView/TabView.cpp
index a72cb85eff..655be6edc5 100755
--- a/dev/TabView/TabView.cpp
+++ b/dev/TabView/TabView.cpp
@@ -21,6 +21,10 @@ static constexpr wstring_view c_tabViewItemMaxWidthName{ L"TabViewItemMaxWidth"s
// TODO: what is the right number and should this be customizable?
static constexpr double c_scrollAmount = 50.0;
+// Change to 'true' to turn on debugging outputs in Output window
+bool TabViewTrace::s_IsDebugOutputEnabled{ false };
+bool TabViewTrace::s_IsVerboseDebugOutputEnabled{ false };
+
TabView::TabView()
{
__RP_Marker_ClassById(RuntimeProfiler::ProfId_TabView);
@@ -968,9 +972,9 @@ void TabView::OnScrollIncreaseClick(const winrt::IInspectable&, const winrt::Rou
winrt::Size TabView::MeasureOverride(winrt::Size const& availableSize)
{
- if (previousAvailableSize.Width != availableSize.Width)
+ if (m_previousAvailableSize.Width != availableSize.Width)
{
- previousAvailableSize = availableSize;
+ m_previousAvailableSize = availableSize;
UpdateTabWidths();
}
@@ -1006,7 +1010,7 @@ void TabView::UpdateTabWidths(bool shouldUpdateWidths, bool fillAllAvailableSpac
if (auto&& tabColumn = m_tabColumn.get())
{
// Note: can be infinite
- const auto availableWidth = previousAvailableSize.Width - widthTaken;
+ const auto availableWidth = m_previousAvailableSize.Width - widthTaken;
// Size can be 0 when window is first created; in that case, skip calculations; we'll get a new size soon
if (availableWidth > 0)
diff --git a/dev/TabView/TabView.h b/dev/TabView/TabView.h
index 5130e23ac0..c92836554d 100755
--- a/dev/TabView/TabView.h
+++ b/dev/TabView/TabView.h
@@ -12,6 +12,7 @@
#include "TabViewTabDroppedOutsideEventArgs.g.h"
#include "TabViewTabDragStartingEventArgs.g.h"
#include "TabViewTabDragCompletedEventArgs.g.h"
+#include "TabViewTrace.h"
#include "DispatcherHelper.h"
static constexpr double c_tabShadowDepth = 16.0;
@@ -218,7 +219,7 @@ class TabView :
winrt::hstring m_tabCloseButtonTooltipText{};
- winrt::Size previousAvailableSize{};
+ winrt::Size m_previousAvailableSize{};
bool m_isDragging{ false };
};
diff --git a/dev/TabView/TabView.vcxitems b/dev/TabView/TabView.vcxitems
index ee6b1e1220..cd6f83e39b 100644
--- a/dev/TabView/TabView.vcxitems
+++ b/dev/TabView/TabView.vcxitems
@@ -20,6 +20,7 @@
+
diff --git a/dev/TabView/TabViewItem.cpp b/dev/TabView/TabViewItem.cpp
index c99ef5981c..fd473f0580 100644
--- a/dev/TabView/TabViewItem.cpp
+++ b/dev/TabView/TabViewItem.cpp
@@ -104,6 +104,9 @@ void TabViewItem::OnApplyTemplate()
void TabViewItem::UpdateTabGeometry()
{
auto const templateSettings = winrt::get_self(TabViewTemplateSettings());
+ auto const scaleFactor = SharedHelpers::Is19H1OrHigher() ?
+ static_cast(XamlRoot().RasterizationScale()) :
+ static_cast(winrt::DisplayInformation::GetForCurrentView().RawPixelsPerViewPixel());
auto const height = ActualHeight();
auto const popupRadius = unbox_value(ResourceAccessor::ResourceLookup(*this, box_value(c_overlayCornerRadiusKey)));
@@ -115,11 +118,11 @@ void TabViewItem::UpdateTabGeometry()
WCHAR strOut[1024];
StringCchPrintf(strOut, ARRAYSIZE(strOut), data,
- height - 1,
+ height - 1.0f / scaleFactor,
leftCorner, leftCorner, leftCorner, leftCorner, leftCorner,
- ActualWidth() - (leftCorner + rightCorner),
+ ActualWidth() - (leftCorner + rightCorner + 1.0f / scaleFactor),
rightCorner, rightCorner, rightCorner, rightCorner,
- height - (4 + rightCorner + 1));
+ height - (4 + rightCorner + 1.0f / scaleFactor));
const auto geometry = winrt::XamlReader::Load(strOut).try_as();
diff --git a/dev/TabView/TabViewItem.h b/dev/TabView/TabViewItem.h
index 98ef944c01..5b4abc1b67 100755
--- a/dev/TabView/TabViewItem.h
+++ b/dev/TabView/TabViewItem.h
@@ -11,6 +11,7 @@
#include "TabViewItem.properties.h"
#include "TabViewItemAutomationPeer.h"
#include "TabViewItemTemplateSettings.h"
+#include "TabViewTrace.h"
class TabViewItem :
public ReferenceTracker,
diff --git a/dev/TabView/TabViewTrace.h b/dev/TabView/TabViewTrace.h
new file mode 100644
index 0000000000..f19b8d49e2
--- /dev/null
+++ b/dev/TabView/TabViewTrace.h
@@ -0,0 +1,155 @@
+// Copyright (c) Microsoft Corporation. All rights reserved.
+// Licensed under the MIT License. See LICENSE in the project root for license information.
+
+#pragma once
+
+#include "common.h"
+#include "TraceLogging.h"
+#include "Utils.h"
+#include "MUXControlsTestHooks.h"
+
+inline bool IsTabViewTracingEnabled()
+{
+ return g_IsLoggingProviderEnabled &&
+ g_LoggingProviderLevel >= WINEVENT_LEVEL_INFO &&
+ (g_LoggingProviderMatchAnyKeyword & KEYWORD_TABVIEW || g_LoggingProviderMatchAnyKeyword == 0);
+}
+
+inline bool IsTabViewVerboseTracingEnabled()
+{
+ return g_IsLoggingProviderEnabled &&
+ g_LoggingProviderLevel >= WINEVENT_LEVEL_VERBOSE &&
+ (g_LoggingProviderMatchAnyKeyword & KEYWORD_TABVIEW || g_LoggingProviderMatchAnyKeyword == 0);
+}
+
+inline bool IsTabViewPerfTracingEnabled()
+{
+ return g_IsPerfProviderEnabled &&
+ g_PerfProviderLevel >= WINEVENT_LEVEL_INFO &&
+ (g_PerfProviderMatchAnyKeyword & KEYWORD_TABVIEW || g_PerfProviderMatchAnyKeyword == 0);
+}
+
+#define TABVIEW_TRACE_INFO_ENABLED(includeTraceLogging, sender, message, ...) \
+TabViewTrace::TraceInfo(includeTraceLogging, sender, message, __VA_ARGS__); \
+
+#define TABVIEW_TRACE_INFO(sender, message, ...) \
+if (IsTabViewTracingEnabled()) \
+{ \
+ TABVIEW_TRACE_INFO_ENABLED(true /*includeTraceLogging*/, sender, message, __VA_ARGS__); \
+} \
+else if (TabViewTrace::s_IsDebugOutputEnabled || TabViewTrace::s_IsVerboseDebugOutputEnabled) \
+{ \
+ TABVIEW_TRACE_INFO_ENABLED(false /*includeTraceLogging*/, sender, message, __VA_ARGS__); \
+} \
+
+#define TABVIEW_TRACE_VERBOSE_ENABLED(includeTraceLogging, sender, message, ...) \
+TabViewTrace::TraceVerbose(includeTraceLogging, sender, message, __VA_ARGS__); \
+
+#define TABVIEW_TRACE_VERBOSE(sender, message, ...) \
+if (IsTabViewVerboseTracingEnabled()) \
+{ \
+ TABVIEW_TRACE_VERBOSE_ENABLED(true /*includeTraceLogging*/, sender, message, __VA_ARGS__); \
+} \
+else if (TabViewTrace::s_IsVerboseDebugOutputEnabled) \
+{ \
+ TABVIEW_TRACE_VERBOSE_ENABLED(false /*includeTraceLogging*/, sender, message, __VA_ARGS__); \
+} \
+
+#define TABVIEW_TRACE_PERF(info) \
+if (IsTabViewPerfTracingEnabled()) \
+{ \
+ TabViewTrace::TracePerfInfo(info); \
+} \
+
+class TabViewTrace
+{
+public:
+ static bool s_IsDebugOutputEnabled;
+ static bool s_IsVerboseDebugOutputEnabled;
+
+ static void TraceInfo(bool includeTraceLogging, const winrt::IInspectable& sender, PCWSTR message, ...) noexcept
+ {
+ va_list args;
+ va_start(args, message);
+ WCHAR buffer[384]{};
+ if (SUCCEEDED(StringCchVPrintfW(buffer, ARRAYSIZE(buffer), message, args)))
+ {
+ if (includeTraceLogging)
+ {
+ // TraceViewers
+ // http://toolbox/pef
+ // http://fastetw/index.aspx
+ TraceLoggingWrite(
+ g_hLoggingProvider,
+ "TabViewInfo" /* eventName */,
+ TraceLoggingLevel(WINEVENT_LEVEL_INFO),
+ TraceLoggingKeyword(KEYWORD_TABVIEW),
+ TraceLoggingWideString(buffer, "Message"));
+ }
+
+ if (s_IsDebugOutputEnabled)
+ {
+ OutputDebugStringW(buffer);
+ }
+
+ com_ptr globalTestHooks = MUXControlsTestHooks::GetGlobalTestHooks();
+
+ if (globalTestHooks &&
+ (globalTestHooks->GetLoggingLevelForType(L"TabView") >= WINEVENT_LEVEL_INFO || globalTestHooks->GetLoggingLevelForInstance(sender) >= WINEVENT_LEVEL_INFO))
+ {
+ globalTestHooks->LogMessage(sender, buffer, false /*isVerboseLevel*/);
+ }
+ }
+ va_end(args);
+ }
+
+ static void TraceVerbose(bool includeTraceLogging, const winrt::IInspectable& sender, PCWSTR message, ...) noexcept
+ {
+ va_list args;
+ va_start(args, message);
+ WCHAR buffer[1024]{};
+ const HRESULT hr = StringCchVPrintfW(buffer, ARRAYSIZE(buffer), message, args);
+ if (SUCCEEDED(hr) || hr == HRESULT_FROM_WIN32(ERROR_INSUFFICIENT_BUFFER))
+ {
+ if (includeTraceLogging)
+ {
+ // TraceViewers
+ // http://toolbox/pef
+ // http://fastetw/index.aspx
+ TraceLoggingWrite(
+ g_hLoggingProvider,
+ "TabViewVerbose" /* eventName */,
+ TraceLoggingLevel(WINEVENT_LEVEL_VERBOSE),
+ TraceLoggingKeyword(KEYWORD_TABVIEW),
+ TraceLoggingWideString(buffer, "Message"));
+ }
+
+ if (s_IsDebugOutputEnabled || s_IsVerboseDebugOutputEnabled)
+ {
+ OutputDebugStringW(buffer);
+ }
+
+ com_ptr globalTestHooks = MUXControlsTestHooks::GetGlobalTestHooks();
+
+ if (globalTestHooks &&
+ (globalTestHooks->GetLoggingLevelForType(L"TabView") >= WINEVENT_LEVEL_VERBOSE || globalTestHooks->GetLoggingLevelForInstance(sender) >= WINEVENT_LEVEL_VERBOSE))
+ {
+ globalTestHooks->LogMessage(sender, buffer, true /*isVerboseLevel*/);
+ }
+ }
+ va_end(args);
+ }
+
+ static void TracePerfInfo(PCWSTR info) noexcept
+ {
+ // TraceViewers
+ // http://toolbox/pef
+ // http://fastetw/index.aspx
+ TraceLoggingWrite(
+ g_hPerfProvider,
+ "TabViewPerf" /* eventName */,
+ TraceLoggingLevel(WINEVENT_LEVEL_INFO),
+ TraceLoggingKeyword(KEYWORD_TABVIEW),
+ TraceLoggingWideString(info, "Info"));
+ }
+};
diff --git a/dev/TabView/TestUI/TabViewPage.xaml b/dev/TabView/TestUI/TabViewPage.xaml
index 8d4837fbae..46c68433fa 100644
--- a/dev/TabView/TestUI/TabViewPage.xaml
+++ b/dev/TabView/TestUI/TabViewPage.xaml
@@ -17,109 +17,111 @@
-
-
-
-
-
-
-
-
- Tab Width:
-
-
-
-
+
+
+
+
+
+
+
+
+
+ Tab Width:
+
+
+
+
+
+
+
+
+
+
+
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- Selected Index:
-
-
-
- Tab dropped out:
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ Selected Index:
+
+
+
+
+ Tab dropped out:
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
diff --git a/dev/Telemetry/TraceLogging.h b/dev/Telemetry/TraceLogging.h
index dbd68e3344..bde938c3db 100644
--- a/dev/Telemetry/TraceLogging.h
+++ b/dev/Telemetry/TraceLogging.h
@@ -13,11 +13,12 @@
// Keywords
#define KEYWORD_REPEATER 0x0000000000000001
-#define KEYWORD_SCROLLPRESENTER 0x0000000000000002
+#define KEYWORD_SCROLLPRESENTER 0x0000000000000002
#define KEYWORD_PTR 0x0000000000000004
-#define KEYWORD_SCROLLVIEW 0x0000000000000008
+#define KEYWORD_SCROLLVIEW 0x0000000000000008
#define KEYWORD_SWIPECONTROL 0x0000000000000010
#define KEYWORD_COMMANDBARFLYOUT 0x0000000000000020
+#define KEYWORD_TABVIEW 0x0000000000000040
// Common output formats
#define TRACE_MSG_METH L"%s[0x%p]()\n"
diff --git a/dev/TestHooks/MUXControlsTestHooks.cpp b/dev/TestHooks/MUXControlsTestHooks.cpp
index 22845bc025..845dde539a 100644
--- a/dev/TestHooks/MUXControlsTestHooks.cpp
+++ b/dev/TestHooks/MUXControlsTestHooks.cpp
@@ -22,6 +22,8 @@
#include "RepeaterTrace.h"
#endif
+#include "TabViewTrace.h"
+
/*static*/
UCHAR MUXControlsTestHooks::GetLoggingLevelForType(const wstring_view& type)
{
@@ -99,6 +101,10 @@ void MUXControlsTestHooks::SetOutputDebugStringLevelForTypeImpl(const wstring_vi
RepeaterTrace::s_IsDebugOutputEnabled = isLoggingInfoLevel || isLoggingVerboseLevel;
}
#endif
+ if (type == L"TabView" || type.empty())
+ {
+ TabViewTrace::s_IsDebugOutputEnabled = isLoggingInfoLevel || isLoggingVerboseLevel;
+ }
}
void MUXControlsTestHooks::SetLoggingLevelForTypeImpl(const wstring_view& type, bool isLoggingInfoLevel, bool isLoggingVerboseLevel)