summaryrefslogtreecommitdiff
path: root/chromium/ui/views/drag_utils.cc
blob: dc068c54fd8a8bae1c8fa35df2a09eedfa01b14f (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
// Copyright (c) 2012 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/views/drag_utils.h"

#include "ui/display/display.h"
#include "ui/display/screen.h"
#include "ui/gfx/canvas.h"
#include "ui/gfx/geometry/size.h"
#include "ui/views/widget/widget.h"

namespace views {

float ScaleFactorForDragFromWidget(Widget* widget) {
  float device_scale = 1.0f;
  if (widget && widget->GetNativeView()) {
    gfx::NativeView view = widget->GetNativeView();
    display::Display display =
        display::Screen::GetScreen()->GetDisplayNearestWindow(view);
    device_scale = display.device_scale_factor();
  }
  return device_scale;
}

gfx::Canvas* GetCanvasForDragImage(Widget* widget,
                                   const gfx::Size& canvas_size) {
  float device_scale = ScaleFactorForDragFromWidget(widget);
  return new gfx::Canvas(canvas_size, device_scale, false);
}

}  // namespace views