| 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 CHROME_BROWSER_UI_GTK_TABS_DRAGGED_VIEW_GTK_H_ | |
| 6 #define CHROME_BROWSER_UI_GTK_TABS_DRAGGED_VIEW_GTK_H_ | |
| 7 | |
| 8 #include <gtk/gtk.h> | |
| 9 | |
| 10 #include <vector> | |
| 11 | |
| 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" | |
| 21 | |
| 22 class DragData; | |
| 23 class TabRendererGtk; | |
| 24 | |
| 25 class DraggedViewGtk : public gfx::AnimationDelegate { | |
| 26 public: | |
| 27 DraggedViewGtk(DragData* drag_data, | |
| 28 const gfx::Point& mouse_tab_offset, | |
| 29 const gfx::Size& contents_size); | |
| 30 virtual ~DraggedViewGtk(); | |
| 31 | |
| 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); | |
| 36 | |
| 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); | |
| 40 | |
| 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; | |
| 44 } | |
| 45 | |
| 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); | |
| 51 | |
| 52 // Resizes the dragged tab to a width of |width|. | |
| 53 void Resize(int width); | |
| 54 | |
| 55 // Notifies the dragged tab that it has been detached from a tabstrip. | |
| 56 void Detach(); | |
| 57 | |
| 58 // Notifies the dragged tab that it should update itself. | |
| 59 void Update(); | |
| 60 | |
| 61 // Animates the dragged tab to the specified bounds, then calls back to | |
| 62 // |callback|. | |
| 63 void AnimateToBounds(const gfx::Rect& bounds, const base::Closure& callback); | |
| 64 | |
| 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); | |
| 69 | |
| 70 GtkWidget* widget() const { return container_; } | |
| 71 | |
| 72 int mini_width() { return mini_width_; } | |
| 73 int normal_width() { return normal_width_; } | |
| 74 | |
| 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); | |
| 78 | |
| 79 // Returns the total width occupied in the tabstrip. | |
| 80 int GetTotalWidthInTabStrip(); | |
| 81 | |
| 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(); | |
| 85 | |
| 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(); | |
| 90 | |
| 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(); | |
| 94 | |
| 95 private: | |
| 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; | |
| 100 | |
| 101 // Arranges the contents of the dragged tab. | |
| 102 void Layout(); | |
| 103 | |
| 104 // Gets the preferred size of the dragged tab. | |
| 105 gfx::Size GetPreferredSize(); | |
| 106 | |
| 107 // Resizes the container to fit the content for the current attachment mode. | |
| 108 void ResizeContainer(); | |
| 109 | |
| 110 // Utility for scaling a size by the current scaling factor. | |
| 111 int ScaleValue(int value); | |
| 112 | |
| 113 // Returns the bounds of the container window. | |
| 114 gfx::Rect bounds() const; | |
| 115 | |
| 116 // Sets the color map of the container window to allow the window to be | |
| 117 // transparent. | |
| 118 void SetContainerColorMap(); | |
| 119 | |
| 120 // Sets full transparency for the container window. This is used if | |
| 121 // compositing is available for the screen. | |
| 122 void SetContainerTransparency(); | |
| 123 | |
| 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 | |
| 126 // screen. | |
| 127 // |surface| represents the tab only (not the render view). | |
| 128 void SetContainerShapeMask(); | |
| 129 | |
| 130 void PaintTab(int index, GtkWidget* widget, cairo_t* cr, int widget_width); | |
| 131 | |
| 132 // expose-event handler that notifies when the tab needs to be redrawn. | |
| 133 CHROMEGTK_CALLBACK_1(DraggedViewGtk, gboolean, OnExpose, GdkEventExpose*); | |
| 134 | |
| 135 // The window that contains the dragged tab or tab contents. | |
| 136 GtkWidget* container_; | |
| 137 | |
| 138 // The fixed widget that we use to contain the tab renderer so that the | |
| 139 // tab widget won't be resized. | |
| 140 GtkWidget* fixed_; | |
| 141 | |
| 142 // The renderer that paints the dragged tab. | |
| 143 std::vector<TabRendererGtk*> renderers_; | |
| 144 | |
| 145 // Holds various data for each dragged tab needed to handle dragging. It is | |
| 146 // owned by |DraggedTabControllerGtk| class. | |
| 147 DragData* drag_data_; | |
| 148 | |
| 149 // The width of a mini tab at the time the dragging was initiated. | |
| 150 int mini_width_; | |
| 151 | |
| 152 // The width of a normal tab (not mini) at the time the dragging was | |
| 153 // initiated. | |
| 154 int normal_width_; | |
| 155 | |
| 156 // True if the view is currently attached to a tabstrip. Controls rendering | |
| 157 // and sizing modes. | |
| 158 bool attached_; | |
| 159 | |
| 160 // The width of the browser window where the dragged tabs were attached for | |
| 161 // the last time. | |
| 162 int parent_window_width_; | |
| 163 | |
| 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_; | |
| 169 | |
| 170 // The size of the tab renderer when the dragged tab is attached to a | |
| 171 // tabstrip. | |
| 172 gfx::Size attached_tab_size_; | |
| 173 | |
| 174 // The dimensions of the WebContents being dragged. | |
| 175 gfx::Size contents_size_; | |
| 176 | |
| 177 // The animation used to slide the attached tab to its final location. | |
| 178 gfx::SlideAnimation close_animation_; | |
| 179 | |
| 180 // A callback notified when the animation is complete. | |
| 181 base::Closure animation_callback_; | |
| 182 | |
| 183 // The start and end bounds of the animation sequence. | |
| 184 gfx::Rect animation_start_bounds_; | |
| 185 gfx::Rect animation_end_bounds_; | |
| 186 | |
| 187 DISALLOW_COPY_AND_ASSIGN(DraggedViewGtk); | |
| 188 }; | |
| 189 | |
| 190 #endif // CHROME_BROWSER_UI_GTK_TABS_DRAGGED_VIEW_GTK_H_ | |
| OLD | NEW |