2007-03-22 10:30:00 -07:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
|
|
/* vim: set ts=2 sw=2 et tw=78: */
|
2012-05-21 04:12:37 -07:00
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2012-07-31 10:28:22 -07:00
|
|
|
#include "base/basictypes.h"
|
2011-10-10 22:50:08 -07:00
|
|
|
#include "mozilla/Util.h"
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
#include "nsLayoutUtils.h"
|
|
|
|
#include "nsIFormControlFrame.h"
|
|
|
|
#include "nsPresContext.h"
|
|
|
|
#include "nsIContent.h"
|
2010-04-21 06:13:08 -07:00
|
|
|
#include "nsIDOMHTMLDocument.h"
|
2010-04-25 12:52:23 -07:00
|
|
|
#include "nsIDOMHTMLElement.h"
|
2007-03-22 10:30:00 -07:00
|
|
|
#include "nsFrameList.h"
|
|
|
|
#include "nsGkAtoms.h"
|
|
|
|
#include "nsIAtom.h"
|
|
|
|
#include "nsCSSPseudoElements.h"
|
2008-02-27 01:26:15 -08:00
|
|
|
#include "nsCSSAnonBoxes.h"
|
2011-06-22 11:11:48 -07:00
|
|
|
#include "nsCSSColorUtils.h"
|
2007-03-22 10:30:00 -07:00
|
|
|
#include "nsIView.h"
|
|
|
|
#include "nsPlaceholderFrame.h"
|
|
|
|
#include "nsIScrollableFrame.h"
|
|
|
|
#include "nsCSSFrameConstructor.h"
|
|
|
|
#include "nsIDOMEvent.h"
|
|
|
|
#include "nsGUIEvent.h"
|
|
|
|
#include "nsDisplayList.h"
|
|
|
|
#include "nsRegion.h"
|
|
|
|
#include "nsFrameManager.h"
|
|
|
|
#include "nsBlockFrame.h"
|
|
|
|
#include "nsBidiPresUtils.h"
|
|
|
|
#include "imgIContainer.h"
|
|
|
|
#include "gfxRect.h"
|
2007-05-14 22:15:45 -07:00
|
|
|
#include "gfxContext.h"
|
2007-07-26 02:47:43 -07:00
|
|
|
#include "gfxFont.h"
|
2012-03-20 05:15:55 -07:00
|
|
|
#include "nsRenderingContext.h"
|
2007-03-22 10:30:00 -07:00
|
|
|
#include "nsIInterfaceRequestorUtils.h"
|
2007-05-10 08:46:42 -07:00
|
|
|
#include "nsCSSRendering.h"
|
2007-07-26 02:47:43 -07:00
|
|
|
#include "nsContentUtils.h"
|
2008-08-12 17:44:14 -07:00
|
|
|
#include "nsThemeConstants.h"
|
2008-07-26 09:14:49 -07:00
|
|
|
#include "nsPIDOMWindow.h"
|
|
|
|
#include "nsIBaseWindow.h"
|
|
|
|
#include "nsIDocShell.h"
|
|
|
|
#include "nsIDocShellTreeItem.h"
|
|
|
|
#include "nsIWidget.h"
|
2008-09-13 02:42:11 -07:00
|
|
|
#include "gfxMatrix.h"
|
2011-08-02 20:04:21 -07:00
|
|
|
#include "gfxPoint3D.h"
|
2008-09-13 02:42:11 -07:00
|
|
|
#include "gfxTypes.h"
|
2008-09-30 20:01:53 -07:00
|
|
|
#include "gfxUserFontSet.h"
|
2009-02-03 06:42:18 -08:00
|
|
|
#include "nsTArray.h"
|
2010-05-17 21:04:22 -07:00
|
|
|
#include "nsHTMLCanvasElement.h"
|
2009-06-25 13:30:56 -07:00
|
|
|
#include "nsICanvasRenderingContextInternal.h"
|
|
|
|
#include "gfxPlatform.h"
|
2009-09-24 14:01:48 -07:00
|
|
|
#include "nsClientRect.h"
|
2009-07-02 02:57:35 -07:00
|
|
|
#ifdef MOZ_MEDIA
|
2009-06-25 13:30:56 -07:00
|
|
|
#include "nsHTMLVideoElement.h"
|
2009-07-02 02:57:35 -07:00
|
|
|
#endif
|
2012-05-31 11:16:49 -07:00
|
|
|
#include "nsHTMLImageElement.h"
|
2009-06-25 13:30:56 -07:00
|
|
|
#include "imgIRequest.h"
|
|
|
|
#include "nsIImageLoadingContent.h"
|
2009-09-01 09:40:49 -07:00
|
|
|
#include "nsCOMPtr.h"
|
2010-01-11 13:45:18 -08:00
|
|
|
#include "nsListControlFrame.h"
|
2010-03-01 15:41:49 -08:00
|
|
|
#include "ImageLayers.h"
|
2011-04-08 10:15:37 -07:00
|
|
|
#include "mozilla/arm.h"
|
2010-05-05 11:18:05 -07:00
|
|
|
#include "mozilla/dom/Element.h"
|
2010-07-15 14:07:52 -07:00
|
|
|
#include "nsCanvasFrame.h"
|
2010-08-13 06:30:37 -07:00
|
|
|
#include "gfxDrawable.h"
|
|
|
|
#include "gfxUtils.h"
|
2011-01-13 09:45:14 -08:00
|
|
|
#include "nsDataHashtable.h"
|
2011-06-15 23:31:36 -07:00
|
|
|
#include "nsTextFrame.h"
|
|
|
|
#include "nsFontFaceList.h"
|
2012-04-16 15:32:12 -07:00
|
|
|
#include "nsFontInflationData.h"
|
2008-02-27 01:26:15 -08:00
|
|
|
#include "nsSVGUtils.h"
|
2008-09-10 17:24:16 -07:00
|
|
|
#include "nsSVGIntegrationUtils.h"
|
2007-03-22 10:30:00 -07:00
|
|
|
#include "nsSVGForeignObjectFrame.h"
|
|
|
|
#include "nsSVGOuterSVGFrame.h"
|
2012-08-08 04:37:13 -07:00
|
|
|
#include "nsStyleStructInlines.h"
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2011-08-02 20:04:19 -07:00
|
|
|
#include "mozilla/Preferences.h"
|
|
|
|
|
2010-03-18 22:02:53 -07:00
|
|
|
#ifdef MOZ_XUL
|
|
|
|
#include "nsXULPopupManager.h"
|
|
|
|
#endif
|
|
|
|
|
2012-01-17 12:33:04 -08:00
|
|
|
#include "sampler.h"
|
2012-07-31 10:28:22 -07:00
|
|
|
#include "nsAnimationManager.h"
|
|
|
|
#include "nsTransitionManager.h"
|
2012-01-17 12:33:04 -08:00
|
|
|
|
2011-10-10 22:50:08 -07:00
|
|
|
using namespace mozilla;
|
2010-03-01 15:41:49 -08:00
|
|
|
using namespace mozilla::layers;
|
2010-04-30 06:12:05 -07:00
|
|
|
using namespace mozilla::dom;
|
2012-01-24 17:21:29 -08:00
|
|
|
using namespace mozilla::layout;
|
2010-03-01 15:41:49 -08:00
|
|
|
|
2010-10-13 03:52:45 -07:00
|
|
|
#ifdef DEBUG
|
|
|
|
// TODO: remove, see bug 598468.
|
|
|
|
bool nsLayoutUtils::gPreventAssertInCompareTreePosition = false;
|
|
|
|
#endif // DEBUG
|
|
|
|
|
2010-10-11 13:07:59 -07:00
|
|
|
typedef gfxPattern::GraphicsFilter GraphicsFilter;
|
2011-01-13 09:45:14 -08:00
|
|
|
typedef FrameMetrics::ViewID ViewID;
|
2010-10-11 13:07:59 -07:00
|
|
|
|
2012-08-22 08:56:38 -07:00
|
|
|
/* static */ uint32_t nsLayoutUtils::sFontSizeInflationEmPerLine;
|
|
|
|
/* static */ uint32_t nsLayoutUtils::sFontSizeInflationMinTwips;
|
|
|
|
/* static */ uint32_t nsLayoutUtils::sFontSizeInflationLineThreshold;
|
|
|
|
/* static */ int32_t nsLayoutUtils::sFontSizeInflationMappingIntercept;
|
2011-11-23 18:48:23 -08:00
|
|
|
|
2011-01-13 09:45:14 -08:00
|
|
|
static ViewID sScrollIdCounter = FrameMetrics::START_SCROLL_ID;
|
|
|
|
|
|
|
|
typedef nsDataHashtable<nsUint64HashKey, nsIContent*> ContentMap;
|
|
|
|
static ContentMap* sContentMap = NULL;
|
|
|
|
static ContentMap& GetContentMap() {
|
|
|
|
if (!sContentMap) {
|
|
|
|
sContentMap = new ContentMap();
|
2011-02-27 07:46:00 -08:00
|
|
|
sContentMap->Init();
|
2011-01-13 09:45:14 -08:00
|
|
|
}
|
|
|
|
return *sContentMap;
|
|
|
|
}
|
|
|
|
|
2012-07-31 10:28:22 -07:00
|
|
|
bool
|
|
|
|
nsLayoutUtils::HasAnimationsForCompositor(nsIContent* aContent,
|
|
|
|
nsCSSProperty aProperty)
|
|
|
|
{
|
|
|
|
if (!aContent->MayHaveAnimations())
|
|
|
|
return false;
|
|
|
|
ElementAnimations* animations =
|
|
|
|
static_cast<ElementAnimations*>(aContent->GetProperty(nsGkAtoms::animationsProperty));
|
|
|
|
if (animations) {
|
|
|
|
bool propertyMatches = animations->HasAnimationOfProperty(aProperty);
|
|
|
|
if (propertyMatches && animations->CanPerformOnCompositorThread()) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
ElementTransitions* transitions =
|
|
|
|
static_cast<ElementTransitions*>(aContent->GetProperty(nsGkAtoms::transitionsProperty));
|
|
|
|
if (transitions) {
|
|
|
|
bool propertyMatches = transitions->HasTransitionOfProperty(aProperty);
|
|
|
|
if (propertyMatches && transitions->CanPerformOnCompositorThread()) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
2011-08-02 20:04:19 -07:00
|
|
|
|
2011-09-28 23:19:26 -07:00
|
|
|
bool
|
2011-08-02 20:04:19 -07:00
|
|
|
nsLayoutUtils::Are3DTransformsEnabled()
|
|
|
|
{
|
2011-09-28 23:19:26 -07:00
|
|
|
static bool s3DTransformsEnabled;
|
|
|
|
static bool s3DTransformPrefCached = false;
|
2011-08-02 20:04:19 -07:00
|
|
|
|
|
|
|
if (!s3DTransformPrefCached) {
|
2011-10-17 07:59:28 -07:00
|
|
|
s3DTransformPrefCached = true;
|
2012-07-31 10:28:22 -07:00
|
|
|
mozilla::Preferences::AddBoolVarCache(&s3DTransformsEnabled,
|
2011-08-02 20:04:19 -07:00
|
|
|
"layout.3d-transforms.enabled");
|
|
|
|
}
|
|
|
|
|
|
|
|
return s3DTransformsEnabled;
|
|
|
|
}
|
|
|
|
|
2012-07-31 10:28:22 -07:00
|
|
|
bool
|
|
|
|
nsLayoutUtils::AreOpacityAnimationsEnabled()
|
|
|
|
{
|
|
|
|
static bool sAreOpacityAnimationsEnabled;
|
|
|
|
static bool sOpacityPrefCached = false;
|
|
|
|
|
|
|
|
if (!sOpacityPrefCached) {
|
|
|
|
sOpacityPrefCached = true;
|
|
|
|
Preferences::AddBoolVarCache(&sAreOpacityAnimationsEnabled,
|
|
|
|
"layers.offmainthreadcomposition.animate-opacity");
|
|
|
|
}
|
|
|
|
|
2012-08-25 18:27:28 -07:00
|
|
|
return sAreOpacityAnimationsEnabled &&
|
|
|
|
gfxPlatform::OffMainThreadCompositingEnabled();
|
2012-07-31 10:28:22 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
nsLayoutUtils::AreTransformAnimationsEnabled()
|
|
|
|
{
|
|
|
|
static bool sAreTransformAnimationsEnabled;
|
|
|
|
static bool sTransformPrefCached = false;
|
|
|
|
|
|
|
|
if (!sTransformPrefCached) {
|
|
|
|
sTransformPrefCached = true;
|
|
|
|
Preferences::AddBoolVarCache(&sAreTransformAnimationsEnabled,
|
|
|
|
"layers.offmainthreadcomposition.animate-transform");
|
|
|
|
}
|
|
|
|
|
2012-08-25 18:27:28 -07:00
|
|
|
return sAreTransformAnimationsEnabled &&
|
|
|
|
gfxPlatform::OffMainThreadCompositingEnabled();
|
2012-07-31 10:28:22 -07:00
|
|
|
}
|
|
|
|
|
2012-08-06 13:33:23 -07:00
|
|
|
bool
|
|
|
|
nsLayoutUtils::IsAnimationLoggingEnabled()
|
|
|
|
{
|
|
|
|
static bool sShouldLog;
|
|
|
|
static bool sShouldLogPrefCached;
|
|
|
|
|
|
|
|
if (!sShouldLogPrefCached) {
|
|
|
|
sShouldLogPrefCached = true;
|
|
|
|
Preferences::AddBoolVarCache(&sShouldLog,
|
|
|
|
"layers.offmainthreadcomposition.log-animations");
|
|
|
|
}
|
|
|
|
|
|
|
|
return sShouldLog;
|
|
|
|
}
|
|
|
|
|
2012-04-24 07:28:46 -07:00
|
|
|
bool
|
|
|
|
nsLayoutUtils::UseBackgroundNearestFiltering()
|
|
|
|
{
|
|
|
|
static bool sUseBackgroundNearestFilteringEnabled;
|
|
|
|
static bool sUseBackgroundNearestFilteringPrefInitialised = false;
|
|
|
|
|
|
|
|
if (!sUseBackgroundNearestFilteringPrefInitialised) {
|
|
|
|
sUseBackgroundNearestFilteringPrefInitialised = true;
|
|
|
|
sUseBackgroundNearestFilteringEnabled = mozilla::Preferences::GetBool("gfx.filter.nearest.force-enabled", false);
|
|
|
|
}
|
|
|
|
|
|
|
|
return sUseBackgroundNearestFilteringEnabled;
|
|
|
|
}
|
|
|
|
|
2012-05-03 07:05:55 -07:00
|
|
|
bool
|
|
|
|
nsLayoutUtils::GPUImageScalingEnabled()
|
|
|
|
{
|
|
|
|
static bool sGPUImageScalingEnabled;
|
|
|
|
static bool sGPUImageScalingPrefInitialised = false;
|
|
|
|
|
|
|
|
if (!sGPUImageScalingPrefInitialised) {
|
|
|
|
sGPUImageScalingPrefInitialised = true;
|
|
|
|
sGPUImageScalingEnabled = mozilla::Preferences::GetBool("layout.gpu-image-scaling.enabled", false);
|
|
|
|
}
|
|
|
|
|
|
|
|
return sGPUImageScalingEnabled;
|
|
|
|
}
|
|
|
|
|
2011-06-15 14:03:49 -07:00
|
|
|
void
|
|
|
|
nsLayoutUtils::UnionChildOverflow(nsIFrame* aFrame,
|
|
|
|
nsOverflowAreas& aOverflowAreas)
|
|
|
|
{
|
2012-01-18 12:04:51 -08:00
|
|
|
// Iterate over all children except pop-ups.
|
|
|
|
const nsIFrame::ChildListIDs skip(nsIFrame::kPopupList |
|
|
|
|
nsIFrame::kSelectPopupList);
|
2011-06-15 14:03:49 -07:00
|
|
|
for (nsIFrame::ChildListIterator childLists(aFrame);
|
|
|
|
!childLists.IsDone(); childLists.Next()) {
|
2012-01-18 12:04:51 -08:00
|
|
|
if (skip.Contains(childLists.CurrentID())) {
|
2011-06-15 14:03:49 -07:00
|
|
|
continue;
|
2012-01-18 12:04:51 -08:00
|
|
|
}
|
2011-06-15 14:03:49 -07:00
|
|
|
|
|
|
|
nsFrameList children = childLists.CurrentList();
|
|
|
|
for (nsFrameList::Enumerator e(children); !e.AtEnd(); e.Next()) {
|
|
|
|
nsIFrame* child = e.get();
|
|
|
|
nsOverflowAreas childOverflow =
|
|
|
|
child->GetOverflowAreas() + child->GetPosition();
|
|
|
|
aOverflowAreas.UnionWith(childOverflow);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-01-13 09:45:14 -08:00
|
|
|
static void DestroyViewID(void* aObject, nsIAtom* aPropertyName,
|
|
|
|
void* aPropertyValue, void* aData)
|
|
|
|
{
|
|
|
|
ViewID* id = static_cast<ViewID*>(aPropertyValue);
|
|
|
|
GetContentMap().Remove(*id);
|
|
|
|
delete id;
|
|
|
|
}
|
|
|
|
|
2011-03-15 16:20:19 -07:00
|
|
|
/**
|
|
|
|
* A namespace class for static layout utilities.
|
|
|
|
*/
|
|
|
|
|
2011-01-13 09:45:14 -08:00
|
|
|
ViewID
|
|
|
|
nsLayoutUtils::FindIDFor(nsIContent* aContent)
|
|
|
|
{
|
|
|
|
ViewID scrollId;
|
|
|
|
|
|
|
|
void* scrollIdProperty = aContent->GetProperty(nsGkAtoms::RemoteId);
|
|
|
|
if (scrollIdProperty) {
|
|
|
|
scrollId = *static_cast<ViewID*>(scrollIdProperty);
|
|
|
|
} else {
|
|
|
|
scrollId = sScrollIdCounter++;
|
|
|
|
aContent->SetProperty(nsGkAtoms::RemoteId, new ViewID(scrollId),
|
|
|
|
DestroyViewID);
|
|
|
|
GetContentMap().Put(scrollId, aContent);
|
|
|
|
}
|
|
|
|
|
|
|
|
return scrollId;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsIContent*
|
|
|
|
nsLayoutUtils::FindContentFor(ViewID aId)
|
|
|
|
{
|
|
|
|
NS_ABORT_IF_FALSE(aId != FrameMetrics::NULL_SCROLL_ID &&
|
|
|
|
aId != FrameMetrics::ROOT_SCROLL_ID,
|
|
|
|
"Cannot find a content element in map for null or root IDs.");
|
|
|
|
nsIContent* content;
|
|
|
|
bool exists = GetContentMap().Get(aId, &content);
|
|
|
|
|
|
|
|
if (exists) {
|
|
|
|
return content;
|
|
|
|
} else {
|
2012-07-30 07:20:58 -07:00
|
|
|
return nullptr;
|
2011-01-13 09:45:14 -08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-03-15 16:20:19 -07:00
|
|
|
bool
|
|
|
|
nsLayoutUtils::GetDisplayPort(nsIContent* aContent, nsRect *aResult)
|
|
|
|
{
|
|
|
|
void* property = aContent->GetProperty(nsGkAtoms::DisplayPort);
|
|
|
|
if (!property) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (aResult) {
|
|
|
|
*aResult = *static_cast<nsRect*>(property);
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2008-01-27 00:13:19 -08:00
|
|
|
nsIFrame*
|
|
|
|
nsLayoutUtils::GetLastContinuationWithChild(nsIFrame* aFrame)
|
|
|
|
{
|
|
|
|
NS_PRECONDITION(aFrame, "NULL frame pointer");
|
|
|
|
aFrame = aFrame->GetLastContinuation();
|
2011-08-24 13:54:30 -07:00
|
|
|
while (!aFrame->GetFirstPrincipalChild() &&
|
2008-01-27 00:13:19 -08:00
|
|
|
aFrame->GetPrevContinuation()) {
|
|
|
|
aFrame = aFrame->GetPrevContinuation();
|
|
|
|
}
|
|
|
|
return aFrame;
|
|
|
|
}
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
/**
|
|
|
|
* GetFirstChildFrame returns the first "real" child frame of a
|
|
|
|
* given frame. It will descend down into pseudo-frames (unless the
|
2010-04-27 09:15:01 -07:00
|
|
|
* pseudo-frame is the :before generated frame).
|
2007-03-22 10:30:00 -07:00
|
|
|
* @param aFrame the frame
|
|
|
|
* @param aFrame the frame's content node
|
|
|
|
*/
|
|
|
|
static nsIFrame*
|
|
|
|
GetFirstChildFrame(nsIFrame* aFrame,
|
|
|
|
nsIContent* aContent)
|
|
|
|
{
|
|
|
|
NS_PRECONDITION(aFrame, "NULL frame pointer");
|
|
|
|
|
|
|
|
// Get the first child frame
|
2011-08-24 13:54:30 -07:00
|
|
|
nsIFrame* childFrame = aFrame->GetFirstPrincipalChild();
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
// If the child frame is a pseudo-frame, then return its first child.
|
|
|
|
// Note that the frame we create for the generated content is also a
|
|
|
|
// pseudo-frame and so don't drill down in that case
|
|
|
|
if (childFrame &&
|
|
|
|
childFrame->IsPseudoFrame(aContent) &&
|
|
|
|
!childFrame->IsGeneratedContentFrame()) {
|
|
|
|
return GetFirstChildFrame(childFrame, aContent);
|
|
|
|
}
|
|
|
|
|
|
|
|
return childFrame;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* GetLastChildFrame returns the last "real" child frame of a
|
|
|
|
* given frame. It will descend down into pseudo-frames (unless the
|
2010-04-27 09:15:01 -07:00
|
|
|
* pseudo-frame is the :after generated frame).
|
2007-03-22 10:30:00 -07:00
|
|
|
* @param aFrame the frame
|
|
|
|
* @param aFrame the frame's content node
|
|
|
|
*/
|
|
|
|
static nsIFrame*
|
|
|
|
GetLastChildFrame(nsIFrame* aFrame,
|
|
|
|
nsIContent* aContent)
|
|
|
|
{
|
|
|
|
NS_PRECONDITION(aFrame, "NULL frame pointer");
|
|
|
|
|
2008-01-27 00:13:19 -08:00
|
|
|
// Get the last continuation frame that's a parent
|
2011-08-24 13:54:30 -07:00
|
|
|
nsIFrame* lastParentContinuation =
|
|
|
|
nsLayoutUtils::GetLastContinuationWithChild(aFrame);
|
|
|
|
nsIFrame* lastChildFrame =
|
|
|
|
lastParentContinuation->GetLastChild(nsIFrame::kPrincipalList);
|
2009-09-18 04:09:36 -07:00
|
|
|
if (lastChildFrame) {
|
2007-03-22 10:30:00 -07:00
|
|
|
// Get the frame's first continuation. This matters in case the frame has
|
|
|
|
// been continued across multiple lines or split by BiDi resolution.
|
|
|
|
lastChildFrame = lastChildFrame->GetFirstContinuation();
|
2010-04-27 09:15:01 -07:00
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
// If the last child frame is a pseudo-frame, then return its last child.
|
|
|
|
// Note that the frame we create for the generated content is also a
|
|
|
|
// pseudo-frame and so don't drill down in that case
|
|
|
|
if (lastChildFrame &&
|
|
|
|
lastChildFrame->IsPseudoFrame(aContent) &&
|
|
|
|
!lastChildFrame->IsGeneratedContentFrame()) {
|
|
|
|
return GetLastChildFrame(lastChildFrame, aContent);
|
|
|
|
}
|
|
|
|
|
|
|
|
return lastChildFrame;
|
|
|
|
}
|
|
|
|
|
2012-07-30 07:20:58 -07:00
|
|
|
return nullptr;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2009-12-23 21:20:41 -08:00
|
|
|
//static
|
2011-08-24 13:54:30 -07:00
|
|
|
nsIFrame::ChildListID
|
2009-12-23 21:20:41 -08:00
|
|
|
nsLayoutUtils::GetChildListNameFor(nsIFrame* aChildFrame)
|
|
|
|
{
|
2011-08-24 13:54:30 -07:00
|
|
|
nsIFrame::ChildListID id = nsIFrame::kPrincipalList;
|
2009-12-23 21:20:41 -08:00
|
|
|
|
|
|
|
if (aChildFrame->GetStateBits() & NS_FRAME_IS_OVERFLOW_CONTAINER) {
|
|
|
|
nsIFrame* pif = aChildFrame->GetPrevInFlow();
|
|
|
|
if (pif->GetParent() == aChildFrame->GetParent()) {
|
2011-08-24 13:54:30 -07:00
|
|
|
id = nsIFrame::kExcessOverflowContainersList;
|
2009-12-23 21:20:41 -08:00
|
|
|
}
|
|
|
|
else {
|
2011-08-24 13:54:30 -07:00
|
|
|
id = nsIFrame::kOverflowContainersList;
|
2009-12-23 21:20:41 -08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
// See if the frame is moved out of the flow
|
|
|
|
else if (aChildFrame->GetStateBits() & NS_FRAME_OUT_OF_FLOW) {
|
|
|
|
// Look at the style information to tell
|
|
|
|
const nsStyleDisplay* disp = aChildFrame->GetStyleDisplay();
|
|
|
|
|
|
|
|
if (NS_STYLE_POSITION_ABSOLUTE == disp->mPosition) {
|
2011-08-24 13:54:30 -07:00
|
|
|
id = nsIFrame::kAbsoluteList;
|
2009-12-23 21:20:41 -08:00
|
|
|
} else if (NS_STYLE_POSITION_FIXED == disp->mPosition) {
|
|
|
|
if (nsLayoutUtils::IsReallyFixedPos(aChildFrame)) {
|
2011-08-24 13:54:30 -07:00
|
|
|
id = nsIFrame::kFixedList;
|
2009-12-23 21:20:41 -08:00
|
|
|
} else {
|
2011-08-24 13:54:30 -07:00
|
|
|
id = nsIFrame::kAbsoluteList;
|
2009-12-23 21:20:41 -08:00
|
|
|
}
|
|
|
|
#ifdef MOZ_XUL
|
|
|
|
} else if (NS_STYLE_DISPLAY_POPUP == disp->mDisplay) {
|
|
|
|
// Out-of-flows that are DISPLAY_POPUP must be kids of the root popup set
|
|
|
|
#ifdef DEBUG
|
|
|
|
nsIFrame* parent = aChildFrame->GetParent();
|
|
|
|
NS_ASSERTION(parent && parent->GetType() == nsGkAtoms::popupSetFrame,
|
|
|
|
"Unexpected parent");
|
|
|
|
#endif // DEBUG
|
|
|
|
|
|
|
|
// XXX FIXME: Bug 350740
|
|
|
|
// Return here, because the postcondition for this function actually
|
|
|
|
// fails for this case, since the popups are not in a "real" frame list
|
|
|
|
// in the popup set.
|
2011-08-24 13:54:30 -07:00
|
|
|
return nsIFrame::kPopupList;
|
2009-12-23 21:20:41 -08:00
|
|
|
#endif // MOZ_XUL
|
|
|
|
} else {
|
2012-08-02 04:38:49 -07:00
|
|
|
NS_ASSERTION(aChildFrame->IsFloating(),
|
2009-12-23 21:20:41 -08:00
|
|
|
"not a floated frame");
|
2011-08-24 13:54:30 -07:00
|
|
|
id = nsIFrame::kFloatList;
|
2009-12-23 21:20:41 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
} else {
|
|
|
|
nsIAtom* childType = aChildFrame->GetType();
|
|
|
|
if (nsGkAtoms::menuPopupFrame == childType) {
|
|
|
|
nsIFrame* parent = aChildFrame->GetParent();
|
|
|
|
nsIFrame* firstPopup = (parent)
|
2011-08-24 13:54:30 -07:00
|
|
|
? parent->GetFirstChild(nsIFrame::kPopupList)
|
2012-07-30 07:20:58 -07:00
|
|
|
: nullptr;
|
2009-12-23 21:20:41 -08:00
|
|
|
NS_ASSERTION(!firstPopup || !firstPopup->GetNextSibling(),
|
|
|
|
"We assume popupList only has one child, but it has more.");
|
2011-08-24 13:54:30 -07:00
|
|
|
id = firstPopup == aChildFrame
|
|
|
|
? nsIFrame::kPopupList
|
|
|
|
: nsIFrame::kPrincipalList;
|
2009-12-23 21:20:41 -08:00
|
|
|
} else if (nsGkAtoms::tableColGroupFrame == childType) {
|
2011-08-24 13:54:30 -07:00
|
|
|
id = nsIFrame::kColGroupList;
|
2009-12-23 21:20:41 -08:00
|
|
|
} else if (nsGkAtoms::tableCaptionFrame == aChildFrame->GetType()) {
|
2011-08-24 13:54:30 -07:00
|
|
|
id = nsIFrame::kCaptionList;
|
2009-12-23 21:20:41 -08:00
|
|
|
} else {
|
2011-08-24 13:54:30 -07:00
|
|
|
id = nsIFrame::kPrincipalList;
|
2009-12-23 21:20:41 -08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-06-25 12:59:42 -07:00
|
|
|
#ifdef DEBUG
|
2009-12-23 21:20:41 -08:00
|
|
|
// Verify that the frame is actually in that child list or in the
|
|
|
|
// corresponding overflow list.
|
|
|
|
nsIFrame* parent = aChildFrame->GetParent();
|
2011-09-28 23:19:26 -07:00
|
|
|
bool found = parent->GetChildList(id).ContainsFrame(aChildFrame);
|
2009-12-23 21:20:41 -08:00
|
|
|
if (!found) {
|
|
|
|
if (!(aChildFrame->GetStateBits() & NS_FRAME_OUT_OF_FLOW)) {
|
2011-08-24 13:54:30 -07:00
|
|
|
found = parent->GetChildList(nsIFrame::kOverflowList)
|
2009-12-23 21:20:41 -08:00
|
|
|
.ContainsFrame(aChildFrame);
|
|
|
|
}
|
2012-08-02 04:38:49 -07:00
|
|
|
else if (aChildFrame->IsFloating()) {
|
2011-08-24 13:54:30 -07:00
|
|
|
found = parent->GetChildList(nsIFrame::kOverflowOutOfFlowList)
|
2009-12-23 21:20:41 -08:00
|
|
|
.ContainsFrame(aChildFrame);
|
|
|
|
}
|
2011-08-24 13:54:30 -07:00
|
|
|
// else it's positioned and should have been on the 'id' child list.
|
2009-12-23 21:20:41 -08:00
|
|
|
NS_POSTCONDITION(found, "not in child list");
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2011-08-24 13:54:30 -07:00
|
|
|
return id;
|
2009-12-23 21:20:41 -08:00
|
|
|
}
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
// static
|
|
|
|
nsIFrame*
|
|
|
|
nsLayoutUtils::GetBeforeFrame(nsIFrame* aFrame)
|
|
|
|
{
|
|
|
|
NS_PRECONDITION(aFrame, "NULL frame pointer");
|
|
|
|
NS_ASSERTION(!aFrame->GetPrevContinuation(),
|
|
|
|
"aFrame must be first continuation");
|
2010-04-27 09:15:01 -07:00
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
nsIFrame* firstFrame = GetFirstChildFrame(aFrame, aFrame->GetContent());
|
|
|
|
|
2012-07-30 07:20:58 -07:00
|
|
|
if (firstFrame && IsGeneratedContentFor(nullptr, firstFrame,
|
2007-03-22 10:30:00 -07:00
|
|
|
nsCSSPseudoElements::before)) {
|
|
|
|
return firstFrame;
|
|
|
|
}
|
|
|
|
|
2012-07-30 07:20:58 -07:00
|
|
|
return nullptr;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
// static
|
|
|
|
nsIFrame*
|
|
|
|
nsLayoutUtils::GetAfterFrame(nsIFrame* aFrame)
|
|
|
|
{
|
|
|
|
NS_PRECONDITION(aFrame, "NULL frame pointer");
|
|
|
|
|
|
|
|
nsIFrame* lastFrame = GetLastChildFrame(aFrame, aFrame->GetContent());
|
|
|
|
|
2012-07-30 07:20:58 -07:00
|
|
|
if (lastFrame && IsGeneratedContentFor(nullptr, lastFrame,
|
2007-03-22 10:30:00 -07:00
|
|
|
nsCSSPseudoElements::after)) {
|
|
|
|
return lastFrame;
|
|
|
|
}
|
|
|
|
|
2012-07-30 07:20:58 -07:00
|
|
|
return nullptr;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
// static
|
|
|
|
nsIFrame*
|
2007-07-03 18:13:07 -07:00
|
|
|
nsLayoutUtils::GetClosestFrameOfType(nsIFrame* aFrame, nsIAtom* aFrameType)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
for (nsIFrame* frame = aFrame; frame; frame = frame->GetParent()) {
|
2007-07-03 18:13:07 -07:00
|
|
|
if (frame->GetType() == aFrameType) {
|
2007-03-22 10:30:00 -07:00
|
|
|
return frame;
|
|
|
|
}
|
|
|
|
}
|
2012-07-30 07:20:58 -07:00
|
|
|
return nullptr;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2009-12-01 09:21:00 -08:00
|
|
|
// static
|
|
|
|
nsIFrame*
|
|
|
|
nsLayoutUtils::GetStyleFrame(nsIFrame* aFrame)
|
|
|
|
{
|
|
|
|
if (aFrame->GetType() == nsGkAtoms::tableOuterFrame) {
|
2011-08-24 13:54:30 -07:00
|
|
|
nsIFrame* inner = aFrame->GetFirstPrincipalChild();
|
2009-12-01 09:21:00 -08:00
|
|
|
NS_ASSERTION(inner, "Outer table must have an inner");
|
|
|
|
return inner;
|
|
|
|
}
|
|
|
|
|
|
|
|
return aFrame;
|
|
|
|
}
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
nsIFrame*
|
|
|
|
nsLayoutUtils::GetFloatFromPlaceholder(nsIFrame* aFrame) {
|
2009-11-16 13:00:07 -08:00
|
|
|
NS_ASSERTION(nsGkAtoms::placeholderFrame == aFrame->GetType(),
|
|
|
|
"Must have a placeholder here");
|
2009-11-16 13:00:07 -08:00
|
|
|
if (aFrame->GetStateBits() & PLACEHOLDER_FOR_FLOAT) {
|
|
|
|
nsIFrame *outOfFlowFrame =
|
|
|
|
nsPlaceholderFrame::GetRealFrameForPlaceholder(aFrame);
|
2012-08-02 04:38:49 -07:00
|
|
|
NS_ASSERTION(outOfFlowFrame->IsFloating(),
|
2009-11-16 13:00:07 -08:00
|
|
|
"How did that happen?");
|
2007-03-22 10:30:00 -07:00
|
|
|
return outOfFlowFrame;
|
|
|
|
}
|
|
|
|
|
2012-07-30 07:20:58 -07:00
|
|
|
return nullptr;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
// static
|
2011-09-28 23:19:26 -07:00
|
|
|
bool
|
2007-03-22 10:30:00 -07:00
|
|
|
nsLayoutUtils::IsGeneratedContentFor(nsIContent* aContent,
|
|
|
|
nsIFrame* aFrame,
|
|
|
|
nsIAtom* aPseudoElement)
|
|
|
|
{
|
|
|
|
NS_PRECONDITION(aFrame, "Must have a frame");
|
|
|
|
NS_PRECONDITION(aPseudoElement, "Must have a pseudo name");
|
|
|
|
|
|
|
|
if (!aFrame->IsGeneratedContentFrame()) {
|
2011-10-17 07:59:28 -07:00
|
|
|
return false;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
2008-08-17 18:16:42 -07:00
|
|
|
nsIFrame* parent = aFrame->GetParent();
|
|
|
|
NS_ASSERTION(parent, "Generated content can't be root frame");
|
|
|
|
if (parent->IsGeneratedContentFrame()) {
|
|
|
|
// Not the root of the generated content
|
2011-10-17 07:59:28 -07:00
|
|
|
return false;
|
2008-08-17 18:16:42 -07:00
|
|
|
}
|
2010-04-27 09:15:01 -07:00
|
|
|
|
2008-08-17 18:16:42 -07:00
|
|
|
if (aContent && parent->GetContent() != aContent) {
|
2011-10-17 07:59:28 -07:00
|
|
|
return false;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2008-08-17 18:16:42 -07:00
|
|
|
return (aFrame->GetContent()->Tag() == nsGkAtoms::mozgeneratedcontentbefore) ==
|
|
|
|
(aPseudoElement == nsCSSPseudoElements::before);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
// static
|
|
|
|
nsIFrame*
|
2008-09-03 14:35:52 -07:00
|
|
|
nsLayoutUtils::GetCrossDocParentFrame(const nsIFrame* aFrame,
|
|
|
|
nsPoint* aExtraOffset)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
nsIFrame* p = aFrame->GetParent();
|
|
|
|
if (p)
|
|
|
|
return p;
|
|
|
|
|
|
|
|
nsIView* v = aFrame->GetView();
|
|
|
|
if (!v)
|
2012-07-30 07:20:58 -07:00
|
|
|
return nullptr;
|
2007-03-22 10:30:00 -07:00
|
|
|
v = v->GetParent(); // anonymous inner view
|
|
|
|
if (!v)
|
2012-07-30 07:20:58 -07:00
|
|
|
return nullptr;
|
2008-09-03 14:35:52 -07:00
|
|
|
if (aExtraOffset) {
|
|
|
|
*aExtraOffset += v->GetPosition();
|
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
v = v->GetParent(); // subdocumentframe's view
|
2012-07-30 07:20:58 -07:00
|
|
|
return v ? v->GetFrame() : nullptr;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
// static
|
2011-09-28 23:19:26 -07:00
|
|
|
bool
|
2007-03-22 10:30:00 -07:00
|
|
|
nsLayoutUtils::IsProperAncestorFrameCrossDoc(nsIFrame* aAncestorFrame, nsIFrame* aFrame,
|
|
|
|
nsIFrame* aCommonAncestor)
|
|
|
|
{
|
2012-08-19 15:25:49 -07:00
|
|
|
if (aFrame == aAncestorFrame)
|
2011-10-17 07:59:28 -07:00
|
|
|
return false;
|
2012-08-19 15:25:49 -07:00
|
|
|
return IsAncestorFrameCrossDoc(aAncestorFrame, aFrame, aCommonAncestor);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2009-07-21 17:44:56 -07:00
|
|
|
// static
|
2011-09-28 23:19:26 -07:00
|
|
|
bool
|
2012-09-12 17:32:53 -07:00
|
|
|
nsLayoutUtils::IsAncestorFrameCrossDoc(const nsIFrame* aAncestorFrame, const nsIFrame* aFrame,
|
|
|
|
const nsIFrame* aCommonAncestor)
|
2009-07-21 17:44:56 -07:00
|
|
|
{
|
2012-09-12 17:32:53 -07:00
|
|
|
for (const nsIFrame* f = aFrame; f != aCommonAncestor;
|
2012-08-19 15:25:49 -07:00
|
|
|
f = GetCrossDocParentFrame(f)) {
|
|
|
|
if (f == aAncestorFrame)
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return aCommonAncestor == aAncestorFrame;
|
2009-07-21 17:44:56 -07:00
|
|
|
}
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
// static
|
2011-09-28 23:19:26 -07:00
|
|
|
bool
|
2007-03-22 10:30:00 -07:00
|
|
|
nsLayoutUtils::IsProperAncestorFrame(nsIFrame* aAncestorFrame, nsIFrame* aFrame,
|
|
|
|
nsIFrame* aCommonAncestor)
|
|
|
|
{
|
2012-08-19 15:25:49 -07:00
|
|
|
if (aFrame == aAncestorFrame)
|
2011-10-17 07:59:28 -07:00
|
|
|
return false;
|
2012-08-19 15:25:49 -07:00
|
|
|
for (nsIFrame* f = aFrame; f != aCommonAncestor; f = f->GetParent()) {
|
|
|
|
if (f == aAncestorFrame)
|
2011-10-17 07:59:28 -07:00
|
|
|
return true;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
2012-08-19 15:25:49 -07:00
|
|
|
return aCommonAncestor == aAncestorFrame;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
// static
|
2012-08-22 08:56:38 -07:00
|
|
|
int32_t
|
2007-03-22 10:30:00 -07:00
|
|
|
nsLayoutUtils::DoCompareTreePosition(nsIContent* aContent1,
|
|
|
|
nsIContent* aContent2,
|
2012-08-22 08:56:38 -07:00
|
|
|
int32_t aIf1Ancestor,
|
|
|
|
int32_t aIf2Ancestor,
|
2009-09-18 11:52:27 -07:00
|
|
|
const nsIContent* aCommonAncestor)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
NS_PRECONDITION(aContent1, "aContent1 must not be null");
|
|
|
|
NS_PRECONDITION(aContent2, "aContent2 must not be null");
|
|
|
|
|
2007-11-11 12:35:30 -08:00
|
|
|
nsAutoTArray<nsINode*, 32> content1Ancestors;
|
2007-03-22 10:30:00 -07:00
|
|
|
nsINode* c1;
|
|
|
|
for (c1 = aContent1; c1 && c1 != aCommonAncestor; c1 = c1->GetNodeParent()) {
|
|
|
|
content1Ancestors.AppendElement(c1);
|
|
|
|
}
|
|
|
|
if (!c1 && aCommonAncestor) {
|
|
|
|
// So, it turns out aCommonAncestor was not an ancestor of c1. Oops.
|
|
|
|
// Never mind. We can continue as if aCommonAncestor was null.
|
2012-07-30 07:20:58 -07:00
|
|
|
aCommonAncestor = nullptr;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2007-11-11 12:35:30 -08:00
|
|
|
nsAutoTArray<nsINode*, 32> content2Ancestors;
|
2007-03-22 10:30:00 -07:00
|
|
|
nsINode* c2;
|
|
|
|
for (c2 = aContent2; c2 && c2 != aCommonAncestor; c2 = c2->GetNodeParent()) {
|
|
|
|
content2Ancestors.AppendElement(c2);
|
|
|
|
}
|
|
|
|
if (!c2 && aCommonAncestor) {
|
|
|
|
// So, it turns out aCommonAncestor was not an ancestor of c2.
|
|
|
|
// We need to retry with no common ancestor hint.
|
|
|
|
return DoCompareTreePosition(aContent1, aContent2,
|
2012-07-30 07:20:58 -07:00
|
|
|
aIf1Ancestor, aIf2Ancestor, nullptr);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
2010-04-27 09:15:01 -07:00
|
|
|
|
2007-11-11 12:35:30 -08:00
|
|
|
int last1 = content1Ancestors.Length() - 1;
|
|
|
|
int last2 = content2Ancestors.Length() - 1;
|
2012-07-30 07:20:58 -07:00
|
|
|
nsINode* content1Ancestor = nullptr;
|
|
|
|
nsINode* content2Ancestor = nullptr;
|
2007-03-22 10:30:00 -07:00
|
|
|
while (last1 >= 0 && last2 >= 0
|
2007-11-11 12:35:30 -08:00
|
|
|
&& ((content1Ancestor = content1Ancestors.ElementAt(last1)) ==
|
|
|
|
(content2Ancestor = content2Ancestors.ElementAt(last2)))) {
|
2007-03-22 10:30:00 -07:00
|
|
|
last1--;
|
|
|
|
last2--;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (last1 < 0) {
|
|
|
|
if (last2 < 0) {
|
|
|
|
NS_ASSERTION(aContent1 == aContent2, "internal error?");
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
// aContent1 is an ancestor of aContent2
|
|
|
|
return aIf1Ancestor;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (last2 < 0) {
|
|
|
|
// aContent2 is an ancestor of aContent1
|
|
|
|
return aIf2Ancestor;
|
|
|
|
}
|
|
|
|
|
|
|
|
// content1Ancestor != content2Ancestor, so they must be siblings with the same parent
|
|
|
|
nsINode* parent = content1Ancestor->GetNodeParent();
|
2010-10-13 03:52:45 -07:00
|
|
|
#ifdef DEBUG
|
|
|
|
// TODO: remove the uglyness, see bug 598468.
|
|
|
|
NS_ASSERTION(gPreventAssertInCompareTreePosition || parent,
|
|
|
|
"no common ancestor at all???");
|
|
|
|
#endif // DEBUG
|
2007-03-22 10:30:00 -07:00
|
|
|
if (!parent) { // different documents??
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2012-08-22 08:56:38 -07:00
|
|
|
int32_t index1 = parent->IndexOf(content1Ancestor);
|
|
|
|
int32_t index2 = parent->IndexOf(content2Ancestor);
|
2007-03-22 10:30:00 -07:00
|
|
|
if (index1 < 0 || index2 < 0) {
|
|
|
|
// one of them must be anonymous; we can't determine the order
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
return index1 - index2;
|
|
|
|
}
|
|
|
|
|
|
|
|
static nsIFrame* FillAncestors(nsIFrame* aFrame,
|
2012-06-10 16:44:50 -07:00
|
|
|
nsIFrame* aStopAtAncestor,
|
2007-03-22 10:30:00 -07:00
|
|
|
nsTArray<nsIFrame*>* aAncestors)
|
|
|
|
{
|
|
|
|
while (aFrame && aFrame != aStopAtAncestor) {
|
|
|
|
aAncestors->AppendElement(aFrame);
|
2012-06-10 16:44:50 -07:00
|
|
|
aFrame = nsLayoutUtils::GetParentOrPlaceholderFor(aFrame);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
return aFrame;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Return true if aFrame1 is after aFrame2
|
2011-09-28 23:19:26 -07:00
|
|
|
static bool IsFrameAfter(nsIFrame* aFrame1, nsIFrame* aFrame2)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
nsIFrame* f = aFrame2;
|
|
|
|
do {
|
|
|
|
f = f->GetNextSibling();
|
|
|
|
if (f == aFrame1)
|
2011-10-17 07:59:28 -07:00
|
|
|
return true;
|
2007-03-22 10:30:00 -07:00
|
|
|
} while (f);
|
2011-10-17 07:59:28 -07:00
|
|
|
return false;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
// static
|
2012-08-22 08:56:38 -07:00
|
|
|
int32_t
|
2007-03-22 10:30:00 -07:00
|
|
|
nsLayoutUtils::DoCompareTreePosition(nsIFrame* aFrame1,
|
|
|
|
nsIFrame* aFrame2,
|
2012-08-22 08:56:38 -07:00
|
|
|
int32_t aIf1Ancestor,
|
|
|
|
int32_t aIf2Ancestor,
|
2007-03-22 10:30:00 -07:00
|
|
|
nsIFrame* aCommonAncestor)
|
|
|
|
{
|
|
|
|
NS_PRECONDITION(aFrame1, "aFrame1 must not be null");
|
|
|
|
NS_PRECONDITION(aFrame2, "aFrame2 must not be null");
|
|
|
|
|
2007-03-30 14:11:41 -07:00
|
|
|
nsPresContext* presContext = aFrame1->PresContext();
|
|
|
|
if (presContext != aFrame2->PresContext()) {
|
2007-03-22 10:30:00 -07:00
|
|
|
NS_ERROR("no common ancestor at all, different documents");
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsAutoTArray<nsIFrame*,20> frame1Ancestors;
|
2012-06-10 16:44:50 -07:00
|
|
|
if (!FillAncestors(aFrame1, aCommonAncestor, &frame1Ancestors)) {
|
2007-03-22 10:30:00 -07:00
|
|
|
// We reached the root of the frame tree ... if aCommonAncestor was set,
|
|
|
|
// it is wrong
|
2012-07-30 07:20:58 -07:00
|
|
|
aCommonAncestor = nullptr;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
nsAutoTArray<nsIFrame*,20> frame2Ancestors;
|
2012-06-10 16:44:50 -07:00
|
|
|
if (!FillAncestors(aFrame2, aCommonAncestor, &frame2Ancestors) &&
|
2007-03-22 10:30:00 -07:00
|
|
|
aCommonAncestor) {
|
|
|
|
// We reached the root of the frame tree ... aCommonAncestor was wrong.
|
|
|
|
// Try again with no hint.
|
|
|
|
return DoCompareTreePosition(aFrame1, aFrame2,
|
2012-07-30 07:20:58 -07:00
|
|
|
aIf1Ancestor, aIf2Ancestor, nullptr);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2012-08-22 08:56:38 -07:00
|
|
|
int32_t last1 = int32_t(frame1Ancestors.Length()) - 1;
|
|
|
|
int32_t last2 = int32_t(frame2Ancestors.Length()) - 1;
|
2007-03-22 10:30:00 -07:00
|
|
|
while (last1 >= 0 && last2 >= 0 &&
|
|
|
|
frame1Ancestors[last1] == frame2Ancestors[last2]) {
|
|
|
|
last1--;
|
|
|
|
last2--;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (last1 < 0) {
|
|
|
|
if (last2 < 0) {
|
|
|
|
NS_ASSERTION(aFrame1 == aFrame2, "internal error?");
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
// aFrame1 is an ancestor of aFrame2
|
|
|
|
return aIf1Ancestor;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (last2 < 0) {
|
|
|
|
// aFrame2 is an ancestor of aFrame1
|
|
|
|
return aIf2Ancestor;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsIFrame* ancestor1 = frame1Ancestors[last1];
|
|
|
|
nsIFrame* ancestor2 = frame2Ancestors[last2];
|
|
|
|
// Now we should be able to walk sibling chains to find which one is first
|
|
|
|
if (IsFrameAfter(ancestor2, ancestor1))
|
|
|
|
return -1;
|
|
|
|
if (IsFrameAfter(ancestor1, ancestor2))
|
|
|
|
return 1;
|
|
|
|
NS_WARNING("Frames were in different child lists???");
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
// static
|
|
|
|
nsIFrame* nsLayoutUtils::GetLastSibling(nsIFrame* aFrame) {
|
|
|
|
if (!aFrame) {
|
2012-07-30 07:20:58 -07:00
|
|
|
return nullptr;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
nsIFrame* next;
|
2012-07-30 07:20:58 -07:00
|
|
|
while ((next = aFrame->GetNextSibling()) != nullptr) {
|
2007-03-22 10:30:00 -07:00
|
|
|
aFrame = next;
|
|
|
|
}
|
|
|
|
return aFrame;
|
|
|
|
}
|
|
|
|
|
|
|
|
// static
|
|
|
|
nsIView*
|
|
|
|
nsLayoutUtils::FindSiblingViewFor(nsIView* aParentView, nsIFrame* aFrame) {
|
2011-11-21 09:53:20 -08:00
|
|
|
nsIFrame* parentViewFrame = aParentView->GetFrame();
|
2012-07-30 07:20:58 -07:00
|
|
|
nsIContent* parentViewContent = parentViewFrame ? parentViewFrame->GetContent() : nullptr;
|
2007-03-22 10:30:00 -07:00
|
|
|
for (nsIView* insertBefore = aParentView->GetFirstChild(); insertBefore;
|
|
|
|
insertBefore = insertBefore->GetNextSibling()) {
|
2011-11-21 09:53:20 -08:00
|
|
|
nsIFrame* f = insertBefore->GetFrame();
|
2007-03-22 10:30:00 -07:00
|
|
|
if (!f) {
|
|
|
|
// this view could be some anonymous view attached to a meaningful parent
|
|
|
|
for (nsIView* searchView = insertBefore->GetParent(); searchView;
|
|
|
|
searchView = searchView->GetParent()) {
|
2011-11-21 09:53:20 -08:00
|
|
|
f = searchView->GetFrame();
|
2007-03-22 10:30:00 -07:00
|
|
|
if (f) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
NS_ASSERTION(f, "Can't find a frame anywhere!");
|
|
|
|
}
|
|
|
|
if (!f || !aFrame->GetContent() || !f->GetContent() ||
|
|
|
|
CompareTreePosition(aFrame->GetContent(), f->GetContent(), parentViewContent) > 0) {
|
|
|
|
// aFrame's content is after f's content (or we just don't know),
|
|
|
|
// so put our view before f's view
|
|
|
|
return insertBefore;
|
|
|
|
}
|
|
|
|
}
|
2012-07-30 07:20:58 -07:00
|
|
|
return nullptr;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
//static
|
|
|
|
nsIScrollableFrame*
|
2012-08-16 16:40:10 -07:00
|
|
|
nsLayoutUtils::GetScrollableFrameFor(const nsIFrame *aScrolledFrame)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
nsIFrame *frame = aScrolledFrame->GetParent();
|
|
|
|
if (!frame) {
|
2012-07-30 07:20:58 -07:00
|
|
|
return nullptr;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
2009-01-12 11:20:59 -08:00
|
|
|
nsIScrollableFrame *sf = do_QueryFrame(frame);
|
2007-03-22 10:30:00 -07:00
|
|
|
return sf;
|
|
|
|
}
|
|
|
|
|
2010-07-15 14:07:51 -07:00
|
|
|
nsIFrame*
|
|
|
|
nsLayoutUtils::GetActiveScrolledRootFor(nsIFrame* aFrame,
|
2012-09-12 17:32:53 -07:00
|
|
|
const nsIFrame* aStopAtAncestor)
|
2010-07-15 14:07:51 -07:00
|
|
|
{
|
2010-07-15 14:08:02 -07:00
|
|
|
nsIFrame* f = aFrame;
|
|
|
|
while (f != aStopAtAncestor) {
|
2010-08-13 03:03:51 -07:00
|
|
|
if (IsPopup(f))
|
|
|
|
break;
|
2010-08-08 11:49:06 -07:00
|
|
|
nsIFrame* parent = GetCrossDocParentFrame(f);
|
2010-07-15 14:08:02 -07:00
|
|
|
if (!parent)
|
|
|
|
break;
|
|
|
|
nsIScrollableFrame* sf = do_QueryFrame(parent);
|
|
|
|
if (sf && sf->IsScrollingActive() && sf->GetScrolledFrame() == f)
|
|
|
|
break;
|
|
|
|
f = parent;
|
|
|
|
}
|
|
|
|
return f;
|
2010-07-15 14:07:51 -07:00
|
|
|
}
|
|
|
|
|
2011-04-05 22:00:25 -07:00
|
|
|
nsIFrame*
|
|
|
|
nsLayoutUtils::GetActiveScrolledRootFor(nsDisplayItem* aItem,
|
2011-05-09 01:40:09 -07:00
|
|
|
nsDisplayListBuilder* aBuilder,
|
2011-09-28 23:19:26 -07:00
|
|
|
bool* aShouldFixToViewport)
|
2011-04-05 22:00:25 -07:00
|
|
|
{
|
|
|
|
nsIFrame* f = aItem->GetUnderlyingFrame();
|
2011-05-09 01:40:09 -07:00
|
|
|
if (aShouldFixToViewport) {
|
2011-10-17 07:59:28 -07:00
|
|
|
*aShouldFixToViewport = false;
|
2011-05-09 01:40:09 -07:00
|
|
|
}
|
2011-04-05 22:00:25 -07:00
|
|
|
if (!f) {
|
2012-07-30 07:20:58 -07:00
|
|
|
return nullptr;
|
2011-04-05 22:00:25 -07:00
|
|
|
}
|
|
|
|
if (aItem->ShouldFixToViewport(aBuilder)) {
|
2011-05-09 01:40:09 -07:00
|
|
|
if (aShouldFixToViewport) {
|
2011-10-17 07:59:28 -07:00
|
|
|
*aShouldFixToViewport = true;
|
2011-05-09 01:40:09 -07:00
|
|
|
}
|
2011-04-05 22:00:25 -07:00
|
|
|
// Make its active scrolled root be the active scrolled root of
|
|
|
|
// the enclosing viewport, since it shouldn't be scrolled by scrolled
|
|
|
|
// frames in its document. InvalidateFixedBackgroundFramesFromList in
|
|
|
|
// nsGfxScrollFrame will not repaint this item when scrolling occurs.
|
|
|
|
nsIFrame* viewportFrame =
|
|
|
|
nsLayoutUtils::GetClosestFrameOfType(f, nsGkAtoms::viewportFrame);
|
|
|
|
NS_ASSERTION(viewportFrame, "no viewport???");
|
2012-09-16 03:32:59 -07:00
|
|
|
return nsLayoutUtils::GetActiveScrolledRootFor(viewportFrame, aBuilder->FindReferenceFrameFor(viewportFrame));
|
2011-04-05 22:00:25 -07:00
|
|
|
} else {
|
2012-09-16 03:32:59 -07:00
|
|
|
return nsLayoutUtils::GetActiveScrolledRootFor(f, aItem->ReferenceFrame());
|
2011-04-05 22:00:25 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-09-28 23:19:26 -07:00
|
|
|
bool
|
2012-09-12 17:32:53 -07:00
|
|
|
nsLayoutUtils::IsScrolledByRootContentDocumentDisplayportScrolling(const nsIFrame* aActiveScrolledRoot,
|
2012-05-03 22:00:57 -07:00
|
|
|
nsDisplayListBuilder* aBuilder)
|
2011-04-05 22:00:25 -07:00
|
|
|
{
|
2012-05-03 22:00:57 -07:00
|
|
|
nsPresContext* presContext = aActiveScrolledRoot->PresContext()->
|
|
|
|
GetToplevelContentDocumentPresContext();
|
|
|
|
if (!presContext)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
nsIFrame* rootScrollFrame = presContext->GetPresShell()->GetRootScrollFrame();
|
2012-07-30 07:20:58 -07:00
|
|
|
if (!rootScrollFrame || !nsLayoutUtils::GetDisplayPort(rootScrollFrame->GetContent(), nullptr))
|
2012-05-03 22:00:57 -07:00
|
|
|
return false;
|
2011-04-05 22:00:25 -07:00
|
|
|
return nsLayoutUtils::IsAncestorFrameCrossDoc(rootScrollFrame, aActiveScrolledRoot);
|
|
|
|
}
|
|
|
|
|
2009-09-01 04:29:27 -07:00
|
|
|
// static
|
|
|
|
nsIScrollableFrame*
|
|
|
|
nsLayoutUtils::GetNearestScrollableFrameForDirection(nsIFrame* aFrame,
|
|
|
|
Direction aDirection)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2009-09-01 04:29:27 -07:00
|
|
|
NS_ASSERTION(aFrame, "GetNearestScrollableFrameForDirection expects a non-null frame");
|
|
|
|
for (nsIFrame* f = aFrame; f; f = nsLayoutUtils::GetCrossDocParentFrame(f)) {
|
|
|
|
nsIScrollableFrame* scrollableFrame = do_QueryFrame(f);
|
|
|
|
if (scrollableFrame) {
|
|
|
|
nsPresContext::ScrollbarStyles ss = scrollableFrame->GetScrollbarStyles();
|
2012-08-22 08:56:38 -07:00
|
|
|
uint32_t scrollbarVisibility = scrollableFrame->GetScrollbarVisibility();
|
2009-09-01 04:29:27 -07:00
|
|
|
nsRect scrollRange = scrollableFrame->GetScrollRange();
|
|
|
|
// Require visible scrollbars or something to scroll to in
|
|
|
|
// the given direction.
|
2012-08-29 04:21:40 -07:00
|
|
|
nscoord oneDevPixel = f->PresContext()->DevPixelsToAppUnits(1);
|
2009-09-01 04:29:27 -07:00
|
|
|
if (aDirection == eVertical ?
|
|
|
|
(ss.mVertical != NS_STYLE_OVERFLOW_HIDDEN &&
|
2010-01-14 05:00:00 -08:00
|
|
|
((scrollbarVisibility & nsIScrollableFrame::VERTICAL) ||
|
2012-08-29 04:21:40 -07:00
|
|
|
scrollRange.height >= oneDevPixel)) :
|
2009-09-01 04:29:27 -07:00
|
|
|
(ss.mHorizontal != NS_STYLE_OVERFLOW_HIDDEN &&
|
2010-01-14 05:00:00 -08:00
|
|
|
((scrollbarVisibility & nsIScrollableFrame::HORIZONTAL) ||
|
2012-08-29 04:21:40 -07:00
|
|
|
scrollRange.width >= oneDevPixel)))
|
2009-09-01 04:29:27 -07:00
|
|
|
return scrollableFrame;
|
|
|
|
}
|
|
|
|
}
|
2012-07-30 07:20:58 -07:00
|
|
|
return nullptr;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
// static
|
2009-09-01 04:29:27 -07:00
|
|
|
nsIScrollableFrame*
|
|
|
|
nsLayoutUtils::GetNearestScrollableFrame(nsIFrame* aFrame)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2009-09-01 04:29:27 -07:00
|
|
|
NS_ASSERTION(aFrame, "GetNearestScrollableFrame expects a non-null frame");
|
|
|
|
for (nsIFrame* f = aFrame; f; f = nsLayoutUtils::GetCrossDocParentFrame(f)) {
|
|
|
|
nsIScrollableFrame* scrollableFrame = do_QueryFrame(f);
|
|
|
|
if (scrollableFrame) {
|
|
|
|
nsPresContext::ScrollbarStyles ss = scrollableFrame->GetScrollbarStyles();
|
|
|
|
if (ss.mVertical != NS_STYLE_OVERFLOW_HIDDEN ||
|
|
|
|
ss.mHorizontal != NS_STYLE_OVERFLOW_HIDDEN)
|
|
|
|
return scrollableFrame;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
}
|
2012-07-30 07:20:58 -07:00
|
|
|
return nullptr;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2010-08-05 15:11:23 -07:00
|
|
|
//static
|
2011-09-28 23:19:26 -07:00
|
|
|
bool
|
2010-08-05 15:11:23 -07:00
|
|
|
nsLayoutUtils::HasPseudoStyle(nsIContent* aContent,
|
|
|
|
nsStyleContext* aStyleContext,
|
|
|
|
nsCSSPseudoElements::Type aPseudoElement,
|
|
|
|
nsPresContext* aPresContext)
|
|
|
|
{
|
|
|
|
NS_PRECONDITION(aPresContext, "Must have a prescontext");
|
|
|
|
|
|
|
|
nsRefPtr<nsStyleContext> pseudoContext;
|
|
|
|
if (aContent) {
|
|
|
|
pseudoContext = aPresContext->StyleSet()->
|
|
|
|
ProbePseudoElementStyle(aContent->AsElement(), aPseudoElement,
|
|
|
|
aStyleContext);
|
|
|
|
}
|
2012-07-30 07:20:58 -07:00
|
|
|
return pseudoContext != nullptr;
|
2010-08-05 15:11:23 -07:00
|
|
|
}
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
nsPoint
|
|
|
|
nsLayoutUtils::GetDOMEventCoordinatesRelativeTo(nsIDOMEvent* aDOMEvent, nsIFrame* aFrame)
|
|
|
|
{
|
2012-06-10 16:44:50 -07:00
|
|
|
if (!aDOMEvent)
|
2007-03-22 10:30:00 -07:00
|
|
|
return nsPoint(NS_UNCONSTRAINEDSIZE, NS_UNCONSTRAINEDSIZE);
|
2012-06-10 16:44:50 -07:00
|
|
|
nsEvent *event = aDOMEvent->GetInternalNSEvent();
|
2008-10-09 16:23:07 -07:00
|
|
|
if (!event)
|
2007-03-22 10:30:00 -07:00
|
|
|
return nsPoint(NS_UNCONSTRAINEDSIZE, NS_UNCONSTRAINEDSIZE);
|
|
|
|
return GetEventCoordinatesRelativeTo(event, aFrame);
|
|
|
|
}
|
|
|
|
|
|
|
|
nsPoint
|
2007-06-26 17:30:21 -07:00
|
|
|
nsLayoutUtils::GetEventCoordinatesRelativeTo(const nsEvent* aEvent, nsIFrame* aFrame)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2010-04-27 09:15:01 -07:00
|
|
|
if (!aEvent || (aEvent->eventStructType != NS_MOUSE_EVENT &&
|
2008-08-27 05:07:27 -07:00
|
|
|
aEvent->eventStructType != NS_MOUSE_SCROLL_EVENT &&
|
2012-08-11 18:42:34 -07:00
|
|
|
aEvent->eventStructType != NS_WHEEL_EVENT &&
|
2009-01-03 04:40:26 -08:00
|
|
|
aEvent->eventStructType != NS_DRAG_EVENT &&
|
2009-05-14 17:46:24 -07:00
|
|
|
aEvent->eventStructType != NS_SIMPLE_GESTURE_EVENT &&
|
2009-08-13 13:54:09 -07:00
|
|
|
aEvent->eventStructType != NS_GESTURENOTIFY_EVENT &&
|
2011-12-16 16:24:11 -08:00
|
|
|
aEvent->eventStructType != NS_TOUCH_EVENT &&
|
2009-05-14 17:46:24 -07:00
|
|
|
aEvent->eventStructType != NS_QUERY_CONTENT_EVENT))
|
2007-03-22 10:30:00 -07:00
|
|
|
return nsPoint(NS_UNCONSTRAINEDSIZE, NS_UNCONSTRAINEDSIZE);
|
|
|
|
|
2007-07-08 00:08:04 -07:00
|
|
|
const nsGUIEvent* GUIEvent = static_cast<const nsGUIEvent*>(aEvent);
|
2011-12-16 16:24:11 -08:00
|
|
|
return GetEventCoordinatesRelativeTo(aEvent,
|
|
|
|
GUIEvent->refPoint,
|
|
|
|
aFrame);
|
|
|
|
}
|
|
|
|
|
|
|
|
nsPoint
|
|
|
|
nsLayoutUtils::GetEventCoordinatesRelativeTo(const nsEvent* aEvent,
|
|
|
|
const nsIntPoint aPoint,
|
|
|
|
nsIFrame* aFrame)
|
|
|
|
{
|
|
|
|
if (!aFrame) {
|
|
|
|
return nsPoint(NS_UNCONSTRAINEDSIZE, NS_UNCONSTRAINEDSIZE);
|
|
|
|
}
|
|
|
|
|
|
|
|
const nsGUIEvent* GUIEvent = static_cast<const nsGUIEvent*>(aEvent);
|
|
|
|
nsIWidget* widget = GUIEvent->widget;
|
|
|
|
if (!widget) {
|
|
|
|
return nsPoint(NS_UNCONSTRAINEDSIZE, NS_UNCONSTRAINEDSIZE);
|
|
|
|
}
|
|
|
|
|
2012-09-10 14:02:23 -07:00
|
|
|
return GetEventCoordinatesRelativeTo(widget, aPoint, aFrame);
|
|
|
|
}
|
|
|
|
|
|
|
|
nsPoint
|
|
|
|
nsLayoutUtils::GetEventCoordinatesRelativeTo(nsIWidget* aWidget,
|
|
|
|
const nsIntPoint aPoint,
|
|
|
|
nsIFrame* aFrame)
|
|
|
|
{
|
|
|
|
if (!aFrame || !aWidget) {
|
|
|
|
return nsPoint(NS_UNCONSTRAINEDSIZE, NS_UNCONSTRAINEDSIZE);
|
|
|
|
}
|
|
|
|
|
2012-03-03 13:24:13 -08:00
|
|
|
nsIView* view = aFrame->GetView();
|
|
|
|
if (view) {
|
2012-03-06 07:58:36 -08:00
|
|
|
nsIWidget* frameWidget = view->GetWidget();
|
2012-09-10 14:02:23 -07:00
|
|
|
if (frameWidget && frameWidget == aWidget) {
|
2012-03-03 13:24:13 -08:00
|
|
|
// Special case this cause it happens a lot.
|
|
|
|
// This also fixes bug 664707, events in the extra-special case of select
|
|
|
|
// dropdown popups that are transformed.
|
|
|
|
nsPresContext* presContext = aFrame->PresContext();
|
2012-03-06 07:58:36 -08:00
|
|
|
nsPoint pt(presContext->DevPixelsToAppUnits(aPoint.x),
|
|
|
|
presContext->DevPixelsToAppUnits(aPoint.y));
|
2012-03-03 13:24:13 -08:00
|
|
|
return pt - view->ViewToWidgetOffset();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-12-16 16:24:11 -08:00
|
|
|
/* If we walk up the frame tree and discover that any of the frames are
|
|
|
|
* transformed, we need to do extra work to convert from the global
|
|
|
|
* space to the local space.
|
|
|
|
*/
|
|
|
|
nsIFrame* rootFrame = aFrame;
|
|
|
|
bool transformFound = false;
|
|
|
|
for (nsIFrame* f = aFrame; f; f = GetCrossDocParentFrame(f)) {
|
|
|
|
if (f->IsTransformed()) {
|
|
|
|
transformFound = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
rootFrame = f;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsIView* rootView = rootFrame->GetView();
|
|
|
|
if (!rootView) {
|
|
|
|
return nsPoint(NS_UNCONSTRAINEDSIZE, NS_UNCONSTRAINEDSIZE);
|
|
|
|
}
|
|
|
|
|
|
|
|
nsPoint widgetToView = TranslateWidgetToView(rootFrame->PresContext(),
|
2012-09-10 14:02:23 -07:00
|
|
|
aWidget, aPoint, rootView);
|
2011-12-16 16:24:11 -08:00
|
|
|
|
|
|
|
if (widgetToView == nsPoint(NS_UNCONSTRAINEDSIZE, NS_UNCONSTRAINEDSIZE)) {
|
|
|
|
return nsPoint(NS_UNCONSTRAINEDSIZE, NS_UNCONSTRAINEDSIZE);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Convert from root document app units to app units of the document aFrame
|
|
|
|
// is in.
|
2012-08-22 08:56:38 -07:00
|
|
|
int32_t rootAPD = rootFrame->PresContext()->AppUnitsPerDevPixel();
|
|
|
|
int32_t localAPD = aFrame->PresContext()->AppUnitsPerDevPixel();
|
2011-12-16 16:24:11 -08:00
|
|
|
widgetToView = widgetToView.ConvertAppUnits(rootAPD, localAPD);
|
|
|
|
|
|
|
|
/* If we encountered a transform, we can't do simple arithmetic to figure
|
|
|
|
* out how to convert back to aFrame's coordinates and must use the CTM.
|
|
|
|
*/
|
|
|
|
if (transformFound) {
|
|
|
|
return TransformRootPointToFrame(aFrame, widgetToView);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Otherwise, all coordinate systems are translations of one another,
|
|
|
|
* so we can just subtract out the different.
|
|
|
|
*/
|
|
|
|
nsPoint offset = aFrame->GetOffsetToCrossDoc(rootFrame);
|
|
|
|
return widgetToView - offset;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2010-03-18 22:02:53 -07:00
|
|
|
nsIFrame*
|
2010-07-27 06:38:03 -07:00
|
|
|
nsLayoutUtils::GetPopupFrameForEventCoordinates(nsPresContext* aPresContext,
|
|
|
|
const nsEvent* aEvent)
|
2010-03-18 22:02:53 -07:00
|
|
|
{
|
|
|
|
#ifdef MOZ_XUL
|
|
|
|
nsXULPopupManager* pm = nsXULPopupManager::GetInstance();
|
|
|
|
if (!pm) {
|
2012-07-30 07:20:58 -07:00
|
|
|
return nullptr;
|
2010-03-18 22:02:53 -07:00
|
|
|
}
|
|
|
|
nsTArray<nsIFrame*> popups = pm->GetVisiblePopups();
|
2012-08-22 08:56:38 -07:00
|
|
|
uint32_t i;
|
2010-03-18 22:02:53 -07:00
|
|
|
// Search from top to bottom
|
|
|
|
for (i = 0; i < popups.Length(); i++) {
|
|
|
|
nsIFrame* popup = popups[i];
|
2010-07-27 06:38:03 -07:00
|
|
|
if (popup->PresContext()->GetRootPresContext() == aPresContext &&
|
2010-10-06 21:25:47 -07:00
|
|
|
popup->GetScrollableOverflowRect().Contains(
|
2010-03-18 22:02:53 -07:00
|
|
|
GetEventCoordinatesRelativeTo(aEvent, popup))) {
|
|
|
|
return popup;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
2012-07-30 07:20:58 -07:00
|
|
|
return nullptr;
|
2010-03-18 22:02:53 -07:00
|
|
|
}
|
|
|
|
|
2011-07-22 15:28:51 -07:00
|
|
|
gfx3DMatrix
|
2011-08-02 20:04:23 -07:00
|
|
|
nsLayoutUtils::ChangeMatrixBasis(const gfxPoint3D &aOrigin,
|
2011-07-22 15:28:51 -07:00
|
|
|
const gfx3DMatrix &aMatrix)
|
2008-09-13 02:42:11 -07:00
|
|
|
{
|
2011-08-26 17:07:05 -07:00
|
|
|
gfx3DMatrix result = aMatrix;
|
|
|
|
|
|
|
|
/* Translate to the origin before aMatrix */
|
|
|
|
result.Translate(-aOrigin);
|
|
|
|
|
|
|
|
/* Translate back into position after aMatrix */
|
|
|
|
result.TranslatePost(aOrigin);
|
2008-09-13 02:42:11 -07:00
|
|
|
|
2011-08-26 17:07:05 -07:00
|
|
|
return result;
|
2008-09-13 02:42:11 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Given a gfxFloat, constrains its value to be between nscoord_MIN and nscoord_MAX.
|
|
|
|
*
|
|
|
|
* @param aVal The value to constrain (in/out)
|
|
|
|
*/
|
|
|
|
static void ConstrainToCoordValues(gfxFloat &aVal)
|
|
|
|
{
|
|
|
|
if (aVal <= nscoord_MIN)
|
|
|
|
aVal = nscoord_MIN;
|
|
|
|
else if (aVal >= nscoord_MAX)
|
|
|
|
aVal = nscoord_MAX;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsRect
|
|
|
|
nsLayoutUtils::RoundGfxRectToAppRect(const gfxRect &aRect, float aFactor)
|
2010-04-27 09:15:01 -07:00
|
|
|
{
|
|
|
|
/* Get a new gfxRect whose units are app units by scaling by the specified factor. */
|
2011-04-18 20:07:48 -07:00
|
|
|
gfxRect scaledRect = aRect;
|
|
|
|
scaledRect.ScaleRoundOut(aFactor);
|
2008-09-13 02:42:11 -07:00
|
|
|
|
|
|
|
/* We now need to constrain our results to the max and min values for coords. */
|
2011-04-18 20:07:21 -07:00
|
|
|
ConstrainToCoordValues(scaledRect.x);
|
|
|
|
ConstrainToCoordValues(scaledRect.y);
|
|
|
|
ConstrainToCoordValues(scaledRect.width);
|
|
|
|
ConstrainToCoordValues(scaledRect.height);
|
2010-04-27 09:15:01 -07:00
|
|
|
|
2008-09-13 02:42:11 -07:00
|
|
|
/* Now typecast everything back. This is guaranteed to be safe. */
|
2011-04-18 20:07:21 -07:00
|
|
|
return nsRect(nscoord(scaledRect.X()), nscoord(scaledRect.Y()),
|
|
|
|
nscoord(scaledRect.Width()), nscoord(scaledRect.Height()));
|
2008-09-13 02:42:11 -07:00
|
|
|
}
|
|
|
|
|
2011-01-02 17:48:09 -08:00
|
|
|
|
|
|
|
nsRegion
|
|
|
|
nsLayoutUtils::RoundedRectIntersectRect(const nsRect& aRoundedRect,
|
|
|
|
const nscoord aRadii[8],
|
|
|
|
const nsRect& aContainedRect)
|
|
|
|
{
|
|
|
|
// rectFullHeight and rectFullWidth together will approximately contain
|
|
|
|
// the total area of the frame minus the rounded corners.
|
|
|
|
nsRect rectFullHeight = aRoundedRect;
|
|
|
|
nscoord xDiff = NS_MAX(aRadii[NS_CORNER_TOP_LEFT_X], aRadii[NS_CORNER_BOTTOM_LEFT_X]);
|
|
|
|
rectFullHeight.x += xDiff;
|
|
|
|
rectFullHeight.width -= NS_MAX(aRadii[NS_CORNER_TOP_RIGHT_X],
|
|
|
|
aRadii[NS_CORNER_BOTTOM_RIGHT_X]) + xDiff;
|
|
|
|
nsRect r1;
|
|
|
|
r1.IntersectRect(rectFullHeight, aContainedRect);
|
|
|
|
|
|
|
|
nsRect rectFullWidth = aRoundedRect;
|
|
|
|
nscoord yDiff = NS_MAX(aRadii[NS_CORNER_TOP_LEFT_Y], aRadii[NS_CORNER_TOP_RIGHT_Y]);
|
|
|
|
rectFullWidth.y += yDiff;
|
|
|
|
rectFullWidth.height -= NS_MAX(aRadii[NS_CORNER_BOTTOM_LEFT_Y],
|
|
|
|
aRadii[NS_CORNER_BOTTOM_RIGHT_Y]) + yDiff;
|
|
|
|
nsRect r2;
|
|
|
|
r2.IntersectRect(rectFullWidth, aContainedRect);
|
|
|
|
|
|
|
|
nsRegion result;
|
|
|
|
result.Or(r1, r2);
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2011-02-24 14:55:23 -08:00
|
|
|
nsRect
|
|
|
|
nsLayoutUtils::MatrixTransformRectOut(const nsRect &aBounds,
|
2011-07-22 15:28:51 -07:00
|
|
|
const gfx3DMatrix &aMatrix, float aFactor)
|
2011-02-24 14:55:23 -08:00
|
|
|
{
|
|
|
|
nsRect outside = aBounds;
|
|
|
|
outside.ScaleRoundOut(1/aFactor);
|
|
|
|
gfxRect image = aMatrix.TransformBounds(gfxRect(outside.x,
|
|
|
|
outside.y,
|
|
|
|
outside.width,
|
|
|
|
outside.height));
|
|
|
|
return RoundGfxRectToAppRect(image, aFactor);
|
|
|
|
}
|
|
|
|
|
2008-09-13 02:42:11 -07:00
|
|
|
nsRect
|
|
|
|
nsLayoutUtils::MatrixTransformRect(const nsRect &aBounds,
|
2011-07-22 15:28:51 -07:00
|
|
|
const gfx3DMatrix &aMatrix, float aFactor)
|
2008-09-13 02:42:11 -07:00
|
|
|
{
|
2011-02-24 14:55:23 -08:00
|
|
|
gfxRect image = aMatrix.TransformBounds(gfxRect(NSAppUnitsToDoublePixels(aBounds.x, aFactor),
|
|
|
|
NSAppUnitsToDoublePixels(aBounds.y, aFactor),
|
|
|
|
NSAppUnitsToDoublePixels(aBounds.width, aFactor),
|
|
|
|
NSAppUnitsToDoublePixels(aBounds.height, aFactor)));
|
2010-04-27 09:15:01 -07:00
|
|
|
|
2008-09-13 02:42:11 -07:00
|
|
|
return RoundGfxRectToAppRect(image, aFactor);
|
|
|
|
}
|
|
|
|
|
|
|
|
nsPoint
|
|
|
|
nsLayoutUtils::MatrixTransformPoint(const nsPoint &aPoint,
|
2011-07-22 15:28:51 -07:00
|
|
|
const gfx3DMatrix &aMatrix, float aFactor)
|
2008-09-13 02:42:11 -07:00
|
|
|
{
|
|
|
|
gfxPoint image = aMatrix.Transform(gfxPoint(NSAppUnitsToFloatPixels(aPoint.x, aFactor),
|
|
|
|
NSAppUnitsToFloatPixels(aPoint.y, aFactor)));
|
|
|
|
return nsPoint(NSFloatPixelsToAppUnits(float(image.x), aFactor),
|
|
|
|
NSFloatPixelsToAppUnits(float(image.y), aFactor));
|
|
|
|
}
|
|
|
|
|
2012-01-18 07:41:35 -08:00
|
|
|
gfx3DMatrix
|
2012-09-12 17:32:53 -07:00
|
|
|
nsLayoutUtils::GetTransformToAncestor(nsIFrame *aFrame, const nsIFrame *aAncestor)
|
2008-09-13 02:42:11 -07:00
|
|
|
{
|
2011-12-27 19:24:18 -08:00
|
|
|
nsIFrame* parent;
|
|
|
|
gfx3DMatrix ctm = aFrame->GetTransformMatrix(aAncestor, &parent);
|
|
|
|
while (parent && parent != aAncestor) {
|
2012-02-08 11:36:16 -08:00
|
|
|
if (!parent->Preserves3DChildren()) {
|
|
|
|
ctm.ProjectTo2D();
|
|
|
|
}
|
2011-12-27 19:24:18 -08:00
|
|
|
ctm = ctm * parent->GetTransformMatrix(aAncestor, &parent);
|
2011-05-09 01:40:09 -07:00
|
|
|
}
|
2011-12-27 19:24:18 -08:00
|
|
|
return ctm;
|
|
|
|
}
|
2011-08-02 20:04:21 -07:00
|
|
|
|
2011-12-27 19:24:18 -08:00
|
|
|
static gfxPoint
|
|
|
|
TransformGfxPointFromAncestor(nsIFrame *aFrame,
|
|
|
|
const gfxPoint &aPoint,
|
|
|
|
nsIFrame *aAncestor)
|
|
|
|
{
|
2012-01-18 07:41:35 -08:00
|
|
|
gfx3DMatrix ctm = nsLayoutUtils::GetTransformToAncestor(aFrame, aAncestor);
|
2011-12-27 19:24:18 -08:00
|
|
|
return ctm.Inverse().ProjectPoint(aPoint);
|
2008-09-13 02:42:11 -07:00
|
|
|
}
|
|
|
|
|
2011-08-02 20:04:21 -07:00
|
|
|
static gfxRect
|
2011-12-27 19:24:18 -08:00
|
|
|
TransformGfxRectFromAncestor(nsIFrame *aFrame,
|
|
|
|
const gfxRect &aRect,
|
2012-09-12 17:32:53 -07:00
|
|
|
const nsIFrame *aAncestor)
|
2008-09-13 02:42:11 -07:00
|
|
|
{
|
2012-01-18 07:41:35 -08:00
|
|
|
gfx3DMatrix ctm = nsLayoutUtils::GetTransformToAncestor(aFrame, aAncestor);
|
2011-12-27 19:24:18 -08:00
|
|
|
return ctm.Inverse().ProjectRectBounds(aRect);
|
|
|
|
}
|
2011-12-27 20:34:08 -08:00
|
|
|
|
2011-12-27 19:24:18 -08:00
|
|
|
static gfxRect
|
|
|
|
TransformGfxRectToAncestor(nsIFrame *aFrame,
|
|
|
|
const gfxRect &aRect,
|
|
|
|
nsIFrame *aAncestor)
|
|
|
|
{
|
2012-01-18 07:41:35 -08:00
|
|
|
gfx3DMatrix ctm = nsLayoutUtils::GetTransformToAncestor(aFrame, aAncestor);
|
2012-01-22 17:07:37 -08:00
|
|
|
return ctm.TransformBounds(aRect);
|
2011-08-02 20:04:21 -07:00
|
|
|
}
|
2008-09-13 02:42:11 -07:00
|
|
|
|
2011-08-02 20:04:21 -07:00
|
|
|
nsPoint
|
2011-12-27 19:24:18 -08:00
|
|
|
nsLayoutUtils::TransformRootPointToFrame(nsIFrame *aFrame,
|
|
|
|
const nsPoint &aPoint)
|
2011-08-02 20:04:21 -07:00
|
|
|
{
|
|
|
|
float factor = aFrame->PresContext()->AppUnitsPerDevPixel();
|
|
|
|
gfxPoint result(NSAppUnitsToFloatPixels(aPoint.x, factor),
|
|
|
|
NSAppUnitsToFloatPixels(aPoint.y, factor));
|
|
|
|
|
2012-07-30 07:20:58 -07:00
|
|
|
result = TransformGfxPointFromAncestor(aFrame, result, nullptr);
|
2011-08-02 20:04:21 -07:00
|
|
|
|
|
|
|
return nsPoint(NSFloatPixelsToAppUnits(float(result.x), factor),
|
|
|
|
NSFloatPixelsToAppUnits(float(result.y), factor));
|
|
|
|
}
|
2011-07-22 15:28:51 -07:00
|
|
|
|
2011-08-02 20:04:21 -07:00
|
|
|
nsRect
|
2011-12-27 19:24:18 -08:00
|
|
|
nsLayoutUtils::TransformAncestorRectToFrame(nsIFrame* aFrame,
|
|
|
|
const nsRect &aRect,
|
2012-09-12 17:32:53 -07:00
|
|
|
const nsIFrame* aAncestor)
|
2011-08-02 20:04:21 -07:00
|
|
|
{
|
|
|
|
float factor = aFrame->PresContext()->AppUnitsPerDevPixel();
|
|
|
|
gfxRect result(NSAppUnitsToFloatPixels(aRect.x, factor),
|
|
|
|
NSAppUnitsToFloatPixels(aRect.y, factor),
|
|
|
|
NSAppUnitsToFloatPixels(aRect.width, factor),
|
|
|
|
NSAppUnitsToFloatPixels(aRect.height, factor));
|
|
|
|
|
2011-12-27 19:24:18 -08:00
|
|
|
result = TransformGfxRectFromAncestor(aFrame, result, aAncestor);
|
2011-08-02 20:04:21 -07:00
|
|
|
|
|
|
|
return nsRect(NSFloatPixelsToAppUnits(float(result.x), factor),
|
|
|
|
NSFloatPixelsToAppUnits(float(result.y), factor),
|
|
|
|
NSFloatPixelsToAppUnits(float(result.width), factor),
|
|
|
|
NSFloatPixelsToAppUnits(float(result.height), factor));
|
2008-09-13 02:42:11 -07:00
|
|
|
}
|
|
|
|
|
2011-12-27 19:24:18 -08:00
|
|
|
nsRect
|
|
|
|
nsLayoutUtils::TransformFrameRectToAncestor(nsIFrame* aFrame,
|
|
|
|
const nsRect& aRect,
|
|
|
|
nsIFrame* aAncestor)
|
|
|
|
{
|
|
|
|
float factor = aFrame->PresContext()->AppUnitsPerDevPixel();
|
|
|
|
gfxRect result(NSAppUnitsToFloatPixels(aRect.x, factor),
|
|
|
|
NSAppUnitsToFloatPixels(aRect.y, factor),
|
|
|
|
NSAppUnitsToFloatPixels(aRect.width, factor),
|
|
|
|
NSAppUnitsToFloatPixels(aRect.height, factor));
|
|
|
|
|
|
|
|
result = TransformGfxRectToAncestor(aFrame, result, aAncestor);
|
|
|
|
|
|
|
|
return nsRect(NSFloatPixelsToAppUnits(float(result.x), factor),
|
|
|
|
NSFloatPixelsToAppUnits(float(result.y), factor),
|
|
|
|
NSFloatPixelsToAppUnits(float(result.width), factor),
|
|
|
|
NSFloatPixelsToAppUnits(float(result.height), factor));
|
|
|
|
}
|
|
|
|
|
2009-01-14 19:27:09 -08:00
|
|
|
static nsIntPoint GetWidgetOffset(nsIWidget* aWidget, nsIWidget*& aRootWidget) {
|
|
|
|
nsIntPoint offset(0, 0);
|
2007-07-23 09:44:34 -07:00
|
|
|
nsIWidget* parent = aWidget->GetParent();
|
|
|
|
while (parent) {
|
2009-01-14 19:27:09 -08:00
|
|
|
nsIntRect bounds;
|
2007-07-23 09:44:34 -07:00
|
|
|
aWidget->GetBounds(bounds);
|
|
|
|
offset += bounds.TopLeft();
|
|
|
|
aWidget = parent;
|
|
|
|
parent = aWidget->GetParent();
|
|
|
|
}
|
|
|
|
aRootWidget = aWidget;
|
|
|
|
return offset;
|
|
|
|
}
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
nsPoint
|
2010-04-27 09:15:01 -07:00
|
|
|
nsLayoutUtils::TranslateWidgetToView(nsPresContext* aPresContext,
|
2007-03-22 10:30:00 -07:00
|
|
|
nsIWidget* aWidget, nsIntPoint aPt,
|
|
|
|
nsIView* aView)
|
|
|
|
{
|
2007-07-23 09:44:34 -07:00
|
|
|
nsPoint viewOffset;
|
|
|
|
nsIWidget* viewWidget = aView->GetNearestWidget(&viewOffset);
|
2010-08-18 18:16:58 -07:00
|
|
|
if (!viewWidget) {
|
|
|
|
return nsPoint(NS_UNCONSTRAINEDSIZE, NS_UNCONSTRAINEDSIZE);
|
|
|
|
}
|
2007-07-23 09:44:34 -07:00
|
|
|
|
|
|
|
nsIWidget* fromRoot;
|
2009-01-14 19:27:09 -08:00
|
|
|
nsIntPoint fromOffset = GetWidgetOffset(aWidget, fromRoot);
|
2007-07-23 09:44:34 -07:00
|
|
|
nsIWidget* toRoot;
|
2009-01-14 19:27:09 -08:00
|
|
|
nsIntPoint toOffset = GetWidgetOffset(viewWidget, toRoot);
|
2007-07-23 09:44:34 -07:00
|
|
|
|
|
|
|
nsIntPoint widgetPoint;
|
|
|
|
if (fromRoot == toRoot) {
|
|
|
|
widgetPoint = aPt + fromOffset - toOffset;
|
|
|
|
} else {
|
2009-02-18 16:11:49 -08:00
|
|
|
nsIntPoint screenPoint = aWidget->WidgetToScreenOffset();
|
|
|
|
widgetPoint = aPt + screenPoint - viewWidget->WidgetToScreenOffset();
|
2007-07-23 09:44:34 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
nsPoint widgetAppUnits(aPresContext->DevPixelsToAppUnits(widgetPoint.x),
|
|
|
|
aPresContext->DevPixelsToAppUnits(widgetPoint.y));
|
|
|
|
return widgetAppUnits - viewOffset;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
// Combine aNewBreakType with aOrigBreakType, but limit the break types
|
|
|
|
// to NS_STYLE_CLEAR_LEFT, RIGHT, LEFT_AND_RIGHT.
|
2012-08-22 08:56:38 -07:00
|
|
|
uint8_t
|
|
|
|
nsLayoutUtils::CombineBreakType(uint8_t aOrigBreakType,
|
|
|
|
uint8_t aNewBreakType)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2012-08-22 08:56:38 -07:00
|
|
|
uint8_t breakType = aOrigBreakType;
|
2007-03-22 10:30:00 -07:00
|
|
|
switch(breakType) {
|
|
|
|
case NS_STYLE_CLEAR_LEFT:
|
|
|
|
if ((NS_STYLE_CLEAR_RIGHT == aNewBreakType) ||
|
|
|
|
(NS_STYLE_CLEAR_LEFT_AND_RIGHT == aNewBreakType)) {
|
|
|
|
breakType = NS_STYLE_CLEAR_LEFT_AND_RIGHT;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case NS_STYLE_CLEAR_RIGHT:
|
|
|
|
if ((NS_STYLE_CLEAR_LEFT == aNewBreakType) ||
|
|
|
|
(NS_STYLE_CLEAR_LEFT_AND_RIGHT == aNewBreakType)) {
|
|
|
|
breakType = NS_STYLE_CLEAR_LEFT_AND_RIGHT;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case NS_STYLE_CLEAR_NONE:
|
|
|
|
if ((NS_STYLE_CLEAR_LEFT == aNewBreakType) ||
|
|
|
|
(NS_STYLE_CLEAR_RIGHT == aNewBreakType) ||
|
|
|
|
(NS_STYLE_CLEAR_LEFT_AND_RIGHT == aNewBreakType)) {
|
|
|
|
breakType = aNewBreakType;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return breakType;
|
|
|
|
}
|
|
|
|
|
2011-11-16 19:44:16 -08:00
|
|
|
#ifdef MOZ_DUMP_PAINTING
|
2007-03-22 10:30:00 -07:00
|
|
|
#include <stdio.h>
|
|
|
|
|
2012-04-09 10:44:32 -07:00
|
|
|
static bool gDumpEventList = false;
|
2012-03-01 00:26:09 -08:00
|
|
|
int gPaintCount = 0;
|
2007-03-22 10:30:00 -07:00
|
|
|
#endif
|
|
|
|
|
2011-01-13 09:45:14 -08:00
|
|
|
nsresult
|
|
|
|
nsLayoutUtils::GetRemoteContentIds(nsIFrame* aFrame,
|
|
|
|
const nsRect& aTarget,
|
|
|
|
nsTArray<ViewID> &aOutIDs,
|
2011-09-28 23:19:26 -07:00
|
|
|
bool aIgnoreRootScrollFrame)
|
2011-01-13 09:45:14 -08:00
|
|
|
{
|
|
|
|
nsDisplayListBuilder builder(aFrame, nsDisplayListBuilder::EVENT_DELIVERY,
|
2011-10-17 07:59:28 -07:00
|
|
|
false);
|
2011-01-13 09:45:14 -08:00
|
|
|
nsDisplayList list;
|
|
|
|
|
|
|
|
if (aIgnoreRootScrollFrame) {
|
2012-04-09 10:44:32 -07:00
|
|
|
nsIFrame* rootScrollFrame =
|
|
|
|
aFrame->PresContext()->PresShell()->GetRootScrollFrame();
|
2011-01-13 09:45:14 -08:00
|
|
|
if (rootScrollFrame) {
|
|
|
|
builder.SetIgnoreScrollFrame(rootScrollFrame);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
builder.EnterPresShell(aFrame, aTarget);
|
|
|
|
|
|
|
|
nsresult rv =
|
|
|
|
aFrame->BuildDisplayListForStackingContext(&builder, aTarget, &list);
|
|
|
|
|
|
|
|
builder.LeavePresShell(aFrame, aTarget);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
2011-09-08 14:29:54 -07:00
|
|
|
nsAutoTArray<nsIFrame*,8> outFrames;
|
2011-01-13 09:45:14 -08:00
|
|
|
nsDisplayItem::HitTestState hitTestState(&aOutIDs);
|
|
|
|
list.HitTest(&builder, aTarget, &hitTestState, &outFrames);
|
|
|
|
list.DeleteAll();
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
nsIFrame*
|
2007-08-29 13:38:44 -07:00
|
|
|
nsLayoutUtils::GetFrameForPoint(nsIFrame* aFrame, nsPoint aPt,
|
2011-09-28 23:19:26 -07:00
|
|
|
bool aShouldIgnoreSuppression,
|
|
|
|
bool aIgnoreRootScrollFrame)
|
2010-04-07 17:31:26 -07:00
|
|
|
{
|
2012-04-16 11:37:59 -07:00
|
|
|
SAMPLE_LABEL("nsLayoutUtils", "GetFrameForPoint");
|
2010-04-07 17:31:26 -07:00
|
|
|
nsresult rv;
|
2011-09-08 14:29:54 -07:00
|
|
|
nsAutoTArray<nsIFrame*,8> outFrames;
|
2010-04-07 17:31:26 -07:00
|
|
|
rv = GetFramesForArea(aFrame, nsRect(aPt, nsSize(1, 1)), outFrames,
|
|
|
|
aShouldIgnoreSuppression, aIgnoreRootScrollFrame);
|
2012-07-30 07:20:58 -07:00
|
|
|
NS_ENSURE_SUCCESS(rv, nullptr);
|
|
|
|
return outFrames.Length() ? outFrames.ElementAt(0) : nullptr;
|
2010-04-07 17:31:26 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
nsLayoutUtils::GetFramesForArea(nsIFrame* aFrame, const nsRect& aRect,
|
|
|
|
nsTArray<nsIFrame*> &aOutFrames,
|
2011-09-28 23:19:26 -07:00
|
|
|
bool aShouldIgnoreSuppression,
|
|
|
|
bool aIgnoreRootScrollFrame)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2012-04-16 11:37:59 -07:00
|
|
|
SAMPLE_LABEL("nsLayoutUtils","GetFramesForArea");
|
2010-11-08 01:06:14 -08:00
|
|
|
nsDisplayListBuilder builder(aFrame, nsDisplayListBuilder::EVENT_DELIVERY,
|
2011-10-17 07:59:28 -07:00
|
|
|
false);
|
2007-03-22 10:30:00 -07:00
|
|
|
nsDisplayList list;
|
2010-04-07 17:31:26 -07:00
|
|
|
nsRect target(aRect);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2010-04-07 17:31:26 -07:00
|
|
|
if (aShouldIgnoreSuppression) {
|
2007-08-29 13:38:44 -07:00
|
|
|
builder.IgnorePaintSuppression();
|
2010-04-07 17:31:26 -07:00
|
|
|
}
|
2008-10-27 13:16:23 -07:00
|
|
|
|
2008-11-28 11:53:33 -08:00
|
|
|
if (aIgnoreRootScrollFrame) {
|
2012-04-09 10:44:32 -07:00
|
|
|
nsIFrame* rootScrollFrame =
|
|
|
|
aFrame->PresContext()->PresShell()->GetRootScrollFrame();
|
2008-10-27 13:16:23 -07:00
|
|
|
if (rootScrollFrame) {
|
|
|
|
builder.SetIgnoreScrollFrame(rootScrollFrame);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
builder.EnterPresShell(aFrame, target);
|
|
|
|
|
|
|
|
nsresult rv =
|
|
|
|
aFrame->BuildDisplayListForStackingContext(&builder, target, &list);
|
|
|
|
|
|
|
|
builder.LeavePresShell(aFrame, target);
|
2010-04-07 17:31:26 -07:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2011-11-16 19:44:16 -08:00
|
|
|
#ifdef MOZ_DUMP_PAINTING
|
2007-03-22 10:30:00 -07:00
|
|
|
if (gDumpEventList) {
|
2012-04-09 10:44:32 -07:00
|
|
|
fprintf(stdout, "Event handling --- (%d,%d):\n", aRect.x, aRect.y);
|
|
|
|
nsFrame::PrintDisplayList(&builder, list);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
#endif
|
2009-08-20 14:52:48 -07:00
|
|
|
|
2008-01-03 18:08:29 -08:00
|
|
|
nsDisplayItem::HitTestState hitTestState;
|
2010-04-07 17:31:26 -07:00
|
|
|
list.HitTest(&builder, target, &hitTestState, &aOutFrames);
|
2007-03-22 10:30:00 -07:00
|
|
|
list.DeleteAll();
|
2010-04-07 17:31:26 -07:00
|
|
|
return NS_OK;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2008-04-08 06:06:12 -07:00
|
|
|
/**
|
|
|
|
* Remove all leaf display items that are not for descendants of
|
|
|
|
* aBuilder->GetReferenceFrame() from aList, and move all nsDisplayClip
|
|
|
|
* wrappers to their correct locations.
|
|
|
|
* @param aExtraPage the page we constructed aList for
|
|
|
|
* @param aY the Y-coordinate where aPage would be positioned relative
|
|
|
|
* to the main page (aBuilder->GetReferenceFrame()), considering only
|
|
|
|
* the content and ignoring page margins and dead space
|
|
|
|
* @param aList the list that is modified in-place
|
|
|
|
*/
|
|
|
|
static void
|
|
|
|
PruneDisplayListForExtraPage(nsDisplayListBuilder* aBuilder,
|
|
|
|
nsIFrame* aExtraPage, nscoord aY, nsDisplayList* aList)
|
|
|
|
{
|
|
|
|
nsDisplayList newList;
|
|
|
|
// The page which we're really constructing a display list for
|
2012-09-16 03:32:59 -07:00
|
|
|
nsIFrame* mainPage = aBuilder->RootReferenceFrame();
|
2008-04-08 06:06:12 -07:00
|
|
|
|
2011-10-17 07:59:28 -07:00
|
|
|
while (true) {
|
2008-04-08 06:06:12 -07:00
|
|
|
nsDisplayItem* i = aList->RemoveBottom();
|
|
|
|
if (!i)
|
|
|
|
break;
|
|
|
|
nsDisplayList* subList = i->GetList();
|
|
|
|
if (subList) {
|
|
|
|
PruneDisplayListForExtraPage(aBuilder, aExtraPage, aY, subList);
|
2010-09-09 08:21:46 -07:00
|
|
|
nsDisplayItem::Type type = i->GetType();
|
|
|
|
if (type == nsDisplayItem::TYPE_CLIP ||
|
|
|
|
type == nsDisplayItem::TYPE_CLIP_ROUNDED_RECT) {
|
2008-04-08 06:06:12 -07:00
|
|
|
// This might clip an element which should appear on the first
|
|
|
|
// page, and that element might be visible if this uses a 'clip'
|
|
|
|
// property with a negative top.
|
|
|
|
// The clip area needs to be moved because the frame geometry doesn't
|
|
|
|
// put page content frames for adjacent pages vertically adjacent,
|
2010-04-27 09:15:01 -07:00
|
|
|
// there are page margins and dead space between them in print
|
2008-04-08 06:06:12 -07:00
|
|
|
// preview, and in printing all pages are at (0,0)...
|
|
|
|
// XXX we have no way to test this right now that I know of;
|
|
|
|
// the 'clip' property requires an abs-pos element and we never
|
|
|
|
// paint abs-pos elements that start after the main page
|
|
|
|
// (bug 426909).
|
|
|
|
nsDisplayClip* clip = static_cast<nsDisplayClip*>(i);
|
|
|
|
clip->SetClipRect(clip->GetClipRect() + nsPoint(0, aY) -
|
|
|
|
aExtraPage->GetOffsetTo(mainPage));
|
|
|
|
}
|
|
|
|
newList.AppendToTop(i);
|
|
|
|
} else {
|
|
|
|
nsIFrame* f = i->GetUnderlyingFrame();
|
|
|
|
if (f && nsLayoutUtils::IsProperAncestorFrameCrossDoc(mainPage, f)) {
|
|
|
|
// This one is in the page we care about, keep it
|
|
|
|
newList.AppendToTop(i);
|
|
|
|
} else {
|
|
|
|
// We're throwing this away so call its destructor now. The memory
|
|
|
|
// is owned by aBuilder which destroys all items at once.
|
2009-01-16 13:32:09 -08:00
|
|
|
i->~nsDisplayItem();
|
2008-04-08 06:06:12 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
aList->AppendToTop(&newList);
|
|
|
|
}
|
|
|
|
|
|
|
|
static nsresult
|
|
|
|
BuildDisplayListForExtraPage(nsDisplayListBuilder* aBuilder,
|
|
|
|
nsIFrame* aPage, nscoord aY, nsDisplayList* aList)
|
|
|
|
{
|
|
|
|
nsDisplayList list;
|
|
|
|
// Pass an empty dirty rect since we're only interested in finding
|
|
|
|
// placeholders whose out-of-flows are in the page
|
|
|
|
// aBuilder->GetReferenceFrame(), and the paths to those placeholders
|
|
|
|
// have already been marked as NS_FRAME_FORCE_DISPLAY_LIST_DESCEND_INTO.
|
|
|
|
// Note that we should still do a prune step since we don't want to
|
|
|
|
// rely on dirty-rect checking for correctness.
|
|
|
|
nsresult rv = aPage->BuildDisplayListForStackingContext(aBuilder, nsRect(), &list);
|
|
|
|
if (NS_FAILED(rv))
|
|
|
|
return rv;
|
|
|
|
PruneDisplayListForExtraPage(aBuilder, aPage, aY, &list);
|
|
|
|
aList->AppendToTop(&list);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
static nsIFrame*
|
|
|
|
GetNextPage(nsIFrame* aPageContentFrame)
|
|
|
|
{
|
|
|
|
// XXX ugh
|
|
|
|
nsIFrame* pageFrame = aPageContentFrame->GetParent();
|
|
|
|
NS_ASSERTION(pageFrame->GetType() == nsGkAtoms::pageFrame,
|
|
|
|
"pageContentFrame has unexpected parent");
|
|
|
|
nsIFrame* nextPageFrame = pageFrame->GetNextSibling();
|
|
|
|
if (!nextPageFrame)
|
2012-07-30 07:20:58 -07:00
|
|
|
return nullptr;
|
2008-04-08 06:06:12 -07:00
|
|
|
NS_ASSERTION(nextPageFrame->GetType() == nsGkAtoms::pageFrame,
|
|
|
|
"pageFrame's sibling is not a page frame...");
|
2011-08-24 13:54:30 -07:00
|
|
|
nsIFrame* f = nextPageFrame->GetFirstPrincipalChild();
|
2008-04-08 06:06:12 -07:00
|
|
|
NS_ASSERTION(f, "pageFrame has no page content frame!");
|
|
|
|
NS_ASSERTION(f->GetType() == nsGkAtoms::pageContentFrame,
|
|
|
|
"pageFrame's child is not page content!");
|
|
|
|
return f;
|
|
|
|
}
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
nsresult
|
2011-04-07 18:04:40 -07:00
|
|
|
nsLayoutUtils::PaintFrame(nsRenderingContext* aRenderingContext, nsIFrame* aFrame,
|
2009-07-21 17:45:14 -07:00
|
|
|
const nsRegion& aDirtyRegion, nscolor aBackstop,
|
2012-08-22 08:56:38 -07:00
|
|
|
uint32_t aFlags)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2012-04-16 11:37:59 -07:00
|
|
|
SAMPLE_LABEL("nsLayoutUtils","PaintFrame");
|
2010-08-08 11:49:07 -07:00
|
|
|
if (aFlags & PAINT_WIDGET_LAYERS) {
|
|
|
|
nsIView* view = aFrame->GetView();
|
2010-08-21 17:55:55 -07:00
|
|
|
if (!(view && view->GetWidget() && GetDisplayRootFrame(aFrame) == aFrame)) {
|
|
|
|
aFlags &= ~PAINT_WIDGET_LAYERS;
|
|
|
|
NS_ASSERTION(aRenderingContext, "need a rendering context");
|
|
|
|
}
|
2010-08-08 11:49:07 -07:00
|
|
|
}
|
|
|
|
|
2010-07-15 14:07:51 -07:00
|
|
|
nsPresContext* presContext = aFrame->PresContext();
|
2010-07-15 14:07:52 -07:00
|
|
|
nsIPresShell* presShell = presContext->PresShell();
|
2010-07-15 14:07:51 -07:00
|
|
|
|
2011-03-15 16:20:19 -07:00
|
|
|
nsIFrame* rootScrollFrame = presShell->GetRootScrollFrame();
|
|
|
|
bool usingDisplayPort = false;
|
|
|
|
nsRect displayport;
|
|
|
|
if (rootScrollFrame) {
|
|
|
|
nsIContent* content = rootScrollFrame->GetContent();
|
|
|
|
if (content) {
|
|
|
|
usingDisplayPort = nsLayoutUtils::GetDisplayPort(content, &displayport);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-09-28 23:19:26 -07:00
|
|
|
bool ignoreViewportScrolling = presShell->IgnoringViewportScrolling();
|
2010-07-15 14:07:51 -07:00
|
|
|
nsRegion visibleRegion;
|
2010-09-03 13:10:46 -07:00
|
|
|
if (aFlags & PAINT_WIDGET_LAYERS) {
|
2010-07-15 14:07:51 -07:00
|
|
|
// This layer tree will be reused, so we'll need to calculate it
|
2010-09-03 13:10:46 -07:00
|
|
|
// for the whole "visible" area of the window
|
|
|
|
//
|
|
|
|
// |ignoreViewportScrolling| and |usingDisplayPort| are persistent
|
|
|
|
// document-rendering state. We rely on PresShell to flush
|
|
|
|
// retained layers as needed when that persistent state changes.
|
2011-03-15 16:20:19 -07:00
|
|
|
if (!usingDisplayPort) {
|
2010-10-06 21:25:47 -07:00
|
|
|
visibleRegion = aFrame->GetVisualOverflowRectRelativeToSelf();
|
2010-09-03 13:10:46 -07:00
|
|
|
} else {
|
2011-03-15 16:20:19 -07:00
|
|
|
visibleRegion = displayport;
|
2010-09-03 13:10:46 -07:00
|
|
|
}
|
2010-07-15 14:07:51 -07:00
|
|
|
} else {
|
|
|
|
visibleRegion = aDirtyRegion;
|
|
|
|
}
|
|
|
|
|
2010-08-19 20:49:16 -07:00
|
|
|
// If we're going to display something different from what we'd normally
|
|
|
|
// paint in a window then we will flush out any retained layer trees before
|
|
|
|
// *and after* we draw.
|
2011-09-28 23:19:26 -07:00
|
|
|
bool willFlushRetainedLayers = (aFlags & PAINT_HIDE_CARET) != 0;
|
2010-08-19 20:49:16 -07:00
|
|
|
|
2010-11-08 01:06:14 -08:00
|
|
|
nsDisplayListBuilder builder(aFrame, nsDisplayListBuilder::PAINTING,
|
|
|
|
!(aFlags & PAINT_HIDE_CARET));
|
2011-04-08 09:35:16 -07:00
|
|
|
if (usingDisplayPort) {
|
2011-05-09 01:40:09 -07:00
|
|
|
builder.SetDisplayPort(displayport);
|
2011-04-08 09:35:16 -07:00
|
|
|
}
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
nsDisplayList list;
|
2009-07-21 17:45:14 -07:00
|
|
|
if (aFlags & PAINT_IN_TRANSFORM) {
|
2011-10-17 07:59:28 -07:00
|
|
|
builder.SetInTransform(true);
|
2009-07-21 17:45:14 -07:00
|
|
|
}
|
2009-09-12 15:44:18 -07:00
|
|
|
if (aFlags & PAINT_SYNC_DECODE_IMAGES) {
|
2011-10-17 07:59:28 -07:00
|
|
|
builder.SetSyncDecodeImages(true);
|
2009-09-12 15:44:18 -07:00
|
|
|
}
|
2011-02-03 00:45:23 -08:00
|
|
|
if (aFlags & (PAINT_WIDGET_LAYERS | PAINT_TO_WINDOW)) {
|
2011-10-17 07:59:28 -07:00
|
|
|
builder.SetPaintingToWindow(true);
|
2010-05-12 17:56:08 -07:00
|
|
|
}
|
2010-09-01 13:44:48 -07:00
|
|
|
if (aFlags & PAINT_IGNORE_SUPPRESSION) {
|
|
|
|
builder.IgnorePaintSuppression();
|
2010-07-15 14:07:52 -07:00
|
|
|
}
|
|
|
|
nsRect canvasArea(nsPoint(0, 0), aFrame->GetSize());
|
2011-02-17 16:33:31 -08:00
|
|
|
|
|
|
|
#ifdef DEBUG
|
2010-09-03 13:10:46 -07:00
|
|
|
if (ignoreViewportScrolling) {
|
2011-02-17 16:33:31 -08:00
|
|
|
nsIDocument* doc = aFrame->GetContent() ?
|
2012-07-30 07:20:58 -07:00
|
|
|
aFrame->GetContent()->GetCurrentDoc() : nullptr;
|
2011-02-17 16:33:31 -08:00
|
|
|
NS_ASSERTION(!aFrame->GetParent() ||
|
|
|
|
(doc && doc->IsBeingUsedAsImage()),
|
|
|
|
"Only expecting ignoreViewportScrolling for root frames and "
|
|
|
|
"for image documents.");
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
if (ignoreViewportScrolling && !aFrame->GetParent()) {
|
2010-07-15 14:07:52 -07:00
|
|
|
nsIFrame* rootScrollFrame = presShell->GetRootScrollFrame();
|
|
|
|
if (rootScrollFrame) {
|
|
|
|
nsIScrollableFrame* rootScrollableFrame =
|
|
|
|
presShell->GetRootScrollFrameAsScrollable();
|
2010-09-03 13:10:46 -07:00
|
|
|
if (aFlags & PAINT_DOCUMENT_RELATIVE) {
|
|
|
|
// Make visibleRegion and aRenderingContext relative to the
|
|
|
|
// scrolled frame instead of the root frame.
|
|
|
|
nsPoint pos = rootScrollableFrame->GetScrollPosition();
|
|
|
|
visibleRegion.MoveBy(-pos);
|
2010-09-03 13:10:46 -07:00
|
|
|
if (aRenderingContext) {
|
2011-04-07 18:04:39 -07:00
|
|
|
aRenderingContext->Translate(pos);
|
2010-09-03 13:10:46 -07:00
|
|
|
}
|
2010-09-03 13:10:46 -07:00
|
|
|
}
|
2010-07-15 14:07:52 -07:00
|
|
|
builder.SetIgnoreScrollFrame(rootScrollFrame);
|
|
|
|
|
|
|
|
nsCanvasFrame* canvasFrame =
|
|
|
|
do_QueryFrame(rootScrollableFrame->GetScrolledFrame());
|
|
|
|
if (canvasFrame) {
|
|
|
|
// Use UnionRect here to ensure that areas where the scrollbars
|
|
|
|
// were are still filled with the background color.
|
|
|
|
canvasArea.UnionRect(canvasArea,
|
|
|
|
canvasFrame->CanvasArea() + builder.ToReferenceFrame(canvasFrame));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2009-07-04 02:30:59 -07:00
|
|
|
nsresult rv;
|
|
|
|
|
2010-07-15 14:07:51 -07:00
|
|
|
nsRect dirtyRect = visibleRegion.GetBounds();
|
2007-03-22 10:30:00 -07:00
|
|
|
builder.EnterPresShell(aFrame, dirtyRect);
|
2012-04-16 11:37:59 -07:00
|
|
|
{
|
|
|
|
SAMPLE_LABEL("nsLayoutUtils","PaintFrame::BuildDisplayList");
|
2009-07-04 02:30:59 -07:00
|
|
|
rv = aFrame->BuildDisplayListForStackingContext(&builder, dirtyRect, &list);
|
2012-04-16 11:37:59 -07:00
|
|
|
}
|
2011-09-28 23:19:26 -07:00
|
|
|
const bool paintAllContinuations = aFlags & PAINT_ALL_CONTINUATIONS;
|
2010-08-13 06:32:04 -07:00
|
|
|
NS_ASSERTION(!paintAllContinuations || !aFrame->GetPrevContinuation(),
|
|
|
|
"If painting all continuations, the frame must be "
|
|
|
|
"first-continuation");
|
|
|
|
|
2010-08-08 11:49:07 -07:00
|
|
|
nsIAtom* frameType = aFrame->GetType();
|
2010-08-13 06:32:04 -07:00
|
|
|
if (NS_SUCCEEDED(rv) && !paintAllContinuations &&
|
|
|
|
frameType == nsGkAtoms::pageContentFrame) {
|
2010-08-08 11:49:07 -07:00
|
|
|
NS_ASSERTION(!(aFlags & PAINT_WIDGET_LAYERS),
|
|
|
|
"shouldn't be painting with widget layers for page content frames");
|
2009-02-15 10:14:21 -08:00
|
|
|
// We may need to paint out-of-flow frames whose placeholders are
|
|
|
|
// on other pages. Add those pages to our display list. Note that
|
|
|
|
// out-of-flow frames can't be placed after their placeholders so
|
|
|
|
// we don't have to process earlier pages. The display lists for
|
|
|
|
// these extra pages are pruned so that only display items for the
|
|
|
|
// page we currently care about (which we would have reached by
|
|
|
|
// following placeholders to their out-of-flows) end up on the list.
|
|
|
|
nsIFrame* page = aFrame;
|
|
|
|
nscoord y = aFrame->GetSize().height;
|
2012-07-30 07:20:58 -07:00
|
|
|
while ((page = GetNextPage(page)) != nullptr) {
|
2012-04-16 11:37:59 -07:00
|
|
|
SAMPLE_LABEL("nsLayoutUtils","PaintFrame::BuildDisplayListForExtraPage");
|
2009-02-15 10:14:21 -08:00
|
|
|
rv = BuildDisplayListForExtraPage(&builder, page, y, &list);
|
|
|
|
if (NS_FAILED(rv))
|
|
|
|
break;
|
|
|
|
y += page->GetSize().height;
|
2008-04-08 06:06:12 -07:00
|
|
|
}
|
2008-01-29 20:53:46 -08:00
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2010-08-13 06:32:04 -07:00
|
|
|
if (paintAllContinuations) {
|
|
|
|
nsIFrame* currentFrame = aFrame;
|
|
|
|
while (NS_SUCCEEDED(rv) &&
|
2012-07-30 07:20:58 -07:00
|
|
|
(currentFrame = currentFrame->GetNextContinuation()) != nullptr) {
|
2012-04-16 11:37:59 -07:00
|
|
|
SAMPLE_LABEL("nsLayoutUtils","PaintFrame::ContinuationsBuildDisplayList");
|
2010-08-13 06:32:04 -07:00
|
|
|
nsRect frameDirty = dirtyRect - builder.ToReferenceFrame(currentFrame);
|
|
|
|
rv = currentFrame->BuildDisplayListForStackingContext(&builder,
|
|
|
|
frameDirty, &list);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-07-29 15:10:50 -07:00
|
|
|
// For the viewport frame in print preview/page layout we want to paint
|
|
|
|
// the grey background behind the page, not the canvas color.
|
2010-08-08 11:49:07 -07:00
|
|
|
if (frameType == nsGkAtoms::viewportFrame &&
|
|
|
|
nsLayoutUtils::NeedsPrintPreviewBackground(presContext)) {
|
2009-07-29 15:10:50 -07:00
|
|
|
nsRect bounds = nsRect(builder.ToReferenceFrame(aFrame),
|
|
|
|
aFrame->GetSize());
|
2010-08-08 11:49:07 -07:00
|
|
|
rv = presShell->AddPrintPreviewBackgroundItem(builder, list, aFrame, bounds);
|
2009-07-29 15:10:50 -07:00
|
|
|
} else if (frameType != nsGkAtoms::pageFrame) {
|
|
|
|
// For printing, this function is first called on an nsPageFrame, which
|
|
|
|
// creates a display list with a PageContent item. The PageContent item's
|
|
|
|
// paint function calls this function on the nsPageFrame's child which is
|
|
|
|
// an nsPageContentFrame. We only want to add the canvas background color
|
|
|
|
// item once, for the nsPageContentFrame.
|
|
|
|
|
2010-07-15 14:07:53 -07:00
|
|
|
// Add the canvas background color to the bottom of the list. This
|
|
|
|
// happens after we've built the list so that AddCanvasBackgroundColorItem
|
|
|
|
// can monkey with the contents if necessary.
|
2011-10-18 12:28:20 -07:00
|
|
|
canvasArea.IntersectRect(canvasArea, visibleRegion.GetBounds());
|
2010-07-15 14:07:52 -07:00
|
|
|
rv = presShell->AddCanvasBackgroundColorItem(
|
|
|
|
builder, list, aFrame, canvasArea, aBackstop);
|
2010-08-08 11:49:07 -07:00
|
|
|
|
|
|
|
// If the passed in backstop color makes us draw something different from
|
|
|
|
// normal, we need to flush layers.
|
2010-09-03 13:10:46 -07:00
|
|
|
if ((aFlags & PAINT_WIDGET_LAYERS) && !willFlushRetainedLayers) {
|
2010-08-08 11:49:07 -07:00
|
|
|
nsIView* view = aFrame->GetView();
|
|
|
|
if (view) {
|
|
|
|
nscolor backstop = presShell->ComputeBackstopColor(view);
|
|
|
|
// The PresShell's canvas background color doesn't get updated until
|
|
|
|
// EnterPresShell, so this check has to be done after that.
|
|
|
|
nscolor canvasColor = presShell->GetCanvasBackground();
|
|
|
|
if (NS_ComposeColors(aBackstop, canvasColor) !=
|
|
|
|
NS_ComposeColors(backstop, canvasColor)) {
|
2011-10-17 07:59:28 -07:00
|
|
|
willFlushRetainedLayers = true;
|
2010-08-08 11:49:07 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2009-07-04 02:30:59 -07:00
|
|
|
}
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
builder.LeavePresShell(aFrame, dirtyRect);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
2010-09-01 13:44:48 -07:00
|
|
|
if (builder.GetHadToIgnorePaintSuppression()) {
|
2011-10-17 07:59:28 -07:00
|
|
|
willFlushRetainedLayers = true;
|
2010-09-01 13:44:48 -07:00
|
|
|
}
|
|
|
|
|
2011-11-16 19:44:16 -08:00
|
|
|
#ifdef MOZ_DUMP_PAINTING
|
2012-03-28 11:10:28 -07:00
|
|
|
if (gfxUtils::sDumpPaintList || gfxUtils::sDumpPainting) {
|
2012-03-01 00:26:09 -08:00
|
|
|
if (gfxUtils::sDumpPaintingToFile) {
|
|
|
|
nsCString string("dump-");
|
|
|
|
string.AppendInt(gPaintCount);
|
|
|
|
string.Append(".html");
|
|
|
|
gfxUtils::sDumpPaintFile = fopen(string.BeginReading(), "w");
|
|
|
|
} else {
|
|
|
|
gfxUtils::sDumpPaintFile = stdout;
|
|
|
|
}
|
2012-08-07 10:57:26 -07:00
|
|
|
if (gfxUtils::sDumpPaintingToFile) {
|
|
|
|
fprintf(gfxUtils::sDumpPaintFile, "<html><head><script>var array = {}; function ViewImage(index) { window.location = array[index]; }</script></head><body>");
|
|
|
|
}
|
2012-03-01 00:26:09 -08:00
|
|
|
fprintf(gfxUtils::sDumpPaintFile, "Painting --- before optimization (dirty %d,%d,%d,%d):\n",
|
2007-03-22 10:30:00 -07:00
|
|
|
dirtyRect.x, dirtyRect.y, dirtyRect.width, dirtyRect.height);
|
2012-08-07 10:57:26 -07:00
|
|
|
nsFrame::PrintDisplayList(&builder, list, gfxUtils::sDumpPaintFile, gfxUtils::sDumpPaintingToFile);
|
2012-03-01 00:26:09 -08:00
|
|
|
if (gfxUtils::sDumpPaintingToFile) {
|
|
|
|
fprintf(gfxUtils::sDumpPaintFile, "<script>");
|
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
#endif
|
2009-08-20 14:52:48 -07:00
|
|
|
|
2010-08-27 16:15:08 -07:00
|
|
|
list.ComputeVisibilityForRoot(&builder, &visibleRegion);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2012-08-22 08:56:38 -07:00
|
|
|
uint32_t flags = nsDisplayList::PAINT_DEFAULT;
|
2010-03-01 00:03:49 -08:00
|
|
|
if (aFlags & PAINT_WIDGET_LAYERS) {
|
|
|
|
flags |= nsDisplayList::PAINT_USE_WIDGET_LAYERS;
|
2010-09-03 13:10:46 -07:00
|
|
|
if (willFlushRetainedLayers) {
|
|
|
|
// The caller wanted to paint from retained layers, but set up
|
|
|
|
// the paint in such a way that we can't use them. We're going
|
|
|
|
// to display something different from what we'd normally paint
|
|
|
|
// in a window, so make sure we flush out any retained layer
|
|
|
|
// trees before *and after* we draw. Callers should be fixed to
|
|
|
|
// not do this.
|
|
|
|
NS_WARNING("Flushing retained layers!");
|
2010-07-15 14:07:52 -07:00
|
|
|
flags |= nsDisplayList::PAINT_FLUSH_LAYERS;
|
2011-02-17 13:42:39 -08:00
|
|
|
} else if (!(aFlags & PAINT_DOCUMENT_RELATIVE)) {
|
2011-03-25 08:03:35 -07:00
|
|
|
nsIWidget *widget = aFrame->GetNearestWidget();
|
|
|
|
if (widget) {
|
2011-02-17 13:42:39 -08:00
|
|
|
builder.SetFinalTransparentRegion(visibleRegion);
|
|
|
|
// If we're finished building display list items for painting of the outermost
|
|
|
|
// pres shell, notify the widget about any toolbars we've encountered.
|
2011-03-25 08:03:35 -07:00
|
|
|
widget->UpdateThemeGeometries(builder.GetThemeGeometries());
|
2011-02-17 13:42:39 -08:00
|
|
|
}
|
2010-07-15 14:07:52 -07:00
|
|
|
}
|
2010-03-01 00:03:49 -08:00
|
|
|
}
|
2011-01-19 00:27:54 -08:00
|
|
|
if (aFlags & PAINT_EXISTING_TRANSACTION) {
|
|
|
|
flags |= nsDisplayList::PAINT_EXISTING_TRANSACTION;
|
|
|
|
}
|
2012-08-13 03:10:10 -07:00
|
|
|
if (aFlags & PAINT_NO_COMPOSITE) {
|
|
|
|
flags |= nsDisplayList::PAINT_NO_COMPOSITE;
|
|
|
|
}
|
2010-07-15 14:07:51 -07:00
|
|
|
|
2010-03-10 12:55:05 -08:00
|
|
|
list.PaintRoot(&builder, aRenderingContext, flags);
|
2010-07-15 14:07:51 -07:00
|
|
|
|
2011-05-13 09:40:46 -07:00
|
|
|
// Update the widget's opaque region information. This sets
|
2011-02-17 13:42:39 -08:00
|
|
|
// glass boundaries on Windows.
|
|
|
|
if ((aFlags & PAINT_WIDGET_LAYERS) &&
|
|
|
|
!willFlushRetainedLayers &&
|
|
|
|
!(aFlags & PAINT_DOCUMENT_RELATIVE)) {
|
2011-03-25 08:03:35 -07:00
|
|
|
nsIWidget *widget = aFrame->GetNearestWidget();
|
|
|
|
if (widget) {
|
2011-05-13 09:40:46 -07:00
|
|
|
nsRegion excludedRegion = builder.GetExcludedGlassRegion();
|
|
|
|
excludedRegion.Sub(excludedRegion, visibleRegion);
|
|
|
|
nsIntRegion windowRegion(excludedRegion.ToNearestPixels(presContext->AppUnitsPerDevPixel()));
|
|
|
|
widget->UpdateOpaqueRegion(windowRegion);
|
2011-02-17 13:42:39 -08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-11-16 19:44:16 -08:00
|
|
|
#ifdef MOZ_DUMP_PAINTING
|
2012-03-28 11:10:28 -07:00
|
|
|
if (gfxUtils::sDumpPaintList || gfxUtils::sDumpPainting) {
|
2012-08-07 10:57:26 -07:00
|
|
|
if (gfxUtils::sDumpPaintingToFile) {
|
|
|
|
fprintf(gfxUtils::sDumpPaintFile, "</script>");
|
|
|
|
}
|
|
|
|
fprintf(gfxUtils::sDumpPaintFile, "Painting --- after optimization:\n");
|
|
|
|
nsFrame::PrintDisplayList(&builder, list, gfxUtils::sDumpPaintFile, gfxUtils::sDumpPaintingToFile);
|
2011-01-03 19:56:57 -08:00
|
|
|
|
2012-03-01 00:26:09 -08:00
|
|
|
fprintf(gfxUtils::sDumpPaintFile, "Painting --- retained layer tree:\n");
|
2012-07-17 10:03:51 -07:00
|
|
|
nsIWidget* widget = aFrame->GetNearestWidget();
|
|
|
|
if (widget) {
|
|
|
|
nsRefPtr<LayerManager> layerManager = widget->GetLayerManager();
|
|
|
|
if (layerManager) {
|
2012-08-07 10:57:26 -07:00
|
|
|
FrameLayerBuilder::DumpRetainedLayerTree(layerManager, gfxUtils::sDumpPaintFile,
|
|
|
|
gfxUtils::sDumpPaintingToFile);
|
2012-07-17 10:03:51 -07:00
|
|
|
}
|
|
|
|
}
|
2012-03-01 00:26:09 -08:00
|
|
|
if (gfxUtils::sDumpPaintingToFile) {
|
2012-08-07 10:57:26 -07:00
|
|
|
fprintf(gfxUtils::sDumpPaintFile, "</body></html>");
|
2012-03-01 00:26:09 -08:00
|
|
|
fclose(gfxUtils::sDumpPaintFile);
|
|
|
|
}
|
|
|
|
gfxUtils::sDumpPaintFile = NULL;
|
|
|
|
gPaintCount++;
|
2010-07-15 14:07:51 -07:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
// Flush the list so we don't trigger the IsEmpty-on-destruction assertion
|
|
|
|
list.DeleteAll();
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2012-08-22 08:56:38 -07:00
|
|
|
int32_t
|
2007-03-22 10:30:00 -07:00
|
|
|
nsLayoutUtils::GetZIndex(nsIFrame* aFrame) {
|
2012-08-02 04:38:50 -07:00
|
|
|
if (!aFrame->IsPositioned())
|
2007-03-22 10:30:00 -07:00
|
|
|
return 0;
|
|
|
|
|
|
|
|
const nsStylePosition* position =
|
|
|
|
aFrame->GetStylePosition();
|
|
|
|
if (position->mZIndex.GetUnit() == eStyleUnit_Integer)
|
|
|
|
return position->mZIndex.GetIntValue();
|
|
|
|
|
|
|
|
// sort the auto and 0 elements together
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Uses a binary search for find where the cursor falls in the line of text
|
|
|
|
* It also keeps track of the part of the string that has already been measured
|
|
|
|
* so it doesn't have to keep measuring the same text over and over
|
|
|
|
*
|
2010-04-27 09:15:01 -07:00
|
|
|
* @param "aBaseWidth" contains the width in twips of the portion
|
2007-03-22 10:30:00 -07:00
|
|
|
* of the text that has already been measured, and aBaseInx contains
|
|
|
|
* the index of the text that has already been measured.
|
|
|
|
*
|
|
|
|
* @param aTextWidth returns the (in twips) the length of the text that falls
|
|
|
|
* before the cursor aIndex contains the index of the text where the cursor falls
|
|
|
|
*/
|
2011-09-28 23:19:26 -07:00
|
|
|
bool
|
2011-04-07 18:04:40 -07:00
|
|
|
nsLayoutUtils::BinarySearchForPosition(nsRenderingContext* aRendContext,
|
2007-03-22 10:30:00 -07:00
|
|
|
const PRUnichar* aText,
|
2012-08-22 08:56:38 -07:00
|
|
|
int32_t aBaseWidth,
|
|
|
|
int32_t aBaseInx,
|
|
|
|
int32_t aStartInx,
|
|
|
|
int32_t aEndInx,
|
|
|
|
int32_t aCursorPos,
|
|
|
|
int32_t& aIndex,
|
|
|
|
int32_t& aTextWidth)
|
|
|
|
{
|
|
|
|
int32_t range = aEndInx - aStartInx;
|
2007-03-22 10:30:00 -07:00
|
|
|
if ((range == 1) || (range == 2 && NS_IS_HIGH_SURROGATE(aText[aStartInx]))) {
|
|
|
|
aIndex = aStartInx + aBaseInx;
|
2011-04-07 18:04:40 -07:00
|
|
|
aTextWidth = aRendContext->GetWidth(aText, aIndex);
|
2011-10-17 07:59:28 -07:00
|
|
|
return true;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2012-08-22 08:56:38 -07:00
|
|
|
int32_t inx = aStartInx + (range / 2);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
// Make sure we don't leave a dangling low surrogate
|
|
|
|
if (NS_IS_HIGH_SURROGATE(aText[inx-1]))
|
|
|
|
inx++;
|
|
|
|
|
2012-08-22 08:56:38 -07:00
|
|
|
int32_t textWidth = aRendContext->GetWidth(aText, inx);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2012-08-22 08:56:38 -07:00
|
|
|
int32_t fullWidth = aBaseWidth + textWidth;
|
2007-03-22 10:30:00 -07:00
|
|
|
if (fullWidth == aCursorPos) {
|
|
|
|
aTextWidth = textWidth;
|
|
|
|
aIndex = inx;
|
2011-10-17 07:59:28 -07:00
|
|
|
return true;
|
2007-03-22 10:30:00 -07:00
|
|
|
} else if (aCursorPos < fullWidth) {
|
|
|
|
aTextWidth = aBaseWidth;
|
|
|
|
if (BinarySearchForPosition(aRendContext, aText, aBaseWidth, aBaseInx, aStartInx, inx, aCursorPos, aIndex, aTextWidth)) {
|
2011-10-17 07:59:28 -07:00
|
|
|
return true;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
aTextWidth = fullWidth;
|
|
|
|
if (BinarySearchForPosition(aRendContext, aText, aBaseWidth, aBaseInx, inx, aEndInx, aCursorPos, aIndex, aTextWidth)) {
|
2011-10-17 07:59:28 -07:00
|
|
|
return true;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
}
|
2011-10-17 07:59:28 -07:00
|
|
|
return false;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2008-02-27 01:26:15 -08:00
|
|
|
static void
|
2008-09-10 17:24:16 -07:00
|
|
|
AddBoxesForFrame(nsIFrame* aFrame,
|
|
|
|
nsLayoutUtils::BoxCallback* aCallback)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2009-10-29 14:17:56 -07:00
|
|
|
nsIAtom* pseudoType = aFrame->GetStyleContext()->GetPseudo();
|
2008-02-27 01:26:15 -08:00
|
|
|
|
|
|
|
if (pseudoType == nsCSSAnonBoxes::tableOuter) {
|
2011-08-24 13:54:30 -07:00
|
|
|
AddBoxesForFrame(aFrame->GetFirstPrincipalChild(), aCallback);
|
|
|
|
nsIFrame* kid = aFrame->GetFirstChild(nsIFrame::kCaptionList);
|
2008-02-27 01:26:15 -08:00
|
|
|
if (kid) {
|
2008-09-10 17:24:16 -07:00
|
|
|
AddBoxesForFrame(kid, aCallback);
|
2008-02-27 01:26:15 -08:00
|
|
|
}
|
|
|
|
} else if (pseudoType == nsCSSAnonBoxes::mozAnonymousBlock ||
|
|
|
|
pseudoType == nsCSSAnonBoxes::mozAnonymousPositionedBlock ||
|
|
|
|
pseudoType == nsCSSAnonBoxes::mozMathMLAnonymousBlock ||
|
|
|
|
pseudoType == nsCSSAnonBoxes::mozXULAnonymousBlock) {
|
2011-08-24 13:54:30 -07:00
|
|
|
for (nsIFrame* kid = aFrame->GetFirstPrincipalChild(); kid; kid = kid->GetNextSibling()) {
|
2008-09-10 17:24:16 -07:00
|
|
|
AddBoxesForFrame(kid, aCallback);
|
2008-02-27 01:26:15 -08:00
|
|
|
}
|
|
|
|
} else {
|
2008-09-10 17:24:16 -07:00
|
|
|
aCallback->AddBox(aFrame);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsLayoutUtils::GetAllInFlowBoxes(nsIFrame* aFrame, BoxCallback* aCallback)
|
|
|
|
{
|
|
|
|
while (aFrame) {
|
|
|
|
AddBoxesForFrame(aFrame, aCallback);
|
|
|
|
aFrame = nsLayoutUtils::GetNextContinuationOrSpecialSibling(aFrame);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-06-21 06:35:17 -07:00
|
|
|
struct BoxToRect : public nsLayoutUtils::BoxCallback {
|
|
|
|
typedef nsSize (*GetRectFromFrameFun)(nsIFrame*);
|
|
|
|
|
2011-12-27 19:24:29 -08:00
|
|
|
nsIFrame* mRelativeTo;
|
2008-09-10 17:24:16 -07:00
|
|
|
nsLayoutUtils::RectCallback* mCallback;
|
2012-08-22 08:56:38 -07:00
|
|
|
uint32_t mFlags;
|
2012-06-21 06:35:17 -07:00
|
|
|
GetRectFromFrameFun mRectFromFrame;
|
2008-09-10 17:24:16 -07:00
|
|
|
|
2012-06-21 06:35:17 -07:00
|
|
|
BoxToRect(nsIFrame* aRelativeTo, nsLayoutUtils::RectCallback* aCallback,
|
2012-08-22 08:56:38 -07:00
|
|
|
uint32_t aFlags, GetRectFromFrameFun aRectFromFrame)
|
2012-06-21 06:35:17 -07:00
|
|
|
: mRelativeTo(aRelativeTo), mCallback(aCallback), mFlags(aFlags),
|
|
|
|
mRectFromFrame(aRectFromFrame) {}
|
2008-09-10 17:24:16 -07:00
|
|
|
|
|
|
|
virtual void AddBox(nsIFrame* aFrame) {
|
2008-02-27 01:26:15 -08:00
|
|
|
nsRect r;
|
|
|
|
nsIFrame* outer = nsSVGUtils::GetOuterSVGFrameAndCoveredRegion(aFrame, &r);
|
2011-12-27 19:24:29 -08:00
|
|
|
if (!outer) {
|
|
|
|
outer = aFrame;
|
2012-06-21 06:35:17 -07:00
|
|
|
r = nsRect(nsPoint(0, 0), mRectFromFrame(aFrame));
|
2011-12-27 19:24:29 -08:00
|
|
|
}
|
|
|
|
if (mFlags & nsLayoutUtils::RECTS_ACCOUNT_FOR_TRANSFORMS) {
|
|
|
|
r = nsLayoutUtils::TransformFrameRectToAncestor(outer, r, mRelativeTo);
|
|
|
|
} else {
|
|
|
|
r += outer->GetOffsetTo(mRelativeTo);
|
|
|
|
}
|
|
|
|
mCallback->AddRect(r);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
2008-09-10 17:24:16 -07:00
|
|
|
};
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2012-06-21 06:35:17 -07:00
|
|
|
static nsSize
|
|
|
|
GetFrameBorderSize(nsIFrame* aFrame)
|
|
|
|
{
|
|
|
|
return aFrame->GetSize();
|
|
|
|
}
|
|
|
|
|
2008-02-27 01:26:15 -08:00
|
|
|
void
|
|
|
|
nsLayoutUtils::GetAllInFlowRects(nsIFrame* aFrame, nsIFrame* aRelativeTo,
|
2012-08-22 08:56:38 -07:00
|
|
|
RectCallback* aCallback, uint32_t aFlags)
|
2008-02-27 01:26:15 -08:00
|
|
|
{
|
2012-06-21 06:35:17 -07:00
|
|
|
BoxToRect converter(aRelativeTo, aCallback, aFlags, &GetFrameBorderSize);
|
|
|
|
GetAllInFlowBoxes(aFrame, &converter);
|
|
|
|
}
|
|
|
|
|
|
|
|
static nsSize
|
|
|
|
GetFramePaddingSize(nsIFrame* aFrame)
|
|
|
|
{
|
|
|
|
return aFrame->GetPaddingRect().Size();
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsLayoutUtils::GetAllInFlowPaddingRects(nsIFrame* aFrame, nsIFrame* aRelativeTo,
|
2012-08-22 08:56:38 -07:00
|
|
|
RectCallback* aCallback, uint32_t aFlags)
|
2012-06-21 06:35:17 -07:00
|
|
|
{
|
|
|
|
BoxToRect converter(aRelativeTo, aCallback, aFlags, &GetFramePaddingSize);
|
2008-09-10 17:24:16 -07:00
|
|
|
GetAllInFlowBoxes(aFrame, &converter);
|
2008-02-27 01:26:15 -08:00
|
|
|
}
|
|
|
|
|
2011-10-17 07:59:28 -07:00
|
|
|
nsLayoutUtils::RectAccumulator::RectAccumulator() : mSeenFirstRect(false) {}
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2009-09-24 14:01:48 -07:00
|
|
|
void nsLayoutUtils::RectAccumulator::AddRect(const nsRect& aRect) {
|
|
|
|
mResultRect.UnionRect(mResultRect, aRect);
|
|
|
|
if (!mSeenFirstRect) {
|
2011-10-17 07:59:28 -07:00
|
|
|
mSeenFirstRect = true;
|
2009-09-24 14:01:48 -07:00
|
|
|
mFirstRect = aRect;
|
|
|
|
}
|
|
|
|
}
|
2008-02-27 01:26:15 -08:00
|
|
|
|
2009-09-24 14:01:48 -07:00
|
|
|
nsLayoutUtils::RectListBuilder::RectListBuilder(nsClientRectList* aList)
|
|
|
|
: mRectList(aList), mRV(NS_OK) {}
|
|
|
|
|
|
|
|
void nsLayoutUtils::RectListBuilder::AddRect(const nsRect& aRect) {
|
|
|
|
nsRefPtr<nsClientRect> rect = new nsClientRect();
|
|
|
|
|
|
|
|
rect->SetLayoutRect(aRect);
|
|
|
|
mRectList->Append(rect);
|
|
|
|
}
|
|
|
|
|
|
|
|
nsIFrame* nsLayoutUtils::GetContainingBlockForClientRect(nsIFrame* aFrame)
|
|
|
|
{
|
2011-12-27 19:24:29 -08:00
|
|
|
return aFrame->PresContext()->PresShell()->GetRootFrame();
|
2009-09-24 14:01:48 -07:00
|
|
|
}
|
2008-02-27 01:26:15 -08:00
|
|
|
|
|
|
|
nsRect
|
2011-12-27 19:24:29 -08:00
|
|
|
nsLayoutUtils::GetAllInFlowRectsUnion(nsIFrame* aFrame, nsIFrame* aRelativeTo,
|
2012-08-22 08:56:38 -07:00
|
|
|
uint32_t aFlags) {
|
2008-02-27 01:26:15 -08:00
|
|
|
RectAccumulator accumulator;
|
2011-12-27 19:24:29 -08:00
|
|
|
GetAllInFlowRects(aFrame, aRelativeTo, &accumulator, aFlags);
|
2008-02-27 01:26:15 -08:00
|
|
|
return accumulator.mResultRect.IsEmpty() ? accumulator.mFirstRect
|
|
|
|
: accumulator.mResultRect;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2012-06-21 06:35:17 -07:00
|
|
|
nsRect
|
|
|
|
nsLayoutUtils::GetAllInFlowPaddingRectsUnion(nsIFrame* aFrame,
|
|
|
|
nsIFrame* aRelativeTo,
|
2012-08-22 08:56:38 -07:00
|
|
|
uint32_t aFlags)
|
2012-06-21 06:35:17 -07:00
|
|
|
{
|
|
|
|
RectAccumulator accumulator;
|
|
|
|
GetAllInFlowPaddingRects(aFrame, aRelativeTo, &accumulator, aFlags);
|
|
|
|
return accumulator.mResultRect.IsEmpty() ? accumulator.mFirstRect
|
|
|
|
: accumulator.mResultRect;
|
|
|
|
}
|
|
|
|
|
2008-06-12 15:02:32 -07:00
|
|
|
nsRect
|
|
|
|
nsLayoutUtils::GetTextShadowRectsUnion(const nsRect& aTextAndDecorationsRect,
|
2011-01-02 17:48:09 -08:00
|
|
|
nsIFrame* aFrame,
|
2012-08-22 08:56:38 -07:00
|
|
|
uint32_t aFlags)
|
2008-06-12 15:02:32 -07:00
|
|
|
{
|
|
|
|
const nsStyleText* textStyle = aFrame->GetStyleText();
|
2012-08-08 04:37:13 -07:00
|
|
|
if (!textStyle->HasTextShadow(aFrame))
|
2008-06-12 15:02:32 -07:00
|
|
|
return aTextAndDecorationsRect;
|
|
|
|
|
|
|
|
nsRect resultRect = aTextAndDecorationsRect;
|
2012-08-22 08:56:38 -07:00
|
|
|
int32_t A2D = aFrame->PresContext()->AppUnitsPerDevPixel();
|
|
|
|
for (uint32_t i = 0; i < textStyle->mTextShadow->Length(); ++i) {
|
2008-07-07 17:56:52 -07:00
|
|
|
nsCSSShadowItem* shadow = textStyle->mTextShadow->ShadowAt(i);
|
2011-01-02 17:48:09 -08:00
|
|
|
nsMargin blur = nsContextBoxBlur::GetBlurRadiusMargin(shadow->mRadius, A2D);
|
|
|
|
if ((aFlags & EXCLUDE_BLUR_SHADOWS) && blur != nsMargin(0, 0, 0, 0))
|
|
|
|
continue;
|
|
|
|
|
|
|
|
nsRect tmpRect(aTextAndDecorationsRect);
|
2008-06-12 15:02:32 -07:00
|
|
|
|
2008-09-12 20:45:37 -07:00
|
|
|
tmpRect.MoveBy(nsPoint(shadow->mXOffset, shadow->mYOffset));
|
2011-01-02 17:48:09 -08:00
|
|
|
tmpRect.Inflate(blur);
|
2008-06-12 15:02:32 -07:00
|
|
|
|
|
|
|
resultRect.UnionRect(resultRect, tmpRect);
|
|
|
|
}
|
|
|
|
return resultRect;
|
|
|
|
}
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
nsresult
|
2010-08-31 11:54:44 -07:00
|
|
|
nsLayoutUtils::GetFontMetricsForFrame(const nsIFrame* aFrame,
|
2011-11-23 18:48:23 -08:00
|
|
|
nsFontMetrics** aFontMetrics,
|
|
|
|
float aInflation)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2007-08-07 12:22:26 -07:00
|
|
|
return nsLayoutUtils::GetFontMetricsForStyleContext(aFrame->GetStyleContext(),
|
2011-11-23 18:48:23 -08:00
|
|
|
aFontMetrics,
|
|
|
|
aInflation);
|
2007-08-07 12:22:26 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
nsLayoutUtils::GetFontMetricsForStyleContext(nsStyleContext* aStyleContext,
|
2011-11-23 18:48:23 -08:00
|
|
|
nsFontMetrics** aFontMetrics,
|
|
|
|
float aInflation)
|
2007-08-07 12:22:26 -07:00
|
|
|
{
|
2008-09-30 20:01:53 -07:00
|
|
|
// pass the user font set object into the device context to pass along to CreateFontGroup
|
|
|
|
gfxUserFontSet* fs = aStyleContext->PresContext()->GetUserFontSet();
|
2010-04-27 09:15:01 -07:00
|
|
|
|
2011-11-23 18:48:23 -08:00
|
|
|
nsFont font = aStyleContext->GetStyleFont()->mFont;
|
|
|
|
// We need to not run font.size through floats when it's large since
|
|
|
|
// doing so would be lossy. Fortunately, in such cases, aInflation is
|
|
|
|
// guaranteed to be 1.0f.
|
|
|
|
if (aInflation != 1.0f) {
|
|
|
|
font.size = NSToCoordRound(font.size * aInflation);
|
|
|
|
}
|
2008-09-30 20:01:53 -07:00
|
|
|
return aStyleContext->PresContext()->DeviceContext()->GetMetricsFor(
|
2012-01-24 05:09:55 -08:00
|
|
|
font, aStyleContext->GetStyleFont()->mLanguage,
|
2008-12-04 08:09:53 -08:00
|
|
|
fs, *aFontMetrics);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
nsIFrame*
|
|
|
|
nsLayoutUtils::FindChildContainingDescendant(nsIFrame* aParent, nsIFrame* aDescendantFrame)
|
|
|
|
{
|
|
|
|
nsIFrame* result = aDescendantFrame;
|
|
|
|
|
|
|
|
while (result) {
|
|
|
|
nsIFrame* parent = result->GetParent();
|
|
|
|
if (parent == aParent) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
// The frame is not an immediate child of aParent so walk up another level
|
|
|
|
result = parent;
|
|
|
|
}
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2007-12-20 19:28:18 -08:00
|
|
|
nsBlockFrame*
|
|
|
|
nsLayoutUtils::GetAsBlock(nsIFrame* aFrame)
|
|
|
|
{
|
2009-01-12 11:20:59 -08:00
|
|
|
nsBlockFrame* block = do_QueryFrame(aFrame);
|
|
|
|
return block;
|
2007-12-20 19:28:18 -08:00
|
|
|
}
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
nsBlockFrame*
|
|
|
|
nsLayoutUtils::FindNearestBlockAncestor(nsIFrame* aFrame)
|
|
|
|
{
|
|
|
|
nsIFrame* nextAncestor;
|
|
|
|
for (nextAncestor = aFrame->GetParent(); nextAncestor;
|
|
|
|
nextAncestor = nextAncestor->GetParent()) {
|
2007-12-20 19:28:18 -08:00
|
|
|
nsBlockFrame* block = GetAsBlock(nextAncestor);
|
|
|
|
if (block)
|
2007-03-22 10:30:00 -07:00
|
|
|
return block;
|
|
|
|
}
|
2012-07-30 07:20:58 -07:00
|
|
|
return nullptr;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2008-11-25 14:15:41 -08:00
|
|
|
nsIFrame*
|
|
|
|
nsLayoutUtils::GetNonGeneratedAncestor(nsIFrame* aFrame)
|
|
|
|
{
|
|
|
|
if (!(aFrame->GetStateBits() & NS_FRAME_GENERATED_CONTENT))
|
|
|
|
return aFrame;
|
|
|
|
|
|
|
|
nsIFrame* f = aFrame;
|
|
|
|
do {
|
2012-06-10 16:44:50 -07:00
|
|
|
f = GetParentOrPlaceholderFor(f);
|
2008-11-25 14:15:41 -08:00
|
|
|
} while (f->GetStateBits() & NS_FRAME_GENERATED_CONTENT);
|
|
|
|
return f;
|
|
|
|
}
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
nsIFrame*
|
2012-06-10 16:44:50 -07:00
|
|
|
nsLayoutUtils::GetParentOrPlaceholderFor(nsIFrame* aFrame)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2007-10-01 22:57:45 -07:00
|
|
|
if ((aFrame->GetStateBits() & NS_FRAME_OUT_OF_FLOW)
|
2009-08-31 11:25:36 -07:00
|
|
|
&& !aFrame->GetPrevInFlow()) {
|
2012-06-10 16:44:50 -07:00
|
|
|
return aFrame->PresContext()->PresShell()->FrameManager()->
|
|
|
|
GetPlaceholderFrameFor(aFrame);
|
2007-10-01 22:57:45 -07:00
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
return aFrame->GetParent();
|
|
|
|
}
|
|
|
|
|
2012-06-10 16:44:50 -07:00
|
|
|
nsIFrame*
|
|
|
|
nsLayoutUtils::GetParentOrPlaceholderForCrossDoc(nsIFrame* aFrame)
|
|
|
|
{
|
|
|
|
nsIFrame* f = GetParentOrPlaceholderFor(aFrame);
|
|
|
|
if (f)
|
|
|
|
return f;
|
|
|
|
return GetCrossDocParentFrame(aFrame);
|
|
|
|
}
|
|
|
|
|
2007-03-25 20:27:53 -07:00
|
|
|
nsIFrame*
|
|
|
|
nsLayoutUtils::GetNextContinuationOrSpecialSibling(nsIFrame *aFrame)
|
|
|
|
{
|
|
|
|
nsIFrame *result = aFrame->GetNextContinuation();
|
|
|
|
if (result)
|
|
|
|
return result;
|
|
|
|
|
|
|
|
if ((aFrame->GetStateBits() & NS_FRAME_IS_SPECIAL) != 0) {
|
|
|
|
// We only store the "special sibling" annotation with the first
|
2009-04-14 19:28:27 -07:00
|
|
|
// frame in the continuation chain. Walk back to find that frame now.
|
|
|
|
aFrame = aFrame->GetFirstContinuation();
|
2007-03-25 20:27:53 -07:00
|
|
|
|
2010-03-28 18:46:55 -07:00
|
|
|
void* value = aFrame->Properties().Get(nsIFrame::IBSplitSpecialSibling());
|
2007-07-08 00:08:04 -07:00
|
|
|
return static_cast<nsIFrame*>(value);
|
2007-03-25 20:27:53 -07:00
|
|
|
}
|
|
|
|
|
2012-07-30 07:20:58 -07:00
|
|
|
return nullptr;
|
2007-03-25 20:27:53 -07:00
|
|
|
}
|
|
|
|
|
2008-09-10 17:24:16 -07:00
|
|
|
nsIFrame*
|
|
|
|
nsLayoutUtils::GetFirstContinuationOrSpecialSibling(nsIFrame *aFrame)
|
|
|
|
{
|
|
|
|
nsIFrame *result = aFrame->GetFirstContinuation();
|
|
|
|
if (result->GetStateBits() & NS_FRAME_IS_SPECIAL) {
|
2011-10-17 07:59:28 -07:00
|
|
|
while (true) {
|
2008-09-10 17:24:16 -07:00
|
|
|
nsIFrame *f = static_cast<nsIFrame*>
|
2010-03-28 18:46:55 -07:00
|
|
|
(result->Properties().Get(nsIFrame::IBSplitSpecialPrevSibling()));
|
2008-09-10 17:24:16 -07:00
|
|
|
if (!f)
|
|
|
|
break;
|
|
|
|
result = f;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2011-09-28 23:19:26 -07:00
|
|
|
bool
|
2007-03-22 10:30:00 -07:00
|
|
|
nsLayoutUtils::IsViewportScrollbarFrame(nsIFrame* aFrame)
|
|
|
|
{
|
|
|
|
if (!aFrame)
|
2011-10-17 07:59:28 -07:00
|
|
|
return false;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
nsIFrame* rootScrollFrame =
|
2007-03-30 14:11:41 -07:00
|
|
|
aFrame->PresContext()->PresShell()->GetRootScrollFrame();
|
2007-03-22 10:30:00 -07:00
|
|
|
if (!rootScrollFrame)
|
2011-10-17 07:59:28 -07:00
|
|
|
return false;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2009-01-12 11:20:59 -08:00
|
|
|
nsIScrollableFrame* rootScrollableFrame = do_QueryFrame(rootScrollFrame);
|
2007-03-22 10:30:00 -07:00
|
|
|
NS_ASSERTION(rootScrollableFrame, "The root scorollable frame is null");
|
|
|
|
|
|
|
|
if (!IsProperAncestorFrame(rootScrollFrame, aFrame))
|
2011-10-17 07:59:28 -07:00
|
|
|
return false;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
nsIFrame* rootScrolledFrame = rootScrollableFrame->GetScrolledFrame();
|
|
|
|
return !(rootScrolledFrame == aFrame ||
|
|
|
|
IsProperAncestorFrame(rootScrolledFrame, aFrame));
|
|
|
|
}
|
|
|
|
|
|
|
|
static nscoord AddPercents(nsLayoutUtils::IntrinsicWidthType aType,
|
|
|
|
nscoord aCurrent, float aPercent)
|
|
|
|
{
|
|
|
|
nscoord result = aCurrent;
|
|
|
|
if (aPercent > 0.0f && aType == nsLayoutUtils::PREF_WIDTH) {
|
|
|
|
// XXX Should we also consider percentages for min widths, up to a
|
|
|
|
// limit?
|
|
|
|
if (aPercent >= 1.0f)
|
|
|
|
result = nscoord_MAX;
|
|
|
|
else
|
|
|
|
result = NSToCoordRound(float(result) / (1.0f - aPercent));
|
|
|
|
}
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2010-08-25 03:17:55 -07:00
|
|
|
// Use only for widths/heights (or their min/max), since it clamps
|
|
|
|
// negative calc() results to 0.
|
2011-09-28 23:19:26 -07:00
|
|
|
static bool GetAbsoluteCoord(const nsStyleCoord& aStyle, nscoord& aResult)
|
2008-07-17 16:37:12 -07:00
|
|
|
{
|
2010-08-11 12:32:53 -07:00
|
|
|
if (aStyle.IsCalcUnit()) {
|
|
|
|
if (aStyle.CalcHasPercent()) {
|
2011-10-17 07:59:28 -07:00
|
|
|
return false;
|
2010-08-11 12:32:53 -07:00
|
|
|
}
|
|
|
|
// If it has no percents, we can pass 0 for the percentage basis.
|
|
|
|
aResult = nsRuleNode::ComputeComputedCalc(aStyle, 0);
|
2010-08-25 03:17:55 -07:00
|
|
|
if (aResult < 0)
|
|
|
|
aResult = 0;
|
2011-10-17 07:59:28 -07:00
|
|
|
return true;
|
2010-08-11 12:32:53 -07:00
|
|
|
}
|
|
|
|
|
2008-07-17 16:37:12 -07:00
|
|
|
if (eStyleUnit_Coord != aStyle.GetUnit())
|
2011-10-17 07:59:28 -07:00
|
|
|
return false;
|
2010-04-27 09:15:01 -07:00
|
|
|
|
2008-07-17 16:37:12 -07:00
|
|
|
aResult = aStyle.GetCoordValue();
|
2010-08-25 03:17:55 -07:00
|
|
|
NS_ASSERTION(aResult >= 0, "negative widths not allowed");
|
2011-10-17 07:59:28 -07:00
|
|
|
return true;
|
2008-07-17 16:37:12 -07:00
|
|
|
}
|
|
|
|
|
2011-09-28 23:19:26 -07:00
|
|
|
static bool
|
2007-06-12 11:27:09 -07:00
|
|
|
GetPercentHeight(const nsStyleCoord& aStyle,
|
|
|
|
nsIFrame* aFrame,
|
|
|
|
nscoord& aResult)
|
|
|
|
{
|
|
|
|
if (eStyleUnit_Percent != aStyle.GetUnit())
|
2011-10-17 07:59:28 -07:00
|
|
|
return false;
|
2007-06-12 11:27:09 -07:00
|
|
|
|
2011-05-11 21:04:30 -07:00
|
|
|
nsIFrame *f = aFrame->GetContainingBlock();
|
2007-06-12 11:27:09 -07:00
|
|
|
if (!f) {
|
|
|
|
NS_NOTREACHED("top of frame tree not a containing block");
|
2011-10-17 07:59:28 -07:00
|
|
|
return false;
|
2007-06-12 11:27:09 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
const nsStylePosition *pos = f->GetStylePosition();
|
|
|
|
nscoord h;
|
2008-07-17 16:37:12 -07:00
|
|
|
if (!GetAbsoluteCoord(pos->mHeight, h) &&
|
|
|
|
!GetPercentHeight(pos->mHeight, f, h)) {
|
2007-06-12 11:27:09 -07:00
|
|
|
NS_ASSERTION(pos->mHeight.GetUnit() == eStyleUnit_Auto ||
|
2010-08-25 03:17:55 -07:00
|
|
|
pos->mHeight.HasPercent(),
|
2007-06-12 11:27:09 -07:00
|
|
|
"unknown height unit");
|
2010-08-05 14:59:36 -07:00
|
|
|
nsIAtom* fType = f->GetType();
|
|
|
|
if (fType != nsGkAtoms::viewportFrame && fType != nsGkAtoms::canvasFrame &&
|
|
|
|
fType != nsGkAtoms::pageContentFrame) {
|
|
|
|
// There's no basis for the percentage height, so it acts like auto.
|
|
|
|
// Should we consider a max-height < min-height pair a basis for
|
|
|
|
// percentage heights? The spec is somewhat unclear, and not doing
|
|
|
|
// so is simpler and avoids troubling discontinuities in behavior,
|
|
|
|
// so I'll choose not to. -LDB
|
2011-10-17 07:59:28 -07:00
|
|
|
return false;
|
2010-08-05 14:59:36 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_ASSERTION(pos->mHeight.GetUnit() == eStyleUnit_Auto,
|
|
|
|
"Unexpected height unit for viewport or canvas or page-content");
|
|
|
|
// For the viewport, canvas, and page-content kids, the percentage
|
|
|
|
// basis is just the parent height.
|
|
|
|
h = f->GetSize().height;
|
|
|
|
if (h == NS_UNCONSTRAINEDSIZE) {
|
|
|
|
// We don't have a percentage basis after all
|
2011-10-17 07:59:28 -07:00
|
|
|
return false;
|
2010-08-05 14:59:36 -07:00
|
|
|
}
|
2007-06-12 11:27:09 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
nscoord maxh;
|
2008-07-17 16:37:12 -07:00
|
|
|
if (GetAbsoluteCoord(pos->mMaxHeight, maxh) ||
|
|
|
|
GetPercentHeight(pos->mMaxHeight, f, maxh)) {
|
2007-06-12 11:27:09 -07:00
|
|
|
if (maxh < h)
|
|
|
|
h = maxh;
|
|
|
|
} else {
|
|
|
|
NS_ASSERTION(pos->mMaxHeight.GetUnit() == eStyleUnit_None ||
|
2010-08-25 03:17:55 -07:00
|
|
|
pos->mMaxHeight.HasPercent(),
|
2007-06-12 11:27:09 -07:00
|
|
|
"unknown max-height unit");
|
|
|
|
}
|
|
|
|
|
|
|
|
nscoord minh;
|
2008-07-17 16:37:12 -07:00
|
|
|
if (GetAbsoluteCoord(pos->mMinHeight, minh) ||
|
|
|
|
GetPercentHeight(pos->mMinHeight, f, minh)) {
|
2007-06-12 11:27:09 -07:00
|
|
|
if (minh > h)
|
|
|
|
h = minh;
|
|
|
|
} else {
|
2012-09-04 16:26:11 -07:00
|
|
|
NS_ASSERTION(pos->mMinHeight.HasPercent() ||
|
|
|
|
pos->mMinHeight.GetUnit() == eStyleUnit_Auto,
|
2007-06-12 11:27:09 -07:00
|
|
|
"unknown min-height unit");
|
|
|
|
}
|
|
|
|
|
|
|
|
aResult = NSToCoordRound(aStyle.GetPercentValue() * h);
|
2011-10-17 07:59:28 -07:00
|
|
|
return true;
|
2007-06-12 11:27:09 -07:00
|
|
|
}
|
|
|
|
|
2007-11-15 10:10:31 -08:00
|
|
|
// Handles only -moz-max-content and -moz-min-content, and
|
|
|
|
// -moz-fit-content for min-width and max-width, since the others
|
|
|
|
// (-moz-fit-content for width, and -moz-available) have no effect on
|
2007-05-03 16:11:00 -07:00
|
|
|
// intrinsic widths.
|
|
|
|
enum eWidthProperty { PROP_WIDTH, PROP_MAX_WIDTH, PROP_MIN_WIDTH };
|
2011-09-28 23:19:26 -07:00
|
|
|
static bool
|
2007-05-03 16:11:00 -07:00
|
|
|
GetIntrinsicCoord(const nsStyleCoord& aStyle,
|
2011-04-07 18:04:40 -07:00
|
|
|
nsRenderingContext* aRenderingContext,
|
2007-05-03 16:11:00 -07:00
|
|
|
nsIFrame* aFrame,
|
|
|
|
eWidthProperty aProperty,
|
|
|
|
nscoord& aResult)
|
|
|
|
{
|
|
|
|
NS_PRECONDITION(aProperty == PROP_WIDTH || aProperty == PROP_MAX_WIDTH ||
|
|
|
|
aProperty == PROP_MIN_WIDTH, "unexpected property");
|
|
|
|
if (aStyle.GetUnit() != eStyleUnit_Enumerated)
|
2011-10-17 07:59:28 -07:00
|
|
|
return false;
|
2012-08-22 08:56:38 -07:00
|
|
|
int32_t val = aStyle.GetIntValue();
|
2007-11-15 10:10:31 -08:00
|
|
|
NS_ASSERTION(val == NS_STYLE_WIDTH_MAX_CONTENT ||
|
|
|
|
val == NS_STYLE_WIDTH_MIN_CONTENT ||
|
|
|
|
val == NS_STYLE_WIDTH_FIT_CONTENT ||
|
|
|
|
val == NS_STYLE_WIDTH_AVAILABLE,
|
2007-05-03 16:11:00 -07:00
|
|
|
"unexpected enumerated value for width property");
|
2007-11-15 10:10:31 -08:00
|
|
|
if (val == NS_STYLE_WIDTH_AVAILABLE)
|
2011-10-17 07:59:28 -07:00
|
|
|
return false;
|
2007-11-15 10:10:31 -08:00
|
|
|
if (val == NS_STYLE_WIDTH_FIT_CONTENT) {
|
2007-05-03 16:11:00 -07:00
|
|
|
if (aProperty == PROP_WIDTH)
|
2011-10-17 07:59:28 -07:00
|
|
|
return false; // handle like 'width: auto'
|
2007-05-03 16:11:00 -07:00
|
|
|
if (aProperty == PROP_MAX_WIDTH)
|
2007-11-15 10:10:31 -08:00
|
|
|
// constrain large 'width' values down to -moz-max-content
|
|
|
|
val = NS_STYLE_WIDTH_MAX_CONTENT;
|
2007-05-03 16:11:00 -07:00
|
|
|
else
|
2007-11-15 10:10:31 -08:00
|
|
|
// constrain small 'width' or 'max-width' values up to -moz-min-content
|
|
|
|
val = NS_STYLE_WIDTH_MIN_CONTENT;
|
2007-05-03 16:11:00 -07:00
|
|
|
}
|
|
|
|
|
2007-11-15 10:10:31 -08:00
|
|
|
NS_ASSERTION(val == NS_STYLE_WIDTH_MAX_CONTENT ||
|
|
|
|
val == NS_STYLE_WIDTH_MIN_CONTENT,
|
2007-05-03 16:11:00 -07:00
|
|
|
"should have reduced everything remaining to one of these");
|
2012-01-24 17:21:29 -08:00
|
|
|
|
|
|
|
// If aFrame is a container for font size inflation, then shrink
|
|
|
|
// wrapping inside of it should not apply font size inflation.
|
2012-05-20 22:18:27 -07:00
|
|
|
AutoMaybeDisableFontInflation an(aFrame);
|
2012-01-24 17:21:29 -08:00
|
|
|
|
2007-11-15 10:10:31 -08:00
|
|
|
if (val == NS_STYLE_WIDTH_MAX_CONTENT)
|
2007-05-03 16:11:00 -07:00
|
|
|
aResult = aFrame->GetPrefWidth(aRenderingContext);
|
|
|
|
else
|
|
|
|
aResult = aFrame->GetMinWidth(aRenderingContext);
|
2011-10-17 07:59:28 -07:00
|
|
|
return true;
|
2007-05-03 16:11:00 -07:00
|
|
|
}
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
#undef DEBUG_INTRINSIC_WIDTH
|
|
|
|
|
|
|
|
#ifdef DEBUG_INTRINSIC_WIDTH
|
2012-08-22 08:56:38 -07:00
|
|
|
static int32_t gNoiseIndent = 0;
|
2007-03-22 10:30:00 -07:00
|
|
|
#endif
|
|
|
|
|
|
|
|
/* static */ nscoord
|
2011-04-07 18:04:40 -07:00
|
|
|
nsLayoutUtils::IntrinsicForContainer(nsRenderingContext *aRenderingContext,
|
2007-03-22 10:30:00 -07:00
|
|
|
nsIFrame *aFrame,
|
|
|
|
IntrinsicWidthType aType)
|
|
|
|
{
|
|
|
|
NS_PRECONDITION(aFrame, "null frame");
|
|
|
|
NS_PRECONDITION(aType == MIN_WIDTH || aType == PREF_WIDTH, "bad type");
|
|
|
|
|
|
|
|
#ifdef DEBUG_INTRINSIC_WIDTH
|
|
|
|
nsFrame::IndentBy(stdout, gNoiseIndent);
|
2007-07-08 00:08:04 -07:00
|
|
|
static_cast<nsFrame*>(aFrame)->ListTag(stdout);
|
2007-03-22 10:30:00 -07:00
|
|
|
printf(" %s intrinsic width for container:\n",
|
|
|
|
aType == MIN_WIDTH ? "min" : "pref");
|
|
|
|
#endif
|
|
|
|
|
2012-01-24 17:21:29 -08:00
|
|
|
// If aFrame is a container for font size inflation, then shrink
|
|
|
|
// wrapping inside of it should not apply font size inflation.
|
2012-05-20 22:18:27 -07:00
|
|
|
AutoMaybeDisableFontInflation an(aFrame);
|
2012-01-24 17:21:29 -08:00
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
nsIFrame::IntrinsicWidthOffsetData offsets =
|
|
|
|
aFrame->IntrinsicWidthOffsets(aRenderingContext);
|
|
|
|
|
|
|
|
const nsStylePosition *stylePos = aFrame->GetStylePosition();
|
2012-08-22 08:56:38 -07:00
|
|
|
uint8_t boxSizing = stylePos->mBoxSizing;
|
2007-03-22 10:30:00 -07:00
|
|
|
const nsStyleCoord &styleWidth = stylePos->mWidth;
|
|
|
|
const nsStyleCoord &styleMinWidth = stylePos->mMinWidth;
|
|
|
|
const nsStyleCoord &styleMaxWidth = stylePos->mMaxWidth;
|
|
|
|
|
|
|
|
// We build up two values starting with the content box, and then
|
|
|
|
// adding padding, border and margin. The result is normally
|
|
|
|
// |result|. Then, when we handle 'width', 'min-width', and
|
|
|
|
// 'max-width', we use the results we've been building in |min| as a
|
|
|
|
// minimum, overriding 'min-width'. This ensures two things:
|
|
|
|
// * that we don't let a value of 'box-sizing' specifying a width
|
|
|
|
// smaller than the padding/border inside the box-sizing box give
|
|
|
|
// a content width less than zero
|
|
|
|
// * that we prevent tables from becoming smaller than their
|
|
|
|
// intrinsic minimum width
|
|
|
|
nscoord result = 0, min = 0;
|
|
|
|
|
2010-08-25 03:17:56 -07:00
|
|
|
nscoord maxw;
|
2011-09-28 23:19:26 -07:00
|
|
|
bool haveFixedMaxWidth = GetAbsoluteCoord(styleMaxWidth, maxw);
|
2010-08-25 03:17:56 -07:00
|
|
|
nscoord minw;
|
2012-09-04 16:26:10 -07:00
|
|
|
|
|
|
|
// Treat "min-width: auto" as 0.
|
|
|
|
bool haveFixedMinWidth;
|
|
|
|
if (eStyleUnit_Auto == styleMinWidth.GetUnit()) {
|
|
|
|
// NOTE: Technically, "auto" is supposed to behave like "min-content" on
|
|
|
|
// flex items. However, we don't need to worry about that here, because
|
|
|
|
// flex items' min-sizes are intentionally ignored until the flex
|
|
|
|
// container explicitly considers them during space distribution.
|
|
|
|
minw = 0;
|
|
|
|
haveFixedMinWidth = true;
|
|
|
|
} else {
|
|
|
|
haveFixedMinWidth = GetAbsoluteCoord(styleMinWidth, minw);
|
|
|
|
}
|
2010-08-25 03:17:56 -07:00
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
// If we have a specified width (or a specified 'min-width' greater
|
|
|
|
// than the specified 'max-width', which works out to the same thing),
|
|
|
|
// don't even bother getting the frame's intrinsic width.
|
2007-05-03 16:11:00 -07:00
|
|
|
if (styleWidth.GetUnit() == eStyleUnit_Enumerated &&
|
2007-11-15 10:10:31 -08:00
|
|
|
(styleWidth.GetIntValue() == NS_STYLE_WIDTH_MAX_CONTENT ||
|
|
|
|
styleWidth.GetIntValue() == NS_STYLE_WIDTH_MIN_CONTENT)) {
|
|
|
|
// -moz-fit-content and -moz-available enumerated widths compute intrinsic
|
2007-05-03 16:11:00 -07:00
|
|
|
// widths just like auto.
|
2007-11-15 10:10:31 -08:00
|
|
|
// For -moz-max-content and -moz-min-content, we handle them like
|
2007-05-03 16:11:00 -07:00
|
|
|
// specified widths, but ignore -moz-box-sizing.
|
|
|
|
boxSizing = NS_STYLE_BOX_SIZING_CONTENT;
|
|
|
|
} else if (styleWidth.GetUnit() != eStyleUnit_Coord &&
|
2010-08-25 03:17:56 -07:00
|
|
|
!(haveFixedMinWidth && haveFixedMaxWidth && maxw <= minw)) {
|
2007-03-22 10:30:00 -07:00
|
|
|
#ifdef DEBUG_INTRINSIC_WIDTH
|
|
|
|
++gNoiseIndent;
|
|
|
|
#endif
|
|
|
|
if (aType == MIN_WIDTH)
|
|
|
|
result = aFrame->GetMinWidth(aRenderingContext);
|
|
|
|
else
|
|
|
|
result = aFrame->GetPrefWidth(aRenderingContext);
|
|
|
|
#ifdef DEBUG_INTRINSIC_WIDTH
|
|
|
|
--gNoiseIndent;
|
|
|
|
nsFrame::IndentBy(stdout, gNoiseIndent);
|
2007-07-08 00:08:04 -07:00
|
|
|
static_cast<nsFrame*>(aFrame)->ListTag(stdout);
|
2007-03-22 10:30:00 -07:00
|
|
|
printf(" %s intrinsic width from frame is %d.\n",
|
|
|
|
aType == MIN_WIDTH ? "min" : "pref", result);
|
|
|
|
#endif
|
2007-06-12 11:27:09 -07:00
|
|
|
|
|
|
|
// Handle elements with an intrinsic ratio (or size) and a specified
|
|
|
|
// height, min-height, or max-height.
|
2012-09-04 16:26:11 -07:00
|
|
|
// NOTE: We treat "min-height:auto" as "0" for the purpose of this code,
|
|
|
|
// since that's what it means in all cases except for on flex items -- and
|
|
|
|
// even there, we're supposed to ignore it (i.e. treat it as 0) until the
|
|
|
|
// flex container explicitly considers it.
|
2007-06-12 11:27:09 -07:00
|
|
|
const nsStyleCoord &styleHeight = stylePos->mHeight;
|
|
|
|
const nsStyleCoord &styleMinHeight = stylePos->mMinHeight;
|
|
|
|
const nsStyleCoord &styleMaxHeight = stylePos->mMaxHeight;
|
2012-09-04 16:26:11 -07:00
|
|
|
|
2007-06-12 11:27:09 -07:00
|
|
|
if (styleHeight.GetUnit() != eStyleUnit_Auto ||
|
2012-09-04 16:26:11 -07:00
|
|
|
!(styleMinHeight.GetUnit() == eStyleUnit_Auto ||
|
|
|
|
(styleMinHeight.GetUnit() == eStyleUnit_Coord &&
|
|
|
|
styleMinHeight.GetCoordValue() == 0)) ||
|
2007-06-12 11:27:09 -07:00
|
|
|
styleMaxHeight.GetUnit() != eStyleUnit_None) {
|
|
|
|
|
|
|
|
nsSize ratio = aFrame->GetIntrinsicRatio();
|
|
|
|
|
|
|
|
if (ratio.height != 0) {
|
|
|
|
|
|
|
|
nscoord h;
|
2008-07-17 16:37:12 -07:00
|
|
|
if (GetAbsoluteCoord(styleHeight, h) ||
|
|
|
|
GetPercentHeight(styleHeight, aFrame, h)) {
|
2007-06-12 11:27:09 -07:00
|
|
|
result =
|
|
|
|
NSToCoordRound(h * (float(ratio.width) / float(ratio.height)));
|
|
|
|
}
|
|
|
|
|
2008-07-17 16:37:12 -07:00
|
|
|
if (GetAbsoluteCoord(styleMaxHeight, h) ||
|
|
|
|
GetPercentHeight(styleMaxHeight, aFrame, h)) {
|
2007-06-12 11:27:09 -07:00
|
|
|
h = NSToCoordRound(h * (float(ratio.width) / float(ratio.height)));
|
|
|
|
if (h < result)
|
|
|
|
result = h;
|
|
|
|
}
|
|
|
|
|
2008-07-17 16:37:12 -07:00
|
|
|
if (GetAbsoluteCoord(styleMinHeight, h) ||
|
|
|
|
GetPercentHeight(styleMinHeight, aFrame, h)) {
|
2007-06-12 11:27:09 -07:00
|
|
|
h = NSToCoordRound(h * (float(ratio.width) / float(ratio.height)));
|
|
|
|
if (h > result)
|
|
|
|
result = h;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
2010-04-27 09:15:01 -07:00
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
if (aFrame->GetType() == nsGkAtoms::tableFrame) {
|
|
|
|
// Tables can't shrink smaller than their intrinsic minimum width,
|
|
|
|
// no matter what.
|
|
|
|
min = aFrame->GetMinWidth(aRenderingContext);
|
|
|
|
}
|
|
|
|
|
|
|
|
// We also need to track what has been added on outside of the box
|
|
|
|
// (controlled by 'box-sizing') where 'width', 'min-width' and
|
|
|
|
// 'max-width' are applied. We have to account for these properties
|
|
|
|
// after getting all the offsets (margin, border, padding) because
|
|
|
|
// percentages do not operate linearly.
|
|
|
|
// Doing this is ok because although percentages aren't handled
|
|
|
|
// linearly, they are handled monotonically.
|
|
|
|
nscoord coordOutsideWidth = offsets.hPadding;
|
|
|
|
float pctOutsideWidth = offsets.hPctPadding;
|
|
|
|
|
|
|
|
float pctTotal = 0.0f;
|
|
|
|
|
|
|
|
if (boxSizing == NS_STYLE_BOX_SIZING_PADDING) {
|
|
|
|
min += coordOutsideWidth;
|
2007-09-24 10:30:42 -07:00
|
|
|
result = NSCoordSaturatingAdd(result, coordOutsideWidth);
|
2007-03-22 10:30:00 -07:00
|
|
|
pctTotal += pctOutsideWidth;
|
|
|
|
|
|
|
|
coordOutsideWidth = 0;
|
|
|
|
pctOutsideWidth = 0.0f;
|
|
|
|
}
|
|
|
|
|
|
|
|
coordOutsideWidth += offsets.hBorder;
|
|
|
|
|
|
|
|
if (boxSizing == NS_STYLE_BOX_SIZING_BORDER) {
|
|
|
|
min += coordOutsideWidth;
|
2007-09-24 10:30:42 -07:00
|
|
|
result = NSCoordSaturatingAdd(result, coordOutsideWidth);
|
2007-03-22 10:30:00 -07:00
|
|
|
pctTotal += pctOutsideWidth;
|
|
|
|
|
|
|
|
coordOutsideWidth = 0;
|
|
|
|
pctOutsideWidth = 0.0f;
|
|
|
|
}
|
|
|
|
|
|
|
|
coordOutsideWidth += offsets.hMargin;
|
|
|
|
pctOutsideWidth += offsets.hPctMargin;
|
|
|
|
|
|
|
|
min += coordOutsideWidth;
|
2007-09-24 10:30:42 -07:00
|
|
|
result = NSCoordSaturatingAdd(result, coordOutsideWidth);
|
2007-03-22 10:30:00 -07:00
|
|
|
pctTotal += pctOutsideWidth;
|
|
|
|
|
|
|
|
nscoord w;
|
2008-07-17 16:37:12 -07:00
|
|
|
if (GetAbsoluteCoord(styleWidth, w) ||
|
2007-05-03 16:11:00 -07:00
|
|
|
GetIntrinsicCoord(styleWidth, aRenderingContext, aFrame,
|
|
|
|
PROP_WIDTH, w)) {
|
2007-03-22 10:30:00 -07:00
|
|
|
result = AddPercents(aType, w + coordOutsideWidth, pctOutsideWidth);
|
|
|
|
}
|
2010-08-11 12:32:53 -07:00
|
|
|
else if (aType == MIN_WIDTH &&
|
|
|
|
// The only cases of coord-percent-calc() units that
|
|
|
|
// GetAbsoluteCoord didn't handle are percent and calc()s
|
|
|
|
// containing percent.
|
|
|
|
styleWidth.IsCoordPercentCalcUnit() &&
|
2007-03-22 10:30:00 -07:00
|
|
|
aFrame->IsFrameOfType(nsIFrame::eReplaced)) {
|
|
|
|
// A percentage width on replaced elements means they can shrink to 0.
|
|
|
|
result = 0; // let |min| handle padding/border/margin
|
|
|
|
}
|
|
|
|
else {
|
2010-08-11 12:32:53 -07:00
|
|
|
// NOTE: We could really do a lot better for percents and for some
|
|
|
|
// cases of calc() containing percent (certainly including any where
|
|
|
|
// the coefficient on the percent is positive and there are no max()
|
|
|
|
// expressions). However, doing better for percents wouldn't be
|
|
|
|
// backwards compatible.
|
2007-03-22 10:30:00 -07:00
|
|
|
result = AddPercents(aType, result, pctTotal);
|
|
|
|
}
|
|
|
|
|
2010-08-25 03:17:56 -07:00
|
|
|
if (haveFixedMaxWidth ||
|
2007-05-03 16:11:00 -07:00
|
|
|
GetIntrinsicCoord(styleMaxWidth, aRenderingContext, aFrame,
|
|
|
|
PROP_MAX_WIDTH, maxw)) {
|
2007-03-22 10:30:00 -07:00
|
|
|
maxw = AddPercents(aType, maxw + coordOutsideWidth, pctOutsideWidth);
|
|
|
|
if (result > maxw)
|
|
|
|
result = maxw;
|
|
|
|
}
|
|
|
|
|
2010-08-25 03:17:56 -07:00
|
|
|
if (haveFixedMinWidth ||
|
2007-05-03 16:11:00 -07:00
|
|
|
GetIntrinsicCoord(styleMinWidth, aRenderingContext, aFrame,
|
|
|
|
PROP_MIN_WIDTH, minw)) {
|
2007-03-22 10:30:00 -07:00
|
|
|
minw = AddPercents(aType, minw + coordOutsideWidth, pctOutsideWidth);
|
|
|
|
if (result < minw)
|
|
|
|
result = minw;
|
|
|
|
}
|
|
|
|
|
|
|
|
min = AddPercents(aType, min, pctTotal);
|
|
|
|
if (result < min)
|
|
|
|
result = min;
|
|
|
|
|
|
|
|
const nsStyleDisplay *disp = aFrame->GetStyleDisplay();
|
|
|
|
if (aFrame->IsThemed(disp)) {
|
2009-01-14 19:27:09 -08:00
|
|
|
nsIntSize size(0, 0);
|
2011-09-28 23:19:26 -07:00
|
|
|
bool canOverride = true;
|
2007-03-30 14:11:41 -07:00
|
|
|
nsPresContext *presContext = aFrame->PresContext();
|
2007-03-22 10:30:00 -07:00
|
|
|
presContext->GetTheme()->
|
|
|
|
GetMinimumWidgetSize(aRenderingContext, aFrame, disp->mAppearance,
|
|
|
|
&size, &canOverride);
|
|
|
|
|
|
|
|
nscoord themeWidth = presContext->DevPixelsToAppUnits(size.width);
|
|
|
|
|
|
|
|
// GMWS() returns a border-box width
|
|
|
|
themeWidth += offsets.hMargin;
|
|
|
|
themeWidth = AddPercents(aType, themeWidth, offsets.hPctMargin);
|
|
|
|
|
|
|
|
if (themeWidth > result || !canOverride)
|
|
|
|
result = themeWidth;
|
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef DEBUG_INTRINSIC_WIDTH
|
|
|
|
nsFrame::IndentBy(stdout, gNoiseIndent);
|
2007-07-08 00:08:04 -07:00
|
|
|
static_cast<nsFrame*>(aFrame)->ListTag(stdout);
|
2007-03-22 10:30:00 -07:00
|
|
|
printf(" %s intrinsic width for container is %d twips.\n",
|
|
|
|
aType == MIN_WIDTH ? "min" : "pref", result);
|
|
|
|
#endif
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* static */ nscoord
|
|
|
|
nsLayoutUtils::ComputeWidthDependentValue(
|
|
|
|
nscoord aContainingBlockWidth,
|
|
|
|
const nsStyleCoord& aCoord)
|
|
|
|
{
|
2010-06-28 13:47:39 -07:00
|
|
|
NS_WARN_IF_FALSE(aContainingBlockWidth != NS_UNCONSTRAINEDSIZE,
|
|
|
|
"have unconstrained width; this should only result from "
|
|
|
|
"very large sizes, not attempts at intrinsic width "
|
|
|
|
"calculation");
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2010-08-25 03:17:55 -07:00
|
|
|
if (aCoord.IsCoordPercentCalcUnit()) {
|
|
|
|
return nsRuleNode::ComputeCoordPercentCalc(aCoord, aContainingBlockWidth);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
2007-05-10 23:01:31 -07:00
|
|
|
NS_ASSERTION(aCoord.GetUnit() == eStyleUnit_None ||
|
2007-05-03 16:11:00 -07:00
|
|
|
aCoord.GetUnit() == eStyleUnit_Auto,
|
|
|
|
"unexpected width value");
|
2007-03-22 10:30:00 -07:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2007-05-03 16:11:00 -07:00
|
|
|
/* static */ nscoord
|
|
|
|
nsLayoutUtils::ComputeWidthValue(
|
2011-04-07 18:04:40 -07:00
|
|
|
nsRenderingContext* aRenderingContext,
|
2007-05-03 16:11:00 -07:00
|
|
|
nsIFrame* aFrame,
|
|
|
|
nscoord aContainingBlockWidth,
|
|
|
|
nscoord aContentEdgeToBoxSizing,
|
|
|
|
nscoord aBoxSizingToMarginEdge,
|
|
|
|
const nsStyleCoord& aCoord)
|
|
|
|
{
|
|
|
|
NS_PRECONDITION(aFrame, "non-null frame expected");
|
|
|
|
NS_PRECONDITION(aRenderingContext, "non-null rendering context expected");
|
2009-10-28 20:22:28 -07:00
|
|
|
NS_WARN_IF_FALSE(aContainingBlockWidth != NS_UNCONSTRAINEDSIZE,
|
|
|
|
"have unconstrained width; this should only result from "
|
|
|
|
"very large sizes, not attempts at intrinsic width "
|
|
|
|
"calculation");
|
2007-05-03 16:11:00 -07:00
|
|
|
NS_PRECONDITION(aContainingBlockWidth >= 0,
|
|
|
|
"width less than zero");
|
|
|
|
|
|
|
|
nscoord result;
|
2010-08-11 12:32:53 -07:00
|
|
|
if (aCoord.IsCoordPercentCalcUnit()) {
|
2012-08-08 08:58:26 -07:00
|
|
|
result = nsRuleNode::ComputeCoordPercentCalc(aCoord,
|
|
|
|
aContainingBlockWidth);
|
2010-08-11 12:32:53 -07:00
|
|
|
// The result of a calc() expression might be less than 0; we
|
|
|
|
// should clamp at runtime (below). (Percentages and coords that
|
|
|
|
// are less than 0 have already been dropped by the parser.)
|
2007-05-03 16:11:00 -07:00
|
|
|
result -= aContentEdgeToBoxSizing;
|
2012-08-08 08:58:26 -07:00
|
|
|
} else {
|
|
|
|
MOZ_ASSERT(eStyleUnit_Enumerated == aCoord.GetUnit());
|
2012-01-24 17:21:29 -08:00
|
|
|
// If aFrame is a container for font size inflation, then shrink
|
|
|
|
// wrapping inside of it should not apply font size inflation.
|
2012-05-20 22:18:27 -07:00
|
|
|
AutoMaybeDisableFontInflation an(aFrame);
|
2012-01-24 17:21:29 -08:00
|
|
|
|
2012-08-22 08:56:38 -07:00
|
|
|
int32_t val = aCoord.GetIntValue();
|
2007-05-03 16:11:00 -07:00
|
|
|
switch (val) {
|
2007-11-15 10:10:31 -08:00
|
|
|
case NS_STYLE_WIDTH_MAX_CONTENT:
|
2007-05-03 16:11:00 -07:00
|
|
|
result = aFrame->GetPrefWidth(aRenderingContext);
|
|
|
|
NS_ASSERTION(result >= 0, "width less than zero");
|
|
|
|
break;
|
2007-11-15 10:10:31 -08:00
|
|
|
case NS_STYLE_WIDTH_MIN_CONTENT:
|
2007-05-03 16:11:00 -07:00
|
|
|
result = aFrame->GetMinWidth(aRenderingContext);
|
|
|
|
NS_ASSERTION(result >= 0, "width less than zero");
|
|
|
|
break;
|
2007-11-15 10:10:31 -08:00
|
|
|
case NS_STYLE_WIDTH_FIT_CONTENT:
|
2007-05-03 16:11:00 -07:00
|
|
|
{
|
|
|
|
nscoord pref = aFrame->GetPrefWidth(aRenderingContext),
|
|
|
|
min = aFrame->GetMinWidth(aRenderingContext),
|
|
|
|
fill = aContainingBlockWidth -
|
|
|
|
(aBoxSizingToMarginEdge + aContentEdgeToBoxSizing);
|
2009-09-16 08:01:36 -07:00
|
|
|
result = NS_MAX(min, NS_MIN(pref, fill));
|
2007-05-03 16:11:00 -07:00
|
|
|
NS_ASSERTION(result >= 0, "width less than zero");
|
|
|
|
}
|
|
|
|
break;
|
2007-11-15 10:10:31 -08:00
|
|
|
case NS_STYLE_WIDTH_AVAILABLE:
|
2007-05-03 16:11:00 -07:00
|
|
|
result = aContainingBlockWidth -
|
|
|
|
(aBoxSizingToMarginEdge + aContentEdgeToBoxSizing);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-08-08 08:58:26 -07:00
|
|
|
return NS_MAX(0, result);
|
|
|
|
}
|
2007-05-03 16:11:00 -07:00
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
/* static */ nscoord
|
|
|
|
nsLayoutUtils::ComputeHeightDependentValue(
|
|
|
|
nscoord aContainingBlockHeight,
|
|
|
|
const nsStyleCoord& aCoord)
|
|
|
|
{
|
2010-08-25 03:17:55 -07:00
|
|
|
// XXXldb Some callers explicitly check aContainingBlockHeight
|
|
|
|
// against NS_AUTOHEIGHT *and* unit against eStyleUnit_Percent or
|
|
|
|
// calc()s containing percents before calling this function.
|
|
|
|
// However, it would be much more likely to catch problems without
|
|
|
|
// the unit conditions.
|
|
|
|
// XXXldb Many callers pass a non-'auto' containing block height when
|
|
|
|
// according to CSS2.1 they should be passing 'auto'.
|
|
|
|
NS_PRECONDITION(NS_AUTOHEIGHT != aContainingBlockHeight ||
|
2010-08-25 03:17:55 -07:00
|
|
|
!aCoord.HasPercent(),
|
2010-08-25 03:17:55 -07:00
|
|
|
"unexpected containing block height");
|
|
|
|
|
|
|
|
if (aCoord.IsCoordPercentCalcUnit()) {
|
|
|
|
return nsRuleNode::ComputeCoordPercentCalc(aCoord, aContainingBlockHeight);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
2010-08-25 03:17:55 -07:00
|
|
|
|
2007-05-10 23:01:31 -07:00
|
|
|
NS_ASSERTION(aCoord.GetUnit() == eStyleUnit_None ||
|
2007-05-03 16:11:00 -07:00
|
|
|
aCoord.GetUnit() == eStyleUnit_Auto,
|
|
|
|
"unexpected height value");
|
2007-03-22 10:30:00 -07:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2012-08-22 08:56:38 -07:00
|
|
|
#define MULDIV(a,b,c) (nscoord(int64_t(a) * int64_t(b) / int64_t(c)))
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
/* static */ nsSize
|
|
|
|
nsLayoutUtils::ComputeSizeWithIntrinsicDimensions(
|
2011-04-07 18:04:40 -07:00
|
|
|
nsRenderingContext* aRenderingContext, nsIFrame* aFrame,
|
2007-11-18 06:22:55 -08:00
|
|
|
const nsIFrame::IntrinsicSize& aIntrinsicSize,
|
2007-11-18 04:09:03 -08:00
|
|
|
nsSize aIntrinsicRatio, nsSize aCBSize,
|
2007-05-03 16:11:00 -07:00
|
|
|
nsSize aMargin, nsSize aBorder, nsSize aPadding)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2012-09-05 14:13:37 -07:00
|
|
|
const nsStylePosition* stylePos = aFrame->GetStylePosition();
|
|
|
|
|
|
|
|
// If we're a flex item, we'll compute our size a bit differently.
|
|
|
|
const nsStyleCoord* widthStyleCoord = &(stylePos->mWidth);
|
|
|
|
const nsStyleCoord* heightStyleCoord = &(stylePos->mHeight);
|
|
|
|
|
|
|
|
bool isFlexItem = aFrame->IsFlexItem();
|
|
|
|
bool isHorizontalFlexItem = false;
|
|
|
|
|
|
|
|
#ifdef MOZ_FLEXBOX
|
|
|
|
if (isFlexItem) {
|
|
|
|
// Flex items use their "flex-basis" property in place of their main-size
|
|
|
|
// property (e.g. "width") for sizing purposes, *unless* they have
|
|
|
|
// "flex-basis:auto", in which case they use their main-size property after
|
|
|
|
// all.
|
|
|
|
uint32_t flexDirection =
|
|
|
|
aFrame->GetParent()->GetStylePosition()->mFlexDirection;
|
|
|
|
isHorizontalFlexItem =
|
|
|
|
flexDirection == NS_STYLE_FLEX_DIRECTION_ROW ||
|
|
|
|
flexDirection == NS_STYLE_FLEX_DIRECTION_ROW_REVERSE;
|
|
|
|
|
|
|
|
if (stylePos->mFlexBasis.GetUnit() != eStyleUnit_Auto) {
|
|
|
|
if (isHorizontalFlexItem) {
|
|
|
|
widthStyleCoord = &(stylePos->mFlexBasis);
|
|
|
|
} else {
|
|
|
|
heightStyleCoord = &(stylePos->mFlexBasis);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif // MOZ_FLEXBOX
|
|
|
|
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
// Handle intrinsic sizes and their interaction with
|
|
|
|
// {min-,max-,}{width,height} according to the rules in
|
|
|
|
// http://www.w3.org/TR/CSS21/visudet.html#min-max-widths
|
|
|
|
|
|
|
|
// Note: throughout the following section of the function, I avoid
|
|
|
|
// a * (b / c) because of its reduced accuracy relative to a * b / c
|
|
|
|
// or (a * b) / c (which are equivalent).
|
|
|
|
|
2012-09-05 14:13:37 -07:00
|
|
|
const bool isAutoWidth = widthStyleCoord->GetUnit() == eStyleUnit_Auto;
|
|
|
|
const bool isAutoHeight = IsAutoHeight(*heightStyleCoord, aCBSize.height);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
nsSize boxSizingAdjust(0,0);
|
|
|
|
switch (stylePos->mBoxSizing) {
|
|
|
|
case NS_STYLE_BOX_SIZING_BORDER:
|
|
|
|
boxSizingAdjust += aBorder;
|
|
|
|
// fall through
|
|
|
|
case NS_STYLE_BOX_SIZING_PADDING:
|
|
|
|
boxSizingAdjust += aPadding;
|
|
|
|
}
|
2007-05-03 16:11:00 -07:00
|
|
|
nscoord boxSizingToMarginEdgeWidth =
|
|
|
|
aMargin.width + aBorder.width + aPadding.width - boxSizingAdjust.width;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
nscoord width, minWidth, maxWidth, height, minHeight, maxHeight;
|
|
|
|
|
|
|
|
if (!isAutoWidth) {
|
2007-05-03 16:11:00 -07:00
|
|
|
width = nsLayoutUtils::ComputeWidthValue(aRenderingContext,
|
|
|
|
aFrame, aCBSize.width, boxSizingAdjust.width,
|
2012-09-05 14:13:37 -07:00
|
|
|
boxSizingToMarginEdgeWidth, *widthStyleCoord);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2012-09-05 14:13:37 -07:00
|
|
|
if (stylePos->mMaxWidth.GetUnit() != eStyleUnit_None &&
|
|
|
|
!(isFlexItem && isHorizontalFlexItem)) {
|
2007-05-03 16:11:00 -07:00
|
|
|
maxWidth = nsLayoutUtils::ComputeWidthValue(aRenderingContext,
|
|
|
|
aFrame, aCBSize.width, boxSizingAdjust.width,
|
|
|
|
boxSizingToMarginEdgeWidth, stylePos->mMaxWidth);
|
2007-03-22 10:30:00 -07:00
|
|
|
} else {
|
|
|
|
maxWidth = nscoord_MAX;
|
|
|
|
}
|
|
|
|
|
2012-09-05 14:13:37 -07:00
|
|
|
// NOTE: Flex items ignore their min & max sizing properties in their
|
|
|
|
// flex container's main-axis. (Those properties get applied later in
|
|
|
|
// the flexbox algorithm.)
|
|
|
|
if (stylePos->mMinWidth.GetUnit() != eStyleUnit_Auto &&
|
|
|
|
!(isFlexItem && isHorizontalFlexItem)) {
|
2012-09-04 16:26:10 -07:00
|
|
|
minWidth = nsLayoutUtils::ComputeWidthValue(aRenderingContext,
|
|
|
|
aFrame, aCBSize.width, boxSizingAdjust.width,
|
|
|
|
boxSizingToMarginEdgeWidth, stylePos->mMinWidth);
|
|
|
|
} else {
|
|
|
|
// Treat "min-width: auto" as 0.
|
|
|
|
// NOTE: Technically, "auto" is supposed to behave like "min-content" on
|
|
|
|
// flex items. However, we don't need to worry about that here, because
|
|
|
|
// flex items' min-sizes are intentionally ignored until the flex
|
|
|
|
// container explicitly considers them during space distribution.
|
|
|
|
minWidth = 0;
|
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
if (!isAutoHeight) {
|
2012-08-08 08:58:26 -07:00
|
|
|
height = nsLayoutUtils::ComputeHeightValue(aCBSize.height,
|
|
|
|
boxSizingAdjust.height,
|
2012-09-05 14:13:37 -07:00
|
|
|
*heightStyleCoord);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2012-09-05 14:13:37 -07:00
|
|
|
if (!IsAutoHeight(stylePos->mMaxHeight, aCBSize.height) &&
|
|
|
|
!(isFlexItem && !isHorizontalFlexItem)) {
|
2012-08-08 08:58:26 -07:00
|
|
|
maxHeight = nsLayoutUtils::ComputeHeightValue(aCBSize.height,
|
|
|
|
boxSizingAdjust.height,
|
|
|
|
stylePos->mMaxHeight);
|
2007-03-22 10:30:00 -07:00
|
|
|
} else {
|
|
|
|
maxHeight = nscoord_MAX;
|
|
|
|
}
|
|
|
|
|
2012-09-05 14:13:37 -07:00
|
|
|
if (!IsAutoHeight(stylePos->mMinHeight, aCBSize.height) &&
|
|
|
|
!(isFlexItem && !isHorizontalFlexItem)) {
|
2012-08-08 08:58:26 -07:00
|
|
|
minHeight = nsLayoutUtils::ComputeHeightValue(aCBSize.height,
|
|
|
|
boxSizingAdjust.height,
|
|
|
|
stylePos->mMinHeight);
|
2007-03-22 10:30:00 -07:00
|
|
|
} else {
|
|
|
|
minHeight = 0;
|
|
|
|
}
|
|
|
|
|
2007-11-18 04:09:03 -08:00
|
|
|
// Resolve percentage intrinsic width/height as necessary:
|
|
|
|
|
|
|
|
NS_ASSERTION(aCBSize.width != NS_UNCONSTRAINEDSIZE,
|
|
|
|
"Our containing block must not have unconstrained width!");
|
|
|
|
|
2011-09-28 23:19:26 -07:00
|
|
|
bool hasIntrinsicWidth, hasIntrinsicHeight;
|
2007-11-18 04:09:03 -08:00
|
|
|
nscoord intrinsicWidth, intrinsicHeight;
|
|
|
|
|
2011-06-12 18:52:32 -07:00
|
|
|
if (aIntrinsicSize.width.GetUnit() == eStyleUnit_Coord) {
|
2011-10-17 07:59:28 -07:00
|
|
|
hasIntrinsicWidth = true;
|
2011-06-12 18:52:32 -07:00
|
|
|
intrinsicWidth = aIntrinsicSize.width.GetCoordValue();
|
|
|
|
if (intrinsicWidth < 0)
|
|
|
|
intrinsicWidth = 0;
|
2007-11-18 04:09:03 -08:00
|
|
|
} else {
|
2011-06-12 18:52:32 -07:00
|
|
|
NS_ASSERTION(aIntrinsicSize.width.GetUnit() == eStyleUnit_None,
|
|
|
|
"unexpected unit");
|
2011-10-17 07:59:28 -07:00
|
|
|
hasIntrinsicWidth = false;
|
2007-11-18 04:09:03 -08:00
|
|
|
intrinsicWidth = 0;
|
|
|
|
}
|
|
|
|
|
2011-06-12 18:52:32 -07:00
|
|
|
if (aIntrinsicSize.height.GetUnit() == eStyleUnit_Coord) {
|
2011-10-17 07:59:28 -07:00
|
|
|
hasIntrinsicHeight = true;
|
2011-06-12 18:52:32 -07:00
|
|
|
intrinsicHeight = aIntrinsicSize.height.GetCoordValue();
|
2007-11-18 04:09:03 -08:00
|
|
|
if (intrinsicHeight < 0)
|
|
|
|
intrinsicHeight = 0;
|
|
|
|
} else {
|
2011-06-12 18:52:32 -07:00
|
|
|
NS_ASSERTION(aIntrinsicSize.height.GetUnit() == eStyleUnit_None,
|
|
|
|
"unexpected unit");
|
2011-10-17 07:59:28 -07:00
|
|
|
hasIntrinsicHeight = false;
|
2007-11-18 04:09:03 -08:00
|
|
|
intrinsicHeight = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_ASSERTION(aIntrinsicRatio.width >= 0 && aIntrinsicRatio.height >= 0,
|
|
|
|
"Intrinsic ratio has a negative component!");
|
|
|
|
|
|
|
|
// Now calculate the used values for width and height:
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
if (isAutoWidth) {
|
|
|
|
if (isAutoHeight) {
|
|
|
|
|
|
|
|
// 'auto' width, 'auto' height
|
2007-11-18 04:09:03 -08:00
|
|
|
|
|
|
|
// Get tentative values - CSS 2.1 sections 10.3.2 and 10.6.2:
|
|
|
|
|
|
|
|
nscoord tentWidth, tentHeight;
|
|
|
|
|
|
|
|
if (hasIntrinsicWidth) {
|
|
|
|
tentWidth = intrinsicWidth;
|
|
|
|
} else if (hasIntrinsicHeight && aIntrinsicRatio.height > 0) {
|
|
|
|
tentWidth = MULDIV(intrinsicHeight, aIntrinsicRatio.width, aIntrinsicRatio.height);
|
|
|
|
} else if (aIntrinsicRatio.width > 0) {
|
|
|
|
tentWidth = aCBSize.width - boxSizingToMarginEdgeWidth; // XXX scrollbar?
|
|
|
|
if (tentWidth < 0) tentWidth = 0;
|
|
|
|
} else {
|
|
|
|
tentWidth = nsPresContext::CSSPixelsToAppUnits(300);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (hasIntrinsicHeight) {
|
|
|
|
tentHeight = intrinsicHeight;
|
|
|
|
} else if (aIntrinsicRatio.width > 0) {
|
|
|
|
tentHeight = MULDIV(tentWidth, aIntrinsicRatio.height, aIntrinsicRatio.width);
|
|
|
|
} else {
|
|
|
|
tentHeight = nsPresContext::CSSPixelsToAppUnits(150);
|
|
|
|
}
|
|
|
|
|
2011-08-05 12:24:24 -07:00
|
|
|
return ComputeAutoSizeWithIntrinsicDimensions(minWidth, minHeight,
|
|
|
|
maxWidth, maxHeight,
|
|
|
|
tentWidth, tentHeight);
|
2007-03-22 10:30:00 -07:00
|
|
|
} else {
|
|
|
|
|
|
|
|
// 'auto' width, non-'auto' height
|
|
|
|
height = NS_CSS_MINMAX(height, minHeight, maxHeight);
|
2007-11-18 04:09:03 -08:00
|
|
|
if (aIntrinsicRatio.height > 0) {
|
|
|
|
width = MULDIV(height, aIntrinsicRatio.width, aIntrinsicRatio.height);
|
|
|
|
} else if (hasIntrinsicWidth) {
|
|
|
|
width = intrinsicWidth;
|
2007-03-22 10:30:00 -07:00
|
|
|
} else {
|
2007-11-18 04:09:03 -08:00
|
|
|
width = nsPresContext::CSSPixelsToAppUnits(300);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
width = NS_CSS_MINMAX(width, minWidth, maxWidth);
|
|
|
|
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if (isAutoHeight) {
|
|
|
|
|
|
|
|
// non-'auto' width, 'auto' height
|
|
|
|
width = NS_CSS_MINMAX(width, minWidth, maxWidth);
|
2007-11-18 04:09:03 -08:00
|
|
|
if (aIntrinsicRatio.width > 0) {
|
|
|
|
height = MULDIV(width, aIntrinsicRatio.height, aIntrinsicRatio.width);
|
|
|
|
} else if (hasIntrinsicHeight) {
|
|
|
|
height = intrinsicHeight;
|
2007-03-22 10:30:00 -07:00
|
|
|
} else {
|
2007-11-18 04:09:03 -08:00
|
|
|
height = nsPresContext::CSSPixelsToAppUnits(150);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
height = NS_CSS_MINMAX(height, minHeight, maxHeight);
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
// non-'auto' width, non-'auto' height
|
|
|
|
width = NS_CSS_MINMAX(width, minWidth, maxWidth);
|
2007-11-18 04:09:03 -08:00
|
|
|
height = NS_CSS_MINMAX(height, minHeight, maxHeight);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return nsSize(width, height);
|
|
|
|
}
|
|
|
|
|
2011-08-05 12:24:24 -07:00
|
|
|
nsSize
|
|
|
|
nsLayoutUtils::ComputeAutoSizeWithIntrinsicDimensions(nscoord minWidth, nscoord minHeight,
|
|
|
|
nscoord maxWidth, nscoord maxHeight,
|
|
|
|
nscoord tentWidth, nscoord tentHeight)
|
|
|
|
{
|
|
|
|
// Now apply min/max-width/height - CSS 2.1 sections 10.4 and 10.7:
|
|
|
|
|
|
|
|
if (minWidth > maxWidth)
|
|
|
|
maxWidth = minWidth;
|
|
|
|
if (minHeight > maxHeight)
|
|
|
|
maxHeight = minHeight;
|
|
|
|
|
|
|
|
nscoord heightAtMaxWidth, heightAtMinWidth,
|
|
|
|
widthAtMaxHeight, widthAtMinHeight;
|
|
|
|
|
|
|
|
if (tentWidth > 0) {
|
|
|
|
heightAtMaxWidth = MULDIV(maxWidth, tentHeight, tentWidth);
|
|
|
|
if (heightAtMaxWidth < minHeight)
|
|
|
|
heightAtMaxWidth = minHeight;
|
|
|
|
heightAtMinWidth = MULDIV(minWidth, tentHeight, tentWidth);
|
|
|
|
if (heightAtMinWidth > maxHeight)
|
|
|
|
heightAtMinWidth = maxHeight;
|
|
|
|
} else {
|
2011-08-17 17:54:59 -07:00
|
|
|
heightAtMaxWidth = heightAtMinWidth = NS_CSS_MINMAX(tentHeight, minHeight, maxHeight);
|
2011-08-05 12:24:24 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
if (tentHeight > 0) {
|
|
|
|
widthAtMaxHeight = MULDIV(maxHeight, tentWidth, tentHeight);
|
|
|
|
if (widthAtMaxHeight < minWidth)
|
|
|
|
widthAtMaxHeight = minWidth;
|
|
|
|
widthAtMinHeight = MULDIV(minHeight, tentWidth, tentHeight);
|
|
|
|
if (widthAtMinHeight > maxWidth)
|
|
|
|
widthAtMinHeight = maxWidth;
|
|
|
|
} else {
|
2011-08-17 17:54:59 -07:00
|
|
|
widthAtMaxHeight = widthAtMinHeight = NS_CSS_MINMAX(tentWidth, minWidth, maxWidth);
|
2011-08-05 12:24:24 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
// The table at http://www.w3.org/TR/CSS21/visudet.html#min-max-widths :
|
|
|
|
|
|
|
|
nscoord width, height;
|
|
|
|
|
|
|
|
if (tentWidth > maxWidth) {
|
|
|
|
if (tentHeight > maxHeight) {
|
2012-08-22 08:56:38 -07:00
|
|
|
if (int64_t(maxWidth) * int64_t(tentHeight) <=
|
|
|
|
int64_t(maxHeight) * int64_t(tentWidth)) {
|
2011-08-05 12:24:24 -07:00
|
|
|
width = maxWidth;
|
|
|
|
height = heightAtMaxWidth;
|
|
|
|
} else {
|
|
|
|
width = widthAtMaxHeight;
|
|
|
|
height = maxHeight;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
// This also covers "(w > max-width) and (h < min-height)" since in
|
|
|
|
// that case (max-width/w < 1), and with (h < min-height):
|
|
|
|
// max(max-width * h/w, min-height) == min-height
|
|
|
|
width = maxWidth;
|
|
|
|
height = heightAtMaxWidth;
|
|
|
|
}
|
|
|
|
} else if (tentWidth < minWidth) {
|
|
|
|
if (tentHeight < minHeight) {
|
2012-08-22 08:56:38 -07:00
|
|
|
if (int64_t(minWidth) * int64_t(tentHeight) <=
|
|
|
|
int64_t(minHeight) * int64_t(tentWidth)) {
|
2011-08-05 12:24:24 -07:00
|
|
|
width = widthAtMinHeight;
|
|
|
|
height = minHeight;
|
|
|
|
} else {
|
|
|
|
width = minWidth;
|
|
|
|
height = heightAtMinWidth;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
// This also covers "(w < min-width) and (h > max-height)" since in
|
|
|
|
// that case (min-width/w > 1), and with (h > max-height):
|
|
|
|
// min(min-width * h/w, max-height) == max-height
|
|
|
|
width = minWidth;
|
|
|
|
height = heightAtMinWidth;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if (tentHeight > maxHeight) {
|
|
|
|
width = widthAtMaxHeight;
|
|
|
|
height = maxHeight;
|
|
|
|
} else if (tentHeight < minHeight) {
|
|
|
|
width = widthAtMinHeight;
|
|
|
|
height = minHeight;
|
|
|
|
} else {
|
|
|
|
width = tentWidth;
|
|
|
|
height = tentHeight;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return nsSize(width, height);
|
|
|
|
}
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
/* static */ nscoord
|
|
|
|
nsLayoutUtils::MinWidthFromInline(nsIFrame* aFrame,
|
2011-04-07 18:04:40 -07:00
|
|
|
nsRenderingContext* aRenderingContext)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2012-01-24 17:21:29 -08:00
|
|
|
NS_ASSERTION(!nsLayoutUtils::IsContainerForFontSizeInflation(aFrame),
|
|
|
|
"should not be container for font size inflation");
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
nsIFrame::InlineMinWidthData data;
|
|
|
|
DISPLAY_MIN_WIDTH(aFrame, data.prevLines);
|
|
|
|
aFrame->AddInlineMinWidth(aRenderingContext, &data);
|
2007-06-21 15:32:47 -07:00
|
|
|
data.ForceBreak(aRenderingContext);
|
2007-03-22 10:30:00 -07:00
|
|
|
return data.prevLines;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* static */ nscoord
|
|
|
|
nsLayoutUtils::PrefWidthFromInline(nsIFrame* aFrame,
|
2011-04-07 18:04:40 -07:00
|
|
|
nsRenderingContext* aRenderingContext)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2012-01-24 17:21:29 -08:00
|
|
|
NS_ASSERTION(!nsLayoutUtils::IsContainerForFontSizeInflation(aFrame),
|
|
|
|
"should not be container for font size inflation");
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
nsIFrame::InlinePrefWidthData data;
|
|
|
|
DISPLAY_PREF_WIDTH(aFrame, data.prevLines);
|
|
|
|
aFrame->AddInlinePrefWidth(aRenderingContext, &data);
|
2007-06-21 15:32:47 -07:00
|
|
|
data.ForceBreak(aRenderingContext);
|
2007-03-22 10:30:00 -07:00
|
|
|
return data.prevLines;
|
|
|
|
}
|
|
|
|
|
2011-06-22 11:11:48 -07:00
|
|
|
static nscolor
|
|
|
|
DarkenColor(nscolor aColor)
|
|
|
|
{
|
2012-08-22 08:56:38 -07:00
|
|
|
uint16_t hue, sat, value;
|
|
|
|
uint8_t alpha;
|
2011-06-22 11:11:48 -07:00
|
|
|
|
|
|
|
// convert the RBG to HSV so we can get the lightness (which is the v)
|
|
|
|
NS_RGB2HSV(aColor, hue, sat, value, alpha);
|
|
|
|
|
|
|
|
// The goal here is to send white to black while letting colored
|
|
|
|
// stuff stay colored... So we adopt the following approach.
|
|
|
|
// Something with sat = 0 should end up with value = 0. Something
|
|
|
|
// with a high sat can end up with a high value and it's ok.... At
|
|
|
|
// the same time, we don't want to make things lighter. Do
|
|
|
|
// something simple, since it seems to work.
|
|
|
|
if (value > sat) {
|
|
|
|
value = sat;
|
|
|
|
// convert this color back into the RGB color space.
|
|
|
|
NS_HSV2RGB(aColor, hue, sat, value, alpha);
|
|
|
|
}
|
|
|
|
return aColor;
|
|
|
|
}
|
|
|
|
|
2011-08-09 08:14:36 -07:00
|
|
|
// Check whether we should darken text/decoration colors. We need to do this if
|
2011-06-22 11:11:48 -07:00
|
|
|
// background images and colors are being suppressed, because that means
|
|
|
|
// light text will not be visible against the (presumed light-colored) background.
|
2011-09-28 23:19:26 -07:00
|
|
|
static bool
|
2011-06-22 11:11:48 -07:00
|
|
|
ShouldDarkenColors(nsPresContext* aPresContext)
|
|
|
|
{
|
|
|
|
return !aPresContext->GetBackgroundColorDraw() &&
|
2011-08-09 08:14:36 -07:00
|
|
|
!aPresContext->GetBackgroundImageDraw();
|
2011-06-22 11:11:48 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
nscolor
|
2011-08-09 08:14:36 -07:00
|
|
|
nsLayoutUtils::GetColor(nsIFrame* aFrame, nsCSSProperty aProperty)
|
2011-06-22 11:11:48 -07:00
|
|
|
{
|
2011-08-09 08:14:36 -07:00
|
|
|
nscolor color = aFrame->GetVisitedDependentColor(aProperty);
|
2011-06-22 11:11:48 -07:00
|
|
|
if (ShouldDarkenColors(aFrame->PresContext())) {
|
|
|
|
color = DarkenColor(color);
|
|
|
|
}
|
|
|
|
return color;
|
|
|
|
}
|
|
|
|
|
2011-07-03 22:47:59 -07:00
|
|
|
gfxFloat
|
|
|
|
nsLayoutUtils::GetSnappedBaselineY(nsIFrame* aFrame, gfxContext* aContext,
|
|
|
|
nscoord aY, nscoord aAscent)
|
|
|
|
{
|
|
|
|
gfxFloat appUnitsPerDevUnit = aFrame->PresContext()->AppUnitsPerDevPixel();
|
|
|
|
gfxFloat baseline = gfxFloat(aY) + aAscent;
|
|
|
|
gfxRect putativeRect(0, baseline/appUnitsPerDevUnit, 1, 1);
|
2011-10-17 07:59:28 -07:00
|
|
|
if (!aContext->UserToDevicePixelSnapped(putativeRect, true))
|
2011-07-03 22:47:59 -07:00
|
|
|
return baseline;
|
|
|
|
return aContext->DeviceToUser(putativeRect.TopLeft()).y * appUnitsPerDevUnit;
|
|
|
|
}
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
void
|
|
|
|
nsLayoutUtils::DrawString(const nsIFrame* aFrame,
|
2011-04-07 18:04:40 -07:00
|
|
|
nsRenderingContext* aContext,
|
2007-03-22 10:30:00 -07:00
|
|
|
const PRUnichar* aString,
|
2012-08-22 08:56:38 -07:00
|
|
|
int32_t aLength,
|
2009-02-14 23:21:40 -08:00
|
|
|
nsPoint aPoint,
|
2012-08-22 08:56:38 -07:00
|
|
|
uint8_t aDirection)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
#ifdef IBMBIDI
|
|
|
|
nsresult rv = NS_ERROR_FAILURE;
|
2007-03-30 14:11:41 -07:00
|
|
|
nsPresContext* presContext = aFrame->PresContext();
|
2007-03-22 10:30:00 -07:00
|
|
|
if (presContext->BidiEnabled()) {
|
2011-04-13 02:23:49 -07:00
|
|
|
if (aDirection == NS_STYLE_DIRECTION_INHERIT) {
|
|
|
|
aDirection = aFrame->GetStyleVisibility()->mDirection;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
2011-04-13 02:23:49 -07:00
|
|
|
nsBidiDirection direction =
|
|
|
|
(NS_STYLE_DIRECTION_RTL == aDirection) ?
|
|
|
|
NSBIDI_RTL : NSBIDI_LTR;
|
|
|
|
rv = nsBidiPresUtils::RenderText(aString, aLength, direction,
|
|
|
|
presContext, *aContext, *aContext,
|
|
|
|
aPoint.x, aPoint.y);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
if (NS_FAILED(rv))
|
|
|
|
#endif // IBMBIDI
|
2010-04-27 09:15:01 -07:00
|
|
|
{
|
2011-10-17 07:59:28 -07:00
|
|
|
aContext->SetTextRunRTL(false);
|
2007-03-22 10:30:00 -07:00
|
|
|
aContext->DrawString(aString, aLength, aPoint.x, aPoint.y);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
nscoord
|
|
|
|
nsLayoutUtils::GetStringWidth(const nsIFrame* aFrame,
|
2011-04-07 18:04:40 -07:00
|
|
|
nsRenderingContext* aContext,
|
2007-03-22 10:30:00 -07:00
|
|
|
const PRUnichar* aString,
|
2012-08-22 08:56:38 -07:00
|
|
|
int32_t aLength)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
#ifdef IBMBIDI
|
2008-08-11 08:19:01 -07:00
|
|
|
nsPresContext* presContext = aFrame->PresContext();
|
|
|
|
if (presContext->BidiEnabled()) {
|
2011-04-13 02:23:49 -07:00
|
|
|
const nsStyleVisibility* vis = aFrame->GetStyleVisibility();
|
|
|
|
nsBidiDirection direction =
|
|
|
|
(NS_STYLE_DIRECTION_RTL == vis->mDirection) ?
|
|
|
|
NSBIDI_RTL : NSBIDI_LTR;
|
|
|
|
return nsBidiPresUtils::MeasureTextWidth(aString, aLength,
|
|
|
|
direction, presContext, *aContext);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
#endif // IBMBIDI
|
2011-10-17 07:59:28 -07:00
|
|
|
aContext->SetTextRunRTL(false);
|
2011-04-07 18:04:40 -07:00
|
|
|
return aContext->GetWidth(aString, aLength);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2011-06-30 23:43:11 -07:00
|
|
|
/* static */ void
|
|
|
|
nsLayoutUtils::PaintTextShadow(const nsIFrame* aFrame,
|
|
|
|
nsRenderingContext* aContext,
|
|
|
|
const nsRect& aTextRect,
|
|
|
|
const nsRect& aDirtyRect,
|
|
|
|
const nscolor& aForegroundColor,
|
|
|
|
TextShadowCallback aCallback,
|
|
|
|
void* aCallbackData)
|
|
|
|
{
|
|
|
|
const nsStyleText* textStyle = aFrame->GetStyleText();
|
2012-08-08 04:37:13 -07:00
|
|
|
if (!textStyle->HasTextShadow(aFrame))
|
2011-06-30 23:43:11 -07:00
|
|
|
return;
|
|
|
|
|
|
|
|
// Text shadow happens with the last value being painted at the back,
|
|
|
|
// ie. it is painted first.
|
|
|
|
gfxContext* aDestCtx = aContext->ThebesContext();
|
2012-08-22 08:56:38 -07:00
|
|
|
for (uint32_t i = textStyle->mTextShadow->Length(); i > 0; --i) {
|
2011-06-30 23:43:11 -07:00
|
|
|
nsCSSShadowItem* shadowDetails = textStyle->mTextShadow->ShadowAt(i - 1);
|
|
|
|
nsPoint shadowOffset(shadowDetails->mXOffset,
|
|
|
|
shadowDetails->mYOffset);
|
|
|
|
nscoord blurRadius = NS_MAX(shadowDetails->mRadius, 0);
|
|
|
|
|
|
|
|
nsRect shadowRect(aTextRect);
|
|
|
|
shadowRect.MoveBy(shadowOffset);
|
|
|
|
|
|
|
|
nsPresContext* presCtx = aFrame->PresContext();
|
|
|
|
nsContextBoxBlur contextBoxBlur;
|
|
|
|
gfxContext* shadowContext = contextBoxBlur.Init(shadowRect, 0, blurRadius,
|
|
|
|
presCtx->AppUnitsPerDevPixel(),
|
2012-07-30 07:20:58 -07:00
|
|
|
aDestCtx, aDirtyRect, nullptr);
|
2011-06-30 23:43:11 -07:00
|
|
|
if (!shadowContext)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
nscolor shadowColor;
|
|
|
|
if (shadowDetails->mHasColor)
|
|
|
|
shadowColor = shadowDetails->mColor;
|
|
|
|
else
|
|
|
|
shadowColor = aForegroundColor;
|
|
|
|
|
|
|
|
// Conjure an nsRenderingContext from a gfxContext for drawing the text
|
2011-06-30 23:48:30 -07:00
|
|
|
// to blur.
|
2011-06-30 23:43:11 -07:00
|
|
|
nsRefPtr<nsRenderingContext> renderingContext = new nsRenderingContext();
|
|
|
|
renderingContext->Init(presCtx->DeviceContext(), shadowContext);
|
|
|
|
|
|
|
|
aDestCtx->Save();
|
|
|
|
aDestCtx->NewPath();
|
|
|
|
aDestCtx->SetColor(gfxRGBA(shadowColor));
|
|
|
|
|
|
|
|
// The callback will draw whatever we want to blur as a shadow.
|
|
|
|
aCallback(renderingContext, shadowOffset, shadowColor, aCallbackData);
|
|
|
|
|
|
|
|
contextBoxBlur.DoPaint();
|
|
|
|
aDestCtx->Restore();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-05-18 15:13:12 -07:00
|
|
|
/* static */ nscoord
|
2011-04-07 18:05:49 -07:00
|
|
|
nsLayoutUtils::GetCenteredFontBaseline(nsFontMetrics* aFontMetrics,
|
2009-05-18 15:13:12 -07:00
|
|
|
nscoord aLineHeight)
|
|
|
|
{
|
2011-04-07 21:18:43 -07:00
|
|
|
nscoord fontAscent = aFontMetrics->MaxAscent();
|
|
|
|
nscoord fontHeight = aFontMetrics->MaxHeight();
|
2009-05-18 15:13:12 -07:00
|
|
|
|
|
|
|
nscoord leading = aLineHeight - fontHeight;
|
|
|
|
return fontAscent + leading/2;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-09-28 23:19:26 -07:00
|
|
|
/* static */ bool
|
2007-03-22 10:30:00 -07:00
|
|
|
nsLayoutUtils::GetFirstLineBaseline(const nsIFrame* aFrame, nscoord* aResult)
|
2009-04-08 13:52:36 -07:00
|
|
|
{
|
|
|
|
LinePosition position;
|
|
|
|
if (!GetFirstLinePosition(aFrame, &position))
|
2011-10-17 07:59:28 -07:00
|
|
|
return false;
|
2009-04-08 13:52:36 -07:00
|
|
|
*aResult = position.mBaseline;
|
2011-10-17 07:59:28 -07:00
|
|
|
return true;
|
2009-04-08 13:52:36 -07:00
|
|
|
}
|
|
|
|
|
2011-09-28 23:19:26 -07:00
|
|
|
/* static */ bool
|
2009-04-08 13:52:36 -07:00
|
|
|
nsLayoutUtils::GetFirstLinePosition(const nsIFrame* aFrame,
|
|
|
|
LinePosition* aResult)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2008-07-13 15:10:23 -07:00
|
|
|
const nsBlockFrame* block = nsLayoutUtils::GetAsBlock(const_cast<nsIFrame*>(aFrame));
|
|
|
|
if (!block) {
|
2007-03-22 10:30:00 -07:00
|
|
|
// For the first-line baseline we also have to check for a table, and if
|
|
|
|
// so, use the baseline of its first row.
|
|
|
|
nsIAtom* fType = aFrame->GetType();
|
|
|
|
if (fType == nsGkAtoms::tableOuterFrame) {
|
2009-04-08 13:52:36 -07:00
|
|
|
aResult->mTop = 0;
|
|
|
|
aResult->mBaseline = aFrame->GetBaseline();
|
|
|
|
// This is what we want for the list bullet caller; not sure if
|
|
|
|
// other future callers will want the same.
|
|
|
|
aResult->mBottom = aFrame->GetSize().height;
|
2011-10-17 07:59:28 -07:00
|
|
|
return true;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
// For first-line baselines, we have to consider scroll frames.
|
|
|
|
if (fType == nsGkAtoms::scrollFrame) {
|
2009-01-12 11:20:59 -08:00
|
|
|
nsIScrollableFrame *sFrame = do_QueryFrame(const_cast<nsIFrame*>(aFrame));
|
|
|
|
if (!sFrame) {
|
2007-03-22 10:30:00 -07:00
|
|
|
NS_NOTREACHED("not scroll frame");
|
|
|
|
}
|
2009-04-08 13:52:36 -07:00
|
|
|
LinePosition kidPosition;
|
|
|
|
if (GetFirstLinePosition(sFrame->GetScrolledFrame(), &kidPosition)) {
|
2007-03-22 10:30:00 -07:00
|
|
|
// Consider only the border and padding that contributes to the
|
|
|
|
// kid's position, not the scrolling, so we get the initial
|
|
|
|
// position.
|
2009-04-08 13:52:36 -07:00
|
|
|
*aResult = kidPosition + aFrame->GetUsedBorderAndPadding().top;
|
2011-10-17 07:59:28 -07:00
|
|
|
return true;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
2011-10-17 07:59:28 -07:00
|
|
|
return false;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2010-08-04 19:40:19 -07:00
|
|
|
if (fType == nsGkAtoms::fieldSetFrame) {
|
|
|
|
LinePosition kidPosition;
|
2011-08-24 13:54:30 -07:00
|
|
|
nsIFrame* kid = aFrame->GetFirstPrincipalChild();
|
2010-08-04 19:40:19 -07:00
|
|
|
// kid might be a legend frame here, but that's ok.
|
|
|
|
if (GetFirstLinePosition(kid, &kidPosition)) {
|
|
|
|
*aResult = kidPosition + kid->GetPosition().y;
|
2011-10-17 07:59:28 -07:00
|
|
|
return true;
|
2010-08-04 19:40:19 -07:00
|
|
|
}
|
2011-10-17 07:59:28 -07:00
|
|
|
return false;
|
2010-08-04 19:40:19 -07:00
|
|
|
}
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
// No baseline.
|
2011-10-17 07:59:28 -07:00
|
|
|
return false;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
for (nsBlockFrame::const_line_iterator line = block->begin_lines(),
|
|
|
|
line_end = block->end_lines();
|
|
|
|
line != line_end; ++line) {
|
|
|
|
if (line->IsBlock()) {
|
|
|
|
nsIFrame *kid = line->mFirstChild;
|
2009-04-08 13:52:36 -07:00
|
|
|
LinePosition kidPosition;
|
|
|
|
if (GetFirstLinePosition(kid, &kidPosition)) {
|
|
|
|
*aResult = kidPosition + kid->GetPosition().y;
|
2011-10-17 07:59:28 -07:00
|
|
|
return true;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
// XXX Is this the right test? We have some bogus empty lines
|
|
|
|
// floating around, but IsEmpty is perhaps too weak.
|
|
|
|
if (line->GetHeight() != 0 || !line->IsEmpty()) {
|
2009-04-08 13:52:36 -07:00
|
|
|
nscoord top = line->mBounds.y;
|
|
|
|
aResult->mTop = top;
|
|
|
|
aResult->mBaseline = top + line->GetAscent();
|
|
|
|
aResult->mBottom = top + line->GetHeight();
|
2011-10-17 07:59:28 -07:00
|
|
|
return true;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2011-10-17 07:59:28 -07:00
|
|
|
return false;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2011-09-28 23:19:26 -07:00
|
|
|
/* static */ bool
|
2007-03-22 10:30:00 -07:00
|
|
|
nsLayoutUtils::GetLastLineBaseline(const nsIFrame* aFrame, nscoord* aResult)
|
|
|
|
{
|
2008-07-13 15:10:23 -07:00
|
|
|
const nsBlockFrame* block = nsLayoutUtils::GetAsBlock(const_cast<nsIFrame*>(aFrame));
|
|
|
|
if (!block)
|
2007-03-22 10:30:00 -07:00
|
|
|
// No baseline. (We intentionally don't descend into scroll frames.)
|
2011-10-17 07:59:28 -07:00
|
|
|
return false;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
for (nsBlockFrame::const_reverse_line_iterator line = block->rbegin_lines(),
|
|
|
|
line_end = block->rend_lines();
|
|
|
|
line != line_end; ++line) {
|
|
|
|
if (line->IsBlock()) {
|
|
|
|
nsIFrame *kid = line->mFirstChild;
|
|
|
|
nscoord kidBaseline;
|
|
|
|
if (GetLastLineBaseline(kid, &kidBaseline)) {
|
|
|
|
*aResult = kidBaseline + kid->GetPosition().y;
|
2011-10-17 07:59:28 -07:00
|
|
|
return true;
|
2007-03-22 10:30:00 -07:00
|
|
|
} else if (kid->GetType() == nsGkAtoms::scrollFrame) {
|
|
|
|
// Use the bottom of the scroll frame.
|
|
|
|
// XXX CSS2.1 really doesn't say what to do here.
|
|
|
|
*aResult = kid->GetRect().YMost();
|
2011-10-17 07:59:28 -07:00
|
|
|
return true;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
// XXX Is this the right test? We have some bogus empty lines
|
|
|
|
// floating around, but IsEmpty is perhaps too weak.
|
|
|
|
if (line->GetHeight() != 0 || !line->IsEmpty()) {
|
|
|
|
*aResult = line->mBounds.y + line->GetAscent();
|
2011-10-17 07:59:28 -07:00
|
|
|
return true;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2011-10-17 07:59:28 -07:00
|
|
|
return false;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2008-04-18 00:40:35 -07:00
|
|
|
static nscoord
|
|
|
|
CalculateBlockContentBottom(nsBlockFrame* aFrame)
|
|
|
|
{
|
|
|
|
NS_PRECONDITION(aFrame, "null ptr");
|
|
|
|
|
|
|
|
nscoord contentBottom = 0;
|
|
|
|
|
|
|
|
for (nsBlockFrame::line_iterator line = aFrame->begin_lines(),
|
|
|
|
line_end = aFrame->end_lines();
|
|
|
|
line != line_end; ++line) {
|
|
|
|
if (line->IsBlock()) {
|
|
|
|
nsIFrame* child = line->mFirstChild;
|
|
|
|
nscoord offset = child->GetRect().y - child->GetRelativeOffset().y;
|
2009-08-22 10:10:11 -07:00
|
|
|
contentBottom = NS_MAX(contentBottom,
|
2008-04-18 00:40:35 -07:00
|
|
|
nsLayoutUtils::CalculateContentBottom(child) + offset);
|
|
|
|
}
|
|
|
|
else {
|
2009-08-22 10:10:11 -07:00
|
|
|
contentBottom = NS_MAX(contentBottom, line->mBounds.YMost());
|
2008-04-18 00:40:35 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return contentBottom;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* static */ nscoord
|
|
|
|
nsLayoutUtils::CalculateContentBottom(nsIFrame* aFrame)
|
|
|
|
{
|
|
|
|
NS_PRECONDITION(aFrame, "null ptr");
|
|
|
|
|
|
|
|
nscoord contentBottom = aFrame->GetRect().height;
|
|
|
|
|
2010-10-06 21:25:47 -07:00
|
|
|
// We want scrollable overflow rather than visual because this
|
|
|
|
// calculation is intended to affect layout.
|
|
|
|
if (aFrame->GetScrollableOverflowRect().height > contentBottom) {
|
2011-08-24 13:54:29 -07:00
|
|
|
nsIFrame::ChildListIDs skip(nsIFrame::kOverflowList |
|
|
|
|
nsIFrame::kExcessOverflowContainersList |
|
|
|
|
nsIFrame::kOverflowOutOfFlowList);
|
2008-04-18 00:40:35 -07:00
|
|
|
nsBlockFrame* blockFrame = GetAsBlock(aFrame);
|
2011-08-24 13:54:29 -07:00
|
|
|
if (blockFrame) {
|
|
|
|
contentBottom =
|
|
|
|
NS_MAX(contentBottom, CalculateBlockContentBottom(blockFrame));
|
|
|
|
skip |= nsIFrame::kPrincipalList;
|
|
|
|
}
|
|
|
|
nsIFrame::ChildListIterator lists(aFrame);
|
|
|
|
for (; !lists.IsDone(); lists.Next()) {
|
|
|
|
if (!skip.Contains(lists.CurrentID())) {
|
|
|
|
nsFrameList::Enumerator childFrames(lists.CurrentList());
|
|
|
|
for (; !childFrames.AtEnd(); childFrames.Next()) {
|
|
|
|
nsIFrame* child = childFrames.get();
|
2008-04-18 00:40:35 -07:00
|
|
|
nscoord offset = child->GetRect().y - child->GetRelativeOffset().y;
|
2009-08-22 10:10:11 -07:00
|
|
|
contentBottom = NS_MAX(contentBottom,
|
2008-04-18 00:40:35 -07:00
|
|
|
CalculateContentBottom(child) + offset);
|
|
|
|
}
|
|
|
|
}
|
2011-08-24 13:54:29 -07:00
|
|
|
}
|
2008-04-18 00:40:35 -07:00
|
|
|
}
|
|
|
|
return contentBottom;
|
|
|
|
}
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
/* static */ nsIFrame*
|
|
|
|
nsLayoutUtils::GetClosestLayer(nsIFrame* aFrame)
|
|
|
|
{
|
|
|
|
nsIFrame* layer;
|
|
|
|
for (layer = aFrame; layer; layer = layer->GetParent()) {
|
2012-08-02 04:38:50 -07:00
|
|
|
if (layer->IsPositioned() ||
|
2007-03-22 10:30:00 -07:00
|
|
|
(layer->GetParent() &&
|
|
|
|
layer->GetParent()->GetType() == nsGkAtoms::scrollFrame))
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (layer)
|
|
|
|
return layer;
|
2007-03-30 14:11:41 -07:00
|
|
|
return aFrame->PresContext()->PresShell()->FrameManager()->GetRootFrame();
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2010-10-11 13:07:59 -07:00
|
|
|
GraphicsFilter
|
2009-04-10 06:41:59 -07:00
|
|
|
nsLayoutUtils::GetGraphicsFilterForFrame(nsIFrame* aForFrame)
|
2009-04-05 02:52:14 -07:00
|
|
|
{
|
2010-10-11 13:07:59 -07:00
|
|
|
GraphicsFilter defaultFilter = gfxPattern::FILTER_GOOD;
|
2009-04-10 06:41:59 -07:00
|
|
|
nsIFrame *frame = nsCSSRendering::IsCanvasFrame(aForFrame) ?
|
2009-12-01 09:21:00 -08:00
|
|
|
nsCSSRendering::FindBackgroundStyleFrame(aForFrame) : aForFrame;
|
2009-04-10 06:41:59 -07:00
|
|
|
|
|
|
|
switch (frame->GetStyleSVG()->mImageRendering) {
|
2009-04-05 02:52:14 -07:00
|
|
|
case NS_STYLE_IMAGE_RENDERING_OPTIMIZESPEED:
|
|
|
|
return gfxPattern::FILTER_FAST;
|
|
|
|
case NS_STYLE_IMAGE_RENDERING_OPTIMIZEQUALITY:
|
|
|
|
return gfxPattern::FILTER_BEST;
|
|
|
|
case NS_STYLE_IMAGE_RENDERING_CRISPEDGES:
|
|
|
|
return gfxPattern::FILTER_NEAREST;
|
|
|
|
default:
|
2010-04-20 09:36:00 -07:00
|
|
|
return defaultFilter;
|
2009-04-05 02:52:14 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-11-17 23:48:46 -08:00
|
|
|
/**
|
|
|
|
* Given an image being drawn into an appunit coordinate system, and
|
|
|
|
* a point in that coordinate system, map the point back into image
|
|
|
|
* pixel space.
|
|
|
|
* @param aSize the size of the image, in pixels
|
|
|
|
* @param aDest the rectangle that the image is being mapped into
|
|
|
|
* @param aPt a point in the same coordinate system as the rectangle
|
|
|
|
*/
|
2008-11-04 14:01:21 -08:00
|
|
|
static gfxPoint
|
2008-12-02 17:32:18 -08:00
|
|
|
MapToFloatImagePixels(const gfxSize& aSize,
|
|
|
|
const gfxRect& aDest, const gfxPoint& aPt)
|
2008-11-04 14:01:21 -08:00
|
|
|
{
|
2011-04-18 20:07:21 -07:00
|
|
|
return gfxPoint(((aPt.x - aDest.X())*aSize.width)/aDest.Width(),
|
|
|
|
((aPt.y - aDest.Y())*aSize.height)/aDest.Height());
|
2008-11-04 14:01:21 -08:00
|
|
|
}
|
|
|
|
|
2008-11-17 23:48:46 -08:00
|
|
|
/**
|
|
|
|
* Given an image being drawn into an pixel-based coordinate system, and
|
|
|
|
* a point in image space, map the point into the pixel-based coordinate
|
|
|
|
* system.
|
|
|
|
* @param aSize the size of the image, in pixels
|
|
|
|
* @param aDest the rectangle that the image is being mapped into
|
|
|
|
* @param aPt a point in image space
|
|
|
|
*/
|
|
|
|
static gfxPoint
|
2008-12-02 17:32:18 -08:00
|
|
|
MapToFloatUserPixels(const gfxSize& aSize,
|
2008-11-17 23:48:46 -08:00
|
|
|
const gfxRect& aDest, const gfxPoint& aPt)
|
|
|
|
{
|
2011-04-18 20:07:21 -07:00
|
|
|
return gfxPoint(aPt.x*aDest.Width()/aSize.width + aDest.X(),
|
|
|
|
aPt.y*aDest.Height()/aSize.height + aDest.Y());
|
2008-11-17 23:48:46 -08:00
|
|
|
}
|
|
|
|
|
2010-09-07 15:20:35 -07:00
|
|
|
/* static */ gfxRect
|
2012-08-22 08:56:38 -07:00
|
|
|
nsLayoutUtils::RectToGfxRect(const nsRect& aRect, int32_t aAppUnitsPerDevPixel)
|
2010-07-01 09:43:06 -07:00
|
|
|
{
|
|
|
|
return gfxRect(gfxFloat(aRect.x) / aAppUnitsPerDevPixel,
|
|
|
|
gfxFloat(aRect.y) / aAppUnitsPerDevPixel,
|
|
|
|
gfxFloat(aRect.width) / aAppUnitsPerDevPixel,
|
|
|
|
gfxFloat(aRect.height) / aAppUnitsPerDevPixel);
|
|
|
|
}
|
|
|
|
|
|
|
|
struct SnappedImageDrawingParameters {
|
|
|
|
// A transform from either device space or user space (depending on mResetCTM)
|
|
|
|
// to image space
|
|
|
|
gfxMatrix mUserSpaceToImageSpace;
|
|
|
|
// A device-space, pixel-aligned rectangle to fill
|
|
|
|
gfxRect mFillRect;
|
|
|
|
// A pixel rectangle in tiled image space outside of which gfx should not
|
|
|
|
// sample (using EXTEND_PAD as necessary)
|
|
|
|
nsIntRect mSubimage;
|
|
|
|
// Whether there's anything to draw at all
|
2011-09-28 23:19:26 -07:00
|
|
|
bool mShouldDraw;
|
2011-10-17 07:59:28 -07:00
|
|
|
// true iff the CTM of the rendering context needs to be reset to the
|
2010-07-01 09:43:06 -07:00
|
|
|
// identity matrix before drawing
|
2011-09-28 23:19:26 -07:00
|
|
|
bool mResetCTM;
|
2010-07-01 09:43:06 -07:00
|
|
|
|
|
|
|
SnappedImageDrawingParameters()
|
2011-10-17 07:59:28 -07:00
|
|
|
: mShouldDraw(false)
|
|
|
|
, mResetCTM(false)
|
2010-07-01 09:43:06 -07:00
|
|
|
{}
|
|
|
|
|
|
|
|
SnappedImageDrawingParameters(const gfxMatrix& aUserSpaceToImageSpace,
|
|
|
|
const gfxRect& aFillRect,
|
|
|
|
const nsIntRect& aSubimage,
|
2011-09-28 23:19:26 -07:00
|
|
|
bool aResetCTM)
|
2010-07-01 09:43:06 -07:00
|
|
|
: mUserSpaceToImageSpace(aUserSpaceToImageSpace)
|
|
|
|
, mFillRect(aFillRect)
|
|
|
|
, mSubimage(aSubimage)
|
2011-10-17 07:59:28 -07:00
|
|
|
, mShouldDraw(true)
|
2010-07-01 09:43:06 -07:00
|
|
|
, mResetCTM(aResetCTM)
|
|
|
|
{}
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Given a set of input parameters, compute certain output parameters
|
|
|
|
* for drawing an image with the image snapping algorithm.
|
|
|
|
* See https://wiki.mozilla.org/Gecko:Image_Snapping_and_Rendering
|
|
|
|
*
|
|
|
|
* @see nsLayoutUtils::DrawImage() for the descriptions of input parameters
|
|
|
|
*/
|
|
|
|
static SnappedImageDrawingParameters
|
|
|
|
ComputeSnappedImageDrawingParameters(gfxContext* aCtx,
|
2012-08-22 08:56:38 -07:00
|
|
|
int32_t aAppUnitsPerDevPixel,
|
2010-07-01 09:43:06 -07:00
|
|
|
const nsRect aDest,
|
|
|
|
const nsRect aFill,
|
|
|
|
const nsPoint aAnchor,
|
|
|
|
const nsRect aDirty,
|
|
|
|
const nsIntSize aImageSize)
|
|
|
|
|
2008-11-04 14:01:21 -08:00
|
|
|
{
|
2008-11-06 16:58:42 -08:00
|
|
|
if (aDest.IsEmpty() || aFill.IsEmpty())
|
2010-07-01 09:43:06 -07:00
|
|
|
return SnappedImageDrawingParameters();
|
|
|
|
|
2010-09-07 15:20:35 -07:00
|
|
|
gfxRect devPixelDest =
|
|
|
|
nsLayoutUtils::RectToGfxRect(aDest, aAppUnitsPerDevPixel);
|
|
|
|
gfxRect devPixelFill =
|
|
|
|
nsLayoutUtils::RectToGfxRect(aFill, aAppUnitsPerDevPixel);
|
|
|
|
gfxRect devPixelDirty =
|
|
|
|
nsLayoutUtils::RectToGfxRect(aDirty, aAppUnitsPerDevPixel);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2011-09-28 23:19:26 -07:00
|
|
|
bool ignoreScale = false;
|
2008-11-04 14:01:21 -08:00
|
|
|
#ifdef MOZ_GFX_OPTIMIZE_MOBILE
|
2011-10-17 07:59:28 -07:00
|
|
|
ignoreScale = true;
|
2008-11-04 14:01:21 -08:00
|
|
|
#endif
|
2008-11-06 16:58:42 -08:00
|
|
|
gfxRect fill = devPixelFill;
|
2011-09-28 23:19:26 -07:00
|
|
|
bool didSnap = aCtx->UserToDevicePixelSnapped(fill, ignoreScale);
|
2012-09-03 15:32:20 -07:00
|
|
|
gfxMatrix currentMatrix = aCtx->CurrentMatrix();
|
|
|
|
if (didSnap && currentMatrix.HasNonAxisAlignedTransform()) {
|
|
|
|
// currentMatrix must have some rotation by a multiple of 90 degrees.
|
|
|
|
didSnap = false;
|
|
|
|
fill = devPixelFill;
|
|
|
|
}
|
2008-11-04 14:01:21 -08:00
|
|
|
|
2009-01-29 23:33:57 -08:00
|
|
|
gfxSize imageSize(aImageSize.width, aImageSize.height);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2008-11-04 14:01:21 -08:00
|
|
|
// Compute the set of pixels that would be sampled by an ideal rendering
|
|
|
|
gfxPoint subimageTopLeft =
|
2008-12-02 18:02:29 -08:00
|
|
|
MapToFloatImagePixels(imageSize, devPixelDest, devPixelFill.TopLeft());
|
2008-11-04 14:01:21 -08:00
|
|
|
gfxPoint subimageBottomRight =
|
2008-12-02 18:02:29 -08:00
|
|
|
MapToFloatImagePixels(imageSize, devPixelDest, devPixelFill.BottomRight());
|
2008-11-04 14:01:21 -08:00
|
|
|
nsIntRect intSubimage;
|
|
|
|
intSubimage.MoveTo(NSToIntFloor(subimageTopLeft.x),
|
|
|
|
NSToIntFloor(subimageTopLeft.y));
|
|
|
|
intSubimage.SizeTo(NSToIntCeil(subimageBottomRight.x) - intSubimage.x,
|
|
|
|
NSToIntCeil(subimageBottomRight.y) - intSubimage.y);
|
|
|
|
|
|
|
|
// Compute the anchor point and compute final fill rect.
|
|
|
|
// This code assumes that pixel-based devices have one pixel per
|
|
|
|
// device unit!
|
2010-07-01 09:43:06 -07:00
|
|
|
gfxPoint anchorPoint(gfxFloat(aAnchor.x)/aAppUnitsPerDevPixel,
|
|
|
|
gfxFloat(aAnchor.y)/aAppUnitsPerDevPixel);
|
2008-11-17 23:48:46 -08:00
|
|
|
gfxPoint imageSpaceAnchorPoint =
|
2008-12-02 18:02:29 -08:00
|
|
|
MapToFloatImagePixels(imageSize, devPixelDest, anchorPoint);
|
2008-11-17 23:48:46 -08:00
|
|
|
|
2008-11-04 14:01:21 -08:00
|
|
|
if (didSnap) {
|
2008-11-17 23:48:46 -08:00
|
|
|
imageSpaceAnchorPoint.Round();
|
|
|
|
anchorPoint = imageSpaceAnchorPoint;
|
|
|
|
anchorPoint = MapToFloatUserPixels(imageSize, devPixelDest, anchorPoint);
|
2010-07-01 09:43:06 -07:00
|
|
|
anchorPoint = currentMatrix.Transform(anchorPoint);
|
2008-11-17 13:13:55 -08:00
|
|
|
anchorPoint.Round();
|
2008-11-04 14:01:21 -08:00
|
|
|
|
|
|
|
// This form of Transform is safe to call since non-axis-aligned
|
|
|
|
// transforms wouldn't be snapped.
|
2010-07-01 09:43:06 -07:00
|
|
|
devPixelDirty = currentMatrix.Transform(devPixelDirty);
|
2008-11-04 14:01:21 -08:00
|
|
|
}
|
|
|
|
|
2010-07-01 09:43:06 -07:00
|
|
|
gfxFloat scaleX = imageSize.width*aAppUnitsPerDevPixel/aDest.width;
|
|
|
|
gfxFloat scaleY = imageSize.height*aAppUnitsPerDevPixel/aDest.height;
|
2008-11-04 14:01:21 -08:00
|
|
|
if (didSnap) {
|
2010-07-01 09:43:06 -07:00
|
|
|
// We'll reset aCTX to the identity matrix before drawing, so we need to
|
|
|
|
// adjust our scales to match.
|
|
|
|
scaleX /= currentMatrix.xx;
|
|
|
|
scaleY /= currentMatrix.yy;
|
2008-11-04 14:01:21 -08:00
|
|
|
}
|
|
|
|
gfxFloat translateX = imageSpaceAnchorPoint.x - anchorPoint.x*scaleX;
|
|
|
|
gfxFloat translateY = imageSpaceAnchorPoint.y - anchorPoint.y*scaleY;
|
|
|
|
gfxMatrix transform(scaleX, 0, 0, scaleY, translateX, translateY);
|
|
|
|
|
2008-12-02 12:46:44 -08:00
|
|
|
gfxRect finalFillRect = fill;
|
|
|
|
// If the user-space-to-image-space transform is not a straight
|
|
|
|
// translation by integers, then filtering will occur, and
|
|
|
|
// restricting the fill rect to the dirty rect would change the values
|
|
|
|
// computed for edge pixels, which we can't allow.
|
2010-07-01 09:43:06 -07:00
|
|
|
// Also, if didSnap is false then rounding out 'devPixelDirty' might not
|
2008-12-02 12:46:44 -08:00
|
|
|
// produce pixel-aligned coordinates, which would also break the values
|
|
|
|
// computed for edge pixels.
|
|
|
|
if (didSnap && !transform.HasNonIntegerTranslation()) {
|
2010-07-01 09:43:06 -07:00
|
|
|
devPixelDirty.RoundOut();
|
|
|
|
finalFillRect = fill.Intersect(devPixelDirty);
|
2008-12-02 12:46:44 -08:00
|
|
|
}
|
|
|
|
if (finalFillRect.IsEmpty())
|
2010-07-01 09:43:06 -07:00
|
|
|
return SnappedImageDrawingParameters();
|
|
|
|
|
|
|
|
return SnappedImageDrawingParameters(transform, finalFillRect, intSubimage,
|
|
|
|
didSnap);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static nsresult
|
2011-04-07 18:04:40 -07:00
|
|
|
DrawImageInternal(nsRenderingContext* aRenderingContext,
|
2010-07-01 09:43:06 -07:00
|
|
|
imgIContainer* aImage,
|
2010-10-11 13:07:59 -07:00
|
|
|
GraphicsFilter aGraphicsFilter,
|
2010-07-01 09:43:06 -07:00
|
|
|
const nsRect& aDest,
|
|
|
|
const nsRect& aFill,
|
|
|
|
const nsPoint& aAnchor,
|
|
|
|
const nsRect& aDirty,
|
|
|
|
const nsIntSize& aImageSize,
|
2012-08-22 08:56:38 -07:00
|
|
|
uint32_t aImageFlags)
|
2010-07-01 09:43:06 -07:00
|
|
|
{
|
2012-04-17 15:04:15 -07:00
|
|
|
if (aDest.Contains(aFill)) {
|
|
|
|
aImageFlags |= imgIContainer::FLAG_CLAMP;
|
|
|
|
}
|
2012-08-22 08:56:38 -07:00
|
|
|
int32_t appUnitsPerDevPixel = aRenderingContext->AppUnitsPerDevPixel();
|
2010-07-01 09:43:06 -07:00
|
|
|
gfxContext* ctx = aRenderingContext->ThebesContext();
|
|
|
|
|
|
|
|
SnappedImageDrawingParameters drawingParams =
|
|
|
|
ComputeSnappedImageDrawingParameters(ctx, appUnitsPerDevPixel, aDest, aFill,
|
|
|
|
aAnchor, aDirty, aImageSize);
|
|
|
|
|
|
|
|
if (!drawingParams.mShouldDraw)
|
2008-12-02 12:46:44 -08:00
|
|
|
return NS_OK;
|
|
|
|
|
2010-07-01 09:43:06 -07:00
|
|
|
gfxContextMatrixAutoSaveRestore saveMatrix(ctx);
|
|
|
|
if (drawingParams.mResetCTM) {
|
|
|
|
ctx->IdentityMatrix();
|
|
|
|
}
|
|
|
|
|
|
|
|
aImage->Draw(ctx, aGraphicsFilter, drawingParams.mUserSpaceToImageSpace,
|
2010-09-08 13:40:39 -07:00
|
|
|
drawingParams.mFillRect, drawingParams.mSubimage, aImageSize,
|
|
|
|
aImageFlags);
|
2008-11-04 14:01:21 -08:00
|
|
|
return NS_OK;
|
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2010-08-13 06:30:37 -07:00
|
|
|
/* static */ void
|
2011-04-07 18:04:40 -07:00
|
|
|
nsLayoutUtils::DrawPixelSnapped(nsRenderingContext* aRenderingContext,
|
2010-08-13 06:30:37 -07:00
|
|
|
gfxDrawable* aDrawable,
|
2010-10-11 13:07:59 -07:00
|
|
|
GraphicsFilter aFilter,
|
2010-08-13 06:30:37 -07:00
|
|
|
const nsRect& aDest,
|
|
|
|
const nsRect& aFill,
|
|
|
|
const nsPoint& aAnchor,
|
|
|
|
const nsRect& aDirty)
|
|
|
|
{
|
2012-08-22 08:56:38 -07:00
|
|
|
int32_t appUnitsPerDevPixel = aRenderingContext->AppUnitsPerDevPixel();
|
2010-08-13 06:30:37 -07:00
|
|
|
gfxContext* ctx = aRenderingContext->ThebesContext();
|
|
|
|
gfxIntSize drawableSize = aDrawable->Size();
|
|
|
|
nsIntSize imageSize(drawableSize.width, drawableSize.height);
|
|
|
|
|
|
|
|
SnappedImageDrawingParameters drawingParams =
|
|
|
|
ComputeSnappedImageDrawingParameters(ctx, appUnitsPerDevPixel, aDest, aFill,
|
|
|
|
aAnchor, aDirty, imageSize);
|
|
|
|
|
|
|
|
if (!drawingParams.mShouldDraw)
|
|
|
|
return;
|
|
|
|
|
|
|
|
gfxContextMatrixAutoSaveRestore saveMatrix(ctx);
|
|
|
|
if (drawingParams.mResetCTM) {
|
|
|
|
ctx->IdentityMatrix();
|
|
|
|
}
|
|
|
|
|
|
|
|
gfxRect sourceRect =
|
|
|
|
drawingParams.mUserSpaceToImageSpace.Transform(drawingParams.mFillRect);
|
|
|
|
gfxRect imageRect(0, 0, imageSize.width, imageSize.height);
|
|
|
|
gfxRect subimage(drawingParams.mSubimage.x, drawingParams.mSubimage.y,
|
|
|
|
drawingParams.mSubimage.width, drawingParams.mSubimage.height);
|
|
|
|
|
|
|
|
NS_ASSERTION(!sourceRect.Intersect(subimage).IsEmpty(),
|
|
|
|
"We must be allowed to sample *some* source pixels!");
|
|
|
|
|
|
|
|
gfxUtils::DrawPixelSnapped(ctx, aDrawable,
|
|
|
|
drawingParams.mUserSpaceToImageSpace, subimage,
|
|
|
|
sourceRect, imageRect, drawingParams.mFillRect,
|
|
|
|
gfxASurface::ImageFormatARGB32, aFilter);
|
|
|
|
}
|
|
|
|
|
2009-07-27 16:48:13 -07:00
|
|
|
/* static */ nsresult
|
2011-04-07 18:04:40 -07:00
|
|
|
nsLayoutUtils::DrawSingleUnscaledImage(nsRenderingContext* aRenderingContext,
|
2009-07-27 16:48:13 -07:00
|
|
|
imgIContainer* aImage,
|
2010-10-11 13:08:07 -07:00
|
|
|
GraphicsFilter aGraphicsFilter,
|
2009-07-27 16:48:13 -07:00
|
|
|
const nsPoint& aDest,
|
2010-10-11 13:08:07 -07:00
|
|
|
const nsRect* aDirty,
|
2012-08-22 08:56:38 -07:00
|
|
|
uint32_t aImageFlags,
|
2009-07-27 16:48:13 -07:00
|
|
|
const nsRect* aSourceArea)
|
|
|
|
{
|
|
|
|
nsIntSize imageSize;
|
|
|
|
aImage->GetWidth(&imageSize.width);
|
|
|
|
aImage->GetHeight(&imageSize.height);
|
|
|
|
NS_ENSURE_TRUE(imageSize.width > 0 && imageSize.height > 0, NS_ERROR_FAILURE);
|
2008-11-04 14:01:21 -08:00
|
|
|
|
2011-04-16 18:22:44 -07:00
|
|
|
nscoord appUnitsPerCSSPixel = nsDeviceContext::AppUnitsPerCSSPixel();
|
2009-07-27 16:48:13 -07:00
|
|
|
nsSize size(imageSize.width*appUnitsPerCSSPixel,
|
|
|
|
imageSize.height*appUnitsPerCSSPixel);
|
2009-01-29 23:33:57 -08:00
|
|
|
|
2008-11-04 14:01:21 -08:00
|
|
|
nsRect source;
|
|
|
|
if (aSourceArea) {
|
|
|
|
source = *aSourceArea;
|
|
|
|
} else {
|
2009-01-29 23:33:57 -08:00
|
|
|
source.SizeTo(size);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2009-01-29 23:33:57 -08:00
|
|
|
nsRect dest(aDest - source.TopLeft(), size);
|
2008-11-04 14:01:21 -08:00
|
|
|
nsRect fill(aDest, source.Size());
|
2008-11-09 23:24:21 -08:00
|
|
|
// Ensure that only a single image tile is drawn. If aSourceArea extends
|
|
|
|
// outside the image bounds, we want to honor the aSourceArea-to-aDest
|
|
|
|
// translation but we don't want to actually tile the image.
|
|
|
|
fill.IntersectRect(fill, dest);
|
2010-10-11 13:08:07 -07:00
|
|
|
return DrawImageInternal(aRenderingContext, aImage, aGraphicsFilter,
|
|
|
|
dest, fill, aDest, aDirty ? *aDirty : dest,
|
|
|
|
imageSize, aImageFlags);
|
2008-11-04 14:01:21 -08:00
|
|
|
}
|
2010-04-27 09:15:01 -07:00
|
|
|
|
2009-07-27 16:48:13 -07:00
|
|
|
/* static */ nsresult
|
2011-04-07 18:04:40 -07:00
|
|
|
nsLayoutUtils::DrawSingleImage(nsRenderingContext* aRenderingContext,
|
2009-07-27 16:48:13 -07:00
|
|
|
imgIContainer* aImage,
|
2010-10-11 13:07:59 -07:00
|
|
|
GraphicsFilter aGraphicsFilter,
|
2009-07-27 16:48:13 -07:00
|
|
|
const nsRect& aDest,
|
|
|
|
const nsRect& aDirty,
|
2012-08-22 08:56:38 -07:00
|
|
|
uint32_t aImageFlags,
|
2009-07-27 16:48:13 -07:00
|
|
|
const nsRect* aSourceArea)
|
|
|
|
{
|
|
|
|
nsIntSize imageSize;
|
2010-09-08 13:40:39 -07:00
|
|
|
if (aImage->GetType() == imgIContainer::TYPE_VECTOR) {
|
|
|
|
imageSize.width = nsPresContext::AppUnitsToIntCSSPixels(aDest.width);
|
|
|
|
imageSize.height = nsPresContext::AppUnitsToIntCSSPixels(aDest.height);
|
|
|
|
} else {
|
|
|
|
aImage->GetWidth(&imageSize.width);
|
|
|
|
aImage->GetHeight(&imageSize.height);
|
|
|
|
}
|
2009-07-27 16:48:13 -07:00
|
|
|
NS_ENSURE_TRUE(imageSize.width > 0 && imageSize.height > 0, NS_ERROR_FAILURE);
|
2009-01-29 23:33:57 -08:00
|
|
|
|
2008-11-04 14:01:21 -08:00
|
|
|
nsRect source;
|
|
|
|
if (aSourceArea) {
|
|
|
|
source = *aSourceArea;
|
|
|
|
} else {
|
2011-04-16 18:22:44 -07:00
|
|
|
nscoord appUnitsPerCSSPixel = nsDeviceContext::AppUnitsPerCSSPixel();
|
2009-07-27 16:48:13 -07:00
|
|
|
source.SizeTo(imageSize.width*appUnitsPerCSSPixel,
|
|
|
|
imageSize.height*appUnitsPerCSSPixel);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2009-07-27 16:48:13 -07:00
|
|
|
nsRect dest = nsLayoutUtils::GetWholeImageDestination(imageSize, source,
|
2009-01-29 23:33:57 -08:00
|
|
|
aDest);
|
2008-11-09 23:24:21 -08:00
|
|
|
// Ensure that only a single image tile is drawn. If aSourceArea extends
|
|
|
|
// outside the image bounds, we want to honor the aSourceArea-to-aDest
|
|
|
|
// transform but we don't want to actually tile the image.
|
|
|
|
nsRect fill;
|
|
|
|
fill.IntersectRect(aDest, dest);
|
2009-04-05 02:52:14 -07:00
|
|
|
return DrawImageInternal(aRenderingContext, aImage, aGraphicsFilter, dest, fill,
|
2009-09-12 15:44:18 -07:00
|
|
|
fill.TopLeft(), aDirty, imageSize, aImageFlags);
|
2009-01-29 23:33:57 -08:00
|
|
|
}
|
|
|
|
|
2010-09-08 13:40:39 -07:00
|
|
|
/* static */ void
|
|
|
|
nsLayoutUtils::ComputeSizeForDrawing(imgIContainer *aImage,
|
|
|
|
nsIntSize& aImageSize, /*outparam*/
|
2011-01-13 02:40:12 -08:00
|
|
|
nsSize& aIntrinsicRatio, /*outparam*/
|
|
|
|
bool& aGotWidth, /*outparam*/
|
|
|
|
bool& aGotHeight /*outparam*/)
|
2010-09-08 13:40:39 -07:00
|
|
|
{
|
|
|
|
aGotWidth = NS_SUCCEEDED(aImage->GetWidth(&aImageSize.width));
|
|
|
|
aGotHeight = NS_SUCCEEDED(aImage->GetHeight(&aImageSize.height));
|
|
|
|
|
2011-01-13 02:40:12 -08:00
|
|
|
if (aGotWidth && aGotHeight) {
|
|
|
|
aIntrinsicRatio = nsSize(aImageSize.width, aImageSize.height);
|
2010-09-08 13:40:39 -07:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2011-01-13 02:40:12 -08:00
|
|
|
// If we failed to get width or height, we either have a vector image and
|
|
|
|
// should return its intrinsic ratio, or we hit an error (say, because the
|
|
|
|
// image failed to load or couldn't be decoded) and should return zero size.
|
|
|
|
if (nsIFrame* rootFrame = aImage->GetRootLayoutFrame()) {
|
|
|
|
aIntrinsicRatio = rootFrame->GetIntrinsicRatio();
|
|
|
|
} else {
|
|
|
|
aGotWidth = aGotHeight = true;
|
|
|
|
aImageSize = nsIntSize(0, 0);
|
|
|
|
aIntrinsicRatio = nsSize(0, 0);
|
2010-09-08 13:40:39 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-01-13 02:40:12 -08:00
|
|
|
/* static */ nsresult
|
|
|
|
nsLayoutUtils::DrawBackgroundImage(nsRenderingContext* aRenderingContext,
|
|
|
|
imgIContainer* aImage,
|
|
|
|
const nsIntSize& aImageSize,
|
|
|
|
GraphicsFilter aGraphicsFilter,
|
|
|
|
const nsRect& aDest,
|
|
|
|
const nsRect& aFill,
|
|
|
|
const nsPoint& aAnchor,
|
|
|
|
const nsRect& aDirty,
|
2012-08-22 08:56:38 -07:00
|
|
|
uint32_t aImageFlags)
|
2011-01-13 02:40:12 -08:00
|
|
|
{
|
2012-01-17 12:33:04 -08:00
|
|
|
SAMPLE_LABEL("layout", "nsLayoutUtils::DrawBackgroundImage");
|
2012-04-24 07:28:46 -07:00
|
|
|
|
|
|
|
if (UseBackgroundNearestFiltering()) {
|
|
|
|
aGraphicsFilter = gfxPattern::FILTER_NEAREST;
|
|
|
|
}
|
|
|
|
|
2011-01-13 02:40:12 -08:00
|
|
|
return DrawImageInternal(aRenderingContext, aImage, aGraphicsFilter,
|
|
|
|
aDest, aFill, aAnchor, aDirty,
|
|
|
|
aImageSize, aImageFlags);
|
|
|
|
}
|
|
|
|
|
2009-01-29 23:33:57 -08:00
|
|
|
/* static */ nsresult
|
2011-04-07 18:04:40 -07:00
|
|
|
nsLayoutUtils::DrawImage(nsRenderingContext* aRenderingContext,
|
2009-01-29 23:33:57 -08:00
|
|
|
imgIContainer* aImage,
|
2010-10-11 13:07:59 -07:00
|
|
|
GraphicsFilter aGraphicsFilter,
|
2009-01-29 23:33:57 -08:00
|
|
|
const nsRect& aDest,
|
|
|
|
const nsRect& aFill,
|
|
|
|
const nsPoint& aAnchor,
|
2009-09-12 15:44:18 -07:00
|
|
|
const nsRect& aDirty,
|
2012-08-22 08:56:38 -07:00
|
|
|
uint32_t aImageFlags)
|
2009-01-29 23:33:57 -08:00
|
|
|
{
|
|
|
|
nsIntSize imageSize;
|
2011-01-13 02:40:12 -08:00
|
|
|
nsSize imageRatio;
|
|
|
|
bool gotHeight, gotWidth;
|
|
|
|
ComputeSizeForDrawing(aImage, imageSize, imageRatio, gotWidth, gotHeight);
|
|
|
|
|
|
|
|
// XXX Dimensionless images shouldn't fall back to filled-area size -- the
|
|
|
|
// caller should provide the image size, a la DrawBackgroundImage.
|
|
|
|
if (gotWidth != gotHeight) {
|
|
|
|
if (!gotWidth) {
|
|
|
|
if (imageRatio.height != 0) {
|
|
|
|
imageSize.width =
|
|
|
|
NSCoordSaturatingNonnegativeMultiply(imageSize.height,
|
|
|
|
float(imageRatio.width) /
|
|
|
|
float(imageRatio.height));
|
|
|
|
gotWidth = true;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if (imageRatio.width != 0) {
|
|
|
|
imageSize.height =
|
|
|
|
NSCoordSaturatingNonnegativeMultiply(imageSize.width,
|
|
|
|
float(imageRatio.height) /
|
|
|
|
float(imageRatio.width));
|
|
|
|
gotHeight = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2010-09-08 13:40:39 -07:00
|
|
|
|
|
|
|
if (!gotWidth) {
|
|
|
|
imageSize.width = nsPresContext::AppUnitsToIntCSSPixels(aFill.width);
|
|
|
|
}
|
|
|
|
if (!gotHeight) {
|
|
|
|
imageSize.height = nsPresContext::AppUnitsToIntCSSPixels(aFill.height);
|
|
|
|
}
|
2009-01-29 23:33:57 -08:00
|
|
|
|
2009-04-05 02:52:14 -07:00
|
|
|
return DrawImageInternal(aRenderingContext, aImage, aGraphicsFilter,
|
2009-01-29 23:33:57 -08:00
|
|
|
aDest, aFill, aAnchor, aDirty,
|
2009-09-12 15:44:18 -07:00
|
|
|
imageSize, aImageFlags);
|
2009-01-29 23:33:57 -08:00
|
|
|
}
|
|
|
|
|
2008-11-04 14:01:21 -08:00
|
|
|
/* static */ nsRect
|
|
|
|
nsLayoutUtils::GetWholeImageDestination(const nsIntSize& aWholeImageSize,
|
|
|
|
const nsRect& aImageSourceArea,
|
|
|
|
const nsRect& aDestArea)
|
|
|
|
{
|
|
|
|
double scaleX = double(aDestArea.width)/aImageSourceArea.width;
|
|
|
|
double scaleY = double(aDestArea.height)/aImageSourceArea.height;
|
|
|
|
nscoord destOffsetX = NSToCoordRound(aImageSourceArea.x*scaleX);
|
|
|
|
nscoord destOffsetY = NSToCoordRound(aImageSourceArea.y*scaleY);
|
2011-04-16 18:22:44 -07:00
|
|
|
nscoord appUnitsPerCSSPixel = nsDeviceContext::AppUnitsPerCSSPixel();
|
2008-11-04 14:01:21 -08:00
|
|
|
nscoord wholeSizeX = NSToCoordRound(aWholeImageSize.width*appUnitsPerCSSPixel*scaleX);
|
|
|
|
nscoord wholeSizeY = NSToCoordRound(aWholeImageSize.height*appUnitsPerCSSPixel*scaleY);
|
|
|
|
return nsRect(aDestArea.TopLeft() - nsPoint(destOffsetX, destOffsetY),
|
|
|
|
nsSize(wholeSizeX, wholeSizeY));
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
2007-05-04 23:09:50 -07:00
|
|
|
|
2011-09-28 23:19:26 -07:00
|
|
|
static bool NonZeroStyleCoord(const nsStyleCoord& aCoord)
|
2007-05-10 08:46:42 -07:00
|
|
|
{
|
2010-09-09 08:21:45 -07:00
|
|
|
if (aCoord.IsCoordPercentCalcUnit()) {
|
|
|
|
// Since negative results are clamped to 0, check > 0.
|
|
|
|
return nsRuleNode::ComputeCoordPercentCalc(aCoord, nscoord_MAX) > 0 ||
|
|
|
|
nsRuleNode::ComputeCoordPercentCalc(aCoord, 0) > 0;
|
2007-05-10 08:46:42 -07:00
|
|
|
}
|
2010-09-09 08:21:45 -07:00
|
|
|
|
2011-10-17 07:59:28 -07:00
|
|
|
return true;
|
2007-05-10 08:46:42 -07:00
|
|
|
}
|
|
|
|
|
2011-09-28 23:19:26 -07:00
|
|
|
/* static */ bool
|
2008-09-30 22:50:52 -07:00
|
|
|
nsLayoutUtils::HasNonZeroCorner(const nsStyleCorners& aCorners)
|
2007-05-10 08:46:42 -07:00
|
|
|
{
|
2008-09-30 22:50:52 -07:00
|
|
|
NS_FOR_CSS_HALF_CORNERS(corner) {
|
|
|
|
if (NonZeroStyleCoord(aCorners.Get(corner)))
|
2011-10-17 07:59:28 -07:00
|
|
|
return true;
|
2008-09-30 22:50:52 -07:00
|
|
|
}
|
2011-10-17 07:59:28 -07:00
|
|
|
return false;
|
2007-05-10 08:46:42 -07:00
|
|
|
}
|
|
|
|
|
2009-05-07 18:52:22 -07:00
|
|
|
// aCorner is a "full corner" value, i.e. NS_CORNER_TOP_LEFT etc
|
2012-08-22 08:56:38 -07:00
|
|
|
static bool IsCornerAdjacentToSide(uint8_t aCorner, mozilla::css::Side aSide)
|
2009-05-07 18:52:22 -07:00
|
|
|
{
|
2010-04-27 09:15:02 -07:00
|
|
|
PR_STATIC_ASSERT((int)NS_SIDE_TOP == NS_CORNER_TOP_LEFT);
|
|
|
|
PR_STATIC_ASSERT((int)NS_SIDE_RIGHT == NS_CORNER_TOP_RIGHT);
|
|
|
|
PR_STATIC_ASSERT((int)NS_SIDE_BOTTOM == NS_CORNER_BOTTOM_RIGHT);
|
|
|
|
PR_STATIC_ASSERT((int)NS_SIDE_LEFT == NS_CORNER_BOTTOM_LEFT);
|
|
|
|
PR_STATIC_ASSERT((int)NS_SIDE_TOP == ((NS_CORNER_TOP_RIGHT - 1)&3));
|
|
|
|
PR_STATIC_ASSERT((int)NS_SIDE_RIGHT == ((NS_CORNER_BOTTOM_RIGHT - 1)&3));
|
|
|
|
PR_STATIC_ASSERT((int)NS_SIDE_BOTTOM == ((NS_CORNER_BOTTOM_LEFT - 1)&3));
|
|
|
|
PR_STATIC_ASSERT((int)NS_SIDE_LEFT == ((NS_CORNER_TOP_LEFT - 1)&3));
|
2009-05-07 18:52:22 -07:00
|
|
|
|
|
|
|
return aSide == aCorner || aSide == ((aCorner - 1)&3);
|
|
|
|
}
|
|
|
|
|
2011-09-28 23:19:26 -07:00
|
|
|
/* static */ bool
|
2009-05-07 18:52:22 -07:00
|
|
|
nsLayoutUtils::HasNonZeroCornerOnSide(const nsStyleCorners& aCorners,
|
2010-04-27 09:15:02 -07:00
|
|
|
mozilla::css::Side aSide)
|
2009-05-07 18:52:22 -07:00
|
|
|
{
|
|
|
|
PR_STATIC_ASSERT(NS_CORNER_TOP_LEFT_X/2 == NS_CORNER_TOP_LEFT);
|
|
|
|
PR_STATIC_ASSERT(NS_CORNER_TOP_LEFT_Y/2 == NS_CORNER_TOP_LEFT);
|
|
|
|
PR_STATIC_ASSERT(NS_CORNER_TOP_RIGHT_X/2 == NS_CORNER_TOP_RIGHT);
|
|
|
|
PR_STATIC_ASSERT(NS_CORNER_TOP_RIGHT_Y/2 == NS_CORNER_TOP_RIGHT);
|
|
|
|
PR_STATIC_ASSERT(NS_CORNER_BOTTOM_RIGHT_X/2 == NS_CORNER_BOTTOM_RIGHT);
|
|
|
|
PR_STATIC_ASSERT(NS_CORNER_BOTTOM_RIGHT_Y/2 == NS_CORNER_BOTTOM_RIGHT);
|
|
|
|
PR_STATIC_ASSERT(NS_CORNER_BOTTOM_LEFT_X/2 == NS_CORNER_BOTTOM_LEFT);
|
|
|
|
PR_STATIC_ASSERT(NS_CORNER_BOTTOM_LEFT_Y/2 == NS_CORNER_BOTTOM_LEFT);
|
|
|
|
|
|
|
|
NS_FOR_CSS_HALF_CORNERS(corner) {
|
|
|
|
// corner is a "half corner" value, so dividing by two gives us a
|
|
|
|
// "full corner" value.
|
|
|
|
if (NonZeroStyleCoord(aCorners.Get(corner)) &&
|
|
|
|
IsCornerAdjacentToSide(corner/2, aSide))
|
2011-10-17 07:59:28 -07:00
|
|
|
return true;
|
2009-05-07 18:52:22 -07:00
|
|
|
}
|
2011-10-17 07:59:28 -07:00
|
|
|
return false;
|
2009-05-07 18:52:22 -07:00
|
|
|
}
|
|
|
|
|
2008-08-12 17:44:14 -07:00
|
|
|
/* static */ nsTransparencyMode
|
2009-08-13 15:08:13 -07:00
|
|
|
nsLayoutUtils::GetFrameTransparency(nsIFrame* aBackgroundFrame,
|
|
|
|
nsIFrame* aCSSRootFrame) {
|
|
|
|
if (aCSSRootFrame->GetStyleContext()->GetStyleDisplay()->mOpacity < 1.0f)
|
2008-08-12 17:44:14 -07:00
|
|
|
return eTransparencyTransparent;
|
2007-05-10 08:46:42 -07:00
|
|
|
|
2009-08-13 15:08:13 -07:00
|
|
|
if (HasNonZeroCorner(aCSSRootFrame->GetStyleContext()->GetStyleBorder()->mBorderRadius))
|
2008-08-12 17:44:14 -07:00
|
|
|
return eTransparencyTransparent;
|
2007-05-10 08:46:42 -07:00
|
|
|
|
2009-08-13 15:08:13 -07:00
|
|
|
if (aCSSRootFrame->GetStyleDisplay()->mAppearance == NS_THEME_WIN_GLASS)
|
2008-08-12 17:44:14 -07:00
|
|
|
return eTransparencyGlass;
|
2009-02-04 19:05:48 -08:00
|
|
|
|
2010-08-17 20:07:10 -07:00
|
|
|
if (aCSSRootFrame->GetStyleDisplay()->mAppearance == NS_THEME_WIN_BORDERLESS_GLASS)
|
|
|
|
return eTransparencyBorderlessGlass;
|
|
|
|
|
2010-10-19 10:02:25 -07:00
|
|
|
nsITheme::Transparency transparency;
|
|
|
|
if (aCSSRootFrame->IsThemed(&transparency))
|
|
|
|
return transparency == nsITheme::eTransparent
|
|
|
|
? eTransparencyTransparent
|
|
|
|
: eTransparencyOpaque;
|
|
|
|
|
2009-02-04 19:05:48 -08:00
|
|
|
// We need an uninitialized window to be treated as opaque because
|
|
|
|
// doing otherwise breaks window display effects on some platforms,
|
|
|
|
// specifically Vista. (bug 450322)
|
2009-08-13 15:08:13 -07:00
|
|
|
if (aBackgroundFrame->GetType() == nsGkAtoms::viewportFrame &&
|
2011-08-24 13:54:30 -07:00
|
|
|
!aBackgroundFrame->GetFirstPrincipalChild()) {
|
2009-02-04 19:05:48 -08:00
|
|
|
return eTransparencyOpaque;
|
|
|
|
}
|
|
|
|
|
2010-04-02 18:58:26 -07:00
|
|
|
nsStyleContext* bgSC;
|
2009-08-13 15:08:13 -07:00
|
|
|
if (!nsCSSRendering::FindBackground(aBackgroundFrame->PresContext(),
|
2010-04-02 18:58:26 -07:00
|
|
|
aBackgroundFrame, &bgSC)) {
|
2008-08-12 17:44:14 -07:00
|
|
|
return eTransparencyTransparent;
|
2009-08-13 15:08:13 -07:00
|
|
|
}
|
2010-04-02 18:58:26 -07:00
|
|
|
const nsStyleBackground* bg = bgSC->GetStyleBackground();
|
2009-02-19 21:29:21 -08:00
|
|
|
if (NS_GET_A(bg->mBackgroundColor) < 255 ||
|
|
|
|
// bottom layer's clip is used for the color
|
|
|
|
bg->BottomLayer().mClip != NS_STYLE_BG_CLIP_BORDER)
|
2008-08-12 17:44:14 -07:00
|
|
|
return eTransparencyTransparent;
|
|
|
|
return eTransparencyOpaque;
|
2007-05-10 08:46:42 -07:00
|
|
|
}
|
2007-07-26 02:47:43 -07:00
|
|
|
|
2012-01-16 15:38:10 -08:00
|
|
|
static bool IsPopupFrame(nsIFrame* aFrame)
|
2010-01-11 13:45:18 -08:00
|
|
|
{
|
2012-01-16 15:38:10 -08:00
|
|
|
// aFrame is a popup it's the list control frame dropdown for a combobox.
|
2010-01-11 13:45:18 -08:00
|
|
|
nsIAtom* frameType = aFrame->GetType();
|
|
|
|
if (frameType == nsGkAtoms::listControlFrame) {
|
2012-01-16 15:38:10 -08:00
|
|
|
nsListControlFrame* lcf = static_cast<nsListControlFrame*>(aFrame);
|
|
|
|
return lcf->IsInDropDownMode();
|
2010-01-11 13:45:18 -08:00
|
|
|
}
|
|
|
|
|
2012-01-16 15:38:10 -08:00
|
|
|
// ... or if it's a XUL menupopup frame.
|
|
|
|
return frameType == nsGkAtoms::menuPopupFrame;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* static */ bool
|
|
|
|
nsLayoutUtils::IsPopup(nsIFrame* aFrame)
|
|
|
|
{
|
|
|
|
// Optimization: the frame can't possibly be a popup if it has no view.
|
|
|
|
if (!aFrame->HasView()) {
|
|
|
|
NS_ASSERTION(!IsPopupFrame(aFrame), "popup frame must have a view");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return IsPopupFrame(aFrame);
|
2010-01-11 13:45:18 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
/* static */ nsIFrame*
|
|
|
|
nsLayoutUtils::GetDisplayRootFrame(nsIFrame* aFrame)
|
|
|
|
{
|
|
|
|
nsIFrame* f = aFrame;
|
|
|
|
for (;;) {
|
|
|
|
if (IsPopup(f))
|
|
|
|
return f;
|
|
|
|
nsIFrame* parent = GetCrossDocParentFrame(f);
|
|
|
|
if (!parent)
|
|
|
|
return f;
|
|
|
|
f = parent;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-08-22 08:56:38 -07:00
|
|
|
/* static */ uint32_t
|
2007-07-26 02:47:43 -07:00
|
|
|
nsLayoutUtils::GetTextRunFlagsForStyle(nsStyleContext* aStyleContext,
|
2012-08-02 04:38:47 -07:00
|
|
|
const nsStyleFont* aStyleFont,
|
|
|
|
nscoord aLetterSpacing)
|
2007-07-26 02:47:43 -07:00
|
|
|
{
|
2012-08-22 08:56:38 -07:00
|
|
|
uint32_t result = 0;
|
2012-08-02 04:38:47 -07:00
|
|
|
if (aLetterSpacing != 0) {
|
2007-07-26 02:47:43 -07:00
|
|
|
result |= gfxTextRunFactory::TEXT_DISABLE_OPTIONAL_LIGATURES;
|
|
|
|
}
|
|
|
|
switch (aStyleContext->GetStyleSVG()->mTextRendering) {
|
|
|
|
case NS_STYLE_TEXT_RENDERING_OPTIMIZESPEED:
|
|
|
|
result |= gfxTextRunFactory::TEXT_OPTIMIZE_SPEED;
|
|
|
|
break;
|
|
|
|
case NS_STYLE_TEXT_RENDERING_AUTO:
|
|
|
|
if (aStyleFont->mFont.size <
|
|
|
|
aStyleContext->PresContext()->GetAutoQualityMinFontSize()) {
|
|
|
|
result |= gfxTextRunFactory::TEXT_OPTIMIZE_SPEED;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
return result;
|
|
|
|
}
|
2008-02-08 01:36:32 -08:00
|
|
|
|
|
|
|
/* static */ void
|
|
|
|
nsLayoutUtils::GetRectDifferenceStrips(const nsRect& aR1, const nsRect& aR2,
|
|
|
|
nsRect* aHStrip, nsRect* aVStrip) {
|
|
|
|
NS_ASSERTION(aR1.TopLeft() == aR2.TopLeft(),
|
|
|
|
"expected rects at the same position");
|
2009-09-16 08:01:36 -07:00
|
|
|
nsRect unionRect(aR1.x, aR1.y, NS_MAX(aR1.width, aR2.width),
|
|
|
|
NS_MAX(aR1.height, aR2.height));
|
|
|
|
nscoord VStripStart = NS_MIN(aR1.width, aR2.width);
|
|
|
|
nscoord HStripStart = NS_MIN(aR1.height, aR2.height);
|
2008-02-08 01:36:32 -08:00
|
|
|
*aVStrip = unionRect;
|
|
|
|
aVStrip->x += VStripStart;
|
|
|
|
aVStrip->width -= VStripStart;
|
|
|
|
*aHStrip = unionRect;
|
|
|
|
aHStrip->y += HStripStart;
|
|
|
|
aHStrip->height -= HStripStart;
|
|
|
|
}
|
|
|
|
|
2011-04-16 18:22:44 -07:00
|
|
|
nsDeviceContext*
|
2012-03-14 11:14:53 -07:00
|
|
|
nsLayoutUtils::GetDeviceContextForScreenInfo(nsPIDOMWindow* aWindow)
|
2008-07-26 09:14:49 -07:00
|
|
|
{
|
2012-04-16 02:33:35 -07:00
|
|
|
if (!aWindow) {
|
2012-07-30 07:20:58 -07:00
|
|
|
return nullptr;
|
2012-04-16 02:33:35 -07:00
|
|
|
}
|
|
|
|
|
2012-03-14 11:14:53 -07:00
|
|
|
nsCOMPtr<nsIDocShell> docShell = aWindow->GetDocShell();
|
2008-07-26 09:14:49 -07:00
|
|
|
while (docShell) {
|
|
|
|
// Now make sure our size is up to date. That will mean that the device
|
|
|
|
// context does the right thing on multi-monitor systems when we return it to
|
|
|
|
// the caller. It will also make sure that our prescontext has been created,
|
|
|
|
// if we're supposed to have one.
|
|
|
|
nsCOMPtr<nsPIDOMWindow> win = do_GetInterface(docShell);
|
|
|
|
if (!win) {
|
|
|
|
// No reason to go on
|
2012-07-30 07:20:58 -07:00
|
|
|
return nullptr;
|
2008-07-26 09:14:49 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
win->EnsureSizeUpToDate();
|
|
|
|
|
2009-09-01 09:40:49 -07:00
|
|
|
nsRefPtr<nsPresContext> presContext;
|
|
|
|
docShell->GetPresContext(getter_AddRefs(presContext));
|
|
|
|
if (presContext) {
|
2011-04-16 18:22:44 -07:00
|
|
|
nsDeviceContext* context = presContext->DeviceContext();
|
2009-09-01 09:40:49 -07:00
|
|
|
if (context) {
|
|
|
|
return context;
|
|
|
|
}
|
2008-07-26 09:14:49 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
nsCOMPtr<nsIDocShellTreeItem> curItem = do_QueryInterface(docShell);
|
|
|
|
nsCOMPtr<nsIDocShellTreeItem> parentItem;
|
|
|
|
curItem->GetParent(getter_AddRefs(parentItem));
|
|
|
|
docShell = do_QueryInterface(parentItem);
|
|
|
|
}
|
|
|
|
|
2012-07-30 07:20:58 -07:00
|
|
|
return nullptr;
|
2008-07-26 09:14:49 -07:00
|
|
|
}
|
|
|
|
|
2011-09-28 23:19:26 -07:00
|
|
|
/* static */ bool
|
2008-11-25 13:27:54 -08:00
|
|
|
nsLayoutUtils::IsReallyFixedPos(nsIFrame* aFrame)
|
|
|
|
{
|
|
|
|
NS_PRECONDITION(aFrame->GetParent(),
|
|
|
|
"IsReallyFixedPos called on frame not in tree");
|
|
|
|
NS_PRECONDITION(aFrame->GetStyleDisplay()->mPosition ==
|
|
|
|
NS_STYLE_POSITION_FIXED,
|
|
|
|
"IsReallyFixedPos called on non-'position:fixed' frame");
|
|
|
|
|
2008-12-29 07:07:37 -08:00
|
|
|
nsIAtom *parentType = aFrame->GetParent()->GetType();
|
|
|
|
return parentType == nsGkAtoms::viewportFrame ||
|
|
|
|
parentType == nsGkAtoms::pageContentFrame;
|
2008-11-25 13:27:54 -08:00
|
|
|
}
|
|
|
|
|
2009-06-25 13:30:56 -07:00
|
|
|
nsLayoutUtils::SurfaceFromElementResult
|
2012-05-31 11:16:49 -07:00
|
|
|
nsLayoutUtils::SurfaceFromElement(nsIImageLoadingContent* aElement,
|
2012-08-22 08:56:38 -07:00
|
|
|
uint32_t aSurfaceFlags)
|
2009-06-25 13:30:56 -07:00
|
|
|
{
|
|
|
|
SurfaceFromElementResult result;
|
|
|
|
nsresult rv;
|
|
|
|
|
2011-09-28 23:19:26 -07:00
|
|
|
bool forceCopy = (aSurfaceFlags & SFE_WANT_NEW_SURFACE) != 0;
|
|
|
|
bool wantImageSurface = (aSurfaceFlags & SFE_WANT_IMAGE_SURFACE) != 0;
|
2012-03-23 15:10:50 -07:00
|
|
|
bool premultAlpha = (aSurfaceFlags & SFE_NO_PREMULTIPLY_ALPHA) == 0;
|
2009-06-25 13:30:56 -07:00
|
|
|
|
2012-03-23 15:10:50 -07:00
|
|
|
if (!premultAlpha) {
|
2011-10-17 07:59:28 -07:00
|
|
|
forceCopy = true;
|
|
|
|
wantImageSurface = true;
|
2011-01-12 17:45:13 -08:00
|
|
|
}
|
|
|
|
|
2011-01-31 20:50:01 -08:00
|
|
|
// Push a null JSContext on the stack so that code that runs within
|
|
|
|
// the below code doesn't think it's being called by JS. See bug
|
|
|
|
// 604262.
|
|
|
|
nsCxPusher pusher;
|
|
|
|
pusher.PushNull();
|
|
|
|
|
2009-06-25 13:30:56 -07:00
|
|
|
nsCOMPtr<imgIRequest> imgRequest;
|
2012-05-31 11:16:49 -07:00
|
|
|
rv = aElement->GetRequest(nsIImageLoadingContent::CURRENT_REQUEST,
|
|
|
|
getter_AddRefs(imgRequest));
|
2009-06-25 13:30:56 -07:00
|
|
|
if (NS_FAILED(rv) || !imgRequest)
|
|
|
|
return result;
|
|
|
|
|
2012-08-22 08:56:38 -07:00
|
|
|
uint32_t status;
|
2009-06-25 13:30:56 -07:00
|
|
|
imgRequest->GetImageStatus(&status);
|
2010-06-18 09:23:05 -07:00
|
|
|
if ((status & imgIRequest::STATUS_LOAD_COMPLETE) == 0) {
|
|
|
|
// Spec says to use GetComplete, but that only works on
|
|
|
|
// nsIDOMHTMLImageElement, and we support all sorts of other stuff
|
|
|
|
// here. Do this for now pending spec clarification.
|
|
|
|
result.mIsStillLoading = (status & imgIRequest::STATUS_ERROR) == 0;
|
2009-06-25 13:30:56 -07:00
|
|
|
return result;
|
2010-06-18 09:23:05 -07:00
|
|
|
}
|
2009-06-25 13:30:56 -07:00
|
|
|
|
|
|
|
nsCOMPtr<nsIPrincipal> principal;
|
2011-09-20 14:00:42 -07:00
|
|
|
rv = imgRequest->GetImagePrincipal(getter_AddRefs(principal));
|
|
|
|
if (NS_FAILED(rv) || !principal)
|
|
|
|
return result;
|
2009-06-25 13:30:56 -07:00
|
|
|
|
Bug 753 - Remove nsIImage, gfxIImageFrame, and their implementations, and expose an equivalent api on imgIContainer. r=roc,josh,bz,longsonr,vlad,karlt,jimm,bsmedberg,mfinkle,peterw,peterv sr=vlad,roc
--HG--
rename : gfx/src/shared/gfxImageFrame.cpp => modules/libpr0n/src/imgFrame.cpp
rename : gfx/src/shared/gfxImageFrame.h => modules/libpr0n/src/imgFrame.h
2009-07-20 18:50:15 -07:00
|
|
|
nsCOMPtr<imgIContainer> imgContainer;
|
2009-06-25 13:30:56 -07:00
|
|
|
rv = imgRequest->GetImage(getter_AddRefs(imgContainer));
|
|
|
|
if (NS_FAILED(rv) || !imgContainer)
|
|
|
|
return result;
|
|
|
|
|
2012-08-22 08:56:38 -07:00
|
|
|
uint32_t whichFrame = (aSurfaceFlags & SFE_WANT_FIRST_FRAME)
|
|
|
|
? (uint32_t) imgIContainer::FRAME_FIRST
|
|
|
|
: (uint32_t) imgIContainer::FRAME_CURRENT;
|
|
|
|
uint32_t frameFlags = imgIContainer::FLAG_SYNC_DECODE;
|
2011-01-12 17:45:13 -08:00
|
|
|
if (aSurfaceFlags & SFE_NO_COLORSPACE_CONVERSION)
|
|
|
|
frameFlags |= imgIContainer::FLAG_DECODE_NO_COLORSPACE_CONVERSION;
|
|
|
|
if (aSurfaceFlags & SFE_NO_PREMULTIPLY_ALPHA)
|
|
|
|
frameFlags |= imgIContainer::FLAG_DECODE_NO_PREMULTIPLY_ALPHA;
|
Bug 753 - Remove nsIImage, gfxIImageFrame, and their implementations, and expose an equivalent api on imgIContainer. r=roc,josh,bz,longsonr,vlad,karlt,jimm,bsmedberg,mfinkle,peterw,peterv sr=vlad,roc
--HG--
rename : gfx/src/shared/gfxImageFrame.cpp => modules/libpr0n/src/imgFrame.cpp
rename : gfx/src/shared/gfxImageFrame.h => modules/libpr0n/src/imgFrame.h
2009-07-20 18:50:15 -07:00
|
|
|
nsRefPtr<gfxASurface> framesurf;
|
2009-09-12 15:44:18 -07:00
|
|
|
rv = imgContainer->GetFrame(whichFrame,
|
2011-01-12 17:45:13 -08:00
|
|
|
frameFlags,
|
2009-09-12 15:44:18 -07:00
|
|
|
getter_AddRefs(framesurf));
|
2009-06-25 13:30:56 -07:00
|
|
|
if (NS_FAILED(rv))
|
|
|
|
return result;
|
|
|
|
|
2012-08-22 08:56:38 -07:00
|
|
|
int32_t imgWidth, imgHeight;
|
Bug 753 - Remove nsIImage, gfxIImageFrame, and their implementations, and expose an equivalent api on imgIContainer. r=roc,josh,bz,longsonr,vlad,karlt,jimm,bsmedberg,mfinkle,peterw,peterv sr=vlad,roc
--HG--
rename : gfx/src/shared/gfxImageFrame.cpp => modules/libpr0n/src/imgFrame.cpp
rename : gfx/src/shared/gfxImageFrame.h => modules/libpr0n/src/imgFrame.h
2009-07-20 18:50:15 -07:00
|
|
|
rv = imgContainer->GetWidth(&imgWidth);
|
2012-07-27 07:03:08 -07:00
|
|
|
nsresult rv2 = imgContainer->GetHeight(&imgHeight);
|
|
|
|
if (NS_FAILED(rv) || NS_FAILED(rv2))
|
2009-06-25 13:30:56 -07:00
|
|
|
return result;
|
|
|
|
|
Bug 753 - Remove nsIImage, gfxIImageFrame, and their implementations, and expose an equivalent api on imgIContainer. r=roc,josh,bz,longsonr,vlad,karlt,jimm,bsmedberg,mfinkle,peterw,peterv sr=vlad,roc
--HG--
rename : gfx/src/shared/gfxImageFrame.cpp => modules/libpr0n/src/imgFrame.cpp
rename : gfx/src/shared/gfxImageFrame.h => modules/libpr0n/src/imgFrame.h
2009-07-20 18:50:15 -07:00
|
|
|
if (wantImageSurface && framesurf->GetType() != gfxASurface::SurfaceTypeImage) {
|
2011-10-17 07:59:28 -07:00
|
|
|
forceCopy = true;
|
2009-06-25 13:30:56 -07:00
|
|
|
}
|
|
|
|
|
Bug 753 - Remove nsIImage, gfxIImageFrame, and their implementations, and expose an equivalent api on imgIContainer. r=roc,josh,bz,longsonr,vlad,karlt,jimm,bsmedberg,mfinkle,peterw,peterv sr=vlad,roc
--HG--
rename : gfx/src/shared/gfxImageFrame.cpp => modules/libpr0n/src/imgFrame.cpp
rename : gfx/src/shared/gfxImageFrame.h => modules/libpr0n/src/imgFrame.h
2009-07-20 18:50:15 -07:00
|
|
|
nsRefPtr<gfxASurface> gfxsurf = framesurf;
|
|
|
|
if (forceCopy) {
|
2009-06-25 13:30:56 -07:00
|
|
|
if (wantImageSurface) {
|
|
|
|
gfxsurf = new gfxImageSurface (gfxIntSize(imgWidth, imgHeight), gfxASurface::ImageFormatARGB32);
|
|
|
|
} else {
|
|
|
|
gfxsurf = gfxPlatform::GetPlatform()->CreateOffscreenSurface(gfxIntSize(imgWidth, imgHeight),
|
2010-09-16 14:34:53 -07:00
|
|
|
gfxASurface::CONTENT_COLOR_ALPHA);
|
2009-06-25 13:30:56 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
nsRefPtr<gfxContext> ctx = new gfxContext(gfxsurf);
|
|
|
|
|
|
|
|
ctx->SetOperator(gfxContext::OPERATOR_SOURCE);
|
Bug 753 - Remove nsIImage, gfxIImageFrame, and their implementations, and expose an equivalent api on imgIContainer. r=roc,josh,bz,longsonr,vlad,karlt,jimm,bsmedberg,mfinkle,peterw,peterv sr=vlad,roc
--HG--
rename : gfx/src/shared/gfxImageFrame.cpp => modules/libpr0n/src/imgFrame.cpp
rename : gfx/src/shared/gfxImageFrame.h => modules/libpr0n/src/imgFrame.h
2009-07-20 18:50:15 -07:00
|
|
|
ctx->SetSource(framesurf);
|
2009-06-25 13:30:56 -07:00
|
|
|
ctx->Paint();
|
|
|
|
}
|
|
|
|
|
2012-08-22 08:56:38 -07:00
|
|
|
int32_t corsmode;
|
2011-09-09 14:58:35 -07:00
|
|
|
if (NS_SUCCEEDED(imgRequest->GetCORSMode(&corsmode))) {
|
|
|
|
result.mCORSUsed = (corsmode != imgIRequest::CORS_NONE);
|
|
|
|
}
|
|
|
|
|
2009-06-25 13:30:56 -07:00
|
|
|
result.mSurface = gfxsurf;
|
|
|
|
result.mSize = gfxIntSize(imgWidth, imgHeight);
|
2011-03-23 20:13:56 -07:00
|
|
|
result.mPrincipal = principal.forget();
|
2011-12-18 13:57:41 -08:00
|
|
|
// no images, including SVG images, can load content from another domain.
|
|
|
|
result.mIsWriteOnly = false;
|
2011-03-23 20:13:56 -07:00
|
|
|
result.mImageRequest = imgRequest.forget();
|
2009-06-25 13:30:56 -07:00
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2012-05-31 11:16:49 -07:00
|
|
|
nsLayoutUtils::SurfaceFromElementResult
|
|
|
|
nsLayoutUtils::SurfaceFromElement(nsHTMLImageElement *aElement,
|
2012-08-22 08:56:38 -07:00
|
|
|
uint32_t aSurfaceFlags)
|
2012-05-31 11:16:49 -07:00
|
|
|
{
|
|
|
|
return SurfaceFromElement(static_cast<nsIImageLoadingContent*>(aElement),
|
|
|
|
aSurfaceFlags);
|
|
|
|
}
|
|
|
|
|
|
|
|
nsLayoutUtils::SurfaceFromElementResult
|
|
|
|
nsLayoutUtils::SurfaceFromElement(nsHTMLCanvasElement* aElement,
|
2012-08-22 08:56:38 -07:00
|
|
|
uint32_t aSurfaceFlags)
|
2012-05-31 11:16:49 -07:00
|
|
|
{
|
|
|
|
SurfaceFromElementResult result;
|
|
|
|
nsresult rv;
|
|
|
|
|
|
|
|
bool forceCopy = (aSurfaceFlags & SFE_WANT_NEW_SURFACE) != 0;
|
|
|
|
bool wantImageSurface = (aSurfaceFlags & SFE_WANT_IMAGE_SURFACE) != 0;
|
|
|
|
bool premultAlpha = (aSurfaceFlags & SFE_NO_PREMULTIPLY_ALPHA) == 0;
|
|
|
|
|
|
|
|
if (!premultAlpha) {
|
|
|
|
forceCopy = true;
|
|
|
|
wantImageSurface = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
gfxIntSize size = aElement->GetSize();
|
|
|
|
|
|
|
|
nsRefPtr<gfxASurface> surf;
|
|
|
|
|
|
|
|
if (!forceCopy && aElement->CountContexts() == 1) {
|
|
|
|
nsICanvasRenderingContextInternal *srcCanvas = aElement->GetContextAtIndex(0);
|
|
|
|
rv = srcCanvas->GetThebesSurface(getter_AddRefs(surf));
|
|
|
|
|
|
|
|
if (NS_FAILED(rv))
|
2012-07-30 07:20:58 -07:00
|
|
|
surf = nullptr;
|
2012-05-31 11:16:49 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
if (surf && wantImageSurface && surf->GetType() != gfxASurface::SurfaceTypeImage)
|
2012-07-30 07:20:58 -07:00
|
|
|
surf = nullptr;
|
2012-05-31 11:16:49 -07:00
|
|
|
|
|
|
|
if (!surf) {
|
|
|
|
if (wantImageSurface) {
|
|
|
|
surf = new gfxImageSurface(size, gfxASurface::ImageFormatARGB32);
|
|
|
|
} else {
|
|
|
|
surf = gfxPlatform::GetPlatform()->CreateOffscreenSurface(size, gfxASurface::CONTENT_COLOR_ALPHA);
|
|
|
|
}
|
|
|
|
|
|
|
|
nsRefPtr<gfxContext> ctx = new gfxContext(surf);
|
|
|
|
// XXX shouldn't use the external interface, but maybe we can layerify this
|
2012-08-22 08:56:38 -07:00
|
|
|
uint32_t flags = premultAlpha ? nsHTMLCanvasElement::RenderFlagPremultAlpha : 0;
|
2012-05-31 11:16:49 -07:00
|
|
|
rv = aElement->RenderContextsExternal(ctx, gfxPattern::FILTER_NEAREST, flags);
|
|
|
|
if (NS_FAILED(rv))
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Ensure that any future changes to the canvas trigger proper invalidation,
|
|
|
|
// in case this is being used by -moz-element()
|
|
|
|
aElement->MarkContextClean();
|
|
|
|
|
|
|
|
result.mSurface = surf;
|
|
|
|
result.mSize = size;
|
|
|
|
result.mPrincipal = aElement->NodePrincipal();
|
|
|
|
result.mIsWriteOnly = aElement->IsWriteOnly();
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsLayoutUtils::SurfaceFromElementResult
|
|
|
|
nsLayoutUtils::SurfaceFromElement(nsHTMLVideoElement* aElement,
|
2012-08-22 08:56:38 -07:00
|
|
|
uint32_t aSurfaceFlags)
|
2012-05-31 11:16:49 -07:00
|
|
|
{
|
|
|
|
SurfaceFromElementResult result;
|
|
|
|
|
|
|
|
bool wantImageSurface = (aSurfaceFlags & SFE_WANT_IMAGE_SURFACE) != 0;
|
|
|
|
bool premultAlpha = (aSurfaceFlags & SFE_NO_PREMULTIPLY_ALPHA) == 0;
|
|
|
|
|
|
|
|
if (!premultAlpha) {
|
|
|
|
wantImageSurface = true;
|
|
|
|
}
|
|
|
|
|
2012-08-22 08:56:38 -07:00
|
|
|
uint16_t readyState;
|
2012-05-31 11:16:49 -07:00
|
|
|
if (NS_SUCCEEDED(aElement->GetReadyState(&readyState)) &&
|
|
|
|
(readyState == nsIDOMHTMLMediaElement::HAVE_NOTHING ||
|
|
|
|
readyState == nsIDOMHTMLMediaElement::HAVE_METADATA)) {
|
|
|
|
result.mIsStillLoading = true;
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
// If it doesn't have a principal, just bail
|
|
|
|
nsCOMPtr<nsIPrincipal> principal = aElement->GetCurrentPrincipal();
|
|
|
|
if (!principal)
|
|
|
|
return result;
|
|
|
|
|
|
|
|
ImageContainer *container = aElement->GetImageContainer();
|
|
|
|
if (!container)
|
|
|
|
return result;
|
|
|
|
|
|
|
|
gfxIntSize size;
|
|
|
|
nsRefPtr<gfxASurface> surf = container->GetCurrentAsSurface(&size);
|
|
|
|
if (!surf)
|
|
|
|
return result;
|
|
|
|
|
|
|
|
if (wantImageSurface && surf->GetType() != gfxASurface::SurfaceTypeImage) {
|
|
|
|
nsRefPtr<gfxImageSurface> imgSurf =
|
|
|
|
new gfxImageSurface(size, gfxASurface::ImageFormatARGB32);
|
|
|
|
|
|
|
|
nsRefPtr<gfxContext> ctx = new gfxContext(imgSurf);
|
|
|
|
ctx->SetOperator(gfxContext::OPERATOR_SOURCE);
|
|
|
|
ctx->DrawSurface(surf, size);
|
|
|
|
surf = imgSurf;
|
|
|
|
}
|
|
|
|
|
|
|
|
result.mCORSUsed = aElement->GetCORSMode() != CORS_NONE;
|
|
|
|
result.mSurface = surf;
|
|
|
|
result.mSize = size;
|
|
|
|
result.mPrincipal = principal.forget();
|
|
|
|
result.mIsWriteOnly = false;
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsLayoutUtils::SurfaceFromElementResult
|
|
|
|
nsLayoutUtils::SurfaceFromElement(dom::Element* aElement,
|
2012-08-22 08:56:38 -07:00
|
|
|
uint32_t aSurfaceFlags)
|
2012-05-31 11:16:49 -07:00
|
|
|
{
|
|
|
|
// If it's a <canvas>, we may be able to just grab its internal surface
|
|
|
|
if (nsHTMLCanvasElement* canvas = nsHTMLCanvasElement::FromContent(aElement)) {
|
|
|
|
return SurfaceFromElement(canvas, aSurfaceFlags);
|
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef MOZ_MEDIA
|
|
|
|
// Maybe it's <video>?
|
|
|
|
if (nsHTMLVideoElement* video = nsHTMLVideoElement::FromContent(aElement)) {
|
|
|
|
return SurfaceFromElement(video, aSurfaceFlags);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
// Finally, check if it's a normal image
|
|
|
|
nsCOMPtr<nsIImageLoadingContent> imageLoader = do_QueryInterface(aElement);
|
|
|
|
|
|
|
|
if (!imageLoader) {
|
|
|
|
return SurfaceFromElementResult();
|
|
|
|
}
|
|
|
|
|
|
|
|
return SurfaceFromElement(imageLoader, aSurfaceFlags);
|
|
|
|
}
|
|
|
|
|
2010-04-21 06:13:08 -07:00
|
|
|
/* static */
|
|
|
|
nsIContent*
|
|
|
|
nsLayoutUtils::GetEditableRootContentByContentEditable(nsIDocument* aDocument)
|
|
|
|
{
|
|
|
|
// If the document is in designMode we should return NULL.
|
|
|
|
if (!aDocument || aDocument->HasFlag(NODE_IS_EDITABLE)) {
|
2012-07-30 07:20:58 -07:00
|
|
|
return nullptr;
|
2010-04-21 06:13:08 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
// contenteditable only works with HTML document.
|
|
|
|
// Note: Use nsIDOMHTMLDocument rather than nsIHTMLDocument for getting the
|
|
|
|
// body node because nsIDOMHTMLDocument::GetBody() does something
|
|
|
|
// additional work for some cases and nsEditor uses them.
|
|
|
|
nsCOMPtr<nsIDOMHTMLDocument> domHTMLDoc = do_QueryInterface(aDocument);
|
|
|
|
if (!domHTMLDoc) {
|
2012-07-30 07:20:58 -07:00
|
|
|
return nullptr;
|
2010-04-21 06:13:08 -07:00
|
|
|
}
|
|
|
|
|
2010-04-30 06:12:05 -07:00
|
|
|
Element* rootElement = aDocument->GetRootElement();
|
|
|
|
if (rootElement && rootElement->IsEditable()) {
|
|
|
|
return rootElement;
|
2010-04-21 06:13:08 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
// If there are no editable root element, check its <body> element.
|
|
|
|
// Note that the body element could be <frameset> element.
|
|
|
|
nsCOMPtr<nsIDOMHTMLElement> body;
|
|
|
|
nsresult rv = domHTMLDoc->GetBody(getter_AddRefs(body));
|
|
|
|
nsCOMPtr<nsIContent> content = do_QueryInterface(body);
|
|
|
|
if (NS_SUCCEEDED(rv) && content && content->IsEditable()) {
|
|
|
|
return content;
|
|
|
|
}
|
2012-07-30 07:20:58 -07:00
|
|
|
return nullptr;
|
2010-04-21 06:13:08 -07:00
|
|
|
}
|
|
|
|
|
2011-01-11 17:09:21 -08:00
|
|
|
#ifdef DEBUG
|
|
|
|
/* static */ void
|
|
|
|
nsLayoutUtils::AssertNoDuplicateContinuations(nsIFrame* aContainer,
|
|
|
|
const nsFrameList& aFrameList)
|
|
|
|
{
|
|
|
|
for (nsIFrame* f = aFrameList.FirstChild(); f ; f = f->GetNextSibling()) {
|
|
|
|
// Check only later continuations of f; we deal with checking the
|
|
|
|
// earlier continuations when we hit those earlier continuations in
|
|
|
|
// the frame list.
|
|
|
|
for (nsIFrame *c = f; (c = c->GetNextInFlow());) {
|
|
|
|
NS_ASSERTION(c->GetParent() != aContainer ||
|
|
|
|
!aFrameList.ContainsFrame(c),
|
|
|
|
"Two continuations of the same frame in the same "
|
|
|
|
"frame list");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2011-01-11 17:09:22 -08:00
|
|
|
|
|
|
|
// Is one of aFrame's ancestors a letter frame?
|
|
|
|
static bool
|
|
|
|
IsInLetterFrame(nsIFrame *aFrame)
|
|
|
|
{
|
|
|
|
for (nsIFrame *f = aFrame->GetParent(); f; f = f->GetParent()) {
|
|
|
|
if (f->GetType() == nsGkAtoms::letterFrame) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* static */ void
|
|
|
|
nsLayoutUtils::AssertTreeOnlyEmptyNextInFlows(nsIFrame *aSubtreeRoot)
|
|
|
|
{
|
|
|
|
NS_ASSERTION(aSubtreeRoot->GetPrevInFlow(),
|
|
|
|
"frame tree not empty, but caller reported complete status");
|
|
|
|
|
|
|
|
// Also assert that text frames map no text.
|
2012-08-22 08:56:38 -07:00
|
|
|
int32_t start, end;
|
2011-01-11 17:09:22 -08:00
|
|
|
nsresult rv = aSubtreeRoot->GetOffsets(start, end);
|
|
|
|
NS_ASSERTION(NS_SUCCEEDED(rv), "GetOffsets failed");
|
|
|
|
// In some cases involving :first-letter, we'll partially unlink a
|
|
|
|
// continuation in the middle of a continuation chain from its
|
|
|
|
// previous and next continuations before destroying it, presumably so
|
|
|
|
// that we don't also destroy the later continuations. Once we've
|
|
|
|
// done this, GetOffsets returns incorrect values.
|
|
|
|
// For examples, see list of tests in
|
|
|
|
// https://bugzilla.mozilla.org/show_bug.cgi?id=619021#c29
|
|
|
|
NS_ASSERTION(start == end || IsInLetterFrame(aSubtreeRoot),
|
|
|
|
"frame tree not empty, but caller reported complete status");
|
|
|
|
|
2011-08-24 13:54:29 -07:00
|
|
|
nsIFrame::ChildListIterator lists(aSubtreeRoot);
|
|
|
|
for (; !lists.IsDone(); lists.Next()) {
|
|
|
|
nsFrameList::Enumerator childFrames(lists.CurrentList());
|
|
|
|
for (; !childFrames.AtEnd(); childFrames.Next()) {
|
|
|
|
nsLayoutUtils::AssertTreeOnlyEmptyNextInFlows(childFrames.get());
|
2011-01-11 17:09:22 -08:00
|
|
|
}
|
2011-08-24 13:54:29 -07:00
|
|
|
}
|
2011-01-11 17:09:22 -08:00
|
|
|
}
|
2011-01-11 17:09:21 -08:00
|
|
|
#endif
|
|
|
|
|
2011-06-15 23:31:36 -07:00
|
|
|
/* static */
|
|
|
|
nsresult
|
|
|
|
nsLayoutUtils::GetFontFacesForFrames(nsIFrame* aFrame,
|
|
|
|
nsFontFaceList* aFontFaceList)
|
|
|
|
{
|
|
|
|
NS_PRECONDITION(aFrame, "NULL frame pointer");
|
|
|
|
|
|
|
|
if (aFrame->GetType() == nsGkAtoms::textFrame) {
|
2011-10-17 07:59:28 -07:00
|
|
|
return GetFontFacesForText(aFrame, 0, PR_INT32_MAX, false,
|
2011-06-15 23:31:36 -07:00
|
|
|
aFontFaceList);
|
|
|
|
}
|
|
|
|
|
|
|
|
while (aFrame) {
|
2011-08-24 13:54:29 -07:00
|
|
|
nsIFrame::ChildListID childLists[] = { nsIFrame::kPrincipalList,
|
|
|
|
nsIFrame::kPopupList };
|
2011-12-19 19:46:39 -08:00
|
|
|
for (size_t i = 0; i < ArrayLength(childLists); ++i) {
|
2011-06-15 23:31:36 -07:00
|
|
|
nsFrameList children(aFrame->GetChildList(childLists[i]));
|
|
|
|
for (nsFrameList::Enumerator e(children); !e.AtEnd(); e.Next()) {
|
|
|
|
nsIFrame* child = e.get();
|
|
|
|
if (child->GetPrevContinuation()) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
child = nsPlaceholderFrame::GetRealFrameFor(child);
|
|
|
|
nsresult rv = GetFontFacesForFrames(child, aFontFaceList);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
aFrame = GetNextContinuationOrSpecialSibling(aFrame);
|
|
|
|
}
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* static */
|
|
|
|
nsresult
|
|
|
|
nsLayoutUtils::GetFontFacesForText(nsIFrame* aFrame,
|
2012-08-22 08:56:38 -07:00
|
|
|
int32_t aStartOffset, int32_t aEndOffset,
|
2011-09-28 23:19:26 -07:00
|
|
|
bool aFollowContinuations,
|
2011-06-15 23:31:36 -07:00
|
|
|
nsFontFaceList* aFontFaceList)
|
|
|
|
{
|
|
|
|
NS_PRECONDITION(aFrame, "NULL frame pointer");
|
|
|
|
|
|
|
|
if (aFrame->GetType() != nsGkAtoms::textFrame) {
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsTextFrame* curr = static_cast<nsTextFrame*>(aFrame);
|
|
|
|
do {
|
2012-08-22 08:56:38 -07:00
|
|
|
int32_t fstart = NS_MAX(curr->GetContentOffset(), aStartOffset);
|
|
|
|
int32_t fend = NS_MIN(curr->GetContentEnd(), aEndOffset);
|
2011-06-15 23:31:36 -07:00
|
|
|
if (fstart >= fend) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
// overlapping with the offset we want
|
2011-11-23 18:48:23 -08:00
|
|
|
gfxSkipCharsIterator iter = curr->EnsureTextRun(nsTextFrame::eInflated);
|
|
|
|
gfxTextRun* textRun = curr->GetTextRun(nsTextFrame::eInflated);
|
2011-06-15 23:31:36 -07:00
|
|
|
NS_ENSURE_TRUE(textRun, NS_ERROR_OUT_OF_MEMORY);
|
|
|
|
|
2012-08-22 08:56:38 -07:00
|
|
|
uint32_t skipStart = iter.ConvertOriginalToSkipped(fstart);
|
|
|
|
uint32_t skipEnd = iter.ConvertOriginalToSkipped(fend);
|
2011-06-15 23:31:36 -07:00
|
|
|
aFontFaceList->AddFontsFromTextRun(textRun,
|
2011-10-21 00:13:51 -07:00
|
|
|
skipStart,
|
|
|
|
skipEnd - skipStart,
|
2011-06-15 23:31:36 -07:00
|
|
|
curr);
|
2011-06-15 23:31:36 -07:00
|
|
|
} while (aFollowContinuations &&
|
|
|
|
(curr = static_cast<nsTextFrame*>(curr->GetNextContinuation())));
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2011-10-14 00:06:35 -07:00
|
|
|
/* static */
|
2011-11-27 19:03:14 -08:00
|
|
|
size_t
|
|
|
|
nsLayoutUtils::SizeOfTextRunsForFrames(nsIFrame* aFrame,
|
|
|
|
nsMallocSizeOfFun aMallocSizeOf,
|
|
|
|
bool clear)
|
2011-10-14 00:06:35 -07:00
|
|
|
{
|
|
|
|
NS_PRECONDITION(aFrame, "NULL frame pointer");
|
|
|
|
|
2011-11-27 19:03:14 -08:00
|
|
|
size_t total = 0;
|
|
|
|
|
2011-10-14 00:06:35 -07:00
|
|
|
if (aFrame->GetType() == nsGkAtoms::textFrame) {
|
|
|
|
nsTextFrame* textFrame = static_cast<nsTextFrame*>(aFrame);
|
2012-08-22 08:56:38 -07:00
|
|
|
for (uint32_t i = 0; i < 2; ++i) {
|
2011-11-23 18:48:23 -08:00
|
|
|
gfxTextRun *run = textFrame->GetTextRun(
|
|
|
|
(i != 0) ? nsTextFrame::eInflated : nsTextFrame::eNotInflated);
|
|
|
|
if (run) {
|
2011-11-27 19:03:14 -08:00
|
|
|
if (clear) {
|
|
|
|
run->ResetSizeOfAccountingFlags();
|
2011-11-23 18:48:23 -08:00
|
|
|
} else {
|
2011-11-27 19:03:14 -08:00
|
|
|
total += run->MaybeSizeOfIncludingThis(aMallocSizeOf);
|
2011-11-23 18:48:23 -08:00
|
|
|
}
|
2011-10-14 00:06:35 -07:00
|
|
|
}
|
|
|
|
}
|
2011-11-27 19:03:14 -08:00
|
|
|
return total;
|
2011-10-14 00:06:35 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
nsAutoTArray<nsIFrame::ChildList,4> childListArray;
|
|
|
|
aFrame->GetChildLists(&childListArray);
|
|
|
|
|
|
|
|
for (nsIFrame::ChildListArrayIterator childLists(childListArray);
|
|
|
|
!childLists.IsDone(); childLists.Next()) {
|
|
|
|
for (nsFrameList::Enumerator e(childLists.CurrentList());
|
|
|
|
!e.AtEnd(); e.Next()) {
|
2011-11-27 19:03:14 -08:00
|
|
|
total += SizeOfTextRunsForFrames(e.get(), aMallocSizeOf, clear);
|
2011-10-14 00:06:35 -07:00
|
|
|
}
|
|
|
|
}
|
2011-11-27 19:03:14 -08:00
|
|
|
return total;
|
2011-10-14 00:06:35 -07:00
|
|
|
}
|
|
|
|
|
2011-11-23 18:48:23 -08:00
|
|
|
/* static */
|
|
|
|
void
|
|
|
|
nsLayoutUtils::Initialize()
|
|
|
|
{
|
|
|
|
mozilla::Preferences::AddUintVarCache(&sFontSizeInflationEmPerLine,
|
|
|
|
"font.size.inflation.emPerLine");
|
|
|
|
mozilla::Preferences::AddUintVarCache(&sFontSizeInflationMinTwips,
|
|
|
|
"font.size.inflation.minTwips");
|
2012-04-16 15:32:11 -07:00
|
|
|
mozilla::Preferences::AddUintVarCache(&sFontSizeInflationLineThreshold,
|
|
|
|
"font.size.inflation.lineThreshold");
|
2012-08-11 11:33:36 -07:00
|
|
|
mozilla::Preferences::AddIntVarCache(&sFontSizeInflationMappingIntercept,
|
|
|
|
"font.size.inflation.mappingIntercept");
|
2011-11-23 18:48:23 -08:00
|
|
|
}
|
|
|
|
|
2011-01-13 09:45:14 -08:00
|
|
|
/* static */
|
|
|
|
void
|
|
|
|
nsLayoutUtils::Shutdown()
|
|
|
|
{
|
|
|
|
if (sContentMap) {
|
|
|
|
delete sContentMap;
|
|
|
|
sContentMap = NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-11-09 13:39:16 -08:00
|
|
|
/* static */
|
|
|
|
void
|
|
|
|
nsLayoutUtils::RegisterImageRequest(nsPresContext* aPresContext,
|
|
|
|
imgIRequest* aRequest,
|
|
|
|
bool* aRequestRegistered)
|
|
|
|
{
|
|
|
|
if (!aPresContext) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (aRequestRegistered && *aRequestRegistered) {
|
|
|
|
// Our request is already registered with the refresh driver, so
|
|
|
|
// no need to register it again.
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (aRequest) {
|
|
|
|
if (!aPresContext->RefreshDriver()->AddImageRequest(aRequest)) {
|
|
|
|
NS_WARNING("Unable to add image request");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (aRequestRegistered) {
|
|
|
|
*aRequestRegistered = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* static */
|
|
|
|
void
|
|
|
|
nsLayoutUtils::RegisterImageRequestIfAnimated(nsPresContext* aPresContext,
|
|
|
|
imgIRequest* aRequest,
|
|
|
|
bool* aRequestRegistered)
|
|
|
|
{
|
|
|
|
if (!aPresContext) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (aRequestRegistered && *aRequestRegistered) {
|
|
|
|
// Our request is already registered with the refresh driver, so
|
|
|
|
// no need to register it again.
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (aRequest) {
|
|
|
|
nsCOMPtr<imgIContainer> image;
|
|
|
|
aRequest->GetImage(getter_AddRefs(image));
|
|
|
|
if (image) {
|
|
|
|
|
|
|
|
// Check to verify that the image is animated. If so, then add it to the
|
|
|
|
// list of images tracked by the refresh driver.
|
|
|
|
bool isAnimated = false;
|
|
|
|
nsresult rv = image->GetAnimated(&isAnimated);
|
|
|
|
if (NS_SUCCEEDED(rv) && isAnimated) {
|
|
|
|
if (!aPresContext->RefreshDriver()->AddImageRequest(aRequest)) {
|
|
|
|
NS_WARNING("Unable to add image request");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (aRequestRegistered) {
|
|
|
|
*aRequestRegistered = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* static */
|
|
|
|
void
|
|
|
|
nsLayoutUtils::DeregisterImageRequest(nsPresContext* aPresContext,
|
|
|
|
imgIRequest* aRequest,
|
|
|
|
bool* aRequestRegistered)
|
|
|
|
{
|
|
|
|
if (!aPresContext) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Deregister our imgIRequest with the refresh driver to
|
|
|
|
// complete tear-down, but only if it has been registered
|
|
|
|
if (aRequestRegistered && !*aRequestRegistered) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (aRequest) {
|
|
|
|
nsCOMPtr<imgIContainer> image;
|
|
|
|
aRequest->GetImage(getter_AddRefs(image));
|
|
|
|
if (image) {
|
|
|
|
aPresContext->RefreshDriver()->RemoveImageRequest(aRequest);
|
|
|
|
|
|
|
|
if (aRequestRegistered) {
|
|
|
|
*aRequestRegistered = false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-05-16 21:05:09 -07:00
|
|
|
/* static */
|
|
|
|
void
|
|
|
|
nsLayoutUtils::PostRestyleEvent(Element* aElement,
|
|
|
|
nsRestyleHint aRestyleHint,
|
|
|
|
nsChangeHint aMinChangeHint)
|
|
|
|
{
|
|
|
|
nsIDocument* doc = aElement->GetCurrentDoc();
|
|
|
|
if (doc) {
|
|
|
|
nsCOMPtr<nsIPresShell> presShell = doc->GetShell();
|
|
|
|
if (presShell) {
|
|
|
|
presShell->FrameConstructor()->PostRestyleEvent(
|
|
|
|
aElement, aRestyleHint, aMinChangeHint);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-04-14 16:59:21 -07:00
|
|
|
nsSetAttrRunnable::nsSetAttrRunnable(nsIContent* aContent, nsIAtom* aAttrName,
|
|
|
|
const nsAString& aValue)
|
|
|
|
: mContent(aContent),
|
|
|
|
mAttrName(aAttrName),
|
|
|
|
mValue(aValue)
|
|
|
|
{
|
|
|
|
NS_ASSERTION(aContent && aAttrName, "Missing stuff, prepare to crash");
|
|
|
|
}
|
|
|
|
|
2010-05-03 06:23:36 -07:00
|
|
|
nsSetAttrRunnable::nsSetAttrRunnable(nsIContent* aContent, nsIAtom* aAttrName,
|
2012-08-22 08:56:38 -07:00
|
|
|
int32_t aValue)
|
2010-05-03 06:23:36 -07:00
|
|
|
: mContent(aContent),
|
|
|
|
mAttrName(aAttrName)
|
|
|
|
{
|
|
|
|
NS_ASSERTION(aContent && aAttrName, "Missing stuff, prepare to crash");
|
|
|
|
mValue.AppendInt(aValue);
|
|
|
|
}
|
|
|
|
|
2008-04-14 16:59:21 -07:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsSetAttrRunnable::Run()
|
|
|
|
{
|
2011-10-17 07:59:28 -07:00
|
|
|
return mContent->SetAttr(kNameSpaceID_None, mAttrName, mValue, true);
|
2008-04-14 16:59:21 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
nsUnsetAttrRunnable::nsUnsetAttrRunnable(nsIContent* aContent,
|
|
|
|
nsIAtom* aAttrName)
|
|
|
|
: mContent(aContent),
|
|
|
|
mAttrName(aAttrName)
|
|
|
|
{
|
|
|
|
NS_ASSERTION(aContent && aAttrName, "Missing stuff, prepare to crash");
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsUnsetAttrRunnable::Run()
|
|
|
|
{
|
2011-10-17 07:59:28 -07:00
|
|
|
return mContent->UnsetAttr(kNameSpaceID_None, mAttrName, true);
|
2008-04-14 16:59:21 -07:00
|
|
|
}
|
2009-01-19 01:29:48 -08:00
|
|
|
|
|
|
|
nsReflowFrameRunnable::nsReflowFrameRunnable(nsIFrame* aFrame,
|
|
|
|
nsIPresShell::IntrinsicDirty aIntrinsicDirty,
|
|
|
|
nsFrameState aBitToAdd)
|
|
|
|
: mWeakFrame(aFrame),
|
|
|
|
mIntrinsicDirty(aIntrinsicDirty),
|
|
|
|
mBitToAdd(aBitToAdd)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsReflowFrameRunnable::Run()
|
|
|
|
{
|
|
|
|
if (mWeakFrame.IsAlive()) {
|
|
|
|
mWeakFrame->PresContext()->PresShell()->
|
|
|
|
FrameNeedsReflow(mWeakFrame, mIntrinsicDirty, mBitToAdd);
|
|
|
|
}
|
|
|
|
return NS_OK;
|
|
|
|
}
|
2011-11-23 18:48:23 -08:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Compute the minimum font size inside of a container with the given
|
|
|
|
* width, such that **when the user zooms the container to fill the full
|
|
|
|
* width of the device**, the fonts satisfy our minima.
|
|
|
|
*/
|
|
|
|
static nscoord
|
|
|
|
MinimumFontSizeFor(nsPresContext* aPresContext, nscoord aContainerWidth)
|
|
|
|
{
|
2012-06-05 20:47:33 -07:00
|
|
|
nsIPresShell* presShell = aPresContext->PresShell();
|
|
|
|
|
2012-08-22 08:56:38 -07:00
|
|
|
uint32_t emPerLine = presShell->FontSizeInflationEmPerLine();
|
|
|
|
uint32_t minTwips = presShell->FontSizeInflationMinTwips();
|
2012-05-05 06:28:06 -07:00
|
|
|
if (emPerLine == 0 && minTwips == 0) {
|
2011-11-23 18:48:23 -08:00
|
|
|
return 0;
|
|
|
|
}
|
2011-12-20 14:34:54 -08:00
|
|
|
|
|
|
|
// Clamp the container width to the device dimensions
|
|
|
|
nscoord iFrameWidth = aPresContext->GetVisibleArea().width;
|
|
|
|
nscoord effectiveContainerWidth = NS_MIN(iFrameWidth, aContainerWidth);
|
|
|
|
|
2011-11-23 18:48:23 -08:00
|
|
|
nscoord byLine = 0, byInch = 0;
|
2012-05-05 06:28:06 -07:00
|
|
|
if (emPerLine != 0) {
|
|
|
|
byLine = effectiveContainerWidth / emPerLine;
|
2011-11-23 18:48:23 -08:00
|
|
|
}
|
2012-05-05 06:28:06 -07:00
|
|
|
if (minTwips != 0) {
|
2011-11-23 18:48:23 -08:00
|
|
|
// REVIEW: Is this giving us app units and sizes *not* counting
|
|
|
|
// viewport scaling?
|
|
|
|
float deviceWidthInches =
|
2012-05-05 06:25:45 -07:00
|
|
|
aPresContext->ScreenWidthInchesForFontInflation();
|
2011-12-20 14:34:54 -08:00
|
|
|
byInch = NSToCoordRound(effectiveContainerWidth /
|
2011-11-23 18:48:23 -08:00
|
|
|
(deviceWidthInches * 1440 /
|
2012-05-05 06:28:06 -07:00
|
|
|
minTwips ));
|
2011-11-23 18:48:23 -08:00
|
|
|
}
|
|
|
|
return NS_MAX(byLine, byInch);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* static */ float
|
|
|
|
nsLayoutUtils::FontSizeInflationInner(const nsIFrame *aFrame,
|
|
|
|
nscoord aMinFontSize)
|
|
|
|
{
|
|
|
|
// Note that line heights should be inflated by the same ratio as the
|
|
|
|
// font size of the same text; thus we operate only on the font size
|
|
|
|
// even when we're scaling a line height.
|
|
|
|
nscoord styleFontSize = aFrame->GetStyleFont()->mFont.size;
|
|
|
|
if (styleFontSize <= 0) {
|
|
|
|
// Never scale zero font size.
|
|
|
|
return 1.0;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (aMinFontSize <= 0) {
|
|
|
|
// No need to scale.
|
|
|
|
return 1.0;
|
|
|
|
}
|
|
|
|
|
2012-04-13 00:21:39 -07:00
|
|
|
// If between this current frame and its font inflation container there is a
|
|
|
|
// non-inline element with fixed width or height, then we should not inflate
|
|
|
|
// fonts for this frame.
|
|
|
|
for (const nsIFrame* f = aFrame;
|
|
|
|
f && !IsContainerForFontSizeInflation(f);
|
|
|
|
f = f->GetParent()) {
|
|
|
|
nsIContent* content = f->GetContent();
|
2012-06-04 16:26:30 -07:00
|
|
|
nsIAtom* fType = f->GetType();
|
2012-04-13 00:21:39 -07:00
|
|
|
// Also, if there is more than one frame corresponding to a single
|
|
|
|
// content node, we want the outermost one.
|
2012-05-04 10:08:23 -07:00
|
|
|
if (!(f->GetParent() && f->GetParent()->GetContent() == content) &&
|
2012-06-04 16:26:30 -07:00
|
|
|
// ignore width/height on inlines since they don't apply
|
|
|
|
fType != nsGkAtoms::inlineFrame &&
|
|
|
|
// ignore width on radios and checkboxes since we enlarge them and
|
|
|
|
// they have width/height in ua.css
|
|
|
|
fType != nsGkAtoms::formControlFrame) {
|
2012-04-13 00:21:39 -07:00
|
|
|
nsStyleCoord stylePosWidth = f->GetStylePosition()->mWidth;
|
|
|
|
nsStyleCoord stylePosHeight = f->GetStylePosition()->mHeight;
|
|
|
|
if (stylePosWidth.GetUnit() != eStyleUnit_Auto ||
|
|
|
|
stylePosHeight.GetUnit() != eStyleUnit_Auto) {
|
|
|
|
|
|
|
|
return 1.0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-08-22 08:56:38 -07:00
|
|
|
int32_t interceptParam = nsLayoutUtils::FontSizeInflationMappingIntercept();
|
2012-08-11 11:33:36 -07:00
|
|
|
|
2011-11-23 18:48:23 -08:00
|
|
|
float ratio = float(styleFontSize) / float(aMinFontSize);
|
|
|
|
|
2012-08-11 11:33:36 -07:00
|
|
|
// Given a minimum inflated font size m, a specified font size s, we want to
|
|
|
|
// find the inflated font size i and then return the ratio of i to s (i/s).
|
|
|
|
if (interceptParam >= 0) {
|
|
|
|
// Since the mapping intercept parameter P is greater than zero, we use it
|
|
|
|
// to determine the point where our mapping function intersects the i=s
|
|
|
|
// line. This means that we have an equation of the form:
|
|
|
|
//
|
|
|
|
// i = m + s·(P/2)/(1 + P/2), if s <= (1 + P/2)·m
|
|
|
|
// i = s, if s >= (1 + P/2)·m
|
|
|
|
|
|
|
|
float intercept = 1 + float(interceptParam)/2.0f;
|
|
|
|
if (ratio >= intercept) {
|
|
|
|
// If we're already at 1+P/2 or more times the minimum, don't scale.
|
|
|
|
return 1.0;
|
|
|
|
}
|
|
|
|
|
|
|
|
// The point (intercept, intercept) is where the part of the i vs. s graph
|
|
|
|
// that's not slope 1 meets the i=s line. (This part of the
|
|
|
|
// graph is a line from (0, m), to that point). We calculate the
|
|
|
|
// intersection point to be ((1+P/2)m, (1+P/2)m), where P is the
|
|
|
|
// intercept parameter above. We then need to return i/s.
|
|
|
|
return (1.0f + (ratio * (intercept - 1) / intercept)) / ratio;
|
|
|
|
} else {
|
|
|
|
// This is the case where P is negative. We essentially want to implement
|
|
|
|
// the case for P=infinity here, so we make i = s + m, which means that
|
|
|
|
// i/s = s/s + m/s = 1 + 1/ratio
|
|
|
|
return 1 + 1.0f / ratio;
|
|
|
|
}
|
2011-11-23 18:48:23 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
static bool
|
|
|
|
ShouldInflateFontsForContainer(const nsIFrame *aFrame)
|
|
|
|
{
|
|
|
|
// We only want to inflate fonts for text that is in a place
|
|
|
|
// with room to expand. The question is what the best heuristic for
|
|
|
|
// that is...
|
|
|
|
// For now, we're going to use NS_FRAME_IN_CONSTRAINED_HEIGHT, which
|
|
|
|
// indicates whether the frame is inside something with a constrained
|
|
|
|
// height (propagating down the tree), but the propagation stops when
|
|
|
|
// we hit overflow-y: scroll or auto.
|
2012-03-02 09:25:33 -08:00
|
|
|
const nsStyleText* styleText = aFrame->GetStyleText();
|
|
|
|
|
|
|
|
return styleText->mTextSizeAdjust != NS_STYLE_TEXT_SIZE_ADJUST_NONE &&
|
|
|
|
!(aFrame->GetStateBits() & NS_FRAME_IN_CONSTRAINED_HEIGHT) &&
|
|
|
|
// We also want to disable font inflation for containers that have
|
|
|
|
// preformatted text.
|
2012-05-20 22:18:27 -07:00
|
|
|
styleText->WhiteSpaceCanWrap();
|
2011-11-23 18:48:23 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
nscoord
|
2012-05-20 22:18:28 -07:00
|
|
|
nsLayoutUtils::InflationMinFontSizeFor(const nsIFrame *aFrame)
|
2011-11-23 18:48:23 -08:00
|
|
|
{
|
2012-05-20 22:18:27 -07:00
|
|
|
nsPresContext *presContext = aFrame->PresContext();
|
|
|
|
if (!FontSizeInflationEnabled(presContext) ||
|
|
|
|
presContext->mInflationDisabledForShrinkWrap) {
|
2011-11-23 18:48:23 -08:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (const nsIFrame *f = aFrame; f; f = f->GetParent()) {
|
|
|
|
if (IsContainerForFontSizeInflation(f)) {
|
|
|
|
if (!ShouldInflateFontsForContainer(f)) {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2012-05-20 22:18:27 -07:00
|
|
|
nsFontInflationData *data =
|
|
|
|
nsFontInflationData::FindFontInflationDataFor(aFrame);
|
|
|
|
// FIXME: The need to null-check here is sort of a bug, and might
|
|
|
|
// lead to incorrect results.
|
|
|
|
if (!data || !data->InflationEnabled()) {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2011-11-23 18:48:23 -08:00
|
|
|
return MinimumFontSizeFor(aFrame->PresContext(),
|
2012-05-20 22:18:27 -07:00
|
|
|
data->EffectiveWidth());
|
2011-11-23 18:48:23 -08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_ABORT_IF_FALSE(false, "root should always be container");
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
float
|
2012-05-20 22:18:28 -07:00
|
|
|
nsLayoutUtils::FontSizeInflationFor(const nsIFrame *aFrame)
|
2011-11-23 18:48:23 -08:00
|
|
|
{
|
|
|
|
if (!FontSizeInflationEnabled(aFrame->PresContext())) {
|
|
|
|
return 1.0;
|
|
|
|
}
|
|
|
|
|
2012-05-20 22:18:28 -07:00
|
|
|
return FontSizeInflationInner(aFrame, InflationMinFontSizeFor(aFrame));
|
2011-11-23 18:48:23 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
/* static */ bool
|
|
|
|
nsLayoutUtils::FontSizeInflationEnabled(nsPresContext *aPresContext)
|
|
|
|
{
|
2012-06-05 20:47:33 -07:00
|
|
|
nsIPresShell* presShell = aPresContext->GetPresShell();
|
|
|
|
|
|
|
|
if (!presShell ||
|
|
|
|
(presShell->FontSizeInflationEmPerLine() == 0 &&
|
|
|
|
presShell->FontSizeInflationMinTwips() == 0) ||
|
2012-01-30 14:52:11 -08:00
|
|
|
aPresContext->IsChrome()) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2012-08-22 13:17:20 -07:00
|
|
|
// XXXjwir3:
|
|
|
|
// See bug 706918, comment 23 for more information on this particular section
|
|
|
|
// of the code. We're using "screen size" in place of the size of the content
|
|
|
|
// area, because on mobile, these are close or equal. This will work for our
|
|
|
|
// purposes (bug 706198), but it will need to be changed in the future to be
|
|
|
|
// more correct when we bring the rest of the viewport code into platform.
|
|
|
|
// We actually want the size of the content area, in the event that we don't
|
|
|
|
// have any metadata about the width and/or height. On mobile, the screen size
|
|
|
|
// and the size of the content area are very close, or the same value.
|
|
|
|
// In XUL fennec, the content area is the size of the <browser> widget, but
|
|
|
|
// in native fennec, the content area is the size of the Gecko LayerView
|
|
|
|
// object.
|
|
|
|
|
|
|
|
// TODO:
|
|
|
|
// Once bug 716575 has been resolved, this code should be changed so that it
|
|
|
|
// does the right thing on all platforms.
|
|
|
|
nsresult rv;
|
|
|
|
nsCOMPtr<nsIScreenManager> screenMgr =
|
|
|
|
do_GetService("@mozilla.org/gfx/screenmanager;1", &rv);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2012-01-30 14:52:11 -08:00
|
|
|
|
2012-08-22 13:17:20 -07:00
|
|
|
nsCOMPtr<nsIScreen> screen;
|
|
|
|
screenMgr->GetPrimaryScreen(getter_AddRefs(screen));
|
|
|
|
if (screen) {
|
|
|
|
int32_t screenLeft, screenTop, screenWidth, screenHeight;
|
|
|
|
screen->GetRect(&screenLeft, &screenTop, &screenWidth, &screenHeight);
|
|
|
|
|
|
|
|
ViewportInfo vInf =
|
|
|
|
nsContentUtils::GetViewportInfo(aPresContext->PresShell()->GetDocument(),
|
|
|
|
screenWidth, screenHeight);
|
|
|
|
|
|
|
|
if (vInf.defaultZoom >= 1.0 || vInf.autoSize) {
|
|
|
|
return false;
|
|
|
|
}
|
2012-01-30 14:52:11 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
2011-11-23 18:48:23 -08:00
|
|
|
}
|