View.Mouse.cs 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647
  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. var args = new MouseEventEventArgs (mouseEvent);
  141. MouseEnter?.Invoke (this, args);
  142. return args.Handled;
  143. }
  144. /// <summary>Called when a mouse event occurs within the view's <see cref="Viewport"/>.</summary>
  145. /// <remarks>
  146. /// <para>
  147. /// The coordinates are relative to <see cref="View.Viewport"/>.
  148. /// </para>
  149. /// </remarks>
  150. /// <param name="mouseEvent"></param>
  151. /// <returns><see langword="true"/>, if the event was handled, <see langword="false"/> otherwise.</returns>
  152. protected internal virtual bool OnMouseEvent (MouseEvent mouseEvent)
  153. {
  154. var args = new MouseEventEventArgs (mouseEvent);
  155. MouseEvent?.Invoke (this, args);
  156. return args.Handled;
  157. }
  158. /// <summary>
  159. /// Called by <see cref="NewMouseEvent"/> when a mouse leaves <see cref="Viewport"/>. The view will
  160. /// no longer receive mouse events.
  161. /// </summary>
  162. /// <remarks>
  163. /// <para>
  164. /// Override this method or subscribe to <see cref="MouseEnter"/> to change the default leave behavior.
  165. /// </para>
  166. /// <para>
  167. /// The coordinates are relative to <see cref="View.Viewport"/>.
  168. /// </para>
  169. /// </remarks>
  170. /// <param name="mouseEvent"></param>
  171. /// <returns><see langword="true"/>, if the event was handled, <see langword="false"/> otherwise.</returns>
  172. protected internal virtual bool OnMouseLeave (MouseEvent mouseEvent)
  173. {
  174. if (!Enabled)
  175. {
  176. return true;
  177. }
  178. if (!CanBeVisible (this))
  179. {
  180. return false;
  181. }
  182. var args = new MouseEventEventArgs (mouseEvent);
  183. MouseLeave?.Invoke (this, args);
  184. return args.Handled;
  185. }
  186. /// <summary>
  187. /// Called when the view is to be highlighted.
  188. /// </summary>
  189. /// <returns><see langword="true"/>, if the event was handled, <see langword="false"/> otherwise.</returns>
  190. protected virtual bool? OnHighlight (CancelEventArgs<HighlightStyle> args)
  191. {
  192. Highlight?.Invoke (this, args);
  193. if (args.Cancel)
  194. {
  195. return true;
  196. }
  197. Margin?.Highlight?.Invoke (this, args);
  198. //args = new (highlight);
  199. //Border?.Highlight?.Invoke (this, args);
  200. //args = new (highlight);
  201. //Padding?.Highlight?.Invoke (this, args);
  202. return args.Cancel;
  203. }
  204. /// <summary>Invokes the MouseClick event.</summary>
  205. /// <remarks>
  206. /// <para>
  207. /// Called when the mouse is either clicked or double-clicked. Check
  208. /// <see cref="MouseEvent.Flags"/> to see which button was clicked.
  209. /// </para>
  210. /// </remarks>
  211. /// <returns><see langword="true"/>, if the event was handled, <see langword="false"/> otherwise.</returns>
  212. protected bool OnMouseClick (MouseEventEventArgs args)
  213. {
  214. if (!Enabled)
  215. {
  216. // QUESTION: Is this right? Should a disabled view eat mouse clicks?
  217. return args.Handled = false;
  218. }
  219. MouseClick?.Invoke (this, args);
  220. if (args.Handled)
  221. {
  222. return true;
  223. }
  224. if (!HasFocus && CanFocus)
  225. {
  226. args.Handled = true;
  227. SetFocus ();
  228. }
  229. return args.Handled;
  230. }
  231. /// <summary>
  232. /// For cases where the view is grabbed and the mouse is clicked, this method handles the click event (typically
  233. /// when <see cref="WantContinuousButtonPressed"/> or <see cref="HighlightStyle"/> are set).
  234. /// </summary>
  235. /// <remarks>
  236. /// Marked internal just to support unit tests
  237. /// </remarks>
  238. /// <param name="mouseEvent"></param>
  239. /// <returns><see langword="true"/>, if the event was handled, <see langword="false"/> otherwise.</returns>
  240. internal bool HandleClicked (MouseEvent mouseEvent)
  241. {
  242. if (Application.MouseGrabView == this
  243. && (mouseEvent.Flags.HasFlag (MouseFlags.Button1Clicked)
  244. || mouseEvent.Flags.HasFlag (MouseFlags.Button2Clicked)
  245. || mouseEvent.Flags.HasFlag (MouseFlags.Button3Clicked)
  246. || mouseEvent.Flags.HasFlag (MouseFlags.Button4Clicked)))
  247. {
  248. // We're grabbed. Clicked event comes after the last Release. This is our signal to ungrab
  249. Application.UngrabMouse ();
  250. if (SetHighlight (HighlightStyle.None))
  251. {
  252. return true;
  253. }
  254. // If mouse is still in bounds, click
  255. if (!WantContinuousButtonPressed && Viewport.Contains (mouseEvent.Position))
  256. {
  257. return OnMouseClick (new (mouseEvent));
  258. }
  259. return mouseEvent.Handled = true;
  260. }
  261. return false;
  262. }
  263. /// <summary>
  264. /// For cases where the view is grabbed and the mouse is clicked, this method handles the released event (typically
  265. /// when <see cref="WantContinuousButtonPressed"/> or <see cref="HighlightStyle"/> are set).
  266. /// </summary>
  267. /// <remarks>
  268. /// Marked internal just to support unit tests
  269. /// </remarks>
  270. /// <param name="mouseEvent"></param>
  271. /// <returns><see langword="true"/>, if the event was handled, <see langword="false"/> otherwise.</returns>
  272. internal bool HandleReleased (MouseEvent mouseEvent)
  273. {
  274. if (mouseEvent.Flags.HasFlag (MouseFlags.Button1Released)
  275. || mouseEvent.Flags.HasFlag (MouseFlags.Button2Released)
  276. || mouseEvent.Flags.HasFlag (MouseFlags.Button3Released)
  277. || mouseEvent.Flags.HasFlag (MouseFlags.Button4Released))
  278. {
  279. if (Application.MouseGrabView == this)
  280. {
  281. SetHighlight (HighlightStyle.None);
  282. }
  283. return mouseEvent.Handled = true;
  284. }
  285. return false;
  286. }
  287. /// <summary>
  288. /// Called by <see cref="Application.OnMouseEvent"/> when the mouse enters <see cref="Viewport"/>. <see cref="MouseLeave"/> will
  289. /// be raised when the mouse is no longer over the <see cref="Viewport"/>. If another View occludes the current one, the
  290. /// that View will also receive a MouseEnter event.
  291. /// </summary>
  292. /// <remarks>
  293. /// <para>
  294. /// A view must be visible to receive Enter/Leave events.
  295. /// </para>
  296. /// <para>
  297. /// This method calls <see cref="OnMouseEnter"/> to raise the <see cref="MouseEnter"/> event.
  298. /// </para>
  299. /// <para>
  300. /// See <see cref="SetHighlight"/> for more information.
  301. /// </para>
  302. /// </remarks>
  303. /// <param name="mouseEvent"></param>
  304. /// <returns><see langword="true"/> if the event was handled, <see langword="false"/> otherwise. Handling the event
  305. /// prevents Views higher in the visible hierarchy from recieving Enter/Leave events.</returns>
  306. internal bool? NewMouseEnterEvent (MouseEvent mouseEvent)
  307. {
  308. if (!Enabled)
  309. {
  310. return true;
  311. }
  312. if (!CanBeVisible (this))
  313. {
  314. return false;
  315. }
  316. if (OnMouseEnter (mouseEvent) == true)
  317. {
  318. return true;
  319. }
  320. #if HOVER
  321. if (HighlightStyle.HasFlag(HighlightStyle.Hover))
  322. {
  323. if (SetHighlight (HighlightStyle.Hover))
  324. {
  325. return true;
  326. }
  327. }
  328. #endif
  329. return false;
  330. }
  331. /// <summary>
  332. /// Called by <see cref="Application.OnMouseEvent"/> when the mouse leaves <see cref="Viewport"/>.
  333. /// </summary>
  334. /// <remarks>
  335. /// <para>
  336. /// A view must be visible to receive Enter/Leave events.
  337. /// </para>
  338. /// <para>
  339. /// This method calls <see cref="OnMouseLeave"/> to raise the <see cref="MouseLeave"/> event.
  340. /// </para>
  341. /// <para>
  342. /// See <see cref="SetHighlight"/> for more information.
  343. /// </para>
  344. /// </remarks>
  345. /// <param name="mouseEvent"></param>
  346. /// <returns><see langword="true"/> if the event was handled, <see langword="false"/> otherwise. </returns>
  347. internal bool? NewMouseLeaveEvent (MouseEvent mouseEvent)
  348. {
  349. if (!CanBeVisible (this))
  350. {
  351. return false;
  352. }
  353. if (OnMouseLeave (mouseEvent))
  354. {
  355. return true;
  356. }
  357. #if HOVER
  358. if (HighlightStyle.HasFlag (HighlightStyle.Hover))
  359. {
  360. SetHighlight (HighlightStyle.None);
  361. }
  362. #endif
  363. return false;
  364. }
  365. /// <summary>
  366. /// Enables the highlight for the view when the mouse is pressed. Called from OnMouseEvent.
  367. /// </summary>
  368. /// <remarks>
  369. /// <para>
  370. /// Set <see cref="HighlightStyle"/> to have the view highlighted based on the mouse.
  371. /// </para>
  372. /// <para>
  373. /// Calls <see cref="OnHighlight"/> which fires the <see cref="Highlight"/> event.
  374. /// </para>
  375. /// <para>
  376. /// Marked internal just to support unit tests
  377. /// </para>
  378. /// </remarks>
  379. /// <returns><see langword="true"/>, if the Highlight event was handled, <see langword="false"/> otherwise.</returns>
  380. internal bool SetHighlight (HighlightStyle newHighlightStyle)
  381. {
  382. // TODO: Make the highlight colors configurable
  383. if (!CanFocus)
  384. {
  385. return false;
  386. }
  387. // Enable override via virtual method and/or event
  388. HighlightStyle copy = HighlightStyle;
  389. var args = new CancelEventArgs<HighlightStyle> (ref copy, ref newHighlightStyle);
  390. if (OnHighlight (args) == true)
  391. {
  392. return true;
  393. }
  394. #if HOVER
  395. if (style.HasFlag (HighlightStyle.Hover))
  396. {
  397. if (_savedHighlightColorScheme is null && ColorScheme is { })
  398. {
  399. _savedHighlightColorScheme ??= ColorScheme;
  400. var cs = new ColorScheme (ColorScheme)
  401. {
  402. Normal = GetFocusColor (),
  403. HotNormal = ColorScheme.HotFocus
  404. };
  405. ColorScheme = cs;
  406. }
  407. return true;
  408. }
  409. #endif
  410. if (args.NewValue.HasFlag (HighlightStyle.Pressed) || args.NewValue.HasFlag (HighlightStyle.PressedOutside))
  411. {
  412. if (_savedHighlightColorScheme is null && ColorScheme is { })
  413. {
  414. _savedHighlightColorScheme ??= ColorScheme;
  415. if (CanFocus)
  416. {
  417. var cs = new ColorScheme (ColorScheme)
  418. {
  419. // Highlight the foreground focus color
  420. Focus = new (ColorScheme.Focus.Foreground.GetHighlightColor (), ColorScheme.Focus.Background.GetHighlightColor ())
  421. };
  422. ColorScheme = cs;
  423. }
  424. else
  425. {
  426. var cs = new ColorScheme (ColorScheme)
  427. {
  428. // Invert Focus color foreground/background. We can do this because we know the view is not going to be focused.
  429. Normal = new (ColorScheme.Focus.Background, ColorScheme.Normal.Foreground)
  430. };
  431. ColorScheme = cs;
  432. }
  433. }
  434. // Return false since we don't want to eat the event
  435. return false;
  436. }
  437. if (args.NewValue == HighlightStyle.None)
  438. {
  439. // Unhighlight
  440. if (_savedHighlightColorScheme is { })
  441. {
  442. ColorScheme = _savedHighlightColorScheme;
  443. _savedHighlightColorScheme = null;
  444. }
  445. }
  446. return false;
  447. }
  448. /// <summary>
  449. /// For cases where the view is grabbed and the mouse is clicked, this method handles the released event (typically
  450. /// when <see cref="WantContinuousButtonPressed"/> or <see cref="HighlightStyle"/> are set).
  451. /// </summary>
  452. /// <remarks>
  453. /// <para>
  454. /// Marked internal just to support unit tests
  455. /// </para>
  456. /// </remarks>
  457. /// <param name="mouseEvent"></param>
  458. /// <returns><see langword="true"/>, if the event was handled, <see langword="false"/> otherwise.</returns>
  459. private bool HandlePressed (MouseEvent mouseEvent)
  460. {
  461. if (mouseEvent.Flags.HasFlag (MouseFlags.Button1Pressed)
  462. || mouseEvent.Flags.HasFlag (MouseFlags.Button2Pressed)
  463. || mouseEvent.Flags.HasFlag (MouseFlags.Button3Pressed)
  464. || mouseEvent.Flags.HasFlag (MouseFlags.Button4Pressed))
  465. {
  466. // The first time we get pressed event, grab the mouse and set focus
  467. if (Application.MouseGrabView != this)
  468. {
  469. Application.GrabMouse (this);
  470. if (!HasFocus && CanFocus)
  471. {
  472. // Set the focus, but don't invoke Accept
  473. SetFocus ();
  474. }
  475. mouseEvent.Handled = true;
  476. }
  477. if (Viewport.Contains (mouseEvent.Position))
  478. {
  479. if (this is not Adornment
  480. && SetHighlight (HighlightStyle.HasFlag (HighlightStyle.Pressed) ? HighlightStyle.Pressed : HighlightStyle.None))
  481. {
  482. return true;
  483. }
  484. }
  485. else
  486. {
  487. if (this is not Adornment
  488. && SetHighlight (HighlightStyle.HasFlag (HighlightStyle.PressedOutside) ? HighlightStyle.PressedOutside : HighlightStyle.None))
  489. {
  490. return true;
  491. }
  492. }
  493. if (WantContinuousButtonPressed && Application.MouseGrabView == this)
  494. {
  495. // If this is not the first pressed event, click
  496. return OnMouseClick (new (mouseEvent));
  497. }
  498. return mouseEvent.Handled = true;
  499. }
  500. return false;
  501. }
  502. /// <summary>
  503. /// INTERNAL: Gets the Views that are under the mouse at <paramref name="location"/>, including Adornments.
  504. /// </summary>
  505. /// <param name="location"></param>
  506. /// <returns></returns>
  507. internal static List<View?> GetViewsUnderMouse (in Point location)
  508. {
  509. List<View?> viewsUnderMouse = new ();
  510. View? start = Application.Current ?? Application.Top;
  511. Point currentLocation = location;
  512. while (start is { Visible: true } && start.Contains (currentLocation))
  513. {
  514. viewsUnderMouse.Add (start);
  515. Adornment? found = null;
  516. if (start.Margin.Contains (currentLocation))
  517. {
  518. found = start.Margin;
  519. }
  520. else if (start.Border.Contains (currentLocation))
  521. {
  522. found = start.Border;
  523. }
  524. else if (start.Padding.Contains (currentLocation))
  525. {
  526. found = start.Padding;
  527. }
  528. Point viewportOffset = start.GetViewportOffsetFromFrame ();
  529. if (found is { })
  530. {
  531. start = found;
  532. viewsUnderMouse.Add (start);
  533. viewportOffset = found.Parent?.Frame.Location ?? Point.Empty;
  534. }
  535. int startOffsetX = currentLocation.X - (start.Frame.X + viewportOffset.X);
  536. int startOffsetY = currentLocation.Y - (start.Frame.Y + viewportOffset.Y);
  537. View? subview = null;
  538. for (int i = start.InternalSubviews.Count - 1; i >= 0; i--)
  539. {
  540. if (start.InternalSubviews [i].Visible
  541. && start.InternalSubviews [i].Contains (new (startOffsetX + start.Viewport.X, startOffsetY + start.Viewport.Y)))
  542. {
  543. subview = start.InternalSubviews [i];
  544. currentLocation.X = startOffsetX + start.Viewport.X;
  545. currentLocation.Y = startOffsetY + start.Viewport.Y;
  546. // start is the deepest subview under the mouse; stop searching the subviews
  547. break;
  548. }
  549. }
  550. if (subview is null)
  551. {
  552. // No subview was found that's under the mouse, so we're done
  553. return viewsUnderMouse;
  554. }
  555. // We found a subview of start that's under the mouse, continue...
  556. start = subview;
  557. }
  558. return viewsUnderMouse;
  559. }
  560. }