Commit d30e9dd0 authored by sadrul@chromium.org's avatar sadrul@chromium.org

aura: Use PlatformWindow from WindowTreeHostWin.

With this patch, both Windows and Ozone implementations use PlatformWindow for
interacting with the native windowing system. Eventually, the X11 implementations
will also use this, and WindowTreeHost will have a single implementation on all
platforms.

BUG=none
R=ben@chromium.org

Previously landed in r284850, but reverted in r284905 because it broke a multi-
window ash unit-test on Windows. The test is now disabled (r284931).

Review URL: https://codereview.chromium.org/400413002

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@284986 0039d316-1c4b-4281-b951-d872f2087c98
parent 26efe319
......@@ -1031,6 +1031,7 @@
'dependencies': [
'../ipc/ipc.gyp:ipc',
'../ui/metro_viewer/metro_viewer.gyp:metro_viewer_messages',
'../ui/platform_window/win/win_window.gyp:win_window',
'../win8/win8.gyp:metro_viewer',
'../win8/win8.gyp:test_support_win8',
'../win8/win8_tests.gyp:test_registrar',
......
......@@ -44,6 +44,7 @@
#include "base/win/windows_version.h"
#include "ui/aura/remote_window_tree_host_win.h"
#include "ui/aura/window_tree_host_win.h"
#include "ui/platform_window/win/win_window.h"
#include "win8/test/test_registrar_constants.h"
#endif
......@@ -123,7 +124,7 @@ void AshTestBase::SetUp() {
switches::kAshHostWindowBounds, "1+1-800x600");
}
#if defined(OS_WIN)
aura::test::SetUsePopupAsRootWindowForTest(true);
ui::test::SetUsePopupAsRootWindowForTest(true);
#endif
ash_test_helper_->SetUp(start_session_);
......@@ -173,7 +174,7 @@ void AshTestBase::TearDown() {
ash_test_helper_->TearDown();
#if defined(OS_WIN)
aura::test::SetUsePopupAsRootWindowForTest(false);
ui::test::SetUsePopupAsRootWindowForTest(false);
// Kill the viewer process if we spun one up.
metro_viewer_host_.reset();
......
......@@ -81,6 +81,8 @@ class NativeViewportOzone : public NativeViewport,
delegate_->OnAcceleratedWidgetAvailable(widget);
}
virtual void OnActivationChanged(bool active) OVERRIDE {}
scoped_ptr<ui::PlatformWindow> platform_window_;
NativeViewportDelegate* delegate_;
......
......@@ -89,6 +89,8 @@ class NativeViewportWin : public NativeViewport,
delegate_->OnAcceleratedWidgetAvailable(widget);
}
virtual void OnActivationChanged(bool active) OVERRIDE {}
scoped_ptr<ui::PlatformWindow> platform_window_;
NativeViewportDelegate* delegate_;
......
......@@ -102,6 +102,8 @@ class NativeViewportX11 : public NativeViewport,
delegate_->OnAcceleratedWidgetAvailable(widget);
}
virtual void OnActivationChanged(bool active) OVERRIDE {}
scoped_ptr<ui::PlatformEventSource> event_source_;
scoped_ptr<ui::PlatformWindow> platform_window_;
NativeViewportDelegate* delegate_;
......
......@@ -124,6 +124,7 @@
['OS=="win"', {
'dependencies': [
'../metro_viewer/metro_viewer.gyp:metro_viewer_messages',
'../platform_window/win/win_window.gyp:win_window',
'../../ipc/ipc.gyp:ipc',
],
'sources!': [
......
......@@ -56,6 +56,9 @@ void WindowTreeHostOzone::OnAcceleratedWidgetAvailable(
CreateCompositor(widget_);
}
void WindowTreeHostOzone::OnActivationChanged(bool active) {
}
ui::EventSource* WindowTreeHostOzone::GetEventSource() {
return this;
}
......
......@@ -35,6 +35,7 @@ class AURA_EXPORT WindowTreeHostOzone : public WindowTreeHost,
virtual void OnLostCapture() OVERRIDE;
virtual void OnAcceleratedWidgetAvailable(
gfx::AcceleratedWidget widget) OVERRIDE;
virtual void OnActivationChanged(bool active) OVERRIDE;
// WindowTreeHost:
virtual ui::EventSource* GetEventSource() OVERRIDE;
......
......@@ -17,7 +17,9 @@
#include "ui/events/event.h"
#include "ui/gfx/display.h"
#include "ui/gfx/insets.h"
#include "ui/gfx/native_widget_types.h"
#include "ui/gfx/screen.h"
#include "ui/platform_window/win/win_window.h"
using std::max;
using std::min;
......@@ -41,18 +43,15 @@ gfx::Size WindowTreeHost::GetNativeScreenSize() {
}
WindowTreeHostWin::WindowTreeHostWin(const gfx::Rect& bounds)
: has_capture_(false) {
if (use_popup_as_root_window_for_test)
set_window_style(WS_POPUP);
Init(NULL, bounds);
SetWindowText(hwnd(), L"aura::RootWindow!");
CreateCompositor(GetAcceleratedWidget());
: has_capture_(false),
widget_(gfx::kNullAcceleratedWidget),
window_(new ui::WinWindow(this, bounds)) {
}
WindowTreeHostWin::~WindowTreeHostWin() {
DestroyCompositor();
DestroyDispatcher();
DestroyWindow(hwnd());
window_.reset();
}
ui::EventSource* WindowTreeHostWin::GetEventSource() {
......@@ -60,70 +59,39 @@ ui::EventSource* WindowTreeHostWin::GetEventSource() {
}
gfx::AcceleratedWidget WindowTreeHostWin::GetAcceleratedWidget() {
return hwnd();
return widget_;
}
void WindowTreeHostWin::Show() {
ShowWindow(hwnd(), SW_SHOWNORMAL);
window_->Show();
}
void WindowTreeHostWin::Hide() {
NOTIMPLEMENTED();
window_->Hide();
}
gfx::Rect WindowTreeHostWin::GetBounds() const {
RECT r;
GetClientRect(hwnd(), &r);
return gfx::Rect(r);
return window_->GetBounds();
}
void WindowTreeHostWin::SetBounds(const gfx::Rect& bounds) {
RECT window_rect;
window_rect.left = bounds.x();
window_rect.top = bounds.y();
window_rect.right = bounds.right() ;
window_rect.bottom = bounds.bottom();
AdjustWindowRectEx(&window_rect,
GetWindowLong(hwnd(), GWL_STYLE),
FALSE,
GetWindowLong(hwnd(), GWL_EXSTYLE));
SetWindowPos(
hwnd(),
NULL,
window_rect.left,
window_rect.top,
window_rect.right - window_rect.left,
window_rect.bottom - window_rect.top,
SWP_NOMOVE | SWP_NOOWNERZORDER | SWP_NOREDRAW | SWP_NOREPOSITION);
// Explicity call OnHostResized when the scale has changed because
// the window size may not have changed.
float current_scale = compositor()->device_scale_factor();
float new_scale = gfx::Screen::GetScreenFor(window())->
GetDisplayNearestWindow(window()).device_scale_factor();
if (current_scale != new_scale)
OnHostResized(bounds.size());
window_->SetBounds(bounds);
}
gfx::Point WindowTreeHostWin::GetLocationOnNativeScreen() const {
RECT r;
GetClientRect(hwnd(), &r);
return gfx::Point(r.left, r.top);
return window_->GetBounds().origin();
}
void WindowTreeHostWin::SetCapture() {
if (!has_capture_) {
has_capture_ = true;
::SetCapture(hwnd());
window_->SetCapture();
}
}
void WindowTreeHostWin::ReleaseCapture() {
if (has_capture_) {
has_capture_ = false;
::ReleaseCapture();
}
if (has_capture_)
window_->ReleaseCapture();
}
void WindowTreeHostWin::SetCursorNative(gfx::NativeCursor native_cursor) {
......@@ -146,88 +114,60 @@ void WindowTreeHostWin::OnCursorVisibilityChangedNative(bool show) {
void WindowTreeHostWin::PostNativeEvent(const base::NativeEvent& native_event) {
::PostMessage(
hwnd(), native_event.message, native_event.wParam, native_event.lParam);
widget_, native_event.message, native_event.wParam, native_event.lParam);
}
ui::EventProcessor* WindowTreeHostWin::GetEventProcessor() {
return dispatcher();
}
void WindowTreeHostWin::OnClose() {
// TODO: this obviously shouldn't be here.
base::MessageLoopForUI::current()->Quit();
void WindowTreeHostWin::OnBoundsChanged(const gfx::Rect& new_bounds) {
gfx::Rect old_bounds = bounds_;
bounds_ = new_bounds;
if (bounds_.origin() != old_bounds.origin())
OnHostMoved(bounds_.origin());
if (bounds_.size() != old_bounds.size())
OnHostResized(bounds_.size());
}
LRESULT WindowTreeHostWin::OnKeyEvent(UINT message,
WPARAM w_param,
LPARAM l_param) {
MSG msg = { hwnd(), message, w_param, l_param };
ui::KeyEvent keyev(msg, message == WM_CHAR);
ui::EventDispatchDetails details = SendEventToProcessor(&keyev);
SetMsgHandled(keyev.handled() || details.dispatcher_destroyed);
return 0;
}
LRESULT WindowTreeHostWin::OnMouseRange(UINT message,
WPARAM w_param,
LPARAM l_param) {
MSG msg = { hwnd(), message, w_param, l_param, 0,
{ CR_GET_X_LPARAM(l_param), CR_GET_Y_LPARAM(l_param) } };
ui::MouseEvent event(msg);
bool handled = false;
if (!(event.flags() & ui::EF_IS_NON_CLIENT)) {
ui::EventDispatchDetails details = SendEventToProcessor(&event);
handled = event.handled() || details.dispatcher_destroyed;
}
SetMsgHandled(handled);
return 0;
void WindowTreeHostWin::OnDamageRect(const gfx::Rect& damage_rect) {
compositor()->ScheduleRedrawRect(damage_rect);
}
LRESULT WindowTreeHostWin::OnCaptureChanged(UINT message,
WPARAM w_param,
LPARAM l_param) {
if (has_capture_) {
has_capture_ = false;
OnHostLostWindowCapture();
}
return 0;
void WindowTreeHostWin::DispatchEvent(ui::Event* event) {
ui::EventDispatchDetails details = SendEventToProcessor(event);
if (details.dispatcher_destroyed)
event->SetHandled();
}
LRESULT WindowTreeHostWin::OnNCActivate(UINT message,
WPARAM w_param,
LPARAM l_param) {
if (!!w_param)
OnHostActivated();
return DefWindowProc(hwnd(), message, w_param, l_param);
void WindowTreeHostWin::OnCloseRequest() {
// TODO: this obviously shouldn't be here.
base::MessageLoopForUI::current()->Quit();
}
void WindowTreeHostWin::OnMove(const gfx::Point& point) {
OnHostMoved(point);
void WindowTreeHostWin::OnClosed() {
}
void WindowTreeHostWin::OnPaint(HDC dc) {
gfx::Rect damage_rect;
RECT update_rect = {0};
if (GetUpdateRect(hwnd(), &update_rect, FALSE))
damage_rect = gfx::Rect(update_rect);
compositor()->ScheduleRedrawRect(damage_rect);
ValidateRect(hwnd(), NULL);
void WindowTreeHostWin::OnWindowStateChanged(
ui::PlatformWindowState new_state) {
}
void WindowTreeHostWin::OnSize(UINT param, const gfx::Size& size) {
// Minimizing resizes the window to 0x0 which causes our layout to go all
// screwy, so we just ignore it.
if (dispatcher() && param != SIZE_MINIMIZED)
OnHostResized(size);
void WindowTreeHostWin::OnLostCapture() {
if (has_capture_) {
has_capture_ = false;
OnHostLostWindowCapture();
}
}
namespace test {
// static
void SetUsePopupAsRootWindowForTest(bool use) {
use_popup_as_root_window_for_test = use;
void WindowTreeHostWin::OnAcceleratedWidgetAvailable(
gfx::AcceleratedWidget widget) {
widget_ = widget;
CreateCompositor(widget);
}
} // namespace test
void WindowTreeHostWin::OnActivationChanged(bool active) {
if (active)
OnHostActivated();
}
} // namespace aura
......@@ -6,19 +6,23 @@
#define UI_AURA_WINDOW_TREE_HOST_WIN_H_
#include "base/compiler_specific.h"
#include "base/memory/scoped_ptr.h"
#include "ui/aura/aura_export.h"
#include "ui/aura/window_tree_host.h"
#include "ui/events/event_source.h"
#include "ui/gfx/win/window_impl.h"
#include "ui/platform_window/platform_window.h"
#include "ui/platform_window/platform_window_delegate.h"
namespace aura {
class AURA_EXPORT WindowTreeHostWin : public WindowTreeHost,
public ui::EventSource,
public gfx::WindowImpl {
class AURA_EXPORT WindowTreeHostWin
: public WindowTreeHost,
public ui::EventSource,
public NON_EXPORTED_BASE(ui::PlatformWindowDelegate) {
public:
explicit WindowTreeHostWin(const gfx::Rect& bounds);
virtual ~WindowTreeHostWin();
// WindowTreeHost:
virtual ui::EventSource* GetEventSource() OVERRIDE;
virtual gfx::AcceleratedWidget GetAcceleratedWidget() OVERRIDE;
......@@ -37,56 +41,30 @@ class AURA_EXPORT WindowTreeHostWin : public WindowTreeHost,
// ui::EventSource:
virtual ui::EventProcessor* GetEventProcessor() OVERRIDE;
private:
CR_BEGIN_MSG_MAP_EX(WindowTreeHostWin)
// Range handlers must go first!
CR_MESSAGE_RANGE_HANDLER_EX(WM_MOUSEFIRST, WM_MOUSELAST, OnMouseRange)
CR_MESSAGE_RANGE_HANDLER_EX(WM_NCMOUSEMOVE,
WM_NCXBUTTONDBLCLK,
OnMouseRange)
// Mouse capture events.
CR_MESSAGE_HANDLER_EX(WM_CAPTURECHANGED, OnCaptureChanged)
// Key events.
CR_MESSAGE_HANDLER_EX(WM_KEYDOWN, OnKeyEvent)
CR_MESSAGE_HANDLER_EX(WM_KEYUP, OnKeyEvent)
CR_MESSAGE_HANDLER_EX(WM_SYSKEYDOWN, OnKeyEvent)
CR_MESSAGE_HANDLER_EX(WM_SYSKEYUP, OnKeyEvent)
CR_MESSAGE_HANDLER_EX(WM_CHAR, OnKeyEvent)
CR_MESSAGE_HANDLER_EX(WM_SYSCHAR, OnKeyEvent)
CR_MESSAGE_HANDLER_EX(WM_IME_CHAR, OnKeyEvent)
CR_MESSAGE_HANDLER_EX(WM_NCACTIVATE, OnNCActivate)
CR_MSG_WM_CLOSE(OnClose)
CR_MSG_WM_MOVE(OnMove)
CR_MSG_WM_PAINT(OnPaint)
CR_MSG_WM_SIZE(OnSize)
CR_END_MSG_MAP()
protected:
gfx::AcceleratedWidget hwnd() const { return widget_; }
void OnClose();
LRESULT OnKeyEvent(UINT message, WPARAM w_param, LPARAM l_param);
LRESULT OnMouseRange(UINT message, WPARAM w_param, LPARAM l_param);
LRESULT OnCaptureChanged(UINT message, WPARAM w_param, LPARAM l_param);
LRESULT OnNCActivate(UINT message, WPARAM w_param, LPARAM l_param);
void OnMove(const gfx::Point& point);
void OnPaint(HDC dc);
void OnSize(UINT param, const gfx::Size& size);
private:
// ui::PlatformWindowDelegate:
virtual void OnBoundsChanged(const gfx::Rect& new_bounds) OVERRIDE;
virtual void OnDamageRect(const gfx::Rect& damaged_region) OVERRIDE;
virtual void DispatchEvent(ui::Event* event) OVERRIDE;
virtual void OnCloseRequest() OVERRIDE;
virtual void OnClosed() OVERRIDE;
virtual void OnWindowStateChanged(ui::PlatformWindowState new_state) OVERRIDE;
virtual void OnLostCapture() OVERRIDE;
virtual void OnAcceleratedWidgetAvailable(
gfx::AcceleratedWidget widget) OVERRIDE;
virtual void OnActivationChanged(bool active) OVERRIDE;
bool has_capture_;
gfx::Rect bounds_;
gfx::AcceleratedWidget widget_;
scoped_ptr<ui::PlatformWindow> window_;
DISALLOW_COPY_AND_ASSIGN(WindowTreeHostWin);
};
namespace test {
// Set true to let WindowTreeHostWin use a popup window
// with no frame/title so that the window size and test's
// expectations matches.
AURA_EXPORT void SetUsePopupAsRootWindowForTest(bool use);
} // namespace
} // namespace aura
#endif // UI_AURA_WINDOW_TREE_HOST_WIN_H_
......@@ -48,6 +48,7 @@ class DemoWindow : public ui::PlatformWindowDelegate {
CHECK_NE(widget, gfx::kNullAcceleratedWidget);
widget_ = widget;
}
virtual void OnActivationChanged(bool active) OVERRIDE {}
private:
scoped_ptr<ui::PlatformWindow> platform_window_;
......
......@@ -44,6 +44,8 @@ class PlatformWindowDelegate {
virtual void OnLostCapture() = 0;
virtual void OnAcceleratedWidgetAvailable(gfx::AcceleratedWidget widget) = 0;
virtual void OnActivationChanged(bool active) = 0;
};
} // namespace ui
......
......@@ -13,6 +13,8 @@ namespace ui {
namespace {
bool use_popup_as_root_window_for_test = false;
gfx::Rect GetWindowBoundsForClientBounds(DWORD style, DWORD ex_style,
const gfx::Rect& bounds) {
RECT wr;
......@@ -37,6 +39,8 @@ WinWindow::WinWindow(PlatformWindowDelegate* delegate,
const gfx::Rect& bounds)
: delegate_(delegate) {
CHECK(delegate_);
if (use_popup_as_root_window_for_test)
set_window_style(WS_POPUP);
gfx::Rect window_bounds = GetWindowBoundsForClientBounds(
WS_OVERLAPPEDWINDOW, window_ex_style(), bounds);
gfx::WindowImpl::Init(NULL, window_bounds);
......@@ -126,6 +130,7 @@ LRESULT WinWindow::OnKeyEvent(UINT message, WPARAM w_param, LPARAM l_param) {
}
LRESULT WinWindow::OnNCActivate(UINT message, WPARAM w_param, LPARAM l_param) {
delegate_->OnActivationChanged(!!w_param);
return DefWindowProc(hwnd(), message, w_param, l_param);
}
......@@ -162,4 +167,12 @@ void WinWindow::OnWindowPosChanged(WINDOWPOS* window_pos) {
}
}
namespace test {
// static
void SetUsePopupAsRootWindowForTest(bool use) {
use_popup_as_root_window_for_test = use;
}
} // namespace test
} // namespace ui
......@@ -72,6 +72,15 @@ class WIN_WINDOW_EXPORT WinWindow : public NON_EXPORTED_BASE(PlatformWindow),
DISALLOW_COPY_AND_ASSIGN(WinWindow);
};
namespace test {
// Set true to let WindowTreeHostWin use a popup window
// with no frame/title so that the window size and test's
// expectations matches.
WIN_WINDOW_EXPORT void SetUsePopupAsRootWindowForTest(bool use);
} // namespace test
} // namespace ui
#endif // UI_PLATFORM_WINDOW_WIN_WIN_WINDOW_H_
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment