OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/browser/ui/panels/panel_browser_window_gtk.h" | 5 #include "chrome/browser/ui/panels/panel_browser_window_gtk.h" |
6 | 6 |
7 #include "chrome/browser/ui/panels/panel.h" | 7 #include "chrome/browser/ui/panels/panel.h" |
8 #include "chrome/browser/ui/panels/panel_manager.h" | 8 #include "chrome/browser/ui/panels/panel_manager.h" |
9 #include "ui/base/dragdrop/gtk_dnd_util.h" | 9 #include "ui/base/dragdrop/gtk_dnd_util.h" |
10 | 10 |
(...skipping 163 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
174 } | 174 } |
175 | 175 |
176 Browser* PanelBrowserWindowGtk::GetPanelBrowser() const { | 176 Browser* PanelBrowserWindowGtk::GetPanelBrowser() const { |
177 return browser(); | 177 return browser(); |
178 } | 178 } |
179 | 179 |
180 void PanelBrowserWindowGtk::DestroyPanelBrowser() { | 180 void PanelBrowserWindowGtk::DestroyPanelBrowser() { |
181 DestroyBrowser(); | 181 DestroyBrowser(); |
182 } | 182 } |
183 | 183 |
184 NativePanelTesting* PanelBrowserWindowGtk::GetNativePanelTesting() { | |
185 return this; | |
186 } | |
187 | |
188 void PanelBrowserWindowGtk::SetBoundsImpl() { | 184 void PanelBrowserWindowGtk::SetBoundsImpl() { |
189 gtk_window_move(window_, bounds_.x(), bounds_.y()); | 185 gtk_window_move(window_, bounds_.x(), bounds_.y()); |
190 gtk_window_resize(window(), bounds_.width(), bounds_.height()); | 186 gtk_window_resize(window(), bounds_.width(), bounds_.height()); |
191 } | 187 } |
192 | 188 |
193 void PanelBrowserWindowGtk::WillProcessEvent(GdkEvent* event) { | 189 void PanelBrowserWindowGtk::WillProcessEvent(GdkEvent* event) { |
194 // Nothing to do. | 190 // Nothing to do. |
195 } | 191 } |
196 | 192 |
197 void PanelBrowserWindowGtk::DidProcessEvent(GdkEvent* event) { | 193 void PanelBrowserWindowGtk::DidProcessEvent(GdkEvent* event) { |
198 DCHECK(last_mouse_down_); | 194 DCHECK(last_mouse_down_); |
199 if (event->type != GDK_MOTION_NOTIFY) | 195 if (event->type != GDK_MOTION_NOTIFY) |
200 return; | 196 return; |
201 | 197 |
202 gdouble new_x_double; | 198 gdouble new_x_double; |
203 gdouble new_y_double; | 199 gdouble new_y_double; |
| 200 gdouble old_x_double; |
| 201 gdouble old_y_double; |
204 gdk_event_get_root_coords(event, &new_x_double, &new_y_double); | 202 gdk_event_get_root_coords(event, &new_x_double, &new_y_double); |
| 203 gdk_event_get_root_coords(last_mouse_down_, &old_x_double, &old_y_double); |
205 | 204 |
206 gint new_x = static_cast<gint>(new_x_double); | 205 gint new_x = static_cast<gint>(new_x_double); |
207 gint new_y = static_cast<gint>(new_y_double); | 206 gint new_y = static_cast<gint>(new_y_double); |
208 gint old_x = static_cast<gint>(last_mouse_down_->button.x_root); | 207 gint old_x = static_cast<gint>(old_x_double); |
209 gint old_y = static_cast<gint>(last_mouse_down_->button.y_root); | 208 gint old_y = static_cast<gint>(old_y_double); |
210 | 209 |
211 if (drag_widget_) { | 210 if (drag_widget_) { |
212 panel_->manager()->Drag(new_x - old_x); | 211 panel_->manager()->Drag(new_x - old_x); |
213 gdk_event_free(last_mouse_down_); | 212 gdk_event_free(last_mouse_down_); |
214 last_mouse_down_ = gdk_event_copy(reinterpret_cast<GdkEvent*>(event)); | 213 last_mouse_down_ = gdk_event_copy(reinterpret_cast<GdkEvent*>(event)); |
215 } else if (gtk_drag_check_threshold(titlebar_widget(), old_x, | 214 } else if (gtk_drag_check_threshold(titlebar_widget(), old_x, |
216 old_y, new_x, new_y)) { | 215 old_y, new_x, new_y)) { |
217 CreateDragWidget(); | 216 CreateDragWidget(); |
218 GtkTargetList* list = ui::GetTargetListFromCodeMask(ui::CHROME_TAB); | 217 GtkTargetList* list = ui::GetTargetListFromCodeMask(ui::CHROME_TAB); |
219 gtk_drag_begin(drag_widget_, list, GDK_ACTION_MOVE, 1, last_mouse_down_); | 218 gtk_drag_begin(drag_widget_, list, GDK_ACTION_MOVE, 1, last_mouse_down_); |
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
308 // if the user ended the drag with space or enter, we don't get a follow up | 307 // if the user ended the drag with space or enter, we don't get a follow up |
309 // event to tell us the drag has finished (either a drag-failed or a | 308 // event to tell us the drag has finished (either a drag-failed or a |
310 // drag-end). We post a task, instead of calling EndDrag right here, to give | 309 // drag-end). We post a task, instead of calling EndDrag right here, to give |
311 // GTK+ a chance to send the drag-failed event with the right status. If | 310 // GTK+ a chance to send the drag-failed event with the right status. If |
312 // GTK+ does send the drag-failed event, we cancel the task. | 311 // GTK+ does send the drag-failed event, we cancel the task. |
313 MessageLoop::current()->PostTask(FROM_HERE, | 312 MessageLoop::current()->PostTask(FROM_HERE, |
314 drag_end_factory_.NewRunnableMethod( | 313 drag_end_factory_.NewRunnableMethod( |
315 &PanelBrowserWindowGtk::EndDrag, false)); | 314 &PanelBrowserWindowGtk::EndDrag, false)); |
316 return TRUE; | 315 return TRUE; |
317 } | 316 } |
| 317 |
| 318 // NativePanelTesting implementation. |
| 319 class NativePanelTestingGtk : public NativePanelTesting { |
| 320 public: |
| 321 explicit NativePanelTestingGtk( |
| 322 PanelBrowserWindowGtk* panel_browser_window_gtk); |
| 323 |
| 324 private: |
| 325 virtual void PressLeftMouseButtonTitlebar( |
| 326 const gfx::Point& point) OVERRIDE; |
| 327 virtual void ReleaseMouseButtonTitlebar() OVERRIDE; |
| 328 virtual void DragTitlebar(int delta_x, int delta_y) OVERRIDE; |
| 329 virtual void CancelDragTitlebar() OVERRIDE; |
| 330 virtual void FinishDragTitlebar() OVERRIDE; |
| 331 |
| 332 PanelBrowserWindowGtk* panel_browser_window_gtk_; |
| 333 }; |
| 334 |
| 335 // static |
| 336 NativePanelTesting* NativePanelTesting::Create(NativePanel* native_panel) { |
| 337 return new NativePanelTestingGtk(static_cast<PanelBrowserWindowGtk*>( |
| 338 native_panel)); |
| 339 } |
| 340 |
| 341 NativePanelTestingGtk::NativePanelTestingGtk( |
| 342 PanelBrowserWindowGtk* panel_browser_window_gtk) : |
| 343 panel_browser_window_gtk_(panel_browser_window_gtk) { |
| 344 } |
| 345 |
| 346 void NativePanelTestingGtk::PressLeftMouseButtonTitlebar( |
| 347 const gfx::Point& point) { |
| 348 GdkEvent* event = gdk_event_new(GDK_BUTTON_PRESS); |
| 349 event->button.button = 1; |
| 350 event->button.x_root = point.x(); |
| 351 event->button.y_root = point.y(); |
| 352 panel_browser_window_gtk_->OnTitlebarButtonPressEvent( |
| 353 panel_browser_window_gtk_->titlebar_widget(), |
| 354 reinterpret_cast<GdkEventButton*>(event)); |
| 355 gdk_event_free(event); |
| 356 MessageLoopForUI::current()->RunAllPending(); |
| 357 } |
| 358 |
| 359 void NativePanelTestingGtk::ReleaseMouseButtonTitlebar() { |
| 360 panel_browser_window_gtk_->OnTitlebarButtonReleaseEvent(NULL, NULL); |
| 361 MessageLoopForUI::current()->RunAllPending(); |
| 362 } |
| 363 |
| 364 void NativePanelTestingGtk::DragTitlebar(int delta_x, int delta_y) { |
| 365 if (!panel_browser_window_gtk_->drag_widget_) { |
| 366 panel_browser_window_gtk_->CreateDragWidget(); |
| 367 panel_browser_window_gtk_->panel_->manager()->StartDragging( |
| 368 panel_browser_window_gtk_->panel_.get()); |
| 369 } |
| 370 GdkEvent* event = gdk_event_new(GDK_MOTION_NOTIFY); |
| 371 gdk_event_get_root_coords(panel_browser_window_gtk_->last_mouse_down_, |
| 372 &event->motion.x_root, &event->motion.y_root); |
| 373 event->motion.x_root += delta_x; |
| 374 event->motion.y_root += delta_y; |
| 375 panel_browser_window_gtk_->DidProcessEvent(event); |
| 376 gdk_event_free(event); |
| 377 MessageLoopForUI::current()->RunAllPending(); |
| 378 } |
| 379 |
| 380 void NativePanelTestingGtk::CancelDragTitlebar() { |
| 381 panel_browser_window_gtk_->OnDragFailed( |
| 382 panel_browser_window_gtk_->drag_widget_, NULL, |
| 383 GTK_DRAG_RESULT_USER_CANCELLED); |
| 384 MessageLoopForUI::current()->RunAllPending(); |
| 385 } |
| 386 |
| 387 void NativePanelTestingGtk::FinishDragTitlebar() { |
| 388 panel_browser_window_gtk_->OnDragFailed( |
| 389 panel_browser_window_gtk_->drag_widget_, NULL, |
| 390 GTK_DRAG_RESULT_NO_TARGET); |
| 391 MessageLoopForUI::current()->RunAllPending(); |
| 392 } |
OLD | NEW |