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

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

Issue 188853003: Revert of Clean up WindowEventDispatcher some more. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 9 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 | « ui/aura/window_tree_host.h ('k') | ui/aura/window_tree_host_delegate.h » ('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) 2013 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2013 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.h" 5 #include "ui/aura/window_tree_host.h"
6 6
7 #include "base/debug/trace_event.h" 7 #include "base/debug/trace_event.h"
8 #include "ui/aura/client/capture_client.h"
9 #include "ui/aura/client/cursor_client.h" 8 #include "ui/aura/client/cursor_client.h"
10 #include "ui/aura/env.h" 9 #include "ui/aura/env.h"
11 #include "ui/aura/root_window_transformer.h" 10 #include "ui/aura/root_window_transformer.h"
12 #include "ui/aura/window.h" 11 #include "ui/aura/window.h"
13 #include "ui/aura/window_event_dispatcher.h" 12 #include "ui/aura/window_event_dispatcher.h"
14 #include "ui/aura/window_targeter.h" 13 #include "ui/aura/window_targeter.h"
14 #include "ui/aura/window_tree_host_delegate.h"
15 #include "ui/aura/window_tree_host_observer.h" 15 #include "ui/aura/window_tree_host_observer.h"
16 #include "ui/base/view_prop.h" 16 #include "ui/base/view_prop.h"
17 #include "ui/compositor/dip_util.h" 17 #include "ui/compositor/dip_util.h"
18 #include "ui/compositor/layer.h" 18 #include "ui/compositor/layer.h"
19 #include "ui/gfx/display.h" 19 #include "ui/gfx/display.h"
20 #include "ui/gfx/insets.h" 20 #include "ui/gfx/insets.h"
21 #include "ui/gfx/point.h" 21 #include "ui/gfx/point.h"
22 #include "ui/gfx/point3_f.h" 22 #include "ui/gfx/point3_f.h"
23 #include "ui/gfx/point_conversions.h" 23 #include "ui/gfx/point_conversions.h"
24 #include "ui/gfx/screen.h" 24 #include "ui/gfx/screen.h"
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
77 DISALLOW_COPY_AND_ASSIGN(SimpleRootWindowTransformer); 77 DISALLOW_COPY_AND_ASSIGN(SimpleRootWindowTransformer);
78 }; 78 };
79 79
80 //////////////////////////////////////////////////////////////////////////////// 80 ////////////////////////////////////////////////////////////////////////////////
81 // WindowTreeHost, public: 81 // WindowTreeHost, public:
82 82
83 WindowTreeHost::~WindowTreeHost() { 83 WindowTreeHost::~WindowTreeHost() {
84 DCHECK(!compositor_) << "compositor must be destroyed before root window"; 84 DCHECK(!compositor_) << "compositor must be destroyed before root window";
85 } 85 }
86 86
87 #if defined(OS_ANDROID)
88 // static
89 WindowTreeHost* WindowTreeHost::Create(const gfx::Rect& bounds) {
90 // This is only hit for tests and ash, right now these aren't an issue so
91 // adding the CHECK.
92 // TODO(sky): decide if we want a factory.
93 CHECK(false);
94 return NULL;
95 }
96 #endif
97
98 // static 87 // static
99 WindowTreeHost* WindowTreeHost::GetForAcceleratedWidget( 88 WindowTreeHost* WindowTreeHost::GetForAcceleratedWidget(
100 gfx::AcceleratedWidget widget) { 89 gfx::AcceleratedWidget widget) {
101 return reinterpret_cast<WindowTreeHost*>( 90 return reinterpret_cast<WindowTreeHost*>(
102 ui::ViewProp::GetValue(widget, kWindowTreeHostForAcceleratedWidget)); 91 ui::ViewProp::GetValue(widget, kWindowTreeHostForAcceleratedWidget));
103 } 92 }
104 93
105 void WindowTreeHost::InitHost() { 94 void WindowTreeHost::InitHost() {
106 InitCompositor(); 95 InitCompositor();
107 UpdateRootWindowSize(GetBounds().size()); 96 UpdateRootWindowSize(GetBounds().size());
108 Env::GetInstance()->NotifyRootWindowInitialized(dispatcher()); 97 Env::GetInstance()->NotifyRootWindowInitialized(delegate_->AsDispatcher());
109 window()->Show(); 98 window()->Show();
110 } 99 }
111 100
112 void WindowTreeHost::InitCompositor() { 101 void WindowTreeHost::InitCompositor() {
113 compositor_->SetScaleAndSize(GetDeviceScaleFactorFromDisplay(window()), 102 compositor_->SetScaleAndSize(GetDeviceScaleFactorFromDisplay(window()),
114 GetBounds().size()); 103 GetBounds().size());
115 compositor_->SetRootLayer(window()->layer()); 104 compositor_->SetRootLayer(window()->layer());
116 transformer_.reset( 105 transformer_.reset(
117 new SimpleRootWindowTransformer(window(), gfx::Transform())); 106 new SimpleRootWindowTransformer(window(), gfx::Transform()));
118 } 107 }
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after
191 // so just pass everything along to the host. 180 // so just pass everything along to the host.
192 SetCursorNative(cursor); 181 SetCursorNative(cursor);
193 } 182 }
194 183
195 void WindowTreeHost::OnCursorVisibilityChanged(bool show) { 184 void WindowTreeHost::OnCursorVisibilityChanged(bool show) {
196 // Clear any existing mouse hover effects when the cursor becomes invisible. 185 // Clear any existing mouse hover effects when the cursor becomes invisible.
197 // Note we do not need to dispatch a mouse enter when the cursor becomes 186 // Note we do not need to dispatch a mouse enter when the cursor becomes
198 // visible because that can only happen in response to a mouse event, which 187 // visible because that can only happen in response to a mouse event, which
199 // will trigger its own mouse enter. 188 // will trigger its own mouse enter.
200 if (!show) { 189 if (!show) {
201 dispatcher()->DispatchMouseExitAtPoint( 190 delegate_->AsDispatcher()->DispatchMouseExitAtPoint(
202 dispatcher()->GetLastMouseLocationInRoot()); 191 delegate_->AsDispatcher()->GetLastMouseLocationInRoot());
203 } 192 }
204 193
205 OnCursorVisibilityChangedNative(show); 194 OnCursorVisibilityChangedNative(show);
206 } 195 }
207 196
208 void WindowTreeHost::MoveCursorTo(const gfx::Point& location_in_dip) { 197 void WindowTreeHost::MoveCursorTo(const gfx::Point& location_in_dip) {
209 gfx::Point host_location(location_in_dip); 198 gfx::Point host_location(location_in_dip);
210 ConvertPointToHost(&host_location); 199 ConvertPointToHost(&host_location);
211 MoveCursorToInternal(location_in_dip, host_location); 200 MoveCursorToInternal(location_in_dip, host_location);
212 } 201 }
213 202
214 void WindowTreeHost::MoveCursorToHostLocation(const gfx::Point& host_location) { 203 void WindowTreeHost::MoveCursorToHostLocation(const gfx::Point& host_location) {
215 gfx::Point root_location(host_location); 204 gfx::Point root_location(host_location);
216 ConvertPointFromHost(&root_location); 205 ConvertPointFromHost(&root_location);
217 MoveCursorToInternal(root_location, host_location); 206 MoveCursorToInternal(root_location, host_location);
218 } 207 }
219 208
209 WindowEventDispatcher* WindowTreeHost::GetDispatcher() {
210 return delegate_->AsDispatcher();
211 }
212
220 //////////////////////////////////////////////////////////////////////////////// 213 ////////////////////////////////////////////////////////////////////////////////
221 // WindowTreeHost, protected: 214 // WindowTreeHost, protected:
222 215
223 WindowTreeHost::WindowTreeHost() 216 WindowTreeHost::WindowTreeHost()
224 : window_(new Window(NULL)), 217 : delegate_(NULL),
218 window_(new Window(NULL)),
225 last_cursor_(ui::kCursorNull) { 219 last_cursor_(ui::kCursorNull) {
226 } 220 }
227 221
228 void WindowTreeHost::DestroyCompositor() { 222 void WindowTreeHost::DestroyCompositor() {
229 DCHECK(GetAcceleratedWidget()); 223 DCHECK(GetAcceleratedWidget());
230 compositor_.reset(); 224 compositor_.reset();
231 } 225 }
232 226
233 void WindowTreeHost::DestroyDispatcher() { 227 void WindowTreeHost::DestroyDispatcher() {
228 // An observer may have been added by an animation on the
229 // WindowEventDispatcher.
230 window()->layer()->GetAnimator()->RemoveObserver(dispatcher());
231
234 delete window_; 232 delete window_;
235 window_ = NULL; 233 window_ = NULL;
236 dispatcher_.reset(); 234 dispatcher_.reset();
237 235
238 // TODO(beng): this comment is no longer quite valid since this function 236 // TODO(beng): this comment is no longer quite valid since this function
239 // isn't called from WED, and WED isn't a subclass of Window. So it seems 237 // isn't called from WED, and WED isn't a subclass of Window. So it seems
240 // like we could just rely on ~Window now. 238 // like we could just rely on ~Window now.
241 // Destroy child windows while we're still valid. This is also done by 239 // Destroy child windows while we're still valid. This is also done by
242 // ~Window, but by that time any calls to virtual methods overriden here (such 240 // ~Window, but by that time any calls to virtual methods overriden here (such
243 // as GetRootWindow()) result in Window's implementation. By destroying here 241 // as GetRootWindow()) result in Window's implementation. By destroying here
(...skipping 11 matching lines...) Expand all
255 window()->Init(WINDOW_LAYER_NOT_DRAWN); 253 window()->Init(WINDOW_LAYER_NOT_DRAWN);
256 window()->set_host(this); 254 window()->set_host(this);
257 window()->SetName("RootWindow"); 255 window()->SetName("RootWindow");
258 window()->SetEventTargeter( 256 window()->SetEventTargeter(
259 scoped_ptr<ui::EventTargeter>(new WindowTargeter())); 257 scoped_ptr<ui::EventTargeter>(new WindowTargeter()));
260 prop_.reset(new ui::ViewProp(GetAcceleratedWidget(), 258 prop_.reset(new ui::ViewProp(GetAcceleratedWidget(),
261 kWindowTreeHostForAcceleratedWidget, 259 kWindowTreeHostForAcceleratedWidget,
262 this)); 260 this));
263 dispatcher_.reset(new WindowEventDispatcher(this)); 261 dispatcher_.reset(new WindowEventDispatcher(this));
264 } 262 }
263 delegate_ = dispatcher();
265 } 264 }
266 265
267 void WindowTreeHost::OnHostMoved(const gfx::Point& new_location) { 266 void WindowTreeHost::OnHostMoved(const gfx::Point& new_location) {
268 TRACE_EVENT1("ui", "WindowTreeHost::OnHostMoved", 267 TRACE_EVENT1("ui", "WindowTreeHost::OnHostMoved",
269 "origin", new_location.ToString()); 268 "origin", new_location.ToString());
270 269
271 FOR_EACH_OBSERVER(WindowTreeHostObserver, observers_, 270 FOR_EACH_OBSERVER(WindowTreeHostObserver, observers_,
272 OnHostMoved(this, new_location)); 271 OnHostMoved(this, new_location));
273 } 272 }
274 273
275 void WindowTreeHost::OnHostResized(const gfx::Size& new_size) { 274 void WindowTreeHost::OnHostResized(const gfx::Size& new_size) {
276 // The compositor should have the same size as the native root window host. 275 // The compositor should have the same size as the native root window host.
277 // Get the latest scale from display because it might have been changed. 276 // Get the latest scale from display because it might have been changed.
278 compositor_->SetScaleAndSize(GetDeviceScaleFactorFromDisplay(window()), 277 compositor_->SetScaleAndSize(GetDeviceScaleFactorFromDisplay(window()),
279 new_size); 278 new_size);
280 279
281 gfx::Size layer_size = GetBounds().size(); 280 gfx::Size layer_size = GetBounds().size();
282 // The layer, and the observers should be notified of the 281 // The layer, and the observers should be notified of the
283 // transformed size of the root window. 282 // transformed size of the root window.
284 UpdateRootWindowSize(layer_size); 283 UpdateRootWindowSize(layer_size);
285 FOR_EACH_OBSERVER(WindowTreeHostObserver, observers_, OnHostResized(this)); 284 FOR_EACH_OBSERVER(WindowTreeHostObserver, observers_, OnHostResized(this));
286 dispatcher()->OnHostResized(layer_size); 285 delegate_->OnHostResized(layer_size);
287 } 286 }
288 287
289 void WindowTreeHost::OnHostCloseRequested() { 288 void WindowTreeHost::OnHostCloseRequested() {
290 FOR_EACH_OBSERVER(WindowTreeHostObserver, observers_, 289 FOR_EACH_OBSERVER(WindowTreeHostObserver, observers_,
291 OnHostCloseRequested(this)); 290 OnHostCloseRequested(this));
292 } 291 }
293 292
294 void WindowTreeHost::OnHostActivated() {
295 Env::GetInstance()->RootWindowActivated(dispatcher());
296 }
297
298 void WindowTreeHost::OnHostLostWindowCapture() {
299 Window* capture_window = client::GetCaptureWindow(window());
300 if (capture_window && capture_window->GetRootWindow() == window())
301 capture_window->ReleaseCapture();
302 }
303
304 ////////////////////////////////////////////////////////////////////////////////
305 // WindowTreeHost, private:
306
307 void WindowTreeHost::MoveCursorToInternal(const gfx::Point& root_location, 293 void WindowTreeHost::MoveCursorToInternal(const gfx::Point& root_location,
308 const gfx::Point& host_location) { 294 const gfx::Point& host_location) {
309 MoveCursorToNative(host_location); 295 MoveCursorToNative(host_location);
310 client::CursorClient* cursor_client = client::GetCursorClient(window()); 296 client::CursorClient* cursor_client = client::GetCursorClient(window());
311 if (cursor_client) { 297 if (cursor_client) {
312 const gfx::Display& display = 298 const gfx::Display& display =
313 gfx::Screen::GetScreenFor(window())->GetDisplayNearestWindow(window()); 299 gfx::Screen::GetScreenFor(window())->GetDisplayNearestWindow(window());
314 cursor_client->SetDisplay(display); 300 cursor_client->SetDisplay(display);
315 } 301 }
316 dispatcher()->OnCursorMovedToRootLocation(root_location); 302 delegate_->OnCursorMovedToRootLocation(root_location);
317 } 303 }
318 304
305 #if defined(OS_ANDROID)
306 // static
307 WindowTreeHost* WindowTreeHost::Create(const gfx::Rect& bounds) {
308 // This is only hit for tests and ash, right now these aren't an issue so
309 // adding the CHECK.
310 // TODO(sky): decide if we want a factory.
311 CHECK(false);
312 return NULL;
313 }
314 #endif
315
319 } // namespace aura 316 } // namespace aura
OLDNEW
« no previous file with comments | « ui/aura/window_tree_host.h ('k') | ui/aura/window_tree_host_delegate.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698