| 532 | } |
| 533 | |
| 534 | void StyleSheetSpecification::registerDefaultNodeSelectors() { |
| 535 | mNodeSelectors["empty"] = []( const UIWidget* node, int, int, const FunctionString& ) -> bool { |
| 536 | return node->getFirstChild() == NULL; |
| 537 | }; |
| 538 | mNodeSelectors["first-child"] = []( const UIWidget* node, int, int, |
| 539 | const FunctionString& ) -> bool { |
| 540 | return NULL != node->getParent() && node->getParent()->getFirstChild() == node; |
| 541 | }; |
| 542 | mNodeSelectors["enabled"] = []( const UIWidget* node, int, int, |
| 543 | const FunctionString& ) -> bool { return node->isEnabled(); }; |
| 544 | mNodeSelectors["disabled"] = []( const UIWidget* node, int, int, |
| 545 | const FunctionString& ) -> bool { return !node->isEnabled(); }; |
| 546 | mNodeSelectors["first-of-type"] = []( const UIWidget* node, int, int, |
| 547 | const FunctionString& ) -> bool { |
| 548 | Node* child = NULL != node->getParent() ? node->getParent()->getFirstChild() : NULL; |
| 549 | Uint32 type = node->getType(); |
| 550 | while ( NULL != child ) { |
| 551 | if ( type == child->getType() ) { |
| 552 | return child == node; |
| 553 | } |
| 554 | child = child->getNextNode(); |
| 555 | }; |
| 556 | return false; |
| 557 | }; |
| 558 | mNodeSelectors["last-child"] = []( const UIWidget* node, int, int, |
| 559 | const FunctionString& ) -> bool { |
| 560 | return NULL != node->getParent() && node->getParent()->getLastChild() == node; |
| 561 | }; |
| 562 | mNodeSelectors["last-of-type"] = []( const UIWidget* node, int, int, |
| 563 | const FunctionString& ) -> bool { |
| 564 | Node* child = NULL != node->getParent() ? node->getParent()->getLastChild() : NULL; |
| 565 | Uint32 type = node->getType(); |
| 566 | while ( NULL != child ) { |
| 567 | if ( type == child->getType() ) { |
| 568 | return child == node; |
| 569 | } |
| 570 | child = child->getPrevNode(); |
| 571 | }; |
| 572 | return false; |
| 573 | }; |
| 574 | mNodeSelectors["only-child"] = []( const UIWidget* node, int, int, |
| 575 | const FunctionString& ) -> bool { |
| 576 | return NULL != node->getParent() && node->getParent()->getChildCount() == 1; |
| 577 | }; |
| 578 | mNodeSelectors["only-of-type"] = []( const UIWidget* node, int, int, |
| 579 | const FunctionString& ) -> bool { |
| 580 | Node* child = NULL != node->getParent() ? node->getParent()->getFirstChild() : NULL; |
| 581 | Uint32 type = node->getType(); |
| 582 | Uint32 typeCount = 0; |
| 583 | while ( NULL != child ) { |
| 584 | if ( child->getType() == type ) { |
| 585 | typeCount++; |
| 586 | } |
| 587 | if ( typeCount > 1 ) |
| 588 | return false; |
| 589 | child = child->getNextNode(); |
| 590 | }; |
| 591 | return typeCount == 1; |
nothing calls this directly
no test coverage detected