summaryrefslogtreecommitdiffstats
path: root/ash/host/ash_window_tree_host.cc
blob: 0bc59558f36effcf81d2c04348067faf9a6147e0 (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
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
// Copyright 2014 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 "ash/host/ash_window_tree_host.h"

#include "ash/host/ash_window_tree_host_init_params.h"
#include "ash/host/ash_window_tree_host_unified.h"
#include "ui/aura/client/screen_position_client.h"
#include "ui/aura/window_tree_host.h"
#include "ui/events/event.h"
#include "ui/gfx/geometry/rect.h"

#if defined(USE_OZONE)
#include "ash/host/ash_window_tree_host_platform.h"
#elif defined(USE_X11)
#include "ash/host/ash_window_tree_host_x11.h"
#elif defined(OS_WIN)
#include "ash/host/ash_window_tree_host_win.h"
#endif

namespace ash {

namespace {

AshWindowTreeHost::Factory creation_factory;

}  // namespace

AshWindowTreeHost::AshWindowTreeHost() : input_method_handler_(nullptr) {
}

void AshWindowTreeHost::TranslateLocatedEvent(ui::LocatedEvent* event) {
  if (event->IsTouchEvent())
    return;

  aura::WindowTreeHost* wth = AsWindowTreeHost();
  aura::Window* root_window = wth->window();
  aura::client::ScreenPositionClient* screen_position_client =
      aura::client::GetScreenPositionClient(root_window);
  gfx::Rect local(wth->GetBounds().size());
  local.Inset(GetHostInsets());

  if (screen_position_client && !local.Contains(event->location())) {
    gfx::Point location(event->location());
    // In order to get the correct point in screen coordinates
    // during passive grab, we first need to find on which host window
    // the mouse is on, and find out the screen coordinates on that
    // host window, then convert it back to this host window's coordinate.
    screen_position_client->ConvertHostPointToScreen(root_window, &location);
    screen_position_client->ConvertPointFromScreen(root_window, &location);
    wth->ConvertPointToHost(&location);
    event->set_location(location);
    event->set_root_location(location);
  }
}

// static
AshWindowTreeHost* AshWindowTreeHost::Create(
    const AshWindowTreeHostInitParams& init_params) {
  if (!creation_factory.is_null())
    return creation_factory.Run(init_params);

  if (init_params.offscreen)
    return new AshWindowTreeHostUnified(init_params.initial_bounds);
#if defined(USE_OZONE)
  return new AshWindowTreeHostPlatform(init_params.initial_bounds);
#elif defined(USE_X11)
  return new AshWindowTreeHostX11(init_params.initial_bounds);
#elif defined(OS_WIN)
  return new AshWindowTreeHostWin(init_params.initial_bounds);
#else
#error Unsupported platform.
#endif
}

// static
void AshWindowTreeHost::SetFactory(const Factory& factory) {
  creation_factory = factory;
}

}  // namespace ash