| 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 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 61 float GetDeviceScaleFactorFromDisplay(Window* window) { | 61 float GetDeviceScaleFactorFromDisplay(Window* window) { |
| 62 return gfx::Screen::GetScreenFor(window)-> | 62 return gfx::Screen::GetScreenFor(window)-> |
| 63 GetDisplayNearestWindow(window).device_scale_factor(); | 63 GetDisplayNearestWindow(window).device_scale_factor(); |
| 64 } | 64 } |
| 65 | 65 |
| 66 Window* ConsumerToWindow(ui::GestureConsumer* consumer) { | 66 Window* ConsumerToWindow(ui::GestureConsumer* consumer) { |
| 67 return consumer && !consumer->ignores_events() ? | 67 return consumer && !consumer->ignores_events() ? |
| 68 static_cast<Window*>(consumer) : NULL; | 68 static_cast<Window*>(consumer) : NULL; |
| 69 } | 69 } |
| 70 | 70 |
| 71 void SetLastMouseLocation(const Window* root_window, | 71 void SetLastMouseLocation(const RootWindow* root_window, |
| 72 const gfx::Point& location) { | 72 const gfx::Point& location_in_root) { |
| 73 Env::GetInstance()->SetLastMouseLocation(*root_window, location); | 73 client::ScreenPositionClient* client = |
| 74 client::GetScreenPositionClient(root_window); |
| 75 if (client) { |
| 76 gfx::Point location_in_screen = location_in_root; |
| 77 client->ConvertPointToScreen(root_window, &location_in_screen); |
| 78 Env::GetInstance()->set_last_mouse_location(location_in_screen); |
| 79 } else { |
| 80 Env::GetInstance()->set_last_mouse_location(location_in_root); |
| 81 } |
| 74 } | 82 } |
| 75 | 83 |
| 76 RootWindowHost* CreateHost(RootWindow* root_window, | 84 RootWindowHost* CreateHost(RootWindow* root_window, |
| 77 const RootWindow::CreateParams& params) { | 85 const RootWindow::CreateParams& params) { |
| 78 RootWindowHost* host = params.host ? | 86 RootWindowHost* host = params.host ? |
| 79 params.host : RootWindowHost::Create(params.initial_bounds); | 87 params.host : RootWindowHost::Create(params.initial_bounds); |
| 80 host->SetDelegate(root_window); | 88 host->SetDelegate(root_window); |
| 81 return host; | 89 return host; |
| 82 } | 90 } |
| 83 | 91 |
| (...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 198 return host_->GetBounds().origin(); | 206 return host_->GetBounds().origin(); |
| 199 } | 207 } |
| 200 | 208 |
| 201 void RootWindow::SetCursor(gfx::NativeCursor cursor) { | 209 void RootWindow::SetCursor(gfx::NativeCursor cursor) { |
| 202 last_cursor_ = cursor; | 210 last_cursor_ = cursor; |
| 203 // A lot of code seems to depend on NULL cursors actually showing an arrow, | 211 // A lot of code seems to depend on NULL cursors actually showing an arrow, |
| 204 // so just pass everything along to the host. | 212 // so just pass everything along to the host. |
| 205 host_->SetCursor(cursor); | 213 host_->SetCursor(cursor); |
| 206 } | 214 } |
| 207 | 215 |
| 208 void RootWindow::OnCursorVisibilityChanged(bool show) { | 216 void RootWindow::OnCursorEnableStateChanged(bool enabled) { |
| 209 // Send entered / exited so that visual state can be updated to match | 217 // Send entered / exited so that visual state can be updated to match |
| 210 // cursor state. | 218 // cursor state. |
| 211 Env::GetInstance()->SetCursorShown(show); | |
| 212 PostMouseMoveEventAfterWindowChange(); | 219 PostMouseMoveEventAfterWindowChange(); |
| 213 host_->OnCursorVisibilityChanged(show); | 220 host_->OnCursorEnableStateChanged(enabled); |
| 214 } | 221 } |
| 215 | 222 |
| 216 void RootWindow::MoveCursorTo(const gfx::Point& location_in_dip) { | 223 void RootWindow::MoveCursorTo(const gfx::Point& location_in_dip) { |
| 217 gfx::Point location = location_in_dip; | 224 gfx::Point location = location_in_dip; |
| 218 layer()->transform().TransformPoint(location); | 225 layer()->transform().TransformPoint(location); |
| 219 host_->MoveCursorTo(ui::ConvertPointToPixel(layer(), location)); | 226 host_->MoveCursorTo(ui::ConvertPointToPixel(layer(), location)); |
| 220 SetLastMouseLocation(this, location_in_dip); | 227 SetLastMouseLocation(this, location_in_dip); |
| 221 client::CursorClient* cursor_client = client::GetCursorClient(this); | 228 client::CursorClient* cursor_client = client::GetCursorClient(this); |
| 222 if (cursor_client) | 229 if (cursor_client) |
| 223 cursor_client->SetDeviceScaleFactor(GetDeviceScaleFactor()); | 230 cursor_client->SetDeviceScaleFactor(GetDeviceScaleFactor()); |
| (...skipping 267 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 491 | 498 |
| 492 void RootWindow::OnDeviceScaleFactorChanged( | 499 void RootWindow::OnDeviceScaleFactorChanged( |
| 493 float device_scale_factor) { | 500 float device_scale_factor) { |
| 494 const bool cursor_is_in_bounds = | 501 const bool cursor_is_in_bounds = |
| 495 GetBoundsInScreen().Contains(Env::GetInstance()->last_mouse_location()); | 502 GetBoundsInScreen().Contains(Env::GetInstance()->last_mouse_location()); |
| 496 bool cursor_visible = false; | 503 bool cursor_visible = false; |
| 497 client::CursorClient* cursor_client = client::GetCursorClient(this); | 504 client::CursorClient* cursor_client = client::GetCursorClient(this); |
| 498 if (cursor_is_in_bounds && cursor_client) { | 505 if (cursor_is_in_bounds && cursor_client) { |
| 499 cursor_visible = cursor_client->IsCursorVisible(); | 506 cursor_visible = cursor_client->IsCursorVisible(); |
| 500 if (cursor_visible) | 507 if (cursor_visible) |
| 501 cursor_client->ShowCursor(false); | 508 cursor_client->EnableCursor(false); |
| 502 } | 509 } |
| 503 host_->OnDeviceScaleFactorChanged(device_scale_factor); | 510 host_->OnDeviceScaleFactorChanged(device_scale_factor); |
| 504 Window::OnDeviceScaleFactorChanged(device_scale_factor); | 511 Window::OnDeviceScaleFactorChanged(device_scale_factor); |
| 505 // Update the device scale factor of the cursor client only when the last | 512 // Update the device scale factor of the cursor client only when the last |
| 506 // mouse location is on this root window. | 513 // mouse location is on this root window. |
| 507 if (cursor_is_in_bounds) { | 514 if (cursor_is_in_bounds) { |
| 508 if (cursor_client) | 515 if (cursor_client) |
| 509 cursor_client->SetDeviceScaleFactor(device_scale_factor); | 516 cursor_client->SetDeviceScaleFactor(device_scale_factor); |
| 510 } | 517 } |
| 511 if (cursor_is_in_bounds && cursor_client && cursor_visible) | 518 if (cursor_is_in_bounds && cursor_client && cursor_visible) |
| 512 cursor_client->ShowCursor(true); | 519 cursor_client->EnableCursor(true); |
| 513 } | 520 } |
| 514 | 521 |
| 515 //////////////////////////////////////////////////////////////////////////////// | 522 //////////////////////////////////////////////////////////////////////////////// |
| 516 // RootWindow, overridden from aura::Window: | 523 // RootWindow, overridden from aura::Window: |
| 517 | 524 |
| 518 bool RootWindow::CanFocus() const { | 525 bool RootWindow::CanFocus() const { |
| 519 return IsVisible(); | 526 return IsVisible(); |
| 520 } | 527 } |
| 521 | 528 |
| 522 bool RootWindow::CanReceiveEvents() const { | 529 bool RootWindow::CanReceiveEvents() const { |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 561 } | 568 } |
| 562 | 569 |
| 563 void RootWindow::SetNativeCapture() { | 570 void RootWindow::SetNativeCapture() { |
| 564 host_->SetCapture(); | 571 host_->SetCapture(); |
| 565 } | 572 } |
| 566 | 573 |
| 567 void RootWindow::ReleaseNativeCapture() { | 574 void RootWindow::ReleaseNativeCapture() { |
| 568 host_->ReleaseCapture(); | 575 host_->ReleaseCapture(); |
| 569 } | 576 } |
| 570 | 577 |
| 571 gfx::Point RootWindow::QueryMouseLocationForTest() const { | 578 bool RootWindow::QueryMouseLocationForTest(gfx::Point* point) const { |
| 572 gfx::Point point; | 579 return host_->QueryMouseLocation(point); |
| 573 host_->QueryMouseLocation(&point); | |
| 574 return point; | |
| 575 } | 580 } |
| 576 | 581 |
| 577 //////////////////////////////////////////////////////////////////////////////// | 582 //////////////////////////////////////////////////////////////////////////////// |
| 578 // RootWindow, private: | 583 // RootWindow, private: |
| 579 | 584 |
| 580 void RootWindow::TransformEventForDeviceScaleFactor(ui::LocatedEvent* event) { | 585 void RootWindow::TransformEventForDeviceScaleFactor(ui::LocatedEvent* event) { |
| 581 float scale = ui::GetDeviceScaleFactor(layer()); | 586 float scale = ui::GetDeviceScaleFactor(layer()); |
| 582 gfx::Transform transform; | 587 gfx::Transform transform; |
| 583 transform.Scale(scale, scale); | 588 transform.Scale(scale, scale); |
| 584 transform *= layer()->transform(); | 589 transform *= layer()->transform(); |
| (...skipping 403 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 988 ui::MouseEvent event(ui::ET_MOUSE_MOVED, | 993 ui::MouseEvent event(ui::ET_MOUSE_MOVED, |
| 989 orig_mouse_location, | 994 orig_mouse_location, |
| 990 orig_mouse_location, | 995 orig_mouse_location, |
| 991 ui::EF_IS_SYNTHESIZED); | 996 ui::EF_IS_SYNTHESIZED); |
| 992 event.set_system_location(Env::GetInstance()->last_mouse_location()); | 997 event.set_system_location(Env::GetInstance()->last_mouse_location()); |
| 993 OnHostMouseEvent(&event); | 998 OnHostMouseEvent(&event); |
| 994 #endif | 999 #endif |
| 995 } | 1000 } |
| 996 | 1001 |
| 997 } // namespace aura | 1002 } // namespace aura |
| OLD | NEW |