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 #include "chrome/views/widget/widget_gtk.h" | 5 #include "chrome/views/widget/widget_gtk.h" |
6 | 6 |
7 #include "chrome/views/fill_layout.h" | 7 #include "chrome/views/fill_layout.h" |
8 #include "chrome/views/widget/root_view.h" | 8 #include "chrome/views/widget/root_view.h" |
9 #include "chrome/views/window/window_gtk.h" | |
9 | 10 |
10 namespace views { | 11 namespace views { |
11 | 12 |
12 WidgetGtk::WidgetGtk() | 13 // Returns the position of a widget on screen. |
13 : widget_(NULL), | 14 static void GetWidgetPositionOnScreen(GtkWidget* widget, int* x, int *y) { |
15 GtkWidget* parent = widget; | |
16 while (parent) { | |
17 if (GTK_IS_WINDOW(widget)) { | |
18 int window_x, window_y; | |
19 gtk_window_get_position(GTK_WINDOW(widget), &window_x, &window_y); | |
20 *x += window_x; | |
21 *y += window_y; | |
22 return; | |
23 } | |
24 // Not a window. | |
25 *x += widget->allocation.x; | |
26 *y += widget->allocation.y; | |
27 parent = gtk_widget_get_parent(parent); | |
28 } | |
29 } | |
30 | |
31 WidgetGtk::WidgetGtk(Type type) | |
32 : type_(type), | |
33 widget_(NULL), | |
34 child_widget_parent_(NULL), | |
14 is_mouse_down_(false), | 35 is_mouse_down_(false), |
15 last_mouse_event_was_move_(false) { | 36 last_mouse_event_was_move_(false) { |
16 } | 37 } |
17 | 38 |
18 WidgetGtk::~WidgetGtk() { | 39 WidgetGtk::~WidgetGtk() { |
19 gtk_widget_unref(widget_); | 40 if (widget_) { |
20 | 41 // TODO: make sure this is right. |
42 gtk_widget_destroy(widget_); | |
43 child_widget_parent_ = widget_ = NULL; | |
44 } | |
21 // MessageLoopForUI::current()->RemoveObserver(this); | 45 // MessageLoopForUI::current()->RemoveObserver(this); |
22 } | 46 } |
23 | 47 |
24 void WidgetGtk::Init(const gfx::Rect& bounds, | 48 void WidgetGtk::Init(const gfx::Rect& bounds, |
25 bool has_own_focus_manager) { | 49 bool has_own_focus_manager) { |
26 | |
27 // Force creation of the RootView if it hasn't been created yet. | 50 // Force creation of the RootView if it hasn't been created yet. |
28 GetRootView(); | 51 GetRootView(); |
29 | 52 |
30 // Make container here. | 53 // Make container here. |
31 widget_ = gtk_drawing_area_new(); | 54 CreateGtkWidget(); |
32 gtk_drawing_area_size(GTK_DRAWING_AREA(widget_), 100, 100); | |
33 gtk_widget_show(widget_); | |
34 | 55 |
35 // Make sure we receive our motion events. | 56 // Make sure we receive our motion events. |
36 gtk_widget_set_events(widget_, | 57 |
37 gtk_widget_get_events(widget_) | | 58 // We register everything on the parent of all widgets. At a minimum we need |
59 // painting to happen on the parent (otherwise painting doesn't work at all), | |
60 // and similarly we need mouse release events on the parent as windows don't | |
61 // get mouse releases. | |
62 gtk_widget_add_events(child_widget_parent_, | |
38 GDK_ENTER_NOTIFY_MASK | | 63 GDK_ENTER_NOTIFY_MASK | |
39 GDK_LEAVE_NOTIFY_MASK | | 64 GDK_LEAVE_NOTIFY_MASK | |
40 GDK_BUTTON_PRESS_MASK | | 65 GDK_BUTTON_PRESS_MASK | |
41 GDK_BUTTON_RELEASE_MASK | | 66 GDK_BUTTON_RELEASE_MASK | |
42 GDK_POINTER_MOTION_MASK | | 67 GDK_POINTER_MOTION_MASK | |
43 GDK_KEY_PRESS_MASK | | 68 GDK_KEY_PRESS_MASK | |
44 GDK_KEY_RELEASE_MASK); | 69 GDK_KEY_RELEASE_MASK); |
45 | 70 |
46 root_view_->OnWidgetCreated(); | 71 root_view_->OnWidgetCreated(); |
47 | 72 |
48 // TODO(port): if(has_own_focus_manager) block | 73 // TODO(port): if(has_own_focus_manager) block |
49 | 74 |
50 SetViewForNative(widget_, this); | |
51 SetRootViewForWidget(widget_, root_view_.get()); | 75 SetRootViewForWidget(widget_, root_view_.get()); |
52 | 76 |
53 // MessageLoopForUI::current()->AddObserver(this); | 77 // MessageLoopForUI::current()->AddObserver(this); |
54 | 78 |
55 g_signal_connect_after(G_OBJECT(widget_), "size_allocate", | 79 g_signal_connect_after(G_OBJECT(child_widget_parent_), "size_allocate", |
56 G_CALLBACK(CallSizeAllocate), NULL); | 80 G_CALLBACK(CallSizeAllocate), NULL); |
57 g_signal_connect(G_OBJECT(widget_), "expose_event", | 81 g_signal_connect(G_OBJECT(child_widget_parent_), "expose_event", |
58 G_CALLBACK(CallPaint), NULL); | 82 G_CALLBACK(CallPaint), NULL); |
59 g_signal_connect(G_OBJECT(widget_), "enter_notify_event", | 83 g_signal_connect(G_OBJECT(child_widget_parent_), "enter_notify_event", |
60 G_CALLBACK(CallEnterNotify), NULL); | 84 G_CALLBACK(CallEnterNotify), NULL); |
61 g_signal_connect(G_OBJECT(widget_), "leave_notify_event", | 85 g_signal_connect(G_OBJECT(child_widget_parent_), "leave_notify_event", |
62 G_CALLBACK(CallLeaveNotify), NULL); | 86 G_CALLBACK(CallLeaveNotify), NULL); |
63 g_signal_connect(G_OBJECT(widget_), "motion_notify_event", | 87 g_signal_connect(G_OBJECT(child_widget_parent_), "motion_notify_event", |
64 G_CALLBACK(CallMotionNotify), NULL); | 88 G_CALLBACK(CallMotionNotify), NULL); |
65 g_signal_connect(G_OBJECT(widget_), "button_press_event", | 89 g_signal_connect(G_OBJECT(child_widget_parent_), "button_press_event", |
66 G_CALLBACK(CallButtonPress), NULL); | 90 G_CALLBACK(CallButtonPress), NULL); |
67 g_signal_connect(G_OBJECT(widget_), "button_release_event", | 91 g_signal_connect(G_OBJECT(child_widget_parent_), "button_release_event", |
68 G_CALLBACK(CallButtonRelease), NULL); | 92 G_CALLBACK(CallButtonRelease), NULL); |
69 g_signal_connect(G_OBJECT(widget_), "focus_in_event", | 93 g_signal_connect(G_OBJECT(child_widget_parent_), "focus_in_event", |
70 G_CALLBACK(CallFocusIn), NULL); | 94 G_CALLBACK(CallFocusIn), NULL); |
71 g_signal_connect(G_OBJECT(widget_), "focus_out_event", | 95 g_signal_connect(G_OBJECT(child_widget_parent_), "focus_out_event", |
72 G_CALLBACK(CallFocusOut), NULL); | 96 G_CALLBACK(CallFocusOut), NULL); |
73 g_signal_connect(G_OBJECT(widget_), "key_press_event", | 97 g_signal_connect(G_OBJECT(child_widget_parent_), "key_press_event", |
74 G_CALLBACK(CallKeyPress), NULL); | 98 G_CALLBACK(CallKeyPress), NULL); |
75 g_signal_connect(G_OBJECT(widget_), "key_release_event", | 99 g_signal_connect(G_OBJECT(child_widget_parent_), "key_release_event", |
76 G_CALLBACK(CallKeyRelease), NULL); | 100 G_CALLBACK(CallKeyRelease), NULL); |
77 g_signal_connect(G_OBJECT(widget_), "scroll_event", | 101 g_signal_connect(G_OBJECT(child_widget_parent_), "scroll_event", |
78 G_CALLBACK(CallScroll), NULL); | 102 G_CALLBACK(CallScroll), NULL); |
79 g_signal_connect(G_OBJECT(widget_), "visibility_notify_event", | 103 g_signal_connect(G_OBJECT(child_widget_parent_), "visibility_notify_event", |
80 G_CALLBACK(CallVisibilityNotify), NULL); | 104 G_CALLBACK(CallVisibilityNotify), NULL); |
81 | 105 |
82 // TODO(erg): Ignore these signals for now because they're such a drag. | 106 // TODO(erg): Ignore these signals for now because they're such a drag. |
83 // | 107 // |
84 // g_signal_connect(G_OBJECT(widget_), "drag_motion", | 108 // g_signal_connect(G_OBJECT(widget_), "drag_motion", |
85 // G_CALLBACK(drag_motion_event_cb), NULL); | 109 // G_CALLBACK(drag_motion_event_cb), NULL); |
86 // g_signal_connect(G_OBJECT(widget_), "drag_leave", | 110 // g_signal_connect(G_OBJECT(widget_), "drag_leave", |
87 // G_CALLBACK(drag_leave_event_cb), NULL); | 111 // G_CALLBACK(drag_leave_event_cb), NULL); |
88 // g_signal_connect(G_OBJECT(widget_), "drag_drop", | 112 // g_signal_connect(G_OBJECT(widget_), "drag_drop", |
89 // G_CALLBACK(drag_drop_event_cb), NULL); | 113 // G_CALLBACK(drag_drop_event_cb), NULL); |
90 // g_signal_connect(G_OBJECT(widget_), "drag_data_received", | 114 // g_signal_connect(G_OBJECT(widget_), "drag_data_received", |
91 // G_CALLBACK(drag_data_received_event_cb), NULL); | 115 // G_CALLBACK(drag_data_received_event_cb), NULL); |
92 } | 116 } |
93 | 117 |
118 void WidgetGtk::AddChild(GtkWidget* child) { | |
119 gtk_container_add(GTK_CONTAINER(child_widget_parent_), child); | |
120 } | |
121 | |
122 void WidgetGtk::RemoveChild(GtkWidget* child) { | |
123 gtk_container_remove(GTK_CONTAINER(child_widget_parent_), child); | |
124 } | |
125 | |
126 void WidgetGtk::PositionChild(GtkWidget* child, int x, int y, int w, int h) { | |
127 GtkAllocation alloc = { x, y, w, h }; | |
128 gtk_widget_size_allocate(child, &alloc); | |
129 gtk_fixed_move(GTK_FIXED(child_widget_parent_), child, x, y); | |
Elliot Glaysher
2009/05/07 22:25:29
(General issue; doesn't block this patch.)
If you
| |
130 } | |
131 | |
94 void WidgetGtk::SetContentsView(View* view) { | 132 void WidgetGtk::SetContentsView(View* view) { |
95 DCHECK(view && widget_) << "Can't be called until after the HWND is created!"; | 133 DCHECK(view && widget_) |
134 << "Can't be called until after the HWND is created!"; | |
96 // The ContentsView must be set up _after_ the window is created so that its | 135 // The ContentsView must be set up _after_ the window is created so that its |
97 // Widget pointer is valid. | 136 // Widget pointer is valid. |
98 root_view_->SetLayoutManager(new FillLayout); | 137 root_view_->SetLayoutManager(new FillLayout); |
99 if (root_view_->GetChildViewCount() != 0) | 138 if (root_view_->GetChildViewCount() != 0) |
100 root_view_->RemoveAllChildViews(true); | 139 root_view_->RemoveAllChildViews(true); |
101 root_view_->AddChildView(view); | 140 root_view_->AddChildView(view); |
102 | 141 |
103 // TODO(erg): Terrible hack to work around lack of real sizing mechanics for | 142 DCHECK(widget_); // Widget must have been created by now. |
104 // now. | 143 |
105 root_view_->SetBounds(0, 0, 100, 100); | 144 OnSizeAllocate(widget_, &(widget_->allocation)); |
106 root_view_->Layout(); | |
107 root_view_->SchedulePaint(); | |
108 NOTIMPLEMENTED(); | |
109 } | 145 } |
110 | 146 |
111 void WidgetGtk::GetBounds(gfx::Rect* out, bool including_frame) const { | 147 void WidgetGtk::GetBounds(gfx::Rect* out, bool including_frame) const { |
112 if (including_frame) { | 148 DCHECK(widget_); |
113 NOTIMPLEMENTED(); | 149 |
114 *out = gfx::Rect(); | 150 int x = 0, y = 0, w, h; |
115 return; | 151 if (GTK_IS_WINDOW(widget_)) { |
152 gtk_window_get_position(GTK_WINDOW(widget_), &x, &y); | |
153 gtk_window_get_size(GTK_WINDOW(widget_), &w, &h); | |
154 } else { | |
155 // TODO: make sure this is right. Docs indicate gtk_window_get_position | |
156 // returns a value useful to the window manager, which may not be the same | |
157 // as the actual location on the screen. | |
158 GetWidgetPositionOnScreen(widget_, &x, &y); | |
159 w = widget_->allocation.width; | |
160 h = widget_->allocation.height; | |
116 } | 161 } |
117 | 162 |
118 // TODO(erg): Not sure how to implement this. gtk_widget_size_request() | 163 if (including_frame) { |
119 // returns a widget's requested size--not it's actual size. The system of | 164 // TODO: Docs indicate it isn't possible to get at this value. We may need |
120 // containers and such do auto sizing tricks to make everything work within | 165 // to turn off all decorations so that the frame is always of a 0x0 size. |
121 // the constraints and requested sizes... | 166 NOTIMPLEMENTED(); |
122 NOTIMPLEMENTED(); | 167 } |
168 | |
169 return out->SetRect(x, y, w, h); | |
123 } | 170 } |
124 | 171 |
125 gfx::NativeView WidgetGtk::GetNativeView() const { | 172 gfx::NativeView WidgetGtk::GetNativeView() const { |
126 return widget_; | 173 return widget_; |
127 } | 174 } |
128 | 175 |
129 void WidgetGtk::PaintNow(const gfx::Rect& update_rect) { | 176 void WidgetGtk::PaintNow(const gfx::Rect& update_rect) { |
130 // TODO(erg): This is woefully incomplete and is a straw man implementation. | |
131 gtk_widget_queue_draw_area(widget_, update_rect.x(), update_rect.y(), | 177 gtk_widget_queue_draw_area(widget_, update_rect.x(), update_rect.y(), |
132 update_rect.width(), update_rect.height()); | 178 update_rect.width(), update_rect.height()); |
133 } | 179 } |
134 | 180 |
135 RootView* WidgetGtk::GetRootView() { | 181 RootView* WidgetGtk::GetRootView() { |
136 if (!root_view_.get()) { | 182 if (!root_view_.get()) { |
137 // First time the root view is being asked for, create it now. | 183 // First time the root view is being asked for, create it now. |
138 root_view_.reset(CreateRootView()); | 184 root_view_.reset(CreateRootView()); |
139 } | 185 } |
140 return root_view_.get(); | 186 return root_view_.get(); |
141 } | 187 } |
142 | 188 |
143 bool WidgetGtk::IsVisible() const { | 189 bool WidgetGtk::IsVisible() const { |
144 return GTK_WIDGET_VISIBLE(widget_); | 190 return GTK_WIDGET_VISIBLE(widget_); |
145 } | 191 } |
146 | 192 |
147 bool WidgetGtk::IsActive() const { | 193 bool WidgetGtk::IsActive() const { |
148 NOTIMPLEMENTED(); | 194 // If this only applies to windows, it shouldn't be in widget. |
149 return false; | 195 DCHECK(GTK_IS_WINDOW(widget_)); |
196 return gtk_window_is_active(GTK_WINDOW(widget_)); | |
150 } | 197 } |
151 | 198 |
152 TooltipManager* WidgetGtk::GetTooltipManager() { | 199 TooltipManager* WidgetGtk::GetTooltipManager() { |
153 NOTIMPLEMENTED(); | 200 NOTIMPLEMENTED(); |
154 return NULL; | 201 return NULL; |
155 } | 202 } |
156 | 203 |
157 bool WidgetGtk::GetAccelerator(int cmd_id, Accelerator* accelerator) { | 204 bool WidgetGtk::GetAccelerator(int cmd_id, Accelerator* accelerator) { |
158 NOTIMPLEMENTED(); | 205 NOTIMPLEMENTED(); |
159 return false; | 206 return false; |
160 } | 207 } |
161 | 208 |
209 Window* WidgetGtk::GetWindow() { | |
210 return GetWindowImpl(widget_); | |
211 } | |
212 | |
213 const Window* WidgetGtk::GetWindow() const { | |
214 return GetWindowImpl(widget_); | |
215 } | |
216 | |
217 void WidgetGtk::CreateGtkWidget() { | |
218 if (type_ == TYPE_CHILD) { | |
219 child_widget_parent_ = widget_ = gtk_fixed_new(); | |
220 SetViewForNative(widget_, this); | |
221 } else { | |
222 widget_ = gtk_window_new( | |
223 type_ == TYPE_WINDOW ? GTK_WINDOW_TOPLEVEL : GTK_WINDOW_POPUP); | |
224 gtk_window_set_decorated(GTK_WINDOW(widget_), false); | |
225 // We'll take care of positioning our window. | |
226 gtk_window_set_position(GTK_WINDOW(widget_), GTK_WIN_POS_NONE); | |
227 SetWindowForNative(widget_, static_cast<WindowGtk*>(this)); | |
228 SetViewForNative(widget_, this); | |
229 | |
230 child_widget_parent_ = gtk_fixed_new(); | |
231 gtk_fixed_set_has_window(GTK_FIXED(child_widget_parent_), true); | |
232 gtk_container_add(GTK_CONTAINER(widget_), child_widget_parent_); | |
233 gtk_widget_show(child_widget_parent_); | |
234 | |
235 SetViewForNative(child_widget_parent_, this); | |
236 } | |
237 gtk_widget_show(widget_); | |
238 } | |
239 | |
240 void WidgetGtk::OnSizeAllocate(GtkWidget* widget, GtkAllocation* allocation) { | |
241 root_view_->SetBounds(0, 0, allocation->width, allocation->height); | |
242 root_view_->Layout(); | |
243 root_view_->SchedulePaint(); | |
244 } | |
245 | |
162 gboolean WidgetGtk::OnMotionNotify(GtkWidget* widget, GdkEventMotion* event) { | 246 gboolean WidgetGtk::OnMotionNotify(GtkWidget* widget, GdkEventMotion* event) { |
163 gfx::Point screen_loc(event->x_root, event->y_root); | 247 gfx::Point screen_loc(event->x_root, event->y_root); |
164 if (last_mouse_event_was_move_ && last_mouse_move_x_ == screen_loc.x() && | 248 if (last_mouse_event_was_move_ && last_mouse_move_x_ == screen_loc.x() && |
165 last_mouse_move_y_ == screen_loc.y()) { | 249 last_mouse_move_y_ == screen_loc.y()) { |
166 // Don't generate a mouse event for the same location as the last. | 250 // Don't generate a mouse event for the same location as the last. |
167 return false; | 251 return false; |
168 } | 252 } |
169 last_mouse_move_x_ = screen_loc.x(); | 253 last_mouse_move_x_ = screen_loc.x(); |
170 last_mouse_move_y_ = screen_loc.y(); | 254 last_mouse_move_y_ = screen_loc.y(); |
171 last_mouse_event_was_move_ = true; | 255 last_mouse_event_was_move_ = true; |
172 MouseEvent mouse_move(Event::ET_MOUSE_MOVED, | 256 MouseEvent mouse_move(Event::ET_MOUSE_MOVED, |
173 event->x, | 257 event->x, |
174 event->y, | 258 event->y, |
175 Event::GetFlagsFromGdkState(event->state)); | 259 Event::GetFlagsFromGdkState(event->state)); |
176 root_view_->OnMouseMoved(mouse_move); | 260 root_view_->OnMouseMoved(mouse_move); |
177 return true; | 261 return true; |
178 } | 262 } |
179 | 263 |
180 gboolean WidgetGtk::OnButtonPress(GtkWidget* widget, GdkEventButton* event) { | 264 gboolean WidgetGtk::OnButtonPress(GtkWidget* widget, GdkEventButton* event) { |
181 return ProcessMousePressed(event); | 265 ProcessMousePressed(event); |
266 return true; | |
182 } | 267 } |
183 | 268 |
184 gboolean WidgetGtk::OnButtonRelease(GtkWidget* widget, GdkEventButton* event) { | 269 gboolean WidgetGtk::OnButtonRelease(GtkWidget* widget, GdkEventButton* event) { |
185 ProcessMouseReleased(event); | 270 ProcessMouseReleased(event); |
186 return true; | 271 return true; |
187 } | 272 } |
188 | 273 |
189 gboolean WidgetGtk::OnPaint(GtkWidget* widget, GdkEventExpose* event) { | 274 void WidgetGtk::OnPaint(GtkWidget* widget, GdkEventExpose* event) { |
190 root_view_->OnPaint(event); | 275 root_view_->OnPaint(event); |
191 return true; | |
192 } | 276 } |
193 | 277 |
194 gboolean WidgetGtk::OnEnterNotify(GtkWidget* widget, GdkEventCrossing* event) { | 278 gboolean WidgetGtk::OnEnterNotify(GtkWidget* widget, GdkEventCrossing* event) { |
195 // TODO(port): We may not actually need this message; it looks like | 279 // TODO(port): We may not actually need this message; it looks like |
196 // OnNotificationNotify() takes care of this case... | 280 // OnNotificationNotify() takes care of this case... |
197 return false; | 281 return false; |
198 } | 282 } |
199 | 283 |
200 gboolean WidgetGtk::OnLeaveNotify(GtkWidget* widget, GdkEventCrossing* event) { | 284 gboolean WidgetGtk::OnLeaveNotify(GtkWidget* widget, GdkEventCrossing* event) { |
201 last_mouse_event_was_move_ = false; | 285 last_mouse_event_was_move_ = false; |
202 root_view_->ProcessOnMouseExited(); | 286 root_view_->ProcessOnMouseExited(); |
203 return true; | 287 return true; |
204 } | 288 } |
205 | 289 |
206 gboolean WidgetGtk::OnKeyPress(GtkWidget* widget, GdkEventKey* event) { | 290 gboolean WidgetGtk::OnKeyPress(GtkWidget* widget, GdkEventKey* event) { |
207 KeyEvent key_event(event); | 291 KeyEvent key_event(event); |
208 return root_view_->ProcessKeyEvent(key_event); | 292 return root_view_->ProcessKeyEvent(key_event); |
209 } | 293 } |
210 | 294 |
211 gboolean WidgetGtk::OnKeyRelease(GtkWidget* widget, GdkEventKey* event) { | 295 gboolean WidgetGtk::OnKeyRelease(GtkWidget* widget, GdkEventKey* event) { |
212 KeyEvent key_event(event); | 296 KeyEvent key_event(event); |
213 return root_view_->ProcessKeyEvent(key_event); | 297 return root_view_->ProcessKeyEvent(key_event); |
214 } | 298 } |
215 | 299 |
300 // static | |
301 WindowGtk* WidgetGtk::GetWindowForNative(GtkWidget* widget) { | |
302 gpointer user_data = g_object_get_data(G_OBJECT(widget), "chrome-window"); | |
303 return static_cast<WindowGtk*>(user_data); | |
304 } | |
305 | |
306 // static | |
307 void WidgetGtk::SetWindowForNative(GtkWidget* widget, WindowGtk* window) { | |
308 g_object_set_data(G_OBJECT(widget), "chrome-window", window); | |
309 } | |
310 | |
216 RootView* WidgetGtk::CreateRootView() { | 311 RootView* WidgetGtk::CreateRootView() { |
217 return new RootView(this); | 312 return new RootView(this); |
218 } | 313 } |
219 | 314 |
220 bool WidgetGtk::ProcessMousePressed(GdkEventButton* event) { | 315 bool WidgetGtk::ProcessMousePressed(GdkEventButton* event) { |
221 last_mouse_event_was_move_ = false; | 316 last_mouse_event_was_move_ = false; |
317 // TODO: move this code into a common place. Also need support for | |
318 // double/triple click. | |
319 int flags = Event::GetFlagsFromGdkState(event->state); | |
320 switch (event->button) { | |
321 case 1: | |
322 flags |= Event::EF_LEFT_BUTTON_DOWN; | |
323 break; | |
324 case 2: | |
325 flags |= Event::EF_MIDDLE_BUTTON_DOWN; | |
326 break; | |
327 case 3: | |
328 flags |= Event::EF_MIDDLE_BUTTON_DOWN; | |
329 break; | |
330 default: | |
331 // We only deal with 1-3. | |
332 break; | |
333 } | |
222 MouseEvent mouse_pressed(Event::ET_MOUSE_PRESSED, | 334 MouseEvent mouse_pressed(Event::ET_MOUSE_PRESSED, |
223 event->x, event->y, | 335 event->x, event->y, flags); |
224 // (dbl_click ? MouseEvent::EF_IS_DOUBLE_CLICK : 0) | | |
225 Event::GetFlagsFromGdkState(event->state)); | |
226 if (root_view_->OnMousePressed(mouse_pressed)) { | 336 if (root_view_->OnMousePressed(mouse_pressed)) { |
227 is_mouse_down_ = true; | 337 is_mouse_down_ = true; |
228 // TODO(port): Enable this once I figure out what capture is. | 338 // TODO(port): Enable this once I figure out what capture is. |
229 // if (!has_capture_) { | 339 // if (!has_capture_) { |
230 // SetCapture(); | 340 // SetCapture(); |
231 // has_capture_ = true; | 341 // has_capture_ = true; |
232 // current_action_ = FA_FORWARDING; | 342 // current_action_ = FA_FORWARDING; |
233 // } | 343 // } |
234 return true; | 344 return true; |
235 } | 345 } |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
281 void WidgetGtk::CallSizeAllocate(GtkWidget* widget, GtkAllocation* allocation) { | 391 void WidgetGtk::CallSizeAllocate(GtkWidget* widget, GtkAllocation* allocation) { |
282 WidgetGtk* widget_gtk = GetViewForNative(widget); | 392 WidgetGtk* widget_gtk = GetViewForNative(widget); |
283 if (!widget_gtk) | 393 if (!widget_gtk) |
284 return; | 394 return; |
285 | 395 |
286 widget_gtk->OnSizeAllocate(widget, allocation); | 396 widget_gtk->OnSizeAllocate(widget, allocation); |
287 } | 397 } |
288 | 398 |
289 gboolean WidgetGtk::CallPaint(GtkWidget* widget, GdkEventExpose* event) { | 399 gboolean WidgetGtk::CallPaint(GtkWidget* widget, GdkEventExpose* event) { |
290 WidgetGtk* widget_gtk = GetViewForNative(widget); | 400 WidgetGtk* widget_gtk = GetViewForNative(widget); |
291 if (!widget_gtk) | 401 if (widget_gtk) |
292 return false; | 402 widget_gtk->OnPaint(widget, event); |
293 | 403 return false; // False indicates other widgets should get the event as well. |
294 return widget_gtk->OnPaint(widget, event); | |
295 } | 404 } |
296 | 405 |
297 gboolean WidgetGtk::CallEnterNotify(GtkWidget* widget, GdkEventCrossing* event) { | 406 gboolean WidgetGtk::CallEnterNotify(GtkWidget* widget, GdkEventCrossing* event) { |
298 WidgetGtk* widget_gtk = GetViewForNative(widget); | 407 WidgetGtk* widget_gtk = GetViewForNative(widget); |
299 if (!widget_gtk) | 408 if (!widget_gtk) |
300 return false; | 409 return false; |
301 | 410 |
302 return widget_gtk->OnEnterNotify(widget, event); | 411 return widget_gtk->OnEnterNotify(widget, event); |
303 } | 412 } |
304 | 413 |
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
376 | 485 |
377 gboolean WidgetGtk::CallVisibilityNotify(GtkWidget* widget, | 486 gboolean WidgetGtk::CallVisibilityNotify(GtkWidget* widget, |
378 GdkEventVisibility* event) { | 487 GdkEventVisibility* event) { |
379 WidgetGtk* widget_gtk = GetViewForNative(widget); | 488 WidgetGtk* widget_gtk = GetViewForNative(widget); |
380 if (!widget_gtk) | 489 if (!widget_gtk) |
381 return false; | 490 return false; |
382 | 491 |
383 return widget_gtk->OnVisibilityNotify(widget, event); | 492 return widget_gtk->OnVisibilityNotify(widget, event); |
384 } | 493 } |
385 | 494 |
495 // Returns the first ancestor of |widget| that is a window. | |
496 // static | |
497 Window* WidgetGtk::GetWindowImpl(GtkWidget* widget) { | |
498 GtkWidget* parent = widget; | |
499 while (parent) { | |
500 WindowGtk* window = GetWindowForNative(widget); | |
501 if (window) | |
502 return window; | |
503 parent = gtk_widget_get_parent(parent); | |
504 } | |
505 return NULL; | |
386 } | 506 } |
507 | |
508 } | |
OLD | NEW |