| 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 "ui/aura_shell/root_window_event_filter.h" | 5 #include "ui/aura_shell/root_window_event_filter.h" |
| 6 | 6 |
| 7 #include "ui/aura/event.h" | 7 #include "ui/aura/event.h" |
| 8 #include "ui/aura/focus_manager.h" | 8 #include "ui/aura/focus_manager.h" |
| 9 #include "ui/aura/root_window.h" | 9 #include "ui/aura/root_window.h" |
| 10 #include "ui/aura/window_delegate.h" | 10 #include "ui/aura/window_delegate.h" |
| 11 #include "ui/aura_shell/activation_controller.h" | |
| 12 #include "ui/aura_shell/shell.h" | 11 #include "ui/aura_shell/shell.h" |
| 13 #include "ui/aura_shell/window_util.h" | 12 #include "ui/aura_shell/stacking_controller.h" |
| 14 #include "ui/base/hit_test.h" | 13 #include "ui/base/hit_test.h" |
| 15 | 14 |
| 16 namespace aura_shell { | 15 namespace aura_shell { |
| 17 namespace internal { | 16 namespace internal { |
| 18 | 17 |
| 19 // Returns the default cursor for a window component. | 18 // Returns the default cursor for a window component. |
| 20 gfx::NativeCursor CursorForWindowComponent(int window_component) { | 19 gfx::NativeCursor CursorForWindowComponent(int window_component) { |
| 21 switch (window_component) { | 20 switch (window_component) { |
| 22 case HTBOTTOM: | 21 case HTBOTTOM: |
| 23 return aura::kCursorSouthResize; | 22 return aura::kCursorSouthResize; |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 73 aura::MouseEvent* event) { | 72 aura::MouseEvent* event) { |
| 74 // We must always update the cursor, otherwise the cursor can get stuck if an | 73 // We must always update the cursor, otherwise the cursor can get stuck if an |
| 75 // event filter registered with us consumes the event. | 74 // event filter registered with us consumes the event. |
| 76 if (event->type() == ui::ET_MOUSE_MOVED) | 75 if (event->type() == ui::ET_MOUSE_MOVED) |
| 77 UpdateCursor(target, event); | 76 UpdateCursor(target, event); |
| 78 | 77 |
| 79 if (FilterMouseEvent(target, event)) | 78 if (FilterMouseEvent(target, event)) |
| 80 return true; | 79 return true; |
| 81 | 80 |
| 82 if (event->type() == ui::ET_MOUSE_PRESSED) | 81 if (event->type() == ui::ET_MOUSE_PRESSED) |
| 83 target->GetFocusManager()->SetFocusedWindow(target); | 82 ActivateIfNecessary(target, event); |
| 84 | 83 |
| 85 return false; | 84 return false; |
| 86 } | 85 } |
| 87 | 86 |
| 88 ui::TouchStatus RootWindowEventFilter::PreHandleTouchEvent( | 87 ui::TouchStatus RootWindowEventFilter::PreHandleTouchEvent( |
| 89 aura::Window* target, | 88 aura::Window* target, |
| 90 aura::TouchEvent* event) { | 89 aura::TouchEvent* event) { |
| 91 ui::TouchStatus status = FilterTouchEvent(target, event); | 90 ui::TouchStatus status = FilterTouchEvent(target, event); |
| 92 if (status != ui::TOUCH_STATUS_UNKNOWN) | 91 if (status != ui::TOUCH_STATUS_UNKNOWN) |
| 93 return status; | 92 return status; |
| 94 | 93 |
| 95 if (event->type() == ui::ET_TOUCH_PRESSED) | 94 if (event->type() == ui::ET_TOUCH_PRESSED) |
| 96 target->GetFocusManager()->SetFocusedWindow(target); | 95 ActivateIfNecessary(target, event); |
| 97 return ui::TOUCH_STATUS_UNKNOWN; | 96 return ui::TOUCH_STATUS_UNKNOWN; |
| 98 } | 97 } |
| 99 | 98 |
| 100 //////////////////////////////////////////////////////////////////////////////// | 99 //////////////////////////////////////////////////////////////////////////////// |
| 101 // RootWindowEventFilter, private: | 100 // RootWindowEventFilter, private: |
| 102 | 101 |
| 102 void RootWindowEventFilter::ActivateIfNecessary(aura::Window* window, |
| 103 aura::Event* event) { |
| 104 aura::Window* activatable = StackingController::GetActivatableWindow(window); |
| 105 if (activatable == aura::RootWindow::GetInstance()->active_window()) { |
| 106 // |window| is a descendant of the active window, no need to activate. |
| 107 window->GetFocusManager()->SetFocusedWindow(window); |
| 108 } else { |
| 109 aura::RootWindow::GetInstance()->SetActiveWindow(activatable, window); |
| 110 } |
| 111 } |
| 112 |
| 103 void RootWindowEventFilter::UpdateCursor(aura::Window* target, | 113 void RootWindowEventFilter::UpdateCursor(aura::Window* target, |
| 104 aura::MouseEvent* event) { | 114 aura::MouseEvent* event) { |
| 105 gfx::NativeCursor cursor = target->GetCursor(event->location()); | 115 gfx::NativeCursor cursor = target->GetCursor(event->location()); |
| 106 if (event->flags() & ui::EF_IS_NON_CLIENT) { | 116 if (event->flags() & ui::EF_IS_NON_CLIENT) { |
| 107 int window_component = | 117 int window_component = |
| 108 target->delegate()->GetNonClientComponent(event->location()); | 118 target->delegate()->GetNonClientComponent(event->location()); |
| 109 cursor = CursorForWindowComponent(window_component); | 119 cursor = CursorForWindowComponent(window_component); |
| 110 } | 120 } |
| 111 aura::RootWindow::GetInstance()->SetCursor(cursor); | 121 aura::RootWindow::GetInstance()->SetCursor(cursor); |
| 112 } | 122 } |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 145 while (status == ui::TOUCH_STATUS_UNKNOWN && | 155 while (status == ui::TOUCH_STATUS_UNKNOWN && |
| 146 (filter = it.GetNext()) != NULL) { | 156 (filter = it.GetNext()) != NULL) { |
| 147 status = filter->PreHandleTouchEvent(target, event); | 157 status = filter->PreHandleTouchEvent(target, event); |
| 148 } | 158 } |
| 149 } | 159 } |
| 150 return status; | 160 return status; |
| 151 } | 161 } |
| 152 | 162 |
| 153 } // namespace internal | 163 } // namespace internal |
| 154 } // namespace aura_shell | 164 } // namespace aura_shell |
| OLD | NEW |