| 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" |
| 11 #include "base/command_line.h" | 11 #include "base/command_line.h" |
| 12 #include "base/debug/trace_event.h" | 12 #include "base/debug/trace_event.h" |
| 13 #include "base/logging.h" | 13 #include "base/logging.h" |
| 14 #include "base/message_loop.h" | 14 #include "base/message_loop.h" |
| 15 #include "ui/aura/aura_switches.h" | 15 #include "ui/aura/aura_switches.h" |
| 16 #include "ui/aura/client/activation_client.h" | 16 #include "ui/aura/client/activation_client.h" |
| 17 #include "ui/aura/client/capture_client.h" | 17 #include "ui/aura/client/capture_client.h" |
| 18 #include "ui/aura/client/cursor_client.h" | 18 #include "ui/aura/client/cursor_client.h" |
| 19 #include "ui/aura/client/event_client.h" | 19 #include "ui/aura/client/event_client.h" |
| 20 #include "ui/aura/client/focus_client.h" |
| 20 #include "ui/aura/client/screen_position_client.h" | 21 #include "ui/aura/client/screen_position_client.h" |
| 21 #include "ui/aura/env.h" | 22 #include "ui/aura/env.h" |
| 22 #include "ui/aura/focus_manager.h" | |
| 23 #include "ui/aura/root_window_host.h" | 23 #include "ui/aura/root_window_host.h" |
| 24 #include "ui/aura/root_window_observer.h" | 24 #include "ui/aura/root_window_observer.h" |
| 25 #include "ui/aura/window.h" | 25 #include "ui/aura/window.h" |
| 26 #include "ui/aura/window_delegate.h" | 26 #include "ui/aura/window_delegate.h" |
| 27 #include "ui/aura/window_tracker.h" | 27 #include "ui/aura/window_tracker.h" |
| 28 #include "ui/base/events/event.h" | 28 #include "ui/base/events/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/base/view_prop.h" | 32 #include "ui/base/view_prop.h" |
| (...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 96 ALLOW_THIS_IN_INITIALIZER_LIST(host_(CreateHost(this, params))), | 96 ALLOW_THIS_IN_INITIALIZER_LIST(host_(CreateHost(this, params))), |
| 97 ALLOW_THIS_IN_INITIALIZER_LIST(schedule_paint_factory_(this)), | 97 ALLOW_THIS_IN_INITIALIZER_LIST(schedule_paint_factory_(this)), |
| 98 ALLOW_THIS_IN_INITIALIZER_LIST(event_factory_(this)), | 98 ALLOW_THIS_IN_INITIALIZER_LIST(event_factory_(this)), |
| 99 mouse_button_flags_(0), | 99 mouse_button_flags_(0), |
| 100 touch_ids_down_(0), | 100 touch_ids_down_(0), |
| 101 last_cursor_(ui::kCursorNull), | 101 last_cursor_(ui::kCursorNull), |
| 102 mouse_pressed_handler_(NULL), | 102 mouse_pressed_handler_(NULL), |
| 103 mouse_moved_handler_(NULL), | 103 mouse_moved_handler_(NULL), |
| 104 mouse_event_dispatch_target_(NULL), | 104 mouse_event_dispatch_target_(NULL), |
| 105 event_dispatch_target_(NULL), | 105 event_dispatch_target_(NULL), |
| 106 focus_manager_(NULL), | |
| 107 ALLOW_THIS_IN_INITIALIZER_LIST( | 106 ALLOW_THIS_IN_INITIALIZER_LIST( |
| 108 gesture_recognizer_(ui::GestureRecognizer::Create(this))), | 107 gesture_recognizer_(ui::GestureRecognizer::Create(this))), |
| 109 synthesize_mouse_move_(false), | 108 synthesize_mouse_move_(false), |
| 110 waiting_on_compositing_end_(false), | 109 waiting_on_compositing_end_(false), |
| 111 draw_on_compositing_end_(false), | 110 draw_on_compositing_end_(false), |
| 112 defer_draw_scheduling_(false), | 111 defer_draw_scheduling_(false), |
| 113 mouse_move_hold_count_(0), | 112 mouse_move_hold_count_(0), |
| 114 ALLOW_THIS_IN_INITIALIZER_LIST(held_mouse_event_factory_(this)) { | 113 ALLOW_THIS_IN_INITIALIZER_LIST(held_mouse_event_factory_(this)) { |
| 115 SetName("RootWindow"); | 114 SetName("RootWindow"); |
| 116 | 115 |
| (...skipping 404 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 521 // RootWindow, overridden from aura::Window: | 520 // RootWindow, overridden from aura::Window: |
| 522 | 521 |
| 523 bool RootWindow::CanFocus() const { | 522 bool RootWindow::CanFocus() const { |
| 524 return IsVisible(); | 523 return IsVisible(); |
| 525 } | 524 } |
| 526 | 525 |
| 527 bool RootWindow::CanReceiveEvents() const { | 526 bool RootWindow::CanReceiveEvents() const { |
| 528 return IsVisible(); | 527 return IsVisible(); |
| 529 } | 528 } |
| 530 | 529 |
| 531 FocusManager* RootWindow::GetFocusManager() { | |
| 532 return focus_manager_; | |
| 533 } | |
| 534 | |
| 535 //////////////////////////////////////////////////////////////////////////////// | 530 //////////////////////////////////////////////////////////////////////////////// |
| 536 // RootWindow, overridden from aura::client::CaptureDelegate: | 531 // RootWindow, overridden from aura::client::CaptureDelegate: |
| 537 | 532 |
| 538 void RootWindow::UpdateCapture(Window* old_capture, | 533 void RootWindow::UpdateCapture(Window* old_capture, |
| 539 Window* new_capture) { | 534 Window* new_capture) { |
| 540 if (old_capture && old_capture->GetRootWindow() == this && | 535 if (old_capture && old_capture->GetRootWindow() == this && |
| 541 old_capture->delegate()) { | 536 old_capture->delegate()) { |
| 542 // Send a capture changed event with bogus location data. | 537 // Send a capture changed event with bogus location data. |
| 543 ui::MouseEvent event(ui::ET_MOUSE_CAPTURE_CHANGED, gfx::Point(), | 538 ui::MouseEvent event(ui::ET_MOUSE_CAPTURE_CHANGED, gfx::Point(), |
| 544 gfx::Point(), 0); | 539 gfx::Point(), 0); |
| (...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 685 } | 680 } |
| 686 | 681 |
| 687 void RootWindow::OnWindowHidden(Window* invisible, | 682 void RootWindow::OnWindowHidden(Window* invisible, |
| 688 WindowHiddenReason reason, | 683 WindowHiddenReason reason, |
| 689 RootWindow* new_root) { | 684 RootWindow* new_root) { |
| 690 // Update the focused window state if the invisible window contains | 685 // Update the focused window state if the invisible window contains |
| 691 // focused_window. See the comment below, which also applies for focus with | 686 // focused_window. See the comment below, which also applies for focus with |
| 692 // the exception for the case where the focus managers change (otherwise a | 687 // the exception for the case where the focus managers change (otherwise a |
| 693 // focus manager might dereference a deleted root window). | 688 // focus manager might dereference a deleted root window). |
| 694 if (reason != WINDOW_MOVING || | 689 if (reason != WINDOW_MOVING || |
| 695 (new_root->GetFocusManager() != focus_manager_)) { | 690 (client::GetFocusClient(new_root) != client::GetFocusClient(this))) { |
| 696 Window* focused_window = focus_manager_->GetFocusedWindow(); | 691 Window* focused_window = client::GetFocusClient(this)->GetFocusedWindow(); |
| 697 if (invisible->Contains(focused_window)) { | 692 if (invisible->Contains(focused_window)) { |
| 698 Window* focus_to = invisible->transient_parent(); | 693 Window* focus_to = invisible->transient_parent(); |
| 699 if (focus_to) { | 694 if (focus_to) { |
| 700 // Has to be removed from the transient parent before focusing, | 695 // Has to be removed from the transient parent before focusing, |
| 701 // otherwise |window| will be focused again. | 696 // otherwise |window| will be focused again. |
| 702 if (reason == WINDOW_DESTROYED) | 697 if (reason == WINDOW_DESTROYED) |
| 703 focus_to->RemoveTransientChild(invisible); | 698 focus_to->RemoveTransientChild(invisible); |
| 704 } else { | 699 } else { |
| 705 // If the invisible view has no visible transient window, focus to the | 700 // If the invisible view has no visible transient window, focus to the |
| 706 // topmost visible parent window. | 701 // topmost visible parent window. |
| 707 focus_to = invisible->parent(); | 702 focus_to = invisible->parent(); |
| 708 } | 703 } |
| 709 if (focus_to && | 704 if (focus_to && |
| 710 (!focus_to->IsVisible() || | 705 (!focus_to->IsVisible() || |
| 711 !focus_to->CanFocus() || | 706 !focus_to->CanFocus() || |
| 712 (client::GetActivationClient(this) && | 707 (client::GetActivationClient(this) && |
| 713 !client::GetActivationClient(this)->OnWillFocusWindow(focus_to, | 708 !client::GetActivationClient(this)->OnWillFocusWindow(focus_to, |
| 714 NULL)))) { | 709 NULL)))) { |
| 715 focus_to = NULL; | 710 focus_to = NULL; |
| 716 } | 711 } |
| 717 GetFocusManager()->SetFocusedWindow(focus_to, NULL); | 712 client::GetFocusClient(this)->FocusWindow(focus_to, NULL); |
| 718 } | 713 } |
| 719 } | 714 } |
| 720 | 715 |
| 721 // Do not clear the capture, and the dispatch targets if the window is moving | 716 // Do not clear the capture, and the dispatch targets if the window is moving |
| 722 // across root windows, because the target itself is actually still visible | 717 // across root windows, because the target itself is actually still visible |
| 723 // and clearing them stops further event processing, which can cause | 718 // and clearing them stops further event processing, which can cause |
| 724 // unexpected behaviors. See crbug.com/157583 | 719 // unexpected behaviors. See crbug.com/157583 |
| 725 if (reason != WINDOW_MOVING) { | 720 if (reason != WINDOW_MOVING) { |
| 726 Window* capture_window = aura::client::GetCaptureWindow(this); | 721 Window* capture_window = aura::client::GetCaptureWindow(this); |
| 727 // If the ancestor of the capture window is hidden, | 722 // If the ancestor of the capture window is hidden, |
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 786 } | 781 } |
| 787 | 782 |
| 788 //////////////////////////////////////////////////////////////////////////////// | 783 //////////////////////////////////////////////////////////////////////////////// |
| 789 // RootWindow, RootWindowHostDelegate implementation: | 784 // RootWindow, RootWindowHostDelegate implementation: |
| 790 | 785 |
| 791 bool RootWindow::OnHostKeyEvent(ui::KeyEvent* event) { | 786 bool RootWindow::OnHostKeyEvent(ui::KeyEvent* event) { |
| 792 DispatchHeldMouseMove(); | 787 DispatchHeldMouseMove(); |
| 793 if (event->key_code() == ui::VKEY_UNKNOWN) | 788 if (event->key_code() == ui::VKEY_UNKNOWN) |
| 794 return false; | 789 return false; |
| 795 client::EventClient* client = client::GetEventClient(GetRootWindow()); | 790 client::EventClient* client = client::GetEventClient(GetRootWindow()); |
| 796 Window* focused_window = focus_manager_->GetFocusedWindow(); | 791 Window* focused_window = client::GetFocusClient(this)->GetFocusedWindow(); |
| 797 if (client && !client->CanProcessEventsWithinSubtree(focused_window)) { | 792 if (client && !client->CanProcessEventsWithinSubtree(focused_window)) { |
| 798 GetFocusManager()->SetFocusedWindow(NULL, NULL); | 793 client::GetFocusClient(this)->FocusWindow(NULL, NULL); |
| 799 return false; | 794 return false; |
| 800 } | 795 } |
| 801 return ProcessKeyEvent(focused_window, event); | 796 return ProcessKeyEvent(focused_window, event); |
| 802 } | 797 } |
| 803 | 798 |
| 804 bool RootWindow::OnHostMouseEvent(ui::MouseEvent* event) { | 799 bool RootWindow::OnHostMouseEvent(ui::MouseEvent* event) { |
| 805 if (event->type() == ui::ET_MOUSE_DRAGGED || | 800 if (event->type() == ui::ET_MOUSE_DRAGGED || |
| 806 (event->flags() & ui::EF_IS_SYNTHESIZED)) { | 801 (event->flags() & ui::EF_IS_SYNTHESIZED)) { |
| 807 if (mouse_move_hold_count_) { | 802 if (mouse_move_hold_count_) { |
| 808 Window* null_window = static_cast<Window*>(NULL); | 803 Window* null_window = static_cast<Window*>(NULL); |
| (...skipping 236 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1045 ui::MouseEvent event(ui::ET_MOUSE_MOVED, | 1040 ui::MouseEvent event(ui::ET_MOUSE_MOVED, |
| 1046 orig_mouse_location, | 1041 orig_mouse_location, |
| 1047 orig_mouse_location, | 1042 orig_mouse_location, |
| 1048 ui::EF_IS_SYNTHESIZED); | 1043 ui::EF_IS_SYNTHESIZED); |
| 1049 event.set_system_location(Env::GetInstance()->last_mouse_location()); | 1044 event.set_system_location(Env::GetInstance()->last_mouse_location()); |
| 1050 OnHostMouseEvent(&event); | 1045 OnHostMouseEvent(&event); |
| 1051 #endif | 1046 #endif |
| 1052 } | 1047 } |
| 1053 | 1048 |
| 1054 } // namespace aura | 1049 } // namespace aura |
| OLD | NEW |