Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(649)

Side by Side Diff: ui/aura/window_tree_host_win.cc

Issue 400413002: aura: Use PlatformWindow from WindowTreeHost. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: . Created 6 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "ui/aura/window_tree_host_win.h" 5 #include "ui/aura/window_tree_host_win.h"
6 6
7 #include <windows.h> 7 #include <windows.h>
8 8
9 #include <algorithm> 9 #include <algorithm>
10 10
11 #include "base/message_loop/message_loop.h" 11 #include "base/message_loop/message_loop.h"
12 #include "ui/aura/client/cursor_client.h" 12 #include "ui/aura/client/cursor_client.h"
13 #include "ui/aura/window_event_dispatcher.h" 13 #include "ui/aura/window_event_dispatcher.h"
14 #include "ui/base/cursor/cursor_loader_win.h" 14 #include "ui/base/cursor/cursor_loader_win.h"
15 #include "ui/base/view_prop.h" 15 #include "ui/base/view_prop.h"
16 #include "ui/compositor/compositor.h" 16 #include "ui/compositor/compositor.h"
17 #include "ui/events/event.h" 17 #include "ui/events/event.h"
18 #include "ui/gfx/display.h" 18 #include "ui/gfx/display.h"
19 #include "ui/gfx/insets.h" 19 #include "ui/gfx/insets.h"
20 #include "ui/gfx/native_widget_types.h"
20 #include "ui/gfx/screen.h" 21 #include "ui/gfx/screen.h"
22 #include "ui/platform_window/win/win_window.h"
21 23
22 using std::max; 24 using std::max;
23 using std::min; 25 using std::min;
24 26
25 namespace aura { 27 namespace aura {
26 namespace { 28 namespace {
27 29
28 bool use_popup_as_root_window_for_test = false; 30 bool use_popup_as_root_window_for_test = false;
29 31
30 } // namespace 32 } // namespace
31 33
32 // static 34 // static
33 WindowTreeHost* WindowTreeHost::Create(const gfx::Rect& bounds) { 35 WindowTreeHost* WindowTreeHost::Create(const gfx::Rect& bounds) {
34 return new WindowTreeHostWin(bounds); 36 return new WindowTreeHostWin(bounds);
35 } 37 }
36 38
37 // static 39 // static
38 gfx::Size WindowTreeHost::GetNativeScreenSize() { 40 gfx::Size WindowTreeHost::GetNativeScreenSize() {
39 return gfx::Size(GetSystemMetrics(SM_CXSCREEN), 41 return gfx::Size(GetSystemMetrics(SM_CXSCREEN),
40 GetSystemMetrics(SM_CYSCREEN)); 42 GetSystemMetrics(SM_CYSCREEN));
41 } 43 }
42 44
43 WindowTreeHostWin::WindowTreeHostWin(const gfx::Rect& bounds) 45 WindowTreeHostWin::WindowTreeHostWin(const gfx::Rect& bounds)
44 : has_capture_(false) { 46 : has_capture_(false),
45 if (use_popup_as_root_window_for_test) 47 widget_(gfx::kNullAcceleratedWidget),
46 set_window_style(WS_POPUP); 48 window_(new ui::WinWindow(this, bounds)) {
47 Init(NULL, bounds);
48 SetWindowText(hwnd(), L"aura::RootWindow!");
49 CreateCompositor(GetAcceleratedWidget());
50 } 49 }
51 50
52 WindowTreeHostWin::~WindowTreeHostWin() { 51 WindowTreeHostWin::~WindowTreeHostWin() {
53 DestroyCompositor(); 52 DestroyCompositor();
54 DestroyDispatcher(); 53 DestroyDispatcher();
55 DestroyWindow(hwnd()); 54 window_.reset();
56 } 55 }
57 56
58 ui::EventSource* WindowTreeHostWin::GetEventSource() { 57 ui::EventSource* WindowTreeHostWin::GetEventSource() {
59 return this; 58 return this;
60 } 59 }
61 60
62 gfx::AcceleratedWidget WindowTreeHostWin::GetAcceleratedWidget() { 61 gfx::AcceleratedWidget WindowTreeHostWin::GetAcceleratedWidget() {
63 return hwnd(); 62 return widget_;
64 } 63 }
65 64
66 void WindowTreeHostWin::Show() { 65 void WindowTreeHostWin::Show() {
67 ShowWindow(hwnd(), SW_SHOWNORMAL); 66 window_->Show();
68 } 67 }
69 68
70 void WindowTreeHostWin::Hide() { 69 void WindowTreeHostWin::Hide() {
71 NOTIMPLEMENTED(); 70 window_->Hide();
72 } 71 }
73 72
74 gfx::Rect WindowTreeHostWin::GetBounds() const { 73 gfx::Rect WindowTreeHostWin::GetBounds() const {
75 RECT r; 74 return window_->GetBounds();
76 GetClientRect(hwnd(), &r);
77 return gfx::Rect(r);
78 } 75 }
79 76
80 void WindowTreeHostWin::SetBounds(const gfx::Rect& bounds) { 77 void WindowTreeHostWin::SetBounds(const gfx::Rect& bounds) {
81 RECT window_rect; 78 window_->SetBounds(bounds);
82 window_rect.left = bounds.x();
83 window_rect.top = bounds.y();
84 window_rect.right = bounds.right() ;
85 window_rect.bottom = bounds.bottom();
86 AdjustWindowRectEx(&window_rect,
87 GetWindowLong(hwnd(), GWL_STYLE),
88 FALSE,
89 GetWindowLong(hwnd(), GWL_EXSTYLE));
90 SetWindowPos(
91 hwnd(),
92 NULL,
93 window_rect.left,
94 window_rect.top,
95 window_rect.right - window_rect.left,
96 window_rect.bottom - window_rect.top,
97 SWP_NOMOVE | SWP_NOOWNERZORDER | SWP_NOREDRAW | SWP_NOREPOSITION);
98
99 // Explicity call OnHostResized when the scale has changed because
100 // the window size may not have changed.
101 float current_scale = compositor()->device_scale_factor();
102 float new_scale = gfx::Screen::GetScreenFor(window())->
103 GetDisplayNearestWindow(window()).device_scale_factor();
104 if (current_scale != new_scale)
105 OnHostResized(bounds.size());
106 } 79 }
107 80
108 gfx::Point WindowTreeHostWin::GetLocationOnNativeScreen() const { 81 gfx::Point WindowTreeHostWin::GetLocationOnNativeScreen() const {
109 RECT r; 82 return window_->GetBounds().origin();
110 GetClientRect(hwnd(), &r);
111 return gfx::Point(r.left, r.top);
112 } 83 }
113 84
114
115 void WindowTreeHostWin::SetCapture() { 85 void WindowTreeHostWin::SetCapture() {
116 if (!has_capture_) { 86 if (!has_capture_) {
117 has_capture_ = true; 87 has_capture_ = true;
118 ::SetCapture(hwnd()); 88 window_->SetCapture();
119 } 89 }
120 } 90 }
121 91
122 void WindowTreeHostWin::ReleaseCapture() { 92 void WindowTreeHostWin::ReleaseCapture() {
123 if (has_capture_) { 93 if (has_capture_)
124 has_capture_ = false; 94 window_->ReleaseCapture();
125 ::ReleaseCapture();
126 }
127 } 95 }
128 96
129 void WindowTreeHostWin::SetCursorNative(gfx::NativeCursor native_cursor) { 97 void WindowTreeHostWin::SetCursorNative(gfx::NativeCursor native_cursor) {
130 // Custom web cursors are handled directly. 98 // Custom web cursors are handled directly.
131 if (native_cursor == ui::kCursorCustom) 99 if (native_cursor == ui::kCursorCustom)
132 return; 100 return;
133 101
134 ui::CursorLoaderWin cursor_loader; 102 ui::CursorLoaderWin cursor_loader;
135 cursor_loader.SetPlatformCursor(&native_cursor); 103 cursor_loader.SetPlatformCursor(&native_cursor);
136 ::SetCursor(native_cursor.platform()); 104 ::SetCursor(native_cursor.platform());
137 } 105 }
138 106
139 void WindowTreeHostWin::MoveCursorToNative(const gfx::Point& location) { 107 void WindowTreeHostWin::MoveCursorToNative(const gfx::Point& location) {
140 // Deliberately not implemented. 108 // Deliberately not implemented.
141 } 109 }
142 110
143 void WindowTreeHostWin::OnCursorVisibilityChangedNative(bool show) { 111 void WindowTreeHostWin::OnCursorVisibilityChangedNative(bool show) {
144 NOTIMPLEMENTED(); 112 NOTIMPLEMENTED();
145 } 113 }
146 114
147 void WindowTreeHostWin::PostNativeEvent(const base::NativeEvent& native_event) { 115 void WindowTreeHostWin::PostNativeEvent(const base::NativeEvent& native_event) {
148 ::PostMessage( 116 ::PostMessage(
149 hwnd(), native_event.message, native_event.wParam, native_event.lParam); 117 widget_, native_event.message, native_event.wParam, native_event.lParam);
150 } 118 }
151 119
152 ui::EventProcessor* WindowTreeHostWin::GetEventProcessor() { 120 ui::EventProcessor* WindowTreeHostWin::GetEventProcessor() {
153 return dispatcher(); 121 return dispatcher();
154 } 122 }
155 123
156 void WindowTreeHostWin::OnClose() { 124 void WindowTreeHostWin::OnBoundsChanged(const gfx::Rect& new_bounds) {
125 gfx::Rect old_bounds = bounds_;
126 bounds_ = new_bounds;
127 if (bounds_.origin() != old_bounds.origin())
128 OnHostMoved(bounds_.origin());
129 if (bounds_.size() != old_bounds.size())
130 OnHostResized(bounds_.size());
131 }
132
133 void WindowTreeHostWin::OnDamageRect(const gfx::Rect& damage_rect) {
134 compositor()->ScheduleRedrawRect(damage_rect);
135 }
136
137 void WindowTreeHostWin::DispatchEvent(ui::Event* event) {
138 ui::EventDispatchDetails details = SendEventToProcessor(event);
139 if (details.dispatcher_destroyed)
140 event->SetHandled();
141 }
142
143 void WindowTreeHostWin::OnCloseRequest() {
157 // TODO: this obviously shouldn't be here. 144 // TODO: this obviously shouldn't be here.
158 base::MessageLoopForUI::current()->Quit(); 145 base::MessageLoopForUI::current()->Quit();
159 } 146 }
160 147
161 LRESULT WindowTreeHostWin::OnKeyEvent(UINT message, 148 void WindowTreeHostWin::OnClosed() {
162 WPARAM w_param,
163 LPARAM l_param) {
164 MSG msg = { hwnd(), message, w_param, l_param };
165 ui::KeyEvent keyev(msg, message == WM_CHAR);
166 ui::EventDispatchDetails details = SendEventToProcessor(&keyev);
167 SetMsgHandled(keyev.handled() || details.dispatcher_destroyed);
168 return 0;
169 } 149 }
170 150
171 LRESULT WindowTreeHostWin::OnMouseRange(UINT message, 151 void WindowTreeHostWin::OnWindowStateChanged(
172 WPARAM w_param, 152 ui::PlatformWindowState new_state) {
173 LPARAM l_param) {
174 MSG msg = { hwnd(), message, w_param, l_param, 0,
175 { CR_GET_X_LPARAM(l_param), CR_GET_Y_LPARAM(l_param) } };
176 ui::MouseEvent event(msg);
177 bool handled = false;
178 if (!(event.flags() & ui::EF_IS_NON_CLIENT)) {
179 ui::EventDispatchDetails details = SendEventToProcessor(&event);
180 handled = event.handled() || details.dispatcher_destroyed;
181 }
182 SetMsgHandled(handled);
183 return 0;
184 } 153 }
185 154
186 LRESULT WindowTreeHostWin::OnCaptureChanged(UINT message, 155 void WindowTreeHostWin::OnLostCapture() {
187 WPARAM w_param,
188 LPARAM l_param) {
189 if (has_capture_) { 156 if (has_capture_) {
190 has_capture_ = false; 157 has_capture_ = false;
191 OnHostLostWindowCapture(); 158 OnHostLostWindowCapture();
192 } 159 }
193 return 0;
194 } 160 }
195 161
196 LRESULT WindowTreeHostWin::OnNCActivate(UINT message, 162 void WindowTreeHostWin::OnAcceleratedWidgetAvailable(
197 WPARAM w_param, 163 gfx::AcceleratedWidget widget) {
198 LPARAM l_param) { 164 widget_ = widget;
199 if (!!w_param) 165 CreateCompositor(widget);
200 OnHostActivated();
201 return DefWindowProc(hwnd(), message, w_param, l_param);
202 } 166 }
203 167
204 void WindowTreeHostWin::OnMove(const gfx::Point& point) { 168 void WindowTreeHostWin::OnActivationChanged(bool active) {
205 OnHostMoved(point); 169 if (active)
170 OnHostActivated();
206 } 171 }
207 172
208 void WindowTreeHostWin::OnPaint(HDC dc) {
209 gfx::Rect damage_rect;
210 RECT update_rect = {0};
211 if (GetUpdateRect(hwnd(), &update_rect, FALSE))
212 damage_rect = gfx::Rect(update_rect);
213 compositor()->ScheduleRedrawRect(damage_rect);
214 ValidateRect(hwnd(), NULL);
215 }
216
217 void WindowTreeHostWin::OnSize(UINT param, const gfx::Size& size) {
218 // Minimizing resizes the window to 0x0 which causes our layout to go all
219 // screwy, so we just ignore it.
220 if (dispatcher() && param != SIZE_MINIMIZED)
221 OnHostResized(size);
222 }
223
224 namespace test {
225
226 // static
227 void SetUsePopupAsRootWindowForTest(bool use) {
228 use_popup_as_root_window_for_test = use;
229 }
230
231 } // namespace test
232
233 } // namespace aura 173 } // namespace aura
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698