2017-10-27 20:33:53 +03:00
|
|
|
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
|
|
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
|
2012-05-21 15:12:37 +04:00
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
1999-09-03 18:25:15 +04:00
|
|
|
#include "nsSelectsAreaFrame.h"
|
2019-04-16 10:24:49 +03:00
|
|
|
|
|
|
|
#include "mozilla/PresShell.h"
|
1999-09-03 18:25:15 +04:00
|
|
|
#include "nsIContent.h"
|
2002-04-11 04:53:20 +04:00
|
|
|
#include "nsListControlFrame.h"
|
2006-01-26 05:29:17 +03:00
|
|
|
#include "nsDisplayList.h"
|
2015-02-08 18:31:14 +03:00
|
|
|
#include "WritingModes.h"
|
|
|
|
|
|
|
|
using namespace mozilla;
|
1999-09-03 18:25:15 +04:00
|
|
|
|
2019-04-16 10:24:49 +03:00
|
|
|
nsContainerFrame* NS_NewSelectsAreaFrame(PresShell* aShell,
|
2018-03-22 21:20:41 +03:00
|
|
|
ComputedStyle* aStyle,
|
|
|
|
nsFrameState aFlags) {
|
2019-02-05 19:45:54 +03:00
|
|
|
nsSelectsAreaFrame* it =
|
|
|
|
new (aShell) nsSelectsAreaFrame(aStyle, aShell->GetPresContext());
|
2005-11-04 05:38:33 +03:00
|
|
|
|
2013-08-03 08:11:06 +04:00
|
|
|
// We need NS_BLOCK_FLOAT_MGR to ensure that the options inside the select
|
|
|
|
// aren't expanded by right floats outside the select.
|
2016-09-09 10:26:57 +03:00
|
|
|
it->AddStateBits(aFlags | NS_BLOCK_FLOAT_MGR);
|
2005-11-04 05:38:33 +03:00
|
|
|
|
|
|
|
return it;
|
1999-09-03 18:25:15 +04:00
|
|
|
}
|
|
|
|
|
2009-09-12 20:49:24 +04:00
|
|
|
NS_IMPL_FRAMEARENA_HELPERS(nsSelectsAreaFrame)
|
|
|
|
|
1999-09-03 18:25:15 +04:00
|
|
|
//---------------------------------------------------------
|
2006-01-26 05:29:17 +03:00
|
|
|
/**
|
|
|
|
* This wrapper class lets us redirect mouse hits from the child frame of
|
|
|
|
* an option element to the element's own frame.
|
|
|
|
* REVIEW: This is what nsSelectsAreaFrame::GetFrameForPoint used to do
|
|
|
|
*/
|
|
|
|
class nsDisplayOptionEventGrabber : public nsDisplayWrapList {
|
|
|
|
public:
|
2010-08-13 14:01:13 +04:00
|
|
|
nsDisplayOptionEventGrabber(nsDisplayListBuilder* aBuilder, nsIFrame* aFrame,
|
|
|
|
nsDisplayItem* aItem)
|
|
|
|
: nsDisplayWrapList(aBuilder, aFrame, aItem) {}
|
|
|
|
nsDisplayOptionEventGrabber(nsDisplayListBuilder* aBuilder, nsIFrame* aFrame,
|
|
|
|
nsDisplayList* aList)
|
|
|
|
: nsDisplayWrapList(aBuilder, aFrame, aList) {}
|
2010-04-08 04:31:26 +04:00
|
|
|
virtual void HitTest(nsDisplayListBuilder* aBuilder, const nsRect& aRect,
|
2015-03-21 19:28:04 +03:00
|
|
|
HitTestState* aState,
|
|
|
|
nsTArray<nsIFrame*>* aOutFrames) override;
|
|
|
|
virtual bool ShouldFlattenAway(nsDisplayListBuilder* aBuilder) override {
|
2014-06-09 08:47:59 +04:00
|
|
|
return false;
|
|
|
|
}
|
2010-07-16 01:07:49 +04:00
|
|
|
NS_DISPLAY_DECL_NAME("OptionEventGrabber", TYPE_OPTION_EVENT_GRABBER)
|
2006-01-26 05:29:17 +03:00
|
|
|
};
|
1999-09-03 18:25:15 +04:00
|
|
|
|
2010-04-08 04:31:26 +04:00
|
|
|
void nsDisplayOptionEventGrabber::HitTest(nsDisplayListBuilder* aBuilder,
|
|
|
|
const nsRect& aRect,
|
|
|
|
HitTestState* aState,
|
|
|
|
nsTArray<nsIFrame*>* aOutFrames) {
|
|
|
|
nsTArray<nsIFrame*> outFrames;
|
|
|
|
mList.HitTest(aBuilder, aRect, aState, &outFrames);
|
2000-03-22 05:43:08 +03:00
|
|
|
|
2012-08-22 19:56:38 +04:00
|
|
|
for (uint32_t i = 0; i < outFrames.Length(); i++) {
|
2010-04-08 04:31:26 +04:00
|
|
|
nsIFrame* selectedFrame = outFrames.ElementAt(i);
|
2006-01-26 05:29:17 +03:00
|
|
|
while (selectedFrame &&
|
2011-08-08 19:14:33 +04:00
|
|
|
!(selectedFrame->GetContent() &&
|
2015-03-03 14:08:59 +03:00
|
|
|
selectedFrame->GetContent()->IsHTMLElement(nsGkAtoms::option))) {
|
2003-06-30 14:46:59 +04:00
|
|
|
selectedFrame = selectedFrame->GetParent();
|
2005-09-19 06:15:54 +04:00
|
|
|
}
|
2003-06-30 14:46:59 +04:00
|
|
|
if (selectedFrame) {
|
2010-04-08 04:31:26 +04:00
|
|
|
aOutFrames->AppendElement(selectedFrame);
|
|
|
|
} else {
|
|
|
|
// keep the original result, which could be this frame
|
|
|
|
aOutFrames->AppendElement(outFrames.ElementAt(i));
|
2000-03-22 05:43:08 +03:00
|
|
|
}
|
|
|
|
}
|
2006-01-26 05:29:17 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
class nsOptionEventGrabberWrapper : public nsDisplayWrapper {
|
|
|
|
public:
|
|
|
|
nsOptionEventGrabberWrapper() {}
|
|
|
|
virtual nsDisplayItem* WrapList(nsDisplayListBuilder* aBuilder,
|
2017-11-06 06:37:28 +03:00
|
|
|
nsIFrame* aFrame,
|
|
|
|
nsDisplayList* aList) override {
|
2018-02-13 03:43:28 +03:00
|
|
|
return MakeDisplayItem<nsDisplayOptionEventGrabber>(aBuilder, aFrame,
|
|
|
|
aList);
|
2006-01-26 05:29:17 +03:00
|
|
|
}
|
|
|
|
virtual nsDisplayItem* WrapItem(nsDisplayListBuilder* aBuilder,
|
2017-11-06 06:37:28 +03:00
|
|
|
nsDisplayItem* aItem) override {
|
2018-02-13 03:43:28 +03:00
|
|
|
return MakeDisplayItem<nsDisplayOptionEventGrabber>(aBuilder,
|
|
|
|
aItem->Frame(), aItem);
|
2006-01-26 05:29:17 +03:00
|
|
|
}
|
|
|
|
};
|
2002-04-11 04:53:20 +04:00
|
|
|
|
2006-01-26 05:29:17 +03:00
|
|
|
static nsListControlFrame* GetEnclosingListFrame(nsIFrame* aSelectsAreaFrame) {
|
|
|
|
nsIFrame* frame = aSelectsAreaFrame->GetParent();
|
2003-04-09 00:50:57 +04:00
|
|
|
while (frame) {
|
2017-04-30 18:30:08 +03:00
|
|
|
if (frame->IsListControlFrame())
|
2007-07-08 11:08:04 +04:00
|
|
|
return static_cast<nsListControlFrame*>(frame);
|
2003-06-30 14:46:59 +04:00
|
|
|
frame = frame->GetParent();
|
2003-04-09 00:50:57 +04:00
|
|
|
}
|
2012-07-30 18:20:58 +04:00
|
|
|
return nullptr;
|
2006-01-26 05:29:17 +03:00
|
|
|
}
|
|
|
|
|
2019-05-08 16:49:56 +03:00
|
|
|
class nsDisplayListFocus : public nsPaintedDisplayItem {
|
2006-04-18 06:41:42 +04:00
|
|
|
public:
|
2010-08-13 14:01:13 +04:00
|
|
|
nsDisplayListFocus(nsDisplayListBuilder* aBuilder, nsSelectsAreaFrame* aFrame)
|
2019-05-08 16:49:56 +03:00
|
|
|
: nsPaintedDisplayItem(aBuilder, aFrame) {
|
2006-04-18 06:41:42 +04:00
|
|
|
MOZ_COUNT_CTOR(nsDisplayListFocus);
|
|
|
|
}
|
|
|
|
#ifdef NS_BUILD_REFCNT_LOGGING
|
|
|
|
virtual ~nsDisplayListFocus() { MOZ_COUNT_DTOR(nsDisplayListFocus); }
|
|
|
|
#endif
|
|
|
|
|
2017-08-24 18:09:44 +03:00
|
|
|
virtual nsRect GetBounds(nsDisplayListBuilder* aBuilder,
|
|
|
|
bool* aSnap) const override {
|
2012-04-10 15:24:18 +04:00
|
|
|
*aSnap = false;
|
2006-04-18 06:41:42 +04:00
|
|
|
// override bounds because the list item focus ring may extend outside
|
|
|
|
// the nsSelectsAreaFrame
|
2013-04-19 16:02:13 +04:00
|
|
|
nsListControlFrame* listFrame = GetEnclosingListFrame(Frame());
|
2011-10-21 21:45:32 +04:00
|
|
|
return listFrame->GetVisualOverflowRectRelativeToSelf() +
|
2012-09-16 14:32:59 +04:00
|
|
|
listFrame->GetOffsetToCrossDoc(ReferenceFrame());
|
2006-04-18 06:41:42 +04:00
|
|
|
}
|
2009-09-07 04:35:14 +04:00
|
|
|
virtual void Paint(nsDisplayListBuilder* aBuilder,
|
2017-06-09 22:14:53 +03:00
|
|
|
gfxContext* aCtx) override {
|
2013-04-19 16:02:13 +04:00
|
|
|
nsListControlFrame* listFrame = GetEnclosingListFrame(Frame());
|
2006-04-18 06:41:42 +04:00
|
|
|
// listFrame must be non-null or we wouldn't get called.
|
2015-12-04 06:16:59 +03:00
|
|
|
listFrame->PaintFocus(aCtx->GetDrawTarget(),
|
|
|
|
aBuilder->ToReferenceFrame(listFrame));
|
2006-04-18 06:41:42 +04:00
|
|
|
}
|
2010-07-16 01:07:49 +04:00
|
|
|
NS_DISPLAY_DECL_NAME("ListFocus", TYPE_LIST_FOCUS)
|
2006-04-18 06:41:42 +04:00
|
|
|
};
|
2003-04-09 00:50:57 +04:00
|
|
|
|
2006-01-26 05:29:17 +03:00
|
|
|
void nsSelectsAreaFrame::BuildDisplayList(nsDisplayListBuilder* aBuilder,
|
|
|
|
const nsDisplayListSet& aLists) {
|
2013-02-14 15:12:27 +04:00
|
|
|
if (!aBuilder->IsForEventDelivery()) {
|
2017-08-07 05:23:35 +03:00
|
|
|
BuildDisplayListInternal(aBuilder, aLists);
|
2013-02-14 15:12:27 +04:00
|
|
|
return;
|
|
|
|
}
|
2013-03-06 15:08:14 +04:00
|
|
|
|
2017-10-17 05:19:44 +03:00
|
|
|
nsDisplayListCollection set(aBuilder);
|
2017-08-07 05:23:35 +03:00
|
|
|
BuildDisplayListInternal(aBuilder, set);
|
2017-07-06 15:00:35 +03:00
|
|
|
|
2006-01-26 05:29:17 +03:00
|
|
|
nsOptionEventGrabberWrapper wrapper;
|
2013-02-14 15:12:27 +04:00
|
|
|
wrapper.WrapLists(aBuilder, this, set, aLists);
|
2006-01-26 05:29:17 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void nsSelectsAreaFrame::BuildDisplayListInternal(
|
|
|
|
nsDisplayListBuilder* aBuilder, const nsDisplayListSet& aLists) {
|
2017-08-07 05:23:35 +03:00
|
|
|
nsBlockFrame::BuildDisplayList(aBuilder, aLists);
|
2006-01-26 05:29:17 +03:00
|
|
|
|
|
|
|
nsListControlFrame* listFrame = GetEnclosingListFrame(this);
|
|
|
|
if (listFrame && listFrame->IsFocused()) {
|
|
|
|
// we can't just associate the display item with the list frame,
|
|
|
|
// because then the list's scrollframe won't clip it (the scrollframe
|
|
|
|
// only clips contained descendants).
|
2019-04-01 19:53:11 +03:00
|
|
|
aLists.Outlines()->AppendNewToTop<nsDisplayListFocus>(aBuilder, this);
|
2006-01-26 05:29:17 +03:00
|
|
|
}
|
2002-04-11 07:25:58 +04:00
|
|
|
}
|
Bug 300030: Move intrinsic width computation out of nsIFrame::Reflow and into its own methods on nsIFrame. Replace reflow reasons, types, and commands with dirty bits/notifications. Thanks to bzbarsky for almost all of the HTML form controls (mozilla/layout/forms) changes, and many others for help testing and patching. For detailed commit logs, see REFLOW_YYYYMMDD_BRANCH, where YYYYMMDD is one of 20061031, 20060830, 20060603, 20060302, 20060119, 20051011, 20050804, 20050429, 20050315, 20050111, and 20041213.
2006-12-08 08:38:33 +03:00
|
|
|
|
2017-07-06 15:00:35 +03:00
|
|
|
void nsSelectsAreaFrame::Reflow(nsPresContext* aPresContext,
|
2016-07-21 13:36:38 +03:00
|
|
|
ReflowOutput& aDesiredSize,
|
2017-07-06 15:00:35 +03:00
|
|
|
const ReflowInput& aReflowInput,
|
Bug 300030: Move intrinsic width computation out of nsIFrame::Reflow and into its own methods on nsIFrame. Replace reflow reasons, types, and commands with dirty bits/notifications. Thanks to bzbarsky for almost all of the HTML form controls (mozilla/layout/forms) changes, and many others for help testing and patching. For detailed commit logs, see REFLOW_YYYYMMDD_BRANCH, where YYYYMMDD is one of 20061031, 20060830, 20060603, 20060302, 20060119, 20051011, 20050804, 20050429, 20050315, 20050111, and 20041213.
2006-12-08 08:38:33 +03:00
|
|
|
nsReflowStatus& aStatus) {
|
2017-09-13 13:00:25 +03:00
|
|
|
MOZ_ASSERT(aStatus.IsEmpty(), "Caller should pass a fresh reflow status!");
|
|
|
|
|
Bug 300030: Move intrinsic width computation out of nsIFrame::Reflow and into its own methods on nsIFrame. Replace reflow reasons, types, and commands with dirty bits/notifications. Thanks to bzbarsky for almost all of the HTML form controls (mozilla/layout/forms) changes, and many others for help testing and patching. For detailed commit logs, see REFLOW_YYYYMMDD_BRANCH, where YYYYMMDD is one of 20061031, 20060830, 20060603, 20060302, 20060119, 20051011, 20050804, 20050429, 20050315, 20050111, and 20041213.
2006-12-08 08:38:33 +03:00
|
|
|
nsListControlFrame* list = GetEnclosingListFrame(this);
|
|
|
|
NS_ASSERTION(list,
|
|
|
|
"Must have an nsListControlFrame! Frame constructor is "
|
|
|
|
"broken");
|
2015-02-08 18:31:14 +03:00
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
bool isInDropdownMode = list->IsInDropDownMode();
|
2015-02-08 18:31:14 +03:00
|
|
|
|
Bug 300030: Move intrinsic width computation out of nsIFrame::Reflow and into its own methods on nsIFrame. Replace reflow reasons, types, and commands with dirty bits/notifications. Thanks to bzbarsky for almost all of the HTML form controls (mozilla/layout/forms) changes, and many others for help testing and patching. For detailed commit logs, see REFLOW_YYYYMMDD_BRANCH, where YYYYMMDD is one of 20061031, 20060830, 20060603, 20060302, 20060119, 20051011, 20050804, 20050429, 20050315, 20050111, and 20041213.
2006-12-08 08:38:33 +03:00
|
|
|
// See similar logic in nsListControlFrame::Reflow and
|
|
|
|
// nsListControlFrame::ReflowAsDropdown. We need to match it here.
|
2016-07-21 13:36:39 +03:00
|
|
|
WritingMode wm = aReflowInput.GetWritingMode();
|
2015-02-08 18:31:14 +03:00
|
|
|
nscoord oldBSize;
|
Bug 300030: Move intrinsic width computation out of nsIFrame::Reflow and into its own methods on nsIFrame. Replace reflow reasons, types, and commands with dirty bits/notifications. Thanks to bzbarsky for almost all of the HTML form controls (mozilla/layout/forms) changes, and many others for help testing and patching. For detailed commit logs, see REFLOW_YYYYMMDD_BRANCH, where YYYYMMDD is one of 20061031, 20060830, 20060603, 20060302, 20060119, 20051011, 20050804, 20050429, 20050315, 20050111, and 20041213.
2006-12-08 08:38:33 +03:00
|
|
|
if (isInDropdownMode) {
|
2015-02-08 18:31:14 +03:00
|
|
|
// Store the block size now in case it changes during
|
2008-12-29 18:07:38 +03:00
|
|
|
// nsBlockFrame::Reflow for some odd reason.
|
Bug 300030: Move intrinsic width computation out of nsIFrame::Reflow and into its own methods on nsIFrame. Replace reflow reasons, types, and commands with dirty bits/notifications. Thanks to bzbarsky for almost all of the HTML form controls (mozilla/layout/forms) changes, and many others for help testing and patching. For detailed commit logs, see REFLOW_YYYYMMDD_BRANCH, where YYYYMMDD is one of 20061031, 20060830, 20060603, 20060302, 20060119, 20051011, 20050804, 20050429, 20050315, 20050111, and 20041213.
2006-12-08 08:38:33 +03:00
|
|
|
if (!(GetStateBits() & NS_FRAME_FIRST_REFLOW)) {
|
2015-02-08 18:31:14 +03:00
|
|
|
oldBSize = BSize(wm);
|
Bug 300030: Move intrinsic width computation out of nsIFrame::Reflow and into its own methods on nsIFrame. Replace reflow reasons, types, and commands with dirty bits/notifications. Thanks to bzbarsky for almost all of the HTML form controls (mozilla/layout/forms) changes, and many others for help testing and patching. For detailed commit logs, see REFLOW_YYYYMMDD_BRANCH, where YYYYMMDD is one of 20061031, 20060830, 20060603, 20060302, 20060119, 20051011, 20050804, 20050429, 20050315, 20050111, and 20041213.
2006-12-08 08:38:33 +03:00
|
|
|
} else {
|
2015-02-08 18:31:14 +03:00
|
|
|
oldBSize = NS_UNCONSTRAINEDSIZE;
|
Bug 300030: Move intrinsic width computation out of nsIFrame::Reflow and into its own methods on nsIFrame. Replace reflow reasons, types, and commands with dirty bits/notifications. Thanks to bzbarsky for almost all of the HTML form controls (mozilla/layout/forms) changes, and many others for help testing and patching. For detailed commit logs, see REFLOW_YYYYMMDD_BRANCH, where YYYYMMDD is one of 20061031, 20060830, 20060603, 20060302, 20060119, 20051011, 20050804, 20050429, 20050315, 20050111, and 20041213.
2006-12-08 08:38:33 +03:00
|
|
|
}
|
|
|
|
}
|
2015-02-08 18:31:14 +03:00
|
|
|
|
2016-07-21 13:36:39 +03:00
|
|
|
nsBlockFrame::Reflow(aPresContext, aDesiredSize, aReflowInput, aStatus);
|
Bug 300030: Move intrinsic width computation out of nsIFrame::Reflow and into its own methods on nsIFrame. Replace reflow reasons, types, and commands with dirty bits/notifications. Thanks to bzbarsky for almost all of the HTML form controls (mozilla/layout/forms) changes, and many others for help testing and patching. For detailed commit logs, see REFLOW_YYYYMMDD_BRANCH, where YYYYMMDD is one of 20061031, 20060830, 20060603, 20060302, 20060119, 20051011, 20050804, 20050429, 20050315, 20050111, and 20041213.
2006-12-08 08:38:33 +03:00
|
|
|
|
2015-02-08 18:31:14 +03:00
|
|
|
// Check whether we need to suppress scrollbar updates. We want to do
|
|
|
|
// that if we're in a possible first pass and our block size of a row
|
|
|
|
// has changed.
|
Bug 300030: Move intrinsic width computation out of nsIFrame::Reflow and into its own methods on nsIFrame. Replace reflow reasons, types, and commands with dirty bits/notifications. Thanks to bzbarsky for almost all of the HTML form controls (mozilla/layout/forms) changes, and many others for help testing and patching. For detailed commit logs, see REFLOW_YYYYMMDD_BRANCH, where YYYYMMDD is one of 20061031, 20060830, 20060603, 20060302, 20060119, 20051011, 20050804, 20050429, 20050315, 20050111, and 20041213.
2006-12-08 08:38:33 +03:00
|
|
|
if (list->MightNeedSecondPass()) {
|
2015-02-08 18:31:14 +03:00
|
|
|
nscoord newBSizeOfARow = list->CalcBSizeOfARow();
|
|
|
|
// We'll need a second pass if our block size of a row changed. For
|
|
|
|
// comboboxes, we'll also need it if our block size changed. If
|
|
|
|
// we're going to do a second pass, suppress scrollbar updates for
|
|
|
|
// this pass.
|
|
|
|
if (newBSizeOfARow != mBSizeOfARow ||
|
|
|
|
(isInDropdownMode &&
|
|
|
|
(oldBSize != aDesiredSize.BSize(wm) || oldBSize != BSize(wm)))) {
|
|
|
|
mBSizeOfARow = newBSizeOfARow;
|
2011-10-17 18:59:28 +04:00
|
|
|
list->SetSuppressScrollbarUpdate(true);
|
Bug 300030: Move intrinsic width computation out of nsIFrame::Reflow and into its own methods on nsIFrame. Replace reflow reasons, types, and commands with dirty bits/notifications. Thanks to bzbarsky for almost all of the HTML form controls (mozilla/layout/forms) changes, and many others for help testing and patching. For detailed commit logs, see REFLOW_YYYYMMDD_BRANCH, where YYYYMMDD is one of 20061031, 20060830, 20060603, 20060302, 20060119, 20051011, 20050804, 20050429, 20050315, 20050111, and 20041213.
2006-12-08 08:38:33 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|