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_PANELS_PANEL_DRAG_GTK_H_
6 #define CHROME_BROWSER_UI_GTK_PANELS_PANEL_DRAG_GTK_H_
10 #include "base/basictypes.h"
11 #include "base/compiler_specific.h"
12 #include "ui/base/gtk/gtk_signal.h"
15 class PanelDragDelegate
;
17 // Class for GTK handling of move-drag and resize-drag on a panel.
18 // Only one type of drag may be active at any time.
19 // Dragging only begins if the mouse is moved beyond the drag threshold.
20 // If mouse is released without exceeding the drag threshold, the mouse
21 // press and release is treated as a mouse click.
24 explicit PanelDragGtk(Panel
* panel
);
27 GtkWidget
* widget() const { return drag_widget_
; }
29 // Sets up mouse and keyboard events processing while the mouse
30 // is pressed on a window edge.
31 // |event| is the mouse press event.
32 // |cursor| is the cursor to display during the drag.
33 // |edge| is the window edge from which to resize the panel.
34 void InitialWindowEdgeMousePress(GdkEventButton
* event
, GdkCursor
* cursor
,
37 // Sets up mouse and keyboard events processing while the mouse is
38 // pressed on the titlebar.
39 // |event| is the mouse press event.
40 // |titlebar_widget| should handle the mouse release event if the mouse
41 // is released without exceeding the drag threshold (a mouse click).
42 void InitialTitlebarMousePress(GdkEventButton
* event
,
43 GtkWidget
* titlebar_widget
);
46 friend class GtkNativePanelTesting
;
50 DRAG_CAN_START
, // mouse pressed
51 DRAG_IN_PROGRESS
, // mouse moved beyond drag threshold
52 DRAG_ENDED_WAITING_FOR_MOUSE_RELEASE
55 // Callbacks for GTK mouse and key events.
56 CHROMEGTK_CALLBACK_1(PanelDragGtk
, gboolean
, OnMouseMoveEvent
,
58 CHROMEGTK_CALLBACK_1(PanelDragGtk
, gboolean
, OnButtonPressEvent
,
60 CHROMEGTK_CALLBACK_1(PanelDragGtk
, gboolean
, OnButtonReleaseEvent
,
62 CHROMEGTK_CALLBACK_1(PanelDragGtk
, gboolean
, OnKeyPressEvent
,
64 CHROMEGTK_CALLBACK_1(PanelDragGtk
, gboolean
, OnKeyReleaseEvent
,
66 CHROMEGTK_CALLBACK_1(PanelDragGtk
, gboolean
, OnGrabBrokenEvent
,
69 // Utility to dcheck a bunch of state to ensure a clean slate.
70 // Returns only if all the dchecks pass.
71 void AssertCleanState();
73 void GrabPointerAndKeyboard(GdkEventButton
* event
,
75 void ReleasePointerAndKeyboardGrab();
77 // Ends any drag that is currently in progress (if any).
78 // Resets all drag state except for pointer and keyboard grabs.
79 // The grabs are released when the mouse is released to prevent a
80 // mouse release *after* the drag has ended (e.g. via ESC key) from
81 // being treated as a mouse click.
82 void EndDrag(bool canceled
);
84 // Weak pointer to the panel being dragged.
87 // Invisible event box to receive mouse and key events.
88 GtkWidget
* drag_widget_
;
90 DragState drag_state_
;
92 // A copy of the initial button press event.
93 GdkEvent
* initial_mouse_down_
;
95 // Widget that should process the mouse click if mouse is released
96 // without exceeding the drag threshold. May be NULL if no click
97 // handling is necessary.
98 GtkWidget
* click_handler_
;
100 // Delegate for processing drag depends on actual type of drag.
101 PanelDragDelegate
* drag_delegate_
;
103 DISALLOW_COPY_AND_ASSIGN(PanelDragGtk
);
106 #endif // CHROME_BROWSER_UI_GTK_PANELS_PANEL_DRAG_GTK_H_