diff options
author | ben@chromium.org <ben@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-09-11 19:22:55 +0000 |
---|---|---|
committer | ben@chromium.org <ben@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-09-11 19:22:55 +0000 |
commit | d789d6d70ea30397ec2e8d5c123f63db52c3139c (patch) | |
tree | 7a701828ed42736ef5dbc7299f0c024139e716e4 /ui | |
parent | 8638758a1d03dd50a51d1e8c3da2725943fa442c (diff) | |
download | chromium_src-d789d6d70ea30397ec2e8d5c123f63db52c3139c.zip chromium_src-d789d6d70ea30397ec2e8d5c123f63db52c3139c.tar.gz chromium_src-d789d6d70ea30397ec2e8d5c123f63db52c3139c.tar.bz2 |
Get mouse events to work with win aura, and make the combobox function in the views examples app.
http://crbug.com/146077
R=sky@chromium.org
Committed: https://src.chromium.org/viewvc/chrome?view=rev&revision=155832
Review URL: https://chromiumcodereview.appspot.com/10910144
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@156096 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'ui')
-rw-r--r-- | ui/views/controls/menu/menu_host.cc | 9 | ||||
-rw-r--r-- | ui/views/views.gyp | 2 | ||||
-rw-r--r-- | ui/views/widget/desktop_capture_client.cc | 44 | ||||
-rw-r--r-- | ui/views/widget/desktop_capture_client.h | 3 | ||||
-rw-r--r-- | ui/views/widget/desktop_native_widget_aura.cc | 34 | ||||
-rw-r--r-- | ui/views/widget/desktop_root_window_host.h | 10 | ||||
-rw-r--r-- | ui/views/widget/desktop_root_window_host_linux.cc | 28 | ||||
-rw-r--r-- | ui/views/widget/desktop_root_window_host_linux.h | 5 | ||||
-rw-r--r-- | ui/views/widget/desktop_root_window_host_win.cc | 51 | ||||
-rw-r--r-- | ui/views/widget/desktop_root_window_host_win.h | 16 | ||||
-rw-r--r-- | ui/views/win/hwnd_message_handler.h | 2 |
11 files changed, 193 insertions, 11 deletions
diff --git a/ui/views/controls/menu/menu_host.cc b/ui/views/controls/menu/menu_host.cc index a9f2f7f..e1cd8d9 100644 --- a/ui/views/controls/menu/menu_host.cc +++ b/ui/views/controls/menu/menu_host.cc @@ -12,6 +12,11 @@ #include "ui/views/widget/native_widget_private.h" #include "ui/views/widget/widget.h" +#if defined(USE_AURA) +#include "base/command_line.h" +#include "ui/views/widget/desktop_native_widget_aura.h" +#endif + namespace views { //////////////////////////////////////////////////////////////////////////////// @@ -34,6 +39,10 @@ void MenuHost::InitMenuHost(Widget* parent, params.has_dropshadow = true; params.parent_widget = parent; params.bounds = bounds; +#if defined(USE_AURA) && !defined(OS_CHROMEOS) + if (CommandLine::ForCurrentProcess()->HasSwitch("win-aura")) + params.native_widget = new DesktopNativeWidgetAura(this); +#endif Init(params); SetContentsView(contents_view); ShowMenuHost(do_capture); diff --git a/ui/views/views.gyp b/ui/views/views.gyp index b61bbe2..bfe5864 100644 --- a/ui/views/views.gyp +++ b/ui/views/views.gyp @@ -313,6 +313,8 @@ 'widget/child_window_message_processor.h', 'widget/default_theme_provider.cc', 'widget/default_theme_provider.h', + 'widget/desktop_capture_client.cc', + 'widget/desktop_capture_client.h', 'widget/desktop_native_widget_aura.cc', 'widget/desktop_native_widget_aura.h', 'widget/desktop_native_widget_helper_aura.cc', diff --git a/ui/views/widget/desktop_capture_client.cc b/ui/views/widget/desktop_capture_client.cc new file mode 100644 index 0000000..2c7cc6a --- /dev/null +++ b/ui/views/widget/desktop_capture_client.cc @@ -0,0 +1,44 @@ +// Copyright (c) 2012 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 "ui/views/widget/desktop_capture_client.h" + +#include "ui/aura/root_window.h" +#include "ui/aura/window.h" + +namespace views { + +DesktopCaptureClient::DesktopCaptureClient() : capture_window_(NULL) { +} + +DesktopCaptureClient::~DesktopCaptureClient() { +} + +void DesktopCaptureClient::SetCapture(aura::Window* window) { + if (window) { + DCHECK(window->GetRootWindow()); + if (capture_window_) + DCHECK_EQ(window->GetRootWindow(), capture_window_->GetRootWindow()); + } + + aura::Window* old_capture = capture_window_; + capture_window_ = window; + + aura::RootWindow* root_window = window ? window->GetRootWindow() : + capture_window_ ? capture_window_->GetRootWindow() : NULL; + if (root_window) + root_window->UpdateCapture(old_capture, window); +} + +void DesktopCaptureClient::ReleaseCapture(aura::Window* window) { + if (capture_window_ != window) + return; + SetCapture(NULL); +} + +aura::Window* DesktopCaptureClient::GetCaptureWindow() { + return capture_window_; +} + +} // namespace views diff --git a/ui/views/widget/desktop_capture_client.h b/ui/views/widget/desktop_capture_client.h index 3371140..0e8a945 100644 --- a/ui/views/widget/desktop_capture_client.h +++ b/ui/views/widget/desktop_capture_client.h @@ -8,10 +8,11 @@ #include "base/basictypes.h" #include "base/compiler_specific.h" #include "ui/aura/client/capture_client.h" +#include "ui/views/views_export.h" namespace views { -class DesktopCaptureClient : public aura::client::CaptureClient { +class VIEWS_EXPORT DesktopCaptureClient : public aura::client::CaptureClient { public: DesktopCaptureClient(); virtual ~DesktopCaptureClient(); diff --git a/ui/views/widget/desktop_native_widget_aura.cc b/ui/views/widget/desktop_native_widget_aura.cc index fb750d7f..56f972b 100644 --- a/ui/views/widget/desktop_native_widget_aura.cc +++ b/ui/views/widget/desktop_native_widget_aura.cc @@ -4,8 +4,10 @@ #include "ui/views/widget/desktop_native_widget_aura.h" +#include "ui/aura/root_window_host.h" #include "ui/aura/window.h" #include "ui/base/hit_test.h" +#include "ui/compositor/layer.h" #include "ui/views/widget/desktop_root_window_host.h" namespace views { @@ -68,11 +70,11 @@ Widget* DesktopNativeWidgetAura::GetTopLevelWidget() { } const ui::Compositor* DesktopNativeWidgetAura::GetCompositor() const { - return NULL; + return window_->layer()->GetCompositor(); } ui::Compositor* DesktopNativeWidgetAura::GetCompositor() { - return NULL; + return window_->layer()->GetCompositor(); } void DesktopNativeWidgetAura::CalculateOffsetToAncestorWithLayer( @@ -157,7 +159,7 @@ gfx::Rect DesktopNativeWidgetAura::GetWindowBoundsInScreen() const { } gfx::Rect DesktopNativeWidgetAura::GetClientAreaBoundsInScreen() const { - return gfx::Rect(100, 100); + return desktop_root_window_host_->GetClientAreaBoundsInScreen(); } gfx::Rect DesktopNativeWidgetAura::GetRestoredBounds() const { @@ -183,15 +185,19 @@ void DesktopNativeWidgetAura::SetShape(gfx::NativeRegion shape) { } void DesktopNativeWidgetAura::Close() { + desktop_root_window_host_->Close(); } void DesktopNativeWidgetAura::CloseNow() { + desktop_root_window_host_->CloseNow(); } void DesktopNativeWidgetAura::Show() { + desktop_root_window_host_->AsRootWindowHost()->Show(); } void DesktopNativeWidgetAura::Hide() { + desktop_root_window_host_->AsRootWindowHost()->Hide(); } void DesktopNativeWidgetAura::ShowMaximizedWithBounds( @@ -203,7 +209,7 @@ void DesktopNativeWidgetAura::ShowWithWindowState(ui::WindowShowState state) { } bool DesktopNativeWidgetAura::IsVisible() const { - return false; + return desktop_root_window_host_->IsVisible(); } void DesktopNativeWidgetAura::Activate() { @@ -263,6 +269,8 @@ void DesktopNativeWidgetAura::RunShellDrag(View* view, } void DesktopNativeWidgetAura::SchedulePaintInRect(const gfx::Rect& rect) { + if (window_) + window_->SchedulePaintInRect(rect); } void DesktopNativeWidgetAura::SetCursor(gfx::NativeCursor cursor) { @@ -369,7 +377,23 @@ ui::EventResult DesktopNativeWidgetAura::OnKeyEvent(ui::KeyEvent* event) { } ui::EventResult DesktopNativeWidgetAura::OnMouseEvent(ui::MouseEvent* event) { - return ui::ER_UNHANDLED; + DCHECK(window_->IsVisible()); + if (event->type() == ui::ET_MOUSEWHEEL) { + return native_widget_delegate_->OnMouseEvent(*event) ? + ui::ER_HANDLED : ui::ER_UNHANDLED; + } + + if (event->type() == ui::ET_SCROLL) { + if (native_widget_delegate_->OnMouseEvent(*event)) + return ui::ER_HANDLED; + + // Convert unprocessed scroll events into wheel events. + ui::MouseWheelEvent mwe(*static_cast<ui::ScrollEvent*>(event)); + return native_widget_delegate_->OnMouseEvent(mwe) ? + ui::ER_HANDLED : ui::ER_UNHANDLED; + } + return native_widget_delegate_->OnMouseEvent(*event) ? + ui::ER_HANDLED : ui::ER_UNHANDLED; } ui::TouchStatus DesktopNativeWidgetAura::OnTouchEvent(ui::TouchEvent* event) { diff --git a/ui/views/widget/desktop_root_window_host.h b/ui/views/widget/desktop_root_window_host.h index 84e133f..eaf643a 100644 --- a/ui/views/widget/desktop_root_window_host.h +++ b/ui/views/widget/desktop_root_window_host.h @@ -9,6 +9,7 @@ #include "ui/views/widget/widget.h" namespace aura { +class RootWindowHost; class Window; } @@ -32,7 +33,16 @@ class DesktopRootWindowHost { virtual void Init(aura::Window* content_window, const Widget::InitParams& params) = 0; + virtual void Close() = 0; + virtual void CloseNow() = 0; + + virtual aura::RootWindowHost* AsRootWindowHost() = 0; + virtual void ShowWindowWithState(ui::WindowShowState show_state) = 0; + + virtual bool IsVisible() const = 0; + + virtual gfx::Rect GetClientAreaBoundsInScreen() const = 0; }; } // namespace views diff --git a/ui/views/widget/desktop_root_window_host_linux.cc b/ui/views/widget/desktop_root_window_host_linux.cc index bef2cff..3f54d8b 100644 --- a/ui/views/widget/desktop_root_window_host_linux.cc +++ b/ui/views/widget/desktop_root_window_host_linux.cc @@ -26,12 +26,40 @@ void DesktopRootWindowHostLinux::Init(aura::Window* content_window, NOTIMPLEMENTED(); } +void DesktopRootWindowHostLinux::Close() { + // TODO(erg): + NOTIMPLEMENTED(); +} + +void DesktopRootWindowHostLinux::CloseNow() { + // TODO(erg): + NOTIMPLEMENTED(); +} + +aura::RootWindowHost* DesktopRootWindowHostLinux::AsRootWindowHost() { + // TODO(erg): + NOTIMPLEMENTED(); + return NULL; +} + void DesktopRootWindowHostLinux::ShowWindowWithState( ui::WindowShowState show_state) { // TODO(erg): NOTIMPLEMENTED(); } +bool DesktopRootWindowHostLinux::IsVisible() const { + // TODO(erg): + NOTIMPLEMENTED(); + return true; +} + +gfx::Rect DesktopRootWindowHostLinux::GetClientAreaBoundsInScreen() const { + // TODO(erg): + NOTIMPLEMENTED(); + return gfx::Rect(100, 100); +} + //////////////////////////////////////////////////////////////////////////////// // DesktopRootWindowHost, public: diff --git a/ui/views/widget/desktop_root_window_host_linux.h b/ui/views/widget/desktop_root_window_host_linux.h index d546345..c3a2e2c 100644 --- a/ui/views/widget/desktop_root_window_host_linux.h +++ b/ui/views/widget/desktop_root_window_host_linux.h @@ -19,7 +19,12 @@ class DesktopRootWindowHostLinux : public DesktopRootWindowHost { // Overridden from DesktopRootWindowHost: virtual void Init(aura::Window* content_window, const Widget::InitParams& params) OVERRIDE; + virtual void Close() OVERRIDE; + virtual void CloseNow() OVERRIDE; + virtual aura::RootWindowHost* AsRootWindowHost() OVERRIDE; virtual void ShowWindowWithState(ui::WindowShowState show_state) OVERRIDE; + virtual bool IsVisible() const OVERRIDE; + virtual gfx::Rect GetClientAreaBoundsInScreen() const OVERRIDE; DISALLOW_COPY_AND_ASSIGN(DesktopRootWindowHostLinux); }; diff --git a/ui/views/widget/desktop_root_window_host_win.cc b/ui/views/widget/desktop_root_window_host_win.cc index b68b3a3..a834ec18 100644 --- a/ui/views/widget/desktop_root_window_host_win.cc +++ b/ui/views/widget/desktop_root_window_host_win.cc @@ -4,7 +4,11 @@ #include "ui/views/widget/desktop_root_window_host_win.h" +#include "ui/aura/desktop/desktop_activation_client.h" +#include "ui/aura/desktop/desktop_dispatcher_client.h" +#include "ui/aura/focus_manager.h" #include "ui/aura/root_window.h" +#include "ui/views/widget/desktop_capture_client.h" #include "ui/views/win/hwnd_message_handler.h" namespace views { @@ -40,6 +44,35 @@ void DesktopRootWindowHostWin::Init(aura::Window* content_window, root_window_->Init(); root_window_->AddChild(content_window_); root_window_host_delegate_ = root_window_.get(); + + native_widget_delegate_->OnNativeWidgetCreated(); + + capture_client_.reset(new DesktopCaptureClient); + aura::client::SetCaptureClient(root_window_.get(), capture_client_.get()); + + focus_manager_.reset(new aura::FocusManager); + root_window_->set_focus_manager(focus_manager_.get()); + + activation_client_.reset( + new aura::DesktopActivationClient(root_window_->GetFocusManager())); + aura::client::SetActivationClient(root_window_.get(), + activation_client_.get()); + + dispatcher_client_.reset(new aura::DesktopDispatcherClient); + aura::client::SetDispatcherClient(root_window_.get(), + dispatcher_client_.get()); +} + +void DesktopRootWindowHostWin::Close() { + message_handler_->Close(); +} + +void DesktopRootWindowHostWin::CloseNow() { + message_handler_->CloseNow(); +} + +aura::RootWindowHost* DesktopRootWindowHostWin::AsRootWindowHost() { + return this; } void DesktopRootWindowHostWin::ShowWindowWithState( @@ -47,6 +80,14 @@ void DesktopRootWindowHostWin::ShowWindowWithState( message_handler_->ShowWindowWithState(show_state); } +bool DesktopRootWindowHostWin::IsVisible() const { + return message_handler_->IsVisible(); +} + +gfx::Rect DesktopRootWindowHostWin::GetClientAreaBoundsInScreen() const { + return message_handler_->GetClientAreaBoundsInScreen(); +} + //////////////////////////////////////////////////////////////////////////////// // DesktopRootWindowHostWin, RootWindowHost implementation: @@ -59,9 +100,11 @@ gfx::AcceleratedWidget DesktopRootWindowHostWin::GetAcceleratedWidget() { } void DesktopRootWindowHostWin::Show() { + message_handler_->Show(); } void DesktopRootWindowHostWin::Hide() { + message_handler_->Hide(); } void DesktopRootWindowHostWin::ToggleFullScreen() { @@ -254,8 +297,6 @@ void DesktopRootWindowHostWin::HandleCreate() { // 2. MouseWheel. // 3. Drop target. // 4. Tooltip Manager. - - native_widget_delegate_->OnNativeWidgetCreated(); } void DesktopRootWindowHostWin::HandleDestroying() { @@ -289,7 +330,8 @@ void DesktopRootWindowHostWin::HandleVisibilityChanged(bool visible) { void DesktopRootWindowHostWin::HandleClientSizeChanged( const gfx::Size& new_size) { - root_window_host_delegate_->OnHostResized(new_size); + if (root_window_host_delegate_) + root_window_host_delegate_->OnHostResized(new_size); // TODO(beng): replace with a layout manager?? content_window_->SetBounds(gfx::Rect(new_size)); } @@ -304,7 +346,8 @@ void DesktopRootWindowHostWin::HandleNativeBlur(HWND focused_window) { } bool DesktopRootWindowHostWin::HandleMouseEvent(const ui::MouseEvent& event) { - return false; + return root_window_host_delegate_->OnHostMouseEvent( + const_cast<ui::MouseEvent*>(&event)); } bool DesktopRootWindowHostWin::HandleKeyEvent(const ui::KeyEvent& event) { diff --git a/ui/views/widget/desktop_root_window_host_win.h b/ui/views/widget/desktop_root_window_host_win.h index 9293aea..c2cf93e 100644 --- a/ui/views/widget/desktop_root_window_host_win.h +++ b/ui/views/widget/desktop_root_window_host_win.h @@ -9,7 +9,14 @@ #include "ui/views/widget/desktop_root_window_host.h" #include "ui/views/win/hwnd_message_handler_delegate.h" +namespace aura { +class DesktopActivationClient; +class DesktopDispatcherClient; +class FocusManager; +} + namespace views { +class DesktopCaptureClient; class HWNDMessageHandler; class DesktopRootWindowHostWin : public DesktopRootWindowHost, @@ -25,7 +32,12 @@ class DesktopRootWindowHostWin : public DesktopRootWindowHost, // Overridden from DesktopRootWindowHost: virtual void Init(aura::Window* content_window, const Widget::InitParams& params) OVERRIDE; + virtual void Close() OVERRIDE; + virtual void CloseNow() OVERRIDE; + virtual aura::RootWindowHost* AsRootWindowHost() OVERRIDE; virtual void ShowWindowWithState(ui::WindowShowState show_state) OVERRIDE; + virtual bool IsVisible() const OVERRIDE; + virtual gfx::Rect GetClientAreaBoundsInScreen() const OVERRIDE; // Overridden from aura::RootWindowHost: virtual aura::RootWindow* GetRootWindow() OVERRIDE; @@ -128,6 +140,10 @@ class DesktopRootWindowHostWin : public DesktopRootWindowHost, scoped_ptr<aura::RootWindow> root_window_; scoped_ptr<HWNDMessageHandler> message_handler_; + scoped_ptr<DesktopCaptureClient> capture_client_; + scoped_ptr<aura::DesktopActivationClient> activation_client_; + scoped_ptr<aura::DesktopDispatcherClient> dispatcher_client_; + scoped_ptr<aura::FocusManager> focus_manager_; // TODO(beng): Consider providing an interface to DesktopNativeWidgetAura // instead of providing this route back to Widget. diff --git a/ui/views/win/hwnd_message_handler.h b/ui/views/win/hwnd_message_handler.h index 7f73b2b..b573582 100644 --- a/ui/views/win/hwnd_message_handler.h +++ b/ui/views/win/hwnd_message_handler.h @@ -229,7 +229,7 @@ class VIEWS_EXPORT HWNDMessageHandler : public ui::WindowImpl, // Message Handlers ---------------------------------------------------------- - BEGIN_MSG_MAP_EX(NativeWidgetWin) + BEGIN_MSG_MAP_EX(HWNDMessageHandler) // Range handlers must go first! MESSAGE_RANGE_HANDLER_EX(WM_MOUSEFIRST, WM_MOUSELAST, OnMouseRange) MESSAGE_RANGE_HANDLER_EX(WM_NCMOUSEMOVE, WM_NCXBUTTONDBLCLK, OnMouseRange) |