gecko-dev/layout/forms/nsListControlFrame.h

253 строки
11 KiB
C
Исходник Обычный вид История

1999-01-18 18:14:00 +03:00
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
*
* The contents of this file are subject to the Netscape Public
* License Version 1.1 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy of
* the License at http://www.mozilla.org/NPL/
1999-01-18 18:14:00 +03:00
*
* Software distributed under the License is distributed on an "AS
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
* implied. See the License for the specific language governing
* rights and limitations under the License.
1999-01-18 18:14:00 +03:00
*
* The Original Code is Mozilla Communicator client code.
*
* The Initial Developer of the Original Code is Netscape Communications
* Corporation. Portions created by Netscape are
* Copyright (C) 1998 Netscape Communications Corporation. All
* Rights Reserved.
*
* Contributor(s):
1999-01-18 18:14:00 +03:00
*/
#ifndef nsListControlFrame_h___
#define nsListControlFrame_h___
#include "nsScrollFrame.h"
#include "nsIFormControlFrame.h"
#include "nsIListControlFrame.h"
#include "nsISelectControlFrame.h"
#include "nsIDOMMouseListener.h"
#include "nsIDOMMouseMotionListener.h"
#include "nsIDOMKeyListener.h"
#include "nsIStatefulFrame.h"
1999-01-18 18:14:00 +03:00
class nsIDOMHTMLSelectElement;
class nsIDOMHTMLCollection;
class nsIDOMHTMLOptionElement;
class nsIComboboxControlFrame;
class nsIViewManager;
class nsIPresContext;
1999-01-18 18:14:00 +03:00
/**
* Frame-based listbox.
1999-01-18 18:14:00 +03:00
*/
1999-01-18 18:14:00 +03:00
class nsListControlFrame : public nsScrollFrame,
public nsIFormControlFrame,
public nsIListControlFrame,
public nsIDOMMouseListener,
public nsIDOMMouseMotionListener,
public nsIDOMKeyListener,
public nsISelectControlFrame,
public nsIStatefulFrame
1999-01-18 18:14:00 +03:00
{
public:
friend nsresult NS_NewListControlFrame(nsIFrame** aNewFrame);
1999-01-18 18:14:00 +03:00
// nsISupports
NS_IMETHOD QueryInterface(const nsIID& aIID, void** aInstancePtr);
1999-01-18 18:14:00 +03:00
// nsIFrame
NS_IMETHOD HandleEvent(nsIPresContext& aPresContext,
nsGUIEvent* aEvent,
nsEventStatus& aEventStatus);
1999-01-18 18:14:00 +03:00
NS_IMETHOD SetInitialChildList(nsIPresContext& aPresContext,
nsIAtom* aListName,
nsIFrame* aChildList);
1999-01-18 18:14:00 +03:00
NS_IMETHOD Reflow(nsIPresContext& aCX,
nsHTMLReflowMetrics& aDesiredSize,
const nsHTMLReflowState& aReflowState,
nsReflowStatus& aStatus);
NS_IMETHOD Init(nsIPresContext& aPresContext,
1999-01-18 18:14:00 +03:00
nsIContent* aContent,
nsIFrame* aParent,
nsIStyleContext* aContext,
nsIFrame* aPrevInFlow);
1999-01-18 18:14:00 +03:00
NS_IMETHOD DidReflow(nsIPresContext& aPresContext, nsDidReflowStatus aStatus);
NS_IMETHOD MoveTo(nsIPresContext* aPresContext, nscoord aX, nscoord aY);
1999-01-18 18:14:00 +03:00
// nsIFormControlFrame
NS_IMETHOD GetType(PRInt32* aType) const;
NS_IMETHOD GetName(nsString* aName);
NS_IMETHOD SetProperty(nsIPresContext* aPresContext, nsIAtom* aName, const nsString& aValue);
NS_IMETHOD GetProperty(nsIAtom* aName, nsString& aValue);
NS_IMETHOD GetMultiple(PRBool* aResult, nsIDOMHTMLSelectElement* aSelect = nsnull);
1999-01-18 18:14:00 +03:00
NS_IMETHOD GetFont(nsIPresContext* aPresContext,
nsFont& aFont);
NS_IMETHOD GetFormContent(nsIContent*& aContent) const;
virtual void SetFocus(PRBool aOn = PR_TRUE, PRBool aRepaint = PR_FALSE);
virtual void ScrollIntoView(nsIPresContext* aPresContext);
1999-01-18 18:14:00 +03:00
virtual void MouseClicked(nsIPresContext* aPresContext);
virtual void Reset(nsIPresContext* aPresContext);
1999-01-18 18:14:00 +03:00
virtual PRBool IsSuccessful(nsIFormControlFrame* aSubmitter);
virtual PRInt32 GetMaxNumValues();
virtual PRBool GetNamesValues(PRInt32 aMaxNumValues, PRInt32& aNumValues,
nsString* aValues, nsString* aNames);
virtual void SetFormFrame(nsFormFrame* aFrame);
virtual nscoord GetVerticalInsidePadding(nsIPresContext& aPresContext,
float aPixToTwip,
nscoord aInnerHeight) const;
virtual nscoord GetHorizontalInsidePadding(nsIPresContext& aPresContext,
float aPixToTwip,
nscoord aInnerWidth,
nscoord aCharWidth) const;
virtual nsresult RequiresWidget(PRBool &aRequiresWidget);
// nsHTMLContainerFrame
virtual PRIntn GetSkipSides() const;
// nsIListControlFrame
1999-01-18 18:14:00 +03:00
NS_IMETHOD SetComboboxFrame(nsIFrame* aComboboxFrame);
NS_IMETHOD GetSelectedIndex(PRInt32* aIndex);
1999-01-18 18:14:00 +03:00
NS_IMETHOD GetSelectedItem(nsString & aStr);
NS_IMETHOD CaptureMouseEvents(nsIPresContext* aPresContext, PRBool aGrabMouseEvents);
NS_IMETHOD GetMaximumSize(nsSize &aSize);
NS_IMETHOD SetSuggestedSize(nscoord aWidth, nscoord aHeight);
NS_IMETHOD GetNumberOfOptions(PRInt32* aNumOptions);
NS_IMETHOD SyncViewWithFrame(nsIPresContext* aPresContext);
NS_IMETHOD AboutToDropDown();
NS_IMETHOD AboutToRollup();
NS_IMETHOD UpdateSelection(PRBool aDoDispatchEvent, PRBool aForceUpdate, nsIContent* aContent);
1999-01-18 18:14:00 +03:00
// nsISelectControlFrame
NS_IMETHOD AddOption(nsIPresContext* aPresContext, PRInt32 index);
NS_IMETHOD RemoveOption(nsIPresContext* aPresContext, PRInt32 index);
NS_IMETHOD SetOptionSelected(PRInt32 aIndex, PRBool aValue);
NS_IMETHOD GetOptionSelected(PRInt32 aIndex, PRBool* aValue);
//nsIStatefulFrame
NS_IMETHOD GetStateType(nsIPresContext* aPresContext, nsIStatefulFrame::StateType* aStateType);
NS_IMETHOD SaveState(nsIPresContext* aPresContext, nsISupports** aState);
NS_IMETHOD RestoreState(nsIPresContext* aPresContext, nsISupports* aState);
//nsIDOMEventListener
virtual nsresult MouseDown(nsIDOMEvent* aMouseEvent);
virtual nsresult MouseUp(nsIDOMEvent* aMouseEvent);
virtual nsresult MouseClick(nsIDOMEvent* aMouseEvent) { return NS_OK; }
virtual nsresult MouseDblClick(nsIDOMEvent* aMouseEvent) { return NS_OK; }
virtual nsresult MouseOver(nsIDOMEvent* aMouseEvent) { return NS_OK; }
virtual nsresult MouseOut(nsIDOMEvent* aMouseEvent) { return NS_OK; }
virtual nsresult HandleEvent(nsIDOMEvent* aEvent) { return NS_OK; }
//nsIDOMEventMotionListener
virtual nsresult MouseMove(nsIDOMEvent* aMouseEvent);
virtual nsresult DragMove(nsIDOMEvent* aMouseEvent) { return NS_OK; }
//nsIDOMKeyListener
virtual nsresult KeyDown(nsIDOMEvent* aKeyEvent);
virtual nsresult KeyUp(nsIDOMEvent* aKeyEvent) { return NS_OK; }
virtual nsresult KeyPress(nsIDOMEvent* aKeyEvent);
// Static Methods
1999-01-18 18:14:00 +03:00
static nsIDOMHTMLSelectElement* GetSelect(nsIContent * aContent);
static nsIDOMHTMLCollection* GetOptions(nsIContent * aContent, nsIDOMHTMLSelectElement* aSelect = nsnull);
static nsIDOMHTMLOptionElement* GetOption(nsIDOMHTMLCollection& aOptions, PRInt32 aIndex);
static nsIContent* GetOptionAsContent(nsIDOMHTMLCollection* aCollection,PRInt32 aIndex);
static PRBool GetOptionValue(nsIDOMHTMLCollection& aCollecton, PRInt32 aIndex, nsString& aValue);
1999-01-18 18:14:00 +03:00
protected:
NS_IMETHOD GetSelectedIndexFromDOM(PRInt32* aIndex); // from DOM
NS_IMETHOD IsTargetOptionDisabled(PRBool &aIsDisabled);
nsresult CountAllChild(nsIDOMNode * aNode, PRInt32& aCount);
1999-01-18 18:14:00 +03:00
nsListControlFrame();
virtual ~nsListControlFrame();
// nsScrollFrame overrides
// Override the widget created for the list box so a Borderless top level widget is created
// for drop-down lists.
virtual nsresult CreateScrollingViewWidget(nsIView* aView,const nsStylePosition* aPosition);
virtual nsresult GetScrollingParentView(nsIPresContext* aPresContext,
nsIFrame* aParent,
nsIView** aParentView);
PRInt32 GetNumberOfOptions();
1999-01-18 18:14:00 +03:00
// Utility methods
nsresult GetSizeAttribute(PRInt32 *aSize);
PRInt32 GetNumberOfSelections();
nsIContent* GetOptionFromContent(nsIContent *aContent);
nsresult GetIndexFromDOMEvent(nsIDOMEvent* aMouseEvent, PRInt32& aOldIndex, PRInt32& aCurIndex);
PRInt32 GetSelectedIndexFromContent(nsIContent *aContent);
nsIContent* GetOptionContent(PRInt32 aIndex);
PRBool IsContentSelected(nsIContent* aContent);
PRBool IsContentSelectedByIndex(PRInt32 aIndex);
void SetContentSelected(PRInt32 aIndex, PRBool aSelected);
void GetViewOffset(nsIViewManager* aManager, nsIView* aView, nsPoint& aPoint);
nsresult Deselect();
nsIFrame *GetOptionFromChild(nsIFrame* aParentFrame);
PRBool IsAncestor(nsIView* aAncestor, nsIView* aChild);
nsIView* GetViewFor(nsIWidget* aWidget);
PRBool IsInDropDownMode();
PRBool IsOptionElement(nsIContent* aContent);
PRBool IsOptionElementFrame(nsIFrame *aFrame);
nsIFrame *GetSelectableFrame(nsIFrame *aFrame);
void DisplaySelected(nsIContent* aContent);
void DisplayDeselected(nsIContent* aContent);
void ForceRedraw(nsIPresContext* aPresContext);
PRBool IsOptionGroup(nsIFrame* aFrame);
void SingleSelection();
void MultipleSelection(PRBool aIsShift, PRBool aIsControl);
void SelectIndex(PRInt32 aIndex);
void ToggleSelected(PRInt32 aIndex);
void ClearSelection();
void ExtendedSelection(PRInt32 aStartIndex, PRInt32 aEndIndex, PRBool aDoInvert, PRBool aSetValue);
void ResetSelectedItem();
PRBool HasSameContent(nsIFrame* aFrame1, nsIFrame* aFrame2);
void HandleListSelection(nsIDOMEvent * aDOMEvent);
PRInt32 GetSelectedIndexFromFrame(nsIFrame *aHitFrame);
// onChange detection
nsresult InitSelectionCache(PRInt32 aLength);
nsresult SelectionChanged(nsIContent* aContent);
1999-01-18 18:14:00 +03:00
// Data Members
nscoord mBorderOffsetY;
1999-01-18 18:14:00 +03:00
nsFormFrame* mFormFrame;
PRInt32 mSelectedIndex;
PRInt32 mOldSelectedIndex;
PRInt32 mSelectedIndexWhenPoppedDown;
1999-01-18 18:14:00 +03:00
PRInt32 mStartExtendedIndex;
PRInt32 mEndExtendedIndex;
nsIFrame* mHitFrame;
1999-01-18 18:14:00 +03:00
PRBool mIsInitializedFromContent;
nsIFrame* mContentFrame;
nsIComboboxControlFrame *mComboboxFrame;
PRBool mDisplayed;
PRBool mButtonDown;
nsIFrame* mLastFrame;
nscoord mMaxWidth;
nscoord mMaxHeight;
PRBool mIsCapturingMouseEvents;
PRBool mIgnoreMouseUp;
PRBool* mSelectionCache;
PRInt32 mSelectionCacheLength;
nsIPresContext* mPresContext; // XXX: Remove the need to cache the pres context.
1999-07-29 01:38:08 +04:00
// XXX temprary only until full system mouse capture works
PRBool mIsScrollbarVisible;
private:
NS_IMETHOD_(nsrefcnt) AddRef() { return NS_OK; }
NS_IMETHOD_(nsrefcnt) Release() { return NS_OK; }
1999-01-18 18:14:00 +03:00
};
#endif /* nsListControlFrame_h___ */