Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Sign in
Toggle navigation
F
Front-End
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
abdullh.alsoleman
Front-End
Commits
715cb513
Unverified
Commit
715cb513
authored
Apr 15, 2019
by
Jonah Williams
Committed by
GitHub
Apr 15, 2019
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix bugs in contrast guideline and improve heuristic (#31000)
parent
301eaa8c
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
48 additions
and
22 deletions
+48
-22
accessibility_test.dart
examples/flutter_gallery/test/accessibility_test.dart
+1
-1
accessibility.dart
packages/flutter_test/lib/src/accessibility.dart
+20
-16
accessibility_test.dart
packages/flutter_test/test/accessibility_test.dart
+27
-5
No files found.
examples/flutter_gallery/test/accessibility_test.dart
View file @
715cb513
...
...
@@ -501,7 +501,7 @@ void main() {
await
tester
.
pumpWidget
(
MaterialApp
(
theme:
theme
,
home:
BottomAppBarDemo
()));
await
expectLater
(
tester
,
meetsGuideline
(
textContrastGuideline
));
handle
.
dispose
();
});
}
,
skip:
theme
==
ThemeData
.
light
()
);
testWidgets
(
'bottom_navigation_demo
$themeName
'
,
(
WidgetTester
tester
)
async
{
tester
.
binding
.
addTime
(
const
Duration
(
seconds:
3
));
...
...
packages/flutter_test/lib/src/accessibility.dart
View file @
715cb513
...
...
@@ -200,7 +200,7 @@ class MinimumTextContrastGuideline extends AccessibilityGuideline {
final
ByteData
byteData
=
await
tester
.
binding
.
runAsync
<
ByteData
>(()
async
{
// Needs to be the same pixel ratio otherwise our dimensions won't match the
// last transform layer.
image
=
await
layer
.
toImage
(
renderView
.
paintBounds
,
pixelRatio:
1
.0
);
image
=
await
layer
.
toImage
(
renderView
.
paintBounds
,
pixelRatio:
1
/
3
);
return
image
.
toByteData
();
});
...
...
@@ -214,10 +214,12 @@ class MinimumTextContrastGuideline extends AccessibilityGuideline {
children
.
add
(
child
);
return
true
;
});
for
(
SemanticsNode
child
in
children
)
for
(
SemanticsNode
child
in
children
)
{
result
+=
await
evaluateNode
(
child
);
if
(
_shouldSkipNode
(
data
))
}
if
(
_shouldSkipNode
(
data
))
{
return
result
;
}
// We need to look up the inherited text properties to determine the
// contrast ratio based on text size/weight.
...
...
@@ -225,14 +227,22 @@ class MinimumTextContrastGuideline extends AccessibilityGuideline {
bool
isBold
;
final
String
text
=
(
data
.
label
?.
isEmpty
==
true
)
?
data
.
value
:
data
.
label
;
final
List
<
Element
>
elements
=
find
.
text
(
text
).
hitTestable
().
evaluate
().
toList
();
Rect
paintBounds
;
if
(
elements
.
length
==
1
)
{
final
Element
element
=
elements
.
single
;
final
RenderBox
renderObject
=
element
.
renderObject
;
element
.
renderObject
.
paintBounds
;
paintBounds
=
Rect
.
fromPoints
(
renderObject
.
localToGlobal
(
element
.
renderObject
.
paintBounds
.
topLeft
-
const
Offset
(
4.0
,
4.0
)),
renderObject
.
localToGlobal
(
element
.
renderObject
.
paintBounds
.
bottomRight
+
const
Offset
(
4.0
,
4.0
)),
);
final
Widget
widget
=
element
.
widget
;
final
DefaultTextStyle
defaultTextStyle
=
DefaultTextStyle
.
of
(
element
);
if
(
widget
is
Text
)
{
TextStyle
effectiveTextStyle
=
widget
.
style
;
if
(
widget
.
style
==
null
||
widget
.
style
.
inherit
)
if
(
widget
.
style
==
null
||
widget
.
style
.
inherit
)
{
effectiveTextStyle
=
defaultTextStyle
.
style
.
merge
(
widget
.
style
);
}
fontSize
=
effectiveTextStyle
.
fontSize
;
isBold
=
effectiveTextStyle
.
fontWeight
==
FontWeight
.
bold
;
}
else
if
(
widget
is
EditableText
)
{
...
...
@@ -249,21 +259,14 @@ class MinimumTextContrastGuideline extends AccessibilityGuideline {
return
result
;
}
// Transform local coordinate to screen coordinates.
Rect
paintBounds
=
node
.
rect
;
SemanticsNode
current
=
node
;
while
(
current
!=
null
&&
current
.
parent
!=
null
)
{
if
(
current
.
transform
!=
null
)
paintBounds
=
MatrixUtils
.
transformRect
(
current
.
transform
,
paintBounds
);
paintBounds
=
paintBounds
.
shift
(
current
.
parent
?.
rect
?.
topLeft
??
Offset
.
zero
);
current
=
current
.
parent
;
}
if
(
_isNodeOffScreen
(
paintBounds
))
if
(
_isNodeOffScreen
(
paintBounds
))
{
return
result
;
}
final
List
<
int
>
subset
=
_subsetToRect
(
byteData
,
paintBounds
,
image
.
width
,
image
.
height
);
// Node was too far off screen.
if
(
subset
.
isEmpty
)
if
(
subset
.
isEmpty
)
{
return
result
;
}
final
_ContrastReport
report
=
_ContrastReport
(
subset
);
final
double
contrastRatio
=
report
.
contrastRatio
();
const
double
delta
=
-
0.01
;
...
...
@@ -342,8 +345,9 @@ class MinimumTextContrastGuideline extends AccessibilityGuideline {
class
_ContrastReport
{
factory
_ContrastReport
(
List
<
int
>
colors
)
{
final
Map
<
int
,
int
>
colorHistogram
=
<
int
,
int
>{};
for
(
int
color
in
colors
)
for
(
int
color
in
colors
)
{
colorHistogram
[
color
]
=
(
colorHistogram
[
color
]
??
0
)
+
1
;
}
if
(
colorHistogram
.
length
==
1
)
{
final
Color
hslColor
=
Color
(
colorHistogram
.
keys
.
first
);
return
_ContrastReport
.
_
(
hslColor
,
hslColor
);
...
...
packages/flutter_test/test/accessibility_test.dart
View file @
715cb513
...
...
@@ -92,13 +92,17 @@ void main() {
await
tester
.
pumpWidget
(
MaterialApp
(
home:
Scaffold
(
body:
Center
(
child:
TextField
(
controller:
TextEditingController
(
text:
'this is a test'
),
child:
SizedBox
(
width:
100
,
child:
TextField
(
controller:
TextEditingController
(
text:
'this is a test'
),
),
),
),
),
),
);
await
tester
.
idle
();
await
expectLater
(
tester
,
meetsGuideline
(
textContrastGuideline
));
handle
.
dispose
();
});
...
...
@@ -121,9 +125,9 @@ void main() {
expect
(
result
.
reason
,
'SemanticsNode#21(Rect.fromLTRB(300.0, 200.0, 500.0, 400.0), label: "this is a test",'
' textDirection: ltr):
\n
Expected contrast ratio of at least '
'4.5 but found
0.88 for a font size of 14.0.
'
'
The computed foreground color was: Color(0xffffeb3b),
'
'
The computed background color was: Color(0xffffff00
)
\n
'
'4.5 but found
1.17 for a font size of 14.0. The
'
'
computed foreground color was: Color(0xfffafafa), The computed background color was:
'
'
Color(0xffffeb3b
)
\n
'
'See also: https://www.w3.org/TR/UNDERSTANDING-WCAG20/visual-audio-contrast-contrast.html'
);
handle
.
dispose
();
});
...
...
@@ -418,6 +422,24 @@ void main() {
});
});
testWidgets
(
'regression test for material widget'
,
(
WidgetTester
tester
)
async
{
final
SemanticsHandle
handle
=
tester
.
ensureSemantics
();
await
tester
.
pumpWidget
(
MaterialApp
(
theme:
ThemeData
.
light
(),
home:
Scaffold
(
backgroundColor:
Colors
.
white
,
body:
RaisedButton
(
color:
const
Color
(
0xFFFBBC04
),
elevation:
0
,
onPressed:
()
{},
child:
const
Text
(
'Button'
,
style:
TextStyle
(
color:
Colors
.
black
)),
),
),
));
await
expectLater
(
tester
,
meetsGuideline
(
textContrastGuideline
));
handle
.
dispose
();
});
}
Widget
_boilerplate
(
Widget
child
)
{
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment