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