Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion source/uwp/Renderer/AdaptiveCardRenderer.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,7 @@
<ClCompile Include="lib\AdaptiveHighlightColorConfig.cpp" />
<ClCompile Include="lib\AdaptiveRequirement.cpp" />
<ClCompile Include="lib\ElementTagContent.cpp" />
<ClCompile Include="lib\LinkButton.cpp" />
<ClCompile Include="lib\XamlHelpers.cpp" />
<ClInclude Include="lib\ActionHelpers.h" />
<ClInclude Include="lib\AdaptiveActionElement.h" />
Expand Down Expand Up @@ -202,6 +203,7 @@
<ClInclude Include="lib\CustomElementWrapper.h" />
<ClInclude Include="lib\DateTimeParser.h" />
<ClInclude Include="lib\ElementTagContent.h" />
<ClInclude Include="lib\LinkButton.h" />
<ClInclude Include="lib\TextHelpers.h" />
<ClInclude Include="lib\InputValue.h" />
<ClInclude Include="lib\MediaHelpers.h" />
Expand Down Expand Up @@ -373,4 +375,4 @@
</ItemGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets" />
</Project>
</Project>
4 changes: 3 additions & 1 deletion source/uwp/Renderer/AdaptiveCardRenderer.vcxproj.filters
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@
<ClCompile Include="lib\AdaptiveRequirement.cpp" />
<ClCompile Include="lib\ActionHelpers.cpp" />
<ClCompile Include="lib\XamlHelpers.cpp" />
<ClCompile Include="lib\LinkButton.cpp" />
</ItemGroup>
<ItemGroup>
<ClInclude Include="lib\AdaptiveCard.h" />
Expand Down Expand Up @@ -234,8 +235,9 @@
<ClInclude Include="lib\AdaptiveFontTypesDefinition.h" />
<ClInclude Include="lib\AdaptiveRequirement.h" />
<ClInclude Include="lib\ActionHelpers.h" />
<ClInclude Include="lib\LinkButton.h" />
</ItemGroup>
<ItemGroup>
<Midl Include="idl\AdaptiveCards.Rendering.Uwp.idl" />
</ItemGroup>
</Project>
</Project>
30 changes: 22 additions & 8 deletions source/uwp/Renderer/lib/ActionHelpers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
#include "AdaptiveImage.h"
#include "AdaptiveRenderArgs.h"
#include "AdaptiveShowCardActionRenderer.h"
#include "LinkButton.h"

using namespace Microsoft::WRL;
using namespace Microsoft::WRL::Wrappers;
Expand Down Expand Up @@ -58,8 +59,9 @@ namespace AdaptiveNamespace::ActionHelpers

ComPtr<IButton> localButton(button);
ComPtr<IAutomationPropertiesStatics> automationProperties;
THROW_IF_FAILED(GetActivationFactory(
HStringReference(RuntimeClass_Windows_UI_Xaml_Automation_AutomationProperties).Get(), &automationProperties));
THROW_IF_FAILED(
GetActivationFactory(HStringReference(RuntimeClass_Windows_UI_Xaml_Automation_AutomationProperties).Get(),
&automationProperties));
ComPtr<IDependencyObject> buttonAsDependencyObject;
THROW_IF_FAILED(localButton.As(&buttonAsDependencyObject));
THROW_IF_FAILED(automationProperties->SetName(buttonAsDependencyObject.Get(), title.Get()));
Expand Down Expand Up @@ -274,10 +276,25 @@ namespace AdaptiveNamespace::ActionHelpers
_In_ IAdaptiveRenderArgs* renderArgs,
_Outptr_ IUIElement** actionControl)
{
// Render a button for the action
// determine what type of action we're building
ComPtr<IAdaptiveActionElement> action(adaptiveActionElement);
ComPtr<IButton> button =
XamlHelpers::CreateXamlClass<IButton>(HStringReference(RuntimeClass_Windows_UI_Xaml_Controls_Button));
ABI::AdaptiveNamespace::ActionType actionType;
RETURN_IF_FAILED(action->get_ActionType(&actionType));

// now construct an appropriate button for the action type
ComPtr<IButton> button;
if (actionType == ABI::AdaptiveNamespace::ActionType_OpenUrl)
{
// OpenUrl buttons should appear as links for accessibility purposes, so we use our custom LinkButton.
auto linkButton = winrt::make<LinkButton>();
button = linkButton.as<IButton>().detach();

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

button = linkButton.as().detach [](start = 11, length = 41)

Can we just add some very basic unit tests to test construction etc of the new LinkButton object type? Also how much of manual testing should we try for this? ANy backcompat issues that you anticipate at all ?

}

if (!button)
{
// Either non-OpenUrl action or instantiating LinkButton failed. Use standard button.
button = XamlHelpers::CreateXamlClass<IButton>(HStringReference(RuntimeClass_Windows_UI_Xaml_Controls_Button));
}

ComPtr<IFrameworkElement> buttonFrameworkElement;
RETURN_IF_FAILED(button.As(&buttonFrameworkElement));
Expand Down Expand Up @@ -336,9 +353,6 @@ namespace AdaptiveNamespace::ActionHelpers
allowAboveTitleIconPlacement,
button.Get());

