private ToolLayout CalculateLayout()
        {
            ToolLayout layout = new ToolLayout();

            Bounds bounds = selectionBounds;

            bool canScaleX = !Mathf.Approximately(bounds.size.x, 0f);

            float xMin = TimeToPixel(bounds.min.x);
            float xMax = TimeToPixel(bounds.max.x);

            float yMin = 0f, yMax = 0f;
            bool  firstKey = true;

            float heightCumul = 0f;

            List <DopeLine> dopelines = m_State.dopelines;

            for (int i = 0; i < dopelines.Count; ++i)
            {
                DopeLine dopeline = dopelines[i];

                float dopelineHeight = (dopeline.tallMode ? AnimationWindowHierarchyGUI.k_DopeSheetRowHeightTall : AnimationWindowHierarchyGUI.k_DopeSheetRowHeight);

                if (!dopeline.isMasterDopeline)
                {
                    int length = dopeline.keys.Count;
                    for (int j = 0; j < length; j++)
                    {
                        AnimationWindowKeyframe keyframe = dopeline.keys[j];
                        if (m_State.KeyIsSelected(keyframe))
                        {
                            if (firstKey)
                            {
                                yMin     = heightCumul;
                                firstKey = false;
                            }

                            yMax = heightCumul + dopelineHeight;
                            break;
                        }
                    }
                }

                heightCumul += dopelineHeight;
            }

            layout.summaryRect   = new Rect(xMin, 0f, xMax - xMin, AnimationWindowHierarchyGUI.k_DopeSheetRowHeight);
            layout.selectionRect = new Rect(xMin, yMin, xMax - xMin, yMax - yMin);

            // Scale handles.
            if (canScaleX)
            {
                layout.scaleLeftRect  = new Rect(layout.selectionRect.xMin - kScaleLeftMarginHorizontal - kScaleLeftWidth, layout.selectionRect.yMin + kScaleLeftMarginVertical, kScaleLeftWidth, layout.selectionRect.height - kScaleLeftMarginVertical * 2);
                layout.scaleRightRect = new Rect(layout.selectionRect.xMax + kScaleRightMarginHorizontal, layout.selectionRect.yMin + kScaleRightMarginVertical, kScaleRightWidth, layout.selectionRect.height - kScaleRightMarginVertical * 2);
            }
            else
            {
                layout.scaleLeftRect  = g_EmptyRect;
                layout.scaleRightRect = g_EmptyRect;
            }

            if (canScaleX)
            {
                layout.leftLabelAnchor  = new Vector2(layout.summaryRect.xMin - kHLabelMarginHorizontal, contentRect.yMin + kHLabelMarginVertical);
                layout.rightLabelAnchor = new Vector2(layout.summaryRect.xMax + kHLabelMarginHorizontal, contentRect.yMin + kHLabelMarginVertical);
            }
            else
            {
                layout.leftLabelAnchor = layout.rightLabelAnchor = new Vector2(layout.summaryRect.center.x + kHLabelMarginHorizontal, contentRect.yMin + kHLabelMarginVertical);
            }

            return(layout);
        }