| 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 141 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 152 gfx::AcceleratedWidget widget) { | 152 gfx::AcceleratedWidget widget) { |
| 153 return reinterpret_cast<RootWindow*>( | 153 return reinterpret_cast<RootWindow*>( |
| 154 ui::ViewProp::GetValue(widget, kRootWindowForAcceleratedWidget)); | 154 ui::ViewProp::GetValue(widget, kRootWindowForAcceleratedWidget)); |
| 155 } | 155 } |
| 156 | 156 |
| 157 void RootWindow::Init() { | 157 void RootWindow::Init() { |
| 158 compositor()->SetScaleAndSize(GetDeviceScaleFactorFromDisplay(this), | 158 compositor()->SetScaleAndSize(GetDeviceScaleFactorFromDisplay(this), |
| 159 host_->GetBounds().size()); | 159 host_->GetBounds().size()); |
| 160 Window::Init(ui::LAYER_NOT_DRAWN); | 160 Window::Init(ui::LAYER_NOT_DRAWN); |
| 161 compositor()->SetRootLayer(layer()); | 161 compositor()->SetRootLayer(layer()); |
| 162 SetTransformInternal(gfx::Transform()); | 162 gfx::Transform identity; |
| 163 SetTransformInternal(identity, identity); |
| 163 UpdateWindowSize(host_->GetBounds().size()); | 164 UpdateWindowSize(host_->GetBounds().size()); |
| 164 Env::GetInstance()->NotifyRootWindowInitialized(this); | 165 Env::GetInstance()->NotifyRootWindowInitialized(this); |
| 165 Show(); | 166 Show(); |
| 166 } | 167 } |
| 167 | 168 |
| 168 void RootWindow::ShowRootWindow() { | 169 void RootWindow::ShowRootWindow() { |
| 169 host_->Show(); | 170 host_->Show(); |
| 170 } | 171 } |
| 171 | 172 |
| 172 void RootWindow::HideRootWindow() { | 173 void RootWindow::HideRootWindow() { |
| (...skipping 223 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 396 } | 397 } |
| 397 | 398 |
| 398 void RootWindow::ConvertPointToHost(gfx::Point* point) const { | 399 void RootWindow::ConvertPointToHost(gfx::Point* point) const { |
| 399 gfx::Point3F point_3f(*point); | 400 gfx::Point3F point_3f(*point); |
| 400 GetRootTransform().TransformPoint(point_3f); | 401 GetRootTransform().TransformPoint(point_3f); |
| 401 *point = gfx::ToFlooredPoint(point_3f.AsPointF()); | 402 *point = gfx::ToFlooredPoint(point_3f.AsPointF()); |
| 402 } | 403 } |
| 403 | 404 |
| 404 void RootWindow::ConvertPointFromHost(gfx::Point* point) const { | 405 void RootWindow::ConvertPointFromHost(gfx::Point* point) const { |
| 405 gfx::Point3F point_3f(*point); | 406 gfx::Point3F point_3f(*point); |
| 406 GetRootTransform().TransformPointReverse(point_3f); | 407 GetInvertedRootTransform().TransformPoint(point_3f); |
| 407 *point = gfx::ToFlooredPoint(point_3f.AsPointF()); | 408 *point = gfx::ToFlooredPoint(point_3f.AsPointF()); |
| 408 } | 409 } |
| 409 | 410 |
| 410 void RootWindow::ProcessedTouchEvent(ui::TouchEvent* event, | 411 void RootWindow::ProcessedTouchEvent(ui::TouchEvent* event, |
| 411 Window* window, | 412 Window* window, |
| 412 ui::EventResult result) { | 413 ui::EventResult result) { |
| 413 scoped_ptr<ui::GestureRecognizer::Gestures> gestures; | 414 scoped_ptr<ui::GestureRecognizer::Gestures> gestures; |
| 414 gestures.reset(gesture_recognizer_->ProcessTouchEventForGesture( | 415 gestures.reset(gesture_recognizer_->ProcessTouchEventForGesture( |
| 415 *event, result, window)); | 416 *event, result, window)); |
| 416 ProcessGestures(gestures.get()); | 417 ProcessGestures(gestures.get()); |
| (...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 486 | 487 |
| 487 RootWindow* RootWindow::GetRootWindow() { | 488 RootWindow* RootWindow::GetRootWindow() { |
| 488 return this; | 489 return this; |
| 489 } | 490 } |
| 490 | 491 |
| 491 const RootWindow* RootWindow::GetRootWindow() const { | 492 const RootWindow* RootWindow::GetRootWindow() const { |
| 492 return this; | 493 return this; |
| 493 } | 494 } |
| 494 | 495 |
| 495 void RootWindow::SetTransform(const gfx::Transform& transform) { | 496 void RootWindow::SetTransform(const gfx::Transform& transform) { |
| 496 SetTransformInternal(transform); | 497 gfx::Transform invert; |
| 498 if (!transform.GetInverse(&invert)) |
| 499 NOTREACHED() << "Singular matrix is set."; |
| 500 SetTransformPair(transform, invert); |
| 501 } |
| 502 |
| 503 void RootWindow::SetTransformPair(const gfx::Transform& transform, |
| 504 const gfx::Transform& invert) { |
| 505 SetTransformInternal(transform, invert); |
| 497 | 506 |
| 498 // If the layer is not animating, then we need to update the host size | 507 // If the layer is not animating, then we need to update the host size |
| 499 // immediately. | 508 // immediately. |
| 500 if (!layer()->GetAnimator()->is_animating()) | 509 if (!layer()->GetAnimator()->is_animating()) |
| 501 OnHostResized(host_->GetBounds().size()); | 510 OnHostResized(host_->GetBounds().size()); |
| 502 } | 511 } |
| 503 | 512 |
| 504 void RootWindow::SetTransformInternal(const gfx::Transform& transform) { | 513 void RootWindow::SetTransformInternal(const gfx::Transform& transform, |
| 514 const gfx::Transform& inverted) { |
| 505 gfx::Insets insets = host_->GetInsets(); | 515 gfx::Insets insets = host_->GetInsets(); |
| 506 gfx::Transform translate; | 516 gfx::Transform translate; |
| 517 invert_transform_ = inverted; |
| 518 invert_transform_.Scale(root_window_scale_, root_window_scale_); |
| 519 |
| 507 if (insets.top() != 0 || insets.left() != 0) { | 520 if (insets.top() != 0 || insets.left() != 0) { |
| 508 float device_scale_factor = GetDeviceScaleFactor(); | 521 float device_scale_factor = GetDeviceScaleFactor(); |
| 509 translate.Translate(insets.left() / device_scale_factor, | 522 float x_offset = insets.left() / device_scale_factor; |
| 510 insets.top() / device_scale_factor); | 523 float y_offset = insets.top() / device_scale_factor; |
| 511 Window::SetTransform(translate * transform); | 524 translate.Translate(x_offset, y_offset); |
| 525 invert_transform_.Translate(-x_offset, -y_offset); |
| 512 } | 526 } |
| 513 float invert = 1.0f / root_window_scale_; | 527 float inverted_scale = 1.0f / root_window_scale_; |
| 514 translate.Scale(invert, invert); | 528 translate.Scale(inverted_scale, inverted_scale); |
| 529 |
| 515 Window::SetTransform(translate * transform); | 530 Window::SetTransform(translate * transform); |
| 516 } | 531 } |
| 517 | 532 |
| 518 //////////////////////////////////////////////////////////////////////////////// | 533 //////////////////////////////////////////////////////////////////////////////// |
| 519 // RootWindow, ui::EventTarget implementation: | 534 // RootWindow, ui::EventTarget implementation: |
| 520 | 535 |
| 521 ui::EventTarget* RootWindow::GetParentTarget() { | 536 ui::EventTarget* RootWindow::GetParentTarget() { |
| 522 return client::GetEventClient(this) ? | 537 return client::GetEventClient(this) ? |
| 523 client::GetEventClient(this)->GetToplevelEventTarget() : | 538 client::GetEventClient(this)->GetToplevelEventTarget() : |
| 524 Env::GetInstance(); | 539 Env::GetInstance(); |
| (...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 664 mouse_pressed_handler_ = NULL; | 679 mouse_pressed_handler_ = NULL; |
| 665 mouse_moved_handler_ = NULL; | 680 mouse_moved_handler_ = NULL; |
| 666 mouse_event_dispatch_target_ = NULL; | 681 mouse_event_dispatch_target_ = NULL; |
| 667 } | 682 } |
| 668 | 683 |
| 669 //////////////////////////////////////////////////////////////////////////////// | 684 //////////////////////////////////////////////////////////////////////////////// |
| 670 // RootWindow, private: | 685 // RootWindow, private: |
| 671 | 686 |
| 672 void RootWindow::TransformEventForDeviceScaleFactor(bool keep_inside_root, | 687 void RootWindow::TransformEventForDeviceScaleFactor(bool keep_inside_root, |
| 673 ui::LocatedEvent* event) { | 688 ui::LocatedEvent* event) { |
| 674 event->UpdateForRootTransform(GetRootTransform()); | 689 event->UpdateForRootTransform(GetInvertedRootTransform()); |
| 675 #if defined(OS_CHROMEOS) | 690 #if defined(OS_CHROMEOS) |
| 676 const gfx::Rect& root_bounds = bounds(); | 691 const gfx::Rect& root_bounds = bounds(); |
| 677 if (keep_inside_root & | 692 if (keep_inside_root & |
| 678 host_->GetBounds().Contains(event->system_location()) && | 693 host_->GetBounds().Contains(event->system_location()) && |
| 679 !root_bounds.Contains(event->root_location())) { | 694 !root_bounds.Contains(event->root_location())) { |
| 680 // Make sure that the mouse location inside the host window gets | 695 // Make sure that the mouse location inside the host window gets |
| 681 // translated inside root window. | 696 // translated inside root window. |
| 682 // TODO(oshima): This is (hopefully) short term bandaid to deal | 697 // TODO(oshima): This is (hopefully) short term bandaid to deal |
| 683 // with calculation error in inverted matrix. We'll try better | 698 // with calculation error due to the fact that we rotate in dip |
| 684 // alternative (crbug.com/222483) for m28. | 699 // coordinates instead of pixels. crbug.com/222483. |
| 685 int x = event->location().x(); | 700 int x = event->location().x(); |
| 686 int y = event->location().y(); | 701 int y = event->location().y(); |
| 687 x = std::min(std::max(x, root_bounds.x()), root_bounds.right()); | 702 x = std::min(std::max(x, root_bounds.x()), root_bounds.right()); |
| 688 y = std::min(std::max(y, root_bounds.y()), root_bounds.bottom()); | 703 y = std::min(std::max(y, root_bounds.y()), root_bounds.bottom()); |
| 689 const gfx::Point new_location(x, y); | 704 const gfx::Point new_location(x, y); |
| 690 event->set_location(new_location); | 705 event->set_location(new_location); |
| 691 event->set_root_location(new_location); | 706 event->set_root_location(new_location); |
| 692 } | 707 } |
| 693 #endif // defined(OS_CHROMEOS) | 708 #endif // defined(OS_CHROMEOS) |
| 694 } | 709 } |
| (...skipping 477 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1172 } | 1187 } |
| 1173 | 1188 |
| 1174 gfx::Transform RootWindow::GetRootTransform() const { | 1189 gfx::Transform RootWindow::GetRootTransform() const { |
| 1175 float scale = ui::GetDeviceScaleFactor(layer()); | 1190 float scale = ui::GetDeviceScaleFactor(layer()); |
| 1176 gfx::Transform transform; | 1191 gfx::Transform transform; |
| 1177 transform.Scale(scale, scale); | 1192 transform.Scale(scale, scale); |
| 1178 transform *= layer()->transform(); | 1193 transform *= layer()->transform(); |
| 1179 return transform; | 1194 return transform; |
| 1180 } | 1195 } |
| 1181 | 1196 |
| 1197 gfx::Transform RootWindow::GetInvertedRootTransform() const { |
| 1198 float scale = ui::GetDeviceScaleFactor(layer()); |
| 1199 gfx::Transform transform; |
| 1200 transform.Scale(1.0f / scale, 1.0f / scale); |
| 1201 return invert_transform_ * transform; |
| 1202 } |
| 1203 |
| 1182 } // namespace aura | 1204 } // namespace aura |
| OLD | NEW |