Exemple #1
0
/* Updates the viewNode approximating the current focusNode */
void zoom(int level) {
  while (level < 0) {
    if (viewNode -> parent) { 
      unmapNode(viewNode);
      viewNode = viewNode -> parent;
    } else { return; }
    placeNode(viewNode, rootX, rootY, rootWidth, rootHeight);
    focusNode(focusedNode, NULL, True, True);
    level++;
  }
  while (level > 0) {
    if (focusedNode == viewNode) return;
    Node *n = focusedNode;
    while (n && n -> parent != viewNode) n = n -> parent;
    if (!n) return;

    unmapNode(viewNode);
    viewNode = n;
    //TODO:: Need placeNode to be aware of focusnnode (in)active colors....
    
    fprintf(stderr, "placeing yo");
    placeNode(viewNode, rootX, rootY, rootWidth, rootHeight);
    if (focusedNode == viewNode && !isClient(focusedNode)) {
      focusNode(focusOrChildOf(focusedNode), NULL, True, True);
    }
    level--;
  }
}
Exemple #2
0
Range* DOMSelection::getRangeAt(int index, ExceptionState& exceptionState) {
    if (!isAvailable())
        return nullptr;

    if (index < 0 || index >= rangeCount()) {
        exceptionState.throwDOMException(
            IndexSizeError, String::number(index) + " is not a valid index.");
        return nullptr;
    }

    // If you're hitting this, you've added broken multi-range selection support
    DCHECK_EQ(rangeCount(), 1);

    Position anchor = anchorPosition(visibleSelection());
    if (!anchor.anchorNode()->isInShadowTree())
        return frame()->selection().firstRange();

    Node* node = shadowAdjustedNode(anchor);
    if (!node)  // crbug.com/595100
        return nullptr;
    if (!visibleSelection().isBaseFirst())
        return Range::create(*anchor.document(), focusNode(), focusOffset(), node,
                             anchorOffset());
    return Range::create(*anchor.document(), node, anchorOffset(), focusNode(),
                         focusOffset());
}
void InteractionHandler::updateCamera() {
    ghoul_assert(_inputState != nullptr, "InputState cannot be null!");
    ghoul_assert(_camera != nullptr, "Camera cannot be null!");

    if (_cameraUpdatedFromScript) {
        _cameraUpdatedFromScript = false;
    }
    else {
        if (_camera && focusNode()) {
            _currentInteractionMode->updateCameraStateFromMouseStates(*_camera);
            _camera->setFocusPositionVec3(focusNode()->worldPosition());
        }
    }
}
void InteractionHandler::resetCameraDirection() {
    LINFO("Setting camera direction to point at focus node.");

    glm::dquat rotation = _camera->rotationQuaternion();
    glm::dvec3 focusPosition = focusNode()->worldPosition();
    glm::dvec3 cameraPosition = _camera->positionVec3();
    glm::dvec3 lookUpVector = _camera->lookUpVectorWorldSpace();

    glm::dvec3 directionToFocusNode = glm::normalize(focusPosition - cameraPosition);

    // To make sure the lookAt function won't fail
    static const double epsilon = 0.000001;
    if (glm::dot(lookUpVector, directionToFocusNode) > 1.0 - epsilon) {
        // Change the look up vector a little bit
        lookUpVector = glm::normalize(lookUpVector + glm::dvec3(epsilon));
    }

    // Create the rotation to look at  focus node
    glm::dmat4 lookAtMat = glm::lookAt(
        glm::dvec3(0, 0, 0),
        directionToFocusNode,
        lookUpVector);
    glm::dquat rotationLookAtFocusNode = normalize(quat_cast(inverse(lookAtMat)));

    // Update camera Rotation
    _camera->setRotation(rotationLookAtFocusNode);
}
void InspectorController::inspect(Node* node)
{
    if (!node || !enabled())
        return;

    if (!m_page) {
        m_page = m_client->createPage();
        if (!m_page)
            return;

        m_page->setParentInspectorController(this);
    }

    if (node->nodeType() != Node::ELEMENT_NODE && node->nodeType() != Node::DOCUMENT_NODE)
        node = node->parentNode();
    m_nodeToFocus = node;

    if (!m_scriptObject)
        return;

    if (windowVisible())
        focusNode();
    else
        m_client->showWindow();
}
Exemple #6
0
//Moves the current selection given amount
void shift(char * argA, int delta) {

  int brotherSwitch = -1;
  if (!strcmp(argA, "brother")) brotherSwitch = 1;
  else if (!strcmp(argA, "pc")) brotherSwitch = 0;
  else return;

  while (delta != 0) {
    if (brotherSwitch) {
      Node *swapNode = getBrother(focusedNode, delta);
      swapNodes(focusedNode, swapNode);
      focusNode(focusedNode, NULL, True, True);
      delta = 0;
    } else {
      if (delta > 0) { return; } else {
        if (focusedNode -> parent && focusedNode -> parent -> parent) {
          Node *newParent = focusedNode -> parent -> parent;
          parentNode(focusedNode, newParent);
          rePlaceNode(newParent);
        } else { return; }
        delta++;
      }
    }
  }

}
void InteractionHandler::saveCameraStateToFile(const std::string& filepath) {
    if (!filepath.empty()) {
        auto fullpath = absPath(filepath);
        LINFO("Saving camera position: " << filepath);

        ghoul::Dictionary cameraDict = getCameraStateDictionary();

        // TODO : Should get the camera state as a dictionary and save the dictionary to
        // a file in form of a lua state and not use ofstreams here.
        
        std::ofstream ofs(fullpath.c_str());
        
        glm::dvec3 p = _camera->positionVec3();
        glm::dquat q = _camera->rotationQuaternion();

        ofs << "return {" << std::endl;
        ofs << "    " << KeyFocus << " = " << "\"" << focusNode()->name() << "\"" << "," << std::endl;
        ofs << "    " << KeyPosition << " = {"
            << std::to_string(p.x) << ", "
            << std::to_string(p.y) << ", "
            << std::to_string(p.z) << "}," << std::endl;
        ofs << "    " << KeyRotation << " = {"
            << std::to_string(q.w) << ", "
            << std::to_string(q.x) << ", "
            << std::to_string(q.y) << ", "
            << std::to_string(q.z) << "}," << std::endl;
        ofs << "}"<< std::endl;

        ofs.close();
    }
}
Exemple #8
0
void eButtonPress(XEvent *event) {
  fprintf(stderr, "Button Event Window is %p\n", &(event -> xbutton.window));

  // Root Window
  if (event -> xbutton.window == None) return;

  // Click to Focus
  focusNode(getNodeByWindow(&(event -> xbutton.window)), event, True, True);
}
Exemple #9
0
void focus(char * argA, char * argB) {
  if (!focusedNode) return;

  int delta = atoi(argB);
  Node * newFocus = NULL;

  if (!strcmp(argA, "id")) {
    newFocus = getNodeById(delta);

  } else if (!strcmp(argA, "brother")) {
      newFocus = getBrother(focusedNode, delta);
  } else if (!strcmp(argA, "pc")) {
    while (delta != 0) {
      newFocus = (delta < 0) ? 
          focusedNode -> parent : focusOrChildOf(focusedNode);
      delta = delta + ( delta > 0 ? -1 : 1);  
      focusNode(newFocus, NULL, True, True);
    } return;
  }

  focusNode(newFocus, NULL, True, True);
}
Exemple #10
0
void jump(char * markName) {
  fprintf(stderr, "Finding a node");

  Mark *n = NULL;
  for(n = markTail; n; n = n -> previous) {
    if (!strcmp(n -> name, markName)) {
      fprintf(stderr, "Going to focus mark %p", n -> node);
      unmapNode(viewNode);
      viewNode = n -> node;
      placeNode(n -> node, rootX, rootY, rootWidth, rootHeight);
      focusNode(n -> node, NULL, True, True);
      while (!isClient(focusedNode)) focus("pc", "1");
    }
  }
}
ghoul::Dictionary InteractionHandler::getCameraStateDictionary() {
    glm::dvec3 cameraPosition;
    glm::dquat quat;
    glm::dvec4 cameraRotation;

    cameraPosition = _camera->positionVec3();
    quat = _camera->rotationQuaternion();
    cameraRotation = glm::dvec4(quat.w, quat.x, quat.y, quat.z);

    ghoul::Dictionary cameraDict;
    cameraDict.setValue(KeyPosition, cameraPosition);
    cameraDict.setValue(KeyRotation, cameraRotation);
    cameraDict.setValue(KeyFocus, focusNode()->name());

    return cameraDict;
}
nsresult
nsContentEventHandler::OnQuerySelectedText(nsQueryContentEvent* aEvent)
{
  nsresult rv = Init(aEvent);
  if (NS_FAILED(rv))
    return rv;

  NS_ASSERTION(aEvent->mReply.mString.IsEmpty(),
               "The reply string must be empty");

  rv = GetFlatTextOffsetOfRange(mRootContent,
                                mFirstSelectedRange, &aEvent->mReply.mOffset);
  NS_ENSURE_SUCCESS(rv, rv);

  nsCOMPtr<nsIDOMNode> anchorDomNode, focusDomNode;
  rv = mSelection->GetAnchorNode(getter_AddRefs(anchorDomNode));
  NS_ENSURE_TRUE(anchorDomNode, NS_ERROR_FAILURE);
  rv = mSelection->GetFocusNode(getter_AddRefs(focusDomNode));
  NS_ENSURE_TRUE(focusDomNode, NS_ERROR_FAILURE);

  PRInt32 anchorOffset, focusOffset;
  rv = mSelection->GetAnchorOffset(&anchorOffset);
  NS_ENSURE_SUCCESS(rv, rv);
  rv = mSelection->GetFocusOffset(&focusOffset);
  NS_ENSURE_SUCCESS(rv, rv);

  nsCOMPtr<nsINode> anchorNode(do_QueryInterface(anchorDomNode));
  nsCOMPtr<nsINode> focusNode(do_QueryInterface(focusDomNode));
  NS_ENSURE_TRUE(anchorNode && focusNode, NS_ERROR_UNEXPECTED);

  PRInt16 compare = nsContentUtils::ComparePoints(anchorNode, anchorOffset,
                                                  focusNode, focusOffset);
  aEvent->mReply.mReversed = compare > 0;

  if (compare) {
    nsCOMPtr<nsIRange> range = mFirstSelectedRange;
    rv = GenerateFlatTextContent(range, aEvent->mReply.mString);
    NS_ENSURE_SUCCESS(rv, rv);
  }

  aEvent->mSucceeded = PR_TRUE;
  return NS_OK;
}
void InspectorController::setWindowVisible(bool visible)
{
    if (visible == m_windowVisible)
        return;

    m_windowVisible = visible;

    if (!m_scriptContext || !m_scriptObject)
        return;

    if (m_windowVisible) {
        populateScriptResources();
        if (m_nodeToFocus)
            focusNode();
    } else {
        clearScriptResources();
        clearScriptConsoleMessages();
        clearNetworkTimeline();
    }
}
Exemple #14
0
void eMapRequest(XEvent *event) {
  fprintf(stderr, "Got a map request\n");
  Node *newNode = allocateNode();
  newNode -> window = event -> xmaprequest.window;

  /* For Click to Focus */
  XGrabButton(display, AnyButton, AnyModifier, newNode -> window,
      True, ButtonPressMask | ButtonReleaseMask, GrabModeAsync, GrabModeSync,
      None, None);

  //Containerize and move the viewNode
  if (focusedNode == viewNode) {
    fprintf(stderr, "Focused node is equal to the viewnode\n");
    containerize();
    viewNode = viewNode -> parent ? viewNode -> parent : viewNode;

    //This is the case in which we reparented the root node
    if (focusedNode == rootNode) { rootNode = viewNode; }

    //Brother the new node and rerender
    brotherNode(newNode, viewNode -> child, 1);
    placeNode(viewNode,  rootX, rootY, rootWidth, rootHeight);
  } else if (focusedNode && focusedNode -> parent) {
    brotherNode(newNode, focusedNode, 1);
    placeNode(focusedNode,
        focusedNode -> parent -> x, focusedNode -> parent -> y,
        focusedNode -> parent -> width, focusedNode -> parent -> height);
  } else {
    //No focus node, fist element created
    fprintf(stderr, "FIRST NODE YO\n");

    parentNode(newNode, viewNode);
  }

  fprintf(stderr, "\n\nAFTA\n\n");

  addLookupEntry(newNode, &newNode -> window);
  fprintf(stderr, "added the lookup entry\n");
  focusNode(newNode, NULL, True, True);
  fprintf(stderr, "done with the map request\n");
}
PassRefPtrWillBeRawPtr<Range> DOMSelection::getRangeAt(int index, ExceptionState& exceptionState)
{
    if (!m_frame)
        return nullptr;

    if (index < 0 || index >= rangeCount()) {
        exceptionState.throwDOMException(IndexSizeError, String::number(index) + " is not a valid index.");
        return nullptr;
    }

    // If you're hitting this, you've added broken multi-range selection support
    ASSERT(rangeCount() == 1);

    Position anchor = anchorPosition(visibleSelection());
    if (!anchor.anchorNode()->isInShadowTree())
        return m_frame->selection().firstRange();

    if (!visibleSelection().isBaseFirst())
        return Range::create(*anchor.document(), focusNode(), focusOffset(), shadowAdjustedNode(anchor), anchorOffset());
    return Range::create(*anchor.document(), shadowAdjustedNode(anchor), anchorOffset(), focusNode(), focusOffset());
}
Exemple #16
0
void kill(void) {
  fprintf(stderr, "Destroying Client %p\n", focusedNode);

  if (isClient(focusedNode)) {

    /* Save closest client and destroy node */
    Node *newFocus = getClosestClient(focusedNode);

    if (focusedNode == viewNode) viewNode = viewNode -> parent;

    if ( isOnlyChild(focusedNode) && focusedNode -> parent) {
      viewNode = focusedNode -> parent -> parent ?
        focusedNode -> parent -> parent : focusedNode -> parent;
    }

    Node *oldFocus = focusedNode;
    focusNode(newFocus, NULL, True, True);
    destroyNode(oldFocus);

    rePlaceNode(viewNode);
  }
}
Exemple #17
0
nsHyperTextAccessible*
nsAccUtils::GetTextAccessibleFromSelection(nsISelection* aSelection)
{
  // Get accessible from selection's focus DOM point (the DOM point where
  // selection is ended).

  nsCOMPtr<nsIDOMNode> focusDOMNode;
  aSelection->GetFocusNode(getter_AddRefs(focusDOMNode));
  if (!focusDOMNode)
    return nsnull;

  PRInt32 focusOffset = 0;
  aSelection->GetFocusOffset(&focusOffset);

  nsCOMPtr<nsINode> focusNode(do_QueryInterface(focusDOMNode));
  nsCOMPtr<nsINode> resultNode =
    nsCoreUtils::GetDOMNodeFromDOMPoint(focusNode, focusOffset);
  nsCOMPtr<nsIWeakReference> weakShell(nsCoreUtils::GetWeakShellFor(resultNode));

  // Get text accessible containing the result node.
  nsAccessible* accessible =
    GetAccService()->GetAccessibleOrContainer(resultNode, weakShell);
  if (!accessible) {
    NS_NOTREACHED("No nsIAccessibleText for selection change event!");
    return nsnull;
  }

  do {
    nsHyperTextAccessible* textAcc = accessible->AsHyperText();
    if (textAcc)
      return textAcc;

  } while (accessible = accessible->GetParent());

  NS_NOTREACHED("We must reach document accessible implementing nsIAccessibleText!");
  return nsnull;
}