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

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

Issue 410873003: Revert 284850 "aura: Use PlatformWindow from WindowTreeHostWin." (Closed) Base URL: svn://svn.chromium.org/chrome/
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
« no previous file with comments | « trunk/src/ui/aura/window_tree_host_win.h ('k') | trunk/src/ui/ozone/demo/egl_demo.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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"
21 #include "ui/gfx/screen.h" 20 #include "ui/gfx/screen.h"
22 #include "ui/platform_window/win/win_window.h"
23 21
24 using std::max; 22 using std::max;
25 using std::min; 23 using std::min;
26 24
27 namespace aura { 25 namespace aura {
28 namespace { 26 namespace {
29 27
30 bool use_popup_as_root_window_for_test = false; 28 bool use_popup_as_root_window_for_test = false;
31 29
32 } // namespace 30 } // namespace
33 31
34 // static 32 // static
35 WindowTreeHost* WindowTreeHost::Create(const gfx::Rect& bounds) { 33 WindowTreeHost* WindowTreeHost::Create(const gfx::Rect& bounds) {
36 return new WindowTreeHostWin(bounds); 34 return new WindowTreeHostWin(bounds);
37 } 35 }
38 36
39 // static 37 // static
40 gfx::Size WindowTreeHost::GetNativeScreenSize() { 38 gfx::Size WindowTreeHost::GetNativeScreenSize() {
41 return gfx::Size(GetSystemMetrics(SM_CXSCREEN), 39 return gfx::Size(GetSystemMetrics(SM_CXSCREEN),
42 GetSystemMetrics(SM_CYSCREEN)); 40 GetSystemMetrics(SM_CYSCREEN));
43 } 41 }
44 42
45 WindowTreeHostWin::WindowTreeHostWin(const gfx::Rect& bounds) 43 WindowTreeHostWin::WindowTreeHostWin(const gfx::Rect& bounds)
46 : has_capture_(false), 44 : has_capture_(false) {
47 widget_(gfx::kNullAcceleratedWidget), 45 if (use_popup_as_root_window_for_test)
48 window_(new ui::WinWindow(this, bounds)) { 46 set_window_style(WS_POPUP);
47 Init(NULL, bounds);
48 SetWindowText(hwnd(), L"aura::RootWindow!");
49 CreateCompositor(GetAcceleratedWidget());
49 } 50 }
50 51
51 WindowTreeHostWin::~WindowTreeHostWin() { 52 WindowTreeHostWin::~WindowTreeHostWin() {
52 DestroyCompositor(); 53 DestroyCompositor();
53 DestroyDispatcher(); 54 DestroyDispatcher();
54 window_.reset(); 55 DestroyWindow(hwnd());
55 } 56 }
56 57
57 ui::EventSource* WindowTreeHostWin::GetEventSource() { 58 ui::EventSource* WindowTreeHostWin::GetEventSource() {
58 return this; 59 return this;
59 } 60 }
60 61
61 gfx::AcceleratedWidget WindowTreeHostWin::GetAcceleratedWidget() { 62 gfx::AcceleratedWidget WindowTreeHostWin::GetAcceleratedWidget() {
62 return widget_; 63 return hwnd();
63 } 64 }
64 65
65 void WindowTreeHostWin::Show() { 66 void WindowTreeHostWin::Show() {
66 window_->Show(); 67 ShowWindow(hwnd(), SW_SHOWNORMAL);
67 } 68 }
68 69
69 void WindowTreeHostWin::Hide() { 70 void WindowTreeHostWin::Hide() {
70 window_->Hide(); 71 NOTIMPLEMENTED();
71 } 72 }
72 73
73 gfx::Rect WindowTreeHostWin::GetBounds() const { 74 gfx::Rect WindowTreeHostWin::GetBounds() const {
74 return window_->GetBounds(); 75 RECT r;
76 GetClientRect(hwnd(), &r);
77 return gfx::Rect(r);
75 } 78 }
76 79
77 void WindowTreeHostWin::SetBounds(const gfx::Rect& bounds) { 80 void WindowTreeHostWin::SetBounds(const gfx::Rect& bounds) {
78 window_->SetBounds(bounds); 81 RECT window_rect;
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());
79 } 106 }
80 107
81 gfx::Point WindowTreeHostWin::GetLocationOnNativeScreen() const { 108 gfx::Point WindowTreeHostWin::GetLocationOnNativeScreen() const {
82 return window_->GetBounds().origin(); 109 RECT r;
110 GetClientRect(hwnd(), &r);
111 return gfx::Point(r.left, r.top);
83 } 112 }
84 113
114
85 void WindowTreeHostWin::SetCapture() { 115 void WindowTreeHostWin::SetCapture() {
86 if (!has_capture_) { 116 if (!has_capture_) {
87 has_capture_ = true; 117 has_capture_ = true;
88 window_->SetCapture(); 118 ::SetCapture(hwnd());
89 } 119 }
90 } 120 }
91 121
92 void WindowTreeHostWin::ReleaseCapture() { 122 void WindowTreeHostWin::ReleaseCapture() {
93 if (has_capture_) 123 if (has_capture_) {
94 window_->ReleaseCapture(); 124 has_capture_ = false;
125 ::ReleaseCapture();
126 }
95 } 127 }
96 128
97 void WindowTreeHostWin::SetCursorNative(gfx::NativeCursor native_cursor) { 129 void WindowTreeHostWin::SetCursorNative(gfx::NativeCursor native_cursor) {
98 // Custom web cursors are handled directly. 130 // Custom web cursors are handled directly.
99 if (native_cursor == ui::kCursorCustom) 131 if (native_cursor == ui::kCursorCustom)
100 return; 132 return;
101 133
102 ui::CursorLoaderWin cursor_loader; 134 ui::CursorLoaderWin cursor_loader;
103 cursor_loader.SetPlatformCursor(&native_cursor); 135 cursor_loader.SetPlatformCursor(&native_cursor);
104 ::SetCursor(native_cursor.platform()); 136 ::SetCursor(native_cursor.platform());
105 } 137 }
106 138
107 void WindowTreeHostWin::MoveCursorToNative(const gfx::Point& location) { 139 void WindowTreeHostWin::MoveCursorToNative(const gfx::Point& location) {
108 // Deliberately not implemented. 140 // Deliberately not implemented.
109 } 141 }
110 142
111 void WindowTreeHostWin::OnCursorVisibilityChangedNative(bool show) { 143 void WindowTreeHostWin::OnCursorVisibilityChangedNative(bool show) {
112 NOTIMPLEMENTED(); 144 NOTIMPLEMENTED();
113 } 145 }
114 146
115 void WindowTreeHostWin::PostNativeEvent(const base::NativeEvent& native_event) { 147 void WindowTreeHostWin::PostNativeEvent(const base::NativeEvent& native_event) {
116 ::PostMessage( 148 ::PostMessage(
117 widget_, native_event.message, native_event.wParam, native_event.lParam); 149 hwnd(), native_event.message, native_event.wParam, native_event.lParam);
118 } 150 }
119 151
120 ui::EventProcessor* WindowTreeHostWin::GetEventProcessor() { 152 ui::EventProcessor* WindowTreeHostWin::GetEventProcessor() {
121 return dispatcher(); 153 return dispatcher();
122 } 154 }
123 155
124 void WindowTreeHostWin::OnBoundsChanged(const gfx::Rect& new_bounds) { 156 void WindowTreeHostWin::OnClose() {
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() {
144 // TODO: this obviously shouldn't be here. 157 // TODO: this obviously shouldn't be here.
145 base::MessageLoopForUI::current()->Quit(); 158 base::MessageLoopForUI::current()->Quit();
146 } 159 }
147 160
148 void WindowTreeHostWin::OnClosed() { 161 LRESULT WindowTreeHostWin::OnKeyEvent(UINT message,
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;
149 } 169 }
150 170
151 void WindowTreeHostWin::OnWindowStateChanged( 171 LRESULT WindowTreeHostWin::OnMouseRange(UINT message,
152 ui::PlatformWindowState new_state) { 172 WPARAM w_param,
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;
153 } 184 }
154 185
155 void WindowTreeHostWin::OnLostCapture() { 186 LRESULT WindowTreeHostWin::OnCaptureChanged(UINT message,
187 WPARAM w_param,
188 LPARAM l_param) {
156 if (has_capture_) { 189 if (has_capture_) {
157 has_capture_ = false; 190 has_capture_ = false;
158 OnHostLostWindowCapture(); 191 OnHostLostWindowCapture();
159 } 192 }
193 return 0;
160 } 194 }
161 195
162 void WindowTreeHostWin::OnAcceleratedWidgetAvailable( 196 LRESULT WindowTreeHostWin::OnNCActivate(UINT message,
163 gfx::AcceleratedWidget widget) { 197 WPARAM w_param,
164 widget_ = widget; 198 LPARAM l_param) {
165 CreateCompositor(widget); 199 if (!!w_param)
200 OnHostActivated();
201 return DefWindowProc(hwnd(), message, w_param, l_param);
166 } 202 }
167 203
168 void WindowTreeHostWin::OnActivationChanged(bool active) { 204 void WindowTreeHostWin::OnMove(const gfx::Point& point) {
169 if (active) 205 OnHostMoved(point);
170 OnHostActivated();
171 } 206 }
172 207
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
173 } // namespace aura 233 } // namespace aura
OLDNEW
« no previous file with comments | « trunk/src/ui/aura/window_tree_host_win.h ('k') | trunk/src/ui/ozone/demo/egl_demo.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698