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

content / common / input / synthetic_pointer_action_params.cc [blame]

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

#include "content/common/input/synthetic_pointer_action_params.h"

namespace content {

SyntheticPointerActionParams::SyntheticPointerActionParams() = default;

SyntheticPointerActionParams::SyntheticPointerActionParams(
    PointerActionType action_type)
    : pointer_action_type_(action_type),
      button_(action_type == PointerActionType::MOVE ? Button::NO_BUTTON
                                                     : Button::LEFT) {}

SyntheticPointerActionParams::SyntheticPointerActionParams(
    const SyntheticPointerActionParams& other) = default;

SyntheticPointerActionParams::~SyntheticPointerActionParams() = default;

// static
unsigned SyntheticPointerActionParams::GetWebMouseEventModifier(
    SyntheticPointerActionParams::Button button) {
  switch (button) {
    case SyntheticPointerActionParams::Button::LEFT:
      return blink::WebMouseEvent::kLeftButtonDown;
    case SyntheticPointerActionParams::Button::MIDDLE:
      return blink::WebMouseEvent::kMiddleButtonDown;
    case SyntheticPointerActionParams::Button::RIGHT:
      return blink::WebMouseEvent::kRightButtonDown;
    case SyntheticPointerActionParams::Button::BACK:
      return blink::WebMouseEvent::kBackButtonDown;
    case SyntheticPointerActionParams::Button::FORWARD:
      return blink::WebMouseEvent::kForwardButtonDown;
    case SyntheticPointerActionParams::Button::NO_BUTTON:
      return blink::WebMouseEvent::kNoModifiers;
  }
  NOTREACHED_IN_MIGRATION();
  return blink::WebMouseEvent::kNoModifiers;
}

// static
blink::WebMouseEvent::Button
SyntheticPointerActionParams::GetWebMouseEventButton(
    SyntheticPointerActionParams::Button button) {
  switch (button) {
    case SyntheticPointerActionParams::Button::LEFT:
      return blink::WebMouseEvent::Button::kLeft;
    case SyntheticPointerActionParams::Button::MIDDLE:
      return blink::WebMouseEvent::Button::kMiddle;
    case SyntheticPointerActionParams::Button::RIGHT:
      return blink::WebMouseEvent::Button::kRight;
    case SyntheticPointerActionParams::Button::BACK:
      return blink::WebMouseEvent::Button::kBack;
    case SyntheticPointerActionParams::Button::FORWARD:
      return blink::WebMouseEvent::Button::kForward;
    case SyntheticPointerActionParams::Button::NO_BUTTON:
      return blink::WebMouseEvent::Button::kNoButton;
  }
  NOTREACHED_IN_MIGRATION();
  return blink::WebMouseEvent::Button::kNoButton;
}

// static
blink::WebMouseEvent::Button
SyntheticPointerActionParams::GetWebMouseEventButtonFromModifier(
    unsigned modifiers) {
  blink::WebMouseEvent::Button button = blink::WebMouseEvent::Button::kNoButton;
  if (modifiers & blink::WebMouseEvent::kLeftButtonDown)
    button = blink::WebMouseEvent::Button::kLeft;
  if (modifiers & blink::WebMouseEvent::kMiddleButtonDown)
    button = blink::WebMouseEvent::Button::kMiddle;
  if (modifiers & blink::WebMouseEvent::kRightButtonDown)
    button = blink::WebMouseEvent::Button::kRight;
  return button;
}

}  // namespace content