OLD | NEW |
| (Empty) |
1 // Copyright 2016 The Chromium Authors. All rights reserved. | |
2 // Use of this source code is governed by a BSD-style license that can be | |
3 // found in the LICENSE file. | |
4 | |
5 #include "ui/aura/window_port_local.h" | |
6 | |
7 #include "ui/aura/client/cursor_client.h" | |
8 #include "ui/aura/env.h" | |
9 #include "ui/aura/window.h" | |
10 #include "ui/aura/window_delegate.h" | |
11 #include "ui/display/display.h" | |
12 #include "ui/display/screen.h" | |
13 | |
14 namespace aura { | |
15 namespace { | |
16 | |
17 class ScopedCursorHider { | |
18 public: | |
19 explicit ScopedCursorHider(Window* window) | |
20 : window_(window), hid_cursor_(false) { | |
21 if (!window_->IsRootWindow()) | |
22 return; | |
23 const bool cursor_is_in_bounds = window_->GetBoundsInScreen().Contains( | |
24 Env::GetInstance()->last_mouse_location()); | |
25 client::CursorClient* cursor_client = client::GetCursorClient(window_); | |
26 if (cursor_is_in_bounds && cursor_client && | |
27 cursor_client->IsCursorVisible()) { | |
28 cursor_client->HideCursor(); | |
29 hid_cursor_ = true; | |
30 } | |
31 } | |
32 ~ScopedCursorHider() { | |
33 if (!window_->IsRootWindow()) | |
34 return; | |
35 | |
36 // Update the device scale factor of the cursor client only when the last | |
37 // mouse location is on this root window. | |
38 if (hid_cursor_) { | |
39 client::CursorClient* cursor_client = client::GetCursorClient(window_); | |
40 if (cursor_client) { | |
41 const display::Display& display = | |
42 display::Screen::GetScreen()->GetDisplayNearestWindow(window_); | |
43 cursor_client->SetDisplay(display); | |
44 cursor_client->ShowCursor(); | |
45 } | |
46 } | |
47 } | |
48 | |
49 private: | |
50 Window* window_; | |
51 bool hid_cursor_; | |
52 | |
53 DISALLOW_COPY_AND_ASSIGN(ScopedCursorHider); | |
54 }; | |
55 | |
56 } // namespace | |
57 | |
58 WindowPortLocal::WindowPortLocal(Window* window) : window_(window) {} | |
59 | |
60 WindowPortLocal::~WindowPortLocal() {} | |
61 | |
62 void WindowPortLocal::OnPreInit(Window* window) {} | |
63 | |
64 void WindowPortLocal::OnDeviceScaleFactorChanged(float device_scale_factor) { | |
65 ScopedCursorHider hider(window_); | |
66 if (window_->delegate()) | |
67 window_->delegate()->OnDeviceScaleFactorChanged(device_scale_factor); | |
68 } | |
69 | |
70 void WindowPortLocal::OnWillAddChild(Window* child) {} | |
71 | |
72 void WindowPortLocal::OnWillRemoveChild(Window* child) {} | |
73 | |
74 void WindowPortLocal::OnWillMoveChild(size_t current_index, size_t dest_index) { | |
75 } | |
76 | |
77 void WindowPortLocal::OnVisibilityChanged(bool visible) {} | |
78 | |
79 void WindowPortLocal::OnDidChangeBounds(const gfx::Rect& old_bounds, | |
80 const gfx::Rect& new_bounds) {} | |
81 | |
82 std::unique_ptr<ui::PropertyData> WindowPortLocal::OnWillChangeProperty( | |
83 const void* key) { | |
84 return nullptr; | |
85 } | |
86 | |
87 void WindowPortLocal::OnPropertyChanged( | |
88 const void* key, | |
89 int64_t old_value, | |
90 std::unique_ptr<ui::PropertyData> data) {} | |
91 | |
92 } // namespace aura | |
OLD | NEW |