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.
5 #include "ui/aura/window_tree_host_win.h"
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"
30 WindowTreeHost
* WindowTreeHost::Create(const gfx::Rect
& bounds
) {
31 return new WindowTreeHostWin(bounds
);
35 gfx::Size
WindowTreeHost::GetNativeScreenSize() {
36 return gfx::Size(GetSystemMetrics(SM_CXSCREEN
),
37 GetSystemMetrics(SM_CYSCREEN
));
40 WindowTreeHostWin::WindowTreeHostWin(const gfx::Rect
& bounds
)
41 : has_capture_(false),
42 widget_(gfx::kNullAcceleratedWidget
),
43 window_(new ui::WinWindow(this, bounds
)) {
46 WindowTreeHostWin::~WindowTreeHostWin() {
52 ui::EventSource
* WindowTreeHostWin::GetEventSource() {
56 gfx::AcceleratedWidget
WindowTreeHostWin::GetAcceleratedWidget() {
60 void WindowTreeHostWin::ShowImpl() {
64 void WindowTreeHostWin::HideImpl() {
68 gfx::Rect
WindowTreeHostWin::GetBounds() const {
69 return window_
->GetBounds();
72 void WindowTreeHostWin::SetBounds(const gfx::Rect
& bounds
) {
73 window_
->SetBounds(bounds
);
76 gfx::Point
WindowTreeHostWin::GetLocationOnNativeScreen() const {
77 return window_
->GetBounds().origin();
80 void WindowTreeHostWin::SetCapture() {
83 window_
->SetCapture();
87 void WindowTreeHostWin::ReleaseCapture() {
89 window_
->ReleaseCapture();
92 void WindowTreeHostWin::SetCursorNative(gfx::NativeCursor native_cursor
) {
93 // Custom web cursors are handled directly.
94 if (native_cursor
== ui::kCursorCustom
)
97 ui::CursorLoaderWin cursor_loader
;
98 cursor_loader
.SetPlatformCursor(&native_cursor
);
99 ::SetCursor(native_cursor
.platform());
102 void WindowTreeHostWin::MoveCursorToNative(const gfx::Point
& location
) {
103 // Deliberately not implemented.
106 void WindowTreeHostWin::OnCursorVisibilityChangedNative(bool show
) {
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());
119 void WindowTreeHostWin::OnDamageRect(const gfx::Rect
& damage_rect
) {
120 compositor()->ScheduleRedrawRect(damage_rect
);
123 void WindowTreeHostWin::DispatchEvent(ui::Event
* event
) {
124 ui::EventDispatchDetails details
= SendEventToProcessor(event
);
125 if (details
.dispatcher_destroyed
)
129 void WindowTreeHostWin::OnCloseRequest() {
130 // TODO: this obviously shouldn't be here.
131 base::MessageLoopForUI::current()->Quit();
134 void WindowTreeHostWin::OnClosed() {
137 void WindowTreeHostWin::OnWindowStateChanged(
138 ui::PlatformWindowState new_state
) {
141 void WindowTreeHostWin::OnLostCapture() {
143 has_capture_
= false;
144 OnHostLostWindowCapture();
148 void WindowTreeHostWin::OnAcceleratedWidgetAvailable(
149 gfx::AcceleratedWidget widget
,
150 float device_pixel_ratio
) {
153 WindowTreeHost::OnAcceleratedWidgetAvailable();
156 void WindowTreeHostWin::OnActivationChanged(bool active
) {