コード例 #1
0
ファイル: cefclient.cpp プロジェクト: amate/unChromium
 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
0
 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
0
ファイル: cefclient.cpp プロジェクト: amate/unChromium
    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
0
    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);
      }
    }