MCPcopy Create free account
hub / github.com/SeleniumHQ/selenium / GetZoomLevel

Method GetZoomLevel

cpp/iedriver/BrowserFactory.cpp:778–861  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

776}
777
778int BrowserFactory::GetZoomLevel(IHTMLDocument2* document, IHTMLWindow2* window) {
779 LOG(TRACE) << "Entering BrowserFactory::GetZoomLevel";
780 int zoom = 100; // Chances are the zoom level hasn't been modified....
781 HRESULT hr = S_OK;
782 if (this->ie_major_version_ == 7) {
783 CComPtr<IHTMLElement> body;
784 hr = document->get_body(&body);
785 if (FAILED(hr)) {
786 LOGHR(WARN, hr) << "Call to IHTMLDocument2::get_body failed";
787 return zoom;
788 }
789
790 long offset_width = 0;
791 hr = body->get_offsetWidth(&offset_width);
792 if (FAILED(hr)) {
793 LOGHR(WARN, hr) << "Call to IHTMLElement::get_offsetWidth failed";
794 return zoom;
795 }
796
797 CComPtr<IHTMLElement2> body2;
798 hr = body.QueryInterface<IHTMLElement2>(&body2);
799 if (FAILED(hr)) {
800 LOGHR(WARN, hr) << "Attempt to QueryInterface for IHTMLElement2 failed";
801 return zoom;
802 }
803
804 CComPtr<IHTMLRect> rect;
805 hr = body2->getBoundingClientRect(&rect);
806 if (FAILED(hr)) {
807 LOGHR(WARN, hr) << "Call to IHTMLElement2::getBoundingClientRect failed";
808 return zoom;
809 }
810
811 long left = 0, right = 0;
812 hr = rect->get_left(&left);
813 if (FAILED(hr)) {
814 LOGHR(WARN, hr) << "Call to IHTMLRect::get_left failed";
815 return zoom;
816 }
817
818 hr = rect->get_right(&right);
819 if (FAILED(hr)) {
820 LOGHR(WARN, hr) << "Call to IHTMLRect::get_right failed";
821 return zoom;
822 }
823
824 zoom = static_cast<int>((static_cast<double>(right - left) / offset_width) * 100.0);
825 } else if (this->ie_major_version_ >= 8) {
826 CComPtr<IHTMLScreen> screen;
827 hr = window->get_screen(&screen);
828 if (FAILED(hr)) {
829 LOGHR(WARN, hr) << "Call to IHTMLWindow2::get_screen failed";
830 return zoom;
831 }
832
833 CComPtr<IHTMLScreen2> screen2;
834 hr = screen.QueryInterface<IHTMLScreen2>(&screen2);
835 if (FAILED(hr)) {

Callers 1

GetBrowserZoomLevelMethod · 0.95

Calls 1

LOGClass · 0.50

Tested by

no test coverage detected