2007-03-22 10:30:00 -07:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
|
|
/* ***** BEGIN LICENSE BLOCK *****
|
|
|
|
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
|
|
|
*
|
|
|
|
* The contents of this file are subject to the Mozilla 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/MPL/
|
|
|
|
*
|
|
|
|
* 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.org code.
|
|
|
|
*
|
|
|
|
* The Initial Developer of the Original Code is
|
|
|
|
* Netscape Communications Corporation.
|
|
|
|
* Portions created by the Initial Developer are Copyright (C) 1998
|
|
|
|
* the Initial Developer. All Rights Reserved.
|
|
|
|
*
|
|
|
|
* Contributor(s):
|
|
|
|
* Pierre Phaneuf <pp@ludusdesign.com>
|
|
|
|
* Mats Palmgren <mats.palmgren@bredband.net>
|
|
|
|
*
|
|
|
|
* Alternatively, the contents of this file may be used under the terms of
|
|
|
|
* either of the GNU General Public License Version 2 or later (the "GPL"),
|
|
|
|
* or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
|
|
|
* in which case the provisions of the GPL or the LGPL are applicable instead
|
|
|
|
* of those above. If you wish to allow use of your version of this file only
|
|
|
|
* under the terms of either the GPL or the LGPL, and not to allow others to
|
|
|
|
* use your version of this file under the terms of the MPL, indicate your
|
|
|
|
* decision by deleting the provisions above and replace them with the notice
|
|
|
|
* and other provisions required by the GPL or the LGPL. If you do not delete
|
|
|
|
* the provisions above, a recipient may use your version of this file under
|
|
|
|
* the terms of any one of the MPL, the GPL or the LGPL.
|
|
|
|
*
|
|
|
|
* ***** END LICENSE BLOCK ***** */
|
|
|
|
#include "nsCOMPtr.h"
|
|
|
|
#include "nsReadableUtils.h"
|
|
|
|
#include "nsComboboxControlFrame.h"
|
2007-05-14 02:11:38 -07:00
|
|
|
#include "nsIDOMEventTarget.h"
|
2007-03-22 10:30:00 -07:00
|
|
|
#include "nsFrameManager.h"
|
|
|
|
#include "nsFormControlFrame.h"
|
|
|
|
#include "nsGfxButtonControlFrame.h"
|
|
|
|
#include "nsGkAtoms.h"
|
|
|
|
#include "nsCSSAnonBoxes.h"
|
|
|
|
#include "nsHTMLParts.h"
|
|
|
|
#include "nsIFormControl.h"
|
|
|
|
#include "nsINameSpaceManager.h"
|
|
|
|
#include "nsIDOMElement.h"
|
|
|
|
#include "nsIListControlFrame.h"
|
|
|
|
#include "nsIDOMHTMLCollection.h"
|
|
|
|
#include "nsIDOMHTMLSelectElement.h"
|
|
|
|
#include "nsIDOMHTMLOptionElement.h"
|
|
|
|
#include "nsIDOMNSHTMLOptionCollectn.h"
|
2010-04-21 07:53:42 -07:00
|
|
|
#include "nsPIDOMWindow.h"
|
2007-03-22 10:30:00 -07:00
|
|
|
#include "nsIPresShell.h"
|
|
|
|
#include "nsIDeviceContext.h"
|
|
|
|
#include "nsIView.h"
|
|
|
|
#include "nsIViewManager.h"
|
|
|
|
#include "nsEventDispatcher.h"
|
|
|
|
#include "nsIEventStateManager.h"
|
|
|
|
#include "nsIEventListenerManager.h"
|
|
|
|
#include "nsIDOMNode.h"
|
|
|
|
#include "nsIPrivateDOMEvent.h"
|
|
|
|
#include "nsISelectControlFrame.h"
|
|
|
|
#include "nsXPCOM.h"
|
|
|
|
#include "nsISupportsPrimitives.h"
|
|
|
|
#include "nsIComponentManager.h"
|
|
|
|
#include "nsContentUtils.h"
|
|
|
|
#include "nsTextFragment.h"
|
|
|
|
#include "nsCSSFrameConstructor.h"
|
|
|
|
#include "nsIDocument.h"
|
|
|
|
#include "nsINodeInfo.h"
|
|
|
|
#include "nsIScrollableFrame.h"
|
|
|
|
#include "nsListControlFrame.h"
|
|
|
|
#include "nsContentCID.h"
|
|
|
|
#ifdef ACCESSIBILITY
|
|
|
|
#include "nsIAccessibilityService.h"
|
|
|
|
#endif
|
|
|
|
#include "nsIServiceManager.h"
|
|
|
|
#include "nsIDOMNode.h"
|
|
|
|
#include "nsGUIEvent.h"
|
|
|
|
#include "nsAutoPtr.h"
|
|
|
|
#include "nsStyleSet.h"
|
|
|
|
#include "nsNodeInfoManager.h"
|
|
|
|
#include "nsContentCreatorFunctions.h"
|
|
|
|
#include "nsLayoutUtils.h"
|
|
|
|
#include "nsDisplayList.h"
|
|
|
|
#include "nsITheme.h"
|
|
|
|
#include "nsThemeConstants.h"
|
2009-12-18 11:27:57 -08:00
|
|
|
#include "nsPLDOMEvent.h"
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsComboboxControlFrame::RedisplayTextEvent::Run()
|
|
|
|
{
|
|
|
|
if (mControlFrame)
|
|
|
|
mControlFrame->HandleRedisplayTextEvent();
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
class nsPresState;
|
|
|
|
|
|
|
|
#define FIX_FOR_BUG_53259
|
|
|
|
|
|
|
|
// Drop down list event management.
|
|
|
|
// The combo box uses the following strategy for managing the drop-down list.
|
|
|
|
// If the combo box or it's arrow button is clicked on the drop-down list is displayed
|
|
|
|
// If mouse exit's the combo box with the drop-down list displayed the drop-down list
|
|
|
|
// is asked to capture events
|
|
|
|
// The drop-down list will capture all events including mouse down and up and will always
|
|
|
|
// return with ListWasSelected method call regardless of whether an item in the list was
|
|
|
|
// actually selected.
|
|
|
|
// The ListWasSelected code will turn off mouse-capture for the drop-down list.
|
|
|
|
// The drop-down list does not explicitly set capture when it is in the drop-down mode.
|
|
|
|
|
|
|
|
|
|
|
|
//XXX: This is temporary. It simulates pseudo states by using a attribute selector on
|
|
|
|
|
|
|
|
const PRInt32 kSizeNotSet = -1;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Helper class that listens to the combo boxes button. If the button is pressed the
|
|
|
|
* combo box is toggled to open or close. this is used by Accessibility which presses
|
|
|
|
* that button Programmatically.
|
|
|
|
*/
|
|
|
|
class nsComboButtonListener: public nsIDOMMouseListener
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
|
|
|
|
NS_DECL_ISUPPORTS
|
|
|
|
NS_IMETHOD HandleEvent(nsIDOMEvent* anEvent) { return PR_FALSE; }
|
|
|
|
NS_IMETHOD MouseDown(nsIDOMEvent* aMouseEvent) { return PR_FALSE; }
|
|
|
|
NS_IMETHOD MouseUp(nsIDOMEvent* aMouseEvent) { return PR_FALSE; }
|
|
|
|
NS_IMETHOD MouseDblClick(nsIDOMEvent* aMouseEvent) { return PR_FALSE; }
|
|
|
|
NS_IMETHOD MouseOver(nsIDOMEvent* aMouseEvent) { return PR_FALSE; }
|
|
|
|
NS_IMETHOD MouseOut(nsIDOMEvent* aMouseEvent) { return PR_FALSE; }
|
|
|
|
|
|
|
|
NS_IMETHOD MouseClick(nsIDOMEvent* aMouseEvent)
|
|
|
|
{
|
|
|
|
mComboBox->ShowDropDown(!mComboBox->IsDroppedDown());
|
2007-05-17 04:12:30 -07:00
|
|
|
return NS_OK;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
nsComboButtonListener(nsComboboxControlFrame* aCombobox)
|
|
|
|
{
|
|
|
|
mComboBox = aCombobox;
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual ~nsComboButtonListener() {}
|
|
|
|
|
|
|
|
nsComboboxControlFrame* mComboBox;
|
|
|
|
};
|
|
|
|
|
2008-04-06 05:28:34 -07:00
|
|
|
NS_IMPL_ISUPPORTS2(nsComboButtonListener,
|
|
|
|
nsIDOMMouseListener,
|
|
|
|
nsIDOMEventListener)
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
// static class data member for Bug 32920
|
|
|
|
nsComboboxControlFrame * nsComboboxControlFrame::mFocused = nsnull;
|
|
|
|
|
|
|
|
nsIFrame*
|
|
|
|
NS_NewComboboxControlFrame(nsIPresShell* aPresShell, nsStyleContext* aContext, PRUint32 aStateFlags)
|
|
|
|
{
|
|
|
|
nsComboboxControlFrame* it = new (aPresShell) nsComboboxControlFrame(aContext);
|
|
|
|
|
|
|
|
if (it) {
|
|
|
|
// set the state flags (if any are provided)
|
|
|
|
it->AddStateBits(aStateFlags);
|
|
|
|
}
|
|
|
|
|
|
|
|
return it;
|
|
|
|
}
|
|
|
|
|
2009-09-12 09:49:24 -07:00
|
|
|
NS_IMPL_FRAMEARENA_HELPERS(nsComboboxControlFrame)
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
//-----------------------------------------------------------
|
|
|
|
// Reflow Debugging Macros
|
|
|
|
// These let us "see" how many reflow counts are happening
|
|
|
|
//-----------------------------------------------------------
|
|
|
|
#ifdef DO_REFLOW_COUNTER
|
|
|
|
|
|
|
|
#define MAX_REFLOW_CNT 1024
|
|
|
|
static PRInt32 gTotalReqs = 0;;
|
|
|
|
static PRInt32 gTotalReflows = 0;;
|
|
|
|
static PRInt32 gReflowControlCntRQ[MAX_REFLOW_CNT];
|
|
|
|
static PRInt32 gReflowControlCnt[MAX_REFLOW_CNT];
|
|
|
|
static PRInt32 gReflowInx = -1;
|
|
|
|
|
|
|
|
#define REFLOW_COUNTER() \
|
|
|
|
if (mReflowId > -1) \
|
|
|
|
gReflowControlCnt[mReflowId]++;
|
|
|
|
|
|
|
|
#define REFLOW_COUNTER_REQUEST() \
|
|
|
|
if (mReflowId > -1) \
|
|
|
|
gReflowControlCntRQ[mReflowId]++;
|
|
|
|
|
|
|
|
#define REFLOW_COUNTER_DUMP(__desc) \
|
|
|
|
if (mReflowId > -1) {\
|
|
|
|
gTotalReqs += gReflowControlCntRQ[mReflowId];\
|
|
|
|
gTotalReflows += gReflowControlCnt[mReflowId];\
|
|
|
|
printf("** Id:%5d %s RF: %d RQ: %d %d/%d %5.2f\n", \
|
|
|
|
mReflowId, (__desc), \
|
|
|
|
gReflowControlCnt[mReflowId], \
|
|
|
|
gReflowControlCntRQ[mReflowId],\
|
|
|
|
gTotalReflows, gTotalReqs, float(gTotalReflows)/float(gTotalReqs)*100.0f);\
|
|
|
|
}
|
|
|
|
|
|
|
|
#define REFLOW_COUNTER_INIT() \
|
|
|
|
if (gReflowInx < MAX_REFLOW_CNT) { \
|
|
|
|
gReflowInx++; \
|
|
|
|
mReflowId = gReflowInx; \
|
|
|
|
gReflowControlCnt[mReflowId] = 0; \
|
|
|
|
gReflowControlCntRQ[mReflowId] = 0; \
|
|
|
|
} else { \
|
|
|
|
mReflowId = -1; \
|
|
|
|
}
|
|
|
|
|
|
|
|
// reflow messages
|
|
|
|
#define REFLOW_DEBUG_MSG(_msg1) printf((_msg1))
|
|
|
|
#define REFLOW_DEBUG_MSG2(_msg1, _msg2) printf((_msg1), (_msg2))
|
|
|
|
#define REFLOW_DEBUG_MSG3(_msg1, _msg2, _msg3) printf((_msg1), (_msg2), (_msg3))
|
|
|
|
#define REFLOW_DEBUG_MSG4(_msg1, _msg2, _msg3, _msg4) printf((_msg1), (_msg2), (_msg3), (_msg4))
|
|
|
|
|
|
|
|
#else //-------------
|
|
|
|
|
|
|
|
#define REFLOW_COUNTER_REQUEST()
|
|
|
|
#define REFLOW_COUNTER()
|
|
|
|
#define REFLOW_COUNTER_DUMP(__desc)
|
|
|
|
#define REFLOW_COUNTER_INIT()
|
|
|
|
|
|
|
|
#define REFLOW_DEBUG_MSG(_msg)
|
|
|
|
#define REFLOW_DEBUG_MSG2(_msg1, _msg2)
|
|
|
|
#define REFLOW_DEBUG_MSG3(_msg1, _msg2, _msg3)
|
|
|
|
#define REFLOW_DEBUG_MSG4(_msg1, _msg2, _msg3, _msg4)
|
|
|
|
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
//------------------------------------------
|
|
|
|
// This is for being VERY noisy
|
|
|
|
//------------------------------------------
|
|
|
|
#ifdef DO_VERY_NOISY
|
|
|
|
#define REFLOW_NOISY_MSG(_msg1) printf((_msg1))
|
|
|
|
#define REFLOW_NOISY_MSG2(_msg1, _msg2) printf((_msg1), (_msg2))
|
|
|
|
#define REFLOW_NOISY_MSG3(_msg1, _msg2, _msg3) printf((_msg1), (_msg2), (_msg3))
|
|
|
|
#define REFLOW_NOISY_MSG4(_msg1, _msg2, _msg3, _msg4) printf((_msg1), (_msg2), (_msg3), (_msg4))
|
|
|
|
#else
|
|
|
|
#define REFLOW_NOISY_MSG(_msg)
|
|
|
|
#define REFLOW_NOISY_MSG2(_msg1, _msg2)
|
|
|
|
#define REFLOW_NOISY_MSG3(_msg1, _msg2, _msg3)
|
|
|
|
#define REFLOW_NOISY_MSG4(_msg1, _msg2, _msg3, _msg4)
|
|
|
|
#endif
|
|
|
|
|
|
|
|
//------------------------------------------
|
|
|
|
// Displays value in pixels or twips
|
|
|
|
//------------------------------------------
|
|
|
|
#ifdef DO_PIXELS
|
|
|
|
#define PX(__v) __v / 15
|
|
|
|
#else
|
|
|
|
#define PX(__v) __v
|
|
|
|
#endif
|
|
|
|
|
|
|
|
//------------------------------------------------------
|
|
|
|
//-- Done with macros
|
|
|
|
//------------------------------------------------------
|
|
|
|
|
|
|
|
nsComboboxControlFrame::nsComboboxControlFrame(nsStyleContext* aContext)
|
2008-12-29 07:07:38 -08:00
|
|
|
: nsBlockFrame(aContext),
|
2007-03-22 10:30:00 -07:00
|
|
|
mDisplayWidth(0)
|
|
|
|
{
|
|
|
|
mListControlFrame = nsnull;
|
|
|
|
mDroppedDown = PR_FALSE;
|
|
|
|
mDisplayFrame = nsnull;
|
|
|
|
mButtonFrame = nsnull;
|
|
|
|
mDropdownFrame = nsnull;
|
|
|
|
|
|
|
|
mInRedisplayText = PR_FALSE;
|
|
|
|
|
|
|
|
mRecentSelectedIndex = NS_SKIP_NOTIFY_INDEX;
|
|
|
|
|
|
|
|
REFLOW_COUNTER_INIT()
|
|
|
|
}
|
|
|
|
|
|
|
|
//--------------------------------------------------------------
|
|
|
|
nsComboboxControlFrame::~nsComboboxControlFrame()
|
|
|
|
{
|
|
|
|
REFLOW_COUNTER_DUMP("nsCCF");
|
|
|
|
}
|
|
|
|
|
|
|
|
//--------------------------------------------------------------
|
2009-01-12 11:20:59 -08:00
|
|
|
|
|
|
|
NS_QUERYFRAME_HEAD(nsComboboxControlFrame)
|
|
|
|
NS_QUERYFRAME_ENTRY(nsIComboboxControlFrame)
|
|
|
|
NS_QUERYFRAME_ENTRY(nsIFormControlFrame)
|
|
|
|
NS_QUERYFRAME_ENTRY(nsIAnonymousContentCreator)
|
|
|
|
NS_QUERYFRAME_ENTRY(nsISelectControlFrame)
|
|
|
|
NS_QUERYFRAME_ENTRY(nsIStatefulFrame)
|
|
|
|
NS_QUERYFRAME_TAIL_INHERITING(nsBlockFrame)
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
#ifdef ACCESSIBILITY
|
2010-06-28 05:02:03 -07:00
|
|
|
already_AddRefed<nsAccessible>
|
|
|
|
nsComboboxControlFrame::CreateAccessible()
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
nsCOMPtr<nsIAccessibilityService> accService = do_GetService("@mozilla.org/accessibilityService;1");
|
|
|
|
|
|
|
|
if (accService) {
|
2010-06-28 05:02:03 -07:00
|
|
|
return accService->CreateHTMLComboboxAccessible(mContent,
|
|
|
|
PresContext()->PresShell());
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2010-06-28 05:02:03 -07:00
|
|
|
return nsnull;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
void
|
|
|
|
nsComboboxControlFrame::SetFocus(PRBool aOn, PRBool aRepaint)
|
|
|
|
{
|
|
|
|
nsWeakFrame weakFrame(this);
|
|
|
|
if (aOn) {
|
|
|
|
nsListControlFrame::ComboboxFocusSet();
|
|
|
|
mFocused = this;
|
|
|
|
} else {
|
|
|
|
mFocused = nsnull;
|
|
|
|
if (mDroppedDown) {
|
2007-05-17 04:12:30 -07:00
|
|
|
mListControlFrame->ComboboxFinish(mDisplayedIndex); // might destroy us
|
|
|
|
if (!weakFrame.IsAlive()) {
|
|
|
|
return;
|
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
// May delete |this|.
|
|
|
|
mListControlFrame->FireOnChange();
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!weakFrame.IsAlive()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// This is needed on a temporary basis. It causes the focus
|
|
|
|
// rect to be drawn. This is much faster than ReResolvingStyle
|
|
|
|
// Bug 32920
|
2008-09-18 02:47:21 -07:00
|
|
|
Invalidate(nsRect(0,0,mRect.width,mRect.height));
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
// Make sure the content area gets updated for where the dropdown was
|
|
|
|
// This is only needed for embedding, the focus may go to
|
|
|
|
// the chrome that is not part of the Gecko system (Bug 83493)
|
|
|
|
// XXX this is rather inefficient
|
2009-03-11 08:43:08 -07:00
|
|
|
nsIViewManager* vm = PresContext()->GetPresShell()->GetViewManager();
|
2007-03-22 10:30:00 -07:00
|
|
|
if (vm) {
|
|
|
|
vm->UpdateAllViews(NS_VMREFRESH_NO_SYNC);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsComboboxControlFrame::ShowPopup(PRBool aShowPopup)
|
|
|
|
{
|
|
|
|
nsIView* view = mDropdownFrame->GetView();
|
|
|
|
nsIViewManager* viewManager = view->GetViewManager();
|
|
|
|
|
|
|
|
if (aShowPopup) {
|
|
|
|
nsRect rect = mDropdownFrame->GetRect();
|
|
|
|
rect.x = rect.y = 0;
|
|
|
|
viewManager->ResizeView(view, rect);
|
|
|
|
viewManager->SetViewVisibility(view, nsViewVisibility_kShow);
|
|
|
|
} else {
|
|
|
|
viewManager->SetViewVisibility(view, nsViewVisibility_kHide);
|
|
|
|
nsRect emptyRect(0, 0, 0, 0);
|
|
|
|
viewManager->ResizeView(view, emptyRect);
|
|
|
|
}
|
|
|
|
|
|
|
|
// fire a popup dom event
|
|
|
|
nsEventStatus status = nsEventStatus_eIgnore;
|
|
|
|
nsMouseEvent event(PR_TRUE, aShowPopup ?
|
|
|
|
NS_XUL_POPUP_SHOWING : NS_XUL_POPUP_HIDING, nsnull,
|
|
|
|
nsMouseEvent::eReal);
|
|
|
|
|
2007-03-30 14:11:41 -07:00
|
|
|
nsCOMPtr<nsIPresShell> shell = PresContext()->GetPresShell();
|
2007-03-22 10:30:00 -07:00
|
|
|
if (shell)
|
|
|
|
shell->HandleDOMEventWithTarget(mContent, &event, &status);
|
|
|
|
}
|
|
|
|
|
2007-05-17 04:12:30 -07:00
|
|
|
PRBool
|
2009-09-01 19:46:47 -07:00
|
|
|
nsComboboxControlFrame::ShowList(PRBool aShowList)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2007-05-17 04:12:30 -07:00
|
|
|
nsCOMPtr<nsIPresShell> shell = PresContext()->GetPresShell();
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2007-05-17 04:12:30 -07:00
|
|
|
nsWeakFrame weakFrame(this);
|
|
|
|
ShowPopup(aShowList); // might destroy us
|
|
|
|
if (!weakFrame.IsAlive()) {
|
|
|
|
return PR_FALSE;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2007-05-17 04:12:30 -07:00
|
|
|
mDroppedDown = aShowList;
|
|
|
|
if (mDroppedDown) {
|
|
|
|
// The listcontrol frame will call back to the nsComboboxControlFrame's
|
|
|
|
// ListWasSelected which will stop the capture.
|
2007-03-22 10:30:00 -07:00
|
|
|
mListControlFrame->AboutToDropDown();
|
|
|
|
mListControlFrame->CaptureMouseEvents(PR_TRUE);
|
|
|
|
}
|
|
|
|
|
2007-08-21 19:57:06 -07:00
|
|
|
// XXXbz so why do we need to flush here, exactly?
|
|
|
|
shell->GetDocument()->FlushPendingNotifications(Flush_Layout);
|
2007-05-17 04:12:30 -07:00
|
|
|
if (!weakFrame.IsAlive()) {
|
|
|
|
return PR_FALSE;
|
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2009-01-12 11:20:59 -08:00
|
|
|
nsIFrame* listFrame = do_QueryFrame(mListControlFrame);
|
2007-05-17 04:12:30 -07:00
|
|
|
if (listFrame) {
|
|
|
|
nsIView* view = listFrame->GetView();
|
|
|
|
NS_ASSERTION(view, "nsComboboxControlFrame view is null");
|
|
|
|
if (view) {
|
|
|
|
nsIWidget* widget = view->GetWidget();
|
|
|
|
if (widget)
|
2009-12-22 15:49:33 -08:00
|
|
|
widget->CaptureRollupEvents(this, nsnull, mDroppedDown, mDroppedDown);
|
2007-05-17 04:12:30 -07:00
|
|
|
}
|
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2007-05-17 04:12:30 -07:00
|
|
|
return weakFrame.IsAlive();
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
nsComboboxControlFrame::ReflowDropdown(nsPresContext* aPresContext,
|
|
|
|
const nsHTMLReflowState& aReflowState)
|
|
|
|
{
|
|
|
|
// All we want out of it later on, really, is the height of a row, so we
|
|
|
|
// don't even need to cache mDropdownFrame's ascent or anything. If we don't
|
|
|
|
// need to reflow it, just bail out here.
|
|
|
|
if (!aReflowState.ShouldReflowAllKids() &&
|
2007-05-06 12:16:51 -07:00
|
|
|
!NS_SUBTREE_DIRTY(mDropdownFrame)) {
|
2007-03-22 10:30:00 -07:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
// XXXbz this will, for small-height dropdowns, have extra space on the right
|
|
|
|
// edge for the scrollbar we don't show... but that's the best we can do here
|
|
|
|
// for now.
|
|
|
|
nsSize availSize(aReflowState.availableWidth, NS_UNCONSTRAINEDSIZE);
|
|
|
|
nsHTMLReflowState kidReflowState(aPresContext, aReflowState, mDropdownFrame,
|
|
|
|
availSize);
|
|
|
|
|
|
|
|
// If the dropdown's intrinsic width is narrower than our specified width,
|
|
|
|
// then expand it out. We want our border-box width to end up the same as
|
|
|
|
// the dropdown's so account for both sets of mComputedBorderPadding.
|
|
|
|
nscoord forcedWidth = aReflowState.ComputedWidth() +
|
|
|
|
aReflowState.mComputedBorderPadding.LeftRight() -
|
|
|
|
kidReflowState.mComputedBorderPadding.LeftRight();
|
2009-09-16 08:01:36 -07:00
|
|
|
kidReflowState.SetComputedWidth(NS_MAX(kidReflowState.ComputedWidth(),
|
2007-03-22 10:30:00 -07:00
|
|
|
forcedWidth));
|
|
|
|
|
|
|
|
// ensure we start off hidden
|
|
|
|
if (GetStateBits() & NS_FRAME_FIRST_REFLOW) {
|
|
|
|
nsIView* view = mDropdownFrame->GetView();
|
|
|
|
nsIViewManager* viewManager = view->GetViewManager();
|
|
|
|
viewManager->SetViewVisibility(view, nsViewVisibility_kHide);
|
|
|
|
nsRect emptyRect(0, 0, 0, 0);
|
|
|
|
viewManager->ResizeView(view, emptyRect);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Allow the child to move/size/change-visibility its view if it's currently
|
|
|
|
// dropped down
|
2008-09-03 14:35:52 -07:00
|
|
|
PRInt32 flags = NS_FRAME_NO_MOVE_FRAME | NS_FRAME_NO_VISIBILITY | NS_FRAME_NO_SIZE_VIEW;
|
2007-03-22 10:30:00 -07:00
|
|
|
if (mDroppedDown) {
|
|
|
|
flags = 0;
|
|
|
|
}
|
|
|
|
nsRect rect = mDropdownFrame->GetRect();
|
|
|
|
nsHTMLReflowMetrics desiredSize;
|
|
|
|
nsReflowStatus ignoredStatus;
|
|
|
|
nsresult rv = ReflowChild(mDropdownFrame, aPresContext, desiredSize,
|
|
|
|
kidReflowState, rect.x, rect.y, flags,
|
|
|
|
ignoredStatus);
|
|
|
|
|
|
|
|
// Set the child's width and height to it's desired size
|
|
|
|
FinishReflowChild(mDropdownFrame, aPresContext, &kidReflowState,
|
|
|
|
desiredSize, rect.x, rect.y, flags);
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
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
|
|
|
|
// frame.
|
|
|
|
|
|
|
|
// Note: As first glance, it appears that you could simply get the absolute bounding box for the
|
|
|
|
// dropdown list by first getting its view, then getting the view's nsIWidget, then asking the nsIWidget
|
|
|
|
// for it's AbsoluteBounds. The problem with this approach, is that the dropdown lists y location can
|
|
|
|
// change based on whether the dropdown is placed below or above the display frame.
|
|
|
|
// The approach, taken here is to get use the absolute position of the display frame and use it's location
|
|
|
|
// to determine if the dropdown will go offscreen.
|
|
|
|
|
|
|
|
// Use the height calculated for the area frame so it includes both
|
|
|
|
// the display and button heights.
|
|
|
|
nscoord dropdownYOffset = GetRect().height;
|
|
|
|
nsSize dropdownSize = mDropdownFrame->GetSize();
|
|
|
|
|
2009-08-17 20:21:07 -07:00
|
|
|
nsRect screen = nsFormControlFrame::GetUsableScreenRect(PresContext());
|
|
|
|
|
|
|
|
// Check to see if the drop-down list will go offscreen
|
|
|
|
if (GetScreenRectInAppUnits().YMost() + dropdownSize.height > screen.YMost()) {
|
|
|
|
// move the dropdown list up
|
|
|
|
dropdownYOffset = - (dropdownSize.height);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
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.
|
|
|
|
dropdownPosition.x = GetRect().width - dropdownSize.width;
|
|
|
|
} else {
|
|
|
|
dropdownPosition.x = 0;
|
|
|
|
}
|
|
|
|
dropdownPosition.y = dropdownYOffset;
|
|
|
|
|
|
|
|
mDropdownFrame->SetPosition(dropdownPosition);
|
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------
|
|
|
|
//
|
|
|
|
//----------------------------------------------------------
|
|
|
|
#ifdef DO_REFLOW_DEBUG
|
|
|
|
static int myCounter = 0;
|
|
|
|
|
|
|
|
static void printSize(char * aDesc, nscoord aSize)
|
|
|
|
{
|
|
|
|
printf(" %s: ", aDesc);
|
|
|
|
if (aSize == NS_UNCONSTRAINEDSIZE) {
|
|
|
|
printf("UC");
|
|
|
|
} else {
|
|
|
|
printf("%d", PX(aSize));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
//-------------------------------------------------------------------
|
|
|
|
//-- Main Reflow for the Combobox
|
|
|
|
//-------------------------------------------------------------------
|
|
|
|
|
|
|
|
nscoord
|
2007-12-02 22:41:38 -08:00
|
|
|
nsComboboxControlFrame::GetIntrinsicWidth(nsIRenderingContext* aRenderingContext,
|
|
|
|
nsLayoutUtils::IntrinsicWidthType aType)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2007-05-28 22:31:04 -07:00
|
|
|
// get the scrollbar width, we'll use this later
|
|
|
|
nscoord scrollbarWidth = 0;
|
|
|
|
nsPresContext* presContext = PresContext();
|
|
|
|
if (mListControlFrame) {
|
2009-01-12 11:20:59 -08:00
|
|
|
nsIScrollableFrame* scrollable = do_QueryFrame(mListControlFrame);
|
2007-05-28 22:31:04 -07:00
|
|
|
NS_ASSERTION(scrollable, "List must be a scrollable frame");
|
2008-04-09 21:39:41 -07:00
|
|
|
scrollbarWidth =
|
|
|
|
scrollable->GetDesiredScrollbarSizes(presContext, aRenderingContext).LeftRight();
|
2007-05-28 22:31:04 -07:00
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2007-12-02 22:41:38 -08:00
|
|
|
nscoord displayWidth = 0;
|
2007-05-28 22:31:04 -07:00
|
|
|
if (NS_LIKELY(mDisplayFrame)) {
|
2007-12-02 22:41:38 -08:00
|
|
|
displayWidth = nsLayoutUtils::IntrinsicForContainer(aRenderingContext,
|
|
|
|
mDisplayFrame,
|
|
|
|
aType);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2007-05-28 22:31:04 -07:00
|
|
|
if (mDropdownFrame) {
|
2007-12-02 22:41:38 -08:00
|
|
|
nscoord dropdownContentWidth;
|
|
|
|
if (aType == nsLayoutUtils::MIN_WIDTH) {
|
|
|
|
dropdownContentWidth = mDropdownFrame->GetMinWidth(aRenderingContext);
|
|
|
|
} else {
|
|
|
|
NS_ASSERTION(aType == nsLayoutUtils::PREF_WIDTH, "Unexpected type");
|
|
|
|
dropdownContentWidth = mDropdownFrame->GetPrefWidth(aRenderingContext);
|
|
|
|
}
|
2007-12-18 11:26:35 -08:00
|
|
|
dropdownContentWidth = NSCoordSaturatingSubtract(dropdownContentWidth,
|
|
|
|
scrollbarWidth,
|
|
|
|
nscoord_MAX);
|
2007-12-02 22:41:38 -08:00
|
|
|
|
2009-09-16 08:01:36 -07:00
|
|
|
displayWidth = NS_MAX(dropdownContentWidth, displayWidth);
|
2007-05-04 23:20:10 -07:00
|
|
|
}
|
|
|
|
|
2007-05-28 22:31:04 -07:00
|
|
|
// add room for the dropmarker button if there is one
|
|
|
|
if (!IsThemed() || presContext->GetTheme()->ThemeNeedsComboboxDropmarker())
|
2007-12-02 22:41:38 -08:00
|
|
|
displayWidth += scrollbarWidth;
|
|
|
|
|
|
|
|
return displayWidth;
|
2007-05-28 22:31:04 -07:00
|
|
|
|
2007-12-02 22:41:38 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
nscoord
|
|
|
|
nsComboboxControlFrame::GetMinWidth(nsIRenderingContext *aRenderingContext)
|
|
|
|
{
|
|
|
|
nscoord minWidth;
|
|
|
|
DISPLAY_MIN_WIDTH(this, minWidth);
|
|
|
|
minWidth = GetIntrinsicWidth(aRenderingContext, nsLayoutUtils::MIN_WIDTH);
|
|
|
|
return minWidth;
|
|
|
|
}
|
|
|
|
|
|
|
|
nscoord
|
|
|
|
nsComboboxControlFrame::GetPrefWidth(nsIRenderingContext *aRenderingContext)
|
|
|
|
{
|
|
|
|
nscoord prefWidth;
|
|
|
|
DISPLAY_PREF_WIDTH(this, prefWidth);
|
|
|
|
prefWidth = GetIntrinsicWidth(aRenderingContext, nsLayoutUtils::PREF_WIDTH);
|
|
|
|
return prefWidth;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsComboboxControlFrame::Reflow(nsPresContext* aPresContext,
|
|
|
|
nsHTMLReflowMetrics& aDesiredSize,
|
|
|
|
const nsHTMLReflowState& aReflowState,
|
|
|
|
nsReflowStatus& aStatus)
|
|
|
|
{
|
|
|
|
// Constraints we try to satisfy:
|
|
|
|
|
|
|
|
// 1) Default width of button is the vertical scrollbar size
|
|
|
|
// 2) If the width of button is bigger than our width, set width of
|
|
|
|
// button to 0.
|
|
|
|
// 3) Default height of button is height of display area
|
|
|
|
// 4) Width of display area is whatever is left over from our width after
|
|
|
|
// allocating width for the button.
|
|
|
|
// 5) Height of display area is GetHeightOfARow() on the
|
|
|
|
// mListControlFrame.
|
|
|
|
|
|
|
|
if (!mDisplayFrame || !mButtonFrame || !mDropdownFrame) {
|
|
|
|
NS_ERROR("Why did the frame constructor allow this to happen? Fix it!!");
|
|
|
|
return NS_ERROR_UNEXPECTED;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Make sure the displayed text is the same as the selected option, bug 297389.
|
|
|
|
PRInt32 selectedIndex;
|
|
|
|
nsAutoString selectedOptionText;
|
|
|
|
if (!mDroppedDown) {
|
|
|
|
selectedIndex = mListControlFrame->GetSelectedIndex();
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
// In dropped down mode the "selected index" is the hovered menu item,
|
|
|
|
// we want the last selected item which is |mDisplayedIndex| in this case.
|
|
|
|
selectedIndex = mDisplayedIndex;
|
|
|
|
}
|
|
|
|
if (selectedIndex != -1) {
|
|
|
|
mListControlFrame->GetOptionText(selectedIndex, selectedOptionText);
|
|
|
|
}
|
|
|
|
if (mDisplayedOptionText != selectedOptionText) {
|
|
|
|
RedisplayText(selectedIndex);
|
|
|
|
}
|
|
|
|
|
|
|
|
// First reflow our dropdown so that we know how tall we should be.
|
|
|
|
ReflowDropdown(aPresContext, aReflowState);
|
|
|
|
|
|
|
|
// Get the width of the vertical scrollbar. That will be the width of the
|
|
|
|
// dropdown button.
|
2007-05-17 20:04:04 -07:00
|
|
|
nscoord buttonWidth;
|
|
|
|
const nsStyleDisplay *disp = GetStyleDisplay();
|
|
|
|
if (IsThemed(disp) && !aPresContext->GetTheme()->ThemeNeedsComboboxDropmarker()) {
|
2007-03-22 10:30:00 -07:00
|
|
|
buttonWidth = 0;
|
|
|
|
}
|
2007-05-17 20:04:04 -07:00
|
|
|
else {
|
2009-01-12 11:20:59 -08:00
|
|
|
nsIScrollableFrame* scrollable = do_QueryFrame(mListControlFrame);
|
2007-05-17 20:04:04 -07:00
|
|
|
NS_ASSERTION(scrollable, "List must be a scrollable frame");
|
2008-04-09 21:39:41 -07:00
|
|
|
buttonWidth =
|
|
|
|
scrollable->GetDesiredScrollbarSizes(PresContext(),
|
|
|
|
aReflowState.rendContext).LeftRight();
|
2007-05-17 20:04:04 -07:00
|
|
|
if (buttonWidth > aReflowState.ComputedWidth()) {
|
|
|
|
buttonWidth = 0;
|
|
|
|
}
|
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
mDisplayWidth = aReflowState.ComputedWidth() - buttonWidth;
|
|
|
|
|
2008-12-29 07:07:38 -08:00
|
|
|
nsresult rv = nsBlockFrame::Reflow(aPresContext, aDesiredSize, aReflowState,
|
2007-03-22 10:30:00 -07:00
|
|
|
aStatus);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
// Now set the correct width and height on our button. The width we need to
|
|
|
|
// set always, the height only if we had an auto height.
|
|
|
|
nsRect buttonRect = mButtonFrame->GetRect();
|
|
|
|
// If we have a non-intrinsic computed height, our kids should have sized
|
|
|
|
// themselves properly on their own.
|
2007-08-02 11:08:05 -07:00
|
|
|
if (aReflowState.ComputedHeight() == NS_INTRINSICSIZE) {
|
2007-03-22 10:30:00 -07:00
|
|
|
// The display frame is going to be the right height and width at this
|
|
|
|
// point. Use its height as the button height.
|
|
|
|
nsRect displayRect = mDisplayFrame->GetRect();
|
|
|
|
buttonRect.height = displayRect.height;
|
|
|
|
buttonRect.y = displayRect.y;
|
|
|
|
}
|
|
|
|
#ifdef DEBUG
|
|
|
|
else {
|
2007-04-25 18:17:05 -07:00
|
|
|
nscoord buttonHeight = mButtonFrame->GetSize().height;
|
|
|
|
nscoord displayHeight = mDisplayFrame->GetSize().height;
|
|
|
|
|
|
|
|
// The button and display area should be equal heights, unless the computed
|
|
|
|
// height on the combobox is too small to fit their borders and padding.
|
|
|
|
NS_ASSERTION(buttonHeight == displayHeight ||
|
2007-08-02 11:08:05 -07:00
|
|
|
(aReflowState.ComputedHeight() < buttonHeight &&
|
2007-04-25 18:17:05 -07:00
|
|
|
buttonHeight ==
|
|
|
|
mButtonFrame->GetUsedBorderAndPadding().TopBottom()) ||
|
2007-08-02 11:08:05 -07:00
|
|
|
(aReflowState.ComputedHeight() < displayHeight &&
|
2007-04-25 18:17:05 -07:00
|
|
|
displayHeight ==
|
|
|
|
mDisplayFrame->GetUsedBorderAndPadding().TopBottom()),
|
2007-03-22 10:30:00 -07:00
|
|
|
"Different heights?");
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
if (GetStyleVisibility()->mDirection == NS_STYLE_DIRECTION_RTL) {
|
|
|
|
// Make sure the right edge of the button frame stays where it is now
|
|
|
|
buttonRect.x -= buttonWidth - buttonRect.width;
|
|
|
|
}
|
|
|
|
buttonRect.width = buttonWidth;
|
|
|
|
mButtonFrame->SetRect(buttonRect);
|
|
|
|
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
//--------------------------------------------------------------
|
|
|
|
|
|
|
|
nsIAtom*
|
|
|
|
nsComboboxControlFrame::GetType() const
|
|
|
|
{
|
|
|
|
return nsGkAtoms::comboboxControlFrame;
|
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef NS_DEBUG
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsComboboxControlFrame::GetFrameName(nsAString& aResult) const
|
|
|
|
{
|
|
|
|
return MakeFrameName(NS_LITERAL_STRING("ComboboxControl"), aResult);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
// nsIComboboxControlFrame
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
void
|
|
|
|
nsComboboxControlFrame::ShowDropDown(PRBool aDoDropDown)
|
|
|
|
{
|
|
|
|
if (mContent->HasAttr(kNameSpaceID_None, nsGkAtoms::disabled)) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!mDroppedDown && aDoDropDown) {
|
|
|
|
if (mListControlFrame) {
|
|
|
|
mListControlFrame->SyncViewWithFrame();
|
|
|
|
}
|
2009-09-01 19:46:47 -07:00
|
|
|
ShowList(aDoDropDown); // might destroy us
|
2007-03-22 10:30:00 -07:00
|
|
|
} else if (mDroppedDown && !aDoDropDown) {
|
2009-09-01 19:46:47 -07:00
|
|
|
ShowList(aDoDropDown); // might destroy us
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsComboboxControlFrame::SetDropDown(nsIFrame* aDropDownFrame)
|
|
|
|
{
|
|
|
|
mDropdownFrame = aDropDownFrame;
|
2009-01-12 11:20:59 -08:00
|
|
|
mListControlFrame = do_QueryFrame(mDropdownFrame);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
nsIFrame*
|
|
|
|
nsComboboxControlFrame::GetDropDown()
|
|
|
|
{
|
|
|
|
return mDropdownFrame;
|
|
|
|
}
|
|
|
|
|
|
|
|
///////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsComboboxControlFrame::RedisplaySelectedText()
|
|
|
|
{
|
2009-02-17 19:27:25 -08:00
|
|
|
nsAutoScriptBlocker scriptBlocker;
|
2007-03-22 10:30:00 -07:00
|
|
|
return RedisplayText(mListControlFrame->GetSelectedIndex());
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
nsComboboxControlFrame::RedisplayText(PRInt32 aIndex)
|
|
|
|
{
|
|
|
|
// Get the text to display
|
|
|
|
if (aIndex != -1) {
|
|
|
|
mListControlFrame->GetOptionText(aIndex, mDisplayedOptionText);
|
|
|
|
} else {
|
|
|
|
mDisplayedOptionText.Truncate();
|
|
|
|
}
|
|
|
|
mDisplayedIndex = aIndex;
|
|
|
|
|
|
|
|
REFLOW_DEBUG_MSG2("RedisplayText \"%s\"\n",
|
|
|
|
NS_LossyConvertUTF16toASCII(mDisplayedOptionText).get());
|
|
|
|
|
|
|
|
// Send reflow command because the new text maybe larger
|
|
|
|
nsresult rv = NS_OK;
|
|
|
|
if (mDisplayContent) {
|
|
|
|
// Don't call ActuallyDisplayText(PR_TRUE) directly here since that
|
|
|
|
// could cause recursive frame construction. See bug 283117 and the comment in
|
|
|
|
// HandleRedisplayTextEvent() below.
|
|
|
|
|
|
|
|
// Revoke outstanding events to avoid out-of-order events which could mean
|
|
|
|
// displaying the wrong text.
|
|
|
|
mRedisplayTextEvent.Revoke();
|
|
|
|
|
2009-02-17 19:27:25 -08:00
|
|
|
NS_ASSERTION(!nsContentUtils::IsSafeToRunScript(),
|
|
|
|
"If we happen to run our redisplay event now, we might kill "
|
|
|
|
"ourselves!");
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
nsRefPtr<RedisplayTextEvent> event = new RedisplayTextEvent(this);
|
2009-02-17 19:27:25 -08:00
|
|
|
mRedisplayTextEvent = event;
|
|
|
|
if (!nsContentUtils::AddScriptRunner(event))
|
|
|
|
mRedisplayTextEvent.Forget();
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsComboboxControlFrame::HandleRedisplayTextEvent()
|
|
|
|
{
|
|
|
|
// First, make sure that the content model is up to date and we've
|
|
|
|
// constructed the frames for all our content in the right places.
|
|
|
|
// Otherwise they'll end up under the wrong insertion frame when we
|
|
|
|
// ActuallyDisplayText, since that flushes out the content sink by
|
|
|
|
// calling SetText on a DOM node with aNotify set to true. See bug
|
|
|
|
// 289730.
|
2009-10-15 19:49:57 -07:00
|
|
|
nsWeakFrame weakThis(this);
|
2007-03-30 14:11:41 -07:00
|
|
|
PresContext()->Document()->
|
2007-03-22 10:30:00 -07:00
|
|
|
FlushPendingNotifications(Flush_ContentAndNotify);
|
2009-10-15 19:49:57 -07:00
|
|
|
if (!weakThis.IsAlive())
|
|
|
|
return;
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
// Redirect frame insertions during this method (see GetContentInsertionFrame())
|
|
|
|
// so that any reframing that the frame constructor forces upon us is inserted
|
|
|
|
// into the correct parent (mDisplayFrame). See bug 282607.
|
|
|
|
NS_PRECONDITION(!mInRedisplayText, "Nested RedisplayText");
|
|
|
|
mInRedisplayText = PR_TRUE;
|
|
|
|
mRedisplayTextEvent.Forget();
|
|
|
|
|
|
|
|
ActuallyDisplayText(PR_TRUE);
|
|
|
|
// XXXbz This should perhaps be eResize. Check.
|
2007-03-30 14:11:41 -07:00
|
|
|
PresContext()->PresShell()->FrameNeedsReflow(mDisplayFrame,
|
2007-05-06 12:16:51 -07:00
|
|
|
nsIPresShell::eStyleChange,
|
|
|
|
NS_FRAME_IS_DIRTY);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
mInRedisplayText = PR_FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsComboboxControlFrame::ActuallyDisplayText(PRBool aNotify)
|
|
|
|
{
|
|
|
|
if (mDisplayedOptionText.IsEmpty()) {
|
|
|
|
// Have to use a non-breaking space for line-height calculations
|
|
|
|
// to be right
|
|
|
|
static const PRUnichar space = 0xA0;
|
|
|
|
mDisplayContent->SetText(&space, 1, aNotify);
|
|
|
|
} else {
|
|
|
|
mDisplayContent->SetText(mDisplayedOptionText, aNotify);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
PRInt32
|
|
|
|
nsComboboxControlFrame::GetIndexOfDisplayArea()
|
|
|
|
{
|
|
|
|
return mDisplayedIndex;
|
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
// nsISelectControlFrame
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsComboboxControlFrame::DoneAddingChildren(PRBool aIsDone)
|
|
|
|
{
|
2009-01-12 11:20:59 -08:00
|
|
|
nsISelectControlFrame* listFrame = do_QueryFrame(mDropdownFrame);
|
|
|
|
if (!listFrame)
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
|
|
|
|
return listFrame->DoneAddingChildren(aIsDone);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2009-02-17 19:27:25 -08:00
|
|
|
nsComboboxControlFrame::AddOption(PRInt32 aIndex)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
if (aIndex <= mDisplayedIndex) {
|
|
|
|
++mDisplayedIndex;
|
|
|
|
}
|
|
|
|
|
2007-07-08 00:08:04 -07:00
|
|
|
nsListControlFrame* lcf = static_cast<nsListControlFrame*>(mDropdownFrame);
|
2009-02-17 19:27:25 -08:00
|
|
|
return lcf->AddOption(aIndex);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2009-02-17 19:27:25 -08:00
|
|
|
nsComboboxControlFrame::RemoveOption(PRInt32 aIndex)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2009-10-15 19:49:57 -07:00
|
|
|
nsWeakFrame weakThis(this);
|
2007-03-22 10:30:00 -07:00
|
|
|
if (mListControlFrame->GetNumberOfOptions() > 0) {
|
|
|
|
if (aIndex < mDisplayedIndex) {
|
|
|
|
--mDisplayedIndex;
|
|
|
|
} else if (aIndex == mDisplayedIndex) {
|
|
|
|
mDisplayedIndex = 0; // IE6 compat
|
|
|
|
RedisplayText(mDisplayedIndex);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
// If we removed the last option, we need to blank things out
|
|
|
|
RedisplayText(-1);
|
|
|
|
}
|
|
|
|
|
2009-10-15 19:49:57 -07:00
|
|
|
if (!weakThis.IsAlive())
|
|
|
|
return NS_OK;
|
|
|
|
|
2007-07-08 00:08:04 -07:00
|
|
|
nsListControlFrame* lcf = static_cast<nsListControlFrame*>(mDropdownFrame);
|
2009-02-17 19:27:25 -08:00
|
|
|
return lcf->RemoveOption(aIndex);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsComboboxControlFrame::OnSetSelectedIndex(PRInt32 aOldIndex, PRInt32 aNewIndex)
|
|
|
|
{
|
2009-02-17 19:27:25 -08:00
|
|
|
nsAutoScriptBlocker scriptBlocker;
|
2007-08-21 20:25:42 -07:00
|
|
|
RedisplayText(aNewIndex);
|
2009-01-09 08:35:24 -08:00
|
|
|
NS_ASSERTION(mDropdownFrame, "No dropdown frame!");
|
2009-01-12 11:20:59 -08:00
|
|
|
|
|
|
|
nsISelectControlFrame* listFrame = do_QueryFrame(mDropdownFrame);
|
2007-03-22 10:30:00 -07:00
|
|
|
NS_ASSERTION(listFrame, "No list frame!");
|
|
|
|
|
|
|
|
return listFrame->OnSetSelectedIndex(aOldIndex, aNewIndex);
|
|
|
|
}
|
|
|
|
|
|
|
|
// End nsISelectControlFrame
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsComboboxControlFrame::HandleEvent(nsPresContext* aPresContext,
|
|
|
|
nsGUIEvent* aEvent,
|
|
|
|
nsEventStatus* aEventStatus)
|
|
|
|
{
|
|
|
|
NS_ENSURE_ARG_POINTER(aEventStatus);
|
|
|
|
|
|
|
|
if (nsEventStatus_eConsumeNoDefault == *aEventStatus) {
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
if (mContent->HasAttr(kNameSpaceID_None, nsGkAtoms::disabled)) {
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
// If we have style that affects how we are selected, feed event down to
|
|
|
|
// nsFrame::HandleEvent so that selection takes place when appropriate.
|
|
|
|
const nsStyleUserInterface* uiStyle = GetStyleUserInterface();
|
|
|
|
if (uiStyle->mUserInput == NS_STYLE_USER_INPUT_NONE || uiStyle->mUserInput == NS_STYLE_USER_INPUT_DISABLED)
|
2008-12-29 07:07:38 -08:00
|
|
|
return nsBlockFrame::HandleEvent(aPresContext, aEvent, aEventStatus);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
nsComboboxControlFrame::SetFormProperty(nsIAtom* aName, const nsAString& aValue)
|
|
|
|
{
|
2009-01-12 11:20:59 -08:00
|
|
|
nsIFormControlFrame* fcFrame = do_QueryFrame(mDropdownFrame);
|
|
|
|
if (!fcFrame) {
|
|
|
|
return NS_NOINTERFACE;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
2009-01-12 11:20:59 -08:00
|
|
|
|
|
|
|
return fcFrame->SetFormProperty(aName, aValue);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
nsComboboxControlFrame::GetFormProperty(nsIAtom* aName, nsAString& aValue) const
|
|
|
|
{
|
2009-01-12 11:20:59 -08:00
|
|
|
nsIFormControlFrame* fcFrame = do_QueryFrame(mDropdownFrame);
|
|
|
|
if (!fcFrame) {
|
|
|
|
return NS_ERROR_FAILURE;
|
2009-01-09 08:35:24 -08:00
|
|
|
}
|
2009-01-12 11:20:59 -08:00
|
|
|
|
|
|
|
return fcFrame->GetFormProperty(aName, aValue);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
nsIFrame*
|
|
|
|
nsComboboxControlFrame::GetContentInsertionFrame() {
|
|
|
|
return mInRedisplayText ? mDisplayFrame : mDropdownFrame->GetContentInsertionFrame();
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
nsComboboxControlFrame::CreateAnonymousContent(nsTArray<nsIContent*>& aElements)
|
|
|
|
{
|
|
|
|
// The frames used to display the combo box and the button used to popup the dropdown list
|
|
|
|
// are created through anonymous content. The dropdown list is not created through anonymous
|
|
|
|
// content because it's frame is initialized specifically for the drop-down case and it is placed
|
|
|
|
// a special list referenced through NS_COMBO_FRAME_POPUP_LIST_INDEX to keep separate from the
|
|
|
|
// layout of the display and button.
|
|
|
|
//
|
|
|
|
// Note: The value attribute of the display content is set when an item is selected in the dropdown list.
|
|
|
|
// If the content specified below does not honor the value attribute than nothing will be displayed.
|
|
|
|
|
|
|
|
// For now the content that is created corresponds to two input buttons. It would be better to create the
|
|
|
|
// tag as something other than input, but then there isn't any way to create a button frame since it
|
|
|
|
// isn't possible to set the display type in CSS2 to create a button frame.
|
|
|
|
|
|
|
|
// create content used for display
|
|
|
|
//nsIAtom* tag = NS_NewAtom("mozcombodisplay");
|
|
|
|
|
|
|
|
// Add a child text content node for the label
|
|
|
|
|
|
|
|
nsNodeInfoManager *nimgr = mContent->NodeInfo()->NodeInfoManager();
|
|
|
|
|
|
|
|
NS_NewTextNode(getter_AddRefs(mDisplayContent), nimgr);
|
|
|
|
if (!mDisplayContent)
|
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
|
|
|
|
// set the value of the text node
|
|
|
|
mDisplayedIndex = mListControlFrame->GetSelectedIndex();
|
|
|
|
if (mDisplayedIndex != -1) {
|
|
|
|
mListControlFrame->GetOptionText(mDisplayedIndex, mDisplayedOptionText);
|
|
|
|
}
|
|
|
|
ActuallyDisplayText(PR_FALSE);
|
|
|
|
|
|
|
|
if (!aElements.AppendElement(mDisplayContent))
|
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
|
|
|
|
nsCOMPtr<nsINodeInfo> nodeInfo;
|
2009-06-09 00:41:19 -07:00
|
|
|
nodeInfo = nimgr->GetNodeInfo(nsGkAtoms::input, nsnull, kNameSpaceID_XHTML);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
// create button which drops the list down
|
2010-07-23 02:49:57 -07:00
|
|
|
NS_NewHTMLElement(getter_AddRefs(mButtonContent), nodeInfo.forget(),
|
|
|
|
PR_FALSE);
|
2007-03-22 10:30:00 -07:00
|
|
|
if (!mButtonContent)
|
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
|
|
|
|
// make someone to listen to the button. If its pressed by someone like Accessibility
|
|
|
|
// then open or close the combo box.
|
2007-05-14 02:11:38 -07:00
|
|
|
mButtonListener = new nsComboButtonListener(this);
|
|
|
|
if (!mButtonListener)
|
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
mButtonContent->AddEventListenerByIID(mButtonListener,
|
|
|
|
NS_GET_IID(nsIDOMMouseListener));
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
mButtonContent->SetAttr(kNameSpaceID_None, nsGkAtoms::type,
|
|
|
|
NS_LITERAL_STRING("button"), PR_FALSE);
|
|
|
|
// Set tabindex="-1" so that the button is not tabbable
|
|
|
|
mButtonContent->SetAttr(kNameSpaceID_None, nsGkAtoms::tabindex,
|
|
|
|
NS_LITERAL_STRING("-1"), PR_FALSE);
|
|
|
|
|
|
|
|
if (!aElements.AppendElement(mButtonContent))
|
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2010-02-11 09:34:01 -08:00
|
|
|
void
|
2010-02-20 16:52:50 -08:00
|
|
|
nsComboboxControlFrame::AppendAnonymousContentTo(nsBaseContentList& aElements)
|
2010-02-11 09:34:01 -08:00
|
|
|
{
|
|
|
|
aElements.MaybeAppendElement(mDisplayContent);
|
|
|
|
aElements.MaybeAppendElement(mButtonContent);
|
|
|
|
}
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
// XXXbz this is a for-now hack. Now that display:inline-block works,
|
|
|
|
// need to revisit this.
|
|
|
|
class nsComboboxDisplayFrame : public nsBlockFrame {
|
|
|
|
public:
|
2009-09-12 09:49:24 -07:00
|
|
|
NS_DECL_FRAMEARENA_HELPERS
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
nsComboboxDisplayFrame (nsStyleContext* aContext,
|
|
|
|
nsComboboxControlFrame* aComboBox)
|
|
|
|
: nsBlockFrame(aContext),
|
|
|
|
mComboBox(aComboBox)
|
|
|
|
{}
|
|
|
|
|
|
|
|
// Need this so that line layout knows that this block's width
|
|
|
|
// depends on the available width.
|
|
|
|
virtual nsIAtom* GetType() const;
|
|
|
|
|
|
|
|
virtual PRBool IsFrameOfType(PRUint32 aFlags) const
|
|
|
|
{
|
|
|
|
return nsBlockFrame::IsFrameOfType(aFlags &
|
|
|
|
~(nsIFrame::eReplacedContainsBlock));
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHOD Reflow(nsPresContext* aPresContext,
|
|
|
|
nsHTMLReflowMetrics& aDesiredSize,
|
|
|
|
const nsHTMLReflowState& aReflowState,
|
|
|
|
nsReflowStatus& aStatus);
|
|
|
|
|
2007-05-22 12:42:01 -07:00
|
|
|
NS_IMETHOD BuildDisplayList(nsDisplayListBuilder* aBuilder,
|
|
|
|
const nsRect& aDirtyRect,
|
|
|
|
const nsDisplayListSet& aLists);
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
protected:
|
|
|
|
nsComboboxControlFrame* mComboBox;
|
|
|
|
};
|
|
|
|
|
2009-09-12 09:49:24 -07:00
|
|
|
NS_IMPL_FRAMEARENA_HELPERS(nsComboboxDisplayFrame)
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
nsIAtom*
|
|
|
|
nsComboboxDisplayFrame::GetType() const
|
|
|
|
{
|
|
|
|
return nsGkAtoms::comboboxDisplayFrame;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsComboboxDisplayFrame::Reflow(nsPresContext* aPresContext,
|
|
|
|
nsHTMLReflowMetrics& aDesiredSize,
|
|
|
|
const nsHTMLReflowState& aReflowState,
|
|
|
|
nsReflowStatus& aStatus)
|
|
|
|
{
|
|
|
|
nsHTMLReflowState state(aReflowState);
|
2007-08-02 11:08:05 -07:00
|
|
|
if (state.ComputedHeight() == NS_INTRINSICSIZE) {
|
2007-03-22 10:30:00 -07:00
|
|
|
// Note that the only way we can have a computed height here is if the
|
|
|
|
// combobox had a specified height. If it didn't, size based on what our
|
|
|
|
// rows look like, for lack of anything better.
|
2007-08-02 11:08:05 -07:00
|
|
|
state.SetComputedHeight(mComboBox->mListControlFrame->GetHeightOfARow());
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
nscoord computedWidth = mComboBox->mDisplayWidth -
|
|
|
|
state.mComputedBorderPadding.LeftRight();
|
|
|
|
if (computedWidth < 0) {
|
|
|
|
computedWidth = 0;
|
|
|
|
}
|
|
|
|
state.SetComputedWidth(computedWidth);
|
|
|
|
|
|
|
|
return nsBlockFrame::Reflow(aPresContext, aDesiredSize, state, aStatus);
|
|
|
|
}
|
|
|
|
|
2007-05-22 12:42:01 -07:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsComboboxDisplayFrame::BuildDisplayList(nsDisplayListBuilder* aBuilder,
|
|
|
|
const nsRect& aDirtyRect,
|
|
|
|
const nsDisplayListSet& aLists)
|
|
|
|
{
|
|
|
|
nsDisplayListCollection set;
|
|
|
|
nsresult rv = nsBlockFrame::BuildDisplayList(aBuilder, aDirtyRect, set);
|
|
|
|
if (NS_FAILED(rv))
|
|
|
|
return rv;
|
|
|
|
|
|
|
|
// remove background items if parent frame is themed
|
|
|
|
if (mComboBox->IsThemed()) {
|
|
|
|
set.BorderBackground()->DeleteAll();
|
|
|
|
}
|
|
|
|
|
|
|
|
set.MoveTo(aLists);
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
nsIFrame*
|
|
|
|
nsComboboxControlFrame::CreateFrameFor(nsIContent* aContent)
|
|
|
|
{
|
|
|
|
NS_PRECONDITION(nsnull != aContent, "null ptr");
|
|
|
|
|
|
|
|
NS_ASSERTION(mDisplayContent, "mDisplayContent can't be null!");
|
|
|
|
|
|
|
|
if (mDisplayContent != aContent) {
|
|
|
|
// We only handle the frames for mDisplayContent here
|
|
|
|
return nsnull;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Get PresShell
|
2007-03-30 14:11:41 -07:00
|
|
|
nsIPresShell *shell = PresContext()->PresShell();
|
2007-03-22 10:30:00 -07:00
|
|
|
nsStyleSet *styleSet = shell->StyleSet();
|
|
|
|
|
|
|
|
// create the style contexts for the anonymous block frame and text frame
|
|
|
|
nsRefPtr<nsStyleContext> styleContext;
|
|
|
|
styleContext = styleSet->
|
2009-12-10 23:37:40 -08:00
|
|
|
ResolveAnonymousBoxStyle(nsCSSAnonBoxes::mozDisplayComboboxControlFrame,
|
|
|
|
mStyleContext);
|
2007-03-22 10:30:00 -07:00
|
|
|
if (NS_UNLIKELY(!styleContext)) {
|
|
|
|
return nsnull;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsRefPtr<nsStyleContext> textStyleContext;
|
2007-06-15 22:11:20 -07:00
|
|
|
textStyleContext = styleSet->ResolveStyleForNonElement(mStyleContext);
|
2007-03-22 10:30:00 -07:00
|
|
|
if (NS_UNLIKELY(!textStyleContext)) {
|
|
|
|
return nsnull;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Start by by creating our anonymous block frame
|
|
|
|
mDisplayFrame = new (shell) nsComboboxDisplayFrame(styleContext, this);
|
|
|
|
if (NS_UNLIKELY(!mDisplayFrame)) {
|
|
|
|
return nsnull;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult rv = mDisplayFrame->Init(mContent, this, nsnull);
|
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
mDisplayFrame->Destroy();
|
|
|
|
mDisplayFrame = nsnull;
|
|
|
|
return nsnull;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Create a text frame and put it inside the block frame
|
2010-05-12 17:56:11 -07:00
|
|
|
nsIFrame* textFrame = NS_NewTextFrame(shell, textStyleContext);
|
|
|
|
if (NS_UNLIKELY(!textFrame)) {
|
2007-03-22 10:30:00 -07:00
|
|
|
return nsnull;
|
|
|
|
}
|
|
|
|
|
|
|
|
// initialize the text frame
|
2010-05-12 17:56:11 -07:00
|
|
|
rv = textFrame->Init(aContent, mDisplayFrame, nsnull);
|
2007-03-22 10:30:00 -07:00
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
mDisplayFrame->Destroy();
|
|
|
|
mDisplayFrame = nsnull;
|
2010-05-12 17:56:11 -07:00
|
|
|
textFrame->Destroy();
|
|
|
|
textFrame = nsnull;
|
2007-03-22 10:30:00 -07:00
|
|
|
return nsnull;
|
|
|
|
}
|
2010-05-12 17:56:11 -07:00
|
|
|
mDisplayContent->SetPrimaryFrame(textFrame);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2010-05-12 17:56:11 -07:00
|
|
|
nsFrameList textList(textFrame, textFrame);
|
2009-07-28 05:53:20 -07:00
|
|
|
mDisplayFrame->SetInitialChildList(nsnull, textList);
|
2007-03-22 10:30:00 -07:00
|
|
|
return mDisplayFrame;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2009-12-23 21:21:15 -08:00
|
|
|
nsComboboxControlFrame::DestroyFrom(nsIFrame* aDestructRoot)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
// Revoke any pending RedisplayTextEvent
|
|
|
|
mRedisplayTextEvent.Revoke();
|
|
|
|
|
2007-07-08 00:08:04 -07:00
|
|
|
nsFormControlFrame::RegUnRegAccessKey(static_cast<nsIFrame*>(this), PR_FALSE);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
if (mDroppedDown) {
|
|
|
|
// Get parent view
|
2009-01-12 11:20:59 -08:00
|
|
|
nsIFrame * listFrame = do_QueryFrame(mListControlFrame);
|
|
|
|
if (listFrame) {
|
2007-03-22 10:30:00 -07:00
|
|
|
nsIView* view = listFrame->GetView();
|
|
|
|
NS_ASSERTION(view, "nsComboboxControlFrame view is null");
|
|
|
|
if (view) {
|
|
|
|
nsIWidget* widget = view->GetWidget();
|
|
|
|
if (widget)
|
2009-12-22 15:49:33 -08:00
|
|
|
widget->CaptureRollupEvents(this, nsnull, PR_FALSE, PR_TRUE);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Cleanup frames in popup child list
|
2009-12-23 21:21:15 -08:00
|
|
|
mPopupFrames.DestroyFramesFrom(aDestructRoot);
|
2007-03-22 10:30:00 -07:00
|
|
|
nsContentUtils::DestroyAnonymousContent(&mDisplayContent);
|
|
|
|
nsContentUtils::DestroyAnonymousContent(&mButtonContent);
|
2009-12-23 21:21:15 -08:00
|
|
|
nsBlockFrame::DestroyFrom(aDestructRoot);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-07-28 05:51:09 -07:00
|
|
|
nsFrameList
|
|
|
|
nsComboboxControlFrame::GetChildList(nsIAtom* aListName) const
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2007-08-10 05:42:06 -07:00
|
|
|
if (nsGkAtoms::selectPopupList == aListName) {
|
2009-07-28 05:51:09 -07:00
|
|
|
return mPopupFrames;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
2009-07-28 05:51:09 -07:00
|
|
|
return nsBlockFrame::GetChildList(aListName);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsComboboxControlFrame::SetInitialChildList(nsIAtom* aListName,
|
2009-07-28 05:53:20 -07:00
|
|
|
nsFrameList& aChildList)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
nsresult rv = NS_OK;
|
2007-08-10 05:42:06 -07:00
|
|
|
if (nsGkAtoms::selectPopupList == aListName) {
|
2007-03-22 10:30:00 -07:00
|
|
|
mPopupFrames.SetFrames(aChildList);
|
|
|
|
} else {
|
2009-07-28 05:53:20 -07:00
|
|
|
for (nsFrameList::Enumerator e(aChildList); !e.AtEnd(); e.Next()) {
|
|
|
|
nsCOMPtr<nsIFormControl> formControl =
|
|
|
|
do_QueryInterface(e.get()->GetContent());
|
2007-03-22 10:30:00 -07:00
|
|
|
if (formControl && formControl->GetType() == NS_FORM_INPUT_BUTTON) {
|
2009-07-28 05:53:20 -07:00
|
|
|
mButtonFrame = e.get();
|
2007-03-22 10:30:00 -07:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
NS_ASSERTION(mButtonFrame, "missing button frame in initial child list");
|
2009-07-28 05:53:20 -07:00
|
|
|
rv = nsBlockFrame::SetInitialChildList(aListName, aChildList);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
2007-07-25 21:03:29 -07:00
|
|
|
#define NS_COMBO_FRAME_POPUP_LIST_INDEX (NS_BLOCK_LIST_COUNT)
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
nsIAtom*
|
|
|
|
nsComboboxControlFrame::GetAdditionalChildListName(PRInt32 aIndex) const
|
|
|
|
{
|
|
|
|
// Maintain a separate child list for the dropdown list (i.e. popup listbox)
|
|
|
|
// This is necessary because we don't want the listbox to be included in the layout
|
|
|
|
// of the combox's children because it would take up space, when it is suppose to
|
|
|
|
// be floating above the display.
|
2007-07-25 21:03:29 -07:00
|
|
|
if (aIndex < NS_BLOCK_LIST_COUNT) {
|
2008-12-29 07:07:38 -08:00
|
|
|
return nsBlockFrame::GetAdditionalChildListName(aIndex);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
if (NS_COMBO_FRAME_POPUP_LIST_INDEX == aIndex) {
|
2007-08-10 05:42:06 -07:00
|
|
|
return nsGkAtoms::selectPopupList;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
return nsnull;
|
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
//nsIRollupListener
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
NS_IMETHODIMP
|
2009-06-12 11:23:16 -07:00
|
|
|
nsComboboxControlFrame::Rollup(PRUint32 aCount,
|
|
|
|
nsIContent** aLastRolledUp)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2007-12-03 08:33:42 -08:00
|
|
|
if (aLastRolledUp)
|
|
|
|
*aLastRolledUp = nsnull;
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
if (mDroppedDown) {
|
2007-05-17 04:12:30 -07:00
|
|
|
nsWeakFrame weakFrame(this);
|
|
|
|
mListControlFrame->AboutToRollup(); // might destroy us
|
|
|
|
if (!weakFrame.IsAlive())
|
|
|
|
return NS_OK;
|
|
|
|
ShowDropDown(PR_FALSE); // might destroy us
|
|
|
|
if (!weakFrame.IsAlive())
|
|
|
|
return NS_OK;
|
2007-03-22 10:30:00 -07:00
|
|
|
mListControlFrame->CaptureMouseEvents(PR_FALSE);
|
|
|
|
}
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsComboboxControlFrame::RollupFromList()
|
|
|
|
{
|
2009-09-01 19:46:47 -07:00
|
|
|
if (ShowList(PR_FALSE))
|
2007-05-17 04:12:30 -07:00
|
|
|
mListControlFrame->CaptureMouseEvents(PR_FALSE);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
PRInt32
|
|
|
|
nsComboboxControlFrame::UpdateRecentIndex(PRInt32 aIndex)
|
|
|
|
{
|
|
|
|
PRInt32 index = mRecentSelectedIndex;
|
|
|
|
if (mRecentSelectedIndex == NS_SKIP_NOTIFY_INDEX || aIndex == NS_SKIP_NOTIFY_INDEX)
|
|
|
|
mRecentSelectedIndex = aIndex;
|
|
|
|
return index;
|
|
|
|
}
|
|
|
|
|
|
|
|
class nsDisplayComboboxFocus : public nsDisplayItem {
|
|
|
|
public:
|
2010-08-13 03:01:13 -07:00
|
|
|
nsDisplayComboboxFocus(nsDisplayListBuilder* aBuilder,
|
|
|
|
nsComboboxControlFrame* aFrame)
|
|
|
|
: nsDisplayItem(aBuilder, aFrame) {
|
2007-03-22 10:30:00 -07:00
|
|
|
MOZ_COUNT_CTOR(nsDisplayComboboxFocus);
|
|
|
|
}
|
|
|
|
#ifdef NS_BUILD_REFCNT_LOGGING
|
|
|
|
virtual ~nsDisplayComboboxFocus() {
|
|
|
|
MOZ_COUNT_DTOR(nsDisplayComboboxFocus);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2009-09-06 17:35:14 -07:00
|
|
|
virtual void Paint(nsDisplayListBuilder* aBuilder,
|
|
|
|
nsIRenderingContext* aCtx);
|
2010-07-15 14:07:49 -07:00
|
|
|
NS_DISPLAY_DECL_NAME("ComboboxFocus", TYPE_COMBOBOX_FOCUS)
|
2007-03-22 10:30:00 -07:00
|
|
|
};
|
|
|
|
|
|
|
|
void nsDisplayComboboxFocus::Paint(nsDisplayListBuilder* aBuilder,
|
2009-09-06 17:35:14 -07:00
|
|
|
nsIRenderingContext* aCtx)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2007-07-08 00:08:04 -07:00
|
|
|
static_cast<nsComboboxControlFrame*>(mFrame)
|
2010-08-13 03:01:58 -07:00
|
|
|
->PaintFocus(*aCtx, ToReferenceFrame());
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsComboboxControlFrame::BuildDisplayList(nsDisplayListBuilder* aBuilder,
|
|
|
|
const nsRect& aDirtyRect,
|
|
|
|
const nsDisplayListSet& aLists)
|
|
|
|
{
|
|
|
|
#ifdef NOISY
|
|
|
|
printf("%p paint at (%d, %d, %d, %d)\n", this,
|
|
|
|
aDirtyRect.x, aDirtyRect.y, aDirtyRect.width, aDirtyRect.height);
|
|
|
|
#endif
|
|
|
|
|
|
|
|
if (aBuilder->IsForEventDelivery()) {
|
|
|
|
// Don't allow children to receive events.
|
|
|
|
// REVIEW: following old GetFrameForPoint
|
|
|
|
nsresult rv = DisplayBorderBackgroundOutline(aBuilder, aLists);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
} else {
|
|
|
|
// REVIEW: Our in-flow child frames are inline-level so they will paint in our
|
|
|
|
// content list, so we don't need to mess with layers.
|
2008-12-29 07:07:38 -08:00
|
|
|
nsresult rv = nsBlockFrame::BuildDisplayList(aBuilder, aDirtyRect, aLists);
|
2007-03-22 10:30:00 -07:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
}
|
|
|
|
|
2010-04-21 07:53:42 -07:00
|
|
|
// draw a focus indicator only when focus rings should be drawn
|
|
|
|
nsIDocument* doc = mContent->GetCurrentDoc();
|
|
|
|
if (doc) {
|
|
|
|
nsPIDOMWindow* window = doc->GetWindow();
|
|
|
|
if (window && window->ShouldShowFocusRing()) {
|
|
|
|
nsPresContext *presContext = PresContext();
|
|
|
|
const nsStyleDisplay *disp = GetStyleDisplay();
|
|
|
|
if ((!IsThemed(disp) ||
|
|
|
|
!presContext->GetTheme()->ThemeDrawsFocusForWidget(presContext, this, disp->mAppearance)) &&
|
|
|
|
mDisplayFrame && IsVisibleForPainting(aBuilder)) {
|
2010-08-13 03:01:13 -07:00
|
|
|
nsresult rv = aLists.Content()->AppendNewToTop(
|
|
|
|
new (aBuilder) nsDisplayComboboxFocus(aBuilder, this));
|
2010-04-21 07:53:42 -07:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
}
|
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
return DisplaySelectionOverlay(aBuilder, aLists);
|
|
|
|
}
|
|
|
|
|
|
|
|
void nsComboboxControlFrame::PaintFocus(nsIRenderingContext& aRenderingContext,
|
2008-04-28 20:55:07 -07:00
|
|
|
nsPoint aPt)
|
|
|
|
{
|
|
|
|
/* Do we need to do anything? */
|
|
|
|
if (mContent->HasAttr(kNameSpaceID_None, nsGkAtoms::disabled) ||
|
|
|
|
mFocused != this)
|
|
|
|
return;
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
aRenderingContext.PushState();
|
|
|
|
nsRect clipRect = mDisplayFrame->GetRect() + aPt;
|
|
|
|
aRenderingContext.SetClipRect(clipRect, nsClipCombine_kIntersect);
|
|
|
|
|
|
|
|
// REVIEW: Why does the old code paint mDisplayFrame again? We've
|
|
|
|
// already painted it in the children above. So clipping it here won't do
|
|
|
|
// us much good.
|
|
|
|
|
|
|
|
/////////////////////
|
|
|
|
// draw focus
|
2008-04-28 20:55:07 -07:00
|
|
|
|
|
|
|
aRenderingContext.SetLineStyle(nsLineStyle_kDotted);
|
|
|
|
aRenderingContext.SetColor(GetStyleColor()->mColor);
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
//aRenderingContext.DrawRect(clipRect);
|
2008-04-28 20:55:07 -07:00
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
nscoord onePixel = nsPresContext::CSSPixelsToAppUnits(1);
|
|
|
|
clipRect.width -= onePixel;
|
|
|
|
clipRect.height -= onePixel;
|
|
|
|
aRenderingContext.DrawLine(clipRect.x, clipRect.y,
|
|
|
|
clipRect.x+clipRect.width, clipRect.y);
|
|
|
|
aRenderingContext.DrawLine(clipRect.x+clipRect.width, clipRect.y,
|
|
|
|
clipRect.x+clipRect.width, clipRect.y+clipRect.height);
|
|
|
|
aRenderingContext.DrawLine(clipRect.x+clipRect.width, clipRect.y+clipRect.height,
|
|
|
|
clipRect.x, clipRect.y+clipRect.height);
|
|
|
|
aRenderingContext.DrawLine(clipRect.x, clipRect.y+clipRect.height,
|
|
|
|
clipRect.x, clipRect.y);
|
|
|
|
aRenderingContext.DrawLine(clipRect.x, clipRect.y+clipRect.height,
|
|
|
|
clipRect.x, clipRect.y);
|
|
|
|
|
|
|
|
aRenderingContext.PopState();
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------
|
|
|
|
// gets the content (an option) by index and then set it as
|
|
|
|
// being selected or not selected
|
|
|
|
//---------------------------------------------------------
|
|
|
|
NS_IMETHODIMP
|
2009-02-17 19:27:25 -08:00
|
|
|
nsComboboxControlFrame::OnOptionSelected(PRInt32 aIndex, PRBool aSelected)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
if (mDroppedDown) {
|
2009-01-12 11:20:59 -08:00
|
|
|
nsISelectControlFrame *selectFrame = do_QueryFrame(mListControlFrame);
|
2007-03-22 10:30:00 -07:00
|
|
|
if (selectFrame) {
|
2009-02-17 19:27:25 -08:00
|
|
|
selectFrame->OnOptionSelected(aIndex, aSelected);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if (aSelected) {
|
2009-02-17 19:27:25 -08:00
|
|
|
nsAutoScriptBlocker blocker;
|
2007-03-22 10:30:00 -07:00
|
|
|
RedisplayText(aIndex);
|
|
|
|
} else {
|
2009-02-17 19:27:25 -08:00
|
|
|
nsWeakFrame weakFrame(this);
|
2007-03-22 10:30:00 -07:00
|
|
|
RedisplaySelectedText();
|
2009-02-17 19:27:25 -08:00
|
|
|
if (weakFrame.IsAlive()) {
|
|
|
|
FireValueChangeEvent(); // Fire after old option is unselected
|
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
void nsComboboxControlFrame::FireValueChangeEvent()
|
|
|
|
{
|
|
|
|
// Fire ValueChange event to indicate data value of combo box has changed
|
2010-02-24 18:45:43 -08:00
|
|
|
nsContentUtils::AddScriptRunner(
|
|
|
|
new nsPLDOMEvent(mContent, NS_LITERAL_STRING("ValueChange"), PR_TRUE,
|
|
|
|
PR_FALSE));
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsComboboxControlFrame::OnContentReset()
|
|
|
|
{
|
|
|
|
if (mListControlFrame) {
|
|
|
|
mListControlFrame->OnContentReset();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//--------------------------------------------------------
|
|
|
|
// nsIStatefulFrame
|
|
|
|
//--------------------------------------------------------
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsComboboxControlFrame::SaveState(SpecialStateID aStateID,
|
|
|
|
nsPresState** aState)
|
|
|
|
{
|
|
|
|
if (!mListControlFrame)
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
|
2009-01-12 11:20:59 -08:00
|
|
|
nsIStatefulFrame* stateful = do_QueryFrame(mListControlFrame);
|
2007-03-22 10:30:00 -07:00
|
|
|
return stateful->SaveState(aStateID, aState);
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsComboboxControlFrame::RestoreState(nsPresState* aState)
|
|
|
|
{
|
|
|
|
if (!mListControlFrame)
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
|
2009-01-12 11:20:59 -08:00
|
|
|
nsIStatefulFrame* stateful = do_QueryFrame(mListControlFrame);
|
|
|
|
NS_ASSERTION(stateful, "Must implement nsIStatefulFrame");
|
|
|
|
return stateful->RestoreState(aState);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//
|
|
|
|
// Camino uses a native widget for the combobox
|
|
|
|
// popup, which affects drawing and event
|
|
|
|
// handling here and in nsListControlFrame.
|
2009-07-06 06:39:54 -07:00
|
|
|
//
|
|
|
|
// Also, Fennec use a custom combobox built-in widget
|
2007-03-22 10:30:00 -07:00
|
|
|
//
|
|
|
|
|
|
|
|
/* static */
|
|
|
|
PRBool
|
|
|
|
nsComboboxControlFrame::ToolkitHasNativePopup()
|
|
|
|
{
|
2007-03-30 12:51:51 -07:00
|
|
|
return nsContentUtils::GetBoolPref("ui.use_native_popup_windows");
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|