OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "ui/aura/root_window.h" | 5 #include "ui/aura/root_window.h" |
6 | 6 |
7 #include <vector> | 7 #include <vector> |
8 | 8 |
9 #include "base/auto_reset.h" | 9 #include "base/auto_reset.h" |
10 #include "base/bind.h" | 10 #include "base/bind.h" |
(...skipping 243 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
254 Window* target = client::GetCaptureWindow(this); | 254 Window* target = client::GetCaptureWindow(this); |
255 if (!target) { | 255 if (!target) { |
256 target = ConsumerToWindow( | 256 target = ConsumerToWindow( |
257 gesture_recognizer_->GetTargetForGestureEvent(event)); | 257 gesture_recognizer_->GetTargetForGestureEvent(event)); |
258 if (!target) | 258 if (!target) |
259 return false; | 259 return false; |
260 } | 260 } |
261 | 261 |
262 if (target) { | 262 if (target) { |
263 event->ConvertLocationToTarget(static_cast<Window*>(this), target); | 263 event->ConvertLocationToTarget(static_cast<Window*>(this), target); |
264 ui::EventResult status = ProcessGestureEvent(target, event); | 264 ProcessGestureEvent(target, event); |
265 return status != ui::ER_UNHANDLED; | 265 return event->default_prevented(); |
266 } | 266 } |
267 | 267 |
268 return false; | 268 return false; |
269 } | 269 } |
270 | 270 |
271 void RootWindow::OnWindowDestroying(Window* window) { | 271 void RootWindow::OnWindowDestroying(Window* window) { |
272 OnWindowHidden(window, WINDOW_DESTROYED, NULL); | 272 OnWindowHidden(window, WINDOW_DESTROYED, NULL); |
273 | 273 |
274 if (window->IsVisible() && | 274 if (window->IsVisible() && |
275 window->ContainsPointInRoot(GetLastMouseLocationInRoot())) { | 275 window->ContainsPointInRoot(GetLastMouseLocationInRoot())) { |
(...skipping 332 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
608 if (mouse_moved_handler_ && mouse_moved_handler_->delegate()) { | 608 if (mouse_moved_handler_ && mouse_moved_handler_->delegate()) { |
609 ui::MouseEvent translated_event(event, | 609 ui::MouseEvent translated_event(event, |
610 static_cast<Window*>(this), | 610 static_cast<Window*>(this), |
611 mouse_moved_handler_, | 611 mouse_moved_handler_, |
612 ui::ET_MOUSE_ENTERED, | 612 ui::ET_MOUSE_ENTERED, |
613 event.flags()); | 613 event.flags()); |
614 ProcessMouseEvent(mouse_moved_handler_, &translated_event); | 614 ProcessMouseEvent(mouse_moved_handler_, &translated_event); |
615 } | 615 } |
616 } | 616 } |
617 | 617 |
618 bool RootWindow::ProcessMouseEvent(Window* target, ui::MouseEvent* event) { | 618 void RootWindow::ProcessMouseEvent(Window* target, ui::MouseEvent* event) { |
619 base::AutoReset<Window*> reset(&event_dispatch_target_, target); | 619 base::AutoReset<Window*> reset(&event_dispatch_target_, target); |
620 return ProcessEvent(target, event) != ui::ER_UNHANDLED; | 620 ProcessEvent(target, event); |
621 } | 621 } |
622 | 622 |
623 bool RootWindow::ProcessKeyEvent(Window* target, ui::KeyEvent* event) { | 623 void RootWindow::ProcessKeyEvent(Window* target, ui::KeyEvent* event) { |
624 if (!target) | 624 if (!target) |
625 target = this; | 625 target = this; |
626 base::AutoReset<Window*> reset(&event_dispatch_target_, target); | 626 base::AutoReset<Window*> reset(&event_dispatch_target_, target); |
627 return ProcessEvent(target, event) != ui::ER_UNHANDLED; | 627 ProcessEvent(target, event); |
628 } | 628 } |
629 | 629 |
630 bool RootWindow::ProcessScrollEvent(Window* target, ui::ScrollEvent* event) { | 630 void RootWindow::ProcessScrollEvent(Window* target, ui::ScrollEvent* event) { |
631 base::AutoReset<Window*> reset(&event_dispatch_target_, target); | 631 base::AutoReset<Window*> reset(&event_dispatch_target_, target); |
632 return ProcessEvent(target, event) != ui::ER_UNHANDLED; | 632 ProcessEvent(target, event); |
633 } | 633 } |
634 | 634 |
635 ui::EventResult RootWindow::ProcessTouchEvent(Window* target, | 635 void RootWindow::ProcessTouchEvent(Window* target, ui::TouchEvent* event) { |
636 ui::TouchEvent* event) { | |
637 if (!target) | 636 if (!target) |
638 target = this; | 637 target = this; |
639 base::AutoReset<Window*> reset(&event_dispatch_target_, target); | 638 base::AutoReset<Window*> reset(&event_dispatch_target_, target); |
640 return static_cast<ui::EventResult>(ProcessEvent(target, event)); | 639 ProcessEvent(target, event); |
641 } | 640 } |
642 | 641 |
643 ui::EventResult RootWindow::ProcessGestureEvent(Window* target, | 642 void RootWindow::ProcessGestureEvent(Window* target, ui::GestureEvent* event) { |
644 ui::GestureEvent* event) { | |
645 if (!target) | 643 if (!target) |
646 target = this; | 644 target = this; |
647 base::AutoReset<Window*> reset(&event_dispatch_target_, target); | 645 base::AutoReset<Window*> reset(&event_dispatch_target_, target); |
648 return static_cast<ui::EventResult>(ProcessEvent(target, event)); | 646 ProcessEvent(target, event); |
649 } | 647 } |
650 | 648 |
651 bool RootWindow::ProcessGestures(ui::GestureRecognizer::Gestures* gestures) { | 649 bool RootWindow::ProcessGestures(ui::GestureRecognizer::Gestures* gestures) { |
652 if (!gestures) | 650 if (!gestures) |
653 return false; | 651 return false; |
654 bool handled = false; | 652 bool handled = false; |
655 for (unsigned int i = 0; i < gestures->size(); i++) { | 653 for (unsigned int i = 0; i < gestures->size(); i++) { |
656 ui::GestureEvent* gesture = gestures->get().at(i); | 654 ui::GestureEvent* gesture = gestures->get().at(i); |
657 if (DispatchGestureEvent(gesture) != ui::ER_UNHANDLED) | 655 if (DispatchGestureEvent(gesture) != ui::ER_UNHANDLED) |
658 handled = true; | 656 handled = true; |
(...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
781 bool RootWindow::OnHostKeyEvent(ui::KeyEvent* event) { | 779 bool RootWindow::OnHostKeyEvent(ui::KeyEvent* event) { |
782 DispatchHeldMouseMove(); | 780 DispatchHeldMouseMove(); |
783 if (event->key_code() == ui::VKEY_UNKNOWN) | 781 if (event->key_code() == ui::VKEY_UNKNOWN) |
784 return false; | 782 return false; |
785 client::EventClient* client = client::GetEventClient(GetRootWindow()); | 783 client::EventClient* client = client::GetEventClient(GetRootWindow()); |
786 Window* focused_window = client::GetFocusClient(this)->GetFocusedWindow(); | 784 Window* focused_window = client::GetFocusClient(this)->GetFocusedWindow(); |
787 if (client && !client->CanProcessEventsWithinSubtree(focused_window)) { | 785 if (client && !client->CanProcessEventsWithinSubtree(focused_window)) { |
788 client::GetFocusClient(this)->FocusWindow(NULL, NULL); | 786 client::GetFocusClient(this)->FocusWindow(NULL, NULL); |
789 return false; | 787 return false; |
790 } | 788 } |
791 return ProcessKeyEvent(focused_window, event); | 789 ProcessKeyEvent(focused_window, event); |
| 790 return event->default_prevented(); |
792 } | 791 } |
793 | 792 |
794 bool RootWindow::OnHostMouseEvent(ui::MouseEvent* event) { | 793 bool RootWindow::OnHostMouseEvent(ui::MouseEvent* event) { |
795 if (event->type() == ui::ET_MOUSE_DRAGGED || | 794 if (event->type() == ui::ET_MOUSE_DRAGGED || |
796 (event->flags() & ui::EF_IS_SYNTHESIZED)) { | 795 (event->flags() & ui::EF_IS_SYNTHESIZED)) { |
797 if (mouse_move_hold_count_) { | 796 if (mouse_move_hold_count_) { |
798 Window* null_window = static_cast<Window*>(NULL); | 797 Window* null_window = static_cast<Window*>(NULL); |
799 held_mouse_move_.reset( | 798 held_mouse_move_.reset( |
800 new ui::MouseEvent(*event, null_window, null_window)); | 799 new ui::MouseEvent(*event, null_window, null_window)); |
801 return true; | 800 return true; |
(...skipping 22 matching lines...) Expand all Loading... |
824 target = GetEventHandlerForPoint(event->location()); | 823 target = GetEventHandlerForPoint(event->location()); |
825 | 824 |
826 if (target && target->delegate()) { | 825 if (target && target->delegate()) { |
827 int flags = event->flags(); | 826 int flags = event->flags(); |
828 gfx::Point location_in_window = event->location(); | 827 gfx::Point location_in_window = event->location(); |
829 Window::ConvertPointToTarget(this, target, &location_in_window); | 828 Window::ConvertPointToTarget(this, target, &location_in_window); |
830 if (IsNonClientLocation(target, location_in_window)) | 829 if (IsNonClientLocation(target, location_in_window)) |
831 flags |= ui::EF_IS_NON_CLIENT; | 830 flags |= ui::EF_IS_NON_CLIENT; |
832 event->set_flags(flags); | 831 event->set_flags(flags); |
833 event->ConvertLocationToTarget(static_cast<Window*>(this), target); | 832 event->ConvertLocationToTarget(static_cast<Window*>(this), target); |
834 return ProcessScrollEvent(target, event); | 833 ProcessScrollEvent(target, event); |
| 834 return event->default_prevented(); |
835 } | 835 } |
836 return false; | 836 return false; |
837 } | 837 } |
838 | 838 |
839 bool RootWindow::OnHostTouchEvent(ui::TouchEvent* event) { | 839 bool RootWindow::OnHostTouchEvent(ui::TouchEvent* event) { |
840 DispatchHeldMouseMove(); | 840 DispatchHeldMouseMove(); |
841 switch (event->type()) { | 841 switch (event->type()) { |
842 case ui::ET_TOUCH_PRESSED: | 842 case ui::ET_TOUCH_PRESSED: |
843 touch_ids_down_ |= (1 << event->touch_id()); | 843 touch_ids_down_ |= (1 << event->touch_id()); |
844 Env::GetInstance()->set_touch_down(touch_ids_down_ != 0); | 844 Env::GetInstance()->set_touch_down(touch_ids_down_ != 0); |
845 break; | 845 break; |
846 | 846 |
847 // Don't handle ET_TOUCH_CANCELLED since we always get a ET_TOUCH_RELEASED. | 847 // Don't handle ET_TOUCH_CANCELLED since we always get a ET_TOUCH_RELEASED. |
848 case ui::ET_TOUCH_RELEASED: | 848 case ui::ET_TOUCH_RELEASED: |
849 touch_ids_down_ = (touch_ids_down_ | (1 << event->touch_id())) ^ | 849 touch_ids_down_ = (touch_ids_down_ | (1 << event->touch_id())) ^ |
850 (1 << event->touch_id()); | 850 (1 << event->touch_id()); |
851 Env::GetInstance()->set_touch_down(touch_ids_down_ != 0); | 851 Env::GetInstance()->set_touch_down(touch_ids_down_ != 0); |
852 break; | 852 break; |
853 | 853 |
854 default: | 854 default: |
855 break; | 855 break; |
856 } | 856 } |
857 TransformEventForDeviceScaleFactor(event); | 857 TransformEventForDeviceScaleFactor(event); |
858 bool handled = false; | 858 bool handled = false; |
859 ui::EventResult result = ui::ER_UNHANDLED; | |
860 Window* target = client::GetCaptureWindow(this); | 859 Window* target = client::GetCaptureWindow(this); |
861 if (!target) { | 860 if (!target) { |
862 target = ConsumerToWindow( | 861 target = ConsumerToWindow( |
863 gesture_recognizer_->GetTouchLockedTarget(event)); | 862 gesture_recognizer_->GetTouchLockedTarget(event)); |
864 if (!target) { | 863 if (!target) { |
865 target = ConsumerToWindow( | 864 target = ConsumerToWindow( |
866 gesture_recognizer_->GetTargetForLocation(event->location())); | 865 gesture_recognizer_->GetTargetForLocation(event->location())); |
867 } | 866 } |
868 } | 867 } |
869 | 868 |
| 869 ui::EventResult result = ui::ER_UNHANDLED; |
870 if (!target && !bounds().Contains(event->location())) { | 870 if (!target && !bounds().Contains(event->location())) { |
871 // If the initial touch is outside the root window, target the root. | 871 // If the initial touch is outside the root window, target the root. |
872 target = this; | 872 target = this; |
873 result = ProcessTouchEvent(target, event); | 873 ProcessTouchEvent(target, event); |
874 CHECK_EQ(ui::ER_UNHANDLED, result); | 874 CHECK_EQ(ui::ER_UNHANDLED, event->result()); |
| 875 result = event->result(); |
875 } else { | 876 } else { |
876 // We only come here when the first contact was within the root window. | 877 // We only come here when the first contact was within the root window. |
877 if (!target) { | 878 if (!target) { |
878 target = GetEventHandlerForPoint(event->location()); | 879 target = GetEventHandlerForPoint(event->location()); |
879 if (!target) | 880 if (!target) |
880 return false; | 881 return false; |
881 } | 882 } |
882 | 883 |
883 ui::TouchEvent translated_event( | 884 ui::TouchEvent translated_event( |
884 *event, static_cast<Window*>(this), target); | 885 *event, static_cast<Window*>(this), target); |
885 result = ProcessTouchEvent(target, &translated_event); | 886 ProcessTouchEvent(target, &translated_event); |
886 handled = result != ui::ER_UNHANDLED; | 887 handled = translated_event.default_prevented(); |
| 888 result = translated_event.result(); |
887 } | 889 } |
888 | 890 |
889 // Get the list of GestureEvents from GestureRecognizer. | 891 // Get the list of GestureEvents from GestureRecognizer. |
890 scoped_ptr<ui::GestureRecognizer::Gestures> gestures; | 892 scoped_ptr<ui::GestureRecognizer::Gestures> gestures; |
891 gestures.reset(gesture_recognizer_->ProcessTouchEventForGesture( | 893 gestures.reset(gesture_recognizer_->ProcessTouchEventForGesture( |
892 *event, result, target)); | 894 *event, result, target)); |
893 | 895 |
894 return ProcessGestures(gestures.get()) ? true : handled; | 896 return ProcessGestures(gestures.get()) ? true : handled; |
895 } | 897 } |
896 | 898 |
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
984 ~event->changed_button_flags(); | 986 ~event->changed_button_flags(); |
985 Env::GetInstance()->set_mouse_button_flags(mouse_button_flags_); | 987 Env::GetInstance()->set_mouse_button_flags(mouse_button_flags_); |
986 break; | 988 break; |
987 default: | 989 default: |
988 break; | 990 break; |
989 } | 991 } |
990 if (target) { | 992 if (target) { |
991 event->ConvertLocationToTarget(static_cast<Window*>(this), target); | 993 event->ConvertLocationToTarget(static_cast<Window*>(this), target); |
992 if (IsNonClientLocation(target, event->location())) | 994 if (IsNonClientLocation(target, event->location())) |
993 event->set_flags(event->flags() | ui::EF_IS_NON_CLIENT); | 995 event->set_flags(event->flags() | ui::EF_IS_NON_CLIENT); |
994 return ProcessMouseEvent(target, event); | 996 ProcessMouseEvent(target, event); |
| 997 return event->default_prevented(); |
995 } | 998 } |
996 return false; | 999 return false; |
997 } | 1000 } |
998 | 1001 |
999 void RootWindow::DispatchHeldMouseMove() { | 1002 void RootWindow::DispatchHeldMouseMove() { |
1000 if (held_mouse_move_.get()) { | 1003 if (held_mouse_move_.get()) { |
1001 // If a mouse move has been synthesized, the target location is suspect, | 1004 // If a mouse move has been synthesized, the target location is suspect, |
1002 // so drop the held event. | 1005 // so drop the held event. |
1003 if (!synthesize_mouse_move_) | 1006 if (!synthesize_mouse_move_) |
1004 DispatchMouseEventImpl(held_mouse_move_.get()); | 1007 DispatchMouseEventImpl(held_mouse_move_.get()); |
(...skipping 30 matching lines...) Expand all Loading... |
1035 ui::MouseEvent event(ui::ET_MOUSE_MOVED, | 1038 ui::MouseEvent event(ui::ET_MOUSE_MOVED, |
1036 orig_mouse_location, | 1039 orig_mouse_location, |
1037 orig_mouse_location, | 1040 orig_mouse_location, |
1038 ui::EF_IS_SYNTHESIZED); | 1041 ui::EF_IS_SYNTHESIZED); |
1039 event.set_system_location(Env::GetInstance()->last_mouse_location()); | 1042 event.set_system_location(Env::GetInstance()->last_mouse_location()); |
1040 OnHostMouseEvent(&event); | 1043 OnHostMouseEvent(&event); |
1041 #endif | 1044 #endif |
1042 } | 1045 } |
1043 | 1046 |
1044 } // namespace aura | 1047 } // namespace aura |
OLD | NEW |