refactor Widget flip logic
add button flip test
finish tests
Merge pull request #9028 from andyque/fixWidgetFlipIssue

Fix widget flip issue