本文整理汇总了C++中CefRefPtr::GetElementById方法的典型用法代码示例。如果您正苦于以下问题:C++ CefRefPtr::GetElementById方法的具体用法?C++ CefRefPtr::GetElementById怎么用?C++ CefRefPtr::GetElementById使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类CefRefPtr
的用法示例。
在下文中一共展示了CefRefPtr::GetElementById方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: Visit
virtual void Visit(CefRefPtr<CefDOMDocument> document)
{
// Register an click listener for the button.
CefRefPtr<CefDOMNode> button = document->GetElementById("button");
ASSERT(button.get());
button->AddEventListener("click", new Listener(), false);
}
示例2: RegisterClickListener
void RegisterClickListener(CefRefPtr<CefDOMDocument> document,
CefRefPtr<CefDOMEventListener> listener,
const std::string& elementId)
{
CefRefPtr<CefDOMNode> element = document->GetElementById(elementId);
ASSERT(element.get());
element->AddEventListener("click", listener, false);
}
示例3: HandleEvent
virtual void HandleEvent(CefRefPtr<CefDOMEvent> event)
{
CefRefPtr<CefDOMDocument> document = event->GetDocument();
ASSERT(document.get());
std::stringstream ss;
CefRefPtr<CefDOMNode> button = event->GetTarget();
ASSERT(button.get());
std::string buttonValue = button->GetElementAttribute("value");
ss << "You clicked the " << buttonValue.c_str() << " button. ";
if (document->HasSelection()) {
std::string startName, endName;
// Determine the start name by first trying to locate the "id" attribute
// and then defaulting to the tag name.
{
CefRefPtr<CefDOMNode> node = document->GetSelectionStartNode();
if (!node->IsElement())
node = node->GetParent();
if (node->IsElement() && node->HasElementAttribute("id"))
startName = node->GetElementAttribute("id");
else
startName = node->GetName();
}
// Determine the end name by first trying to locate the "id" attribute
// and then defaulting to the tag name.
{
CefRefPtr<CefDOMNode> node = document->GetSelectionEndNode();
if (!node->IsElement())
node = node->GetParent();
if (node->IsElement() && node->HasElementAttribute("id"))
endName = node->GetElementAttribute("id");
else
endName = node->GetName();
}
ss << "The selection is from " <<
startName.c_str() << ":" << document->GetSelectionStartOffset() <<
" to " <<
endName.c_str() << ":" << document->GetSelectionEndOffset();
} else {
ss << "Nothing is selected.";
}
// Update the description.
CefRefPtr<CefDOMNode> desc = document->GetElementById("description");
ASSERT(desc.get());
CefRefPtr<CefDOMNode> text = desc->GetFirstChild();
ASSERT(text.get());
ASSERT(text->IsText());
text->SetValue(ss.str());
}
示例4: HandleEvent
virtual void HandleEvent(CefRefPtr<CefDOMEvent> event)
{
CefRefPtr<CefBrowser> browser = GetOffScreenBrowser();
CefRefPtr<CefDOMNode> element = event->GetTarget();
ASSERT(element.get());
std::string elementId = element->GetElementAttribute("id");
if (elementId == "back") {
browser->GoBack();
} else if(elementId == "forward") {
browser->GoForward();
} else if(elementId == "stop") {
browser->Reload();
} else if(elementId == "reload") {
browser->StopLoad();
} else if (elementId == "go") {
// Retrieve the value of the "url" field and load it in the off-screen
// browser window.
CefRefPtr<CefDOMDocument> document = event->GetDocument();
ASSERT(document.get());
CefRefPtr<CefDOMNode> url = document->GetElementById("url");
ASSERT(url.get());
CefString value = url->GetValue();
if (!value.empty())
browser->GetMainFrame()->LoadURL(value);
} else if(elementId == "testTransparency") {
// Transparency test.
browser->GetMainFrame()->LoadURL(
"http://tests/transparency");
} else if(elementId == "testWindowlessPlugin") {
// Load flash, which is a windowless plugin.
browser->GetMainFrame()->LoadURL(
"http://www.adobe.com/software/flash/about/");
} else if(elementId == "viewSource") {
// View the page source for the host browser window.
AppGetBrowser()->GetMainFrame()->ViewSource();
} else {
// Not reached.
ASSERT(false);
}
}