private MouseTarget findTargetTab(final double x,
                                      final double y,
                                      final TabLayoutConfig layoutConfig,
                                      final PositionAndSize positionAndSize,
                                      final boolean selecting) {
        MouseTarget mouseTarget = null;

        final double width = positionAndSize.getWidth();
        final double height = positionAndSize.getHeight();
        final double left = ElementUtil.getClientLeft(designSurfaceElement) + positionAndSize.getLeft();
        final double right = left + width;
        final double top = ElementUtil.getClientTop(designSurfaceElement) + positionAndSize.getTop();
        final double bottom = top + height;

        // First see if the mouse is even over the layout.
        if (x >= left && x <= right && y >= top && y <= bottom) {
            // Test if the mouse is over a tab.
            final TabLayout tabLayout = layoutToWidgetMap.get(layoutConfig);
            if (tabLayout != null && tabLayout.getTabBar().getTabs() != null) {
                final LinkTabBar tabBar = tabLayout.getTabBar();
                if (x >= ElementUtil.getClientLeft(tabBar.getElement()) &&
                        x <= ElementUtil.getClientLeft(tabBar.getElement()) +
                                ElementUtil.getSubPixelOffsetWidth(tabBar.getElement()) &&
                        y >= ElementUtil.getClientTop(tabBar.getElement()) &&
                        y <= ElementUtil.getClientTop(tabBar.getElement()) + tabBar.getOffsetHeight()) {

                    final List<TabConfig> tabConfigList = layoutConfig.getTabs();
                    int visibleTabIndex = 0;
                    for (int i = 0; i < tabConfigList.size(); i++) {
                        final TabConfig tabConfig = tabConfigList.get(i);
                        if (tabConfig.visible()) {
                            final TabData tabData = tabBar.getTabs().get(visibleTabIndex);

                            // This is somewhat confusing but there is a difference between tabs that have been hidden
                            // by the user and tabs that are not currently visible due to UI size constraints.
                            if (tabBar.getVisibleTabs().contains(tabData)) {
                                final LinkTab linkTab = (LinkTab) tabBar.getTab(tabData);
                                final Element tabElement = linkTab.getElement();

                                if (selecting) {
                                    if (x >= ElementUtil.getClientLeft(tabElement) &&
                                            x <= ElementUtil.getClientRight(tabElement)) {
                                        // If the mouse position is left or equal to the right-hand side of the tab
                                        // then this tab might be the one to select.
                                        mouseTarget = new MouseTarget(layoutConfig,
                                                positionAndSize,
                                                Pos.TAB,
                                                tabLayout,
                                                layoutConfig,
                                                Collections.singletonList(tabData),
                                                i,
                                                linkTab);
                                    }
                                } else if (selection == null || !tabData.equals(selection.getFirstTab())) {
                                    final double clientLeft = ElementUtil.getClientLeft(tabElement);
                                    final double clientRight = ElementUtil.getClientRight(tabElement);
//                                    Console.log(tabData.getLabel() +
//                                            " " +
//                                            "clientLeft=" +
//                                            clientLeft +
//                                            " clientRight=" +
//                                            clientRight +
//                                            " x=" +
//                                            x);

                                    if (x >= clientLeft && x <= clientRight) {
                                        // If the mouse position is over the tab then we might want to insert before
                                        // this tab.
                                        mouseTarget = new MouseTarget(layoutConfig,
                                                positionAndSize,
                                                Pos.TAB,
                                                tabLayout,
                                                layoutConfig,
                                                Collections.singletonList(tabData),
                                                i,
                                                linkTab);
//                                        Console.log("tab");

                                    } else if (x > clientRight) {
                                        // If the mouse position is right of the right-hand side of the tab then we
                                        // might want to insert the tab we are dragging after the current tab.
                                        mouseTarget = new MouseTarget(layoutConfig,
                                                positionAndSize,
                                                Pos.AFTER_TAB,
                                                tabLayout,
                                                layoutConfig,
                                                Collections.singletonList(tabData),
                                                i + 1,
                                                linkTab);
//                                        Console.log("after tab");
                                    }
                                }
                            }

                            visibleTabIndex++;
                        }
                    }
                }
            }
        }

        return mouseTarget;
    }
Tests the supplied layout to see if it is the current mouse target and
returns mouse target if it is.

@param x               The mouse x coordinate.
@param y               The mouse y coordinate.
@param splitter        True if the layout is a splitter. Splitters are targeted
                       outside their rect.
@param layoutConfig    The layout data to test to see if it is a target.
@param positionAndSize The position and size of the layout being tested.
@return The mouse target if the tested layout is the target, else null.
stroom-core-client/src/main/java/stroom/dashboard/client/flexlayout/FlexLayout.java