Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(587)

Unified Diff: ui/aura/window_tree_host_impl.cc

Issue 1390883003: aura: Unify WindowTreeHost for some platforms (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: ui/aura/window_tree_host_impl.cc
diff --git a/ui/aura/window_tree_host_impl.cc b/ui/aura/window_tree_host_impl.cc
new file mode 100644
index 0000000000000000000000000000000000000000..be198729339cf6795d054d64ac5d1c2bf9249032
--- /dev/null
+++ b/ui/aura/window_tree_host_impl.cc
@@ -0,0 +1,197 @@
+// 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_impl.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 WindowTreeHostImpl(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
+}
+
+WindowTreeHostImpl::WindowTreeHostWin(const gfx::Rect& bounds)
mfomitchev 2015/10/08 15:03:27 fix constructor name
no sievers 2015/10/09 00:34:18 Done.
+ : widget_(gfx::kNullAcceleratedWidget),
+ window_(PlatformWindow::Create(this, bounds)),
+ current_cursor_(ui::kCursorNull),
+ has_capture_(false) {
+}
+
+WindowTreeHostImpl::~WindowTreeHostWin() {
mfomitchev 2015/10/08 15:03:27 fix destructor name
no sievers 2015/10/09 00:34:18 Done.
+ DestroyCompositor();
+ DestroyDispatcher();
+ window_.reset();
+}
+
+ui::EventSource* WindowTreeHostImpl::GetEventSource() {
+ return this;
+}
+
+gfx::AcceleratedWidget WindowTreeHostImpl::GetAcceleratedWidget() {
+ return widget_;
+}
+
+void WindowTreeHostImpl::ShowImpl() {
+ window_->Show();
+}
+
+void WindowTreeHostImpl::HideImpl() {
+ window_->Hide();
+}
+
+gfx::Rect WindowTreeHostImpl::GetBounds() const {
+ return window_->GetBounds();
+}
+
+void WindowTreeHostImpl::SetBounds(const gfx::Rect& bounds) {
+ window_->SetBounds(bounds);
+}
+
+gfx::Point WindowTreeHostImpl::GetLocationOnNativeScreen() const {
+ return window_->GetBounds().origin();
+}
+
+void WindowTreeHostImpl::SetCapture() {
+#if defined(USE_OZONE)
+ window_->SetCapture();
+#else
+ if (!has_capture_) {
+ has_capture_ = true;
+ window_->SetCapture();
+ }
+#endif
+}
+
+void WindowTreeHostImpl::ReleaseCapture() {
+#if !defined(USE_OZONE)
+ if (has_capture_)
+#endif
+ window_->ReleaseCapture();
+}
+
+void WindowTreeHostImpl::SetCursorNative(gfx::NativeCursor native_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
+ if (cursor == current_cursor_)
mfomitchev 2015/10/08 15:03:27 native_cursor? Perhaps we just move this if up and
no sievers 2015/10/09 00:34:18 Done.
+ return;
+ current_cursor_ = cursor;
+ platform_window_->SetCursor(cursor.platform());
+#endif
+}
+
+void WindowTreeHostImpl::MoveCursorToNative(const gfx::Point& location) {
+#if defined(OS_WIN)
+ // Deliberately not implemented.
+#else
+ platform_window_->MoveCursorTo(location);
+#endif
+}
+
+void WindowTreeHostImpl::OnCursorVisibilityChangedNative(bool show) {
+ NOTIMPLEMENTED();
+}
+
+void WindowTreeHostImpl::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 WindowTreeHostImpl::OnDamageRect(const gfx::Rect& damage_rect) {
+#if !defined(USE_OZONE)
mfomitchev 2015/10/08 15:03:27 @dnicoara - do you know if we need this ifdef?
+ compositor()->ScheduleRedrawRect(damage_rect);
+#endif
+}
+
+void WindowTreeHostImpl::DispatchEvent(ui::Event* event) {
+ TRACE_EVENT0("input", "WindowTreeHostOzone::DispatchEvent");
mfomitchev 2015/10/08 15:03:27 Fix class name in msg
no sievers 2015/10/09 00:34:18 Done.
+ ui::EventDispatchDetails details = SendEventToProcessor(event);
+#if defined(OS_WIN)
mfomitchev 2015/10/08 15:03:27 I don't think there's a good reason for this to be
no sievers 2015/10/09 00:34:18 Done.
+ if (details.dispatcher_destroyed)
+ event->SetHandled();
+#endif
+}
+
+void WindowTreeHostImpl::OnCloseRequest() {
+#if defined(OS_WIN)
+ // TODO: this obviously shouldn't be here.
mfomitchev 2015/10/08 15:03:27 Heh..
+ base::MessageLoopForUI::current()->Quit();
+#else
+ OnHostCloseRequested();
+#endif
+}
+
+void WindowTreeHostImpl::OnClosed() {
+}
+
+void WindowTreeHostImpl::OnWindowStateChanged(
+ ui::PlatformWindowState new_state) {
+}
+
+void WindowTreeHostImpl::OnLostCapture() {
+#if !defined(USE_OZONE)
mfomitchev 2015/10/08 15:03:27 I am not sure we need this ifdef either...
no sievers 2015/10/08 17:59:06 So this comes down to whether someone can confirm
mfomitchev 2015/10/09 13:56:54 Yeah, lets wait for @dnicoara to respond to these.
+ if (has_capture_) {
+ has_capture_ = false;
+ OnHostLostWindowCapture();
+ }
+#endif
+}
+
+void WindowTreeHostImpl::OnAcceleratedWidgetAvailable(
+ gfx::AcceleratedWidget widget,
+ float device_pixel_ratio) {
+ widget_ = widget;
+ CreateCompositor();
+ WindowTreeHost::OnAcceleratedWidgetAvailable();
+}
+
+void WindowTreeHostImpl::OnActivationChanged(bool active) {
+#if !defined(USE_OZONE)
mfomitchev 2015/10/08 15:03:27 or this..
+ if (active)
+ OnHostActivated();
+#endif
+}
+
+} // namespace aura

Powered by Google App Engine
This is Rietveld 408576698