diff options
author | sadrul@chromium.org <sadrul@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2014-07-23 06:04:04 +0000 |
---|---|---|
committer | sadrul@chromium.org <sadrul@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2014-07-23 06:04:04 +0000 |
commit | f1ab0f1684e5d6251d87ed7f36f78d97ba761ebb (patch) | |
tree | 97388e5a6b125a52299348be353c28ce6a3127b1 /ui/aura/window_tree_host_win.cc | |
parent | 6344f4206c189f03f90eb434cf2b28ba46c03f95 (diff) | |
download | chromium_src-f1ab0f1684e5d6251d87ed7f36f78d97ba761ebb.zip chromium_src-f1ab0f1684e5d6251d87ed7f36f78d97ba761ebb.tar.gz chromium_src-f1ab0f1684e5d6251d87ed7f36f78d97ba761ebb.tar.bz2 |
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
Review URL: https://codereview.chromium.org/400413002
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@284850 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'ui/aura/window_tree_host_win.cc')
-rw-r--r-- | ui/aura/window_tree_host_win.cc | 156 |
1 files changed, 48 insertions, 108 deletions
diff --git a/ui/aura/window_tree_host_win.cc b/ui/aura/window_tree_host_win.cc index 46b2e10..51bbcc6 100644 --- a/ui/aura/window_tree_host_win.cc +++ b/ui/aura/window_tree_host_win.cc @@ -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 |