blob: 0fd5e5e91c8236fc9c89db09737f309255fe8a35 [file] [log] [blame]
[email protected]36557fd02012-04-03 23:44:511// 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.
4
5#include "ui/views/drag_utils.h"
6
[email protected]de732e802014-03-10 18:12:097#include "ui/gfx/canvas.h"
[email protected]c600edba2012-06-19 21:25:348#include "ui/gfx/display.h"
9#include "ui/gfx/screen.h"
[email protected]de732e802014-03-10 18:12:0910#include "ui/gfx/size.h"
[email protected]c600edba2012-06-19 21:25:3411#include "ui/views/widget/widget.h"
[email protected]1b21d1a82014-04-30 11:19:3212
13namespace {
[email protected]36557fd02012-04-03 23:44:5114
[email protected]50b66262013-09-24 03:25:4815float GetDeviceScaleForNativeView(views::Widget* widget) {
16 float device_scale = 1.0f;
[email protected]c600edba2012-06-19 21:25:3417 // 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()) {
[email protected]ffabb1e2012-10-12 19:51:1721 gfx::NativeView view = widget->GetNativeView();
22 gfx::Display display = gfx::Screen::GetScreenFor(view)->
23 GetDisplayNearestWindow(view);
[email protected]50b66262013-09-24 03:25:4824 device_scale = display.device_scale_factor();
[email protected]c600edba2012-06-19 21:25:3425 }
[email protected]50b66262013-09-24 03:25:4826 return device_scale;
[email protected]c600edba2012-06-19 21:25:3427}
28
[email protected]1b21d1a82014-04-30 11:19:3229} // namespace
[email protected]36557fd02012-04-03 23:44:5130
[email protected]1b21d1a82014-04-30 11:19:3231namespace views {
[email protected]36557fd02012-04-03 23:44:5132
[email protected]c600edba2012-06-19 21:25:3433gfx::Canvas* GetCanvasForDragImage(views::Widget* widget,
34 const gfx::Size& canvas_size) {
[email protected]50b66262013-09-24 03:25:4835 float device_scale = GetDeviceScaleForNativeView(widget);
36 return new gfx::Canvas(canvas_size, device_scale, false);
[email protected]c600edba2012-06-19 21:25:3437}
38
[email protected]36557fd02012-04-03 23:44:5139} // namespace views