Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(2520)

Unified Diff: ash/mus/window_manager.cc

Issue 2171973003: Separates out accelerator handling in windowmanager (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: merge Created 4 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « ash/mus/window_manager.h ('k') | ash/mus/window_manager_application.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: ash/mus/window_manager.cc
diff --git a/ash/mus/window_manager.cc b/ash/mus/window_manager.cc
index 3ab6ea52b2d2cd7f27322188ff18ace019e9e82b..b9640f6f340eb0d8296e68a2cfd84e709f5556f1 100644
--- a/ash/mus/window_manager.cc
+++ b/ash/mus/window_manager.cc
@@ -9,6 +9,8 @@
#include <utility>
#include "ash/common/shell_window_ids.h"
+#include "ash/mus/accelerators/accelerator_handler.h"
+#include "ash/mus/accelerators/accelerator_ids.h"
#include "ash/mus/bridge/wm_lookup_mus.h"
#include "ash/mus/bridge/wm_shell_mus.h"
#include "ash/mus/bridge/wm_window_mus.h"
@@ -36,8 +38,6 @@
namespace ash {
namespace mus {
-const uint32_t kWindowSwitchAccelerator = 1;
-
void AssertTrue(bool success) {
DCHECK(success);
}
@@ -79,8 +79,6 @@ void WindowManager::Init(::ui::WindowTreeClient* window_tree_client) {
shadow_controller_.reset(new ShadowController(window_tree_client));
- AddAccelerators();
-
// The insets are roughly what is needed by CustomFrameView. The expectation
// is at some point we'll write our own NonClientFrameView and get the insets
// from it.
@@ -127,6 +125,26 @@ std::set<RootWindowController*> WindowManager::GetRootWindowControllers() {
return result;
}
+bool WindowManager::GetNextAcceleratorNamespaceId(uint16_t* id) {
+ if (accelerator_handlers_.size() == std::numeric_limits<uint16_t>::max())
+ return false;
+ while (accelerator_handlers_.count(next_accelerator_namespace_id_) > 0)
+ ++next_accelerator_namespace_id_;
+ *id = next_accelerator_namespace_id_;
+ ++next_accelerator_namespace_id_;
+ return true;
+}
+
+void WindowManager::AddAcceleratorHandler(uint16_t id_namespace,
+ AcceleratorHandler* handler) {
+ DCHECK_EQ(0u, accelerator_handlers_.count(id_namespace));
+ accelerator_handlers_[id_namespace] = handler;
+}
+
+void WindowManager::RemoveAcceleratorHandler(uint16_t id_namespace) {
+ accelerator_handlers_.erase(id_namespace);
+}
+
void WindowManager::AddObserver(WindowManagerObserver* observer) {
observers_.AddObserver(observer);
}
@@ -135,16 +153,6 @@ void WindowManager::RemoveObserver(WindowManagerObserver* observer) {
observers_.RemoveObserver(observer);
}
-void WindowManager::AddAccelerators() {
- // TODO(sky): this is broke for multi-display case. Need to fix mus to
- // deal correctly.
- window_manager_client_->AddAccelerator(
- kWindowSwitchAccelerator,
- ::ui::CreateKeyMatcher(ui::mojom::KeyboardCode::TAB,
- ui::mojom::kEventFlagControlDown),
- base::Bind(&AssertTrue));
-}
-
RootWindowController* WindowManager::CreateRootWindowController(
::ui::Window* window,
const display::Display& display) {
@@ -288,17 +296,11 @@ void WindowManager::OnWmCancelMoveLoop(::ui::Window* window) {
ui::mojom::EventResult WindowManager::OnAccelerator(uint32_t id,
const ui::Event& event) {
- switch (id) {
- case kWindowSwitchAccelerator:
- window_manager_client()->ActivateNextWindow();
- break;
- default:
- FOR_EACH_OBSERVER(WindowManagerObserver, observers_,
- OnAccelerator(id, event));
- break;
- }
+ auto iter = accelerator_handlers_.find(GetAcceleratorNamespaceId(id));
+ if (iter == accelerator_handlers_.end())
+ return ui::mojom::EventResult::HANDLED;
- return ui::mojom::EventResult::HANDLED;
+ return iter->second->OnAccelerator(id, event);
}
} // namespace mus
« no previous file with comments | « ash/mus/window_manager.h ('k') | ash/mus/window_manager_application.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698