Unverified Commit 0377e80d authored by Tomasz Gucio's avatar Tomasz Gucio Committed by GitHub

Size CupertinoTextSelectionToolbar to children (#133386)

parent 85e52d43
......@@ -6837,7 +6837,7 @@ void main() {
includes: <Offset> [
// Expected center of the arrow. The arrow should stay clear of
// the edges of the selection toolbar.
Offset(26.0, bottomLeftSelectionPosition.dy + 7.0 + 8.0 + 0.1),
Offset(26.0, bottomLeftSelectionPosition.dy + 8.0 + 0.1),
],
),
),
......@@ -6847,10 +6847,10 @@ void main() {
find.byType(CupertinoTextSelectionToolbar),
paints..clipPath(
pathMatcher: PathBoundsMatcher(
topMatcher: moreOrLessEquals(bottomLeftSelectionPosition.dy + 7 + 8, epsilon: 0.01),
topMatcher: moreOrLessEquals(bottomLeftSelectionPosition.dy + 8, epsilon: 0.01),
leftMatcher: moreOrLessEquals(8),
rightMatcher: lessThanOrEqualTo(400 - 8),
bottomMatcher: moreOrLessEquals(bottomLeftSelectionPosition.dy + 8 + 45, epsilon: 0.01),
bottomMatcher: moreOrLessEquals(bottomLeftSelectionPosition.dy + 8 + 44, epsilon: 0.01),
),
),
);
......@@ -6898,7 +6898,7 @@ void main() {
],
includes: <Offset> [
// Expected center of the arrow.
Offset(400 - 26.0, bottomLeftSelectionPosition.dy + 7 + 8 + 0.1),
Offset(400 - 26.0, bottomLeftSelectionPosition.dy + 8 + 0.1),
],
),
),
......@@ -6908,9 +6908,9 @@ void main() {
find.byType(CupertinoTextSelectionToolbar),
paints..clipPath(
pathMatcher: PathBoundsMatcher(
topMatcher: moreOrLessEquals(bottomLeftSelectionPosition.dy + 7 + 8, epsilon: 0.01),
topMatcher: moreOrLessEquals(bottomLeftSelectionPosition.dy + 8, epsilon: 0.01),
rightMatcher: moreOrLessEquals(400.0 - 8),
bottomMatcher: moreOrLessEquals(bottomLeftSelectionPosition.dy + 8 + 45, epsilon: 0.01),
bottomMatcher: moreOrLessEquals(bottomLeftSelectionPosition.dy + 8 + 44, epsilon: 0.01),
leftMatcher: greaterThanOrEqualTo(8),
),
),
......@@ -6963,7 +6963,7 @@ void main() {
paints..clipPath(
pathMatcher: PathBoundsMatcher(
bottomMatcher: moreOrLessEquals(bottomLeftSelectionPosition.dy - 8 - lineHeight, epsilon: 0.01),
topMatcher: moreOrLessEquals(bottomLeftSelectionPosition.dy - 8 - lineHeight - 45, epsilon: 0.01),
topMatcher: moreOrLessEquals(bottomLeftSelectionPosition.dy - 8 - lineHeight - 44, epsilon: 0.01),
rightMatcher: lessThanOrEqualTo(400 - 8),
leftMatcher: greaterThanOrEqualTo(8),
),
......@@ -7032,7 +7032,7 @@ void main() {
paints..clipPath(
pathMatcher: PathBoundsMatcher(
bottomMatcher: moreOrLessEquals(selectionPosition.dy - 8 - lineHeight, epsilon: 0.01),
topMatcher: moreOrLessEquals(selectionPosition.dy - 8 - lineHeight - 45, epsilon: 0.01),
topMatcher: moreOrLessEquals(selectionPosition.dy - 8 - lineHeight - 44, epsilon: 0.01),
rightMatcher: lessThanOrEqualTo(400 - 8),
leftMatcher: greaterThanOrEqualTo(8),
),
......@@ -7105,7 +7105,7 @@ void main() {
paints..clipPath(
pathMatcher: PathBoundsMatcher(
bottomMatcher: moreOrLessEquals(selectionPosition.dy - 8 - lineHeight, epsilon: 0.01),
topMatcher: moreOrLessEquals(selectionPosition.dy - 8 - lineHeight - 45, epsilon: 0.01),
topMatcher: moreOrLessEquals(selectionPosition.dy - 8 - lineHeight - 44, epsilon: 0.01),
rightMatcher: lessThanOrEqualTo(400 - 8),
leftMatcher: greaterThanOrEqualTo(8),
),
......
......@@ -671,8 +671,8 @@ void main() {
final Offset textFieldOffset =
tester.getTopLeft(find.byType(CupertinoTextField));
// 7.0 + 45.0 + 8.0 - 8.0 = _kToolbarArrowSize + _kToolbarHeight + _kToolbarContentDistance - padding
expect(selectionOffset.dy + 7.0 + 45.0 + 8.0 - 8.0, equals(textFieldOffset.dy));
// 7.0 + 44.0 + 8.0 - 8.0 = _kToolbarArrowSize + text_button_height + _kToolbarContentDistance - padding
expect(selectionOffset.dy + 7.0 + 44.0 + 8.0 - 8.0, equals(textFieldOffset.dy));
},
skip: isBrowser, // [intended] the selection menu isn't required by web
variant: const TargetPlatformVariant(<TargetPlatform>{ TargetPlatform.iOS }),
......
......@@ -12,7 +12,7 @@ import '../widgets/editable_text_utils.dart' show textOffsetToPosition;
// These constants are copied from cupertino/text_selection_toolbar.dart.
const double _kArrowScreenPadding = 26.0;
const double _kToolbarContentDistance = 8.0;
const double _kToolbarHeight = 45.0;
const Size _kToolbarArrowSize = Size(14.0, 7.0);
// A custom text selection menu that just displays a single custom button.
class _CustomCupertinoTextSelectionControls extends CupertinoTextSelectionControls {
......@@ -271,7 +271,7 @@ void main() {
testWidgetsWithLeakTracking('positions itself at anchorAbove if it fits', (WidgetTester tester) async {
late StateSetter setState;
const double height = _kToolbarHeight;
const double height = 50.0;
const double anchorBelowY = 500.0;
double anchorAboveY = 0.0;
const double paddingAbove = 12.0;
......@@ -332,7 +332,7 @@ void main() {
});
await tester.pump();
toolbarY = tester.getTopLeft(findToolbar()).dy;
expect(toolbarY, equals(anchorAboveY - height - _kToolbarContentDistance));
expect(toolbarY, equals(anchorAboveY - height + _kToolbarArrowSize.height - _kToolbarContentDistance));
}, skip: kIsWeb); // [intended] We do not use Flutter-rendered context menu on the Web.
testWidgetsWithLeakTracking('can create and use a custom toolbar', (WidgetTester tester) async {
......@@ -429,7 +429,7 @@ void main() {
testWidgetsWithLeakTracking('draws a shadow below the toolbar in light mode', (WidgetTester tester) async {
late StateSetter setState;
const double height = _kToolbarHeight;
const double height = 50.0;
double anchorAboveY = 0.0;
await tester.pumpWidget(
......@@ -468,20 +468,15 @@ void main() {
),
);
// When the toolbar is below the content, the shadow hangs below the entire
// toolbar.
final Finder finder = find.descendant(
of: find.byType(CupertinoTextSelectionToolbar),
matching: find.byType(DecoratedBox),
final double dividerWidth = 1.0 / tester.view.devicePixelRatio;
expect(
find.byType(CupertinoTextSelectionToolbar),
paints..rrect(
rrect: RRect.fromLTRBR(8.0, 515.0, 158.0 + 2 * dividerWidth, 558.0, const Radius.circular(8.0)),
color: const Color(0x33000000),
),
);
expect(finder, findsOneWidget);
DecoratedBox decoratedBox = tester.widget(finder.first);
BoxDecoration boxDecoration = decoratedBox.decoration as BoxDecoration;
List<BoxShadow>? shadows = boxDecoration.boxShadow;
expect(shadows, isNotNull);
expect(shadows, hasLength(1));
BoxShadow shadow = boxDecoration.boxShadow!.first;
expect(shadow.offset.dy, equals(7.0));
// When the toolbar is above the content, the shadow sits around the arrow
// with no offset.
......@@ -489,12 +484,13 @@ void main() {
anchorAboveY = 80.0;
});
await tester.pump();
decoratedBox = tester.widget(finder.first);
boxDecoration = decoratedBox.decoration as BoxDecoration;
shadows = boxDecoration.boxShadow;
expect(shadows, isNotNull);
expect(shadows, hasLength(1));
shadow = boxDecoration.boxShadow!.first;
expect(shadow.offset.dy, equals(0.0));
expect(
find.byType(CupertinoTextSelectionToolbar),
paints..rrect(
rrect: RRect.fromLTRBR(8.0, 29.0, 158.0 + 2 * dividerWidth, 72.0, const Radius.circular(8.0)),
color: const Color(0x33000000),
),
);
}, skip: kIsWeb); // [intended] We do not use Flutter-rendered context menu on the Web.
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment