Chromium Code Reviews| 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_ANDROID) | |
| 20 #include "ui/platform_window/android/platform_window_android.h" | |
| 21 #endif | |
| 22 | |
| 23 #if defined(USE_OZONE) | |
| 24 #include "ui/ozone/public/ozone_platform.h" | |
| 25 #endif | |
| 26 | |
| 27 #if defined(OS_WIN) | |
| 28 #include "base/message_loop/message_loop.h" | |
| 29 #include "ui/base/cursor/cursor_loader_win.h" | |
| 30 #include "ui/platform_window/win/win_window.h" | |
| 31 #endif | |
| 32 | |
| 33 using std::max; | |
| 34 using std::min; | |
| 35 | |
| 36 namespace aura { | |
| 37 | |
| 38 // static | |
| 39 WindowTreeHost* WindowTreeHost::Create(const gfx::Rect& bounds) { | |
| 40 return new WindowTreeHostPlatform(bounds); | |
| 41 } | |
| 42 | |
| 43 // static | |
| 44 gfx::Size WindowTreeHost::GetNativeScreenSize() { | |
| 45 #if defined(OS_WIN) | |
| 46 return gfx::Size(GetSystemMetrics(SM_CXSCREEN), | |
| 47 GetSystemMetrics(SM_CYSCREEN)); | |
| 48 #else | |
| 49 NOTIMPLEMENTED(); | |
| 50 return gfx::Size(); | |
| 51 #endif | |
| 52 } | |
| 53 | |
| 54 WindowTreeHostPlatform::WindowTreeHostPlatform(const gfx::Rect& bounds) | |
| 55 : widget_(gfx::kNullAcceleratedWidget), | |
| 56 current_cursor_(ui::kCursorNull), | |
| 57 has_capture_(false) { | |
| 58 #if defined(USE_OZONE) | |
| 59 window_.reset( | |
| 60 new ui::OzonePlatform::GetInstance()->CreatePlatformWindow(this, bounds)); | |
|
mfomitchev
2015/10/15 15:00:57
We need to get rid of "new" here. This is probably
no sievers
2015/10/15 17:24:23
Oops, thanks, done.
| |
| 61 #elif defined(OS_WIN) | |
| 62 window_.reset(new ui::WinWindow(this, bounds)); | |
| 63 #elif defined(OS_ANDROID) | |
| 64 window_.reset(new ui::PlatformWindowAndroid(this)); | |
| 65 #else | |
| 66 NOTIMPLEMENTED(); | |
| 67 #endif | |
| 68 } | |
| 69 | |
| 70 WindowTreeHostPlatform::~WindowTreeHostPlatform() { | |
| 71 DestroyCompositor(); | |
| 72 DestroyDispatcher(); | |
| 73 } | |
| 74 | |
| 75 ui::EventSource* WindowTreeHostPlatform::GetEventSource() { | |
| 76 return this; | |
| 77 } | |
| 78 | |
| 79 gfx::AcceleratedWidget WindowTreeHostPlatform::GetAcceleratedWidget() { | |
| 80 return widget_; | |
| 81 } | |
| 82 | |
| 83 void WindowTreeHostPlatform::ShowImpl() { | |
| 84 window_->Show(); | |
| 85 } | |
| 86 | |
| 87 void WindowTreeHostPlatform::HideImpl() { | |
| 88 window_->Hide(); | |
| 89 } | |
| 90 | |
| 91 gfx::Rect WindowTreeHostPlatform::GetBounds() const { | |
| 92 return window_->GetBounds(); | |
| 93 } | |
| 94 | |
| 95 void WindowTreeHostPlatform::SetBounds(const gfx::Rect& bounds) { | |
| 96 window_->SetBounds(bounds); | |
| 97 } | |
| 98 | |
| 99 gfx::Point WindowTreeHostPlatform::GetLocationOnNativeScreen() const { | |
| 100 return window_->GetBounds().origin(); | |
| 101 } | |
| 102 | |
| 103 void WindowTreeHostPlatform::SetCapture() { | |
| 104 if (!has_capture_) { | |
| 105 has_capture_ = true; | |
| 106 window_->SetCapture(); | |
| 107 } | |
| 108 } | |
| 109 | |
| 110 void WindowTreeHostPlatform::ReleaseCapture() { | |
| 111 if (has_capture_) | |
| 112 window_->ReleaseCapture(); | |
| 113 } | |
| 114 | |
| 115 void WindowTreeHostPlatform::SetCursorNative(gfx::NativeCursor cursor) { | |
| 116 if (cursor == current_cursor_) | |
| 117 return; | |
| 118 current_cursor_ = cursor; | |
| 119 | |
| 120 #if defined(OS_WIN) | |
| 121 // Custom web cursors are handled directly. | |
| 122 if (cursor == ui::kCursorCustom) | |
| 123 return; | |
| 124 | |
| 125 ui::CursorLoaderWin cursor_loader; | |
| 126 cursor_loader.SetPlatformCursor(&cursor); | |
| 127 ::SetCursor(cursor.platform()); | |
| 128 #else | |
| 129 window_->SetCursor(cursor.platform()); | |
| 130 #endif | |
| 131 } | |
| 132 | |
| 133 void WindowTreeHostPlatform::MoveCursorToNative(const gfx::Point& location) { | |
| 134 #if defined(OS_WIN) | |
| 135 // Deliberately not implemented. | |
| 136 #else | |
| 137 window_->MoveCursorTo(location); | |
| 138 #endif | |
| 139 } | |
| 140 | |
| 141 void WindowTreeHostPlatform::OnCursorVisibilityChangedNative(bool show) { | |
| 142 NOTIMPLEMENTED(); | |
| 143 } | |
| 144 | |
| 145 void WindowTreeHostPlatform::OnBoundsChanged(const gfx::Rect& new_bounds) { | |
| 146 gfx::Rect old_bounds = bounds_; | |
| 147 bounds_ = new_bounds; | |
| 148 if (bounds_.origin() != old_bounds.origin()) | |
| 149 OnHostMoved(bounds_.origin()); | |
| 150 if (bounds_.size() != old_bounds.size()) | |
| 151 OnHostResized(bounds_.size()); | |
| 152 } | |
| 153 | |
| 154 void WindowTreeHostPlatform::OnDamageRect(const gfx::Rect& damage_rect) { | |
| 155 compositor()->ScheduleRedrawRect(damage_rect); | |
| 156 } | |
| 157 | |
| 158 void WindowTreeHostPlatform::DispatchEvent(ui::Event* event) { | |
| 159 TRACE_EVENT0("input", "WindowTreeHostPlatform::DispatchEvent"); | |
| 160 ui::EventDispatchDetails details = SendEventToProcessor(event); | |
| 161 if (details.dispatcher_destroyed) | |
| 162 event->SetHandled(); | |
| 163 } | |
| 164 | |
| 165 void WindowTreeHostPlatform::OnCloseRequest() { | |
| 166 #if defined(OS_WIN) | |
| 167 // TODO: this obviously shouldn't be here. | |
| 168 base::MessageLoopForUI::current()->QuitWhenIdle(); | |
| 169 #else | |
| 170 OnHostCloseRequested(); | |
| 171 #endif | |
| 172 } | |
| 173 | |
| 174 void WindowTreeHostPlatform::OnClosed() {} | |
| 175 | |
| 176 void WindowTreeHostPlatform::OnWindowStateChanged( | |
| 177 ui::PlatformWindowState new_state) {} | |
| 178 | |
| 179 void WindowTreeHostPlatform::OnLostCapture() { | |
| 180 if (has_capture_) { | |
| 181 has_capture_ = false; | |
| 182 OnHostLostWindowCapture(); | |
| 183 } | |
| 184 } | |
| 185 | |
| 186 void WindowTreeHostPlatform::OnAcceleratedWidgetAvailable( | |
| 187 gfx::AcceleratedWidget widget, | |
| 188 float device_pixel_ratio) { | |
| 189 widget_ = widget; | |
| 190 CreateCompositor(); | |
| 191 WindowTreeHost::OnAcceleratedWidgetAvailable(); | |
| 192 } | |
| 193 | |
| 194 void WindowTreeHostPlatform::OnActivationChanged(bool active) { | |
| 195 if (active) | |
| 196 OnHostActivated(); | |
| 197 } | |
| 198 | |
| 199 } // namespace aura | |
| OLD | NEW |