blob: 9eae9f6472bf0a06d3e7b417f867dbf7213f7eec [file] [log] [blame]
// 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/gfx/canvas.h"
#include "ui/gfx/display.h"
#include "ui/gfx/geometry/size.h"
#include "ui/gfx/screen.h"
#include "ui/views/widget/widget.h"
namespace {
float GetDeviceScaleForNativeView(views::Widget* widget) {
float device_scale = 1.0f;
if (widget && widget->GetNativeView()) {
gfx::NativeView view = widget->GetNativeView();
gfx::Display display =
gfx::Screen::GetScreen()->GetDisplayNearestWindow(view);
device_scale = display.device_scale_factor();
}
return device_scale;
}
} // namespace
namespace views {
gfx::Canvas* GetCanvasForDragImage(views::Widget* widget,
const gfx::Size& canvas_size) {
float device_scale = GetDeviceScaleForNativeView(widget);
return new gfx::Canvas(canvas_size, device_scale, false);
}
} // namespace views