OLD | NEW |
(Empty) | |
| 1 // Copyright (c) 2010 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_TAB_GTK_H_ |
| 6 #define CHROME_BROWSER_UI_GTK_TABS_TAB_GTK_H_ |
| 7 #pragma once |
| 8 |
| 9 #include "app/gtk_signal.h" |
| 10 #include "base/basictypes.h" |
| 11 #include "base/message_loop.h" |
| 12 #include "chrome/browser/gtk/tabs/tab_renderer_gtk.h" |
| 13 #include "chrome/browser/tabs/tab_strip_model.h" |
| 14 |
| 15 namespace gfx { |
| 16 class Path; |
| 17 } |
| 18 |
| 19 class ThemeProvider; |
| 20 |
| 21 class TabGtk : public TabRendererGtk, |
| 22 public MessageLoopForUI::Observer { |
| 23 public: |
| 24 // An interface implemented by an object that can help this Tab complete |
| 25 // various actions. The index parameter is the index of this Tab in the |
| 26 // TabRenderer::Model. |
| 27 class TabDelegate { |
| 28 public: |
| 29 // Returns true if the specified Tab is selected. |
| 30 virtual bool IsTabSelected(const TabGtk* tab) const = 0; |
| 31 |
| 32 // Returns true if the specified Tab is pinned. |
| 33 virtual bool IsTabPinned(const TabGtk* tab) const = 0; |
| 34 |
| 35 // Returns true if the specified Tab is detached. |
| 36 virtual bool IsTabDetached(const TabGtk* tab) const = 0; |
| 37 |
| 38 // Selects the specified Tab. |
| 39 virtual void SelectTab(TabGtk* tab) = 0; |
| 40 |
| 41 // Closes the specified Tab. |
| 42 virtual void CloseTab(TabGtk* tab) = 0; |
| 43 |
| 44 // Returns true if the specified command is enabled for the specified Tab. |
| 45 virtual bool IsCommandEnabledForTab( |
| 46 TabStripModel::ContextMenuCommand command_id, |
| 47 const TabGtk* tab) const = 0; |
| 48 |
| 49 // Executes the specified command for the specified Tab. |
| 50 virtual void ExecuteCommandForTab( |
| 51 TabStripModel::ContextMenuCommand command_id, TabGtk* tab) = 0; |
| 52 |
| 53 // Starts/Stops highlighting the tabs that will be affected by the |
| 54 // specified command for the specified Tab. |
| 55 virtual void StartHighlightTabsForCommand( |
| 56 TabStripModel::ContextMenuCommand command_id, TabGtk* tab) = 0; |
| 57 virtual void StopHighlightTabsForCommand( |
| 58 TabStripModel::ContextMenuCommand command_id, TabGtk* tab) = 0; |
| 59 virtual void StopAllHighlighting() = 0; |
| 60 |
| 61 // Potentially starts a drag for the specified Tab. |
| 62 virtual void MaybeStartDrag(TabGtk* tab, const gfx::Point& point) = 0; |
| 63 |
| 64 // Continues dragging a Tab. |
| 65 virtual void ContinueDrag(GdkDragContext* context) = 0; |
| 66 |
| 67 // Ends dragging a Tab. |canceled| is true if the drag was aborted in a way |
| 68 // other than the user releasing the mouse. Returns whether the tab has been |
| 69 // destroyed. |
| 70 virtual bool EndDrag(bool canceled) = 0; |
| 71 |
| 72 // Returns true if the associated TabStrip's delegate supports tab moving or |
| 73 // detaching. Used by the Frame to determine if dragging on the Tab |
| 74 // itself should move the window in cases where there's only one |
| 75 // non drag-able Tab. |
| 76 virtual bool HasAvailableDragActions() const = 0; |
| 77 |
| 78 // Returns the theme provider for icons and colors. |
| 79 virtual ThemeProvider* GetThemeProvider() = 0; |
| 80 |
| 81 protected: |
| 82 virtual ~TabDelegate() {} |
| 83 }; |
| 84 |
| 85 explicit TabGtk(TabDelegate* delegate); |
| 86 virtual ~TabGtk(); |
| 87 |
| 88 // Access the delegate. |
| 89 TabDelegate* delegate() const { return delegate_; } |
| 90 |
| 91 GtkWidget* widget() const { return event_box_; } |
| 92 |
| 93 // Used to set/check whether this Tab is being animated closed. |
| 94 void set_closing(bool closing) { closing_ = closing; } |
| 95 bool closing() const { return closing_; } |
| 96 |
| 97 // Used to set/check whether this Tab is being dragged. |
| 98 void set_dragging(bool dragging) { dragging_ = dragging; } |
| 99 bool dragging() const { return dragging_; } |
| 100 |
| 101 // TabRendererGtk overrides: |
| 102 virtual bool IsSelected() const; |
| 103 virtual bool IsVisible() const; |
| 104 virtual void SetVisible(bool visible) const; |
| 105 virtual void CloseButtonClicked(); |
| 106 virtual void UpdateData(TabContents* contents, bool app, bool loading_only); |
| 107 virtual void SetBounds(const gfx::Rect& bounds); |
| 108 |
| 109 private: |
| 110 class ContextMenuController; |
| 111 class TabGtkObserverHelper; |
| 112 friend class ContextMenuController; |
| 113 |
| 114 // MessageLoop::Observer implementation: |
| 115 virtual void WillProcessEvent(GdkEvent* event); |
| 116 virtual void DidProcessEvent(GdkEvent* event); |
| 117 |
| 118 // button-press-event handler that handles mouse clicks. |
| 119 CHROMEGTK_CALLBACK_1(TabGtk, gboolean, OnButtonPressEvent, GdkEventButton*); |
| 120 |
| 121 // button-release-event handler that handles mouse click releases. |
| 122 CHROMEGTK_CALLBACK_1(TabGtk, gboolean, OnButtonReleaseEvent, GdkEventButton*); |
| 123 |
| 124 // drag-begin is emitted when the drag is started. We connect so that we can |
| 125 // set the drag icon to a transparent pixbuf. |
| 126 CHROMEGTK_CALLBACK_1(TabGtk, void, OnDragBegin, GdkDragContext*); |
| 127 |
| 128 // drag-failed is emitted when the drag is finished. In our case the signal |
| 129 // does not imply failure as we don't use the drag-n-drop API to transfer drop |
| 130 // data. |
| 131 CHROMEGTK_CALLBACK_2(TabGtk, gboolean, OnDragFailed, GdkDragContext*, |
| 132 GtkDragResult); |
| 133 |
| 134 // When a drag is ending, a fake button release event is passed to the drag |
| 135 // widget to fake letting go of the mouse button. We need a callback for |
| 136 // this event because it is the only way to catch drag end events when the |
| 137 // user presses space or return. |
| 138 CHROMEGTK_CALLBACK_1(TabGtk, gboolean, OnDragButtonReleased, GdkEventButton*); |
| 139 |
| 140 // Shows the context menu. |
| 141 void ShowContextMenu(); |
| 142 |
| 143 // Invoked when the context menu closes. |
| 144 void ContextMenuClosed(); |
| 145 |
| 146 // Sets whether the tooltip should be shown or not, depending on the size of |
| 147 // the tab. |
| 148 void UpdateTooltipState(); |
| 149 |
| 150 // Creates the drag widget used to track a drag operation. |
| 151 void CreateDragWidget(); |
| 152 |
| 153 // Destroys the drag widget. |
| 154 void DestroyDragWidget(); |
| 155 |
| 156 // Starts the dragging operation. |drag_offset| is the offset inside the tab |
| 157 // bounds where the grab occurred. |
| 158 void StartDragging(gfx::Point drag_offset); |
| 159 |
| 160 // Ends the dragging operations. |canceled| is true if the operation was |
| 161 // canceled. |
| 162 void EndDrag(bool canceled); |
| 163 |
| 164 // An instance of a delegate object that can perform various actions based on |
| 165 // user gestures. |
| 166 TabDelegate* delegate_; |
| 167 |
| 168 // True if the tab is being animated closed. |
| 169 bool closing_; |
| 170 |
| 171 // True if the tab is being dragged. |
| 172 bool dragging_; |
| 173 |
| 174 // The context menu controller. |
| 175 scoped_ptr<ContextMenuController> menu_controller_; |
| 176 |
| 177 // The windowless widget used to collect input events for the tab. We can't |
| 178 // use an OwnedWidgetGtk because of the way the dragged tab controller |
| 179 // destroys the source tab. The source tab is destroyed when the drag ends |
| 180 // before we let gtk handle the end of the drag. This results in the widget |
| 181 // having an extra reference, which will cause OwnedWidgetGtk.Destroy to |
| 182 // DCHECK. |
| 183 GtkWidget* event_box_; |
| 184 |
| 185 // A copy of the last button press event, used to initiate a drag. |
| 186 GdkEvent* last_mouse_down_; |
| 187 |
| 188 // A GtkInivisible used to track the drag event. GtkInvisibles are of the |
| 189 // type GInitiallyUnowned, but the widget initialization code sinks the |
| 190 // reference, so we can't used an OwnedWidgetGtk here. |
| 191 GtkWidget* drag_widget_; |
| 192 |
| 193 // The cached width of the title in pixels, updated whenever the title |
| 194 // changes. |
| 195 int title_width_; |
| 196 |
| 197 // Keep track of whether or not we have an observer. |
| 198 scoped_ptr<TabGtkObserverHelper> observer_; |
| 199 |
| 200 // Used to destroy the drag widget after a return to the message loop. |
| 201 ScopedRunnableMethodFactory<TabGtk> destroy_factory_; |
| 202 |
| 203 // Due to a bug in GTK+, we need to force the end of a drag when we get a |
| 204 // mouse release event on the the dragged widget, otherwise, we don't know |
| 205 // when the drag has ended when the user presses space or enter. We queue |
| 206 // a task to end the drag and only run it if GTK+ didn't send us the |
| 207 // drag-failed event. |
| 208 ScopedRunnableMethodFactory<TabGtk> drag_end_factory_; |
| 209 |
| 210 DISALLOW_COPY_AND_ASSIGN(TabGtk); |
| 211 }; |
| 212 |
| 213 #endif // CHROME_BROWSER_UI_GTK_TABS_TAB_GTK_H_ |
OLD | NEW |