OLD | NEW |
(Empty) | |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "ui/aura/window_tree_host_platform.h" |
| 6 |
| 7 |
| 8 #include <algorithm> |
| 9 |
| 10 #if defined(OS_WIN) |
| 11 #include <windows.h> |
| 12 #endif |
| 13 |
| 14 #include "base/trace_event/trace_event.h" |
| 15 #include "ui/aura/window_event_dispatcher.h" |
| 16 #include "ui/compositor/compositor.h" |
| 17 #include "ui/events/event.h" |
| 18 |
| 19 #if defined(OS_WIN) |
| 20 #include "base/message_loop/message_loop.h" |
| 21 #include "ui/base/cursor/cursor_loader_win.h" |
| 22 #endif |
| 23 |
| 24 using std::max; |
| 25 using std::min; |
| 26 |
| 27 namespace aura { |
| 28 |
| 29 // static |
| 30 WindowTreeHost* WindowTreeHost::Create(const gfx::Rect& bounds) { |
| 31 return new WindowTreeHostPlatform(bounds); |
| 32 } |
| 33 |
| 34 // static |
| 35 gfx::Size WindowTreeHost::GetNativeScreenSize() { |
| 36 #if defined(OS_WIN) |
| 37 return gfx::Size(GetSystemMetrics(SM_CXSCREEN), |
| 38 GetSystemMetrics(SM_CYSCREEN)); |
| 39 #else |
| 40 NOTIMPLEMENTED(); |
| 41 return gfx::Size(); |
| 42 #endif |
| 43 } |
| 44 |
| 45 WindowTreeHostPlatform::WindowTreeHostPlatform(const gfx::Rect& bounds) |
| 46 : widget_(gfx::kNullAcceleratedWidget), |
| 47 #if defined(USE_OZONE) |
| 48 window_(ui::OzonePlatform::GetInstance()->CreatePlatformWindow(delegate, |
| 49 bounds)), |
| 50 #else |
| 51 window_(PlatformWindow::Create(this, bounds)), |
| 52 #endif |
| 53 current_cursor_(ui::kCursorNull), |
| 54 has_capture_(false) { |
| 55 } |
| 56 |
| 57 WindowTreeHostPlatform::~WindowTreeHostPlatform() { |
| 58 DestroyCompositor(); |
| 59 DestroyDispatcher(); |
| 60 } |
| 61 |
| 62 ui::EventSource* WindowTreeHostPlatform::GetEventSource() { |
| 63 return this; |
| 64 } |
| 65 |
| 66 gfx::AcceleratedWidget WindowTreeHostPlatform::GetAcceleratedWidget() { |
| 67 return widget_; |
| 68 } |
| 69 |
| 70 void WindowTreeHostPlatform::ShowImpl() { |
| 71 window_->Show(); |
| 72 } |
| 73 |
| 74 void WindowTreeHostPlatform::HideImpl() { |
| 75 window_->Hide(); |
| 76 } |
| 77 |
| 78 gfx::Rect WindowTreeHostPlatform::GetBounds() const { |
| 79 return window_->GetBounds(); |
| 80 } |
| 81 |
| 82 void WindowTreeHostPlatform::SetBounds(const gfx::Rect& bounds) { |
| 83 window_->SetBounds(bounds); |
| 84 } |
| 85 |
| 86 gfx::Point WindowTreeHostPlatform::GetLocationOnNativeScreen() const { |
| 87 return window_->GetBounds().origin(); |
| 88 } |
| 89 |
| 90 void WindowTreeHostPlatform::SetCapture() { |
| 91 if (!has_capture_) { |
| 92 has_capture_ = true; |
| 93 window_->SetCapture(); |
| 94 } |
| 95 } |
| 96 |
| 97 void WindowTreeHostPlatform::ReleaseCapture() { |
| 98 if (has_capture_) |
| 99 window_->ReleaseCapture(); |
| 100 } |
| 101 |
| 102 void WindowTreeHostPlatform::SetCursorNative(gfx::NativeCursor native_cursor) { |
| 103 if (cursor == current_cursor_) |
| 104 return; |
| 105 current_cursor_ = cursor; |
| 106 |
| 107 #if defined(OS_WIN) |
| 108 // Custom web cursors are handled directly. |
| 109 if (native_cursor == ui::kCursorCustom) |
| 110 return; |
| 111 |
| 112 ui::CursorLoaderWin cursor_loader; |
| 113 cursor_loader.SetPlatformCursor(&native_cursor); |
| 114 ::SetCursor(native_cursor.platform()); |
| 115 #else |
| 116 platform_window_->SetCursor(cursor.platform()); |
| 117 #endif |
| 118 } |
| 119 |
| 120 void WindowTreeHostPlatform::MoveCursorToNative(const gfx::Point& location) { |
| 121 #if defined(OS_WIN) |
| 122 // Deliberately not implemented. |
| 123 #else |
| 124 platform_window_->MoveCursorTo(location); |
| 125 #endif |
| 126 } |
| 127 |
| 128 void WindowTreeHostPlatform::OnCursorVisibilityChangedNative(bool show) { |
| 129 NOTIMPLEMENTED(); |
| 130 } |
| 131 |
| 132 void WindowTreeHostPlatform::OnBoundsChanged(const gfx::Rect& new_bounds) { |
| 133 gfx::Rect old_bounds = bounds_; |
| 134 bounds_ = new_bounds; |
| 135 if (bounds_.origin() != old_bounds.origin()) |
| 136 OnHostMoved(bounds_.origin()); |
| 137 if (bounds_.size() != old_bounds.size()) |
| 138 OnHostResized(bounds_.size()); |
| 139 } |
| 140 |
| 141 void WindowTreeHostPlatform::OnDamageRect(const gfx::Rect& damage_rect) { |
| 142 compositor()->ScheduleRedrawRect(damage_rect); |
| 143 } |
| 144 |
| 145 void WindowTreeHostPlatform::DispatchEvent(ui::Event* event) { |
| 146 TRACE_EVENT0("input", "WindowTreeHostPlatform::DispatchEvent"); |
| 147 ui::EventDispatchDetails details = SendEventToProcessor(event); |
| 148 if (details.dispatcher_destroyed) |
| 149 event->SetHandled(); |
| 150 } |
| 151 |
| 152 void WindowTreeHostPlatform::OnCloseRequest() { |
| 153 #if defined(OS_WIN) |
| 154 // TODO: this obviously shouldn't be here. |
| 155 base::MessageLoopForUI::current()->Quit(); |
| 156 #else |
| 157 OnHostCloseRequested(); |
| 158 #endif |
| 159 } |
| 160 |
| 161 void WindowTreeHostPlatform::OnClosed() {} |
| 162 |
| 163 void WindowTreeHostPlatform::OnWindowStateChanged( |
| 164 ui::PlatformWindowState new_state) {} |
| 165 |
| 166 void WindowTreeHostPlatform::OnLostCapture() { |
| 167 if (has_capture_) { |
| 168 has_capture_ = false; |
| 169 OnHostLostWindowCapture(); |
| 170 } |
| 171 } |
| 172 |
| 173 void WindowTreeHostPlatform::OnAcceleratedWidgetAvailable( |
| 174 gfx::AcceleratedWidget widget, |
| 175 float device_pixel_ratio) { |
| 176 widget_ = widget; |
| 177 CreateCompositor(); |
| 178 WindowTreeHost::OnAcceleratedWidgetAvailable(); |
| 179 } |
| 180 |
| 181 void WindowTreeHostPlatform::OnActivationChanged(bool active) { |
| 182 if (active) |
| 183 OnHostActivated(); |
| 184 } |
| 185 |
| 186 } // namespace aura |
OLD | NEW |