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.
5 #ifndef CHROME_BROWSER_UI_GTK_TABS_DRAGGED_VIEW_GTK_H_
6 #define CHROME_BROWSER_UI_GTK_TABS_DRAGGED_VIEW_GTK_H_
12 #include "base/callback.h"
13 #include "base/compiler_specific.h"
14 #include "ui/base/gtk/gtk_signal.h"
15 #include "ui/gfx/animation/animation_delegate.h"
16 #include "ui/gfx/animation/slide_animation.h"
17 #include "ui/gfx/canvas.h"
18 #include "ui/gfx/point.h"
19 #include "ui/gfx/rect.h"
20 #include "ui/gfx/size.h"
25 class DraggedViewGtk
: public gfx::AnimationDelegate
{
27 DraggedViewGtk(DragData
* drag_data
,
28 const gfx::Point
& mouse_tab_offset
,
29 const gfx::Size
& contents_size
);
30 virtual ~DraggedViewGtk();
32 // Moves the attached dragged view to the appropriate location.
33 // |tabstrip_point| is the location of the upper left corner of the dragged
34 // view in screen coordinates.
35 void MoveAttachedTo(const gfx::Point
& tabstrip_point
);
37 // Moves the detached dragged view to the appropriate location. |screen_point|
38 // is the current position of the mouse pointer in screen coordinates.
39 void MoveDetachedTo(const gfx::Point
& screen_point
);
41 // Sets the offset of the mouse from the upper left corner of the tab.
42 void set_mouse_tab_offset(const gfx::Point
& offset
) {
43 mouse_tab_offset_
= offset
;
46 // Notifies the dragged tab that it has become attached to a tabstrip.
47 // |normal_width| and |mini_width| is the width of a mini and a normal tab
48 // respectively after attaching. |parent_window_width| is the width of the
49 // parent window of the tabstrip.
50 void Attach(int normal_width
, int mini_width
, int parent_window_width
);
52 // Resizes the dragged tab to a width of |width|.
53 void Resize(int width
);
55 // Notifies the dragged tab that it has been detached from a tabstrip.
58 // Notifies the dragged tab that it should update itself.
61 // Animates the dragged tab to the specified bounds, then calls back to
63 void AnimateToBounds(const gfx::Rect
& bounds
, const base::Closure
& callback
);
65 // Returns the size of the dragged tab. Used when attaching to a tabstrip
66 // to determine where to place the tab in the attached tabstrip.
67 const gfx::Size
& attached_tab_size() const { return attached_tab_size_
; }
68 int GetAttachedTabWidthAt(int index
);
70 GtkWidget
* widget() const { return container_
; }
72 int mini_width() { return mini_width_
; }
73 int normal_width() { return normal_width_
; }
75 // Returns the width occupied in the tabstrip from index |from| included to
76 // index |to| excluded. The indices are with respect to |drag_data_|.
77 int GetWidthInTabStripFromTo(int from
, int to
);
79 // Returns the total width occupied in the tabstrip.
80 int GetTotalWidthInTabStrip();
82 // Returns the width occupied in the tabstrip from the left most point of the
83 // dragged view up to the source tab excluded.
84 int GetWidthInTabStripUpToSourceTab();
86 // Returns the width occupied in the tabstrip from the left most point
87 // (regardless of RTL or LTR mode) of the dragged view up to the mouse pointer
88 // when the drag was initiated.
89 int GetWidthInTabStripUpToMousePointer();
91 // Returns the distance from the start of the tabstrip (left, regardless of
92 // RTL) up to the position of the mouse pointer.
93 gfx::Point
GetDistanceFromTabStripOriginToMousePointer();
96 // Overridden from gfx::AnimationDelegate:
97 virtual void AnimationProgressed(const gfx::Animation
* animation
) OVERRIDE
;
98 virtual void AnimationEnded(const gfx::Animation
* animation
) OVERRIDE
;
99 virtual void AnimationCanceled(const gfx::Animation
* animation
) OVERRIDE
;
101 // Arranges the contents of the dragged tab.
104 // Gets the preferred size of the dragged tab.
105 gfx::Size
GetPreferredSize();
107 // Resizes the container to fit the content for the current attachment mode.
108 void ResizeContainer();
110 // Utility for scaling a size by the current scaling factor.
111 int ScaleValue(int value
);
113 // Returns the bounds of the container window.
114 gfx::Rect
bounds() const;
116 // Sets the color map of the container window to allow the window to be
118 void SetContainerColorMap();
120 // Sets full transparency for the container window. This is used if
121 // compositing is available for the screen.
122 void SetContainerTransparency();
124 // Sets the shape mask for the container window to emulate a transparent
125 // container window. This is used if compositing is not available for the
127 // |surface| represents the tab only (not the render view).
128 void SetContainerShapeMask();
130 void PaintTab(int index
, GtkWidget
* widget
, cairo_t
* cr
, int widget_width
);
132 // expose-event handler that notifies when the tab needs to be redrawn.
133 CHROMEGTK_CALLBACK_1(DraggedViewGtk
, gboolean
, OnExpose
, GdkEventExpose
*);
135 // The window that contains the dragged tab or tab contents.
136 GtkWidget
* container_
;
138 // The fixed widget that we use to contain the tab renderer so that the
139 // tab widget won't be resized.
142 // The renderer that paints the dragged tab.
143 std::vector
<TabRendererGtk
*> renderers_
;
145 // Holds various data for each dragged tab needed to handle dragging. It is
146 // owned by |DraggedTabControllerGtk| class.
147 DragData
* drag_data_
;
149 // The width of a mini tab at the time the dragging was initiated.
152 // The width of a normal tab (not mini) at the time the dragging was
156 // True if the view is currently attached to a tabstrip. Controls rendering
160 // The width of the browser window where the dragged tabs were attached for
162 int parent_window_width_
;
164 // The unscaled offset of the mouse from the top left of the dragged tab.
165 // This is used to maintain an appropriate offset for the mouse pointer when
166 // dragging scaled and unscaled representations, and also to calculate the
167 // position of detached windows.
168 gfx::Point mouse_tab_offset_
;
170 // The size of the tab renderer when the dragged tab is attached to a
172 gfx::Size attached_tab_size_
;
174 // The dimensions of the WebContents being dragged.
175 gfx::Size contents_size_
;
177 // The animation used to slide the attached tab to its final location.
178 gfx::SlideAnimation close_animation_
;
180 // A callback notified when the animation is complete.
181 base::Closure animation_callback_
;
183 // The start and end bounds of the animation sequence.
184 gfx::Rect animation_start_bounds_
;
185 gfx::Rect animation_end_bounds_
;
187 DISALLOW_COPY_AND_ASSIGN(DraggedViewGtk
);
190 #endif // CHROME_BROWSER_UI_GTK_TABS_DRAGGED_VIEW_GTK_H_