1
    2
    3
    4
    5
    6
    7
    8
    9
   10
   11
   12
   13
   14
   15
   16
   17
   18
   19
   20
   21
   22
   23
   24
   25
   26
   27
   28
   29
   30
   31
   32
   33
   34
   35
   36
   37
   38
   39
   40
   41
   42
   43
   44
   45
   46
   47
   48
   49
   50
   51
   52
   53
   54
   55
   56
   57
   58
   59
   60
   61
   62
   63
   64
   65
   66
   67
   68
   69
   70
   71
   72
   73
   74
   75
   76
   77
   78
   79
   80
   81
   82
   83
   84
   85
   86
   87

content / browser / renderer_host / direct_manipulation_test_helper_win.h [blame]

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

#ifndef CONTENT_BROWSER_RENDERER_HOST_DIRECT_MANIPULATION_TEST_HELPER_WIN_H_
#define CONTENT_BROWSER_RENDERER_HOST_DIRECT_MANIPULATION_TEST_HELPER_WIN_H_

#include <windows.h>

#include <directmanipulation.h>
#include <wrl.h>

#include <array>

namespace content {
class PrecisionTouchpadBrowserTest;

// Size of the |transforms_| array. The DirectManipulationContent API specifies
// that the size is always 6 for direct manipulation transforms.
static constexpr int kTransformMatrixSize = 6;

// This class is used for setting up mock content to be used for testing direct
// manipulation and precision touchpad code paths. Most of its methods aren't
// used, and its only real purpose is to store, update, and provide the
// transforms scale, scroll_x, and scroll_y.
class MockDirectManipulationContent
    : public Microsoft::WRL::RuntimeClass<
          Microsoft::WRL::RuntimeClassFlags<
              Microsoft::WRL::RuntimeClassType::ClassicCom>,
          Microsoft::WRL::Implements<
              Microsoft::WRL::RuntimeClassFlags<
                  Microsoft::WRL::RuntimeClassType::ClassicCom>,
              Microsoft::WRL::FtmBase,
              IDirectManipulationContent>> {
 public:
  MockDirectManipulationContent();

  MockDirectManipulationContent(const MockDirectManipulationContent&) = delete;
  MockDirectManipulationContent& operator=(
      const MockDirectManipulationContent&) = delete;

  // IDirectManipulationContent:
  ~MockDirectManipulationContent() override;

  void SetContentTransform(float scale, float scroll_x, float scroll_y);

  // IDirectManipulationContent:
  HRESULT STDMETHODCALLTYPE GetContentTransform(float* transforms,
                                                DWORD point_count) override;

  // Other Overrides, also from IDirectManipulationContent
  HRESULT STDMETHODCALLTYPE GetContentRect(RECT* contentSize) override;

  HRESULT STDMETHODCALLTYPE SetContentRect(const RECT* contentSize) override;

  HRESULT STDMETHODCALLTYPE GetViewport(REFIID riid, void** object) override;

  HRESULT STDMETHODCALLTYPE GetTag(REFIID riid,
                                   void** object,
                                   UINT32* id) override;

  HRESULT STDMETHODCALLTYPE SetTag(IUnknown* object, UINT32 id) override;

  HRESULT STDMETHODCALLTYPE GetOutputTransform(float* matrix,
                                               DWORD point_count) override;

  HRESULT STDMETHODCALLTYPE SyncContentTransform(const float* matrix,
                                                 DWORD point_count) override;

 private:
  friend class PrecisionTouchpadBrowserTest;

  // IDirectManipulationContent provides a 3x2 transform matrix, written out
  // flatly as M = [(1,1), (1,2), (2,1), (2,2), (3,1), (3,2)].
  // Each element stores the following information:
  // (1,1) - x scale
  // (1,2) - y rotation (0 when rotation is not allowed, such as in Chromium)
  // (2,1) - x rotation (0 when rotation is not allowed)
  // (2,2) - y scale
  // (3,1) - x offset
  // (3,2) - y offset.
  std::array<float, kTransformMatrixSize> transforms_;
};

}  // namespace content

#endif  // CONTENT_BROWSER_RENDERER_HOST_DIRECT_MANIPULATION_TEST_HELPER_WIN_H_