diff --git a/accessible/generic/Accessible.cpp b/accessible/generic/Accessible.cpp index dcc5be91fd..2a7c4cd0d2 100644 --- a/accessible/generic/Accessible.cpp +++ b/accessible/generic/Accessible.cpp @@ -432,9 +432,9 @@ Accessible::NativeState() // XXX we should look at layout for non XUL box frames, but need to decide // how that interacts with ARIA. - if (HasOwnContent() && mContent->IsXULElement() && frame->IsBoxFrame()) { + if (HasOwnContent() && mContent->IsXULElement() && frame->IsXULBoxFrame()) { const nsStyleXUL* xulStyle = frame->StyleXUL(); - if (xulStyle && frame->IsBoxFrame()) { + if (xulStyle && frame->IsXULBoxFrame()) { // In XUL all boxes are either vertical or horizontal if (xulStyle->mBoxOrient == NS_STYLE_BOX_ORIENT_VERTICAL) state |= states::VERTICAL; diff --git a/accessible/html/HTMLTableAccessible.cpp b/accessible/html/HTMLTableAccessible.cpp index 5a8de9ff0b..ce91cf2e90 100644 --- a/accessible/html/HTMLTableAccessible.cpp +++ b/accessible/html/HTMLTableAccessible.cpp @@ -1066,7 +1066,7 @@ HTMLTableAccessible::IsProbablyLayoutTable() RETURN_LAYOUT_ANSWER(false, "table's first cell has no frame!"); nsMargin border; - cellFrame->GetBorder(border); + cellFrame->GetXULBorder(border); if (border.top && border.bottom && border.left && border.right) { RETURN_LAYOUT_ANSWER(false, "Has nonzero border-width on table cell"); } diff --git a/dom/base/nsContentUtils.cpp b/dom/base/nsContentUtils.cpp index d91c81c3f3..1d5cc868ed 100644 --- a/dom/base/nsContentUtils.cpp +++ b/dom/base/nsContentUtils.cpp @@ -3142,7 +3142,8 @@ nsContentUtils::IsImageInCache(nsIURI* aURI, nsIDocument* aDocument) // static nsresult -nsContentUtils::LoadImage(nsIURI* aURI, nsIDocument* aLoadingDocument, +nsContentUtils::LoadImage(nsIURI* aURI, nsINode* aContext, + nsIDocument* aLoadingDocument, nsIPrincipal* aLoadingPrincipal, nsIURI* aReferrer, net::ReferrerPolicy aReferrerPolicy, imgINotificationObserver* aObserver, int32_t aLoadFlags, @@ -3151,6 +3152,7 @@ nsContentUtils::LoadImage(nsIURI* aURI, nsIDocument* aLoadingDocument, uint32_t aContentPolicyType) { NS_PRECONDITION(aURI, "Must have a URI"); + NS_PRECONDITION(aContext, "Must have a context"); NS_PRECONDITION(aLoadingDocument, "Must have a document"); NS_PRECONDITION(aLoadingPrincipal, "Must have a principal"); NS_PRECONDITION(aRequest, "Null out param"); @@ -3180,6 +3182,7 @@ nsContentUtils::LoadImage(nsIURI* aURI, nsIDocument* aLoadingDocument, aLoadingPrincipal, /* loading principal */ loadGroup, /* loadgroup */ aObserver, /* imgINotificationObserver */ + aContext, /* loading context */ aLoadingDocument, /* uniquification key */ aLoadFlags, /* load flags */ nullptr, /* cache key */ @@ -7636,6 +7639,8 @@ int16_t nsContentUtils::GetButtonsFlagForButton(int32_t aButton) { switch (aButton) { + case -1: + return WidgetMouseEvent::eNoButtonFlag; case WidgetMouseEvent::eLeftButton: return WidgetMouseEvent::eLeftButtonFlag; case WidgetMouseEvent::eMiddleButton: diff --git a/dom/base/nsContentUtils.h b/dom/base/nsContentUtils.h index f8d69e8ed5..9163947eee 100644 --- a/dom/base/nsContentUtils.h +++ b/dom/base/nsContentUtils.h @@ -662,6 +662,8 @@ public: * keep a mutable version around should pass in a clone. * * @param aURI uri of the image to be loaded + * @param aContext element of document where the result of this request + * will be used. * @param aLoadingDocument the document we belong to * @param aLoadingPrincipal the principal doing the load * @param aReferrer the referrer URI @@ -674,6 +676,7 @@ public: * @return the imgIRequest for the image load */ static nsresult LoadImage(nsIURI* aURI, + nsINode* aContext, nsIDocument* aLoadingDocument, nsIPrincipal* aLoadingPrincipal, nsIURI* aReferrer, diff --git a/dom/base/nsDocument.cpp b/dom/base/nsDocument.cpp index e7040a73c5..2d111cfffe 100644 --- a/dom/base/nsDocument.cpp +++ b/dom/base/nsDocument.cpp @@ -9794,6 +9794,7 @@ nsDocument::MaybePreLoadImage(nsIURI* uri, const nsAString &aCrossOriginAttr, RefPtr request; nsresult rv = nsContentUtils::LoadImage(uri, + static_cast(this), this, NodePrincipal(), mDocumentURI, // uri of document used as referrer diff --git a/dom/base/nsImageLoadingContent.cpp b/dom/base/nsImageLoadingContent.cpp index f7fec46ec6..6adb56b214 100644 --- a/dom/base/nsImageLoadingContent.cpp +++ b/dom/base/nsImageLoadingContent.cpp @@ -878,7 +878,11 @@ nsImageLoadingContent::LoadImage(nsIURI* aNewURI, // Not blocked. Do the load. RefPtr& req = PrepareNextRequest(aImageLoadType); nsIContent* content = AsContent(); - nsresult rv = nsContentUtils::LoadImage(aNewURI, aDocument, + nsCOMPtr thisNode = + do_QueryInterface(static_cast(this)); + nsresult rv = nsContentUtils::LoadImage(aNewURI, + thisNode, + aDocument, aDocument->NodePrincipal(), aDocument->GetDocumentURI(), referrerPolicy, diff --git a/dom/media/MediaDecoderStateMachine.cpp b/dom/media/MediaDecoderStateMachine.cpp index 34eba13745..3625cdf74c 100644 --- a/dom/media/MediaDecoderStateMachine.cpp +++ b/dom/media/MediaDecoderStateMachine.cpp @@ -42,6 +42,7 @@ #include "ImageContainer.h" #include "MediaDecoder.h" #include "MediaDecoderReader.h" +#include "MediaDecoderReaderWrapper.h" #include "MediaDecoderStateMachine.h" #include "MediaShutdownManager.h" #include "MediaTimer.h" @@ -219,6 +220,7 @@ MediaDecoderStateMachine::MediaDecoderStateMachine(MediaDecoder* aDecoder, mObservedDuration(TimeUnit(), "MediaDecoderStateMachine::mObservedDuration"), mFragmentEndTime(-1), mReader(aReader), + mReaderWrapper(new MediaDecoderReaderWrapper(aRealTime, mTaskQueue, aReader)), mDecodedAudioEndTime(0), mDecodedVideoEndTime(0), mPlaybackRate(1.0), @@ -332,8 +334,6 @@ MediaDecoderStateMachine::~MediaDecoderStateMachine() MOZ_ASSERT(NS_IsMainThread(), "Should be on main thread."); MOZ_COUNT_DTOR(MediaDecoderStateMachine); - mReader = nullptr; - #ifdef XP_WIN timeEndPeriod(1); #endif @@ -464,12 +464,13 @@ void MediaDecoderStateMachine::DiscardStreamData() } } -bool MediaDecoderStateMachine::HaveEnoughDecodedAudio(int64_t aAmpleAudioUSecs) +bool MediaDecoderStateMachine::HaveEnoughDecodedAudio() { MOZ_ASSERT(OnTaskQueue()); + int64_t ampleAudioUSecs = mAmpleAudioThresholdUsecs * mPlaybackRate; if (AudioQueue().GetSize() == 0 || - GetDecodedAudioDuration() < aAmpleAudioUSecs) { + GetDecodedAudioDuration() < ampleAudioUSecs) { return false; } @@ -566,14 +567,12 @@ MediaDecoderStateMachine::NeedToDecodeAudio() { MOZ_ASSERT(OnTaskQueue()); SAMPLE_LOG("NeedToDecodeAudio() isDec=%d minPrl=%d enufAud=%d", - IsAudioDecoding(), mMinimizePreroll, - HaveEnoughDecodedAudio(mAmpleAudioThresholdUsecs * mPlaybackRate)); + IsAudioDecoding(), mMinimizePreroll, HaveEnoughDecodedAudio()); return IsAudioDecoding() && mState != DECODER_STATE_SEEKING && ((IsDecodingFirstFrame() && AudioQueue().GetSize() == 0) || - (!mMinimizePreroll && - !HaveEnoughDecodedAudio(mAmpleAudioThresholdUsecs * mPlaybackRate))); + (!mMinimizePreroll && !HaveEnoughDecodedAudio())); } bool @@ -609,7 +608,6 @@ MediaDecoderStateMachine::OnAudioDecoded(MediaData* aAudioSample) RefPtr audio(aAudioSample); MOZ_ASSERT(audio); mAudioDataRequest.Complete(); - aAudioSample->AdjustForStartTime(StartTime()); // audio->GetEndTime() is not always mono-increasing in chained ogg. mDecodedAudioEndTime = std::max(audio->GetEndTime(), mDecodedAudioEndTime); @@ -707,22 +705,6 @@ MediaDecoderStateMachine::Push(MediaData* aSample, MediaData::Type aSampleType) DispatchDecodeTasksIfNeeded(); } -void -MediaDecoderStateMachine::PushFront(MediaData* aSample, MediaData::Type aSampleType) -{ - MOZ_ASSERT(OnTaskQueue()); - MOZ_ASSERT(aSample); - if (aSample->mType == MediaData::AUDIO_DATA) { - AudioQueue().PushFront(aSample); - } else if (aSample->mType == MediaData::VIDEO_DATA) { - aSample->As()->mFrameID = ++mCurrentFrameID; - VideoQueue().PushFront(aSample); - } else { - // TODO: Handle MediaRawData, determine which queue should be pushed. - } - UpdateNextFrameStatus(); -} - void MediaDecoderStateMachine::CheckIsAudible(const MediaData* aSample) { @@ -852,6 +834,11 @@ MediaDecoderStateMachine::OnNotDecoded(MediaData::Type aType, return; } CheckIfDecodeComplete(); + + // Schedule next cycle to see if we can leave buffering state. + if (mState == DECODER_STATE_BUFFERING) { + ScheduleStateMachine(); + } return; } case DECODER_STATE_SEEKING: { @@ -890,20 +877,19 @@ MediaDecoderStateMachine::MaybeFinishDecodeFirstFrame() } // We can now complete the pending seek. - mPendingSeek.Steal(mQueuedSeek); SetState(DECODER_STATE_SEEKING); - ScheduleStateMachine(); + InitiateSeek(Move(mQueuedSeek)); return true; } void -MediaDecoderStateMachine::OnVideoDecoded(MediaData* aVideoSample) +MediaDecoderStateMachine::OnVideoDecoded(MediaData* aVideoSample, + TimeStamp aDecodeStartTime) { MOZ_ASSERT(OnTaskQueue()); RefPtr video(aVideoSample); MOZ_ASSERT(video); mVideoDataRequest.Complete(); - aVideoSample->AdjustForStartTime(StartTime()); // Handle abnormal or negative timestamps. mDecodedVideoEndTime = std::max(mDecodedVideoEndTime, video->GetEndTime()); @@ -939,7 +925,7 @@ MediaDecoderStateMachine::OnVideoDecoded(MediaData* aVideoSample) if (mReader->IsAsync()) { return; } - TimeDuration decodeTime = TimeStamp::Now() - mVideoDecodeStartTime; + TimeDuration decodeTime = TimeStamp::Now() - aDecodeStartTime; if (!IsDecodingFirstFrame() && THRESHOLD_FACTOR * DurationToUsecs(decodeTime) > mLowAudioThresholdUsecs && !HasLowUndecodedData()) @@ -977,10 +963,8 @@ MediaDecoderStateMachine::OnVideoDecoded(MediaData* aVideoSample) // in this case, we'll just decode forward. Bug 1026330. mCurrentSeek.mTarget.SetType(SeekTarget::Accurate); } - if (mCurrentSeek.mTarget.IsFast() || - mPendingSeek.Exists()) { - // Non-precise seek; or a pending seek exists ; we can stop the seek - // at the first sample. + if (mCurrentSeek.mTarget.IsFast()) { + // Non-precise seek. We can stop the seek at the first sample. Push(video, MediaData::VIDEO_DATA); } else { // We're doing an accurate seek. We still need to discard @@ -1274,10 +1258,6 @@ MediaDecoderStateMachine::SetDormant(bool aDormant) return; } - if (!mReader) { - return; - } - if (mMetadataRequest.Exists()) { if (mPendingDormant && mPendingDormant.ref() != aDormant && !aDormant) { // We already have a dormant request pending; the new request would have @@ -1296,10 +1276,8 @@ MediaDecoderStateMachine::SetDormant(bool aDormant) if (mState == DECODER_STATE_SEEKING) { if (mQueuedSeek.Exists()) { // Keep latest seek target - } else if (mPendingSeek.Exists()) { - mQueuedSeek.Steal(mPendingSeek); } else if (mCurrentSeek.Exists()) { - mQueuedSeek.Steal(mCurrentSeek); + mQueuedSeek = Move(mCurrentSeek); } else { mQueuedSeek.mTarget = SeekTarget(mCurrentPosition, SeekTarget::Accurate, @@ -1316,7 +1294,6 @@ MediaDecoderStateMachine::SetDormant(bool aDormant) // back to MediaDecoder when we come out of dormant? RefPtr unused = mQueuedSeek.mPromise.Ensure(__func__); } - mPendingSeek.RejectIfExists(__func__); mCurrentSeek.RejectIfExists(__func__); SetState(DECODER_STATE_DORMANT); if (IsPlaying()) { @@ -1354,7 +1331,6 @@ MediaDecoderStateMachine::Shutdown() mBufferedUpdateRequest.DisconnectIfExists(); mQueuedSeek.RejectIfExists(__func__); - mPendingSeek.RejectIfExists(__func__); mCurrentSeek.RejectIfExists(__func__); #ifdef MOZ_EME @@ -1368,11 +1344,7 @@ MediaDecoderStateMachine::Shutdown() Reset(); mMediaSink->Shutdown(); - - // Shut down our start time rendezvous. - if (mStartTimeRendezvous) { - mStartTimeRendezvous->Destroy(); - } + mReaderWrapper->Shutdown(); DECODER_LOG("Shutdown started"); @@ -1408,9 +1380,8 @@ void MediaDecoderStateMachine::StartDecoding() "Return from dormant must have queued seek"); } if (mQueuedSeek.Exists()) { - mPendingSeek.Steal(mQueuedSeek); SetState(DECODER_STATE_SEEKING); - ScheduleStateMachine(); + InitiateSeek(Move(mQueuedSeek)); return; } } @@ -1510,8 +1481,7 @@ MediaDecoderStateMachine::ReadMetadata() DECODER_LOG("Dispatching AsyncReadMetadata"); // Set mode to METADATA since we are about to read metadata. mResource->SetReadMode(MediaCacheStream::MODE_METADATA); - mMetadataRequest.Begin(InvokeAsync(DecodeTaskQueue(), mReader.get(), __func__, - &MediaDecoderReader::AsyncReadMetadata) + mMetadataRequest.Begin(mReaderWrapper->ReadMetadata() ->Then(OwnerThread(), __func__, this, &MediaDecoderStateMachine::OnMetadataRead, &MediaDecoderStateMachine::OnMetadataNotRead)); @@ -1544,14 +1514,14 @@ MediaDecoderStateMachine::Seek(SeekTarget aTarget) return mQueuedSeek.mPromise.Ensure(__func__); } mQueuedSeek.RejectIfExists(__func__); - mPendingSeek.RejectIfExists(__func__); - mPendingSeek.mTarget = aTarget; - DECODER_LOG("Changed state to SEEKING (to %lld)", mPendingSeek.mTarget.GetTime().ToMicroseconds()); + DECODER_LOG("Changed state to SEEKING (to %lld)", aTarget.GetTime().ToMicroseconds()); SetState(DECODER_STATE_SEEKING); - ScheduleStateMachine(); - return mPendingSeek.mPromise.Ensure(__func__); + SeekJob seekJob; + seekJob.mTarget = aTarget; + InitiateSeek(Move(seekJob)); + return mCurrentSeek.mPromise.Ensure(__func__); } RefPtr @@ -1631,12 +1601,12 @@ MediaDecoderStateMachine::DispatchDecodeTasksIfNeeded() } void -MediaDecoderStateMachine::InitiateSeek() +MediaDecoderStateMachine::InitiateSeek(SeekJob aSeekJob) { MOZ_ASSERT(OnTaskQueue()); mCurrentSeek.RejectIfExists(__func__); - mCurrentSeek.Steal(mPendingSeek); + mCurrentSeek = Move(aSeekJob); // Bound the seek time to be inside the media range. int64_t end = Duration().ToMicroseconds(); @@ -1665,11 +1635,8 @@ MediaDecoderStateMachine::InitiateSeek() // Do the seek. RefPtr self = this; - SeekTarget seekTarget = mCurrentSeek.mTarget; - seekTarget.SetTime(seekTarget.GetTime() + media::TimeUnit::FromMicroseconds(StartTime())); - mSeekRequest.Begin(InvokeAsync(DecodeTaskQueue(), mReader.get(), __func__, - &MediaDecoderReader::Seek, seekTarget, - Duration().ToMicroseconds()) + mSeekRequest.Begin( + mReaderWrapper->Seek(mCurrentSeek.mTarget, Duration()) ->Then(OwnerThread(), __func__, [self] (media::TimeUnit) -> void { self->mSeekRequest.Complete(); @@ -1731,25 +1698,11 @@ MediaDecoderStateMachine::RequestAudioData() SAMPLE_LOG("Queueing audio task - queued=%i, decoder-queued=%o", AudioQueue().GetSize(), mReader->SizeOfAudioQueueInFrames()); - if (mSentFirstFrameLoadedEvent) { - mAudioDataRequest.Begin(InvokeAsync(DecodeTaskQueue(), mReader.get(), - __func__, &MediaDecoderReader::RequestAudioData) - ->Then(OwnerThread(), __func__, this, - &MediaDecoderStateMachine::OnAudioDecoded, - &MediaDecoderStateMachine::OnAudioNotDecoded)); - } else { - mAudioDataRequest.Begin( - InvokeAsync(DecodeTaskQueue(), mReader.get(), __func__, - &MediaDecoderReader::RequestAudioData) - ->Then(OwnerThread(), __func__, mStartTimeRendezvous.get(), - &StartTimeRendezvous::ProcessFirstSample, - &StartTimeRendezvous::FirstSampleRejected) - ->CompletionPromise() - ->Then(OwnerThread(), __func__, this, - &MediaDecoderStateMachine::OnAudioDecoded, - &MediaDecoderStateMachine::OnAudioNotDecoded) - ); - } + mAudioDataRequest.Begin( + mReaderWrapper->RequestAudioData() + ->Then(OwnerThread(), __func__, this, + &MediaDecoderStateMachine::OnAudioDecoded, + &MediaDecoderStateMachine::OnAudioNotDecoded)); } nsresult @@ -1799,40 +1752,28 @@ MediaDecoderStateMachine::RequestVideoData() // Time the video decode, so that if it's slow, we can increase our low // audio threshold to reduce the chance of an audio underrun while we're // waiting for a video decode to complete. - mVideoDecodeStartTime = TimeStamp::Now(); + TimeStamp videoDecodeStartTime = TimeStamp::Now(); bool skipToNextKeyFrame = mSentFirstFrameLoadedEvent && NeedToSkipToNextKeyframe(); - int64_t currentTime = - mState == DECODER_STATE_SEEKING || !mSentFirstFrameLoadedEvent - ? 0 : GetMediaTime() + StartTime(); + media::TimeUnit currentTime = media::TimeUnit::FromMicroseconds( + mState == DECODER_STATE_SEEKING ? 0 : GetMediaTime()); SAMPLE_LOG("Queueing video task - queued=%i, decoder-queued=%o, skip=%i, time=%lld", VideoQueue().GetSize(), mReader->SizeOfVideoQueueInFrames(), skipToNextKeyFrame, - currentTime); + currentTime.ToMicroseconds()); - if (mSentFirstFrameLoadedEvent) { - mVideoDataRequest.Begin( - InvokeAsync(DecodeTaskQueue(), mReader.get(), __func__, - &MediaDecoderReader::RequestVideoData, - skipToNextKeyFrame, currentTime) - ->Then(OwnerThread(), __func__, this, - &MediaDecoderStateMachine::OnVideoDecoded, - &MediaDecoderStateMachine::OnVideoNotDecoded)); - } else { - mVideoDataRequest.Begin( - InvokeAsync(DecodeTaskQueue(), mReader.get(), __func__, - &MediaDecoderReader::RequestVideoData, - skipToNextKeyFrame, currentTime) - ->Then(OwnerThread(), __func__, mStartTimeRendezvous.get(), - &StartTimeRendezvous::ProcessFirstSample, - &StartTimeRendezvous::FirstSampleRejected) - ->CompletionPromise() - ->Then(OwnerThread(), __func__, this, - &MediaDecoderStateMachine::OnVideoDecoded, - &MediaDecoderStateMachine::OnVideoNotDecoded)); - } + RefPtr self = this; + mVideoDataRequest.Begin( + mReaderWrapper->RequestVideoData(skipToNextKeyFrame, currentTime) + ->Then(OwnerThread(), __func__, + [self, videoDecodeStartTime] (MediaData* aVideoSample) { + self->OnVideoDecoded(aVideoSample, videoDecodeStartTime); + }, + [self] (MediaDecoderReader::NotDecodedReason aReason) { + self->OnVideoNotDecoded(aReason); + })); } void @@ -1974,29 +1915,14 @@ MediaDecoderStateMachine::OnMetadataRead(MetadataHolder* aMetadata) mMetadataTags = aMetadata->mTags.forget(); RefPtr self = this; - // Set up the start time rendezvous if it doesn't already exist (which is - // generally the case, unless we're coming out of dormant mode). - if (!mStartTimeRendezvous) { - mStartTimeRendezvous = new StartTimeRendezvous(OwnerThread(), HasAudio(), HasVideo(), - mReader->ForceZeroStartTime() || IsRealTime()); - - mStartTimeRendezvous->AwaitStartTime()->Then(OwnerThread(), __func__, - [self] () -> void { - NS_ENSURE_TRUE_VOID(!self->IsShutdown()); - self->mReader->DispatchSetStartTime(self->StartTime()); - }, - [] () -> void { NS_WARNING("Setting start time on reader failed"); } - ); - } - if (mInfo.mMetadataDuration.isSome()) { RecomputeDuration(); } else if (mInfo.mUnadjustedMetadataEndTime.isSome()) { - mStartTimeRendezvous->AwaitStartTime()->Then(OwnerThread(), __func__, + mReaderWrapper->AwaitStartTime()->Then(OwnerThread(), __func__, [self] () -> void { NS_ENSURE_TRUE_VOID(!self->IsShutdown()); TimeUnit unadjusted = self->mInfo.mUnadjustedMetadataEndTime.ref(); - TimeUnit adjustment = TimeUnit::FromMicroseconds(self->StartTime()); + TimeUnit adjustment = self->mReaderWrapper->StartTime(); self->mInfo.mMetadataDuration.emplace(unadjusted - adjustment); self->RecomputeDuration(); }, [] () -> void { NS_WARNING("Adjusting metadata end time failed"); } @@ -2157,34 +2083,36 @@ MediaDecoderStateMachine::SeekCompleted() newCurrentTime = video ? video->mTime : seekTime; } - if (mDecodingFirstFrame) { - // We were resuming from dormant, or initiated a seek early. - // We can fire loadeddata now. - FinishDecodeFirstFrame(); - } - - // Change state to DECODING or COMPLETED now. SeekingStopped will - // call MediaDecoderStateMachine::Seek to reset our state to SEEKING - // if we need to seek again. - + // Change state to DECODING or COMPLETED now. bool isLiveStream = mResource->IsLiveStream(); - if (mPendingSeek.Exists()) { - // A new seek target came in while we were processing the old one. No rest - // for the seeking. - DECODER_LOG("A new seek came along while we were finishing the old one - staying in SEEKING"); - SetState(DECODER_STATE_SEEKING); - } else if (GetMediaTime() == Duration().ToMicroseconds() && !isLiveStream) { + State nextState; + if (GetMediaTime() == Duration().ToMicroseconds() && !isLiveStream) { // Seeked to end of media, move to COMPLETED state. Note we don't do // this when playing a live stream, since the end of media will advance // once we download more data! DECODER_LOG("Changed state from SEEKING (to %lld) to COMPLETED", seekTime); // Explicitly set our state so we don't decode further, and so // we report playback ended to the media element. - SetState(DECODER_STATE_COMPLETED); - DispatchDecodeTasksIfNeeded(); + nextState = DECODER_STATE_COMPLETED; } else { DECODER_LOG("Changed state from SEEKING (to %lld) to DECODING", seekTime); + nextState = DECODER_STATE_DECODING; + } + + // We want to resolve the seek request prior finishing the first frame + // to ensure that the seeked event is fired prior loadeded. + mCurrentSeek.Resolve(nextState == DECODER_STATE_COMPLETED, __func__); + + if (mDecodingFirstFrame) { + // We were resuming from dormant, or initiated a seek early. + // We can fire loadeddata now. + FinishDecodeFirstFrame(); + } + + if (nextState == DECODER_STATE_DECODING) { StartDecoding(); + } else { + SetState(nextState); } // Ensure timestamps are up to date. @@ -2198,7 +2126,6 @@ MediaDecoderStateMachine::SeekCompleted() // if we need to buffer after the seek. mQuickBuffering = false; - mCurrentSeek.Resolve(mState == DECODER_STATE_COMPLETED, __func__); ScheduleStateMachine(); if (video) { @@ -2347,9 +2274,6 @@ nsresult MediaDecoderStateMachine::RunStateMachine() } case DECODER_STATE_SEEKING: { - if (mPendingSeek.Exists()) { - InitiateSeek(); - } return NS_OK; } @@ -2531,7 +2455,8 @@ MediaDecoderStateMachine::DropVideoUpToSeekTarget(MediaData* aSample) DECODER_LOG("DropVideoUpToSeekTarget() found video frame [%lld, %lld] containing target=%lld", video->mTime, video->GetEndTime(), target); - PushFront(video, MediaData::VIDEO_DATA); + MOZ_ASSERT(VideoQueue().GetSize() == 0, "Should be the 1st sample after seeking"); + Push(video, MediaData::VIDEO_DATA); } return NS_OK; @@ -2607,7 +2532,8 @@ MediaDecoderStateMachine::DropAudioUpToSeekTarget(MediaData* aSample) Move(audioData), channels, audio->mRate)); - PushFront(data, MediaData::AUDIO_DATA); + MOZ_ASSERT(AudioQueue().GetSize() == 0, "Should be the 1st sample after seeking"); + Push(data, MediaData::AUDIO_DATA); return NS_OK; } diff --git a/dom/media/MediaDecoderStateMachine.h b/dom/media/MediaDecoderStateMachine.h index 989b209779..235ab2246e 100644 --- a/dom/media/MediaDecoderStateMachine.h +++ b/dom/media/MediaDecoderStateMachine.h @@ -104,6 +104,7 @@ class MediaSink; class AudioSegment; class DecodedStream; +class MediaDecoderReaderWrapper; class OutputStreamManager; class TaskQueue; @@ -210,12 +211,10 @@ public: OwnerThread()->Dispatch(r.forget()); } - // Drop reference to mReader and mResource. Only called during shutdown dance. + // Drop reference to mResource. Only called during shutdown dance. void BreakCycles() { MOZ_ASSERT(NS_IsMainThread()); - if (mReader) { - mReader->BreakCycles(); - } + mReader->BreakCycles(); mResource = nullptr; } @@ -246,17 +245,11 @@ public: bool IsRealTime() const { return mRealTime; } size_t SizeOfVideoQueue() { - if (mReader) { - return mReader->SizeOfVideoQueueInBytes(); - } - return 0; + return mReader->SizeOfVideoQueueInBytes(); } size_t SizeOfAudioQueue() { - if (mReader) { - return mReader->SizeOfAudioQueueInBytes(); - } - return 0; + return mReader->SizeOfAudioQueueInBytes(); } private: @@ -348,7 +341,7 @@ private: // Discard audio/video data that are already played by MSG. void DiscardStreamData(); - bool HaveEnoughDecodedAudio(int64_t aAmpleAudioUSecs); + bool HaveEnoughDecodedAudio(); bool HaveEnoughDecodedVideo(); // Returns true if the state machine has shutdown or is in the process of @@ -362,7 +355,7 @@ private: // TODO: Those callback function may receive demuxed-only data. // Need to figure out a suitable API name for this case. void OnAudioDecoded(MediaData* aAudioSample); - void OnVideoDecoded(MediaData* aVideoSample); + void OnVideoDecoded(MediaData* aVideoSample, TimeStamp aDecodeStartTime); void OnNotDecoded(MediaData::Type aType, MediaDecoderReader::NotDecodedReason aReason); void OnAudioNotDecoded(MediaDecoderReader::NotDecodedReason aReason) { @@ -390,7 +383,6 @@ protected: // aSample must not be null. void Push(MediaData* aSample, MediaData::Type aSampleType); - void PushFront(MediaData* aSample, MediaData::Type aSampleType); void OnAudioPopped(const RefPtr& aSample); void OnVideoPopped(const RefPtr& aSample); @@ -528,9 +520,56 @@ protected: void EnqueueFirstFrameLoadedEvent(); + struct SeekJob { + SeekJob() {} + + SeekJob(SeekJob&& aOther) : mTarget(aOther.mTarget) + { + aOther.mTarget.Reset(); + mPromise = Move(aOther.mPromise); + } + + SeekJob& operator=(SeekJob&& aOther) + { + MOZ_DIAGNOSTIC_ASSERT(!Exists()); + mTarget = aOther.mTarget; + aOther.mTarget.Reset(); + mPromise = Move(aOther.mPromise); + return *this; + } + + bool Exists() + { + MOZ_ASSERT(mTarget.IsValid() == !mPromise.IsEmpty()); + return mTarget.IsValid(); + } + + void Resolve(bool aAtEnd, const char* aCallSite) + { + mTarget.Reset(); + MediaDecoder::SeekResolveValue val(aAtEnd, mTarget.mEventVisibility); + mPromise.Resolve(val, aCallSite); + } + + void RejectIfExists(const char* aCallSite) + { + mTarget.Reset(); + mPromise.RejectIfExists(true, aCallSite); + } + + ~SeekJob() + { + MOZ_DIAGNOSTIC_ASSERT(!mTarget.IsValid()); + MOZ_DIAGNOSTIC_ASSERT(mPromise.IsEmpty()); + } + + SeekTarget mTarget; + MozPromiseHolder mPromise; + }; + // Clears any previous seeking state and initiates a new see on the decoder. // The decoder monitor must be held. - void InitiateSeek(); + void InitiateSeek(SeekJob aSeekJob); nsresult DispatchAudioDecodeTaskIfNeeded(); @@ -662,138 +701,6 @@ private: // Used to dispatch another round schedule with specific target time. DelayedScheduler mDelayedScheduler; - // StartTimeRendezvous is a helper class that quarantines the first sample - // until it gets a sample from both channels, such that we can be guaranteed - // to know the start time by the time On{Audio,Video}Decoded is called. - class StartTimeRendezvous { - public: - typedef MediaDecoderReader::AudioDataPromise AudioDataPromise; - typedef MediaDecoderReader::VideoDataPromise VideoDataPromise; - typedef MozPromise HaveStartTimePromise; - - NS_INLINE_DECL_THREADSAFE_REFCOUNTING(StartTimeRendezvous); - StartTimeRendezvous(AbstractThread* aOwnerThread, bool aHasAudio, bool aHasVideo, - bool aForceZeroStartTime) - : mOwnerThread(aOwnerThread) - { - if (aForceZeroStartTime) { - mAudioStartTime.emplace(0); - mVideoStartTime.emplace(0); - return; - } - - if (!aHasAudio) { - mAudioStartTime.emplace(INT64_MAX); - } - - if (!aHasVideo) { - mVideoStartTime.emplace(INT64_MAX); - } - } - - void Destroy() - { - mAudioStartTime = Some(mAudioStartTime.refOr(INT64_MAX)); - mVideoStartTime = Some(mVideoStartTime.refOr(INT64_MAX)); - mHaveStartTimePromise.RejectIfExists(false, __func__); - } - - RefPtr AwaitStartTime() - { - if (HaveStartTime()) { - return HaveStartTimePromise::CreateAndResolve(true, __func__); - } - return mHaveStartTimePromise.Ensure(__func__); - } - - template - struct PromiseSampleType { - typedef typename PromiseType::ResolveValueType::element_type Type; - }; - - template - RefPtr ProcessFirstSample(typename PromiseSampleType::Type* aData) - { - typedef typename PromiseSampleType::Type DataType; - typedef typename PromiseType::Private PromisePrivate; - MOZ_ASSERT(mOwnerThread->IsCurrentThreadIn()); - - MaybeSetChannelStartTime(aData->mTime); - - RefPtr p = new PromisePrivate(__func__); - RefPtr data = aData; - RefPtr self = this; - AwaitStartTime()->Then(mOwnerThread, __func__, - [p, data, self] () -> void { - MOZ_ASSERT(self->mOwnerThread->IsCurrentThreadIn()); - p->Resolve(data, __func__); - }, - [p] () -> void { p->Reject(MediaDecoderReader::CANCELED, __func__); }); - - return p.forget(); - } - - template - void FirstSampleRejected(MediaDecoderReader::NotDecodedReason aReason) - { - MOZ_ASSERT(mOwnerThread->IsCurrentThreadIn()); - if (aReason == MediaDecoderReader::DECODE_ERROR) { - mHaveStartTimePromise.RejectIfExists(false, __func__); - } else if (aReason == MediaDecoderReader::END_OF_STREAM) { - MOZ_LOG(gMediaDecoderLog, LogLevel::Debug, - ("StartTimeRendezvous=%p SampleType(%d) Has no samples.", this, SampleType)); - MaybeSetChannelStartTime(INT64_MAX); - } - } - - bool HaveStartTime() { return mAudioStartTime.isSome() && mVideoStartTime.isSome(); } - int64_t StartTime() - { - int64_t time = std::min(mAudioStartTime.ref(), mVideoStartTime.ref()); - return time == INT64_MAX ? 0 : time; - } - private: - virtual ~StartTimeRendezvous() {} - - template - void MaybeSetChannelStartTime(int64_t aStartTime) - { - if (ChannelStartTime(SampleType).isSome()) { - // If we're initialized with aForceZeroStartTime=true, the channel start - // times are already set. - return; - } - - MOZ_LOG(gMediaDecoderLog, LogLevel::Debug, - ("StartTimeRendezvous=%p Setting SampleType(%d) start time to %lld", - this, SampleType, aStartTime)); - - ChannelStartTime(SampleType).emplace(aStartTime); - if (HaveStartTime()) { - mHaveStartTimePromise.ResolveIfExists(true, __func__); - } - } - - Maybe& ChannelStartTime(MediaData::Type aType) - { - return aType == MediaData::AUDIO_DATA ? mAudioStartTime : mVideoStartTime; - } - - MozPromiseHolder mHaveStartTimePromise; - RefPtr mOwnerThread; - Maybe mAudioStartTime; - Maybe mVideoStartTime; - }; - RefPtr mStartTimeRendezvous; - - bool HaveStartTime() { return mStartTimeRendezvous && mStartTimeRendezvous->HaveStartTime(); } - int64_t StartTime() { return mStartTimeRendezvous->StartTime(); } - - // Time at which the last video sample was requested. If it takes too long - // before the sample arrives, we will increase the amount of audio we buffer. - // This is necessary for legacy synchronous decoders to prevent underruns. - TimeStamp mVideoDecodeStartTime; - // Queue of audio frames. This queue is threadsafe, and is accessed from // the audio, decoder, state machine, and main threads. MediaQueue mAudioQueue; @@ -840,50 +747,9 @@ private: mNextPlayState == MediaDecoder::PLAY_STATE_PLAYING; } - struct SeekJob { - void Steal(SeekJob& aOther) - { - MOZ_DIAGNOSTIC_ASSERT(!Exists()); - mTarget = aOther.mTarget; - aOther.mTarget.Reset(); - mPromise = Move(aOther.mPromise); - } - - bool Exists() - { - MOZ_ASSERT(mTarget.IsValid() == !mPromise.IsEmpty()); - return mTarget.IsValid(); - } - - void Resolve(bool aAtEnd, const char* aCallSite) - { - mTarget.Reset(); - MediaDecoder::SeekResolveValue val(aAtEnd, mTarget.mEventVisibility); - mPromise.Resolve(val, aCallSite); - } - - void RejectIfExists(const char* aCallSite) - { - mTarget.Reset(); - mPromise.RejectIfExists(true, aCallSite); - } - - ~SeekJob() - { - MOZ_DIAGNOSTIC_ASSERT(!mTarget.IsValid()); - MOZ_DIAGNOSTIC_ASSERT(mPromise.IsEmpty()); - } - - SeekTarget mTarget; - MozPromiseHolder mPromise; - }; - - // Queued seek - moves to mPendingSeek when DecodeFirstFrame completes. + // Queued seek - moves to mCurrentSeek when DecodeFirstFrame completes. SeekJob mQueuedSeek; - // Position to seek to in microseconds when the seek state transition occurs. - SeekJob mPendingSeek; - // The position that we're currently seeking to. SeekJob mCurrentSeek; @@ -895,7 +761,9 @@ private: // The reader, don't call its methods with the decoder monitor held. // This is created in the state machine's constructor. - RefPtr mReader; + const RefPtr mReader; + + const RefPtr mReaderWrapper; // The end time of the last audio frame that's been pushed onto the media sink // in microseconds. This will approximately be the end time diff --git a/dom/media/mediasource/test/mochitest.ini b/dom/media/mediasource/test/mochitest.ini index bcd7501340..ba734fb560 100644 --- a/dom/media/mediasource/test/mochitest.ini +++ b/dom/media/mediasource/test/mochitest.ini @@ -78,6 +78,8 @@ skip-if = true # bug 1182946 skip-if = ((os == "win" && os_version == "5.1") || (os != "win" && os != "mac")) # Only supported on osx and vista+ [test_SeekNoData_mp4.html] skip-if = ((os == "win" && os_version == "5.1") || (os != "win" && os != "mac")) # Only supported on osx and vista+ +[test_SeekedEvent_mp4.html] +skip-if = ((os == "win" && os_version == "5.1") || (os != "win" && os != "mac")) # Only supported on osx and vista+ [test_SeekTwice_mp4.html] skip-if = ((os == "win" && os_version == "5.1") || (os != "win" && os != "mac")) # Only supported on osx and vista+ [test_SetModeThrows.html] diff --git a/dom/media/mediasource/test/test_SeekedEvent_mp4.html b/dom/media/mediasource/test/test_SeekedEvent_mp4.html new file mode 100644 index 0000000000..f80ae86f5a --- /dev/null +++ b/dom/media/mediasource/test/test_SeekedEvent_mp4.html @@ -0,0 +1,75 @@ + + + + MSE: Check that seeked event is fired prior loadeddata + + + + + +
+
+
+ + diff --git a/dom/xbl/nsXBLResourceLoader.cpp b/dom/xbl/nsXBLResourceLoader.cpp index aa6a15eb9a..9653d8825f 100644 --- a/dom/xbl/nsXBLResourceLoader.cpp +++ b/dom/xbl/nsXBLResourceLoader.cpp @@ -122,7 +122,7 @@ nsXBLResourceLoader::LoadResources(bool* aResult) // Passing nullptr for pretty much everything -- cause we don't care! // XXX: initialDocumentURI is nullptr! RefPtr req; - nsContentUtils::LoadImage(url, doc, docPrincipal, docURL, + nsContentUtils::LoadImage(url, doc, doc, docPrincipal, docURL, doc->GetReferrerPolicy(), nullptr, nsIRequest::LOAD_BACKGROUND, EmptyString(), getter_AddRefs(req)); diff --git a/embedding/browser/nsContextMenuInfo.cpp b/embedding/browser/nsContextMenuInfo.cpp index f7d0ac578d..52f5100cea 100644 --- a/embedding/browser/nsContextMenuInfo.cpp +++ b/embedding/browser/nsContextMenuInfo.cpp @@ -292,7 +292,7 @@ nsContextMenuInfo::GetBackgroundImageRequestInternal(nsIDOMNode* aDOMNode, return il->LoadImage(bgUri, nullptr, nullptr, doc->GetReferrerPolicy(), principal, nullptr, - nullptr, nullptr, nsIRequest::LOAD_NORMAL, + nullptr, nullptr, nullptr, nsIRequest::LOAD_NORMAL, nullptr, nsIContentPolicy::TYPE_INTERNAL_IMAGE, EmptyString(), aRequest); } diff --git a/image/imgLoader.cpp b/image/imgLoader.cpp index 976fccfd76..440908719a 100644 --- a/image/imgLoader.cpp +++ b/image/imgLoader.cpp @@ -2071,6 +2071,8 @@ imgLoader::LoadImageXPCOM(nsIURI* aURI, } imgRequestProxy* proxy; ReferrerPolicy refpol = ReferrerPolicyFromString(aReferrerPolicy); + nsCOMPtr node = do_QueryInterface(aCX); + nsCOMPtr doc = do_QueryInterface(aCX); nsresult rv = LoadImage(aURI, aInitialDocumentURI, aReferrerURI, @@ -2078,7 +2080,8 @@ imgLoader::LoadImageXPCOM(nsIURI* aURI, aLoadingPrincipal, aLoadGroup, aObserver, - aCX, + node, + doc, aLoadFlags, aCacheKey, aContentPolicyType, @@ -2096,7 +2099,8 @@ imgLoader::LoadImage(nsIURI* aURI, nsIPrincipal* aLoadingPrincipal, nsILoadGroup* aLoadGroup, imgINotificationObserver* aObserver, - nsISupports* aCX, + nsINode *aContext, + nsIDocument* aLoadingDocument, nsLoadFlags aLoadFlags, nsISupports* aCacheKey, nsContentPolicyType aContentPolicyType, @@ -2175,13 +2179,13 @@ imgLoader::LoadImage(nsIURI* aURI, // XXX For now ignore aCacheKey. We will need it in the future // for correctly dealing with image load requests that are a result // of post data. - nsCOMPtr doc = do_QueryInterface(aCX); + nsCOMPtr doc = do_QueryInterface(aLoadingDocument); ImageCacheKey key(aURI, doc); imgCacheTable& cache = GetCache(key); if (cache.Get(key, getter_AddRefs(entry)) && entry) { if (ValidateEntry(entry, aURI, aInitialDocumentURI, aReferrerURI, - aReferrerPolicy, aLoadGroup, aObserver, aCX, + aReferrerPolicy, aLoadGroup, aObserver, aLoadingDocument, requestFlags, aContentPolicyType, true, _retval, aLoadingPrincipal, corsmode)) { request = entry->GetRequest(); @@ -2232,7 +2236,7 @@ imgLoader::LoadImage(nsIURI* aURI, requestFlags, aContentPolicyType, aLoadingPrincipal, - aCX); + aContext); if (NS_FAILED(rv)) { return NS_ERROR_FAILURE; } @@ -2250,7 +2254,7 @@ imgLoader::LoadImage(nsIURI* aURI, nsCOMPtr channelLoadGroup; newChannel->GetLoadGroup(getter_AddRefs(channelLoadGroup)); request->Init(aURI, aURI, /* aHadInsecureRedirect = */ false, - channelLoadGroup, newChannel, entry, aCX, + channelLoadGroup, newChannel, entry, aLoadingDocument, aLoadingPrincipal, corsmode, aReferrerPolicy); // Add the initiator type for this image load @@ -2322,7 +2326,7 @@ imgLoader::LoadImage(nsIURI* aURI, // URL maps to the same image on a page) if we load the same image in a // different tab (see bug 528003), because its load id will get re-set, and // that'll cause us to validate over the network. - request->SetLoadId(aCX); + request->SetLoadId(aLoadingDocument); LOG_MSG(gImgLog, "imgLoader::LoadImage", "creating proxy request."); rv = CreateNewProxyForRequest(request, aLoadGroup, aObserver, diff --git a/image/imgLoader.h b/image/imgLoader.h index 4d7ec5bfde..f98336fe5c 100644 --- a/image/imgLoader.h +++ b/image/imgLoader.h @@ -252,7 +252,8 @@ public: nsIPrincipal* aLoadingPrincipal, nsILoadGroup* aLoadGroup, imgINotificationObserver* aObserver, - nsISupports* aCX, + nsINode* aContext, + nsIDocument* aLoadingDocument, nsLoadFlags aLoadFlags, nsISupports* aCacheKey, nsContentPolicyType aContentPolicyType, diff --git a/js/public/Initialization.h b/js/public/Initialization.h index fa022c9f60..631441e489 100644 --- a/js/public/Initialization.h +++ b/js/public/Initialization.h @@ -61,6 +61,14 @@ JS_SetICUMemoryFunctions(JS_ICUAllocFn allocFn, extern JS_PUBLIC_API(bool) JS_Init(void); +/** + * A variant of JS_Init. On success it returns nullptr. On failure it returns a + * pointer to a string literal that describes how initialization failed, which + * can be useful for debugging purposes. + */ +extern JS_PUBLIC_API(const char*) +JS_InitWithFailureDiagnostic(void); + /** * Destroy free-standing resources allocated by SpiderMonkey, not associated * with any runtime, context, or other structure. diff --git a/js/src/asmjs/Wasm.cpp b/js/src/asmjs/Wasm.cpp index 2d42d5aff1..3881b70fb9 100644 --- a/js/src/asmjs/Wasm.cpp +++ b/js/src/asmjs/Wasm.cpp @@ -32,6 +32,7 @@ #include "vm/Debugger-inl.h" using namespace js; +using namespace js::jit; using namespace js::wasm; using mozilla::CheckedInt; diff --git a/js/src/builtin/ModuleObject.cpp b/js/src/builtin/ModuleObject.cpp index 03300f598f..28141fb274 100644 --- a/js/src/builtin/ModuleObject.cpp +++ b/js/src/builtin/ModuleObject.cpp @@ -13,6 +13,7 @@ #include "gc/Tracer.h" #include "jsobjinlines.h" +#include "jsscriptinlines.h" using namespace js; using namespace js::frontend; diff --git a/js/src/devtools/automation/cgc-jittest-timeouts.txt b/js/src/devtools/automation/cgc-jittest-timeouts.txt index beb0ae6c0f..617793e2c9 100644 --- a/js/src/devtools/automation/cgc-jittest-timeouts.txt +++ b/js/src/devtools/automation/cgc-jittest-timeouts.txt @@ -23,6 +23,9 @@ ion/bug787921.js ion/bug977966.js parallel/alloc-many-objs.js parallel/alloc-too-many-objs.js +parser/bug-1263881-1.js +parser/bug-1263881-2.js +parser/bug-1263881-3.js saved-stacks/bug-1006876-too-much-recursion.js self-test/assertDeepEq.js sunspider/check-string-unpack-code.js diff --git a/js/src/frontend/BytecodeCompiler.cpp b/js/src/frontend/BytecodeCompiler.cpp index e095aa0be3..c8d76f78dc 100644 --- a/js/src/frontend/BytecodeCompiler.cpp +++ b/js/src/frontend/BytecodeCompiler.cpp @@ -346,12 +346,16 @@ BytecodeCompiler::prepareAndEmitTree(ParseNode** ppn) { if (!FoldConstants(cx, ppn, parser.ptr()) || !NameFunctions(cx, *ppn) || - !emitter->updateLocalsToFrameSlots() || - !emitter->emitTree(*ppn)) + !emitter->updateLocalsToFrameSlots()) { return false; } + emitter->setFunctionBodyEndPos((*ppn)->pn_pos); + + if (!emitter->emitTree(*ppn)) + return false; + return true; } @@ -846,7 +850,7 @@ frontend::CompileLazyFunction(JSContext* cx, Handle lazy, const cha MOZ_ASSERT(!options.forEval); BytecodeEmitter bce(/* parent = */ nullptr, &parser, pn->pn_funbox, script, lazy, /* insideEval = */ false, /* evalCaller = */ nullptr, - /* insideNonGlobalEval = */ false, options.lineno, + /* insideNonGlobalEval = */ false, pn->pn_pos, BytecodeEmitter::LazyFunction); if (!bce.init()) return false; diff --git a/js/src/frontend/BytecodeEmitter.cpp b/js/src/frontend/BytecodeEmitter.cpp index 6f33fb3f9e..c8c91873f6 100644 --- a/js/src/frontend/BytecodeEmitter.cpp +++ b/js/src/frontend/BytecodeEmitter.cpp @@ -143,12 +143,27 @@ BytecodeEmitter::BytecodeEmitter(BytecodeEmitter* parent, insideEval(insideEval), insideNonGlobalEval(insideNonGlobalEval), insideModule(false), - emitterMode(emitterMode) + emitterMode(emitterMode), + functionBodyEndPosSet(false) { MOZ_ASSERT_IF(evalCaller, insideEval); MOZ_ASSERT_IF(emitterMode == LazyFunction, lazyScript); } +BytecodeEmitter::BytecodeEmitter(BytecodeEmitter* parent, + Parser* parser, SharedContext* sc, + HandleScript script, Handle lazyScript, + bool insideEval, HandleScript evalCaller, + bool insideNonGlobalEval, TokenPos bodyPosition, + EmitterMode emitterMode) + : BytecodeEmitter(parent, parser, sc, script, lazyScript, insideEval, + evalCaller, insideNonGlobalEval, + parser->tokenStream.srcCoords.lineNum(bodyPosition.begin), + emitterMode) +{ + setFunctionBodyEndPos(bodyPosition); +} + bool BytecodeEmitter::init() { @@ -2820,8 +2835,13 @@ BytecodeEmitter::emitElemOperands(ParseNode* pn, EmitElemOption opts) if (!emitTree(pn->pn_right)) return false; - if (opts == EmitElemOption::Set && !emit2(JSOP_PICK, 2)) - return false; + if (opts == EmitElemOption::Set) { + if (!emit2(JSOP_PICK, 2)) + return false; + } else if (opts == EmitElemOption::IncDec || opts == EmitElemOption::CompoundAssign) { + if (!emit1(JSOP_TOID)) + return false; + } return true; } @@ -2840,8 +2860,10 @@ BytecodeEmitter::emitSuperElemOperands(ParseNode* pn, EmitElemOption opts) // We need to convert the key to an object id first, so that we do not do // it inside both the GETELEM and the SETELEM. - if (opts == EmitElemOption::IncDec && !emit1(JSOP_TOID)) - return false; + if (opts == EmitElemOption::IncDec || opts == EmitElemOption::CompoundAssign) { + if (!emit1(JSOP_TOID)) + return false; + } if (!emitGetThisForSuperBase(pn->pn_left)) return false; @@ -2913,6 +2935,9 @@ BytecodeEmitter::emitElemIncDec(ParseNode* pn) bool isSuper = pn->pn_kid->as().isSuper(); + // We need to convert the key to an object id first, so that we do not do + // it inside both the GETELEM and the SETELEM. This is done by + // emit(Super)ElemOperands. if (isSuper) { if (!emitSuperElemOperands(pn->pn_kid, EmitElemOption::IncDec)) return false; @@ -2936,12 +2961,7 @@ BytecodeEmitter::emitElemIncDec(ParseNode* pn) return false; getOp = JSOP_GETELEM_SUPER; } else { - // We need to convert the key to an object id first, so that we do not do - // it inside both the GETELEM and the SETELEM. In the super case, this is - // done by emitSuperElemOperands. - // OBJ KEY* - if (!emit1(JSOP_TOID)) // OBJ KEY - return false; + // OBJ KEY if (!emit1(JSOP_DUP2)) // OBJ KEY OBJ KEY return false; getOp = JSOP_GETELEM; @@ -3598,9 +3618,13 @@ BytecodeEmitter::emitFunctionScript(ParseNode* body) switchToMain(); } + setFunctionBodyEndPos(body->pn_pos); if (!emitTree(body)) return false; + if (!updateSourceCoordNotes(body->pn_pos.end)) + return false; + if (sc->isFunctionBox()) { if (sc->asFunctionBox()->isGenerator()) { // If we fall off the end of a generator, do a final yield. @@ -3700,6 +3724,7 @@ BytecodeEmitter::emitModuleScript(ParseNode* body) // may walk the scope chain of currently compiling scripts. JSScript::linkToModuleFromEmitter(cx, script, modulebox); + setFunctionBodyEndPos(body->pn_pos); if (!emitTree(body)) return false; @@ -4601,20 +4626,20 @@ BytecodeEmitter::emitAssignment(ParseNode* lhs, JSOp op, ParseNode* rhs) if (!makeAtomIndex(lhs->pn_atom, &atomIndex)) return false; break; - case PNK_ELEM: + case PNK_ELEM: { MOZ_ASSERT(lhs->isArity(PN_BINARY)); + EmitElemOption opt = op == JSOP_NOP ? EmitElemOption::Get : EmitElemOption::CompoundAssign; if (lhs->as().isSuper()) { - if (!emitSuperElemOperands(lhs)) + if (!emitSuperElemOperands(lhs, opt)) return false; offset += 3; } else { - if (!emitTree(lhs->pn_left)) - return false; - if (!emitTree(lhs->pn_right)) + if (!emitElemOperands(lhs, opt)) return false; offset += 2; } break; + } case PNK_ARRAY: case PNK_OBJECT: break; @@ -6425,10 +6450,9 @@ BytecodeEmitter::emitFunction(ParseNode* pn, bool needsProto) script->bindings = funbox->bindings; - uint32_t lineNum = parser->tokenStream.srcCoords.lineNum(pn->pn_pos.begin); BytecodeEmitter bce2(this, parser, funbox, script, /* lazyScript = */ nullptr, insideEval, evalCaller, - insideNonGlobalEval, lineNum, emitterMode); + insideNonGlobalEval, pn->pn_pos, emitterMode); if (!bce2.init()) return false; @@ -6799,6 +6823,13 @@ BytecodeEmitter::emitReturn(ParseNode* pn) return false; } + // We know functionBodyEndPos is set because "return" is only + // valid in a function, and so we've passed through + // emitFunctionScript. + MOZ_ASSERT(functionBodyEndPosSet); + if (!updateSourceCoordNotes(functionBodyEndPos)) + return false; + /* * EmitNonLocalJumpFixup may add fixup bytecode to close open try * blocks having finally clauses and to exit intermingled let blocks. diff --git a/js/src/frontend/BytecodeEmitter.h b/js/src/frontend/BytecodeEmitter.h index 2427b89028..fca73f045a 100644 --- a/js/src/frontend/BytecodeEmitter.h +++ b/js/src/frontend/BytecodeEmitter.h @@ -232,6 +232,11 @@ struct BytecodeEmitter const EmitterMode emitterMode; + // The end location of a function body that is being emitted. + uint32_t functionBodyEndPos; + // Whether functionBodyEndPos was set. + bool functionBodyEndPosSet; + /* * Note that BytecodeEmitters are magic: they own the arena "top-of-stack" * space above their tempMark points. This means that you cannot alloc from @@ -242,6 +247,14 @@ struct BytecodeEmitter HandleScript script, Handle lazyScript, bool insideEval, HandleScript evalCaller, bool insideNonGlobalEval, uint32_t lineNum, EmitterMode emitterMode = Normal); + + // An alternate constructor that uses a TokenPos for the starting + // line and that sets functionBodyEndPos as well. + BytecodeEmitter(BytecodeEmitter* parent, Parser* parser, SharedContext* sc, + HandleScript script, Handle lazyScript, + bool insideEval, HandleScript evalCaller, + bool insideNonGlobalEval, TokenPos bodyPosition, EmitterMode emitterMode = Normal); + bool init(); bool updateLocalsToFrameSlots(); @@ -302,6 +315,11 @@ struct BytecodeEmitter unsigned currentLine() const { return current->currentLine; } unsigned lastColumn() const { return current->lastColumn; } + void setFunctionBodyEndPos(TokenPos pos) { + functionBodyEndPos = pos.end; + functionBodyEndPosSet = true; + } + bool reportError(ParseNode* pn, unsigned errorNumber, ...); bool reportStrictWarning(ParseNode* pn, unsigned errorNumber, ...); bool reportStrictModeError(ParseNode* pn, unsigned errorNumber, ...); @@ -519,7 +537,7 @@ struct BytecodeEmitter // Emit bytecode to put operands for a JSOP_GETELEM/CALLELEM/SETELEM/DELELEM // opcode onto the stack in the right order. In the case of SETELEM, the // value to be assigned must already be pushed. - enum class EmitElemOption { Get, Set, Call, IncDec }; + enum class EmitElemOption { Get, Set, Call, IncDec, CompoundAssign }; bool emitElemOperands(ParseNode* pn, EmitElemOption opts); bool emitElemOpBase(JSOp op); diff --git a/js/src/frontend/Parser.cpp b/js/src/frontend/Parser.cpp index b862c7c416..5f8536f0f2 100644 --- a/js/src/frontend/Parser.cpp +++ b/js/src/frontend/Parser.cpp @@ -94,7 +94,9 @@ template <> bool ParseContext::checkLocalsOverflow(TokenStream& ts) { - if (vars_.length() + bodyLevelLexicals_.length() >= LOCALNO_LIMIT) { + if (vars_.length() + bodyLevelLexicals_.length() >= LOCALNO_LIMIT || + bodyLevelLexicals_.length() >= Bindings::BODY_LEVEL_LEXICAL_LIMIT) + { ts.reportError(JSMSG_TOO_MANY_LOCALS); return false; } @@ -2331,8 +2333,9 @@ Parser::bindBodyLevelFunctionName(HandlePropertyName funName, MOZ_ASSERT(!dn->isUsed()); MOZ_ASSERT(dn->isDefn()); - if (dn->kind() == Definition::CONSTANT || dn->kind() == Definition::LET) - return reportRedeclaration(nullptr, Definition::VAR, funName); + Definition::Kind kind = dn->kind(); + if (kind == Definition::CONSTANT || kind == Definition::LET || kind == Definition::IMPORT) + return reportRedeclaration(nullptr, kind, funName); /* * Body-level function statements are effectively variable @@ -2342,7 +2345,7 @@ Parser::bindBodyLevelFunctionName(HandlePropertyName funName, * the function's binding (which is mutable), so turn any existing * declaration into a use. */ - if (dn->kind() == Definition::ARG) { + if (kind == Definition::ARG) { // The exception to the above comment is when the function // has the same name as an argument. Then the argument node // remains a definition. But change the function node pn so @@ -2751,7 +2754,10 @@ Parser::templateLiteral(YieldHandling yieldHandling) Node pn = noSubstitutionTemplate(); if (!pn) return null(); + Node nodeList = handler.newList(PNK_TEMPLATE_STRING_LIST, pn); + if (!nodeList) + return null(); TokenKind tt; do { @@ -3212,6 +3218,8 @@ Parser::functionArgsAndBodyGeneric(InHandling inHandling, return false; } + handler.setEndPosition(body, pos().begin); + return finishFunctionDefinition(pn, funbox, body); } @@ -4016,7 +4024,7 @@ HasOuterLexicalBinding(ParseContext* pc, StmtInfoPC* stmt, HandleA while (stmt->enclosingScope) { stmt = LexicalLookup(pc, atom, stmt->enclosingScope); if (!stmt) - return false; + break; if (stmt->type == StmtType::BLOCK) return true; } @@ -7584,8 +7592,11 @@ Parser::expr(InHandling inHandling, YieldHandling yieldHandling, // We begin by checking for an outer pending error since it would // have occurred first. - if (possibleError->checkForExprErrors()) - possibleErrorInner.checkForExprErrors(); + if (possibleError && !possibleError->checkForExprErrors()) + return null(); + + // Go ahead and report the inner error. + possibleErrorInner.checkForExprErrors(); return null(); } handler.addList(seq, pn); diff --git a/js/src/gc/Barrier.h b/js/src/gc/Barrier.h index a9e23966f4..d822bab65e 100644 --- a/js/src/gc/Barrier.h +++ b/js/src/gc/Barrier.h @@ -470,11 +470,25 @@ class HeapPtr : public WriteBarrieredBase }; /* - * A pre- and post-barriered heap pointer, for use inside the JS engine. + * A pre- and post-barriered heap pointer, for use inside the JS engine. These + * heap pointers can be stored in C++ containers like GCVector and GCHashMap. * - * Unlike HeapPtr, it can be used in memory that is not managed by the GC, - * i.e. in C++ containers. It is, however, somewhat slower, so should only be - * used in contexts where this ability is necessary. + * The GC sometimes keeps pointers to pointers to GC things --- for example, to + * track references into the nursery. However, C++ containers like GCVector and + * GCHashMap usually reserve the right to relocate their elements any time + * they're modified, invalidating all pointers to the elements. RelocatablePtr + * has a move constructor which knows how to keep the GC up to date if it is + * moved to a new location. + * + * However, because of this additional communication with the GC, RelocatablePtr + * is somewhat slower, so it should only be used in contexts where this ability + * is necessary. + * + * Obviously, JSObjects, JSStrings, and the like get tenured and compacted, so + * whatever pointers they contain get relocated, in the sense used here. + * However, since the GC itself is moving those values, it takes care of its + * internal pointers to those pointers itself. RelocatablePtr is only necessary + * when the relocation would otherwise occur without the GC's knowledge. */ template class RelocatablePtr : public WriteBarrieredBase diff --git a/js/src/gc/Marking.cpp b/js/src/gc/Marking.cpp index d2284eb1ff..d839505898 100644 --- a/js/src/gc/Marking.cpp +++ b/js/src/gc/Marking.cpp @@ -2154,6 +2154,7 @@ JSObject* js::TenuringTracer::moveToTenured(JSObject* src) { MOZ_ASSERT(IsInsideNursery(src)); + MOZ_ASSERT(!src->zone()->usedByExclusiveThread); AllocKind dstKind = src->allocKindForTenure(nursery()); Zone* zone = src->zone(); @@ -2286,20 +2287,18 @@ js::TenuringTracer::moveObjectToTenured(JSObject* dst, JSObject* src, AllocKind } } - if (src->getClass()->flags & JSCLASS_SKIP_NURSERY_FINALIZE) { - if (src->is()) { - InlineTypedObject::objectMovedDuringMinorGC(this, dst, src); - } else if (src->is()) { - tenuredSize += UnboxedArrayObject::objectMovedDuringMinorGC(this, dst, src, dstKind); - } else if (src->is()) { - tenuredSize += ArgumentsObject::objectMovedDuringMinorGC(this, dst, src); - } else if (JSObjectMovedOp op = dst->getClass()->extObjectMovedOp()) { - op(dst, src); - } else { - // Objects with JSCLASS_SKIP_NURSERY_FINALIZE need to be handled above - // to ensure any additional nursery buffers they hold are moved. - MOZ_CRASH("Unhandled JSCLASS_SKIP_NURSERY_FINALIZE Class"); - } + if (src->is()) { + InlineTypedObject::objectMovedDuringMinorGC(this, dst, src); + } else if (src->is()) { + tenuredSize += UnboxedArrayObject::objectMovedDuringMinorGC(this, dst, src, dstKind); + } else if (src->is()) { + tenuredSize += ArgumentsObject::objectMovedDuringMinorGC(this, dst, src); + } else if (JSObjectMovedOp op = dst->getClass()->extObjectMovedOp()) { + op(dst, src); + } else if (src->getClass()->flags & JSCLASS_SKIP_NURSERY_FINALIZE) { + // Objects with JSCLASS_SKIP_NURSERY_FINALIZE need to be handled above + // to ensure any additional nursery buffers they hold are moved. + MOZ_CRASH("Unhandled JSCLASS_SKIP_NURSERY_FINALIZE Class"); } return tenuredSize; diff --git a/js/src/gc/Policy.h b/js/src/gc/Policy.h index 0348195ea3..b5a94389ce 100644 --- a/js/src/gc/Policy.h +++ b/js/src/gc/Policy.h @@ -10,6 +10,8 @@ #define gc_Policy_h #include "mozilla/TypeTraits.h" +#include "gc/Barrier.h" +#include "gc/Marking.h" #include "js/GCPolicyAPI.h" // Forward declare the types we're defining policies for. This file is @@ -17,6 +19,7 @@ // will be available when we do template expansion, allowing for use of // static members in the underlying types. We cannot, however, use // static_assert to verify relations between types. +class JSLinearString; namespace js { class AccessorShape; class ArgumentsObject; diff --git a/js/src/jit-test/tests/basic/bug1264954.js b/js/src/jit-test/tests/basic/bug1264954.js new file mode 100644 index 0000000000..d67ac2b63a --- /dev/null +++ b/js/src/jit-test/tests/basic/bug1264954.js @@ -0,0 +1,8 @@ +if (!('oomTest' in this)) + quit(); +function f(x) { + oomTest(() => eval(x)); +} +f(""); +f(""); +f(`eval([ "x = \`\${new Error.lineNumber}" ].join())`); diff --git a/js/src/jit-test/tests/debug/Frame-onPop-23.js b/js/src/jit-test/tests/debug/Frame-onPop-23.js new file mode 100644 index 0000000000..d49e1d456c --- /dev/null +++ b/js/src/jit-test/tests/debug/Frame-onPop-23.js @@ -0,0 +1,34 @@ +// Check that the line number reported at an onPop stop makes sense, +// even when it happens on an "artificial" instruction. + +var g = newGlobal(); + +// This bit of code arranges for the line number of the "artificial" +// instruction to be something nonsensical -- the middle of a loop +// which cannot be entered. +g.eval(`function f() { + debugger; // +0 + if(false) { // +1 + for(var b=0; b<0; b++) { // +2 + c = 2; // +3 + } // +4 + } // +5 +} // +6 +`); + +var dbg = Debugger(g); + +let debugLine; +let foundLine; + +dbg.onDebuggerStatement = function(frame) { + debugLine = frame.script.getOffsetLocation(frame.offset).lineNumber; + frame.onPop = function(c) { + foundLine = this.script.getOffsetLocation(this.offset).lineNumber; + }; +}; + +g.eval("f();\n"); + +// The stop should happen on the closing brace of the function. +assertEq(foundLine == debugLine + 6, true); diff --git a/js/src/jit-test/tests/debug/Frame-onStep-11.js b/js/src/jit-test/tests/debug/Frame-onStep-11.js index 21521ae525..dae366165c 100644 --- a/js/src/jit-test/tests/debug/Frame-onStep-11.js +++ b/js/src/jit-test/tests/debug/Frame-onStep-11.js @@ -33,4 +33,4 @@ dbg.onDebuggerStatement = function(frame) { g.f(); -assertEq(foundLines, ",1,2,3,4,5,6,7,8,10"); +assertEq(foundLines, ",1,2,3,4,5,6,7,8,10,11"); diff --git a/js/src/jit-test/tests/debug/Frame-onStep-12.js b/js/src/jit-test/tests/debug/Frame-onStep-12.js index 517ccbf1d9..4db38b3136 100644 --- a/js/src/jit-test/tests/debug/Frame-onStep-12.js +++ b/js/src/jit-test/tests/debug/Frame-onStep-12.js @@ -65,7 +65,7 @@ testOne("testTryFinally", } finally { // +6 } // +7 nothing(); // +8 - `, "168"); + `, "1689"); // The same but without a finally clause. testOne("testTryCatch", @@ -74,7 +74,7 @@ testOne("testTryCatch", } catch (e) { // +6 } // +7 nothing(); // +8 - `, "18"); + `, "189"); // Test the instructions at the end of a "catch". testOne("testCatchFinally", @@ -85,7 +85,7 @@ testOne("testCatchFinally", } finally { // +6 } // +7 nothing(); // +8 - `, "168"); + `, "1689"); // The same but without a finally clause. This relies on a // SpiderMonkey extension, because otherwise there's no way to see @@ -98,7 +98,7 @@ testOne("testCatch", } catch (e) { // +6 } // +7 nothing(); // +8 - `, "18"); + `, "189"); // Test the instruction at the end of a "finally" clause. testOne("testFinally", @@ -107,7 +107,7 @@ testOne("testFinally", ${bitOfCode} } // +6 nothing(); // +7 - `, "17"); + `, "178"); // Test the instruction at the end of a "then" clause. testOne("testThen", @@ -116,7 +116,7 @@ testOne("testThen", } else { // +6 } // +7 nothing(); // +8 - `, "18"); + `, "189"); // Test the instructions leaving a switch block. testOne("testSwitch", @@ -126,4 +126,4 @@ testOne("testSwitch", ${bitOfCode} } // +6 nothing(); // +7 - `, "17"); + `, "178"); diff --git a/js/src/jit-test/tests/debug/Frame-onStep-13.js b/js/src/jit-test/tests/debug/Frame-onStep-13.js new file mode 100644 index 0000000000..cc2c18c6d6 --- /dev/null +++ b/js/src/jit-test/tests/debug/Frame-onStep-13.js @@ -0,0 +1,29 @@ +// Stepping over a not-taken "if" that is at the end of the function +// should move to the end of the function, not somewhere in the body +// of the "if". + +var g = newGlobal(); +g.eval(`function f() { // 1 + var a,c; // 2 + debugger; // 3 + if(false) { // 4 + for(var b=0; b<0; b++) { // 5 + c = 2; // 6 + } // 7 + } // 8 +} // 9 +`); + +var dbg = Debugger(g); +var badStep = false; + +dbg.onDebuggerStatement = function(frame) { + let debugLine = frame.script.getOffsetLocation(frame.offset).lineNumber; + assertEq(debugLine, 3); + frame.onStep = function() { + let foundLine = this.script.getOffsetLocation(this.offset).lineNumber; + assertEq(foundLine <= 4 || foundLine >= 8, true); + }; +}; + +g.eval("f();\n"); diff --git a/js/src/jit-test/tests/debug/Frame-onStep-16.js b/js/src/jit-test/tests/debug/Frame-onStep-16.js new file mode 100644 index 0000000000..b011da4288 --- /dev/null +++ b/js/src/jit-test/tests/debug/Frame-onStep-16.js @@ -0,0 +1,34 @@ +// Stepping through a function with a return statement should pause on +// the closing brace of the function. + +var g = newGlobal(); +var dbg = Debugger(g); +var log; + +function test(fnStr) { + log = ''; + g.eval(fnStr); + + dbg.onDebuggerStatement = function(frame) { + frame.onStep = function() { + let {lineNumber, isEntryPoint} = frame.script.getOffsetLocation(frame.offset); + if (isEntryPoint) { + log += lineNumber + ' '; + } + }; + }; + + g.eval("f(23);"); +} + +test("function f(x) {\n" + // 1 + " debugger;\n" + // 2 + " return 23 + x;\n" + // 3 + "}\n"); // 4 +assertEq(log, '3 4 '); + +test("function f(x) {\n" + // 1 + " debugger;\n" + // 2 + " return;\n" + // 3 + "}\n"); // 4 +assertEq(log, '3 4 '); diff --git a/js/src/jit-test/tests/debug/Frame-onStep-lines-01.js b/js/src/jit-test/tests/debug/Frame-onStep-lines-01.js index b805f0efcb..0c486971c7 100644 --- a/js/src/jit-test/tests/debug/Frame-onStep-lines-01.js +++ b/js/src/jit-test/tests/debug/Frame-onStep-lines-01.js @@ -48,7 +48,7 @@ assertEq(Object.keys(offsets).length, 2); // have no effect on this one. doSingleStep = false; g.eval('t(0, 0, 0)'); -assertEq(Object.keys(offsets).length, 6); +assertEq(Object.keys(offsets).length, 7); doSingleStep = true; // Single-step in an eval frame. This should reach every line but the diff --git a/js/src/jit-test/tests/debug/Script-getAllColumnOffsets-01.js b/js/src/jit-test/tests/debug/Script-getAllColumnOffsets-01.js index 50c38dffe1..620d562441 100644 --- a/js/src/jit-test/tests/debug/Script-getAllColumnOffsets-01.js +++ b/js/src/jit-test/tests/debug/Script-getAllColumnOffsets-01.js @@ -16,4 +16,4 @@ Debugger(global).onDebuggerStatement = function (frame) { global.log = ''; global.eval("function f(n) { for (var i = 0; i < n; ++i) log += '. '; log += '! '; } debugger;"); global.f(3); -assertEq(global.log, "25 32 44 . 39 32 44 . 39 32 44 . 39 32 57 ! 69 "); +assertEq(global.log, "25 32 44 . 39 32 44 . 39 32 44 . 39 32 57 ! 70 "); diff --git a/js/src/jit-test/tests/debug/Script-getAllColumnOffsets-06.js b/js/src/jit-test/tests/debug/Script-getAllColumnOffsets-06.js index fe9bdb6217..20b49add88 100644 --- a/js/src/jit-test/tests/debug/Script-getAllColumnOffsets-06.js +++ b/js/src/jit-test/tests/debug/Script-getAllColumnOffsets-06.js @@ -16,7 +16,7 @@ Debugger(global).onDebuggerStatement = function (frame) { global.log = ""; global.eval("function ppppp() { return 1; }"); // 1 2 3 4 -// 0123456789012345678901234567890123456789012345678 +// 01234567890123456789012345678901234567890123456789 global.eval("function f(){ 1 && ppppp(ppppp()) && new Error() } debugger;"); global.f(); @@ -24,5 +24,5 @@ global.f(); // 25 - Inner print() // 19 - Outer print() // 37 - new Error() -// 48 - Exit the function body -assertEq(global.log, "14 25 19 37 48 "); +// 49 - Exit the function body +assertEq(global.log, "14 25 19 37 49 "); diff --git a/js/src/jit-test/tests/debug/Script-startLine.js b/js/src/jit-test/tests/debug/Script-startLine.js index 4d3c499501..f5b2d10850 100644 --- a/js/src/jit-test/tests/debug/Script-startLine.js +++ b/js/src/jit-test/tests/debug/Script-startLine.js @@ -55,7 +55,9 @@ g.eval("/* Any copyright is dedicated to the Public Domain.\n" + " eval(\"42;\");\n" + " function foo() {}\n" + " if (true) {\n" + - " foo();\n" + // <- this is +6 and must be within the extent - " }\n" + - "}"); -test(g.secondCall, 7); + " foo();\n" + + // The "missing" newline here is a trick to make a newline + // source note come at the end. A real newline between the two + // closing braces causes a setline note instead. + " } }"); +test(g.secondCall, 8); diff --git a/js/src/jit-test/tests/ion/pgo-bug1252120.js b/js/src/jit-test/tests/ion/pgo-bug1252120.js new file mode 100644 index 0000000000..100fbfd34a --- /dev/null +++ b/js/src/jit-test/tests/ion/pgo-bug1252120.js @@ -0,0 +1,14 @@ +// |jit-test| --ion-pgo=on; + +target = handler = {} +for (p of[new Proxy(target, handler)]) + evaluate("foo()"); +function foo() { + symbols = [Symbol] + values = [NaN] + for (comparator of[""]) + for (b of values) assertEq; + for (comparator of[""]) + for (a of symbols) + for (b of values) assertEq; +} diff --git a/js/src/jit-test/tests/modules/bug-1258097.js b/js/src/jit-test/tests/modules/bug-1258097.js new file mode 100644 index 0000000000..c7f8770436 --- /dev/null +++ b/js/src/jit-test/tests/modules/bug-1258097.js @@ -0,0 +1,3 @@ +// |jit-test| module; error:SyntaxError +import x from 'y'; +function x() {} diff --git a/js/src/jit-test/tests/parser/bug-1263881-1.js b/js/src/jit-test/tests/parser/bug-1263881-1.js new file mode 100644 index 0000000000..8bb9d7ab28 --- /dev/null +++ b/js/src/jit-test/tests/parser/bug-1263881-1.js @@ -0,0 +1,11 @@ +// |jit-test| error: SyntaxError +let moduleRepo = {}; +setModuleResolveHook(function(module, specifier) { + return moduleRepo[specifier]; +}); +moduleRepo['a'] = parseModule("export let a = 1;"); +let s = ""; +let max = 65536; +for (let i = 0; i < max; i++) + s += "import * as ns" + i + " from 'a';\n"; +parseModule(s); diff --git a/js/src/jit-test/tests/parser/bug-1263881-2.js b/js/src/jit-test/tests/parser/bug-1263881-2.js new file mode 100644 index 0000000000..c2bc5e5108 --- /dev/null +++ b/js/src/jit-test/tests/parser/bug-1263881-2.js @@ -0,0 +1,6 @@ +// |jit-test| error: SyntaxError +let s = ""; +let max = 65536; +for (let i = 0; i < max; i++) + s += "let ns" + i + " = "+ i +";\n"; +eval(s); diff --git a/js/src/jit-test/tests/parser/bug-1263881-3.js b/js/src/jit-test/tests/parser/bug-1263881-3.js new file mode 100644 index 0000000000..f8d43d73c4 --- /dev/null +++ b/js/src/jit-test/tests/parser/bug-1263881-3.js @@ -0,0 +1,7 @@ +// |jit-test| error: SyntaxError +let s = "function foo() {\n"; +let max = 65536; +for (let i = 0; i < max; i++) + s += "let ns" + i + " = "+ i +";\n"; +s += "};"; +eval(s); diff --git a/js/src/jit/IonAnalysis.cpp b/js/src/jit/IonAnalysis.cpp index c7ffc4805c..1430c32e67 100644 --- a/js/src/jit/IonAnalysis.cpp +++ b/js/src/jit/IonAnalysis.cpp @@ -1909,7 +1909,8 @@ jit::RenumberBlocks(MIRGraph& graph) // A utility for code which deletes blocks. Renumber the remaining blocks, // recompute dominators, and optionally recompute AliasAnalysis dependencies. bool -jit::AccountForCFGChanges(MIRGenerator* mir, MIRGraph& graph, bool updateAliasAnalysis) +jit::AccountForCFGChanges(MIRGenerator* mir, MIRGraph& graph, bool updateAliasAnalysis, + bool underValueNumberer) { // Renumber the blocks and clear out the old dominator info. size_t id = 0; @@ -1928,7 +1929,7 @@ jit::AccountForCFGChanges(MIRGenerator* mir, MIRGraph& graph, bool updateAliasAn return false; } - AssertExtendedGraphCoherency(graph); + AssertExtendedGraphCoherency(graph, underValueNumberer); return true; } @@ -2556,7 +2557,7 @@ AssertResumePointDominatedByOperands(MResumePoint* resume) #endif // DEBUG void -jit::AssertExtendedGraphCoherency(MIRGraph& graph) +jit::AssertExtendedGraphCoherency(MIRGraph& graph, bool underValueNumberer) { // Checks the basic GraphCoherency but also other conditions that // do not hold immediately (such as the fact that critical edges @@ -2580,8 +2581,15 @@ jit::AssertExtendedGraphCoherency(MIRGraph& graph) MOZ_ASSERT(block->getSuccessor(i)->numPredecessors() == 1); if (block->isLoopHeader()) { - MOZ_ASSERT(block->numPredecessors() == 2); - MBasicBlock* backedge = block->getPredecessor(1); + if (underValueNumberer && block->numPredecessors() == 3) { + // Fixup block. + MOZ_ASSERT(block->getPredecessor(1)->numPredecessors() == 0); + MOZ_ASSERT(graph.osrBlock(), + "Fixup blocks should only exists if we have an osr block."); + } else { + MOZ_ASSERT(block->numPredecessors() == 2); + } + MBasicBlock* backedge = block->backedge(); MOZ_ASSERT(backedge->id() >= block->id()); MOZ_ASSERT(backedge->numSuccessors() == 1); MOZ_ASSERT(backedge->getSuccessor(0) == *block); diff --git a/js/src/jit/IonAnalysis.h b/js/src/jit/IonAnalysis.h index 600ce78aca..652a1ec473 100644 --- a/js/src/jit/IonAnalysis.h +++ b/js/src/jit/IonAnalysis.h @@ -60,7 +60,8 @@ bool RenumberBlocks(MIRGraph& graph); bool -AccountForCFGChanges(MIRGenerator* mir, MIRGraph& graph, bool updateAliasAnalysis); +AccountForCFGChanges(MIRGenerator* mir, MIRGraph& graph, bool updateAliasAnalysis, + bool underValueNumberer = false); bool RemoveUnmarkedBlocks(MIRGenerator* mir, MIRGraph& graph, uint32_t numMarkedBlocks); @@ -81,7 +82,7 @@ void AssertGraphCoherency(MIRGraph& graph); void -AssertExtendedGraphCoherency(MIRGraph& graph); +AssertExtendedGraphCoherency(MIRGraph& graph, bool underValueNumberer = false); bool EliminateRedundantChecks(MIRGraph& graph); diff --git a/js/src/jit/MIRGraph.h b/js/src/jit/MIRGraph.h index cc2375b29c..c43797b85b 100644 --- a/js/src/jit/MIRGraph.h +++ b/js/src/jit/MIRGraph.h @@ -429,7 +429,11 @@ class MBasicBlock : public TempObject, public InlineListNode bool hasUniqueBackedge() const { MOZ_ASSERT(isLoopHeader()); MOZ_ASSERT(numPredecessors() >= 2); - return numPredecessors() == 2; + if (numPredecessors() == 2) + return true; + if (numPredecessors() == 3) // fixup block added by ValueNumbering phase. + return getPredecessor(1)->numPredecessors() == 0; + return false; } MBasicBlock* backedge() const { MOZ_ASSERT(hasUniqueBackedge()); @@ -476,6 +480,9 @@ class MBasicBlock : public TempObject, public InlineListNode } void unmark() { MOZ_ASSERT(mark_, "Unarking unmarked block"); + unmarkUnchecked(); + } + void unmarkUnchecked() { mark_ = false; } diff --git a/js/src/jit/ValueNumbering.cpp b/js/src/jit/ValueNumbering.cpp index a8d4a7a307..b9bad2944c 100644 --- a/js/src/jit/ValueNumbering.cpp +++ b/js/src/jit/ValueNumbering.cpp @@ -520,14 +520,12 @@ ValueNumberer::removePredecessorAndCleanUp(MBasicBlock* block, MBasicBlock* pred // If this is a loop header, test whether it will become an unreachable // loop, or whether it needs special OSR-related fixups. bool isUnreachableLoop = false; - MBasicBlock* origBackedgeForOSRFixup = nullptr; if (block->isLoopHeader()) { if (block->loopPredecessor() == pred) { if (MOZ_UNLIKELY(hasNonDominatingPredecessor(block, pred))) { JitSpew(JitSpew_GVN, " " "Loop with header block%u is now only reachable through an " "OSR entry into the middle of the loop!!", block->id()); - origBackedgeForOSRFixup = block->backedge(); } else { // Deleting the entry into the loop makes the loop unreachable. isUnreachableLoop = true; @@ -606,11 +604,6 @@ ValueNumberer::removePredecessorAndCleanUp(MBasicBlock* block, MBasicBlock* pred // Use the mark to note that we've already removed all its predecessors, // and we know it's unreachable. block->mark(); - } else if (MOZ_UNLIKELY(origBackedgeForOSRFixup != nullptr)) { - // The loop is no only reachable through OSR into the middle. Fix it - // up so that the CFG can remain valid. - if (!fixupOSROnlyLoop(block, origBackedgeForOSRFixup)) - return false; } return true; @@ -1079,6 +1072,30 @@ ValueNumberer::visitGraph() return true; } +bool +ValueNumberer::insertOSRFixups() +{ + ReversePostorderIterator end(graph_.end()); + for (ReversePostorderIterator iter(graph_.begin()); iter != end; ) { + MBasicBlock* block = *iter++; + + // Only add fixup block above for loops which can be reached from OSR. + if (!block->isLoopHeader()) + continue; + + // If the loop header is not self-dominated, then this loop does not + // have to deal with a second entry point, so there is no need to add a + // second entry point with a fixup block. + if (block->immediateDominator() != block) + continue; + + if (!fixupOSROnlyLoop(block, block->backedge())) + return false; + } + + return true; +} + // OSR fixups serve the purpose of representing the non-OSR entry into a loop // when the only real entry is an OSR entry into the middle. However, if the // entry into the middle is subsequently folded away, the loop may actually @@ -1101,22 +1118,44 @@ bool ValueNumberer::cleanupOSRFixups() succ->mark(); if (!worklist.append(succ)) return false; + } else if (succ->isLoopHeader() && + succ->loopPredecessor() == block && + succ->numPredecessors() == 3) + { + // Unmark fixup blocks if the loop predecessor is marked after + // the loop header. + succ->getPredecessor(1)->unmarkUnchecked(); } } - // The one special thing we do during this mark pass is to mark - // loop predecessors of reachable blocks as reachable. These blocks are - // the OSR fixups blocks which need to remain if the loop remains, - // though they can be removed if the loop is removed. + + // OSR fixup blocks are needed if and only if the loop header is + // reachable from its backedge (via the OSR block) and not from its + // original loop predecessor. + // + // Thus OSR fixup blocks are removed if the loop header is not + // reachable, or if the loop header is reachable from both its backedge + // and its original loop predecessor. if (block->isLoopHeader()) { - MBasicBlock* pred = block->loopPredecessor(); - if (!pred->isMarked() && pred->numPredecessors() == 0) { - MOZ_ASSERT(pred->numSuccessors() == 1, + MBasicBlock* maybeFixupBlock = nullptr; + if (block->numPredecessors() == 2) { + maybeFixupBlock = block->getPredecessor(0); + } else { + MOZ_ASSERT(block->numPredecessors() == 3); + if (!block->loopPredecessor()->isMarked()) + maybeFixupBlock = block->getPredecessor(1); + } + + if (maybeFixupBlock && + !maybeFixupBlock->isMarked() && + maybeFixupBlock->numPredecessors() == 0) + { + MOZ_ASSERT(maybeFixupBlock->numSuccessors() == 1, "OSR fixup block should have exactly one successor"); - MOZ_ASSERT(pred != graph_.entryBlock(), + MOZ_ASSERT(maybeFixupBlock != graph_.entryBlock(), "OSR fixup block shouldn't be the entry block"); - MOZ_ASSERT(pred != graph_.osrBlock(), + MOZ_ASSERT(maybeFixupBlock != graph_.osrBlock(), "OSR fixup block shouldn't be the OSR entry block"); - pred->mark(); + maybeFixupBlock->mark(); } } } @@ -1159,6 +1198,11 @@ ValueNumberer::run(UpdateAliasAnalysisFlag updateAliasAnalysis) JitSpew(JitSpew_GVN, "Running GVN on graph (with %llu blocks)", uint64_t(graph_.numBlocks())); + // Adding fixup blocks only make sense iff we have a second entry point into + // the graph which cannot be reached any more from the entry point. + if (graph_.osrBlock()) + insertOSRFixups(); + // Top level non-sparse iteration loop. If an iteration performs a // significant change, such as discarding a block which changes the // dominator tree and may enable more optimization, this loop takes another @@ -1182,7 +1226,7 @@ ValueNumberer::run(UpdateAliasAnalysisFlag updateAliasAnalysis) } if (blocksRemoved_) { - if (!AccountForCFGChanges(mir_, graph_, dependenciesBroken_)) + if (!AccountForCFGChanges(mir_, graph_, dependenciesBroken_, /* underValueNumberer = */ true)) return false; blocksRemoved_ = false; diff --git a/js/src/jit/ValueNumbering.h b/js/src/jit/ValueNumbering.h index 5e6fe5816d..bbb088f38a 100644 --- a/js/src/jit/ValueNumbering.h +++ b/js/src/jit/ValueNumbering.h @@ -101,6 +101,8 @@ class ValueNumberer bool visitBlock(MBasicBlock* block, const MBasicBlock* root); bool visitDominatorTree(MBasicBlock* root); bool visitGraph(); + + bool insertOSRFixups(); bool cleanupOSRFixups(); public: diff --git a/js/src/jsapi-tests/testForceLexicalInitialization.cpp b/js/src/jsapi-tests/testForceLexicalInitialization.cpp index 48e4a65004..15c8158123 100644 --- a/js/src/jsapi-tests/testForceLexicalInitialization.cpp +++ b/js/src/jsapi-tests/testForceLexicalInitialization.cpp @@ -13,24 +13,24 @@ BEGIN_TEST(testForceLexicalInitialization) { // Attach an uninitialized lexical to a scope and ensure that it's // set to undefined - RootedGlobalObject g(cx, cx->global()); - Rooted scope(cx, ClonedBlockObject::createGlobal(cx, g)); + js::RootedGlobalObject g(cx, cx->global()); + JS::Rooted scope(cx, js::ClonedBlockObject::createGlobal(cx, g)); - RootedValue uninitialized(cx, MagicValue(JS_UNINITIALIZED_LEXICAL)); - RootedPropertyName name(cx, Atomize(cx, "foopi", 4)->asPropertyName()); - RootedId id(cx, NameToId(name)); + JS::RootedValue uninitialized(cx, JS::MagicValue(JS_UNINITIALIZED_LEXICAL)); + js::RootedPropertyName name(cx, Atomize(cx, "foopi", 4)->asPropertyName()); + JS::RootedId id(cx, NameToId(name)); unsigned attrs = JSPROP_ENUMERATE | JSPROP_PERMANENT; NativeDefineProperty(cx, scope, id, uninitialized, nullptr, nullptr, attrs); // Verify that "foopi" is uninitialized - const Value v = scope->getSlot(scope->lookup(cx, id)->slot()); + const JS::Value v = scope->getSlot(scope->lookup(cx, id)->slot()); CHECK(v.isMagic(JS_UNINITIALIZED_LEXICAL)); ForceLexicalInitialization(cx, scope); // Verify that "foopi" has been initialized to undefined - const Value v2 = scope->getSlot(scope->lookup(cx, id)->slot()); + const JS::Value v2 = scope->getSlot(scope->lookup(cx, id)->slot()); CHECK(v2.isUndefined()); return true; diff --git a/js/src/jsapi-tests/testWasmLEB128.cpp b/js/src/jsapi-tests/testWasmLEB128.cpp index 0a4471dc06..3ef4d2fe4b 100644 --- a/js/src/jsapi-tests/testWasmLEB128.cpp +++ b/js/src/jsapi-tests/testWasmLEB128.cpp @@ -8,7 +8,7 @@ #include "jsapi-tests/tests.h" -static bool WriteValidBytes(wasm::Encoder& encoder, bool* passed) +static bool WriteValidBytes(js::wasm::Encoder& encoder, bool* passed) { *passed = false; if (!encoder.empty()) @@ -40,6 +40,7 @@ static bool WriteValidBytes(wasm::Encoder& encoder, bool* passed) BEGIN_TEST(testWasmLEB128_encoding) { + using namespace js; using namespace wasm; Bytes bytes; @@ -69,6 +70,7 @@ END_TEST(testWasmLEB128_encoding) BEGIN_TEST(testWasmLEB128_valid_decoding) { + using namespace js; using namespace wasm; Bytes bytes; @@ -119,6 +121,7 @@ END_TEST(testWasmLEB128_valid_decoding) BEGIN_TEST(testWasmLEB128_invalid_decoding) { + using namespace js; using namespace wasm; Bytes bytes; diff --git a/js/src/jsapi-tests/testXDR.cpp b/js/src/jsapi-tests/testXDR.cpp index a28cc464d4..24676953be 100644 --- a/js/src/jsapi-tests/testXDR.cpp +++ b/js/src/jsapi-tests/testXDR.cpp @@ -139,7 +139,7 @@ BEGIN_TEST(testXDR_sourceMap) CHECK(script); size_t len = strlen(*sm); - UniqueTwoByteChars expected_wrapper(js::InflateString(cx, *sm, &len)); + JS::UniqueTwoByteChars expected_wrapper(js::InflateString(cx, *sm, &len)); char16_t *expected = expected_wrapper.get(); CHECK(expected); diff --git a/js/src/jsscript.h b/js/src/jsscript.h index e86dbbad7b..440be3138f 100644 --- a/js/src/jsscript.h +++ b/js/src/jsscript.h @@ -254,6 +254,7 @@ class Bindings } public: + static const uint32_t BODY_LEVEL_LEXICAL_LIMIT = UINT16_LIMIT; static const uint32_t BLOCK_SCOPED_LIMIT = UINT16_LIMIT; @@ -362,7 +363,6 @@ class Bindings static_assert(sizeof(Bindings) % js::gc::CellSize == 0, "Size of Bindings must be an integral multiple of js::gc::CellSize"); - template class BindingsOperations { @@ -437,12 +437,26 @@ class MutableBindingsOperations : public BindingsOperations void setBindingArray(const Binding* bindingArray, uintptr_t temporaryBit) { bindings().bindingArrayAndFlag_ = uintptr_t(bindingArray) | temporaryBit; } - void setNumArgs(uint16_t num) { bindings().numArgs_ = num; } - void setNumVars(uint32_t num) { bindings().numVars_ = num; } - void setNumBodyLevelLexicals(uint16_t num) { bindings().numBodyLevelLexicals_ = num; } - void setNumBlockScoped(uint16_t num) { bindings().numBlockScoped_ = num; } - void setNumUnaliasedVars(uint32_t num) { bindings().numUnaliasedVars_ = num; } - void setNumUnaliasedBodyLevelLexicals(uint16_t num) { + void setNumArgs(uint32_t num) { + MOZ_ASSERT(num <= UINT16_MAX); + bindings().numArgs_ = num; + } + void setNumVars(uint32_t num) { + bindings().numVars_ = num; + } + void setNumBodyLevelLexicals(uint32_t num) { + MOZ_ASSERT(num <= UINT16_MAX); + bindings().numBodyLevelLexicals_ = num; + } + void setNumBlockScoped(uint32_t num) { + MOZ_ASSERT(num <= UINT16_MAX); + bindings().numBlockScoped_ = num; + } + void setNumUnaliasedVars(uint32_t num) { + bindings().numUnaliasedVars_ = num; + } + void setNumUnaliasedBodyLevelLexicals(uint32_t num) { + MOZ_ASSERT(num <= UINT16_MAX); bindings().numUnaliasedBodyLevelLexicals_ = num; } void setAliasedBodyLevelLexicalBegin(uint32_t offset) { diff --git a/js/src/tests/ecma_6/LexicalEnvironment/var-in-catch-body-annex-b.js b/js/src/tests/ecma_6/LexicalEnvironment/var-in-catch-body-annex-b.js index 95eeafa406..fd8ca41de7 100644 --- a/js/src/tests/ecma_6/LexicalEnvironment/var-in-catch-body-annex-b.js +++ b/js/src/tests/ecma_6/LexicalEnvironment/var-in-catch-body-annex-b.js @@ -42,6 +42,17 @@ assertThrowsInstanceOf(function () { `); }, SyntaxError); +// Tests that redeclaring a var inside the catch is not allowed if there's a +// body-level lexical. +assertThrowsInstanceOf(function () { + eval(` + let x; + try {} catch (x) { + var x; + } + `); +}, SyntaxError); + var log = ''; var x = 'global-x'; diff --git a/js/src/tests/ecma_6/Object/destructuring-shorthand-defaults.js b/js/src/tests/ecma_6/Object/destructuring-shorthand-defaults.js index 480d6b1006..09adc77199 100644 --- a/js/src/tests/ecma_6/Object/destructuring-shorthand-defaults.js +++ b/js/src/tests/ecma_6/Object/destructuring-shorthand-defaults.js @@ -38,6 +38,7 @@ const SYNTAX_ERROR_STMTS = [ "delete ({x=1})", "delete {x=1} = {}", "({x=1}.abc)", + "x > (0, {a = b} );", // declarations "var x = 0 + {a=1} = {}", "let o = {x=1};", diff --git a/js/src/tests/ecma_6/Statements/property-reference-self-assignment.js b/js/src/tests/ecma_6/Statements/property-reference-self-assignment.js new file mode 100644 index 0000000000..81c95b9cfb --- /dev/null +++ b/js/src/tests/ecma_6/Statements/property-reference-self-assignment.js @@ -0,0 +1,38 @@ +var hits = 0; + +var p = { toString() { hits++; return "prop" } }; +var obj = { foo: 1 }; + + +var ops = [["obj[p]++", 2], + ["++obj[p]", 2], + ["--obj[p]", 0], + ["obj[p]--", 0], + ["obj[p] += 2", 3], + ["obj[p] -= 2", -1], + ["obj[p] *= 2", 2], + ["obj[p] /= 2", 0.5], + ["obj[p] %= 2", 1], + ["obj[p] >>>= 2", 0], + ["obj[p] >>= 2", 0], + ["obj[p] <<= 2", 4], + ["obj[p] |= 2", 3], + ["obj[p] ^= 2", 3], + ["obj[p] &= 2", 0]]; + +var testHits = 0; +for (let op of ops) { + // Seed the value for each test. + obj.prop = 1; + + // Do the operation. + eval(op[0]); + assertEq(obj.prop, op[1]); + + // We should always call toString once, for each operation. + testHits++; + assertEq(hits, testHits); +} + +if (typeof reportCompare === 'function') + reportCompare(0,0,"OK"); diff --git a/js/src/threading/ExclusiveData.h b/js/src/threading/ExclusiveData.h index eac8473548..5d991b2b13 100644 --- a/js/src/threading/ExclusiveData.h +++ b/js/src/threading/ExclusiveData.h @@ -7,6 +7,7 @@ #ifndef threading_ExclusiveData_h #define threading_ExclusiveData_h +#include "mozilla/Alignment.h" #include "mozilla/Maybe.h" #include "mozilla/Move.h" @@ -80,7 +81,7 @@ template class ExclusiveData { mutable Mutex lock_; - mutable T value_; + mutable mozilla::AlignedStorage2 value_; ExclusiveData(const ExclusiveData&) = delete; ExclusiveData& operator=(const ExclusiveData&) = delete; @@ -94,15 +95,19 @@ class ExclusiveData * value. */ template - explicit ExclusiveData(U&& u) - : value_(mozilla::Forward(u)) - { + explicit ExclusiveData(U&& u) { + new (value_.addr()) T(mozilla::Forward(u)); } - ExclusiveData(ExclusiveData&& rhs) - : value_(mozilla::Move(rhs.value_)) - { + ~ExclusiveData() { + acquire(); + value_.addr()->~T(); + release(); + } + + ExclusiveData(ExclusiveData&& rhs) { MOZ_ASSERT(&rhs != this, "self-move disallowed!"); + new (value_.addr()) T(mozilla::Move(*rhs.value_.addr())); } ExclusiveData& operator=(ExclusiveData&& rhs) { @@ -148,7 +153,7 @@ class ExclusiveData T& get() const { MOZ_ASSERT(parent_); - return parent_->value_; + return *parent_->value_.addr(); } operator T& () const { return get(); } diff --git a/js/src/vm/DateTime.h b/js/src/vm/DateTime.h index d9726fc554..3c3445bdc0 100644 --- a/js/src/vm/DateTime.h +++ b/js/src/vm/DateTime.h @@ -119,7 +119,7 @@ class DateTimeInfo } }; - friend bool ::JS_Init(); + friend const char* ::JS_InitWithFailureDiagnostic(); // Initialize global date/time tracking state. This operation occurs // during, and is restricted to, SpiderMonkey initialization. diff --git a/js/src/vm/GeneratorObject.cpp b/js/src/vm/GeneratorObject.cpp index 548e6aa283..16d0f97a77 100644 --- a/js/src/vm/GeneratorObject.cpp +++ b/js/src/vm/GeneratorObject.cpp @@ -295,7 +295,9 @@ GlobalObject::initStarGenerators(JSContext* cx, Handle global) if (!iteratorProto) return false; - RootedPlainObject genObjectProto(cx, NewObjectWithGivenProto(cx, iteratorProto)); + RootedObject genObjectProto(cx, global->createBlankPrototypeInheriting(cx, + &PlainObject::class_, + iteratorProto)); if (!genObjectProto) return false; if (!DefinePropertiesAndFunctions(cx, genObjectProto, nullptr, star_generator_methods)) diff --git a/js/src/vm/Initialization.cpp b/js/src/vm/Initialization.cpp index e510822662..9086f35dda 100644 --- a/js/src/vm/Initialization.cpp +++ b/js/src/vm/Initialization.cpp @@ -59,8 +59,8 @@ CheckMessageParameterCounts() } #endif /* DEBUG */ -JS_PUBLIC_API(bool) -JS_Init(void) +JS_PUBLIC_API(const char*) +JS_InitWithFailureDiagnostic(void) { MOZ_ASSERT(libraryInitState == InitState::Uninitialized, "must call JS_Init once before any JSAPI operation except " @@ -76,18 +76,18 @@ JS_Init(void) using js::TlsPerThreadData; if (!TlsPerThreadData.init()) - return false; + return "JS_InitWithFailureDiagnostic: TlsPerThreadData.init() failed"; #if defined(DEBUG) || defined(JS_OOM_BREAKPOINT) if (!js::oom::InitThreadType()) - return false; + return "JS_InitWithFailureDiagnostic: js::oom::InitThreadType() failed"; js::oom::SetThreadType(js::oom::THREAD_TYPE_MAIN); #endif js::jit::ExecutableAllocator::initStatic(); if (!js::jit::InitializeIon()) - return false; + return "JS_InitWithFailureDiagnostic: js::jit::InitializeIon() failed"; js::DateTimeInfo::init(); @@ -95,20 +95,27 @@ JS_Init(void) UErrorCode err = U_ZERO_ERROR; u_init(&err); if (U_FAILURE(err)) - return false; + return "JS_InitWithFailureDiagnostic: u_init() failed"; #endif // EXPOSE_INTL_API if (!js::CreateHelperThreadsState()) - return false; + return "JS_InitWithFailureDiagnostic: js::CreateHelperThreadState() failed"; if (!FutexRuntime::initialize()) - return false; + return "JS_InitWithFailureDiagnostic: FutexRuntime::initialize() failed"; if (!js::gcstats::Statistics::initialize()) - return false; + return "JS_InitWithFailureDiagnostic: js::gcstats::Statistics::initialize() failed"; libraryInitState = InitState::Running; - return true; + return nullptr; +} + +JS_PUBLIC_API(bool) +JS_Init(void) +{ + const char* failure = JS_InitWithFailureDiagnostic(); + return !failure; } JS_PUBLIC_API(void) diff --git a/js/src/vm/Runtime.cpp b/js/src/vm/Runtime.cpp index c39c4368f6..d8ca042eb5 100644 --- a/js/src/vm/Runtime.cpp +++ b/js/src/vm/Runtime.cpp @@ -205,7 +205,7 @@ JSRuntime::JSRuntime(JSRuntime* parentRuntime) canUseSignalHandlers_(false), defaultFreeOp_(thisFromCtor()), debuggerMutations(0), - securityCallbacks(const_cast(&NullSecurityCallbacks)), + securityCallbacks(&NullSecurityCallbacks), DOMcallbacks(nullptr), destroyPrincipals(nullptr), readPrincipals(nullptr), @@ -698,9 +698,7 @@ JSRuntime::getDefaultLocale() if (defaultLocale) return defaultLocale; - char* locale; - char* lang; - char* p; + const char* locale; #ifdef HAVE_SETLOCALE locale = setlocale(LC_ALL, nullptr); #else @@ -708,10 +706,13 @@ JSRuntime::getDefaultLocale() #endif // convert to a well-formed BCP 47 language tag if (!locale || !strcmp(locale, "C")) - locale = const_cast("und"); - lang = JS_strdup(this, locale); + locale = "und"; + + char* lang = JS_strdup(this, locale); if (!lang) return nullptr; + + char* p; if ((p = strchr(lang, '.'))) *p = '\0'; while ((p = strchr(lang, '_'))) diff --git a/js/src/vm/SavedStacks.cpp b/js/src/vm/SavedStacks.cpp index 0510dccb3c..bf4e6d20a4 100644 --- a/js/src/vm/SavedStacks.cpp +++ b/js/src/vm/SavedStacks.cpp @@ -895,7 +895,7 @@ IsSavedFrame(JSObject* obj) if (!obj) return false; - JSObject* unwrapped = CheckedUnwrap(obj); + JSObject* unwrapped = js::CheckedUnwrap(obj); if (!unwrapped) return false; diff --git a/js/src/vm/ScopeObject.h b/js/src/vm/ScopeObject.h index 5438a6bc85..d41eb8f0b3 100644 --- a/js/src/vm/ScopeObject.h +++ b/js/src/vm/ScopeObject.h @@ -141,8 +141,10 @@ class StaticBlockScope : public NestedStaticScope /* Return the number of variables associated with this block. */ uint32_t numVariables() const { - // TODO: propertyCount() is O(n), use O(1) lastProperty()->slot() instead - return propertyCount(); + uint32_t num = 0; + if (!lastProperty()->isEmptyShape()) + num = lastProperty()->slot() + 1 - RESERVED_SLOTS; + return num; } private: diff --git a/js/src/vm/TaggedProto.cpp b/js/src/vm/TaggedProto.cpp index 9230889acc..a7c79aff27 100644 --- a/js/src/vm/TaggedProto.cpp +++ b/js/src/vm/TaggedProto.cpp @@ -12,6 +12,8 @@ #include "gc/Barrier.h" #include "gc/Zone.h" +#include "vm/Runtime-inl.h" + namespace js { /* static */ void diff --git a/js/src/vm/UbiNodeCensus.cpp b/js/src/vm/UbiNodeCensus.cpp index 197db246a0..3eda7fecf7 100644 --- a/js/src/vm/UbiNodeCensus.cpp +++ b/js/src/vm/UbiNodeCensus.cpp @@ -10,6 +10,8 @@ #include "jscompartment.h" #include "jsobjinlines.h" +#include "vm/NativeObject-inl.h" + using namespace js; namespace JS { diff --git a/js/src/vm/UnboxedObject.cpp b/js/src/vm/UnboxedObject.cpp index 1b5d0a914c..90d7bff987 100644 --- a/js/src/vm/UnboxedObject.cpp +++ b/js/src/vm/UnboxedObject.cpp @@ -698,6 +698,7 @@ UnboxedPlainObject::createWithProperties(ExclusiveContext* cx, HandleObjectGroup #ifndef JS_CODEGEN_NONE if (cx->isJSContext() && + !group->unknownProperties() && !layout.constructorCode() && cx->asJSContext()->runtime()->jitSupportsFloatingPoint) { diff --git a/layout/base/RestyleManager.cpp b/layout/base/RestyleManager.cpp index ad31bfc8eb..bd4eaf1e9c 100644 --- a/layout/base/RestyleManager.cpp +++ b/layout/base/RestyleManager.cpp @@ -570,7 +570,7 @@ static bool HasBoxAncestor(nsIFrame* aFrame) { for (nsIFrame* f = aFrame; f; f = f->GetParent()) { - if (f->IsBoxFrame()) { + if (f->IsXULBoxFrame()) { return true; } } @@ -1117,6 +1117,8 @@ RestyleManager::AnimationsWithDestroyedFrame::StopAnimationsWithoutFrame( { nsAnimationManager* animationManager = mRestyleManager->PresContext()->AnimationManager(); + nsTransitionManager* transitionManager = + mRestyleManager->PresContext()->TransitionManager(); for (nsIContent* content : aArray) { if (content->GetPrimaryFrame()) { continue; @@ -1124,6 +1126,7 @@ RestyleManager::AnimationsWithDestroyedFrame::StopAnimationsWithoutFrame( dom::Element* element = content->AsElement(); animationManager->StopAnimationsForElement(element, aPseudoType); + transitionManager->StopTransitionsForElement(element, aPseudoType); } } diff --git a/layout/base/RestyleManager.h b/layout/base/RestyleManager.h index f58b95f129..299d0aca65 100644 --- a/layout/base/RestyleManager.h +++ b/layout/base/RestyleManager.h @@ -250,8 +250,8 @@ public: nsStyleContext* aOldStyleContext, RefPtr* aNewStyleContext /* inout */); - // AnimationsWithDestroyedFrame is used to stop animations on elements that - // have no frame at the end of the restyling process. + // AnimationsWithDestroyedFrame is used to stop animations and transitions + // on elements that have no frame at the end of the restyling process. // It only lives during the restyling process. class MOZ_STACK_CLASS AnimationsWithDestroyedFrame final { public: @@ -260,13 +260,10 @@ public: // object. (This is generally easy since the caller is typically a // method of RestyleManager.) explicit AnimationsWithDestroyedFrame(RestyleManager* aRestyleManager); - ~AnimationsWithDestroyedFrame() - { - } // This method takes the content node for the generated content for - // animation on ::before and ::after, rather than the content node for - // the real element. + // animation/transition on ::before and ::after, rather than the + // content node for the real element. void Put(nsIContent* aContent, nsStyleContext* aStyleContext) { MOZ_ASSERT(aContent); CSSPseudoElementType pseudoType = aStyleContext->GetPseudoType(); @@ -291,7 +288,7 @@ public: AutoRestore mRestorePointer; // Below three arrays might include elements that have already had their - // animations stopped. + // animations or transitions stopped. // // mBeforeContents and mAfterContents hold the real element rather than // the content node for the generated content (which might change during diff --git a/layout/base/RestyleTracker.cpp b/layout/base/RestyleTracker.cpp index db2aa51a5f..ce30dd6644 100644 --- a/layout/base/RestyleTracker.cpp +++ b/layout/base/RestyleTracker.cpp @@ -123,8 +123,8 @@ RestyleTracker::DoProcessRestyles() bool isTimelineRecording = timelines && timelines->HasConsumer(docShell); // Create a AnimationsWithDestroyedFrame during restyling process to - // stop animations on elements that have no frame at the end of the - // restyling process. + // stop animations and transitions on elements that have no frame at the end + // of the restyling process. RestyleManager::AnimationsWithDestroyedFrame animationsWithDestroyedFrame(mRestyleManager); diff --git a/layout/base/nsCSSFrameConstructor.cpp b/layout/base/nsCSSFrameConstructor.cpp index f09cf22c3e..52adf69589 100644 --- a/layout/base/nsCSSFrameConstructor.cpp +++ b/layout/base/nsCSSFrameConstructor.cpp @@ -425,7 +425,7 @@ static bool ShouldSuppressFloatingOfDescendants(nsIFrame* aFrame) { return aFrame->IsFrameOfType(nsIFrame::eMathML) || - aFrame->IsBoxFrame() || + aFrame->IsXULBoxFrame() || ::IsFlexOrGridContainer(aFrame); } @@ -8345,7 +8345,7 @@ nsCSSFrameConstructor::ContentRemoved(nsIContent* aContainer, // (If we're in the XUL block-wrapping situation, parentFrame is the // wrapper frame.) nsIFrame* grandparentFrame = parentFrame->GetParent(); - if (grandparentFrame && grandparentFrame->IsBoxFrame() && + if (grandparentFrame && grandparentFrame->IsXULBoxFrame() && (grandparentFrame->GetStateBits() & NS_STATE_BOX_WRAPS_KIDS_IN_BLOCK) && // check if this frame is the only one needing wrapping aChild == AnyKidsNeedBlockParent(parentFrame->PrincipalChildList().FirstChild()) && @@ -10486,6 +10486,49 @@ void nsCSSFrameConstructor::CreateNeededPseudoSiblings( iter.InsertItem(newItem); } +#ifdef DEBUG +static bool +FrameWantsToBeInAnonymousItem(const nsIAtom* aParentType, const nsIFrame* aFrame) +{ + // Note: This needs to match the logic in + // nsCSSFrameConstructor::FrameConstructionItem::NeedsAnonFlexOrGridItem() + if (aParentType == nsGkAtoms::gridContainerFrame) { + return aFrame->IsFrameOfType(nsIFrame::eLineParticipant); + } + MOZ_ASSERT(aParentType == nsGkAtoms::flexContainerFrame); + return aFrame->IsFrameOfType(nsIFrame::eLineParticipant) || + aFrame->GetType() == nsGkAtoms::placeholderFrame; +} +#endif + +static void +VerifyGridFlexContainerChildren(nsIFrame* aParentFrame, + const nsFrameList& aChildren) +{ +#ifdef DEBUG + auto parentType = aParentFrame->GetType(); + if (parentType != nsGkAtoms::flexContainerFrame && + parentType != nsGkAtoms::gridContainerFrame) { + return; + } + + bool prevChildWasAnonItem = false; + for (const nsIFrame* child : aChildren) { + MOZ_ASSERT(!FrameWantsToBeInAnonymousItem(parentType, child), + "frame wants to be inside an anonymous item, but it isn't"); + if (IsAnonymousFlexOrGridItem(child)) { + AssertAnonymousFlexOrGridItemParent(child, aParentFrame); + MOZ_ASSERT(!prevChildWasAnonItem, "two anon items in a row"); + nsIFrame* firstWrappedChild = child->PrincipalChildList().FirstChild(); + MOZ_ASSERT(firstWrappedChild, "anonymous item shouldn't be empty"); + prevChildWasAnonItem = true; + } else { + prevChildWasAnonItem = false; + } + } +#endif +} + inline void nsCSSFrameConstructor::ConstructFramesFromItemList(nsFrameConstructorState& aState, FrameConstructionItemList& aItems, @@ -10504,6 +10547,7 @@ nsCSSFrameConstructor::ConstructFramesFromItemList(nsFrameConstructorState& aSta ConstructFramesFromItem(aState, iter, aParentFrame, aFrameItems); } + VerifyGridFlexContainerChildren(aParentFrame, aFrameItems); NS_ASSERTION(!aState.mHavePendingPopupgroup, "Should have proccessed it by now"); } @@ -10703,7 +10747,7 @@ nsCSSFrameConstructor::ProcessChildren(nsFrameConstructorState& aState, ConstructFramesFromItemList(aState, itemsToConstruct, aFrame, aFrameItems); - NS_ASSERTION(!aAllowBlockStyles || !aFrame->IsBoxFrame(), + NS_ASSERTION(!aAllowBlockStyles || !aFrame->IsXULBoxFrame(), "can't be both block and box"); if (haveFirstLetterStyle) { @@ -10716,15 +10760,15 @@ nsCSSFrameConstructor::ProcessChildren(nsFrameConstructorState& aState, // We might end up with first-line frames that change // AnyKidsNeedBlockParent() without changing itemsToConstruct, but that - // should never happen for cases whan aFrame->IsBoxFrame(). - NS_ASSERTION(!haveFirstLineStyle || !aFrame->IsBoxFrame(), + // should never happen for cases whan aFrame->IsXULBoxFrame(). + NS_ASSERTION(!haveFirstLineStyle || !aFrame->IsXULBoxFrame(), "Shouldn't have first-line style if we're a box"); - NS_ASSERTION(!aFrame->IsBoxFrame() || + NS_ASSERTION(!aFrame->IsXULBoxFrame() || itemsToConstruct.AnyItemsNeedBlockParent() == (AnyKidsNeedBlockParent(aFrameItems.FirstChild()) != nullptr), "Something went awry in our block parent calculations"); - if (aFrame->IsBoxFrame() && itemsToConstruct.AnyItemsNeedBlockParent()) { + if (aFrame->IsXULBoxFrame() && itemsToConstruct.AnyItemsNeedBlockParent()) { // XXXbz we could do this on the FrameConstructionItemList level, // no? And if we cared we could look through the item list // instead of groveling through the framelist here.. @@ -12061,7 +12105,7 @@ nsCSSFrameConstructor::WipeContainingBlock(nsFrameConstructorState& aState, // Situation #1 is a XUL frame that contains frames that are required // to be wrapped in blocks. - if (aFrame->IsBoxFrame() && + if (aFrame->IsXULBoxFrame() && !(aFrame->GetStateBits() & NS_STATE_BOX_WRAPS_KIDS_IN_BLOCK) && aItems.AnyItemsNeedBlockParent()) { RecreateFramesForContent(aFrame->GetContent(), true, diff --git a/layout/base/nsCSSRendering.cpp b/layout/base/nsCSSRendering.cpp index d3df3bda64..cadc7388b4 100644 --- a/layout/base/nsCSSRendering.cpp +++ b/layout/base/nsCSSRendering.cpp @@ -5519,21 +5519,6 @@ nsImageRenderer::IsAnimatedImage() return false; } -bool -nsImageRenderer::IsContainerAvailable(LayerManager* aManager, - nsDisplayListBuilder* aBuilder) -{ - if (mType != eStyleImageType_Image || !mImageContainer) { - return false; - } - - uint32_t flags = aBuilder->ShouldSyncDecodeImages() - ? imgIContainer::FLAG_SYNC_DECODE - : imgIContainer::FLAG_NONE; - - return mImageContainer->IsImageContainerAvailable(aManager, flags); -} - already_AddRefed nsImageRenderer::GetImage() { diff --git a/layout/base/nsCSSRendering.h b/layout/base/nsCSSRendering.h index 0520218220..d9f5be8fd2 100644 --- a/layout/base/nsCSSRendering.h +++ b/layout/base/nsCSSRendering.h @@ -252,16 +252,6 @@ public: bool IsRasterImage(); bool IsAnimatedImage(); - /** - * @return true if this nsImageRenderer wraps an image which has an - * ImageContainer available. - * - * If IsContainerAvailable() returns true, GetImage() will return a non-null - * imgIContainer which callers can use to retrieve the ImageContainer. - */ - bool IsContainerAvailable(LayerManager* aManager, - nsDisplayListBuilder* aBuilder); - /// Retrieves the image associated with this nsImageRenderer, if there is one. already_AddRefed GetImage(); diff --git a/layout/base/nsDisplayList.cpp b/layout/base/nsDisplayList.cpp index 0e1740f3a2..ef581d9fad 100644 --- a/layout/base/nsDisplayList.cpp +++ b/layout/base/nsDisplayList.cpp @@ -1941,7 +1941,7 @@ void nsDisplayList::DeleteAll() { static bool GetMouseThrough(const nsIFrame* aFrame) { - if (!aFrame->IsBoxFrame()) + if (!aFrame->IsXULBoxFrame()) return false; const nsIFrame* frame = aFrame; @@ -1951,7 +1951,7 @@ GetMouseThrough(const nsIFrame* aFrame) } else if (frame->GetStateBits() & NS_FRAME_MOUSE_THROUGH_NEVER) { return false; } - frame = nsBox::GetParentBox(frame); + frame = nsBox::GetParentXULBox(frame); } return false; } @@ -2348,32 +2348,33 @@ nsDisplayBackgroundImage::nsDisplayBackgroundImage(nsDisplayListBuilder* aBuilde : nsDisplayImageContainer(aBuilder, aFrame) , mBackgroundStyle(aBackgroundStyle) , mLayer(aLayer) + , mIsRasterImage(false) { MOZ_COUNT_CTOR(nsDisplayBackgroundImage); mBounds = GetBoundsInternal(aBuilder); - mDestArea = GetDestAreaInternal(aBuilder); if (ShouldFixToViewport(aBuilder)) { mAnimatedGeometryRoot = aBuilder->FindAnimatedGeometryRootFor(this); } -} - -nsRect -nsDisplayBackgroundImage::GetDestAreaInternal(nsDisplayListBuilder* aBuilder) -{ - if (!mBackgroundStyle) { - return nsRect(); - } - + nsPresContext* presContext = mFrame->PresContext(); uint32_t flags = aBuilder->GetBackgroundPaintFlags(); nsRect borderArea = nsRect(ToReferenceFrame(), mFrame->GetSize()); - const nsStyleImageLayers::Layer& layer = mBackgroundStyle->mImage.mLayers[mLayer]; + const nsStyleImageLayers::Layer &layer = mBackgroundStyle->mImage.mLayers[mLayer]; nsBackgroundLayerState state = nsCSSRendering::PrepareImageLayer(presContext, mFrame, flags, borderArea, borderArea, layer); - return state.mDestArea; + + mFillRect = state.mFillArea; + mDestRect = state.mDestArea; + + nsImageRenderer* imageRenderer = &state.mImageRenderer; + // We only care about images here, not gradients. + if (imageRenderer->IsRasterImage()) { + mIsRasterImage = true; + mImage = imageRenderer->GetImage(); + } } nsDisplayBackgroundImage::~nsDisplayBackgroundImage() @@ -2606,24 +2607,16 @@ nsDisplayBackgroundImage::IsSingleFixedPositionImage(nsDisplayListBuilder* aBuil if (mBackgroundStyle->mImage.mLayers.Length() != 1) return false; - nsPresContext* presContext = mFrame->PresContext(); - uint32_t flags = aBuilder->GetBackgroundPaintFlags(); - nsRect borderArea = nsRect(ToReferenceFrame(), mFrame->GetSize()); const nsStyleImageLayers::Layer &layer = mBackgroundStyle->mImage.mLayers[mLayer]; - if (layer.mAttachment != NS_STYLE_IMAGELAYER_ATTACHMENT_FIXED) return false; - nsBackgroundLayerState state = - nsCSSRendering::PrepareImageLayer(presContext, mFrame, flags, - borderArea, aClipRect, layer); - nsImageRenderer* imageRenderer = &state.mImageRenderer; // We only care about images here, not gradients. - if (!imageRenderer->IsRasterImage()) + if (!mIsRasterImage) return false; - int32_t appUnitsPerDevPixel = presContext->AppUnitsPerDevPixel(); - *aDestRect = nsLayoutUtils::RectToGfxRect(state.mFillArea, appUnitsPerDevPixel); + int32_t appUnitsPerDevPixel = mFrame->PresContext()->AppUnitsPerDevPixel(); + *aDestRect = nsLayoutUtils::RectToGfxRect(mFillRect, appUnitsPerDevPixel); return true; } @@ -2658,75 +2651,35 @@ nsDisplayBackgroundImage::CanOptimizeToImageLayer(LayerManager* aManager, return false; } - nsPresContext* presContext = mFrame->PresContext(); - uint32_t flags = aBuilder->GetBackgroundPaintFlags(); - nsRect borderArea = nsRect(ToReferenceFrame(), mFrame->GetSize()); - const nsStyleImageLayers::Layer &layer = mBackgroundStyle->mImage.mLayers[mLayer]; - - nsBackgroundLayerState state = - nsCSSRendering::PrepareImageLayer(presContext, mFrame, flags, - borderArea, borderArea, layer); - nsImageRenderer* imageRenderer = &state.mImageRenderer; - // We only care about images here, not gradients. - if (!imageRenderer->IsRasterImage()) { - return false; - } - - if (!imageRenderer->IsContainerAvailable(aManager, aBuilder)) { - // The image is not ready to be made into a layer yet. - return false; - } - // We currently can't handle tiled backgrounds. - if (!state.mDestArea.Contains(state.mFillArea)) { + if (!mDestRect.Contains(mFillRect)) { return false; } // For 'contain' and 'cover', we allow any pixel of the image to be sampled // because there isn't going to be any spriting/atlasing going on. + const nsStyleImageLayers::Layer &layer = mBackgroundStyle->mImage.mLayers[mLayer]; bool allowPartialImages = (layer.mSize.mWidthType == nsStyleImageLayers::Size::eContain || layer.mSize.mWidthType == nsStyleImageLayers::Size::eCover); - if (!allowPartialImages && !state.mFillArea.Contains(state.mDestArea)) { + if (!allowPartialImages && !mFillRect.Contains(mDestRect)) { return false; } - // XXX Ignoring state.mAnchor. ImageLayer drawing snaps mDestArea edges to - // layer pixel boundaries. This should be OK for now. - - int32_t appUnitsPerDevPixel = presContext->AppUnitsPerDevPixel(); - mImageLayerDestRect = - LayoutDeviceRect::FromAppUnits(state.mDestArea, appUnitsPerDevPixel); - - // Ok, we can turn this into a layer if needed. - mImage = imageRenderer->GetImage(); - MOZ_ASSERT(mImage); - - return true; + return nsDisplayImageContainer::CanOptimizeToImageLayer(aManager, aBuilder); } -already_AddRefed -nsDisplayBackgroundImage::GetContainer(LayerManager* aManager, - nsDisplayListBuilder *aBuilder) +nsRect +nsDisplayBackgroundImage::GetDestRect() { - if (!mImage) { - MOZ_ASSERT_UNREACHABLE("Must call CanOptimizeToImage() and get true " - "before calling GetContainer()"); - return nullptr; - } + return mDestRect; +} - if (!mImageContainer) { - // We don't have an ImageContainer yet; get it from mImage. - - uint32_t flags = aBuilder->ShouldSyncDecodeImages() - ? imgIContainer::FLAG_SYNC_DECODE - : imgIContainer::FLAG_NONE; - - mImageContainer = mImage->GetImageContainer(aManager, flags); - } - - RefPtr container = mImageContainer; - return container.forget(); +already_AddRefed +nsDisplayBackgroundImage::GetImage() +{ + nsCOMPtr image = mImage; + return image.forget(); } nsDisplayBackgroundImage::ImageLayerization @@ -2787,8 +2740,11 @@ nsDisplayBackgroundImage::GetLayerState(nsDisplayListBuilder* aBuilder, mImage->GetWidth(&imageWidth); mImage->GetHeight(&imageHeight); NS_ASSERTION(imageWidth != 0 && imageHeight != 0, "Invalid image size!"); + + int32_t appUnitsPerDevPixel = mFrame->PresContext()->AppUnitsPerDevPixel(); + LayoutDeviceRect destRect = LayoutDeviceRect::FromAppUnits(GetDestRect(), appUnitsPerDevPixel); - const LayerRect destLayerRect = mImageLayerDestRect * aParameters.Scale(); + const LayerRect destLayerRect = destRect * aParameters.Scale(); // Calculate the scaling factor for the frame. const gfxSize scale = gfxSize(destLayerRect.width / imageWidth, @@ -2824,51 +2780,6 @@ nsDisplayBackgroundImage::BuildLayer(nsDisplayListBuilder* aBuilder, return layer.forget(); } -void -nsDisplayBackgroundImage::ConfigureLayer(ImageLayer* aLayer, - const ContainerLayerParameters& aParameters) -{ - aLayer->SetFilter(nsLayoutUtils::GetGraphicsFilterForFrame(mFrame)); - - MOZ_ASSERT(mImage); - int32_t imageWidth; - int32_t imageHeight; - mImage->GetWidth(&imageWidth); - mImage->GetHeight(&imageHeight); - NS_ASSERTION(imageWidth != 0 && imageHeight != 0, "Invalid image size!"); - - if (imageWidth > 0 && imageHeight > 0) { - // We're actually using the ImageContainer. Let our frame know that it - // should consider itself to have painted successfully. - nsDisplayBackgroundGeometry::UpdateDrawResult(this, - image::DrawResult::SUCCESS); - } - - // XXX(seth): Right now we ignore aParameters.Scale() and - // aParameters.Offset(), because FrameLayerBuilder already applies - // aParameters.Scale() via the layer's post-transform, and - // aParameters.Offset() is always zero. - MOZ_ASSERT(aParameters.Offset() == LayerIntPoint(0,0)); - - // It's possible (for example, due to downscale-during-decode) that the - // ImageContainer this ImageLayer is holding has a different size from the - // intrinsic size of the image. For this reason we compute the transform using - // the ImageContainer's size rather than the image's intrinsic size. - // XXX(seth): In reality, since the size of the ImageContainer may change - // asynchronously, this is not enough. Bug 1183378 will provide a more - // complete fix, but this solution is safe in more cases than simply relying - // on the intrinsic size. - IntSize containerSize = aLayer->GetContainer() - ? aLayer->GetContainer()->GetCurrentSize() - : IntSize(imageWidth, imageHeight); - - const LayoutDevicePoint p = mImageLayerDestRect.TopLeft(); - Matrix transform = Matrix::Translation(p.x, p.y); - transform.PreScale(mImageLayerDestRect.width / containerSize.width, - mImageLayerDestRect.height / containerSize.height); - aLayer->SetBaseTransform(gfx::Matrix4x4::From2D(transform)); -} - void nsDisplayBackgroundImage::HitTest(nsDisplayListBuilder* aBuilder, const nsRect& aRect, @@ -3079,7 +2990,7 @@ void nsDisplayBackgroundImage::ComputeInvalidationRegion(nsDisplayListBuilder* a } return; } - if (!mDestArea.IsEqualInterior(geometry->mDestArea)) { + if (!mDestRect.IsEqualInterior(geometry->mDestRect)) { // Dest area changed in a way that could cause everything to change, // so invalidate everything (both old and new painting areas). aInvalidRegion->Or(bounds, geometry->mBounds); @@ -3305,6 +3216,118 @@ nsDisplayThemedBackground::GetBoundsInternal() { return r + ToReferenceFrame(); } +void +nsDisplayImageContainer::ConfigureLayer(ImageLayer* aLayer, + const ContainerLayerParameters& aParameters) +{ + aLayer->SetFilter(nsLayoutUtils::GetGraphicsFilterForFrame(mFrame)); + + nsCOMPtr image = GetImage(); + MOZ_ASSERT(image); + int32_t imageWidth; + int32_t imageHeight; + image->GetWidth(&imageWidth); + image->GetHeight(&imageHeight); + NS_ASSERTION(imageWidth != 0 && imageHeight != 0, "Invalid image size!"); + + if (imageWidth > 0 && imageHeight > 0) { + // We're actually using the ImageContainer. Let our frame know that it + // should consider itself to have painted successfully. + nsDisplayBackgroundGeometry::UpdateDrawResult(this, + image::DrawResult::SUCCESS); + } + + // XXX(seth): Right now we ignore aParameters.Scale() and + // aParameters.Offset(), because FrameLayerBuilder already applies + // aParameters.Scale() via the layer's post-transform, and + // aParameters.Offset() is always zero. + MOZ_ASSERT(aParameters.Offset() == LayerIntPoint(0,0)); + + // It's possible (for example, due to downscale-during-decode) that the + // ImageContainer this ImageLayer is holding has a different size from the + // intrinsic size of the image. For this reason we compute the transform using + // the ImageContainer's size rather than the image's intrinsic size. + // XXX(seth): In reality, since the size of the ImageContainer may change + // asynchronously, this is not enough. Bug 1183378 will provide a more + // complete fix, but this solution is safe in more cases than simply relying + // on the intrinsic size. + IntSize containerSize = aLayer->GetContainer() + ? aLayer->GetContainer()->GetCurrentSize() + : IntSize(imageWidth, imageHeight); + + const int32_t factor = mFrame->PresContext()->AppUnitsPerDevPixel(); + const LayoutDeviceRect destRect = + LayoutDeviceRect::FromAppUnits(GetDestRect(), factor); + + const LayoutDevicePoint p = destRect.TopLeft(); + Matrix transform = Matrix::Translation(p.x, p.y); + transform.PreScale(destRect.width / containerSize.width, + destRect.height / containerSize.height); + aLayer->SetBaseTransform(gfx::Matrix4x4::From2D(transform)); +} + +already_AddRefed +nsDisplayImageContainer::GetContainer(LayerManager* aManager, + nsDisplayListBuilder *aBuilder) +{ + nsCOMPtr image = GetImage(); + if (!image) { + MOZ_ASSERT_UNREACHABLE("Must call CanOptimizeToImage() and get true " + "before calling GetContainer()"); + return nullptr; + } + + uint32_t flags = aBuilder->ShouldSyncDecodeImages() + ? imgIContainer::FLAG_SYNC_DECODE + : imgIContainer::FLAG_NONE; + + return image->GetImageContainer(aManager, flags); +} + +bool +nsDisplayImageContainer::CanOptimizeToImageLayer(LayerManager* aManager, + nsDisplayListBuilder* aBuilder) +{ + uint32_t flags = aBuilder->ShouldSyncDecodeImages() + ? imgIContainer::FLAG_SYNC_DECODE + : imgIContainer::FLAG_NONE; + + nsCOMPtr image = GetImage(); + if (!image) { + return false; + } + + if (!image->IsImageContainerAvailable(aManager, flags)) { + return false; + } + + int32_t imageWidth; + int32_t imageHeight; + image->GetWidth(&imageWidth); + image->GetHeight(&imageHeight); + + if (imageWidth == 0 || imageHeight == 0) { + NS_ASSERTION(false, "invalid image size"); + return false; + } + + const int32_t factor = mFrame->PresContext()->AppUnitsPerDevPixel(); + const LayoutDeviceRect destRect = + LayoutDeviceRect::FromAppUnits(GetDestRect(), factor); + + // Calculate the scaling factor for the frame. + const gfxSize scale = gfxSize(destRect.width / imageWidth, + destRect.height / imageHeight); + + if (scale.width < 0.2 || scale.height < 0.2) { + // This would look awful as long as we can't use high-quality downscaling + // for image layers (bug 803703), so don't turn this into an image layer. + return false; + } + + return true; +} + void nsDisplayBackgroundColor::ApplyOpacity(nsDisplayListBuilder* aBuilder, float aOpacity, diff --git a/layout/base/nsDisplayList.h b/layout/base/nsDisplayList.h index ddaff9c880..af7ea1421a 100644 --- a/layout/base/nsDisplayList.h +++ b/layout/base/nsDisplayList.h @@ -2330,12 +2330,16 @@ public: * CanOptimizeToImageLayer() first and it returned true. */ virtual bool CanOptimizeToImageLayer(LayerManager* aManager, - nsDisplayListBuilder* aBuilder) = 0; + nsDisplayListBuilder* aBuilder); - virtual already_AddRefed GetContainer(LayerManager* aManager, - nsDisplayListBuilder* aBuilder) = 0; - virtual void ConfigureLayer(ImageLayer* aLayer, - const ContainerLayerParameters& aParameters) = 0; + already_AddRefed GetContainer(LayerManager* aManager, + nsDisplayListBuilder* aBuilder); + void ConfigureLayer(ImageLayer* aLayer, + const ContainerLayerParameters& aParameters); + + virtual already_AddRefed GetImage() = 0; + + virtual nsRect GetDestRect() = 0; virtual bool SupportsOptimizingToImage() override { return true; } }; @@ -2705,11 +2709,6 @@ public: */ nsRect GetPositioningArea(); - /** - * Return the destination area of one instance of the image. - */ - nsRect GetDestArea() const { return mDestArea; } - /** * Returns true if existing rendered pixels of this display item may need * to be redrawn if the positioning area size changes but its position does @@ -2730,10 +2729,8 @@ public: virtual bool CanOptimizeToImageLayer(LayerManager* aManager, nsDisplayListBuilder* aBuilder) override; - virtual already_AddRefed GetContainer(LayerManager* aManager, - nsDisplayListBuilder *aBuilder) override; - virtual void ConfigureLayer(ImageLayer* aLayer, - const ContainerLayerParameters& aParameters) override; + virtual already_AddRefed GetImage() override; + virtual nsRect GetDestRect() override; static nsRegion GetInsideClipRegion(nsDisplayItem* aItem, uint8_t aClip, const nsRect& aRect); @@ -2750,7 +2747,6 @@ protected: gfxRect* aDestRect); bool IsNonEmptyFixedImage() const; nsRect GetBoundsInternal(nsDisplayListBuilder* aBuilder); - nsRect GetDestAreaInternal(nsDisplayListBuilder* aBuilder); void PaintInternal(nsDisplayListBuilder* aBuilder, nsRenderingContext* aCtx, const nsRect& aBounds, nsRect* aClipRect); @@ -2769,12 +2765,12 @@ protected: // mIsThemed is true or if FindBackground returned false. const nsStyleBackground* mBackgroundStyle; nsCOMPtr mImage; - RefPtr mImageContainer; - LayoutDeviceRect mImageLayerDestRect; + nsRect mFillRect; + nsRect mDestRect; /* Bounds of this display item */ nsRect mBounds; - nsRect mDestArea; uint32_t mLayer; + bool mIsRasterImage; }; diff --git a/layout/base/nsDisplayListInvalidation.cpp b/layout/base/nsDisplayListInvalidation.cpp index 38951dd8c6..32fc372bef 100644 --- a/layout/base/nsDisplayListInvalidation.cpp +++ b/layout/base/nsDisplayListInvalidation.cpp @@ -63,7 +63,7 @@ nsDisplayBackgroundGeometry::nsDisplayBackgroundGeometry(nsDisplayBackgroundImag : nsDisplayItemGeometry(aItem, aBuilder) , nsImageGeometryMixin(aItem, aBuilder) , mPositioningArea(aItem->GetPositioningArea()) - , mDestArea(aItem->GetDestArea()) + , mDestRect(aItem->GetDestRect()) {} void @@ -71,7 +71,7 @@ nsDisplayBackgroundGeometry::MoveBy(const nsPoint& aOffset) { nsDisplayItemGeometry::MoveBy(aOffset); mPositioningArea.MoveBy(aOffset); - mDestArea.MoveBy(aOffset); + mDestRect.MoveBy(aOffset); } nsDisplayThemedBackgroundGeometry::nsDisplayThemedBackgroundGeometry(nsDisplayThemedBackground* aItem, diff --git a/layout/base/nsDisplayListInvalidation.h b/layout/base/nsDisplayListInvalidation.h index 319913b11f..59404ceba2 100644 --- a/layout/base/nsDisplayListInvalidation.h +++ b/layout/base/nsDisplayListInvalidation.h @@ -194,7 +194,7 @@ public: virtual void MoveBy(const nsPoint& aOffset) override; nsRect mPositioningArea; - nsRect mDestArea; + nsRect mDestRect; }; class nsDisplayThemedBackgroundGeometry : public nsDisplayItemGeometry diff --git a/layout/forms/nsTextControlFrame.cpp b/layout/forms/nsTextControlFrame.cpp index 49d4ff7e20..9b9ce48574 100644 --- a/layout/forms/nsTextControlFrame.cpp +++ b/layout/forms/nsTextControlFrame.cpp @@ -477,7 +477,7 @@ nsTextControlFrame::ComputeAutoSize(nsRenderingContext *aRenderingContext, aCBSize, aAvailableISize, aMargin, aBorder, aPadding, aShrinkWrap); - // Disabled when there's inflation; see comment in GetPrefSize. + // Disabled when there's inflation; see comment in GetXULPrefSize. MOZ_ASSERT(inflation != 1.0f || ancestorAutoSize.ISize(aWM) == autoSize.ISize(aWM), "Incorrect size computed by ComputeAutoSize?"); @@ -586,14 +586,14 @@ nsTextControlFrame::ReflowTextControlChild(nsIFrame* aKid, } nsSize -nsTextControlFrame::GetMinSize(nsBoxLayoutState& aState) +nsTextControlFrame::GetXULMinSize(nsBoxLayoutState& aState) { // XXXbz why? Why not the nsBoxFrame sizes? - return nsBox::GetMinSize(aState); + return nsBox::GetXULMinSize(aState); } bool -nsTextControlFrame::IsCollapsed() +nsTextControlFrame::IsXULCollapsed() { // We're never collapsed in the box sense. return false; diff --git a/layout/forms/nsTextControlFrame.h b/layout/forms/nsTextControlFrame.h index 9e12342cf1..47795a76b0 100644 --- a/layout/forms/nsTextControlFrame.h +++ b/layout/forms/nsTextControlFrame.h @@ -62,8 +62,8 @@ public: const nsHTMLReflowState& aReflowState, nsReflowStatus& aStatus) override; - virtual nsSize GetMinSize(nsBoxLayoutState& aBoxLayoutState) override; - virtual bool IsCollapsed() override; + virtual nsSize GetXULMinSize(nsBoxLayoutState& aBoxLayoutState) override; + virtual bool IsXULCollapsed() override; virtual bool IsLeaf() const override; diff --git a/layout/generic/crashtests/1233191.html b/layout/generic/crashtests/1233191.html new file mode 100644 index 0000000000..6a6a06edf9 --- /dev/null +++ b/layout/generic/crashtests/1233191.html @@ -0,0 +1,9 @@ + + + +
yx
+
yx
+
yx
+
yx
+ + diff --git a/layout/generic/crashtests/crashtests.list b/layout/generic/crashtests/crashtests.list index 962e58748d..fccfcbd37f 100644 --- a/layout/generic/crashtests/crashtests.list +++ b/layout/generic/crashtests/crashtests.list @@ -611,3 +611,4 @@ load details-display-none-summary-3.html load 1304441.html pref(dom.details_element.enabled,true) load summary-position-out-of-flow.html asserts(4) load 1225005.html # bug 682647 and bug 448083 +load 1233191.html diff --git a/layout/generic/nsContainerFrame.cpp b/layout/generic/nsContainerFrame.cpp index b7c2967d02..48d598098e 100644 --- a/layout/generic/nsContainerFrame.cpp +++ b/layout/generic/nsContainerFrame.cpp @@ -704,8 +704,8 @@ nsContainerFrame::SyncWindowProperties(nsPresContext* aPresContext, } nsBoxLayoutState aState(aPresContext, aRC); - nsSize minSize = rootFrame->GetMinSize(aState); - nsSize maxSize = rootFrame->GetMaxSize(aState); + nsSize minSize = rootFrame->GetXULMinSize(aState); + nsSize maxSize = rootFrame->GetXULMaxSize(aState); SetSizeConstraints(aPresContext, windowWidget, minSize, maxSize); #endif diff --git a/layout/generic/nsFlexContainerFrame.cpp b/layout/generic/nsFlexContainerFrame.cpp index a53f065d4d..b7b2ad0b1b 100644 --- a/layout/generic/nsFlexContainerFrame.cpp +++ b/layout/generic/nsFlexContainerFrame.cpp @@ -2032,54 +2032,6 @@ nsFlexContainerFrame::BuildDisplayList(nsDisplayListBuilder* aBuilder, } } -#ifdef DEBUG -// helper for the debugging method below -bool -FrameWantsToBeInAnonymousFlexItem(nsIFrame* aFrame) -{ - // Note: This needs to match the logic in - // nsCSSFrameConstructor::FrameConstructionItem::NeedsAnonFlexOrGridItem() - return (aFrame->IsFrameOfType(nsIFrame::eLineParticipant) || - nsGkAtoms::placeholderFrame == aFrame->GetType()); -} - -// Debugging method, to let us assert that our anonymous flex items are -// set up correctly -- in particular, we assert: -// (1) we don't have any inline non-replaced children -// (2) we don't have any consecutive anonymous flex items -// (3) we don't have any empty anonymous flex items -// -// XXXdholbert This matches what nsCSSFrameConstructor currently does, and what -// the spec used to say. However, the spec has now changed regarding what -// types of content get wrapped in an anonymous flexbox item. The patch that -// implements those changes (in nsCSSFrameConstructor) will need to change -// this method as well. -void -nsFlexContainerFrame::SanityCheckAnonymousFlexItems() const -{ - bool prevChildWasAnonFlexItem = false; - for (nsIFrame* child : mFrames) { - MOZ_ASSERT(!FrameWantsToBeInAnonymousFlexItem(child), - "frame wants to be inside an anonymous flex item, " - "but it isn't"); - if (child->StyleContext()->GetPseudo() == - nsCSSAnonBoxes::anonymousFlexItem) { - MOZ_ASSERT(!prevChildWasAnonFlexItem || - HasAnyStateBits(NS_STATE_FLEX_CHILDREN_REORDERED), - "two anon flex items in a row (shouldn't happen, unless our " - "children have been reordered with the 'order' property)"); - - nsIFrame* firstWrappedChild = child->PrincipalChildList().FirstChild(); - MOZ_ASSERT(firstWrappedChild, - "anonymous flex item is empty (shouldn't happen)"); - prevChildWasAnonFlexItem = true; - } else { - prevChildWasAnonFlexItem = false; - } - } -} -#endif // DEBUG - void FlexLine::FreezeItemsEarly(bool aIsUsingFlexGrow) { @@ -3677,10 +3629,6 @@ nsFlexContainerFrame::Reflow(nsPresContext* aPresContext, AddStateBits(NS_FRAME_CONTAINS_RELATIVE_BSIZE); } -#ifdef DEBUG - SanityCheckAnonymousFlexItems(); -#endif // DEBUG - // If we've never reordered our children, then we can trust that they're // already in DOM-order, and we only need to consider their "order" property // when checking them for sortedness & sorting them. diff --git a/layout/generic/nsFrame.cpp b/layout/generic/nsFrame.cpp index f41025d3fe..f6a29413e5 100644 --- a/layout/generic/nsFrame.cpp +++ b/layout/generic/nsFrame.cpp @@ -183,11 +183,11 @@ InitBoxMetrics(nsIFrame* aFrame, bool aClear) } static bool -IsBoxWrapped(const nsIFrame* aFrame) +IsXULBoxWrapped(const nsIFrame* aFrame) { return aFrame->GetParent() && - aFrame->GetParent()->IsBoxFrame() && - !aFrame->IsBoxFrame(); + aFrame->GetParent()->IsXULBoxFrame() && + !aFrame->IsXULBoxFrame(); } // Formerly the nsIFrameDebug interface @@ -497,7 +497,7 @@ IsFontSizeInflationContainer(nsIFrame* aFrame, nsGkAtoms::optgroup, nsGkAtoms::select) || content->IsInNativeAnonymousSubtree()))) && - !(aFrame->IsBoxFrame() && aFrame->GetParent()->IsBoxFrame()); + !(aFrame->IsXULBoxFrame() && aFrame->GetParent()->IsXULBoxFrame()); NS_ASSERTION(!aFrame->IsFrameOfType(nsIFrame::eLineParticipant) || isInline || // br frames and mathml frames report being line @@ -611,7 +611,7 @@ nsFrame::Init(nsIContent* aContent, DidSetStyleContext(nullptr); - if (::IsBoxWrapped(this)) + if (::IsXULBoxWrapped(this)) ::InitBoxMetrics(this, false); } @@ -710,9 +710,9 @@ nsFrame::DestroyFrom(nsIFrame* aDestructRoot) } } - if (HasCSSAnimations()) { + if (HasCSSAnimations() || HasCSSTransitions()) { // If no new frame for this element is created by the end of the - // restyling process, stop animations for this frame + // restyling process, stop animations and transitions for this frame if (presContext->RestyleManager()->IsGecko()) { RestyleManager::AnimationsWithDestroyedFrame* adf = presContext->RestyleManager()->AsGecko()->GetAnimationsWithDestroyedFrame(); @@ -4252,7 +4252,7 @@ nsFrame::MarkIntrinsicISizesDirty() { // This version is meant only for what used to be box-to-block adaptors. // It should not be called by other derived classes. - if (::IsBoxWrapped(this)) { + if (::IsXULBoxWrapped(this)) { nsBoxLayoutMetrics *metrics = BoxMetrics(); SizeNeedsRecalc(metrics->mPrefSize); @@ -5029,12 +5029,6 @@ nsIFrame::GetView() const return value; } -/* virtual */ nsView* -nsIFrame::GetViewExternal() const -{ - return GetView(); -} - nsresult nsIFrame::SetView(nsView* aView) { @@ -5068,11 +5062,6 @@ nsIFrame::SetView(nsView* aView) return NS_OK; } -nsIFrame* nsIFrame::GetAncestorWithViewExternal() const -{ - return GetAncestorWithView(); -} - // Find the first geometric parent that has a view nsIFrame* nsIFrame::GetAncestorWithView() const { @@ -5084,12 +5073,6 @@ nsIFrame* nsIFrame::GetAncestorWithView() const return nullptr; } -// virtual -nsPoint nsIFrame::GetOffsetToExternal(const nsIFrame* aOther) const -{ - return GetOffsetTo(aOther); -} - nsPoint nsIFrame::GetOffsetTo(const nsIFrame* aOther) const { NS_PRECONDITION(aOther, @@ -5179,23 +5162,11 @@ nsIFrame::GetOffsetToCrossDoc(const nsIFrame* aOther, const int32_t aAPD) const return offset; } -// virtual -nsIntRect nsIFrame::GetScreenRectExternal() const -{ - return GetScreenRect(); -} - nsIntRect nsIFrame::GetScreenRect() const { return GetScreenRectInAppUnits().ToNearestPixels(PresContext()->AppUnitsPerCSSPixel()); } -// virtual -nsRect nsIFrame::GetScreenRectInAppUnitsExternal() const -{ - return GetScreenRectInAppUnits(); -} - nsRect nsIFrame::GetScreenRectInAppUnits() const { nsPresContext* presContext = PresContext(); @@ -5920,7 +5891,7 @@ nsFrame::UpdateOverflow() nsOverflowAreas overflowAreas(rect, rect); if (!DoesClipChildren() && - !(IsCollapsed() && (IsBoxFrame() || ::IsBoxWrapped(this)))) { + !(IsXULCollapsed() && (IsXULBoxFrame() || ::IsXULBoxWrapped(this)))) { nsLayoutUtils::UnionChildOverflow(this, overflowAreas); } @@ -8008,7 +7979,7 @@ nsIFrame::FinishAndStoreOverflow(nsOverflowAreas& aOverflowAreas, // Note that NS_STYLE_OVERFLOW_CLIP doesn't clip the frame background, // so we add theme background overflow here so it's not clipped. - if (!::IsBoxWrapped(this) && IsThemed(disp)) { + if (!::IsXULBoxWrapped(this) && IsThemed(disp)) { nsRect r(bounds); nsPresContext *presContext = PresContext(); if (presContext->GetTheme()-> @@ -8655,7 +8626,7 @@ nsFrame::RefreshSizeCache(nsBoxLayoutState& aState) nsRect rect = GetRect(); nsMargin bp(0,0,0,0); - GetBorderAndPadding(bp); + GetXULBorderAndPadding(bp); { // If we're a container for font size inflation, then shrink @@ -8730,7 +8701,7 @@ nsFrame::GetLineIterator() } nsSize -nsFrame::GetPrefSize(nsBoxLayoutState& aState) +nsFrame::GetXULPrefSize(nsBoxLayoutState& aState) { nsSize size(0,0); DISPLAY_PREF_SIZE(this, size); @@ -8741,12 +8712,12 @@ nsFrame::GetPrefSize(nsBoxLayoutState& aState) return metrics->mPrefSize; } - if (IsCollapsed()) + if (IsXULCollapsed()) return size; // get our size in CSS. bool widthSet, heightSet; - bool completelyRedefined = nsIFrame::AddCSSPrefSize(this, size, widthSet, heightSet); + bool completelyRedefined = nsIFrame::AddXULPrefSize(this, size, widthSet, heightSet); // Refresh our caches with new sizes. if (!completelyRedefined) { @@ -8766,7 +8737,7 @@ nsFrame::GetPrefSize(nsBoxLayoutState& aState) } nsSize -nsFrame::GetMinSize(nsBoxLayoutState& aState) +nsFrame::GetXULMinSize(nsBoxLayoutState& aState) { nsSize size(0,0); DISPLAY_MIN_SIZE(this, size); @@ -8777,13 +8748,13 @@ nsFrame::GetMinSize(nsBoxLayoutState& aState) return size; } - if (IsCollapsed()) + if (IsXULCollapsed()) return size; // get our size in CSS. bool widthSet, heightSet; bool completelyRedefined = - nsIFrame::AddCSSMinSize(aState, this, size, widthSet, heightSet); + nsIFrame::AddXULMinSize(aState, this, size, widthSet, heightSet); // Refresh our caches with new sizes. if (!completelyRedefined) { @@ -8801,7 +8772,7 @@ nsFrame::GetMinSize(nsBoxLayoutState& aState) } nsSize -nsFrame::GetMaxSize(nsBoxLayoutState& aState) +nsFrame::GetXULMaxSize(nsBoxLayoutState& aState) { nsSize size(NS_INTRINSICSIZE, NS_INTRINSICSIZE); DISPLAY_MAX_SIZE(this, size); @@ -8812,35 +8783,35 @@ nsFrame::GetMaxSize(nsBoxLayoutState& aState) return size; } - if (IsCollapsed()) + if (IsXULCollapsed()) return size; - size = nsBox::GetMaxSize(aState); + size = nsBox::GetXULMaxSize(aState); metrics->mMaxSize = size; return size; } nscoord -nsFrame::GetFlex() +nsFrame::GetXULFlex() { nsBoxLayoutMetrics *metrics = BoxMetrics(); if (!DoesNeedRecalc(metrics->mFlex)) return metrics->mFlex; - metrics->mFlex = nsBox::GetFlex(); + metrics->mFlex = nsBox::GetXULFlex(); return metrics->mFlex; } nscoord -nsFrame::GetBoxAscent(nsBoxLayoutState& aState) +nsFrame::GetXULBoxAscent(nsBoxLayoutState& aState) { nsBoxLayoutMetrics *metrics = BoxMetrics(); if (!DoesNeedRecalc(metrics->mAscent)) return metrics->mAscent; - if (IsCollapsed()) { + if (IsXULCollapsed()) { metrics->mAscent = 0; } else { // Refresh our caches with new sizes. @@ -8852,7 +8823,7 @@ nsFrame::GetBoxAscent(nsBoxLayoutState& aState) } nsresult -nsFrame::DoLayout(nsBoxLayoutState& aState) +nsFrame::DoXULLayout(nsBoxLayoutState& aState) { nsRect ourRect(mRect); @@ -8869,7 +8840,7 @@ nsFrame::DoLayout(nsBoxLayoutState& aState) BoxReflow(aState, presContext, desiredSize, rendContext, ourRect.x, ourRect.y, ourRect.width, ourRect.height); - if (IsCollapsed()) { + if (IsXULCollapsed()) { SetSize(nsSize(0, 0)); } else { @@ -8880,7 +8851,7 @@ nsFrame::DoLayout(nsBoxLayoutState& aState) desiredSize.BSize(outerWM) > ourSize.BSize(outerWM)) { #ifdef DEBUG_GROW - DumpBox(stdout); + XULDumpBox(stdout); printf(" GREW from (%d,%d) -> (%d,%d)\n", ourSize.ISize(outerWM), ourSize.BSize(outerWM), desiredSize.ISize(outerWM), desiredSize.BSize(outerWM)); @@ -8901,7 +8872,7 @@ nsFrame::DoLayout(nsBoxLayoutState& aState) } } - // Should we do this if IsCollapsed() is true? + // Should we do this if IsXULCollapsed() is true? LogicalSize size(GetLogicalSize(outerWM)); desiredSize.ISize(outerWM) = size.ISize(outerWM); desiredSize.BSize(outerWM) = size.BSize(outerWM); @@ -9001,7 +8972,7 @@ nsFrame::BoxReflow(nsBoxLayoutState& aState, // Construct a bogus parent reflow state so that there's a usable // containing block reflow state. nsMargin margin(0,0,0,0); - GetMargin(margin); + GetXULMargin(margin); nsSize parentSize(aWidth, aHeight); if (parentSize.height != NS_INTRINSICSIZE) @@ -9026,8 +8997,8 @@ nsFrame::BoxReflow(nsBoxLayoutState& aState, parentReflowState.SetComputedHeight(std::max(parentSize.height, 0)); parentReflowState.ComputedPhysicalMargin().SizeTo(0, 0, 0, 0); // XXX use box methods - parentFrame->GetPadding(parentReflowState.ComputedPhysicalPadding()); - parentFrame->GetBorder(parentReflowState.ComputedPhysicalBorderPadding()); + parentFrame->GetXULPadding(parentReflowState.ComputedPhysicalPadding()); + parentFrame->GetXULBorder(parentReflowState.ComputedPhysicalBorderPadding()); parentReflowState.ComputedPhysicalBorderPadding() += parentReflowState.ComputedPhysicalPadding(); @@ -9097,7 +9068,7 @@ nsFrame::BoxReflow(nsBoxLayoutState& aState, } } - // Box layout calls SetRect before Layout, whereas non-box layout + // Box layout calls SetRect before XULLayout, whereas non-box layout // calls SetRect after Reflow. // XXX Perhaps we should be doing this by twiddling the rect back to // mLastSize before calling Reflow and then switching it back, but @@ -9136,7 +9107,7 @@ nsFrame::BoxReflow(nsBoxLayoutState& aState, &reflowState, aX, aY, layoutFlags | NS_FRAME_NO_MOVE_FRAME); // Save the ascent. (bug 103925) - if (IsCollapsed()) { + if (IsXULCollapsed()) { metrics->mAscent = 0; } else { if (aDesiredSize.BlockStartAscent() == @@ -9245,12 +9216,12 @@ nsIFrame::SetParent(nsContainerFrame* aParent) { // Note that the current mParent may already be destroyed at this point. mParent = aParent; - if (::IsBoxWrapped(this)) { + if (::IsXULBoxWrapped(this)) { ::InitBoxMetrics(this, true); } else { // We could call Properties().Delete(BoxMetricsProperty()); here but // that's kind of slow and re-parenting in such a way that we were - // IsBoxWrapped() before but not now should be very rare, so we'll just + // IsXULBoxWrapped() before but not now should be very rare, so we'll just // keep this unused frame property until this frame dies instead. } @@ -9382,6 +9353,14 @@ nsFrame::HasCSSAnimations() return collection && collection->mAnimations.Length() > 0; } +bool +nsFrame::HasCSSTransitions() +{ + auto collection = + AnimationCollection::GetAnimationCollection(this); + return collection && collection->mAnimations.Length() > 0; +} + // Box layout debugging #ifdef DEBUG_REFLOW int32_t gIndent2 = 0; @@ -10303,7 +10282,7 @@ void* nsFrame::DisplayLayoutEnter(nsIFrame* aFrame) DR_FrameTreeNode* treeNode = DR_state->CreateTreeNode(aFrame, nullptr); if (treeNode && treeNode->mDisplay) { DR_state->DisplayFrameTypeInfo(aFrame, treeNode->mIndent); - printf("Layout\n"); + printf("XULLayout\n"); } return treeNode; } @@ -10415,7 +10394,7 @@ void nsFrame::DisplayLayoutExit(nsIFrame* aFrame, if (treeNode->mDisplay) { DR_state->DisplayFrameTypeInfo(aFrame, treeNode->mIndent); nsRect rect = aFrame->GetRect(); - printf("Layout=%d,%d,%d,%d\n", rect.x, rect.y, rect.width, rect.height); + printf("XULLayout=%d,%d,%d,%d\n", rect.x, rect.y, rect.width, rect.height); } DR_state->DeleteTreeNode(*treeNode); } diff --git a/layout/generic/nsFrame.h b/layout/generic/nsFrame.h index fc3eea9820..24fa804f4e 100644 --- a/layout/generic/nsFrame.h +++ b/layout/generic/nsFrame.h @@ -408,11 +408,11 @@ public: virtual ContentOffsets CalcContentOffsetsFromFramePoint(nsPoint aPoint); // Box layout methods - virtual nsSize GetPrefSize(nsBoxLayoutState& aBoxLayoutState) override; - virtual nsSize GetMinSize(nsBoxLayoutState& aBoxLayoutState) override; - virtual nsSize GetMaxSize(nsBoxLayoutState& aBoxLayoutState) override; - virtual nscoord GetFlex() override; - virtual nscoord GetBoxAscent(nsBoxLayoutState& aBoxLayoutState) override; + virtual nsSize GetXULPrefSize(nsBoxLayoutState& aBoxLayoutState) override; + virtual nsSize GetXULMinSize(nsBoxLayoutState& aBoxLayoutState) override; + virtual nsSize GetXULMaxSize(nsBoxLayoutState& aBoxLayoutState) override; + virtual nscoord GetXULFlex() override; + virtual nscoord GetXULBoxAscent(nsBoxLayoutState& aBoxLayoutState) override; // We compute and store the HTML content's overflow area. So don't // try to compute it in the box code. @@ -651,7 +651,7 @@ protected: // Fills aCursor with the appropriate information from ui static void FillCursorInformationFromStyle(const nsStyleUserInterface* ui, nsIFrame::Cursor& aCursor); - NS_IMETHOD DoLayout(nsBoxLayoutState& aBoxLayoutState) override; + NS_IMETHOD DoXULLayout(nsBoxLayoutState& aBoxLayoutState) override; #ifdef DEBUG_LAYOUT virtual void GetBoxName(nsAutoString& aName) override; @@ -678,6 +678,9 @@ private: // Returns true if this frame has any kind of CSS animations. bool HasCSSAnimations(); + // Returns true if this frame has any kind of CSS transitions. + bool HasCSSTransitions(); + #ifdef DEBUG_FRAME_DUMP public: /** diff --git a/layout/generic/nsGfxScrollFrame.cpp b/layout/generic/nsGfxScrollFrame.cpp index abd8cd6626..3c0f725559 100644 --- a/layout/generic/nsGfxScrollFrame.cpp +++ b/layout/generic/nsGfxScrollFrame.cpp @@ -268,7 +268,7 @@ GetScrollbarMetrics(nsBoxLayoutState& aState, nsIFrame* aBox, nsSize* aMin, "computations"); if (aMin) { - *aMin = aBox->GetMinSize(aState); + *aMin = aBox->GetXULMinSize(aState); nsBox::AddMargin(aBox, *aMin); if (aMin->width < 0) { aMin->width = 0; @@ -279,7 +279,7 @@ GetScrollbarMetrics(nsBoxLayoutState& aState, nsIFrame* aBox, nsSize* aMin, } if (aPref) { - *aPref = aBox->GetPrefSize(aState); + *aPref = aBox->GetXULPrefSize(aState); nsBox::AddMargin(aBox, *aPref); if (aPref->width < 0) { aPref->width = 0; @@ -794,18 +794,18 @@ nsHTMLScrollFrame::GetPrefISize(nsRenderingContext *aRenderingContext) } nsresult -nsHTMLScrollFrame::GetPadding(nsMargin& aMargin) +nsHTMLScrollFrame::GetXULPadding(nsMargin& aMargin) { // Our padding hangs out on the inside of the scrollframe, but XUL doesn't // reaize that. If we're stuck inside a XUL box, we need to claim no // padding. - // @see also nsXULScrollFrame::GetPadding. + // @see also nsXULScrollFrame::GetXULPadding. aMargin.SizeTo(0,0,0,0); return NS_OK; } bool -nsHTMLScrollFrame::IsCollapsed() +nsHTMLScrollFrame::IsXULCollapsed() { // We're never collapsed in the box sense. return false; @@ -1009,7 +1009,7 @@ nsXULScrollFrame::nsXULScrollFrame(nsStyleContext* aContext, : nsBoxFrame(aContext, aIsRoot), mHelper(ALLOW_THIS_IN_INITIALIZER_LIST(this), aIsRoot) { - SetLayoutManager(nullptr); + SetXULLayoutManager(nullptr); mHelper.mClipAllDescendants = aClipAllDescendants; } @@ -1039,7 +1039,7 @@ ScrollFrameHelper::GetDesiredScrollbarSizes(nsBoxLayoutState* aState) nsMargin result(0, 0, 0, 0); if (mVScrollbarBox) { - nsSize size = mVScrollbarBox->GetPrefSize(*aState); + nsSize size = mVScrollbarBox->GetXULPrefSize(*aState); nsBox::AddMargin(mVScrollbarBox, size); if (IsScrollbarOnRight()) result.left = size.width; @@ -1048,7 +1048,7 @@ ScrollFrameHelper::GetDesiredScrollbarSizes(nsBoxLayoutState* aState) } if (mHScrollbarBox) { - nsSize size = mHScrollbarBox->GetPrefSize(*aState); + nsSize size = mHScrollbarBox->GetXULPrefSize(*aState); nsBox::AddMargin(mHScrollbarBox, size); // We don't currently support any scripts that would require a scrollbar // at the top. (Are there any?) @@ -1207,7 +1207,7 @@ void ScrollFrameHelper::ScrollByLine(nsScrollbarFrame* aScrollbar, int32_t aDirection, nsIScrollbarMediator::ScrollSnapMode aSnap) { - bool isHorizontal = aScrollbar->IsHorizontal(); + bool isHorizontal = aScrollbar->IsXULHorizontal(); nsIntPoint delta; if (isHorizontal) { const double kScrollMultiplier = @@ -1253,7 +1253,7 @@ ScrollFrameHelper::ThumbMoved(nsScrollbarFrame* aScrollbar, nscoord aNewPos) { MOZ_ASSERT(aScrollbar != nullptr); - bool isHorizontal = aScrollbar->IsHorizontal(); + bool isHorizontal = aScrollbar->IsXULHorizontal(); nsPoint current = GetScrollPosition(); nsPoint dest = current; if (isHorizontal) { @@ -1293,7 +1293,7 @@ ScrollFrameHelper::ScrollByUnit(nsScrollbarFrame* aScrollbar, nsIScrollbarMediator::ScrollSnapMode aSnap) { MOZ_ASSERT(aScrollbar != nullptr); - bool isHorizontal = aScrollbar->IsHorizontal(); + bool isHorizontal = aScrollbar->IsXULHorizontal(); nsIntPoint delta; if (isHorizontal) { delta.x = aDirection; @@ -1368,7 +1368,7 @@ nsXULScrollFrame::GetSplittableType() const } nsresult -nsXULScrollFrame::GetPadding(nsMargin& aMargin) +nsXULScrollFrame::GetXULPadding(nsMargin& aMargin) { aMargin.SizeTo(0,0,0,0); return NS_OK; @@ -1381,29 +1381,29 @@ nsXULScrollFrame::GetType() const } nscoord -nsXULScrollFrame::GetBoxAscent(nsBoxLayoutState& aState) +nsXULScrollFrame::GetXULBoxAscent(nsBoxLayoutState& aState) { if (!mHelper.mScrolledFrame) return 0; - nscoord ascent = mHelper.mScrolledFrame->GetBoxAscent(aState); + nscoord ascent = mHelper.mScrolledFrame->GetXULBoxAscent(aState); nsMargin m(0,0,0,0); - GetBorderAndPadding(m); + GetXULBorderAndPadding(m); ascent += m.top; - GetMargin(m); + GetXULMargin(m); ascent += m.top; return ascent; } nsSize -nsXULScrollFrame::GetPrefSize(nsBoxLayoutState& aState) +nsXULScrollFrame::GetXULPrefSize(nsBoxLayoutState& aState) { #ifdef DEBUG_LAYOUT PropagateDebug(aState); #endif - nsSize pref = mHelper.mScrolledFrame->GetPrefSize(aState); + nsSize pref = mHelper.mScrolledFrame->GetXULPrefSize(aState); ScrollbarStyles styles = GetScrollbarStyles(); @@ -1411,38 +1411,38 @@ nsXULScrollFrame::GetPrefSize(nsBoxLayoutState& aState) if (mHelper.mVScrollbarBox && styles.mVertical == NS_STYLE_OVERFLOW_SCROLL) { - nsSize vSize = mHelper.mVScrollbarBox->GetPrefSize(aState); + nsSize vSize = mHelper.mVScrollbarBox->GetXULPrefSize(aState); nsBox::AddMargin(mHelper.mVScrollbarBox, vSize); pref.width += vSize.width; } if (mHelper.mHScrollbarBox && styles.mHorizontal == NS_STYLE_OVERFLOW_SCROLL) { - nsSize hSize = mHelper.mHScrollbarBox->GetPrefSize(aState); + nsSize hSize = mHelper.mHScrollbarBox->GetXULPrefSize(aState); nsBox::AddMargin(mHelper.mHScrollbarBox, hSize); pref.height += hSize.height; } AddBorderAndPadding(pref); bool widthSet, heightSet; - nsIFrame::AddCSSPrefSize(this, pref, widthSet, heightSet); + nsIFrame::AddXULPrefSize(this, pref, widthSet, heightSet); return pref; } nsSize -nsXULScrollFrame::GetMinSize(nsBoxLayoutState& aState) +nsXULScrollFrame::GetXULMinSize(nsBoxLayoutState& aState) { #ifdef DEBUG_LAYOUT PropagateDebug(aState); #endif - nsSize min = mHelper.mScrolledFrame->GetMinSizeForScrollArea(aState); + nsSize min = mHelper.mScrolledFrame->GetXULMinSizeForScrollArea(aState); ScrollbarStyles styles = GetScrollbarStyles(); if (mHelper.mVScrollbarBox && styles.mVertical == NS_STYLE_OVERFLOW_SCROLL) { - nsSize vSize = mHelper.mVScrollbarBox->GetMinSize(aState); + nsSize vSize = mHelper.mVScrollbarBox->GetXULMinSize(aState); AddMargin(mHelper.mVScrollbarBox, vSize); min.width += vSize.width; if (min.height < vSize.height) @@ -1451,7 +1451,7 @@ nsXULScrollFrame::GetMinSize(nsBoxLayoutState& aState) if (mHelper.mHScrollbarBox && styles.mHorizontal == NS_STYLE_OVERFLOW_SCROLL) { - nsSize hSize = mHelper.mHScrollbarBox->GetMinSize(aState); + nsSize hSize = mHelper.mHScrollbarBox->GetXULMinSize(aState); AddMargin(mHelper.mHScrollbarBox, hSize); min.height += hSize.height; if (min.width < hSize.width) @@ -1460,12 +1460,12 @@ nsXULScrollFrame::GetMinSize(nsBoxLayoutState& aState) AddBorderAndPadding(min); bool widthSet, heightSet; - nsIFrame::AddCSSMinSize(aState, this, min, widthSet, heightSet); + nsIFrame::AddXULMinSize(aState, this, min, widthSet, heightSet); return min; } nsSize -nsXULScrollFrame::GetMaxSize(nsBoxLayoutState& aState) +nsXULScrollFrame::GetXULMaxSize(nsBoxLayoutState& aState) { #ifdef DEBUG_LAYOUT PropagateDebug(aState); @@ -1475,7 +1475,7 @@ nsXULScrollFrame::GetMaxSize(nsBoxLayoutState& aState) AddBorderAndPadding(maxSize); bool widthSet, heightSet; - nsIFrame::AddCSSMaxSize(this, maxSize, widthSet, heightSet); + nsIFrame::AddXULMaxSize(this, maxSize, widthSet, heightSet); return maxSize; } @@ -1488,13 +1488,13 @@ nsXULScrollFrame::GetFrameName(nsAString& aResult) const #endif NS_IMETHODIMP -nsXULScrollFrame::DoLayout(nsBoxLayoutState& aState) +nsXULScrollFrame::DoXULLayout(nsBoxLayoutState& aState) { uint32_t flags = aState.LayoutFlags(); - nsresult rv = Layout(aState); + nsresult rv = XULLayout(aState); aState.SetLayoutFlags(flags); - nsBox::DoLayout(aState); + nsBox::DoXULLayout(aState); return rv; } @@ -4590,7 +4590,7 @@ nsXULScrollFrame::AddRemoveScrollbar(nsBoxLayoutState& aState, if (mHelper.mNeverHasHorizontalScrollbar || !mHelper.mHScrollbarBox) return false; - nsSize hSize = mHelper.mHScrollbarBox->GetPrefSize(aState); + nsSize hSize = mHelper.mHScrollbarBox->GetXULPrefSize(aState); nsBox::AddMargin(mHelper.mHScrollbarBox, hSize); mHelper.SetScrollbarVisibility(mHelper.mHScrollbarBox, aAdd); @@ -4609,7 +4609,7 @@ nsXULScrollFrame::AddRemoveScrollbar(nsBoxLayoutState& aState, if (mHelper.mNeverHasVerticalScrollbar || !mHelper.mVScrollbarBox) return false; - nsSize vSize = mHelper.mVScrollbarBox->GetPrefSize(aState); + nsSize vSize = mHelper.mVScrollbarBox->GetXULPrefSize(aState); nsBox::AddMargin(mHelper.mVScrollbarBox, vSize); mHelper.SetScrollbarVisibility(mHelper.mVScrollbarBox, aAdd); @@ -4668,7 +4668,7 @@ nsXULScrollFrame::LayoutScrollArea(nsBoxLayoutState& aState, mHelper.mScrollPort.Size()); int32_t flags = NS_FRAME_NO_MOVE_VIEW; - nsSize minSize = mHelper.mScrolledFrame->GetMinSize(aState); + nsSize minSize = mHelper.mScrolledFrame->GetXULMinSize(aState); if (minSize.height > childRect.height) childRect.height = minSize.height; @@ -4678,7 +4678,7 @@ nsXULScrollFrame::LayoutScrollArea(nsBoxLayoutState& aState, aState.SetLayoutFlags(flags); ClampAndSetBounds(aState, childRect, aScrollPosition); - mHelper.mScrolledFrame->Layout(aState); + mHelper.mScrolledFrame->XULLayout(aState); childRect = mHelper.mScrolledFrame->GetRect(); @@ -4813,14 +4813,14 @@ ScrollFrameHelper::IsScrollingActive(nsDisplayListBuilder* aBuilder) const * cause any of the scrollbars to need to be reflowed. */ nsresult -nsXULScrollFrame::Layout(nsBoxLayoutState& aState) +nsXULScrollFrame::XULLayout(nsBoxLayoutState& aState) { bool scrollbarRight = IsScrollbarOnRight(); bool scrollbarBottom = true; // get the content rect nsRect clientRect(0,0,0,0); - GetClientRect(clientRect); + GetXULClientRect(clientRect); nsRect oldScrollAreaBounds = mHelper.mScrollPort; nsPoint oldScrollPosition = mHelper.GetLogicalScrollPosition(); @@ -5304,7 +5304,7 @@ ScrollFrameHelper::LayoutScrollbars(nsBoxLayoutState& aState, // place the scrollcorner if (mScrollCornerBox || mResizerBox) { - NS_PRECONDITION(!mScrollCornerBox || mScrollCornerBox->IsBoxFrame(), "Must be a box frame!"); + NS_PRECONDITION(!mScrollCornerBox || mScrollCornerBox->IsXULBoxFrame(), "Must be a box frame!"); nsRect r(0, 0, 0, 0); if (aContentArea.x != mScrollPort.x || scrollbarOnLeft) { @@ -5334,17 +5334,17 @@ ScrollFrameHelper::LayoutScrollbars(nsBoxLayoutState& aState, if (hasResizer) { // if a resizer is present, get its size. Assume a default size of 15 pixels. nscoord defaultSize = nsPresContext::CSSPixelsToAppUnits(15); - nsSize resizerMinSize = mResizerBox->GetMinSize(aState); + nsSize resizerMinSize = mResizerBox->GetXULMinSize(aState); nscoord vScrollbarWidth = mVScrollbarBox ? - mVScrollbarBox->GetPrefSize(aState).width : defaultSize; + mVScrollbarBox->GetXULPrefSize(aState).width : defaultSize; r.width = std::max(std::max(r.width, vScrollbarWidth), resizerMinSize.width); if (aContentArea.x == mScrollPort.x && !scrollbarOnLeft) { r.x = aContentArea.XMost() - r.width; } nscoord hScrollbarHeight = mHScrollbarBox ? - mHScrollbarBox->GetPrefSize(aState).height : defaultSize; + mHScrollbarBox->GetXULPrefSize(aState).height : defaultSize; r.height = std::max(std::max(r.height, hScrollbarHeight), resizerMinSize.height); if (aContentArea.y == mScrollPort.y) { r.y = aContentArea.YMost() - r.height; @@ -5361,7 +5361,7 @@ ScrollFrameHelper::LayoutScrollbars(nsBoxLayoutState& aState, nsPresContext* presContext = mScrolledFrame->PresContext(); nsRect vRect; if (mVScrollbarBox) { - NS_PRECONDITION(mVScrollbarBox->IsBoxFrame(), "Must be a box frame!"); + NS_PRECONDITION(mVScrollbarBox->IsXULBoxFrame(), "Must be a box frame!"); vRect = mScrollPort; if (overlayScrollBarsWithZoom) { vRect.height = NSToCoordRound(res * scrollPortClampingSize.height); @@ -5370,7 +5370,7 @@ ScrollFrameHelper::LayoutScrollbars(nsBoxLayoutState& aState, vRect.x = scrollbarOnLeft ? aContentArea.x : mScrollPort.x + NSToCoordRound(res * scrollPortClampingSize.width); if (mHasVerticalScrollbar) { nsMargin margin; - mVScrollbarBox->GetMargin(margin); + mVScrollbarBox->GetXULMargin(margin); vRect.Deflate(margin); } AdjustScrollbarRectForResizer(mOuter, presContext, vRect, hasResizer, true); @@ -5378,7 +5378,7 @@ ScrollFrameHelper::LayoutScrollbars(nsBoxLayoutState& aState, nsRect hRect; if (mHScrollbarBox) { - NS_PRECONDITION(mHScrollbarBox->IsBoxFrame(), "Must be a box frame!"); + NS_PRECONDITION(mHScrollbarBox->IsXULBoxFrame(), "Must be a box frame!"); hRect = mScrollPort; if (overlayScrollBarsWithZoom) { hRect.width = NSToCoordRound(res * scrollPortClampingSize.width); @@ -5387,7 +5387,7 @@ ScrollFrameHelper::LayoutScrollbars(nsBoxLayoutState& aState, hRect.y = mScrollPort.y + NSToCoordRound(res * scrollPortClampingSize.height); if (mHasHorizontalScrollbar) { nsMargin margin; - mHScrollbarBox->GetMargin(margin); + mHScrollbarBox->GetXULMargin(margin); hRect.Deflate(margin); } AdjustScrollbarRectForResizer(mOuter, presContext, hRect, hasResizer, false); diff --git a/layout/generic/nsGfxScrollFrame.h b/layout/generic/nsGfxScrollFrame.h index a4d03b176f..2e45a2cd22 100644 --- a/layout/generic/nsGfxScrollFrame.h +++ b/layout/generic/nsGfxScrollFrame.h @@ -700,8 +700,8 @@ public: virtual nscoord GetMinISize(nsRenderingContext *aRenderingContext) override; virtual nscoord GetPrefISize(nsRenderingContext *aRenderingContext) override; - virtual nsresult GetPadding(nsMargin& aPadding) override; - virtual bool IsCollapsed() override; + virtual nsresult GetXULPadding(nsMargin& aPadding) override; + virtual bool IsXULCollapsed() override; virtual void Reflow(nsPresContext* aPresContext, nsHTMLReflowMetrics& aDesiredSize, @@ -1128,20 +1128,20 @@ public: virtual void AppendAnonymousContentTo(nsTArray& aElements, uint32_t aFilter) override; - virtual nsSize GetMinSize(nsBoxLayoutState& aBoxLayoutState) override; - virtual nsSize GetPrefSize(nsBoxLayoutState& aBoxLayoutState) override; - virtual nsSize GetMaxSize(nsBoxLayoutState& aBoxLayoutState) override; - virtual nscoord GetBoxAscent(nsBoxLayoutState& aBoxLayoutState) override; + virtual nsSize GetXULMinSize(nsBoxLayoutState& aBoxLayoutState) override; + virtual nsSize GetXULPrefSize(nsBoxLayoutState& aBoxLayoutState) override; + virtual nsSize GetXULMaxSize(nsBoxLayoutState& aBoxLayoutState) override; + virtual nscoord GetXULBoxAscent(nsBoxLayoutState& aBoxLayoutState) override; - NS_IMETHOD DoLayout(nsBoxLayoutState& aBoxLayoutState) override; - virtual nsresult GetPadding(nsMargin& aPadding) override; + NS_IMETHOD DoXULLayout(nsBoxLayoutState& aBoxLayoutState) override; + virtual nsresult GetXULPadding(nsMargin& aPadding) override; virtual bool GetBorderRadii(const nsSize& aFrameSize, const nsSize& aBorderArea, Sides aSkipSides, nscoord aRadii[8]) const override { return mHelper.GetBorderRadii(aFrameSize, aBorderArea, aSkipSides, aRadii); } - nsresult Layout(nsBoxLayoutState& aState); + nsresult XULLayout(nsBoxLayoutState& aState); void LayoutScrollArea(nsBoxLayoutState& aState, const nsPoint& aScrollPosition); static bool AddRemoveScrollbar(bool& aHasScrollbar, @@ -1452,7 +1452,7 @@ protected: if (!mHelper.IsLTR()) { aRect.x = mHelper.mScrollPort.XMost() - aScrollPosition.x - aRect.width; } - mHelper.mScrolledFrame->SetBounds(aState, aRect, aRemoveOverflowAreas); + mHelper.mScrolledFrame->SetXULBounds(aState, aRect, aRemoveOverflowAreas); } private: diff --git a/layout/generic/nsGridContainerFrame.cpp b/layout/generic/nsGridContainerFrame.cpp index dfca6bb325..2e70305cf9 100644 --- a/layout/generic/nsGridContainerFrame.cpp +++ b/layout/generic/nsGridContainerFrame.cpp @@ -16,6 +16,7 @@ #include "nsAlgorithm.h" // for clamped() #include "nsAutoPtr.h" #include "nsCSSAnonBoxes.h" +#include "nsCSSFrameConstructor.h" #include "nsDataHashtable.h" #include "nsDisplayList.h" #include "nsHashKeys.h" @@ -151,8 +152,21 @@ nsGridContainerFrame::TrackSize::Initialize(nscoord aPercentageBasis, { MOZ_ASSERT(mBase == 0 && mLimit == 0 && mState == 0, "track size data is expected to be initialized to zero"); + auto minSizeUnit = aMinCoord.GetUnit(); + auto maxSizeUnit = aMaxCoord.GetUnit(); + if (aPercentageBasis == NS_UNCONSTRAINEDSIZE) { + // https://drafts.csswg.org/css-grid/#valdef-grid-template-columns-percentage + // "If the inline or block size of the grid container is indefinite, + // values relative to that size are treated as 'auto'." + if (aMinCoord.HasPercent()) { + minSizeUnit = eStyleUnit_Auto; + } + if (aMaxCoord.HasPercent()) { + maxSizeUnit = eStyleUnit_Auto; + } + } // http://dev.w3.org/csswg/css-grid/#algo-init - switch (aMinCoord.GetUnit()) { + switch (minSizeUnit) { case eStyleUnit_Auto: mState = eAutoMinSizing; break; @@ -166,7 +180,7 @@ nsGridContainerFrame::TrackSize::Initialize(nscoord aPercentageBasis, default: mBase = nsRuleNode::ComputeCoordPercentCalc(aMinCoord, aPercentageBasis); } - switch (aMaxCoord.GetUnit()) { + switch (maxSizeUnit) { case eStyleUnit_Auto: mState |= eAutoMaxSizing; mLimit = NS_UNCONSTRAINEDSIZE; @@ -2038,12 +2052,10 @@ nsGridContainerFrame::GridReflowState::CalculateTrackSizes( mRows.Initialize(mRowFunctions, mGridStyle->mGridRowGap, aGrid.mGridRowEnd, aContentBox.BSize(mWM)); - mIter.Reset(); // XXX cleanup this Reset mess! mCols.CalculateSizes(*this, mGridItems, mColFunctions, aContentBox.ISize(mWM), &GridArea::mCols, aConstraint); - mIter.Reset(); // XXX cleanup this Reset mess! mRows.CalculateSizes(*this, mGridItems, mRowFunctions, aContentBox.BSize(mWM), &GridArea::mRows, aConstraint); @@ -2937,6 +2949,7 @@ nsGridContainerFrame::Grid::PlaceGridItems(GridReflowState& aState, int32_t minCol = 1; int32_t minRow = 1; aState.mGridItems.ClearAndRetainStorage(); + aState.mIter.Reset(); for (; !aState.mIter.AtEnd(); aState.mIter.Next()) { nsIFrame* child = *aState.mIter; GridItemInfo* info = @@ -3208,12 +3221,8 @@ nsGridContainerFrame::Tracks::Initialize( aFunctions.NumExplicitTracks()); mSizes.SetLength(aNumTracks); PodZero(mSizes.Elements(), mSizes.Length()); - nscoord percentageBasis = aContentBoxSize; - if (percentageBasis == NS_UNCONSTRAINEDSIZE) { - percentageBasis = 0; - } for (uint32_t i = 0, len = mSizes.Length(); i < len; ++i) { - mSizes[i].Initialize(percentageBasis, + mSizes[i].Initialize(aContentBoxSize, aFunctions.MinSizingFor(i), aFunctions.MaxSizingFor(i)); } @@ -3485,6 +3494,7 @@ nsGridContainerFrame::Tracks::ResolveIntrinsicSize( const TrackSize::StateBits flexMin = aConstraint == nsLayoutUtils::MIN_ISIZE ? TrackSize::eFlexMinSizing : TrackSize::StateBits(0); + iter.Reset(); for (; !iter.AtEnd(); iter.Next()) { nsIFrame* child = *iter; const GridArea& area = aGridItems[iter.GridItemIndex()].mArea; @@ -5005,7 +5015,6 @@ nsGridContainerFrame::Reflow(nsPresContext* aPresContext, grid.PlaceGridItems(gridReflowState, computedMinSize, computedSize, aReflowState.ComputedMaxSize()); - gridReflowState.mIter.Reset(); gridReflowState.CalculateTrackSizes(grid, computedSize, nsLayoutUtils::PREF_ISIZE); @@ -5149,7 +5158,6 @@ nsGridContainerFrame::IntrinsicISize(nsRenderingContext* aRenderingContext, } state.mCols.Initialize(state.mColFunctions, state.mGridStyle->mGridColumnGap, grid.mGridColEnd, NS_UNCONSTRAINEDSIZE); - state.mIter.Reset(); state.mCols.CalculateSizes(state, state.mGridItems, state.mColFunctions, NS_UNCONSTRAINEDSIZE, &GridArea::mCols, aConstraint); @@ -5342,20 +5350,6 @@ nsGridContainerFrame::MergeSortedExcessOverflowContainers(nsFrameList& aList) } #ifdef DEBUG -static bool -FrameWantsToBeInAnonymousGridItem(nsIFrame* aFrame) -{ - // Note: This needs to match the logic in - // nsCSSFrameConstructor::FrameConstructionItem::NeedsAnonFlexOrGridItem() - return aFrame->IsFrameOfType(nsIFrame::eLineParticipant); -} - -// Debug-only override, to let us assert that our anonymous grid items are -// set up correctly by the frame constructor -- in particular, we assert: -// (1) we don't have any inline non-replaced children -// (2) we don't have any consecutive anonymous grid items -// (3) we don't have any empty anonymous grid items -// (4) all children are on the expected child lists void nsGridContainerFrame::SetInitialChildList(ChildListID aListID, nsFrameList& aChildList) @@ -5363,25 +5357,6 @@ nsGridContainerFrame::SetInitialChildList(ChildListID aListID, ChildListIDs supportedLists = kAbsoluteList | kFixedList | kPrincipalList; MOZ_ASSERT(supportedLists.Contains(aListID), "unexpected child list"); - if (aListID == kPrincipalList) { - bool prevChildWasAnonGridItem = false; - for (nsFrameList::Enumerator e(aChildList); !e.AtEnd(); e.Next()) { - nsIFrame* child = e.get(); - MOZ_ASSERT(!FrameWantsToBeInAnonymousGridItem(child), - "frame wants to be inside an anonymous grid item, but it isn't"); - if (child->StyleContext()->GetPseudo() == - nsCSSAnonBoxes::anonymousGridItem) { - MOZ_ASSERT(!prevChildWasAnonGridItem, "two anon grid items in a row"); - nsIFrame* firstWrappedChild = child->PrincipalChildList().FirstChild(); - MOZ_ASSERT(firstWrappedChild, - "anonymous grid item is empty (shouldn't happen)"); - prevChildWasAnonGridItem = true; - } else { - prevChildWasAnonGridItem = false; - } - } - } - return nsContainerFrame::SetInitialChildList(aListID, aChildList); } diff --git a/layout/generic/nsGridContainerFrame.h b/layout/generic/nsGridContainerFrame.h index 1915ff04d5..ed8d13e241 100644 --- a/layout/generic/nsGridContainerFrame.h +++ b/layout/generic/nsGridContainerFrame.h @@ -9,6 +9,7 @@ #ifndef nsGridContainerFrame_h___ #define nsGridContainerFrame_h___ +#include "mozilla/Maybe.h" #include "mozilla/TypeTraits.h" #include "nsContainerFrame.h" #include "nsHashKeys.h" @@ -46,6 +47,7 @@ public: NS_DECL_FRAMEARENA_HELPERS NS_DECL_QUERYFRAME_TARGET(nsGridContainerFrame) NS_DECL_QUERYFRAME + typedef mozilla::ComputedGridTrackInfo ComputedGridTrackInfo; // nsIFrame overrides void Reflow(nsPresContext* aPresContext, @@ -202,7 +204,7 @@ private: bool mIsAutoBSize; }; - Maybe + mozilla::Maybe GetNearestFragmentainer(const GridReflowState& aState) const; // @return the consumed size of all continuations so far including this frame diff --git a/layout/generic/nsHTMLReflowState.cpp b/layout/generic/nsHTMLReflowState.cpp index fad32f5047..7a73adda61 100644 --- a/layout/generic/nsHTMLReflowState.cpp +++ b/layout/generic/nsHTMLReflowState.cpp @@ -665,7 +665,7 @@ nsHTMLReflowState::InitResizeFlags(nsPresContext* aPresContext, nsIAtom* aFrameT mStylePosition->MaxBSizeDependsOnContainer(wm) || mStylePosition->OffsetHasPercent(wm.PhysicalSide(eLogicalSideBStart)) || mStylePosition->mOffset.GetBEndUnit(wm) != eStyleUnit_Auto || - frame->IsBoxFrame(); + frame->IsXULBoxFrame(); if (mStyleText->mLineHeight.GetUnit() == eStyleUnit_Enumerated) { NS_ASSERTION(mStyleText->mLineHeight.GetIntValue() == diff --git a/layout/generic/nsIFrame.h b/layout/generic/nsIFrame.h index e8d6309acb..86f6c6da09 100644 --- a/layout/generic/nsIFrame.h +++ b/layout/generic/nsIFrame.h @@ -2107,7 +2107,6 @@ public: */ bool HasView() const { return !!(mState & NS_FRAME_HAS_VIEW); } nsView* GetView() const; - virtual nsView* GetViewExternal() const; nsresult SetView(nsView* aView); /** @@ -2121,7 +2120,6 @@ public: * Find the closest ancestor (excluding |this| !) that has a view */ nsIFrame* GetAncestorWithView() const; - virtual nsIFrame* GetAncestorWithViewExternal() const; /** * Get the offset between the coordinate systems of |this| and aOther. @@ -2140,7 +2138,6 @@ public: * aOther. */ nsPoint GetOffsetTo(const nsIFrame* aOther) const; - virtual nsPoint GetOffsetToExternal(const nsIFrame* aOther) const; /** * Get the offset between the coordinate systems of |this| and aOther @@ -2175,14 +2172,12 @@ public: * @return the pixel rect of the frame in screen coordinates. */ nsIntRect GetScreenRect() const; - virtual nsIntRect GetScreenRectExternal() const; /** * Get the screen rect of the frame in app units. * @return the app unit rect of the frame in screen coordinates. */ nsRect GetScreenRectInAppUnits() const; - virtual nsRect GetScreenRectInAppUnitsExternal() const; /** * Returns the offset from this frame to the closest geometric parent that @@ -2195,16 +2190,15 @@ public: * view and the view has a widget, then this frame's widget is * returned, otherwise this frame's geometric parent is checked * recursively upwards. - * XXX virtual because gfx callers use it! (themes) */ - virtual nsIWidget* GetNearestWidget() const; + nsIWidget* GetNearestWidget() const; /** * Same as GetNearestWidget() above but uses an outparam to return the offset * of this frame to the returned widget expressed in appunits of |this| (the * widget might be in a different document with a different zoom). */ - virtual nsIWidget* GetNearestWidget(nsPoint& aOffset) const; + nsIWidget* GetNearestWidget(nsPoint& aOffset) const; /** * Get the "type" of the frame. May return nullptr. @@ -2868,7 +2862,7 @@ public: // BOX LAYOUT METHODS // These methods have been migrated from nsIBox and are in the process of // being refactored. DO NOT USE OUTSIDE OF XUL. - bool IsBoxFrame() const + bool IsXULBoxFrame() const { return IsFrameOfType(nsIFrame::eXULBox); } @@ -2891,87 +2885,85 @@ public: * @param[in] aBoxLayoutState The desired state to calculate for * @return The minimum size */ - virtual nsSize GetMinSize(nsBoxLayoutState& aBoxLayoutState) = 0; + virtual nsSize GetXULMinSize(nsBoxLayoutState& aBoxLayoutState) = 0; /** * This calculates the preferred size of a box based on its state * @param[in] aBoxLayoutState The desired state to calculate for * @return The preferred size */ - virtual nsSize GetPrefSize(nsBoxLayoutState& aBoxLayoutState) = 0; + virtual nsSize GetXULPrefSize(nsBoxLayoutState& aBoxLayoutState) = 0; /** * This calculates the maximum size for a box based on its state * @param[in] aBoxLayoutState The desired state to calculate for * @return The maximum size */ - virtual nsSize GetMaxSize(nsBoxLayoutState& aBoxLayoutState) = 0; + virtual nsSize GetXULMaxSize(nsBoxLayoutState& aBoxLayoutState) = 0; /** * This returns the minimum size for the scroll area if this frame is * being scrolled. Usually it's (0,0). */ - virtual nsSize GetMinSizeForScrollArea(nsBoxLayoutState& aBoxLayoutState) = 0; + virtual nsSize GetXULMinSizeForScrollArea(nsBoxLayoutState& aBoxLayoutState) = 0; // Implemented in nsBox, used in nsBoxFrame - uint32_t GetOrdinal(); + uint32_t GetXULOrdinal(); - virtual nscoord GetFlex() = 0; - virtual nscoord GetBoxAscent(nsBoxLayoutState& aBoxLayoutState) = 0; - virtual bool IsCollapsed() = 0; + virtual nscoord GetXULFlex() = 0; + virtual nscoord GetXULBoxAscent(nsBoxLayoutState& aBoxLayoutState) = 0; + virtual bool IsXULCollapsed() = 0; // This does not alter the overflow area. If the caller is changing // the box size, the caller is responsible for updating the overflow - // area. It's enough to just call Layout or SyncLayout on the + // area. It's enough to just call XULLayout or SyncLayout on the // box. You can pass true to aRemoveOverflowArea as a // convenience. - virtual void SetBounds(nsBoxLayoutState& aBoxLayoutState, const nsRect& aRect, - bool aRemoveOverflowAreas = false) = 0; - nsresult Layout(nsBoxLayoutState& aBoxLayoutState); + virtual void SetXULBounds(nsBoxLayoutState& aBoxLayoutState, const nsRect& aRect, + bool aRemoveOverflowAreas = false) = 0; + nsresult XULLayout(nsBoxLayoutState& aBoxLayoutState); // Box methods. Note that these do NOT just get the CSS border, padding, // etc. They also talk to nsITheme. - virtual nsresult GetBorderAndPadding(nsMargin& aBorderAndPadding); - virtual nsresult GetBorder(nsMargin& aBorder)=0; - virtual nsresult GetPadding(nsMargin& aBorderAndPadding)=0; - virtual nsresult GetMargin(nsMargin& aMargin)=0; - virtual void SetLayoutManager(nsBoxLayout* aLayout) { } - virtual nsBoxLayout* GetLayoutManager() { return nullptr; } - nsresult GetClientRect(nsRect& aContentRect); + virtual nsresult GetXULBorderAndPadding(nsMargin& aBorderAndPadding); + virtual nsresult GetXULBorder(nsMargin& aBorder)=0; + virtual nsresult GetXULPadding(nsMargin& aBorderAndPadding)=0; + virtual nsresult GetXULMargin(nsMargin& aMargin)=0; + virtual void SetXULLayoutManager(nsBoxLayout* aLayout) { } + virtual nsBoxLayout* GetXULLayoutManager() { return nullptr; } + nsresult GetXULClientRect(nsRect& aContentRect); // For nsSprocketLayout - virtual Valignment GetVAlign() const = 0; - virtual Halignment GetHAlign() const = 0; + virtual Valignment GetXULVAlign() const = 0; + virtual Halignment GetXULHAlign() const = 0; - bool IsHorizontal() const { return (mState & NS_STATE_IS_HORIZONTAL) != 0; } - bool IsNormalDirection() const { return (mState & NS_STATE_IS_DIRECTION_NORMAL) != 0; } + bool IsXULHorizontal() const { return (mState & NS_STATE_IS_HORIZONTAL) != 0; } + bool IsXULNormalDirection() const { return (mState & NS_STATE_IS_DIRECTION_NORMAL) != 0; } - nsresult Redraw(nsBoxLayoutState& aState); - virtual nsresult RelayoutChildAtOrdinal(nsIFrame* aChild)=0; - // XXX take this out after we've branched - virtual bool GetMouseThrough() const { return false; } + nsresult XULRedraw(nsBoxLayoutState& aState); + virtual nsresult XULRelayoutChildAtOrdinal(nsIFrame* aChild)=0; #ifdef DEBUG_LAYOUT - virtual nsresult SetDebug(nsBoxLayoutState& aState, bool aDebug)=0; - virtual nsresult GetDebug(bool& aDebug)=0; + virtual nsresult SetXULDebug(nsBoxLayoutState& aState, bool aDebug)=0; + virtual nsresult GetXULDebug(bool& aDebug)=0; - virtual nsresult DumpBox(FILE* out)=0; + virtual nsresult XULDumpBox(FILE* out)=0; #endif + static bool AddXULPrefSize(nsIFrame* aBox, nsSize& aSize, bool& aWidth, bool& aHeightSet); + static bool AddXULMinSize(nsBoxLayoutState& aState, nsIFrame* aBox, + nsSize& aSize, bool& aWidth, bool& aHeightSet); + static bool AddXULMaxSize(nsIFrame* aBox, nsSize& aSize, bool& aWidth, bool& aHeightSet); + static bool AddXULFlex(nsIFrame* aBox, nscoord& aFlex); + + // END OF BOX LAYOUT METHODS + // The above methods have been migrated from nsIBox and are in the process of + // being refactored. DO NOT USE OUTSIDE OF XUL. + /** * @return true if this text frame ends with a newline character. It * should return false if this is not a text frame. */ virtual bool HasSignificantTerminalNewline() const; - static bool AddCSSPrefSize(nsIFrame* aBox, nsSize& aSize, bool& aWidth, bool& aHeightSet); - static bool AddCSSMinSize(nsBoxLayoutState& aState, nsIFrame* aBox, - nsSize& aSize, bool& aWidth, bool& aHeightSet); - static bool AddCSSMaxSize(nsIFrame* aBox, nsSize& aSize, bool& aWidth, bool& aHeightSet); - static bool AddCSSFlex(nsIFrame* aBox, nscoord& aFlex); - - // END OF BOX LAYOUT METHODS - // The above methods have been migrated from nsIBox and are in the process of - // being refactored. DO NOT USE OUTSIDE OF XUL. - struct CaretPosition { CaretPosition(); ~CaretPosition(); diff --git a/layout/generic/nsImageFrame.cpp b/layout/generic/nsImageFrame.cpp index f0169606cc..3c42ad2ee1 100644 --- a/layout/generic/nsImageFrame.cpp +++ b/layout/generic/nsImageFrame.cpp @@ -1524,64 +1524,18 @@ nsDisplayImage::ComputeInvalidationRegion(nsDisplayListBuilder* aBuilder, nsDisplayImageContainer::ComputeInvalidationRegion(aBuilder, aGeometry, aInvalidRegion); } -bool -nsDisplayImage::CanOptimizeToImageLayer(LayerManager* aManager, - nsDisplayListBuilder* aBuilder) +already_AddRefed +nsDisplayImage::GetImage() { - uint32_t flags = aBuilder->ShouldSyncDecodeImages() - ? imgIContainer::FLAG_SYNC_DECODE - : imgIContainer::FLAG_NONE; - - if (!mImage->IsImageContainerAvailable(aManager, flags)) { - return false; - } - - int32_t imageWidth; - int32_t imageHeight; - mImage->GetWidth(&imageWidth); - mImage->GetHeight(&imageHeight); - - if (imageWidth == 0 || imageHeight == 0) { - NS_ASSERTION(false, "invalid image size"); - return false; - } - - const int32_t factor = mFrame->PresContext()->AppUnitsPerDevPixel(); - const LayoutDeviceRect destRect = - LayoutDeviceRect::FromAppUnits(GetDestRect(), factor); - - // Calculate the scaling factor for the frame. - const gfxSize scale = gfxSize(destRect.width / imageWidth, - destRect.height / imageHeight); - - if (scale.width < 0.2 || scale.height < 0.2) { - // This would look awful as long as we can't use high-quality downscaling - // for image layers (bug 803703), so don't turn this into an image layer. - return false; - } - - return true; -} - -already_AddRefed -nsDisplayImage::GetContainer(LayerManager* aManager, - nsDisplayListBuilder* aBuilder) -{ - uint32_t flags = aBuilder->ShouldSyncDecodeImages() - ? imgIContainer::FLAG_SYNC_DECODE - : imgIContainer::FLAG_NONE; - - return mImage->GetImageContainer(aManager, flags); + nsCOMPtr image = mImage; + return image.forget(); } nsRect -nsDisplayImage::GetDestRect(bool* aSnap) +nsDisplayImage::GetDestRect() { bool snap = true; const nsRect frameContentBox = GetBounds(&snap); - if (aSnap) { - *aSnap = snap; - } nsImageFrame* imageFrame = static_cast(mFrame); return imageFrame->PredictedDestRect(frameContentBox); @@ -1682,54 +1636,6 @@ nsDisplayImage::BuildLayer(nsDisplayListBuilder* aBuilder, return layer.forget(); } -void -nsDisplayImage::ConfigureLayer(ImageLayer* aLayer, - const ContainerLayerParameters& aParameters) -{ - aLayer->SetFilter(nsLayoutUtils::GetGraphicsFilterForFrame(mFrame)); - - int32_t imageWidth; - int32_t imageHeight; - mImage->GetWidth(&imageWidth); - mImage->GetHeight(&imageHeight); - - NS_ASSERTION(imageWidth != 0 && imageHeight != 0, "Invalid image size!"); - if (imageWidth > 0 && imageHeight > 0) { - // We're actually using the ImageContainer. Let our frame know that it - // should consider itself to have painted successfully. - nsDisplayItemGenericImageGeometry::UpdateDrawResult(this, - DrawResult::SUCCESS); - } - - const int32_t factor = mFrame->PresContext()->AppUnitsPerDevPixel(); - const LayoutDeviceRect destRect = - LayoutDeviceRect::FromAppUnits(GetDestRect(), factor); - - // XXX(seth): Right now we ignore aParameters.Scale() and - // aParameters.Offset(), because FrameLayerBuilder already applies - // aParameters.Scale() via the layer's post-transform, and - // aParameters.Offset() is always zero. - MOZ_ASSERT(aParameters.Offset() == LayerIntPoint(0,0)); - - // It's possible (for example, due to downscale-during-decode) that the - // ImageContainer this ImageLayer is holding has a different size from the - // intrinsic size of the image. For this reason we compute the transform using - // the ImageContainer's size rather than the image's intrinsic size. - // XXX(seth): In reality, since the size of the ImageContainer may change - // asynchronously, this is not enough. Bug 1183378 will provide a more - // complete fix, but this solution is safe in more cases than simply relying - // on the intrinsic size. - IntSize containerSize = aLayer->GetContainer() - ? aLayer->GetContainer()->GetCurrentSize() - : IntSize(imageWidth, imageHeight); - - const LayoutDevicePoint p = destRect.TopLeft(); - Matrix transform = Matrix::Translation(p.x, p.y); - transform.PreScale(destRect.Width() / containerSize.width, - destRect.Height() / containerSize.height); - aLayer->SetBaseTransform(gfx::Matrix4x4::From2D(transform)); -} - DrawResult nsImageFrame::PaintImage(nsRenderingContext& aRenderingContext, nsPoint aPt, const nsRect& aDirtyRect, imgIContainer* aImage, @@ -2265,6 +2171,7 @@ nsImageFrame::LoadIcon(const nsAString& aSpec, nullptr, /* principal (not relevant for icons) */ loadGroup, gIconLoad, + nullptr, /* No context */ nullptr, /* Not associated with any particular document */ loadFlags, nullptr, diff --git a/layout/generic/nsImageFrame.h b/layout/generic/nsImageFrame.h index a51911857b..175b9b019c 100644 --- a/layout/generic/nsImageFrame.h +++ b/layout/generic/nsImageFrame.h @@ -428,21 +428,13 @@ public: virtual void Paint(nsDisplayListBuilder* aBuilder, nsRenderingContext* aCtx) override; - virtual bool CanOptimizeToImageLayer(LayerManager* aManager, - nsDisplayListBuilder* aBuilder) override; - - /** - * Returns an ImageContainer for this image if the image type - * supports it (TYPE_RASTER only). - */ - virtual already_AddRefed GetContainer(LayerManager* aManager, - nsDisplayListBuilder* aBuilder) override; + virtual already_AddRefed GetImage() override; /** * @return The dest rect we'll use when drawing this image, in app units. * Not necessarily contained in this item's bounds. */ - nsRect GetDestRect(bool* aSnap = nullptr); + virtual nsRect GetDestRect() override; virtual LayerState GetLayerState(nsDisplayListBuilder* aBuilder, LayerManager* aManager, @@ -468,13 +460,6 @@ public: LayerManager* aManager, const ContainerLayerParameters& aContainerParameters) override; - /** - * Configure an ImageLayer for this display item. - * Set the required filter and scaling transform. - */ - virtual void ConfigureLayer(ImageLayer* aLayer, - const ContainerLayerParameters& aParameters) override; - NS_DISPLAY_DECL_NAME("Image", TYPE_IMAGE) private: nsCOMPtr mImage; diff --git a/layout/generic/nsPlaceholderFrame.cpp b/layout/generic/nsPlaceholderFrame.cpp index 45d68119b0..0e42736d98 100644 --- a/layout/generic/nsPlaceholderFrame.cpp +++ b/layout/generic/nsPlaceholderFrame.cpp @@ -38,7 +38,7 @@ NS_QUERYFRAME_TAIL_INHERITING(nsFrame) #endif /* virtual */ nsSize -nsPlaceholderFrame::GetMinSize(nsBoxLayoutState& aBoxLayoutState) +nsPlaceholderFrame::GetXULMinSize(nsBoxLayoutState& aBoxLayoutState) { nsSize size(0, 0); DISPLAY_MIN_SIZE(this, size); @@ -46,7 +46,7 @@ nsPlaceholderFrame::GetMinSize(nsBoxLayoutState& aBoxLayoutState) } /* virtual */ nsSize -nsPlaceholderFrame::GetPrefSize(nsBoxLayoutState& aBoxLayoutState) +nsPlaceholderFrame::GetXULPrefSize(nsBoxLayoutState& aBoxLayoutState) { nsSize size(0, 0); DISPLAY_PREF_SIZE(this, size); @@ -54,7 +54,7 @@ nsPlaceholderFrame::GetPrefSize(nsBoxLayoutState& aBoxLayoutState) } /* virtual */ nsSize -nsPlaceholderFrame::GetMaxSize(nsBoxLayoutState& aBoxLayoutState) +nsPlaceholderFrame::GetXULMaxSize(nsBoxLayoutState& aBoxLayoutState) { nsSize size(NS_INTRINSICSIZE, NS_INTRINSICSIZE); DISPLAY_MAX_SIZE(this, size); diff --git a/layout/generic/nsPlaceholderFrame.h b/layout/generic/nsPlaceholderFrame.h index b38a35fa6c..400eb4f816 100644 --- a/layout/generic/nsPlaceholderFrame.h +++ b/layout/generic/nsPlaceholderFrame.h @@ -88,15 +88,15 @@ public: } // nsIFrame overrides - // We need to override GetMinSize and GetPrefSize because XUL uses + // We need to override GetXULMinSize and GetXULPrefSize because XUL uses // placeholders not within lines. virtual void AddInlineMinISize(nsRenderingContext* aRenderingContext, InlineMinISizeData* aData) override; virtual void AddInlinePrefISize(nsRenderingContext* aRenderingContext, InlinePrefISizeData* aData) override; - virtual nsSize GetMinSize(nsBoxLayoutState& aBoxLayoutState) override; - virtual nsSize GetPrefSize(nsBoxLayoutState& aBoxLayoutState) override; - virtual nsSize GetMaxSize(nsBoxLayoutState& aBoxLayoutState) override; + virtual nsSize GetXULMinSize(nsBoxLayoutState& aBoxLayoutState) override; + virtual nsSize GetXULPrefSize(nsBoxLayoutState& aBoxLayoutState) override; + virtual nsSize GetXULMaxSize(nsBoxLayoutState& aBoxLayoutState) override; virtual void Reflow(nsPresContext* aPresContext, nsHTMLReflowMetrics& aDesiredSize, diff --git a/layout/generic/nsVideoFrame.cpp b/layout/generic/nsVideoFrame.cpp index b8bd1711ba..cb6fec48c2 100644 --- a/layout/generic/nsVideoFrame.cpp +++ b/layout/generic/nsVideoFrame.cpp @@ -610,7 +610,7 @@ nsVideoFrame::GetVideoIntrinsicSize(nsRenderingContext *aRenderingContext) // Ask the controls frame what its preferred height is nsBoxLayoutState boxState(PresContext(), aRenderingContext, 0); - nscoord prefHeight = mFrames.LastChild()->GetPrefSize(boxState).height; + nscoord prefHeight = mFrames.LastChild()->GetXULPrefSize(boxState).height; return nsSize(nsPresContext::CSSPixelsToAppUnits(size.width), prefHeight); } diff --git a/layout/style/ImageLoader.cpp b/layout/style/ImageLoader.cpp index c71a166db4..d1144c3cef 100644 --- a/layout/style/ImageLoader.cpp +++ b/layout/style/ImageLoader.cpp @@ -263,7 +263,8 @@ ImageLoader::LoadImage(nsIURI* aURI, nsIPrincipal* aOriginPrincipal, } RefPtr request; - nsContentUtils::LoadImage(aURI, mDocument, aOriginPrincipal, aReferrer, + nsContentUtils::LoadImage(aURI, mDocument, mDocument, + aOriginPrincipal, aReferrer, mDocument->GetReferrerPolicy(), nullptr, nsIRequest::LOAD_NORMAL, NS_LITERAL_STRING("css"), diff --git a/layout/style/nsTransitionManager.cpp b/layout/style/nsTransitionManager.cpp index 2de9556123..67c8937333 100644 --- a/layout/style/nsTransitionManager.cpp +++ b/layout/style/nsTransitionManager.cpp @@ -800,3 +800,19 @@ nsTransitionManager::PruneCompletedTransitions(mozilla::dom::Element* aElement, collection = nullptr; } } + +void +nsTransitionManager::StopTransitionsForElement( + mozilla::dom::Element* aElement, + mozilla::CSSPseudoElementType aPseudoType) +{ + MOZ_ASSERT(aElement); + CSSTransitionCollection* collection = + CSSTransitionCollection::GetAnimationCollection(aElement, aPseudoType); + if (!collection) { + return; + } + + nsAutoAnimationMutationBatch mb(aElement->OwnerDoc()); + collection->Destroy(); +} diff --git a/layout/style/nsTransitionManager.h b/layout/style/nsTransitionManager.h index 862d7e3296..a33b9bbbd0 100644 --- a/layout/style/nsTransitionManager.h +++ b/layout/style/nsTransitionManager.h @@ -339,6 +339,12 @@ public: void SortEvents() { mEventDispatcher.SortEvents(); } void ClearEventQueue() { mEventDispatcher.ClearEventQueue(); } + // Stop transitions on the element. This method takes the real element + // rather than the element for the generated content for transitions on + // ::before and ::after. + void StopTransitionsForElement(mozilla::dom::Element* aElement, + mozilla::CSSPseudoElementType aPseudoType); + protected: virtual ~nsTransitionManager() {} diff --git a/layout/xul/ScrollBoxObject.cpp b/layout/xul/ScrollBoxObject.cpp index 207b7cc9e8..26f7bc9bb1 100644 --- a/layout/xul/ScrollBoxObject.cpp +++ b/layout/xul/ScrollBoxObject.cpp @@ -92,7 +92,7 @@ static nsIFrame* GetScrolledBox(BoxObject* aScrollBox) { nsIFrame* scrolledFrame = scrollFrame->GetScrolledFrame(); if (!scrolledFrame) return nullptr; - return nsBox::GetChildBox(scrolledFrame); + return nsBox::GetChildXULBox(scrolledFrame); } void ScrollBoxObject::ScrollByIndex(int32_t dindexes, ErrorResult& aRv) @@ -112,13 +112,13 @@ void ScrollBoxObject::ScrollByIndex(int32_t dindexes, ErrorResult& aRv) nsRect rect; // now get the scrolled boxes first child. - nsIFrame* child = nsBox::GetChildBox(scrolledBox); + nsIFrame* child = nsBox::GetChildXULBox(scrolledBox); - bool horiz = scrolledBox->IsHorizontal(); + bool horiz = scrolledBox->IsXULHorizontal(); nsPoint cp = sf->GetScrollPosition(); nscoord diff = 0; int32_t curIndex = 0; - bool isLTR = scrolledBox->IsNormalDirection(); + bool isLTR = scrolledBox->IsXULNormalDirection(); int32_t frameWidth = 0; if (!isLTR && horiz) { @@ -152,7 +152,7 @@ void ScrollBoxObject::ScrollByIndex(int32_t dindexes, ErrorResult& aRv) break; } } - child = nsBox::GetNextBox(child); + child = nsBox::GetNextXULBox(child); curIndex++; } @@ -163,7 +163,7 @@ void ScrollBoxObject::ScrollByIndex(int32_t dindexes, ErrorResult& aRv) if (dindexes > 0) { while(child) { - child = nsBox::GetNextBox(child); + child = nsBox::GetNextXULBox(child); if (child) { rect = child->GetRect(); } @@ -174,7 +174,7 @@ void ScrollBoxObject::ScrollByIndex(int32_t dindexes, ErrorResult& aRv) } } else if (dindexes < 0) { - child = nsBox::GetChildBox(scrolledBox); + child = nsBox::GetChildXULBox(scrolledBox); while(child) { rect = child->GetRect(); if (count >= curIndex + dindexes) { @@ -182,7 +182,7 @@ void ScrollBoxObject::ScrollByIndex(int32_t dindexes, ErrorResult& aRv) } count++; - child = nsBox::GetNextBox(child); + child = nsBox::GetNextXULBox(child); } } diff --git a/layout/xul/grid/nsGrid.cpp b/layout/xul/grid/nsGrid.cpp index 8dd0573213..49e08a668c 100644 --- a/layout/xul/grid/nsGrid.cpp +++ b/layout/xul/grid/nsGrid.cpp @@ -245,7 +245,7 @@ nsGrid::FindRowsAndColumns(nsIFrame** aRows, nsIFrame** aColumns) nsIFrame* child = nullptr; // if we have then mBox will be null (bug 125689) if (mBox) - child = nsBox::GetChildBox(mBox); + child = nsBox::GetChildXULBox(mBox); while(child) { @@ -262,7 +262,7 @@ nsGrid::FindRowsAndColumns(nsIFrame** aRows, nsIFrame** aColumns) { nsGridRowGroupLayout* rowGroup = monument->CastToRowGroupLayout(); if (rowGroup) { - bool isHorizontal = !nsSprocketLayout::IsHorizontal(child); + bool isHorizontal = !nsSprocketLayout::IsXULHorizontal(child); if (isHorizontal) *aRows = child; else @@ -277,7 +277,7 @@ nsGrid::FindRowsAndColumns(nsIFrame** aRows, nsIFrame** aColumns) child = oldBox; } - child = nsBox::GetNextBox(child); + child = nsBox::GetNextXULBox(child); } } @@ -397,7 +397,7 @@ nsGrid::PopulateCellMap(nsGridRow* aRows, nsGridRow* aColumns, int32_t aRowCount child = row->mBox; if (child) { - child = nsBox::GetChildBox(child); + child = nsBox::GetChildXULBox(child); j = 0; @@ -416,7 +416,7 @@ nsGrid::PopulateCellMap(nsGridRow* aRows, nsGridRow* aColumns, int32_t aRowCount else GetCellAt(i,j)->SetBoxInColumn(child); - child = nsBox::GetNextBox(child); + child = nsBox::GetNextXULBox(child); j++; } @@ -543,7 +543,7 @@ nsGrid::GetPartFromBox(nsIFrame* aBox) if (!aBox) return nullptr; - nsBoxLayout* layout = aBox->GetLayoutManager(); + nsBoxLayout* layout = aBox->GetXULLayoutManager(); return layout ? layout->AsGridPart() : nullptr; } @@ -598,7 +598,7 @@ nsGrid::GetFirstAndLastRow(int32_t& aFirstIndex, for (i=0; i < count; i++) { nsGridRow* row = GetRowAt(i,aIsHorizontal); - if (!row->IsCollapsed()) { + if (!row->IsXULCollapsed()) { aFirstIndex = i; aFirstRow = row; break; @@ -609,7 +609,7 @@ nsGrid::GetFirstAndLastRow(int32_t& aFirstIndex, for (i=count-1; i >= 0; i--) { nsGridRow* row = GetRowAt(i,aIsHorizontal); - if (!row->IsCollapsed()) { + if (!row->IsXULCollapsed()) { aLastIndex = i; aLastRow = row; break; @@ -652,13 +652,13 @@ nsGrid::GetRowOffsets(int32_t aIndex, nscoord& aTop, nscoord& aBottom, bool aIsH // borders padding into account if (box && !row->mIsBogus) { - if (!box->IsCollapsed()) + if (!box->IsXULCollapsed()) { - // get real border and padding. GetBorderAndPadding + // get real border and padding. GetXULBorderAndPadding // is redefined on nsGridRowLeafFrame. If we called it here // we would be in finite recurson. - box->GetBorder(border); - box->GetPadding(padding); + box->GetXULBorder(border); + box->GetXULPadding(padding); totalBorderPadding += border; totalBorderPadding += padding; @@ -717,17 +717,17 @@ nsGrid::GetRowOffsets(int32_t aIndex, nscoord& aTop, nscoord& aBottom, bool aIsH if (box) { // ignore collapsed children - if (!box->IsCollapsed()) + if (!box->IsXULCollapsed()) { // include the margin of the columns. To the row // at this point border/padding and margins all added // up to more needed space. margin = GetBoxTotalMargin(box, !aIsHorizontal); - // get real border and padding. GetBorderAndPadding + // get real border and padding. GetXULBorderAndPadding // is redefined on nsGridRowLeafFrame. If we called it here // we would be in finite recurson. - box->GetBorder(border); - box->GetPadding(padding); + box->GetXULBorder(border); + box->GetXULPadding(padding); totalChildBorderPadding += border; totalChildBorderPadding += padding; totalChildBorderPadding += margin; @@ -792,7 +792,7 @@ nsGrid::GetPrefRowHeight(nsBoxLayoutState& aState, int32_t aIndex, bool aIsHoriz nsGridRow* row = GetRowAt(aIndex, aIsHorizontal); - if (row->IsCollapsed()) + if (row->IsXULCollapsed()) return 0; if (row->IsPrefSet()) @@ -805,7 +805,7 @@ nsGrid::GetPrefRowHeight(nsBoxLayoutState& aState, int32_t aIndex, bool aIsHoriz { bool widthSet, heightSet; nsSize cssSize(-1, -1); - nsIFrame::AddCSSPrefSize(box, cssSize, widthSet, heightSet); + nsIFrame::AddXULPrefSize(box, cssSize, widthSet, heightSet); row->mPref = GET_HEIGHT(cssSize, aIsHorizontal); @@ -826,7 +826,7 @@ nsGrid::GetPrefRowHeight(nsBoxLayoutState& aState, int32_t aIndex, bool aIsHoriz nsSize size(0,0); if (box) { - size = box->GetPrefSize(aState); + size = box->GetXULPrefSize(aState); nsBox::AddMargin(box, size); nsGridLayout2::AddOffset(box, size); } @@ -849,9 +849,9 @@ nsGrid::GetPrefRowHeight(nsBoxLayoutState& aState, int32_t aIndex, bool aIsHoriz child = GetCellAt(aIndex,i); // ignore collapsed children - if (!child->IsCollapsed()) + if (!child->IsXULCollapsed()) { - nsSize childSize = child->GetPrefSize(aState); + nsSize childSize = child->GetXULPrefSize(aState); nsSprocketLayout::AddLargestSize(size, childSize, aIsHorizontal); } @@ -869,7 +869,7 @@ nsGrid::GetMinRowHeight(nsBoxLayoutState& aState, int32_t aIndex, bool aIsHorizo nsGridRow* row = GetRowAt(aIndex, aIsHorizontal); - if (row->IsCollapsed()) + if (row->IsXULCollapsed()) return 0; if (row->IsMinSet()) @@ -881,7 +881,7 @@ nsGrid::GetMinRowHeight(nsBoxLayoutState& aState, int32_t aIndex, bool aIsHorizo if (box) { bool widthSet, heightSet; nsSize cssSize(-1, -1); - nsIFrame::AddCSSMinSize(aState, box, cssSize, widthSet, heightSet); + nsIFrame::AddXULMinSize(aState, box, cssSize, widthSet, heightSet); row->mMin = GET_HEIGHT(cssSize, aIsHorizontal); @@ -901,7 +901,7 @@ nsGrid::GetMinRowHeight(nsBoxLayoutState& aState, int32_t aIndex, bool aIsHorizo { nsSize size(0,0); if (box) { - size = box->GetPrefSize(aState); + size = box->GetXULPrefSize(aState); nsBox::AddMargin(box, size); nsGridLayout2::AddOffset(box, size); } @@ -924,9 +924,9 @@ nsGrid::GetMinRowHeight(nsBoxLayoutState& aState, int32_t aIndex, bool aIsHorizo child = GetCellAt(aIndex,i); // ignore collapsed children - if (!child->IsCollapsed()) + if (!child->IsXULCollapsed()) { - nsSize childSize = child->GetMinSize(aState); + nsSize childSize = child->GetXULMinSize(aState); nsSprocketLayout::AddLargestSize(size, childSize, aIsHorizontal); } @@ -944,7 +944,7 @@ nsGrid::GetMaxRowHeight(nsBoxLayoutState& aState, int32_t aIndex, bool aIsHorizo nsGridRow* row = GetRowAt(aIndex, aIsHorizontal); - if (row->IsCollapsed()) + if (row->IsXULCollapsed()) return 0; if (row->IsMaxSet()) @@ -956,7 +956,7 @@ nsGrid::GetMaxRowHeight(nsBoxLayoutState& aState, int32_t aIndex, bool aIsHorizo if (box) { bool widthSet, heightSet; nsSize cssSize(-1, -1); - nsIFrame::AddCSSMaxSize(box, cssSize, widthSet, heightSet); + nsIFrame::AddXULMaxSize(box, cssSize, widthSet, heightSet); row->mMax = GET_HEIGHT(cssSize, aIsHorizontal); @@ -976,7 +976,7 @@ nsGrid::GetMaxRowHeight(nsBoxLayoutState& aState, int32_t aIndex, bool aIsHorizo { nsSize size(NS_INTRINSICSIZE,NS_INTRINSICSIZE); if (box) { - size = box->GetPrefSize(aState); + size = box->GetXULPrefSize(aState); nsBox::AddMargin(box, size); nsGridLayout2::AddOffset(box, size); } @@ -999,10 +999,10 @@ nsGrid::GetMaxRowHeight(nsBoxLayoutState& aState, int32_t aIndex, bool aIsHorizo child = GetCellAt(aIndex,i); // ignore collapsed children - if (!child->IsCollapsed()) + if (!child->IsXULCollapsed()) { - nsSize min = child->GetMinSize(aState); - nsSize childSize = nsBox::BoundsCheckMinMax(min, child->GetMaxSize(aState)); + nsSize min = child->GetXULMinSize(aState); + nsSize childSize = nsBox::BoundsCheckMinMax(min, child->GetXULMaxSize(aState)); nsSprocketLayout::AddLargestSize(size, childSize, aIsHorizontal); } } @@ -1092,21 +1092,21 @@ nsGrid::GetRowFlex(int32_t aIndex, bool aIsHorizontal) // the grid. 3) Then we are not flexible box = GetScrollBox(box); - nsIFrame* parent = nsBox::GetParentBox(box); + nsIFrame* parent = nsBox::GetParentXULBox(box); nsIFrame* parentsParent=nullptr; while(parent) { parent = GetScrollBox(parent); - parentsParent = nsBox::GetParentBox(parent); + parentsParent = nsBox::GetParentXULBox(parent); // if our parents parent is not a grid // the get its flex. If its 0 then we are // not flexible. if (parentsParent) { if (!IsGrid(parentsParent)) { - nscoord flex = parent->GetFlex(); - nsIFrame::AddCSSFlex(parent, flex); + nscoord flex = parent->GetXULFlex(); + nsIFrame::AddXULFlex(parent, flex); if (flex == 0) { row->mFlex = 0; return row->mFlex; @@ -1119,8 +1119,8 @@ nsGrid::GetRowFlex(int32_t aIndex, bool aIsHorizontal) } // get the row flex. - row->mFlex = box->GetFlex(); - nsIFrame::AddCSSFlex(box, row->mFlex); + row->mFlex = box->GetXULFlex(); + nsIFrame::AddXULFlex(box, row->mFlex); } return row->mFlex; @@ -1225,7 +1225,7 @@ nsGrid::GetScrollBox(nsIFrame* aChild) return nullptr; // get parent - nsIFrame* parent = nsBox::GetParentBox(aChild); + nsIFrame* parent = nsBox::GetParentXULBox(aChild); // walk up until we find a scrollframe or a part // if it's a scrollframe return it. @@ -1242,7 +1242,7 @@ nsGrid::GetScrollBox(nsIFrame* aChild) if (parentGridRow) break; - parent = nsBox::GetParentBox(parent); + parent = nsBox::GetParentXULBox(parent); } return aChild; diff --git a/layout/xul/grid/nsGridCell.cpp b/layout/xul/grid/nsGridCell.cpp index 72458d9779..c54256297d 100644 --- a/layout/xul/grid/nsGridCell.cpp +++ b/layout/xul/grid/nsGridCell.cpp @@ -27,7 +27,7 @@ nsGridCell::~nsGridCell() } nsSize -nsGridCell::GetPrefSize(nsBoxLayoutState& aState) +nsGridCell::GetXULPrefSize(nsBoxLayoutState& aState) { nsSize sum(0,0); @@ -36,7 +36,7 @@ nsGridCell::GetPrefSize(nsBoxLayoutState& aState) // we are tall as the tallest child plus its top offset if (mBoxInColumn) { - nsSize pref = mBoxInColumn->GetPrefSize(aState); + nsSize pref = mBoxInColumn->GetXULPrefSize(aState); nsBox::AddMargin(mBoxInColumn, pref); nsGridLayout2::AddOffset(mBoxInColumn, pref); @@ -45,7 +45,7 @@ nsGridCell::GetPrefSize(nsBoxLayoutState& aState) } if (mBoxInRow) { - nsSize pref = mBoxInRow->GetPrefSize(aState); + nsSize pref = mBoxInRow->GetXULPrefSize(aState); nsBox::AddMargin(mBoxInRow, pref); nsGridLayout2::AddOffset(mBoxInRow, pref); @@ -57,7 +57,7 @@ nsGridCell::GetPrefSize(nsBoxLayoutState& aState) } nsSize -nsGridCell::GetMinSize(nsBoxLayoutState& aState) +nsGridCell::GetXULMinSize(nsBoxLayoutState& aState) { nsSize sum(0, 0); @@ -66,7 +66,7 @@ nsGridCell::GetMinSize(nsBoxLayoutState& aState) // we are tall as the tallest child plus its top offset if (mBoxInColumn) { - nsSize min = mBoxInColumn->GetMinSize(aState); + nsSize min = mBoxInColumn->GetXULMinSize(aState); nsBox::AddMargin(mBoxInColumn, min); nsGridLayout2::AddOffset(mBoxInColumn, min); @@ -75,7 +75,7 @@ nsGridCell::GetMinSize(nsBoxLayoutState& aState) } if (mBoxInRow) { - nsSize min = mBoxInRow->GetMinSize(aState); + nsSize min = mBoxInRow->GetXULMinSize(aState); nsBox::AddMargin(mBoxInRow, min); nsGridLayout2::AddOffset(mBoxInRow, min); @@ -87,7 +87,7 @@ nsGridCell::GetMinSize(nsBoxLayoutState& aState) } nsSize -nsGridCell::GetMaxSize(nsBoxLayoutState& aState) +nsGridCell::GetXULMaxSize(nsBoxLayoutState& aState) { nsSize sum(NS_INTRINSICSIZE, NS_INTRINSICSIZE); @@ -96,7 +96,7 @@ nsGridCell::GetMaxSize(nsBoxLayoutState& aState) // we are tall as the shortest child plus its top offset if (mBoxInColumn) { - nsSize max = mBoxInColumn->GetMaxSize(aState); + nsSize max = mBoxInColumn->GetXULMaxSize(aState); nsBox::AddMargin(mBoxInColumn, max); nsGridLayout2::AddOffset(mBoxInColumn, max); @@ -105,7 +105,7 @@ nsGridCell::GetMaxSize(nsBoxLayoutState& aState) } if (mBoxInRow) { - nsSize max = mBoxInRow->GetMaxSize(aState); + nsSize max = mBoxInRow->GetXULMaxSize(aState); nsBox::AddMargin(mBoxInRow, max); nsGridLayout2::AddOffset(mBoxInRow, max); @@ -118,10 +118,10 @@ nsGridCell::GetMaxSize(nsBoxLayoutState& aState) bool -nsGridCell::IsCollapsed() +nsGridCell::IsXULCollapsed() { - return ((mBoxInColumn && mBoxInColumn->IsCollapsed()) || - (mBoxInRow && mBoxInRow->IsCollapsed())); + return ((mBoxInColumn && mBoxInColumn->IsXULCollapsed()) || + (mBoxInRow && mBoxInRow->IsXULCollapsed())); } diff --git a/layout/xul/grid/nsGridCell.h b/layout/xul/grid/nsGridCell.h index 21012bf639..eca652776f 100644 --- a/layout/xul/grid/nsGridCell.h +++ b/layout/xul/grid/nsGridCell.h @@ -33,10 +33,10 @@ public: nsGridCell(); ~nsGridCell(); - nsSize GetPrefSize(nsBoxLayoutState& aBoxLayoutState); - nsSize GetMinSize(nsBoxLayoutState& aBoxLayoutState); - nsSize GetMaxSize(nsBoxLayoutState& aBoxLayoutState); - bool IsCollapsed(); + nsSize GetXULPrefSize(nsBoxLayoutState& aBoxLayoutState); + nsSize GetXULMinSize(nsBoxLayoutState& aBoxLayoutState); + nsSize GetXULMaxSize(nsBoxLayoutState& aBoxLayoutState); + bool IsXULCollapsed(); // accessors nsIFrame* GetBoxInColumn() { return mBoxInColumn; } diff --git a/layout/xul/grid/nsGridLayout2.cpp b/layout/xul/grid/nsGridLayout2.cpp index 0d4fd3d6d8..069bbe2611 100644 --- a/layout/xul/grid/nsGridLayout2.cpp +++ b/layout/xul/grid/nsGridLayout2.cpp @@ -47,13 +47,13 @@ nsGridLayout2::AddOffset(nsIFrame* aChild, nsSize& aSize) } NS_IMETHODIMP -nsGridLayout2::Layout(nsIFrame* aBox, nsBoxLayoutState& aBoxLayoutState) +nsGridLayout2::XULLayout(nsIFrame* aBox, nsBoxLayoutState& aBoxLayoutState) { // XXX This should be set a better way! mGrid.SetBox(aBox); - NS_ASSERTION(aBox->GetLayoutManager() == this, "setting incorrect box"); + NS_ASSERTION(aBox->GetXULLayoutManager() == this, "setting incorrect box"); - nsresult rv = nsStackLayout::Layout(aBox, aBoxLayoutState); + nsresult rv = nsStackLayout::XULLayout(aBox, aBoxLayoutState); #ifdef DEBUG_grid mGrid.PrintCellMap(); #endif @@ -75,7 +75,7 @@ nsGridLayout2::GetGrid(nsIFrame* aBox, int32_t* aIndex, nsGridRowLayout* aReques { // XXX This should be set a better way! mGrid.SetBox(aBox); - NS_ASSERTION(aBox->GetLayoutManager() == this, "setting incorrect box"); + NS_ASSERTION(aBox->GetXULLayoutManager() == this, "setting incorrect box"); return &mGrid; } @@ -93,9 +93,9 @@ nsGridLayout2::AddWidth(nsSize& aSize, nscoord aSize2, bool aIsHorizontal) } nsSize -nsGridLayout2::GetMinSize(nsIFrame* aBox, nsBoxLayoutState& aState) +nsGridLayout2::GetXULMinSize(nsIFrame* aBox, nsBoxLayoutState& aState) { - nsSize minSize = nsStackLayout::GetMinSize(aBox, aState); + nsSize minSize = nsStackLayout::GetXULMinSize(aBox, aState); // if there are no tags that will sum up our columns, // sum up our columns here. @@ -132,9 +132,9 @@ nsGridLayout2::GetMinSize(nsIFrame* aBox, nsBoxLayoutState& aState) } nsSize -nsGridLayout2::GetPrefSize(nsIFrame* aBox, nsBoxLayoutState& aState) +nsGridLayout2::GetXULPrefSize(nsIFrame* aBox, nsBoxLayoutState& aState) { - nsSize pref = nsStackLayout::GetPrefSize(aBox, aState); + nsSize pref = nsStackLayout::GetXULPrefSize(aBox, aState); // if there are no tags that will sum up our columns, // sum up our columns here. @@ -171,9 +171,9 @@ nsGridLayout2::GetPrefSize(nsIFrame* aBox, nsBoxLayoutState& aState) } nsSize -nsGridLayout2::GetMaxSize(nsIFrame* aBox, nsBoxLayoutState& aState) +nsGridLayout2::GetXULMaxSize(nsIFrame* aBox, nsBoxLayoutState& aState) { - nsSize maxSize = nsStackLayout::GetMaxSize(aBox, aState); + nsSize maxSize = nsStackLayout::GetXULMaxSize(aBox, aState); // if there are no tags that will sum up our columns, // sum up our columns here. diff --git a/layout/xul/grid/nsGridLayout2.h b/layout/xul/grid/nsGridLayout2.h index 1411126165..eb696faf8b 100644 --- a/layout/xul/grid/nsGridLayout2.h +++ b/layout/xul/grid/nsGridLayout2.h @@ -30,7 +30,7 @@ public: NS_DECL_ISUPPORTS_INHERITED - NS_IMETHOD Layout(nsIFrame* aBox, nsBoxLayoutState& aBoxLayoutState) override; + NS_IMETHOD XULLayout(nsIFrame* aBox, nsBoxLayoutState& aBoxLayoutState) override; virtual void IntrinsicISizesDirty(nsIFrame* aBox, nsBoxLayoutState& aBoxLayoutState) override; virtual nsGridRowGroupLayout* CastToRowGroupLayout() override { return nullptr; } @@ -39,9 +39,9 @@ public: virtual nsIGridPart* GetParentGridPart(nsIFrame* aBox, nsIFrame** aParentBox) override { NS_NOTREACHED("Should not be called"); return nullptr; } - virtual nsSize GetMinSize(nsIFrame* aBox, nsBoxLayoutState& aBoxLayoutState) override; - virtual nsSize GetMaxSize(nsIFrame* aBox, nsBoxLayoutState& aBoxLayoutState) override; - virtual nsSize GetPrefSize(nsIFrame* aBox, nsBoxLayoutState& aBoxLayoutState) override; + virtual nsSize GetXULMinSize(nsIFrame* aBox, nsBoxLayoutState& aBoxLayoutState) override; + virtual nsSize GetXULMaxSize(nsIFrame* aBox, nsBoxLayoutState& aBoxLayoutState) override; + virtual nsSize GetXULPrefSize(nsIFrame* aBox, nsBoxLayoutState& aBoxLayoutState) override; virtual void CountRowsColumns(nsIFrame* aBox, int32_t& aRowCount, int32_t& aComputedColumnCount) override { aRowCount++; } virtual void DirtyRows(nsIFrame* aBox, nsBoxLayoutState& aState) override { } virtual int32_t BuildRows(nsIFrame* aBox, nsGridRow* aRows) override; diff --git a/layout/xul/grid/nsGridRow.cpp b/layout/xul/grid/nsGridRow.cpp index 3e6c18edc2..2a2a640168 100644 --- a/layout/xul/grid/nsGridRow.cpp +++ b/layout/xul/grid/nsGridRow.cpp @@ -50,8 +50,8 @@ nsGridRow::~nsGridRow() } bool -nsGridRow::IsCollapsed() +nsGridRow::IsXULCollapsed() { - return mBox && mBox->IsCollapsed(); + return mBox && mBox->IsXULCollapsed(); } diff --git a/layout/xul/grid/nsGridRow.h b/layout/xul/grid/nsGridRow.h index e2eadeb7e9..a5bc391589 100644 --- a/layout/xul/grid/nsGridRow.h +++ b/layout/xul/grid/nsGridRow.h @@ -35,7 +35,7 @@ public: bool IsMaxSet() { return (mMax != -1); } bool IsFlexSet() { return (mFlex != -1); } bool IsOffsetSet() { return (mTop != -1 && mBottom != -1); } - bool IsCollapsed(); + bool IsXULCollapsed(); public: diff --git a/layout/xul/grid/nsGridRowGroupFrame.cpp b/layout/xul/grid/nsGridRowGroupFrame.cpp index 9ec59a0361..5b72d3753f 100644 --- a/layout/xul/grid/nsGridRowGroupFrame.cpp +++ b/layout/xul/grid/nsGridRowGroupFrame.cpp @@ -34,7 +34,7 @@ NS_IMPL_FRAMEARENA_HELPERS(nsGridRowGroupFrame) * then their flex must be equal to the sum of their children's flexes. */ nscoord -nsGridRowGroupFrame::GetFlex() +nsGridRowGroupFrame::GetXULFlex() { // if we are flexible out flexibility is determined by our columns. // so first get the our flex. If not 0 then our flex is the sum of @@ -43,16 +43,16 @@ nsGridRowGroupFrame::GetFlex() if (!DoesNeedRecalc(mFlex)) return mFlex; - if (nsBoxFrame::GetFlex() == 0) + if (nsBoxFrame::GetXULFlex() == 0) return 0; // ok we are flexible add up our children nscoord totalFlex = 0; - nsIFrame* child = nsBox::GetChildBox(this); + nsIFrame* child = nsBox::GetChildXULBox(this); while (child) { - totalFlex += child->GetFlex(); - child = GetNextBox(child); + totalFlex += child->GetXULFlex(); + child = GetNextXULBox(child); } mFlex = totalFlex; diff --git a/layout/xul/grid/nsGridRowGroupFrame.h b/layout/xul/grid/nsGridRowGroupFrame.h index c0eda0c1c6..f367e21216 100644 --- a/layout/xul/grid/nsGridRowGroupFrame.h +++ b/layout/xul/grid/nsGridRowGroupFrame.h @@ -39,7 +39,7 @@ public: nsBoxLayout* aLayoutManager): nsBoxFrame(aContext, false, aLayoutManager) {} - virtual nscoord GetFlex() override; + virtual nscoord GetXULFlex() override; }; // class nsGridRowGroupFrame diff --git a/layout/xul/grid/nsGridRowGroupLayout.cpp b/layout/xul/grid/nsGridRowGroupLayout.cpp index 72ad10c8aa..115c5edeaf 100644 --- a/layout/xul/grid/nsGridRowGroupLayout.cpp +++ b/layout/xul/grid/nsGridRowGroupLayout.cpp @@ -43,7 +43,7 @@ nsGridRowGroupLayout::ChildAddedOrRemoved(nsIFrame* aBox, nsBoxLayoutState& aSta { int32_t index = 0; nsGrid* grid = GetGrid(aBox, &index); - bool isHorizontal = IsHorizontal(aBox); + bool isHorizontal = IsXULHorizontal(aBox); if (grid) grid->RowAddedOrRemoved(aState, index, isHorizontal); @@ -61,9 +61,9 @@ nsGridRowGroupLayout::AddWidth(nsSize& aSize, nscoord aSize2, bool aIsHorizontal } nsSize -nsGridRowGroupLayout::GetPrefSize(nsIFrame* aBox, nsBoxLayoutState& aState) +nsGridRowGroupLayout::GetXULPrefSize(nsIFrame* aBox, nsBoxLayoutState& aState) { - nsSize vpref = nsGridRowLayout::GetPrefSize(aBox, aState); + nsSize vpref = nsGridRowLayout::GetXULPrefSize(aBox, aState); /* It is possible that we could have some extra columns. This is when less columns in XUL were @@ -79,7 +79,7 @@ nsGridRowGroupLayout::GetPrefSize(nsIFrame* aBox, nsBoxLayoutState& aState) if (grid) { // make sure we add in extra columns sizes as well - bool isHorizontal = IsHorizontal(aBox); + bool isHorizontal = IsXULHorizontal(aBox); int32_t extraColumns = grid->GetExtraColumnCount(isHorizontal); int32_t start = grid->GetColumnCount(isHorizontal) - grid->GetExtraColumnCount(isHorizontal); for (int32_t i=0; i < extraColumns; i++) @@ -95,9 +95,9 @@ nsGridRowGroupLayout::GetPrefSize(nsIFrame* aBox, nsBoxLayoutState& aState) } nsSize -nsGridRowGroupLayout::GetMaxSize(nsIFrame* aBox, nsBoxLayoutState& aState) +nsGridRowGroupLayout::GetXULMaxSize(nsIFrame* aBox, nsBoxLayoutState& aState) { - nsSize maxSize = nsGridRowLayout::GetMaxSize(aBox, aState); + nsSize maxSize = nsGridRowLayout::GetXULMaxSize(aBox, aState); int32_t index = 0; nsGrid* grid = GetGrid(aBox, &index); @@ -105,7 +105,7 @@ nsGridRowGroupLayout::GetMaxSize(nsIFrame* aBox, nsBoxLayoutState& aState) if (grid) { // make sure we add in extra columns sizes as well - bool isHorizontal = IsHorizontal(aBox); + bool isHorizontal = IsXULHorizontal(aBox); int32_t extraColumns = grid->GetExtraColumnCount(isHorizontal); int32_t start = grid->GetColumnCount(isHorizontal) - grid->GetExtraColumnCount(isHorizontal); for (int32_t i=0; i < extraColumns; i++) @@ -121,9 +121,9 @@ nsGridRowGroupLayout::GetMaxSize(nsIFrame* aBox, nsBoxLayoutState& aState) } nsSize -nsGridRowGroupLayout::GetMinSize(nsIFrame* aBox, nsBoxLayoutState& aState) +nsGridRowGroupLayout::GetXULMinSize(nsIFrame* aBox, nsBoxLayoutState& aState) { - nsSize minSize = nsGridRowLayout::GetMinSize(aBox, aState); + nsSize minSize = nsGridRowLayout::GetXULMinSize(aBox, aState); int32_t index = 0; nsGrid* grid = GetGrid(aBox, &index); @@ -131,7 +131,7 @@ nsGridRowGroupLayout::GetMinSize(nsIFrame* aBox, nsBoxLayoutState& aState) if (grid) { // make sure we add in extra columns sizes as well - bool isHorizontal = IsHorizontal(aBox); + bool isHorizontal = IsXULHorizontal(aBox); int32_t extraColumns = grid->GetExtraColumnCount(isHorizontal); int32_t start = grid->GetColumnCount(isHorizontal) - grid->GetExtraColumnCount(isHorizontal); for (int32_t i=0; i < extraColumns; i++) @@ -157,7 +157,7 @@ nsGridRowGroupLayout::DirtyRows(nsIFrame* aBox, nsBoxLayoutState& aState) // calling MarkIntrinsicISizesDirty for every row group. aState.PresShell()->FrameNeedsReflow(aBox, nsIPresShell::eTreeChange, NS_FRAME_IS_DIRTY); - nsIFrame* child = nsBox::GetChildBox(aBox); + nsIFrame* child = nsBox::GetChildXULBox(aBox); while(child) { @@ -169,7 +169,7 @@ nsGridRowGroupLayout::DirtyRows(nsIFrame* aBox, nsBoxLayoutState& aState) if (monument) monument->DirtyRows(deepChild, aState); - child = nsBox::GetNextBox(child); + child = nsBox::GetNextXULBox(child); } } } @@ -181,7 +181,7 @@ nsGridRowGroupLayout::CountRowsColumns(nsIFrame* aBox, int32_t& aRowCount, int32 if (aBox) { int32_t startCount = aRowCount; - nsIFrame* child = nsBox::GetChildBox(aBox); + nsIFrame* child = nsBox::GetChildXULBox(aBox); while(child) { @@ -191,12 +191,12 @@ nsGridRowGroupLayout::CountRowsColumns(nsIFrame* aBox, int32_t& aRowCount, int32 nsIGridPart* monument = nsGrid::GetPartFromBox(deepChild); if (monument) { monument->CountRowsColumns(deepChild, aRowCount, aComputedColumnCount); - child = nsBox::GetNextBox(child); + child = nsBox::GetNextXULBox(child); deepChild = child; continue; } - child = nsBox::GetNextBox(child); + child = nsBox::GetNextXULBox(child); // if not a monument. Then count it. It will be a bogus row aRowCount++; @@ -216,7 +216,7 @@ nsGridRowGroupLayout::BuildRows(nsIFrame* aBox, nsGridRow* aRows) int32_t rowCount = 0; if (aBox) { - nsIFrame* child = nsBox::GetChildBox(aBox); + nsIFrame* child = nsBox::GetChildXULBox(aBox); while(child) { @@ -226,14 +226,14 @@ nsGridRowGroupLayout::BuildRows(nsIFrame* aBox, nsGridRow* aRows) nsIGridPart* monument = nsGrid::GetPartFromBox(deepChild); if (monument) { rowCount += monument->BuildRows(deepChild, &aRows[rowCount]); - child = nsBox::GetNextBox(child); + child = nsBox::GetNextXULBox(child); deepChild = child; continue; } aRows[rowCount].Init(child, true); - child = nsBox::GetNextBox(child); + child = nsBox::GetNextXULBox(child); // if not a monument. Then count it. It will be a bogus row rowCount++; @@ -256,7 +256,7 @@ nsGridRowGroupLayout::GetTotalMargin(nsIFrame* aBox, bool aIsHorizontal) // add our border/padding to it nsMargin borderPadding(0,0,0,0); - aBox->GetBorderAndPadding(borderPadding); + aBox->GetXULBorderAndPadding(borderPadding); margin += borderPadding; return margin; diff --git a/layout/xul/grid/nsGridRowGroupLayout.h b/layout/xul/grid/nsGridRowGroupLayout.h index 88bb4d9394..07f2aa1eb5 100644 --- a/layout/xul/grid/nsGridRowGroupLayout.h +++ b/layout/xul/grid/nsGridRowGroupLayout.h @@ -26,9 +26,9 @@ public: friend already_AddRefed NS_NewGridRowGroupLayout(); virtual nsGridRowGroupLayout* CastToRowGroupLayout() override { return this; } - virtual nsSize GetMinSize(nsIFrame* aBox, nsBoxLayoutState& aBoxLayoutState) override; - virtual nsSize GetPrefSize(nsIFrame* aBox, nsBoxLayoutState& aBoxLayoutState) override; - virtual nsSize GetMaxSize(nsIFrame* aBox, nsBoxLayoutState& aBoxLayoutState) override; + virtual nsSize GetXULMinSize(nsIFrame* aBox, nsBoxLayoutState& aBoxLayoutState) override; + virtual nsSize GetXULPrefSize(nsIFrame* aBox, nsBoxLayoutState& aBoxLayoutState) override; + virtual nsSize GetXULMaxSize(nsIFrame* aBox, nsBoxLayoutState& aBoxLayoutState) override; virtual void CountRowsColumns(nsIFrame* aBox, int32_t& aRowCount, int32_t& aComputedColumnCount) override; virtual void DirtyRows(nsIFrame* aBox, nsBoxLayoutState& aState) override; virtual int32_t BuildRows(nsIFrame* aBox, nsGridRow* aRows) override; diff --git a/layout/xul/grid/nsGridRowLayout.cpp b/layout/xul/grid/nsGridRowLayout.cpp index 51d8b702bf..a658e088e2 100644 --- a/layout/xul/grid/nsGridRowLayout.cpp +++ b/layout/xul/grid/nsGridRowLayout.cpp @@ -64,7 +64,7 @@ nsGridRowLayout::GetParentGridPart(nsIFrame* aBox, nsIFrame** aParentBox) // get the parent if (aBox) - aBox = nsBox::GetParentBox(aBox); + aBox = nsBox::GetParentXULBox(aBox); if (aBox) { @@ -93,14 +93,14 @@ nsGridRowLayout::GetGrid(nsIFrame* aBox, int32_t* aIndex, nsGridRowLayout* aRequ } int32_t index = -1; - nsIFrame* child = nsBox::GetChildBox(aBox); + nsIFrame* child = nsBox::GetChildXULBox(aBox); int32_t count = 0; while(child) { // if there is a scrollframe walk inside it to its child nsIFrame* childBox = nsGrid::GetScrolledBox(child); - nsBoxLayout* layout = childBox->GetLayoutManager(); + nsBoxLayout* layout = childBox->GetXULLayoutManager(); nsIGridPart* gridRow = nsGrid::GetPartFromBox(childBox); if (gridRow) { @@ -112,7 +112,7 @@ nsGridRowLayout::GetGrid(nsIFrame* aBox, int32_t* aIndex, nsGridRowLayout* aRequ } else count++; - child = nsBox::GetNextBox(child); + child = nsBox::GetNextXULBox(child); } // if we didn't find ourselves then the tree isn't properly formed yet @@ -147,10 +147,10 @@ nsGridRowLayout::GetTotalMargin(nsIFrame* aBox, bool aIsHorizontal) aBox = nsGrid::GetScrollBox(aBox); // see if we have a next to see if we are last - nsIFrame* next = nsBox::GetNextBox(aBox); + nsIFrame* next = nsBox::GetNextXULBox(aBox); // get the parent first child to see if we are first - nsIFrame* child = nsBox::GetChildBox(parent); + nsIFrame* child = nsBox::GetChildXULBox(parent); margin = part->GetTotalMargin(parent, aIsHorizontal); @@ -182,7 +182,7 @@ nsGridRowLayout::GetTotalMargin(nsIFrame* aBox, bool aIsHorizontal) // add ours to it. nsMargin ourMargin; - aBox->GetMargin(ourMargin); + aBox->GetXULMargin(ourMargin); margin += ourMargin; return margin; diff --git a/layout/xul/grid/nsGridRowLeafFrame.cpp b/layout/xul/grid/nsGridRowLeafFrame.cpp index 51bf61cc85..e973877a40 100644 --- a/layout/xul/grid/nsGridRowLeafFrame.cpp +++ b/layout/xul/grid/nsGridRowLeafFrame.cpp @@ -33,10 +33,10 @@ NS_IMPL_FRAMEARENA_HELPERS(nsGridRowLeafFrame) * Let's go check it out. */ nsresult -nsGridRowLeafFrame::GetBorderAndPadding(nsMargin& aBorderAndPadding) +nsGridRowLeafFrame::GetXULBorderAndPadding(nsMargin& aBorderAndPadding) { // if our columns have made our padding larger add it in. - nsresult rv = nsBoxFrame::GetBorderAndPadding(aBorderAndPadding); + nsresult rv = nsBoxFrame::GetXULBorderAndPadding(aBorderAndPadding); nsIGridPart* part = nsGrid::GetPartFromBox(this); if (!part) @@ -48,7 +48,7 @@ nsGridRowLeafFrame::GetBorderAndPadding(nsMargin& aBorderAndPadding) if (!grid) return rv; - bool isHorizontal = IsHorizontal(); + bool isHorizontal = IsXULHorizontal(); int32_t firstIndex = 0; int32_t lastIndex = 0; diff --git a/layout/xul/grid/nsGridRowLeafFrame.h b/layout/xul/grid/nsGridRowLeafFrame.h index 0db102dc75..dd4ee6835d 100644 --- a/layout/xul/grid/nsGridRowLeafFrame.h +++ b/layout/xul/grid/nsGridRowLeafFrame.h @@ -44,7 +44,7 @@ public: nsBoxLayout* aLayoutManager): nsBoxFrame(aContext, aIsRoot, aLayoutManager) {} - virtual nsresult GetBorderAndPadding(nsMargin& aBorderAndPadding) override; + virtual nsresult GetXULBorderAndPadding(nsMargin& aBorderAndPadding) override; }; // class nsGridRowLeafFrame diff --git a/layout/xul/grid/nsGridRowLeafLayout.cpp b/layout/xul/grid/nsGridRowLeafLayout.cpp index 65285bceba..2a089af0c8 100644 --- a/layout/xul/grid/nsGridRowLeafLayout.cpp +++ b/layout/xul/grid/nsGridRowLeafLayout.cpp @@ -35,16 +35,16 @@ nsGridRowLeafLayout::~nsGridRowLeafLayout() } nsSize -nsGridRowLeafLayout::GetPrefSize(nsIFrame* aBox, nsBoxLayoutState& aState) +nsGridRowLeafLayout::GetXULPrefSize(nsIFrame* aBox, nsBoxLayoutState& aState) { int32_t index = 0; nsGrid* grid = GetGrid(aBox, &index); - bool isHorizontal = IsHorizontal(aBox); + bool isHorizontal = IsXULHorizontal(aBox); // If we are not in a grid. Then we just work like a box. But if we are in a grid // ask the grid for our size. if (!grid) { - return nsGridRowLayout::GetPrefSize(aBox, aState); + return nsGridRowLayout::GetXULPrefSize(aBox, aState); } else { return grid->GetPrefRowSize(aState, index, isHorizontal); @@ -53,14 +53,14 @@ nsGridRowLeafLayout::GetPrefSize(nsIFrame* aBox, nsBoxLayoutState& aState) } nsSize -nsGridRowLeafLayout::GetMinSize(nsIFrame* aBox, nsBoxLayoutState& aState) +nsGridRowLeafLayout::GetXULMinSize(nsIFrame* aBox, nsBoxLayoutState& aState) { int32_t index = 0; nsGrid* grid = GetGrid(aBox, &index); - bool isHorizontal = IsHorizontal(aBox); + bool isHorizontal = IsXULHorizontal(aBox); if (!grid) - return nsGridRowLayout::GetMinSize(aBox, aState); + return nsGridRowLayout::GetXULMinSize(aBox, aState); else { nsSize minSize = grid->GetMinRowSize(aState, index, isHorizontal); AddBorderAndPadding(aBox, minSize); @@ -69,14 +69,14 @@ nsGridRowLeafLayout::GetMinSize(nsIFrame* aBox, nsBoxLayoutState& aState) } nsSize -nsGridRowLeafLayout::GetMaxSize(nsIFrame* aBox, nsBoxLayoutState& aState) +nsGridRowLeafLayout::GetXULMaxSize(nsIFrame* aBox, nsBoxLayoutState& aState) { int32_t index = 0; nsGrid* grid = GetGrid(aBox, &index); - bool isHorizontal = IsHorizontal(aBox); + bool isHorizontal = IsXULHorizontal(aBox); if (!grid) - return nsGridRowLayout::GetMaxSize(aBox, aState); + return nsGridRowLayout::GetXULMaxSize(aBox, aState); else { nsSize maxSize; maxSize = grid->GetMaxRowSize(aState, index, isHorizontal); @@ -92,7 +92,7 @@ nsGridRowLeafLayout::ChildAddedOrRemoved(nsIFrame* aBox, nsBoxLayoutState& aStat { int32_t index = 0; nsGrid* grid = GetGrid(aBox, &index); - bool isHorizontal = IsHorizontal(aBox); + bool isHorizontal = IsXULHorizontal(aBox); if (grid) grid->CellAddedOrRemoved(aState, index, isHorizontal); @@ -103,7 +103,7 @@ nsGridRowLeafLayout::PopulateBoxSizes(nsIFrame* aBox, nsBoxLayoutState& aState, { int32_t index = 0; nsGrid* grid = GetGrid(aBox, &index); - bool isHorizontal = IsHorizontal(aBox); + bool isHorizontal = IsXULHorizontal(aBox); // Our base class SprocketLayout is giving us a chance to change the box sizes before layout // If we are a row lets change the sizes to match our columns. If we are a column then do the opposite @@ -114,7 +114,7 @@ nsGridRowLeafLayout::PopulateBoxSizes(nsIFrame* aBox, nsBoxLayoutState& aState, nsBoxSize* start = nullptr; nsBoxSize* last = nullptr; nsBoxSize* current = nullptr; - nsIFrame* child = nsBox::GetChildBox(aBox); + nsIFrame* child = nsBox::GetChildXULBox(aBox); for (int i=0; i < count; i++) { column = grid->GetColumnAt(i,isHorizontal); @@ -137,7 +137,7 @@ nsGridRowLeafLayout::PopulateBoxSizes(nsIFrame* aBox, nsBoxLayoutState& aState, nscoord bottomMargin = column->mBottomMargin; if (box) - collapsed = box->IsCollapsed(); + collapsed = box->IsXULCollapsed(); pref = pref - (left + right); if (pref < 0) @@ -159,9 +159,9 @@ nsGridRowLeafLayout::PopulateBoxSizes(nsIFrame* aBox, nsBoxLayoutState& aState, nsMargin border(0,0,0,0); // can't call GetBorderPadding we will get into recursion - aBox->GetBorder(border); + aBox->GetXULBorder(border); offset += border; - aBox->GetPadding(border); + aBox->GetXULPadding(border); offset += border; // subtract from out left and right @@ -205,7 +205,7 @@ nsGridRowLeafLayout::PopulateBoxSizes(nsIFrame* aBox, nsBoxLayoutState& aState, } if (child && !column->mIsBogus) - child = nsBox::GetNextBox(child); + child = nsBox::GetNextXULBox(child); } aBoxSizes = start; @@ -224,7 +224,7 @@ nsGridRowLeafLayout::ComputeChildSizes(nsIFrame* aBox, // see if we are in a scrollable frame. If we are then there could be scrollbars present // if so we need to subtract them out to make sure our columns line up. if (aBox) { - bool isHorizontal = aBox->IsHorizontal(); + bool isHorizontal = aBox->IsXULHorizontal(); // go up the parent chain looking for scrollframes nscoord diff = 0; @@ -277,9 +277,9 @@ nsGridRowLeafLayout::ComputeChildSizes(nsIFrame* aBox, } NS_IMETHODIMP -nsGridRowLeafLayout::Layout(nsIFrame* aBox, nsBoxLayoutState& aBoxLayoutState) +nsGridRowLeafLayout::XULLayout(nsIFrame* aBox, nsBoxLayoutState& aBoxLayoutState) { - return nsGridRowLayout::Layout(aBox, aBoxLayoutState); + return nsGridRowLayout::XULLayout(aBox, aBoxLayoutState); } void @@ -298,12 +298,12 @@ void nsGridRowLeafLayout::CountRowsColumns(nsIFrame* aBox, int32_t& aRowCount, int32_t& aComputedColumnCount) { if (aBox) { - nsIFrame* child = nsBox::GetChildBox(aBox); + nsIFrame* child = nsBox::GetChildXULBox(aBox); // count the children int32_t columnCount = 0; while(child) { - child = nsBox::GetNextBox(child); + child = nsBox::GetNextXULBox(child); columnCount++; } diff --git a/layout/xul/grid/nsGridRowLeafLayout.h b/layout/xul/grid/nsGridRowLeafLayout.h index 75cba7310b..b103ab176b 100644 --- a/layout/xul/grid/nsGridRowLeafLayout.h +++ b/layout/xul/grid/nsGridRowLeafLayout.h @@ -28,11 +28,11 @@ public: friend already_AddRefed NS_NewGridRowLeafLayout(); - virtual nsSize GetPrefSize(nsIFrame* aBox, nsBoxLayoutState& aBoxLayoutState) override; - virtual nsSize GetMinSize(nsIFrame* aBox, nsBoxLayoutState& aBoxLayoutState) override; - virtual nsSize GetMaxSize(nsIFrame* aBox, nsBoxLayoutState& aBoxLayoutState) override; + virtual nsSize GetXULPrefSize(nsIFrame* aBox, nsBoxLayoutState& aBoxLayoutState) override; + virtual nsSize GetXULMinSize(nsIFrame* aBox, nsBoxLayoutState& aBoxLayoutState) override; + virtual nsSize GetXULMaxSize(nsIFrame* aBox, nsBoxLayoutState& aBoxLayoutState) override; virtual void ChildAddedOrRemoved(nsIFrame* aBox, nsBoxLayoutState& aState) override; - NS_IMETHOD Layout(nsIFrame* aBox, nsBoxLayoutState& aBoxLayoutState) override; + NS_IMETHOD XULLayout(nsIFrame* aBox, nsBoxLayoutState& aBoxLayoutState) override; virtual void CountRowsColumns(nsIFrame* aBox, int32_t& aRowCount, int32_t& aComputedColumnCount) override; virtual void DirtyRows(nsIFrame* aBox, nsBoxLayoutState& aState) override; virtual int32_t BuildRows(nsIFrame* aBox, nsGridRow* aRows) override; diff --git a/layout/xul/nsBox.cpp b/layout/xul/nsBox.cpp index 4d5bbc7895..6c6ce43f0c 100644 --- a/layout/xul/nsBox.cpp +++ b/layout/xul/nsBox.cpp @@ -85,7 +85,7 @@ nsBox::ListBox(nsAutoString& aResult) } nsresult -nsBox::DumpBox(FILE* aFile) +nsBox::XULDumpBox(FILE* aFile) { nsAutoString s; ListBox(s); @@ -99,11 +99,11 @@ nsBox::PropagateDebug(nsBoxLayoutState& aState) // propagate debug information if (mState & NS_STATE_DEBUG_WAS_SET) { if (mState & NS_STATE_SET_TO_DEBUG) - SetDebug(aState, true); + SetXULDebug(aState, true); else - SetDebug(aState, false); + SetXULDebug(aState, false); } else if (mState & NS_STATE_IS_ROOT) { - SetDebug(aState, gDebug); + SetXULDebug(aState, gDebug); } } #endif @@ -117,13 +117,13 @@ nsBox::GetBoxName(nsAutoString& aName) #endif nsresult -nsBox::BeginLayout(nsBoxLayoutState& aState) +nsBox::BeginXULLayout(nsBoxLayoutState& aState) { #ifdef DEBUG_LAYOUT nsBoxAddIndents(); - printf("Layout: "); - DumpBox(stdout); + printf("XULLayout: "); + XULDumpBox(stdout); printf("\n"); gIndent++; #endif @@ -138,7 +138,7 @@ nsBox::BeginLayout(nsBoxLayoutState& aState) // If the parent is dirty, all the children are dirty (nsHTMLReflowState // does this too). nsIFrame* box; - for (box = GetChildBox(this); box; box = GetNextBox(box)) + for (box = GetChildXULBox(this); box; box = GetNextXULBox(box)) box->AddStateBits(NS_FRAME_IS_DIRTY); } @@ -157,13 +157,13 @@ nsBox::BeginLayout(nsBoxLayoutState& aState) } NS_IMETHODIMP -nsBox::DoLayout(nsBoxLayoutState& aState) +nsBox::DoXULLayout(nsBoxLayoutState& aState) { return NS_OK; } nsresult -nsBox::EndLayout(nsBoxLayoutState& aState) +nsBox::EndXULLayout(nsBoxLayoutState& aState) { #ifdef DEBUG_LAYOUT @@ -202,19 +202,19 @@ nsBox::Shutdown() } nsresult -nsBox::RelayoutChildAtOrdinal(nsIFrame* aChild) +nsBox::XULRelayoutChildAtOrdinal(nsIFrame* aChild) { return NS_OK; } nsresult -nsIFrame::GetClientRect(nsRect& aClientRect) +nsIFrame::GetXULClientRect(nsRect& aClientRect) { aClientRect = mRect; aClientRect.MoveTo(0,0); nsMargin borderPadding; - GetBorderAndPadding(borderPadding); + GetXULBorderAndPadding(borderPadding); aClientRect.Deflate(borderPadding); @@ -230,9 +230,9 @@ nsIFrame::GetClientRect(nsRect& aClientRect) } void -nsBox::SetBounds(nsBoxLayoutState& aState, const nsRect& aRect, bool aRemoveOverflowAreas) +nsBox::SetXULBounds(nsBoxLayoutState& aState, const nsRect& aRect, bool aRemoveOverflowAreas) { - NS_BOX_ASSERTION(this, aRect.width >=0 && aRect.height >= 0, "SetBounds Size < 0"); + NS_BOX_ASSERTION(this, aRect.width >=0 && aRect.height >= 0, "SetXULBounds Size < 0"); nsRect rect(mRect); @@ -284,15 +284,15 @@ nsBox::GetLayoutFlags(uint32_t& aFlags) nsresult -nsIFrame::GetBorderAndPadding(nsMargin& aBorderAndPadding) +nsIFrame::GetXULBorderAndPadding(nsMargin& aBorderAndPadding) { aBorderAndPadding.SizeTo(0, 0, 0, 0); - nsresult rv = GetBorder(aBorderAndPadding); + nsresult rv = GetXULBorder(aBorderAndPadding); if (NS_FAILED(rv)) return rv; nsMargin padding; - rv = GetPadding(padding); + rv = GetXULPadding(padding); if (NS_FAILED(rv)) return rv; @@ -302,7 +302,7 @@ nsIFrame::GetBorderAndPadding(nsMargin& aBorderAndPadding) } nsresult -nsBox::GetBorder(nsMargin& aMargin) +nsBox::GetXULBorder(nsMargin& aMargin) { aMargin.SizeTo(0,0,0,0); @@ -328,7 +328,7 @@ nsBox::GetBorder(nsMargin& aMargin) } nsresult -nsBox::GetPadding(nsMargin& aMargin) +nsBox::GetXULPadding(nsMargin& aMargin) { const nsStyleDisplay *disp = StyleDisplay(); if (disp->mAppearance && gTheme) { @@ -358,7 +358,7 @@ nsBox::GetPadding(nsMargin& aMargin) } nsresult -nsBox::GetMargin(nsMargin& aMargin) +nsBox::GetXULMargin(nsMargin& aMargin) { aMargin.SizeTo(0,0,0,0); StyleMargin()->GetMargin(aMargin); @@ -392,77 +392,77 @@ nsBox::DoesNeedRecalc(nscoord aCoord) } nsSize -nsBox::GetPrefSize(nsBoxLayoutState& aState) +nsBox::GetXULPrefSize(nsBoxLayoutState& aState) { NS_ASSERTION(aState.GetRenderingContext(), "must have rendering context"); nsSize pref(0,0); DISPLAY_PREF_SIZE(this, pref); - if (IsCollapsed()) + if (IsXULCollapsed()) return pref; AddBorderAndPadding(pref); bool widthSet, heightSet; - nsIFrame::AddCSSPrefSize(this, pref, widthSet, heightSet); + nsIFrame::AddXULPrefSize(this, pref, widthSet, heightSet); - nsSize minSize = GetMinSize(aState); - nsSize maxSize = GetMaxSize(aState); + nsSize minSize = GetXULMinSize(aState); + nsSize maxSize = GetXULMaxSize(aState); return BoundsCheck(minSize, pref, maxSize); } nsSize -nsBox::GetMinSize(nsBoxLayoutState& aState) +nsBox::GetXULMinSize(nsBoxLayoutState& aState) { NS_ASSERTION(aState.GetRenderingContext(), "must have rendering context"); nsSize min(0,0); DISPLAY_MIN_SIZE(this, min); - if (IsCollapsed()) + if (IsXULCollapsed()) return min; AddBorderAndPadding(min); bool widthSet, heightSet; - nsIFrame::AddCSSMinSize(aState, this, min, widthSet, heightSet); + nsIFrame::AddXULMinSize(aState, this, min, widthSet, heightSet); return min; } nsSize -nsBox::GetMinSizeForScrollArea(nsBoxLayoutState& aBoxLayoutState) +nsBox::GetXULMinSizeForScrollArea(nsBoxLayoutState& aBoxLayoutState) { return nsSize(0, 0); } nsSize -nsBox::GetMaxSize(nsBoxLayoutState& aState) +nsBox::GetXULMaxSize(nsBoxLayoutState& aState) { NS_ASSERTION(aState.GetRenderingContext(), "must have rendering context"); nsSize maxSize(NS_INTRINSICSIZE, NS_INTRINSICSIZE); DISPLAY_MAX_SIZE(this, maxSize); - if (IsCollapsed()) + if (IsXULCollapsed()) return maxSize; AddBorderAndPadding(maxSize); bool widthSet, heightSet; - nsIFrame::AddCSSMaxSize(this, maxSize, widthSet, heightSet); + nsIFrame::AddXULMaxSize(this, maxSize, widthSet, heightSet); return maxSize; } nscoord -nsBox::GetFlex() +nsBox::GetXULFlex() { nscoord flex = 0; - nsIFrame::AddCSSFlex(this, flex); + nsIFrame::AddXULFlex(this, flex); return flex; } uint32_t -nsIFrame::GetOrdinal() +nsIFrame::GetXULOrdinal() { uint32_t ordinal = StyleXUL()->mBoxOrdinal; @@ -482,33 +482,33 @@ nsIFrame::GetOrdinal() } nscoord -nsBox::GetBoxAscent(nsBoxLayoutState& aState) +nsBox::GetXULBoxAscent(nsBoxLayoutState& aState) { - if (IsCollapsed()) + if (IsXULCollapsed()) return 0; - return GetPrefSize(aState).height; + return GetXULPrefSize(aState).height; } bool -nsBox::IsCollapsed() +nsBox::IsXULCollapsed() { return StyleVisibility()->mVisible == NS_STYLE_VISIBILITY_COLLAPSE; } nsresult -nsIFrame::Layout(nsBoxLayoutState& aState) +nsIFrame::XULLayout(nsBoxLayoutState& aState) { NS_ASSERTION(aState.GetRenderingContext(), "must have rendering context"); nsBox *box = static_cast(this); DISPLAY_LAYOUT(box); - box->BeginLayout(aState); + box->BeginXULLayout(aState); - box->DoLayout(aState); + box->DoXULLayout(aState); - box->EndLayout(aState); + box->EndXULLayout(aState); return NS_OK; } @@ -527,7 +527,7 @@ nsresult nsBox::SyncLayout(nsBoxLayoutState& aState) { /* - if (IsCollapsed()) { + if (IsXULCollapsed()) { CollapseChild(aState, this, true); return NS_OK; } @@ -535,7 +535,7 @@ nsBox::SyncLayout(nsBoxLayoutState& aState) if (GetStateBits() & NS_FRAME_IS_DIRTY) - Redraw(aState); + XULRedraw(aState); RemoveStateBits(NS_FRAME_HAS_DIRTY_CHILDREN | NS_FRAME_IS_DIRTY | NS_FRAME_FIRST_REFLOW | NS_FRAME_IN_REFLOW); @@ -557,7 +557,7 @@ nsBox::SyncLayout(nsBoxLayoutState& aState) else { nsRect rect(nsPoint(0, 0), GetSize()); nsOverflowAreas overflowAreas(rect, rect); - if (!DoesClipChildren() && !IsCollapsed()) { + if (!DoesClipChildren() && !IsXULCollapsed()) { // See if our child frames caused us to overflow after being laid // out. If so, store the overflow area. This normally can't happen // in XUL, but it can happen with the CSS 'outline' property and @@ -582,7 +582,7 @@ nsBox::SyncLayout(nsBoxLayoutState& aState) } nsresult -nsIFrame::Redraw(nsBoxLayoutState& aState) +nsIFrame::XULRedraw(nsBoxLayoutState& aState) { if (aState.PaintingDisabled()) return NS_OK; @@ -595,7 +595,7 @@ nsIFrame::Redraw(nsBoxLayoutState& aState) } bool -nsIFrame::AddCSSPrefSize(nsIFrame* aBox, nsSize& aSize, bool &aWidthSet, bool &aHeightSet) +nsIFrame::AddXULPrefSize(nsIFrame* aBox, nsSize& aSize, bool &aWidthSet, bool &aHeightSet) { aWidthSet = false; aHeightSet = false; @@ -606,7 +606,7 @@ nsIFrame::AddCSSPrefSize(nsIFrame* aBox, nsSize& aSize, bool &aWidthSet, bool &a // see if the width or height was specifically set // XXX Handle eStyleUnit_Enumerated? // (Handling the eStyleUnit_Enumerated types requires - // GetPrefSize/GetMinSize methods that don't consider + // GetXULPrefSize/GetXULMinSize methods that don't consider // (min-/max-/)(width/height) properties.) const nsStyleCoord &width = position->mWidth; if (width.GetUnit() == eStyleUnit_Coord) { @@ -668,7 +668,7 @@ nsIFrame::AddCSSPrefSize(nsIFrame* aBox, nsSize& aSize, bool &aWidthSet, bool &a bool -nsIFrame::AddCSSMinSize(nsBoxLayoutState& aState, nsIFrame* aBox, nsSize& aSize, +nsIFrame::AddXULMinSize(nsBoxLayoutState& aState, nsIFrame* aBox, nsSize& aSize, bool &aWidthSet, bool &aHeightSet) { aWidthSet = false; @@ -718,7 +718,7 @@ nsIFrame::AddCSSMinSize(nsBoxLayoutState& aState, nsIFrame* aBox, nsSize& aSize, } // XXX Handle eStyleUnit_Enumerated? // (Handling the eStyleUnit_Enumerated types requires - // GetPrefSize/GetMinSize methods that don't consider + // GetXULPrefSize/GetXULMinSize methods that don't consider // (min-/max-/)(width/height) properties. // calc() with percentage is treated like '0' (unset) @@ -775,7 +775,7 @@ nsIFrame::AddCSSMinSize(nsBoxLayoutState& aState, nsIFrame* aBox, nsSize& aSize, } bool -nsIFrame::AddCSSMaxSize(nsIFrame* aBox, nsSize& aSize, bool &aWidthSet, bool &aHeightSet) +nsIFrame::AddXULMaxSize(nsIFrame* aBox, nsSize& aSize, bool &aWidthSet, bool &aHeightSet) { aWidthSet = false; aHeightSet = false; @@ -787,7 +787,7 @@ nsIFrame::AddCSSMaxSize(nsIFrame* aBox, nsSize& aSize, bool &aWidthSet, bool &aH // see if the width or height was specifically set // XXX Handle eStyleUnit_Enumerated? // (Handling the eStyleUnit_Enumerated types requires - // GetPrefSize/GetMinSize methods that don't consider + // GetXULPrefSize/GetXULMinSize methods that don't consider // (min-/max-/)(width/height) properties.) const nsStyleCoord maxWidth = position->mMaxWidth; if (maxWidth.ConvertsToLength()) { @@ -834,7 +834,7 @@ nsIFrame::AddCSSMaxSize(nsIFrame* aBox, nsSize& aSize, bool &aWidthSet, bool &aH } bool -nsIFrame::AddCSSFlex(nsIFrame* aBox, nscoord& aFlex) +nsIFrame::AddXULFlex(nsIFrame* aBox, nscoord& aFlex) { bool flexSet = false; @@ -873,7 +873,7 @@ void nsBox::AddBorderAndPadding(nsIFrame* aBox, nsSize& aSize) { nsMargin borderPadding(0,0,0,0); - aBox->GetBorderAndPadding(borderPadding); + aBox->GetXULBorderAndPadding(borderPadding); AddMargin(aSize, borderPadding); } @@ -881,7 +881,7 @@ void nsBox::AddMargin(nsIFrame* aChild, nsSize& aSize) { nsMargin margin(0,0,0,0); - aChild->GetMargin(margin); + aChild->GetXULMargin(margin); AddMargin(aSize, margin); } @@ -922,30 +922,30 @@ nsBox::BoundsCheck(const nsSize& aMinSize, const nsSize& aPrefSize, const nsSize } /*static*/ nsIFrame* -nsBox::GetChildBox(const nsIFrame* aFrame) +nsBox::GetChildXULBox(const nsIFrame* aFrame) { // box layout ends at box-wrapped frames, so don't allow these frames // to report child boxes. - return aFrame->IsBoxFrame() ? aFrame->PrincipalChildList().FirstChild() : nullptr; + return aFrame->IsXULBoxFrame() ? aFrame->PrincipalChildList().FirstChild() : nullptr; } /*static*/ nsIFrame* -nsBox::GetNextBox(const nsIFrame* aFrame) +nsBox::GetNextXULBox(const nsIFrame* aFrame) { return aFrame->GetParent() && - aFrame->GetParent()->IsBoxFrame() ? aFrame->GetNextSibling() : nullptr; + aFrame->GetParent()->IsXULBoxFrame() ? aFrame->GetNextSibling() : nullptr; } /*static*/ nsIFrame* -nsBox::GetParentBox(const nsIFrame* aFrame) +nsBox::GetParentXULBox(const nsIFrame* aFrame) { return aFrame->GetParent() && - aFrame->GetParent()->IsBoxFrame() ? aFrame->GetParent() : nullptr; + aFrame->GetParent()->IsXULBoxFrame() ? aFrame->GetParent() : nullptr; } #ifdef DEBUG_LAYOUT nsresult -nsBox::SetDebug(nsBoxLayoutState& aState, bool aDebug) +nsBox::SetXULDebug(nsBoxLayoutState& aState, bool aDebug) { return NS_OK; } @@ -958,7 +958,7 @@ nsBox::GetDebugBoxAt( const nsPoint& aPoint, if (!thisRect.Contains(aPoint)) return NS_ERROR_FAILURE; - nsIFrame* child = nsBox::GetChildBox(this); + nsIFrame* child = nsBox::GetChildXULBox(this); nsIFrame* hit = nullptr; *aBox = nullptr; @@ -968,7 +968,7 @@ nsBox::GetDebugBoxAt( const nsPoint& aPoint, if (NS_SUCCEEDED(rv) && hit) { *aBox = hit; } - child = GetNextBox(child); + child = GetNextXULBox(child); } // found a child @@ -981,7 +981,7 @@ nsBox::GetDebugBoxAt( const nsPoint& aPoint, nsresult -nsBox::GetDebug(bool& aDebug) +nsBox::GetXULDebug(bool& aDebug) { aDebug = false; return NS_OK; diff --git a/layout/xul/nsBox.h b/layout/xul/nsBox.h index d9062e5fba..1c04fcf634 100644 --- a/layout/xul/nsBox.h +++ b/layout/xul/nsBox.h @@ -19,34 +19,34 @@ public: static void Shutdown(); - virtual nsSize GetPrefSize(nsBoxLayoutState& aBoxLayoutState) override; - virtual nsSize GetMinSize(nsBoxLayoutState& aBoxLayoutState) override; - virtual nsSize GetMaxSize(nsBoxLayoutState& aBoxLayoutState) override; - virtual nscoord GetFlex() override; - virtual nscoord GetBoxAscent(nsBoxLayoutState& aBoxLayoutState) override; + virtual nsSize GetXULPrefSize(nsBoxLayoutState& aBoxLayoutState) override; + virtual nsSize GetXULMinSize(nsBoxLayoutState& aBoxLayoutState) override; + virtual nsSize GetXULMaxSize(nsBoxLayoutState& aBoxLayoutState) override; + virtual nscoord GetXULFlex() override; + virtual nscoord GetXULBoxAscent(nsBoxLayoutState& aBoxLayoutState) override; - virtual nsSize GetMinSizeForScrollArea(nsBoxLayoutState& aBoxLayoutState) override; + virtual nsSize GetXULMinSizeForScrollArea(nsBoxLayoutState& aBoxLayoutState) override; - virtual bool IsCollapsed() override; + virtual bool IsXULCollapsed() override; - virtual void SetBounds(nsBoxLayoutState& aBoxLayoutState, const nsRect& aRect, - bool aRemoveOverflowAreas = false) override; + virtual void SetXULBounds(nsBoxLayoutState& aBoxLayoutState, const nsRect& aRect, + bool aRemoveOverflowAreas = false) override; - virtual nsresult GetBorder(nsMargin& aBorderAndPadding) override; - virtual nsresult GetPadding(nsMargin& aBorderAndPadding) override; - virtual nsresult GetMargin(nsMargin& aMargin) override; + virtual nsresult GetXULBorder(nsMargin& aBorderAndPadding) override; + virtual nsresult GetXULPadding(nsMargin& aBorderAndPadding) override; + virtual nsresult GetXULMargin(nsMargin& aMargin) override; - virtual Valignment GetVAlign() const override { return vAlign_Top; } - virtual Halignment GetHAlign() const override { return hAlign_Left; } + virtual Valignment GetXULVAlign() const override { return vAlign_Top; } + virtual Halignment GetXULHAlign() const override { return hAlign_Left; } - virtual nsresult RelayoutChildAtOrdinal(nsIFrame* aChild) override; + virtual nsresult XULRelayoutChildAtOrdinal(nsIFrame* aChild) override; #ifdef DEBUG_LAYOUT NS_IMETHOD GetDebugBoxAt(const nsPoint& aPoint, nsIFrame** aBox); - virtual nsresult GetDebug(bool& aDebug) override; - virtual nsresult SetDebug(nsBoxLayoutState& aState, bool aDebug) override; + virtual nsresult GetXULDebug(bool& aDebug) override; + virtual nsresult SetXULDebug(nsBoxLayoutState& aState, bool aDebug) override; - virtual nsresult DumpBox(FILE* out) override; + virtual nsresult XULDumpBox(FILE* out) override; void PropagateDebug(nsBoxLayoutState& aState); #endif @@ -77,9 +77,9 @@ rollbox. static nsSize BoundsCheck(const nsSize& aMinSize, const nsSize& aPrefSize, const nsSize& aMaxSize); static nscoord BoundsCheck(nscoord aMinSize, nscoord aPrefSize, nscoord aMaxSize); - static nsIFrame* GetChildBox(const nsIFrame* aFrame); - static nsIFrame* GetNextBox(const nsIFrame* aFrame); - static nsIFrame* GetParentBox(const nsIFrame* aFrame); + static nsIFrame* GetChildXULBox(const nsIFrame* aFrame); + static nsIFrame* GetNextXULBox(const nsIFrame* aFrame); + static nsIFrame* GetParentXULBox(const nsIFrame* aFrame); protected: @@ -91,9 +91,9 @@ protected: virtual void GetLayoutFlags(uint32_t& aFlags); - nsresult BeginLayout(nsBoxLayoutState& aState); - NS_IMETHOD DoLayout(nsBoxLayoutState& aBoxLayoutState); - nsresult EndLayout(nsBoxLayoutState& aState); + nsresult BeginXULLayout(nsBoxLayoutState& aState); + NS_IMETHOD DoXULLayout(nsBoxLayoutState& aBoxLayoutState); + nsresult EndXULLayout(nsBoxLayoutState& aState); #ifdef DEBUG_LAYOUT virtual void GetBoxName(nsAutoString& aName); @@ -118,7 +118,7 @@ private: #ifdef DEBUG_LAYOUT #define NS_BOX_ASSERTION(box,expr,str) \ if (!(expr)) { \ - box->DumpBox(stdout); \ + box->XULDumpBox(stdout); \ NS_DebugBreak(NSDebugAssertion, str, #expr, __FILE__, __LINE__); \ } #else diff --git a/layout/xul/nsBoxFrame.cpp b/layout/xul/nsBoxFrame.cpp index 424b2aa162..0e1a27b5af 100644 --- a/layout/xul/nsBoxFrame.cpp +++ b/layout/xul/nsBoxFrame.cpp @@ -136,7 +136,7 @@ nsBoxFrame::nsBoxFrame(nsStyleContext* aContext, NS_NewSprocketLayout(layout); } - SetLayoutManager(layout); + SetXULLayoutManager(layout); } nsBoxFrame::~nsBoxFrame() @@ -221,7 +221,7 @@ nsBoxFrame::CacheAttributes() { /* printf("Caching: "); - DumpBox(stdout); + XULDumpBox(stdout); printf("\n"); */ @@ -315,7 +315,7 @@ nsBoxFrame::GetInitialHAlignment(nsBoxFrame::Halignment& aHalign) // Now that the deprecated stuff is out of the way, we move on to check the appropriate // attribute. For horizontal boxes, we are checking the PACK attribute. For vertical boxes // we are checking the ALIGN attribute. - nsIAtom* attrName = IsHorizontal() ? nsGkAtoms::pack : nsGkAtoms::align; + nsIAtom* attrName = IsXULHorizontal() ? nsGkAtoms::pack : nsGkAtoms::align; static nsIContent::AttrValuesArray strings[] = {&nsGkAtoms::_empty, &nsGkAtoms::start, &nsGkAtoms::center, &nsGkAtoms::end, nullptr}; static const Halignment values[] = @@ -336,7 +336,7 @@ nsBoxFrame::GetInitialHAlignment(nsBoxFrame::Halignment& aHalign) // horizontal boxes we're checking PACK. For vertical boxes we are checking // ALIGN. const nsStyleXUL* boxInfo = StyleXUL(); - if (IsHorizontal()) { + if (IsXULHorizontal()) { switch (boxInfo->mBoxPack) { case NS_STYLE_BOX_PACK_START: aHalign = nsBoxFrame::hAlign_Left; @@ -390,7 +390,7 @@ nsBoxFrame::GetInitialVAlignment(nsBoxFrame::Valignment& aValign) // Now that the deprecated stuff is out of the way, we move on to check the appropriate // attribute. For horizontal boxes, we are checking the ALIGN attribute. For vertical boxes // we are checking the PACK attribute. - nsIAtom* attrName = IsHorizontal() ? nsGkAtoms::align : nsGkAtoms::pack; + nsIAtom* attrName = IsXULHorizontal() ? nsGkAtoms::align : nsGkAtoms::pack; static nsIContent::AttrValuesArray strings[] = {&nsGkAtoms::_empty, &nsGkAtoms::start, &nsGkAtoms::center, &nsGkAtoms::baseline, &nsGkAtoms::end, nullptr}; @@ -411,7 +411,7 @@ nsBoxFrame::GetInitialVAlignment(nsBoxFrame::Valignment& aValign) // horizontal boxes we're checking ALIGN. For vertical boxes we are checking // PACK. const nsStyleXUL* boxInfo = StyleXUL(); - if (IsHorizontal()) { + if (IsXULHorizontal()) { switch (boxInfo->mBoxAlign) { case NS_STYLE_BOX_ALIGN_START: aValign = nsBoxFrame::vAlign_Top; @@ -479,7 +479,7 @@ nsBoxFrame::GetInitialDirection(bool& aIsNormal) if (!GetContent()) return; - if (IsHorizontal()) { + if (IsXULHorizontal()) { // For horizontal boxes only, we initialize our value based off the CSS 'direction' property. // This means that BiDI users will end up with horizontally inverted chrome. aIsNormal = (StyleVisibility()->mDirection == NS_STYLE_DIRECTION_LTR); // If text runs RTL then so do we. @@ -494,7 +494,7 @@ nsBoxFrame::GetInitialDirection(bool& aIsNormal) // Now see if we have an attribute. The attribute overrides // the style system value. - if (IsHorizontal()) { + if (IsXULHorizontal()) { static nsIContent::AttrValuesArray strings[] = {&nsGkAtoms::reverse, &nsGkAtoms::ltr, &nsGkAtoms::rtl, nullptr}; int32_t index = GetContent()->FindAttrValueIn(kNameSpaceID_None, nsGkAtoms::dir, @@ -590,14 +590,14 @@ nsBoxFrame::GetMinISize(nsRenderingContext *aRenderingContext) DISPLAY_MIN_WIDTH(this, result); nsBoxLayoutState state(PresContext(), aRenderingContext); - nsSize minSize = GetMinSize(state); + nsSize minSize = GetXULMinSize(state); - // GetMinSize returns border-box width, and we want to return content + // GetXULMinSize returns border-box width, and we want to return content // width. Since Reflow uses the reflow state's border and padding, we - // actually just want to subtract what GetMinSize added, which is the - // result of GetBorderAndPadding. + // actually just want to subtract what GetXULMinSize added, which is the + // result of GetXULBorderAndPadding. nsMargin bp; - GetBorderAndPadding(bp); + GetXULBorderAndPadding(bp); result = minSize.width - bp.LeftRight(); result = std::max(result, 0); @@ -612,14 +612,14 @@ nsBoxFrame::GetPrefISize(nsRenderingContext *aRenderingContext) DISPLAY_PREF_WIDTH(this, result); nsBoxLayoutState state(PresContext(), aRenderingContext); - nsSize prefSize = GetPrefSize(state); + nsSize prefSize = GetXULPrefSize(state); - // GetPrefSize returns border-box width, and we want to return content + // GetXULPrefSize returns border-box width, and we want to return content // width. Since Reflow uses the reflow state's border and padding, we - // actually just want to subtract what GetPrefSize added, which is the - // result of GetBorderAndPadding. + // actually just want to subtract what GetXULPrefSize added, which is the + // result of GetXULBorderAndPadding. nsMargin bp; - GetBorderAndPadding(bp); + GetXULBorderAndPadding(bp); result = prefSize.width - bp.LeftRight(); result = std::max(result, 0); @@ -667,7 +667,7 @@ nsBoxFrame::Reflow(nsPresContext* aPresContext, aReflowState.ComputedBSize()); LogicalMargin m = aReflowState.ComputedLogicalBorderPadding(); - // GetBorderAndPadding(m); + // GetXULBorderAndPadding(m); LogicalSize prefSize(wm); @@ -675,10 +675,10 @@ nsBoxFrame::Reflow(nsPresContext* aPresContext, NS_ASSERTION(computedSize.ISize(wm) != NS_INTRINSICSIZE, "computed inline size should always be computed"); if (computedSize.BSize(wm) == NS_INTRINSICSIZE) { - nsSize physicalPrefSize = GetPrefSize(state); - nsSize minSize = GetMinSize(state); - nsSize maxSize = GetMaxSize(state); - // XXXbz isn't GetPrefSize supposed to bounds-check for us? + nsSize physicalPrefSize = GetXULPrefSize(state); + nsSize minSize = GetXULMinSize(state); + nsSize maxSize = GetXULMaxSize(state); + // XXXbz isn't GetXULPrefSize supposed to bounds-check for us? physicalPrefSize = BoundsCheck(minSize, physicalPrefSize, maxSize); prefSize = LogicalSize(wm, physicalPrefSize); } @@ -703,10 +703,10 @@ nsBoxFrame::Reflow(nsPresContext* aPresContext, nsSize physicalSize = computedSize.GetPhysicalSize(wm); nsRect r(mRect.x, mRect.y, physicalSize.width, physicalSize.height); - SetBounds(state, r); + SetXULBounds(state, r); // layout our children - Layout(state); + XULLayout(state); // ok our child could have gotten bigger. So lets get its bounds @@ -717,7 +717,7 @@ nsBoxFrame::Reflow(nsPresContext* aPresContext, // getting the ascent could be a lot of work. Don't get it if // we are the root. The viewport doesn't care about it. if (!(mState & NS_STATE_IS_ROOT)) { - ascent = GetBoxAscent(state); + ascent = GetXULBoxAscent(state); } aDesiredSize.SetSize(wm, boxSize); @@ -744,7 +744,7 @@ nsBoxFrame::Reflow(nsPresContext* aPresContext, } nsSize -nsBoxFrame::GetPrefSize(nsBoxLayoutState& aBoxLayoutState) +nsBoxFrame::GetXULPrefSize(nsBoxLayoutState& aBoxLayoutState) { NS_ASSERTION(aBoxLayoutState.GetRenderingContext(), "must have rendering context"); @@ -759,34 +759,34 @@ nsBoxFrame::GetPrefSize(nsBoxLayoutState& aBoxLayoutState) PropagateDebug(aBoxLayoutState); #endif - if (IsCollapsed()) + if (IsXULCollapsed()) return size; // if the size was not completely redefined in CSS then ask our children bool widthSet, heightSet; - if (!nsIFrame::AddCSSPrefSize(this, size, widthSet, heightSet)) + if (!nsIFrame::AddXULPrefSize(this, size, widthSet, heightSet)) { if (mLayoutManager) { - nsSize layoutSize = mLayoutManager->GetPrefSize(this, aBoxLayoutState); + nsSize layoutSize = mLayoutManager->GetXULPrefSize(this, aBoxLayoutState); if (!widthSet) size.width = layoutSize.width; if (!heightSet) size.height = layoutSize.height; } else { - size = nsBox::GetPrefSize(aBoxLayoutState); + size = nsBox::GetXULPrefSize(aBoxLayoutState); } } - nsSize minSize = GetMinSize(aBoxLayoutState); - nsSize maxSize = GetMaxSize(aBoxLayoutState); + nsSize minSize = GetXULMinSize(aBoxLayoutState); + nsSize maxSize = GetXULMaxSize(aBoxLayoutState); mPrefSize = BoundsCheck(minSize, size, maxSize); return mPrefSize; } nscoord -nsBoxFrame::GetBoxAscent(nsBoxLayoutState& aBoxLayoutState) +nsBoxFrame::GetXULBoxAscent(nsBoxLayoutState& aBoxLayoutState) { if (!DoesNeedRecalc(mAscent)) return mAscent; @@ -795,19 +795,19 @@ nsBoxFrame::GetBoxAscent(nsBoxLayoutState& aBoxLayoutState) PropagateDebug(aBoxLayoutState); #endif - if (IsCollapsed()) + if (IsXULCollapsed()) return 0; if (mLayoutManager) mAscent = mLayoutManager->GetAscent(this, aBoxLayoutState); else - mAscent = nsBox::GetBoxAscent(aBoxLayoutState); + mAscent = nsBox::GetXULBoxAscent(aBoxLayoutState); return mAscent; } nsSize -nsBoxFrame::GetMinSize(nsBoxLayoutState& aBoxLayoutState) +nsBoxFrame::GetXULMinSize(nsBoxLayoutState& aBoxLayoutState) { NS_ASSERTION(aBoxLayoutState.GetRenderingContext(), "must have rendering context"); @@ -822,22 +822,22 @@ nsBoxFrame::GetMinSize(nsBoxLayoutState& aBoxLayoutState) PropagateDebug(aBoxLayoutState); #endif - if (IsCollapsed()) + if (IsXULCollapsed()) return size; // if the size was not completely redefined in CSS then ask our children bool widthSet, heightSet; - if (!nsIFrame::AddCSSMinSize(aBoxLayoutState, this, size, widthSet, heightSet)) + if (!nsIFrame::AddXULMinSize(aBoxLayoutState, this, size, widthSet, heightSet)) { if (mLayoutManager) { - nsSize layoutSize = mLayoutManager->GetMinSize(this, aBoxLayoutState); + nsSize layoutSize = mLayoutManager->GetXULMinSize(this, aBoxLayoutState); if (!widthSet) size.width = layoutSize.width; if (!heightSet) size.height = layoutSize.height; } else { - size = nsBox::GetMinSize(aBoxLayoutState); + size = nsBox::GetXULMinSize(aBoxLayoutState); } } @@ -847,7 +847,7 @@ nsBoxFrame::GetMinSize(nsBoxLayoutState& aBoxLayoutState) } nsSize -nsBoxFrame::GetMaxSize(nsBoxLayoutState& aBoxLayoutState) +nsBoxFrame::GetXULMaxSize(nsBoxLayoutState& aBoxLayoutState) { NS_ASSERTION(aBoxLayoutState.GetRenderingContext(), "must have rendering context"); @@ -862,22 +862,22 @@ nsBoxFrame::GetMaxSize(nsBoxLayoutState& aBoxLayoutState) PropagateDebug(aBoxLayoutState); #endif - if (IsCollapsed()) + if (IsXULCollapsed()) return size; // if the size was not completely redefined in CSS then ask our children bool widthSet, heightSet; - if (!nsIFrame::AddCSSMaxSize(this, size, widthSet, heightSet)) + if (!nsIFrame::AddXULMaxSize(this, size, widthSet, heightSet)) { if (mLayoutManager) { - nsSize layoutSize = mLayoutManager->GetMaxSize(this, aBoxLayoutState); + nsSize layoutSize = mLayoutManager->GetXULMaxSize(this, aBoxLayoutState); if (!widthSet) size.width = layoutSize.width; if (!heightSet) size.height = layoutSize.height; } else { - size = nsBox::GetMaxSize(aBoxLayoutState); + size = nsBox::GetXULMaxSize(aBoxLayoutState); } } @@ -887,12 +887,12 @@ nsBoxFrame::GetMaxSize(nsBoxLayoutState& aBoxLayoutState) } nscoord -nsBoxFrame::GetFlex() +nsBoxFrame::GetXULFlex() { if (!DoesNeedRecalc(mFlex)) return mFlex; - mFlex = nsBox::GetFlex(); + mFlex = nsBox::GetXULFlex(); return mFlex; } @@ -902,7 +902,7 @@ nsBoxFrame::GetFlex() * layout will call this method. */ NS_IMETHODIMP -nsBoxFrame::DoLayout(nsBoxLayoutState& aState) +nsBoxFrame::DoXULLayout(nsBoxLayoutState& aState) { uint32_t oldFlags = aState.LayoutFlags(); aState.SetLayoutFlags(0); @@ -910,7 +910,7 @@ nsBoxFrame::DoLayout(nsBoxLayoutState& aState) nsresult rv = NS_OK; if (mLayoutManager) { CoordNeedsRecalc(mAscent); - rv = mLayoutManager->Layout(this, aState); + rv = mLayoutManager->XULLayout(this, aState); } aState.SetLayoutFlags(oldFlags); @@ -934,7 +934,7 @@ nsBoxFrame::DoLayout(nsBoxLayoutState& aState) // getting the ascent could be a lot of work. Don't get it if // we are the root. The viewport doesn't care about it. if (!(mState & NS_STATE_IS_ROOT)) { - ascent = GetBoxAscent(aState); + ascent = GetXULBoxAscent(aState); } desiredSize.SetBlockStartAscent(ascent); desiredSize.mOverflowAreas = GetOverflowAreas(); @@ -958,14 +958,14 @@ nsBoxFrame::DestroyFrom(nsIFrame* aDestructRoot) RegUnregAccessKey(false); // clean up the container box's layout manager and child boxes - SetLayoutManager(nullptr); + SetXULLayoutManager(nullptr); nsContainerFrame::DestroyFrom(aDestructRoot); } #ifdef DEBUG_LAYOUT nsresult -nsBoxFrame::SetDebug(nsBoxLayoutState& aState, bool aDebug) +nsBoxFrame::SetXULDebug(nsBoxLayoutState& aState, bool aDebug) { // see if our state matches the given debug state bool debugSet = mState & NS_STATE_CURRENTLY_IN_DEBUG; @@ -1004,7 +1004,7 @@ nsBoxFrame::MarkIntrinsicISizesDirty() } // Don't call base class method, since everything it does is within an - // IsBoxWrapped check. + // IsXULBoxWrapped check. } void @@ -1228,15 +1228,15 @@ nsBoxFrame::AttributeChanged(int32_t aNameSpaceID, FrameNeedsReflow(this, nsIPresShell::eStyleChange, NS_FRAME_IS_DIRTY); } else if (aAttribute == nsGkAtoms::ordinal) { - nsIFrame* parent = GetParentBox(this); + nsIFrame* parent = GetParentXULBox(this); // If our parent is not a box, there's not much we can do... but in that // case our ordinal doesn't matter anyway, so that's ok. // Also don't bother with popup frames since they are kept on the - // kPopupList and RelayoutChildAtOrdinal() only handles + // kPopupList and XULRelayoutChildAtOrdinal() only handles // principal children. if (parent && !(GetStateBits() & NS_FRAME_OUT_OF_FLOW) && StyleDisplay()->mDisplay != NS_STYLE_DISPLAY_POPUP) { - parent->RelayoutChildAtOrdinal(this); + parent->XULRelayoutChildAtOrdinal(this); // XXXldb Should this instead be a tree change on the child or parent? PresContext()->PresShell()-> FrameNeedsReflow(parent, nsIPresShell::eStyleChange, @@ -1400,13 +1400,13 @@ void nsBoxFrame::PaintXULDebugBackground(DrawTarget* aDrawTarget, nsPoint aPt) { nsMargin border; - GetBorder(border); + GetXULBorder(border); nsMargin debugBorder; nsMargin debugMargin; nsMargin debugPadding; - bool isHorizontal = IsHorizontal(); + bool isHorizontal = IsXULHorizontal(); GetDebugBorder(debugBorder); PixelMarginToTwips(debugBorder); @@ -1462,7 +1462,7 @@ void nsBoxFrame::PaintXULDebugOverlay(DrawTarget& aDrawTarget, nsPoint aPt) { nsMargin border; - GetBorder(border); + GetXULBorder(border); nsMargin debugMargin; GetDebugMargin(debugMargin); @@ -1475,15 +1475,15 @@ nsBoxFrame::PaintXULDebugOverlay(DrawTarget& aDrawTarget, nsPoint aPt) nscoord onePixel = GetPresContext()->IntScaledPixelsToTwips(1); - kid = nsBox::GetChildBox(this); + kid = nsBox::GetChildXULBox(this); while (nullptr != kid) { - bool isHorizontal = IsHorizontal(); + bool isHorizontal = IsXULHorizontal(); nscoord x, y, borderSize, spacerSize; nsRect cr(kid->mRect); nsMargin margin; - kid->GetMargin(margin); + kid->GetXULMargin(margin); cr.Inflate(margin); if (isHorizontal) @@ -1499,9 +1499,9 @@ nsBoxFrame::PaintXULDebugOverlay(DrawTarget& aDrawTarget, nsPoint aPt) spacerSize = debugBorder.left - onePixel*4; } - nscoord flex = kid->GetFlex(); + nscoord flex = kid->GetXULFlex(); - if (!kid->IsCollapsed()) { + if (!kid->IsXULCollapsed()) { if (isHorizontal) borderSize = cr.width; else @@ -1510,7 +1510,7 @@ nsBoxFrame::PaintXULDebugOverlay(DrawTarget& aDrawTarget, nsPoint aPt) DrawSpacer(GetPresContext(), aDrawTarget, isHorizontal, flex, x, y, borderSize, spacerSize); } - kid = GetNextBox(kid); + kid = GetNextXULBox(kid); } } #endif @@ -1539,7 +1539,7 @@ nsBoxFrame::GetType() const #ifdef DEBUG_LAYOUT nsresult -nsBoxFrame::GetDebug(bool& aDebug) +nsBoxFrame::GetXULDebug(bool& aDebug) { aDebug = (mState & NS_STATE_CURRENTLY_IN_DEBUG); return NS_OK; @@ -1649,7 +1649,7 @@ nsBoxFrame::GetDebugBorder(nsMargin& aInset) { aInset.SizeTo(2,2,2,2); - if (IsHorizontal()) + if (IsXULHorizontal()) aInset.top = 10; else aInset.left = 10; @@ -1723,10 +1723,10 @@ nsBoxFrame::DisplayDebugInfoFor(nsIFrame* aBox, nsRect insideBorder(aBox->mRect); insideBorder.MoveTo(0,0): nsMargin border(0,0,0,0); - aBox->GetBorderAndPadding(border); + aBox->GetXULBorderAndPadding(border); insideBorder.Deflate(border); - bool isHorizontal = IsHorizontal(); + bool isHorizontal = IsXULHorizontal(); if (!insideBorder.Contains(nsPoint(x,y))) return NS_ERROR_FAILURE; @@ -1734,7 +1734,7 @@ nsBoxFrame::DisplayDebugInfoFor(nsIFrame* aBox, //printf("%%%%%% inside box %%%%%%%\n"); int count = 0; - nsIFrame* child = nsBox::GetChildBox(aBox); + nsIFrame* child = nsBox::GetChildXULBox(aBox); nsMargin m; nsMargin m2; @@ -1763,13 +1763,13 @@ nsBoxFrame::DisplayDebugInfoFor(nsIFrame* aBox, if (aBox->GetContent()) { printf("---------------\n"); - DumpBox(stdout); + XULDumpBox(stdout); printf("\n"); } if (child->GetContent()) { printf("child #%d: ", count); - child->DumpBox(stdout); + child->XULDumpBox(stdout); printf("\n"); } @@ -1781,16 +1781,16 @@ nsBoxFrame::DisplayDebugInfoFor(nsIFrame* aBox, nscoord flexCSS = NS_INTRINSICSIZE; bool widthSet, heightSet; - nsIFrame::AddCSSPrefSize(child, prefSizeCSS, widthSet, heightSet); - nsIFrame::AddCSSMinSize (state, child, minSizeCSS, widthSet, heightSet); - nsIFrame::AddCSSMaxSize (child, maxSizeCSS, widthSet, heightSet); - nsIFrame::AddCSSFlex (child, flexCSS); + nsIFrame::AddXULPrefSize(child, prefSizeCSS, widthSet, heightSet); + nsIFrame::AddXULMinSize (state, child, minSizeCSS, widthSet, heightSet); + nsIFrame::AddXULMaxSize (child, maxSizeCSS, widthSet, heightSet); + nsIFrame::AddXULFlex (child, flexCSS); - nsSize prefSize = child->GetPrefSize(state); - nsSize minSize = child->GetMinSize(state); - nsSize maxSize = child->GetMaxSize(state); - nscoord flexSize = child->GetFlex(); - nscoord ascentSize = child->GetBoxAscent(state); + nsSize prefSize = child->GetXULPrefSize(state); + nsSize minSize = child->GetXULMinSize(state); + nsSize maxSize = child->GetXULMaxSize(state); + nscoord flexSize = child->GetXULFlex(); + nscoord ascentSize = child->GetXULBoxAscent(state); char min[100]; char pref[100]; @@ -1823,7 +1823,7 @@ nsBoxFrame::DisplayDebugInfoFor(nsIFrame* aBox, return NS_OK; } - child = GetNextBox(child); + child = GetNextXULBox(child); count++; } } else { @@ -1837,11 +1837,11 @@ nsBoxFrame::DisplayDebugInfoFor(nsIFrame* aBox, void nsBoxFrame::SetDebugOnChildList(nsBoxLayoutState& aState, nsIFrame* aChild, bool aDebug) { - nsIFrame* child = nsBox::GetChildBox(this); + nsIFrame* child = nsBox::GetChildXULBox(this); while (child) { - child->SetDebug(aState, aDebug); - child = GetNextBox(child); + child->SetXULDebug(aState, aDebug); + child = GetNextXULBox(child); } } @@ -1850,7 +1850,7 @@ nsBoxFrame::GetFrameSizeWithMargin(nsIFrame* aBox, nsSize& aSize) { nsRect rect(aBox->GetRect()); nsMargin margin(0,0,0,0); - aBox->GetMargin(margin); + aBox->GetXULMargin(margin); rect.Inflate(margin); aSize.width = rect.width; aSize.height = rect.height; @@ -1907,7 +1907,7 @@ IsBoxOrdinalLEQ(nsIFrame* aFrame1, // If we've got a placeholder frame, use its out-of-flow frame's ordinal val. nsIFrame* aRealFrame1 = nsPlaceholderFrame::GetRealFrameFor(aFrame1); nsIFrame* aRealFrame2 = nsPlaceholderFrame::GetRealFrameFor(aFrame2); - return aRealFrame1->GetOrdinal() <= aRealFrame2->GetOrdinal(); + return aRealFrame1->GetXULOrdinal() <= aRealFrame2->GetXULOrdinal(); } void @@ -1924,30 +1924,30 @@ nsBoxFrame::LayoutChildAt(nsBoxLayoutState& aState, nsIFrame* aBox, const nsRect { // get the current rect nsRect oldRect(aBox->GetRect()); - aBox->SetBounds(aState, aRect); + aBox->SetXULBounds(aState, aRect); bool layout = NS_SUBTREE_DIRTY(aBox); if (layout || (oldRect.width != aRect.width || oldRect.height != aRect.height)) { - return aBox->Layout(aState); + return aBox->XULLayout(aState); } return NS_OK; } nsresult -nsBoxFrame::RelayoutChildAtOrdinal(nsIFrame* aChild) +nsBoxFrame::XULRelayoutChildAtOrdinal(nsIFrame* aChild) { if (!SupportsOrdinalsInChildren()) return NS_OK; - uint32_t ord = aChild->GetOrdinal(); + uint32_t ord = aChild->GetXULOrdinal(); nsIFrame* child = mFrames.FirstChild(); nsIFrame* newPrevSib = nullptr; while (child) { - if (ord < child->GetOrdinal()) { + if (ord < child->GetXULOrdinal()) { break; } @@ -1955,7 +1955,7 @@ nsBoxFrame::RelayoutChildAtOrdinal(nsIFrame* aChild) newPrevSib = child; } - child = GetNextBox(child); + child = GetNextXULBox(child); } if (aChild->GetPrevSibling() == newPrevSib) { diff --git a/layout/xul/nsBoxFrame.h b/layout/xul/nsBoxFrame.h index 50eb183810..a1b6faf00d 100644 --- a/layout/xul/nsBoxFrame.h +++ b/layout/xul/nsBoxFrame.h @@ -56,23 +56,23 @@ public: // gets the rect inside our border and debug border. If you wish to paint inside a box // call this method to get the rect so you don't draw on the debug border or outer border. - virtual void SetLayoutManager(nsBoxLayout* aLayout) override { mLayoutManager = aLayout; } - virtual nsBoxLayout* GetLayoutManager() override { return mLayoutManager; } + virtual void SetXULLayoutManager(nsBoxLayout* aLayout) override { mLayoutManager = aLayout; } + virtual nsBoxLayout* GetXULLayoutManager() override { return mLayoutManager; } - virtual nsresult RelayoutChildAtOrdinal(nsIFrame* aChild) override; + virtual nsresult XULRelayoutChildAtOrdinal(nsIFrame* aChild) override; - virtual nsSize GetPrefSize(nsBoxLayoutState& aBoxLayoutState) override; - virtual nsSize GetMinSize(nsBoxLayoutState& aBoxLayoutState) override; - virtual nsSize GetMaxSize(nsBoxLayoutState& aBoxLayoutState) override; - virtual nscoord GetFlex() override; - virtual nscoord GetBoxAscent(nsBoxLayoutState& aBoxLayoutState) override; + virtual nsSize GetXULPrefSize(nsBoxLayoutState& aBoxLayoutState) override; + virtual nsSize GetXULMinSize(nsBoxLayoutState& aBoxLayoutState) override; + virtual nsSize GetXULMaxSize(nsBoxLayoutState& aBoxLayoutState) override; + virtual nscoord GetXULFlex() override; + virtual nscoord GetXULBoxAscent(nsBoxLayoutState& aBoxLayoutState) override; #ifdef DEBUG_LAYOUT - virtual nsresult SetDebug(nsBoxLayoutState& aBoxLayoutState, bool aDebug) override; - virtual nsresult GetDebug(bool& aDebug) override; + virtual nsresult SetXULDebug(nsBoxLayoutState& aBoxLayoutState, bool aDebug) override; + virtual nsresult GetXULDebug(bool& aDebug) override; #endif - virtual Valignment GetVAlign() const override { return mValign; } - virtual Halignment GetHAlign() const override { return mHalign; } - NS_IMETHOD DoLayout(nsBoxLayoutState& aBoxLayoutState) override; + virtual Valignment GetXULVAlign() const override { return mValign; } + virtual Halignment GetXULHAlign() const override { return mHalign; } + NS_IMETHOD DoXULLayout(nsBoxLayoutState& aBoxLayoutState) override; virtual bool ComputesOwnOverflowArea() override { return false; } @@ -220,7 +220,7 @@ protected: private: #ifdef DEBUG_LAYOUT - nsresult SetDebug(nsPresContext* aPresContext, bool aDebug); + nsresult SetXULDebug(nsPresContext* aPresContext, bool aDebug); bool GetInitialDebug(bool& aDebug); void GetDebugPref(); diff --git a/layout/xul/nsBoxLayout.cpp b/layout/xul/nsBoxLayout.cpp index 4783f0269c..60db32a7a5 100644 --- a/layout/xul/nsBoxLayout.cpp +++ b/layout/xul/nsBoxLayout.cpp @@ -34,7 +34,7 @@ nsBoxLayout::AddMargin(nsSize& aSize, const nsMargin& aMargin) } nsSize -nsBoxLayout::GetPrefSize(nsIFrame* aBox, nsBoxLayoutState& aBoxLayoutState) +nsBoxLayout::GetXULPrefSize(nsIFrame* aBox, nsBoxLayoutState& aBoxLayoutState) { nsSize pref (0, 0); AddBorderAndPadding(aBox, pref); @@ -43,7 +43,7 @@ nsBoxLayout::GetPrefSize(nsIFrame* aBox, nsBoxLayoutState& aBoxLayoutState) } nsSize -nsBoxLayout::GetMinSize(nsIFrame* aBox, nsBoxLayoutState& aBoxLayoutState) +nsBoxLayout::GetXULMinSize(nsIFrame* aBox, nsBoxLayoutState& aBoxLayoutState) { nsSize minSize (0,0); AddBorderAndPadding(aBox, minSize); @@ -51,7 +51,7 @@ nsBoxLayout::GetMinSize(nsIFrame* aBox, nsBoxLayoutState& aBoxLayoutState) } nsSize -nsBoxLayout::GetMaxSize(nsIFrame* aBox, nsBoxLayoutState& aBoxLayoutState) +nsBoxLayout::GetXULMaxSize(nsIFrame* aBox, nsBoxLayoutState& aBoxLayoutState) { //AddBorderAndPadding () never changes maxSize (NS_INTRINSICSIZE) //AddBorderAndPadding(aBox, maxSize); @@ -66,7 +66,7 @@ nsBoxLayout::GetAscent(nsIFrame* aBox, nsBoxLayoutState& aBoxLayoutState) } NS_IMETHODIMP -nsBoxLayout::Layout(nsIFrame* aBox, nsBoxLayoutState& aBoxLayoutState) +nsBoxLayout::XULLayout(nsIFrame* aBox, nsBoxLayoutState& aBoxLayoutState) { return NS_OK; } diff --git a/layout/xul/nsBoxLayout.h b/layout/xul/nsBoxLayout.h index 77c1011f81..cb4d77170e 100644 --- a/layout/xul/nsBoxLayout.h +++ b/layout/xul/nsBoxLayout.h @@ -34,11 +34,11 @@ public: NS_DECLARE_STATIC_IID_ACCESSOR(NS_BOX_LAYOUT_IID) - NS_IMETHOD Layout(nsIFrame* aBox, nsBoxLayoutState& aState); + NS_IMETHOD XULLayout(nsIFrame* aBox, nsBoxLayoutState& aState); - virtual nsSize GetPrefSize(nsIFrame* aBox, nsBoxLayoutState& aBoxLayoutState); - virtual nsSize GetMinSize(nsIFrame* aBox, nsBoxLayoutState& aBoxLayoutState); - virtual nsSize GetMaxSize(nsIFrame* aBox, nsBoxLayoutState& aBoxLayoutState); + virtual nsSize GetXULPrefSize(nsIFrame* aBox, nsBoxLayoutState& aBoxLayoutState); + virtual nsSize GetXULMinSize(nsIFrame* aBox, nsBoxLayoutState& aBoxLayoutState); + virtual nsSize GetXULMaxSize(nsIFrame* aBox, nsBoxLayoutState& aBoxLayoutState); virtual nscoord GetAscent(nsIFrame* aBox, nsBoxLayoutState& aBoxLayoutState); virtual void ChildrenInserted(nsIFrame* aBox, nsBoxLayoutState& aState, nsIFrame* aPrevBox, diff --git a/layout/xul/nsDeckFrame.cpp b/layout/xul/nsDeckFrame.cpp index 89ec9411c1..b0c0296b2e 100644 --- a/layout/xul/nsDeckFrame.cpp +++ b/layout/xul/nsDeckFrame.cpp @@ -49,7 +49,7 @@ nsDeckFrame::nsDeckFrame(nsStyleContext* aContext) { nsCOMPtr layout; NS_NewStackLayout(layout); - SetLayoutManager(layout); + SetXULLayoutManager(layout); } nsIAtom* @@ -200,7 +200,7 @@ nsDeckFrame::BuildDisplayListForChildren(nsDisplayListBuilder* aBuilder, } NS_IMETHODIMP -nsDeckFrame::DoLayout(nsBoxLayoutState& aState) +nsDeckFrame::DoXULLayout(nsBoxLayoutState& aState) { // Make sure we tweak the state so it does not resize our children. // We will do that. @@ -208,10 +208,10 @@ nsDeckFrame::DoLayout(nsBoxLayoutState& aState) aState.SetLayoutFlags(NS_FRAME_NO_SIZE_VIEW | NS_FRAME_NO_VISIBILITY); // do a normal layout - nsresult rv = nsBoxFrame::DoLayout(aState); + nsresult rv = nsBoxFrame::DoXULLayout(aState); // run though each child. Hide all but the selected one - nsIFrame* box = nsBox::GetChildBox(this); + nsIFrame* box = nsBox::GetChildXULBox(this); nscoord count = 0; while (box) @@ -220,7 +220,7 @@ nsDeckFrame::DoLayout(nsBoxLayoutState& aState) if (count != mIndex) HideBox(box); - box = GetNextBox(box); + box = GetNextXULBox(box); count++; } diff --git a/layout/xul/nsDeckFrame.h b/layout/xul/nsDeckFrame.h index 5639bcac7e..2c7ae14451 100644 --- a/layout/xul/nsDeckFrame.h +++ b/layout/xul/nsDeckFrame.h @@ -31,7 +31,7 @@ public: nsIAtom* aAttribute, int32_t aModType) override; - NS_IMETHOD DoLayout(nsBoxLayoutState& aState) override; + NS_IMETHOD DoXULLayout(nsBoxLayoutState& aState) override; virtual void BuildDisplayList(nsDisplayListBuilder* aBuilder, const nsRect& aDirtyRect, diff --git a/layout/xul/nsGroupBoxFrame.cpp b/layout/xul/nsGroupBoxFrame.cpp index 978397d35e..a2a7f3dea3 100644 --- a/layout/xul/nsGroupBoxFrame.cpp +++ b/layout/xul/nsGroupBoxFrame.cpp @@ -25,7 +25,7 @@ public: explicit nsGroupBoxFrame(nsStyleContext* aContext): nsBoxFrame(aContext) {} - virtual nsresult GetBorderAndPadding(nsMargin& aBorderAndPadding) override; + virtual nsresult GetXULBorderAndPadding(nsMargin& aBorderAndPadding) override; virtual void BuildDisplayList(nsDisplayListBuilder* aBuilder, const nsRect& aDirtyRect, @@ -256,21 +256,21 @@ nsIFrame* nsGroupBoxFrame::GetCaptionBox(nsRect& aCaptionRect) { // first child is our grouped area - nsIFrame* box = nsBox::GetChildBox(this); + nsIFrame* box = nsBox::GetChildXULBox(this); // no area fail. if (!box) return nullptr; // get the first child in the grouped area, that is the caption - box = nsBox::GetChildBox(box); + box = nsBox::GetChildXULBox(box); // nothing in the area? fail if (!box) return nullptr; // now get the caption itself. It is in the caption frame. - nsIFrame* child = nsBox::GetChildBox(box); + nsIFrame* child = nsBox::GetChildXULBox(box); if (child) { // convert to our coordinates. @@ -284,7 +284,7 @@ nsGroupBoxFrame::GetCaptionBox(nsRect& aCaptionRect) } nsresult -nsGroupBoxFrame::GetBorderAndPadding(nsMargin& aBorderAndPadding) +nsGroupBoxFrame::GetXULBorderAndPadding(nsMargin& aBorderAndPadding) { aBorderAndPadding.SizeTo(0,0,0,0); return NS_OK; diff --git a/layout/xul/nsImageBoxFrame.cpp b/layout/xul/nsImageBoxFrame.cpp index e05ee9d5b2..6349eb5ae7 100644 --- a/layout/xul/nsImageBoxFrame.cpp +++ b/layout/xul/nsImageBoxFrame.cpp @@ -236,7 +236,7 @@ nsImageBoxFrame::UpdateImage() if (uri && nsContentUtils::CanLoadImage(uri, mContent, doc, mContent->NodePrincipal())) { - nsContentUtils::LoadImage(uri, doc, mContent->NodePrincipal(), + nsContentUtils::LoadImage(uri, mContent, doc, mContent->NodePrincipal(), doc->GetDocumentURI(), doc->GetReferrerPolicy(), mListener, mLoadFlags, EmptyString(), getter_AddRefs(mImageRequest)); @@ -329,7 +329,7 @@ nsImageBoxFrame::PaintImage(nsRenderingContext& aRenderingContext, uint32_t aFlags) { nsRect constraintRect; - GetClientRect(constraintRect); + GetXULClientRect(constraintRect); constraintRect += aPt; @@ -345,6 +345,13 @@ nsImageBoxFrame::PaintImage(nsRenderingContext& aRenderingContext, return DrawResult::TEMPORARY_ERROR; } + // Don't draw if the image's size isn't available. + uint32_t imgStatus; + if (!NS_SUCCEEDED(mImageRequest->GetImageStatus(&imgStatus)) || + !(imgStatus & imgIRequest::STATUS_SIZE_AVAILABLE)) { + return DrawResult::NOT_READY; + } + nsCOMPtr imgCon; mImageRequest->GetImage(getter_AddRefs(imgCon)); @@ -437,126 +444,53 @@ nsDisplayXULImage::ComputeInvalidationRegion(nsDisplayListBuilder* aBuilder, nsDisplayImageContainer::ComputeInvalidationRegion(aBuilder, aGeometry, aInvalidRegion); } -void -nsDisplayXULImage::ConfigureLayer(ImageLayer* aLayer, - const ContainerLayerParameters& aParameters) -{ - aLayer->SetFilter(nsLayoutUtils::GetGraphicsFilterForFrame(mFrame)); - - nsImageBoxFrame* imageFrame = static_cast(mFrame); - - nsRect clientRect; - imageFrame->GetClientRect(clientRect); - - const int32_t factor = mFrame->PresContext()->AppUnitsPerDevPixel(); - const LayoutDeviceRect destRect = - LayoutDeviceRect::FromAppUnits(clientRect + ToReferenceFrame(), factor); - - nsCOMPtr imgCon; - imageFrame->mImageRequest->GetImage(getter_AddRefs(imgCon)); - int32_t imageWidth; - int32_t imageHeight; - imgCon->GetWidth(&imageWidth); - imgCon->GetHeight(&imageHeight); - - NS_ASSERTION(imageWidth != 0 && imageHeight != 0, "Invalid image size!"); - if (imageWidth > 0 && imageHeight > 0) { - // We're actually using the ImageContainer. Let our frame know that it - // should consider itself to have painted successfully. - nsDisplayItemGenericImageGeometry::UpdateDrawResult(this, - DrawResult::SUCCESS); - } - - // XXX(seth): Right now we ignore aParameters.Scale() and - // aParameters.Offset(), because FrameLayerBuilder already applies - // aParameters.Scale() via the layer's post-transform, and - // aParameters.Offset() is always zero. - MOZ_ASSERT(aParameters.Offset() == LayerIntPoint(0,0)); - - // It's possible (for example, due to downscale-during-decode) that the - // ImageContainer this ImageLayer is holding has a different size from the - // intrinsic size of the image. For this reason we compute the transform using - // the ImageContainer's size rather than the image's intrinsic size. - // XXX(seth): In reality, since the size of the ImageContainer may change - // asynchronously, this is not enough. Bug 1183378 will provide a more - // complete fix, but this solution is safe in more cases than simply relying - // on the intrinsic size. - IntSize containerSize = aLayer->GetContainer() - ? aLayer->GetContainer()->GetCurrentSize() - : IntSize(imageWidth, imageHeight); - - const LayoutDevicePoint p = destRect.TopLeft(); - Matrix transform = Matrix::Translation(p.x, p.y); - transform.PreScale(destRect.Width() / containerSize.width, - destRect.Height() / containerSize.height); - aLayer->SetBaseTransform(gfx::Matrix4x4::From2D(transform)); -} - bool nsDisplayXULImage::CanOptimizeToImageLayer(LayerManager* aManager, nsDisplayListBuilder* aBuilder) { - uint32_t flags = aBuilder->ShouldSyncDecodeImages() - ? imgIContainer::FLAG_SYNC_DECODE - : imgIContainer::FLAG_NONE; + nsImageBoxFrame* imageFrame = static_cast(mFrame); + if (!imageFrame->CanOptimizeToImageLayer()) { + return false; + } - return static_cast(mFrame) - ->IsImageContainerAvailable(aManager, flags); + return nsDisplayImageContainer::CanOptimizeToImageLayer(aManager, aBuilder); +} + +already_AddRefed +nsDisplayXULImage::GetImage() +{ + nsImageBoxFrame* imageFrame = static_cast(mFrame); + if (!imageFrame->mImageRequest) { + return nullptr; + } + + nsCOMPtr imgCon; + imageFrame->mImageRequest->GetImage(getter_AddRefs(imgCon)); + + return imgCon.forget(); +} + +nsRect +nsDisplayXULImage::GetDestRect() +{ + nsImageBoxFrame* imageFrame = static_cast(mFrame); + + nsRect clientRect; + imageFrame->GetXULClientRect(clientRect); + + return clientRect + ToReferenceFrame(); } bool -nsImageBoxFrame::IsImageContainerAvailable(LayerManager* aManager, - uint32_t aFlags) +nsImageBoxFrame::CanOptimizeToImageLayer() { bool hasSubRect = !mUseSrcAttr && (mSubRect.width > 0 || mSubRect.height > 0); - if (hasSubRect || !mImageRequest) { + if (hasSubRect) { return false; } - - nsCOMPtr imgCon; - mImageRequest->GetImage(getter_AddRefs(imgCon)); - if (!imgCon) { - return false; - } - - return imgCon->IsImageContainerAvailable(aManager, aFlags); + return true; } -already_AddRefed -nsDisplayXULImage::GetContainer(LayerManager* aManager, - nsDisplayListBuilder* aBuilder) -{ - uint32_t flags = aBuilder->ShouldSyncDecodeImages() - ? imgIContainer::FLAG_SYNC_DECODE - : imgIContainer::FLAG_NONE; - - return static_cast(mFrame)->GetContainer(aManager, flags); -} - -already_AddRefed -nsImageBoxFrame::GetContainer(LayerManager* aManager, uint32_t aFlags) -{ - MOZ_ASSERT(IsImageContainerAvailable(aManager, aFlags), - "Should call IsImageContainerAvailable and get true before " - "calling GetContainer"); - if (!mImageRequest) { - MOZ_ASSERT_UNREACHABLE("mImageRequest should be available if " - "IsImageContainerAvailable returned true"); - return nullptr; - } - - nsCOMPtr imgCon; - mImageRequest->GetImage(getter_AddRefs(imgCon)); - if (!imgCon) { - MOZ_ASSERT_UNREACHABLE("An imgIContainer should be available if " - "IsImageContainerAvailable returned true"); - return nullptr; - } - - return imgCon->GetImageContainer(aManager, aFlags); -} - - // // DidSetStyleContext // @@ -611,7 +545,7 @@ nsImageBoxFrame::GetImageSize() * Ok return our dimensions */ nsSize -nsImageBoxFrame::GetPrefSize(nsBoxLayoutState& aState) +nsImageBoxFrame::GetXULPrefSize(nsBoxLayoutState& aState) { nsSize size(0,0); DISPLAY_PREF_SIZE(this, size); @@ -626,17 +560,17 @@ nsImageBoxFrame::GetPrefSize(nsBoxLayoutState& aState) nsSize intrinsicSize = size; nsMargin borderPadding(0,0,0,0); - GetBorderAndPadding(borderPadding); + GetXULBorderAndPadding(borderPadding); size.width += borderPadding.LeftRight(); size.height += borderPadding.TopBottom(); bool widthSet, heightSet; - nsIFrame::AddCSSPrefSize(this, size, widthSet, heightSet); + nsIFrame::AddXULPrefSize(this, size, widthSet, heightSet); NS_ASSERTION(size.width != NS_INTRINSICSIZE && size.height != NS_INTRINSICSIZE, "non-intrinsic size expected"); - nsSize minSize = GetMinSize(aState); - nsSize maxSize = GetMaxSize(aState); + nsSize minSize = GetXULMinSize(aState); + nsSize maxSize = GetXULMaxSize(aState); if (!widthSet && !heightSet) { if (minSize.width != NS_INTRINSICSIZE) @@ -689,21 +623,21 @@ nsImageBoxFrame::GetPrefSize(nsBoxLayoutState& aState) } nsSize -nsImageBoxFrame::GetMinSize(nsBoxLayoutState& aState) +nsImageBoxFrame::GetXULMinSize(nsBoxLayoutState& aState) { // An image can always scale down to (0,0). nsSize size(0,0); DISPLAY_MIN_SIZE(this, size); AddBorderAndPadding(size); bool widthSet, heightSet; - nsIFrame::AddCSSMinSize(aState, this, size, widthSet, heightSet); + nsIFrame::AddXULMinSize(aState, this, size, widthSet, heightSet); return size; } nscoord -nsImageBoxFrame::GetBoxAscent(nsBoxLayoutState& aState) +nsImageBoxFrame::GetXULBoxAscent(nsBoxLayoutState& aState) { - return GetPrefSize(aState).height; + return GetXULPrefSize(aState).height; } nsIAtom* @@ -783,7 +717,7 @@ nsresult nsImageBoxFrame::OnDecodeComplete(imgIRequest* aRequest) { nsBoxLayoutState state(PresContext()); - this->Redraw(state); + this->XULRedraw(state); return NS_OK; } diff --git a/layout/xul/nsImageBoxFrame.h b/layout/xul/nsImageBoxFrame.h index 251224437f..7faccccaee 100644 --- a/layout/xul/nsImageBoxFrame.h +++ b/layout/xul/nsImageBoxFrame.h @@ -47,9 +47,9 @@ public: friend class nsDisplayXULImage; NS_DECL_FRAMEARENA_HELPERS - virtual nsSize GetPrefSize(nsBoxLayoutState& aBoxLayoutState) override; - virtual nsSize GetMinSize(nsBoxLayoutState& aBoxLayoutState) override; - virtual nscoord GetBoxAscent(nsBoxLayoutState& aBoxLayoutState) override; + virtual nsSize GetXULPrefSize(nsBoxLayoutState& aBoxLayoutState) override; + virtual nsSize GetXULMinSize(nsBoxLayoutState& aBoxLayoutState) override; + virtual nscoord GetXULBoxAscent(nsBoxLayoutState& aBoxLayoutState) override; virtual void MarkIntrinsicISizesDirty() override; nsresult Notify(imgIRequest *aRequest, int32_t aType, const nsIntRect* aData); @@ -96,9 +96,7 @@ public: const nsRect& aDirtyRect, nsPoint aPt, uint32_t aFlags); - bool IsImageContainerAvailable(LayerManager* aManager, uint32_t aFlags); - already_AddRefed GetContainer(LayerManager* aManager, - uint32_t aFlags); + bool CanOptimizeToImageLayer(); protected: explicit nsImageBoxFrame(nsStyleContext* aContext); @@ -144,10 +142,8 @@ public: virtual bool CanOptimizeToImageLayer(LayerManager* aManager, nsDisplayListBuilder* aBuilder) override; - virtual already_AddRefed GetContainer(LayerManager* aManager, - nsDisplayListBuilder* aBuilder) override; - virtual void ConfigureLayer(ImageLayer* aLayer, - const ContainerLayerParameters& aParameters) override; + virtual already_AddRefed GetImage() override; + virtual nsRect GetDestRect() override; virtual nsRect GetBounds(nsDisplayListBuilder* aBuilder, bool* aSnap) override { *aSnap = true; diff --git a/layout/xul/nsLeafBoxFrame.cpp b/layout/xul/nsLeafBoxFrame.cpp index 4c4519edf2..b7ae7c55c7 100644 --- a/layout/xul/nsLeafBoxFrame.cpp +++ b/layout/xul/nsLeafBoxFrame.cpp @@ -131,14 +131,14 @@ nsLeafBoxFrame::GetMinISize(nsRenderingContext *aRenderingContext) nsBoxLayoutState state(PresContext(), aRenderingContext); WritingMode wm = GetWritingMode(); - LogicalSize minSize(wm, GetMinSize(state)); + LogicalSize minSize(wm, GetXULMinSize(state)); - // GetMinSize returns border-box size, and we want to return content + // GetXULMinSize returns border-box size, and we want to return content // inline-size. Since Reflow uses the reflow state's border and padding, we - // actually just want to subtract what GetMinSize added, which is the - // result of GetBorderAndPadding. + // actually just want to subtract what GetXULMinSize added, which is the + // result of GetXULBorderAndPadding. nsMargin bp; - GetBorderAndPadding(bp); + GetXULBorderAndPadding(bp); result = minSize.ISize(wm) - LogicalMargin(wm, bp).IStartEnd(wm); @@ -153,14 +153,14 @@ nsLeafBoxFrame::GetPrefISize(nsRenderingContext *aRenderingContext) nsBoxLayoutState state(PresContext(), aRenderingContext); WritingMode wm = GetWritingMode(); - LogicalSize prefSize(wm, GetPrefSize(state)); + LogicalSize prefSize(wm, GetXULPrefSize(state)); - // GetPrefSize returns border-box size, and we want to return content + // GetXULPrefSize returns border-box size, and we want to return content // inline-size. Since Reflow uses the reflow state's border and padding, we - // actually just want to subtract what GetPrefSize added, which is the - // result of GetBorderAndPadding. + // actually just want to subtract what GetXULPrefSize added, which is the + // result of GetXULBorderAndPadding. nsMargin bp; - GetBorderAndPadding(bp); + GetXULBorderAndPadding(bp); result = prefSize.ISize(wm) - LogicalMargin(wm, bp).IStartEnd(wm); @@ -245,11 +245,11 @@ nsLeafBoxFrame::Reflow(nsPresContext* aPresContext, nsMargin m; m = aReflowState.ComputedPhysicalBorderPadding(); - //GetBorderAndPadding(m); + //GetXULBorderAndPadding(m); // this happens sometimes. So lets handle it gracefully. if (aReflowState.ComputedHeight() == 0) { - nsSize minSize = GetMinSize(state); + nsSize minSize = GetXULMinSize(state); computedSize.height = minSize.height - m.top - m.bottom; } @@ -257,9 +257,9 @@ nsLeafBoxFrame::Reflow(nsPresContext* aPresContext, // if we are told to layout intrinic then get our preferred size. if (computedSize.width == NS_INTRINSICSIZE || computedSize.height == NS_INTRINSICSIZE) { - prefSize = GetPrefSize(state); - nsSize minSize = GetMinSize(state); - nsSize maxSize = GetMaxSize(state); + prefSize = GetXULPrefSize(state); + nsSize minSize = GetXULMinSize(state); + nsSize maxSize = GetXULMaxSize(state); prefSize = BoundsCheck(minSize, prefSize, maxSize); } @@ -298,17 +298,17 @@ nsLeafBoxFrame::Reflow(nsPresContext* aPresContext, nsRect r(mRect.x, mRect.y, computedSize.width, computedSize.height); - SetBounds(state, r); + SetXULBounds(state, r); // layout our children - Layout(state); + XULLayout(state); // ok our child could have gotten bigger. So lets get its bounds aDesiredSize.Width() = mRect.width; aDesiredSize.Height() = mRect.height; - aDesiredSize.SetBlockStartAscent(GetBoxAscent(state)); + aDesiredSize.SetBlockStartAscent(GetXULBoxAscent(state)); - // the overflow rect is set in SetBounds() above + // the overflow rect is set in SetXULBounds() above aDesiredSize.mOverflowAreas = GetOverflowAreas(); #ifdef DO_NOISY_REFLOW @@ -347,44 +347,44 @@ nsLeafBoxFrame::CharacterDataChanged(CharacterDataChangeInfo* aInfo) } /* virtual */ nsSize -nsLeafBoxFrame::GetPrefSize(nsBoxLayoutState& aState) +nsLeafBoxFrame::GetXULPrefSize(nsBoxLayoutState& aState) { - return nsBox::GetPrefSize(aState); + return nsBox::GetXULPrefSize(aState); } /* virtual */ nsSize -nsLeafBoxFrame::GetMinSize(nsBoxLayoutState& aState) +nsLeafBoxFrame::GetXULMinSize(nsBoxLayoutState& aState) { - return nsBox::GetMinSize(aState); + return nsBox::GetXULMinSize(aState); } /* virtual */ nsSize -nsLeafBoxFrame::GetMaxSize(nsBoxLayoutState& aState) +nsLeafBoxFrame::GetXULMaxSize(nsBoxLayoutState& aState) { - return nsBox::GetMaxSize(aState); + return nsBox::GetXULMaxSize(aState); } /* virtual */ nscoord -nsLeafBoxFrame::GetFlex() +nsLeafBoxFrame::GetXULFlex() { - return nsBox::GetFlex(); + return nsBox::GetXULFlex(); } /* virtual */ nscoord -nsLeafBoxFrame::GetBoxAscent(nsBoxLayoutState& aState) +nsLeafBoxFrame::GetXULBoxAscent(nsBoxLayoutState& aState) { - return nsBox::GetBoxAscent(aState); + return nsBox::GetXULBoxAscent(aState); } /* virtual */ void nsLeafBoxFrame::MarkIntrinsicISizesDirty() { // Don't call base class method, since everything it does is within an - // IsBoxWrapped check. + // IsXULBoxWrapped check. } NS_IMETHODIMP -nsLeafBoxFrame::DoLayout(nsBoxLayoutState& aState) +nsLeafBoxFrame::DoXULLayout(nsBoxLayoutState& aState) { - return nsBox::DoLayout(aState); + return nsBox::DoXULLayout(aState); } diff --git a/layout/xul/nsLeafBoxFrame.h b/layout/xul/nsLeafBoxFrame.h index 916df090b8..bc8196ad1e 100644 --- a/layout/xul/nsLeafBoxFrame.h +++ b/layout/xul/nsLeafBoxFrame.h @@ -16,11 +16,11 @@ public: friend nsIFrame* NS_NewLeafBoxFrame(nsIPresShell* aPresShell, nsStyleContext* aContext); - virtual nsSize GetPrefSize(nsBoxLayoutState& aState) override; - virtual nsSize GetMinSize(nsBoxLayoutState& aState) override; - virtual nsSize GetMaxSize(nsBoxLayoutState& aState) override; - virtual nscoord GetFlex() override; - virtual nscoord GetBoxAscent(nsBoxLayoutState& aState) override; + virtual nsSize GetXULPrefSize(nsBoxLayoutState& aState) override; + virtual nsSize GetXULMinSize(nsBoxLayoutState& aState) override; + virtual nsSize GetXULMaxSize(nsBoxLayoutState& aState) override; + virtual nscoord GetXULFlex() override; + virtual nscoord GetXULBoxAscent(nsBoxLayoutState& aState) override; virtual nsIAtom* GetType() const override; virtual bool IsFrameOfType(uint32_t aFlags) const override @@ -75,7 +75,7 @@ public: protected: - NS_IMETHOD DoLayout(nsBoxLayoutState& aState) override; + NS_IMETHOD DoXULLayout(nsBoxLayoutState& aState) override; #ifdef DEBUG_LAYOUT virtual void GetBoxName(nsAutoString& aName) override; diff --git a/layout/xul/nsListBoxBodyFrame.cpp b/layout/xul/nsListBoxBodyFrame.cpp index 7fb7e453b0..cb1fca615f 100644 --- a/layout/xul/nsListBoxBodyFrame.cpp +++ b/layout/xul/nsListBoxBodyFrame.cpp @@ -250,12 +250,12 @@ nsListBoxBodyFrame::MarkIntrinsicISizesDirty() /////////// nsBox /////////////// NS_IMETHODIMP -nsListBoxBodyFrame::DoLayout(nsBoxLayoutState& aBoxLayoutState) +nsListBoxBodyFrame::DoXULLayout(nsBoxLayoutState& aBoxLayoutState) { if (mScrolling) aBoxLayoutState.SetPaintingDisabled(true); - nsresult rv = nsBoxFrame::DoLayout(aBoxLayoutState); + nsresult rv = nsBoxFrame::DoXULLayout(aBoxLayoutState); // determine the real height for the scrollable area from the total number // of rows, since non-visible rows don't yet have frames @@ -268,7 +268,7 @@ nsListBoxBodyFrame::DoLayout(nsBoxLayoutState& aBoxLayoutState) childFrame = childFrame->GetNextSibling(); } - nsSize prefSize = mLayoutManager->GetPrefSize(this, aBoxLayoutState); + nsSize prefSize = mLayoutManager->GetXULPrefSize(this, aBoxLayoutState); NS_FOR_FRAME_OVERFLOW_TYPES(otype) { nsRect& o = overflow.Overflow(otype); o.height = std::max(o.height, prefSize.height); @@ -288,12 +288,12 @@ nsListBoxBodyFrame::DoLayout(nsBoxLayoutState& aBoxLayoutState) } nsSize -nsListBoxBodyFrame::GetMinSizeForScrollArea(nsBoxLayoutState& aBoxLayoutState) +nsListBoxBodyFrame::GetXULMinSizeForScrollArea(nsBoxLayoutState& aBoxLayoutState) { nsSize result(0, 0); if (nsContentUtils::HasNonEmptyAttr(GetContent(), kNameSpaceID_None, nsGkAtoms::sizemode)) { - result = GetPrefSize(aBoxLayoutState); + result = GetXULPrefSize(aBoxLayoutState); result.height = 0; nsIScrollableFrame* scrollFrame = nsLayoutUtils::GetScrollableFrameFor(this); if (scrollFrame && @@ -307,9 +307,9 @@ nsListBoxBodyFrame::GetMinSizeForScrollArea(nsBoxLayoutState& aBoxLayoutState) } nsSize -nsListBoxBodyFrame::GetPrefSize(nsBoxLayoutState& aBoxLayoutState) +nsListBoxBodyFrame::GetXULPrefSize(nsBoxLayoutState& aBoxLayoutState) { - nsSize pref = nsBoxFrame::GetPrefSize(aBoxLayoutState); + nsSize pref = nsBoxFrame::GetXULPrefSize(aBoxLayoutState); int32_t size = GetFixedRowSize(); if (size > -1) @@ -1008,7 +1008,7 @@ nsListBoxBodyFrame::CreateRows() { // Get our client rect. nsRect clientRect; - GetClientRect(clientRect); + GetXULClientRect(clientRect); // Get the starting y position and the remaining available // height. @@ -1130,7 +1130,7 @@ nsListBoxBodyFrame::GetFirstItemBox(int32_t aOffset, bool* aCreated) mBottomFrame = mTopFrame; if (mTopFrame) { - return mTopFrame->IsBoxFrame() ? mTopFrame : nullptr; + return mTopFrame->IsXULBoxFrame() ? mTopFrame : nullptr; } // top frame was cleared out @@ -1138,7 +1138,7 @@ nsListBoxBodyFrame::GetFirstItemBox(int32_t aOffset, bool* aCreated) mBottomFrame = mTopFrame; if (mTopFrame && mRowsToPrepend <= 0) { - return mTopFrame->IsBoxFrame() ? mTopFrame : nullptr; + return mTopFrame->IsXULBoxFrame() ? mTopFrame : nullptr; } // At this point, we either have no frames at all, @@ -1168,7 +1168,7 @@ nsListBoxBodyFrame::GetFirstItemBox(int32_t aOffset, bool* aCreated) return GetFirstItemBox(++aOffset, aCreated); } if (existingFrame) { - return existingFrame->IsBoxFrame() ? existingFrame : nullptr; + return existingFrame->IsXULBoxFrame() ? existingFrame : nullptr; } // Either append the new frame, or prepend it (at index 0) @@ -1187,7 +1187,7 @@ nsListBoxBodyFrame::GetFirstItemBox(int32_t aOffset, bool* aCreated) mBottomFrame = mTopFrame; - return mTopFrame->IsBoxFrame() ? mTopFrame : nullptr; + return mTopFrame->IsXULBoxFrame() ? mTopFrame : nullptr; } else return GetFirstItemBox(++aOffset, 0); } @@ -1252,10 +1252,10 @@ nsListBoxBodyFrame::GetNextItemBox(nsIFrame* aBox, int32_t aOffset, mBottomFrame = result; - NS_ASSERTION(!result->IsBoxFrame() || result->GetParent() == this, + NS_ASSERTION(!result->IsXULBoxFrame() || result->GetParent() == this, "returning frame that is not in childlist"); - return result->IsBoxFrame() ? result : nullptr; + return result->IsXULBoxFrame() ? result : nullptr; } bool diff --git a/layout/xul/nsListBoxBodyFrame.h b/layout/xul/nsListBoxBodyFrame.h index 1af819ddee..37fe5a563a 100644 --- a/layout/xul/nsListBoxBodyFrame.h +++ b/layout/xul/nsListBoxBodyFrame.h @@ -84,11 +84,11 @@ public: virtual bool ReflowFinished() override; virtual void ReflowCallbackCanceled() override; - NS_IMETHOD DoLayout(nsBoxLayoutState& aBoxLayoutState) override; + NS_IMETHOD DoXULLayout(nsBoxLayoutState& aBoxLayoutState) override; virtual void MarkIntrinsicISizesDirty() override; - virtual nsSize GetMinSizeForScrollArea(nsBoxLayoutState& aBoxLayoutState) override; - virtual nsSize GetPrefSize(nsBoxLayoutState& aBoxLayoutState) override; + virtual nsSize GetXULMinSizeForScrollArea(nsBoxLayoutState& aBoxLayoutState) override; + virtual nsSize GetXULPrefSize(nsBoxLayoutState& aBoxLayoutState) override; // size calculation int32_t GetRowCount(); diff --git a/layout/xul/nsListBoxLayout.cpp b/layout/xul/nsListBoxLayout.cpp index 58224d7d0f..a2f915191a 100644 --- a/layout/xul/nsListBoxLayout.cpp +++ b/layout/xul/nsListBoxLayout.cpp @@ -21,9 +21,9 @@ nsListBoxLayout::nsListBoxLayout() : nsGridRowGroupLayout() ////////// nsBoxLayout ////////////// nsSize -nsListBoxLayout::GetPrefSize(nsIFrame* aBox, nsBoxLayoutState& aBoxLayoutState) +nsListBoxLayout::GetXULPrefSize(nsIFrame* aBox, nsBoxLayoutState& aBoxLayoutState) { - nsSize pref = nsGridRowGroupLayout::GetPrefSize(aBox, aBoxLayoutState); + nsSize pref = nsGridRowGroupLayout::GetXULPrefSize(aBox, aBoxLayoutState); nsListBoxBodyFrame* frame = static_cast(aBox); if (frame) { @@ -47,9 +47,9 @@ nsListBoxLayout::GetPrefSize(nsIFrame* aBox, nsBoxLayoutState& aBoxLayoutState) } nsSize -nsListBoxLayout::GetMinSize(nsIFrame* aBox, nsBoxLayoutState& aBoxLayoutState) +nsListBoxLayout::GetXULMinSize(nsIFrame* aBox, nsBoxLayoutState& aBoxLayoutState) { - nsSize minSize = nsGridRowGroupLayout::GetMinSize(aBox, aBoxLayoutState); + nsSize minSize = nsGridRowGroupLayout::GetXULMinSize(aBox, aBoxLayoutState); nsListBoxBodyFrame* frame = static_cast(aBox); if (frame) { @@ -73,9 +73,9 @@ nsListBoxLayout::GetMinSize(nsIFrame* aBox, nsBoxLayoutState& aBoxLayoutState) } nsSize -nsListBoxLayout::GetMaxSize(nsIFrame* aBox, nsBoxLayoutState& aBoxLayoutState) +nsListBoxLayout::GetXULMaxSize(nsIFrame* aBox, nsBoxLayoutState& aBoxLayoutState) { - nsSize maxSize = nsGridRowGroupLayout::GetMaxSize(aBox, aBoxLayoutState); + nsSize maxSize = nsGridRowGroupLayout::GetXULMaxSize(aBox, aBoxLayoutState); nsListBoxBodyFrame* frame = static_cast(aBox); if (frame) { @@ -93,7 +93,7 @@ nsListBoxLayout::GetMaxSize(nsIFrame* aBox, nsBoxLayoutState& aBoxLayoutState) } NS_IMETHODIMP -nsListBoxLayout::Layout(nsIFrame* aBox, nsBoxLayoutState& aState) +nsListBoxLayout::XULLayout(nsIFrame* aBox, nsBoxLayoutState& aState) { return LayoutInternal(aBox, aState); } @@ -120,7 +120,7 @@ nsListBoxLayout::LayoutInternal(nsIFrame* aBox, nsBoxLayoutState& aState) // Get our client rect. nsRect clientRect; - aBox->GetClientRect(clientRect); + aBox->GetXULClientRect(clientRect); // Get the starting y position and the remaining available // height. @@ -136,7 +136,7 @@ nsListBoxLayout::LayoutInternal(nsIFrame* aBox, nsBoxLayoutState& aState) } // run through all our currently created children - nsIFrame* box = nsBox::GetChildBox(body); + nsIFrame* box = nsBox::GetChildXULBox(body); // if the reason is resize or initial we must relayout. nscoord rowHeight = body->GetRowHeightAppUnits(); @@ -145,7 +145,7 @@ nsListBoxLayout::LayoutInternal(nsIFrame* aBox, nsBoxLayoutState& aState) // If this box is dirty or if it has dirty children, we // call layout on it. nsRect childRect(box->GetRect()); - box->GetMargin(margin); + box->GetXULMargin(margin); // relayout if we must or we are dirty or some of our children are dirty // or the client area is wider than us @@ -155,14 +155,14 @@ nsListBoxLayout::LayoutInternal(nsIFrame* aBox, nsBoxLayoutState& aState) childRect.y = yOffset; childRect.width = clientRect.width; - nsSize size = box->GetPrefSize(aState); + nsSize size = box->GetXULPrefSize(aState); body->SetRowHeight(size.height); childRect.height = rowHeight; childRect.Deflate(margin); - box->SetBounds(aState, childRect); - box->Layout(aState); + box->SetXULBounds(aState, childRect); + box->XULLayout(aState); } else { // if the child did not need to be relayed out. Then its easy. // Place the child by just grabbing its rect and adjusting the y. @@ -175,7 +175,7 @@ nsListBoxLayout::LayoutInternal(nsIFrame* aBox, nsBoxLayoutState& aState) redrawStart = newPos; childRect.y = newPos; - box->SetBounds(aState, childRect); + box->SetXULBounds(aState, childRect); } // Ok now the available size gets smaller and we move the @@ -185,7 +185,7 @@ nsListBoxLayout::LayoutInternal(nsIFrame* aBox, nsBoxLayoutState& aState) yOffset += size; availableHeight -= size; - box = nsBox::GetNextBox(box); + box = nsBox::GetNextXULBox(box); } // We have enough available height left to add some more rows @@ -197,7 +197,7 @@ nsListBoxLayout::LayoutInternal(nsIFrame* aBox, nsBoxLayoutState& aState) // before them then redraw everything under the inserted rows. The inserted // rows will automatically be redrawn because the were marked dirty on insertion. if (redrawStart > -1) { - aBox->Redraw(aState); + aBox->XULRedraw(aState); } return NS_OK; diff --git a/layout/xul/nsListBoxLayout.h b/layout/xul/nsListBoxLayout.h index 999a26fcb6..d1f9788433 100644 --- a/layout/xul/nsListBoxLayout.h +++ b/layout/xul/nsListBoxLayout.h @@ -19,10 +19,10 @@ public: nsListBoxLayout(); // nsBoxLayout - NS_IMETHOD Layout(nsIFrame* aBox, nsBoxLayoutState& aState) override; - virtual nsSize GetPrefSize(nsIFrame* aBox, nsBoxLayoutState& aBoxLayoutState) override; - virtual nsSize GetMinSize(nsIFrame* aBox, nsBoxLayoutState& aBoxLayoutState) override; - virtual nsSize GetMaxSize(nsIFrame* aBox, nsBoxLayoutState& aBoxLayoutState) override; + NS_IMETHOD XULLayout(nsIFrame* aBox, nsBoxLayoutState& aState) override; + virtual nsSize GetXULPrefSize(nsIFrame* aBox, nsBoxLayoutState& aBoxLayoutState) override; + virtual nsSize GetXULMinSize(nsIFrame* aBox, nsBoxLayoutState& aBoxLayoutState) override; + virtual nsSize GetXULMaxSize(nsIFrame* aBox, nsBoxLayoutState& aBoxLayoutState) override; protected: NS_IMETHOD LayoutInternal(nsIFrame* aBox, nsBoxLayoutState& aState); diff --git a/layout/xul/nsListItemFrame.cpp b/layout/xul/nsListItemFrame.cpp index 69d36b1df5..1776f1b6cb 100644 --- a/layout/xul/nsListItemFrame.cpp +++ b/layout/xul/nsListItemFrame.cpp @@ -26,9 +26,9 @@ nsListItemFrame::~nsListItemFrame() } nsSize -nsListItemFrame::GetPrefSize(nsBoxLayoutState& aState) +nsListItemFrame::GetXULPrefSize(nsBoxLayoutState& aState) { - nsSize size = nsBoxFrame::GetPrefSize(aState); + nsSize size = nsBoxFrame::GetXULPrefSize(aState); DISPLAY_PREF_SIZE(this, size); // guarantee that our preferred height doesn't exceed the standard diff --git a/layout/xul/nsListItemFrame.h b/layout/xul/nsListItemFrame.h index 95f874ac02..40e731efa5 100644 --- a/layout/xul/nsListItemFrame.h +++ b/layout/xul/nsListItemFrame.h @@ -23,7 +23,7 @@ public: const nsRect& aDirtyRect, const nsDisplayListSet& aLists) override; - virtual nsSize GetPrefSize(nsBoxLayoutState& aState) override; + virtual nsSize GetXULPrefSize(nsBoxLayoutState& aState) override; protected: explicit nsListItemFrame(nsStyleContext *aContext, diff --git a/layout/xul/nsMenuBarFrame.cpp b/layout/xul/nsMenuBarFrame.cpp index 07da739242..03ce9fbe35 100644 --- a/layout/xul/nsMenuBarFrame.cpp +++ b/layout/xul/nsMenuBarFrame.cpp @@ -52,7 +52,6 @@ NS_QUERYFRAME_TAIL_INHERITING(nsBoxFrame) // nsMenuBarFrame::nsMenuBarFrame(nsStyleContext* aContext): nsBoxFrame(aContext), - mMenuBarListener(nullptr), mStayActive(false), mIsActive(false), mCurrentMenu(nullptr), @@ -69,7 +68,6 @@ nsMenuBarFrame::Init(nsIContent* aContent, // Create the menu bar listener. mMenuBarListener = new nsMenuBarListener(this); - NS_ADDREF(mMenuBarListener); // Hook up the menu bar as a key listener on the whole document. It will see every // key press that occurs, but after everyone else does. @@ -423,7 +421,8 @@ nsMenuBarFrame::DestroyFrom(nsIFrame* aDestructRoot) mTarget->RemoveEventListener(NS_LITERAL_STRING("mousedown"), mMenuBarListener, false); mTarget->RemoveEventListener(NS_LITERAL_STRING("blur"), mMenuBarListener, true); - NS_IF_RELEASE(mMenuBarListener); + mMenuBarListener->OnDestroyMenuBarFrame(); + mMenuBarListener = nullptr; nsBoxFrame::DestroyFrom(aDestructRoot); } diff --git a/layout/xul/nsMenuBarFrame.h b/layout/xul/nsMenuBarFrame.h index 89f36dd84c..676463c50e 100644 --- a/layout/xul/nsMenuBarFrame.h +++ b/layout/xul/nsMenuBarFrame.h @@ -103,7 +103,7 @@ public: #endif protected: - nsMenuBarListener* mMenuBarListener; // The listener that tells us about key and mouse events. + RefPtr mMenuBarListener; // The listener that tells us about key and mouse events. // flag that is temporarily set when switching from one menu on the menubar to another // to indicate that the menubar should not be deactivated. diff --git a/layout/xul/nsMenuBarListener.cpp b/layout/xul/nsMenuBarListener.cpp index 9a705bbcf1..f600389b3c 100644 --- a/layout/xul/nsMenuBarListener.cpp +++ b/layout/xul/nsMenuBarListener.cpp @@ -47,6 +47,12 @@ nsMenuBarListener::~nsMenuBarListener() { } +void +nsMenuBarListener::OnDestroyMenuBarFrame() +{ + mMenuBarFrame = nullptr; +} + void nsMenuBarListener::InitializeStatics() { @@ -140,15 +146,30 @@ nsMenuBarListener::KeyUp(nsIDOMEvent* aKeyEvent) { // The access key was down and is now up, and no other // keys were pressed in between. + bool toggleMenuActiveState = true; if (!mMenuBarFrame->IsActive()) { - mMenuBarFrame->SetActiveByKeyboard(); + // First, close all existing popups because other popups shouldn't + // handle key events when menubar is active and IME should be + // disabled. + nsXULPopupManager* pm = nsXULPopupManager::GetInstance(); + if (pm) { + pm->Rollup(0, false, nullptr, nullptr); + } + // If menubar active state is changed or the menubar is destroyed + // during closing the popups, we should do nothing anymore. + toggleMenuActiveState = !Destroyed() && !mMenuBarFrame->IsActive(); + } + if (toggleMenuActiveState) { + if (!mMenuBarFrame->IsActive()) { + mMenuBarFrame->SetActiveByKeyboard(); + } + ToggleMenuActiveState(); } - ToggleMenuActiveState(); } mAccessKeyDown = false; mAccessKeyDownCanceled = false; - bool active = mMenuBarFrame->IsActive(); + bool active = !Destroyed() && mMenuBarFrame->IsActive(); if (active) { aKeyEvent->StopPropagation(); aKeyEvent->PreventDefault(); diff --git a/layout/xul/nsMenuBarListener.h b/layout/xul/nsMenuBarListener.h index cbab21e3f5..c4b2673b29 100644 --- a/layout/xul/nsMenuBarListener.h +++ b/layout/xul/nsMenuBarListener.h @@ -42,6 +42,8 @@ public: static bool IsAccessKeyPressed(nsIDOMKeyEvent* event); + void OnDestroyMenuBarFrame(); + protected: /** default destructor */ @@ -55,6 +57,8 @@ protected: // thus ensuring that this doesn't get destroyed during the process. void ToggleMenuActiveState(); + bool Destroyed() const { return !mMenuBarFrame; } + nsMenuBarFrame* mMenuBarFrame; // The menu bar object. // Whether or not the ALT key is currently down. bool mAccessKeyDown; diff --git a/layout/xul/nsMenuFrame.cpp b/layout/xul/nsMenuFrame.cpp index d1e911b219..3abe06f6b2 100644 --- a/layout/xul/nsMenuFrame.cpp +++ b/layout/xul/nsMenuFrame.cpp @@ -711,9 +711,9 @@ nsMenuFrame::IsSizedToPopup(nsIContent* aContent, bool aRequireAlways) } nsSize -nsMenuFrame::GetMinSize(nsBoxLayoutState& aBoxLayoutState) +nsMenuFrame::GetXULMinSize(nsBoxLayoutState& aBoxLayoutState) { - nsSize size = nsBoxFrame::GetMinSize(aBoxLayoutState); + nsSize size = nsBoxFrame::GetXULMinSize(aBoxLayoutState); DISPLAY_MIN_SIZE(this, size); if (IsSizedToPopup(mContent, true)) @@ -723,10 +723,10 @@ nsMenuFrame::GetMinSize(nsBoxLayoutState& aBoxLayoutState) } NS_IMETHODIMP -nsMenuFrame::DoLayout(nsBoxLayoutState& aState) +nsMenuFrame::DoXULLayout(nsBoxLayoutState& aState) { // lay us out - nsresult rv = nsBoxFrame::DoLayout(aState); + nsresult rv = nsBoxFrame::DoXULLayout(aState); nsMenuPopupFrame* popupFrame = GetPopup(); if (popupFrame) { @@ -739,7 +739,7 @@ nsMenuFrame::DoLayout(nsBoxLayoutState& aState) #ifdef DEBUG_LAYOUT nsresult -nsMenuFrame::SetDebug(nsBoxLayoutState& aState, bool aDebug) +nsMenuFrame::SetXULDebug(nsBoxLayoutState& aState, bool aDebug) { // see if our state matches the given debug state bool debugSet = mState & NS_STATE_CURRENTLY_IN_DEBUG; @@ -748,24 +748,24 @@ nsMenuFrame::SetDebug(nsBoxLayoutState& aState, bool aDebug) // if it doesn't then tell each child below us the new debug state if (debugChanged) { - nsBoxFrame::SetDebug(aState, aDebug); + nsBoxFrame::SetXULDebug(aState, aDebug); nsMenuPopupFrame* popupFrame = GetPopup(); if (popupFrame) - SetDebug(aState, popupFrame, aDebug); + SetXULDebug(aState, popupFrame, aDebug); } return NS_OK; } nsresult -nsMenuFrame::SetDebug(nsBoxLayoutState& aState, nsIFrame* aList, bool aDebug) +nsMenuFrame::SetXULDebug(nsBoxLayoutState& aState, nsIFrame* aList, bool aDebug) { if (!aList) return NS_OK; while (aList) { - if (aList->IsBoxFrame()) - aList->SetDebug(aState, aDebug); + if (aList->IsXULBoxFrame()) + aList->SetXULDebug(aState, aDebug); aList = aList->GetNextSibling(); } @@ -1293,7 +1293,7 @@ nsMenuFrame::InsertFrames(ChildListID aListID, if (HasPopup()) { #ifdef DEBUG_LAYOUT nsBoxLayoutState state(PresContext()); - SetDebug(state, aFrameList, mState & NS_STATE_CURRENTLY_IN_DEBUG); + SetXULDebug(state, aFrameList, mState & NS_STATE_CURRENTLY_IN_DEBUG); #endif PresContext()->PresShell()-> @@ -1322,7 +1322,7 @@ nsMenuFrame::AppendFrames(ChildListID aListID, #ifdef DEBUG_LAYOUT nsBoxLayoutState state(PresContext()); - SetDebug(state, aFrameList, mState & NS_STATE_CURRENTLY_IN_DEBUG); + SetXULDebug(state, aFrameList, mState & NS_STATE_CURRENTLY_IN_DEBUG); #endif PresContext()->PresShell()-> FrameNeedsReflow(this, nsIPresShell::eTreeChange, @@ -1339,15 +1339,15 @@ nsMenuFrame::AppendFrames(ChildListID aListID, bool nsMenuFrame::SizeToPopup(nsBoxLayoutState& aState, nsSize& aSize) { - if (!IsCollapsed()) { + if (!IsXULCollapsed()) { bool widthSet, heightSet; nsSize tmpSize(-1, 0); - nsIFrame::AddCSSPrefSize(this, tmpSize, widthSet, heightSet); - if (!widthSet && GetFlex() == 0) { + nsIFrame::AddXULPrefSize(this, tmpSize, widthSet, heightSet); + if (!widthSet && GetXULFlex() == 0) { nsMenuPopupFrame* popupFrame = GetPopup(); if (!popupFrame) return false; - tmpSize = popupFrame->GetPrefSize(aState); + tmpSize = popupFrame->GetXULPrefSize(aState); // Produce a size such that: // (1) the menu and its popup can be the same width @@ -1356,7 +1356,7 @@ nsMenuFrame::SizeToPopup(nsBoxLayoutState& aState, nsSize& aSize) // (3) there's enough room in the popup for the content and its // scrollbar nsMargin borderPadding; - GetBorderAndPadding(borderPadding); + GetXULBorderAndPadding(borderPadding); // if there is a scroll frame, add the desired width of the scrollbar as well nsIScrollableFrame* scrollFrame = do_QueryFrame(popupFrame->PrincipalChildList().FirstChild()); @@ -1377,9 +1377,9 @@ nsMenuFrame::SizeToPopup(nsBoxLayoutState& aState, nsSize& aSize) } nsSize -nsMenuFrame::GetPrefSize(nsBoxLayoutState& aState) +nsMenuFrame::GetXULPrefSize(nsBoxLayoutState& aState) { - nsSize size = nsBoxFrame::GetPrefSize(aState); + nsSize size = nsBoxFrame::GetXULPrefSize(aState); DISPLAY_PREF_SIZE(this, size); // If we are using sizetopopup="always" then @@ -1388,8 +1388,8 @@ nsMenuFrame::GetPrefSize(nsBoxLayoutState& aState) IsSizedToPopup(mContent, false) && SizeToPopup(aState, size)) { // We now need to ensure that size is within the min - max range. - nsSize minSize = nsBoxFrame::GetMinSize(aState); - nsSize maxSize = GetMaxSize(aState); + nsSize minSize = nsBoxFrame::GetXULMinSize(aState); + nsSize maxSize = GetXULMaxSize(aState); size = BoundsCheck(minSize, size, maxSize); } diff --git a/layout/xul/nsMenuFrame.h b/layout/xul/nsMenuFrame.h index c49382436c..1941ec69e6 100644 --- a/layout/xul/nsMenuFrame.h +++ b/layout/xul/nsMenuFrame.h @@ -80,16 +80,16 @@ public: NS_DECL_QUERYFRAME NS_DECL_FRAMEARENA_HELPERS - NS_IMETHOD DoLayout(nsBoxLayoutState& aBoxLayoutState) override; - virtual nsSize GetMinSize(nsBoxLayoutState& aBoxLayoutState) override; - virtual nsSize GetPrefSize(nsBoxLayoutState& aBoxLayoutState) override; + NS_IMETHOD DoXULLayout(nsBoxLayoutState& aBoxLayoutState) override; + virtual nsSize GetXULMinSize(nsBoxLayoutState& aBoxLayoutState) override; + virtual nsSize GetXULPrefSize(nsBoxLayoutState& aBoxLayoutState) override; virtual void Init(nsIContent* aContent, nsContainerFrame* aParent, nsIFrame* aPrevInFlow) override; #ifdef DEBUG_LAYOUT - virtual nsresult SetDebug(nsBoxLayoutState& aState, bool aDebug) override; + virtual nsresult SetXULDebug(nsBoxLayoutState& aState, bool aDebug) override; #endif // The following methods are all overridden so that the menupopup @@ -263,7 +263,7 @@ protected: protected: #ifdef DEBUG_LAYOUT - nsresult SetDebug(nsBoxLayoutState& aState, nsIFrame* aList, bool aDebug); + nsresult SetXULDebug(nsBoxLayoutState& aState, nsIFrame* aList, bool aDebug); #endif nsresult Notify(nsITimer* aTimer); diff --git a/layout/xul/nsMenuPopupFrame.cpp b/layout/xul/nsMenuPopupFrame.cpp index c9b7cd9bb8..9217d64316 100644 --- a/layout/xul/nsMenuPopupFrame.cpp +++ b/layout/xul/nsMenuPopupFrame.cpp @@ -360,6 +360,13 @@ NS_IMETHODIMP nsXULPopupShownEvent::Run() NS_IMETHODIMP nsXULPopupShownEvent::HandleEvent(nsIDOMEvent* aEvent) { nsMenuPopupFrame* popup = do_QueryFrame(mPopup->GetPrimaryFrame()); + nsCOMPtr eventTarget; + aEvent->GetTarget(getter_AddRefs(eventTarget)); + // Ignore events not targeted at the popup itself (ie targeted at + // descendants): + if (!SameCOMIdentity(mPopup, eventTarget)) { + return NS_OK; + } if (popup) { // ResetPopupShownDispatcher will delete the reference to this, so keep // another one until Run is finished. @@ -438,7 +445,7 @@ nsMenuPopupFrame::LayoutPopup(nsBoxLayoutState& aState, nsIFrame* aParentMenu, // if the popup has just been opened, make sure the scrolled window is at 0,0 if (mIsOpenChanged) { - nsIScrollableFrame *scrollframe = do_QueryFrame(nsBox::GetChildBox(this)); + nsIScrollableFrame *scrollframe = do_QueryFrame(nsBox::GetChildXULBox(this)); if (scrollframe) { nsWeakFrame weakFrame(this); scrollframe->ScrollTo(nsPoint(0,0), nsIScrollableFrame::INSTANT); @@ -450,9 +457,9 @@ nsMenuPopupFrame::LayoutPopup(nsBoxLayoutState& aState, nsIFrame* aParentMenu, // get the preferred, minimum and maximum size. If the menu is sized to the // popup, then the popup's width is the menu's width. - nsSize prefSize = GetPrefSize(aState); - nsSize minSize = GetMinSize(aState); - nsSize maxSize = GetMaxSize(aState); + nsSize prefSize = GetXULPrefSize(aState); + nsSize minSize = GetXULMinSize(aState); + nsSize maxSize = GetXULMaxSize(aState); if (aSizedToPopup) { prefSize.width = aParentMenu->GetRect().width; @@ -462,7 +469,7 @@ nsMenuPopupFrame::LayoutPopup(nsBoxLayoutState& aState, nsIFrame* aParentMenu, // if the size changed then set the bounds to be the preferred size bool sizeChanged = (mPrefSize != prefSize); if (sizeChanged) { - SetBounds(aState, nsRect(0, 0, prefSize.width, prefSize.height), false); + SetXULBounds(aState, nsRect(0, 0, prefSize.width, prefSize.height), false); mPrefSize = prefSize; } @@ -474,7 +481,7 @@ nsMenuPopupFrame::LayoutPopup(nsBoxLayoutState& aState, nsIFrame* aParentMenu, } nsRect bounds(GetRect()); - Layout(aState); + XULLayout(aState); // if the width or height changed, readjust the popup position. This is a // special case for tooltips where the preferred height doesn't include the @@ -1302,6 +1309,13 @@ nsMenuPopupFrame::SetPopupPosition(nsIFrame* aAnchorFrame, bool aIsMove, bool aS mRect.width = aSizedToPopup ? parentWidth : mPrefSize.width; mRect.height = mPrefSize.height; + // If we're anchoring to a rect, and the rect is smaller than the preferred size + // of the popup, change its width accordingly. + if (mAnchorType == MenuPopupAnchorType_Rect && + parentWidth < mPrefSize.width) { + mRect.width = mPrefSize.width; + } + // the screen position in app units where the popup should appear nsPoint screenPoint; @@ -1400,8 +1414,17 @@ nsMenuPopupFrame::SetPopupPosition(nsIFrame* aAnchorFrame, bool aIsMove, bool aS screenPoint.MoveBy(margin.left + offsetForContextMenu.x, margin.top + offsetForContextMenu.y); - // screen positioned popups can be flipped vertically but never horizontally +#ifdef XP_MACOSX + // OSX tooltips follow standard flip rule but other popups flip horizontally not vertically + if (mPopupType == ePopupTypeTooltip) { + vFlip = FlipStyle_Outside; + } else { + hFlip = FlipStyle_Outside; + } +#else + // Other OS screen positioned popups can be flipped vertically but never horizontally vFlip = FlipStyle_Outside; +#endif // #ifdef XP_MACOSX } // If a panel is being moved or has flip="none", don't constrain or flip it. But always do this for @@ -1502,7 +1525,7 @@ nsMenuPopupFrame::SetPopupPosition(nsIFrame* aAnchorFrame, bool aIsMove, bool aS if (aSizedToPopup) { nsBoxLayoutState state(PresContext()); // XXXndeakin can parentSize.width still extend outside? - SetBounds(state, nsRect(mRect.x, mRect.y, parentWidth, mRect.height)); + SetXULBounds(state, mRect); } return NS_OK; @@ -1531,9 +1554,12 @@ nsMenuPopupFrame::GetConstraintRect(const LayoutDeviceIntRect& aAnchorRect, // This is because we need to constrain the content to this content area, // so we should use the same screen. Otherwise, use the screen where the // anchor is located. - LayoutDeviceIntRect rect = mInContentShell ? aRootScreenRect : aAnchorRect; - int32_t width = std::max(1, rect.width); - int32_t height = std::max(1, rect.height); + DesktopToLayoutDeviceScale scale = + PresContext()->DeviceContext()->GetDesktopToDeviceScale(); + DesktopRect rect = + (mInContentShell ? aRootScreenRect : aAnchorRect) / scale; + int32_t width = std::max(1, NSToIntRound(rect.width)); + int32_t height = std::max(1, NSToIntRound(rect.height)); sm->ScreenForRect(rect.x, rect.y, width, height, getter_AddRefs(screen)); if (screen) { // Non-top-level popups (which will always be panels) @@ -1832,8 +1858,7 @@ nsMenuPopupFrame::ChangeMenuItem(nsMenuFrame* aMenuItem, // Fire a command event as the new item, but we don't want to close // the menu, blink it, or update any other state of the menuitem. The // command event will cause the item to be selected. - nsContentUtils::DispatchXULCommand(aMenuItem->GetContent(), - nsContentUtils::IsCallerChrome(), + nsContentUtils::DispatchXULCommand(aMenuItem->GetContent(), /* aTrusted = */ true, nullptr, PresContext()->PresShell(), false, false, false, false); } @@ -2080,6 +2105,14 @@ nsMenuPopupFrame::AttributeChanged(int32_t aNameSpaceID, if (aAttribute == nsGkAtoms::left || aAttribute == nsGkAtoms::top) MoveToAttributePosition(); +#ifndef MOZ_GTK2 + if (aAttribute == nsGkAtoms::noautohide) { + nsXULPopupManager* pm = nsXULPopupManager::GetInstance(); + if (pm) + pm->EnableRollup(mContent, !IsNoAutoHide()); + } +#endif + if (aAttribute == nsGkAtoms::label) { // set the label for the titlebar nsView* view = GetView(); @@ -2171,8 +2204,7 @@ nsMenuPopupFrame::MoveTo(const CSSIntPoint& aPos, bool aUpdateAttrs) } nsPresContext* presContext = PresContext(); - mAnchorType = aPos.x == -1 || aPos.y == -1 ? - MenuPopupAnchorType_Node : MenuPopupAnchorType_Point; + mAnchorType = MenuPopupAnchorType_Point; mScreenRect.x = aPos.x - presContext->AppUnitsToIntCSSPixels(margin.left); mScreenRect.y = aPos.y - presContext->AppUnitsToIntCSSPixels(margin.top); diff --git a/layout/xul/nsPopupSetFrame.cpp b/layout/xul/nsPopupSetFrame.cpp index f1d243aa50..a627ee0795 100644 --- a/layout/xul/nsPopupSetFrame.cpp +++ b/layout/xul/nsPopupSetFrame.cpp @@ -122,10 +122,10 @@ nsPopupSetFrame::DestroyFrom(nsIFrame* aDestructRoot) } NS_IMETHODIMP -nsPopupSetFrame::DoLayout(nsBoxLayoutState& aState) +nsPopupSetFrame::DoXULLayout(nsBoxLayoutState& aState) { // lay us out - nsresult rv = nsBoxFrame::DoLayout(aState); + nsresult rv = nsBoxFrame::DoXULLayout(aState); // lay out all of our currently open popups. for (nsFrameList::Enumerator e(mPopupList); !e.AtEnd(); e.Next()) { diff --git a/layout/xul/nsPopupSetFrame.h b/layout/xul/nsPopupSetFrame.h index 5b6249b080..1981b996d3 100644 --- a/layout/xul/nsPopupSetFrame.h +++ b/layout/xul/nsPopupSetFrame.h @@ -40,7 +40,7 @@ public: virtual const nsFrameList& GetChildList(ChildListID aList) const override; virtual void GetChildLists(nsTArray* aLists) const override; - NS_IMETHOD DoLayout(nsBoxLayoutState& aBoxLayoutState) override; + NS_IMETHOD DoXULLayout(nsBoxLayoutState& aBoxLayoutState) override; // Used to destroy our popup frames. virtual void DestroyFrom(nsIFrame* aDestructRoot) override; diff --git a/layout/xul/nsProgressMeterFrame.cpp b/layout/xul/nsProgressMeterFrame.cpp index 2d46386f67..d2ce346d30 100644 --- a/layout/xul/nsProgressMeterFrame.cpp +++ b/layout/xul/nsProgressMeterFrame.cpp @@ -104,7 +104,7 @@ public: }; NS_IMETHODIMP -nsProgressMeterFrame::DoLayout(nsBoxLayoutState& aState) +nsProgressMeterFrame::DoXULLayout(nsBoxLayoutState& aState) { if (mNeedsReflowCallback) { nsIReflowCallback* cb = new nsAsyncProgressMeterInit(this); @@ -113,7 +113,7 @@ nsProgressMeterFrame::DoLayout(nsBoxLayoutState& aState) } mNeedsReflowCallback = false; } - return nsBoxFrame::DoLayout(aState); + return nsBoxFrame::DoXULLayout(aState); } nsresult diff --git a/layout/xul/nsProgressMeterFrame.h b/layout/xul/nsProgressMeterFrame.h index 31e2a99d17..0a4af7ff41 100644 --- a/layout/xul/nsProgressMeterFrame.h +++ b/layout/xul/nsProgressMeterFrame.h @@ -27,7 +27,7 @@ public: friend nsIFrame* NS_NewProgressMeterFrame(nsIPresShell* aPresShell, nsStyleContext* aContext); - NS_IMETHOD DoLayout(nsBoxLayoutState& aBoxLayoutState) override; + NS_IMETHOD DoXULLayout(nsBoxLayoutState& aBoxLayoutState) override; virtual nsresult AttributeChanged(int32_t aNameSpaceID, nsIAtom* aAttribute, diff --git a/layout/xul/nsRootBoxFrame.cpp b/layout/xul/nsRootBoxFrame.cpp index 1c0f8cd4f8..c8b4d54e61 100644 --- a/layout/xul/nsRootBoxFrame.cpp +++ b/layout/xul/nsRootBoxFrame.cpp @@ -120,7 +120,7 @@ nsRootBoxFrame::nsRootBoxFrame(nsStyleContext* aContext): nsCOMPtr layout; NS_NewStackLayout(layout); - SetLayoutManager(layout); + SetXULLayoutManager(layout); } void diff --git a/layout/xul/nsScrollbarButtonFrame.cpp b/layout/xul/nsScrollbarButtonFrame.cpp index b610cbccc7..206d9717f6 100644 --- a/layout/xul/nsScrollbarButtonFrame.cpp +++ b/layout/xul/nsScrollbarButtonFrame.cpp @@ -22,8 +22,11 @@ #include "nsRepeatService.h" #include "mozilla/LookAndFeel.h" #include "mozilla/MouseEvents.h" +#include "mozilla/Telemetry.h" +#include "mozilla/layers/ScrollInputMethods.h" using namespace mozilla; +using mozilla::layers::ScrollInputMethod; // // NS_NewToolbarFrame @@ -167,6 +170,10 @@ nsScrollbarButtonFrame::HandleButtonPress(nsPresContext* aPresContext, if (!weakFrame.IsAlive()) { return false; } + + mozilla::Telemetry::Accumulate(mozilla::Telemetry::SCROLL_INPUT_METHODS, + (uint32_t) ScrollInputMethod::MainThreadScrollbarButtonClick); + if (!m) { sb->MoveToNewPosition(); if (!weakFrame.IsAlive()) { diff --git a/layout/xul/nsScrollbarFrame.cpp b/layout/xul/nsScrollbarFrame.cpp index 6b7be5afae..98e2d4d9fa 100644 --- a/layout/xul/nsScrollbarFrame.cpp +++ b/layout/xul/nsScrollbarFrame.cpp @@ -167,7 +167,7 @@ nsScrollbarFrame::GetScrollbarMediator() } nsresult -nsScrollbarFrame::GetMargin(nsMargin& aMargin) +nsScrollbarFrame::GetXULMargin(nsMargin& aMargin) { nsresult rv = NS_ERROR_FAILURE; aMargin.SizeTo(0,0,0,0); @@ -180,7 +180,7 @@ nsScrollbarFrame::GetMargin(nsMargin& aMargin) bool isOverridable; theme->GetMinimumWidgetSize(presContext, this, NS_THEME_SCROLLBAR, &size, &isOverridable); - if (IsHorizontal()) { + if (IsXULHorizontal()) { aMargin.top = -presContext->DevPixelsToAppUnits(size.height); } else { @@ -191,10 +191,10 @@ nsScrollbarFrame::GetMargin(nsMargin& aMargin) } if (NS_FAILED(rv)) { - rv = nsBox::GetMargin(aMargin); + rv = nsBox::GetXULMargin(aMargin); } - if (NS_SUCCEEDED(rv) && !IsHorizontal()) { + if (NS_SUCCEEDED(rv) && !IsXULHorizontal()) { nsIScrollbarMediator* scrollFrame = GetScrollbarMediator(); if (scrollFrame && !scrollFrame->IsScrollbarOnRight()) { Swap(aMargin.left, aMargin.right); diff --git a/layout/xul/nsScrollbarFrame.h b/layout/xul/nsScrollbarFrame.h index 098167cbb4..9522f94701 100644 --- a/layout/xul/nsScrollbarFrame.h +++ b/layout/xul/nsScrollbarFrame.h @@ -81,7 +81,7 @@ public: */ virtual bool DoesClipChildren() override { return true; } - virtual nsresult GetMargin(nsMargin& aMargin) override; + virtual nsresult GetXULMargin(nsMargin& aMargin) override; /** * The following three methods set the value of mIncrement when a diff --git a/layout/xul/nsSliderFrame.cpp b/layout/xul/nsSliderFrame.cpp index ba68f005f6..7d126b3eeb 100644 --- a/layout/xul/nsSliderFrame.cpp +++ b/layout/xul/nsSliderFrame.cpp @@ -22,11 +22,13 @@ #include "nsHTMLParts.h" #include "nsIPresShell.h" #include "nsCSSRendering.h" +#include "nsIDOMEvent.h" #include "nsIDOMMouseEvent.h" #include "nsScrollbarButtonFrame.h" #include "nsISliderListener.h" #include "nsIScrollableFrame.h" #include "nsIScrollbarMediator.h" +#include "nsISupportsImpl.h" #include "nsScrollbarFrame.h" #include "nsRepeatService.h" #include "nsBoxLayoutState.h" @@ -35,16 +37,22 @@ #include "nsContentUtils.h" #include "nsLayoutUtils.h" #include "nsDisplayList.h" +#include "mozilla/Assertions.h" // for MOZ_ASSERT #include "mozilla/Preferences.h" #include "mozilla/LookAndFeel.h" #include "mozilla/MouseEvents.h" +#include "mozilla/Telemetry.h" +#include "mozilla/layers/APZCCallbackHelper.h" #include "mozilla/layers/AsyncDragMetrics.h" #include "mozilla/layers/InputAPZContext.h" +#include "mozilla/layers/ScrollInputMethods.h" #include using namespace mozilla; +using mozilla::layers::APZCCallbackHelper; using mozilla::layers::AsyncDragMetrics; using mozilla::layers::InputAPZContext; +using mozilla::layers::ScrollInputMethod; bool nsSliderFrame::gMiddlePref = false; int32_t nsSliderFrame::gSnapMultiplier; @@ -77,7 +85,8 @@ nsSliderFrame::nsSliderFrame(nsStyleContext* aContext): mChange(0), mDragFinished(true), mUserChanged(false), - mScrollingWithAPZ(false) + mScrollingWithAPZ(false), + mSuppressionActive(false) { } @@ -317,16 +326,16 @@ nsSliderFrame::BuildDisplayListForChildren(nsDisplayListBuilder* aBuilder, const nsDisplayListSet& aLists) { // if we are too small to have a thumb don't paint it. - nsIFrame* thumb = nsBox::GetChildBox(this); + nsIFrame* thumb = nsBox::GetChildXULBox(this); if (thumb) { nsRect thumbRect(thumb->GetRect()); nsMargin m; - thumb->GetMargin(m); + thumb->GetXULMargin(m); thumbRect.Inflate(m); nsRect crect; - GetClientRect(crect); + GetXULClientRect(crect); if (crect.width < thumbRect.width || crect.height < thumbRect.height) return; @@ -341,7 +350,6 @@ nsSliderFrame::BuildDisplayListForChildren(nsDisplayListBuilder* aBuilder, uint32_t flags = 0; mozilla::layers::FrameMetrics::ViewID scrollTargetId = mozilla::layers::FrameMetrics::NULL_SCROLL_ID; - float scrollbarThumbRatio = 0.0f; aBuilder->GetScrollbarInfo(&scrollTargetId, &flags); bool thumbGetsLayer = (scrollTargetId != layers::FrameMetrics::NULL_SCROLL_ID); nsLayoutUtils::SetScrollbarThumbLayerization(thumb, thumbGetsLayer); @@ -363,7 +371,7 @@ nsSliderFrame::BuildDisplayListForChildren(nsDisplayListBuilder* aBuilder, // Wrap the list to make it its own layer. aLists.Content()->AppendNewToTop(new (aBuilder) nsDisplayOwnLayer(aBuilder, this, &masterList, flags, scrollTargetId, - scrollbarThumbRatio)); + GetThumbRatio())); return; } @@ -373,10 +381,10 @@ nsSliderFrame::BuildDisplayListForChildren(nsDisplayListBuilder* aBuilder, } NS_IMETHODIMP -nsSliderFrame::DoLayout(nsBoxLayoutState& aState) +nsSliderFrame::DoXULLayout(nsBoxLayoutState& aState) { // get the thumb should be our only child - nsIFrame* thumbBox = nsBox::GetChildBox(this); + nsIFrame* thumbBox = nsBox::GetChildXULBox(this); if (!thumbBox) { SyncLayout(aState); @@ -388,15 +396,15 @@ nsSliderFrame::DoLayout(nsBoxLayoutState& aState) #ifdef DEBUG_LAYOUT if (mState & NS_STATE_DEBUG_WAS_SET) { if (mState & NS_STATE_SET_TO_DEBUG) - SetDebug(aState, true); + SetXULDebug(aState, true); else - SetDebug(aState, false); + SetXULDebug(aState, false); } #endif // get the content area inside our borders nsRect clientRect; - GetClientRect(clientRect); + GetXULClientRect(clientRect); // get the scrollbar nsIFrame* scrollbarBox = GetScrollbar(); @@ -404,9 +412,9 @@ nsSliderFrame::DoLayout(nsBoxLayoutState& aState) scrollbar = GetContentOfBox(scrollbarBox); // get the thumb's pref size - nsSize thumbSize = thumbBox->GetPrefSize(aState); + nsSize thumbSize = thumbBox->GetXULPrefSize(aState); - if (IsHorizontal()) + if (IsXULHorizontal()) thumbSize.height = clientRect.height; else thumbSize.width = clientRect.width; @@ -419,10 +427,10 @@ nsSliderFrame::DoLayout(nsBoxLayoutState& aState) maxPos = std::max(minPos, maxPos); curPos = clamped(curPos, minPos, maxPos); - nscoord& availableLength = IsHorizontal() ? clientRect.width : clientRect.height; - nscoord& thumbLength = IsHorizontal() ? thumbSize.width : thumbSize.height; + nscoord& availableLength = IsXULHorizontal() ? clientRect.width : clientRect.height; + nscoord& thumbLength = IsXULHorizontal() ? thumbSize.width : thumbSize.height; - if ((pageIncrement + maxPos - minPos) > 0 && thumbBox->GetFlex() > 0) { + if ((pageIncrement + maxPos - minPos) > 0 && thumbBox->GetXULFlex() > 0) { float ratio = float(pageIncrement) / float(maxPos - minPos + pageIncrement); thumbLength = std::max(thumbLength, NSToCoordRound(availableLength * ratio)); } @@ -444,7 +452,7 @@ nsSliderFrame::DoLayout(nsBoxLayoutState& aState) // set the thumb's coord to be the current pos * the ratio. nsRect thumbRect(clientRect.x, clientRect.y, thumbSize.width, thumbSize.height); - int32_t& thumbPos = (IsHorizontal() ? thumbRect.x : thumbRect.y); + int32_t& thumbPos = (IsXULHorizontal() ? thumbRect.x : thumbRect.y); thumbPos += NSToCoordRound(pos * mRatio); nsRect oldThumbRect(thumbBox->GetRect()); @@ -454,7 +462,7 @@ nsSliderFrame::DoLayout(nsBoxLayoutState& aState) // Redraw only if thumb changed size. if (!oldThumbRect.IsEqualInterior(thumbRect)) - Redraw(aState); + XULRedraw(aState); return NS_OK; } @@ -482,7 +490,7 @@ nsSliderFrame::HandleEvent(nsPresContext* aPresContext, nsIFrame* scrollbarBox = GetScrollbar(); nsCOMPtr scrollbar; scrollbar = GetContentOfBox(scrollbarBox); - bool isHorizontal = IsHorizontal(); + bool isHorizontal = IsXULHorizontal(); if (isDraggingThumb()) { @@ -516,6 +524,9 @@ nsSliderFrame::HandleEvent(nsPresContext* aPresContext, return NS_OK; } + mozilla::Telemetry::Accumulate(mozilla::Telemetry::SCROLL_INPUT_METHODS, + (uint32_t) ScrollInputMethod::MainThreadScrollbarDrag); + // take our current position and subtract the start location pos -= mDragStart; bool isMouseOutsideThumb = false; @@ -582,6 +593,9 @@ nsSliderFrame::HandleEvent(nsPresContext* aPresContext, nsSize thumbSize = thumbFrame->GetSize(); nscoord thumbLength = isHorizontal ? thumbSize.width : thumbSize.height; + mozilla::Telemetry::Accumulate(mozilla::Telemetry::SCROLL_INPUT_METHODS, + (uint32_t) ScrollInputMethod::MainThreadScrollbarTrackClick); + // set it nsWeakFrame weakFrame(this); // should aMaySnap be true here? @@ -672,7 +686,7 @@ nsSliderFrame::GetScrollbar() if (scrollbar == nullptr) return this; - return scrollbar->IsBoxFrame() ? scrollbar : this; + return scrollbar->IsXULBoxFrame() ? scrollbar : this; } void @@ -730,7 +744,7 @@ nsSliderFrame::CurrentPositionChanged() nsRect thumbRect = thumbFrame->GetRect(); nsRect clientRect; - GetClientRect(clientRect); + GetXULClientRect(clientRect); // figure out the new rect nsRect newThumbRect(thumbRect); @@ -739,22 +753,21 @@ nsSliderFrame::CurrentPositionChanged() nsGkAtoms::reverse, eCaseMatters); nscoord pos = reverse ? (maxPos - curPos) : (curPos - minPos); - if (IsHorizontal()) + if (IsXULHorizontal()) newThumbRect.x = clientRect.x + NSToCoordRound(pos * mRatio); else newThumbRect.y = clientRect.y + NSToCoordRound(pos * mRatio); // avoid putting the scroll thumb at subpixel positions which cause needless invalidations nscoord appUnitsPerPixel = PresContext()->AppUnitsPerDevPixel(); - nsRect snappedThumbRect = ToAppUnits(newThumbRect.ToNearestPixels(appUnitsPerPixel), appUnitsPerPixel); - if (IsHorizontal()) { - newThumbRect.x = snappedThumbRect.x; - newThumbRect.width = snappedThumbRect.width; + nsPoint snappedThumbLocation = ToAppUnits( + newThumbRect.TopLeft().ToNearestPixels(appUnitsPerPixel), + appUnitsPerPixel); + if (IsXULHorizontal()) { + newThumbRect.x = snappedThumbLocation.x; } else { - newThumbRect.y = snappedThumbRect.y; - newThumbRect.height = snappedThumbRect.height; + newThumbRect.y = snappedThumbLocation.y; } - newThumbRect = newThumbRect.Intersect(clientRect); // set the rect thumbFrame->SetRect(newThumbRect); @@ -801,8 +814,8 @@ nsSliderFrame::SetCurrentThumbPosition(nsIContent* aScrollbar, nscoord aNewThumb bool aIsSmooth, bool aMaySnap) { nsRect crect; - GetClientRect(crect); - nscoord offset = IsHorizontal() ? crect.x : crect.y; + GetXULClientRect(crect); + nscoord offset = IsXULHorizontal() ? crect.x : crect.y; int32_t newPos = NSToIntRound((aNewThumbPos - offset) / mRatio); if (aMaySnap && mContent->AttrValueIs(kNameSpaceID_None, nsGkAtoms::snap, @@ -949,8 +962,8 @@ nsSliderFrame::StartAPZDrag() NSAppUnitsToIntPixels(mDragStart, float(AppUnitsPerCSSPixel())), sliderTrackCSS, - IsHorizontal() ? AsyncDragMetrics::HORIZONTAL : - AsyncDragMetrics::VERTICAL); + IsXULHorizontal() ? AsyncDragMetrics::HORIZONTAL : + AsyncDragMetrics::VERTICAL); if (!nsLayoutUtils::HasDisplayPort(scrollableContent)) { return false; @@ -982,7 +995,7 @@ nsSliderFrame::StartDrag(nsIDOMEvent* aEvent) if (!GetEventPoint(event, pt)) { return NS_OK; } - bool isHorizontal = IsHorizontal(); + bool isHorizontal = IsXULHorizontal(); nscoord pos = isHorizontal ? pt.x : pt.y; // If we should scroll-to-click, first place the middle of the slider thumb @@ -1204,7 +1217,7 @@ nsSliderFrame::IsEventOverThumb(WidgetGUIEvent* aEvent) return eventPoint.x >= thumbRect.x && eventPoint.x < thumbRect.XMost() && eventPoint.y >= thumbRect.y && eventPoint.y < thumbRect.YMost(); #else - bool isHorizontal = IsHorizontal(); + bool isHorizontal = IsXULHorizontal(); nscoord eventPos = isHorizontal ? eventPoint.x : eventPoint.y; nscoord thumbStart = isHorizontal ? thumbRect.x : thumbRect.y; nscoord thumbEnd = isHorizontal ? thumbRect.XMost() : thumbRect.YMost(); @@ -1241,8 +1254,8 @@ nsSliderFrame::HandlePress(nsPresContext* aPresContext, if (!GetEventPoint(aEvent, eventPoint)) { return NS_OK; } - if (IsHorizontal() ? eventPoint.x < thumbRect.x - : eventPoint.y < thumbRect.y) + if (IsXULHorizontal() ? eventPoint.x < thumbRect.x + : eventPoint.y < thumbRect.y) change = -1; mChange = change; @@ -1253,7 +1266,7 @@ nsSliderFrame::HandlePress(nsPresContext* aPresContext, // position. #ifdef MOZ_WIDGET_GTK nsRect clientRect; - GetClientRect(clientRect); + GetXULClientRect(clientRect); // Set the destination point to the very end of the scrollbar so that // scrolling doesn't stop halfway through. @@ -1305,26 +1318,26 @@ nsSliderFrame::DestroyFrom(nsIFrame* aDestructRoot) } nsSize -nsSliderFrame::GetPrefSize(nsBoxLayoutState& aState) +nsSliderFrame::GetXULPrefSize(nsBoxLayoutState& aState) { EnsureOrient(); - return nsBoxFrame::GetPrefSize(aState); + return nsBoxFrame::GetXULPrefSize(aState); } nsSize -nsSliderFrame::GetMinSize(nsBoxLayoutState& aState) +nsSliderFrame::GetXULMinSize(nsBoxLayoutState& aState) { EnsureOrient(); // our min size is just our borders and padding - return nsBox::GetMinSize(aState); + return nsBox::GetXULMinSize(aState); } nsSize -nsSliderFrame::GetMaxSize(nsBoxLayoutState& aState) +nsSliderFrame::GetXULMaxSize(nsBoxLayoutState& aState) { EnsureOrient(); - return nsBoxFrame::GetMaxSize(aState); + return nsBoxFrame::GetXULMaxSize(aState); } void @@ -1352,7 +1365,7 @@ nsSliderFrame::Notify(void) } nsRect thumbRect = thumbFrame->GetRect(); - bool isHorizontal = IsHorizontal(); + bool isHorizontal = IsXULHorizontal(); // See if the thumb has moved past our destination point. // if it has we want to stop. diff --git a/layout/xul/nsSliderFrame.h b/layout/xul/nsSliderFrame.h index 2b55a949cc..832065a210 100644 --- a/layout/xul/nsSliderFrame.h +++ b/layout/xul/nsSliderFrame.h @@ -55,10 +55,10 @@ public: } #endif - virtual nsSize GetPrefSize(nsBoxLayoutState& aBoxLayoutState) override; - virtual nsSize GetMinSize(nsBoxLayoutState& aBoxLayoutState) override; - virtual nsSize GetMaxSize(nsBoxLayoutState& aBoxLayoutState) override; - NS_IMETHOD DoLayout(nsBoxLayoutState& aBoxLayoutState) override; + virtual nsSize GetXULPrefSize(nsBoxLayoutState& aBoxLayoutState) override; + virtual nsSize GetXULMinSize(nsBoxLayoutState& aBoxLayoutState) override; + virtual nsSize GetXULMaxSize(nsBoxLayoutState& aBoxLayoutState) override; + NS_IMETHOD DoXULLayout(nsBoxLayoutState& aBoxLayoutState) override; // nsIFrame overrides virtual void DestroyFrom(nsIFrame* aDestructRoot) override; @@ -195,6 +195,10 @@ private: // causing the scroll position to jump. bool mScrollingWithAPZ; + // true if displayport suppression is active, for more performant + // scrollbar-dragging behaviour. + bool mSuppressionActive; + static bool gMiddlePref; static int32_t gSnapMultiplier; }; // class nsSliderFrame diff --git a/layout/xul/nsSplitterFrame.cpp b/layout/xul/nsSplitterFrame.cpp index 299ce8f129..f7bd8815ac 100644 --- a/layout/xul/nsSplitterFrame.cpp +++ b/layout/xul/nsSplitterFrame.cpp @@ -229,7 +229,7 @@ nsSplitterFrame::GetCursor(const nsPoint& aPoint, return nsBoxFrame::GetCursor(aPoint, aCursor); /* - if (IsHorizontal()) + if (IsXULHorizontal()) aCursor = NS_STYLE_CURSOR_N_RESIZE; else aCursor = NS_STYLE_CURSOR_W_RESIZE; @@ -279,8 +279,8 @@ nsSplitterFrame::Init(nsIContent* aContent, // on splitter content, then re-resolve style // XXXbz this is pretty messed up, since this can change whether we should // have a frame at all. This really needs a better solution. - if (aParent && aParent->IsBoxFrame()) { - if (!aParent->IsHorizontal()) { + if (aParent && aParent->IsXULBoxFrame()) { + if (!aParent->IsXULHorizontal()) { if (!nsContentUtils::HasNonEmptyAttr(aContent, kNameSpaceID_None, nsGkAtoms::orient)) { aContent->SetAttr(kNameSpaceID_None, nsGkAtoms::orient, @@ -301,24 +301,24 @@ nsSplitterFrame::Init(nsIContent* aContent, } NS_IMETHODIMP -nsSplitterFrame::DoLayout(nsBoxLayoutState& aState) +nsSplitterFrame::DoXULLayout(nsBoxLayoutState& aState) { if (GetStateBits() & NS_FRAME_FIRST_REFLOW) { - mInner->mParentBox = nsBox::GetParentBox(this); + mInner->mParentBox = nsBox::GetParentXULBox(this); mInner->UpdateState(); } - return nsBoxFrame::DoLayout(aState); + return nsBoxFrame::DoXULLayout(aState); } void nsSplitterFrame::GetInitialOrientation(bool& aIsHorizontal) { - nsIFrame* box = nsBox::GetParentBox(this); + nsIFrame* box = nsBox::GetParentXULBox(this); if (box) { - aIsHorizontal = !box->IsHorizontal(); + aIsHorizontal = !box->IsXULHorizontal(); } else nsBoxFrame::GetInitialOrientation(aIsHorizontal); @@ -444,7 +444,7 @@ nsSplitterFrameInner::MouseDrag(nsPresContext* aPresContext, //printf("Dragging\n"); - bool isHorizontal = !mOuter->IsHorizontal(); + bool isHorizontal = !mOuter->IsXULHorizontal(); // convert coord to pixels nsPoint pt = nsLayoutUtils::GetEventCoordinatesRelativeTo(aEvent, mParentBox); @@ -617,7 +617,7 @@ nsSplitterFrameInner::MouseDown(nsIDOMEvent* aMouseEvent) nsGkAtoms::_true, eCaseMatters)) return NS_OK; - mParentBox = nsBox::GetParentBox(mOuter); + mParentBox = nsBox::GetParentXULBox(mOuter); if (!mParentBox) return NS_OK; @@ -644,7 +644,7 @@ nsSplitterFrameInner::MouseDown(nsIDOMEvent* aMouseEvent) mDidDrag = false; EnsureOrient(); - bool isHorizontal = !mOuter->IsHorizontal(); + bool isHorizontal = !mOuter->IsXULHorizontal(); ResizeType resizeBefore = GetResizeBefore(); ResizeType resizeAfter = GetResizeAfter(); @@ -657,7 +657,7 @@ nsSplitterFrameInner::MouseDown(nsIDOMEvent* aMouseEvent) mChildInfosBeforeCount = 0; mChildInfosAfterCount = 0; - nsIFrame* childBox = nsBox::GetChildBox(mParentBox); + nsIFrame* childBox = nsBox::GetChildXULBox(mParentBox); while (nullptr != childBox) { @@ -668,19 +668,19 @@ nsSplitterFrameInner::MouseDown(nsIDOMEvent* aMouseEvent) // skip over any splitters if (atom != nsGkAtoms::splitter) { - nsSize prefSize = childBox->GetPrefSize(state); - nsSize minSize = childBox->GetMinSize(state); - nsSize maxSize = nsBox::BoundsCheckMinMax(minSize, childBox->GetMaxSize(state)); + nsSize prefSize = childBox->GetXULPrefSize(state); + nsSize minSize = childBox->GetXULMinSize(state); + nsSize maxSize = nsBox::BoundsCheckMinMax(minSize, childBox->GetXULMaxSize(state)); prefSize = nsBox::BoundsCheck(minSize, prefSize, maxSize); mOuter->AddMargin(childBox, minSize); mOuter->AddMargin(childBox, prefSize); mOuter->AddMargin(childBox, maxSize); - nscoord flex = childBox->GetFlex(); + nscoord flex = childBox->GetXULFlex(); nsMargin margin(0,0,0,0); - childBox->GetMargin(margin); + childBox->GetXULMargin(margin); nsRect r(childBox->GetRect()); r.Inflate(margin); @@ -712,11 +712,11 @@ nsSplitterFrameInner::MouseDown(nsIDOMEvent* aMouseEvent) } } - childBox = nsBox::GetNextBox(childBox); + childBox = nsBox::GetNextXULBox(childBox); count++; } - if (!mParentBox->IsNormalDirection()) { + if (!mParentBox->IsXULNormalDirection()) { // The before array is really the after array, and the order needs to be reversed. // First reverse both arrays. Reverse(mChildInfosBefore, mChildInfosBeforeCount); @@ -839,7 +839,7 @@ nsSplitterFrameInner::UpdateState() } if ((SupportsCollapseDirection(Before) || SupportsCollapseDirection(After)) && - mOuter->GetParent()->IsBoxFrame()) { + mOuter->GetParent()->IsXULBoxFrame()) { // Find the splitter's immediate sibling. nsIFrame* splitterSibling; if (newState == CollapsedBefore || mState == CollapsedBefore) { @@ -887,7 +887,7 @@ void nsSplitterFrameInner::AdjustChildren(nsPresContext* aPresContext) { EnsureOrient(); - bool isHorizontal = !mOuter->IsHorizontal(); + bool isHorizontal = !mOuter->IsXULHorizontal(); AdjustChildren(aPresContext, mChildInfosBefore.get(), mChildInfosBeforeCount, isHorizontal); @@ -897,13 +897,13 @@ nsSplitterFrameInner::AdjustChildren(nsPresContext* aPresContext) static nsIFrame* GetChildBoxForContent(nsIFrame* aParentBox, nsIContent* aContent) { - nsIFrame* childBox = nsBox::GetChildBox(aParentBox); + nsIFrame* childBox = nsBox::GetChildXULBox(aParentBox); while (nullptr != childBox) { if (childBox->GetContent() == aContent) { return childBox; } - childBox = nsBox::GetNextBox(childBox); + childBox = nsBox::GetNextXULBox(childBox); } return nullptr; } @@ -918,11 +918,11 @@ nsSplitterFrameInner::AdjustChildren(nsPresContext* aPresContext, nsSplitterInfo nscoord onePixel = nsPresContext::CSSPixelsToAppUnits(1); // first set all the widths. - nsIFrame* child = nsBox::GetChildBox(mOuter); + nsIFrame* child = nsBox::GetChildXULBox(mOuter); while(child) { SetPreferredSize(state, child, onePixel, aIsHorizontal, nullptr); - child = nsBox::GetNextBox(child); + child = nsBox::GetNextXULBox(child); } // now set our changed widths. @@ -954,7 +954,7 @@ nsSplitterFrameInner::SetPreferredSize(nsBoxLayoutState& aState, nsIFrame* aChil } nsMargin margin(0,0,0,0); - aChildBox->GetMargin(margin); + aChildBox->GetXULMargin(margin); nsCOMPtr attribute; @@ -1042,8 +1042,6 @@ nsSplitterFrameInner::ResizeChildTo(nscoord& aDiff, if (aBounded) { aDiff += spaceLeft; AddRemoveSpace(spaceLeft, aChildrenBeforeInfos,aChildrenBeforeCount,spaceLeft); - } else { - spaceLeft = 0; } } } diff --git a/layout/xul/nsSplitterFrame.h b/layout/xul/nsSplitterFrame.h index 22f708a76c..df8872255e 100644 --- a/layout/xul/nsSplitterFrame.h +++ b/layout/xul/nsSplitterFrame.h @@ -44,7 +44,7 @@ public: virtual nsresult GetCursor(const nsPoint& aPoint, nsIFrame::Cursor& aCursor) override; - NS_IMETHOD DoLayout(nsBoxLayoutState& aBoxLayoutState) override; + NS_IMETHOD DoXULLayout(nsBoxLayoutState& aBoxLayoutState) override; NS_IMETHOD HandlePress(nsPresContext* aPresContext, mozilla::WidgetGUIEvent* aEvent, diff --git a/layout/xul/nsSprocketLayout.cpp b/layout/xul/nsSprocketLayout.cpp index 08abb6db7e..968da11c98 100644 --- a/layout/xul/nsSprocketLayout.cpp +++ b/layout/xul/nsSprocketLayout.cpp @@ -54,7 +54,7 @@ nsSprocketLayout::nsSprocketLayout() } bool -nsSprocketLayout::IsHorizontal(nsIFrame* aBox) +nsSprocketLayout::IsXULHorizontal(nsIFrame* aBox) { return (aBox->GetStateBits() & NS_STATE_IS_HORIZONTAL) != 0; } @@ -114,8 +114,8 @@ HandleBoxPack(nsIFrame* aBox, const nsFrameState& aFrameState, nscoord& aX, nsco } // Get our pack/alignment information. - nsIFrame::Halignment halign = aBox->GetHAlign(); - nsIFrame::Valignment valign = aBox->GetVAlign(); + nsIFrame::Halignment halign = aBox->GetXULHAlign(); + nsIFrame::Valignment valign = aBox->GetXULVAlign(); // The following code handles box PACKING. Packing comes into play in the case where the computed size for // all of our children (now stored in our client rect) is smaller than the size available for @@ -168,16 +168,16 @@ HandleBoxPack(nsIFrame* aBox, const nsFrameState& aFrameState, nscoord& aX, nsco } NS_IMETHODIMP -nsSprocketLayout::Layout(nsIFrame* aBox, nsBoxLayoutState& aState) +nsSprocketLayout::XULLayout(nsIFrame* aBox, nsBoxLayoutState& aState) { // See if we are collapsed. If we are, then simply iterate over all our // children and give them a rect of 0 width and height. - if (aBox->IsCollapsed()) { - nsIFrame* child = nsBox::GetChildBox(aBox); + if (aBox->IsXULCollapsed()) { + nsIFrame* child = nsBox::GetChildXULBox(aBox); while(child) { nsBoxFrame::LayoutChildAt(aState, child, nsRect(0,0,0,0)); - child = nsBox::GetNextBox(child); + child = nsBox::GetNextXULBox(child); } return NS_OK; } @@ -190,7 +190,7 @@ nsSprocketLayout::Layout(nsIFrame* aBox, nsBoxLayoutState& aState) // -- make sure we remove our border and padding ---- nsRect clientRect; - aBox->GetClientRect(clientRect); + aBox->GetXULClientRect(clientRect); // |originalClientRect| represents the rect of the entire box (excluding borders // and padding). We store it here because we're going to use |clientRect| to hold @@ -219,7 +219,7 @@ nsSprocketLayout::Layout(nsIFrame* aBox, nsBoxLayoutState& aState) // the box. Continuing with the example begun in the comment above, size would // be 150 pixels. nscoord size = clientRect.width; - if (!IsHorizontal(aBox)) + if (!IsXULHorizontal(aBox)) size = clientRect.height; ComputeChildSizes(aBox, aState, size, boxSizes, computedBoxSizes); @@ -232,7 +232,7 @@ nsSprocketLayout::Layout(nsIFrame* aBox, nsBoxLayoutState& aState) // in the OPPOSITE orientation, e.g., for a horizontal box, |min| is the minimum // height we require to enclose our children, and |max| is the maximum height // required to enclose our children. - if (IsHorizontal(aBox)) { + if (IsXULHorizontal(aBox)) { clientRect.width = size; if (clientRect.height < min) clientRect.height = min; @@ -293,16 +293,13 @@ nsSprocketLayout::Layout(nsIFrame* aBox, nsBoxLayoutState& aState) origX = x; origY = y; - nscoord nextX = x; - nscoord nextY = y; - // Now we iterate over our box children and our box size lists in // parallel. For each child, we look at its sizes and figure out // where to place it. nsComputedBoxSize* childComputedBoxSize = computedBoxSizes; nsBoxSize* childBoxSize = boxSizes; - nsIFrame* child = nsBox::GetChildBox(aBox); + nsIFrame* child = nsBox::GetChildXULBox(aBox); int32_t count = 0; while (child || (childBoxSize && childBoxSize->bogus)) @@ -323,9 +320,9 @@ nsSprocketLayout::Layout(nsIFrame* aBox, nsBoxLayoutState& aState) // ALIGN is not stretch, however, then we also need to know the child's size along the // opposite axis. if (!(frameState & NS_STATE_AUTO_STRETCH)) { - nsSize prefSize = child->GetPrefSize(aState); - nsSize minSize = child->GetMinSize(aState); - nsSize maxSize = child->GetMaxSize(aState); + nsSize prefSize = child->GetXULPrefSize(aState); + nsSize minSize = child->GetXULMinSize(aState); + nsSize maxSize = child->GetXULMaxSize(aState); prefSize = nsBox::BoundsCheck(minSize, prefSize, maxSize); AddMargin(child, prefSize); @@ -354,9 +351,6 @@ nsSprocketLayout::Layout(nsIFrame* aBox, nsBoxLayoutState& aState) y -= (childBoxSize->right); } - nextX = x; - nextY = y; - // Now we build a child rect. nscoord rectX = x; nscoord rectY = y; @@ -383,6 +377,9 @@ nsSprocketLayout::Layout(nsIFrame* aBox, nsBoxLayoutState& aState) // Either |nextX| or |nextY| is updated by this function call, according // to our axis. + nscoord nextX = x; + nscoord nextY = y; + ComputeChildsNextPosition(aBox, x, y, nextX, nextY, childRect); // Now we further update our nextX/Y along our axis. @@ -425,7 +422,7 @@ nsSprocketLayout::Layout(nsIFrame* aBox, nsBoxLayoutState& aState) bool layout = true; // Deflate the rect of our child by its margin. - child->GetMargin(margin); + child->GetXULMargin(margin); childRect.Deflate(margin); if (childRect.width < 0) childRect.width = 0; @@ -433,7 +430,7 @@ nsSprocketLayout::Layout(nsIFrame* aBox, nsBoxLayoutState& aState) childRect.height = 0; // Now we're trying to figure out if we have to lay out this child, i.e., to call - // the child's Layout method. + // the child's XULLayout method. if (passes > 0) { layout = false; } else { @@ -458,15 +455,15 @@ nsSprocketLayout::Layout(nsIFrame* aBox, nsBoxLayoutState& aState) // If our old rect is different, then we know our size changed and we cache that fact // in the |sizeChanged| variable. - child->SetBounds(aState, childRect); + child->SetXULBounds(aState, childRect); bool sizeChanged = (childRect.width != oldRect.width || childRect.height != oldRect.height); if (sizeChanged) { // Our size is different. Sanity check against our maximum allowed size to ensure // we didn't exceed it. - nsSize minSize = child->GetMinSize(aState); - nsSize maxSize = child->GetMaxSize(aState); + nsSize minSize = child->GetXULMinSize(aState); + nsSize maxSize = child->GetXULMaxSize(aState); maxSize = nsBox::BoundsCheckMinMax(minSize, maxSize); // make sure the size is in our max size. @@ -477,14 +474,14 @@ nsSprocketLayout::Layout(nsIFrame* aBox, nsBoxLayoutState& aState) childRect.height = maxSize.height; // set it again - child->SetBounds(aState, childRect); + child->SetXULBounds(aState, childRect); } // If we already determined that layout was required or if our size has changed, then // we make sure to call layout on the child, since its children may need to be shifted // around as a result of the size change. if (layout || sizeChanged) - child->Layout(aState); + child->XULLayout(aState); // If the child was a block or inline (e.g., HTML) it may have changed its rect *during* layout. // We have to check for this. @@ -492,7 +489,7 @@ nsSprocketLayout::Layout(nsIFrame* aBox, nsBoxLayoutState& aState) if (!newChildRect.IsEqualInterior(childRect)) { #ifdef DEBUG_GROW - child->DumpBox(stdout); + child->XULDumpBox(stdout); printf(" GREW from (%d,%d) -> (%d,%d)\n", childRect.width, childRect.height, newChildRect.width, newChildRect.height); #endif newChildRect.Inflate(margin); @@ -553,7 +550,7 @@ nsSprocketLayout::Layout(nsIFrame* aBox, nsBoxLayoutState& aState) if (childRect.width >= margin.left + margin.right && childRect.height >= margin.top + margin.bottom) childRect.Deflate(margin); - child->SetBounds(aState, newChildRect); + child->SetXULBounds(aState, newChildRect); // If we are the first box that changed size, then we don't need to do a second pass if (count == 0) @@ -568,7 +565,7 @@ nsSprocketLayout::Layout(nsIFrame* aBox, nsBoxLayoutState& aState) childComputedBoxSize = childComputedBoxSize->next; childBoxSize = childBoxSize->next; - child = nsBox::GetNextBox(child); + child = nsBox::GetNextXULBox(child); count++; } @@ -598,7 +595,7 @@ nsSprocketLayout::Layout(nsIFrame* aBox, nsBoxLayoutState& aState) // See if one of our children forced us to get bigger nsRect tmpClientRect(originalClientRect); nsMargin bp(0,0,0,0); - aBox->GetBorderAndPadding(bp); + aBox->GetXULBorderAndPadding(bp); tmpClientRect.Inflate(bp); if (tmpClientRect.width > originalSize.width || tmpClientRect.height > originalSize.height) @@ -611,7 +608,7 @@ nsSprocketLayout::Layout(nsIFrame* aBox, nsBoxLayoutState& aState) if (tmpClientRect.height > originalSize.height) bounds.height = tmpClientRect.height; - aBox->SetBounds(aState, bounds); + aBox->SetXULBounds(aState, bounds); } } @@ -623,7 +620,7 @@ nsSprocketLayout::Layout(nsIFrame* aBox, nsBoxLayoutState& aState) // we really did have to change the positions because of packing (typically for 'center' // or 'end' pack values). if (x != origX || y != origY) { - nsIFrame* child = nsBox::GetChildBox(aBox); + nsIFrame* child = nsBox::GetChildXULBox(aBox); // reposition all our children while (child) @@ -631,8 +628,8 @@ nsSprocketLayout::Layout(nsIFrame* aBox, nsBoxLayoutState& aState) nsRect childRect(child->GetRect()); childRect.x += (x - origX); childRect.y += (y - origY); - child->SetBounds(aState, childRect); - child = nsBox::GetNextBox(child); + child->SetXULBounds(aState, childRect); + child = nsBox::GetNextXULBox(child); } } @@ -665,7 +662,7 @@ nsSprocketLayout::PopulateBoxSizes(nsIFrame* aBox, nsBoxLayoutState& aState, nsB bool isHorizontal; - if (IsHorizontal(aBox)) + if (IsXULHorizontal(aBox)) isHorizontal = true; else isHorizontal = false; @@ -680,7 +677,7 @@ nsSprocketLayout::PopulateBoxSizes(nsIFrame* aBox, nsBoxLayoutState& aState, nsB // so we can just optimize it out this way. // set flexes - nsIFrame* child = nsBox::GetChildBox(aBox); + nsIFrame* child = nsBox::GetChildXULBox(aBox); aFlexes = 0; nsBoxSize* currentBox = nullptr; @@ -705,10 +702,10 @@ nsSprocketLayout::PopulateBoxSizes(nsIFrame* aBox, nsBoxLayoutState& aState, nsB } - flex = child->GetFlex(); + flex = child->GetXULFlex(); currentBox->flex = flex; - currentBox->collapsed = child->IsCollapsed(); + currentBox->collapsed = child->IsXULCollapsed(); } else { flex = start->flex; start = start->next; @@ -717,12 +714,12 @@ nsSprocketLayout::PopulateBoxSizes(nsIFrame* aBox, nsBoxLayoutState& aState, nsB if (flex > 0) aFlexes++; - child = GetNextBox(child); + child = GetNextXULBox(child); } #endif // get pref, min, max - child = nsBox::GetChildBox(aBox); + child = nsBox::GetChildXULBox(aBox); currentBox = aBoxSizes; nsBoxSize* last = nullptr; @@ -740,19 +737,19 @@ nsSprocketLayout::PopulateBoxSizes(nsIFrame* aBox, nsBoxLayoutState& aState, nsB nsSize minSize(0,0); nsSize maxSize(NS_INTRINSICSIZE,NS_INTRINSICSIZE); nscoord ascent = 0; - bool collapsed = child->IsCollapsed(); + bool collapsed = child->IsXULCollapsed(); if (!collapsed) { // only one flexible child? Cool we will just make its preferred size // 0 then and not even have to ask for it. //if (flexes != 1) { - pref = child->GetPrefSize(aState); - minSize = child->GetMinSize(aState); - maxSize = nsBox::BoundsCheckMinMax(minSize, child->GetMaxSize(aState)); - ascent = child->GetBoxAscent(aState); + pref = child->GetXULPrefSize(aState); + minSize = child->GetXULMinSize(aState); + maxSize = nsBox::BoundsCheckMinMax(minSize, child->GetXULMaxSize(aState)); + ascent = child->GetXULBoxAscent(aState); nsMargin margin; - child->GetMargin(margin); + child->GetXULMargin(margin); ascent += margin.top; //} @@ -789,7 +786,7 @@ nsSprocketLayout::PopulateBoxSizes(nsIFrame* aBox, nsBoxLayoutState& aState, nsB prefWidth = pref.height; } - nscoord flex = child->GetFlex(); + nscoord flex = child->GetXULFlex(); // set them if you collapsed you are not flexible. if (collapsed) { @@ -841,7 +838,7 @@ nsSprocketLayout::PopulateBoxSizes(nsIFrame* aBox, nsBoxLayoutState& aState, nsB currentBox->collapsed = collapsed; aFlexes += currentBox->flex; - child = nsBox::GetNextBox(child); + child = nsBox::GetNextXULBox(child); last = currentBox; currentBox = currentBox->next; @@ -903,7 +900,7 @@ nsSprocketLayout::ComputeChildsNextPosition(nsIFrame* aBox, nsFrameState frameState = nsFrameState(0); GetFrameState(aBox, frameState); - if (IsHorizontal(aBox)) { + if (IsXULHorizontal(aBox)) { // horizontal box's children. if (frameState & NS_STATE_IS_DIRECTION_NORMAL) aNextX = aCurX + aCurrentChildSize.width; @@ -927,7 +924,7 @@ nsSprocketLayout::AlignChildren(nsIFrame* aBox, GetFrameState(aBox, frameState); bool isHorizontal = (frameState & NS_STATE_IS_HORIZONTAL) != 0; nsRect clientRect; - aBox->GetClientRect(clientRect); + aBox->GetXULClientRect(clientRect); NS_PRECONDITION(!(frameState & NS_STATE_AUTO_STRETCH), "Only AlignChildren() with non-stretch alignment"); @@ -939,20 +936,20 @@ nsSprocketLayout::AlignChildren(nsIFrame* aBox, bool isLTR; if (isHorizontal) { - valign = aBox->GetVAlign(); + valign = aBox->GetXULVAlign(); if (valign == nsBoxFrame::vAlign_BaseLine) { - maxAscent = aBox->GetBoxAscent(aState); + maxAscent = aBox->GetXULBoxAscent(aState); } } else { isLTR = GetFrameDirection(aBox) == NS_STYLE_DIRECTION_LTR; - halign = aBox->GetHAlign(); + halign = aBox->GetXULHAlign(); } - nsIFrame* child = nsBox::GetChildBox(aBox); + nsIFrame* child = nsBox::GetChildXULBox(aBox); while (child) { nsMargin margin; - child->GetMargin(margin); + child->GetXULMargin(margin); nsRect childRect = child->GetRect(); if (isHorizontal) { @@ -976,7 +973,7 @@ nsSprocketLayout::AlignChildren(nsIFrame* aBox, case nsBoxFrame::vAlign_BaseLine: // Alignments don't force the box to grow (only sizes do), // so keep the children within the box. - y = maxAscent - child->GetBoxAscent(aState); + y = maxAscent - child->GetXULBoxAscent(aState); y = std::max(startAlign, y); y = std::min(y, endAlign); break; @@ -1006,10 +1003,10 @@ nsSprocketLayout::AlignChildren(nsIFrame* aBox, } if (childRect.TopLeft() != child->GetPosition()) { - child->SetBounds(aState, childRect); + child->SetXULBounds(aState, childRect); } - child = nsBox::GetNextBox(child); + child = nsBox::GetNextXULBox(child); } } @@ -1030,7 +1027,7 @@ nsSprocketLayout::ChildResized(nsIFrame* aBox, { nsRect childCurrentRect(aChildLayoutRect); - bool isHorizontal = IsHorizontal(aBox); + bool isHorizontal = IsXULHorizontal(aBox); nscoord childLayoutWidth = GET_WIDTH(aChildLayoutRect,isHorizontal); nscoord& childActualWidth = GET_WIDTH(aChildActualRect,isHorizontal); nscoord& containingWidth = GET_WIDTH(aContainingRect,isHorizontal); @@ -1048,8 +1045,8 @@ nsSprocketLayout::ChildResized(nsIFrame* aBox, // ok if the height changed then we need to reflow everyone but us at the new height // so we will set the changed index to be us. And signal that we need a new pass. - nsSize min = aChild->GetMinSize(aState); - nsSize max = nsBox::BoundsCheckMinMax(min, aChild->GetMaxSize(aState)); + nsSize min = aChild->GetXULMinSize(aState); + nsSize max = nsBox::BoundsCheckMinMax(min, aChild->GetXULMaxSize(aState)); AddMargin(aChild, max); if (isHorizontal) @@ -1083,8 +1080,8 @@ nsSprocketLayout::ChildResized(nsIFrame* aBox, } if (childActualWidth > childLayoutWidth) { - nsSize min = aChild->GetMinSize(aState); - nsSize max = nsBox::BoundsCheckMinMax(min, aChild->GetMaxSize(aState)); + nsSize min = aChild->GetXULMinSize(aState); + nsSize max = nsBox::BoundsCheckMinMax(min, aChild->GetXULMaxSize(aState)); AddMargin(aChild, max); @@ -1133,13 +1130,13 @@ nsSprocketLayout::ChildResized(nsIFrame* aBox, // make sure we remove it before setting // the bounds. nsMargin margin(0,0,0,0); - aChild->GetMargin(margin); + aChild->GetXULMargin(margin); nsRect rect(aChildActualRect); if (rect.width >= margin.left + margin.right && rect.height >= margin.top + margin.bottom) rect.Deflate(margin); - aChild->SetBounds(aState, rect); - aChild->Layout(aState); + aChild->SetXULBounds(aState, rect); + aChild->XULLayout(aState); } } @@ -1307,17 +1304,17 @@ nsSprocketLayout::ComputeChildSizes(nsIFrame* aBox, nsSize -nsSprocketLayout::GetPrefSize(nsIFrame* aBox, nsBoxLayoutState& aState) +nsSprocketLayout::GetXULPrefSize(nsIFrame* aBox, nsBoxLayoutState& aState) { nsSize vpref (0, 0); - bool isHorizontal = IsHorizontal(aBox); + bool isHorizontal = IsXULHorizontal(aBox); nscoord biggestPref = 0; // run through all the children and get their min, max, and preferred sizes // return us the size of the box - nsIFrame* child = nsBox::GetChildBox(aBox); + nsIFrame* child = nsBox::GetChildXULBox(aBox); nsFrameState frameState = nsFrameState(0); GetFrameState(aBox, frameState); bool isEqual = !!(frameState & NS_STATE_EQUAL_SIZE); @@ -1326,9 +1323,9 @@ nsSprocketLayout::GetPrefSize(nsIFrame* aBox, nsBoxLayoutState& aState) while (child) { // ignore collapsed children - if (!child->IsCollapsed()) + if (!child->IsXULCollapsed()) { - nsSize pref = child->GetPrefSize(aState); + nsSize pref = child->GetXULPrefSize(aState); AddMargin(child, pref); if (isEqual) { @@ -1346,7 +1343,7 @@ nsSprocketLayout::GetPrefSize(nsIFrame* aBox, nsBoxLayoutState& aState) count++; } - child = nsBox::GetNextBox(child); + child = nsBox::GetNextXULBox(child); } if (isEqual) { @@ -1363,10 +1360,10 @@ nsSprocketLayout::GetPrefSize(nsIFrame* aBox, nsBoxLayoutState& aState) } nsSize -nsSprocketLayout::GetMinSize(nsIFrame* aBox, nsBoxLayoutState& aState) +nsSprocketLayout::GetXULMinSize(nsIFrame* aBox, nsBoxLayoutState& aState) { nsSize minSize (0, 0); - bool isHorizontal = IsHorizontal(aBox); + bool isHorizontal = IsXULHorizontal(aBox); nscoord biggestMin = 0; @@ -1374,7 +1371,7 @@ nsSprocketLayout::GetMinSize(nsIFrame* aBox, nsBoxLayoutState& aState) // run through all the children and get their min, max, and preferred sizes // return us the size of the box - nsIFrame* child = nsBox::GetChildBox(aBox); + nsIFrame* child = nsBox::GetChildXULBox(aBox); nsFrameState frameState = nsFrameState(0); GetFrameState(aBox, frameState); bool isEqual = !!(frameState & NS_STATE_EQUAL_SIZE); @@ -1383,15 +1380,15 @@ nsSprocketLayout::GetMinSize(nsIFrame* aBox, nsBoxLayoutState& aState) while (child) { // ignore collapsed children - if (!child->IsCollapsed()) + if (!child->IsXULCollapsed()) { - nsSize min = child->GetMinSize(aState); + nsSize min = child->GetXULMinSize(aState); nsSize pref(0,0); // if the child is not flexible then // its min size is its pref size. - if (child->GetFlex() == 0) { - pref = child->GetPrefSize(aState); + if (child->GetXULFlex() == 0) { + pref = child->GetXULPrefSize(aState); if (isHorizontal) min.width = pref.width; else @@ -1414,7 +1411,7 @@ nsSprocketLayout::GetMinSize(nsIFrame* aBox, nsBoxLayoutState& aState) count++; } - child = nsBox::GetNextBox(child); + child = nsBox::GetNextXULBox(child); } @@ -1432,10 +1429,10 @@ nsSprocketLayout::GetMinSize(nsIFrame* aBox, nsBoxLayoutState& aState) } nsSize -nsSprocketLayout::GetMaxSize(nsIFrame* aBox, nsBoxLayoutState& aState) +nsSprocketLayout::GetXULMaxSize(nsIFrame* aBox, nsBoxLayoutState& aState) { - bool isHorizontal = IsHorizontal(aBox); + bool isHorizontal = IsXULHorizontal(aBox); nscoord smallestMax = NS_INTRINSICSIZE; nsSize maxSize (NS_INTRINSICSIZE, NS_INTRINSICSIZE); @@ -1443,7 +1440,7 @@ nsSprocketLayout::GetMaxSize(nsIFrame* aBox, nsBoxLayoutState& aState) // run through all the children and get their min, max, and preferred sizes // return us the size of the box - nsIFrame* child = nsBox::GetChildBox(aBox); + nsIFrame* child = nsBox::GetChildXULBox(aBox); nsFrameState frameState = nsFrameState(0); GetFrameState(aBox, frameState); bool isEqual = !!(frameState & NS_STATE_EQUAL_SIZE); @@ -1452,11 +1449,11 @@ nsSprocketLayout::GetMaxSize(nsIFrame* aBox, nsBoxLayoutState& aState) while (child) { // ignore collapsed children - if (!child->IsCollapsed()) + if (!child->IsXULCollapsed()) { // if completely redefined don't even ask our child for its size. - nsSize min = child->GetMinSize(aState); - nsSize max = nsBox::BoundsCheckMinMax(min, child->GetMaxSize(aState)); + nsSize min = child->GetXULMinSize(aState); + nsSize max = nsBox::BoundsCheckMinMax(min, child->GetXULMaxSize(aState)); AddMargin(child, max); AddSmallestSize(maxSize, max, isHorizontal); @@ -1474,7 +1471,7 @@ nsSprocketLayout::GetMaxSize(nsIFrame* aBox, nsBoxLayoutState& aState) count++; } - child = nsBox::GetNextBox(child); + child = nsBox::GetNextXULBox(child); } if (isEqual) { @@ -1503,23 +1500,23 @@ nsSprocketLayout::GetAscent(nsIFrame* aBox, nsBoxLayoutState& aState) { nscoord vAscent = 0; - bool isHorizontal = IsHorizontal(aBox); + bool isHorizontal = IsXULHorizontal(aBox); // run through all the children and get their min, max, and preferred sizes // return us the size of the box - nsIFrame* child = nsBox::GetChildBox(aBox); + nsIFrame* child = nsBox::GetChildXULBox(aBox); while (child) { // ignore collapsed children - //if (!child->IsCollapsed()) + //if (!child->IsXULCollapsed()) //{ // if completely redefined don't even ask our child for its size. - nscoord ascent = child->GetBoxAscent(aState); + nscoord ascent = child->GetXULBoxAscent(aState); nsMargin margin; - child->GetMargin(margin); + child->GetXULMargin(margin); ascent += margin.top; if (isHorizontal) @@ -1532,11 +1529,11 @@ nsSprocketLayout::GetAscent(nsIFrame* aBox, nsBoxLayoutState& aState) } //} - child = nsBox::GetNextBox(child); + child = nsBox::GetNextXULBox(child); } nsMargin borderPadding; - aBox->GetBorderAndPadding(borderPadding); + aBox->GetXULBorderAndPadding(borderPadding); return vAscent + borderPadding.top; } diff --git a/layout/xul/nsSprocketLayout.h b/layout/xul/nsSprocketLayout.h index 4bec2e739e..0f15dce442 100644 --- a/layout/xul/nsSprocketLayout.h +++ b/layout/xul/nsSprocketLayout.h @@ -68,16 +68,16 @@ public: friend nsresult NS_NewSprocketLayout(nsCOMPtr& aNewLayout); static void Shutdown(); - NS_IMETHOD Layout(nsIFrame* aBox, nsBoxLayoutState& aState) override; + NS_IMETHOD XULLayout(nsIFrame* aBox, nsBoxLayoutState& aState) override; - virtual nsSize GetPrefSize(nsIFrame* aBox, nsBoxLayoutState& aBoxLayoutState) override; - virtual nsSize GetMinSize(nsIFrame* aBox, nsBoxLayoutState& aBoxLayoutState) override; - virtual nsSize GetMaxSize(nsIFrame* aBox, nsBoxLayoutState& aBoxLayoutState) override; + virtual nsSize GetXULPrefSize(nsIFrame* aBox, nsBoxLayoutState& aBoxLayoutState) override; + virtual nsSize GetXULMinSize(nsIFrame* aBox, nsBoxLayoutState& aBoxLayoutState) override; + virtual nsSize GetXULMaxSize(nsIFrame* aBox, nsBoxLayoutState& aBoxLayoutState) override; virtual nscoord GetAscent(nsIFrame* aBox, nsBoxLayoutState& aBoxLayoutState) override; nsSprocketLayout(); - static bool IsHorizontal(nsIFrame* aBox); + static bool IsXULHorizontal(nsIFrame* aBox); static void SetLargestSize(nsSize& aSize1, const nsSize& aSize2, bool aIsHorizontal); static void SetSmallestSize(nsSize& aSize1, const nsSize& aSize2, bool aIsHorizontal); diff --git a/layout/xul/nsStackFrame.cpp b/layout/xul/nsStackFrame.cpp index 78304a4bf8..437d558f91 100644 --- a/layout/xul/nsStackFrame.cpp +++ b/layout/xul/nsStackFrame.cpp @@ -34,7 +34,7 @@ nsStackFrame::nsStackFrame(nsStyleContext* aContext): { nsCOMPtr layout; NS_NewStackLayout(layout); - SetLayoutManager(layout); + SetXULLayoutManager(layout); } // REVIEW: The old code put everything in the background layer. To be more diff --git a/layout/xul/nsStackLayout.cpp b/layout/xul/nsStackLayout.cpp index a63ab3cb99..6072e0612b 100644 --- a/layout/xul/nsStackLayout.cpp +++ b/layout/xul/nsStackLayout.cpp @@ -59,14 +59,14 @@ nsStackLayout::nsStackLayout() */ nsSize -nsStackLayout::GetPrefSize(nsIFrame* aBox, nsBoxLayoutState& aState) +nsStackLayout::GetXULPrefSize(nsIFrame* aBox, nsBoxLayoutState& aState) { nsSize prefSize (0, 0); - nsIFrame* child = nsBox::GetChildBox(aBox); + nsIFrame* child = nsBox::GetChildXULBox(aBox); while (child) { if (child->StyleXUL()->mStretchStack) { - nsSize pref = child->GetPrefSize(aState); + nsSize pref = child->GetXULPrefSize(aState); AddMargin(child, pref); nsMargin offset; @@ -76,7 +76,7 @@ nsStackLayout::GetPrefSize(nsIFrame* aBox, nsBoxLayoutState& aState) AddLargestSize(prefSize, pref); } - child = nsBox::GetNextBox(child); + child = nsBox::GetNextXULBox(child); } AddBorderAndPadding(aBox, prefSize); @@ -85,14 +85,14 @@ nsStackLayout::GetPrefSize(nsIFrame* aBox, nsBoxLayoutState& aState) } nsSize -nsStackLayout::GetMinSize(nsIFrame* aBox, nsBoxLayoutState& aState) +nsStackLayout::GetXULMinSize(nsIFrame* aBox, nsBoxLayoutState& aState) { nsSize minSize (0, 0); - nsIFrame* child = nsBox::GetChildBox(aBox); + nsIFrame* child = nsBox::GetChildXULBox(aBox); while (child) { if (child->StyleXUL()->mStretchStack) { - nsSize min = child->GetMinSize(aState); + nsSize min = child->GetXULMinSize(aState); AddMargin(child, min); nsMargin offset; @@ -102,7 +102,7 @@ nsStackLayout::GetMinSize(nsIFrame* aBox, nsBoxLayoutState& aState) AddLargestSize(minSize, min); } - child = nsBox::GetNextBox(child); + child = nsBox::GetNextXULBox(child); } AddBorderAndPadding(aBox, minSize); @@ -111,15 +111,15 @@ nsStackLayout::GetMinSize(nsIFrame* aBox, nsBoxLayoutState& aState) } nsSize -nsStackLayout::GetMaxSize(nsIFrame* aBox, nsBoxLayoutState& aState) +nsStackLayout::GetXULMaxSize(nsIFrame* aBox, nsBoxLayoutState& aState) { nsSize maxSize (NS_INTRINSICSIZE, NS_INTRINSICSIZE); - nsIFrame* child = nsBox::GetChildBox(aBox); + nsIFrame* child = nsBox::GetChildXULBox(aBox); while (child) { if (child->StyleXUL()->mStretchStack) { - nsSize min = child->GetMinSize(aState); - nsSize max = child->GetMaxSize(aState); + nsSize min = child->GetXULMinSize(aState); + nsSize max = child->GetXULMaxSize(aState); max = nsBox::BoundsCheckMinMax(min, max); @@ -131,7 +131,7 @@ nsStackLayout::GetMaxSize(nsIFrame* aBox, nsBoxLayoutState& aState) AddSmallestSize(maxSize, max); } - child = nsBox::GetNextBox(child); + child = nsBox::GetNextXULBox(child); } AddBorderAndPadding(aBox, maxSize); @@ -145,16 +145,16 @@ nsStackLayout::GetAscent(nsIFrame* aBox, nsBoxLayoutState& aState) { nscoord vAscent = 0; - nsIFrame* child = nsBox::GetChildBox(aBox); + nsIFrame* child = nsBox::GetChildXULBox(aBox); while (child) { - nscoord ascent = child->GetBoxAscent(aState); + nscoord ascent = child->GetXULBoxAscent(aState); nsMargin margin; - child->GetMargin(margin); + child->GetXULMargin(margin); ascent += margin.top; if (ascent > vAscent) vAscent = ascent; - child = nsBox::GetNextBox(child); + child = nsBox::GetNextXULBox(child); } return vAscent; @@ -169,7 +169,7 @@ nsStackLayout::GetOffset(nsIFrame* aChild, nsMargin& aOffset) // As an optimization, we cache the fact that we are not positioned to avoid // wasting time fetching attributes. - if (aChild->IsBoxFrame() && + if (aChild->IsXULBoxFrame() && (aChild->GetStateBits() & NS_STATE_STACK_NOT_POSITIONED)) return 0; @@ -241,7 +241,7 @@ nsStackLayout::GetOffset(nsIFrame* aChild, nsMargin& aOffset) } } - if (!offsetSpecified && aChild->IsBoxFrame()) { + if (!offsetSpecified && aChild->IsXULBoxFrame()) { // If no offset was specified at all, then we cache this fact to avoid requerying // CSS or the content model. aChild->AddStateBits(NS_STATE_STACK_NOT_POSITIONED); @@ -252,21 +252,21 @@ nsStackLayout::GetOffset(nsIFrame* aChild, nsMargin& aOffset) NS_IMETHODIMP -nsStackLayout::Layout(nsIFrame* aBox, nsBoxLayoutState& aState) +nsStackLayout::XULLayout(nsIFrame* aBox, nsBoxLayoutState& aState) { nsRect clientRect; - aBox->GetClientRect(clientRect); + aBox->GetXULClientRect(clientRect); bool grow; do { - nsIFrame* child = nsBox::GetChildBox(aBox); + nsIFrame* child = nsBox::GetChildXULBox(aBox); grow = false; while (child) { nsMargin margin; - child->GetMargin(margin); + child->GetXULMargin(margin); nsRect childRect(clientRect); childRect.Deflate(margin); @@ -283,7 +283,7 @@ nsStackLayout::Layout(nsIFrame* aBox, nsBoxLayoutState& aState) if (sizeChanged || NS_SUBTREE_DIRTY(child)) { // add in the child's margin nsMargin margin; - child->GetMargin(margin); + child->GetXULMargin(margin); // obtain our offset from the top left border of the stack's content box. nsMargin offset; @@ -298,46 +298,48 @@ nsStackLayout::Layout(nsIFrame* aBox, nsBoxLayoutState& aState) // // Margins on the child are also included in the edge offsets if (offsetSpecified) { + nsSize min = child->GetXULMinSize(aState); + nsSize max = child->GetXULMaxSize(aState); if (offsetSpecified & SPECIFIED_LEFT) { childRect.x = clientRect.x + offset.left + margin.left; if (offsetSpecified & SPECIFIED_RIGHT) { - nsSize min = child->GetMinSize(aState); - nsSize max = child->GetMaxSize(aState); nscoord width = clientRect.width - offset.LeftRight() - margin.LeftRight(); childRect.width = clamped(width, min.width, max.width); } else { - childRect.width = child->GetPrefSize(aState).width; + nscoord width = child->GetXULPrefSize(aState).width; + childRect.width = clamped(width, min.width, max.width); } } else if (offsetSpecified & SPECIFIED_RIGHT) { - childRect.width = child->GetPrefSize(aState).width; + nscoord width = child->GetXULPrefSize(aState).width; + childRect.width = clamped(width, min.width, max.width); childRect.x = clientRect.XMost() - offset.right - margin.right - childRect.width; } if (offsetSpecified & SPECIFIED_TOP) { childRect.y = clientRect.y + offset.top + margin.top; if (offsetSpecified & SPECIFIED_BOTTOM) { - nsSize min = child->GetMinSize(aState); - nsSize max = child->GetMaxSize(aState); nscoord height = clientRect.height - offset.TopBottom() - margin.TopBottom(); childRect.height = clamped(height, min.height, max.height); } else { - childRect.height = child->GetPrefSize(aState).height; + nscoord height = child->GetXULPrefSize(aState).height; + childRect.height = clamped(height, min.height, max.height); } } else if (offsetSpecified & SPECIFIED_BOTTOM) { - childRect.height = child->GetPrefSize(aState).height; + nscoord height = child->GetXULPrefSize(aState).height; + childRect.height = clamped(height, min.height, max.height); childRect.y = clientRect.YMost() - offset.bottom - margin.bottom - childRect.height; } } // Now place the child. - child->SetBounds(aState, childRect); + child->SetXULBounds(aState, childRect); // Flow the child. - child->Layout(aState); + child->XULLayout(aState); // Get the child's new rect. childRect = child->GetRect(); @@ -357,7 +359,7 @@ nsStackLayout::Layout(nsIFrame* aBox, nsBoxLayoutState& aState) } } - child = nsBox::GetNextBox(child); + child = nsBox::GetNextXULBox(child); } } while (grow); @@ -365,7 +367,7 @@ nsStackLayout::Layout(nsIFrame* aBox, nsBoxLayoutState& aState) // get bigger nsRect bounds(aBox->GetRect()); nsMargin bp; - aBox->GetBorderAndPadding(bp); + aBox->GetXULBorderAndPadding(bp); clientRect.Inflate(bp); if (clientRect.width > bounds.width || clientRect.height > bounds.height) @@ -375,7 +377,7 @@ nsStackLayout::Layout(nsIFrame* aBox, nsBoxLayoutState& aState) if (clientRect.height > bounds.height) bounds.height = clientRect.height; - aBox->SetBounds(aState, bounds); + aBox->SetXULBounds(aState, bounds); } return NS_OK; diff --git a/layout/xul/nsStackLayout.h b/layout/xul/nsStackLayout.h index 4d7876291c..1eb1a6318d 100644 --- a/layout/xul/nsStackLayout.h +++ b/layout/xul/nsStackLayout.h @@ -32,11 +32,11 @@ public: nsStackLayout(); - NS_IMETHOD Layout(nsIFrame* aBox, nsBoxLayoutState& aState) override; + NS_IMETHOD XULLayout(nsIFrame* aBox, nsBoxLayoutState& aState) override; - virtual nsSize GetPrefSize(nsIFrame* aBox, nsBoxLayoutState& aBoxLayoutState) override; - virtual nsSize GetMinSize(nsIFrame* aBox, nsBoxLayoutState& aBoxLayoutState) override; - virtual nsSize GetMaxSize(nsIFrame* aBox, nsBoxLayoutState& aBoxLayoutState) override; + virtual nsSize GetXULPrefSize(nsIFrame* aBox, nsBoxLayoutState& aBoxLayoutState) override; + virtual nsSize GetXULMinSize(nsIFrame* aBox, nsBoxLayoutState& aBoxLayoutState) override; + virtual nsSize GetXULMaxSize(nsIFrame* aBox, nsBoxLayoutState& aBoxLayoutState) override; virtual nscoord GetAscent(nsIFrame* aBox, nsBoxLayoutState& aBoxLayoutState) override; // get the child offsets for aChild and set them in aMargin. Returns a diff --git a/layout/xul/nsTextBoxFrame.cpp b/layout/xul/nsTextBoxFrame.cpp index 25fbf89984..71177c1d10 100644 --- a/layout/xul/nsTextBoxFrame.cpp +++ b/layout/xul/nsTextBoxFrame.cpp @@ -86,7 +86,7 @@ nsTextBoxFrame::AttributeChanged(int32_t aNameSpaceID, NS_FRAME_IS_DIRTY); } else if (aRedraw) { nsBoxLayoutState state(PresContext()); - Redraw(state); + XULRedraw(state); } // If the accesskey changed, register for the new value @@ -228,7 +228,7 @@ nsTextBoxFrame::UpdateAttributes(nsIAtom* aAttribute, if (aAttribute == nullptr || aAttribute == nsGkAtoms::crop) { static nsIContent::AttrValuesArray strings[] = {&nsGkAtoms::left, &nsGkAtoms::start, &nsGkAtoms::center, - &nsGkAtoms::right, &nsGkAtoms::end, nullptr}; + &nsGkAtoms::right, &nsGkAtoms::end, &nsGkAtoms::none, nullptr}; CroppingStyle cropType; switch (mContent->FindAttrValueIn(kNameSpaceID_None, nsGkAtoms::crop, strings, eCaseMatters)) { @@ -243,9 +243,12 @@ nsTextBoxFrame::UpdateAttributes(nsIAtom* aAttribute, case 4: cropType = CropRight; break; - default: + case 5: cropType = CropNone; break; + default: + cropType = CropAuto; + break; } if (cropType != mCropType) { @@ -646,31 +649,37 @@ nsTextBoxFrame::CalculateTitleForWidth(nsRenderingContext& aRenderingContext, } const nsDependentString& kEllipsis = nsContentUtils::GetLocalizedEllipsis(); - // start with an ellipsis - mCroppedTitle.Assign(kEllipsis); + if (mCropType != CropNone) { + // start with an ellipsis + mCroppedTitle.Assign(kEllipsis); - // see if the width is even smaller than the ellipsis - // if so, clear the text (XXX set as many '.' as we can?). - fm->SetTextRunRTL(false); - titleWidth = nsLayoutUtils::AppUnitWidthOfString(kEllipsis, *fm, - drawTarget); + // see if the width is even smaller than the ellipsis + // if so, clear the text (XXX set as many '.' as we can?). + fm->SetTextRunRTL(false); + titleWidth = nsLayoutUtils::AppUnitWidthOfString(kEllipsis, *fm, + drawTarget); - if (titleWidth > aWidth) { - mCroppedTitle.SetLength(0); - return 0; + if (titleWidth > aWidth) { + mCroppedTitle.SetLength(0); + return 0; + } + + // if the ellipsis fits perfectly, no use in trying to insert + if (titleWidth == aWidth) + return titleWidth; + + aWidth -= titleWidth; + } else { + mCroppedTitle.Truncate(0); + titleWidth = 0; } - // if the ellipsis fits perfectly, no use in trying to insert - if (titleWidth == aWidth) - return titleWidth; - - aWidth -= titleWidth; - // XXX: This whole block should probably take surrogates into account // XXX and clusters! // ok crop things switch (mCropType) { + case CropAuto: case CropNone: case CropRight: { @@ -940,7 +949,7 @@ nsTextBoxFrame::DidSetStyleContext(nsStyleContext* aOldStyleContext) } NS_IMETHODIMP -nsTextBoxFrame::DoLayout(nsBoxLayoutState& aBoxLayoutState) +nsTextBoxFrame::DoXULLayout(nsBoxLayoutState& aBoxLayoutState) { if (mNeedsReflowCallback) { nsIReflowCallback* cb = new nsAsyncAccesskeyUpdate(this); @@ -950,7 +959,7 @@ nsTextBoxFrame::DoLayout(nsBoxLayoutState& aBoxLayoutState) mNeedsReflowCallback = false; } - nsresult rv = nsLeafBoxFrame::DoLayout(aBoxLayoutState); + nsresult rv = nsLeafBoxFrame::DoXULLayout(aBoxLayoutState); CalcDrawRect(*aBoxLayoutState.GetRenderingContext()); @@ -1053,7 +1062,7 @@ nsTextBoxFrame::CalcDrawRect(nsRenderingContext &aRenderingContext) LogicalRect textRect(wm, LogicalPoint(wm, 0, 0), GetLogicalSize(wm)); nsMargin borderPadding; - GetBorderAndPadding(borderPadding); + GetXULBorderAndPadding(borderPadding); textRect.Deflate(wm, LogicalMargin(wm, borderPadding)); // determine (cropped) title and underline position @@ -1099,7 +1108,7 @@ nsTextBoxFrame::CalcDrawRect(nsRenderingContext &aRenderingContext) * Ok return our dimensions */ nsSize -nsTextBoxFrame::GetPrefSize(nsBoxLayoutState& aBoxLayoutState) +nsTextBoxFrame::GetXULPrefSize(nsBoxLayoutState& aBoxLayoutState) { CalcTextSize(aBoxLayoutState); @@ -1108,7 +1117,7 @@ nsTextBoxFrame::GetPrefSize(nsBoxLayoutState& aBoxLayoutState) AddBorderAndPadding(size); bool widthSet, heightSet; - nsIFrame::AddCSSPrefSize(this, size, widthSet, heightSet); + nsIFrame::AddXULPrefSize(this, size, widthSet, heightSet); return size; } @@ -1117,7 +1126,7 @@ nsTextBoxFrame::GetPrefSize(nsBoxLayoutState& aBoxLayoutState) * Ok return our dimensions */ nsSize -nsTextBoxFrame::GetMinSize(nsBoxLayoutState& aBoxLayoutState) +nsTextBoxFrame::GetXULMinSize(nsBoxLayoutState& aBoxLayoutState) { CalcTextSize(aBoxLayoutState); @@ -1125,7 +1134,7 @@ nsTextBoxFrame::GetMinSize(nsBoxLayoutState& aBoxLayoutState) DISPLAY_MIN_SIZE(this, size); // if there is cropping our min width becomes our border and padding - if (mCropType != CropNone) { + if (mCropType != CropNone && mCropType != CropAuto) { if (GetWritingMode().IsVertical()) { size.height = 0; } else { @@ -1135,20 +1144,20 @@ nsTextBoxFrame::GetMinSize(nsBoxLayoutState& aBoxLayoutState) AddBorderAndPadding(size); bool widthSet, heightSet; - nsIFrame::AddCSSMinSize(aBoxLayoutState, this, size, widthSet, heightSet); + nsIFrame::AddXULMinSize(aBoxLayoutState, this, size, widthSet, heightSet); return size; } nscoord -nsTextBoxFrame::GetBoxAscent(nsBoxLayoutState& aBoxLayoutState) +nsTextBoxFrame::GetXULBoxAscent(nsBoxLayoutState& aBoxLayoutState) { CalcTextSize(aBoxLayoutState); nscoord ascent = mAscent; nsMargin m(0,0,0,0); - GetBorderAndPadding(m); + GetXULBorderAndPadding(m); WritingMode wm = GetWritingMode(); ascent += LogicalMargin(wm, m).BStart(wm); diff --git a/layout/xul/nsTextBoxFrame.h b/layout/xul/nsTextBoxFrame.h index 8999ba7fc0..e404bb0cda 100644 --- a/layout/xul/nsTextBoxFrame.h +++ b/layout/xul/nsTextBoxFrame.h @@ -20,13 +20,13 @@ public: NS_DECL_QUERYFRAME NS_DECL_FRAMEARENA_HELPERS - virtual nsSize GetPrefSize(nsBoxLayoutState& aBoxLayoutState) override; - virtual nsSize GetMinSize(nsBoxLayoutState& aBoxLayoutState) override; - virtual nscoord GetBoxAscent(nsBoxLayoutState& aBoxLayoutState) override; - NS_IMETHOD DoLayout(nsBoxLayoutState& aBoxLayoutState) override; + virtual nsSize GetXULPrefSize(nsBoxLayoutState& aBoxLayoutState) override; + virtual nsSize GetXULMinSize(nsBoxLayoutState& aBoxLayoutState) override; + virtual nscoord GetXULBoxAscent(nsBoxLayoutState& aBoxLayoutState) override; + NS_IMETHOD DoXULLayout(nsBoxLayoutState& aBoxLayoutState) override; virtual void MarkIntrinsicISizesDirty() override; - enum CroppingStyle { CropNone, CropLeft, CropRight, CropCenter }; + enum CroppingStyle { CropNone, CropLeft, CropRight, CropCenter, CropAuto }; friend nsIFrame* NS_NewTextBoxFrame(nsIPresShell* aPresShell, nsStyleContext* aContext); diff --git a/layout/xul/nsXULPopupManager.cpp b/layout/xul/nsXULPopupManager.cpp index 42f66ec213..446acdb196 100644 --- a/layout/xul/nsXULPopupManager.cpp +++ b/layout/xul/nsXULPopupManager.cpp @@ -1237,6 +1237,41 @@ nsXULPopupManager::HidePopupsInList(const nsTArray &aFrames) SetCaptureState(nullptr); } +void +nsXULPopupManager::EnableRollup(nsIContent* aPopup, bool aShouldRollup) +{ +#ifndef MOZ_GTK + if (aShouldRollup) { + nsMenuChainItem* item = mNoHidePanels; + while (item) { + if (item->Content() == aPopup) { + item->Detach(&mNoHidePanels); + nsIContent* oldmenu = nullptr; + if (mPopups) + oldmenu = mPopups->Content(); + item->SetParent(mPopups); + mPopups = item; + SetCaptureState(oldmenu); + return; + } + item = item->GetParent(); + } + } else { + nsMenuChainItem* item = mPopups; + while (item) { + if (item->Content() == aPopup) { + item->Detach(&mPopups); + item->SetParent(mNoHidePanels); + mNoHidePanels = item; + SetCaptureState(nullptr); + return; + } + item = item->GetParent(); + } + } +#endif +} + bool nsXULPopupManager::IsChildOfDocShell(nsIDocument* aDoc, nsIDocShellTreeItem* aExpected) { diff --git a/layout/xul/nsXULPopupManager.h b/layout/xul/nsXULPopupManager.h index c9968544ea..94c17fcb53 100644 --- a/layout/xul/nsXULPopupManager.h +++ b/layout/xul/nsXULPopupManager.h @@ -484,6 +484,14 @@ public: */ void HidePopupsInDocShell(nsIDocShellTreeItem* aDocShellToHide); + /** + * Enable or disable the dynamic noautohide state of a panel. + * + * aPanel - the panel whose state is to change + * aShouldRollup - whether the panel is no longer noautohide + */ + void EnableRollup(nsIContent* aPopup, bool aShouldRollup); + /** * Execute a menu command from the triggering event aEvent. * diff --git a/layout/xul/test/browser.ini b/layout/xul/test/browser.ini index 3998b63748..708007d197 100644 --- a/layout/xul/test/browser.ini +++ b/layout/xul/test/browser.ini @@ -3,3 +3,5 @@ [browser_bug685470.js] [browser_bug703210.js] [browser_bug706743.js] +[browser_bug1163304.js] +skip-if = os != 'linux' && os != 'win' // Due to testing menubar behavior with keyboard diff --git a/layout/xul/test/browser_bug1163304.js b/layout/xul/test/browser_bug1163304.js new file mode 100644 index 0000000000..b8e9409ddf --- /dev/null +++ b/layout/xul/test/browser_bug1163304.js @@ -0,0 +1,35 @@ +function test() { + waitForExplicitFinish(); + + let searchBar = BrowserSearch.searchBar; + searchBar.focus(); + + let DOMWindowUtils = EventUtils._getDOMWindowUtils(); + is(DOMWindowUtils.IMEStatus, DOMWindowUtils.IME_STATUS_ENABLED, + "IME should be available when searchbar has focus"); + + let searchPopup = document.getElementById("PopupSearchAutoComplete"); + searchPopup.addEventListener("popupshown", function (aEvent) { + searchPopup.removeEventListener("popupshown", arguments.callee); + setTimeout(function () { + is(DOMWindowUtils.IMEStatus, DOMWindowUtils.IME_STATUS_ENABLED, + "IME should be available even when the popup of searchbar is open"); + searchPopup.addEventListener("popuphidden", function (aEvent) { + searchPopup.removeEventListener("popuphidden", arguments.callee); + setTimeout(function () { + is(DOMWindowUtils.IMEStatus, DOMWindowUtils.IME_STATUS_DISABLED, + "IME should not be available when menubar is active"); + // Inactivate the menubar (and restore the focus to the searchbar + EventUtils.synthesizeKey("VK_ESCAPE", {}); + is(DOMWindowUtils.IMEStatus, DOMWindowUtils.IME_STATUS_ENABLED, + "IME should be available after focus is back to the searchbar"); + finish(); + }, 0); + }); + // Activate the menubar, then, the popup should be closed + EventUtils.synthesizeKey("VK_ALT", {}); + }, 0); + }); + // Open popup of the searchbar + EventUtils.synthesizeKey("VK_F4", {}); +} diff --git a/layout/xul/tree/nsTreeBodyFrame.cpp b/layout/xul/tree/nsTreeBodyFrame.cpp index 166d973a5c..8dd5cf4afe 100644 --- a/layout/xul/tree/nsTreeBodyFrame.cpp +++ b/layout/xul/tree/nsTreeBodyFrame.cpp @@ -183,7 +183,7 @@ nsTreeBodyFrame::Init(nsIContent* aContent, } nsSize -nsTreeBodyFrame::GetMinSize(nsBoxLayoutState& aBoxLayoutState) +nsTreeBodyFrame::GetXULMinSize(nsBoxLayoutState& aBoxLayoutState) { EnsureView(); @@ -226,7 +226,7 @@ nsTreeBodyFrame::GetMinSize(nsBoxLayoutState& aBoxLayoutState) AddBorderAndPadding(min); bool widthSet, heightSet; - nsIFrame::AddCSSMinSize(aBoxLayoutState, this, min, widthSet, heightSet); + nsIFrame::AddXULMinSize(aBoxLayoutState, this, min, widthSet, heightSet); return min; } @@ -404,14 +404,14 @@ nsTreeBodyFrame::ManageReflowCallback(const nsRect& aRect, nscoord aHorzWidth) } void -nsTreeBodyFrame::SetBounds(nsBoxLayoutState& aBoxLayoutState, const nsRect& aRect, - bool aRemoveOverflowArea) +nsTreeBodyFrame::SetXULBounds(nsBoxLayoutState& aBoxLayoutState, const nsRect& aRect, + bool aRemoveOverflowArea) { nscoord horzWidth = CalcHorzWidth(GetScrollParts()); ManageReflowCallback(aRect, horzWidth); mHorzWidth = horzWidth; - nsLeafBoxFrame::SetBounds(aBoxLayoutState, aRect, aRemoveOverflowArea); + nsLeafBoxFrame::SetXULBounds(aBoxLayoutState, aRect, aRemoveOverflowArea); } @@ -804,7 +804,7 @@ FindScrollParts(nsIFrame* aCurrFrame, nsTreeBodyFrame::ScrollParts* aResult) nsScrollbarFrame *sf = do_QueryFrame(aCurrFrame); if (sf) { - if (!aCurrFrame->IsHorizontal()) { + if (!aCurrFrame->IsXULHorizontal()) { if (!aResult->mVScrollbar) { aResult->mVScrollbar = sf; } @@ -2194,6 +2194,7 @@ nsTreeBodyFrame::GetImage(int32_t aRowIndex, nsTreeColumn* aCol, bool aUseContex if (nsContentUtils::CanLoadImage(srcURI, mContent, doc, mContent->NodePrincipal())) { nsresult rv = nsContentUtils::LoadImage(srcURI, + mContent, doc, mContent->NodePrincipal(), doc->GetDocumentURI(), @@ -4339,7 +4340,7 @@ nsTreeBodyFrame::RepeatButtonScroll(nsScrollbarFrame* aScrollbar) } else if (increment > 0) { direction = 1; } - bool isHorizontal = aScrollbar->IsHorizontal(); + bool isHorizontal = aScrollbar->IsXULHorizontal(); nsWeakFrame weakFrame(this); if (isHorizontal) { diff --git a/layout/xul/tree/nsTreeBodyFrame.h b/layout/xul/tree/nsTreeBodyFrame.h index 4f8172c044..0e344731a1 100644 --- a/layout/xul/tree/nsTreeBodyFrame.h +++ b/layout/xul/tree/nsTreeBodyFrame.h @@ -124,9 +124,9 @@ public: void ManageReflowCallback(const nsRect& aRect, nscoord aHorzWidth); - virtual nsSize GetMinSize(nsBoxLayoutState& aBoxLayoutState) override; - virtual void SetBounds(nsBoxLayoutState& aBoxLayoutState, const nsRect& aRect, - bool aRemoveOverflowArea = false) override; + virtual nsSize GetXULMinSize(nsBoxLayoutState& aBoxLayoutState) override; + virtual void SetXULBounds(nsBoxLayoutState& aBoxLayoutState, const nsRect& aRect, + bool aRemoveOverflowArea = false) override; // nsIReflowCallback virtual bool ReflowFinished() override; diff --git a/layout/xul/tree/nsTreeColFrame.cpp b/layout/xul/tree/nsTreeColFrame.cpp index 86a660b799..649c0b0b4c 100644 --- a/layout/xul/tree/nsTreeColFrame.cpp +++ b/layout/xul/tree/nsTreeColFrame.cpp @@ -143,12 +143,13 @@ nsTreeColFrame::AttributeChanged(int32_t aNameSpaceID, } void -nsTreeColFrame::SetBounds(nsBoxLayoutState& aBoxLayoutState, - const nsRect& aRect, - bool aRemoveOverflowArea) { +nsTreeColFrame::SetXULBounds(nsBoxLayoutState& aBoxLayoutState, + const nsRect& aRect, + bool aRemoveOverflowArea) +{ nscoord oldWidth = mRect.width; - nsBoxFrame::SetBounds(aBoxLayoutState, aRect, aRemoveOverflowArea); + nsBoxFrame::SetXULBounds(aBoxLayoutState, aRect, aRemoveOverflowArea); if (mRect.width != oldWidth) { nsITreeBoxObject* treeBoxObject = GetTreeBoxObject(); if (treeBoxObject) { diff --git a/layout/xul/tree/nsTreeColFrame.h b/layout/xul/tree/nsTreeColFrame.h index a1c7c20160..8fc3219d50 100644 --- a/layout/xul/tree/nsTreeColFrame.h +++ b/layout/xul/tree/nsTreeColFrame.h @@ -33,8 +33,8 @@ public: nsIAtom* aAttribute, int32_t aModType) override; - virtual void SetBounds(nsBoxLayoutState& aBoxLayoutState, const nsRect& aRect, - bool aRemoveOverflowArea = false) override; + virtual void SetXULBounds(nsBoxLayoutState& aBoxLayoutState, const nsRect& aRect, + bool aRemoveOverflowArea = false) override; friend nsIFrame* NS_NewTreeColFrame(nsIPresShell* aPresShell, nsStyleContext* aContext); diff --git a/toolkit/content/tests/chrome/test_bug624329.xul b/toolkit/content/tests/chrome/test_bug624329.xul index 46ee919e9a..893b386870 100644 --- a/toolkit/content/tests/chrome/test_bug624329.xul +++ b/toolkit/content/tests/chrome/test_bug624329.xul @@ -99,12 +99,13 @@ function openContextMenu() { function checkPosition() { var menubox = menu.boxObject; - var winbox = win.document.documentElement.boxObject + var winbox = win.document.documentElement.boxObject; + var platformIsMac = navigator.userAgent.indexOf("Mac") > -1; var x = menubox.screenX - winbox.screenX; var y = menubox.screenY - winbox.screenY; - if (navigator.userAgent.indexOf("Mac") > -1) + if (platformIsMac) { // This check is alterered slightly for OSX which adds padding to the top // and bottom of its context menus. The menu position calculation must @@ -126,8 +127,17 @@ function openContextMenu() { ok(x < mouseX, "menu left " + x + " should be left of click point " + mouseX); var right = x + menubox.width; - ok(right > mouseX, - "menu right " + right + " should be right of click point " + mouseX); + + if (platformIsMac) { + // Rather than be constrained by the right hand screen edge, OSX menus flip + // horizontally and appear to the left of the mouse pointer + ok(right < mouseX, + "menu right " + right + " should be left of click point " + mouseX); + } + else { + ok(right > mouseX, + "menu right " + right + " should be right of click point " + mouseX); + } clearTimeout(timeoutID); finish(); diff --git a/toolkit/content/tests/chrome/window_largemenu.xul b/toolkit/content/tests/chrome/window_largemenu.xul index c54b8226c6..72e1c077d8 100644 --- a/toolkit/content/tests/chrome/window_largemenu.xul +++ b/toolkit/content/tests/chrome/window_largemenu.xul @@ -19,14 +19,14 @@ var gOverflowed = false, gUnderflowed = false; var gContextMenuTests = false; var gScreenY = -1; var gTestIndex = 0; -var gTests = ["open normal", "open flipped position", "open with scrolling", +var gTests = ["open normal", "open when bottom would overlap", "open with scrolling", "open after scrolling", "open small again", "menu movement", "panel movement", "context menu enough space below", "context menu more space above", "context menu too big either side", - "context menu larger than screen"]; - + "context menu larger than screen", + "context menu flips horizontally on osx"]; function getScreenXY(element) { var screenX, screenY; @@ -64,7 +64,7 @@ function nextTest() gOverflowed = false, gUnderflowed = false; var y = screen.height; - if (gTestIndex == 1) // open flipped position test: + if (gTestIndex == 1) // open with bottom overlap test: y -= 100; else y /= 2; @@ -72,14 +72,16 @@ function nextTest() var popup = document.getElementById("popup"); if (gTestIndex == 2) { // add some more menuitems so that scrolling will be necessary - for (var t = 1; t <= 30; t++) { + var moreItemCount = Math.round(screen.height / popup.firstChild.getBoundingClientRect().height); + for (var t = 1; t <= moreItemCount; t++) { var menu = document.createElement("menuitem"); menu.setAttribute("label", "More" + t); popup.appendChild(menu); } } else if (gTestIndex == 4) { - for (var t = 1; t <= 30; t++) + // remove the items added in test 2 above + while (popup.childNodes.length > 15) popup.removeChild(popup.lastChild); } @@ -116,12 +118,22 @@ function popupShown() } else if (gTestIndex == 1) { // the popup was supposed to open 100 pixels from the bottom, but that - // would put it off screen so it should be flipped to have its bottom - // edge 100 pixels from the bottom - ok(Math.round(rect.top) + gScreenY >= screen.top, gTests[gTestIndex] + " top"); - is(Math.round(rect.bottom) + gScreenY, screen.height - 100, - gTests[gTestIndex] + " bottom"); - ok(!gOverflowed && !gUnderflowed, gTests[gTestIndex] + " overflow") + // would put it off screen so ... + if (platformIsMac()) { + // On OSX the popup is constrained so it remains within the + // bounds of the screen + ok(Math.round(rect.top) + gScreenY >= screen.top, gTests[gTestIndex] + " top"); + is(Math.round(rect.bottom) + gScreenY, screen.availTop + screen.availHeight, gTests[gTestIndex] + " bottom"); + ok(!gOverflowed && !gUnderflowed, gTests[gTestIndex] + " overflow"); + } + else { + // On other platforms the menu should be flipped to have its bottom + // edge 100 pixels from the bottom + ok(Math.round(rect.top) + gScreenY >= screen.top, gTests[gTestIndex] + " top"); + is(Math.round(rect.bottom) + gScreenY, screen.height - 100, + gTests[gTestIndex] + " bottom"); + ok(!gOverflowed && !gUnderflowed, gTests[gTestIndex] + " overflow"); + } } else if (gTestIndex == 2) { // the popup is too large so ensure that it is on screen @@ -142,7 +154,7 @@ function popupShown() gTests[gTestIndex] + " top"); ok(Math.round(rect.bottom) + gScreenY < screen.height, gTests[gTestIndex] + " bottom"); - ok(!gOverflowed && gUnderflowed, gTests[gTestIndex] + " overflow") + ok(!gOverflowed && gUnderflowed, gTests[gTestIndex] + " overflow"); } is(sbo.positionY, expectedScrollPos, "menu scroll position"); @@ -218,13 +230,21 @@ function contextMenuPopupShown() // Click to open popup in popupHidden() occurs at (4,4) in label's coordinate space var clickX = clickY = 4; - is(rect.left, labelrect.left + clickX + (platformIsMac() ? 1 : 2), gTests[gTestIndex] + " left"); + var testPopupAppearedRightOfCursor = true; switch (gTests[gTestIndex]) { case "context menu enough space below": is(rect.top, labelrect.top + clickY + (platformIsMac() ? -6 : 2), gTests[gTestIndex] + " top"); break; case "context menu more space above": - is(rect.top, labelrect.top + clickY - rect.height - (platformIsMac() ? 0 : 2), gTests[gTestIndex] + " top"); + if (platformIsMac()) { + let screenY; + [, screenY] = getScreenXY(popup); + // Macs constrain their popup menus vertically rather than flip them. + is(screenY, screen.availTop + screen.availHeight - rect.height, gTests[gTestIndex] + " top"); + } else { + is(rect.top, labelrect.top + clickY - rect.height - 2, gTests[gTestIndex] + " top"); + } + break; case "context menu too big either side": [, gScreenY] = getScreenXY(document.documentElement); @@ -238,6 +258,16 @@ function contextMenuPopupShown() case "context menu larger than screen": ok(rect.top == -(gScreenY - screen.availTop) || rect.top == -(gScreenY - screen.top), gTests[gTestIndex] + " top"); break; + case "context menu flips horizontally on osx": + testPopupAppearedRightOfCursor = false; + if (platformIsMac()) { + is(Math.round(rect.right), labelrect.left + clickX - 1, gTests[gTestIndex] + " right"); + } + break; + } + + if (testPopupAppearedRightOfCursor) { + is(rect.left, labelrect.left + clickX + (platformIsMac() ? 1 : 2), gTests[gTestIndex] + " left"); } hidePopup(); @@ -256,6 +286,11 @@ function contextMenuPopupHidden() else if (gTests[gTestIndex] == "context menu larger than screen") { nextContextMenuTest(screen.availHeight + 80); } + else if (gTests[gTestIndex] == "context menu flips horizontally on osx") { + var popup = document.getElementById("popup"); + var popupWidth = popup.getBoundingClientRect().width; + moveWindowTo(screen.availLeft + screen.availWidth - popupWidth, 100, nextContextMenuTest, -1); + } } function nextContextMenuTest(desiredHeight) @@ -341,9 +376,14 @@ function testPopupMovement() popup.moveTo(-1, -1); [screenX, screenY] = getScreenXY(popup); - [buttonScreenX, buttonScreenY] = getScreenXY(button); - is(screenX, buttonScreenX, gTests[gTestIndex] + " original x"); - is(screenY, buttonScreenY + button.getBoundingClientRect().height, gTests[gTestIndex] + " original y"); + + expectedx = (overlapOSChrome ? screen.left : screen.availLeft); + expectedy = (overlapOSChrome ? screen.top : screen.availTop); + + is(screenX, expectedx, gTests[gTestIndex] + " move after set left and top x to -1"); + is(screenY, expectedy, gTests[gTestIndex] + " move after set left and top y to -1"); + is(popup.left, "", gTests[gTestIndex] + " left is not set after moving to -1"); + is(popup.top, "", gTests[gTestIndex] + " top is not set after moving to -1"); popup.hidePopup(); } diff --git a/toolkit/content/tests/chrome/window_tooltip.xul b/toolkit/content/tests/chrome/window_tooltip.xul index 569804f805..087c91c3e7 100644 --- a/toolkit/content/tests/chrome/window_tooltip.xul +++ b/toolkit/content/tests/chrome/window_tooltip.xul @@ -229,10 +229,72 @@ var popupTests = [ is(gOriginalWidth, rect.right - rect.left, testname + " tooltip is original width"); is(gOriginalHeight, rect.bottom - rect.top, testname + " tooltip is original height"); } +}, +{ + testname: "hover tooltip at bottom edge of screen", + events: [ "popupshowing thetooltip", "popupshown thetooltip" ], + autohide: "thetooltip", + condition: function() { + // Only checking OSX here because on other platforms popups and tooltips behave the same way + // when there's not enough space to show them below (by flipping vertically) + // However, on OSX most popups are not flipped but tooltips are. + return navigator.platform.indexOf("Mac") > -1; + }, + test: function() { + var buttonRect = document.getElementById("withtext").getBoundingClientRect(); + var windowY = screen.height - + (window.mozInnerScreenY - window.screenY ) - buttonRect.bottom; + + moveWindowTo(window.screenX, windowY, function() { + gButton = document.getElementById("withtooltip"); + disableNonTestMouse(true); + synthesizeMouse(gButton, 2, 2, { type: "mouseover" }); + synthesizeMouse(gButton, 6, 6, { type: "mousemove" }); + synthesizeMouse(gButton, 4, 4, { type: "mousemove" }); + disableNonTestMouse(false); + }); + }, + result: function(testname) { + var buttonrect = document.getElementById("withtooltip").getBoundingClientRect(); + var rect = document.getElementById("thetooltip").getBoundingClientRect(); + var popupstyle = window.getComputedStyle(document.getElementById("thetooltip"), ""); + + is(Math.round(rect.y + rect.height), + Math.round(buttonrect.top + 4 - parseFloat(popupstyle.marginTop)), + testname + " position of tooltip above button"); + } } ]; +var waitSteps = 0; +function moveWindowTo(x, y, callback, arg) +{ + if (!waitSteps) { + oldx = window.screenX; + oldy = window.screenY; + window.moveTo(x, y); + + waitSteps++; + setTimeout(moveWindowTo, 100, x, y, callback, arg); + return; + } + + if (window.screenX == oldx && window.screenY == oldy) { + if (waitSteps++ > 10) { + ok(false, "Window never moved properly to " + x + "," + y); + window.opener.wrappedJSObject.SimpleTest.finish(); + window.close(); + } + + setTimeout(moveWindowTo, 100, x, y, callback, arg); + } + else { + waitSteps = 0; + callback(arg); + } +} + window.opener.wrappedJSObject.SimpleTest.waitForFocus(runTest, window); ]]> diff --git a/widget/MouseEvents.h b/widget/MouseEvents.h index 67978d3075..d3b5804324 100644 --- a/widget/MouseEvents.h +++ b/widget/MouseEvents.h @@ -115,6 +115,7 @@ public: int16_t button; enum buttonsFlag { + eNoButtonFlag = 0x00, eLeftButtonFlag = 0x01, eRightButtonFlag = 0x02, eMiddleButtonFlag = 0x04, diff --git a/widget/cocoa/OSXNotificationCenter.mm b/widget/cocoa/OSXNotificationCenter.mm index 07ea00a728..6acc42f25c 100644 --- a/widget/cocoa/OSXNotificationCenter.mm +++ b/widget/cocoa/OSXNotificationCenter.mm @@ -407,7 +407,7 @@ OSXNotificationCenter::ShowAlertWithIconData(nsIAlertNotification* aAlert, rv = il->LoadImage(imageUri, nullptr, nullptr, mozilla::net::RP_Default, principal, nullptr, - this, nullptr, + this, nullptr, nullptr, inPrivateBrowsing ? nsIRequest::LOAD_ANONYMOUS : nsIRequest::LOAD_NORMAL, nullptr, nsIContentPolicy::TYPE_INTERNAL_IMAGE, diff --git a/widget/cocoa/nsMenuItemIconX.mm b/widget/cocoa/nsMenuItemIconX.mm index 79e0955166..d742b81772 100644 --- a/widget/cocoa/nsMenuItemIconX.mm +++ b/widget/cocoa/nsMenuItemIconX.mm @@ -310,7 +310,7 @@ nsMenuItemIconX::LoadIcon(nsIURI* aIconURI) nsresult rv = loader->LoadImage(aIconURI, nullptr, nullptr, mozilla::net::RP_Default, nullptr, loadGroup, this, - nullptr, nsIRequest::LOAD_NORMAL, nullptr, + nullptr, nullptr, nsIRequest::LOAD_NORMAL, nullptr, nsIContentPolicy::TYPE_INTERNAL_IMAGE, EmptyString(), getter_AddRefs(mIconRequest)); if (NS_FAILED(rv)) return rv; diff --git a/xpcom/build/XPCOMInit.cpp b/xpcom/build/XPCOMInit.cpp index ea4a45b052..5370a90d7b 100644 --- a/xpcom/build/XPCOMInit.cpp +++ b/xpcom/build/XPCOMInit.cpp @@ -688,8 +688,9 @@ NS_InitXPCOM2(nsIServiceManager** aResult, #endif // Initialize the JS engine. - if (!JS_Init()) { - NS_RUNTIMEABORT("JS_Init failed"); + const char* jsInitFailureReason = JS_InitWithFailureDiagnostic(); + if (jsInitFailureReason) { + NS_RUNTIMEABORT(jsInitFailureReason); } rv = nsComponentManagerImpl::gComponentManager->Init();