diff --git a/engine/src/flutter/BUILD.gn b/engine/src/flutter/BUILD.gn index 5a686fbbd74..ee665ca6e7a 100644 --- a/engine/src/flutter/BUILD.gn +++ b/engine/src/flutter/BUILD.gn @@ -14,10 +14,14 @@ group("sky") { "//sky/engine/web:sky_unittests", "//sky/engine/wtf:unittests", "//sky/services/inspector", - "//sky/tools/debugger", - "//sky/tools/tester", "//sky/viewer", ] + if (use_aura) { + deps += [ + "//sky/tools/debugger", + "//sky/tools/tester", + ] + } if (!is_android) { deps += [ "//third_party/mesa:osmesa" ] } diff --git a/engine/src/flutter/tools/debugger/BUILD.gn b/engine/src/flutter/tools/debugger/BUILD.gn index 72a4a1b076d..199269cc46c 100644 --- a/engine/src/flutter/tools/debugger/BUILD.gn +++ b/engine/src/flutter/tools/debugger/BUILD.gn @@ -17,6 +17,8 @@ shared_library("sky_debugger") { sources = [ "debugger.cc", "debugger.h", + "focus_rules.cc", + "focus_rules.h", "main.cc", "navigator_host_impl.cc", "navigator_host_impl.h", @@ -35,6 +37,8 @@ shared_library("sky_debugger") { "//mojo/services/public/interfaces/navigation", "//mojo/services/window_manager:lib", "//sky/viewer:bindings", + "//ui/aura:aura", + "//ui/wm:wm", ":bindings", ] } diff --git a/engine/src/flutter/tools/debugger/debugger.cc b/engine/src/flutter/tools/debugger/debugger.cc index 3fb3a9834ab..96e68cc1bff 100644 --- a/engine/src/flutter/tools/debugger/debugger.cc +++ b/engine/src/flutter/tools/debugger/debugger.cc @@ -4,8 +4,6 @@ #include "sky/tools/debugger/debugger.h" -#include "mojo/services/window_manager/basic_focus_rules.h" - namespace sky { namespace debugger { @@ -60,8 +58,8 @@ void SkyDebugger::OnEmbed( content_->SetBounds(root_->bounds()); root_->AddChild(content_); - window_manager_app_->InitFocus(scoped_ptr( - new mojo::BasicFocusRules(window_manager_app_.get(), content_))); + window_manager_app_->InitFocus( + new FocusRules(window_manager_app_.get(), content_)); if (!pending_url_.empty()) NavigateToURL(pending_url_); diff --git a/engine/src/flutter/tools/debugger/debugger.h b/engine/src/flutter/tools/debugger/debugger.h index 8c40fc4f5c0..e48a6280d7b 100644 --- a/engine/src/flutter/tools/debugger/debugger.h +++ b/engine/src/flutter/tools/debugger/debugger.h @@ -15,6 +15,7 @@ #include "mojo/services/window_manager/window_manager_app.h" #include "mojo/services/window_manager/window_manager_delegate.h" #include "sky/tools/debugger/debugger.mojom.h" +#include "sky/tools/debugger/focus_rules.h" #include "sky/tools/debugger/navigator_host_impl.h" #include "sky/viewer/services/inspector.mojom.h" diff --git a/engine/src/flutter/tools/debugger/focus_rules.cc b/engine/src/flutter/tools/debugger/focus_rules.cc new file mode 100644 index 00000000000..68eca6223cd --- /dev/null +++ b/engine/src/flutter/tools/debugger/focus_rules.cc @@ -0,0 +1,61 @@ +// 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 "sky/tools/debugger/focus_rules.h" + +namespace sky { +namespace debugger { + +FocusRules::FocusRules(mojo::WindowManagerApp* window_manager_app, + mojo::View* content) + : content_(content), + window_manager_app_(window_manager_app) { +} + +FocusRules::~FocusRules() { +} + +bool FocusRules::IsToplevelWindow(aura::Window* window) const { + return mojo::WindowManagerApp::GetViewForWindow(window)->parent() == content_; +} + +bool FocusRules::CanActivateWindow(aura::Window* window) const { + return mojo::WindowManagerApp::GetViewForWindow(window)->parent() == content_; +} + +bool FocusRules::CanFocusWindow(aura::Window* window) const { + return true; +} + +aura::Window* FocusRules::GetToplevelWindow(aura::Window* window) const { + mojo::View* view = mojo::WindowManagerApp::GetViewForWindow(window); + while (view->parent() != content_) { + view = view->parent(); + if (!view) + return NULL; + } + return window_manager_app_->GetWindowForViewId(view->id()); +} + +aura::Window* FocusRules::GetActivatableWindow(aura::Window* window) const { + return GetToplevelWindow(window); +} + +aura::Window* FocusRules::GetFocusableWindow(aura::Window* window) const { + return window; +} + +aura::Window* FocusRules::GetNextActivatableWindow(aura::Window* ignore) const { + aura::Window* activatable = GetActivatableWindow(ignore); + const aura::Window::Windows& children = activatable->parent()->children(); + for (aura::Window::Windows::const_reverse_iterator it = children.rbegin(); + it != children.rend(); ++it) { + if (*it != ignore) + return *it; + } + return NULL; +} + +} // namespace debugger +} // namespace sky diff --git a/engine/src/flutter/tools/debugger/focus_rules.h b/engine/src/flutter/tools/debugger/focus_rules.h new file mode 100644 index 00000000000..fa5a91974fa --- /dev/null +++ b/engine/src/flutter/tools/debugger/focus_rules.h @@ -0,0 +1,39 @@ +// 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 SKY_TOOLS_DEBUGGER_FOCUS_RULES_H_ +#define SKY_TOOLS_DEBUGGER_FOCUS_RULES_H_ + +#include "mojo/services/window_manager/window_manager_app.h" +#include "ui/aura/window.h" +#include "ui/wm/core/focus_rules.h" + +namespace sky { +namespace debugger { + +class FocusRules : public wm::FocusRules { + public: + FocusRules(mojo::WindowManagerApp* window_manager_app, mojo::View* content); + virtual ~FocusRules(); + + private: + // Overridden from wm::FocusRules: + bool IsToplevelWindow(aura::Window* window) const override; + bool CanActivateWindow(aura::Window* window) const override; + bool CanFocusWindow(aura::Window* window) const override; + aura::Window* GetToplevelWindow(aura::Window* window) const override; + aura::Window* GetActivatableWindow(aura::Window* window) const override; + aura::Window* GetFocusableWindow(aura::Window* window) const override; + aura::Window* GetNextActivatableWindow(aura::Window* ignore) const override; + + mojo::View* content_; + mojo::WindowManagerApp* window_manager_app_; + + DISALLOW_COPY_AND_ASSIGN(FocusRules); +}; + +} // namespace debugger +} // namespace sky + +#endif // SKY_TOOLS_DEBUGGER_FOCUS_RULES_H_