| OLD | NEW |
| (Empty) |
| 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 | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #ifndef ASH_DRAG_DROP_DRAG_IMAGE_VIEW_H_ | |
| 6 #define ASH_DRAG_DROP_DRAG_IMAGE_VIEW_H_ | |
| 7 | |
| 8 #include <memory> | |
| 9 | |
| 10 #include "base/macros.h" | |
| 11 #include "ui/base/dragdrop/drag_drop_types.h" | |
| 12 #include "ui/views/controls/image_view.h" | |
| 13 | |
| 14 namespace gfx { | |
| 15 class Image; | |
| 16 } | |
| 17 | |
| 18 namespace views { | |
| 19 class Widget; | |
| 20 } | |
| 21 | |
| 22 namespace ash { | |
| 23 | |
| 24 // This class allows to show a (native) view always on top of everything. It | |
| 25 // does this by creating a widget and setting the content as the given view. The | |
| 26 // caller can then use this object to freely move / drag it around on the | |
| 27 // desktop in screen coordinates. | |
| 28 class DragImageView : public views::ImageView { | |
| 29 public: | |
| 30 // |context is the native view context used to create the widget holding the | |
| 31 // drag image. | |
| 32 // |source| is the event source that started this drag drop operation (touch | |
| 33 // or mouse). It is used to determine attributes of the drag image such as | |
| 34 // whether to show drag operation hint on top of the image. | |
| 35 DragImageView(gfx::NativeView context, | |
| 36 ui::DragDropTypes::DragEventSource source); | |
| 37 ~DragImageView() override; | |
| 38 | |
| 39 // Sets the bounds of the native widget in screen | |
| 40 // coordinates. | |
| 41 // TODO(oshima): Looks like this is root window's | |
| 42 // coordinate. Change this to screen's coordinate. | |
| 43 void SetBoundsInScreen(const gfx::Rect& bounds); | |
| 44 | |
| 45 // Sets the position of the native widget. | |
| 46 void SetScreenPosition(const gfx::Point& position); | |
| 47 | |
| 48 // Gets the image position in screen coordinates. | |
| 49 gfx::Rect GetBoundsInScreen() const; | |
| 50 | |
| 51 // Sets the visibility of the native widget. | |
| 52 void SetWidgetVisible(bool visible); | |
| 53 | |
| 54 // For touch drag drop, we show a hint corresponding to the drag operation | |
| 55 // (since no mouse cursor is visible). These functions set the hint | |
| 56 // parameters. | |
| 57 void SetTouchDragOperationHintOff(); | |
| 58 | |
| 59 // |operation| is a bit field indicating allowable drag operations from | |
| 60 // ui::DragDropTypes::DragOperation. | |
| 61 void SetTouchDragOperation(int operation); | |
| 62 void SetTouchDragOperationHintPosition(const gfx::Point& position); | |
| 63 | |
| 64 // Sets the |opacity| of the image view between 0.0 and 1.0. | |
| 65 void SetOpacity(float opacity); | |
| 66 | |
| 67 private: | |
| 68 gfx::Image* DragHint() const; | |
| 69 | |
| 70 // Overridden from views::ImageView. | |
| 71 void OnPaint(gfx::Canvas* canvas) override; | |
| 72 | |
| 73 // Overridden from views::view | |
| 74 void Layout() override; | |
| 75 | |
| 76 std::unique_ptr<views::Widget> widget_; | |
| 77 gfx::Size widget_size_; | |
| 78 | |
| 79 ui::DragDropTypes::DragEventSource drag_event_source_; | |
| 80 int touch_drag_operation_; | |
| 81 gfx::Point touch_drag_operation_indicator_position_; | |
| 82 | |
| 83 DISALLOW_COPY_AND_ASSIGN(DragImageView); | |
| 84 }; | |
| 85 | |
| 86 } // namespace ash | |
| 87 | |
| 88 #endif // ASH_DRAG_DROP_DRAG_IMAGE_VIEW_H_ | |
| OLD | NEW |