OLD | NEW |
1 // Copyright (c) 2015 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2015 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 "content/browser/media/capture/cursor_renderer_aura.h" | 5 #include "content/browser/media/capture/cursor_renderer_aura.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 #include <cmath> | 8 #include <cmath> |
9 | 9 |
10 #include "base/logging.h" | 10 #include "base/logging.h" |
11 #include "base/time/default_tick_clock.h" | 11 #include "base/time/default_tick_clock.h" |
12 #include "ui/aura/client/screen_position_client.h" | 12 #include "ui/aura/client/screen_position_client.h" |
13 #include "ui/aura/env.h" | 13 #include "ui/aura/env.h" |
14 #include "ui/aura/window.h" | 14 #include "ui/aura/window.h" |
15 #include "ui/aura/window_tree_host.h" | 15 #include "ui/aura/window_tree_host.h" |
16 #include "ui/base/cursor/cursors_aura.h" | 16 #include "ui/base/cursor/cursors_aura.h" |
17 #include "ui/compositor/dip_util.h" | 17 #include "ui/compositor/dip_util.h" |
18 #include "ui/compositor/layer.h" | 18 #include "ui/compositor/layer.h" |
19 #include "ui/events/event_utils.h" | 19 #include "ui/events/event_utils.h" |
20 #include "ui/wm/public/activation_client.h" | 20 #include "ui/wm/public/activation_client.h" |
21 | 21 |
22 namespace content { | 22 namespace content { |
23 | 23 |
24 namespace { | 24 namespace { |
25 | 25 |
| 26 // The time period within which a triggered UI event is considered |
| 27 // currently active. |
| 28 const int kTimePeriodUiEventMicros = 100000; // 100 ms |
| 29 |
26 inline int clip_byte(int x) { | 30 inline int clip_byte(int x) { |
27 return std::max(0, std::min(x, 255)); | 31 return std::max(0, std::min(x, 255)); |
28 } | 32 } |
29 | 33 |
30 inline int alpha_blend(int alpha, int src, int dst) { | 34 inline int alpha_blend(int alpha, int src, int dst) { |
31 return (src * alpha + dst * (255 - alpha)) / 255; | 35 return (src * alpha + dst * (255 - alpha)) / 255; |
32 } | 36 } |
33 | 37 |
34 } // namespace | 38 } // namespace |
35 | 39 |
(...skipping 10 matching lines...) Expand all Loading... |
46 if (window_) { | 50 if (window_) { |
47 window_->RemoveObserver(this); | 51 window_->RemoveObserver(this); |
48 window_->RemovePreTargetHandler(this); | 52 window_->RemovePreTargetHandler(this); |
49 } | 53 } |
50 } | 54 } |
51 | 55 |
52 base::WeakPtr<CursorRenderer> CursorRendererAura::GetWeakPtr() { | 56 base::WeakPtr<CursorRenderer> CursorRendererAura::GetWeakPtr() { |
53 return weak_factory_.GetWeakPtr(); | 57 return weak_factory_.GetWeakPtr(); |
54 } | 58 } |
55 | 59 |
| 60 bool CursorRendererAura::ui_event_detected() const { |
| 61 return (tick_clock_->NowTicks() - last_time_ui_event_detected_) < |
| 62 base::TimeDelta::FromMicroseconds(kTimePeriodUiEventMicros); |
| 63 } |
| 64 |
56 void CursorRendererAura::Clear() { | 65 void CursorRendererAura::Clear() { |
57 last_cursor_ = ui::Cursor(); | 66 last_cursor_ = ui::Cursor(); |
58 window_size_when_cursor_last_updated_ = gfx::Size(); | 67 window_size_when_cursor_last_updated_ = gfx::Size(); |
59 scaled_cursor_bitmap_.reset(); | 68 scaled_cursor_bitmap_.reset(); |
60 last_mouse_position_x_ = 0; | 69 last_mouse_position_x_ = 0; |
61 last_mouse_position_y_ = 0; | 70 last_mouse_position_y_ = 0; |
62 cursor_displayed_ = false; | 71 cursor_displayed_ = false; |
63 } | 72 } |
64 | 73 |
65 bool CursorRendererAura::SnapshotCursorState(const gfx::Rect& region_in_frame) { | 74 bool CursorRendererAura::SnapshotCursorState(const gfx::Rect& region_in_frame) { |
(...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
177 int color_v = clip_byte( | 186 int color_v = clip_byte( |
178 ((color_r * 112 + color_g * -94 + color_b * -18 + 128) >> 8) + 128); | 187 ((color_r * 112 + color_g * -94 + color_b * -18 + 128) >> 8) + 128); |
179 uplane[x / 2] = alpha_blend(alpha, color_u, uplane[x / 2]); | 188 uplane[x / 2] = alpha_blend(alpha, color_u, uplane[x / 2]); |
180 vplane[x / 2] = alpha_blend(alpha, color_v, vplane[x / 2]); | 189 vplane[x / 2] = alpha_blend(alpha, color_v, vplane[x / 2]); |
181 } | 190 } |
182 } | 191 } |
183 } | 192 } |
184 scaled_cursor_bitmap_.unlockPixels(); | 193 scaled_cursor_bitmap_.unlockPixels(); |
185 } | 194 } |
186 | 195 |
| 196 void CursorRendererAura::OnEvent(ui::Event* event) { |
| 197 last_time_ui_event_detected_ = tick_clock_->NowTicks(); |
| 198 ui::EventHandler::OnEvent(event); |
| 199 } |
| 200 |
187 void CursorRendererAura::OnMouseEvent(ui::MouseEvent* event) { | 201 void CursorRendererAura::OnMouseEvent(ui::MouseEvent* event) { |
188 switch (event->type()) { | 202 switch (event->type()) { |
189 case ui::ET_MOUSE_MOVED: | 203 case ui::ET_MOUSE_MOVED: |
190 if (!cursor_displayed_) { | 204 if (!cursor_displayed_) { |
191 if (std::abs(event->x() - last_mouse_position_x_) > | 205 if (std::abs(event->x() - last_mouse_position_x_) > |
192 MIN_MOVEMENT_PIXELS || | 206 MIN_MOVEMENT_PIXELS || |
193 std::abs(event->y() - last_mouse_position_y_) > MIN_MOVEMENT_PIXELS) | 207 std::abs(event->y() - last_mouse_position_y_) > MIN_MOVEMENT_PIXELS) |
194 cursor_displayed_ = true; | 208 cursor_displayed_ = true; |
195 } | 209 } |
196 if (cursor_displayed_) { | 210 if (cursor_displayed_) { |
197 last_mouse_movement_timestamp_ = event->time_stamp(); | 211 last_mouse_movement_timestamp_ = event->time_stamp(); |
198 last_mouse_position_x_ = event->x(); | 212 last_mouse_position_x_ = event->x(); |
199 last_mouse_position_y_ = event->y(); | 213 last_mouse_position_y_ = event->y(); |
200 } | 214 } |
201 break; | 215 break; |
202 default: | 216 default: |
203 break; | 217 break; |
204 } | 218 } |
205 } | 219 } |
206 | 220 |
207 void CursorRendererAura::OnWindowDestroying(aura::Window* window) { | 221 void CursorRendererAura::OnWindowDestroying(aura::Window* window) { |
208 DCHECK_EQ(window_, window); | 222 DCHECK_EQ(window_, window); |
209 window_->RemovePreTargetHandler(this); | 223 window_->RemovePreTargetHandler(this); |
210 window_->RemoveObserver(this); | 224 window_->RemoveObserver(this); |
211 window_ = nullptr; | 225 window_ = nullptr; |
212 } | 226 } |
213 | 227 |
214 } // namespace content | 228 } // namespace content |
OLD | NEW |