Chromium Code Reviews| 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 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 57 } | 57 } |
| 58 | 58 |
| 59 typedef std::vector<EventFilter*> EventFilters; | 59 typedef std::vector<EventFilter*> EventFilters; |
| 60 | 60 |
| 61 void GetEventFiltersToNotify(Window* target, EventFilters* filters) { | 61 void GetEventFiltersToNotify(Window* target, EventFilters* filters) { |
| 62 while (target) { | 62 while (target) { |
| 63 if (target->event_filter()) | 63 if (target->event_filter()) |
| 64 filters->push_back(target->event_filter()); | 64 filters->push_back(target->event_filter()); |
| 65 target = target->parent(); | 65 target = target->parent(); |
| 66 } | 66 } |
| 67 if (Env::GetInstance()->event_filter()) | |
| 68 filters->push_back(Env::GetInstance()->event_filter()); | |
| 69 } | 67 } |
| 70 | 68 |
| 71 float GetDeviceScaleFactorFromDisplay(const Window* window) { | 69 float GetDeviceScaleFactorFromDisplay(const Window* window) { |
| 72 DisplayManager* display_manager = Env::GetInstance()->display_manager(); | 70 DisplayManager* display_manager = Env::GetInstance()->display_manager(); |
| 73 return display_manager->GetDisplayNearestWindow(window).device_scale_factor(); | 71 return display_manager->GetDisplayNearestWindow(window).device_scale_factor(); |
| 74 } | 72 } |
| 75 | 73 |
| 76 Window* ConsumerToWindow(ui::GestureConsumer* consumer) { | 74 Window* ConsumerToWindow(ui::GestureConsumer* consumer) { |
| 77 return consumer && !consumer->ignores_events() ? | 75 return consumer && !consumer->ignores_events() ? |
| 78 static_cast<Window*>(consumer) : NULL; | 76 static_cast<Window*>(consumer) : NULL; |
| (...skipping 390 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 469 void RootWindow::SetTransform(const ui::Transform& transform) { | 467 void RootWindow::SetTransform(const ui::Transform& transform) { |
| 470 Window::SetTransform(transform); | 468 Window::SetTransform(transform); |
| 471 | 469 |
| 472 // If the layer is not animating, then we need to update the host size | 470 // If the layer is not animating, then we need to update the host size |
| 473 // immediately. | 471 // immediately. |
| 474 if (!layer()->GetAnimator()->is_animating()) | 472 if (!layer()->GetAnimator()->is_animating()) |
| 475 OnHostResized(host_->GetBounds().size()); | 473 OnHostResized(host_->GetBounds().size()); |
| 476 } | 474 } |
| 477 | 475 |
| 478 //////////////////////////////////////////////////////////////////////////////// | 476 //////////////////////////////////////////////////////////////////////////////// |
| 477 // RootWindow, ui::EventTarget implementation: | |
| 478 | |
| 479 ui::EventTarget* RootWindow::GetParentTarget() { | |
| 480 return Env::GetInstance(); | |
| 481 } | |
| 482 | |
| 483 //////////////////////////////////////////////////////////////////////////////// | |
| 479 // RootWindow, ui::CompositorDelegate implementation: | 484 // RootWindow, ui::CompositorDelegate implementation: |
| 480 | 485 |
| 481 void RootWindow::ScheduleDraw() { | 486 void RootWindow::ScheduleDraw() { |
| 482 if (compositor_lock_) { | 487 if (compositor_lock_) { |
| 483 draw_on_compositor_unlock_ = true; | 488 draw_on_compositor_unlock_ = true; |
| 484 } else if (!defer_draw_scheduling_) { | 489 } else if (!defer_draw_scheduling_) { |
| 485 defer_draw_scheduling_ = true; | 490 defer_draw_scheduling_ = true; |
| 486 MessageLoop::current()->PostTask( | 491 MessageLoop::current()->PostTask( |
| 487 FROM_HERE, | 492 FROM_HERE, |
| 488 base::Bind(&RootWindow::Draw, schedule_paint_factory_.GetWeakPtr())); | 493 base::Bind(&RootWindow::Draw, schedule_paint_factory_.GetWeakPtr())); |
| (...skipping 168 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 657 } | 662 } |
| 658 | 663 |
| 659 ui::TouchStatus RootWindow::ProcessTouchEvent(Window* target, | 664 ui::TouchStatus RootWindow::ProcessTouchEvent(Window* target, |
| 660 ui::TouchEvent* event) { | 665 ui::TouchEvent* event) { |
| 661 if (ProcessEvent(NULL, event) != ui::ER_UNHANDLED) | 666 if (ProcessEvent(NULL, event) != ui::ER_UNHANDLED) |
| 662 return ui::TOUCH_STATUS_CONTINUE; | 667 return ui::TOUCH_STATUS_CONTINUE; |
| 663 | 668 |
| 664 if (!target->IsVisible()) | 669 if (!target->IsVisible()) |
| 665 return ui::TOUCH_STATUS_UNKNOWN; | 670 return ui::TOUCH_STATUS_UNKNOWN; |
| 666 | 671 |
| 672 ui::Event::DispatcherApi dispatch_helper(event); | |
| 673 dispatch_helper.set_target(target); | |
| 674 | |
| 675 // It is necessary to dispatch the event to the event-handlers on env first. | |
| 676 // TODO(sad): Fix touch-event handling so it can use the same | |
| 677 // event-dispatching code used for other events. | |
| 678 ui::EventTarget::DispatcherApi dispatch_target_helper(Env::GetInstance()); | |
| 679 const ui::EventHandlerList& pre_target = | |
| 680 dispatch_target_helper.pre_target_list(); | |
| 681 for (ui::EventHandlerList::const_iterator iter = pre_target.begin(); | |
| 682 iter != pre_target.end(); ++iter) { | |
| 683 ui::TouchStatus status = (*iter)->OnTouchEvent(event); | |
| 684 if (status != ui::TOUCH_STATUS_UNKNOWN) | |
| 685 return status; | |
| 686 } | |
| 687 | |
| 667 EventFilters filters; | 688 EventFilters filters; |
| 668 if (target == this) | 689 if (target == this) |
| 669 GetEventFiltersToNotify(target, &filters); | 690 GetEventFiltersToNotify(target, &filters); |
| 670 else | 691 else |
| 671 GetEventFiltersToNotify(target->parent(), &filters); | 692 GetEventFiltersToNotify(target->parent(), &filters); |
| 672 | 693 |
| 673 // |target| can be deleted by any of the handlers below. | 694 // |target| can be deleted by any of the handlers below. |
| 674 WindowTracker tracker; | 695 WindowTracker tracker; |
| 675 tracker.Add(target); | 696 tracker.Add(target); |
| 676 | 697 |
| 677 ui::Event::DispatcherApi dispatcher(event); | |
| 678 dispatcher.set_target(target); | |
| 679 for (EventFilters::const_reverse_iterator it = filters.rbegin(), | 698 for (EventFilters::const_reverse_iterator it = filters.rbegin(), |
| 680 rend = filters.rend(); | 699 rend = filters.rend(); |
| 681 it != rend; ++it) { | 700 it != rend; ++it) { |
| 682 ui::TouchStatus status = (*it)->PreHandleTouchEvent(target, event); | 701 ui::TouchStatus status = (*it)->PreHandleTouchEvent(target, event); |
| 683 if (status != ui::TOUCH_STATUS_UNKNOWN) | 702 if (status != ui::TOUCH_STATUS_UNKNOWN) |
| 684 return status; | 703 return status; |
| 685 } | 704 } |
| 686 | 705 |
| 687 if (tracker.Contains(target) && target->delegate()) { | 706 if (tracker.Contains(target) && target->delegate()) { |
| 688 ui::TouchStatus status = target->delegate()->OnTouchEvent(event); | 707 ui::TouchStatus status = target->delegate()->OnTouchEvent(event); |
| (...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 784 if (attached->IsVisible() && | 803 if (attached->IsVisible() && |
| 785 attached->ContainsPointInRoot(GetLastMouseLocationInRoot())) | 804 attached->ContainsPointInRoot(GetLastMouseLocationInRoot())) |
| 786 PostMouseMoveEventAfterWindowChange(); | 805 PostMouseMoveEventAfterWindowChange(); |
| 787 } | 806 } |
| 788 | 807 |
| 789 bool RootWindow::CanDispatchToTarget(ui::EventTarget* target) { | 808 bool RootWindow::CanDispatchToTarget(ui::EventTarget* target) { |
| 790 return event_dispatch_target_ == target; | 809 return event_dispatch_target_ == target; |
| 791 } | 810 } |
| 792 | 811 |
| 793 void RootWindow::ProcessPreTargetList(ui::EventHandlerList* list) { | 812 void RootWindow::ProcessPreTargetList(ui::EventHandlerList* list) { |
| 794 if (Env::GetInstance()->event_filter()) | |
| 795 list->insert(list->begin(), Env::GetInstance()->event_filter()); | |
| 796 } | 813 } |
| 797 | 814 |
| 798 void RootWindow::ProcessPostTargetList(ui::EventHandlerList* list) { | 815 void RootWindow::ProcessPostTargetList(ui::EventHandlerList* list) { |
|
Ben Goodger (Google)
2012/09/21 18:09:18
seems like you could also nix this api now, since
sadrul
2012/09/21 19:05:36
Good point. But I am going to keep this for now si
| |
| 799 // TODO(sad): | |
| 800 } | 816 } |
| 801 | 817 |
| 802 bool RootWindow::DispatchLongPressGestureEvent(ui::GestureEvent* event) { | 818 bool RootWindow::DispatchLongPressGestureEvent(ui::GestureEvent* event) { |
| 803 return DispatchGestureEvent(event); | 819 return DispatchGestureEvent(event); |
| 804 } | 820 } |
| 805 | 821 |
| 806 bool RootWindow::DispatchCancelTouchEvent(ui::TouchEvent* event) { | 822 bool RootWindow::DispatchCancelTouchEvent(ui::TouchEvent* event) { |
| 807 return OnHostTouchEvent(event); | 823 return OnHostTouchEvent(event); |
| 808 } | 824 } |
| 809 | 825 |
| (...skipping 282 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1092 void RootWindow::UnlockCompositor() { | 1108 void RootWindow::UnlockCompositor() { |
| 1093 DCHECK(compositor_lock_); | 1109 DCHECK(compositor_lock_); |
| 1094 compositor_lock_ = NULL; | 1110 compositor_lock_ = NULL; |
| 1095 if (draw_on_compositor_unlock_) { | 1111 if (draw_on_compositor_unlock_) { |
| 1096 draw_on_compositor_unlock_ = false; | 1112 draw_on_compositor_unlock_ = false; |
| 1097 ScheduleDraw(); | 1113 ScheduleDraw(); |
| 1098 } | 1114 } |
| 1099 } | 1115 } |
| 1100 | 1116 |
| 1101 } // namespace aura | 1117 } // namespace aura |
| OLD | NEW |