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

Side by Side Diff: ui/views/button_drag_utils.cc

Issue 2694023003: Make CanvasPainter raster directly to an SkBitmap (Closed)
Patch Set: Replace CanvasPainter rect with size Created 3 years, 10 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
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 "ui/views/button_drag_utils.h" 5 #include "ui/views/button_drag_utils.h"
6 6
7 #include "base/strings/utf_string_conversions.h" 7 #include "base/strings/utf_string_conversions.h"
8 #include "ui/base/dragdrop/drag_utils.h" 8 #include "ui/base/dragdrop/drag_utils.h"
9 #include "ui/base/dragdrop/os_exchange_data.h" 9 #include "ui/base/dragdrop/os_exchange_data.h"
10 #include "ui/base/resource/resource_bundle.h" 10 #include "ui/base/resource/resource_bundle.h"
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
64 button.SetBorder(button.CreateDefaultBorder()); 64 button.SetBorder(button.CreateDefaultBorder());
65 } 65 }
66 button.SetMaxSize(gfx::Size(kLinkDragImageMaxWidth, 0)); 66 button.SetMaxSize(gfx::Size(kLinkDragImageMaxWidth, 0));
67 if (icon.isNull()) { 67 if (icon.isNull()) {
68 button.SetImage(views::Button::STATE_NORMAL, 68 button.SetImage(views::Button::STATE_NORMAL,
69 *ui::ResourceBundle::GetSharedInstance().GetImageNamed( 69 *ui::ResourceBundle::GetSharedInstance().GetImageNamed(
70 IDR_DEFAULT_FAVICON).ToImageSkia()); 70 IDR_DEFAULT_FAVICON).ToImageSkia());
71 } else { 71 } else {
72 button.SetImage(views::Button::STATE_NORMAL, icon); 72 button.SetImage(views::Button::STATE_NORMAL, icon);
73 } 73 }
74 gfx::Size prefsize = button.GetPreferredSize(); 74
75 button.SetBounds(0, 0, prefsize.width(), prefsize.height()); 75 gfx::Size size(button.GetPreferredSize());
76 button.SetBoundsRect(gfx::Rect(size));
76 77
77 gfx::Vector2d press_point; 78 gfx::Vector2d press_point;
78 if (press_pt) 79 if (press_pt)
79 press_point = press_pt->OffsetFromOrigin(); 80 press_point = press_pt->OffsetFromOrigin();
80 else 81 else
81 press_point = gfx::Vector2d(prefsize.width() / 2, prefsize.height() / 2); 82 press_point = gfx::Vector2d(size.width() / 2, size.height() / 2);
82 83
83 // Render the image. 84 SkBitmap bitmap;
84 std::unique_ptr<gfx::Canvas> canvas( 85 float raster_scale = GetDeviceScaleForNativeView(widget);
85 views::GetCanvasForDragImage(widget, prefsize)); 86 SkColor color = SkColorSetARGB(0, 0, 0, 0);
danakj 2017/02/14 21:37:26 This is Sk_ColorTRANSPARENT
86 button.Paint(ui::CanvasPainter(canvas.get(), 1.f).context()); 87 button.Paint(ui::CanvasPainter(&bitmap, size, raster_scale, color).context());
87 drag_utils::SetDragImageOnDataObject(*canvas, press_point, data); 88 gfx::ImageSkia image(gfx::ImageSkiaRep(bitmap, raster_scale));
89 drag_utils::SetDragImageOnDataObject(image, press_point, data);
88 } 90 }
89 91
90 } // namespace button_drag_utils 92 } // namespace button_drag_utils
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698