Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(533)

Side by Side Diff: ash/common/drag_drop/drag_image_view.cc

Issue 2206033002: mash: Migrate ash::DragImageView to wm common types (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: nits Created 4 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « ash/common/drag_drop/drag_image_view.h ('k') | ash/drag_drop/drag_drop_controller.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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/common/drag_drop/drag_image_view.h"
6 6
7 #include <memory>
8
9 #include "ash/common/shell_window_ids.h"
10 #include "ash/common/wm_lookup.h"
11 #include "ash/common/wm_root_window_controller.h"
12 #include "ash/common/wm_window.h"
7 #include "skia/ext/image_operations.h" 13 #include "skia/ext/image_operations.h"
8 #include "ui/aura/window.h"
9 #include "ui/base/resource/resource_bundle.h" 14 #include "ui/base/resource/resource_bundle.h"
10 #include "ui/compositor/dip_util.h" 15 #include "ui/display/display.h"
11 #include "ui/gfx/canvas.h" 16 #include "ui/gfx/canvas.h"
12 #include "ui/gfx/geometry/size_conversions.h"
13 #include "ui/resources/grit/ui_resources.h" 17 #include "ui/resources/grit/ui_resources.h"
14 #include "ui/views/widget/widget.h" 18 #include "ui/views/widget/widget.h"
15 #include "ui/wm/core/shadow_types.h"
16 19
17 namespace ash { 20 namespace ash {
18 namespace { 21 namespace {
19 using views::Widget; 22 using views::Widget;
20 23
21 Widget* CreateDragWidget(gfx::NativeView context) { 24 std::unique_ptr<Widget> CreateDragWidget(WmWindow* root_window) {
22 Widget* drag_widget = new Widget; 25 std::unique_ptr<Widget> drag_widget(new Widget);
23 Widget::InitParams params; 26 Widget::InitParams params;
24 params.type = Widget::InitParams::TYPE_TOOLTIP; 27 params.type = Widget::InitParams::TYPE_TOOLTIP;
28 params.name = "DragWidget";
25 params.keep_on_top = true; 29 params.keep_on_top = true;
26 params.context = context;
27 params.accept_events = false; 30 params.accept_events = false;
28 params.ownership = Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET; 31 params.ownership = Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET;
32 params.shadow_type = Widget::InitParams::SHADOW_TYPE_NONE;
29 params.opacity = Widget::InitParams::TRANSLUCENT_WINDOW; 33 params.opacity = Widget::InitParams::TRANSLUCENT_WINDOW;
34 root_window->GetRootWindowController()->ConfigureWidgetInitParamsForContainer(
35 drag_widget.get(), kShellWindowId_DragImageAndTooltipContainer, &params);
30 drag_widget->Init(params); 36 drag_widget->Init(params);
31 drag_widget->SetOpacity(1.f); 37 drag_widget->SetOpacity(1.f);
32 drag_widget->GetNativeWindow()->set_owned_by_parent(false);
33 drag_widget->GetNativeWindow()->SetName("DragWidget");
34 SetShadowType(drag_widget->GetNativeView(), wm::SHADOW_TYPE_NONE);
35 return drag_widget; 38 return drag_widget;
36 } 39 }
37 }
38 40
39 DragImageView::DragImageView(gfx::NativeView context, 41 } // namespace
42
43 DragImageView::DragImageView(WmWindow* root_window,
40 ui::DragDropTypes::DragEventSource event_source) 44 ui::DragDropTypes::DragEventSource event_source)
41 : views::ImageView(), 45 : drag_event_source_(event_source),
42 drag_event_source_(event_source),
43 touch_drag_operation_(ui::DragDropTypes::DRAG_NONE) { 46 touch_drag_operation_(ui::DragDropTypes::DRAG_NONE) {
44 widget_.reset(CreateDragWidget(context)); 47 DCHECK(root_window);
48 widget_ = CreateDragWidget(root_window);
45 widget_->SetContentsView(this); 49 widget_->SetContentsView(this);
46 widget_->SetAlwaysOnTop(true); 50 widget_->SetAlwaysOnTop(true);
47 51
48 // We are owned by the DragDropController. 52 // We are owned by the DragDropController.
49 set_owned_by_client(); 53 set_owned_by_client();
50 } 54 }
51 55
52 DragImageView::~DragImageView() { 56 DragImageView::~DragImageView() {
53 widget_->Hide(); 57 widget_->Hide();
54 } 58 }
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
103 } 107 }
104 108
105 void DragImageView::OnPaint(gfx::Canvas* canvas) { 109 void DragImageView::OnPaint(gfx::Canvas* canvas) {
106 if (GetImage().isNull()) 110 if (GetImage().isNull())
107 return; 111 return;
108 112
109 // |widget_size_| is in DIP. ImageSkia::size() also returns the size in DIP. 113 // |widget_size_| is in DIP. ImageSkia::size() also returns the size in DIP.
110 if (GetImage().size() == widget_size_) { 114 if (GetImage().size() == widget_size_) {
111 canvas->DrawImageInt(GetImage(), 0, 0); 115 canvas->DrawImageInt(GetImage(), 0, 0);
112 } else { 116 } else {
113 float device_scale = 1; 117 WmWindow* window = WmLookup::Get()->GetWindowForWidget(widget_.get());
114 if (widget_->GetNativeView() && widget_->GetNativeView()->layer()) { 118 const float device_scale =
115 device_scale = 119 window->GetDisplayNearestWindow().device_scale_factor();
116 ui::GetDeviceScaleFactor(widget_->GetNativeView()->layer());
117 }
118 // The drag image already has device scale factor applied. But 120 // The drag image already has device scale factor applied. But
119 // |widget_size_| is in DIP units. 121 // |widget_size_| is in DIP units.
120 gfx::Size scaled_widget_size = 122 gfx::Size scaled_widget_size =
121 gfx::ScaleToRoundedSize(widget_size_, device_scale); 123 gfx::ScaleToRoundedSize(widget_size_, device_scale);
122 gfx::ImageSkiaRep image_rep = GetImage().GetRepresentation(device_scale); 124 gfx::ImageSkiaRep image_rep = GetImage().GetRepresentation(device_scale);
123 if (image_rep.is_null()) 125 if (image_rep.is_null())
124 return; 126 return;
125 SkBitmap scaled = skia::ImageOperations::Resize( 127 SkBitmap scaled = skia::ImageOperations::Resize(
126 image_rep.sk_bitmap(), skia::ImageOperations::RESIZE_LANCZOS3, 128 image_rep.sk_bitmap(), skia::ImageOperations::RESIZE_LANCZOS3,
127 scaled_widget_size.width(), scaled_widget_size.height()); 129 scaled_widget_size.width(), scaled_widget_size.height());
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
178 // Enlarge widget if required to fit the drag hint image. 180 // Enlarge widget if required to fit the drag hint image.
179 if (drag_hint_size.width() > widget_size_.width() || 181 if (drag_hint_size.width() > widget_size_.width() ||
180 drag_hint_size.height() > widget_size_.height()) { 182 drag_hint_size.height() > widget_size_.height()) {
181 gfx::Size new_widget_size = widget_size_; 183 gfx::Size new_widget_size = widget_size_;
182 new_widget_size.SetToMax(drag_hint_size); 184 new_widget_size.SetToMax(drag_hint_size);
183 widget_->SetSize(new_widget_size); 185 widget_->SetSize(new_widget_size);
184 } 186 }
185 } 187 }
186 188
187 } // namespace ash 189 } // namespace ash
OLDNEW
« no previous file with comments | « ash/common/drag_drop/drag_image_view.h ('k') | ash/drag_drop/drag_drop_controller.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698