Repository navigation
Expose Text Attributes to UI Automation #10336
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
84bca57
136a548
a7bbf9d
2be632b
84fdf5a
3fa8c95
7c88010
74a645f
2e7895c
96a5551
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -5,6 +5,7 @@ | |
| #include "XamlUiaTextRange.h" | ||
| #include "../types/TermControlUiaTextRange.hpp" | ||
| #include <UIAutomationClient.h> | ||
| #include <UIAutomationCoreApi.h> | ||
|
|
||
| // the same as COR_E_NOTSUPPORTED | ||
| // we don't want to import the CLR headers to get it | ||
|
|
@@ -89,12 +90,52 @@ namespace winrt::Microsoft::Terminal::Control::implementation | |
|
|
||
| winrt::Windows::Foundation::IInspectable XamlUiaTextRange::GetAttributeValue(int32_t textAttributeId) const | ||
| { | ||
| // Copied functionality from Types::UiaTextRange.cpp | ||
| if (textAttributeId == UIA_IsReadOnlyAttributeId) | ||
| // Call the function off of the underlying UiaTextRange. | ||
| VARIANT result; | ||
| THROW_IF_FAILED(_uiaProvider->GetAttributeValue(textAttributeId, &result)); | ||
|
|
||
| // Convert the resulting VARIANT into a format that is consumable by XAML. | ||
| switch (result.vt) | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm surprised that nobody has made a C++ visitor specialization for a variant |
||
| { | ||
| case VT_BSTR: | ||
| { | ||
| return box_value(result.bstrVal); | ||
| } | ||
| case VT_I4: | ||
| { | ||
| // Surprisingly, `long` is _not_ a WinRT type. | ||
| // So we have to use `int32_t` to make sure this is output properly. | ||
| // Otherwise, you'll get "Attribute does not exist" out the other end. | ||
| return box_value<int32_t>(result.lVal); | ||
| } | ||
| case VT_R8: | ||
| { | ||
| return box_value(result.dblVal); | ||
| } | ||
| case VT_BOOL: | ||
| { | ||
| return winrt::box_value(false); | ||
| return box_value<bool>(result.boolVal); | ||
| } | ||
| else | ||
| case VT_UNKNOWN: | ||
| { | ||
| // This one is particularly special. | ||
| // We might return a special value like UiaGetReservedMixedAttributeValue | ||
| // or UiaGetReservedNotSupportedValue. | ||
| // Some text attributes may return a real value, however, none of those | ||
| // are supported at this time. | ||
| // So we need to figure out what was actually intended to be returned. | ||
|
|
||
| com_ptr<IUnknown> mixedAttributeVal; | ||
| UiaGetReservedMixedAttributeValue(mixedAttributeVal.put()); | ||
|
|
||
| if (result.punkVal == mixedAttributeVal.get()) | ||
| { | ||
| return Windows::UI::Xaml::DependencyProperty::UnsetValue(); | ||
| } | ||
|
|
||
| [[fallthrough]]; | ||
| } | ||
| default: | ||
| { | ||
| // We _need_ to return XAML_E_NOT_SUPPORTED here. | ||
| // Returning nullptr is an improper implementation of it being unsupported. | ||
|
|
@@ -103,6 +144,7 @@ namespace winrt::Microsoft::Terminal::Control::implementation | |
| // Magically, this doesn't affect other forms of navigation... | ||
| winrt::throw_hresult(XAML_E_NOT_SUPPORTED); | ||
| } | ||
| } | ||
| } | ||
|
|
||
| void XamlUiaTextRange::GetBoundingRectangles(com_array<double>& returnValue) const | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -27,23 +27,15 @@ const TextBuffer& Terminal::GetTextBuffer() noexcept | |
| return *_buffer; | ||
| } | ||
|
|
||
| // Creating a FontInfo can technically throw (on string allocation) and this is noexcept. | ||
| // That means this will std::terminate. We could come back and make there be a default constructor | ||
| // backup to FontInfo that throws no exceptions and allocates a default FontInfo structure. | ||
| #pragma warning(push) | ||
| #pragma warning(disable : 26447) | ||
| const FontInfo& Terminal::GetFontInfo() noexcept | ||
| { | ||
| // TODO: This font value is only used to check if the font is a raster font. | ||
| // Otherwise, the font is changed with the renderer via TriggerFontChange. | ||
| // The renderer never uses any of the other members from the value returned | ||
| // by this method. | ||
| // We could very likely replace this with just an IsRasterFont method | ||
| // (which would return false) | ||
| static const FontInfo _fakeFontInfo(DEFAULT_FONT_FACE, TMPF_TRUETYPE, 10, { 0, DEFAULT_FONT_SIZE }, CP_UTF8, false); | ||
| return _fakeFontInfo; | ||
| return _fontInfo; | ||
| } | ||
|
|
||
| void Terminal::SetFontInfo(const FontInfo& fontInfo) | ||
| { | ||
| _fontInfo = fontInfo; | ||
| } | ||
|
Comment on lines
+35
to
38
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Wait hold up wat.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We specifically need this to get the font name (already in this PR) and the font size (excluded from this PR). What's annoying is that this is a Terminal-specific issue too. ConHost returns an actual thing in
What if we double down on this info being stored in TerminalCore? And anytime ControlCore needs something from it, it has to call
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
The need for it was solely to get the renderer to "do the right thing". The terminal actually didn't need to know anything about its font at any point other than rendering. All it did was jog the renderer into knowing that it was, in fact, not rendering a raster font. Why we cared about that, I will never know. |
||
| #pragma warning(pop) | ||
|
|
||
| const TextAttribute Terminal::GetDefaultBrushColors() noexcept | ||
| { | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.