| 641 | } |
| 642 | |
| 643 | int Element::GetCssPropertyValue(const std::string& property_name, |
| 644 | std::string* property_value) { |
| 645 | LOG(TRACE) << "Entering Element::GetCssPropertyValue"; |
| 646 | |
| 647 | int status_code = WD_SUCCESS; |
| 648 | CComPtr<IHTMLDocument2> doc; |
| 649 | this->GetContainingDocument(false, &doc); |
| 650 | if (this->IsXmlDocument(doc)) { |
| 651 | *property_value = ""; |
| 652 | return status_code; |
| 653 | } |
| 654 | |
| 655 | // The atom is just the definition of an anonymous |
| 656 | // function: "function() {...}"; Wrap it in another function so we can |
| 657 | // invoke it with our arguments without polluting the current namespace. |
| 658 | std::wstring script_source = L"(function() { return ("; |
| 659 | script_source += atoms::asString(atoms::GET_EFFECTIVE_STYLE); |
| 660 | script_source += L")})();"; |
| 661 | |
| 662 | Script script_wrapper(doc, script_source, 2); |
| 663 | script_wrapper.AddArgument(this->element_); |
| 664 | script_wrapper.AddArgument(property_name); |
| 665 | status_code = script_wrapper.Execute(); |
| 666 | |
| 667 | if (status_code == WD_SUCCESS) { |
| 668 | std::wstring raw_value = L""; |
| 669 | if (script_wrapper.ResultIsString()) { |
| 670 | raw_value.assign(script_wrapper.result().bstrVal); |
| 671 | } else if (script_wrapper.ResultIsInteger()) { |
| 672 | long int_value = script_wrapper.result().lVal; |
| 673 | raw_value = std::to_wstring(int_value); |
| 674 | } else if (script_wrapper.ResultIsDouble()) { |
| 675 | double dbl_value = script_wrapper.result().dblVal; |
| 676 | raw_value = std::to_wstring(dbl_value); |
| 677 | } else if (script_wrapper.ResultIsBoolean()) { |
| 678 | if (script_wrapper.result().boolVal == VARIANT_TRUE) { |
| 679 | raw_value = L"true"; |
| 680 | } else { |
| 681 | raw_value = L"false"; |
| 682 | } |
| 683 | } |
| 684 | std::string value = StringUtilities::ToString(raw_value); |
| 685 | std::transform(value.begin(), |
| 686 | value.end(), |
| 687 | value.begin(), |
| 688 | tolower); |
| 689 | *property_value = value; |
| 690 | } else { |
| 691 | LOG(WARN) << "Failed to get value of CSS property"; |
| 692 | } |
| 693 | return status_code; |
| 694 | } |
| 695 | |
| 696 | int Element::GetLocationOnceScrolledIntoView(const ElementScrollBehavior scroll, |
| 697 | LocationInfo* location, |
no test coverage detected