Mac: Bring back "Text boxes and list only" tab navigation
authorGabriel de Dietrich <gabriel.dietrich-de@nokia.com>
Tue, 9 Oct 2012 09:27:01 +0000 (11:27 +0200)
committerThe Qt Project <gerrit-noreply@qt-project.org>
Wed, 10 Oct 2012 11:15:57 +0000 (13:15 +0200)
Added ThemeHint::TabAllWidgets as a mean to access that platform
specific bool. The default implementation returns always true when
querying QPlatformTheme::themeHint().

Several auto-tests had to be updated to reflect for qt_tab_all_widgets'
type change. One XFAIL removed from tst_QApplication::focusChanged().

Task-number: QTBUG-24372
Change-Id: Ie1f0486c19898fe54c53aa4a27e378485075e512
Reviewed-by: Morten Johan Sørvig <morten.sorvig@digia.com>
src/gui/kernel/qplatformtheme.cpp
src/gui/kernel/qplatformtheme.h
src/plugins/platforms/cocoa/qcocoatheme.mm
src/widgets/graphicsview/qgraphicsproxywidget.cpp
src/widgets/kernel/qapplication.cpp
src/widgets/widgets/qabstractbutton.cpp
tests/auto/widgets/itemviews/qtableview/tst_qtableview.cpp
tests/auto/widgets/kernel/qapplication/tst_qapplication.cpp
tests/auto/widgets/widgets/qbuttongroup/tst_qbuttongroup.cpp
tests/auto/widgets/widgets/qmdisubwindow/tst_qmdisubwindow.cpp
tests/auto/widgets/widgets/qmenu/tst_qmenu.cpp

index c35b534..b91d3d0 100644 (file)
@@ -129,6 +129,9 @@ QT_BEGIN_NAMESPACE
     \value SpellCheckUnderlineStyle (int) A QTextCharFormat::UnderlineStyle specifying
                                     the underline style used misspelled words when spell checking.
 
+    \value TabAllWidgets (bool) Whether tab navigation should go through all the widgets or components,
+                         or just through text boxes and list views. This is mostly a Mac feature.
+
     \sa themeHint(), QStyle::pixelMetric()
 */
 
@@ -218,6 +221,8 @@ QVariant QPlatformTheme::defaultThemeHint(ThemeHint hint)
         return QVariant(int(0));
     case SpellCheckUnderlineStyle:
         return QVariant(int(QTextCharFormat::SpellCheckUnderline));
+    case TabAllWidgets:
+        return QVariant(true);
     }
     return QVariant();
 }
index 417b4ed..3983392 100644 (file)
@@ -96,7 +96,8 @@ public:
         UseFullScreenForPopupMenu,
         KeyboardScheme,
         UiEffects,
-        SpellCheckUnderlineStyle
+        SpellCheckUnderlineStyle,
+        TabAllWidgets
     };
 
     enum DialogType {
index 3e2515d..ddb550d 100644 (file)
@@ -39,6 +39,8 @@
 **
 ****************************************************************************/
 
+#import <Cocoa/Cocoa.h>
+
 #include "qcocoatheme.h"
 
 #include <QtCore/QVariant>
@@ -142,6 +144,8 @@ QVariant QCocoaTheme::themeHint(ThemeHint hint) const
         return QVariant(1); // QDialogButtonBox::MacLayout
     case KeyboardScheme:
         return QVariant(int(MacKeyboardScheme));
+    case TabAllWidgets:
+        return QVariant(bool([[NSApplication sharedApplication] isFullKeyboardAccessEnabled]));
     default:
         break;
     }
index a0b3f99..6dd03e7 100644 (file)
@@ -190,7 +190,7 @@ QT_BEGIN_NAMESPACE
 */
 
 extern bool qt_sendSpontaneousEvent(QObject *, QEvent *);
