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: + + + + + + + + + + + - - - - - - - - - - - -