View.Mouse.cs 23 KB

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