summaryrefslogtreecommitdiffstats
path: root/athena/env
diff options
context:
space:
mode:
authoroshima <oshima@chromium.org>2014-08-25 14:32:49 -0700
committerCommit bot <commit-bot@chromium.org>2014-08-25 21:35:50 +0000
commit1629c184e328e7263e93042de97af58651ebe510 (patch)
tree5d91c6827fc18651b95c6530c7da403a162ea8e0 /athena/env
parentd27cb086ffcbfdc4c3f5b1d1d483b28dff5bd26c (diff)
downloadchromium_src-1629c184e328e7263e93042de97af58651ebe510.zip
chromium_src-1629c184e328e7263e93042de97af58651ebe510.tar.gz
chromium_src-1629c184e328e7263e93042de97af58651ebe510.tar.bz2
Separate athena's startup process from AppShell's
* Introduced DesktopController interface. app_shell's Init process stays in ShellDesktopController * Removed ShellAppWindowController * Athena has its own AthenaDesktopController * Intorduced AthenaEnv. This is now used for both AthenaMain and Unit test. * Removed ScreenManagerDelegate and integrate it into AthenaEnv. * Moved FocusController to ScreenManager, and removed CreateFocusRules() BUG=397167 TBR=sky@chromium.org Review URL: https://codereview.chromium.org/480353006 Cr-Commit-Position: refs/heads/master@{#291763}
Diffstat (limited to 'athena/env')
-rw-r--r--athena/env/DEPS9
-rw-r--r--athena/env/athena_env_impl.cc260
-rw-r--r--athena/env/public/DEPS4
-rw-r--r--athena/env/public/athena_env.h39
4 files changed, 312 insertions, 0 deletions
diff --git a/athena/env/DEPS b/athena/env/DEPS
new file mode 100644
index 0000000..bcac64e
--- /dev/null
+++ b/athena/env/DEPS
@@ -0,0 +1,9 @@
+include_rules = [
+ "+chromeos/dbus",
+ "+ui/aura",
+ "+ui/base",
+ "+ui/chromeos",
+ "+ui/display",
+ "+ui/gfx",
+ "+ui/wm",
+]
diff --git a/athena/env/athena_env_impl.cc b/athena/env/athena_env_impl.cc
new file mode 100644
index 0000000..d94291b
--- /dev/null
+++ b/athena/env/athena_env_impl.cc
@@ -0,0 +1,260 @@
+// 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 "athena/env/public/athena_env.h"
+
+#include "athena/common/fill_layout_manager.h"
+#include "base/sys_info.h"
+#include "ui/aura/client/aura_constants.h"
+#include "ui/aura/client/cursor_client.h"
+#include "ui/aura/client/default_capture_client.h"
+#include "ui/aura/env.h"
+#include "ui/aura/test/test_screen.h"
+#include "ui/aura/window_event_dispatcher.h"
+#include "ui/aura/window_tree_host.h"
+#include "ui/aura/window_tree_host_observer.h"
+#include "ui/base/cursor/cursor.h"
+#include "ui/base/cursor/image_cursors.h"
+#include "ui/chromeos/user_activity_power_manager_notifier.h"
+#include "ui/display/chromeos/display_configurator.h"
+#include "ui/display/types/chromeos/display_mode.h"
+#include "ui/display/types/chromeos/display_snapshot.h"
+#include "ui/gfx/screen.h"
+#include "ui/wm/core/compound_event_filter.h"
+#include "ui/wm/core/cursor_manager.h"
+#include "ui/wm/core/input_method_event_filter.h"
+#include "ui/wm/core/native_cursor_manager.h"
+#include "ui/wm/core/native_cursor_manager_delegate.h"
+#include "ui/wm/core/user_activity_detector.h"
+
+namespace athena {
+
+namespace {
+
+AthenaEnv* instance = NULL;
+
+// A class that bridges the gap between CursorManager and Aura. It borrows
+// heavily from AshNativeCursorManager.
+class AthenaNativeCursorManager : public wm::NativeCursorManager {
+ public:
+ explicit AthenaNativeCursorManager(aura::WindowTreeHost* host)
+ : host_(host), image_cursors_(new ui::ImageCursors) {}
+ virtual ~AthenaNativeCursorManager() {}
+
+ // wm::NativeCursorManager overrides.
+ virtual void SetDisplay(const gfx::Display& display,
+ wm::NativeCursorManagerDelegate* delegate) OVERRIDE {
+ if (image_cursors_->SetDisplay(display, display.device_scale_factor()))
+ SetCursor(delegate->GetCursor(), delegate);
+ }
+
+ virtual void SetCursor(gfx::NativeCursor cursor,
+ wm::NativeCursorManagerDelegate* delegate) OVERRIDE {
+ image_cursors_->SetPlatformCursor(&cursor);
+ cursor.set_device_scale_factor(image_cursors_->GetScale());
+ delegate->CommitCursor(cursor);
+
+ if (delegate->IsCursorVisible())
+ ApplyCursor(cursor);
+ }
+
+ virtual void SetVisibility(
+ bool visible,
+ wm::NativeCursorManagerDelegate* delegate) OVERRIDE {
+ delegate->CommitVisibility(visible);
+
+ if (visible) {
+ SetCursor(delegate->GetCursor(), delegate);
+ } else {
+ gfx::NativeCursor invisible_cursor(ui::kCursorNone);
+ image_cursors_->SetPlatformCursor(&invisible_cursor);
+ ApplyCursor(invisible_cursor);
+ }
+ }
+
+ virtual void SetCursorSet(
+ ui::CursorSetType cursor_set,
+ wm::NativeCursorManagerDelegate* delegate) OVERRIDE {
+ image_cursors_->SetCursorSet(cursor_set);
+ delegate->CommitCursorSet(cursor_set);
+ if (delegate->IsCursorVisible())
+ SetCursor(delegate->GetCursor(), delegate);
+ }
+
+ virtual void SetMouseEventsEnabled(
+ bool enabled,
+ wm::NativeCursorManagerDelegate* delegate) OVERRIDE {
+ delegate->CommitMouseEventsEnabled(enabled);
+ SetVisibility(delegate->IsCursorVisible(), delegate);
+ }
+
+ private:
+ // Sets |cursor| as the active cursor within Aura.
+ void ApplyCursor(gfx::NativeCursor cursor) { host_->SetCursor(cursor); }
+
+ aura::WindowTreeHost* host_; // Not owned.
+
+ scoped_ptr<ui::ImageCursors> image_cursors_;
+
+ DISALLOW_COPY_AND_ASSIGN(AthenaNativeCursorManager);
+};
+
+class AthenaEnvImpl : public AthenaEnv,
+ public aura::WindowTreeHostObserver,
+ public ui::DisplayConfigurator::Observer {
+ public:
+ AthenaEnvImpl() : display_configurator_(new ui::DisplayConfigurator) {
+ display_configurator_->Init(false);
+ display_configurator_->ForceInitialConfigure(0);
+ display_configurator_->AddObserver(this);
+
+ gfx::Size screen_size = GetPrimaryDisplaySize();
+ if (screen_size.IsEmpty()) {
+ // TODO(oshima): Remove this hack.
+ if (base::SysInfo::IsRunningOnChromeOS())
+ screen_size.SetSize(2560, 1600);
+ else
+ screen_size.SetSize(1280, 720);
+ }
+ screen_.reset(aura::TestScreen::Create(screen_size));
+
+ gfx::Screen::SetScreenInstance(gfx::SCREEN_TYPE_NATIVE, screen_.get());
+ host_.reset(screen_->CreateHostForPrimaryDisplay());
+ host_->InitHost();
+
+ aura::Window* root_window = GetHost()->window();
+ input_method_filter_.reset(
+ new wm::InputMethodEventFilter(host_->GetAcceleratedWidget()));
+ input_method_filter_->SetInputMethodPropertyInRootWindow(root_window);
+
+ root_window_event_filter_.reset(new wm::CompoundEventFilter);
+ host_->window()->AddPreTargetHandler(root_window_event_filter_.get());
+
+ input_method_filter_.reset(
+ new wm::InputMethodEventFilter(host_->GetAcceleratedWidget()));
+ input_method_filter_->SetInputMethodPropertyInRootWindow(host_->window());
+ root_window_event_filter_->AddHandler(input_method_filter_.get());
+
+ capture_client_.reset(
+ new aura::client::DefaultCaptureClient(host_->window()));
+
+ // Ensure new windows fill the display.
+ root_window->SetLayoutManager(new FillLayoutManager(root_window));
+
+ cursor_manager_.reset(
+ new wm::CursorManager(scoped_ptr<wm::NativeCursorManager>(
+ new AthenaNativeCursorManager(host_.get()))));
+ cursor_manager_->SetDisplay(
+ gfx::Screen::GetNativeScreen()->GetPrimaryDisplay());
+ cursor_manager_->SetCursor(ui::kCursorPointer);
+ aura::client::SetCursorClient(host_->window(), cursor_manager_.get());
+
+ user_activity_detector_.reset(new wm::UserActivityDetector);
+ host_->event_processor()->GetRootTarget()->AddPreTargetHandler(
+ user_activity_detector_.get());
+ user_activity_notifier_.reset(new ui::UserActivityPowerManagerNotifier(
+ user_activity_detector_.get()));
+
+ host_->AddObserver(this);
+ host_->Show();
+
+ DCHECK(!instance);
+ instance = this;
+ }
+
+ virtual ~AthenaEnvImpl() {
+ instance = NULL;
+
+ host_->RemoveObserver(this);
+ if (input_method_filter_)
+ root_window_event_filter_->RemoveHandler(input_method_filter_.get());
+ if (user_activity_detector_) {
+ host_->event_processor()->GetRootTarget()->RemovePreTargetHandler(
+ user_activity_detector_.get());
+ }
+ root_window_event_filter_.reset();
+ capture_client_.reset();
+ input_method_filter_.reset();
+ cursor_manager_.reset();
+ user_activity_notifier_.reset();
+ user_activity_detector_.reset();
+
+ input_method_filter_.reset();
+ host_.reset();
+ screen_.reset();
+ gfx::Screen::SetScreenInstance(gfx::SCREEN_TYPE_NATIVE, NULL);
+
+ aura::Env::DeleteInstance();
+
+ display_configurator_->RemoveObserver(this);
+ display_configurator_.reset();
+ }
+
+ private:
+ virtual aura::WindowTreeHost* GetHost() OVERRIDE { return host_.get(); }
+
+ // AthenaEnv:
+ virtual void SetDisplayWorkAreaInsets(const gfx::Insets& insets) OVERRIDE {
+ screen_->SetWorkAreaInsets(insets);
+ }
+
+ // ui::DisplayConfigurator::Observer:
+ virtual void OnDisplayModeChanged(const std::vector<
+ ui::DisplayConfigurator::DisplayState>& displays) OVERRIDE {
+ gfx::Size size = GetPrimaryDisplaySize();
+ if (!size.IsEmpty())
+ host_->UpdateRootWindowSize(size);
+ }
+
+ // aura::WindowTreeHostObserver:
+ virtual void OnHostCloseRequested(const aura::WindowTreeHost* host) OVERRIDE {
+ base::MessageLoopForUI::current()->PostTask(
+ FROM_HERE, base::MessageLoop::QuitClosure());
+ }
+
+ gfx::Size GetPrimaryDisplaySize() const {
+ const std::vector<ui::DisplayConfigurator::DisplayState>& displays =
+ display_configurator_->cached_displays();
+ if (displays.empty())
+ return gfx::Size();
+ const ui::DisplayMode* mode = displays[0].display->current_mode();
+ return mode ? mode->size() : gfx::Size();
+ }
+
+ scoped_ptr<aura::TestScreen> screen_;
+ scoped_ptr<aura::WindowTreeHost> host_;
+
+ scoped_ptr<wm::InputMethodEventFilter> input_method_filter_;
+ scoped_ptr<wm::CompoundEventFilter> root_window_event_filter_;
+ scoped_ptr<aura::client::DefaultCaptureClient> capture_client_;
+ scoped_ptr<wm::CursorManager> cursor_manager_;
+ scoped_ptr<wm::UserActivityDetector> user_activity_detector_;
+ scoped_ptr<ui::DisplayConfigurator> display_configurator_;
+ scoped_ptr<ui::UserActivityPowerManagerNotifier> user_activity_notifier_;
+
+ DISALLOW_COPY_AND_ASSIGN(AthenaEnvImpl);
+};
+
+} // namespace
+
+// static
+void AthenaEnv::Create() {
+ DCHECK(!instance);
+ new AthenaEnvImpl();
+}
+
+AthenaEnv* AthenaEnv::Get() {
+ DCHECK(instance);
+ return instance;
+}
+
+// static
+
+// static
+void AthenaEnv::Shutdown() {
+ DCHECK(instance);
+ delete instance;
+}
+
+} // namespace athena
diff --git a/athena/env/public/DEPS b/athena/env/public/DEPS
new file mode 100644
index 0000000..c97ecd3
--- /dev/null
+++ b/athena/env/public/DEPS
@@ -0,0 +1,4 @@
+include_rules = [
+ "-athena/env",
+ "+athena/athena_export.h",
+]
diff --git a/athena/env/public/athena_env.h b/athena/env/public/athena_env.h
new file mode 100644
index 0000000..703a87f
--- /dev/null
+++ b/athena/env/public/athena_env.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 ATHENA_ENV_PUBLIC_ATHENA_ENV_H_
+#define ATHENA_ENV_PUBLIC_ATHENA_ENV_H_
+
+#include "athena/athena_export.h"
+
+namespace gfx {
+class Insets;
+}
+
+namespace aura {
+class WindowTreeHost;
+}
+
+namespace athena {
+
+// AthenaEnv creates/shuts down the environment necessary to
+// start Athena shell.
+class ATHENA_EXPORT AthenaEnv {
+ public:
+ static void Create();
+ static AthenaEnv* Get();
+ static void Shutdown();
+
+ virtual ~AthenaEnv() {}
+
+ // Returns the single WindowTreeHost for the primary display.
+ virtual aura::WindowTreeHost* GetHost() = 0;
+
+ // Sets the insets for the primary displays's work area.
+ virtual void SetDisplayWorkAreaInsets(const gfx::Insets& insets) = 0;
+};
+
+} // namespace athena
+
+#endif // ATHENA_ENV_PUBLIC_ATHENA_ENV_H_