2001-09-29 00:14:13 +04:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
2012-05-21 15:12:37 +04:00
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
2005-02-16 08:13:16 +03:00
|
|
|
|
2001-08-14 11:59:59 +04:00
|
|
|
#include "nscore.h"
|
1999-02-12 20:45:58 +03:00
|
|
|
#include "nsCOMPtr.h"
|
2001-10-26 21:18:35 +04:00
|
|
|
#include "nsUnicharUtils.h"
|
1999-01-18 18:14:00 +03:00
|
|
|
#include "nsListControlFrame.h"
|
1999-10-08 01:39:50 +04:00
|
|
|
#include "nsFormControlFrame.h" // for COMPARE macro
|
2007-01-30 03:06:41 +03:00
|
|
|
#include "nsGkAtoms.h"
|
2010-07-29 03:43:52 +04:00
|
|
|
#include "nsIDOMHTMLSelectElement.h"
|
2011-04-17 05:22:41 +04:00
|
|
|
#include "nsIDOMHTMLOptionElement.h"
|
2005-02-16 08:13:16 +03:00
|
|
|
#include "nsComboboxControlFrame.h"
|
1999-05-08 00:30:16 +04:00
|
|
|
#include "nsIDOMHTMLOptGroupElement.h"
|
1999-08-06 18:14:38 +04:00
|
|
|
#include "nsIPresShell.h"
|
2011-04-21 21:35:52 +04:00
|
|
|
#include "nsEventStateManager.h"
|
1999-11-03 10:11:45 +03:00
|
|
|
#include "nsIDOMMouseEvent.h"
|
2011-04-08 05:05:49 +04:00
|
|
|
#include "nsFontMetrics.h"
|
2000-04-19 17:55:17 +04:00
|
|
|
#include "nsIScrollableFrame.h"
|
2002-04-11 04:53:20 +04:00
|
|
|
#include "nsCSSRendering.h"
|
2011-06-29 22:07:25 +04:00
|
|
|
#include "nsIDOMEventListener.h"
|
2005-06-02 13:00:48 +04:00
|
|
|
#include "nsLayoutUtils.h"
|
2006-01-26 05:29:17 +03:00
|
|
|
#include "nsDisplayList.h"
|
2011-08-11 17:29:50 +04:00
|
|
|
#include "nsContentUtils.h"
|
2012-06-19 07:26:34 +04:00
|
|
|
#include "mozilla/Attributes.h"
|
2013-08-02 11:08:19 +04:00
|
|
|
#include "mozilla/dom/HTMLOptionsCollection.h"
|
2013-04-04 11:03:33 +04:00
|
|
|
#include "mozilla/dom/HTMLSelectElement.h"
|
|
|
|
#include "mozilla/LookAndFeel.h"
|
2013-09-25 15:21:18 +04:00
|
|
|
#include "mozilla/MouseEvents.h"
|
2013-08-26 05:34:23 +04:00
|
|
|
#include "mozilla/Preferences.h"
|
2013-09-25 15:21:19 +04:00
|
|
|
#include "mozilla/TextEvents.h"
|
2013-01-15 16:22:03 +04:00
|
|
|
#include <algorithm>
|
2011-09-09 06:27:13 +04:00
|
|
|
|
|
|
|
using namespace mozilla;
|
1999-11-12 01:13:33 +03:00
|
|
|
|
1999-01-18 18:14:00 +03:00
|
|
|
// Constants
|
2012-10-10 09:00:05 +04:00
|
|
|
const uint32_t kMaxDropDownRows = 20; // This matches the setting for 4.x browsers
|
2012-08-22 19:56:38 +04:00
|
|
|
const int32_t kNothingSelected = -1;
|
1999-05-08 00:30:16 +04:00
|
|
|
|
2009-08-09 02:00:26 +04:00
|
|
|
// Static members
|
2012-07-30 18:20:58 +04:00
|
|
|
nsListControlFrame * nsListControlFrame::mFocused = nullptr;
|
|
|
|
nsString * nsListControlFrame::sIncrementalString = nullptr;
|
2002-04-11 04:53:20 +04:00
|
|
|
|
2002-09-20 06:12:12 +04:00
|
|
|
// Using for incremental typing navigation
|
|
|
|
#define INCREMENTAL_SEARCH_KEYPRESS_TIME 1000
|
|
|
|
// XXX, kyle.yuan@sun.com, there are 4 definitions for the same purpose:
|
|
|
|
// nsMenuPopupFrame.h, nsListControlFrame.cpp, listbox.xml, tree.xml
|
|
|
|
// need to find a good place to put them together.
|
|
|
|
// if someone changes one, please also change the other.
|
|
|
|
|
2002-11-07 13:25:03 +03:00
|
|
|
DOMTimeStamp nsListControlFrame::gLastKeyTime = 0;
|
1999-03-03 01:43:26 +03:00
|
|
|
|
2004-01-10 01:18:26 +03:00
|
|
|
/******************************************************************************
|
|
|
|
* nsListEventListener
|
|
|
|
* This class is responsible for propagating events to the nsListControlFrame.
|
|
|
|
* Frames are not refcounted so they can't be used as event listeners.
|
|
|
|
*****************************************************************************/
|
|
|
|
|
2012-06-19 07:26:34 +04:00
|
|
|
class nsListEventListener MOZ_FINAL : public nsIDOMEventListener
|
2004-01-10 01:18:26 +03:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
nsListEventListener(nsListControlFrame *aFrame)
|
|
|
|
: mFrame(aFrame) { }
|
|
|
|
|
|
|
|
void SetFrame(nsListControlFrame *aFrame) { mFrame = aFrame; }
|
|
|
|
|
|
|
|
NS_DECL_ISUPPORTS
|
2011-06-29 22:07:25 +04:00
|
|
|
NS_DECL_NSIDOMEVENTLISTENER
|
2004-01-10 01:18:26 +03:00
|
|
|
|
|
|
|
private:
|
|
|
|
nsListControlFrame *mFrame;
|
|
|
|
};
|
|
|
|
|
1999-07-29 01:38:08 +04:00
|
|
|
//---------------------------------------------------------
|
2005-11-04 05:38:33 +03:00
|
|
|
nsIFrame*
|
2006-03-27 01:30:36 +04:00
|
|
|
NS_NewListControlFrame(nsIPresShell* aPresShell, nsStyleContext* aContext)
|
1999-01-18 18:14:00 +03:00
|
|
|
{
|
2004-08-02 08:52:55 +04:00
|
|
|
nsListControlFrame* it =
|
2006-03-27 01:30:36 +04:00
|
|
|
new (aPresShell) nsListControlFrame(aPresShell, aPresShell->GetDocument(), aContext);
|
2005-11-04 05:38:33 +03:00
|
|
|
|
2013-08-03 08:11:06 +04:00
|
|
|
it->AddStateBits(NS_FRAME_INDEPENDENT_SELECTION);
|
2005-11-04 05:38:33 +03:00
|
|
|
|
|
|
|
return it;
|
1999-01-18 18:14:00 +03:00
|
|
|
}
|
|
|
|
|
2009-09-12 20:49:24 +04:00
|
|
|
NS_IMPL_FRAMEARENA_HELPERS(nsListControlFrame)
|
|
|
|
|
1999-07-29 01:38:08 +04:00
|
|
|
//---------------------------------------------------------
|
2006-03-27 01:30:36 +04:00
|
|
|
nsListControlFrame::nsListControlFrame(
|
|
|
|
nsIPresShell* aShell, nsIDocument* aDocument, nsStyleContext* aContext)
|
2011-10-17 18:59:28 +04:00
|
|
|
: nsHTMLScrollFrame(aShell, aContext, false),
|
|
|
|
mMightNeedSecondPass(false),
|
|
|
|
mHasPendingInterruptAtStartOfReflow(false),
|
2012-06-23 05:13:56 +04:00
|
|
|
mDropdownCanGrow(false),
|
Bug 300030: Move intrinsic width computation out of nsIFrame::Reflow and into its own methods on nsIFrame. Replace reflow reasons, types, and commands with dirty bits/notifications. Thanks to bzbarsky for almost all of the HTML form controls (mozilla/layout/forms) changes, and many others for help testing and patching. For detailed commit logs, see REFLOW_YYYYMMDD_BRANCH, where YYYYMMDD is one of 20061031, 20060830, 20060603, 20060302, 20060119, 20051011, 20050804, 20050429, 20050315, 20050111, and 20041213.
2006-12-08 08:38:33 +03:00
|
|
|
mLastDropdownComputedHeight(NS_UNCONSTRAINEDSIZE)
|
1999-01-18 18:14:00 +03:00
|
|
|
{
|
2012-07-30 18:20:58 +04:00
|
|
|
mComboboxFrame = nullptr;
|
2011-10-17 18:59:28 +04:00
|
|
|
mChangesSinceDragStart = false;
|
|
|
|
mButtonDown = false;
|
2000-02-15 18:04:38 +03:00
|
|
|
|
2011-10-17 18:59:28 +04:00
|
|
|
mIsAllContentHere = false;
|
|
|
|
mIsAllFramesHere = false;
|
|
|
|
mHasBeenInitialized = false;
|
|
|
|
mNeedToReset = true;
|
|
|
|
mPostChildrenLoadedReset = false;
|
2000-01-09 04:41:11 +03:00
|
|
|
|
2011-10-17 18:59:28 +04:00
|
|
|
mControlSelectMode = false;
|
1999-01-18 18:14:00 +03:00
|
|
|
}
|
|
|
|
|
1999-07-29 01:38:08 +04:00
|
|
|
//---------------------------------------------------------
|
1999-01-18 18:14:00 +03:00
|
|
|
nsListControlFrame::~nsListControlFrame()
|
|
|
|
{
|
2012-07-30 18:20:58 +04:00
|
|
|
mComboboxFrame = nullptr;
|
1999-01-18 18:14:00 +03:00
|
|
|
}
|
|
|
|
|
2000-08-03 18:13:58 +04:00
|
|
|
// for Bug 47302 (remove this comment later)
|
2006-04-10 04:16:29 +04:00
|
|
|
void
|
2009-12-24 08:21:15 +03:00
|
|
|
nsListControlFrame::DestroyFrom(nsIFrame* aDestructRoot)
|
2000-08-03 18:13:58 +04:00
|
|
|
{
|
2002-11-07 13:25:03 +03:00
|
|
|
// get the receiver interface from the browser button's content node
|
2007-05-14 13:11:38 +04:00
|
|
|
ENSURE_TRUE(mContent);
|
2000-08-15 02:05:28 +04:00
|
|
|
|
2004-01-10 01:18:26 +03:00
|
|
|
// Clear the frame pointer on our event listener, just in case the
|
|
|
|
// event listener can outlive the frame.
|
2000-08-15 02:05:28 +04:00
|
|
|
|
2012-07-30 18:20:58 +04:00
|
|
|
mEventListener->SetFrame(nullptr);
|
2000-08-15 02:05:28 +04:00
|
|
|
|
2013-07-25 10:09:29 +04:00
|
|
|
mContent->RemoveSystemEventListener(NS_LITERAL_STRING("keydown"),
|
|
|
|
mEventListener, false);
|
2013-07-19 18:32:51 +04:00
|
|
|
mContent->RemoveSystemEventListener(NS_LITERAL_STRING("keypress"),
|
|
|
|
mEventListener, false);
|
|
|
|
mContent->RemoveSystemEventListener(NS_LITERAL_STRING("mousedown"),
|
|
|
|
mEventListener, false);
|
|
|
|
mContent->RemoveSystemEventListener(NS_LITERAL_STRING("mouseup"),
|
|
|
|
mEventListener, false);
|
|
|
|
mContent->RemoveSystemEventListener(NS_LITERAL_STRING("mousemove"),
|
|
|
|
mEventListener, false);
|
2000-08-15 02:05:28 +04:00
|
|
|
|
2011-10-17 18:59:28 +04:00
|
|
|
nsFormControlFrame::RegUnRegAccessKey(static_cast<nsIFrame*>(this), false);
|
2009-12-24 08:21:15 +03:00
|
|
|
nsHTMLScrollFrame::DestroyFrom(aDestructRoot);
|
2000-08-03 18:13:58 +04:00
|
|
|
}
|
|
|
|
|
2013-02-14 15:12:27 +04:00
|
|
|
void
|
2006-01-26 05:29:17 +03:00
|
|
|
nsListControlFrame::BuildDisplayList(nsDisplayListBuilder* aBuilder,
|
|
|
|
const nsRect& aDirtyRect,
|
|
|
|
const nsDisplayListSet& aLists)
|
2001-01-27 17:09:34 +03:00
|
|
|
{
|
2006-01-26 05:29:17 +03:00
|
|
|
// We allow visibility:hidden <select>s to contain visible options.
|
|
|
|
|
2001-04-25 23:52:49 +04:00
|
|
|
// Don't allow painting of list controls when painting is suppressed.
|
2006-01-26 05:29:17 +03:00
|
|
|
// XXX why do we need this here? we should never reach this. Maybe
|
|
|
|
// because these can have widgets? Hmm
|
|
|
|
if (aBuilder->IsBackgroundOnly())
|
2013-02-14 15:12:27 +04:00
|
|
|
return;
|
2006-09-19 08:26:20 +04:00
|
|
|
|
|
|
|
DO_GLOBAL_REFLOW_COUNT_DSP("nsListControlFrame");
|
|
|
|
|
2009-08-25 23:07:57 +04:00
|
|
|
if (IsInDropDownMode()) {
|
2009-09-02 06:46:47 +04:00
|
|
|
NS_ASSERTION(NS_GET_A(mLastDropdownBackstopColor) == 255,
|
|
|
|
"need an opaque backstop color");
|
2009-08-25 23:07:57 +04:00
|
|
|
// XXX Because we have an opaque widget and we get called to paint with
|
|
|
|
// this frame as the root of a stacking context we need make sure to draw
|
|
|
|
// some opaque color over the whole widget. (Bug 511323)
|
|
|
|
aLists.BorderBackground()->AppendNewToBottom(
|
2010-08-13 14:01:13 +04:00
|
|
|
new (aBuilder) nsDisplaySolidColor(aBuilder,
|
2009-08-25 23:07:57 +04:00
|
|
|
this, nsRect(aBuilder->ToReferenceFrame(this), GetSize()),
|
|
|
|
mLastDropdownBackstopColor));
|
|
|
|
}
|
|
|
|
|
2013-02-14 15:12:27 +04:00
|
|
|
nsHTMLScrollFrame::BuildDisplayList(aBuilder, aDirtyRect, aLists);
|
2001-01-27 17:09:34 +03:00
|
|
|
}
|
1999-01-18 18:14:00 +03:00
|
|
|
|
2006-01-26 05:29:17 +03:00
|
|
|
/**
|
|
|
|
* This is called by the SelectsAreaFrame, which is the same
|
|
|
|
* as the frame returned by GetOptionsContainer. It's the frame which is
|
|
|
|
* scrolled by us.
|
|
|
|
* @param aPt the offset of this frame, relative to the rendering reference
|
|
|
|
* frame
|
|
|
|
*/
|
2011-04-08 05:04:40 +04:00
|
|
|
void nsListControlFrame::PaintFocus(nsRenderingContext& aRC, nsPoint aPt)
|
2002-04-11 04:53:20 +04:00
|
|
|
{
|
|
|
|
if (mFocused != this) return;
|
|
|
|
|
2007-03-31 01:11:41 +04:00
|
|
|
nsPresContext* presContext = PresContext();
|
2002-04-11 04:53:20 +04:00
|
|
|
|
2005-10-24 02:11:27 +04:00
|
|
|
nsIFrame* containerFrame = GetOptionsContainer();
|
2002-04-11 04:53:20 +04:00
|
|
|
if (!containerFrame) return;
|
|
|
|
|
2012-07-30 18:20:58 +04:00
|
|
|
nsIFrame* childframe = nullptr;
|
2011-09-28 05:46:11 +04:00
|
|
|
nsCOMPtr<nsIContent> focusedContent = GetCurrentOption();
|
|
|
|
if (focusedContent) {
|
|
|
|
childframe = focusedContent->GetPrimaryFrame();
|
2002-04-11 04:53:20 +04:00
|
|
|
}
|
|
|
|
|
2005-11-05 02:36:27 +03:00
|
|
|
nsRect fRect;
|
|
|
|
if (childframe) {
|
|
|
|
// get the child rect
|
|
|
|
fRect = childframe->GetRect();
|
2006-04-20 06:37:31 +04:00
|
|
|
// get it into our coordinates
|
2006-01-26 05:29:17 +03:00
|
|
|
fRect.MoveBy(childframe->GetParent()->GetOffsetTo(this));
|
2005-11-05 02:36:27 +03:00
|
|
|
} else {
|
2012-05-21 09:18:28 +04:00
|
|
|
float inflation = nsLayoutUtils::FontSizeInflationFor(this);
|
2005-11-05 02:36:27 +03:00
|
|
|
fRect.x = fRect.y = 0;
|
2009-10-08 07:01:15 +04:00
|
|
|
fRect.width = GetScrollPortRect().width;
|
2011-11-24 06:48:23 +04:00
|
|
|
fRect.height = CalcFallbackRowHeight(inflation);
|
2006-01-26 05:29:17 +03:00
|
|
|
fRect.MoveBy(containerFrame->GetOffsetTo(this));
|
2005-11-05 02:36:27 +03:00
|
|
|
}
|
2006-01-26 05:29:17 +03:00
|
|
|
fRect += aPt;
|
2003-04-09 00:50:57 +04:00
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
bool lastItemIsSelected = false;
|
2006-04-20 06:37:31 +04:00
|
|
|
if (focusedContent) {
|
|
|
|
nsCOMPtr<nsIDOMHTMLOptionElement> domOpt =
|
|
|
|
do_QueryInterface(focusedContent);
|
|
|
|
if (domOpt) {
|
2002-08-09 02:27:57 +04:00
|
|
|
domOpt->GetSelected(&lastItemIsSelected);
|
|
|
|
}
|
2002-04-17 04:09:54 +04:00
|
|
|
}
|
|
|
|
|
2002-04-11 04:53:20 +04:00
|
|
|
// set up back stop colors and then ask L&F service for the real colors
|
2011-09-09 06:27:13 +04:00
|
|
|
nscolor color =
|
|
|
|
LookAndFeel::GetColor(lastItemIsSelected ?
|
|
|
|
LookAndFeel::eColorID_WidgetSelectForeground :
|
|
|
|
LookAndFeel::eColorID_WidgetSelectBackground);
|
2002-04-11 04:53:20 +04:00
|
|
|
|
2008-08-06 14:33:18 +04:00
|
|
|
nsCSSRendering::PaintFocus(presContext, aRC, fRect, color);
|
2002-04-11 04:53:20 +04:00
|
|
|
}
|
|
|
|
|
2007-09-28 03:06:31 +04:00
|
|
|
void
|
2012-05-21 09:18:28 +04:00
|
|
|
nsListControlFrame::InvalidateFocus()
|
2007-09-28 03:06:31 +04:00
|
|
|
{
|
|
|
|
if (mFocused != this)
|
|
|
|
return;
|
|
|
|
|
|
|
|
nsIFrame* containerFrame = GetOptionsContainer();
|
|
|
|
if (containerFrame) {
|
2012-08-29 09:39:31 +04:00
|
|
|
containerFrame->InvalidateFrame();
|
2007-09-28 03:06:31 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-01-12 22:20:59 +03:00
|
|
|
NS_QUERYFRAME_HEAD(nsListControlFrame)
|
|
|
|
NS_QUERYFRAME_ENTRY(nsIFormControlFrame)
|
|
|
|
NS_QUERYFRAME_ENTRY(nsIListControlFrame)
|
|
|
|
NS_QUERYFRAME_ENTRY(nsISelectControlFrame)
|
|
|
|
NS_QUERYFRAME_TAIL_INHERITING(nsHTMLScrollFrame)
|
2003-04-09 00:50:57 +04:00
|
|
|
|
2001-08-17 07:13:07 +04:00
|
|
|
#ifdef ACCESSIBILITY
|
2012-09-29 01:53:44 +04:00
|
|
|
a11y::AccType
|
|
|
|
nsListControlFrame::AccessibleType()
|
2001-06-30 04:25:09 +04:00
|
|
|
{
|
2012-12-18 05:25:52 +04:00
|
|
|
return a11y::eHTMLSelectListType;
|
2001-06-30 04:25:09 +04:00
|
|
|
}
|
2001-08-17 07:13:07 +04:00
|
|
|
#endif
|
2001-06-30 04:25:09 +04:00
|
|
|
|
2003-01-10 03:30:50 +03:00
|
|
|
static nscoord
|
2005-07-24 05:02:15 +04:00
|
|
|
GetMaxOptionHeight(nsIFrame* aContainer)
|
2003-01-10 03:30:50 +03:00
|
|
|
{
|
|
|
|
nscoord result = 0;
|
2011-08-25 00:54:30 +04:00
|
|
|
for (nsIFrame* option = aContainer->GetFirstPrincipalChild();
|
2003-07-04 16:50:32 +04:00
|
|
|
option; option = option->GetNextSibling()) {
|
2003-01-10 03:30:50 +03:00
|
|
|
nscoord optionHeight;
|
2003-07-04 16:50:32 +04:00
|
|
|
if (nsCOMPtr<nsIDOMHTMLOptGroupElement>
|
|
|
|
(do_QueryInterface(option->GetContent()))) {
|
2003-01-10 03:30:50 +03:00
|
|
|
// an optgroup
|
2005-07-24 05:02:15 +04:00
|
|
|
optionHeight = GetMaxOptionHeight(option);
|
2003-01-10 03:30:50 +03:00
|
|
|
} else {
|
|
|
|
// an option
|
2003-07-04 16:50:32 +04:00
|
|
|
optionHeight = option->GetSize().height;
|
2003-01-10 03:30:50 +03:00
|
|
|
}
|
|
|
|
if (result < optionHeight)
|
|
|
|
result = optionHeight;
|
|
|
|
}
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2000-03-03 07:28:59 +03:00
|
|
|
//-----------------------------------------------------------------
|
|
|
|
// Main Reflow for ListBox/Dropdown
|
|
|
|
//-----------------------------------------------------------------
|
Bug 300030: Move intrinsic width computation out of nsIFrame::Reflow and into its own methods on nsIFrame. Replace reflow reasons, types, and commands with dirty bits/notifications. Thanks to bzbarsky for almost all of the HTML form controls (mozilla/layout/forms) changes, and many others for help testing and patching. For detailed commit logs, see REFLOW_YYYYMMDD_BRANCH, where YYYYMMDD is one of 20061031, 20060830, 20060603, 20060302, 20060119, 20051011, 20050804, 20050429, 20050315, 20050111, and 20041213.
2006-12-08 08:38:33 +03:00
|
|
|
|
|
|
|
nscoord
|
2012-01-25 05:21:29 +04:00
|
|
|
nsListControlFrame::CalcHeightOfARow()
|
Bug 300030: Move intrinsic width computation out of nsIFrame::Reflow and into its own methods on nsIFrame. Replace reflow reasons, types, and commands with dirty bits/notifications. Thanks to bzbarsky for almost all of the HTML form controls (mozilla/layout/forms) changes, and many others for help testing and patching. For detailed commit logs, see REFLOW_YYYYMMDD_BRANCH, where YYYYMMDD is one of 20061031, 20060830, 20060603, 20060302, 20060119, 20051011, 20050804, 20050429, 20050315, 20050111, and 20041213.
2006-12-08 08:38:33 +03:00
|
|
|
{
|
|
|
|
// Calculate the height of a single row in the listbox or dropdown list by
|
|
|
|
// using the tallest thing in the subtree, since there may be option groups
|
|
|
|
// in addition to option elements, either of which may be visible or
|
|
|
|
// invisible, may use different fonts, etc.
|
2012-08-22 19:56:38 +04:00
|
|
|
int32_t heightOfARow = GetMaxOptionHeight(GetOptionsContainer());
|
Bug 300030: Move intrinsic width computation out of nsIFrame::Reflow and into its own methods on nsIFrame. Replace reflow reasons, types, and commands with dirty bits/notifications. Thanks to bzbarsky for almost all of the HTML form controls (mozilla/layout/forms) changes, and many others for help testing and patching. For detailed commit logs, see REFLOW_YYYYMMDD_BRANCH, where YYYYMMDD is one of 20061031, 20060830, 20060603, 20060302, 20060119, 20051011, 20050804, 20050429, 20050315, 20050111, and 20041213.
2006-12-08 08:38:33 +03:00
|
|
|
|
2008-12-04 19:09:53 +03:00
|
|
|
// Check to see if we have zero items (and optimize by checking
|
|
|
|
// heightOfARow first)
|
|
|
|
if (heightOfARow == 0 && GetNumberOfOptions() == 0) {
|
2012-05-21 09:18:28 +04:00
|
|
|
float inflation = nsLayoutUtils::FontSizeInflationFor(this);
|
2011-11-24 06:48:23 +04:00
|
|
|
heightOfARow = CalcFallbackRowHeight(inflation);
|
Bug 300030: Move intrinsic width computation out of nsIFrame::Reflow and into its own methods on nsIFrame. Replace reflow reasons, types, and commands with dirty bits/notifications. Thanks to bzbarsky for almost all of the HTML form controls (mozilla/layout/forms) changes, and many others for help testing and patching. For detailed commit logs, see REFLOW_YYYYMMDD_BRANCH, where YYYYMMDD is one of 20061031, 20060830, 20060603, 20060302, 20060119, 20051011, 20050804, 20050429, 20050315, 20050111, and 20041213.
2006-12-08 08:38:33 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
return heightOfARow;
|
|
|
|
}
|
|
|
|
|
2008-02-28 23:37:06 +03:00
|
|
|
nscoord
|
2011-04-08 05:04:40 +04:00
|
|
|
nsListControlFrame::GetPrefWidth(nsRenderingContext *aRenderingContext)
|
2008-02-28 23:37:06 +03:00
|
|
|
{
|
|
|
|
nscoord result;
|
|
|
|
DISPLAY_PREF_WIDTH(this, result);
|
|
|
|
|
|
|
|
// Always add scrollbar widths to the pref-width of the scrolled
|
|
|
|
// content. Combobox frames depend on this happening in the dropdown,
|
|
|
|
// and standalone listboxes are overflow:scroll so they need it too.
|
|
|
|
result = GetScrolledFrame()->GetPrefWidth(aRenderingContext);
|
2008-04-10 08:39:41 +04:00
|
|
|
result = NSCoordSaturatingAdd(result,
|
|
|
|
GetDesiredScrollbarSizes(PresContext(), aRenderingContext).LeftRight());
|
2008-02-28 23:37:06 +03:00
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
Bug 300030: Move intrinsic width computation out of nsIFrame::Reflow and into its own methods on nsIFrame. Replace reflow reasons, types, and commands with dirty bits/notifications. Thanks to bzbarsky for almost all of the HTML form controls (mozilla/layout/forms) changes, and many others for help testing and patching. For detailed commit logs, see REFLOW_YYYYMMDD_BRANCH, where YYYYMMDD is one of 20061031, 20060830, 20060603, 20060302, 20060119, 20051011, 20050804, 20050429, 20050315, 20050111, and 20041213.
2006-12-08 08:38:33 +03:00
|
|
|
nscoord
|
2011-04-08 05:04:40 +04:00
|
|
|
nsListControlFrame::GetMinWidth(nsRenderingContext *aRenderingContext)
|
Bug 300030: Move intrinsic width computation out of nsIFrame::Reflow and into its own methods on nsIFrame. Replace reflow reasons, types, and commands with dirty bits/notifications. Thanks to bzbarsky for almost all of the HTML form controls (mozilla/layout/forms) changes, and many others for help testing and patching. For detailed commit logs, see REFLOW_YYYYMMDD_BRANCH, where YYYYMMDD is one of 20061031, 20060830, 20060603, 20060302, 20060119, 20051011, 20050804, 20050429, 20050315, 20050111, and 20041213.
2006-12-08 08:38:33 +03:00
|
|
|
{
|
|
|
|
nscoord result;
|
|
|
|
DISPLAY_MIN_WIDTH(this, result);
|
|
|
|
|
2008-02-28 23:37:06 +03:00
|
|
|
// Always add scrollbar widths to the min-width of the scrolled
|
|
|
|
// content. Combobox frames depend on this happening in the dropdown,
|
|
|
|
// and standalone listboxes are overflow:scroll so they need it too.
|
2007-12-03 10:38:48 +03:00
|
|
|
result = GetScrolledFrame()->GetMinWidth(aRenderingContext);
|
2008-04-10 08:39:41 +04:00
|
|
|
result += GetDesiredScrollbarSizes(PresContext(), aRenderingContext).LeftRight();
|
Bug 300030: Move intrinsic width computation out of nsIFrame::Reflow and into its own methods on nsIFrame. Replace reflow reasons, types, and commands with dirty bits/notifications. Thanks to bzbarsky for almost all of the HTML form controls (mozilla/layout/forms) changes, and many others for help testing and patching. For detailed commit logs, see REFLOW_YYYYMMDD_BRANCH, where YYYYMMDD is one of 20061031, 20060830, 20060603, 20060302, 20060119, 20051011, 20050804, 20050429, 20050315, 20050111, and 20041213.
2006-12-08 08:38:33 +03:00
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
1999-01-18 18:14:00 +03:00
|
|
|
NS_IMETHODIMP
|
2005-10-15 08:08:04 +04:00
|
|
|
nsListControlFrame::Reflow(nsPresContext* aPresContext,
|
1999-07-29 01:38:08 +04:00
|
|
|
nsHTMLReflowMetrics& aDesiredSize,
|
|
|
|
const nsHTMLReflowState& aReflowState,
|
|
|
|
nsReflowStatus& aStatus)
|
1999-01-18 18:14:00 +03:00
|
|
|
{
|
2007-01-26 03:05:12 +03:00
|
|
|
NS_PRECONDITION(aReflowState.ComputedWidth() != NS_UNCONSTRAINEDSIZE,
|
Bug 300030: Move intrinsic width computation out of nsIFrame::Reflow and into its own methods on nsIFrame. Replace reflow reasons, types, and commands with dirty bits/notifications. Thanks to bzbarsky for almost all of the HTML form controls (mozilla/layout/forms) changes, and many others for help testing and patching. For detailed commit logs, see REFLOW_YYYYMMDD_BRANCH, where YYYYMMDD is one of 20061031, 20060830, 20060603, 20060302, 20060119, 20051011, 20050804, 20050429, 20050315, 20050111, and 20041213.
2006-12-08 08:38:33 +03:00
|
|
|
"Must have a computed width");
|
2000-03-03 07:28:59 +03:00
|
|
|
|
2012-10-25 03:04:41 +04:00
|
|
|
SchedulePaint();
|
|
|
|
|
2009-09-05 01:07:38 +04:00
|
|
|
mHasPendingInterruptAtStartOfReflow = aPresContext->HasPendingInterrupt();
|
|
|
|
|
1999-11-12 01:13:33 +03:00
|
|
|
// If all the content and frames are here
|
|
|
|
// then initialize it before reflow
|
Bug 300030: Move intrinsic width computation out of nsIFrame::Reflow and into its own methods on nsIFrame. Replace reflow reasons, types, and commands with dirty bits/notifications. Thanks to bzbarsky for almost all of the HTML form controls (mozilla/layout/forms) changes, and many others for help testing and patching. For detailed commit logs, see REFLOW_YYYYMMDD_BRANCH, where YYYYMMDD is one of 20061031, 20060830, 20060603, 20060302, 20060119, 20051011, 20050804, 20050429, 20050315, 20050111, and 20041213.
2006-12-08 08:38:33 +03:00
|
|
|
if (mIsAllContentHere && !mHasBeenInitialized) {
|
2011-10-17 18:59:28 +04:00
|
|
|
if (false == mIsAllFramesHere) {
|
Bug 300030: Move intrinsic width computation out of nsIFrame::Reflow and into its own methods on nsIFrame. Replace reflow reasons, types, and commands with dirty bits/notifications. Thanks to bzbarsky for almost all of the HTML form controls (mozilla/layout/forms) changes, and many others for help testing and patching. For detailed commit logs, see REFLOW_YYYYMMDD_BRANCH, where YYYYMMDD is one of 20061031, 20060830, 20060603, 20060302, 20060119, 20051011, 20050804, 20050429, 20050315, 20050111, and 20041213.
2006-12-08 08:38:33 +03:00
|
|
|
CheckIfAllFramesHere();
|
1999-11-12 01:13:33 +03:00
|
|
|
}
|
Bug 300030: Move intrinsic width computation out of nsIFrame::Reflow and into its own methods on nsIFrame. Replace reflow reasons, types, and commands with dirty bits/notifications. Thanks to bzbarsky for almost all of the HTML form controls (mozilla/layout/forms) changes, and many others for help testing and patching. For detailed commit logs, see REFLOW_YYYYMMDD_BRANCH, where YYYYMMDD is one of 20061031, 20060830, 20060603, 20060302, 20060119, 20051011, 20050804, 20050429, 20050315, 20050111, and 20041213.
2006-12-08 08:38:33 +03:00
|
|
|
if (mIsAllFramesHere && !mHasBeenInitialized) {
|
2011-10-17 18:59:28 +04:00
|
|
|
mHasBeenInitialized = true;
|
2000-01-19 02:33:22 +03:00
|
|
|
}
|
1999-08-10 23:22:51 +04:00
|
|
|
}
|
|
|
|
|
Bug 300030: Move intrinsic width computation out of nsIFrame::Reflow and into its own methods on nsIFrame. Replace reflow reasons, types, and commands with dirty bits/notifications. Thanks to bzbarsky for almost all of the HTML form controls (mozilla/layout/forms) changes, and many others for help testing and patching. For detailed commit logs, see REFLOW_YYYYMMDD_BRANCH, where YYYYMMDD is one of 20061031, 20060830, 20060603, 20060302, 20060119, 20051011, 20050804, 20050429, 20050315, 20050111, and 20041213.
2006-12-08 08:38:33 +03:00
|
|
|
if (GetStateBits() & NS_FRAME_FIRST_REFLOW) {
|
2011-10-17 18:59:28 +04:00
|
|
|
nsFormControlFrame::RegUnRegAccessKey(this, true);
|
Bug 300030: Move intrinsic width computation out of nsIFrame::Reflow and into its own methods on nsIFrame. Replace reflow reasons, types, and commands with dirty bits/notifications. Thanks to bzbarsky for almost all of the HTML form controls (mozilla/layout/forms) changes, and many others for help testing and patching. For detailed commit logs, see REFLOW_YYYYMMDD_BRANCH, where YYYYMMDD is one of 20061031, 20060830, 20060603, 20060302, 20060119, 20051011, 20050804, 20050429, 20050315, 20050111, and 20041213.
2006-12-08 08:38:33 +03:00
|
|
|
}
|
1999-07-21 02:32:41 +04:00
|
|
|
|
Bug 300030: Move intrinsic width computation out of nsIFrame::Reflow and into its own methods on nsIFrame. Replace reflow reasons, types, and commands with dirty bits/notifications. Thanks to bzbarsky for almost all of the HTML form controls (mozilla/layout/forms) changes, and many others for help testing and patching. For detailed commit logs, see REFLOW_YYYYMMDD_BRANCH, where YYYYMMDD is one of 20061031, 20060830, 20060603, 20060302, 20060119, 20051011, 20050804, 20050429, 20050315, 20050111, and 20041213.
2006-12-08 08:38:33 +03:00
|
|
|
if (IsInDropDownMode()) {
|
|
|
|
return ReflowAsDropdown(aPresContext, aDesiredSize, aReflowState, aStatus);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Due to the fact that our intrinsic height depends on the heights of our
|
|
|
|
* kids, we end up having to do two-pass reflow, in general -- the first pass
|
|
|
|
* to find the intrinsic height and a second pass to reflow the scrollframe
|
|
|
|
* at that height (which will size the scrollbars correctly, etc).
|
|
|
|
*
|
|
|
|
* Naturaly, we want to avoid doing the second reflow as much as possible.
|
|
|
|
* We can skip it in the following cases (in all of which the first reflow is
|
|
|
|
* already happening at the right height):
|
|
|
|
*
|
|
|
|
* - We're reflowing with a constrained computed height -- just use that
|
|
|
|
* height.
|
2007-08-03 02:02:25 +04:00
|
|
|
* - We're not dirty and have no dirty kids and shouldn't be reflowing all
|
|
|
|
* kids. In this case, our cached max height of a child is not going to
|
|
|
|
* change.
|
Bug 300030: Move intrinsic width computation out of nsIFrame::Reflow and into its own methods on nsIFrame. Replace reflow reasons, types, and commands with dirty bits/notifications. Thanks to bzbarsky for almost all of the HTML form controls (mozilla/layout/forms) changes, and many others for help testing and patching. For detailed commit logs, see REFLOW_YYYYMMDD_BRANCH, where YYYYMMDD is one of 20061031, 20060830, 20060603, 20060302, 20060119, 20051011, 20050804, 20050429, 20050315, 20050111, and 20041213.
2006-12-08 08:38:33 +03:00
|
|
|
* - We do our first reflow using our cached max height of a child, then
|
|
|
|
* compute the new max height and it's the same as the old one.
|
|
|
|
*/
|
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
bool autoHeight = (aReflowState.ComputedHeight() == NS_UNCONSTRAINEDSIZE);
|
Bug 300030: Move intrinsic width computation out of nsIFrame::Reflow and into its own methods on nsIFrame. Replace reflow reasons, types, and commands with dirty bits/notifications. Thanks to bzbarsky for almost all of the HTML form controls (mozilla/layout/forms) changes, and many others for help testing and patching. For detailed commit logs, see REFLOW_YYYYMMDD_BRANCH, where YYYYMMDD is one of 20061031, 20060830, 20060603, 20060302, 20060119, 20051011, 20050804, 20050429, 20050315, 20050111, and 20041213.
2006-12-08 08:38:33 +03:00
|
|
|
|
2007-08-03 02:02:25 +04:00
|
|
|
mMightNeedSecondPass = autoHeight &&
|
|
|
|
(NS_SUBTREE_DIRTY(this) || aReflowState.ShouldReflowAllKids());
|
1999-03-23 00:32:12 +03:00
|
|
|
|
Bug 300030: Move intrinsic width computation out of nsIFrame::Reflow and into its own methods on nsIFrame. Replace reflow reasons, types, and commands with dirty bits/notifications. Thanks to bzbarsky for almost all of the HTML form controls (mozilla/layout/forms) changes, and many others for help testing and patching. For detailed commit logs, see REFLOW_YYYYMMDD_BRANCH, where YYYYMMDD is one of 20061031, 20060830, 20060603, 20060302, 20060119, 20051011, 20050804, 20050429, 20050315, 20050111, and 20041213.
2006-12-08 08:38:33 +03:00
|
|
|
nsHTMLReflowState state(aReflowState);
|
2012-11-01 02:00:36 +04:00
|
|
|
int32_t length = GetNumberOfRows();
|
2002-05-10 22:22:41 +04:00
|
|
|
|
Bug 300030: Move intrinsic width computation out of nsIFrame::Reflow and into its own methods on nsIFrame. Replace reflow reasons, types, and commands with dirty bits/notifications. Thanks to bzbarsky for almost all of the HTML form controls (mozilla/layout/forms) changes, and many others for help testing and patching. For detailed commit logs, see REFLOW_YYYYMMDD_BRANCH, where YYYYMMDD is one of 20061031, 20060830, 20060603, 20060302, 20060119, 20051011, 20050804, 20050429, 20050315, 20050111, and 20041213.
2006-12-08 08:38:33 +03:00
|
|
|
nscoord oldHeightOfARow = HeightOfARow();
|
2010-05-05 22:18:04 +04:00
|
|
|
|
Bug 300030: Move intrinsic width computation out of nsIFrame::Reflow and into its own methods on nsIFrame. Replace reflow reasons, types, and commands with dirty bits/notifications. Thanks to bzbarsky for almost all of the HTML form controls (mozilla/layout/forms) changes, and many others for help testing and patching. For detailed commit logs, see REFLOW_YYYYMMDD_BRANCH, where YYYYMMDD is one of 20061031, 20060830, 20060603, 20060302, 20060119, 20051011, 20050804, 20050429, 20050315, 20050111, and 20041213.
2006-12-08 08:38:33 +03:00
|
|
|
if (!(GetStateBits() & NS_FRAME_FIRST_REFLOW) && autoHeight) {
|
|
|
|
// When not doing an initial reflow, and when the height is auto, start off
|
|
|
|
// with our computed height set to what we'd expect our height to be.
|
2007-08-02 22:08:05 +04:00
|
|
|
nscoord computedHeight = CalcIntrinsicHeight(oldHeightOfARow, length);
|
2012-07-18 18:26:05 +04:00
|
|
|
computedHeight = state.ApplyMinMaxHeight(computedHeight);
|
2007-08-02 22:08:05 +04:00
|
|
|
state.SetComputedHeight(computedHeight);
|
1999-05-28 01:17:10 +04:00
|
|
|
}
|
|
|
|
|
Bug 300030: Move intrinsic width computation out of nsIFrame::Reflow and into its own methods on nsIFrame. Replace reflow reasons, types, and commands with dirty bits/notifications. Thanks to bzbarsky for almost all of the HTML form controls (mozilla/layout/forms) changes, and many others for help testing and patching. For detailed commit logs, see REFLOW_YYYYMMDD_BRANCH, where YYYYMMDD is one of 20061031, 20060830, 20060603, 20060302, 20060119, 20051011, 20050804, 20050429, 20050315, 20050111, and 20041213.
2006-12-08 08:38:33 +03:00
|
|
|
nsresult rv = nsHTMLScrollFrame::Reflow(aPresContext, aDesiredSize,
|
|
|
|
state, aStatus);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2001-02-23 04:45:45 +03:00
|
|
|
|
Bug 300030: Move intrinsic width computation out of nsIFrame::Reflow and into its own methods on nsIFrame. Replace reflow reasons, types, and commands with dirty bits/notifications. Thanks to bzbarsky for almost all of the HTML form controls (mozilla/layout/forms) changes, and many others for help testing and patching. For detailed commit logs, see REFLOW_YYYYMMDD_BRANCH, where YYYYMMDD is one of 20061031, 20060830, 20060603, 20060302, 20060119, 20051011, 20050804, 20050429, 20050315, 20050111, and 20041213.
2006-12-08 08:38:33 +03:00
|
|
|
if (!mMightNeedSecondPass) {
|
|
|
|
NS_ASSERTION(!autoHeight || HeightOfARow() == oldHeightOfARow,
|
|
|
|
"How did our height of a row change if nothing was dirty?");
|
2010-05-05 22:18:04 +04:00
|
|
|
NS_ASSERTION(!autoHeight ||
|
|
|
|
!(GetStateBits() & NS_FRAME_FIRST_REFLOW),
|
|
|
|
"How do we not need a second pass during initial reflow at "
|
|
|
|
"auto height?");
|
Bug 300030: Move intrinsic width computation out of nsIFrame::Reflow and into its own methods on nsIFrame. Replace reflow reasons, types, and commands with dirty bits/notifications. Thanks to bzbarsky for almost all of the HTML form controls (mozilla/layout/forms) changes, and many others for help testing and patching. For detailed commit logs, see REFLOW_YYYYMMDD_BRANCH, where YYYYMMDD is one of 20061031, 20060830, 20060603, 20060302, 20060119, 20051011, 20050804, 20050429, 20050315, 20050111, and 20041213.
2006-12-08 08:38:33 +03:00
|
|
|
NS_ASSERTION(!IsScrollbarUpdateSuppressed(),
|
|
|
|
"Shouldn't be suppressing if we don't need a second pass!");
|
2010-05-05 22:18:04 +04:00
|
|
|
if (!autoHeight) {
|
|
|
|
// Update our mNumDisplayRows based on our new row height now that we
|
|
|
|
// know it. Note that if autoHeight and we landed in this code then we
|
|
|
|
// already set mNumDisplayRows in CalcIntrinsicHeight. Also note that we
|
|
|
|
// can't use HeightOfARow() here because that just uses a cached value
|
|
|
|
// that we didn't compute.
|
2012-01-25 05:21:29 +04:00
|
|
|
nscoord rowHeight = CalcHeightOfARow();
|
2010-05-05 22:18:04 +04:00
|
|
|
if (rowHeight == 0) {
|
|
|
|
// Just pick something
|
|
|
|
mNumDisplayRows = 1;
|
|
|
|
} else {
|
2013-01-15 16:22:03 +04:00
|
|
|
mNumDisplayRows = std::max(1, state.ComputedHeight() / rowHeight);
|
2010-05-05 22:18:04 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
Bug 300030: Move intrinsic width computation out of nsIFrame::Reflow and into its own methods on nsIFrame. Replace reflow reasons, types, and commands with dirty bits/notifications. Thanks to bzbarsky for almost all of the HTML form controls (mozilla/layout/forms) changes, and many others for help testing and patching. For detailed commit logs, see REFLOW_YYYYMMDD_BRANCH, where YYYYMMDD is one of 20061031, 20060830, 20060603, 20060302, 20060119, 20051011, 20050804, 20050429, 20050315, 20050111, and 20041213.
2006-12-08 08:38:33 +03:00
|
|
|
return rv;
|
1999-04-16 23:28:12 +04:00
|
|
|
}
|
2000-01-09 04:41:11 +03:00
|
|
|
|
2011-10-17 18:59:28 +04:00
|
|
|
mMightNeedSecondPass = false;
|
1999-05-08 00:30:16 +04:00
|
|
|
|
2007-01-22 07:29:35 +03:00
|
|
|
// Now see whether we need a second pass. If we do, our nsSelectsAreaFrame
|
|
|
|
// will have suppressed the scrollbar update.
|
|
|
|
if (!IsScrollbarUpdateSuppressed()) {
|
Bug 300030: Move intrinsic width computation out of nsIFrame::Reflow and into its own methods on nsIFrame. Replace reflow reasons, types, and commands with dirty bits/notifications. Thanks to bzbarsky for almost all of the HTML form controls (mozilla/layout/forms) changes, and many others for help testing and patching. For detailed commit logs, see REFLOW_YYYYMMDD_BRANCH, where YYYYMMDD is one of 20061031, 20060830, 20060603, 20060302, 20060119, 20051011, 20050804, 20050429, 20050315, 20050111, and 20041213.
2006-12-08 08:38:33 +03:00
|
|
|
// All done. No need to do more reflow.
|
|
|
|
NS_ASSERTION(!IsScrollbarUpdateSuppressed(),
|
|
|
|
"Shouldn't be suppressing if the height of a row has not "
|
|
|
|
"changed!");
|
|
|
|
return rv;
|
1999-03-23 00:32:12 +03:00
|
|
|
}
|
|
|
|
|
2011-10-17 18:59:28 +04:00
|
|
|
SetSuppressScrollbarUpdate(false);
|
1999-09-09 23:37:23 +04:00
|
|
|
|
Bug 300030: Move intrinsic width computation out of nsIFrame::Reflow and into its own methods on nsIFrame. Replace reflow reasons, types, and commands with dirty bits/notifications. Thanks to bzbarsky for almost all of the HTML form controls (mozilla/layout/forms) changes, and many others for help testing and patching. For detailed commit logs, see REFLOW_YYYYMMDD_BRANCH, where YYYYMMDD is one of 20061031, 20060830, 20060603, 20060302, 20060119, 20051011, 20050804, 20050429, 20050315, 20050111, and 20041213.
2006-12-08 08:38:33 +03:00
|
|
|
// Gotta reflow again.
|
|
|
|
// XXXbz We're just changing the height here; do we need to dirty ourselves
|
|
|
|
// or anything like that? We might need to, per the letter of the reflow
|
|
|
|
// protocol, but things seem to work fine without it... Is that just an
|
|
|
|
// implementation detail of nsHTMLScrollFrame that we're depending on?
|
2012-11-09 05:27:48 +04:00
|
|
|
nsHTMLScrollFrame::DidReflow(aPresContext, &state,
|
2012-11-14 10:47:33 +04:00
|
|
|
nsDidReflowStatus::FINISHED);
|
2000-12-20 18:15:28 +03:00
|
|
|
|
Bug 300030: Move intrinsic width computation out of nsIFrame::Reflow and into its own methods on nsIFrame. Replace reflow reasons, types, and commands with dirty bits/notifications. Thanks to bzbarsky for almost all of the HTML form controls (mozilla/layout/forms) changes, and many others for help testing and patching. For detailed commit logs, see REFLOW_YYYYMMDD_BRANCH, where YYYYMMDD is one of 20061031, 20060830, 20060603, 20060302, 20060119, 20051011, 20050804, 20050429, 20050315, 20050111, and 20041213.
2006-12-08 08:38:33 +03:00
|
|
|
// Now compute the height we want to have
|
2007-08-02 22:08:05 +04:00
|
|
|
nscoord computedHeight = CalcIntrinsicHeight(HeightOfARow(), length);
|
2012-07-18 18:26:05 +04:00
|
|
|
computedHeight = state.ApplyMinMaxHeight(computedHeight);
|
2007-08-02 22:08:05 +04:00
|
|
|
state.SetComputedHeight(computedHeight);
|
2000-01-09 04:41:11 +03:00
|
|
|
|
Bug 300030: Move intrinsic width computation out of nsIFrame::Reflow and into its own methods on nsIFrame. Replace reflow reasons, types, and commands with dirty bits/notifications. Thanks to bzbarsky for almost all of the HTML form controls (mozilla/layout/forms) changes, and many others for help testing and patching. For detailed commit logs, see REFLOW_YYYYMMDD_BRANCH, where YYYYMMDD is one of 20061031, 20060830, 20060603, 20060302, 20060119, 20051011, 20050804, 20050429, 20050315, 20050111, and 20041213.
2006-12-08 08:38:33 +03:00
|
|
|
nsHTMLScrollFrame::WillReflow(aPresContext);
|
2004-07-28 05:24:58 +04:00
|
|
|
|
Bug 300030: Move intrinsic width computation out of nsIFrame::Reflow and into its own methods on nsIFrame. Replace reflow reasons, types, and commands with dirty bits/notifications. Thanks to bzbarsky for almost all of the HTML form controls (mozilla/layout/forms) changes, and many others for help testing and patching. For detailed commit logs, see REFLOW_YYYYMMDD_BRANCH, where YYYYMMDD is one of 20061031, 20060830, 20060603, 20060302, 20060119, 20051011, 20050804, 20050429, 20050315, 20050111, and 20041213.
2006-12-08 08:38:33 +03:00
|
|
|
// XXXbz to make the ascent really correct, we should add our
|
|
|
|
// mComputedPadding.top to it (and subtract it from descent). Need that
|
|
|
|
// because nsGfxScrollFrame just adds in the border....
|
|
|
|
return nsHTMLScrollFrame::Reflow(aPresContext, aDesiredSize, state, aStatus);
|
|
|
|
}
|
2001-06-05 22:09:13 +04:00
|
|
|
|
Bug 300030: Move intrinsic width computation out of nsIFrame::Reflow and into its own methods on nsIFrame. Replace reflow reasons, types, and commands with dirty bits/notifications. Thanks to bzbarsky for almost all of the HTML form controls (mozilla/layout/forms) changes, and many others for help testing and patching. For detailed commit logs, see REFLOW_YYYYMMDD_BRANCH, where YYYYMMDD is one of 20061031, 20060830, 20060603, 20060302, 20060119, 20051011, 20050804, 20050429, 20050315, 20050111, and 20041213.
2006-12-08 08:38:33 +03:00
|
|
|
nsresult
|
|
|
|
nsListControlFrame::ReflowAsDropdown(nsPresContext* aPresContext,
|
|
|
|
nsHTMLReflowMetrics& aDesiredSize,
|
|
|
|
const nsHTMLReflowState& aReflowState,
|
|
|
|
nsReflowStatus& aStatus)
|
|
|
|
{
|
2007-08-02 22:08:05 +04:00
|
|
|
NS_PRECONDITION(aReflowState.ComputedHeight() == NS_UNCONSTRAINEDSIZE,
|
Bug 300030: Move intrinsic width computation out of nsIFrame::Reflow and into its own methods on nsIFrame. Replace reflow reasons, types, and commands with dirty bits/notifications. Thanks to bzbarsky for almost all of the HTML form controls (mozilla/layout/forms) changes, and many others for help testing and patching. For detailed commit logs, see REFLOW_YYYYMMDD_BRANCH, where YYYYMMDD is one of 20061031, 20060830, 20060603, 20060302, 20060119, 20051011, 20050804, 20050429, 20050315, 20050111, and 20041213.
2006-12-08 08:38:33 +03:00
|
|
|
"We should not have a computed height here!");
|
|
|
|
|
2007-08-03 02:02:25 +04:00
|
|
|
mMightNeedSecondPass = NS_SUBTREE_DIRTY(this) ||
|
|
|
|
aReflowState.ShouldReflowAllKids();
|
Bug 300030: Move intrinsic width computation out of nsIFrame::Reflow and into its own methods on nsIFrame. Replace reflow reasons, types, and commands with dirty bits/notifications. Thanks to bzbarsky for almost all of the HTML form controls (mozilla/layout/forms) changes, and many others for help testing and patching. For detailed commit logs, see REFLOW_YYYYMMDD_BRANCH, where YYYYMMDD is one of 20061031, 20060830, 20060603, 20060302, 20060119, 20051011, 20050804, 20050429, 20050315, 20050111, and 20041213.
2006-12-08 08:38:33 +03:00
|
|
|
|
2008-09-20 17:42:03 +04:00
|
|
|
#ifdef DEBUG
|
Bug 300030: Move intrinsic width computation out of nsIFrame::Reflow and into its own methods on nsIFrame. Replace reflow reasons, types, and commands with dirty bits/notifications. Thanks to bzbarsky for almost all of the HTML form controls (mozilla/layout/forms) changes, and many others for help testing and patching. For detailed commit logs, see REFLOW_YYYYMMDD_BRANCH, where YYYYMMDD is one of 20061031, 20060830, 20060603, 20060302, 20060119, 20051011, 20050804, 20050429, 20050315, 20050111, and 20041213.
2006-12-08 08:38:33 +03:00
|
|
|
nscoord oldHeightOfARow = HeightOfARow();
|
2012-06-23 05:13:56 +04:00
|
|
|
nscoord oldVisibleHeight = (GetStateBits() & NS_FRAME_FIRST_REFLOW) ?
|
|
|
|
NS_UNCONSTRAINEDSIZE : GetScrolledFrame()->GetSize().height;
|
2008-09-20 17:42:03 +04:00
|
|
|
#endif
|
Bug 300030: Move intrinsic width computation out of nsIFrame::Reflow and into its own methods on nsIFrame. Replace reflow reasons, types, and commands with dirty bits/notifications. Thanks to bzbarsky for almost all of the HTML form controls (mozilla/layout/forms) changes, and many others for help testing and patching. For detailed commit logs, see REFLOW_YYYYMMDD_BRANCH, where YYYYMMDD is one of 20061031, 20060830, 20060603, 20060302, 20060119, 20051011, 20050804, 20050429, 20050315, 20050111, and 20041213.
2006-12-08 08:38:33 +03:00
|
|
|
|
|
|
|
nsHTMLReflowState state(aReflowState);
|
|
|
|
|
|
|
|
if (!(GetStateBits() & NS_FRAME_FIRST_REFLOW)) {
|
|
|
|
// When not doing an initial reflow, and when the height is auto, start off
|
|
|
|
// with our computed height set to what we'd expect our height to be.
|
|
|
|
// Note: At this point, mLastDropdownComputedHeight can be
|
|
|
|
// NS_UNCONSTRAINEDSIZE in cases when last time we didn't have to constrain
|
|
|
|
// the height. That's fine; just do the same thing as last time.
|
2007-08-02 22:08:05 +04:00
|
|
|
state.SetComputedHeight(mLastDropdownComputedHeight);
|
Bug 300030: Move intrinsic width computation out of nsIFrame::Reflow and into its own methods on nsIFrame. Replace reflow reasons, types, and commands with dirty bits/notifications. Thanks to bzbarsky for almost all of the HTML form controls (mozilla/layout/forms) changes, and many others for help testing and patching. For detailed commit logs, see REFLOW_YYYYMMDD_BRANCH, where YYYYMMDD is one of 20061031, 20060830, 20060603, 20060302, 20060119, 20051011, 20050804, 20050429, 20050315, 20050111, and 20041213.
2006-12-08 08:38:33 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
nsresult rv = nsHTMLScrollFrame::Reflow(aPresContext, aDesiredSize,
|
|
|
|
state, aStatus);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
if (!mMightNeedSecondPass) {
|
|
|
|
NS_ASSERTION(oldVisibleHeight == GetScrolledFrame()->GetSize().height,
|
|
|
|
"How did our kid's height change if nothing was dirty?");
|
|
|
|
NS_ASSERTION(HeightOfARow() == oldHeightOfARow,
|
|
|
|
"How did our height of a row change if nothing was dirty?");
|
|
|
|
NS_ASSERTION(!IsScrollbarUpdateSuppressed(),
|
|
|
|
"Shouldn't be suppressing if we don't need a second pass!");
|
|
|
|
NS_ASSERTION(!(GetStateBits() & NS_FRAME_FIRST_REFLOW),
|
|
|
|
"How can we avoid a second pass during first reflow?");
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
2011-10-17 18:59:28 +04:00
|
|
|
mMightNeedSecondPass = false;
|
Bug 300030: Move intrinsic width computation out of nsIFrame::Reflow and into its own methods on nsIFrame. Replace reflow reasons, types, and commands with dirty bits/notifications. Thanks to bzbarsky for almost all of the HTML form controls (mozilla/layout/forms) changes, and many others for help testing and patching. For detailed commit logs, see REFLOW_YYYYMMDD_BRANCH, where YYYYMMDD is one of 20061031, 20060830, 20060603, 20060302, 20060119, 20051011, 20050804, 20050429, 20050315, 20050111, and 20041213.
2006-12-08 08:38:33 +03:00
|
|
|
|
2007-01-22 07:29:35 +03:00
|
|
|
// Now see whether we need a second pass. If we do, our nsSelectsAreaFrame
|
|
|
|
// will have suppressed the scrollbar update.
|
|
|
|
if (!IsScrollbarUpdateSuppressed()) {
|
Bug 300030: Move intrinsic width computation out of nsIFrame::Reflow and into its own methods on nsIFrame. Replace reflow reasons, types, and commands with dirty bits/notifications. Thanks to bzbarsky for almost all of the HTML form controls (mozilla/layout/forms) changes, and many others for help testing and patching. For detailed commit logs, see REFLOW_YYYYMMDD_BRANCH, where YYYYMMDD is one of 20061031, 20060830, 20060603, 20060302, 20060119, 20051011, 20050804, 20050429, 20050315, 20050111, and 20041213.
2006-12-08 08:38:33 +03:00
|
|
|
// All done. No need to do more reflow.
|
|
|
|
NS_ASSERTION(!(GetStateBits() & NS_FRAME_FIRST_REFLOW),
|
|
|
|
"How can we avoid a second pass during first reflow?");
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
2011-10-17 18:59:28 +04:00
|
|
|
SetSuppressScrollbarUpdate(false);
|
Bug 300030: Move intrinsic width computation out of nsIFrame::Reflow and into its own methods on nsIFrame. Replace reflow reasons, types, and commands with dirty bits/notifications. Thanks to bzbarsky for almost all of the HTML form controls (mozilla/layout/forms) changes, and many others for help testing and patching. For detailed commit logs, see REFLOW_YYYYMMDD_BRANCH, where YYYYMMDD is one of 20061031, 20060830, 20060603, 20060302, 20060119, 20051011, 20050804, 20050429, 20050315, 20050111, and 20041213.
2006-12-08 08:38:33 +03:00
|
|
|
|
2007-01-22 07:29:35 +03:00
|
|
|
nscoord visibleHeight = GetScrolledFrame()->GetSize().height;
|
|
|
|
nscoord heightOfARow = HeightOfARow();
|
|
|
|
|
Bug 300030: Move intrinsic width computation out of nsIFrame::Reflow and into its own methods on nsIFrame. Replace reflow reasons, types, and commands with dirty bits/notifications. Thanks to bzbarsky for almost all of the HTML form controls (mozilla/layout/forms) changes, and many others for help testing and patching. For detailed commit logs, see REFLOW_YYYYMMDD_BRANCH, where YYYYMMDD is one of 20061031, 20060830, 20060603, 20060302, 20060119, 20051011, 20050804, 20050429, 20050315, 20050111, and 20041213.
2006-12-08 08:38:33 +03:00
|
|
|
// Gotta reflow again.
|
|
|
|
// XXXbz We're just changing the height here; do we need to dirty ourselves
|
|
|
|
// or anything like that? We might need to, per the letter of the reflow
|
|
|
|
// protocol, but things seem to work fine without it... Is that just an
|
|
|
|
// implementation detail of nsHTMLScrollFrame that we're depending on?
|
2012-11-09 05:27:48 +04:00
|
|
|
nsHTMLScrollFrame::DidReflow(aPresContext, &state,
|
2012-11-14 10:47:33 +04:00
|
|
|
nsDidReflowStatus::FINISHED);
|
Bug 300030: Move intrinsic width computation out of nsIFrame::Reflow and into its own methods on nsIFrame. Replace reflow reasons, types, and commands with dirty bits/notifications. Thanks to bzbarsky for almost all of the HTML form controls (mozilla/layout/forms) changes, and many others for help testing and patching. For detailed commit logs, see REFLOW_YYYYMMDD_BRANCH, where YYYYMMDD is one of 20061031, 20060830, 20060603, 20060302, 20060119, 20051011, 20050804, 20050429, 20050315, 20050111, and 20041213.
2006-12-08 08:38:33 +03:00
|
|
|
|
2012-06-23 05:13:56 +04:00
|
|
|
// Now compute the height we want to have.
|
|
|
|
// Note: no need to apply min/max constraints, since we have no such
|
|
|
|
// rules applied to the combobox dropdown.
|
1999-10-08 01:39:50 +04:00
|
|
|
|
2012-06-23 05:13:56 +04:00
|
|
|
mDropdownCanGrow = false;
|
|
|
|
if (visibleHeight <= 0 || heightOfARow <= 0) {
|
Bug 300030: Move intrinsic width computation out of nsIFrame::Reflow and into its own methods on nsIFrame. Replace reflow reasons, types, and commands with dirty bits/notifications. Thanks to bzbarsky for almost all of the HTML form controls (mozilla/layout/forms) changes, and many others for help testing and patching. For detailed commit logs, see REFLOW_YYYYMMDD_BRANCH, where YYYYMMDD is one of 20061031, 20060830, 20060603, 20060302, 20060119, 20051011, 20050804, 20050429, 20050315, 20050111, and 20041213.
2006-12-08 08:38:33 +03:00
|
|
|
// Looks like we have no options. Just size us to a single row height.
|
2007-08-02 22:08:05 +04:00
|
|
|
state.SetComputedHeight(heightOfARow);
|
2012-06-23 05:13:56 +04:00
|
|
|
mNumDisplayRows = 1;
|
Bug 300030: Move intrinsic width computation out of nsIFrame::Reflow and into its own methods on nsIFrame. Replace reflow reasons, types, and commands with dirty bits/notifications. Thanks to bzbarsky for almost all of the HTML form controls (mozilla/layout/forms) changes, and many others for help testing and patching. For detailed commit logs, see REFLOW_YYYYMMDD_BRANCH, where YYYYMMDD is one of 20061031, 20060830, 20060603, 20060302, 20060119, 20051011, 20050804, 20050429, 20050315, 20050111, and 20041213.
2006-12-08 08:38:33 +03:00
|
|
|
} else {
|
2012-06-23 05:13:56 +04:00
|
|
|
nsComboboxControlFrame* combobox = static_cast<nsComboboxControlFrame*>(mComboboxFrame);
|
|
|
|
nsPoint translation;
|
|
|
|
nscoord above, below;
|
|
|
|
combobox->GetAvailableDropdownSpace(&above, &below, &translation);
|
|
|
|
if (above <= 0 && below <= 0) {
|
|
|
|
state.SetComputedHeight(heightOfARow);
|
|
|
|
mNumDisplayRows = 1;
|
2012-11-01 02:00:36 +04:00
|
|
|
mDropdownCanGrow = GetNumberOfRows() > 1;
|
2012-06-23 05:13:56 +04:00
|
|
|
} else {
|
|
|
|
nscoord bp = aReflowState.mComputedBorderPadding.TopBottom();
|
2013-01-15 16:22:03 +04:00
|
|
|
nscoord availableHeight = std::max(above, below) - bp;
|
2012-06-23 05:13:56 +04:00
|
|
|
nscoord newHeight;
|
2012-10-10 09:00:05 +04:00
|
|
|
uint32_t rows;
|
2012-06-23 05:13:56 +04:00
|
|
|
if (visibleHeight <= availableHeight) {
|
|
|
|
// The dropdown fits in the available height.
|
2012-11-01 02:00:36 +04:00
|
|
|
rows = GetNumberOfRows();
|
2012-10-10 09:00:05 +04:00
|
|
|
mNumDisplayRows = clamped<uint32_t>(rows, 1, kMaxDropDownRows);
|
2012-06-23 05:13:56 +04:00
|
|
|
if (mNumDisplayRows == rows) {
|
|
|
|
newHeight = visibleHeight; // use the exact height
|
|
|
|
} else {
|
|
|
|
newHeight = mNumDisplayRows * heightOfARow; // approximate
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
rows = availableHeight / heightOfARow;
|
2012-10-10 09:00:05 +04:00
|
|
|
mNumDisplayRows = clamped<uint32_t>(rows, 1, kMaxDropDownRows);
|
2012-06-23 05:13:56 +04:00
|
|
|
newHeight = mNumDisplayRows * heightOfARow; // approximate
|
|
|
|
}
|
2012-06-23 05:13:56 +04:00
|
|
|
state.SetComputedHeight(newHeight);
|
|
|
|
mDropdownCanGrow = visibleHeight - newHeight >= heightOfARow &&
|
|
|
|
mNumDisplayRows != kMaxDropDownRows;
|
|
|
|
}
|
2000-03-18 17:17:34 +03:00
|
|
|
}
|
2000-03-03 07:28:59 +03:00
|
|
|
|
2007-08-02 22:08:05 +04:00
|
|
|
mLastDropdownComputedHeight = state.ComputedHeight();
|
2000-03-03 07:28:59 +03:00
|
|
|
|
Bug 300030: Move intrinsic width computation out of nsIFrame::Reflow and into its own methods on nsIFrame. Replace reflow reasons, types, and commands with dirty bits/notifications. Thanks to bzbarsky for almost all of the HTML form controls (mozilla/layout/forms) changes, and many others for help testing and patching. For detailed commit logs, see REFLOW_YYYYMMDD_BRANCH, where YYYYMMDD is one of 20061031, 20060830, 20060603, 20060302, 20060119, 20051011, 20050804, 20050429, 20050315, 20050111, and 20041213.
2006-12-08 08:38:33 +03:00
|
|
|
nsHTMLScrollFrame::WillReflow(aPresContext);
|
|
|
|
return nsHTMLScrollFrame::Reflow(aPresContext, aDesiredSize, state, aStatus);
|
1999-01-18 18:14:00 +03:00
|
|
|
}
|
|
|
|
|
2013-08-24 00:20:07 +04:00
|
|
|
ScrollbarStyles
|
2003-05-22 05:46:13 +04:00
|
|
|
nsListControlFrame::GetScrollbarStyles() const
|
|
|
|
{
|
|
|
|
// We can't express this in the style system yet; when we can, this can go away
|
|
|
|
// and GetScrollbarStyles can be devirtualized
|
2012-08-22 19:56:38 +04:00
|
|
|
int32_t verticalStyle = IsInDropDownMode() ? NS_STYLE_OVERFLOW_AUTO
|
2004-05-05 06:32:27 +04:00
|
|
|
: NS_STYLE_OVERFLOW_SCROLL;
|
2013-08-24 00:20:07 +04:00
|
|
|
return ScrollbarStyles(NS_STYLE_OVERFLOW_HIDDEN, verticalStyle);
|
2003-05-22 05:46:13 +04:00
|
|
|
}
|
fixed bugs #6303, #6753, #6756, #6759
Re-wrote nsComboboxFrame.
removed the obsolete nsHTMLAtoms: comboText,comoTextSelected,comTextSelectedFocus,dropDownVisible,
dropdownHidden, dropDownBtnOut, dropDownBtnPressed,
Added nsHTMLAtoms::combobox, nsLayoutAtoms::popupList
Renamed dropDownList to dropDownListPseudo
Added "arrow.gif" as to be used the background-image for the combobox button
ua.css - added rules for select to differentiate between comboboxes and listboxes.
Added style rules to more closely match the XPTOOLKIT XPWidgets look.
removed the following :-moz-combobox-text, -moz-combobox-textselected
nsIFormControlFrame.h - Added SetSuggestedSize method.
nsButtonControlFrame - Implemented SetSuggestedSize.
nsCSSFrameConstructor.cpp - Rewrote ConstructSelectFrame.
nsIWidget.h -Added GetAbsoluteBounds method.
nsWindow.cpp - Implemented GetAbsoluteBounds.
1999-07-15 02:00:24 +04:00
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
bool
|
2007-12-07 03:10:31 +03:00
|
|
|
nsListControlFrame::ShouldPropagateComputedHeightToScrolledContent() const
|
|
|
|
{
|
|
|
|
return !IsInDropDownMode();
|
|
|
|
}
|
|
|
|
|
1999-07-29 01:38:08 +04:00
|
|
|
//---------------------------------------------------------
|
2004-07-18 16:02:53 +04:00
|
|
|
nsIFrame*
|
|
|
|
nsListControlFrame::GetContentInsertionFrame() {
|
2005-10-24 02:11:27 +04:00
|
|
|
return GetOptionsContainer()->GetContentInsertionFrame();
|
2004-07-18 16:02:53 +04:00
|
|
|
}
|
1999-05-14 03:45:40 +04:00
|
|
|
|
1999-08-26 18:54:07 +04:00
|
|
|
//---------------------------------------------------------
|
2011-09-29 10:19:26 +04:00
|
|
|
bool
|
2012-08-22 19:56:38 +04:00
|
|
|
nsListControlFrame::ExtendedSelection(int32_t aStartIndex,
|
|
|
|
int32_t aEndIndex,
|
2011-09-29 10:19:26 +04:00
|
|
|
bool aClearAll)
|
1999-01-18 18:14:00 +03:00
|
|
|
{
|
2002-01-26 02:35:44 +03:00
|
|
|
return SetOptionsSelectedFromFrame(aStartIndex, aEndIndex,
|
2011-10-17 18:59:28 +04:00
|
|
|
true, aClearAll);
|
1999-01-18 18:14:00 +03:00
|
|
|
}
|
|
|
|
|
1999-07-29 01:38:08 +04:00
|
|
|
//---------------------------------------------------------
|
2011-09-29 10:19:26 +04:00
|
|
|
bool
|
2012-08-22 19:56:38 +04:00
|
|
|
nsListControlFrame::SingleSelection(int32_t aClickedIndex, bool aDoToggle)
|
1999-01-18 18:14:00 +03:00
|
|
|
{
|
2004-07-23 12:25:44 +04:00
|
|
|
if (mComboboxFrame) {
|
2006-03-01 04:00:29 +03:00
|
|
|
mComboboxFrame->UpdateRecentIndex(GetSelectedIndex());
|
2004-07-23 12:25:44 +04:00
|
|
|
}
|
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
bool wasChanged = false;
|
2001-11-02 10:40:01 +03:00
|
|
|
// Get Current selection
|
|
|
|
if (aDoToggle) {
|
2002-12-20 08:32:27 +03:00
|
|
|
wasChanged = ToggleOptionSelectedFromFrame(aClickedIndex);
|
1999-01-18 18:14:00 +03:00
|
|
|
} else {
|
2002-12-20 08:32:27 +03:00
|
|
|
wasChanged = SetOptionsSelectedFromFrame(aClickedIndex, aClickedIndex,
|
2011-10-17 18:59:28 +04:00
|
|
|
true, true);
|
1999-01-18 18:14:00 +03:00
|
|
|
}
|
2013-08-09 02:04:59 +04:00
|
|
|
nsWeakFrame weakFrame(this);
|
2002-12-20 08:32:27 +03:00
|
|
|
ScrollToIndex(aClickedIndex);
|
2013-08-09 02:04:59 +04:00
|
|
|
if (!weakFrame.IsAlive()) {
|
|
|
|
return wasChanged;
|
|
|
|
}
|
2011-09-28 05:46:11 +04:00
|
|
|
|
|
|
|
#ifdef ACCESSIBILITY
|
|
|
|
bool isCurrentOptionChanged = mEndSelectionIndex != aClickedIndex;
|
|
|
|
#endif
|
2002-12-20 08:32:27 +03:00
|
|
|
mStartSelectionIndex = aClickedIndex;
|
|
|
|
mEndSelectionIndex = aClickedIndex;
|
2007-09-28 03:06:31 +04:00
|
|
|
InvalidateFocus();
|
2011-09-28 05:46:11 +04:00
|
|
|
|
|
|
|
#ifdef ACCESSIBILITY
|
|
|
|
if (isCurrentOptionChanged) {
|
|
|
|
FireMenuItemActiveEvent();
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2002-01-26 02:35:44 +03:00
|
|
|
return wasChanged;
|
1999-01-18 18:14:00 +03:00
|
|
|
}
|
|
|
|
|
2002-12-20 08:32:27 +03:00
|
|
|
void
|
2012-08-22 19:56:38 +04:00
|
|
|
nsListControlFrame::InitSelectionRange(int32_t aClickedIndex)
|
2002-12-20 08:32:27 +03:00
|
|
|
{
|
|
|
|
//
|
|
|
|
// If nothing is selected, set the start selection depending on where
|
|
|
|
// the user clicked and what the initial selection is:
|
|
|
|
// - if the user clicked *before* selectedIndex, set the start index to
|
|
|
|
// the end of the first contiguous selection.
|
|
|
|
// - if the user clicked *after* the end of the first contiguous
|
|
|
|
// selection, set the start index to selectedIndex.
|
|
|
|
// - if the user clicked *within* the first contiguous selection, set the
|
|
|
|
// start index to selectedIndex.
|
|
|
|
// The last two rules, of course, boil down to the same thing: if the user
|
|
|
|
// clicked >= selectedIndex, return selectedIndex.
|
|
|
|
//
|
|
|
|
// This makes it so that shift click works properly when you first click
|
|
|
|
// in a multiple select.
|
|
|
|
//
|
2012-08-22 19:56:38 +04:00
|
|
|
int32_t selectedIndex = GetSelectedIndex();
|
2002-12-20 08:32:27 +03:00
|
|
|
if (selectedIndex >= 0) {
|
|
|
|
// Get the end of the contiguous selection
|
2013-08-02 11:08:19 +04:00
|
|
|
nsRefPtr<dom::HTMLOptionsCollection> options = GetOptions();
|
2002-12-20 08:32:27 +03:00
|
|
|
NS_ASSERTION(options, "Collection of options is null!");
|
2013-08-02 11:08:19 +04:00
|
|
|
uint32_t numOptions = options->Length();
|
|
|
|
// Push i to one past the last selected index in the group.
|
2012-08-22 19:56:38 +04:00
|
|
|
uint32_t i;
|
2013-08-02 11:08:19 +04:00
|
|
|
for (i = selectedIndex + 1; i < numOptions; i++) {
|
|
|
|
if (!options->ItemAsOption(i)->Selected()) {
|
2002-12-20 08:32:27 +03:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (aClickedIndex < selectedIndex) {
|
|
|
|
// User clicked before selection, so start selection at end of
|
|
|
|
// contiguous selection
|
|
|
|
mStartSelectionIndex = i-1;
|
|
|
|
mEndSelectionIndex = selectedIndex;
|
|
|
|
} else {
|
|
|
|
// User clicked after selection, so start selection at start of
|
|
|
|
// contiguous selection
|
|
|
|
mStartSelectionIndex = selectedIndex;
|
|
|
|
mEndSelectionIndex = i-1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-11-01 02:00:36 +04:00
|
|
|
static uint32_t
|
|
|
|
CountOptionsAndOptgroups(nsIFrame* aFrame)
|
|
|
|
{
|
|
|
|
uint32_t count = 0;
|
|
|
|
nsFrameList::Enumerator e(aFrame->PrincipalChildList());
|
|
|
|
for (; !e.AtEnd(); e.Next()) {
|
|
|
|
nsIFrame* child = e.get();
|
|
|
|
nsIContent* content = child->GetContent();
|
|
|
|
if (content) {
|
|
|
|
if (content->IsHTML(nsGkAtoms::option)) {
|
|
|
|
++count;
|
|
|
|
} else {
|
|
|
|
nsCOMPtr<nsIDOMHTMLOptGroupElement> optgroup = do_QueryInterface(content);
|
|
|
|
if (optgroup) {
|
|
|
|
nsAutoString label;
|
|
|
|
optgroup->GetLabel(label);
|
|
|
|
if (label.Length() > 0) {
|
|
|
|
++count;
|
|
|
|
}
|
|
|
|
count += CountOptionsAndOptgroups(child);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return count;
|
|
|
|
}
|
|
|
|
|
|
|
|
uint32_t
|
|
|
|
nsListControlFrame::GetNumberOfRows()
|
|
|
|
{
|
|
|
|
return ::CountOptionsAndOptgroups(GetContentInsertionFrame());
|
|
|
|
}
|
|
|
|
|
1999-07-29 01:38:08 +04:00
|
|
|
//---------------------------------------------------------
|
2011-09-29 10:19:26 +04:00
|
|
|
bool
|
2012-08-22 19:56:38 +04:00
|
|
|
nsListControlFrame::PerformSelection(int32_t aClickedIndex,
|
2011-09-29 10:19:26 +04:00
|
|
|
bool aIsShift,
|
|
|
|
bool aIsControl)
|
1999-01-18 18:14:00 +03:00
|
|
|
{
|
2011-09-29 10:19:26 +04:00
|
|
|
bool wasChanged = false;
|
2002-01-26 02:35:44 +03:00
|
|
|
|
2002-12-20 08:32:27 +03:00
|
|
|
if (aClickedIndex == kNothingSelected) {
|
2005-12-13 02:53:06 +03:00
|
|
|
}
|
|
|
|
else if (GetMultiple()) {
|
1999-08-27 18:42:27 +04:00
|
|
|
if (aIsShift) {
|
2002-12-20 08:32:27 +03:00
|
|
|
// Make sure shift+click actually does something expected when
|
|
|
|
// the user has never clicked on the select
|
|
|
|
if (mStartSelectionIndex == kNothingSelected) {
|
|
|
|
InitSelectionRange(aClickedIndex);
|
|
|
|
}
|
|
|
|
|
2001-11-02 10:40:01 +03:00
|
|
|
// Get the range from beginning (low) to end (high)
|
|
|
|
// Shift *always* works, even if the current option is disabled
|
2012-08-22 19:56:38 +04:00
|
|
|
int32_t startIndex;
|
|
|
|
int32_t endIndex;
|
2001-11-02 10:40:01 +03:00
|
|
|
if (mStartSelectionIndex == kNothingSelected) {
|
2002-12-20 08:32:27 +03:00
|
|
|
startIndex = aClickedIndex;
|
|
|
|
endIndex = aClickedIndex;
|
|
|
|
} else if (mStartSelectionIndex <= aClickedIndex) {
|
2001-11-02 10:40:01 +03:00
|
|
|
startIndex = mStartSelectionIndex;
|
2002-12-20 08:32:27 +03:00
|
|
|
endIndex = aClickedIndex;
|
1999-08-26 18:54:07 +04:00
|
|
|
} else {
|
2002-12-20 08:32:27 +03:00
|
|
|
startIndex = aClickedIndex;
|
2001-11-02 10:40:01 +03:00
|
|
|
endIndex = mStartSelectionIndex;
|
1999-08-26 18:54:07 +04:00
|
|
|
}
|
2001-06-06 14:41:17 +04:00
|
|
|
|
2003-11-15 07:23:53 +03:00
|
|
|
// Clear only if control was not pressed
|
|
|
|
wasChanged = ExtendedSelection(startIndex, endIndex, !aIsControl);
|
2013-08-09 02:04:59 +04:00
|
|
|
nsWeakFrame weakFrame(this);
|
2002-12-20 08:32:27 +03:00
|
|
|
ScrollToIndex(aClickedIndex);
|
2013-08-09 02:04:59 +04:00
|
|
|
if (!weakFrame.IsAlive()) {
|
|
|
|
return wasChanged;
|
|
|
|
}
|
2001-11-02 10:40:01 +03:00
|
|
|
|
|
|
|
if (mStartSelectionIndex == kNothingSelected) {
|
2002-12-20 08:32:27 +03:00
|
|
|
mStartSelectionIndex = aClickedIndex;
|
1999-01-18 18:14:00 +03:00
|
|
|
}
|
2011-09-28 05:46:11 +04:00
|
|
|
#ifdef ACCESSIBILITY
|
|
|
|
bool isCurrentOptionChanged = mEndSelectionIndex != aClickedIndex;
|
|
|
|
#endif
|
|
|
|
mEndSelectionIndex = aClickedIndex;
|
2007-09-28 03:06:31 +04:00
|
|
|
InvalidateFocus();
|
2011-09-28 05:46:11 +04:00
|
|
|
|
|
|
|
#ifdef ACCESSIBILITY
|
|
|
|
if (isCurrentOptionChanged) {
|
|
|
|
FireMenuItemActiveEvent();
|
|
|
|
}
|
|
|
|
#endif
|
2001-11-02 10:40:01 +03:00
|
|
|
} else if (aIsControl) {
|
2013-08-09 02:04:59 +04:00
|
|
|
wasChanged = SingleSelection(aClickedIndex, true); // might destroy us
|
1999-08-26 18:54:07 +04:00
|
|
|
} else {
|
2013-08-09 02:04:59 +04:00
|
|
|
wasChanged = SingleSelection(aClickedIndex, false); // might destroy us
|
1999-08-26 18:54:07 +04:00
|
|
|
}
|
2001-11-02 10:40:01 +03:00
|
|
|
} else {
|
2013-08-09 02:04:59 +04:00
|
|
|
wasChanged = SingleSelection(aClickedIndex, false); // might destroy us
|
1999-08-26 18:54:07 +04:00
|
|
|
}
|
2001-11-02 10:40:01 +03:00
|
|
|
|
2002-01-26 02:35:44 +03:00
|
|
|
return wasChanged;
|
1999-05-08 00:30:16 +04:00
|
|
|
}
|
|
|
|
|
1999-07-29 01:38:08 +04:00
|
|
|
//---------------------------------------------------------
|
2011-09-29 10:19:26 +04:00
|
|
|
bool
|
2001-11-02 10:40:01 +03:00
|
|
|
nsListControlFrame::HandleListSelection(nsIDOMEvent* aEvent,
|
2012-08-22 19:56:38 +04:00
|
|
|
int32_t aClickedIndex)
|
1999-05-29 01:12:09 +04:00
|
|
|
{
|
2001-11-02 10:40:01 +03:00
|
|
|
nsCOMPtr<nsIDOMMouseEvent> mouseEvent = do_QueryInterface(aEvent);
|
2011-09-29 10:19:26 +04:00
|
|
|
bool isShift;
|
|
|
|
bool isControl;
|
2007-02-15 00:00:15 +03:00
|
|
|
#ifdef XP_MACOSX
|
2001-11-02 10:40:01 +03:00
|
|
|
mouseEvent->GetMetaKey(&isControl);
|
2000-01-13 19:01:04 +03:00
|
|
|
#else
|
2001-11-02 10:40:01 +03:00
|
|
|
mouseEvent->GetCtrlKey(&isControl);
|
2000-01-13 19:01:04 +03:00
|
|
|
#endif
|
2001-11-02 10:40:01 +03:00
|
|
|
mouseEvent->GetShiftKey(&isShift);
|
2013-08-09 02:04:59 +04:00
|
|
|
return PerformSelection(aClickedIndex, isShift, isControl); // might destroy us
|
1999-05-29 01:12:09 +04:00
|
|
|
}
|
|
|
|
|
1999-07-29 01:38:08 +04:00
|
|
|
//---------------------------------------------------------
|
2006-03-01 04:00:29 +03:00
|
|
|
void
|
2011-09-29 10:19:26 +04:00
|
|
|
nsListControlFrame::CaptureMouseEvents(bool aGrabMouseEvents)
|
1999-04-16 23:28:12 +04:00
|
|
|
{
|
2005-02-16 08:13:16 +03:00
|
|
|
// Currently cocoa widgets use a native popup widget which tracks clicks synchronously,
|
|
|
|
// so we never want to do mouse capturing. Note that we only bail if the list
|
|
|
|
// is in drop-down mode, and the caller is requesting capture (we let release capture
|
|
|
|
// requests go through to ensure that we can release capture requested via other
|
|
|
|
// code paths, if any exist).
|
|
|
|
if (aGrabMouseEvents && IsInDropDownMode() && nsComboboxControlFrame::ToolkitHasNativePopup())
|
2006-03-01 04:00:29 +03:00
|
|
|
return;
|
2003-04-09 00:50:57 +04:00
|
|
|
|
2009-09-13 17:13:16 +04:00
|
|
|
if (aGrabMouseEvents) {
|
|
|
|
nsIPresShell::SetCapturingContent(mContent, CAPTURE_IGNOREALLOWED);
|
|
|
|
} else {
|
|
|
|
nsIContent* capturingContent = nsIPresShell::GetCapturingContent();
|
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
bool dropDownIsHidden = false;
|
2009-09-13 17:13:16 +04:00
|
|
|
if (IsInDropDownMode()) {
|
|
|
|
dropDownIsHidden = !mComboboxFrame->IsDroppedDown();
|
|
|
|
}
|
|
|
|
if (capturingContent == mContent || dropDownIsHidden) {
|
|
|
|
// only clear the capturing content if *we* are the ones doing the
|
|
|
|
// capturing (or if the dropdown is hidden, in which case NO-ONE should
|
|
|
|
// be capturing anything - it could be a scrollbar inside this listbox
|
|
|
|
// which is actually grabbing
|
|
|
|
// This shouldn't be necessary. We should simply ensure that events targeting
|
|
|
|
// scrollbars are never visible to DOM consumers.
|
2012-07-30 18:20:58 +04:00
|
|
|
nsIPresShell::SetCapturingContent(nullptr, 0);
|
1999-04-16 23:28:12 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
1999-07-29 01:38:08 +04:00
|
|
|
//---------------------------------------------------------
|
fixed bugs #6303, #6753, #6756, #6759
Re-wrote nsComboboxFrame.
removed the obsolete nsHTMLAtoms: comboText,comoTextSelected,comTextSelectedFocus,dropDownVisible,
dropdownHidden, dropDownBtnOut, dropDownBtnPressed,
Added nsHTMLAtoms::combobox, nsLayoutAtoms::popupList
Renamed dropDownList to dropDownListPseudo
Added "arrow.gif" as to be used the background-image for the combobox button
ua.css - added rules for select to differentiate between comboboxes and listboxes.
Added style rules to more closely match the XPTOOLKIT XPWidgets look.
removed the following :-moz-combobox-text, -moz-combobox-textselected
nsIFormControlFrame.h - Added SetSuggestedSize method.
nsButtonControlFrame - Implemented SetSuggestedSize.
nsCSSFrameConstructor.cpp - Rewrote ConstructSelectFrame.
nsIWidget.h -Added GetAbsoluteBounds method.
nsWindow.cpp - Implemented GetAbsoluteBounds.
1999-07-15 02:00:24 +04:00
|
|
|
NS_IMETHODIMP
|
2013-10-02 07:46:03 +04:00
|
|
|
nsListControlFrame::HandleEvent(nsPresContext* aPresContext,
|
|
|
|
WidgetGUIEvent* aEvent,
|
2005-10-15 08:08:04 +04:00
|
|
|
nsEventStatus* aEventStatus)
|
1999-01-18 18:14:00 +03:00
|
|
|
{
|
1999-11-24 09:03:41 +03:00
|
|
|
NS_ENSURE_ARG_POINTER(aEventStatus);
|
1999-07-29 01:38:08 +04:00
|
|
|
|
|
|
|
/*const char * desc[] = {"NS_MOUSE_MOVE",
|
1999-01-18 18:14:00 +03:00
|
|
|
"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",
|
2000-04-24 08:41:27 +04:00
|
|
|
"NS_MOUSE_ENTER_SYNTH",
|
|
|
|
"NS_MOUSE_EXIT_SYNTH",
|
1999-01-18 18:14:00 +03:00
|
|
|
"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)) {
|
2000-10-29 02:17:53 +04:00
|
|
|
printf("Mouse in ListFrame %s [%d]\n", desc[inx], aEvent->message);
|
1999-01-18 18:14:00 +03:00
|
|
|
} else {
|
2000-10-29 02:17:53 +04:00
|
|
|
printf("Mouse in ListFrame <UNKNOWN> [%d]\n", aEvent->message);
|
1999-07-29 01:38:08 +04:00
|
|
|
}*/
|
|
|
|
|
1999-11-24 09:03:41 +03:00
|
|
|
if (nsEventStatus_eConsumeNoDefault == *aEventStatus)
|
1999-01-18 18:14:00 +03:00
|
|
|
return NS_OK;
|
|
|
|
|
2000-08-09 03:38:00 +04:00
|
|
|
// do we have style that affects how we are selected?
|
|
|
|
// do we have user-input style?
|
2013-02-17 01:51:02 +04:00
|
|
|
const nsStyleUserInterface* uiStyle = StyleUserInterface();
|
2000-08-09 03:38:00 +04:00
|
|
|
if (uiStyle->mUserInput == NS_STYLE_USER_INPUT_NONE || uiStyle->mUserInput == NS_STYLE_USER_INPUT_DISABLED)
|
|
|
|
return nsFrame::HandleEvent(aPresContext, aEvent, aEventStatus);
|
|
|
|
|
2011-06-01 05:46:57 +04:00
|
|
|
nsEventStates eventStates = mContent->AsElement()->State();
|
2010-10-20 15:26:32 +04:00
|
|
|
if (eventStates.HasState(NS_EVENT_STATE_DISABLED))
|
1999-08-10 23:22:51 +04:00
|
|
|
return NS_OK;
|
|
|
|
|
2004-06-18 06:08:19 +04:00
|
|
|
return nsHTMLScrollFrame::HandleEvent(aPresContext, aEvent, aEventStatus);
|
1999-01-18 18:14:00 +03:00
|
|
|
}
|
|
|
|
|
fixed bugs #6303, #6753, #6756, #6759
Re-wrote nsComboboxFrame.
removed the obsolete nsHTMLAtoms: comboText,comoTextSelected,comTextSelectedFocus,dropDownVisible,
dropdownHidden, dropDownBtnOut, dropDownBtnPressed,
Added nsHTMLAtoms::combobox, nsLayoutAtoms::popupList
Renamed dropDownList to dropDownListPseudo
Added "arrow.gif" as to be used the background-image for the combobox button
ua.css - added rules for select to differentiate between comboboxes and listboxes.
Added style rules to more closely match the XPTOOLKIT XPWidgets look.
removed the following :-moz-combobox-text, -moz-combobox-textselected
nsIFormControlFrame.h - Added SetSuggestedSize method.
nsButtonControlFrame - Implemented SetSuggestedSize.
nsCSSFrameConstructor.cpp - Rewrote ConstructSelectFrame.
nsIWidget.h -Added GetAbsoluteBounds method.
nsWindow.cpp - Implemented GetAbsoluteBounds.
1999-07-15 02:00:24 +04:00
|
|
|
|
1999-07-29 01:38:08 +04:00
|
|
|
//---------------------------------------------------------
|
1999-01-18 18:14:00 +03:00
|
|
|
NS_IMETHODIMP
|
2011-08-25 00:54:30 +04:00
|
|
|
nsListControlFrame::SetInitialChildList(ChildListID aListID,
|
2009-07-28 16:53:20 +04:00
|
|
|
nsFrameList& aChildList)
|
1999-01-18 18:14:00 +03:00
|
|
|
{
|
1999-11-12 01:13:33 +03:00
|
|
|
// First check to see if all the content has been added
|
2004-06-02 04:25:00 +04:00
|
|
|
mIsAllContentHere = mContent->IsDoneAddingChildren();
|
|
|
|
if (!mIsAllContentHere) {
|
2011-10-17 18:59:28 +04:00
|
|
|
mIsAllFramesHere = false;
|
|
|
|
mHasBeenInitialized = false;
|
1999-11-12 01:13:33 +03:00
|
|
|
}
|
2011-08-25 00:54:30 +04:00
|
|
|
nsresult rv = nsHTMLScrollFrame::SetInitialChildList(aListID, aChildList);
|
1999-11-12 01:13:33 +03:00
|
|
|
|
|
|
|
// If all the content is here now check
|
|
|
|
// to see if all the frames have been created
|
1999-11-19 18:46:20 +03:00
|
|
|
/*if (mIsAllContentHere) {
|
1999-11-12 01:13:33 +03:00
|
|
|
// If all content and frames are here
|
|
|
|
// the reset/initialize
|
|
|
|
if (CheckIfAllFramesHere()) {
|
2001-06-08 06:34:09 +04:00
|
|
|
ResetList(aPresContext);
|
2011-10-17 18:59:28 +04:00
|
|
|
mHasBeenInitialized = true;
|
1999-11-12 01:13:33 +03:00
|
|
|
}
|
1999-11-19 18:46:20 +03:00
|
|
|
}*/
|
1999-11-12 01:13:33 +03:00
|
|
|
|
|
|
|
return rv;
|
1999-01-18 18:14:00 +03:00
|
|
|
}
|
|
|
|
|
1999-07-29 01:38:08 +04:00
|
|
|
//---------------------------------------------------------
|
2013-03-20 05:47:48 +04:00
|
|
|
void
|
2006-03-09 21:55:21 +03:00
|
|
|
nsListControlFrame::Init(nsIContent* aContent,
|
2005-10-15 08:08:04 +04:00
|
|
|
nsIFrame* aParent,
|
|
|
|
nsIFrame* aPrevInFlow)
|
1999-01-18 18:14:00 +03:00
|
|
|
{
|
2013-03-20 05:47:48 +04:00
|
|
|
nsHTMLScrollFrame::Init(aContent, aParent, aPrevInFlow);
|
1999-08-26 18:54:07 +04:00
|
|
|
|
|
|
|
// we shouldn't have to unregister this listener because when
|
|
|
|
// our frame goes away all these content node go away as well
|
|
|
|
// because our frame is the only one who references them.
|
2000-08-14 18:42:12 +04:00
|
|
|
// we need to hook up our listeners before the editor is initialized
|
2004-01-10 01:18:26 +03:00
|
|
|
mEventListener = new nsListEventListener(this);
|
2000-08-14 18:42:12 +04:00
|
|
|
|
2013-07-25 10:09:29 +04:00
|
|
|
mContent->AddSystemEventListener(NS_LITERAL_STRING("keydown"),
|
|
|
|
mEventListener, false, false);
|
2013-07-19 18:32:51 +04:00
|
|
|
mContent->AddSystemEventListener(NS_LITERAL_STRING("keypress"),
|
|
|
|
mEventListener, false, false);
|
|
|
|
mContent->AddSystemEventListener(NS_LITERAL_STRING("mousedown"),
|
|
|
|
mEventListener, false, false);
|
|
|
|
mContent->AddSystemEventListener(NS_LITERAL_STRING("mouseup"),
|
|
|
|
mEventListener, false, false);
|
|
|
|
mContent->AddSystemEventListener(NS_LITERAL_STRING("mousemove"),
|
|
|
|
mEventListener, false, false);
|
1999-09-11 02:56:23 +04:00
|
|
|
|
2001-11-02 10:40:01 +03:00
|
|
|
mStartSelectionIndex = kNothingSelected;
|
|
|
|
mEndSelectionIndex = kNothingSelected;
|
|
|
|
|
2009-09-02 06:46:47 +04:00
|
|
|
mLastDropdownBackstopColor = PresContext()->DefaultBackgroundColor();
|
|
|
|
|
2013-02-22 11:38:06 +04:00
|
|
|
if (IsInDropDownMode()) {
|
|
|
|
AddStateBits(NS_FRAME_IN_POPUP);
|
|
|
|
}
|
1999-01-18 18:14:00 +03:00
|
|
|
}
|
|
|
|
|
2013-08-02 11:08:19 +04:00
|
|
|
dom::HTMLOptionsCollection*
|
|
|
|
nsListControlFrame::GetOptions() const
|
1999-01-18 18:14:00 +03:00
|
|
|
{
|
2013-08-02 11:08:19 +04:00
|
|
|
dom::HTMLSelectElement* select =
|
|
|
|
dom::HTMLSelectElement::FromContentOrNull(mContent);
|
|
|
|
NS_ENSURE_TRUE(select, nullptr);
|
Landing the XPCDOM_20010329_BRANCH branch, changes mostly done by jband@netscape.com and jst@netscape.com, also some changes done by shaver@mozilla.org, peterv@netscape.com and markh@activestate.com. r= and sr= by vidur@netscape.com, jband@netscape.com, jst@netscpae.com, danm@netscape.com, hyatt@netscape.com, shaver@mozilla.org, dbradley@netscape.com, rpotts@netscape.com.
2001-05-08 21:42:36 +04:00
|
|
|
|
2013-08-02 11:08:19 +04:00
|
|
|
return select->Options();
|
1999-01-18 18:14:00 +03:00
|
|
|
}
|
|
|
|
|
2013-08-02 11:07:04 +04:00
|
|
|
dom::HTMLOptionElement*
|
|
|
|
nsListControlFrame::GetOption(uint32_t aIndex) const
|
|
|
|
{
|
|
|
|
dom::HTMLSelectElement* select =
|
|
|
|
dom::HTMLSelectElement::FromContentOrNull(mContent);
|
|
|
|
NS_ENSURE_TRUE(select, nullptr);
|
|
|
|
|
|
|
|
return select->Item(aIndex);
|
|
|
|
}
|
|
|
|
|
2001-11-02 10:40:01 +03:00
|
|
|
NS_IMETHODIMP
|
2012-08-22 19:56:38 +04:00
|
|
|
nsListControlFrame::OnOptionSelected(int32_t aIndex, bool aSelected)
|
1999-01-18 18:14:00 +03:00
|
|
|
{
|
2001-11-02 10:40:01 +03:00
|
|
|
if (aSelected) {
|
|
|
|
ScrollToIndex(aIndex);
|
2001-06-08 06:34:09 +04:00
|
|
|
}
|
1999-01-18 18:14:00 +03:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2005-12-13 02:53:06 +03:00
|
|
|
void
|
2001-11-02 10:40:01 +03:00
|
|
|
nsListControlFrame::OnContentReset()
|
1999-01-18 18:14:00 +03:00
|
|
|
{
|
2011-10-17 18:59:28 +04:00
|
|
|
ResetList(true);
|
1999-01-18 18:14:00 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2012-05-21 09:18:28 +04:00
|
|
|
nsListControlFrame::ResetList(bool aAllowScrolling)
|
1999-01-18 18:14:00 +03:00
|
|
|
{
|
1999-11-12 01:13:33 +03:00
|
|
|
// if all the frames aren't here
|
|
|
|
// don't bother reseting
|
|
|
|
if (!mIsAllFramesHere) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2004-09-13 06:10:29 +04:00
|
|
|
if (aAllowScrolling) {
|
2011-10-17 18:59:28 +04:00
|
|
|
mPostChildrenLoadedReset = true;
|
2001-06-08 06:34:09 +04:00
|
|
|
|
2004-09-13 06:10:29 +04:00
|
|
|
// Scroll to the selected index
|
2012-08-22 19:56:38 +04:00
|
|
|
int32_t indexToSelect = kNothingSelected;
|
2004-09-13 06:10:29 +04:00
|
|
|
|
|
|
|
nsCOMPtr<nsIDOMHTMLSelectElement> selectElement(do_QueryInterface(mContent));
|
|
|
|
NS_ASSERTION(selectElement, "No select element!");
|
|
|
|
if (selectElement) {
|
|
|
|
selectElement->GetSelectedIndex(&indexToSelect);
|
2013-08-09 02:04:59 +04:00
|
|
|
nsWeakFrame weakFrame(this);
|
2004-09-13 06:10:29 +04:00
|
|
|
ScrollToIndex(indexToSelect);
|
2013-08-09 02:04:59 +04:00
|
|
|
if (!weakFrame.IsAlive()) {
|
|
|
|
return;
|
|
|
|
}
|
2004-09-13 06:10:29 +04:00
|
|
|
}
|
1999-01-18 18:14:00 +03:00
|
|
|
}
|
1999-10-06 03:43:06 +04:00
|
|
|
|
2001-11-02 10:40:01 +03:00
|
|
|
mStartSelectionIndex = kNothingSelected;
|
|
|
|
mEndSelectionIndex = kNothingSelected;
|
2012-05-21 09:18:28 +04:00
|
|
|
InvalidateFocus();
|
2002-01-26 02:35:44 +03:00
|
|
|
// Combobox will redisplay itself with the OnOptionSelected event
|
1999-01-18 18:14:00 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2011-09-29 10:19:26 +04:00
|
|
|
nsListControlFrame::SetFocus(bool aOn, bool aRepaint)
|
1999-01-18 18:14:00 +03:00
|
|
|
{
|
2007-09-28 03:06:31 +04:00
|
|
|
InvalidateFocus();
|
|
|
|
|
2002-04-11 04:53:20 +04:00
|
|
|
if (aOn) {
|
2002-11-07 13:25:03 +03:00
|
|
|
ComboboxFocusSet();
|
2002-04-11 04:53:20 +04:00
|
|
|
mFocused = this;
|
|
|
|
} else {
|
2012-07-30 18:20:58 +04:00
|
|
|
mFocused = nullptr;
|
2002-04-11 04:53:20 +04:00
|
|
|
}
|
|
|
|
|
2007-09-28 03:06:31 +04:00
|
|
|
InvalidateFocus();
|
2002-11-07 13:25:03 +03:00
|
|
|
}
|
2002-04-11 04:53:20 +04:00
|
|
|
|
2002-11-07 13:25:03 +03:00
|
|
|
void nsListControlFrame::ComboboxFocusSet()
|
|
|
|
{
|
|
|
|
gLastKeyTime = 0;
|
1999-01-18 18:14:00 +03:00
|
|
|
}
|
|
|
|
|
2006-03-01 04:00:29 +03:00
|
|
|
void
|
1999-01-18 18:14:00 +03:00
|
|
|
nsListControlFrame::SetComboboxFrame(nsIFrame* aComboboxFrame)
|
|
|
|
{
|
2012-07-30 18:20:58 +04:00
|
|
|
if (nullptr != aComboboxFrame) {
|
2009-01-12 22:20:59 +03:00
|
|
|
mComboboxFrame = do_QueryFrame(aComboboxFrame);
|
1999-01-18 18:14:00 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-03-01 04:00:29 +03:00
|
|
|
void
|
2013-08-02 11:07:08 +04:00
|
|
|
nsListControlFrame::GetOptionText(uint32_t aIndex, nsAString& aStr)
|
1999-01-18 18:14:00 +03:00
|
|
|
{
|
2013-08-02 11:07:08 +04:00
|
|
|
aStr.Truncate();
|
|
|
|
if (dom::HTMLOptionElement* optionElement = GetOption(aIndex)) {
|
|
|
|
optionElement->GetText(aStr);
|
1999-05-28 01:17:10 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-08-22 19:56:38 +04:00
|
|
|
int32_t
|
2006-03-01 04:00:29 +03:00
|
|
|
nsListControlFrame::GetSelectedIndex()
|
1999-08-19 18:11:28 +04:00
|
|
|
{
|
2013-08-02 11:09:05 +04:00
|
|
|
dom::HTMLSelectElement* select =
|
|
|
|
dom::HTMLSelectElement::FromContentOrNull(mContent);
|
|
|
|
return select->SelectedIndex();
|
1999-08-26 18:54:07 +04:00
|
|
|
}
|
|
|
|
|
2013-08-02 11:07:22 +04:00
|
|
|
dom::HTMLOptionElement*
|
2011-09-28 05:46:11 +04:00
|
|
|
nsListControlFrame::GetCurrentOption()
|
|
|
|
{
|
|
|
|
// The mEndSelectionIndex is what is currently being selected. Use
|
|
|
|
// the selected index if this is kNothingSelected.
|
2012-08-22 19:56:38 +04:00
|
|
|
int32_t focusedIndex = (mEndSelectionIndex == kNothingSelected) ?
|
2011-09-28 05:46:11 +04:00
|
|
|
GetSelectedIndex() : mEndSelectionIndex;
|
|
|
|
|
|
|
|
if (focusedIndex != kNothingSelected) {
|
2013-08-02 11:07:22 +04:00
|
|
|
return GetOption(SafeCast<uint32_t>(focusedIndex));
|
2011-09-28 05:46:11 +04:00
|
|
|
}
|
|
|
|
|
2013-08-02 11:07:22 +04:00
|
|
|
// There is no selected item. Return the first non-disabled item.
|
2013-04-04 11:03:33 +04:00
|
|
|
nsRefPtr<dom::HTMLSelectElement> selectElement =
|
|
|
|
dom::HTMLSelectElement::FromContent(mContent);
|
2011-09-28 05:46:11 +04:00
|
|
|
|
2013-08-02 11:07:22 +04:00
|
|
|
for (uint32_t i = 0, length = selectElement->Length(); i < length; ++i) {
|
|
|
|
dom::HTMLOptionElement* node = selectElement->Item(i);
|
2011-09-28 05:46:11 +04:00
|
|
|
if (!node) {
|
2012-07-30 18:20:58 +04:00
|
|
|
return nullptr;
|
2011-09-28 05:46:11 +04:00
|
|
|
}
|
|
|
|
|
2013-08-02 11:07:22 +04:00
|
|
|
if (!selectElement->IsOptionDisabled(node)) {
|
|
|
|
return node;
|
|
|
|
}
|
2011-09-28 05:46:11 +04:00
|
|
|
}
|
2013-08-02 11:07:22 +04:00
|
|
|
|
2012-07-30 18:20:58 +04:00
|
|
|
return nullptr;
|
2011-09-28 05:46:11 +04:00
|
|
|
}
|
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
bool
|
2003-05-22 05:46:13 +04:00
|
|
|
nsListControlFrame::IsInDropDownMode() const
|
1999-05-28 01:17:10 +04:00
|
|
|
{
|
2012-07-30 18:20:58 +04:00
|
|
|
return (mComboboxFrame != nullptr);
|
1999-01-18 18:14:00 +03:00
|
|
|
}
|
|
|
|
|
2012-10-10 09:00:05 +04:00
|
|
|
uint32_t
|
Bug 300030: Move intrinsic width computation out of nsIFrame::Reflow and into its own methods on nsIFrame. Replace reflow reasons, types, and commands with dirty bits/notifications. Thanks to bzbarsky for almost all of the HTML form controls (mozilla/layout/forms) changes, and many others for help testing and patching. For detailed commit logs, see REFLOW_YYYYMMDD_BRANCH, where YYYYMMDD is one of 20061031, 20060830, 20060603, 20060302, 20060119, 20051011, 20050804, 20050429, 20050315, 20050111, and 20041213.
2006-12-08 08:38:33 +03:00
|
|
|
nsListControlFrame::GetNumberOfOptions()
|
1999-04-13 02:14:31 +04:00
|
|
|
{
|
2013-08-02 11:08:19 +04:00
|
|
|
dom::HTMLOptionsCollection* options = GetOptions();
|
2012-10-10 09:00:05 +04:00
|
|
|
if (!options) {
|
|
|
|
return 0;
|
1999-04-13 02:14:31 +04:00
|
|
|
}
|
2012-10-10 09:00:05 +04:00
|
|
|
|
2013-08-02 11:08:19 +04:00
|
|
|
return options->Length();
|
1999-04-13 02:14:31 +04:00
|
|
|
}
|
|
|
|
|
1999-08-26 18:54:07 +04:00
|
|
|
//----------------------------------------------------------------------
|
|
|
|
// nsISelectControlFrame
|
|
|
|
//----------------------------------------------------------------------
|
2011-09-29 10:19:26 +04:00
|
|
|
bool nsListControlFrame::CheckIfAllFramesHere()
|
1999-11-12 01:13:33 +03:00
|
|
|
{
|
|
|
|
// Get the number of optgroups and options
|
2012-08-22 19:56:38 +04:00
|
|
|
//int32_t numContentItems = 0;
|
1999-11-12 01:13:33 +03:00
|
|
|
nsCOMPtr<nsIDOMNode> node(do_QueryInterface(mContent));
|
|
|
|
if (node) {
|
1999-12-08 03:08:41 +03:00
|
|
|
// XXX Need to find a fail proff way to determine that
|
|
|
|
// all the frames are there
|
2011-10-17 18:59:28 +04:00
|
|
|
mIsAllFramesHere = true;//NS_OK == CountAllChild(node, numContentItems);
|
1999-11-12 01:13:33 +03:00
|
|
|
}
|
|
|
|
// now make sure we have a frame each piece of content
|
|
|
|
|
|
|
|
return mIsAllFramesHere;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2011-09-29 10:19:26 +04:00
|
|
|
nsListControlFrame::DoneAddingChildren(bool aIsDone)
|
1999-11-12 01:13:33 +03:00
|
|
|
{
|
1999-11-19 18:46:20 +03:00
|
|
|
mIsAllContentHere = aIsDone;
|
|
|
|
if (mIsAllContentHere) {
|
|
|
|
// Here we check to see if all the frames have been created
|
|
|
|
// for all the content.
|
|
|
|
// If so, then we can initialize;
|
2010-02-07 18:52:43 +03:00
|
|
|
if (!mIsAllFramesHere) {
|
2005-11-21 01:05:24 +03:00
|
|
|
// if all the frames are now present we can initialize
|
2004-08-11 08:49:05 +04:00
|
|
|
if (CheckIfAllFramesHere()) {
|
2011-10-17 18:59:28 +04:00
|
|
|
mHasBeenInitialized = true;
|
|
|
|
ResetList(true);
|
1999-11-19 18:46:20 +03:00
|
|
|
}
|
1999-11-12 01:13:33 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
1999-08-26 18:54:07 +04:00
|
|
|
NS_IMETHODIMP
|
2012-08-22 19:56:38 +04:00
|
|
|
nsListControlFrame::AddOption(int32_t aIndex)
|
1999-08-26 18:54:07 +04:00
|
|
|
{
|
2000-03-03 07:28:59 +03:00
|
|
|
#ifdef DO_REFLOW_DEBUG
|
2000-10-29 02:17:53 +04:00
|
|
|
printf("---- Id: %d nsLCF %p Added Option %d\n", mReflowId, this, aIndex);
|
2000-03-03 07:28:59 +03:00
|
|
|
#endif
|
|
|
|
|
1999-11-12 01:13:33 +03:00
|
|
|
if (!mIsAllContentHere) {
|
2004-06-02 04:25:00 +04:00
|
|
|
mIsAllContentHere = mContent->IsDoneAddingChildren();
|
|
|
|
if (!mIsAllContentHere) {
|
2011-10-17 18:59:28 +04:00
|
|
|
mIsAllFramesHere = false;
|
|
|
|
mHasBeenInitialized = false;
|
2004-06-02 04:25:00 +04:00
|
|
|
} else {
|
2012-10-10 09:00:05 +04:00
|
|
|
mIsAllFramesHere = (aIndex == static_cast<int32_t>(GetNumberOfOptions()-1));
|
1999-11-12 01:13:33 +03:00
|
|
|
}
|
|
|
|
}
|
2012-10-10 09:00:05 +04:00
|
|
|
|
2009-08-24 22:17:56 +04:00
|
|
|
// Make sure we scroll to the selected option as needed
|
2011-10-17 18:59:28 +04:00
|
|
|
mNeedToReset = true;
|
2009-08-24 22:17:56 +04:00
|
|
|
|
1999-11-12 01:13:33 +03:00
|
|
|
if (!mHasBeenInitialized) {
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2004-09-13 06:10:29 +04:00
|
|
|
mPostChildrenLoadedReset = mIsAllContentHere;
|
1999-08-26 18:54:07 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2012-08-22 19:56:38 +04:00
|
|
|
static int32_t
|
|
|
|
DecrementAndClamp(int32_t aSelectionIndex, int32_t aLength)
|
2010-06-28 00:53:47 +04:00
|
|
|
{
|
2013-01-15 16:22:03 +04:00
|
|
|
return aLength == 0 ? kNothingSelected : std::max(0, aSelectionIndex - 1);
|
2010-06-28 00:53:47 +04:00
|
|
|
}
|
|
|
|
|
1999-08-26 18:54:07 +04:00
|
|
|
NS_IMETHODIMP
|
2012-08-22 19:56:38 +04:00
|
|
|
nsListControlFrame::RemoveOption(int32_t aIndex)
|
1999-08-26 18:54:07 +04:00
|
|
|
{
|
2010-06-28 00:53:47 +04:00
|
|
|
NS_PRECONDITION(aIndex >= 0, "negative <option> index");
|
|
|
|
|
2004-08-11 08:49:05 +04:00
|
|
|
// Need to reset if we're a dropdown
|
|
|
|
if (IsInDropDownMode()) {
|
2011-10-17 18:59:28 +04:00
|
|
|
mNeedToReset = true;
|
2004-09-13 06:10:29 +04:00
|
|
|
mPostChildrenLoadedReset = mIsAllContentHere;
|
2001-06-08 06:34:09 +04:00
|
|
|
}
|
1999-08-26 18:54:07 +04:00
|
|
|
|
2010-06-28 00:53:47 +04:00
|
|
|
if (mStartSelectionIndex != kNothingSelected) {
|
|
|
|
NS_ASSERTION(mEndSelectionIndex != kNothingSelected, "");
|
2012-08-22 19:56:38 +04:00
|
|
|
int32_t numOptions = GetNumberOfOptions();
|
2010-06-28 00:53:47 +04:00
|
|
|
// NOTE: numOptions is the new number of options whereas aIndex is the
|
|
|
|
// unadjusted index of the removed option (hence the <= below).
|
|
|
|
NS_ASSERTION(aIndex <= numOptions, "out-of-bounds <option> index");
|
|
|
|
|
2012-08-22 19:56:38 +04:00
|
|
|
int32_t forward = mEndSelectionIndex - mStartSelectionIndex;
|
|
|
|
int32_t* low = forward >= 0 ? &mStartSelectionIndex : &mEndSelectionIndex;
|
|
|
|
int32_t* high = forward >= 0 ? &mEndSelectionIndex : &mStartSelectionIndex;
|
2010-06-28 00:53:47 +04:00
|
|
|
if (aIndex < *low)
|
|
|
|
*low = ::DecrementAndClamp(*low, numOptions);
|
|
|
|
if (aIndex <= *high)
|
|
|
|
*high = ::DecrementAndClamp(*high, numOptions);
|
|
|
|
if (forward == 0)
|
|
|
|
*low = *high;
|
2006-04-20 06:37:31 +04:00
|
|
|
}
|
2010-06-28 00:53:47 +04:00
|
|
|
else
|
|
|
|
NS_ASSERTION(mEndSelectionIndex == kNothingSelected, "");
|
2006-04-20 06:37:31 +04:00
|
|
|
|
2007-09-28 03:06:31 +04:00
|
|
|
InvalidateFocus();
|
1999-08-26 18:54:07 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
1999-08-27 07:58:13 +04:00
|
|
|
|
|
|
|
//---------------------------------------------------------
|
2001-11-02 10:40:01 +03:00
|
|
|
// Set the option selected in the DOM. This method is named
|
|
|
|
// as it is because it indicates that the frame is the source
|
|
|
|
// of this event rather than the receiver.
|
2011-09-29 10:19:26 +04:00
|
|
|
bool
|
2012-08-22 19:56:38 +04:00
|
|
|
nsListControlFrame::SetOptionsSelectedFromFrame(int32_t aStartIndex,
|
|
|
|
int32_t aEndIndex,
|
2011-09-29 10:19:26 +04:00
|
|
|
bool aValue,
|
|
|
|
bool aClearAll)
|
2001-11-02 10:40:01 +03:00
|
|
|
{
|
2013-04-04 11:03:33 +04:00
|
|
|
nsRefPtr<dom::HTMLSelectElement> selectElement =
|
|
|
|
dom::HTMLSelectElement::FromContent(mContent);
|
2013-09-28 23:04:20 +04:00
|
|
|
|
|
|
|
uint32_t mask = dom::HTMLSelectElement::NOTIFY;
|
|
|
|
if (aValue) {
|
|
|
|
mask |= dom::HTMLSelectElement::IS_SELECTED;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (aClearAll) {
|
|
|
|
mask |= dom::HTMLSelectElement::CLEAR_ALL;
|
|
|
|
}
|
|
|
|
|
|
|
|
return selectElement->SetOptionsSelectedByIndex(aStartIndex, aEndIndex, mask);
|
2001-11-02 10:40:01 +03:00
|
|
|
}
|
2000-12-20 18:15:28 +03:00
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
bool
|
2012-08-22 19:56:38 +04:00
|
|
|
nsListControlFrame::ToggleOptionSelectedFromFrame(int32_t aIndex)
|
2001-11-02 10:40:01 +03:00
|
|
|
{
|
2013-08-02 11:07:32 +04:00
|
|
|
nsRefPtr<dom::HTMLOptionElement> option =
|
|
|
|
GetOption(static_cast<uint32_t>(aIndex));
|
|
|
|
NS_ENSURE_TRUE(option, false);
|
2001-08-17 04:42:50 +04:00
|
|
|
|
2013-04-04 11:03:33 +04:00
|
|
|
nsRefPtr<dom::HTMLSelectElement> selectElement =
|
|
|
|
dom::HTMLSelectElement::FromContent(mContent);
|
2013-08-02 11:07:32 +04:00
|
|
|
|
2013-09-28 23:04:20 +04:00
|
|
|
uint32_t mask = dom::HTMLSelectElement::NOTIFY;
|
|
|
|
if (!option->Selected()) {
|
|
|
|
mask |= dom::HTMLSelectElement::IS_SELECTED;
|
|
|
|
}
|
|
|
|
|
|
|
|
return selectElement->SetOptionsSelectedByIndex(aIndex, aIndex, mask);
|
1999-10-06 03:43:06 +04:00
|
|
|
}
|
|
|
|
|
2001-11-02 10:40:01 +03:00
|
|
|
|
|
|
|
// Dispatch event and such
|
2011-09-29 10:19:26 +04:00
|
|
|
bool
|
2001-11-02 10:40:01 +03:00
|
|
|
nsListControlFrame::UpdateSelection()
|
1999-10-06 03:43:06 +04:00
|
|
|
{
|
2002-02-08 21:35:48 +03:00
|
|
|
if (mIsAllFramesHere) {
|
|
|
|
// if it's a combobox, display the new text
|
2009-02-18 06:27:25 +03:00
|
|
|
nsWeakFrame weakFrame(this);
|
2002-02-08 21:35:48 +03:00
|
|
|
if (mComboboxFrame) {
|
2006-03-01 04:00:29 +03:00
|
|
|
mComboboxFrame->RedisplaySelectedText();
|
2002-02-08 21:35:48 +03:00
|
|
|
}
|
|
|
|
// if it's a listbox, fire on change
|
|
|
|
else if (mIsAllContentHere) {
|
2006-03-01 04:00:29 +03:00
|
|
|
FireOnChange();
|
2002-02-08 21:35:48 +03:00
|
|
|
}
|
2009-02-18 06:27:25 +03:00
|
|
|
return weakFrame.IsAlive();
|
1999-08-27 07:58:13 +04:00
|
|
|
}
|
2011-10-17 18:59:28 +04:00
|
|
|
return true;
|
1999-08-27 07:58:13 +04:00
|
|
|
}
|
|
|
|
|
2006-03-01 04:00:29 +03:00
|
|
|
void
|
2012-08-22 19:56:38 +04:00
|
|
|
nsListControlFrame::ComboboxFinish(int32_t aIndex)
|
2000-03-18 17:17:34 +03:00
|
|
|
{
|
2002-09-20 06:12:12 +04:00
|
|
|
gLastKeyTime = 0;
|
|
|
|
|
2001-11-02 10:40:01 +03:00
|
|
|
if (mComboboxFrame) {
|
2009-02-18 06:27:25 +03:00
|
|
|
nsWeakFrame weakFrame(this);
|
2013-08-09 02:04:59 +04:00
|
|
|
PerformSelection(aIndex, false, false); // might destroy us
|
|
|
|
if (!weakFrame.IsAlive() || !mComboboxFrame) {
|
|
|
|
return;
|
|
|
|
}
|
2009-02-18 06:27:25 +03:00
|
|
|
|
2013-08-09 02:04:59 +04:00
|
|
|
int32_t displayIndex = mComboboxFrame->GetIndexOfDisplayArea();
|
2002-01-26 02:35:44 +03:00
|
|
|
if (displayIndex != aIndex) {
|
2009-02-18 06:27:25 +03:00
|
|
|
mComboboxFrame->RedisplaySelectedText(); // might destroy us
|
2002-01-26 02:35:44 +03:00
|
|
|
}
|
|
|
|
|
2009-02-18 06:27:25 +03:00
|
|
|
if (weakFrame.IsAlive() && mComboboxFrame) {
|
|
|
|
mComboboxFrame->RollupFromList(); // might destroy us
|
|
|
|
}
|
2002-01-26 02:35:44 +03:00
|
|
|
}
|
2000-03-18 17:17:34 +03:00
|
|
|
}
|
|
|
|
|
1999-10-06 03:43:06 +04:00
|
|
|
// Send out an onchange notification.
|
2006-03-01 04:00:29 +03:00
|
|
|
void
|
2002-01-26 02:35:44 +03:00
|
|
|
nsListControlFrame::FireOnChange()
|
1999-10-06 03:43:06 +04:00
|
|
|
{
|
2002-03-14 03:56:56 +03:00
|
|
|
if (mComboboxFrame) {
|
2004-07-23 12:25:44 +04:00
|
|
|
// Return hit without changing anything
|
2012-08-22 19:56:38 +04:00
|
|
|
int32_t index = mComboboxFrame->UpdateRecentIndex(NS_SKIP_NOTIFY_INDEX);
|
2006-09-30 09:07:49 +04:00
|
|
|
if (index == NS_SKIP_NOTIFY_INDEX)
|
2006-03-01 04:00:29 +03:00
|
|
|
return;
|
2004-07-23 12:25:44 +04:00
|
|
|
|
|
|
|
// See if the selection actually changed
|
2006-03-01 04:00:29 +03:00
|
|
|
if (index == GetSelectedIndex())
|
|
|
|
return;
|
2002-03-14 03:56:56 +03:00
|
|
|
}
|
2000-05-17 01:58:37 +04:00
|
|
|
|
2010-12-17 20:45:46 +03:00
|
|
|
// Dispatch the change event.
|
2011-10-18 14:53:36 +04:00
|
|
|
nsContentUtils::DispatchTrustedEvent(mContent->OwnerDoc(), mContent,
|
2011-10-17 18:59:28 +04:00
|
|
|
NS_LITERAL_STRING("change"), true,
|
|
|
|
false);
|
1999-10-06 03:43:06 +04:00
|
|
|
}
|
|
|
|
|
2005-02-05 01:56:13 +03:00
|
|
|
NS_IMETHODIMP
|
2012-08-22 19:56:38 +04:00
|
|
|
nsListControlFrame::OnSetSelectedIndex(int32_t aOldIndex, int32_t aNewIndex)
|
2005-02-05 01:56:13 +03:00
|
|
|
{
|
|
|
|
if (mComboboxFrame) {
|
2006-09-30 09:07:49 +04:00
|
|
|
// UpdateRecentIndex with NS_SKIP_NOTIFY_INDEX, so that we won't fire an onchange
|
2005-02-17 07:29:37 +03:00
|
|
|
// event for this setting of selectedIndex.
|
2006-09-30 09:07:49 +04:00
|
|
|
mComboboxFrame->UpdateRecentIndex(NS_SKIP_NOTIFY_INDEX);
|
2005-02-05 01:56:13 +03:00
|
|
|
}
|
|
|
|
|
2013-08-09 02:04:59 +04:00
|
|
|
nsWeakFrame weakFrame(this);
|
2005-02-05 01:56:13 +03:00
|
|
|
ScrollToIndex(aNewIndex);
|
2013-08-09 02:04:59 +04:00
|
|
|
if (!weakFrame.IsAlive()) {
|
|
|
|
return NS_OK;
|
|
|
|
}
|
2005-02-05 01:56:13 +03:00
|
|
|
mStartSelectionIndex = aNewIndex;
|
|
|
|
mEndSelectionIndex = aNewIndex;
|
2007-09-28 03:06:31 +04:00
|
|
|
InvalidateFocus();
|
2005-02-05 01:56:13 +03:00
|
|
|
|
2005-07-14 18:20:21 +04:00
|
|
|
#ifdef ACCESSIBILITY
|
|
|
|
FireMenuItemActiveEvent();
|
|
|
|
#endif
|
|
|
|
|
2005-02-05 01:56:13 +03:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
1999-08-26 18:54:07 +04:00
|
|
|
//----------------------------------------------------------------------
|
|
|
|
// End nsISelectControlFrame
|
|
|
|
//----------------------------------------------------------------------
|
1999-05-08 00:30:16 +04:00
|
|
|
|
2005-12-13 02:53:06 +03:00
|
|
|
nsresult
|
|
|
|
nsListControlFrame::SetFormProperty(nsIAtom* aName,
|
2002-03-24 01:26:36 +03:00
|
|
|
const nsAString& aValue)
|
1999-01-26 01:16:27 +03:00
|
|
|
{
|
2006-12-26 20:47:52 +03:00
|
|
|
if (nsGkAtoms::selected == aName) {
|
1999-04-13 02:14:31 +04:00
|
|
|
return NS_ERROR_INVALID_ARG; // Selected is readonly according to spec.
|
2006-12-26 20:47:52 +03:00
|
|
|
} else if (nsGkAtoms::selectedindex == aName) {
|
2001-11-02 10:40:01 +03:00
|
|
|
// You shouldn't be calling me for this!!!
|
|
|
|
return NS_ERROR_INVALID_ARG;
|
1999-04-13 02:14:31 +04:00
|
|
|
}
|
2000-03-21 02:43:07 +03:00
|
|
|
|
2001-11-02 10:40:01 +03:00
|
|
|
// We should be told about selectedIndex by the DOM element through
|
|
|
|
// OnOptionSelected
|
|
|
|
|
1999-01-26 01:16:27 +03:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2006-03-01 04:00:29 +03:00
|
|
|
void
|
1999-09-08 18:27:38 +04:00
|
|
|
nsListControlFrame::AboutToDropDown()
|
|
|
|
{
|
2009-08-25 23:07:57 +04:00
|
|
|
NS_ASSERTION(IsInDropDownMode(),
|
|
|
|
"AboutToDropDown called without being in dropdown mode");
|
|
|
|
|
|
|
|
// Our widget doesn't get invalidated on changes to the rest of the document,
|
|
|
|
// so compute and store this color at the start of a dropdown so we don't
|
|
|
|
// get weird painting behaviour.
|
|
|
|
// We start looking for backgrounds above the combobox frame to avoid
|
|
|
|
// duplicating the combobox frame's background and compose each background
|
|
|
|
// color we find underneath until we have an opaque color, or run out of
|
|
|
|
// backgrounds. We compose with the PresContext default background color,
|
|
|
|
// which is always opaque, in case we don't end up with an opaque color.
|
|
|
|
// This gives us a very poor approximation of translucency.
|
|
|
|
nsIFrame* comboboxFrame = do_QueryFrame(mComboboxFrame);
|
2013-02-16 09:38:33 +04:00
|
|
|
nsStyleContext* context = comboboxFrame->StyleContext()->GetParent();
|
2009-08-25 23:07:57 +04:00
|
|
|
mLastDropdownBackstopColor = NS_RGBA(0,0,0,0);
|
|
|
|
while (NS_GET_A(mLastDropdownBackstopColor) < 255 && context) {
|
|
|
|
mLastDropdownBackstopColor =
|
2013-02-17 01:51:02 +04:00
|
|
|
NS_ComposeColors(context->StyleBackground()->mBackgroundColor,
|
2009-08-25 23:07:57 +04:00
|
|
|
mLastDropdownBackstopColor);
|
|
|
|
context = context->GetParent();
|
|
|
|
}
|
|
|
|
mLastDropdownBackstopColor =
|
|
|
|
NS_ComposeColors(PresContext()->DefaultBackgroundColor(),
|
|
|
|
mLastDropdownBackstopColor);
|
2009-09-02 06:46:47 +04:00
|
|
|
|
|
|
|
if (mIsAllContentHere && mIsAllFramesHere && mHasBeenInitialized) {
|
2013-08-09 02:04:59 +04:00
|
|
|
nsWeakFrame weakFrame(this);
|
2009-09-02 06:46:47 +04:00
|
|
|
ScrollToIndex(GetSelectedIndex());
|
2013-08-09 02:04:59 +04:00
|
|
|
if (!weakFrame.IsAlive()) {
|
|
|
|
return;
|
|
|
|
}
|
2009-09-02 06:46:47 +04:00
|
|
|
#ifdef ACCESSIBILITY
|
|
|
|
FireMenuItemActiveEvent(); // Inform assistive tech what got focus
|
|
|
|
#endif
|
|
|
|
}
|
2011-10-17 18:59:28 +04:00
|
|
|
mItemSelectionStarted = false;
|
1999-09-08 18:27:38 +04:00
|
|
|
}
|
|
|
|
|
1999-10-01 18:30:33 +04:00
|
|
|
// We are about to be rolledup from the outside (ComboboxFrame)
|
2006-03-01 04:00:29 +03:00
|
|
|
void
|
1999-10-01 18:30:33 +04:00
|
|
|
nsListControlFrame::AboutToRollup()
|
|
|
|
{
|
2002-01-26 02:35:44 +03:00
|
|
|
// We've been updating the combobox with the keyboard up until now, but not
|
|
|
|
// with the mouse. The problem is, even with mouse selection, we are
|
|
|
|
// updating the <select>. So if the mouse goes over an option just before
|
|
|
|
// he leaves the box and clicks, that's what the <select> will show.
|
2002-01-25 22:54:55 +03:00
|
|
|
//
|
2002-01-26 02:35:44 +03:00
|
|
|
// To deal with this we say "whatever is in the combobox is canonical."
|
|
|
|
// - IF the combobox is different from the current selected index, we
|
|
|
|
// reset the index.
|
|
|
|
|
2005-02-16 08:13:16 +03:00
|
|
|
if (IsInDropDownMode()) {
|
2007-05-17 15:12:30 +04:00
|
|
|
ComboboxFinish(mComboboxFrame->GetIndexOfDisplayArea()); // might destroy us
|
2000-12-21 02:25:40 +03:00
|
|
|
}
|
1999-10-01 18:30:33 +04:00
|
|
|
}
|
|
|
|
|
1999-06-22 00:41:56 +04:00
|
|
|
NS_IMETHODIMP
|
2004-08-01 03:15:21 +04:00
|
|
|
nsListControlFrame::DidReflow(nsPresContext* aPresContext,
|
2005-10-15 08:08:04 +04:00
|
|
|
const nsHTMLReflowState* aReflowState,
|
|
|
|
nsDidReflowStatus aStatus)
|
1999-06-22 00:41:56 +04:00
|
|
|
{
|
2004-08-11 08:49:05 +04:00
|
|
|
nsresult rv;
|
2011-09-29 10:19:26 +04:00
|
|
|
bool wasInterrupted = !mHasPendingInterruptAtStartOfReflow &&
|
2009-09-05 01:07:38 +04:00
|
|
|
aPresContext->HasPendingInterrupt();
|
|
|
|
|
2012-06-23 05:13:56 +04:00
|
|
|
rv = nsHTMLScrollFrame::DidReflow(aPresContext, aReflowState, aStatus);
|
2004-08-11 08:49:05 +04:00
|
|
|
|
2009-09-05 01:07:38 +04:00
|
|
|
if (mNeedToReset && !wasInterrupted) {
|
2011-10-17 18:59:28 +04:00
|
|
|
mNeedToReset = false;
|
2004-09-13 06:10:29 +04:00
|
|
|
// Suppress scrolling to the selected element if we restored
|
|
|
|
// scroll history state AND the list contents have not changed
|
|
|
|
// since we loaded all the children AND nothing else forced us
|
2011-10-17 18:59:28 +04:00
|
|
|
// to scroll by calling ResetList(true). The latter two conditions
|
2004-09-13 06:10:29 +04:00
|
|
|
// are folded into mPostChildrenLoadedReset.
|
|
|
|
//
|
|
|
|
// The idea is that we want scroll history restoration to trump ResetList
|
|
|
|
// scrolling to the selected element, when the ResetList was probably only
|
|
|
|
// caused by content loading normally.
|
2012-05-21 09:18:28 +04:00
|
|
|
ResetList(!DidHistoryRestore() || mPostChildrenLoadedReset);
|
2004-08-11 08:49:05 +04:00
|
|
|
}
|
|
|
|
|
2011-10-17 18:59:28 +04:00
|
|
|
mHasPendingInterruptAtStartOfReflow = false;
|
2004-08-11 08:49:05 +04:00
|
|
|
return rv;
|
1999-06-22 00:41:56 +04:00
|
|
|
}
|
|
|
|
|
2003-10-31 23:19:18 +03:00
|
|
|
nsIAtom*
|
|
|
|
nsListControlFrame::GetType() const
|
2001-03-20 02:20:21 +03:00
|
|
|
{
|
2006-12-26 20:47:52 +03:00
|
|
|
return nsGkAtoms::listControlFrame;
|
2001-03-20 02:20:21 +03:00
|
|
|
}
|
1999-08-31 17:22:50 +04:00
|
|
|
|
2001-10-25 05:08:40 +04:00
|
|
|
#ifdef DEBUG
|
|
|
|
NS_IMETHODIMP
|
2001-11-14 04:33:42 +03:00
|
|
|
nsListControlFrame::GetFrameName(nsAString& aResult) const
|
2001-10-25 05:08:40 +04:00
|
|
|
{
|
2001-11-14 04:33:42 +03:00
|
|
|
return MakeFrameName(NS_LITERAL_STRING("ListControl"), aResult);
|
2001-10-25 05:08:40 +04:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
Bug 300030: Move intrinsic width computation out of nsIFrame::Reflow and into its own methods on nsIFrame. Replace reflow reasons, types, and commands with dirty bits/notifications. Thanks to bzbarsky for almost all of the HTML form controls (mozilla/layout/forms) changes, and many others for help testing and patching. For detailed commit logs, see REFLOW_YYYYMMDD_BRANCH, where YYYYMMDD is one of 20061031, 20060830, 20060603, 20060302, 20060119, 20051011, 20050804, 20050429, 20050315, 20050111, and 20041213.
2006-12-08 08:38:33 +03:00
|
|
|
nscoord
|
|
|
|
nsListControlFrame::GetHeightOfARow()
|
fixed bugs #6303, #6753, #6756, #6759
Re-wrote nsComboboxFrame.
removed the obsolete nsHTMLAtoms: comboText,comoTextSelected,comTextSelectedFocus,dropDownVisible,
dropdownHidden, dropDownBtnOut, dropDownBtnPressed,
Added nsHTMLAtoms::combobox, nsLayoutAtoms::popupList
Renamed dropDownList to dropDownListPseudo
Added "arrow.gif" as to be used the background-image for the combobox button
ua.css - added rules for select to differentiate between comboboxes and listboxes.
Added style rules to more closely match the XPTOOLKIT XPWidgets look.
removed the following :-moz-combobox-text, -moz-combobox-textselected
nsIFormControlFrame.h - Added SetSuggestedSize method.
nsButtonControlFrame - Implemented SetSuggestedSize.
nsCSSFrameConstructor.cpp - Rewrote ConstructSelectFrame.
nsIWidget.h -Added GetAbsoluteBounds method.
nsWindow.cpp - Implemented GetAbsoluteBounds.
1999-07-15 02:00:24 +04:00
|
|
|
{
|
Bug 300030: Move intrinsic width computation out of nsIFrame::Reflow and into its own methods on nsIFrame. Replace reflow reasons, types, and commands with dirty bits/notifications. Thanks to bzbarsky for almost all of the HTML form controls (mozilla/layout/forms) changes, and many others for help testing and patching. For detailed commit logs, see REFLOW_YYYYMMDD_BRANCH, where YYYYMMDD is one of 20061031, 20060830, 20060603, 20060302, 20060119, 20051011, 20050804, 20050429, 20050315, 20050111, and 20041213.
2006-12-08 08:38:33 +03:00
|
|
|
return HeightOfARow();
|
fixed bugs #6303, #6753, #6756, #6759
Re-wrote nsComboboxFrame.
removed the obsolete nsHTMLAtoms: comboText,comoTextSelected,comTextSelectedFocus,dropDownVisible,
dropdownHidden, dropDownBtnOut, dropDownBtnPressed,
Added nsHTMLAtoms::combobox, nsLayoutAtoms::popupList
Renamed dropDownList to dropDownListPseudo
Added "arrow.gif" as to be used the background-image for the combobox button
ua.css - added rules for select to differentiate between comboboxes and listboxes.
Added style rules to more closely match the XPTOOLKIT XPWidgets look.
removed the following :-moz-combobox-text, -moz-combobox-textselected
nsIFormControlFrame.h - Added SetSuggestedSize method.
nsButtonControlFrame - Implemented SetSuggestedSize.
nsCSSFrameConstructor.cpp - Rewrote ConstructSelectFrame.
nsIWidget.h -Added GetAbsoluteBounds method.
nsWindow.cpp - Implemented GetAbsoluteBounds.
1999-07-15 02:00:24 +04:00
|
|
|
}
|
1999-05-28 01:17:10 +04:00
|
|
|
|
2001-11-02 10:40:01 +03:00
|
|
|
nsresult
|
2012-08-22 19:56:38 +04:00
|
|
|
nsListControlFrame::IsOptionDisabled(int32_t anIndex, bool &aIsDisabled)
|
2000-08-18 01:38:15 +04:00
|
|
|
{
|
2013-04-04 11:03:33 +04:00
|
|
|
nsRefPtr<dom::HTMLSelectElement> sel =
|
|
|
|
dom::HTMLSelectElement::FromContent(mContent);
|
2001-11-02 10:40:01 +03:00
|
|
|
if (sel) {
|
|
|
|
sel->IsOptionDisabled(anIndex, &aIsDisabled);
|
|
|
|
return NS_OK;
|
2000-08-18 01:38:15 +04:00
|
|
|
}
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
|
2000-02-09 22:34:39 +03:00
|
|
|
//----------------------------------------------------------------------
|
|
|
|
// helper
|
|
|
|
//----------------------------------------------------------------------
|
2011-09-29 10:19:26 +04:00
|
|
|
bool
|
2000-02-09 22:34:39 +03:00
|
|
|
nsListControlFrame::IsLeftButton(nsIDOMEvent* aMouseEvent)
|
|
|
|
{
|
|
|
|
// only allow selection with the left button
|
|
|
|
nsCOMPtr<nsIDOMMouseEvent> mouseEvent = do_QueryInterface(aMouseEvent);
|
|
|
|
if (mouseEvent) {
|
2012-08-22 19:56:38 +04:00
|
|
|
uint16_t whichButton;
|
2000-02-09 22:34:39 +03:00
|
|
|
if (NS_SUCCEEDED(mouseEvent->GetButton(&whichButton))) {
|
2011-10-17 18:59:28 +04:00
|
|
|
return whichButton != 0?false:true;
|
2000-02-09 22:34:39 +03:00
|
|
|
}
|
|
|
|
}
|
2011-10-17 18:59:28 +04:00
|
|
|
return false;
|
2000-02-09 22:34:39 +03:00
|
|
|
}
|
|
|
|
|
2005-11-05 02:36:27 +03:00
|
|
|
nscoord
|
2011-11-24 06:48:23 +04:00
|
|
|
nsListControlFrame::CalcFallbackRowHeight(float aFontSizeInflation)
|
2005-11-05 02:36:27 +03:00
|
|
|
{
|
|
|
|
nscoord rowHeight = 0;
|
2011-04-08 08:18:43 +04:00
|
|
|
|
2011-04-08 05:05:49 +04:00
|
|
|
nsRefPtr<nsFontMetrics> fontMet;
|
2011-11-24 06:48:23 +04:00
|
|
|
nsLayoutUtils::GetFontMetricsForFrame(this, getter_AddRefs(fontMet),
|
|
|
|
aFontSizeInflation);
|
2008-12-04 19:09:53 +03:00
|
|
|
if (fontMet) {
|
2011-04-08 08:18:43 +04:00
|
|
|
rowHeight = fontMet->MaxHeight();
|
2005-11-05 02:36:27 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
return rowHeight;
|
|
|
|
}
|
|
|
|
|
Bug 300030: Move intrinsic width computation out of nsIFrame::Reflow and into its own methods on nsIFrame. Replace reflow reasons, types, and commands with dirty bits/notifications. Thanks to bzbarsky for almost all of the HTML form controls (mozilla/layout/forms) changes, and many others for help testing and patching. For detailed commit logs, see REFLOW_YYYYMMDD_BRANCH, where YYYYMMDD is one of 20061031, 20060830, 20060603, 20060302, 20060119, 20051011, 20050804, 20050429, 20050315, 20050111, and 20041213.
2006-12-08 08:38:33 +03:00
|
|
|
nscoord
|
|
|
|
nsListControlFrame::CalcIntrinsicHeight(nscoord aHeightOfARow,
|
2012-08-22 19:56:38 +04:00
|
|
|
int32_t aNumberOfOptions)
|
Bug 300030: Move intrinsic width computation out of nsIFrame::Reflow and into its own methods on nsIFrame. Replace reflow reasons, types, and commands with dirty bits/notifications. Thanks to bzbarsky for almost all of the HTML form controls (mozilla/layout/forms) changes, and many others for help testing and patching. For detailed commit logs, see REFLOW_YYYYMMDD_BRANCH, where YYYYMMDD is one of 20061031, 20060830, 20060603, 20060302, 20060119, 20051011, 20050804, 20050429, 20050315, 20050111, and 20041213.
2006-12-08 08:38:33 +03:00
|
|
|
{
|
|
|
|
NS_PRECONDITION(!IsInDropDownMode(),
|
|
|
|
"Shouldn't be in dropdown mode when we call this");
|
2010-11-09 17:24:01 +03:00
|
|
|
|
2013-08-02 11:09:02 +04:00
|
|
|
dom::HTMLSelectElement* select =
|
|
|
|
dom::HTMLSelectElement::FromContentOrNull(mContent);
|
|
|
|
if (select) {
|
|
|
|
mNumDisplayRows = select->Size();
|
|
|
|
} else {
|
|
|
|
mNumDisplayRows = 1;
|
|
|
|
}
|
Bug 300030: Move intrinsic width computation out of nsIFrame::Reflow and into its own methods on nsIFrame. Replace reflow reasons, types, and commands with dirty bits/notifications. Thanks to bzbarsky for almost all of the HTML form controls (mozilla/layout/forms) changes, and many others for help testing and patching. For detailed commit logs, see REFLOW_YYYYMMDD_BRANCH, where YYYYMMDD is one of 20061031, 20060830, 20060603, 20060302, 20060119, 20051011, 20050804, 20050429, 20050315, 20050111, and 20041213.
2006-12-08 08:38:33 +03:00
|
|
|
|
|
|
|
if (mNumDisplayRows < 1) {
|
2010-11-09 17:24:01 +03:00
|
|
|
mNumDisplayRows = 4;
|
Bug 300030: Move intrinsic width computation out of nsIFrame::Reflow and into its own methods on nsIFrame. Replace reflow reasons, types, and commands with dirty bits/notifications. Thanks to bzbarsky for almost all of the HTML form controls (mozilla/layout/forms) changes, and many others for help testing and patching. For detailed commit logs, see REFLOW_YYYYMMDD_BRANCH, where YYYYMMDD is one of 20061031, 20060830, 20060603, 20060302, 20060119, 20051011, 20050804, 20050429, 20050315, 20050111, and 20041213.
2006-12-08 08:38:33 +03:00
|
|
|
}
|
|
|
|
|
2010-11-09 17:24:01 +03:00
|
|
|
return mNumDisplayRows * aHeightOfARow;
|
Bug 300030: Move intrinsic width computation out of nsIFrame::Reflow and into its own methods on nsIFrame. Replace reflow reasons, types, and commands with dirty bits/notifications. Thanks to bzbarsky for almost all of the HTML form controls (mozilla/layout/forms) changes, and many others for help testing and patching. For detailed commit logs, see REFLOW_YYYYMMDD_BRANCH, where YYYYMMDD is one of 20061031, 20060830, 20060603, 20060302, 20060119, 20051011, 20050804, 20050429, 20050315, 20050111, and 20041213.
2006-12-08 08:38:33 +03:00
|
|
|
}
|
|
|
|
|
1999-08-26 18:54:07 +04:00
|
|
|
//----------------------------------------------------------------------
|
|
|
|
// nsIDOMMouseListener
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
nsresult
|
|
|
|
nsListControlFrame::MouseUp(nsIDOMEvent* aMouseEvent)
|
|
|
|
{
|
2012-07-30 18:20:58 +04:00
|
|
|
NS_ASSERTION(aMouseEvent != nullptr, "aMouseEvent is null.");
|
2000-03-07 18:54:31 +03:00
|
|
|
|
2011-06-29 22:07:25 +04:00
|
|
|
nsCOMPtr<nsIDOMMouseEvent> mouseEvent = do_QueryInterface(aMouseEvent);
|
|
|
|
NS_ENSURE_TRUE(mouseEvent, NS_ERROR_FAILURE);
|
|
|
|
|
2005-06-02 13:00:48 +04:00
|
|
|
UpdateInListState(aMouseEvent);
|
|
|
|
|
2011-10-17 18:59:28 +04:00
|
|
|
mButtonDown = false;
|
2001-11-02 10:40:01 +03:00
|
|
|
|
2011-06-01 05:46:57 +04:00
|
|
|
nsEventStates eventStates = mContent->AsElement()->State();
|
2010-10-20 15:26:32 +04:00
|
|
|
if (eventStates.HasState(NS_EVENT_STATE_DISABLED)) {
|
1999-08-26 18:54:07 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2000-02-09 22:34:39 +03:00
|
|
|
// only allow selection with the left button
|
2000-08-03 18:13:58 +04:00
|
|
|
// if a right button click is on the combobox itself
|
|
|
|
// or on the select when in listbox mode, then let the click through
|
2000-02-09 22:34:39 +03:00
|
|
|
if (!IsLeftButton(aMouseEvent)) {
|
2005-02-16 08:13:16 +03:00
|
|
|
if (IsInDropDownMode()) {
|
2005-06-02 13:00:48 +04:00
|
|
|
if (!IgnoreMouseEventForSelection(aMouseEvent)) {
|
2000-08-03 18:13:58 +04:00
|
|
|
aMouseEvent->PreventDefault();
|
2006-03-26 01:03:49 +03:00
|
|
|
aMouseEvent->StopPropagation();
|
2000-08-03 18:13:58 +04:00
|
|
|
} else {
|
2011-10-17 18:59:28 +04:00
|
|
|
CaptureMouseEvents(false);
|
2000-08-03 18:13:58 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
2011-10-17 18:59:28 +04:00
|
|
|
CaptureMouseEvents(false);
|
2000-08-03 18:13:58 +04:00
|
|
|
return NS_ERROR_FAILURE; // means consume event
|
|
|
|
} else {
|
2011-10-17 18:59:28 +04:00
|
|
|
CaptureMouseEvents(false);
|
1999-09-08 18:27:38 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-02-17 01:51:02 +04:00
|
|
|
const nsStyleVisibility* vis = StyleVisibility();
|
2001-06-01 02:19:43 +04:00
|
|
|
|
|
|
|
if (!vis->IsVisible()) {
|
1999-08-26 18:54:07 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2001-11-02 10:40:01 +03:00
|
|
|
if (IsInDropDownMode()) {
|
2000-05-27 03:31:25 +04:00
|
|
|
// XXX This is a bit of a hack, but.....
|
|
|
|
// But the idea here is to make sure you get an "onclick" event when you mouse
|
|
|
|
// down on the select and the drag over an option and let go
|
|
|
|
// And then NOT get an "onclick" event when when you click down on the select
|
|
|
|
// and then up outside of the select
|
|
|
|
// the EventStateManager tracks the content of the mouse down and the mouse up
|
|
|
|
// to make sure they are the same, and the onclick is sent in the PostHandleEvent
|
|
|
|
// depeneding on whether the clickCount is non-zero.
|
|
|
|
// So we cheat here by either setting or unsetting the clcikCount in the native event
|
|
|
|
// so the right thing happens for the onclick event
|
2013-10-02 10:38:27 +04:00
|
|
|
WidgetMouseEvent* mouseEvent =
|
|
|
|
static_cast<WidgetMouseEvent*>(aMouseEvent->GetInternalNSEvent());
|
2000-05-27 03:31:25 +04:00
|
|
|
|
2012-08-22 19:56:38 +04:00
|
|
|
int32_t selectedIndex;
|
2001-11-02 10:40:01 +03:00
|
|
|
if (NS_SUCCEEDED(GetIndexFromDOMEvent(aMouseEvent, selectedIndex))) {
|
|
|
|
// If it's disabled, disallow the click and leave.
|
2011-09-29 10:19:26 +04:00
|
|
|
bool isDisabled = false;
|
2001-11-02 10:40:01 +03:00
|
|
|
IsOptionDisabled(selectedIndex, isDisabled);
|
|
|
|
if (isDisabled) {
|
|
|
|
aMouseEvent->PreventDefault();
|
2006-03-26 01:03:49 +03:00
|
|
|
aMouseEvent->StopPropagation();
|
2011-10-17 18:59:28 +04:00
|
|
|
CaptureMouseEvents(false);
|
2001-11-02 10:40:01 +03:00
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (kNothingSelected != selectedIndex) {
|
2007-05-17 15:12:30 +04:00
|
|
|
nsWeakFrame weakFrame(this);
|
2002-01-26 02:35:44 +03:00
|
|
|
ComboboxFinish(selectedIndex);
|
2007-05-17 15:12:30 +04:00
|
|
|
if (!weakFrame.IsAlive())
|
|
|
|
return NS_OK;
|
2004-05-28 20:25:04 +04:00
|
|
|
FireOnChange();
|
1999-08-26 18:54:07 +04:00
|
|
|
}
|
2002-01-26 02:35:44 +03:00
|
|
|
|
2000-05-27 03:31:25 +04:00
|
|
|
mouseEvent->clickCount = 1;
|
|
|
|
} else {
|
|
|
|
// the click was out side of the select or its dropdown
|
2005-06-02 13:00:48 +04:00
|
|
|
mouseEvent->clickCount = IgnoreMouseEventForSelection(aMouseEvent) ? 1 : 0;
|
1999-08-26 18:54:07 +04:00
|
|
|
}
|
|
|
|
} else {
|
2011-10-17 18:59:28 +04:00
|
|
|
CaptureMouseEvents(false);
|
2001-11-02 10:40:01 +03:00
|
|
|
// Notify
|
2002-01-26 02:35:44 +03:00
|
|
|
if (mChangesSinceDragStart) {
|
2003-08-12 20:00:20 +04:00
|
|
|
// reset this so that future MouseUps without a prior MouseDown
|
|
|
|
// won't fire onchange
|
2011-10-17 18:59:28 +04:00
|
|
|
mChangesSinceDragStart = false;
|
2002-02-08 21:35:48 +03:00
|
|
|
FireOnChange();
|
2002-01-26 02:35:44 +03:00
|
|
|
}
|
1999-08-26 18:54:07 +04:00
|
|
|
}
|
|
|
|
|
2000-03-07 18:54:31 +03:00
|
|
|
return NS_OK;
|
1999-08-26 18:54:07 +04:00
|
|
|
}
|
|
|
|
|
2005-06-02 13:00:48 +04:00
|
|
|
void
|
|
|
|
nsListControlFrame::UpdateInListState(nsIDOMEvent* aEvent)
|
2000-01-11 23:36:37 +03:00
|
|
|
{
|
2006-02-18 04:52:03 +03:00
|
|
|
if (!mComboboxFrame || !mComboboxFrame->IsDroppedDown())
|
2005-06-02 13:00:48 +04:00
|
|
|
return;
|
|
|
|
|
|
|
|
nsPoint pt = nsLayoutUtils::GetDOMEventCoordinatesRelativeTo(aEvent, this);
|
2009-09-03 08:49:16 +04:00
|
|
|
nsRect borderInnerEdge = GetScrollPortRect();
|
2005-06-15 02:15:53 +04:00
|
|
|
if (pt.y >= borderInnerEdge.y && pt.y < borderInnerEdge.YMost()) {
|
2011-10-17 18:59:28 +04:00
|
|
|
mItemSelectionStarted = true;
|
2000-01-11 23:36:37 +03:00
|
|
|
}
|
2005-06-02 13:00:48 +04:00
|
|
|
}
|
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
bool nsListControlFrame::IgnoreMouseEventForSelection(nsIDOMEvent* aEvent)
|
2005-06-02 13:00:48 +04:00
|
|
|
{
|
|
|
|
if (!mComboboxFrame)
|
2011-10-17 18:59:28 +04:00
|
|
|
return false;
|
2005-06-02 13:00:48 +04:00
|
|
|
|
|
|
|
// Our DOM listener does get called when the dropdown is not
|
|
|
|
// showing, because it listens to events on the SELECT element
|
2006-02-18 04:52:03 +03:00
|
|
|
if (!mComboboxFrame->IsDroppedDown())
|
2011-10-17 18:59:28 +04:00
|
|
|
return true;
|
2005-06-02 13:00:48 +04:00
|
|
|
|
|
|
|
return !mItemSelectionStarted;
|
2000-01-11 23:36:37 +03:00
|
|
|
}
|
|
|
|
|
2002-10-25 06:53:45 +04:00
|
|
|
#ifdef ACCESSIBILITY
|
|
|
|
void
|
|
|
|
nsListControlFrame::FireMenuItemActiveEvent()
|
|
|
|
{
|
2005-07-14 18:20:21 +04:00
|
|
|
if (mFocused != this && !IsInDropDownMode()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2011-09-28 05:46:11 +04:00
|
|
|
nsCOMPtr<nsIContent> optionContent = GetCurrentOption();
|
2005-02-08 02:11:30 +03:00
|
|
|
if (!optionContent) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2006-05-03 21:02:37 +04:00
|
|
|
FireDOMEvent(NS_LITERAL_STRING("DOMMenuItemActive"), optionContent);
|
2002-10-25 06:53:45 +04:00
|
|
|
}
|
|
|
|
#endif
|
1999-08-26 18:54:07 +04:00
|
|
|
|
|
|
|
nsresult
|
1999-08-27 18:42:27 +04:00
|
|
|
nsListControlFrame::GetIndexFromDOMEvent(nsIDOMEvent* aMouseEvent,
|
2012-08-22 19:56:38 +04:00
|
|
|
int32_t& aCurIndex)
|
1999-08-26 18:54:07 +04:00
|
|
|
{
|
2006-01-26 05:29:17 +03:00
|
|
|
if (IgnoreMouseEventForSelection(aMouseEvent))
|
2000-01-11 23:36:37 +03:00
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
|
2009-09-13 17:13:16 +04:00
|
|
|
if (nsIPresShell::GetCapturingContent() != mContent) {
|
2005-06-17 06:44:31 +04:00
|
|
|
// If we're not capturing, then ignore movement in the border
|
|
|
|
nsPoint pt = nsLayoutUtils::GetDOMEventCoordinatesRelativeTo(aMouseEvent, this);
|
2009-09-03 08:49:16 +04:00
|
|
|
nsRect borderInnerEdge = GetScrollPortRect();
|
2005-06-17 06:44:31 +04:00
|
|
|
if (!borderInnerEdge.Contains(pt)) {
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-08-02 11:07:56 +04:00
|
|
|
nsRefPtr<dom::HTMLOptionElement> option;
|
|
|
|
for (nsCOMPtr<nsIContent> content =
|
|
|
|
PresContext()->EventStateManager()->GetEventTargetContent(nullptr);
|
|
|
|
content && !option;
|
|
|
|
content = content->GetParent()) {
|
|
|
|
option = dom::HTMLOptionElement::FromContent(content);
|
|
|
|
}
|
2004-02-27 20:17:37 +03:00
|
|
|
|
2013-08-02 11:07:56 +04:00
|
|
|
if (option) {
|
2013-08-14 10:57:04 +04:00
|
|
|
aCurIndex = option->Index();
|
2013-08-02 11:07:56 +04:00
|
|
|
MOZ_ASSERT(aCurIndex >= 0);
|
2005-06-02 13:00:48 +04:00
|
|
|
return NS_OK;
|
1999-08-26 18:54:07 +04:00
|
|
|
}
|
2004-02-27 20:17:37 +03:00
|
|
|
|
2012-08-22 19:56:38 +04:00
|
|
|
int32_t numOptions = GetNumberOfOptions();
|
2005-06-02 13:00:48 +04:00
|
|
|
if (numOptions < 1)
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
|
|
|
|
nsPoint pt = nsLayoutUtils::GetDOMEventCoordinatesRelativeTo(aMouseEvent, this);
|
|
|
|
|
|
|
|
// If the event coordinate is above the first option frame, then target the
|
|
|
|
// first option frame
|
2013-08-02 11:07:56 +04:00
|
|
|
nsRefPtr<dom::HTMLOptionElement> firstOption = GetOption(0);
|
2005-06-02 13:00:48 +04:00
|
|
|
NS_ASSERTION(firstOption, "Can't find first option that's supposed to be there");
|
2009-12-25 00:20:06 +03:00
|
|
|
nsIFrame* optionFrame = firstOption->GetPrimaryFrame();
|
2005-08-23 02:24:29 +04:00
|
|
|
if (optionFrame) {
|
2005-06-02 13:00:48 +04:00
|
|
|
nsPoint ptInOptionFrame = pt - optionFrame->GetOffsetTo(this);
|
|
|
|
if (ptInOptionFrame.y < 0 && ptInOptionFrame.x >= 0 &&
|
|
|
|
ptInOptionFrame.x < optionFrame->GetSize().width) {
|
|
|
|
aCurIndex = 0;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-08-02 11:07:56 +04:00
|
|
|
nsRefPtr<dom::HTMLOptionElement> lastOption = GetOption(numOptions - 1);
|
2005-06-02 13:00:48 +04:00
|
|
|
// If the event coordinate is below the last option frame, then target the
|
|
|
|
// last option frame
|
|
|
|
NS_ASSERTION(lastOption, "Can't find last option that's supposed to be there");
|
2009-12-25 00:20:06 +03:00
|
|
|
optionFrame = lastOption->GetPrimaryFrame();
|
2005-08-23 02:24:29 +04:00
|
|
|
if (optionFrame) {
|
2005-06-02 13:00:48 +04:00
|
|
|
nsPoint ptInOptionFrame = pt - optionFrame->GetOffsetTo(this);
|
|
|
|
if (ptInOptionFrame.y >= optionFrame->GetSize().height && ptInOptionFrame.x >= 0 &&
|
|
|
|
ptInOptionFrame.x < optionFrame->GetSize().width) {
|
|
|
|
aCurIndex = numOptions - 1;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return NS_ERROR_FAILURE;
|
1999-08-26 18:54:07 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
nsListControlFrame::MouseDown(nsIDOMEvent* aMouseEvent)
|
|
|
|
{
|
2012-07-30 18:20:58 +04:00
|
|
|
NS_ASSERTION(aMouseEvent != nullptr, "aMouseEvent is null.");
|
2000-03-07 18:54:31 +03:00
|
|
|
|
2011-06-29 22:07:25 +04:00
|
|
|
nsCOMPtr<nsIDOMMouseEvent> mouseEvent = do_QueryInterface(aMouseEvent);
|
|
|
|
NS_ENSURE_TRUE(mouseEvent, NS_ERROR_FAILURE);
|
|
|
|
|
2005-06-02 13:00:48 +04:00
|
|
|
UpdateInListState(aMouseEvent);
|
|
|
|
|
2011-06-01 05:46:57 +04:00
|
|
|
nsEventStates eventStates = mContent->AsElement()->State();
|
2010-10-20 15:26:32 +04:00
|
|
|
if (eventStates.HasState(NS_EVENT_STATE_DISABLED)) {
|
1999-08-26 18:54:07 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
1999-09-08 18:27:38 +04:00
|
|
|
|
2000-02-09 22:34:39 +03:00
|
|
|
// only allow selection with the left button
|
2000-08-03 18:13:58 +04:00
|
|
|
// if a right button click is on the combobox itself
|
|
|
|
// or on the select when in listbox mode, then let the click through
|
2000-02-09 22:34:39 +03:00
|
|
|
if (!IsLeftButton(aMouseEvent)) {
|
2000-08-03 18:13:58 +04:00
|
|
|
if (IsInDropDownMode()) {
|
2005-06-02 13:00:48 +04:00
|
|
|
if (!IgnoreMouseEventForSelection(aMouseEvent)) {
|
2000-08-03 18:13:58 +04:00
|
|
|
aMouseEvent->PreventDefault();
|
2006-03-26 01:03:49 +03:00
|
|
|
aMouseEvent->StopPropagation();
|
2000-08-03 18:13:58 +04:00
|
|
|
} else {
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
return NS_ERROR_FAILURE; // means consume event
|
|
|
|
} else {
|
|
|
|
return NS_OK;
|
|
|
|
}
|
2000-02-09 22:34:39 +03:00
|
|
|
}
|
|
|
|
|
2012-08-22 19:56:38 +04:00
|
|
|
int32_t selectedIndex;
|
2001-11-02 10:40:01 +03:00
|
|
|
if (NS_SUCCEEDED(GetIndexFromDOMEvent(aMouseEvent, selectedIndex))) {
|
2005-07-11 03:46:56 +04:00
|
|
|
// Handle Like List
|
2011-10-17 18:59:28 +04:00
|
|
|
mButtonDown = true;
|
|
|
|
CaptureMouseEvents(true);
|
2013-08-09 02:04:59 +04:00
|
|
|
nsWeakFrame weakFrame(this);
|
|
|
|
bool change =
|
|
|
|
HandleListSelection(aMouseEvent, selectedIndex); // might destroy us
|
|
|
|
if (!weakFrame.IsAlive()) {
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
mChangesSinceDragStart = change;
|
1999-08-26 18:54:07 +04:00
|
|
|
} else {
|
1999-09-08 18:27:38 +04:00
|
|
|
// NOTE: the combo box is responsible for dropping it down
|
1999-08-26 18:54:07 +04:00
|
|
|
if (mComboboxFrame) {
|
2013-08-26 05:34:23 +04:00
|
|
|
if (XRE_GetProcessType() == GeckoProcessType_Content &&
|
|
|
|
Preferences::GetBool("browser.tabs.remote", false)) {
|
|
|
|
nsContentUtils::DispatchChromeEvent(mContent->OwnerDoc(), mContent,
|
|
|
|
NS_LITERAL_STRING("mozshowdropdown"), true,
|
|
|
|
false);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2005-06-02 13:00:48 +04:00
|
|
|
if (!IgnoreMouseEventForSelection(aMouseEvent)) {
|
2003-06-06 05:11:57 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
1999-09-30 15:37:58 +04:00
|
|
|
|
2005-02-16 08:13:16 +03:00
|
|
|
if (!nsComboboxControlFrame::ToolkitHasNativePopup())
|
|
|
|
{
|
2011-09-29 10:19:26 +04:00
|
|
|
bool isDroppedDown = mComboboxFrame->IsDroppedDown();
|
2009-01-12 22:20:59 +03:00
|
|
|
nsIFrame* comboFrame = do_QueryFrame(mComboboxFrame);
|
2007-05-17 15:12:30 +04:00
|
|
|
nsWeakFrame weakFrame(comboFrame);
|
2005-02-16 08:13:16 +03:00
|
|
|
mComboboxFrame->ShowDropDown(!isDroppedDown);
|
2007-05-17 15:12:30 +04:00
|
|
|
if (!weakFrame.IsAlive())
|
|
|
|
return NS_OK;
|
2005-02-16 08:13:16 +03:00
|
|
|
if (isDroppedDown) {
|
2011-10-17 18:59:28 +04:00
|
|
|
CaptureMouseEvents(false);
|
2005-02-16 08:13:16 +03:00
|
|
|
}
|
1999-08-26 18:54:07 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2000-03-03 07:28:59 +03:00
|
|
|
|
|
|
|
return NS_OK;
|
1999-08-26 18:54:07 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
// nsIDOMMouseMotionListener
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
nsresult
|
|
|
|
nsListControlFrame::MouseMove(nsIDOMEvent* aMouseEvent)
|
|
|
|
{
|
2002-01-10 07:23:13 +03:00
|
|
|
NS_ASSERTION(aMouseEvent, "aMouseEvent is null.");
|
2011-06-29 22:07:25 +04:00
|
|
|
nsCOMPtr<nsIDOMMouseEvent> mouseEvent = do_QueryInterface(aMouseEvent);
|
|
|
|
NS_ENSURE_TRUE(mouseEvent, NS_ERROR_FAILURE);
|
2000-03-07 18:54:31 +03:00
|
|
|
|
2005-06-02 13:00:48 +04:00
|
|
|
UpdateInListState(aMouseEvent);
|
|
|
|
|
2005-02-16 08:13:16 +03:00
|
|
|
if (IsInDropDownMode()) {
|
2006-02-18 04:52:03 +03:00
|
|
|
if (mComboboxFrame->IsDroppedDown()) {
|
2012-08-22 19:56:38 +04:00
|
|
|
int32_t selectedIndex;
|
2001-11-02 10:40:01 +03:00
|
|
|
if (NS_SUCCEEDED(GetIndexFromDOMEvent(aMouseEvent, selectedIndex))) {
|
2013-08-09 02:04:59 +04:00
|
|
|
PerformSelection(selectedIndex, false, false); // might destroy us
|
1999-08-26 18:54:07 +04:00
|
|
|
}
|
|
|
|
}
|
2000-03-15 18:55:30 +03:00
|
|
|
} else {// XXX - temporary until we get drag events
|
2000-03-07 18:54:31 +03:00
|
|
|
if (mButtonDown) {
|
2013-08-09 02:04:59 +04:00
|
|
|
return DragMove(aMouseEvent); // might destroy us
|
2000-03-15 18:55:30 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
nsListControlFrame::DragMove(nsIDOMEvent* aMouseEvent)
|
|
|
|
{
|
2002-01-10 07:23:13 +03:00
|
|
|
NS_ASSERTION(aMouseEvent, "aMouseEvent is null.");
|
2000-03-15 18:55:30 +03:00
|
|
|
|
2005-06-02 13:00:48 +04:00
|
|
|
UpdateInListState(aMouseEvent);
|
|
|
|
|
2005-02-16 08:13:16 +03:00
|
|
|
if (!IsInDropDownMode()) {
|
2012-08-22 19:56:38 +04:00
|
|
|
int32_t selectedIndex;
|
2001-11-02 10:40:01 +03:00
|
|
|
if (NS_SUCCEEDED(GetIndexFromDOMEvent(aMouseEvent, selectedIndex))) {
|
2002-01-10 07:23:13 +03:00
|
|
|
// Don't waste cycles if we already dragged over this item
|
|
|
|
if (selectedIndex == mEndSelectionIndex) {
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
nsCOMPtr<nsIDOMMouseEvent> mouseEvent = do_QueryInterface(aMouseEvent);
|
|
|
|
NS_ASSERTION(mouseEvent, "aMouseEvent is not an nsIDOMMouseEvent!");
|
2011-09-29 10:19:26 +04:00
|
|
|
bool isControl;
|
2007-02-15 00:00:15 +03:00
|
|
|
#ifdef XP_MACOSX
|
2002-01-10 07:23:13 +03:00
|
|
|
mouseEvent->GetMetaKey(&isControl);
|
|
|
|
#else
|
|
|
|
mouseEvent->GetCtrlKey(&isControl);
|
|
|
|
#endif
|
2013-08-09 02:04:59 +04:00
|
|
|
nsWeakFrame weakFrame(this);
|
2002-01-10 07:23:13 +03:00
|
|
|
// Turn SHIFT on when you are dragging, unless control is on.
|
2011-09-29 10:19:26 +04:00
|
|
|
bool wasChanged = PerformSelection(selectedIndex,
|
2002-01-26 02:35:44 +03:00
|
|
|
!isControl, isControl);
|
2013-08-09 02:04:59 +04:00
|
|
|
if (!weakFrame.IsAlive()) {
|
|
|
|
return NS_OK;
|
|
|
|
}
|
2002-01-26 02:35:44 +03:00
|
|
|
mChangesSinceDragStart = mChangesSinceDragStart || wasChanged;
|
2001-11-02 10:40:01 +03:00
|
|
|
}
|
1999-08-26 18:54:07 +04:00
|
|
|
}
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2007-05-17 15:12:30 +04:00
|
|
|
//----------------------------------------------------------------------
|
|
|
|
// Scroll helpers.
|
|
|
|
//----------------------------------------------------------------------
|
2013-08-02 11:08:13 +04:00
|
|
|
void
|
2012-08-22 19:56:38 +04:00
|
|
|
nsListControlFrame::ScrollToIndex(int32_t aIndex)
|
2001-11-02 10:40:01 +03:00
|
|
|
{
|
|
|
|
if (aIndex < 0) {
|
2004-09-13 06:10:29 +04:00
|
|
|
// XXX shouldn't we just do nothing if we're asked to scroll to
|
|
|
|
// kNothingSelected?
|
2013-08-02 11:08:13 +04:00
|
|
|
ScrollTo(nsPoint(0, 0), nsIScrollableFrame::INSTANT);
|
2001-11-02 10:40:01 +03:00
|
|
|
} else {
|
2013-08-02 11:08:13 +04:00
|
|
|
nsRefPtr<dom::HTMLOptionElement> option =
|
|
|
|
GetOption(SafeCast<uint32_t>(aIndex));
|
|
|
|
if (option) {
|
|
|
|
ScrollToFrame(*option);
|
2001-11-02 10:40:01 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-08-02 11:08:13 +04:00
|
|
|
void
|
|
|
|
nsListControlFrame::ScrollToFrame(dom::HTMLOptionElement& aOptElement)
|
1999-11-12 01:13:33 +03:00
|
|
|
{
|
2009-09-03 08:49:16 +04:00
|
|
|
// otherwise we find the content's frame and scroll to it
|
2013-08-02 11:08:13 +04:00
|
|
|
nsIFrame* childFrame = aOptElement.GetPrimaryFrame();
|
2009-09-03 08:49:16 +04:00
|
|
|
if (childFrame) {
|
2012-02-08 00:21:13 +04:00
|
|
|
PresContext()->PresShell()->
|
|
|
|
ScrollFrameRectIntoView(childFrame,
|
|
|
|
nsRect(nsPoint(0, 0), childFrame->GetSize()),
|
|
|
|
nsIPresShell::ScrollAxis(), nsIPresShell::ScrollAxis(),
|
|
|
|
nsIPresShell::SCROLL_OVERFLOW_HIDDEN |
|
|
|
|
nsIPresShell::SCROLL_FIRST_ANCESTOR_ONLY);
|
1999-11-12 01:13:33 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2000-08-18 01:38:15 +04:00
|
|
|
//---------------------------------------------------------------------
|
|
|
|
// Ok, the entire idea of this routine is to move to the next item that
|
|
|
|
// is suppose to be selected. If the item is disabled then we search in
|
|
|
|
// the same direction looking for the next item to select. If we run off
|
|
|
|
// the end of the list then we start at the end of the list and search
|
|
|
|
// backwards until we get back to the original item or an enabled option
|
|
|
|
//
|
2002-12-17 03:56:01 +03:00
|
|
|
// aStartIndex - the index to start searching from
|
|
|
|
// aNewIndex - will get set to the new index if it finds one
|
2000-08-18 01:38:15 +04:00
|
|
|
// aNumOptions - the total number of options in the list
|
|
|
|
// aDoAdjustInc - the initial increment 1-n
|
|
|
|
// aDoAdjustIncNext - the increment used to search for the next enabled option
|
2001-11-02 10:40:01 +03:00
|
|
|
//
|
|
|
|
// the aDoAdjustInc could be a "1" for a single item or
|
|
|
|
// any number greater representing a page of items
|
|
|
|
//
|
2000-08-18 01:38:15 +04:00
|
|
|
void
|
2012-08-22 19:56:38 +04:00
|
|
|
nsListControlFrame::AdjustIndexForDisabledOpt(int32_t aStartIndex,
|
|
|
|
int32_t &aNewIndex,
|
|
|
|
int32_t aNumOptions,
|
|
|
|
int32_t aDoAdjustInc,
|
|
|
|
int32_t aDoAdjustIncNext)
|
2000-08-18 01:38:15 +04:00
|
|
|
{
|
2002-12-17 03:56:01 +03:00
|
|
|
// Cannot select anything if there is nothing to select
|
|
|
|
if (aNumOptions == 0) {
|
|
|
|
aNewIndex = kNothingSelected;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2001-11-02 10:40:01 +03:00
|
|
|
// means we reached the end of the list and now we are searching backwards
|
2011-09-29 10:19:26 +04:00
|
|
|
bool doingReverse = false;
|
2001-11-02 10:40:01 +03:00
|
|
|
// lowest index in the search range
|
2012-08-22 19:56:38 +04:00
|
|
|
int32_t bottom = 0;
|
2001-11-02 10:40:01 +03:00
|
|
|
// highest index in the search range
|
2012-08-22 19:56:38 +04:00
|
|
|
int32_t top = aNumOptions;
|
2001-11-02 10:40:01 +03:00
|
|
|
|
|
|
|
// Start off keyboard options at selectedIndex if nothing else is defaulted to
|
2000-08-18 01:38:15 +04:00
|
|
|
//
|
2001-11-02 10:40:01 +03:00
|
|
|
// XXX Perhaps this should happen for mouse too, to start off shift click
|
|
|
|
// automatically in multiple ... to do this, we'd need to override
|
|
|
|
// OnOptionSelected and set mStartSelectedIndex if nothing is selected. Not
|
|
|
|
// sure of the effects, though, so I'm not doing it just yet.
|
2012-08-22 19:56:38 +04:00
|
|
|
int32_t startIndex = aStartIndex;
|
2001-11-02 10:40:01 +03:00
|
|
|
if (startIndex < bottom) {
|
2006-03-01 04:00:29 +03:00
|
|
|
startIndex = GetSelectedIndex();
|
2001-11-02 10:40:01 +03:00
|
|
|
}
|
2012-08-22 19:56:38 +04:00
|
|
|
int32_t newIndex = startIndex + aDoAdjustInc;
|
2000-08-18 01:38:15 +04:00
|
|
|
|
|
|
|
// make sure we start off in the range
|
|
|
|
if (newIndex < bottom) {
|
|
|
|
newIndex = 0;
|
|
|
|
} else if (newIndex >= top) {
|
2000-08-29 17:24:38 +04:00
|
|
|
newIndex = aNumOptions-1;
|
2000-08-18 01:38:15 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
while (1) {
|
|
|
|
// if the newIndex isn't disabled, we are golden, bail out
|
2011-09-29 10:19:26 +04:00
|
|
|
bool isDisabled = true;
|
2002-12-17 03:56:01 +03:00
|
|
|
if (NS_SUCCEEDED(IsOptionDisabled(newIndex, isDisabled)) && !isDisabled) {
|
2000-08-18 01:38:15 +04:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
// it WAS disabled, so sart looking ahead for the next enabled option
|
|
|
|
newIndex += aDoAdjustIncNext;
|
|
|
|
|
|
|
|
// well, if we reach end reverse the search
|
|
|
|
if (newIndex < bottom) {
|
|
|
|
if (doingReverse) {
|
|
|
|
return; // if we are in reverse mode and reach the end bail out
|
|
|
|
} else {
|
|
|
|
// reset the newIndex to the end of the list we hit
|
|
|
|
// reverse the incrementer
|
|
|
|
// set the other end of the list to our original starting index
|
|
|
|
newIndex = bottom;
|
2001-11-02 10:40:01 +03:00
|
|
|
aDoAdjustIncNext = 1;
|
2011-10-17 18:59:28 +04:00
|
|
|
doingReverse = true;
|
2001-11-02 10:40:01 +03:00
|
|
|
top = startIndex;
|
2000-08-18 01:38:15 +04:00
|
|
|
}
|
|
|
|
} else if (newIndex >= top) {
|
|
|
|
if (doingReverse) {
|
|
|
|
return; // if we are in reverse mode and reach the end bail out
|
|
|
|
} else {
|
|
|
|
// reset the newIndex to the end of the list we hit
|
|
|
|
// reverse the incrementer
|
|
|
|
// set the other end of the list to our original starting index
|
|
|
|
newIndex = top - 1;
|
2001-11-02 10:40:01 +03:00
|
|
|
aDoAdjustIncNext = -1;
|
2011-10-17 18:59:28 +04:00
|
|
|
doingReverse = true;
|
2001-11-02 10:40:01 +03:00
|
|
|
bottom = startIndex;
|
2000-08-18 01:38:15 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Looks like we found one
|
2002-12-17 03:56:01 +03:00
|
|
|
aNewIndex = newIndex;
|
2000-08-18 01:38:15 +04:00
|
|
|
}
|
|
|
|
|
2002-09-20 06:12:12 +04:00
|
|
|
nsAString&
|
|
|
|
nsListControlFrame::GetIncrementalString()
|
|
|
|
{
|
2012-07-30 18:20:58 +04:00
|
|
|
if (sIncrementalString == nullptr)
|
2009-08-09 02:00:26 +04:00
|
|
|
sIncrementalString = new nsString();
|
|
|
|
|
|
|
|
return *sIncrementalString;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsListControlFrame::Shutdown()
|
|
|
|
{
|
|
|
|
delete sIncrementalString;
|
2012-07-30 18:20:58 +04:00
|
|
|
sIncrementalString = nullptr;
|
2002-09-20 06:12:12 +04:00
|
|
|
}
|
|
|
|
|
2003-07-09 10:36:33 +04:00
|
|
|
void
|
|
|
|
nsListControlFrame::DropDownToggleKey(nsIDOMEvent* aKeyEvent)
|
|
|
|
{
|
2005-02-16 08:13:16 +03:00
|
|
|
// Cocoa widgets do native popups, so don't try to show
|
|
|
|
// dropdowns there.
|
|
|
|
if (IsInDropDownMode() && !nsComboboxControlFrame::ToolkitHasNativePopup()) {
|
2007-05-17 15:12:30 +04:00
|
|
|
aKeyEvent->PreventDefault();
|
2008-12-14 13:17:06 +03:00
|
|
|
if (!mComboboxFrame->IsDroppedDown()) {
|
2011-10-17 18:59:28 +04:00
|
|
|
mComboboxFrame->ShowDropDown(true);
|
2008-12-14 13:17:06 +03:00
|
|
|
} else {
|
|
|
|
nsWeakFrame weakFrame(this);
|
|
|
|
// mEndSelectionIndex is the last item that got selected.
|
|
|
|
ComboboxFinish(mEndSelectionIndex);
|
|
|
|
if (weakFrame.IsAlive()) {
|
|
|
|
FireOnChange();
|
|
|
|
}
|
|
|
|
}
|
2003-07-09 10:36:33 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
1999-08-27 18:42:27 +04:00
|
|
|
nsresult
|
2013-07-25 10:09:29 +04:00
|
|
|
nsListControlFrame::KeyDown(nsIDOMEvent* aKeyEvent)
|
1999-08-27 18:42:27 +04:00
|
|
|
{
|
2013-07-25 10:09:29 +04:00
|
|
|
MOZ_ASSERT(aKeyEvent, "aKeyEvent is null.");
|
2000-03-07 18:54:31 +03:00
|
|
|
|
2011-06-01 05:46:57 +04:00
|
|
|
nsEventStates eventStates = mContent->AsElement()->State();
|
2013-07-25 10:09:29 +04:00
|
|
|
if (eventStates.HasState(NS_EVENT_STATE_DISABLED)) {
|
1999-11-12 18:08:28 +03:00
|
|
|
return NS_OK;
|
2013-07-25 10:09:29 +04:00
|
|
|
}
|
1999-11-12 18:08:28 +03:00
|
|
|
|
2013-07-25 10:09:29 +04:00
|
|
|
// Don't check defaultPrevented value because other browsers don't prevent
|
|
|
|
// the key navigation of list control even if preventDefault() is called.
|
2000-12-20 18:15:28 +03:00
|
|
|
|
2013-10-01 11:22:58 +04:00
|
|
|
const WidgetKeyboardEvent* keyEvent =
|
|
|
|
static_cast<WidgetKeyboardEvent*>(aKeyEvent->GetInternalNSEvent());
|
2013-07-25 10:09:29 +04:00
|
|
|
MOZ_ASSERT(keyEvent, "DOM event must have internal event");
|
|
|
|
MOZ_ASSERT(keyEvent->eventStructType == NS_KEY_EVENT,
|
2013-10-01 11:22:58 +04:00
|
|
|
"The keydown event's internal event struct must be WidgetKeyboardEvent");
|
2002-12-17 03:56:01 +03:00
|
|
|
|
2013-07-25 10:09:29 +04:00
|
|
|
if (keyEvent->IsAlt()) {
|
|
|
|
if (keyEvent->keyCode == NS_VK_UP || keyEvent->keyCode == NS_VK_DOWN) {
|
2003-07-09 10:36:33 +04:00
|
|
|
DropDownToggleKey(aKeyEvent);
|
2002-01-10 07:23:13 +03:00
|
|
|
}
|
2002-12-17 03:56:01 +03:00
|
|
|
return NS_OK;
|
|
|
|
}
|
1999-09-30 15:37:58 +04:00
|
|
|
|
2002-12-17 03:56:01 +03:00
|
|
|
// now make sure there are options or we are wasting our time
|
2013-08-02 11:08:19 +04:00
|
|
|
nsRefPtr<dom::HTMLOptionsCollection> options = GetOptions();
|
2002-12-17 03:56:01 +03:00
|
|
|
NS_ENSURE_TRUE(options, NS_ERROR_FAILURE);
|
1999-08-27 18:42:27 +04:00
|
|
|
|
2013-08-02 11:08:19 +04:00
|
|
|
uint32_t numOptions = options->Length();
|
2001-12-06 09:57:03 +03:00
|
|
|
|
2001-11-02 10:40:01 +03:00
|
|
|
// this is the new index to set
|
2012-08-22 19:56:38 +04:00
|
|
|
int32_t newIndex = kNothingSelected;
|
2000-08-03 18:13:58 +04:00
|
|
|
|
2013-07-25 10:09:29 +04:00
|
|
|
bool isControlOrMeta = (keyEvent->IsControl() || keyEvent->IsMeta());
|
|
|
|
if (isControlOrMeta && (keyEvent->keyCode == NS_VK_UP ||
|
|
|
|
keyEvent->keyCode == NS_VK_LEFT ||
|
|
|
|
keyEvent->keyCode == NS_VK_DOWN ||
|
|
|
|
keyEvent->keyCode == NS_VK_RIGHT)) {
|
2005-07-14 18:20:21 +04:00
|
|
|
// Don't go into multiple select mode unless this list can handle it
|
2013-07-25 10:09:29 +04:00
|
|
|
isControlOrMeta = mControlSelectMode = GetMultiple();
|
|
|
|
} else if (keyEvent->keyCode != NS_VK_SPACE) {
|
2011-10-17 18:59:28 +04:00
|
|
|
mControlSelectMode = false;
|
2005-03-08 06:05:03 +03:00
|
|
|
}
|
2000-08-03 18:13:58 +04:00
|
|
|
|
2013-07-25 10:09:29 +04:00
|
|
|
switch (keyEvent->keyCode) {
|
|
|
|
case NS_VK_UP:
|
|
|
|
case NS_VK_LEFT:
|
2001-11-02 10:40:01 +03:00
|
|
|
AdjustIndexForDisabledOpt(mEndSelectionIndex, newIndex,
|
2013-07-25 10:09:29 +04:00
|
|
|
static_cast<int32_t>(numOptions),
|
2001-11-02 10:40:01 +03:00
|
|
|
-1, -1);
|
2013-07-25 10:09:29 +04:00
|
|
|
break;
|
|
|
|
case NS_VK_DOWN:
|
|
|
|
case NS_VK_RIGHT:
|
2001-11-02 10:40:01 +03:00
|
|
|
AdjustIndexForDisabledOpt(mEndSelectionIndex, newIndex,
|
2013-07-25 10:09:29 +04:00
|
|
|
static_cast<int32_t>(numOptions),
|
2001-11-02 10:40:01 +03:00
|
|
|
1, 1);
|
2013-07-25 10:09:29 +04:00
|
|
|
break;
|
|
|
|
case NS_VK_RETURN:
|
|
|
|
if (mComboboxFrame) {
|
2013-08-14 10:34:03 +04:00
|
|
|
nsWeakFrame weakFrame(this);
|
2006-02-18 04:52:03 +03:00
|
|
|
if (mComboboxFrame->IsDroppedDown()) {
|
2013-08-14 10:34:03 +04:00
|
|
|
// At closing dropdown, users may not expect there is additional
|
|
|
|
// behavior for this key event. Therefore, let's consume the event.
|
|
|
|
aKeyEvent->PreventDefault();
|
2002-01-26 02:35:44 +03:00
|
|
|
ComboboxFinish(mEndSelectionIndex);
|
2013-07-25 10:09:29 +04:00
|
|
|
if (!weakFrame.IsAlive()) {
|
2007-05-17 15:12:30 +04:00
|
|
|
return NS_OK;
|
2013-07-25 10:09:29 +04:00
|
|
|
}
|
2001-11-02 10:40:01 +03:00
|
|
|
}
|
2004-05-28 20:25:04 +04:00
|
|
|
FireOnChange();
|
2013-08-14 10:34:03 +04:00
|
|
|
if (!weakFrame.IsAlive()) {
|
|
|
|
// If the keydown event causes destroying this, fired keypress on
|
|
|
|
// another element may cause another action which may not be
|
|
|
|
// expected by the user.
|
|
|
|
aKeyEvent->PreventDefault();
|
|
|
|
}
|
2002-01-26 02:35:44 +03:00
|
|
|
return NS_OK;
|
2000-08-18 01:38:15 +04:00
|
|
|
}
|
2013-07-25 10:09:29 +04:00
|
|
|
newIndex = mEndSelectionIndex;
|
|
|
|
break;
|
|
|
|
case NS_VK_ESCAPE: {
|
2007-05-17 15:12:30 +04:00
|
|
|
nsWeakFrame weakFrame(this);
|
2013-08-14 10:34:03 +04:00
|
|
|
// XXX When the Escape keydown causes closing dropdown, it shouldn't
|
|
|
|
// cause any additonal actions. We should call preventDefault() here.
|
2004-05-28 20:25:04 +04:00
|
|
|
AboutToRollup();
|
2007-05-17 15:12:30 +04:00
|
|
|
if (!weakFrame.IsAlive()) {
|
2013-08-14 10:34:03 +04:00
|
|
|
// If the keydown event causes destroying this, fired keypress on
|
|
|
|
// another element may cause another action which may not be
|
|
|
|
// expected by the user.
|
|
|
|
aKeyEvent->PreventDefault();
|
2007-05-17 15:12:30 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
2013-07-25 10:09:29 +04:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
case NS_VK_PAGE_UP: {
|
|
|
|
int32_t itemsPerPage =
|
|
|
|
std::max(1, static_cast<int32_t>(mNumDisplayRows - 1));
|
2001-11-02 10:40:01 +03:00
|
|
|
AdjustIndexForDisabledOpt(mEndSelectionIndex, newIndex,
|
2013-07-25 10:09:29 +04:00
|
|
|
static_cast<int32_t>(numOptions),
|
|
|
|
-itemsPerPage, -1);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case NS_VK_PAGE_DOWN: {
|
|
|
|
int32_t itemsPerPage =
|
|
|
|
std::max(1, static_cast<int32_t>(mNumDisplayRows - 1));
|
2001-11-02 10:40:01 +03:00
|
|
|
AdjustIndexForDisabledOpt(mEndSelectionIndex, newIndex,
|
2013-07-25 10:09:29 +04:00
|
|
|
static_cast<int32_t>(numOptions),
|
|
|
|
itemsPerPage, 1);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case NS_VK_HOME:
|
2001-11-02 10:40:01 +03:00
|
|
|
AdjustIndexForDisabledOpt(0, newIndex,
|
2013-07-25 10:09:29 +04:00
|
|
|
static_cast<int32_t>(numOptions),
|
2001-11-02 10:40:01 +03:00
|
|
|
0, 1);
|
2013-07-25 10:09:29 +04:00
|
|
|
break;
|
|
|
|
case NS_VK_END:
|
|
|
|
AdjustIndexForDisabledOpt(static_cast<int32_t>(numOptions) - 1, newIndex,
|
|
|
|
static_cast<int32_t>(numOptions),
|
2001-11-02 10:40:01 +03:00
|
|
|
0, -1);
|
2013-07-25 10:09:29 +04:00
|
|
|
break;
|
2000-08-03 18:13:58 +04:00
|
|
|
|
2002-03-08 18:49:30 +03:00
|
|
|
#if defined(XP_WIN) || defined(XP_OS2)
|
2013-07-25 10:09:29 +04:00
|
|
|
case NS_VK_F4:
|
2003-07-09 10:36:33 +04:00
|
|
|
DropDownToggleKey(aKeyEvent);
|
|
|
|
return NS_OK;
|
2002-03-08 18:49:30 +03:00
|
|
|
#endif
|
|
|
|
|
2013-07-25 10:09:29 +04:00
|
|
|
default: // printable key will be handled by keypress event.
|
2002-04-05 08:34:02 +04:00
|
|
|
return NS_OK;
|
2013-07-25 10:09:29 +04:00
|
|
|
}
|
2002-04-05 08:34:02 +04:00
|
|
|
|
2013-07-25 10:09:29 +04:00
|
|
|
aKeyEvent->PreventDefault();
|
2013-07-19 18:32:51 +04:00
|
|
|
|
2013-07-25 10:09:29 +04:00
|
|
|
// Cancel incremental search if it's being performed.
|
|
|
|
GetIncrementalString().Truncate();
|
2013-07-19 18:32:51 +04:00
|
|
|
|
2013-07-25 10:09:29 +04:00
|
|
|
// Actually process the new index and let the selection code
|
|
|
|
// do the scrolling for us
|
|
|
|
PostHandleKeyEvent(newIndex, 0, keyEvent->IsShift(), isControlOrMeta);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
2002-01-10 07:23:13 +03:00
|
|
|
|
2013-07-25 10:09:29 +04:00
|
|
|
nsresult
|
|
|
|
nsListControlFrame::KeyPress(nsIDOMEvent* aKeyEvent)
|
|
|
|
{
|
|
|
|
MOZ_ASSERT(aKeyEvent, "aKeyEvent is null.");
|
2002-09-20 06:12:12 +04:00
|
|
|
|
2013-07-25 10:09:29 +04:00
|
|
|
nsEventStates eventStates = mContent->AsElement()->State();
|
|
|
|
if (eventStates.HasState(NS_EVENT_STATE_DISABLED)) {
|
|
|
|
return NS_OK;
|
|
|
|
}
|
2003-02-23 04:19:17 +03:00
|
|
|
|
2013-10-01 11:22:58 +04:00
|
|
|
const WidgetKeyboardEvent* keyEvent =
|
|
|
|
static_cast<WidgetKeyboardEvent*>(aKeyEvent->GetInternalNSEvent());
|
2013-07-25 10:09:29 +04:00
|
|
|
MOZ_ASSERT(keyEvent, "DOM event must have internal event");
|
|
|
|
MOZ_ASSERT(keyEvent->eventStructType == NS_KEY_EVENT,
|
2013-10-01 11:22:58 +04:00
|
|
|
"The keydown event's internal event struct must be WidgetKeyboardEvent");
|
2002-09-20 06:12:12 +04:00
|
|
|
|
2013-07-25 10:09:29 +04:00
|
|
|
// Select option with this as the first character
|
|
|
|
// XXX Not I18N compliant
|
2002-09-20 06:12:12 +04:00
|
|
|
|
2013-07-25 10:09:29 +04:00
|
|
|
// Don't do incremental search if the key event has already consumed.
|
|
|
|
if (keyEvent->mFlags.mDefaultPrevented) {
|
|
|
|
return NS_OK;
|
|
|
|
}
|
2013-03-22 21:52:52 +04:00
|
|
|
|
2013-07-25 10:09:29 +04:00
|
|
|
if (keyEvent->IsAlt()) {
|
|
|
|
return NS_OK;
|
|
|
|
}
|
2013-03-22 21:52:52 +04:00
|
|
|
|
2013-07-25 10:09:29 +04:00
|
|
|
// With some keyboard layout, space key causes non-ASCII space.
|
|
|
|
// So, the check in keydown event handler isn't enough, we need to check it
|
|
|
|
// again with keypress event.
|
|
|
|
if (keyEvent->charCode != ' ') {
|
|
|
|
mControlSelectMode = false;
|
|
|
|
}
|
2013-03-22 21:52:52 +04:00
|
|
|
|
2013-07-25 10:09:29 +04:00
|
|
|
bool isControlOrMeta = (keyEvent->IsControl() || keyEvent->IsMeta());
|
|
|
|
if (isControlOrMeta && keyEvent->charCode != ' ') {
|
|
|
|
return NS_OK;
|
|
|
|
}
|
2002-12-17 03:56:01 +03:00
|
|
|
|
2013-07-25 10:09:29 +04:00
|
|
|
// NOTE: If keyCode of keypress event is not 0, charCode is always 0.
|
|
|
|
// Therefore, all non-printable keys are not handled after this block.
|
|
|
|
if (!keyEvent->charCode) {
|
|
|
|
// Backspace key will delete the last char in the string
|
|
|
|
// XXX Backspace key causes "go back the history" on Windows. Shouldn't we
|
|
|
|
// prevent its default action if incremental search is used since
|
|
|
|
// getting focus? When I tested this, it worked accidentally.
|
|
|
|
if (keyEvent->keyCode == NS_VK_BACK && !GetIncrementalString().IsEmpty()) {
|
|
|
|
GetIncrementalString().Truncate(GetIncrementalString().Length() - 1);
|
|
|
|
aKeyEvent->PreventDefault();
|
|
|
|
}
|
|
|
|
return NS_OK;
|
|
|
|
}
|
2002-09-20 06:12:12 +04:00
|
|
|
|
2002-12-17 03:56:01 +03:00
|
|
|
// We ate the key if we got this far.
|
|
|
|
aKeyEvent->PreventDefault();
|
2002-10-30 04:05:43 +03:00
|
|
|
|
2013-07-25 10:09:29 +04:00
|
|
|
// XXX Why don't we check/modify timestamp first?
|
|
|
|
|
|
|
|
// Incremental Search: if time elapsed is below
|
|
|
|
// INCREMENTAL_SEARCH_KEYPRESS_TIME, append this keystroke to the search
|
|
|
|
// string we will use to find options and start searching at the current
|
|
|
|
// keystroke. Otherwise, Truncate the string if it's been a long time
|
|
|
|
// since our last keypress.
|
|
|
|
if (keyEvent->time - gLastKeyTime > INCREMENTAL_SEARCH_KEYPRESS_TIME) {
|
|
|
|
// If this is ' ' and we are at the beginning of the string, treat it as
|
|
|
|
// "select this option" (bug 191543)
|
|
|
|
if (keyEvent->charCode == ' ') {
|
|
|
|
// Actually process the new index and let the selection code
|
|
|
|
// do the scrolling for us
|
|
|
|
PostHandleKeyEvent(mEndSelectionIndex, keyEvent->charCode,
|
|
|
|
keyEvent->IsShift(), isControlOrMeta);
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2002-09-20 06:12:12 +04:00
|
|
|
GetIncrementalString().Truncate();
|
|
|
|
}
|
2002-12-17 03:56:01 +03:00
|
|
|
|
2013-07-25 10:09:29 +04:00
|
|
|
gLastKeyTime = keyEvent->time;
|
2011-09-28 05:46:11 +04:00
|
|
|
|
2013-07-25 10:09:29 +04:00
|
|
|
// Append this keystroke to the search string.
|
|
|
|
PRUnichar uniChar = ToLowerCase(static_cast<PRUnichar>(keyEvent->charCode));
|
|
|
|
GetIncrementalString().Append(uniChar);
|
|
|
|
|
|
|
|
// See bug 188199, if all letters in incremental string are same, just try to
|
|
|
|
// match the first one
|
|
|
|
nsAutoString incrementalString(GetIncrementalString());
|
|
|
|
uint32_t charIndex = 1, stringLength = incrementalString.Length();
|
|
|
|
while (charIndex < stringLength &&
|
|
|
|
incrementalString[charIndex] == incrementalString[charIndex - 1]) {
|
|
|
|
charIndex++;
|
|
|
|
}
|
|
|
|
if (charIndex == stringLength) {
|
|
|
|
incrementalString.Truncate(1);
|
|
|
|
stringLength = 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Determine where we're going to start reading the string
|
|
|
|
// If we have multiple characters to look for, we start looking *at* the
|
|
|
|
// current option. If we have only one character to look for, we start
|
|
|
|
// looking *after* the current option.
|
|
|
|
// Exception: if there is no option selected to start at, we always start
|
|
|
|
// *at* 0.
|
|
|
|
int32_t startIndex = GetSelectedIndex();
|
|
|
|
if (startIndex == kNothingSelected) {
|
|
|
|
startIndex = 0;
|
|
|
|
} else if (stringLength == 1) {
|
|
|
|
startIndex++;
|
|
|
|
}
|
|
|
|
|
|
|
|
// now make sure there are options or we are wasting our time
|
2013-08-02 11:08:19 +04:00
|
|
|
nsRefPtr<dom::HTMLOptionsCollection> options = GetOptions();
|
2013-07-25 10:09:29 +04:00
|
|
|
NS_ENSURE_TRUE(options, NS_ERROR_FAILURE);
|
|
|
|
|
2013-08-02 11:08:19 +04:00
|
|
|
uint32_t numOptions = options->Length();
|
2013-07-25 10:09:29 +04:00
|
|
|
|
2013-08-09 02:04:59 +04:00
|
|
|
nsWeakFrame weakFrame(this);
|
2013-07-25 10:09:29 +04:00
|
|
|
for (uint32_t i = 0; i < numOptions; ++i) {
|
|
|
|
uint32_t index = (i + startIndex) % numOptions;
|
2013-08-02 11:08:19 +04:00
|
|
|
nsRefPtr<dom::HTMLOptionElement> optionElement =
|
|
|
|
options->ItemAsOption(index);
|
2013-10-02 13:56:03 +04:00
|
|
|
if (!optionElement || !optionElement->GetPrimaryFrame()) {
|
2013-07-25 10:09:29 +04:00
|
|
|
continue;
|
2005-07-14 18:20:21 +04:00
|
|
|
}
|
2013-07-25 10:09:29 +04:00
|
|
|
|
|
|
|
nsAutoString text;
|
|
|
|
if (NS_FAILED(optionElement->GetText(text)) ||
|
|
|
|
!StringBeginsWith(
|
|
|
|
nsContentUtils::TrimWhitespace<
|
|
|
|
nsContentUtils::IsHTMLWhitespaceOrNBSP>(text, false),
|
|
|
|
incrementalString, nsCaseInsensitiveStringComparator())) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2013-08-09 02:04:59 +04:00
|
|
|
bool wasChanged = PerformSelection(index, keyEvent->IsShift(), isControlOrMeta);
|
|
|
|
if (!weakFrame.IsAlive()) {
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
if (!wasChanged) {
|
2013-07-25 10:09:29 +04:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
// If UpdateSelection() returns false, that means the frame is no longer
|
|
|
|
// alive. We should stop doing anything.
|
|
|
|
if (!UpdateSelection()) {
|
|
|
|
return NS_OK;
|
1999-08-27 18:42:27 +04:00
|
|
|
}
|
2013-07-25 10:09:29 +04:00
|
|
|
break;
|
1999-08-27 18:42:27 +04:00
|
|
|
}
|
2000-08-03 18:13:58 +04:00
|
|
|
|
1999-08-27 18:42:27 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
1999-08-06 18:14:38 +04:00
|
|
|
|
2013-07-25 10:09:29 +04:00
|
|
|
void
|
|
|
|
nsListControlFrame::PostHandleKeyEvent(int32_t aNewIndex,
|
|
|
|
uint32_t aCharCode,
|
|
|
|
bool aIsShift,
|
|
|
|
bool aIsControlOrMeta)
|
|
|
|
{
|
|
|
|
if (aNewIndex == kNothingSelected) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// If you hold control, but not shift, no key will actually do anything
|
|
|
|
// except space.
|
2013-08-09 02:04:59 +04:00
|
|
|
nsWeakFrame weakFrame(this);
|
2013-07-25 10:09:29 +04:00
|
|
|
bool wasChanged = false;
|
|
|
|
if (aIsControlOrMeta && !aIsShift && aCharCode != ' ') {
|
|
|
|
mStartSelectionIndex = aNewIndex;
|
|
|
|
mEndSelectionIndex = aNewIndex;
|
|
|
|
InvalidateFocus();
|
|
|
|
ScrollToIndex(aNewIndex);
|
2013-08-09 02:04:59 +04:00
|
|
|
if (!weakFrame.IsAlive()) {
|
|
|
|
return;
|
|
|
|
}
|
2013-07-25 10:09:29 +04:00
|
|
|
|
|
|
|
#ifdef ACCESSIBILITY
|
|
|
|
FireMenuItemActiveEvent();
|
|
|
|
#endif
|
|
|
|
} else if (mControlSelectMode && aCharCode == ' ') {
|
|
|
|
wasChanged = SingleSelection(aNewIndex, true);
|
|
|
|
} else {
|
|
|
|
wasChanged = PerformSelection(aNewIndex, aIsShift, aIsControlOrMeta);
|
|
|
|
}
|
2013-08-09 02:04:59 +04:00
|
|
|
if (wasChanged && weakFrame.IsAlive()) {
|
2013-07-25 10:09:29 +04:00
|
|
|
// dispatch event, update combobox, etc.
|
|
|
|
UpdateSelection();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2000-08-14 18:42:12 +04:00
|
|
|
|
2004-01-10 01:18:26 +03:00
|
|
|
/******************************************************************************
|
2000-08-14 18:42:12 +04:00
|
|
|
* nsListEventListener
|
2004-01-10 01:18:26 +03:00
|
|
|
*****************************************************************************/
|
2000-08-14 18:42:12 +04:00
|
|
|
|
2011-06-29 22:07:25 +04:00
|
|
|
NS_IMPL_ISUPPORTS1(nsListEventListener, nsIDOMEventListener)
|
2000-08-14 18:42:12 +04:00
|
|
|
|
2011-06-29 22:07:25 +04:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsListEventListener::HandleEvent(nsIDOMEvent* aEvent)
|
|
|
|
{
|
|
|
|
if (!mFrame)
|
|
|
|
return NS_OK;
|
2000-08-14 18:42:12 +04:00
|
|
|
|
2011-06-29 22:07:25 +04:00
|
|
|
nsAutoString eventType;
|
|
|
|
aEvent->GetType(eventType);
|
2013-07-25 10:09:29 +04:00
|
|
|
if (eventType.EqualsLiteral("keydown"))
|
|
|
|
return mFrame->nsListControlFrame::KeyDown(aEvent);
|
2011-06-29 22:07:25 +04:00
|
|
|
if (eventType.EqualsLiteral("keypress"))
|
|
|
|
return mFrame->nsListControlFrame::KeyPress(aEvent);
|
|
|
|
if (eventType.EqualsLiteral("mousedown"))
|
|
|
|
return mFrame->nsListControlFrame::MouseDown(aEvent);
|
|
|
|
if (eventType.EqualsLiteral("mouseup"))
|
|
|
|
return mFrame->nsListControlFrame::MouseUp(aEvent);
|
|
|
|
if (eventType.EqualsLiteral("mousemove"))
|
|
|
|
return mFrame->nsListControlFrame::MouseMove(aEvent);
|
|
|
|
|
|
|
|
NS_ABORT();
|
|
|
|
return NS_OK;
|
|
|
|
}
|