Pin Chrome's shortcut to the Win10 Start menu on install and OS upgrade.
[chromium-blink-merge.git] / ui / views / drag_utils.cc
blob2597bf2936bc47ddcabfd0214ff6a5d80f657e0e
1 // Copyright (c) 2012 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.
5 #include "ui/views/drag_utils.h"
7 #include "ui/gfx/canvas.h"
8 #include "ui/gfx/display.h"
9 #include "ui/gfx/geometry/size.h"
10 #include "ui/gfx/screen.h"
11 #include "ui/views/widget/widget.h"
13 namespace {
15 float GetDeviceScaleForNativeView(views::Widget* widget) {
16 float device_scale = 1.0f;
17 // The following code should work on other platforms as well. But we do not
18 // yet care about device scale factor on other platforms. So to keep drag and
19 // drop behavior on other platforms un-touched, we wrap this in the #if guard.
20 if (widget && widget->GetNativeView()) {
21 gfx::NativeView view = widget->GetNativeView();
22 gfx::Display display = gfx::Screen::GetScreenFor(view)->
23 GetDisplayNearestWindow(view);
24 device_scale = display.device_scale_factor();
26 return device_scale;
29 } // namespace
31 namespace views {
33 gfx::Canvas* GetCanvasForDragImage(views::Widget* widget,
34 const gfx::Size& canvas_size) {
35 float device_scale = GetDeviceScaleForNativeView(widget);
36 return new gfx::Canvas(canvas_size, device_scale, false);
39 } // namespace views