Commit 165de394 authored by mmenke@chromium.org's avatar mmenke@chromium.org

Revert 272740 "Refactor and move ash independent accelerator han..."

Causing compile failures on Windows.  Possible comatability issue
with https://codereview.chromium.org/298703007

Sample errors:

FAILED: ninja -t msvc -e environment.x86 -- C:\b\build\goma/gomacc "C:\b\depot_tools\win_toolchain\vs2013_files\VC\bin\amd64_x86\cl.exe" /nologo /showIncludes /FC @obj\ui\wm\core\wm_unittests.nested_accelerator_controller_unittest.obj.rsp /c ..\..\ui\wm\core\nested_accelerator_controller_unittest.cc /Foobj\ui\wm\core\wm_unittests.nested_accelerator_controller_unittest.obj /Fdobj\ui\wm\wm_unittests.cc.pdb 
c:\b\build\slave\win\build\src\ui\wm\core\nested_accelerator_controller_unittest.cc(83) : error C2039: 'host' : is not a member of 'aura::Window'
        c:\b\build\slave\win\build\src\ui\aura\window.h(62) : see declaration of 'aura::Window'
c:\b\build\slave\win\build\src\ui\wm\core\nested_accelerator_controller_unittest.cc(83) : error C2227: left of '->PostNativeEvent' must point to class/struct/union/generic type
c:\b\build\slave\win\build\src\ui\wm\core\nested_accelerator_controller_unittest.cc(85) : error C2039: 'host' : is not a member of 'aura::Window'
        c:\b\build\slave\win\build\src\ui\aura\window.h(62) : see declaration of 'aura::Window'
c:\b\build\slave\win\build\src\ui\wm\core\nested_accelerator_controller_unittest.cc(85) : error C2227: left of '->PostNativeEvent' must point to class/struct/union/generic type
ninja: build stopped: subcommand failed.


> Refactor and move ash independent accelerator handling code in nested loop to ui/wm/core
> 
> I also renamed classes to NestedAcceleratorXxx. I felt this is a bit more clearer than NestedDispatcher, especially in ui/wm/core. Please let me know if you disagree or have better suggestion. I'm happy to rename them.
> 
> BUG=None
> 
> Review URL: https://codereview.chromium.org/298703007

TBR=oshima@chromium.org

