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