chromium/ui/base/pointer/touch_ui_controller.cc

// Copyright 2015 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#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  // BUILDFLAG(USE_BLINK)

#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   // BUILDFLAG(USE_BLINK)
  return message == WM_SETTINGCHANGE;
#endif  // BUILDFLAG(USE_BLINK)
}

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  // BUILDFLAG(USE_BLINK)
    default:
      NOTREACHED();
  }
}

void OnWndProc(HWND hwnd, UINT message, WPARAM wparam, LPARAM lparam) {
  if (!IsWndProcMessageObserved(message)) {
    return;
  }
  // Pass the work to a separate task to avoid possible jank when handling
  // winapi events. This also makes sure events are processed after
  // OnInitializePointerDevices which needs to run before handling
  // WM_POINTERDEVICECHANGE.
  base::SequencedTaskRunner::GetCurrentDefault()->PostTask(
      FROM_HERE,
      base::BindOnce(&SequencedWndProcHandler, message, wparam, lparam));
}

#endif  // BUILDFLAG(IS_WIN)

void RecordEnteredTouchMode() {}

void RecordEnteredNonTouchMode() {}

}  // namespace

TouchUiController::TouchUiScoperForTesting::TouchUiScoperForTesting(
    bool enabled,
    TouchUiController* controller)
    :{}

TouchUiController::TouchUiScoperForTesting::~TouchUiScoperForTesting() {}

void TouchUiController::TouchUiScoperForTesting::UpdateState(bool enabled) {}

// static
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  // BUILDFLAG(USE_BLINK)

}  // namespace ui