summaryrefslogtreecommitdiffstats
path: root/ui
diff options
context:
space:
mode:
authorsky <sky@chromium.org>2015-10-23 14:57:13 -0700
committerCommit bot <commit-bot@chromium.org>2015-10-23 21:59:19 +0000
commit683d613678de4d791baeedd6768aabf31b76ce88 (patch)
tree519c8101fa2988bc60acfe4ac6aadb37d98d5fa8 /ui
parent3d017ea8475add1d3c4a544edbbc664eefcc30b0 (diff)
downloadchromium_src-683d613678de4d791baeedd6768aabf31b76ce88.zip
chromium_src-683d613678de4d791baeedd6768aabf31b76ce88.tar.gz
chromium_src-683d613678de4d791baeedd6768aabf31b76ce88.tar.bz2
Gets events working better in views+mus
There were a couple of problems: . capture was getting set to the wrong window. . NativeWidgetMus wasn't forwarding events. . WindowTreeHostMojo wasn't forwarding events either. BUG=none TEST=none R=ben@chromium.org Review URL: https://codereview.chromium.org/1426473002 Cr-Commit-Position: refs/heads/master@{#355896}
Diffstat (limited to 'ui')
-rw-r--r--ui/views/mus/native_widget_mus.cc53
-rw-r--r--ui/views/mus/native_widget_mus.h6
-rw-r--r--ui/views/mus/native_widget_view_manager.cc23
-rw-r--r--ui/views/mus/window_tree_host_mus.cc23
-rw-r--r--ui/views/mus/window_tree_host_mus.h4
-rw-r--r--ui/views/widget/desktop_aura/desktop_native_widget_aura.cc3
6 files changed, 86 insertions, 26 deletions
diff --git a/ui/views/mus/native_widget_mus.cc b/ui/views/mus/native_widget_mus.cc
index 99e3f2b..1d7873b 100644
--- a/ui/views/mus/native_widget_mus.cc
+++ b/ui/views/mus/native_widget_mus.cc
@@ -186,11 +186,11 @@ TooltipManager* NativeWidgetMus::GetTooltipManager() const {
}
void NativeWidgetMus::SetCapture() {
- window_tree_host_->window()->SetCapture();
+ content_->SetCapture();
}
void NativeWidgetMus::ReleaseCapture() {
- window_tree_host_->window()->ReleaseCapture();
+ content_->ReleaseCapture();
}
bool NativeWidgetMus::HasCapture() const {
@@ -539,4 +539,53 @@ void NativeWidgetMus::GetHitTestMask(gfx::Path* mask) const {
native_widget_delegate_->GetHitTestMask(mask);
}
+void NativeWidgetMus::OnKeyEvent(ui::KeyEvent* event) {
+ if (event->is_char()) {
+ // If a ui::InputMethod object is attached to the root window, character
+ // events are handled inside the object and are not passed to this function.
+ // If such object is not attached, character events might be sent (e.g. on
+ // Windows). In this case, we just skip these.
+ return;
+ }
+ // Renderer may send a key event back to us if the key event wasn't handled,
+ // and the window may be invisible by that time.
+ if (!content_->IsVisible())
+ return;
+
+ native_widget_delegate_->OnKeyEvent(event);
+ if (event->handled())
+ return;
+
+ if (GetWidget()->HasFocusManager() &&
+ !GetWidget()->GetFocusManager()->OnKeyEvent(*event))
+ event->SetHandled();
+}
+
+void NativeWidgetMus::OnMouseEvent(ui::MouseEvent* event) {
+ // TODO(sky): forward to tooltipmanager. See NativeWidgetDesktopAura.
+ DCHECK(content_->IsVisible());
+ native_widget_delegate_->OnMouseEvent(event);
+ // WARNING: we may have been deleted.
+}
+
+void NativeWidgetMus::OnScrollEvent(ui::ScrollEvent* event) {
+ if (event->type() == ui::ET_SCROLL) {
+ native_widget_delegate_->OnScrollEvent(event);
+ if (event->handled())
+ return;
+
+ // Convert unprocessed scroll events into wheel events.
+ ui::MouseWheelEvent mwe(*static_cast<ui::ScrollEvent*>(event));
+ native_widget_delegate_->OnMouseEvent(&mwe);
+ if (mwe.handled())
+ event->SetHandled();
+ } else {
+ native_widget_delegate_->OnScrollEvent(event);
+ }
+}
+
+void NativeWidgetMus::OnGestureEvent(ui::GestureEvent* event) {
+ native_widget_delegate_->OnGestureEvent(event);
+}
+
} // namespace views
diff --git a/ui/views/mus/native_widget_mus.h b/ui/views/mus/native_widget_mus.h
index c67863c..f4894e8 100644
--- a/ui/views/mus/native_widget_mus.h
+++ b/ui/views/mus/native_widget_mus.h
@@ -160,6 +160,12 @@ class NativeWidgetMus : public internal::NativeWidgetPrivate,
bool HasHitTestMask() const override;
void GetHitTestMask(gfx::Path* mask) const override;
+ // Overridden from ui::EventHandler:
+ void OnKeyEvent(ui::KeyEvent* event) override;
+ void OnMouseEvent(ui::MouseEvent* event) override;
+ void OnScrollEvent(ui::ScrollEvent* event) override;
+ void OnGestureEvent(ui::GestureEvent* event) override;
+
mus::Window* window_;
mojo::Shell* shell_;
diff --git a/ui/views/mus/native_widget_view_manager.cc b/ui/views/mus/native_widget_view_manager.cc
index 7e0a9f6..1bfd57c 100644
--- a/ui/views/mus/native_widget_view_manager.cc
+++ b/ui/views/mus/native_widget_view_manager.cc
@@ -7,7 +7,6 @@
#include "components/mus/public/cpp/window.h"
#include "components/mus/public/interfaces/window_manager.mojom.h"
#include "mojo/converters/geometry/geometry_type_converters.h"
-#include "mojo/converters/input_events/input_events_type_converters.h"
#include "ui/aura/client/default_capture_client.h"
#include "ui/aura/layout_manager.h"
#include "ui/aura/window.h"
@@ -58,28 +57,6 @@ class NativeWidgetWindowObserver : public mus::WindowObserver {
// NativeWidgetWindowObserver needs to deal, likely by deleting this.
}
- void OnWindowFocusChanged(mus::Window* gained_focus,
- mus::Window* lost_focus) override {
- if (gained_focus == view_manager_->window_)
- view_manager_->window_tree_host_->GetInputMethod()->OnFocus();
- else if (lost_focus == view_manager_->window_)
- view_manager_->window_tree_host_->GetInputMethod()->OnBlur();
- }
-
- void OnWindowInputEvent(mus::Window* 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(NativeWidgetWindowObserver);
diff --git a/ui/views/mus/window_tree_host_mus.cc b/ui/views/mus/window_tree_host_mus.cc
index e9040d8..466299c 100644
--- a/ui/views/mus/window_tree_host_mus.cc
+++ b/ui/views/mus/window_tree_host_mus.cc
@@ -7,6 +7,7 @@
#include "components/mus/public/cpp/window_tree_connection.h"
#include "mojo/application/public/interfaces/shell.mojom.h"
#include "mojo/converters/geometry/geometry_type_converters.h"
+#include "mojo/converters/input_events/input_events_type_converters.h"
#include "ui/aura/env.h"
#include "ui/aura/window.h"
#include "ui/aura/window_event_dispatcher.h"
@@ -116,4 +117,26 @@ void WindowTreeHostMojo::OnWindowBoundsChanged(mus::Window* window,
OnHostResized(new_bounds2.size());
}
+void WindowTreeHostMojo::OnWindowFocusChanged(mus::Window* gained_focus,
+ mus::Window* lost_focus) {
+ if (gained_focus == mus_window_)
+ GetInputMethod()->OnFocus();
+ else if (lost_focus == mus_window_)
+ GetInputMethod()->OnBlur();
+}
+
+void WindowTreeHostMojo::OnWindowInputEvent(mus::Window* 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()) {
+ GetInputMethod()->DispatchKeyEvent(
+ static_cast<ui::KeyEvent*>(ui_event.get()));
+ } else {
+ SendEventToProcessor(ui_event.get());
+ }
+}
+
} // namespace views
diff --git a/ui/views/mus/window_tree_host_mus.h b/ui/views/mus/window_tree_host_mus.h
index 3a10383..a4211c7 100644
--- a/ui/views/mus/window_tree_host_mus.h
+++ b/ui/views/mus/window_tree_host_mus.h
@@ -57,6 +57,10 @@ class WindowTreeHostMojo : public aura::WindowTreeHost,
void OnWindowBoundsChanged(mus::Window* window,
const mojo::Rect& old_bounds,
const mojo::Rect& new_bounds) override;
+ void OnWindowFocusChanged(mus::Window* gained_focus,
+ mus::Window* lost_focus) override;
+ void OnWindowInputEvent(mus::Window* view,
+ const mojo::EventPtr& event) override;
mus::Window* mus_window_;
diff --git a/ui/views/widget/desktop_aura/desktop_native_widget_aura.cc b/ui/views/widget/desktop_aura/desktop_native_widget_aura.cc
index 0bf8d12..ba42e96 100644
--- a/ui/views/widget/desktop_aura/desktop_native_widget_aura.cc
+++ b/ui/views/widget/desktop_aura/desktop_native_widget_aura.cc
@@ -211,7 +211,8 @@ class DesktopNativeWidgetAuraWindowTreeClient :
class FocusManagerEventHandler : public ui::EventHandler {
public:
- FocusManagerEventHandler(DesktopNativeWidgetAura* desktop_native_widget_aura)
+ explicit FocusManagerEventHandler(
+ DesktopNativeWidgetAura* desktop_native_widget_aura)
: desktop_native_widget_aura_(desktop_native_widget_aura) {}
// Implementation of ui::EventHandler: