| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "ash/drag_drop/drag_image_view.h" | 5 #include "ash/drag_drop/drag_image_view.h" |
| 6 | 6 |
| 7 #include <memory> | 7 #include <memory> |
| 8 | 8 |
| 9 #include "ash/public/cpp/shell_window_ids.h" | 9 #include "ash/public/cpp/shell_window_ids.h" |
| 10 #include "ash/root_window_controller.h" | 10 #include "ash/root_window_controller.h" |
| 11 #include "ash/wm_window.h" | |
| 12 #include "skia/ext/image_operations.h" | 11 #include "skia/ext/image_operations.h" |
| 12 #include "ui/aura/window.h" |
| 13 #include "ui/base/resource/resource_bundle.h" | 13 #include "ui/base/resource/resource_bundle.h" |
| 14 #include "ui/display/display.h" | 14 #include "ui/display/display.h" |
| 15 #include "ui/display/screen.h" |
| 15 #include "ui/gfx/canvas.h" | 16 #include "ui/gfx/canvas.h" |
| 16 #include "ui/resources/grit/ui_resources.h" | 17 #include "ui/resources/grit/ui_resources.h" |
| 17 #include "ui/views/widget/widget.h" | 18 #include "ui/views/widget/widget.h" |
| 18 | 19 |
| 19 namespace ash { | 20 namespace ash { |
| 20 namespace { | 21 namespace { |
| 21 using views::Widget; | 22 using views::Widget; |
| 22 | 23 |
| 23 std::unique_ptr<Widget> CreateDragWidget(WmWindow* root_window) { | 24 std::unique_ptr<Widget> CreateDragWidget(aura::Window* root_window) { |
| 24 std::unique_ptr<Widget> drag_widget(new Widget); | 25 std::unique_ptr<Widget> drag_widget(new Widget); |
| 25 Widget::InitParams params; | 26 Widget::InitParams params; |
| 26 params.type = Widget::InitParams::TYPE_TOOLTIP; | 27 params.type = Widget::InitParams::TYPE_TOOLTIP; |
| 27 params.name = "DragWidget"; | 28 params.name = "DragWidget"; |
| 28 params.keep_on_top = true; | 29 params.keep_on_top = true; |
| 29 params.accept_events = false; | 30 params.accept_events = false; |
| 30 params.ownership = Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET; | 31 params.ownership = Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET; |
| 31 params.shadow_type = Widget::InitParams::SHADOW_TYPE_NONE; | 32 params.shadow_type = Widget::InitParams::SHADOW_TYPE_NONE; |
| 32 params.opacity = Widget::InitParams::TRANSLUCENT_WINDOW; | 33 params.opacity = Widget::InitParams::TRANSLUCENT_WINDOW; |
| 33 root_window->GetRootWindowController()->ConfigureWidgetInitParamsForContainer( | 34 RootWindowController::ForWindow(root_window) |
| 34 drag_widget.get(), kShellWindowId_DragImageAndTooltipContainer, ¶ms); | 35 ->ConfigureWidgetInitParamsForContainer( |
| 36 drag_widget.get(), kShellWindowId_DragImageAndTooltipContainer, |
| 37 ¶ms); |
| 35 drag_widget->Init(params); | 38 drag_widget->Init(params); |
| 36 drag_widget->SetOpacity(1.f); | 39 drag_widget->SetOpacity(1.f); |
| 37 return drag_widget; | 40 return drag_widget; |
| 38 } | 41 } |
| 39 | 42 |
| 40 } // namespace | 43 } // namespace |
| 41 | 44 |
| 42 DragImageView::DragImageView(WmWindow* root_window, | 45 DragImageView::DragImageView(aura::Window* root_window, |
| 43 ui::DragDropTypes::DragEventSource event_source) | 46 ui::DragDropTypes::DragEventSource event_source) |
| 44 : drag_event_source_(event_source), | 47 : drag_event_source_(event_source), |
| 45 touch_drag_operation_(ui::DragDropTypes::DRAG_NONE) { | 48 touch_drag_operation_(ui::DragDropTypes::DRAG_NONE) { |
| 46 DCHECK(root_window); | 49 DCHECK(root_window); |
| 47 widget_ = CreateDragWidget(root_window); | 50 widget_ = CreateDragWidget(root_window); |
| 48 widget_->SetContentsView(this); | 51 widget_->SetContentsView(this); |
| 49 widget_->SetAlwaysOnTop(true); | 52 widget_->SetAlwaysOnTop(true); |
| 50 | 53 |
| 51 // We are owned by the DragDropController. | 54 // We are owned by the DragDropController. |
| 52 set_owned_by_client(); | 55 set_owned_by_client(); |
| (...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 114 | 117 |
| 115 void DragImageView::OnPaint(gfx::Canvas* canvas) { | 118 void DragImageView::OnPaint(gfx::Canvas* canvas) { |
| 116 if (GetImage().isNull()) | 119 if (GetImage().isNull()) |
| 117 return; | 120 return; |
| 118 | 121 |
| 119 // |drag_image_size_| is in DIP. | 122 // |drag_image_size_| is in DIP. |
| 120 // ImageSkia::size() also returns the size in DIP. | 123 // ImageSkia::size() also returns the size in DIP. |
| 121 if (GetImage().size() == drag_image_size_) { | 124 if (GetImage().size() == drag_image_size_) { |
| 122 canvas->DrawImageInt(GetImage(), 0, 0); | 125 canvas->DrawImageInt(GetImage(), 0, 0); |
| 123 } else { | 126 } else { |
| 124 WmWindow* window = WmWindow::Get(widget_->GetNativeWindow()); | 127 aura::Window* window = widget_->GetNativeWindow(); |
| 125 const float device_scale = | 128 const float device_scale = display::Screen::GetScreen() |
| 126 window->GetDisplayNearestWindow().device_scale_factor(); | 129 ->GetDisplayNearestWindow(window) |
| 130 .device_scale_factor(); |
| 127 // The drag image already has device scale factor applied. But | 131 // The drag image already has device scale factor applied. But |
| 128 // |drag_image_size_| is in DIP units. | 132 // |drag_image_size_| is in DIP units. |
| 129 gfx::Size drag_image_size_pixels = | 133 gfx::Size drag_image_size_pixels = |
| 130 gfx::ScaleToRoundedSize(drag_image_size_, device_scale); | 134 gfx::ScaleToRoundedSize(drag_image_size_, device_scale); |
| 131 gfx::ImageSkiaRep image_rep = GetImage().GetRepresentation(device_scale); | 135 gfx::ImageSkiaRep image_rep = GetImage().GetRepresentation(device_scale); |
| 132 if (image_rep.is_null()) | 136 if (image_rep.is_null()) |
| 133 return; | 137 return; |
| 134 SkBitmap scaled = skia::ImageOperations::Resize( | 138 SkBitmap scaled = skia::ImageOperations::Resize( |
| 135 image_rep.sk_bitmap(), skia::ImageOperations::RESIZE_LANCZOS3, | 139 image_rep.sk_bitmap(), skia::ImageOperations::RESIZE_LANCZOS3, |
| 136 drag_image_size_pixels.width(), drag_image_size_pixels.height()); | 140 drag_image_size_pixels.width(), drag_image_size_pixels.height()); |
| (...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 199 // Enlarge widget if required to fit the drag hint image. | 203 // Enlarge widget if required to fit the drag hint image. |
| 200 gfx::Size widget_size = widget_->GetWindowBoundsInScreen().size(); | 204 gfx::Size widget_size = widget_->GetWindowBoundsInScreen().size(); |
| 201 if (drag_hint_size.width() > widget_size.width() || | 205 if (drag_hint_size.width() > widget_size.width() || |
| 202 drag_hint_size.height() > widget_size.height()) { | 206 drag_hint_size.height() > widget_size.height()) { |
| 203 widget_size.SetToMax(drag_hint_size); | 207 widget_size.SetToMax(drag_hint_size); |
| 204 widget_->SetSize(widget_size); | 208 widget_->SetSize(widget_size); |
| 205 } | 209 } |
| 206 } | 210 } |
| 207 | 211 |
| 208 } // namespace ash | 212 } // namespace ash |
| OLD | NEW |