View.Mouse.cs 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645
  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/Leave events.
  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/Leave events.
  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 (!CanBeVisible (this))
  346. {
  347. return false;
  348. }
  349. if (OnMouseLeave (mouseEvent))
  350. {
  351. return true;
  352. }
  353. var args = new MouseEventEventArgs (mouseEvent);
  354. MouseLeave?.Invoke (this, args);
  355. #if HOVER
  356. if (HighlightStyle.HasFlag (HighlightStyle.Hover))
  357. {
  358. SetHighlight (HighlightStyle.None);
  359. }
  360. #endif
  361. return args.Handled;
  362. }
  363. /// <summary>
  364. /// Enables the highlight for the view when the mouse is pressed. Called from OnMouseEvent.
  365. /// </summary>
  366. /// <remarks>
  367. /// <para>
  368. /// Set <see cref="HighlightStyle"/> to have the view highlighted based on the mouse.
  369. /// </para>
  370. /// <para>
  371. /// Calls <see cref="OnHighlight"/> which fires the <see cref="Highlight"/> event.
  372. /// </para>
  373. /// <para>
  374. /// Marked internal just to support unit tests
  375. /// </para>
  376. /// </remarks>
  377. /// <returns><see langword="true"/>, if the Highlight event was handled, <see langword="false"/> otherwise.</returns>
  378. internal bool SetHighlight (HighlightStyle newHighlightStyle)
  379. {
  380. // TODO: Make the highlight colors configurable
  381. if (!CanFocus)
  382. {
  383. return false;
  384. }
  385. // Enable override via virtual method and/or event
  386. HighlightStyle copy = HighlightStyle;
  387. var args = new CancelEventArgs<HighlightStyle> (ref copy, ref newHighlightStyle);
  388. if (OnHighlight (args) == true)
  389. {
  390. return true;
  391. }
  392. #if HOVER
  393. if (style.HasFlag (HighlightStyle.Hover))
  394. {
  395. if (_savedHighlightColorScheme is null && ColorScheme is { })
  396. {
  397. _savedHighlightColorScheme ??= ColorScheme;
  398. var cs = new ColorScheme (ColorScheme)
  399. {
  400. Normal = GetFocusColor (),
  401. HotNormal = ColorScheme.HotFocus
  402. };
  403. ColorScheme = cs;
  404. }
  405. return true;
  406. }
  407. #endif
  408. if (args.NewValue.HasFlag (HighlightStyle.Pressed) || args.NewValue.HasFlag (HighlightStyle.PressedOutside))
  409. {
  410. if (_savedHighlightColorScheme is null && ColorScheme is { })
  411. {
  412. _savedHighlightColorScheme ??= ColorScheme;
  413. if (CanFocus)
  414. {
  415. var cs = new ColorScheme (ColorScheme)
  416. {
  417. // Highlight the foreground focus color
  418. Focus = new (ColorScheme.Focus.Foreground.GetHighlightColor (), ColorScheme.Focus.Background.GetHighlightColor ())
  419. };
  420. ColorScheme = cs;
  421. }
  422. else
  423. {
  424. var cs = new ColorScheme (ColorScheme)
  425. {
  426. // Invert Focus color foreground/background. We can do this because we know the view is not going to be focused.
  427. Normal = new (ColorScheme.Focus.Background, ColorScheme.Normal.Foreground)
  428. };
  429. ColorScheme = cs;
  430. }
  431. }
  432. // Return false since we don't want to eat the event
  433. return false;
  434. }
  435. if (args.NewValue == HighlightStyle.None)
  436. {
  437. // Unhighlight
  438. if (_savedHighlightColorScheme is { })
  439. {
  440. ColorScheme = _savedHighlightColorScheme;
  441. _savedHighlightColorScheme = null;
  442. }
  443. }
  444. return false;
  445. }
  446. /// <summary>
  447. /// For cases where the view is grabbed and the mouse is clicked, this method handles the released event (typically
  448. /// when <see cref="WantContinuousButtonPressed"/> or <see cref="HighlightStyle"/> are set).
  449. /// </summary>
  450. /// <remarks>
  451. /// <para>
  452. /// Marked internal just to support unit tests
  453. /// </para>
  454. /// </remarks>
  455. /// <param name="mouseEvent"></param>
  456. /// <returns><see langword="true"/>, if the event was handled, <see langword="false"/> otherwise.</returns>
  457. private bool HandlePressed (MouseEvent mouseEvent)
  458. {
  459. if (mouseEvent.Flags.HasFlag (MouseFlags.Button1Pressed)
  460. || mouseEvent.Flags.HasFlag (MouseFlags.Button2Pressed)
  461. || mouseEvent.Flags.HasFlag (MouseFlags.Button3Pressed)
  462. || mouseEvent.Flags.HasFlag (MouseFlags.Button4Pressed))
  463. {
  464. // The first time we get pressed event, grab the mouse and set focus
  465. if (Application.MouseGrabView != this)
  466. {
  467. Application.GrabMouse (this);
  468. if (!HasFocus && CanFocus)
  469. {
  470. // Set the focus, but don't invoke Accept
  471. SetFocus ();
  472. }
  473. mouseEvent.Handled = true;
  474. }
  475. if (Viewport.Contains (mouseEvent.Position))
  476. {
  477. if (this is not Adornment
  478. && SetHighlight (HighlightStyle.HasFlag (HighlightStyle.Pressed) ? HighlightStyle.Pressed : HighlightStyle.None))
  479. {
  480. return true;
  481. }
  482. }
  483. else
  484. {
  485. if (this is not Adornment
  486. && SetHighlight (HighlightStyle.HasFlag (HighlightStyle.PressedOutside) ? HighlightStyle.PressedOutside : HighlightStyle.None))
  487. {
  488. return true;
  489. }
  490. }
  491. if (WantContinuousButtonPressed && Application.MouseGrabView == this)
  492. {
  493. // If this is not the first pressed event, click
  494. return OnMouseClick (new (mouseEvent));
  495. }
  496. return mouseEvent.Handled = true;
  497. }
  498. return false;
  499. }
  500. /// <summary>
  501. /// INTERNAL: Gets the Views that are under the mouse at <paramref name="location"/>, including Adornments.
  502. /// </summary>
  503. /// <param name="location"></param>
  504. /// <returns></returns>
  505. internal static List<View?> GetViewsUnderMouse (in Point location)
  506. {
  507. List<View?> viewsUnderMouse = new ();
  508. View? start = Application.Current ?? Application.Top;
  509. Point currentLocation = location;
  510. while (start is { Visible: true } && start.Contains (currentLocation))
  511. {
  512. viewsUnderMouse.Add (start);
  513. Adornment? found = null;
  514. if (start.Margin.Contains (currentLocation))
  515. {
  516. found = start.Margin;
  517. }
  518. else if (start.Border.Contains (currentLocation))
  519. {
  520. found = start.Border;
  521. }
  522. else if (start.Padding.Contains (currentLocation))
  523. {
  524. found = start.Padding;
  525. }
  526. Point viewportOffset = start.GetViewportOffsetFromFrame ();
  527. if (found is { })
  528. {
  529. start = found;
  530. viewsUnderMouse.Add (start);
  531. viewportOffset = found.Parent?.Frame.Location ?? Point.Empty;
  532. }
  533. int startOffsetX = currentLocation.X - (start.Frame.X + viewportOffset.X);
  534. int startOffsetY = currentLocation.Y - (start.Frame.Y + viewportOffset.Y);
  535. View? subview = null;
  536. for (int i = start.InternalSubviews.Count - 1; i >= 0; i--)
  537. {
  538. if (start.InternalSubviews [i].Visible
  539. && start.InternalSubviews [i].Contains (new (startOffsetX + start.Viewport.X, startOffsetY + start.Viewport.Y)))
  540. {
  541. subview = start.InternalSubviews [i];
  542. currentLocation.X = startOffsetX + start.Viewport.X;
  543. currentLocation.Y = startOffsetY + start.Viewport.Y;
  544. // start is the deepest subview under the mouse; stop searching the subviews
  545. break;
  546. }
  547. }
  548. if (subview is null)
  549. {
  550. // No subview was found that's under the mouse, so we're done
  551. return viewsUnderMouse;
  552. }
  553. // We found a subview of start that's under the mouse, continue...
  554. start = subview;
  555. }
  556. return viewsUnderMouse;
  557. }
  558. }