Skip to content

Commit

Permalink
Fix UiaTextRange Misaligned Bounding Rects (#4497)
Browse files Browse the repository at this point in the history
## Summary of the Pull Request
Forgot to include the scaling factor. Also went ahead and used chromium math for this portion.

## References

<!-- Please review the items on the PR checklist before submitting-->
## PR Checklist
* [x] Closes #2551
* [x] CLA signed.

## Validation Steps Performed
Tested on 200% display and 100% display. Rects are aligned on both.
  • Loading branch information
carlos-zamora authored Feb 11, 2020
1 parent a241dbd commit 3b58e04
Showing 1 changed file with 46 additions and 7 deletions.
53 changes: 46 additions & 7 deletions src/cascadia/TerminalControl/UiaTextRange.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
using namespace Microsoft::Terminal;
using namespace Microsoft::Console::Types;
using namespace Microsoft::WRL;
using namespace winrt::Windows::Graphics::Display;

HRESULT UiaTextRange::GetSelectionRanges(_In_ IUiaData* pData,
_In_ IRawElementProviderSimple* pProvider,
Expand Down Expand Up @@ -121,21 +122,59 @@ void UiaTextRange::_TranslatePointToScreen(LPPOINT clientPoint) const
{
auto provider = static_cast<TermControlUiaProvider*>(_pProvider);

auto includeOffsets = [](long clientPos, double termControlPos, double padding, double scaleFactor) {
auto result = base::ClampedNumeric<double>(clientPos);
result += padding;
result *= scaleFactor;
result += termControlPos;
return result;
};

// update based on TermControl location (important for Panes)
UiaRect boundingRect;
THROW_IF_FAILED(provider->get_BoundingRectangle(&boundingRect));
clientPoint->x += gsl::narrow<LONG>(boundingRect.left);
clientPoint->y += gsl::narrow<LONG>(boundingRect.top);

// update based on TermControl padding
auto padding = provider->GetPadding();
clientPoint->x += gsl::narrow<LONG>(padding.Left);
clientPoint->y += gsl::narrow<LONG>(padding.Top);
const auto padding = provider->GetPadding();

// Get scale factor for display
const auto scaleFactor = DisplayInformation::GetForCurrentView().RawPixelsPerViewPixel();

clientPoint->x = includeOffsets(clientPoint->x, boundingRect.left, padding.Left, scaleFactor);
clientPoint->y = includeOffsets(clientPoint->y, boundingRect.top, padding.Top, scaleFactor);
}

void UiaTextRange::_TranslatePointFromScreen(LPPOINT /*screenPoint*/) const
// Method Description:
// - Transform coordinates relative to the screen to relative to the client
// Arguments:
// - screenPoint: coordinates relative to the screen where
// (0,0) is the top-left of the screen
// Return Value:
// - <none>
void UiaTextRange::_TranslatePointFromScreen(LPPOINT screenPoint) const
{
// TODO GitHub #2103: NON-HWND IMPLEMENTATION OF SCREENTOCLIENT()
auto provider = static_cast<TermControlUiaProvider*>(_pProvider);

auto includeOffsets = [](long screenPos, double termControlPos, double padding, double scaleFactor) {
auto result = base::ClampedNumeric<double>(screenPos);
result -= termControlPos;
result /= scaleFactor;
result -= padding;
return result;
};

// update based on TermControl location (important for Panes)
UiaRect boundingRect;
THROW_IF_FAILED(provider->get_BoundingRectangle(&boundingRect));

// update based on TermControl padding
const auto padding = provider->GetPadding();

// Get scale factor for display
const auto scaleFactor = DisplayInformation::GetForCurrentView().RawPixelsPerViewPixel();

screenPoint->x = includeOffsets(screenPoint->x, boundingRect.left, padding.Left, scaleFactor);
screenPoint->y = includeOffsets(screenPoint->y, boundingRect.top, padding.Top, scaleFactor);
}

const COORD UiaTextRange::_getScreenFontSize() const
Expand Down

0 comments on commit 3b58e04

Please sign in to comment.