aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRichard Moe Gustavsen <richard.gustavsen@qt.io>2020-10-02 17:54:47 +0200
committerRichard Moe Gustavsen <richard.gustavsen@qt.io>2020-10-06 14:15:06 +0200
commitb68a83595d77d9967b5296858865c6a11d1022de (patch)
tree09cd36683a5260e2d6f1b14a7db5f718197d6915
parentd1b4b38046388d7823ec66e8875301dc70e0db0f (diff)
Native style, macOS: handle focus frame special case from c++
Move the expression that finds the correct target for TextArea from QML to C++. Keeping the code in QML simply became to messy when trying to also detect if a TextArea is inside a ScrollView. Change-Id: I3906dd37df73eaceffd60413d2378db7eab5f1bb Reviewed-by: Jan Arve Sæther <jan-arve.saether@qt.io>
-rw-r--r--src/imports/controls/macos/TextArea.qml8
-rw-r--r--src/imports/nativestyle/util/qquickmacfocusframe.mm23
2 files changed, 23 insertions, 8 deletions
diff --git a/src/imports/controls/macos/TextArea.qml b/src/imports/controls/macos/TextArea.qml
index 98884bda..38c8a7b7 100644
--- a/src/imports/controls/macos/TextArea.qml
+++ b/src/imports/controls/macos/TextArea.qml
@@ -40,13 +40,7 @@ import QtQuick.NativeStyle as NativeStyle
NativeStyle.DefaultTextArea {
id: control
- // If you place a TextArea inside a Frame or Flickable (/ScrollView), and
- // the TextArea is the only child of the content item, we place the focus
- // frame around the Flickable/Frame instead.
- readonly property Item __focusFrameTarget:
- (parent.parent instanceof Frame || parent.parent instanceof Flickable)
- && parent.children.length === 1
- ? parent.parent : control
+ readonly property Item __focusFrameTarget: control
background: Rectangle {
color: control.palette.light
diff --git a/src/imports/nativestyle/util/qquickmacfocusframe.mm b/src/imports/nativestyle/util/qquickmacfocusframe.mm
index 87d37366..7a30370c 100644
--- a/src/imports/nativestyle/util/qquickmacfocusframe.mm
+++ b/src/imports/nativestyle/util/qquickmacfocusframe.mm
@@ -125,7 +125,7 @@ QQuickFocusFrameDescription QQuickMacFocusFrame::getDescriptionForItem(QQuickIte
// editable ComboBox). In that case, resolve the actual control first.
const auto proxy = focusItem->property("__focusFrameControl").value<QQuickItem *>();
const auto control = proxy ? proxy : focusItem;
- const auto target = control->property("__focusFrameTarget").value<QQuickItem *>();
+ auto target = control->property("__focusFrameTarget").value<QQuickItem *>();
qCDebug(lcFocusFrame) << "target:" << target;
qCDebug(lcFocusFrame) << "control:" << control;
@@ -146,6 +146,27 @@ QQuickFocusFrameDescription QQuickMacFocusFrame::getDescriptionForItem(QQuickIte
return QQuickFocusFrameDescription::Invalid;
}
+ if (qobject_cast<QQuickTextArea *>(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<QQuickScrollView *>(parent3)) {
+ target = parent3;
+ qCDebug(lcFocusFrame) << "redirecting target to ScrollView:" << target;
+ } else if (qobject_cast<QQuickFlickable *>(parent2)) {
+ target = parent2;
+ qCDebug(lcFocusFrame) << "redirecting target to Flickable:" << target;
+ } else if (qobject_cast<QQuickFrame *>(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.