point_transformer.cc 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. // Copyright 2014 The Chromium Authors. All rights reserved.
  2. // Use of this source code is governed by a BSD-style license that can be
  3. // found in the LICENSE file.
  4. #include "remoting/host/chromeos/point_transformer.h"
  5. #include "ash/shell.h"
  6. #include "ash/wm/window_util.h"
  7. #include "ui/aura/window_tree_host.h"
  8. #include "ui/compositor/layer.h"
  9. #include "ui/wm/core/coordinate_conversion.h"
  10. namespace remoting {
  11. namespace {
  12. gfx::PointF ConvertScreenDIPToWindowDIP(const aura::Window* window,
  13. gfx::PointF location_in_screen_in_dip) {
  14. gfx::PointF result(location_in_screen_in_dip);
  15. wm::ConvertPointFromScreen(window, &result);
  16. return result;
  17. }
  18. gfx::PointF ConvertWindowDIPToScreenDIP(const aura::Window* window,
  19. gfx::PointF location_in_window_in_dip) {
  20. gfx::PointF result(location_in_window_in_dip);
  21. wm::ConvertPointToScreen(window, &result);
  22. return result;
  23. }
  24. gfx::PointF ConvertWindowDIPtoWindowPixels(
  25. const aura::Window* window,
  26. gfx::PointF location_in_window_in_dip) {
  27. gfx::PointF result(location_in_window_in_dip);
  28. window->GetHost()->ConvertDIPToPixels(&result);
  29. return result;
  30. }
  31. gfx::PointF ConvertWindowPixelsToWindowDIP(
  32. const aura::Window* window,
  33. gfx::PointF location_in_window_in_pixels) {
  34. gfx::PointF result(location_in_window_in_pixels);
  35. window->GetHost()->ConvertPixelsToDIP(&result);
  36. return result;
  37. }
  38. gfx::PointF ConvertWindowPixelsToScreenPixels(
  39. const aura::Window* window,
  40. gfx::PointF location_in_window_in_pixels) {
  41. return location_in_window_in_pixels +
  42. window->GetHost()->GetBoundsInPixels().OffsetFromOrigin();
  43. }
  44. } // namespace
  45. // static
  46. gfx::PointF PointTransformer::ConvertScreenInDipToScreenInPixel(
  47. gfx::PointF location_in_screen_in_dip) {
  48. const aura::Window* window = ash::window_util::GetRootWindowAt(
  49. gfx::ToRoundedPoint(location_in_screen_in_dip));
  50. gfx::PointF location_in_window_in_dip =
  51. ConvertScreenDIPToWindowDIP(window, location_in_screen_in_dip);
  52. gfx::PointF location_in_window_in_pixels =
  53. ConvertWindowDIPtoWindowPixels(window, location_in_window_in_dip);
  54. gfx::PointF location_in_screen_in_pixel =
  55. ConvertWindowPixelsToScreenPixels(window, location_in_window_in_pixels);
  56. return location_in_screen_in_pixel;
  57. }
  58. // static
  59. gfx::PointF PointTransformer::ConvertWindowInPixelToScreenInDip(
  60. const aura::Window* window,
  61. gfx::PointF location_in_window_in_pixels) {
  62. gfx::PointF location_in_window_in_dip =
  63. ConvertWindowPixelsToWindowDIP(window, location_in_window_in_pixels);
  64. gfx::PointF location_in_screen_in_dip =
  65. ConvertWindowDIPToScreenDIP(window, location_in_window_in_dip);
  66. return location_in_screen_in_dip;
  67. }
  68. } // namespace remoting