summaryrefslogtreecommitdiffstats
path: root/mandoline/ui
diff options
context:
space:
mode:
authorfsamuel <fsamuel@chromium.org>2015-10-14 11:08:16 -0700
committerCommit bot <commit-bot@chromium.org>2015-10-14 18:09:17 +0000
commit37721dde845ddd941c38f3cfa8cd9f2937c8ec33 (patch)
treeb7c9c3e6805162f791a31fbe07a76717b559ce4b /mandoline/ui
parent6f1dd4000a5336c6c126ad30cd205d85b1a32aa3 (diff)
downloadchromium_src-37721dde845ddd941c38f3cfa8cd9f2937c8ec33.zip
chromium_src-37721dde845ddd941c38f3cfa8cd9f2937c8ec33.tar.gz
chromium_src-37721dde845ddd941c38f3cfa8cd9f2937c8ec33.tar.bz2
Move ViewObserver out of NativeWidgetViewManager
In order to avoid name collisions in subsequent CLs, this CL moves the ViewObserver parts out. BUG=542848 Review URL: https://codereview.chromium.org/1392113003 Cr-Commit-Position: refs/heads/master@{#354062}
Diffstat (limited to 'mandoline/ui')
-rw-r--r--mandoline/ui/aura/native_widget_view_manager.cc102
-rw-r--r--mandoline/ui/aura/native_widget_view_manager.h24
-rw-r--r--mandoline/ui/omnibox/omnibox_application.cc1
3 files changed, 72 insertions, 55 deletions
diff --git a/mandoline/ui/aura/native_widget_view_manager.cc b/mandoline/ui/aura/native_widget_view_manager.cc
index 7211d89..003aca9 100644
--- a/mandoline/ui/aura/native_widget_view_manager.cc
+++ b/mandoline/ui/aura/native_widget_view_manager.cc
@@ -4,6 +4,7 @@
#include "mandoline/ui/aura/native_widget_view_manager.h"
+#include "components/mus/public/cpp/view.h"
#include "mandoline/ui/aura/input_method_mandoline.h"
#include "mandoline/ui/aura/window_tree_host_mojo.h"
#include "mojo/converters/geometry/geometry_type_converters.h"
@@ -33,6 +34,61 @@ class FocusRulesImpl : public wm::BaseFocusRules {
DISALLOW_COPY_AND_ASSIGN(FocusRulesImpl);
};
+class NativeWidgetViewObserver : public mus::ViewObserver {
+ public:
+ NativeWidgetViewObserver(NativeWidgetViewManager* view_manager)
+ : view_manager_(view_manager) {
+ view_manager_->view_->AddObserver(this);
+ }
+
+ ~NativeWidgetViewObserver() override {
+ if (view_manager_->view_)
+ view_manager_->view_->RemoveObserver(this);
+ }
+
+ private:
+ // ViewObserver:
+ void OnViewDestroyed(mus::View* view) override {
+ DCHECK_EQ(view, view_manager_->view_);
+ view->RemoveObserver(this);
+ view_manager_->view_ = nullptr;
+ // TODO(sky): WindowTreeHostMojo assumes the View outlives it.
+ // NativeWidgetViewObserver needs to deal, likely by deleting this.
+ }
+
+ void OnViewBoundsChanged(mus::View* view,
+ const mojo::Rect& old_bounds,
+ const mojo::Rect& new_bounds) override {
+ gfx::Rect view_rect = view->bounds().To<gfx::Rect>();
+ view_manager_->SetBounds(gfx::Rect(view_rect.size()));
+ }
+
+ void OnViewFocusChanged(mus::View* gained_focus,
+ mus::View* lost_focus) override {
+ if (gained_focus == view_manager_->view_)
+ view_manager_->window_tree_host_->GetInputMethod()->OnFocus();
+ else if (lost_focus == view_manager_->view_)
+ view_manager_->window_tree_host_->GetInputMethod()->OnBlur();
+ }
+
+ void OnViewInputEvent(mus::View* view, const mojo::EventPtr& event) override {
+ scoped_ptr<ui::Event> ui_event(event.To<scoped_ptr<ui::Event>>());
+ if (!ui_event)
+ return;
+
+ if (ui_event->IsKeyEvent()) {
+ view_manager_->window_tree_host_->GetInputMethod()->DispatchKeyEvent(
+ static_cast<ui::KeyEvent*>(ui_event.get()));
+ } else {
+ view_manager_->window_tree_host_->SendEventToProcessor(ui_event.get());
+ }
+ }
+
+ NativeWidgetViewManager* const view_manager_;
+
+ DISALLOW_COPY_AND_ASSIGN(NativeWidgetViewObserver);
+};
+
} // namespace
NativeWidgetViewManager::NativeWidgetViewManager(
@@ -40,7 +96,6 @@ NativeWidgetViewManager::NativeWidgetViewManager(
mojo::Shell* shell,
mus::View* view)
: NativeWidgetAura(delegate), view_(view) {
- view_->AddObserver(this);
window_tree_host_.reset(new WindowTreeHostMojo(shell, view_));
window_tree_host_->InitHost();
@@ -54,13 +109,12 @@ NativeWidgetViewManager::NativeWidgetViewManager(
capture_client_.reset(
new aura::client::DefaultCaptureClient(window_tree_host_->window()));
-}
-NativeWidgetViewManager::~NativeWidgetViewManager() {
- if (view_)
- view_->RemoveObserver(this);
+ view_observer_.reset(new NativeWidgetViewObserver(this));
}
+NativeWidgetViewManager::~NativeWidgetViewManager() {}
+
void NativeWidgetViewManager::InitNativeWidget(
const views::Widget::InitParams& in_params) {
views::Widget::InitParams params(in_params);
@@ -76,42 +130,4 @@ void NativeWidgetViewManager::OnWindowVisibilityChanged(aura::Window* window,
// I'm not bothering.
}
-void NativeWidgetViewManager::OnViewDestroyed(mus::View* view) {
- DCHECK_EQ(view, view_);
- view->RemoveObserver(this);
- view_ = NULL;
- // TODO(sky): WindowTreeHostMojo assumes the View outlives it.
- // NativeWidgetViewManager needs to deal, likely by deleting this.
-}
-
-void NativeWidgetViewManager::OnViewBoundsChanged(
- mus::View* view,
- const mojo::Rect& old_bounds,
- const mojo::Rect& new_bounds) {
- gfx::Rect view_rect = view->bounds().To<gfx::Rect>();
- GetWidget()->SetBounds(gfx::Rect(view_rect.size()));
-}
-
-void NativeWidgetViewManager::OnViewFocusChanged(mus::View* gained_focus,
- mus::View* lost_focus) {
- if (gained_focus == view_)
- window_tree_host_->GetInputMethod()->OnFocus();
- else if (lost_focus == view_)
- window_tree_host_->GetInputMethod()->OnBlur();
-}
-
-void NativeWidgetViewManager::OnViewInputEvent(mus::View* view,
- const mojo::EventPtr& event) {
- scoped_ptr<ui::Event> ui_event(event.To<scoped_ptr<ui::Event>>());
- if (!ui_event)
- return;
-
- if (ui_event->IsKeyEvent()) {
- window_tree_host_->GetInputMethod()->DispatchKeyEvent(
- static_cast<ui::KeyEvent*>(ui_event.get()));
- } else {
- window_tree_host_->SendEventToProcessor(ui_event.get());
- }
-}
-
} // namespace mandoline
diff --git a/mandoline/ui/aura/native_widget_view_manager.h b/mandoline/ui/aura/native_widget_view_manager.h
index 22cce85..93b99fd 100644
--- a/mandoline/ui/aura/native_widget_view_manager.h
+++ b/mandoline/ui/aura/native_widget_view_manager.h
@@ -5,7 +5,6 @@
#ifndef MANDOLINE_UI_AURA_NATIVE_WIDGET_VIEW_MANAGER_H_
#define MANDOLINE_UI_AURA_NATIVE_WIDGET_VIEW_MANAGER_H_
-#include "components/mus/public/cpp/view_observer.h"
#include "ui/views/widget/native_widget_aura.h"
namespace aura {
@@ -28,12 +27,19 @@ namespace mojo {
class Shell;
}
+namespace mus {
+class View;
+}
+
namespace mandoline {
+namespace {
+class NativeWidgetViewObserver;
+}
+
class WindowTreeHostMojo;
-class NativeWidgetViewManager : public views::NativeWidgetAura,
- public mus::ViewObserver {
+class NativeWidgetViewManager : public views::NativeWidgetAura {
public:
NativeWidgetViewManager(views::internal::NativeWidgetDelegate* delegate,
mojo::Shell* shell,
@@ -41,20 +47,14 @@ class NativeWidgetViewManager : public views::NativeWidgetAura,
~NativeWidgetViewManager() override;
private:
+ friend class NativeWidgetViewObserver;
+
// Overridden from internal::NativeWidgetAura:
void InitNativeWidget(const views::Widget::InitParams& in_params) override;
void OnWindowVisibilityChanged(aura::Window* window, bool visible) override;
- // ViewObserver:
- void OnViewDestroyed(mus::View* view) override;
- void OnViewBoundsChanged(mus::View* view,
- const mojo::Rect& old_bounds,
- const mojo::Rect& new_bounds) override;
- void OnViewFocusChanged(mus::View* gained_focus,
- mus::View* lost_focus) override;
- void OnViewInputEvent(mus::View* view, const mojo::EventPtr& event) override;
-
scoped_ptr<WindowTreeHostMojo> window_tree_host_;
+ scoped_ptr<NativeWidgetViewObserver> view_observer_;
scoped_ptr<wm::FocusController> focus_client_;
diff --git a/mandoline/ui/omnibox/omnibox_application.cc b/mandoline/ui/omnibox/omnibox_application.cc
index 7c3eb17..7e8fd07 100644
--- a/mandoline/ui/omnibox/omnibox_application.cc
+++ b/mandoline/ui/omnibox/omnibox_application.cc
@@ -6,6 +6,7 @@
#include "base/strings/string16.h"
#include "base/strings/utf_string_conversions.h"
+#include "components/mus/public/cpp/view.h"
#include "components/mus/public/cpp/view_tree_connection.h"
#include "components/mus/public/cpp/view_tree_delegate.h"
#include "components/url_formatter/url_fixer.h"