-Q_WIDGETS_EXPORT extern bool qt_tab_all_widgets;
+Q_WIDGETS_EXPORT extern bool qt_tab_all_widgets();
 
 /*!
     \internal
@@ -357,7 +357,7 @@ QWidget *QGraphicsProxyWidgetPrivate::findFocusChild(QWidget *child, bool next)
     }
 
     QWidget *oldChild = child;
-    uint focus_flag = qt_tab_all_widgets ? Qt::TabFocus : Qt::StrongFocus;
+    uint focus_flag = qt_tab_all_widgets() ? Qt::TabFocus : Qt::StrongFocus;
     do {
         if (child->isEnabled()
            && child->isVisibleTo(widget)
index 68d7ee3..86a27b2 100644 (file)
@@ -397,7 +397,6 @@ QWidget *QApplicationPrivate::active_window = 0;        // toplevel with keyboar
 #ifndef QT_NO_WHEELEVENT
 int QApplicationPrivate::wheel_scroll_lines;   // number of lines to scroll
 #endif
-bool Q_WIDGETS_EXPORT qt_tab_all_widgets = true;
 bool qt_in_tab_key_event = false;
 int qt_antialiasing_threshold = -1;
 QSize QApplicationPrivate::app_strut = QSize(0,0); // no default application strut
@@ -416,6 +415,13 @@ inline bool QApplicationPrivate::isAlien(QWidget *widget)
     return widget && !widget->isWindow();
 }
 
+bool Q_WIDGETS_EXPORT qt_tab_all_widgets()
+{
+    if (const QPlatformTheme *theme = QGuiApplicationPrivate::platformTheme())
+        return theme->themeHint(QPlatformTheme::TabAllWidgets).toBool();
+    return true;
+}
+
 // ######## move to QApplicationPrivate
 // Default application palettes and fonts (per widget type)
 Q_GLOBAL_STATIC(PaletteHash, app_palettes)
@@ -2080,7 +2086,7 @@ void QApplication::setActiveWindow(QWidget* act)
 */
 QWidget *QApplicationPrivate::focusNextPrevChild_helper(QWidget *toplevel, bool next)
 {
-    uint focus_flag = qt_tab_all_widgets ? Qt::TabFocus : Qt::StrongFocus;
+    uint focus_flag = qt_tab_all_widgets() ? Qt::TabFocus : Qt::StrongFocus;
 
     QWidget *f = toplevel->focusWidget();
     if (!f)
index 451a7d3..5d879c8 100644 (file)
@@ -57,7 +57,7 @@ QT_BEGIN_NAMESPACE
 #define AUTO_REPEAT_DELAY  300
 #define AUTO_REPEAT_INTERVAL 100
 
-Q_WIDGETS_EXPORT extern bool qt_tab_all_widgets;
+Q_WIDGETS_EXPORT extern bool qt_tab_all_widgets();
 
 /*!
     \class QAbstractButton
@@ -385,7 +385,7 @@ void QAbstractButtonPrivate::moveFocus(int key)
     int bestScore = -1;
     QRect target = f->rect().translated(f->mapToGlobal(QPoint(0,0)));
     QPoint goal = target.center();
-    uint focus_flag = qt_tab_all_widgets ? Qt::TabFocus : Qt::StrongFocus;
+    uint focus_flag = qt_tab_all_widgets() ? Qt::TabFocus : Qt::StrongFocus;
 
     for (int i = 0; i < buttonList.count(); ++i) {
         QAbstractButton *button = buttonList.at(i);
index 259b060..dc4171e 100644 (file)
@@ -3331,12 +3331,12 @@ void tst_QTableView::resizeToContents()
 }
 
 QT_BEGIN_NAMESPACE
-extern bool Q_GUI_EXPORT qt_tab_all_widgets; // qapplication.cpp
+extern bool Q_GUI_EXPORT qt_tab_all_widgets(); // qapplication.cpp
 QT_END_NAMESPACE
 
 void tst_QTableView::tabFocus()
 {
-    if (!qt_tab_all_widgets)
+    if (!qt_tab_all_widgets())
         QSKIP("This test requires full keyboard control to be enabled.");
 
     // QTableView enables tabKeyNavigation by default, but you should be able
index 2a3a3a1..9ea8589 100644 (file)
@@ -100,7 +100,7 @@ static QList<struct QWindowSystemInterface::TouchPoint> touchPointList(const QLi
 
 
 
-extern bool Q_GUI_EXPORT qt_tab_all_widgets; // from qapplication.cpp
+extern bool Q_GUI_EXPORT qt_tab_all_widgets(); // from qapplication.cpp
 QT_END_NAMESPACE
 
 class tst_QApplication : public QObject
@@ -1597,14 +1597,10 @@ void tst_QApplication::focusChanged()
     QSettings appleSettings(QLatin1String("apple.com"));
     QVariant appleValue = appleSettings.value(QLatin1String("AppleKeyboardUIMode"), 0);
     tabAllControls = (appleValue.toInt() & 0x2);
-    if (!tabAllControls) {
-        QEXPECT_FAIL("", "QTBUG-24372 Mac tab key \"Text boxes and lists only\" vs "
-                         "\"All controls\" setting is not respected in Qt5", Abort);
-    }
 #endif
 
     // make sure Qt's idea of tabbing between widgets matches what we think it should
-    QCOMPARE(qt_tab_all_widgets, tabAllControls);
+    QCOMPARE(qt_tab_all_widgets(), tabAllControls);
 
     tab.simulate(now);
     if (!tabAllControls) {
index 3e0cc42..5c1de27 100644 (file)
@@ -121,13 +121,13 @@ void tst_QButtonGroup::cleanup()
 }
 
 QT_BEGIN_NAMESPACE
-extern bool Q_GUI_EXPORT qt_tab_all_widgets;
+extern bool Q_GUI_EXPORT qt_tab_all_widgets();
 QT_END_NAMESPACE
 
 
 void tst_QButtonGroup::arrowKeyNavigation()
 {
-    if (!qt_tab_all_widgets)
+    if (!qt_tab_all_widgets())
         QSKIP("This test requires full keyboard control to be enabled.");
 
     QDialog dlg(0);
index 77a3dd5..589f157 100644 (file)
@@ -65,7 +65,7 @@
 
 QT_BEGIN_NAMESPACE
 #if !defined(Q_WS_WIN)
-extern bool qt_tab_all_widgets;
+extern bool qt_tab_all_widgets();
 #endif
 QT_END_NAMESPACE
 
@@ -73,7 +73,7 @@ static inline bool tabAllWidgets()
 {
 #if !defined(Q_OS_WIN)
     if (qApp->style()->inherits("QMacStyle"))
-        return qt_tab_all_widgets;
+        return qt_tab_all_widgets();
 #endif
     return true;
 }
index bcd7f4f..b159d0e 100644 (file)
@@ -366,7 +366,7 @@ void tst_QMenu::keyboardNavigation()
 
 #ifdef Q_OS_MAC
 QT_BEGIN_NAMESPACE
-    extern bool qt_tab_all_widgets; // from qapplication.cpp
+extern bool qt_tab_all_widgets(); // from qapplication.cpp
 QT_END_NAMESPACE
 #endif
 
@@ -378,7 +378,7 @@ void tst_QMenu::focus()
     menu.addAction("Three");
 
 #ifdef Q_OS_MAC
-    if (!qt_tab_all_widgets)
+    if (!qt_tab_all_widgets())
         QSKIP("Computer is currently set up to NOT tab to all widgets,"
              " this test assumes you can tab to all widgets");
 #endif