Esempio n. 1
0
nsresult
nsBox::EndLayout(nsBoxLayoutState& aState)
{

  #ifdef DEBUG_LAYOUT
      --gIndent;
  #endif

  return SyncLayout(aState);
}
Esempio n. 2
0
Image OpSpeedDialView::GetThumbnailImage(UINT32 width, UINT32 height)
{
	// Must first sync layout in case this speed dials window hasn't
	// been visible yet (then it hasn't been layouted either)
	SyncLayout();

	if (rect.width == 0 || rect.height == 0)
		return Image();

	WidgetThumbnailGenerator thumbnail_generator(*this);

	return thumbnail_generator.GenerateThumbnail(width, height);
}
Esempio n. 3
0
NS_IMETHODIMP
nsPopupSetFrame::DoLayout(nsBoxLayoutState& aState)
{
  // lay us out
  nsresult rv = nsBoxFrame::DoLayout(aState);

  // lay out all of our currently open popups.
  nsPopupFrameList* currEntry = mPopupList;
  while (currEntry) {
    nsIFrame* popupChild = currEntry->mPopupFrame;
    if (popupChild) {
      NS_ASSERTION(popupChild->IsBoxFrame(), "popupChild is not box!!");

      // then get its preferred size
      nsSize prefSize(0,0);
      nsSize minSize(0,0);
      nsSize maxSize(0,0);

      popupChild->GetPrefSize(aState, prefSize);
      popupChild->GetMinSize(aState, minSize);
      popupChild->GetMaxSize(aState, maxSize);

      BoundsCheck(minSize, prefSize, maxSize);

      // if the pref size changed then set bounds to be the pref size
      // and sync the view. Also set new pref size.
     // if (currEntry->mLastPref != prefSize) {
        popupChild->SetBounds(aState, nsRect(0,0,prefSize.width, prefSize.height));
        RepositionPopup(currEntry, aState);
        currEntry->mLastPref = prefSize;
     // }

      // is the new size too small? Make sure we handle scrollbars correctly
      nsIBox* child;
      popupChild->GetChildBox(&child);

      nsRect bounds(popupChild->GetRect());

      nsCOMPtr<nsIScrollableFrame> scrollframe = do_QueryInterface(child);
      if (scrollframe &&
          scrollframe->GetScrollbarStyles().mVertical == NS_STYLE_OVERFLOW_AUTO) {
        // if our pref height
        if (bounds.height < prefSize.height) {
          // layout the child
          popupChild->Layout(aState);

          nsMargin scrollbars = scrollframe->GetActualScrollbarSizes();
          if (bounds.width < prefSize.width + scrollbars.left + scrollbars.right)
          {
            bounds.width += scrollbars.left + scrollbars.right;
            //printf("Width=%d\n",width);
            popupChild->SetBounds(aState, bounds);
          }
        }
      }
    
      // layout the child
      popupChild->Layout(aState);

      // only size popup if open
      if (currEntry->mCreateHandlerSucceeded) {
        nsIView* view = popupChild->GetView();
        nsIViewManager* viewManager = view->GetViewManager();
        nsRect r(0, 0, bounds.width, bounds.height);
        viewManager->ResizeView(view, r);
        viewManager->SetViewVisibility(view, nsViewVisibility_kShow);
      }
    }

    currEntry = currEntry->mNextPopup;
  }

  SyncLayout(aState);

  return rv;
}
Esempio n. 4
0
BOOL Hotlist::OnInputAction(OpInputAction* action)
{
	if (!m_selector)
		return FALSE;

	if (OpBar::OnInputAction(action))
		return TRUE;

	HotlistPanel* panel = m_selector->GetFocused() != -1 ? GetPanel(m_selector->GetFocused()) : NULL;
	WebPanel* web_panel = panel && panel->GetType() == PANEL_TYPE_WEB ? (WebPanel*) panel : NULL;

	switch (action->GetAction())
	{
		case OpInputAction::ACTION_GET_ACTION_STATE:
		{
			OpInputAction* child_action = action->GetChildAction();

			switch (child_action->GetAction())
			{
				case OpInputAction::ACTION_FOCUS_PANEL:
				{
					child_action->SetEnabled(TRUE);
					child_action->SetSelected(!child_action->HasActionDataString() && m_selector->GetSelected() == child_action->GetActionData());
					return TRUE;
				}

				case OpInputAction::ACTION_EDIT_PANEL:
				{
					child_action->SetEnabled(web_panel != NULL);
					return TRUE;
				}
				case OpInputAction::ACTION_SHOW_POPUP_MENU:
				{
					if (child_action->HasActionDataString() && uni_stricmp(child_action->GetActionDataString(), UNI_L("Internal Panels")) == 0)
					{
						OpString text;
						GetPanelText(m_selector->GetSelected(), text, PANEL_TEXT_NAME);

						child_action->SetActionText(text.CStr());
						return TRUE;
					}
					return FALSE;
				}
				case OpInputAction::ACTION_ADD_WEB_PANEL:
				{
					// DSK-351304: adding a web panel creates new bookmark - disable until bookmarks are loaded
					child_action->SetEnabled(g_desktop_bookmark_manager->GetBookmarkModel()->Loaded());
					return TRUE;
				}
			}
			break;
		}

		case OpInputAction::ACTION_GET_TYPED_OBJECT:
		{
			if (action->GetActionData() == WIDGET_TYPE_HOTLIST)
			{
				action->SetActionObject(this);
				return TRUE;
			}
			return FALSE;
		}

		case OpInputAction::ACTION_HIDE_PANEL:
		{
			if (action->GetActionData() == -1 && IsCollapsableToSmall())
			{
				return m_selector->SetSelected(-1, TRUE);
			}

			BOOL has_focus = IsFocused(TRUE);
			BOOL result = ShowPanelByName(action->GetActionDataString(), FALSE);

			if( has_focus )
			{
				DesktopWindow *window = g_application->GetActiveDesktopWindow();
				if( window )
				{
					//Does not work. Would like to use it but does not work yet [espen 2004-04-01]
					//window->RestoreFocus(FOCUS_REASON_OTHER);
					g_input_manager->InvokeAction(OpInputAction::ACTION_FOCUS_PAGE);
				}
			}

			return result;
		}

		case OpInputAction::ACTION_SHOW_PANEL:
		case OpInputAction::ACTION_FOCUS_PANEL:
		{
			INT32 index = action->GetActionData();

			HotlistPanel* panel = NULL;
			BOOL handled = FALSE;

			if (action->HasActionDataString()) // show a specific panel (another panel might already be open)
			{
				handled = ShowPanelByName(action->GetActionDataString(), TRUE);

				if (!handled && action->GetAction() == OpInputAction::ACTION_SHOW_PANEL)
					return FALSE;

				panel = GetPanelByType(GetPanelTypeByName(action->GetActionDataString()), &index);
			}
			else if (action->GetAction() == OpInputAction::ACTION_FOCUS_PANEL ||	// focus a specific panel
					 GetAlignment() == ALIGNMENT_OFF || GetSelectedPanel() == -1)	// show the currently active panel (no panel is currently open)
			{
				if (index == -1)
					index = ReadActiveTab();

				panel = GetPanel(index);
			}
			else // don't show anything (advance to next input action, which is normally: hide panel)
			{
				action->SetWasReallyHandled(FALSE);
				return TRUE;
			}

			if (!panel)
				return FALSE;

			// make sure we are visible

			if (SetAlignment(OpBar::ALIGNMENT_OLD_VISIBLE))
				handled = TRUE;

			SyncLayout();

			if (m_selector->SetSelected(index, TRUE, TRUE))
				handled = TRUE;

			if (GetParentDesktopWindow()->Activate())
				handled = TRUE;

			panel->RestoreFocus(FOCUS_REASON_ACTION);

			return handled;
		}

		case OpInputAction::ACTION_REMOVE_PANEL:
		{
			if (web_panel)
			{
				g_hotlist_manager->ShowInPanel( web_panel->GetID(), FALSE );
			}
			else if (panel)
			{
				RemovePanel(m_selector->GetFocused());
				m_selector->WriteContent();
			}
			return TRUE;
		}

		case OpInputAction::ACTION_EDIT_PANEL:
		{
			if (web_panel)
			{
				g_hotlist_manager->EditItem( web_panel->GetID(), GetParentDesktopWindow() );
			}
			return TRUE;
		}

		case OpInputAction::ACTION_SHOW_CONTEXT_MENU:
		{
			ShowContextMenu(m_selector->GetBounds().Center(),TRUE,TRUE);
			return TRUE;
		}

		case OpInputAction::ACTION_ADD_WEB_PANEL:
		{
			AddWebPanelController* controller = OP_NEW(AddWebPanelController, ());
			OpStatus::Ignore(ShowDialog(controller, g_global_ui_context, g_application->GetActiveDocumentDesktopWindow()));
			return TRUE;
		}

		case OpInputAction::ACTION_MANAGE:
		{
			if (action->HasActionDataString() || !panel)
				return FALSE;

			if (web_panel)
			{
				OpenURLSetting settings;
				web_panel->GetURL(settings.m_address);
				settings.m_ignore_modifier_keys = (action->IsKeyboardInvoked());

				g_application->OpenURL(settings);
			}
			else
			{
				g_application->GetPanelDesktopWindow(panel->GetType() , TRUE);
			}
			return TRUE;
		}
	}

	return FALSE;
}
Esempio n. 5
0
NS_IMETHODIMP
nsSliderFrame::DoLayout(nsBoxLayoutState& aState)
{
  // get the thumb should be our only child
  nsIBox* thumbBox = GetChildBox();

  if (!thumbBox) {
    SyncLayout(aState);
    return NS_OK;
  }

  EnsureOrient();

#ifdef DEBUG_LAYOUT
  if (mState & NS_STATE_DEBUG_WAS_SET) {
      if (mState & NS_STATE_SET_TO_DEBUG)
          SetDebug(aState, PR_TRUE);
      else
          SetDebug(aState, PR_FALSE);
  }
#endif

  // get the content area inside our borders
  nsRect clientRect;
  GetClientRect(clientRect);

  // get the scrollbar
  nsIBox* scrollbarBox = GetScrollbar();
  nsCOMPtr<nsIContent> scrollbar;
  scrollbar = GetContentOfBox(scrollbarBox);

  // get the thumb's pref size
  nsSize thumbSize = thumbBox->GetPrefSize(aState);

  if (IsHorizontal())
    thumbSize.height = clientRect.height;
  else
    thumbSize.width = clientRect.width;

  PRInt32 curPos = GetCurrentPosition(scrollbar);
  PRInt32 minPos = GetMinPosition(scrollbar);
  PRInt32 maxPos = GetMaxPosition(scrollbar);
  PRInt32 pageIncrement = GetPageIncrement(scrollbar);

  maxPos = NS_MAX(minPos, maxPos);
  curPos = NS_MAX(minPos, NS_MIN(curPos, maxPos));

  nscoord& availableLength = IsHorizontal() ? clientRect.width : clientRect.height;
  nscoord& thumbLength = IsHorizontal() ? thumbSize.width : thumbSize.height;

  if ((pageIncrement + maxPos - minPos) > 0 && thumbBox->GetFlex(aState) > 0) {
    float ratio = float(pageIncrement) / float(maxPos - minPos + pageIncrement);
    thumbLength = NS_MAX(thumbLength, NSToCoordRound(availableLength * ratio));
  }

  // Round the thumb's length to device pixels.
  nsPresContext* presContext = PresContext();
  thumbLength = presContext->DevPixelsToAppUnits(
                  presContext->AppUnitsToDevPixels(thumbLength));

  // mRatio translates the thumb position in app units to the value.
  mRatio = (minPos != maxPos) ? float(availableLength - thumbLength) / float(maxPos - minPos) : 1;

  // in reverse mode, curpos is reversed such that lower values are to the
  // right or bottom and increase leftwards or upwards. In this case, use the
  // offset from the end instead of the beginning.
  PRBool reverse = mContent->AttrValueIs(kNameSpaceID_None, nsGkAtoms::dir,
                                         nsGkAtoms::reverse, eCaseMatters);
  nscoord pos = reverse ? (maxPos - curPos) : (curPos - minPos);

  // set the thumb's coord to be the current pos * the ratio.
  nsRect thumbRect(clientRect.x, clientRect.y, thumbSize.width, thumbSize.height);
  PRInt32& thumbPos = (IsHorizontal() ? thumbRect.x : thumbRect.y);
  thumbPos += NSToCoordRound(pos * mRatio);

  nsRect oldThumbRect(thumbBox->GetRect());
  LayoutChildAt(aState, thumbBox, thumbRect);

  SyncLayout(aState);

  // Redraw only if thumb changed size.
  if (oldThumbRect != thumbRect)
    Redraw(aState);

  return NS_OK;
}