Bug 370303: Cleanup in layout/forms. r+sr=roc.

git-svn-id: svn://10.0.0.236/trunk@220186 18797224-902f-48f8-a5cc-f745e15eee43
This commit is contained in:
sharparrow1%yahoo.com
2007-02-15 10:58:31 +00:00
parent 94b87aa7a6
commit db1730f015
10 changed files with 23 additions and 236 deletions

View File

@@ -38,8 +38,6 @@
#include "nsIRenderingContext.h"
#include "nsCSSRendering.h"
#include "nsPresContext.h"
#include "nsIView.h"
#include "nsIViewManager.h"
#include "nsGkAtoms.h"
#include "nsCSSPseudoElements.h"
#include "nsINameSpaceManager.h"

View File

@@ -495,11 +495,8 @@ nsComboboxControlFrame::ReflowDropdown(nsPresContext* aPresContext,
return rv;
}
nsresult
nsComboboxControlFrame::PositionDropdown(nsPresContext* aPresContext,
nscoord aHeight,
nsRect aAbsoluteTwipsRect,
nsRect aAbsolutePixelRect)
void
nsComboboxControlFrame::AbsolutelyPositionDropDown()
{
// Position the dropdown list. It is positioned below the display frame if there is enough
// room on the screen to display the entire list. Otherwise it is placed above the display
@@ -514,34 +511,33 @@ nsComboboxControlFrame::PositionDropdown(nsPresContext* aPresContext,
// Use the height calculated for the area frame so it includes both
// the display and button heights.
nsresult rv = NS_OK;
nscoord dropdownYOffset = aHeight;
nscoord dropdownYOffset = GetRect().height;
nsPresContext* presContext = GetPresContext();
// XXX: Enable this code to debug popping up above the display frame, rather than below it
nsRect dropdownRect = mDropdownFrame->GetRect();
nsSize dropdownSize = mDropdownFrame->GetSize();
nscoord screenHeightInPixels = 0;
if (NS_SUCCEEDED(nsFormControlFrame::GetScreenHeight(aPresContext, screenHeightInPixels))) {
// Get the height of the dropdown list in pixels.
nscoord absoluteDropDownHeight = aPresContext->AppUnitsToDevPixels(dropdownRect.height);
// Check to see if the drop-down list will go offscreen
if (NS_SUCCEEDED(rv) && ((aAbsolutePixelRect.y + aAbsolutePixelRect.height + absoluteDropDownHeight) > screenHeightInPixels)) {
if (NS_SUCCEEDED(nsFormControlFrame::GetScreenHeight(presContext, screenHeightInPixels))) {
// Get the height of the dropdown list in pixels.
nscoord absoluteDropDownHeight = presContext->AppUnitsToDevPixels(dropdownSize.height);
// Check to see if the drop-down list will go offscreen
if (GetScreenRect().YMost() + absoluteDropDownHeight > screenHeightInPixels) {
// move the dropdown list up
dropdownYOffset = - (dropdownRect.height);
dropdownYOffset = - (dropdownSize.height);
}
}
nsPoint dropdownPosition;
const nsStyleVisibility* vis = GetStyleVisibility();
if (vis->mDirection == NS_STYLE_DIRECTION_RTL) {
// Align the right edge of the drop-down with the right edge of the control.
dropdownRect.x = aAbsoluteTwipsRect.width - dropdownRect.width;
dropdownPosition.x = GetRect().width - dropdownSize.width;
} else {
dropdownRect.x = 0;
dropdownPosition.x = 0;
}
dropdownRect.y = dropdownYOffset;
dropdownPosition.y = dropdownYOffset;
mDropdownFrame->SetRect(dropdownRect);
return rv;
mDropdownFrame->SetPosition(dropdownPosition);
}
//----------------------------------------------------------
@@ -750,17 +746,6 @@ nsComboboxControlFrame::ToggleList(nsPresContext* aPresContext)
return NS_OK;
}
void
nsComboboxControlFrame::AbsolutelyPositionDropDown()
{
nsRect absoluteTwips;
nsRect absolutePixels;
if (NS_SUCCEEDED(nsFormControlFrame::GetAbsoluteFramePosition(GetPresContext(), this, absoluteTwips, absolutePixels))) {
PositionDropdown(GetPresContext(), GetRect().height, absoluteTwips, absolutePixels);
}
}
///////////////////////////////////////////////////////////////
NS_IMETHODIMP

View File

@@ -203,11 +203,6 @@ protected:
nsresult ReflowDropdown(nsPresContext* aPresContext,
const nsHTMLReflowState& aReflowState);
public:
nsresult PositionDropdown(nsPresContext* aPresContext,
nscoord aHeight,
nsRect aAbsoluteTwipsRect,
nsRect aAbsolutePixelRect);
protected:
class RedisplayTextEvent;
friend class RedisplayTextEvent;

View File

@@ -44,7 +44,6 @@
#include "nsGkAtoms.h"
#include "nsWidgetsCID.h"
#include "nsIComponentManager.h"
#include "nsIView.h"
#include "nsHTMLParts.h"
#include "nsIDOMHTMLInputElement.h"
#include "nsIFormControl.h"

View File

@@ -41,15 +41,13 @@
#include "nsIEventStateManager.h"
#include "nsIScrollableView.h"
#include "nsILookAndFeel.h"
#include "nsIViewManager.h"
//#define FCF_NOISY
const PRInt32 kSizeNotSet = -1;
nsFormControlFrame::nsFormControlFrame(nsStyleContext* aContext) :
nsLeafFrame(aContext),
mDidInit(PR_FALSE)
nsLeafFrame(aContext)
{
}
@@ -60,8 +58,7 @@ nsFormControlFrame::~nsFormControlFrame()
void
nsFormControlFrame::Destroy()
{
// XXXldb Do we really need to do this? Shouldn't only those frames
// that use it do it?
// Unregister the access key registered in reflow
nsFormControlFrame::RegUnRegAccessKey(NS_STATIC_CAST(nsIFrame*, this), PR_FALSE);
nsLeafFrame::Destroy();
}
@@ -84,55 +81,15 @@ nsFormControlFrame::QueryInterface(const nsIID& aIID, void** aInstancePtr)
nscoord
nsFormControlFrame::GetIntrinsicWidth()
{
// Intrinsic width is 144 twips. Why? I have no idea; that's what
// it was before I touched this code, and the original checkin
// comment is not so helpful.
return 144;
// Actual width is set in forms.css
return 0;
}
nscoord
nsFormControlFrame::GetIntrinsicHeight()
{
// Intrinsic height is 144 twips. Why? I have no idea; that's what
// it was before I touched this code, and the original checkin
// comment is not so helpful.
return 144;
}
NS_IMETHODIMP
nsFormControlFrame::DidReflow(nsPresContext* aPresContext,
const nsHTMLReflowState* aReflowState,
nsDidReflowStatus aStatus)
{
nsresult rv = nsLeafFrame::DidReflow(aPresContext, aReflowState, aStatus);
// The view is created hidden; once we have reflowed it and it has been
// positioned then we show it.
if (NS_FRAME_REFLOW_FINISHED == aStatus) {
nsIView* view = GetView();
if (view) {
nsViewVisibility newVis = GetStyleVisibility()->IsVisible()
? nsViewVisibility_kShow
: nsViewVisibility_kHide;
// only change if different.
if (newVis != view->GetVisibility()) {
nsIViewManager* vm = view->GetViewManager();
if (vm) {
vm->SetViewVisibility(view, newVis);
}
}
}
}
return rv;
}
NS_IMETHODIMP
nsFormControlFrame::SetInitialChildList(nsIAtom* aListName,
nsIFrame* aChildList)
{
return NS_OK;
// Actual width is set in forms.css
return 0;
}
NS_METHOD
@@ -236,69 +193,3 @@ nsFormControlFrame::GetScreenHeight(nsPresContext* aPresContext,
aHeight = aPresContext->AppUnitsToDevPixels(screen.height);
return NS_OK;
}
// Calculate a frame's position in screen coordinates
nsresult
nsFormControlFrame::GetAbsoluteFramePosition(nsPresContext* aPresContext,
nsIFrame *aFrame,
nsRect& aAbsoluteTwipsRect,
nsRect& aAbsolutePixelRect)
{
nsresult rv = NS_OK;
aAbsoluteTwipsRect = aFrame->GetRect();
// zero these out,
// because the GetOffsetFromView figures them out
// XXXbz why do we need to do this, really? Will we ever fail to
// get a containing view?
aAbsoluteTwipsRect.x = 0;
aAbsoluteTwipsRect.y = 0;
// Start with frame's offset from it it's containing view
nsIView *view = nsnull;
nsPoint frameOffset;
rv = aFrame->GetOffsetFromView(frameOffset, &view);
if (NS_SUCCEEDED(rv) && view) {
aAbsoluteTwipsRect.MoveTo(frameOffset);
nsIWidget* widget;
// Walk up the views, looking for a widget
do {
// add in the offset of the view from its parent.
aAbsoluteTwipsRect += view->GetPosition();
widget = view->GetWidget();
if (widget) {
// account for space above and to the left of the view origin.
// the widget is aligned with view's bounds, not its origin
nsRect bounds = view->GetBounds();
aAbsoluteTwipsRect.x -= bounds.x;
aAbsoluteTwipsRect.y -= bounds.y;
// Add in the absolute offset of the widget.
nsRect absBounds;
nsRect zeroRect;
// XXX a twip version of this would be really nice here!
widget->WidgetToScreen(zeroRect, absBounds);
// Convert widget coordinates to twips
aAbsoluteTwipsRect.x += aPresContext->DevPixelsToAppUnits(absBounds.x);
aAbsoluteTwipsRect.y += aPresContext->DevPixelsToAppUnits(absBounds.y);
break;
}
view = view->GetParent();
} while (view);
}
// convert to pixel coordinates
if (NS_SUCCEEDED(rv)) {
aAbsolutePixelRect.x = aPresContext->AppUnitsToDevPixels(aAbsoluteTwipsRect.x);
aAbsolutePixelRect.y = aPresContext->AppUnitsToDevPixels(aAbsoluteTwipsRect.y);
aAbsolutePixelRect.width = aPresContext->AppUnitsToDevPixels(aAbsoluteTwipsRect.width);
aAbsolutePixelRect.height = aPresContext->AppUnitsToDevPixels(aAbsoluteTwipsRect.height);
}
return rv;
}

View File

@@ -41,29 +41,6 @@
#include "nsIFormControlFrame.h"
#include "nsLeafFrame.h"
#define ATTR_NOTSET -1
#ifdef DEBUG_rods
#define COMPARE_QUIRK_SIZE(__class, __navWidth, __navHeight) \
{ \
float t2p; \
t2p = aPresContext->TwipsToPixels(); \
printf ("%-25s::Size=%4d,%4d %3d,%3d Nav:%3d,%3d Diffs: %3d,%3d\n", \
(__class), \
aDesiredSize.width, aDesiredSize.height, \
NSToCoordRound(aDesiredSize.width * t2p), \
NSToCoordRound(aDesiredSize.height * t2p), \
(__navWidth), \
(__navHeight), \
NSToCoordRound(aDesiredSize.width * t2p) - (__navWidth), \
NSToCoordRound(aDesiredSize.height * t2p) - (__navHeight)); \
}
#else
#define COMPARE_QUIRK_SIZE(__class, __navWidth, __navHeight)
#endif
/**
* nsFormControlFrame is the base class for frames of form controls. It
* provides a uniform way of creating widgets, resizing, and painting.
@@ -91,13 +68,6 @@ public:
nsGUIEvent* aEvent,
nsEventStatus* aEventStatus);
NS_IMETHOD SetInitialChildList(nsIAtom* aListName,
nsIFrame* aChildList);
NS_IMETHOD DidReflow(nsPresContext* aPresContext,
const nsHTMLReflowState* aReflowState,
nsDidReflowStatus aStatus);
/**
* Respond to the request to resize and/or reflow
* @see nsIFrame::Reflow
@@ -127,14 +97,6 @@ public:
*/
static nsresult GetScreenHeight(nsPresContext* aPresContext, nscoord& aHeight);
/**
* Helper method to get the absolute position of a frame
*
*/
static nsresult GetAbsoluteFramePosition(nsPresContext* aPresContext,
nsIFrame *aFrame,
nsRect& aAbsoluteTwipsRect,
nsRect& aAbsolutePixelRect);
protected:
virtual ~nsFormControlFrame();
@@ -155,8 +117,6 @@ protected:
void GetCurrentCheckState(PRBool* aState);
PRBool mDidInit;
private:
NS_IMETHOD_(nsrefcnt) AddRef() { return NS_OK; }
NS_IMETHOD_(nsrefcnt) Release() { return NS_OK; }

View File

@@ -45,7 +45,6 @@
#include "nsPresState.h"
#include "nsWidgetsCID.h"
#include "nsIComponentManager.h"
#include "nsIView.h"
#include "nsHTMLParts.h"
#include "nsIDOMHTMLInputElement.h"
#include "nsINameSpaceManager.h"
@@ -254,18 +253,6 @@ nsIsIndexFrame::QueryInterface(const nsIID& aIID, void** aInstancePtr)
return nsHTMLContainerFrame::QueryInterface(aIID, aInstancePtr);
}
void
nsIsIndexFrame::ScrollIntoView(nsPresContext* aPresContext)
{
if (aPresContext) {
nsIPresShell *presShell = aPresContext->GetPresShell();
if (presShell) {
presShell->ScrollFrameIntoView(this,
NS_PRESSHELL_SCROLL_IF_NOT_VISIBLE,NS_PRESSHELL_SCROLL_IF_NOT_VISIBLE);
}
}
}
nscoord
nsIsIndexFrame::GetMinWidth(nsIRenderingContext *aRenderingContext)
{

View File

@@ -96,7 +96,6 @@ public:
PRInt32 aModType);
void SetFocus(PRBool aOn, PRBool aRepaint);
void ScrollIntoView(nsPresContext* aPresContext);
// from nsIAnonymousContentCreator
NS_IMETHOD CreateAnonymousContent(nsPresContext* aPresContext,

View File

@@ -62,10 +62,8 @@ class nsIDOMHTMLSelectElement;
class nsIDOMHTMLOptionsCollection;
class nsIDOMHTMLOptionElement;
class nsIComboboxControlFrame;
class nsIViewManager;
class nsPresContext;
class nsVoidArray;
class nsIScrollableView;
class nsVoidArray;
class nsListEventListener;

View File

@@ -70,10 +70,6 @@
#include "nsIContent.h"
#include "nsIAtom.h"
#include "nsPresContext.h"
#ifdef USE_QI_IN_SUPPRESS_EVENT_HANDLERS
#include "nsIPrintContext.h"
#include "nsIPrintPreviewContext.h"
#endif // USE_QI_IN_SUPPRESS_EVENT_HANDLERS
#include "nsGkAtoms.h"
#include "nsLayoutUtils.h"
#include "nsIComponentManager.h"
@@ -1058,31 +1054,10 @@ SuppressEventHandlers(nsPresContext* aPresContext)
// Right now we only suppress event handlers and controller manipulation
// when in a print preview or print context!
#ifdef USE_QI_IN_SUPPRESS_EVENT_HANDLERS
// Using QI to see if we're printing or print previewing is more
// accurate, but a bit more heavy weight then just checking
// the pagination bool, which will return the right answer to us
// with the current implementation.
nsCOMPtr<nsIPrintContext> printContext = do_QueryInterface(aPresContext);
if (printContext)
suppressHandlers = PR_TRUE;
else
{
nsCOMPtr<nsIPrintPreviewContext> printPreviewContext = do_QueryInterface(aPresContext);
if (printPreviewContext)
suppressHandlers = PR_TRUE;
}
#else
// In the current implementation, we only paginate when
// printing or in print preview.
suppressHandlers = aPresContext->IsPaginated();
#endif
}
return suppressHandlers;