diff options
author | iain holmes <iain@xamarin.com> | 2017-06-05 14:51:09 +0300 |
---|---|---|
committer | iain holmes <iain@xamarin.com> | 2017-06-05 14:51:09 +0300 |
commit | 37b48a615c6791aba6a72f025beab5f7a09a7ecc (patch) | |
tree | 14f8a8573a1d8d56306adfcf4f613ada46c06abb /main/src/core/MonoDevelop.Ide/MonoDevelop.Components | |
parent | 806a96fa11908634b08b0f26814b9522188cac9e (diff) |
[A11y] Make MonoDevelop.Components.Tabstrip keyboard accessible
Diffstat (limited to 'main/src/core/MonoDevelop.Ide/MonoDevelop.Components')
-rw-r--r-- | main/src/core/MonoDevelop.Ide/MonoDevelop.Components/Tabstrip.cs | 89 |
1 files changed, 86 insertions, 3 deletions
diff --git a/main/src/core/MonoDevelop.Ide/MonoDevelop.Components/Tabstrip.cs b/main/src/core/MonoDevelop.Ide/MonoDevelop.Components/Tabstrip.cs index 8e383e352a..b950d27904 100644 --- a/main/src/core/MonoDevelop.Ide/MonoDevelop.Components/Tabstrip.cs +++ b/main/src/core/MonoDevelop.Ide/MonoDevelop.Components/Tabstrip.cs @@ -75,7 +75,8 @@ namespace MonoDevelop.Components public Tabstrip () { Accessible.SetRole (AtkCocoa.Roles.AXTabGroup); - Events |= Gdk.EventMask.ButtonPressMask | Gdk.EventMask.PointerMotionMask | Gdk.EventMask.LeaveNotifyMask; + Events |= Gdk.EventMask.ButtonPressMask | Gdk.EventMask.PointerMotionMask | Gdk.EventMask.LeaveNotifyMask | Gdk.EventMask.FocusChangeMask; + CanFocus = true; } protected override void OnDestroyed () @@ -217,8 +218,73 @@ namespace MonoDevelop.Components tabs[ActiveTab].Draw (cr, GetBounds (tabs[ActiveTab])); } + return base.OnExposeEvent (evnt); } + + int focusedTab = -1; + protected override bool OnFocused (DirectionType direction) + { + bool ret = true; + int oldFocus = focusedTab; + + switch (direction) { + case DirectionType.TabForward: + case DirectionType.Right: + focusedTab++; + if (focusedTab >= tabs.Count) { + ret = false; + } + break; + + case DirectionType.TabBackward: + case DirectionType.Left: + if (focusedTab == -1) { + focusedTab = tabs.Count; + } + focusedTab--; + if (focusedTab < 0) { + ret = false; + } + break; + } + + if (ret) { + GrabFocus (); + if (oldFocus >= 0) { + tabs [oldFocus].Focused = false; + } + + tabs [focusedTab].Focused = true; + } else { + focusedTab = 0; + } + QueueDraw (); + + return ret; + } + + protected override bool OnFocusInEvent (Gdk.EventFocus evnt) + { + QueueDraw (); + return base.OnFocusInEvent (evnt); + } + + protected override bool OnFocusOutEvent (Gdk.EventFocus evnt) + { + if (focusedTab > -1) { + tabs [focusedTab].Focused = false; + focusedTab = -1; + } + QueueDraw (); + return base.OnFocusOutEvent (evnt); + } + + protected override void OnActivate () + { + ActiveTab = focusedTab; + base.OnActivate (); + } } public enum TabPosition { @@ -231,7 +297,7 @@ namespace MonoDevelop.Components internal static readonly int SpacerWidth = 8; const int Padding = 6; Pango.Layout layout; - //Tabstrip parent; + Tabstrip parent; int w, h; public string Label { @@ -268,6 +334,11 @@ namespace MonoDevelop.Components set; } + public bool Focused { + get; + set; + } + Cairo.Rectangle allocation; public Cairo.Rectangle Allocation { get { @@ -304,7 +375,7 @@ namespace MonoDevelop.Components public Tab (Tabstrip parent, string label, TabPosition tabPosition) { - //this.parent = parent; + this.parent = parent; this.Label = label; layout = PangoUtil.CreateLayout (parent); @@ -371,6 +442,18 @@ namespace MonoDevelop.Components cr.MoveTo (rectangle.X + (int)(rectangle.Width / 2), (rectangle.Height - h) / 2 - 1); Pango.CairoHelper.ShowLayout (cr, layout); + + if (parent.HasFocus && Focused) { + cr.LineWidth = 1.0; + cr.SetDash (new double[] { 1, 1 }, 0.5); + if (Active) { + cr.SetSourceColor (Styles.SubTabBarActiveTextColor.ToCairoColor ()); + } else { + cr.SetSourceColor (Styles.FocusColor.ToCairoColor ()); + } + cr.Rectangle (rectangle.X + 2, rectangle.Y + 2, rectangle.Width - 4, rectangle.Height - 4); + cr.Stroke (); + } } public override string ToString () |