#include "ui/base/pointer/touch_ui_controller.h"
#include <memory>
#include <string>
#include "base/command_line.h"
#include "base/functional/bind.h"
#include "base/metrics/histogram_functions.h"
#include "base/metrics/user_metrics.h"
#include "base/no_destructor.h"
#include "base/task/current_thread.h"
#include "base/trace_event/trace_event.h"
#include "ui/base/ui_base_switches.h"
#if BUILDFLAG(IS_WIN)
#include "base/win/win_util.h"
#include "ui/gfx/win/singleton_hwnd.h"
#include "ui/gfx/win/singleton_hwnd_observer.h"
#endif
namespace ui {
namespace {
#if BUILDFLAG(USE_BLINK)
void RecordPointerDigitizerTypeOnStartup(const PointerDevice& device) { … }
void RecordPointerDigitizerTypeOnConnected(const PointerDevice& device) { … }
void RecordPointerDigitizerTypeOnDisconnected(const PointerDevice& device) { … }
void RecordMaxTouchPointsHistogram(const char* histogram_name, int32_t sample) { … }
constexpr const char* GetMaxTouchPointsHistogramName(
PointerDigitizerType type) { … }
void RecordPointerDigitizerTypeMaxTouchPoints(const PointerDevice& device) { … }
void RecordMaxTouchPointsSupportedBySystem(int max_touch_points) { … }
#endif
#if BUILDFLAG(IS_WIN)
bool IsTabletMode() {
return base::win::IsWindows10OrGreaterTabletMode(
gfx::SingletonHwnd::GetInstance()->hwnd());
}
bool IsWndProcMessageObserved(UINT message) {
#if BUILDFLAG(USE_BLINK)
return message == WM_SETTINGCHANGE || message == WM_POINTERDEVICECHANGE;
#elif
return message == WM_SETTINGCHANGE;
#endif
}
void SequencedWndProcHandler(UINT message, WPARAM wparam, LPARAM lparam) {
switch (message) {
case WM_SETTINGCHANGE:
TouchUiController::Get()->OnTabletModeToggled(IsTabletMode());
break;
#if BUILDFLAG(USE_BLINK)
case WM_POINTERDEVICECHANGE:
if (wparam == PDC_ARRIVAL) {
TouchUiController::Get()->OnPointerDeviceConnected(
reinterpret_cast<HANDLE>(lparam));
} else if (wparam == PDC_REMOVAL) {
TouchUiController::Get()->OnPointerDeviceDisconnected(
reinterpret_cast<HANDLE>(lparam));
}
break;
#endif
default:
NOTREACHED();
}
}
void OnWndProc(HWND hwnd, UINT message, WPARAM wparam, LPARAM lparam) {
if (!IsWndProcMessageObserved(message)) {
return;
}
base::SequencedTaskRunner::GetCurrentDefault()->PostTask(
FROM_HERE,
base::BindOnce(&SequencedWndProcHandler, message, wparam, lparam));
}
#endif
void RecordEnteredTouchMode() { … }
void RecordEnteredNonTouchMode() { … }
}
TouchUiController::TouchUiScoperForTesting::TouchUiScoperForTesting(
bool enabled,
TouchUiController* controller)
: … { … }
TouchUiController::TouchUiScoperForTesting::~TouchUiScoperForTesting() { … }
void TouchUiController::TouchUiScoperForTesting::UpdateState(bool enabled) { … }
TouchUiController* TouchUiController::Get() { … }
TouchUiController::TouchUiController(TouchUiState touch_ui_state)
: … { … }
TouchUiController::~TouchUiController() = default;
void TouchUiController::OnTabletModeToggled(bool enabled) { … }
base::CallbackListSubscription TouchUiController::RegisterCallback(
const base::RepeatingClosure& closure) { … }
TouchUiController::TouchUiState TouchUiController::SetTouchUiState(
TouchUiState touch_ui_state) { … }
void TouchUiController::TouchUiChanged() { … }
#if BUILDFLAG(USE_BLINK)
void TouchUiController::OnPointerDeviceConnected(PointerDevice::Key key) { … }
void TouchUiController::OnPointerDeviceDisconnected(PointerDevice::Key key) { … }
int TouchUiController::MaxTouchPoints() const { … }
std::optional<PointerDevice> TouchUiController::GetPointerDevice(
PointerDevice::Key key) const { … }
std::vector<PointerDevice> TouchUiController::GetPointerDevices() const { … }
const std::vector<PointerDevice>&
TouchUiController::GetLastKnownPointerDevicesForTesting() const { … }
void TouchUiController::OnInitializePointerDevices() { … }
#endif
}