Chromium Code Reviews| Index: ui/aura/window_tree_host_platform.cc |
| diff --git a/ui/aura/window_tree_host_platform.cc b/ui/aura/window_tree_host_platform.cc |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..66cedf2e566c96ccac606c6743ace89ad27c7422 |
| --- /dev/null |
| +++ b/ui/aura/window_tree_host_platform.cc |
| @@ -0,0 +1,202 @@ |
| +// Copyright 2015 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/aura/window_tree_host_platform.h" |
| + |
| + |
| +#include <algorithm> |
| + |
| +#if defined(OS_WIN) |
| +#include <windows.h> |
| +#endif |
| + |
| +#include "base/trace_event/trace_event.h" |
| +#include "ui/aura/window_event_dispatcher.h" |
| +#include "ui/compositor/compositor.h" |
| +#include "ui/events/event.h" |
| + |
| +#if defined(OS_WIN) |
| +#include "base/message_loop/message_loop.h" |
| +#include "ui/base/cursor/cursor_loader_win.h" |
| +#endif |
| + |
| +using std::max; |
| +using std::min; |
| + |
| +namespace aura { |
| + |
| +// static |
| +WindowTreeHost* WindowTreeHost::Create(const gfx::Rect& bounds) { |
| + return new WindowTreeHostPlatform(bounds); |
| +} |
| + |
| +// static |
| +gfx::Size WindowTreeHost::GetNativeScreenSize() { |
| +#if defined(OS_WIN) |
| + return gfx::Size(GetSystemMetrics(SM_CXSCREEN), |
| + GetSystemMetrics(SM_CYSCREEN)); |
| +#else |
| + NOTIMPLEMENTED(); |
| + return gfx::Size(); |
| +#endif |
| +} |
| + |
| +WindowTreeHostPlatform::WindowTreeHostPlatform(const gfx::Rect& bounds) |
| + : widget_(gfx::kNullAcceleratedWidget), |
| +#if defined(USE_OZONE) |
| + window_(ui::OzonePlatform::GetInstance()->CreatePlatformWindow(delegate, |
| + bounds)), |
| +#else |
| + window_(PlatformWindow::Create(this, bounds)), |
| +#endif |
| + current_cursor_(ui::kCursorNull), |
| + has_capture_(false) { |
| +} |
| + |
| +WindowTreeHostPlatform::~WindowTreeHostPlatform() { |
| + DestroyCompositor(); |
| + DestroyDispatcher(); |
| + window_.reset(); |
|
dnicoara
2015/10/09 15:04:22
Any reason this is needed? The destructor should c
no sievers
2015/10/09 19:31:51
Done.
|
| +} |
| + |
| +ui::EventSource* WindowTreeHostPlatform::GetEventSource() { |
| + return this; |
| +} |
| + |
| +gfx::AcceleratedWidget WindowTreeHostPlatform::GetAcceleratedWidget() { |
| + return widget_; |
| +} |
| + |
| +void WindowTreeHostPlatform::ShowImpl() { |
| + window_->Show(); |
| +} |
| + |
| +void WindowTreeHostPlatform::HideImpl() { |
| + window_->Hide(); |
| +} |
| + |
| +gfx::Rect WindowTreeHostPlatform::GetBounds() const { |
| + return window_->GetBounds(); |
| +} |
| + |
| +void WindowTreeHostPlatform::SetBounds(const gfx::Rect& bounds) { |
| + window_->SetBounds(bounds); |
| +} |
| + |
| +gfx::Point WindowTreeHostPlatform::GetLocationOnNativeScreen() const { |
| + return window_->GetBounds().origin(); |
| +} |
| + |
| +void WindowTreeHostPlatform::SetCapture() { |
| +#if defined(USE_OZONE) |
| + window_->SetCapture(); |
| +#else |
| + if (!has_capture_) { |
| + has_capture_ = true; |
| + window_->SetCapture(); |
| + } |
| +#endif |
| +} |
| + |
| +void WindowTreeHostPlatform::ReleaseCapture() { |
| +#if !defined(USE_OZONE) |
| + if (has_capture_) |
| +#endif |
| + window_->ReleaseCapture(); |
| +} |
| + |
| +void WindowTreeHostPlatform::SetCursorNative(gfx::NativeCursor native_cursor) { |
| + if (cursor == current_cursor_) |
| + return; |
| + current_cursor_ = cursor; |
| + |
| +#if defined(OS_WIN) |
| + // Custom web cursors are handled directly. |
| + if (native_cursor == ui::kCursorCustom) |
| + return; |
| + |
| + ui::CursorLoaderWin cursor_loader; |
| + cursor_loader.SetPlatformCursor(&native_cursor); |
| + ::SetCursor(native_cursor.platform()); |
| +#else |
| + platform_window_->SetCursor(cursor.platform()); |
| +#endif |
| +} |
| + |
| +void WindowTreeHostPlatform::MoveCursorToNative(const gfx::Point& location) { |
| +#if defined(OS_WIN) |
| +// Deliberately not implemented. |
| +#else |
| + platform_window_->MoveCursorTo(location); |
| +#endif |
| +} |
| + |
| +void WindowTreeHostPlatform::OnCursorVisibilityChangedNative(bool show) { |
| + NOTIMPLEMENTED(); |
| +} |
| + |
| +void WindowTreeHostPlatform::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()); |
| +} |
| + |
| +void WindowTreeHostPlatform::OnDamageRect(const gfx::Rect& damage_rect) { |
| +// TODO: Can the ifdef be removed? |
| +#if !defined(USE_OZONE) |
|
dnicoara
2015/10/09 15:04:22
It should be safe to remove the #ifdef and call th
|
| + compositor()->ScheduleRedrawRect(damage_rect); |
| +#endif |
| +} |
| + |
| +void WindowTreeHostPlatform::DispatchEvent(ui::Event* event) { |
| + TRACE_EVENT0("input", "WindowTreeHostPlatform::DispatchEvent"); |
| + ui::EventDispatchDetails details = SendEventToProcessor(event); |
| + if (details.dispatcher_destroyed) |
| + event->SetHandled(); |
| +} |
| + |
| +void WindowTreeHostPlatform::OnCloseRequest() { |
| +#if defined(OS_WIN) |
| + // TODO: this obviously shouldn't be here. |
| + base::MessageLoopForUI::current()->Quit(); |
| +#else |
| + OnHostCloseRequested(); |
| +#endif |
| +} |
| + |
| +void WindowTreeHostPlatform::OnClosed() {} |
| + |
| +void WindowTreeHostPlatform::OnWindowStateChanged( |
| + ui::PlatformWindowState new_state) {} |
| + |
| +void WindowTreeHostPlatform::OnLostCapture() { |
| +// TODO: Can the ifdef be removed? |
| +#if !defined(USE_OZONE) |
|
dnicoara
2015/10/09 15:04:22
It should be safe to remove the #ifdef (same with
|
| + if (has_capture_) { |
| + has_capture_ = false; |
| + OnHostLostWindowCapture(); |
| + } |
| +#endif |
| +} |
| + |
| +void WindowTreeHostPlatform::OnAcceleratedWidgetAvailable( |
| + gfx::AcceleratedWidget widget, |
| + float device_pixel_ratio) { |
| + widget_ = widget; |
| + CreateCompositor(); |
| + WindowTreeHost::OnAcceleratedWidgetAvailable(); |
| +} |
| + |
| +void WindowTreeHostPlatform::OnActivationChanged(bool active) { |
| +// TODO: Can the ifdef be removed? |
| +#if !defined(USE_OZONE) |
|
dnicoara
2015/10/09 15:04:22
It should be safe to remove the #ifdef.
All of th
|
| + if (active) |
| + OnHostActivated(); |
| +#endif |
| +} |
| + |
| +} // namespace aura |