OLD | NEW |
1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef CHROME_VIEWS_WIDGET_WIDGET_GTK_H_ | 5 #ifndef CHROME_VIEWS_WIDGET_WIDGET_GTK_H_ |
6 #define CHROME_VIEWS_WIDGET_WIDGET_GTK_H_ | 6 #define CHROME_VIEWS_WIDGET_WIDGET_GTK_H_ |
7 | 7 |
8 #include <gtk/gtk.h> | 8 #include <gtk/gtk.h> |
9 | 9 |
10 #include "base/message_loop.h" | 10 #include "base/message_loop.h" |
11 #include "chrome/views/widget/widget.h" | 11 #include "chrome/views/widget/widget.h" |
12 | 12 |
13 namespace gfx { | 13 namespace gfx { |
14 class Rect; | 14 class Rect; |
15 } | 15 } |
16 | 16 |
17 namespace views { | 17 namespace views { |
18 | 18 |
19 class View; | 19 class View; |
| 20 class WindowGtk; |
20 | 21 |
| 22 // Widget implementation for GTK. |
21 class WidgetGtk : public Widget { | 23 class WidgetGtk : public Widget { |
22 public: | 24 public: |
23 static WidgetGtk* Construct() { | 25 // Type of widget. |
24 // This isn't used, but exists to force WidgetGtk to be instantiable. | 26 enum Type { |
25 return new WidgetGtk; | 27 // Used for popup type windows (bubbles, menus ...). |
26 } | 28 TYPE_POPUP, |
27 | 29 |
28 WidgetGtk(); | 30 // A top level window. |
| 31 TYPE_WINDOW, |
| 32 |
| 33 // A child widget. |
| 34 TYPE_CHILD |
| 35 }; |
| 36 |
| 37 explicit WidgetGtk(Type type); |
29 virtual ~WidgetGtk(); | 38 virtual ~WidgetGtk(); |
30 | 39 |
31 // Initializes this widget and returns the gtk drawing area for the caller to | 40 // Initializes this widget. |
32 // add to its hierarchy. (We can't pass in the parent to this method because | |
33 // there are no standard adding semantics in gtk...) | |
34 void Init(const gfx::Rect& bounds, bool has_own_focus_manager); | 41 void Init(const gfx::Rect& bounds, bool has_own_focus_manager); |
35 | 42 |
| 43 void AddChild(GtkWidget* child); |
| 44 void RemoveChild(GtkWidget* child); |
| 45 |
| 46 // Positions a child GtkWidget at the specified location and bounds. |
| 47 void PositionChild(GtkWidget* child, int x, int y, int w, int h); |
| 48 |
| 49 // Parent GtkWidget all children are added to. This is not necessarily |
| 50 // the same as returned by GetNativeView. |
| 51 GtkWidget* child_widget_parent() const { return child_widget_parent_; } |
| 52 |
36 virtual void SetContentsView(View* view); | 53 virtual void SetContentsView(View* view); |
37 | 54 |
38 // Overridden from Widget: | 55 // Overridden from Widget: |
39 virtual void GetBounds(gfx::Rect* out, bool including_frame) const; | 56 virtual void GetBounds(gfx::Rect* out, bool including_frame) const; |
40 virtual gfx::NativeView GetNativeView() const; | 57 virtual gfx::NativeView GetNativeView() const; |
41 virtual void PaintNow(const gfx::Rect& update_rect); | 58 virtual void PaintNow(const gfx::Rect& update_rect); |
42 virtual RootView* GetRootView(); | 59 virtual RootView* GetRootView(); |
43 virtual bool IsVisible() const; | 60 virtual bool IsVisible() const; |
44 virtual bool IsActive() const; | 61 virtual bool IsActive() const; |
45 virtual TooltipManager* GetTooltipManager(); | 62 virtual TooltipManager* GetTooltipManager(); |
46 virtual bool GetAccelerator(int cmd_id, Accelerator* accelerator); | 63 virtual bool GetAccelerator(int cmd_id, Accelerator* accelerator); |
| 64 virtual Window* GetWindow(); |
| 65 virtual const Window* GetWindow() const; |
47 | 66 |
48 protected: | 67 protected: |
49 virtual void OnSizeAllocate(GtkWidget* widget, GtkAllocation* allocation) {} | 68 virtual void OnSizeAllocate(GtkWidget* widget, GtkAllocation* allocation); |
50 virtual gboolean OnPaint(GtkWidget* widget, GdkEventExpose* event); | 69 virtual void OnPaint(GtkWidget* widget, GdkEventExpose* event); |
51 virtual gboolean OnEnterNotify(GtkWidget* widget, GdkEventCrossing* event); | 70 virtual gboolean OnEnterNotify(GtkWidget* widget, GdkEventCrossing* event); |
52 virtual gboolean OnLeaveNotify(GtkWidget* widget, GdkEventCrossing* event); | 71 virtual gboolean OnLeaveNotify(GtkWidget* widget, GdkEventCrossing* event); |
53 virtual gboolean OnMotionNotify(GtkWidget* widget, GdkEventMotion* event); | 72 virtual gboolean OnMotionNotify(GtkWidget* widget, GdkEventMotion* event); |
54 virtual gboolean OnButtonPress(GtkWidget* widget, GdkEventButton* event); | 73 virtual gboolean OnButtonPress(GtkWidget* widget, GdkEventButton* event); |
55 virtual gboolean OnButtonRelease(GtkWidget* widget, GdkEventButton* event); | 74 virtual gboolean OnButtonRelease(GtkWidget* widget, GdkEventButton* event); |
56 virtual gboolean OnFocusIn(GtkWidget* widget, GdkEventFocus* event) { | 75 virtual gboolean OnFocusIn(GtkWidget* widget, GdkEventFocus* event) { |
57 return false; | 76 return false; |
58 } | 77 } |
59 virtual gboolean OnFocusOut(GtkWidget* widget, GdkEventFocus* event) { | 78 virtual gboolean OnFocusOut(GtkWidget* widget, GdkEventFocus* event) { |
60 return false; | 79 return false; |
61 } | 80 } |
62 virtual gboolean OnKeyPress(GtkWidget* widget, GdkEventKey* event); | 81 virtual gboolean OnKeyPress(GtkWidget* widget, GdkEventKey* event); |
63 virtual gboolean OnKeyRelease(GtkWidget* widget, GdkEventKey* event); | 82 virtual gboolean OnKeyRelease(GtkWidget* widget, GdkEventKey* event); |
64 virtual gboolean OnScroll(GtkWidget* widget, GdkEventScroll* event) { | 83 virtual gboolean OnScroll(GtkWidget* widget, GdkEventScroll* event) { |
65 return false; | 84 return false; |
66 } | 85 } |
67 virtual gboolean OnVisibilityNotify(GtkWidget* widget, | 86 virtual gboolean OnVisibilityNotify(GtkWidget* widget, |
68 GdkEventVisibility* event) { | 87 GdkEventVisibility* event) { |
69 return false; | 88 return false; |
70 } | 89 } |
71 | 90 |
| 91 // Sets and retrieves the WidgetGtk in the userdata section of the widget. |
| 92 static WindowGtk* GetWindowForNative(GtkWidget* widget); |
| 93 static void SetWindowForNative(GtkWidget* widget, WindowGtk* window); |
| 94 |
72 private: | 95 private: |
73 virtual RootView* CreateRootView(); | 96 virtual RootView* CreateRootView(); |
74 | 97 |
75 // Process a mouse click | 98 // Process a mouse click |
76 bool ProcessMousePressed(GdkEventButton* event); | 99 bool ProcessMousePressed(GdkEventButton* event); |
77 void ProcessMouseReleased(GdkEventButton* event); | 100 void ProcessMouseReleased(GdkEventButton* event); |
78 | 101 |
79 // Sets and retrieves the WidgetGtk in the userdata section of the widget. | 102 // Sets and retrieves the WidgetGtk in the userdata section of the widget. |
80 static WidgetGtk* GetViewForNative(GtkWidget* widget); | 103 static WidgetGtk* GetViewForNative(GtkWidget* widget); |
81 static void SetViewForNative(GtkWidget* widget, WidgetGtk* view); | 104 static void SetViewForNative(GtkWidget* widget, WidgetGtk* view); |
(...skipping 10 matching lines...) Expand all Loading... |
92 static gboolean CallButtonPress(GtkWidget* widget, GdkEventButton* event); | 115 static gboolean CallButtonPress(GtkWidget* widget, GdkEventButton* event); |
93 static gboolean CallButtonRelease(GtkWidget* widget, GdkEventButton* event); | 116 static gboolean CallButtonRelease(GtkWidget* widget, GdkEventButton* event); |
94 static gboolean CallFocusIn(GtkWidget* widget, GdkEventFocus* event); | 117 static gboolean CallFocusIn(GtkWidget* widget, GdkEventFocus* event); |
95 static gboolean CallFocusOut(GtkWidget* widget, GdkEventFocus* event); | 118 static gboolean CallFocusOut(GtkWidget* widget, GdkEventFocus* event); |
96 static gboolean CallKeyPress(GtkWidget* widget, GdkEventKey* event); | 119 static gboolean CallKeyPress(GtkWidget* widget, GdkEventKey* event); |
97 static gboolean CallKeyRelease(GtkWidget* widget, GdkEventKey* event); | 120 static gboolean CallKeyRelease(GtkWidget* widget, GdkEventKey* event); |
98 static gboolean CallScroll(GtkWidget* widget, GdkEventScroll* event); | 121 static gboolean CallScroll(GtkWidget* widget, GdkEventScroll* event); |
99 static gboolean CallVisibilityNotify(GtkWidget* widget, | 122 static gboolean CallVisibilityNotify(GtkWidget* widget, |
100 GdkEventVisibility* event); | 123 GdkEventVisibility* event); |
101 | 124 |
102 // Our native view. | 125 static Window* GetWindowImpl(GtkWidget* widget); |
| 126 |
| 127 // Creates the GtkWidget. |
| 128 void CreateGtkWidget(); |
| 129 |
| 130 const Type type_; |
| 131 |
| 132 // Our native views. If we're a window/popup, then widget_ is the window and |
| 133 // child_widget_parent_ is a GtkFixed. If we're not a window/popup, then |
| 134 // widget_ and child_widget_parent_ are a GtkFixed. |
103 GtkWidget* widget_; | 135 GtkWidget* widget_; |
| 136 GtkWidget* child_widget_parent_; |
104 | 137 |
105 // The root of the View hierarchy attached to this window. | 138 // The root of the View hierarchy attached to this window. |
106 scoped_ptr<RootView> root_view_; | 139 scoped_ptr<RootView> root_view_; |
107 | 140 |
108 // If true, the mouse is currently down. | 141 // If true, the mouse is currently down. |
109 bool is_mouse_down_; | 142 bool is_mouse_down_; |
110 | 143 |
111 // The following are used to detect duplicate mouse move events and not | 144 // The following are used to detect duplicate mouse move events and not |
112 // deliver them. Displaying a window may result in the system generating | 145 // deliver them. Displaying a window may result in the system generating |
113 // duplicate move events even though the mouse hasn't moved. | 146 // duplicate move events even though the mouse hasn't moved. |
114 | 147 |
115 // If true, the last event was a mouse move event. | 148 // If true, the last event was a mouse move event. |
116 bool last_mouse_event_was_move_; | 149 bool last_mouse_event_was_move_; |
117 | 150 |
118 // Coordinates of the last mouse move event, in screen coordinates. | 151 // Coordinates of the last mouse move event, in screen coordinates. |
119 int last_mouse_move_x_; | 152 int last_mouse_move_x_; |
120 int last_mouse_move_y_; | 153 int last_mouse_move_y_; |
| 154 |
| 155 DISALLOW_COPY_AND_ASSIGN(WidgetGtk); |
121 }; | 156 }; |
122 | 157 |
123 } // namespace views | 158 } // namespace views |
124 | 159 |
125 #endif // CHROME_VIEWS_WIDGET_WIDGET_GTK_H_ | 160 #endif // CHROME_VIEWS_WIDGET_WIDGET_GTK_H_ |
OLD | NEW |