forked from firka/flutter
Eliminate hardcoded scale factor in a11y scroll (flutter/engine#30013)
When performing an accessibilty scroll, the default scroll distance is kSmallScrollIncrement (40 pixels). This value is then multiplied by the system scale factor, as set in the display settings drop-down in the Windows system settings. When we imported the AX tree from Chromium, we hard-coded the system scale factor to 1.0 due to a fair amount of abstraction of the scale factor lookup in their code. This fills it back in. Issue: https://github.com/flutter/flutter/issues/78798
This commit is contained in:
@@ -2390,6 +2390,9 @@ ORIGIN: ../../../flutter/third_party/accessibility/base/win/atl_module.h + ../..
|
||||
TYPE: LicenseType.bsd
|
||||
FILE: ../../../flutter/third_party/accessibility/base/auto_reset.h
|
||||
FILE: ../../../flutter/third_party/accessibility/base/win/atl_module.h
|
||||
FILE: ../../../flutter/third_party/accessibility/base/win/display.cc
|
||||
FILE: ../../../flutter/third_party/accessibility/base/win/display.h
|
||||
FILE: ../../../flutter/third_party/accessibility/base/win/display_unittest.cc
|
||||
FILE: ../../../flutter/third_party/accessibility/base/win/enum_variant.cc
|
||||
FILE: ../../../flutter/third_party/accessibility/base/win/enum_variant.h
|
||||
FILE: ../../../flutter/third_party/accessibility/base/win/enum_variant_unittest.cc
|
||||
|
||||
@@ -81,6 +81,7 @@ if (enable_unittests) {
|
||||
"ax/platform/ax_platform_node_win_unittest.cc",
|
||||
"base/win/dispatch_stub.cc",
|
||||
"base/win/dispatch_stub.h",
|
||||
"base/win/display_unittest.cc",
|
||||
"base/win/scoped_bstr_unittest.cc",
|
||||
"base/win/scoped_safearray_unittest.cc",
|
||||
"base/win/scoped_variant_unittest.cc",
|
||||
|
||||
@@ -99,6 +99,7 @@ source_set("ax") {
|
||||
]
|
||||
libs = [
|
||||
"oleacc.lib",
|
||||
"shcore.lib",
|
||||
"uiautomationcore.lib",
|
||||
]
|
||||
}
|
||||
|
||||
@@ -31,10 +31,12 @@
|
||||
#include "ax_fragment_root_win.h"
|
||||
#include "ax_platform_node_delegate.h"
|
||||
#include "ax_platform_node_delegate_utils_win.h"
|
||||
#include "shellscalingapi.h"
|
||||
#include "uia_registrar_win.h"
|
||||
|
||||
#include "base/logging.h"
|
||||
#include "base/win/atl_module.h"
|
||||
#include "base/win/display.h"
|
||||
#include "gfx/geometry/rect_conversions.h"
|
||||
|
||||
// From ax.constants.mojom
|
||||
@@ -476,9 +478,7 @@ gfx::Vector2d AXPlatformNodeWin::CalculateUIAScrollPoint(
|
||||
|
||||
const HWND hwnd = GetDelegate()->GetTargetForNativeAccessibilityEvent();
|
||||
BASE_DCHECK(hwnd);
|
||||
// TODO(gw280): https://github.com/flutter/flutter/issues/78798
|
||||
// Support scale factors
|
||||
const float scale_factor = 1.0f;
|
||||
const float scale_factor = base::win::GetScaleFactorForHWND(hwnd);
|
||||
const int small_change =
|
||||
base::ClampRound(kSmallScrollIncrement * scale_factor);
|
||||
|
||||
|
||||
@@ -26,6 +26,8 @@ source_set("base") {
|
||||
sources += [
|
||||
"win/atl.h",
|
||||
"win/atl_module.h",
|
||||
"win/display.cc",
|
||||
"win/display.h",
|
||||
"win/enum_variant.cc",
|
||||
"win/enum_variant.h",
|
||||
"win/scoped_bstr.cc",
|
||||
|
||||
59
engine/src/flutter/third_party/accessibility/base/win/display.cc
vendored
Normal file
59
engine/src/flutter/third_party/accessibility/base/win/display.cc
vendored
Normal file
@@ -0,0 +1,59 @@
|
||||
// Copyright (c) 2011 The Chromium Authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
#include "base/win/display.h"
|
||||
|
||||
namespace base {
|
||||
namespace win {
|
||||
|
||||
float GetScaleFactorForHWND(HWND hwnd) {
|
||||
HMONITOR monitor = MonitorFromWindow(hwnd, MONITOR_DEFAULTTONEAREST);
|
||||
DEVICE_SCALE_FACTOR scale_factor = DEVICE_SCALE_FACTOR_INVALID;
|
||||
if (SUCCEEDED(GetScaleFactorForMonitor(monitor, &scale_factor))) {
|
||||
return ScaleFactorToFloat(scale_factor);
|
||||
}
|
||||
return 1.0f;
|
||||
}
|
||||
|
||||
float ScaleFactorToFloat(DEVICE_SCALE_FACTOR scale_factor) {
|
||||
switch (scale_factor) {
|
||||
case SCALE_100_PERCENT:
|
||||
return 1.0f;
|
||||
case SCALE_120_PERCENT:
|
||||
return 1.2f;
|
||||
case SCALE_125_PERCENT:
|
||||
return 1.25f;
|
||||
case SCALE_140_PERCENT:
|
||||
return 1.4f;
|
||||
case SCALE_150_PERCENT:
|
||||
return 1.5f;
|
||||
case SCALE_160_PERCENT:
|
||||
return 1.6f;
|
||||
case SCALE_175_PERCENT:
|
||||
return 1.75f;
|
||||
case SCALE_180_PERCENT:
|
||||
return 1.8f;
|
||||
case SCALE_200_PERCENT:
|
||||
return 2.0f;
|
||||
case SCALE_225_PERCENT:
|
||||
return 2.25f;
|
||||
case SCALE_250_PERCENT:
|
||||
return 2.5f;
|
||||
case SCALE_300_PERCENT:
|
||||
return 3.0f;
|
||||
case SCALE_350_PERCENT:
|
||||
return 3.5f;
|
||||
case SCALE_400_PERCENT:
|
||||
return 4.0f;
|
||||
case SCALE_450_PERCENT:
|
||||
return 4.5f;
|
||||
case SCALE_500_PERCENT:
|
||||
return 5.0f;
|
||||
default:
|
||||
return 1.0f;
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace win
|
||||
} // namespace base
|
||||
23
engine/src/flutter/third_party/accessibility/base/win/display.h
vendored
Normal file
23
engine/src/flutter/third_party/accessibility/base/win/display.h
vendored
Normal file
@@ -0,0 +1,23 @@
|
||||
// Copyright (c) 2011 The Chromium Authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
#ifndef BASE_WIN_DISPLAY_H_
|
||||
#define BASE_WIN_DISPLAY_H_
|
||||
|
||||
#include <windows.h>
|
||||
|
||||
#include <shellscalingapi.h>
|
||||
|
||||
#include "base/base_export.h"
|
||||
|
||||
namespace base {
|
||||
namespace win {
|
||||
|
||||
float GetScaleFactorForHWND(HWND hwnd);
|
||||
float ScaleFactorToFloat(DEVICE_SCALE_FACTOR scale_factor);
|
||||
|
||||
} // namespace win
|
||||
} // namespace base
|
||||
|
||||
#endif // BASE_WIN_DISPLAY_H_
|
||||
32
engine/src/flutter/third_party/accessibility/base/win/display_unittest.cc
vendored
Normal file
32
engine/src/flutter/third_party/accessibility/base/win/display_unittest.cc
vendored
Normal file
@@ -0,0 +1,32 @@
|
||||
// Copyright (c) 2011 The Chromium Authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
#include "base/win/display.h"
|
||||
|
||||
#include "gtest/gtest.h"
|
||||
|
||||
namespace base {
|
||||
namespace win {
|
||||
|
||||
TEST(Display, ScaleFactorToFloat) {
|
||||
EXPECT_EQ(ScaleFactorToFloat(SCALE_100_PERCENT), 1.00f);
|
||||
EXPECT_EQ(ScaleFactorToFloat(SCALE_120_PERCENT), 1.20f);
|
||||
EXPECT_EQ(ScaleFactorToFloat(SCALE_125_PERCENT), 1.25f);
|
||||
EXPECT_EQ(ScaleFactorToFloat(SCALE_140_PERCENT), 1.40f);
|
||||
EXPECT_EQ(ScaleFactorToFloat(SCALE_150_PERCENT), 1.50f);
|
||||
EXPECT_EQ(ScaleFactorToFloat(SCALE_160_PERCENT), 1.60f);
|
||||
EXPECT_EQ(ScaleFactorToFloat(SCALE_175_PERCENT), 1.75f);
|
||||
EXPECT_EQ(ScaleFactorToFloat(SCALE_180_PERCENT), 1.80f);
|
||||
EXPECT_EQ(ScaleFactorToFloat(SCALE_200_PERCENT), 2.00f);
|
||||
EXPECT_EQ(ScaleFactorToFloat(SCALE_225_PERCENT), 2.25f);
|
||||
EXPECT_EQ(ScaleFactorToFloat(SCALE_250_PERCENT), 2.50f);
|
||||
EXPECT_EQ(ScaleFactorToFloat(SCALE_350_PERCENT), 3.50f);
|
||||
EXPECT_EQ(ScaleFactorToFloat(SCALE_400_PERCENT), 4.00f);
|
||||
EXPECT_EQ(ScaleFactorToFloat(SCALE_450_PERCENT), 4.50f);
|
||||
EXPECT_EQ(ScaleFactorToFloat(SCALE_500_PERCENT), 5.00f);
|
||||
EXPECT_EQ(ScaleFactorToFloat(DEVICE_SCALE_FACTOR_INVALID), 1.0f);
|
||||
}
|
||||
|
||||
} // namespace win
|
||||
} // namespace base
|
||||
Reference in New Issue
Block a user