| 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 "views/widget/root_view.h" | 5 #include "views/widget/root_view.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 | 8 |
| 9 #if defined(TOUCH_UI) && defined(HAVE_XINPUT2) | 9 #if defined(TOUCH_UI) && defined(HAVE_XINPUT2) |
| 10 #include <gdk/gdkx.h> | 10 #include <gdk/gdkx.h> |
| (...skipping 368 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 379 return status; | 379 return status; |
| 380 } | 380 } |
| 381 #endif | 381 #endif |
| 382 | 382 |
| 383 bool RootView::OnMousePressed(const MouseEvent& e) { | 383 bool RootView::OnMousePressed(const MouseEvent& e) { |
| 384 // This function does not normally handle non-client messages except for | 384 // This function does not normally handle non-client messages except for |
| 385 // non-client double-clicks. Actually, all double-clicks are special as the | 385 // non-client double-clicks. Actually, all double-clicks are special as the |
| 386 // are formed from a single-click followed by a double-click event. When the | 386 // are formed from a single-click followed by a double-click event. When the |
| 387 // double-click event lands on a different view than its single-click part, | 387 // double-click event lands on a different view than its single-click part, |
| 388 // we transform it into a single-click which prevents odd things. | 388 // we transform it into a single-click which prevents odd things. |
| 389 if ((e.GetFlags() & MouseEvent::EF_IS_NON_CLIENT) && | 389 if ((e.flags() & MouseEvent::EF_IS_NON_CLIENT) && |
| 390 !(e.GetFlags() & MouseEvent::EF_IS_DOUBLE_CLICK)) { | 390 !(e.flags() & MouseEvent::EF_IS_DOUBLE_CLICK)) { |
| 391 last_click_handler_ = NULL; | 391 last_click_handler_ = NULL; |
| 392 return false; | 392 return false; |
| 393 } | 393 } |
| 394 | 394 |
| 395 UpdateCursor(e); | 395 UpdateCursor(e); |
| 396 SetMouseLocationAndFlags(e); | 396 SetMouseLocationAndFlags(e); |
| 397 | 397 |
| 398 // If mouse_pressed_handler_ is non null, we are currently processing | 398 // If mouse_pressed_handler_ is non null, we are currently processing |
| 399 // a pressed -> drag -> released session. In that case we send the | 399 // a pressed -> drag -> released session. In that case we send the |
| 400 // event to mouse_pressed_handler_ | 400 // event to mouse_pressed_handler_ |
| (...skipping 16 matching lines...) Expand all Loading... |
| 417 hit_disabled_view = true; | 417 hit_disabled_view = true; |
| 418 break; | 418 break; |
| 419 } | 419 } |
| 420 | 420 |
| 421 // See if this view wants to handle the mouse press. | 421 // See if this view wants to handle the mouse press. |
| 422 MouseEvent mouse_pressed_event(e, this, mouse_pressed_handler_); | 422 MouseEvent mouse_pressed_event(e, this, mouse_pressed_handler_); |
| 423 | 423 |
| 424 // Remove the double-click flag if the handler is different than the | 424 // Remove the double-click flag if the handler is different than the |
| 425 // one which got the first click part of the double-click. | 425 // one which got the first click part of the double-click. |
| 426 if (mouse_pressed_handler_ != last_click_handler_) | 426 if (mouse_pressed_handler_ != last_click_handler_) |
| 427 mouse_pressed_event.set_flags(e.GetFlags() & | 427 mouse_pressed_event.set_flags(e.flags() & |
| 428 ~MouseEvent::EF_IS_DOUBLE_CLICK); | 428 ~MouseEvent::EF_IS_DOUBLE_CLICK); |
| 429 | 429 |
| 430 drag_info.Reset(); | 430 drag_info.Reset(); |
| 431 bool handled = mouse_pressed_handler_->ProcessMousePressed( | 431 bool handled = mouse_pressed_handler_->ProcessMousePressed( |
| 432 mouse_pressed_event, &drag_info); | 432 mouse_pressed_event, &drag_info); |
| 433 | 433 |
| 434 // The view could have removed itself from the tree when handling | 434 // The view could have removed itself from the tree when handling |
| 435 // OnMousePressed(). In this case, the removal notification will have | 435 // OnMousePressed(). In this case, the removal notification will have |
| 436 // reset mouse_pressed_handler_ to NULL out from under us. Detect this | 436 // reset mouse_pressed_handler_ to NULL out from under us. Detect this |
| 437 // case and stop. (See comments in view.h.) | 437 // case and stop. (See comments in view.h.) |
| (...skipping 24 matching lines...) Expand all Loading... |
| 462 GtkWidget* widget = GetWidget()->GetNativeView(); | 462 GtkWidget* widget = GetWidget()->GetNativeView(); |
| 463 if (!gtk_widget_is_focus(widget)) | 463 if (!gtk_widget_is_focus(widget)) |
| 464 gtk_widget_grab_focus(widget); | 464 gtk_widget_grab_focus(widget); |
| 465 #endif | 465 #endif |
| 466 } | 466 } |
| 467 | 467 |
| 468 // In the event that a double-click is not handled after traversing the | 468 // In the event that a double-click is not handled after traversing the |
| 469 // entire hierarchy (even as a single-click when sent to a different view), | 469 // entire hierarchy (even as a single-click when sent to a different view), |
| 470 // it must be marked as handled to avoid anything happening from default | 470 // it must be marked as handled to avoid anything happening from default |
| 471 // processing if it the first click-part was handled by us. | 471 // processing if it the first click-part was handled by us. |
| 472 if (last_click_handler_ && e.GetFlags() & MouseEvent::EF_IS_DOUBLE_CLICK) | 472 if (last_click_handler_ && e.flags() & MouseEvent::EF_IS_DOUBLE_CLICK) |
| 473 hit_disabled_view = true; | 473 hit_disabled_view = true; |
| 474 | 474 |
| 475 last_click_handler_ = NULL; | 475 last_click_handler_ = NULL; |
| 476 return hit_disabled_view; | 476 return hit_disabled_view; |
| 477 } | 477 } |
| 478 | 478 |
| 479 bool RootView::ConvertPointToMouseHandler(const gfx::Point& l, | 479 bool RootView::ConvertPointToMouseHandler(const gfx::Point& l, |
| 480 gfx::Point* p) { | 480 gfx::Point* p) { |
| 481 // | 481 // |
| 482 // If the mouse_handler was set explicitly, we need to keep | 482 // If the mouse_handler was set explicitly, we need to keep |
| (...skipping 18 matching lines...) Expand all Loading... |
| 501 } | 501 } |
| 502 return true; | 502 return true; |
| 503 } | 503 } |
| 504 | 504 |
| 505 void RootView::UpdateCursor(const MouseEvent& e) { | 505 void RootView::UpdateCursor(const MouseEvent& e) { |
| 506 gfx::NativeCursor cursor = NULL; | 506 gfx::NativeCursor cursor = NULL; |
| 507 View* v = GetViewForPoint(e.location()); | 507 View* v = GetViewForPoint(e.location()); |
| 508 if (v && v != this) { | 508 if (v && v != this) { |
| 509 gfx::Point l(e.location()); | 509 gfx::Point l(e.location()); |
| 510 View::ConvertPointToView(this, v, &l); | 510 View::ConvertPointToView(this, v, &l); |
| 511 cursor = v->GetCursorForPoint(e.GetType(), l); | 511 cursor = v->GetCursorForPoint(e.type(), l); |
| 512 } | 512 } |
| 513 SetActiveCursor(cursor); | 513 SetActiveCursor(cursor); |
| 514 } | 514 } |
| 515 | 515 |
| 516 bool RootView::OnMouseDragged(const MouseEvent& e) { | 516 bool RootView::OnMouseDragged(const MouseEvent& e) { |
| 517 UpdateCursor(e); | 517 UpdateCursor(e); |
| 518 | 518 |
| 519 if (mouse_pressed_handler_) { | 519 if (mouse_pressed_handler_) { |
| 520 SetMouseLocationAndFlags(e); | 520 SetMouseLocationAndFlags(e); |
| 521 | 521 |
| 522 gfx::Point p; | 522 gfx::Point p; |
| 523 ConvertPointToMouseHandler(e.location(), &p); | 523 ConvertPointToMouseHandler(e.location(), &p); |
| 524 MouseEvent mouse_event(e.GetType(), p.x(), p.y(), e.GetFlags()); | 524 MouseEvent mouse_event(e.type(), p.x(), p.y(), e.flags()); |
| 525 return mouse_pressed_handler_->ProcessMouseDragged(mouse_event, &drag_info); | 525 return mouse_pressed_handler_->ProcessMouseDragged(mouse_event, &drag_info); |
| 526 } | 526 } |
| 527 return false; | 527 return false; |
| 528 } | 528 } |
| 529 | 529 |
| 530 void RootView::OnMouseReleased(const MouseEvent& e, bool canceled) { | 530 void RootView::OnMouseReleased(const MouseEvent& e, bool canceled) { |
| 531 UpdateCursor(e); | 531 UpdateCursor(e); |
| 532 | 532 |
| 533 if (mouse_pressed_handler_) { | 533 if (mouse_pressed_handler_) { |
| 534 gfx::Point p; | 534 gfx::Point p; |
| 535 ConvertPointToMouseHandler(e.location(), &p); | 535 ConvertPointToMouseHandler(e.location(), &p); |
| 536 MouseEvent mouse_released(e.GetType(), p.x(), p.y(), e.GetFlags()); | 536 MouseEvent mouse_released(e.type(), p.x(), p.y(), e.flags()); |
| 537 // We allow the view to delete us from ProcessMouseReleased. As such, | 537 // We allow the view to delete us from ProcessMouseReleased. As such, |
| 538 // configure state such that we're done first, then call View. | 538 // configure state such that we're done first, then call View. |
| 539 View* mouse_pressed_handler = mouse_pressed_handler_; | 539 View* mouse_pressed_handler = mouse_pressed_handler_; |
| 540 mouse_pressed_handler_ = NULL; | 540 mouse_pressed_handler_ = NULL; |
| 541 explicit_mouse_handler_ = false; | 541 explicit_mouse_handler_ = false; |
| 542 mouse_pressed_handler->ProcessMouseReleased(mouse_released, canceled); | 542 mouse_pressed_handler->ProcessMouseReleased(mouse_released, canceled); |
| 543 // WARNING: we may have been deleted. | 543 // WARNING: we may have been deleted. |
| 544 } | 544 } |
| 545 } | 545 } |
| 546 | 546 |
| (...skipping 22 matching lines...) Expand all Loading... |
| 569 mouse_move_handler_->OnMouseEntered(entered_event); | 569 mouse_move_handler_->OnMouseEntered(entered_event); |
| 570 } | 570 } |
| 571 MouseEvent moved_event(Event::ET_MOUSE_MOVED, | 571 MouseEvent moved_event(Event::ET_MOUSE_MOVED, |
| 572 this, | 572 this, |
| 573 mouse_move_handler_, | 573 mouse_move_handler_, |
| 574 e.location(), | 574 e.location(), |
| 575 0); | 575 0); |
| 576 mouse_move_handler_->OnMouseMoved(moved_event); | 576 mouse_move_handler_->OnMouseMoved(moved_event); |
| 577 | 577 |
| 578 gfx::NativeCursor cursor = mouse_move_handler_->GetCursorForPoint( | 578 gfx::NativeCursor cursor = mouse_move_handler_->GetCursorForPoint( |
| 579 moved_event.GetType(), moved_event.location()); | 579 moved_event.type(), moved_event.location()); |
| 580 SetActiveCursor(cursor); | 580 SetActiveCursor(cursor); |
| 581 } else if (mouse_move_handler_ != NULL) { | 581 } else if (mouse_move_handler_ != NULL) { |
| 582 MouseEvent exited_event(Event::ET_MOUSE_EXITED, 0, 0, 0); | 582 MouseEvent exited_event(Event::ET_MOUSE_EXITED, 0, 0, 0); |
| 583 mouse_move_handler_->OnMouseExited(exited_event); | 583 mouse_move_handler_->OnMouseExited(exited_event); |
| 584 SetActiveCursor(NULL); | 584 SetActiveCursor(NULL); |
| 585 } | 585 } |
| 586 } | 586 } |
| 587 | 587 |
| 588 void RootView::ProcessOnMouseExited() { | 588 void RootView::ProcessOnMouseExited() { |
| 589 if (mouse_move_handler_ != NULL) { | 589 if (mouse_move_handler_ != NULL) { |
| (...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 673 gfx::NativeView native_view) { | 673 gfx::NativeView native_view) { |
| 674 PropagateNativeViewHierarchyChanged(attached, native_view, this); | 674 PropagateNativeViewHierarchyChanged(attached, native_view, this); |
| 675 } | 675 } |
| 676 | 676 |
| 677 bool RootView::ProcessKeyEvent(const KeyEvent& event) { | 677 bool RootView::ProcessKeyEvent(const KeyEvent& event) { |
| 678 bool consumed = false; | 678 bool consumed = false; |
| 679 | 679 |
| 680 View* v = GetFocusedView(); | 680 View* v = GetFocusedView(); |
| 681 // Special case to handle right-click context menus triggered by the | 681 // Special case to handle right-click context menus triggered by the |
| 682 // keyboard. | 682 // keyboard. |
| 683 if (v && v->IsEnabled() && ((event.GetKeyCode() == ui::VKEY_APPS) || | 683 if (v && v->IsEnabled() && ((event.key_code() == ui::VKEY_APPS) || |
| 684 (event.GetKeyCode() == ui::VKEY_F10 && event.IsShiftDown()))) { | 684 (event.key_code() == ui::VKEY_F10 && event.IsShiftDown()))) { |
| 685 v->ShowContextMenu(v->GetKeyboardContextMenuLocation(), false); | 685 v->ShowContextMenu(v->GetKeyboardContextMenuLocation(), false); |
| 686 return true; | 686 return true; |
| 687 } | 687 } |
| 688 for (; v && v != this && !consumed; v = v->parent()) { | 688 for (; v && v != this && !consumed; v = v->parent()) { |
| 689 consumed = (event.GetType() == Event::ET_KEY_PRESSED) ? | 689 consumed = (event.type() == Event::ET_KEY_PRESSED) ? |
| 690 v->OnKeyPressed(event) : v->OnKeyReleased(event); | 690 v->OnKeyPressed(event) : v->OnKeyReleased(event); |
| 691 } | 691 } |
| 692 | 692 |
| 693 if (!consumed && default_keyboard_handler_) { | 693 if (!consumed && default_keyboard_handler_) { |
| 694 consumed = (event.GetType() == Event::ET_KEY_PRESSED) ? | 694 consumed = (event.type() == Event::ET_KEY_PRESSED) ? |
| 695 default_keyboard_handler_->OnKeyPressed(event) : | 695 default_keyboard_handler_->OnKeyPressed(event) : |
| 696 default_keyboard_handler_->OnKeyReleased(event); | 696 default_keyboard_handler_->OnKeyReleased(event); |
| 697 } | 697 } |
| 698 | 698 |
| 699 return consumed; | 699 return consumed; |
| 700 } | 700 } |
| 701 | 701 |
| 702 bool RootView::ProcessMouseWheelEvent(const MouseWheelEvent& e) { | 702 bool RootView::ProcessMouseWheelEvent(const MouseWheelEvent& e) { |
| 703 View* v; | 703 View* v; |
| 704 bool consumed = false; | 704 bool consumed = false; |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 751 return; | 751 return; |
| 752 view->registered_for_visible_bounds_notification_ = false; | 752 view->registered_for_visible_bounds_notification_ = false; |
| 753 View* ancestor = view->parent(); | 753 View* ancestor = view->parent(); |
| 754 while (ancestor) { | 754 while (ancestor) { |
| 755 ancestor->RemoveDescendantToNotify(view); | 755 ancestor->RemoveDescendantToNotify(view); |
| 756 ancestor = ancestor->parent(); | 756 ancestor = ancestor->parent(); |
| 757 } | 757 } |
| 758 } | 758 } |
| 759 | 759 |
| 760 void RootView::SetMouseLocationAndFlags(const MouseEvent& e) { | 760 void RootView::SetMouseLocationAndFlags(const MouseEvent& e) { |
| 761 last_mouse_event_flags_ = e.GetFlags(); | 761 last_mouse_event_flags_ = e.flags(); |
| 762 last_mouse_event_x_ = e.x(); | 762 last_mouse_event_x_ = e.x(); |
| 763 last_mouse_event_y_ = e.y(); | 763 last_mouse_event_y_ = e.y(); |
| 764 } | 764 } |
| 765 | 765 |
| 766 std::string RootView::GetClassName() const { | 766 std::string RootView::GetClassName() const { |
| 767 return kViewClassName; | 767 return kViewClassName; |
| 768 } | 768 } |
| 769 | 769 |
| 770 void RootView::ClearPaintRect() { | 770 void RootView::ClearPaintRect() { |
| 771 invalid_rect_.SetRect(0, 0, 0, 0); | 771 invalid_rect_.SetRect(0, 0, 0, 0); |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 809 if (!TouchFactory::GetInstance()->is_cursor_visible()) { | 809 if (!TouchFactory::GetInstance()->is_cursor_visible()) { |
| 810 cursor = gfx::GetCursor(GDK_BLANK_CURSOR); | 810 cursor = gfx::GetCursor(GDK_BLANK_CURSOR); |
| 811 } | 811 } |
| 812 #endif | 812 #endif |
| 813 | 813 |
| 814 gdk_window_set_cursor(native_view->window, cursor); | 814 gdk_window_set_cursor(native_view->window, cursor); |
| 815 #endif | 815 #endif |
| 816 } | 816 } |
| 817 | 817 |
| 818 } // namespace views | 818 } // namespace views |
| OLD | NEW |