| OLD | NEW |
| (Empty) |
| 1 // Copyright (c) 2012 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_win.h" | |
| 6 | |
| 7 #include <windows.h> | |
| 8 | |
| 9 #include <algorithm> | |
| 10 | |
| 11 #include "base/message_loop/message_loop.h" | |
| 12 #include "ui/aura/client/cursor_client.h" | |
| 13 #include "ui/aura/window_event_dispatcher.h" | |
| 14 #include "ui/base/cursor/cursor_loader_win.h" | |
| 15 #include "ui/base/view_prop.h" | |
| 16 #include "ui/compositor/compositor.h" | |
| 17 #include "ui/events/event.h" | |
| 18 #include "ui/gfx/display.h" | |
| 19 #include "ui/gfx/geometry/insets.h" | |
| 20 #include "ui/gfx/native_widget_types.h" | |
| 21 #include "ui/gfx/screen.h" | |
| 22 #include "ui/platform_window/win/win_window.h" | |
| 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 WindowTreeHostWin(bounds); | |
| 32 } | |
| 33 | |
| 34 // static | |
| 35 gfx::Size WindowTreeHost::GetNativeScreenSize() { | |
| 36 return gfx::Size(GetSystemMetrics(SM_CXSCREEN), | |
| 37 GetSystemMetrics(SM_CYSCREEN)); | |
| 38 } | |
| 39 | |
| 40 WindowTreeHostWin::WindowTreeHostWin(const gfx::Rect& bounds) | |
| 41 : has_capture_(false), | |
| 42 widget_(gfx::kNullAcceleratedWidget), | |
| 43 window_(new ui::WinWindow(this, bounds)) { | |
| 44 } | |
| 45 | |
| 46 WindowTreeHostWin::~WindowTreeHostWin() { | |
| 47 DestroyCompositor(); | |
| 48 DestroyDispatcher(); | |
| 49 window_.reset(); | |
| 50 } | |
| 51 | |
| 52 ui::EventSource* WindowTreeHostWin::GetEventSource() { | |
| 53 return this; | |
| 54 } | |
| 55 | |
| 56 gfx::AcceleratedWidget WindowTreeHostWin::GetAcceleratedWidget() { | |
| 57 return widget_; | |
| 58 } | |
| 59 | |
| 60 void WindowTreeHostWin::ShowImpl() { | |
| 61 window_->Show(); | |
| 62 } | |
| 63 | |
| 64 void WindowTreeHostWin::HideImpl() { | |
| 65 window_->Hide(); | |
| 66 } | |
| 67 | |
| 68 gfx::Rect WindowTreeHostWin::GetBounds() const { | |
| 69 return window_->GetBounds(); | |
| 70 } | |
| 71 | |
| 72 void WindowTreeHostWin::SetBounds(const gfx::Rect& bounds) { | |
| 73 window_->SetBounds(bounds); | |
| 74 } | |
| 75 | |
| 76 gfx::Point WindowTreeHostWin::GetLocationOnNativeScreen() const { | |
| 77 return window_->GetBounds().origin(); | |
| 78 } | |
| 79 | |
| 80 void WindowTreeHostWin::SetCapture() { | |
| 81 if (!has_capture_) { | |
| 82 has_capture_ = true; | |
| 83 window_->SetCapture(); | |
| 84 } | |
| 85 } | |
| 86 | |
| 87 void WindowTreeHostWin::ReleaseCapture() { | |
| 88 if (has_capture_) | |
| 89 window_->ReleaseCapture(); | |
| 90 } | |
| 91 | |
| 92 void WindowTreeHostWin::SetCursorNative(gfx::NativeCursor native_cursor) { | |
| 93 // Custom web cursors are handled directly. | |
| 94 if (native_cursor == ui::kCursorCustom) | |
| 95 return; | |
| 96 | |
| 97 ui::CursorLoaderWin cursor_loader; | |
| 98 cursor_loader.SetPlatformCursor(&native_cursor); | |
| 99 ::SetCursor(native_cursor.platform()); | |
| 100 } | |
| 101 | |
| 102 void WindowTreeHostWin::MoveCursorToNative(const gfx::Point& location) { | |
| 103 // Deliberately not implemented. | |
| 104 } | |
| 105 | |
| 106 void WindowTreeHostWin::OnCursorVisibilityChangedNative(bool show) { | |
| 107 NOTIMPLEMENTED(); | |
| 108 } | |
| 109 | |
| 110 void WindowTreeHostWin::OnBoundsChanged(const gfx::Rect& new_bounds) { | |
| 111 gfx::Rect old_bounds = bounds_; | |
| 112 bounds_ = new_bounds; | |
| 113 if (bounds_.origin() != old_bounds.origin()) | |
| 114 OnHostMoved(bounds_.origin()); | |
| 115 if (bounds_.size() != old_bounds.size()) | |
| 116 OnHostResized(bounds_.size()); | |
| 117 } | |
| 118 | |
| 119 void WindowTreeHostWin::OnDamageRect(const gfx::Rect& damage_rect) { | |
| 120 compositor()->ScheduleRedrawRect(damage_rect); | |
| 121 } | |
| 122 | |
| 123 void WindowTreeHostWin::DispatchEvent(ui::Event* event) { | |
| 124 ui::EventDispatchDetails details = SendEventToProcessor(event); | |
| 125 if (details.dispatcher_destroyed) | |
| 126 event->SetHandled(); | |
| 127 } | |
| 128 | |
| 129 void WindowTreeHostWin::OnCloseRequest() { | |
| 130 // TODO: this obviously shouldn't be here. | |
| 131 base::MessageLoopForUI::current()->Quit(); | |
| 132 } | |
| 133 | |
| 134 void WindowTreeHostWin::OnClosed() { | |
| 135 } | |
| 136 | |
| 137 void WindowTreeHostWin::OnWindowStateChanged( | |
| 138 ui::PlatformWindowState new_state) { | |
| 139 } | |
| 140 | |
| 141 void WindowTreeHostWin::OnLostCapture() { | |
| 142 if (has_capture_) { | |
| 143 has_capture_ = false; | |
| 144 OnHostLostWindowCapture(); | |
| 145 } | |
| 146 } | |
| 147 | |
| 148 void WindowTreeHostWin::OnAcceleratedWidgetAvailable( | |
| 149 gfx::AcceleratedWidget widget, | |
| 150 float device_pixel_ratio) { | |
| 151 widget_ = widget; | |
| 152 CreateCompositor(); | |
| 153 WindowTreeHost::OnAcceleratedWidgetAvailable(); | |
| 154 } | |
| 155 | |
| 156 void WindowTreeHostWin::OnActivationChanged(bool active) { | |
| 157 if (active) | |
| 158 OnHostActivated(); | |
| 159 } | |
| 160 | |
| 161 } // namespace aura | |
| OLD | NEW |