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

Side by Side Diff: ui/views/controls/textfield/textfield.cc

Issue 2694023003: Make CanvasPainter raster directly to an SkBitmap (Closed)
Patch Set: danakj review 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/controls/textfield/textfield.h" 5 #include "ui/views/controls/textfield/textfield.h"
6 6
7 #include <string> 7 #include <string>
8 #include <utility> 8 #include <utility>
9 9
10 #include "base/memory/ptr_util.h" 10 #include "base/memory/ptr_util.h"
(...skipping 1045 matching lines...) Expand 10 before | Expand all | Expand 10 after
1056 data->SetString(selected_text); 1056 data->SetString(selected_text);
1057 Label label(selected_text, GetFontList()); 1057 Label label(selected_text, GetFontList());
1058 label.SetBackgroundColor(GetBackgroundColor()); 1058 label.SetBackgroundColor(GetBackgroundColor());
1059 label.SetSubpixelRenderingEnabled(false); 1059 label.SetSubpixelRenderingEnabled(false);
1060 gfx::Size size(label.GetPreferredSize()); 1060 gfx::Size size(label.GetPreferredSize());
1061 gfx::NativeView native_view = GetWidget()->GetNativeView(); 1061 gfx::NativeView native_view = GetWidget()->GetNativeView();
1062 display::Display display = 1062 display::Display display =
1063 display::Screen::GetScreen()->GetDisplayNearestWindow(native_view); 1063 display::Screen::GetScreen()->GetDisplayNearestWindow(native_view);
1064 size.SetToMin(gfx::Size(display.size().width(), height())); 1064 size.SetToMin(gfx::Size(display.size().width(), height()));
1065 label.SetBoundsRect(gfx::Rect(size)); 1065 label.SetBoundsRect(gfx::Rect(size));
1066 std::unique_ptr<gfx::Canvas> canvas(
1067 GetCanvasForDragImage(GetWidget(), label.size()));
1068 label.SetEnabledColor(GetTextColor()); 1066 label.SetEnabledColor(GetTextColor());
1067
1068 SkBitmap bitmap;
1069 float raster_scale = GetDeviceScaleForNativeView(GetWidget());
1069 #if defined(OS_LINUX) && !defined(OS_CHROMEOS) 1070 #if defined(OS_LINUX) && !defined(OS_CHROMEOS)
1070 // Desktop Linux Aura does not yet support transparency in drag images. 1071 // Desktop Linux Aura does not yet support transparency in drag images.
1071 canvas->DrawColor(GetBackgroundColor()); 1072 SkColor color(GetBackgroundColor());
tapted 2017/02/14 23:34:07 color = (same below)
1073 #else
1074 SkColor color(SK_ColorTRANSPARENT);
1072 #endif 1075 #endif
1073 label.Paint(ui::CanvasPainter(canvas.get(), 1.f).context()); 1076 label.Paint(
1077 ui::CanvasPainter(&bitmap, label.size(), raster_scale, color).context());
1074 const gfx::Vector2d kOffset(-15, 0); 1078 const gfx::Vector2d kOffset(-15, 0);
1075 drag_utils::SetDragImageOnDataObject(*canvas, kOffset, data); 1079 gfx::ImageSkia image(gfx::ImageSkiaRep(bitmap, raster_scale));
1080 drag_utils::SetDragImageOnDataObject(image, kOffset, data);
1076 if (controller_) 1081 if (controller_)
1077 controller_->OnWriteDragData(data); 1082 controller_->OnWriteDragData(data);
1078 } 1083 }
1079 1084
1080 int Textfield::GetDragOperationsForView(View* sender, const gfx::Point& p) { 1085 int Textfield::GetDragOperationsForView(View* sender, const gfx::Point& p) {
1081 int drag_operations = ui::DragDropTypes::DRAG_COPY; 1086 int drag_operations = ui::DragDropTypes::DRAG_COPY;
1082 if (!enabled() || text_input_type_ == ui::TEXT_INPUT_TYPE_PASSWORD || 1087 if (!enabled() || text_input_type_ == ui::TEXT_INPUT_TYPE_PASSWORD ||
1083 !GetRenderText()->IsPointInSelection(p)) { 1088 !GetRenderText()->IsPointInSelection(p)) {
1084 drag_operations = ui::DragDropTypes::DRAG_NONE; 1089 drag_operations = ui::DragDropTypes::DRAG_NONE;
1085 } else if (sender == this && !read_only()) { 1090 } else if (sender == this && !read_only()) {
(...skipping 989 matching lines...) Expand 10 before | Expand all | Expand 10 after
2075 } 2080 }
2076 2081
2077 void Textfield::OnCursorBlinkTimerFired() { 2082 void Textfield::OnCursorBlinkTimerFired() {
2078 DCHECK(ShouldBlinkCursor()); 2083 DCHECK(ShouldBlinkCursor());
2079 gfx::RenderText* render_text = GetRenderText(); 2084 gfx::RenderText* render_text = GetRenderText();
2080 render_text->set_cursor_visible(!render_text->cursor_visible()); 2085 render_text->set_cursor_visible(!render_text->cursor_visible());
2081 RepaintCursor(); 2086 RepaintCursor();
2082 } 2087 }
2083 2088
2084 } // namespace views 2089 } // namespace views
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698