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_COMMON_DRAG_DROP_DRAG_IMAGE_VIEW_H_ | |
6 #define ASH_COMMON_DRAG_DROP_DRAG_IMAGE_VIEW_H_ | |
7 | |
8 #include <memory> | |
9 | |
10 #include "ash/ash_export.h" | |
11 #include "base/macros.h" | |
12 #include "ui/base/dragdrop/drag_drop_types.h" | |
13 #include "ui/gfx/geometry/point.h" | |
14 #include "ui/gfx/geometry/size.h" | |
15 #include "ui/views/controls/image_view.h" | |
16 | |
17 namespace gfx { | |
18 class Image; | |
19 } | |
20 | |
21 namespace views { | |
22 class Widget; | |
23 } | |
24 | |
25 namespace ash { | |
26 | |
27 class WmWindow; | |
28 | |
29 // This class allows to show a (native) view always on top of everything. It | |
30 // does this by creating a widget and setting the content as the given view. The | |
31 // caller can then use this object to freely move / drag it around on the | |
32 // desktop in screen coordinates. | |
33 class ASH_EXPORT DragImageView : public views::ImageView { | |
34 public: | |
35 // |root_window| is the root window on which to create the drag image widget. | |
36 // |source| is the event source that started this drag drop operation (touch | |
37 // or mouse). It is used to determine attributes of the drag image such as | |
38 // whether to show drag operation hint on top of the image. | |
39 DragImageView(WmWindow* root_window, | |
40 ui::DragDropTypes::DragEventSource source); | |
41 ~DragImageView() override; | |
42 | |
43 // Sets the bounds of the native widget in screen | |
44 // coordinates. | |
45 // TODO(oshima): Looks like this is root window's | |
46 // coordinate. Change this to screen's coordinate. | |
47 void SetBoundsInScreen(const gfx::Rect& bounds); | |
48 | |
49 // Sets the position of the native widget. | |
50 void SetScreenPosition(const gfx::Point& position); | |
51 | |
52 // Gets the image position in screen coordinates. | |
53 gfx::Rect GetBoundsInScreen() const; | |
54 | |
55 // Sets the visibility of the native widget. | |
56 void SetWidgetVisible(bool visible); | |
57 | |
58 // For touch drag drop, we show a hint corresponding to the drag operation | |
59 // (since no mouse cursor is visible). These functions set the hint | |
60 // parameters. | |
61 void SetTouchDragOperationHintOff(); | |
62 | |
63 // |operation| is a bit field indicating allowable drag operations from | |
64 // ui::DragDropTypes::DragOperation. | |
65 void SetTouchDragOperation(int operation); | |
66 void SetTouchDragOperationHintPosition(const gfx::Point& position); | |
67 | |
68 // Sets the |opacity| of the image view between 0.0 and 1.0. | |
69 void SetOpacity(float opacity); | |
70 | |
71 gfx::Size GetMinimumSize() const override; | |
72 | |
73 private: | |
74 gfx::Image* DragHint() const; | |
75 // Drag hint images are only drawn when the input source is touch. | |
76 bool ShouldDrawDragHint() const; | |
77 | |
78 // Overridden from views::ImageView. | |
79 void OnPaint(gfx::Canvas* canvas) override; | |
80 | |
81 // Overridden from views::view | |
82 void Layout() override; | |
83 | |
84 std::unique_ptr<views::Widget> widget_; | |
85 | |
86 // Save the requested drag image size. We may need to display a drag hint | |
87 // image, which potentially expands |widget_|'s size. That drag hint image | |
88 // may be disabled (e.g. during the drag cancel animation). In that case, | |
89 // we need to know the originally requested size to render the drag image. | |
90 gfx::Size drag_image_size_; | |
91 | |
92 ui::DragDropTypes::DragEventSource drag_event_source_; | |
93 | |
94 // Bitmask of ui::DragDropTypes::DragOperation values. | |
95 int touch_drag_operation_; | |
96 gfx::Point touch_drag_operation_indicator_position_; | |
97 | |
98 DISALLOW_COPY_AND_ASSIGN(DragImageView); | |
99 }; | |
100 | |
101 } // namespace ash | |
102 | |
103 #endif // ASH_COMMON_DRAG_DROP_DRAG_IMAGE_VIEW_H_ | |
OLD | NEW |