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

Side by Side Diff: ui/aura/root_window.cc

Issue 10827145: Convert Aura to use ui::Event. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Created 8 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
« no previous file with comments | « ui/aura/root_window.h ('k') | ui/aura/root_window_host_delegate.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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/bind.h" 9 #include "base/bind.h"
10 #include "base/command_line.h" 10 #include "base/command_line.h"
11 #include "base/debug/trace_event.h" 11 #include "base/debug/trace_event.h"
12 #include "base/logging.h" 12 #include "base/logging.h"
13 #include "base/message_loop.h" 13 #include "base/message_loop.h"
14 #include "ui/aura/aura_switches.h" 14 #include "ui/aura/aura_switches.h"
15 #include "ui/aura/client/activation_client.h" 15 #include "ui/aura/client/activation_client.h"
16 #include "ui/aura/client/capture_client.h" 16 #include "ui/aura/client/capture_client.h"
17 #include "ui/aura/client/drag_drop_client.h" 17 #include "ui/aura/client/drag_drop_client.h"
18 #include "ui/aura/client/event_client.h" 18 #include "ui/aura/client/event_client.h"
19 #include "ui/aura/client/screen_position_client.h" 19 #include "ui/aura/client/screen_position_client.h"
20 #include "ui/aura/env.h" 20 #include "ui/aura/env.h"
21 #include "ui/aura/event.h"
22 #include "ui/aura/event_filter.h" 21 #include "ui/aura/event_filter.h"
23 #include "ui/aura/focus_manager.h" 22 #include "ui/aura/focus_manager.h"
24 #include "ui/aura/display_manager.h" 23 #include "ui/aura/display_manager.h"
25 #include "ui/aura/root_window_host.h" 24 #include "ui/aura/root_window_host.h"
26 #include "ui/aura/root_window_observer.h" 25 #include "ui/aura/root_window_observer.h"
27 #include "ui/aura/window.h" 26 #include "ui/aura/window.h"
28 #include "ui/aura/window_delegate.h" 27 #include "ui/aura/window_delegate.h"
28 #include "ui/base/event.h"
29 #include "ui/base/gestures/gesture_recognizer.h" 29 #include "ui/base/gestures/gesture_recognizer.h"
30 #include "ui/base/gestures/gesture_types.h" 30 #include "ui/base/gestures/gesture_types.h"
31 #include "ui/base/hit_test.h" 31 #include "ui/base/hit_test.h"
32 #include "ui/compositor/compositor.h" 32 #include "ui/compositor/compositor.h"
33 #include "ui/compositor/dip_util.h" 33 #include "ui/compositor/dip_util.h"
34 #include "ui/compositor/layer.h" 34 #include "ui/compositor/layer.h"
35 #include "ui/compositor/layer_animator.h" 35 #include "ui/compositor/layer_animator.h"
36 #include "ui/gfx/display.h" 36 #include "ui/gfx/display.h"
37 #include "ui/gfx/point3.h" 37 #include "ui/gfx/point3.h"
38 #include "ui/gfx/screen.h" 38 #include "ui/gfx/screen.h"
(...skipping 226 matching lines...) Expand 10 before | Expand all | Expand 10 after
265 TRACE_EVENT_ASYNC_BEGIN0("ui", "RootWindow::Draw", 265 TRACE_EVENT_ASYNC_BEGIN0("ui", "RootWindow::Draw",
266 compositor_->last_started_frame() + 1); 266 compositor_->last_started_frame() + 1);
267 267
268 compositor_->Draw(false); 268 compositor_->Draw(false);
269 } 269 }
270 270
271 void RootWindow::ScheduleFullDraw() { 271 void RootWindow::ScheduleFullDraw() {
272 compositor_->ScheduleFullDraw(); 272 compositor_->ScheduleFullDraw();
273 } 273 }
274 274
275 bool RootWindow::DispatchGestureEvent(GestureEvent* event) { 275 bool RootWindow::DispatchGestureEvent(ui::GestureEventImpl* event) {
276 DispatchHeldMouseMove(); 276 DispatchHeldMouseMove();
277 277
278 Window* target = client::GetCaptureWindow(this); 278 Window* target = client::GetCaptureWindow(this);
279 if (!target) { 279 if (!target) {
280 target = ConsumerToWindow( 280 target = ConsumerToWindow(
281 gesture_recognizer_->GetTargetForGestureEvent(event)); 281 gesture_recognizer_->GetTargetForGestureEvent(event));
282 if (!target) 282 if (!target)
283 return false; 283 return false;
284 } 284 }
285 285
286 if (target) { 286 if (target) {
287 GestureEvent translated_event(*event, this, target); 287 ui::GestureEventImpl translated_event(
288 *event, static_cast<Window*>(this), target);
288 ui::GestureStatus status = ProcessGestureEvent(target, &translated_event); 289 ui::GestureStatus status = ProcessGestureEvent(target, &translated_event);
289 return status != ui::GESTURE_STATUS_UNKNOWN; 290 return status != ui::GESTURE_STATUS_UNKNOWN;
290 } 291 }
291 292
292 return false; 293 return false;
293 } 294 }
294 295
295 void RootWindow::OnWindowDestroying(Window* window) { 296 void RootWindow::OnWindowDestroying(Window* window) {
296 OnWindowHidden(window, true); 297 OnWindowHidden(window, true);
297 298
(...skipping 214 matching lines...) Expand 10 before | Expand all | Expand 10 after
512 } 513 }
513 514
514 //////////////////////////////////////////////////////////////////////////////// 515 ////////////////////////////////////////////////////////////////////////////////
515 // RootWindow, overridden from aura::client::CaptureDelegate: 516 // RootWindow, overridden from aura::client::CaptureDelegate:
516 517
517 void RootWindow::UpdateCapture(Window* old_capture, 518 void RootWindow::UpdateCapture(Window* old_capture,
518 Window* new_capture) { 519 Window* new_capture) {
519 if (old_capture && old_capture->GetRootWindow() == this && 520 if (old_capture && old_capture->GetRootWindow() == this &&
520 old_capture->delegate()) { 521 old_capture->delegate()) {
521 // Send a capture changed event with bogus location data. 522 // Send a capture changed event with bogus location data.
522 MouseEvent event( 523 ui::MouseEvent event(ui::ET_MOUSE_CAPTURE_CHANGED, gfx::Point(),
523 ui::ET_MOUSE_CAPTURE_CHANGED, gfx::Point(), gfx::Point(), 0); 524 gfx::Point(), 0);
524 ProcessMouseEvent(old_capture, &event); 525 ProcessMouseEvent(old_capture, &event);
525 526
526 old_capture->delegate()->OnCaptureLost(); 527 old_capture->delegate()->OnCaptureLost();
527 } 528 }
528 529
529 // Reset the mouse_moved_handler_ if the mouse_moved_handler_ belongs 530 // Reset the mouse_moved_handler_ if the mouse_moved_handler_ belongs
530 // to another root window when losing the capture. 531 // to another root window when losing the capture.
531 if (mouse_moved_handler_ && old_capture && 532 if (mouse_moved_handler_ && old_capture &&
532 old_capture->Contains(mouse_moved_handler_) && 533 old_capture->Contains(mouse_moved_handler_) &&
533 old_capture->GetRootWindow() != this) { 534 old_capture->GetRootWindow() != this) {
(...skipping 23 matching lines...) Expand all
557 558
558 gfx::Point RootWindow::QueryMouseLocationForTest() const { 559 gfx::Point RootWindow::QueryMouseLocationForTest() const {
559 gfx::Point point; 560 gfx::Point point;
560 host_->QueryMouseLocation(&point); 561 host_->QueryMouseLocation(&point);
561 return point; 562 return point;
562 } 563 }
563 564
564 //////////////////////////////////////////////////////////////////////////////// 565 ////////////////////////////////////////////////////////////////////////////////
565 // RootWindow, private: 566 // RootWindow, private:
566 567
567 void RootWindow::HandleMouseMoved(const MouseEvent& event, Window* target) { 568 void RootWindow::HandleMouseMoved(const ui::MouseEvent& event, Window* target) {
568 if (target == mouse_moved_handler_) 569 if (target == mouse_moved_handler_)
569 return; 570 return;
570 571
571 // Send an exited event. 572 // Send an exited event.
572 if (mouse_moved_handler_ && mouse_moved_handler_->delegate()) { 573 if (mouse_moved_handler_ && mouse_moved_handler_->delegate()) {
573 MouseEvent translated_event(event, this, mouse_moved_handler_, 574 ui::MouseEvent translated_event(event,
574 ui::ET_MOUSE_EXITED, event.flags()); 575 static_cast<Window*>(this),
576 mouse_moved_handler_,
577 ui::ET_MOUSE_EXITED,
578 event.flags());
575 ProcessMouseEvent(mouse_moved_handler_, &translated_event); 579 ProcessMouseEvent(mouse_moved_handler_, &translated_event);
576 } 580 }
577 mouse_moved_handler_ = target; 581 mouse_moved_handler_ = target;
578 // Send an entered event. 582 // Send an entered event.
579 if (mouse_moved_handler_ && mouse_moved_handler_->delegate()) { 583 if (mouse_moved_handler_ && mouse_moved_handler_->delegate()) {
580 MouseEvent translated_event(event, this, mouse_moved_handler_, 584 ui::MouseEvent translated_event(event,
581 ui::ET_MOUSE_ENTERED, event.flags()); 585 static_cast<Window*>(this),
586 mouse_moved_handler_,
587 ui::ET_MOUSE_ENTERED,
588 event.flags());
582 ProcessMouseEvent(mouse_moved_handler_, &translated_event); 589 ProcessMouseEvent(mouse_moved_handler_, &translated_event);
583 } 590 }
584 } 591 }
585 592
586 bool RootWindow::ProcessMouseEvent(Window* target, MouseEvent* event) { 593 bool RootWindow::ProcessMouseEvent(Window* target, ui::MouseEvent* event) {
587 if (!target->IsVisible()) 594 if (!target->IsVisible())
588 return false; 595 return false;
589 596
590 EventFilters filters; 597 EventFilters filters;
591 GetEventFiltersToNotify(target->parent(), &filters); 598 GetEventFiltersToNotify(target->parent(), &filters);
592 for (EventFilters::const_reverse_iterator it = filters.rbegin(), 599 for (EventFilters::const_reverse_iterator it = filters.rbegin(),
593 rend = filters.rend(); 600 rend = filters.rend();
594 it != rend; ++it) { 601 it != rend; ++it) {
595 if ((*it)->PreHandleMouseEvent(target, event)) 602 if ((*it)->PreHandleMouseEvent(target, event))
596 return true; 603 return true;
597 } 604 }
598 605
599 if (!target->delegate()) 606 if (!target->delegate())
600 return false; 607 return false;
601 return target->delegate()->OnMouseEvent(event); 608 return target->delegate()->OnMouseEvent(event);
602 } 609 }
603 610
604 bool RootWindow::ProcessKeyEvent(Window* target, KeyEvent* event) { 611 bool RootWindow::ProcessKeyEvent(Window* target, ui::KeyEvent* event) {
605 EventFilters filters; 612 EventFilters filters;
606 613
607 if (!target) { 614 if (!target) {
608 // When no window is focused, send the key event to |this| so event filters 615 // When no window is focused, send the key event to |this| so event filters
609 // for the window could check if the key is a global shortcut like Alt+Tab. 616 // for the window could check if the key is a global shortcut like Alt+Tab.
610 target = this; 617 target = this;
611 GetEventFiltersToNotify(this, &filters); 618 GetEventFiltersToNotify(this, &filters);
612 } else { 619 } else {
613 if (!target->IsVisible()) 620 if (!target->IsVisible())
614 return false; 621 return false;
615 GetEventFiltersToNotify(target->parent(), &filters); 622 GetEventFiltersToNotify(target->parent(), &filters);
616 } 623 }
617 624
618 for (EventFilters::const_reverse_iterator it = filters.rbegin(), 625 for (EventFilters::const_reverse_iterator it = filters.rbegin(),
619 rend = filters.rend(); 626 rend = filters.rend();
620 it != rend; ++it) { 627 it != rend; ++it) {
621 if ((*it)->PreHandleKeyEvent(target, event)) 628 if ((*it)->PreHandleKeyEvent(target, event))
622 return true; 629 return true;
623 } 630 }
624 631
625 if (!target->delegate()) 632 if (!target->delegate())
626 return false; 633 return false;
627 return target->delegate()->OnKeyEvent(event); 634 return target->delegate()->OnKeyEvent(event);
628 } 635 }
629 636
630 ui::TouchStatus RootWindow::ProcessTouchEvent(Window* target, 637 ui::TouchStatus RootWindow::ProcessTouchEvent(Window* target,
631 TouchEvent* event) { 638 ui::TouchEventImpl* event) {
632 if (!target->IsVisible()) 639 if (!target->IsVisible())
633 return ui::TOUCH_STATUS_UNKNOWN; 640 return ui::TOUCH_STATUS_UNKNOWN;
634 641
635 EventFilters filters; 642 EventFilters filters;
636 if (target == this) 643 if (target == this)
637 GetEventFiltersToNotify(target, &filters); 644 GetEventFiltersToNotify(target, &filters);
638 else 645 else
639 GetEventFiltersToNotify(target->parent(), &filters); 646 GetEventFiltersToNotify(target->parent(), &filters);
640 for (EventFilters::const_reverse_iterator it = filters.rbegin(), 647 for (EventFilters::const_reverse_iterator it = filters.rbegin(),
641 rend = filters.rend(); 648 rend = filters.rend();
642 it != rend; ++it) { 649 it != rend; ++it) {
643 ui::TouchStatus status = (*it)->PreHandleTouchEvent(target, event); 650 ui::TouchStatus status = (*it)->PreHandleTouchEvent(target, event);
644 if (status != ui::TOUCH_STATUS_UNKNOWN) 651 if (status != ui::TOUCH_STATUS_UNKNOWN)
645 return status; 652 return status;
646 } 653 }
647 654
648 if (target->delegate()) 655 if (target->delegate())
649 return target->delegate()->OnTouchEvent(event); 656 return target->delegate()->OnTouchEvent(event);
650 657
651 return ui::TOUCH_STATUS_UNKNOWN; 658 return ui::TOUCH_STATUS_UNKNOWN;
652 } 659 }
653 660
654 ui::GestureStatus RootWindow::ProcessGestureEvent(Window* target, 661 ui::GestureStatus RootWindow::ProcessGestureEvent(Window* target,
655 GestureEvent* event) { 662 ui::GestureEventImpl* event) {
656 if (!target->IsVisible()) 663 if (!target->IsVisible())
657 return ui::GESTURE_STATUS_UNKNOWN; 664 return ui::GESTURE_STATUS_UNKNOWN;
658 665
659 EventFilters filters; 666 EventFilters filters;
660 if (target == this) 667 if (target == this)
661 GetEventFiltersToNotify(target, &filters); 668 GetEventFiltersToNotify(target, &filters);
662 else 669 else
663 GetEventFiltersToNotify(target->parent(), &filters); 670 GetEventFiltersToNotify(target->parent(), &filters);
664 ui::GestureStatus status = ui::GESTURE_STATUS_UNKNOWN; 671 ui::GestureStatus status = ui::GESTURE_STATUS_UNKNOWN;
665 for (EventFilters::const_reverse_iterator it = filters.rbegin(), 672 for (EventFilters::const_reverse_iterator it = filters.rbegin(),
666 rend = filters.rend(); 673 rend = filters.rend();
667 it != rend; ++it) { 674 it != rend; ++it) {
668 status = (*it)->PreHandleGestureEvent(target, event); 675 status = (*it)->PreHandleGestureEvent(target, event);
669 if (status != ui::GESTURE_STATUS_UNKNOWN) 676 if (status != ui::GESTURE_STATUS_UNKNOWN)
670 return status; 677 return status;
671 } 678 }
672 679
673 if (target->delegate()) 680 if (target->delegate())
674 status = target->delegate()->OnGestureEvent(event); 681 status = target->delegate()->OnGestureEvent(event);
675 682
676 return status; 683 return status;
677 } 684 }
678 685
679 bool RootWindow::ProcessGestures(ui::GestureRecognizer::Gestures* gestures) { 686 bool RootWindow::ProcessGestures(ui::GestureRecognizer::Gestures* gestures) {
680 if (!gestures) 687 if (!gestures)
681 return false; 688 return false;
682 bool handled = false; 689 bool handled = false;
683 for (unsigned int i = 0; i < gestures->size(); i++) { 690 for (unsigned int i = 0; i < gestures->size(); i++) {
684 GestureEvent* gesture = 691 ui::GestureEventImpl* gesture =
685 static_cast<GestureEvent*>(gestures->get().at(i)); 692 static_cast<ui::GestureEventImpl*>(gestures->get().at(i));
686 if (DispatchGestureEvent(gesture) != ui::GESTURE_STATUS_UNKNOWN) 693 if (DispatchGestureEvent(gesture) != ui::GESTURE_STATUS_UNKNOWN)
687 handled = true; 694 handled = true;
688 } 695 }
689 return handled; 696 return handled;
690 } 697 }
691 698
692 void RootWindow::OnWindowRemovedFromRootWindow(Window* detached) { 699 void RootWindow::OnWindowRemovedFromRootWindow(Window* detached) {
693 DCHECK(aura::client::GetCaptureWindow(this) != this); 700 DCHECK(aura::client::GetCaptureWindow(this) != this);
694 701
695 OnWindowHidden(detached, false); 702 OnWindowHidden(detached, false);
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
741 gesture_recognizer_->FlushTouchQueue(invisible); 748 gesture_recognizer_->FlushTouchQueue(invisible);
742 } 749 }
743 750
744 void RootWindow::OnWindowAddedToRootWindow(Window* attached) { 751 void RootWindow::OnWindowAddedToRootWindow(Window* attached) {
745 if (attached->IsVisible() && 752 if (attached->IsVisible() &&
746 attached->ContainsPointInRoot(GetLastMouseLocationInRoot())) 753 attached->ContainsPointInRoot(GetLastMouseLocationInRoot()))
747 PostMouseMoveEventAfterWindowChange(); 754 PostMouseMoveEventAfterWindowChange();
748 } 755 }
749 756
750 bool RootWindow::DispatchLongPressGestureEvent(ui::GestureEvent* event) { 757 bool RootWindow::DispatchLongPressGestureEvent(ui::GestureEvent* event) {
751 return DispatchGestureEvent(static_cast<GestureEvent*>(event)); 758 return DispatchGestureEvent(static_cast<ui::GestureEventImpl*>(event));
752 } 759 }
753 760
754 bool RootWindow::DispatchCancelTouchEvent(ui::TouchEvent* event) { 761 bool RootWindow::DispatchCancelTouchEvent(ui::TouchEvent* event) {
755 return OnHostTouchEvent(static_cast<TouchEvent*>(event)); 762 return OnHostTouchEvent(static_cast<ui::TouchEventImpl*>(event));
756 } 763 }
757 764
758 ui::GestureEvent* RootWindow::CreateGestureEvent( 765 ui::GestureEvent* RootWindow::CreateGestureEvent(
759 const ui::GestureEventDetails& details, 766 const ui::GestureEventDetails& details,
760 const gfx::Point& location, 767 const gfx::Point& location,
761 int flags, 768 int flags,
762 base::Time time, 769 base::Time time,
763 unsigned int touch_id_bitfield) { 770 unsigned int touch_id_bitfield) {
764 return new GestureEvent(details.type(), location.x(), location.y(), 771 return new ui::GestureEventImpl(details.type(), location.x(), location.y(),
765 flags, time, details, 772 flags, time, details, touch_id_bitfield);
766 touch_id_bitfield);
767 } 773 }
768 774
769 ui::TouchEvent* RootWindow::CreateTouchEvent(ui::EventType type, 775 ui::TouchEvent* RootWindow::CreateTouchEvent(ui::EventType type,
770 const gfx::Point& location, 776 const gfx::Point& location,
771 int touch_id, 777 int touch_id,
772 base::TimeDelta time_stamp) { 778 base::TimeDelta time_stamp) {
773 return new TouchEvent(type, location, touch_id, time_stamp); 779 return new ui::TouchEventImpl(type, location, touch_id, time_stamp);
774 } 780 }
775 781
776 void RootWindow::OnLayerAnimationEnded( 782 void RootWindow::OnLayerAnimationEnded(
777 ui::LayerAnimationSequence* animation) { 783 ui::LayerAnimationSequence* animation) {
778 OnHostResized(host_->GetBounds().size()); 784 OnHostResized(host_->GetBounds().size());
779 } 785 }
780 786
781 void RootWindow::OnLayerAnimationScheduled( 787 void RootWindow::OnLayerAnimationScheduled(
782 ui::LayerAnimationSequence* animation) { 788 ui::LayerAnimationSequence* animation) {
783 } 789 }
784 790
785 void RootWindow::OnLayerAnimationAborted( 791 void RootWindow::OnLayerAnimationAborted(
786 ui::LayerAnimationSequence* animation) { 792 ui::LayerAnimationSequence* animation) {
787 } 793 }
788 794
789 //////////////////////////////////////////////////////////////////////////////// 795 ////////////////////////////////////////////////////////////////////////////////
790 // RootWindow, RootWindowHostDelegate implementation: 796 // RootWindow, RootWindowHostDelegate implementation:
791 797
792 bool RootWindow::OnHostKeyEvent(KeyEvent* event) { 798 bool RootWindow::OnHostKeyEvent(ui::KeyEvent* event) {
793 DispatchHeldMouseMove(); 799 DispatchHeldMouseMove();
794 if (event->key_code() == ui::VKEY_UNKNOWN) 800 if (event->key_code() == ui::VKEY_UNKNOWN)
795 return false; 801 return false;
796 client::EventClient* client = client::GetEventClient(GetRootWindow()); 802 client::EventClient* client = client::GetEventClient(GetRootWindow());
797 Window* focused_window = focus_manager_->GetFocusedWindow(); 803 Window* focused_window = focus_manager_->GetFocusedWindow();
798 if (client && !client->CanProcessEventsWithinSubtree(focused_window)) { 804 if (client && !client->CanProcessEventsWithinSubtree(focused_window)) {
799 GetFocusManager()->SetFocusedWindow(NULL, NULL); 805 GetFocusManager()->SetFocusedWindow(NULL, NULL);
800 return false; 806 return false;
801 } 807 }
802 return ProcessKeyEvent(focused_window, event); 808 return ProcessKeyEvent(focused_window, event);
803 } 809 }
804 810
805 bool RootWindow::OnHostMouseEvent(MouseEvent* event) { 811 bool RootWindow::OnHostMouseEvent(ui::MouseEvent* event) {
806 if (event->type() == ui::ET_MOUSE_DRAGGED || 812 if (event->type() == ui::ET_MOUSE_DRAGGED ||
807 (event->flags() & ui::EF_IS_SYNTHESIZED)) { 813 (event->flags() & ui::EF_IS_SYNTHESIZED)) {
808 if (mouse_move_hold_count_) { 814 if (mouse_move_hold_count_) {
809 held_mouse_move_.reset(new MouseEvent(*event, NULL, NULL)); 815 Window* null_window = static_cast<Window*>(NULL);
816 held_mouse_move_.reset(
817 new ui::MouseEvent(*event, null_window, null_window));
810 return true; 818 return true;
811 } else { 819 } else {
812 // We may have a held event for a period between the time 820 // We may have a held event for a period between the time
813 // mouse_move_hold_count_ fell to 0 and the DispatchHeldMouseMove 821 // mouse_move_hold_count_ fell to 0 and the DispatchHeldMouseMove
814 // executes. Since we're going to dispatch the new event directly below, 822 // executes. Since we're going to dispatch the new event directly below,
815 // we can reset the old one. 823 // we can reset the old one.
816 held_mouse_move_.reset(); 824 held_mouse_move_.reset();
817 } 825 }
818 } 826 }
819 DispatchHeldMouseMove(); 827 DispatchHeldMouseMove();
820 return DispatchMouseEventImpl(event); 828 return DispatchMouseEventImpl(event);
821 } 829 }
822 830
823 bool RootWindow::OnHostScrollEvent(ScrollEvent* event) { 831 bool RootWindow::OnHostScrollEvent(ui::ScrollEvent* event) {
824 DispatchHeldMouseMove(); 832 DispatchHeldMouseMove();
825 float scale = ui::GetDeviceScaleFactor(layer()); 833 float scale = ui::GetDeviceScaleFactor(layer());
826 ui::Transform transform = layer()->transform(); 834 ui::Transform transform = layer()->transform();
827 transform.ConcatScale(scale, scale); 835 transform.ConcatScale(scale, scale);
828 event->UpdateForRootTransform(transform); 836 event->UpdateForRootTransform(transform);
829 837
830 SetLastMouseLocation(this, event->location()); 838 SetLastMouseLocation(this, event->location());
831 synthesize_mouse_move_ = false; 839 synthesize_mouse_move_ = false;
832 840
833 Window* target = mouse_pressed_handler_ ? 841 Window* target = mouse_pressed_handler_ ?
834 mouse_pressed_handler_ : client::GetCaptureWindow(this); 842 mouse_pressed_handler_ : client::GetCaptureWindow(this);
835 if (!target) 843 if (!target)
836 target = GetEventHandlerForPoint(event->location()); 844 target = GetEventHandlerForPoint(event->location());
837 845
838 if (target && target->delegate()) { 846 if (target && target->delegate()) {
839 int flags = event->flags(); 847 int flags = event->flags();
840 gfx::Point location_in_window = event->location(); 848 gfx::Point location_in_window = event->location();
841 Window::ConvertPointToWindow(this, target, &location_in_window); 849 Window::ConvertPointToTarget(this, target, &location_in_window);
842 if (IsNonClientLocation(target, location_in_window)) 850 if (IsNonClientLocation(target, location_in_window))
843 flags |= ui::EF_IS_NON_CLIENT; 851 flags |= ui::EF_IS_NON_CLIENT;
844 ScrollEvent translated_event(*event, this, target, event->type(), flags); 852 ui::ScrollEvent translated_event(
853 *event, static_cast<Window*>(this), target, event->type(), flags);
845 return ProcessMouseEvent(target, &translated_event); 854 return ProcessMouseEvent(target, &translated_event);
846 } 855 }
847 return false; 856 return false;
848 } 857 }
849 858
850 bool RootWindow::OnHostTouchEvent(TouchEvent* event) { 859 bool RootWindow::OnHostTouchEvent(ui::TouchEventImpl* event) {
851 DispatchHeldMouseMove(); 860 DispatchHeldMouseMove();
852 switch (event->type()) { 861 switch (event->type()) {
853 case ui::ET_TOUCH_PRESSED: 862 case ui::ET_TOUCH_PRESSED:
854 touch_ids_down_ |= (1 << event->touch_id()); 863 touch_ids_down_ |= (1 << event->touch_id());
855 Env::GetInstance()->set_touch_down(touch_ids_down_ != 0); 864 Env::GetInstance()->set_touch_down(touch_ids_down_ != 0);
856 break; 865 break;
857 866
858 // Don't handle ET_TOUCH_CANCELLED since we always get a ET_TOUCH_RELEASED. 867 // Don't handle ET_TOUCH_CANCELLED since we always get a ET_TOUCH_RELEASED.
859 case ui::ET_TOUCH_RELEASED: 868 case ui::ET_TOUCH_RELEASED:
860 touch_ids_down_ = (touch_ids_down_ | (1 << event->touch_id())) ^ 869 touch_ids_down_ = (touch_ids_down_ | (1 << event->touch_id())) ^
(...skipping 24 matching lines...) Expand all
885 // If the initial touch is outside the root window, target the root. 894 // If the initial touch is outside the root window, target the root.
886 target = this; 895 target = this;
887 } else { 896 } else {
888 // We only come here when the first contact was within the root window. 897 // We only come here when the first contact was within the root window.
889 if (!target) { 898 if (!target) {
890 target = GetEventHandlerForPoint(event->location()); 899 target = GetEventHandlerForPoint(event->location());
891 if (!target) 900 if (!target)
892 return false; 901 return false;
893 } 902 }
894 903
895 TouchEvent translated_event(*event, this, target); 904 ui::TouchEventImpl translated_event(
905 *event, static_cast<Window*>(this), target);
896 status = ProcessTouchEvent(target, &translated_event); 906 status = ProcessTouchEvent(target, &translated_event);
897 handled = status != ui::TOUCH_STATUS_UNKNOWN; 907 handled = status != ui::TOUCH_STATUS_UNKNOWN;
898 908
899 if (status == ui::TOUCH_STATUS_QUEUED || 909 if (status == ui::TOUCH_STATUS_QUEUED ||
900 status == ui::TOUCH_STATUS_QUEUED_END) 910 status == ui::TOUCH_STATUS_QUEUED_END)
901 gesture_recognizer_->QueueTouchEventForGesture(target, *event); 911 gesture_recognizer_->QueueTouchEventForGesture(target, *event);
902 } 912 }
903 913
904 // Get the list of GestureEvents from GestureRecognizer. 914 // Get the list of GestureEvents from GestureRecognizer.
905 scoped_ptr<ui::GestureRecognizer::Gestures> gestures; 915 scoped_ptr<ui::GestureRecognizer::Gestures> gestures;
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
939 return compositor()->device_scale_factor(); 949 return compositor()->device_scale_factor();
940 } 950 }
941 951
942 RootWindow* RootWindow::AsRootWindow() { 952 RootWindow* RootWindow::AsRootWindow() {
943 return this; 953 return this;
944 } 954 }
945 955
946 //////////////////////////////////////////////////////////////////////////////// 956 ////////////////////////////////////////////////////////////////////////////////
947 // RootWindow, private: 957 // RootWindow, private:
948 958
949 bool RootWindow::DispatchMouseEventImpl(MouseEvent* event) { 959 bool RootWindow::DispatchMouseEventImpl(ui::MouseEvent* event) {
950 float scale = ui::GetDeviceScaleFactor(layer()); 960 float scale = ui::GetDeviceScaleFactor(layer());
951 ui::Transform transform = layer()->transform(); 961 ui::Transform transform = layer()->transform();
952 transform.ConcatScale(scale, scale); 962 transform.ConcatScale(scale, scale);
953 event->UpdateForRootTransform(transform); 963 event->UpdateForRootTransform(transform);
954 Window* target = mouse_pressed_handler_ ? 964 Window* target = mouse_pressed_handler_ ?
955 mouse_pressed_handler_ : client::GetCaptureWindow(this); 965 mouse_pressed_handler_ : client::GetCaptureWindow(this);
956 if (!target) 966 if (!target)
957 target = GetEventHandlerForPoint(event->location()); 967 target = GetEventHandlerForPoint(event->location());
958 return DispatchMouseEventToTarget(event, target); 968 return DispatchMouseEventToTarget(event, target);
959 } 969 }
960 970
961 bool RootWindow::DispatchMouseEventToTarget(MouseEvent* event, 971 bool RootWindow::DispatchMouseEventToTarget(ui::MouseEvent* event,
962 Window* target) { 972 Window* target) {
963 static const int kMouseButtonFlagMask = 973 static const int kMouseButtonFlagMask =
964 ui::EF_LEFT_MOUSE_BUTTON | 974 ui::EF_LEFT_MOUSE_BUTTON |
965 ui::EF_MIDDLE_MOUSE_BUTTON | 975 ui::EF_MIDDLE_MOUSE_BUTTON |
966 ui::EF_RIGHT_MOUSE_BUTTON; 976 ui::EF_RIGHT_MOUSE_BUTTON;
967 SetLastMouseLocation(this, event->location()); 977 SetLastMouseLocation(this, event->location());
968 synthesize_mouse_move_ = false; 978 synthesize_mouse_move_ = false;
969 switch (event->type()) { 979 switch (event->type()) {
970 case ui::ET_MOUSE_MOVED: 980 case ui::ET_MOUSE_MOVED:
971 HandleMouseMoved(*event, target); 981 HandleMouseMoved(*event, target);
972 break; 982 break;
973 case ui::ET_MOUSE_PRESSED: 983 case ui::ET_MOUSE_PRESSED:
974 if (!mouse_pressed_handler_) 984 if (!mouse_pressed_handler_)
975 mouse_pressed_handler_ = target; 985 mouse_pressed_handler_ = target;
976 mouse_button_flags_ = event->flags() & kMouseButtonFlagMask; 986 mouse_button_flags_ = event->flags() & kMouseButtonFlagMask;
977 Env::GetInstance()->set_mouse_button_flags(mouse_button_flags_); 987 Env::GetInstance()->set_mouse_button_flags(mouse_button_flags_);
978 break; 988 break;
979 case ui::ET_MOUSE_RELEASED: 989 case ui::ET_MOUSE_RELEASED:
980 mouse_pressed_handler_ = NULL; 990 mouse_pressed_handler_ = NULL;
981 mouse_button_flags_ = event->flags() & kMouseButtonFlagMask; 991 mouse_button_flags_ = event->flags() & kMouseButtonFlagMask;
982 Env::GetInstance()->set_mouse_button_flags(mouse_button_flags_); 992 Env::GetInstance()->set_mouse_button_flags(mouse_button_flags_);
983 break; 993 break;
984 default: 994 default:
985 break; 995 break;
986 } 996 }
987 if (target && target->delegate()) { 997 if (target && target->delegate()) {
988 int flags = event->flags(); 998 int flags = event->flags();
989 gfx::Point location_in_window = event->location(); 999 gfx::Point location_in_window = event->location();
990 Window::ConvertPointToWindow(this, target, &location_in_window); 1000 Window::ConvertPointToTarget(this, target, &location_in_window);
991 if (IsNonClientLocation(target, location_in_window)) 1001 if (IsNonClientLocation(target, location_in_window))
992 flags |= ui::EF_IS_NON_CLIENT; 1002 flags |= ui::EF_IS_NON_CLIENT;
993 MouseEvent translated_event(*event, this, target, event->type(), flags); 1003 ui::MouseEvent translated_event(
1004 *event, static_cast<Window*>(this), target, event->type(), flags);
994 return ProcessMouseEvent(target, &translated_event); 1005 return ProcessMouseEvent(target, &translated_event);
995 } 1006 }
996 return false; 1007 return false;
997 } 1008 }
998 1009
999 void RootWindow::DispatchHeldMouseMove() { 1010 void RootWindow::DispatchHeldMouseMove() {
1000 if (held_mouse_move_.get()) { 1011 if (held_mouse_move_.get()) {
1001 // If a mouse move has been synthesized, the target location is suspect, 1012 // If a mouse move has been synthesized, the target location is suspect,
1002 // so drop the held event. 1013 // so drop the held event.
1003 if (!synthesize_mouse_move_) 1014 if (!synthesize_mouse_move_)
(...skipping 20 matching lines...) Expand all
1024 // Temporarily disabled for windows. See crbug.com/112222. 1035 // Temporarily disabled for windows. See crbug.com/112222.
1025 gfx::Point3f point(GetLastMouseLocationInRoot()); 1036 gfx::Point3f point(GetLastMouseLocationInRoot());
1026 ui::Transform transform = layer()->transform(); 1037 ui::Transform transform = layer()->transform();
1027 float scale = ui::GetDeviceScaleFactor(layer()); 1038 float scale = ui::GetDeviceScaleFactor(layer());
1028 transform.ConcatScale(scale, scale); 1039 transform.ConcatScale(scale, scale);
1029 transform.TransformPoint(point); 1040 transform.TransformPoint(point);
1030 gfx::Point orig_mouse_location = point.AsPoint(); 1041 gfx::Point orig_mouse_location = point.AsPoint();
1031 1042
1032 // TODO(derat|oshima): Don't use mouse_button_flags_ as it's 1043 // TODO(derat|oshima): Don't use mouse_button_flags_ as it's
1033 // currently broken. See/ crbug.com/107931. 1044 // currently broken. See/ crbug.com/107931.
1034 MouseEvent event(ui::ET_MOUSE_MOVED, 1045 ui::MouseEvent event(ui::ET_MOUSE_MOVED,
1035 orig_mouse_location, 1046 orig_mouse_location,
1036 orig_mouse_location, 1047 orig_mouse_location,
1037 ui::EF_IS_SYNTHESIZED); 1048 ui::EF_IS_SYNTHESIZED);
1038 OnHostMouseEvent(&event); 1049 OnHostMouseEvent(&event);
1039 #endif 1050 #endif
1040 } 1051 }
1041 1052
1042 void RootWindow::UnlockCompositor() { 1053 void RootWindow::UnlockCompositor() {
1043 DCHECK(compositor_lock_); 1054 DCHECK(compositor_lock_);
1044 compositor_lock_ = NULL; 1055 compositor_lock_ = NULL;
1045 if (draw_on_compositor_unlock_) { 1056 if (draw_on_compositor_unlock_) {
1046 draw_on_compositor_unlock_ = false; 1057 draw_on_compositor_unlock_ = false;
1047 ScheduleDraw(); 1058 ScheduleDraw();
1048 } 1059 }
1049 } 1060 }
1050 1061
1051 } // namespace aura 1062 } // namespace aura
OLDNEW
« no previous file with comments | « ui/aura/root_window.h ('k') | ui/aura/root_window_host_delegate.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698