1 // Copyright (c) 2011 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 CHROME_BROWSER_UI_GTK_TABS_DRAGGED_TAB_GTK_H_ 6 #define CHROME_BROWSER_UI_GTK_TABS_DRAGGED_TAB_GTK_H_ 7 #pragma once 8 9 #include <gtk/gtk.h> 10 11 #include "base/callback.h" 12 #include "base/memory/scoped_ptr.h" 13 #include "base/task.h" 14 #include "ui/base/animation/animation_delegate.h" 15 #include "ui/base/animation/slide_animation.h" 16 #include "ui/gfx/canvas.h" 17 #include "ui/gfx/point.h" 18 #include "ui/gfx/rect.h" 19 #include "ui/gfx/size.h" 20 21 class TabContents; 22 class TabRendererGtk; 23 24 class DraggedTabGtk : public ui::AnimationDelegate { 25 public: 26 DraggedTabGtk(TabContents* datasource, 27 const gfx::Point& mouse_tab_offset, 28 const gfx::Size& contents_size, 29 bool mini); 30 virtual ~DraggedTabGtk(); 31 32 // Moves the dragged tab to the appropriate location given the mouse 33 // pointer at |screen_point|. 34 void MoveTo(const gfx::Point& screen_point); 35 36 // Sets the offset of the mouse from the upper left corner of the tab. 37 void set_mouse_tab_offset(const gfx::Point& offset) { 38 mouse_tab_offset_ = offset; 39 } 40 41 // Notifies the dragged tab that it has become attached to a tabstrip. 42 void Attach(int selected_width); 43 44 // Resizes the dragged tab to a width of |width|. 45 void Resize(int width); 46 47 // Notifies the dragged tab that it has been detached from a tabstrip. 48 void Detach(); 49 50 // Notifies the dragged tab that it should update itself. 51 void Update(); 52 53 // Animates the dragged tab to the specified bounds, then calls back to 54 // |callback|. 55 typedef Callback0::Type AnimateToBoundsCallback; 56 void AnimateToBounds(const gfx::Rect& bounds, 57 AnimateToBoundsCallback* callback); 58 59 // Returns the size of the dragged tab. Used when attaching to a tabstrip 60 // to determine where to place the tab in the attached tabstrip. 61 const gfx::Size& attached_tab_size() const { return attached_tab_size_; } 62 63 GtkWidget* widget() const { return container_; } 64 65 private: 66 // Overridden from ui::AnimationDelegate: 67 virtual void AnimationProgressed(const ui::Animation* animation); 68 virtual void AnimationEnded(const ui::Animation* animation); 69 virtual void AnimationCanceled(const ui::Animation* animation); 70 71 // Arranges the contents of the dragged tab. 72 void Layout(); 73 74 // Gets the preferred size of the dragged tab. 75 gfx::Size GetPreferredSize(); 76 77 // Resizes the container to fit the content for the current attachment mode. 78 void ResizeContainer(); 79 80 // Utility for scaling a size by the current scaling factor. 81 int ScaleValue(int value); 82 83 // Returns the bounds of the container window. 84 gfx::Rect bounds() const; 85 86 // Sets the color map of the container window to allow the window to be 87 // transparent. 88 void SetContainerColorMap(); 89 90 // Sets full transparency for the container window. This is used if 91 // compositing is available for the screen. 92 void SetContainerTransparency(); 93 94 // Sets the shape mask for the container window to emulate a transparent 95 // container window. This is used if compositing is not available for the 96 // screen. 97 // |surface| represents the tab only (not the render view). 98 void SetContainerShapeMask(cairo_surface_t* surface); 99 100 // expose-event handler that notifies when the tab needs to be redrawn. 101 static gboolean OnExposeEvent(GtkWidget* widget, GdkEventExpose* event, 102 DraggedTabGtk* dragged_tab); 103 104 // The tab contents that the dragged tab contains. 105 TabContents* data_source_; 106 107 // The window that contains the dragged tab or tab contents. 108 GtkWidget* container_; 109 110 // The fixed widget that we use to contain the tab renderer so that the 111 // tab widget won't be resized. 112 GtkWidget* fixed_; 113 114 // The renderer that paints the dragged tab. 115 scoped_ptr<TabRendererGtk> renderer_; 116 117 // True if the view is currently attached to a tabstrip. Controls rendering 118 // and sizing modes. 119 bool attached_; 120 121 // The unscaled offset of the mouse from the top left of the dragged tab. 122 // This is used to maintain an appropriate offset for the mouse pointer when 123 // dragging scaled and unscaled representations, and also to calculate the 124 // position of detached windows. 125 gfx::Point mouse_tab_offset_; 126 127 // The size of the tab renderer when the dragged tab is attached to a 128 // tabstrip. 129 gfx::Size attached_tab_size_; 130 131 // The dimensions of the TabContents being dragged. 132 gfx::Size contents_size_; 133 134 // The animation used to slide the attached tab to its final location. 135 ui::SlideAnimation close_animation_; 136 137 // A callback notified when the animation is complete. 138 scoped_ptr<Callback0::Type> animation_callback_; 139 140 // The start and end bounds of the animation sequence. 141 gfx::Rect animation_start_bounds_; 142 gfx::Rect animation_end_bounds_; 143 144 DISALLOW_COPY_AND_ASSIGN(DraggedTabGtk); 145 }; 146 147 #endif // CHROME_BROWSER_UI_GTK_TABS_DRAGGED_TAB_GTK_H_ 148