1999-01-18 15:14:00 +00: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.0 (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/
|
|
|
|
*
|
|
|
|
* 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.
|
|
|
|
*
|
|
|
|
* 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.
|
|
|
|
*/
|
1999-02-12 17:45:58 +00:00
|
|
|
#include "nsCOMPtr.h"
|
1999-01-18 15:14:00 +00:00
|
|
|
#include "nsListControlFrame.h"
|
|
|
|
#include "nsFormControlHelper.h"
|
|
|
|
#include "nsFormControlFrame.h"
|
|
|
|
#include "nsBlockReflowContext.h"
|
|
|
|
#include "nsBlockBandData.h"
|
|
|
|
#include "nsBulletFrame.h"
|
|
|
|
|
|
|
|
#include "nsPlaceholderFrame.h"
|
|
|
|
#include "nsStyleConsts.h"
|
|
|
|
#include "nsHTMLIIDs.h"
|
|
|
|
#include "nsCSSRendering.h"
|
|
|
|
#include "nsIPresContext.h"
|
|
|
|
#include "nsIPresShell.h"
|
|
|
|
#include "nsIReflowCommand.h"
|
|
|
|
#include "nsISpaceManager.h"
|
|
|
|
#include "nsIStyleContext.h"
|
|
|
|
#include "nsIView.h"
|
|
|
|
#include "nsIFontMetrics.h"
|
|
|
|
#include "nsHTMLParts.h"
|
|
|
|
#include "nsHTMLAtoms.h"
|
|
|
|
#include "nsHTMLValue.h"
|
|
|
|
#include "nsDOMEvent.h"
|
|
|
|
#include "nsIHTMLContent.h"
|
|
|
|
#include "prprf.h"
|
|
|
|
#include "nsLayoutAtoms.h"
|
|
|
|
|
|
|
|
#include "nsIFormControl.h"
|
|
|
|
#include "nsStyleUtil.h"
|
|
|
|
#include "nsINameSpaceManager.h"
|
1999-03-22 21:32:12 +00:00
|
|
|
#include "nsIDeviceContext.h"
|
|
|
|
#include "nsIHTMLContent.h"
|
|
|
|
#include "nsIDOMHTMLCollection.h"
|
|
|
|
#include "nsIDOMHTMLSelectElement.h"
|
|
|
|
#include "nsIDOMHTMLOptionElement.h"
|
|
|
|
#include "nsIDOMNode.h"
|
|
|
|
#include "nsHTMLAtoms.h"
|
|
|
|
#include "nsIAtom.h"
|
1999-01-18 15:14:00 +00:00
|
|
|
#include "nsIDOMEventReceiver.h"
|
|
|
|
#include "nsIComboboxControlFrame.h"
|
|
|
|
#include "nsComboboxControlFrame.h" // for the static helper function
|
|
|
|
#include "nsIListControlFrame.h"
|
|
|
|
#include "nsIViewManager.h"
|
|
|
|
#include "nsFormFrame.h"
|
1999-03-22 21:32:12 +00:00
|
|
|
#include "nsIScrollableView.h"
|
1999-05-07 20:30:16 +00:00
|
|
|
#include "nsVoidArray.h"
|
|
|
|
#include "nsIDOMHTMLOptGroupElement.h"
|
|
|
|
|
|
|
|
|
1999-01-18 15:14:00 +00:00
|
|
|
|
|
|
|
// Constants
|
|
|
|
const char * kNormal = "";
|
|
|
|
const char * kSelected = "SELECTED";
|
|
|
|
const char * kSelectedFocus = "SELECTEDFOCUS";
|
1999-05-07 20:30:16 +00:00
|
|
|
const nscoord kMaxDropDownRows = 3;
|
|
|
|
const PRInt32 kNothingSelected = -1;
|
|
|
|
|
1999-04-12 22:14:31 +00:00
|
|
|
//XXX: This is temporary. It simulates psuedo states by using a attribute selector on
|
|
|
|
// -moz-option-selected in the ua.css style sheet. This will not be needed when
|
|
|
|
//The event state manager is functional. KMM
|
1999-03-02 22:43:26 +00:00
|
|
|
const char * kMozSelected = "-moz-option-selected";
|
|
|
|
|
1999-03-22 21:32:12 +00:00
|
|
|
static NS_DEFINE_IID(kIContentIID, NS_ICONTENT_IID);
|
|
|
|
static NS_DEFINE_IID(kIFormControlFrameIID, NS_IFORMCONTROLFRAME_IID);
|
|
|
|
static NS_DEFINE_IID(kIScrollableViewIID, NS_ISCROLLABLEVIEW_IID);
|
|
|
|
static NS_DEFINE_IID(kIListControlFrameIID, NS_ILISTCONTROLFRAME_IID);
|
|
|
|
static NS_DEFINE_IID(kIDOMHTMLSelectElementIID, NS_IDOMHTMLSELECTELEMENT_IID);
|
|
|
|
static NS_DEFINE_IID(kIDOMHTMLOptionElementIID, NS_IDOMHTMLOPTIONELEMENT_IID);
|
|
|
|
static NS_DEFINE_IID(kIDOMNodeIID, NS_IDOMNODE_IID);
|
|
|
|
static NS_DEFINE_IID(kIDOMElementIID, NS_IDOMELEMENT_IID);
|
1999-05-07 20:30:16 +00:00
|
|
|
static NS_DEFINE_IID(kIFrameIID, NS_IFRAME_IID);
|
|
|
|
static NS_DEFINE_IID(kIDOMHTMLOptGroupElementIID, NS_IDOMHTMLOPTGROUPELEMENT_IID);
|
1999-01-18 15:14:00 +00:00
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
|
|
|
|
nsresult
|
1999-05-11 22:03:29 +00:00
|
|
|
NS_NewListControlFrame(nsIFrame** aNewFrame)
|
1999-01-18 15:14:00 +00:00
|
|
|
{
|
1999-05-11 22:03:29 +00:00
|
|
|
NS_PRECONDITION(aNewFrame, "null OUT ptr");
|
|
|
|
if (nsnull == aNewFrame) {
|
|
|
|
return NS_ERROR_NULL_POINTER;
|
|
|
|
}
|
1999-01-18 15:14:00 +00:00
|
|
|
nsListControlFrame* it = new nsListControlFrame;
|
1999-05-11 22:03:29 +00:00
|
|
|
if (!it) {
|
1999-01-18 15:14:00 +00:00
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
}
|
1999-05-11 22:03:29 +00:00
|
|
|
*aNewFrame = it;
|
1999-01-18 15:14:00 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
nsListControlFrame::nsListControlFrame()
|
|
|
|
{
|
|
|
|
mHitFrame = nsnull;
|
|
|
|
mCurrentHitFrame = nsnull;
|
|
|
|
mSelectedContent = nsnull;
|
1999-05-07 20:30:16 +00:00
|
|
|
mSelectedIndex = kNothingSelected;
|
1999-01-18 15:14:00 +00:00
|
|
|
mNumRows = 0;
|
|
|
|
mIsInitializedFromContent = PR_FALSE;
|
|
|
|
mNumSelections = 0;
|
|
|
|
mInDropDownMode = PR_FALSE;
|
|
|
|
mComboboxFrame = nsnull;
|
1999-04-27 00:06:03 +00:00
|
|
|
mFormFrame = nsnull;
|
1999-05-07 20:30:16 +00:00
|
|
|
mSelectableFrames = new nsVoidArray;
|
1999-01-18 15:14:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
nsListControlFrame::~nsListControlFrame()
|
|
|
|
{
|
1999-05-07 20:30:16 +00:00
|
|
|
mComboboxFrame = nsnull;
|
1999-04-27 00:06:03 +00:00
|
|
|
mFormFrame = nsnull;
|
1999-05-07 20:30:16 +00:00
|
|
|
delete mSelectableFrames;
|
|
|
|
mSelectableFrames = nsnull;
|
1999-01-18 15:14:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
NS_IMPL_ADDREF(nsListControlFrame)
|
|
|
|
NS_IMPL_RELEASE(nsListControlFrame)
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsListControlFrame::QueryInterface(const nsIID& aIID, void** aInstancePtr)
|
|
|
|
{
|
|
|
|
if (NULL == aInstancePtr) {
|
|
|
|
return NS_ERROR_NULL_POINTER;
|
|
|
|
}
|
|
|
|
if (aIID.Equals(kIFormControlFrameIID)) {
|
|
|
|
*aInstancePtr = (void*) ((nsIFormControlFrame*) this);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
if (aIID.Equals(kIListControlFrameIID)) {
|
|
|
|
NS_ADDREF_THIS(); // Increase reference count for caller
|
|
|
|
*aInstancePtr = (void *)((nsIListControlFrame*)this);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
1999-03-22 21:32:12 +00:00
|
|
|
|
1999-01-18 15:14:00 +00:00
|
|
|
return nsScrollFrame::QueryInterface(aIID, aInstancePtr);
|
|
|
|
}
|
|
|
|
|
1999-05-07 20:30:16 +00:00
|
|
|
PRBool nsListControlFrame::IsOptionGroup(nsIFrame* aFrame)
|
|
|
|
{
|
|
|
|
PRBool result = PR_FALSE;
|
|
|
|
nsIContent*content = nsnull;
|
|
|
|
aFrame->GetContent(&content);
|
|
|
|
nsIDOMHTMLOptGroupElement* og = nsnull;
|
|
|
|
if (content && (NS_OK == content->QueryInterface(kIDOMHTMLOptGroupElementIID, (void**) &og))) {
|
|
|
|
if (og != nsnull) {
|
|
|
|
result = PR_TRUE;
|
|
|
|
NS_RELEASE(og);
|
|
|
|
}
|
|
|
|
NS_RELEASE(content);
|
|
|
|
}
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
void nsListControlFrame::ConstructSelectableList(nsIFrame* aFrame, nsVoidArray* aList)
|
|
|
|
{
|
|
|
|
nsIFrame* kid = nsnull;
|
|
|
|
aFrame->FirstChild(nsnull, &kid);
|
|
|
|
while (nsnull != kid) {
|
|
|
|
if (IsOptionGroup(kid)) {
|
|
|
|
ConstructSelectableList(kid, aList);
|
|
|
|
} else {
|
|
|
|
aList->AppendElement(kid);
|
|
|
|
kid->GetNextSibling(&kid);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
nsIFrame* nsListControlFrame::GetFirstSelectableFrame(nsVoidArray *aList, PRInt32& aPos)
|
|
|
|
{
|
|
|
|
aPos = 1;
|
|
|
|
return((nsIFrame*)aList->ElementAt(0));
|
|
|
|
}
|
|
|
|
|
|
|
|
nsIFrame* nsListControlFrame::GetNextSelectableFrame(nsVoidArray *aList, PRInt32& aPos)
|
|
|
|
{
|
|
|
|
return((nsIFrame*)aList->ElementAt(aPos++));
|
|
|
|
}
|
|
|
|
|
1999-01-18 15:14:00 +00:00
|
|
|
|
1999-05-13 23:45:40 +00:00
|
|
|
|
|
|
|
|
1999-01-18 15:14:00 +00:00
|
|
|
//----------------------------------------------------------------------
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsListControlFrame::GetFrameForPoint(const nsPoint& aPoint, nsIFrame** aFrame)
|
|
|
|
{
|
1999-04-12 22:14:31 +00:00
|
|
|
// Save the result of GetFrameForPointUsing in the mHitFrame member variable.
|
|
|
|
// mHitFrame is used later in the HandleLikeListEvent to determine what was clicked on.
|
|
|
|
// XXX: This is kludgy, but there doesn't seem to be a way to get what was just clicked
|
|
|
|
// on in the HandleEvent. The GetFrameForPointUsing is always called before the HandleEvent.
|
|
|
|
//
|
1999-03-22 21:32:12 +00:00
|
|
|
nsresult rv;
|
|
|
|
|
|
|
|
nsIFrame *childFrame;
|
|
|
|
FirstChild(nsnull, &childFrame);
|
|
|
|
rv = GetFrameForPointUsing(aPoint, nsnull, aFrame);
|
1999-01-18 15:14:00 +00:00
|
|
|
if (NS_OK == rv) {
|
|
|
|
if (*aFrame != this) {
|
1999-05-13 23:45:40 +00:00
|
|
|
*aFrame = GetSelectableFrame(*aFrame);
|
|
|
|
if (nsnull == *aFrame) {
|
|
|
|
mHitFrame = this;
|
|
|
|
} else {
|
|
|
|
mHitFrame = *aFrame;
|
|
|
|
}
|
1999-01-18 15:14:00 +00:00
|
|
|
*aFrame = this;
|
|
|
|
}
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
*aFrame = this;
|
|
|
|
return NS_ERROR_FAILURE;
|
1999-03-22 21:32:12 +00:00
|
|
|
|
1999-01-18 15:14:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
nsresult
|
|
|
|
nsListControlFrame::GetFrameForPointUsing(const nsPoint& aPoint,
|
|
|
|
nsIAtom* aList,
|
|
|
|
nsIFrame** aFrame)
|
|
|
|
{
|
1999-03-22 21:32:12 +00:00
|
|
|
nsIFrame* kid = nsnull;
|
1999-01-18 15:14:00 +00:00
|
|
|
nsRect kidRect;
|
|
|
|
nsPoint tmp;
|
1999-03-22 21:32:12 +00:00
|
|
|
nsRect offset(0, 0, 0, 0);
|
1999-01-18 15:14:00 +00:00
|
|
|
*aFrame = nsnull;
|
1999-03-22 21:32:12 +00:00
|
|
|
nsIFrame* firstKid = nsnull;
|
|
|
|
|
|
|
|
|
|
|
|
// Get the scrolled offset from the view.
|
|
|
|
//
|
1999-04-12 22:14:31 +00:00
|
|
|
// XXX:Hack. This should not be necessary. It is only required because we interpose on the
|
|
|
|
// normal event flow by redirecting to the listbox using the SetVFlags(NS_DONT_CHECK_CHILDREN).
|
|
|
|
// What we should really do is have a manager which the option items report there events to.
|
|
|
|
// The listbox frame would be the manager for the option items. KMM.
|
|
|
|
//
|
|
|
|
//
|
1999-03-22 21:32:12 +00:00
|
|
|
// This is needed because:
|
|
|
|
// The scrolled view is below the nsListControlFrame's ScrollingView in
|
|
|
|
// the view hierarchy. This presents a problem for event translation when the events
|
|
|
|
// are re-directed with the nsView::SetVFlags(NS_DONT_CHECK_CHILDREN). Since
|
|
|
|
// the handling of the view event is short-circuited at the nsListControlFrame's
|
|
|
|
// scrolling view level mouse click events do not have the scolled offset added to them.
|
|
|
|
// The view containing the offset is below the nsListControlFrame's scrolling
|
|
|
|
// view, so the short-circuiting of the event processing provided by nsView:SetVFlags(NS_DONT_CHECK_CHILDREN)
|
|
|
|
// prevents the scrolled view's offset from ever being added to the event's offset.
|
|
|
|
// When nsListControlFrame::GetFrameForPoint is invoked the nsPoint passed in does not include the scrolled view offset,
|
|
|
|
// so the frame returned will always be wrong when the listbox is scrolled.
|
|
|
|
// As a hack we adjust for missing view offset by adding code to the nsListControlFrame::GetFrameForPoint which first
|
|
|
|
// gets the ScrollableView associated with the nsListControlFrame and asks for it's GetScrollPosition offsets. These are
|
|
|
|
// added to the point that is passed in so the correct frame is returned from nsListControlFrame::GetFrameForPoint.
|
1999-05-07 20:30:16 +00:00
|
|
|
|
|
|
|
tmp.MoveTo(aPoint.x, aPoint.y);
|
1999-03-22 21:32:12 +00:00
|
|
|
nsIView *view = nsnull;
|
|
|
|
GetView(&view);
|
|
|
|
if (nsnull != view) {
|
|
|
|
nscoord offsetx;
|
|
|
|
nscoord offsety;
|
|
|
|
nsIScrollableView* scrollableView;
|
|
|
|
if (NS_SUCCEEDED(view->QueryInterface(kIScrollableViewIID, (void **)&scrollableView))) {
|
|
|
|
scrollableView->GetScrollPosition(offsetx, offsety);
|
1999-05-07 20:30:16 +00:00
|
|
|
tmp.x += offsetx;
|
|
|
|
tmp.y += offsety;
|
1999-03-22 21:32:12 +00:00
|
|
|
// Note: scrollableView is not ref counted so it's interface is not NS_RELEASE'd
|
|
|
|
}
|
|
|
|
}
|
1999-05-07 20:30:16 +00:00
|
|
|
|
|
|
|
#ifdef NS_OPTGROUPSUPPORT
|
|
|
|
nsIFrame* selectedFrame = nsnull;
|
|
|
|
nsresult rv = nsScrollFrame::GetFrameForPoint(tmp, &selectedFrame);
|
|
|
|
|
|
|
|
|
|
|
|
// Walk up the frames looking for a selectable frame.
|
|
|
|
// A selectable frame is defined as a frame sitting under the ScrollArea's
|
|
|
|
// Area Frame or the first optiongroup ancestor.
|
|
|
|
|
|
|
|
if (nsnull != selectedFrame) {
|
|
|
|
PRBool done = PR_FALSE;
|
|
|
|
while (! done) {
|
|
|
|
nsIFrame* parent = nsnull;
|
|
|
|
selectedFrame->GetParent(&parent);
|
|
|
|
if (parent != nsnull) {
|
|
|
|
if ((parent == mContentFrame) || (IsOptionGroup(parent))) {
|
|
|
|
done = PR_TRUE;
|
|
|
|
} else {
|
|
|
|
// Continue looking at ancestors
|
|
|
|
selectedFrame = parent;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
// Parent is null so stop looking
|
|
|
|
done = PR_TRUE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
*aFrame = selectedFrame;
|
|
|
|
|
|
|
|
return rv;
|
|
|
|
|
|
|
|
#else
|
|
|
|
|
|
|
|
//XXX: Remove the following code when the code above works
|
|
|
|
|
|
|
|
// Remove the top border from the offset.
|
|
|
|
nsMargin border;
|
|
|
|
tmp.y -= mBorderOffsetY;
|
|
|
|
|
1999-02-10 02:25:01 +00:00
|
|
|
mContentFrame->FirstChild(aList, &kid);
|
1999-01-18 15:14:00 +00:00
|
|
|
while (nsnull != kid) {
|
|
|
|
kid->GetRect(kidRect);
|
1999-05-07 20:30:16 +00:00
|
|
|
if (kidRect.Contains(tmp)) {
|
|
|
|
tmp.MoveTo(tmp.x - kidRect.x, tmp.y - kidRect.y);
|
1999-01-18 15:14:00 +00:00
|
|
|
|
|
|
|
nsIContent * content;
|
1999-02-10 00:42:56 +00:00
|
|
|
kid->GetContent(&content);
|
1999-01-18 15:14:00 +00:00
|
|
|
static NS_DEFINE_IID(kIDOMHTMLOptionElementIID, NS_IDOMHTMLOPTIONELEMENT_IID);
|
|
|
|
nsIDOMHTMLOptionElement* oe;
|
|
|
|
if (content && (NS_OK == content->QueryInterface(kIDOMHTMLOptionElementIID, (void**) &oe))) {
|
|
|
|
*aFrame = kid;
|
|
|
|
NS_RELEASE(content);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
NS_RELEASE(content);
|
|
|
|
return kid->GetFrameForPoint(tmp, aFrame);
|
|
|
|
}
|
1999-02-10 06:13:38 +00:00
|
|
|
kid->GetNextSibling(&kid);
|
1999-01-18 15:14:00 +00:00
|
|
|
}
|
|
|
|
|
1999-02-10 02:25:01 +00:00
|
|
|
mContentFrame->FirstChild(aList, &kid);
|
1999-01-18 15:14:00 +00:00
|
|
|
while (nsnull != kid) {
|
|
|
|
nsFrameState state;
|
1999-02-10 04:17:06 +00:00
|
|
|
kid->GetFrameState(&state);
|
1999-01-18 15:14:00 +00:00
|
|
|
if (NS_FRAME_OUTSIDE_CHILDREN & state) {
|
|
|
|
kid->GetRect(kidRect);
|
1999-05-07 20:30:16 +00:00
|
|
|
tmp.MoveTo(tmp.x - kidRect.x, tmp.y - kidRect.y);
|
1999-01-18 15:14:00 +00:00
|
|
|
if (NS_OK == kid->GetFrameForPoint(tmp, aFrame)) {
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
}
|
1999-02-10 06:13:38 +00:00
|
|
|
kid->GetNextSibling(&kid);
|
1999-01-18 15:14:00 +00:00
|
|
|
}
|
|
|
|
*aFrame = this;
|
|
|
|
return NS_ERROR_FAILURE;
|
1999-05-07 20:30:16 +00:00
|
|
|
#endif
|
1999-01-18 15:14:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
1999-03-22 21:32:12 +00:00
|
|
|
// Reflow is overriden to constrain the listbox height to the number of rows and columns
|
|
|
|
// specified.
|
|
|
|
//
|
1999-01-18 15:14:00 +00:00
|
|
|
NS_IMETHODIMP
|
1999-03-22 21:32:12 +00:00
|
|
|
nsListControlFrame::Reflow(nsIPresContext& aPresContext,
|
1999-01-18 15:14:00 +00:00
|
|
|
nsHTMLReflowMetrics& aDesiredSize,
|
|
|
|
const nsHTMLReflowState& aReflowState,
|
|
|
|
nsReflowStatus& aStatus)
|
|
|
|
{
|
1999-03-22 21:32:12 +00:00
|
|
|
// Strategy: Let the inherited reflow happen as though the width and height of the
|
|
|
|
// ScrollFrame are big enough to allow the listbox to
|
|
|
|
// shrink to fit the longest option element line in the list.
|
|
|
|
// The desired width and height returned by the inherited reflow is returned,
|
|
|
|
// unless one of the following has been specified.
|
|
|
|
// 1. A css width has been specified.
|
|
|
|
// 2. The size has been specified.
|
|
|
|
// 3. The css height has been specified, but the number of rows has not.
|
|
|
|
// The size attribute overrides the height setting but the height setting
|
|
|
|
// should be honored if there isn't a size specified.
|
|
|
|
|
|
|
|
// Determine the desired width + height for the listbox +
|
1999-01-18 15:14:00 +00:00
|
|
|
aDesiredSize.width = 0;
|
|
|
|
aDesiredSize.height = 0;
|
|
|
|
|
1999-03-22 21:32:12 +00:00
|
|
|
// Initialize the current selected and not selected state's for
|
|
|
|
// the listbox items from the content
|
|
|
|
if (!mIsInitializedFromContent) {
|
|
|
|
mIsInitializedFromContent = PR_TRUE;
|
|
|
|
InitializeFromContent(PR_TRUE);
|
1999-01-18 15:14:00 +00:00
|
|
|
}
|
1999-03-22 21:32:12 +00:00
|
|
|
|
|
|
|
|
|
|
|
//--Calculate a width just big enough for the scrollframe to shrink around the
|
|
|
|
//longest element in the list
|
1999-05-07 20:30:16 +00:00
|
|
|
nsHTMLReflowState secondPassState(aReflowState);
|
|
|
|
nsHTMLReflowState firstPassState(aReflowState);
|
|
|
|
|
|
|
|
// Get the size of option elements inside the listbox
|
1999-03-22 21:32:12 +00:00
|
|
|
// Compute the width based on the longest line in the listbox.
|
|
|
|
|
1999-05-07 20:30:16 +00:00
|
|
|
firstPassState.computedWidth = NS_UNCONSTRAINEDSIZE;
|
|
|
|
firstPassState.computedHeight = NS_UNCONSTRAINEDSIZE;
|
|
|
|
firstPassState.availableWidth = NS_UNCONSTRAINEDSIZE;
|
|
|
|
firstPassState.availableHeight = NS_UNCONSTRAINEDSIZE;
|
1999-04-12 22:14:31 +00:00
|
|
|
|
1999-05-07 20:30:16 +00:00
|
|
|
|
|
|
|
nsSize scrolledAreaSize(0,0);
|
|
|
|
nsHTMLReflowMetrics scrolledAreaDesiredSize(&scrolledAreaSize);
|
|
|
|
nsScrollFrame::Reflow(aPresContext,
|
|
|
|
scrolledAreaDesiredSize,
|
|
|
|
firstPassState,
|
|
|
|
aStatus);
|
|
|
|
|
|
|
|
// Compute the bounding box of the contents of the list using the area
|
|
|
|
// calculated by the first reflow as a starting point.
|
|
|
|
|
|
|
|
nscoord scrolledAreaWidth = scrolledAreaDesiredSize.maxElementSize->width;
|
|
|
|
nscoord scrolledAreaHeight = scrolledAreaDesiredSize.height;
|
|
|
|
|
|
|
|
// The first reflow produces a box with the scrollbar width and borders
|
|
|
|
// added in so we need to subtract them out.
|
|
|
|
|
|
|
|
// Retrieve the scrollbar's width and height
|
1999-03-22 21:32:12 +00:00
|
|
|
float sbWidth = 0.0;
|
|
|
|
float sbHeight = 0.0;;
|
|
|
|
nsCOMPtr<nsIDeviceContext> dc;
|
|
|
|
aPresContext.GetDeviceContext(getter_AddRefs(dc));
|
|
|
|
dc->GetScrollBarDimensions(sbWidth, sbHeight);
|
|
|
|
// Convert to nscoord's by rounding
|
|
|
|
nscoord scrollbarWidth = NSToCoordRound(sbWidth);
|
|
|
|
nscoord scrollbarHeight = NSToCoordRound(sbHeight);
|
|
|
|
|
1999-05-07 20:30:16 +00:00
|
|
|
// Subtract out the scrollbar width
|
|
|
|
scrolledAreaWidth -= scrollbarWidth;
|
1999-04-12 22:14:31 +00:00
|
|
|
|
1999-05-07 20:30:16 +00:00
|
|
|
// Subtract out the borders
|
|
|
|
nsMargin border;
|
|
|
|
if (!aReflowState.mStyleSpacing->GetBorder(border)) {
|
|
|
|
border.SizeTo(0, 0, 0, 0);
|
|
|
|
}
|
|
|
|
//XXX: Should just get the border.top when needed instead of
|
|
|
|
//caching it.
|
|
|
|
mBorderOffsetY = border.top;
|
1999-03-22 21:32:12 +00:00
|
|
|
|
1999-05-07 20:30:16 +00:00
|
|
|
scrolledAreaWidth -= (border.left + border.right);
|
|
|
|
scrolledAreaHeight -= (border.top + border.bottom);
|
1999-03-22 21:32:12 +00:00
|
|
|
|
1999-05-07 20:30:16 +00:00
|
|
|
// Now the scrolledAreaWidth and scrolledAreaHeight are exactly
|
|
|
|
// wide and high enough to enclose their contents
|
1999-04-16 19:28:12 +00:00
|
|
|
|
1999-05-07 20:30:16 +00:00
|
|
|
nscoord visibleWidth = 0;
|
1999-04-16 19:28:12 +00:00
|
|
|
if (mInDropDownMode) {
|
1999-05-07 20:30:16 +00:00
|
|
|
// Always set the width to be
|
|
|
|
// XXX: TODO The width of the list should be passed in so it can
|
|
|
|
// be set to the same as the text box + dropdown arrow.
|
|
|
|
visibleWidth = scrolledAreaWidth;
|
|
|
|
if (nsnull != mComboboxFrame) {
|
|
|
|
nsRect comboRect;
|
|
|
|
nsIFrame *comboFrame = nsnull;
|
|
|
|
if (NS_SUCCEEDED(mComboboxFrame->QueryInterface(kIFrameIID, (void **)&comboFrame))) {
|
|
|
|
comboFrame->GetRect(comboRect);
|
|
|
|
visibleWidth = comboRect.width;
|
|
|
|
visibleWidth -= (border.left + border.right);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
} else {
|
|
|
|
if (NS_UNCONSTRAINEDSIZE == aReflowState.computedWidth) {
|
|
|
|
visibleWidth = scrolledAreaWidth;
|
|
|
|
} else {
|
|
|
|
visibleWidth = aReflowState.computedWidth;
|
1999-04-16 19:28:12 +00:00
|
|
|
}
|
|
|
|
}
|
1999-05-07 20:30:16 +00:00
|
|
|
|
|
|
|
// Determine if a scrollbar will be needed, If so we need to add
|
|
|
|
// enough the width to allow for the scrollbar.
|
|
|
|
// The scrollbar will be needed under two conditions:
|
|
|
|
// (size * heightOfaRow) < scrolledAreaHeight or
|
|
|
|
// the height set through Style < scrolledAreaHeight.
|
|
|
|
|
|
|
|
// Calculate the height of a row.
|
|
|
|
// XXX: Fix this for optgroup's.
|
|
|
|
nsIFrame* childFrame = nsnull;
|
|
|
|
mContentFrame->FirstChild(nsnull, &childFrame);
|
|
|
|
PRInt32 numChildren = LengthOf(childFrame);
|
|
|
|
PRInt32 heightOfARow = scrolledAreaHeight / numChildren;
|
1999-03-22 21:32:12 +00:00
|
|
|
|
1999-05-07 20:30:16 +00:00
|
|
|
nscoord visibleHeight = 0;
|
|
|
|
if (mInDropDownMode) {
|
|
|
|
// Compute the visible height of the drop-down list
|
|
|
|
// The dropdown list height is the smaller of it's height setting or the height
|
|
|
|
// of the smallest box that can drawn around it's contents.
|
|
|
|
visibleHeight = scrolledAreaHeight;
|
1999-03-22 21:32:12 +00:00
|
|
|
|
1999-05-07 20:30:16 +00:00
|
|
|
if (visibleHeight > (kMaxDropDownRows * heightOfARow))
|
|
|
|
visibleHeight = (kMaxDropDownRows * heightOfARow);
|
|
|
|
|
|
|
|
} else {
|
|
|
|
// Calculate the visible height of the listbox
|
|
|
|
if (NS_UNCONSTRAINEDSIZE != aReflowState.computedHeight) {
|
|
|
|
visibleHeight = aReflowState.computedHeight;
|
|
|
|
} else {
|
|
|
|
if (numChildren == mNumRows) {
|
|
|
|
// Make sure scrollbars go away when the number of rows
|
|
|
|
// matchs the number of items to scroll.
|
|
|
|
visibleHeight = aReflowState.computedHeight;
|
|
|
|
} else {
|
|
|
|
visibleHeight = mNumRows * heightOfARow;
|
|
|
|
}
|
1999-04-16 19:28:12 +00:00
|
|
|
}
|
1999-03-22 21:32:12 +00:00
|
|
|
}
|
|
|
|
|
1999-05-07 20:30:16 +00:00
|
|
|
PRBool needsVerticalScrollbar = PR_FALSE;
|
|
|
|
if (visibleHeight < scrolledAreaHeight) {
|
|
|
|
needsVerticalScrollbar = PR_TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ((needsVerticalScrollbar) && (! mInDropDownMode)) {
|
|
|
|
visibleWidth += scrollbarWidth;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Do a second reflow with the adjusted width and height settings
|
|
|
|
// This sets up all of the frames with the correct width and height.
|
|
|
|
secondPassState.computedWidth = visibleWidth;
|
|
|
|
secondPassState.computedHeight = visibleHeight;
|
|
|
|
secondPassState.reason = eReflowReason_Resize;
|
|
|
|
nsScrollFrame::Reflow(aPresContext,
|
|
|
|
aDesiredSize,
|
|
|
|
secondPassState,
|
|
|
|
aStatus);
|
|
|
|
|
1999-03-22 21:32:12 +00:00
|
|
|
// Set the max element size to be the same as the desired element size.
|
1999-01-18 15:14:00 +00:00
|
|
|
if (nsnull != aDesiredSize.maxElementSize) {
|
|
|
|
aDesiredSize.maxElementSize->width = aDesiredSize.width;
|
|
|
|
aDesiredSize.maxElementSize->height = aDesiredSize.height;
|
|
|
|
}
|
|
|
|
|
1999-03-22 21:32:12 +00:00
|
|
|
aStatus = NS_FRAME_COMPLETE;
|
1999-04-12 22:14:31 +00:00
|
|
|
|
1999-01-18 15:14:00 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
nsIFrame *
|
|
|
|
nsListControlFrame::GetOptionFromChild(nsIFrame* aParentFrame)
|
|
|
|
{
|
|
|
|
|
|
|
|
nsIFrame* kid;
|
|
|
|
|
1999-02-10 02:25:01 +00:00
|
|
|
aParentFrame->FirstChild(nsnull, &kid);
|
1999-01-18 15:14:00 +00:00
|
|
|
while (nsnull != kid) {
|
|
|
|
nsIContent * content;
|
1999-02-10 00:42:56 +00:00
|
|
|
kid->GetContent(&content);
|
1999-01-18 15:14:00 +00:00
|
|
|
static NS_DEFINE_IID(kIDOMHTMLOptionElementIID, NS_IDOMHTMLOPTIONELEMENT_IID);
|
|
|
|
nsIDOMHTMLOptionElement* element;
|
|
|
|
if (content && (NS_OK == content->QueryInterface(kIDOMHTMLOptionElementIID, (void**) &element))) {
|
|
|
|
NS_RELEASE(content);
|
|
|
|
NS_RELEASE(element);
|
|
|
|
return kid;
|
|
|
|
}
|
|
|
|
NS_RELEASE(content);
|
|
|
|
nsIFrame * frame = GetOptionFromChild(kid);
|
|
|
|
if (nsnull != frame) {
|
|
|
|
return frame;
|
|
|
|
}
|
1999-02-10 06:13:38 +00:00
|
|
|
kid->GetNextSibling(&kid);
|
1999-01-18 15:14:00 +00:00
|
|
|
}
|
|
|
|
return nsnull;
|
|
|
|
}
|
|
|
|
|
1999-05-07 20:30:16 +00:00
|
|
|
|
1999-01-18 15:14:00 +00:00
|
|
|
//--------------------------------------------------------------
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsListControlFrame::GetFormContent(nsIContent*& aContent) const
|
|
|
|
{
|
1999-02-10 00:42:56 +00:00
|
|
|
nsIContent* content;
|
|
|
|
nsresult rv;
|
|
|
|
|
|
|
|
rv = GetContent(&content);
|
|
|
|
aContent = content;
|
|
|
|
return rv;
|
1999-01-18 15:14:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
//--------------------------------------------------------------
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsListControlFrame::GetFont(nsIPresContext* aPresContext,
|
|
|
|
nsFont& aFont)
|
|
|
|
{
|
|
|
|
nsFormControlHelper::GetFont(this, aPresContext, mStyleContext, aFont);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
1999-03-22 21:32:12 +00:00
|
|
|
|
1999-05-13 23:45:40 +00:00
|
|
|
PRBool nsListControlFrame::IsOptionElement(nsIContent* aContent)
|
|
|
|
{
|
|
|
|
PRBool result = PR_FALSE;
|
|
|
|
|
|
|
|
nsIDOMHTMLOptionElement* oe = nsnull;
|
|
|
|
if (NS_SUCCEEDED(aContent->QueryInterface(kIDOMHTMLOptionElementIID, (void**) &oe))) {
|
|
|
|
if (oe != nsnull) {
|
|
|
|
result = PR_TRUE;
|
|
|
|
NS_RELEASE(oe);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
PRBool nsListControlFrame::IsOptionElementFrame(nsIFrame *aFrame)
|
|
|
|
{
|
|
|
|
nsIContent *content = nsnull;
|
|
|
|
aFrame->GetContent(&content);
|
|
|
|
PRBool result = PR_FALSE;
|
|
|
|
if (nsnull != content) {
|
|
|
|
result = IsOptionElement(content);
|
|
|
|
NS_RELEASE(content);
|
|
|
|
}
|
|
|
|
return(result);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Go up the frame tree looking for the first ancestor that has content
|
|
|
|
// which is selectable
|
|
|
|
|
|
|
|
nsIFrame *nsListControlFrame::GetSelectableFrame(nsIFrame *aFrame)
|
|
|
|
{
|
|
|
|
nsIFrame* selectedFrame = aFrame;
|
|
|
|
|
|
|
|
while ((nsnull != selectedFrame) &&
|
|
|
|
(PR_FALSE ==IsOptionElementFrame(selectedFrame))) {
|
|
|
|
selectedFrame->GetParent(&selectedFrame);
|
|
|
|
}
|
|
|
|
|
|
|
|
return(selectedFrame);
|
|
|
|
}
|
|
|
|
|
1999-05-07 20:30:16 +00:00
|
|
|
void nsListControlFrame::ForceRedraw(nsIContent* aContent)
|
|
|
|
{
|
|
|
|
//XXX: Hack. This should not be needed. The problem is DisplaySelected
|
|
|
|
//and DisplayDeselected set and unset an attribute on generic HTML content
|
|
|
|
//which does not know that it should repaint as the result of the attribute
|
|
|
|
//being set. This should not be needed once the event state manager handles
|
|
|
|
//selection.
|
|
|
|
nsFormControlHelper::ForceDrawFrame(this);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
1999-03-22 21:32:12 +00:00
|
|
|
// XXX: Here we introduce a new -moz-option-selected attribute so a attribute
|
|
|
|
// selecitor n the ua.css can change the style when the option is selected.
|
|
|
|
|
|
|
|
void nsListControlFrame::DisplaySelected(nsIContent* aContent)
|
1999-01-18 15:14:00 +00:00
|
|
|
{
|
1999-04-12 22:14:31 +00:00
|
|
|
//XXX: This is temporary. It simulates psuedo states by using a attribute selector on
|
|
|
|
// -moz-option-selected in the ua.css style sheet. This will not be needed when
|
|
|
|
// The event state manager is functional. KMM
|
1999-05-07 20:30:16 +00:00
|
|
|
|
1999-03-22 21:32:12 +00:00
|
|
|
nsCOMPtr<nsIAtom> selectedAtom ( dont_QueryInterface(NS_NewAtom(kMozSelected)));
|
|
|
|
aContent->SetAttribute(kNameSpaceID_None, selectedAtom, "", PR_TRUE);
|
1999-05-07 20:30:16 +00:00
|
|
|
ForceRedraw(aContent);
|
|
|
|
|
1999-01-18 15:14:00 +00:00
|
|
|
}
|
|
|
|
|
1999-03-22 21:32:12 +00:00
|
|
|
void nsListControlFrame::DisplayDeselected(nsIContent* aContent)
|
|
|
|
{
|
1999-04-12 22:14:31 +00:00
|
|
|
//XXX: This is temporary. It simulates psuedo states by using a attribute selector on
|
|
|
|
// -moz-option-selected in the ua.css style sheet. This will not be needed when
|
|
|
|
// The event state manager is functional. KMM
|
1999-05-07 20:30:16 +00:00
|
|
|
|
1999-03-22 21:32:12 +00:00
|
|
|
nsCOMPtr<nsIAtom> selectedAtom ( dont_QueryInterface(NS_NewAtom(kMozSelected)));
|
|
|
|
aContent->UnsetAttribute(kNameSpaceID_None, selectedAtom, PR_TRUE);
|
1999-05-07 20:30:16 +00:00
|
|
|
ForceRedraw(aContent);
|
|
|
|
|
1999-03-22 21:32:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void nsListControlFrame::UpdateItem(nsIContent* aContent, PRBool aSelected)
|
1999-01-18 15:14:00 +00:00
|
|
|
{
|
1999-03-22 21:32:12 +00:00
|
|
|
if (aSelected) {
|
|
|
|
DisplaySelected(aContent);
|
|
|
|
} else {
|
|
|
|
DisplayDeselected(aContent);
|
|
|
|
}
|
1999-01-18 15:14:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
PRInt32 nsListControlFrame::SetContentSelected(nsIFrame * aHitFrame,
|
|
|
|
nsIContent *& aHitContent,
|
1999-04-12 22:14:31 +00:00
|
|
|
PRBool aDisplaySelected)
|
1999-01-18 15:14:00 +00:00
|
|
|
{
|
|
|
|
PRInt32 index = 0;
|
|
|
|
nsIFrame* kid;
|
1999-02-10 02:25:01 +00:00
|
|
|
mContentFrame->FirstChild(nsnull, &kid);
|
1999-01-18 15:14:00 +00:00
|
|
|
while (nsnull != kid) {
|
|
|
|
if (kid == aHitFrame) {
|
|
|
|
NS_IF_RELEASE(aHitContent);
|
1999-02-10 00:42:56 +00:00
|
|
|
nsIContent* content;
|
|
|
|
kid->GetContent(&content);
|
|
|
|
aHitContent = content;
|
1999-04-12 22:14:31 +00:00
|
|
|
if (PR_TRUE == aDisplaySelected)
|
|
|
|
DisplaySelected(aHitContent);
|
1999-01-18 15:14:00 +00:00
|
|
|
return index;
|
|
|
|
}
|
1999-02-10 06:13:38 +00:00
|
|
|
kid->GetNextSibling(&kid);
|
1999-01-18 15:14:00 +00:00
|
|
|
index++;
|
|
|
|
}
|
1999-05-07 20:30:16 +00:00
|
|
|
return kNothingSelected;
|
1999-01-18 15:14:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
void nsListControlFrame::ClearSelection()
|
|
|
|
{
|
|
|
|
PRInt32 i = 0;
|
|
|
|
nsIFrame* kid;
|
1999-02-10 02:25:01 +00:00
|
|
|
mContentFrame->FirstChild(nsnull, &kid);
|
1999-01-18 15:14:00 +00:00
|
|
|
while (nsnull != kid) {
|
|
|
|
nsIContent * content;
|
1999-02-10 00:42:56 +00:00
|
|
|
kid->GetContent(&content);
|
1999-03-22 21:32:12 +00:00
|
|
|
if (IsFrameSelected(i)) {
|
1999-01-18 15:14:00 +00:00
|
|
|
if (i != mSelectedIndex) {
|
1999-03-22 21:32:12 +00:00
|
|
|
DisplayDeselected(content);
|
|
|
|
SetFrameSelected(i, PR_FALSE);
|
1999-01-18 15:14:00 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
NS_RELEASE(content);
|
1999-02-10 06:13:38 +00:00
|
|
|
kid->GetNextSibling(&kid);
|
1999-01-18 15:14:00 +00:00
|
|
|
i++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
void nsListControlFrame::ExtendedSelection(PRInt32 aStartIndex, PRInt32 aEndIndex, PRBool aDoInvert, PRBool aSetValue)
|
|
|
|
{
|
|
|
|
PRInt32 startInx;
|
|
|
|
PRInt32 endInx;
|
|
|
|
|
|
|
|
if (aStartIndex < aEndIndex) {
|
|
|
|
startInx = aStartIndex;
|
|
|
|
endInx = aEndIndex;
|
|
|
|
} else {
|
|
|
|
startInx = aEndIndex;
|
|
|
|
endInx = aStartIndex;
|
|
|
|
}
|
|
|
|
|
|
|
|
PRInt32 i = 0;
|
|
|
|
nsIFrame* kid;
|
|
|
|
PRBool startInverting = PR_FALSE;
|
1999-02-10 02:25:01 +00:00
|
|
|
mContentFrame->FirstChild(nsnull, &kid);
|
1999-01-18 15:14:00 +00:00
|
|
|
while (nsnull != kid) {
|
|
|
|
nsIContent * content;
|
1999-02-10 00:42:56 +00:00
|
|
|
kid->GetContent(&content);
|
1999-01-18 15:14:00 +00:00
|
|
|
if (i == startInx) {
|
|
|
|
startInverting = PR_TRUE;
|
|
|
|
}
|
|
|
|
if (startInverting && ((i != mStartExtendedIndex && aDoInvert) || !aDoInvert)) {
|
|
|
|
if (aDoInvert) {
|
1999-03-22 21:32:12 +00:00
|
|
|
SetFrameSelected(i, !IsFrameSelected(i));
|
1999-01-18 15:14:00 +00:00
|
|
|
} else {
|
1999-03-22 21:32:12 +00:00
|
|
|
SetFrameSelected(i, aSetValue);
|
1999-01-18 15:14:00 +00:00
|
|
|
}
|
|
|
|
if (i != mSelectedIndex) {
|
1999-03-22 21:32:12 +00:00
|
|
|
UpdateItem(content, IsFrameSelected(i));
|
1999-01-18 15:14:00 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
if (i == endInx) {
|
|
|
|
startInverting = PR_FALSE;
|
|
|
|
}
|
|
|
|
NS_RELEASE(content);
|
1999-02-10 06:13:38 +00:00
|
|
|
kid->GetNextSibling(&kid);
|
1999-01-18 15:14:00 +00:00
|
|
|
i++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
1999-05-07 20:30:16 +00:00
|
|
|
void nsListControlFrame::SingleSelection()
|
1999-01-18 15:14:00 +00:00
|
|
|
{
|
1999-05-13 23:45:40 +00:00
|
|
|
//XXX: Experimental code for supporting option groups
|
|
|
|
#if 0
|
|
|
|
// Donothing if a item was not clicked on
|
|
|
|
if (this == mHitFrame)
|
|
|
|
return;
|
|
|
|
|
|
|
|
// Store previous selection
|
|
|
|
nsIFrame* oldSelectedFrame = mSelectedFrame;
|
|
|
|
// Get Current selection
|
|
|
|
mSelectedFrame = mHitFrame;
|
|
|
|
if (mSelectedFrame != nsnull) {
|
|
|
|
if (oldSelectedFrame != mSelectedFrame) {
|
|
|
|
// Deselect the previous selection if there is one
|
|
|
|
if (oldSelectedFrame != nsnull) {
|
|
|
|
nsIContent* content = nsnull;
|
|
|
|
oldSelectedFrame->GetContent(&content);
|
|
|
|
DisplayDeselected(content);
|
|
|
|
NS_RELEASE(content);
|
|
|
|
}
|
|
|
|
// Display the new selection
|
|
|
|
nsIContent* content = nsnull;
|
|
|
|
mSelectedFrame->GetContent(&content);
|
|
|
|
DisplaySelected(content);
|
|
|
|
NS_RELEASE(content);
|
|
|
|
mSelectedContent = mHitContent;
|
|
|
|
} else {
|
|
|
|
// Selecting the currently selected item so do nothing.
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
//XXX: Endof experimental code
|
|
|
|
|
|
|
|
|
1999-05-07 20:30:16 +00:00
|
|
|
// Store previous selection
|
|
|
|
PRInt32 oldSelectedIndex = mSelectedIndex;
|
|
|
|
// Get Current selection
|
|
|
|
mSelectedIndex = (PRInt32)SetContentSelected(mHitFrame, mHitContent, PR_FALSE);
|
|
|
|
if (mSelectedIndex != kNothingSelected) {
|
|
|
|
if (oldSelectedIndex != mSelectedIndex) {
|
|
|
|
// Deselect the previous selection if there is one
|
|
|
|
if (oldSelectedIndex != kNothingSelected) {
|
|
|
|
SetFrameSelected(oldSelectedIndex, PR_FALSE);
|
|
|
|
}
|
1999-05-13 23:45:40 +00:00
|
|
|
// Display the new selection
|
1999-03-22 21:32:12 +00:00
|
|
|
SetFrameSelected(mSelectedIndex, PR_TRUE);
|
1999-05-07 20:30:16 +00:00
|
|
|
mSelectedContent = mHitContent;
|
|
|
|
} else {
|
|
|
|
// Selecting the currently selected item so do nothing.
|
|
|
|
}
|
|
|
|
}
|
1999-05-13 23:45:40 +00:00
|
|
|
|
1999-05-07 20:30:16 +00:00
|
|
|
}
|
1999-01-18 15:14:00 +00:00
|
|
|
|
1999-05-07 20:30:16 +00:00
|
|
|
void nsListControlFrame::MultipleSelection(PRBool aIsShift, PRBool aIsControl)
|
|
|
|
{
|
|
|
|
PRInt32 oldSelectedIndex = mSelectedIndex;
|
|
|
|
|
|
|
|
mSelectedIndex = (PRInt32)SetContentSelected(mHitFrame, mHitContent, PR_FALSE);
|
|
|
|
if (kNothingSelected != mSelectedIndex) {
|
|
|
|
PRBool wasSelected = IsFrameSelected(mSelectedIndex);
|
|
|
|
SetFrameSelected(mSelectedIndex, PR_TRUE);
|
|
|
|
PRBool selected = wasSelected;
|
|
|
|
|
|
|
|
if (aIsShift) {
|
|
|
|
selected = PR_TRUE;
|
|
|
|
if (mEndExtendedIndex == kNothingSelected) {
|
|
|
|
mEndExtendedIndex = mSelectedIndex;
|
|
|
|
ExtendedSelection(mStartExtendedIndex, mEndExtendedIndex, PR_FALSE, PR_TRUE);
|
|
|
|
} else {
|
|
|
|
if (mStartExtendedIndex < mEndExtendedIndex) {
|
|
|
|
if (mSelectedIndex < mStartExtendedIndex) {
|
|
|
|
ExtendedSelection(mSelectedIndex, mEndExtendedIndex, PR_TRUE, PR_TRUE);
|
|
|
|
mEndExtendedIndex = mSelectedIndex;
|
|
|
|
} else if (mSelectedIndex > mEndExtendedIndex) {
|
|
|
|
ExtendedSelection(mEndExtendedIndex+1, mSelectedIndex, PR_FALSE, PR_TRUE);
|
|
|
|
mEndExtendedIndex = mSelectedIndex;
|
|
|
|
} else if (mSelectedIndex < mEndExtendedIndex) {
|
|
|
|
ExtendedSelection(mSelectedIndex+1, mEndExtendedIndex, PR_FALSE, PR_FALSE);
|
1999-01-18 15:14:00 +00:00
|
|
|
mEndExtendedIndex = mSelectedIndex;
|
|
|
|
}
|
1999-05-07 20:30:16 +00:00
|
|
|
} else if (mStartExtendedIndex > mEndExtendedIndex) {
|
|
|
|
if (mSelectedIndex > mStartExtendedIndex) {
|
|
|
|
ExtendedSelection(mEndExtendedIndex, mSelectedIndex, PR_TRUE, PR_TRUE);
|
|
|
|
mEndExtendedIndex = mSelectedIndex;
|
|
|
|
} else if (mSelectedIndex < mEndExtendedIndex) {
|
|
|
|
ExtendedSelection(mStartExtendedIndex+1, mEndExtendedIndex-1, PR_FALSE, PR_TRUE);
|
|
|
|
mEndExtendedIndex = mSelectedIndex;
|
|
|
|
} else if (mSelectedIndex > mEndExtendedIndex) {
|
|
|
|
ExtendedSelection(mEndExtendedIndex, mSelectedIndex-1, PR_FALSE, PR_FALSE);
|
|
|
|
mEndExtendedIndex = mSelectedIndex;
|
1999-01-18 15:14:00 +00:00
|
|
|
}
|
|
|
|
}
|
1999-05-07 20:30:16 +00:00
|
|
|
}
|
|
|
|
} else if (aIsControl) {
|
|
|
|
selected = !selected;
|
|
|
|
if (nsnull != mSelectedContent) {
|
|
|
|
if (mHitContent != mSelectedContent) {
|
|
|
|
// Toggle the selection
|
|
|
|
UpdateItem(mHitContent, !wasSelected);
|
|
|
|
} else {
|
|
|
|
//XXX: Fix this mSelectedContent->SetAttribute(kNameSpaceID_HTML, nsHTMLAtoms::kClass, (selected?kSelectedFocus:kNormal), PR_TRUE);
|
1999-01-18 15:14:00 +00:00
|
|
|
}
|
|
|
|
}
|
1999-05-07 20:30:16 +00:00
|
|
|
} else {
|
|
|
|
mStartExtendedIndex = mSelectedIndex;
|
|
|
|
mEndExtendedIndex = kNothingSelected;
|
|
|
|
ClearSelection();
|
|
|
|
selected = PR_TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
//XXX Fix this mHitContent->SetAttribute(kNameSpaceID_HTML, nsHTMLAtoms::kClass, (selected?kSelectedFocus:kNormal), PR_TRUE);
|
|
|
|
mSelectedContent = mHitContent;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
NS_IMETHODIMP nsListControlFrame::HandleLikeListEvent(nsIPresContext& aPresContext,
|
|
|
|
nsGUIEvent* aEvent,
|
|
|
|
nsEventStatus& aEventStatus)
|
|
|
|
{
|
|
|
|
if (aEvent->message == NS_MOUSE_LEFT_BUTTON_DOWN) {
|
|
|
|
if (mMultipleSelections) {
|
|
|
|
MultipleSelection(((nsMouseEvent *)aEvent)->isShift, ((nsMouseEvent *)aEvent)->isControl);
|
|
|
|
} else {
|
|
|
|
SingleSelection();
|
1999-01-18 15:14:00 +00:00
|
|
|
}
|
|
|
|
}
|
1999-05-07 20:30:16 +00:00
|
|
|
|
|
|
|
aEventStatus = nsEventStatus_eConsumeNoDefault;
|
1999-01-18 15:14:00 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
1999-04-16 19:28:12 +00:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsListControlFrame :: CaptureMouseEvents(PRBool aGrabMouseEvents)
|
|
|
|
{
|
|
|
|
// get its view
|
|
|
|
nsIView* view = nsnull;
|
|
|
|
GetView(&view);
|
|
|
|
nsCOMPtr<nsIViewManager> viewMan;
|
|
|
|
PRBool result;
|
|
|
|
|
|
|
|
if (view) {
|
|
|
|
view->GetViewManager(*getter_AddRefs(viewMan));
|
|
|
|
|
|
|
|
if (viewMan) {
|
|
|
|
if (aGrabMouseEvents) {
|
|
|
|
viewMan->GrabMouseEvents(view,result);
|
|
|
|
} else {
|
|
|
|
viewMan->GrabMouseEvents(nsnull,result);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
1999-01-18 15:14:00 +00:00
|
|
|
//----------------------------------------------------------------------
|
|
|
|
NS_IMETHODIMP nsListControlFrame::HandleLikeDropDownListEvent(nsIPresContext& aPresContext,
|
|
|
|
nsGUIEvent* aEvent,
|
|
|
|
nsEventStatus& aEventStatus)
|
|
|
|
{
|
|
|
|
// Mouse Move behavior is as follows:
|
|
|
|
// When the DropDown occurs, if an item is selected it displayed as being selected.
|
|
|
|
// It may or may not be currently visible, when the mouse is moved across any item
|
|
|
|
// in the the list it is displayed as the currently selected item.
|
1999-05-07 20:30:16 +00:00
|
|
|
// (Selection doesn't actually occur until the mouse is released, or clicked and released)
|
1999-01-18 15:14:00 +00:00
|
|
|
if (aEvent->message == NS_MOUSE_MOVE) {
|
|
|
|
|
|
|
|
// If the DropDown is currently has a selected item
|
|
|
|
// then clear the selected item
|
|
|
|
if (nsnull != mSelectedContent) {
|
1999-03-22 21:32:12 +00:00
|
|
|
DisplayDeselected(mSelectedContent);
|
1999-01-18 15:14:00 +00:00
|
|
|
NS_RELEASE(mSelectedContent);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Now check to see if the newly hit frame is different
|
|
|
|
// from the currently hit frame
|
|
|
|
if (nsnull != mHitFrame && mHitFrame != mCurrentHitFrame) {
|
|
|
|
|
|
|
|
// Since the new frame is different then clear the selection on the old frame (the current frame)
|
|
|
|
if (nsnull != mCurrentHitContent) {
|
1999-03-22 21:32:12 +00:00
|
|
|
DisplayDeselected(mCurrentHitContent);
|
1999-01-18 15:14:00 +00:00
|
|
|
NS_RELEASE(mCurrentHitContent);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Find the new hit "content" from the hit frame and select it
|
|
|
|
SetContentSelected(mHitFrame, mHitContent, PR_TRUE);
|
|
|
|
|
|
|
|
// Now cache the the newly hit frame and content as the "current" values
|
|
|
|
mCurrentHitFrame = mHitFrame;
|
|
|
|
mCurrentHitContent = mHitContent;
|
|
|
|
}
|
|
|
|
|
1999-04-16 19:28:12 +00:00
|
|
|
} else if (aEvent->message == NS_MOUSE_LEFT_BUTTON_DOWN) {
|
|
|
|
// Initiate mouse capture
|
|
|
|
CaptureMouseEvents(PR_TRUE);
|
|
|
|
|
1999-01-18 15:14:00 +00:00
|
|
|
} else if (aEvent->message == NS_MOUSE_LEFT_BUTTON_UP) {
|
1999-04-16 19:28:12 +00:00
|
|
|
// Stop grabbing mouse events
|
|
|
|
CaptureMouseEvents(PR_FALSE);
|
1999-01-18 15:14:00 +00:00
|
|
|
|
|
|
|
// Start by finding the newly "hit" content from the hit frame
|
1999-04-12 22:14:31 +00:00
|
|
|
PRInt32 index = SetContentSelected(mHitFrame, mHitContent, PR_TRUE);
|
1999-05-07 20:30:16 +00:00
|
|
|
if (kNothingSelected != index) {
|
1999-01-18 15:14:00 +00:00
|
|
|
|
|
|
|
nsIDOMHTMLOptionElement* option = nsnull;
|
|
|
|
nsresult rv = mHitContent->QueryInterface(kIDOMHTMLOptionElementIID, (void**)&option);
|
|
|
|
if (NS_OK == rv) {
|
|
|
|
nsAutoString text;
|
|
|
|
if (NS_CONTENT_ATTR_HAS_VALUE == option->GetText(text)) {
|
|
|
|
mSelectionStr = text;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IF_RELEASE(mSelectedContent);
|
|
|
|
mSelectedIndex = index;
|
|
|
|
|
|
|
|
// Clean up frames before disappearing
|
|
|
|
if (nsnull != mSelectedContent) {
|
1999-03-22 21:32:12 +00:00
|
|
|
DisplayDeselected(mSelectedContent);
|
1999-01-18 15:14:00 +00:00
|
|
|
NS_RELEASE(mSelectedContent);
|
|
|
|
}
|
|
|
|
if (nsnull != mHitContent) {
|
1999-03-22 21:32:12 +00:00
|
|
|
DisplayDeselected(mHitContent);
|
1999-01-18 15:14:00 +00:00
|
|
|
NS_RELEASE(mHitContent);
|
|
|
|
}
|
|
|
|
if (nsnull != mCurrentHitContent) {
|
1999-03-22 21:32:12 +00:00
|
|
|
DisplayDeselected(mCurrentHitContent);
|
1999-01-18 15:14:00 +00:00
|
|
|
NS_RELEASE(mCurrentHitContent);
|
|
|
|
}
|
|
|
|
NS_RELEASE(option);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (mComboboxFrame) {
|
1999-04-16 19:28:12 +00:00
|
|
|
mComboboxFrame->ListWasSelected(&aPresContext);
|
1999-01-18 15:14:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
1999-04-16 19:28:12 +00:00
|
|
|
}
|
1999-01-18 15:14:00 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
NS_IMETHODIMP nsListControlFrame::HandleEvent(nsIPresContext& aPresContext,
|
|
|
|
nsGUIEvent* aEvent,
|
|
|
|
nsEventStatus& aEventStatus)
|
|
|
|
{
|
|
|
|
/* const char * desc[] = {"NS_MOUSE_MOVE",
|
|
|
|
"NS_MOUSE_LEFT_BUTTON_UP",
|
|
|
|
"NS_MOUSE_LEFT_BUTTON_DOWN",
|
|
|
|
"<NA>","<NA>","<NA>","<NA>","<NA>","<NA>","<NA>",
|
|
|
|
"NS_MOUSE_MIDDLE_BUTTON_UP",
|
|
|
|
"NS_MOUSE_MIDDLE_BUTTON_DOWN",
|
|
|
|
"<NA>","<NA>","<NA>","<NA>","<NA>","<NA>","<NA>","<NA>",
|
|
|
|
"NS_MOUSE_RIGHT_BUTTON_UP",
|
|
|
|
"NS_MOUSE_RIGHT_BUTTON_DOWN",
|
|
|
|
"NS_MOUSE_ENTER",
|
|
|
|
"NS_MOUSE_EXIT",
|
|
|
|
"NS_MOUSE_LEFT_DOUBLECLICK",
|
|
|
|
"NS_MOUSE_MIDDLE_DOUBLECLICK",
|
|
|
|
"NS_MOUSE_RIGHT_DOUBLECLICK",
|
|
|
|
"NS_MOUSE_LEFT_CLICK",
|
|
|
|
"NS_MOUSE_MIDDLE_CLICK",
|
|
|
|
"NS_MOUSE_RIGHT_CLICK"};
|
|
|
|
int inx = aEvent->message-NS_MOUSE_MESSAGE_START;
|
|
|
|
if (inx >= 0 && inx <= (NS_MOUSE_RIGHT_CLICK-NS_MOUSE_MESSAGE_START)) {
|
|
|
|
printf("Mouse in ListFrame %s [%d]\n", desc[inx], aEvent->message);
|
|
|
|
} else {
|
|
|
|
printf("Mouse in ListFrame <UNKNOWN> [%d]\n", aEvent->message);
|
|
|
|
}*/
|
1999-03-02 22:43:26 +00:00
|
|
|
|
1999-01-18 15:14:00 +00:00
|
|
|
if (nsEventStatus_eConsumeNoDefault == aEventStatus) {
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
const nsStyleDisplay* disp = (const nsStyleDisplay*)mStyleContext->GetStyleData(eStyleStruct_Display);
|
|
|
|
if (!disp->mVisible) {
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(nsEventStatus_eConsumeNoDefault != aEventStatus) {
|
|
|
|
|
|
|
|
aEventStatus = nsEventStatus_eConsumeNoDefault;
|
|
|
|
if (mInDropDownMode) {
|
|
|
|
HandleLikeDropDownListEvent(aPresContext, aEvent, aEventStatus);
|
|
|
|
} else {
|
|
|
|
HandleLikeListEvent(aPresContext, aEvent, aEventStatus);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsListControlFrame::SetInitialChildList(nsIPresContext& aPresContext,
|
1999-04-27 00:06:03 +00:00
|
|
|
nsIAtom* aListName,
|
|
|
|
nsIFrame* aChildList)
|
1999-01-18 15:14:00 +00:00
|
|
|
{
|
|
|
|
mContentFrame = aChildList;
|
1999-03-22 21:32:12 +00:00
|
|
|
|
1999-01-18 15:14:00 +00:00
|
|
|
if (!mInDropDownMode) {
|
|
|
|
nsFormFrame::AddFormControlFrame(aPresContext, *this);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!mIsInitializedFromContent) {
|
|
|
|
InitializeFromContent();
|
|
|
|
}
|
|
|
|
|
|
|
|
return nsScrollFrame::SetInitialChildList(aPresContext, aListName, aChildList);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsListControlFrame::Init(nsIPresContext& aPresContext,
|
1999-02-25 03:27:57 +00:00
|
|
|
nsIContent* aContent,
|
|
|
|
nsIFrame* aParent,
|
|
|
|
nsIStyleContext* aContext,
|
|
|
|
nsIFrame* aPrevInFlow)
|
1999-01-18 15:14:00 +00:00
|
|
|
{
|
1999-02-25 03:27:57 +00:00
|
|
|
nsresult result = nsScrollFrame::Init(aPresContext, aContent, aParent, aContext,
|
|
|
|
aPrevInFlow);
|
1999-01-18 15:14:00 +00:00
|
|
|
if (NS_OK == result) {
|
|
|
|
nsIDOMHTMLSelectElement* select;
|
|
|
|
if (mContent && (NS_OK == mContent->QueryInterface(kIDOMHTMLSelectElementIID, (void**) &select))) {
|
|
|
|
select->GetMultiple(&mMultipleSelections);
|
|
|
|
select->GetSize(&mNumRows);
|
|
|
|
|
|
|
|
NS_RELEASE(select);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
1999-05-07 20:30:16 +00:00
|
|
|
// XXX: This following methods are not referenced. They should be removed if they
|
|
|
|
// are not needed
|
1999-01-18 15:14:00 +00:00
|
|
|
//----------------------------------------------------------------------
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsListControlFrame::GetMaxLength(PRInt32* aSize)
|
|
|
|
{
|
|
|
|
*aSize = -1;
|
|
|
|
nsresult result = NS_CONTENT_ATTR_NOT_THERE;
|
|
|
|
nsIHTMLContent* content = nsnull;
|
|
|
|
mContent->QueryInterface(kIHTMLContentIID, (void**) &content);
|
|
|
|
if (nsnull != content) {
|
|
|
|
nsHTMLValue value;
|
|
|
|
result = content->GetHTMLAttribute(nsHTMLAtoms::maxlength, value);
|
|
|
|
if (eHTMLUnit_Integer == value.GetUnit()) {
|
|
|
|
*aSize = value.GetIntValue();
|
|
|
|
}
|
|
|
|
NS_RELEASE(content);
|
|
|
|
}
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
1999-02-03 22:56:50 +00:00
|
|
|
nsresult
|
|
|
|
nsListControlFrame::GetSizeFromContent(PRInt32* aSize) const
|
1999-01-18 15:14:00 +00:00
|
|
|
{
|
|
|
|
*aSize = -1;
|
|
|
|
nsresult result = NS_CONTENT_ATTR_NOT_THERE;
|
|
|
|
nsIHTMLContent* content = nsnull;
|
|
|
|
mContent->QueryInterface(kIHTMLContentIID, (void**) &content);
|
|
|
|
if (nsnull != content) {
|
|
|
|
nsHTMLValue value;
|
|
|
|
result = content->GetHTMLAttribute(nsHTMLAtoms::size, value);
|
|
|
|
if (eHTMLUnit_Integer == value.GetUnit()) {
|
|
|
|
*aSize = value.GetIntValue();
|
|
|
|
}
|
|
|
|
NS_RELEASE(content);
|
|
|
|
}
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
1999-05-07 20:30:16 +00:00
|
|
|
//XXX: End of the un-referenced methods.
|
1999-01-18 15:14:00 +00:00
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
nscoord
|
|
|
|
nsListControlFrame::GetVerticalInsidePadding(float aPixToTwip,
|
|
|
|
nscoord aInnerHeight) const
|
|
|
|
{
|
1999-03-22 21:32:12 +00:00
|
|
|
return NSIntPixelsToTwips(0, aPixToTwip);
|
1999-01-18 15:14:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
nscoord
|
|
|
|
nsListControlFrame::GetHorizontalInsidePadding(nsIPresContext& aPresContext,
|
|
|
|
float aPixToTwip,
|
|
|
|
nscoord aInnerWidth,
|
|
|
|
nscoord aCharWidth) const
|
|
|
|
{
|
|
|
|
return GetVerticalInsidePadding(aPixToTwip, aInnerWidth);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsListControlFrame::GetMultiple(PRBool* aMultiple, nsIDOMHTMLSelectElement* aSelect)
|
|
|
|
{
|
|
|
|
if (!aSelect) {
|
|
|
|
nsIDOMHTMLSelectElement* select = nsnull;
|
|
|
|
nsresult result = mContent->QueryInterface(kIDOMHTMLSelectElementIID, (void**)&select);
|
|
|
|
if ((NS_OK == result) && select) {
|
|
|
|
result = select->GetMultiple(aMultiple);
|
|
|
|
NS_RELEASE(select);
|
|
|
|
}
|
|
|
|
return result;
|
|
|
|
} else {
|
|
|
|
return aSelect->GetMultiple(aMultiple);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
nsIDOMHTMLSelectElement*
|
|
|
|
nsListControlFrame::GetSelect(nsIContent * aContent)
|
|
|
|
{
|
|
|
|
nsIDOMHTMLSelectElement* select = nsnull;
|
|
|
|
nsresult result = aContent->QueryInterface(kIDOMHTMLSelectElementIID, (void**)&select);
|
|
|
|
if ((NS_OK == result) && select) {
|
|
|
|
return select;
|
|
|
|
} else {
|
|
|
|
return nsnull;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsListControlFrame::AboutToDropDown()
|
|
|
|
{
|
|
|
|
PRInt32 i = 0;
|
|
|
|
nsIFrame* kid;
|
1999-02-10 02:25:01 +00:00
|
|
|
mContentFrame->FirstChild(nsnull, &kid);
|
1999-01-18 15:14:00 +00:00
|
|
|
while (nsnull != kid) {
|
|
|
|
nsIContent * content;
|
1999-02-10 00:42:56 +00:00
|
|
|
kid->GetContent(&content);
|
1999-01-18 15:14:00 +00:00
|
|
|
if (i == mSelectedIndex) {
|
|
|
|
mSelectedContent = content;
|
1999-03-22 21:32:12 +00:00
|
|
|
DisplaySelected(mSelectedContent);
|
1999-01-18 15:14:00 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
NS_RELEASE(content);
|
1999-02-10 06:13:38 +00:00
|
|
|
kid->GetNextSibling(&kid);
|
1999-01-18 15:14:00 +00:00
|
|
|
i++;
|
|
|
|
}
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
1999-03-22 21:32:12 +00:00
|
|
|
|
|
|
|
nsIContent*
|
|
|
|
nsListControlFrame::GetOptionContent(PRUint32 aIndex)
|
|
|
|
{
|
|
|
|
nsresult result = NS_OK;
|
|
|
|
nsIDOMHTMLCollection* options = GetOptions(mContent);
|
|
|
|
nsIDOMHTMLOptionElement* optionElement = GetOption(*options, aIndex);
|
|
|
|
|
|
|
|
nsIContent *content = nsnull;
|
|
|
|
result = optionElement->QueryInterface(kIContentIID, (void**) &content);
|
|
|
|
|
|
|
|
NS_RELEASE(optionElement);
|
|
|
|
NS_RELEASE(options);
|
|
|
|
|
|
|
|
if (NS_SUCCEEDED(result)) {
|
|
|
|
return(content);
|
|
|
|
} else {
|
|
|
|
return(nsnull);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
PRBool
|
|
|
|
nsListControlFrame::IsFrameSelected(PRUint32 aIndex)
|
|
|
|
{
|
|
|
|
nsIContent* content = GetOptionContent(aIndex);
|
|
|
|
NS_ASSERTION(nsnull != content, "Failed to retrieve option content");
|
|
|
|
nsString value;
|
|
|
|
nsCOMPtr<nsIAtom> selectedAtom ( dont_QueryInterface(NS_NewAtom(kMozSelected)));
|
|
|
|
nsresult result = content->GetAttribute(kNameSpaceID_None, selectedAtom, value);
|
|
|
|
NS_IF_RELEASE(content);
|
|
|
|
|
|
|
|
if (NS_CONTENT_ATTR_NOT_THERE == result) {
|
|
|
|
return(PR_FALSE);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
return(PR_TRUE);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsListControlFrame::SetFrameSelected(PRUint32 aIndex, PRBool aSelected)
|
|
|
|
{
|
|
|
|
nsIContent* content = GetOptionContent(aIndex);
|
|
|
|
NS_ASSERTION(nsnull != content, "Failed to retrieve option content");
|
|
|
|
if (aSelected) {
|
|
|
|
DisplaySelected(content);
|
|
|
|
} else {
|
|
|
|
DisplayDeselected(content);
|
|
|
|
}
|
|
|
|
NS_IF_RELEASE(content);
|
|
|
|
}
|
|
|
|
|
1999-01-18 15:14:00 +00:00
|
|
|
//----------------------------------------------------------------------
|
|
|
|
void
|
|
|
|
nsListControlFrame::InitializeFromContent(PRBool aDoDisplay)
|
|
|
|
{
|
|
|
|
PRInt32 i;
|
|
|
|
|
|
|
|
i = 0;
|
|
|
|
nsIFrame* kid;
|
1999-02-10 02:25:01 +00:00
|
|
|
mContentFrame->FirstChild(nsnull, &kid);
|
1999-01-18 15:14:00 +00:00
|
|
|
while (nsnull != kid) {
|
|
|
|
nsIContent * content;
|
1999-02-10 00:42:56 +00:00
|
|
|
kid->GetContent(&content);
|
1999-01-18 15:14:00 +00:00
|
|
|
|
|
|
|
nsIDOMHTMLOptionElement* option = nsnull;
|
|
|
|
nsresult result = content->QueryInterface(kIDOMHTMLOptionElementIID, (void**)&option);
|
|
|
|
if (result == NS_OK) {
|
|
|
|
PRBool selected;
|
|
|
|
option->GetDefaultSelected(&selected);
|
1999-03-22 21:32:12 +00:00
|
|
|
SetFrameSelected(i, selected);
|
1999-05-07 20:30:16 +00:00
|
|
|
// Set the selected index for single selection list boxes.
|
|
|
|
if (selected) {
|
|
|
|
mSelectedIndex = i;
|
|
|
|
}
|
1999-01-18 15:14:00 +00:00
|
|
|
|
|
|
|
if (mInDropDownMode) {
|
|
|
|
if (selected) {
|
|
|
|
nsAutoString text;
|
|
|
|
if (NS_CONTENT_ATTR_HAS_VALUE == option->GetText(text)) {
|
|
|
|
mSelectionStr = text;
|
|
|
|
}
|
|
|
|
mSelectedIndex = i;
|
|
|
|
NS_RELEASE(option);
|
|
|
|
mSelectedContent = content;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
} else {
|
1999-03-22 21:32:12 +00:00
|
|
|
if (selected && aDoDisplay) {
|
|
|
|
DisplaySelected(content);
|
|
|
|
mSelectedContent = content;
|
|
|
|
NS_ADDREF(content);
|
1999-01-18 15:14:00 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
NS_RELEASE(option);
|
|
|
|
}
|
|
|
|
NS_RELEASE(content);
|
1999-02-10 06:13:38 +00:00
|
|
|
kid->GetNextSibling(&kid);
|
1999-01-18 15:14:00 +00:00
|
|
|
i++;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
nsIDOMHTMLCollection*
|
|
|
|
nsListControlFrame::GetOptions(nsIContent * aContent, nsIDOMHTMLSelectElement* aSelect)
|
|
|
|
{
|
|
|
|
nsIDOMHTMLCollection* options = nsnull;
|
|
|
|
if (!aSelect) {
|
|
|
|
nsIDOMHTMLSelectElement* select = GetSelect(aContent);
|
|
|
|
if (select) {
|
|
|
|
select->GetOptions(&options);
|
|
|
|
NS_RELEASE(select);
|
|
|
|
return options;
|
|
|
|
} else {
|
|
|
|
return nsnull;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
aSelect->GetOptions(&options);
|
|
|
|
return options;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
nsIDOMHTMLOptionElement*
|
|
|
|
nsListControlFrame::GetOption(nsIDOMHTMLCollection& aCollection, PRUint32 aIndex)
|
|
|
|
{
|
|
|
|
nsIDOMNode* node = nsnull;
|
|
|
|
if ((NS_OK == aCollection.Item(aIndex, &node)) && node) {
|
|
|
|
nsIDOMHTMLOptionElement* option = nsnull;
|
1999-02-12 17:45:58 +00:00
|
|
|
node->QueryInterface(kIDOMHTMLOptionElementIID, (void**)&option);
|
1999-01-18 15:14:00 +00:00
|
|
|
NS_RELEASE(node);
|
|
|
|
return option;
|
|
|
|
}
|
|
|
|
return nsnull;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
PRBool
|
|
|
|
nsListControlFrame::GetOptionValue(nsIDOMHTMLCollection& aCollection, PRUint32 aIndex, nsString& aValue)
|
|
|
|
{
|
|
|
|
PRBool status = PR_FALSE;
|
|
|
|
nsIDOMHTMLOptionElement* option = GetOption(aCollection, aIndex);
|
|
|
|
if (option) {
|
|
|
|
nsresult result = option->GetValue(aValue);
|
|
|
|
if (aValue.Length() > 0) {
|
|
|
|
status = PR_TRUE;
|
|
|
|
} else {
|
|
|
|
result = option->GetText(aValue);
|
|
|
|
if (aValue.Length() > 0) {
|
|
|
|
status = PR_TRUE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
NS_RELEASE(option);
|
|
|
|
}
|
|
|
|
return status;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsListControlFrame::Deselect()
|
|
|
|
{
|
|
|
|
PRInt32 i;
|
|
|
|
for (i=0;i<mMaxNumSelections;i++) {
|
1999-03-22 21:32:12 +00:00
|
|
|
SetFrameSelected(i, PR_FALSE);
|
1999-01-18 15:14:00 +00:00
|
|
|
// update visual here
|
|
|
|
}
|
|
|
|
mNumSelections = 0;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
// nsHTMLContainerFrame
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
PRIntn
|
|
|
|
nsListControlFrame::GetSkipSides() const
|
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
// nsIFormControlFrame
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsListControlFrame::GetType(PRInt32* aType) const
|
|
|
|
{
|
|
|
|
*aType = NS_FORM_SELECT;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsListControlFrame::SetFormFrame(nsFormFrame* aFormFrame)
|
|
|
|
{
|
|
|
|
mFormFrame = aFormFrame;
|
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
PRBool
|
|
|
|
nsListControlFrame::IsSuccessful(nsIFormControlFrame* aSubmitter)
|
|
|
|
{
|
|
|
|
nsAutoString name;
|
|
|
|
return (NS_CONTENT_ATTR_HAS_VALUE == GetName(&name));
|
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
void
|
|
|
|
nsListControlFrame::MouseClicked(nsIPresContext* aPresContext)
|
|
|
|
{
|
|
|
|
}
|
1999-03-22 21:32:12 +00:00
|
|
|
|
1999-01-18 15:14:00 +00:00
|
|
|
//----------------------------------------------------------------------
|
|
|
|
PRInt32
|
|
|
|
nsListControlFrame::GetMaxNumValues()
|
|
|
|
{
|
|
|
|
PRBool multiple;
|
|
|
|
GetMultiple(&multiple);
|
|
|
|
if (multiple) {
|
|
|
|
PRUint32 length = 0;
|
|
|
|
nsIDOMHTMLCollection* options = GetOptions(mContent);
|
|
|
|
if (options) {
|
|
|
|
options->GetLength(&length);
|
|
|
|
}
|
|
|
|
return (PRInt32)length; // XXX fix return on GetMaxNumValues
|
|
|
|
} else {
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
void
|
|
|
|
nsListControlFrame::Reset()
|
|
|
|
{
|
|
|
|
SetFocus(PR_TRUE, PR_TRUE);
|
|
|
|
|
|
|
|
nsIDOMHTMLCollection* options = GetOptions(mContent);
|
|
|
|
if (!options) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
PRUint32 numOptions;
|
|
|
|
options->GetLength(&numOptions);
|
|
|
|
|
|
|
|
Deselect();
|
|
|
|
for (PRUint32 i = 0; i < numOptions; i++) {
|
|
|
|
nsIDOMHTMLOptionElement* option = GetOption(*options, i);
|
|
|
|
if (option) {
|
|
|
|
PRBool selected = PR_FALSE;
|
|
|
|
option->GetSelected(&selected);
|
|
|
|
if (selected) {
|
1999-03-22 21:32:12 +00:00
|
|
|
SetFrameSelected(i, PR_TRUE);
|
1999-01-18 15:14:00 +00:00
|
|
|
}
|
|
|
|
NS_RELEASE(option);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// update visual here
|
|
|
|
NS_RELEASE(options);
|
|
|
|
}
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsListControlFrame::GetName(nsString* aResult)
|
|
|
|
{
|
|
|
|
nsresult result = NS_FORM_NOTOK;
|
|
|
|
if (mContent) {
|
|
|
|
nsIHTMLContent* formControl = nsnull;
|
|
|
|
result = mContent->QueryInterface(kIHTMLContentIID, (void**)&formControl);
|
|
|
|
if ((NS_OK == result) && formControl) {
|
|
|
|
nsHTMLValue value;
|
|
|
|
result = formControl->GetHTMLAttribute(nsHTMLAtoms::name, value);
|
|
|
|
if (NS_CONTENT_ATTR_HAS_VALUE == result) {
|
|
|
|
if (eHTMLUnit_String == value.GetUnit()) {
|
|
|
|
value.GetStringValue(*aResult);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
NS_RELEASE(formControl);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
PRBool
|
|
|
|
nsListControlFrame::GetNamesValues(PRInt32 aMaxNumValues, PRInt32& aNumValues,
|
|
|
|
nsString* aValues, nsString* aNames)
|
|
|
|
{
|
|
|
|
PRBool status = PR_FALSE;
|
|
|
|
|
|
|
|
aNumValues = 0;
|
|
|
|
nsAutoString name;
|
|
|
|
nsresult result = GetName(&name);
|
|
|
|
if ((aMaxNumValues <= 0) || (NS_CONTENT_ATTR_NOT_THERE == result)) {
|
|
|
|
return PR_FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsIDOMHTMLCollection* options = GetOptions(mContent);
|
|
|
|
if (!options) {
|
|
|
|
return PR_FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_ASSERTION(aMaxNumValues >= mNumSelections, "invalid max num values");
|
|
|
|
if (mNumSelections >= 0) {
|
|
|
|
PRInt32* selections = new PRInt32[mNumSelections];
|
|
|
|
PRInt32 i = 0;
|
|
|
|
PRInt32 inx;
|
|
|
|
for (inx=0;i<mNumSelections;i++) {
|
1999-03-22 21:32:12 +00:00
|
|
|
if (IsFrameSelected(inx)) {
|
1999-01-18 15:14:00 +00:00
|
|
|
selections[i++] = inx;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
aNumValues = 0;
|
|
|
|
for (i = 0; i < mNumSelections; i++) {
|
|
|
|
nsAutoString value;
|
|
|
|
GetOptionValue(*options, selections[i], value);
|
|
|
|
aNames[i] = name;
|
|
|
|
aValues[i] = value;
|
|
|
|
aNumValues++;
|
|
|
|
}
|
|
|
|
delete[] selections;
|
|
|
|
status = PR_TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_RELEASE(options);
|
|
|
|
|
|
|
|
return status;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
1999-03-22 21:32:12 +00:00
|
|
|
|
1999-01-18 15:14:00 +00:00
|
|
|
//----------------------------------------------------------------------
|
|
|
|
// native widgets don't unset focus explicitly and don't need to repaint
|
|
|
|
void
|
|
|
|
nsListControlFrame::SetFocus(PRBool aOn, PRBool aRepaint)
|
|
|
|
{
|
|
|
|
// XXX I don't know whether to use the aRepaint flag as last param
|
|
|
|
// in this call?
|
|
|
|
if (mSelectedContent) {
|
1999-04-12 22:14:31 +00:00
|
|
|
//XXX: Need correct attribute here
|
1999-05-07 20:30:16 +00:00
|
|
|
// mSelectedContent->SetAttribute(kNameSpaceID_HTML, nsHTMLAtoms::kClass, (aOn?kSelectedFocus:kNormal), PR_TRUE);
|
|
|
|
}
|
1999-01-18 15:14:00 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
// nsIListControlFrame
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsListControlFrame::SetComboboxFrame(nsIFrame* aComboboxFrame)
|
|
|
|
{
|
|
|
|
static NS_DEFINE_IID(kIComboboxIID, NS_ICOMBOBOXCONTROLFRAME_IID);
|
|
|
|
if (aComboboxFrame && (NS_OK == aComboboxFrame->QueryInterface(kIComboboxIID, (void**) &mComboboxFrame))) {
|
|
|
|
mInDropDownMode = PR_TRUE;
|
|
|
|
}
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsListControlFrame::GetSelectedItem(nsString & aStr)
|
|
|
|
{
|
|
|
|
aStr = mSelectionStr;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
1999-04-12 22:14:31 +00:00
|
|
|
nsresult nsListControlFrame::RequiresWidget(PRBool& aRequiresWidget)
|
1999-01-25 22:16:27 +00:00
|
|
|
{
|
1999-04-12 22:14:31 +00:00
|
|
|
aRequiresWidget = PR_FALSE;
|
1999-01-25 22:16:27 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
1999-04-12 22:14:31 +00:00
|
|
|
|
|
|
|
PRInt32 nsListControlFrame::GetNumberOfOptions()
|
|
|
|
{
|
|
|
|
nsIDOMHTMLCollection* options = GetOptions(mContent);
|
|
|
|
if (!options) {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
PRUint32 numOptions;
|
|
|
|
options->GetLength(&numOptions);
|
|
|
|
NS_RELEASE(options);
|
|
|
|
return(numOptions);
|
|
|
|
}
|
|
|
|
|
1999-05-07 20:30:16 +00:00
|
|
|
// Set the selected attribute for an item in the listbox. If the listbox has
|
|
|
|
// been initialized the result of the setting the attribute is displayed otherwise
|
|
|
|
// it is not.
|
1999-04-12 22:14:31 +00:00
|
|
|
|
1999-05-07 20:30:16 +00:00
|
|
|
void
|
|
|
|
nsListControlFrame::SetContentSelectedAttribute(PRUint32 aIndex, PRBool aSelected)
|
|
|
|
{
|
|
|
|
// Only display the result of the attribute changed if the listbox has been
|
|
|
|
// initialized.
|
|
|
|
if (mIsInitializedFromContent) {
|
|
|
|
// Update the attribute and display it
|
|
|
|
SetFrameSelected(aIndex, aSelected);
|
|
|
|
} else {
|
|
|
|
// Update the attribute without displaying it
|
|
|
|
nsIContent* content = GetOptionContent(aIndex);
|
|
|
|
NS_ASSERTION(nsnull != content, "Failed to retrieve option content");
|
|
|
|
nsCOMPtr<nsIAtom> selectedAtom ( dont_QueryInterface(NS_NewAtom(kMozSelected)));
|
|
|
|
if (aSelected) {
|
|
|
|
content->SetAttribute(kNameSpaceID_None, selectedAtom, "", PR_FALSE);
|
|
|
|
} else {
|
|
|
|
content->UnsetAttribute(kNameSpaceID_None, selectedAtom, PR_FALSE);
|
|
|
|
}
|
|
|
|
NS_IF_RELEASE(content);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Set a single item in the listbox to selected.
|
|
|
|
|
|
|
|
void
|
|
|
|
nsListControlFrame::SetSelectedIndex(PRInt32 aIndex, nsIContent *aContent)
|
|
|
|
{
|
|
|
|
SetContentSelectedAttribute(aIndex, PR_TRUE);
|
|
|
|
mSelectedContent = aContent;
|
|
|
|
mSelectedIndex = aIndex;
|
|
|
|
|
|
|
|
// Get the selected string from the content
|
|
|
|
nsIDOMHTMLOptionElement* option = nsnull;
|
|
|
|
nsresult rv = aContent->QueryInterface(kIDOMHTMLOptionElementIID, (void**)&option);
|
|
|
|
if (NS_SUCCEEDED(rv)) {
|
|
|
|
nsAutoString text;
|
|
|
|
if (NS_CONTENT_ATTR_HAS_VALUE == option->GetText(text)) {
|
|
|
|
mSelectionStr = text;
|
|
|
|
}
|
|
|
|
NS_RELEASE(option);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Select the specified item in the listbox using control logic.
|
|
|
|
// If it a single selection listbox the previous selection will be
|
|
|
|
// de-selected.
|
|
|
|
|
|
|
|
void
|
|
|
|
nsListControlFrame::ToggleSelected(PRInt32 aIndex, nsIContent *aContent)
|
|
|
|
{
|
|
|
|
PRBool multiple;
|
|
|
|
GetMultiple(&multiple);
|
|
|
|
|
|
|
|
if (PR_TRUE == multiple) {
|
|
|
|
SetSelectedIndex(aIndex, aContent);
|
|
|
|
} else {
|
|
|
|
if (mSelectedIndex != kNothingSelected) {
|
|
|
|
SetContentSelectedAttribute(aIndex, PR_FALSE);
|
|
|
|
}
|
|
|
|
SetSelectedIndex(aIndex, aContent);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Select the specified item in the listbox using
|
|
|
|
|
|
|
|
void
|
|
|
|
nsListControlFrame::SelectIndex(PRInt32 aIndex)
|
|
|
|
{
|
|
|
|
nsIDOMHTMLCollection* options = GetOptions(mContent);
|
|
|
|
nsIDOMHTMLOptionElement* optionElement = GetOption(*options, aIndex);
|
|
|
|
nsIContent *content = nsnull;
|
|
|
|
nsresult result = optionElement->QueryInterface(kIContentIID, (void**) &content);
|
|
|
|
ToggleSelected(aIndex, content);
|
|
|
|
NS_RELEASE(content);
|
|
|
|
NS_RELEASE(optionElement);
|
|
|
|
NS_RELEASE(options);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsListControlFrame::SetProperty(nsIAtom* aName, const nsString& aValue)
|
1999-01-25 22:16:27 +00:00
|
|
|
{
|
1999-04-12 22:14:31 +00:00
|
|
|
if (nsHTMLAtoms::selected == aName) {
|
|
|
|
return NS_ERROR_INVALID_ARG; // Selected is readonly according to spec.
|
|
|
|
} else if (nsHTMLAtoms::selectedindex == aName) {
|
|
|
|
PRInt32 error = 0;
|
|
|
|
PRInt32 selectedIndex = aValue.ToInteger(&error, 10); // Get index from aValue
|
|
|
|
if (error) {
|
|
|
|
return NS_ERROR_INVALID_ARG; // Couldn't convert to integer
|
|
|
|
} else {
|
1999-05-07 20:30:16 +00:00
|
|
|
// Select the specified item in the list box.
|
|
|
|
SelectIndex(selectedIndex);
|
1999-04-12 22:14:31 +00:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
//XXX: TODO What about all othe other properties that form elements can set here?
|
|
|
|
// return nsFormControlFrame::SetProperty(aName, aValue);
|
|
|
|
}
|
1999-01-25 22:16:27 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
1999-05-07 20:30:16 +00:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsListControlFrame::GetProperty(nsIAtom* aName, nsString& aValue)
|
1999-03-06 19:43:13 +00:00
|
|
|
{
|
1999-04-12 22:14:31 +00:00
|
|
|
// Get the selected value of option from local cache (optimization vs. widget)
|
|
|
|
if (nsHTMLAtoms::selected == aName) {
|
|
|
|
PRInt32 error = 0;
|
|
|
|
PRBool selected = PR_FALSE;
|
|
|
|
PRInt32 index = aValue.ToInteger(&error, 10); // Get index from aValue
|
|
|
|
if (error == 0)
|
|
|
|
selected = IsFrameSelected(index);
|
|
|
|
|
|
|
|
nsFormControlHelper::GetBoolString(selected, aValue);
|
|
|
|
|
|
|
|
// For selectedIndex, get the value from the widget
|
|
|
|
} else if (nsHTMLAtoms::selectedindex == aName) {
|
|
|
|
// Spin through loooking for the first selection in the list
|
|
|
|
PRInt32 index = 0;
|
|
|
|
PRInt32 maxOptions = GetNumberOfOptions();
|
1999-05-07 20:30:16 +00:00
|
|
|
PRInt32 selectedIndex = kNothingSelected;
|
1999-04-12 22:14:31 +00:00
|
|
|
for (index = 0; index < maxOptions; index++) {
|
|
|
|
PRBool isSelected = PR_FALSE;
|
|
|
|
|
|
|
|
if (PR_TRUE == IsFrameSelected(index)) {
|
|
|
|
selectedIndex = isSelected;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
aValue.Append(selectedIndex, 10);
|
|
|
|
} else {
|
|
|
|
//XXX: TODO: What about all of the other form properties???
|
|
|
|
//return nsFormControlFrame::GetProperty(aName, aValue);
|
|
|
|
}
|
|
|
|
|
1999-03-06 19:43:13 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
1999-03-28 22:22:54 +00:00
|
|
|
|