From 84d8bcd11756a0a076262295544c08765e267a51 Mon Sep 17 00:00:00 2001 From: Richard Moe Gustavsen Date: Mon, 16 Nov 2020 15:06:21 +0100 Subject: macOS: don't use a focus frame around TextArea MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit As it turns out, text areas in general should not show a focus frame. We don't do that for widgets, and AppKit doesn't do that for NSTextView. And for good reason, we don't want to show a big focus ring around the whole text edit in e.g a text editor application. Change-Id: Idc344c9f8d9f4a11dce22b2d2284800f05cd551a Reviewed-by: Jan Arve Sæther --- src/imports/controls/macos/TextArea.qml | 11 --------- .../nativestyle/util/qquickmacfocusframe.mm | 26 ++-------------------- 2 files changed, 2 insertions(+), 35 deletions(-) (limited to 'src') diff --git a/src/imports/controls/macos/TextArea.qml b/src/imports/controls/macos/TextArea.qml index 38c8a7b7..f6b88303 100644 --- a/src/imports/controls/macos/TextArea.qml +++ b/src/imports/controls/macos/TextArea.qml @@ -38,15 +38,4 @@ import QtQuick import QtQuick.NativeStyle as NativeStyle NativeStyle.DefaultTextArea { - id: control - - readonly property Item __focusFrameTarget: control - - background: Rectangle { - color: control.palette.light - // Since this delegate is a plain Rectangle, we need to tag it to know - // that it's still the default one, and not some custom item set by the - // application. Only in the former case do we wan't to show a focus frame. - readonly property bool __isDefaultDelegate: true - } } diff --git a/src/imports/nativestyle/util/qquickmacfocusframe.mm b/src/imports/nativestyle/util/qquickmacfocusframe.mm index 7a30370c..14b5de60 100644 --- a/src/imports/nativestyle/util/qquickmacfocusframe.mm +++ b/src/imports/nativestyle/util/qquickmacfocusframe.mm @@ -132,8 +132,7 @@ QQuickFocusFrameDescription QQuickMacFocusFrame::getDescriptionForItem(QQuickIte if (!target) { // __focusFrameTarget points to the item in the control that should // get the focus frame. This is usually the control itself, but can - // sometimes be a child (CheckBox), and other times a grand parent - // (a ScrollView that has a TextArea as child). We anyway require + // sometimes be a child (CheckBox). We anyway require // this property to be set if we are to show the focus frame around // the control in the first place. So for controls that don't want // a frame (ProgressBar), we simply skip setting it. @@ -146,27 +145,6 @@ QQuickFocusFrameDescription QQuickMacFocusFrame::getDescriptionForItem(QQuickIte return QQuickFocusFrameDescription::Invalid; } - if (qobject_cast(target)) { - // Special case: if the target is a TextArea, we check if it's the only - // child inside a ScrollArea, Flickable, or Frame. If that is the case, we - // redirect the focus frame to be around the container instead. - const auto parent1 = target->parentItem(); - if (parent1 && parent1->childItems().count() == 1) { - const auto parent2 = parent1->parentItem(); - const auto parent3 = parent2 ? parent2->parentItem() : nullptr; - if (qobject_cast(parent3)) { - target = parent3; - qCDebug(lcFocusFrame) << "redirecting target to ScrollView:" << target; - } else if (qobject_cast(parent2)) { - target = parent2; - qCDebug(lcFocusFrame) << "redirecting target to Flickable:" << target; - } else if (qobject_cast(parent2)) { - target = parent2; - qCDebug(lcFocusFrame) << "redirecting target to Frame:" << target; - } - } - } - // If the control gives us a QQuickStyleItem, we use that to configure the focus frame. // By default we assume that the background delegate is a QQuickStyleItem, but the // control can override this by setting __focusFrameStyleItem. @@ -182,7 +160,7 @@ QQuickFocusFrameDescription QQuickMacFocusFrame::getDescriptionForItem(QQuickIte if (QQuickStyleItem *styleItem = qobject_cast(item)) return { target, QQuickStyleMargins(styleItem->layoutMargins()), styleItem->focusFrameRadius() }; - // Some controls don't have a QQuickStyleItem (TextArea). But if the __focusFrameStyleItem + // Some controls don't have a QQuickStyleItem. But if the __focusFrameStyleItem // has a "__isDefaultDelegate" property set, we show a default focus frame instead. if (item->property("__isDefaultDelegate").toBool() == true) { qCDebug(lcFocusFrame) << "'__isDefaultDelegate' property found, showing a default focus frame"; -- cgit v1.2.3