Chromium Code Reviews| 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 "views/widget/widget_gtk.h" | 5 #include "views/widget/widget_gtk.h" |
| 6 | 6 |
| 7 #include "base/compiler_specific.h" | 7 #include "base/compiler_specific.h" |
| 8 #include "views/fill_layout.h" | 8 #include "views/fill_layout.h" |
| 9 #include "views/widget/root_view.h" | 9 #include "views/widget/root_view.h" |
| 10 #include "views/window/window_gtk.h" | 10 #include "views/window/window_gtk.h" |
| 11 | 11 |
| 12 namespace views { | 12 namespace views { |
| 13 | 13 |
| 14 // Returns the position of a widget on screen. | 14 // Returns the position of a widget on screen. |
| 15 static void GetWidgetPositionOnScreen(GtkWidget* widget, int* x, int *y) { | 15 static void GetWidgetPositionOnScreen(GtkWidget* widget, int* x, int *y) { |
| 16 GtkWidget* parent = widget; | 16 while (widget) { |
| 17 while (parent) { | |
| 18 if (GTK_IS_WINDOW(widget)) { | 17 if (GTK_IS_WINDOW(widget)) { |
| 19 int window_x, window_y; | 18 int window_x, window_y; |
| 20 gtk_window_get_position(GTK_WINDOW(widget), &window_x, &window_y); | 19 gtk_window_get_position(GTK_WINDOW(widget), &window_x, &window_y); |
| 21 *x += window_x; | 20 *x += window_x; |
| 22 *y += window_y; | 21 *y += window_y; |
| 23 return; | 22 return; |
| 24 } | 23 } |
| 25 // Not a window. | 24 // Not a window. |
| 26 *x += widget->allocation.x; | 25 *x += widget->allocation.x; |
| 27 *y += widget->allocation.y; | 26 *y += widget->allocation.y; |
| 28 parent = gtk_widget_get_parent(parent); | 27 widget = gtk_widget_get_parent(widget); |
| 29 } | 28 } |
| 30 } | 29 } |
| 31 | 30 |
| 32 // Returns the view::Event::flags for a GdkEventButton. | 31 // Returns the view::Event::flags for a GdkEventButton. |
| 33 static int GetFlagsForEventButton(const GdkEventButton& event) { | 32 static int GetFlagsForEventButton(const GdkEventButton& event) { |
| 34 int flags = Event::GetFlagsFromGdkState(event.state); | 33 int flags = Event::GetFlagsFromGdkState(event.state); |
| 35 switch (event.button) { | 34 switch (event.button) { |
| 36 case 1: | 35 case 1: |
| 37 flags |= Event::EF_LEFT_BUTTON_DOWN; | 36 flags |= Event::EF_LEFT_BUTTON_DOWN; |
| 38 break; | 37 break; |
| (...skipping 436 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 475 return true; | 474 return true; |
| 476 } | 475 } |
| 477 | 476 |
| 478 last_mouse_event_was_move_ = false; | 477 last_mouse_event_was_move_ = false; |
| 479 MouseEvent mouse_pressed(Event::ET_MOUSE_PRESSED, event->x, event->y, | 478 MouseEvent mouse_pressed(Event::ET_MOUSE_PRESSED, event->x, event->y, |
| 480 GetFlagsForEventButton(*event)); | 479 GetFlagsForEventButton(*event)); |
| 481 if (root_view_->OnMousePressed(mouse_pressed)) { | 480 if (root_view_->OnMousePressed(mouse_pressed)) { |
| 482 is_mouse_down_ = true; | 481 is_mouse_down_ = true; |
| 483 if (!has_capture_) { | 482 if (!has_capture_) { |
| 484 has_capture_ = true; | 483 has_capture_ = true; |
| 484 // TODO: this should also do a gdk_pointer_grab. See gtkmenu.cc for detail s: | |
|
brettw
2009/05/27 20:24:30
Line too long, and remove the empty // line here.
| |
| 485 // | |
| 485 gtk_grab_add(child_widget_parent_); | 486 gtk_grab_add(child_widget_parent_); |
| 486 } | 487 } |
| 487 return true; | 488 return true; |
| 488 } | 489 } |
| 489 | 490 |
| 490 return false; | 491 return false; |
| 491 } | 492 } |
| 492 | 493 |
| 493 void WidgetGtk::ProcessMouseReleased(GdkEventButton* event) { | 494 void WidgetGtk::ProcessMouseReleased(GdkEventButton* event) { |
| 494 last_mouse_event_was_move_ = false; | 495 last_mouse_event_was_move_ = false; |
| (...skipping 179 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 674 void WidgetGtk::HandleGrabBroke() { | 675 void WidgetGtk::HandleGrabBroke() { |
| 675 if (has_capture_) { | 676 if (has_capture_) { |
| 676 if (is_mouse_down_) | 677 if (is_mouse_down_) |
| 677 root_view_->ProcessMouseDragCanceled(); | 678 root_view_->ProcessMouseDragCanceled(); |
| 678 is_mouse_down_ = false; | 679 is_mouse_down_ = false; |
| 679 has_capture_ = false; | 680 has_capture_ = false; |
| 680 } | 681 } |
| 681 } | 682 } |
| 682 | 683 |
| 683 } // namespace views | 684 } // namespace views |
| OLD | NEW |