summaryrefslogtreecommitdiff
path: root/chromium/ui/aura/mus/gesture_synchronizer.cc
blob: ce216f54f3505e0071c959269f6c3a09dc7008d6 (plain)
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
// Copyright 2018 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 "ui/aura/mus/gesture_synchronizer.h"

#include "services/ws/public/mojom/window_tree.mojom.h"
#include "ui/aura/env.h"
#include "ui/aura/mus/window_mus.h"
#include "ui/aura/window.h"
#include "ui/events/gestures/gesture_recognizer.h"

namespace aura {

GestureSynchronizer::GestureSynchronizer(ws::mojom::WindowTree* window_tree)
    : window_tree_(window_tree) {
  Env::GetInstance()->gesture_recognizer()->AddObserver(this);
}

GestureSynchronizer::~GestureSynchronizer() {
  Env::GetInstance()->gesture_recognizer()->RemoveObserver(this);
}

void GestureSynchronizer::OnActiveTouchesCanceledExcept(
    ui::GestureConsumer* not_cancelled) {
  ws::Id not_cancelled_window_id = kInvalidServerId;
  if (not_cancelled) {
    WindowMus* not_cancelled_window =
        WindowMus::Get(static_cast<Window*>(not_cancelled));
    not_cancelled_window_id = not_cancelled_window->server_id();
  }
  window_tree_->CancelActiveTouchesExcept(not_cancelled_window_id);
}

void GestureSynchronizer::OnEventsTransferred(
    ui::GestureConsumer* current_consumer,
    ui::GestureConsumer* new_consumer,
    ui::TransferTouchesBehavior transfer_touches_behavior) {
  WindowMus* current_window =
      WindowMus::Get(static_cast<Window*>(current_consumer));
  WindowMus* new_window = WindowMus::Get(static_cast<Window*>(new_consumer));
  DCHECK(current_window);
  DCHECK(new_window);
  window_tree_->TransferGestureEventsTo(
      current_window->server_id(), new_window->server_id(),
      transfer_touches_behavior == ui::TransferTouchesBehavior::kCancel);
}

void GestureSynchronizer::OnActiveTouchesCanceled(
    ui::GestureConsumer* consumer) {
  WindowMus* window = WindowMus::Get(static_cast<Window*>(consumer));
  window_tree_->CancelActiveTouches(window->server_id());
}

}  // namespace aura