Example #1
0
void FolderView::OnMouseLeftDown(NervMouseEvent* in_event){
	//we capture mouse events so that we could perform mouse drag actions 
	//we release mouse events when mouse button is up
	CaptureMouseEvents();
	//ContainsMouse() method calculates if the mouse was in the scrollbar area
	//during previous MouseMove events
	//if scrollbar state is other than State::normal, that means that mouse is 
	//inside scrollbar area. We process scrollbar mouse messages internally,
	//because scrollbar position only affects the view
	if (scrollbar.ContainsMouse()){
		scrollbar.OnMouseLeftDown(in_event->pt);
	}

	//if the MouseClick event has occured in the area of elements, that could be
	//meaningful for our model/controller, thats why we pass it to the Controller
	//with the index of the item that was under mouse pointer in the last MouseMove
	//event
	else{
		PerformCallback(NervEvent::MouseLeftClicked, 0);
	}
}
Example #2
0
NS_IMETHODIMP
nsTitleBarFrame::HandleEvent(nsPresContext* aPresContext,
                                      nsGUIEvent* aEvent,
                                      nsEventStatus* aEventStatus)
{
  NS_ENSURE_ARG_POINTER(aEventStatus);
  if (nsEventStatus_eConsumeNoDefault == *aEventStatus) {
    return NS_OK;
  }

  PRBool doDefault = PR_TRUE;

  switch (aEvent->message) {

   case NS_MOUSE_BUTTON_DOWN:  {
       if (aEvent->eventStructType == NS_MOUSE_EVENT &&
           static_cast<nsMouseEvent*>(aEvent)->button ==
             nsMouseEvent::eLeftButton)
       {
         // titlebar has no effect in non-chrome shells
         nsCOMPtr<nsISupports> cont = aPresContext->GetContainer();
         nsCOMPtr<nsIDocShellTreeItem> dsti = do_QueryInterface(cont);
         if (dsti) {
           PRInt32 type = -1;
           if (NS_SUCCEEDED(dsti->GetItemType(&type)) &&
               type == nsIDocShellTreeItem::typeChrome) {
             // we're tracking.
             mTrackingMouseMove = PR_TRUE;

             // start capture.
             CaptureMouseEvents(aPresContext,PR_TRUE);

             // remember current mouse coordinates.
             mLastPoint = aEvent->refPoint;
           }
         }

         *aEventStatus = nsEventStatus_eConsumeNoDefault;
         doDefault = PR_FALSE;
       }
     }
     break;


   case NS_MOUSE_BUTTON_UP: {
       if(mTrackingMouseMove && aEvent->eventStructType == NS_MOUSE_EVENT &&
          static_cast<nsMouseEvent*>(aEvent)->button ==
            nsMouseEvent::eLeftButton)
       {
         // we're done tracking.
         mTrackingMouseMove = PR_FALSE;

         // end capture
         CaptureMouseEvents(aPresContext,PR_FALSE);

         *aEventStatus = nsEventStatus_eConsumeNoDefault;
         doDefault = PR_FALSE;
       }
     }
     break;

   case NS_MOUSE_MOVE: {
       if(mTrackingMouseMove)
       {
         nsIntPoint nsMoveBy = aEvent->refPoint - mLastPoint;

         nsIFrame* parent = GetParent();
         while (parent && parent->GetType() != nsGkAtoms::menuPopupFrame)
           parent = parent->GetParent();

         // if the titlebar is in a popup, move the popup's widget, otherwise
         // move the widget associated with the window
         if (parent) {
           nsCOMPtr<nsIWidget> widget;
           (static_cast<nsMenuPopupFrame*>(parent))->
             GetWidget(getter_AddRefs(widget));
           nsIntRect bounds;
           widget->GetScreenBounds(bounds);
           widget->Move(bounds.x + nsMoveBy.x, bounds.y + nsMoveBy.y);
         }
         else {
           nsIPresShell* presShell = aPresContext->PresShell();
           nsPIDOMWindow *window = presShell->GetDocument()->GetWindow();
           if (window) {
             window->MoveBy(nsMoveBy.x, nsMoveBy.y);
           }
         }

         *aEventStatus = nsEventStatus_eConsumeNoDefault;

         doDefault = PR_FALSE;
       }
     }
     break;



    case NS_MOUSE_CLICK:
      if (NS_IS_MOUSE_LEFT_CLICK(aEvent))
      {
        MouseClicked(aPresContext, aEvent);
      }
      break;
  }

  if ( doDefault )
    return nsBoxFrame::HandleEvent(aPresContext, aEvent, aEventStatus);
  else
    return NS_OK;
}
Example #3
0
NS_IMETHODIMP
nsTitleBarFrame::HandleEvent(nsPresContext* aPresContext, 
                                      nsGUIEvent* aEvent,
                                      nsEventStatus* aEventStatus)
{


  PRBool doDefault = PR_TRUE;

  switch (aEvent->message) {

	 case NS_MOUSE_LEFT_BUTTON_DOWN:	{
			 
			 // we're tracking.
			 mTrackingMouseMove = PR_TRUE;
			 
			 // start capture.		
			 CaptureMouseEvents(aPresContext,PR_TRUE);


			 
			 // remember current mouse coordinates.
			 mLastPoint = aEvent->refPoint;

			 *aEventStatus = nsEventStatus_eConsumeNoDefault;
			 doDefault = PR_FALSE;
		 }
		 break;
		 

	 case NS_MOUSE_LEFT_BUTTON_UP: {

			 if(mTrackingMouseMove)
			 {
				 // we're done tracking.
				 mTrackingMouseMove = PR_FALSE;
				 
				 // end capture
				 CaptureMouseEvents(aPresContext,PR_FALSE);

				 *aEventStatus = nsEventStatus_eConsumeNoDefault;
				 doDefault = PR_FALSE;
			 }
		 }
		 break;

	 case NS_MOUSE_MOVE: {
			 if(mTrackingMouseMove)
			 {				 				 
			   // get the document and the global script object - should this be cached?
			   nsCOMPtr<nsIDOMWindowInternal>
           window(do_QueryInterface(aPresContext->PresShell()->GetDocument()->GetScriptGlobalObject()));

         if (window) {
           nsPoint nsMoveBy = aEvent->refPoint - mLastPoint;
           window->MoveBy(nsMoveBy.x,nsMoveBy.y);
         }
				 
				 *aEventStatus = nsEventStatus_eConsumeNoDefault;				
				 
				 doDefault = PR_FALSE;
			 }
		 }
		 break;



    case NS_MOUSE_LEFT_CLICK:
      MouseClicked(aPresContext, aEvent);
      break;
  }
  
  if ( doDefault )  
	  return nsBoxFrame::HandleEvent(aPresContext, aEvent, aEventStatus);
  else
	  return NS_OK;
}
Example #4
0
NS_IMETHODIMP
nsResizerFrame::HandleEvent(nsPresContext* aPresContext,
                            nsGUIEvent* aEvent,
                            nsEventStatus* aEventStatus)
{
  nsWeakFrame weakFrame(this);
  PRBool doDefault = PR_TRUE;

  switch (aEvent->message) {

   case NS_MOUSE_BUTTON_DOWN: {
       if (aEvent->eventStructType == NS_MOUSE_EVENT &&
           static_cast<nsMouseEvent*>(aEvent)->button ==
             nsMouseEvent::eLeftButton)
       {

         nsresult rv = NS_OK;

         // what direction should we go in? 
         // convert eDirection to horizontal and vertical directions
         static const PRInt8 directions[][2] = {
           {-1, -1}, {0, -1}, {1, -1},
           {-1,  0},          {1,  0},
           {-1,  1}, {0,  1}, {1,  1}
         };

         // ask the widget implementation to begin a resize drag if it can
         rv = aEvent->widget->BeginResizeDrag(aEvent, 
             directions[mDirection][0], directions[mDirection][1]);

         if (rv == NS_ERROR_NOT_IMPLEMENTED) {
           // there's no native resize support, 
           // we need to window resizing ourselves

           // we're tracking.
           mTrackingMouseMove = PR_TRUE;

           // start capture.
           aEvent->widget->CaptureMouse(PR_TRUE);
           CaptureMouseEvents(aPresContext,PR_TRUE);

           // remember current mouse coordinates.
           mLastPoint = aEvent->refPoint;
           aEvent->widget->GetScreenBounds(mWidgetRect);
         }

         *aEventStatus = nsEventStatus_eConsumeNoDefault;
         doDefault = PR_FALSE;
       }
     }
     break;


   case NS_MOUSE_BUTTON_UP: {

       if(mTrackingMouseMove && aEvent->eventStructType == NS_MOUSE_EVENT &&
          static_cast<nsMouseEvent*>(aEvent)->button ==
            nsMouseEvent::eLeftButton)
       {
         // we're done tracking.
         mTrackingMouseMove = PR_FALSE;

         // end capture
         aEvent->widget->CaptureMouse(PR_FALSE);
         CaptureMouseEvents(aPresContext,PR_FALSE);

         *aEventStatus = nsEventStatus_eConsumeNoDefault;
         doDefault = PR_FALSE;
       }
     }
     break;

   case NS_MOUSE_MOVE: {
       if(mTrackingMouseMove)
       {
         // get the document and the window - should this be cached?
         nsPIDOMWindow *domWindow =
           aPresContext->PresShell()->GetDocument()->GetWindow();
         NS_ENSURE_TRUE(domWindow, NS_ERROR_FAILURE);

         nsCOMPtr<nsIDocShellTreeItem> docShellAsItem =
           do_QueryInterface(domWindow->GetDocShell());
         NS_ENSURE_TRUE(docShellAsItem, NS_ERROR_FAILURE);

         nsCOMPtr<nsIDocShellTreeOwner> treeOwner;
         docShellAsItem->GetTreeOwner(getter_AddRefs(treeOwner));

         nsCOMPtr<nsIBaseWindow> window(do_QueryInterface(treeOwner));

         if (!window) {
           return NS_OK;
         }

         nsPoint nsMoveBy(0,0),nsSizeBy(0,0);
         nsPoint nsMouseMove(aEvent->refPoint - mLastPoint);

         switch(mDirection)
         {
            case topleft:
              nsMoveBy = nsMouseMove;
              nsSizeBy -= nsMouseMove;
              break;
            case top:
              nsMoveBy.y = nsMouseMove.y;
              nsSizeBy.y = - nsMouseMove.y;
              break;
            case topright:
              nsMoveBy.y = nsMouseMove.y;
              nsSizeBy.x = nsMouseMove.x;
              mLastPoint.x += nsMouseMove.x;
              nsSizeBy.y = -nsMouseMove.y;
              break;
            case left:
              nsMoveBy.x = nsMouseMove.x;
              nsSizeBy.x = -nsMouseMove.x;
              break;
            case right:
              nsSizeBy.x = nsMouseMove.x;
              mLastPoint.x += nsMouseMove.x;
              break;
            case bottomleft:
              nsMoveBy.x = nsMouseMove.x;
              nsSizeBy.y = nsMouseMove.y;
              nsSizeBy.x = -nsMouseMove.x;
              mLastPoint.y += nsMouseMove.y;
              break;
            case bottom:
              nsSizeBy.y = nsMouseMove.y;
              mLastPoint.y += nsMouseMove.y;
              break;
            case bottomright:
              nsSizeBy = nsMouseMove;
              mLastPoint += nsMouseMove;
              break;
         }

         PRInt32 x,y,cx,cy;
         window->GetPositionAndSize(&x,&y,&cx,&cy);

         x+=nsMoveBy.x;
         y+=nsMoveBy.y;
         cx+=nsSizeBy.x;
         cy+=nsSizeBy.y;

         window->SetPositionAndSize(x,y,cx,cy,PR_TRUE); // do the repaint.

         /*
         if(nsSizeBy.x || nsSizeBy.y)
         {
          window->ResizeBy(nsSizeBy.x,nsSizeBy.y);
         }

         if(nsMoveBy.x || nsMoveBy.y)
         {
          window->MoveBy(nsMoveBy.x,nsMoveBy.y);
         }  */

         *aEventStatus = nsEventStatus_eConsumeNoDefault;

         doDefault = PR_FALSE;
       }
     }
     break;



    case NS_MOUSE_CLICK:
      if (NS_IS_MOUSE_LEFT_CLICK(aEvent))
      {
        MouseClicked(aPresContext, aEvent);
      }
      break;
  }

  if (doDefault && weakFrame.IsAlive())
    return nsTitleBarFrame::HandleEvent(aPresContext, aEvent, aEventStatus);
  else
    return NS_OK;
}