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