mirror of
https://github.com/roytam1/palemoon27.git
synced 2026-05-26 14:18:48 +00:00
049b3235ac
- Bug 1207494 - Part 8: Remove use of expression closure from dom/identity/. r=ferjm (34fac889f8) - minor crash thing (13fe2827c2) - Bug 1243359 - initialize mScrollSeriesNumber in all ScrollWheelInput constructors. r=roc (94163d8eca) - fix misspatch (b380a7bbe4) - Bug 1207412 - Make SystemTimeConverter use TimeStamp::Now() when converting times; r=karlt (f408549605) - Bug 1212102 - Drop unnecessary assertion comparing timestamps in SystemTimeConverter; r=karlt (1efaa04b3f) - Bug 1241302 - Slightly modernize this code. r=jst (c1e97bc069) - bug 1216916 clean up when InvokeDragSessionWithImage/Selection() fails r=roc (9cdf71b717) - Bug 1231329 - run ConvertToUnscaledDevPixels if *aPresContext is valid. r=roc (d10f23633b) - Bug 1245927: Innerize before creating DOM files from the file picker. r=baku (8754128362) - Bug 1155214 - Mark nsIBidiKeyboard as builtinclass; r=mrbkap (2d00326d2b) - reorder (c3c1ba92c9) - Bug 1236566 - add override declarations for widget/windows/GfxInfo.h; r=roc (940b40ed91) - Bug 1242659: Part 1. More information on the mismatches. r=jrmuizel (78331ddad2) - Block some Radeon drivers that crash on D3D9. (bug 1213107, r=jrmuizel) (482b66d313) - Bug 1203199 - Blacklist DXVA on some older intel drivers for causing crashes. r=jrmuizel (f1827d4498) - Bug 1203199 - Fix driver range with blacklist to avoid blacklisting other OSes. (2c2d547296) - Bug 1203199 - Bustage fix. CLOSED TREE (3233d407f3) - Bug 1178385. Enable DXVA on the G45 r=ajones (3c59a58a15) - Bug 1188442 IMMHandler::GetSelection() should use static Selection instance when IME doesn't have focus and return its or mSelection's reference r=emk (5cc4b30433) - Bug 1238899 Create hidden native caret for ATOK at composing in windowless plugin r=m_kato (40ef5bb4aa) - Bug 1257919 part 1. Kill off nsIXSLTException. r=khuey (11f37643f2) - Bug 1242072 - Change implementation of BaseProxyHandler::get() to follow ES6 [[Get]] specification. r=jorendorff (094a67f284) - Bug 489636 - Add a GC u-bench test for property tree splitting via deletion; r=sfink (9282fec25f) - Bug 1257919 part 2. Make nsIException and nsIStackFrame builtinclass, so we can start using [implicit_jscontext] on them. r=khuey (0e65fb8554) - Bug 1257919 part 3. Make the various toString methods on exceptions take an explicit JSContext. r=khuey (b342fb4930) - Bug 1257919 part 4. Stop returning StackFrame instances from exceptions::CreateStack. C++ callers of GetCurrentJSStack or exceptions::CreateStack always check for null anyway, and none of them seem to want this non-JS thing. r=khuey (d34036ccf9) - Bug 1257919 part 5. Get rid of the now-unused StackFrame class. r=khuey (aa13af0dfe) - Bug 1141222 - Create ScriptError with stack from Cu.reportError. r=bholley (b83ad26aa0) - Bug 1208641 - Extract stack from DOM/XPC exception. r=bholley (e382b5f48c) - Bug 1254380 part 1. Find the relevant window when the compartment we've got is an addon sandbox compartment in AutoJSAPI exception/warning reporting code. r=bholley (4b1f6c64a9) - Bug 1250630 - remove PBackgroundTest and ifdef ENABLE_TEST blocks. r=khuey (d7b36860a3) - Bug 1250963 part 1. Change NotifyRunnable::Dispatch to not require a JSContext. r=khuey (48e03c2fc2) - Bug 1250963 part 2. Remove the unused JSContext argument of WorkerPrivate::ModifyBusyCount. r=khuey (0f5ca42be1) - Bug 1250291 part 1. Stop pretending to report exceptions in MainThreadStopSyncLoopRunnable::PostDispatch. r=khuey (6e1c81cc06) - Bug 1250291 part 2. Stop pretending to report exceptions in MainThreadWorkerSyncRunnable::PostDispatch. r=khuey (f3d846ea31) - Bug 1250291 part 3. Stop pretending to report exceptions in WorkerDebuggerRunnable::PostDispatch. r=khuey (10bc1710d1) - Bug 1250975. Stop passing a JSContext argument to WorkerRunnable::PreDispatch and its overrides. r=khuey (71ab9046f0) - Bug 1255298. Just pass through the JSContext when passing through the NotificationOptions in notification code. r=wchen (552ae8e33e) - Bug 1250185 part 2. Remove some JSContext stuff that's no longer needed in Notification code. r=khuey (20b99ef28b) - Bug 1251045 part 8. Remove the JSContext argument from some nsINotificationStorageCallback methods. r=khuey (170c4afabc) - Bug 1227015 P7 Supress unused ErrorResult exception if the worker runnable failed to dispatch. r=catalinb (23a3cc6f45) - Bug 1251045 part 3. Remove the JSContext argument of WorkerRunnable::PostDispatch and its overrides. r=khuey (6a666d1a4a) - Bug 1251045 part 2. Remove the JSContext argument of ModifyBusyCountFromWorker. r=khuey (105bc4f59e) - Bug 1252130. Remove unnecessary JSContext argument from NotificationWorkerRunnable::WorkerRunInternal. r=khuey (642727f6f6) - Bug 1252127. Remove unnecessary JSContext argument from PromiseWorkerProxy::CleanUp. r=khuey (339e1157d1) - Bug 1251045 part 1. Make it possible to dispatch a ModifyBusyCountRunnable without a JSContext. r=khuey (665c1f81b4) - Bug 1251045 part 4. Remove the JSContext argument of WorkerRunnable::Dispatch. r=khuey (6c5cdab2b7) - Bug 1250185 part 1. nsIStructuredCloneContainer.initFromBase64 doesn't need a JSContext argument. r=khuey (d63a219209) - fix (773c0393aa) - Bug 1251045 part 5. Remove the JSContext argument from WorkerPrivateParent::Freeze/Thaw. r=khuey (cd419bfd2c) - Bug 1251045 part 6. Remove the JSContext argument from some worker debugger methods that no longer need it. r=khuey (abcc437cb9) - Bug 1251045 part 7. Remove the JSContext argument from some worker methods that no longer need it. r=khuey (3ddcbca08c) - Bug 1249652 part 1. Add a method on ErrorResult to steal an exception, if any, from a JSContext. r=khuey (9c07f5044b) - Bug 1229071 - importScripts should throw the correct error result in case the loading of one of scripts fails, r=bz (cd37645d76) - Bug 1229970 Abort script loading start requests if a load has been canceled. r=khuey (a44d9128ca) - Bug 1233171 Cancel channel when ScriptLoader is aborted during service worker script load. r=khuey (3b6ceafec7) - Bug 1249351 part 1. When doing importScripts of multiple scripts in a service worker, make sure to track the cache streams per-loadinfo, instead of trying to make them all wait on the same stream. r=bkelly (e1ccea9685) - Bug 1157544 - Fix a typo in the test; r=baku (8c0bf8f504) - Bug 1249351 part 2. Clean up test_importscript.html and add multiple-url importScript() case. r=bz (52b0a31032) - Bug 1249652 part 2. ScriptExecutorRunnable::WorkerRun should immediately move JS exceptions to its ErrorResult instead of allowing them to linger on the JSContext. r=baku,khuey (f628d3c8ba) - Bug 1249652 part 3. Simplify way we handle canceling when ScriptLoaderRunnable::RunInternal fails by canceling things with its actual failure code, so we don't have to guess which failed loads are actual failures and which are just canceled via this mechanism. r=baku,khuey (388543fbc3) - Bug 1251369. Use an AutoJSAPI that reports its own exceptions around the main runloop in workers. r=khuey (28b33287cd) - Bug 1251518. Fix js::ErrorReportToString to make a bit more sense, and change worker code to not use it anyway, so it matches the mainthread code. r=bholley,terrence (a48a40de90) - Bug 1254380 part 2. Go ahead and log the stack from our exception in AutoJSAPI::ReportException even if we don't have a window. r=bholley (64532b6017) - Bug 1212328 - Clean up some JSErrorReport-related code. r=Waldo,bz (d5aa611edc) - Bug 1255192 part 1. Remove the JSContext argument of JS::ExceptionStackOrNull. r=bholley (39b631d5ad) - bug 1252687 - make the ctor for CycleCollectorStats constexpr r=mccr8 (9e8168d8ac) - Bug 1254380 part 3. Skip firing error events for mainthread out of memory exceptions via AutoJSAPI::ReportException. r=bholley (d5e4e7dc29) - Bug 1254230 kinda-fix. Make sure to never send script errors with stacks attached to the console service if the associated windows have already had FreeInnerObjects called on them. r=bholley (8c379fe0e0) - Bug 1255192 part 2. Clean up the JSContext usage around xpc::FindExceptionStackForConsoleReport now that it just needs a JSContext for rooting. r=bholley (cade862491) - Bug 1255201. Improve the stack handling in nsXPCComponents_Utils::ReportError for the DOMException case to include the stack from the DOMException. r=bholley (fc6c065284) - Bug 1257919 part 6. Make the filename getter on JSStackFrame take an explicit JSContext. r=khuey (cde115b789) - Bug 1257919 part 7. Make the name getter on JSStackFrame take an explicit JSContext. r=khuey (d7466e9eab) - Bug 1257919 part 8. Make the line/column number getters on JSStackFrame take an explicit JSContext. r=khuey (b8766b98b2) - Bug 1257919 part 9. Make the asyncCause/asyncCaller getters on JSStackFrame take an explicit JSContext. r=khuey (b776ff9c6d) - Bug 1257919 part 10. Make the caller and formattedStack getters on JSStackFrame take an explicit JSContext. r=khuey (dc4d3d9091) - Bug 1252091. Add/RemoveFeature don't need a JSContext argument. r=khuey (5be6253a67) - Bug 1252123. Remove some unnecessary JSContext arguments from worker ScriptLoader methods. r=khuey (1657a35268) - Bug 1255181. Remove AutoJSAPI::InitWithLegacyErrorReporting. r=bholley (5ee7ac506e) - Bug 1254847 part 1. Take ownership of error reporting on the AutoEntryScript in nsXPCWrappedJSClass::DelegatedQueryInterface. r=bholley (62d987b030) - make style wrong again.... (fa4e6cfbc1) - Bug 1254847 part 2. Change nsJSNPRuntime to always use AutoEntryScript and always take ownership of error reporting. r=bholley (d24cb80622) - Bug 1251655 - Remove support for JavaScript-global-constructor-prototype-alias. r=bz. (2b354ea423) - Bug 1251655 - Remove support for JavaScript-DOM-class and JavaScript-DOM-interface. r=bz. (dd6786ea57) - Bug 1251275. Switch to using an AutoEntryScript in WorkerPrivate::RunExpiredTimeouts. r=khuey (f10d1b0dec) - Bug 1072144 part 1. Just release-assert that Promise::Resolve does not fail in service worker code. It can only do that on OOM or overrecursion anyway, and overrecursion is not likely if we're coming right off a runnable. r=khuey (ba4c89a3bc) - Bug 1072144 part 2. When UnregisterWorker tries to ScheduleWorker and that throws, just suppress the exception: there is no good place to report it anyway. r=khuey (ca563ec5cd) - Bug 1072144 part 3. Hoist the exception reporting out of WorkerRunnable::PostRun into WorkerRunnable::Run and make it unconditional. r=khuey (9914acd4a6) - Bug 1252221. When GetOrCreateGlobalScope fails while trying to run a ScriptExecutorRunnable::WorkerRun, just suppress the exception, because there is no way to report it without a compartment to work with. r=khuey (abcc9df148) - Bug 1072144 part 4. Add a WorkerRunnable::PreRun so that we can move worker global creation to it and always have an AutoEntryScript by the time we're evaluating the main worker script. r=khuey (007b528868) - Bug 1251276 part 1. Change WorkerPrivate::CancelAllTimeouts to no longer call RunExpiredTimeouts. r=khuey (6b937370a1) - Bug 1251276 part 2. Remove the JSContext argument of WorkerPrivate::CancelAllTimeouts. r=khuey (336b788e03) - Bug 1251380. Change things so that WorkerPrivate::NotifyInternal (hopefully) never throws. r=khuey (1d4863f83a) - Bug 1254846. Add an AutoEntryScript constructor that takes a JSObject instead of an nsIGlobalObject, for convenience. r=bholley (693857f9b0) - Bug 1255706 part 1. Remove JSContext argument from WorkerPrivate constructor. r=khuey (0486bdb01c) - Bug 1255706 part 2. Remove JSContext argument from WorkerPrivate::Terminate. r=khuey (f0b62de092) - Bug 1257568. Remove the JSContext argument of WorkerPrivate::Kill. r=khuey (ebe7d247b5) - Bug 1252189. Remove the unnecessary JSContext argument from WorkerPrivate::FreezeInternal/ThawInternal. r=khuey (22b137b05e) - Bug 1119490 - Expose the URL constructor to WorkerDebuggerGlobalScope;r=khuey (6f4fc13e1e) - Bug 1241841 - Clear the worker's debugger event queue before destroying its context;r=khuey (a1e8dd4b2d) - Bug 1249950 - Add Performance Markers for MessagePort - patch 1 - remove non-useful 'explicit', r=smaug (8a014b53e6) - Bug 1249950 - Add Performance Markers for MessagePort - patch 2, r=smaug, r=vporof (560caf0ae1) - bug 1250486 - make the ComponentsSH ctor constexpr r=bz (1c441dbb0f) - Bug 1257032: Make files in dom/workers actually build without unification. r=baku (6ab4ae0b65) - Bug 1241522 - handle OOM in nsExpatDriver::HandleCharacterData; r=hsivonen (b652220cdc) - Bug 1219482: Replace PRLogModuleInfo with LazyLogModule in various files.r=benjamin (5fd5e8dbc8) - Bug 1238545 - Remove nsISimpleUnicharStreamFactory; r=froydnj (f0018c5b16) - Bug 1257335. Replace some AutoSafeJSContext uses with AutoJSAPI or AutoJSContext uses. r=bholley (7baf79deb7) - Bug 1247635 - Unify PostMessageRunnable and DispatchEventRunnable in MessagePort.cpp, r=smaug (df2765c215) - Bug 1250572 - Force a parent object in MessagePort/Channel and in StructuredCloneHolder, r=smaug (2a929d59d1) - Bug 1255375 - MessagePort should not leak if DispatchMessage() fails, r=smaug (0a5cdebfb0) - Bug 1251272. Remove the dead code in ReportErrorRunnable::ReportError that could fail, and make it infallible. r=khuey (89e80694d0) - Bug 1072144 part 5. Stop fiddling with compartments on the JSContext before calling PostRun in WorkerRunnable::Run. Add some documentation explaining what's going on. r=khuey (91f4bb6a7c) - Bug 1072144 part 6. Switch WorkerRunnable::Run to calling TakeOwnershipOfErrorReporting on its AutoJSAPI/AutoEntryScript and remove the remaining JS_ReportPendingException callers in worker code. r=khuey (405d9e0282) - Bug 1179548 - Close the windows opened in private browsing worker tests; r=baku (acf3430b69) - Bug 1179753 - Use pushPrefEnv more in worker tests; r=baku (4bfd949c72) - Bug 1134224 - More test for test_bug1132395.html, r=ehsan (626eb100cd) - Bug 1134224 - onerror for test_bug1132395.html, r=ehsan (147195f57e) - Bug 1207635 - get rid of dom.workers.sharedWorkers.enabled pref, r=khuey (22fe2965c6) - Bug 1252592. JS warnings should not trigger error events on shared workers. r=khuey (7f05c2c00d) - Bug 1251308; r=luke (3cbec95738) - Bug 1246838 - Handle const qualifiers and references better in Variant. r=waldo (30da6e3ebf) - Bug 1254565 - Allow passing matchers as rvalues to Variant::match. r=froydnj (1dd799fb0a) - Bug 1246841 - Allow construction of Variant values using type inference. r=waldo (6ba3e6704c) - Bug 1250666 - Forward Variant's move constructor argument correctly to the underlying variant type. r=waldo (7353a53bf0) - Bug 1252185. Remove the dead "target" variable from CloseEventRunnable::WorkerRun. r=khuey (be172da10b) - Bug 1253059: Use fallible allocation in the worker error reporter. r=baku (963222bdd4) - Bug 1253199 - MessagePort should handle the dispatching a message when the parent window is gone, r=smaug (d552e3cd9e) - Bug 1252839 - Remove some if stmt after allocation with 'new' - patch 2, r=bz (3c7eb959bc) - Bug 1252839 - Remove some if stmt after allocation with 'new' - patch 1, r=bz (85067dbfb6) - Bug 1254855. Switch AutoEntryScripts in nsDirectoryViewer to take ownership of error reporting. r=bholley (8c10532323) - Bug 1252565 part 1. Push the script environment preparer bits up from XPCJSRuntime to CycleCollectedJSRuntime, because we need them on workers to do ctypes on workers properly. r=bholley (aecf2595dd) - Bug 1252565 part 2. Make dom::WarningOnlyErrorReporter handle workers. r=bholley (f415b8868b) - Bug 1244222 - Check for function interfaces in DelegatedQueryInterface. r=bz (d213eec83c) - Bug 1254393. Take ownership of error reporting on the AutoEntryScript in nsXPCWrappedJSClass::CallMethod. r=bholley (4765b501c0) - Bug 1251769 - Remove remaining references to MOZILLA_XPCOMRT_API from mfbt. r=froydnj (236adc1d4c) - Bug 1247835 (part 0) - Minor comment and style tweaks in BinarySearch.h. r=luke. (db04793721) - Bug 1244074 - Part 1: Move SheetParsingMode to a separate file. r=dholbert (290adaadea) - Bug 1244074 - Part 2: Add HandleRefPtr for refcounting StyleSheetHandles. r=dholbert r=waldo (8549b24392) - Bug 1244068 - Part 1: Add enum to represent the style system backend type. r=dholbert (c2e53feaf2) - Bug 1244068 - Part 2: Add skeleton ServoStyleSet and a StyleSetHandle smart pointer. r=dholbert (71a5c28629) - Bug 1244068 - Part 3: Factor out nsStyleSet getting in RestyleManager/ElementRestyler. r=dholbert (9e9f4f2e80) - Bug 1245406: In ReflowBlockFrame, use Maybe<> to destroy & reconstruct a stack-allocated object, instead of an explicit call to destructor & placement 'new'. r=dbaron (d36858b818) - Bug 1244068 - Part 4: Use StyleSetHandle instead of concrete style set class in most places. r=dholbert (93f9bcf799) - Bug 1244074 - Part 3: Add skeleton ServoStyleSheet and a StyleSheetHandle smart pointer. r=dholbert (5b4fbdce38) - Bug 1195173 - Apply CSP to preloaded styles within layout/style/Loader.cpp (r=bz) (d1ba920fd3) - Bug 1245681 - Fix addOverrideStyleSheet. r=bz (64099eac73) - Bug 1244074 - Part 4: Use StyleSheetHandle instead of concrete style sheet class in most places. r=dholberti (867470ac83) - Bug 1246013 (part 1) - Store a copy of the ETLDEntry directly in DomainEntry instead of a pointer to it. r=jduell. (587b3a9fb7) - Bug 1246013 (part 2) - Change "explicit/xpcom/effective-TLD-service" path to the more sensible "explicit/network/effective-TLD-service". r=jduell. (2e0df6f28f) - Bug 1247835 (part 1) - Use binary search instead of a hash table in nsEffectiveTLDService. r=jduell. (685dae01c0) - Bug 1257121 part 1 - Use struct for passing some params of font metrics. r=jfkthame (1dfd7a7429) - Bug 1257121 part 2 - Merge nsFontMetrics::Init to the constructor and remove unused failure handling code. r=jfkthame (0cdc441511) - Bug 1257121 part 3 - Add GetInflatedFontMetricsForFrame function to simplify a common use pattern. r=jfkthame (d9630ebd1b) - Bug 1257121 part 4 - Use return value rather than out param to retur font metrics. r=jfkthame (c9a5b1d1dd) - Bug 1257121 part 5 - Make nsDeviceContext::mFontCache a RefPtr. r=jfkthame (9c53238a6a)
950 lines
33 KiB
C++
950 lines
33 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 "nsRangeFrame.h"
|
|
|
|
#include "mozilla/EventStates.h"
|
|
#include "mozilla/TouchEvents.h"
|
|
|
|
#include "nsContentCreatorFunctions.h"
|
|
#include "nsContentList.h"
|
|
#include "nsContentUtils.h"
|
|
#include "nsCSSPseudoElements.h"
|
|
#include "nsCSSRendering.h"
|
|
#include "nsFormControlFrame.h"
|
|
#include "nsIContent.h"
|
|
#include "nsIDocument.h"
|
|
#include "nsNameSpaceManager.h"
|
|
#include "nsIPresShell.h"
|
|
#include "nsGkAtoms.h"
|
|
#include "mozilla/dom/HTMLInputElement.h"
|
|
#include "nsPresContext.h"
|
|
#include "nsNodeInfoManager.h"
|
|
#include "nsRenderingContext.h"
|
|
#include "mozilla/dom/Element.h"
|
|
#include "mozilla/StyleSetHandle.h"
|
|
#include "mozilla/StyleSetHandleInlines.h"
|
|
#include "nsThemeConstants.h"
|
|
|
|
#ifdef ACCESSIBILITY
|
|
#include "nsAccessibilityService.h"
|
|
#endif
|
|
|
|
#define LONG_SIDE_TO_SHORT_SIDE_RATIO 10
|
|
|
|
using namespace mozilla;
|
|
using namespace mozilla::dom;
|
|
using namespace mozilla::image;
|
|
|
|
NS_IMPL_ISUPPORTS(nsRangeFrame::DummyTouchListener, nsIDOMEventListener)
|
|
|
|
nsIFrame*
|
|
NS_NewRangeFrame(nsIPresShell* aPresShell, nsStyleContext* aContext)
|
|
{
|
|
return new (aPresShell) nsRangeFrame(aContext);
|
|
}
|
|
|
|
nsRangeFrame::nsRangeFrame(nsStyleContext* aContext)
|
|
: nsContainerFrame(aContext)
|
|
{
|
|
}
|
|
|
|
nsRangeFrame::~nsRangeFrame()
|
|
{
|
|
#ifdef DEBUG
|
|
if (mOuterFocusStyle) {
|
|
mOuterFocusStyle->FrameRelease();
|
|
}
|
|
#endif
|
|
}
|
|
|
|
NS_IMPL_FRAMEARENA_HELPERS(nsRangeFrame)
|
|
|
|
NS_QUERYFRAME_HEAD(nsRangeFrame)
|
|
NS_QUERYFRAME_ENTRY(nsRangeFrame)
|
|
NS_QUERYFRAME_ENTRY(nsIAnonymousContentCreator)
|
|
NS_QUERYFRAME_TAIL_INHERITING(nsContainerFrame)
|
|
|
|
void
|
|
nsRangeFrame::Init(nsIContent* aContent,
|
|
nsContainerFrame* aParent,
|
|
nsIFrame* aPrevInFlow)
|
|
{
|
|
// With APZ enabled, touch events may be handled directly by the APZC code
|
|
// if the APZ knows that there is no content interested in the touch event.
|
|
// The range input element *is* interested in touch events, but doesn't use
|
|
// the usual mechanism (i.e. registering an event listener) to handle touch
|
|
// input. Instead, we do it here so that the APZ finds out about it, and
|
|
// makes sure to wait for content to run handlers before handling the touch
|
|
// input itself.
|
|
if (!mDummyTouchListener) {
|
|
mDummyTouchListener = new DummyTouchListener();
|
|
}
|
|
aContent->AddEventListener(NS_LITERAL_STRING("touchstart"), mDummyTouchListener, false);
|
|
|
|
StyleSetHandle styleSet = PresContext()->StyleSet();
|
|
|
|
mOuterFocusStyle =
|
|
styleSet->ProbePseudoElementStyle(aContent->AsElement(),
|
|
CSSPseudoElementType::mozFocusOuter,
|
|
StyleContext());
|
|
|
|
return nsContainerFrame::Init(aContent, aParent, aPrevInFlow);
|
|
}
|
|
|
|
void
|
|
nsRangeFrame::DestroyFrom(nsIFrame* aDestructRoot)
|
|
{
|
|
NS_ASSERTION(!GetPrevContinuation() && !GetNextContinuation(),
|
|
"nsRangeFrame should not have continuations; if it does we "
|
|
"need to call RegUnregAccessKey only for the first.");
|
|
|
|
mContent->RemoveEventListener(NS_LITERAL_STRING("touchstart"), mDummyTouchListener, false);
|
|
|
|
nsFormControlFrame::RegUnRegAccessKey(static_cast<nsIFrame*>(this), false);
|
|
nsContentUtils::DestroyAnonymousContent(&mTrackDiv);
|
|
nsContentUtils::DestroyAnonymousContent(&mProgressDiv);
|
|
nsContentUtils::DestroyAnonymousContent(&mThumbDiv);
|
|
nsContainerFrame::DestroyFrom(aDestructRoot);
|
|
}
|
|
|
|
nsresult
|
|
nsRangeFrame::MakeAnonymousDiv(Element** aResult,
|
|
CSSPseudoElementType aPseudoType,
|
|
nsTArray<ContentInfo>& aElements)
|
|
{
|
|
nsCOMPtr<nsIDocument> doc = mContent->GetComposedDoc();
|
|
RefPtr<Element> resultElement = doc->CreateHTMLElement(nsGkAtoms::div);
|
|
|
|
// Associate the pseudo-element with the anonymous child.
|
|
RefPtr<nsStyleContext> newStyleContext =
|
|
PresContext()->StyleSet()->ResolvePseudoElementStyle(mContent->AsElement(),
|
|
aPseudoType,
|
|
StyleContext(),
|
|
resultElement);
|
|
|
|
if (!aElements.AppendElement(ContentInfo(resultElement, newStyleContext))) {
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
|
}
|
|
|
|
resultElement.forget(aResult);
|
|
return NS_OK;
|
|
}
|
|
|
|
nsresult
|
|
nsRangeFrame::CreateAnonymousContent(nsTArray<ContentInfo>& aElements)
|
|
{
|
|
nsresult rv;
|
|
|
|
// Create the ::-moz-range-track pseuto-element (a div):
|
|
rv = MakeAnonymousDiv(getter_AddRefs(mTrackDiv),
|
|
CSSPseudoElementType::mozRangeTrack,
|
|
aElements);
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
// Create the ::-moz-range-progress pseudo-element (a div):
|
|
rv = MakeAnonymousDiv(getter_AddRefs(mProgressDiv),
|
|
CSSPseudoElementType::mozRangeProgress,
|
|
aElements);
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
// Create the ::-moz-range-thumb pseudo-element (a div):
|
|
rv = MakeAnonymousDiv(getter_AddRefs(mThumbDiv),
|
|
CSSPseudoElementType::mozRangeThumb,
|
|
aElements);
|
|
return rv;
|
|
}
|
|
|
|
void
|
|
nsRangeFrame::AppendAnonymousContentTo(nsTArray<nsIContent*>& aElements,
|
|
uint32_t aFilter)
|
|
{
|
|
if (mTrackDiv) {
|
|
aElements.AppendElement(mTrackDiv);
|
|
}
|
|
|
|
if (mProgressDiv) {
|
|
aElements.AppendElement(mProgressDiv);
|
|
}
|
|
|
|
if (mThumbDiv) {
|
|
aElements.AppendElement(mThumbDiv);
|
|
}
|
|
}
|
|
|
|
class nsDisplayRangeFocusRing : public nsDisplayItem
|
|
{
|
|
public:
|
|
nsDisplayRangeFocusRing(nsDisplayListBuilder* aBuilder, nsIFrame* aFrame)
|
|
: nsDisplayItem(aBuilder, aFrame) {
|
|
MOZ_COUNT_CTOR(nsDisplayRangeFocusRing);
|
|
}
|
|
#ifdef NS_BUILD_REFCNT_LOGGING
|
|
virtual ~nsDisplayRangeFocusRing() {
|
|
MOZ_COUNT_DTOR(nsDisplayRangeFocusRing);
|
|
}
|
|
#endif
|
|
|
|
nsDisplayItemGeometry* AllocateGeometry(nsDisplayListBuilder* aBuilder) override;
|
|
void ComputeInvalidationRegion(nsDisplayListBuilder* aBuilder,
|
|
const nsDisplayItemGeometry* aGeometry,
|
|
nsRegion *aInvalidRegion) override;
|
|
virtual nsRect GetBounds(nsDisplayListBuilder* aBuilder, bool* aSnap) override;
|
|
virtual void Paint(nsDisplayListBuilder* aBuilder, nsRenderingContext* aCtx) override;
|
|
NS_DISPLAY_DECL_NAME("RangeFocusRing", TYPE_RANGE_FOCUS_RING)
|
|
};
|
|
|
|
nsDisplayItemGeometry*
|
|
nsDisplayRangeFocusRing::AllocateGeometry(nsDisplayListBuilder* aBuilder)
|
|
{
|
|
return new nsDisplayItemGenericImageGeometry(this, aBuilder);
|
|
}
|
|
|
|
void
|
|
nsDisplayRangeFocusRing::ComputeInvalidationRegion(
|
|
nsDisplayListBuilder* aBuilder,
|
|
const nsDisplayItemGeometry* aGeometry,
|
|
nsRegion* aInvalidRegion)
|
|
{
|
|
auto geometry =
|
|
static_cast<const nsDisplayItemGenericImageGeometry*>(aGeometry);
|
|
|
|
if (aBuilder->ShouldSyncDecodeImages() &&
|
|
geometry->ShouldInvalidateToSyncDecodeImages()) {
|
|
bool snap;
|
|
aInvalidRegion->Or(*aInvalidRegion, GetBounds(aBuilder, &snap));
|
|
}
|
|
|
|
nsDisplayItem::ComputeInvalidationRegion(aBuilder, aGeometry, aInvalidRegion);
|
|
}
|
|
|
|
nsRect
|
|
nsDisplayRangeFocusRing::GetBounds(nsDisplayListBuilder* aBuilder, bool* aSnap)
|
|
{
|
|
*aSnap = false;
|
|
nsRect rect(ToReferenceFrame(), Frame()->GetSize());
|
|
|
|
// We want to paint as if specifying a border for ::-moz-focus-outer
|
|
// specifies an outline for our frame, so inflate by the border widths:
|
|
nsStyleContext* styleContext =
|
|
static_cast<nsRangeFrame*>(mFrame)->mOuterFocusStyle;
|
|
MOZ_ASSERT(styleContext, "We only exist if mOuterFocusStyle is non-null");
|
|
rect.Inflate(styleContext->StyleBorder()->GetComputedBorder());
|
|
|
|
return rect;
|
|
}
|
|
|
|
void
|
|
nsDisplayRangeFocusRing::Paint(nsDisplayListBuilder* aBuilder,
|
|
nsRenderingContext* aCtx)
|
|
{
|
|
bool unused;
|
|
nsStyleContext* styleContext =
|
|
static_cast<nsRangeFrame*>(mFrame)->mOuterFocusStyle;
|
|
MOZ_ASSERT(styleContext, "We only exist if mOuterFocusStyle is non-null");
|
|
|
|
PaintBorderFlags flags = aBuilder->ShouldSyncDecodeImages()
|
|
? PaintBorderFlags::SYNC_DECODE_IMAGES
|
|
: PaintBorderFlags();
|
|
|
|
DrawResult result =
|
|
nsCSSRendering::PaintBorder(mFrame->PresContext(), *aCtx, mFrame,
|
|
mVisibleRect, GetBounds(aBuilder, &unused),
|
|
styleContext, flags);
|
|
|
|
nsDisplayItemGenericImageGeometry::UpdateDrawResult(this, result);
|
|
}
|
|
|
|
void
|
|
nsRangeFrame::BuildDisplayList(nsDisplayListBuilder* aBuilder,
|
|
const nsRect& aDirtyRect,
|
|
const nsDisplayListSet& aLists)
|
|
{
|
|
if (IsThemed()) {
|
|
DisplayBorderBackgroundOutline(aBuilder, aLists);
|
|
// Only create items for the thumb. Specifically, we do not want
|
|
// the track to paint, since *our* background is used to paint
|
|
// the track, and we don't want the unthemed track painting over
|
|
// the top of the themed track.
|
|
// This logic is copied from
|
|
// nsContainerFrame::BuildDisplayListForNonBlockChildren as
|
|
// called by BuildDisplayListForInline.
|
|
nsIFrame* thumb = mThumbDiv->GetPrimaryFrame();
|
|
if (thumb) {
|
|
nsDisplayListSet set(aLists, aLists.Content());
|
|
BuildDisplayListForChild(aBuilder, thumb, aDirtyRect, set, DISPLAY_CHILD_INLINE);
|
|
}
|
|
} else {
|
|
BuildDisplayListForInline(aBuilder, aDirtyRect, aLists);
|
|
}
|
|
|
|
// Draw a focus outline if appropriate:
|
|
|
|
if (!aBuilder->IsForPainting() ||
|
|
!IsVisibleForPainting(aBuilder)) {
|
|
// we don't want the focus ring item for hit-testing or if the item isn't
|
|
// in the area being [re]painted
|
|
return;
|
|
}
|
|
|
|
EventStates eventStates = mContent->AsElement()->State();
|
|
if (eventStates.HasState(NS_EVENT_STATE_DISABLED) ||
|
|
!eventStates.HasState(NS_EVENT_STATE_FOCUSRING)) {
|
|
return; // can't have focus or doesn't match :-moz-focusring
|
|
}
|
|
|
|
if (!mOuterFocusStyle ||
|
|
!mOuterFocusStyle->StyleBorder()->HasBorder()) {
|
|
// no ::-moz-focus-outer specified border (how style specifies a focus ring
|
|
// for range)
|
|
return;
|
|
}
|
|
|
|
const nsStyleDisplay *disp = StyleDisplay();
|
|
if (IsThemed(disp) &&
|
|
PresContext()->GetTheme()->ThemeDrawsFocusForWidget(disp->mAppearance)) {
|
|
return; // the native theme displays its own visual indication of focus
|
|
}
|
|
|
|
aLists.Content()->AppendNewToTop(
|
|
new (aBuilder) nsDisplayRangeFocusRing(aBuilder, this));
|
|
}
|
|
|
|
void
|
|
nsRangeFrame::Reflow(nsPresContext* aPresContext,
|
|
nsHTMLReflowMetrics& aDesiredSize,
|
|
const nsHTMLReflowState& aReflowState,
|
|
nsReflowStatus& aStatus)
|
|
{
|
|
MarkInReflow();
|
|
DO_GLOBAL_REFLOW_COUNT("nsRangeFrame");
|
|
DISPLAY_REFLOW(aPresContext, this, aReflowState, aDesiredSize, aStatus);
|
|
|
|
NS_ASSERTION(mTrackDiv, "::-moz-range-track div must exist!");
|
|
NS_ASSERTION(mProgressDiv, "::-moz-range-progress div must exist!");
|
|
NS_ASSERTION(mThumbDiv, "::-moz-range-thumb div must exist!");
|
|
NS_ASSERTION(!GetPrevContinuation() && !GetNextContinuation(),
|
|
"nsRangeFrame should not have continuations; if it does we "
|
|
"need to call RegUnregAccessKey only for the first.");
|
|
|
|
if (mState & NS_FRAME_FIRST_REFLOW) {
|
|
nsFormControlFrame::RegUnRegAccessKey(this, true);
|
|
}
|
|
|
|
WritingMode wm = aReflowState.GetWritingMode();
|
|
nscoord computedBSize = aReflowState.ComputedBSize();
|
|
if (computedBSize == NS_AUTOHEIGHT) {
|
|
computedBSize = 0;
|
|
}
|
|
LogicalSize
|
|
finalSize(wm,
|
|
aReflowState.ComputedISize() +
|
|
aReflowState.ComputedLogicalBorderPadding().IStartEnd(wm),
|
|
computedBSize +
|
|
aReflowState.ComputedLogicalBorderPadding().BStartEnd(wm));
|
|
aDesiredSize.SetSize(wm, finalSize);
|
|
|
|
ReflowAnonymousContent(aPresContext, aDesiredSize, aReflowState);
|
|
|
|
aDesiredSize.SetOverflowAreasToDesiredBounds();
|
|
|
|
nsIFrame* trackFrame = mTrackDiv->GetPrimaryFrame();
|
|
if (trackFrame) {
|
|
ConsiderChildOverflow(aDesiredSize.mOverflowAreas, trackFrame);
|
|
}
|
|
|
|
nsIFrame* rangeProgressFrame = mProgressDiv->GetPrimaryFrame();
|
|
if (rangeProgressFrame) {
|
|
ConsiderChildOverflow(aDesiredSize.mOverflowAreas, rangeProgressFrame);
|
|
}
|
|
|
|
nsIFrame* thumbFrame = mThumbDiv->GetPrimaryFrame();
|
|
if (thumbFrame) {
|
|
ConsiderChildOverflow(aDesiredSize.mOverflowAreas, thumbFrame);
|
|
}
|
|
|
|
FinishAndStoreOverflow(&aDesiredSize);
|
|
|
|
aStatus = NS_FRAME_COMPLETE;
|
|
|
|
NS_FRAME_SET_TRUNCATION(aStatus, aReflowState, aDesiredSize);
|
|
}
|
|
|
|
void
|
|
nsRangeFrame::ReflowAnonymousContent(nsPresContext* aPresContext,
|
|
nsHTMLReflowMetrics& aDesiredSize,
|
|
const nsHTMLReflowState& aReflowState)
|
|
{
|
|
// The width/height of our content box, which is the available width/height
|
|
// for our anonymous content:
|
|
nscoord rangeFrameContentBoxWidth = aReflowState.ComputedWidth();
|
|
nscoord rangeFrameContentBoxHeight = aReflowState.ComputedHeight();
|
|
if (rangeFrameContentBoxHeight == NS_AUTOHEIGHT) {
|
|
rangeFrameContentBoxHeight = 0;
|
|
}
|
|
|
|
nsIFrame* trackFrame = mTrackDiv->GetPrimaryFrame();
|
|
|
|
if (trackFrame) { // display:none?
|
|
|
|
// Position the track:
|
|
// The idea here is that we allow content authors to style the width,
|
|
// height, border and padding of the track, but we ignore margin and
|
|
// positioning properties and do the positioning ourself to keep the center
|
|
// of the track's border box on the center of the nsRangeFrame's content
|
|
// box.
|
|
|
|
WritingMode wm = trackFrame->GetWritingMode();
|
|
LogicalSize availSize = aReflowState.ComputedSize(wm);
|
|
availSize.BSize(wm) = NS_UNCONSTRAINEDSIZE;
|
|
nsHTMLReflowState trackReflowState(aPresContext, aReflowState,
|
|
trackFrame, availSize);
|
|
|
|
// Find the x/y position of the track frame such that it will be positioned
|
|
// as described above. These coordinates are with respect to the
|
|
// nsRangeFrame's border-box.
|
|
nscoord trackX = rangeFrameContentBoxWidth / 2;
|
|
nscoord trackY = rangeFrameContentBoxHeight / 2;
|
|
|
|
// Account for the track's border and padding (we ignore its margin):
|
|
trackX -= trackReflowState.ComputedPhysicalBorderPadding().left +
|
|
trackReflowState.ComputedWidth() / 2;
|
|
trackY -= trackReflowState.ComputedPhysicalBorderPadding().top +
|
|
trackReflowState.ComputedHeight() / 2;
|
|
|
|
// Make relative to our border box instead of our content box:
|
|
trackX += aReflowState.ComputedPhysicalBorderPadding().left;
|
|
trackY += aReflowState.ComputedPhysicalBorderPadding().top;
|
|
|
|
nsReflowStatus frameStatus;
|
|
nsHTMLReflowMetrics trackDesiredSize(aReflowState);
|
|
ReflowChild(trackFrame, aPresContext, trackDesiredSize,
|
|
trackReflowState, trackX, trackY, 0, frameStatus);
|
|
MOZ_ASSERT(NS_FRAME_IS_FULLY_COMPLETE(frameStatus),
|
|
"We gave our child unconstrained height, so it should be complete");
|
|
FinishReflowChild(trackFrame, aPresContext, trackDesiredSize,
|
|
&trackReflowState, trackX, trackY, 0);
|
|
}
|
|
|
|
nsIFrame* thumbFrame = mThumbDiv->GetPrimaryFrame();
|
|
|
|
if (thumbFrame) { // display:none?
|
|
WritingMode wm = thumbFrame->GetWritingMode();
|
|
LogicalSize availSize = aReflowState.ComputedSize(wm);
|
|
availSize.BSize(wm) = NS_UNCONSTRAINEDSIZE;
|
|
nsHTMLReflowState thumbReflowState(aPresContext, aReflowState,
|
|
thumbFrame, availSize);
|
|
|
|
// Where we position the thumb depends on its size, so we first reflow
|
|
// the thumb at {0,0} to obtain its size, then position it afterwards.
|
|
|
|
nsReflowStatus frameStatus;
|
|
nsHTMLReflowMetrics thumbDesiredSize(aReflowState);
|
|
ReflowChild(thumbFrame, aPresContext, thumbDesiredSize,
|
|
thumbReflowState, 0, 0, 0, frameStatus);
|
|
MOZ_ASSERT(NS_FRAME_IS_FULLY_COMPLETE(frameStatus),
|
|
"We gave our child unconstrained height, so it should be complete");
|
|
FinishReflowChild(thumbFrame, aPresContext, thumbDesiredSize,
|
|
&thumbReflowState, 0, 0, 0);
|
|
DoUpdateThumbPosition(thumbFrame, nsSize(aDesiredSize.Width(),
|
|
aDesiredSize.Height()));
|
|
}
|
|
|
|
nsIFrame* rangeProgressFrame = mProgressDiv->GetPrimaryFrame();
|
|
|
|
if (rangeProgressFrame) { // display:none?
|
|
WritingMode wm = rangeProgressFrame->GetWritingMode();
|
|
LogicalSize availSize = aReflowState.ComputedSize(wm);
|
|
availSize.BSize(wm) = NS_UNCONSTRAINEDSIZE;
|
|
nsHTMLReflowState progressReflowState(aPresContext, aReflowState,
|
|
rangeProgressFrame, availSize);
|
|
|
|
// We first reflow the range-progress frame at {0,0} to obtain its
|
|
// unadjusted dimensions, then we adjust it to so that the appropriate edge
|
|
// ends at the thumb.
|
|
|
|
nsReflowStatus frameStatus;
|
|
nsHTMLReflowMetrics progressDesiredSize(aReflowState);
|
|
ReflowChild(rangeProgressFrame, aPresContext,
|
|
progressDesiredSize, progressReflowState, 0, 0,
|
|
0, frameStatus);
|
|
MOZ_ASSERT(NS_FRAME_IS_FULLY_COMPLETE(frameStatus),
|
|
"We gave our child unconstrained height, so it should be complete");
|
|
FinishReflowChild(rangeProgressFrame, aPresContext,
|
|
progressDesiredSize, &progressReflowState, 0, 0, 0);
|
|
DoUpdateRangeProgressFrame(rangeProgressFrame, nsSize(aDesiredSize.Width(),
|
|
aDesiredSize.Height()));
|
|
}
|
|
}
|
|
|
|
#ifdef ACCESSIBILITY
|
|
a11y::AccType
|
|
nsRangeFrame::AccessibleType()
|
|
{
|
|
return a11y::eHTMLRangeType;
|
|
}
|
|
#endif
|
|
|
|
double
|
|
nsRangeFrame::GetValueAsFractionOfRange()
|
|
{
|
|
MOZ_ASSERT(mContent->IsHTMLElement(nsGkAtoms::input), "bad cast");
|
|
dom::HTMLInputElement* input = static_cast<dom::HTMLInputElement*>(mContent);
|
|
|
|
MOZ_ASSERT(input->GetType() == NS_FORM_INPUT_RANGE);
|
|
|
|
Decimal value = input->GetValueAsDecimal();
|
|
Decimal minimum = input->GetMinimum();
|
|
Decimal maximum = input->GetMaximum();
|
|
|
|
MOZ_ASSERT(value.isFinite() && minimum.isFinite() && maximum.isFinite(),
|
|
"type=range should have a default maximum/minimum");
|
|
|
|
if (maximum <= minimum) {
|
|
MOZ_ASSERT(value == minimum, "Unsanitized value");
|
|
return 0.0;
|
|
}
|
|
|
|
MOZ_ASSERT(value >= minimum && value <= maximum, "Unsanitized value");
|
|
|
|
return ((value - minimum) / (maximum - minimum)).toDouble();
|
|
}
|
|
|
|
Decimal
|
|
nsRangeFrame::GetValueAtEventPoint(WidgetGUIEvent* aEvent)
|
|
{
|
|
MOZ_ASSERT(aEvent->mClass == eMouseEventClass ||
|
|
aEvent->mClass == eTouchEventClass,
|
|
"Unexpected event type - aEvent->refPoint may be meaningless");
|
|
|
|
MOZ_ASSERT(mContent->IsHTMLElement(nsGkAtoms::input), "bad cast");
|
|
dom::HTMLInputElement* input = static_cast<dom::HTMLInputElement*>(mContent);
|
|
|
|
MOZ_ASSERT(input->GetType() == NS_FORM_INPUT_RANGE);
|
|
|
|
Decimal minimum = input->GetMinimum();
|
|
Decimal maximum = input->GetMaximum();
|
|
MOZ_ASSERT(minimum.isFinite() && maximum.isFinite(),
|
|
"type=range should have a default maximum/minimum");
|
|
if (maximum <= minimum) {
|
|
return minimum;
|
|
}
|
|
Decimal range = maximum - minimum;
|
|
|
|
LayoutDeviceIntPoint absPoint;
|
|
if (aEvent->mClass == eTouchEventClass) {
|
|
MOZ_ASSERT(aEvent->AsTouchEvent()->touches.Length() == 1,
|
|
"Unexpected number of touches");
|
|
absPoint = aEvent->AsTouchEvent()->touches[0]->mRefPoint;
|
|
} else {
|
|
absPoint = aEvent->refPoint;
|
|
}
|
|
nsPoint point =
|
|
nsLayoutUtils::GetEventCoordinatesRelativeTo(aEvent, absPoint, this);
|
|
|
|
if (point == nsPoint(NS_UNCONSTRAINEDSIZE, NS_UNCONSTRAINEDSIZE)) {
|
|
// We don't want to change the current value for this error state.
|
|
return static_cast<dom::HTMLInputElement*>(mContent)->GetValueAsDecimal();
|
|
}
|
|
|
|
nsRect rangeContentRect = GetContentRectRelativeToSelf();
|
|
nsSize thumbSize;
|
|
|
|
if (IsThemed()) {
|
|
// We need to get the size of the thumb from the theme.
|
|
nsPresContext *presContext = PresContext();
|
|
bool notUsedCanOverride;
|
|
LayoutDeviceIntSize size;
|
|
presContext->GetTheme()->
|
|
GetMinimumWidgetSize(presContext, this, NS_THEME_RANGE_THUMB, &size,
|
|
¬UsedCanOverride);
|
|
thumbSize.width = presContext->DevPixelsToAppUnits(size.width);
|
|
thumbSize.height = presContext->DevPixelsToAppUnits(size.height);
|
|
MOZ_ASSERT(thumbSize.width > 0 && thumbSize.height > 0);
|
|
} else {
|
|
nsIFrame* thumbFrame = mThumbDiv->GetPrimaryFrame();
|
|
if (thumbFrame) { // diplay:none?
|
|
thumbSize = thumbFrame->GetSize();
|
|
}
|
|
}
|
|
|
|
Decimal fraction;
|
|
if (IsHorizontal()) {
|
|
nscoord traversableDistance = rangeContentRect.width - thumbSize.width;
|
|
if (traversableDistance <= 0) {
|
|
return minimum;
|
|
}
|
|
nscoord posAtStart = rangeContentRect.x + thumbSize.width/2;
|
|
nscoord posAtEnd = posAtStart + traversableDistance;
|
|
nscoord posOfPoint = mozilla::clamped(point.x, posAtStart, posAtEnd);
|
|
fraction = Decimal(posOfPoint - posAtStart) / Decimal(traversableDistance);
|
|
if (IsRightToLeft()) {
|
|
fraction = Decimal(1) - fraction;
|
|
}
|
|
} else {
|
|
nscoord traversableDistance = rangeContentRect.height - thumbSize.height;
|
|
if (traversableDistance <= 0) {
|
|
return minimum;
|
|
}
|
|
nscoord posAtStart = rangeContentRect.y + thumbSize.height/2;
|
|
nscoord posAtEnd = posAtStart + traversableDistance;
|
|
nscoord posOfPoint = mozilla::clamped(point.y, posAtStart, posAtEnd);
|
|
// For a vertical range, the top (posAtStart) is the highest value, so we
|
|
// subtract the fraction from 1.0 to get that polarity correct.
|
|
fraction = Decimal(1) - Decimal(posOfPoint - posAtStart) / Decimal(traversableDistance);
|
|
}
|
|
|
|
MOZ_ASSERT(fraction >= Decimal(0) && fraction <= Decimal(1));
|
|
return minimum + fraction * range;
|
|
}
|
|
|
|
void
|
|
nsRangeFrame::UpdateForValueChange()
|
|
{
|
|
if (NS_SUBTREE_DIRTY(this)) {
|
|
return; // we're going to be updated when we reflow
|
|
}
|
|
nsIFrame* rangeProgressFrame = mProgressDiv->GetPrimaryFrame();
|
|
nsIFrame* thumbFrame = mThumbDiv->GetPrimaryFrame();
|
|
if (!rangeProgressFrame && !thumbFrame) {
|
|
return; // diplay:none?
|
|
}
|
|
if (rangeProgressFrame) {
|
|
DoUpdateRangeProgressFrame(rangeProgressFrame, GetSize());
|
|
}
|
|
if (thumbFrame) {
|
|
DoUpdateThumbPosition(thumbFrame, GetSize());
|
|
}
|
|
if (IsThemed()) {
|
|
// We don't know the exact dimensions or location of the thumb when native
|
|
// theming is applied, so we just repaint the entire range.
|
|
InvalidateFrame();
|
|
}
|
|
|
|
#ifdef ACCESSIBILITY
|
|
nsAccessibilityService* accService = nsIPresShell::AccService();
|
|
if (accService) {
|
|
accService->RangeValueChanged(PresContext()->PresShell(), mContent);
|
|
}
|
|
#endif
|
|
|
|
SchedulePaint();
|
|
}
|
|
|
|
void
|
|
nsRangeFrame::DoUpdateThumbPosition(nsIFrame* aThumbFrame,
|
|
const nsSize& aRangeSize)
|
|
{
|
|
MOZ_ASSERT(aThumbFrame);
|
|
|
|
// The idea here is that we want to position the thumb so that the center
|
|
// of the thumb is on an imaginary line drawn from the middle of one edge
|
|
// of the range frame's content box to the middle of the opposite edge of
|
|
// its content box (the opposite edges being the left/right edge if the
|
|
// range is horizontal, or else the top/bottom edges if the range is
|
|
// vertical). How far along this line the center of the thumb is placed
|
|
// depends on the value of the range.
|
|
|
|
nsMargin borderAndPadding = GetUsedBorderAndPadding();
|
|
nsPoint newPosition(borderAndPadding.left, borderAndPadding.top);
|
|
|
|
nsSize rangeContentBoxSize(aRangeSize);
|
|
rangeContentBoxSize.width -= borderAndPadding.LeftRight();
|
|
rangeContentBoxSize.height -= borderAndPadding.TopBottom();
|
|
|
|
nsSize thumbSize = aThumbFrame->GetSize();
|
|
double fraction = GetValueAsFractionOfRange();
|
|
MOZ_ASSERT(fraction >= 0.0 && fraction <= 1.0);
|
|
|
|
if (IsHorizontal()) {
|
|
if (thumbSize.width < rangeContentBoxSize.width) {
|
|
nscoord traversableDistance =
|
|
rangeContentBoxSize.width - thumbSize.width;
|
|
if (IsRightToLeft()) {
|
|
newPosition.x += NSToCoordRound((1.0 - fraction) * traversableDistance);
|
|
} else {
|
|
newPosition.x += NSToCoordRound(fraction * traversableDistance);
|
|
}
|
|
newPosition.y += (rangeContentBoxSize.height - thumbSize.height)/2;
|
|
}
|
|
} else {
|
|
if (thumbSize.height < rangeContentBoxSize.height) {
|
|
nscoord traversableDistance =
|
|
rangeContentBoxSize.height - thumbSize.height;
|
|
newPosition.x += (rangeContentBoxSize.width - thumbSize.width)/2;
|
|
newPosition.y += NSToCoordRound((1.0 - fraction) * traversableDistance);
|
|
}
|
|
}
|
|
aThumbFrame->SetPosition(newPosition);
|
|
}
|
|
|
|
void
|
|
nsRangeFrame::DoUpdateRangeProgressFrame(nsIFrame* aRangeProgressFrame,
|
|
const nsSize& aRangeSize)
|
|
{
|
|
MOZ_ASSERT(aRangeProgressFrame);
|
|
|
|
// The idea here is that we want to position the ::-moz-range-progress
|
|
// pseudo-element so that the center line running along its length is on the
|
|
// corresponding center line of the nsRangeFrame's content box. In the other
|
|
// dimension, we align the "start" edge of the ::-moz-range-progress
|
|
// pseudo-element's border-box with the corresponding edge of the
|
|
// nsRangeFrame's content box, and we size the progress element's border-box
|
|
// to have a length of GetValueAsFractionOfRange() times the nsRangeFrame's
|
|
// content-box size.
|
|
|
|
nsMargin borderAndPadding = GetUsedBorderAndPadding();
|
|
nsSize progSize = aRangeProgressFrame->GetSize();
|
|
nsRect progRect(borderAndPadding.left, borderAndPadding.top,
|
|
progSize.width, progSize.height);
|
|
|
|
nsSize rangeContentBoxSize(aRangeSize);
|
|
rangeContentBoxSize.width -= borderAndPadding.LeftRight();
|
|
rangeContentBoxSize.height -= borderAndPadding.TopBottom();
|
|
|
|
double fraction = GetValueAsFractionOfRange();
|
|
MOZ_ASSERT(fraction >= 0.0 && fraction <= 1.0);
|
|
|
|
if (IsHorizontal()) {
|
|
nscoord progLength = NSToCoordRound(fraction * rangeContentBoxSize.width);
|
|
if (IsRightToLeft()) {
|
|
progRect.x += rangeContentBoxSize.width - progLength;
|
|
}
|
|
progRect.y += (rangeContentBoxSize.height - progSize.height)/2;
|
|
progRect.width = progLength;
|
|
} else {
|
|
nscoord progLength = NSToCoordRound(fraction * rangeContentBoxSize.height);
|
|
progRect.x += (rangeContentBoxSize.width - progSize.width)/2;
|
|
progRect.y += rangeContentBoxSize.height - progLength;
|
|
progRect.height = progLength;
|
|
}
|
|
aRangeProgressFrame->SetRect(progRect);
|
|
}
|
|
|
|
nsresult
|
|
nsRangeFrame::AttributeChanged(int32_t aNameSpaceID,
|
|
nsIAtom* aAttribute,
|
|
int32_t aModType)
|
|
{
|
|
NS_ASSERTION(mTrackDiv, "The track div must exist!");
|
|
NS_ASSERTION(mThumbDiv, "The thumb div must exist!");
|
|
|
|
if (aNameSpaceID == kNameSpaceID_None) {
|
|
if (aAttribute == nsGkAtoms::value ||
|
|
aAttribute == nsGkAtoms::min ||
|
|
aAttribute == nsGkAtoms::max ||
|
|
aAttribute == nsGkAtoms::step) {
|
|
// We want to update the position of the thumb, except in one special
|
|
// case: If the value attribute is being set, it is possible that we are
|
|
// in the middle of a type change away from type=range, under the
|
|
// SetAttr(..., nsGkAtoms::value, ...) call in HTMLInputElement::
|
|
// HandleTypeChange. In that case the HTMLInputElement's type will
|
|
// already have changed, and if we call UpdateForValueChange()
|
|
// we'll fail the asserts under that call that check the type of our
|
|
// HTMLInputElement. Given that we're changing away from being a range
|
|
// and this frame will shortly be destroyed, there's no point in calling
|
|
// UpdateForValueChange() anyway.
|
|
MOZ_ASSERT(mContent->IsHTMLElement(nsGkAtoms::input), "bad cast");
|
|
bool typeIsRange = static_cast<dom::HTMLInputElement*>(mContent)->GetType() ==
|
|
NS_FORM_INPUT_RANGE;
|
|
// If script changed the <input>'s type before setting these attributes
|
|
// then we don't need to do anything since we are going to be reframed.
|
|
if (typeIsRange) {
|
|
UpdateForValueChange();
|
|
}
|
|
} else if (aAttribute == nsGkAtoms::orient) {
|
|
PresContext()->PresShell()->FrameNeedsReflow(this, nsIPresShell::eResize,
|
|
NS_FRAME_IS_DIRTY);
|
|
}
|
|
}
|
|
|
|
return nsContainerFrame::AttributeChanged(aNameSpaceID, aAttribute, aModType);
|
|
}
|
|
|
|
LogicalSize
|
|
nsRangeFrame::ComputeAutoSize(nsRenderingContext *aRenderingContext,
|
|
WritingMode aWM,
|
|
const LogicalSize& aCBSize,
|
|
nscoord aAvailableISize,
|
|
const LogicalSize& aMargin,
|
|
const LogicalSize& aBorder,
|
|
const LogicalSize& aPadding,
|
|
bool aShrinkWrap)
|
|
{
|
|
nscoord oneEm = NSToCoordRound(StyleFont()->mFont.size *
|
|
nsLayoutUtils::FontSizeInflationFor(this)); // 1em
|
|
|
|
bool isInlineOriented = IsInlineOriented();
|
|
|
|
const WritingMode wm = GetWritingMode();
|
|
LogicalSize autoSize(wm);
|
|
|
|
// nsFrame::ComputeSize calls GetMinimumWidgetSize to prevent us from being
|
|
// given too small a size when we're natively themed. If we're themed, we set
|
|
// our "thickness" dimension to zero below and rely on that
|
|
// GetMinimumWidgetSize check to correct that dimension to the natural
|
|
// thickness of a slider in the current theme.
|
|
|
|
if (isInlineOriented) {
|
|
autoSize.ISize(wm) = LONG_SIDE_TO_SHORT_SIDE_RATIO * oneEm;
|
|
autoSize.BSize(wm) = IsThemed() ? 0 : oneEm;
|
|
} else {
|
|
autoSize.ISize(wm) = IsThemed() ? 0 : oneEm;
|
|
autoSize.BSize(wm) = LONG_SIDE_TO_SHORT_SIDE_RATIO * oneEm;
|
|
}
|
|
|
|
return autoSize.ConvertTo(aWM, wm);
|
|
}
|
|
|
|
nscoord
|
|
nsRangeFrame::GetMinISize(nsRenderingContext *aRenderingContext)
|
|
{
|
|
// nsFrame::ComputeSize calls GetMinimumWidgetSize to prevent us from being
|
|
// given too small a size when we're natively themed. If we aren't native
|
|
// themed, we don't mind how small we're sized.
|
|
return nscoord(0);
|
|
}
|
|
|
|
nscoord
|
|
nsRangeFrame::GetPrefISize(nsRenderingContext *aRenderingContext)
|
|
{
|
|
bool isInline = IsInlineOriented();
|
|
|
|
if (!isInline && IsThemed()) {
|
|
// nsFrame::ComputeSize calls GetMinimumWidgetSize to prevent us from being
|
|
// given too small a size when we're natively themed. We return zero and
|
|
// depend on that correction to get our "natural" width when we're a
|
|
// vertical slider.
|
|
return 0;
|
|
}
|
|
|
|
nscoord prefISize = NSToCoordRound(StyleFont()->mFont.size *
|
|
nsLayoutUtils::FontSizeInflationFor(this)); // 1em
|
|
|
|
if (isInline) {
|
|
prefISize *= LONG_SIDE_TO_SHORT_SIDE_RATIO;
|
|
}
|
|
|
|
return prefISize;
|
|
}
|
|
|
|
bool
|
|
nsRangeFrame::IsHorizontal() const
|
|
{
|
|
dom::HTMLInputElement* element =
|
|
static_cast<dom::HTMLInputElement*>(mContent);
|
|
return element->AttrValueIs(kNameSpaceID_None, nsGkAtoms::orient,
|
|
nsGkAtoms::horizontal, eCaseMatters) ||
|
|
(!element->AttrValueIs(kNameSpaceID_None, nsGkAtoms::orient,
|
|
nsGkAtoms::vertical, eCaseMatters) &&
|
|
GetWritingMode().IsVertical() ==
|
|
element->AttrValueIs(kNameSpaceID_None, nsGkAtoms::orient,
|
|
nsGkAtoms::block, eCaseMatters));
|
|
}
|
|
|
|
double
|
|
nsRangeFrame::GetMin() const
|
|
{
|
|
return static_cast<dom::HTMLInputElement*>(mContent)->GetMinimum().toDouble();
|
|
}
|
|
|
|
double
|
|
nsRangeFrame::GetMax() const
|
|
{
|
|
return static_cast<dom::HTMLInputElement*>(mContent)->GetMaximum().toDouble();
|
|
}
|
|
|
|
double
|
|
nsRangeFrame::GetValue() const
|
|
{
|
|
return static_cast<dom::HTMLInputElement*>(mContent)->GetValueAsDecimal().toDouble();
|
|
}
|
|
|
|
nsIAtom*
|
|
nsRangeFrame::GetType() const
|
|
{
|
|
return nsGkAtoms::rangeFrame;
|
|
}
|
|
|
|
#define STYLES_DISABLING_NATIVE_THEMING \
|
|
NS_AUTHOR_SPECIFIED_BACKGROUND | \
|
|
NS_AUTHOR_SPECIFIED_PADDING | \
|
|
NS_AUTHOR_SPECIFIED_BORDER
|
|
|
|
bool
|
|
nsRangeFrame::ShouldUseNativeStyle() const
|
|
{
|
|
nsIFrame* trackFrame = mTrackDiv->GetPrimaryFrame();
|
|
nsIFrame* progressFrame = mProgressDiv->GetPrimaryFrame();
|
|
nsIFrame* thumbFrame = mThumbDiv->GetPrimaryFrame();
|
|
|
|
return (StyleDisplay()->mAppearance == NS_THEME_RANGE) &&
|
|
!PresContext()->HasAuthorSpecifiedRules(this,
|
|
(NS_AUTHOR_SPECIFIED_BORDER |
|
|
NS_AUTHOR_SPECIFIED_BACKGROUND)) &&
|
|
trackFrame &&
|
|
!PresContext()->HasAuthorSpecifiedRules(trackFrame,
|
|
STYLES_DISABLING_NATIVE_THEMING) &&
|
|
progressFrame &&
|
|
!PresContext()->HasAuthorSpecifiedRules(progressFrame,
|
|
STYLES_DISABLING_NATIVE_THEMING) &&
|
|
thumbFrame &&
|
|
!PresContext()->HasAuthorSpecifiedRules(thumbFrame,
|
|
STYLES_DISABLING_NATIVE_THEMING);
|
|
}
|
|
|
|
Element*
|
|
nsRangeFrame::GetPseudoElement(CSSPseudoElementType aType)
|
|
{
|
|
if (aType == CSSPseudoElementType::mozRangeTrack) {
|
|
return mTrackDiv;
|
|
}
|
|
|
|
if (aType == CSSPseudoElementType::mozRangeThumb) {
|
|
return mThumbDiv;
|
|
}
|
|
|
|
if (aType == CSSPseudoElementType::mozRangeProgress) {
|
|
return mProgressDiv;
|
|
}
|
|
|
|
return nsContainerFrame::GetPseudoElement(aType);
|
|
}
|
|
|
|
nsStyleContext*
|
|
nsRangeFrame::GetAdditionalStyleContext(int32_t aIndex) const
|
|
{
|
|
// We only implement this so that SetAdditionalStyleContext will be
|
|
// called if style changes that would change the -moz-focus-outer
|
|
// pseudo-element have occurred.
|
|
if (aIndex != 0) {
|
|
return nullptr;
|
|
}
|
|
return mOuterFocusStyle;
|
|
}
|
|
|
|
void
|
|
nsRangeFrame::SetAdditionalStyleContext(int32_t aIndex,
|
|
nsStyleContext* aStyleContext)
|
|
{
|
|
MOZ_ASSERT(aIndex == 0,
|
|
"GetAdditionalStyleContext is handling other indexes?");
|
|
|
|
#ifdef DEBUG
|
|
if (mOuterFocusStyle) {
|
|
mOuterFocusStyle->FrameRelease();
|
|
}
|
|
#endif
|
|
|
|
// The -moz-focus-outer pseudo-element's style has changed.
|
|
mOuterFocusStyle = aStyleContext;
|
|
|
|
#ifdef DEBUG
|
|
if (mOuterFocusStyle) {
|
|
mOuterFocusStyle->FrameAddRef();
|
|
}
|
|
#endif
|
|
}
|