View.Mouse.cs 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640
  1. #nullable enable
  2. using System.ComponentModel;
  3. namespace Terminal.Gui;
  4. public partial class View // Mouse APIs
  5. {
  6. private ColorScheme? _savedHighlightColorScheme;
  7. /// <summary>
  8. /// Fired when the view is highlighted. Set <see cref="CancelEventArgs.Cancel"/> to <see langword="true"/>
  9. /// to implement a custom highlight scheme or prevent the view from being highlighted.
  10. /// </summary>
  11. public event EventHandler<CancelEventArgs<HighlightStyle>>? Highlight;
  12. /// <summary>
  13. /// Gets or sets whether the <see cref="View"/> will be highlighted visually while the mouse button is
  14. /// pressed.
  15. /// </summary>
  16. public HighlightStyle HighlightStyle { get; set; }
  17. /// <summary>Event fired when a mouse click occurs.</summary>
  18. /// <remarks>
  19. /// <para>
  20. /// Fired when the mouse is either clicked or double-clicked. Check
  21. /// <see cref="MouseEvent.Flags"/> to see which button was clicked.
  22. /// </para>
  23. /// <para>
  24. /// The coordinates are relative to <see cref="View.Viewport"/>.
  25. /// </para>
  26. /// </remarks>
  27. public event EventHandler<MouseEventEventArgs>? MouseClick;
  28. /// <summary>Event fired when the mouse moves into the View's <see cref="Viewport"/>.</summary>
  29. public event EventHandler<MouseEventEventArgs>? MouseEnter;
  30. /// <summary>Event fired when a mouse event occurs.</summary>
  31. /// <remarks>
  32. /// <para>
  33. /// The coordinates are relative to <see cref="View.Viewport"/>.
  34. /// </para>
  35. /// </remarks>
  36. public event EventHandler<MouseEventEventArgs>? MouseEvent;
  37. /// <summary>Event fired when the mouse leaves the View's <see cref="Viewport"/>.</summary>
  38. public event EventHandler<MouseEventEventArgs>? MouseLeave;
  39. /// <summary>
  40. /// Processes a <see cref="MouseEvent"/>. This method is called by <see cref="Application.OnMouseEvent"/> when a mouse
  41. /// event occurs.
  42. /// </summary>
  43. /// <remarks>
  44. /// <para>
  45. /// A view must be both enabled and visible to receive mouse events.
  46. /// </para>
  47. /// <para>
  48. /// This method calls <see cref="OnMouseEvent"/> to process the event. If the event is not handled, and one of the
  49. /// mouse buttons was clicked, it calls <see cref="OnMouseClick"/> to process the click.
  50. /// </para>
  51. /// <para>
  52. /// See <see cref="SetHighlight"/> for more information.
  53. /// </para>
  54. /// <para>
  55. /// If <see cref="WantContinuousButtonPressed"/> is <see langword="true"/>, the <see cref="OnMouseClick"/> event
  56. /// will be invoked repeatedly while the button is pressed.
  57. /// </para>
  58. /// </remarks>
  59. /// <param name="mouseEvent"></param>
  60. /// <returns><see langword="true"/> if the event was handled, <see langword="false"/> otherwise.</returns>
  61. public bool? NewMouseEvent (MouseEvent mouseEvent)
  62. {
  63. if (!Enabled)
  64. {
  65. // A disabled view should not eat mouse events
  66. return false;
  67. }
  68. if (!CanBeVisible (this))
  69. {
  70. return false;
  71. }
  72. if (!WantMousePositionReports && mouseEvent.Flags == MouseFlags.ReportMousePosition)
  73. {
  74. return false;
  75. }
  76. if (OnMouseEvent (mouseEvent))
  77. {
  78. // Technically mouseEvent.Handled should already be true if implementers of OnMouseEvent
  79. // follow the rules. But we'll update it just in case.
  80. return mouseEvent.Handled = true;
  81. }
  82. if (HighlightStyle != HighlightStyle.None || (WantContinuousButtonPressed && WantMousePositionReports))
  83. {
  84. if (HandlePressed (mouseEvent))
  85. {
  86. return mouseEvent.Handled;
  87. }
  88. if (HandleReleased (mouseEvent))
  89. {
  90. return mouseEvent.Handled;
  91. }
  92. if (HandleClicked (mouseEvent))
  93. {
  94. return mouseEvent.Handled;
  95. }
  96. }
  97. if (mouseEvent.Flags.HasFlag (MouseFlags.Button1Clicked)
  98. || mouseEvent.Flags.HasFlag (MouseFlags.Button2Clicked)
  99. || mouseEvent.Flags.HasFlag (MouseFlags.Button3Clicked)
  100. || mouseEvent.Flags.HasFlag (MouseFlags.Button4Clicked)
  101. || mouseEvent.Flags.HasFlag (MouseFlags.Button1DoubleClicked)
  102. || mouseEvent.Flags.HasFlag (MouseFlags.Button2DoubleClicked)
  103. || mouseEvent.Flags.HasFlag (MouseFlags.Button3DoubleClicked)
  104. || mouseEvent.Flags.HasFlag (MouseFlags.Button4DoubleClicked)
  105. || mouseEvent.Flags.HasFlag (MouseFlags.Button1TripleClicked)
  106. || mouseEvent.Flags.HasFlag (MouseFlags.Button2TripleClicked)
  107. || mouseEvent.Flags.HasFlag (MouseFlags.Button3TripleClicked)
  108. || mouseEvent.Flags.HasFlag (MouseFlags.Button4TripleClicked)
  109. )
  110. {
  111. // If it's a click, and we didn't handle it, then we'll call OnMouseClick
  112. // We get here if the view did not handle the mouse event via OnMouseEvent/MouseEvent and
  113. // it did not handle the press/release/clicked events via HandlePress/HandleRelease/HandleClicked
  114. return OnMouseClick (new (mouseEvent));
  115. }
  116. return false;
  117. }
  118. /// <summary>Gets or sets whether the <see cref="View"/> wants continuous button pressed events.</summary>
  119. public virtual bool WantContinuousButtonPressed { get; set; }
  120. /// <summary>Gets or sets whether the <see cref="View"/> wants mouse position reports.</summary>
  121. /// <value><see langword="true"/> if mouse position reports are wanted; otherwise, <see langword="false"/>.</value>
  122. public virtual bool WantMousePositionReports { get; set; }
  123. /// <summary>
  124. /// Called by <see cref="NewMouseEvent"/> when the mouse enters <see cref="Viewport"/>. The view will
  125. /// then receive mouse events until <see cref="OnMouseLeave"/> is called indicating the mouse has left
  126. /// the view.
  127. /// </summary>
  128. /// <remarks>
  129. /// <para>
  130. /// Override this method or subscribe to <see cref="MouseEnter"/> to change the default enter behavior.
  131. /// </para>
  132. /// <para>
  133. /// The coordinates are relative to <see cref="View.Viewport"/>.
  134. /// </para>
  135. /// </remarks>
  136. /// <param name="mouseEvent"></param>
  137. /// <returns><see langword="true"/>, if the event was handled, <see langword="false"/> otherwise.</returns>
  138. protected internal virtual bool? OnMouseEnter (MouseEvent mouseEvent)
  139. {
  140. return false;
  141. }
  142. /// <summary>Called when a mouse event occurs within the view's <see cref="Viewport"/>.</summary>
  143. /// <remarks>
  144. /// <para>
  145. /// The coordinates are relative to <see cref="View.Viewport"/>.
  146. /// </para>
  147. /// </remarks>
  148. /// <param name="mouseEvent"></param>
  149. /// <returns><see langword="true"/>, if the event was handled, <see langword="false"/> otherwise.</returns>
  150. protected internal virtual bool OnMouseEvent (MouseEvent mouseEvent)
  151. {
  152. var args = new MouseEventEventArgs (mouseEvent);
  153. MouseEvent?.Invoke (this, args);
  154. return args.Handled;
  155. }
  156. /// <summary>
  157. /// Called by <see cref="NewMouseEvent"/> when a mouse leaves <see cref="Viewport"/>. The view will
  158. /// no longer receive mouse events.
  159. /// </summary>
  160. /// <remarks>
  161. /// <para>
  162. /// Override this method or subscribe to <see cref="MouseEnter"/> to change the default leave behavior.
  163. /// </para>
  164. /// <para>
  165. /// The coordinates are relative to <see cref="View.Viewport"/>.
  166. /// </para>
  167. /// </remarks>
  168. /// <param name="mouseEvent"></param>
  169. /// <returns><see langword="true"/>, if the event was handled, <see langword="false"/> otherwise.</returns>
  170. protected internal virtual bool OnMouseLeave (MouseEvent mouseEvent)
  171. {
  172. return false;
  173. }
  174. /// <summary>
  175. /// Called when the view is to be highlighted.
  176. /// </summary>
  177. /// <returns><see langword="true"/>, if the event was handled, <see langword="false"/> otherwise.</returns>
  178. protected virtual bool? OnHighlight (CancelEventArgs<HighlightStyle> args)
  179. {
  180. Highlight?.Invoke (this, args);
  181. if (args.Cancel)
  182. {
  183. return true;
  184. }
  185. Margin?.Highlight?.Invoke (this, args);
  186. //args = new (highlight);
  187. //Border?.Highlight?.Invoke (this, args);
  188. //args = new (highlight);
  189. //Padding?.Highlight?.Invoke (this, args);
  190. return args.Cancel;
  191. }
  192. /// <summary>Invokes the MouseClick event.</summary>
  193. /// <remarks>
  194. /// <para>
  195. /// Called when the mouse is either clicked or double-clicked. Check
  196. /// <see cref="MouseEvent.Flags"/> to see which button was clicked.
  197. /// </para>
  198. /// </remarks>
  199. /// <returns><see langword="true"/>, if the event was handled, <see langword="false"/> otherwise.</returns>
  200. protected bool OnMouseClick (MouseEventEventArgs args)
  201. {
  202. if (!Enabled)
  203. {
  204. // QUESTION: Is this right? Should a disabled view eat mouse clicks?
  205. return args.Handled = false;
  206. }
  207. MouseClick?.Invoke (this, args);
  208. if (args.Handled)
  209. {
  210. return true;
  211. }
  212. if (!HasFocus && CanFocus)
  213. {
  214. args.Handled = true;
  215. SetFocus ();
  216. }
  217. return args.Handled;
  218. }
  219. /// <summary>
  220. /// For cases where the view is grabbed and the mouse is clicked, this method handles the click event (typically
  221. /// when <see cref="WantContinuousButtonPressed"/> or <see cref="HighlightStyle"/> are set).
  222. /// </summary>
  223. /// <remarks>
  224. /// Marked internal just to support unit tests
  225. /// </remarks>
  226. /// <param name="mouseEvent"></param>
  227. /// <returns><see langword="true"/>, if the event was handled, <see langword="false"/> otherwise.</returns>
  228. internal bool HandleClicked (MouseEvent mouseEvent)
  229. {
  230. if (Application.MouseGrabView == this
  231. && (mouseEvent.Flags.HasFlag (MouseFlags.Button1Clicked)
  232. || mouseEvent.Flags.HasFlag (MouseFlags.Button2Clicked)
  233. || mouseEvent.Flags.HasFlag (MouseFlags.Button3Clicked)
  234. || mouseEvent.Flags.HasFlag (MouseFlags.Button4Clicked)))
  235. {
  236. // We're grabbed. Clicked event comes after the last Release. This is our signal to ungrab
  237. Application.UngrabMouse ();
  238. if (SetHighlight (HighlightStyle.None))
  239. {
  240. return true;
  241. }
  242. // If mouse is still in bounds, click
  243. if (!WantContinuousButtonPressed && Viewport.Contains (mouseEvent.Position))
  244. {
  245. return OnMouseClick (new (mouseEvent));
  246. }
  247. return mouseEvent.Handled = true;
  248. }
  249. return false;
  250. }
  251. /// <summary>
  252. /// For cases where the view is grabbed and the mouse is clicked, this method handles the released event (typically
  253. /// when <see cref="WantContinuousButtonPressed"/> or <see cref="HighlightStyle"/> are set).
  254. /// </summary>
  255. /// <remarks>
  256. /// Marked internal just to support unit tests
  257. /// </remarks>
  258. /// <param name="mouseEvent"></param>
  259. /// <returns><see langword="true"/>, if the event was handled, <see langword="false"/> otherwise.</returns>
  260. internal bool HandleReleased (MouseEvent mouseEvent)
  261. {
  262. if (mouseEvent.Flags.HasFlag (MouseFlags.Button1Released)
  263. || mouseEvent.Flags.HasFlag (MouseFlags.Button2Released)
  264. || mouseEvent.Flags.HasFlag (MouseFlags.Button3Released)
  265. || mouseEvent.Flags.HasFlag (MouseFlags.Button4Released))
  266. {
  267. if (Application.MouseGrabView == this)
  268. {
  269. SetHighlight (HighlightStyle.None);
  270. }
  271. return mouseEvent.Handled = true;
  272. }
  273. return false;
  274. }
  275. /// <summary>
  276. /// INTERNAL Called by <see cref="Application.OnMouseEvent"/> when the mouse moves over the View's <see cref="Frame"/>. <see cref="MouseLeave"/> will
  277. /// be raised when the mouse is no longer over the <see cref="Frame"/>. If another View occludes this View, the
  278. /// that View will also receive MouseEnter/Leave events.
  279. /// </summary>
  280. /// <remarks>
  281. /// <para>
  282. /// A view must be visible to receive Enter events (Leave events are always received).
  283. /// </para>
  284. /// <para>
  285. /// This method calls <see cref="OnMouseEnter"/> to raise the <see cref="MouseEnter"/> event.
  286. /// </para>
  287. /// <para>
  288. /// Adornments receive MouseEnter/Leave events when the mouse is over the Adornment's <see cref="Thickness"/>.
  289. /// </para>
  290. /// <para>
  291. /// See <see cref="SetHighlight"/> for more information.
  292. /// </para>
  293. /// </remarks>
  294. /// <param name="mouseEvent"></param>
  295. /// <returns><see langword="true"/> if the event was handled, <see langword="false"/> otherwise. Handling the event
  296. /// prevents Views higher in the visible hierarchy from receiving Enter/Leave events.</returns>
  297. internal bool? NewMouseEnterEvent (MouseEvent mouseEvent)
  298. {
  299. if (!Enabled)
  300. {
  301. return false;
  302. }
  303. if (!CanBeVisible (this))
  304. {
  305. return false;
  306. }
  307. if (OnMouseEnter (mouseEvent) == true)
  308. {
  309. return true;
  310. }
  311. var args = new MouseEventEventArgs (mouseEvent);
  312. MouseEnter?.Invoke (this, args);
  313. #if HOVER
  314. if (HighlightStyle.HasFlag(HighlightStyle.Hover))
  315. {
  316. if (SetHighlight (HighlightStyle.Hover))
  317. {
  318. return true;
  319. }
  320. }
  321. #endif
  322. return args.Handled;
  323. }
  324. /// <summary>
  325. /// INTERNAL Called by <see cref="Application.OnMouseEvent"/> when the mouse leaves <see cref="Frame"/>.
  326. /// </summary>
  327. /// <remarks>
  328. /// <para>
  329. /// A view must be visible to receive Enter events (Leave events are always received).
  330. /// </para>
  331. /// <para>
  332. /// This method calls <see cref="OnMouseLeave"/> to raise the <see cref="MouseLeave"/> event.
  333. /// </para>
  334. /// <para>
  335. /// Adornments receive MouseEnter/Leave events when the mouse is over the Adornment's <see cref="Thickness"/>.
  336. /// </para>
  337. /// <para>
  338. /// See <see cref="SetHighlight"/> for more information.
  339. /// </para>
  340. /// </remarks>
  341. /// <param name="mouseEvent"></param>
  342. /// <returns><see langword="true"/> if the event was handled, <see langword="false"/> otherwise. </returns>
  343. internal bool? NewMouseLeaveEvent (MouseEvent mouseEvent)
  344. {
  345. if (OnMouseLeave (mouseEvent))
  346. {
  347. return true;
  348. }
  349. var args = new MouseEventEventArgs (mouseEvent);
  350. MouseLeave?.Invoke (this, args);
  351. #if HOVER
  352. if (HighlightStyle.HasFlag (HighlightStyle.Hover))
  353. {
  354. SetHighlight (HighlightStyle.None);
  355. }
  356. #endif
  357. return args.Handled;
  358. }
  359. /// <summary>
  360. /// Enables the highlight for the view when the mouse is pressed. Called from OnMouseEvent.
  361. /// </summary>
  362. /// <remarks>
  363. /// <para>
  364. /// Set <see cref="HighlightStyle"/> to have the view highlighted based on the mouse.
  365. /// </para>
  366. /// <para>
  367. /// Calls <see cref="OnHighlight"/> which fires the <see cref="Highlight"/> event.
  368. /// </para>
  369. /// <para>
  370. /// Marked internal just to support unit tests
  371. /// </para>
  372. /// </remarks>
  373. /// <returns><see langword="true"/>, if the Highlight event was handled, <see langword="false"/> otherwise.</returns>
  374. internal bool SetHighlight (HighlightStyle newHighlightStyle)
  375. {
  376. // TODO: Make the highlight colors configurable
  377. if (!CanFocus)
  378. {
  379. return false;
  380. }
  381. // Enable override via virtual method and/or event
  382. HighlightStyle copy = HighlightStyle;
  383. var args = new CancelEventArgs<HighlightStyle> (ref copy, ref newHighlightStyle);
  384. if (OnHighlight (args) == true)
  385. {
  386. return true;
  387. }
  388. #if HOVER
  389. if (style.HasFlag (HighlightStyle.Hover))
  390. {
  391. if (_savedHighlightColorScheme is null && ColorScheme is { })
  392. {
  393. _savedHighlightColorScheme ??= ColorScheme;
  394. var cs = new ColorScheme (ColorScheme)
  395. {
  396. Normal = GetFocusColor (),
  397. HotNormal = ColorScheme.HotFocus
  398. };
  399. ColorScheme = cs;
  400. }
  401. return true;
  402. }
  403. #endif
  404. if (args.NewValue.HasFlag (HighlightStyle.Pressed) || args.NewValue.HasFlag (HighlightStyle.PressedOutside))
  405. {
  406. if (_savedHighlightColorScheme is null && ColorScheme is { })
  407. {
  408. _savedHighlightColorScheme ??= ColorScheme;
  409. if (CanFocus)
  410. {
  411. var cs = new ColorScheme (ColorScheme)
  412. {
  413. // Highlight the foreground focus color
  414. Focus = new (ColorScheme.Focus.Foreground.GetHighlightColor (), ColorScheme.Focus.Background.GetHighlightColor ())
  415. };
  416. ColorScheme = cs;
  417. }
  418. else
  419. {
  420. var cs = new ColorScheme (ColorScheme)
  421. {
  422. // Invert Focus color foreground/background. We can do this because we know the view is not going to be focused.
  423. Normal = new (ColorScheme.Focus.Background, ColorScheme.Normal.Foreground)
  424. };
  425. ColorScheme = cs;
  426. }
  427. }
  428. // Return false since we don't want to eat the event
  429. return false;
  430. }
  431. if (args.NewValue == HighlightStyle.None)
  432. {
  433. // Unhighlight
  434. if (_savedHighlightColorScheme is { })
  435. {
  436. ColorScheme = _savedHighlightColorScheme;
  437. _savedHighlightColorScheme = null;
  438. }
  439. }
  440. return false;
  441. }
  442. /// <summary>
  443. /// For cases where the view is grabbed and the mouse is clicked, this method handles the released event (typically
  444. /// when <see cref="WantContinuousButtonPressed"/> or <see cref="HighlightStyle"/> are set).
  445. /// </summary>
  446. /// <remarks>
  447. /// <para>
  448. /// Marked internal just to support unit tests
  449. /// </para>
  450. /// </remarks>
  451. /// <param name="mouseEvent"></param>
  452. /// <returns><see langword="true"/>, if the event was handled, <see langword="false"/> otherwise.</returns>
  453. private bool HandlePressed (MouseEvent mouseEvent)
  454. {
  455. if (mouseEvent.Flags.HasFlag (MouseFlags.Button1Pressed)
  456. || mouseEvent.Flags.HasFlag (MouseFlags.Button2Pressed)
  457. || mouseEvent.Flags.HasFlag (MouseFlags.Button3Pressed)
  458. || mouseEvent.Flags.HasFlag (MouseFlags.Button4Pressed))
  459. {
  460. // The first time we get pressed event, grab the mouse and set focus
  461. if (Application.MouseGrabView != this)
  462. {
  463. Application.GrabMouse (this);
  464. if (!HasFocus && CanFocus)
  465. {
  466. // Set the focus, but don't invoke Accept
  467. SetFocus ();
  468. }
  469. mouseEvent.Handled = true;
  470. }
  471. if (Viewport.Contains (mouseEvent.Position))
  472. {
  473. if (this is not Adornment
  474. && SetHighlight (HighlightStyle.HasFlag (HighlightStyle.Pressed) ? HighlightStyle.Pressed : HighlightStyle.None))
  475. {
  476. return true;
  477. }
  478. }
  479. else
  480. {
  481. if (this is not Adornment
  482. && SetHighlight (HighlightStyle.HasFlag (HighlightStyle.PressedOutside) ? HighlightStyle.PressedOutside : HighlightStyle.None))
  483. {
  484. return true;
  485. }
  486. }
  487. if (WantContinuousButtonPressed && Application.MouseGrabView == this)
  488. {
  489. // If this is not the first pressed event, click
  490. return OnMouseClick (new (mouseEvent));
  491. }
  492. return mouseEvent.Handled = true;
  493. }
  494. return false;
  495. }
  496. /// <summary>
  497. /// INTERNAL: Gets the Views that are under the mouse at <paramref name="location"/>, including Adornments.
  498. /// </summary>
  499. /// <param name="location"></param>
  500. /// <returns></returns>
  501. internal static List<View?> GetViewsUnderMouse (in Point location)
  502. {
  503. List<View?> viewsUnderMouse = new ();
  504. View? start = Application.Current ?? Application.Top;
  505. Point currentLocation = location;
  506. while (start is { Visible: true } && start.Contains (currentLocation))
  507. {
  508. viewsUnderMouse.Add (start);
  509. Adornment? found = null;
  510. if (start.Margin.Contains (currentLocation))
  511. {
  512. found = start.Margin;
  513. }
  514. else if (start.Border.Contains (currentLocation))
  515. {
  516. found = start.Border;
  517. }
  518. else if (start.Padding.Contains (currentLocation))
  519. {
  520. found = start.Padding;
  521. }
  522. Point viewportOffset = start.GetViewportOffsetFromFrame ();
  523. if (found is { })
  524. {
  525. start = found;
  526. viewsUnderMouse.Add (start);
  527. viewportOffset = found.Parent?.Frame.Location ?? Point.Empty;
  528. }
  529. int startOffsetX = currentLocation.X - (start.Frame.X + viewportOffset.X);
  530. int startOffsetY = currentLocation.Y - (start.Frame.Y + viewportOffset.Y);
  531. View? subview = null;
  532. for (int i = start.InternalSubviews.Count - 1; i >= 0; i--)
  533. {
  534. if (start.InternalSubviews [i].Visible
  535. && start.InternalSubviews [i].Contains (new (startOffsetX + start.Viewport.X, startOffsetY + start.Viewport.Y)))
  536. {
  537. subview = start.InternalSubviews [i];
  538. currentLocation.X = startOffsetX + start.Viewport.X;
  539. currentLocation.Y = startOffsetY + start.Viewport.Y;
  540. // start is the deepest subview under the mouse; stop searching the subviews
  541. break;
  542. }
  543. }
  544. if (subview is null)
  545. {
  546. // No subview was found that's under the mouse, so we're done
  547. return viewsUnderMouse;
  548. }
  549. // We found a subview of start that's under the mouse, continue...
  550. start = subview;
  551. }
  552. return viewsUnderMouse;
  553. }
  554. }