Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(474)

Side by Side Diff: chrome/browser/ui/panels/panel_browser_window_gtk.cc

Issue 7605009: Implement drag and drop testing in a platform independent way. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: More code review feedback. Created 9 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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
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
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 {
jianli 2011/08/11 20:52:09 Please move this subclass to the anonymous namespa
prasadt 2011/08/11 21:07:56 Need it in header file.
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 NativePanelTesting* NativePanelTesting::Create(NativePanel* native_panel) {
jianli 2011/08/11 20:52:09 Please add the comment for indicate it is static.
prasadt 2011/08/11 21:07:56 Done.
336 return new NativePanelTestingGtk(static_cast<PanelBrowserWindowGtk*>(
337 native_panel));
338 }
339
340 NativePanelTestingGtk::NativePanelTestingGtk(
341 PanelBrowserWindowGtk* panel_browser_window_gtk) :
342 panel_browser_window_gtk_(panel_browser_window_gtk) {
343 }
344
345 void NativePanelTestingGtk::PressLeftMouseButtonTitlebar(
346 const gfx::Point& point) {
347 GdkEvent* event = gdk_event_new(GDK_BUTTON_PRESS);
348 event->button.button = 1;
349 event->button.x_root = point.x();
350 event->button.y_root = point.y();
351 panel_browser_window_gtk_->OnTitlebarButtonPressEvent(
352 panel_browser_window_gtk_->titlebar_widget(),
353 reinterpret_cast<GdkEventButton*>(event));
354 gdk_event_free(event);
355 MessageLoopForUI::current()->RunAllPending();
356 }
357
358 void NativePanelTestingGtk::ReleaseMouseButtonTitlebar() {
359 panel_browser_window_gtk_->OnTitlebarButtonReleaseEvent(NULL, NULL);
360 MessageLoopForUI::current()->RunAllPending();
361 }
362
363 void NativePanelTestingGtk::DragTitlebar(int delta_x, int delta_y) {
364 if (!panel_browser_window_gtk_->drag_widget_) {
365 panel_browser_window_gtk_->CreateDragWidget();
366 panel_browser_window_gtk_->panel_->manager()->StartDragging(
367 panel_browser_window_gtk_->panel_.get());
368 }
369 GdkEvent* event = gdk_event_new(GDK_MOTION_NOTIFY);
370 gdk_event_get_root_coords(panel_browser_window_gtk_->last_mouse_down_,
371 &event->motion.x_root, &event->motion.y_root);
372 event->motion.x_root += delta_x;
373 event->motion.y_root += delta_y;
374 panel_browser_window_gtk_->DidProcessEvent(event);
375 gdk_event_free(event);
376 MessageLoopForUI::current()->RunAllPending();
377 }
378
379 void NativePanelTestingGtk::CancelDragTitlebar() {
380 panel_browser_window_gtk_->OnDragFailed(
381 panel_browser_window_gtk_->drag_widget_, NULL,
382 GTK_DRAG_RESULT_USER_CANCELLED);
383 MessageLoopForUI::current()->RunAllPending();
384 }
385
386 void NativePanelTestingGtk::FinishDragTitlebar() {
387 panel_browser_window_gtk_->OnDragFailed(
388 panel_browser_window_gtk_->drag_widget_, NULL,
389 GTK_DRAG_RESULT_NO_TARGET);
390 MessageLoopForUI::current()->RunAllPending();
391 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698