2007-03-22 10:30:00 -07:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
2012-05-21 04:12:37 -07: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/. */
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
#include "nscore.h"
|
|
|
|
#include "nsCOMPtr.h"
|
|
|
|
#include "nsUnicharUtils.h"
|
|
|
|
#include "nsListControlFrame.h"
|
|
|
|
#include "nsFormControlFrame.h" // for COMPARE macro
|
|
|
|
#include "nsGkAtoms.h"
|
2010-07-28 16:43:52 -07:00
|
|
|
#include "nsIDOMHTMLSelectElement.h"
|
2011-04-16 18:22:41 -07:00
|
|
|
#include "nsIDOMHTMLOptionElement.h"
|
2007-03-22 10:30:00 -07:00
|
|
|
#include "nsComboboxControlFrame.h"
|
|
|
|
#include "nsIDOMHTMLOptGroupElement.h"
|
|
|
|
#include "nsIPresShell.h"
|
|
|
|
#include "nsIDOMMouseEvent.h"
|
2013-12-12 14:13:20 -08:00
|
|
|
#include "nsIXULRuntime.h"
|
2011-04-07 18:05:49 -07:00
|
|
|
#include "nsFontMetrics.h"
|
2007-03-22 10:30:00 -07:00
|
|
|
#include "nsIScrollableFrame.h"
|
|
|
|
#include "nsCSSRendering.h"
|
2011-06-29 11:07:25 -07:00
|
|
|
#include "nsIDOMEventListener.h"
|
2007-03-22 10:30:00 -07:00
|
|
|
#include "nsLayoutUtils.h"
|
|
|
|
#include "nsDisplayList.h"
|
2011-08-11 06:29:50 -07:00
|
|
|
#include "nsContentUtils.h"
|
2012-06-18 20:26:34 -07:00
|
|
|
#include "mozilla/Attributes.h"
|
2013-08-02 00:08:19 -07:00
|
|
|
#include "mozilla/dom/HTMLOptionsCollection.h"
|
2013-04-04 00:03:33 -07:00
|
|
|
#include "mozilla/dom/HTMLSelectElement.h"
|
2014-03-31 21:09:23 -07:00
|
|
|
#include "mozilla/EventStateManager.h"
|
2014-04-02 21:18:36 -07:00
|
|
|
#include "mozilla/EventStates.h"
|
2013-04-04 00:03:33 -07:00
|
|
|
#include "mozilla/LookAndFeel.h"
|
2013-09-25 04:21:18 -07:00
|
|
|
#include "mozilla/MouseEvents.h"
|
2013-08-25 18:34:23 -07:00
|
|
|
#include "mozilla/Preferences.h"
|
2013-09-25 04:21:19 -07:00
|
|
|
#include "mozilla/TextEvents.h"
|
2013-01-15 04:22:03 -08:00
|
|
|
#include <algorithm>
|
2011-09-08 19:27:13 -07:00
|
|
|
|
|
|
|
using namespace mozilla;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
// Constants
|
2012-10-09 22:00:05 -07:00
|
|
|
const uint32_t kMaxDropDownRows = 20; // This matches the setting for 4.x browsers
|
2012-08-22 08:56:38 -07:00
|
|
|
const int32_t kNothingSelected = -1;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2009-08-08 15:00:26 -07:00
|
|
|
// Static members
|
2012-07-30 07:20:58 -07:00
|
|
|
nsListControlFrame * nsListControlFrame::mFocused = nullptr;
|
|
|
|
nsString * nsListControlFrame::sIncrementalString = nullptr;
|
2007-03-22 10:30:00 -07: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.
|
|
|
|
|
|
|
|
DOMTimeStamp nsListControlFrame::gLastKeyTime = 0;
|
|
|
|
|
|
|
|
/******************************************************************************
|
|
|
|
* 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-18 20:26:34 -07:00
|
|
|
class nsListEventListener MOZ_FINAL : public nsIDOMEventListener
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
public:
|
2014-08-31 20:36:37 -07:00
|
|
|
explicit nsListEventListener(nsListControlFrame *aFrame)
|
2007-03-22 10:30:00 -07:00
|
|
|
: mFrame(aFrame) { }
|
|
|
|
|
|
|
|
void SetFrame(nsListControlFrame *aFrame) { mFrame = aFrame; }
|
|
|
|
|
|
|
|
NS_DECL_ISUPPORTS
|
2011-06-29 11:07:25 -07:00
|
|
|
NS_DECL_NSIDOMEVENTLISTENER
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
private:
|
2014-06-23 15:40:01 -07:00
|
|
|
~nsListEventListener() {}
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
nsListControlFrame *mFrame;
|
|
|
|
};
|
|
|
|
|
|
|
|
//---------------------------------------------------------
|
2014-05-24 15:20:40 -07:00
|
|
|
nsContainerFrame*
|
2007-03-22 10:30:00 -07:00
|
|
|
NS_NewListControlFrame(nsIPresShell* aPresShell, nsStyleContext* aContext)
|
|
|
|
{
|
|
|
|
nsListControlFrame* it =
|
|
|
|
new (aPresShell) nsListControlFrame(aPresShell, aPresShell->GetDocument(), aContext);
|
|
|
|
|
2013-08-02 21:11:06 -07:00
|
|
|
it->AddStateBits(NS_FRAME_INDEPENDENT_SELECTION);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
return it;
|
|
|
|
}
|
|
|
|
|
2009-09-12 09:49:24 -07:00
|
|
|
NS_IMPL_FRAMEARENA_HELPERS(nsListControlFrame)
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
//---------------------------------------------------------
|
|
|
|
nsListControlFrame::nsListControlFrame(
|
|
|
|
nsIPresShell* aShell, nsIDocument* aDocument, nsStyleContext* aContext)
|
2011-10-17 07:59:28 -07:00
|
|
|
: nsHTMLScrollFrame(aShell, aContext, false),
|
|
|
|
mMightNeedSecondPass(false),
|
|
|
|
mHasPendingInterruptAtStartOfReflow(false),
|
2012-06-22 18:13:56 -07:00
|
|
|
mDropdownCanGrow(false),
|
2007-03-22 10:30:00 -07:00
|
|
|
mLastDropdownComputedHeight(NS_UNCONSTRAINEDSIZE)
|
|
|
|
{
|
2012-07-30 07:20:58 -07:00
|
|
|
mComboboxFrame = nullptr;
|
2011-10-17 07:59:28 -07:00
|
|
|
mChangesSinceDragStart = false;
|
|
|
|
mButtonDown = false;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2011-10-17 07:59:28 -07:00
|
|
|
mIsAllContentHere = false;
|
|
|
|
mIsAllFramesHere = false;
|
|
|
|
mHasBeenInitialized = false;
|
|
|
|
mNeedToReset = true;
|
|
|
|
mPostChildrenLoadedReset = false;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2011-10-17 07:59:28 -07:00
|
|
|
mControlSelectMode = false;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------
|
|
|
|
nsListControlFrame::~nsListControlFrame()
|
|
|
|
{
|
2012-07-30 07:20:58 -07:00
|
|
|
mComboboxFrame = nullptr;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
// for Bug 47302 (remove this comment later)
|
|
|
|
void
|
2009-12-23 21:21:15 -08:00
|
|
|
nsListControlFrame::DestroyFrom(nsIFrame* aDestructRoot)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
// get the receiver interface from the browser button's content node
|
2007-05-14 02:11:38 -07:00
|
|
|
ENSURE_TRUE(mContent);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
// Clear the frame pointer on our event listener, just in case the
|
|
|
|
// event listener can outlive the frame.
|
|
|
|
|
2012-07-30 07:20:58 -07:00
|
|
|
mEventListener->SetFrame(nullptr);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2013-07-24 23:09:29 -07:00
|
|
|
mContent->RemoveSystemEventListener(NS_LITERAL_STRING("keydown"),
|
|
|
|
mEventListener, false);
|
2013-07-19 07:32:51 -07: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);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2011-10-17 07:59:28 -07:00
|
|
|
nsFormControlFrame::RegUnRegAccessKey(static_cast<nsIFrame*>(this), false);
|
2009-12-23 21:21:15 -08:00
|
|
|
nsHTMLScrollFrame::DestroyFrom(aDestructRoot);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2013-02-14 03:12:27 -08:00
|
|
|
void
|
2007-03-22 10:30:00 -07:00
|
|
|
nsListControlFrame::BuildDisplayList(nsDisplayListBuilder* aBuilder,
|
|
|
|
const nsRect& aDirtyRect,
|
|
|
|
const nsDisplayListSet& aLists)
|
|
|
|
{
|
|
|
|
// We allow visibility:hidden <select>s to contain visible options.
|
|
|
|
|
|
|
|
// Don't allow painting of list controls when painting is suppressed.
|
|
|
|
// 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 03:12:27 -08:00
|
|
|
return;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
DO_GLOBAL_REFLOW_COUNT_DSP("nsListControlFrame");
|
|
|
|
|
2009-08-25 12:07:57 -07:00
|
|
|
if (IsInDropDownMode()) {
|
2009-09-01 19:46:47 -07:00
|
|
|
NS_ASSERTION(NS_GET_A(mLastDropdownBackstopColor) == 255,
|
|
|
|
"need an opaque backstop color");
|
2009-08-25 12:07:57 -07: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 03:01:13 -07:00
|
|
|
new (aBuilder) nsDisplaySolidColor(aBuilder,
|
2009-08-25 12:07:57 -07:00
|
|
|
this, nsRect(aBuilder->ToReferenceFrame(this), GetSize()),
|
|
|
|
mLastDropdownBackstopColor));
|
|
|
|
}
|
|
|
|
|
2013-02-14 03:12:27 -08:00
|
|
|
nsHTMLScrollFrame::BuildDisplayList(aBuilder, aDirtyRect, aLists);
|
2007-03-22 10:30:00 -07: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-07 18:04:40 -07:00
|
|
|
void nsListControlFrame::PaintFocus(nsRenderingContext& aRC, nsPoint aPt)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
if (mFocused != this) return;
|
|
|
|
|
2007-03-30 14:11:41 -07:00
|
|
|
nsPresContext* presContext = PresContext();
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
nsIFrame* containerFrame = GetOptionsContainer();
|
|
|
|
if (!containerFrame) return;
|
|
|
|
|
2012-07-30 07:20:58 -07:00
|
|
|
nsIFrame* childframe = nullptr;
|
2011-09-27 18:46:11 -07:00
|
|
|
nsCOMPtr<nsIContent> focusedContent = GetCurrentOption();
|
|
|
|
if (focusedContent) {
|
|
|
|
childframe = focusedContent->GetPrimaryFrame();
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
nsRect fRect;
|
|
|
|
if (childframe) {
|
|
|
|
// get the child rect
|
|
|
|
fRect = childframe->GetRect();
|
|
|
|
// get it into our coordinates
|
|
|
|
fRect.MoveBy(childframe->GetParent()->GetOffsetTo(this));
|
|
|
|
} else {
|
2012-05-20 22:18:28 -07:00
|
|
|
float inflation = nsLayoutUtils::FontSizeInflationFor(this);
|
2007-03-22 10:30:00 -07:00
|
|
|
fRect.x = fRect.y = 0;
|
2009-10-07 20:01:15 -07:00
|
|
|
fRect.width = GetScrollPortRect().width;
|
2011-11-23 18:48:23 -08:00
|
|
|
fRect.height = CalcFallbackRowHeight(inflation);
|
2007-03-22 10:30:00 -07:00
|
|
|
fRect.MoveBy(containerFrame->GetOffsetTo(this));
|
|
|
|
}
|
|
|
|
fRect += aPt;
|
|
|
|
|
2011-09-28 23:19:26 -07:00
|
|
|
bool lastItemIsSelected = false;
|
2007-03-22 10:30:00 -07:00
|
|
|
if (focusedContent) {
|
|
|
|
nsCOMPtr<nsIDOMHTMLOptionElement> domOpt =
|
|
|
|
do_QueryInterface(focusedContent);
|
|
|
|
if (domOpt) {
|
|
|
|
domOpt->GetSelected(&lastItemIsSelected);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// set up back stop colors and then ask L&F service for the real colors
|
2011-09-08 19:27:13 -07:00
|
|
|
nscolor color =
|
|
|
|
LookAndFeel::GetColor(lastItemIsSelected ?
|
|
|
|
LookAndFeel::eColorID_WidgetSelectForeground :
|
|
|
|
LookAndFeel::eColorID_WidgetSelectBackground);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2008-08-06 03:33:18 -07:00
|
|
|
nsCSSRendering::PaintFocus(presContext, aRC, fRect, color);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2007-09-27 16:06:31 -07:00
|
|
|
void
|
2012-05-20 22:18:28 -07:00
|
|
|
nsListControlFrame::InvalidateFocus()
|
2007-09-27 16:06:31 -07:00
|
|
|
{
|
|
|
|
if (mFocused != this)
|
|
|
|
return;
|
|
|
|
|
|
|
|
nsIFrame* containerFrame = GetOptionsContainer();
|
|
|
|
if (containerFrame) {
|
2012-08-28 22:39:31 -07:00
|
|
|
containerFrame->InvalidateFrame();
|
2007-09-27 16:06:31 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-01-12 11:20:59 -08:00
|
|
|
NS_QUERYFRAME_HEAD(nsListControlFrame)
|
|
|
|
NS_QUERYFRAME_ENTRY(nsIFormControlFrame)
|
|
|
|
NS_QUERYFRAME_ENTRY(nsIListControlFrame)
|
|
|
|
NS_QUERYFRAME_ENTRY(nsISelectControlFrame)
|
|
|
|
NS_QUERYFRAME_TAIL_INHERITING(nsHTMLScrollFrame)
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
#ifdef ACCESSIBILITY
|
2012-09-28 14:53:44 -07:00
|
|
|
a11y::AccType
|
|
|
|
nsListControlFrame::AccessibleType()
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2012-12-17 17:25:52 -08:00
|
|
|
return a11y::eHTMLSelectListType;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
static nscoord
|
|
|
|
GetMaxOptionHeight(nsIFrame* aContainer)
|
|
|
|
{
|
|
|
|
nscoord result = 0;
|
2011-08-24 13:54:30 -07:00
|
|
|
for (nsIFrame* option = aContainer->GetFirstPrincipalChild();
|
2007-03-22 10:30:00 -07:00
|
|
|
option; option = option->GetNextSibling()) {
|
|
|
|
nscoord optionHeight;
|
|
|
|
if (nsCOMPtr<nsIDOMHTMLOptGroupElement>
|
|
|
|
(do_QueryInterface(option->GetContent()))) {
|
|
|
|
// an optgroup
|
|
|
|
optionHeight = GetMaxOptionHeight(option);
|
|
|
|
} else {
|
|
|
|
// an option
|
|
|
|
optionHeight = option->GetSize().height;
|
|
|
|
}
|
|
|
|
if (result < optionHeight)
|
|
|
|
result = optionHeight;
|
|
|
|
}
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
//-----------------------------------------------------------------
|
|
|
|
// Main Reflow for ListBox/Dropdown
|
|
|
|
//-----------------------------------------------------------------
|
|
|
|
|
|
|
|
nscoord
|
2012-01-24 17:21:29 -08:00
|
|
|
nsListControlFrame::CalcHeightOfARow()
|
2007-03-22 10:30:00 -07: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 08:56:38 -07:00
|
|
|
int32_t heightOfARow = GetMaxOptionHeight(GetOptionsContainer());
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2008-12-04 08:09:53 -08:00
|
|
|
// Check to see if we have zero items (and optimize by checking
|
|
|
|
// heightOfARow first)
|
|
|
|
if (heightOfARow == 0 && GetNumberOfOptions() == 0) {
|
2012-05-20 22:18:28 -07:00
|
|
|
float inflation = nsLayoutUtils::FontSizeInflationFor(this);
|
2011-11-23 18:48:23 -08:00
|
|
|
heightOfARow = CalcFallbackRowHeight(inflation);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
return heightOfARow;
|
|
|
|
}
|
|
|
|
|
2008-02-28 12:37:06 -08:00
|
|
|
nscoord
|
2014-07-24 10:03:25 -07:00
|
|
|
nsListControlFrame::GetPrefISize(nsRenderingContext *aRenderingContext)
|
2008-02-28 12:37:06 -08: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.
|
2014-07-24 10:03:25 -07:00
|
|
|
result = GetScrolledFrame()->GetPrefISize(aRenderingContext);
|
2008-04-09 21:39:41 -07:00
|
|
|
result = NSCoordSaturatingAdd(result,
|
|
|
|
GetDesiredScrollbarSizes(PresContext(), aRenderingContext).LeftRight());
|
2008-02-28 12:37:06 -08:00
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
nscoord
|
2014-07-24 10:03:25 -07:00
|
|
|
nsListControlFrame::GetMinISize(nsRenderingContext *aRenderingContext)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
nscoord result;
|
|
|
|
DISPLAY_MIN_WIDTH(this, result);
|
|
|
|
|
2008-02-28 12:37:06 -08: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.
|
2014-07-24 10:03:25 -07:00
|
|
|
result = GetScrolledFrame()->GetMinISize(aRenderingContext);
|
2008-04-09 21:39:41 -07:00
|
|
|
result += GetDesiredScrollbarSizes(PresContext(), aRenderingContext).LeftRight();
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2014-05-12 17:47:52 -07:00
|
|
|
void
|
2007-03-22 10:30:00 -07:00
|
|
|
nsListControlFrame::Reflow(nsPresContext* aPresContext,
|
|
|
|
nsHTMLReflowMetrics& aDesiredSize,
|
|
|
|
const nsHTMLReflowState& aReflowState,
|
|
|
|
nsReflowStatus& aStatus)
|
|
|
|
{
|
|
|
|
NS_PRECONDITION(aReflowState.ComputedWidth() != NS_UNCONSTRAINEDSIZE,
|
|
|
|
"Must have a computed width");
|
|
|
|
|
2012-10-24 16:04:41 -07:00
|
|
|
SchedulePaint();
|
|
|
|
|
2009-09-04 14:07:38 -07:00
|
|
|
mHasPendingInterruptAtStartOfReflow = aPresContext->HasPendingInterrupt();
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
// If all the content and frames are here
|
|
|
|
// then initialize it before reflow
|
|
|
|
if (mIsAllContentHere && !mHasBeenInitialized) {
|
2011-10-17 07:59:28 -07:00
|
|
|
if (false == mIsAllFramesHere) {
|
2007-03-22 10:30:00 -07:00
|
|
|
CheckIfAllFramesHere();
|
|
|
|
}
|
|
|
|
if (mIsAllFramesHere && !mHasBeenInitialized) {
|
2011-10-17 07:59:28 -07:00
|
|
|
mHasBeenInitialized = true;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (GetStateBits() & NS_FRAME_FIRST_REFLOW) {
|
2011-10-17 07:59:28 -07:00
|
|
|
nsFormControlFrame::RegUnRegAccessKey(this, true);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
if (IsInDropDownMode()) {
|
2014-05-12 17:47:52 -07:00
|
|
|
ReflowAsDropdown(aPresContext, aDesiredSize, aReflowState, aStatus);
|
|
|
|
return;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* 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-02 15:02:25 -07: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.
|
2007-03-22 10:30:00 -07: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-28 23:19:26 -07:00
|
|
|
bool autoHeight = (aReflowState.ComputedHeight() == NS_UNCONSTRAINEDSIZE);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2007-08-02 15:02:25 -07:00
|
|
|
mMightNeedSecondPass = autoHeight &&
|
|
|
|
(NS_SUBTREE_DIRTY(this) || aReflowState.ShouldReflowAllKids());
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
nsHTMLReflowState state(aReflowState);
|
2012-10-31 15:00:36 -07:00
|
|
|
int32_t length = GetNumberOfRows();
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
nscoord oldHeightOfARow = HeightOfARow();
|
2010-05-05 11:18:04 -07:00
|
|
|
|
2007-03-22 10:30:00 -07: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.
|
2014-07-24 10:03:26 -07:00
|
|
|
nscoord computedHeight = CalcIntrinsicBSize(oldHeightOfARow, length);
|
2012-07-18 07:26:05 -07:00
|
|
|
computedHeight = state.ApplyMinMaxHeight(computedHeight);
|
2007-08-02 11:08:05 -07:00
|
|
|
state.SetComputedHeight(computedHeight);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2014-05-12 17:47:52 -07:00
|
|
|
nsHTMLScrollFrame::Reflow(aPresContext, aDesiredSize, state, aStatus);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
if (!mMightNeedSecondPass) {
|
|
|
|
NS_ASSERTION(!autoHeight || HeightOfARow() == oldHeightOfARow,
|
|
|
|
"How did our height of a row change if nothing was dirty?");
|
2010-05-05 11:18:04 -07:00
|
|
|
NS_ASSERTION(!autoHeight ||
|
|
|
|
!(GetStateBits() & NS_FRAME_FIRST_REFLOW),
|
|
|
|
"How do we not need a second pass during initial reflow at "
|
|
|
|
"auto height?");
|
2007-03-22 10:30:00 -07:00
|
|
|
NS_ASSERTION(!IsScrollbarUpdateSuppressed(),
|
|
|
|
"Shouldn't be suppressing if we don't need a second pass!");
|
2010-05-05 11:18:04 -07: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
|
2014-07-24 10:03:26 -07:00
|
|
|
// already set mNumDisplayRows in CalcIntrinsicBSize. Also note that we
|
2010-05-05 11:18:04 -07:00
|
|
|
// can't use HeightOfARow() here because that just uses a cached value
|
|
|
|
// that we didn't compute.
|
2012-01-24 17:21:29 -08:00
|
|
|
nscoord rowHeight = CalcHeightOfARow();
|
2010-05-05 11:18:04 -07:00
|
|
|
if (rowHeight == 0) {
|
|
|
|
// Just pick something
|
|
|
|
mNumDisplayRows = 1;
|
|
|
|
} else {
|
2013-01-15 04:22:03 -08:00
|
|
|
mNumDisplayRows = std::max(1, state.ComputedHeight() / rowHeight);
|
2010-05-05 11:18:04 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-05-12 17:47:52 -07:00
|
|
|
return;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2011-10-17 07:59:28 -07:00
|
|
|
mMightNeedSecondPass = false;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
// Now see whether we need a second pass. If we do, our nsSelectsAreaFrame
|
|
|
|
// will have suppressed the scrollbar update.
|
|
|
|
if (!IsScrollbarUpdateSuppressed()) {
|
|
|
|
// All done. No need to do more reflow.
|
|
|
|
NS_ASSERTION(!IsScrollbarUpdateSuppressed(),
|
|
|
|
"Shouldn't be suppressing if the height of a row has not "
|
|
|
|
"changed!");
|
2014-05-12 17:47:52 -07:00
|
|
|
return;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2011-10-17 07:59:28 -07:00
|
|
|
SetSuppressScrollbarUpdate(false);
|
2007-03-22 10:30:00 -07: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-08 17:27:48 -08:00
|
|
|
nsHTMLScrollFrame::DidReflow(aPresContext, &state,
|
2012-11-13 22:47:33 -08:00
|
|
|
nsDidReflowStatus::FINISHED);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
// Now compute the height we want to have
|
2014-07-24 10:03:26 -07:00
|
|
|
nscoord computedHeight = CalcIntrinsicBSize(HeightOfARow(), length);
|
2012-07-18 07:26:05 -07:00
|
|
|
computedHeight = state.ApplyMinMaxHeight(computedHeight);
|
2007-08-02 11:08:05 -07:00
|
|
|
state.SetComputedHeight(computedHeight);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
nsHTMLScrollFrame::WillReflow(aPresContext);
|
|
|
|
|
|
|
|
// 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....
|
2014-05-12 17:47:52 -07:00
|
|
|
nsHTMLScrollFrame::Reflow(aPresContext, aDesiredSize, state, aStatus);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2014-05-12 17:47:52 -07:00
|
|
|
void
|
2007-03-22 10:30:00 -07:00
|
|
|
nsListControlFrame::ReflowAsDropdown(nsPresContext* aPresContext,
|
|
|
|
nsHTMLReflowMetrics& aDesiredSize,
|
|
|
|
const nsHTMLReflowState& aReflowState,
|
|
|
|
nsReflowStatus& aStatus)
|
|
|
|
{
|
2007-08-02 11:08:05 -07:00
|
|
|
NS_PRECONDITION(aReflowState.ComputedHeight() == NS_UNCONSTRAINEDSIZE,
|
2007-03-22 10:30:00 -07:00
|
|
|
"We should not have a computed height here!");
|
|
|
|
|
2007-08-02 15:02:25 -07:00
|
|
|
mMightNeedSecondPass = NS_SUBTREE_DIRTY(this) ||
|
|
|
|
aReflowState.ShouldReflowAllKids();
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2008-09-20 06:42:03 -07:00
|
|
|
#ifdef DEBUG
|
2007-03-22 10:30:00 -07:00
|
|
|
nscoord oldHeightOfARow = HeightOfARow();
|
2012-06-22 18:13:56 -07:00
|
|
|
nscoord oldVisibleHeight = (GetStateBits() & NS_FRAME_FIRST_REFLOW) ?
|
|
|
|
NS_UNCONSTRAINEDSIZE : GetScrolledFrame()->GetSize().height;
|
2008-09-20 06:42:03 -07:00
|
|
|
#endif
|
2007-03-22 10:30:00 -07: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 11:08:05 -07:00
|
|
|
state.SetComputedHeight(mLastDropdownComputedHeight);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2014-05-12 17:47:52 -07:00
|
|
|
nsHTMLScrollFrame::Reflow(aPresContext, aDesiredSize, state, aStatus);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
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?");
|
2014-05-12 17:47:52 -07:00
|
|
|
return;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2011-10-17 07:59:28 -07:00
|
|
|
mMightNeedSecondPass = false;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
// Now see whether we need a second pass. If we do, our nsSelectsAreaFrame
|
|
|
|
// will have suppressed the scrollbar update.
|
|
|
|
if (!IsScrollbarUpdateSuppressed()) {
|
|
|
|
// 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?");
|
2014-05-12 17:47:52 -07:00
|
|
|
return;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2011-10-17 07:59:28 -07:00
|
|
|
SetSuppressScrollbarUpdate(false);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
nscoord visibleHeight = GetScrolledFrame()->GetSize().height;
|
|
|
|
nscoord heightOfARow = HeightOfARow();
|
|
|
|
|
|
|
|
// 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-08 17:27:48 -08:00
|
|
|
nsHTMLScrollFrame::DidReflow(aPresContext, &state,
|
2012-11-13 22:47:33 -08:00
|
|
|
nsDidReflowStatus::FINISHED);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2012-06-22 18:13:56 -07: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.
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2012-06-22 18:13:56 -07:00
|
|
|
mDropdownCanGrow = false;
|
|
|
|
if (visibleHeight <= 0 || heightOfARow <= 0) {
|
2007-03-22 10:30:00 -07:00
|
|
|
// Looks like we have no options. Just size us to a single row height.
|
2007-08-02 11:08:05 -07:00
|
|
|
state.SetComputedHeight(heightOfARow);
|
2012-06-22 18:13:56 -07:00
|
|
|
mNumDisplayRows = 1;
|
2007-03-22 10:30:00 -07:00
|
|
|
} else {
|
2012-06-22 18:13:56 -07: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-10-31 15:00:36 -07:00
|
|
|
mDropdownCanGrow = GetNumberOfRows() > 1;
|
2012-06-22 18:13:56 -07:00
|
|
|
} else {
|
2013-12-27 09:59:21 -08:00
|
|
|
nscoord bp = aReflowState.ComputedPhysicalBorderPadding().TopBottom();
|
2013-01-15 04:22:03 -08:00
|
|
|
nscoord availableHeight = std::max(above, below) - bp;
|
2012-06-22 18:13:56 -07:00
|
|
|
nscoord newHeight;
|
2012-10-09 22:00:05 -07:00
|
|
|
uint32_t rows;
|
2012-06-22 18:13:56 -07:00
|
|
|
if (visibleHeight <= availableHeight) {
|
|
|
|
// The dropdown fits in the available height.
|
2012-10-31 15:00:36 -07:00
|
|
|
rows = GetNumberOfRows();
|
2012-10-09 22:00:05 -07:00
|
|
|
mNumDisplayRows = clamped<uint32_t>(rows, 1, kMaxDropDownRows);
|
2012-06-22 18:13:56 -07:00
|
|
|
if (mNumDisplayRows == rows) {
|
|
|
|
newHeight = visibleHeight; // use the exact height
|
|
|
|
} else {
|
|
|
|
newHeight = mNumDisplayRows * heightOfARow; // approximate
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
rows = availableHeight / heightOfARow;
|
2012-10-09 22:00:05 -07:00
|
|
|
mNumDisplayRows = clamped<uint32_t>(rows, 1, kMaxDropDownRows);
|
2012-06-22 18:13:56 -07:00
|
|
|
newHeight = mNumDisplayRows * heightOfARow; // approximate
|
|
|
|
}
|
2012-06-22 18:13:56 -07:00
|
|
|
state.SetComputedHeight(newHeight);
|
|
|
|
mDropdownCanGrow = visibleHeight - newHeight >= heightOfARow &&
|
|
|
|
mNumDisplayRows != kMaxDropDownRows;
|
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2007-08-02 11:08:05 -07:00
|
|
|
mLastDropdownComputedHeight = state.ComputedHeight();
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
nsHTMLScrollFrame::WillReflow(aPresContext);
|
2014-05-12 17:47:52 -07:00
|
|
|
nsHTMLScrollFrame::Reflow(aPresContext, aDesiredSize, state, aStatus);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2013-08-23 13:20:07 -07:00
|
|
|
ScrollbarStyles
|
2007-03-22 10:30:00 -07: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 08:56:38 -07:00
|
|
|
int32_t verticalStyle = IsInDropDownMode() ? NS_STYLE_OVERFLOW_AUTO
|
2007-03-22 10:30:00 -07:00
|
|
|
: NS_STYLE_OVERFLOW_SCROLL;
|
2014-09-15 12:30:00 -07:00
|
|
|
return ScrollbarStyles(NS_STYLE_OVERFLOW_HIDDEN, verticalStyle,
|
|
|
|
NS_STYLE_SCROLL_BEHAVIOR_AUTO);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2011-09-28 23:19:26 -07:00
|
|
|
bool
|
2007-12-06 16:10:31 -08:00
|
|
|
nsListControlFrame::ShouldPropagateComputedHeightToScrolledContent() const
|
|
|
|
{
|
|
|
|
return !IsInDropDownMode();
|
|
|
|
}
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
//---------------------------------------------------------
|
2014-05-24 15:20:39 -07:00
|
|
|
nsContainerFrame*
|
2007-03-22 10:30:00 -07:00
|
|
|
nsListControlFrame::GetContentInsertionFrame() {
|
|
|
|
return GetOptionsContainer()->GetContentInsertionFrame();
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------
|
2011-09-28 23:19:26 -07:00
|
|
|
bool
|
2012-08-22 08:56:38 -07:00
|
|
|
nsListControlFrame::ExtendedSelection(int32_t aStartIndex,
|
|
|
|
int32_t aEndIndex,
|
2011-09-28 23:19:26 -07:00
|
|
|
bool aClearAll)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
return SetOptionsSelectedFromFrame(aStartIndex, aEndIndex,
|
2011-10-17 07:59:28 -07:00
|
|
|
true, aClearAll);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------
|
2011-09-28 23:19:26 -07:00
|
|
|
bool
|
2012-08-22 08:56:38 -07:00
|
|
|
nsListControlFrame::SingleSelection(int32_t aClickedIndex, bool aDoToggle)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
if (mComboboxFrame) {
|
|
|
|
mComboboxFrame->UpdateRecentIndex(GetSelectedIndex());
|
|
|
|
}
|
|
|
|
|
2011-09-28 23:19:26 -07:00
|
|
|
bool wasChanged = false;
|
2007-03-22 10:30:00 -07:00
|
|
|
// Get Current selection
|
|
|
|
if (aDoToggle) {
|
|
|
|
wasChanged = ToggleOptionSelectedFromFrame(aClickedIndex);
|
|
|
|
} else {
|
|
|
|
wasChanged = SetOptionsSelectedFromFrame(aClickedIndex, aClickedIndex,
|
2011-10-17 07:59:28 -07:00
|
|
|
true, true);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
2013-08-08 15:04:59 -07:00
|
|
|
nsWeakFrame weakFrame(this);
|
2007-03-22 10:30:00 -07:00
|
|
|
ScrollToIndex(aClickedIndex);
|
2013-08-08 15:04:59 -07:00
|
|
|
if (!weakFrame.IsAlive()) {
|
|
|
|
return wasChanged;
|
|
|
|
}
|
2011-09-27 18:46:11 -07:00
|
|
|
|
|
|
|
#ifdef ACCESSIBILITY
|
|
|
|
bool isCurrentOptionChanged = mEndSelectionIndex != aClickedIndex;
|
|
|
|
#endif
|
2007-03-22 10:30:00 -07:00
|
|
|
mStartSelectionIndex = aClickedIndex;
|
|
|
|
mEndSelectionIndex = aClickedIndex;
|
2007-09-27 16:06:31 -07:00
|
|
|
InvalidateFocus();
|
2011-09-27 18:46:11 -07:00
|
|
|
|
|
|
|
#ifdef ACCESSIBILITY
|
|
|
|
if (isCurrentOptionChanged) {
|
|
|
|
FireMenuItemActiveEvent();
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
return wasChanged;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2012-08-22 08:56:38 -07:00
|
|
|
nsListControlFrame::InitSelectionRange(int32_t aClickedIndex)
|
2007-03-22 10:30:00 -07: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 08:56:38 -07:00
|
|
|
int32_t selectedIndex = GetSelectedIndex();
|
2007-03-22 10:30:00 -07:00
|
|
|
if (selectedIndex >= 0) {
|
|
|
|
// Get the end of the contiguous selection
|
2013-08-02 00:08:19 -07:00
|
|
|
nsRefPtr<dom::HTMLOptionsCollection> options = GetOptions();
|
2007-03-22 10:30:00 -07:00
|
|
|
NS_ASSERTION(options, "Collection of options is null!");
|
2013-08-02 00:08:19 -07:00
|
|
|
uint32_t numOptions = options->Length();
|
|
|
|
// Push i to one past the last selected index in the group.
|
2012-08-22 08:56:38 -07:00
|
|
|
uint32_t i;
|
2013-08-02 00:08:19 -07:00
|
|
|
for (i = selectedIndex + 1; i < numOptions; i++) {
|
|
|
|
if (!options->ItemAsOption(i)->Selected()) {
|
2007-03-22 10:30:00 -07: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-10-31 15:00:36 -07: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());
|
|
|
|
}
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
//---------------------------------------------------------
|
2011-09-28 23:19:26 -07:00
|
|
|
bool
|
2012-08-22 08:56:38 -07:00
|
|
|
nsListControlFrame::PerformSelection(int32_t aClickedIndex,
|
2011-09-28 23:19:26 -07:00
|
|
|
bool aIsShift,
|
|
|
|
bool aIsControl)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2011-09-28 23:19:26 -07:00
|
|
|
bool wasChanged = false;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
if (aClickedIndex == kNothingSelected) {
|
|
|
|
}
|
|
|
|
else if (GetMultiple()) {
|
|
|
|
if (aIsShift) {
|
|
|
|
// Make sure shift+click actually does something expected when
|
|
|
|
// the user has never clicked on the select
|
|
|
|
if (mStartSelectionIndex == kNothingSelected) {
|
|
|
|
InitSelectionRange(aClickedIndex);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Get the range from beginning (low) to end (high)
|
|
|
|
// Shift *always* works, even if the current option is disabled
|
2012-08-22 08:56:38 -07:00
|
|
|
int32_t startIndex;
|
|
|
|
int32_t endIndex;
|
2007-03-22 10:30:00 -07:00
|
|
|
if (mStartSelectionIndex == kNothingSelected) {
|
|
|
|
startIndex = aClickedIndex;
|
|
|
|
endIndex = aClickedIndex;
|
|
|
|
} else if (mStartSelectionIndex <= aClickedIndex) {
|
|
|
|
startIndex = mStartSelectionIndex;
|
|
|
|
endIndex = aClickedIndex;
|
|
|
|
} else {
|
|
|
|
startIndex = aClickedIndex;
|
|
|
|
endIndex = mStartSelectionIndex;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Clear only if control was not pressed
|
|
|
|
wasChanged = ExtendedSelection(startIndex, endIndex, !aIsControl);
|
2013-08-08 15:04:59 -07:00
|
|
|
nsWeakFrame weakFrame(this);
|
2007-03-22 10:30:00 -07:00
|
|
|
ScrollToIndex(aClickedIndex);
|
2013-08-08 15:04:59 -07:00
|
|
|
if (!weakFrame.IsAlive()) {
|
|
|
|
return wasChanged;
|
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
if (mStartSelectionIndex == kNothingSelected) {
|
|
|
|
mStartSelectionIndex = aClickedIndex;
|
|
|
|
}
|
2011-09-27 18:46:11 -07:00
|
|
|
#ifdef ACCESSIBILITY
|
|
|
|
bool isCurrentOptionChanged = mEndSelectionIndex != aClickedIndex;
|
|
|
|
#endif
|
|
|
|
mEndSelectionIndex = aClickedIndex;
|
2007-09-27 16:06:31 -07:00
|
|
|
InvalidateFocus();
|
2011-09-27 18:46:11 -07:00
|
|
|
|
|
|
|
#ifdef ACCESSIBILITY
|
|
|
|
if (isCurrentOptionChanged) {
|
|
|
|
FireMenuItemActiveEvent();
|
|
|
|
}
|
|
|
|
#endif
|
2007-03-22 10:30:00 -07:00
|
|
|
} else if (aIsControl) {
|
2013-08-08 15:04:59 -07:00
|
|
|
wasChanged = SingleSelection(aClickedIndex, true); // might destroy us
|
2007-03-22 10:30:00 -07:00
|
|
|
} else {
|
2013-08-08 15:04:59 -07:00
|
|
|
wasChanged = SingleSelection(aClickedIndex, false); // might destroy us
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
} else {
|
2013-08-08 15:04:59 -07:00
|
|
|
wasChanged = SingleSelection(aClickedIndex, false); // might destroy us
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
return wasChanged;
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------
|
2011-09-28 23:19:26 -07:00
|
|
|
bool
|
2007-03-22 10:30:00 -07:00
|
|
|
nsListControlFrame::HandleListSelection(nsIDOMEvent* aEvent,
|
2012-08-22 08:56:38 -07:00
|
|
|
int32_t aClickedIndex)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
nsCOMPtr<nsIDOMMouseEvent> mouseEvent = do_QueryInterface(aEvent);
|
2011-09-28 23:19:26 -07:00
|
|
|
bool isShift;
|
|
|
|
bool isControl;
|
2007-03-22 10:30:00 -07:00
|
|
|
#ifdef XP_MACOSX
|
|
|
|
mouseEvent->GetMetaKey(&isControl);
|
|
|
|
#else
|
|
|
|
mouseEvent->GetCtrlKey(&isControl);
|
|
|
|
#endif
|
|
|
|
mouseEvent->GetShiftKey(&isShift);
|
2013-08-08 15:04:59 -07:00
|
|
|
return PerformSelection(aClickedIndex, isShift, isControl); // might destroy us
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------
|
|
|
|
void
|
2011-09-28 23:19:26 -07:00
|
|
|
nsListControlFrame::CaptureMouseEvents(bool aGrabMouseEvents)
|
2007-03-22 10:30:00 -07: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())
|
|
|
|
return;
|
|
|
|
|
2009-09-13 06:13:16 -07:00
|
|
|
if (aGrabMouseEvents) {
|
|
|
|
nsIPresShell::SetCapturingContent(mContent, CAPTURE_IGNOREALLOWED);
|
|
|
|
} else {
|
|
|
|
nsIContent* capturingContent = nsIPresShell::GetCapturingContent();
|
|
|
|
|
2011-09-28 23:19:26 -07:00
|
|
|
bool dropDownIsHidden = false;
|
2009-09-13 06:13:16 -07: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 07:20:58 -07:00
|
|
|
nsIPresShell::SetCapturingContent(nullptr, 0);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------
|
2014-02-17 23:47:48 -08:00
|
|
|
nsresult
|
2013-10-01 20:46:03 -07:00
|
|
|
nsListControlFrame::HandleEvent(nsPresContext* aPresContext,
|
|
|
|
WidgetGUIEvent* aEvent,
|
2007-03-22 10:30:00 -07:00
|
|
|
nsEventStatus* aEventStatus)
|
|
|
|
{
|
|
|
|
NS_ENSURE_ARG_POINTER(aEventStatus);
|
|
|
|
|
|
|
|
/*const char * desc[] = {"NS_MOUSE_MOVE",
|
|
|
|
"NS_MOUSE_LEFT_BUTTON_UP",
|
|
|
|
"NS_MOUSE_LEFT_BUTTON_DOWN",
|
|
|
|
"<NA>","<NA>","<NA>","<NA>","<NA>","<NA>","<NA>",
|
|
|
|
"NS_MOUSE_MIDDLE_BUTTON_UP",
|
|
|
|
"NS_MOUSE_MIDDLE_BUTTON_DOWN",
|
|
|
|
"<NA>","<NA>","<NA>","<NA>","<NA>","<NA>","<NA>","<NA>",
|
|
|
|
"NS_MOUSE_RIGHT_BUTTON_UP",
|
|
|
|
"NS_MOUSE_RIGHT_BUTTON_DOWN",
|
|
|
|
"NS_MOUSE_ENTER_SYNTH",
|
|
|
|
"NS_MOUSE_EXIT_SYNTH",
|
|
|
|
"NS_MOUSE_LEFT_DOUBLECLICK",
|
|
|
|
"NS_MOUSE_MIDDLE_DOUBLECLICK",
|
|
|
|
"NS_MOUSE_RIGHT_DOUBLECLICK",
|
|
|
|
"NS_MOUSE_LEFT_CLICK",
|
|
|
|
"NS_MOUSE_MIDDLE_CLICK",
|
|
|
|
"NS_MOUSE_RIGHT_CLICK"};
|
|
|
|
int inx = aEvent->message-NS_MOUSE_MESSAGE_START;
|
|
|
|
if (inx >= 0 && inx <= (NS_MOUSE_RIGHT_CLICK-NS_MOUSE_MESSAGE_START)) {
|
|
|
|
printf("Mouse in ListFrame %s [%d]\n", desc[inx], aEvent->message);
|
|
|
|
} else {
|
|
|
|
printf("Mouse in ListFrame <UNKNOWN> [%d]\n", aEvent->message);
|
|
|
|
}*/
|
|
|
|
|
|
|
|
if (nsEventStatus_eConsumeNoDefault == *aEventStatus)
|
|
|
|
return NS_OK;
|
|
|
|
|
|
|
|
// do we have style that affects how we are selected?
|
|
|
|
// do we have user-input style?
|
2013-02-16 13:51:02 -08:00
|
|
|
const nsStyleUserInterface* uiStyle = StyleUserInterface();
|
2007-03-22 10:30:00 -07:00
|
|
|
if (uiStyle->mUserInput == NS_STYLE_USER_INPUT_NONE || uiStyle->mUserInput == NS_STYLE_USER_INPUT_DISABLED)
|
|
|
|
return nsFrame::HandleEvent(aPresContext, aEvent, aEventStatus);
|
|
|
|
|
2014-04-02 21:18:36 -07:00
|
|
|
EventStates eventStates = mContent->AsElement()->State();
|
2010-10-20 04:26:32 -07:00
|
|
|
if (eventStates.HasState(NS_EVENT_STATE_DISABLED))
|
2007-03-22 10:30:00 -07:00
|
|
|
return NS_OK;
|
|
|
|
|
|
|
|
return nsHTMLScrollFrame::HandleEvent(aPresContext, aEvent, aEventStatus);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//---------------------------------------------------------
|
2014-05-28 12:36:58 -07:00
|
|
|
void
|
2011-08-24 13:54:30 -07:00
|
|
|
nsListControlFrame::SetInitialChildList(ChildListID aListID,
|
2009-07-28 05:53:20 -07:00
|
|
|
nsFrameList& aChildList)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
// First check to see if all the content has been added
|
|
|
|
mIsAllContentHere = mContent->IsDoneAddingChildren();
|
|
|
|
if (!mIsAllContentHere) {
|
2011-10-17 07:59:28 -07:00
|
|
|
mIsAllFramesHere = false;
|
|
|
|
mHasBeenInitialized = false;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
2014-05-28 12:36:58 -07:00
|
|
|
nsHTMLScrollFrame::SetInitialChildList(aListID, aChildList);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
// If all the content is here now check
|
|
|
|
// to see if all the frames have been created
|
|
|
|
/*if (mIsAllContentHere) {
|
|
|
|
// If all content and frames are here
|
|
|
|
// the reset/initialize
|
|
|
|
if (CheckIfAllFramesHere()) {
|
|
|
|
ResetList(aPresContext);
|
2011-10-17 07:59:28 -07:00
|
|
|
mHasBeenInitialized = true;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
}*/
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------
|
2013-03-19 18:47:48 -07:00
|
|
|
void
|
2014-05-24 15:20:40 -07:00
|
|
|
nsListControlFrame::Init(nsIContent* aContent,
|
|
|
|
nsContainerFrame* aParent,
|
|
|
|
nsIFrame* aPrevInFlow)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2013-03-19 18:47:48 -07:00
|
|
|
nsHTMLScrollFrame::Init(aContent, aParent, aPrevInFlow);
|
2007-03-22 10:30:00 -07: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.
|
|
|
|
// we need to hook up our listeners before the editor is initialized
|
|
|
|
mEventListener = new nsListEventListener(this);
|
|
|
|
|
2013-07-24 23:09:29 -07:00
|
|
|
mContent->AddSystemEventListener(NS_LITERAL_STRING("keydown"),
|
|
|
|
mEventListener, false, false);
|
2013-07-19 07:32:51 -07: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);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
mStartSelectionIndex = kNothingSelected;
|
|
|
|
mEndSelectionIndex = kNothingSelected;
|
|
|
|
|
2009-09-01 19:46:47 -07:00
|
|
|
mLastDropdownBackstopColor = PresContext()->DefaultBackgroundColor();
|
|
|
|
|
2013-02-21 23:38:06 -08:00
|
|
|
if (IsInDropDownMode()) {
|
|
|
|
AddStateBits(NS_FRAME_IN_POPUP);
|
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2013-08-02 00:08:19 -07:00
|
|
|
dom::HTMLOptionsCollection*
|
|
|
|
nsListControlFrame::GetOptions() const
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2013-08-02 00:08:19 -07:00
|
|
|
dom::HTMLSelectElement* select =
|
|
|
|
dom::HTMLSelectElement::FromContentOrNull(mContent);
|
|
|
|
NS_ENSURE_TRUE(select, nullptr);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2013-08-02 00:08:19 -07:00
|
|
|
return select->Options();
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2013-08-02 00:07:04 -07: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);
|
|
|
|
}
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
NS_IMETHODIMP
|
2012-08-22 08:56:38 -07:00
|
|
|
nsListControlFrame::OnOptionSelected(int32_t aIndex, bool aSelected)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
if (aSelected) {
|
|
|
|
ScrollToIndex(aIndex);
|
|
|
|
}
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsListControlFrame::OnContentReset()
|
|
|
|
{
|
2011-10-17 07:59:28 -07:00
|
|
|
ResetList(true);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2012-05-20 22:18:28 -07:00
|
|
|
nsListControlFrame::ResetList(bool aAllowScrolling)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
// if all the frames aren't here
|
|
|
|
// don't bother reseting
|
|
|
|
if (!mIsAllFramesHere) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (aAllowScrolling) {
|
2011-10-17 07:59:28 -07:00
|
|
|
mPostChildrenLoadedReset = true;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
// Scroll to the selected index
|
2012-08-22 08:56:38 -07:00
|
|
|
int32_t indexToSelect = kNothingSelected;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
nsCOMPtr<nsIDOMHTMLSelectElement> selectElement(do_QueryInterface(mContent));
|
|
|
|
NS_ASSERTION(selectElement, "No select element!");
|
|
|
|
if (selectElement) {
|
|
|
|
selectElement->GetSelectedIndex(&indexToSelect);
|
2013-08-08 15:04:59 -07:00
|
|
|
nsWeakFrame weakFrame(this);
|
2007-03-22 10:30:00 -07:00
|
|
|
ScrollToIndex(indexToSelect);
|
2013-08-08 15:04:59 -07:00
|
|
|
if (!weakFrame.IsAlive()) {
|
|
|
|
return;
|
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
mStartSelectionIndex = kNothingSelected;
|
|
|
|
mEndSelectionIndex = kNothingSelected;
|
2012-05-20 22:18:28 -07:00
|
|
|
InvalidateFocus();
|
2007-03-22 10:30:00 -07:00
|
|
|
// Combobox will redisplay itself with the OnOptionSelected event
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2011-09-28 23:19:26 -07:00
|
|
|
nsListControlFrame::SetFocus(bool aOn, bool aRepaint)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2007-09-27 16:06:31 -07:00
|
|
|
InvalidateFocus();
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
if (aOn) {
|
|
|
|
ComboboxFocusSet();
|
|
|
|
mFocused = this;
|
|
|
|
} else {
|
2012-07-30 07:20:58 -07:00
|
|
|
mFocused = nullptr;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2007-09-27 16:06:31 -07:00
|
|
|
InvalidateFocus();
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
void nsListControlFrame::ComboboxFocusSet()
|
|
|
|
{
|
|
|
|
gLastKeyTime = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsListControlFrame::SetComboboxFrame(nsIFrame* aComboboxFrame)
|
|
|
|
{
|
2012-07-30 07:20:58 -07:00
|
|
|
if (nullptr != aComboboxFrame) {
|
2009-01-12 11:20:59 -08:00
|
|
|
mComboboxFrame = do_QueryFrame(aComboboxFrame);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2013-08-02 00:07:08 -07:00
|
|
|
nsListControlFrame::GetOptionText(uint32_t aIndex, nsAString& aStr)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2013-08-02 00:07:08 -07:00
|
|
|
aStr.Truncate();
|
|
|
|
if (dom::HTMLOptionElement* optionElement = GetOption(aIndex)) {
|
|
|
|
optionElement->GetText(aStr);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-08-22 08:56:38 -07:00
|
|
|
int32_t
|
2007-03-22 10:30:00 -07:00
|
|
|
nsListControlFrame::GetSelectedIndex()
|
|
|
|
{
|
2013-08-02 00:09:05 -07:00
|
|
|
dom::HTMLSelectElement* select =
|
|
|
|
dom::HTMLSelectElement::FromContentOrNull(mContent);
|
|
|
|
return select->SelectedIndex();
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2013-08-02 00:07:22 -07:00
|
|
|
dom::HTMLOptionElement*
|
2011-09-27 18:46:11 -07:00
|
|
|
nsListControlFrame::GetCurrentOption()
|
|
|
|
{
|
|
|
|
// The mEndSelectionIndex is what is currently being selected. Use
|
|
|
|
// the selected index if this is kNothingSelected.
|
2012-08-22 08:56:38 -07:00
|
|
|
int32_t focusedIndex = (mEndSelectionIndex == kNothingSelected) ?
|
2011-09-27 18:46:11 -07:00
|
|
|
GetSelectedIndex() : mEndSelectionIndex;
|
|
|
|
|
|
|
|
if (focusedIndex != kNothingSelected) {
|
2014-08-25 12:17:32 -07:00
|
|
|
return GetOption(AssertedCast<uint32_t>(focusedIndex));
|
2011-09-27 18:46:11 -07:00
|
|
|
}
|
|
|
|
|
2013-08-02 00:07:22 -07:00
|
|
|
// There is no selected item. Return the first non-disabled item.
|
2013-04-04 00:03:33 -07:00
|
|
|
nsRefPtr<dom::HTMLSelectElement> selectElement =
|
|
|
|
dom::HTMLSelectElement::FromContent(mContent);
|
2011-09-27 18:46:11 -07:00
|
|
|
|
2013-08-02 00:07:22 -07:00
|
|
|
for (uint32_t i = 0, length = selectElement->Length(); i < length; ++i) {
|
|
|
|
dom::HTMLOptionElement* node = selectElement->Item(i);
|
2011-09-27 18:46:11 -07:00
|
|
|
if (!node) {
|
2012-07-30 07:20:58 -07:00
|
|
|
return nullptr;
|
2011-09-27 18:46:11 -07:00
|
|
|
}
|
|
|
|
|
2013-08-02 00:07:22 -07:00
|
|
|
if (!selectElement->IsOptionDisabled(node)) {
|
|
|
|
return node;
|
|
|
|
}
|
2011-09-27 18:46:11 -07:00
|
|
|
}
|
2013-08-02 00:07:22 -07:00
|
|
|
|
2012-07-30 07:20:58 -07:00
|
|
|
return nullptr;
|
2011-09-27 18:46:11 -07:00
|
|
|
}
|
|
|
|
|
2011-09-28 23:19:26 -07:00
|
|
|
bool
|
2007-03-22 10:30:00 -07:00
|
|
|
nsListControlFrame::IsInDropDownMode() const
|
|
|
|
{
|
2012-07-30 07:20:58 -07:00
|
|
|
return (mComboboxFrame != nullptr);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2012-10-09 22:00:05 -07:00
|
|
|
uint32_t
|
2007-03-22 10:30:00 -07:00
|
|
|
nsListControlFrame::GetNumberOfOptions()
|
|
|
|
{
|
2013-08-02 00:08:19 -07:00
|
|
|
dom::HTMLOptionsCollection* options = GetOptions();
|
2012-10-09 22:00:05 -07:00
|
|
|
if (!options) {
|
|
|
|
return 0;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
2012-10-09 22:00:05 -07:00
|
|
|
|
2013-08-02 00:08:19 -07:00
|
|
|
return options->Length();
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
// nsISelectControlFrame
|
|
|
|
//----------------------------------------------------------------------
|
2011-09-28 23:19:26 -07:00
|
|
|
bool nsListControlFrame::CheckIfAllFramesHere()
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
// Get the number of optgroups and options
|
2012-08-22 08:56:38 -07:00
|
|
|
//int32_t numContentItems = 0;
|
2007-03-22 10:30:00 -07:00
|
|
|
nsCOMPtr<nsIDOMNode> node(do_QueryInterface(mContent));
|
|
|
|
if (node) {
|
|
|
|
// XXX Need to find a fail proff way to determine that
|
|
|
|
// all the frames are there
|
2011-10-17 07:59:28 -07:00
|
|
|
mIsAllFramesHere = true;//NS_OK == CountAllChild(node, numContentItems);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
// now make sure we have a frame each piece of content
|
|
|
|
|
|
|
|
return mIsAllFramesHere;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2011-09-28 23:19:26 -07:00
|
|
|
nsListControlFrame::DoneAddingChildren(bool aIsDone)
|
2007-03-22 10:30:00 -07: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 07:52:43 -08:00
|
|
|
if (!mIsAllFramesHere) {
|
2007-03-22 10:30:00 -07:00
|
|
|
// if all the frames are now present we can initialize
|
|
|
|
if (CheckIfAllFramesHere()) {
|
2011-10-17 07:59:28 -07:00
|
|
|
mHasBeenInitialized = true;
|
|
|
|
ResetList(true);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2012-08-22 08:56:38 -07:00
|
|
|
nsListControlFrame::AddOption(int32_t aIndex)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
#ifdef DO_REFLOW_DEBUG
|
|
|
|
printf("---- Id: %d nsLCF %p Added Option %d\n", mReflowId, this, aIndex);
|
|
|
|
#endif
|
|
|
|
|
|
|
|
if (!mIsAllContentHere) {
|
|
|
|
mIsAllContentHere = mContent->IsDoneAddingChildren();
|
|
|
|
if (!mIsAllContentHere) {
|
2011-10-17 07:59:28 -07:00
|
|
|
mIsAllFramesHere = false;
|
|
|
|
mHasBeenInitialized = false;
|
2007-03-22 10:30:00 -07:00
|
|
|
} else {
|
2012-10-09 22:00:05 -07:00
|
|
|
mIsAllFramesHere = (aIndex == static_cast<int32_t>(GetNumberOfOptions()-1));
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
}
|
2012-10-09 22:00:05 -07:00
|
|
|
|
2009-08-24 11:17:56 -07:00
|
|
|
// Make sure we scroll to the selected option as needed
|
2011-10-17 07:59:28 -07:00
|
|
|
mNeedToReset = true;
|
2009-08-24 11:17:56 -07:00
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
if (!mHasBeenInitialized) {
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
mPostChildrenLoadedReset = mIsAllContentHere;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2012-08-22 08:56:38 -07:00
|
|
|
static int32_t
|
|
|
|
DecrementAndClamp(int32_t aSelectionIndex, int32_t aLength)
|
2010-06-27 13:53:47 -07:00
|
|
|
{
|
2013-01-15 04:22:03 -08:00
|
|
|
return aLength == 0 ? kNothingSelected : std::max(0, aSelectionIndex - 1);
|
2010-06-27 13:53:47 -07:00
|
|
|
}
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
NS_IMETHODIMP
|
2012-08-22 08:56:38 -07:00
|
|
|
nsListControlFrame::RemoveOption(int32_t aIndex)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2010-06-27 13:53:47 -07:00
|
|
|
NS_PRECONDITION(aIndex >= 0, "negative <option> index");
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
// Need to reset if we're a dropdown
|
|
|
|
if (IsInDropDownMode()) {
|
2011-10-17 07:59:28 -07:00
|
|
|
mNeedToReset = true;
|
2007-03-22 10:30:00 -07:00
|
|
|
mPostChildrenLoadedReset = mIsAllContentHere;
|
|
|
|
}
|
|
|
|
|
2010-06-27 13:53:47 -07:00
|
|
|
if (mStartSelectionIndex != kNothingSelected) {
|
|
|
|
NS_ASSERTION(mEndSelectionIndex != kNothingSelected, "");
|
2012-08-22 08:56:38 -07:00
|
|
|
int32_t numOptions = GetNumberOfOptions();
|
2010-06-27 13:53:47 -07: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 08:56:38 -07:00
|
|
|
int32_t forward = mEndSelectionIndex - mStartSelectionIndex;
|
|
|
|
int32_t* low = forward >= 0 ? &mStartSelectionIndex : &mEndSelectionIndex;
|
|
|
|
int32_t* high = forward >= 0 ? &mEndSelectionIndex : &mStartSelectionIndex;
|
2010-06-27 13:53:47 -07:00
|
|
|
if (aIndex < *low)
|
|
|
|
*low = ::DecrementAndClamp(*low, numOptions);
|
|
|
|
if (aIndex <= *high)
|
|
|
|
*high = ::DecrementAndClamp(*high, numOptions);
|
|
|
|
if (forward == 0)
|
|
|
|
*low = *high;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
2010-06-27 13:53:47 -07:00
|
|
|
else
|
|
|
|
NS_ASSERTION(mEndSelectionIndex == kNothingSelected, "");
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2007-09-27 16:06:31 -07:00
|
|
|
InvalidateFocus();
|
2007-03-22 10:30:00 -07:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------
|
|
|
|
// 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-28 23:19:26 -07:00
|
|
|
bool
|
2012-08-22 08:56:38 -07:00
|
|
|
nsListControlFrame::SetOptionsSelectedFromFrame(int32_t aStartIndex,
|
|
|
|
int32_t aEndIndex,
|
2011-09-28 23:19:26 -07:00
|
|
|
bool aValue,
|
|
|
|
bool aClearAll)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2013-04-04 00:03:33 -07:00
|
|
|
nsRefPtr<dom::HTMLSelectElement> selectElement =
|
|
|
|
dom::HTMLSelectElement::FromContent(mContent);
|
2013-09-28 12:04:20 -07: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);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2011-09-28 23:19:26 -07:00
|
|
|
bool
|
2012-08-22 08:56:38 -07:00
|
|
|
nsListControlFrame::ToggleOptionSelectedFromFrame(int32_t aIndex)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2013-08-02 00:07:32 -07:00
|
|
|
nsRefPtr<dom::HTMLOptionElement> option =
|
|
|
|
GetOption(static_cast<uint32_t>(aIndex));
|
|
|
|
NS_ENSURE_TRUE(option, false);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2013-04-04 00:03:33 -07:00
|
|
|
nsRefPtr<dom::HTMLSelectElement> selectElement =
|
|
|
|
dom::HTMLSelectElement::FromContent(mContent);
|
2013-08-02 00:07:32 -07:00
|
|
|
|
2013-09-28 12:04:20 -07:00
|
|
|
uint32_t mask = dom::HTMLSelectElement::NOTIFY;
|
|
|
|
if (!option->Selected()) {
|
|
|
|
mask |= dom::HTMLSelectElement::IS_SELECTED;
|
|
|
|
}
|
|
|
|
|
|
|
|
return selectElement->SetOptionsSelectedByIndex(aIndex, aIndex, mask);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Dispatch event and such
|
2011-09-28 23:19:26 -07:00
|
|
|
bool
|
2007-03-22 10:30:00 -07:00
|
|
|
nsListControlFrame::UpdateSelection()
|
|
|
|
{
|
|
|
|
if (mIsAllFramesHere) {
|
|
|
|
// if it's a combobox, display the new text
|
2009-02-17 19:27:25 -08:00
|
|
|
nsWeakFrame weakFrame(this);
|
2007-03-22 10:30:00 -07:00
|
|
|
if (mComboboxFrame) {
|
|
|
|
mComboboxFrame->RedisplaySelectedText();
|
|
|
|
}
|
|
|
|
// if it's a listbox, fire on change
|
|
|
|
else if (mIsAllContentHere) {
|
|
|
|
FireOnChange();
|
|
|
|
}
|
2009-02-17 19:27:25 -08:00
|
|
|
return weakFrame.IsAlive();
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
2011-10-17 07:59:28 -07:00
|
|
|
return true;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2012-08-22 08:56:38 -07:00
|
|
|
nsListControlFrame::ComboboxFinish(int32_t aIndex)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
gLastKeyTime = 0;
|
|
|
|
|
|
|
|
if (mComboboxFrame) {
|
2009-02-17 19:27:25 -08:00
|
|
|
nsWeakFrame weakFrame(this);
|
2013-08-08 15:04:59 -07:00
|
|
|
PerformSelection(aIndex, false, false); // might destroy us
|
|
|
|
if (!weakFrame.IsAlive() || !mComboboxFrame) {
|
|
|
|
return;
|
|
|
|
}
|
2009-02-17 19:27:25 -08:00
|
|
|
|
2013-08-08 15:04:59 -07:00
|
|
|
int32_t displayIndex = mComboboxFrame->GetIndexOfDisplayArea();
|
2007-03-22 10:30:00 -07:00
|
|
|
if (displayIndex != aIndex) {
|
2009-02-17 19:27:25 -08:00
|
|
|
mComboboxFrame->RedisplaySelectedText(); // might destroy us
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2009-02-17 19:27:25 -08:00
|
|
|
if (weakFrame.IsAlive() && mComboboxFrame) {
|
|
|
|
mComboboxFrame->RollupFromList(); // might destroy us
|
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Send out an onchange notification.
|
|
|
|
void
|
|
|
|
nsListControlFrame::FireOnChange()
|
|
|
|
{
|
|
|
|
if (mComboboxFrame) {
|
|
|
|
// Return hit without changing anything
|
2012-08-22 08:56:38 -07:00
|
|
|
int32_t index = mComboboxFrame->UpdateRecentIndex(NS_SKIP_NOTIFY_INDEX);
|
2007-03-22 10:30:00 -07:00
|
|
|
if (index == NS_SKIP_NOTIFY_INDEX)
|
|
|
|
return;
|
|
|
|
|
|
|
|
// See if the selection actually changed
|
|
|
|
if (index == GetSelectedIndex())
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2010-12-17 09:45:46 -08:00
|
|
|
// Dispatch the change event.
|
2011-10-18 03:53:36 -07:00
|
|
|
nsContentUtils::DispatchTrustedEvent(mContent->OwnerDoc(), mContent,
|
2011-10-17 07:59:28 -07:00
|
|
|
NS_LITERAL_STRING("change"), true,
|
|
|
|
false);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2012-08-22 08:56:38 -07:00
|
|
|
nsListControlFrame::OnSetSelectedIndex(int32_t aOldIndex, int32_t aNewIndex)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
if (mComboboxFrame) {
|
|
|
|
// UpdateRecentIndex with NS_SKIP_NOTIFY_INDEX, so that we won't fire an onchange
|
|
|
|
// event for this setting of selectedIndex.
|
|
|
|
mComboboxFrame->UpdateRecentIndex(NS_SKIP_NOTIFY_INDEX);
|
|
|
|
}
|
|
|
|
|
2013-08-08 15:04:59 -07:00
|
|
|
nsWeakFrame weakFrame(this);
|
2007-03-22 10:30:00 -07:00
|
|
|
ScrollToIndex(aNewIndex);
|
2013-08-08 15:04:59 -07:00
|
|
|
if (!weakFrame.IsAlive()) {
|
|
|
|
return NS_OK;
|
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
mStartSelectionIndex = aNewIndex;
|
|
|
|
mEndSelectionIndex = aNewIndex;
|
2007-09-27 16:06:31 -07:00
|
|
|
InvalidateFocus();
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
#ifdef ACCESSIBILITY
|
|
|
|
FireMenuItemActiveEvent();
|
|
|
|
#endif
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
// End nsISelectControlFrame
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
nsListControlFrame::SetFormProperty(nsIAtom* aName,
|
|
|
|
const nsAString& aValue)
|
|
|
|
{
|
|
|
|
if (nsGkAtoms::selected == aName) {
|
|
|
|
return NS_ERROR_INVALID_ARG; // Selected is readonly according to spec.
|
|
|
|
} else if (nsGkAtoms::selectedindex == aName) {
|
|
|
|
// You shouldn't be calling me for this!!!
|
|
|
|
return NS_ERROR_INVALID_ARG;
|
|
|
|
}
|
|
|
|
|
|
|
|
// We should be told about selectedIndex by the DOM element through
|
|
|
|
// OnOptionSelected
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsListControlFrame::AboutToDropDown()
|
|
|
|
{
|
2009-08-25 12:07:57 -07: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-15 21:38:33 -08:00
|
|
|
nsStyleContext* context = comboboxFrame->StyleContext()->GetParent();
|
2009-08-25 12:07:57 -07:00
|
|
|
mLastDropdownBackstopColor = NS_RGBA(0,0,0,0);
|
|
|
|
while (NS_GET_A(mLastDropdownBackstopColor) < 255 && context) {
|
|
|
|
mLastDropdownBackstopColor =
|
2013-02-16 13:51:02 -08:00
|
|
|
NS_ComposeColors(context->StyleBackground()->mBackgroundColor,
|
2009-08-25 12:07:57 -07:00
|
|
|
mLastDropdownBackstopColor);
|
|
|
|
context = context->GetParent();
|
|
|
|
}
|
|
|
|
mLastDropdownBackstopColor =
|
|
|
|
NS_ComposeColors(PresContext()->DefaultBackgroundColor(),
|
|
|
|
mLastDropdownBackstopColor);
|
2009-09-01 19:46:47 -07:00
|
|
|
|
|
|
|
if (mIsAllContentHere && mIsAllFramesHere && mHasBeenInitialized) {
|
2013-08-08 15:04:59 -07:00
|
|
|
nsWeakFrame weakFrame(this);
|
2009-09-01 19:46:47 -07:00
|
|
|
ScrollToIndex(GetSelectedIndex());
|
2013-08-08 15:04:59 -07:00
|
|
|
if (!weakFrame.IsAlive()) {
|
|
|
|
return;
|
|
|
|
}
|
2009-09-01 19:46:47 -07:00
|
|
|
#ifdef ACCESSIBILITY
|
|
|
|
FireMenuItemActiveEvent(); // Inform assistive tech what got focus
|
|
|
|
#endif
|
|
|
|
}
|
2011-10-17 07:59:28 -07:00
|
|
|
mItemSelectionStarted = false;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
// We are about to be rolledup from the outside (ComboboxFrame)
|
|
|
|
void
|
|
|
|
nsListControlFrame::AboutToRollup()
|
|
|
|
{
|
|
|
|
// 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.
|
|
|
|
//
|
|
|
|
// 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.
|
|
|
|
|
|
|
|
if (IsInDropDownMode()) {
|
2007-05-17 04:12:30 -07:00
|
|
|
ComboboxFinish(mComboboxFrame->GetIndexOfDisplayArea()); // might destroy us
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-05-12 17:47:53 -07:00
|
|
|
void
|
2007-03-22 10:30:00 -07:00
|
|
|
nsListControlFrame::DidReflow(nsPresContext* aPresContext,
|
|
|
|
const nsHTMLReflowState* aReflowState,
|
|
|
|
nsDidReflowStatus aStatus)
|
|
|
|
{
|
2011-09-28 23:19:26 -07:00
|
|
|
bool wasInterrupted = !mHasPendingInterruptAtStartOfReflow &&
|
2009-09-04 14:07:38 -07:00
|
|
|
aPresContext->HasPendingInterrupt();
|
|
|
|
|
2014-05-12 17:47:53 -07:00
|
|
|
nsHTMLScrollFrame::DidReflow(aPresContext, aReflowState, aStatus);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2009-09-04 14:07:38 -07:00
|
|
|
if (mNeedToReset && !wasInterrupted) {
|
2011-10-17 07:59:28 -07:00
|
|
|
mNeedToReset = false;
|
2007-03-22 10:30:00 -07: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 07:59:28 -07:00
|
|
|
// to scroll by calling ResetList(true). The latter two conditions
|
2007-03-22 10:30:00 -07: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-20 22:18:28 -07:00
|
|
|
ResetList(!DidHistoryRestore() || mPostChildrenLoadedReset);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2011-10-17 07:59:28 -07:00
|
|
|
mHasPendingInterruptAtStartOfReflow = false;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
nsIAtom*
|
|
|
|
nsListControlFrame::GetType() const
|
|
|
|
{
|
|
|
|
return nsGkAtoms::listControlFrame;
|
|
|
|
}
|
|
|
|
|
2014-01-05 15:31:14 -08:00
|
|
|
#ifdef DEBUG_FRAME_DUMP
|
2014-02-17 23:47:48 -08:00
|
|
|
nsresult
|
2007-03-22 10:30:00 -07:00
|
|
|
nsListControlFrame::GetFrameName(nsAString& aResult) const
|
|
|
|
{
|
|
|
|
return MakeFrameName(NS_LITERAL_STRING("ListControl"), aResult);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
nscoord
|
|
|
|
nsListControlFrame::GetHeightOfARow()
|
|
|
|
{
|
|
|
|
return HeightOfARow();
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
2012-08-22 08:56:38 -07:00
|
|
|
nsListControlFrame::IsOptionDisabled(int32_t anIndex, bool &aIsDisabled)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2013-04-04 00:03:33 -07:00
|
|
|
nsRefPtr<dom::HTMLSelectElement> sel =
|
|
|
|
dom::HTMLSelectElement::FromContent(mContent);
|
2007-03-22 10:30:00 -07:00
|
|
|
if (sel) {
|
|
|
|
sel->IsOptionDisabled(anIndex, &aIsDisabled);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
// helper
|
|
|
|
//----------------------------------------------------------------------
|
2011-09-28 23:19:26 -07:00
|
|
|
bool
|
2007-03-22 10:30:00 -07:00
|
|
|
nsListControlFrame::IsLeftButton(nsIDOMEvent* aMouseEvent)
|
|
|
|
{
|
|
|
|
// only allow selection with the left button
|
|
|
|
nsCOMPtr<nsIDOMMouseEvent> mouseEvent = do_QueryInterface(aMouseEvent);
|
|
|
|
if (mouseEvent) {
|
2014-02-20 10:38:13 -08:00
|
|
|
int16_t whichButton;
|
2007-03-22 10:30:00 -07:00
|
|
|
if (NS_SUCCEEDED(mouseEvent->GetButton(&whichButton))) {
|
2011-10-17 07:59:28 -07:00
|
|
|
return whichButton != 0?false:true;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
}
|
2011-10-17 07:59:28 -07:00
|
|
|
return false;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
nscoord
|
2011-11-23 18:48:23 -08:00
|
|
|
nsListControlFrame::CalcFallbackRowHeight(float aFontSizeInflation)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
nscoord rowHeight = 0;
|
2011-04-07 21:18:43 -07:00
|
|
|
|
2011-04-07 18:05:49 -07:00
|
|
|
nsRefPtr<nsFontMetrics> fontMet;
|
2011-11-23 18:48:23 -08:00
|
|
|
nsLayoutUtils::GetFontMetricsForFrame(this, getter_AddRefs(fontMet),
|
|
|
|
aFontSizeInflation);
|
2008-12-04 08:09:53 -08:00
|
|
|
if (fontMet) {
|
2011-04-07 21:18:43 -07:00
|
|
|
rowHeight = fontMet->MaxHeight();
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
return rowHeight;
|
|
|
|
}
|
|
|
|
|
|
|
|
nscoord
|
2014-07-24 10:03:26 -07:00
|
|
|
nsListControlFrame::CalcIntrinsicBSize(nscoord aHeightOfARow,
|
2012-08-22 08:56:38 -07:00
|
|
|
int32_t aNumberOfOptions)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
NS_PRECONDITION(!IsInDropDownMode(),
|
|
|
|
"Shouldn't be in dropdown mode when we call this");
|
2010-11-09 06:24:01 -08:00
|
|
|
|
2013-08-02 00:09:02 -07:00
|
|
|
dom::HTMLSelectElement* select =
|
|
|
|
dom::HTMLSelectElement::FromContentOrNull(mContent);
|
|
|
|
if (select) {
|
|
|
|
mNumDisplayRows = select->Size();
|
|
|
|
} else {
|
|
|
|
mNumDisplayRows = 1;
|
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
if (mNumDisplayRows < 1) {
|
2010-11-09 06:24:01 -08:00
|
|
|
mNumDisplayRows = 4;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2010-11-09 06:24:01 -08:00
|
|
|
return mNumDisplayRows * aHeightOfARow;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
// nsIDOMMouseListener
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
nsresult
|
|
|
|
nsListControlFrame::MouseUp(nsIDOMEvent* aMouseEvent)
|
|
|
|
{
|
2012-07-30 07:20:58 -07:00
|
|
|
NS_ASSERTION(aMouseEvent != nullptr, "aMouseEvent is null.");
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2011-06-29 11:07:25 -07:00
|
|
|
nsCOMPtr<nsIDOMMouseEvent> mouseEvent = do_QueryInterface(aMouseEvent);
|
|
|
|
NS_ENSURE_TRUE(mouseEvent, NS_ERROR_FAILURE);
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
UpdateInListState(aMouseEvent);
|
|
|
|
|
2011-10-17 07:59:28 -07:00
|
|
|
mButtonDown = false;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2014-04-02 21:18:36 -07:00
|
|
|
EventStates eventStates = mContent->AsElement()->State();
|
2010-10-20 04:26:32 -07:00
|
|
|
if (eventStates.HasState(NS_EVENT_STATE_DISABLED)) {
|
2007-03-22 10:30:00 -07:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
// only allow selection with the left button
|
|
|
|
// if a right button click is on the combobox itself
|
|
|
|
// or on the select when in listbox mode, then let the click through
|
|
|
|
if (!IsLeftButton(aMouseEvent)) {
|
|
|
|
if (IsInDropDownMode()) {
|
|
|
|
if (!IgnoreMouseEventForSelection(aMouseEvent)) {
|
|
|
|
aMouseEvent->PreventDefault();
|
|
|
|
aMouseEvent->StopPropagation();
|
|
|
|
} else {
|
2011-10-17 07:59:28 -07:00
|
|
|
CaptureMouseEvents(false);
|
2007-03-22 10:30:00 -07:00
|
|
|
return NS_OK;
|
|
|
|
}
|
2011-10-17 07:59:28 -07:00
|
|
|
CaptureMouseEvents(false);
|
2007-03-22 10:30:00 -07:00
|
|
|
return NS_ERROR_FAILURE; // means consume event
|
|
|
|
} else {
|
2011-10-17 07:59:28 -07:00
|
|
|
CaptureMouseEvents(false);
|
2007-03-22 10:30:00 -07:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-02-16 13:51:02 -08:00
|
|
|
const nsStyleVisibility* vis = StyleVisibility();
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
if (!vis->IsVisible()) {
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (IsInDropDownMode()) {
|
|
|
|
// 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-01 23:38:27 -07:00
|
|
|
WidgetMouseEvent* mouseEvent =
|
2013-10-22 01:55:20 -07:00
|
|
|
aMouseEvent->GetInternalNSEvent()->AsMouseEvent();
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2012-08-22 08:56:38 -07:00
|
|
|
int32_t selectedIndex;
|
2007-03-22 10:30:00 -07:00
|
|
|
if (NS_SUCCEEDED(GetIndexFromDOMEvent(aMouseEvent, selectedIndex))) {
|
|
|
|
// If it's disabled, disallow the click and leave.
|
2011-09-28 23:19:26 -07:00
|
|
|
bool isDisabled = false;
|
2007-03-22 10:30:00 -07:00
|
|
|
IsOptionDisabled(selectedIndex, isDisabled);
|
|
|
|
if (isDisabled) {
|
|
|
|
aMouseEvent->PreventDefault();
|
|
|
|
aMouseEvent->StopPropagation();
|
2011-10-17 07:59:28 -07:00
|
|
|
CaptureMouseEvents(false);
|
2007-03-22 10:30:00 -07:00
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (kNothingSelected != selectedIndex) {
|
2007-05-17 04:12:30 -07:00
|
|
|
nsWeakFrame weakFrame(this);
|
2007-03-22 10:30:00 -07:00
|
|
|
ComboboxFinish(selectedIndex);
|
2007-05-17 04:12:30 -07:00
|
|
|
if (!weakFrame.IsAlive())
|
|
|
|
return NS_OK;
|
2007-03-22 10:30:00 -07:00
|
|
|
FireOnChange();
|
|
|
|
}
|
|
|
|
|
|
|
|
mouseEvent->clickCount = 1;
|
|
|
|
} else {
|
|
|
|
// the click was out side of the select or its dropdown
|
|
|
|
mouseEvent->clickCount = IgnoreMouseEventForSelection(aMouseEvent) ? 1 : 0;
|
|
|
|
}
|
|
|
|
} else {
|
2011-10-17 07:59:28 -07:00
|
|
|
CaptureMouseEvents(false);
|
2007-03-22 10:30:00 -07:00
|
|
|
// Notify
|
|
|
|
if (mChangesSinceDragStart) {
|
|
|
|
// reset this so that future MouseUps without a prior MouseDown
|
|
|
|
// won't fire onchange
|
2011-10-17 07:59:28 -07:00
|
|
|
mChangesSinceDragStart = false;
|
2007-03-22 10:30:00 -07:00
|
|
|
FireOnChange();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsListControlFrame::UpdateInListState(nsIDOMEvent* aEvent)
|
|
|
|
{
|
|
|
|
if (!mComboboxFrame || !mComboboxFrame->IsDroppedDown())
|
|
|
|
return;
|
|
|
|
|
|
|
|
nsPoint pt = nsLayoutUtils::GetDOMEventCoordinatesRelativeTo(aEvent, this);
|
2009-09-02 21:49:16 -07:00
|
|
|
nsRect borderInnerEdge = GetScrollPortRect();
|
2007-03-22 10:30:00 -07:00
|
|
|
if (pt.y >= borderInnerEdge.y && pt.y < borderInnerEdge.YMost()) {
|
2011-10-17 07:59:28 -07:00
|
|
|
mItemSelectionStarted = true;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-09-28 23:19:26 -07:00
|
|
|
bool nsListControlFrame::IgnoreMouseEventForSelection(nsIDOMEvent* aEvent)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
if (!mComboboxFrame)
|
2011-10-17 07:59:28 -07:00
|
|
|
return false;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
// Our DOM listener does get called when the dropdown is not
|
|
|
|
// showing, because it listens to events on the SELECT element
|
|
|
|
if (!mComboboxFrame->IsDroppedDown())
|
2011-10-17 07:59:28 -07:00
|
|
|
return true;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
return !mItemSelectionStarted;
|
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef ACCESSIBILITY
|
|
|
|
void
|
|
|
|
nsListControlFrame::FireMenuItemActiveEvent()
|
|
|
|
{
|
|
|
|
if (mFocused != this && !IsInDropDownMode()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2011-09-27 18:46:11 -07:00
|
|
|
nsCOMPtr<nsIContent> optionContent = GetCurrentOption();
|
2007-03-22 10:30:00 -07:00
|
|
|
if (!optionContent) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
FireDOMEvent(NS_LITERAL_STRING("DOMMenuItemActive"), optionContent);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
nsListControlFrame::GetIndexFromDOMEvent(nsIDOMEvent* aMouseEvent,
|
2012-08-22 08:56:38 -07:00
|
|
|
int32_t& aCurIndex)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
if (IgnoreMouseEventForSelection(aMouseEvent))
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
|
2009-09-13 06:13:16 -07:00
|
|
|
if (nsIPresShell::GetCapturingContent() != mContent) {
|
2007-03-22 10:30:00 -07:00
|
|
|
// If we're not capturing, then ignore movement in the border
|
|
|
|
nsPoint pt = nsLayoutUtils::GetDOMEventCoordinatesRelativeTo(aMouseEvent, this);
|
2009-09-02 21:49:16 -07:00
|
|
|
nsRect borderInnerEdge = GetScrollPortRect();
|
2007-03-22 10:30:00 -07:00
|
|
|
if (!borderInnerEdge.Contains(pt)) {
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-08-02 00:07:56 -07:00
|
|
|
nsRefPtr<dom::HTMLOptionElement> option;
|
|
|
|
for (nsCOMPtr<nsIContent> content =
|
|
|
|
PresContext()->EventStateManager()->GetEventTargetContent(nullptr);
|
|
|
|
content && !option;
|
|
|
|
content = content->GetParent()) {
|
|
|
|
option = dom::HTMLOptionElement::FromContent(content);
|
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2013-08-02 00:07:56 -07:00
|
|
|
if (option) {
|
2013-08-13 23:57:04 -07:00
|
|
|
aCurIndex = option->Index();
|
2013-08-02 00:07:56 -07:00
|
|
|
MOZ_ASSERT(aCurIndex >= 0);
|
2007-03-22 10:30:00 -07:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2012-08-22 08:56:38 -07:00
|
|
|
int32_t numOptions = GetNumberOfOptions();
|
2007-03-22 10:30:00 -07: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 00:07:56 -07:00
|
|
|
nsRefPtr<dom::HTMLOptionElement> firstOption = GetOption(0);
|
2007-03-22 10:30:00 -07:00
|
|
|
NS_ASSERTION(firstOption, "Can't find first option that's supposed to be there");
|
2009-12-24 13:20:06 -08:00
|
|
|
nsIFrame* optionFrame = firstOption->GetPrimaryFrame();
|
2007-03-22 10:30:00 -07:00
|
|
|
if (optionFrame) {
|
|
|
|
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 00:07:56 -07:00
|
|
|
nsRefPtr<dom::HTMLOptionElement> lastOption = GetOption(numOptions - 1);
|
2007-03-22 10:30:00 -07: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-24 13:20:06 -08:00
|
|
|
optionFrame = lastOption->GetPrimaryFrame();
|
2007-03-22 10:30:00 -07:00
|
|
|
if (optionFrame) {
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
nsListControlFrame::MouseDown(nsIDOMEvent* aMouseEvent)
|
|
|
|
{
|
2012-07-30 07:20:58 -07:00
|
|
|
NS_ASSERTION(aMouseEvent != nullptr, "aMouseEvent is null.");
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2011-06-29 11:07:25 -07:00
|
|
|
nsCOMPtr<nsIDOMMouseEvent> mouseEvent = do_QueryInterface(aMouseEvent);
|
|
|
|
NS_ENSURE_TRUE(mouseEvent, NS_ERROR_FAILURE);
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
UpdateInListState(aMouseEvent);
|
|
|
|
|
2014-04-02 21:18:36 -07:00
|
|
|
EventStates eventStates = mContent->AsElement()->State();
|
2010-10-20 04:26:32 -07:00
|
|
|
if (eventStates.HasState(NS_EVENT_STATE_DISABLED)) {
|
2007-03-22 10:30:00 -07:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
// only allow selection with the left button
|
|
|
|
// if a right button click is on the combobox itself
|
|
|
|
// or on the select when in listbox mode, then let the click through
|
|
|
|
if (!IsLeftButton(aMouseEvent)) {
|
|
|
|
if (IsInDropDownMode()) {
|
|
|
|
if (!IgnoreMouseEventForSelection(aMouseEvent)) {
|
|
|
|
aMouseEvent->PreventDefault();
|
|
|
|
aMouseEvent->StopPropagation();
|
|
|
|
} else {
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
return NS_ERROR_FAILURE; // means consume event
|
|
|
|
} else {
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-08-22 08:56:38 -07:00
|
|
|
int32_t selectedIndex;
|
2007-03-22 10:30:00 -07:00
|
|
|
if (NS_SUCCEEDED(GetIndexFromDOMEvent(aMouseEvent, selectedIndex))) {
|
|
|
|
// Handle Like List
|
2011-10-17 07:59:28 -07:00
|
|
|
mButtonDown = true;
|
|
|
|
CaptureMouseEvents(true);
|
2013-08-08 15:04:59 -07:00
|
|
|
nsWeakFrame weakFrame(this);
|
|
|
|
bool change =
|
|
|
|
HandleListSelection(aMouseEvent, selectedIndex); // might destroy us
|
|
|
|
if (!weakFrame.IsAlive()) {
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
mChangesSinceDragStart = change;
|
2007-03-22 10:30:00 -07:00
|
|
|
} else {
|
|
|
|
// NOTE: the combo box is responsible for dropping it down
|
|
|
|
if (mComboboxFrame) {
|
2014-09-29 14:11:08 -07:00
|
|
|
if (XRE_GetProcessType() == GeckoProcessType_Content &&
|
|
|
|
Preferences::GetBool("browser.tabs.remote.desktopbehavior", false)) {
|
2013-08-25 18:34:23 -07:00
|
|
|
nsContentUtils::DispatchChromeEvent(mContent->OwnerDoc(), mContent,
|
|
|
|
NS_LITERAL_STRING("mozshowdropdown"), true,
|
|
|
|
false);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
if (!IgnoreMouseEventForSelection(aMouseEvent)) {
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!nsComboboxControlFrame::ToolkitHasNativePopup())
|
|
|
|
{
|
2011-09-28 23:19:26 -07:00
|
|
|
bool isDroppedDown = mComboboxFrame->IsDroppedDown();
|
2009-01-12 11:20:59 -08:00
|
|
|
nsIFrame* comboFrame = do_QueryFrame(mComboboxFrame);
|
2007-05-17 04:12:30 -07:00
|
|
|
nsWeakFrame weakFrame(comboFrame);
|
2007-03-22 10:30:00 -07:00
|
|
|
mComboboxFrame->ShowDropDown(!isDroppedDown);
|
2007-05-17 04:12:30 -07:00
|
|
|
if (!weakFrame.IsAlive())
|
|
|
|
return NS_OK;
|
2007-03-22 10:30:00 -07:00
|
|
|
if (isDroppedDown) {
|
2011-10-17 07:59:28 -07:00
|
|
|
CaptureMouseEvents(false);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
// nsIDOMMouseMotionListener
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
nsresult
|
|
|
|
nsListControlFrame::MouseMove(nsIDOMEvent* aMouseEvent)
|
|
|
|
{
|
|
|
|
NS_ASSERTION(aMouseEvent, "aMouseEvent is null.");
|
2011-06-29 11:07:25 -07:00
|
|
|
nsCOMPtr<nsIDOMMouseEvent> mouseEvent = do_QueryInterface(aMouseEvent);
|
|
|
|
NS_ENSURE_TRUE(mouseEvent, NS_ERROR_FAILURE);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
UpdateInListState(aMouseEvent);
|
|
|
|
|
|
|
|
if (IsInDropDownMode()) {
|
|
|
|
if (mComboboxFrame->IsDroppedDown()) {
|
2012-08-22 08:56:38 -07:00
|
|
|
int32_t selectedIndex;
|
2007-03-22 10:30:00 -07:00
|
|
|
if (NS_SUCCEEDED(GetIndexFromDOMEvent(aMouseEvent, selectedIndex))) {
|
2013-08-08 15:04:59 -07:00
|
|
|
PerformSelection(selectedIndex, false, false); // might destroy us
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {// XXX - temporary until we get drag events
|
|
|
|
if (mButtonDown) {
|
2013-08-08 15:04:59 -07:00
|
|
|
return DragMove(aMouseEvent); // might destroy us
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
nsListControlFrame::DragMove(nsIDOMEvent* aMouseEvent)
|
|
|
|
{
|
|
|
|
NS_ASSERTION(aMouseEvent, "aMouseEvent is null.");
|
|
|
|
|
|
|
|
UpdateInListState(aMouseEvent);
|
|
|
|
|
|
|
|
if (!IsInDropDownMode()) {
|
2012-08-22 08:56:38 -07:00
|
|
|
int32_t selectedIndex;
|
2007-03-22 10:30:00 -07:00
|
|
|
if (NS_SUCCEEDED(GetIndexFromDOMEvent(aMouseEvent, selectedIndex))) {
|
|
|
|
// 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-28 23:19:26 -07:00
|
|
|
bool isControl;
|
2007-03-22 10:30:00 -07:00
|
|
|
#ifdef XP_MACOSX
|
|
|
|
mouseEvent->GetMetaKey(&isControl);
|
|
|
|
#else
|
|
|
|
mouseEvent->GetCtrlKey(&isControl);
|
|
|
|
#endif
|
2013-08-08 15:04:59 -07:00
|
|
|
nsWeakFrame weakFrame(this);
|
2007-03-22 10:30:00 -07:00
|
|
|
// Turn SHIFT on when you are dragging, unless control is on.
|
2011-09-28 23:19:26 -07:00
|
|
|
bool wasChanged = PerformSelection(selectedIndex,
|
2007-03-22 10:30:00 -07:00
|
|
|
!isControl, isControl);
|
2013-08-08 15:04:59 -07:00
|
|
|
if (!weakFrame.IsAlive()) {
|
|
|
|
return NS_OK;
|
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
mChangesSinceDragStart = mChangesSinceDragStart || wasChanged;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2007-05-17 04:12:30 -07:00
|
|
|
//----------------------------------------------------------------------
|
|
|
|
// Scroll helpers.
|
|
|
|
//----------------------------------------------------------------------
|
2013-08-02 00:08:13 -07:00
|
|
|
void
|
2012-08-22 08:56:38 -07:00
|
|
|
nsListControlFrame::ScrollToIndex(int32_t aIndex)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
if (aIndex < 0) {
|
|
|
|
// XXX shouldn't we just do nothing if we're asked to scroll to
|
|
|
|
// kNothingSelected?
|
2013-08-02 00:08:13 -07:00
|
|
|
ScrollTo(nsPoint(0, 0), nsIScrollableFrame::INSTANT);
|
2007-03-22 10:30:00 -07:00
|
|
|
} else {
|
2013-08-02 00:08:13 -07:00
|
|
|
nsRefPtr<dom::HTMLOptionElement> option =
|
2014-08-25 12:17:32 -07:00
|
|
|
GetOption(AssertedCast<uint32_t>(aIndex));
|
2013-08-02 00:08:13 -07:00
|
|
|
if (option) {
|
|
|
|
ScrollToFrame(*option);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-08-02 00:08:13 -07:00
|
|
|
void
|
|
|
|
nsListControlFrame::ScrollToFrame(dom::HTMLOptionElement& aOptElement)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2009-09-02 21:49:16 -07:00
|
|
|
// otherwise we find the content's frame and scroll to it
|
2013-08-02 00:08:13 -07:00
|
|
|
nsIFrame* childFrame = aOptElement.GetPrimaryFrame();
|
2009-09-02 21:49:16 -07:00
|
|
|
if (childFrame) {
|
2012-02-07 12:21:13 -08:00
|
|
|
PresContext()->PresShell()->
|
|
|
|
ScrollFrameRectIntoView(childFrame,
|
|
|
|
nsRect(nsPoint(0, 0), childFrame->GetSize()),
|
|
|
|
nsIPresShell::ScrollAxis(), nsIPresShell::ScrollAxis(),
|
|
|
|
nsIPresShell::SCROLL_OVERFLOW_HIDDEN |
|
|
|
|
nsIPresShell::SCROLL_FIRST_ANCESTOR_ONLY);
|
2007-03-22 10:30:00 -07: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
|
|
|
|
//
|
|
|
|
// aStartIndex - the index to start searching from
|
|
|
|
// aNewIndex - will get set to the new index if it finds one
|
|
|
|
// 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
|
|
|
|
//
|
|
|
|
// the aDoAdjustInc could be a "1" for a single item or
|
|
|
|
// any number greater representing a page of items
|
|
|
|
//
|
|
|
|
void
|
2012-08-22 08:56:38 -07:00
|
|
|
nsListControlFrame::AdjustIndexForDisabledOpt(int32_t aStartIndex,
|
|
|
|
int32_t &aNewIndex,
|
|
|
|
int32_t aNumOptions,
|
|
|
|
int32_t aDoAdjustInc,
|
|
|
|
int32_t aDoAdjustIncNext)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
// Cannot select anything if there is nothing to select
|
|
|
|
if (aNumOptions == 0) {
|
|
|
|
aNewIndex = kNothingSelected;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// means we reached the end of the list and now we are searching backwards
|
2011-09-28 23:19:26 -07:00
|
|
|
bool doingReverse = false;
|
2007-03-22 10:30:00 -07:00
|
|
|
// lowest index in the search range
|
2012-08-22 08:56:38 -07:00
|
|
|
int32_t bottom = 0;
|
2007-03-22 10:30:00 -07:00
|
|
|
// highest index in the search range
|
2012-08-22 08:56:38 -07:00
|
|
|
int32_t top = aNumOptions;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
// Start off keyboard options at selectedIndex if nothing else is defaulted to
|
|
|
|
//
|
|
|
|
// 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 08:56:38 -07:00
|
|
|
int32_t startIndex = aStartIndex;
|
2007-03-22 10:30:00 -07:00
|
|
|
if (startIndex < bottom) {
|
|
|
|
startIndex = GetSelectedIndex();
|
|
|
|
}
|
2012-08-22 08:56:38 -07:00
|
|
|
int32_t newIndex = startIndex + aDoAdjustInc;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
// make sure we start off in the range
|
|
|
|
if (newIndex < bottom) {
|
|
|
|
newIndex = 0;
|
|
|
|
} else if (newIndex >= top) {
|
|
|
|
newIndex = aNumOptions-1;
|
|
|
|
}
|
|
|
|
|
|
|
|
while (1) {
|
|
|
|
// if the newIndex isn't disabled, we are golden, bail out
|
2011-09-28 23:19:26 -07:00
|
|
|
bool isDisabled = true;
|
2007-03-22 10:30:00 -07:00
|
|
|
if (NS_SUCCEEDED(IsOptionDisabled(newIndex, isDisabled)) && !isDisabled) {
|
|
|
|
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;
|
|
|
|
aDoAdjustIncNext = 1;
|
2011-10-17 07:59:28 -07:00
|
|
|
doingReverse = true;
|
2007-03-22 10:30:00 -07:00
|
|
|
top = startIndex;
|
|
|
|
}
|
|
|
|
} 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;
|
|
|
|
aDoAdjustIncNext = -1;
|
2011-10-17 07:59:28 -07:00
|
|
|
doingReverse = true;
|
2007-03-22 10:30:00 -07:00
|
|
|
bottom = startIndex;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Looks like we found one
|
|
|
|
aNewIndex = newIndex;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsAString&
|
|
|
|
nsListControlFrame::GetIncrementalString()
|
|
|
|
{
|
2012-07-30 07:20:58 -07:00
|
|
|
if (sIncrementalString == nullptr)
|
2009-08-08 15:00:26 -07:00
|
|
|
sIncrementalString = new nsString();
|
|
|
|
|
|
|
|
return *sIncrementalString;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsListControlFrame::Shutdown()
|
|
|
|
{
|
|
|
|
delete sIncrementalString;
|
2012-07-30 07:20:58 -07:00
|
|
|
sIncrementalString = nullptr;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsListControlFrame::DropDownToggleKey(nsIDOMEvent* aKeyEvent)
|
|
|
|
{
|
|
|
|
// Cocoa widgets do native popups, so don't try to show
|
|
|
|
// dropdowns there.
|
|
|
|
if (IsInDropDownMode() && !nsComboboxControlFrame::ToolkitHasNativePopup()) {
|
2007-05-17 04:12:30 -07:00
|
|
|
aKeyEvent->PreventDefault();
|
2008-12-14 02:17:06 -08:00
|
|
|
if (!mComboboxFrame->IsDroppedDown()) {
|
2011-10-17 07:59:28 -07:00
|
|
|
mComboboxFrame->ShowDropDown(true);
|
2008-12-14 02:17:06 -08:00
|
|
|
} else {
|
|
|
|
nsWeakFrame weakFrame(this);
|
|
|
|
// mEndSelectionIndex is the last item that got selected.
|
|
|
|
ComboboxFinish(mEndSelectionIndex);
|
|
|
|
if (weakFrame.IsAlive()) {
|
|
|
|
FireOnChange();
|
|
|
|
}
|
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
2013-07-24 23:09:29 -07:00
|
|
|
nsListControlFrame::KeyDown(nsIDOMEvent* aKeyEvent)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2013-07-24 23:09:29 -07:00
|
|
|
MOZ_ASSERT(aKeyEvent, "aKeyEvent is null.");
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2014-04-02 21:18:36 -07:00
|
|
|
EventStates eventStates = mContent->AsElement()->State();
|
2013-07-24 23:09:29 -07:00
|
|
|
if (eventStates.HasState(NS_EVENT_STATE_DISABLED)) {
|
2007-03-22 10:30:00 -07:00
|
|
|
return NS_OK;
|
2013-07-24 23:09:29 -07:00
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2014-01-23 22:26:52 -08:00
|
|
|
AutoIncrementalSearchResetter incrementalSearchResetter;
|
|
|
|
|
2013-07-24 23:09:29 -07:00
|
|
|
// Don't check defaultPrevented value because other browsers don't prevent
|
|
|
|
// the key navigation of list control even if preventDefault() is called.
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2013-10-01 00:22:58 -07:00
|
|
|
const WidgetKeyboardEvent* keyEvent =
|
2013-10-17 23:10:24 -07:00
|
|
|
aKeyEvent->GetInternalNSEvent()->AsKeyboardEvent();
|
|
|
|
MOZ_ASSERT(keyEvent,
|
|
|
|
"DOM event must have WidgetKeyboardEvent for its internal event");
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2013-07-24 23:09:29 -07:00
|
|
|
if (keyEvent->IsAlt()) {
|
|
|
|
if (keyEvent->keyCode == NS_VK_UP || keyEvent->keyCode == NS_VK_DOWN) {
|
2007-03-22 10:30:00 -07:00
|
|
|
DropDownToggleKey(aKeyEvent);
|
|
|
|
}
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
// now make sure there are options or we are wasting our time
|
2013-08-02 00:08:19 -07:00
|
|
|
nsRefPtr<dom::HTMLOptionsCollection> options = GetOptions();
|
2007-03-22 10:30:00 -07:00
|
|
|
NS_ENSURE_TRUE(options, NS_ERROR_FAILURE);
|
|
|
|
|
2013-08-02 00:08:19 -07:00
|
|
|
uint32_t numOptions = options->Length();
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
// this is the new index to set
|
2012-08-22 08:56:38 -07:00
|
|
|
int32_t newIndex = kNothingSelected;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2013-07-24 23:09:29 -07:00
|
|
|
bool isControlOrMeta = (keyEvent->IsControl() || keyEvent->IsMeta());
|
2014-01-25 02:03:54 -08:00
|
|
|
// Don't try to handle multiple-select pgUp/pgDown in single-select lists.
|
|
|
|
if (isControlOrMeta && !GetMultiple() &&
|
|
|
|
(keyEvent->keyCode == NS_VK_PAGE_UP ||
|
|
|
|
keyEvent->keyCode == NS_VK_PAGE_DOWN)) {
|
|
|
|
return NS_OK;
|
|
|
|
}
|
2013-07-24 23:09:29 -07:00
|
|
|
if (isControlOrMeta && (keyEvent->keyCode == NS_VK_UP ||
|
|
|
|
keyEvent->keyCode == NS_VK_LEFT ||
|
|
|
|
keyEvent->keyCode == NS_VK_DOWN ||
|
2014-01-25 02:03:54 -08:00
|
|
|
keyEvent->keyCode == NS_VK_RIGHT ||
|
|
|
|
keyEvent->keyCode == NS_VK_HOME ||
|
|
|
|
keyEvent->keyCode == NS_VK_END)) {
|
|
|
|
// Don't go into multiple-select mode unless this list can handle it.
|
2013-07-24 23:09:29 -07:00
|
|
|
isControlOrMeta = mControlSelectMode = GetMultiple();
|
|
|
|
} else if (keyEvent->keyCode != NS_VK_SPACE) {
|
2011-10-17 07:59:28 -07:00
|
|
|
mControlSelectMode = false;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2013-07-24 23:09:29 -07:00
|
|
|
switch (keyEvent->keyCode) {
|
|
|
|
case NS_VK_UP:
|
|
|
|
case NS_VK_LEFT:
|
2007-03-22 10:30:00 -07:00
|
|
|
AdjustIndexForDisabledOpt(mEndSelectionIndex, newIndex,
|
2013-07-24 23:09:29 -07:00
|
|
|
static_cast<int32_t>(numOptions),
|
2007-03-22 10:30:00 -07:00
|
|
|
-1, -1);
|
2013-07-24 23:09:29 -07:00
|
|
|
break;
|
|
|
|
case NS_VK_DOWN:
|
|
|
|
case NS_VK_RIGHT:
|
2007-03-22 10:30:00 -07:00
|
|
|
AdjustIndexForDisabledOpt(mEndSelectionIndex, newIndex,
|
2013-07-24 23:09:29 -07:00
|
|
|
static_cast<int32_t>(numOptions),
|
2007-03-22 10:30:00 -07:00
|
|
|
1, 1);
|
2013-07-24 23:09:29 -07:00
|
|
|
break;
|
|
|
|
case NS_VK_RETURN:
|
2014-01-23 22:26:52 -08:00
|
|
|
if (IsInDropDownMode()) {
|
2007-03-22 10:30:00 -07:00
|
|
|
if (mComboboxFrame->IsDroppedDown()) {
|
2014-05-16 02:45:25 -07:00
|
|
|
// If the select element is a dropdown style, Enter key should be
|
|
|
|
// consumed while the dropdown is open for security.
|
|
|
|
aKeyEvent->PreventDefault();
|
|
|
|
|
2014-01-23 22:26:52 -08:00
|
|
|
nsWeakFrame weakFrame(this);
|
2007-03-22 10:30:00 -07:00
|
|
|
ComboboxFinish(mEndSelectionIndex);
|
2013-07-24 23:09:29 -07:00
|
|
|
if (!weakFrame.IsAlive()) {
|
2007-05-17 04:12:30 -07:00
|
|
|
return NS_OK;
|
2013-07-24 23:09:29 -07:00
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
2014-01-23 22:26:52 -08:00
|
|
|
// XXX This is strange. On other browsers, "change" event is fired
|
|
|
|
// immediately after the selected item is changed rather than
|
|
|
|
// Enter key is pressed.
|
2007-03-22 10:30:00 -07:00
|
|
|
FireOnChange();
|
|
|
|
return NS_OK;
|
|
|
|
}
|
2014-01-23 22:26:52 -08:00
|
|
|
|
|
|
|
// If this is single select listbox, Enter key doesn't cause anything.
|
|
|
|
if (!GetMultiple()) {
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2013-07-24 23:09:29 -07:00
|
|
|
newIndex = mEndSelectionIndex;
|
|
|
|
break;
|
|
|
|
case NS_VK_ESCAPE: {
|
2014-01-23 22:26:52 -08:00
|
|
|
// If the select element is a listbox style, Escape key causes nothing.
|
|
|
|
if (!IsInDropDownMode()) {
|
2007-05-17 04:12:30 -07:00
|
|
|
return NS_OK;
|
|
|
|
}
|
2014-01-23 22:26:52 -08:00
|
|
|
|
|
|
|
AboutToRollup();
|
|
|
|
// If the select element is a dropdown style, Enter key should be
|
|
|
|
// consumed everytime since Escape key may be pressed accidentally after
|
|
|
|
// the dropdown is closed by Escepe key.
|
|
|
|
aKeyEvent->PreventDefault();
|
|
|
|
return NS_OK;
|
2013-07-24 23:09:29 -07:00
|
|
|
}
|
|
|
|
case NS_VK_PAGE_UP: {
|
|
|
|
int32_t itemsPerPage =
|
|
|
|
std::max(1, static_cast<int32_t>(mNumDisplayRows - 1));
|
2007-03-22 10:30:00 -07:00
|
|
|
AdjustIndexForDisabledOpt(mEndSelectionIndex, newIndex,
|
2013-07-24 23:09:29 -07: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));
|
2007-03-22 10:30:00 -07:00
|
|
|
AdjustIndexForDisabledOpt(mEndSelectionIndex, newIndex,
|
2013-07-24 23:09:29 -07:00
|
|
|
static_cast<int32_t>(numOptions),
|
|
|
|
itemsPerPage, 1);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case NS_VK_HOME:
|
2007-03-22 10:30:00 -07:00
|
|
|
AdjustIndexForDisabledOpt(0, newIndex,
|
2013-07-24 23:09:29 -07:00
|
|
|
static_cast<int32_t>(numOptions),
|
2007-03-22 10:30:00 -07:00
|
|
|
0, 1);
|
2013-07-24 23:09:29 -07:00
|
|
|
break;
|
|
|
|
case NS_VK_END:
|
|
|
|
AdjustIndexForDisabledOpt(static_cast<int32_t>(numOptions) - 1, newIndex,
|
|
|
|
static_cast<int32_t>(numOptions),
|
2007-03-22 10:30:00 -07:00
|
|
|
0, -1);
|
2013-07-24 23:09:29 -07:00
|
|
|
break;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2014-02-10 14:57:01 -08:00
|
|
|
#if defined(XP_WIN)
|
2013-07-24 23:09:29 -07:00
|
|
|
case NS_VK_F4:
|
2014-01-30 04:12:02 -08:00
|
|
|
if (!isControlOrMeta) {
|
|
|
|
DropDownToggleKey(aKeyEvent);
|
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
return NS_OK;
|
|
|
|
#endif
|
|
|
|
|
2013-07-24 23:09:29 -07:00
|
|
|
default: // printable key will be handled by keypress event.
|
2014-01-23 22:26:52 -08:00
|
|
|
incrementalSearchResetter.Cancel();
|
2007-03-22 10:30:00 -07:00
|
|
|
return NS_OK;
|
2013-07-24 23:09:29 -07:00
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2013-07-24 23:09:29 -07:00
|
|
|
aKeyEvent->PreventDefault();
|
2013-07-19 07:32:51 -07:00
|
|
|
|
2013-07-24 23:09:29 -07: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;
|
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2013-07-24 23:09:29 -07:00
|
|
|
nsresult
|
|
|
|
nsListControlFrame::KeyPress(nsIDOMEvent* aKeyEvent)
|
|
|
|
{
|
|
|
|
MOZ_ASSERT(aKeyEvent, "aKeyEvent is null.");
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2014-04-02 21:18:36 -07:00
|
|
|
EventStates eventStates = mContent->AsElement()->State();
|
2013-07-24 23:09:29 -07:00
|
|
|
if (eventStates.HasState(NS_EVENT_STATE_DISABLED)) {
|
|
|
|
return NS_OK;
|
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2014-01-23 22:26:52 -08:00
|
|
|
AutoIncrementalSearchResetter incrementalSearchResetter;
|
|
|
|
|
2013-10-01 00:22:58 -07:00
|
|
|
const WidgetKeyboardEvent* keyEvent =
|
2013-10-17 23:10:24 -07:00
|
|
|
aKeyEvent->GetInternalNSEvent()->AsKeyboardEvent();
|
|
|
|
MOZ_ASSERT(keyEvent,
|
|
|
|
"DOM event must have WidgetKeyboardEvent for its internal event");
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2013-07-24 23:09:29 -07:00
|
|
|
// Select option with this as the first character
|
|
|
|
// XXX Not I18N compliant
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2013-07-24 23:09:29 -07:00
|
|
|
// Don't do incremental search if the key event has already consumed.
|
|
|
|
if (keyEvent->mFlags.mDefaultPrevented) {
|
|
|
|
return NS_OK;
|
|
|
|
}
|
2013-03-22 10:52:52 -07:00
|
|
|
|
2013-07-24 23:09:29 -07:00
|
|
|
if (keyEvent->IsAlt()) {
|
|
|
|
return NS_OK;
|
|
|
|
}
|
2013-03-22 10:52:52 -07:00
|
|
|
|
2013-07-24 23:09:29 -07: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 10:52:52 -07:00
|
|
|
|
2013-07-24 23:09:29 -07:00
|
|
|
bool isControlOrMeta = (keyEvent->IsControl() || keyEvent->IsMeta());
|
|
|
|
if (isControlOrMeta && keyEvent->charCode != ' ') {
|
|
|
|
return NS_OK;
|
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2013-07-24 23:09:29 -07: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) {
|
2014-01-23 22:26:52 -08:00
|
|
|
// Backspace key will delete the last char in the string. Otherwise,
|
|
|
|
// non-printable keypress should reset incremental search.
|
|
|
|
if (keyEvent->keyCode == NS_VK_BACK) {
|
|
|
|
incrementalSearchResetter.Cancel();
|
|
|
|
if (!GetIncrementalString().IsEmpty()) {
|
|
|
|
GetIncrementalString().Truncate(GetIncrementalString().Length() - 1);
|
|
|
|
}
|
2013-07-24 23:09:29 -07:00
|
|
|
aKeyEvent->PreventDefault();
|
2014-01-23 22:26:52 -08:00
|
|
|
} else {
|
|
|
|
// XXX When a select element has focus, even if the key causes nothing,
|
|
|
|
// it might be better to call preventDefault() here because nobody
|
|
|
|
// should expect one of other elements including chrome handles the
|
|
|
|
// key event.
|
2013-07-24 23:09:29 -07:00
|
|
|
}
|
|
|
|
return NS_OK;
|
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2014-01-23 22:26:52 -08:00
|
|
|
incrementalSearchResetter.Cancel();
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
// We ate the key if we got this far.
|
|
|
|
aKeyEvent->PreventDefault();
|
|
|
|
|
2013-07-24 23:09:29 -07: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;
|
|
|
|
}
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
GetIncrementalString().Truncate();
|
|
|
|
}
|
|
|
|
|
2013-07-24 23:09:29 -07:00
|
|
|
gLastKeyTime = keyEvent->time;
|
2011-09-27 18:46:11 -07:00
|
|
|
|
2013-07-24 23:09:29 -07:00
|
|
|
// Append this keystroke to the search string.
|
2014-01-04 07:02:17 -08:00
|
|
|
char16_t uniChar = ToLowerCase(static_cast<char16_t>(keyEvent->charCode));
|
2013-07-24 23:09:29 -07:00
|
|
|
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 00:08:19 -07:00
|
|
|
nsRefPtr<dom::HTMLOptionsCollection> options = GetOptions();
|
2013-07-24 23:09:29 -07:00
|
|
|
NS_ENSURE_TRUE(options, NS_ERROR_FAILURE);
|
|
|
|
|
2013-08-02 00:08:19 -07:00
|
|
|
uint32_t numOptions = options->Length();
|
2013-07-24 23:09:29 -07:00
|
|
|
|
2013-08-08 15:04:59 -07:00
|
|
|
nsWeakFrame weakFrame(this);
|
2013-07-24 23:09:29 -07:00
|
|
|
for (uint32_t i = 0; i < numOptions; ++i) {
|
|
|
|
uint32_t index = (i + startIndex) % numOptions;
|
2013-08-02 00:08:19 -07:00
|
|
|
nsRefPtr<dom::HTMLOptionElement> optionElement =
|
|
|
|
options->ItemAsOption(index);
|
2013-10-02 02:56:03 -07:00
|
|
|
if (!optionElement || !optionElement->GetPrimaryFrame()) {
|
2013-07-24 23:09:29 -07:00
|
|
|
continue;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
2013-07-24 23:09:29 -07:00
|
|
|
|
|
|
|
nsAutoString text;
|
|
|
|
if (NS_FAILED(optionElement->GetText(text)) ||
|
|
|
|
!StringBeginsWith(
|
|
|
|
nsContentUtils::TrimWhitespace<
|
|
|
|
nsContentUtils::IsHTMLWhitespaceOrNBSP>(text, false),
|
|
|
|
incrementalString, nsCaseInsensitiveStringComparator())) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2013-08-08 15:04:59 -07:00
|
|
|
bool wasChanged = PerformSelection(index, keyEvent->IsShift(), isControlOrMeta);
|
|
|
|
if (!weakFrame.IsAlive()) {
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
if (!wasChanged) {
|
2013-07-24 23:09:29 -07:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
// If UpdateSelection() returns false, that means the frame is no longer
|
|
|
|
// alive. We should stop doing anything.
|
|
|
|
if (!UpdateSelection()) {
|
|
|
|
return NS_OK;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
2013-07-24 23:09:29 -07:00
|
|
|
break;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2013-07-24 23:09:29 -07: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-08 15:04:59 -07:00
|
|
|
nsWeakFrame weakFrame(this);
|
2013-07-24 23:09:29 -07:00
|
|
|
bool wasChanged = false;
|
|
|
|
if (aIsControlOrMeta && !aIsShift && aCharCode != ' ') {
|
|
|
|
mStartSelectionIndex = aNewIndex;
|
|
|
|
mEndSelectionIndex = aNewIndex;
|
|
|
|
InvalidateFocus();
|
|
|
|
ScrollToIndex(aNewIndex);
|
2013-08-08 15:04:59 -07:00
|
|
|
if (!weakFrame.IsAlive()) {
|
|
|
|
return;
|
|
|
|
}
|
2013-07-24 23:09:29 -07:00
|
|
|
|
|
|
|
#ifdef ACCESSIBILITY
|
|
|
|
FireMenuItemActiveEvent();
|
|
|
|
#endif
|
|
|
|
} else if (mControlSelectMode && aCharCode == ' ') {
|
|
|
|
wasChanged = SingleSelection(aNewIndex, true);
|
|
|
|
} else {
|
|
|
|
wasChanged = PerformSelection(aNewIndex, aIsShift, aIsControlOrMeta);
|
|
|
|
}
|
2013-08-08 15:04:59 -07:00
|
|
|
if (wasChanged && weakFrame.IsAlive()) {
|
2013-07-24 23:09:29 -07:00
|
|
|
// dispatch event, update combobox, etc.
|
|
|
|
UpdateSelection();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
/******************************************************************************
|
|
|
|
* nsListEventListener
|
|
|
|
*****************************************************************************/
|
|
|
|
|
2014-04-27 00:06:00 -07:00
|
|
|
NS_IMPL_ISUPPORTS(nsListEventListener, nsIDOMEventListener)
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2011-06-29 11:07:25 -07:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsListEventListener::HandleEvent(nsIDOMEvent* aEvent)
|
|
|
|
{
|
|
|
|
if (!mFrame)
|
|
|
|
return NS_OK;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2011-06-29 11:07:25 -07:00
|
|
|
nsAutoString eventType;
|
|
|
|
aEvent->GetType(eventType);
|
2013-07-24 23:09:29 -07:00
|
|
|
if (eventType.EqualsLiteral("keydown"))
|
|
|
|
return mFrame->nsListControlFrame::KeyDown(aEvent);
|
2011-06-29 11:07:25 -07: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;
|
|
|
|
}
|