| OLD | NEW |
| 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/auto_reset.h" | 9 #include "base/auto_reset.h" |
| 10 #include "base/bind.h" | 10 #include "base/bind.h" |
| (...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 112 event_dispatch_target_(NULL), | 112 event_dispatch_target_(NULL), |
| 113 ALLOW_THIS_IN_INITIALIZER_LIST( | 113 ALLOW_THIS_IN_INITIALIZER_LIST( |
| 114 gesture_recognizer_(ui::GestureRecognizer::Create(this))), | 114 gesture_recognizer_(ui::GestureRecognizer::Create(this))), |
| 115 synthesize_mouse_move_(false), | 115 synthesize_mouse_move_(false), |
| 116 waiting_on_compositing_end_(false), | 116 waiting_on_compositing_end_(false), |
| 117 draw_on_compositing_end_(false), | 117 draw_on_compositing_end_(false), |
| 118 defer_draw_scheduling_(false), | 118 defer_draw_scheduling_(false), |
| 119 mouse_move_hold_count_(0), | 119 mouse_move_hold_count_(0), |
| 120 ALLOW_THIS_IN_INITIALIZER_LIST(held_mouse_event_factory_(this)) { | 120 ALLOW_THIS_IN_INITIALIZER_LIST(held_mouse_event_factory_(this)) { |
| 121 SetName("RootWindow"); | 121 SetName("RootWindow"); |
| 122 host_->SetInsets(params.initial_insets); |
| 122 | 123 |
| 123 compositor_.reset(new ui::Compositor(this, host_->GetAcceleratedWidget())); | 124 compositor_.reset(new ui::Compositor(this, host_->GetAcceleratedWidget())); |
| 124 DCHECK(compositor_.get()); | 125 DCHECK(compositor_.get()); |
| 125 compositor_->AddObserver(this); | 126 compositor_->AddObserver(this); |
| 126 | 127 |
| 127 prop_.reset(new ui::ViewProp(host_->GetAcceleratedWidget(), | 128 prop_.reset(new ui::ViewProp(host_->GetAcceleratedWidget(), |
| 128 kRootWindowForAcceleratedWidget, | 129 kRootWindowForAcceleratedWidget, |
| 129 this)); | 130 this)); |
| 130 } | 131 } |
| 131 | 132 |
| (...skipping 15 matching lines...) Expand all Loading... |
| 147 gfx::AcceleratedWidget widget) { | 148 gfx::AcceleratedWidget widget) { |
| 148 return reinterpret_cast<RootWindow*>( | 149 return reinterpret_cast<RootWindow*>( |
| 149 ui::ViewProp::GetValue(widget, kRootWindowForAcceleratedWidget)); | 150 ui::ViewProp::GetValue(widget, kRootWindowForAcceleratedWidget)); |
| 150 } | 151 } |
| 151 | 152 |
| 152 void RootWindow::Init() { | 153 void RootWindow::Init() { |
| 153 compositor()->SetScaleAndSize(GetDeviceScaleFactorFromDisplay(this), | 154 compositor()->SetScaleAndSize(GetDeviceScaleFactorFromDisplay(this), |
| 154 host_->GetBounds().size()); | 155 host_->GetBounds().size()); |
| 155 Window::Init(ui::LAYER_NOT_DRAWN); | 156 Window::Init(ui::LAYER_NOT_DRAWN); |
| 156 compositor()->SetRootLayer(layer()); | 157 compositor()->SetRootLayer(layer()); |
| 157 SetBounds( | 158 SetTransformInternal(gfx::Transform()); |
| 158 ui::ConvertRectToDIP(layer(), gfx::Rect(host_->GetBounds().size()))); | 159 UpdateWindowSize(host_->GetBounds().size()); |
| 159 Env::GetInstance()->NotifyRootWindowInitialized(this); | 160 Env::GetInstance()->NotifyRootWindowInitialized(this); |
| 160 Show(); | 161 Show(); |
| 161 } | 162 } |
| 162 | 163 |
| 163 void RootWindow::ShowRootWindow() { | 164 void RootWindow::ShowRootWindow() { |
| 164 host_->Show(); | 165 host_->Show(); |
| 165 } | 166 } |
| 166 | 167 |
| 167 void RootWindow::HideRootWindow() { | 168 void RootWindow::HideRootWindow() { |
| 168 host_->Hide(); | 169 host_->Hide(); |
| (...skipping 21 matching lines...) Expand all Loading... |
| 190 SetLastMouseLocation(this, ui::ConvertPointToDIP(layer(), point)); | 191 SetLastMouseLocation(this, ui::ConvertPointToDIP(layer(), point)); |
| 191 | 192 |
| 192 synthesize_mouse_move_ = false; | 193 synthesize_mouse_move_ = false; |
| 193 } | 194 } |
| 194 | 195 |
| 195 gfx::Size RootWindow::GetHostSize() const { | 196 gfx::Size RootWindow::GetHostSize() const { |
| 196 return host_->GetBounds().size(); | 197 return host_->GetBounds().size(); |
| 197 } | 198 } |
| 198 | 199 |
| 199 void RootWindow::SetHostBounds(const gfx::Rect& bounds_in_pixel) { | 200 void RootWindow::SetHostBounds(const gfx::Rect& bounds_in_pixel) { |
| 201 SetHostBoundsAndInsets(bounds_in_pixel, gfx::Insets()); |
| 202 } |
| 203 |
| 204 void RootWindow::SetHostBoundsAndInsets(const gfx::Rect& bounds_in_pixel, |
| 205 const gfx::Insets& insets_in_pixel) { |
| 200 DCHECK(!bounds_in_pixel.IsEmpty()); | 206 DCHECK(!bounds_in_pixel.IsEmpty()); |
| 201 DispatchHeldMouseMove(); | 207 DispatchHeldMouseMove(); |
| 208 host_->SetInsets(insets_in_pixel); |
| 202 host_->SetBounds(bounds_in_pixel); | 209 host_->SetBounds(bounds_in_pixel); |
| 203 synthesize_mouse_move_ = false; | 210 synthesize_mouse_move_ = false; |
| 204 } | 211 } |
| 205 | 212 |
| 206 gfx::Point RootWindow::GetHostOrigin() const { | 213 gfx::Point RootWindow::GetHostOrigin() const { |
| 207 return host_->GetBounds().origin(); | 214 return host_->GetBounds().origin(); |
| 208 } | 215 } |
| 209 | 216 |
| 210 void RootWindow::SetCursor(gfx::NativeCursor cursor) { | 217 void RootWindow::SetCursor(gfx::NativeCursor cursor) { |
| 211 last_cursor_ = cursor; | 218 last_cursor_ = cursor; |
| (...skipping 224 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 436 | 443 |
| 437 RootWindow* RootWindow::GetRootWindow() { | 444 RootWindow* RootWindow::GetRootWindow() { |
| 438 return this; | 445 return this; |
| 439 } | 446 } |
| 440 | 447 |
| 441 const RootWindow* RootWindow::GetRootWindow() const { | 448 const RootWindow* RootWindow::GetRootWindow() const { |
| 442 return this; | 449 return this; |
| 443 } | 450 } |
| 444 | 451 |
| 445 void RootWindow::SetTransform(const gfx::Transform& transform) { | 452 void RootWindow::SetTransform(const gfx::Transform& transform) { |
| 446 Window::SetTransform(transform); | 453 SetTransformInternal(transform); |
| 447 | 454 |
| 448 // If the layer is not animating, then we need to update the host size | 455 // If the layer is not animating, then we need to update the host size |
| 449 // immediately. | 456 // immediately. |
| 450 if (!layer()->GetAnimator()->is_animating()) | 457 if (!layer()->GetAnimator()->is_animating()) |
| 451 OnHostResized(host_->GetBounds().size()); | 458 OnHostResized(host_->GetBounds().size()); |
| 452 } | 459 } |
| 453 | 460 |
| 461 void RootWindow::SetTransformInternal(const gfx::Transform& transform) { |
| 462 gfx::Insets insets = host_->GetInsets(); |
| 463 if (insets.top() != 0 || insets.left() != 0) { |
| 464 float device_scale_factor = GetDeviceScaleFactor(); |
| 465 gfx::Transform translate; |
| 466 translate.Translate(insets.left() / device_scale_factor, |
| 467 insets.top() / device_scale_factor); |
| 468 Window::SetTransform(translate * transform); |
| 469 } else { |
| 470 Window::SetTransform(transform); |
| 471 } |
| 472 } |
| 473 |
| 454 //////////////////////////////////////////////////////////////////////////////// | 474 //////////////////////////////////////////////////////////////////////////////// |
| 455 // RootWindow, ui::EventTarget implementation: | 475 // RootWindow, ui::EventTarget implementation: |
| 456 | 476 |
| 457 ui::EventTarget* RootWindow::GetParentTarget() { | 477 ui::EventTarget* RootWindow::GetParentTarget() { |
| 458 return client::GetEventClient(this) ? | 478 return client::GetEventClient(this) ? |
| 459 client::GetEventClient(this)->GetToplevelEventTarget() : | 479 client::GetEventClient(this)->GetToplevelEventTarget() : |
| 460 Env::GetInstance(); | 480 Env::GetInstance(); |
| 461 } | 481 } |
| 462 | 482 |
| 463 //////////////////////////////////////////////////////////////////////////////// | 483 //////////////////////////////////////////////////////////////////////////////// |
| (...skipping 251 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 715 void RootWindow::CleanupGestureRecognizerState(Window* window) { | 735 void RootWindow::CleanupGestureRecognizerState(Window* window) { |
| 716 gesture_recognizer_->CleanupStateForConsumer(window); | 736 gesture_recognizer_->CleanupStateForConsumer(window); |
| 717 Windows windows = window->children(); | 737 Windows windows = window->children(); |
| 718 for (Windows::const_iterator iter = windows.begin(); | 738 for (Windows::const_iterator iter = windows.begin(); |
| 719 iter != windows.end(); | 739 iter != windows.end(); |
| 720 ++iter) { | 740 ++iter) { |
| 721 CleanupGestureRecognizerState(*iter); | 741 CleanupGestureRecognizerState(*iter); |
| 722 } | 742 } |
| 723 } | 743 } |
| 724 | 744 |
| 745 void RootWindow::UpdateWindowSize(const gfx::Size& host_size) { |
| 746 gfx::Rect bounds(host_size); |
| 747 bounds.Inset(host_->GetInsets()); |
| 748 bounds = ui::ConvertRectToDIP(layer(), bounds); |
| 749 gfx::RectF new_bounds(bounds); |
| 750 layer()->transform().TransformRect(&new_bounds); |
| 751 // Ignore the origin because RootWindow's insets are handled by |
| 752 // the transform. |
| 753 SetBounds(gfx::Rect(gfx::ToNearestRect(new_bounds).size())); |
| 754 } |
| 755 |
| 725 void RootWindow::OnWindowAddedToRootWindow(Window* attached) { | 756 void RootWindow::OnWindowAddedToRootWindow(Window* attached) { |
| 726 if (attached->IsVisible() && | 757 if (attached->IsVisible() && |
| 727 attached->ContainsPointInRoot(GetLastMouseLocationInRoot())) | 758 attached->ContainsPointInRoot(GetLastMouseLocationInRoot())) |
| 728 PostMouseMoveEventAfterWindowChange(); | 759 PostMouseMoveEventAfterWindowChange(); |
| 729 } | 760 } |
| 730 | 761 |
| 731 bool RootWindow::CanDispatchToTarget(ui::EventTarget* target) { | 762 bool RootWindow::CanDispatchToTarget(ui::EventTarget* target) { |
| 732 return event_dispatch_target_ == target; | 763 return event_dispatch_target_ == target; |
| 733 } | 764 } |
| 734 | 765 |
| (...skipping 182 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 917 | 948 |
| 918 void RootWindow::OnHostResized(const gfx::Size& size) { | 949 void RootWindow::OnHostResized(const gfx::Size& size) { |
| 919 DispatchHeldMouseMove(); | 950 DispatchHeldMouseMove(); |
| 920 // The compositor should have the same size as the native root window host. | 951 // The compositor should have the same size as the native root window host. |
| 921 // Get the latest scale from display because it might have been changed. | 952 // Get the latest scale from display because it might have been changed. |
| 922 compositor_->SetScaleAndSize(GetDeviceScaleFactorFromDisplay(this), size); | 953 compositor_->SetScaleAndSize(GetDeviceScaleFactorFromDisplay(this), size); |
| 923 | 954 |
| 924 // The layer, and all the observers should be notified of the | 955 // The layer, and all the observers should be notified of the |
| 925 // transformed size of the root window. | 956 // transformed size of the root window. |
| 926 gfx::Size old(bounds().size()); | 957 gfx::Size old(bounds().size()); |
| 927 gfx::RectF bounds(ui::ConvertSizeToDIP(layer(), size)); | 958 UpdateWindowSize(size); |
| 928 layer()->transform().TransformRect(&bounds); | 959 // TODO(oshima): Rename this to OnHostWindowResized. |
| 929 // The transform is expected to produce an integer rect as its output. | |
| 930 SetBounds(gfx::ToNearestRect(bounds)); | |
| 931 FOR_EACH_OBSERVER(RootWindowObserver, observers_, | 960 FOR_EACH_OBSERVER(RootWindowObserver, observers_, |
| 932 OnRootWindowResized(this, old)); | 961 OnRootWindowResized(this, old)); |
| 933 } | 962 } |
| 934 | 963 |
| 935 float RootWindow::GetDeviceScaleFactor() { | 964 float RootWindow::GetDeviceScaleFactor() { |
| 936 return compositor()->device_scale_factor(); | 965 return compositor()->device_scale_factor(); |
| 937 } | 966 } |
| 938 | 967 |
| 939 RootWindow* RootWindow::AsRootWindow() { | 968 RootWindow* RootWindow::AsRootWindow() { |
| 940 return this; | 969 return this; |
| (...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1039 // currently broken. See/ crbug.com/107931. | 1068 // currently broken. See/ crbug.com/107931. |
| 1040 ui::MouseEvent event(ui::ET_MOUSE_MOVED, | 1069 ui::MouseEvent event(ui::ET_MOUSE_MOVED, |
| 1041 orig_mouse_location, | 1070 orig_mouse_location, |
| 1042 orig_mouse_location, | 1071 orig_mouse_location, |
| 1043 ui::EF_IS_SYNTHESIZED); | 1072 ui::EF_IS_SYNTHESIZED); |
| 1044 event.set_system_location(Env::GetInstance()->last_mouse_location()); | 1073 event.set_system_location(Env::GetInstance()->last_mouse_location()); |
| 1045 OnHostMouseEvent(&event); | 1074 OnHostMouseEvent(&event); |
| 1046 } | 1075 } |
| 1047 | 1076 |
| 1048 } // namespace aura | 1077 } // namespace aura |
| OLD | NEW |