mirror of
https://github.com/roytam1/palemoon27.git
synced 2026-05-27 04:39:37 +00:00
fb49d72bb0
- Bug 1252882 - Content-Signature Service - some tests r=keeler,r=fkiefer (7fc1f726a4)
- Bug 1265085 - Replace verification source with a SAN in the content signature verifier interface. r=Cykesiopka,r=fkiefer (0881ba797d)
- Bug 1264706: Move nsILocalCertService, and implementation, to security/manager/ssl in order to alloow use w use elsewhere in gecko. r=dkeeler (6f2200f2a6)
- Bug 1219088 - Clear the session cache when a weak crypto override is revoked. r=keeler (456e2ce3e6)
- Bug 550185 - Ensure nsCertTree::GetCellText returns an initialized value. r=kaie (ee356452a5)
- Bug 1252384 - Remove nsICertTree.isHostPortOverride(). r=dkeele It is unused since the changes in Bug 825583 landed. (61400adad7)
- reorder as Bug 1411458 (600fc338a9)
- bug 1264761 - improve handling of x509 versions in certificate manager r=Cykesiopka (a89237c66d)
- Bug 1263857 - (followup) Disable windows crash reporter on automated tests. r=sfink (bb9581fec9)
- bug 1263221 - improve how PSM handles the visibility of __CERT_AddTempCertToPerm r=chmanchester,mgoodwin (d9fd09d9a6)
- bug 1182742 - allow users to override small key size errors r=rbarnes (b09074987b)
- Bug 1252722 - Fully implement nsNSSShutDownObject everywhere. r=keeler (8c1a8df597)
- Bug 1252722 - Use smart pointers for NSS resources. r=keeler (b2ef34f9d2)
- Bug 1252722 - Ensure arguments of all public methods are checked. r=keeler (7064697e25)
- bug 1242032 - change some pipnss logging output from Debug to Verbose r=Cykesiopka (516c52da9f)
- Bug 1252722 - Improve handling of PK11_* function error codes. r=keeler (b47d13bd7e)
- Bug 1251801 - Ensure arguments of all public methods are checked. r=keeler (ffe77174e7)
- Bug 1127158 - Remove brittle debug only flag math in nsSecureBrowserUIImpl.cpp. r=dkeeler (410d25dc3e)
- Bug 1257246: Update security/manager for eslint 2. r=cykesiopka (bbdcf78264)
- bug 1218515 - flip pinning-test.badssl.com into production mode r=jcj DONTBUILD NPOTB (0d93e78cab)
- Bug 1199624 - Don't use memset and memcmp in files that don't include cstring explicitly. r=briansmith (5a938e056c)
- Bug 1154399 - Part 1: De-templatize and un-inline IntegralValue. r=keeler (bcaa11a646)
- Bug 1154399 - Part 2: Simplify and un-inline OptionalVersion. r=keeler (a5a9bb5e46)
- Bug 1154399 - Part 3: Simplify OptionalExtensions. r=keeler (0d3f613cde)
- Bug 1154399 - Part 4: Simplify certificate parsing in OCSP responses. r=keeler (94aa90a96d)
- Bug 1189020 - Replace |// unnamed namespace| with |// namespace| in mozilla::pkix. r=Cykesiopka (bb016e13ac)
- bug 1255153 - (re)move redundant xpcshell name constraint tests to gtests r=Cykesiopka,jcj (d8597a3bb1)
- bug 1248099 - add extended key usage tests for mozilla::pkix r=Cykesiopka,jcj (f9c11a8ecc)
- Bug 1266298 - Add sys_fchmod to seccomp whitelist r=jld (e16608d738)
- Bug 1268579 - Add inotify_rm_watch to the seccomp-bpf whitelist. r=jld (c20823e237)
- Bug 1176099 - Add hooks for sigprocmask/pthread_sigmask. r=jld r=glandium (55d16a8e41)
- Bug 1176099 - Fix missing NULL check r=luke (2f6e6e3836)
- Bug 1245789 - Use ifdef MOZ_WIDEVINE_EME to prevent compilation when not enabled. r=gerald (40d13ca2d9)
- Bug 1267453 - Amazon Widevine rejects HDCP on MacBook Pro with or without an external display. r=gcp (5366006c54)
- Bug 1268379 - Delay WMF checks in GMPParent - r=jesup (0f6642fdcc)
- bit of Bug 1245789 - Push detection of WMF decoding (e60b0634de)
- missing bit of 1267453 (573b867a62)
- Bug 1243594 (part 3) - leave the utf-8 encoding of the payload to rest.js instead of directly in loop. r=Standard8 (7781df1275)
- Bug 1243594 (part 2) - have rest.js automatically encode the request body as utf-8. r=gfritzsche (fd98dddf43)
- Bug 1246938 - Allow extra headers to be passed via hawk requests. r=markh (3692244524)
- Bug 1239354: Replace old-style generator function with star functions. r=asuth (a7793a89aa)
- Bug 1217982 - Remove for-each from storage/. r=mak (bbff0f0b7b)
- Bug 1223510, part 1 - Always finishTest() in test_nonUnicode.html. r=baku (ba3fb681ad)
- Bug 1223510, part 2 - Make ArchiveReader tests use pushPrefEnv. r=baku (5a4a5f9a7a)
- Bug 1223510, part 3 - Change where generator is created. r=baku Mostly this lets us take advantage of things created during the initial setup. (ee337d83de)
- Bug 1220304 - Part 1 - Make test_XHRSendData.html use SpecialPowers.createFiles(). r=baku (91fc25f3b7)
- Bug 1220304 - Part 2 - Make ArchiveReader tests use SpecialPowers.createFiles(). r=baku (5a0bfc4200)
- Bug 1267966 - Remove the deprecation warning from Attr.ownerElement; r=baku (cfd8910f2f)
- Bug 1269646 - Console API should be NOP after window-inner-destroyed, r=smaug (c4e5959d1f)
- Bug 1263392 - ConsoleCallData::mStatus should be set also when ConsoleCallData is not used in workers, r=smaug (10358e33a1)
- Bug 1268361 - Strip leading '?' in new URLSearchParams(query), r=smaug (a1a5075185)
- Bug 1052139 - Make more objects on the global prototype chain have immutable [[Prototype]], when we enable enforcement of this requirement. r=bz (8e48cfc3d6)
- Bug 1267932 - Update EventSource.webidl, r=ehsan (41532a54d5)
- Bug 1269383 - Remove dom.server-events.enabled pref, r=smaug (21e65b8436)
- Bug 1237077 - Part 3: use createCodebasePrincipal. r=tanvi (7da7268d47)
- Bug 1268721, part 1 - Use early continue in TransferableToIPCTransferable. r=jimm (317ab04f38)
- Bug 1268721, part 2 - Null check first argument to nsContentUtils::GetSurfaceData(). r=jimm (544d181021)
- Bug 1272203 (part 3) - Use NotNull in nsContentUtils::GetSurfaceData(). r=froydnj. (65e488c4f8)
- Bug 1272203 (part 1) - Add mozilla::NotNull to MFBT. r=froydnj. (4653d120fc)
- Bug 964092: don't let DOM DataChannels get GC'd if they have an active callback r=smaug,jib (c9c291f44a)
- Bug 1224186: Implement DOMTokenlist.replace r=baku,Ms2ger (329f4f942e)
- Bug 1265715 - Part 1. Pull Mode out of nsDisplayListBuilder; r=jfkthame (2c7cae0f3a)
- Bug 1265715 - Part 2. Add nsDisplayListBuilderMode parameter into nsLayoutUtils::PaintFrame; r=jfkthame (5ecabbda5d)
- Bug 1264949 - Ensure that the display list does not contain any background-image/background-color display item; r=jfkthame (018a7aec15)
- Bug 1265715 - Part 3. Use nsLayoutUtils::PaintFrame in ClipBackgroundByText; r=jfkthame (182a700fa6)
- Bug 1265715 - Part 4. Fix transform problem; r=jfkthame (37f77bf24b)
- Bug 1265715 - Part 5. bg-clip:text transform reftest; r=jfkthame (44778bcfd7)
- Bug 1267209 - Convert nsLayoutUtils::PaintFrame flags to be an enum class. r=jfkthame (4f304b84f1)
- Bug 1265280 - Temporary debugging code to crash with a useful abort message. r=khuey (43d532166f)
- Bug 1232939 - Ensure the opaque region of a fixed background layer is correctly clipped. r=mstange (cc2118e0a0)
- Bug 735857 - Treat background-attachment:fixed as background-attachment:scroll if it's on a non-root element affected by a transform. r=mstange (273d62aabf)
- Bug 735857 - Factor out a helper function nsLayoutUtils::IsTransformed(). r=mstange (61528fafef)
- Bug 1263286 - Move base-uri CSP check into SetBaseURIUsingFirstBaseWithHref. r=bz (03114b2fcb)
- Bug 1227327 - Allow specifying a background rect for background dislay items. r=mattwoodrow (410ef269eb)
- Bug 1227327 - Make fieldset frames build nsDisplayBackgroundImage items. r=mattwoodrow (9a3a8953b4)
- Fix temporary debugging patch for bug 1265280 so we'll hit the condition. r=khuey (fd30f8f0b4)
- Bug 1265715 - followup - Correct dirty region; r=me (38fc76e698)
- Bug 550426 - Use background-position-x/y in ActiveLayerTracker. r=dbaron (4f154a39dd)
- Bug 1266131 part 1 - [css-grid] 'order' doesn't apply to grid-aligned abs.pos. descendants (anymore). r=dholbert (ba8aa18fea)
- Bug 1266131 part 2 - [css-grid] Remove unused nsDisplayList::SortByCSSOrder() function. r=dholbert (b676c48a26)
- Bug 550426 - Add support for {background,mask}-position-{x,y}, most of the style system changes. r=dbaron (3739a8ec58)
- Bug 550426 - Add support for {background,mask}-position-{x,y}, StyleAnimation changes. r=dbaron (0fd2f97a60)
- Bug 852754 - Part 4: Reduce max downscaling allowed to <3. r=mstange (399b851221)
- Bug 1266868, part 1 - Fix nsCSSValue::Array leaks in the StyleAnimationValue code. r=dholbert (c6fc4f7d9c)
- Bug 1266868, part 2 - Fix leaks of the values passed to nsCSSValue::.SetPairValue in the StyleAnimationValue code. r=dholbert (e5a1ff8603)
- Bug 1266868, part 3 - Avoid Maybe::ref() where not necessary. r=dholbert (8dd435fd5e)
- Back out bug 1164227, because bug 1236043 fixes the original problem in a better way. (6b734f0718)
- Bug 1267524 Part 1 - Use member initializer list for nsStyleOutline. r=heycam (d7cabb2ea8)
- Bug 1267524 Part 2 - Use member initializer list for nsStyleXUL. r=heycam (82107506a6)
- Bug 1267524 Part 3 - Use member initializer list for nsStyleColumn. r=heycam (80318b0056)
- Bug 1267524 Part 4.1 - Add Reset() and rewrite methods for nsStyleSVGPaint. r=heycam (02ba8762cb)
- Bug 1267524 Part 4.2 - Use member initializer list for nsStyleSVG. r=heycam (5531ed4a93)
- Bug 1267524 Part 5 - Use member initializer list for nsStyleSVGReset. r=heycam (4a72005b1b)
- Bug 1267524 Part 6 - Use member initializer list for nsStylePosition. r=heycam (cfd6a8b640)
- Bug 1267524 Part 7 - Use member initializer list for nsStyleTable. r=heycam (510678ed8b)
- Bug 1267524 Part 8 - Use member initializer list for nsStyleTableBorder. r=heycam (c1617af193)
- Bug 1267524 Part 9 - Use member initializer list for nsStyleColor. r=heycam (753afba9f8)
- Bug 1267524 Part 10 - Use member initializer list for nsStyleDisplay. r=heycam (a6cc7ce52b)
- Bug 1267524 Part 11 - Use member initializer list for nsStyleVisibility. r=heycam (c93d75480e)
- Bug 1267524 Part 12 - Use member initializer list for nsStyleContent. r=heycam (ccc17aa74a)
- Bug 1267524 Part 13 - Use member initializer list for nsStyleTextReset. r=heycam (fc8b6ae837)
- Bug 1267524 Part 14 - Use member initializer list for nsStyleText. r=heycam (d73abb7d32)
- Bug 1267524 Part 15 - Use member initializer list for nsStyleUserInterface. r=heycam (3964558f27)
- Bug 1267524 Part 16 - Use member initializer list for nsStyleUIReset. r=heycam (3154cbc7d2)
- Bug 1267524 Part 17 - Use member initializer list for nsStyleVariables. r=heycam (3d286d2299)
- Bug 1267524 Part 18 - Remove "void" from zero argument functions. r=heycam (57b1a87c19)
- Bug 1267524 Part 19 - Move nsStyleCoord members to initializer list. r=heycam (385231a406)
- Bug 1227327 - Invalidate table parts and MathML frames when background-position changes on them. r=dbaron (088fad2be7)
- Bug 1268290: stylo: Pass SheetParsingMode to Servo, r=bholley (f05d51b7b1)
- Bug 1267833 - Pass the RawServoStyleSet to Servo_GetComputedValuesForAnonymousBox. r=heycam (c4870e2005)
- Bug 1268392 - Make Servo_GetComputedValues take a node rather than an element. r=bholley (61230bdc1f)
- Bug 1268390 - Part 1: Factor out most of nsStyleSet::AddDocStyleSheet for re-use. r=bholley (5bd89657a1)
- Bug 1268390 - Part 2: Add bindings for Servo_InsertStyleSheetBefore. r=bholley (f83ea77d37)
- Bug 1268404 - Part 1: Split out ResolveStyleForText from ResolveStyleForNonElement and pass in the text node. r=bholley (dc40bbc9dc)
- Bug 1268404 - Part 2: Implement ServoStyleSet::ResolveStyleForText. r=bholley (0c6bffbd4b)
- Bug 1268748 - Implement {Resolve,Probe}PseudoElementStyle. r=heycam (cd674703d6)
- Bug 1267560 - Get style structs from ServoComputedValues rather than the rule node, when using the Servo-backed style system. r=bholley (62784ed0ee)
- Bug 1268290 followup: remove stray semicolon on a CLOSED TREE. (609540fab1)
- Bug 1268390 - Part 3: Add support for doc style sheets in ServoStyleSet. r=bholley (787cee0d54)
- Bug 1267564 - Implement a couple of Servo-backed style object methods. r=bholley (b27b0f78a0)
- Bug 1250820 - Part 1: Define scoped enum for CSSPseudoClass::Type. r=heycam (c2992f4c01)
- Bug 1250820 - Part 2: Replace nsCSSPseudoClasses::Type with CSSPseudoClassType. r=heycam (8102ab491b)
- Bug 1250820 - Part 3: Replace notPseudo with negation. r=heycam (94f4b95650)
- Bug 1250820 - Part 4: Add MAX to CSSPseudoClassType. r=heycam (85acf2bc45)
- Bug 1206961 - Use channel->AsyncOpen2() for imageLoader; Remove security checks from callsites (r=bz) (0d5b91ca12)
- Bug 1134163 - Part1.Modify animationstart event timing in order to fire event after end of pending task. r=birtles (e2c333fb8d)
- Bug 1134163 - Part2 - Modify animation tests which rely on animationstart timing. r=birtles (fb780f4298)
- Bug 1067769 - Part 1: Avoid doing RequestRestyle and mutation batch for null target. r=birtles (c3a0c1a1ef)
- Bug 1067769 - Part 2: Support nullable target in KeyframeEffect(ReadOnly) constructor. r=birtles (e8ac02ebf0)
- Bug 1067769 - Part 3: Test for KeyframeEffectReadOnly with null target. r=birtles (9ee7fc48c3)
- Bug 1067769 - Part 4: Add some simple tests for document.getAnimation() in wpt. r=birtles (77c18ad32a)
- Bug 1067769 - Part 5: Support setting KeyframeEffect.target webidl interface. r=smaug (cb450cd6f7)
- Bug 1067769 - Part 6: Rename NonOwningAnimationTarget.h to AnimationTarget.h. r=birtles (45083b4141)
- Bug 1067769 - Part 7: Define OwningAnimationTarget and use it. r=birtles (0a716665aa)
- Bug 1067769 - Part 8: Add ConvertTarget function. r=birtles (2663246043)
- Bug 1067769 - Part 9: Wrap RequestRestyle and UnregisterTarget. r=birtles (1deb75c7e0)
- Bug 1067769 - Part 10: Implement SetTarget(). r=birtles (0823f6da17)
- Bug 1067769 - Part 11: Implement animation mutation observer while setting the target. r=birtles (8224724c49)
- Bug 1067769 - Part 12: Use Maybe<OwningAnimationTarget> in KeyframeEffect(ReadOnly) constructors. r=birtles (e057c15804)
- Bug 1067769 - Part 13: Test for setting the target in basic cases. r=birtles (b6a638a268)
- Bug 1067769 - Part 14: Test for our animation mutation observer. r=birtles (5381522d25)
- Bug 1264067 - [css-grid] 'fr' min-sizing is now invalid. r=dholbert (abc7d63364)
- Bug 550426 - Add support for {background,mask}-position-{x,y}, computed style additions. r=dbaron (0dea650527)
- Bug 1266948 - text-decoration-color: currentcolor should not use value from -webkit-text-fill-color; r=jfkthame (9b36b2f493)
- Bug 1271590 - Rename timespecadd to moz_timespecadd. r=jandem (4b417dabae)
- Bug 550426 - Use background-position-x/y when detecting scroll-linked effects. r=dbaron (478331b348)
- Bug 1227327 - Use regular background drawing for XUL groupbox frames. r=mattwoodrow (db42359656)
- Bug 1260329 - Properly escape the frameTable when running |dmd.py --clamp-contents|. r=mccr8. (b40a5a0f49)
- Bug 1148544 - Update tests to work with new way of handling user agent overrides. r=jchen (2cede65d5b)
- Bug 1262326 - Make test_user_agent_overrides.html work in e10s r=nwgh (81c4d7ba00)
- Bug 1180107: Factor out logic for determining whether a flex item's main size could influence cross size. r=mats (94b89305ea)
- Bug 1267471 - Check the snap info when comparing scroll metadata for equality. rs=botond (e5a40f0387)
- Bug 1257288 - Improve the APZ gtest infrastructure to make writing multi-FrameMetrics tests easier. r=kats (b4b898abc2)
- Bug 1256344 - Add a gtest to catch scenarios where the long-press block is interrupted by a non-touch block. r=botond (84982b1ba7)
- Bug 1265510 - Add a gtest for interrupting a scroll snap. r=botond (5f33cdadea)
- Bug 1246290 - Add a simple gtest to exercise the force-disabled-APZ codepaths. r=botond (be91113c70)
- Bug 1267470 - Move more fields from FrameMetrics to ScrollMetadata. r=kats (259f44ab15)
- Bug 1030952 part 4: For flex items with an aspect ratio, stomp on reflow state's main size *and cross size* in final reflow. r=mats (3f02ed9761)
- Bug 550426 - In PropertySupportsVariant, add {background,mask}-position-{x,y} to the list of properties that are parsed by functions. r=dbaron (b350dd9ec4)
- Bug 1258609: Initialize nsICanvasRenderingContextInternal with a DrawTarget instead of a gfxASurface. r=jrmuizel (236656c82d)
- Merge remote-tracking branch 'upstream/dev' into winbuild (c0659b547d)
- [mfbt] NotNull: VC2013 fix (86139057b8)
- layout: put back array initializations back to function body, fix VC2013 build. (3ac23f6474)
1717 lines
55 KiB
C++
1717 lines
55 KiB
C++
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
/* 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/. */
|
|
|
|
#include "nsComboboxControlFrame.h"
|
|
|
|
#include "gfxUtils.h"
|
|
#include "mozilla/gfx/2D.h"
|
|
#include "mozilla/gfx/PathHelpers.h"
|
|
#include "nsCOMPtr.h"
|
|
#include "nsFocusManager.h"
|
|
#include "nsFormControlFrame.h"
|
|
#include "nsGkAtoms.h"
|
|
#include "nsCSSAnonBoxes.h"
|
|
#include "nsHTMLParts.h"
|
|
#include "nsIFormControl.h"
|
|
#include "nsNameSpaceManager.h"
|
|
#include "nsIListControlFrame.h"
|
|
#include "nsPIDOMWindow.h"
|
|
#include "nsIPresShell.h"
|
|
#include "nsPresState.h"
|
|
#include "nsContentList.h"
|
|
#include "nsView.h"
|
|
#include "nsViewManager.h"
|
|
#include "nsIDOMEventListener.h"
|
|
#include "nsIDOMNode.h"
|
|
#include "nsISelectControlFrame.h"
|
|
#include "nsContentUtils.h"
|
|
#include "nsIDocument.h"
|
|
#include "nsIScrollableFrame.h"
|
|
#include "nsListControlFrame.h"
|
|
#include "nsAutoPtr.h"
|
|
#include "mozilla/StyleSetHandle.h"
|
|
#include "mozilla/StyleSetHandleInlines.h"
|
|
#include "nsNodeInfoManager.h"
|
|
#include "nsContentCreatorFunctions.h"
|
|
#include "nsLayoutUtils.h"
|
|
#include "nsDisplayList.h"
|
|
#include "nsITheme.h"
|
|
#include "nsThemeConstants.h"
|
|
#include "nsRenderingContext.h"
|
|
#include "mozilla/Likely.h"
|
|
#include <algorithm>
|
|
#include "nsTextNode.h"
|
|
#include "nsIContentInlines.h"
|
|
#include "mozilla/AsyncEventDispatcher.h"
|
|
#include "mozilla/EventStates.h"
|
|
#include "mozilla/LookAndFeel.h"
|
|
#include "mozilla/MouseEvents.h"
|
|
#include "mozilla/unused.h"
|
|
#include "gfx2DGlue.h"
|
|
|
|
#ifdef XP_WIN
|
|
#define COMBOBOX_ROLLUP_CONSUME_EVENT 0
|
|
#else
|
|
#define COMBOBOX_ROLLUP_CONSUME_EVENT 1
|
|
#endif
|
|
|
|
using namespace mozilla;
|
|
using namespace mozilla::gfx;
|
|
|
|
NS_IMETHODIMP
|
|
nsComboboxControlFrame::RedisplayTextEvent::Run()
|
|
{
|
|
if (mControlFrame)
|
|
mControlFrame->HandleRedisplayTextEvent();
|
|
return NS_OK;
|
|
}
|
|
|
|
class nsPresState;
|
|
|
|
#define FIX_FOR_BUG_53259
|
|
|
|
// Drop down list event management.
|
|
// The combo box uses the following strategy for managing the drop-down list.
|
|
// If the combo box or its arrow button is clicked on the drop-down list is displayed
|
|
// If mouse exits the combo box with the drop-down list displayed the drop-down list
|
|
// is asked to capture events
|
|
// The drop-down list will capture all events including mouse down and up and will always
|
|
// return with ListWasSelected method call regardless of whether an item in the list was
|
|
// actually selected.
|
|
// The ListWasSelected code will turn off mouse-capture for the drop-down list.
|
|
// The drop-down list does not explicitly set capture when it is in the drop-down mode.
|
|
|
|
|
|
/**
|
|
* Helper class that listens to the combo boxes button. If the button is pressed the
|
|
* combo box is toggled to open or close. this is used by Accessibility which presses
|
|
* that button Programmatically.
|
|
*/
|
|
class nsComboButtonListener : public nsIDOMEventListener
|
|
{
|
|
private:
|
|
virtual ~nsComboButtonListener() {}
|
|
|
|
public:
|
|
NS_DECL_ISUPPORTS
|
|
|
|
NS_IMETHOD HandleEvent(nsIDOMEvent*) override
|
|
{
|
|
mComboBox->ShowDropDown(!mComboBox->IsDroppedDown());
|
|
return NS_OK;
|
|
}
|
|
|
|
explicit nsComboButtonListener(nsComboboxControlFrame* aCombobox)
|
|
{
|
|
mComboBox = aCombobox;
|
|
}
|
|
|
|
nsComboboxControlFrame* mComboBox;
|
|
};
|
|
|
|
NS_IMPL_ISUPPORTS(nsComboButtonListener,
|
|
nsIDOMEventListener)
|
|
|
|
// static class data member for Bug 32920
|
|
nsComboboxControlFrame* nsComboboxControlFrame::sFocused = nullptr;
|
|
|
|
nsContainerFrame*
|
|
NS_NewComboboxControlFrame(nsIPresShell* aPresShell, nsStyleContext* aContext, nsFrameState aStateFlags)
|
|
{
|
|
nsComboboxControlFrame* it = new (aPresShell) nsComboboxControlFrame(aContext);
|
|
|
|
if (it) {
|
|
// set the state flags (if any are provided)
|
|
it->AddStateBits(aStateFlags);
|
|
}
|
|
|
|
return it;
|
|
}
|
|
|
|
NS_IMPL_FRAMEARENA_HELPERS(nsComboboxControlFrame)
|
|
|
|
//-----------------------------------------------------------
|
|
// Reflow Debugging Macros
|
|
// These let us "see" how many reflow counts are happening
|
|
//-----------------------------------------------------------
|
|
#ifdef DO_REFLOW_COUNTER
|
|
|
|
#define MAX_REFLOW_CNT 1024
|
|
static int32_t gTotalReqs = 0;;
|
|
static int32_t gTotalReflows = 0;;
|
|
static int32_t gReflowControlCntRQ[MAX_REFLOW_CNT];
|
|
static int32_t gReflowControlCnt[MAX_REFLOW_CNT];
|
|
static int32_t gReflowInx = -1;
|
|
|
|
#define REFLOW_COUNTER() \
|
|
if (mReflowId > -1) \
|
|
gReflowControlCnt[mReflowId]++;
|
|
|
|
#define REFLOW_COUNTER_REQUEST() \
|
|
if (mReflowId > -1) \
|
|
gReflowControlCntRQ[mReflowId]++;
|
|
|
|
#define REFLOW_COUNTER_DUMP(__desc) \
|
|
if (mReflowId > -1) {\
|
|
gTotalReqs += gReflowControlCntRQ[mReflowId];\
|
|
gTotalReflows += gReflowControlCnt[mReflowId];\
|
|
printf("** Id:%5d %s RF: %d RQ: %d %d/%d %5.2f\n", \
|
|
mReflowId, (__desc), \
|
|
gReflowControlCnt[mReflowId], \
|
|
gReflowControlCntRQ[mReflowId],\
|
|
gTotalReflows, gTotalReqs, float(gTotalReflows)/float(gTotalReqs)*100.0f);\
|
|
}
|
|
|
|
#define REFLOW_COUNTER_INIT() \
|
|
if (gReflowInx < MAX_REFLOW_CNT) { \
|
|
gReflowInx++; \
|
|
mReflowId = gReflowInx; \
|
|
gReflowControlCnt[mReflowId] = 0; \
|
|
gReflowControlCntRQ[mReflowId] = 0; \
|
|
} else { \
|
|
mReflowId = -1; \
|
|
}
|
|
|
|
// reflow messages
|
|
#define REFLOW_DEBUG_MSG(_msg1) printf((_msg1))
|
|
#define REFLOW_DEBUG_MSG2(_msg1, _msg2) printf((_msg1), (_msg2))
|
|
#define REFLOW_DEBUG_MSG3(_msg1, _msg2, _msg3) printf((_msg1), (_msg2), (_msg3))
|
|
#define REFLOW_DEBUG_MSG4(_msg1, _msg2, _msg3, _msg4) printf((_msg1), (_msg2), (_msg3), (_msg4))
|
|
|
|
#else //-------------
|
|
|
|
#define REFLOW_COUNTER_REQUEST()
|
|
#define REFLOW_COUNTER()
|
|
#define REFLOW_COUNTER_DUMP(__desc)
|
|
#define REFLOW_COUNTER_INIT()
|
|
|
|
#define REFLOW_DEBUG_MSG(_msg)
|
|
#define REFLOW_DEBUG_MSG2(_msg1, _msg2)
|
|
#define REFLOW_DEBUG_MSG3(_msg1, _msg2, _msg3)
|
|
#define REFLOW_DEBUG_MSG4(_msg1, _msg2, _msg3, _msg4)
|
|
|
|
|
|
#endif
|
|
|
|
//------------------------------------------
|
|
// This is for being VERY noisy
|
|
//------------------------------------------
|
|
#ifdef DO_VERY_NOISY
|
|
#define REFLOW_NOISY_MSG(_msg1) printf((_msg1))
|
|
#define REFLOW_NOISY_MSG2(_msg1, _msg2) printf((_msg1), (_msg2))
|
|
#define REFLOW_NOISY_MSG3(_msg1, _msg2, _msg3) printf((_msg1), (_msg2), (_msg3))
|
|
#define REFLOW_NOISY_MSG4(_msg1, _msg2, _msg3, _msg4) printf((_msg1), (_msg2), (_msg3), (_msg4))
|
|
#else
|
|
#define REFLOW_NOISY_MSG(_msg)
|
|
#define REFLOW_NOISY_MSG2(_msg1, _msg2)
|
|
#define REFLOW_NOISY_MSG3(_msg1, _msg2, _msg3)
|
|
#define REFLOW_NOISY_MSG4(_msg1, _msg2, _msg3, _msg4)
|
|
#endif
|
|
|
|
//------------------------------------------
|
|
// Displays value in pixels or twips
|
|
//------------------------------------------
|
|
#ifdef DO_PIXELS
|
|
#define PX(__v) __v / 15
|
|
#else
|
|
#define PX(__v) __v
|
|
#endif
|
|
|
|
//------------------------------------------------------
|
|
//-- Done with macros
|
|
//------------------------------------------------------
|
|
|
|
nsComboboxControlFrame::nsComboboxControlFrame(nsStyleContext* aContext)
|
|
: nsBlockFrame(aContext)
|
|
, mDisplayFrame(nullptr)
|
|
, mButtonFrame(nullptr)
|
|
, mDropdownFrame(nullptr)
|
|
, mListControlFrame(nullptr)
|
|
, mDisplayISize(0)
|
|
, mRecentSelectedIndex(NS_SKIP_NOTIFY_INDEX)
|
|
, mDisplayedIndex(-1)
|
|
, mLastDropDownBeforeScreenBCoord(nscoord_MIN)
|
|
, mLastDropDownAfterScreenBCoord(nscoord_MIN)
|
|
, mDroppedDown(false)
|
|
, mInRedisplayText(false)
|
|
, mDelayedShowDropDown(false)
|
|
{
|
|
REFLOW_COUNTER_INIT()
|
|
}
|
|
|
|
//--------------------------------------------------------------
|
|
nsComboboxControlFrame::~nsComboboxControlFrame()
|
|
{
|
|
REFLOW_COUNTER_DUMP("nsCCF");
|
|
}
|
|
|
|
//--------------------------------------------------------------
|
|
|
|
NS_QUERYFRAME_HEAD(nsComboboxControlFrame)
|
|
NS_QUERYFRAME_ENTRY(nsIComboboxControlFrame)
|
|
NS_QUERYFRAME_ENTRY(nsIFormControlFrame)
|
|
NS_QUERYFRAME_ENTRY(nsIAnonymousContentCreator)
|
|
NS_QUERYFRAME_ENTRY(nsISelectControlFrame)
|
|
NS_QUERYFRAME_ENTRY(nsIStatefulFrame)
|
|
NS_QUERYFRAME_TAIL_INHERITING(nsBlockFrame)
|
|
|
|
#ifdef ACCESSIBILITY
|
|
a11y::AccType
|
|
nsComboboxControlFrame::AccessibleType()
|
|
{
|
|
return a11y::eHTMLComboboxType;
|
|
}
|
|
#endif
|
|
|
|
void
|
|
nsComboboxControlFrame::SetFocus(bool aOn, bool aRepaint)
|
|
{
|
|
nsWeakFrame weakFrame(this);
|
|
if (aOn) {
|
|
nsListControlFrame::ComboboxFocusSet();
|
|
sFocused = this;
|
|
if (mDelayedShowDropDown) {
|
|
ShowDropDown(true); // might destroy us
|
|
if (!weakFrame.IsAlive()) {
|
|
return;
|
|
}
|
|
}
|
|
} else {
|
|
sFocused = nullptr;
|
|
mDelayedShowDropDown = false;
|
|
if (mDroppedDown) {
|
|
mListControlFrame->ComboboxFinish(mDisplayedIndex); // might destroy us
|
|
if (!weakFrame.IsAlive()) {
|
|
return;
|
|
}
|
|
}
|
|
// May delete |this|.
|
|
mListControlFrame->FireOnChange();
|
|
}
|
|
|
|
if (!weakFrame.IsAlive()) {
|
|
return;
|
|
}
|
|
|
|
// This is needed on a temporary basis. It causes the focus
|
|
// rect to be drawn. This is much faster than ReResolvingStyle
|
|
// Bug 32920
|
|
InvalidateFrame();
|
|
}
|
|
|
|
void
|
|
nsComboboxControlFrame::ShowPopup(bool aShowPopup)
|
|
{
|
|
nsView* view = mDropdownFrame->GetView();
|
|
nsViewManager* viewManager = view->GetViewManager();
|
|
|
|
if (aShowPopup) {
|
|
nsRect rect = mDropdownFrame->GetRect();
|
|
rect.x = rect.y = 0;
|
|
viewManager->ResizeView(view, rect);
|
|
viewManager->SetViewVisibility(view, nsViewVisibility_kShow);
|
|
} else {
|
|
viewManager->SetViewVisibility(view, nsViewVisibility_kHide);
|
|
nsRect emptyRect(0, 0, 0, 0);
|
|
viewManager->ResizeView(view, emptyRect);
|
|
}
|
|
|
|
// fire a popup dom event if it is safe to do so
|
|
nsCOMPtr<nsIPresShell> shell = PresContext()->GetPresShell();
|
|
if (shell && nsContentUtils::IsSafeToRunScript()) {
|
|
nsEventStatus status = nsEventStatus_eIgnore;
|
|
WidgetMouseEvent event(true, aShowPopup ? eXULPopupShowing : eXULPopupHiding,
|
|
nullptr, WidgetMouseEvent::eReal);
|
|
|
|
shell->HandleDOMEventWithTarget(mContent, &event, &status);
|
|
}
|
|
}
|
|
|
|
bool
|
|
nsComboboxControlFrame::ShowList(bool aShowList)
|
|
{
|
|
nsView* view = mDropdownFrame->GetView();
|
|
if (aShowList) {
|
|
NS_ASSERTION(!view->HasWidget(),
|
|
"We shouldn't have a widget before we need to display the popup");
|
|
|
|
// Create the widget for the drop-down list
|
|
view->GetViewManager()->SetViewFloating(view, true);
|
|
|
|
nsWidgetInitData widgetData;
|
|
widgetData.mWindowType = eWindowType_popup;
|
|
widgetData.mBorderStyle = eBorderStyle_default;
|
|
view->CreateWidgetForPopup(&widgetData);
|
|
} else {
|
|
nsIWidget* widget = view->GetWidget();
|
|
if (widget) {
|
|
// We must do this before ShowPopup in case it destroys us (bug 813442).
|
|
widget->CaptureRollupEvents(this, false);
|
|
}
|
|
}
|
|
|
|
nsWeakFrame weakFrame(this);
|
|
ShowPopup(aShowList); // might destroy us
|
|
if (!weakFrame.IsAlive()) {
|
|
return false;
|
|
}
|
|
|
|
mDroppedDown = aShowList;
|
|
nsIWidget* widget = view->GetWidget();
|
|
if (mDroppedDown) {
|
|
// The listcontrol frame will call back to the nsComboboxControlFrame's
|
|
// ListWasSelected which will stop the capture.
|
|
mListControlFrame->AboutToDropDown();
|
|
mListControlFrame->CaptureMouseEvents(true);
|
|
if (widget) {
|
|
widget->CaptureRollupEvents(this, true);
|
|
}
|
|
} else {
|
|
if (widget) {
|
|
view->DestroyWidget();
|
|
}
|
|
}
|
|
|
|
return weakFrame.IsAlive();
|
|
}
|
|
|
|
class nsResizeDropdownAtFinalPosition final
|
|
: public nsIReflowCallback, public Runnable
|
|
{
|
|
public:
|
|
explicit nsResizeDropdownAtFinalPosition(nsComboboxControlFrame* aFrame)
|
|
: mFrame(aFrame)
|
|
{
|
|
MOZ_COUNT_CTOR(nsResizeDropdownAtFinalPosition);
|
|
}
|
|
|
|
protected:
|
|
~nsResizeDropdownAtFinalPosition()
|
|
{
|
|
MOZ_COUNT_DTOR(nsResizeDropdownAtFinalPosition);
|
|
}
|
|
|
|
public:
|
|
virtual bool ReflowFinished() override
|
|
{
|
|
Run();
|
|
NS_RELEASE_THIS();
|
|
return false;
|
|
}
|
|
|
|
virtual void ReflowCallbackCanceled() override
|
|
{
|
|
NS_RELEASE_THIS();
|
|
}
|
|
|
|
NS_IMETHODIMP Run() override
|
|
{
|
|
if (mFrame.IsAlive()) {
|
|
static_cast<nsComboboxControlFrame*>(mFrame.GetFrame())->
|
|
AbsolutelyPositionDropDown();
|
|
}
|
|
return NS_OK;
|
|
}
|
|
|
|
nsWeakFrame mFrame;
|
|
};
|
|
|
|
void
|
|
nsComboboxControlFrame::ReflowDropdown(nsPresContext* aPresContext,
|
|
const nsHTMLReflowState& aReflowState)
|
|
{
|
|
// All we want out of it later on, really, is the block size of a row, so we
|
|
// don't even need to cache mDropdownFrame's ascent or anything. If we don't
|
|
// need to reflow it, just bail out here.
|
|
if (!aReflowState.ShouldReflowAllKids() &&
|
|
!NS_SUBTREE_DIRTY(mDropdownFrame)) {
|
|
return;
|
|
}
|
|
|
|
// XXXbz this will, for small-block-size dropdowns, have extra space
|
|
// on the appropriate edge for the scrollbar we don't show... but
|
|
// that's the best we can do here for now.
|
|
WritingMode wm = mDropdownFrame->GetWritingMode();
|
|
LogicalSize availSize = aReflowState.AvailableSize(wm);
|
|
availSize.BSize(wm) = NS_UNCONSTRAINEDSIZE;
|
|
nsHTMLReflowState kidReflowState(aPresContext, aReflowState, mDropdownFrame,
|
|
availSize);
|
|
|
|
// If the dropdown's intrinsic inline size is narrower than our
|
|
// specified inline size, then expand it out. We want our border-box
|
|
// inline size to end up the same as the dropdown's so account for
|
|
// both sets of mComputedBorderPadding.
|
|
nscoord forcedISize = aReflowState.ComputedISize() +
|
|
aReflowState.ComputedLogicalBorderPadding().IStartEnd(wm) -
|
|
kidReflowState.ComputedLogicalBorderPadding().IStartEnd(wm);
|
|
kidReflowState.SetComputedISize(std::max(kidReflowState.ComputedISize(),
|
|
forcedISize));
|
|
|
|
// ensure we start off hidden
|
|
if (!mDroppedDown && GetStateBits() & NS_FRAME_FIRST_REFLOW) {
|
|
nsView* view = mDropdownFrame->GetView();
|
|
nsViewManager* viewManager = view->GetViewManager();
|
|
viewManager->SetViewVisibility(view, nsViewVisibility_kHide);
|
|
nsRect emptyRect(0, 0, 0, 0);
|
|
viewManager->ResizeView(view, emptyRect);
|
|
}
|
|
|
|
// Allow the child to move/size/change-visibility its view if it's currently
|
|
// dropped down
|
|
int32_t flags = mDroppedDown ? 0
|
|
: NS_FRAME_NO_MOVE_FRAME |
|
|
NS_FRAME_NO_VISIBILITY |
|
|
NS_FRAME_NO_SIZE_VIEW;
|
|
|
|
//XXX Can this be different from the dropdown's writing mode?
|
|
// That would be odd!
|
|
// Note that we don't need to pass the true frame position or container size
|
|
// to ReflowChild or FinishReflowChild here; it will be positioned as needed
|
|
// by AbsolutelyPositionDropDown().
|
|
WritingMode outerWM = GetWritingMode();
|
|
const nsSize dummyContainerSize;
|
|
nsHTMLReflowMetrics desiredSize(aReflowState);
|
|
nsReflowStatus ignoredStatus;
|
|
ReflowChild(mDropdownFrame, aPresContext, desiredSize,
|
|
kidReflowState, outerWM, LogicalPoint(outerWM),
|
|
dummyContainerSize, flags, ignoredStatus);
|
|
|
|
// Set the child's width and height to its desired size
|
|
FinishReflowChild(mDropdownFrame, aPresContext, desiredSize, &kidReflowState,
|
|
outerWM, LogicalPoint(outerWM), dummyContainerSize, flags);
|
|
}
|
|
|
|
nsPoint
|
|
nsComboboxControlFrame::GetCSSTransformTranslation()
|
|
{
|
|
nsIFrame* frame = this;
|
|
bool is3DTransform = false;
|
|
Matrix transform;
|
|
while (frame) {
|
|
nsIFrame* parent;
|
|
Matrix4x4 ctm = frame->GetTransformMatrix(nullptr, &parent);
|
|
Matrix matrix;
|
|
if (ctm.Is2D(&matrix)) {
|
|
transform = transform * matrix;
|
|
} else {
|
|
is3DTransform = true;
|
|
break;
|
|
}
|
|
frame = parent;
|
|
}
|
|
nsPoint translation;
|
|
if (!is3DTransform && !transform.HasNonTranslation()) {
|
|
nsPresContext* pc = PresContext();
|
|
// To get the translation introduced only by transforms we subtract the
|
|
// regular non-transform translation.
|
|
nsRootPresContext* rootPC = pc->GetRootPresContext();
|
|
if (rootPC) {
|
|
int32_t apd = pc->AppUnitsPerDevPixel();
|
|
translation.x = NSFloatPixelsToAppUnits(transform._31, apd);
|
|
translation.y = NSFloatPixelsToAppUnits(transform._32, apd);
|
|
translation -= GetOffsetToCrossDoc(rootPC->PresShell()->GetRootFrame());
|
|
}
|
|
}
|
|
return translation;
|
|
}
|
|
|
|
class nsAsyncRollup : public Runnable
|
|
{
|
|
public:
|
|
explicit nsAsyncRollup(nsComboboxControlFrame* aFrame) : mFrame(aFrame) {}
|
|
NS_IMETHODIMP Run()
|
|
{
|
|
if (mFrame.IsAlive()) {
|
|
static_cast<nsComboboxControlFrame*>(mFrame.GetFrame())
|
|
->RollupFromList();
|
|
}
|
|
return NS_OK;
|
|
}
|
|
nsWeakFrame mFrame;
|
|
};
|
|
|
|
class nsAsyncResize : public Runnable
|
|
{
|
|
public:
|
|
explicit nsAsyncResize(nsComboboxControlFrame* aFrame) : mFrame(aFrame) {}
|
|
NS_IMETHODIMP Run()
|
|
{
|
|
if (mFrame.IsAlive()) {
|
|
nsComboboxControlFrame* combo =
|
|
static_cast<nsComboboxControlFrame*>(mFrame.GetFrame());
|
|
static_cast<nsListControlFrame*>(combo->mDropdownFrame)->
|
|
SetSuppressScrollbarUpdate(true);
|
|
nsCOMPtr<nsIPresShell> shell = mFrame->PresContext()->PresShell();
|
|
shell->FrameNeedsReflow(combo->mDropdownFrame, nsIPresShell::eResize,
|
|
NS_FRAME_IS_DIRTY);
|
|
shell->FlushPendingNotifications(Flush_Layout);
|
|
if (mFrame.IsAlive()) {
|
|
combo = static_cast<nsComboboxControlFrame*>(mFrame.GetFrame());
|
|
static_cast<nsListControlFrame*>(combo->mDropdownFrame)->
|
|
SetSuppressScrollbarUpdate(false);
|
|
if (combo->mDelayedShowDropDown) {
|
|
combo->ShowDropDown(true);
|
|
}
|
|
}
|
|
}
|
|
return NS_OK;
|
|
}
|
|
nsWeakFrame mFrame;
|
|
};
|
|
|
|
void
|
|
nsComboboxControlFrame::GetAvailableDropdownSpace(WritingMode aWM,
|
|
nscoord* aBefore,
|
|
nscoord* aAfter,
|
|
LogicalPoint* aTranslation)
|
|
{
|
|
MOZ_ASSERT(!XRE_IsContentProcess());
|
|
// Note: At first glance, it appears that you could simply get the
|
|
// absolute bounding box for the dropdown list by first getting its
|
|
// view, then getting the view's nsIWidget, then asking the nsIWidget
|
|
// for its AbsoluteBounds.
|
|
// The problem with this approach, is that the dropdown list's bcoord
|
|
// location can change based on whether the dropdown is placed after
|
|
// or before the display frame. The approach taken here is to get the
|
|
// absolute position of the display frame and use its location to
|
|
// determine if the dropdown will go offscreen.
|
|
|
|
// Normal frame geometry (eg GetOffsetTo, mRect) doesn't include transforms.
|
|
// In the special case that our transform is only a 2D translation we
|
|
// introduce this hack so that the dropdown will show up in the right place.
|
|
// Use null container size when converting a vector from logical to physical.
|
|
const nsSize nullContainerSize;
|
|
*aTranslation = LogicalPoint(aWM, GetCSSTransformTranslation(),
|
|
nullContainerSize);
|
|
*aBefore = 0;
|
|
*aAfter = 0;
|
|
|
|
nsRect screen = nsFormControlFrame::GetUsableScreenRect(PresContext());
|
|
nsSize containerSize = screen.Size();
|
|
LogicalRect logicalScreen(aWM, screen, containerSize);
|
|
if (mLastDropDownAfterScreenBCoord == nscoord_MIN) {
|
|
LogicalRect thisScreenRect(aWM, GetScreenRectInAppUnits(),
|
|
containerSize);
|
|
mLastDropDownAfterScreenBCoord = thisScreenRect.BEnd(aWM) +
|
|
aTranslation->B(aWM);
|
|
mLastDropDownBeforeScreenBCoord = thisScreenRect.BEnd(aWM) +
|
|
aTranslation->B(aWM);
|
|
}
|
|
|
|
nscoord minBCoord;
|
|
nsPresContext* pc = PresContext()->GetToplevelContentDocumentPresContext();
|
|
nsIFrame* root = pc ? pc->PresShell()->GetRootFrame() : nullptr;
|
|
if (root) {
|
|
minBCoord = LogicalRect(aWM,
|
|
root->GetScreenRectInAppUnits(),
|
|
containerSize).BStart(aWM);
|
|
if (mLastDropDownAfterScreenBCoord < minBCoord) {
|
|
// Don't allow the drop-down to be placed before the content area.
|
|
return;
|
|
}
|
|
} else {
|
|
minBCoord = logicalScreen.BStart(aWM);
|
|
}
|
|
|
|
nscoord after = logicalScreen.BEnd(aWM) - mLastDropDownAfterScreenBCoord;
|
|
nscoord before = mLastDropDownBeforeScreenBCoord - minBCoord;
|
|
|
|
// If the difference between the space before and after is less
|
|
// than a row-block-size, then we favor the space after.
|
|
if (before >= after) {
|
|
nsListControlFrame* lcf = static_cast<nsListControlFrame*>(mDropdownFrame);
|
|
nscoord rowBSize = lcf->GetBSizeOfARow();
|
|
if (before < after + rowBSize) {
|
|
before -= rowBSize;
|
|
}
|
|
}
|
|
|
|
*aAfter = after;
|
|
*aBefore = before;
|
|
}
|
|
|
|
nsComboboxControlFrame::DropDownPositionState
|
|
nsComboboxControlFrame::AbsolutelyPositionDropDown()
|
|
{
|
|
if (XRE_IsContentProcess()) {
|
|
return eDropDownPositionSuppressed;
|
|
}
|
|
|
|
WritingMode wm = GetWritingMode();
|
|
LogicalPoint translation(wm);
|
|
nscoord before, after;
|
|
mLastDropDownAfterScreenBCoord = nscoord_MIN;
|
|
GetAvailableDropdownSpace(wm, &before, &after, &translation);
|
|
if (before <= 0 && after <= 0) {
|
|
if (IsDroppedDown()) {
|
|
// Hide the view immediately to minimize flicker.
|
|
nsView* view = mDropdownFrame->GetView();
|
|
view->GetViewManager()->SetViewVisibility(view, nsViewVisibility_kHide);
|
|
NS_DispatchToCurrentThread(new nsAsyncRollup(this));
|
|
}
|
|
return eDropDownPositionSuppressed;
|
|
}
|
|
|
|
LogicalSize dropdownSize = mDropdownFrame->GetLogicalSize(wm);
|
|
nscoord bSize = std::max(before, after);
|
|
nsListControlFrame* lcf = static_cast<nsListControlFrame*>(mDropdownFrame);
|
|
if (bSize < dropdownSize.BSize(wm)) {
|
|
if (lcf->GetNumDisplayRows() > 1) {
|
|
// The drop-down doesn't fit and currently shows more than 1 row -
|
|
// schedule a resize to show fewer rows.
|
|
NS_DispatchToCurrentThread(new nsAsyncResize(this));
|
|
return eDropDownPositionPendingResize;
|
|
}
|
|
} else if (bSize > (dropdownSize.BSize(wm) + lcf->GetBSizeOfARow() * 1.5) &&
|
|
lcf->GetDropdownCanGrow()) {
|
|
// The drop-down fits but there is room for at least 1.5 more rows -
|
|
// schedule a resize to show more rows if it has more rows to show.
|
|
// (1.5 rows for good measure to avoid any rounding issues that would
|
|
// lead to a loop of reflow requests)
|
|
NS_DispatchToCurrentThread(new nsAsyncResize(this));
|
|
return eDropDownPositionPendingResize;
|
|
}
|
|
|
|
// Position the drop-down after if there is room, otherwise place it before
|
|
// if there is room. If there is no room for it on either side then place
|
|
// it after (to avoid overlapping UI like the URL bar).
|
|
bool b = dropdownSize.BSize(wm)<= after || dropdownSize.BSize(wm) > before;
|
|
LogicalPoint dropdownPosition(wm, 0, b ? BSize(wm) : -dropdownSize.BSize(wm));
|
|
|
|
// Don't position the view unless the position changed since it might cause
|
|
// a call to NotifyGeometryChange() and an infinite loop here.
|
|
nsSize containerSize = GetSize();
|
|
const LogicalPoint currentPos =
|
|
mDropdownFrame->GetLogicalPosition(containerSize);
|
|
const LogicalPoint newPos = dropdownPosition + translation;
|
|
if (currentPos != newPos) {
|
|
mDropdownFrame->SetPosition(wm, newPos, containerSize);
|
|
nsContainerFrame::PositionFrameView(mDropdownFrame);
|
|
}
|
|
return eDropDownPositionFinal;
|
|
}
|
|
|
|
void
|
|
nsComboboxControlFrame::NotifyGeometryChange()
|
|
{
|
|
if (XRE_IsContentProcess()) {
|
|
return;
|
|
}
|
|
|
|
// We don't need to resize if we're not dropped down since ShowDropDown
|
|
// does that, or if we're dirty then the reflow callback does it,
|
|
// or if we have a delayed ShowDropDown pending.
|
|
if (IsDroppedDown() &&
|
|
!(GetStateBits() & NS_FRAME_IS_DIRTY) &&
|
|
!mDelayedShowDropDown) {
|
|
// Async because we're likely in a middle of a scroll here so
|
|
// frame/view positions are in flux.
|
|
RefPtr<nsResizeDropdownAtFinalPosition> resize =
|
|
new nsResizeDropdownAtFinalPosition(this);
|
|
NS_DispatchToCurrentThread(resize);
|
|
}
|
|
}
|
|
|
|
//----------------------------------------------------------
|
|
//
|
|
//----------------------------------------------------------
|
|
#ifdef DO_REFLOW_DEBUG
|
|
static int myCounter = 0;
|
|
|
|
static void printSize(char * aDesc, nscoord aSize)
|
|
{
|
|
printf(" %s: ", aDesc);
|
|
if (aSize == NS_UNCONSTRAINEDSIZE) {
|
|
printf("UC");
|
|
} else {
|
|
printf("%d", PX(aSize));
|
|
}
|
|
}
|
|
#endif
|
|
|
|
//-------------------------------------------------------------------
|
|
//-- Main Reflow for the Combobox
|
|
//-------------------------------------------------------------------
|
|
|
|
nscoord
|
|
nsComboboxControlFrame::GetIntrinsicISize(nsRenderingContext* aRenderingContext,
|
|
nsLayoutUtils::IntrinsicISizeType aType)
|
|
{
|
|
// get the scrollbar width, we'll use this later
|
|
nscoord scrollbarWidth = 0;
|
|
nsPresContext* presContext = PresContext();
|
|
if (mListControlFrame) {
|
|
nsIScrollableFrame* scrollable = do_QueryFrame(mListControlFrame);
|
|
NS_ASSERTION(scrollable, "List must be a scrollable frame");
|
|
scrollbarWidth = scrollable->GetNondisappearingScrollbarWidth(
|
|
presContext, aRenderingContext, GetWritingMode());
|
|
}
|
|
|
|
nscoord displayISize = 0;
|
|
if (MOZ_LIKELY(mDisplayFrame)) {
|
|
displayISize = nsLayoutUtils::IntrinsicForContainer(aRenderingContext,
|
|
mDisplayFrame,
|
|
aType);
|
|
}
|
|
|
|
if (mDropdownFrame) {
|
|
nscoord dropdownContentISize;
|
|
bool isUsingOverlayScrollbars =
|
|
LookAndFeel::GetInt(LookAndFeel::eIntID_UseOverlayScrollbars) != 0;
|
|
if (aType == nsLayoutUtils::MIN_ISIZE) {
|
|
dropdownContentISize = mDropdownFrame->GetMinISize(aRenderingContext);
|
|
if (isUsingOverlayScrollbars) {
|
|
dropdownContentISize += scrollbarWidth;
|
|
}
|
|
} else {
|
|
NS_ASSERTION(aType == nsLayoutUtils::PREF_ISIZE, "Unexpected type");
|
|
dropdownContentISize = mDropdownFrame->GetPrefISize(aRenderingContext);
|
|
if (isUsingOverlayScrollbars) {
|
|
dropdownContentISize += scrollbarWidth;
|
|
}
|
|
}
|
|
dropdownContentISize = NSCoordSaturatingSubtract(dropdownContentISize,
|
|
scrollbarWidth,
|
|
nscoord_MAX);
|
|
|
|
displayISize = std::max(dropdownContentISize, displayISize);
|
|
}
|
|
|
|
// add room for the dropmarker button if there is one
|
|
if ((!IsThemed() ||
|
|
presContext->GetTheme()->ThemeNeedsComboboxDropmarker()) &&
|
|
StyleDisplay()->mAppearance != NS_THEME_NONE) {
|
|
displayISize += scrollbarWidth;
|
|
}
|
|
|
|
return displayISize;
|
|
|
|
}
|
|
|
|
nscoord
|
|
nsComboboxControlFrame::GetMinISize(nsRenderingContext *aRenderingContext)
|
|
{
|
|
nscoord minISize;
|
|
DISPLAY_MIN_WIDTH(this, minISize);
|
|
minISize = GetIntrinsicISize(aRenderingContext, nsLayoutUtils::MIN_ISIZE);
|
|
return minISize;
|
|
}
|
|
|
|
nscoord
|
|
nsComboboxControlFrame::GetPrefISize(nsRenderingContext *aRenderingContext)
|
|
{
|
|
nscoord prefISize;
|
|
DISPLAY_PREF_WIDTH(this, prefISize);
|
|
prefISize = GetIntrinsicISize(aRenderingContext, nsLayoutUtils::PREF_ISIZE);
|
|
return prefISize;
|
|
}
|
|
|
|
void
|
|
nsComboboxControlFrame::Reflow(nsPresContext* aPresContext,
|
|
nsHTMLReflowMetrics& aDesiredSize,
|
|
const nsHTMLReflowState& aReflowState,
|
|
nsReflowStatus& aStatus)
|
|
{
|
|
MarkInReflow();
|
|
// Constraints we try to satisfy:
|
|
|
|
// 1) Default inline size of button is the vertical scrollbar size
|
|
// 2) If the inline size of button is bigger than our inline size, set
|
|
// inline size of button to 0.
|
|
// 3) Default block size of button is block size of display area
|
|
// 4) Inline size of display area is whatever is left over from our
|
|
// inline size after allocating inline size for the button.
|
|
// 5) Block Size of display area is GetBSizeOfARow() on the
|
|
// mListControlFrame.
|
|
|
|
if (!mDisplayFrame || !mButtonFrame || !mDropdownFrame) {
|
|
NS_ERROR("Why did the frame constructor allow this to happen? Fix it!!");
|
|
return;
|
|
}
|
|
|
|
// Make sure the displayed text is the same as the selected option, bug 297389.
|
|
int32_t selectedIndex;
|
|
nsAutoString selectedOptionText;
|
|
if (!mDroppedDown) {
|
|
selectedIndex = mListControlFrame->GetSelectedIndex();
|
|
}
|
|
else {
|
|
// In dropped down mode the "selected index" is the hovered menu item,
|
|
// we want the last selected item which is |mDisplayedIndex| in this case.
|
|
selectedIndex = mDisplayedIndex;
|
|
}
|
|
if (selectedIndex != -1) {
|
|
mListControlFrame->GetOptionText(selectedIndex, selectedOptionText);
|
|
}
|
|
if (mDisplayedOptionText != selectedOptionText) {
|
|
RedisplayText(selectedIndex);
|
|
}
|
|
|
|
// First reflow our dropdown so that we know how tall we should be.
|
|
ReflowDropdown(aPresContext, aReflowState);
|
|
RefPtr<nsResizeDropdownAtFinalPosition> resize =
|
|
new nsResizeDropdownAtFinalPosition(this);
|
|
if (NS_SUCCEEDED(aPresContext->PresShell()->PostReflowCallback(resize))) {
|
|
// The reflow callback queue doesn't AddRef so we keep it alive until
|
|
// it's released in its ReflowFinished / ReflowCallbackCanceled.
|
|
Unused << resize.forget();
|
|
}
|
|
|
|
// Get the width of the vertical scrollbar. That will be the inline
|
|
// size of the dropdown button.
|
|
WritingMode wm = aReflowState.GetWritingMode();
|
|
nscoord buttonISize;
|
|
const nsStyleDisplay *disp = StyleDisplay();
|
|
if ((IsThemed(disp) && !aPresContext->GetTheme()->ThemeNeedsComboboxDropmarker()) ||
|
|
StyleDisplay()->mAppearance == NS_THEME_NONE) {
|
|
buttonISize = 0;
|
|
}
|
|
else {
|
|
nsIScrollableFrame* scrollable = do_QueryFrame(mListControlFrame);
|
|
NS_ASSERTION(scrollable, "List must be a scrollable frame");
|
|
buttonISize = scrollable->GetNondisappearingScrollbarWidth(
|
|
PresContext(), aReflowState.rendContext, wm);
|
|
if (buttonISize > aReflowState.ComputedISize()) {
|
|
buttonISize = 0;
|
|
}
|
|
}
|
|
|
|
mDisplayISize = aReflowState.ComputedISize() - buttonISize;
|
|
|
|
nsBlockFrame::Reflow(aPresContext, aDesiredSize, aReflowState, aStatus);
|
|
|
|
// The button should occupy the same space as a scrollbar
|
|
nsSize containerSize = aDesiredSize.PhysicalSize();
|
|
LogicalRect buttonRect = mButtonFrame->GetLogicalRect(containerSize);
|
|
|
|
buttonRect.IStart(wm) =
|
|
aReflowState.ComputedLogicalBorderPadding().IStartEnd(wm) +
|
|
mDisplayISize -
|
|
(aReflowState.ComputedLogicalBorderPadding().IEnd(wm) -
|
|
aReflowState.ComputedLogicalPadding().IEnd(wm));
|
|
buttonRect.ISize(wm) = buttonISize;
|
|
|
|
buttonRect.BStart(wm) = this->GetLogicalUsedBorder(wm).BStart(wm);
|
|
buttonRect.BSize(wm) = mDisplayFrame->BSize(wm) +
|
|
this->GetLogicalUsedPadding(wm).BStartEnd(wm);
|
|
|
|
mButtonFrame->SetRect(buttonRect, containerSize);
|
|
|
|
if (!NS_INLINE_IS_BREAK_BEFORE(aStatus) &&
|
|
!NS_FRAME_IS_FULLY_COMPLETE(aStatus)) {
|
|
// This frame didn't fit inside a fragmentation container. Splitting
|
|
// a nsComboboxControlFrame makes no sense, so we override the status here.
|
|
aStatus = NS_FRAME_COMPLETE;
|
|
}
|
|
}
|
|
|
|
//--------------------------------------------------------------
|
|
|
|
nsIAtom*
|
|
nsComboboxControlFrame::GetType() const
|
|
{
|
|
return nsGkAtoms::comboboxControlFrame;
|
|
}
|
|
|
|
#ifdef DEBUG_FRAME_DUMP
|
|
nsresult
|
|
nsComboboxControlFrame::GetFrameName(nsAString& aResult) const
|
|
{
|
|
return MakeFrameName(NS_LITERAL_STRING("ComboboxControl"), aResult);
|
|
}
|
|
#endif
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
// nsIComboboxControlFrame
|
|
//----------------------------------------------------------------------
|
|
void
|
|
nsComboboxControlFrame::ShowDropDown(bool aDoDropDown)
|
|
{
|
|
MOZ_ASSERT(!XRE_IsContentProcess());
|
|
mDelayedShowDropDown = false;
|
|
EventStates eventStates = mContent->AsElement()->State();
|
|
if (aDoDropDown && eventStates.HasState(NS_EVENT_STATE_DISABLED)) {
|
|
return;
|
|
}
|
|
|
|
if (!mDroppedDown && aDoDropDown) {
|
|
nsFocusManager* fm = nsFocusManager::GetFocusManager();
|
|
if (!fm || fm->GetFocusedContent() == GetContent()) {
|
|
DropDownPositionState state = AbsolutelyPositionDropDown();
|
|
if (state == eDropDownPositionFinal) {
|
|
ShowList(aDoDropDown); // might destroy us
|
|
} else if (state == eDropDownPositionPendingResize) {
|
|
// Delay until after the resize reflow, see nsAsyncResize.
|
|
mDelayedShowDropDown = true;
|
|
}
|
|
} else {
|
|
// Delay until we get focus, see SetFocus().
|
|
mDelayedShowDropDown = true;
|
|
}
|
|
} else if (mDroppedDown && !aDoDropDown) {
|
|
ShowList(aDoDropDown); // might destroy us
|
|
}
|
|
}
|
|
|
|
void
|
|
nsComboboxControlFrame::SetDropDown(nsIFrame* aDropDownFrame)
|
|
{
|
|
mDropdownFrame = aDropDownFrame;
|
|
mListControlFrame = do_QueryFrame(mDropdownFrame);
|
|
if (!sFocused && nsContentUtils::IsFocusedContent(GetContent())) {
|
|
sFocused = this;
|
|
nsListControlFrame::ComboboxFocusSet();
|
|
}
|
|
}
|
|
|
|
nsIFrame*
|
|
nsComboboxControlFrame::GetDropDown()
|
|
{
|
|
return mDropdownFrame;
|
|
}
|
|
|
|
///////////////////////////////////////////////////////////////
|
|
|
|
NS_IMETHODIMP
|
|
nsComboboxControlFrame::RedisplaySelectedText()
|
|
{
|
|
nsAutoScriptBlocker scriptBlocker;
|
|
return RedisplayText(mListControlFrame->GetSelectedIndex());
|
|
}
|
|
|
|
nsresult
|
|
nsComboboxControlFrame::RedisplayText(int32_t aIndex)
|
|
{
|
|
// Get the text to display
|
|
if (aIndex != -1) {
|
|
mListControlFrame->GetOptionText(aIndex, mDisplayedOptionText);
|
|
} else {
|
|
mDisplayedOptionText.Truncate();
|
|
}
|
|
mDisplayedIndex = aIndex;
|
|
|
|
REFLOW_DEBUG_MSG2("RedisplayText \"%s\"\n",
|
|
NS_LossyConvertUTF16toASCII(mDisplayedOptionText).get());
|
|
|
|
// Send reflow command because the new text maybe larger
|
|
nsresult rv = NS_OK;
|
|
if (mDisplayContent) {
|
|
// Don't call ActuallyDisplayText(true) directly here since that
|
|
// could cause recursive frame construction. See bug 283117 and the comment in
|
|
// HandleRedisplayTextEvent() below.
|
|
|
|
// Revoke outstanding events to avoid out-of-order events which could mean
|
|
// displaying the wrong text.
|
|
mRedisplayTextEvent.Revoke();
|
|
|
|
NS_ASSERTION(!nsContentUtils::IsSafeToRunScript(),
|
|
"If we happen to run our redisplay event now, we might kill "
|
|
"ourselves!");
|
|
|
|
RefPtr<RedisplayTextEvent> event = new RedisplayTextEvent(this);
|
|
mRedisplayTextEvent = event;
|
|
if (!nsContentUtils::AddScriptRunner(event))
|
|
mRedisplayTextEvent.Forget();
|
|
}
|
|
return rv;
|
|
}
|
|
|
|
void
|
|
nsComboboxControlFrame::HandleRedisplayTextEvent()
|
|
{
|
|
// First, make sure that the content model is up to date and we've
|
|
// constructed the frames for all our content in the right places.
|
|
// Otherwise they'll end up under the wrong insertion frame when we
|
|
// ActuallyDisplayText, since that flushes out the content sink by
|
|
// calling SetText on a DOM node with aNotify set to true. See bug
|
|
// 289730.
|
|
nsWeakFrame weakThis(this);
|
|
PresContext()->Document()->
|
|
FlushPendingNotifications(Flush_ContentAndNotify);
|
|
if (!weakThis.IsAlive())
|
|
return;
|
|
|
|
// Redirect frame insertions during this method (see GetContentInsertionFrame())
|
|
// so that any reframing that the frame constructor forces upon us is inserted
|
|
// into the correct parent (mDisplayFrame). See bug 282607.
|
|
NS_PRECONDITION(!mInRedisplayText, "Nested RedisplayText");
|
|
mInRedisplayText = true;
|
|
mRedisplayTextEvent.Forget();
|
|
|
|
ActuallyDisplayText(true);
|
|
if (!weakThis.IsAlive()) {
|
|
return;
|
|
}
|
|
// XXXbz This should perhaps be eResize. Check.
|
|
PresContext()->PresShell()->FrameNeedsReflow(mDisplayFrame,
|
|
nsIPresShell::eStyleChange,
|
|
NS_FRAME_IS_DIRTY);
|
|
|
|
mInRedisplayText = false;
|
|
}
|
|
|
|
void
|
|
nsComboboxControlFrame::ActuallyDisplayText(bool aNotify)
|
|
{
|
|
nsCOMPtr<nsIContent> displayContent = mDisplayContent;
|
|
if (mDisplayedOptionText.IsEmpty()) {
|
|
// Have to use a non-breaking space for line-block-size calculations
|
|
// to be right
|
|
static const char16_t space = 0xA0;
|
|
displayContent->SetText(&space, 1, aNotify);
|
|
} else {
|
|
displayContent->SetText(mDisplayedOptionText, aNotify);
|
|
}
|
|
}
|
|
|
|
int32_t
|
|
nsComboboxControlFrame::GetIndexOfDisplayArea()
|
|
{
|
|
return mDisplayedIndex;
|
|
}
|
|
|
|
//----------------------------------------------------------------------
|
|
// nsISelectControlFrame
|
|
//----------------------------------------------------------------------
|
|
NS_IMETHODIMP
|
|
nsComboboxControlFrame::DoneAddingChildren(bool aIsDone)
|
|
{
|
|
nsISelectControlFrame* listFrame = do_QueryFrame(mDropdownFrame);
|
|
if (!listFrame)
|
|
return NS_ERROR_FAILURE;
|
|
|
|
return listFrame->DoneAddingChildren(aIsDone);
|
|
}
|
|
|
|
NS_IMETHODIMP
|
|
nsComboboxControlFrame::AddOption(int32_t aIndex)
|
|
{
|
|
if (aIndex <= mDisplayedIndex) {
|
|
++mDisplayedIndex;
|
|
}
|
|
|
|
nsListControlFrame* lcf = static_cast<nsListControlFrame*>(mDropdownFrame);
|
|
return lcf->AddOption(aIndex);
|
|
}
|
|
|
|
|
|
NS_IMETHODIMP
|
|
nsComboboxControlFrame::RemoveOption(int32_t aIndex)
|
|
{
|
|
nsWeakFrame weakThis(this);
|
|
if (mListControlFrame->GetNumberOfOptions() > 0) {
|
|
if (aIndex < mDisplayedIndex) {
|
|
--mDisplayedIndex;
|
|
} else if (aIndex == mDisplayedIndex) {
|
|
mDisplayedIndex = 0; // IE6 compat
|
|
RedisplayText(mDisplayedIndex);
|
|
}
|
|
}
|
|
else {
|
|
// If we removed the last option, we need to blank things out
|
|
RedisplayText(-1);
|
|
}
|
|
|
|
if (!weakThis.IsAlive())
|
|
return NS_OK;
|
|
|
|
nsListControlFrame* lcf = static_cast<nsListControlFrame*>(mDropdownFrame);
|
|
return lcf->RemoveOption(aIndex);
|
|
}
|
|
|
|
NS_IMETHODIMP
|
|
nsComboboxControlFrame::OnSetSelectedIndex(int32_t aOldIndex, int32_t aNewIndex)
|
|
{
|
|
nsAutoScriptBlocker scriptBlocker;
|
|
RedisplayText(aNewIndex);
|
|
NS_ASSERTION(mDropdownFrame, "No dropdown frame!");
|
|
|
|
nsISelectControlFrame* listFrame = do_QueryFrame(mDropdownFrame);
|
|
NS_ASSERTION(listFrame, "No list frame!");
|
|
|
|
return listFrame->OnSetSelectedIndex(aOldIndex, aNewIndex);
|
|
}
|
|
|
|
// End nsISelectControlFrame
|
|
//----------------------------------------------------------------------
|
|
|
|
nsresult
|
|
nsComboboxControlFrame::HandleEvent(nsPresContext* aPresContext,
|
|
WidgetGUIEvent* aEvent,
|
|
nsEventStatus* aEventStatus)
|
|
{
|
|
NS_ENSURE_ARG_POINTER(aEventStatus);
|
|
|
|
if (nsEventStatus_eConsumeNoDefault == *aEventStatus) {
|
|
return NS_OK;
|
|
}
|
|
|
|
EventStates eventStates = mContent->AsElement()->State();
|
|
if (eventStates.HasState(NS_EVENT_STATE_DISABLED)) {
|
|
return NS_OK;
|
|
}
|
|
|
|
#if COMBOBOX_ROLLUP_CONSUME_EVENT == 0
|
|
if (aEvent->mMessage == eMouseDown) {
|
|
nsIWidget* widget = GetNearestWidget();
|
|
if (widget && GetContent() == widget->GetLastRollup()) {
|
|
// This event did a Rollup on this control - prevent it from opening
|
|
// the dropdown again!
|
|
*aEventStatus = nsEventStatus_eConsumeNoDefault;
|
|
return NS_OK;
|
|
}
|
|
}
|
|
#endif
|
|
|
|
// If we have style that affects how we are selected, feed event down to
|
|
// nsFrame::HandleEvent so that selection takes place when appropriate.
|
|
const nsStyleUserInterface* uiStyle = StyleUserInterface();
|
|
if (uiStyle->mUserInput == NS_STYLE_USER_INPUT_NONE || uiStyle->mUserInput == NS_STYLE_USER_INPUT_DISABLED)
|
|
return nsBlockFrame::HandleEvent(aPresContext, aEvent, aEventStatus);
|
|
|
|
return NS_OK;
|
|
}
|
|
|
|
|
|
nsresult
|
|
nsComboboxControlFrame::SetFormProperty(nsIAtom* aName, const nsAString& aValue)
|
|
{
|
|
nsIFormControlFrame* fcFrame = do_QueryFrame(mDropdownFrame);
|
|
if (!fcFrame) {
|
|
return NS_NOINTERFACE;
|
|
}
|
|
|
|
return fcFrame->SetFormProperty(aName, aValue);
|
|
}
|
|
|
|
nsContainerFrame*
|
|
nsComboboxControlFrame::GetContentInsertionFrame() {
|
|
return mInRedisplayText ? mDisplayFrame : mDropdownFrame->GetContentInsertionFrame();
|
|
}
|
|
|
|
nsresult
|
|
nsComboboxControlFrame::CreateAnonymousContent(nsTArray<ContentInfo>& aElements)
|
|
{
|
|
// The frames used to display the combo box and the button used to popup the dropdown list
|
|
// are created through anonymous content. The dropdown list is not created through anonymous
|
|
// content because its frame is initialized specifically for the drop-down case and it is placed
|
|
// a special list referenced through NS_COMBO_FRAME_POPUP_LIST_INDEX to keep separate from the
|
|
// layout of the display and button.
|
|
//
|
|
// Note: The value attribute of the display content is set when an item is selected in the dropdown list.
|
|
// If the content specified below does not honor the value attribute than nothing will be displayed.
|
|
|
|
// For now the content that is created corresponds to two input buttons. It would be better to create the
|
|
// tag as something other than input, but then there isn't any way to create a button frame since it
|
|
// isn't possible to set the display type in CSS2 to create a button frame.
|
|
|
|
// create content used for display
|
|
//nsIAtom* tag = NS_Atomize("mozcombodisplay");
|
|
|
|
// Add a child text content node for the label
|
|
|
|
nsNodeInfoManager *nimgr = mContent->NodeInfo()->NodeInfoManager();
|
|
|
|
mDisplayContent = new nsTextNode(nimgr);
|
|
|
|
// set the value of the text node
|
|
mDisplayedIndex = mListControlFrame->GetSelectedIndex();
|
|
if (mDisplayedIndex != -1) {
|
|
mListControlFrame->GetOptionText(mDisplayedIndex, mDisplayedOptionText);
|
|
}
|
|
ActuallyDisplayText(false);
|
|
|
|
if (!aElements.AppendElement(mDisplayContent))
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
mButtonContent = mContent->OwnerDoc()->CreateHTMLElement(nsGkAtoms::button);
|
|
if (!mButtonContent)
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
// make someone to listen to the button. If its pressed by someone like Accessibility
|
|
// then open or close the combo box.
|
|
mButtonListener = new nsComboButtonListener(this);
|
|
mButtonContent->AddEventListener(NS_LITERAL_STRING("click"), mButtonListener,
|
|
false, false);
|
|
|
|
mButtonContent->SetAttr(kNameSpaceID_None, nsGkAtoms::type,
|
|
NS_LITERAL_STRING("button"), false);
|
|
// Set tabindex="-1" so that the button is not tabbable
|
|
mButtonContent->SetAttr(kNameSpaceID_None, nsGkAtoms::tabindex,
|
|
NS_LITERAL_STRING("-1"), false);
|
|
|
|
WritingMode wm = GetWritingMode();
|
|
if (wm.IsVertical()) {
|
|
mButtonContent->SetAttr(kNameSpaceID_None, nsGkAtoms::orientation,
|
|
wm.IsVerticalRL() ? NS_LITERAL_STRING("left")
|
|
: NS_LITERAL_STRING("right"),
|
|
false);
|
|
}
|
|
|
|
if (!aElements.AppendElement(mButtonContent))
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
return NS_OK;
|
|
}
|
|
|
|
void
|
|
nsComboboxControlFrame::AppendAnonymousContentTo(nsTArray<nsIContent*>& aElements,
|
|
uint32_t aFilter)
|
|
{
|
|
if (mDisplayContent) {
|
|
aElements.AppendElement(mDisplayContent);
|
|
}
|
|
|
|
if (mButtonContent) {
|
|
aElements.AppendElement(mButtonContent);
|
|
}
|
|
}
|
|
|
|
// XXXbz this is a for-now hack. Now that display:inline-block works,
|
|
// need to revisit this.
|
|
class nsComboboxDisplayFrame : public nsBlockFrame {
|
|
public:
|
|
NS_DECL_FRAMEARENA_HELPERS
|
|
|
|
nsComboboxDisplayFrame (nsStyleContext* aContext,
|
|
nsComboboxControlFrame* aComboBox)
|
|
: nsBlockFrame(aContext),
|
|
mComboBox(aComboBox)
|
|
{}
|
|
|
|
// Need this so that line layout knows that this block's inline size
|
|
// depends on the available inline size.
|
|
virtual nsIAtom* GetType() const override;
|
|
|
|
virtual bool IsFrameOfType(uint32_t aFlags) const override
|
|
{
|
|
return nsBlockFrame::IsFrameOfType(aFlags &
|
|
~(nsIFrame::eReplacedContainsBlock));
|
|
}
|
|
|
|
virtual void Reflow(nsPresContext* aPresContext,
|
|
nsHTMLReflowMetrics& aDesiredSize,
|
|
const nsHTMLReflowState& aReflowState,
|
|
nsReflowStatus& aStatus) override;
|
|
|
|
virtual void BuildDisplayList(nsDisplayListBuilder* aBuilder,
|
|
const nsRect& aDirtyRect,
|
|
const nsDisplayListSet& aLists) override;
|
|
|
|
protected:
|
|
nsComboboxControlFrame* mComboBox;
|
|
};
|
|
|
|
NS_IMPL_FRAMEARENA_HELPERS(nsComboboxDisplayFrame)
|
|
|
|
nsIAtom*
|
|
nsComboboxDisplayFrame::GetType() const
|
|
{
|
|
return nsGkAtoms::comboboxDisplayFrame;
|
|
}
|
|
|
|
void
|
|
nsComboboxDisplayFrame::Reflow(nsPresContext* aPresContext,
|
|
nsHTMLReflowMetrics& aDesiredSize,
|
|
const nsHTMLReflowState& aReflowState,
|
|
nsReflowStatus& aStatus)
|
|
{
|
|
nsHTMLReflowState state(aReflowState);
|
|
if (state.ComputedBSize() == NS_INTRINSICSIZE) {
|
|
// Note that the only way we can have a computed block size here is
|
|
// if the combobox had a specified block size. If it didn't, size
|
|
// based on what our rows look like, for lack of anything better.
|
|
state.SetComputedBSize(mComboBox->mListControlFrame->GetBSizeOfARow());
|
|
}
|
|
WritingMode wm = aReflowState.GetWritingMode();
|
|
nscoord computedISize = mComboBox->mDisplayISize -
|
|
state.ComputedLogicalBorderPadding().IStartEnd(wm);
|
|
if (computedISize < 0) {
|
|
computedISize = 0;
|
|
}
|
|
state.SetComputedISize(computedISize);
|
|
nsBlockFrame::Reflow(aPresContext, aDesiredSize, state, aStatus);
|
|
aStatus = NS_FRAME_COMPLETE; // this type of frame can't be split
|
|
}
|
|
|
|
void
|
|
nsComboboxDisplayFrame::BuildDisplayList(nsDisplayListBuilder* aBuilder,
|
|
const nsRect& aDirtyRect,
|
|
const nsDisplayListSet& aLists)
|
|
{
|
|
nsDisplayListCollection set;
|
|
nsBlockFrame::BuildDisplayList(aBuilder, aDirtyRect, set);
|
|
|
|
// remove background items if parent frame is themed
|
|
if (mComboBox->IsThemed()) {
|
|
set.BorderBackground()->DeleteAll();
|
|
}
|
|
|
|
set.MoveTo(aLists);
|
|
}
|
|
|
|
nsIFrame*
|
|
nsComboboxControlFrame::CreateFrameFor(nsIContent* aContent)
|
|
{
|
|
NS_PRECONDITION(nullptr != aContent, "null ptr");
|
|
|
|
NS_ASSERTION(mDisplayContent, "mDisplayContent can't be null!");
|
|
|
|
if (mDisplayContent != aContent) {
|
|
// We only handle the frames for mDisplayContent here
|
|
return nullptr;
|
|
}
|
|
|
|
// Get PresShell
|
|
nsIPresShell *shell = PresContext()->PresShell();
|
|
StyleSetHandle styleSet = shell->StyleSet();
|
|
|
|
// create the style contexts for the anonymous block frame and text frame
|
|
RefPtr<nsStyleContext> styleContext;
|
|
styleContext = styleSet->
|
|
ResolveAnonymousBoxStyle(nsCSSAnonBoxes::mozDisplayComboboxControlFrame,
|
|
mStyleContext,
|
|
nsStyleSet::eSkipParentDisplayBasedStyleFixup);
|
|
|
|
RefPtr<nsStyleContext> textStyleContext;
|
|
textStyleContext =
|
|
styleSet->ResolveStyleForText(mDisplayContent, mStyleContext);
|
|
|
|
// Start by creating our anonymous block frame
|
|
mDisplayFrame = new (shell) nsComboboxDisplayFrame(styleContext, this);
|
|
mDisplayFrame->Init(mContent, this, nullptr);
|
|
|
|
// Create a text frame and put it inside the block frame
|
|
nsIFrame* textFrame = NS_NewTextFrame(shell, textStyleContext);
|
|
|
|
// initialize the text frame
|
|
textFrame->Init(aContent, mDisplayFrame, nullptr);
|
|
mDisplayContent->SetPrimaryFrame(textFrame);
|
|
|
|
nsFrameList textList(textFrame, textFrame);
|
|
mDisplayFrame->SetInitialChildList(kPrincipalList, textList);
|
|
return mDisplayFrame;
|
|
}
|
|
|
|
void
|
|
nsComboboxControlFrame::DestroyFrom(nsIFrame* aDestructRoot)
|
|
{
|
|
if (sFocused == this) {
|
|
sFocused = nullptr;
|
|
}
|
|
|
|
// Revoke any pending RedisplayTextEvent
|
|
mRedisplayTextEvent.Revoke();
|
|
|
|
nsFormControlFrame::RegUnRegAccessKey(static_cast<nsIFrame*>(this), false);
|
|
|
|
if (mDroppedDown) {
|
|
MOZ_ASSERT(mDropdownFrame, "mDroppedDown without frame");
|
|
nsView* view = mDropdownFrame->GetView();
|
|
MOZ_ASSERT(view);
|
|
nsIWidget* widget = view->GetWidget();
|
|
if (widget) {
|
|
widget->CaptureRollupEvents(this, false);
|
|
}
|
|
}
|
|
|
|
// Cleanup frames in popup child list
|
|
mPopupFrames.DestroyFramesFrom(aDestructRoot);
|
|
nsContentUtils::DestroyAnonymousContent(&mDisplayContent);
|
|
nsContentUtils::DestroyAnonymousContent(&mButtonContent);
|
|
nsBlockFrame::DestroyFrom(aDestructRoot);
|
|
}
|
|
|
|
const nsFrameList&
|
|
nsComboboxControlFrame::GetChildList(ChildListID aListID) const
|
|
{
|
|
if (kSelectPopupList == aListID) {
|
|
return mPopupFrames;
|
|
}
|
|
return nsBlockFrame::GetChildList(aListID);
|
|
}
|
|
|
|
void
|
|
nsComboboxControlFrame::GetChildLists(nsTArray<ChildList>* aLists) const
|
|
{
|
|
nsBlockFrame::GetChildLists(aLists);
|
|
mPopupFrames.AppendIfNonempty(aLists, kSelectPopupList);
|
|
}
|
|
|
|
void
|
|
nsComboboxControlFrame::SetInitialChildList(ChildListID aListID,
|
|
nsFrameList& aChildList)
|
|
{
|
|
if (kSelectPopupList == aListID) {
|
|
mPopupFrames.SetFrames(aChildList);
|
|
} else {
|
|
for (nsFrameList::Enumerator e(aChildList); !e.AtEnd(); e.Next()) {
|
|
nsCOMPtr<nsIFormControl> formControl =
|
|
do_QueryInterface(e.get()->GetContent());
|
|
if (formControl && formControl->GetType() == NS_FORM_BUTTON_BUTTON) {
|
|
mButtonFrame = e.get();
|
|
break;
|
|
}
|
|
}
|
|
NS_ASSERTION(mButtonFrame, "missing button frame in initial child list");
|
|
nsBlockFrame::SetInitialChildList(aListID, aChildList);
|
|
}
|
|
}
|
|
|
|
//----------------------------------------------------------------------
|
|
//nsIRollupListener
|
|
//----------------------------------------------------------------------
|
|
bool
|
|
nsComboboxControlFrame::Rollup(uint32_t aCount, bool aFlush,
|
|
const nsIntPoint* pos, nsIContent** aLastRolledUp)
|
|
{
|
|
if (!mDroppedDown) {
|
|
return false;
|
|
}
|
|
|
|
bool consume = !!COMBOBOX_ROLLUP_CONSUME_EVENT;
|
|
nsWeakFrame weakFrame(this);
|
|
mListControlFrame->AboutToRollup(); // might destroy us
|
|
if (!weakFrame.IsAlive()) {
|
|
return consume;
|
|
}
|
|
ShowDropDown(false); // might destroy us
|
|
if (weakFrame.IsAlive()) {
|
|
mListControlFrame->CaptureMouseEvents(false);
|
|
}
|
|
|
|
if (aFlush && weakFrame.IsAlive()) {
|
|
// The popup's visibility doesn't update until the minimize animation has
|
|
// finished, so call UpdateWidgetGeometry to update it right away.
|
|
nsViewManager* viewManager = mDropdownFrame->GetView()->GetViewManager();
|
|
viewManager->UpdateWidgetGeometry();
|
|
}
|
|
|
|
if (aLastRolledUp) {
|
|
*aLastRolledUp = GetContent();
|
|
}
|
|
return consume;
|
|
}
|
|
|
|
nsIWidget*
|
|
nsComboboxControlFrame::GetRollupWidget()
|
|
{
|
|
nsView* view = mDropdownFrame->GetView();
|
|
MOZ_ASSERT(view);
|
|
return view->GetWidget();
|
|
}
|
|
|
|
void
|
|
nsComboboxControlFrame::RollupFromList()
|
|
{
|
|
if (ShowList(false))
|
|
mListControlFrame->CaptureMouseEvents(false);
|
|
}
|
|
|
|
int32_t
|
|
nsComboboxControlFrame::UpdateRecentIndex(int32_t aIndex)
|
|
{
|
|
int32_t index = mRecentSelectedIndex;
|
|
if (mRecentSelectedIndex == NS_SKIP_NOTIFY_INDEX || aIndex == NS_SKIP_NOTIFY_INDEX)
|
|
mRecentSelectedIndex = aIndex;
|
|
return index;
|
|
}
|
|
|
|
class nsDisplayComboboxFocus : public nsDisplayItem {
|
|
public:
|
|
nsDisplayComboboxFocus(nsDisplayListBuilder* aBuilder,
|
|
nsComboboxControlFrame* aFrame)
|
|
: nsDisplayItem(aBuilder, aFrame) {
|
|
MOZ_COUNT_CTOR(nsDisplayComboboxFocus);
|
|
}
|
|
#ifdef NS_BUILD_REFCNT_LOGGING
|
|
virtual ~nsDisplayComboboxFocus() {
|
|
MOZ_COUNT_DTOR(nsDisplayComboboxFocus);
|
|
}
|
|
#endif
|
|
|
|
virtual void Paint(nsDisplayListBuilder* aBuilder,
|
|
nsRenderingContext* aCtx) override;
|
|
NS_DISPLAY_DECL_NAME("ComboboxFocus", TYPE_COMBOBOX_FOCUS)
|
|
};
|
|
|
|
void nsDisplayComboboxFocus::Paint(nsDisplayListBuilder* aBuilder,
|
|
nsRenderingContext* aCtx)
|
|
{
|
|
static_cast<nsComboboxControlFrame*>(mFrame)
|
|
->PaintFocus(*aCtx->GetDrawTarget(), ToReferenceFrame());
|
|
}
|
|
|
|
void
|
|
nsComboboxControlFrame::BuildDisplayList(nsDisplayListBuilder* aBuilder,
|
|
const nsRect& aDirtyRect,
|
|
const nsDisplayListSet& aLists)
|
|
{
|
|
#ifdef NOISY
|
|
printf("%p paint at (%d, %d, %d, %d)\n", this,
|
|
aDirtyRect.x, aDirtyRect.y, aDirtyRect.width, aDirtyRect.height);
|
|
#endif
|
|
|
|
if (aBuilder->IsForEventDelivery()) {
|
|
// Don't allow children to receive events.
|
|
// REVIEW: following old GetFrameForPoint
|
|
DisplayBorderBackgroundOutline(aBuilder, aLists);
|
|
} else {
|
|
// REVIEW: Our in-flow child frames are inline-level so they will paint in our
|
|
// content list, so we don't need to mess with layers.
|
|
nsBlockFrame::BuildDisplayList(aBuilder, aDirtyRect, aLists);
|
|
}
|
|
|
|
// draw a focus indicator only when focus rings should be drawn
|
|
nsIDocument* doc = mContent->GetComposedDoc();
|
|
if (doc) {
|
|
nsPIDOMWindow* window = doc->GetWindow();
|
|
if (window && window->ShouldShowFocusRing()) {
|
|
nsPresContext *presContext = PresContext();
|
|
const nsStyleDisplay *disp = StyleDisplay();
|
|
if ((!IsThemed(disp) ||
|
|
!presContext->GetTheme()->ThemeDrawsFocusForWidget(disp->mAppearance)) &&
|
|
mDisplayFrame && IsVisibleForPainting(aBuilder)) {
|
|
aLists.Content()->AppendNewToTop(
|
|
new (aBuilder) nsDisplayComboboxFocus(aBuilder, this));
|
|
}
|
|
}
|
|
}
|
|
|
|
DisplaySelectionOverlay(aBuilder, aLists.Content());
|
|
}
|
|
|
|
void nsComboboxControlFrame::PaintFocus(DrawTarget& aDrawTarget, nsPoint aPt)
|
|
{
|
|
/* Do we need to do anything? */
|
|
EventStates eventStates = mContent->AsElement()->State();
|
|
if (eventStates.HasState(NS_EVENT_STATE_DISABLED) || sFocused != this)
|
|
return;
|
|
|
|
int32_t appUnitsPerDevPixel = PresContext()->AppUnitsPerDevPixel();
|
|
|
|
nsRect clipRect = mDisplayFrame->GetRect() + aPt;
|
|
aDrawTarget.PushClipRect(NSRectToSnappedRect(clipRect,
|
|
appUnitsPerDevPixel,
|
|
aDrawTarget));
|
|
|
|
// REVIEW: Why does the old code paint mDisplayFrame again? We've
|
|
// already painted it in the children above. So clipping it here won't do
|
|
// us much good.
|
|
|
|
/////////////////////
|
|
// draw focus
|
|
|
|
StrokeOptions strokeOptions;
|
|
nsLayoutUtils::InitDashPattern(strokeOptions, NS_STYLE_BORDER_STYLE_DOTTED);
|
|
ColorPattern color(ToDeviceColor(StyleColor()->mColor));
|
|
nscoord onePixel = nsPresContext::CSSPixelsToAppUnits(1);
|
|
clipRect.width -= onePixel;
|
|
clipRect.height -= onePixel;
|
|
Rect r = ToRect(nsLayoutUtils::RectToGfxRect(clipRect, appUnitsPerDevPixel));
|
|
StrokeSnappedEdgesOfRect(r, aDrawTarget, color, strokeOptions);
|
|
|
|
aDrawTarget.PopClip();
|
|
}
|
|
|
|
//---------------------------------------------------------
|
|
// gets the content (an option) by index and then set it as
|
|
// being selected or not selected
|
|
//---------------------------------------------------------
|
|
NS_IMETHODIMP
|
|
nsComboboxControlFrame::OnOptionSelected(int32_t aIndex, bool aSelected)
|
|
{
|
|
if (mDroppedDown) {
|
|
nsISelectControlFrame *selectFrame = do_QueryFrame(mListControlFrame);
|
|
if (selectFrame) {
|
|
selectFrame->OnOptionSelected(aIndex, aSelected);
|
|
}
|
|
} else {
|
|
if (aSelected) {
|
|
nsAutoScriptBlocker blocker;
|
|
RedisplayText(aIndex);
|
|
} else {
|
|
nsWeakFrame weakFrame(this);
|
|
RedisplaySelectedText();
|
|
if (weakFrame.IsAlive()) {
|
|
FireValueChangeEvent(); // Fire after old option is unselected
|
|
}
|
|
}
|
|
}
|
|
|
|
return NS_OK;
|
|
}
|
|
|
|
void nsComboboxControlFrame::FireValueChangeEvent()
|
|
{
|
|
// Fire ValueChange event to indicate data value of combo box has changed
|
|
nsContentUtils::AddScriptRunner(
|
|
new AsyncEventDispatcher(mContent, NS_LITERAL_STRING("ValueChange"), true,
|
|
false));
|
|
}
|
|
|
|
void
|
|
nsComboboxControlFrame::OnContentReset()
|
|
{
|
|
if (mListControlFrame) {
|
|
mListControlFrame->OnContentReset();
|
|
}
|
|
}
|
|
|
|
|
|
//--------------------------------------------------------
|
|
// nsIStatefulFrame
|
|
//--------------------------------------------------------
|
|
NS_IMETHODIMP
|
|
nsComboboxControlFrame::SaveState(nsPresState** aState)
|
|
{
|
|
MOZ_ASSERT(!(*aState));
|
|
(*aState) = new nsPresState();
|
|
(*aState)->SetDroppedDown(mDroppedDown);
|
|
return NS_OK;
|
|
}
|
|
|
|
NS_IMETHODIMP
|
|
nsComboboxControlFrame::RestoreState(nsPresState* aState)
|
|
{
|
|
if (!aState) {
|
|
return NS_ERROR_FAILURE;
|
|
}
|
|
ShowList(aState->GetDroppedDown()); // might destroy us
|
|
return NS_OK;
|
|
}
|
|
|
|
// Append a suffix so that the state key for the combobox is different
|
|
// from the state key the list control uses to sometimes save the scroll
|
|
// position for the same Element
|
|
NS_IMETHODIMP
|
|
nsComboboxControlFrame::GenerateStateKey(nsIContent* aContent,
|
|
nsIDocument* aDocument,
|
|
nsACString& aKey)
|
|
{
|
|
nsresult rv = nsContentUtils::GenerateStateKey(aContent, aDocument, aKey);
|
|
if (NS_FAILED(rv) || aKey.IsEmpty()) {
|
|
return rv;
|
|
}
|
|
aKey.Append("CCF");
|
|
return NS_OK;
|
|
}
|
|
|
|
// Fennec uses a custom combobox built-in widget.
|
|
//
|
|
|
|
/* static */
|
|
bool
|
|
nsComboboxControlFrame::ToolkitHasNativePopup()
|
|
{
|
|
#ifdef MOZ_USE_NATIVE_POPUP_WINDOWS
|
|
return true;
|
|
#else
|
|
return false;
|
|
#endif /* MOZ_USE_NATIVE_POPUP_WINDOWS */
|
|
}
|
|
|