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 "ui/views/controls/menu/menu_controller.h" | 5 #include "ui/views/controls/menu/menu_controller.h" |
6 | 6 |
7 #include "base/i18n/case_conversion.h" | 7 #include "base/i18n/case_conversion.h" |
8 #include "base/i18n/rtl.h" | 8 #include "base/i18n/rtl.h" |
9 #include "base/macros.h" | 9 #include "base/macros.h" |
10 #include "base/strings/utf_string_conversions.h" | 10 #include "base/strings/utf_string_conversions.h" |
11 #include "base/time/time.h" | 11 #include "base/time/time.h" |
12 #include "build/build_config.h" | 12 #include "build/build_config.h" |
13 #include "ui/base/dragdrop/drag_utils.h" | 13 #include "ui/base/dragdrop/drag_utils.h" |
14 #include "ui/base/dragdrop/os_exchange_data.h" | 14 #include "ui/base/dragdrop/os_exchange_data.h" |
15 #include "ui/display/screen.h" | 15 #include "ui/display/screen.h" |
16 #include "ui/events/event.h" | 16 #include "ui/events/event.h" |
17 #include "ui/events/event_utils.h" | 17 #include "ui/events/event_utils.h" |
18 #include "ui/gfx/canvas.h" | 18 #include "ui/gfx/canvas.h" |
19 #include "ui/gfx/geometry/point.h" | 19 #include "ui/gfx/geometry/point.h" |
20 #include "ui/gfx/geometry/vector2d.h" | 20 #include "ui/gfx/geometry/vector2d.h" |
21 #include "ui/gfx/image/image.h" | |
22 #include "ui/gfx/image/image_skia.h" | |
23 #include "ui/gfx/image/image_skia_rep.h" | |
21 #include "ui/gfx/native_widget_types.h" | 24 #include "ui/gfx/native_widget_types.h" |
22 #include "ui/native_theme/native_theme.h" | 25 #include "ui/native_theme/native_theme.h" |
23 #include "ui/views/controls/button/menu_button.h" | 26 #include "ui/views/controls/button/menu_button.h" |
24 #include "ui/views/controls/menu/menu_config.h" | 27 #include "ui/views/controls/menu/menu_config.h" |
25 #include "ui/views/controls/menu/menu_controller_delegate.h" | 28 #include "ui/views/controls/menu/menu_controller_delegate.h" |
26 #include "ui/views/controls/menu/menu_host_root_view.h" | 29 #include "ui/views/controls/menu/menu_host_root_view.h" |
27 #include "ui/views/controls/menu/menu_item_view.h" | 30 #include "ui/views/controls/menu/menu_item_view.h" |
28 #include "ui/views/controls/menu/menu_scroll_view_container.h" | 31 #include "ui/views/controls/menu/menu_scroll_view_container.h" |
29 #include "ui/views/controls/menu/submenu_view.h" | 32 #include "ui/views/controls/menu/submenu_view.h" |
30 #include "ui/views/drag_utils.h" | 33 #include "ui/views/drag_utils.h" |
(...skipping 1204 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1235 MenuItemView* item = state_.item; | 1238 MenuItemView* item = state_.item; |
1236 DCHECK(item); | 1239 DCHECK(item); |
1237 // Points are in the coordinates of the submenu, need to map to that of | 1240 // Points are in the coordinates of the submenu, need to map to that of |
1238 // the selected item. Additionally source may not be the parent of | 1241 // the selected item. Additionally source may not be the parent of |
1239 // the selected item, so need to map to screen first then to item. | 1242 // the selected item, so need to map to screen first then to item. |
1240 gfx::Point press_loc(location); | 1243 gfx::Point press_loc(location); |
1241 View::ConvertPointToScreen(source->GetScrollViewContainer(), &press_loc); | 1244 View::ConvertPointToScreen(source->GetScrollViewContainer(), &press_loc); |
1242 View::ConvertPointFromScreen(item, &press_loc); | 1245 View::ConvertPointFromScreen(item, &press_loc); |
1243 gfx::Point widget_loc(press_loc); | 1246 gfx::Point widget_loc(press_loc); |
1244 View::ConvertPointToWidget(item, &widget_loc); | 1247 View::ConvertPointToWidget(item, &widget_loc); |
1245 std::unique_ptr<gfx::Canvas> canvas(GetCanvasForDragImage( | 1248 |
1246 source->GetWidget(), gfx::Size(item->width(), item->height()))); | 1249 float raster_scale = ScaleFactorForDragFromWidget(source->GetWidget()); |
1247 item->PaintButton(canvas.get(), MenuItemView::PB_FOR_DRAG); | 1250 gfx::Canvas canvas(item->size(), raster_scale, false); |
sadrul
2017/04/04 04:09:03
false /* is_opaque */
danakj
2017/04/04 14:46:16
Done.
| |
1251 item->PaintButton(&canvas, MenuItemView::PB_FOR_DRAG); | |
1252 gfx::ImageSkia image(gfx::ImageSkiaRep(canvas.GetBitmap(), raster_scale)); | |
1248 | 1253 |
1249 OSExchangeData data; | 1254 OSExchangeData data; |
1250 item->GetDelegate()->WriteDragData(item, &data); | 1255 item->GetDelegate()->WriteDragData(item, &data); |
1251 drag_utils::SetDragImageOnDataObject(*canvas, | 1256 drag_utils::SetDragImageOnDataObject(std::move(image), |
sadrul
2017/04/04 04:14:08
Oh btw: SetDragImageOnDataObject() takes a const&.
danakj
2017/04/04 14:46:16
move is just a static_cast to a gfx::ImageSkia&&.
| |
1252 press_loc.OffsetFromOrigin(), | 1257 press_loc.OffsetFromOrigin(), &data); |
1253 &data); | 1258 |
1254 StopScrolling(); | 1259 StopScrolling(); |
1255 int drag_ops = item->GetDelegate()->GetDragOperations(item); | 1260 int drag_ops = item->GetDelegate()->GetDragOperations(item); |
1256 did_initiate_drag_ = true; | 1261 did_initiate_drag_ = true; |
1257 base::WeakPtr<MenuController> this_ref = AsWeakPtr(); | 1262 base::WeakPtr<MenuController> this_ref = AsWeakPtr(); |
1258 // TODO(varunjain): Properly determine and send DRAG_EVENT_SOURCE below. | 1263 // TODO(varunjain): Properly determine and send DRAG_EVENT_SOURCE below. |
1259 item->GetWidget()->RunShellDrag(NULL, data, widget_loc, drag_ops, | 1264 item->GetWidget()->RunShellDrag(NULL, data, widget_loc, drag_ops, |
1260 ui::DragDropTypes::DRAG_EVENT_SOURCE_MOUSE); | 1265 ui::DragDropTypes::DRAG_EVENT_SOURCE_MOUSE); |
1261 // MenuController may have been deleted so check before accessing member | 1266 // MenuController may have been deleted so check before accessing member |
1262 // variables. | 1267 // variables. |
1263 if (this_ref) | 1268 if (this_ref) |
(...skipping 1447 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2711 if (hot_button_) | 2716 if (hot_button_) |
2712 hot_button_->SetHotTracked(false); | 2717 hot_button_->SetHotTracked(false); |
2713 hot_button_ = hot_button; | 2718 hot_button_ = hot_button; |
2714 if (hot_button) { | 2719 if (hot_button) { |
2715 hot_button->SetHotTracked(true); | 2720 hot_button->SetHotTracked(true); |
2716 hot_button->NotifyAccessibilityEvent(ui::AX_EVENT_SELECTION, true); | 2721 hot_button->NotifyAccessibilityEvent(ui::AX_EVENT_SELECTION, true); |
2717 } | 2722 } |
2718 } | 2723 } |
2719 | 2724 |
2720 } // namespace views | 2725 } // namespace views |
OLD | NEW |