Review URL: https://codereview.chromium.org/300093002

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@272759 0039d316-1c4b-4281-b951-d872f2087c98
parent 7dca93ea
// Copyright 2014 The Chromium Authors. All rights reserved.
// Copyright (c) 2012 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "ash/accelerators/nested_accelerator_delegate.h"
#include "ash/accelerators/accelerator_dispatcher.h"
#include "ash/accelerators/accelerator_controller.h"
#include "ash/shell.h"
......@@ -35,28 +35,21 @@ bool IsPossibleAcceleratorNotForMenu(const ui::KeyEvent& key_event) {
} // namespace
NestedAcceleratorDelegate::NestedAcceleratorDelegate() {
LOG(ERROR) << "NAD";
}
NestedAcceleratorDelegate::~NestedAcceleratorDelegate() {
LOG(ERROR) << "~NAD";
}
bool NestedAcceleratorDelegate::ShouldProcessEventNow(
bool AcceleratorDispatcher::MenuClosedForPossibleAccelerator(
const ui::KeyEvent& key_event) {
if (!IsPossibleAcceleratorNotForMenu(key_event))
return true;
return false;
if (views::MenuController* menu_controller =
views::MenuController::GetActiveInstance()) {
menu_controller->CancelAll();
return false;
return true;
}
return true;
return false;
}
bool NestedAcceleratorDelegate::ProcessEvent(const ui::KeyEvent& key_event) {
bool AcceleratorDispatcher::AcceleratorProcessedForKeyEvent(
const ui::KeyEvent& key_event) {
ash::AcceleratorController* accelerator_controller =
ash::Shell::GetInstance()->accelerator_controller();
if (!accelerator_controller)
......
// Copyright 2014 The Chromium Authors. All rights reserved.
// Copyright (c) 2012 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef UI_WM_CORE_NESTED_ACCELERATOR_DISPATCHER_H_
#define UI_WM_CORE_NESTED_ACCELERATOR_DISPATCHER_H_
#ifndef ASH_ACCELERATORS_ACCELERATOR_DISPATCHER_H_
#define ASH_ACCELERATORS_ACCELERATOR_DISPATCHER_H_
#include "ash/ash_export.h"
#include "base/macros.h"
#include "base/memory/scoped_ptr.h"
#include "ui/wm/wm_export.h"
namespace base {
class MessagePumpDispatcher;
......@@ -18,9 +18,7 @@ namespace ui {
class KeyEvent;
}
namespace wm {
class NestedAcceleratorDelegate;
namespace ash {
// Dispatcher for handling accelerators from menu.
//
......@@ -29,27 +27,32 @@ class NestedAcceleratorDelegate;
// passed back to the default dispatcher.
// TODO(pkotwicz): Add support for a |nested_dispatcher| which sends
// events to a system IME.
class WM_EXPORT NestedAcceleratorDispatcher {
class ASH_EXPORT AcceleratorDispatcher {
public:
virtual ~NestedAcceleratorDispatcher();
virtual ~AcceleratorDispatcher() {}
static scoped_ptr<NestedAcceleratorDispatcher> Create(
NestedAcceleratorDelegate* dispatcher_delegate,
static scoped_ptr<AcceleratorDispatcher> Create(
base::MessagePumpDispatcher* nested_dispatcher);
// Creates a base::RunLoop object to run a nested message loop.
virtual scoped_ptr<base::RunLoop> CreateRunLoop() = 0;
protected:
explicit NestedAcceleratorDispatcher(NestedAcceleratorDelegate* delegate);
AcceleratorDispatcher() {}
// Closes any open menu if the key-event could potentially be a system
// accelerator.
// Returns whether a menu was closed.
bool MenuClosedForPossibleAccelerator(const ui::KeyEvent& key_event);
NestedAcceleratorDelegate*
delegate_; // Owned by NestedAcceleratorController.
// Attempts to trigger an accelerator for the key-event.
// Returns whether an accelerator was triggered.
bool AcceleratorProcessedForKeyEvent(const ui::KeyEvent& key_event);
private:
DISALLOW_COPY_AND_ASSIGN(NestedAcceleratorDispatcher);
DISALLOW_COPY_AND_ASSIGN(AcceleratorDispatcher);
};
} // namespace wm
} // namespace ash
#endif // UI_WM_CORE_NESTED_ACCELERATOR_DISPATCHER_H_
#endif // ASH_ACCELERATORS_ACCELERATOR_DISPATCHER_H_
......@@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "ui/wm/core/nested_accelerator_dispatcher.h"
#include "ash/accelerators/accelerator_dispatcher.h"
#include "base/memory/scoped_ptr.h"
#include "base/run_loop.h"
......@@ -10,13 +10,12 @@
#include "ui/events/platform/platform_event_dispatcher.h"
#include "ui/events/platform/platform_event_source.h"
#include "ui/events/platform/scoped_event_dispatcher.h"
#include "ui/wm/core/nested_accelerator_delegate.h"
#if defined(USE_X11)
#include <X11/Xlib.h>
#endif
namespace wm {
namespace ash {
namespace {
......@@ -42,14 +41,13 @@ scoped_ptr<ui::ScopedEventDispatcher> OverrideDispatcher(
} // namespace
class NestedAcceleratorDispatcherLinux : public NestedAcceleratorDispatcher,
public ui::PlatformEventDispatcher {
class AcceleratorDispatcherLinux : public AcceleratorDispatcher,
public ui::PlatformEventDispatcher {
public:
explicit NestedAcceleratorDispatcherLinux(NestedAcceleratorDelegate* delegate)
: NestedAcceleratorDispatcher(delegate),
restore_dispatcher_(OverrideDispatcher(this)) {}
AcceleratorDispatcherLinux()
: restore_dispatcher_(OverrideDispatcher(this)) {}
virtual ~NestedAcceleratorDispatcherLinux() {}
virtual ~AcceleratorDispatcherLinux() {}
private:
// AcceleratorDispatcher:
......@@ -65,7 +63,7 @@ class NestedAcceleratorDispatcherLinux : public NestedAcceleratorDispatcher,
virtual uint32_t DispatchEvent(const ui::PlatformEvent& event) OVERRIDE {
if (IsKeyEvent(event)) {
ui::KeyEvent key_event(event, false);
if (!delegate_->ShouldProcessEventNow(key_event)) {
if (MenuClosedForPossibleAccelerator(key_event)) {
#if defined(USE_X11)
XPutBackEvent(event->xany.display, event);
#else
......@@ -74,25 +72,23 @@ class NestedAcceleratorDispatcherLinux : public NestedAcceleratorDispatcher,
return ui::POST_DISPATCH_NONE;
}
if (delegate_->ProcessEvent(key_event))
if (AcceleratorProcessedForKeyEvent(key_event))
return ui::POST_DISPATCH_NONE;
}
ui::PlatformEventDispatcher* prev = *restore_dispatcher_;
ui::PlatformEventDispatcher* prev = *restore_dispatcher_;
return prev ? prev->DispatchEvent(event)
: ui::POST_DISPATCH_PERFORM_DEFAULT;
}
scoped_ptr<ui::ScopedEventDispatcher> restore_dispatcher_;
DISALLOW_COPY_AND_ASSIGN(NestedAcceleratorDispatcherLinux);
DISALLOW_COPY_AND_ASSIGN(AcceleratorDispatcherLinux);
};
scoped_ptr<NestedAcceleratorDispatcher> NestedAcceleratorDispatcher::Create(
NestedAcceleratorDelegate* delegate,
scoped_ptr<AcceleratorDispatcher> AcceleratorDispatcher::Create(
base::MessagePumpDispatcher* nested_dispatcher) {
return scoped_ptr<NestedAcceleratorDispatcher>(
new NestedAcceleratorDispatcherLinux(delegate));
return scoped_ptr<AcceleratorDispatcher>(new AcceleratorDispatcherLinux());
}
} // namespace wm
} // namespace ash
......@@ -2,17 +2,16 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "ui/wm/core/nested_accelerator_dispatcher.h"
#include "ash/accelerators/accelerator_dispatcher.h"
#include "base/memory/scoped_ptr.h"
#include "base/message_loop/message_pump_dispatcher.h"
#include "base/run_loop.h"
#include "ui/events/event.h"
#include "ui/wm/core/nested_accelerator_delegate.h"
using base::MessagePumpDispatcher;
namespace wm {
namespace ash {
namespace {
......@@ -23,16 +22,15 @@ bool IsKeyEvent(const MSG& msg) {
} // namespace
class NestedAcceleratorDispatcherWin : public NestedAcceleratorDispatcher,
public MessagePumpDispatcher {
class AcceleratorDispatcherWin : public AcceleratorDispatcher,
public MessagePumpDispatcher {
public:
NestedAcceleratorDispatcherWin(NestedAcceleratorDelegate* delegate,
MessagePumpDispatcher* nested)
: NestedAcceleratorDispatcher(delegate), nested_dispatcher_(nested) {}
virtual ~NestedAcceleratorDispatcherWin() {}
explicit AcceleratorDispatcherWin(MessagePumpDispatcher* nested)
: nested_dispatcher_(nested) {}
virtual ~AcceleratorDispatcherWin() {}
private:
// NestedAcceleratorDispatcher:
// AcceleratorDispatcher:
virtual scoped_ptr<base::RunLoop> CreateRunLoop() OVERRIDE {
return scoped_ptr<base::RunLoop>(new base::RunLoop(this));
}
......@@ -41,10 +39,10 @@ class NestedAcceleratorDispatcherWin : public NestedAcceleratorDispatcher,
virtual uint32_t Dispatch(const MSG& event) OVERRIDE {
if (IsKeyEvent(event)) {
ui::KeyEvent key_event(event, false);
if (!delegate_->ShouldProcessEventNow(key_event))
if (MenuClosedForPossibleAccelerator(key_event))
return POST_DISPATCH_QUIT_LOOP;
if (delegate_->ProcessEvent(key_event))
if (AcceleratorProcessedForKeyEvent(key_event))
return POST_DISPATCH_NONE;
}
......@@ -54,14 +52,13 @@ class NestedAcceleratorDispatcherWin : public NestedAcceleratorDispatcher,
MessagePumpDispatcher* nested_dispatcher_;
DISALLOW_COPY_AND_ASSIGN(NestedAcceleratorDispatcherWin);
DISALLOW_COPY_AND_ASSIGN(AcceleratorDispatcherWin);
};
scoped_ptr<NestedAcceleratorDispatcher> NestedAcceleratorDispatcher::Create(
NestedAcceleratorDelegate* delegate,
scoped_ptr<AcceleratorDispatcher> AcceleratorDispatcher::Create(
MessagePumpDispatcher* nested_dispatcher) {
return scoped_ptr<NestedAcceleratorDispatcher>(
new NestedAcceleratorDispatcherWin(delegate, nested_dispatcher));
return scoped_ptr<AcceleratorDispatcher>(
new AcceleratorDispatcherWin(nested_dispatcher));
}
} // namespace wm
} // namespace ash
// Copyright 2014 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef ASH_ACCELERATORS_NESTED_ACCELERATOR_DELEGATE_H_
#define ASH_ACCELERATORS_NESTED_ACCELERATOR_DELEGATE_H_
#include "base/macros.h"
#include "ui/wm/core/nested_accelerator_delegate.h"
namespace ash {
class NestedAcceleratorDelegate : public wm::NestedAcceleratorDelegate {
public:
NestedAcceleratorDelegate();
virtual ~NestedAcceleratorDelegate();
// wm::AcceleratorDispatcher::Delegate
virtual bool ShouldProcessEventNow(const ui::KeyEvent& key_event) OVERRIDE;
virtual bool ProcessEvent(const ui::KeyEvent& key_event) OVERRIDE;
private:
DISALLOW_COPY_AND_ASSIGN(NestedAcceleratorDelegate);
};
} // namespace
#endif // ASH_ACCELERATORS_NESTED_ACCELERATOR_DELEGATE_H_
// Copyright 2014 The Chromium Authors. All rights reserved.
// Copyright (c) 2012 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "ui/wm/core/nested_accelerator_controller.h"
#include "ash/accelerators/nested_dispatcher_controller.h"
#include "ash/accelerators/accelerator_dispatcher.h"
#include "ash/shell.h"
#include "base/auto_reset.h"
#include "base/run_loop.h"
#include "ui/wm/core/nested_accelerator_delegate.h"
#include "ui/wm/core/nested_accelerator_dispatcher.h"
namespace wm {
namespace ash {
NestedAcceleratorController::NestedAcceleratorController(
NestedAcceleratorDelegate* delegate)
: dispatcher_delegate_(delegate) {
DCHECK(delegate);
NestedDispatcherController::NestedDispatcherController() {
}
NestedAcceleratorController::~NestedAcceleratorController() {
NestedDispatcherController::~NestedDispatcherController() {
}
void NestedAcceleratorController::RunWithDispatcher(
void NestedDispatcherController::RunWithDispatcher(
base::MessagePumpDispatcher* nested_dispatcher) {
base::MessageLoopForUI* loop = base::MessageLoopForUI::current();
base::MessageLoopForUI::ScopedNestableTaskAllower allow_nested(loop);
scoped_ptr<NestedAcceleratorDispatcher> old_accelerator_dispatcher =
scoped_ptr<AcceleratorDispatcher> old_accelerator_dispatcher =
accelerator_dispatcher_.Pass();
accelerator_dispatcher_ = NestedAcceleratorDispatcher::Create(
dispatcher_delegate_.get(), nested_dispatcher);
accelerator_dispatcher_ = AcceleratorDispatcher::Create(nested_dispatcher);
// TODO(jbates) crbug.com/134753 Find quitters of this RunLoop and have them
// use run_loop.QuitClosure().
......@@ -39,10 +35,10 @@ void NestedAcceleratorController::RunWithDispatcher(
accelerator_dispatcher_ = old_accelerator_dispatcher.Pass();
}
void NestedAcceleratorController::QuitNestedMessageLoop() {
void NestedDispatcherController::QuitNestedMessageLoop() {
CHECK(!quit_closure_.is_null());
quit_closure_.Run();
accelerator_dispatcher_.reset();
}
} // namespace wm
} // namespace ash
// Copyright 2014 The Chromium Authors. All rights reserved.
// Copyright (c) 2012 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef UI_WM_CORE_NESTED_ACCELERATOR_CONTROLLER_H_
#define UI_WM_CORE_NESTED_ACCELERATOR_CONTROLLER_H_
#ifndef ASH_ACCELERATORS_NESTED_DISPATCHER_CONTROLLER_H_
#define ASH_ACCELERATORS_NESTED_DISPATCHER_CONTROLLER_H_
#include "ash/ash_export.h"
#include "base/callback.h"
#include "base/message_loop/message_loop.h"
#include "ui/wm/public/dispatcher_client.h"
#include "ui/wm/wm_export.h"
namespace wm {
namespace ash {
class NestedAcceleratorDelegate;
class NestedAcceleratorDispatcher;
class AcceleratorDispatcher;
// Creates a dispatcher which wraps another dispatcher.
// The outer dispatcher runs first and performs ash specific handling.
// If it does not consume the event it forwards the event to the nested
// dispatcher.
class WM_EXPORT NestedAcceleratorController
class ASH_EXPORT NestedDispatcherController
: public aura::client::DispatcherClient {
public:
explicit NestedAcceleratorController(NestedAcceleratorDelegate* delegate);
virtual ~NestedAcceleratorController();
NestedDispatcherController();
virtual ~NestedDispatcherController();
// aura::client::DispatcherClient:
virtual void RunWithDispatcher(
......@@ -32,12 +31,11 @@ class WM_EXPORT NestedAcceleratorController
private:
base::Closure quit_closure_;
scoped_ptr<NestedAcceleratorDispatcher> accelerator_dispatcher_;
scoped_ptr<NestedAcceleratorDelegate> dispatcher_delegate_;
scoped_ptr<AcceleratorDispatcher> accelerator_dispatcher_;
DISALLOW_COPY_AND_ASSIGN(NestedAcceleratorController);
DISALLOW_COPY_AND_ASSIGN(NestedDispatcherController);
};
} // namespace wm
} // namespace ash
#endif // UI_WM_CORE_NESTED_ACCELERATOR_CONTROLLER_H_
#endif // ASH_ACCELERATORS_NESTED_DISPATCHER_CONTROLLER_H_
// Copyright 2014 The Chromium Authors. All rights reserved.
// Copyright (c) 2012 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "ui/wm/core/nested_accelerator_controller.h"
#include "ash/accelerators/accelerator_controller.h"
#include "ash/session/session_state_delegate.h"
#include "ash/shell.h"
#include "ash/shell_window_ids.h"
#include "ash/test/ash_test_base.h"
#include "base/bind.h"
#include "base/event_types.h"
#include "base/message_loop/message_loop.h"
#include "ui/aura/test/aura_test_base.h"
#include "ui/aura/test/test_windows.h"
#include "ui/aura/window.h"
#include "ui/aura/window_event_dispatcher.h"
#include "ui/base/accelerators/accelerator.h"
#include "ui/base/accelerators/accelerator.h"
#include "ui/base/accelerators/accelerator_manager.h"
#include "ui/events/event_constants.h"
#include "ui/events/event_utils.h"
#include "ui/events/platform/platform_event_dispatcher.h"
#include "ui/events/platform/platform_event_source.h"
#include "ui/events/platform/scoped_event_dispatcher.h"
#include "ui/wm/core/nested_accelerator_delegate.h"
#include "ui/wm/public/dispatcher_client.h"
#if defined(USE_X11)
......@@ -27,14 +26,15 @@
#include "ui/events/test/events_test_utils_x11.h"
#endif // USE_X11
namespace wm {
namespace ash {
namespace test {
namespace {
class MockDispatcher : public ui::PlatformEventDispatcher {
public:
MockDispatcher() : num_key_events_dispatched_(0) {}
MockDispatcher() : num_key_events_dispatched_(0) {
}
int num_key_events_dispatched() { return num_key_events_dispatched_; }
......@@ -56,17 +56,23 @@ class MockDispatcher : public ui::PlatformEventDispatcher {
class TestTarget : public ui::AcceleratorTarget {
public:
TestTarget() : accelerator_pressed_count_(0) {}
virtual ~TestTarget() {}
TestTarget() : accelerator_pressed_count_(0) {
}
virtual ~TestTarget() {
}
int accelerator_pressed_count() const { return accelerator_pressed_count_; }
int accelerator_pressed_count() const {
return accelerator_pressed_count_;
}
// Overridden from ui::AcceleratorTarget:
virtual bool AcceleratorPressed(const ui::Accelerator& accelerator) OVERRIDE {
accelerator_pressed_count_++;
return true;
}
virtual bool CanHandleAccelerators() const OVERRIDE { return true; }
virtual bool CanHandleAccelerators() const OVERRIDE {
return true;
}
private:
int accelerator_pressed_count_;
......@@ -74,128 +80,72 @@ class TestTarget : public ui::AcceleratorTarget {
DISALLOW_COPY_AND_ASSIGN(TestTarget);
};
void DispatchKeyReleaseA(aura::Window* root_window) {
// Sending both keydown and keyup is necessary here because the accelerator
// manager only checks a keyup event following a keydown event. See
// ShouldHandle() in ui/base/accelerators/accelerator_manager.cc for details.
void DispatchKeyReleaseA() {
// Sending both keydown and keyup is necessary here because the accelerator
// manager only checks a keyup event following a keydown event. See
// ShouldHandle() in ui/base/accelerators/accelerator_manager.cc for details.
#if defined(OS_WIN)
MSG native_event_down = {NULL, WM_KEYDOWN, ui::VKEY_A, 0};
root_window->host()->PostNativeEvent(native_event_down);
MSG native_event_up = {NULL, WM_KEYUP, ui::VKEY_A, 0};
root_window->host()->PostNativeEvent(native_event_up);
MSG native_event_down = { NULL, WM_KEYDOWN, ui::VKEY_A, 0 };
ash::Shell::GetPrimaryRootWindow()->host()->PostNativeEvent(
native_event_down);
MSG native_event_up = { NULL, WM_KEYUP, ui::VKEY_A, 0 };
ash::Shell::GetPrimaryRootWindow()->host()->PostNativeEvent(native_event_up);
#elif defined(USE_X11)
ui::ScopedXI2Event native_event;
native_event.InitKeyEvent(ui::ET_KEY_PRESSED, ui::VKEY_A, 0);
aura::WindowTreeHost* host = root_window->GetHost();
aura::WindowTreeHost* host = ash::Shell::GetPrimaryRootWindow()->GetHost();
host->PostNativeEvent(native_event);
native_event.InitKeyEvent(ui::ET_KEY_RELEASED, ui::VKEY_A, 0);
host->PostNativeEvent(native_event);
#endif
// Make sure the inner message-loop terminates after dispatching the events.
base::MessageLoop::current()->PostTask(
FROM_HERE, base::MessageLoop::current()->QuitClosure());
base::MessageLoop::current()->PostTask(FROM_HERE,
base::MessageLoop::current()->QuitClosure());
}
class MockNestedAcceleratorDelegate : public NestedAcceleratorDelegate {
public:
MockNestedAcceleratorDelegate()
: accelerator_manager_(new ui::AcceleratorManager) {}
virtual ~MockNestedAcceleratorDelegate() {}
// NestedAcceleratorDelegate:
virtual bool ShouldProcessEventNow(const ui::KeyEvent& key_event) OVERRIDE {
return true;
}
virtual bool ProcessEvent(const ui::KeyEvent& key_event) OVERRIDE {
const int kModifierMask =
(ui::EF_SHIFT_DOWN | ui::EF_CONTROL_DOWN | ui::EF_ALT_DOWN);
ui::Accelerator accelerator(key_event.key_code(),
key_event.flags() & kModifierMask);
if (key_event.type() == ui::ET_KEY_RELEASED)
accelerator.set_type(ui::ET_KEY_RELEASED);
return accelerator_manager_->Process(accelerator);
}
void Register(const ui::Accelerator& accelerator,
ui::AcceleratorTarget* target) {
accelerator_manager_->Register(
accelerator, ui::AcceleratorManager::kNormalPriority, target);
}
private:
scoped_ptr<ui::AcceleratorManager> accelerator_manager_;
DISALLOW_COPY_AND_ASSIGN(MockNestedAcceleratorDelegate);
};
class NestedAcceleratorTest : public aura::test::AuraTestBase {
public:
NestedAcceleratorTest() {}
virtual ~NestedAcceleratorTest() {}
virtual void SetUp() OVERRIDE {
AuraTestBase::SetUp();
delegate_ = new MockNestedAcceleratorDelegate();
nested_accelerator_controller_.reset(
new NestedAcceleratorController(delegate_));
aura::client::SetDispatcherClient(root_window(),
nested_accelerator_controller_.get());
}
virtual void TearDown() OVERRIDE {
aura::client::SetDispatcherClient(root_window(), NULL);
AuraTestBase::TearDown();
delegate_ = NULL;
nested_accelerator_controller_.reset();
}
MockNestedAcceleratorDelegate* delegate() { return delegate_; }
private:
scoped_ptr<NestedAcceleratorController> nested_accelerator_controller_;
MockNestedAcceleratorDelegate* delegate_;
DISALLOW_COPY_AND_ASSIGN(NestedAcceleratorTest);
};
} // namespace
typedef AshTestBase NestedDispatcherTest;
// Aura window above lock screen in z order.
TEST_F(NestedAcceleratorTest, AssociatedWindowAboveLockScreen) {
TEST_F(NestedDispatcherTest, AssociatedWindowAboveLockScreen) {
MockDispatcher inner_dispatcher;
scoped_ptr<aura::Window> mock_lock_container(
CreateNormalWindow(0, root_window(), NULL));
CreateTestWindowInShellWithId(0));
aura::test::CreateTestWindowWithId(1, mock_lock_container.get());
scoped_ptr<aura::Window> associated_window(
CreateNormalWindow(2, root_window(), NULL));
scoped_ptr<aura::Window> associated_window(CreateTestWindowInShellWithId(2));
EXPECT_TRUE(aura::test::WindowIsAbove(associated_window.get(),
mock_lock_container.get()));
mock_lock_container.get()));
DispatchKeyReleaseA(root_window());
DispatchKeyReleaseA();
aura::Window* root_window = ash::Shell::GetPrimaryRootWindow();
scoped_ptr<ui::ScopedEventDispatcher> override_dispatcher =
ui::PlatformEventSource::GetInstance()->OverrideDispatcher(
&inner_dispatcher);
aura::client::GetDispatcherClient(root_window())->RunWithDispatcher(NULL);
aura::client::GetDispatcherClient(root_window)->RunWithDispatcher(NULL);
EXPECT_EQ(1, inner_dispatcher.num_key_events_dispatched());
}
// Test that the nested dispatcher handles accelerators.
TEST_F(NestedAcceleratorTest, AcceleratorsHandled) {
TEST_F(NestedDispatcherTest, AcceleratorsHandled) {
MockDispatcher inner_dispatcher;
aura::Window* root_window = ash::Shell::GetPrimaryRootWindow();
ui::Accelerator accelerator(ui::VKEY_A, ui::EF_NONE);
accelerator.set_type(ui::ET_KEY_RELEASED);
TestTarget target;
delegate()->Register(accelerator, &target);
Shell::GetInstance()->accelerator_controller()->Register(accelerator,
&target);
DispatchKeyReleaseA(root_window());
DispatchKeyReleaseA();
scoped_ptr<ui::ScopedEventDispatcher> override_dispatcher =
ui::PlatformEventSource::GetInstance()->OverrideDispatcher(
&inner_dispatcher);
aura::client::GetDispatcherClient(root_window())->RunWithDispatcher(NULL);
aura::client::GetDispatcherClient(root_window)->RunWithDispatcher(NULL);
EXPECT_EQ(0, inner_dispatcher.num_key_events_dispatched());
EXPECT_EQ(1, target.accelerator_pressed_count());
}
} // namespace test
} // namespace wm
} // namespace test
} // namespace ash
#a Copyright (c) 2012 The Chromium Authors. All rights reserved.
# Copyright (c) 2012 The Chromium Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
......@@ -55,8 +55,10 @@
'accelerators/accelerator_commands.h',
'accelerators/accelerator_controller.cc',
'accelerators/accelerator_controller.h',
'accelerators/nested_accelerator_delegate.cc',
'accelerators/nested_accelerator_delegate.h',
'accelerators/accelerator_dispatcher.cc',
'accelerators/accelerator_dispatcher.h',
'accelerators/accelerator_dispatcher_linux.cc',
'accelerators/accelerator_dispatcher_win.cc',
'accelerators/accelerator_filter.cc',
'accelerators/accelerator_filter.h',
'accelerators/accelerator_table.cc',
......@@ -71,6 +73,8 @@
'accelerators/focus_manager_factory.h',
'accelerators/magnifier_key_scroller.cc',
'accelerators/magnifier_key_scroller.h',
'accelerators/nested_dispatcher_controller.cc',
'accelerators/nested_dispatcher_controller.h',
'accelerators/spoken_feedback_toggler.cc',
'accelerators/spoken_feedback_toggler.h',
'accelerometer/accelerometer_controller.cc',
......@@ -916,6 +920,7 @@
'accelerators/accelerator_filter_unittest.cc',
'accelerators/accelerator_table_unittest.cc',
'accelerators/magnifier_key_scroller_unittest.cc',
'accelerators/nested_dispatcher_controller_unittest.cc',
'accelerators/spoken_feedback_toggler_unittest.cc',
'autoclick/autoclick_unittest.cc',
'desktop_background/desktop_background_controller_unittest.cc',
......
......@@ -10,7 +10,7 @@
#include "ash/accelerators/accelerator_controller.h"
#include "ash/accelerators/accelerator_filter.h"
#include "ash/accelerators/focus_manager_factory.h"
#include "ash/accelerators/nested_accelerator_delegate.h"
#include "ash/accelerators/nested_dispatcher_controller.h"
#include "ash/accelerometer/accelerometer_controller.h"
#include "ash/ash_switches.h"
#include "ash/autoclick/autoclick_controller.h"
......@@ -108,7 +108,6 @@
#include "ui/wm/core/compound_event_filter.h"
#include "ui/wm/core/focus_controller.h"
#include "ui/wm/core/input_method_event_filter.h"
#include "ui/wm/core/nested_accelerator_controller.h"
#include "ui/wm/core/shadow_controller.h"
#include "ui/wm/core/user_activity_detector.h"
#include "ui/wm/core/visibility_controller.h"
......@@ -754,7 +753,7 @@ Shell::~Shell() {
partial_magnification_controller_.reset();
tooltip_controller_.reset();
event_client_.reset();
nested_accelerator_controller_.reset();
nested_dispatcher_controller_.reset();
toplevel_window_event_handler_.reset();
visibility_controller_.reset();
// |shelf_item_delegate_manager_| observes |shelf_model_|. It must be
......@@ -880,8 +879,7 @@ void Shell::Init(const ShellInitParams& init_params) {
cursor_manager_.SetDisplay(GetScreen()->GetPrimaryDisplay());
nested_accelerator_controller_.reset(
new ::wm::NestedAcceleratorController(new NestedAcceleratorDelegate));
nested_dispatcher_controller_.reset(new NestedDispatcherController);
accelerator_controller_.reset(new AcceleratorController);
maximize_mode_controller_.reset(new MaximizeModeController());
......@@ -1094,9 +1092,9 @@ void Shell::InitRootWindow(aura::Window* root_window) {
root_window->AddPreTargetHandler(toplevel_window_event_handler_.get());
root_window->AddPostTargetHandler(toplevel_window_event_handler_.get());
if (nested_accelerator_controller_) {
if (nested_dispatcher_controller_) {
aura::client::SetDispatcherClient(root_window,
nested_accelerator_controller_.get());
nested_dispatcher_controller_.get());
}
}
......
......@@ -64,7 +64,6 @@ class TooltipController;
namespace wm {
class CompoundEventFilter;
class InputMethodEventFilter;
class NestedAcceleratorController;
class ShadowController;
class VisibilityController;
class UserActivityDetector;
......@@ -107,6 +106,7 @@ class MaximizeModeWindowManager;
class MediaDelegate;
class MouseCursorEventFilter;
class MruWindowTracker;
class NestedDispatcherController;
class NewWindowDelegate;
class OverlayEventFilter;
class PartialMagnificationController;
......@@ -623,7 +623,7 @@ class ASH_EXPORT Shell : public SystemModalContainerEventFilterDelegate,
std::vector<WindowAndBoundsPair> to_restore_;
scoped_ptr<UserMetricsRecorder> user_metrics_recorder_;
scoped_ptr< ::wm::NestedAcceleratorController> nested_accelerator_controller_;
scoped_ptr<NestedDispatcherController> nested_dispatcher_controller_;
scoped_ptr<AcceleratorController> accelerator_controller_;
scoped_ptr<ShellDelegate> delegate_;
scoped_ptr<SystemTrayDelegate> system_tray_delegate_;
......
include_rules = [
"+grit/ui_resources.h",
"+ui/aura",
"+ui/base/accelerators",
"+ui/base/cursor",
"+ui/base/hit_test.h",
"+ui/base/ime",
......
// Copyright 2014 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef UI_WM_CORE_NESTED_ACCELERATOR_DELEGATE_H_
#define UI_WM_CORE_NESTED_ACCELERATOR_DELEGATE_H_
namespace ui {
class KeyEvent;
}
namespace wm {
// A delegate interface that implements the behavior of nested accelerator
// handling.
class NestedAcceleratorDelegate {
public:
virtual ~NestedAcceleratorDelegate() {}
// If the key event should be ignored now and instead be reposted so that next
// event loop.
virtual bool ShouldProcessEventNow(const ui::KeyEvent& key_event) = 0;
// Attempts to process an accelerator for the key-event.
// Returns whether an accelerator was triggered and processed.
virtual bool ProcessEvent(const ui::KeyEvent& key_event) = 0;
};
} // namespace wm
#endif // UI_WM_CORE_NESTED_ACCELERATOR_DELEGATE_H_
// Copyright 2014 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "ui/wm/core/nested_accelerator_dispatcher.h"
#include "base/logging.h"
#include "ui/wm/core/nested_accelerator_delegate.h"
namespace wm {
NestedAcceleratorDispatcher::NestedAcceleratorDispatcher(
NestedAcceleratorDelegate* delegate)
: delegate_(delegate) {
DCHECK(delegate);
}
NestedAcceleratorDispatcher::~NestedAcceleratorDispatcher() {
}
} // namespace wm
......@@ -26,14 +26,6 @@
'WM_IMPLEMENTATION',
],
'sources': [
'core/nested_accelerator_dispatcher_linux.cc',
'core/nested_accelerator_dispatcher_win.cc',
'core/nested_accelerator_dispatcher.cc',
'core/nested_accelerator_dispatcher.h',
'core/nested_accelerator_delegate.h',
'core/nested_accelerator_controller.cc',
'core/nested_accelerator_controller.h',
'core/base_focus_rules.h',
'core/base_focus_rules.cc',
'core/base_focus_rules.h',
'core/capture_controller.cc',
......@@ -129,7 +121,6 @@
'core/focus_controller_unittest.cc',
'core/input_method_event_filter_unittest.cc',
'core/image_grid_unittest.cc',
'core/nested_accelerator_controller_unittest.cc',
'core/shadow_controller_unittest.cc',
'core/transient_window_manager_unittest.cc',
'core/transient_window_stacking_client_unittest.cc',
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment