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

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

Issue 72503002: Remove some pass-thrus on RootWindow API in favor of exposing the RootWindowHost again. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: . Created 7 years, 1 month 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/root_window.h ('k') | ui/aura/root_window_host_ozone.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) 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/root_window.h" 5 #include "ui/aura/root_window.h"
6 6
7 #include <vector> 7 #include <vector>
8 8
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/command_line.h" 10 #include "base/command_line.h"
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
78 Env::GetInstance()->set_last_mouse_location(location_in_screen); 78 Env::GetInstance()->set_last_mouse_location(location_in_screen);
79 } else { 79 } else {
80 Env::GetInstance()->set_last_mouse_location(location_in_root); 80 Env::GetInstance()->set_last_mouse_location(location_in_root);
81 } 81 }
82 } 82 }
83 83
84 RootWindowHost* CreateHost(RootWindow* root_window, 84 RootWindowHost* CreateHost(RootWindow* root_window,
85 const RootWindow::CreateParams& params) { 85 const RootWindow::CreateParams& params) {
86 RootWindowHost* host = params.host ? 86 RootWindowHost* host = params.host ?
87 params.host : RootWindowHost::Create(params.initial_bounds); 87 params.host : RootWindowHost::Create(params.initial_bounds);
88 host->SetDelegate(root_window); 88 host->set_delegate(root_window);
89 return host; 89 return host;
90 } 90 }
91 91
92 class SimpleRootWindowTransformer : public RootWindowTransformer { 92 class SimpleRootWindowTransformer : public RootWindowTransformer {
93 public: 93 public:
94 SimpleRootWindowTransformer(const Window* root_window, 94 SimpleRootWindowTransformer(const Window* root_window,
95 const gfx::Transform& transform) 95 const gfx::Transform& transform)
96 : root_window_(root_window), 96 : root_window_(root_window),
97 transform_(transform) { 97 transform_(transform) {
98 } 98 }
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after
196 ui::ViewProp::GetValue(widget, kRootWindowForAcceleratedWidget)); 196 ui::ViewProp::GetValue(widget, kRootWindowForAcceleratedWidget));
197 } 197 }
198 198
199 void RootWindow::Init() { 199 void RootWindow::Init() {
200 compositor()->SetScaleAndSize(GetDeviceScaleFactorFromDisplay(window()), 200 compositor()->SetScaleAndSize(GetDeviceScaleFactorFromDisplay(window()),
201 host_->GetBounds().size()); 201 host_->GetBounds().size());
202 window()->Init(ui::LAYER_NOT_DRAWN); 202 window()->Init(ui::LAYER_NOT_DRAWN);
203 compositor()->SetRootLayer(window()->layer()); 203 compositor()->SetRootLayer(window()->layer());
204 transformer_.reset( 204 transformer_.reset(
205 new SimpleRootWindowTransformer(window(), gfx::Transform())); 205 new SimpleRootWindowTransformer(window(), gfx::Transform()));
206 UpdateRootWindowSize(GetHostSize()); 206 UpdateRootWindowSize(host_->GetBounds().size());
207 Env::GetInstance()->NotifyRootWindowInitialized(this); 207 Env::GetInstance()->NotifyRootWindowInitialized(this);
208 window()->Show(); 208 window()->Show();
209 } 209 }
210 210
211 void RootWindow::ShowRootWindow() {
212 host_->Show();
213 }
214
215 void RootWindow::HideRootWindow() {
216 host_->Hide();
217 }
218
219 void RootWindow::PrepareForShutdown() { 211 void RootWindow::PrepareForShutdown() {
220 host_->PrepareForShutdown(); 212 host_->PrepareForShutdown();
221 // discard synthesize event request as well. 213 // discard synthesize event request as well.
222 synthesize_mouse_move_ = false; 214 synthesize_mouse_move_ = false;
223 } 215 }
224 216
225 void RootWindow::RepostEvent(const ui::LocatedEvent& event) { 217 void RootWindow::RepostEvent(const ui::LocatedEvent& event) {
226 DCHECK(event.type() == ui::ET_MOUSE_PRESSED || 218 DCHECK(event.type() == ui::ET_MOUSE_PRESSED ||
227 event.type() == ui::ET_GESTURE_TAP_DOWN); 219 event.type() == ui::ET_GESTURE_TAP_DOWN);
228 // We allow for only one outstanding repostable event. This is used 220 // We allow for only one outstanding repostable event. This is used
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
260 // Requery the location to constrain it within the new root window size. 252 // Requery the location to constrain it within the new root window size.
261 gfx::Point point; 253 gfx::Point point;
262 if (host_->QueryMouseLocation(&point)) { 254 if (host_->QueryMouseLocation(&point)) {
263 SetLastMouseLocation(window(), 255 SetLastMouseLocation(window(),
264 ui::ConvertPointToDIP(window()->layer(), point)); 256 ui::ConvertPointToDIP(window()->layer(), point));
265 } 257 }
266 258
267 synthesize_mouse_move_ = false; 259 synthesize_mouse_move_ = false;
268 } 260 }
269 261
270 gfx::Size RootWindow::GetHostSize() const {
271 return host_->GetBounds().size();
272 }
273
274 void RootWindow::SetHostBounds(const gfx::Rect& bounds_in_pixel) { 262 void RootWindow::SetHostBounds(const gfx::Rect& bounds_in_pixel) {
275 DCHECK(!bounds_in_pixel.IsEmpty()); 263 DCHECK(!bounds_in_pixel.IsEmpty());
276 DispatchDetails details = DispatchHeldEvents(); 264 DispatchDetails details = DispatchHeldEvents();
277 if (details.dispatcher_destroyed) 265 if (details.dispatcher_destroyed)
278 return; 266 return;
279 host_->SetBounds(bounds_in_pixel); 267 host_->SetBounds(bounds_in_pixel);
280 synthesize_mouse_move_ = false; 268 synthesize_mouse_move_ = false;
281 } 269 }
282 270
283 gfx::Point RootWindow::GetHostOrigin() const {
284 return host_->GetBounds().origin();
285 }
286
287 void RootWindow::SetCursor(gfx::NativeCursor cursor) { 271 void RootWindow::SetCursor(gfx::NativeCursor cursor) {
288 last_cursor_ = cursor; 272 last_cursor_ = cursor;
289 // A lot of code seems to depend on NULL cursors actually showing an arrow, 273 // A lot of code seems to depend on NULL cursors actually showing an arrow,
290 // so just pass everything along to the host. 274 // so just pass everything along to the host.
291 host_->SetCursor(cursor); 275 host_->SetCursor(cursor);
292 } 276 }
293 277
294 void RootWindow::OnCursorVisibilityChanged(bool show) { 278 void RootWindow::OnCursorVisibilityChanged(bool show) {
295 // Clear any existing mouse hover effects when the cursor becomes invisible. 279 // Clear any existing mouse hover effects when the cursor becomes invisible.
296 // Note we do not need to dispatch a mouse enter when the cursor becomes 280 // Note we do not need to dispatch a mouse enter when the cursor becomes
(...skipping 17 matching lines...) Expand all
314 ConvertPointToHost(&host_location); 298 ConvertPointToHost(&host_location);
315 MoveCursorToInternal(location_in_dip, host_location); 299 MoveCursorToInternal(location_in_dip, host_location);
316 } 300 }
317 301
318 void RootWindow::MoveCursorToHostLocation(const gfx::Point& host_location) { 302 void RootWindow::MoveCursorToHostLocation(const gfx::Point& host_location) {
319 gfx::Point root_location(host_location); 303 gfx::Point root_location(host_location);
320 ConvertPointFromHost(&root_location); 304 ConvertPointFromHost(&root_location);
321 MoveCursorToInternal(root_location, host_location); 305 MoveCursorToInternal(root_location, host_location);
322 } 306 }
323 307
324 bool RootWindow::ConfineCursorToWindow() {
325 // We would like to be able to confine the cursor to that window. However,
326 // currently, we do not have such functionality in X. So we just confine
327 // to the root window. This is ok because this option is currently only
328 // being used in fullscreen mode, so root_window bounds = window bounds.
329 return host_->ConfineCursorToRootWindow();
330 }
331
332 void RootWindow::UnConfineCursor() {
333 host_->UnConfineCursor();
334 }
335
336 void RootWindow::ScheduleRedrawRect(const gfx::Rect& damage_rect) { 308 void RootWindow::ScheduleRedrawRect(const gfx::Rect& damage_rect) {
337 compositor_->ScheduleRedrawRect(damage_rect); 309 compositor_->ScheduleRedrawRect(damage_rect);
338 } 310 }
339 311
340 Window* RootWindow::GetGestureTarget(ui::GestureEvent* event) { 312 Window* RootWindow::GetGestureTarget(ui::GestureEvent* event) {
341 Window* target = client::GetCaptureWindow(window()); 313 Window* target = client::GetCaptureWindow(window());
342 if (!target) { 314 if (!target) {
343 target = ConsumerToWindow( 315 target = ConsumerToWindow(
344 ui::GestureRecognizer::Get()->GetTargetForGestureEvent(event)); 316 ui::GestureRecognizer::Get()->GetTargetForGestureEvent(event));
345 } 317 }
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after
427 } 399 }
428 400
429 void RootWindow::AddRootWindowObserver(RootWindowObserver* observer) { 401 void RootWindow::AddRootWindowObserver(RootWindowObserver* observer) {
430 observers_.AddObserver(observer); 402 observers_.AddObserver(observer);
431 } 403 }
432 404
433 void RootWindow::RemoveRootWindowObserver(RootWindowObserver* observer) { 405 void RootWindow::RemoveRootWindowObserver(RootWindowObserver* observer) {
434 observers_.RemoveObserver(observer); 406 observers_.RemoveObserver(observer);
435 } 407 }
436 408
437 void RootWindow::PostNativeEvent(const base::NativeEvent& native_event) {
438 host_->PostNativeEvent(native_event);
439 }
440
441 void RootWindow::ConvertPointToNativeScreen(gfx::Point* point) const {
442 ConvertPointToHost(point);
443 gfx::Point location = host_->GetLocationOnNativeScreen();
444 point->Offset(location.x(), location.y());
445 }
446
447 void RootWindow::ConvertPointFromNativeScreen(gfx::Point* point) const {
448 gfx::Point location = host_->GetLocationOnNativeScreen();
449 point->Offset(-location.x(), -location.y());
450 ConvertPointFromHost(point);
451 }
452
453 void RootWindow::ConvertPointToHost(gfx::Point* point) const { 409 void RootWindow::ConvertPointToHost(gfx::Point* point) const {
454 gfx::Point3F point_3f(*point); 410 gfx::Point3F point_3f(*point);
455 GetRootTransform().TransformPoint(&point_3f); 411 GetRootTransform().TransformPoint(&point_3f);
456 *point = gfx::ToFlooredPoint(point_3f.AsPointF()); 412 *point = gfx::ToFlooredPoint(point_3f.AsPointF());
457 } 413 }
458 414
459 void RootWindow::ConvertPointFromHost(gfx::Point* point) const { 415 void RootWindow::ConvertPointFromHost(gfx::Point* point) const {
460 gfx::Point3F point_3f(*point); 416 gfx::Point3F point_3f(*point);
461 GetInverseRootTransform().TransformPoint(&point_3f); 417 GetInverseRootTransform().TransformPoint(&point_3f);
462 *point = gfx::ToFlooredPoint(point_3f.AsPointF()); 418 *point = gfx::ToFlooredPoint(point_3f.AsPointF());
463 } 419 }
464 420
465 void RootWindow::ProcessedTouchEvent(ui::TouchEvent* event, 421 void RootWindow::ProcessedTouchEvent(ui::TouchEvent* event,
466 Window* window, 422 Window* window,
467 ui::EventResult result) { 423 ui::EventResult result) {
468 scoped_ptr<ui::GestureRecognizer::Gestures> gestures; 424 scoped_ptr<ui::GestureRecognizer::Gestures> gestures;
469 gestures.reset(ui::GestureRecognizer::Get()-> 425 gestures.reset(ui::GestureRecognizer::Get()->
470 ProcessTouchEventForGesture(*event, result, window)); 426 ProcessTouchEventForGesture(*event, result, window));
471 DispatchDetails details = ProcessGestures(gestures.get()); 427 DispatchDetails details = ProcessGestures(gestures.get());
472 if (details.dispatcher_destroyed) 428 if (details.dispatcher_destroyed)
473 return; 429 return;
474 } 430 }
475 431
476 gfx::AcceleratedWidget RootWindow::GetAcceleratedWidget() {
477 return host_->GetAcceleratedWidget();
478 }
479
480 void RootWindow::ToggleFullScreen() {
481 host_->ToggleFullScreen();
482 }
483
484 void RootWindow::HoldPointerMoves() { 432 void RootWindow::HoldPointerMoves() {
485 if (!move_hold_count_) 433 if (!move_hold_count_)
486 held_event_factory_.InvalidateWeakPtrs(); 434 held_event_factory_.InvalidateWeakPtrs();
487 ++move_hold_count_; 435 ++move_hold_count_;
488 TRACE_EVENT_ASYNC_BEGIN0("ui", "RootWindow::HoldPointerMoves", this); 436 TRACE_EVENT_ASYNC_BEGIN0("ui", "RootWindow::HoldPointerMoves", this);
489 } 437 }
490 438
491 void RootWindow::ReleasePointerMoves() { 439 void RootWindow::ReleasePointerMoves() {
492 --move_hold_count_; 440 --move_hold_count_;
493 DCHECK_GE(move_hold_count_, 0); 441 DCHECK_GE(move_hold_count_, 0);
494 if (!move_hold_count_ && held_move_event_) { 442 if (!move_hold_count_ && held_move_event_) {
495 // We don't want to call DispatchHeldEvents directly, because this might be 443 // We don't want to call DispatchHeldEvents directly, because this might be
496 // called from a deep stack while another event, in which case dispatching 444 // called from a deep stack while another event, in which case dispatching
497 // another one may not be safe/expected. Instead we post a task, that we 445 // another one may not be safe/expected. Instead we post a task, that we
498 // may cancel if HoldPointerMoves is called again before it executes. 446 // may cancel if HoldPointerMoves is called again before it executes.
499 base::MessageLoop::current()->PostTask( 447 base::MessageLoop::current()->PostTask(
500 FROM_HERE, 448 FROM_HERE,
501 base::Bind(&RootWindow::DispatchHeldEventsAsync, 449 base::Bind(&RootWindow::DispatchHeldEventsAsync,
502 held_event_factory_.GetWeakPtr())); 450 held_event_factory_.GetWeakPtr()));
503 } 451 }
504 TRACE_EVENT_ASYNC_END0("ui", "RootWindow::HoldPointerMoves", this); 452 TRACE_EVENT_ASYNC_END0("ui", "RootWindow::HoldPointerMoves", this);
505 } 453 }
506 454
507 void RootWindow::SetFocusWhenShown(bool focused) {
508 host_->SetFocusWhenShown(focused);
509 }
510
511 gfx::Point RootWindow::GetLastMouseLocationInRoot() const { 455 gfx::Point RootWindow::GetLastMouseLocationInRoot() const {
512 gfx::Point location = Env::GetInstance()->last_mouse_location(); 456 gfx::Point location = Env::GetInstance()->last_mouse_location();
513 client::ScreenPositionClient* client = 457 client::ScreenPositionClient* client =
514 client::GetScreenPositionClient(window()); 458 client::GetScreenPositionClient(window());
515 if (client) 459 if (client)
516 client->ConvertPointFromScreen(window(), &location); 460 client->ConvertPointFromScreen(window(), &location);
517 return location; 461 return location;
518 } 462 }
519 463
520 bool RootWindow::QueryMouseLocationForTest(gfx::Point* point) const {
521 return host_->QueryMouseLocation(point);
522 }
523
524 void RootWindow::SetRootWindowTransformer( 464 void RootWindow::SetRootWindowTransformer(
525 scoped_ptr<RootWindowTransformer> transformer) { 465 scoped_ptr<RootWindowTransformer> transformer) {
526 transformer_ = transformer.Pass(); 466 transformer_ = transformer.Pass();
527 host_->SetInsets(transformer_->GetHostInsets()); 467 host_->SetInsets(transformer_->GetHostInsets());
528 window()->SetTransform(transformer_->GetTransform()); 468 window()->SetTransform(transformer_->GetTransform());
529 // If the layer is not animating, then we need to update the root window 469 // If the layer is not animating, then we need to update the root window
530 // size immediately. 470 // size immediately.
531 if (!window()->layer()->GetAnimator()->is_animating()) 471 if (!window()->layer()->GetAnimator()->is_animating())
532 UpdateRootWindowSize(GetHostSize()); 472 UpdateRootWindowSize(host_->GetBounds().size());
533 } 473 }
534 474
535 gfx::Transform RootWindow::GetRootTransform() const { 475 gfx::Transform RootWindow::GetRootTransform() const {
536 float scale = ui::GetDeviceScaleFactor(window()->layer()); 476 float scale = ui::GetDeviceScaleFactor(window()->layer());
537 gfx::Transform transform; 477 gfx::Transform transform;
538 transform.Scale(scale, scale); 478 transform.Scale(scale, scale);
539 transform *= transformer_->GetTransform(); 479 transform *= transformer_->GetTransform();
540 return transform; 480 return transform;
541 } 481 }
542 482
543 void RootWindow::SetTransform(const gfx::Transform& transform) { 483 void RootWindow::SetTransform(const gfx::Transform& transform) {
544 scoped_ptr<RootWindowTransformer> transformer( 484 scoped_ptr<RootWindowTransformer> transformer(
545 new SimpleRootWindowTransformer(window(), transform)); 485 new SimpleRootWindowTransformer(window(), transform));
546 SetRootWindowTransformer(transformer.Pass()); 486 SetRootWindowTransformer(transformer.Pass());
547 } 487 }
548 488
549 void RootWindow::DeviceScaleFactorChanged(float device_scale_factor) {
550 host_->OnDeviceScaleFactorChanged(device_scale_factor);
551 }
552
553 //////////////////////////////////////////////////////////////////////////////// 489 ////////////////////////////////////////////////////////////////////////////////
554 // RootWindow, private: 490 // RootWindow, private:
555 491
556 void RootWindow::TransformEventForDeviceScaleFactor(ui::LocatedEvent* event) { 492 void RootWindow::TransformEventForDeviceScaleFactor(ui::LocatedEvent* event) {
557 event->UpdateForRootTransform(GetInverseRootTransform()); 493 event->UpdateForRootTransform(GetInverseRootTransform());
558 } 494 }
559 495
560 void RootWindow::MoveCursorToInternal(const gfx::Point& root_location, 496 void RootWindow::MoveCursorToInternal(const gfx::Point& root_location,
561 const gfx::Point& host_location) { 497 const gfx::Point& host_location) {
562 host_->MoveCursorTo(host_location); 498 host_->MoveCursorTo(host_location);
(...skipping 184 matching lines...) Expand 10 before | Expand all | Expand 10 after
747 683
748 void RootWindow::DispatchCancelTouchEvent(ui::TouchEvent* event) { 684 void RootWindow::DispatchCancelTouchEvent(ui::TouchEvent* event) {
749 OnHostTouchEvent(event); 685 OnHostTouchEvent(event);
750 } 686 }
751 687
752 //////////////////////////////////////////////////////////////////////////////// 688 ////////////////////////////////////////////////////////////////////////////////
753 // RootWindow, ui::LayerAnimationObserver implementation: 689 // RootWindow, ui::LayerAnimationObserver implementation:
754 690
755 void RootWindow::OnLayerAnimationEnded( 691 void RootWindow::OnLayerAnimationEnded(
756 ui::LayerAnimationSequence* animation) { 692 ui::LayerAnimationSequence* animation) {
757 UpdateRootWindowSize(GetHostSize()); 693 UpdateRootWindowSize(host_->GetBounds().size());
758 } 694 }
759 695
760 void RootWindow::OnLayerAnimationScheduled( 696 void RootWindow::OnLayerAnimationScheduled(
761 ui::LayerAnimationSequence* animation) { 697 ui::LayerAnimationSequence* animation) {
762 } 698 }
763 699
764 void RootWindow::OnLayerAnimationAborted( 700 void RootWindow::OnLayerAnimationAborted(
765 ui::LayerAnimationSequence* animation) { 701 ui::LayerAnimationSequence* animation) {
766 } 702 }
767 703
(...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after
899 } 835 }
900 836
901 float RootWindow::GetDeviceScaleFactor() { 837 float RootWindow::GetDeviceScaleFactor() {
902 return compositor()->device_scale_factor(); 838 return compositor()->device_scale_factor();
903 } 839 }
904 840
905 RootWindow* RootWindow::AsRootWindow() { 841 RootWindow* RootWindow::AsRootWindow() {
906 return this; 842 return this;
907 } 843 }
908 844
845 const RootWindow* RootWindow::AsRootWindow() const {
846 return this;
847 }
848
909 //////////////////////////////////////////////////////////////////////////////// 849 ////////////////////////////////////////////////////////////////////////////////
910 // RootWindow, private: 850 // RootWindow, private:
911 851
912 ui::EventDispatchDetails RootWindow::OnHostMouseEventImpl( 852 ui::EventDispatchDetails RootWindow::OnHostMouseEventImpl(
913 ui::MouseEvent* event) { 853 ui::MouseEvent* event) {
914 if (event->type() == ui::ET_MOUSE_DRAGGED || 854 if (event->type() == ui::ET_MOUSE_DRAGGED ||
915 (event->flags() & ui::EF_IS_SYNTHESIZED)) { 855 (event->flags() & ui::EF_IS_SYNTHESIZED)) {
916 if (move_hold_count_) { 856 if (move_hold_count_) {
917 Window* null_window = static_cast<Window*>(NULL); 857 Window* null_window = static_cast<Window*>(NULL);
918 held_move_event_.reset( 858 held_move_event_.reset(
(...skipping 266 matching lines...) Expand 10 before | Expand all | Expand 10 after
1185 } 1125 }
1186 1126
1187 gfx::Transform RootWindow::GetInverseRootTransform() const { 1127 gfx::Transform RootWindow::GetInverseRootTransform() const {
1188 float scale = ui::GetDeviceScaleFactor(window()->layer()); 1128 float scale = ui::GetDeviceScaleFactor(window()->layer());
1189 gfx::Transform transform; 1129 gfx::Transform transform;
1190 transform.Scale(1.0f / scale, 1.0f / scale); 1130 transform.Scale(1.0f / scale, 1.0f / scale);
1191 return transformer_->GetInverseTransform() * transform; 1131 return transformer_->GetInverseTransform() * transform;
1192 } 1132 }
1193 1133
1194 } // namespace aura 1134 } // namespace aura
OLDNEW
« no previous file with comments | « ui/aura/root_window.h ('k') | ui/aura/root_window_host_ozone.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698