| 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 "ash/wm/toplevel_window_event_handler.h" | 5 #include "ash/wm/toplevel_window_event_handler.h" |
| 6 | 6 |
| 7 #include "ash/aura/wm_window_aura.h" |
| 7 #include "ash/shell.h" | 8 #include "ash/shell.h" |
| 8 #include "ash/wm/aura/wm_window_aura.h" | |
| 9 #include "base/message_loop/message_loop.h" | 9 #include "base/message_loop/message_loop.h" |
| 10 #include "base/run_loop.h" | 10 #include "base/run_loop.h" |
| 11 #include "ui/aura/client/cursor_client.h" | 11 #include "ui/aura/client/cursor_client.h" |
| 12 #include "ui/aura/env.h" | 12 #include "ui/aura/env.h" |
| 13 #include "ui/aura/window.h" | 13 #include "ui/aura/window.h" |
| 14 #include "ui/aura/window_event_dispatcher.h" | 14 #include "ui/aura/window_event_dispatcher.h" |
| 15 #include "ui/aura/window_tree_host.h" | 15 #include "ui/aura/window_tree_host.h" |
| 16 #include "ui/base/cursor/cursor.h" | 16 #include "ui/base/cursor/cursor.h" |
| 17 #include "ui/base/hit_test.h" | 17 #include "ui/base/hit_test.h" |
| 18 #include "ui/events/event.h" | 18 #include "ui/events/event.h" |
| 19 #include "ui/events/event_utils.h" | 19 #include "ui/events/event_utils.h" |
| 20 #include "ui/events/gestures/gesture_recognizer.h" | 20 #include "ui/events/gestures/gesture_recognizer.h" |
| 21 | 21 |
| 22 namespace ash { | 22 namespace ash { |
| 23 | 23 |
| 24 ToplevelWindowEventHandler::ToplevelWindowEventHandler(wm::WmGlobals* globals) | 24 ToplevelWindowEventHandler::ToplevelWindowEventHandler(WmShell* shell) |
| 25 : wm_toplevel_window_event_handler_(globals), weak_factory_(this) {} | 25 : wm_toplevel_window_event_handler_(shell), weak_factory_(this) {} |
| 26 | 26 |
| 27 ToplevelWindowEventHandler::~ToplevelWindowEventHandler() {} | 27 ToplevelWindowEventHandler::~ToplevelWindowEventHandler() {} |
| 28 | 28 |
| 29 void ToplevelWindowEventHandler::OnKeyEvent(ui::KeyEvent* event) { | 29 void ToplevelWindowEventHandler::OnKeyEvent(ui::KeyEvent* event) { |
| 30 wm_toplevel_window_event_handler_.OnKeyEvent(event); | 30 wm_toplevel_window_event_handler_.OnKeyEvent(event); |
| 31 } | 31 } |
| 32 | 32 |
| 33 void ToplevelWindowEventHandler::OnMouseEvent(ui::MouseEvent* event) { | 33 void ToplevelWindowEventHandler::OnMouseEvent(ui::MouseEvent* event) { |
| 34 aura::Window* target = static_cast<aura::Window*>(event->target()); | 34 aura::Window* target = static_cast<aura::Window*>(event->target()); |
| 35 wm_toplevel_window_event_handler_.OnMouseEvent(event, | 35 wm_toplevel_window_event_handler_.OnMouseEvent(event, |
| 36 wm::WmWindowAura::Get(target)); | 36 WmWindowAura::Get(target)); |
| 37 } | 37 } |
| 38 | 38 |
| 39 void ToplevelWindowEventHandler::OnGestureEvent(ui::GestureEvent* event) { | 39 void ToplevelWindowEventHandler::OnGestureEvent(ui::GestureEvent* event) { |
| 40 aura::Window* target = static_cast<aura::Window*>(event->target()); | 40 aura::Window* target = static_cast<aura::Window*>(event->target()); |
| 41 wm_toplevel_window_event_handler_.OnGestureEvent( | 41 wm_toplevel_window_event_handler_.OnGestureEvent(event, |
| 42 event, wm::WmWindowAura::Get(target)); | 42 WmWindowAura::Get(target)); |
| 43 } | 43 } |
| 44 | 44 |
| 45 aura::client::WindowMoveResult ToplevelWindowEventHandler::RunMoveLoop( | 45 aura::client::WindowMoveResult ToplevelWindowEventHandler::RunMoveLoop( |
| 46 aura::Window* source, | 46 aura::Window* source, |
| 47 const gfx::Vector2d& drag_offset, | 47 const gfx::Vector2d& drag_offset, |
| 48 aura::client::WindowMoveSource move_source) { | 48 aura::client::WindowMoveSource move_source) { |
| 49 DCHECK(!in_move_loop_); // Can only handle one nested loop at a time. | 49 DCHECK(!in_move_loop_); // Can only handle one nested loop at a time. |
| 50 aura::Window* root_window = source->GetRootWindow(); | 50 aura::Window* root_window = source->GetRootWindow(); |
| 51 DCHECK(root_window); | 51 DCHECK(root_window); |
| 52 gfx::Point drag_location; | 52 gfx::Point drag_location; |
| (...skipping 15 matching lines...) Expand all Loading... |
| 68 aura::client::CursorClient* cursor_client = | 68 aura::client::CursorClient* cursor_client = |
| 69 aura::client::GetCursorClient(root_window); | 69 aura::client::GetCursorClient(root_window); |
| 70 if (cursor_client) | 70 if (cursor_client) |
| 71 cursor_client->SetCursor(ui::kCursorPointer); | 71 cursor_client->SetCursor(ui::kCursorPointer); |
| 72 | 72 |
| 73 base::RunLoop run_loop; | 73 base::RunLoop run_loop; |
| 74 | 74 |
| 75 wm::WmToplevelWindowEventHandler::DragResult result = | 75 wm::WmToplevelWindowEventHandler::DragResult result = |
| 76 wm::WmToplevelWindowEventHandler::DragResult::SUCCESS; | 76 wm::WmToplevelWindowEventHandler::DragResult::SUCCESS; |
| 77 if (!wm_toplevel_window_event_handler_.AttemptToStartDrag( | 77 if (!wm_toplevel_window_event_handler_.AttemptToStartDrag( |
| 78 wm::WmWindowAura::Get(source), drag_location, HTCAPTION, move_source, | 78 WmWindowAura::Get(source), drag_location, HTCAPTION, move_source, |
| 79 base::Bind(&ToplevelWindowEventHandler::OnDragCompleted, | 79 base::Bind(&ToplevelWindowEventHandler::OnDragCompleted, |
| 80 weak_factory_.GetWeakPtr(), &result, &run_loop))) { | 80 weak_factory_.GetWeakPtr(), &result, &run_loop))) { |
| 81 return aura::client::MOVE_CANCELED; | 81 return aura::client::MOVE_CANCELED; |
| 82 } | 82 } |
| 83 | 83 |
| 84 in_move_loop_ = true; | 84 in_move_loop_ = true; |
| 85 base::WeakPtr<ToplevelWindowEventHandler> weak_ptr( | 85 base::WeakPtr<ToplevelWindowEventHandler> weak_ptr( |
| 86 weak_factory_.GetWeakPtr()); | 86 weak_factory_.GetWeakPtr()); |
| 87 base::MessageLoop* loop = base::MessageLoop::current(); | 87 base::MessageLoop* loop = base::MessageLoop::current(); |
| 88 base::MessageLoop::ScopedNestableTaskAllower allow_nested(loop); | 88 base::MessageLoop::ScopedNestableTaskAllower allow_nested(loop); |
| (...skipping 16 matching lines...) Expand all Loading... |
| 105 | 105 |
| 106 void ToplevelWindowEventHandler::OnDragCompleted( | 106 void ToplevelWindowEventHandler::OnDragCompleted( |
| 107 wm::WmToplevelWindowEventHandler::DragResult* result_return_value, | 107 wm::WmToplevelWindowEventHandler::DragResult* result_return_value, |
| 108 base::RunLoop* run_loop, | 108 base::RunLoop* run_loop, |
| 109 wm::WmToplevelWindowEventHandler::DragResult result) { | 109 wm::WmToplevelWindowEventHandler::DragResult result) { |
| 110 *result_return_value = result; | 110 *result_return_value = result; |
| 111 run_loop->Quit(); | 111 run_loop->Quit(); |
| 112 } | 112 } |
| 113 | 113 |
| 114 } // namespace ash | 114 } // namespace ash |
| OLD | NEW |