ABI::AdaptiveNamespace::ActionType actionType;
RETURN_IF_FAILED(action->get_ActionType(&actionType));

ComPtr<IAdaptiveShowCardActionConfig> showCardActionConfig;
RETURN_IF_FAILED(actionsConfig->get_ShowCard(&showCardActionConfig));
ABI::AdaptiveNamespace::ActionMode showCardActionMode;
Expand Down
29 changes: 29 additions & 0 deletions source/uwp/Renderer/lib/LinkButton.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
// Copyright (C) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
#include "pch.h"
#include "LinkButton.h"

namespace AdaptiveNamespace
{
winrt::Windows::UI::Xaml::Automation::Peers::AutomationPeer LinkButton::OnCreateAutomationPeer()
{
// instead of the standard ButtonAutomationPeer, use our custom peer
return winrt::make<LinkButtonAutomationPeer>(*this);
}

LinkButtonAutomationPeer::LinkButtonAutomationPeer(LinkButton& linkButton) :
winrt::Windows::UI::Xaml::Automation::Peers::ButtonAutomationPeerT<LinkButtonAutomationPeer>(
linkButton.operator winrt::Windows::UI::Xaml::Controls::Button())
{
}

winrt::Windows::UI::Xaml::Automation::Peers::AutomationControlType LinkButtonAutomationPeer::GetAutomationControlType() const
{
return winrt::Windows::UI::Xaml::Automation::Peers::AutomationControlType::Hyperlink;
}

winrt::Windows::UI::Xaml::Automation::Peers::AutomationControlType LinkButtonAutomationPeer::GetAutomationControlTypeCore() const
{
return winrt::Windows::UI::Xaml::Automation::Peers::AutomationControlType::Hyperlink;
}
}
22 changes: 22 additions & 0 deletions source/uwp/Renderer/lib/LinkButton.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
// Copyright (C) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
#pragma once

namespace AdaptiveNamespace
{
// LinkButton is a templated button that exists strictly to behave as a button but appear as a link for
// accessibility purposes.
struct LinkButton : public winrt::Windows::UI::Xaml::Controls::ButtonT<LinkButton>
{
winrt::Windows::UI::Xaml::Automation::Peers::AutomationPeer OnCreateAutomationPeer();
};

struct LinkButtonAutomationPeer
: public winrt::Windows::UI::Xaml::Automation::Peers::ButtonAutomationPeerT<LinkButtonAutomationPeer>
{
LinkButtonAutomationPeer(LinkButton& linkButton);

winrt::Windows::UI::Xaml::Automation::Peers::AutomationControlType GetAutomationControlType() const;
winrt::Windows::UI::Xaml::Automation::Peers::AutomationControlType GetAutomationControlTypeCore() const;
};
}
6 changes: 6 additions & 0 deletions source/uwp/Renderer/lib/pch.h
Original file line number Diff line number Diff line change
Expand Up @@ -57,3 +57,9 @@
#include <windows.foundation.collections.h>
#include <windows.ui.xaml.shapes.h>
#include <windows.ui.xaml.markup.h>

#include <winrt/base.h>
#include <winrt/Windows.UI.Xaml.Automation.h>
#include <winrt/Windows.UI.Xaml.Automation.Peers.h>
#include <winrt/Windows.UI.Xaml.Controls.h>

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nice! Thanks for getting this done and getting us started on the winrt/cpp route !

#include <winrt/Windows.UI.Xaml.Controls.Primitives.h>