9a30344cc57d95be000cdb254585f06adb150d95
[platform/framework/web/crosswalk.git] / src / ui / aura / window_tree_host_win.cc
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/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 namespace {
29
30 bool use_popup_as_root_window_for_test = false;
31
32 }  // namespace
33
34 // static
35 WindowTreeHost* WindowTreeHost::Create(const gfx::Rect& bounds) {
36   return new WindowTreeHostWin(bounds);
37 }
38
39 // static
40 gfx::Size WindowTreeHost::GetNativeScreenSize() {
41   return gfx::Size(GetSystemMetrics(SM_CXSCREEN),
42                    GetSystemMetrics(SM_CYSCREEN));
43 }
44
45 WindowTreeHostWin::WindowTreeHostWin(const gfx::Rect& bounds)
46     : has_capture_(false),
47       widget_(gfx::kNullAcceleratedWidget),
48       window_(new ui::WinWindow(this, bounds)) {
49 }
50
51 WindowTreeHostWin::~WindowTreeHostWin() {
52   DestroyCompositor();
53   DestroyDispatcher();
54   window_.reset();
55 }
56
57 ui::EventSource* WindowTreeHostWin::GetEventSource() {
58   return this;
59 }
60
61 gfx::AcceleratedWidget WindowTreeHostWin::GetAcceleratedWidget() {
62   return widget_;
63 }
64
65 void WindowTreeHostWin::Show() {
66   window_->Show();
67 }
68
69 void WindowTreeHostWin::Hide() {
70   window_->Hide();
71 }
72
73 gfx::Rect WindowTreeHostWin::GetBounds() const {
74   return window_->GetBounds();
75 }
76
77 void WindowTreeHostWin::SetBounds(const gfx::Rect& bounds) {
78   window_->SetBounds(bounds);
79 }
80
81 gfx::Point WindowTreeHostWin::GetLocationOnNativeScreen() const {
82   return window_->GetBounds().origin();
83 }
84
85 void WindowTreeHostWin::SetCapture() {
86   if (!has_capture_) {
87     has_capture_ = true;
88     window_->SetCapture();
89   }
90 }
91
92 void WindowTreeHostWin::ReleaseCapture() {
93   if (has_capture_)
94     window_->ReleaseCapture();
95 }
96
97 void WindowTreeHostWin::SetCursorNative(gfx::NativeCursor native_cursor) {
98   // Custom web cursors are handled directly.
99   if (native_cursor == ui::kCursorCustom)
100     return;
101
102   ui::CursorLoaderWin cursor_loader;
103   cursor_loader.SetPlatformCursor(&native_cursor);
104   ::SetCursor(native_cursor.platform());
105 }
106
107 void WindowTreeHostWin::MoveCursorToNative(const gfx::Point& location) {
108   // Deliberately not implemented.
109 }
110
111 void WindowTreeHostWin::OnCursorVisibilityChangedNative(bool show) {
112   NOTIMPLEMENTED();
113 }
114
115 ui::EventProcessor* WindowTreeHostWin::GetEventProcessor() {
116   return dispatcher();
117 }
118
119 void WindowTreeHostWin::OnBoundsChanged(const gfx::Rect& new_bounds) {
120   gfx::Rect old_bounds = bounds_;
121   bounds_ = new_bounds;
122   if (bounds_.origin() != old_bounds.origin())
123     OnHostMoved(bounds_.origin());
124   if (bounds_.size() != old_bounds.size())
125     OnHostResized(bounds_.size());
126 }
127
128 void WindowTreeHostWin::OnDamageRect(const gfx::Rect& damage_rect) {
129   compositor()->ScheduleRedrawRect(damage_rect);
130 }
131
132 void WindowTreeHostWin::DispatchEvent(ui::Event* event) {
133   ui::EventDispatchDetails details = SendEventToProcessor(event);
134   if (details.dispatcher_destroyed)
135     event->SetHandled();
136 }
137
138 void WindowTreeHostWin::OnCloseRequest() {
139   // TODO: this obviously shouldn't be here.
140   base::MessageLoopForUI::current()->Quit();
141 }
142
143 void WindowTreeHostWin::OnClosed() {
144 }
145
146 void WindowTreeHostWin::OnWindowStateChanged(
147     ui::PlatformWindowState new_state) {
148 }
149
150 void WindowTreeHostWin::OnLostCapture() {
151   if (has_capture_) {
152     has_capture_ = false;
153     OnHostLostWindowCapture();
154   }
155 }
156
157 void WindowTreeHostWin::OnAcceleratedWidgetAvailable(
158     gfx::AcceleratedWidget widget) {
159   widget_ = widget;
160   CreateCompositor(widget);
161 }
162
163 void WindowTreeHostWin::OnActivationChanged(bool active) {
164   if (active)
165     OnHostActivated();
166 }
167
168 }  // namespace aura