Fix DOMTest failure related to device scaling
This commit is contained in:
parent
47dab09c5e
commit
bdfed81c70
|
@ -33,7 +33,7 @@
|
|||
// by hand. See the translator.README.txt file in the tools directory for
|
||||
// more information.
|
||||
//
|
||||
// $hash=c6de3fb4d64a2b2ad06a4b9c5e9d7625d40b5bb6$
|
||||
// $hash=ddff4ad975fc26d0abfe05799aedb597b8274ffd$
|
||||
//
|
||||
|
||||
#ifndef CEF_INCLUDE_CAPI_CEF_DOM_CAPI_H_
|
||||
|
@ -335,7 +335,8 @@ typedef struct _cef_domnode_t {
|
|||
struct _cef_domnode_t* self);
|
||||
|
||||
///
|
||||
// Returns the bounds of the element.
|
||||
// Returns the bounds of the element in device pixels. Use
|
||||
// "window.devicePixelRatio" to convert to/from CSS pixels.
|
||||
///
|
||||
cef_rect_t(CEF_CALLBACK* get_element_bounds)(struct _cef_domnode_t* self);
|
||||
} cef_domnode_t;
|
||||
|
|
|
@ -323,7 +323,8 @@ class CefDOMNode : public virtual CefBaseRefCounted {
|
|||
virtual CefString GetElementInnerText() = 0;
|
||||
|
||||
///
|
||||
// Returns the bounds of the element.
|
||||
// Returns the bounds of the element in device pixels. Use
|
||||
// "window.devicePixelRatio" to convert to/from CSS pixels.
|
||||
///
|
||||
/*--cef()--*/
|
||||
virtual CefRect GetElementBounds() = 0;
|
||||
|
|
|
@ -59,7 +59,8 @@ class TestDOMVisitor : public CefDOMVisitor {
|
|||
EXPECT_FALSE(textNode->HasChildren());
|
||||
}
|
||||
|
||||
void TestBodyNodeStructure(CefRefPtr<CefDOMNode> bodyNode) {
|
||||
void TestBodyNodeStructure(CefRefPtr<CefDOMNode> bodyNode,
|
||||
float devicePixelRatio) {
|
||||
EXPECT_TRUE(bodyNode.get());
|
||||
EXPECT_TRUE(bodyNode->IsElement());
|
||||
EXPECT_FALSE(bodyNode->IsText());
|
||||
|
@ -133,11 +134,14 @@ class TestDOMVisitor : public CefDOMVisitor {
|
|||
EXPECT_TRUE(divNode.get());
|
||||
EXPECT_TRUE(divNode->IsElement());
|
||||
EXPECT_FALSE(divNode->IsText());
|
||||
|
||||
// Returned bounds are in device pixels.
|
||||
CefRect divRect = divNode->GetElementBounds();
|
||||
EXPECT_EQ(divRect.width, 50);
|
||||
EXPECT_EQ(divRect.height, 25);
|
||||
EXPECT_EQ(divRect.x, 150);
|
||||
EXPECT_EQ(divRect.y, 100);
|
||||
EXPECT_EQ(divRect.width, 50.0 * devicePixelRatio);
|
||||
EXPECT_EQ(divRect.height, 25.0 * devicePixelRatio);
|
||||
EXPECT_EQ(divRect.x, 150.0 * devicePixelRatio);
|
||||
EXPECT_EQ(divRect.y, 100.0 * devicePixelRatio);
|
||||
|
||||
EXPECT_FALSE(divNode->GetNextSibling().get());
|
||||
}
|
||||
|
||||
|
@ -166,8 +170,10 @@ class TestDOMVisitor : public CefDOMVisitor {
|
|||
CefRefPtr<CefDOMNode> headNode = htmlNode->GetFirstChild();
|
||||
TestHeadNodeStructure(headNode);
|
||||
|
||||
const float devicePixelRatio = GetDevicePixelRatio();
|
||||
|
||||
CefRefPtr<CefDOMNode> bodyNode = headNode->GetNextSibling();
|
||||
TestBodyNodeStructure(bodyNode);
|
||||
TestBodyNodeStructure(bodyNode, devicePixelRatio);
|
||||
|
||||
// Retrieve the head node directly.
|
||||
headNode = document->GetHead();
|
||||
|
@ -175,7 +181,7 @@ class TestDOMVisitor : public CefDOMVisitor {
|
|||
|
||||
// Retrieve the body node directly.
|
||||
bodyNode = document->GetBody();
|
||||
TestBodyNodeStructure(bodyNode);
|
||||
TestBodyNodeStructure(bodyNode, devicePixelRatio);
|
||||
}
|
||||
|
||||
// Test document modification by changing the H1 tag.
|
||||
|
@ -226,6 +232,28 @@ class TestDOMVisitor : public CefDOMVisitor {
|
|||
browser_->GetMainFrame()->SendProcessMessage(PID_BROWSER, return_msg);
|
||||
}
|
||||
|
||||
// Used to convert between device pixels and CSS pixels.
|
||||
float GetDevicePixelRatio() {
|
||||
auto context = browser_->GetMainFrame()->GetV8Context();
|
||||
EXPECT_TRUE(context);
|
||||
|
||||
CefRefPtr<CefV8Value> retval;
|
||||
CefRefPtr<CefV8Exception> exception;
|
||||
EXPECT_TRUE(context->Eval("window.devicePixelRatio", CefString(), 0, retval,
|
||||
exception));
|
||||
if (exception) {
|
||||
ADD_FAILURE() << exception->GetMessage().c_str();
|
||||
return 1.0;
|
||||
}
|
||||
|
||||
if (retval->IsValid() && retval->IsDouble()) {
|
||||
return static_cast<float>(retval->GetDoubleValue());
|
||||
}
|
||||
|
||||
ADD_FAILURE() << "Failed to retrieve devicePixelRatio";
|
||||
return 1.0;
|
||||
}
|
||||
|
||||
CefRefPtr<CefBrowser> browser_;
|
||||
DOMTestType test_type_;
|
||||
|
||||
|
@ -263,6 +291,7 @@ class TestDOMHandler : public TestHandler {
|
|||
explicit TestDOMHandler(DOMTestType test) : test_type_(test) {}
|
||||
|
||||
void RunTest() override {
|
||||
// Specified values are in CSS pixels.
|
||||
std::stringstream mainHtml;
|
||||
mainHtml << "<html>"
|
||||
"<head><title>The Title</title></head>"
|
||||
|
|
Loading…
Reference in New Issue