1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "ui/wm/core/nested_accelerator_controller.h"
7 #include "base/auto_reset.h"
9 #include "base/run_loop.h"
10 #include "ui/wm/core/nested_accelerator_delegate.h"
11 #include "ui/wm/core/nested_accelerator_dispatcher.h"
15 NestedAcceleratorController::NestedAcceleratorController(
16 NestedAcceleratorDelegate
* delegate
)
17 : dispatcher_delegate_(delegate
) {
21 NestedAcceleratorController::~NestedAcceleratorController() {
24 void NestedAcceleratorController::PrepareNestedLoopClosures(
25 base::MessagePumpDispatcher
* nested_dispatcher
,
26 base::Closure
* run_closure
,
27 base::Closure
* quit_closure
) {
28 scoped_ptr
<NestedAcceleratorDispatcher
> old_accelerator_dispatcher
=
29 accelerator_dispatcher_
.Pass();
30 accelerator_dispatcher_
= NestedAcceleratorDispatcher::Create(
31 dispatcher_delegate_
.get(), nested_dispatcher
);
33 scoped_ptr
<base::RunLoop
> run_loop
= accelerator_dispatcher_
->CreateRunLoop();
35 base::Bind(&NestedAcceleratorController::QuitNestedMessageLoop
,
36 base::Unretained(this),
37 run_loop
->QuitClosure());
38 *run_closure
= base::Bind(&NestedAcceleratorController::RunNestedMessageLoop
,
39 base::Unretained(this),
40 base::Passed(&run_loop
),
41 base::Passed(&old_accelerator_dispatcher
));
44 void NestedAcceleratorController::RunNestedMessageLoop(
45 scoped_ptr
<base::RunLoop
> run_loop
,
46 scoped_ptr
<NestedAcceleratorDispatcher
> old_accelerator_dispatcher
) {
48 accelerator_dispatcher_
= old_accelerator_dispatcher
.Pass();
51 void NestedAcceleratorController::QuitNestedMessageLoop(
52 const base::Closure
& quit_runloop
) {
54 accelerator_dispatcher_
.reset();